From a4a9bef11b4db23869e0e06c02cbb0ac986f9cc4 Mon Sep 17 00:00:00 2001 From: Khang Vu Date: Thu, 5 Mar 2026 23:31:50 -0800 Subject: [PATCH 01/15] remove unneeded test and adjust test to work with oajs changes --- karma.conf.maker.js | 18 +- modules/utiqIdSystem.js | 2 +- modules/utiqMtpIdSystem.js | 2 +- test/spec/modules/1plusXRtdProvider_spec.js | 470 -- .../modules/33acrossAnalyticsAdapter_spec.js | 1162 ---- test/spec/modules/33acrossBidAdapter_spec.js | 2645 -------- .../spec/modules/360playvidBidAdapter_spec.js | 518 -- .../spec/modules/51DegreesRtdProvider_spec.js | 485 -- .../AsteriobidPbmAnalyticsAdapter_spec.js | 152 - test/spec/modules/ViouslyBidAdapter_spec.js | 480 -- test/spec/modules/a1MediaBidAdapter_spec.js | 249 - test/spec/modules/a1MediaRtdProvider_spec.js | 105 - test/spec/modules/a4gBidAdapter_spec.js | 235 - test/spec/modules/ablidaBidAdapter_spec.js | 151 - test/spec/modules/acuityadsBidAdapter_spec.js | 566 -- test/spec/modules/ad2ictionBidAdapter_spec.js | 223 - .../modules/adWMGAnalyticsAdapter_spec.js | 178 - test/spec/modules/adWMGBidAdapter_spec.js | 330 - .../modules/adagioAnalyticsAdapter_spec.js | 1256 ---- test/spec/modules/adagioBidAdapter_spec.js | 1677 ----- test/spec/modules/adagioRtdProvider_spec.js | 732 --- test/spec/modules/adbutlerBidAdapter_spec.js | 329 - test/spec/modules/addefendBidAdapter_spec.js | 185 - test/spec/modules/adfBidAdapter_spec.js | 1371 ---- test/spec/modules/adfusionBidAdapter_spec.js | 130 - .../modules/adgenerationBidAdapter_spec.js | 1421 ----- test/spec/modules/adgridBidAdapter_spec.js | 573 -- test/spec/modules/adhashBidAdapter_spec.js | 339 - test/spec/modules/adheseBidAdapter_spec.js | 558 -- test/spec/modules/adipoloBidAdapter_spec.js | 477 -- .../modules/adkernelAdnBidAdapter_spec.js | 432 -- test/spec/modules/adkernelBidAdapter_spec.js | 804 --- test/spec/modules/adlaneRtdProvider_spec.js | 264 - .../modules/adlooxAnalyticsAdapter_spec.js | 284 - test/spec/modules/adlooxRtdProvider_spec.js | 223 - test/spec/modules/admaruBidAdapter_spec.js | 172 - test/spec/modules/admaticBidAdapter_spec.js | 1161 ---- test/spec/modules/admediaBidAdapter_spec.js | 130 - test/spec/modules/admixerBidAdapter_spec.js | 324 - test/spec/modules/adnowBidAdapter_spec.js | 163 - .../modules/adnuntiusAnalyticsAdapter_spec.js | 536 -- test/spec/modules/adnuntiusBidAdapter_spec.js | 1865 ------ .../spec/modules/adnuntiusRtdProvider_spec.js | 145 - test/spec/modules/adotBidAdapter_spec.js | 336 - test/spec/modules/adpartnerBidAdapter_spec.js | 337 - .../modules/adplusAnalyticsAdapter_spec.js | 176 - test/spec/modules/adplusBidAdapter_spec.js | 237 - test/spec/modules/adponeBidAdapter_spec.js | 218 - test/spec/modules/adprimeBidAdapter_spec.js | 471 -- test/spec/modules/adqueryBidAdapter_spec.js | 237 - .../modules/adrelevantisBidAdapter_spec.js | 755 --- test/spec/modules/adrinoBidAdapter_spec.js | 353 -- test/spec/modules/adriverBidAdapter_spec.js | 605 -- .../modules/ads_interactiveBidAdapter_spec.js | 517 -- test/spec/modules/adspiritBidAdapter_spec.js | 493 -- test/spec/modules/adstirBidAdapter_spec.js | 413 -- test/spec/modules/adtargetBidAdapter_spec.js | 353 -- .../modules/adtelligentBidAdapter_spec.js | 471 -- test/spec/modules/adtrgtmeBidAdapter_spec.js | 733 --- test/spec/modules/adtrueBidAdapter_spec.js | 525 -- test/spec/modules/aduptechBidAdapter_spec.js | 784 --- .../modules/advRedAnalyticsAdapter_spec.js | 114 - .../modules/advangelistsBidAdapter_spec.js | 117 - .../modules/advertisingBidAdapter_spec.js | 1544 ----- test/spec/modules/adverxoBidAdapter_spec.js | 749 --- .../modules/adxcgAnalyticsAdapter_spec.js | 207 - test/spec/modules/adxcgBidAdapter_spec.js | 576 -- .../adxpremiumAnalyticsAdapter_spec.js | 415 -- test/spec/modules/adyoulikeBidAdapter_spec.js | 1014 --- test/spec/modules/afpBidAdapter_spec.js | 309 - .../spec/modules/agmaAnalyticsAdapter_spec.js | 421 -- test/spec/modules/aidemBidAdapter_spec.js | 697 -- test/spec/modules/airgridRtdProvider_spec.js | 93 - test/spec/modules/ajaBidAdapter_spec.js | 293 - test/spec/modules/akceloBidAdapter_spec.js | 263 - test/spec/modules/alkimiBidAdapter_spec.js | 240 - test/spec/modules/ampliffyBidAdapter_spec.js | 453 -- test/spec/modules/amxBidAdapter_spec.js | 849 --- test/spec/modules/aniviewBidAdapter_spec.js | 426 -- .../modules/anonymisedRtdProvider_spec.js | 324 - test/spec/modules/anyclipBidAdapter_spec.js | 449 -- test/spec/modules/apacdexBidAdapter_spec.js | 734 --- .../modules/appStockSSPBidAdapter_spec.js | 534 -- .../modules/appierAnalyticsAdapter_spec.js | 705 --- test/spec/modules/appierBidAdapter_spec.js | 178 - test/spec/modules/appnexusBidAdapter_spec.js | 2522 -------- test/spec/modules/appushBidAdapter_spec.js | 383 -- test/spec/modules/apstreamBidAdapter_spec.js | 327 - test/spec/modules/arcspanRtdProvider_spec.js | 187 - test/spec/modules/asealBidAdapter_spec.js | 212 - test/spec/modules/asoBidAdapter_spec.js | 493 -- .../asteriobidAnalyticsAdapter_spec.js | 151 - test/spec/modules/astraoneBidAdapter_spec.js | 216 - test/spec/modules/atsAnalyticsAdapter_spec.js | 278 - .../modules/audiencerunBidAdapter_spec.js | 337 - .../modules/automatadAnalyticsAdapter_spec.js | 620 -- test/spec/modules/automatadBidAdapter_spec.js | 242 - test/spec/modules/axisBidAdapter_spec.js | 481 -- test/spec/modules/axonixBidAdapter_spec.js | 351 -- .../modules/azerionedgeRtdProvider_spec.js | 198 - .../spec/modules/beachfrontBidAdapter_spec.js | 1037 --- .../spec/modules/bedigitechBidAdapter_spec.js | 136 - test/spec/modules/beopBidAdapter_spec.js | 452 -- test/spec/modules/betweenBidAdapter_spec.js | 365 -- .../modules/beyondmediaBidAdapter_spec.js | 466 -- test/spec/modules/bidResponseFilter_spec.js | 3 + test/spec/modules/biddoBidAdapter_spec.js | 172 - test/spec/modules/bidfuseBidAdapter_spec.js | 552 -- test/spec/modules/bidmaticBidAdapter_spec.js | 433 -- test/spec/modules/bidscubeBidAdapter_spec.js | 226 - .../spec/modules/bidtheatreBidAdapter_spec.js | 266 - .../modules/big-richmediaBidAdapter_spec.js | 273 - test/spec/modules/bitmediaBidAdapter_spec.js | 499 -- test/spec/modules/blastoBidAdapter_spec.js | 310 - test/spec/modules/bliinkBidAdapter_spec.js | 1196 ---- .../modules/blockthroughBidAdapter_spec.js | 207 - test/spec/modules/blueBidAdapter_spec.js | 164 - .../spec/modules/blueconicRtdProvider_spec.js | 135 - test/spec/modules/bmsBidAdapter_spec.js | 165 - test/spec/modules/bmtmBidAdapter_spec.js | 327 - test/spec/modules/boldwinBidAdapter_spec.js | 469 -- test/spec/modules/brainxBidAdapter_spec.js | 132 - .../modules/brandmetricsRtdProvider_spec.js | 259 - test/spec/modules/braveBidAdapter_spec.js | 363 -- test/spec/modules/bridBidAdapter_spec.js | 173 - .../spec/modules/bridgewellBidAdapter_spec.js | 1344 ---- .../modules/browsiAnalyticsAdapter_spec.js | 321 - test/spec/modules/browsiBidAdapter_spec.js | 218 - test/spec/modules/browsiRtdProvider_spec.js | 522 -- test/spec/modules/bucksenseBidAdapter_spec.js | 145 - test/spec/modules/buzzoolaBidAdapter_spec.js | 413 -- .../modules/byDataAnalyticsAdapter_spec.js | 192 - test/spec/modules/c1xBidAdapter_spec.js | 189 - .../cadent_aperture_mxBidAdapter_spec.js | 871 --- test/spec/modules/carodaBidAdapter_spec.js | 505 -- test/spec/modules/ccxBidAdapter_spec.js | 572 -- test/spec/modules/chromeAiRtdProvider_spec.js | 393 -- test/spec/modules/chtnwBidAdapter_spec.js | 108 - test/spec/modules/cleanioRtdProvider_spec.js | 211 - .../spec/modules/clickforceBidAdapter_spec.js | 201 - test/spec/modules/codefuelBidAdapter_spec.js | 326 - .../modules/cointrafficBidAdapter_spec.js | 341 - test/spec/modules/coinzillaBidAdapter_spec.js | 123 - test/spec/modules/colombiaBidAdapter_spec.js | 278 - .../modules/colossussspBidAdapter_spec.js | 459 -- test/spec/modules/compassBidAdapter_spec.js | 517 -- test/spec/modules/conceptxBidAdapter_spec.js | 124 - .../modules/concertAnalyticsAdapter_spec.js | 151 - test/spec/modules/concertBidAdapter_spec.js | 308 - test/spec/modules/condorxBidAdapter_spec.js | 553 -- test/spec/modules/confiantRtdProvider_spec.js | 120 - test/spec/modules/connatixBidAdapter_spec.js | 1105 ---- test/spec/modules/connectadBidAdapter_spec.js | 794 --- .../spec/modules/consumableBidAdapter_spec.js | 819 --- .../modules/contentexchangeBidAdapter_spec.js | 516 -- test/spec/modules/contxtfulBidAdapter_spec.js | 1008 --- .../spec/modules/contxtfulRtdProvider_spec.js | 1051 ---- .../spec/modules/conversantBidAdapter_spec.js | 749 --- .../spec/modules/copper6sspBidAdapter_spec.js | 519 -- test/spec/modules/cpmstarBidAdapter_spec.js | 237 - test/spec/modules/craftBidAdapter_spec.js | 169 - test/spec/modules/criteoBidAdapter_spec.js | 2849 --------- test/spec/modules/cwireBidAdapter_spec.js | 484 -- test/spec/modules/dailyhuntBidAdapter_spec.js | 403 -- .../modules/dailymotionBidAdapter_spec.js | 2404 ------- .../spec/modules/datablocksBidAdapter_spec.js | 533 -- .../modules/datawrkzAnalyticsAdapter_spec.js | 178 - test/spec/modules/datawrkzBidAdapter_spec.js | 652 -- .../spec/modules/deepintentBidAdapter_spec.js | 519 -- .../modules/deltaprojectsBidAdapter_spec.js | 394 -- test/spec/modules/dexertoBidAdapter_spec.js | 199 - .../spec/modules/dgkeywordRtdProvider_spec.js | 452 -- test/spec/modules/dianomiBidAdapter_spec.js | 1555 ----- .../modules/digitalMatterBidAdapter_spec.js | 271 - .../modules/digitalcaramelBidAdapter_spec.js | 263 - test/spec/modules/discoveryBidAdapter_spec.js | 664 -- test/spec/modules/displayioBidAdapter_spec.js | 203 - .../modules/distroscaleBidAdapter_spec.js | 213 - test/spec/modules/djaxBidAdapter_spec.js | 100 - .../docereeAdManagerBidAdapter_spec.js | 219 - test/spec/modules/docereeBidAdapter_spec.js | 138 - test/spec/modules/dochaseBidAdapter_spec.js | 322 - .../spec/modules/driftpixelBidAdapter_spec.js | 449 -- .../spec/modules/dsp_genieeBidAdapter_spec.js | 181 - test/spec/modules/dspxBidAdapter_spec.js | 808 --- test/spec/modules/dvgroupBidAdapter_spec.js | 248 - test/spec/modules/dxkultureBidAdapter_spec.js | 649 -- test/spec/modules/dxtechBidAdapter_spec.js | 604 -- .../modules/dynamicAdBoostRtdProvider_spec.js | 35 - .../spec/modules/e_volutionBidAdapter_spec.js | 478 -- test/spec/modules/eclickBidAdapter_spec.js | 214 - test/spec/modules/edge226BidAdapter_spec.js | 479 -- .../ehealthcaresolutionsBidAdapter_spec.js | 322 - .../modules/eightPodAnalyticsAdapter_spec.js | 187 - test/spec/modules/eightPodBidAdapter_spec.js | 203 - test/spec/modules/emtvBidAdapter_spec.js | 520 -- test/spec/modules/engageyaBidAdapter_spec.js | 524 -- test/spec/modules/eplanningBidAdapter_spec.js | 1520 ----- test/spec/modules/epom_dspBidAdapter_spec.js | 173 - test/spec/modules/equativBidAdapter_spec.js | 1150 ---- test/spec/modules/escalaxBidAdapter_spec.js | 305 - test/spec/modules/eskimiBidAdapter_spec.js | 307 - test/spec/modules/etargetBidAdapter_spec.js | 476 -- test/spec/modules/exadsBidAdapter_spec.js | 632 -- test/spec/modules/excoBidAdapter_spec.js | 401 -- test/spec/modules/experianRtdProvider_spec.js | 365 -- test/spec/modules/fanBidAdapter_spec.js | 349 - test/spec/modules/feedadBidAdapter_spec.js | 629 -- test/spec/modules/finativeBidAdapter_spec.js | 174 - .../modules/fintezaAnalyticsAdapter_spec.js | 235 - test/spec/modules/flippBidAdapter_spec.js | 178 - test/spec/modules/fluctBidAdapter_spec.js | 664 -- .../modules/freeWheelAdserverVideo_spec.js | 37 +- test/spec/modules/freepassBidAdapter_spec.js | 222 - test/spec/modules/fwsspBidAdapter_spec.js | 1200 ---- test/spec/modules/gameraRtdProvider_spec.js | 223 - test/spec/modules/gammaBidAdapter_spec.js | 107 - test/spec/modules/gamoshiBidAdapter_spec.js | 702 --- .../modules/genericAnalyticsAdapter_spec.js | 287 - test/spec/modules/geoedgeRtdProvider_spec.js | 174 - .../modules/geolocationRtdProvider_spec.js | 123 - test/spec/modules/getintentBidAdapter_spec.js | 220 - test/spec/modules/gjirafaBidAdapter_spec.js | 185 - test/spec/modules/glomexBidAdapter_spec.js | 144 - test/spec/modules/gmosspBidAdapter_spec.js | 193 - test/spec/modules/gnetBidAdapter_spec.js | 162 - test/spec/modules/goldbachBidAdapter_spec.js | 561 -- .../modules/goldfishAdsRtdProvider_spec.js | 163 - .../modules/greenbidsAnalyticsAdapter_spec.js | 453 -- .../spec/modules/greenbidsBidAdapter_specs.js | 1051 ---- .../spec/modules/greenbidsRtdProvider_spec.js | 357 -- test/spec/modules/gridBidAdapter_spec.js | 1696 ----- test/spec/modules/growadsBidAdapter_spec.js | 228 - .../growthCodeAnalyticsAdapter_spec.js | 69 - .../modules/growthCodeRtdProvider_spec.js | 127 - test/spec/modules/gumgumBidAdapter_spec.js | 1153 ---- test/spec/modules/h12mediaBidAdapter_spec.js | 439 -- .../modules/hadronAnalyticsAdapter_spec.js | 60 - test/spec/modules/hadronRtdProvider_spec.js | 756 --- test/spec/modules/holidBidAdapter_spec.js | 216 - ...umansecurityMalvDefenseRtdProvider_spec.js | 211 - .../modules/humansecurityRtdProvider_spec.js | 210 - test/spec/modules/hybridBidAdapter_spec.js | 343 - test/spec/modules/hypelabBidAdapter_spec.js | 326 - test/spec/modules/iasRtdProvider_spec.js | 380 -- test/spec/modules/id5AnalyticsAdapter_spec.js | 457 -- test/spec/modules/idxBidAdapter_spec.js | 103 - test/spec/modules/illuminBidAdapter_spec.js | 760 --- test/spec/modules/imRtdProvider_spec.js | 209 - test/spec/modules/impactifyBidAdapter_spec.js | 563 -- .../modules/improvedigitalBidAdapter_spec.js | 1382 ---- .../spec/modules/incrementxBidAdapter_spec.js | 229 - test/spec/modules/inmobiBidAdapter_spec.js | 1961 ------ test/spec/modules/innityBidAdapter_spec.js | 130 - .../spec/modules/insticatorBidAdapter_spec.js | 1214 ---- test/spec/modules/integr8BidAdapter_spec.js | 226 - .../modules/intentIqAnalyticsAdapter_spec.js | 657 -- test/spec/modules/intenzeBidAdapter_spec.js | 416 -- .../interactiveOffersBidAdapter_spec.js | 43 - .../modules/intersectionRtdProvider_spec.js | 164 - test/spec/modules/invamiaBidAdapter_spec.js | 172 - test/spec/modules/invibesBidAdapter_spec.js | 1539 ----- .../modules/invisiblyAnalyticsAdapter_spec.js | 574 -- test/spec/modules/ipromBidAdapter_spec.js | 197 - test/spec/modules/iqxBidAdapter_spec.js | 438 -- test/spec/modules/iqzoneBidAdapter_spec.js | 515 -- test/spec/modules/ivsBidAdapter_spec.js | 195 - test/spec/modules/ixBidAdapter_spec.js | 5592 ----------------- test/spec/modules/jixieBidAdapter_spec.js | 781 --- .../modules/justpremiumBidAdapter_spec.js | 227 - test/spec/modules/jwplayerBidAdapter_spec.js | 418 -- test/spec/modules/jwplayerRtdProvider_spec.js | 1856 ------ .../modules/kargoAnalyticsAdapter_spec.js | 42 - test/spec/modules/kargoBidAdapter_spec.js | 2141 ------- .../spec/modules/kimberliteBidAdapter_spec.js | 260 - test/spec/modules/kiviadsBidAdapter_spec.js | 518 -- test/spec/modules/koblerBidAdapter_spec.js | 789 --- .../spec/modules/krushmediaBidAdapter_spec.js | 518 -- test/spec/modules/kubientBidAdapter_spec.js | 507 -- test/spec/modules/kueezRtbBidAdapter_spec.js | 815 --- test/spec/modules/lane4BidAdapter_spec.js | 322 - test/spec/modules/lassoBidAdapter_spec.js | 419 -- .../modules/lemmaDigitalBidAdapter_spec.js | 623 -- .../spec/modules/lifestreetBidAdapter_spec.js | 232 - .../limelightDigitalBidAdapter_spec.js | 768 --- .../liveIntentAnalyticsAdapter_spec.js | 159 - .../modules/liveIntentRtdProvider_spec.js | 116 - .../livewrappedAnalyticsAdapter_spec.js | 716 --- .../modules/livewrappedBidAdapter_spec.js | 1736 ----- test/spec/modules/lkqdBidAdapter_spec.js | 322 - .../spec/modules/lm_kiviadsBidAdapter_spec.js | 438 -- .../spec/modules/lockerdomeBidAdapter_spec.js | 252 - test/spec/modules/loganBidAdapter_spec.js | 337 - test/spec/modules/logicadBidAdapter_spec.js | 453 -- test/spec/modules/loopmeBidAdapter_spec.js | 192 - test/spec/modules/loyalBidAdapter_spec.js | 480 -- test/spec/modules/luceadBidAdapter_spec.js | 183 - .../modules/lunamediahbBidAdapter_spec.js | 467 -- .../spec/modules/luponmediaBidAdapter_spec.js | 261 - test/spec/modules/mabidderBidAdapter_spec.js | 126 - test/spec/modules/madsenseBidAdapter_spec.js | 188 - .../spec/modules/madvertiseBidAdapter_spec.js | 205 - .../modules/magniteAnalyticsAdapter_spec.js | 2484 -------- .../modules/malltvAnalyticsAdapter_spec.js | 540 -- test/spec/modules/malltvBidAdapter_spec.js | 185 - test/spec/modules/mantisBidAdapter_spec.js | 361 -- test/spec/modules/marsmediaBidAdapter_spec.js | 720 --- .../modules/mathildeadsBidAdapter_spec.js | 467 -- .../modules/mediaConsortiumBidAdapter_spec.js | 412 -- .../spec/modules/mediabramaBidAdapter_spec.js | 256 - test/spec/modules/mediaeyesBidAdapter_spec.js | 183 - .../modules/mediafilterRtdProvider_spec.js | 147 - .../spec/modules/mediaforceBidAdapter_spec.js | 810 --- test/spec/modules/mediafuseBidAdapter_spec.js | 1451 ----- test/spec/modules/mediagoBidAdapter_spec.js | 551 -- .../modules/mediaimpactBidAdapter_spec.js | 337 - test/spec/modules/mediakeysBidAdapter_spec.js | 902 --- .../modules/medianetAnalyticsAdapter_spec.js | 863 --- test/spec/modules/medianetBidAdapter_spec.js | 2490 -------- test/spec/modules/medianetRtdProvider_spec.js | 146 - .../modules/mediasniperBidAdapter_spec.js | 498 -- .../modules/mediasquareBidAdapter_spec.js | 299 - test/spec/modules/mgidBidAdapter_spec.js | 1036 --- test/spec/modules/mgidRtdProvider_spec.js | 362 -- test/spec/modules/mgidXBidAdapter_spec.js | 543 -- test/spec/modules/michaoBidAdapter_spec.js | 651 -- test/spec/modules/microadBidAdapter_spec.js | 705 --- .../modules/minutemediaBidAdapter_spec.js | 744 --- test/spec/modules/missenaBidAdapter_spec.js | 371 -- test/spec/modules/mobfoxpbBidAdapter_spec.js | 479 -- test/spec/modules/mobianRtdProvider_spec.js | 281 - .../spec/modules/mobilefuseBidAdapter_spec.js | 184 - .../modules/mobkoiAnalyticsAdapter_spec.js | 516 -- test/spec/modules/mobkoiBidAdapter_spec.js | 348 - test/spec/modules/my6senseBidAdapter_spec.js | 134 - test/spec/modules/nativeryBidAdapter_spec.js | 195 - test/spec/modules/nativoBidAdapter_spec.js | 919 --- test/spec/modules/neuwoRtdProvider_spec.js | 123 - .../spec/modules/newspassidBidAdapter_spec.js | 346 - .../modules/nextMillenniumBidAdapter_spec.js | 1341 ---- test/spec/modules/nextrollBidAdapter_spec.js | 290 - test/spec/modules/nexverseBidAdapter_spec.js | 216 - test/spec/modules/nexx360BidAdapter_spec.js | 724 --- .../modules/nobidAnalyticsAdapter_spec.js | 617 -- test/spec/modules/nobidBidAdapter_spec.js | 1086 ---- test/spec/modules/nodalsAiRtdProvider_spec.js | 865 --- test/spec/modules/oftmediaRtdProvider_spec.js | 437 -- test/spec/modules/oguryBidAdapter_spec.js | 1039 --- test/spec/modules/omnidexBidAdapter_spec.js | 775 --- test/spec/modules/omsBidAdapter_spec.js | 577 -- test/spec/modules/oneKeyRtdProvider_spec.js | 152 - test/spec/modules/onetagBidAdapter_spec.js | 1158 ---- test/spec/modules/onomagicBidAdapter_spec.js | 297 - .../spec/modules/ooloAnalyticsAdapter_spec.js | 793 --- .../modules/opaMarketplaceBidAdapter_spec.js | 785 --- test/spec/modules/open8BidAdapter_spec.js | 258 - .../modules/openadsServerBidAdapter_spec.js | 4701 -------------- test/spec/modules/openwebBidAdapter_spec.js | 753 --- test/spec/modules/openxBidAdapter_spec.js | 2190 ------- test/spec/modules/operaadsBidAdapter_spec.js | 826 --- test/spec/modules/oprxBidAdapter_spec.js | 99 - test/spec/modules/opscoBidAdapter_spec.js | 263 - test/spec/modules/optableBidAdapter_spec.js | 116 - test/spec/modules/optableRtdProvider_spec.js | 262 - .../modules/optidigitalBidAdapter_spec.js | 667 -- test/spec/modules/optimeraRtdProvider_spec.js | 231 - .../modules/optimonAnalyticsAdapter_spec.js | 32 - test/spec/modules/optoutBidAdapter_spec.js | 115 - test/spec/modules/orakiBidAdapter_spec.js | 513 -- test/spec/modules/orbidderBidAdapter_spec.js | 560 -- test/spec/modules/orbitsoftBidAdapter_spec.js | 255 - test/spec/modules/otmBidAdapter_spec.js | 88 - test/spec/modules/outbrainBidAdapter_spec.js | 937 --- .../spec/modules/overtoneRtdProvider_spec.mjs | 76 - test/spec/modules/ownadxBidAdapter_spec.js | 103 - .../modules/oxxionAnalyticsAdapter_spec.js | 349 - test/spec/modules/oxxionRtdProvider_spec.js | 160 - test/spec/modules/ozoneBidAdapter_spec.js | 3717 ----------- test/spec/modules/paapi_spec.js | 10 - test/spec/modules/padsquadBidAdapter_spec.js | 262 - test/spec/modules/pangleBidAdapter_spec.js | 391 -- test/spec/modules/performaxBidAdapter_spec.js | 175 - test/spec/modules/pgamsspBidAdapter_spec.js | 516 -- .../modules/pianoDmpAnalyticsAdapter_spec.js | 63 - test/spec/modules/pilotxBidAdapter_spec.js | 370 -- test/spec/modules/pinkLionBidAdapter_spec.js | 478 -- test/spec/modules/pixfutureBidAdapter_spec.js | 255 - test/spec/modules/playdigoBidAdapter_spec.js | 478 -- test/spec/modules/precisoBidAdapter_spec.js | 342 - test/spec/modules/prismaBidAdapter_spec.js | 261 - .../modules/programmaticXBidAdapter_spec.js | 788 --- .../modules/programmaticaBidAdapter_spec.js | 263 - .../spec/modules/proxistoreBidAdapter_spec.js | 167 - test/spec/modules/pstudioBidAdapter_spec.js | 514 -- test/spec/modules/pubCircleBidAdapter_spec.js | 467 -- test/spec/modules/pubgeniusBidAdapter_spec.js | 552 -- test/spec/modules/publirBidAdapter_spec.js | 493 -- .../modules/pubmaticAnalyticsAdapter_spec.js | 1569 ----- test/spec/modules/pubmaticBidAdapter_spec.js | 1876 ------ test/spec/modules/pubmaticRtdProvider_spec.js | 1243 ---- .../modules/pubperfAnalyticsAdapter_spec.js | 43 - test/spec/modules/pubriseBidAdapter_spec.js | 517 -- .../modules/pubstackAnalyticsAdapter_spec.js | 24 - .../modules/pubwiseAnalyticsAdapter_spec.js | 151 - test/spec/modules/pubxBidAdapter_spec.js | 207 - .../modules/pubxaiAnalyticsAdapter_spec.js | 1178 ---- test/spec/modules/pubxaiRtdProvider_spec.js | 429 -- .../spec/modules/pulsepointBidAdapter_spec.js | 706 --- test/spec/modules/pwbidBidAdapter_spec.js | 897 --- test/spec/modules/pxyzBidAdapter_spec.js | 224 - test/spec/modules/qortexRtdProvider_spec.js | 410 -- test/spec/modules/qtBidAdapter_spec.js | 516 -- test/spec/modules/quantcastBidAdapter_spec.js | 859 --- test/spec/modules/qwarryBidAdapter_spec.js | 170 - test/spec/modules/r2b2BidAdapter_spec.js | 689 -- test/spec/modules/rakutenBidAdapter_spec.js | 171 - .../spec/modules/raveltechRtdProvider_spec.js | 108 - test/spec/modules/raynRtdProvider_spec.js | 368 -- test/spec/modules/readpeakBidAdapter_spec.js | 539 -- .../modules/reconciliationRtdProvider_spec.js | 221 - test/spec/modules/rediadsBidAdapter_spec.js | 144 - test/spec/modules/redtramBidAdapter_spec.js | 256 - test/spec/modules/relaidoBidAdapter_spec.js | 584 -- test/spec/modules/relayBidAdapter_spec.js | 131 - test/spec/modules/relevadRtdProvider_spec.js | 412 -- .../modules/relevantAnalyticsAdapter_spec.js | 43 - .../modules/relevantdigitalBidAdapter_spec.js | 299 - .../modules/relevatehealthBidAdapter_spec.js | 209 - .../modules/resetdigitalBidAdapter_spec.js | 221 - .../modules/responsiveAdsBidAdapter_spec.js | 145 - .../spec/modules/retailspotBidAdapter_spec.js | 426 -- .../spec/modules/revcontentBidAdapter_spec.js | 366 -- test/spec/modules/rhythmoneBidAdapter_spec.js | 763 --- .../modules/richaudienceBidAdapter_spec.js | 1306 ---- .../ringieraxelspringerBidAdapter_spec.js | 676 -- test/spec/modules/riseBidAdapter_spec.js | 795 --- .../modules/risemediatechBidAdapter_spec.js | 497 -- .../spec/modules/rivrAnalyticsAdapter_spec.js | 149 - test/spec/modules/rixengineBidAdapter_spec.js | 141 - .../spec/modules/robustAppsBidAdapter_spec.js | 441 -- test/spec/modules/robustaBidAdapter_spec.js | 150 - test/spec/modules/rocketlabBidAdapter_spec.js | 597 -- .../modules/roxotAnalyticsAdapter_spec.js | 443 -- test/spec/modules/rtbhouseBidAdapter_spec.js | 815 --- test/spec/modules/rtbsapeBidAdapter_spec.js | 209 - test/spec/modules/rubiconBidAdapter_spec.js | 4919 --------------- test/spec/modules/rumbleBidAdapter_spec.js | 125 - .../modules/scaleableAnalyticsAdapter_spec.js | 165 - test/spec/modules/scatteredBidAdapter_spec.js | 208 - test/spec/modules/scope3RtdProvider_spec.js | 500 -- test/spec/modules/seedtagBidAdapter_spec.js | 959 --- test/spec/modules/semantiqRtdProvider_spec.js | 441 -- test/spec/modules/setupadBidAdapter_spec.js | 390 -- test/spec/modules/sevioBidAdapter_spec.js | 209 - .../modules/sharethroughBidAdapter_spec.js | 1545 ----- test/spec/modules/shinezBidAdapter_spec.js | 608 -- test/spec/modules/shinezRtbBidAdapter_spec.js | 763 --- .../modules/showheroes-bsBidAdapter_spec.js | 362 -- test/spec/modules/silvermobBidAdapter_spec.js | 303 - .../spec/modules/silverpushBidAdapter_spec.js | 394 -- test/spec/modules/sirdataRtdProvider_spec.js | 362 -- test/spec/modules/slimcutBidAdapter_spec.js | 199 - test/spec/modules/smaatoBidAdapter_spec.js | 1778 ------ .../modules/smartadserverBidAdapter_spec.js | 1693 ----- test/spec/modules/smarthubBidAdapter_spec.js | 490 -- test/spec/modules/smarticoBidAdapter_spec.js | 135 - test/spec/modules/smartxBidAdapter_spec.js | 704 --- .../modules/smartyadsAnalyticsAdapter_spec.js | 441 -- test/spec/modules/smartyadsBidAdapter_spec.js | 278 - .../spec/modules/smartytechBidAdapter_spec.js | 361 -- .../modules/smilewantedBidAdapter_spec.js | 662 -- test/spec/modules/smootBidAdapter_spec.js | 597 -- test/spec/modules/snigelBidAdapter_spec.js | 451 -- test/spec/modules/sonaradsBidAdapter_spec.js | 1156 ---- test/spec/modules/sonobiBidAdapter_spec.js | 909 --- test/spec/modules/sovrnBidAdapter_spec.js | 1413 ----- test/spec/modules/sparteoBidAdapter_spec.js | 534 -- test/spec/modules/ssmasBidAdapter_spec.js | 244 - test/spec/modules/sspBCBidAdapter_spec.js | 835 --- .../spec/modules/ssp_genieeBidAdapter_spec.js | 681 -- .../spec/modules/stackadaptBidAdapter_spec.js | 1391 ---- test/spec/modules/startioBidAdapter_spec.js | 373 -- test/spec/modules/stnBidAdapter_spec.js | 745 --- .../modules/stroeerCoreBidAdapter_spec.js | 1150 ---- test/spec/modules/stvBidAdapter_spec.js | 526 -- test/spec/modules/sublimeBidAdapter_spec.js | 614 -- test/spec/modules/suimBidAdapter_spec.js | 154 - .../modules/symitriAnalyticsAdapter_spec.js | 90 - .../modules/symitriDapRtdProvider_spec.js | 708 --- test/spec/modules/taboolaBidAdapter_spec.js | 1527 ----- .../modules/tadvertisingBidAdapter_spec.js | 965 --- test/spec/modules/tagorasBidAdapter_spec.js | 777 --- test/spec/modules/talkadsBidAdapter_spec.js | 233 - test/spec/modules/tapnativeBidAdapter_spec.js | 322 - test/spec/modules/tappxBidAdapter_spec.js | 531 -- .../modules/targetVideoBidAdapter_spec.js | 356 -- test/spec/modules/teadsBidAdapter_spec.js | 1411 ----- test/spec/modules/tealBidAdapter_spec.js | 268 - test/spec/modules/temedyaBidAdapter_spec.js | 177 - .../modules/terceptAnalyticsAdapter_spec.js | 1020 --- test/spec/modules/theAdxBidAdapter_spec.js | 752 --- .../modules/themoneytizerBidAdapter_spec.js | 283 - test/spec/modules/timeoutRtdProvider_spec.js | 338 - test/spec/modules/tpmnBidAdapter_spec.js | 447 -- .../modules/trafficgateBidAdapter_spec.js | 1384 ---- test/spec/modules/trionBidAdapter_spec.js | 407 -- .../spec/modules/tripleliftBidAdapter_spec.js | 1512 ----- test/spec/modules/truereachBidAdapter_spec.js | 102 - test/spec/modules/ttdBidAdapter_spec.js | 1697 ----- .../modules/twistDigitalBidAdapter_spec.js | 1064 ---- .../modules/ucfunnelAnalyticsAdapter_spec.js | 487 -- test/spec/modules/ucfunnelBidAdapter_spec.js | 367 -- .../modules/underdogmediaBidAdapter_spec.js | 1058 ---- test/spec/modules/undertoneBidAdapter_spec.js | 665 -- test/spec/modules/unicornBidAdapter_spec.js | 570 -- .../modules/uniquestAnalyticsAdapter_spec.js | 461 -- test/spec/modules/uniquestBidAdapter_spec.js | 104 - test/spec/modules/unrulyBidAdapter_spec.js | 1328 ---- test/spec/modules/userId_spec.js | 2 +- test/spec/modules/valuadBidAdapter_spec.js | 508 -- test/spec/modules/vdoaiBidAdapter_spec.js | 768 --- test/spec/modules/ventesBidAdapter_spec.js | 846 --- test/spec/modules/viantBidAdapter_spec.js | 557 -- .../modules/vibrantmediaBidAdapter_spec.js | 1227 ---- test/spec/modules/vidazooBidAdapter_spec.js | 1124 ---- test/spec/modules/videobyteBidAdapter_spec.js | 628 -- .../modules/videoheroesBidAdapter_spec.js | 363 -- test/spec/modules/videonowBidAdapter_spec.js | 80 - .../spec/modules/videoreachBidAdapter_spec.js | 145 - test/spec/modules/vidoomyBidAdapter_spec.js | 452 -- .../spec/modules/viewdeosDXBidAdapter_spec.js | 345 - test/spec/modules/viqeoBidAdapter_spec.js | 119 - .../modules/visiblemeasuresBidAdapter_spec.js | 518 -- test/spec/modules/vistarsBidAdapter_spec.js | 248 - test/spec/modules/visxBidAdapter_spec.js | 2306 ------- test/spec/modules/vlybyBidAdapter_spec.js | 111 - test/spec/modules/voxBidAdapter_spec.js | 425 -- test/spec/modules/vrtcalBidAdapter_spec.js | 172 - test/spec/modules/vuukleBidAdapter_spec.js | 148 - test/spec/modules/waardexBidAdapter_spec.js | 376 -- test/spec/modules/weboramaRtdProvider_spec.js | 3970 ------------ test/spec/modules/welectBidAdapter_spec.js | 227 - test/spec/modules/widespaceBidAdapter_spec.js | 264 - test/spec/modules/winrBidAdapter_spec.js | 779 --- test/spec/modules/wipesBidAdapter_spec.js | 154 - test/spec/modules/wurflRtdProvider_spec.js | 489 -- test/spec/modules/xeBidAdapter_spec.js | 449 -- test/spec/modules/yahooAdsBidAdapter_spec.js | 1699 ----- .../modules/yandexAnalyticsAdapter_spec.js | 164 - test/spec/modules/yandexBidAdapter_spec.js | 954 --- test/spec/modules/yieldlabBidAdapter_spec.js | 979 --- test/spec/modules/yieldliftBidAdapter_spec.js | 278 - test/spec/modules/yieldloveBidAdapter_spec.js | 128 - test/spec/modules/yieldmoBidAdapter_spec.js | 938 --- .../modules/yieldoneAnalyticsAdapter_spec.js | 289 - test/spec/modules/yieldoneBidAdapter_spec.js | 737 --- .../yuktamediaAnalyticsAdapter_spec.js | 714 --- .../modules/zeta_globalBidAdapter_spec.js | 84 - .../zeta_global_sspAnalyticsAdapter_spec.js | 706 --- .../modules/zeta_global_sspBidAdapter_spec.js | 877 --- test/spec/modules/zmaticooBidAdapter_spec.js | 266 - 561 files changed, 32 insertions(+), 309744 deletions(-) delete mode 100644 test/spec/modules/1plusXRtdProvider_spec.js delete mode 100644 test/spec/modules/33acrossAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/33acrossBidAdapter_spec.js delete mode 100644 test/spec/modules/360playvidBidAdapter_spec.js delete mode 100644 test/spec/modules/51DegreesRtdProvider_spec.js delete mode 100644 test/spec/modules/AsteriobidPbmAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/ViouslyBidAdapter_spec.js delete mode 100644 test/spec/modules/a1MediaBidAdapter_spec.js delete mode 100644 test/spec/modules/a1MediaRtdProvider_spec.js delete mode 100644 test/spec/modules/a4gBidAdapter_spec.js delete mode 100644 test/spec/modules/ablidaBidAdapter_spec.js delete mode 100644 test/spec/modules/acuityadsBidAdapter_spec.js delete mode 100644 test/spec/modules/ad2ictionBidAdapter_spec.js delete mode 100644 test/spec/modules/adWMGAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/adWMGBidAdapter_spec.js delete mode 100644 test/spec/modules/adagioAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/adagioBidAdapter_spec.js delete mode 100644 test/spec/modules/adagioRtdProvider_spec.js delete mode 100644 test/spec/modules/adbutlerBidAdapter_spec.js delete mode 100644 test/spec/modules/addefendBidAdapter_spec.js delete mode 100644 test/spec/modules/adfBidAdapter_spec.js delete mode 100644 test/spec/modules/adfusionBidAdapter_spec.js delete mode 100644 test/spec/modules/adgenerationBidAdapter_spec.js delete mode 100644 test/spec/modules/adgridBidAdapter_spec.js delete mode 100644 test/spec/modules/adhashBidAdapter_spec.js delete mode 100644 test/spec/modules/adheseBidAdapter_spec.js delete mode 100644 test/spec/modules/adipoloBidAdapter_spec.js delete mode 100644 test/spec/modules/adkernelAdnBidAdapter_spec.js delete mode 100644 test/spec/modules/adkernelBidAdapter_spec.js delete mode 100644 test/spec/modules/adlaneRtdProvider_spec.js delete mode 100644 test/spec/modules/adlooxAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/adlooxRtdProvider_spec.js delete mode 100644 test/spec/modules/admaruBidAdapter_spec.js delete mode 100644 test/spec/modules/admaticBidAdapter_spec.js delete mode 100644 test/spec/modules/admediaBidAdapter_spec.js delete mode 100644 test/spec/modules/admixerBidAdapter_spec.js delete mode 100644 test/spec/modules/adnowBidAdapter_spec.js delete mode 100644 test/spec/modules/adnuntiusAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/adnuntiusBidAdapter_spec.js delete mode 100644 test/spec/modules/adnuntiusRtdProvider_spec.js delete mode 100644 test/spec/modules/adotBidAdapter_spec.js delete mode 100644 test/spec/modules/adpartnerBidAdapter_spec.js delete mode 100644 test/spec/modules/adplusAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/adplusBidAdapter_spec.js delete mode 100644 test/spec/modules/adponeBidAdapter_spec.js delete mode 100644 test/spec/modules/adprimeBidAdapter_spec.js delete mode 100644 test/spec/modules/adqueryBidAdapter_spec.js delete mode 100644 test/spec/modules/adrelevantisBidAdapter_spec.js delete mode 100644 test/spec/modules/adrinoBidAdapter_spec.js delete mode 100644 test/spec/modules/adriverBidAdapter_spec.js delete mode 100644 test/spec/modules/ads_interactiveBidAdapter_spec.js delete mode 100644 test/spec/modules/adspiritBidAdapter_spec.js delete mode 100644 test/spec/modules/adstirBidAdapter_spec.js delete mode 100644 test/spec/modules/adtargetBidAdapter_spec.js delete mode 100644 test/spec/modules/adtelligentBidAdapter_spec.js delete mode 100644 test/spec/modules/adtrgtmeBidAdapter_spec.js delete mode 100644 test/spec/modules/adtrueBidAdapter_spec.js delete mode 100644 test/spec/modules/aduptechBidAdapter_spec.js delete mode 100644 test/spec/modules/advRedAnalyticsAdapter_spec.js delete mode 100755 test/spec/modules/advangelistsBidAdapter_spec.js delete mode 100644 test/spec/modules/advertisingBidAdapter_spec.js delete mode 100644 test/spec/modules/adverxoBidAdapter_spec.js delete mode 100644 test/spec/modules/adxcgAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/adxcgBidAdapter_spec.js delete mode 100644 test/spec/modules/adxpremiumAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/adyoulikeBidAdapter_spec.js delete mode 100644 test/spec/modules/afpBidAdapter_spec.js delete mode 100644 test/spec/modules/agmaAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/aidemBidAdapter_spec.js delete mode 100644 test/spec/modules/airgridRtdProvider_spec.js delete mode 100644 test/spec/modules/ajaBidAdapter_spec.js delete mode 100644 test/spec/modules/akceloBidAdapter_spec.js delete mode 100644 test/spec/modules/alkimiBidAdapter_spec.js delete mode 100644 test/spec/modules/ampliffyBidAdapter_spec.js delete mode 100644 test/spec/modules/amxBidAdapter_spec.js delete mode 100644 test/spec/modules/aniviewBidAdapter_spec.js delete mode 100644 test/spec/modules/anonymisedRtdProvider_spec.js delete mode 100644 test/spec/modules/anyclipBidAdapter_spec.js delete mode 100644 test/spec/modules/apacdexBidAdapter_spec.js delete mode 100644 test/spec/modules/appStockSSPBidAdapter_spec.js delete mode 100644 test/spec/modules/appierAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/appierBidAdapter_spec.js delete mode 100644 test/spec/modules/appnexusBidAdapter_spec.js delete mode 100644 test/spec/modules/appushBidAdapter_spec.js delete mode 100644 test/spec/modules/apstreamBidAdapter_spec.js delete mode 100644 test/spec/modules/arcspanRtdProvider_spec.js delete mode 100644 test/spec/modules/asealBidAdapter_spec.js delete mode 100644 test/spec/modules/asoBidAdapter_spec.js delete mode 100644 test/spec/modules/asteriobidAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/astraoneBidAdapter_spec.js delete mode 100644 test/spec/modules/atsAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/audiencerunBidAdapter_spec.js delete mode 100644 test/spec/modules/automatadAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/automatadBidAdapter_spec.js delete mode 100644 test/spec/modules/axisBidAdapter_spec.js delete mode 100644 test/spec/modules/axonixBidAdapter_spec.js delete mode 100644 test/spec/modules/azerionedgeRtdProvider_spec.js delete mode 100644 test/spec/modules/beachfrontBidAdapter_spec.js delete mode 100644 test/spec/modules/bedigitechBidAdapter_spec.js delete mode 100644 test/spec/modules/beopBidAdapter_spec.js delete mode 100644 test/spec/modules/betweenBidAdapter_spec.js delete mode 100644 test/spec/modules/beyondmediaBidAdapter_spec.js delete mode 100644 test/spec/modules/biddoBidAdapter_spec.js delete mode 100644 test/spec/modules/bidfuseBidAdapter_spec.js delete mode 100644 test/spec/modules/bidmaticBidAdapter_spec.js delete mode 100644 test/spec/modules/bidscubeBidAdapter_spec.js delete mode 100644 test/spec/modules/bidtheatreBidAdapter_spec.js delete mode 100644 test/spec/modules/big-richmediaBidAdapter_spec.js delete mode 100644 test/spec/modules/bitmediaBidAdapter_spec.js delete mode 100644 test/spec/modules/blastoBidAdapter_spec.js delete mode 100644 test/spec/modules/bliinkBidAdapter_spec.js delete mode 100644 test/spec/modules/blockthroughBidAdapter_spec.js delete mode 100755 test/spec/modules/blueBidAdapter_spec.js delete mode 100644 test/spec/modules/blueconicRtdProvider_spec.js delete mode 100755 test/spec/modules/bmsBidAdapter_spec.js delete mode 100644 test/spec/modules/bmtmBidAdapter_spec.js delete mode 100644 test/spec/modules/boldwinBidAdapter_spec.js delete mode 100644 test/spec/modules/brainxBidAdapter_spec.js delete mode 100644 test/spec/modules/brandmetricsRtdProvider_spec.js delete mode 100644 test/spec/modules/braveBidAdapter_spec.js delete mode 100644 test/spec/modules/bridBidAdapter_spec.js delete mode 100644 test/spec/modules/bridgewellBidAdapter_spec.js delete mode 100644 test/spec/modules/browsiAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/browsiBidAdapter_spec.js delete mode 100644 test/spec/modules/browsiRtdProvider_spec.js delete mode 100644 test/spec/modules/bucksenseBidAdapter_spec.js delete mode 100644 test/spec/modules/buzzoolaBidAdapter_spec.js delete mode 100644 test/spec/modules/byDataAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/c1xBidAdapter_spec.js delete mode 100644 test/spec/modules/cadent_aperture_mxBidAdapter_spec.js delete mode 100644 test/spec/modules/carodaBidAdapter_spec.js delete mode 100644 test/spec/modules/ccxBidAdapter_spec.js delete mode 100644 test/spec/modules/chromeAiRtdProvider_spec.js delete mode 100644 test/spec/modules/chtnwBidAdapter_spec.js delete mode 100644 test/spec/modules/cleanioRtdProvider_spec.js delete mode 100644 test/spec/modules/clickforceBidAdapter_spec.js delete mode 100644 test/spec/modules/codefuelBidAdapter_spec.js delete mode 100644 test/spec/modules/cointrafficBidAdapter_spec.js delete mode 100644 test/spec/modules/coinzillaBidAdapter_spec.js delete mode 100644 test/spec/modules/colombiaBidAdapter_spec.js delete mode 100644 test/spec/modules/colossussspBidAdapter_spec.js delete mode 100644 test/spec/modules/compassBidAdapter_spec.js delete mode 100644 test/spec/modules/conceptxBidAdapter_spec.js delete mode 100644 test/spec/modules/concertAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/concertBidAdapter_spec.js delete mode 100644 test/spec/modules/condorxBidAdapter_spec.js delete mode 100644 test/spec/modules/confiantRtdProvider_spec.js delete mode 100644 test/spec/modules/connatixBidAdapter_spec.js delete mode 100644 test/spec/modules/connectadBidAdapter_spec.js delete mode 100644 test/spec/modules/consumableBidAdapter_spec.js delete mode 100644 test/spec/modules/contentexchangeBidAdapter_spec.js delete mode 100644 test/spec/modules/contxtfulBidAdapter_spec.js delete mode 100644 test/spec/modules/contxtfulRtdProvider_spec.js delete mode 100644 test/spec/modules/conversantBidAdapter_spec.js delete mode 100644 test/spec/modules/copper6sspBidAdapter_spec.js delete mode 100755 test/spec/modules/cpmstarBidAdapter_spec.js delete mode 100644 test/spec/modules/craftBidAdapter_spec.js delete mode 100644 test/spec/modules/criteoBidAdapter_spec.js delete mode 100644 test/spec/modules/cwireBidAdapter_spec.js delete mode 100644 test/spec/modules/dailyhuntBidAdapter_spec.js delete mode 100644 test/spec/modules/dailymotionBidAdapter_spec.js delete mode 100644 test/spec/modules/datablocksBidAdapter_spec.js delete mode 100644 test/spec/modules/datawrkzAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/datawrkzBidAdapter_spec.js delete mode 100644 test/spec/modules/deepintentBidAdapter_spec.js delete mode 100644 test/spec/modules/deltaprojectsBidAdapter_spec.js delete mode 100644 test/spec/modules/dexertoBidAdapter_spec.js delete mode 100644 test/spec/modules/dgkeywordRtdProvider_spec.js delete mode 100644 test/spec/modules/dianomiBidAdapter_spec.js delete mode 100644 test/spec/modules/digitalMatterBidAdapter_spec.js delete mode 100644 test/spec/modules/digitalcaramelBidAdapter_spec.js delete mode 100644 test/spec/modules/discoveryBidAdapter_spec.js delete mode 100644 test/spec/modules/displayioBidAdapter_spec.js delete mode 100644 test/spec/modules/distroscaleBidAdapter_spec.js delete mode 100644 test/spec/modules/djaxBidAdapter_spec.js delete mode 100644 test/spec/modules/docereeAdManagerBidAdapter_spec.js delete mode 100644 test/spec/modules/docereeBidAdapter_spec.js delete mode 100644 test/spec/modules/dochaseBidAdapter_spec.js delete mode 100644 test/spec/modules/driftpixelBidAdapter_spec.js delete mode 100644 test/spec/modules/dsp_genieeBidAdapter_spec.js delete mode 100644 test/spec/modules/dspxBidAdapter_spec.js delete mode 100644 test/spec/modules/dvgroupBidAdapter_spec.js delete mode 100644 test/spec/modules/dxkultureBidAdapter_spec.js delete mode 100644 test/spec/modules/dxtechBidAdapter_spec.js delete mode 100644 test/spec/modules/dynamicAdBoostRtdProvider_spec.js delete mode 100644 test/spec/modules/e_volutionBidAdapter_spec.js delete mode 100644 test/spec/modules/eclickBidAdapter_spec.js delete mode 100644 test/spec/modules/edge226BidAdapter_spec.js delete mode 100644 test/spec/modules/ehealthcaresolutionsBidAdapter_spec.js delete mode 100644 test/spec/modules/eightPodAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/eightPodBidAdapter_spec.js delete mode 100644 test/spec/modules/emtvBidAdapter_spec.js delete mode 100644 test/spec/modules/engageyaBidAdapter_spec.js delete mode 100644 test/spec/modules/eplanningBidAdapter_spec.js delete mode 100644 test/spec/modules/epom_dspBidAdapter_spec.js delete mode 100644 test/spec/modules/equativBidAdapter_spec.js delete mode 100644 test/spec/modules/escalaxBidAdapter_spec.js delete mode 100644 test/spec/modules/eskimiBidAdapter_spec.js delete mode 100644 test/spec/modules/etargetBidAdapter_spec.js delete mode 100644 test/spec/modules/exadsBidAdapter_spec.js delete mode 100644 test/spec/modules/excoBidAdapter_spec.js delete mode 100644 test/spec/modules/experianRtdProvider_spec.js delete mode 100644 test/spec/modules/fanBidAdapter_spec.js delete mode 100644 test/spec/modules/feedadBidAdapter_spec.js delete mode 100644 test/spec/modules/finativeBidAdapter_spec.js delete mode 100644 test/spec/modules/fintezaAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/flippBidAdapter_spec.js delete mode 100644 test/spec/modules/fluctBidAdapter_spec.js delete mode 100644 test/spec/modules/freepassBidAdapter_spec.js delete mode 100644 test/spec/modules/fwsspBidAdapter_spec.js delete mode 100644 test/spec/modules/gameraRtdProvider_spec.js delete mode 100644 test/spec/modules/gammaBidAdapter_spec.js delete mode 100644 test/spec/modules/gamoshiBidAdapter_spec.js delete mode 100644 test/spec/modules/genericAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/geoedgeRtdProvider_spec.js delete mode 100644 test/spec/modules/geolocationRtdProvider_spec.js delete mode 100644 test/spec/modules/getintentBidAdapter_spec.js delete mode 100644 test/spec/modules/gjirafaBidAdapter_spec.js delete mode 100644 test/spec/modules/glomexBidAdapter_spec.js delete mode 100644 test/spec/modules/gmosspBidAdapter_spec.js delete mode 100644 test/spec/modules/gnetBidAdapter_spec.js delete mode 100644 test/spec/modules/goldbachBidAdapter_spec.js delete mode 100755 test/spec/modules/goldfishAdsRtdProvider_spec.js delete mode 100644 test/spec/modules/greenbidsAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/greenbidsBidAdapter_specs.js delete mode 100644 test/spec/modules/greenbidsRtdProvider_spec.js delete mode 100644 test/spec/modules/gridBidAdapter_spec.js delete mode 100644 test/spec/modules/growadsBidAdapter_spec.js delete mode 100644 test/spec/modules/growthCodeAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/growthCodeRtdProvider_spec.js delete mode 100644 test/spec/modules/gumgumBidAdapter_spec.js delete mode 100644 test/spec/modules/h12mediaBidAdapter_spec.js delete mode 100644 test/spec/modules/hadronAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/hadronRtdProvider_spec.js delete mode 100644 test/spec/modules/holidBidAdapter_spec.js delete mode 100644 test/spec/modules/humansecurityMalvDefenseRtdProvider_spec.js delete mode 100644 test/spec/modules/humansecurityRtdProvider_spec.js delete mode 100644 test/spec/modules/hybridBidAdapter_spec.js delete mode 100644 test/spec/modules/hypelabBidAdapter_spec.js delete mode 100644 test/spec/modules/iasRtdProvider_spec.js delete mode 100644 test/spec/modules/id5AnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/idxBidAdapter_spec.js delete mode 100644 test/spec/modules/illuminBidAdapter_spec.js delete mode 100644 test/spec/modules/imRtdProvider_spec.js delete mode 100644 test/spec/modules/impactifyBidAdapter_spec.js delete mode 100644 test/spec/modules/improvedigitalBidAdapter_spec.js delete mode 100644 test/spec/modules/incrementxBidAdapter_spec.js delete mode 100644 test/spec/modules/inmobiBidAdapter_spec.js delete mode 100644 test/spec/modules/innityBidAdapter_spec.js delete mode 100644 test/spec/modules/insticatorBidAdapter_spec.js delete mode 100644 test/spec/modules/integr8BidAdapter_spec.js delete mode 100644 test/spec/modules/intentIqAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/intenzeBidAdapter_spec.js delete mode 100644 test/spec/modules/interactiveOffersBidAdapter_spec.js delete mode 100644 test/spec/modules/intersectionRtdProvider_spec.js delete mode 100644 test/spec/modules/invamiaBidAdapter_spec.js delete mode 100644 test/spec/modules/invibesBidAdapter_spec.js delete mode 100644 test/spec/modules/invisiblyAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/ipromBidAdapter_spec.js delete mode 100644 test/spec/modules/iqxBidAdapter_spec.js delete mode 100644 test/spec/modules/iqzoneBidAdapter_spec.js delete mode 100644 test/spec/modules/ivsBidAdapter_spec.js delete mode 100644 test/spec/modules/ixBidAdapter_spec.js delete mode 100644 test/spec/modules/jixieBidAdapter_spec.js delete mode 100644 test/spec/modules/justpremiumBidAdapter_spec.js delete mode 100644 test/spec/modules/jwplayerBidAdapter_spec.js delete mode 100644 test/spec/modules/jwplayerRtdProvider_spec.js delete mode 100644 test/spec/modules/kargoAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/kargoBidAdapter_spec.js delete mode 100644 test/spec/modules/kimberliteBidAdapter_spec.js delete mode 100644 test/spec/modules/kiviadsBidAdapter_spec.js delete mode 100644 test/spec/modules/koblerBidAdapter_spec.js delete mode 100644 test/spec/modules/krushmediaBidAdapter_spec.js delete mode 100644 test/spec/modules/kubientBidAdapter_spec.js delete mode 100644 test/spec/modules/kueezRtbBidAdapter_spec.js delete mode 100644 test/spec/modules/lane4BidAdapter_spec.js delete mode 100644 test/spec/modules/lassoBidAdapter_spec.js delete mode 100644 test/spec/modules/lemmaDigitalBidAdapter_spec.js delete mode 100644 test/spec/modules/lifestreetBidAdapter_spec.js delete mode 100644 test/spec/modules/limelightDigitalBidAdapter_spec.js delete mode 100644 test/spec/modules/liveIntentAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/liveIntentRtdProvider_spec.js delete mode 100644 test/spec/modules/livewrappedAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/livewrappedBidAdapter_spec.js delete mode 100644 test/spec/modules/lkqdBidAdapter_spec.js delete mode 100644 test/spec/modules/lm_kiviadsBidAdapter_spec.js delete mode 100644 test/spec/modules/lockerdomeBidAdapter_spec.js delete mode 100644 test/spec/modules/loganBidAdapter_spec.js delete mode 100644 test/spec/modules/logicadBidAdapter_spec.js delete mode 100644 test/spec/modules/loopmeBidAdapter_spec.js delete mode 100644 test/spec/modules/loyalBidAdapter_spec.js delete mode 100755 test/spec/modules/luceadBidAdapter_spec.js delete mode 100644 test/spec/modules/lunamediahbBidAdapter_spec.js delete mode 100755 test/spec/modules/luponmediaBidAdapter_spec.js delete mode 100644 test/spec/modules/mabidderBidAdapter_spec.js delete mode 100644 test/spec/modules/madsenseBidAdapter_spec.js delete mode 100644 test/spec/modules/madvertiseBidAdapter_spec.js delete mode 100644 test/spec/modules/magniteAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/malltvAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/malltvBidAdapter_spec.js delete mode 100644 test/spec/modules/mantisBidAdapter_spec.js delete mode 100644 test/spec/modules/marsmediaBidAdapter_spec.js delete mode 100644 test/spec/modules/mathildeadsBidAdapter_spec.js delete mode 100644 test/spec/modules/mediaConsortiumBidAdapter_spec.js delete mode 100644 test/spec/modules/mediabramaBidAdapter_spec.js delete mode 100644 test/spec/modules/mediaeyesBidAdapter_spec.js delete mode 100644 test/spec/modules/mediafilterRtdProvider_spec.js delete mode 100644 test/spec/modules/mediaforceBidAdapter_spec.js delete mode 100644 test/spec/modules/mediafuseBidAdapter_spec.js delete mode 100644 test/spec/modules/mediagoBidAdapter_spec.js delete mode 100644 test/spec/modules/mediaimpactBidAdapter_spec.js delete mode 100644 test/spec/modules/mediakeysBidAdapter_spec.js delete mode 100644 test/spec/modules/medianetAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/medianetBidAdapter_spec.js delete mode 100644 test/spec/modules/medianetRtdProvider_spec.js delete mode 100644 test/spec/modules/mediasniperBidAdapter_spec.js delete mode 100644 test/spec/modules/mediasquareBidAdapter_spec.js delete mode 100644 test/spec/modules/mgidBidAdapter_spec.js delete mode 100644 test/spec/modules/mgidRtdProvider_spec.js delete mode 100644 test/spec/modules/mgidXBidAdapter_spec.js delete mode 100644 test/spec/modules/michaoBidAdapter_spec.js delete mode 100644 test/spec/modules/microadBidAdapter_spec.js delete mode 100644 test/spec/modules/minutemediaBidAdapter_spec.js delete mode 100644 test/spec/modules/missenaBidAdapter_spec.js delete mode 100644 test/spec/modules/mobfoxpbBidAdapter_spec.js delete mode 100644 test/spec/modules/mobianRtdProvider_spec.js delete mode 100644 test/spec/modules/mobilefuseBidAdapter_spec.js delete mode 100644 test/spec/modules/mobkoiAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/mobkoiBidAdapter_spec.js delete mode 100644 test/spec/modules/my6senseBidAdapter_spec.js delete mode 100644 test/spec/modules/nativeryBidAdapter_spec.js delete mode 100644 test/spec/modules/nativoBidAdapter_spec.js delete mode 100644 test/spec/modules/neuwoRtdProvider_spec.js delete mode 100644 test/spec/modules/newspassidBidAdapter_spec.js delete mode 100644 test/spec/modules/nextMillenniumBidAdapter_spec.js delete mode 100644 test/spec/modules/nextrollBidAdapter_spec.js delete mode 100644 test/spec/modules/nexverseBidAdapter_spec.js delete mode 100644 test/spec/modules/nexx360BidAdapter_spec.js delete mode 100644 test/spec/modules/nobidAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/nobidBidAdapter_spec.js delete mode 100644 test/spec/modules/nodalsAiRtdProvider_spec.js delete mode 100644 test/spec/modules/oftmediaRtdProvider_spec.js delete mode 100644 test/spec/modules/oguryBidAdapter_spec.js delete mode 100644 test/spec/modules/omnidexBidAdapter_spec.js delete mode 100644 test/spec/modules/omsBidAdapter_spec.js delete mode 100644 test/spec/modules/oneKeyRtdProvider_spec.js delete mode 100644 test/spec/modules/onetagBidAdapter_spec.js delete mode 100644 test/spec/modules/onomagicBidAdapter_spec.js delete mode 100644 test/spec/modules/ooloAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/opaMarketplaceBidAdapter_spec.js delete mode 100644 test/spec/modules/open8BidAdapter_spec.js delete mode 100644 test/spec/modules/openadsServerBidAdapter_spec.js delete mode 100644 test/spec/modules/openwebBidAdapter_spec.js delete mode 100644 test/spec/modules/openxBidAdapter_spec.js delete mode 100644 test/spec/modules/operaadsBidAdapter_spec.js delete mode 100644 test/spec/modules/oprxBidAdapter_spec.js delete mode 100644 test/spec/modules/opscoBidAdapter_spec.js delete mode 100644 test/spec/modules/optableBidAdapter_spec.js delete mode 100644 test/spec/modules/optableRtdProvider_spec.js delete mode 100755 test/spec/modules/optidigitalBidAdapter_spec.js delete mode 100644 test/spec/modules/optimeraRtdProvider_spec.js delete mode 100644 test/spec/modules/optimonAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/optoutBidAdapter_spec.js delete mode 100644 test/spec/modules/orakiBidAdapter_spec.js delete mode 100644 test/spec/modules/orbidderBidAdapter_spec.js delete mode 100644 test/spec/modules/orbitsoftBidAdapter_spec.js delete mode 100644 test/spec/modules/otmBidAdapter_spec.js delete mode 100644 test/spec/modules/outbrainBidAdapter_spec.js delete mode 100644 test/spec/modules/overtoneRtdProvider_spec.mjs delete mode 100644 test/spec/modules/ownadxBidAdapter_spec.js delete mode 100644 test/spec/modules/oxxionAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/oxxionRtdProvider_spec.js delete mode 100644 test/spec/modules/ozoneBidAdapter_spec.js delete mode 100644 test/spec/modules/padsquadBidAdapter_spec.js delete mode 100644 test/spec/modules/pangleBidAdapter_spec.js delete mode 100644 test/spec/modules/performaxBidAdapter_spec.js delete mode 100644 test/spec/modules/pgamsspBidAdapter_spec.js delete mode 100644 test/spec/modules/pianoDmpAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/pilotxBidAdapter_spec.js delete mode 100644 test/spec/modules/pinkLionBidAdapter_spec.js delete mode 100644 test/spec/modules/pixfutureBidAdapter_spec.js delete mode 100644 test/spec/modules/playdigoBidAdapter_spec.js delete mode 100644 test/spec/modules/precisoBidAdapter_spec.js delete mode 100644 test/spec/modules/prismaBidAdapter_spec.js delete mode 100644 test/spec/modules/programmaticXBidAdapter_spec.js delete mode 100644 test/spec/modules/programmaticaBidAdapter_spec.js delete mode 100644 test/spec/modules/proxistoreBidAdapter_spec.js delete mode 100644 test/spec/modules/pstudioBidAdapter_spec.js delete mode 100644 test/spec/modules/pubCircleBidAdapter_spec.js delete mode 100644 test/spec/modules/pubgeniusBidAdapter_spec.js delete mode 100644 test/spec/modules/publirBidAdapter_spec.js delete mode 100755 test/spec/modules/pubmaticAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/pubmaticBidAdapter_spec.js delete mode 100644 test/spec/modules/pubmaticRtdProvider_spec.js delete mode 100644 test/spec/modules/pubperfAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/pubriseBidAdapter_spec.js delete mode 100644 test/spec/modules/pubstackAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/pubwiseAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/pubxBidAdapter_spec.js delete mode 100644 test/spec/modules/pubxaiAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/pubxaiRtdProvider_spec.js delete mode 100644 test/spec/modules/pulsepointBidAdapter_spec.js delete mode 100644 test/spec/modules/pwbidBidAdapter_spec.js delete mode 100644 test/spec/modules/pxyzBidAdapter_spec.js delete mode 100644 test/spec/modules/qortexRtdProvider_spec.js delete mode 100644 test/spec/modules/qtBidAdapter_spec.js delete mode 100644 test/spec/modules/quantcastBidAdapter_spec.js delete mode 100644 test/spec/modules/qwarryBidAdapter_spec.js delete mode 100644 test/spec/modules/r2b2BidAdapter_spec.js delete mode 100644 test/spec/modules/rakutenBidAdapter_spec.js delete mode 100644 test/spec/modules/raveltechRtdProvider_spec.js delete mode 100644 test/spec/modules/raynRtdProvider_spec.js delete mode 100644 test/spec/modules/readpeakBidAdapter_spec.js delete mode 100644 test/spec/modules/reconciliationRtdProvider_spec.js delete mode 100644 test/spec/modules/rediadsBidAdapter_spec.js delete mode 100644 test/spec/modules/redtramBidAdapter_spec.js delete mode 100644 test/spec/modules/relaidoBidAdapter_spec.js delete mode 100644 test/spec/modules/relayBidAdapter_spec.js delete mode 100644 test/spec/modules/relevadRtdProvider_spec.js delete mode 100644 test/spec/modules/relevantAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/relevantdigitalBidAdapter_spec.js delete mode 100644 test/spec/modules/relevatehealthBidAdapter_spec.js delete mode 100644 test/spec/modules/resetdigitalBidAdapter_spec.js delete mode 100644 test/spec/modules/responsiveAdsBidAdapter_spec.js delete mode 100644 test/spec/modules/retailspotBidAdapter_spec.js delete mode 100644 test/spec/modules/revcontentBidAdapter_spec.js delete mode 100644 test/spec/modules/rhythmoneBidAdapter_spec.js delete mode 100644 test/spec/modules/richaudienceBidAdapter_spec.js delete mode 100644 test/spec/modules/ringieraxelspringerBidAdapter_spec.js delete mode 100644 test/spec/modules/riseBidAdapter_spec.js delete mode 100644 test/spec/modules/risemediatechBidAdapter_spec.js delete mode 100644 test/spec/modules/rivrAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/rixengineBidAdapter_spec.js delete mode 100644 test/spec/modules/robustAppsBidAdapter_spec.js delete mode 100644 test/spec/modules/robustaBidAdapter_spec.js delete mode 100644 test/spec/modules/rocketlabBidAdapter_spec.js delete mode 100644 test/spec/modules/roxotAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/rtbhouseBidAdapter_spec.js delete mode 100644 test/spec/modules/rtbsapeBidAdapter_spec.js delete mode 100644 test/spec/modules/rubiconBidAdapter_spec.js delete mode 100644 test/spec/modules/rumbleBidAdapter_spec.js delete mode 100644 test/spec/modules/scaleableAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/scatteredBidAdapter_spec.js delete mode 100644 test/spec/modules/scope3RtdProvider_spec.js delete mode 100644 test/spec/modules/seedtagBidAdapter_spec.js delete mode 100644 test/spec/modules/semantiqRtdProvider_spec.js delete mode 100644 test/spec/modules/setupadBidAdapter_spec.js delete mode 100644 test/spec/modules/sevioBidAdapter_spec.js delete mode 100644 test/spec/modules/sharethroughBidAdapter_spec.js delete mode 100644 test/spec/modules/shinezBidAdapter_spec.js delete mode 100644 test/spec/modules/shinezRtbBidAdapter_spec.js delete mode 100644 test/spec/modules/showheroes-bsBidAdapter_spec.js delete mode 100644 test/spec/modules/silvermobBidAdapter_spec.js delete mode 100644 test/spec/modules/silverpushBidAdapter_spec.js delete mode 100644 test/spec/modules/sirdataRtdProvider_spec.js delete mode 100644 test/spec/modules/slimcutBidAdapter_spec.js delete mode 100644 test/spec/modules/smaatoBidAdapter_spec.js delete mode 100644 test/spec/modules/smartadserverBidAdapter_spec.js delete mode 100644 test/spec/modules/smarthubBidAdapter_spec.js delete mode 100644 test/spec/modules/smarticoBidAdapter_spec.js delete mode 100644 test/spec/modules/smartxBidAdapter_spec.js delete mode 100644 test/spec/modules/smartyadsAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/smartyadsBidAdapter_spec.js delete mode 100644 test/spec/modules/smartytechBidAdapter_spec.js delete mode 100644 test/spec/modules/smilewantedBidAdapter_spec.js delete mode 100644 test/spec/modules/smootBidAdapter_spec.js delete mode 100644 test/spec/modules/snigelBidAdapter_spec.js delete mode 100644 test/spec/modules/sonaradsBidAdapter_spec.js delete mode 100644 test/spec/modules/sonobiBidAdapter_spec.js delete mode 100644 test/spec/modules/sovrnBidAdapter_spec.js delete mode 100644 test/spec/modules/sparteoBidAdapter_spec.js delete mode 100644 test/spec/modules/ssmasBidAdapter_spec.js delete mode 100644 test/spec/modules/sspBCBidAdapter_spec.js delete mode 100644 test/spec/modules/ssp_genieeBidAdapter_spec.js delete mode 100644 test/spec/modules/stackadaptBidAdapter_spec.js delete mode 100644 test/spec/modules/startioBidAdapter_spec.js delete mode 100644 test/spec/modules/stnBidAdapter_spec.js delete mode 100644 test/spec/modules/stroeerCoreBidAdapter_spec.js delete mode 100644 test/spec/modules/stvBidAdapter_spec.js delete mode 100644 test/spec/modules/sublimeBidAdapter_spec.js delete mode 100644 test/spec/modules/suimBidAdapter_spec.js delete mode 100644 test/spec/modules/symitriAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/symitriDapRtdProvider_spec.js delete mode 100644 test/spec/modules/taboolaBidAdapter_spec.js delete mode 100644 test/spec/modules/tadvertisingBidAdapter_spec.js delete mode 100644 test/spec/modules/tagorasBidAdapter_spec.js delete mode 100644 test/spec/modules/talkadsBidAdapter_spec.js delete mode 100644 test/spec/modules/tapnativeBidAdapter_spec.js delete mode 100644 test/spec/modules/tappxBidAdapter_spec.js delete mode 100644 test/spec/modules/targetVideoBidAdapter_spec.js delete mode 100644 test/spec/modules/teadsBidAdapter_spec.js delete mode 100644 test/spec/modules/tealBidAdapter_spec.js delete mode 100644 test/spec/modules/temedyaBidAdapter_spec.js delete mode 100644 test/spec/modules/terceptAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/theAdxBidAdapter_spec.js delete mode 100644 test/spec/modules/themoneytizerBidAdapter_spec.js delete mode 100644 test/spec/modules/timeoutRtdProvider_spec.js delete mode 100644 test/spec/modules/tpmnBidAdapter_spec.js delete mode 100644 test/spec/modules/trafficgateBidAdapter_spec.js delete mode 100644 test/spec/modules/trionBidAdapter_spec.js delete mode 100644 test/spec/modules/tripleliftBidAdapter_spec.js delete mode 100644 test/spec/modules/truereachBidAdapter_spec.js delete mode 100644 test/spec/modules/ttdBidAdapter_spec.js delete mode 100644 test/spec/modules/twistDigitalBidAdapter_spec.js delete mode 100644 test/spec/modules/ucfunnelAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/ucfunnelBidAdapter_spec.js delete mode 100644 test/spec/modules/underdogmediaBidAdapter_spec.js delete mode 100644 test/spec/modules/undertoneBidAdapter_spec.js delete mode 100644 test/spec/modules/unicornBidAdapter_spec.js delete mode 100644 test/spec/modules/uniquestAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/uniquestBidAdapter_spec.js delete mode 100644 test/spec/modules/unrulyBidAdapter_spec.js delete mode 100644 test/spec/modules/valuadBidAdapter_spec.js delete mode 100644 test/spec/modules/vdoaiBidAdapter_spec.js delete mode 100644 test/spec/modules/ventesBidAdapter_spec.js delete mode 100644 test/spec/modules/viantBidAdapter_spec.js delete mode 100644 test/spec/modules/vibrantmediaBidAdapter_spec.js delete mode 100644 test/spec/modules/vidazooBidAdapter_spec.js delete mode 100644 test/spec/modules/videobyteBidAdapter_spec.js delete mode 100644 test/spec/modules/videoheroesBidAdapter_spec.js delete mode 100644 test/spec/modules/videonowBidAdapter_spec.js delete mode 100644 test/spec/modules/videoreachBidAdapter_spec.js delete mode 100644 test/spec/modules/vidoomyBidAdapter_spec.js delete mode 100644 test/spec/modules/viewdeosDXBidAdapter_spec.js delete mode 100644 test/spec/modules/viqeoBidAdapter_spec.js delete mode 100644 test/spec/modules/visiblemeasuresBidAdapter_spec.js delete mode 100644 test/spec/modules/vistarsBidAdapter_spec.js delete mode 100755 test/spec/modules/visxBidAdapter_spec.js delete mode 100644 test/spec/modules/vlybyBidAdapter_spec.js delete mode 100644 test/spec/modules/voxBidAdapter_spec.js delete mode 100644 test/spec/modules/vrtcalBidAdapter_spec.js delete mode 100644 test/spec/modules/vuukleBidAdapter_spec.js delete mode 100644 test/spec/modules/waardexBidAdapter_spec.js delete mode 100644 test/spec/modules/weboramaRtdProvider_spec.js delete mode 100644 test/spec/modules/welectBidAdapter_spec.js delete mode 100644 test/spec/modules/widespaceBidAdapter_spec.js delete mode 100644 test/spec/modules/winrBidAdapter_spec.js delete mode 100644 test/spec/modules/wipesBidAdapter_spec.js delete mode 100644 test/spec/modules/wurflRtdProvider_spec.js delete mode 100644 test/spec/modules/xeBidAdapter_spec.js delete mode 100644 test/spec/modules/yahooAdsBidAdapter_spec.js delete mode 100644 test/spec/modules/yandexAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/yandexBidAdapter_spec.js delete mode 100644 test/spec/modules/yieldlabBidAdapter_spec.js delete mode 100644 test/spec/modules/yieldliftBidAdapter_spec.js delete mode 100644 test/spec/modules/yieldloveBidAdapter_spec.js delete mode 100644 test/spec/modules/yieldmoBidAdapter_spec.js delete mode 100644 test/spec/modules/yieldoneAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/yieldoneBidAdapter_spec.js delete mode 100644 test/spec/modules/yuktamediaAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/zeta_globalBidAdapter_spec.js delete mode 100644 test/spec/modules/zeta_global_sspAnalyticsAdapter_spec.js delete mode 100644 test/spec/modules/zeta_global_sspBidAdapter_spec.js delete mode 100644 test/spec/modules/zmaticooBidAdapter_spec.js diff --git a/karma.conf.maker.js b/karma.conf.maker.js index ce7110def..99817022d 100644 --- a/karma.conf.maker.js +++ b/karma.conf.maker.js @@ -98,18 +98,14 @@ function setBrowsers(karmaConf, browserstack) { karmaConf.browsers = Object.keys(karmaConf.customLaunchers); } else { var isDocker = require('is-docker')(); - if (isDocker) { - karmaConf.customLaunchers = karmaConf.customLaunchers || {}; - karmaConf.customLaunchers.ChromeCustom = { - base: 'ChromeHeadless', - // We must disable the Chrome sandbox when running Chrome inside Docker (Chrome's sandbox needs - // more permissions than Docker allows by default) - flags: ['--no-sandbox'] - } - karmaConf.browsers = ['ChromeCustom']; - } else { - karmaConf.browsers = ['ChromeHeadless']; + karmaConf.customLaunchers = karmaConf.customLaunchers || {}; + karmaConf.customLaunchers.ChromeCustom = { + base: 'ChromeHeadless', + // We must disable the Chrome sandbox when running Chrome inside Docker (Chrome's sandbox needs + // more permissions than Docker allows by default) + flags: ['--no-sandbox'] } + karmaConf.browsers = ['ChromeCustom']; } } diff --git a/modules/utiqIdSystem.js b/modules/utiqIdSystem.js index f9790713f..972ba1dc1 100644 --- a/modules/utiqIdSystem.js +++ b/modules/utiqIdSystem.js @@ -153,5 +153,5 @@ export const utiqIdSubmodule = { } }; -findUtiqService(storage, window.pbjs.refreshUserIds, LOG_PREFIX, MODULE_NAME); +findUtiqService(storage, window.oajs.refreshUserIds, LOG_PREFIX, MODULE_NAME); submodule('userId', utiqIdSubmodule); diff --git a/modules/utiqMtpIdSystem.js b/modules/utiqMtpIdSystem.js index 03f06f449..fb00b1492 100644 --- a/modules/utiqMtpIdSystem.js +++ b/modules/utiqMtpIdSystem.js @@ -140,5 +140,5 @@ export const utiqMtpIdSubmodule = { } }; -findUtiqService(storage, window.pbjs.refreshUserIds, LOG_PREFIX, MODULE_NAME); +findUtiqService(storage, window.oajs.refreshUserIds, LOG_PREFIX, MODULE_NAME); submodule('userId', utiqMtpIdSubmodule); diff --git a/test/spec/modules/1plusXRtdProvider_spec.js b/test/spec/modules/1plusXRtdProvider_spec.js deleted file mode 100644 index b971fda65..000000000 --- a/test/spec/modules/1plusXRtdProvider_spec.js +++ /dev/null @@ -1,470 +0,0 @@ -import assert from 'assert'; -import {config} from 'src/config'; -import { - buildOrtb2Updates, - extractConfig, - extractConsent, - extractFpid, - getPapiUrl, - onePlusXSubmodule, - segtaxes, - setTargetingDataToConfig, - updateBidderConfig, -} from 'modules/1plusXRtdProvider'; -import {deepClone} from '../../../src/utils.js'; -import { STORAGE_TYPE_COOKIES, STORAGE_TYPE_LOCALSTORAGE } from 'src/storageManager.js'; -import { server } from 'test/mocks/xhr.js'; - -describe('1plusXRtdProvider', () => { - // Fake server config - const fakeResponseHeaders = { - 'Content-Type': 'application/json', - 'Access-Control-Allow-Origin': '*' - }; - const fakeResponse = { - s: ['segment1', 'segment2', 'segment3'], - t: ['targeting1', 'targeting2', 'targeting3'] - }; - - // Bid request config - const reqBidsConfigObj = { - adUnits: [{ - bids: [ - { bidder: 'appnexus' } - ] - }] - }; - - // Bidder configs - const bidderConfigInitial = { - user: { keywords: '' }, - site: { ext: {} } - } - const bidderConfigInitialWith1plusXUserData = { - user: { - data: [{ name: '1plusX.com', segment: [{ id: 'initial' }] }] - }, - site: { content: { data: [] } } - } - const bidderConfigInitialWithUserData = { - user: { - data: [{ name: 'hello.world', segment: [{ id: 'initial' }] }] - }, - site: { content: { data: [] } } - } - const bidderConfigInitialWith1plusXSiteContent = { - user: { data: [] }, - site: { - content: { - data: [{ - name: '1plusX.com', segment: [{ id: 'initial' }], ext: { segtax: 525 } - }] - } - } - } - const bidderConfigInitialWithSiteContent = { - user: { data: [] }, - site: { - content: { - data: [{ name: 'hello.world', segment: [{ id: 'initial' }] }] - } - } - } - // Util functions - const randomBidder = (len = 5) => Math.random().toString(36).replace(/[^a-z]+/g, '').substring(0, len); - - before(() => { - config.resetConfig(); - }) - - after(() => { }) - - beforeEach(() => { - server.respondWith('GET', '*', [200, fakeResponseHeaders, JSON.stringify(fakeResponse)]); - }) - - describe('onePlusXSubmodule', () => { - it('init is successfull', () => { - const initResult = onePlusXSubmodule.init(); - expect(initResult).to.be.true; - }) - - it('callback is called after getBidRequestData', () => { - // Nice case; everything runs as expected - { - const callbackSpy = sinon.spy(); - const config = { params: { customerId: 'test', bidders: ['appnexus'] } }; - onePlusXSubmodule.getBidRequestData(reqBidsConfigObj, callbackSpy, config); - server.respond(); - setTimeout(() => { - expect(callbackSpy.calledOnce).to.be.true - }, 100) - } - // No customer id in config => error but still callback called - { - const callbackSpy = sinon.spy(); - const config = {} - onePlusXSubmodule.getBidRequestData(reqBidsConfigObj, callbackSpy, config); - server.respond(); - setTimeout(() => { - expect(callbackSpy.calledOnce).to.be.true - }, 100); - } - // No bidders in config => error but still callback called - { - const callbackSpy = sinon.spy(); - const config = { customerId: 'test' } - onePlusXSubmodule.getBidRequestData(reqBidsConfigObj, callbackSpy, config); - server.respond(); - setTimeout(() => { - expect(callbackSpy.calledOnce).to.be.true - }, 100); - } - }) - }) - - describe('extractConfig', () => { - const customerId = 'test'; - const timeout = 1000; - const bidders = ['appnexus']; - const fpidStorageType = STORAGE_TYPE_LOCALSTORAGE - - it('Throws an error if no customerId is specified', () => { - const moduleConfig = { params: { timeout, bidders } }; - expect(() => extractConfig(moduleConfig, reqBidsConfigObj)).to.throw(); - }) - it('Throws an error if no bidder is specified', () => { - const moduleConfig = { params: { customerId, timeout } }; - expect(() => extractConfig(moduleConfig, reqBidsConfigObj)).to.throw(); - }) - it("Throws an error if there's no bidder in reqBidsConfigObj", () => { - const moduleConfig = { params: { customerId, timeout, bidders } }; - const reqBidsConfigEmpty = { adUnits: [{ bids: [] }] }; - expect(() => extractConfig(moduleConfig, reqBidsConfigEmpty)).to.throw(); - }) - it('Returns an object containing the parameters specified', () => { - const moduleConfig = { params: { customerId, timeout, bidders, fpidStorageType } }; - const expectedKeys = ['customerId', 'timeout', 'bidders', 'fpidStorageType'] - const extractedConfig = extractConfig(moduleConfig, reqBidsConfigObj); - expect(extractedConfig).to.be.an('object').and.to.have.all.keys(expectedKeys); - expect(extractedConfig.customerId).to.equal(customerId); - expect(extractedConfig.timeout).to.equal(timeout); - expect(extractedConfig.bidders).to.deep.equal(bidders); - expect(extractedConfig.fpidStorageType).to.equal(fpidStorageType) - }) - /* 1plusX RTD module may only use bidders that are both specified in : - - the bid request configuration - - AND in the 1plusX RTD module configuration - Below 2 tests are enforcing those rules - */ - it('Returns the intersection of bidders found in bid request config & module config', () => { - const bidders = ['appnexus', 'rubicon']; - const moduleConfig = { params: { customerId, timeout, bidders } }; - const { bidders: extractedBidders } = extractConfig(moduleConfig, reqBidsConfigObj); - expect(extractedBidders).to.be.an('array').and.to.have.length(1); - expect(extractedBidders[0]).to.equal('appnexus'); - }) - it('Throws an error if no bidder can be used by the module', () => { - const bidders = ['rubicon']; - const moduleConfig = { params: { customerId, timeout, bidders } }; - expect(() => extractConfig(moduleConfig, reqBidsConfigObj)).to.throw(); - }) - it('Throws an error if wrong fpidStorageType is provided', () => { - const moduleConfig = { params: { customerId, timeout, bidders, fpidStorageType: 'bogus' } }; - expect(() => extractConfig(moduleConfig, reqBidsConfigObj).to.throw()) - }) - it('Defaults fpidStorageType to localStorage', () => { - const moduleConfig = { params: { customerId, timeout, bidders } }; - const extractedConfig = extractConfig(moduleConfig, reqBidsConfigObj); - expect(extractedConfig.fpidStorageType).to.equal(STORAGE_TYPE_LOCALSTORAGE) - }) - it('Correctly instantiates fpidStorageType to cookie store if instructed', () => { - const moduleConfig = { params: { customerId, timeout, bidders, fpidStorageType: STORAGE_TYPE_COOKIES } }; - const extractedConfig = extractConfig(moduleConfig, reqBidsConfigObj); - expect(extractedConfig.fpidStorageType).to.equal(STORAGE_TYPE_COOKIES) - }) - }) - - describe('buildOrtb2Updates', () => { - it('fills site.content.data & user.data in the ortb2 config', () => { - const rtdData = { segments: fakeResponse.s, topics: fakeResponse.t }; - const ortb2Updates = buildOrtb2Updates(rtdData, randomBidder()); - - const expectedOutput = { - siteContentData: { - name: '1plusX.com', - segment: rtdData.topics.map((topicId) => ({ id: topicId })), - ext: { segtax: segtaxes.CONTENT } - }, - userData: { - name: '1plusX.com', - segment: rtdData.segments.map((segmentId) => ({ id: segmentId })), - ext: { segtax: segtaxes.AUDIENCE } - } - } - expect([ortb2Updates]).to.deep.include.members([expectedOutput]); - }); - - it('defaults to empty array if no segment is given', () => { - const rtdData = { topics: fakeResponse.t }; - const ortb2Updates = buildOrtb2Updates(rtdData, randomBidder()); - - const expectedOutput = { - siteContentData: { - name: '1plusX.com', - segment: rtdData.topics.map((topicId) => ({ id: topicId })), - ext: { segtax: segtaxes.CONTENT } - }, - userData: { - name: '1plusX.com', - segment: [], - ext: { segtax: segtaxes.AUDIENCE } - } - } - expect(ortb2Updates).to.deep.include(expectedOutput); - }) - - it('defaults to empty array if no topic is given', () => { - const rtdData = { segments: fakeResponse.s }; - const ortb2Updates = buildOrtb2Updates(rtdData, randomBidder()); - - const expectedOutput = { - siteContentData: { - name: '1plusX.com', - segment: [], - ext: { segtax: segtaxes.CONTENT } - }, - userData: { - name: '1plusX.com', - segment: rtdData.segments.map((segmentId) => ({ id: segmentId })), - ext: { segtax: segtaxes.AUDIENCE } - }, - } - expect(ortb2Updates, `${JSON.stringify(ortb2Updates, null, 2)}`).to.deep.include(expectedOutput); - }) - }) - - describe('extractConsent', () => { - it('extracts consent strings correctly if given', () => { - const consent = { - gdpr: { - gdprApplies: 1, - consentString: 'myConsent' - } - } - const output = extractConsent(consent) - const expectedOutput = { - gdpr_applies: 1, - consent_string: 'myConsent' - } - expect(expectedOutput).to.deep.include(output) - expect(output).to.deep.include(expectedOutput) - }) - - it('extracts null if consent object is empty', () => { - const consent1 = {} - expect(extractConsent(consent1)).to.equal(null) - }) - - it('returns null if the consent is malformed', () => { - const consent1 = { - gdpr: { - consentString: 'myConsent' - } - } - const consent2 = { - gdpr: { - gdprApplies: 1, - consentString: 3 - } - } - const consent3 = { - gdpr: { - gdprApplies: 'yes', - consentString: 'myConsent' - } - } - const consent4 = { - gdpr: {} - } - - for (const consent of [consent1, consent2, consent3, consent4]) { - expect(extractConsent(consent)).to.be.null - } - }) - }) - - describe('getPapiUrl', () => { - const customer = 'acme' - const consent = { - gdpr: { - gdprApplies: 1, - consentString: 'myConsent' - } - } - - it('correctly builds URLs if gdpr parameters are present', () => { - const url1 = getPapiUrl(customer); - const url2 = getPapiUrl(customer, extractConsent(consent)); - expect(['&consent_string=myConsent&gdpr_applies=1', '&gdpr_applies=1&consent_string=myConsent']).to.contain(url2.replace(url1, '')); - }) - - it('correctly builds URLs if fpid parameters are present', () => { - const url1 = getPapiUrl(customer); - const url2 = getPapiUrl(customer, {}, 'my_first_party_id'); - expect(url2.replace(url1, '')).to.equal('&fpid=my_first_party_id'); - }) - }) - - describe('updateBidderConfig', () => { - const ortb2Updates = { - siteContentData: { - name: '1plusX.com', - segment: fakeResponse.t.map((topicId) => ({ id: topicId })), - ext: { segtax: segtaxes.CONTENT } - }, - userData: { - name: '1plusX.com', - segment: fakeResponse.s.map((segmentId) => ({ id: segmentId })) - }, - } - - it('merges fetched data in bidderConfig for configured bidders', () => { - // Set initial config - const bidder = randomBidder(); - const ortb2Fragments = { [bidder]: deepClone(bidderConfigInitial) } - // Call submodule's setBidderConfig - updateBidderConfig(bidder, ortb2Updates, ortb2Fragments); - const newBidderConfig = ortb2Fragments[bidder]; - // Check that the targeting data has been set in the config - expect(newBidderConfig).not.to.be.null.and.not.to.be.undefined; - expect(newBidderConfig.user).not.to.be.null.and.not.to.be.undefined; - expect(newBidderConfig.site).not.to.be.null.and.not.to.be.undefined; - expect(newBidderConfig.user.data).to.deep.include(ortb2Updates.userData); - expect(newBidderConfig.site.content.data).to.deep.include(ortb2Updates.siteContentData); - // Check that existing config didn't get erased - expect(newBidderConfig.site).to.deep.include(bidderConfigInitial.site); - expect(newBidderConfig.user).to.deep.include(bidderConfigInitial.user); - }) - - it('overwrites an existing 1plus.com entry in ortb2.user.data', () => { - // Set initial config - const bidder = randomBidder(); - const ortb2Fragments = { [bidder]: { ...bidderConfigInitialWith1plusXUserData } } - // Save previous user.data entry - const previousUserData = bidderConfigInitialWith1plusXUserData.user.data[0]; - // Call submodule's setBidderConfig - updateBidderConfig(bidder, ortb2Updates, ortb2Fragments); - const newBidderConfig = ortb2Fragments[bidder]; - // Check that the targeting data has been set in the config - expect(newBidderConfig).not.to.be.null; - expect(newBidderConfig.site).not.to.be.null; - expect(newBidderConfig.user).not.to.be.null; - expect(newBidderConfig.user.data).to.deep.include(ortb2Updates.userData); - expect(newBidderConfig.user.data).not.to.include(previousUserData); - }) - it("doesn't overwrite entries in ortb2.user.data that aren't 1plusx.com", () => { - // Set initial config - const bidder = randomBidder(); - const ortb2Fragments = { [bidder]: { ...bidderConfigInitialWithUserData } } - // Save previous user.data entry - const previousUserData = bidderConfigInitialWithUserData.user.data[0]; - // Call submodule's setBidderConfig - updateBidderConfig(bidder, ortb2Updates, ortb2Fragments); - const newBidderConfig = ortb2Fragments[bidder]; - // Check that the targeting data has been set in the config - expect(newBidderConfig).not.to.be.null; - expect(newBidderConfig.site).not.to.be.null; - expect(newBidderConfig.user).not.to.be.null; - expect(newBidderConfig.user.data).to.deep.include(ortb2Updates.userData); - expect(newBidderConfig.user.data).to.deep.include(previousUserData); - }) - - it('overwrites an existing 1plus.com entry in ortb2.site.content.data', () => { - // Set initial config - const bidder = randomBidder(); - const ortb2Fragments = { [bidder]: { ...bidderConfigInitialWith1plusXSiteContent } } - // Save previous user.data entry - const previousSiteContent = bidderConfigInitialWith1plusXSiteContent.site.content.data[0]; - // Call submodule's setBidderConfig - updateBidderConfig(bidder, ortb2Updates, ortb2Fragments); - const newBidderConfig = ortb2Fragments[bidder]; - // Check that the targeting data has been set in the config - expect(newBidderConfig).not.to.be.null; - expect(newBidderConfig.site).not.to.be.null; - expect(newBidderConfig.user).not.to.be.null; - expect(newBidderConfig.site.content.data).to.deep.include(ortb2Updates.siteContentData); - expect(newBidderConfig.site.content.data).not.to.include(previousSiteContent); - }) - it("doesn't overwrite entries in ortb2.site.content.data that aren't 1plusx.com", () => { - // Set initial config - const bidder = randomBidder(); - const ortb2Fragments = { [bidder]: { ...bidderConfigInitialWithSiteContent } } - // Save previous user.data entry - const previousSiteContent = bidderConfigInitialWithSiteContent.site.content.data[0]; - // Call submodule's setBidderConfig - updateBidderConfig(bidder, ortb2Updates, ortb2Fragments); - const newBidderConfig = ortb2Fragments[bidder]; - // Check that the targeting data has been set in the config - expect(newBidderConfig).not.to.be.null; - expect(newBidderConfig.site).not.to.be.null; - expect(newBidderConfig.user).not.to.be.null; - expect(newBidderConfig.site.content.data).to.deep.include(ortb2Updates.siteContentData); - expect(newBidderConfig.site.content.data).to.deep.include(previousSiteContent); - }) - }) - - describe('setTargetingDataToConfig', () => { - const expectedSiteContentObj = { - data: [{ - name: '1plusX.com', - segment: fakeResponse.t.map((topicId) => ({ id: topicId })), - ext: { segtax: segtaxes.CONTENT } - }] - } - const expectedUserObj = { - data: [{ - name: '1plusX.com', - segment: fakeResponse.s.map((segmentId) => ({ id: segmentId })), - ext: { segtax: segtaxes.AUDIENCE } - }] - } - const expectedOrtb2 = { - appnexus: { - site: { content: expectedSiteContentObj }, - user: expectedUserObj - }, - rubicon: { - site: { content: expectedSiteContentObj }, - user: expectedUserObj - } - } - - it('sets the config for the selected bidders', () => { - const bidders = ['appnexus', 'rubicon']; - // setting initial config for those bidders - config.setBidderConfig({ - bidders, - config: bidderConfigInitial - }) - const biddersOrtb2 = config.getBidderConfig(); - // call setTargetingDataToConfig - setTargetingDataToConfig(fakeResponse, { bidders, biddersOrtb2 }); - - // Check that the targeting data has been set in both configs - for (const bidder of bidders) { - const newConfig = config.getBidderConfig()[bidder]; - // Check that we got what we expect - const expectedConfErr = (prop) => `New config for ${bidder} doesn't comply with expected at ${prop}`; - expect(newConfig.site, expectedConfErr('site')).to.deep.include(expectedOrtb2[bidder].site); - if (expectedOrtb2[bidder].user) { - expect(newConfig.user, expectedConfErr('user')).to.deep.include(expectedOrtb2[bidder].user); - } - // Check that existing config didn't get erased - const existingConfErr = (prop) => `Existing config for ${bidder} got unlawfully overwritten at ${prop}`; - expect(newConfig.site, existingConfErr('site')).to.deep.include(bidderConfigInitial.site); - expect(newConfig.user, existingConfErr('user')).to.deep.include(bidderConfigInitial.user); - } - }) - }) -}) diff --git a/test/spec/modules/33acrossAnalyticsAdapter_spec.js b/test/spec/modules/33acrossAnalyticsAdapter_spec.js deleted file mode 100644 index b31117e00..000000000 --- a/test/spec/modules/33acrossAnalyticsAdapter_spec.js +++ /dev/null @@ -1,1162 +0,0 @@ -import analyticsAdapter, { log } from 'modules/33acrossAnalyticsAdapter.js'; - -import * as mockGpt from 'test/spec/integration/faker/googletag.js'; -import * as events from 'src/events.js'; -import * as faker from 'faker'; -import { EVENTS } from 'src/constants.js'; -import { gdprDataHandler, gppDataHandler, uspDataHandler } from '../../../src/adapterManager.js'; -import { DEFAULT_ENDPOINT, POST_GAM_TIMEOUT, locals } from '../../../modules/33acrossAnalyticsAdapter.js'; - -describe('33acrossAnalyticsAdapter:', function () { - let sandbox; - const assert = getLocalAssert(); - - beforeEach(function () { - mockGpt.reset(); - - sandbox = sinon.createSandbox({ - useFakeTimers: { - now: new Date(2023, 3, 3, 0, 1, 33, 425), - shouldClearNativeTimers: true - }, - }); - - sandbox.stub(events, 'getEvents').returns([]); - - sandbox.spy(log, 'info'); - sandbox.spy(log, 'warn'); - sandbox.spy(log, 'error'); - - sandbox.stub(navigator, 'sendBeacon').callsFake(function (url, data) { - const json = JSON.parse(data); - assert.isValidAnalyticsReport(json); - - return true; - }); - }); - - afterEach(function () { - analyticsAdapter.disableAnalytics(); - mockGpt.enable(); - sandbox.restore(); - }); - - describe('enableAnalytics:', function () { - context('When pid is given', function () { - context('but endpoint is not', function () { - it('uses the default endpoint', function () { - analyticsAdapter.enableAnalytics({ - options: { - pid: 'test-pid', - }, - }); - - assert.equal(analyticsAdapter.getUrl(), DEFAULT_ENDPOINT); - }); - }); - - context('but the endpoint is invalid', function () { - it('logs an info message', function () { - analyticsAdapter.enableAnalytics({ - options: { - pid: 'test-pid', - endpoint: 'foo' - }, - }); - - assert.calledWithExactly(log.info, 'Invalid endpoint provided for "options.endpoint". Using default endpoint.'); - }); - }); - }); - - context('When endpoint is given', function () { - context('but pid is not', function () { - it('logs an error message', function () { - analyticsAdapter.enableAnalytics({ - options: { - endpoint: faker.internet.url() - }, - }); - - assert.calledWithExactly(log.error, 'No partnerId provided for "options.pid". No analytics will be sent.'); - }); - }); - }); - - context('When pid and endpoint are given', function () { - context('and an invalid timeout config value is given', function () { - it('logs an info message', function () { - [null, 'foo', -1].forEach(timeout => { - analyticsAdapter.enableAnalytics({ - options: { - pid: 'test-pid', - endpoint: 'http://test-endpoint', - timeout - }, - }); - analyticsAdapter.disableAnalytics(); - - assert.calledWithExactly(log.info, 'Invalid timeout provided for "options.timeout". Using default timeout of 10000ms.'); - log.info.resetHistory(); - }); - }); - }); - }); - }); - - // check that upcoming tests are derived from a valid report - describe('Report Mocks', function () { - it('the report should have the correct format', function () { - assert.isValidAnalyticsReport(createReportWithThreeBidWonEvents()); - }); - }); - - describe('Event Handling', function () { - beforeEach(function () { - this.defaultTimeout = 10000; - this.enableAnalytics = (options) => { - analyticsAdapter.enableAnalytics({ - options: { - endpoint: 'http://test-endpoint', - pid: 'test-pid', - timeout: this.defaultTimeout, - ...options - }, - }); - window.googletag.cmd.forEach(cmd => cmd()); - } - }); - - context('when an auction is complete', function () { - context('and the AnalyticsReport is sent successfully to the given endpoint', function () { - it('calls "sendBeacon" with all won bids', function () { - const endpoint = faker.internet.url(); - this.enableAnalytics({ endpoint }); - - navigator.sendBeacon - .withArgs(endpoint, JSON.stringify(createReportWithThreeBidWonEvents())); - - performStandardAuction(); - sandbox.clock.tick(this.defaultTimeout + 1000); - - const [url, jsonString] = navigator.sendBeacon.firstCall.args; - const { auctions } = JSON.parse(jsonString); - - assert.lengthOf(mapToBids(auctions).filter(bid => bid.hasWon), 3); - }); - - it('calls "sendBeacon" with the correct report string', function () { - const endpoint = faker.internet.url(); - this.enableAnalytics({ endpoint }); - - navigator.sendBeacon - .withArgs(endpoint, JSON.stringify(createReportWithThreeBidWonEvents())); - - performStandardAuction(); - sandbox.clock.tick(this.defaultTimeout + 1000); - - assert.calledOnceWithStringJsonEquivalent(navigator.sendBeacon, endpoint, createReportWithThreeBidWonEvents()); - }); - - it('logs an info message containing the report', function () { - const endpoint = faker.internet.url(); - this.enableAnalytics({ endpoint }); - - navigator.sendBeacon - .withArgs(endpoint, JSON.stringify(createReportWithThreeBidWonEvents())) - .returns(true); - - performStandardAuction(); - sandbox.clock.tick(this.defaultTimeout + 1000); - - assert.calledWithExactly(log.info, `Analytics report sent to ${endpoint}`, createReportWithThreeBidWonEvents()); - }); - - it('calls "sendBeacon" as soon as all values are available (before timeout)', function () { - const endpoint = faker.internet.url(); - this.enableAnalytics({ endpoint }); - - navigator.sendBeacon - .withArgs(endpoint, JSON.stringify(createReportWithThreeBidWonEvents())); - - performStandardAuction(); - sandbox.clock.tick(1); - - assert.calledOnceWithStringJsonEquivalent(navigator.sendBeacon, endpoint, createReportWithThreeBidWonEvents()); - }); - }); - - context('and a valid US Privacy configuration is present', function () { - ['1YNY', '1---', '1NY-', '1Y--', '1--Y', '1N--', '1--N', '1NNN'].forEach(consent => { - it(`calls "sendBeacon" with a report containing the "${consent}" privacy string`, function () { - sandbox.stub(uspDataHandler, 'getConsentData').returns(consent); - this.enableAnalytics(); - - const reportWithConsent = { - ...createReportWithThreeBidWonEvents(), - usPrivacy: consent - }; - navigator.sendBeacon - .withArgs('http://test-endpoint', reportWithConsent); - - performStandardAuction(); - sandbox.clock.tick(this.defaultTimeout + 1000); - - assert.calledOnceWithStringJsonEquivalent(navigator.sendBeacon, 'http://test-endpoint', reportWithConsent); - }); - }); - }); - - context('and a GDPR Privacy configuration is present', function () { - it('it calls "sendBeacon" with a report containing the GDPR consent string', function () { - sandbox.stub(gdprDataHandler, 'getConsentData').returns({ - consentString: 'foo', - gdprApplies: true - }); - this.enableAnalytics(); - - const reportWithConsent = { - ...createReportWithThreeBidWonEvents(), - gdpr: 1, - gdprConsent: 'foo' - }; - navigator.sendBeacon - .withArgs('http://test-endpoint', reportWithConsent); - - performStandardAuction(); - sandbox.clock.tick(this.defaultTimeout + 1); - - assert.calledOnceWithStringJsonEquivalent(navigator.sendBeacon, 'http://test-endpoint', reportWithConsent); - }); - }); - }); - - context('when an auction is complete and a GPP configuration is present', function () { - it('it calls "sendBeacon" with a report containing the GPP consent string', function () { - sandbox.stub(gppDataHandler, 'getConsentData').returns({ - gppString: 'gppString', - applicableSections: [7] - }); - this.enableAnalytics(); - - const reportWithConsent = { - ...createReportWithThreeBidWonEvents(), - gpp: 'gppString', - gppSid: [7] - }; - navigator.sendBeacon - .withArgs('http://test-endpoint', reportWithConsent); - - performStandardAuction(); - sandbox.clock.tick(this.defaultTimeout + 1); - - assert.calledOnceWithStringJsonEquivalent(navigator.sendBeacon, 'http://test-endpoint', reportWithConsent); - }); - }); - - context('when an error occurs while sending the AnalyticsReport', function () { - it('logs an error', function () { - this.enableAnalytics(); - navigator.sendBeacon.returns(false); - - performStandardAuction(); - sandbox.clock.tick(this.defaultTimeout + 1000); - - assert.calledWithExactly(log.error, 'Analytics report exceeded User-Agent data limits and was not sent.', createReportWithThreeBidWonEvents()); - }); - }); - - context('when an auction report was already sent', function () { - context('and a new bid won event is returned after the report completes', function () { - it('finishes the auction without error', function () { - const incompleteAnalyticsReport = createReportWithThreeBidWonEvents(); - incompleteAnalyticsReport.auctions.forEach(auction => { - auction.adUnits.forEach(adUnit => { - adUnit.bids.forEach(bid => { - delete bid.bidResponse; - bid.hasWon = 0; - bid.status = 'pending'; - }); - }); - }); - - this.enableAnalytics(); - const { prebid: [auction] } = getMockEvents(); - - events.emit(EVENTS.AUCTION_INIT, auction.AUCTION_INIT); - for (const bidRequestedEvent of auction.BID_REQUESTED) { - events.emit(EVENTS.BID_REQUESTED, bidRequestedEvent); - }; - - sandbox.clock.tick(this.defaultTimeout + 1000); - - for (const bidResponseEvent of auction.BID_RESPONSE) { - events.emit(EVENTS.BID_RESPONSE, bidResponseEvent); - }; - for (const bidWonEvent of auction.BID_WON) { - events.emit(EVENTS.BID_WON, bidWonEvent); - }; - - events.emit(EVENTS.AUCTION_END, auction.AUCTION_END); - - sandbox.clock.tick(1); - - assert.calledOnceWithStringJsonEquivalent(navigator.sendBeacon, 'http://test-endpoint', incompleteAnalyticsReport); - }); - }); - - context('and another auction completes after that', function () { - it('sends the new report', function () { - const endpoint = faker.internet.url(); - this.enableAnalytics({ endpoint }); - - navigator.sendBeacon - .withArgs(endpoint, JSON.stringify(createReportWithThreeBidWonEvents())); - - performStandardAuction(); - sandbox.clock.tick(this.defaultTimeout + 1000); - - performStandardAuction(); - sandbox.clock.tick(this.defaultTimeout + 1000); - - assert.calledTwice(navigator.sendBeacon); - }); - }); - }); - - context('when two auctions overlap', function() { - it('sends a report for each auction', function () { - const endpoint = faker.internet.url(); - this.enableAnalytics({ endpoint }); - - navigator.sendBeacon - .withArgs(endpoint, JSON.stringify(createReportWithThreeBidWonEvents())); - - performStandardAuction(); - performStandardAuction(); - sandbox.clock.tick(this.defaultTimeout + 1000); - - assert.calledTwice(navigator.sendBeacon); - }); - }); - - context('when an AUCTION_END event is received before BID_WON events', function () { - it('sends a report with the bids that have won after all bids are won', function () { - const endpoint = faker.internet.url(); - this.enableAnalytics({ endpoint }); - - navigator.sendBeacon - .withArgs(endpoint, JSON.stringify(createReportWithThreeBidWonEvents())); - - const { prebid: [auction] } = getMockEvents(); - - performStandardAuction({ exclude: [EVENTS.BID_WON] }); - - assert.notCalled(navigator.sendBeacon); - for (const bidWon of auction.BID_WON) { - events.emit(EVENTS.BID_WON, bidWon); - } - assert.calledOnceWithStringJsonEquivalent(navigator.sendBeacon, endpoint, createReportWithThreeBidWonEvents()); - }); - }); - - context('when a BID_WON event is received', function () { - context('and there is no record of that bid being requested', function () { - it('logs a warning message', function () { - this.enableAnalytics(); - - const mockEvents = getMockEvents(); - const { prebid } = mockEvents; - const [auction] = prebid; - - events.emit(EVENTS.AUCTION_INIT, auction.AUCTION_INIT); - - const fakeBidWonEvent = Object.assign(auction.BID_WON[0], { - transactionId: 'foo' - }) - - events.emit(EVENTS.BID_WON, fakeBidWonEvent); - - const { auctionId, requestId } = fakeBidWonEvent; - assert.calledWithExactly(log.error, `Cannot find bid "${requestId}" in auction "${auctionId}".`); - }); - }); - }); - - context('when a BID_REJECTED event is received', function () { - it(`marks the rejected bid as "rejected"`, function () { - this.enableAnalytics(); - - const auction = getMockEvents().prebid[0]; - - // Start the auction - events.emit(EVENTS.AUCTION_INIT, auction.AUCTION_INIT); - for (const bidRequestedEvent of auction.BID_REQUESTED) { - events.emit(EVENTS.BID_REQUESTED, bidRequestedEvent); - }; - - // Reject first bid - const bidToReject = auction.BID_REQUESTED[0].bids[0]; - events.emit(EVENTS.BID_REJECTED, auction.BID_REJECTED[0]); - - // Accept remaining bids - for (let i = 1; i < auction.BID_RESPONSE.length; ++i) { - events.emit(EVENTS.BID_RESPONSE, auction.BID_RESPONSE[i]); - }; - - // Complete the auction - events.emit(EVENTS.AUCTION_END, auction.AUCTION_END); - - sandbox.clock.tick(this.defaultTimeout + 1); - - // Verify that we detected that the first bid was rejected - const expectedRejectedBid = JSON.parse(navigator.sendBeacon.firstCall.args[1]).auctions[0].adUnits[0].bids[0]; - assert.strictEqual(expectedRejectedBid.status, 'rejected'); - }); - }); - - context('when a transaction does not reach its complete state', function () { - context('and a timeout config value has been given', function () { - context('and the timeout value has elapsed', function () { - it('logs a warning', function () { - const timeout = 2000; - this.enableAnalytics({ timeout }); - - performStandardAuction({exclude: ['bidWon', 'slotRenderEnded', 'auctionEnd']}); - - sandbox.clock.tick(timeout + 1000); - - assert.calledWithExactly(log.warn, 'Timed out waiting for ad transactions to complete. Sending report.'); - }); - - it(`marks timed out bids as "timeout"`, function () { - const timeout = 2000; - this.enableAnalytics({ timeout }); - const request = getMockEvents().prebid[0].BID_REQUESTED[0]; - const bidToTimeout = request.bids[0]; - - performStandardAuction({exclude: ['bidWon', 'slotRenderEnded', 'auctionEnd']}); - sandbox.clock.tick(1); - events.emit(EVENTS.BID_TIMEOUT, [{ - auctionId: request.auctionId, - bidId: bidToTimeout.bidId, - transactionId: bidToTimeout.transactionId, - }]); - sandbox.clock.tick(timeout + 1000); - - const timeoutBid = JSON.parse(navigator.sendBeacon.firstCall.args[1]).auctions[0].adUnits[0].bids[0]; - assert.strictEqual(timeoutBid.status, 'timeout'); - }); - }); - }); - - context('and a timeout config value has not been given', function () { - context('and the default timeout has elapsed', function () { - it('logs an error', function () { - this.enableAnalytics(); - - performStandardAuction({exclude: ['bidWon', 'slotRenderEnded', 'auctionEnd']}); - - sandbox.clock.tick(this.defaultTimeout + 1000); - - assert.calledWithExactly(log.warn, 'Timed out waiting for ad transactions to complete. Sending report.'); - }); - }) - }); - - context('and the `slotRenderEnded` event fired for all bids, but not all bids have won', function () { - context('and the GAM slot IDs are configured as the ad unit codes', function () { - it('sends a report after the all `slotRenderEnded` events have fired and timed out', function () { - const timeout = POST_GAM_TIMEOUT + 2000; - this.enableAnalytics({ timeout }); - - performStandardAuction({exclude: ['bidWon', 'auctionEnd']}); - sandbox.clock.tick(POST_GAM_TIMEOUT + 1); - - assert.strictEqual(navigator.sendBeacon.callCount, 1); - }); - }); - - context('and the slot element IDs are configured as the ad unit codes', function () { - it('sends a report after the all `slotRenderEnded` events have fired and timed out', function () { - const timeout = POST_GAM_TIMEOUT + 2000; - this.enableAnalytics({ timeout }); - - performStandardAuction({exclude: ['bidWon', 'auctionEnd'], useSlotElementIds: true}); - sandbox.clock.tick(POST_GAM_TIMEOUT + 1); - - assert.strictEqual(navigator.sendBeacon.callCount, 1); - }); - }); - - it('does NOT send a report if not all `slotRenderEnded` events have timed out', function () { - const timeout = POST_GAM_TIMEOUT + 2000; - this.enableAnalytics({ timeout }); - - performStandardAuction({exclude: ['bidWon', 'auctionEnd']}); - sandbox.clock.tick(POST_GAM_TIMEOUT - 1); - - assert.strictEqual(navigator.sendBeacon.callCount, 0); - }); - }); - - context('and the `slotRenderEnded` event has fired for an unknown slot code', function () { - it('logs a warning message', function () { - this.enableAnalytics(); - - const { prebid: [auction], gam } = getMockEvents(); - auction.AUCTION_INIT.adUnits[0].code = 'INVALID_AD_UNIT_CODE'; - - const slotRenderEnded = gam.slotRenderEnded[0]; - events.emit(EVENTS.AUCTION_INIT, auction.AUCTION_INIT); - events.emit(EVENTS.BID_REQUESTED, auction.BID_REQUESTED[0]); - mockGpt.emitEvent('slotRenderEnded', slotRenderEnded); - - sandbox.clock.tick(POST_GAM_TIMEOUT + 1); - - assert.calledWithExactly(log.warn, - 'Could not find configured ad unit matching GAM render of slot:', - { slotName: `${adUnitCodes[0]} - ${adSlotElementIds[0]}` }); - }); - }); - - context('and the incomplete report has been sent successfully', function () { - it('sends a report string with any bids with rendered status set to hasWon: 1', function () { - navigator.sendBeacon.returns(true); - - this.enableAnalytics(); - - performStandardAuction({exclude: ['auctionEnd']}); - sandbox.clock.tick(this.defaultTimeout + 1000); - - const incompleteSentBid = JSON.parse(navigator.sendBeacon.firstCall.args[1]).auctions[0].adUnits[1].bids[0]; - assert.strictEqual(incompleteSentBid.hasWon, 1); - }); - - it('reports bids with only targetingSet status as hasWon: 0', function () { - navigator.sendBeacon.returns(true); - - this.enableAnalytics(); - - performStandardAuction({exclude: ['bidWon', 'auctionEnd']}); - sandbox.clock.tick(this.defaultTimeout + 1000); - - const incompleteSentBid = JSON.parse(navigator.sendBeacon.firstCall.args[1]).auctions[0].adUnits[1].bids[0]; - assert.strictEqual(incompleteSentBid.hasWon, 0); - }); - - it('logs an info message', function () { - navigator.sendBeacon.returns(true); - - const endpoint = faker.internet.url(); - this.enableAnalytics({ endpoint }); - - performStandardAuction({exclude: ['bidWon', 'auctionEnd']}); - sandbox.clock.tick(this.defaultTimeout + 1000); - - assert.calledWith(log.info, `Analytics report sent to ${endpoint}`); - }); - }); - }); - - context('when the transaction manager has open transactions', function () { - it('reports those transactions as pending', function () { - this.enableAnalytics(); - - const { prebid: [auction] } = getMockEvents(); - events.emit(EVENTS.AUCTION_INIT, auction.AUCTION_INIT); - events.emit(EVENTS.BID_REQUESTED, auction.BID_REQUESTED[0]); - - const manager = locals.transactionManagers[auction.AUCTION_INIT.auctionId]; - assert.equal(manager.status().pending.length, auction.BID_REQUESTED[0].bids.length); - }); - - context('and a single bidWon event has triggered', function () { - it('completes the transaction', function () { - this.enableAnalytics(); - - const { prebid: [auction] } = getMockEvents(); - events.emit(EVENTS.AUCTION_INIT, auction.AUCTION_INIT); - events.emit(EVENTS.BID_REQUESTED, auction.BID_REQUESTED[0]); - events.emit(EVENTS.BID_WON, auction.BID_WON[0]); - - const manager = locals.transactionManagers[auction.AUCTION_INIT.auctionId]; - assert.deepEqual({ - completed: manager.status().completed.length, - pending: manager.status().pending.length - }, { - completed: 1, - pending: auction.BID_REQUESTED[0].bids.length - 1 - }); - }); - }); - - context('and a single slotRenderEnded event has triggered', function () { - context('and the Google Ad Manager timeout has not elapsed', function () { - it('does NOT complete the transaction', function () { - this.enableAnalytics(); - - const { prebid: [auction], gam } = getMockEvents(); - const slotRenderEnded = gam.slotRenderEnded[0]; - events.emit(EVENTS.AUCTION_INIT, auction.AUCTION_INIT); - events.emit(EVENTS.BID_REQUESTED, auction.BID_REQUESTED[0]); - mockGpt.emitEvent('slotRenderEnded', slotRenderEnded); - - const manager = locals.transactionManagers[auction.AUCTION_INIT.auctionId]; - assert.deepEqual({ - completed: manager.status().completed.length, - pending: manager.status().pending.length - }, { - completed: 0, - pending: auction.BID_REQUESTED[0].bids.length - }); - }); - }); - - context('and the Google Ad Manager timeout has elapsed', function () { - it('completes the transaction', function () { - const timeout = POST_GAM_TIMEOUT + 2000; - this.enableAnalytics({timeout}); - - const { prebid: [auction], gam } = getMockEvents(); - const slotRenderEnded = gam.slotRenderEnded[0]; - events.emit(EVENTS.AUCTION_INIT, auction.AUCTION_INIT); - events.emit(EVENTS.BID_REQUESTED, auction.BID_REQUESTED[0]); - mockGpt.emitEvent('slotRenderEnded', slotRenderEnded); - - sandbox.clock.tick(POST_GAM_TIMEOUT + 1); - const manager = locals.transactionManagers[auction.AUCTION_INIT.auctionId]; - assert.deepEqual({ - completed: manager.status().completed.length, - pending: manager.status().pending.length - }, { - completed: 1, - pending: auction.BID_REQUESTED[0].bids.length - 1 - }); - }); - }); - }); - }); - }); -}); - -const adUnitCodes = ['/19968336/header-bid-tag-0', '/19968336/header-bid-tag-1', '/17118521/header-bid-tag-2']; -const adSlotElementIds = ['ad-slot-div-0', 'ad-slot-div-1', 'ad-slot-div-2']; - -function performStandardAuction({ exclude = [], useSlotElementIds = false } = {}) { - const mockEvents = getMockEvents(); - const { prebid, gam } = mockEvents; - const [auction] = prebid; - - if (!exclude.includes(EVENTS.AUCTION_INIT)) { - if (useSlotElementIds) { - // With this option, identify the ad units by slot element IDs instead of GAM paths - auction.AUCTION_INIT.adUnits.forEach((adUnit, i) => { - adUnit.code = adSlotElementIds[i]; - }); - } - events.emit(EVENTS.AUCTION_INIT, auction.AUCTION_INIT); - } - - if (!exclude.includes(EVENTS.BID_REQUESTED)) { - for (const bidRequestedEvent of auction.BID_REQUESTED) { - events.emit(EVENTS.BID_REQUESTED, bidRequestedEvent); - }; - } - - if (!exclude.includes(EVENTS.BID_RESPONSE)) { - for (const bidResponseEvent of auction.BID_RESPONSE) { - events.emit(EVENTS.BID_RESPONSE, bidResponseEvent); - }; - } - - if (!exclude.includes(EVENTS.AUCTION_END)) { - events.emit(EVENTS.AUCTION_END, auction.AUCTION_END); - } - - if (!exclude.includes('slotRenderEnded')) { - for (const gEvent of gam.slotRenderEnded) { - mockGpt.emitEvent('slotRenderEnded', gEvent); - } - } - - if (!exclude.includes(EVENTS.BID_WON)) { - for (const bidWonEvent of auction.BID_WON) { - events.emit(EVENTS.BID_WON, bidWonEvent); - }; - } -} - -function mapToBids(auctions) { - return auctions.flatMap( - auction => auction.adUnits.flatMap( - au => au.bids - ) - ); -} - -function getLocalAssert() { - function isValidAnalyticsReport(report) { - assert.containsAllKeys(report, ['analyticsVersion', 'pid', 'src', 'pbjsVersion', 'auctions']); - if ('usPrivacy' in report) { - assert.match(report.usPrivacy, /[0|1][Y|N|-]{3}/); - } - if ('gdpr' in report) { - assert.oneOf(report.gdpr, [0, 1]); - } - if (report.gdpr === 1) { - assert.isString(report.gdprConsent); - } - if ('gpp' in report) { - assert.isString(report.gpp); - assert.isArray(report.gppSid); - } - if ('coppa' in report) { - assert.oneOf(report.coppa, [0, 1]); - } - - assert.equal(report.analyticsVersion, '1.0.0'); - assert.isString(report.pid); - assert.isString(report.src); - assert.equal(report.pbjsVersion, '$prebid.version$'); - assert.isArray(report.auctions); - assert.isAbove(report.auctions.length, 0); - report.auctions.forEach(isValidAuction); - } - function isValidAuction(auction) { - assert.hasAllKeys(auction, ['adUnits', 'auctionId', 'userIds']); - assert.isArray(auction.adUnits); - assert.isString(auction.auctionId); - assert.isArray(auction.userIds); - auction.adUnits.forEach(isValidAdUnit); - } - function isValidAdUnit(adUnit) { - assert.hasAllKeys(adUnit, ['transactionId', 'adUnitCode', 'slotId', 'mediaTypes', 'sizes', 'bids']); - assert.isString(adUnit.transactionId); - assert.isString(adUnit.adUnitCode); - assert.isString(adUnit.slotId); - assert.isArray(adUnit.mediaTypes); - assert.isArray(adUnit.sizes); - assert.isArray(adUnit.bids); - adUnit.mediaTypes.forEach(isValidMediaType); - adUnit.sizes.forEach(isValidSizeString); - adUnit.bids.forEach(isValidBid); - } - function isValidBid(bid) { - assert.containsAllKeys(bid, ['bidder', 'bidId', 'source', 'status', 'hasWon']); - if ('bidResponse' in bid) { - isValidBidResponse(bid.bidResponse); - } - assert.isString(bid.bidder); - assert.isString(bid.bidId); - assert.isString(bid.source); - assert.oneOf(bid.status, ['pending', 'timeout', 'targetingSet', 'rendered', 'success', 'rejected', 'no-bid', 'error']); - assert.oneOf(bid.hasWon, [0, 1]); - } - function isValidBidResponse(bidResponse) { - assert.containsAllKeys(bidResponse, ['mediaType', 'size', 'cur', 'cpm', 'cpmFloor']); - if ('cpmOrig' in bidResponse) { - assert.isNumber(bidResponse.cpmOrig); - } - isValidMediaType(bidResponse.mediaType); - isValidSizeString(bidResponse.size); - assert.isString(bidResponse.cur); - assert.isNumber(bidResponse.cpm); - assert.isNumber(bidResponse.cpmFloor); - } - function isValidMediaType(mediaType) { - assert.oneOf(mediaType, ['banner', 'video', 'native']); - } - function isValidSizeString(size) { - assert.match(size, /[0-9]+x[0-9]+/); - } - - function calledOnceWithStringJsonEquivalent(sinonSpy, ...args) { - sinon.assert.calledOnce(sinonSpy); - args.forEach((arg, i) => { - const stubCallArgs = sinonSpy.firstCall.args[i] - - if (typeof arg === 'object') { - assert.deepEqual(JSON.parse(stubCallArgs), arg); - } else { - assert.strictEqual(stubCallArgs, arg); - } - }); - } - - sinon.assert.expose(assert, { prefix: '' }); - return { - ...assert, - calledOnceWithStringJsonEquivalent, - isValidAnalyticsReport, - isValidAuction, - isValidAdUnit, - isValidBid, - isValidBidResponse, - isValidMediaType, - isValidSizeString, - } -}; - -function createReportWithThreeBidWonEvents() { - return { - pid: 'test-pid', - src: 'pbjs', - analyticsVersion: '1.0.0', - pbjsVersion: '$prebid.version$', - auctions: [{ - adUnits: [{ - transactionId: 'ef947609-7b55-4420-8407-599760d0e373', - adUnitCode: adUnitCodes[0], - slotId: adUnitCodes[0], - mediaTypes: ['banner'], - sizes: ['300x250', '300x600'], - bids: [{ - bidder: 'bidder0', - bidId: '20661fc5fbb5d9b', - source: 'client', - status: 'rendered', - bidResponse: { - cpm: 1.5, - cur: 'USD', - cpmOrig: 1.5, - cpmFloor: 1, - mediaType: 'banner', - size: '300x250' - }, - hasWon: 1 - }] - }, { - transactionId: 'abab4423-d962-41aa-adc7-0681f686c330', - adUnitCode: adUnitCodes[1], - slotId: adUnitCodes[1], - mediaTypes: ['banner'], - sizes: ['728x90', '970x250'], - bids: [{ - bidder: 'bidder0', - bidId: '21ad295f40dd7ab', - source: 'client', - status: 'rendered', - bidResponse: { - cpm: 1.5, - cur: 'USD', - cpmOrig: 1.5, - cpmFloor: 1, - mediaType: 'banner', - size: '728x90' - }, - hasWon: 1 - }] - }, { - transactionId: 'b43e7487-0a52-4689-a0f7-d139d08b1f9f', - adUnitCode: adUnitCodes[2], - slotId: adUnitCodes[2], - mediaTypes: ['banner'], - sizes: ['300x250'], - bids: [{ - bidder: 'bidder0', - bidId: '22108ac7b778717', - source: 'client', - status: 'rendered', - bidResponse: { - cpm: 1.5, - cur: 'USD', - cpmOrig: 1.5, - cpmFloor: 1, - mediaType: 'banner', - size: '728x90' - }, - hasWon: 1 - }] - }], - auctionId: 'auction-000', - userIds: ['33acrossId'] - }], - }; -} - -function getMockEvents() { - const auctionId = 'auction-000'; - const userId = { - '33acrossId': { - envelope: 'v1.0014', - }, - }; - - return { - gam: { - slotRenderEnded: [ - { - serviceName: 'publisher_ads', - slot: mockGpt.makeSlot({ code: adUnitCodes[0], divId: adSlotElementIds[0] }), - isEmpty: true, - slotContentChanged: true, - size: null, - advertiserId: null, - campaignId: null, - creativeId: null, - creativeTemplateId: null, - labelIds: null, - lineItemId: null, - isBackfill: false, - }, - { - serviceName: 'publisher_ads', - slot: mockGpt.makeSlot({ code: adUnitCodes[1], divId: adSlotElementIds[1] }), - isEmpty: false, - slotContentChanged: true, - size: [1, 1], - advertiserId: 12345, - campaignId: 400000001, - creativeId: 6789, - creativeTemplateId: null, - labelIds: null, - lineItemId: 1011, - isBackfill: false, - yieldGroupIds: null, - companyIds: null, - }, - { - serviceName: 'publisher_ads', - slot: mockGpt.makeSlot({ code: adUnitCodes[2], divId: adSlotElementIds[2] }), - isEmpty: false, - slotContentChanged: true, - size: [728, 90], - advertiserId: 12346, - campaignId: 299999000, - creativeId: 6790, - creativeTemplateId: null, - labelIds: null, - lineItemId: 1012, - isBackfill: false, - yieldGroupIds: null, - companyIds: null, - }, - ], - }, - prebid: [{ - AUCTION_INIT: { - auctionId, - adUnits: [ - { - code: adUnitCodes[0], - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - }, - }, - bids: [ - { - bidder: 'bidder0', - userId, - }, - ], - sizes: [ - [300, 250], - [300, 600], - ], - transactionId: 'ef947609-7b55-4420-8407-599760d0e373', - ortb2Imp: { - ext: { - gpid: adUnitCodes[0], - }, - }, - }, - { - code: adUnitCodes[1], - mediaTypes: { - banner: { - sizes: [ - [728, 90], - [970, 250], - ], - }, - }, - bids: [ - { - bidder: 'bidder0', - userId, - }, - ], - sizes: [ - [728, 90], - [970, 250], - ], - transactionId: 'abab4423-d962-41aa-adc7-0681f686c330', - ortb2Imp: { - ext: { - gpid: adUnitCodes[1], - }, - }, - }, - { - code: adUnitCodes[2], - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - bids: [ - { - bidder: '33across', - userId, - }, - { - bidder: 'bidder0', - userId, - }, - ], - sizes: [[300, 250]], - transactionId: 'b43e7487-0a52-4689-a0f7-d139d08b1f9f', - ortb2Imp: { - ext: { - gpid: adUnitCodes[2], - }, - }, - }, - ], - bidderRequests: [ - { - bids: [ - { userId }, - ], - } - ], - }, - BID_REQUESTED: [ - { - auctionId, - bids: [ - { - bidder: 'bidder0', - transactionId: 'ef947609-7b55-4420-8407-599760d0e373', - bidId: '20661fc5fbb5d9b', - src: 'client', - }, - { - bidder: 'bidder0', - transactionId: 'abab4423-d962-41aa-adc7-0681f686c330', - bidId: '21ad295f40dd7ab', - src: 'client', - }, - { - bidder: 'bidder0', - transactionId: 'b43e7487-0a52-4689-a0f7-d139d08b1f9f', - bidId: '22108ac7b778717', - src: 'client', - }, - ], - }], - BID_RESPONSE: [{ - auctionId, - cpm: 1.5, - currency: 'USD', - floorData: { - floorValue: 1 - }, - mediaType: 'banner', - originalCpm: 1.5, - requestId: '20661fc5fbb5d9b', - size: '300x250', - source: 'client', - status: 'targetingSet' - }, - { - auctionId, - cpm: 1.5, - currency: 'USD', - floorData: { - floorValue: 1 - }, - mediaType: 'banner', - originalCpm: 1.5, - requestId: '21ad295f40dd7ab', - size: '728x90', - source: 'client', - status: 'targetingSet', - }, - { - auctionId, - cpm: 1.5, - currency: 'USD', - floorData: { - floorValue: 1 - }, - mediaType: 'banner', - originalCpm: 1.5, - requestId: '22108ac7b778717', - size: '728x90', - source: 'client', - status: 'targetingSet', - }], - BID_WON: [{ - auctionId, - cpm: 1.5, - currency: 'USD', - floorData: { - floorValue: 1 - }, - mediaType: 'banner', - originalCpm: 1.5, - requestId: '20661fc5fbb5d9b', - size: '300x250', - source: 'client', - status: 'rendered', - transactionId: 'ef947609-7b55-4420-8407-599760d0e373', - }, - { - auctionId, - cpm: 1.5, - currency: 'USD', - floorData: { - floorValue: 1 - }, - mediaType: 'banner', - originalCpm: 1.5, - requestId: '21ad295f40dd7ab', - size: '728x90', - source: 'client', - status: 'rendered', - transactionId: 'abab4423-d962-41aa-adc7-0681f686c330', - }, - { - auctionId, - cpm: 1.5, - currency: 'USD', - floorData: { - floorValue: 1 - }, - mediaType: 'banner', - originalCpm: 1.5, - requestId: '22108ac7b778717', - size: '728x90', - source: 'client', - status: 'rendered', - transactionId: 'b43e7487-0a52-4689-a0f7-d139d08b1f9f', - }], - BID_REJECTED: [{ - auctionId, - cpm: 1.5, - currency: 'USD', - floorData: { - floorValue: 2 - }, - mediaType: 'banner', - originalCpm: 1.5, - requestId: '20661fc5fbb5d9b', - width: 300, - height: 250, - source: 'client', - transactionId: 'ef947609-7b55-4420-8407-599760d0e373', - statusMessage: 'Bid available', - rejectionReason: 'Bid does not meet price floor', - }], - AUCTION_END: { - auctionId, - }, - }], - }; -} diff --git a/test/spec/modules/33acrossBidAdapter_spec.js b/test/spec/modules/33acrossBidAdapter_spec.js deleted file mode 100644 index 110a5655f..000000000 --- a/test/spec/modules/33acrossBidAdapter_spec.js +++ /dev/null @@ -1,2645 +0,0 @@ -import { expect } from 'chai'; - -import * as utils from 'src/utils.js'; -import { internal } from 'src/utils.js'; -import { config } from 'src/config.js'; - -import { spec } from 'modules/33acrossBidAdapter.js'; -import { resetWinDimensions } from '../../../src/utils.js'; - -function validateBuiltServerRequest(builtReq, expectedReq) { - expect(builtReq.url).to.equal(expectedReq.url); - expect(builtReq.options).to.deep.equal(expectedReq.options); - - const builtRequestData = JSON.parse(builtReq.data); - const expectedRequestData = JSON.parse(expectedReq.data); - - expectedRequestData.id = builtRequestData.id; // Copy the generated ID - - expect(builtRequestData).to.deep.equal(expectedRequestData) -} - -describe('33acrossBidAdapter:', function () { - const ZONE_ID = 'sample33xGUID123456789'; - const END_POINT = 'https://ssc.33across.com/api/v1/hb'; - - function TtxRequestBuilder(additionalAttributes = { - site: { id: ZONE_ID } - }) { - const ttxRequest = { - imp: [{ - id: 'b1' - }], - device: { - w: 1024, - h: 728, - ext: { - ttx: { - vp: { - w: 800, - h: 600 - } - } - }, - sua: { - browsers: [{ - brand: 'Google Chrome', - version: ['104', '0', '5112', '79'] - }], - platform: { - brand: 'macOS', - version: ['11', '6', '8'] - }, - mobile: 0 - } - }, - regs: { - gdpr: 0 - }, - ext: { - ttx: { - prebidStartedAt: 1, - caller: [{ - 'name': 'prebidjs', - 'version': '$prebid.version$' - }] - } - }, - test: 0, - ...additionalAttributes - }; - - this.addImp = (id = 'b2') => { - ttxRequest.imp.push({ id }); - - return this; - } - - this.withBanner = () => { - ttxRequest.imp.forEach((imp) => { - Object.assign(imp, { - banner: { - format: [ - { - w: 300, - h: 250 - }, - { - w: 728, - h: 90 - } - ], - ext: { - ttx: { - viewability: { - amount: 100 - } - } - } - } - }); - }); - return this; - }; - - this.withBannerSizes = this.withSizes = sizes => { - ttxRequest.imp.forEach((imp) => { - Object.assign(imp.banner, { format: sizes }); - }); - - return this; - }; - - this.withVideo = (params = {}) => { - ttxRequest.imp.forEach((imp) => { - Object.assign(imp, { - video: { - w: 300, - h: 250, - plcmt: 4, - ...params - } - }); - }); - - return this; - }; - - this.withViewability = (viewability, format = 'banner') => { - ttxRequest.imp.forEach((imp) => { - Object.assign(imp[format], { - ext: { - ttx: { viewability } - } - }); - }); - - return this; - }; - - this.withProduct = (prod = 'siab') => { - ttxRequest.imp.forEach((imp) => { - utils.mergeDeep(imp, { - ext: { - ttx: { - prod - } - } - }); - }); - - return this; - }; - - this.withGpid = (gpid) => { - ttxRequest.imp.forEach((imp) => { - utils.mergeDeep(imp, { - ext: { - gpid - } - }); - }); - - return this; - }; - - this.withGdprConsent = (consent, gdpr) => { - utils.mergeDeep(ttxRequest, { - user: { - consent - }, - regs: { - gdpr - } - }); - return this; - }; - - this.withUspConsent = (consent) => { - utils.mergeDeep(ttxRequest, { - regs: { - us_privacy: consent - } - }); - - return this; - }; - - this.withCoppa = coppaValue => { - Object.assign(ttxRequest.regs, { - coppa: coppaValue - }); - - return this; - }; - - this.withGppConsent = (consentString, applicableSections) => { - Object.assign(ttxRequest, { - regs: { - gdpr: 0, - gpp: consentString, - gpp_sid: applicableSections, - ...(ttxRequest.regs?.ext ? { ext: ttxRequest.regs.ext } : {}) - } - }); - - return this; - }; - - this.withSite = site => { - utils.mergeDeep(ttxRequest, { site }); - - return this; - }; - - this.withApp = app => { - utils.mergeDeep(ttxRequest, { app }); - - return this; - }; - - this.withDevice = (device) => { - utils.mergeDeep(ttxRequest, { device }); - - return this; - }; - - this.withPageUrl = pageUrl => { - Object.assign(ttxRequest.site, { - page: pageUrl - }); - - return this; - }; - - this.withReferer = referer => { - Object.assign(ttxRequest.site, { - ref: referer - }); - - return this; - }; - - this.withSchain = schain => { - Object.assign(ttxRequest, { - source: { - schain - } - }); - - return this; - }; - - this.withFloors = this.withFormatFloors = (mediaType, floors) => { - switch (mediaType) { - case 'banner': - const format = ttxRequest.imp[0].banner.format.map((fm, i) => { - return Object.assign(fm, { - ext: { - ttx: { - bidfloors: [ floors[i] ] - } - } - }) - }); - - ttxRequest.imp[0].banner.format = format; - break; - case 'video': - Object.assign(ttxRequest.imp[0].video, { - ext: { - ttx: { - bidfloors: floors - } - } - }); - break; - } - - return this; - }; - - this.withUserIds = (eids) => { - Object.assign(ttxRequest, { - user: { - eids - } - }); - - return this; - } - - this.build = () => ttxRequest; - } - - function ServerRequestBuilder() { - const serverRequest = { - 'method': 'POST', - 'url': `${END_POINT}?guid=${ZONE_ID}`, - 'data': null, - 'options': { - 'contentType': 'text/plain', - 'withCredentials': true - } - }; - - this.withData = data => { - serverRequest['data'] = JSON.stringify(data); - return this; - }; - - this.withUrl = url => { - serverRequest['url'] = url; - return this; - }; - - this.withOptions = options => { - serverRequest['options'] = options; - return this; - }; - - this.build = () => serverRequest; - } - - function BidRequestsBuilder() { - const bidRequests = [ - { - bidId: 'b1', - bidder: '33across', - bidderRequestId: 'b1a', - params: { - zoneId: ZONE_ID, - productId: 'siab' - }, - adUnitCode: 'div-id', - auctionId: 'r1', - mediaTypes: {}, - transactionId: 't1', - ortb2: { - device: { - sua: { - browsers: [{ - brand: 'Google Chrome', - version: ['104', '0', '5112', '79'] - }], - platform: { - brand: 'macOS', - version: ['11', '6', '8'] - }, - mobile: 0 - } - } - } - } - ]; - - this.addBid = (bidParams = {}) => { - bidRequests.push({ - bidId: 'b2', - bidder: '33across', - bidderRequestId: 'b1b', - params: { - zoneId: ZONE_ID, - productId: 'siab' - }, - adUnitCode: 'div-id', - auctionId: 'r1', - mediaTypes: {}, - transactionId: 't2', - ortb2: { - device: { - sua: { - browsers: [{ - brand: 'Google Chrome', - version: ['104', '0', '5112', '79'] - }], - platform: { - brand: 'macOS', - version: ['11', '6', '8'] - }, - model: '', - mobile: 0 - } - } - }, - ...bidParams - }); - - return this; - }; - - this.withBanner = () => { - bidRequests.forEach((bid) => { - bid.mediaTypes.banner = { - sizes: [ - [300, 250], - [728, 90] - ] - }; - }); - - return this; - }; - - this.withProduct = (prod) => { - bidRequests.forEach((bid) => { - bid.params.productId = prod; - }); - return this; - }; - - this.withVideo = (params) => { - bidRequests.forEach((bid) => { - bid.mediaTypes.video = { - playerSize: [[300, 250]], - context: 'outstream', - plcmt: 4, - ...params - }; - }); - - return this; - } - - this.withUserIds = (eids) => { - bidRequests.forEach((bid) => { - bid.userIdAsEids = eids; - }); - - return this; - }; - - this.build = () => bidRequests; - } - - beforeEach(function() { - const element = this.element = { - x: 0, - y: 0, - - width: 0, - height: 0, - - getBoundingClientRect: () => { - return { - width: element.width, - height: element.height, - - left: element.x, - top: element.y, - right: element.x + element.width, - bottom: element.y + element.height - }; - } - }; - this.win = { - parent: null, - document: { - visibilityState: 'visible', - documentElement: { - clientWidth: 800, - clientHeight: 600 - } - }, - innerWidth: 800, - innerHeight: 600 - }; - - this.sandbox = sinon.sandbox.create(); - this.sandbox.stub(Date, 'now').returns(1); - this.sandbox.stub(document, 'getElementById').returns(this.element); - this.sandbox.stub(internal, 'getWindowTop').returns(this.win); - this.sandbox.stub(internal, 'getWindowSelf').returns(this.win); - this.sandbox.stub(utils, 'getWindowTop').returns(this.win); - this.sandbox.stub(utils, 'getWindowSelf').returns(this.win); - - this.buildBannerBidRequests = ({ withVideoParams } = {}) => { - const bidRequestsBuilder = new BidRequestsBuilder(); - - return bidRequestsBuilder - .withBanner() - .build(); - } - - this.buildBidderRequest = (bidRequests, additionalProps) => { - const [ bidRequest ] = bidRequests; - - return utils.mergeDeep({ - ortb2: utils.mergeDeep({ - device: { - w: 1024, - h: 728 - } - }, bidRequest.ortb2), - }, additionalProps); - }; - - this.buildServerRequest = (data, url) => { - const serverRequestBuilder = new ServerRequestBuilder(); - - if (url) { - serverRequestBuilder.withUrl(url); - } - - return serverRequestBuilder - .withData(data) - .build(); - }; - }); - - afterEach(function() { - resetWinDimensions(); - this.sandbox.restore(); - }); - - describe('isBidRequestValid()', function() { - context('basic validation', function() { - it('returns true for valid bidder name values', function() { - const validBidderName = [ - '33across', - '33across_mgni' - ]; - - validBidderName.forEach((bidderName) => { - const bid = { - bidder: bidderName, - params: { - zoneId: 'sample33xGUID123456789' - } - }; - - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - }); - - it('returns true for valid guid values', function() { - // NOTE: We ignore whitespace at the start and end since - // in our experience these are common typos - const validGUIDs = [ - `${ZONE_ID}`, - `${ZONE_ID} `, - ` ${ZONE_ID}`, - ` ${ZONE_ID} ` - ]; - - validGUIDs.forEach((zoneId) => { - const bid = { - bidder: '33across', - params: { - zoneId - } - }; - - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - - // GUID specified via the DEPRECATED siteID parameter - validGUIDs.forEach((siteId) => { - const bid = { - bidder: '33across', - params: { - siteId - } - }; - - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - }); - - it('returns false for invalid guid values', function() { - const invalidGUIDs = [ - undefined, - 'siab' - ]; - - invalidGUIDs.forEach((zoneId) => { - const bid = { - bidder: '33across', - params: { - zoneId - } - }; - - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - invalidGUIDs.forEach((siteId) => { - const bid = { - bidder: '33across', - params: { - siteId - } - }; - - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - }); - }); - - context('banner validation', function() { - context('when banner mediaType does not exist', function() { - it('returns true', function() { - const bid = { - bidder: '33across', - params: { - zoneId: 'cxBE0qjUir6iopaKkGJozW' - } - }; - - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - }); - - context('when banner sizes are defined', function() { - it('returns true', function() { - const bid = { - bidder: '33across', - mediaTypes: { - banner: { - sizes: [[250, 300]] - } - }, - params: { - zoneId: 'cxBE0qjUir6iopaKkGJozW' - } - }; - - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - }); - - context('when banner sizes are invalid', function() { - it('returns false', function() { - const invalidSizes = [ - undefined, - '16:9', - 300, - 'foo' - ]; - - invalidSizes.forEach((sizes) => { - const bid = { - bidder: '33across', - mediaTypes: { - banner: { - sizes - } - }, - params: { - zoneId: 'cxBE0qjUir6iopaKkGJozW' - } - }; - - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - }); - }); - }); - - context('video validation', function() { - beforeEach(function() { - // Basic Valid BidRequest - this.bid = { - bidder: '33across', - mediaTypes: { - video: { - playerSize: [[300, 50]], - context: 'outstream', - mimes: ['foo', 'bar'], - protocols: [1, 2] - } - }, - params: { - zoneId: `${ZONE_ID}` - } - }; - }); - - context('when video mediaType does not exist', function() { - it('returns true', function() { - const bid = { - bidder: '33across', - params: { - zoneId: `${ZONE_ID}` - } - }; - - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - }); - - context('when valid video mediaType is defined', function() { - it('returns true', function() { - expect(spec.isBidRequestValid(this.bid)).to.be.true; - }); - }); - - context('when video context is not defined', function() { - it('returns false', function() { - delete this.bid.mediaTypes.video.context; - - expect(spec.isBidRequestValid(this.bid)).to.be.false; - }); - }); - - context('when video player size is invalid', function() { - it('returns false', function() { - const invalidSizes = [ - undefined, - '16:9', - 300, - 'foo' - ]; - - invalidSizes.forEach((playerSize) => { - this.bid.mediaTypes.video.playerSize = playerSize; - expect(spec.isBidRequestValid(this.bid)).to.be.false; - }); - }); - }); - - context('when video mimes is invalid', function() { - it('returns false', function() { - const invalidMimes = [ - undefined, - 'foo', - 1, - [] - ] - - invalidMimes.forEach((mimes) => { - this.bid.mediaTypes.video.mimes = mimes; - expect(spec.isBidRequestValid(this.bid)).to.be.false; - }) - }); - }); - - context('when video protocols is invalid', function() { - it('returns false', function() { - const invalidMimes = [ - undefined, - 'foo', - 1, - [] - ] - - invalidMimes.forEach((protocols) => { - this.bid.mediaTypes.video.protocols = protocols; - expect(spec.isBidRequestValid(this.bid)).to.be.false; - }) - }); - }); - - context('when video placement is invalid', function() { - it('returns false', function() { - const invalidPlacement = [ - [], - '1', - {}, - 'foo' - ]; - - invalidPlacement.forEach((placement) => { - this.bid.mediaTypes.video.plcmt = placement; - expect(spec.isBidRequestValid(this.bid)).to.be.false; - }); - - invalidPlacement.forEach((placement) => { - this.bid.mediaTypes.video.placement = placement; - expect(spec.isBidRequestValid(this.bid)).to.be.false; - }); - }); - }); - - context('when video start delay is invalid for instream context', function() { - it('returns false', function() { - const bidRequests = ( - new BidRequestsBuilder() - .withVideo({context: 'instream', protocols: [1, 2], mimes: ['foo', 'bar']}) - .build() - ); - - const invalidStartdelay = [ - [], - '1', - {}, - 'foo' - ]; - - invalidStartdelay.forEach((startdelay) => { - bidRequests[0].mediaTypes.video.startdelay = startdelay; - expect(spec.isBidRequestValid(bidRequests[0])).to.be.false; - }); - }); - }); - - context('when video start delay is invalid for outstream context', function() { - it('returns true', function() { - const bidRequests = ( - new BidRequestsBuilder() - .withVideo({context: 'outstream', protocols: [1, 2], mimes: ['foo', 'bar']}) - .build() - ); - - const invalidStartdelay = [ - [], - '1', - {}, - 'foo' - ]; - - invalidStartdelay.forEach((startdelay) => { - bidRequests[0].mediaTypes.video.startdelay = startdelay; - expect(spec.isBidRequestValid(bidRequests[0])).to.be.true; - }); - }); - }); - }) - }); - - describe('buildRequests()', function() { - context('when the zone ID is for a site request', function() { - it('sets it in the site attribute', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withSite({ - id: ZONE_ID - }) - .build() - ); - - const bidRequests = this.buildBannerBidRequests(); // Bids have the default zone ID configured - const bidderRequest = this.buildBidderRequest(bidRequests); - - const [ buildRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(buildRequest, serverRequest); - }) - }); - - context('when the zone ID is for an app request', function() { - it('sets it in the app attribute', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder({ - app: { - id: ZONE_ID - } - }) - .withBanner() - .withProduct() - .withApp({ - foo: 'bar' - }) - .build() - ); - - const bidRequests = this.buildBannerBidRequests(); // Bids have the default zone ID configured - const bidderRequest = this.buildBidderRequest(bidRequests, { - ortb2: { - app: { - foo: 'bar' - } - } - }); - - const [ buildRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(buildRequest, serverRequest); - }); - }); - - context('when element is fully in view', function() { - it('returns 100', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withViewability({amount: 100}) - .build() - ); - - Object.assign(this.element, { width: 600, height: 400 }); - - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ buildRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(buildRequest, serverRequest); - }); - }); - - context('when element is out of view', function() { - it('returns 0', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withViewability({amount: 0}) - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - - Object.assign(this.element, { x: -300, y: 0, width: 207, height: 320 }); - - const [ buildRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(buildRequest, serverRequest); - }); - }); - - context('when element is partially in view', function() { - it('returns percentage', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withViewability({amount: 75}) - .build() - ) - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - - Object.assign(this.element, { width: 800, height: 800 }); - - const [ buildRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(buildRequest, serverRequest); - }); - }); - - context('when width or height of the element is zero', function() { - it('try to use alternative values', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withSizes([{ w: 800, h: 2400 }]) - .withViewability({amount: 25}) - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - - Object.assign(this.element, { width: 0, height: 0 }); - bidRequests[0].mediaTypes.banner.sizes = [[800, 2400]]; - - const [ buildRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(buildRequest, serverRequest); - }); - }); - - context('when nested iframes', function() { - it('returns \'nm\'', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withViewability({amount: spec.NON_MEASURABLE}) - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - - Object.assign(this.element, { width: 600, height: 400 }); - - utils.getWindowTop.restore(); - utils.getWindowSelf.restore(); - this.sandbox.stub(utils, 'getWindowTop').returns({}); - this.sandbox.stub(utils, 'getWindowSelf').returns(this.win); - - const [ buildRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(buildRequest, serverRequest); - }); - - context('when all the wrapping windows are accessible', function() { - it('returns the viewport dimensions of the top most accessible window', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withDevice({ - ext: { - ttx: { - vp: { - w: 6789, - h: 2345 - } - } - } - }) - .withProduct() - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - - this.sandbox.stub(this.win, 'parent').value({ - document: { - documentElement: { - clientWidth: 1234, - clientHeight: 4567 - } - }, - parent: { - document: { - documentElement: { - clientWidth: 6789, - clientHeight: 2345 - } - }, - } - }); - - const [ buildRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(buildRequest, serverRequest); - }); - }); - - context('when one of the wrapping windows cannot be accessed', function() { - it('returns the viewport dimensions of the top most accessible window', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withDevice({ - ext: { - ttx: { - vp: { - w: 9876, - h: 5432 - } - } - } - }) - .withProduct() - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - const notAccessibleParentWindow = {}; - - Object.defineProperty(notAccessibleParentWindow, 'document', { - get() { throw new Error('fakeError'); } - }); - - this.sandbox.stub(this.win, 'parent').value({ - document: { - documentElement: { - clientWidth: 1234, - clientHeight: 4567 - } - }, - parent: { - parent: notAccessibleParentWindow, - document: { - documentElement: { - clientWidth: 9876, - clientHeight: 5432 - } - }, - } - }); - - const [ buildRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(buildRequest, serverRequest); - }); - }); - }); - - context('when tab is inactive', function() { - it('returns 0', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withViewability({amount: 0}) - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - - Object.assign(this.element, { width: 600, height: 400 }); - - utils.getWindowTop.restore(); - this.win.document.visibilityState = 'hidden'; - this.sandbox.stub(utils, 'getWindowTop').returns(this.win); - resetWinDimensions(); - - const [ buildRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(buildRequest, serverRequest); - }); - }); - - context('when gdpr consent data exists', function() { - it('returns corresponding server requests with gdpr consent data', function() { - const gdprConsent = 'foobarMyPreference'; - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withGdprConsent(gdprConsent, 1) - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests, { - ortb2: { - user: { - consent: gdprConsent - }, - regs: { - gdpr: 1 - } - } - }); - - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - - it('returns corresponding test server requests with gdpr consent data', function() { - this.sandbox.stub(config, 'getConfig') - .withArgs('ttxSettings') - .returns({ - 'url': 'https://foo.com/hb/' - }); - - const gdprConsent = 'foobarMyPreference'; - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withGdprConsent(gdprConsent, 1) - .build(), - 'https://foo.com/hb/' - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests, { - ortb2: { - user: { - consent: gdprConsent - }, - regs: { - gdpr: 1 - } - } - }); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when gdpr consent data does not exist', function() { - it('returns corresponding server requests with default gdpr consent data', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - - it('returns corresponding test server requests with default gdpr consent data', function() { - this.sandbox.stub(config, 'getConfig') - .withArgs('ttxSettings') - .returns({ - 'url': 'https://foo.com/hb/' - }); - - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .build(), - 'https://foo.com/hb/' - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when us_privacy consent data exists', function() { - it('returns corresponding server requests with us_privacy consent data', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withUspConsent('foo') - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests, { - ortb2: { - regs: { - us_privacy: 'foo' - } - } - }); - - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - - it('returns corresponding test server requests with us_privacy consent data', function() { - this.sandbox.stub(config, 'getConfig') - .withArgs('ttxSettings') - .returns({ - 'url': 'https://foo.com/hb/' - }); - - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withUspConsent('foo') - .build(), - 'https://foo.com/hb/' - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests, { - ortb2: { - regs: { - us_privacy: 'foo' - } - } - }); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when us_privacy consent data does not exist', function() { - it('returns corresponding server requests with default us_privacy data', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - - it('returns corresponding test server requests with default us_privacy consent data', function() { - this.sandbox.stub(config, 'getConfig') - .withArgs('ttxSettings') - .returns({ - 'url': 'https://foo.com/hb/' - }); - - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .build(), - 'https://foo.com/hb/' - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when coppa has been enabled', function() { - beforeEach(function() { - this.sandbox.stub(config, 'getConfig').withArgs('coppa').returns(true); - }); - - it('returns corresponding server requests with coppa: 1', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withCoppa(1) - .build() - ) - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests, { - ortb2: { - regs: { - coppa: 1 - } - } - }); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when coppa has been disabled', function() { - beforeEach(function() { - this.sandbox.stub(config, 'getConfig').withArgs('coppa').returns(false); - }); - - it('returns corresponding server requests with coppa: 0', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withCoppa(0) - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests, { - ortb2: { - regs: { - coppa: 0 - } - } - }); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when GPP consent data exists', function() { - it('returns corresponding server requests with GPP consent data', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withGppConsent('foo', '123') - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests, { - ortb2: { - regs: { - gpp: 'foo', - gpp_sid: '123' - } - } - }); - - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - - it('returns corresponding test server requests with GPP consent data', function() { - this.sandbox.stub(config, 'getConfig').withArgs('ttxSettings') - .returns({ - 'url': 'https://foo.com/hb/' - }); - - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withGppConsent('foo', '123') - .build(), - 'https://foo.com/hb/' - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests, { - ortb2: { - regs: { - gpp: 'foo', - gpp_sid: '123' - } - } - }); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when refererInfo values are available', function() { - context('when refererInfo.page is defined', function() { - it('returns corresponding server requests with site.page set', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withPageUrl('http://foo.com/bar') - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests, { - ortb2: { - site: { - page: 'http://foo.com/bar' - } - } - }); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when refererInfo.ref is defined', function() { - it('returns corresponding server requests with site.ref set', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withReferer('google.com') - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests, { - refererInfo: { - ref: 'google.com' - } - }); - - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - }); - - context('when Global Placement ID (gpid) is defined', function() { - it('passes the Global Placement ID (gpid) in the request', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withGpid('fakeGPID0') - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - - const copyBidRequest = utils.deepClone(bidRequests); - const bidRequestsWithGpid = copyBidRequest.map(function(bidRequest, index) { - return { - ...bidRequest, - ortb2Imp: { - ext: { - gpid: 'fakeGPID' + index - } - } - }; - }); - - const [ builtServerRequest ] = spec.buildRequests(bidRequestsWithGpid, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when referer value is not available', function() { - it('returns corresponding server requests without site.page and site.ref set', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests, { - refererInfo: {} - }); - - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when there is schain object in the bidRequest', function() { - it('builds request with schain info in source', function() { - const schainValues = [ - { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'bidderA.com', - 'sid': '00001', - 'hp': 1 - } - ] - }, - { - 'ver': '1.0', - 'complete': 1, - }, - { - 'ver': '1.0', - 'complete': '1', - 'nodes': [ - { - 'asi': 'bidderA.com', - 'sid': '00001', - 'hp': 1 - } - ] - } - ]; - - schainValues.forEach((schain) => { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withSchain(schain) - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests, { - ortb2: { - source: { - schain - } - } - }); - - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - }); - - context('when there no schain object is passed', function() { - it('does not set source field', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when price floor module is not enabled for banner in bidRequest', function() { - it('does not set any bidfloors in ttxRequest', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when price floor module is enabled for banner in bidRequest', function() { - context('and there\'s no floor', function() { - it('does not set any bidfloors in ttxRequest', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - - bidRequests[0].getFloor = () => ({}); - - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('and there\'s a floor', function() { - it('sets bidfloors in ttxRequest', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct() - .withFormatFloors('banner', [ 1.0, 0.10 ]) - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - - bidRequests[0].getFloor = ({size, currency, mediaType}) => { - const floor = (size[0] === 300 && size[1] === 250) ? 1.0 : 0.10 - return ( - { - floor, - currency: 'USD' - } - ); - }; - - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - }); - - context('when mediaType has video only', function() { - context('and context is instream', function() { - it('builds instream request with default params', function() { - const bidRequests = new BidRequestsBuilder() - .withVideo({context: 'instream'}) - .build(); - const ttxRequest = new TtxRequestBuilder() - .withVideo() - .withProduct('instream') - .build(); - ttxRequest.imp[0].video.startdelay = 0; - - const serverRequest = this.buildServerRequest(ttxRequest); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - - it('builds instream request with params passed', function() { - const allowedParams = { - mimes: ['video/mp4'], - minduration: 15, - maxduration: 45, - placement: 1, - plcmt: 1, - protocols: [2, 3], - startdelay: -2, - skip: true, - skipmin: 5, - skipafter: 15, - minbitrate: 300, - maxbitrate: 1500, - delivery: [2], - playbackmethod: [1, 3], - api: [3], - linearity: 1, - rqddurs: 123, - maxseq: 5, - poddur: 3, - podid: 'pod_1', - podseq: 1, - mincpmpersec: 'foo', - slotinpod: 0 - }; - const bidRequests = ( - new BidRequestsBuilder() - .withVideo({context: 'instream', ...allowedParams}) - .build() - ); - const ttxRequest = new TtxRequestBuilder() - .withVideo(allowedParams) - .withProduct('instream') - .build(); - const serverRequest = this.buildServerRequest(ttxRequest); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - - context('when the placement is still specified in the DEPRECATED `placement` field', function() { - it('does not overwrite its value and does not set it in the recent `plcmt` field as well', function() { - const bidRequests = new BidRequestsBuilder() - .withVideo({ - placement: 2, // Incorrect placement for an instream video - context: 'instream' - }) - .build(); - const ttxRequest = new TtxRequestBuilder() - .withVideo() - .withProduct('instream') - .build(); - - ttxRequest.imp[0].video.placement = 2; - ttxRequest.imp[0].video.startdelay = 0; - - const serverRequest = this.buildServerRequest(ttxRequest); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - }); - - context('and context is outstream', function() { - it('builds siab request with video params passed', function() { - const bidRequests = new BidRequestsBuilder() - .withVideo({ - context: 'outstream', - plcmt: 3, - playbackmethod: [2] - }) - .build(); - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withVideo({plcmt: 3, playbackmethod: [2]}) - .withProduct('siab') - .build() - ); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - }); - - context('when mediaType has banner only', function() { - it('builds default siab request', function() { - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct('siab') - .build() - ); - const bidRequests = this.buildBannerBidRequests(); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - - context('when product is set as such', function() { - it('builds default inview request', function() { - const bidRequests = new BidRequestsBuilder() - .withBanner() - .withProduct('inview') - .build() - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withProduct('inview') - .build() - ); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - }); - - context('when mediaType has banner and video', function() { - it('builds siab request with banner and outstream video', function() { - const bidRequests = ( - new BidRequestsBuilder() - .withBanner() - .withVideo({context: 'outstream'}) - .build() - ); - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withBanner() - .withVideo() - .withProduct('siab') - .build() - ); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - - context('when context is instream', function() { - it('builds siab request with banner and outstream video even', function() { - const bidRequests = ( - new BidRequestsBuilder() - .withBanner() - .withVideo({context: 'instream', plcmt: 2}) - .build() - ); - - const ttxRequest = new TtxRequestBuilder() - .withBanner() - .withVideo({ plcmt: 2 }) - .withProduct('siab') - .build(); - const serverRequest = this.buildServerRequest(ttxRequest); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - }); - - context('when price floor module is enabled for video in bidRequest', function() { - context('and there is no floor', function() { - it('does not set any bidfloors in video', function() { - const bidRequests = ( - new BidRequestsBuilder() - .withVideo({context: 'outstream'}) - .build() - ); - - bidRequests[0].getFloor = () => ({}); - - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withVideo() - .withProduct() - .build() - ); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when there is a floor', function() { - it('sets bidfloors in video', function() { - const bidRequests = ( - new BidRequestsBuilder() - .withVideo({context: 'outstream'}) - .build() - ); - - bidRequests[0].getFloor = ({size, currency, mediaType}) => { - const floor = (mediaType === 'video') ? 1.0 : 0.10 - return ( - { - floor, - currency: 'USD' - } - ); - }; - - const ttxRequest = new TtxRequestBuilder() - .withVideo() - .withProduct() - .withFloors('video', [ 1.0 ]) - .build(); - const serverRequest = this.buildServerRequest(ttxRequest); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - }); - - context('when user ID data exists as userIdAsEids Array in bidRequest', function() { - it('passes userIds in eids field in ORTB request', function() { - const eids = [ - { - 'source': 'x-device-vendor-x.com', - 'uids': [ - { - 'id': 'yyy', - 'atype': 1 - }, - { - 'id': 'zzz', - 'atype': 1 - }, - { - 'id': 'DB700403-9A24-4A4B-A8D5-8A0B4BE777D2', - 'atype': 2 - } - ], - 'ext': { - 'foo': 'bar' - } - } - ]; - - const bidRequests = ( - new BidRequestsBuilder() - .withUserIds(eids) - .build() - ); - - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withUserIds(eids) - .withProduct() - .build() - ); - const bidderRequest = this.buildBidderRequest(bidRequests, { - ortb2: { - user: { - eids - } - } - }); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - - it('does not validate eids ORTB', function() { - const eids = [1, 2, 3]; - - const bidRequests = ( - new BidRequestsBuilder() - .withUserIds(eids) - .build() - ); - - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withUserIds(eids) - .withProduct() - .build() - ); - const bidderRequest = this.buildBidderRequest(bidRequests, { - ortb2: { - user: { - eids - } - } - }); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when user IDs are an empty array', function() { - it('does not pass user IDs in the bidRequest ORTB', function() { - const bidRequests = ( - new BidRequestsBuilder() - .withUserIds([]) - .build() - ); - bidRequests.userId = { - 'vendorx': { - 'source': 'x-device-vendor-x.com', - 'uids': [ - { - 'id': 'yyy', - 'atype': 1 - }, - { - 'id': 'zzz', - 'atype': 1 - }, - { - 'id': 'DB700403-9A24-4A4B-A8D5-8A0B4BE777D2', - 'atype': 2 - } - ], - 'ext': { - 'foo': 'bar' - } - } - }; - - const serverRequest = this.buildServerRequest( - new TtxRequestBuilder() - .withProduct() - .build() - ); - const bidderRequest = this.buildBidderRequest(bidRequests); - const [ builtServerRequest ] = spec.buildRequests(bidRequests, bidderRequest); - - validateBuiltServerRequest(builtServerRequest, serverRequest); - }); - }); - - context('when SRA mode is enabled', function() { - it('builds a single request with multiple imps corresponding to each group {zoneId, productId}', function() { - this.sandbox.stub(config, 'getConfig') - .withArgs('ttxSettings') - .returns({ - enableSRAMode: true - }); - - const bidRequests = new BidRequestsBuilder() - .addBid() - .addBid({ - bidId: 'b3', - adUnitCode: 'div-id', - params: { - zoneId: 'sample33xGUID123456780', - productId: 'siab' - } - }) - .addBid({ - bidId: 'b4', - adUnitCode: 'div-id', - params: { - zoneId: 'sample33xGUID123456780', - productId: 'inview' - } - }) - .withBanner() - .withVideo({context: 'outstream'}) - .build(); - - const req1 = new TtxRequestBuilder() - .addImp() - .withProduct('siab') - .withBanner() - .withVideo() - .build(); - - const req2 = new TtxRequestBuilder({ site: { id: 'sample33xGUID123456780' } }) - .withProduct('siab') - .withBanner() - .withVideo() - .build(); - - req2.imp[0].id = 'b3'; - - const req3 = new TtxRequestBuilder({ site: { id: 'sample33xGUID123456780' } }) - .withProduct('inview') - .withBanner() - .withVideo() - .build(); - - req3.imp[0].id = 'b4'; - - const serverReqs = [ - this.buildServerRequest(req1), - this.buildServerRequest(req2, 'https://ssc.33across.com/api/v1/hb?guid=sample33xGUID123456780'), - this.buildServerRequest(req3, 'https://ssc.33across.com/api/v1/hb?guid=sample33xGUID123456780') - ]; - - const bidderRequest = this.buildBidderRequest(bidRequests); - const builtServerRequests = spec.buildRequests(bidRequests, bidderRequest); - - builtServerRequests.forEach((builtServerRequest, index) => { - validateBuiltServerRequest(builtServerRequest, serverReqs[index]); - }); - }); - }); - - context('when SRA mode is not enabled', function() { - it('builds multiple requests, one corresponding to each Ad Unit', function() { - const bidRequests = new BidRequestsBuilder() - .addBid() - .addBid({ - bidId: 'b3', - adUnitCode: 'div-id', - params: { - zoneId: 'sample33xGUID123456780', - productId: 'siab' - } - }) - .withBanner() - .withVideo({context: 'outstream'}) - .build(); - - const req1 = new TtxRequestBuilder() - .withProduct('siab') - .withBanner() - .withVideo() - .build(); - - const req2 = new TtxRequestBuilder() - .withProduct('siab') - .withBanner() - .withVideo() - .build(); - - req2.imp[0].id = 'b2'; - - const req3 = new TtxRequestBuilder({ site: { id: 'sample33xGUID123456780' } }) - .withProduct('siab') - .withBanner() - .withVideo() - .build(); - - req3.imp[0].id = 'b3'; - - const serverReqs = [ - this.buildServerRequest(req1), - this.buildServerRequest(req2), - this.buildServerRequest(req3, 'https://ssc.33across.com/api/v1/hb?guid=sample33xGUID123456780') - ]; - - const bidderRequest = this.buildBidderRequest(bidRequests); - const builtServerRequests = spec.buildRequests(bidRequests, bidderRequest); - - builtServerRequests.forEach((builtServerRequest, index) => { - validateBuiltServerRequest(builtServerRequest, serverReqs[index]); - }); - }); - }); - }); - - describe('interpretResponse', function() { - const videoBid = ''; - - beforeEach(function() { - const ttxRequest = new TtxRequestBuilder() - .withBanner() - .withProduct() - .withSite({ - id: ZONE_ID, - page: 'https://test-url.com' - }) - .build(); - - this.serverRequest = new ServerRequestBuilder() - .withUrl('https://staging-ssc.33across.com/api/v1/hb') - .withData(ttxRequest) - .withOptions({ - contentType: 'text/plain', - withCredentials: false - }) - .build(); - }); - - context('when exactly one bid is returned', function() { - it('interprets and returns the single banner bid response', function() { - const serverResponse = { - cur: 'USD', - ext: {}, - id: 'r1', - seatbid: [ - { - bid: [{ - id: '1', - impid: 'b1', - adm: '

I am an ad

', - crid: 1, - h: 250, - w: 300, - price: 0.0938, - adomain: ['advertiserdomain.com'] - }] - } - ] - }; - const bidResponse = { - requestId: 'b1', - cpm: 0.0938, - width: 300, - height: 250, - ad: '

I am an ad

', - ttl: 60, - creativeId: 1, - mediaType: 'banner', - currency: 'USD', - netRevenue: true, - meta: { - advertiserDomains: ['advertiserdomain.com'] - } - }; - - expect(spec.interpretResponse({ body: serverResponse }, this.serverRequest)).to.deep.equal([bidResponse]); - }); - - it('interprets and returns the single video bid response', function() { - const serverResponse = { - cur: 'USD', - ext: {}, - id: 'r1', - seatbid: [ - { - bid: [{ - id: '1', - impid: 'b1', - adm: videoBid, - ext: { - ttx: { - mediaType: 'video', - vastType: 'xml' - } - }, - crid: 1, - h: 250, - w: 300, - price: 0.0938, - adomain: ['advertiserdomain.com'] - }] - } - ] - }; - const bidResponse = { - requestId: 'b1', - cpm: 0.0938, - width: 300, - height: 250, - ad: videoBid, - ttl: 60, - creativeId: 1, - mediaType: 'video', - currency: 'USD', - netRevenue: true, - vastXml: videoBid, - meta: { - advertiserDomains: ['advertiserdomain.com'] - } - }; - - expect(spec.interpretResponse({ body: serverResponse }, this.serverRequest)).to.deep.equal([bidResponse]); - }); - - context('when the list of advertiser domains for block list checking is empty', function() { - it('doesn\'t include the empty list in the interpreted response', function() { - const serverResponse = { - cur: 'USD', - ext: {}, - id: 'b1', - seatbid: [ - { - bid: [{ - id: '1', - impid: 'b1', - adm: '

I am an ad

', - crid: 1, - h: 250, - w: 300, - price: 0.0938, - adomain: [] // Empty list - }] - } - ] - }; - - // Bid response below doesn't contain meta.advertiserDomains - const bidResponse = { - requestId: 'b1', - cpm: 0.0938, - width: 300, - height: 250, - ad: '

I am an ad

', - ttl: 60, - creativeId: 1, - mediaType: 'banner', - currency: 'USD', - netRevenue: true - }; - - expect(spec.interpretResponse({ body: serverResponse }, this.serverRequest)).to.deep.equal([bidResponse]); - }); - }); - }); - - context('when no bids are returned', function() { - it('interprets and returns empty array', function() { - const serverResponse = { - cur: 'USD', - ext: {}, - id: 'r1', - seatbid: [] - }; - - expect(spec.interpretResponse({ body: serverResponse }, this.serverRequest)).to.deep.equal([]); - }); - }); - - context('when more than one bids are returned', function() { - it('interprets and returns all bids', function() { - const serverResponse = { - cur: 'USD', - ext: {}, - id: 'r1', - seatbid: [ - { - bid: [{ - id: '1', - impid: 'b1', - adm: '

I am an ad

', - crid: 1, - h: 250, - w: 300, - price: 0.0940 - }, - { - id: '2', - impid: 'b2', - adm: '

I am an ad

', - crid: 2, - h: 250, - w: 300, - price: 0.0938 - } - ] - }, - { - bid: [{ - id: '3', - impid: 'b3', - adm: videoBid, - ext: { - ttx: { - mediaType: 'video', - vastType: 'xml' - } - }, - crid: 3, - h: 250, - w: 300, - price: 0.0938 - }] - } - ] - }; - const bidResponse = [ - { - requestId: 'b1', - cpm: 0.0940, - width: 300, - height: 250, - ad: '

I am an ad

', - ttl: 60, - creativeId: 1, - mediaType: 'banner', - currency: 'USD', - netRevenue: true - }, - { - requestId: 'b2', - cpm: 0.0938, - width: 300, - height: 250, - ad: '

I am an ad

', - ttl: 60, - creativeId: 2, - mediaType: 'banner', - currency: 'USD', - netRevenue: true - }, - { - requestId: 'b3', - cpm: 0.0938, - width: 300, - height: 250, - ad: videoBid, - vastXml: '', - ttl: 60, - creativeId: 3, - mediaType: 'video', - currency: 'USD', - netRevenue: true - } - ]; - - expect(spec.interpretResponse({ body: serverResponse }, this.serverRequest)).to.deep.equal(bidResponse); - }); - }); - }); - - describe('getUserSyncs', function() { - beforeEach(function() { - this.syncs = [ - { - type: 'iframe', - url: 'https://ssc-cms.33across.com/ps/?m=xch&rt=html&ru=deb&id=id1' - }, - { - type: 'iframe', - url: 'https://ssc-cms.33across.com/ps/?m=xch&rt=html&ru=deb&id=id2' - }, - ]; - this.bidRequests = [ - { - bidId: 'b1', - bidder: '33across', - bidderRequestId: 'b1a', - params: { - zoneId: 'id1', - productId: 'foo' - }, - adUnitCode: 'div-id', - auctionId: 'r1', - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - transactionId: 't1' - }, - { - bidId: 'b2', - bidder: '33across', - bidderRequestId: 'b2a', - params: { - zoneId: 'id2', - productId: 'foo' - }, - adUnitCode: 'div-id', - auctionId: 'r1', - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - transactionId: 't2' - } - ]; - }); - - context('when iframe is not enabled', function() { - it('returns empty sync array', function() { - const syncOptions = {}; - - spec.buildRequests(this.bidRequests); - - expect(spec.getUserSyncs(syncOptions)).to.deep.equal([]); - }); - }); - - context('when iframe is enabled', function() { - beforeEach(function() { - this.syncOptions = { - iframeEnabled: true - }; - }); - - context('when there is no gdpr consent data', function() { - it('returns sync urls with undefined consent string as param', function() { - spec.buildRequests(this.bidRequests); - - const syncResults = spec.getUserSyncs(this.syncOptions, {}, undefined); - const expectedSyncs = [ - { - type: 'iframe', - url: `${this.syncs[0].url}&gdpr_consent=undefined&us_privacy=undefined&gpp=&gpp_sid=` - }, - { - type: 'iframe', - url: `${this.syncs[1].url}&gdpr_consent=undefined&us_privacy=undefined&gpp=&gpp_sid=` - } - ] - - expect(syncResults).to.deep.equal(expectedSyncs); - }) - }); - - context('when gdpr applies but there is no consent string', function() { - it('returns sync urls with undefined consent string as param and gdpr=1', function() { - spec.buildRequests(this.bidRequests); - - const syncResults = spec.getUserSyncs(this.syncOptions, {}, {gdprApplies: true}); - const expectedSyncs = [ - { - type: 'iframe', - url: `${this.syncs[0].url}&gdpr_consent=undefined&us_privacy=undefined&gpp=&gpp_sid=&gdpr=1` - }, - { - type: 'iframe', - url: `${this.syncs[1].url}&gdpr_consent=undefined&us_privacy=undefined&gpp=&gpp_sid=&gdpr=1` - } - ]; - - expect(syncResults).to.deep.equal(expectedSyncs); - }); - }); - - context('when gdpr applies and there is consent string', function() { - it('returns sync urls with gdpr_consent=consent string as param and gdpr=1', function() { - spec.buildRequests(this.bidRequests); - - const syncResults = spec.getUserSyncs(this.syncOptions, {}, {gdprApplies: true, consentString: 'consent123A'}); - const expectedSyncs = [ - { - type: 'iframe', - url: `${this.syncs[0].url}&gdpr_consent=consent123A&us_privacy=undefined&gpp=&gpp_sid=&gdpr=1` - }, - { - type: 'iframe', - url: `${this.syncs[1].url}&gdpr_consent=consent123A&us_privacy=undefined&gpp=&gpp_sid=&gdpr=1` - } - ]; - - expect(syncResults).to.deep.equal(expectedSyncs); - }); - }); - - context('when gdpr does not apply and there is no consent string', function() { - it('returns sync urls with undefined consent string as param and gdpr=0', function() { - spec.buildRequests(this.bidRequests); - - const syncResults = spec.getUserSyncs(this.syncOptions, {}, {gdprApplies: false}); - const expectedSyncs = [ - { - type: 'iframe', - url: `${this.syncs[0].url}&gdpr_consent=undefined&us_privacy=undefined&gpp=&gpp_sid=&gdpr=0` - }, - { - type: 'iframe', - url: `${this.syncs[1].url}&gdpr_consent=undefined&us_privacy=undefined&gpp=&gpp_sid=&gdpr=0` - } - ]; - expect(syncResults).to.deep.equal(expectedSyncs); - }); - }); - - context('when gdpr is unknown and there is consent string', function() { - it('returns sync urls with only consent string as param', function() { - spec.buildRequests(this.bidRequests); - - const syncResults = spec.getUserSyncs(this.syncOptions, {}, {consentString: 'consent123A'}); - const expectedSyncs = [ - { - type: 'iframe', - url: `${this.syncs[0].url}&gdpr_consent=consent123A&us_privacy=undefined&gpp=&gpp_sid=` - }, - { - type: 'iframe', - url: `${this.syncs[1].url}&gdpr_consent=consent123A&us_privacy=undefined&gpp=&gpp_sid=` - } - ]; - expect(syncResults).to.deep.equal(expectedSyncs); - }); - }); - - context('when gdpr does not apply and there is consent string (yikes!)', function() { - it('returns sync urls with consent string as param and gdpr=0', function() { - spec.buildRequests(this.bidRequests); - - const syncResults = spec.getUserSyncs(this.syncOptions, {}, {gdprApplies: false, consentString: 'consent123A'}); - const expectedSyncs = [ - { - type: 'iframe', - url: `${this.syncs[0].url}&gdpr_consent=consent123A&us_privacy=undefined&gpp=&gpp_sid=&gdpr=0` - }, - { - type: 'iframe', - url: `${this.syncs[1].url}&gdpr_consent=consent123A&us_privacy=undefined&gpp=&gpp_sid=&gdpr=0` - } - ]; - expect(syncResults).to.deep.equal(expectedSyncs); - }); - }); - - context('when there is no usPrivacy data', function() { - it('returns sync urls with undefined consent string as param', function() { - spec.buildRequests(this.bidRequests); - - const syncResults = spec.getUserSyncs(this.syncOptions, {}); - const expectedSyncs = [ - { - type: 'iframe', - url: `${this.syncs[0].url}&gdpr_consent=undefined&us_privacy=undefined&gpp=&gpp_sid=` - }, - { - type: 'iframe', - url: `${this.syncs[1].url}&gdpr_consent=undefined&us_privacy=undefined&gpp=&gpp_sid=` - } - ] - - expect(syncResults).to.deep.equal(expectedSyncs); - }) - }); - - context('when there is usPrivacy data', function() { - it('returns sync urls with consent string as param', function() { - spec.buildRequests(this.bidRequests); - - const syncResults = spec.getUserSyncs(this.syncOptions, {}, {}, 'foo'); - const expectedSyncs = [ - { - type: 'iframe', - url: `${this.syncs[0].url}&gdpr_consent=undefined&us_privacy=foo&gpp=&gpp_sid=` - }, - { - type: 'iframe', - url: `${this.syncs[1].url}&gdpr_consent=undefined&us_privacy=foo&gpp=&gpp_sid=` - } - ]; - - expect(syncResults).to.deep.equal(expectedSyncs); - }); - }); - - context('when there is no GPP data', function() { - it('returns sync urls with empty GPP params', function() { - spec.buildRequests(this.bidRequests); - - const syncResults = spec.getUserSyncs(this.syncOptions, {}); - const expectedSyncs = [ - { - type: 'iframe', - url: `${this.syncs[0].url}&gdpr_consent=undefined&us_privacy=undefined&gpp=&gpp_sid=` - }, - { - type: 'iframe', - url: `${this.syncs[1].url}&gdpr_consent=undefined&us_privacy=undefined&gpp=&gpp_sid=` - } - ] - - expect(syncResults).to.deep.equal(expectedSyncs); - }) - }); - - context('when there is GPP data', function() { - it('returns sync urls with GPP consent string & GPP Section ID as params', function() { - spec.buildRequests(this.bidRequests); - - const syncResults = spec.getUserSyncs(this.syncOptions, {}, {}, undefined, { - gppString: 'foo', - applicableSections: ['123', '456'] - }); - const expectedSyncs = [ - { - type: 'iframe', - url: `${this.syncs[0].url}&gdpr_consent=undefined&us_privacy=undefined&gpp=foo&gpp_sid=123%2C456` - }, - { - type: 'iframe', - url: `${this.syncs[1].url}&gdpr_consent=undefined&us_privacy=undefined&gpp=foo&gpp_sid=123%2C456` - } - ]; - - expect(syncResults).to.deep.equal(expectedSyncs); - }); - }); - - context('when user sync is invoked without a bid request phase', function() { - it('results in an empty syncs array', function() { - const syncResults = spec.getUserSyncs(this.syncOptions, {}, {}, 'foo'); - - expect(syncResults).to.deep.equal([]); - }); - }); - }); - }); -}); diff --git a/test/spec/modules/360playvidBidAdapter_spec.js b/test/spec/modules/360playvidBidAdapter_spec.js deleted file mode 100644 index 393afbf45..000000000 --- a/test/spec/modules/360playvidBidAdapter_spec.js +++ /dev/null @@ -1,518 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/360playvidBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = '360playvid'; - -describe('360PlayVidBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://ssp.360playvid.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - expect(bidderRequest).to.have.property('ortb2'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cookie.360playvid.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cookie.360playvid.com/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cookie.360playvid.com/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/51DegreesRtdProvider_spec.js b/test/spec/modules/51DegreesRtdProvider_spec.js deleted file mode 100644 index 38da88bcc..000000000 --- a/test/spec/modules/51DegreesRtdProvider_spec.js +++ /dev/null @@ -1,485 +0,0 @@ -import { - extractConfig, - get51DegreesJSURL, - is51DegreesMetaPresent, - deepSetNotEmptyValue, - convert51DegreesDataToOrtb2, - convert51DegreesDeviceToOrtb2, - getBidRequestData, - fiftyOneDegreesSubmodule, -} from 'modules/51DegreesRtdProvider'; -import {mergeDeep} from '../../../src/utils.js'; - -const inject51DegreesMeta = () => { - const meta = document.createElement('meta'); - meta.httpEquiv = 'Delegate-CH'; - meta.content = 'sec-ch-ua-full-version-list https://cloud.51degrees.com; sec-ch-ua-model https://cloud.51degrees.com; sec-ch-ua-platform https://cloud.51degrees.com; sec-ch-ua-platform-version https://cloud.51degrees.com'; - document.head.appendChild(meta); -}; - -describe('51DegreesRtdProvider', function() { - const fiftyOneDegreesDevice = { - screenpixelswidth: 5120, - screenpixelsheight: 1440, - hardwarevendor: 'Apple', - hardwaremodel: 'Macintosh', - hardwarename: [ - 'Macintosh', - ], - platformname: 'macOS', - platformversion: '14.1.2', - screeninchesheight: 13.27, - screenincheswidth: 47.17, - devicetype: 'Desktop', - pixelratio: 1, - deviceid: '17595-131215-132535-18092', - }; - - const fiftyOneDegreesDeviceX2scaling = { - ...fiftyOneDegreesDevice, - screenpixelsheight: fiftyOneDegreesDevice.screenpixelsheight / 2, - screenpixelswidth: fiftyOneDegreesDevice.screenpixelswidth / 2, - screenpixelsphysicalheight: fiftyOneDegreesDevice.screenpixelsheight, - screenpixelsphysicalwidth: fiftyOneDegreesDevice.screenpixelswidth, - pixelratio: fiftyOneDegreesDevice.pixelratio * 2, - }; - - const fiftyOneDegreesData = { - device: fiftyOneDegreesDevice, - }; - - const expectedORTB2DeviceResult = { - device: { - devicetype: 2, - make: 'Apple', - model: 'Macintosh', - os: 'macOS', - osv: '14.1.2', - h: 1440, - w: 5120, - ppi: 109, - pxratio: 1, - ext: { - fiftyonedegrees_deviceId: '17595-131215-132535-18092', - }, - }, - }; - - const expectedORTB2Result = {}; - mergeDeep( - expectedORTB2Result, - expectedORTB2DeviceResult, - // placeholder for the next 51Degrees RTD submodule update - ); - - describe('extractConfig', function() { - it('returns the resourceKey from the moduleConfig', function() { - const reqBidsConfigObj = {}; - const moduleConfig = {params: {resourceKey: 'TEST_RESOURCE_KEY'}}; - expect(extractConfig(moduleConfig, reqBidsConfigObj)).to.deep.equal({ - resourceKey: 'TEST_RESOURCE_KEY', - onPremiseJSUrl: undefined, - }); - }); - - it('returns the onPremiseJSUrl from the moduleConfig', function() { - const reqBidsConfigObj = {}; - const moduleConfig = {params: {onPremiseJSUrl: 'https://example.com/51Degrees.core.js'}}; - expect(extractConfig(moduleConfig, reqBidsConfigObj)).to.deep.equal({ - onPremiseJSUrl: 'https://example.com/51Degrees.core.js', - resourceKey: undefined, - }); - }); - - it('throws an error if neither resourceKey nor onPremiseJSUrl is provided', function() { - const reqBidsConfigObj = {}; - const moduleConfig = {params: {}}; - expect(() => extractConfig(moduleConfig, reqBidsConfigObj)).to.throw(); - }); - - it('throws an error if both resourceKey and onPremiseJSUrl are provided', function() { - const reqBidsConfigObj = {}; - const moduleConfig = {params: { - resourceKey: 'TEST_RESOURCE_KEY', - onPremiseJSUrl: 'https://example.com/51Degrees.core.js', - }}; - expect(() => extractConfig(moduleConfig, reqBidsConfigObj)).to.throw(); - }); - - it('throws an error if the resourceKey is equal to "" from example', function() { - const reqBidsConfigObj = {}; - const moduleConfig = {params: {resourceKey: ''}}; - expect(() => extractConfig(moduleConfig, reqBidsConfigObj)).to.throw(); - }); - - it('sets the resourceKey to undefined if it was set to "0"', function() { - const moduleConfig = {params: { - resourceKey: '0', - onPremiseJSUrl: 'https://example.com/51Degrees.core.js', - }}; - expect(extractConfig(moduleConfig, {})).to.deep.equal({ - resourceKey: undefined, - onPremiseJSUrl: 'https://example.com/51Degrees.core.js', - }); - }); - - it('sets the onPremiseJSUrl to undefined if it was set to "0"', function() { - const moduleConfig = {params: { - resourceKey: 'TEST_RESOURCE_KEY', - onPremiseJSUrl: '0', - }}; - expect(extractConfig(moduleConfig, {})).to.deep.equal({ - resourceKey: 'TEST_RESOURCE_KEY', - onPremiseJSUrl: undefined, - }); - }); - - it('throws an error if the onPremiseJSUrl is not a valid URL', function() { - expect(() => extractConfig({ - params: {onPremiseJSUrl: 'invalid URL'} - }, {})).to.throw(); - expect(() => extractConfig({ - params: {onPremiseJSUrl: 'www.example.com/51Degrees.core.js'} - }, {})).to.throw(); - }); - - it('allows the onPremiseJSUrl to be a valid URL', function() { - const VALID_URLS = [ - 'https://www.example.com/51Degrees.core.js', - 'http://example.com/51Degrees.core.js', - '//example.com/51Degrees.core.js', - '/51Degrees.core.js', - ]; - - VALID_URLS.forEach(url => { - expect(() => extractConfig({ - params: {onPremiseJSUrl: url} - }, {})).to.not.throw(); - }); - }); - }); - - describe('get51DegreesJSURL', function() { - const hev = { - 'brands': [ - { - 'brand': 'Chromium', - 'version': '130' - }, - { - 'brand': 'Google Chrome', - 'version': '130' - }, - { - 'brand': 'Not?A_Brand', - 'version': '99' - } - ], - 'fullVersionList': [ - { - 'brand': 'Chromium', - 'version': '130.0.6723.92' - }, - { - 'brand': 'Google Chrome', - 'version': '130.0.6723.92' - }, - { - 'brand': 'Not?A_Brand', - 'version': '99.0.0.0' - } - ], - 'mobile': false, - 'model': '', - 'platform': 'macOS', - 'platformVersion': '14.6.1' - }; - const mockWindow = { - ...window, - screen: { - height: 1117, - width: 1728, - }, - devicePixelRatio: 2, - }; - - it('returns the cloud URL if the resourceKey is provided', function() { - const config = {resourceKey: 'TEST_RESOURCE_KEY'}; - expect(get51DegreesJSURL(config, mockWindow)).to.equal( - 'https://cloud.51degrees.com/api/v4/TEST_RESOURCE_KEY.js?' + - `51D_ScreenPixelsHeight=${mockWindow.screen.height}&` + - `51D_ScreenPixelsWidth=${mockWindow.screen.width}&` + - `51D_PixelRatio=${mockWindow.devicePixelRatio}` - ); - }); - - it('returns the on-premise URL if the onPremiseJSUrl is provided', function () { - const config = {onPremiseJSUrl: 'https://example.com/51Degrees.core.js'}; - expect(get51DegreesJSURL(config, mockWindow)).to.equal( - `https://example.com/51Degrees.core.js?` + - `51D_ScreenPixelsHeight=${mockWindow.screen.height}&` + - `51D_ScreenPixelsWidth=${mockWindow.screen.width}&` + - `51D_PixelRatio=${mockWindow.devicePixelRatio}` - ); - }); - - it('doesn\'t override static query string parameters', function () { - const config = {onPremiseJSUrl: 'https://example.com/51Degrees.core.js?test=1'}; - expect(get51DegreesJSURL(config, mockWindow)).to.equal( - `https://example.com/51Degrees.core.js?test=1&` + - `51D_ScreenPixelsHeight=${mockWindow.screen.height}&` + - `51D_ScreenPixelsWidth=${mockWindow.screen.width}&` + - `51D_PixelRatio=${mockWindow.devicePixelRatio}` - ); - }); - - it('adds high entropy values to the query string, if available', async function () { - const config = { - onPremiseJSUrl: 'https://example.com/51Degrees.core.js', - hev, - }; - expect(get51DegreesJSURL(config, mockWindow)).to.equal( - `https://example.com/51Degrees.core.js?` + - `51D_GetHighEntropyValues=${btoa(JSON.stringify(hev))}&` + - `51D_ScreenPixelsHeight=${mockWindow.screen.height}&` + - `51D_ScreenPixelsWidth=${mockWindow.screen.width}&` + - `51D_PixelRatio=${mockWindow.devicePixelRatio}` - ); - }); - - it('doesn\'t add high entropy values to the query string if object is empty', function () { - const config = { - onPremiseJSUrl: 'https://example.com/51Degrees.core.js', - hev: {}, - }; - expect(get51DegreesJSURL(config, mockWindow)).to.equal( - `https://example.com/51Degrees.core.js?` + - `51D_ScreenPixelsHeight=${mockWindow.screen.height}&` + - `51D_ScreenPixelsWidth=${mockWindow.screen.width}&` + - `51D_PixelRatio=${mockWindow.devicePixelRatio}` - ); - }); - - it('keeps the original URL if none of the additional parameters are available', function () { - // delete screen and devicePixelRatio properties to test the case when they are not available - delete mockWindow.screen; - delete mockWindow.devicePixelRatio; - - const config = {onPremiseJSUrl: 'https://example.com/51Degrees.core.js'}; - expect(get51DegreesJSURL(config, mockWindow)).to.equal('https://example.com/51Degrees.core.js'); - expect(get51DegreesJSURL(config, window)).to.not.equal('https://example.com/51Degrees.core.js'); - }); - }); - - describe('is51DegreesMetaPresent', function() { - let initialHeadInnerHTML; - - before(function() { - initialHeadInnerHTML = document.head.innerHTML; - }); - - afterEach(function() { - document.head.innerHTML = initialHeadInnerHTML; - }); - - it('returns true if the 51Degrees meta tag is present', function () { - inject51DegreesMeta(); - expect(is51DegreesMetaPresent()).to.be.true; - }); - - it('returns false if the 51Degrees meta tag is not present', function() { - expect(is51DegreesMetaPresent()).to.be.false; - }); - - it('works with multiple meta tags, even if those are not to include any `content`', function() { - const meta1 = document.createElement('meta'); - meta1.httpEquiv = 'Delegate-CH'; - document.head.appendChild(meta1); - - inject51DegreesMeta(); - - const meta2 = document.createElement('meta'); - meta2.httpEquiv = 'Delegate-CH'; - document.head.appendChild(meta2); - - expect(is51DegreesMetaPresent()).to.be.true; - }); - }); - - describe('deepSetNotEmptyValue', function() { - it('sets value of ORTB2 key if it is not empty', function() { - const data = {}; - deepSetNotEmptyValue(data, 'TEST_ORTB2_KEY', 'TEST_ORTB2_VALUE'); - expect(data).to.deep.equal({TEST_ORTB2_KEY: 'TEST_ORTB2_VALUE'}); - deepSetNotEmptyValue(data, 'test2.TEST_ORTB2_KEY_2', 'TEST_ORTB2_VALUE_2'); - expect(data).to.deep.equal({ - TEST_ORTB2_KEY: 'TEST_ORTB2_VALUE', - test2: { - TEST_ORTB2_KEY_2: 'TEST_ORTB2_VALUE_2' - }, - }); - }); - - it('throws an error if the key is empty', function() { - const data = {}; - expect(() => deepSetNotEmptyValue(data, '', 'TEST_ORTB2_VALUE')).to.throw(); - }); - - it('does not set value of ORTB2 key if it is empty', function() { - const data = {}; - deepSetNotEmptyValue(data, 'TEST_ORTB2_KEY', ''); - deepSetNotEmptyValue(data, 'TEST_ORTB2_KEY', 0); - deepSetNotEmptyValue(data, 'TEST_ORTB2_KEY', null); - deepSetNotEmptyValue(data, 'TEST_ORTB2_KEY', undefined); - deepSetNotEmptyValue(data, 'TEST.TEST_ORTB2_KEY', undefined); - expect(data).to.deep.equal({}); - }); - }); - - describe('convert51DegreesDataToOrtb2', function() { - it('returns empty object if data is null, undefined or empty', () => { - expect(convert51DegreesDataToOrtb2(null)).to.deep.equal({}); - expect(convert51DegreesDataToOrtb2(undefined)).to.deep.equal({}); - expect(convert51DegreesDataToOrtb2({})).to.deep.equal({}); - }); - - it('converts all 51Degrees data to ORTB2 format', function() { - expect(convert51DegreesDataToOrtb2(fiftyOneDegreesData)).to.deep.equal(expectedORTB2Result); - }); - }); - - describe('convert51DegreesDeviceToOrtb2', function() { - it('converts 51Degrees device data to ORTB2 format', function() { - expect( - convert51DegreesDeviceToOrtb2(fiftyOneDegreesDevice) - ).to.deep.equal(expectedORTB2DeviceResult); - }); - - it('returns an empty object if the device data is not provided', function() { - expect(convert51DegreesDeviceToOrtb2()).to.deep.equal({}); - }); - - it('does not set the deviceid if it is not provided', function() { - const device = {...fiftyOneDegreesDevice}; - delete device.deviceid; - expect(convert51DegreesDeviceToOrtb2(device).device).to.not.have.any.keys('ext'); - }); - - it('sets the model to hardwarename if hardwaremodel is not provided', function() { - const device = {...fiftyOneDegreesDevice}; - delete device.hardwaremodel; - expect(convert51DegreesDeviceToOrtb2(device).device).to.deep.include({model: 'Macintosh'}); - }); - - it('does not set the model if hardwarename is empty', function() { - const device = {...fiftyOneDegreesDevice}; - delete device.hardwaremodel; - device.hardwarename = []; - expect(convert51DegreesDeviceToOrtb2(device).device).to.not.have.any.keys('model'); - }); - - it('does not set the ppi if screeninchesheight is not provided', function() { - const device = {...fiftyOneDegreesDevice}; - delete device.screeninchesheight; - expect(convert51DegreesDeviceToOrtb2(device).device).to.not.have.any.keys('ppi'); - }); - - it('sets correct ppi if screenpixelsphysicalheight & screeninchesheight are provided', function() { - expect(convert51DegreesDeviceToOrtb2(fiftyOneDegreesDeviceX2scaling).device).to.deep.include({ - ppi: expectedORTB2DeviceResult.device.ppi, - }); - }); - - it('if screenpixelsphysical properties are available, use them for screen size', function() { - expect(fiftyOneDegreesDevice.screenpixelswidth).to.not.equal(fiftyOneDegreesDeviceX2scaling.screenpixelswidth); - expect(fiftyOneDegreesDevice.screenpixelsheight).to.not.equal(fiftyOneDegreesDeviceX2scaling.screenpixelsheight); - expect(fiftyOneDegreesDevice.screenpixelsphysicalwidth).to.equal(undefined); - expect(fiftyOneDegreesDevice.screenpixelsphysicalheight).to.equal(undefined); - expect(convert51DegreesDeviceToOrtb2(fiftyOneDegreesDeviceX2scaling).device).to.deep.include({ - h: expectedORTB2DeviceResult.device.h, - w: expectedORTB2DeviceResult.device.w, - }); - }); - }); - - describe('getBidRequestData', function() { - let initialHeadInnerHTML; - let reqBidsConfigObj = {}; - const resetReqBidsConfigObj = () => { - reqBidsConfigObj = { - ortb2Fragments: { - global: { - device: {}, - }, - }, - }; - }; - - before(function() { - initialHeadInnerHTML = document.head.innerHTML; - - const mockScript = document.createElement('script'); - mockScript.innerHTML = ` - window.fod = {complete: (_callback) => _callback(${JSON.stringify(fiftyOneDegreesData)})}; - `; - document.head.appendChild(mockScript); - }); - - beforeEach(function() { - resetReqBidsConfigObj(); - }); - - after(function() { - document.head.innerHTML = initialHeadInnerHTML; - }); - - it('calls the callback even if submodule fails (wrong config)', function() { - const callback = sinon.spy(); - const moduleConfig = {params: {}}; - getBidRequestData(reqBidsConfigObj, callback, moduleConfig, {}); - expect(callback.calledOnce).to.be.true; - }); - - it('calls the callback even if submodule fails (on-premise, non-working URL)', async function() { - const callback = sinon.spy(); - const moduleConfig = {params: {onPremiseJSUrl: 'http://localhost:12345/test/51Degrees.core.js'}}; - - getBidRequestData(reqBidsConfigObj, callback, moduleConfig, {}); - await new Promise(resolve => setTimeout(resolve, 100)); - expect(callback.calledOnce).to.be.true; - }); - - it('calls the callback even if submodule fails (invalid resource key)', async function() { - const callback = sinon.spy(); - const moduleConfig = {params: {resourceKey: 'INVALID_RESOURCE_KEY'}}; - - getBidRequestData(reqBidsConfigObj, callback, moduleConfig, {}); - await new Promise(resolve => setTimeout(resolve, 100)); - expect(callback.calledOnce).to.be.true; - }); - - it('works with Delegate-CH meta tag', async function() { - inject51DegreesMeta(); - const callback = sinon.spy(); - const moduleConfig = {params: {resourceKey: 'INVALID_RESOURCE_KEY'}}; - getBidRequestData(reqBidsConfigObj, callback, moduleConfig, {}); - await new Promise(resolve => setTimeout(resolve, 100)); - expect(callback.calledOnce).to.be.true; - }); - - it('has the correct ORTB2 data', async function() { - const callback = sinon.spy(); - const moduleConfig = {params: {resourceKey: 'INVALID_RESOURCE_KEY'}}; - getBidRequestData(reqBidsConfigObj, callback, moduleConfig, {}); - await new Promise(resolve => setTimeout(resolve, 100)); - expect(callback.calledOnce).to.be.true; - expect(reqBidsConfigObj.ortb2Fragments.global).to.deep.equal(expectedORTB2Result); - }); - }); - - describe('init', function() { - it('initialises the 51Degrees RTD provider', function() { - expect(fiftyOneDegreesSubmodule.init()).to.be.true; - }); - }); -}); diff --git a/test/spec/modules/AsteriobidPbmAnalyticsAdapter_spec.js b/test/spec/modules/AsteriobidPbmAnalyticsAdapter_spec.js deleted file mode 100644 index d94368eee..000000000 --- a/test/spec/modules/AsteriobidPbmAnalyticsAdapter_spec.js +++ /dev/null @@ -1,152 +0,0 @@ -import prebidmanagerAnalytics, {storage} from 'modules/AsteriobidPbmAnalyticsAdapter.js'; -import {expect} from 'chai'; -import {server} from 'test/mocks/xhr.js'; -import * as utils from 'src/utils.js'; -import {expectEvents} from '../../helpers/analytics.js'; -import { EVENTS } from 'src/constants.js'; - -const events = require('src/events'); - -describe('Prebid Manager Analytics Adapter', function () { - const bidWonEvent = { - 'bidderCode': 'appnexus', - 'width': 300, - 'height': 250, - 'adId': '1ebb82ec35375e', - 'mediaType': 'banner', - 'cpm': 0.5, - 'requestId': '1582271863760569973', - 'creative_id': '96846035', - 'creativeId': '96846035', - 'ttl': 60, - 'currency': 'USD', - 'netRevenue': true, - 'auctionId': '9c7b70b9-b6ab-4439-9e71-b7b382797c18', - 'responseTimestamp': 1537521629657, - 'requestTimestamp': 1537521629331, - 'bidder': 'appnexus', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'timeToRespond': 326, - 'size': '300x250', - 'status': 'rendered', - 'eventType': 'bidWon', - 'ad': 'some ad', - 'adUrl': 'ad url' - }; - - describe('Prebid Manager Analytic tests', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - }); - - afterEach(function () { - prebidmanagerAnalytics.disableAnalytics(); - events.getEvents.restore(); - }); - - it('support custom endpoint', function () { - const custom_url = 'custom url'; - prebidmanagerAnalytics.enableAnalytics({ - provider: 'prebidmanager', - options: { - url: custom_url, - bundleId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' - } - }); - - expect(prebidmanagerAnalytics.getOptions().url).to.equal(custom_url); - }); - - it('bid won event', function() { - const bundleId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; - prebidmanagerAnalytics.enableAnalytics({ - provider: 'prebidmanager', - options: { - bundleId: bundleId - } - }); - - events.emit(EVENTS.BID_WON, bidWonEvent); - prebidmanagerAnalytics.flush(); - - expect(server.requests.length).to.equal(1); - expect(server.requests[0].url).to.equal('https://endpt.prebidmanager.com/endpoint'); - expect(server.requests[0].requestBody.substring(0, 2)).to.equal('1:'); - - const pmEvents = JSON.parse(server.requests[0].requestBody.substring(2)); - expect(pmEvents.pageViewId).to.exist; - expect(pmEvents.bundleId).to.equal(bundleId); - expect(pmEvents.ver).to.equal(1); - expect(pmEvents.events.length).to.equal(2); - expect(pmEvents.events[0].eventType).to.equal('pageView'); - expect(pmEvents.events[1].eventType).to.equal('bidWon'); - expect(pmEvents.events[1].ad).to.be.undefined; - expect(pmEvents.events[1].adUrl).to.be.undefined; - }); - - it('track event without errors', function () { - sinon.spy(prebidmanagerAnalytics, 'track'); - - prebidmanagerAnalytics.enableAnalytics({ - provider: 'prebidmanager', - options: { - bundleId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' - } - }); - - expectEvents().to.beTrackedBy(prebidmanagerAnalytics.track); - }); - }); - - describe('build utm tag data', function () { - let getDataFromLocalStorageStub; - this.timeout(4000) - beforeEach(function () { - getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); - getDataFromLocalStorageStub.withArgs('pm_utm_source').returns('utm_source'); - getDataFromLocalStorageStub.withArgs('pm_utm_medium').returns('utm_medium'); - getDataFromLocalStorageStub.withArgs('pm_utm_campaign').returns('utm_camp'); - getDataFromLocalStorageStub.withArgs('pm_utm_term').returns(''); - getDataFromLocalStorageStub.withArgs('pm_utm_content').returns(''); - }); - afterEach(function () { - getDataFromLocalStorageStub.restore(); - prebidmanagerAnalytics.disableAnalytics() - }); - it('should build utm data from local storage', function () { - prebidmanagerAnalytics.enableAnalytics({ - provider: 'prebidmanager', - options: { - bundleId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' - } - }); - - const pmEvents = JSON.parse(server.requests[0].requestBody.substring(2)); - - expect(pmEvents.utmTags.utm_source).to.equal('utm_source'); - expect(pmEvents.utmTags.utm_medium).to.equal('utm_medium'); - expect(pmEvents.utmTags.utm_campaign).to.equal('utm_camp'); - expect(pmEvents.utmTags.utm_term).to.equal(''); - expect(pmEvents.utmTags.utm_content).to.equal(''); - }); - }); - - describe('build page info', function () { - afterEach(function () { - prebidmanagerAnalytics.disableAnalytics() - }); - it('should build page info', function () { - prebidmanagerAnalytics.enableAnalytics({ - provider: 'prebidmanager', - options: { - bundleId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' - } - }); - - const pmEvents = JSON.parse(server.requests[0].requestBody.substring(2)); - - expect(pmEvents.pageInfo.domain).to.equal(window.location.hostname); - expect(pmEvents.pageInfo.referrerDomain).to.equal(utils.parseUrl(document.referrer).hostname); - }); - }); -}); diff --git a/test/spec/modules/ViouslyBidAdapter_spec.js b/test/spec/modules/ViouslyBidAdapter_spec.js deleted file mode 100644 index 16f32e3d6..000000000 --- a/test/spec/modules/ViouslyBidAdapter_spec.js +++ /dev/null @@ -1,480 +0,0 @@ -import {expect} from 'chai'; - -import { deepClone, mergeDeep } from 'src/utils'; -import { BANNER, VIDEO } from 'src/mediaTypes'; -import { createEidsArray } from 'modules/userId/eids.js'; - -import {spec as adapter} from 'modules/viouslyBidAdapter'; - -import sinon from 'sinon'; -import { config } from 'src/config.js'; - -const CURRENCY = 'EUR'; -const TTL = 60; -const HTTP_METHOD = 'POST'; -const REQUEST_URL = 'https://bidder.viously.com/bid'; - -const VALID_BID_BANNER = { - bidder: 'viously', - bidId: '5e6f7g8h', - adUnitCode: 'id-5678', - params: { - pid: '123e4567-e89b-12d3-a456-426614174002' - }, - mediaTypes: { - banner: { - sizes: [300, 50], - pos: 1 - } - } -}; - -const VALID_BID_VIDEO = { - bidder: 'viously', - bidId: '5e6f7g8h', - adUnitCode: 'id-5678', - params: { - pid: '123e4567-e89b-12d3-a456-426614174001' - }, - mediaTypes: { - video: { - playerSize: [640, 360], - context: 'instream', - playbackmethod: [1, 2, 3, 4] - } - } -}; - -const VALID_REQUEST_BANNER = { - method: HTTP_METHOD, - url: REQUEST_URL, - data: { - pid: '123e4567-e89b-12d3-a456-426614174002', - currency_code: CURRENCY, - placements: [ - { - id: 'id-5678', - bid_id: '5e6f7g8h', - sizes: ['300x50'], - type: BANNER, - position: 1 - } - ] - } -}; - -const VALID_REQUEST_VIDEO = { - method: HTTP_METHOD, - url: REQUEST_URL, - data: { - pid: '123e4567-e89b-12d3-a456-426614174001', - currency_code: CURRENCY, - placements: [ - { - id: 'id-5678', - bid_id: '5e6f7g8h', - type: VIDEO, - video_params: { - context: 'instream', - playbackmethod: [1, 2, 3, 4], - size: ['640x360'] - } - } - ] - } -}; - -const VALID_GDPR = { - gdprApplies: true, - apiVersion: 2, - consentString: 'abcdefgh', - addtlConsent: '1~12345678', - vendorData: { - purpose: { - consents: { - 1: true - } - } - } -}; -const US_PRIVACY = '1YNN'; - -describe('ViouslyAdapter', function () { - describe('isBidRequestValid', function () { - describe('Check method return', function () { - it('should return true', function () { - expect(adapter.isBidRequestValid(VALID_BID_BANNER)).to.equal(true); - expect(adapter.isBidRequestValid(VALID_BID_VIDEO)).to.equal(true); - }); - - it('should return true for banner with no pos', function () { - const newBid = deepClone(VALID_BID_BANNER); - const newRequest = deepClone(VALID_REQUEST_BANNER); - - delete newBid.mediaTypes.banner.pos; - newRequest.data.placements[0].position = 0; - - expect(adapter.buildRequests([newBid])).to.deep.equal(newRequest); - }); - - it('should return false because the banner size is missing', function () { - const wrongBid = deepClone(VALID_BID_BANNER); - - wrongBid.mediaTypes.banner.sizes = '123456'; - expect(adapter.isBidRequestValid(wrongBid)).to.equal(false); - - delete wrongBid.mediaTypes.banner.sizes; - expect(adapter.isBidRequestValid(wrongBid)).to.equal(false); - }); - - it('should return false because the pid is missing', function () { - const wrongBid = deepClone(VALID_BID_VIDEO); - delete wrongBid.params.pid; - - expect(adapter.isBidRequestValid(wrongBid)).to.equal(false); - }); - - it('should return false because the video context parameter is missing', function () { - const wrongBid = deepClone(VALID_BID_VIDEO); - - delete wrongBid.mediaTypes.video.context; - expect(adapter.isBidRequestValid(wrongBid)).to.equal(false); - }); - }); - }); - - describe('buildRequests', function () { - describe('Check method return', function () { - it('should return the right formatted banner requests', function() { - expect(adapter.buildRequests([VALID_BID_BANNER])).to.deep.equal(VALID_REQUEST_BANNER); - }); - - it('should return the right formatted video requests', function() { - expect(adapter.buildRequests([VALID_BID_VIDEO])).to.deep.equal(VALID_REQUEST_VIDEO); - }); - - it('should return the right formatted request with the referer info', function() { - const bidderRequest = { - refererInfo: { - page: 'https://www.example.com/test' - } - }; - - const requests = mergeDeep(deepClone(VALID_REQUEST_VIDEO), { - data: { - domain: 'www.example.com', - page_domain: 'https://www.example.com/test' - } - }); - - expect(adapter.buildRequests([VALID_BID_VIDEO], bidderRequest)).to.deep.equal(requests); - }); - - it('should return the right formatted request with the referer info from config', function() { - /** Mock the config.getConfig method */ - sinon.stub(config, 'getConfig') - .withArgs('pageUrl') - .returns('https://www.example.com/page'); - - const requests = mergeDeep(deepClone(VALID_REQUEST_VIDEO), { - data: { - domain: 'www.example.com', - page_domain: 'https://www.example.com/page' - } - }); - - expect(adapter.buildRequests([VALID_BID_VIDEO])).to.deep.equal(requests); - - config.getConfig.restore(); - }); - - it('should return the right formatted request with GDPR Consent info', function() { - const bidderRequest = { - gdprConsent: VALID_GDPR - }; - - const requests = mergeDeep(deepClone(VALID_REQUEST_VIDEO), { - data: { - gdpr: true, - gdpr_consent: 'abcdefgh', - addtl_consent: '1~12345678' - } - }); - - expect(adapter.buildRequests([VALID_BID_VIDEO], bidderRequest)).to.deep.equal(requests); - }); - - it('should return the right formatted request with US Privacy info', function() { - const bidderRequest = { - uspConsent: US_PRIVACY - }; - - const requests = mergeDeep(deepClone(VALID_REQUEST_VIDEO), { - data: { - us_privacy: US_PRIVACY - } - }); - - expect(adapter.buildRequests([VALID_BID_VIDEO], bidderRequest)).to.deep.equal(requests); - }); - - // TODO: Supply chain - it('should return the right formatted request with Supply Chain info', function() { - const schain = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'test1.com', - 'sid': '00001', - 'hp': 1 - }, - { - 'asi': 'test2-2.com', - 'sid': '00002', - 'hp': 2 - } - ] - }; - - const bid = mergeDeep(deepClone(VALID_BID_VIDEO), { - ortb2: { - source: { - ext: { - schain: schain - } - } - } - }); - - const requests = mergeDeep(deepClone(VALID_REQUEST_VIDEO), { - data: { - schain: schain - } - }); - - expect(adapter.buildRequests([bid])).to.deep.equal(requests); - }); - - it('should return the right formatted request with User Ids info', function() { - const userIds = { - idl_env: '1234-5678-9012-3456', // Liveramp - netId: 'testnetid123', // NetId - IDP: 'userIDP000', // IDP - fabrickId: 'fabrickId9000', // FabrickId - uid2: { id: 'testuid2' } // UID 2.0 - }; - - const bid = mergeDeep(deepClone(VALID_BID_VIDEO), { - userIds: userIds - }, { - userIdAsEids: createEidsArray(userIds) - }); - - const requests = mergeDeep(deepClone(VALID_REQUEST_VIDEO), { - data: { - users_uid: createEidsArray(userIds) - } - }); - - expect(adapter.buildRequests([bid])).to.deep.equal(requests); - }); - - it('should return the right formatted request with endpoint test', function() { - const endpoint = 'https://bid-test.viously.com/prebid'; - - const bid = mergeDeep(deepClone(VALID_BID_VIDEO), { - params: { - endpoint: endpoint - } - }); - - const requests = mergeDeep(deepClone(VALID_REQUEST_VIDEO)); - - requests.url = endpoint; - - expect(adapter.buildRequests([bid])).to.deep.equal(requests); - }); - - // TODO: Floor - }); - }); - - describe('interpretResponse', function() { - describe('Check method return', function () { - it('should return the right formatted response', function() { - const response = { - body: { - ads: [ - { - bid: false, - id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-0', - bid_id: '1234' - }, - { - bid: true, - creative_id: '2468', - id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-1', - bid_id: '5678', - cpm: 8, - ad: 'vast xml', - ad_url: 'http://www.example.com/vast', - type: 'video', - size: '640x480', - nurl: [ - 'win.domain.com' - ] - }, - { - bid: true, - creative_id: '1357', - id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-2', - bid_id: '9101112', - cpm: 1.5, - ad: 'html content', - type: 'banner', - size: '300x50', - nurl: [ - 'win.domain2.com', - 'win.domain3.com' - ] - }, - { - bid: true, - creative_id: '1469', - id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-3', - bid_id: '2570', - cpm: 4, - ad: 'vast xml', - type: 'video', - size: '640x480', - } - ] - } - }; - const requests = { - data: { - placements: [ - { - id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-0', - bid_id: '1234' - }, - { - id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-1', - bid_id: '5678' - }, - { - id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-2', - bid_id: '9101112' - }, - { - id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-3', - bid_id: '2570' - } - ] - } - }; - - const formattedReponse = [ - { - requestId: '5678', - id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-1', - cpm: 8, - width: '640', - height: '480', - creativeId: '2468', - currency: CURRENCY, - netRevenue: true, - ttl: TTL, - mediaType: 'video', - meta: {}, - vastUrl: 'http://www.example.com/vast', - nurl: [ - 'win.domain.com' - ] - }, - { - requestId: '9101112', - id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-2', - cpm: 1.5, - width: '300', - height: '50', - creativeId: '1357', - currency: CURRENCY, - netRevenue: true, - ttl: TTL, - mediaType: 'banner', - meta: {}, - ad: 'html content', - nurl: [ - 'win.domain2.com', - 'win.domain3.com' - ] - }, - { - requestId: '2570', - id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-3', - cpm: 4, - width: '640', - height: '480', - creativeId: '1469', - currency: CURRENCY, - netRevenue: true, - ttl: TTL, - mediaType: 'video', - meta: {}, - vastXml: 'vast xml', - nurl: [] - } - ]; - - expect(adapter.interpretResponse(response, requests)).to.deep.equal(formattedReponse); - }); - }); - }); - - describe('onBidWon', function() { - describe('Check methods succeed', function () { - it('should not throw error', function() { - const bids = [ - { - requestId: '5678', - id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-1', - cpm: 8, - width: '640', - height: '480', - creativeId: '2468', - currency: CURRENCY, - netRevenue: true, - ttl: TTL, - mediaType: 'video', - meta: {}, - vastUrl: 'http://www.example.com/vast', - nurl: [ - 'win.domain.com' - ] - }, - { - requestId: '2570', - id: 'id-0157324f-bee4-5390-a14c-47a7da3eb73c-3', - cpm: 4, - width: '640', - height: '480', - creativeId: '1469', - currency: CURRENCY, - netRevenue: true, - ttl: TTL, - mediaType: 'video', - meta: {}, - vastXml: 'vast xml', - nurl: [] - } - ]; - - bids.forEach(function(bid) { - expect(adapter.onBidWon.bind(adapter, bid)).to.not.throw(); - }); - }); - }); - }); -}); diff --git a/test/spec/modules/a1MediaBidAdapter_spec.js b/test/spec/modules/a1MediaBidAdapter_spec.js deleted file mode 100644 index 3c5fa14c6..000000000 --- a/test/spec/modules/a1MediaBidAdapter_spec.js +++ /dev/null @@ -1,249 +0,0 @@ -import { spec } from 'modules/a1MediaBidAdapter.js'; -import { config } from 'src/config.js'; -import { BANNER, VIDEO, NATIVE } from 'src/mediaTypes.js'; -import 'modules/currency.js'; -import 'modules/priceFloors.js'; -import { replaceAuctionPrice } from '../../../src/utils.js'; - -const ortbBlockParams = { - battr: [ 13 ], - bcat: ['IAB1-1'] -}; -const getBidderRequest = (isMulti = false) => { - return { - bidderCode: 'a1media', - auctionId: 'ba87bfdf-493e-4a88-8e26-17b4cbc9adbd', - bidderRequestId: '104e8d2392bd6f', - bids: [ - { - bidder: 'a1media', - params: {}, - auctionId: 'ba87bfdf-493e-4a88-8e26-17b4cbc9adbd', - mediaTypes: { - banner: { - sizes: [ - [ 320, 100 ], - ] - }, - ...(isMulti && { - video: { - mimes: ['video/mp4'] - }, - native: { - title: { - required: true, - }} - }) - }, - ...(isMulti && { - nativeOrtbRequest: { - ver: '1.2', - assets: [ - { - id: 0, - required: 1, - title: { - len: 140 - } - } - ] - } - }), - adUnitCode: 'test-div', - transactionId: 'cab00498-028b-4061-8f9d-a8d66c8cb91d', - bidId: '2e9f38ea93bb9e', - bidderRequestId: '104e8d2392bd6f', - } - ], - } -}; -const getConvertedBidReq = () => { - return { - cur: [ - 'JPY' - ], - imp: [ - { - banner: { - format: [ - { - h: 100, - w: 320 - }, - ], - topframe: 0 - }, - bidfloor: 0, - bidfloorcur: 'JPY', - id: '2e9f38ea93bb9e', - secure: 1 - } - ], - test: 0, - } -}; - -const getBidderResponse = () => { - return { - body: { - id: 'bid-response', - cur: 'JPY', - seatbid: [ - { - bid: [{ - impid: '2e9f38ea93bb9e', - crid: 'creative-id', - cur: 'JPY', - price: 9, - }] - } - ] - } - } -} -const bannerAdm = '
'; -const videoAdm = 'testvast1'; -const nativeAdm = '{"ver":"1.2","link":{"url":"test_url"},"assets":[{"id":1,"required":1,"title":{"text":"native_title"}}]}'; -const macroAdm = '
'; -const macroNurl = 'https://d11.contentsfeed.com/dsp/win/example.com/SITE/a1/${AUCTION_PRICE}'; -const interpretedNurl = `
`; - -describe('a1MediaBidAdapter', function() { - describe('isValidRequest', function() { - const bid = { - bidder: 'a1media', - }; - - it('should return true always', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - - describe('buildRequests', function() { - let bidderRequest, convertedRequest; - beforeEach(function() { - bidderRequest = getBidderRequest(); - convertedRequest = getConvertedBidReq(); - }); - - it('should return expected request object', function() { - const bidRequest = spec.buildRequests(bidderRequest.bids, bidderRequest); - convertedRequest.id = bidRequest.data.id; - - expect(bidRequest.method).equal('POST'); - expect(bidRequest.url).equal('https://d11.contentsfeed.com/dsp/breq/a1'); - expect(bidRequest.data).deep.equal(convertedRequest); - }); - it('should set ortb blocking using params', function() { - bidderRequest.bids[0].params = ortbBlockParams; - - const bidRequest = spec.buildRequests(bidderRequest.bids, bidderRequest); - convertedRequest.id = bidRequest.data.id; - convertedRequest.bcat = ortbBlockParams.bcat; - convertedRequest.imp[0].banner.battr = ortbBlockParams.battr; - - expect(bidRequest.data).deep.equal(convertedRequest); - }); - - it('should set bidfloor when getFloor is available', function() { - bidderRequest.bids[0].getFloor = () => ({ currency: 'USD', floor: 999 }); - const bidRequest = spec.buildRequests(bidderRequest.bids, bidderRequest); - - expect(bidRequest.data.imp[0].bidfloor).equal(999); - expect(bidRequest.data.imp[0].bidfloorcur).equal('USD'); - }); - - it('should set cur when currency config is configured', function() { - config.setConfig({ - currency: { - adServerCurrency: 'USD', - } - }); - const bidRequest = spec.buildRequests(bidderRequest.bids, bidderRequest); - - expect(bidRequest.data.cur[0]).equal('USD'); - }); - - it('should set bidfloor and currency using params when modules not available', function() { - bidderRequest.bids[0].params.currency = 'USD'; - bidderRequest.bids[0].params.bidfloor = 0.99; - - const bidRequest = spec.buildRequests(bidderRequest.bids, bidderRequest); - convertedRequest.id = bidRequest.data.id; - convertedRequest.imp[0].bidfloor = 0.99; - convertedRequest.imp[0].bidfloorcur = 'USD'; - convertedRequest.cur[0] = 'USD'; - - expect(bidRequest.data).deep.equal(convertedRequest); - }); - }); - - describe('interpretResponse', function() { - describe('when request mediaType is single', function() { - let bidRequest, bidderResponse; - beforeEach(function() { - const bidderRequest = getBidderRequest(); - bidRequest = spec.buildRequests(bidderRequest.bids, bidderRequest); - bidderResponse = getBidderResponse(); - }); - it('should set cpm using price attribute', function() { - const bidResPrice = 9; - bidderResponse.body.seatbid[0].bid[0].price = bidResPrice; - const interpretedRes = spec.interpretResponse(bidderResponse, bidRequest); - expect(interpretedRes[0].cpm).equal(bidResPrice); - }); - it('should set mediaType using request mediaTypes', function() { - const interpretedRes = spec.interpretResponse(bidderResponse, bidRequest); - expect(interpretedRes[0].mediaType).equal(BANNER); - }); - }); - - describe('when request mediaType is multi', function() { - let bidRequest, bidderResponse; - beforeEach(function() { - const bidderRequest = getBidderRequest(true); - bidRequest = spec.buildRequests(bidderRequest.bids, bidderRequest); - bidderResponse = getBidderResponse(); - }); - it('should set mediaType to video', function() { - bidderResponse.body.seatbid[0].bid[0].adm = videoAdm; - const interpretedRes = spec.interpretResponse(bidderResponse, bidRequest); - expect(interpretedRes[0].mediaType).equal(VIDEO); - }); - it('should set mediaType to native', function() { - bidderResponse.body.seatbid[0].bid[0].adm = nativeAdm; - const interpretedRes = spec.interpretResponse(bidderResponse, bidRequest); - expect(interpretedRes[0].mediaType).equal(NATIVE); - }); - it('should set mediaType to banner when adm is neither native or video', function() { - bidderResponse.body.seatbid[0].bid[0].adm = bannerAdm; - const interpretedRes = spec.interpretResponse(bidderResponse, bidRequest); - expect(interpretedRes[0].mediaType).equal(BANNER); - }); - }); - - describe('resolve the AUCTION_PRICE macro', function() { - let bidRequest; - beforeEach(function() { - const bidderRequest = getBidderRequest(true); - bidRequest = spec.buildRequests(bidderRequest.bids, bidderRequest); - }); - it('should return empty array when bid response has not contents', function() { - const emptyResponse = { body: '' }; - const interpretedRes = spec.interpretResponse(emptyResponse, bidRequest); - expect(interpretedRes.length).equal(0); - }); - it('should replace macro keyword if is exist', function() { - const bidderResponse = getBidderResponse(); - bidderResponse.body.seatbid[0].bid[0].adm = macroAdm; - bidderResponse.body.seatbid[0].bid[0].nurl = macroNurl; - const interpretedRes = spec.interpretResponse(bidderResponse, bidRequest); - - const expectedResPrice = 9; - const expectedAd = replaceAuctionPrice(interpretedNurl, expectedResPrice) + replaceAuctionPrice(macroAdm, expectedResPrice); - - expect(interpretedRes[0].ad).equal(expectedAd); - }); - }); - }); -}) diff --git a/test/spec/modules/a1MediaRtdProvider_spec.js b/test/spec/modules/a1MediaRtdProvider_spec.js deleted file mode 100644 index f313062b1..000000000 --- a/test/spec/modules/a1MediaRtdProvider_spec.js +++ /dev/null @@ -1,105 +0,0 @@ -import { subModuleObj } from 'modules/a1MediaRtdProvider.js'; -import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; -import { A1_AUD_KEY, A1_SEG_KEY, getStorageData, storage } from '../../../modules/a1MediaRtdProvider.js'; -import { expect } from 'chai'; - -const configWithParams = { - name: 'a1Media', - waitForIt: true, - params: { - tagId: 'lb4test.min.js', - }, -}; -const configWithoutParams = { - name: 'a1Media', - waitForIt: true, - params: { - }, -}; - -const reqBidsConfigObj = { - ortb2Fragments: { - global: {} - } -}; -const a1TestOrtbObj = { - user: { - data: [ - { - name: 'a1mediagroup.com', - ext: { - segtax: 900 - }, - segment: [{id: 'test'}] - } - ], - ext: { - eids: [ - { - source: 'a1mediagroup.com', - uids: [ - { - id: 'tester', - atype: 1 - } - ] - } - ] - } - } -}; - -describe('a1MediaRtdProvider', function() { - describe('init', function() { - describe('initialize with expected params', function() { - it('successfully initialize with load script', function() { - expect(subModuleObj.init(configWithParams)).to.be.true; - expect(window.linkback.l).to.be.true; - expect(loadExternalScriptStub.called).to.be.true; - expect(loadExternalScriptStub.args[0][0]).to.deep.equal('https://linkback.contentsfeed.com/src/lb4test.min.js'); - }) - - it('successfully initialize but script is already exist', function() { - const linkback = { l: true }; - - expect(subModuleObj.init(configWithParams)).to.be.true; - expect(loadExternalScriptStub.called).to.be.false; - }) - }); - - describe('initialize without expected params', function() { - afterEach(function() { - storage.setCookie(A1_SEG_KEY, '', 0); - }) - - it('successfully initialize when publisher side segment is exist in cookie', function() { - storage.setCookie(A1_SEG_KEY, 'test'); - expect(subModuleObj.init(configWithoutParams)).to.be.true; - expect(getStorageData(A1_SEG_KEY)).to.not.equal(''); - }) - it('fails to initialize when publisher side segment does not exist', function() { - expect(subModuleObj.init(configWithoutParams)).to.be.false; - expect(getStorageData(A1_SEG_KEY)).to.equal(''); - }) - }) - }); - - describe('alterBidRequests', function() { - const callback = sinon.stub(); - - before(function() { - storage.setCookie(A1_SEG_KEY, 'test'); - storage.setDataInLocalStorage(A1_AUD_KEY, 'tester'); - }) - after(function() { - storage.setCookie(A1_SEG_KEY, '', 0); - storage.removeDataFromLocalStorage(A1_AUD_KEY); - }) - - it('alterBidRequests', function() { - subModuleObj.getBidRequestData(reqBidsConfigObj, callback); - expect(reqBidsConfigObj.ortb2Fragments.global).to.deep.include(a1TestOrtbObj); - expect(callback.calledOnce).to.be.true; - }) - }); -}) diff --git a/test/spec/modules/a4gBidAdapter_spec.js b/test/spec/modules/a4gBidAdapter_spec.js deleted file mode 100644 index b08462df1..000000000 --- a/test/spec/modules/a4gBidAdapter_spec.js +++ /dev/null @@ -1,235 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/a4gBidAdapter.js'; -import * as utils from 'src/utils.js'; - -describe('a4gAdapterTests', function () { - describe('bidRequestValidity', function () { - it('bidRequest with zoneId and deliveryUrl params', function () { - expect(spec.isBidRequestValid({ - bidder: 'a4g', - params: { - zoneId: 59304, - deliveryUrl: 'http://dev01.ad4game.com/v1/bid' - } - })).to.equal(true); - }); - - it('bidRequest with only zoneId', function () { - expect(spec.isBidRequestValid({ - bidder: 'a4g', - params: { - zoneId: 59304 - } - })).to.equal(true); - }); - - it('bidRequest with only deliveryUrl', function () { - expect(spec.isBidRequestValid({ - bidder: 'a4g', - params: { - deliveryUrl: 'http://dev01.ad4game.com/v1/bid' - } - })).to.equal(false); - }); - }); - - describe('bidRequest', function () { - const DEFAULT_OPTION = { - refererInfo: { - referer: 'https://www.prebid.org', - canonicalUrl: 'https://www.prebid.org/the/link/to/the/page' - } - }; - - const bidRequests = [{ - 'bidder': 'a4g', - 'bidId': '51ef8751f9aead', - 'params': { - 'zoneId': 59304, - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 50], [300, 250], [300, 600]] - } - }, - 'sizes': [[320, 50], [300, 250], [300, 600]], - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757' - }, { - 'bidder': 'a4g', - 'bidId': '51ef8751f9aead', - 'params': { - 'zoneId': 59354, - 'deliveryUrl': '//dev01.ad4game.com/v1/bid' - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 50], [300, 250], [300, 600]] - } - }, - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757' - }]; - - it('bidRequest method', function () { - const request = spec.buildRequests(bidRequests, DEFAULT_OPTION); - expect(request.method).to.equal('GET'); - }); - - it('bidRequest url', function () { - const request = spec.buildRequests(bidRequests, DEFAULT_OPTION); - expect(request.url).to.match(new RegExp(`${bidRequests[1].params.deliveryUrl}`)); - }); - - it('bidRequest data', function () { - const request = spec.buildRequests(bidRequests, DEFAULT_OPTION); - expect(request.data).to.exist; - }); - - it('bidRequest zoneIds', function () { - const request = spec.buildRequests(bidRequests, DEFAULT_OPTION); - expect(request.data.zoneId).to.equal('59304;59354'); - }); - - it('bidRequest gdpr consent', function () { - const consentString = 'consentString'; - const bidderRequest = { - bidderCode: 'a4g', - auctionId: '18fd8b8b0bd757', - bidderRequestId: '418b37f85e772c', - timeout: 3000, - gdprConsent: { - consentString: consentString, - gdprApplies: true - }, - refererInfo: { - referer: 'https://www.prebid.org', - canonicalUrl: 'https://www.prebid.org/the/link/to/the/page' - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.gdpr).to.exist; - expect(request.data.gdpr.applies).to.exist.and.to.be.true; - expect(request.data.gdpr.consent).to.exist.and.to.equal(consentString); - }); - }); - - describe('interpretResponse', function () { - const bidRequest = [{ - 'bidder': 'a4g', - 'bidId': '51ef8751f9aead', - 'params': { - 'zoneId': 59304, - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 50], [300, 250], [300, 600]] - } - }, - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757' - }]; - - const bidResponse = { - body: [{ - 'id': '51ef8751f9aead', - 'ad': 'test ad', - 'width': 320, - 'height': 250, - 'cpm': 5.2, - 'crid': '111' - }], - headers: {} - }; - - it('should get correct bid response for banner ad', function () { - const expectedParse = [ - { - requestId: '51ef8751f9aead', - cpm: 5.2, - creativeId: '111', - width: 320, - height: 250, - ad: 'test ad', - currency: 'USD', - ttl: 120, - netRevenue: true, - meta: { - advertiserDomains: [] - } - - } - ]; - const result = spec.interpretResponse(bidResponse, bidRequest); - expect(result[0]).to.deep.equal(expectedParse[0]); - }); - - it('should set creativeId to default value if not provided', function () { - const bidResponseWithoutCrid = utils.deepClone(bidResponse); - delete bidResponseWithoutCrid.body[0].crid; - const expectedParse = [ - { - requestId: '51ef8751f9aead', - cpm: 5.2, - creativeId: '51ef8751f9aead', - width: 320, - height: 250, - ad: 'test ad', - currency: 'USD', - ttl: 120, - netRevenue: true, - meta: { - advertiserDomains: [] - } - } - ]; - const result = spec.interpretResponse(bidResponseWithoutCrid, bidRequest); - expect(result[0]).to.deep.equal(expectedParse[0]); - }) - - it('required keys', function () { - const result = spec.interpretResponse(bidResponse, bidRequest); - - const requiredKeys = [ - 'requestId', - 'creativeId', - 'adId', - 'cpm', - 'width', - 'height', - 'currency', - 'netRevenue', - 'ttl', - 'ad', - 'meta' - ]; - - const resultKeys = Object.keys(result[0]); - resultKeys.forEach(function(key) { - expect(requiredKeys.indexOf(key) !== -1).to.equal(true); - }); - }) - - it('adId should not be equal to requestId', function () { - const result = spec.interpretResponse(bidResponse, bidRequest); - - expect(result[0].requestId).to.not.equal(result[0].adId); - }) - - it('advertiserDomains is included when sent by server', function () { - bidResponse.body[0].adomain = ['test_adomain']; - const response = spec.interpretResponse(bidResponse, bidRequest); - expect(Object.keys(response[0].meta)).to.include.members(['advertiserDomains']); - expect(response[0].meta.advertiserDomains).to.deep.equal(['test_adomain']); - delete bidResponse.body[0].adomain; - }); - }); -}); diff --git a/test/spec/modules/ablidaBidAdapter_spec.js b/test/spec/modules/ablidaBidAdapter_spec.js deleted file mode 100644 index f5e633369..000000000 --- a/test/spec/modules/ablidaBidAdapter_spec.js +++ /dev/null @@ -1,151 +0,0 @@ -import {assert, expect} from 'chai'; -import {spec} from 'modules/ablidaBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import * as utils from 'src/utils.js'; - -const ENDPOINT_URL = 'https://bidder.ablida.net/prebid'; - -describe('ablidaBidAdapter', function () { - const adapter = newBidder(spec); - describe('isBidRequestValid', function () { - const bid = { - adUnitCode: 'adunit-code', - auctionId: '69e8fef8-5105-4a99-b011-d5669f3bc7f0', - bidRequestsCount: 1, - bidder: 'ablida', - bidderRequestId: '14d2939272a26a', - bidderRequestsCount: 1, - bidderWinsCount: 0, - bidId: '1234asdf1234', - mediaTypes: {banner: {sizes: [[300, 250]]}}, - params: { - placementId: 123 - }, - sizes: [ - [300, 250] - ], - src: 'client', - transactionId: '4781e6ac-93c4-42ba-86fe-ab5f278863cf' - }; - it('should return true where required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - describe('buildRequests', function () { - const bidRequests = [ - { - adUnitCode: 'adunit-code', - auctionId: '69e8fef8-5105-4a99-b011-d5669f3bc7f0', - bidId: '23beaa6af6cdde', - bidRequestsCount: 1, - bidder: 'ablida', - bidderRequestId: '14d2939272a26a', - bidderRequestsCount: 1, - bidderWinsCount: 0, - mediaTypes: {banner: {sizes: [[300, 250]]}}, - params: { - placementId: 123 - }, - sizes: [ - [300, 250] - ], - src: 'client', - transactionId: '4781e6ac-93c4-42ba-86fe-ab5f278863cf' - } - ]; - - const bidderRequests = { - refererInfo: { - canonicalUrl: '', - numIframes: 0, - reachedTop: true, - referer: 'http://example.com', - stack: ['http://example.com'] - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequests); - it('sends bid request via POST', function () { - expect(request[0].method).to.equal('POST'); - }); - }); - - describe('interpretResponse', function () { - const bidRequest = { - method: 'POST', - url: ENDPOINT_URL, - data: { - adapterVersion: 5, - bidId: '2b8c4de0116e54', - categories: undefined, - device: 'desktop', - gdprConsent: undefined, - jaySupported: true, - mediaTypes: {banner: {sizes: [[300, 250]]}}, - placementId: 'testPlacementId', - width: 300, - height: 200, - referer: 'www.example.com' - } - }; - const serverResponse = { - body: [{ - ad: '', - cpm: 1.00, - creativeId: '2b8c4de0116e54', - currency: 'EUR', - height: 250, - mediaType: 'banner', - meta: {}, - netRevenue: true, - nurl: 'https://example.com/some-tracker', - originalCpm: '0.10', - originalCurrency: 'EUR', - requestId: '2b8c4de0116e54', - ttl: 3000, - width: 300 - }] - }; - it('should get the correct bid response', function () { - const expectedResponse = [{ - ad: '', - cpm: 1.00, - creativeId: '2b8c4de0116e54', - currency: 'EUR', - height: 250, - mediaType: 'banner', - meta: {}, - netRevenue: true, - nurl: 'https://example.com/some-tracker', - originalCpm: '0.10', - originalCurrency: 'EUR', - requestId: '2b8c4de0116e54', - ttl: 3000, - width: 300 - }]; - const result = spec.interpretResponse(serverResponse, bidRequest[0]); - expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); - }); - }); - - describe('onBidWon', function() { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - - it('Should not trigger pixel if bid does not contain nurl', function() { - const result = spec.onBidWon({}); - expect(utils.triggerPixel.callCount).to.equal(0) - }) - - it('Should trigger pixel if bid nurl', function() { - const result = spec.onBidWon({ - nurl: 'https://example.com/some-tracker' - }); - expect(utils.triggerPixel.callCount).to.equal(1) - }) - }) -}); diff --git a/test/spec/modules/acuityadsBidAdapter_spec.js b/test/spec/modules/acuityadsBidAdapter_spec.js deleted file mode 100644 index e37b6913c..000000000 --- a/test/spec/modules/acuityadsBidAdapter_spec.js +++ /dev/null @@ -1,566 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/acuityadsBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'acuityads'; - -describe('AcuityAdsBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://prebid.admanmedia.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - expect(placement.publisherId).to.exist.and.to.be.a('string'); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - let serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.admanmedia.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.admanmedia.com/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.admanmedia.com/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/ad2ictionBidAdapter_spec.js b/test/spec/modules/ad2ictionBidAdapter_spec.js deleted file mode 100644 index 99800c6dd..000000000 --- a/test/spec/modules/ad2ictionBidAdapter_spec.js +++ /dev/null @@ -1,223 +0,0 @@ -import { expect } from 'chai'; -import { - spec, - API_ENDPOINT, - API_VERSION_NUMBER, -} from 'modules/ad2ictionBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; - -describe('ad2ictionBidAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - bidder: 'ad2iction', - params: { id: '11ab384c-e936-11ed-a6a7-f23c9173ed43' }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [336, 280], - ], - }, - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250], - [336, 280], - ], - bidId: '2a7a3b48778a1b', - bidderRequestId: '1e6509293abe6b', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when params id is not valid (letters)', function () { - const mockBid = { - ...bid, - params: { id: 1234 }, - }; - - expect(spec.isBidRequestValid(mockBid)).to.equal(false); - }); - - it('should return false when params id is not exist', function () { - const mockBid = { - ...bid, - }; - delete mockBid.params.id; - - expect(spec.isBidRequestValid(mockBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const mockValidBidRequests = [ - { - bidder: 'ad2iction', - params: { id: '11ab384c-e936-11ed-a6a7-f23c9173ed43' }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250], - [336, 280], - ], - bidId: '57ffc0667379e1', - bidderRequestId: '4ddea14478a651', - }, - ]; - - const mockBidderRequest = { - bidderCode: 'ad2iction', - bidderRequestId: '4ddea14478a651', - bids: [ - { - bidder: 'ad2iction', - params: { id: '11ab384c-e936-11ed-a6a7-f23c9173ed43' }, - adUnitCode: 'adunit-code', - transactionId: null, - sizes: [ - [300, 250], - [336, 280], - ], - bidId: '57ffc0667379e1', - bidderRequestId: '4ddea14478a651', - }, - ], - timeout: 1200, - refererInfo: { - ref: 'https://example.com/referer.html', - }, - ortb2: { - source: {}, - site: { - ref: 'https://example.com/referer.html', - }, - device: { - w: 390, - h: 844, - language: 'zh', - }, - }, - start: 1702526505498, - }; - - it('should send bid request to API_ENDPOINT via POST', function () { - const request = spec.buildRequests( - mockValidBidRequests, - mockBidderRequest - ); - - expect(request.url).to.equal(API_ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('should send bid request with API version', function () { - const request = spec.buildRequests( - mockValidBidRequests, - mockBidderRequest - ); - - expect(request.data.v).to.equal(API_VERSION_NUMBER); - }); - - it('should send bid request with dada fields', function () { - const request = spec.buildRequests( - mockValidBidRequests, - mockBidderRequest - ); - - expect(request.data).to.include.all.keys('udid', '_'); - expect(request.data).to.have.property('refererInfo'); - expect(request.data).to.have.property('ortb2'); - }); - }); - - describe('interpretResponse', function () { - it('should return an empty array to indicate no valid bids', function () { - const mockServerResponse = {}; - - const bidResponses = spec.interpretResponse(mockServerResponse); - - expect(bidResponses).is.an('array').that.is.empty; - }); - - it('should return a valid bid response', function () { - const MOCK_AD_DOM = "
" - const mockServerResponse = { - body: [ - { - requestId: '23a3d87fb6bde9', - cpm: 1.61, - currency: 'USD', - width: '336', - height: '280', - creativeId: '46271', - netRevenue: 'false', - ad: MOCK_AD_DOM, - meta: { - advertiserDomains: [''], - }, - ttl: 360, - }, - { - requestId: '3ce3efc40c890b', - cpm: 1.61, - currency: 'USD', - width: '336', - height: '280', - creativeId: '46271', - netRevenue: 'false', - ad: MOCK_AD_DOM, - meta: { - advertiserDomains: [''], - }, - ttl: 360, - }, - ], - }; - - const exceptServerResponse = [ - { - requestId: '23a3d87fb6bde9', - cpm: 1.61, - currency: 'USD', - width: '336', - height: '280', - creativeId: '46271', - netRevenue: 'false', - ad: MOCK_AD_DOM, - meta: { - advertiserDomains: [''], - }, - ttl: 360, - }, - { - requestId: '3ce3efc40c890b', - cpm: 1.61, - currency: 'USD', - width: '336', - height: '280', - creativeId: '46271', - netRevenue: 'false', - ad: MOCK_AD_DOM, - meta: { - advertiserDomains: [''], - }, - ttl: 360, - }, - ] - - const bidResponses = spec.interpretResponse(mockServerResponse); - - expect(bidResponses).to.eql(exceptServerResponse); - }); - }); -}); diff --git a/test/spec/modules/adWMGAnalyticsAdapter_spec.js b/test/spec/modules/adWMGAnalyticsAdapter_spec.js deleted file mode 100644 index d766a0f8b..000000000 --- a/test/spec/modules/adWMGAnalyticsAdapter_spec.js +++ /dev/null @@ -1,178 +0,0 @@ -import adWMGAnalyticsAdapter from 'modules/adWMGAnalyticsAdapter.js'; -import { expect } from 'chai'; -import { server } from 'test/mocks/xhr.js'; -import {expectEvents} from '../../helpers/analytics.js'; -import {EVENTS} from 'src/constants.js'; -const adapterManager = require('src/adapterManager').default; -const events = require('src/events'); - -describe('adWMG Analytics', function () { - const timestamp = new Date() - 256; - const auctionId = '5018eb39-f900-4370-b71e-3bb5b48d324f'; - const timeout = 1500; - - const bidTimeoutArgs = [ - { - bidId: '2baa51527bd015', - bidder: 'bidderA', - adUnitCode: '/19968336/header-bid-tag-0', - auctionId: '66529d4c-8998-47c2-ab3e-5b953490b98f' - }, - { - bidId: '6fe3b4c2c23092', - bidder: 'bidderB', - adUnitCode: '/19968336/header-bid-tag-0', - auctionId: '66529d4c-8998-47c2-ab3e-5b953490b98f' - } - ]; - - const bidResponse = { - bidderCode: 'bidderA', - adId: '208750227436c1', - mediaTypes: ['banner'], - cpm: 0.015, - auctionId: auctionId, - responseTimestamp: 1509369418832, - requestTimestamp: 1509369418389, - bidder: 'bidderA', - timeToRespond: 443, - size: '300x250', - width: 300, - height: 250, - }; - - const wonRequest = { - 'adId': '4587fec4900b81', - 'mediaType': 'banner', - 'requestId': '4587fec4900b81', - 'cpm': 1.962, - 'creativeId': 2126, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 302, - 'auctionId': '914bedad-b145-4e46-ba58-51365faea6cb', - 'statusMessage': 'Bid available', - 'responseTimestamp': 1530628534437, - 'requestTimestamp': 1530628534219, - 'bidder': 'bidderB', - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'sizes': [[300, 250]], - 'size': [300, 250], - }; - - const expectedBidWonData = { - publisher_id: '5abd0543ba45723db49d97ea', - site: 'test.com', - ad_unit_size: ['300,250'], - ad_unit_type: ['banner'], - c_timeout: 1500, - events: [ - { - status: 'bidWon', - bids: [ - { - bidder: 'bidderB', - auction_id: '914bedad-b145-4e46-ba58-51365faea6cb', - ad_unit_code: 'div-gpt-ad-1438287399331-0', - transaction_id: '', - bid_size: ['300,250'], - bid_type: ['banner'], - time_ms: 256, - cur: 'USD', - price: '1.96', - cur_native: '', - price_native: '' - } - ] - } - ] - } - - const adUnits = [{ - code: 'ad-slot-1', - sizes: [[300, 250]], - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - bids: [ - { - bidder: 'bidderA', - params: { - placement: '1000' - } - }, - { - bidder: 'bidderB', - params: { - placement: '56656' - } - } - ] - }]; - - after(function () { - adWMGAnalyticsAdapter.disableAnalytics(); - }); - - describe('main test flow', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - }); - - afterEach(function () { - events.getEvents.restore(); - }); - - it('should catch all events', function () { - sinon.spy(adWMGAnalyticsAdapter, 'track'); - - adapterManager.registerAnalyticsAdapter({ - code: 'adWMG', - adapter: adWMGAnalyticsAdapter - }); - - adapterManager.enableAnalytics({ - provider: 'adWMG', - options: { - site: 'test.com', - publisher_id: '5abd0543ba45723db49d97ea' - } - }); - - expectEvents([ - [EVENTS.AUCTION_INIT, {timestamp, auctionId, timeout, adUnits}], - [EVENTS.BID_REQUESTED, {}], - [EVENTS.BID_RESPONSE, bidResponse], - [EVENTS.NO_BID, {}], - [EVENTS.BID_TIMEOUT, bidTimeoutArgs], - [EVENTS.AUCTION_END, {}], - [EVENTS.BID_WON, wonRequest], - ]).to.beTrackedBy(adWMGAnalyticsAdapter.track); - }); - - it('should be two xhr requests', function () { - events.emit(EVENTS.AUCTION_END, {}); - events.emit(EVENTS.BID_WON, wonRequest); - expect(server.requests.length).to.equal(2); - }); - - it('second request should be bidWon', function () { - events.emit(EVENTS.AUCTION_END, {}); - events.emit(EVENTS.BID_WON, wonRequest); - expect(JSON.parse(server.requests[1].requestBody).events[0].status).to.equal(expectedBidWonData.events[0].status); - }); - - it('check bidWon data', function () { - events.emit(EVENTS.AUCTION_END, {}); - events.emit(EVENTS.BID_WON, wonRequest); - const realBidWonData = JSON.parse(server.requests[1].requestBody); - expect(realBidWonData.publisher_id).to.equal(expectedBidWonData.publisher_id); - expect(realBidWonData.site).to.equal(expectedBidWonData.site); - expect(realBidWonData.ad_unit_type[0]).to.equal(expectedBidWonData.ad_unit_type[0]); - expect(realBidWonData.ad_unit_size[0]).to.equal(expectedBidWonData.ad_unit_size[0]); - expect(realBidWonData.events[0].bids[0].bidder).to.equal(expectedBidWonData.events[0].bids[0].bidder); - }); - }); -}); diff --git a/test/spec/modules/adWMGBidAdapter_spec.js b/test/spec/modules/adWMGBidAdapter_spec.js deleted file mode 100644 index 6b0c444fc..000000000 --- a/test/spec/modules/adWMGBidAdapter_spec.js +++ /dev/null @@ -1,330 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adWMGBidAdapter.js'; -import { config } from 'src/config.js'; - -describe('adWMGBidAdapter', function () { - describe('isBidRequestValid', function () { - let bid; - beforeEach(function() { - bid = { - bidder: 'adWMG', - params: { - publisherId: '5cebea3c9eea646c7b623d5e' - }, - mediaTypes: { - banner: { - size: [[300, 250]] - } - } - }; - }); - - it('should return true when valid bid request is set', function() { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when \'publisherId\' param are not set', function() { - delete bid.params.publisherId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('parseUserAgent', function() { - let ua_desktop, ua_mobile, ua_tv, ua_tablet; - beforeEach(function() { - ua_desktop = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.66 Safari/537.36'; - ua_tv = 'Mozilla/5.0 (Linux; NetCast; U) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/38.0.2125.122 Safari/537.31 SmartTV/7.0'; - ua_mobile = 'Mozilla/5.0 (Linux; Android 7.0; SAMSUNG SM-G610M Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/7.2 Chrome/59.0.3071.125 Mobile Safari/537.36'; - ua_tablet = 'Mozilla/5.0 (iPad; CPU OS 7_1_2 like Mac OS X) AppleWebKit/537.51.2 (KHTML, like Gecko) Version/7.0 Mobile/11D257 Safari/9537.53'; - }); - - it('should return correct device type: desktop', function() { - const userDeviceInfo = spec.parseUserAgent(ua_desktop); - expect(userDeviceInfo.devicetype).to.equal(2); - }); - - it('should return correct device type: TV', function() { - const userDeviceInfo = spec.parseUserAgent(ua_tv); - expect(userDeviceInfo.devicetype).to.equal(3); - }); - - it('should return correct device type: mobile', function() { - const userDeviceInfo = spec.parseUserAgent(ua_mobile); - expect(userDeviceInfo.devicetype).to.equal(4); - }); - - it('should return correct device type: tablet', function() { - const userDeviceInfo = spec.parseUserAgent(ua_tablet); - expect(userDeviceInfo.devicetype).to.equal(5); - }); - - it('should return correct OS name', function() { - const userDeviceInfo = spec.parseUserAgent(ua_desktop); - expect(userDeviceInfo.os).to.equal('Windows'); - }); - - it('should return correct OS version', function() { - const userDeviceInfo = spec.parseUserAgent(ua_desktop); - expect(userDeviceInfo.osv).to.equal('10.0'); - }); - }); - - describe('buildRequests', function () { - let bidRequests; - beforeEach(function() { - bidRequests = [ - { - bidder: 'adWMG', - adUnitCode: 'adwmg-test-ad', - auctionId: 'test-auction-id', - bidId: 'test-bid-id', - bidRequestsCount: 1, - bidderRequestId: 'bidderrequestid123', - transactionId: 'transaction-id-123', - sizes: [[300, 250]], - requestId: 'requestid123', - params: { - floorPrice: 100, - currency: 'USD' - }, - mediaTypes: { - banner: { - size: [[300, 250]] - } - }, - userId: { - pubcid: 'pubc-id-123' - } - }, { - bidder: 'adWMG', - adUnitCode: 'adwmg-test-ad-2', - auctionId: 'test-auction-id-2', - bidId: 'test-bid-id-2', - bidRequestsCount: 1, - bidderRequestId: 'bidderrequestid456', - transactionId: 'transaction-id-456', - sizes: [[320, 50]], - requestId: 'requestid456', - params: { - floorPrice: 100, - currency: 'USD' - }, - mediaTypes: { - banner: { - size: [[320, 50]] - } - }, - userId: { - pubcid: 'pubc-id-456' - } - } - ]; - }); - - const bidderRequest = { - refererInfo: { - referer: 'https://test.com' - }, - gdprConsent: { - consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', - vendorData: {}, - gdprApplies: true, - apiVersion: 2 - } - }; - - it('should not contain a sizes when sizes is not set', function() { - delete bidRequests[0].sizes; - delete bidRequests[1].sizes; - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(JSON.parse(requests[0].data).sizes).to.be.an('undefined'); - expect(JSON.parse(requests[1].data).sizes).to.be.an('undefined'); - }); - - it('should not contain a userId when userId is not set', function() { - delete bidRequests[0].userId; - delete bidRequests[1].userId; - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(JSON.parse(requests[0].data).userId).to.be.an('undefined'); - expect(JSON.parse(requests[1].data).userId).to.be.an('undefined'); - }); - - it('should have a post method', function() { - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(requests[0].method).to.equal('POST'); - expect(requests[1].method).to.equal('POST'); - }); - - it('should contain a request id equals to the bid id', function() { - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(JSON.parse(requests[0].data).requestId).to.equal(bidRequests[0].bidId); - expect(JSON.parse(requests[1].data).requestId).to.equal(bidRequests[1].bidId); - }); - - it('should have an url that match the default endpoint', function() { - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(requests[0].url).to.equal('https://hb.adwmg.com/hb'); - expect(requests[1].url).to.equal('https://hb.adwmg.com/hb'); - }); - - it('should contain GDPR consent data if GDPR set', function() { - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(JSON.parse(requests[0].data).gdpr.applies).to.be.true; - expect(JSON.parse(requests[0].data).gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(JSON.parse(requests[1].data).gdpr.applies).to.be.true; - expect(JSON.parse(requests[1].data).gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - }) - - it('should not contain GDPR consent data if GDPR not set', function() { - delete bidderRequest.gdprConsent; - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(JSON.parse(requests[0].data).gdpr).to.be.an('undefined'); - expect(JSON.parse(requests[1].data).gdpr).to.be.an('undefined'); - }) - - it('should set debug mode in requests if enabled', function() { - sinon.stub(config, 'getConfig').withArgs('debug').returns(true); - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(JSON.parse(requests[0].data).debug).to.be.true; - expect(JSON.parse(requests[1].data).debug).to.be.true; - config.getConfig.restore(); - }) - }); - - describe('interpretResponse', function () { - let serverResponse; - beforeEach(function() { - serverResponse = { - body: { - 'requestId': 'request-id', - 'cpm': 100, - 'width': 300, - 'height': 250, - 'ad': '
ad
', - 'ttl': 300, - 'creativeId': 'creative-id', - 'netRevenue': true, - 'currency': 'USD', - 'adomain': ['testdomain.com'] - } - }; - }); - - it('should return a valid response', () => { - var responses = spec.interpretResponse(serverResponse); - expect(responses).to.be.an('array').that.is.not.empty; - - const response = responses[0]; - expect(response).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'meta', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency'); - expect(response.requestId).to.equal('request-id'); - expect(response.cpm).to.equal(100); - expect(response.width).to.equal(300); - expect(response.height).to.equal(250); - expect(response.ad).to.equal('
ad
'); - expect(response.ttl).to.equal(300); - expect(response.creativeId).to.equal('creative-id'); - expect(response.netRevenue).to.be.true; - expect(response.currency).to.equal('USD'); - expect(response.meta.advertiserDomains[0]).to.equal('testdomain.com'); - expect(response.meta.mediaType).to.equal('banner'); - }); - - it('should return an empty array when serverResponse is empty', () => { - serverResponse = {}; - var responses = spec.interpretResponse(serverResponse); - expect(responses).to.deep.equal([]); - }); - }); - - describe('getUserSyncs', function () { - it('should return nothing when sync is disabled', function () { - const syncOptions = { - 'iframeEnabled': false, - 'pixelEnabled': false - }; - - const syncs = spec.getUserSyncs(syncOptions); - expect(syncs).to.deep.equal([]); - }); - - it('should register iframe sync when only iframe is enabled', function () { - const syncOptions = { - 'iframeEnabled': true, - 'pixelEnabled': false - }; - - const syncs = spec.getUserSyncs(syncOptions); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).includes('https://hb.adwmg.com/cphb.html?'); - }); - - it('should register iframe sync when iframe and image are enabled', function () { - const syncOptions = { - 'iframeEnabled': true, - 'pixelEnabled': true - }; - - const syncs = spec.getUserSyncs(syncOptions); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).includes('https://hb.adwmg.com/cphb.html?'); - }); - - it('should send GDPR consent if enabled', function() { - const syncOptions = { - 'iframeEnabled': true, - 'pixelEnabled': true - }; - const gdprConsent = { - consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', - vendorData: {}, - gdprApplies: true, - apiVersion: 2 - }; - const serverResponse = {}; - const syncs = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent); - expect(syncs[0].url).includes('gdpr=1'); - expect(syncs[0].url).includes(`gdpr_consent=${gdprConsent.consentString}`); - }); - - it('should not add GDPR consent params twice', function() { - const syncOptions = { - 'iframeEnabled': true, - 'pixelEnabled': true - }; - const gdprConsent = { - consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', - vendorData: {}, - gdprApplies: true, - apiVersion: 2 - }; - const gdprConsent2 = { - consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_7_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', - vendorData: {}, - gdprApplies: true, - apiVersion: 2 - }; - const serverResponse = {}; - let syncs = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent); - syncs = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent2); - expect(syncs[0].url.match(/gdpr/g).length).to.equal(2); // gdpr + gdpr_consent - expect(syncs[0].url.match(/gdpr_consent/g).length).to.equal(1); - }); - - it('should delete \'&\' symbol at the end of usersync URL', function() { - const syncOptions = { - 'iframeEnabled': true, - 'pixelEnabled': true - }; - const gdprConsent = { - consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', - vendorData: {}, - gdprApplies: true, - apiVersion: 2 - }; - const serverResponse = {}; - const syncs = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent); - expect(syncs[0].url.slice(-1)).to.not.equal('&'); - }); - }); -}); diff --git a/test/spec/modules/adagioAnalyticsAdapter_spec.js b/test/spec/modules/adagioAnalyticsAdapter_spec.js deleted file mode 100644 index 9178d7b53..000000000 --- a/test/spec/modules/adagioAnalyticsAdapter_spec.js +++ /dev/null @@ -1,1256 +0,0 @@ -import * as prebidGlobal from 'src/prebidGlobal.js'; -import * as utils from 'src/utils.js'; -import adagioAnalyticsAdapter, { _internal } from 'modules/adagioAnalyticsAdapter.js'; -import { EVENTS } from 'src/constants.js'; -import { expect } from 'chai'; -import { server } from 'test/mocks/xhr.js'; - -const adapterManager = require('src/adapterManager').default; -const events = require('src/events'); - -describe('adagio analytics adapter - adagio.js', () => { - let sandbox; - let adagioQueuePushSpy; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - sandbox.stub(events, 'getEvents').returns([]); - - sandbox.stub(prebidGlobal, 'getGlobal').returns({ - installedModules: ['adagioRtdProvider', 'rtdModule'] - }); - - adapterManager.registerAnalyticsAdapter({ - code: 'adagio', - adapter: adagioAnalyticsAdapter - }); - - _internal.getAdagioNs().pageviewId = 'a68e6d70-213b-496c-be0a-c468ff387106'; - - adagioQueuePushSpy = sandbox.spy(_internal.getAdagioNs().queue, 'push'); - }); - - afterEach(() => { - _internal.getAdagioNs().queue = []; - sandbox.restore(); - }); - - describe('track', () => { - beforeEach(() => { - adapterManager.enableAnalytics({ - provider: 'adagio', - options: { - organizationId: '1001', - site: 'test-com', - } - }); - }); - - afterEach(() => { - adagioAnalyticsAdapter.disableAnalytics(); - }); - - it('builds and sends auction data', () => { - const w = utils.getWindowTop(); - - const bidRequest = { - bids: [{ - adUnitCode: 'div-1', - params: { - features: { - siteId: '2', - placement: 'pave_top', - pagetype: 'article', - category: 'IAB12,IAB12-2', - device: '2', - } - } - }, { - adUnitCode: 'div-2', - params: { - features: { - siteId: '2', - placement: 'ban_top', - pagetype: 'article', - category: 'IAB12,IAB12-2', - device: '2', - } - }, - }], - }; - const bidResponse = { - bidderCode: 'adagio', - width: 300, - height: 250, - statusMessage: 'Bid available', - cpm: 6.2189757658226075, - currency: '', - netRevenue: false, - adUnitCode: 'div-1', - timeToRespond: 132, - }; - - const testEvents = { - [EVENTS.BID_REQUESTED]: bidRequest, - [EVENTS.BID_RESPONSE]: bidResponse, - [EVENTS.AUCTION_END]: {} - }; - - // Step 1-3: Send events - Object.entries(testEvents).forEach(([ev, payload]) => events.emit(ev, payload)); - function eventItem(eventName, args) { - return sinon.match({ - action: 'pb-analytics-event', - ts: sinon.match((val) => val !== undefined), - data: { - eventName, - args - } - }) - } - - Object.entries(testEvents).forEach(([ev, payload]) => sinon.assert.calledWith(adagioQueuePushSpy, eventItem(ev, payload))); - }); - }); -}); - -const AUCTION_ID = '25c6d7f5-699a-4bfc-87c9-996f915341fa'; -const RTD_AUCTION_ID = '753b3784-12a1-44c2-9d08-d0e4ee910e69'; -const RTD_AUCTION_ID_CACHE = '04d991be-8f7d-4491-930b-2b7eefb3c447'; -const AUCTION_ID_CACHE = 'b43d24a0-13d4-406d-8176-3181402bafc4'; -const SESSION_ID = 'c4f9e517-a592-45af-9560-ca191823d591'; - -const BID_ADAGIO = { - bidder: 'adagio', - auctionId: AUCTION_ID, - adUnitCode: '/19968336/header-bid-tag-1', - bidId: '3bd4ebb1c900e2', - partnerImpId: 'partnerImpressionID-2', - adId: 'fake_ad_id_2', - requestId: '3bd4ebb1c900e2', - width: 728, - height: 90, - mediaType: 'banner', - cpm: 1.42, - currency: 'USD', - originalCpm: 1.42, - originalCurrency: 'USD', - dealId: 'the-deal-id', - dealChannel: 'PMP', - mi: 'matched-impression', - seatBidId: 'aaaa-bbbb-cccc-dddd', - adserverTargeting: { - 'hb_bidder': 'another', - 'hb_adid': '3bd4ebb1c900e2', - 'hb_pb': '1.500', - 'hb_size': '728x90', - 'hb_source': 'server' - }, - meta: { - advertiserDomains: ['example.com'] - }, - pba: { - sid: '42', - e_pba_test: true - } -}; - -const BID_ANOTHER = { - bidder: 'another', - auctionId: AUCTION_ID, - adUnitCode: '/19968336/header-bid-tag-1', - bidId: '3bd4ebb1c900e2', - partnerImpId: 'partnerImpressionID-2', - adId: 'fake_ad_id_2', - requestId: '3bd4ebb1c900e2', - width: 728, - height: 90, - mediaType: 'banner', - cpm: 1.71, - currency: 'EUR', - originalCpm: 1.62, - originalCurrency: 'GBP', - dealId: 'the-deal-id', - dealChannel: 'PMP', - mi: 'matched-impression', - seatBidId: 'aaaa-bbbb-cccc-dddd', - adserverTargeting: { - 'hb_bidder': 'another', - 'hb_adid': '3bd4ebb1c900e2', - 'hb_pb': '1.500', - 'hb_size': '728x90', - 'hb_source': 'server' - }, - meta: { - advertiserDomains: ['example.com'] - } -}; - -const BID_CACHED = Object.assign({}, BID_ADAGIO, { - auctionId: AUCTION_ID_CACHE, - latestTargetedAuctionId: BID_ADAGIO.auctionId, -}); - -const PARAMS_ADG = { - environment: 'desktop', -}; - -const ORTB_DATA = { - pagetype: 'article', -}; - -const ADG_RTD = { - 'uid': RTD_AUCTION_ID, - 'session': { - 'testName': 'test', - 'testVersion': 'version', - 'id': SESSION_ID, - } -}; - -const AUCTION_INIT_ANOTHER = { - 'auctionId': AUCTION_ID, - 'timestamp': 1519767010567, - 'auctionStatus': 'inProgress', - 'adUnits': [ { - 'code': '/19968336/header-bid-tag-1', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 640, - 480 - ], - [ - 640, - 100 - ] - ] - } - }, - 'sizes': [[640, 480]], - 'bids': [ { - 'bidder': 'another', - 'params': { - 'publisherId': '1001' - }, - }, { - 'bidder': 'nobid', - 'params': { - 'publisherId': '1002' - }, - }, { - 'bidder': 'adagio', - 'params': { - ...PARAMS_ADG - }, - }, { - 'bidder': 'anotherWithAlias', - 'params': { - 'publisherId': '1001' - }, - }, ], - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'ortb2Imp': { - 'ext': { - 'data': { - 'placement': 'pave_top', - } - } - }, - }, { - 'code': '/19968336/footer-bid-tag-1', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 640, - 480 - ] - ] - } - }, - 'sizes': [[640, 480]], - 'bids': [ { - 'bidder': 'another', - 'params': { - 'publisherId': '1001' - }, - } ], - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'ortb2Imp': { - 'ext': { - 'data': { - 'placement': 'pave_top', - } - } - }, - } ], - 'adUnitCodes': ['/19968336/header-bid-tag-1', '/19968336/footer-bid-tag-1'], - 'bidderRequests': [ - { - 'bidderCode': 'another', - 'auctionId': AUCTION_ID, - 'bidderRequestId': '1be65d7958826a', - 'bids': [ - { - 'bidder': 'another', - 'params': { - 'publisherId': '1001', - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[640, 480]] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-1', - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'sizes': [[640, 480]], - 'bidId': '2ecff0db240757', - 'bidderRequestId': '1be65d7958826a', - 'auctionId': AUCTION_ID, - 'src': 'client', - 'bidRequestsCount': 1 - }, - { - 'bidder': 'another', - 'params': { - 'publisherId': '1001' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[640, 480]] - } - }, - 'adUnitCode': '/19968336/footer-bid-tag-1', - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'sizes': [[640, 480]], - 'bidId': '2ecff0db240757', - 'bidderRequestId': '1be65d7958826a', - 'auctionId': AUCTION_ID, - 'src': 'client', - 'bidRequestsCount': 1 - }, - ], - 'timeout': 3000, - 'refererInfo': { - 'topmostLocation': 'http://www.test.com/page.html', 'reachedTop': true, 'numIframes': 0, 'stack': ['http://www.test.com/page.html'] - }, - 'ortb2': { - 'site': { - 'ext': { - 'data': { - 'adg_rtd': { - ...ADG_RTD - }, - ...ORTB_DATA - } - } - } - } - }, - { - 'bidderCode': 'nobid', - 'auctionId': AUCTION_ID, - 'bidderRequestId': '1be65d7958826a', - 'bids': [{ - 'bidder': 'nobid', - 'params': { - 'publisherId': '1001' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[640, 480]] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-1', - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'sizes': [[640, 480]], - 'bidId': '2ecff0db240757', - 'bidderRequestId': '1be65d7958826a', - 'auctionId': AUCTION_ID, - 'src': 'client', - 'bidRequestsCount': 1 - } - ], - 'timeout': 3000, - 'refererInfo': { - 'topmostLocation': 'http://www.test.com/page.html', 'reachedTop': true, 'numIframes': 0, 'stack': ['http://www.test.com/page.html'] - }, - 'ortb2': { - 'site': { - 'ext': { - 'data': { - 'adg_rtd': { - ...ADG_RTD - }, - ...ORTB_DATA - } - } - } - } - }, - { - bidderCode: 'anotherWithAlias', - 'auctionId': AUCTION_ID, - 'bidderRequestId': '1be65d7958826a', - 'bids': [ - { - 'bidder': 'anotherWithAlias', - 'params': { - 'publisherId': '1001', - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[640, 480]] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-1', - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'sizes': [[640, 480]], - 'bidId': '2ecff0db240757', - 'bidderRequestId': '1be65d7958826a', - 'auctionId': AUCTION_ID, - 'src': 'client', - 'bidRequestsCount': 1 - }, - ], - 'timeout': 3000, - 'refererInfo': { - 'topmostLocation': 'http://www.test.com/page.html', 'reachedTop': true, 'numIframes': 0, 'stack': ['http://www.test.com/page.html'] - }, - 'ortb2': { - 'site': { - 'ext': { - 'data': { - 'adg_rtd': { - ...ADG_RTD - }, - ...ORTB_DATA - } - } - } - } - }, - { - 'bidderCode': 'adagio', - 'auctionId': AUCTION_ID, - 'bidderRequestId': '1be65d7958826a', - 'bids': [ { - 'bidder': 'adagio', - 'params': { - ...PARAMS_ADG - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[640, 480]] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-1', - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'sizes': [[640, 480]], - 'bidId': '2ecff0db240757', - 'bidderRequestId': '1be65d7958826a', - 'auctionId': AUCTION_ID, - 'src': 'client', - 'bidRequestsCount': 1 - } - ], - 'timeout': 3000, - 'refererInfo': { - 'topmostLocation': 'http://www.test.com/page.html', 'reachedTop': true, 'numIframes': 0, 'stack': ['http://www.test.com/page.html'] - }, - 'ortb2': { - 'site': { - 'ext': { - 'data': { - 'adg_rtd': { - ...ADG_RTD - }, - ...ORTB_DATA - } - } - } - } - } - ], - 'bidsReceived': [], - 'winningBids': [], - 'timeout': 3000 -}; - -const AUCTION_INIT_CACHE = { - 'auctionId': AUCTION_ID_CACHE, - 'timestamp': 1519767010567, - 'auctionStatus': 'inProgress', - 'adUnits': [ { - 'code': '/19968336/header-bid-tag-1', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 640, - 480 - ], - [ - 640, - 100 - ] - ] - } - }, - 'sizes': [[640, 480]], - 'bids': [ { - 'bidder': 'another', - 'params': { - 'publisherId': '1001' - }, - }, { - 'bidder': 'adagio', - 'params': { - ...PARAMS_ADG - }, - }, ], - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'ortb2Imp': { - 'ext': { - 'data': { - 'placement': 'pave_top', - } - } - }, - }, { - 'code': '/19968336/footer-bid-tag-1', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 640, - 480 - ] - ] - } - }, - 'sizes': [[640, 480]], - 'bids': [ { - 'bidder': 'another', - 'params': { - 'publisherId': '1001' - }, - } ], - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'ortb2Imp': { - 'ext': { - 'data': { - 'placement': 'pave_top', - } - } - }, - } ], - 'adUnitCodes': ['/19968336/header-bid-tag-1', '/19968336/footer-bid-tag-1'], - 'bidderRequests': [ { - 'bidderCode': 'another', - 'auctionId': AUCTION_ID_CACHE, - 'bidderRequestId': '1be65d7958826a', - 'bids': [ { - 'bidder': 'another', - 'params': { - 'publisherId': '1001', - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[640, 480]] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-1', - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'sizes': [[640, 480]], - 'bidId': '2ecff0db240757', - 'bidderRequestId': '1be65d7958826a', - 'auctionId': AUCTION_ID_CACHE, - 'src': 'client', - 'bidRequestsCount': 1 - }, { - 'bidder': 'another', - 'params': { - 'publisherId': '1001' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[640, 480]] - } - }, - 'adUnitCode': '/19968336/footer-bid-tag-1', - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'sizes': [[640, 480]], - 'bidId': '2ecff0db240757', - 'bidderRequestId': '1be65d7958826a', - 'auctionId': AUCTION_ID_CACHE, - 'src': 'client', - 'bidRequestsCount': 1 - } - ], - 'timeout': 3000, - 'refererInfo': { - 'topmostLocation': 'http://www.test.com/page.html', 'reachedTop': true, 'numIframes': 0, 'stack': ['http://www.test.com/page.html'] - }, - 'ortb2': { - 'site': { - 'ext': { - 'data': { - 'adg_rtd': { - ...ADG_RTD, - 'uid': RTD_AUCTION_ID_CACHE - }, - ...ORTB_DATA - } - } - } - } - }, { - 'bidderCode': 'adagio', - 'auctionId': AUCTION_ID_CACHE, - 'bidderRequestId': '1be65d7958826a', - 'bids': [ { - 'bidder': 'adagio', - 'params': { - ...PARAMS_ADG - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[640, 480]] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-1', - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'sizes': [[640, 480]], - 'bidId': '2ecff0db240757', - 'bidderRequestId': '1be65d7958826a', - 'auctionId': AUCTION_ID_CACHE, - 'src': 'client', - 'bidRequestsCount': 1 - } - ], - 'timeout': 3000, - 'refererInfo': { - 'topmostLocation': 'http://www.test.com/page.html', 'reachedTop': true, 'numIframes': 0, 'stack': ['http://www.test.com/page.html'] - }, - 'ortb2': { - 'site': { - 'ext': { - 'data': { - 'adg_rtd': { - ...ADG_RTD, - 'uid': RTD_AUCTION_ID_CACHE - }, - ...ORTB_DATA - } - } - } - } - } - ], - 'bidsReceived': [], - 'winningBids': [], - 'timeout': 3000 -}; - -const AUCTION_END_ANOTHER = Object.assign({}, AUCTION_INIT_ANOTHER, { - bidsReceived: [BID_ANOTHER, BID_ADAGIO] -}); - -const AUCTION_END_ANOTHER_NOBID = Object.assign({}, AUCTION_INIT_ANOTHER, { - bidsReceived: [] -}); - -const PBS_ANALYTICS_ANOTHER = { - atag: [ - { - stage: 'auction-response', - module: 'adg-pba', - pba: { - '/19968336/header-bid-tag-1': { - st_id: '53', - splt_cs_id: '731' - } - } - } - ], - auctionId: AUCTION_ID, -} - -const MOCK = { - SET_TARGETING: { - [BID_ADAGIO.adUnitCode]: BID_ADAGIO.adserverTargeting, - [BID_ANOTHER.adUnitCode]: BID_ANOTHER.adserverTargeting - }, - AUCTION_INIT: { - another: AUCTION_INIT_ANOTHER, - bidcached: AUCTION_INIT_CACHE - }, - BID_RESPONSE: { - adagio: BID_ADAGIO, - another: BID_ANOTHER - }, - BID_TIMEOUT: { - another: [ - { - auctionId: AUCTION_ID, - adUnitCode: '/19968336/header-bid-tag-1', - bidder: 'another', - }, - { - auctionId: AUCTION_ID, - adUnitCode: '/19968336/footer-bid-tag-1', - bidder: 'another', - }, - ] - }, - AUCTION_END: { - another: AUCTION_END_ANOTHER, - another_nobid: AUCTION_END_ANOTHER_NOBID - }, - BID_WON: { - adagio: Object.assign({}, BID_ADAGIO, { - 'status': 'rendered' - }), - another: Object.assign({}, BID_ANOTHER, { - 'status': 'rendered' - }), - bidcached: Object.assign({}, BID_CACHED, { - 'status': 'rendered' - }), - }, - AD_RENDER_SUCCEEDED: { - another: { - ad: '
ad
', - adId: 'fake_ad_id_2', - bid: BID_ANOTHER - }, - bidcached: { - ad: '
ad
', - adId: 'fake_ad_id_2', - bid: BID_CACHED - } - }, - AD_RENDER_FAILED: { - bidcached: { - adId: 'fake_ad_id_2', - bid: BID_CACHED - } - } -}; - -describe('adagio analytics adapter', () => { - let sandbox; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - - sandbox.stub(events, 'getEvents').returns([]); - - sandbox.stub(prebidGlobal, 'getGlobal').returns({ - installedModules: ['adagioRtdProvider', 'rtdModule'], - convertCurrency: (cpm, from, to) => { - const convKeys = { - 'GBP-EUR': 0.7, - 'EUR-GBP': 1.3, - 'USD-EUR': 0.8, - 'EUR-USD': 1.2, - 'USD-GBP': 0.6, - 'GBP-USD': 1.6, - }; - return cpm * (convKeys[`${from}-${to}`] || 1); - } - }); - - _internal.getAdagioNs().pageviewId = 'a68e6d70-213b-496c-be0a-c468ff387106'; - - adapterManager.registerAnalyticsAdapter({ - code: 'adagio', - adapter: adagioAnalyticsAdapter - }); - }); - - afterEach(() => { - _internal.getAdagioNs().queue = []; - sandbox.restore(); - }); - - describe('track', () => { - beforeEach(() => { - adapterManager.enableAnalytics({ - provider: 'adagio', - options: { - organizationId: '1001', - site: 'test-com', - } - }); - adapterManager.aliasRegistry['anotherWithAlias'] = 'another'; - }); - - afterEach(() => { - adagioAnalyticsAdapter.disableAnalytics(); - delete adapterManager.aliasRegistry['anotherWithAlias']; - }); - - it('builds and sends auction data', () => { - events.emit(EVENTS.AUCTION_INIT, MOCK.AUCTION_INIT.another); - events.emit(EVENTS.BID_RESPONSE, MOCK.BID_RESPONSE.adagio); - events.emit(EVENTS.BID_RESPONSE, MOCK.BID_RESPONSE.another); - events.emit(EVENTS.AUCTION_END, MOCK.AUCTION_END.another); - events.emit(EVENTS.BID_WON, MOCK.BID_WON.another); - events.emit(EVENTS.AD_RENDER_SUCCEEDED, MOCK.AD_RENDER_SUCCEEDED.another); - - expect(server.requests.length).to.equal(5, 'requests count'); - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[0].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('1'); - expect(search.pbjsv).to.equal('$prebid.version$'); - expect(search.s_id).to.equal(SESSION_ID); - expect(search.auct_id).to.equal(RTD_AUCTION_ID); - expect(search.adu_code).to.equal('/19968336/header-bid-tag-1'); - expect(search.org_id).to.equal('1001'); - expect(search.site).to.equal('test-com'); - expect(search.pv_id).to.equal('a68e6d70-213b-496c-be0a-c468ff387106'); - expect(search.url_dmn).to.equal(window.location.hostname); - expect(search.pgtyp).to.equal('article'); - expect(search.plcmt).to.equal('pave_top'); - expect(search.mts).to.equal('ban'); - expect(search.ban_szs).to.equal('640x100,640x480'); - expect(search.bdrs).to.equal('adagio,another,anotherWithAlias,nobid'); - expect(search.bdrs_code).to.equal('adagio,another,another,nobid'); - expect(search.bdrs_timeout).to.not.exist; - expect(search.adg_mts).to.equal('ban'); - } - - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[1].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('1'); - } - - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[2].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('2'); - expect(search.adu_code).to.equal('/19968336/header-bid-tag-1'); - expect(search.e_sid).to.equal('42'); - expect(search.e_pba_test).to.equal('true'); - expect(search.bdrs_bid).to.equal('1,1,0,0'); - expect(search.bdrs_cpm).to.equal('1.42,2.052,,'); - expect(search.bdrs_timeout).to.equal('0,0,0,0'); - } - - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[3].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('2'); - expect(search.auct_id).to.equal(RTD_AUCTION_ID); - expect(search.adu_code).to.equal('/19968336/footer-bid-tag-1'); - expect(search.bdrs_timeout).to.equal('0'); - } - - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[4].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('3'); - expect(search.auct_id).to.equal(RTD_AUCTION_ID); - expect(search.adu_code).to.equal('/19968336/header-bid-tag-1'); - expect(search.win_bdr).to.equal('another'); - expect(search.win_mt).to.equal('ban'); - expect(search.win_ban_sz).to.equal('728x90'); - expect(search.win_net_cpm).to.equal('2.052'); - expect(search.win_og_cpm).to.equal('2.592'); - expect(search.bdrs_timeout).to.equal('0,0,0,0'); - } - }); - - it('builds and sends auction data with a cached bid win', () => { - events.emit(EVENTS.AUCTION_INIT, MOCK.AUCTION_INIT.bidcached); - events.emit(EVENTS.AUCTION_INIT, MOCK.AUCTION_INIT.another); - events.emit(EVENTS.BID_RESPONSE, MOCK.BID_RESPONSE.adagio); - events.emit(EVENTS.BID_RESPONSE, MOCK.BID_RESPONSE.another); - events.emit(EVENTS.AUCTION_END, MOCK.AUCTION_END.another_nobid); - events.emit(EVENTS.BID_WON, MOCK.BID_WON.bidcached); - events.emit(EVENTS.AD_RENDER_FAILED, MOCK.AD_RENDER_FAILED.bidcached); - - expect(server.requests.length).to.equal(8, 'requests count'); - { - // the first request is getting cached we expect to see its auction id later when it's re-used - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[0].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('1'); - expect(search.pbjsv).to.equal('$prebid.version$'); - expect(search.auct_id).to.equal(RTD_AUCTION_ID_CACHE); - expect(search.s_id).to.equal(SESSION_ID); - expect(search.adu_code).to.equal('/19968336/header-bid-tag-1'); - expect(search.org_id).to.equal('1001'); - expect(search.site).to.equal('test-com'); - expect(search.pv_id).to.equal('a68e6d70-213b-496c-be0a-c468ff387106'); - expect(search.url_dmn).to.equal(window.location.hostname); - expect(search.pgtyp).to.equal('article'); - expect(search.plcmt).to.equal('pave_top'); - expect(search.mts).to.equal('ban'); - expect(search.ban_szs).to.equal('640x100,640x480'); - expect(search.bdrs).to.equal('adagio,another'); - expect(search.bdrs_code).to.equal('adagio,another'); - expect(search.bdrs_timeout).to.not.exist; - expect(search.adg_mts).to.equal('ban'); - expect(search.t_n).to.equal('test'); - expect(search.t_v).to.equal('version'); - } - - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[1].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('1'); - expect(search.pbjsv).to.equal('$prebid.version$'); - expect(search.auct_id).to.equal(RTD_AUCTION_ID_CACHE); - expect(search.adu_code).to.equal('/19968336/footer-bid-tag-1'); - expect(search.org_id).to.equal('1001'); - expect(search.site).to.equal('test-com'); - expect(search.pv_id).to.equal('a68e6d70-213b-496c-be0a-c468ff387106'); - expect(search.url_dmn).to.equal(window.location.hostname); - expect(search.pgtyp).to.equal('article'); - expect(search.plcmt).to.equal('pave_top'); - expect(search.mts).to.equal('ban'); - expect(search.ban_szs).to.equal('640x480'); - expect(search.bdrs).to.equal('another'); - expect(search.bdrs_code).to.equal('another'); - expect(search.bdrs_timeout).to.not.exist; - expect(search.adg_mts).to.not.exist; - } - - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[2].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('1'); - expect(search.pbjsv).to.equal('$prebid.version$'); - expect(search.auct_id).to.equal(RTD_AUCTION_ID); - expect(search.adu_code).to.equal('/19968336/header-bid-tag-1'); - expect(search.org_id).to.equal('1001'); - expect(search.site).to.equal('test-com'); - expect(search.pv_id).to.equal('a68e6d70-213b-496c-be0a-c468ff387106'); - expect(search.url_dmn).to.equal(window.location.hostname); - expect(search.pgtyp).to.equal('article'); - expect(search.plcmt).to.equal('pave_top'); - expect(search.mts).to.equal('ban'); - expect(search.ban_szs).to.equal('640x100,640x480'); - expect(search.bdrs).to.equal('adagio,another,anotherWithAlias,nobid'); - expect(search.bdrs_code).to.equal('adagio,another,another,nobid'); - expect(search.bdrs_timeout).to.not.exist; - expect(search.adg_mts).to.equal('ban'); - } - - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[3].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('1'); - expect(search.auct_id).to.equal(RTD_AUCTION_ID); - expect(search.adu_code).to.equal('/19968336/footer-bid-tag-1'); - expect(search.pv_id).to.equal('a68e6d70-213b-496c-be0a-c468ff387106'); - expect(search.bdrs_timeout).to.not.exist; - } - - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[4].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('2'); - expect(search.auct_id).to.equal(RTD_AUCTION_ID); - expect(search.adu_code).to.equal('/19968336/header-bid-tag-1'); - expect(search.e_sid).to.equal('42'); - expect(search.e_pba_test).to.equal('true'); - expect(search.bdrs_bid).to.equal('0,0,0,0'); - expect(search.bdrs_cpm).to.equal(',,,'); - expect(search.bdrs_timeout).to.equal('0,0,0,0'); - } - - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[5].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('2'); - expect(search.auct_id).to.equal(RTD_AUCTION_ID); - expect(search.adu_code).to.equal('/19968336/footer-bid-tag-1'); - expect(search.rndr).to.not.exist; - expect(search.bdrs_timeout).to.equal('0'); - } - - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[6].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('3'); - expect(search.auct_id).to.equal(RTD_AUCTION_ID); - expect(search.auct_id_c).to.equal(RTD_AUCTION_ID_CACHE); - expect(search.adu_code).to.equal('/19968336/header-bid-tag-1'); - expect(search.win_bdr).to.equal('adagio'); - expect(search.win_mt).to.equal('ban'); - expect(search.win_ban_sz).to.equal('728x90'); - expect(search.win_net_cpm).to.equal('1.42'); - expect(search.win_og_cpm).to.equal('1.42'); - expect(search.rndr).to.not.exist; - expect(search.bdrs_timeout).to.equal('0,0,0,0'); - } - - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[7].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('4'); - expect(search.auct_id).to.equal(RTD_AUCTION_ID); - expect(search.auct_id_c).to.equal(RTD_AUCTION_ID_CACHE); - expect(search.adu_code).to.equal('/19968336/header-bid-tag-1'); - expect(search.win_bdr).to.equal('adagio'); - expect(search.win_mt).to.equal('ban'); - expect(search.win_ban_sz).to.equal('728x90'); - expect(search.win_net_cpm).to.equal('1.42'); - expect(search.win_og_cpm).to.equal('1.42'); - expect(search.rndr).to.equal('0'); - expect(search.bdrs_timeout).to.equal('0,0,0,0'); - } - }); - - it('send an "empty" cpm when adserver currency != USD and convertCurrency() is undefined', () => { - sandbox.restore(); - sandbox.stub(prebidGlobal, 'getGlobal').returns({ - installedModules: ['adagioRtdProvider', 'rtdModule'] - }); - - events.emit(EVENTS.AUCTION_INIT, MOCK.AUCTION_INIT.another); - events.emit(EVENTS.BID_RESPONSE, MOCK.BID_RESPONSE.adagio); - events.emit(EVENTS.BID_RESPONSE, MOCK.BID_RESPONSE.another); - events.emit(EVENTS.AUCTION_END, MOCK.AUCTION_END.another); - events.emit(EVENTS.BID_WON, MOCK.BID_WON.another); - events.emit(EVENTS.AD_RENDER_SUCCEEDED, MOCK.AD_RENDER_SUCCEEDED.another); - - expect(server.requests.length).to.equal(5, 'requests count'); - - // fail to compute bidder cpm and send an "empty" cpm - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[2].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.s_id).to.equal(SESSION_ID); - expect(search.v).to.equal('2'); - expect(search.e_sid).to.equal('42'); - expect(search.e_pba_test).to.equal('true'); - expect(search.bdrs_bid).to.equal('1,1,0,0'); - expect(search.bdrs_cpm).to.equal('1.42,,,'); - } - }); - - it('set adg-pbs aTags in beacon', () => { - events.emit(EVENTS.AUCTION_INIT, MOCK.AUCTION_INIT.another); - events.emit(EVENTS.BID_RESPONSE, MOCK.BID_RESPONSE.another); - events.emit(EVENTS.PBS_ANALYTICS, PBS_ANALYTICS_ANOTHER); - events.emit(EVENTS.AUCTION_END, MOCK.AUCTION_END.another); - - expect(server.requests.length).to.equal(4, 'requests count'); - - // server.requests[0] -> AUCTION_INIT - AdUnit header-bid-tag-1 - { - const { search } = utils.parseUrl(server.requests[0].url); - - expect(search.adu_code).to.equal('/19968336/header-bid-tag-1'); - expect(search.v).to.equal('1'); - - expect(search.e_st_id).to.be.undefined; - expect(search.e_splt_cs_id).to.be.undefined; - } - - // server.requests[1] -> AUCTION_INIT - AdUnit footer-bid-tag-1 - { - const { search } = utils.parseUrl(server.requests[1].url); - - expect(search.adu_code).to.equal('/19968336/footer-bid-tag-1'); - expect(search.v).to.equal('1'); - - expect(search.e_st_id).to.be.undefined; - expect(search.e_splt_cs_id).to.be.undefined; - } - - // server.requests[2] -> AUCTION_END - AdUnit header-bid-tag-1 - { - const { search } = utils.parseUrl(server.requests[2].url); - - expect(search.adu_code).to.equal('/19968336/header-bid-tag-1'); - expect(search.v).to.equal('2'); - - // The adg-pbs aTags fields are set in the beacon ! - expect(search.e_st_id).to.equal('53'); - expect(search.e_splt_cs_id).to.equal('731'); - } - - // server.requests[3] -> AUCTION_END - AdUnit footer-bid-tag-1 - { - const { search } = utils.parseUrl(server.requests[3].url); - - expect(search.adu_code).to.equal('/19968336/footer-bid-tag-1'); - expect(search.v).to.equal('2'); - - expect(search.e_st_id).to.be.undefined; - expect(search.e_splt_cs_id).to.be.undefined; - } - }); - - it('builds and sends auction data with a bid timeout', () => { - events.emit(EVENTS.AUCTION_INIT, MOCK.AUCTION_INIT.another); - events.emit(EVENTS.BID_RESPONSE, MOCK.BID_RESPONSE.adagio); - events.emit(EVENTS.BID_TIMEOUT, MOCK.BID_TIMEOUT.another); - events.emit(EVENTS.AUCTION_END, MOCK.AUCTION_END.another); - - expect(server.requests.length).to.equal(4, 'requests count'); - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[0].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('1'); - expect(search.bdrs_timeout).to.not.exist; - } - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[1].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('1'); - expect(search.bdrs_timeout).to.not.exist; - } - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[2].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('2'); - expect(search.bdrs).to.equal('adagio,another,anotherWithAlias,nobid'); - expect(search.bdrs_timeout).to.equal('0,1,0,0'); - } - { - const { protocol, hostname, pathname, search } = utils.parseUrl(server.requests[3].url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('c.4dex.io'); - expect(pathname).to.equal('/pba.gif'); - expect(search.v).to.equal('2'); - expect(search.bdrs).to.equal('another'); - expect(search.bdrs_timeout).to.equal('1'); - } - }); - - it('builds and sends auction data with GAM slot callback', () => { - events.emit(EVENTS.AUCTION_INIT, MOCK.AUCTION_INIT.another); - events.emit(EVENTS.BID_RESPONSE, MOCK.BID_RESPONSE.another); - _internal.gamSlotCallback({ - slot: { - getAdUnitPath() { - return '/19968336/header-bid-tag-1' - }, - getSlotElementId() { - return '/19968336/header-bid-tag-1' - } - }, - isEmpty: true, - }); - events.emit(EVENTS.AUCTION_END, MOCK.AUCTION_END.another); - - expect(server.requests.length).to.equal(4, 'requests count'); - { - const { search } = utils.parseUrl(server.requests[0].url); - expect(search.adsrv).to.not.exist; - expect(search.adsrv_empty).to.not.exist; - } - { - const { search } = utils.parseUrl(server.requests[1].url); - expect(search.v).to.equal('1'); - expect(search.adsrv).to.not.exist; - expect(search.adsrv_empty).to.not.exist; - } - { - const { search } = utils.parseUrl(server.requests[2].url); - expect(search.v).to.equal('2'); - expect(search.adsrv).to.equal('gam'); - expect(search.adsrv_empty).to.equal('true'); - } - { - const { search } = utils.parseUrl(server.requests[3].url); - expect(search.v).to.equal('2'); - expect(search.adsrv).to.not.exist; - expect(search.adsrv_empty).to.not.exist; - } - }); - - it('builds and sends auction data with GAM slot callback after auction ended', () => { - events.emit(EVENTS.AUCTION_INIT, MOCK.AUCTION_INIT.another); - events.emit(EVENTS.BID_RESPONSE, MOCK.BID_RESPONSE.another); - events.emit(EVENTS.AUCTION_END, MOCK.AUCTION_END.another); - _internal.gamSlotCallback({ - slot: { - getAdUnitPath() { - return '/19968336/header-bid-tag-1' - }, - getSlotElementId() { - return '/19968336/header-bid-tag-1' - } - }, - isEmpty: true, - }); - - expect(server.requests.length).to.equal(5, 'requests count'); - { - const { search } = utils.parseUrl(server.requests[0].url); - expect(search.adsrv).to.not.exist; - expect(search.adsrv_empty).to.not.exist; - } - { - const { search } = utils.parseUrl(server.requests[1].url); - expect(search.v).to.equal('1'); - expect(search.adsrv).to.not.exist; - expect(search.adsrv_empty).to.not.exist; - } - { - const { search } = utils.parseUrl(server.requests[2].url); - expect(search.v).to.equal('2'); - expect(search.adsrv).to.not.exist; - expect(search.adsrv_empty).to.not.exist; - } - { - const { search } = utils.parseUrl(server.requests[3].url); - expect(search.v).to.equal('2'); - expect(search.adsrv).to.not.exist; - expect(search.adsrv_empty).to.not.exist; - } - { - const { search } = utils.parseUrl(server.requests[4].url); - expect(search.v).to.equal('3'); - expect(search.adsrv).to.equal('gam'); - expect(search.adsrv_empty).to.equal('true'); - } - }); - }); -}); diff --git a/test/spec/modules/adagioBidAdapter_spec.js b/test/spec/modules/adagioBidAdapter_spec.js deleted file mode 100644 index 1a98b69c7..000000000 --- a/test/spec/modules/adagioBidAdapter_spec.js +++ /dev/null @@ -1,1677 +0,0 @@ -import * as utils from '../../../src/utils.js'; -import { - BB_RENDERER_URL, - ENDPOINT, - VERSION, - _internal, - setExtraParam, - spec -} from '../../../modules/adagioBidAdapter.js'; -import { NATIVE } from '../../../src/mediaTypes.js'; -import { config } from '../../../src/config.js'; -import { executeRenderer } from '../../../src/Renderer.js'; -import { expect } from 'chai'; -import { userSync } from '../../../src/userSync.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -const BidRequestBuilder = function BidRequestBuilder(options) { - const defaults = { - request: { - auctionId: '4fd1ca2d-846c-4211-b9e5-321dfe1709c9', - adUnitCode: 'adunit-code', - bidder: 'adagio' - }, - params: { - organizationId: '1000', - placement: 'PAVE_ATF', - site: 'SITE-NAME', - adUnitElementId: 'gpt-adunit-code' - }, - sizes: [[300, 250], [300, 600]], - }; - - const request = { - ...defaults.request, - ...options - }; - - this.withParams = (options) => { - request.params = { - ...defaults.params, - ...options - }; - return this; - }; - - this.build = () => request; -}; - -const BidderRequestBuilder = function BidderRequestBuilder(options) { - const defaults = { - bidderCode: 'adagio', - auctionId: '4fd1ca2d-846c-4211-b9e5-321dfe1709c9', - bidderRequestId: '7g36s867Tr4xF90X', - timeout: 3000, - refererInfo: { - numIframes: 0, - reachedTop: true, - referer: 'http://test.io/index.html?pbjs_debug=true' - } - }; - - const request = { - ...defaults, - ...options - }; - - this.build = () => request; -}; - -describe('Adagio bid adapter', () => { - let utilsMock; - let sandbox; - let fakeRenderer; - - const fixtures = { - getElementById(width, height, x, y) { - const obj = { - x: x || 800, - y: y || 300, - width: width || 300, - height: height || 250, - }; - - return { - ...obj, - getBoundingClientRect: () => { - return { - width: obj.width, - height: obj.height, - left: obj.x, - top: obj.y, - right: obj.x + obj.width, - bottom: obj.y + obj.height - }; - } - }; - } - }; - - // safeFrame implementation - const $sf = { - ext: { - geom: function() {} - } - }; - - beforeEach(() => { - window.ADAGIO = {}; - window.ADAGIO.adUnits = {}; - window.ADAGIO.pbjsAdUnits = []; - window.ADAGIO.queue = []; - window.ADAGIO.versions = {}; - window.ADAGIO.versions.adagioBidderAdapter = VERSION; - window.ADAGIO.pageviewId = 'dda61753-4059-4f75-b0bf-3f60bd2c4d9a'; - - utilsMock = sinon.mock(utils); - - sandbox = sinon.createSandbox(); - utilsMock = sandbox.mock(utils); - }); - - afterEach(() => { - window.ADAGIO = undefined; - getGlobal().bidderSettings = {}; - - utilsMock.restore(); - - sandbox.restore(); - }); - - describe('get and set params at adUnit level from global Prebid configuration', function() { - it('should set params get from bid.ortb2', function() { - const bid = new BidRequestBuilder().build(); - bid.ortb2 = { - site: { - ext: { - data: { - pagetype: 'abc', - category: ['cat1', 'cat2', 'cat3'] - } - } - } - }; - - sandbox.stub(config, 'getConfig').callsFake(key => { - const config = { - adagio: { - pagetype: 'article' - }, - }; - return utils.deepAccess(config, key); - }); - - setExtraParam(bid, 'pagetype') - expect(bid.params.pagetype).to.equal('article'); - - setExtraParam(bid, 'category'); - expect(bid.params.category).to.equal('cat1'); // Only the first value is kept - }); - - it('should use the adUnit param unit if defined', function() { - const bid = new BidRequestBuilder({ params: { pagetype: 'article' } }).build(); - sandbox.stub(config, 'getConfig').withArgs('adagio').returns({ - pagetype: 'ignore-me' - }); - setExtraParam(bid, 'pagetype') - expect(bid.params.pagetype).to.equal('article'); - }); - }) - - describe('isBidRequestValid()', function() { - it('should return true when required params have been found', function() { - const bid = new BidRequestBuilder().withParams().build(); - - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should compute organizationId and site params from global BidderSettings config', function() { - sandbox.stub(_internal, 'getRefererInfo').returns({ reachedTop: true }); - sandbox.stub(config, 'getConfig').withArgs('adagio').returns({ - siteId: '1000:SITE-NAME' - }); - - const bid = new BidRequestBuilder({ - params: { placement: 'PAVE_ATF' } - }).build(); - - expect(spec.isBidRequestValid(bid)).to.equal(true); - }) - - it('should return false if bid.params is missing', function() { - sandbox.spy(utils, 'logWarn'); - const bid01 = new BidRequestBuilder().build(); - - expect(spec.isBidRequestValid(bid01)).to.equal(false); - sinon.assert.callCount(utils.logWarn, 1); - }); - - it('should use adUnit code for adUnitElementId and placement params', function() { - const bid01 = new BidRequestBuilder({ params: { - organizationId: '1000', - site: 'site-name', - useAdUnitCodeAsPlacement: true, - useAdUnitCodeAsAdUnitElementId: true - }}).build(); - - expect(spec.isBidRequestValid(bid01)).to.equal(true); - expect(bid01.params.adUnitElementId).to.equal('adunit-code'); - expect(bid01.params.placement).to.equal('adunit-code'); - }); - - it('should return false when a required param is missing', function() { - const bid01 = new BidRequestBuilder({ params: { - organizationId: '1000', - placement: 'PAVE_ATF' - }}).build(); - - const bid02 = new BidRequestBuilder({ params: { - organizationId: '1000', - site: 'SITE-NAME' - }}).build(); - - const bid03 = new BidRequestBuilder({ params: { - placement: 'PAVE_ATF', - site: 'SITE-NAME' - }}).build(); - - sandbox.stub(config, 'getConfig').withArgs('adagio').returns({ - siteId: '1000' - }); - - const bid04 = new BidRequestBuilder({ params: { placement: 'PAVE_ATF' } }).build(); - - expect(spec.isBidRequestValid(bid01)).to.equal(false); - expect(spec.isBidRequestValid(bid02)).to.equal(false); - expect(spec.isBidRequestValid(bid03)).to.equal(false); - expect(spec.isBidRequestValid(bid04)).to.equal(false); - }); - }); - - describe('buildRequests()', function() { - const expectedDataKeys = [ - 'organizationId', - 'secure', - 'device', - 'site', - 'pageviewId', - 'adUnits', - 'regs', - 'user', - 'schain', - 'prebidVersion', - 'hasRtd', - 'data', - 'usIfr', - ]; - - it('groups requests by organizationId', function() { - const bid01 = new BidRequestBuilder().withParams().build(); - const bid02 = new BidRequestBuilder().withParams().build(); - const bid03 = new BidRequestBuilder().withParams({ - organizationId: '1002' - }).build(); - - const bidderRequest = new BidderRequestBuilder().build(); - - const requests = spec.buildRequests([bid01, bid02, bid03], bidderRequest); - - expect(requests).to.have.lengthOf(2); - - expect(requests[0].data.organizationId).to.equal('1000'); - expect(requests[0].data.adUnits).to.have.lengthOf(2); - - expect(requests[1].data.organizationId).to.equal('1002'); - expect(requests[1].data.adUnits).to.have.lengthOf(1); - }); - - it('should send bid request to ENDPOINT_PB via POST', function() { - sandbox.stub(_internal, 'getDevice').returns({ a: 'a' }); - sandbox.stub(_internal, 'getSite').returns({ domain: 'adagio.io', 'page': 'https://adagio.io/hb' }); - - const bid01 = new BidRequestBuilder().withParams().build(); - const bidderRequest = new BidderRequestBuilder().build(); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests).to.have.lengthOf(1); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(ENDPOINT); - expect(requests[0].options.contentType).to.eq('text/plain'); - expect(requests[0].data).to.have.all.keys(expectedDataKeys); - }); - - it('should use a custom generated auctionId from ortb2.site.ext.data.adg_rtd.uid when available', function() { - const expectedAuctionId = '373bcda7-9794-4f1c-be2c-0d223d11d579' - - const bid01 = new BidRequestBuilder().withParams().build(); - const ortb = { - ortb2: { - site: { - ext: { - data: { - adg_rtd: { - uid: expectedAuctionId - } - } - } - } - } - } - const bidderRequest = new BidderRequestBuilder(ortb).build(); - - const requests = spec.buildRequests([bid01], bidderRequest); - expect(requests[0].data.adUnits[0].auctionId).eq(expectedAuctionId); - expect(requests[0].data.adUnits[0].transactionId).to.not.exist; - }); - - it('should use a custom generated auctionId when ortb2.site.ext.data.adg_rtd.uid is absent and remove transactionId', function() { - const expectedAuctionId = '373bcda7-9794-4f1c-be2c-0d223d11d579' - sandbox.stub(utils, 'generateUUID').returns(expectedAuctionId); - - const bid01 = new BidRequestBuilder().withParams().build(); - const bidderRequest = new BidderRequestBuilder().build(); - - const requests = spec.buildRequests([bid01], bidderRequest); - expect(requests[0].data.adUnits[0].auctionId).eq(expectedAuctionId); - expect(requests[0].data.adUnits[0].transactionId).to.not.exist; - }); - - it('should enrich prebid bid requests params', function() { - const expectedPageviewId = '56befc26-8cf0-472d-b105-73896df8eb89'; - sandbox.stub(_internal, 'getAdagioNs').returns({ pageviewId: expectedPageviewId }); - - const bid01 = new BidRequestBuilder().withParams().build(); - const bidderRequest = new BidderRequestBuilder().build(); - - spec.buildRequests([bid01], bidderRequest); - - expect(bid01.params.pageviewId).eq(expectedPageviewId); - }); - - it('should force split keyword param into a string', function() { - const bid01 = new BidRequestBuilder().withParams({ - splitKeyword: 1234 - }).build(); - const bid02 = new BidRequestBuilder().withParams({ - splitKeyword: ['1234'] - }).build(); - const bidderRequest = new BidderRequestBuilder().build(); - - const requests = spec.buildRequests([bid01, bid02], bidderRequest); - - expect(requests).to.have.lengthOf(1); - expect(requests[0].data).to.have.all.keys(expectedDataKeys); - expect(requests[0].data.adUnits[0].params).to.exist; - expect(requests[0].data.adUnits[0].params.splitKeyword).to.exist; - expect(requests[0].data.adUnits[0].params.splitKeyword).to.equal('1234'); - expect(requests[0].data.adUnits[1].params.splitKeyword).to.not.exist; - }); - - it('should force key and value from data layer param into a string', function() { - const bid01 = new BidRequestBuilder().withParams({ - dataLayer: { - 1234: 'dlparam', - goodkey: 1234, - objectvalue: { - random: 'result' - }, - arrayvalue: ['1234'] - } - }).build(); - - const bid02 = new BidRequestBuilder().withParams({ - dataLayer: 'a random string' - }).build(); - - const bid03 = new BidRequestBuilder().withParams({ - dataLayer: 1234 - }).build(); - - const bid04 = new BidRequestBuilder().withParams({ - dataLayer: ['an array'] - }).build(); - - const bidderRequest = new BidderRequestBuilder().build(); - - const requests = spec.buildRequests([bid01, bid02, bid03, bid04], bidderRequest); - - expect(requests).to.have.lengthOf(1); - expect(requests[0].data).to.have.all.keys(expectedDataKeys); - expect(requests[0].data.adUnits[0].params).to.exist; - expect(requests[0].data.adUnits[0].params.dataLayer).to.not.exist; - expect(requests[0].data.adUnits[0].params.dl).to.exist; - expect(requests[0].data.adUnits[0].params.dl['1234']).to.equal('dlparam'); - expect(requests[0].data.adUnits[0].params.dl.goodkey).to.equal('1234'); - expect(requests[0].data.adUnits[0].params.dl.objectvalue).to.not.exist; - expect(requests[0].data.adUnits[0].params.dl.arrayvalue).to.not.exist; - - expect(requests[0].data.adUnits[1].params).to.exist; - expect(requests[0].data.adUnits[1].params.dl).to.not.exist; - expect(requests[0].data.adUnits[1].params.dataLayer).to.not.exist; - - expect(requests[0].data.adUnits[2].params).to.exist; - expect(requests[0].data.adUnits[2].params.dl).to.not.exist; - expect(requests[0].data.adUnits[2].params.dataLayer).to.not.exist; - - expect(requests[0].data.adUnits[3].params).to.exist; - expect(requests[0].data.adUnits[3].params.dl).to.not.exist; - expect(requests[0].data.adUnits[3].params.dataLayer).to.not.exist; - }); - - describe('with adagioRtdProvider enrichments', function() { - const adUnitRtdEnrichments = { - ortb2: { - site: { - ext: { - data: { - adg_rtd: { - features: { - page_dimensions: '1024x768', - viewport_dimensions: '1024x768', - user_timestamp: '111111111', - dom_loading: '111111111', - } - } - }}} - }, - ortb2Imp: { - ext: { - data: { - adg_rtd: { - adunit_position: '1x1' - } - } - } - } - } - const rtdEnrichments = { - ortb2: { - site: { - ext: { - data: { - adg_rtd: { - session: { - new: true, - rnd: 0.0666 - }, - } - } - } - } - } - } - - it('should add features and data to the request if exists', function() { - const bid01 = new BidRequestBuilder(adUnitRtdEnrichments).withParams().build(); - const bidderRequest = new BidderRequestBuilder(rtdEnrichments).build(); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.data).to.deep.equal({ - session: { - new: true, - rnd: 0.0666 - } - }); - - expect(requests[0].data.adUnits[0].features).to.deep.equal({ - page_dimensions: '1024x768', - viewport_dimensions: '1024x768', - user_timestamp: '111111111', - dom_loading: '111111111', - adunit_position: '1x1', - print_number: '1' - }) - }); - - it('should add an only "print_number" in features object if ortb2 is not properly defined', function() { - const bid01 = new BidRequestBuilder({ - ortb2: {}, - bidderRequestsCount: 2 - }).withParams().build(); - const bidderRequest = new BidderRequestBuilder().build(); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.adUnits[0].features).to.deep.equal({ - print_number: '2' - }); - }); - - it('should send data.session with default if the ortb2 ext is not properly defined', function() { - const bid01 = new BidRequestBuilder().withParams().build(); - const bidderRequest = new BidderRequestBuilder().build(); - sandbox.stub(Math, 'random').returns(0.444); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.data.session).to.exist; - expect(requests[0].data.data.session.new).to.equal(true); - expect(requests[0].data.data.session.rnd).to.equal(0.444); - }); - }); - - describe('With video mediatype', function() { - context('Outstream video', function() { - it('should set playerName = "other" if user does not set renderer.backupOnly: true', function() { - const bid01 = new BidRequestBuilder({ - adUnitCode: 'adunit-code-01', - mediaTypes: { - banner: { sizes: [[300, 250]] }, - video: { - context: 'outstream', - playerSize: [[300, 250]], - renderer: { - url: 'https://url.tld', - render: () => true - } - } - }, - }).withParams().build(); - const bidderRequest = new BidderRequestBuilder().build(); - const request = spec.buildRequests([bid01], bidderRequest)[0]; - - expect(request.data.adUnits[0].mediaTypes.video.playerName).to.equal('other'); - }); - - it('should set playerName = "adagio" if user does not set a renderer or set `renderer.backupOnly: true`', function() { - const bid01 = new BidRequestBuilder({ - adUnitCode: 'adunit-code-01', - mediaTypes: { - banner: { sizes: [[300, 250]] }, - video: { - context: 'outstream', - playerSize: [[300, 250]], - } - }, - }).withParams().build(); - const bid02 = new BidRequestBuilder({ - adUnitCode: 'adunit-code-02', - mediaTypes: { - banner: { sizes: [[300, 250]] }, - video: { - context: 'outstream', - playerSize: [[300, 250]], - renderer: { - url: 'https://url.tld', - render: () => true, - backupOnly: true - } - } - }, - }).withParams().build(); - const bidderRequest = new BidderRequestBuilder().build(); - const request = spec.buildRequests([bid01, bid02], bidderRequest)[0]; - - expect(request.data.adUnits[0].mediaTypes.video.playerName).to.equal('adagio'); - expect(request.data.adUnits[1].mediaTypes.video.playerName).to.equal('adagio'); - }); - }); - - it('Update mediaTypes.video with OpenRTB options. Validate and sanitize whitelisted OpenRTB', function() { - sandbox.spy(utils, 'logWarn'); - const bid01 = new BidRequestBuilder({ - adUnitCode: 'adunit-code-01', - mediaTypes: { - banner: { sizes: [[300, 250]] }, - video: { - context: 'outstream', - playerSize: [[300, 250]], - mimes: ['video/mp4'], - api: 'val', // will be removed because invalid - playbackmethod: ['val'], // will be removed because invalid - } - }, - }).withParams({ - // options in video, will overide - video: { - skip: 1, - skipafter: 4, - minduration: 10, - maxduration: 30, - plcmt: 4, - protocols: [8] - } - }).build(); - - const bidderRequest = new BidderRequestBuilder().build(); - const expected = { - context: 'outstream', - playerSize: [[300, 250]], - playerName: 'adagio', - mimes: ['video/mp4'], - skip: 1, - skipafter: 4, - minduration: 10, - maxduration: 30, - plcmt: 4, - protocols: [8], - w: 300, - h: 250 - }; - - const requests = spec.buildRequests([bid01], bidderRequest); - expect(requests).to.have.lengthOf(1); - expect(requests[0].data.adUnits[0].mediaTypes.video).to.deep.equal(expected); - }); - }); - - describe('with sChain', function() { - const schain = { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'ssp.test', - sid: '00001', - hp: 1 - }] - }; - - it('should add the schain if available at bidder level', function() { - const bid01 = new BidRequestBuilder({ ortb2: { source: { ext: { schain } } } }).withParams().build(); - const bidderRequest = new BidderRequestBuilder().build(); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data).to.have.all.keys(expectedDataKeys); - expect(requests[0].data.schain).to.exist; - expect(requests[0].data.schain).to.deep.equal(schain); - }); - - it('Schain should not be added to the request', function() { - const bid01 = new BidRequestBuilder().withParams().build(); - const bidderRequest = new BidderRequestBuilder().build(); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.schain).to.not.exist; - }); - }); - - describe('with GDPR', function() { - const bid01 = new BidRequestBuilder().withParams().build(); - - const consentString = 'BOJ/P2HOJ/P2HABABMAAAAAZ+A=='; - - const gdprConsentBuilderTCF1 = function gdprConsentBuilderTCF1(applies, allows) { - return { - consentString, - gdprApplies: applies, - allowAuctionWithoutConsent: allows, - apiVersion: 1 - }; - }; - - const gdprConsentBuilderTCF2 = function gdprConsentBuilderTCF2(applies) { - return { - consentString, - gdprApplies: applies, - apiVersion: 2 - }; - }; - - context('When GDPR applies', function() { - it('send data.gdpr object to the server from TCF v.1.1 cmp', function() { - const bidderRequest = new BidderRequestBuilder({ - gdprConsent: gdprConsentBuilderTCF1(true, true) - }).build(); - - const expected = { - consentString, - allowAuctionWithoutConsent: 1, - consentRequired: 1, - apiVersion: 1 - }; - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.regs.gdpr).to.deep.equal(expected); - }); - - it('send data.gdpr object to the server from TCF v.2 cmp', function() { - const bidderRequest = new BidderRequestBuilder({ - gdprConsent: gdprConsentBuilderTCF2(true) - }).build(); - - const expected = { - consentString, - allowAuctionWithoutConsent: 0, - consentRequired: 1, - apiVersion: 2 - }; - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.regs.gdpr).to.deep.equal(expected); - }); - }); - - context('When GDPR does not applies', function() { - it('send data.gdpr object to the server from TCF v.1.1 cmp', function() { - const bidderRequest = new BidderRequestBuilder({ - gdprConsent: gdprConsentBuilderTCF1(false, true) - }).build(); - - const expected = { - consentString, - allowAuctionWithoutConsent: 1, - consentRequired: 0, - apiVersion: 1 - }; - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.regs.gdpr).to.deep.equal(expected); - }); - - it('send data.gdpr object to the server from TCF v.2 cmp', function() { - const bidderRequest = new BidderRequestBuilder({ - gdprConsent: gdprConsentBuilderTCF2(false) - }).build(); - - const expected = { - consentString, - consentRequired: 0, - allowAuctionWithoutConsent: 0, - apiVersion: 2 - }; - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.regs.gdpr).to.deep.equal(expected); - }); - }); - - context('When GDPR is undefined in bidderRequest', function() { - it('send an empty data.gdpr to the server', function() { - const bidderRequest = new BidderRequestBuilder().build(); - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.regs.gdpr).to.be.empty; - }); - }); - }); - - describe('with COPPA', function() { - const bid01 = new BidRequestBuilder().withParams().build(); - - it('should send the Coppa "required" flag set to "1" in the request', function () { - const bidderRequest = new BidderRequestBuilder().build(); - - sandbox.stub(config, 'getConfig') - .withArgs('userSync').returns({ syncEnabled: true }) - .withArgs('coppa').returns(true); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.regs.coppa.required).to.equal(1); - }); - }); - - describe('without COPPA', function() { - const bid01 = new BidRequestBuilder().withParams().build(); - - it('should send the Coppa "required" flag set to "0" in the request', function () { - const bidderRequest = new BidderRequestBuilder().build(); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.regs.coppa.required).to.equal(0); - }); - }); - - describe('with USPrivacy', function() { - const bid01 = new BidRequestBuilder().withParams().build(); - - const consent = 'Y11N'; - - it('should send the USPrivacy "ccpa.uspConsent" in the request', function () { - const bidderRequest = new BidderRequestBuilder({ - uspConsent: consent - }).build(); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.regs.ccpa.uspConsent).to.equal(consent); - }); - }); - - describe('without USPrivacy', function() { - const bid01 = new BidRequestBuilder().withParams().build(); - - it('should have an empty "ccpa" field in the request', function () { - const bidderRequest = new BidderRequestBuilder().build(); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.regs.ccpa).to.be.empty; - }); - }); - - describe('with GPP', function() { - const bid01 = new BidRequestBuilder().withParams().build(); - - const gpp = 'gpp_consent_string'; - const gppSid = [1]; - - context('When GPP is defined', function() { - it('send gpp and gppSid coming from ortb2 to the server', function() { - const bidderRequest = new BidderRequestBuilder({ - ortb2: { - regs: { - gpp, - gpp_sid: gppSid, - } - } - }).build(); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.regs.gpp).to.equal(gpp); - expect(requests[0].data.regs.gppSid).to.equal(gppSid); - }); - }); - - context('When GPP not defined in any modules', function() { - it('send empty gpp and gppSid', function() { - const bidderRequest = new BidderRequestBuilder({}).build(); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.regs.gpp).to.equal(''); - expect(requests[0].data.regs.gppSid).to.be.empty; - }); - }); - }); - - describe('with userID modules', function() { - const userIdAsEids = [{ - 'source': 'pubcid.org', - 'uids': [ - { - 'atype': 1, - 'id': '01EAJWWNEPN3CYMM5N8M5VXY22' - } - ] - }]; - - it('should send "user.eids" in the request for Prebid.js supported modules only', function() { - const bid01 = new BidRequestBuilder({ - userIdAsEids - }).withParams().build(); - - const bidderRequest = new BidderRequestBuilder().build(); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.user.eids).to.deep.equal(userIdAsEids); - }); - - it('should send an empty "user.eids" array in the request if userId module is unsupported', function() { - const bid01 = new BidRequestBuilder({ - userId: { - unsuported: '666' - } - }).withParams().build(); - - const bidderRequest = new BidderRequestBuilder().build(); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.user.eids).to.be.empty; - }); - }); - - describe('with priceFloors module', function() { - it('should get and set floor by mediatype and sizes', function() { - const bid01 = new BidRequestBuilder({ - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - }, - video: { - playerSize: [600, 480] - } - } - }).withParams().build(); - const bidderRequest = new BidderRequestBuilder().build(); - - // delete the computed `sizes` prop as we are based on mediaTypes only. - delete bid01.sizes - - bid01.getFloor = () => { - return { floor: 1, currency: 'USD' } - } - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.adUnits[0].mediaTypes.banner.sizes.length).to.equal(2); - expect(requests[0].data.adUnits[0].mediaTypes.banner.bannerSizes[0]).to.deep.equal({size: [300, 250], floor: 1}); - expect(requests[0].data.adUnits[0].mediaTypes.banner.bannerSizes[1]).to.deep.equal({size: [300, 600], floor: 1}); - expect(requests[0].data.adUnits[0].mediaTypes.video.floor).to.equal(1); - }); - - it('should get and set floor by mediatype if no size provided (ex native, video)', function() { - const bid01 = new BidRequestBuilder({ - mediaTypes: { - video: { - context: 'outstream', - mimes: ['video/mp4'] - }, - native: { - body: { required: true } - } - } - }).withParams().build(); - const bidderRequest = new BidderRequestBuilder().build(); - bid01.getFloor = () => { - return { floor: 1, currency: 'USD' } - } - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.adUnits[0].mediaTypes.video.floor).to.equal(1); - expect(requests[0].data.adUnits[0].mediaTypes.native.floor).to.equal(1); - }); - - it('should get and set floor with default value if no floors found', function() { - const bid01 = new BidRequestBuilder({ - mediaTypes: { - video: { - context: 'outstream', - mimes: ['video/mp4'] - } - } - }).withParams().build(); - const bidderRequest = new BidderRequestBuilder().build(); - bid01.getFloor = () => { - return { floor: NaN, currency: 'USD', mt: 'video' } - } - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.adUnits[0].mediaTypes.video.floor).to.be.undefined; - }); - }); - - describe('with user-sync iframe enabled', function () { - const bid01 = new BidRequestBuilder().withParams().build(); - - it('should send the UsIfr flag set to "true" in the request', function () { - const bidderRequest = new BidderRequestBuilder().build(); - - sandbox.stub(config, 'getConfig') - .withArgs('userSync') - .returns({ syncEnabled: true }); - - sandbox.stub(userSync, 'canBidderRegisterSync') - .withArgs('iframe', 'adagio') - .returns(true); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.usIfr).to.equal(true); - }); - }); - - describe('with user-sync iframe disabled', function () { - const bid01 = new BidRequestBuilder().withParams().build(); - - it('should send the UsIfr flag set to "false" in the request', function () { - const bidderRequest = new BidderRequestBuilder().build(); - - sandbox.stub(config, 'getConfig') - .withArgs('userSync') - .returns({ syncEnabled: true }); - - sandbox.stub(userSync, 'canBidderRegisterSync') - .withArgs('iframe', 'adagio') - .returns(false); - - const requests = spec.buildRequests([bid01], bidderRequest); - - expect(requests[0].data.usIfr).to.equal(false); - }); - }); - - describe('with GPID', function () { - const gpid = '/12345/my-gpt-tag-0'; - - it('should add preferred gpid to the request', function () { - const bid01 = new BidRequestBuilder().withParams().build(); - bid01.ortb2Imp = { - ext: { - gpid: gpid - } - }; - const bidderRequest = new BidderRequestBuilder().build(); - const requests = spec.buildRequests([bid01], bidderRequest); - expect(requests[0].data.adUnits[0].gpid).to.exist.and.equal(gpid); - }); - - it('should add backup gpid to the request', function () { - const bid01 = new BidRequestBuilder().withParams().build(); - bid01.ortb2Imp = { - ext: { - data: {}, - gpid, - } - }; - const bidderRequest = new BidderRequestBuilder().build(); - const requests = spec.buildRequests([bid01], bidderRequest); - expect(requests[0].data.adUnits[0].gpid).to.exist.and.equal(gpid); - }); - }); - - describe('with DSA', function() { - it('should add DSA to the request', function() { - const dsaObject = { - dsarequired: 1, - pubrender: 1, - datatopub: 2, - transparency: [{ - domain: 'domain.com', - dsaparams: [1, 2] - }] - } - - const bid01 = new BidRequestBuilder().withParams().build(); - - const bidderRequest = new BidderRequestBuilder({ - ortb2: { - regs: { - ext: { - dsa: dsaObject - } - } - } - }).build(); - const requests = spec.buildRequests([bid01], bidderRequest); - expect(requests[0].data.regs.dsa).to.deep.equal(dsaObject); - }); - - it('should not add DSA to the request if not present', function() { - const bid01 = new BidRequestBuilder().withParams().build(); - const bidderRequest = new BidderRequestBuilder().build(); - const requests = spec.buildRequests([bid01], bidderRequest); - expect(requests[0].data.regs.dsa).to.be.undefined; - }); - }) - - describe('with ORTB2', function() { - it('should add ortb2 device data to the request', function() { - const ortb2 = { - device: { - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - ext: {fiftyonedegrees_deviceId: '17595-133085-133468-18092'}, - }, - }; - - const bid01 = new BidRequestBuilder().withParams().build(); - const bidderRequest = new BidderRequestBuilder({ortb2}).build(); - const requests = spec.buildRequests([bid01], bidderRequest); - - const expectedData = { - ...ortb2.device, - language: navigator[navigator.language ? 'language' : 'userLanguage'], - js: 1, - geo: {}, - userAgent: navigator.userAgent, - }; - - expect(requests[0].data.device).to.deep.equal(expectedData); - }); - }); - - describe('with `rwdd` and `instl` signals', function() { - const tests = [ - { - n: 'Should set signals in bidRequest if value is 1', - ortb2Imp: { - rwdd: 1, - instl: '1' - }, - expected: { - rwdd: 1, - instl: 1 - } - }, - { - n: 'Should not set signals in bidRequest if value is 0', - ortb2Imp: { - rwdd: 0, - instl: '0' - }, - expected: { - rwdd: undefined, - instl: undefined - } - }, - { - n: 'Should not set if rwdd and instl are missformated', - ortb2Imp: { - rwdd: 'a', - ext: { instl: 1 } - }, - expected: { - rwdd: undefined, - instl: undefined - } - }, - { - n: 'Should not set rwdd and instl in bidRequest if undefined', - ortb2Imp: {}, - expected: { - rwdd: undefined, - instl: undefined - } - } - ] - - tests.forEach((t) => { - it(t.n, function() { - const bid01 = new BidRequestBuilder().withParams().build(); - bid01.ortb2Imp = t.ortb2Imp; - const bidderRequest = new BidderRequestBuilder().build(); - const requests = spec.buildRequests([bid01], bidderRequest); - const expected = t.expected; - expect(requests[0].data.adUnits[0].rwdd).to.equal(expected.rwdd); - expect(requests[0].data.adUnits[0].instl).to.equal(expected.instl); - }); - }) - }) - }); - - describe('interpretResponse()', function() { - const serverResponse = { - body: { - data: { - pred: 1 - }, - bids: [{ - ad: '
', - cpm: 1, - creativeId: 'creativeId', - currency: 'EUR', - height: 250, - netRevenue: true, - requestId: 'c180kg4267tyqz', - ttl: 360, - width: 300, - aDomain: ['advertiser.com'], - mediaType: 'banner', - meta: { - advertiserId: '80', - advertiserName: 'An Advertiser', - networkId: '110' - } - }] - } - }; - - const bidRequest = { - data: { - adUnits: [{ - bidder: 'adagio', - params: { - organizationId: '1000', - placement: 'PAVE_ATF', - site: 'SITE-NAME', - adUnitElementId: 'gpt-adunit-code', - pagetype: 'ARTICLE', - category: 'NEWS', - supportIObs: true - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { sizes: [[300, 250], [300, 600]] } - }, - bidId: 'c180kg4267tyqz', - bidderRequestId: '8vfscuixrovn8i', - auctionId: 'lel4fhp239i9km', - pageviewId: 'd8c4fl2k39i0wn', - }] - } - }; - - it('should return an empty response array if body is empty', function() { - expect(spec.interpretResponse({ - body: null - }, bidRequest)).to.be.an('array').length(0); - - expect(spec.interpretResponse({ - body: {} - }, bidRequest)).to.be.an('array').length(0); - }); - - it('should return an empty response array if bids array is empty', function() { - expect(spec.interpretResponse({ - body: { - bids: [] - } - }, bidRequest)).to.be.an('array').length(0); - }); - - it('should handle properly a correct bid response', function() { - const expectedResponse = [{ - ad: '
', - cpm: 1, - creativeId: 'creativeId', - currency: 'EUR', - height: 250, - netRevenue: true, - requestId: 'c180kg4267tyqz', - ttl: 360, - width: 300, - placement: 'PAVE_ATF', - site: 'SITE-NAME', - pagetype: 'ARTICLE', - category: 'NEWS', - aDomain: ['advertiser.com'], - mediaType: 'banner', - meta: { - advertiserId: '80', - advertiserName: 'An Advertiser', - advertiserDomains: ['advertiser.com'], - networkId: '110', - mediaType: 'banner' - } - }]; - - expect(spec.interpretResponse(serverResponse, bidRequest)).to.be.an('array'); - expect(spec.interpretResponse(serverResponse, bidRequest)).to.deep.equal(expectedResponse); - }); - - it('Meta props should be limited if no bid.meta is provided', function() { - const altServerResponse = utils.deepClone(serverResponse); - delete altServerResponse.body.bids[0].meta; - - const expectedResponse = [{ - ad: '
', - cpm: 1, - creativeId: 'creativeId', - currency: 'EUR', - height: 250, - netRevenue: true, - requestId: 'c180kg4267tyqz', - ttl: 360, - width: 300, - placement: 'PAVE_ATF', - site: 'SITE-NAME', - pagetype: 'ARTICLE', - category: 'NEWS', - aDomain: ['advertiser.com'], - mediaType: 'banner', - meta: { - advertiserDomains: ['advertiser.com'], - mediaType: 'banner' - } - }]; - - expect(spec.interpretResponse(altServerResponse, bidRequest)).to.deep.equal(expectedResponse); - }); - - it('should populate ADAGIO queue with ssp-data', function() { - sandbox.stub(Date, 'now').returns(12345); - sandbox.stub(_internal, 'hasRtd').returns(true); - const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') - - spec.interpretResponse(serverResponse, bidRequest); - - expect(spy.withArgs({ - action: 'ssp-data', - ts: 12345, - data: serverResponse.body.data - }).calledOnce).to.be.true; - }); - - it('should properly try-catch an exception and return an empty array', function() { - sandbox.stub(_internal, 'hasRtd').returns(true); - sandbox.stub(_internal, 'getAdagioNs').returns({ queue: () => { throw new Error('test') } }); - const spy = sandbox.spy(utils, 'logError'); - expect(spec.interpretResponse(serverResponse, bidRequest)).to.be.an('array').length(0); - expect(spy.calledOnce).to.be.true; - }); - - describe('Response with video outstream', function() { - const bidRequestWithOutstream = utils.deepClone(bidRequest); - bidRequestWithOutstream.data.adUnits[0].mediaTypes.video = { - context: 'outstream', - playerSize: [[300, 250]], - mimes: ['video/mp4'], - skip: 1, - skipafter: 3 - }; - - const serverResponseWithOutstream = utils.deepClone(serverResponse); - serverResponseWithOutstream.body.bids[0].vastXml = ''; - serverResponseWithOutstream.body.bids[0].mediaType = 'video'; - - const defaultRendererUrl = BB_RENDERER_URL.replace('$RENDERER', 'renderer'); - - it('should set related properties for video outstream context', function() { - const bidResponse = spec.interpretResponse(serverResponseWithOutstream, bidRequestWithOutstream)[0]; - expect(bidResponse).to.have.any.keys('renderer', 'mediaType'); - expect(bidResponse.renderer).to.be.a('object'); - expect(bidResponse.renderer.url).to.equal(defaultRendererUrl); - expect(bidResponse.renderer.loaded).to.not.be.ok; - expect(bidResponse.width).to.equal(300); - expect(bidResponse.height).to.equal(250); - expect(bidResponse.vastUrl).to.match(/^data:text\/xml;/) - }); - - it('should execute Blue Billywig VAST Renderer bootstrap if defined', function() { - window.bluebillywig = { - renderers: [{ bootstrap: sinon.stub(), _id: 'adagio-renderer' }] - }; - - const bidResponse = spec.interpretResponse(serverResponseWithOutstream, bidRequestWithOutstream)[0]; - executeRenderer(bidResponse.renderer, bidResponse) - sinon.assert.calledOnce(window.bluebillywig.renderers[0].bootstrap); - - delete window.bluebillywig; - }); - - it('Should logError if response does not have a vastXml or vastUrl', function() { - utilsMock.expects('logError').withExactArgs('Adagio: no vastXml or vastUrl on bid').once(); - - const localServerResponseWithOutstream = utils.deepClone(serverResponse); - localServerResponseWithOutstream.body.bids[0].mediaType = 'video'; - - const bidResponse = spec.interpretResponse(localServerResponseWithOutstream, bidRequestWithOutstream)[0]; - executeRenderer(bidResponse.renderer, bidResponse) - - utilsMock.verify(); - }) - - it('should logError if Blue Billywig API is not defined', function() { - utilsMock.expects('logError').withExactArgs('Adagio: no BlueBillywig renderers found!').once(); - - const bidResponse = spec.interpretResponse(serverResponseWithOutstream, bidRequestWithOutstream)[0]; - executeRenderer(bidResponse.renderer, bidResponse) - - utilsMock.verify(); - }); - - it('should logError if correct renderer is not defined', function() { - window.bluebillywig = { renderers: [ { _id: 'adagio-another_renderer' } ] }; - - utilsMock.expects('logError').withExactArgs('Adagio: couldn\'t find a renderer with ID adagio-renderer').once(); - - const bidResponse = spec.interpretResponse(serverResponseWithOutstream, bidRequestWithOutstream)[0]; - executeRenderer(bidResponse.renderer, bidResponse) - - delete window.bluebillywig; - utilsMock.verify(); - }); - }); - - describe('Response with native add', function() { - const serverResponseWithNative = utils.deepClone(serverResponse) - serverResponseWithNative.body.bids[0].mediaType = 'native'; - serverResponseWithNative.body.bids[0].admNative = { - ver: '1.2', - link: { - url: 'https://i.am.a.click.url', - clicktrackers: [ - 'https://i.am.a.clicktracker.url' - ] - }, - privacy: 'http://www.myprivacyurl.url', - ext: { - bvw: 'test' - }, - eventtrackers: [ - { - event: 1, - method: 1, - url: 'https://eventrack.local/impression' - }, - { - event: 1, - method: 2, - url: 'https://eventrack.local/impression' - }, - { - event: 2, - method: 1, - url: 'https://eventrack.local/viewable-mrc50' - } - ], - assets: [ - { - title: { - text: 'My title' - } - }, - { - img: { - url: 'https://images.local/image.jpg', - w: 100, - h: 250 - } - }, - { - img: { - type: 1, - url: 'https://images.local/icon.png', - w: 40, - h: 40 - } - }, - { - data: { - type: 1, // sponsored - value: 'Adagio' - } - }, - { - data: { - type: 2, // desc / body - value: 'The super ad text' - } - }, - { - data: { - type: 3, // rating - value: '10 from 10' - } - }, - { - data: { - type: 11, // displayUrl - value: 'https://i.am.a.display.url' - } - } - ] - }; - - const bidRequestNative = utils.deepClone(bidRequest) - bidRequestNative.nativeParams = { - clickUrl: { - required: true, - }, - title: { - required: true, - }, - body: { - required: true, - }, - sponsoredBy: { - required: false - }, - image: { - required: true - }, - icon: { - required: true - }, - privacyLink: { - required: false - }, - ext: { - adagio_bvw: {} - } - }; - - it('Should ignore native parsing due to missing raw admNative property', () => { - const alternateServerResponse = utils.deepClone(serverResponseWithNative); - delete alternateServerResponse.body.bids[0].admNative - const r = spec.interpretResponse(alternateServerResponse, bidRequestNative); - expect(r[0].mediaType).to.equal(NATIVE); - expect(r[0].native).not.ok; - utilsMock.expects('logError').once(); - }); - - it('Should ignore native parsing due to invalid raw admNative.assets property', () => { - const alternateServerResponse = utils.deepClone(serverResponseWithNative); - alternateServerResponse.body.bids[0].admNative.assets = { title: { text: 'test' } }; - const r = spec.interpretResponse(alternateServerResponse, bidRequestNative); - expect(r[0].mediaType).to.equal(NATIVE); - expect(r[0].native).not.ok; - utilsMock.expects('logError').once(); - }); - - it('Should handle and return a formated Native ad', () => { - const r = spec.interpretResponse(serverResponseWithNative, bidRequestNative); - const expected = { - displayUrl: 'https://i.am.a.display.url', - sponsoredBy: 'Adagio', - body: 'The super ad text', - rating: '10 from 10', - clickUrl: 'https://i.am.a.click.url', - title: 'My title', - impressionTrackers: [ - 'https://eventrack.local/impression' - ], - javascriptTrackers: '', - clickTrackers: [ - 'https://i.am.a.clicktracker.url' - ], - image: { - url: 'https://images.local/image.jpg', - width: 100, - height: 250 - }, - icon: { - url: 'https://images.local/icon.png', - width: 40, - height: 40 - }, - ext: { - adagio_bvw: 'test' - }, - privacyLink: 'http://www.myprivacyurl.url' - } - expect(r[0].mediaType).to.equal(NATIVE); - expect(r[0].native).ok; - expect(r[0].native).to.deep.equal(expected); - }); - - it('Should handle multiple javascriptTrackers in one single string', () => { - const serverResponseWithNativeCopy = utils.deepClone(serverResponseWithNative); - serverResponseWithNativeCopy.body.bids[0].admNative.eventtrackers.push( - { - event: 1, - method: 2, - url: 'https://eventrack.local/impression-2' - },) - const r = spec.interpretResponse(serverResponseWithNativeCopy, bidRequestNative); - const expected = '\n'; - expect(r[0].native.javascriptTrackers).to.equal(expected); - }); - }); - - describe('Response with DSA', function() { - const dsaResponseObj = { - 'behalf': 'Advertiser', - 'paid': 'Advertiser', - 'transparency': { - 'domain': 'dsp1domain.com', - 'params': [1, 2] - }, - 'adrender': 1 - }; - - const serverResponseWithDsa = utils.deepClone(serverResponse); - serverResponseWithDsa.body.bids[0].meta.dsa = dsaResponseObj; - - const bidResponse = spec.interpretResponse(serverResponseWithDsa, bidRequest)[0]; - expect(bidResponse.meta.dsa).to.to.deep.equals(dsaResponseObj); - }) - }); - - describe('getUserSyncs()', function() { - const syncOptions = { - syncEnabled: false - }; - - it('should handle user syncs if data is in the server response ', function() { - const serverResponses = [{ - body: { - userSyncs: [ - { t: 'i', u: 'https://test.url.com/setuid' }, - { t: 'p', u: 'https://test.url.com/setuid' } - ] - } - }]; - - const result = spec.getUserSyncs(syncOptions, serverResponses); - - expect(result[0].type).to.equal('iframe'); - expect(result[0].url).contain('setuid'); - - expect(result[1].type).to.equal('image'); - expect(result[1].url).contain('setuid'); - }); - - it('should return false if data is not in server response', function() { - const serverResponse = [{ body: '' }]; - const result = spec.getUserSyncs(syncOptions, serverResponse); - expect(result).to.equal(false); - }); - }); - - describe('site information using refererDetection or window.top', function() { - it('should returns domain, page and window.referrer in a window.top context', function() { - const bidderRequest = new BidderRequestBuilder({ - refererInfo: { - numIframes: 0, - reachedTop: true, - topmostLocation: 'https://test.io/article/a.html', - page: 'https://test.io/article/a.html', - domain: 'test.io', - ref: 'https://google.com' - } - }).build(); - - expect(_internal.getSite(bidderRequest)).to.deep.equal({ - domain: 'test.io', - page: 'https://test.io/article/a.html', - referrer: 'https://google.com', - top: true - }); - }); - - it('should returns domain and page in a cross-domain w/ top domain reached context', function() { - sandbox.stub(utils, 'canAccessWindowTop').returns(false); - sandbox.stub(utils, 'getWindowSelf').returns({ - document: { - referrer: 'https://google.com' - } - }); - - const info = { - numIframes: 0, - reachedTop: true, - page: 'http://level.io/', - topmostLocation: 'http://level.io/', - stack: [ - 'http://level.io/', - 'http://example.com/iframe1.html', - 'http://example.com/iframe2.html' - ], - canonicalUrl: '', - domain: 'level.io', - ref: null, - }; - - const bidderRequest = new BidderRequestBuilder({ - refererInfo: info - }).build(); - - expect(_internal.getSite(bidderRequest)).to.deep.equal({ - domain: 'level.io', - page: 'http://level.io/', - referrer: 'https://google.com', - top: true - }); - }); - - it('should return info in a cross-domain w/o top domain reached and w/o ancestor context', function() { - sandbox.stub(utils, 'canAccessWindowTop').returns(false); - - const info = { - numIframes: 2, - reachedTop: false, - topmostLocation: 'http://example.com/iframe1.html', - stack: [ - null, - 'http://example.com/iframe1.html', - 'http://example.com/iframe2.html' - ], - canonicalUrl: '', - page: null, - domain: null, - ref: null - }; - - const bidderRequest = new BidderRequestBuilder({ - refererInfo: info - }).build(); - - const s = _internal.getSite(bidderRequest) - expect(s.domain).equal('example.com') - expect(s.page).equal('http://example.com/iframe1.html') - expect(s.referrer).match(/^https?:\/\/.+/); - expect(s.top).equal(false) - }); - }); -}); diff --git a/test/spec/modules/adagioRtdProvider_spec.js b/test/spec/modules/adagioRtdProvider_spec.js deleted file mode 100644 index 84a726d2c..000000000 --- a/test/spec/modules/adagioRtdProvider_spec.js +++ /dev/null @@ -1,732 +0,0 @@ -import { - PLACEMENT_SOURCES, - _internal, - adagioRtdSubmodule, - storage, -} from 'modules/adagioRtdProvider.js'; -import * as utils from 'src/utils.js'; -import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; -import { expect } from 'chai'; -import { getGlobal } from '../../../src/prebidGlobal.js'; - -describe('Adagio Rtd Provider', function () { - const SUBMODULE_NAME = 'adagio'; - - function getElementByIdMock(width, height, x, y) { - const obj = { - x: x || 800, - y: y || 300, - width: width || 300, - height: height || 250, - }; - - return { - ...obj, - getBoundingClientRect: () => { - return { - width: obj.width, - height: obj.height, - left: obj.x, - top: obj.y, - right: obj.x + obj.width, - bottom: obj.y + obj.height - }; - } - }; - } - - let sandbox; - let clock; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - clock = sandbox.useFakeTimers(); - }); - - afterEach(function () { - clock.restore(); - sandbox.restore(); - }); - - describe('submodule `init`', function () { - const config = { - name: SUBMODULE_NAME, - params: { - organizationId: '1000', - site: 'mysite' - } - }; - - it('exists', function () { - expect(adagioRtdSubmodule.init).to.be.a('function'); - }); - - it('returns false missing config params', function () { - const value = adagioRtdSubmodule.init({ - name: SUBMODULE_NAME, - }); - expect(value).to.equal(false); - }); - - it('returns false if missing providers param', function () { - const value = adagioRtdSubmodule.init({ - name: SUBMODULE_NAME, - params: {} - }); - expect(value).to.equal(false); - }); - - it('returns false if organizationId param is not a string', function () { - const value = adagioRtdSubmodule.init({ - name: SUBMODULE_NAME, - params: { - organizationId: 1000, - site: 'mysite' - } - }); - expect(value).to.equal(false); - }); - - it('returns false if `site` param is not a string', function () { - const value = adagioRtdSubmodule.init({ - name: SUBMODULE_NAME, - params: { - organizationId: '1000', - site: 123 - } - }); - expect(value).to.equal(false); - }); - - it('returns true if `organizationId` and `site` params included', function () { - const value = adagioRtdSubmodule.init(config); - expect(value).to.equal(true); - }); - - it('load an external script if localStorageIsEnabled is enabled', function () { - sandbox.stub(storage, 'localStorageIsEnabled').callsArgWith(0, true) - adagioRtdSubmodule.init(config); - expect(loadExternalScriptStub.called).to.be.true; - }); - - it('do not load an external script if localStorageIsEnabled is disabled', function () { - sandbox.stub(storage, 'localStorageIsEnabled').callsArgWith(0, false) - adagioRtdSubmodule.init(config); - expect(loadExternalScriptStub.called).to.be.false; - }); - - describe('store session data in localStorage', function () { - const session = { - expiry: 1714116530700, - id: 'uid-1234', - rnd: 0.5697, - vwSmplg: 0.1, - vwSmplgNxt: 0.1, - pages: 1, - v: 2 - }; - - it('store new session data for further usage', function () { - const storageValue = JSON.stringify({abTest: {}}); - sandbox.stub(storage, 'getDataFromLocalStorage').callsArgWith(1, storageValue); - sandbox.stub(Date, 'now').returns(1714116520710); - sandbox.stub(Math, 'random').returns(0.8); - sandbox.stub(utils, 'generateUUID').returns('uid-1234'); - - const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') - - adagioRtdSubmodule.init(config); - - const expected = { - session: { - v: 2, - new: true, - id: utils.generateUUID(), - rnd: Math.random(), - pages: 1, - } - } - - expect(spy.withArgs({ - action: 'session', - ts: Date.now(), - data: expected, - }).calledOnce).to.be.true; - }); - - it('store existing session data for further usage', function () { - const storageValue = JSON.stringify({session: session, abTest: {}}); - sandbox.stub(storage, 'getDataFromLocalStorage').callsArgWith(1, storageValue); - sandbox.stub(Date, 'now').returns(1714116520710); - sandbox.stub(Math, 'random').returns(0.8); - - const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') - - adagioRtdSubmodule.init(config); - - const expected = { - session: { - ...session, - new: false, - } - } - - expect(spy.withArgs({ - action: 'session', - ts: Date.now(), - data: expected, - }).calledOnce).to.be.true; - }); - - it('store new session if old session has expired data for further usage', function () { - const storageValue = JSON.stringify({session: session, abTest: {}}); - sandbox.stub(Date, 'now').returns(1715679344351); - sandbox.stub(storage, 'getDataFromLocalStorage').callsArgWith(1, storageValue); - sandbox.stub(Math, 'random').returns(0.8); - sandbox.stub(utils, 'generateUUID').returns('uid-5678'); - - const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') - - adagioRtdSubmodule.init(config); - - const expected = { - session: { - ...session, - new: true, - id: utils.generateUUID(), - rnd: Math.random(), - } - } - expect(spy.withArgs({ - action: 'session', - ts: Date.now(), - data: expected, - }).calledOnce).to.be.true; - }); - }); - - describe('store session data in localStorage for old snippet', function () { - it('store new session data for further usage', function () { - const storageValue = null; - sandbox.stub(storage, 'getDataFromLocalStorage').callsArgWith(1, storageValue); - sandbox.stub(Date, 'now').returns(1714116520710); - sandbox.stub(Math, 'random').returns(0.8); - sandbox.stub(utils, 'generateUUID').returns('uid-1234'); - - const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') - - adagioRtdSubmodule.init(config); - - const expected = { - session: { - new: true, - id: utils.generateUUID(), - rnd: Math.random(), - pages: 1 - } - } - - expect(spy.withArgs({ - action: 'session', - ts: Date.now(), - data: expected, - }).calledOnce).to.be.true; - }); - - it('update session data for further usage', function () { - const storageValue = JSON.stringify({ - session: { - new: true, - id: 'uid-1234', - rnd: 0.8, - pages: 1, - expiry: 1714116520710, - testName: 't', - testVersion: 'clt' - } - }); - sandbox.stub(storage, 'getDataFromLocalStorage').callsArgWith(1, storageValue); - sandbox.stub(Date, 'now').returns(1714116520710); - sandbox.stub(Math, 'random').returns(0.8); - sandbox.stub(utils, 'generateUUID').returns('uid-1234'); - - const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') - - adagioRtdSubmodule.init(config); - - const expected = { - session: { - new: false, - expiry: 1714116520710, - id: utils.generateUUID(), - rnd: Math.random(), - pages: 1, - testName: 't', - testVersion: 'clt' - } - } - - expect(spy.withArgs({ - action: 'session', - ts: Date.now(), - data: expected, - }).calledOnce).to.be.true; - }); - }); - - describe('update session data in localStorage from old snippet to new version', function () { - it('update session data for new snippet', function () { - const storageValue = JSON.stringify({ - session: { - new: false, - id: 'uid-1234', - rnd: 0.8, - pages: 1, - expiry: 1714116520710, - testName: 't', - testVersion: 'clt' - }, - abTest: { - expiry: 1714116520810, - testName: 't', - testVersion: 'srv' - } - }); - sandbox.stub(storage, 'getDataFromLocalStorage').callsArgWith(1, storageValue); - sandbox.stub(Date, 'now').returns(1714116520710); - sandbox.stub(Math, 'random').returns(0.8); - sandbox.stub(utils, 'generateUUID').returns('uid-1234'); - - const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') - - adagioRtdSubmodule.init(config); - - const expected = { - session: { - new: false, - expiry: 1714116520710, - id: utils.generateUUID(), - rnd: Math.random(), - pages: 1, - testName: 't', - testVersion: 'srv', - v: 2 - } - } - - expect(spy.withArgs({ - action: 'session', - ts: Date.now(), - data: expected, - }).calledOnce).to.be.true; - }); - }); - }); - - describe('submodule `getBidRequestData`', function () { - const bidReqConfig = { - 'timeout': 700, - 'adUnits': [ - { - 'code': 'div-gpt-ad-1460505748561-0', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]] - } - }, - 'ortb2Imp': {}, - 'bids': [ - { - 'bidder': 'adagio', - 'params': { - 'organizationId': '1004', - 'site': 'maville', - 'useAdUnitCodeAsPlacement': true, - 'adUnitElementId': 'div-gpt-ad-1460505748561-0', - 'pagetype': 'article', - } - }, - { - 'bidder': 'another', - 'params': { - 'pubid': 'xxx', - } - } - ] - } - ], - 'adUnitCodes': [ - 'div-gpt-ad-1460505748561-0' - ], - 'ortb2Fragments': { - 'global': { - 'regs': { - 'ext': { - 'gdpr': 1 - } - }, - 'site': { - 'domain': 'example.com', - 'publisher': { - 'domain': 'example.com' - }, - 'page': 'http://example.com/page.html', - }, - 'device': { - 'w': 1359, - 'h': 1253, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36', - 'language': 'fr' - } - }, - 'bidder': {} - } - }; - - function cb() {} - - beforeEach(function() { - _internal.getFeatures().reset(); - }); - - it('exists', function () { - expect(adagioRtdSubmodule.getBidRequestData).to.be.a('function'); - }); - - it('update the ortb2Fragments object with adg_rtd signals', function() { - const bidRequest = utils.deepClone(bidReqConfig); - - sandbox.stub(window.top.document, 'getElementById').returns(getElementByIdMock()); - sandbox.stub(window.top, 'getComputedStyle').returns({ display: 'block' }); - sandbox.stub(utils, 'inIframe').returns(false); - - adagioRtdSubmodule.getBidRequestData(bidRequest, cb); - const signals = bidRequest.ortb2Fragments.global.site.ext.data.adg_rtd; - expect(signals).to.have.property('features'); - expect(signals).to.have.property('session'); - expect(signals).to.have.property('uid'); - expect(signals.features.viewport_dimensions).to.match(/\d+x\d+/); - expect(signals.features.page_dimensions).to.match(/\d+x\d+/); - - expect(bidRequest.adUnits[0]).to.have.property('ortb2Imp'); - expect(bidRequest.adUnits[0].ortb2Imp.ext.data.adg_rtd.adunit_position).to.match(/\d+x\d+/); - }); - - describe('update the ortb2Fragments object a SafeFrame context', function() { - it('update', function() { - sandbox.stub(utils, 'isSafeFrameWindow').returns(true); - sandbox.stub(utils, 'canAccessWindowTop').returns(false); - - window.$sf = { - ext: { - geom() { - return { - win: {t: 23, r: 1920, b: 1200, l: 0, w: 1920, h: 1177}, - self: {t: 210, r: 1159, b: 460, l: 859, w: 300, h: 250}, - } - } - } - }; - - const bidRequest = utils.deepClone(bidReqConfig); - adagioRtdSubmodule.getBidRequestData(bidRequest, cb); - - const fragmentExt = bidRequest.ortb2Fragments.global.site.ext.data.adg_rtd; - expect(fragmentExt.features.viewport_dimensions).equal('1920x1177'); - expect(fragmentExt.features.page_dimensions).equal(''); - - const ortb2ImpExt = bidRequest.adUnits[0].ortb2Imp.ext.data.adg_rtd; - expect(ortb2ImpExt.adunit_position).equal('210x859'); - - window.$sf = undefined; - }); - - it('handle missformated $sf object and update', function() { - sandbox.stub(utils, 'isSafeFrameWindow').returns(true); - sandbox.stub(utils, 'canAccessWindowTop').returns(false); - - window.$sf = { - ext: { - geom: '' - } - }; - - const bidRequest = utils.deepClone(bidReqConfig); - adagioRtdSubmodule.getBidRequestData(bidRequest, cb); - - const fragmentExt = bidRequest.ortb2Fragments.global.site.ext.data.adg_rtd; - expect(fragmentExt.features.viewport_dimensions).equal(''); - expect(fragmentExt.features.page_dimensions).equal(''); - - const ortb2ImpExt = bidRequest.adUnits[0].ortb2Imp.ext.data.adg_rtd; - expect(ortb2ImpExt.adunit_position).equal(''); - - window.$sf = undefined; - }); - }); - - describe('update the ortb2Fragments object in a "inIframe" context', function() { - it('update when window.top is accessible', function() { - sandbox.stub(utils, 'canAccessWindowTop').returns(true); - sandbox.stub(utils, 'isSafeFrameWindow').returns(false); - sandbox.stub(utils, 'inIframe').returns(true); - - const bidRequest = utils.deepClone(bidReqConfig); - adagioRtdSubmodule.getBidRequestData(bidRequest, cb); - - const ortb2ImpExt = bidRequest.adUnits[0].ortb2Imp.ext.data.adg_rtd; - expect(ortb2ImpExt.adunit_position).equal(''); - }); - - it('catch error when window.top is accessible', function() { - sandbox.stub(utils, 'canAccessWindowTop').returns(true); - sandbox.stub(utils, 'isSafeFrameWindow').returns(false); - sandbox.stub(window.document, 'getElementById').throws(); - - const bidRequest = utils.deepClone(bidReqConfig); - adagioRtdSubmodule.getBidRequestData(bidRequest, cb); - - const ortb2ImpExt = bidRequest.adUnits[0].ortb2Imp.ext.data.adg_rtd; - expect(ortb2ImpExt.adunit_position).equal(''); - }); - }); - - it('update the ortb2Fragments object when window.top is not accessible', function() { - sandbox.stub(utils, 'canAccessWindowTop').returns(false); - sandbox.stub(utils, 'isSafeFrameWindow').returns(false); - - const bidRequest = utils.deepClone(bidReqConfig); - adagioRtdSubmodule.getBidRequestData(bidRequest, cb); - - const fragmentExt = bidRequest.ortb2Fragments.global.site.ext.data.adg_rtd; - expect(fragmentExt.features.viewport_dimensions).equal(''); - expect(fragmentExt.features.page_dimensions).equal(''); - - const ortb2ImpExt = bidRequest.adUnits[0].ortb2Imp.ext.data.adg_rtd; - expect(ortb2ImpExt.adunit_position).equal(''); - }); - - describe('update the ortb2Imp.ext.data.placement if not present', function() { - const config = { - name: SUBMODULE_NAME, - params: { - organizationId: '1000', - site: 'mysite' - } - }; - - it('update the placement value with the adUnit.code value', function() { - const configCopy = utils.deepClone(config); - configCopy.params.placementSource = PLACEMENT_SOURCES.ADUNITCODE; - - const bidRequest = utils.deepClone(bidReqConfig); - - adagioRtdSubmodule.getBidRequestData(bidRequest, cb, configCopy); - expect(bidRequest.adUnits[0]).to.have.property('ortb2Imp'); - expect(bidRequest.adUnits[0].ortb2Imp.ext.data.placement).to.equal('div-gpt-ad-1460505748561-0'); - }); - - it('update the placement value with the gpid value', function() { - const configCopy = utils.deepClone(config); - configCopy.params.placementSource = PLACEMENT_SOURCES.GPID; - - const bidRequest = utils.deepClone(bidReqConfig); - const gpid = '/19968336/header-bid-tag-0' - utils.deepSetValue(bidRequest.adUnits[0], 'ortb2Imp.ext.gpid', gpid) - - adagioRtdSubmodule.getBidRequestData(bidRequest, cb, configCopy); - expect(bidRequest.adUnits[0]).to.have.property('ortb2Imp'); - expect(bidRequest.adUnits[0].ortb2Imp.ext.data.placement).to.equal(gpid); - }); - - it('update the placement value the legacy adUnit[].bids adagio.params.placement value', function() { - const placement = 'placement-value'; - - const configCopy = utils.deepClone(config); - - const bidRequest = utils.deepClone(bidReqConfig); - bidRequest.adUnits[0].bids[0].params.placement = placement; - - adagioRtdSubmodule.getBidRequestData(bidRequest, cb, configCopy); - expect(bidRequest.adUnits[0]).to.have.property('ortb2Imp'); - expect(bidRequest.adUnits[0].ortb2Imp.ext.data.placement).to.equal(placement); - }); - - it('it does not populate `ortb2Imp.ext.data.placement` if no fallback', function() { - const configCopy = utils.deepClone(config); - const bidRequest = utils.deepClone(bidReqConfig); - - adagioRtdSubmodule.getBidRequestData(bidRequest, cb, configCopy); - expect(bidRequest.adUnits[0]).to.have.property('ortb2Imp'); - expect(bidRequest.adUnits[0].ortb2Imp.ext.data.placement).to.not.exist; - }); - - it('ensure we create the `ortb2Imp` object if it does not exist', function() { - const configCopy = utils.deepClone(config); - configCopy.params.placementSource = PLACEMENT_SOURCES.ADUNITCODE; - - const bidRequest = utils.deepClone(bidReqConfig); - delete bidRequest.adUnits[0].ortb2Imp; - - adagioRtdSubmodule.getBidRequestData(bidRequest, cb, configCopy); - expect(bidRequest.adUnits[0]).to.have.property('ortb2Imp'); - expect(bidRequest.adUnits[0].ortb2Imp.ext.data.placement).to.equal('div-gpt-ad-1460505748561-0'); - }); - }); - }); - - describe('submodule `onBidRequestEvent`', function() { - const bidderRequest = { - 'bidderCode': 'adagio', - 'auctionId': '3de10dc0-fe75-480f-95cc-f15f2c4929fe', - 'bidderRequestId': '4ecd1f17cf829b', - 'bids': [ - { - 'bidder': 'adagio', - 'params': { - 'organizationId': '1000', - 'site': 'example', - 'adUnitElementId': 'div-gpt-ad-1460505748561-0', - 'pagetype': 'article', - 'environment': 'desktop', - 'placement': 'div-gpt-ad-1460505748561-0', - 'adagioAuctionId': '4c259968-0158-443d-af93-551bac594b6c', - 'pageviewId': 'dfb9b067-e5c4-4212-97bb-c67d6313ecaf' - }, - 'ortb2Imp': { - 'ext': { - 'tid': '235c991e-fcc4-416b-95d3-f60e53575bee', - 'data': { - 'adserver': { - 'name': 'gam', - 'adslot': '/19968336/header-bid-tag-0' - }, - 'pbadslot': '/19968336/header-bid-tag-0', - 'adunit_position': '8x95' - }, - 'gpid': '/19968336/header-bid-tag-0' - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': '235c991e-fcc4-416b-95d3-f60e53575bee', - 'adUnitId': '79ab5904-0b21-4235-965a-f4905af072b7', - 'bidId': '534aa529a44e0e', - 'bidderRequestId': '4ecd1f17cf829b', - 'auctionId': '3de10dc0-fe75-480f-95cc-f15f2c4929fe', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'site': { - 'ext': { - 'data': { - 'adg_rtd': { - 'uid': 'dfb9b067-e5c4-4212-97bb-c67d6313ecaf', - 'features': { - 'page_dimensions': '1359x1353', - 'viewport_dimensions': '1359x1253', - 'user_timestamp': '1715621032', - 'dom_loading': '28' - }, - 'session': { - 'new': true, - 'rnd': 0.020644826280300954, - 'vwSmplg': 0.1, - 'vwSmplgNxt': 0.1, - 'pages': 1 - } - } - } - } - } - }, - }, - ], - 'auctionStart': 1715613832791, - 'timeout': 700, - 'ortb2': { - 'site': { - 'ext': { - 'data': { - 'adg_rtd': { - 'features': { - 'page_dimensions': '1359x1353', - 'viewport_dimensions': '1359x1253', - 'user_timestamp': '1715621032', - 'dom_loading': '28' - }, - 'session': { - 'new': true, - 'rnd': 0.020644826280300954, - 'vwSmplg': 0.1, - 'vwSmplgNxt': 0.1, - 'pages': 1 - } - } - } - } - } - }, - 'start': 1715613832796 - } - - it('store a copy of computed property', function() { - const spy = sandbox.spy(_internal.getAdagioNs().queue, 'push') - sandbox.stub(Date, 'now').returns(12345); - - _internal.getGuard().clear(); - - const config = { - params: { - organizationId: '1000', - site: 'example' - } - }; - const bidderRequestCopy = utils.deepClone(bidderRequest); - adagioRtdSubmodule.onBidRequestEvent(bidderRequestCopy, config); - - clock.tick(1); - - const { - bidder, - adUnitCode, - mediaTypes, - params, - auctionId, - bidderRequestsCount } = bidderRequestCopy.bids[0]; - - const expected = { - bidder, - adUnitCode, - mediaTypes, - ortb2: bidderRequestCopy.bids[0].ortb2.site.ext.data, - ortb2Imp: bidderRequestCopy.bids[0].ortb2Imp.ext.data, - params, - auctionId, - bidderRequestsCount, - organizationId: config.params.organizationId, - site: config.params.site, - localPbjs: 'pbjs', - localPbjsRef: getGlobal() - } - - expect(spy.withArgs({ - action: 'store', - ts: Date.now(), - data: expected, - }).calledOnce).to.be.true; - }); - }); -}); diff --git a/test/spec/modules/adbutlerBidAdapter_spec.js b/test/spec/modules/adbutlerBidAdapter_spec.js deleted file mode 100644 index be96413ab..000000000 --- a/test/spec/modules/adbutlerBidAdapter_spec.js +++ /dev/null @@ -1,329 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adbutlerBidAdapter.js'; - -describe('AdButler adapter', function () { - let validBidRequests; - - beforeEach(function () { - validBidRequests = [ - { - bidder: 'adbutler', - params: { - accountID: '181556', - zoneID: '705374', - keyword: 'red', - minCPM: '1.00', - maxCPM: '5.00', - }, - placementCode: '/19968336/header-bid-tag-1', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - bidId: '23acc48ad47af5', - auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: '92489f71-1bf2-49a0-adf9-000cea934729', - }, - ]; - }); - - describe('for requests', function () { - describe('without account ID', function () { - it('rejects the bid', function () { - const invalidBid = { - bidder: 'adbutler', - params: { - zoneID: '210093', - }, - }; - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.equal(false); - }); - }); - - describe('without a zone ID', function () { - it('rejects the bid', function () { - const invalidBid = { - bidder: 'adbutler', - params: { - accountID: '167283', - }, - }; - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.equal(false); - }); - }); - - describe('with a valid bid', function () { - describe('with a custom domain', function () { - it('uses the custom domain', function () { - validBidRequests[0].params.domain = 'customadbutlerdomain.com'; - - const requests = spec.buildRequests(validBidRequests); - const requestURL = requests[0].url; - - expect(requestURL).to.have.string('customadbutlerdomain.com'); - }); - }); - - it('accepts the bid', function () { - const validBid = { - bidder: 'adbutler', - params: { - accountID: '167283', - zoneID: '210093', - }, - }; - const isValid = spec.isBidRequestValid(validBid); - - expect(isValid).to.equal(true); - }); - - it('sets default domain', function () { - const requests = spec.buildRequests(validBidRequests); - const request = requests[0]; - - const [domain] = request.url.split('/adserve/'); - - expect(domain).to.equal('https://servedbyadbutler.com'); - }); - - it('sets the keyword parameter', function () { - const requests = spec.buildRequests(validBidRequests); - const requestURL = requests[0].url; - - expect(requestURL).to.have.string(';kw=red;'); - }); - - describe('with extra params', function () { - beforeEach(function() { - validBidRequests[0].params.extra = { - foo: 'bar', - }; - }); - - it('sets the extra parameter', function () { - const requests = spec.buildRequests(validBidRequests); - const requestURL = requests[0].url; - - expect(requestURL).to.have.string(';foo=bar;'); - }); - }); - - describe('with multiple bids to the same zone', function () { - it('increments the place count', function () { - const requests = spec.buildRequests([validBidRequests[0], validBidRequests[0]]); - const firstRequest = requests[0].url; - const secondRequest = requests[1].url; - - expect(firstRequest).to.have.string(';place=0;'); - expect(secondRequest).to.have.string(';place=1;'); - }); - }); - }); - }); - - describe('for server responses', function () { - let serverResponse; - - describe('with no body', function () { - beforeEach(function() { - serverResponse = { - body: null, - }; - }); - - it('does not return any bids', function () { - const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] }); - - expect(bids).to.be.length(0); - }); - }); - - describe('with an incorrect size', function () { - beforeEach(function() { - serverResponse = { - body: { - status: 'SUCCESS', - account_id: 167283, - zone_id: 210083, - cpm: 1.5, - width: 728, - height: 90, - place: 0, - }, - }; - }); - - it('does not return any bids', function () { - const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] }); - - expect(bids).to.be.length(0); - }); - }); - - describe('with a failed status', function () { - beforeEach(function() { - serverResponse = { - body: { - status: 'NO_ELIGIBLE_ADS', - zone_id: 210083, - width: 300, - height: 250, - place: 0, - }, - }; - }); - - it('does not return any bids', function () { - const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] }); - - expect(bids).to.be.length(0); - }); - }); - - describe('with low CPM', function () { - beforeEach(function() { - serverResponse = { - body: { - status: 'SUCCESS', - account_id: 167283, - zone_id: 210093, - cpm: 0.75, - width: 300, - height: 250, - place: 0, - ad_code: '', - tracking_pixels: [], - }, - } - }); - - describe('with a minimum CPM', function () { - it('does not return any bids', function () { - const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] }); - expect(bids).to.be.length(0); - }); - }); - - describe('with no minimum CPM', function () { - beforeEach(function() { - delete validBidRequests[0].params.minCPM; - }); - - it('returns a bid', function() { - const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] }); - - expect(bids).to.be.length(1); - }); - }); - }); - - describe('with high CPM', function () { - beforeEach(function() { - serverResponse = { - body: { - status: 'SUCCESS', - account_id: 167283, - zone_id: 210093, - cpm: 999, - width: 300, - height: 250, - place: 0, - ad_code: '', - tracking_pixels: [], - }, - } - }); - - describe('with a maximum CPM', function () { - it('does not return any bids', function () { - const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] }); - - expect(bids).to.be.length(0); - }); - }); - - describe('with no maximum CPM', function () { - beforeEach(function() { - delete validBidRequests[0].params.maxCPM; - }); - - it('returns a bid', function() { - const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] }); - - expect(bids).to.be.length(1); - }); - }); - }); - - describe('with a valid ad', function () { - beforeEach(function() { - serverResponse = { - body: { - status: 'SUCCESS', - account_id: 167283, - zone_id: 210093, - cpm: 1.5, - width: 300, - height: 250, - place: 0, - ad_code: '', - tracking_pixels: [ - 'http://tracking.pixel.com/params=info', - ], - }, - }; - }); - - it('returns a complete bid', function () { - const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] }); - - expect(bids).to.be.length(1); - expect(bids[0].cpm).to.equal(1.5); - expect(bids[0].width).to.equal(300); - expect(bids[0].height).to.equal(250); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[0].ad).to.have.length.above(1); - expect(bids[0].ad).to.have.string('http://tracking.pixel.com/params=info'); - }); - - describe('for a bid request without banner media type', function () { - beforeEach(function() { - delete validBidRequests[0].mediaTypes.banner; - }); - - it('does not return any bids', function () { - const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] }); - - expect(bids).to.be.length(0); - }); - }); - - describe('with advertiser meta', function () { - beforeEach(function() { - serverResponse.body.advertiser = { - id: 123, - name: 'Advertiser Name', - domain: 'advertiser.com', - }; - }); - - it('returns a bid including advertiser meta', function () { - const bids = spec.interpretResponse(serverResponse, { bidRequest: validBidRequests[0] }); - - expect(bids).to.be.length(1); - expect(bids[0]).to.have.property('meta'); - expect(bids[0].meta.advertiserId).to.equal(123); - expect(bids[0].meta.advertiserName).to.equal('Advertiser Name'); - expect(bids[0].meta.advertiserDomains).to.contain('advertiser.com'); - }); - }); - }); - }); -}); diff --git a/test/spec/modules/addefendBidAdapter_spec.js b/test/spec/modules/addefendBidAdapter_spec.js deleted file mode 100644 index 7faa30c69..000000000 --- a/test/spec/modules/addefendBidAdapter_spec.js +++ /dev/null @@ -1,185 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/addefendBidAdapter.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -describe('addefendBidAdapter', () => { - const defaultBidRequest = { - bidId: 'd66fa86787e0b0ca900a96eacfd5f0bb', - auctionId: 'ccc4c7cdfe11cfbd74065e6dd28413d8', - transactionId: 'd58851660c0c4461e4aa06344fc9c0c6', - sizes: [[300, 250], [300, 600]], - params: { - pageId: 'stringid1', - placementId: 'stringid2' - } - }; - - const deepClone = function (val) { - return JSON.parse(JSON.stringify(val)); - }; - - const buildRequest = (buildRequest, bidderRequest) => { - if (!Array.isArray(buildRequest)) { - buildRequest = [buildRequest]; - } - - return spec.buildRequests(buildRequest, { - ...bidderRequest || {}, - refererInfo: { - page: 'https://referer.example.com' - } - })[0]; - }; - - describe('isBidRequestValid', () => { - it('should return true when required params found', () => { - const bidRequest = deepClone(defaultBidRequest); - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('pageId performs type checking', () => { - const bidRequest = deepClone(defaultBidRequest); - bidRequest.params.pageId = 1; // supposed to be a string - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('placementId performs type checking', () => { - const bidRequest = deepClone(defaultBidRequest); - bidRequest.params.placementId = 1; // supposed to be a string - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false when required params are not passed', () => { - const bidRequest = deepClone(defaultBidRequest); - delete bidRequest.params; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); - - describe('buildRequests', () => { - const bidRequest = deepClone(defaultBidRequest); - const request = buildRequest(bidRequest); - - it('sends bid request to endpoint via https using post', () => { - expect(request.method).to.equal('POST'); - expect(request.url.indexOf('https://')).to.equal(0); - expect(request.url).to.equal(`${spec.hostname}/bid`); - }); - - it('contains prebid version parameter', () => { - expect(request.data.v).to.equal(getGlobal().version); - }); - - it('contains correct referer', () => { - expect(request.data.referer).to.equal('https://referer.example.com'); - }); - - it('contains auctionId', () => { - expect(request.data.auctionId).to.equal('ccc4c7cdfe11cfbd74065e6dd28413d8'); - }); - - it('contains pageId', () => { - expect(request.data.pageId).to.equal('stringid1'); - }); - - it('sends correct bid parameters', () => { - const bidRequest = deepClone(defaultBidRequest); - expect(request.data.bids).to.deep.equal([ { - bidId: bidRequest.bidId, - placementId: bidRequest.params.placementId, - sizes: [ '300x250', '300x600' ], - transactionId: 'd58851660c0c4461e4aa06344fc9c0c6' - } ]); - }); - - it('handles empty gdpr object', () => { - const bidRequest = deepClone(defaultBidRequest); - const request = buildRequest(bidRequest, { - gdprConsent: {} - }); - expect(request.data.gdpr_consent).to.be.equal(''); - }); - - it('handles non-existent gdpr object', () => { - const bidRequest = deepClone(defaultBidRequest); - const request = buildRequest(bidRequest, { - gdprConsent: null - }); - expect(request.data.gdpr_consent).to.be.equal(''); - }); - - it('handles properly filled gdpr string', () => { - const bidRequest = deepClone(defaultBidRequest); - const consentString = 'GDPR_CONSENT_STRING'; - const request = buildRequest(bidRequest, { - gdprConsent: { - gdprApplies: true, - consentString: consentString - } - }); - - expect(request.data.gdpr_consent).to.be.equal(consentString); - }); - }); - - describe('interpretResponse', () => { - it('should get correct bid response', () => { - const serverResponse = [ - { - 'width': 300, - 'height': 250, - 'creativeId': '29681110', - 'ad': '', - 'cpm': 0.5, - 'requestId': 'ccc4c7cdfe11cfbd74065e6dd28413d8', - 'ttl': 120, - 'netRevenue': true, - 'currency': 'EUR', - 'advertiserDomains': ['advertiser.example.com'] - } - ]; - - const expectedResponse = [ - { - 'requestId': 'ccc4c7cdfe11cfbd74065e6dd28413d8', - 'cpm': 0.5, - 'creativeId': '29681110', - 'width': 300, - 'height': 250, - 'ttl': 120, - 'currency': 'EUR', - 'ad': '', - 'netRevenue': true, - 'advertiserDomains': ['advertiser.example.com'] - } - ]; - - const result = spec.interpretResponse({body: serverResponse}); - expect(result.length).to.equal(expectedResponse.length); - Object.keys(expectedResponse[0]).forEach((key) => { - expect(result[0][key]).to.deep.equal(expectedResponse[0][key]); - }); - }); - - it('handles incomplete server response', () => { - const serverResponse = [ - { - 'ad': '', - 'cpm': 0.5, - 'requestId': 'ccc4c7cdfe11cfbd74065e6dd28413d8', - 'ttl': 60 - } - ]; - const result = spec.interpretResponse({body: serverResponse}); - - expect(result.length).to.equal(0); - }); - - it('handles nobid responses', () => { - const serverResponse = []; - const result = spec.interpretResponse({body: serverResponse}); - - expect(result.length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/adfBidAdapter_spec.js b/test/spec/modules/adfBidAdapter_spec.js deleted file mode 100644 index bc15ab40c..000000000 --- a/test/spec/modules/adfBidAdapter_spec.js +++ /dev/null @@ -1,1371 +0,0 @@ -// jshint esversion: 6, es3: false, node: true - -import { assert } from 'chai'; -import { spec } from 'modules/adfBidAdapter.js'; -import { config } from 'src/config.js'; -import { addFPDToBidderRequest } from '../../helpers/fpd.js'; -import { setConfig as setCurrencyConfig } from '../../../modules/currency.js'; - -describe('Adf adapter', function () { - let bids = []; - - describe('backwards-compatibility', function () { - it('should have adformOpenRTB alias defined', function () { - assert.equal(spec.aliases[0].code, 'adformOpenRTB'); - assert.equal(spec.aliases[0].gvlid, 50); - }); - - it('should have adform alias defined', function () { - assert.equal(spec.aliases[1].code, 'adform'); - assert.equal(spec.aliases[1].gvlid, 50); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'adformOpenRTB', - 'params': { - 'mid': '19910113' - } - }; - - it('should return true when required params found', function () { - assert(spec.isBidRequestValid(bid)); - - bid.params = { - inv: 1234, - mname: 'some-placement' - }; - assert(spec.isBidRequestValid(bid)); - - bid.params = { - mid: 4332, - inv: 1234, - mname: 'some-placement' - }; - assert(spec.isBidRequestValid(bid)); - }); - - it('should return false when required params are missing', function () { - bid.params = { adxDomain: 'adx.adform.net' }; - assert.isFalse(spec.isBidRequestValid(bid)); - - bid.params = { - mname: 'some-placement' - }; - assert.isFalse(spec.isBidRequestValid(bid)); - - bid.params = { - inv: 1234 - }; - assert.isFalse(spec.isBidRequestValid(bid)); - }); - }); - - describe('buildRequests', function () { - beforeEach(function () { - config.resetConfig(); - }); - it('should send request with correct structure', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { - adxDomain: '10.8.57.207' - } - }]; - const request = spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }); - - assert.equal(request.method, 'POST'); - assert.equal(request.url, 'https://10.8.57.207/adx/openrtb'); - assert.equal(request.options, undefined); - assert.ok(request.data); - }); - - describe('user privacy', function () { - it('should send GDPR Consent data to adform', function () { - const validBidRequests = [{ bidId: 'bidId', params: { test: 1 } }]; - const ortb2 = { - regs: { - ext: { - gdpr: 1 - } - }, - user: { - ext: { - consent: 'consentDataString' - } - } - }; - const bidderRequest = { ortb2, refererInfo: { page: 'page' } }; - const request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); - - assert.equal(request.user.ext.consent, 'consentDataString'); - assert.equal(request.regs.ext.gdpr, 1); - }); - - it('should send CCPA Consent data to adform', function () { - const validBidRequests = [{ bidId: 'bidId', params: { test: 1 } }]; - const ortb2 = { - regs: { - ext: { - us_privacy: '1YA-' - } - } - }; - let bidderRequest = { ortb2, refererInfo: { page: 'page' } }; - let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); - - assert.equal(request.regs.ext.us_privacy, '1YA-'); - - ortb2.regs.ext.gdpr = 1; - ortb2.user = { ext: { consent: 'consentDataString' } }; - - bidderRequest = { ortb2, refererInfo: { page: 'page' } }; - request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest).data); - - assert.equal(request.regs.ext.us_privacy, '1YA-'); - assert.equal(request.user.ext.consent, 'consentDataString'); - assert.equal(request.regs.ext.gdpr, 1); - }); - - it('should transfer DSA info', function () { - const validBidRequests = [ { bidId: 'bidId', params: { siteId: 'siteId' } } ]; - - const request = JSON.parse( - spec.buildRequests(validBidRequests, { - refererInfo: { page: 'page' }, - ortb2: { - regs: { - ext: { - dsa: { - dsarequired: '1', - pubrender: '2', - datatopub: '3', - transparency: [ - { - domain: 'test.com', - dsaparams: [1, 2, 3] - } - ] - } - } - } - } - }).data - ); - - assert.deepEqual(request.regs, { - ext: { - dsa: { - dsarequired: '1', - pubrender: '2', - datatopub: '3', - transparency: [ - { - domain: 'test.com', - dsaparams: [1, 2, 3] - } - ] - } - } - }); - }); - }); - - it('should add test and is_debug to request, if test is set in parameters', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { test: 1 } - }]; - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data); - - assert.ok(request.is_debug); - assert.equal(request.test, 1); - }); - - it('should have default request structure', function () { - const keys = 'site,user,device,source,ext,imp,regs'.split(','); - const validBidRequests = [{ - bidId: 'bidId', - params: { siteId: 'siteId' } - }]; - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data); - const data = Object.keys(request); - - assert.deepEqual(keys, data); - }); - - it('should set request keys correct values', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { siteId: 'siteId' }, - }]; - const request = JSON.parse(spec.buildRequests(validBidRequests, { - refererInfo: {page: 'page'}, - ortb2: {source: {tid: 'tid'}} - }).data); - - assert.equal(request.source.tid, 'tid'); - assert.equal(request.source.fd, 1); - }); - - it('should send coppa flag', function () { - const ortb2 = { regs: { coppa: 1 } }; - const validBidRequests = [{ bidId: 'bidId', params: { test: 1 } }]; - const request = JSON.parse(spec.buildRequests(validBidRequests, { ortb2, refererInfo: { page: 'page' } }).data); - - assert.equal(request.regs.coppa, 1); - }); - - it('should send info about device', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { mid: '1000' } - }]; - const ortb2 = { device: { ua: 'customUA', h: 100, w: 100, geo: { lat: 1, lon: 1 } } }; - const request = JSON.parse(spec.buildRequests(validBidRequests, { ortb2, refererInfo: { page: 'page' } }).data); - - assert.equal(request.device.ua, 'customUA'); - assert.equal(request.device.w, 100); - assert.equal(request.device.h, 100); - assert.deepEqual(request.device.geo, { lat: 1, lon: 1 }); - }); - - it('should send app info', function () { - const ortb2 = { app: { id: 'appid', name: 'appname' } }; - const validBidRequests = [{ - bidId: 'bidId', - params: { mid: '1000' }, - ortb2 - }]; - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' }, ortb2 }).data); - - assert.equal(request.app.id, 'appid'); - assert.equal(request.app.name, 'appname'); - assert.equal(request.site, undefined); - }); - - it('should send info about the site', function () { - const ortb2 = { - site: { - id: '123123', - publisher: { - domain: 'publisher.domain.com', - name: 'publisher\'s name' - } - } - }; - const validBidRequests = [{ - bidId: 'bidId', - params: { mid: '1000' }, - ortb2 - }]; - const refererInfo = { page: 'page' }; - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo, ortb2 }).data); - - assert.deepEqual(request.site, { - id: '123123', - page: refererInfo.page, - publisher: { - domain: 'publisher.domain.com', - name: 'publisher\'s name' - } - }); - }); - - it('should pass extended ids', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: {}, - userIdAsEids: [ - { source: 'adserver.org', uids: [ { id: 'TTD_ID_FROM_USER_ID_MODULE', atype: 1, ext: { rtiPartner: 'TDID' } } ] }, - { source: 'pubcid.org', uids: [ { id: 'pubCommonId_FROM_USER_ID_MODULE', atype: 1 } ] } - ] - }]; - - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data); - assert.deepEqual(request.user.ext.eids, validBidRequests[0].userIdAsEids); - }); - - it('should send currency if defined', function () { - const validBidRequests = [{ params: {} }]; - const refererInfo = { page: 'page' }; - const bidderRequest = { refererInfo }; - setCurrencyConfig({ adServerCurrency: 'EUR' }) - return addFPDToBidderRequest(bidderRequest).then(res => { - const request = JSON.parse(spec.buildRequests(validBidRequests, res).data); - assert.deepEqual(request.cur, [ 'EUR' ]); - setCurrencyConfig({}); - }); - }); - - it('should pass supply chain object', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: {}, - ortb2: { - source: { - ext: { - schain: { - validation: 'strict', - config: { - ver: '1.0' - } - } - } - } - } - }]; - - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data); - assert.deepEqual(request.source.ext.schain, { - validation: 'strict', - config: { - ver: '1.0' - } - }); - }); - - describe('priceType', function () { - it('should send default priceType', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { siteId: 'siteId' } - }]; - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data); - - assert.equal(request.ext.pt, 'net'); - }); - it('should send correct priceType value', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { priceType: 'net' } - }]; - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data); - - assert.equal(request.ext.pt, 'net'); - }); - }); - - describe('bids', function () { - it('should add more than one bid to the request', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { siteId: 'siteId' } - }, { - bidId: 'bidId2', - params: { siteId: 'siteId' } - }]; - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data); - - assert.equal(request.imp.length, 2); - }); - it('should add incrementing values of id', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { mid: '1000' }, - mediaTypes: {video: {}} - }, { - bidId: 'bidId2', - params: { mid: '1000' }, - mediaTypes: {video: {}} - }, { - bidId: 'bidId3', - params: { mid: '1000' }, - mediaTypes: {video: {}} - }]; - const imps = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data).imp; - - for (let i = 0; i < 3; i++) { - assert.equal(imps[i].id, i + 1); - } - }); - - it('should add mid', function () { - const validBidRequests = [{ bidId: 'bidId', params: {mid: 1000}, mediaTypes: {video: {}} }, - { bidId: 'bidId2', params: {mid: 1001}, mediaTypes: {video: {}} }, - { bidId: 'bidId3', params: {mid: 1002}, mediaTypes: {video: {}} }]; - const imps = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data).imp; - for (let i = 0; i < 3; i++) { - assert.equal(imps[i].tagid, validBidRequests[i].params.mid); - } - }); - - it('should add imp.ext properties', function () { - const validBidRequests = [ - { bidId: 'bidId', params: { mid: 1000 }, mediaTypes: { video: {} }, ortb2Imp: { ext: { some: 'value' } } }, - { bidId: 'bidId2', params: { mid: 1001 }, mediaTypes: { video: {} }, ortb2Imp: { ext: { some: 'value', another: 1 } } }, - { bidId: 'bidId3', params: { mid: 1002 }, mediaTypes: { video: {} }, ortb2Imp: { ext: {} } } - ]; - const expectedExtensions = [ - { some: 'value', bidder: {} }, - { some: 'value', another: 1, bidder: {} }, - { bidder: {} }, - ] - const imps = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data).imp; - for (let i = 0; i < 3; i++) { - assert.deepEqual(imps[i].ext, expectedExtensions[i]); - } - }); - - describe('dynamic placement tag', function () { - it('should add imp parameters correctly', function () { - const validBidRequests = [ - { bidId: 'bidId', params: { inv: 1000, mname: 'placement' }, mediaTypes: {video: {}} }, - { bidId: 'bidId', params: { mid: 1234, inv: 1002, mname: 'placement2' }, mediaTypes: {video: {}} }, - { bidId: 'bidId', params: { mid: 1234 }, mediaTypes: {video: {}} } - ]; - const [ imp1, imp2, imp3 ] = getRequestImps(validBidRequests); - - assert.equal(imp1.ext.bidder.inv, 1000); - assert.equal(imp1.ext.bidder.mname, 'placement'); - assert.equal('tagid' in imp1, false); - - assert.equal(imp2.ext.bidder.inv, 1002); - assert.equal(imp2.ext.bidder.mname, 'placement2'); - assert.equal(imp2.tagid, 1234); - - assert.ok(imp3.ext.bidder); - assert.equal('inv' in imp3.ext.bidder, false); - assert.equal('mname' in imp3.ext.bidder, false); - assert.equal(imp3.tagid, 1234); - }); - }); - - describe('price floors', function () { - it('should not add if floors module not configured', function () { - const validBidRequests = [{ bidId: 'bidId', params: {mid: 1000}, mediaTypes: {video: {}} }]; - const imp = getRequestImps(validBidRequests)[0]; - - assert.equal(imp.bidfloor, undefined); - assert.equal(imp.bidfloorcur, undefined); - }); - - it('should not add if floor price not defined', function () { - const validBidRequests = [ getBidWithFloor() ]; - const imp = getRequestImps(validBidRequests)[0]; - - assert.equal(imp.bidfloor, undefined); - assert.equal(imp.bidfloorcur, 'USD'); - }); - - it('should request floor price in adserver currency', function () { - setCurrencyConfig({ adServerCurrency: 'DKK' }) - const validBidRequests = [ getBidWithFloor() ]; - return addFPDToBidderRequest(validBidRequests[0]).then(res => { - const imp = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' }, ...res }).data).imp[0]; - assert.equal(imp.bidfloor, undefined); - assert.equal(imp.bidfloorcur, 'DKK'); - setCurrencyConfig({}); - }); - }); - - it('should add correct floor values', function () { - const expectedFloors = [ 1, 1.3, 0.5 ]; - const validBidRequests = expectedFloors.map(getBidWithFloor); - const imps = getRequestImps(validBidRequests); - - expectedFloors.forEach((floor, index) => { - assert.equal(imps[index].bidfloor, floor); - assert.equal(imps[index].bidfloorcur, 'USD'); - }); - }); - - it('should add correct params to getFloor', function () { - let result; - let mediaTypes = { video: { - playerSize: [ 100, 200 ] - } }; - const expectedFloors = [ 1, 1.3, 0.5 ]; - setCurrencyConfig({ adServerCurrency: 'DKK' }); - const validBidRequests = expectedFloors.map(getBidWithFloorTest); - return addFPDToBidderRequest(validBidRequests[0]).then(res => { - getRequestImps(validBidRequests, res); - assert.deepEqual(result, { currency: 'DKK', size: '*', mediaType: '*' }) - mediaTypes = { banner: { - sizes: [ [100, 200], [300, 400] ] - }}; - getRequestImps(validBidRequests, res); - - assert.deepEqual(result, { currency: 'DKK', size: '*', mediaType: '*' }); - - mediaTypes = { native: {} }; - getRequestImps(validBidRequests, res); - - assert.deepEqual(result, { currency: 'DKK', size: '*', mediaType: '*' }); - - mediaTypes = {}; - getRequestImps(validBidRequests, res); - - assert.deepEqual(result, { currency: 'DKK', size: '*', mediaType: '*' }); - setCurrencyConfig({}); - }); - - function getBidWithFloorTest(floor) { - return { - params: { mid: 1 }, - mediaTypes: mediaTypes, - getFloor: (args) => { - result = args; - return { - currency: 'DKK', - floor - }; - } - }; - } - }); - - function getBidWithFloor(floor) { - return { - params: { mid: 1 }, - mediaTypes: { video: {} }, - getFloor: ({ currency }) => { - return { - currency: currency, - floor - }; - } - }; - } - }); - - describe('multiple media types', function () { - it('should use all configured media types for bidding', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { mid: 1000 }, - mediaTypes: { - banner: { - sizes: [[100, 100], [200, 300]] - }, - video: {} - } - }, { - bidId: 'bidId1', - params: { mid: 1000 }, - mediaTypes: { - video: {}, - native: {} - } - }, { - bidId: 'bidId2', - params: { mid: 1000 }, - nativeParams: { - title: { required: true, len: 140 } - }, - nativeOrtbRequest: { - assets: [ - { - required: 1, - id: 0, - title: { - len: 140 - } - } - ] - }, - mediaTypes: { - banner: { - sizes: [[100, 100], [200, 300]] - }, - native: {}, - video: {} - } - }]; - const [ first, second, third ] = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data).imp; - - assert.ok(first.banner); - assert.ok(first.video); - assert.equal(first.native, undefined); - - assert.ok(second.video); - assert.equal(second.banner, undefined); - assert.equal(second.native, undefined); - - assert.ok(third.native); - assert.ok(third.video); - assert.ok(third.banner); - }); - }); - - describe('banner', function () { - it('should convert sizes to openrtb format', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { mid: 1000 }, - mediaTypes: { - banner: { - sizes: [[100, 100], [200, 300]] - } - } - }]; - const { banner } = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data).imp[0]; - assert.deepEqual(banner, { - format: [ { w: 100, h: 100 }, { w: 200, h: 300 } ] - }); - }); - }); - - describe('video', function () { - it('should pass video mediatype config', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { mid: 1000 }, - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'outstream', - mimes: ['video/mp4'] - } - } - }]; - const { video } = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data).imp[0]; - assert.deepEqual(video, { - playerSize: [640, 480], - context: 'outstream', - mimes: ['video/mp4'] - }); - }); - }); - - describe('native', function () { - describe('assets', function () { - it('should use nativeOrtbRequest instead of nativeParams or mediaTypes', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { mid: 1000 }, - nativeParams: { - title: { required: true, len: 200 }, - image: { required: true, sizes: [150, 150] }, - icon: { required: false, sizes: [150, 150] }, - body: { required: false, len: 1140 }, - sponsoredBy: { required: true }, - cta: { required: false }, - clickUrl: { required: false }, - ortb: { - ver: '1.2', - assets: [] - } - }, - mediaTypes: { - native: { - title: { required: true, len: 140 }, - image: { required: true, sizes: [150, 50] }, - icon: { required: false, sizes: [50, 50] }, - body: { required: false, len: 140 }, - sponsoredBy: { required: true }, - cta: { required: false }, - clickUrl: { required: false } - } - }, - nativeOrtbRequest: { - assets: [ - { required: 1, title: { len: 200 } }, - { required: 1, img: { type: 3, w: 170, h: 70 } }, - { required: 0, img: { type: 1, w: 70, h: 70 } }, - { required: 0, data: { type: 2, len: 150 } }, - { required: 1, data: { type: 1 } }, - { required: 0, data: { type: 12 } }, - ] - } - }]; - - const assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data).imp[0].native.request.assets; - assert.ok(assets[0].title); - assert.equal(assets[0].title.len, 200); - assert.deepEqual(assets[1].img, { type: 3, w: 170, h: 70 }); - assert.deepEqual(assets[2].img, { type: 1, w: 70, h: 70 }); - assert.deepEqual(assets[3].data, { type: 2, len: 150 }); - assert.deepEqual(assets[4].data, { type: 1 }); - assert.deepEqual(assets[5].data, { type: 12 }); - assert.ok(!assets[6]); - }); - - it('should set correct asset id', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { mid: 1000 }, - nativeParams: { - title: { required: true, len: 140 }, - image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, - body: { len: 140 } - }, - nativeOrtbRequest: { - assets: [ - { - id: 0, - required: 1, - title: { - len: 140 - } - }, - { - id: 1, - required: 0, - img: { - type: 3, - wmin: 836, - hmin: 627, - w: 325, - h: 300, - mimes: [ 'image/jpg', 'image/gif' ] - } - }, - { - id: 2, - data: { - type: 2, - len: 140 - } - } - ] - } - }]; - - const assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data).imp[0].native.request.assets; - - assert.equal(assets[0].id, 0); - assert.equal(assets[1].id, 1); - assert.equal(assets[2].id, 2); - }); - - it('should add required key if it is necessary', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { mid: 1000 }, - nativeParams: { - title: { required: true, len: 140 }, - image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, - body: { len: 140 }, - sponsoredBy: { required: true, len: 140 } - }, - nativeOrtbRequest: { - assets: [ - { required: 1, title: { len: 140 } }, - { required: 0, img: { type: 3, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] } }, - { data: { type: 2, len: 140 } }, - { required: 1, data: { type: 1, len: 140 } } - ] - } - }]; - const assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data).imp[0].native.request.assets; - - assert.equal(assets[0].required, 1); - assert.ok(!assets[1].required); - assert.ok(!assets[2].required); - assert.equal(assets[3].required, 1); - }); - - it('should map img and data assets', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { mid: 1000 }, - nativeParams: { - title: { required: true, len: 140 }, - image: { required: true, sizes: [150, 50] }, - icon: { required: false, sizes: [50, 50] }, - body: { required: false, len: 140 }, - sponsoredBy: { required: true }, - cta: { required: false } - }, - nativeOrtbRequest: { - assets: [ - { required: 1, title: { len: 140 } }, - { required: 1, img: { type: 3, w: 150, h: 50 } }, - { required: 0, img: { type: 1, w: 50, h: 50 } }, - { required: 0, data: { type: 2, len: 140 } }, - { required: 1, data: { type: 1 } }, - { required: 0, data: { type: 12 } }, - ] - } - }]; - - const assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data).imp[0].native.request.assets; - assert.ok(assets[0].title); - assert.equal(assets[0].title.len, 140); - assert.deepEqual(assets[1].img, { type: 3, w: 150, h: 50 }); - assert.deepEqual(assets[2].img, { type: 1, w: 50, h: 50 }); - assert.deepEqual(assets[3].data, { type: 2, len: 140 }); - assert.deepEqual(assets[4].data, { type: 1 }); - assert.deepEqual(assets[5].data, { type: 12 }); - assert.ok(!assets[6]); - }); - - it('should utilise aspect_ratios', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { mid: 1000 }, - nativeParams: { - image: { - aspect_ratios: [{ - min_width: 100, - ratio_height: 3, - ratio_width: 1 - }] - }, - icon: { - aspect_ratios: [{ - min_width: 10, - ratio_height: 5, - ratio_width: 2 - }] - } - }, - nativeOrtbRequest: { - assets: [ - { img: { type: 3, wmin: 100, ext: { aspectratios: ['1:3'] } } }, - { img: { type: 1, wmin: 10, ext: { aspectratios: ['2:5'] } } } - ] - } - }]; - - const assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data).imp[0].native.request.assets; - assert.ok(assets[0].img); - assert.equal(assets[0].img.wmin, 100); - assert.equal(assets[0].img.hmin, 300); - - assert.ok(assets[1].img); - assert.equal(assets[1].img.wmin, 10); - assert.equal(assets[1].img.hmin, 25); - }); - - it('should not throw error if aspect_ratios config is not defined', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { mid: 1000 }, - nativeParams: { - image: { - aspect_ratios: [] - }, - icon: { - aspect_ratios: [] - } - }, - nativeOrtbRequest: { - request: { - assets: [ - { img: {} }, - { img: {} } - ] - } - } - }]; - - assert.doesNotThrow(() => spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } })); - }); - }); - - it('should expect any dimensions if min_width not passed', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: { mid: 1000 }, - nativeParams: { - image: { - aspect_ratios: [{ - ratio_height: 3, - ratio_width: 1 - }] - } - }, - nativeOrtbRequest: { - assets: [ - { img: { type: 3, ext: { aspectratios: ['3:1'] } } } - ] - } - }]; - - const assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }).data).imp[0].native.request.assets; - assert.ok(assets[0].img); - assert.ok(!assets[0].img.wmin); - assert.ok(!assets[0].img.hmin); - assert.ok(!assets[1]); - }); - }); - }); - - function getRequestImps(validBidRequests, enriched = {}) { - return JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' }, ...enriched }).data).imp; - } - }); - - describe('interpretResponse', function () { - it('should return if no body in response', function () { - const serverResponse = {}; - const bidRequest = {}; - - assert.ok(!spec.interpretResponse(serverResponse, bidRequest)); - }); - it('should return more than one bids', function () { - const serverResponse = { - body: { - seatbid: [{ - bid: [{impid: '1', native: {ver: '1.1', link: { url: 'link' }, assets: [{id: 0, title: {text: 'Asset title text'}}]}}] - }, { - bid: [{impid: '2', native: {ver: '1.1', link: { url: 'link' }, assets: [{id: 1, data: {value: 'Asset title text'}}]}}] - }] - } - }; - const bidRequest = { - data: {}, - bids: [ - { - bidId: 'bidId1', - params: { mid: 1000 }, - nativeOrtbRequest: { - assets: [ - { id: 0, required: 1, title: { len: 140 } }, - { id: 1, required: 0, img: { type: 3, wmin: 836, hmin: 627, ext: { aspectratios: ['6:5'] } } }, - { id: 2, required: 0, data: { type: 2 } } - ] - } - }, - { - bidId: 'bidId2', - params: { mid: 1000 }, - nativeOrtbRequest: { - assets: [ - { id: 0, required: 1, title: { len: 140 } }, - { id: 1, required: 0, img: { type: 3, wmin: 836, hmin: 627, ext: { aspectratios: ['6:5'] } } }, - { id: 2, required: 0, data: { type: 2 } } - ] - } - } - ] - }; - - bids = spec.interpretResponse(serverResponse, bidRequest); - assert.equal(spec.interpretResponse(serverResponse, bidRequest).length, 2); - }); - - it('should parse seatbids', function () { - const serverResponse = { - body: { - seatbid: [{ - bid: [ - {impid: '1', native: {ver: '1.1', link: { url: 'link1' }, assets: [{id: 0, title: {text: 'Asset title text'}}]}}, - {impid: '4', native: {ver: '1.1', link: { url: 'link4' }, assets: [{id: 1, title: {text: 'Asset title text'}}]}} - ] - }, { - bid: [{impid: '2', native: {ver: '1.1', link: { url: 'link2' }, assets: [{id: 0, data: {value: 'Asset title text'}}]}}] - }] - } - }; - const bidRequest = { - data: {}, - bids: [ - { - bidId: 'bidId1', - params: { mid: 1000 }, - nativeOrtbRequest: { - assets: [ - { id: 0, required: 1, title: { len: 140 } }, - { id: 1, required: 0, img: { type: 3, wmin: 836, hmin: 627, ext: { aspectratios: ['6:5'] } } }, - { id: 2, required: 0, data: { type: 2 } } - ] - } - }, - { - bidId: 'bidId2', - params: { mid: 1000 }, - nativeOrtbRequest: { - assets: [ - { id: 0, required: 1, title: { len: 140 } }, - { id: 1, required: 0, img: { type: 3, wmin: 836, hmin: 627, ext: { aspectratios: ['6:5'] } } }, - { id: 2, required: 0, data: { type: 2 } } - ] - } - }, - { - bidId: 'bidId3', - params: { mid: 1000 }, - nativeOrtbRequest: { - assets: [ - { id: 0, required: 1, title: { len: 140 } }, - { id: 1, required: 0, img: { type: 3, wmin: 836, hmin: 627, ext: { aspectratios: ['6:5'] } } }, - { id: 2, required: 0, data: { type: 2 } } - ] - } - }, - { - bidId: 'bidId4', - params: { mid: 1000 }, - nativeOrtbRequest: { - assets: [ - { id: 0, required: 1, title: { len: 140 } }, - { id: 1, required: 0, img: { type: 3, wmin: 836, hmin: 627, ext: { aspectratios: ['6:5'] } } }, - { id: 2, required: 0, data: { type: 2 } } - ] - } - } - ] - }; - - bids = spec.interpretResponse(serverResponse, bidRequest).map(bid => { - const { requestId, native: { ortb: { link: { url } } } } = bid; - return [ requestId, url ]; - }); - - assert.equal(bids.length, 3); - assert.deepEqual(bids, [[ 'bidId1', 'link1' ], [ 'bidId2', 'link2' ], [ 'bidId4', 'link4' ]]); - }); - - it('should set correct values to bid', function () { - const serverResponse = { - body: { - id: null, - bidid: null, - seatbid: [{ - bid: [ - { - impid: '1', - price: 93.1231, - crid: '12312312', - native: { - assets: [], - link: { url: 'link' }, - imptrackers: ['imptrackers url1', 'imptrackers url2'] - }, - dealid: 'deal-id', - adomain: [ 'demo.com' ], - ext: { - prebid: { - type: 'native', - }, - dsa: { - behalf: 'some-behalf', - paid: 'some-paid', - transparency: [{ - domain: 'test.com', - dsaparams: [1, 2, 3] - }], - adrender: 1 - } - }, - cat: [ 'IAB1', 'IAB2' ] - } - ] - }], - cur: 'NOK' - } - }; - const bidRequest = { - data: {}, - bids: [ - { - bidId: 'bidId1', - params: { mid: 1000 }, - nativeOrtbRequest: { - assets: [ - { - id: 0, - required: 1, - title: { - len: 140 - } - }, { - id: 1, - required: 1, - img: { - type: 3, - wmin: 836, - hmin: 627, - ext: { - aspectratios: ['6:5'] - } - } - }, { - id: 2, - required: 0, - data: { - type: 2 - } - } - ] - }, - nativeParams: { - title: { required: true, len: 140 }, - image: { required: false, wmin: 836, hmin: 627, w: 325, h: 300, mimes: ['image/jpg', 'image/gif'] }, - body: { len: 140 } - } - } - ] - }; - - const bids = spec.interpretResponse(serverResponse, bidRequest); - const bid = serverResponse.body.seatbid[0].bid[0]; - assert.deepEqual(bids[0].requestId, bidRequest.bids[0].bidId); - assert.deepEqual(bids[0].cpm, bid.price); - assert.deepEqual(bids[0].creativeId, bid.crid); - assert.deepEqual(bids[0].ttl, 360); - assert.deepEqual(bids[0].netRevenue, false); - assert.deepEqual(bids[0].currency, serverResponse.body.cur); - assert.deepEqual(bids[0].mediaType, 'native'); - assert.deepEqual(bids[0].meta.mediaType, 'native'); - assert.deepEqual(bids[0].meta.primaryCatId, 'IAB1'); - assert.deepEqual(bids[0].meta.secondaryCatIds, [ 'IAB2' ]); - assert.deepEqual(bids[0].meta.advertiserDomains, [ 'demo.com' ]); - assert.deepEqual(bids[0].meta.dsa, { - behalf: 'some-behalf', - paid: 'some-paid', - transparency: [{ - domain: 'test.com', - dsaparams: [1, 2, 3] - }], - adrender: 1 - }); - assert.deepEqual(bids[0].dealId, 'deal-id'); - }); - it('should set correct native params', function () { - const bid = [ - { - impid: '1', - native: { - ver: '1.1', - assets: [{ - id: 1, - required: 0, - title: { - text: 'FLS Native' - } - }, { - id: 3, - required: 0, - data: { - value: 'Adform' - } - }, { - id: 2, - required: 0, - data: { - value: 'Native banner. WOW.' - } - }, { - id: 4, - required: 0, - data: { - value: 'Oho' - } - }, { - id: 5, - required: 0, - img: { url: 'test.url.com/Files/58345/308185.jpg?bv=1', w: 30, h: 10 } - }, { - id: 0, - required: 0, - img: { url: 'test.url.com/Files/58345/308200.jpg?bv=1', w: 300, h: 300 } - }], - link: { - url: 'clickUrl', clicktrackers: [ 'clickTracker1', 'clickTracker2' ] - }, - imptrackers: ['imptracker url1', 'imptracker url2'], - jstracker: 'jstracker' - } - } - ]; - const serverResponse = { - body: { - id: null, - bidid: null, - seatbid: [{ bid }], - cur: 'NOK' - } - }; - const bidRequest = { - data: {}, - bids: [{ - bidId: 'bidId1', - nativeOrtbRequest: { - ver: '1.2', - assets: [{ - id: 0, - required: 1, - img: { - type: 3, - wmin: 200, - hmin: 166, - ext: { - aspectratios: ['6:5'] - } - } - }, { - id: 1, - required: 1, - title: { - len: 150 - } - }, { - id: 2, - required: 0, - data: { - type: 2 - } - }, { - id: 3, - required: 1, - data: { - type: 1 - } - }, { - id: 4, - required: 1, - data: { - type: 12 - } - }, { - id: 5, - required: 0, - img: { - type: 1, - wmin: 10, - hmin: 10, - ext: { - aspectratios: ['1:1'] - } - } - }] - }, - }] - }; - - const result = spec.interpretResponse(serverResponse, bidRequest)[0].native; - const native = bid[0].native; - const assets = native.assets; - - assert.deepEqual(result, {ortb: native}); - }); - it('should return empty when there is no bids in response', function () { - const serverResponse = { - body: { - id: null, - bidid: null, - seatbid: [{ bid: [] }], - cur: 'NOK' - } - }; - const bidRequest = { - data: {}, - bids: [{ bidId: 'bidId1' }] - }; - const result = spec.interpretResponse(serverResponse, bidRequest)[0]; - assert.ok(!result); - }); - - describe('banner', function () { - it('should set ad content on response', function () { - const serverResponse = { - body: { - seatbid: [{ - bid: [{ impid: '1', adm: '', ext: { prebid: { type: 'banner' } } }] - }] - } - }; - const bidRequest = { - data: {}, - bids: [ - { - bidId: 'bidId1', - params: { mid: 1000 } - } - ] - }; - - bids = spec.interpretResponse(serverResponse, bidRequest); - assert.equal(bids.length, 1); - assert.equal(bids[0].ad, ''); - assert.equal(bids[0].mediaType, 'banner'); - assert.equal(bids[0].meta.mediaType, 'banner'); - }); - }); - - describe('video', function () { - it('should set vastXml on response', function () { - const serverResponse = { - body: { - seatbid: [{ - bid: [{ impid: '1', adm: '', ext: { prebid: { type: 'video' } } }] - }] - } - }; - const bidRequest = { - data: {}, - bids: [ - { - bidId: 'bidId1', - params: { mid: 1000 } - } - ] - }; - - bids = spec.interpretResponse(serverResponse, bidRequest); - assert.equal(bids.length, 1); - assert.equal(bids[0].vastXml, ''); - assert.equal(bids[0].mediaType, 'video'); - assert.equal(bids[0].meta.mediaType, 'video'); - }); - - it('should set vastUrl if nurl is present in response', function () { - const vastUrl = 'http://url.to/vast' - const serverResponse = { - body: { - seatbid: [{ - bid: [{ impid: '1', adm: '', nurl: vastUrl, ext: { prebid: { type: 'video' } } }] - }] - } - }; - const bidRequest = { - data: {}, - bids: [ - { - bidId: 'bidId1', - params: { mid: 1000 } - } - ] - }; - - bids = spec.interpretResponse(serverResponse, bidRequest); - assert.equal(bids.length, 1); - assert.equal(bids[0].vastUrl, vastUrl); - assert.equal(bids[0].mediaType, 'video'); - assert.equal(bids[0].meta.mediaType, 'video'); - }); - - it('should add renderer for outstream bids', function () { - const serverResponse = { - body: { - seatbid: [{ - bid: [{ impid: '1', adm: '', ext: { prebid: { type: 'video' } } }, { impid: '2', adm: '', ext: { prebid: { type: 'video' } } }] - }] - } - }; - const bidRequest = { - data: {}, - bids: [ - { - bidId: 'bidId1', - params: { mid: 1000 }, - mediaTypes: { - video: { - context: 'outstream' - } - } - }, - { - bidId: 'bidId2', - params: { mid: 1000 }, - mediaTypes: { - video: { - constext: 'instream' - } - } - } - ] - }; - - bids = spec.interpretResponse(serverResponse, bidRequest); - assert.ok(bids[0].renderer); - assert.equal(bids[1].renderer, undefined); - }); - }); - }); -}); diff --git a/test/spec/modules/adfusionBidAdapter_spec.js b/test/spec/modules/adfusionBidAdapter_spec.js deleted file mode 100644 index 951670a92..000000000 --- a/test/spec/modules/adfusionBidAdapter_spec.js +++ /dev/null @@ -1,130 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adfusionBidAdapter'; -import 'modules/priceFloors.js'; -import 'modules/currency.js'; -import { newBidder } from 'src/adapters/bidderFactory'; - -describe('adfusionBidAdapter', function () { - const adapter = newBidder(spec); - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - bidder: 'adfusion', - params: { - accountId: 1234, - }, - adUnitCode: '/adunit-code/test-path', - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - transactionId: 'test-transactionId-1', - }; - - it('should return true when required params are found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when params.accountID is missing', function () { - const localbid = Object.assign({}, bid); - delete localbid.params.accountId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - let bidRequests, bannerBidRequest, bidderRequest; - beforeEach(function () { - bidRequests = [ - { - bidder: 'adfusion', - params: { - accountId: 1234, - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - }, - }, - adUnitCode: '/adunit-code/test-path', - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - transactionId: 'test-transactionId-1', - }, - { - bidder: 'adfusion', - params: { - accountId: 1234, - }, - adUnitCode: 'adunit-code', - mediaTypes: { - video: { - playerSize: [640, 480], - }, - }, - bidId: 'test-bid-id-2', - bidderRequestId: 'test-bid-request-2', - auctionId: 'test-auction-2', - transactionId: 'test-transactionId-2', - }, - ]; - bannerBidRequest = { - bidder: 'adfusion', - params: { - accountId: 1234, - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - }, - }, - adUnitCode: '/adunit-code/test-path', - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - transactionId: 'test-transactionId-1', - }; - bidderRequest = { refererInfo: {} }; - }); - - it('should return an empty array when no bid requests', function () { - const bidRequest = spec.buildRequests([], bidderRequest); - expect(bidRequest).to.be.an('array'); - expect(bidRequest.length).to.equal(0); - }); - - it('should return a valid bid request object', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request).to.be.an('array'); - expect(request[0].data).to.be.an('object'); - expect(request[0].method).to.equal('POST'); - expect(request[0].currency).to.not.equal('USD'); - expect(request[0].url).to.not.equal(''); - expect(request[0].url).to.not.equal(undefined); - expect(request[0].url).to.not.equal(null); - }); - - it('should add bid floor', function () { - const bidRequest = Object.assign({}, bannerBidRequest); - let payload = spec.buildRequests([bidRequest], bidderRequest)[0].data; - expect(payload.imp[0].bidfloorcur).to.not.exist; - - const getFloorResponse = { currency: 'USD', floor: 3 }; - bidRequest.getFloor = () => getFloorResponse; - payload = spec.buildRequests([bidRequest], bidderRequest)[0].data; - expect(payload.imp[0].bidfloor).to.equal(3); - expect(payload.imp[0].bidfloorcur).to.equal('USD'); - }); - }); -}); diff --git a/test/spec/modules/adgenerationBidAdapter_spec.js b/test/spec/modules/adgenerationBidAdapter_spec.js deleted file mode 100644 index 8a542ba29..000000000 --- a/test/spec/modules/adgenerationBidAdapter_spec.js +++ /dev/null @@ -1,1421 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/adgenerationBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import {NATIVE} from 'src/mediaTypes.js'; -import prebid from 'package.json'; -import { setConfig as setCurrencyConfig } from '../../../modules/currency.js'; -import { addFPDToBidderRequest } from '../../helpers/fpd.js'; - -describe('AdgenerationAdapter', function () { - const adapter = newBidder(spec); - const ADGENE_PREBID_VERSION = '1.6.5'; - const ENDPOINT_STG = 'https://api-test.scaleout.jp/adgen/prebid'; - const ENDPOINT_RELEASE = 'https://d.socdm.com/adgen/prebid'; - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'adg', - 'params': { - id: '58278', // banner - } - }; - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const suaSample = { - source: 2, - platform: { - brand: 'macOS' - }, - browsers: [ - { - brand: 'Chromium', - version: ['112'] - }, - { - brand: 'Google Chrome', - version: ['112'] - }, - { - brand: 'Not:A-Brand', - version: ['99'] - } - ], - mobile: 0 - }; - const schainSmaple = {ver: '1.0', complete: 1, nodes: [{asi: 'indirectseller.com', sid: '00001', hp: 1}]}; - const bidRequests = [ - { // banner - bidder: 'adg', - params: { - id: '58278', - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [ - [ - 300, - 250 - ] - ] - } - }, - bidId: '2f6ac468a9c15e', - bidderRequestId: '14a9f773e30243', - auctionId: '4aae9f05-18c6-4fcd-80cf-282708cd584a', - transactionTd: 'f76f6dfd-d64f-4645-a29f-682bac7f431a' - }, - { // native - bidder: 'adg', - params: { - id: '58278', - }, - mediaTypes: { - native: { - image: { - required: true - }, - title: { - required: true, - len: 80 - }, - sponsoredBy: { - required: true - }, - clickUrl: { - required: true - }, - body: { - required: true - }, - icon: { - required: true - } - }, - }, - adUnitCode: 'adunit-code', - sizes: [[1, 1]], - bidId: '2f6ac468a9c15e', - bidderRequestId: '14a9f773e30243', - auctionId: '4aae9f05-18c6-4fcd-80cf-282708cd584a', - transactionTd: 'f76f6dfd-d64f-4645-a29f-682bac7f431a' - }, - { // bannerWithAdgextCriteoId - bidder: 'adg', - params: { - id: '58278', // banner - }, - adUnitCode: 'adunit-code', - sizes: [[320, 100]], - bidId: '2f6ac468a9c15e', - bidderRequestId: '14a9f773e30243', - auctionId: '4aae9f05-18c6-4fcd-80cf-282708cd584a', - transactionTd: 'f76f6dfd-d64f-4645-a29f-682bac7f431a', - userId: { - criteoId: 'criteo-id-test-1234567890' - } - }, - { // bannerWithAdgextIds - bidder: 'adg', - params: { - id: '58278', // banner - }, - adUnitCode: 'adunit-code', - sizes: [[320, 100]], - bidId: '2f6ac468a9c15e', - bidderRequestId: '14a9f773e30243', - auctionId: '4aae9f05-18c6-4fcd-80cf-282708cd584a', - transactionTd: 'f76f6dfd-d64f-4645-a29f-682bac7f431a', - userId: { - id5id: { - ext: { - linkType: 2 - }, - uid: 'id5-id-test-1234567890' - }, - imuid: 'i.KrAH6ZAZTJOnH5S4N2sogA', - uid2: {id: 'AgAAAAVacu1uAxgAxH+HJ8+nWlS2H4uVqr6i+HBDCNREHD8WKsio/x7D8xXFuq1cJycUU86yXfTH9Xe/4C8KkH+7UCiU7uQxhyD7Qxnv251pEs6K8oK+BPLYR+8BLY/sJKesa/koKwx1FHgUzIBum582tSy2Oo+7C6wYUaaV4QcLr/4LPA='}, - }, - ortb2Imp: {ext: {gpid: '/1111/homepage#300x250'}}, - ortb2: { - site: { - domain: 'localhost:9999', - publisher: {'domain': 'localhost:9999'}, - page: 'http://localhost:9999/integrationExamples/gpt/hello_world.html', - ref: 'http://localhost:9999/integrationExamples/gpt/hello_world.html' - }, - device: { - w: 570, - h: 969, - dnt: 0, - ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML,like Gecko)Chrome / 112.0.0.0Safari / 537.36', - language: 'ja', - sua: suaSample - } - }, - } - ]; - const bidderRequest = { - refererInfo: { - page: 'https://example.com' - } - }; - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - // check banner request - for (const req of request) { - const url = new URL(req.url); - expect(url.origin + url.pathname).to.equal(ENDPOINT_RELEASE); - } - }); - - it('sends bid request to debug ENDPOINT via POST', function () { - // change the first bidRequest to debug mode - const copyBidRequests = JSON.parse(JSON.stringify(bidRequests)); - for (const copyBid of copyBidRequests) { - copyBid.params.debug = true - } - // check banner request - const request = spec.buildRequests(copyBidRequests, bidderRequest); - for (const req of request) { - const url = new URL(req.url); - expect(url.origin + url.pathname).to.equal(ENDPOINT_STG); - } - }); - - it('should attache params to the banner request', function () { - const expectedMediaTypes = { - banner: { - sizes: [ - [ - 300, - 250 - ] - ] - } - } - const expectedBanner = { - topframe: 0, - format: [ - { - w: 300, - h: 250 - } - ] - } - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - // check banner request - const url = new URL(request.url); - expect(url.searchParams.get('posall')).equal('SSPLOC'); - expect(url.searchParams.get('id')).equal('58278'); - expect(url.searchParams.get('sdktype')).equal('0'); - expect(request.method).to.equal('POST'); - - // check request data - expect(request.data.currency).to.equal('JPY'); - expect(request.data.pbver).to.equal(prebid.version); - expect(request.data.sdkname).to.equal('prebidjs'); - expect(request.data.adapterver).to.equal(ADGENE_PREBID_VERSION); - expect(request.data.imark).to.equal(1); - expect(request.data.ortb.imp[0].id).to.equal('2f6ac468a9c15e'); - expect(request.data.ortb.imp[0].ext.params.id).to.equal('58278'); - expect(request.data.ortb.imp[0].ext.mediaTypes).to.deep.equal(expectedMediaTypes); - expect(request.data.ortb.imp[0].banner).to.deep.equal(expectedBanner); - }); - - it('should attache params to the native request', function () { - const expectedMediaTypes = { - native: { - image: { - required: true - }, - title: { - required: true, - len: 80 - }, - sponsoredBy: { - required: true - }, - clickUrl: { - required: true - }, - body: { - required: true - }, - icon: { - required: true - } - } - } - const request = spec.buildRequests(bidRequests, bidderRequest)[1]; - // check native request - const url = new URL(request.url); - expect(url.searchParams.get('posall')).equal('SSPLOC'); - expect(url.searchParams.get('id')).equal('58278'); - expect(url.searchParams.get('sdktype')).equal('0'); - expect(request.method).to.equal('POST'); - - // check request data - expect(request.data.currency).to.equal('JPY'); - expect(request.data.pbver).to.equal(prebid.version); - expect(request.data.sdkname).to.equal('prebidjs'); - expect(request.data.adapterver).to.equal(ADGENE_PREBID_VERSION); - expect(request.data.ortb.imp[0].id).to.equal('2f6ac468a9c15e'); - expect(request.data.ortb.imp[0].ext.params.id).to.equal('58278'); - expect(request.data.ortb.imp[0].ext.mediaTypes).to.deep.equal(expectedMediaTypes); - }); - - it('should attache params to the bannerWithAdgextCriteoId request', function () { - const criteoParams = { - user: { - ext: { - eids: [ - { - source: 'criteo.com', - uids: [ - { - id: 'xxxxxxx', - atype: 1 - } - ] - }, - ] - } - } - } - const request = spec.buildRequests(bidRequests, {...bidderRequest, ortb2: criteoParams})[0]; - expect(request.data.ortb.user).to.deep.equal(criteoParams.user); - }); - - it('should attache params to the bannerWithAdgextIds request', function () { - const idparams = { - user: { - ext: { - eids: [ - { - source: 'id5-sync.com', - uids: [ - { - id: 'ID5*RCKp3flI7Jutz2TKfExBb6T2kY8KC6xJ5FAXIVuKo2_SDBBFN9x3KQf-FMHXA3Sv', - atype: 1, - ext: { - linkType: 1, - pba: 'L+L6bQ6WoA2INCSS31vtiawRuBYQQ5H6OioCAXUNkl8=', - abTestingControlGroup: false - } - } - ] - }, - { - source: 'intimatemerger.com', - uids: [ - { - id: 'h.c2bef39c502aef97', - atype: 1 - } - ] - }, - { - source: 'ppid.intimatemerger.com', - uids: [ - { - id: 'f11490d3c7903e7455ac4af887280a3f', - atype: 1 - } - ] - }, - ] - } - }, - device: { - sua: suaSample - }, - source: { - ext: { - schain: schainSmaple - } - }, - } - const request = spec.buildRequests(bidRequests, {...bidderRequest, ortb2: idparams})[3]; - expect(request.data.ortb.user).to.deep.equal(idparams.user); - - // gpid - expect(request.data.ortb.imp[0].ext.gpid).to.equal('/1111/homepage#300x250'); - // sua - expect(request.data.ortb.device.sua).to.deep.equal(suaSample); - // schain - expect(request.data.ortb.source.ext.schain).to.deep.equal(schainSmaple); - }); - - it('allows setConfig to set bidder currency for JPY', function () { - setCurrencyConfig({ adServerCurrency: 'JPY' }); - return addFPDToBidderRequest(bidderRequest).then(res => { - const bidRequest = spec.buildRequests(bidRequests, res)[0]; - expect(bidRequest.data.currency).to.equal('JPY'); - setCurrencyConfig({}); - }); - }); - - it('allows setConfig to set bidder currency for USD', function () { - setCurrencyConfig({ adServerCurrency: 'USD' }); - return addFPDToBidderRequest(bidderRequest).then(res => { - const bidRequest = spec.buildRequests(bidRequests, res)[0]; - expect(bidRequest.data.currency).to.equal('USD'); - setCurrencyConfig({}); - }); - }); - }); - - describe('interpretResponse', function () { - const bidRequests = { - banner: { - bidderRequest: { - ortb2: {ext: {prebid: {adServerCurrency: 'JPY'}}} - }, - method: 'POST', - url: 'https://api-test.scaleout.jp/adgen/prebid?id=15415&posall=SSPLOC&sdktype=0', - data: { - currency: 'JPY', - pbver: prebid.version, - sdkname: 'prebidjs', - adapterver: ADGENE_PREBID_VERSION, - ortb: { - imp: [ - { - ext: { - gpid: '/1111/homepage-leftnav', - data: { - pbadslot: '/1111/homepage-leftnav' - }, - params: { - id: '15415', - debug: true - }, - mediaTypes: { - banner: { - sizes: [ - [ - 1, - 1 - ], - [ - 320, - 180 - ], - [ - 320, - 100 - ], - [ - 320, - 50 - ], - [ - 300, - 250 - ], - [ - 970, - 250 - ] - ] - } - } - }, - id: '2f6ac468a9c15e', - banner: { - topframe: 1, - format: [ - { - 'w': 1, - 'h': 1 - }, - { - 'w': 320, - 'h': 180 - }, - { - 'w': 320, - 'h': 100 - }, - { - 'w': 320, - 'h': 50 - }, - { - 'w': 300, - 'h': 250 - }, - { - 'w': 970, - 'h': 250 - } - ] - } - } - ], - source: {}, - '': { - ext: { - 'data': { - 'CxSegments': [ - 'xxxxxxx', - ] - }, - eids: [ - { - 'source': 'criteo.com', - 'uids': [ - { - 'id': 'xxxxxxxx', - 'atype': 1 - } - ] - }, - { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': 'xxxxxx', - 'atype': 1, - 'ext': { - 'linkType': 1, - 'pba': 'xxxxxx', - 'abTestingControlGroup': false - } - } - ] - }, - { - 'source': 'intimatemerger.com', - 'uids': [ - { - 'id': 'xxxx', - 'atype': 1 - } - ] - }, - { - 'source': 'ppid.intimatemerger.com', - 'uids': [ - { - 'id': 'xxxxxxx', - 'atype': 1 - } - ] - } - ] - } - }, - 'site': { - 'domain': 'example.com', - 'publisher': { - 'domain': 'example.com' - }, - 'page': 'https://example.com/post/html/fi/test2.html?pbjs_debug=true' - }, - 'device': { - 'w': 1792, - 'h': 1120, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36', - 'language': 'ja', - 'ext': { - 'vpw': 616, - 'vph': 974 - }, - 'sua': { - 'source': 1, - 'platform': { - 'brand': 'macOS' - }, - 'browsers': [ - { - 'brand': 'Google Chrome', - 'version': [ - '129' - ] - }, - { - 'brand': 'Not=A?Brand', - 'version': [ - '8' - ] - }, - { - 'brand': 'Chromium', - 'version': [ - '129' - ] - } - ], - 'mobile': 0 - } - }, - 'id': 'f149e3b5-46af-414c-a93a-4bbca5503112', - 'test': 0, - 'tmax': 3000 - }, - 'imark': 1 - }, - 'options': { - 'withCredentials': true, - 'crossOrigin': true - } - }, - native: { - method: 'POST', - url: 'https://api-test.scaleout.jp/adgen/prebid?id=10697&posall=SSPLOC&sdktype=0', - data: { - 'currency': 'JPY', - 'pbver': prebid.version, - 'sdkname': 'prebidjs', - 'adapterver': ADGENE_PREBID_VERSION, - 'ortb': { - 'imp': [ - { - 'ext': { - 'gpid': '/1111/homepage-leftnav', - 'data': { - 'pbadslot': '/1111/homepage-leftnav' - }, - 'params': { - 'id': '10697', - 'debug': true - }, - 'mediaTypes': { - 'native': { - 'image': { - 'required': true - }, - 'title': { - 'required': true, - 'len': 80 - }, - 'sponsoredBy': { - 'required': true - }, - 'clickUrl': { - 'required': true - }, - 'body': { - 'required': true - }, - 'icon': { - 'required': true - }, - 'privacyLink': { - 'required': true, - 'sendId': false - } - } - } - }, - 'id': '2f6ac468a9c15e', - 'native': { - 'request': '{\'ver\':\'1.2\',\'assets\':[{\'id\':0,\'required\':1,\'img\':{\'type\':3}},{\'id\':1,\'required\':1,\'title\':{\'len\':80}},{\'id\':2,\'required\':1,\'data\':{\'type\':1}},{\'id\':3,\'required\':1,\'data\':{\'type\':2}},{\'id\':4,\'required\':1,\'img\':{\'type\':1}}],\'privacy\':1}', - 'ver': '1.2' - } - } - ], - 'source': {}, - 'user': { - 'ext': { - 'data': { - 'CxSegments': [ - 'xxxxxxxx', - 'xxxxxxxy', - ] - }, - 'eids': [ - { - 'source': 'criteo.com', - 'uids': [ - { - 'id': 'xxxxxx', - 'atype': 1 - } - ] - }, - { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': 'xxxxxx', - 'atype': 1, - 'ext': { - 'linkType': 1, - 'pba': 'xxxxxx', - 'abTestingControlGroup': false - } - } - ] - }, - { - 'source': 'intimatemerger.com', - 'uids': [ - { - 'id': 'xxxxxx', - 'atype': 1 - } - ] - }, - { - 'source': 'ppid.intimatemerger.com', - 'uids': [ - { - 'id': 'xxxxxx', - 'atype': 1 - } - ] - } - ] - } - }, - 'site': { - 'domain': 'example.com', - 'publisher': { - 'domain': 'example.com' - }, - 'page': 'https://example.com/post/html/test3.html?pbjs_debug=true' - }, - 'device': { - 'w': 1792, - 'h': 1120, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36', - 'language': 'ja', - 'ext': { - 'vpw': 616, - 'vph': 974 - }, - 'sua': { - 'source': 1, - 'platform': { - 'brand': 'macOS' - }, - 'browsers': [ - { - 'brand': 'Google Chrome', - 'version': [ - '129' - ] - }, - { - 'brand': 'Not=A?Brand', - 'version': [ - '8' - ] - }, - { - 'brand': 'Chromium', - 'version': [ - '129' - ] - } - ], - 'mobile': 0 - } - }, - 'id': '8fa21cb7-d874-41e9-a735-9edf560b306c', - 'test': 0, - 'tmax': 20000 - } - }, - options: { - withCredentials: true, - crossOrigin: true - } - }, - upperBillboard: { - method: 'POST', - url: 'https://api-test.scaleout.jp/adgen/prebid?id=15410&posall=SSPLOC&sdktype=0', - data: { - 'currency': 'USD', - 'pbver': prebid.version, - 'sdkname': 'prebidjs', - 'adapterver': ADGENE_PREBID_VERSION, - 'ortb': { - 'imp': [ - { - 'ext': { - 'params': { - 'id': '15410', - 'debug': true, - 'marginTop': '50' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 1, - 1 - ], - [ - 320, - 180 - ], - [ - 320, - 100 - ], - [ - 320, - 50 - ], - [ - 300, - 250 - ], - [ - 970, - 250 - ] - ] - } - } - }, - 'id': '2f6ac468a9c15e', - 'banner': { - 'topframe': 1, - 'format': [ - { - 'w': 1, - 'h': 1 - }, - { - 'w': 320, - 'h': 180 - }, - { - 'w': 320, - 'h': 100 - }, - { - 'w': 320, - 'h': 50 - }, - { - 'w': 300, - 'h': 250 - }, - { - 'w': 970, - 'h': 250 - } - ] - } - } - ], - 'source': {}, - 'user': { - 'ext': { - 'data': { - 'CxSegments': [ - 'xxxxxxxx', - 'xxxxxxxy', - ] - }, - 'eids': [ - { - 'source': 'criteo.com', - 'uids': [ - { - 'id': 'xxxxxx', - 'atype': 1 - } - ] - }, - { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': 'xxxxxx', - 'atype': 1, - 'ext': { - 'linkType': 1, - 'pba': 'xxxxxx', - 'abTestingControlGroup': false - } - } - ] - }, - { - 'source': 'intimatemerger.com', - 'uids': [ - { - 'id': 'xxxxxx', - 'atype': 1 - } - ] - }, - { - 'source': 'ppid.intimatemerger.com', - 'uids': [ - { - 'id': 'xxxxxx', - 'atype': 1 - } - ] - } - ] - } - }, - 'site': { - 'domain': 'example.com', - 'publisher': { - 'domain': 'example.com' - }, - 'page': 'https://example.com/post/html/fi/test1.html?pbjs_debug=true' - }, - 'device': { - 'w': 1792, - 'h': 1120, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36', - 'language': 'ja', - 'ext': { - 'vpw': 616, - 'vph': 974 - }, - 'sua': { - 'source': 1, - 'platform': { - 'brand': 'macOS' - }, - 'browsers': [ - { - 'brand': 'Google Chrome', - 'version': [ - '129' - ] - }, - { - 'brand': 'Not=A?Brand', - 'version': [ - '8' - ] - }, - { - 'brand': 'Chromium', - 'version': [ - '129' - ] - } - ], - 'mobile': 0 - } - }, - 'id': '24cb6de9-68ee-49df-8a90-27259215e059', - 'test': 0, - 'tmax': 3000 - }, - 'imark': 1 - }, - } - }; - - const serverResponse = { - noAd: { - results: [], - }, - normal: { - banner: { - displaytype: '1', - location_params: null, - results: [ - { - ad: '
', - beacon: '', - cpm: 36.0008, - ids: {}, - w: 320, - h: 100, - locationid: '58279', - rotation: '0', - scheduleid: '512603', - sdktype: '0', - creativeid: '1k2kv35vsa5r', - dealid: 'fd5sa5fa7f', - ttl: 1000, - adomain: ['advertiserdomain.com'] - }, - ], - }, - native: { - displaytype: '1', - location_params: null, - locationid: '58279', - results: [ - { - ad: '
', - beacon: '', - cpm: 36.0008, - ids: {}, - adomain: ['advertiserdomain.com'], - scheduleid: '512603', - creativeid: '1k2kv35vsa5r', - dealid: 'fd5sa5fa7f', - ttl: 1000, - native: { - assets: [ - { - data: { - label: 'accompanying_text', - value: 'AD' - }, - id: 501 - }, - { - data: { - label: 'optout_url', - value: 'https://example.com/optout/#' - }, - id: 502 - }, - { - data: { - ext: { - black_back: 'https://example.com/icon_adg_optout_26x26_white.png', - }, - label: 'information_icon_url', - value: 'https://example.com/icon_adg_optout_26x26_gray.png', - id: 503 - } - }, - { - id: 1, - required: 1, - title: {text: 'Title'} - }, - { - id: 2, - img: { - h: 250, - url: 'https://example.com/adg-sample-ad/img/300x250.png', - w: 300 - }, - required: 1 - }, - { - id: 3, - img: { - h: 300, - url: 'https://example.com/300x300.png', - w: 300 - }, - required: 1 - }, - { - data: {value: 'Description'}, - id: 5, - required: 0 - }, - { - data: {value: 'CTA'}, - id: 6, - required: 0 - }, - { - data: {value: 'Sponsored'}, - id: 4, - required: 0 - } - ], - imptrackers: ['https://example.com/1x1.gif'], - link: { - clicktrackers: [ - 'https://example.com/1x1_clicktracker_access.gif' - ], - url: 'https://example.com' - }, - }, - } - ], - rotation: '0', - }, - upperBillboard: { - 'displaytype': '1', - 'h': 180, - 'ids': { - 'anid': '', - 'diid': '', - 'idfa': '', - 'soc': 'yyyyyyyy' - }, - 'location_params': { - 'option': { - 'ad_type': 'upper_billboard' - } - }, - 'locationid': '143038', - 'results': [ - { - 'ad': '
', - 'beacon': '', - 'beaconurl': 'http://example.com', - 'cpm': 80, - 'creative_params': {}, - 'creativeid': 'ScaleOut_2146187', - 'dealid': '2134-132864_newformat_test', - 'h': 180, - 'landing_url': 'https://example.com/', - 'rparams': {}, - 'scheduleid': '1233323', - 'trackers': { - 'imp': [ - 'https://example.com' - ], - 'viewable_imp': [ - 'https://example.com' - ], - 'viewable_measured': [ - 'https://example.com' - ] - }, - 'ttl': 1000, - 'vastxml': '', - 'vcpm': 0, - 'w': 320, - 'weight': 1 - } - ], - 'rotation': '0', - } - }, - } - serverResponse.emptyAdomain = {}; - serverResponse.emptyAdomain.banner = JSON.parse(JSON.stringify(serverResponse.normal.banner)); - serverResponse.emptyAdomain.banner.results[0].adomain = []; - serverResponse.emptyAdomain.native = JSON.parse(JSON.stringify(serverResponse.normal.native)); - serverResponse.emptyAdomain.native.results[0].adomain = []; - - serverResponse.noAdomain = {}; - serverResponse.noAdomain.banner = JSON.parse(JSON.stringify(serverResponse.normal.banner)); - delete serverResponse.noAdomain.banner.results[0].adomain; - serverResponse.noAdomain.native = JSON.parse(JSON.stringify(serverResponse.normal.native)); - delete serverResponse.noAdomain.native.results[0].adomain; - - const bidResponses = { - normal: { - banner: { - requestId: '2f6ac468a9c15e', - cpm: 36.0008, - width: 320, - height: 100, - creativeId: '1k2kv35vsa5r', - dealId: 'fd5sa5fa7f', - currency: 'JPY', - netRevenue: true, - ttl: 1000, - ad: '
', - adomain: ['advertiserdomain.com'] - }, - native: { - requestId: '2f6ac468a9c15e', - cpm: 36.0008, - width: 1, - height: 1, - creativeId: '1k2kv35vsa5r', - dealId: 'fd5sa5fa7f', - currency: 'JPY', - netRevenue: true, - ttl: 1000, - adomain: ['advertiserdomain.com'], - ad: '
', - native: { - title: 'Title', - image: { - url: 'https://example.com/adg-sample-ad/img/300x250.png', - height: 250, - width: 300 - }, - icon: { - url: 'https://example.com/300x300.png', - height: 300, - width: 300 - }, - sponsoredBy: 'Sponsored', - body: 'Description', - cta: 'CTA', - privacyLink: 'https://example.com/optout/#', - clickUrl: 'https://example.com', - clickTrackers: ['https://example.com/1x1_clicktracker_access.gif'], - impressionTrackers: ['https://example.com/1x1.gif'] - }, - mediaType: NATIVE - }, - upperBillboard: { - requestId: '2f6ac468a9c15e', - cpm: 80, - width: 320, - height: 180, - creativeId: 'ScaleOut_2146187', - dealId: '2134-132864_newformat_test', - currency: 'USD', - netRevenue: true, - ttl: 1000, - ad: ``, - adomain: ['advertiserdomain.com'] - }, - } - }; - - it('no bid responses', function () { - const result = spec.interpretResponse({body: serverResponse.noAd}, bidRequests.banner); - expect(result.length).to.equal(0); - }); - - it('handles ADGBrowserM responses', function () { - setCurrencyConfig({ adServerCurrency: 'USD' }); - const bidderRequest = { - refererInfo: { - page: 'https://example.com' - } - }; - return addFPDToBidderRequest(bidderRequest).then(res => { - const sr = {body: serverResponse.normal.upperBillboard}; - const br = { bidderRequest: res, ...bidRequests.upperBillboard }; - - const result = spec.interpretResponse(sr, br)[0]; - expect(result.requestId).to.equal(bidResponses.normal.upperBillboard.requestId); - expect(result.width).to.equal(bidResponses.normal.upperBillboard.width); - expect(result.height).to.equal(bidResponses.normal.upperBillboard.height); - expect(result.creativeId).to.equal(bidResponses.normal.upperBillboard.creativeId); - expect(result.dealId).to.equal(bidResponses.normal.upperBillboard.dealId); - expect(result.currency).to.equal(bidResponses.normal.upperBillboard.currency); - expect(result.netRevenue).to.equal(bidResponses.normal.upperBillboard.netRevenue); - expect(result.ttl).to.equal(bidResponses.normal.upperBillboard.ttl); - expect(result.ad).to.equal(bidResponses.normal.upperBillboard.ad); - setCurrencyConfig({}); - }); - }); - - it('handles banner responses for empty adomain', function () { - const result = spec.interpretResponse({body: serverResponse.emptyAdomain.banner}, bidRequests.banner)[0]; - expect(result.requestId).to.equal(bidResponses.normal.banner.requestId); - expect(result.width).to.equal(bidResponses.normal.banner.width); - expect(result.height).to.equal(bidResponses.normal.banner.height); - expect(result.creativeId).to.equal(bidResponses.normal.banner.creativeId); - expect(result.dealId).to.equal(bidResponses.normal.banner.dealId); - expect(result.currency).to.equal(bidResponses.normal.banner.currency); - expect(result.netRevenue).to.equal(bidResponses.normal.banner.netRevenue); - expect(result.ttl).to.equal(bidResponses.normal.banner.ttl); - expect(result.ad).to.equal(bidResponses.normal.banner.ad); - // no adomian - expect(result).to.not.have.any.keys('meta'); - expect(result).to.not.have.any.keys('advertiserDomains'); - }); - - it('handles native responses for empty adomain', function () { - const result = spec.interpretResponse({body: serverResponse.emptyAdomain.native}, bidRequests.native)[0]; - expect(result.requestId).to.equal(bidResponses.normal.native.requestId); - expect(result.width).to.equal(bidResponses.normal.native.width); - expect(result.height).to.equal(bidResponses.normal.native.height); - expect(result.creativeId).to.equal(bidResponses.normal.native.creativeId); - expect(result.dealId).to.equal(bidResponses.normal.native.dealId); - expect(result.currency).to.equal(bidResponses.normal.native.currency); - expect(result.netRevenue).to.equal(bidResponses.normal.native.netRevenue); - expect(result.ttl).to.equal(bidResponses.normal.native.ttl); - expect(result.native.title).to.equal(bidResponses.normal.native.native.title); - expect(result.native.image.url).to.equal(bidResponses.normal.native.native.image.url); - expect(result.native.image.height).to.equal(bidResponses.normal.native.native.image.height); - expect(result.native.image.width).to.equal(bidResponses.normal.native.native.image.width); - expect(result.native.icon.url).to.equal(bidResponses.normal.native.native.icon.url); - expect(result.native.icon.width).to.equal(bidResponses.normal.native.native.icon.width); - expect(result.native.icon.height).to.equal(bidResponses.normal.native.native.icon.height); - expect(result.native.sponsoredBy).to.equal(bidResponses.normal.native.native.sponsoredBy); - expect(result.native.body).to.equal(bidResponses.normal.native.native.body); - expect(result.native.cta).to.equal(bidResponses.normal.native.native.cta); - expect(decodeURIComponent(result.native.privacyLink)).to.equal(bidResponses.normal.native.native.privacyLink); - expect(result.native.clickUrl).to.equal(bidResponses.normal.native.native.clickUrl); - expect(result.native.impressionTrackers[0]).to.equal(bidResponses.normal.native.native.impressionTrackers[0]); - expect(result.native.clickTrackers[0]).to.equal(bidResponses.normal.native.native.clickTrackers[0]); - expect(result.mediaType).to.equal(bidResponses.normal.native.mediaType); - // no adomain - expect(result).to.not.have.any.keys('meta'); - expect(result).to.not.have.any.keys('advertiserDomains'); - }); - - it('handles banner responses for no adomain', function () { - const result = spec.interpretResponse({body: serverResponse.noAdomain.banner}, bidRequests.banner)[0]; - expect(result.requestId).to.equal(bidResponses.normal.banner.requestId); - expect(result.width).to.equal(bidResponses.normal.banner.width); - expect(result.height).to.equal(bidResponses.normal.banner.height); - expect(result.creativeId).to.equal(bidResponses.normal.banner.creativeId); - expect(result.dealId).to.equal(bidResponses.normal.banner.dealId); - expect(result.currency).to.equal(bidResponses.normal.banner.currency); - expect(result.netRevenue).to.equal(bidResponses.normal.banner.netRevenue); - expect(result.ttl).to.equal(bidResponses.normal.banner.ttl); - expect(result.ad).to.equal(bidResponses.normal.banner.ad); - // no adomain - expect(result).to.not.have.any.keys('meta'); - expect(result).to.not.have.any.keys('advertiserDomains'); - }); - - it('handles native responses for no adomain', function () { - const result = spec.interpretResponse({body: serverResponse.noAdomain.native}, bidRequests.native)[0]; - expect(result.requestId).to.equal(bidResponses.normal.native.requestId); - expect(result.width).to.equal(bidResponses.normal.native.width); - expect(result.height).to.equal(bidResponses.normal.native.height); - expect(result.creativeId).to.equal(bidResponses.normal.native.creativeId); - expect(result.dealId).to.equal(bidResponses.normal.native.dealId); - expect(result.currency).to.equal(bidResponses.normal.native.currency); - expect(result.netRevenue).to.equal(bidResponses.normal.native.netRevenue); - expect(result.ttl).to.equal(bidResponses.normal.native.ttl); - expect(result.native.title).to.equal(bidResponses.normal.native.native.title); - expect(result.native.image.url).to.equal(bidResponses.normal.native.native.image.url); - expect(result.native.image.height).to.equal(bidResponses.normal.native.native.image.height); - expect(result.native.image.width).to.equal(bidResponses.normal.native.native.image.width); - expect(result.native.icon.url).to.equal(bidResponses.normal.native.native.icon.url); - expect(result.native.icon.width).to.equal(bidResponses.normal.native.native.icon.width); - expect(result.native.icon.height).to.equal(bidResponses.normal.native.native.icon.height); - expect(result.native.sponsoredBy).to.equal(bidResponses.normal.native.native.sponsoredBy); - expect(result.native.body).to.equal(bidResponses.normal.native.native.body); - expect(result.native.cta).to.equal(bidResponses.normal.native.native.cta); - expect(decodeURIComponent(result.native.privacyLink)).to.equal(bidResponses.normal.native.native.privacyLink); - expect(result.native.clickUrl).to.equal(bidResponses.normal.native.native.clickUrl); - expect(result.native.impressionTrackers[0]).to.equal(bidResponses.normal.native.native.impressionTrackers[0]); - expect(result.native.clickTrackers[0]).to.equal(bidResponses.normal.native.native.clickTrackers[0]); - expect(result.mediaType).to.equal(bidResponses.normal.native.mediaType); - // no adomain - expect(result).to.not.have.any.keys('meta'); - expect(result).to.not.have.any.keys('advertiserDomains'); - }); - - describe('currency handling', function () { - const bidRequest = { - method: 'POST', - url: 'https://d.socdm.com/adgen/prebid', - data: { - currency: 'USD', - pbver: prebid.version, - sdkname: 'prebidjs', - adapterver: ADGENE_PREBID_VERSION, - ortb: { - imp: [{ - id: 'test-imp-id', - ext: { - params: { id: '58278' }, - mediaTypes: { banner: { sizes: [[300, 250]] } } - } - }] - } - } - }; - - it('uses currency from data when available', function () { - const serverResponse = { - body: { - results: [{ - cpm: 100, - w: 300, - h: 250, - creativeid: 'test-creative-id', - dealid: 'test-deal-id', - ad: '
Test Ad
' - }] - } - }; - - const result = spec.interpretResponse(serverResponse, bidRequest)[0]; - expect(result.currency).to.equal('USD'); - expect(result.cpm).to.equal(100); - }); - - it('defaults to JPY when no currency information available', function () { - const requestWithoutCurrency = { - method: 'POST', - url: 'https://d.socdm.com/adgen/prebid', - data: { - pbver: prebid.version, - sdkname: 'prebidjs', - adapterver: ADGENE_PREBID_VERSION, - ortb: { - imp: [{ - id: 'test-imp-id', - ext: { - params: { id: '58278' }, - mediaTypes: { banner: { sizes: [[300, 250]] } } - } - }] - } - } - }; - - const serverResponse = { - body: { - results: [{ - cpm: 300, - w: 300, - h: 250, - creativeid: 'test-creative-id', - dealid: 'test-deal-id', - ad: '
Test Ad
' - }] - } - }; - - const result = spec.interpretResponse(serverResponse, requestWithoutCurrency)[0]; - expect(result.currency).to.equal('JPY'); - }); - - it('handles currency correctly with getCurrencyType function logic', function () { - // Test the current implementation which uses bidRequests?.data?.currency || 'JPY' - const bidRequestWithJPY = { - method: 'POST', - url: 'https://d.socdm.com/adgen/prebid', - data: { - currency: 'JPY', - pbver: prebid.version, - sdkname: 'prebidjs', - adapterver: ADGENE_PREBID_VERSION, - ortb: { - imp: [{ - id: 'test-imp-id', - ext: { - params: { id: '58278' }, - mediaTypes: { banner: { sizes: [[300, 250]] } } - } - }] - } - } - }; - - const serverResponse = { - body: { - results: [{ - cpm: 150, - w: 300, - h: 250, - creativeid: 'test-creative-id', - dealid: 'test-deal-id', - ad: '
Test Ad
' - }] - } - }; - - const result = spec.interpretResponse(serverResponse, bidRequestWithJPY)[0]; - expect(result.currency).to.equal('JPY'); - }); - }); - }); -}); diff --git a/test/spec/modules/adgridBidAdapter_spec.js b/test/spec/modules/adgridBidAdapter_spec.js deleted file mode 100644 index 5b6d658e1..000000000 --- a/test/spec/modules/adgridBidAdapter_spec.js +++ /dev/null @@ -1,573 +0,0 @@ -import { expect } from 'chai'; -import { - spec, STORAGE, getLocalStorage, -} from 'modules/adgridBidAdapter.js'; -import sinon from 'sinon'; -import { getAmxId } from '../../../libraries/nexx360Utils/index.js'; -const sandbox = sinon.createSandbox(); - -describe('adgrid bid adapter tests', () => { - const DEFAULT_OPTIONS = { - gdprConsent: { - gdprApplies: true, - consentString: 'BOzZdA0OzZdA0AGABBENDJ-AAAAvh7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__79__3z3_9pxP78k89r7337Mw_v-_v-b7JCPN_Y3v-8Kg', - vendorData: {}, - }, - refererInfo: { - referer: 'https://www.prebid.org', - canonicalUrl: 'https://www.prebid.org/the/link/to/the/page', - }, - uspConsent: '111222333', - userId: { id5id: { uid: '1111' } }, - schain: { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'exchange1.com', - sid: '1234', - hp: 1, - rid: 'bid-request-1', - name: 'publisher', - domain: 'publisher.com', - }], - }, - }; - - describe('isBidRequestValid()', () => { - let bannerBid; - beforeEach(() => { - bannerBid = { - bidder: 'adgrid', - mediaTypes: { banner: { sizes: [[300, 250], [300, 600]] } }, - adUnitCode: 'div-1', - transactionId: '70bdc37e-9475-4b27-8c74-4634bdc2ee66', - sizes: [[300, 250], [300, 600]], - bidId: '4906582fc87d0c', - bidderRequestId: '332fda16002dbe', - auctionId: '98932591-c822-42e3-850e-4b3cf748d063', - } - }); - - it('We verify isBidRequestValid unvalid domainId', () => { - bannerBid.params = { domainid: 1 }; - expect(spec.isBidRequestValid(bannerBid)).to.be.equal(false); - }); - - it('We verify isBidRequestValid with uncorrect domainId', () => { - bannerBid.params = { domainId: '1234', placement: 'testadgd' }; - expect(spec.isBidRequestValid(bannerBid)).to.be.equal(false); - }); - - it('We verify isBidRequestValid with uncorrect placement', () => { - bannerBid.params = { domainId: 1234, placement: 4321 }; - expect(spec.isBidRequestValid(bannerBid)).to.be.equal(false); - }); - - it('We verify isBidRequestValid with correct payload', () => { - bannerBid.params = { domainId: 1234, placement: '4321' }; - expect(spec.isBidRequestValid(bannerBid)).to.be.equal(true); - }); - }); - - describe('getLocalStorage disabled', () => { - before(() => { - sandbox.stub(STORAGE, 'localStorageIsEnabled').callsFake(() => false); - }); - it('We test if we get the adgridId', () => { - const output = getLocalStorage(); - expect(output).to.be.eql(false); - }); - after(() => { - sandbox.restore() - }); - }) - - describe('getLocalStorage enabled but nothing', () => { - before(() => { - sandbox.stub(STORAGE, 'localStorageIsEnabled').callsFake(() => true); - sandbox.stub(STORAGE, 'setDataInLocalStorage'); - sandbox.stub(STORAGE, 'getDataFromLocalStorage').callsFake((key) => null); - }); - it('We test if we get the adgridId', () => { - const output = getLocalStorage(); - expect(typeof output.adgridId).to.be.eql('string'); - }); - after(() => { - sandbox.restore() - }); - }) - - describe('getLocalStorage enabled but wrong payload', () => { - before(() => { - sandbox.stub(STORAGE, 'localStorageIsEnabled').callsFake(() => true); - sandbox.stub(STORAGE, 'setDataInLocalStorage'); - sandbox.stub(STORAGE, 'getDataFromLocalStorage').callsFake((key) => '{"adgridId":"5ad89a6e-7801-48e7-97bb-fe6f251f6cb4",}'); - }); - it('We test if we get the adgridId', () => { - const output = getLocalStorage(); - expect(output).to.be.eql(false); - }); - after(() => { - sandbox.restore() - }); - }); - - describe('getLocalStorage enabled', () => { - before(() => { - sandbox.stub(STORAGE, 'localStorageIsEnabled').callsFake(() => true); - sandbox.stub(STORAGE, 'setDataInLocalStorage'); - sandbox.stub(STORAGE, 'getDataFromLocalStorage').callsFake((key) => '{"adgridId":"5ad89a6e-7801-48e7-97bb-fe6f251f6cb4"}'); - }); - it('We test if we get the adgridId', () => { - const output = getLocalStorage(); - expect(output.adgridId).to.be.eql('5ad89a6e-7801-48e7-97bb-fe6f251f6cb4'); - }); - after(() => { - sandbox.restore() - }); - }); - - describe('buildRequests()', () => { - before(() => { - const documentStub = sandbox.stub(document, 'getElementById'); - documentStub.withArgs('div-1').returns({ - offsetWidth: 200, - offsetHeight: 250, - style: { - maxWidth: '400px', - maxHeight: '350px', - } - }); - }); - describe('We test with a multiple display bids', () => { - const sampleBids = [ - { - bidder: 'adgrid', - params: { - placement: 'testadgd', - domainId: 1234, - }, - ortb2Imp: { - ext: { - gpid: '/12345/Header-Ad', - } - }, - adUnitCode: 'header-ad-1234', - transactionId: '469a570d-f187-488d-b1cb-48c1a2009be9', - sizes: [[300, 250], [300, 600]], - bidId: '44a2706ac3574', - bidderRequestId: '359bf8a3c06b2e', - auctionId: '2e684815-b44e-4e04-b812-56da54adbe74', - userIdAsEids: [ - { - source: 'id5-sync.com', - uids: [ - { - id: 'ID5*xe3R0Pbrc5Y4WBrb5UZSWTiS1t9DU2LgQrhdZOgFdXMoglhqmjs_SfBbyHfSYGZKKIT4Gf-XOQ_anA3iqi0hJSiFyD3aICGHDJFxNS8LO84ohwTQ0EiwOexZAbBlH0chKIhbvdGBfuouNuVF_YHCoyiLQJDp3WQiH96lE9MH2T0ojRqoyR623gxAWlBCBPh7KI4bYtZlet3Vtr-gH5_xqCiSEd7aYV37wHxUTSN38Isok_0qDCHg4pKXCcVM2h6FKJSGmvw-xPm9HkfkIcbh1CiVVG4nREP142XrBecdzhQomNlcalmwdzGHsuHPjTP-KJraa15yvvZDceq-f_YfECicDllYBLEsg24oPRM-ibMonWtT9qOm5dSfWS5G_r09KJ4HMB6REICq1wleDD1mwSigXkM_nxIKa4TxRaRqEekoooWRwuKA5-euHN3xxNfIKKP19EtGhuNTs0YdCSe8_w', - atype: 1, - ext: { - linkType: 2 - } - } - ] - }, - { - source: 'domain.com', - uids: [ - { - id: 'value read from cookie or local storage', - atype: 1, - ext: { - stype: 'ppuid' - } - } - ] - } - ], - }, - { - bidder: 'adgrid', - params: { - placement: 'testadgd', - domainId: 1234, - }, - mediaTypes: { - banner: { - sizes: [[728, 90], [970, 250]] - } - }, - - adUnitCode: 'div-2-abcd', - transactionId: '6196885d-4e76-40dc-a09c-906ed232626b', - sizes: [[728, 90], [970, 250]], - bidId: '5ba94555219a03', - bidderRequestId: '359bf8a3c06b2e', - auctionId: '2e684815-b44e-4e04-b812-56da54adbe74', - } - ] - const bidderRequest = { - bidderCode: 'adgrid', - auctionId: '2e684815-b44e-4e04-b812-56da54adbe74', - bidderRequestId: '359bf8a3c06b2e', - refererInfo: { - reachedTop: true, - isAmp: false, - numIframes: 0, - stack: [ - 'https://test.com' - ], - topmostLocation: 'https://test.com', - location: 'https://test.com', - canonicalUrl: null, - page: 'https://test.com', - domain: 'test.com', - ref: null, - legacy: { - reachedTop: true, - isAmp: false, - numIframes: 0, - stack: [ - 'https://test.com' - ], - referer: 'https://test.com', - canonicalUrl: null - }, - }, - gdprConsent: { - gdprApplies: true, - consentString: 'CPhdLUAPhdLUAAKAsAENCmCsAP_AAE7AAAqIJFNd_H__bW9r-f5_aft0eY1P9_r37uQzDhfNk-8F3L_W_LwX52E7NF36tq4KmR4ku1LBIUNlHMHUDUmwaokVryHsak2cpzNKJ7BEknMZOydYGF9vmxtj-QKY7_5_d3bx2D-t_9v239z3z81Xn3d53-_03LCdV5_9Dfn9fR_bc9KPt_58v8v8_____3_e__3_7997BIiAaADgAJYBnwEeAJXAXmAwQBj4DtgHcgPBAeKBIgAA.YAAAAAAAAAAA', - } - }; - it('We perform a test with 2 display adunits', () => { - const displayBids = structuredClone(sampleBids); - displayBids[0].mediaTypes = { - banner: { - sizes: [[300, 250], [300, 600]] - } - }; - const request = spec.buildRequests(displayBids, bidderRequest); - const requestContent = request.data; - expect(request).to.have.property('method').and.to.equal('POST'); - const expectedRequest = { - imp: [ - { - id: '44a2706ac3574', - banner: { - topframe: 0, - format: [ - { w: 300, h: 250 }, - { w: 300, h: 600 }, - ], - }, - secure: 1, - tagid: 'header-ad-1234', - ext: { - adUnitCode: 'header-ad-1234', - divId: 'header-ad-1234', - gpid: '/12345/Header-Ad', - adgrid: { - placement: 'testadgd', - domainId: 1234, - }, - }, - }, - { - id: '5ba94555219a03', - banner: { - topframe: 0, - format: [ - { w: 728, h: 90 }, - { w: 970, h: 250 }, - ], - }, - secure: 1, - tagid: 'div-2-abcd', - ext: { - adUnitCode: 'div-2-abcd', - divId: 'div-2-abcd', - adgrid: { - placement: 'testadgd', - domainId: 1234, - }, - }, - }, - ], - id: requestContent.id, - test: 0, - ext: { - version: requestContent.ext.version, - source: 'prebid.js', - pageViewId: requestContent.ext.pageViewId, - bidderVersion: '2.0', - }, - cur: [ - 'USD', - ], - user: {}, - }; - expect(requestContent).to.be.eql(expectedRequest); - }); - - if (FEATURES.VIDEO) { - it('We perform a test with a multiformat adunit', () => { - const multiformatBids = structuredClone(sampleBids); - multiformatBids[0].mediaTypes = { - banner: { - sizes: [[300, 250], [300, 600]] - }, - video: { - context: 'outstream', - playerSize: [640, 480], - mimes: ['video/mp4'], - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - playbackmethod: [2], - skip: 1, - playback_method: ['auto_play_sound_off'] - } - }; - const request = spec.buildRequests(multiformatBids, bidderRequest); - const video = request.data.imp[0].video; - const expectedVideo = { - mimes: ['video/mp4'], - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - playbackmethod: [2], - skip: 1, - w: 640, - h: 480, - ext: { - playerSize: [640, 480], - context: 'outstream', - }, - }; - expect(video).to.eql(expectedVideo); - }); - - it('We perform a test with a instream adunit', () => { - const videoBids = structuredClone(sampleBids); - videoBids[0].mediaTypes = { - video: { - context: 'instream', - playerSize: [640, 480], - mimes: ['video/mp4'], - protocols: [1, 2, 3, 4, 5, 6], - playbackmethod: [2], - skip: 1 - } - }; - const request = spec.buildRequests(videoBids, bidderRequest); - const requestContent = request.data; - expect(request).to.have.property('method').and.to.equal('POST'); - expect(requestContent.imp[0].video.ext.context).to.be.eql('instream'); - expect(requestContent.imp[0].video.playbackmethod[0]).to.be.eql(2); - }); - } - }); - after(() => { - sandbox.restore() - }); - }); - - describe('We test intepretResponse', () => { - it('empty response', () => { - const response = { - body: '' - }; - const output = spec.interpretResponse(response); - expect(output.length).to.be.eql(0); - }); - it('banner responses with adm', () => { - const response = { - body: { - id: 'a8d3a675-a4ba-4d26-807f-c8f2fad821e0', - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: '4427551302944024629', - impid: '226175918ebeda', - price: 1.5, - adomain: [ - 'http://prebid.org', - ], - crid: '98493581', - ssp: 'test', - h: 600, - w: 300, - adm: '
TestAd
', - cat: [ - 'IAB3-1', - ], - ext: { - adUnitCode: 'div-1', - mediaType: 'banner', - ssp: 'test', - }, - }, - ], - seat: 'test', - }, - ], - ext: { - id: 'de3de7c7-e1cf-4712-80a9-94eb26bfc718', - cookies: [], - }, - }, - }; - const output = spec.interpretResponse(response); - const expectedOutput = [{ - requestId: '226175918ebeda', - cpm: 1.5, - width: 300, - height: 600, - creativeId: '98493581', - currency: 'USD', - netRevenue: true, - ttl: 120, - mediaType: 'banner', - meta: { - advertiserDomains: [ - 'http://prebid.org', - ], - demandSource: 'test', - }, - ad: '
TestAd
', - }]; - expect(output).to.eql(expectedOutput); - }); - - it('instream responses', () => { - const response = { - body: { - id: '2be64380-ba0c-405a-ab53-51f51c7bde51', - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: '8275140264321181514', - impid: '263cba3b8bfb72', - price: 5, - adomain: [ - 'adgrid.com', - ], - crid: '97517771', - h: 1, - w: 1, - adm: 'vast', - ext: { - mediaType: 'instream', - ssp: 'test', - adUnitCode: 'video1', - }, - }, - ], - seat: 'test', - }, - ], - ext: { - cookies: [], - }, - }, - }; - - const output = spec.interpretResponse(response); - const expectedOutput = [{ - requestId: '263cba3b8bfb72', - cpm: 5, - width: 1, - height: 1, - creativeId: '97517771', - currency: 'USD', - netRevenue: true, - ttl: 120, - mediaType: 'video', - meta: { - advertiserDomains: ['adgrid.com'], - demandSource: 'test' - }, - vastXml: 'vast', - }]; - expect(output).to.eql(expectedOutput); - }); - - it('outstream responses', () => { - const response = { - body: { - id: '40c23932-135e-4602-9701-ca36f8d80c07', - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: '1186971142548769361', - impid: '4ce809b61a3928', - price: 5, - adomain: [ - 'adgrid.com', - ], - crid: '97517771', - h: 1, - w: 1, - adm: 'vast', - ext: { - mediaType: 'outstream', - ssp: 'test', - adUnitCode: 'div-1', - }, - }, - ], - seat: 'test', - }, - ], - ext: { - cookies: [], - }, - }, - }; - - const output = spec.interpretResponse(response); - const expectedOutut = [{ - requestId: '4ce809b61a3928', - cpm: 5, - width: 1, - height: 1, - creativeId: '97517771', - currency: 'USD', - netRevenue: true, - ttl: 120, - mediaType: 'video', - meta: { advertiserDomains: ['adgrid.com'], demandSource: 'test' }, - vastXml: 'vast', - renderer: output[0].renderer, - }]; - expect(output).to.eql(expectedOutut); - }); - }); - - describe('getUserSyncs()', () => { - const response = { body: { cookies: [] } }; - it('Verifies user sync without cookie in bid response', () => { - const syncs = spec.getUserSyncs({}, [response], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.eql([]); - }); - it('Verifies user sync with cookies in bid response', () => { - response.body.ext = { - cookies: [{ 'type': 'image', 'url': 'http://www.cookie.sync.org/' }] - }; - const syncs = spec.getUserSyncs({}, [response], DEFAULT_OPTIONS.gdprConsent); - const expectedSyncs = [{ type: 'image', url: 'http://www.cookie.sync.org/' }]; - expect(syncs).to.eql(expectedSyncs); - }); - it('Verifies user sync with no bid response', () => { - var syncs = spec.getUserSyncs({}, null, DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.eql([]); - }); - it('Verifies user sync with no bid body response', () => { - let syncs = spec.getUserSyncs({}, [], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.eql([]); - syncs = spec.getUserSyncs({}, [{}], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.eql([]); - }); - }); -}); diff --git a/test/spec/modules/adhashBidAdapter_spec.js b/test/spec/modules/adhashBidAdapter_spec.js deleted file mode 100644 index 75ff8b851..000000000 --- a/test/spec/modules/adhashBidAdapter_spec.js +++ /dev/null @@ -1,339 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adhashBidAdapter.js'; - -describe('adhashBidAdapter', function () { - describe('isBidRequestValid', function () { - const validBid = { - bidder: 'adhash', - params: { - publisherId: '0xc3b09b27e9c6ef73957901aa729b9e69e5bbfbfb', - platformURL: 'https://adhash.com/p/struma/' - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - bidId: '12345678901234', - bidderRequestId: '98765432109876', - auctionId: '01234567891234', - }; - - it('should return true when all mandatory parameters are there', function () { - expect(spec.isBidRequestValid(validBid)).to.equal(true); - }); - - it('should return false when there are no params', function () { - const bid = { ...validBid }; - delete bid.params; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when unsupported media type is requested', function () { - const bid = { ...validBid }; - bid.mediaTypes = { native: { sizes: [[300, 250]] } }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when publisherId is not a string', function () { - const bid = { ...validBid }; - bid.params.publisherId = 123; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when publisherId is not valid', function () { - const bid = { ...validBid }; - bid.params.publisherId = 'short string'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when publisherId is not a string', function () { - const bid = { ...validBid }; - bid.params.platformURL = 123; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when publisherId is not valid', function () { - const bid = { ...validBid }; - bid.params.platformURL = 'https://'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when bidderURL is present but not https://', function () { - const bid = { ...validBid }; - bid.params.bidderURL = 'http://example.com/'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequest = { - params: { - publisherId: '0xc3b09b27e9c6ef73957901aa729b9e69e5bbfbfb' - }, - sizes: [[300, 250]], - adUnitCode: 'adUnitCode', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - }; - it('should build the request correctly', function () { - const result = spec.buildRequests( - [ bidRequest ], - { gdprConsent: { gdprApplies: true, consentString: 'example' }, refererInfo: { topmostLocation: 'https://example.com/path.html' } } - ); - expect(result.length).to.equal(1); - expect(result[0].method).to.equal('POST'); - expect(result[0].url).to.equal('https://bidder.adhash.com/rtb?version=3.6&prebid=true&publisher=0xc3b09b27e9c6ef73957901aa729b9e69e5bbfbfb'); - expect(result[0].bidRequest).to.equal(bidRequest); - expect(result[0].data).to.have.property('timezone'); - expect(result[0].data).to.have.property('location'); - expect(result[0].data).to.have.property('publisherId'); - expect(result[0].data).to.have.property('size'); - expect(result[0].data).to.have.property('navigator'); - expect(result[0].data).to.have.property('creatives'); - expect(result[0].data).to.have.property('blockedCreatives'); - expect(result[0].data).to.have.property('currentTimestamp'); - expect(result[0].data).to.have.property('recentAds'); - }); - it('should build the request correctly without referer', function () { - const result = spec.buildRequests([ bidRequest ], { gdprConsent: { gdprApplies: true, consentString: 'example' } }); - expect(result.length).to.equal(1); - expect(result[0].method).to.equal('POST'); - expect(result[0].url).to.equal('https://bidder.adhash.com/rtb?version=3.6&prebid=true&publisher=0xc3b09b27e9c6ef73957901aa729b9e69e5bbfbfb'); - expect(result[0].bidRequest).to.equal(bidRequest); - expect(result[0].data).to.have.property('timezone'); - expect(result[0].data).to.have.property('location'); - expect(result[0].data).to.have.property('publisherId'); - expect(result[0].data).to.have.property('size'); - expect(result[0].data).to.have.property('navigator'); - expect(result[0].data).to.have.property('creatives'); - expect(result[0].data).to.have.property('blockedCreatives'); - expect(result[0].data).to.have.property('currentTimestamp'); - expect(result[0].data).to.have.property('recentAds'); - }); - }); - - describe('interpretResponse', function () { - const request = { - data: { some: 'data' }, - bidRequest: { - bidId: '12345678901234', - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - params: { - platformURL: 'https://adhash.com/p/struma/' - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - } - }; - - let bodyStub; - - const serverResponse = { - body: { - creatives: [{ costEUR: 1.234 }], - advertiserDomains: 'adhash.com', - badWords: [ - ['onqjbeq', 'full', 1], - ['onqjbeqo', 'partial', 1], - ['tbbqjbeq', 'full', -1], - ['fgnegf', 'starts', 1], - ['raqf', 'ends', 1], - ['kkk[no]lll', 'regexp', 1], - ['дума', 'full', 1], - ['старт', 'starts', 1], - ['край', 'ends', 1], - ['onq jbeq', 'partial', 1], - ['dhrra qvrf', 'combo', 2], - ], - maxScore: 2 - } - }; - - afterEach(function() { - if (bodyStub) { - bodyStub.restore(); - } - }); - - it('should interpret the response correctly', function () { - const result = spec.interpretResponse(serverResponse, request); - expect(result.length).to.equal(1); - expect(result[0].requestId).to.equal('12345678901234'); - expect(result[0].cpm).to.equal(1.234); - expect(result[0].width).to.equal(300); - expect(result[0].height).to.equal(250); - expect(result[0].creativeId).to.equal('adunit-code'); - expect(result[0].netRevenue).to.equal(true); - expect(result[0].currency).to.equal('EUR'); - expect(result[0].ttl).to.equal(60); - expect(result[0].meta.advertiserDomains).to.eql(['adhash.com']); - }); - - it('should return empty array when there are bad words (full)', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return 'example text badword badword example badword text' + ' word'.repeat(993); - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(0); - }); - - it('should return empty array when there are bad words (full cyrillic)', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return 'example text дума дума example дума text' + ' текст'.repeat(993); - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(0); - }); - - it('should return empty array when there are bad words (partial)', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return 'example text partialbadwordb badwordb example badwordbtext' + ' word'.repeat(994); - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(0); - }); - - it('should return empty array when there are bad words (partial, compound phrase)', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return 'example text partialbad wordb bad wordb example bad wordbtext' + ' word'.repeat(994); - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(0); - }); - - it('should return empty array when there are bad words (starts)', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return 'example text startsWith starts text startsAgain' + ' word'.repeat(994); - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(0); - }); - - it('should return empty array when there are bad words (starts cyrillic)', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return 'example text стартТекст старт text стартТекст' + ' дума'.repeat(994); - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(0); - }); - - it('should return empty array when there are bad words (ends)', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return 'example text wordEnds ends text anotherends' + ' word'.repeat(994); - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(0); - }); - - it('should return empty array when there are bad words (ends cyrillic)', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return 'example text ДругКрай край text ощеединкрай' + ' дума'.repeat(994); - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(0); - }); - - it('should return empty array when there are bad words (combo)', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return 'queen of england dies, the queen dies' + ' word'.repeat(993); - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(0); - }); - - it('should return empty array when there are bad words (regexp)', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return 'example text xxxayyy zzxxxAyyyzz text xxxbyyy' + ' word'.repeat(994); - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(0); - }); - - it('should return non-empty array when there are not enough bad words (full)', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return 'example text badword badword example text' + ' word'.repeat(994); - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(1); - }); - - it('should return non-empty array when there are not enough bad words (partial)', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return 'example text partialbadwordb example' + ' word'.repeat(996); - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(1); - }); - - it('should return non-empty array when there are no-bad word matches', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return 'example text partialbadword example text' + ' word'.repeat(995); - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(1); - }); - - it('should return non-empty array when there are bad words and good words', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return 'example text badword badword example badword goodWord goodWord ' + ' word'.repeat(992); - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(1); - }); - - it('should return non-empty array when there is a problem with the brand-safety', function () { - bodyStub = sinon.stub(window.top.document.body, 'textContent').get(function() { - return null; - }); - expect(spec.interpretResponse(serverResponse, request).length).to.equal(1); - }); - - it('should return empty array when there are no creatives returned', function () { - expect(spec.interpretResponse({body: {creatives: []}}, request).length).to.equal(0); - }); - - it('should return empty array when there is no creatives key in the response', function () { - expect(spec.interpretResponse({body: {}}, request).length).to.equal(0); - }); - - it('should return empty array when something is not right', function () { - expect(spec.interpretResponse(null, request).length).to.equal(0); - }); - - it('should interpret the video response correctly', function () { - const result = spec.interpretResponse({ - body: { - creatives: [{ costEUR: 1.234, vastURL: 'https://example.com/vast' }], - advertiserDomains: 'adhash.com' - } - }, { - data: { some: 'data' }, - bidRequest: { - bidId: '12345678901234', - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - params: { - platformURL: 'https://adhash.com/p/struma/' - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [300, 250], - mimes: ['video/mp4'], - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - playbackmethod: [2], - skip: 1 - } - } - } - }); - expect(result.length).to.equal(1); - expect(result[0].requestId).to.equal('12345678901234'); - expect(result[0].cpm).to.equal(1.234); - expect(result[0].width).to.equal(300); - expect(result[0].height).to.equal(250); - expect(result[0].creativeId).to.equal('adunit-code'); - expect(result[0].netRevenue).to.equal(true); - expect(result[0].currency).to.equal('EUR'); - expect(result[0].ttl).to.equal(60); - expect(result[0].meta.advertiserDomains).to.eql(['adhash.com']); - expect(result[0].vastUrl).to.equal('https://example.com/vast'); - }); - }); -}); diff --git a/test/spec/modules/adheseBidAdapter_spec.js b/test/spec/modules/adheseBidAdapter_spec.js deleted file mode 100644 index 4c16b7743..000000000 --- a/test/spec/modules/adheseBidAdapter_spec.js +++ /dev/null @@ -1,558 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/adheseBidAdapter.js'; -import {config} from 'src/config.js'; - -const BID_ID = 456; -const TTL = 360; -const NET_REVENUE = true; - -const minimalBid = function() { - return { - 'bidId': BID_ID, - 'bidder': 'adhese', - 'params': { - account: 'demo', - location: '_main_page_', - format: 'leaderboard' - } - } -}; - -const bidWithParams = function(data) { - const bid = minimalBid(); - bid.params.data = data; - return bid; -}; - -describe('AdheseAdapter', function () { - describe('getUserSyncs', function () { - const serverResponses = [{ - account: 'demo' - }]; - const gdprConsent = { - gdprApplies: true, - consentString: 'CONSENT_STRING' - }; - it('should return empty when iframe disallowed', function () { - expect(spec.getUserSyncs({ iframeEnabled: false }, serverResponses, gdprConsent)).to.be.empty; - }); - it('should return empty when no serverResponses present', function () { - expect(spec.getUserSyncs({ iframeEnabled: true }, [], gdprConsent)).to.be.empty; - }); - it('should return empty when no account info present in the response', function () { - expect(spec.getUserSyncs({ iframeEnabled: true }, [{}], gdprConsent)).to.be.empty; - }); - it('should return usersync url when iframe allowed', function () { - expect(spec.getUserSyncs({ iframeEnabled: true }, serverResponses, gdprConsent)).to.deep.equal([{ type: 'iframe', url: 'https://user-sync.adhese.com/iframe/user_sync.html?account=demo&gdpr=1&consentString=CONSENT_STRING' }]); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(minimalBid())).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const bid = Object.assign({}, minimalBid()); - delete bid.params; - bid.params = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidderRequest = { - gdprConsent: { - gdprApplies: true, - consentString: 'CONSENT_STRING' - }, - refererInfo: { - page: 'http://prebid.org/dev-docs/subjects?_d=1' - } - }; - - it('should include requested slots', function () { - const req = spec.buildRequests([ minimalBid() ], bidderRequest); - - expect(JSON.parse(req.data).slots[0].slotname).to.equal('_main_page_-leaderboard'); - }); - - it('should include all extra bid params', function () { - const req = spec.buildRequests([ bidWithParams({ 'ag': '25' }) ], bidderRequest); - - expect(JSON.parse(req.data).slots[0].parameters).to.deep.include({ 'ag': [ '25' ] }); - }); - - it('should assign bid params per slot', function () { - const req = spec.buildRequests([ bidWithParams({ 'ag': '25' }), bidWithParams({ 'ag': '25', 'ci': 'gent' }) ], bidderRequest); - - expect(JSON.parse(req.data).slots[0].parameters).to.deep.include({ 'ag': [ '25' ] }).and.not.to.deep.include({ 'ci': [ 'gent' ] }); - expect(JSON.parse(req.data).slots[1].parameters).to.deep.include({ 'ag': [ '25' ] }).and.to.deep.include({ 'ci': [ 'gent' ] }); - }); - - it('should split multiple target values', function () { - const req = spec.buildRequests([ bidWithParams({ 'ci': 'london' }), bidWithParams({ 'ci': 'gent' }) ], bidderRequest); - - expect(JSON.parse(req.data).slots[0].parameters).to.deep.include({ 'ci': [ 'london' ] }); - expect(JSON.parse(req.data).slots[1].parameters).to.deep.include({ 'ci': [ 'gent' ] }); - }); - - it('should filter out empty params', function () { - const req = spec.buildRequests([ bidWithParams({ 'aa': [], 'bb': null, 'cc': '', 'dd': [ '', '' ], 'ee': [ 0, 1, null ], 'ff': 0, 'gg': [ 'x', 'y', '' ] }) ], bidderRequest); - - const params = JSON.parse(req.data).slots[0].parameters; - expect(params).to.not.have.any.keys('aa', 'bb', 'cc', 'dd'); - expect(params).to.deep.include({ 'ee': [ 0, 1 ], 'ff': [ 0 ], 'gg': [ 'x', 'y' ] }); - }); - - it('should include gdpr consent param', function () { - const req = spec.buildRequests([ minimalBid() ], bidderRequest); - - expect(JSON.parse(req.data).parameters).to.deep.include({ 'xt': [ 'CONSENT_STRING' ] }); - }); - - it('should include referer param in base64url format', function () { - const req = spec.buildRequests([ minimalBid() ], bidderRequest); - - expect(JSON.parse(req.data).parameters).to.deep.include({ 'xf': [ 'aHR0cDovL3ByZWJpZC5vcmcvZGV2LWRvY3Mvc3ViamVjdHM_X2Q9MQ' ] }); - }); - - it('should include eids', function () { - const bid = minimalBid(); - bid.userIdAsEids = [{ source: 'id5-sync.com', uids: [{ id: 'ID5@59sigaS-...' }] }]; - - const req = spec.buildRequests([ bid ], bidderRequest); - - expect(JSON.parse(req.data).user.ext.eids).to.deep.equal(bid.userIdAsEids); - }); - - it('should not include eids field when userid module disabled', function () { - const req = spec.buildRequests([ minimalBid() ], bidderRequest); - - expect(JSON.parse(req.data)).to.not.have.key('eids'); - }); - - it('should request vast content as url by default', function () { - const req = spec.buildRequests([ minimalBid() ], bidderRequest); - - expect(JSON.parse(req.data).vastContentAsUrl).to.equal(true); - }); - - it('should request vast content as markup when configured', function () { - sinon.stub(config, 'getConfig').withArgs('adhese').returns({ vastContentAsUrl: false }); - - const req = spec.buildRequests([ minimalBid() ], bidderRequest); - - expect(JSON.parse(req.data).vastContentAsUrl).to.equal(false); - config.getConfig.restore(); - }); - - it('should include bids', function () { - const bid = minimalBid(); - const req = spec.buildRequests([ bid ], bidderRequest); - - expect(req.bids).to.deep.equal([ bid ]); - }); - - it('should make a POST request', function () { - const req = spec.buildRequests([ minimalBid() ], bidderRequest); - - expect(req.method).to.equal('POST'); - }); - - it('should request the json endpoint', function () { - const req = spec.buildRequests([ minimalBid() ], bidderRequest); - - expect(req.url).to.equal('https://ads-demo.adhese.com/json'); - }); - - it('should include params specified in the config', function () { - sinon.stub(config, 'getConfig').withArgs('adhese').returns({ globalTargets: { 'tl': [ 'all' ] } }); - const req = spec.buildRequests([ minimalBid() ], bidderRequest); - - expect(JSON.parse(req.data).parameters).to.deep.include({ 'tl': [ 'all' ] }); - config.getConfig.restore(); - }); - - it('should give priority to bid params over config params', function () { - sinon.stub(config, 'getConfig').withArgs('adhese').returns({ globalTargets: { 'xt': ['CONFIG_CONSENT_STRING'] } }); - const req = spec.buildRequests([ minimalBid() ], bidderRequest); - - expect(JSON.parse(req.data).parameters).to.deep.include({ 'xt': [ 'CONSENT_STRING' ] }); - config.getConfig.restore(); - }); - }); - - describe('interpretResponse', () => { - const bidRequest = { - bids: [ minimalBid() ] - }; - - it('should get correct ssp banner response', () => { - const sspBannerResponse = { - body: [ - { - origin: 'APPNEXUS', - originInstance: '', - ext: 'js', - slotID: '10', - slotName: '_main_page_-leaderboard', - adType: 'leaderboard', - originData: { - seatbid: [{ - bid: [{ - crid: '60613369', - dealid: null - }], - seat: '958' - }] - }, - width: '728', - height: '90', - body: '
', - tracker: 'https://hosts-demo.adhese.com/rtb_gateway/handlers/client/track/?id=a2f39296-6dd0-4b3c-be85-7baa22e7ff4a', - impressionCounter: 'https://hosts-demo.adhese.com/rtb_gateway/handlers/client/track/?id=a2f39296-6dd0-4b3c-be85-7baa22e7ff4a', - extension: {'prebid': {'cpm': {'amount': '1.000000', 'currency': 'USD'}}, mediaType: 'banner'}, - adomain: [ - 'www.example.com' - ] - } - ] - }; - - const expectedResponse = [{ - requestId: BID_ID, - ad: '
', - cpm: 1, - currency: 'USD', - creativeId: '60613369', - dealId: '', - width: 728, - height: 90, - mediaType: 'banner', - netRevenue: NET_REVENUE, - ttl: TTL, - adhese: { - origin: 'APPNEXUS', - originInstance: '', - originData: { - adType: 'leaderboard', - seatbid: [ - { - bid: [ { crid: '60613369', dealid: null } ], - seat: '958' - } - ], - slotId: '10', - slotName: '_main_page_-leaderboard' - } - }, - meta: { - advertiserDomains: [ - 'www.example.com' - ] - }, - }]; - expect(spec.interpretResponse(sspBannerResponse, bidRequest)).to.deep.equal(expectedResponse); - }); - - it('should get correct ssp video response', () => { - const sspVideoResponse = { - body: [ - { - origin: 'RUBICON', - ext: 'js', - slotName: '_main_page_-leaderboard', - adType: 'leaderboard', - width: '640', - height: '350', - body: '', - extension: {'prebid': {'cpm': {'amount': '2.1', 'currency': 'USD'}}, mediaType: 'video'} - } - ] - }; - - const expectedResponse = [{ - requestId: BID_ID, - vastXml: '', - cpm: 2.1, - currency: 'USD', - creativeId: 'RUBICON', - dealId: '', - width: 640, - height: 350, - mediaType: 'video', - netRevenue: NET_REVENUE, - ttl: TTL, - adhese: { - origin: 'RUBICON', - originInstance: '', - originData: {} - }, - meta: { - advertiserDomains: [] - }, - }]; - expect(spec.interpretResponse(sspVideoResponse, bidRequest)).to.deep.equal(expectedResponse); - }); - - it('should get correct ssp cache video response', () => { - const sspCachedVideoResponse = { - body: [ - { - origin: 'RUBICON', - ext: 'js', - slotName: '_main_page_-leaderboard', - adType: 'leaderboard', - width: '640', - height: '350', - cachedBodyUrl: 'https://ads-demo.adhese.com/content/38983ccc-4083-4c24-932c-96f798d969b3', - extension: {'prebid': {'cpm': {'amount': '2.1', 'currency': 'USD'}}, mediaType: 'video'} - } - ] - }; - - const expectedResponse = [{ - requestId: BID_ID, - vastUrl: 'https://ads-demo.adhese.com/content/38983ccc-4083-4c24-932c-96f798d969b3', - cpm: 2.1, - currency: 'USD', - creativeId: 'RUBICON', - dealId: '', - width: 640, - height: 350, - mediaType: 'video', - netRevenue: NET_REVENUE, - ttl: TTL, - adhese: { - origin: 'RUBICON', - originInstance: '', - originData: {} - }, - meta: { - advertiserDomains: [] - }, - }]; - expect(spec.interpretResponse(sspCachedVideoResponse, bidRequest)).to.deep.equal(expectedResponse); - }); - - it('should get correct Adhese banner response', () => { - const adheseBannerResponse = { - body: [ - { - adType: 'largeleaderboard', // it can differ from the requested slot - adFormat: 'largeleaderboard', - timeStamp: '1544009030000', - orderId: '22051', - adspaceId: '162363', - body: '', - tag: '', - tracker: 'https://hosts-demo.adhese.com/track/tracker', - altText: '', - height: '150', - width: '840', - tagUrl: 'https://pool-demo.adhese.com/pool/lib/90511.js', - libId: '90511', - id: '742898', - advertiserId: '2081', - ext: 'js', - url: 'https://hosts-demo.adhese.com/raylene/url', - clickTag: 'https://hosts-demo.adhese.com/raylene/clickTag', - poolPath: 'https://hosts-demo.adhese.com/pool/lib/', - orderName: 'Luminus boiler comodity-Pareto -201812', - creativeName: 'nl_demo _network_ron_dlbd_840x150_fix_dir_asv_std_dis_brd_nrt_na_red', - slotName: '_main_page_-leaderboard', - slotID: '29306', - impressionCounter: 'https://hosts-demo.adhese.com/track/742898', - origin: 'JERLICIA', - originData: {}, - auctionable: true, - extension: { - prebid: { - cpm: { - amount: '5.96', - currency: 'USD' - } - }, - mediaType: 'banner' - } - } - ] - }; - - const expectedResponse = [{ - requestId: BID_ID, - ad: '', - adhese: { - origin: '', - originInstance: '', - originData: { - adFormat: 'largeleaderboard', - adId: '742898', - adType: 'largeleaderboard', - adspaceId: '162363', - libId: '90511', - orderProperty: undefined, - priority: undefined, - viewableImpressionCounter: undefined, - slotId: '29306', - slotName: '_main_page_-leaderboard', - advertiserId: '2081' - } - }, - cpm: 5.96, - currency: 'USD', - creativeId: '742898', - dealId: '22051', - width: 840, - height: 150, - mediaType: 'banner', - netRevenue: NET_REVENUE, - ttl: TTL, - meta: { - advertiserDomains: [] - }, - }]; - expect(spec.interpretResponse(adheseBannerResponse, bidRequest)).to.deep.equal(expectedResponse); - }); - - it('should get correct Adhese video response', () => { - const adheseVideoResponse = { - body: [ - { - adType: 'preroll', - adFormat: '', - orderId: '22248', - adspaceId: '164196', - body: '', - height: '360', - width: '640', - tag: "", - libId: '89860', - id: '742470', - advertiserId: '2263', - ext: 'advar', - orderName: 'Smartphoto EOY-20181112', - creativeName: 'PREROLL', - slotName: '_main_page_-leaderboard', - slotID: '41711', - impressionCounter: 'https://hosts-demo.adhese.com/track/742898', - origin: 'JERLICIA', - originData: {}, - auctionable: true, - extension: { - mediaType: 'video' - } - } - ] - }; - - const expectedResponse = [{ - requestId: BID_ID, - vastXml: '', - adhese: { - origin: '', - originInstance: '', - originData: { - adFormat: '', - adId: '742470', - adType: 'preroll', - adspaceId: '164196', - libId: '89860', - orderProperty: undefined, - priority: undefined, - viewableImpressionCounter: undefined, - slotId: '41711', - slotName: '_main_page_-leaderboard', - advertiserId: '2263', - } - }, - cpm: 0, - currency: 'USD', - creativeId: '742470', - dealId: '22248', - width: 640, - height: 360, - mediaType: 'video', - netRevenue: NET_REVENUE, - ttl: TTL, - meta: { - advertiserDomains: [] - }, - }]; - expect(spec.interpretResponse(adheseVideoResponse, bidRequest)).to.deep.equal(expectedResponse); - }); - - it('should get correct Adhese cached video response', () => { - const adheseVideoResponse = { - body: [ - { - adType: 'preroll', - adFormat: '', - orderId: '22248', - adspaceId: '164196', - body: '', - height: '360', - width: '640', - extension: { - mediaType: 'video' - }, - cachedBodyUrl: 'https://ads-demo.adhese.com/content/38983ccc-4083-4c24-932c-96f798d969b3', - libId: '89860', - id: '742470', - advertiserId: '2263', - ext: 'advar', - orderName: 'Smartphoto EOY-20181112', - creativeName: 'PREROLL', - slotName: '_main_page_-leaderboard', - slotID: '41711', - impressionCounter: 'https://hosts-demo.adhese.com/track/742898', - origin: 'JERLICIA', - originData: {}, - auctionable: true - } - ] - }; - - const expectedResponse = [{ - requestId: BID_ID, - vastUrl: 'https://ads-demo.adhese.com/content/38983ccc-4083-4c24-932c-96f798d969b3', - adhese: { - origin: '', - originInstance: '', - originData: { - adFormat: '', - adId: '742470', - adType: 'preroll', - adspaceId: '164196', - libId: '89860', - orderProperty: undefined, - priority: undefined, - viewableImpressionCounter: undefined, - slotId: '41711', - slotName: '_main_page_-leaderboard', - advertiserId: '2263', - } - }, - cpm: 0, - currency: 'USD', - creativeId: '742470', - dealId: '22248', - width: 640, - height: 360, - mediaType: 'video', - netRevenue: NET_REVENUE, - ttl: TTL, - meta: { - advertiserDomains: [] - }, - }]; - expect(spec.interpretResponse(adheseVideoResponse, bidRequest)).to.deep.equal(expectedResponse); - }); - - it('should return no bids for empty adserver response', () => { - const adserverResponse = { body: [] }; - expect(spec.interpretResponse(adserverResponse, bidRequest)).to.be.empty; - }); - }); -}); diff --git a/test/spec/modules/adipoloBidAdapter_spec.js b/test/spec/modules/adipoloBidAdapter_spec.js deleted file mode 100644 index 823244ab7..000000000 --- a/test/spec/modules/adipoloBidAdapter_spec.js +++ /dev/null @@ -1,477 +0,0 @@ -import {expect} from 'chai'; -import {config} from 'src/config.js'; -import {spec} from 'modules/adipoloBidAdapter.js'; -import {deepClone} from 'src/utils'; -import {getBidFloor} from '../../../libraries/xeUtils/bidderUtils.js'; -import sinon from 'sinon'; - -const US_ENDPOINT = 'https://prebid.adipolo.live'; -const EU_ENDPOINT = 'https://prebid-eu.adipolo.live'; - -const defaultRequest = { - tmax: 0, - adUnitCode: 'test', - bidId: '1', - requestId: 'qwerty', - ortb2: { - source: { - tid: 'auctionId' - } - }, - ortb2Imp: { - ext: { - tid: 'tr1', - } - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 200] - ] - } - }, - bidder: 'adipolo', - params: { - pid: '40', - ext: {} - }, - bidRequestsCount: 1 -}; - -const defaultRequestVideo = deepClone(defaultRequest); -defaultRequestVideo.mediaTypes = { - video: { - playerSize: [640, 480], - context: 'instream', - skipppable: true - } -}; - -const videoBidderRequest = { - bidderCode: 'adipolo', - bids: [{mediaTypes: {video: {}}, bidId: 'qwerty'}] -}; - -const displayBidderRequest = { - bidderCode: 'adipolo', - bids: [{bidId: 'qwerty'}] -}; - -describe('adipoloBidAdapter', () => { - describe('isBidRequestValid', function () { - it('should return false when request params is missing', function () { - const invalidRequest = deepClone(defaultRequest); - delete invalidRequest.params; - expect(spec.isBidRequestValid(invalidRequest)).to.equal(false); - }); - - it('should return false when required pid param is missing', function () { - const invalidRequest = deepClone(defaultRequest); - delete invalidRequest.params.pid; - expect(spec.isBidRequestValid(invalidRequest)).to.equal(false); - }); - - it('should return false when video.playerSize is missing', function () { - const invalidRequest = deepClone(defaultRequestVideo); - delete invalidRequest.mediaTypes.video.playerSize; - expect(spec.isBidRequestValid(invalidRequest)).to.equal(false); - }); - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(defaultRequest)).to.equal(true); - }); - }); - - describe('buildRequests', function () { - beforeEach(function () { - config.resetConfig(); - }); - - it('should send request with correct structure', function () { - const stub = sinon.stub(Intl, 'DateTimeFormat').returns({ - resolvedOptions: () => ({ timeZone: 'America/New_York' }) - }); - - const request = spec.buildRequests([defaultRequest], {}); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal(US_ENDPOINT + '/bid'); - expect(request.options).to.have.property('contentType').and.to.equal('application/json'); - expect(request).to.have.property('data'); - - stub.restore(); - }); - - it('should use EU endpoint if timezone is in Europe', function () { - const clock = sinon.stub(Intl, 'DateTimeFormat').returns({ - resolvedOptions: () => ({ timeZone: 'Europe/Warsaw' }) - }); - - const built = spec.buildRequests([defaultRequest], {}); - expect(built.url).to.equal(EU_ENDPOINT + '/bid'); - - clock.restore(); - }); - - it('should fallback to default US endpoint if timezone cannot be resolved', function () { - const stub = sinon.stub(Intl, 'DateTimeFormat').throws(new Error('Timezone error')); - const request = spec.buildRequests([defaultRequest], {}); - expect(request.url).to.equal(US_ENDPOINT + '/bid'); - stub.restore(); - }); - - it('should use default US endpoint if timezone is outside Europe', function () { - const stub = sinon.stub(Intl, 'DateTimeFormat').returns({ - resolvedOptions: () => ({ timeZone: 'Asia/Tokyo' }) - }); - - const request = spec.buildRequests([defaultRequest], {}); - expect(request.url).to.equal(US_ENDPOINT + '/bid'); - stub.restore(); - }); - - it('should build basic request structure', function () { - const request = JSON.parse(spec.buildRequests([defaultRequest], {}).data)[0]; - expect(request).to.have.property('tmax').and.to.equal(defaultRequest.tmax); - expect(request).to.have.property('bidId').and.to.equal(defaultRequest.bidId); - expect(request).to.have.property('auctionId').and.to.equal(defaultRequest.ortb2.source.tid); - expect(request).to.have.property('transactionId').and.to.equal(defaultRequest.ortb2Imp.ext.tid); - expect(request).to.have.property('tz').and.to.equal(new Date().getTimezoneOffset()); - expect(request).to.have.property('bc').and.to.equal(1); - expect(request).to.have.property('floor').and.to.equal(null); - expect(request).to.have.property('banner').and.to.deep.equal({sizes: [[300, 250], [300, 200]]}); - expect(request).to.have.property('gdprConsent').and.to.deep.equal({}); - expect(request).to.have.property('userEids').and.to.deep.equal([]); - expect(request).to.have.property('usPrivacy').and.to.equal(''); - expect(request).to.have.property('sizes').and.to.deep.equal(['300x250', '300x200']); - expect(request).to.have.property('ext').and.to.deep.equal({}); - expect(request).to.have.property('env').and.to.deep.equal({ - pid: '40' - }); - expect(request).to.have.property('device').and.to.deep.equal({ - ua: navigator.userAgent, - lang: navigator.language - }); - }); - - it('should build request with schain', function () { - const schainRequest = deepClone(defaultRequest); - const bidderRequest = { - ortb2: { - source: { - ext: { - schain: { - ver: '1.0' - } - } - } - } - }; - const request = JSON.parse(spec.buildRequests([schainRequest], bidderRequest).data)[0]; - expect(request).to.have.property('schain').and.to.deep.equal({ - ver: '1.0' - }); - }); - - it('should build request with location', function () { - const bidderRequest = { - refererInfo: { - page: 'page', - location: 'location', - domain: 'domain', - ref: 'ref', - isAmp: false - } - }; - const request = JSON.parse(spec.buildRequests([defaultRequest], bidderRequest).data)[0]; - expect(request).to.have.property('location'); - const location = request.location; - expect(location).to.have.property('page').and.to.equal('page'); - expect(location).to.have.property('location').and.to.equal('location'); - expect(location).to.have.property('domain').and.to.equal('domain'); - expect(location).to.have.property('ref').and.to.equal('ref'); - expect(location).to.have.property('isAmp').and.to.equal(false); - }); - - it('should build request with ortb2 info', function () { - const ortb2Request = deepClone(defaultRequest); - ortb2Request.ortb2 = { - site: { - name: 'name' - } - }; - const request = JSON.parse(spec.buildRequests([ortb2Request], {}).data)[0]; - expect(request).to.have.property('ortb2').and.to.deep.equal({ - site: { - name: 'name' - } - }); - }); - - it('should build request with ortb2Imp info', function () { - const ortb2ImpRequest = deepClone(defaultRequest); - ortb2ImpRequest.ortb2Imp = { - ext: { - data: { - pbadslot: 'home1', - adUnitSpecificAttribute: '1' - } - } - }; - const request = JSON.parse(spec.buildRequests([ortb2ImpRequest], {}).data)[0]; - expect(request).to.have.property('ortb2Imp').and.to.deep.equal({ - ext: { - data: { - pbadslot: 'home1', - adUnitSpecificAttribute: '1' - } - } - }); - }); - - it('should build request with valid bidfloor', function () { - const bfRequest = deepClone(defaultRequest); - bfRequest.getFloor = () => ({floor: 5, currency: 'USD'}); - const request = JSON.parse(spec.buildRequests([bfRequest], {}).data)[0]; - expect(request).to.have.property('floor').and.to.equal(5); - }); - - it('should build request with usp consent data if applies', function () { - const bidderRequest = { - uspConsent: '1YA-' - }; - const request = JSON.parse(spec.buildRequests([defaultRequest], bidderRequest).data)[0]; - expect(request).to.have.property('usPrivacy').and.equals('1YA-'); - }); - - it('should build request with extended ids', function () { - const idRequest = deepClone(defaultRequest); - idRequest.userIdAsEids = [ - {source: 'adserver.org', uids: [{id: 'TTD_ID_FROM_USER_ID_MODULE', atype: 1, ext: {rtiPartner: 'TDID'}}]}, - {source: 'pubcid.org', uids: [{id: 'pubCommonId_FROM_USER_ID_MODULE', atype: 1}]} - ]; - const request = JSON.parse(spec.buildRequests([idRequest], {}).data)[0]; - expect(request).to.have.property('userEids').and.deep.equal(idRequest.userIdAsEids); - }); - - it('should build request with video', function () { - const request = JSON.parse(spec.buildRequests([defaultRequestVideo], {}).data)[0]; - expect(request).to.have.property('video').and.to.deep.equal({ - playerSize: [640, 480], - context: 'instream', - skipppable: true - }); - expect(request).to.have.property('sizes').and.to.deep.equal(['640x480']); - }); - }); - - describe('interpretResponse', function () { - it('should return empty bids', function () { - const serverResponse = { - body: { - data: null - } - }; - - const invalidResponse = spec.interpretResponse(serverResponse, {}); - expect(invalidResponse).to.be.an('array').that.is.empty; - }); - - it('should interpret valid response', function () { - const serverResponse = { - body: { - data: [{ - requestId: 'qwerty', - cpm: 1, - currency: 'USD', - width: 300, - height: 250, - ttl: 600, - meta: { - advertiserDomains: ['adipolo'] - }, - ext: { - pixels: [ - ['iframe', 'surl1'], - ['image', 'surl2'], - ] - } - }] - } - }; - - const validResponse = spec.interpretResponse(serverResponse, {bidderRequest: displayBidderRequest}); - const bid = validResponse[0]; - expect(validResponse).to.be.an('array').that.is.not.empty; - expect(bid.requestId).to.equal('qwerty'); - expect(bid.cpm).to.equal(1); - expect(bid.currency).to.equal('USD'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.ttl).to.equal(600); - expect(bid.meta).to.deep.equal({advertiserDomains: ['adipolo']}); - }); - - it('should interpret valid banner response', function () { - const serverResponse = { - body: { - data: [{ - requestId: 'qwerty', - cpm: 1, - currency: 'USD', - width: 300, - height: 250, - ttl: 600, - mediaType: 'banner', - creativeId: 'xe-demo-banner', - ad: 'ad', - meta: {} - }] - } - }; - - const validResponseBanner = spec.interpretResponse(serverResponse, {bidderRequest: displayBidderRequest}); - const bid = validResponseBanner[0]; - expect(validResponseBanner).to.be.an('array').that.is.not.empty; - expect(bid.mediaType).to.equal('banner'); - expect(bid.creativeId).to.equal('xe-demo-banner'); - expect(bid.ad).to.equal('ad'); - }); - - it('should interpret valid video response', function () { - const serverResponse = { - body: { - data: [{ - requestId: 'qwerty', - cpm: 1, - currency: 'USD', - width: 600, - height: 480, - ttl: 600, - mediaType: 'video', - creativeId: 'xe-demo-video', - ad: 'vast-xml', - meta: {} - }] - } - }; - - const validResponseBanner = spec.interpretResponse(serverResponse, {bidderRequest: videoBidderRequest}); - const bid = validResponseBanner[0]; - expect(validResponseBanner).to.be.an('array').that.is.not.empty; - expect(bid.mediaType).to.equal('video'); - expect(bid.creativeId).to.equal('xe-demo-video'); - expect(bid.ad).to.equal('vast-xml'); - }); - }); - - describe('getUserSyncs', function () { - it('shoukd handle no params', function () { - const opts = spec.getUserSyncs({}, []); - expect(opts).to.be.an('array').that.is.empty; - }); - - it('should return empty if sync is not allowed', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: false}); - expect(opts).to.be.an('array').that.is.empty; - }); - - it('should allow iframe sync', function () { - const opts = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: false}, [{ - body: { - data: [{ - requestId: 'qwerty', - ext: { - pixels: [ - ['iframe', 'surl1?a=b'], - ['image', 'surl2?a=b'], - ] - } - }] - } - }]); - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('iframe'); - expect(opts[0].url).to.equal('surl1?a=b&us_privacy=&gdpr=0&gdpr_consent='); - }); - - it('should allow pixel sync', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [{ - body: { - data: [{ - requestId: 'qwerty', - ext: { - pixels: [ - ['iframe', 'surl1?a=b'], - ['image', 'surl2?a=b'], - ] - } - }] - } - }]); - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('image'); - expect(opts[0].url).to.equal('surl2?a=b&us_privacy=&gdpr=0&gdpr_consent='); - }); - - it('should allow pixel sync and parse consent params', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [{ - body: { - data: [{ - requestId: 'qwerty', - ext: { - pixels: [ - ['iframe', 'surl1?a=b'], - ['image', 'surl2?a=b'], - ] - } - }] - } - }], { - gdprApplies: 1, - consentString: '1YA-' - }); - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('image'); - expect(opts[0].url).to.equal('surl2?a=b&us_privacy=&gdpr=1&gdpr_consent=1YA-'); - }); - }); - - describe('getBidFloor', function () { - it('should return null when getFloor is not a function', () => { - const bid = {getFloor: 2}; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when getFloor doesnt return an object', () => { - const bid = {getFloor: () => 2}; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when floor is not a number', () => { - const bid = { - getFloor: () => ({floor: 'string', currency: 'USD'}) - }; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when currency is not USD', () => { - const bid = { - getFloor: () => ({floor: 5, currency: 'EUR'}) - }; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return floor value when everything is correct', () => { - const bid = { - getFloor: () => ({floor: 5, currency: 'USD'}) - }; - const result = getBidFloor(bid); - expect(result).to.equal(5); - }); - }); -}); diff --git a/test/spec/modules/adkernelAdnBidAdapter_spec.js b/test/spec/modules/adkernelAdnBidAdapter_spec.js deleted file mode 100644 index 2618d5f8d..000000000 --- a/test/spec/modules/adkernelAdnBidAdapter_spec.js +++ /dev/null @@ -1,432 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/adkernelAdnBidAdapter'; -import {config} from 'src/config'; - -describe('AdkernelAdn adapter', function () { - const bid1_pub1 = { - bidder: 'adkernelAdn', - transactionId: 'transact0', - bidderRequestId: 'req0', - auctionId: '5c66da22-426a-4bac-b153-77360bef5337', - bidId: 'bidid_1', - params: { - pubId: 1, - host: 'tag.adkernel.com' - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 200]] - } - }, - adUnitCode: 'ad-unit-1', - }; const bid2_pub1 = { - bidder: 'adkernelAdn', - transactionId: 'transact0', - bidderRequestId: 'req0', - auctionId: '5c66da22-426a-4bac-b153-77360bef5337', - bidId: 'bidid_2', - params: { - pubId: 1 - }, - adUnitCode: 'ad-unit-2', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - }; const bid1_pub2 = { - bidder: 'adkernelAdn', - transactionId: 'transact2', - bidderRequestId: 'req1', - auctionId: '5c66da22-426a-4bac-b153-77360bef5337', - bidId: 'bidid_3', - params: { - pubId: 7, - host: 'dps-test.com' - }, - adUnitCode: 'ad-unit-2', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - } - }; const bid_video1 = { - bidder: 'adkernelAdn', - transactionId: 'transact3', - bidderRequestId: 'req1', - auctionId: '5c66da22-426a-4bac-b153-77360bef5337', - bidId: 'bidid_4', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 300], - mimes: ['video/mp4', 'video/webm'], - api: [1, 2], - protocols: [5, 6] - } - }, - adUnitCode: 'video_wrapper', - params: { - pubId: 7 - } - }; const bid_video2 = { - bidder: 'adkernelAdn', - transactionId: 'transact3', - bidderRequestId: 'req1', - auctionId: '5c66da22-426a-4bac-b153-77360bef5337', - bidId: 'bidid_5', - mediaTypes: { - video: { - playerSize: [1920, 1080], - context: 'instream' - } - }, - adUnitCode: 'video_wrapper2', - params: { - pubId: 7 - } - }; const bid_multiformat = { - bidder: 'adkernelAdn', - transactionId: 'f82c64b8-c602-42a4-9791-4a268f6559ed', - bidderRequestId: 'req-001', - auctionId: 'auc-001', - bidId: 'Bid_01', - mediaTypes: { - banner: {sizes: [[300, 250], [300, 200]]}, - video: {context: 'instream', playerSize: [[640, 480]]} - }, - adUnitCode: 'ad-unit-1', - params: {pubId: 7} - }; - - const response = { - tags: [{ - id: 'ad-unit-1', - impid: '2c5e951baeeadd', - crid: '108_159810', - bid: 5.0, - tag: '', - w: 300, - h: 250, - advertiserId: 777, - advertiserName: 'advertiser', - agencyName: 'agency', - advertiserDomains: ['example.com'], - primaryCatId: 'IAB1-1', - }, { - id: 'ad-unit-2', - impid: '31d798477126c4', - crid: '108_21226', - bid: 2.5, - tag: '', - w: 300, - h: 250, - advertiserId: 777, - advertiserName: 'advertiser', - agencyName: 'agency', - advertiserDomains: ['example.com'], - secondaryCatIds: ['IAB1-4', 'IAB8-16', 'IAB25-5'] - }, { - id: 'video_wrapper', - impid: '57d602ad1c9545', - crid: '108_158802', - bid: 10.0, - vast_url: 'https://vast.com/vast.xml' - }], - syncpages: ['https://dsp.adkernel.com/sync'] - }; const usersyncOnlyResponse = { - syncpages: ['https://dsp.adkernel.com/sync'] - }; - - const defaultBidderRequest = { - bidderCode: 'adkernelAdn', - bids: [], - auctionStart: 1545836987704, - timeout: 3000, - refererInfo: { - page: 'https://example.com/index.html', - reachedTop: true, - numIframes: 0, - stack: ['https://example.com/index.html'] - }, - start: 1545836987707 - }; - - describe('input parameters validation', () => { - it('empty request shouldn\'t generate exception', () => { - expect(spec.isBidRequestValid({ - bidderCode: 'adkernelAdn' - })).to.be.equal(false); - }); - - it('request without pubid should be ignored', () => { - expect(spec.isBidRequestValid({ - bidder: 'adkernelAdn', - params: {}, - placementCode: 'ad-unit-0', - sizes: [[300, 250]] - })).to.be.equal(false); - }); - - it('request with invalid pubid should be ignored', () => { - expect(spec.isBidRequestValid({ - bidder: 'adkernelAdn', - params: { - pubId: 'invalid id' - }, - placementCode: 'ad-unit-0', - sizes: [[300, 250]] - })).to.be.equal(false); - }); - - it('request with totally invalid host should be ignored', () => { - expect(spec.isBidRequestValid({ - bidder: 'adkernelAdn', - params: { - pubId: 1, - host: 1 - }, - placementCode: 'ad-unit-0', - sizes: [[300, 250]] - })).to.be.equal(false); - }); - - it('valid request should be accepted', () => { - expect(spec.isBidRequestValid({ - bidder: 'adkernelAdn', - params: { - pubId: 1, - host: 'network.com' - }, - placementCode: 'ad-unit-0', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 200]] - } - } - })).to.be.equal(true); - }); - }); - - function buildRequest(bidRequests, bidderRequestAugments = {}) { - const fullBidderRequest = Object.assign(defaultBidderRequest, bidderRequestAugments); - fullBidderRequest.auctionId = bidRequests[0].auctionId; - fullBidderRequest.transactionId = bidRequests[0].transactionId; - fullBidderRequest.bidderRequestId = bidRequests[0].bidderRequestId; - fullBidderRequest.bids = bidRequests; - const pbRequests = spec.buildRequests(bidRequests, fullBidderRequest); - const tagRequests = pbRequests.map(r => JSON.parse(r.data)); - return [pbRequests, tagRequests]; - } - - describe('banner request building', function () { - const [_, tagRequests] = buildRequest([bid1_pub1], {ortb2: {source: {tid: 'mock-tid'}}}); - const tagRequest = tagRequests[0]; - - it('should have request id', function () { - expect(tagRequest).to.have.property('id'); - }); - - it('should have transaction id', function () { - expect(tagRequest).to.have.property('tid'); - }); - - it('should have sizes', function () { - expect(tagRequest.imp[0].banner).to.have.property('format'); - expect(tagRequest.imp[0].banner.format).to.be.eql(['300x250', '300x200']); - }); - - it('should have impression id', function () { - expect(tagRequest.imp[0]).to.have.property('id', 'bidid_1'); - }); - - it('should have tagid', function () { - expect(tagRequest.imp[0]).to.have.property('tagid', 'ad-unit-1'); - }); - - it('should create proper site block', function () { - expect(tagRequest.site).to.have.property('page', 'https://example.com/index.html'); - expect(tagRequest.site).to.have.property('secure', 1); - }); - - it('should not have user object', function () { - expect(tagRequest).to.not.have.property('user'); - }); - - it('shouldn\'t contain gdpr nor ccpa information for default request', function () { - const [_, tagRequests] = buildRequest([bid1_pub1]); - expect(tagRequests[0]).to.not.have.property('user'); - }); - - it('should contain gdpr and ccpa information if consent is configured', function () { - const [_, bidRequests] = buildRequest([bid1_pub1], - {gdprConsent: {gdprApplies: true, consentString: 'test-consent-string'}, uspConsent: '1YNN'}); - expect(bidRequests[0]).to.have.property('user'); - expect(bidRequests[0].user).to.have.property('gdpr', 1); - expect(bidRequests[0].user).to.have.property('consent', 'test-consent-string'); - expect(bidRequests[0].user).to.have.property('us_privacy', '1YNN'); - }); - - it('should\'t contain consent string if gdpr isn\'t applied', function () { - const [_, bidRequests] = buildRequest([bid1_pub1], {gdprConsent: {gdprApplies: false}}); - expect(bidRequests[0]).to.have.property('user'); - expect(bidRequests[0].user).to.have.property('gdpr', 0); - expect(bidRequests[0].user).to.not.have.property('consent'); - }); - - it('should\'t contain consent string if gdpr isn\'t applied', function () { - config.setConfig({coppa: true}); - const [_, bidRequests] = buildRequest([bid1_pub1]); - config.resetConfig(); - expect(bidRequests[0]).to.have.property('user'); - expect(bidRequests[0].user).to.have.property('coppa', 1); - }); - - it('should set bidfloor if configured', function() { - const bid = Object.assign({}, bid1_pub1); - bid.getFloor = function() { - return { - currency: 'USD', - floor: 0.145 - } - }; - const [, tagRequests] = buildRequest([bid]); - expect(tagRequests[0].imp[0]).to.have.property('bidfloor', 0.145); - }); - }); - - describe('video request building', () => { - const [_, tagRequests] = buildRequest([bid_video1, bid_video2]); - const tagRequest = tagRequests[0]; - - it('should have video object', () => { - expect(tagRequest.imp[0]).to.have.property('video'); - expect(tagRequest.imp[1]).to.have.property('video'); - }); - - it('should have tagid', () => { - expect(tagRequest.imp[0]).to.have.property('tagid', 'video_wrapper'); - expect(tagRequest.imp[1]).to.have.property('tagid', 'video_wrapper2'); - }); - - it('should have size', () => { - expect(tagRequest.imp[0].video).to.have.property('w', 640); - expect(tagRequest.imp[0].video).to.have.property('h', 300); - expect(tagRequest.imp[1].video).to.have.property('w', 1920); - expect(tagRequest.imp[1].video).to.have.property('h', 1080); - }); - - it('should have video params', () => { - expect(tagRequest.imp[0].video).to.have.property('mimes'); - expect(tagRequest.imp[0].video.mimes).to.be.eql(['video/mp4', 'video/webm']); - expect(tagRequest.imp[0].video).to.have.property('api'); - expect(tagRequest.imp[0].video.api).to.be.eql([1, 2]); - expect(tagRequest.imp[0].video).to.have.property('protocols'); - expect(tagRequest.imp[0].video.protocols).to.be.eql([5, 6]); - }); - }); - - describe('multiformat request building', function () { - const [_, tagRequests] = buildRequest([bid_multiformat]); - - it('should contain single request', function () { - expect(tagRequests).to.have.length(1); - expect(tagRequests[0].imp).to.have.length(1); - }); - - it('should contain banner-only impression', function () { - expect(tagRequests[0].imp).to.have.length(1); - expect(tagRequests[0].imp[0]).to.have.property('banner'); - expect(tagRequests[0].imp[0]).to.not.have.property('video'); - }); - }); - - describe('requests routing', function () { - it('should issue a request for each publisher', function () { - const [pbRequests, tagRequests] = buildRequest([bid1_pub1, bid_video1]); - expect(pbRequests).to.have.length(2); - expect(pbRequests[0].url).to.have.string(`account=${bid1_pub1.params.pubId}`); - expect(pbRequests[1].url).to.have.string(`account=${bid1_pub2.params.pubId}`); - expect(tagRequests[0].imp).to.have.length(1); - expect(tagRequests[1].imp).to.have.length(1); - }); - - it('should issue a request for each host', function () { - const [pbRequests, tagRequests] = buildRequest([bid1_pub1, bid1_pub2]); - expect(pbRequests).to.have.length(2); - expect(pbRequests[0].url).to.have.string('https://tag.adkernel.com/tag'); - expect(pbRequests[1].url).to.have.string(`https://${bid1_pub2.params.host}/tag`); - expect(tagRequests[0].imp).to.have.length(1); - expect(tagRequests[1].imp).to.have.length(1); - }); - }); - - describe('responses processing', function () { - let responses; - - before(function () { - responses = spec.interpretResponse({body: response}); - }); - - it('should parse all responses', function () { - expect(responses).to.have.length(3); - }); - - it('should return fully-initialized bid-response', function () { - const resp = responses[0]; - expect(resp).to.have.property('requestId', '2c5e951baeeadd'); - expect(resp).to.have.property('cpm', 5.0); - expect(resp).to.have.property('width', 300); - expect(resp).to.have.property('height', 250); - expect(resp).to.have.property('creativeId', '108_159810'); - expect(resp).to.have.property('currency'); - expect(resp).to.have.property('ttl'); - expect(resp).to.have.property('mediaType', 'banner'); - expect(resp).to.have.property('ad'); - expect(resp.ad).to.have.string(''); - expect(resp.meta.advertiserId).to.be.eql(777); - expect(resp.meta.advertiserName).to.be.eql('advertiser'); - expect(resp.meta.agencyName).to.be.eql('agency'); - expect(resp.meta.advertiserDomains).to.be.eql(['example.com']); - expect(resp.meta.primaryCatId).to.be.eql('IAB1-1'); - }); - - it('should return fully-initialized video bid-response', function () { - const resp = responses[2]; - expect(resp).to.have.property('requestId', '57d602ad1c9545'); - expect(resp).to.have.property('cpm', 10.0); - expect(resp).to.have.property('creativeId', '108_158802'); - expect(resp).to.have.property('currency'); - expect(resp).to.have.property('ttl'); - expect(resp).to.have.property('mediaType', 'video'); - expect(resp).to.have.property('vastUrl', 'https://vast.com/vast.xml'); - expect(resp).to.not.have.property('ad'); - }); - - it('should perform usersync', function () { - let syncs = spec.getUserSyncs({iframeEnabled: false}, [{body: response}]); - expect(syncs).to.have.length(0); - syncs = spec.getUserSyncs({iframeEnabled: true}, [{body: response}]); - expect(syncs).to.have.length(1); - expect(syncs[0]).to.have.property('type', 'iframe'); - expect(syncs[0]).to.have.property('url', 'https://dsp.adkernel.com/sync'); - }); - - it('should handle user-sync only response', function () { - const [pbRequests, tagRequests] = buildRequest([bid1_pub1]); - const resp = spec.interpretResponse({body: usersyncOnlyResponse}, pbRequests[0]); - expect(resp).to.have.length(0); - }); - - it('shouldn\' fail on empty response', function () { - const syncs = spec.getUserSyncs({iframeEnabled: true}, [{body: ''}]); - expect(syncs).to.have.length(0); - }); - }); - - describe('adapter configuration', () => { - it('should have aliases', () => { - expect(spec.aliases).to.be.an('array'); - }); - }); -}); diff --git a/test/spec/modules/adkernelBidAdapter_spec.js b/test/spec/modules/adkernelBidAdapter_spec.js deleted file mode 100644 index 1e506c8b8..000000000 --- a/test/spec/modules/adkernelBidAdapter_spec.js +++ /dev/null @@ -1,804 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/adkernelBidAdapter'; -import * as utils from 'src/utils'; -import {NATIVE, BANNER, VIDEO} from 'src/mediaTypes'; -import {config} from 'src/config'; -import {parseDomain} from '../../../src/refererDetection.js'; - -describe('Adkernel adapter', function () { - const bid1_zone1 = { - bidder: 'adkernel', - params: {zoneId: 1, host: 'rtb.adkernel.com'}, - adUnitCode: 'ad-unit-1', - bidId: 'Bid_01', - bidderRequestId: 'req-001', - auctionId: 'auc-001', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 200]], - pos: 1 - } - }, - ortb2Imp: { - battr: [6, 7, 9], - pos: 2 - } - }; const bid2_zone2 = { - bidder: 'adkernel', - params: {zoneId: 2, host: 'rtb.adkernel.com'}, - adUnitCode: 'ad-unit-2', - bidId: 'Bid_02', - bidderRequestId: 'req-001', - auctionId: 'auc-001', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - userIdAsEids: [ - { - source: 'crwdcntrl.net', - uids: [ - {atype: 1, id: '97d09fbba28542b7acbb6317c9534945a702b74c5993c352f332cfe83f40cdd9'} - ] - } - ] - }; const bid3_host2 = { - bidder: 'adkernel', - params: {zoneId: 1, host: 'rtb-private.adkernel.com'}, - adUnitCode: 'ad-unit-2', - bidId: 'Bid_02', - bidderRequestId: 'req-001', - auctionId: 'auc-001', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - } - }; const bid_without_zone = { - bidder: 'adkernel', - params: {host: 'rtb-private.adkernel.com'}, - adUnitCode: 'ad-unit-1', - bidId: 'Bid_W', - bidderRequestId: 'req-002', - auctionId: 'auc-002', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - } - }; const bid_without_host = { - bidder: 'adkernel', - params: {zoneId: 1}, - adUnitCode: 'ad-unit-1', - bidId: 'Bid_W', - bidderRequestId: 'req-002', - auctionId: 'auc-002', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - } - }; const bid_with_wrong_zoneId = { - bidder: 'adkernel', - params: {zoneId: 'wrong id', host: 'rtb.adkernel.com'}, - adUnitCode: 'ad-unit-2', - bidId: 'Bid_02', - bidderRequestId: 'req-002', - auctionId: 'auc-002', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - } - }; const bid_video = { - bidder: 'adkernel', - transactionId: '866394b8-5d37-4d49-803e-f1bdb595f73e', - bidId: 'Bid_Video', - bidderRequestId: '18b2a61ea5d9a7', - auctionId: 'de45acf1-9109-4e52-8013-f2b7cf5f6766', - params: { - zoneId: 1, - host: 'rtb.adkernel.com', - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [[640, 480]], - api: [1, 2], - placement: 1, - plcmt: 1, - skip: 1, - pos: 1 - } - }, - adUnitCode: 'ad-unit-1' - }; const bid_multiformat = { - bidder: 'adkernel', - params: {zoneId: 1, host: 'rtb.adkernel.com'}, - mediaTypes: { - banner: {sizes: [[300, 250], [300, 200]]}, - video: {context: 'instream', playerSize: [[640, 480]]} - }, - adUnitCode: 'ad-unit-1', - transactionId: 'f82c64b8-c602-42a4-9791-4a268f6559ed', - bidId: 'Bid_01', - bidderRequestId: 'req-001', - auctionId: 'auc-001' - }; - const bid_native = { - bidder: 'adkernel', - params: {zoneId: 1, host: 'rtb.adkernel.com'}, - mediaTypes: { - native: { - title: { - required: true, - len: 80 - }, - body: { - required: true - }, - body2: { - required: true - }, - icon: { - required: true, - aspect_ratios: [{min_width: 50, min_height: 50}] - }, - image: { - required: true, - sizes: [300, 200] - }, - clickUrl: { - required: true - }, - rating: { - required: false - }, - price: { - required: false - }, - privacyLink: { - required: false - }, - cta: { - required: false - }, - sponsoredBy: { - required: false - }, - displayUrl: { - required: false - } - } - }, - nativeOrtbRequest: { - ver: '1.2', - assets: [ - { - id: 0, required: 1, title: {len: 80} - }, { - id: 1, required: 1, data: {type: 2}}, - { - id: 2, required: 1, data: {type: 10} - }, { - id: 3, required: 1, img: {type: 1, wmin: 50, hmin: 50} - }, { - id: 4, required: 1, img: {type: 3, w: 300, h: 200} - }, { - id: 5, required: 0, data: {type: 3} - }, { - id: 6, required: 0, data: {type: 6} - }, { - id: 7, required: 0, data: {type: 12} - }, { - id: 8, required: 0, data: {type: 1} - }, { - id: 9, required: 0, data: {type: 11} - } - ], - privacy: 1 - }, - adUnitCode: 'ad-unit-1', - transactionId: 'f82c64b8-c602-42a4-9791-4a268f6559ed', - bidId: 'Bid_01', - bidderRequestId: 'req-001', - auctionId: 'auc-001' - }; - - const bannerBidResponse = { - id: 'bid1', - seatbid: [{ - bid: [{ - id: '1', - impid: 'Bid_01', - crid: '100_001', - price: 3.01, - nurl: 'https://rtb.com/win?i=ZjKoPYSFI3Y_0', - adm: '', - w: 300, - h: 250, - dealid: 'deal', - mtype: 1 - }] - }], - ext: { - adk_usersync: [{type: 1, url: 'https://adk.sync.com/sync'}] - } - }; const videoBidResponse = { - id: '47ce4badcf7482', - seatbid: [{ - bid: [{ - id: 'sZSYq5zYMxo_0', - impid: 'Bid_Video', - crid: '100_003', - price: 0.00145, - adid: '158801', - nurl: 'https://rtb.com/win?i=sZSYq5zYMxo_0&f=nurl', - cid: '16855', - mtype: 2 - }] - }], - }; const videoBidResponseWithAdm = { - id: '47ce4badcf7482', - seatbid: [{ - bid: [{ - id: 'sZSYq5zYMxo_0', - impid: 'Bid_Video', - crid: '100_003', - price: 0.00145, - adid: '158801', - adm: '', - nurl: 'https://rtb.com/win?i=sZSYq5zYMxo_0', - cid: '16855', - mtype: 2 - }] - }], - }; - const usersyncOnlyResponse = { - id: 'nobid1', - ext: { - adk_usersync: [{type: 2, url: 'https://adk.sync.com/sync'}] - } - }; const nativeResponse = { - id: '56fbc713-b737-4651-9050-13376aed9818', - seatbid: [{ - bid: [{ - id: 'someid_01', - impid: 'Bid_01', - price: 2.25, - adid: '4', - adm: JSON.stringify({ - native: { - assets: [ - {id: 0, title: {text: 'Title'}}, - {id: 3, data: {value: 'Description'}}, - {id: 4, data: {value: 'Additional description'}}, - {id: 1, img: {url: 'http://rtb.com/thumbnail?i=pTuOlf5KHUo_0&imgt=icon', w: 50, h: 50}}, - {id: 2, img: {url: 'http://rtb.com/thumbnail?i=pTuOlf5KHUo_0', w: 300, h: 200}}, - {id: 5, data: {value: 'Sponsor.com'}}, - {id: 14, data: {value: 'displayurl.com'}} - ], - link: {url: 'http://rtb.com/click?i=pTuOlf5KHUo_0'}, - imptrackers: ['http://rtb.com/win?i=pTuOlf5KHUo_0&f=imp'] - } - }), - adomain: ['displayurl.com'], - cat: ['IAB1-4', 'IAB8-16', 'IAB25-5'], - cid: '1', - crid: '4', - mtype: 4, - ext: { - 'advertiser_id': 777, - 'advertiser_name': 'advertiser', - 'agency_name': 'agency' - } - }] - }], - bidid: 'pTuOlf5KHUo', - cur: 'EUR' - }; - const multiformat_response = { - id: '47ce4badcf7482', - seatbid: [{ - bid: [{ - id: 'sZSYq5zYMxo_0', - impid: 'Bid_01b__mf', - crid: '100_003', - price: 0.00145, - adid: '158801', - adm: '', - nurl: 'https://rtb.com/win?i=sZSYq5zYMxo_0&f=nurl', - cid: '16855', - mtype: 1 - }, { - id: 'sZSYq5zYMxo_1', - impid: 'Bid_01v__mf', - crid: '100_003', - price: 0.25, - adid: '158801', - nurl: 'https://rtb.com/win?i=sZSYq5zYMxo_1&f=nurl', - cid: '16855', - mtype: 2 - }] - }], - bidid: 'pTuOlf5KHUo', - cur: 'USD' - }; - - var sandbox; - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - - afterEach(function () { - sandbox.restore(); - config.resetConfig(); - }); - - function buildBidderRequest(url = 'https://example.com/index.html', params = {}) { - return Object.assign({}, params, {refererInfo: {page: url, domain: parseDomain(url), reachedTop: true}, timeout: 3000, bidderCode: 'adkernel'}); - } - const DEFAULT_BIDDER_REQUEST = buildBidderRequest(); - - function buildRequest(bidRequests, bidderRequest = DEFAULT_BIDDER_REQUEST, dnt = true) { - const dntmock = sandbox.stub(utils, 'getDNT').callsFake(() => dnt); - bidderRequest.bids = bidRequests; - const pbRequests = spec.buildRequests(bidRequests, bidderRequest); - dntmock.restore(); - const rtbRequests = pbRequests.map(r => JSON.parse(r.data)); - return [pbRequests, rtbRequests]; - } - - describe('input parameters validation', function () { - it('empty request shouldn\'t generate exception', function () { - expect(spec.isBidRequestValid({ - bidderCode: 'adkernel' - })).to.be.equal(false); - }); - - it('request without zone shouldn\'t issue a request', function () { - expect(spec.isBidRequestValid(bid_without_zone)).to.be.equal(false); - }); - - it('request without host shouldn\'t issue a request', function () { - expect(spec.isBidRequestValid(bid_without_host)).to.be.equal(false); - }); - - it('empty request shouldn\'t generate exception', function () { - expect(spec.isBidRequestValid(bid_with_wrong_zoneId)).to.be.equal(false); - }); - - it('valid native requests should pass', () => { - expect(spec.isBidRequestValid(bid_native)).to.be.equal(true); - }) - }); - - describe('banner request building', function () { - let bidRequest, bidRequests, _; - - before(function () { - [_, bidRequests] = buildRequest([bid1_zone1]); - bidRequest = bidRequests[0]; - }); - - it('should be a first-price auction', function () { - expect(bidRequest).to.have.property('at', 1); - }); - - it('should have banner object', function () { - expect(bidRequest.imp[0]).to.have.property('banner'); - }); - - it('should have id', function () { - expect(bidRequest.imp[0]).to.have.property('id'); - expect(bidRequest.imp[0].id).to.be.eql('Bid_01'); - }); - - it('should have w/h', function () { - expect(bidRequest.imp[0].banner).to.have.property('format'); - expect(bidRequest.imp[0].banner.format).to.be.eql([{w: 300, h: 250}, {w: 300, h: 200}]); - }); - - it('should respect secure connection', function () { - expect(bidRequest.imp[0]).to.have.property('secure', 1); - }); - - it('should have tagid', function () { - expect(bidRequest.imp[0]).to.have.property('tagid', 'ad-unit-1'); - }); - - it('should create proper site block', function () { - expect(bidRequest.site).to.have.property('domain', 'example.com'); - expect(bidRequest.site).to.have.property('page', 'https://example.com/index.html'); - }); - - it('should fill device with caller macro', function () { - expect(bidRequest).to.have.property('device'); - expect(bidRequest.device).to.have.property('ip', 'caller'); - expect(bidRequest.device).to.have.property('ipv6', 'caller'); - expect(bidRequest.device).to.have.property('ua', 'caller'); - expect(bidRequest.device).to.have.property('dnt', 1); - }); - - it('should copy FPD to imp.banner', function() { - expect(bidRequest.imp[0].banner).to.have.property('battr'); - expect(bidRequest.imp[0].banner.battr).to.be.eql([6, 7, 9]); - }); - - it('should respect mediatypes attributes over FPD', function() { - expect(bidRequest.imp[0].banner).to.have.property('pos'); - expect(bidRequest.imp[0].banner.pos).to.be.eql(1); - }); - - it('shouldn\'t contain gdpr nor ccpa information for default request', function () { - const [_, bidRequests] = buildRequest([bid1_zone1]); - expect(bidRequests[0]).to.not.have.property('regs'); - expect(bidRequests[0]).to.not.have.property('user'); - }); - - it('should contain gdpr-related information if consent is configured', function () { - const [_, bidRequests] = buildRequest([bid1_zone1], - buildBidderRequest('https://example.com/index.html', { - gdprConsent: {gdprApplies: true, consentString: 'test-consent-string', vendorData: {}}, - uspConsent: '1YNN', - gppConsent: {gppString: 'DBABMA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA', applicableSections: [2]}} - )); - const bidRequest = bidRequests[0]; - expect(bidRequest).to.have.property('regs'); - expect(bidRequest.regs.ext).to.be.eql({'gdpr': 1, 'us_privacy': '1YNN'}); - expect(bidRequest.regs.gpp).to.be.eql('DBABMA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA'); - expect(bidRequest.regs.gpp_sid).to.be.eql([2]); - expect(bidRequest).to.have.property('user'); - expect(bidRequest.user.ext).to.be.eql({'consent': 'test-consent-string'}); - }); - - it('should contain coppa if configured', function () { - config.setConfig({coppa: true}); - const [_, bidRequests] = buildRequest([bid1_zone1]); - const bidRequest = bidRequests[0]; - expect(bidRequest).to.have.property('regs'); - expect(bidRequest.regs).to.have.property('coppa', 1); - }); - - it('should\'t contain consent string if gdpr isn\'t applied', function () { - const [_, bidRequests] = buildRequest([bid1_zone1], buildBidderRequest('https://example.com/index.html', {gdprConsent: {gdprApplies: false}})); - const bidRequest = bidRequests[0]; - expect(bidRequest).to.have.property('regs'); - expect(bidRequest.regs.ext).to.be.eql({'gdpr': 0}); - expect(bidRequest).to.not.have.property('user'); - }); - - it('should\'t pass dnt if state is unknown', function () { - const [_, bidRequests] = buildRequest([bid1_zone1], DEFAULT_BIDDER_REQUEST, false); - expect(bidRequests[0].device).to.not.have.property('dnt'); - }); - - it('should forward default bidder timeout', function() { - const [_, bidRequests] = buildRequest([bid1_zone1]); - expect(bidRequests[0]).to.have.property('tmax', 3000); - }); - - it('should set bidfloor if configured', function() { - const bid = Object.assign({}, bid1_zone1); - bid.getFloor = function() { - return { - currency: 'USD', - floor: 0.145 - } - }; - const [_, bidRequests] = buildRequest([bid]); - expect(bidRequests[0].imp[0]).to.have.property('bidfloor', 0.145); - }); - - it('should forward user ids if available', function() { - const bid = Object.assign({}, bid2_zone2); - const [_, bidRequests] = buildRequest([bid]); - expect(bidRequests[0]).to.have.property('user'); - expect(bidRequests[0].user).to.have.property('ext'); - expect(bidRequests[0].user.ext).to.have.property('eids'); - expect(bidRequests[0].user.ext.eids).to.be.an('array').that.is.not.empty; - expect(bidRequests[0].user.ext.eids[0]).to.have.property('source'); - expect(bidRequests[0].user.ext.eids[0]).to.have.property('uids'); - }); - }); - - describe('video request building', function () { - let _, bidRequests; - before(function () { - [_, bidRequests] = buildRequest([bid_video]); - }); - - it('should have video object', function () { - expect(bidRequests[0].imp[0]).to.have.property('video'); - }); - - it('should have h/w', function () { - expect(bidRequests[0].imp[0].video).to.have.property('w', 640); - expect(bidRequests[0].imp[0].video).to.have.property('h', 480); - }); - - it('should have tagid', function () { - expect(bidRequests[0].imp[0]).to.have.property('tagid', 'ad-unit-1'); - }); - - it('should have openrtb video impression parameters', function() { - const video = bidRequests[0].imp[0].video; - expect(video).to.have.property('api'); - expect(video.api).to.be.eql([1, 2]); - expect(video.placement).to.be.eql(1); - expect(video.plcmt).to.be.eql(1); - expect(video.skip).to.be.eql(1); - expect(video.pos).to.be.eql(1); - }); - }); - - describe('multiformat request building', function () { - let pbRequests, bidRequests; - before(() => { - [pbRequests, bidRequests] = buildRequest([bid_multiformat]); - }); - it('should contain single request', function () { - expect(bidRequests).to.have.length(1); - }); - it('should contain both impression', function () { - expect(bidRequests[0].imp).to.have.length(2); - expect(bidRequests[0].imp[0]).to.have.property('banner'); - expect(bidRequests[0].imp[1]).to.have.property('video'); - // check that splitted imps do not share same impid - expect(bidRequests[0].imp[0].id).to.be.not.eql('Bid_01'); - expect(bidRequests[0].imp[1].id).to.be.not.eql('Bid_01'); - expect(bidRequests[0].imp[1].id).to.be.not.eql(bidRequests[0].imp[0].id); - }); - it('should collect ads back to same requestId', function() { - const bids = spec.interpretResponse({body: multiformat_response}, pbRequests[0]); - expect(bids).to.have.length(2); - expect(bids[0].requestId).to.be.eql('Bid_01'); - expect(bids[0].mediaType).to.be.eql('banner'); - expect(bids[1].requestId).to.be.eql('Bid_01'); - expect(bids[1].mediaType).to.be.eql('video'); - }); - }); - - describe('requests routing', function () { - it('should issue a request for each host', function () { - const [pbRequests, _] = buildRequest([bid1_zone1, bid3_host2]); - expect(pbRequests).to.have.length(2); - expect(pbRequests[0].url).to.have.string(`https://${bid1_zone1.params.host}/`); - expect(pbRequests[1].url).to.have.string(`https://${bid3_host2.params.host}/`); - }); - - it('should issue a request for each zone', function () { - const [pbRequests, _] = buildRequest([bid1_zone1, bid2_zone2]); - expect(pbRequests).to.have.length(2); - expect(pbRequests[0].url).to.include(`zone=${bid1_zone1.params.zoneId}`); - expect(pbRequests[1].url).to.include(`zone=${bid2_zone2.params.zoneId}`); - }); - }); - - describe('User sync request signals', function() { - it('should respect syncEnabled option', function() { - config.setConfig({ - userSync: { - syncEnabled: false, - filterSettings: { - all: { - bidders: '*', - filter: 'include' - } - } - } - }); - const [pbRequests, bidRequests] = buildRequest([bid1_zone1]); - expect(bidRequests).to.have.length(1); - expect(bidRequests[0]).to.not.have.property('ext'); - }); - - it('should respect all config node', function() { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - all: { - bidders: '*', - filter: 'include' - } - } - } - }); - const [pbRequests, bidRequests] = buildRequest([bid1_zone1]); - expect(bidRequests).to.have.length(1); - expect(bidRequests[0].ext).to.have.property('adk_usersync', 1); - }); - - it('should respect exclude filter', function() { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - image: { - bidders: '*', - filter: 'include' - }, - iframe: { - bidders: ['adkernel'], - filter: 'exclude' - } - } - } - }); - const [pbRequests, bidRequests] = buildRequest([bid1_zone1]); - expect(bidRequests).to.have.length(1); - expect(bidRequests[0].ext).to.have.property('adk_usersync', 2); - }); - - it('should respect total exclusion', function() { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - image: { - bidders: ['adkernel'], - filter: 'exclude' - }, - iframe: { - bidders: ['adkernel'], - filter: 'exclude' - } - } - } - }); - const [pbRequests, bidRequests] = buildRequest([bid1_zone1]); - expect(bidRequests).to.have.length(1); - expect(bidRequests[0]).to.not.have.property('ext'); - }); - }); - - describe('responses processing', function () { - it('should return fully-initialized banner bid-response', function () { - const [pbRequests, _] = buildRequest([bid1_zone1]); - const resp = spec.interpretResponse({body: bannerBidResponse}, pbRequests[0])[0]; - expect(resp).to.have.property('requestId', 'Bid_01'); - expect(resp).to.have.property('cpm', 3.01); - expect(resp).to.have.property('width', 300); - expect(resp).to.have.property('height', 250); - expect(resp).to.have.property('creativeId', '100_001'); - expect(resp).to.have.property('currency'); - expect(resp).to.have.property('ttl'); - expect(resp).to.have.property('mediaType', BANNER); - expect(resp).to.have.property('ad'); - expect(resp).to.have.property('dealId', 'deal'); - expect(resp.ad).to.have.string(''); - expect(resp).to.not.have.property('nurl'); - }); - - it('should return fully-initialized video bid-response', function () { - const [pbRequests, _] = buildRequest([bid_video]); - const resp = spec.interpretResponse({body: videoBidResponse}, pbRequests[0])[0]; - expect(resp).to.have.property('requestId', 'Bid_Video'); - expect(resp.mediaType).to.equal(VIDEO); - expect(resp.cpm).to.equal(0.00145); - expect(resp.vastUrl).to.equal('https://rtb.com/win?i=sZSYq5zYMxo_0&f=nurl'); - expect(resp.width).to.equal(640); - expect(resp.height).to.equal(480); - }); - - it('should support vast xml in adm', function () { - const [pbRequests, _] = buildRequest([bid_video]); - const resp = spec.interpretResponse({body: videoBidResponseWithAdm}, pbRequests[0])[0]; - expect(resp).to.have.property('requestId', 'Bid_Video'); - expect(resp.mediaType).to.equal(VIDEO); - expect(resp.cpm).to.equal(0.00145); - expect(resp.vastXml).to.equal(''); - expect(resp.nurl).to.equal('https://rtb.com/win?i=sZSYq5zYMxo_0'); - expect(resp.width).to.equal(640); - expect(resp.height).to.equal(480); - }); - - it('should add nurl as pixel for banner response', function () { - const [pbRequests, _] = buildRequest([bid1_zone1]); - const resp = spec.interpretResponse({body: bannerBidResponse}, pbRequests[0])[0]; - const expectedNurl = bannerBidResponse.seatbid[0].bid[0].nurl + '&px=1'; - expect(resp.ad).to.have.string(expectedNurl); - }); - - it('should handle bidresponse with user-sync only', function () { - const [pbRequests, _] = buildRequest([bid1_zone1]); - const resp = spec.interpretResponse({body: usersyncOnlyResponse}, pbRequests[0]); - expect(resp).to.have.length(0); - }); - - it('should perform usersync', function () { - let syncs = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, []); - expect(syncs).to.have.length(0); - syncs = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: false}, [{body: bannerBidResponse}]); - expect(syncs).to.have.length(0); - syncs = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, [{body: bannerBidResponse}]); - expect(syncs).to.have.length(1); - expect(syncs[0]).to.have.property('type', 'iframe'); - expect(syncs[0]).to.have.property('url', 'https://adk.sync.com/sync'); - syncs = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [{body: usersyncOnlyResponse}]); - expect(syncs).to.have.length(1); - expect(syncs[0]).to.have.property('type', 'image'); - expect(syncs[0]).to.have.property('url', 'https://adk.sync.com/sync'); - }); - }); - - describe('adapter configuration', () => { - it('should have aliases', () => { - expect(spec.aliases).to.be.an('array').that.is.not.empty; - }); - }); - - describe('native support', () => { - let _, bidRequests; - before(function () { - [_, bidRequests] = buildRequest([bid_native]); - }); - - it('native request building', () => { - expect(bidRequests[0].imp).to.have.length(1); - expect(bidRequests[0].imp[0]).to.have.property('native'); - expect(bidRequests[0].imp[0].native).to.have.property('request'); - const request = JSON.parse(bidRequests[0].imp[0].native.request); - expect(request).to.have.property('ver', '1.2'); - expect(request.assets).to.have.length(10); - expect(request.assets[0]).to.be.eql({id: 0, required: 1, title: {len: 80}}); - expect(request.assets[1]).to.be.eql({id: 1, required: 1, data: {type: 2}}); - expect(request.assets[2]).to.be.eql({id: 2, required: 1, data: {type: 10}}); - expect(request.assets[3]).to.be.eql({id: 3, required: 1, img: {wmin: 50, hmin: 50, type: 1}}); - expect(request.assets[4]).to.be.eql({id: 4, required: 1, img: {w: 300, h: 200, type: 3}}); - expect(request.assets[5]).to.be.eql({id: 5, required: 0, data: {type: 3}}); - expect(request.assets[6]).to.be.eql({id: 6, required: 0, data: {type: 6}}); - expect(request.assets[7]).to.be.eql({id: 7, required: 0, data: {type: 12}}); - expect(request.assets[8]).to.be.eql({id: 8, required: 0, data: {type: 1}}); - expect(request.assets[9]).to.be.eql({id: 9, required: 0, data: {type: 11}}); - }); - - it('native response processing', () => { - const [pbRequests, _] = buildRequest([bid_native]); - const resp = spec.interpretResponse({body: nativeResponse}, pbRequests[0])[0]; - expect(resp).to.have.property('requestId', 'Bid_01'); - expect(resp).to.have.property('cpm', 2.25); - expect(resp).to.have.property('currency', 'EUR'); - expect(resp).to.have.property('meta'); - expect(resp.meta.advertiserId).to.be.eql(777); - expect(resp.meta.advertiserName).to.be.eql('advertiser'); - expect(resp.meta.agencyName).to.be.eql('agency'); - expect(resp.meta.advertiserDomains).to.be.eql(['displayurl.com']); - expect(resp.meta.secondaryCatIds).to.be.eql(['IAB1-4', 'IAB8-16', 'IAB25-5']); - expect(resp).to.have.property('mediaType', NATIVE); - expect(resp).to.have.property('native'); - expect(resp.native).to.have.property('ortb'); - - expect(resp.native.ortb).to.be.eql({ - assets: [ - {id: 0, title: {text: 'Title'}}, - {id: 3, data: {value: 'Description'}}, - {id: 4, data: {value: 'Additional description'}}, - {id: 1, img: {url: 'http://rtb.com/thumbnail?i=pTuOlf5KHUo_0&imgt=icon', w: 50, h: 50}}, - {id: 2, img: {url: 'http://rtb.com/thumbnail?i=pTuOlf5KHUo_0', w: 300, h: 200}}, - {id: 5, data: {value: 'Sponsor.com'}}, - {id: 14, data: {value: 'displayurl.com'}} - ], - link: {url: 'http://rtb.com/click?i=pTuOlf5KHUo_0'}, - imptrackers: ['http://rtb.com/win?i=pTuOlf5KHUo_0&f=imp'] - }); - }); - }); - - describe('onBidWon', () => { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - it('should trigger pixel for nurl', () => { - const [pbRequests, _] = buildRequest([bid_video]); - const bid = spec.interpretResponse({body: videoBidResponseWithAdm}, pbRequests[0])[0]; - spec.onBidWon(bid); - expect(utils.triggerPixel.callCount).to.equal(1); - }); - }); -}); diff --git a/test/spec/modules/adlaneRtdProvider_spec.js b/test/spec/modules/adlaneRtdProvider_spec.js deleted file mode 100644 index 43f7790ce..000000000 --- a/test/spec/modules/adlaneRtdProvider_spec.js +++ /dev/null @@ -1,264 +0,0 @@ -import { expect } from 'chai'; -import sinon from 'sinon'; -import { - getAgeVerification, - getAgeVerificationByLocalStorage, - setAgeVerificationConfig, - isAdlCmpAvailable, - adlaneSubmodule -} from '../../../modules/adlaneRtdProvider.js'; -import * as utils from 'src/utils.js'; -import * as storageManager from 'src/storageManager.js'; -import { config } from 'src/config.js'; -import {init} from 'modules/rtdModule' - -describe('adlane Module', () => { - let sandbox; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should have correct module name', () => { - expect(adlaneSubmodule.name).to.equal('adlane'); - }); - - describe('adlaneRtdProvider', () => { - it('should be correctly exported and registered', () => { - expect(adlaneSubmodule).to.be.an('object'); - expect(adlaneSubmodule.name).to.equal('adlane'); - expect(adlaneSubmodule.init).to.be.a('function'); - expect(adlaneSubmodule.getBidRequestData).to.be.a('function'); - }); - - it('should be registered in the RTD module', () => { - const getModuleStub = sinon.stub(config, 'getConfig').callsFake((key) => { - const conf = { - realTimeData: { - auctionDelay: 100, - dataProviders: [{ - name: 'adlane', - waitForIt: true - }] - } - }; - - return conf[key]; - }); - - init(config); - - const rtdConfig = config.getConfig('realTimeData'); - - expect(rtdConfig).to.be.an('object'); - expect(rtdConfig.dataProviders).to.be.an('array'); - - const adlaneProvider = rtdConfig.dataProviders.find(provider => provider.name === 'adlane'); - - expect(adlaneProvider).to.exist; - expect(adlaneProvider.waitForIt).to.be.true; - - getModuleStub.restore(); - }); - }); - - describe('isAdlCmpAvailable', () => { - it('should return true if AdlCmp and getAgeVerification function are available', () => { - const fakeWin = { AdlCmp: { getAgeVerification: () => ({}) } }; - - expect(isAdlCmpAvailable(fakeWin)).to.be.true; - }); - - it('should return false if AdlCmp is missing', () => { - const fakeWin = {}; - - expect(isAdlCmpAvailable(fakeWin)).to.be.false; - }); - - it('should return false if getAgeVerification is not a function', () => { - const fakeWin = { AdlCmp: { getAgeVerification: 'notAFunction' } }; - - expect(isAdlCmpAvailable(fakeWin)).to.be.false; - }); - }); - - describe('getAgeVerificationByLocalStorage', () => { - it('should return parsed ageVerification from localStorage if valid', () => { - const mockData = { - status: 'accepted', - id: '123456789123456789', - decisionDate: '2011-10-05T14:48:00.000Z' - }; - const storage = { - getDataFromLocalStorage: () => JSON.stringify(mockData) - }; - const result = getAgeVerificationByLocalStorage(storage); - - expect(result).to.deep.equal({ - id: '123456789123456789', - status: 'accepted', - decisionDate: '2011-10-05T14:48:00.000Z' - }); - }); - - it('should return null if data is malformed JSON', () => { - const storage = { - getDataFromLocalStorage: () => '{invalid:' - }; - const logErrorStub = sandbox.stub(utils, 'logError'); - const result = getAgeVerificationByLocalStorage(storage); - - expect(result).to.be.null; - expect(logErrorStub.calledOnce).to.be.true; - }); - - it('should return null if localStorage is empty', () => { - const storage = { - getDataFromLocalStorage: () => null - }; - - expect(getAgeVerificationByLocalStorage(storage)).to.be.null; - }); - }); - - describe('getAgeVerification', () => { - it('should get verification data from AdlCmp if available', () => { - const mockAgeVerification = { - status: 'accepted', - id: '123456789123456789', - decisionDate: '2011-10-05T14:48:00.000Z' - } - const resultAgeVerification = { - id: '123456789123456789', - status: 'accepted', - decisionDate: '2011-10-05T14:48:00.000Z' - } - const win = { - AdlCmp: { - getAgeVerification: () => mockAgeVerification - } - }; - const storage = {}; - const cleanStub = sandbox.stub(utils, 'cleanObj').returns(resultAgeVerification); - const result = getAgeVerification(win, storage); - - expect(cleanStub.calledOnce).to.be.true; - expect(result).to.deep.equal(resultAgeVerification); - }); - - it('should fallback to localStorage if AdlCmp is unavailable', () => { - const win = {}; - const storage = { - getDataFromLocalStorage: () => - JSON.stringify({ - status: 'declined', - id: '123456789123456789', - decisionDate: '2011-10-05T14:48:00.000Z' - }) - }; - const cleanStub = sandbox.stub(utils, 'cleanObj').callsFake((o) => o); - const logInfoStub = sandbox.stub(utils, 'logInfo'); - const result = getAgeVerification(win, storage); - - expect(result.status).to.equal('declined'); - expect(logInfoStub.calledOnce).to.be.true; - }); - }); - - describe('setAgeVerificationConfig', () => { - it('should merge config with provided ageVerification', () => { - const mergeStub = sandbox.stub(utils, 'mergeDeep'); - const ageVerification = { id: '123456789123456789', status: 'accepted', decisionDate: '2011-10-05T14:48:00.000Z' }; - const config = { ortb2Fragments: { global: {} } }; - - setAgeVerificationConfig(config, ageVerification); - expect(mergeStub.calledOnce).to.be.true; - const expectedArg = { - regs: { ext: { age_verification: ageVerification } } - }; - - expect(mergeStub.calledWith(config.ortb2Fragments.global, expectedArg)).to.be.true; - }); - - it('should log error if mergeDeep throws', () => { - sandbox.stub(utils, 'mergeDeep').throws(new Error('merge fail')); - const logStub = sandbox.stub(utils, 'logError'); - const config = { ortb2Fragments: { global: {} } }; - - setAgeVerificationConfig(config, { status: 'accepted' }); - expect(logStub.calledOnce).to.be.true; - }); - }); - - describe('adlaneSubmodule', () => { - it('should init with AdlCmp present', () => { - const winStub = sandbox.stub(utils, 'getWindowTop').returns({ - AdlCmp: { getAgeVerification: () => ({ status: 'accepted' }) } - }); - - expect(adlaneSubmodule.init()).to.be.true; - }); - - it('should init with localStorage fallback', () => { - const winStub = sandbox.stub(utils, 'getWindowTop').returns({}); - const storage = { - hasLocalStorage: () => true, - getDataFromLocalStorage: () => JSON.stringify({ status: 'accepted' }) - }; - sandbox.stub(storageManager, 'getStorageManager').returns(storage); - - expect(adlaneSubmodule.init()).to.be.true; - }); - - it('should log warn if init fails', () => { - const winStub = sandbox.stub(utils, 'getWindowTop').returns({}); - const storage = { - hasLocalStorage: () => false, - getDataFromLocalStorage: () => null - }; - sandbox.stub(storageManager, 'getStorageManager').returns(storage); - const logStub = sandbox.stub(utils, 'logWarn'); - - expect(adlaneSubmodule.init()).to.be.false; - expect(logStub.calledOnce).to.be.true; - }); - - it('should call setAgeVerificationConfig in getBidRequestData if valid', (done) => { - const ageVerification = { id: '123456789123456789', status: 'accepted', decisionDate: '2011-10-05T14:48:00.000Z' }; - const cleanStub = sandbox.stub(utils, 'cleanObj').returns(ageVerification); - sandbox.stub(utils, 'getWindowTop').returns({ - AdlCmp: { - getAgeVerification: () => ageVerification - } - }); - const setStub = sandbox.stub(utils, 'mergeDeep'); - const reqBidsConfigObj = { ortb2Fragments: { global: {} } }; - - adlaneSubmodule.getBidRequestData(reqBidsConfigObj, () => { - expect(setStub.calledOnce).to.be.true; - done(); - }); - }); - - it('should log error in getBidRequestData if something fails', (done) => { - sandbox.stub(utils, 'getWindowTop').returns({ - AdlCmp: { - getAgeVerification: () => { - throw new Error('Test error'); - } - } - }); - const logStub = sandbox.stub(utils, 'logError'); - const reqBidsConfigObj = { ortb2Fragments: { global: {} } }; - - adlaneSubmodule.getBidRequestData(reqBidsConfigObj, () => { - expect(logStub.calledOnce).to.be.true; - done(); - }); - }); - }); -}); diff --git a/test/spec/modules/adlooxAnalyticsAdapter_spec.js b/test/spec/modules/adlooxAnalyticsAdapter_spec.js deleted file mode 100644 index ede92f593..000000000 --- a/test/spec/modules/adlooxAnalyticsAdapter_spec.js +++ /dev/null @@ -1,284 +0,0 @@ -import adapterManager from 'src/adapterManager.js'; -import analyticsAdapter, { command as analyticsCommand, COMMAND } from 'modules/adlooxAnalyticsAdapter.js'; -import { AUCTION_COMPLETED } from 'src/auction.js'; -import { expect } from 'chai'; -import * as events from 'src/events.js'; -import { EVENTS } from 'src/constants.js'; -import * as utils from 'src/utils.js'; -import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; - -const analyticsAdapterName = 'adloox'; - -describe('Adloox Analytics Adapter', function () { - let sandbox; - - const esplode = 'esplode'; - - const bid = { - bidder: 'dummy', - adUnitCode: 'ad-slot-1', - mediaType: 'display' - }; - - const auctionDetails = { - auctionStatus: AUCTION_COMPLETED, - bidsReceived: [ - bid - ] - }; - - const analyticsOptions = { - js: 'https://j.adlooxtracking.com/ads/js/tfav_adl_%%clientid%%.js', - client: 'adlooxtest', - clientid: 127, - platformid: 0, - tagid: 0, - params: { - dummy1: '%%client%%', - dummy2: '%%pbadslot%%', - dummy3: function(bid) { throw new Error(esplode) } - } - }; - - adapterManager.registerAnalyticsAdapter({ - code: analyticsAdapterName, - adapter: analyticsAdapter - }); - describe('enableAnalytics', function () { - afterEach(function () { - analyticsAdapter.disableAnalytics(); - expect(analyticsAdapter.context).is.null; - }); - - describe('invalid options', function () { - it('should require options', function (done) { - adapterManager.enableAnalytics({ - provider: analyticsAdapterName - }); - expect(analyticsAdapter.context).is.null; - - done(); - }); - - it('should reject non-string options.js', function (done) { - const analyticsOptionsLocal = utils.deepClone(analyticsOptions); - analyticsOptionsLocal.js = function () { }; - - adapterManager.enableAnalytics({ - provider: analyticsAdapterName, - options: analyticsOptionsLocal - }); - expect(analyticsAdapter.context).is.null; - - done(); - }); - - it('should accept subdomains of adlooxtracking.com for options.js', function (done) { - const analyticsOptionsLocal = utils.deepClone(analyticsOptions); - analyticsOptionsLocal.js = 'https://test.adlooxtracking.com/test.js'; - - adapterManager.enableAnalytics({ - provider: analyticsAdapterName, - options: analyticsOptionsLocal - }); - expect(analyticsAdapter.context).is.not.null; - - done(); - }); - - it('should reject non-subdomains of adlooxtracking.com for options.js', function (done) { - const analyticsOptionsLocal = utils.deepClone(analyticsOptions); - analyticsOptionsLocal.js = 'https://example.com/test.js'; - - adapterManager.enableAnalytics({ - provider: analyticsAdapterName, - options: analyticsOptionsLocal - }); - expect(analyticsAdapter.context).is.null; - - done(); - }); - - it('should reject non-function options.toselector', function (done) { - const analyticsOptionsLocal = utils.deepClone(analyticsOptions); - analyticsOptionsLocal.toselector = esplode; - - adapterManager.enableAnalytics({ - provider: analyticsAdapterName, - options: analyticsOptionsLocal - }); - expect(analyticsAdapter.context).is.null; - - done(); - }); - - [ 'client', 'clientid', 'platformid', 'tagid' ].forEach(function (o) { - it('should require options.' + o, function (done) { - const analyticsOptionsLocal = utils.deepClone(analyticsOptions); - delete analyticsOptionsLocal[o]; - - adapterManager.enableAnalytics({ - provider: analyticsAdapterName, - options: analyticsOptionsLocal - }); - expect(analyticsAdapter.context).is.null; - - done(); - }); - }); - - it('should reject non-object options.params', function (done) { - const analyticsOptionsLocal = utils.deepClone(analyticsOptions); - analyticsOptionsLocal.params = esplode; - - adapterManager.enableAnalytics({ - provider: analyticsAdapterName, - options: analyticsOptionsLocal - }); - expect(analyticsAdapter.context).is.null; - - done(); - }); - }); - }); - - describe('process', function () { - beforeEach(function() { - sandbox = sinon.createSandbox(); - - sandbox.stub(events, 'getEvents').returns([]); - - adapterManager.enableAnalytics({ - provider: analyticsAdapterName, - options: utils.deepClone(analyticsOptions) - }); - - expect(analyticsAdapter.context).is.not.null; - }); - - afterEach(function () { - analyticsAdapter.disableAnalytics(); - expect(analyticsAdapter.context).is.null; - - sandbox.restore(); - sandbox = undefined; - }); - - describe('event', function () { - it('should preload the script on AUCTION_END only once', function (done) { - const insertElementStub = sandbox.stub(utils, 'insertElement'); - - const uri = utils.parseUrl(analyticsAdapter.url(analyticsOptions.js)); - const isLinkPreloadAsScript = function(arg) { - const href_uri = utils.parseUrl(arg.href); // IE11 requires normalisation (hostname always includes port) - return arg.tagName === 'LINK' && arg.getAttribute('rel') === 'preload' && arg.getAttribute('as') === 'script' && href_uri.href === uri.href; - }; - - events.emit(EVENTS.AUCTION_END, auctionDetails); - expect(insertElementStub.calledWith(sinon.match(isLinkPreloadAsScript))).to.true; - - events.emit(EVENTS.AUCTION_END, auctionDetails); - expect(insertElementStub.callCount).to.equal(1); - - done(); - }); - - it('should inject verification JS on BID_WON', function (done) { - const url = analyticsAdapter.url(`${analyticsOptions.js}#`); - - const parent = document.createElement('div'); - - const slot = document.createElement('div'); - slot.id = bid.adUnitCode; - parent.appendChild(slot); - - const dummy = document.createElement('div'); - parent.appendChild(dummy); - - const querySelectorStub = sandbox.stub(document, 'querySelector'); - querySelectorStub.withArgs(`#${bid.adUnitCode}`).returns(slot); - - events.emit(EVENTS.BID_WON, bid); - - const [urlInserted, _, moduleCode] = loadExternalScriptStub.getCall(0).args; - - expect(urlInserted.substr(0, url.length)).to.equal(url); - expect(moduleCode).to.equal(analyticsAdapterName); - expect(/[#&]creatype=2(&|$)/.test(urlInserted)).is.true; // prebid 'display' -> adloox '2' - expect(new RegExp('[#&]dummy3=' + encodeURIComponent('ERROR: ' + esplode) + '(&|$)').test(urlInserted)).is.true; - - done(); - }); - - it('should not inject verification JS on BID_WON when handled via Ad Server module', function (done) { - const bidIgnore = utils.deepClone(bid); - utils.deepSetValue(bidIgnore, 'ext.adloox.video.adserver', true); - - const parent = document.createElement('div'); - - const slot = document.createElement('div'); - slot.id = bidIgnore.adUnitCode; - parent.appendChild(slot); - - const script = document.createElement('script'); - const createElementStub = sandbox.stub(document, 'createElement'); - createElementStub.withArgs('script').returns(script); - - const querySelectorStub = sandbox.stub(document, 'querySelector'); - querySelectorStub.withArgs(`#${bid.adUnitCode}`).returns(slot); - - events.emit(EVENTS.BID_WON, bidIgnore); - - expect(parent.querySelector('script')).is.null; - - done(); - }); - }); - - describe('command', function () { - it('should return config', function (done) { - const expected = utils.deepClone(analyticsOptions); - delete expected.js; - delete expected.toselector; - delete expected.params; - - analyticsCommand(COMMAND.CONFIG, null, function (response) { - expect(utils.deepEqual(response, expected)).is.true; - - done(); - }); - }); - - it('should return expanded URL', function (done) { - const data = { - url: 'https://example.com?', - args: [ - [ 'client', '%%client%%' ] - ], - bid: bid, - ids: true - }; - const expected = `${data.url}${data.args[0][0]}=${analyticsOptions.client}`; - - analyticsCommand(COMMAND.URL, data, function (response) { - expect(response.substr(0, expected.length)).is.equal(expected); - - done(); - }); - }); - - it('should inject tracking event', function (done) { - const data = { - eventType: EVENTS.BID_WON, - args: bid - }; - - analyticsCommand(COMMAND.TRACK, data, function (response) { - expect(response).is.undefined; - - done(); - }); - }); - }); - }); -}); diff --git a/test/spec/modules/adlooxRtdProvider_spec.js b/test/spec/modules/adlooxRtdProvider_spec.js deleted file mode 100644 index 0fb0da58c..000000000 --- a/test/spec/modules/adlooxRtdProvider_spec.js +++ /dev/null @@ -1,223 +0,0 @@ -import adapterManager from 'src/adapterManager.js'; -import analyticsAdapter from 'modules/adlooxAnalyticsAdapter.js'; -import {auctionManager} from 'src/auctionManager.js'; -import { expect } from 'chai'; -import * as events from 'src/events.js'; -import * as prebidGlobal from 'src/prebidGlobal.js'; -import { subModuleObj as rtdProvider } from 'modules/adlooxRtdProvider.js'; -import * as utils from 'src/utils.js'; -import {server} from '../../mocks/xhr.js'; - -const analyticsAdapterName = 'adloox'; - -describe('Adloox RTD Provider', function () { - let sandbox; - - const adUnit = { - code: 'ad-slot-1', - ortb2Imp: { - ext: { - data: { - pbadslot: '/123456/home/ad-slot-1' - } - } - }, - mediaTypes: { - banner: { - sizes: [ [300, 250] ] - } - }, - bids: [ - { - bidder: 'dummy' - } - ] - }; - - const analyticsOptions = { - js: 'https://j.adlooxtracking.com/ads/js/tfav_adl_%%clientid%%.js', - client: 'adlooxtest', - clientid: 127, - platformid: 0, - tagid: 0 - }; - - const config = {}; - - adapterManager.registerAnalyticsAdapter({ - code: analyticsAdapterName, - adapter: analyticsAdapter - }); - - before(function () { - sandbox = sinon.createSandbox(); - sandbox.stub(events, 'getEvents').returns([]); - }); - - after(function () { - sandbox.restore(); - sandbox = undefined; - }); - - describe('invalid config', function () { - it('should require config', function (done) { - const ret = rtdProvider.init(); - - expect(ret).is.false; - - done(); - }); - - it('should reject non-object config.params', function (done) { - const ret = rtdProvider.init({ params: null }); - - expect(ret).is.false; - - done(); - }); - - it('should reject less than one config.params.imps', function (done) { - const ret = rtdProvider.init({ params: { imps: 0 } }); - - expect(ret).is.false; - - done(); - }); - - it('should reject negative config.params.freqcap_ip', function (done) { - const ret = rtdProvider.init({ params: { freqcap_ip: -1 } }); - - expect(ret).is.false; - - done(); - }); - - it('should reject negative integer config.params.freqcap_ipua', function (done) { - const ret = rtdProvider.init({ params: { freqcap_ipua: -1 } }); - - expect(ret).is.false; - - done(); - }); - - it('should reject non-array of integers with value greater than zero config.params.thresholds', function (done) { - const ret = rtdProvider.init({ params: { thresholds: [ 70, null ] } }); - - expect(ret).is.false; - - done(); - }); - - it('should reject non-boolean config.params.slotinpath', function (done) { - const ret = rtdProvider.init({ params: { slotinpath: null } }); - - expect(ret).is.false; - - done(); - }); - - it('should reject invalid config.params.params (legacy/deprecated)', function (done) { - const ret = rtdProvider.init({ params: { params: { clientid: 0, tagid: 0 } } }); - - expect(ret).is.false; - - done(); - }); - }); - - describe('process segments', function () { - before(function () { - adapterManager.enableAnalytics({ - provider: analyticsAdapterName, - options: analyticsOptions - }); - expect(analyticsAdapter.context).is.not.null; - }); - - after(function () { - analyticsAdapter.disableAnalytics(); - expect(analyticsAdapter.context).is.null; - }); - - let CONFIG = null; - beforeEach(function () { - CONFIG = utils.deepClone(config); - }); - afterEach(function () { - CONFIG = null; - }); - - it('should fetch segments', function (done) { - const req = { - adUnitCodes: [ adUnit.code ], - ortb2Fragments: { - global: { - site: { - ext: { - data: { - } - } - }, - user: { - ext: { - data: { - } - } - } - } - } - }; - const adUnitWithSegments = utils.deepClone(adUnit); - const getGlobalStub = sinon.stub(prebidGlobal, 'getGlobal').returns({ - adUnits: [ adUnitWithSegments ] - }); - - const ret = rtdProvider.init(CONFIG); - expect(ret).is.true; - - const callback = function () { - const ortb2 = req.ortb2Fragments.global; - expect(ortb2.site.ext.data.adloox_rtd.ok).is.true; - expect(ortb2.site.ext.data.adloox_rtd.nope).is.undefined; - expect(ortb2.user.ext.data.adloox_rtd.unused).is.false; - expect(ortb2.user.ext.data.adloox_rtd.nope).is.undefined; - expect(adUnitWithSegments.ortb2Imp.ext.data.adloox_rtd.dis.length).is.equal(3); - expect(adUnitWithSegments.ortb2Imp.ext.data.adloox_rtd.nope).is.undefined; - - getGlobalStub.restore(); - - done(); - }; - rtdProvider.getBidRequestData(req, callback, CONFIG, null); - - const request = server.requests[0]; - const response = { unused: false, _: [ { d: 77 } ] }; - request.respond(200, { 'content-type': 'application/json' }, JSON.stringify(response)); - }); - - it('should set ad server targeting', function (done) { - const adUnitWithSegments = utils.deepClone(adUnit); - utils.deepSetValue(adUnitWithSegments, 'ortb2Imp.ext.data.adloox_rtd.dis', [ 50, 60 ]); - const getGlobalStub = sinon.stub(prebidGlobal, 'getGlobal').returns({ - adUnits: [ adUnitWithSegments ] - }); - - const auction = { adUnits: [ adUnitWithSegments ] }; - const getAuctionStub = sinon.stub(auctionManager.index, 'getAuction').returns({ - adUnits: [ adUnitWithSegments ], - getFPD: () => { return { global: { site: { ext: { data: { adloox_rtd: { ok: true } } } } } } } - }); - - const targetingData = rtdProvider.getTargetingData([ adUnitWithSegments.code ], CONFIG, null, auction); - expect(Object.keys(targetingData).length).is.equal(1); - expect(Object.keys(targetingData[adUnit.code]).length).is.equal(2); - expect(targetingData[adUnit.code].adl_ok).is.equal(1); - expect(targetingData[adUnit.code].adl_dis.length).is.equal(2); - - getAuctionStub.restore(); - getGlobalStub.restore(); - - done(); - }); - }); -}); diff --git a/test/spec/modules/admaruBidAdapter_spec.js b/test/spec/modules/admaruBidAdapter_spec.js deleted file mode 100644 index d51451bf6..000000000 --- a/test/spec/modules/admaruBidAdapter_spec.js +++ /dev/null @@ -1,172 +0,0 @@ -import { expect } from 'chai'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { spec } from '../../../modules/admaruBidAdapter.js'; - -const ENDPOINT = 'https://p1.admaru.net/AdCall'; - -describe('Admaru Adapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('should exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValidForBanner', () => { - const bid = { - 'bidder': 'admaru', - 'params': { - 'pub_id': '1234', - 'adspace_id': '1234' - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 250] - ] - } - }, - 'sizes': [[300, 250]], - 'bidId': '26e88c3c703e66', - 'bidderRequestId': '1a8ff729f6c1a3', - 'auctionId': 'cb65d954-ffe1-4f4a-8603-02b521c00333', - }; - - it('should return true when required params found', () => { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', () => { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - wrong: 'missing pub_id or adspace_id' - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequestsForBanner', () => { - const bidRequests = [ - { - 'bidder': 'admaru', - 'params': { - 'pub_id': '1234', - 'adspace_id': '1234' - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 250] - ] - } - }, - 'sizes': [[300, 250]], - 'bidId': '26e88c3c703e66', - 'bidderRequestId': '1a8ff729f6c1a3', - 'auctionId': 'cb65d954-ffe1-4f4a-8603-02b521c00333' - } - ]; - - it('should add parameters to the tag', () => { - const request = spec.buildRequests(bidRequests); - const payload = request[0].data; - expect(payload.pub_id).to.equal('1234'); - expect(payload.adspace_id).to.equal('1234'); - // expect(payload.refererInfo).to.equal('{"referer": "https://www.admaru.com/test/admaru_prebid/icv_reminder/test.html","reachedTop": true,"numIframes": 1,"stack": ["https://www.admaru.com/test/admaru_prebid/icv_reminder/test.html","https://www.admaru.com/test/admaru_prebid/icv_reminder/test.html"]}'); - // expect(payload.os).to.equal('windows'); - // expect(payload.platform).to.equal('pc_web'); - expect(payload.bidderRequestId).to.equal('1a8ff729f6c1a3'); - expect(payload.bidId).to.equal('26e88c3c703e66'); - }); - - it('sends bid request to ENDPOINT via GET', () => { - const request = spec.buildRequests(bidRequests); - expect(request[0].url).to.contain(ENDPOINT); - expect(request[0].method).to.equal('GET'); - }); - }); - - describe('interpretResponseForBanner', () => { - const bidRequests = [ - { - 'bidder': 'admaru', - 'params': { - 'pub_id': '1234', - 'adspace_id': '1234' - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 250] - ] - } - }, - 'sizes': [[300, 250]], - 'bidId': '26e88c3c703e66', - 'bidderRequestId': '1a8ff729f6c1a3', - 'auctionId': 'cb65d954-ffe1-4f4a-8603-02b521c00333' - } - ]; - - it('handles nobid responses', () => { - var request = spec.buildRequests(bidRequests); - const response = ''; - - const result = spec.interpretResponse(response, request[0]); - expect(result.length).to.equal(0); - }); - }); - - describe('getUserSyncs()', () => { - it('should return iframe user sync if iframe sync is enabled', () => { - const syncs = spec.getUserSyncs( - { - pixelEnabled: true, - iframeEnabled: true, - }, - null - ); - - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://p2.admaru.net/UserSync/sync', - }, - ]); - }); - - it('should return image syncs if they are enabled and iframe is disabled', () => { - const syncs = spec.getUserSyncs( - { - pixelEnabled: true, - iframeEnabled: false, - }, - null - ); - - expect(syncs).to.deep.equal([ - { - type: 'image', - url: 'https://p2.admaru.net/UserSync/sync', - }, - ]); - }); - - it('should not return user syncs if syncs are disabled', () => { - const syncs = spec.getUserSyncs( - { - pixelEnabled: false, - iframeEnabled: false, - }, - null - ); - - expect(syncs).to.deep.equal([]); - }); - }); -}); diff --git a/test/spec/modules/admaticBidAdapter_spec.js b/test/spec/modules/admaticBidAdapter_spec.js deleted file mode 100644 index 1fce6a179..000000000 --- a/test/spec/modules/admaticBidAdapter_spec.js +++ /dev/null @@ -1,1161 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/admaticBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; - -const ENDPOINT = 'https://layer.rtb.admatic.com.tr/pb'; - -describe('admaticBidAdapter', () => { - const adapter = newBidder(spec); - const validRequest = [ { - 'refererInfo': { - 'page': 'https://www.admatic.com.tr', - 'domain': 'https://www.admatic.com.tr', - }, - 'bidder': 'admatic', - 'params': { - 'networkId': 10433394, - 'host': 'layer.rtb.admatic.com.tr' - }, - 'ortb2Imp': { 'ext': { 'instl': 1 } }, - 'ortb2': { 'badv': ['admatic.com.tr'] }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [728, 90]] - }, - 'native': { - }, - 'video': { - } - }, - getFloor: inputParams => { - if (inputParams.mediaType === BANNER && inputParams.size[0] === 300 && inputParams.size[1] === 250) { - return { - currency: 'USD', - floor: 1.0 - }; - } else if (inputParams.mediaType === BANNER && inputParams.size[0] === 728 && inputParams.size[1] === 90) { - return { - currency: 'USD', - floor: 2.0 - }; - } else if (inputParams.mediaType === VIDEO) { - return { - currency: 'USD', - floor: 1.0 - }; - } else if (inputParams.mediaType === NATIVE) { - return { - currency: 'USD', - floor: 1.0 - }; - } else { - return {} - } - }, - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'pixad.com.tr', - 'sid': 'px-pub-3000856707', - 'hp': 1 - } - ] - }, - 'at': 1, - 'tmax': 1000, - 'user': { - 'ext': { - 'eids': [ - { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': '0', - 'atype': 1, - 'ext': { - 'linkType': 0, - 'pba': 'wMh3sAXcnhDq7CfSa6ji1g==' - } - } - ] - }, - { - 'source': 'pubcid.org', - 'uids': [ - { - 'id': '5a49273f-a424-454b-b478-169c3551aa72', - 'atype': 1 - } - ] - } - ] - } - }, - 'ortb': { - 'badv': [], - 'bcat': [], - 'site': { - 'page': 'http://localhost:8888/admatic.html', - 'ref': 'http://localhost:8888', - 'publisher': { - 'name': 'localhost' - } - }, - 'device': { - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36' - } - }, - 'site': { - 'page': 'http://localhost:8888/admatic.html', - 'ref': 'http://localhost:8888', - 'publisher': { - 'name': 'localhost', - 'publisherId': 12321312 - } - }, - 'imp': [ - { - 'size': [ - { - 'w': 300, - 'h': 250 - }, - { - 'w': 728, - 'h': 90 - } - ], - 'mediatype': {}, - 'type': 'banner', - 'id': 1, - 'floors': { - 'banner': { - '300x250': { 'currency': 'USD', 'floor': 1 }, - '728x90': { 'currency': 'USD', 'floor': 2 } - } - } - }, - { - 'size': [ - { - 'w': 338, - 'h': 280 - } - ], - 'type': 'video', - 'mediatype': { - 'context': 'instream', - 'mimes': [ - 'video/mp4' - ], - 'maxduration': 240, - 'api': [ - 1, - 2 - ], - 'playerSize': [ - [ - 338, - 280 - ] - ], - 'protocols': [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ], - 'skip': 1, - 'playbackmethod': [ - 2 - ], - 'linearity': 1, - 'placement': 2 - }, - 'floors': { - 'video': { - '338x280': { 'currency': 'USD', 'floor': 1 } - } - }, - 'id': '45e86fc7ce7fc93' - }, - { - 'size': [ - { - 'w': 1, - 'h': 1 - } - ], - 'type': 'native', - 'mediatype': { - 'title': { - 'required': true, - 'len': 120 - }, - 'image': { - 'required': true - }, - 'icon': { - 'required': false, - 'sizes': [ - 640, - 480 - ] - }, - 'sponsoredBy': { - 'required': false - }, - 'body': { - 'required': false - }, - 'clickUrl': { - 'required': false - }, - 'displayUrl': { - 'required': false - } - }, - 'ext': { - 'instl': 0, - 'gpid': 'native-INS_b1b1269f-9570-fe3c-9bf4-f187827ec94a', - 'data': { - 'pbadslot': 'native-INS_b1b1269f-9570-fe3c-9bf4-f187827ec94a' - } - }, - 'floors': { - 'native': { - '*': { 'currency': 'USD', 'floor': 1 } - } - }, - 'id': '16e0c8982318f91' - } - ], - 'ext': { - 'cur': 'USD', - 'bidder': 'admatic' - } - } ]; - const bidderRequest = { - 'refererInfo': { - 'page': 'https://www.admatic.com.tr', - 'domain': 'https://www.admatic.com.tr', - }, - 'bidder': 'admatic', - 'params': { - 'networkId': 10433394, - 'host': 'layer.rtb.admatic.com.tr' - }, - 'ortb2Imp': { 'ext': { 'instl': 1 } }, - 'ortb2': { 'badv': ['admatic.com.tr'] }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [728, 90]] - }, - 'native': { - }, - 'video': { - 'playerSize': [ - 336, - 280 - ] - } - }, - 'userId': { - 'id5id': { - 'uid': '0', - 'ext': { - 'linkType': 0, - 'pba': 'wMh3sAXcnhDq7CfSa6ji1g==' - } - }, - 'pubcid': '5a49273f-a424-454b-b478-169c3551aa72' - }, - 'userIdAsEids': [ - { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': '0', - 'atype': 1, - 'ext': { - 'linkType': 0, - 'pba': 'wMh3sAXcnhDq7CfSa6ji1g==' - } - } - ] - }, - { - 'source': 'pubcid.org', - 'uids': [ - { - 'id': '5a49273f-a424-454b-b478-169c3551aa72', - 'atype': 1 - } - ] - } - ], - getFloor: inputParams => { - if (inputParams.mediaType === BANNER && inputParams.size[0] === 300 && inputParams.size[1] === 250) { - return { - currency: 'USD', - floor: 1.0 - }; - } else if (inputParams.mediaType === BANNER && inputParams.size[0] === 728 && inputParams.size[1] === 90) { - return { - currency: 'USD', - floor: 2.0 - }; - } else if (inputParams.mediaType === VIDEO) { - return { - currency: 'USD', - floor: 1.0 - }; - } else if (inputParams.mediaType === NATIVE) { - return { - currency: 'USD', - floor: 1.0 - }; - } else { - return {} - } - }, - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'pixad.com.tr', - 'sid': 'px-pub-3000856707', - 'hp': 1 - } - ] - }, - 'at': 1, - 'tmax': 1000, - 'user': { - 'ext': { - 'eids': [ - { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': '0', - 'atype': 1, - 'ext': { - 'linkType': 0, - 'pba': 'wMh3sAXcnhDq7CfSa6ji1g==' - } - } - ] - }, - { - 'source': 'pubcid.org', - 'uids': [ - { - 'id': '5a49273f-a424-454b-b478-169c3551aa72', - 'atype': 1 - } - ] - } - ] - } - }, - 'ortb': { - 'source': {}, - 'site': { - 'domain': 'localhost:8888', - 'publisher': { - 'domain': 'localhost:8888' - }, - 'page': 'http://localhost:8888/', - 'name': 'http://localhost:8888' - }, - 'badv': [], - 'bcat': [], - 'device': { - 'w': 896, - 'h': 979, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36', - 'language': 'tr', - 'sua': { - 'source': 1, - 'platform': { - 'brand': 'macOS' - }, - 'browsers': [ - { - 'brand': 'Google Chrome', - 'version': [ - '119' - ] - }, - { - 'brand': 'Chromium', - 'version': [ - '119' - ] - }, - { - 'brand': 'Not?A_Brand', - 'version': [ - '24' - ] - } - ], - 'mobile': 0 - } - } - }, - 'site': { - 'page': 'http://localhost:8888/admatic.html', - 'ref': 'http://localhost:8888', - 'publisher': { - 'name': 'localhost', - 'publisherId': 12321312 - } - }, - 'imp': [ - { - 'size': [ - { - 'w': 300, - 'h': 250 - }, - { - 'w': 728, - 'h': 90 - } - ], - 'id': 1, - 'mediatype': {}, - 'type': 'banner', - 'floors': { - 'banner': { - '300x250': { 'currency': 'USD', 'floor': 1 }, - '728x90': { 'currency': 'USD', 'floor': 2 } - } - } - }, - { - 'size': [ - { - 'w': 338, - 'h': 280 - } - ], - 'type': 'video', - 'mediatype': { - 'context': 'instream', - 'mimes': [ - 'video/mp4' - ], - 'maxduration': 240, - 'api': [ - 1, - 2 - ], - 'playerSize': [ - [ - 338, - 280 - ] - ], - 'protocols': [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ], - 'skip': 1, - 'playbackmethod': [ - 2 - ], - 'linearity': 1, - 'placement': 2 - }, - 'floors': { - 'video': { - '338x280': { 'currency': 'USD', 'floor': 1 } - } - }, - 'id': '45e86fc7ce7fc93' - }, - { - 'size': [ - { - 'w': 1, - 'h': 1 - } - ], - 'type': 'native', - 'mediatype': { - 'title': { - 'required': true, - 'len': 120 - }, - 'image': { - 'required': true - }, - 'icon': { - 'required': false, - 'sizes': [ - 640, - 480 - ] - }, - 'sponsoredBy': { - 'required': false - }, - 'body': { - 'required': false - }, - 'clickUrl': { - 'required': false - }, - 'displayUrl': { - 'required': false - } - }, - 'ext': { - 'instl': 0, - 'gpid': 'native-INS_b1b1269f-9570-fe3c-9bf4-f187827ec94a', - 'data': { - 'pbadslot': 'native-INS_b1b1269f-9570-fe3c-9bf4-f187827ec94a' - } - }, - 'floors': { - 'native': { - '*': { 'currency': 'USD', 'floor': 1 } - } - }, - 'id': '16e0c8982318f91' - } - ], - 'ext': { - 'cur': 'USD', - 'bidder': 'admatic' - } - }; - - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function() { - const bid = { - 'refererInfo': { - 'page': 'https://www.admatic.com.tr', - 'domain': 'https://www.admatic.com.tr', - }, - 'bidder': 'admatic', - 'params': { - 'networkId': 10433394, - 'host': 'layer.rtb.admatic.com.tr' - }, - 'adUnitCode': 'adunit-code', - 'mediaType': 'banner', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'creativeId': 'er2ee', - 'ortb2Imp': { 'ext': { 'instl': 1 } }, - 'ortb2': { 'badv': ['admatic.com.tr'] } - }; - - it('should return true when required params found', function() { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function() { - const bid2 = {}; - bid2.params = { - 'someIncorrectParam': 0 - }; - expect(spec.isBidRequestValid(bid2)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('should not populate GDPR if for non-EEA users', function () { - const bidRequest = Object.assign([], validRequest); - const request = spec.buildRequests( - bidRequest, - Object.assign({}, bidderRequest, { - gdprConsent: { - gdprApplies: true, - consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==' - } - }) - ); - expect(request.data.regs.ext.gdpr).to.equal(1); - expect(request.data.regs.ext.consent).to.equal('BOJ8RZsOJ8RZsABAB8AAAAAZ-A'); - }); - - it('should populate GDPR and empty consent string if available for EEA users without consent string but with consent', function () { - const bidRequest = Object.assign([], validRequest); - const request = spec.buildRequests( - bidRequest, - Object.assign({}, bidderRequest, { - gdprConsent: { - gdprApplies: true - } - }) - ); - expect(request.data.regs.ext.gdpr).to.equal(1); - expect(request.data.regs.ext.consent).to.equal(''); - }); - - it('should properly build a request when coppa flag is true', function () { - const bidRequest = Object.assign([], validRequest); - const request = spec.buildRequests( - bidRequest, - Object.assign({}, bidderRequest, { - coppa: true - }) - ); - expect(request.data.regs.ext.coppa).to.not.be.undefined; - expect(request.data.regs.ext.coppa).to.equal(1); - }); - - it('should properly build a request with gpp consent field', function () { - const bidRequest = Object.assign([], validRequest); - const ortb2 = { - regs: { - gpp: 'gpp_consent_string', - gpp_sid: [0, 1, 2] - } - }; - const request = spec.buildRequests(bidRequest, { ...bidderRequest, ortb2 }); - expect(request.data.regs.ext.gpp).to.equal('gpp_consent_string'); - expect(request.data.regs.ext.gpp_sid).to.deep.equal([0, 1, 2]); - }); - - it('should properly build a request with ccpa consent field', function () { - const bidRequest = Object.assign([], validRequest); - const request = spec.buildRequests( - bidRequest, - Object.assign({}, bidderRequest, { - uspConsent: '1---' - }) - ); - expect(request.data.regs.ext.uspIab).to.not.be.null; - expect(request.data.regs.ext.uspIab).to.equal('1---'); - }); - - it('should properly forward eids', function () { - const bidRequests = [ - { - bidder: 'admatic', - adUnitCode: 'bid-123', - transactionId: 'transaction-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - userIdAsEids: [ - { - source: 'admatic.com.tr', - uids: [{ - id: 'abc', - atype: 1 - }] - } - ], - params: { - networkId: 10433394, - host: 'layer.rtb.admatic.com.tr' - } - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - const ortbRequest = request.data; - expect(ortbRequest.user.ext.eids).to.deep.equal([ - { - source: 'admatic.com.tr', - uids: [{ - id: 'abc', - atype: 1 - }] - } - ]); - }); - - it('should properly build a banner request with floors', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - request.data.imp[0].floors = { - 'banner': { - '300x250': { 'currency': 'USD', 'floor': 1 }, - '728x90': { 'currency': 'USD', 'floor': 2 } - } - }; - }); - - it('should properly build a video request with several player sizes with floors', function () { - const bidRequests = [ - { - 'bidder': 'admatic', - 'adUnitCode': 'bid-123', - 'transactionId': 'transaction-123', - 'mediaTypes': { - 'video': { - 'playerSize': [[300, 250], [728, 90]] - } - }, - 'ortb2Imp': { 'ext': { 'instl': 1 } }, - 'ortb2': { 'badv': ['admatic.com.tr'] }, - 'params': { - 'networkId': 10433394, - 'host': 'layer.rtb.admatic.com.tr' - }, - getFloor: inputParams => { - if (inputParams.mediaType === VIDEO && inputParams.size[0] === 300 && inputParams.size[1] === 250) { - return { - currency: 'USD', - floor: 1.0 - }; - } else if (inputParams.mediaType === VIDEO && inputParams.size[0] === 728 && inputParams.size[1] === 90) { - return { - currency: 'USD', - floor: 2.0 - }; - } else { - return {} - } - } - }, - ]; - const bidderRequest = { - 'refererInfo': { - 'page': 'https://www.admatic.com.tr', - 'domain': 'https://www.admatic.com.tr', - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - }); - - it('should properly build a native request with floors', function () { - const bidRequests = [ - { - 'bidder': 'admatic', - 'adUnitCode': 'bid-123', - 'transactionId': 'transaction-123', - 'mediaTypes': { - 'native': { - } - }, - 'ortb2Imp': { 'ext': { 'instl': 1 } }, - 'ortb2': { 'badv': ['admatic.com.tr'] }, - 'params': { - 'networkId': 10433394, - 'host': 'layer.rtb.admatic.com.tr' - }, - getFloor: inputParams => { - if (inputParams.mediaType === NATIVE) { - return { - currency: 'USD', - floor: 1.0 - }; - } else { - return {} - } - } - }, - ]; - const bidderRequest = { - 'refererInfo': { - 'page': 'https://www.admatic.com.tr', - 'domain': 'https://www.admatic.com.tr', - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - }); - }); - - describe('interpretResponse', function () { - it('should get correct bid responses', function() { - const bids = { body: { - data: [ - { - 'id': 1, - 'creative_id': '374', - 'width': 300, - 'height': 250, - 'price': 0.01, - 'type': 'banner', - 'bidder': 'admatic', - 'currency': 'TRY', - 'mime_type': { - 'name': 'backfill', - 'force': false - }, - 'adomain': ['admatic.com.tr'], - 'party_tag': '
', - 'iurl': 'https://www.admatic.com.tr' - }, - { - 'id': 2, - 'creative_id': '3741', - 'width': 300, - 'height': 250, - 'price': 0.01, - 'currency': 'TRY', - 'type': 'video', - 'mime_type': { - 'name': 'backfill', - 'force': false - }, - 'bidder': 'admatic', - 'adomain': ['admatic.com.tr'], - 'party_tag': '', - 'iurl': 'https://www.admatic.com.tr' - }, - { - 'id': 3, - 'creative_id': '3742', - 'width': 1, - 'height': 1, - 'price': 0.01, - 'currency': 'TRY', - 'type': 'native', - 'mime_type': { - 'name': 'backfill', - 'force': false - }, - 'bidder': 'admatic', - 'adomain': ['admatic.com.tr'], - 'party_tag': '{"native":{"ver":"1.1","assets":[{"id":1,"title":{"text":"title"}},{"id":4,"data":{"value":"body"}},{"id":5,"data":{"value":"sponsored"}},{"id":6,"data":{"value":"cta"}},{"id":2,"img":{"url":"https://www.admatic.com.tr","w":1200,"h":628}},{"id":3,"img":{"url":"https://www.admatic.com.tr","w":640,"h":480}}],"link":{"url":"https://www.admatic.com.tr"},"imptrackers":["https://www.admatic.com.tr"]}}', - 'iurl': 'https://www.admatic.com.tr' - } - ], - 'cur': 'TRY', - 'queryId': 'cdnbh24rlv0hhkpfpln0', - 'status': true - }}; - - const expectedResponse = [ - { - requestId: 1, - cpm: 0.01, - width: 300, - height: 250, - mediaType: 'banner', - netRevenue: true, - currency: 'TRY', - ad: '
', - creativeId: '374', - meta: { - model: { - 'name': 'backfill', - 'force': false - }, - advertiserDomains: ['admatic.com.tr'] - }, - ttl: 60, - bidder: 'admatic' - }, - { - requestId: 2, - cpm: 0.01, - width: 300, - height: 250, - mediaType: 'video', - netRevenue: true, - currency: 'TRY', - vastXml: '', - creativeId: '3741', - meta: { - model: { - 'name': 'backfill', - 'force': false - }, - advertiserDomains: ['admatic.com.tr'] - }, - ttl: 60, - bidder: 'admatic' - }, - { - requestId: 3, - cpm: 0.01, - width: 1, - height: 1, - mediaType: 'native', - netRevenue: true, - currency: 'TRY', - native: { - 'clickUrl': 'https://www.admatic.com.tr', - 'impressionTrackers': ['https://www.admatic.com.tr'], - 'title': 'title', - 'body': 'body', - 'sponsoredBy': 'sponsored', - 'cta': 'cta', - 'image': { - 'url': 'https://www.admatic.com.tr', - 'width': 1200, - 'height': 628 - }, - 'icon': { - 'url': 'https://www.admatic.com.tr', - 'width': 640, - 'height': 480 - } - }, - creativeId: '3742', - meta: { - model: { - 'name': 'backfill', - 'force': false - }, - advertiserDomains: ['admatic.com.tr'] - }, - ttl: 60, - bidder: 'admatic' - } - ]; - const request = { - ext: { - 'cur': 'TRY', - 'type': 'admatic' - }, - imp: [ - { - 'size': [ - { - 'w': 320, - 'h': 100 - } - ], - 'type': 'banner', - 'mediatype': {}, - 'ext': { - 'instl': 0, - 'gpid': 'desktop-standard', - 'pxid': [ - '1111111111' - ], - 'pxtype': 'pixad', - 'ortbstatus': true, - 'viewability': 100, - 'data': { - 'pbadslot': 'desktop-standard' - }, - 'ae': 1 - }, - 'id': 1, - 'floors': { - 'banner': { - '320x100': { - 'floor': 0.1, - 'currency': 'TRY' - } - } - } - }, - { - 'size': [ - { - 'w': 320, - 'h': 100 - } - ], - 'type': 'video', - 'mediatype': { - 'context': 'instream', - 'mimes': [ - 'video/mp4' - ], - 'maxduration': 240, - 'api': [ - 1, - 2 - ], - 'playerSize': [ - [ - 320, - 100 - ] - ], - 'protocols': [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ], - 'skip': 0, - 'playbackmethod': [ - 2 - ], - 'linearity': 1, - 'placement': 2, - 'plcmt': 4 - }, - 'ext': { - 'gpid': 'outstream-desktop-standard', - 'pxtype': 'pixad', - 'pxid': [ - '1111111111' - ], - 'ortbstatus': true, - 'viewability': 100, - 'data': { - 'pbadslot': 'outstream-desktop-standard' - }, - 'ae': 1 - }, - 'id': 2, - 'floors': { - 'video': { - '320x100': { - 'floor': 0.1, - 'currency': 'TRY' - } - } - } - }, - { - 'size': [ - { - 'w': 1, - 'h': 1 - } - ], - 'type': 'native', - 'mediatype': { - 'ortb': { - 'ver': '1.1', - 'context': 2, - 'plcmttype': 1, - 'privacy': 1, - 'assets': [ - { - 'id': 1, - 'required': 1, - 'title': { - 'len': 120 - } - }, - { - 'id': 2, - 'required': 1, - 'img': { - 'type': 3, - 'w': 640, - 'h': 480 - } - }, - { - 'id': 3, - 'required': 0, - 'img': { - 'type': 1, - 'w': 640, - 'h': 480 - } - }, - { - 'id': 4, - 'required': 0, - 'data': { - 'type': 2 - } - }, - { - 'id': 5, - 'required': 0, - 'data': { - 'type': 1 - } - }, - { - 'id': 6, - 'required': 0, - 'data': { - 'type': 11 - } - } - ], - 'eventtrackers': [ - { - 'event': 1, - 'methods': [ - 1, - 2 - ] - } - ] - } - }, - 'ext': { - 'gpid': 'native-desktop-standard', - 'pxtype': 'pixad', - 'pxid': [ - '1111111111' - ], - 'ortbstatus': true, - 'viewability': 100, - 'data': { - 'pbadslot': 'native-desktop-standard' - }, - 'ae': 1 - }, - 'id': 3, - 'floors': { - 'native': { - '*': { - 'floor': 0.1, - 'currency': 'TRY' - } - } - } - } - ] - }; - - const result = spec.interpretResponse(bids, {data: request}); - expect(result).to.eql(expectedResponse); - }); - - it('handles nobid responses', function () { - const request = { - ext: { - 'cur': 'TRY', - 'type': 'admatic' - } - }; - const bids = { body: { - data: [], - 'queryId': 'cdnbh24rlv0hhkpfpln0', - 'status': true, - 'cur': 'TRY' - }}; - - const result = spec.interpretResponse(bids, {data: request}); - expect(result.length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/admediaBidAdapter_spec.js b/test/spec/modules/admediaBidAdapter_spec.js deleted file mode 100644 index 53ccade28..000000000 --- a/test/spec/modules/admediaBidAdapter_spec.js +++ /dev/null @@ -1,130 +0,0 @@ -import {assert, expect} from 'chai'; -import {spec} from 'modules/admediaBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import * as utils from 'src/utils.js'; - -const ENDPOINT_URL = 'https://prebid.admedia.com/bidder/'; - -describe('admediaBidAdapter', function () { - const adapter = newBidder(spec); - describe('isBidRequestValid', function () { - const bid = { - adUnitCode: 'adunit-code', - bidder: 'admedia', - bidId: 'g7ghhs78', - mediaTypes: {banner: {sizes: [[300, 250]]}}, - params: { - placementId: '782332', - aid: '86858', - }, - refererInfo: { - page: 'https://test.com' - } - }; - it('should return true where required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - describe('buildRequests', function () { - const bidRequests = [ - { - adUnitCode: 'adunit-code', - bidder: 'admedia', - bidId: 'g7ghhs78', - mediaTypes: {banner: {sizes: [[300, 250]]}}, - params: { - placementId: '782332', - aid: '86858' - }, - refererInfo: { - page: 'https://test.com' - } - } - ]; - - const bidderRequests = { - refererInfo: { - page: 'https://test.com', - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequests); - it('sends bid request via POST', function () { - expect(request[0].method).to.equal('POST'); - }); - }); - - describe('interpretResponse', function () { - const bidRequest = { - method: 'POST', - url: ENDPOINT_URL, - data: { - 'id': '782332', - 'aid': '86858', - 'tags': [ - { - 'sizes': [ - '300x250' - ], - 'id': '782332', - 'aid': '86858' - } - ], - 'bidId': '2556388472b168', - 'referer': 'https%3A%2F%test.com' - } - }; - const serverResponse = { - body: - { - 'tags': [ - { - 'requestId': '2b8bf2ac497ae', - 'ad': "", - 'width': 300, - 'height': 250, - 'cpm': 0.71, - 'currency': 'USD', - 'ttl': 200, - 'creativeId': 128, - 'netRevenue': true, - 'meta': { - 'advertiserDomains': [ - 'https://www.test.com' - ] - } - } - ] - } - - }; - it('should get the correct bid response', function () { - let expectedResponse = - { - 'tags': [ - { - 'requestId': '2b8bf2ac497ae', - 'ad': "", - 'width': 300, - 'height': 250, - 'cpm': 0.71, - 'currency': 'USD', - 'ttl': 200, - 'creativeId': 128, - 'netRevenue': true, - 'meta': { - 'advertiserDomains': [ - 'https://www.test.com' - ] - } - } - ] - } - let result = spec.interpretResponse(serverResponse, bidRequest); - expect(result).to.be.an('array').that.is.not.empty; - expect(Object.keys(result[0])).to.have.members( - Object.keys(expectedResponse.tags[0]) - ); - }); - }); -}); diff --git a/test/spec/modules/admixerBidAdapter_spec.js b/test/spec/modules/admixerBidAdapter_spec.js deleted file mode 100644 index db8dbd0d2..000000000 --- a/test/spec/modules/admixerBidAdapter_spec.js +++ /dev/null @@ -1,324 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/admixerBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import {config} from '../../../src/config.js'; - -const BIDDER_CODE = 'admixer'; -const RTB_BIDDER_CODE = 'rtbstack' -const ENDPOINT_URL = 'https://inv-nets.admixer.net/prebid.1.2.aspx'; -const ENDPOINT_URL_CUSTOM = 'https://custom.admixer.net/prebid.aspx'; -const ZONE_ID = '2eb6bd58-865c-47ce-af7f-a918108c3fd2'; -const CLIENT_ID = 5124; -const ENDPOINT_ID = 81264; - -describe('AdmixerAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.be.exist.and.to.be.a('function'); - }); - }); - // inv-nets.admixer.net/adxprebid.1.2.aspx - - describe('isBidRequestValid', function () { - const bid = { - bidder: BIDDER_CODE, - params: { - zone: ZONE_ID, - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250], - [300, 600], - ], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - }; - - const rtbBid = { - bidder: RTB_BIDDER_CODE, - params: { - tagId: ENDPOINT_ID, - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250], - [300, 600], - ], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should return true when params required by RTB found', function () { - expect(spec.isBidRequestValid(rtbBid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - placementId: 0, - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - it('should return false when params required by RTB are not passed', function () { - const invalidBid = Object.assign({}, rtbBid); - delete invalidBid.params; - invalidBid.params = { - clientId: 0, - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const validRequest = [ - { - bidder: BIDDER_CODE, - params: { - zone: ZONE_ID, - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250], - [300, 600], - ], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - }, - ]; - const bidderRequest = { - bidderCode: BIDDER_CODE, - refererInfo: { - page: 'https://example.com', - }, - }; - - it('should add referrer and imp to be equal bidRequest', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - const payload = request.data; - expect(payload.referrer).to.not.be.undefined; - expect(payload.imps[0]).to.deep.equal(validRequest[0]); - }); - - it('sends bid request to ENDPOINT via GET', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - expect(request.url).to.equal(ENDPOINT_URL); - expect(request.method).to.equal('POST'); - }); - - it('sends bid request to CUSTOM_ENDPOINT via GET', function () { - config.setBidderConfig({ - bidders: [BIDDER_CODE], // one or more bidders - config: { bidderURL: ENDPOINT_URL_CUSTOM }, - }); - const request = config.runWithBidder(BIDDER_CODE, () => - spec.buildRequests(validRequest, bidderRequest) - ); - expect(request.url).to.equal(ENDPOINT_URL_CUSTOM); - expect(request.method).to.equal('POST'); - }); - }); - - describe('buildRequests URL check', function () { - const requestParamsFor = (bidder) => ({ - validRequest: [ - { - bidder: bidder, - params: bidder === 'rtbstack' ? { - tagId: ENDPOINT_ID - } : { - zone: ZONE_ID, - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250], - [300, 600], - ], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - }, - ], - bidderRequest: { - bidderCode: bidder, - refererInfo: { - page: 'https://example.com', - }, - } - }) - - it('build request for admixer', function () { - const requestParams = requestParamsFor('admixer'); - const request = spec.buildRequests(requestParams.validRequest, requestParams.bidderRequest); - expect(request.url).to.equal('https://inv-nets.admixer.net/prebid.1.2.aspx'); - expect(request.method).to.equal('POST'); - }); - it('build request for go2net', function () { - const requestParams = requestParamsFor('go2net'); - const request = spec.buildRequests(requestParams.validRequest, requestParams.bidderRequest); - expect(request.url).to.equal('https://ads.go2net.com.ua/prebid.1.2.aspx'); - expect(request.method).to.equal('POST'); - }); - it('build request for adblender', function () { - const requestParams = requestParamsFor('adblender'); - const request = spec.buildRequests(requestParams.validRequest, requestParams.bidderRequest); - expect(request.url).to.equal('https://inv-nets.admixer.net/prebid.1.2.aspx'); - expect(request.method).to.equal('POST'); - }); - it('build request for futureads', function () { - const requestParams = requestParamsFor('futureads'); - const request = spec.buildRequests(requestParams.validRequest, requestParams.bidderRequest); - expect(request.url).to.equal('https://ads.futureads.io/prebid.1.2.aspx'); - expect(request.method).to.equal('POST'); - }); - it('build request for smn', function () { - const requestParams = requestParamsFor('smn'); - const request = spec.buildRequests(requestParams.validRequest, requestParams.bidderRequest); - expect(request.url).to.equal('https://ads.smn.rs/prebid.1.2.aspx'); - expect(request.method).to.equal('POST'); - }); - it('build request for admixeradx', function () { - const requestParams = requestParamsFor('admixeradx'); - const request = spec.buildRequests(requestParams.validRequest, requestParams.bidderRequest); - expect(request.url).to.equal('https://inv-nets.admixer.net/adxprebid.1.2.aspx'); - expect(request.method).to.equal('POST'); - }); - it('build request for rtbstack', function () { - const requestParams = requestParamsFor('rtbstack'); - config.setBidderConfig({ - bidders: ['rtbstack'], - config: { bidderURL: ENDPOINT_URL_CUSTOM }, - }); - const request = config.runWithBidder(BIDDER_CODE, () => - spec.buildRequests(requestParams.validRequest, requestParams.bidderRequest) - ); - expect(request.url).to.equal(ENDPOINT_URL_CUSTOM); - expect(request.method).to.equal('POST'); - }); - }); - - describe('checkFloorGetting', function () { - const validRequest = [ - { - bidder: BIDDER_CODE, - params: { - zone: ZONE_ID, - }, - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - }, - ]; - const bidderRequest = { - bidderCode: BIDDER_CODE, - refererInfo: { - page: 'https://example.com', - }, - }; - it('gets floor', function () { - validRequest[0].getFloor = () => { - return { floor: 0.6 }; - }; - const request = spec.buildRequests(validRequest, bidderRequest); - const payload = request.data; - expect(payload.imps[0].bidFloor).to.deep.equal(0.6); - }); - }); - - describe('interpretResponse', function () { - const response = { - body: { - ads: [ - { - currency: 'USD', - cpm: 6.21, - ad: '
ad
', - width: 300, - height: 600, - creativeId: 'ccca3e5e-0c54-4761-9667-771322fbdffc', - ttl: 360, - netRevenue: false, - requestId: '5e4e763b6bc60b', - dealId: 'asd123', - meta: { - advertiserId: 123, - networkId: 123, - advertiserDomains: ['test.com'], - }, - }, - ], - }, - }; - - it('should get correct bid response', function () { - const ads = response.body.ads; - const expectedResponse = [ - { - requestId: ads[0].requestId, - cpm: ads[0].cpm, - creativeId: ads[0].creativeId, - width: ads[0].width, - height: ads[0].height, - ad: ads[0].ad, - currency: ads[0].currency, - netRevenue: ads[0].netRevenue, - ttl: ads[0].ttl, - dealId: ads[0].dealId, - meta: { - advertiserId: 123, - networkId: 123, - advertiserDomains: ['test.com'], - }, - }, - ]; - - const result = spec.interpretResponse(response); - expect(result[0]).to.deep.equal(expectedResponse[0]); - }); - - it('handles nobid responses', function () { - const response = []; - - const result = spec.interpretResponse(response); - expect(result.length).to.equal(0); - }); - }); - - describe('getUserSyncs', function () { - const imgUrl = 'https://example.com/img1'; - const frmUrl = 'https://example.com/frm2'; - const responses = [ - { - body: { - cm: { - pixels: [imgUrl], - iframes: [frmUrl], - }, - }, - }, - ]; - - it('Returns valid values', function () { - const userSyncAll = spec.getUserSyncs({pixelEnabled: true, iframeEnabled: true}, responses); - const userSyncImg = spec.getUserSyncs({pixelEnabled: true, iframeEnabled: false}, responses); - const userSyncFrm = spec.getUserSyncs({pixelEnabled: false, iframeEnabled: true}, responses); - expect(userSyncAll).to.be.an('array').with.lengthOf(2); - expect(userSyncImg).to.be.an('array').with.lengthOf(1); - expect(userSyncImg[0].url).to.be.equal(imgUrl); - expect(userSyncImg[0].type).to.be.equal('image'); - expect(userSyncFrm).to.be.an('array').with.lengthOf(1); - expect(userSyncFrm[0].url).to.be.equal(frmUrl); - expect(userSyncFrm[0].type).to.be.equal('iframe'); - }); - }); -}); diff --git a/test/spec/modules/adnowBidAdapter_spec.js b/test/spec/modules/adnowBidAdapter_spec.js deleted file mode 100644 index a8013e3fa..000000000 --- a/test/spec/modules/adnowBidAdapter_spec.js +++ /dev/null @@ -1,163 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adnowBidAdapter.js'; - -describe('adnowBidAdapter', function () { - describe('isBidRequestValid', function () { - it('Should return true', function() { - expect(spec.isBidRequestValid({ - bidder: 'adnow', - params: { - codeId: 12345 - } - })).to.equal(true); - }); - - it('Should return false when required params is not passed', function() { - expect(spec.isBidRequestValid({ - bidder: 'adnow', - params: {} - })).to.equal(false); - }); - }); - - describe('buildRequests', function() { - it('Common settings', function() { - const bidRequestData = [{ - bidId: 'bid12345', - params: { - codeId: 12345 - } - }]; - - const req = spec.buildRequests(bidRequestData); - const reqData = req[0].data; - - expect(reqData) - .to.match(/Id=12345/) - .to.match(/mediaType=native/) - .to.match(/out=prebid/) - .to.match(/requestid=bid12345/) - .to.match(/d_user_agent=.+/); - }); - - it('Banner sizes', function () { - const bidRequestData = [{ - bidId: 'bid12345', - params: { - codeId: 12345 - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - }]; - - const req = spec.buildRequests(bidRequestData); - const reqData = req[0].data; - - expect(reqData).to.match(/sizes=300x250/); - }); - - it('Native sizes', function () { - const bidRequestData = [{ - bidId: 'bid12345', - params: { - codeId: 12345 - }, - mediaTypes: { - native: { - image: { - sizes: [100, 100] - } - } - } - }]; - - const req = spec.buildRequests(bidRequestData); - const reqData = req[0].data; - - expect(reqData) - .to.match(/width=100/) - .to.match(/height=100/); - }); - }); - - describe('interpretResponse', function() { - const request = { - bidRequest: { - bidId: 'bid12345' - } - }; - - it('Response with native bid', function() { - const response = { - currency: 'USD', - cpm: 0.5, - native: { - title: 'Title', - body: 'Body', - sponsoredBy: 'AdNow', - clickUrl: '//click.url', - image: { - url: '//img.url', - height: 200, - width: 200 - } - }, - meta: { - mediaType: 'native' - } - }; - - const bids = spec.interpretResponse({ body: response }, request); - expect(bids).to.be.an('array').that.is.not.empty; - - const bid = bids[0]; - expect(bid).to.have.keys('requestId', 'cpm', 'currency', 'native', 'creativeId', 'netRevenue', 'meta', 'ttl'); - - const nativePart = bid.native; - - expect(nativePart.title).to.be.equal('Title'); - expect(nativePart.body).to.be.equal('Body'); - expect(nativePart.clickUrl).to.be.equal('//click.url'); - expect(nativePart.image.url).to.be.equal('//img.url'); - expect(nativePart.image.height).to.be.equal(200); - expect(nativePart.image.width).to.be.equal(200); - }); - - it('Response with banner bid', function() { - const response = { - currency: 'USD', - cpm: 0.5, - ad: '
Banner
', - meta: { - mediaType: 'banner' - } - }; - - const bids = spec.interpretResponse({ body: response }, request); - expect(bids).to.be.an('array').that.is.not.empty; - - const bid = bids[0]; - expect(bid).to.have.keys( - 'requestId', 'cpm', 'currency', 'ad', 'creativeId', 'netRevenue', 'meta', 'ttl', 'width', 'height' - ); - - expect(bid.ad).to.be.equal('
Banner
'); - }); - - it('Response with no bid should return an empty array', function() { - const noBidResponses = [ - false, - {}, - {body: false}, - {body: {}} - ]; - - noBidResponses.forEach(response => { - return expect(spec.interpretResponse(response, request)).to.be.an('array').that.is.empty; - }); - }); - }); -}); diff --git a/test/spec/modules/adnuntiusAnalyticsAdapter_spec.js b/test/spec/modules/adnuntiusAnalyticsAdapter_spec.js deleted file mode 100644 index 55cddbb0d..000000000 --- a/test/spec/modules/adnuntiusAnalyticsAdapter_spec.js +++ /dev/null @@ -1,536 +0,0 @@ -import adnAnalyticsAdapter, { BID_WON_TIMEOUT } from 'modules/adnuntiusAnalyticsAdapter.js'; -import { AD_RENDER_FAILED_REASON, EVENTS, STATUS } from 'src/constants.js'; -import { config } from 'src/config.js'; -import { server } from 'test/mocks/xhr.js'; -import { setConfig } from 'modules/currency.js'; - -const events = require('src/events'); -const utils = require('src/utils'); -const adapterManager = require('src/adapterManager').default; - -const { - AUCTION_INIT, - AUCTION_END, - BID_REQUESTED, - BID_RESPONSE, - BIDDER_DONE, - BID_WON, - BID_TIMEOUT, - SET_TARGETING, - AD_RENDER_FAILED -} = EVENTS; - -const BID1 = { - width: 980, - height: 240, - cpm: 1.1, - originalCpm: 12.0, - currency: 'USD', - originalCurrency: 'AUX', - timeToRespond: 200, - bidId: '2ec0db240757', - requestId: '2ec240757', - adId: '2ec240757', - auctionId: '1234-4567-7890', - mediaType: 'banner', - meta: { - data: 'value1' - }, - dealId: 'dealid', - getStatusCode() { - return STATUS.GOOD; - } -}; - -const BID2 = Object.assign({}, BID1, { - width: 300, - height: 250, - cpm: 2.2, - originalCpm: 23.0, - currency: 'USD', - originalCurrency: 'AUX', - timeToRespond: 300, - bidId: '30db240757', - requestId: '30db240757', - adId: '30db240757', - meta: { - data: 'value2' - }, - dealId: undefined -}); - -const BID3 = { - bidId: '4ecff0db240757', - requestId: '4ecff0db240757', - adId: '4ecff0db240757', - auctionId: '1234-4567-7890', - mediaType: 'banner', - getStatusCode() { - return STATUS.GOOD; - } -}; - -const MOCK = { - AUCTION_INIT: { - 'auctionId': '1234-4567-7890', - }, - BID_REQUESTED: { - 'bidder': 'adnuntius', - 'auctionId': '1234-4567-7890', - 'bidderRequestId': '1be65d7958826a', - 'bids': [ - { - 'bidder': 'adnuntius', - 'adUnitCode': 'panorama_d_1', - 'bidId': '2ec240757', - }, - { - 'bidder': 'adnuntius', - 'adUnitCode': 'box_d_1', - 'bidId': '30db240757', - }, - { - 'bidder': 'adnuntius', - 'adUnitCode': 'box_d_2', - 'bidId': '4ecff0db240757', - } - ], - 'start': 1519149562216 - }, - BID_RESPONSE: [ - BID1, - BID2 - ], - AUCTION_END: { - }, - BID_WON: [ - Object.assign({}, BID1, { - 'status': 'rendered', - 'requestId': '2ec240757' - }), - Object.assign({}, BID2, { - 'status': 'rendered', - 'requestId': '30db240757' - }) - ], - BIDDER_DONE: { - 'bidderCode': 'adnuntius', - 'bids': [ - BID1, - BID2, - BID3 - ] - }, - BID_TIMEOUT: [ - { - 'bidId': '2ec240757', - 'auctionId': '1234-4567-7890' - } - ], - AD_RENDER_FAILED: [ - { - 'bidId': '2ec240757', - 'reason': AD_RENDER_FAILED_REASON.CANNOT_FIND_AD, - 'message': 'message', - 'bid': BID1 - } - ] -}; - -const ANALYTICS_MESSAGE = { - publisherId: 'CC411485-42BC-4F92-8389-42C503EE38D7', - gdpr: [{}], - auctionIds: ['1234-4567-7890'], - bidAdUnits: [ - { - adUnit: 'panorama_d_1', - adUnitId: 'adunitid', - timeStamp: 1519149562216 - }, - { - adUnit: 'box_d_1', - adUnitId: 'adunitid', - timeStamp: 1519149562216 - } - ], - requests: [ - { - adUnit: 'panorama_d_1', - adUnitId: 'adunitid', - bidder: 'adnuntius', - timeStamp: 1519149562216, - gdpr: 0, - auctionId: 0 - }, - { - adUnit: 'box_d_1', - adUnitId: 'adunitid', - bidder: 'adnuntius', - timeStamp: 1519149562216, - gdpr: 0, - auctionId: 0 - }, - { - adUnit: 'box_d_2', - adUnitId: 'adunitid', - bidder: 'adnuntius', - timeStamp: 1519149562216, - gdpr: 0, - auctionId: 0 - } - ], - responses: [ - { - adUnit: 'panorama_d_1', - adUnitId: 'adunitid', - bidder: 'adnuntius', - timeStamp: 1519149562216, - width: 980, - height: 240, - cpm: 1.1, - currency: 'USD', - originalCpm: 12, - originalCurrency: 'AUX', - ttr: 200, - isBid: true, - mediaType: 1, - gdpr: 0, - auctionId: 0, - meta: { - data: 'value1' - } - }, - { - adUnit: 'box_d_1', - adUnitId: 'adunitid', - bidder: 'adnuntius', - timeStamp: 1519149562216, - width: 300, - height: 250, - cpm: 2.2, - currency: 'USD', - originalCpm: 23, - originalCurrency: 'AUX', - ttr: 300, - isBid: true, - mediaType: 1, - gdpr: 0, - auctionId: 0, - meta: { - data: 'value2' - } - } - ], - timeouts: [], - wins: [ - { - adUnit: 'panorama_d_1', - adUnitId: 'adunitid', - bidder: 'adnuntius', - timeStamp: 1519149562216, - width: 980, - height: 240, - cpm: 1.1, - currency: 'USD', - originalCpm: 12, - originalCurrency: 'AUX', - mediaType: 1, - gdpr: 0, - auctionId: 0, - meta: { - data: 'value1' - }, - dealId: 'dealid' - }, - { - adUnit: 'box_d_1', - adUnitId: 'adunitid', - bidder: 'adnuntius', - timeStamp: 1519149562216, - width: 300, - height: 250, - cpm: 2.2, - currency: 'USD', - originalCpm: 23, - originalCurrency: 'AUX', - mediaType: 1, - gdpr: 0, - auctionId: 0, - meta: { - data: 'value2' - } - } - ], - rf: [ - { - adUnit: 'panorama_d_1', - adUnitId: 'adunitid', - bidder: 'adnuntius', - timeStamp: 1519149562216, - auctionId: 0, - rsn: AD_RENDER_FAILED_REASON.CANNOT_FIND_AD, - msg: 'message' - }, - ] -}; - -function performStandardAuction() { - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - events.emit(BID_WON, MOCK.BID_WON[1]); - events.emit(AD_RENDER_FAILED, MOCK.AD_RENDER_FAILED[0]); -} - -describe('Adnuntius analytics adapter', function () { - let sandbox; - let clock; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - - const element = { - getAttribute: function() { - return 'adunitid'; - } - } - sandbox.stub(events, 'getEvents').returns([]); - sandbox.stub(utils, 'timestamp').returns(1519149562416); - sandbox.stub(document, 'getElementById').returns(element); - - clock = sandbox.useFakeTimers(1519767013781); - }); - - afterEach(function () { - sandbox.restore(); - config.resetConfig(); - clock.runAll(); - clock.restore(); - }); - - describe('when handling events', function () { - adapterManager.registerAnalyticsAdapter({ - code: 'adnuntius', - adapter: adnAnalyticsAdapter - }); - - beforeEach(function () { - adapterManager.enableAnalytics({ - provider: 'adnuntius', - options: { - publisherId: 'CC411485-42BC-4F92-8389-42C503EE38D7' - } - }); - }); - - afterEach(function () { - adnAnalyticsAdapter.disableAnalytics(); - }); - - it('should build a batched message from prebid events', function () { - performStandardAuction(); - - clock.tick(BID_WON_TIMEOUT + 1000); - - expect(server.requests.length).to.equal(1); - const request = server.requests[0]; - - expect(request.url).to.equal('https://analytics.adnuntius.com/prebid'); - - const message = JSON.parse(request.requestBody); - expect(message).to.deep.equal(ANALYTICS_MESSAGE); - }); - - it('should send batched message without BID_WON AND AD_RENDER_FAILED if necessary and further BID_WON and AD_RENDER_FAILED events individually', function () { - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - - clock.tick(BID_WON_TIMEOUT + 1000); - - events.emit(BID_WON, MOCK.BID_WON[1]); - events.emit(AD_RENDER_FAILED, MOCK.AD_RENDER_FAILED[0]); - - expect(server.requests.length).to.equal(3); - - let message = JSON.parse(server.requests[0].requestBody); - expect(message.wins.length).to.equal(1); - expect(message.requests).to.deep.equal(ANALYTICS_MESSAGE.requests); - expect(message.wins[0]).to.deep.equal(ANALYTICS_MESSAGE.wins[0]); - - message = JSON.parse(server.requests[1].requestBody); - expect(message.wins.length).to.equal(1); - expect(message.wins[0]).to.deep.equal(ANALYTICS_MESSAGE.wins[1]); - - message = JSON.parse(server.requests[2].requestBody); - expect(message.rf.length).to.equal(1); - expect(message.rf[0]).to.deep.equal(ANALYTICS_MESSAGE.rf[0]); - }); - - it('should properly mark bids as timed out', function () { - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_TIMEOUT, MOCK.BID_TIMEOUT); - events.emit(AUCTION_END, MOCK.AUCTION_END); - - clock.tick(BID_WON_TIMEOUT + 1000); - - expect(server.requests.length).to.equal(1); - - const message = JSON.parse(server.requests[0].requestBody); - expect(message.timeouts.length).to.equal(1); - expect(message.timeouts[0].bidder).to.equal('adnuntius'); - expect(message.timeouts[0].adUnit).to.equal('panorama_d_1'); - }); - - it('should forward GDPR data', function () { - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, { - 'bidder': 'adnuntius', - 'auctionId': '1234-4567-7890', - 'bidderRequestId': '1be65d7958826a', - 'bids': [ - { - 'bidder': 'adnuntius', - 'adUnitCode': 'panorama_d_1', - 'bidId': '2ec240757', - }, - { - 'bidder': 'adnuntius', - 'adUnitCode': 'box_d_1', - 'bidId': '30db240757', - } - ], - 'start': 1519149562216, - 'gdprConsent': { - 'gdprApplies': true, - 'consentString': 'consentstring' - } - }, - ); - - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_WON, MOCK.BID_WON[0]); - events.emit(AUCTION_END, MOCK.AUCTION_END); - - clock.tick(BID_WON_TIMEOUT + 1000); - - expect(server.requests.length).to.equal(1); - const request = server.requests[0]; - const message = JSON.parse(request.requestBody); - - expect(message.gdpr.length).to.equal(1); - expect(message.gdpr[0].gdprApplies).to.equal(true); - expect(message.gdpr[0].gdprConsent).to.equal('consentstring'); - expect(message.requests.length).to.equal(2); - expect(message.requests[0].gdpr).to.equal(0); - expect(message.requests[1].gdpr).to.equal(0); - - expect(message.responses.length).to.equal(1); - expect(message.responses[0].gdpr).to.equal(0); - - expect(message.wins.length).to.equal(1); - expect(message.wins[0].gdpr).to.equal(0); - }); - - it('should forward runner-up data as given by Adnuntius wrapper', function () { - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_WON, Object.assign({}, - MOCK.BID_WON[0], - { - 'rUp': 'rUpObject' - })); - events.emit(AUCTION_END, MOCK.AUCTION_END); - - clock.tick(BID_WON_TIMEOUT + 1000); - - expect(server.requests.length).to.equal(1); - const request = server.requests[0]; - const message = JSON.parse(request.requestBody); - - expect(message.wins.length).to.equal(1); - expect(message.wins[0].rUp).to.equal('rUpObject'); - }); - }); - - describe('when given other endpoint', function () { - adapterManager.registerAnalyticsAdapter({ - code: 'adnuntius', - adapter: adnAnalyticsAdapter - }); - - beforeEach(function () { - adapterManager.enableAnalytics({ - provider: 'adnuntius', - options: { - publisherId: 'CC411485-42BC-4F92-8389-42C503EE38D7', - endPoint: 'https://whitelabeled.com/analytics/10' - } - }); - }); - - afterEach(function () { - adnAnalyticsAdapter.disableAnalytics(); - }); - - it('should call the endpoint', function () { - performStandardAuction(); - - clock.tick(BID_WON_TIMEOUT + 1000); - - expect(server.requests.length).to.equal(1); - const request = server.requests[0]; - - expect(request.url).to.equal('https://whitelabeled.com/analytics/10'); - }); - }); - - describe('when given extended options', function () { - adapterManager.registerAnalyticsAdapter({ - code: 'adnuntius', - adapter: adnAnalyticsAdapter - }); - - beforeEach(function () { - adapterManager.enableAnalytics({ - provider: 'adnuntius', - options: { - publisherId: 'CC411485-42BC-4F92-8389-42C503EE38D7', - ext: { - testparam: 123 - } - } - }); - }); - - afterEach(function () { - adnAnalyticsAdapter.disableAnalytics(); - }); - - it('should forward the extended options', function () { - performStandardAuction(); - - clock.tick(BID_WON_TIMEOUT + 1000); - - expect(server.requests.length).to.equal(1); - const request = server.requests[0]; - const message = JSON.parse(request.requestBody); - - expect(message.ext).to.not.equal(null); - expect(message.ext.testparam).to.equal(123); - }); - }); -}); diff --git a/test/spec/modules/adnuntiusBidAdapter_spec.js b/test/spec/modules/adnuntiusBidAdapter_spec.js deleted file mode 100644 index 474345564..000000000 --- a/test/spec/modules/adnuntiusBidAdapter_spec.js +++ /dev/null @@ -1,1865 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adnuntiusBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import * as utils from 'src/utils.js'; -import { getStorageManager } from 'src/storageManager.js'; -import { getGlobal } from '../../../src/prebidGlobal.js'; -import {deepClone, getUnixTimestampFromNow} from 'src/utils.js'; -import { getWinDimensions } from '../../../src/utils.js'; - -import {getGlobalVarName} from '../../../src/buildOptions.js'; -import {getExtraWinDimensions} from '../../../libraries/extraWinDimensions/extraWinDimensions.js'; - -describe('adnuntiusBidAdapter', function () { - const sandbox = sinon.createSandbox(); - const URL = 'https://ads.adnuntius.delivery/i?tzo='; - const EURO_URL = 'https://europe.delivery.adnuntius.com/i?tzo='; - const usi = utils.generateUUID() - - const meta = [{ key: 'valueless' }, { value: 'keyless' }, { key: 'voidAuIds' }, { key: 'voidAuIds', value: [{ auId: '11118b6bc', exp: getUnixTimestampFromNow() }, { exp: getUnixTimestampFromNow(1) }] }, { key: 'valid-withnetwork', value: 'also-valid-network', network: 'the-network', exp: getUnixTimestampFromNow(1) }, { key: 'valid', value: 'also-valid', exp: getUnixTimestampFromNow(1) }, { key: 'expired', value: 'fwefew', exp: getUnixTimestampFromNow() }, { key: 'usi', value: 'should be skipped because timestamp', exp: getUnixTimestampFromNow(), network: 'adnuntius' }, { key: 'usi', value: usi, exp: getUnixTimestampFromNow(100), network: 'adnuntius' }, { key: 'usi', value: 'should be skipped because timestamp', exp: getUnixTimestampFromNow() }] - let storage; - - before(() => { - getGlobal().bidderSettings = { - adnuntius: { - storageAllowed: true - } - }; - storage = getStorageManager({ bidderCode: 'adnuntius' }); - resetExpectedUrls(); - }); - - beforeEach(() => { - storage.setDataInLocalStorage('adn.metaData', JSON.stringify(meta)); - resetExpectedUrls(); - }); - - afterEach(function () { - config.resetConfig(); - config.setBidderConfig({ bidders: [] }); - localStorage.removeItem('adn.metaData'); - sandbox.restore(); - resetExpectedUrls(); - }); - - after(() => { - getGlobal().bidderSettings = {}; - resetExpectedUrls(); - }); - - const tzo = new Date().getTimezoneOffset(); - const prebidVersion = getGlobal().version; - - let screen; - let viewport; - let ENDPOINT_URL_BASE; - let ENDPOINT_URL; - let LOCALHOST_URL; - let ENDPOINT_URL_NOCOOKIE; - let ENDPOINT_URL_SEGMENTS; - let ENDPOINT_URL_CONSENT; - - function resetExpectedUrls() { - const winDimensions = getWinDimensions(); - const extraDims = getExtraWinDimensions(); - screen = extraDims.screen.availWidth + 'x' + extraDims.screen.availHeight; - viewport = winDimensions.innerWidth + 'x' + winDimensions.innerHeight; - ENDPOINT_URL_BASE = `${URL}${tzo}&format=prebid&pbv=${prebidVersion}&screen=${screen}&viewport=${viewport}`; - ENDPOINT_URL = `${ENDPOINT_URL_BASE}&userId=${usi}`; - LOCALHOST_URL = `http://localhost:8078/i?tzo=${tzo}&format=prebid&pbv=${prebidVersion}&screen=${screen}&viewport=${viewport}&userId=${usi}`; - ENDPOINT_URL_NOCOOKIE = `${ENDPOINT_URL_BASE}&userId=${usi}&noCookies=true`; - ENDPOINT_URL_SEGMENTS = `${ENDPOINT_URL_BASE}&segments=segment1,segment2,segment3&userId=${usi}`; - ENDPOINT_URL_CONSENT = `${EURO_URL}${tzo}&format=prebid&pbv=${prebidVersion}&consentString=consentString&gdpr=1&screen=${screen}&viewport=${viewport}&userId=${usi}`; - } - - function expectUrlsEqual(actual, expected) { - const a = utils.parseUrl(actual); - const e = utils.parseUrl(expected); - expect(a.protocol + '://' + a.host + a.pathname).to.equal(e.protocol + '://' + e.host + e.pathname); - const sortEntries = obj => Object.entries(obj).sort(); - const sortedExpectations = sortEntries(a.search); - const sortedActuals = sortEntries(e.search); - for (let i = 0; i < sortedExpectations.length; i++) { - const expectation = sortedExpectations[i]; - const actual = sortedActuals[i]; - - const expectationAsString = expectation[0] + ":" + expectation[1]; - const actualAsString = actual[0] + ":" + actual[1]; - expect(expectationAsString).to.equal(actualAsString); - } - expect(sortedExpectations.length).to.equal(sortedActuals.length); - } - - const adapter = newBidder(spec); - - const bidderRequests = [ - { - bidId: 'adn-000000000008b6bc', - bidder: 'adnuntius', - params: { - auId: '000000000008b6bc', - targetId: '123', - network: 'adnuntius', - maxDeals: 1 - }, - mediaTypes: { - banner: { - sizes: [[640, 480], [600, 400]], - } - }, - }, - { - bidId: 'adn-0000000000000551', - bidder: 'adnuntius', - params: { - auId: '0000000000000551', - network: 'adnuntius', - }, - mediaTypes: { - banner: { - sizes: [[1640, 1480], [1600, 1400]], - } - }, - } - ] - - const videoBidderRequest = [ - { - bidId: 'adn-0000000000000551', - bidder: 'adnuntius', - params: { - auId: '0000000000000551', - network: 'adnuntius', - }, - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'instream' - } - }, - } - ]; - - const legacyNativeBidderRequest = {bid: [ - { - bidId: 'adn-0000000000000551', - bidder: 'adnuntius', - params: { - auId: '0000000000000551', - network: 'adnuntius', - }, - mediaTypes: { - native: { - sizes: [[200, 200], [300, 300]], - image: { - required: true, - sizes: [250, 250] - } - } - } - }]}; - - const nativeBidderRequest = {bid: [ - { - bidId: 'adn-0000000000000551', - bidder: 'adnuntius', - params: { - auId: '0000000000000551', - network: 'adnuntius', - }, - mediaTypes: { - native: { - sizes: [[200, 200], [300, 300]], - ortb: { - assets: [{ - id: 1, - required: 1, - img: { - type: 3, - w: 250, - h: 250, - } - }] - } - } - }, - } - ]}; - - const multiBidAndFormatRequest = { - bid: [{ - bidder: 'adnuntius', - bidId: '3a602680158a85', - params: { - auId: '381535', - network: '1287', - bidType: 'netBid', - }, - mediaTypes: { - banner: { - sizes: [[200, 200]] - }, - video: { - playerSize: [200, 200], - context: 'instream' - } - } - }, - { - bidder: 'adnuntius', - bidId: 'fewwef', - params: { - auId: '381535', - network: '1287', - bidType: 'netBid', - targetId: 'fred', - }, - mediaTypes: { - banner: { - sizes: [[200, 200]] - }, - video: { - playerSize: [200, 200], - context: 'instream' - }, - native: { - ortb: { - assets: [{ - id: 1, - required: 1, - img: { - type: 3, - w: 150, - h: 50, - } - }] - } - } - } - }, - { - bidder: 'adnuntius', - bidId: 'pol', - params: { - auId: '381535', - network: '1287', - bidType: 'netBid', - targetId: 'alt', - }, - mediaTypes: { - banner: { - sizes: [[200, 200]] - }, - video: { - playerSize: [200, 200], - context: 'instream' - }, - native: { - ortb: { - assets: [{ - id: 1, - required: 1, - img: { - type: 3, - w: 150, - h: 50, - } - }] - } - } - } - }] - }; - - const multiBidderRequest = [ - { - bidId: 'adn-0000000000000551', - bidder: 'adnuntius', - params: { - auId: '0000000000000551', - network: 'adnuntius', - }, - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'instream' - }, - banner: { - sizes: [[1640, 1480], [1600, 1400]], - } - }, - } - ]; - - const singleBidRequest = { - bid: [ - { - bidder: 'adnuntius', - bidId: 'adn-0000000000000551', - } - ] - }; - - const videoBidRequest = { - bid: videoBidderRequest, - bidder: 'adnuntius', - params: { - bidType: 'justsomestuff-error-handling' - } - }; - - const deals = [ - { - 'destinationUrlEsc': 'http%3A%2F%2Fads.adnuntius.delivery%2Fc%2FyQtMUwYBn5P4v72WJMqLW4z7uJOBFXJTfjoRyz0z_wsAAAAQCtjQz9kbGWD4nuZy3q6HaCYxq6Lckz2kThplNb227EJdQ5032jcIGkf-UrPmXCU2EbXVaQ3Ok6_FNLuIDTONJyx6ZZCB10wGqA3OaSe1EqwQp84u1_5iQZAWDk73UYf7_vcIypn7ev-SICZ3qaevb2jYSRqTVZx6AiBZQQGlzlOOrbZU9AU1F-JwTds-YV3qtJHGlxI2peWFIuxFlOYyeX9Kzg%3Fct%3D673%26r%3Dhttp%253A%252F%252Fadnuntius.com', - 'assets': { - 'Image': { - 'cdnId': 'https://cdn.adnuntius.com/cdn/iBgqruUNbaUb2hmD3vws7WTi84jg_WB_-VOF_FeOZ7A.png', - 'width': '640', - 'height': '480' - } - }, - 'text': {}, - 'choices': {}, - 'clickUrl': 'https://ads.adnuntius.delivery/c/yQtMUwYBn5P4v72WJMqLW4z7uJOBFXJTfjoRyz0z_wsAAAAQCtjQz9kbGWD4nuZy3q6HaCYxq6Lckz2kThplNb227EJdQ5032jcIGkf-UrPmXCU2EbXVaQ3Ok6_FNLuIDTONJyx6ZZCB10wGqA3OaSe1EqwQp84u1_5iQZAWDk73UYf7_vcIypn7ev-SICZ3qaevb2jYSRqTVZx6AiBZQQGlzlOOrbZU9AU1F-JwTds-YV3qtJHGlxI2peWFIuxFlOYyeX9Kzg', - 'urls': { - 'destination': 'https://ads.adnuntius.delivery/c/yQtMUwYBn5P4v72WJMqLW4z7uJOBFXJTfjoRyz0z_wsAAAAQCtjQz9kbGWD4nuZy3q6HaCYxq6Lckz2kThplNb227EJdQ5032jcIGkf-UrPmXCU2EbXVaQ3Ok6_FNLuIDTONJyx6ZZCB10wGqA3OaSe1EqwQp84u1_5iQZAWDk73UYf7_vcIypn7ev-SICZ3qaevb2jYSRqTVZx6AiBZQQGlzlOOrbZU9AU1F-JwTds-YV3qtJHGlxI2peWFIuxFlOYyeX9Kzg?ct=673&r=http%3A%2F%2Fadnuntius.com' - }, - 'urlsEsc': { - 'destination': 'https%3A%2F%2Fads.adnuntius.delivery%2Fc%2FyQtMUwYBn5P4v72WJMqLW4z7uJOBFXJTfjoRyz0z_wsAAAAQCtjQz9kbGWD4nuZy3q6HaCYxq6Lckz2kThplNb227EJdQ5032jcIGkf-UrPmXCU2EbXVaQ3Ok6_FNLuIDTONJyx6ZZCB10wGqA3OaSe1EqwQp84u1_5iQZAWDk73UYf7_vcIypn7ev-SICZ3qaevb2jYSRqTVZx6AiBZQQGlzlOOrbZU9AU1F-JwTds-YV3qtJHGlxI2peWFIuxFlOYyeX9Kzg%3Fct%3D673%26r%3Dhttp%253A%252F%252Fadnuntius.com' - }, - 'advertiserDomains': ['fred.com', 'george.com'], - 'destinationUrls': { - 'destination': 'https://adnuntius.com' - }, - 'cpm': { - 'amount': 9, - 'currency': 'USD' - }, - 'bid': { - 'amount': 0.009, - 'currency': 'USD' - }, - 'grossBid': { - 'amount': 0.009, - 'currency': 'USD' - }, - 'netBid': { - 'amount': 0.0081, - 'currency': 'USD' - }, - 'dealId': 'abc123xyz', - 'impressionTrackingUrls': [], - 'impressionTrackingUrlsEsc': [], - 'adId': 'adn-id-1064238860', - 'selectedColumn': '0', - 'selectedColumnPosition': '0', - 'renderedPixel': 'https://ads.adnuntius.delivery/b/yQtMUwYBn5P4v72WJMqLW4z7uJOBFXJTfjoRyz0z_wsAAAAQCtjQz9kbGWD4nuZy3q6HaCYxq6Lckz2kThplNb227EJdQ5032jcIGkf-UrPmXCU2EbXVaQ3Ok6_FNLuIDTONJyx6ZZCB10wGqA3OaSe1EqwQp84u1_5iQZAWDk73UYf7_vcIypn7ev-SICZ3qaevb2jYSRqTVZx6AiBZQQGlzlOOrbZU9AU1F-JwTds-YV3qtJHGlxI2peWFIuxFlOYyeX9Kzg.html', - 'renderedPixelEsc': 'http%3A%2F%2Fads.adnuntius.delivery%2Fb%2FyQtMUwYBn5P4v72WJMqLW4z7uJOBFXJTfjoRyz0z_wsAAAAQCtjQz9kbGWD4nuZy3q6HaCYxq6Lckz2kThplNb227EJdQ5032jcIGkf-UrPmXCU2EbXVaQ3Ok6_FNLuIDTONJyx6ZZCB10wGqA3OaSe1EqwQp84u1_5iQZAWDk73UYf7_vcIypn7ev-SICZ3qaevb2jYSRqTVZx6AiBZQQGlzlOOrbZU9AU1F-JwTds-YV3qtJHGlxI2peWFIuxFlOYyeX9Kzg.html', - 'visibleUrl': 'https://ads.adnuntius.delivery/s?rt=yQtMUwYBn5P4v72WJMqLW4z7uJOBFXJTfjoRyz0z_wsAAAAQCtjQz9kbGWD4nuZy3q6HaCYxq6Lckz2kThplNb227EJdQ5032jcIGkf-UrPmXCU2EbXVaQ3Ok6_FNLuIDTONJyx6ZZCB10wGqA3OaSe1EqwQp84u1_5iQZAWDk73UYf7_vcIypn7ev-SICZ3qaevb2jYSRqTVZx6AiBZQQGlzlOOrbZU9AU1F-JwTds-YV3qtJHGlxI2peWFIuxFlOYyeX9Kzg', - 'visibleUrlEsc': 'http%3A%2F%2Fads.adnuntius.delivery%2Fs%3Frt%3DyQtMUwYBn5P4v72WJMqLW4z7uJOBFXJTfjoRyz0z_wsAAAAQCtjQz9kbGWD4nuZy3q6HaCYxq6Lckz2kThplNb227EJdQ5032jcIGkf-UrPmXCU2EbXVaQ3Ok6_FNLuIDTONJyx6ZZCB10wGqA3OaSe1EqwQp84u1_5iQZAWDk73UYf7_vcIypn7ev-SICZ3qaevb2jYSRqTVZx6AiBZQQGlzlOOrbZU9AU1F-JwTds-YV3qtJHGlxI2peWFIuxFlOYyeX9Kzg', - 'viewUrl': 'https://ads.adnuntius.delivery/v?rt=yQtMUwYBn5P4v72WJMqLW4z7uJOBFXJTfjoRyz0z_wsAAAAQCtjQz9kbGWD4nuZy3q6HaCYxq6Lckz2kThplNb227EJdQ5032jcIGkf-UrPmXCU2EbXVaQ3Ok6_FNLuIDTONJyx6ZZCB10wGqA3OaSe1EqwQp84u1_5iQZAWDk73UYf7_vcIypn7ev-SICZ3qaevb2jYSRqTVZx6AiBZQQGlzlOOrbZU9AU1F-JwTds-YV3qtJHGlxI2peWFIuxFlOYyeX9Kzg', - 'viewUrlEsc': 'http%3A%2F%2Fads.adnuntius.delivery%2Fv%3Frt%3DyQtMUwYBn5P4v72WJMqLW4z7uJOBFXJTfjoRyz0z_wsAAAAQCtjQz9kbGWD4nuZy3q6HaCYxq6Lckz2kThplNb227EJdQ5032jcIGkf-UrPmXCU2EbXVaQ3Ok6_FNLuIDTONJyx6ZZCB10wGqA3OaSe1EqwQp84u1_5iQZAWDk73UYf7_vcIypn7ev-SICZ3qaevb2jYSRqTVZx6AiBZQQGlzlOOrbZU9AU1F-JwTds-YV3qtJHGlxI2peWFIuxFlOYyeX9Kzg', - 'rt': 'yQtMUwYBn5P4v72WJMqLW4z7uJOBFXJTfjoRyz0z_wsAAAAQCtjQz9kbGWD4nuZy3q6HaCYxq6Lckz2kThplNb227EJdQ5032jcIGkf-UrPmXCU2EbXVaQ3Ok6_FNLuIDTONJyx6ZZCB10wGqA3OaSe1EqwQp84u1_5iQZAWDk73UYf7_vcIypn7ev-SICZ3qaevb2jYSRqTVZx6AiBZQQGlzlOOrbZU9AU1F-JwTds-YV3qtJHGlxI2peWFIuxFlOYyeX9Kzg', - 'creativeWidth': '640', - 'creativeHeight': '480', - 'creativeId': 's90t0q03pm', - 'lineItemId': 'cr3hnkkxhnkw9ldy', - 'layoutId': 'buyers_network_image_layout_1', - 'layoutName': 'Image', - 'layoutExternalReference': '', - 'html': "\n\n\n \n \n \n\n\n
\n
\"\"/
\n
\n \n\n", - 'renderTemplate': '' - } - ]; - - const nativeResponseBody = [ - { - 'auId': '0000000000000551', - 'targetId': 'adn-0000000000000551', - 'nativeJson': { - 'ortb': { - 'link': { - 'url': 'https://whatever.com' - }, - 'assets': [ - { - 'id': 1, - 'required': 1, - 'img': { - 'url': 'http://something.com/something.png' - } - }] - } - }, - 'matchedAdCount': 1, - 'responseId': '', - 'ads': [ - { - 'advertiserDomains': ['adnuntius.com'], - 'creativeWidth': 640, - 'creativeHeight': 640, - 'cpm': { - 'amount': 2000, - 'currency': 'NOK' - }, - 'bid': { - 'amount': 2, - 'currency': 'NOK' - }, - 'grossBid': { - 'amount': 2, - 'currency': 'NOK' - }, - 'netBid': { - 'amount': 2, - 'currency': 'NOK' - }, - 'cost': { - 'amount': 2, - 'currency': 'NOK' - }, - 'assets': { - 'img': { - 'cdnId': 'http://localhost:8079/cdn/9urJusYWpjFDLcpOwfejrkWlLP1heM3vWIJjuHk48BQ.mp4', - 'width': '1920', - 'height': '1080' - } - }, - } - ] - } - ]; - - const nativeResponse = { - body: { - 'adUnits': nativeResponseBody - } - }; - - const nativeMultiFormatResponseBody = JSON.parse(JSON.stringify(nativeResponseBody[0])); - nativeMultiFormatResponseBody.auId = '0000000000381535'; - nativeMultiFormatResponseBody.targetId = 'alt-native'; - - const multiFormatServerResponse = { - body: { - 'adUnits': [ - { - 'auId': '0000000000381535', - 'targetId': '3a602680158a85-video', - 'vastXml': '\n', - 'matchedAdCount': 1, - 'responseId': 'adn-rsp-453419729', - 'ads': [ - { - 'cpm': { - 'amount': 12500.0, - 'currency': 'NOK' - }, - 'bid': { - 'amount': 5, - 'currency': 'NOK' - }, - 'grossBid': { - 'amount': 5, - 'currency': 'NOK' - }, - 'netBid': { - 'amount': 5, - 'currency': 'NOK' - }, - 'cost': { - 'amount': 5, - 'currency': 'NOK' - }, - creativeWidth: 200, - creativeHeight: 240, - 'adId': 'adn-id-615465411', - 'vastXml': '' - } - ] - }, - { - 'auId': '0000000000381535', - 'targetId': 'fred-video', - 'vastXml': '', - 'matchedAdCount': 1, - 'responseId': 'adn-rsp--1809523040', - 'ads': [ - { - 'cpm': { - 'amount': 1500.0, - 'currency': 'NOK' - }, - 'bid': { - 'amount': 1.5, - 'currency': 'NOK' - }, - 'grossBid': { - 'amount': 1.5, - 'currency': 'NOK' - }, - 'netBid': { - 'amount': 1.5, - 'currency': 'NOK' - }, - 'cost': { - 'amount': 1.5, - 'currency': 'NOK' - }, - creativeWidth: 200, - creativeHeight: 240, - 'adId': 'adn-id-344789675', - 'selectedColumn': '0', - 'selectedColumnPosition': '0', - 'vastXml': '\n', - } - ] - }, - nativeMultiFormatResponseBody, - { - 'auId': '0000000000381535', - 'targetId': '3a602680158a85', - 'html': '\u003C!DOCTYPE html\u003E\n\n\u003C/html\u003E', - 'matchedAdCount': 0, - 'responseId': '', - 'ads': [] - }, - { - 'auId': '0000000000381535', - 'renderOption': 'DIV', - 'targetId': 'fred', - 'html': '\u003C!DOCTYPE html\u003E\n\u003C\u003E\n\u003C/html\u003E', - 'matchedAdCount': 1, - 'responseId': 'adn-rsp-1620340740', - 'ads': [ - { - 'destinationUrlEsc': '', - 'cpm': { - 'amount': 1250.0, - 'currency': 'NOK' - }, - creativeWidth: 200, - creativeHeight: 240, - 'bid': { - 'amount': 1.75, - 'currency': 'NOK' - }, - 'grossBid': { - 'amount': 1.75, - 'currency': 'NOK' - }, - 'netBid': { - 'amount': 1.75, - 'currency': 'NOK' - }, - 'cost': { - 'amount': 1.75, - 'currency': 'NOK' - }, - 'html': '\u003Ca \'\u003E\u003C/script\u003E', - } - ] - }, - { - 'auId': '0000000000381535', - 'renderOption': 'DIV', - 'targetId': 'alt', - 'html': '\u003C!DOCTYPE html\u003E\n\u003C\u003E\n\u003C/html\u003E', - 'matchedAdCount': 1, - 'responseId': 'adn-rsp-1620340740', - 'ads': [ - { - 'destinationUrlEsc': '', - 'cpm': { - 'amount': 1000.0, - 'currency': 'NOK' - }, - creativeWidth: 200, - creativeHeight: 240, - 'bid': { - 'amount': 1.75, - 'currency': 'NOK' - }, - 'grossBid': { - 'amount': 1.75, - 'currency': 'NOK' - }, - 'netBid': { - 'amount': 1.75, - 'currency': 'NOK' - }, - 'cost': { - 'amount': 1.75, - 'currency': 'NOK' - }, - 'html': '\u003Ca \'\u003E\u003C/script\u003E', - } - ] - } - ], - 'network': '1287', - 'keywords': [] - } - }; - - const serverResponse = { - body: { - 'adUnits': [ - { - 'auId': '0000000000000551', - 'targetId': 'adn-0000000000000551', - 'html': "\n\n\n \n \n \n\n\n
\n
\"\"/
\n
\n \n\n", - 'matchedAdCount': 1, - 'responseId': 'adn-rsp--229633088', - 'deals': deals, - 'ads': [ - { - 'destinationUrlEsc': 'http%3A%2F%2Fads.adnuntius.delivery%2Fc%2F5Mu-vFVsaf4dWWx8uyZoV7Mz0sPkF1_j9bSupMwX8dMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxqqTYxj2sS0FkMriztxcORshj3zRbT0KsV7XnDXE0F-OsHX7Ok6_FNLuIDTOMJyx6ZZCB10wGqA3OaSe1Eq9D85h8gP1gGsobC0KsAISm_PYNkJ6ve6qZLnB79fX6XHLYSRqTBM8sBCRXQAetnVzeo7AHoQhkFeouS444YA_q4JCTlRI2peWFIuxFlOYyeX9Kzg%3Fct%3D673%26r%3Dhttp%253A%252F%252Fadnuntius.com', - 'assets': { - 'Image': { - 'cdnId': 'https://cdn.adnuntius.com/cdn/iBgqruUNbaUb2hmD3vws7WTi84jg_WB_-VOF_FeOZ7A.png', - 'width': '640', - 'height': '480' - } - }, - 'dealId': 'not-in-deal-array-here', - 'text': {}, - 'choices': {}, - 'clickUrl': 'https://ads.adnuntius.delivery/c/5Mu-vFVsaf4dWWx8uyZoV7Mz0sPkF1_j9bSupMwX8dMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxqqTYxj2sS0FkMriztxcORshj3zRbT0KsV7XnDXE0F-OsHX7Ok6_FNLuIDTOMJyx6ZZCB10wGqA3OaSe1Eq9D85h8gP1gGsobC0KsAISm_PYNkJ6ve6qZLnB79fX6XHLYSRqTBM8sBCRXQAetnVzeo7AHoQhkFeouS444YA_q4JCTlRI2peWFIuxFlOYyeX9Kzg', - 'urls': { - 'destination': 'https://ads.adnuntius.delivery/c/5Mu-vFVsaf4dWWx8uyZoV7Mz0sPkF1_j9bSupMwX8dMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxqqTYxj2sS0FkMriztxcORshj3zRbT0KsV7XnDXE0F-OsHX7Ok6_FNLuIDTOMJyx6ZZCB10wGqA3OaSe1Eq9D85h8gP1gGsobC0KsAISm_PYNkJ6ve6qZLnB79fX6XHLYSRqTBM8sBCRXQAetnVzeo7AHoQhkFeouS444YA_q4JCTlRI2peWFIuxFlOYyeX9Kzg?ct=673&r=http%3A%2F%2Fadnuntius.com' - }, - 'urlsEsc': { - 'destination': 'http%3A%2F%2Fads.adnuntius.delivery%2Fc%2F5Mu-vFVsaf4dWWx8uyZoV7Mz0sPkF1_j9bSupMwX8dMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxqqTYxj2sS0FkMriztxcORshj3zRbT0KsV7XnDXE0F-OsHX7Ok6_FNLuIDTOMJyx6ZZCB10wGqA3OaSe1Eq9D85h8gP1gGsobC0KsAISm_PYNkJ6ve6qZLnB79fX6XHLYSRqTBM8sBCRXQAetnVzeo7AHoQhkFeouS444YA_q4JCTlRI2peWFIuxFlOYyeX9Kzg%3Fct%3D673%26r%3Dhttp%253A%252F%252Fadnuntius.com' - }, - 'destinationUrls': { - 'destination': 'https://adnuntius.com' - }, - 'cpm': { - 'amount': 9, - 'currency': 'USD' - }, - 'bid': { - 'amount': 0.009, - 'currency': 'USD' - }, - 'grossBid': { - 'amount': 0.009, - 'currency': 'USD' - }, - 'netBid': { - 'amount': 0.0081, - 'currency': 'USD' - }, - 'impressionTrackingUrls': [], - 'impressionTrackingUrlsEsc': [], - 'adId': 'adn-id-1488629603', - 'selectedColumn': '0', - 'selectedColumnPosition': '0', - 'renderedPixel': 'https://ads.adnuntius.delivery/b/5Mu-vFVsaf4dWWx8uyZoV7Mz0sPkF1_j9bSupMwX8dMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxqqTYxj2sS0FkMriztxcORshj3zRbT0KsV7XnDXE0F-OsHX7Ok6_FNLuIDTOMJyx6ZZCB10wGqA3OaSe1Eq9D85h8gP1gGsobC0KsAISm_PYNkJ6ve6qZLnB79fX6XHLYSRqTBM8sBCRXQAetnVzeo7AHoQhkFeouS444YA_q4JCTlRI2peWFIuxFlOYyeX9Kzg.html', - 'renderedPixelEsc': 'http%3A%2F%2Fads.adnuntius.delivery%2Fb%2F5Mu-vFVsaf4dWWx8uyZoV7Mz0sPkF1_j9bSupMwX8dMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxqqTYxj2sS0FkMriztxcORshj3zRbT0KsV7XnDXE0F-OsHX7Ok6_FNLuIDTOMJyx6ZZCB10wGqA3OaSe1Eq9D85h8gP1gGsobC0KsAISm_PYNkJ6ve6qZLnB79fX6XHLYSRqTBM8sBCRXQAetnVzeo7AHoQhkFeouS444YA_q4JCTlRI2peWFIuxFlOYyeX9Kzg.html', - 'visibleUrl': 'https://ads.adnuntius.delivery/s?rt=5Mu-vFVsaf4dWWx8uyZoV7Mz0sPkF1_j9bSupMwX8dMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxqqTYxj2sS0FkMriztxcORshj3zRbT0KsV7XnDXE0F-OsHX7Ok6_FNLuIDTOMJyx6ZZCB10wGqA3OaSe1Eq9D85h8gP1gGsobC0KsAISm_PYNkJ6ve6qZLnB79fX6XHLYSRqTBM8sBCRXQAetnVzeo7AHoQhkFeouS444YA_q4JCTlRI2peWFIuxFlOYyeX9Kzg', - 'visibleUrlEsc': 'http%3A%2F%2Fads.adnuntius.delivery%2Fs%3Frt%3D5Mu-vFVsaf4dWWx8uyZoV7Mz0sPkF1_j9bSupMwX8dMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxqqTYxj2sS0FkMriztxcORshj3zRbT0KsV7XnDXE0F-OsHX7Ok6_FNLuIDTOMJyx6ZZCB10wGqA3OaSe1Eq9D85h8gP1gGsobC0KsAISm_PYNkJ6ve6qZLnB79fX6XHLYSRqTBM8sBCRXQAetnVzeo7AHoQhkFeouS444YA_q4JCTlRI2peWFIuxFlOYyeX9Kzg', - 'viewUrl': 'https://ads.adnuntius.delivery/v?rt=5Mu-vFVsaf4dWWx8uyZoV7Mz0sPkF1_j9bSupMwX8dMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxqqTYxj2sS0FkMriztxcORshj3zRbT0KsV7XnDXE0F-OsHX7Ok6_FNLuIDTOMJyx6ZZCB10wGqA3OaSe1Eq9D85h8gP1gGsobC0KsAISm_PYNkJ6ve6qZLnB79fX6XHLYSRqTBM8sBCRXQAetnVzeo7AHoQhkFeouS444YA_q4JCTlRI2peWFIuxFlOYyeX9Kzg', - 'viewUrlEsc': 'http%3A%2F%2Fads.adnuntius.delivery%2Fv%3Frt%3D5Mu-vFVsaf4dWWx8uyZoV7Mz0sPkF1_j9bSupMwX8dMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxqqTYxj2sS0FkMriztxcORshj3zRbT0KsV7XnDXE0F-OsHX7Ok6_FNLuIDTOMJyx6ZZCB10wGqA3OaSe1Eq9D85h8gP1gGsobC0KsAISm_PYNkJ6ve6qZLnB79fX6XHLYSRqTBM8sBCRXQAetnVzeo7AHoQhkFeouS444YA_q4JCTlRI2peWFIuxFlOYyeX9Kzg', - 'rt': '5Mu-vFVsaf4dWWx8uyZoV7Mz0sPkF1_j9bSupMwX8dMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxqqTYxj2sS0FkMriztxcORshj3zRbT0KsV7XnDXE0F-OsHX7Ok6_FNLuIDTOMJyx6ZZCB10wGqA3OaSe1Eq9D85h8gP1gGsobC0KsAISm_PYNkJ6ve6qZLnB79fX6XHLYSRqTBM8sBCRXQAetnVzeo7AHoQhkFeouS444YA_q4JCTlRI2peWFIuxFlOYyeX9Kzg', - 'creativeWidth': '640', - 'creativeHeight': '480', - 'creativeId': 's90t0q03pm', - 'lineItemId': 'cr3hnkkxhnkw9ldy', - 'layoutId': 'buyers_network_image_layout_1', - 'layoutName': 'Image', - 'layoutExternalReference': '', - 'html': '', - 'renderTemplate': '' - } - ] - }, - { - 'auId': '000000000008b6bc', - 'targetId': 'adn-000000000008b6bc', - 'matchedAdCount': 0, - 'responseId': 'adn-rsp-1460129238', - } - ], - 'metaData': { - 'usi': 'from-api-server dude', - 'voidAuIds': '00000000000abcde;00000000000fffff', - 'randomApiKey': 'randomApiValue' - }, - 'network': 'some-network-id' - } - } - const serverVideoResponse = { - body: { - 'adUnits': [ - { - 'auId': '0000000000000551', - 'targetId': 'adn-0000000000000551', - 'vastXml': '\\n\\n \\n Adnuntius\\n adn-id-500662301\\n \\n \\n \\n \\n 00:00:15\\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n \\n\\n', - 'matchedAdCount': 1, - 'responseId': '', - 'deals': [ - { - 'destinationUrlEsc': '', - 'assets': { - 'Video': { - 'cdnId': 'http://localhost:8079/cdn/9urJusYWpjFDLcpOwfejrkWlLP1heM3vWIJjuHk48BQ.mp4', - 'width': '1920', - 'height': '1080' - } - }, - 'text': { - 'thirdQuartile': { - 'content': 'whatevs', - 'length': '7', - 'minLength': '1', - 'maxLength': '64' - }, - 'complete': { - 'content': 'whatevs', - 'length': '7', - 'minLength': '1', - 'maxLength': '64' - }, - 'firstQuartile': { - 'content': 'whatevs', - 'length': '7', - 'minLength': '1', - 'maxLength': '64' - } - }, - 'choices': {}, - 'clickUrl': 'http://localhost:8078/c/7MRhdEcIndSrWxWhFtMVVnDULl8BOwEaV6vi9558AbYAAAAQCtjQz9kbGWD4nuZy3q6HaCYx_6vZlT33ShgzYb616hZZSpoy2jkAHkGrB-XmXyJmEOCSQ0PLk6_FNLuCBzONJyx6ZZCB10wGqA3OaSe1EqMWoJp41f83FcJLX0SpBoT1-qBbx5_8La-ULiAnqaGtMRDYSRqTBZh5DCANFQWnm1fa8rEE9VRgRORwTNxvZFjq5JCSkEQ2peWFIuxFlOYyeX9Kzg', - 'urls': { - 'destinationUrl': 'http://localhost:8078/c/7MRhdEcIndSrWxWhFtMVVnDULl8BOwEaV6vi9558AbYAAAAQCtjQz9kbGWD4nuZy3q6HaCYx_6vZlT33ShgzYb616hZZSpoy2jkAHkGrB-XmXyJmEOCSQ0PLk6_FNLuCBzONJyx6ZZCB10wGqA3OaSe1EqMWoJp41f83FcJLX0SpBoT1-qBbx5_8La-ULiAnqaGtMRDYSRqTBZh5DCANFQWnm1fa8rEE9VRgRORwTNxvZFjq5JCSkEQ2peWFIuxFlOYyeX9Kzg?ct=682&r=http%3A%2F%2Fadnuntius.com' - }, - 'urlsEsc': { - 'destinationUrl': 'http%3A%2F%2Flocalhost%3A8078%2Fc%2F7MRhdEcIndSrWxWhFtMVVnDULl8BOwEaV6vi9558AbYAAAAQCtjQz9kbGWD4nuZy3q6HaCYx_6vZlT33ShgzYb616hZZSpoy2jkAHkGrB-XmXyJmEOCSQ0PLk6_FNLuCBzONJyx6ZZCB10wGqA3OaSe1EqMWoJp41f83FcJLX0SpBoT1-qBbx5_8La-ULiAnqaGtMRDYSRqTBZh5DCANFQWnm1fa8rEE9VRgRORwTNxvZFjq5JCSkEQ2peWFIuxFlOYyeX9Kzg%3Fct%3D682%26r%3Dhttp%253A%252F%252Fadnuntius.com' - }, - 'destinationUrls': { - 'destinationUrl': 'http://adnuntius.com' - }, - 'cpm': { - 'amount': 9, - 'currency': 'USD' - }, - 'bid': { - 'amount': 0.009, - 'currency': 'USD' - }, - 'grossBid': { - 'amount': 0.009, - 'currency': 'USD' - }, - 'netBid': { - 'amount': 0.0081, - 'currency': 'USD' - }, - 'dealId': 'abc123xyz', - 'impressionTrackingUrls': [], - 'impressionTrackingUrlsEsc': [], - 'adId': 'adn-id-1465065992', - 'selectedColumn': '0', - 'selectedColumnPosition': '0', - 'renderedPixel': 'http://localhost:8078/b/7MRhdEcIndSrWxWhFtMVVnDULl8BOwEaV6vi9558AbYAAAAQCtjQz9kbGWD4nuZy3q6HaCYx_6vZlT33ShgzYb616hZZSpoy2jkAHkGrB-XmXyJmEOCSQ0PLk6_FNLuCBzONJyx6ZZCB10wGqA3OaSe1EqMWoJp41f83FcJLX0SpBoT1-qBbx5_8La-ULiAnqaGtMRDYSRqTBZh5DCANFQWnm1fa8rEE9VRgRORwTNxvZFjq5JCSkEQ2peWFIuxFlOYyeX9Kzg.html', - 'renderedPixelEsc': 'http%3A%2F%2Flocalhost%3A8078%2Fb%2F7MRhdEcIndSrWxWhFtMVVnDULl8BOwEaV6vi9558AbYAAAAQCtjQz9kbGWD4nuZy3q6HaCYx_6vZlT33ShgzYb616hZZSpoy2jkAHkGrB-XmXyJmEOCSQ0PLk6_FNLuCBzONJyx6ZZCB10wGqA3OaSe1EqMWoJp41f83FcJLX0SpBoT1-qBbx5_8La-ULiAnqaGtMRDYSRqTBZh5DCANFQWnm1fa8rEE9VRgRORwTNxvZFjq5JCSkEQ2peWFIuxFlOYyeX9Kzg.html', - 'visibleUrl': 'http://localhost:8078/s?rt=7MRhdEcIndSrWxWhFtMVVnDULl8BOwEaV6vi9558AbYAAAAQCtjQz9kbGWD4nuZy3q6HaCYx_6vZlT33ShgzYb616hZZSpoy2jkAHkGrB-XmXyJmEOCSQ0PLk6_FNLuCBzONJyx6ZZCB10wGqA3OaSe1EqMWoJp41f83FcJLX0SpBoT1-qBbx5_8La-ULiAnqaGtMRDYSRqTBZh5DCANFQWnm1fa8rEE9VRgRORwTNxvZFjq5JCSkEQ2peWFIuxFlOYyeX9Kzg', - 'visibleUrlEsc': 'http%3A%2F%2Flocalhost%3A8078%2Fs%3Frt%3D7MRhdEcIndSrWxWhFtMVVnDULl8BOwEaV6vi9558AbYAAAAQCtjQz9kbGWD4nuZy3q6HaCYx_6vZlT33ShgzYb616hZZSpoy2jkAHkGrB-XmXyJmEOCSQ0PLk6_FNLuCBzONJyx6ZZCB10wGqA3OaSe1EqMWoJp41f83FcJLX0SpBoT1-qBbx5_8La-ULiAnqaGtMRDYSRqTBZh5DCANFQWnm1fa8rEE9VRgRORwTNxvZFjq5JCSkEQ2peWFIuxFlOYyeX9Kzg', - 'viewUrl': 'http://localhost:8078/v?rt=7MRhdEcIndSrWxWhFtMVVnDULl8BOwEaV6vi9558AbYAAAAQCtjQz9kbGWD4nuZy3q6HaCYx_6vZlT33ShgzYb616hZZSpoy2jkAHkGrB-XmXyJmEOCSQ0PLk6_FNLuCBzONJyx6ZZCB10wGqA3OaSe1EqMWoJp41f83FcJLX0SpBoT1-qBbx5_8La-ULiAnqaGtMRDYSRqTBZh5DCANFQWnm1fa8rEE9VRgRORwTNxvZFjq5JCSkEQ2peWFIuxFlOYyeX9Kzg', - 'viewUrlEsc': 'http%3A%2F%2Flocalhost%3A8078%2Fv%3Frt%3D7MRhdEcIndSrWxWhFtMVVnDULl8BOwEaV6vi9558AbYAAAAQCtjQz9kbGWD4nuZy3q6HaCYx_6vZlT33ShgzYb616hZZSpoy2jkAHkGrB-XmXyJmEOCSQ0PLk6_FNLuCBzONJyx6ZZCB10wGqA3OaSe1EqMWoJp41f83FcJLX0SpBoT1-qBbx5_8La-ULiAnqaGtMRDYSRqTBZh5DCANFQWnm1fa8rEE9VRgRORwTNxvZFjq5JCSkEQ2peWFIuxFlOYyeX9Kzg', - 'rt': '7MRhdEcIndSrWxWhFtMVVnDULl8BOwEaV6vi9558AbYAAAAQCtjQz9kbGWD4nuZy3q6HaCYx_6vZlT33ShgzYb616hZZSpoy2jkAHkGrB-XmXyJmEOCSQ0PLk6_FNLuCBzONJyx6ZZCB10wGqA3OaSe1EqMWoJp41f83FcJLX0SpBoT1-qBbx5_8La-ULiAnqaGtMRDYSRqTBZh5DCANFQWnm1fa8rEE9VRgRORwTNxvZFjq5JCSkEQ2peWFIuxFlOYyeX9Kzg', - 'creativeWidth': '640', - 'creativeHeight': '480', - 'creativeId': 'p6sqtvcgxczy258j', - 'lineItemId': 'cr3hnkkxhnkw9ldy', - 'layoutId': 'buyers_networkvast_single_format_layout', - 'layoutName': 'Vast (video upload)', - 'layoutExternalReference': '', - 'vastXml': '\n\n \n Adnuntius\n adn-id-1465065992\n \n \n \n \n 00:00:15\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n\n', - 'renderTemplate': '\n \n Adnuntius\n {{{adId}}}\n \n \n {{#ifEquals vastVersion "4.0"}}\n {{/ifEquals}}\n \n {{assets.Video.duration}}\n \n \n {{#unless preview}}{{#each impressionTrackingUrls}}\n {{/each}}{{/unless}}{{#if text.firstQuartile.content}}\n {{/if}}\n {{#if text.thirdQuartile.content}}\n {{/if}}{{#if text.complete.content}}\n {{/if}}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n' - } - ], - 'ads': [ - { - 'destinationUrlEsc': '', - 'dealId': 'not-in-deal-array', - 'assets': { - 'Video': { - 'cdnId': 'http://localhost:8079/cdn/9urJusYWpjFDLcpOwfejrkWlLP1heM3vWIJjuHk48BQ.mp4', - 'width': '1920', - 'height': '1080' - } - }, - 'text': { - 'thirdQuartile': { - 'content': 'whatevs', - 'length': '7', - 'minLength': '1', - 'maxLength': '64' - }, - 'complete': { - 'content': 'whatevs', - 'length': '7', - 'minLength': '1', - 'maxLength': '64' - }, - 'firstQuartile': { - 'content': 'whatevs', - 'length': '7', - 'minLength': '1', - 'maxLength': '64' - } - }, - 'choices': {}, - 'clickUrl': 'http://localhost:8078/c/ZxGSsEJ8IzI8iCTQ17fHxnE29-y7VILLg2CLjhEbphMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxpfXelzygS0s1MLax6koIS8pnjDAOShX4CbPkDyIzELe5BlfLk6_FNLuCBzOMJyx6ZZCB10wGqA3OaSe1EqpGosot0vsyFMtIWRWtUoKk-aANx531KaOWLyonoP2uC6UpxkXRUJ8iVCcMF1KmmAfe9rNYplI0E-ErHtVvZgm7uZeal_VymQxr0zkhjS_bW0PX', - 'urls': { - 'destinationUrl': 'http://localhost:8078/c/ZxGSsEJ8IzI8iCTQ17fHxnE29-y7VILLg2CLjhEbphMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxpfXelzygS0s1MLax6koIS8pnjDAOShX4CbPkDyIzELe5BlfLk6_FNLuCBzOMJyx6ZZCB10wGqA3OaSe1EqpGosot0vsyFMtIWRWtUoKk-aANx531KaOWLyonoP2uC6UpxkXRUJ8iVCcMF1KmmAfe9rNYplI0E-ErHtVvZgm7uZeal_VymQxr0zkhjS_bW0PX?ct=682&r=http%3A%2F%2Fadnuntius.com' - }, - 'urlsEsc': { - 'destinationUrl': 'http%3A%2F%2Flocalhost%3A8078%2Fc%2FZxGSsEJ8IzI8iCTQ17fHxnE29-y7VILLg2CLjhEbphMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxpfXelzygS0s1MLax6koIS8pnjDAOShX4CbPkDyIzELe5BlfLk6_FNLuCBzOMJyx6ZZCB10wGqA3OaSe1EqpGosot0vsyFMtIWRWtUoKk-aANx531KaOWLyonoP2uC6UpxkXRUJ8iVCcMF1KmmAfe9rNYplI0E-ErHtVvZgm7uZeal_VymQxr0zkhjS_bW0PX%3Fct%3D682%26r%3Dhttp%253A%252F%252Fadnuntius.com' - }, - 'destinationUrls': { - 'destinationUrl': 'http://adnuntius.com' - }, - 'cpm': { - 'amount': 9, - 'currency': 'USD' - }, - 'bid': { - 'amount': 0.009, - 'currency': 'USD' - }, - 'grossBid': { - 'amount': 0.009, - 'currency': 'USD' - }, - 'netBid': { - 'amount': 0.0081, - 'currency': 'USD' - }, - 'impressionTrackingUrls': [], - 'impressionTrackingUrlsEsc': [], - 'adId': 'adn-id-500662301', - 'selectedColumn': '0', - 'selectedColumnPosition': '0', - 'renderedPixel': 'http://localhost:8078/b/ZxGSsEJ8IzI8iCTQ17fHxnE29-y7VILLg2CLjhEbphMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxpfXelzygS0s1MLax6koIS8pnjDAOShX4CbPkDyIzELe5BlfLk6_FNLuCBzOMJyx6ZZCB10wGqA3OaSe1EqpGosot0vsyFMtIWRWtUoKk-aANx531KaOWLyonoP2uC6UpxkXRUJ8iVCcMF1KmmAfe9rNYplI0E-ErHtVvZgm7uZeal_VymQxr0zkhjS_bW0PX.html', - 'renderedPixelEsc': 'http%3A%2F%2Flocalhost%3A8078%2Fb%2FZxGSsEJ8IzI8iCTQ17fHxnE29-y7VILLg2CLjhEbphMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxpfXelzygS0s1MLax6koIS8pnjDAOShX4CbPkDyIzELe5BlfLk6_FNLuCBzOMJyx6ZZCB10wGqA3OaSe1EqpGosot0vsyFMtIWRWtUoKk-aANx531KaOWLyonoP2uC6UpxkXRUJ8iVCcMF1KmmAfe9rNYplI0E-ErHtVvZgm7uZeal_VymQxr0zkhjS_bW0PX.html', - 'visibleUrl': 'http://localhost:8078/s?rt=ZxGSsEJ8IzI8iCTQ17fHxnE29-y7VILLg2CLjhEbphMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxpfXelzygS0s1MLax6koIS8pnjDAOShX4CbPkDyIzELe5BlfLk6_FNLuCBzOMJyx6ZZCB10wGqA3OaSe1EqpGosot0vsyFMtIWRWtUoKk-aANx531KaOWLyonoP2uC6UpxkXRUJ8iVCcMF1KmmAfe9rNYplI0E-ErHtVvZgm7uZeal_VymQxr0zkhjS_bW0PX', - 'visibleUrlEsc': 'http%3A%2F%2Flocalhost%3A8078%2Fs%3Frt%3DZxGSsEJ8IzI8iCTQ17fHxnE29-y7VILLg2CLjhEbphMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxpfXelzygS0s1MLax6koIS8pnjDAOShX4CbPkDyIzELe5BlfLk6_FNLuCBzOMJyx6ZZCB10wGqA3OaSe1EqpGosot0vsyFMtIWRWtUoKk-aANx531KaOWLyonoP2uC6UpxkXRUJ8iVCcMF1KmmAfe9rNYplI0E-ErHtVvZgm7uZeal_VymQxr0zkhjS_bW0PX', - 'viewUrl': 'http://localhost:8078/v?rt=ZxGSsEJ8IzI8iCTQ17fHxnE29-y7VILLg2CLjhEbphMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxpfXelzygS0s1MLax6koIS8pnjDAOShX4CbPkDyIzELe5BlfLk6_FNLuCBzOMJyx6ZZCB10wGqA3OaSe1EqpGosot0vsyFMtIWRWtUoKk-aANx531KaOWLyonoP2uC6UpxkXRUJ8iVCcMF1KmmAfe9rNYplI0E-ErHtVvZgm7uZeal_VymQxr0zkhjS_bW0PX', - 'viewUrlEsc': 'http%3A%2F%2Flocalhost%3A8078%2Fv%3Frt%3DZxGSsEJ8IzI8iCTQ17fHxnE29-y7VILLg2CLjhEbphMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxpfXelzygS0s1MLax6koIS8pnjDAOShX4CbPkDyIzELe5BlfLk6_FNLuCBzOMJyx6ZZCB10wGqA3OaSe1EqpGosot0vsyFMtIWRWtUoKk-aANx531KaOWLyonoP2uC6UpxkXRUJ8iVCcMF1KmmAfe9rNYplI0E-ErHtVvZgm7uZeal_VymQxr0zkhjS_bW0PX', - 'rt': 'ZxGSsEJ8IzI8iCTQ17fHxnE29-y7VILLg2CLjhEbphMAAAAQCtjQz9kbGWD4nuZy3q6HaCYxpfXelzygS0s1MLax6koIS8pnjDAOShX4CbPkDyIzELe5BlfLk6_FNLuCBzOMJyx6ZZCB10wGqA3OaSe1EqpGosot0vsyFMtIWRWtUoKk-aANx531KaOWLyonoP2uC6UpxkXRUJ8iVCcMF1KmmAfe9rNYplI0E-ErHtVvZgm7uZeal_VymQxr0zkhjS_bW0PX', - 'creativeWidth': '640', - 'creativeHeight': '480', - 'creativeId': 'p6sqtvcgxczy258j', - 'lineItemId': 'cr3hnkkxhnkw9ldy', - 'layoutId': 'buyers_networkvast_single_format_layout', - 'layoutName': 'Vast (video upload)', - 'layoutExternalReference': '', - 'vastXml': '\n \n Adnuntius\n adn-id-500662301\n \n \n \n \n 00:00:15\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n \n', - 'renderTemplate': '\n \n Adnuntius\n {{{adId}}}\n \n \n {{#ifEquals vastVersion "4.0"}}\n {{/ifEquals}}\n \n {{assets.Video.duration}}\n \n \n {{#unless preview}}{{#each impressionTrackingUrls}}\n {{/each}}{{/unless}}{{#if text.firstQuartile.content}}\n {{/if}}\n {{#if text.thirdQuartile.content}}\n {{/if}}{{#if text.complete.content}}\n {{/if}}\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n' - } - ] - }, - { - 'auId': '000000000008b6bc', - 'targetId': 'adn-000000000008b6bc', - 'matchedAdCount': 0, - 'responseId': 'adn-rsp-1460129238', - } - ] - } - } - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bidderRequests[0])).to.equal(true); - }); - }); - - describe('buildRequests', function () { - it('Test requests', function () { - const winDimensions = getWinDimensions(); - const extraDims = getExtraWinDimensions(); - const screen = extraDims.screen.availWidth + 'x' + extraDims.screen.availHeight; - const viewport = winDimensions.innerWidth + 'x' + winDimensions.innerHeight; - const prebidVersion = window[getGlobalVarName()].version; - const tzo = new Date().getTimezoneOffset(); - const ENDPOINT_URL = `https://ads.adnuntius.delivery/i?tzo=${tzo}&format=prebid&pbv=${prebidVersion}&screen=${screen}&viewport=${viewport}&userId=${usi}`; - - const bidderRequests = [ - { - bidId: 'adn-000000000008b6bc', - bidder: 'adnuntius', - params: { - auId: '000000000008b6bc', - targetId: '123', - network: 'adnuntius', - maxDeals: 1 - }, - mediaTypes: { - banner: { - sizes: [[640, 480], [600, 400]], - } - }, - }, - { - bidId: 'adn-0000000000000551', - bidder: 'adnuntius', - params: { - auId: '0000000000000551', - network: 'adnuntius', - }, - mediaTypes: { - banner: { - sizes: [[1640, 1480], [1600, 1400]], - } - }, - } - ]; - - const request = spec.buildRequests(bidderRequests, { - refererInfo: { - canonicalUrl: 'https://canonical.com/page.html', - page: 'https://canonical.com/something-else.html' - } - }); - - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('bid'); - const bid = request[0].bid[0]; - expect(bid).to.have.property('bidId'); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL); - expect(request[0]).to.have.property('data'); - expect(request[0].data).to.equal(JSON.stringify({ - adUnits: [ - { - auId: '000000000008b6bc', - targetId: '123', - maxDeals: 1, - dimensions: [[640, 480], [600, 400]] - }, - { - auId: '0000000000000551', - targetId: 'adn-0000000000000551', - dimensions: [[1640, 1480], [1600, 1400]] - } - ], - context: 'https://canonical.com/something-else.html', - canonical: 'https://canonical.com/page.html' - })); - }); - - it('should pass for different end points in config', function () { - config.setConfig({ - env: 'localhost', - protocol: 'http' - }) - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, LOCALHOST_URL); - }); - - it('Test specifying deal IDs', function () { - const dealIdRequest = deepClone(bidderRequests); - dealIdRequest[0].params.dealId = 'simplestringdeal'; - dealIdRequest[0].params.inventory = { - pmp: { - deals: [{id: '123', bidfloor: 12, bidfloorcur: 'USD'}] - } - }; - let request = spec.buildRequests(dealIdRequest, {}); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('bid'); - const bid = request[0].bid[0] - expect(bid).to.have.property('bidId'); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL); - expect(request[0]).to.have.property('data'); - expect(request[0].data).to.equal('{"adUnits":[{"auId":"000000000008b6bc","targetId":"123","dealId":"simplestringdeal","maxDeals":1,"dimensions":[[640,480],[600,400]]},{"auId":"0000000000000551","targetId":"adn-0000000000000551","dimensions":[[1640,1480],[1600,1400]]}]}'); - - delete dealIdRequest[0].params.dealId; - request = spec.buildRequests(dealIdRequest, {}); - expect(request[0].data).to.equal('{"adUnits":[{"auId":"000000000008b6bc","targetId":"123","dealId":[{"id":"123","bidfloor":12,"bidfloorcur":"USD"}],"maxDeals":1,"dimensions":[[640,480],[600,400]]},{"auId":"0000000000000551","targetId":"adn-0000000000000551","dimensions":[[1640,1480],[1600,1400]]}]}'); - }); - - it('Test requests with no local storage', function () { - storage.setDataInLocalStorage('adn.metaData', JSON.stringify([{}])); - const request = spec.buildRequests(bidderRequests, {}); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('bid'); - const bid = request[0].bid[0] - expect(bid).to.have.property('bidId'); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL_BASE); - expect(request[0]).to.have.property('data'); - expect(request[0].data).to.equal('{"adUnits":[{"auId":"000000000008b6bc","targetId":"123","maxDeals":1,"dimensions":[[640,480],[600,400]]},{"auId":"0000000000000551","targetId":"adn-0000000000000551","dimensions":[[1640,1480],[1600,1400]]}]}'); - - localStorage.removeItem('adn.metaData'); - const request2 = spec.buildRequests(bidderRequests, {}); - expect(request2.length).to.equal(1); - expect(request2[0]).to.have.property('url'); - expectUrlsEqual(request2[0].url, ENDPOINT_URL_BASE); - }); - - it('Test request changes for voided au ids', function () { - storage.setDataInLocalStorage('adn.metaData', JSON.stringify([{ key: 'voidAuIds', value: [{ auId: '11118b6bc', exp: getUnixTimestampFromNow(1) }, { auId: '0000000000000023', exp: getUnixTimestampFromNow(1) }] }])); - const bRequests = bidderRequests.concat([{ - bidId: 'adn-11118b6bc', - bidder: 'adnuntius', - params: { - auId: '11118b6bc', - network: 'adnuntius', - }, - mediaTypes: { - banner: { - sizes: [[1640, 1480], [1600, 1400]], - } - }, - }]); - bRequests.push({ - bidId: 'adn-23', - bidder: 'adnuntius', - params: { - auId: '23', - network: 'adnuntius', - }, - mediaTypes: { - banner: { - sizes: [[1640, 1480], [1600, 1400]], - } - }, - }); - bRequests.push({ - bidId: 'adn-13', - bidder: 'adnuntius', - params: { - auId: '13', - network: 'adnuntius', - }, - mediaTypes: { - banner: { - sizes: [[164, 140], [10, 1400]], - } - }, - }); - const request = spec.buildRequests(bRequests, {}); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('bid'); - const bid = request[0].bid[0] - expect(bid).to.have.property('bidId'); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL_BASE); - expect(request[0]).to.have.property('data'); - expect(request[0].data).to.equal('{"adUnits":[{"auId":"000000000008b6bc","targetId":"123","maxDeals":1,"dimensions":[[640,480],[600,400]]},{"auId":"0000000000000551","targetId":"adn-0000000000000551","dimensions":[[1640,1480],[1600,1400]]},{"auId":"13","targetId":"adn-13","dimensions":[[164,140],[10,1400]]}]}'); - }); - - it('Test Video requests', function () { - const request = spec.buildRequests(videoBidderRequest, {}); - expect(request.length).to.equal(1); - - const data = JSON.parse(request[0].data); - expect(data.adUnits.length).to.equal(1); - expect(data.adUnits[0].targetId).to.equal('adn-0000000000000551'); - expect(data.adUnits[0].adType).to.equal('VAST'); - - expect(request[0]).to.have.property('bid'); - const bid = request[0].bid[0] - expect(bid).to.have.property('bidId'); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL); - }); - - it('Test multiformat requests', function () { - const request = spec.buildRequests(multiBidderRequest, {}); - expect(request.length).to.equal(1); - expect(request.data) - const data = JSON.parse(request[0].data); - expect(data.adUnits.length).to.equal(2); - expect(data.adUnits[0].targetId).to.equal('adn-0000000000000551'); - expect(data.adUnits[0]).not.to.have.property('adType'); - expect(data.adUnits[1].targetId).to.equal('adn-0000000000000551-video'); - expect(data.adUnits[1].adType).to.equal('VAST'); - expect(request[0]).to.have.property('bid'); - const bid = request[0].bid[0] - expect(bid).to.have.property('bidId'); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL); - }); - - it('should pass segments if available in config and merge from targeting', function () { - const ortb2 = { - user: { - data: [{ - name: 'adnuntius', - segment: [{ id: 'segment1' }, { id: 'segment2' }, { invalidSegment: 'invalid' }, { id: 123 }, { id: ['3332'] }] - }, - { - name: 'other', - segment: ['segment3'] - }] - } - }; - - bidderRequests[0].params.targeting = { - segments: ['merge-this', 'and-this'] - }; - - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expectUrlsEqual(request[0].url, ENDPOINT_URL_SEGMENTS.replace('segment3', 'segment3,merge-this,and-this')); - - delete bidderRequests[0].params.targeting; - }); - - function countMatches(actualArray, expectedValue) { - return actualArray.filter(val => { - return JSON.stringify(val) === JSON.stringify(expectedValue); - }).length; - } - - it('should pass site data ext as key values to ad server', function () { - const ortb2 = { - site: { - ext: { - data: { - '12345': 'true', - '45678': 'true', - '9090': 'should-be-retained' - } - } - } - }; - bidderRequests[0].params.targeting = { - kv: { - 'merge': ['this'], - '9090': ['take it over'] - } - }; - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - const data = JSON.parse(request[0].data); - expect(countMatches(data.adUnits[0].kv, {'9090': ['take it over']})).to.equal(1); - expect(countMatches(data.adUnits[0].kv, {'merge': ['this']})).to.equal(1); - expect(countMatches(data.adUnits[0].kv, {'9090': 'should-be-retained'})).to.equal(1); - expect(countMatches(data.adUnits[0].kv, {'45678': 'true'})).to.equal(1); - expect(countMatches(data.adUnits[0].kv, {'12345': 'true'})).to.equal(1); - expect(data.adUnits[0].kv.length).to.equal(5); - - delete bidderRequests[0].params.targeting; - }); - - it('should pass site.ext.data and user.ext.data as key values to ad server with targeting in different format', function () { - const ortb2 = { - user: { - ext: { - data: { - 'from': 'user', - '9090': 'from-user' - } - } - }, - site: { - ext: { - data: { - '12345': 'true', - '45678': 'true', - '9090': 'should-be-retained' - } - } - } - }; - bidderRequests[0].params.targeting = { - kv: [ - {'merge': ['this']}, - {'9090': ['take it over']} - ] - }; - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - const data = JSON.parse(request[0].data); - expect(countMatches(data.adUnits[0].kv, {'from': 'user'})).to.equal(1); - expect(countMatches(data.adUnits[0].kv, {'9090': 'from-user'})).to.equal(1); - expect(countMatches(data.adUnits[0].kv, {'9090': ['take it over']})).to.equal(1); - expect(countMatches(data.adUnits[0].kv, {'merge': ['this']})).to.equal(1); - expect(countMatches(data.adUnits[0].kv, {'9090': 'should-be-retained'})).to.equal(1); - expect(countMatches(data.adUnits[0].kv, {'45678': 'true'})).to.equal(1); - expect(countMatches(data.adUnits[0].kv, {'12345': 'true'})).to.equal(1); - expect(data.adUnits[0].kv.length).to.equal(7); - - delete bidderRequests[0].params.targeting; - }); - - it('should pass site data ext as key values to ad server even if no kv targeting specified in params.targeting', function () { - const ortb2 = { - site: { - ext: { - data: { - '12345': 'true', - '45678': 'true', - '9090': 'should-be-retained' - } - } - } - }; - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - const data = JSON.parse(request[0].data); - expect(countMatches(data.adUnits[0].kv, {'9090': 'should-be-retained'})).to.equal(1); - expect(countMatches(data.adUnits[0].kv, {'45678': 'true'})).to.equal(1); - expect(countMatches(data.adUnits[0].kv, {'12345': 'true'})).to.equal(1); - expect(data.adUnits[0].kv.length).to.equal(3); - - delete bidderRequests[0].params.targeting; - }); - - it('should skip passing site ext if missing', function () { - const ortb2 = { - site: { - ext: { - } - } - }; - - delete bidderRequests[0].params.targeting; - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - const data = JSON.parse(request[0].data); - expect(data.adUnits[0]).to.not.have.property('kv'); - }); - - it('should skip passing site ext data if missing', function () { - const ortb2 = { - site: { - ext: { - data: {} - } - } - }; - - delete bidderRequests[0].params.targeting; - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - const data = JSON.parse(request[0].data); - expect(data.adUnits[0]).to.not.have.property('kv'); - }); - - it('should skip segments in config if not either id or array of strings', function () { - const ortb2 = { - user: { - data: [{ - name: 'adnuntius', - segment: [{ id: 'segment1' }, { id: 'segment2' }, { id: 'segment3' }] - }, - { - name: 'other', - segment: [{ - notright: 'segment4' - }] - }], - } - }; - - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL_SEGMENTS); - }); - }); - - describe('user privacy', function () { - it('should send GDPR Consent data if gdprApplies', function () { - const request = spec.buildRequests(bidderRequests, { gdprConsent: { gdprApplies: true, consentString: 'consentString' } }); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL_CONSENT); - }); - - it('should not send GDPR Consent data if gdprApplies equals undefined', function () { - const request = spec.buildRequests(bidderRequests, { gdprConsent: { gdprApplies: undefined, consentString: 'consentString' } }); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL); - }); - - it('should pass segments if available in config', function () { - const ortb2 = { - user: { - data: [{ - name: 'adnuntius', - segment: [{ id: 'segment1' }, { id: 'segment2' }] - }, - { - name: 'other', - segment: ['segment3'] - }] - } - } - - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL_SEGMENTS); - }); - - it('should skip segments in config if not either id or array of strings', function () { - const ortb2 = { - user: { - data: [{ - name: 'adnuntius', - segment: [{ id: 'segment1' }, { id: 'segment2' }, { id: 'segment3' }] - }, - { - name: 'other', - segment: [{ - notright: 'segment4' - }] - }], - } - }; - - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expectUrlsEqual(request[0].url, ENDPOINT_URL_SEGMENTS); - }); - - it('should user user ID if present in ortb2.user.id field', function () { - const ortb2 = { - user: { - id: usi - } - }; - - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, { ortb2 })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expectUrlsEqual(request[0].url, ENDPOINT_URL); - }); - - it('should user in user', function () { - config.setBidderConfig({ - bidders: ['adnuntius'], - }); - - const req = [ - { - bidId: 'adn-000000000008b6bc', - bidder: 'adnuntius', - params: { - auId: '000000000008b6bc', - network: 'adnuntius' - } - } - ]; - let request = config.runWithBidder('adnuntius', () => spec.buildRequests(req, { bids: req })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, `${ENDPOINT_URL_BASE}&userId=${usi}`); - - const ortb2 = {user: {ext: {eids: [{source: 'a', uids: [{id: '123', atype: 1}]}, {source: 'b', uids: [{id: '456', atype: 3, ext: {some: '1'}}]}]}}}; - request = config.runWithBidder('adnuntius', () => spec.buildRequests(req, { bids: req, ortb2: ortb2 })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, `${ENDPOINT_URL_BASE}&userId=${usi}&eids=%5B%7B%22source%22%3A%22a%22%2C%22uids%22%3A%5B%7B%22id%22%3A%22123%22%2C%22atype%22%3A1%7D%5D%7D%2C%7B%22source%22%3A%22b%22%2C%22uids%22%3A%5B%7B%22id%22%3A%22456%22%2C%22atype%22%3A3%2C%22ext%22%3A%7B%22some%22%3A%221%22%7D%7D%5D%7D%5D`); - - ortb2.user.id = "ortb2userid" - request = config.runWithBidder('adnuntius', () => spec.buildRequests(req, { bids: req, ortb2: ortb2 })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, `${ENDPOINT_URL_BASE}&userId=ortb2userid&eids=%5B%7B%22source%22%3A%22a%22%2C%22uids%22%3A%5B%7B%22id%22%3A%22123%22%2C%22atype%22%3A1%7D%5D%7D%2C%7B%22source%22%3A%22b%22%2C%22uids%22%3A%5B%7B%22id%22%3A%22456%22%2C%22atype%22%3A3%2C%22ext%22%3A%7B%22some%22%3A%221%22%7D%7D%5D%7D%5D`); - - req[0].params.userId = 'different_user_id'; - request = config.runWithBidder('adnuntius', () => spec.buildRequests(req, { bids: req })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, `${ENDPOINT_URL_BASE}&userId=different_user_id`); - - const eids = [{source: 'pubcid', uids: [{id: '123', atype: 1}]}, {source: 'otherid', uids: [{id: '456', atype: 3, ext: {some: '1'}}]}]; - req[0].params.userId = 'different_user_id'; - req[0].params.userIdAsEids = eids; - request = config.runWithBidder('adnuntius', () => spec.buildRequests(req, { bids: req })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expectUrlsEqual(request[0].url, `${ENDPOINT_URL_BASE}&userId=different_user_id&eids=` + encodeURIComponent(JSON.stringify(eids))); - - request = config.runWithBidder('adnuntius', () => spec.buildRequests(req, { bids: req, ortb2: ortb2 })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, `${ENDPOINT_URL_BASE}&userId=different_user_id&eids=` + encodeURIComponent(JSON.stringify(eids))); - }); - - it('should handle no user specified', function () { - config.setBidderConfig({ - bidders: ['adnuntius'], - }); - const req = [ - { - bidId: 'adn-000000000008b6bc', - bidder: 'adnuntius', - params: { - auId: '000000000008b6bc', - network: 'adnuntius' - } - } - ]; - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(req, { bids: req })); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL); - }); - }); - - describe('user privacy', function () { - it('should send GDPR Consent data if gdprApplies', function () { - const request = spec.buildRequests(bidderRequests, { gdprConsent: { gdprApplies: true, consentString: 'consentString' } }); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL_CONSENT); - }); - - it('should not send GDPR Consent data if gdprApplies equals undefined', function () { - const request = spec.buildRequests(bidderRequests, { gdprConsent: { gdprApplies: undefined, consentString: 'consentString' } }); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL); - }); - }); - - describe('use cookie', function () { - it('should send noCookie in url if set to false.', function () { - config.setBidderConfig({ - bidders: ['adnuntius'], - config: { - useCookie: false, - advertiserTransparency: true - } - }); - - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, {})); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL_NOCOOKIE + '&advertiserTransparency=true'); - }); - }); - - describe('validate auId', function () { - it('should fail when auId is not hexadecimal', function () { - const invalidRequest = { - bidId: 'adn-000000000008b6bc', - bidder: 'adnuntius', - params: { - auId: 'nothexadecimal', - } - }; - const valid = config.runWithBidder('adnuntius', () => spec.isBidRequestValid(invalidRequest)); - expect(valid).to.equal(false); - }); - - it('should pass when auId is hexadecimal', function () { - const invalidRequest = { - bidId: 'adn-000000000008b6bc', - bidder: 'adnuntius', - params: { - auId: '0123456789abcDEF', - } - }; - const valid = config.runWithBidder('adnuntius', () => spec.isBidRequestValid(invalidRequest)); - expect(valid).to.equal(true); - }); - }); - - describe('request deals', function () { - it('Should set max deals.', function () { - config.setBidderConfig({ - bidders: ['adnuntius'] - }); - - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, {})); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL); - expect(request[0]).to.have.property('data'); - const data = JSON.parse(request[0].data); - expect(data.adUnits.length).to.equal(2); - expect(bidderRequests[0].params.maxDeals).to.equal(1); - expect(data.adUnits[0].maxDeals).to.equal(bidderRequests[0].params.maxDeals); - expect(bidderRequests[1].params).to.not.have.property('maxBids'); - expect(data.adUnits[1].maxDeals).to.equal(undefined); - }); - it('Should allow a maximum of 5 deals.', function () { - config.setBidderConfig({ - bidders: ['adnuntius'], - }); - const request = config.runWithBidder('adnuntius', () => spec.buildRequests([ - { - bidId: 'adn-000000000008b6bc', - bidder: 'adnuntius', - params: { - auId: '000000000008b6bc', - network: 'adnuntius', - maxDeals: 10 - } - } - ], {})); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expectUrlsEqual(request[0].url, ENDPOINT_URL); - expect(request[0]).to.have.property('data'); - const data = JSON.parse(request[0].data); - expect(data.adUnits.length).to.equal(1); - expect(data.adUnits[0].maxDeals).to.equal(5); - }); - it('Should allow a minimum of 0 deals.', function () { - config.setBidderConfig({ - bidders: ['adnuntius'], - }); - const request = config.runWithBidder('adnuntius', () => spec.buildRequests([ - { - bidId: 'adn-000000000008b6bc', - bidder: 'adnuntius', - params: { - auId: '000000000008b6bc', - network: 'adnuntius', - maxDeals: -1 - } - } - ], {})); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expectUrlsEqual(request[0].url, ENDPOINT_URL); - expect(request[0]).to.have.property('data'); - const data = JSON.parse(request[0].data); - expect(data.adUnits.length).to.equal(1); - expect(data.adUnits[0].maxDeals).to.equal(undefined); - }); - it('Should set max deals using bidder config.', function () { - config.setBidderConfig({ - bidders: ['adnuntius'], - config: { - maxDeals: 2, - useCookie: 'ignore-this', - advertiserTransparency: 'ignore-this-as-well' - } - }); - - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, {})); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expectUrlsEqual(request[0].url, ENDPOINT_URL + '&ds=2'); - }); - it('Should allow a maximum of 5 deals when using bidder config.', function () { - config.setBidderConfig({ - bidders: ['adnuntius'], - config: { - maxDeals: 6 - } - }); - - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, {})); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - expectUrlsEqual(request[0].url, ENDPOINT_URL + '&ds=5'); - }); - it('Should allow a minimum of 0 deals when using bidder config.', function () { - config.setBidderConfig({ - bidders: ['adnuntius'], - config: { - maxDeals: -1 - } - }); - - const request = config.runWithBidder('adnuntius', () => spec.buildRequests(bidderRequests, {})); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url'); - // The maxDeals value is ignored because it is less than zero - expectUrlsEqual(request[0].url, ENDPOINT_URL); - }); - }); - - describe('interpretResponse', function () { - it('should return valid response when passed valid server response', function () { - config.setBidderConfig({ - bidders: ['adnuntius'], - config: { - bidType: 'netBid', - maxDeals: 1 - } - }); - - const interpretedResponse = config.runWithBidder('adnuntius', () => spec.interpretResponse(serverResponse, singleBidRequest)); - expect(interpretedResponse).to.have.lengthOf(2); - - const deal = serverResponse.body.adUnits[0].deals[0]; - expect(interpretedResponse[0].bidderCode).to.equal('adnuntius'); - expect(interpretedResponse[0].cpm).to.equal(deal.netBid.amount * 1000); - expect(interpretedResponse[0].width).to.equal(Number(deal.creativeWidth)); - expect(interpretedResponse[0].height).to.equal(Number(deal.creativeHeight)); - expect(interpretedResponse[0].creativeId).to.equal(deal.creativeId); - expect(interpretedResponse[0].currency).to.equal(deal.bid.currency); - expect(interpretedResponse[0].netRevenue).to.equal(false); - expect(interpretedResponse[0].meta).to.have.property('advertiserDomains'); - expect(interpretedResponse[0].meta.advertiserDomains).to.have.lengthOf(2); - expect(interpretedResponse[0].meta.advertiserDomains[0]).to.equal('fred.com'); - expect(interpretedResponse[0].meta.advertiserDomains[1]).to.equal('george.com'); - expect(interpretedResponse[0].ad).to.equal(serverResponse.body.adUnits[0].deals[0].html); - expect(interpretedResponse[0].ttl).to.equal(360); - expect(interpretedResponse[0].dealId).to.equal('abc123xyz'); - expect(interpretedResponse[0].dealCount).to.equal(1); - - const ad = serverResponse.body.adUnits[0].ads[0]; - expect(interpretedResponse[1].bidderCode).to.equal('adnuntius'); - expect(interpretedResponse[1].cpm).to.equal(ad.netBid.amount * 1000); - expect(interpretedResponse[1].width).to.equal(Number(ad.creativeWidth)); - expect(interpretedResponse[1].height).to.equal(Number(ad.creativeHeight)); - expect(interpretedResponse[1].creativeId).to.equal(ad.creativeId); - expect(interpretedResponse[1].currency).to.equal(ad.bid.currency); - expect(interpretedResponse[1].netRevenue).to.equal(false); - expect(interpretedResponse[1].meta).to.have.property('advertiserDomains'); - expect(interpretedResponse[1].meta.advertiserDomains).to.have.lengthOf(1); - expect(interpretedResponse[1].meta.advertiserDomains[0]).to.equal('adnuntius.com'); - expect(interpretedResponse[1].ad).to.equal(serverResponse.body.adUnits[0].html); - expect(interpretedResponse[1].ttl).to.equal(360); - expect(interpretedResponse[1].dealId).to.equal('not-in-deal-array-here'); - expect(interpretedResponse[1].dealCount).to.equal(0); - - const results = JSON.parse(storage.getDataFromLocalStorage('adn.metaData')); - const usiEntry = results.find(entry => entry.key === 'usi' && entry.network === 'some-network-id'); - expect(usiEntry.key).to.equal('usi'); - expect(usiEntry.value).to.equal('from-api-server dude'); - expect(usiEntry.exp).to.be.greaterThan(getUnixTimestampFromNow(90)); - expect(usiEntry.network).to.equal('some-network-id') - - const voidAuIdsEntry = results.find(entry => entry.key === 'voidAuIds'); - expect(voidAuIdsEntry.key).to.equal('voidAuIds'); - expect(voidAuIdsEntry.exp).to.equal(undefined); - expect(voidAuIdsEntry.value[0].auId).to.equal('00000000000abcde'); - expect(voidAuIdsEntry.value[0].exp).to.be.greaterThan(getUnixTimestampFromNow()); - expect(voidAuIdsEntry.value[0].exp).to.be.lessThan(getUnixTimestampFromNow(2)); - expect(voidAuIdsEntry.value[1].auId).to.equal('00000000000fffff'); - expect(voidAuIdsEntry.value[1].exp).to.be.greaterThan(getUnixTimestampFromNow()); - expect(voidAuIdsEntry.value[1].exp).to.be.lessThan(getUnixTimestampFromNow(2)); - - const validEntry = results.find(entry => entry.key === 'valid'); - expect(validEntry.key).to.equal('valid'); - expect(validEntry.value).to.equal('also-valid'); - expect(validEntry.exp).to.be.greaterThan(getUnixTimestampFromNow()); - expect(validEntry.exp).to.be.lessThan(getUnixTimestampFromNow(2)); - - const randomApiEntry = results.find(entry => entry.key === 'randomApiKey'); - expect(randomApiEntry.key).to.equal('randomApiKey'); - expect(randomApiEntry.value).to.equal('randomApiValue'); - expect(randomApiEntry.network).to.equal('some-network-id'); - expect(randomApiEntry.exp).to.be.greaterThan(getUnixTimestampFromNow(90)); - }); - - it('should return valid response when passed valid multiformat server response', function () { - config.setBidderConfig({ - bidders: ['adnuntius'], - config: { - bidType: 'netBid', - maxDeals: 0 - } - }); - - const interpretedResponse = config.runWithBidder('adnuntius', () => spec.interpretResponse(multiFormatServerResponse, multiBidAndFormatRequest)); - expect(interpretedResponse).to.have.lengthOf(3); - - let ad = multiFormatServerResponse.body.adUnits[0].ads[0]; - expect(interpretedResponse[0].bidderCode).to.equal('adnuntius'); - expect(interpretedResponse[0].cpm).to.equal(ad.netBid.amount * 1000); - expect(interpretedResponse[0].width).to.equal(Number(ad.creativeWidth)); - expect(interpretedResponse[0].height).to.equal(Number(ad.creativeHeight)); - expect(interpretedResponse[0].creativeId).to.equal(ad.creativeId); - expect(interpretedResponse[0].currency).to.equal(ad.bid.currency); - expect(interpretedResponse[0].netRevenue).to.equal(false); - expect(interpretedResponse[0].ad).to.equal(multiFormatServerResponse.body.adUnits[0].html); - expect(interpretedResponse[0].ttl).to.equal(360); - - ad = multiFormatServerResponse.body.adUnits[4].ads[0]; - expect(interpretedResponse[1].bidderCode).to.equal('adnuntius'); - expect(interpretedResponse[1].cpm).to.equal(ad.netBid.amount * 1000); - expect(interpretedResponse[1].width).to.equal(Number(ad.creativeWidth)); - expect(interpretedResponse[1].height).to.equal(Number(ad.creativeHeight)); - expect(interpretedResponse[1].creativeId).to.equal(ad.creativeId); - expect(interpretedResponse[1].currency).to.equal(ad.bid.currency); - expect(interpretedResponse[1].netRevenue).to.equal(false); - expect(interpretedResponse[1].ad).to.equal(multiFormatServerResponse.body.adUnits[4].html); - expect(interpretedResponse[1].ttl).to.equal(360); - - ad = multiFormatServerResponse.body.adUnits[2].ads[0]; - expect(interpretedResponse[2].native).to.not.be.undefined; - expect(interpretedResponse[2].bidderCode).to.equal('adnuntius'); - expect(interpretedResponse[2].cpm).to.equal(ad.netBid.amount * 1000); - expect(interpretedResponse[2].width).to.equal(Number(ad.creativeWidth)); - expect(interpretedResponse[2].height).to.equal(Number(ad.creativeHeight)); - expect(interpretedResponse[2].creativeId).to.equal(ad.creativeId); - expect(interpretedResponse[2].currency).to.equal(ad.bid.currency); - expect(interpretedResponse[2].netRevenue).to.equal(false); - expect(interpretedResponse[2].ttl).to.equal(360); - }); - - it('should not process valid response when passed alt bidder that is an adndeal', function () { - const altBidder = { - bid: [ - { - bidder: 'adndeal1', - bidId: 'adn-0000000000000551', - } - ] - }; - serverResponse.body.adUnits[0].deals = []; - delete serverResponse.body.metaData.voidAuIds; // test response with no voidAuIds - - const interpretedResponse = spec.interpretResponse(serverResponse, altBidder); - expect(interpretedResponse).to.have.lengthOf(0); - - serverResponse.body.adUnits[0].deals = deals; - }); - - it('should return valid response when passed alt bidder', function () { - const altBidder = { - bid: [ - { - bidder: 'adn-alt', - bidId: 'adn-0000000000000551', - params: { - bidType: 'netBid' - } - } - ] - }; - serverResponse.body.adUnits[0].deals = []; - - const interpretedResponse = spec.interpretResponse(serverResponse, altBidder); - expect(interpretedResponse).to.have.lengthOf(1); - - const ad = serverResponse.body.adUnits[0].ads[0]; - expect(interpretedResponse[0].bidderCode).to.equal('adn-alt'); - expect(interpretedResponse[0].cpm).to.equal(ad.netBid.amount * 1000); - expect(interpretedResponse[0].width).to.equal(Number(ad.creativeWidth)); - expect(interpretedResponse[0].height).to.equal(Number(ad.creativeHeight)); - expect(interpretedResponse[0].creativeId).to.equal(ad.creativeId); - expect(interpretedResponse[0].currency).to.equal(ad.bid.currency); - expect(interpretedResponse[0].netRevenue).to.equal(false); - expect(interpretedResponse[0].meta).to.have.property('advertiserDomains'); - expect(interpretedResponse[0].meta.advertiserDomains).to.have.lengthOf(1); - expect(interpretedResponse[0].meta.advertiserDomains[0]).to.equal('adnuntius.com'); - expect(interpretedResponse[0].ad).to.equal(serverResponse.body.adUnits[0].html); - expect(interpretedResponse[0].ttl).to.equal(360); - expect(interpretedResponse[0].dealId).to.equal('not-in-deal-array-here'); - expect(interpretedResponse[0].dealCount).to.equal(0); - - serverResponse.body.adUnits[0].deals = deals; - }); - }); - - describe('interpretVideoResponse', function () { - it('should return valid response when passed valid server response', function () { - const interpretedResponse = spec.interpretResponse(serverVideoResponse, videoBidRequest); - const ad = serverVideoResponse.body.adUnits[0].ads[0] - const deal = serverVideoResponse.body.adUnits[0].deals[0] - expect(interpretedResponse).to.have.lengthOf(2); - - expect(interpretedResponse[0].bidderCode).to.equal('adnuntius'); - expect(interpretedResponse[0].cpm).to.equal(deal.bid.amount * 1000); - expect(interpretedResponse[0].width).to.equal(Number(deal.creativeWidth)); - expect(interpretedResponse[0].height).to.equal(Number(deal.creativeHeight)); - expect(interpretedResponse[0].creativeId).to.equal(deal.creativeId); - expect(interpretedResponse[0].currency).to.equal(deal.bid.currency); - expect(interpretedResponse[0].netRevenue).to.equal(false); - expect(interpretedResponse[0].meta).to.have.property('advertiserDomains'); - expect(interpretedResponse[0].meta.advertiserDomains).to.have.lengthOf(1); - expect(interpretedResponse[0].meta.advertiserDomains[0]).to.equal('adnuntius.com'); - expect(interpretedResponse[0].vastXml).to.equal(deal.vastXml); - expect(interpretedResponse[0].dealId).to.equal('abc123xyz'); - expect(interpretedResponse[0].dealCount).to.equal(1); - - expect(interpretedResponse[1].bidderCode).to.equal('adnuntius'); - expect(interpretedResponse[1].cpm).to.equal(ad.bid.amount * 1000); - expect(interpretedResponse[1].width).to.equal(Number(ad.creativeWidth)); - expect(interpretedResponse[1].height).to.equal(Number(ad.creativeHeight)); - expect(interpretedResponse[1].creativeId).to.equal(ad.creativeId); - expect(interpretedResponse[1].currency).to.equal(ad.bid.currency); - expect(interpretedResponse[1].netRevenue).to.equal(false); - expect(interpretedResponse[1].meta).to.have.property('advertiserDomains'); - expect(interpretedResponse[1].meta.advertiserDomains).to.have.lengthOf(1); - expect(interpretedResponse[1].meta.advertiserDomains[0]).to.equal('adnuntius.com'); - expect(interpretedResponse[1].vastXml).to.equal(serverVideoResponse.body.adUnits[0].vastXml); - expect(interpretedResponse[1].dealId).to.equal('not-in-deal-array'); - expect(interpretedResponse[1].dealCount).to.equal(0); - }); - }); - - describe('Native ads handling', function () { - it('should pass requests on correctly', function () { - const request = spec.buildRequests(nativeBidderRequest.bid, {}); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('bid'); - expect(request[0]).to.have.property('data'); - expect(request[0].data).to.equal('{"adUnits":[{"auId":"0000000000000551","targetId":"adn-0000000000000551","adType":"NATIVE","nativeRequest":{"ortb":{"assets":[{"id":1,"required":1,"img":{"type":3,"w":250,"h":250}}]}},"dimensions":[[200,200],[300,300]]}]}'); - }); - - it('should return valid response when passed valid server response', function () { - const interpretedResponse = spec.interpretResponse(nativeResponse, nativeBidderRequest); - const ad = nativeResponse.body.adUnits[0].ads[0] - expect(interpretedResponse).to.have.lengthOf(1); - - expect(interpretedResponse[0].bidderCode).to.equal('adnuntius'); - expect(interpretedResponse[0].cpm).to.equal(ad.bid.amount * 1000); - expect(interpretedResponse[0].width).to.equal(Number(ad.creativeWidth)); - expect(interpretedResponse[0].height).to.equal(Number(ad.creativeHeight)); - expect(interpretedResponse[0].creativeId).to.equal(ad.creativeId); - expect(interpretedResponse[0].currency).to.equal(ad.bid.currency); - expect(interpretedResponse[0].netRevenue).to.equal(false); - expect(interpretedResponse[0].meta).to.have.property('advertiserDomains'); - expect(interpretedResponse[0].meta.advertiserDomains).to.have.lengthOf(1); - expect(interpretedResponse[0].meta.advertiserDomains[0]).to.equal('adnuntius.com'); - expect(interpretedResponse[0].vastXml).to.equal(ad.vastXml); - expect(JSON.stringify(interpretedResponse[0].native.ortb)).to.equal('{"link":{"url":"https://whatever.com"},"assets":[{"id":1,"required":1,"img":{"url":"http://something.com/something.png"}}]}'); - }); - - it('should pass legacy requests on correctly', function () { - const request = spec.buildRequests(legacyNativeBidderRequest.bid, {}); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('bid'); - expect(request[0]).to.have.property('data'); - expect(request[0].data).to.equal('{"adUnits":[{"auId":"0000000000000551","targetId":"adn-0000000000000551","adType":"NATIVE","nativeRequest":{"ortb":{"ver":"1.2","assets":[{"id":0,"required":1,"img":{"type":3,"w":250,"h":250}}],"eventtrackers":[{"event":1,"methods":[1]},{"event":2,"methods":[1]}]}},"dimensions":[[200,200],[300,300]]}]}'); - }); - - it('should return valid legacy response when passed valid server response', function () { - const interpretedResponse = spec.interpretResponse(nativeResponse, legacyNativeBidderRequest); - const ad = nativeResponse.body.adUnits[0].ads[0] - expect(interpretedResponse).to.have.lengthOf(1); - - expect(interpretedResponse[0].bidderCode).to.equal('adnuntius'); - expect(interpretedResponse[0].cpm).to.equal(ad.bid.amount * 1000); - expect(interpretedResponse[0].width).to.equal(Number(ad.creativeWidth)); - expect(interpretedResponse[0].height).to.equal(Number(ad.creativeHeight)); - expect(interpretedResponse[0].creativeId).to.equal(ad.creativeId); - expect(interpretedResponse[0].currency).to.equal(ad.bid.currency); - expect(interpretedResponse[0].netRevenue).to.equal(false); - expect(interpretedResponse[0].meta).to.have.property('advertiserDomains'); - expect(interpretedResponse[0].meta.advertiserDomains).to.have.lengthOf(1); - expect(interpretedResponse[0].meta.advertiserDomains[0]).to.equal('adnuntius.com'); - expect(interpretedResponse[0].vastXml).to.equal(ad.vastXml); - expect(JSON.stringify(interpretedResponse[0].native)).to.equal('{"clickUrl":"https://whatever.com","icon":{"url":"http://something.com/something.png"},"impressionTrackers":[]}'); - }); - }); -}); diff --git a/test/spec/modules/adnuntiusRtdProvider_spec.js b/test/spec/modules/adnuntiusRtdProvider_spec.js deleted file mode 100644 index c1fcfbf29..000000000 --- a/test/spec/modules/adnuntiusRtdProvider_spec.js +++ /dev/null @@ -1,145 +0,0 @@ -import { adnuntiusSubmodule } from 'modules/adnuntiusRtdProvider.js'; -import { expect } from 'chai'; -import { server } from 'test/mocks/xhr.js'; -import { config as _config } from 'src/config.js'; - -const responseHeader = { 'Content-Type': 'application/json' }; - -describe('adnuntiusRtdProvider is a RTD provider that', function () { - describe('has a method `init` that', function () { - it('exists', function () { - expect(adnuntiusSubmodule.init).to.be.a('function'); - }); - it('returns false missing config params', function () { - const config = { - name: 'adnuntius', - waitForIt: true, - }; - const value = adnuntiusSubmodule.init(config); - expect(value).to.equal(false); - }); - it('returns false if missing providers param', function () { - const config = { - name: 'adnuntius', - waitForIt: true, - params: {} - }; - const value = adnuntiusSubmodule.init(config); - expect(value).to.equal(false); - }); - it('returns true if providers param included', function () { - const config = { - name: 'adnuntius', - waitForIt: true, - params: { - providers: [] - } - }; - const value = adnuntiusSubmodule.init(config); - expect(value).to.equal(true); - }); - }); - - describe('has a method `getBidRequestData` that', function () { - it('exists', function () { - expect(adnuntiusSubmodule.getBidRequestData).to.be.a('function'); - }); - it('verify config params', function () { - expect(config.name).to.not.be.undefined; - expect(config.name).to.equal('adnuntius'); - expect(config.params.providers).to.not.be.undefined; - expect(config.params).to.have.property('providers'); - expect(config.params.providers[0]).to.have.property('siteId') - expect(config.params.providers[0]).to.have.property('userId') - }); - - it('send correct request', function () { - const callback = sinon.spy(); - let request; - const adUnitsOriginal = adUnits; - adnuntiusSubmodule.getBidRequestData({ adUnits: adUnits }, callback, config); - request = server.requests[0]; - request.respond(200, responseHeader, JSON.stringify(data)); - expect(request.url).to.be.include(`&s=site123&browserId=mike`); - expect(adUnits).to.length(2); - expect(adUnits[0]).to.be.eq(adUnitsOriginal[0]); - }); - }); - - describe('has a method `setGlobalConfig` that', function () { - it('exists', function () { - expect(adnuntiusSubmodule.setGlobalConfig).to.be.a('function'); - }); - - it('sets global config', function () { - adnuntiusSubmodule.setGlobalConfig(config, concatSegments); - const globalConfig = _config.getBidderConfig() - expect(globalConfig).to.have.property('adnuntius') - expect(globalConfig.adnuntius).to.have.property('ortb2') - expect(globalConfig.adnuntius.ortb2).to.have.property('user') - expect(globalConfig.adnuntius.ortb2.user).to.have.property('data') - expect(globalConfig.adnuntius.ortb2.user.data).to.be.a('array') - expect(globalConfig.adnuntius.ortb2.user.data[0]).to.have.property('name') - expect(globalConfig.adnuntius.ortb2.user.data[0].name).to.equal('adnuntius') - expect(globalConfig.adnuntius.ortb2.user.data[0]).to.have.property('segment') - expect(globalConfig.adnuntius.ortb2.user.data[0].segment).to.be.a('array') - expect(globalConfig.adnuntius.ortb2.user.data[0].segment[0]).to.have.property('id') - expect(globalConfig.adnuntius.ortb2.user.data[0].segment[0].id).to.equal('segment2') - }); - }); -}); - -const config = { - name: 'adnuntius', - waitForIt: true, - params: { - bidders: ['adnuntius'], - providers: [{ - siteId: 'site123', - userId: 'mike' - }] - } -}; - -const adUnits = [ - { - code: 'one-div-id', - mediaTypes: { - banner: { - sizes: [970, 250] - } - }, - bids: [ - { - bidder: 'appnexus', - params: { - placementId: 12345370, - } - }] - }, - { - code: 'two-div-id', - mediaTypes: { - banner: { sizes: [300, 250] } - }, - bids: [ - { - bidder: 'appnexus', - params: { - placementId: 12345370, - } - }] - }]; - -const data = { - 'expiryEpochMillis': 1640165064285, - 'segments': [ - 'segment2', - 'segment1' - ] -}; - -const concatSegments = [ - { id: 'segment2' }, - { id: 'segment1' }, -] diff --git a/test/spec/modules/adotBidAdapter_spec.js b/test/spec/modules/adotBidAdapter_spec.js deleted file mode 100644 index 3cf4d7310..000000000 --- a/test/spec/modules/adotBidAdapter_spec.js +++ /dev/null @@ -1,336 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adotBidAdapter.js'; - -const BIDDER_URL = 'https://dsp.adotmob.com/headerbidding/bidrequest'; - -describe('Adot Adapter', function () { - describe('isBidRequestValid', function () { - it('should return false if video and !isValidVideo', function () { - const bid = { mediaTypes: { video: {} } }; - const isBidRequestValid = spec.isBidRequestValid(bid); - expect(isBidRequestValid).to.equal(false); - }) - - it('should return true if video and isValidVideo', function () { - const bid = { mediaTypes: { video: { 'mimes': 1, 'protocols': 1 } } }; - const isBidRequestValid = spec.isBidRequestValid(bid); - expect(isBidRequestValid).to.equal(true); - }) - - it('should return true if !video', function () { - const bid = { mediaTypes: { banner: {} } }; - const isBidRequestValid = spec.isBidRequestValid(bid); - expect(isBidRequestValid).to.equal(true); - }) - }); - - describe('buildRequests', function () { - it('should build request (banner)', function () { - const bidderRequestId = 'bidderRequestId'; - const validBidRequests = [{ bidderRequestId, mediaTypes: {} }, { bidderRequestId, bidId: 'bidId', mediaTypes: { banner: { sizes: [[300, 250]] } }, params: { placementId: 'placementId', adUnitCode: 200 } }]; - const bidderRequest = { position: 2, refererInfo: { page: 'http://localhost.com', domain: 'localhost.com' }, gdprConsent: { consentString: 'consentString', gdprApplies: true }, ortb2: { source: { ext: { schain: { ver: '1.0' } } } } }; - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const buildBidRequestResponse = { - id: bidderRequestId, - imp: [{ - id: validBidRequests[1].bidId, - ext: { - placementId: validBidRequests[1].params.placementId, - adUnitCode: validBidRequests[1].adUnitCode, - container: undefined - }, - banner: { - pos: bidderRequest.position, - format: [{ w: validBidRequests[1].mediaTypes.banner.sizes[0][0], h: validBidRequests[1].mediaTypes.banner.sizes[0][1] }] - }, - bidfloorcur: 'USD', - bidfloor: 0 - }], - site: { - page: bidderRequest.refererInfo.page, - domain: 'localhost.com', - name: 'localhost.com', - publisher: { - // id: 'adot' - id: undefined - }, - ext: { schain: { ver: '1.0' } } - }, - device: { ua: navigator.userAgent, language: navigator.language }, - user: { ext: { consent: bidderRequest.gdprConsent.consentString } }, - regs: { ext: { gdpr: bidderRequest.gdprConsent.gdprApplies } }, - ext: { - adot: { adapter_version: 'v2.0.0' }, - should_use_gzip: true - }, - at: 1 - } - - expect(request).to.deep.equal([{ - method: 'POST', - url: BIDDER_URL, - data: buildBidRequestResponse - }]) - }) - - it('should build request (native)', function () { - const bidderRequestId = 'bidderRequestId'; - const validBidRequests = [{ bidderRequestId, mediaTypes: {} }, { bidderRequestId, bidId: 'bidId', mediaTypes: { native: { title: { required: true, len: 50, sizes: [[300, 250]] }, wrong: {}, image: {} } }, params: { placementId: 'placementId', adUnitCode: 200 } }]; - const bidderRequest = { position: 2, refererInfo: { page: 'http://localhost.com', domain: 'localhost.com' }, gdprConsent: { consentString: 'consentString', gdprApplies: true }, ortb2: { source: { ext: { schain: { ver: '1.0' } } } } }; - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const buildBidRequestResponse = { - id: bidderRequestId, - imp: [{ - id: validBidRequests[1].bidId, - ext: { - placementId: validBidRequests[1].params.placementId, - adUnitCode: validBidRequests[1].adUnitCode, - container: undefined - }, - native: { - request: '{\"assets\":[{\"id\":1,\"required\":true,\"title\":{\"len\":50,\"wmin\":300,\"hmin\":250}},{\"id\":3,\"img\":{\"type\":3}}]}' - }, - bidfloorcur: 'USD', - bidfloor: 0 - }], - site: { - page: bidderRequest.refererInfo.page, - domain: 'localhost.com', - name: 'localhost.com', - publisher: { - // id: 'adot' - id: undefined - }, - ext: { schain: { ver: '1.0' } } - }, - device: { ua: navigator.userAgent, language: navigator.language }, - user: { ext: { consent: bidderRequest.gdprConsent.consentString } }, - regs: { ext: { gdpr: bidderRequest.gdprConsent.gdprApplies } }, - ext: { - adot: { adapter_version: 'v2.0.0' }, - should_use_gzip: true - }, - at: 1 - } - - expect(request).to.deep.equal([{ - method: 'POST', - url: BIDDER_URL, - data: buildBidRequestResponse - }]) - }) - - it('should build request (video)', function () { - const bidderRequestId = 'bidderRequestId'; - const validBidRequests = [{ bidderRequestId, mediaTypes: {} }, { bidderRequestId, bidId: 'bidId', mediaTypes: { video: { playerSize: [[300, 250]], minduration: 1, maxduration: 2, api: 'api', linearity: 'linearity', mimes: [], plcmt: '1', playbackmethod: 'playbackmethod', protocols: 'protocol', startdelay: 'startdelay' } }, params: { placementId: 'placementId', adUnitCode: 200 } }]; - const bidderRequest = { position: 2, refererInfo: { page: 'http://localhost.com', domain: 'localhost.com' }, gdprConsent: { consentString: 'consentString', gdprApplies: true }, ortb2: { source: { ext: { schain: { ver: '1.0' } } } } }; - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const buildBidRequestResponse = { - id: bidderRequestId, - imp: [{ - id: validBidRequests[1].bidId, - ext: { - placementId: validBidRequests[1].params.placementId, - adUnitCode: validBidRequests[1].adUnitCode, - container: undefined - }, - video: { - api: 'api', - h: 250, - linearity: 'linearity', - maxduration: 2, - mimes: [], - minduration: 1, - placement: '1', - playbackmethod: 'playbackmethod', - pos: 0, - protocols: 'protocol', - skip: 0, - startdelay: 'startdelay', - w: 300 - }, - bidfloorcur: 'USD', - bidfloor: 0 - }], - site: { - page: bidderRequest.refererInfo.page, - domain: 'localhost.com', - name: 'localhost.com', - publisher: { - // id: 'adot' - id: undefined - }, - ext: { schain: { ver: '1.0' } } - }, - device: { ua: navigator.userAgent, language: navigator.language }, - user: { ext: { consent: bidderRequest.gdprConsent.consentString } }, - regs: { ext: { gdpr: bidderRequest.gdprConsent.gdprApplies } }, - ext: { - adot: { adapter_version: 'v2.0.0' }, - should_use_gzip: true - }, - at: 1 - } - - expect(request).to.deep.equal([{ - method: 'POST', - url: BIDDER_URL, - data: buildBidRequestResponse - }]) - }) - }); - - describe('interpretResponse', function () { - it('should return [] if !isValidResponse', function () { - const serverResponse = 'response'; - const request = 'request'; - const interpretedResponse = spec.interpretResponse(serverResponse, request); - expect(interpretedResponse).to.deep.equal([]); - }) - - it('should return [] if !isValidRequest', function () { - const serverResponse = { body: { cur: 'EUR', seatbid: [] } }; - const request = 'request'; - const interpretedResponse = spec.interpretResponse(serverResponse, request); - expect(interpretedResponse).to.deep.equal([]); - }) - - it('should return bidResponse with random media type', function () { - const impId = 'impId'; - const bid = { adm: 'adm', impid: impId, price: 2, crid: 'crid', dealid: 'dealid', adomain: 'adomain', ext: { adot: { media_type: 'media_type', size: { w: 300, h: 250 } } } } - const serverResponse = { body: { cur: 'EUR', seatbid: [{ bid: {} }, { bid: [bid] }] } }; - const request = { data: { imp: [{ id: impId }] } }; - const bidResponse = { - requestId: impId, - cpm: bid.price, - currency: serverResponse.body.cur, - ttl: 10, - creativeId: bid.crid, - netRevenue: true, - mediaType: bid.ext.adot.media_type, - dealId: bid.dealid, - meta: { advertiserDomains: bid.adomain }, - width: bid.ext.adot.size.w, - height: bid.ext.adot.size.h, - ad: bid.adm, - adUrl: null, - vastXml: null, - vastUrl: null, - renderer: null - } - - const interpretedResponse = spec.interpretResponse(serverResponse, request); - expect(interpretedResponse).to.deep.equal([bidResponse]); - }) - - it('should return bidResponse with native', function () { - const impId = 'impId'; - const bid = { adm: '{"native":{"assets":[{"id":1,"title":{"text":"title"}},{"id":3,"img":{"url":"url","w":300,"h":250}}],"link":{"url":"clickUrl","clicktrackers":"clicktrackers"},"imptrackers":["imptracker"],"jstracker":"jstracker"}}', impid: impId, price: 2, crid: 'crid', dealid: 'dealid', adomain: 'adomain', ext: { adot: { media_type: 'native', size: { width: 300, height: 250 } } } } - const serverResponse = { body: { cur: 'EUR', seatbid: [{ bid: {} }, { bid: [bid] }] } }; - const request = { data: { imp: [{ id: impId }] } }; - const bidResponse = { - requestId: impId, - cpm: bid.price, - currency: serverResponse.body.cur, - ttl: 10, - creativeId: bid.crid, - netRevenue: true, - mediaType: bid.ext.adot.media_type, - dealId: bid.dealid, - meta: { advertiserDomains: bid.adomain }, - native: { - title: 'title', - image: { url: 'url', width: 300, height: 250 }, - clickUrl: 'clickUrl', - clickTrackers: 'clicktrackers', - impressionTrackers: ['imptracker'], - javascriptTrackers: ['jstracker'] - } - } - - const interpretedResponse = spec.interpretResponse(serverResponse, request); - expect(interpretedResponse).to.deep.equal([bidResponse]); - }) - - it('should return bidResponse with video', function () { - const impId = 'impId'; - const bid = { nurl: 'nurl', impid: impId, price: 2, crid: 'crid', dealid: 'dealid', adomain: 'adomain', ext: { adot: { media_type: 'video', size: { w: 300, h: 250 }, container: {}, adUnitCode: 20, video: { type: 'outstream' } } } } - const serverResponse = { body: { cur: 'EUR', seatbid: [{ bid: {} }, { bid: [bid] }] } }; - const request = { data: { imp: [{ id: impId }] } }; - const bidResponse = { - requestId: impId, - cpm: bid.price, - currency: serverResponse.body.cur, - ttl: 10, - creativeId: bid.crid, - netRevenue: true, - mediaType: bid.ext.adot.media_type, - dealId: bid.dealid, - meta: { advertiserDomains: bid.adomain }, - w: bid.ext.adot.size.w, - h: bid.ext.adot.size.h, - ad: null, - adUrl: bid.nurl, - vastXml: null, - vastUrl: bid.nurl - } - - const interpretedResponse = spec.interpretResponse(serverResponse, request); - expect(interpretedResponse).to.be.an('array').and.to.have.lengthOf(1) - expect(interpretedResponse[0].requestId).to.deep.equal(bidResponse.requestId); - expect(interpretedResponse[0].cpm).to.deep.equal(bidResponse.cpm); - expect(interpretedResponse[0].currency).to.deep.equal(bidResponse.currency); - expect(interpretedResponse[0].ttl).to.deep.equal(bidResponse.ttl); - expect(interpretedResponse[0].creativeId).to.deep.equal(bidResponse.creativeId); - expect(interpretedResponse[0].netRevenue).to.deep.equal(bidResponse.netRevenue); - expect(interpretedResponse[0].mediaType).to.deep.equal(bidResponse.mediaType); - expect(interpretedResponse[0].dealId).to.deep.equal(bidResponse.dealId); - expect(interpretedResponse[0].meta).to.deep.equal(bidResponse.meta); - expect(interpretedResponse[0].width).to.deep.equal(bidResponse.w); - expect(interpretedResponse[0].height).to.deep.equal(bidResponse.h); - expect(interpretedResponse[0].ad).to.deep.equal(bidResponse.ad); - expect(interpretedResponse[0].adUrl).to.deep.equal(bidResponse.adUrl); - expect(interpretedResponse[0].vastXml).to.deep.equal(bidResponse.vastXml); - expect(interpretedResponse[0].vastUrl).to.deep.equal(bidResponse.vastUrl); - expect(interpretedResponse[0].renderer).to.be.an('object'); - }) - }); - - describe('getFloor', function () { - it('should return 0 if getFloor is not a function', function () { - const floor = spec.getFloor({ getFloor: 0 }); - expect(floor).to.deep.equal(0); - }) - - it('should return floor result if currency are correct', function () { - const currency = 'EUR'; - const floorResult = 2; - const fn = sinon.stub().callsFake(() => ({ currency, floor: floorResult })) - const adUnit = { getFloor: fn }; - const size = {}; - const mediaType = {}; - - const floor = spec.getFloor(adUnit, size, mediaType, currency); - expect(floor).to.deep.equal(floorResult); - expect(fn.calledOnce).to.equal(true); - expect(fn.calledWithExactly({ currency, mediaType, size })).to.equal(true); - }) - - it('should return floor result if currency are not correct', function () { - const currency = 'EUR'; - const floorResult = 2; - const fn = sinon.stub().callsFake(() => ({ currency: 'wrong_currency', floor: floorResult })) - const adUnit = { getFloor: fn }; - const size = {}; - const mediaType = {}; - - const floor = spec.getFloor(adUnit, size, mediaType, currency); - expect(floor).to.deep.equal(0); - expect(fn.calledOnce).to.equal(true); - expect(fn.calledWithExactly({ currency, mediaType, size })).to.equal(true); - }) - }); -}); diff --git a/test/spec/modules/adpartnerBidAdapter_spec.js b/test/spec/modules/adpartnerBidAdapter_spec.js deleted file mode 100644 index fdc63bade..000000000 --- a/test/spec/modules/adpartnerBidAdapter_spec.js +++ /dev/null @@ -1,337 +0,0 @@ -import {expect} from 'chai'; -import {spec, ENDPOINT_PROTOCOL, ENDPOINT_DOMAIN, ENDPOINT_PATH} from 'modules/adpartnerBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import * as miUtils from 'libraries/mediaImpactUtils/index.js'; - -const BIDDER_CODE = 'adpartner'; - -describe('AdpartnerAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.be.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - const validRequest = { - 'params': { - 'unitId': 123 - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(true); - }); - - it('should return true when required params is srting', function () { - const validRequest = { - 'params': { - 'unitId': '456' - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const validRequest = { - 'params': { - 'unknownId': 123 - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(false); - }); - - it('should return false when required params is 0', function () { - const validRequest = { - 'params': { - 'unitId': 0 - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const validEndpoint = ENDPOINT_PROTOCOL + '://' + ENDPOINT_DOMAIN + ENDPOINT_PATH + '?tag=123,456&partner=777&sizes=300x250|300x600,728x90,300x250&referer=https%3A%2F%2Ftest.domain'; - - const validRequest = [ - { - 'bidder': BIDDER_CODE, - 'params': { - 'unitId': 123 - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e' - }, - { - 'bidder': BIDDER_CODE, - 'params': { - 'unitId': '456' - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[728, 90]], - 'bidId': '22aidtbx5eabd9' - }, - { - 'bidder': BIDDER_CODE, - 'params': { - 'partnerId': 777 - }, - 'adUnitCode': 'partner-code-3', - 'sizes': [[300, 250]], - 'bidId': '5d4531d5a6c013' - } - ]; - - const bidderRequest = { - refererInfo: { - page: 'https://test.domain' - } - }; - - it('bidRequest HTTP method', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - expect(request.method).to.equal('POST'); - }); - - it('bidRequest url', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - expect(request.url).to.equal(validEndpoint); - }); - - it('bidRequest data', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload[0].unitId).to.equal(123); - expect(payload[0].sizes).to.deep.equal([[300, 250], [300, 600]]); - expect(payload[0].bidId).to.equal('30b31c1838de1e'); - expect(payload[1].unitId).to.equal(456); - expect(payload[1].sizes).to.deep.equal([[728, 90]]); - expect(payload[1].bidId).to.equal('22aidtbx5eabd9'); - expect(payload[2].partnerId).to.equal(777); - expect(payload[2].sizes).to.deep.equal([[300, 250]]); - expect(payload[2].bidId).to.equal('5d4531d5a6c013'); - }); - }); - - describe('joinSizesToString', function () { - it('success convert sizes list to string', function () { - const sizesStr = miUtils.joinSizesToString([[300, 250], [300, 600]]); - expect(sizesStr).to.equal('300x250|300x600'); - }); - }); - - describe('interpretResponse', function () { - const bidRequest = { - 'method': 'POST', - 'url': ENDPOINT_PROTOCOL + '://' + ENDPOINT_DOMAIN + ENDPOINT_PATH + '?tag=123,456&partner=777code=adunit-code-1,adunit-code-2,partner-code-3&bid=30b31c1838de1e,22aidtbx5eabd9,5d4531d5a6c013&sizes=300x250|300x600,728x90,300x250&referer=https%3A%2F%2Ftest.domain', - 'data': '[{"unitId": 13144370,"adUnitCode": "div-gpt-ad-1460505748561-0","sizes": [[300, 250], [300, 600]],"bidId": "2bdcb0b203c17d","referer": "https://test.domain/index.html"},' + - '{"unitId": 13144370,"adUnitCode":"div-gpt-ad-1460505748561-1","sizes": [[768, 90]],"bidId": "3dc6b8084f91a8","referer": "https://test.domain/index.html"},' + - '{"unitId": 0,"partnerId": 777,"adUnitCode":"div-gpt-ad-1460505748561-2","sizes": [[300, 250]],"bidId": "5d4531d5a6c013","referer": "https://test.domain/index.html"}]' - }; - - const bidResponse = { - body: { - 'div-gpt-ad-1460505748561-0': - { - 'ad': '
ad
', - 'width': 300, - 'height': 250, - 'creativeId': '8:123456', - 'adomain': [ - 'test.domain' - ], - 'syncs': [ - {'type': 'image', 'url': 'https://test.domain/tracker_1.gif'}, - {'type': 'image', 'url': 'https://test.domain/tracker_2.gif'}, - {'type': 'image', 'url': 'https://test.domain/tracker_3.gif'} - ], - 'winNotification': [ - { - 'method': 'POST', - 'path': '/hb/bid_won?test=1', - 'data': { - 'ad': [ - {'dsp': 8, 'id': 800008, 'cost': 1.0e-5, 'nurl': 'https://test.domain/'} - ], - 'unit_id': 1234, - 'site_id': 123 - } - } - ], - 'cpm': 0.01, - 'currency': 'USD', - 'netRevenue': true - } - }, - headers: {} - }; - - it('result is correct', function () { - const result = spec.interpretResponse(bidResponse, bidRequest); - expect(result[0].requestId).to.equal('2bdcb0b203c17d'); - expect(result[0].cpm).to.equal(0.01); - expect(result[0].width).to.equal(300); - expect(result[0].height).to.equal(250); - expect(result[0].creativeId).to.equal('8:123456'); - expect(result[0].currency).to.equal('USD'); - expect(result[0].ttl).to.equal(60); - expect(result[0].meta.advertiserDomains).to.deep.equal(['test.domain']); - expect(result[0].winNotification[0]).to.deep.equal({'method': 'POST', 'path': '/hb/bid_won?test=1', 'data': {'ad': [{'dsp': 8, 'id': 800008, 'cost': 1.0e-5, 'nurl': 'https://test.domain/'}], 'unit_id': 1234, 'site_id': 123}}); - }); - }); - - describe('adResponse', function () { - const bid = { - 'unitId': 13144370, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '2bdcb0b203c17d', - 'referer': 'https://test.domain/index.html' - }; - const ad = { - 'ad': '
ad
', - 'width': 300, - 'height': 250, - 'creativeId': '8:123456', - 'syncs': [], - 'winNotification': [], - 'cpm': 0.01, - 'currency': 'USD', - 'netRevenue': true, - 'adomain': [ - 'test.domain' - ], - }; - - it('fill ad for response', function () { - const result = spec.adResponse(bid, ad); - expect(result.requestId).to.equal('2bdcb0b203c17d'); - expect(result.cpm).to.equal(0.01); - expect(result.width).to.equal(300); - expect(result.height).to.equal(250); - expect(result.creativeId).to.equal('8:123456'); - expect(result.currency).to.equal('USD'); - expect(result.ttl).to.equal(60); - expect(result.meta.advertiserDomains).to.deep.equal(['test.domain']); - }); - }); - - describe('onBidWon', function () { - const bid = { - winNotification: [ - { - 'method': 'POST', - 'path': '/hb/bid_won?test=1', - 'data': { - 'ad': [ - {'dsp': 8, 'id': 800008, 'cost': 0.01, 'nurl': 'http://test.domain/'} - ], - 'unit_id': 1234, - 'site_id': 123 - } - } - ] - }; - - let ajaxStub; - - beforeEach(() => { - ajaxStub = sinon.stub(miUtils, 'postRequest') - }) - - afterEach(() => { - ajaxStub.restore() - }) - - it('calls adpartner\'s callback endpoint', () => { - const result = spec.onBidWon(bid); - expect(result).to.equal(true); - expect(ajaxStub.calledOnce).to.equal(true); - expect(ajaxStub.firstCall.args[0]).to.equal(ENDPOINT_PROTOCOL + '://' + ENDPOINT_DOMAIN + '/hb/bid_won?test=1'); - expect(ajaxStub.firstCall.args[1]).to.deep.equal(JSON.stringify(bid.winNotification[0].data)); - }); - }); - - describe('getUserSyncs', function () { - const bidResponse = [{ - body: { - 'div-gpt-ad-1460505748561-0': - { - 'ad': '
ad
', - 'width': 300, - 'height': 250, - 'creativeId': '8:123456', - 'adomain': [ - 'test.domain' - ], - 'syncs': [ - {'type': 'image', 'link': 'https://test.domain/tracker_1.gif'}, - {'type': 'image', 'link': 'https://test.domain/tracker_2.gif'}, - {'type': 'image', 'link': 'https://test.domain/tracker_3.gif'} - ], - 'winNotification': [ - { - 'method': 'POST', - 'path': '/hb/bid_won?test=1', - 'data': { - 'ad': [ - {'dsp': 8, 'id': 800008, 'cost': 1.0e-5, 'nurl': 'https://test.domain/'} - ], - 'unit_id': 1234, - 'site_id': 123 - } - } - ], - 'cpm': 0.01, - 'currency': 'USD', - 'netRevenue': true - } - }, - headers: {} - }]; - - it('should return nothing when sync is disabled', function () { - const syncOptions = { - 'iframeEnabled': false, - 'pixelEnabled': false - }; - - const syncs = spec.getUserSyncs(syncOptions); - expect(syncs).to.deep.equal([]); - }); - - it('should register image sync when only image is enabled where gdprConsent is undefined', function () { - const syncOptions = { - 'iframeEnabled': false, - 'pixelEnabled': true - }; - - const gdprConsent = undefined; - const syncs = spec.getUserSyncs(syncOptions, bidResponse, gdprConsent); - expect(syncs.length).to.equal(3); - expect(syncs[0].type).to.equal('image'); - expect(syncs[0].url).to.equal('https://test.domain/tracker_1.gif'); - }); - - it('should register image sync when only image is enabled where gdprConsent is defined', function () { - const syncOptions = { - 'iframeEnabled': false, - 'pixelEnabled': true - }; - const gdprConsent = { - consentString: 'someString', - vendorData: {}, - gdprApplies: true, - apiVersion: 2 - }; - - const syncs = spec.getUserSyncs(syncOptions, bidResponse, gdprConsent); - expect(syncs.length).to.equal(3); - expect(syncs[0].type).to.equal('image'); - expect(syncs[0].url).to.equal('https://test.domain/tracker_1.gif?gdpr=1&gdpr_consent=someString'); - }); - }); -}); diff --git a/test/spec/modules/adplusAnalyticsAdapter_spec.js b/test/spec/modules/adplusAnalyticsAdapter_spec.js deleted file mode 100644 index 589a9a589..000000000 --- a/test/spec/modules/adplusAnalyticsAdapter_spec.js +++ /dev/null @@ -1,176 +0,0 @@ -import adplusAnalyticsAdapter from 'modules/adplusAnalyticsAdapter.js'; -import { expect } from 'chai'; -import adapterManager from 'src/adapterManager.js'; -import { server } from 'test/mocks/xhr.js'; -import { EVENTS } from 'src/constants.js'; -import sinon from 'sinon'; - -let events = require('src/events'); - -describe('AdPlus analytics adapter', function () { - let sandbox, clock; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - sandbox.spy(console, 'log'); - - clock = sandbox.useFakeTimers(); - sandbox.stub(events, 'getEvents').returns([]); - adapterManager.enableAnalytics({ provider: 'adplus' }); - }); - - afterEach(function () { - sandbox.restore(); - adplusAnalyticsAdapter.reset(); - }); - - const auctionId = 'test-auction-123'; - - const bidsReceived = [ - { - bidderCode: 'adplus', - auctionId, - adUnitCode: 'adunit-1', - cpm: 5, - currency: 'USD', - size: '300x250', - width: 300, - height: 250, - creativeId: 'crea-1', - timeToRespond: 120, - netRevenue: true, - dealId: null - }, - { - bidderCode: 'adplus', - auctionId, - adUnitCode: 'adunit-2', - cpm: 7, - currency: 'USD', - size: '728x90', - width: 728, - height: 90, - creativeId: 'crea-2', - timeToRespond: 110, - netRevenue: true, - dealId: 'deal123' - } - ]; - - const bidWon1 = { - auctionId, - adUnitCode: 'adunit-1', - bidderCode: 'adplus', - cpm: 5, - currency: 'USD', - size: '300x250', - width: 300, - height: 250, - creativeId: 'crea-1', - timeToRespond: 120, - netRevenue: true, - dealId: null - }; - - const bidWon2 = { - auctionId, - adUnitCode: 'adunit-2', - bidderCode: 'adplus', - cpm: 7, - currency: 'USD', - size: '728x90', - width: 728, - height: 90, - creativeId: 'crea-2', - timeToRespond: 110, - netRevenue: true, - dealId: 'deal123' - }; - - it('should store bids on AUCTION_END and not send immediately', function () { - events.emit(EVENTS.AUCTION_END, { - auctionId, - bidsReceived - }); - - expect(server.requests.length).to.equal(0); - - const storedData = adplusAnalyticsAdapter.auctionBids[auctionId]; - expect(storedData).to.exist; - expect(Object.keys(storedData)).to.have.length(2); - expect(storedData['adunit-1'][0]).to.include({ - auctionId, - adUnitCode: 'adunit-1', - bidder: 'adplus', - cpm: 5, - currency: 'USD' - }); - }); - - it('should batch BID_WON events and send after delay with retries', function (done) { - // First, send AUCTION_END to prepare data - events.emit(EVENTS.AUCTION_END, { auctionId, bidsReceived }); - - // Emit first BID_WON - should send immediately - events.emit(EVENTS.BID_WON, bidWon1); - - clock.tick(0); - expect(server.requests.length).to.equal(1); - - // Fail first request, triggers retry after 200ms - server.requests[0].respond(500, {}, 'Internal Server Error'); - clock.tick(200); - - expect(server.requests.length).to.equal(2); - - // Fail second (retry) request, triggers next retry - server.requests[1].respond(500, {}, 'Internal Server Error'); - clock.tick(200); - - expect(server.requests.length).to.equal(3); - - // Succeed on third retry - server.requests[2].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ status: 'ok' })); - - // Now emit second BID_WON - queue is empty, should send immediately - events.emit(EVENTS.BID_WON, bidWon2); - - // Should wait 200ms after emit. - expect(server.requests.length).to.equal(3); - - // Sends the second BID_WON data after 200ms - clock.tick(200); - expect(server.requests.length).to.equal(4); - - // Succeed second BID_WON send - server.requests[3].respond(200, { 'Content-Type': 'application/json' }, JSON.stringify({ status: 'ok' })); - - // Validate payloads - const payload1 = JSON.parse(server.requests[0].requestBody); - const payload2 = JSON.parse(server.requests[3].requestBody); - - expect(payload1.winningBid).to.include({ - auctionId, - adUnitCode: 'adunit-1', - bidder: 'adplus', - cpm: 5, - }); - - expect(payload2.winningBid).to.include({ - auctionId, - adUnitCode: 'adunit-2', - bidder: 'adplus', - cpm: 7, - }); - - done(); - }); - - it('should skip BID_WON if no auction data available', function () { - // Emit BID_WON without AUCTION_END first - expect(() => events.emit(EVENTS.BID_WON, bidWon1)).to.not.throw(); - - // No ajax call since no auctionData - expect(server.requests.length).to.equal(0); - }); -}); diff --git a/test/spec/modules/adplusBidAdapter_spec.js b/test/spec/modules/adplusBidAdapter_spec.js deleted file mode 100644 index 5dc02ca37..000000000 --- a/test/spec/modules/adplusBidAdapter_spec.js +++ /dev/null @@ -1,237 +0,0 @@ -import {expect} from 'chai'; -import {ADPLUS_ENDPOINT, BIDDER_CODE, spec,} from 'modules/adplusBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; - -const TEST_UID = 'test-uid-value'; - -describe('AplusBidAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.be.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - const validRequest = { - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - inventoryId: '30', - adUnitId: '1', - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const validRequest = { - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - inventoryId: '30', - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(false); - }); - - it('should return false when required param types are wrong', function () { - const validRequest = { - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - inventoryId: 30, - adUnitId: '1', - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(false); - }); - - it('should return false when size is not exists', function () { - const validRequest = { - params: { - inventoryId: 30, - adUnitId: '1', - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(false); - }); - - it('should return false when size is wrong', function () { - const validRequest = { - mediaTypes: { - banner: { - sizes: [[300]] - } - }, - params: { - inventoryId: 30, - adUnitId: '1', - } - }; - expect(spec.isBidRequestValid(validRequest)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const validRequest = [ - { - bidder: BIDDER_CODE, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - inventoryId: '-1', - adUnitId: '-3', - }, - bidId: '2bdcb0b203c17d', - userId: { - adplusId: TEST_UID - }, - userIdAsEids: [{ - source: 'ad-plus.com.tr', - uids: [ - { - atype: 1, - id: TEST_UID - } - ] - }] - }, - ]; - - const bidderRequest = { - refererInfo: { - referer: 'https://test.domain' - } - }; - - it('bidRequest HTTP method', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - expect(request[0].method).to.equal('POST'); - }); - - it('bidRequest url', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - expect(request[0].url).to.equal(ADPLUS_ENDPOINT); - }); - - it('tests bidRequest data is clean and has the right values', function () { - const request = spec.buildRequests(validRequest, bidderRequest); - - expect(request[0].data.bidId).to.equal('2bdcb0b203c17d'); - expect(request[0].data.inventoryId).to.equal(-1); - expect(request[0].data.adUnitId).to.equal(-3); - expect(request[0].data.adUnitWidth).to.equal(300); - expect(request[0].data.adUnitHeight).to.equal(250); - expect(request[0].data.sdkVersion).to.equal('1'); - expect(request[0].data.adplusUid).to.equal(TEST_UID); - expect(request[0].data.eids).to.deep.equal([{ - source: 'ad-plus.com.tr', - uids: [ - { - atype: 1, - id: TEST_UID - } - ] - }]); - expect(typeof request[0].data.session).to.equal('string'); - expect(request[0].data.session).length(36); - expect(request[0].data.interstitial).to.equal(0); - expect(request[0].data).to.not.have.deep.property('extraData'); - expect(request[0].data).to.not.have.deep.property('yearOfBirth'); - expect(request[0].data).to.not.have.deep.property('gender'); - expect(request[0].data).to.not.have.deep.property('categories'); - expect(request[0].data).to.not.have.deep.property('latitude'); - expect(request[0].data).to.not.have.deep.property('longitude'); - }); - }); - - describe('interpretResponse', function () { - const requestData = { - language: window.navigator.language, - screenWidth: 1440, - screenHeight: 900, - sdkVersion: '1', - inventoryId: '-1', - adUnitId: '-3', - adUnitWidth: 300, - adUnitHeight: 250, - domain: 'tassandigi.com', - pageUrl: 'https%3A%2F%2Ftassandigi.com%2Fserafettin%2Fads.html', - interstitial: 0, - session: '1c02db03-5289-932a-93af-7b4022611fec', - token: '1c02db03-5289-937a-93df-7b4022611fec', - secure: 1, - bidId: '2bdcb0b203c17d', - }; - const bidRequest = { - 'method': 'POST', - 'url': ADPLUS_ENDPOINT, - 'data': requestData, - }; - - const bidResponse = { - body: [ - { - 'ad': '
ad
', - 'advertiserDomains': [ - 'advertiser.com' - ], - 'categoryIDs': [ - 'IAB-111' - ], - 'cpm': 3.57, - 'creativeID': '1', - 'currency': 'TRY', - 'dealID': '1', - 'height': 300, - 'mediaType': 'banner', - 'netRevenue': true, - 'requestID': '2bdcb0b203c17d', - 'ttl': 300, - 'width': 250 - } - ], - headers: {} - }; - - const emptyBidResponse = { - body: null, - }; - - it('returns an empty array when the result body is not valid', function () { - const result = spec.interpretResponse(emptyBidResponse, bidRequest); - expect(result).to.deep.equal([]); - }); - - it('result is correct', function () { - const result = spec.interpretResponse(bidResponse, bidRequest); - expect(result[0].requestId).to.equal('2bdcb0b203c17d'); - expect(result[0].cpm).to.equal(3.57); - expect(result[0].width).to.equal(250); - expect(result[0].height).to.equal(300); - expect(result[0].creativeId).to.equal('1'); - expect(result[0].currency).to.equal('TRY'); - expect(result[0].dealId).to.equal('1'); - expect(result[0].mediaType).to.equal('banner'); - expect(result[0].netRevenue).to.equal(true); - expect(result[0].ttl).to.equal(300); - expect(result[0].meta.advertiserDomains).to.deep.equal(['advertiser.com']); - expect(result[0].meta.secondaryCatIds).to.deep.equal(['IAB-111']); - }); - }); -}); diff --git a/test/spec/modules/adponeBidAdapter_spec.js b/test/spec/modules/adponeBidAdapter_spec.js deleted file mode 100644 index f28eecdd6..000000000 --- a/test/spec/modules/adponeBidAdapter_spec.js +++ /dev/null @@ -1,218 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adponeBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import * as utils from 'src/utils.js'; - -const EMPTY_ARRAY = []; -describe('adponeBidAdapter', function () { - const bid = { - bidder: 'adpone', - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - params: { - placementId: '1', - } - }; - - describe('build requests', () => { - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests([ - { - bidder: 'adpone', - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - params: { - placementId: '1', - } - } - ]); - expect(request[0].method).to.equal('POST'); - }); - it('sends bid request to adpone endpoint', function () { - const request = spec.buildRequests([ - { - bidder: 'adpone', - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - params: { - placementId: '1', - } - } - ]); - expect(request[0].url).to.equal('https://rtb.adpone.com/bid-request?pid=1'); - }); - }); - - describe('inherited functions', () => { - const adapter = newBidder(spec); - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when necessary information is found', function () { - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - - it('should return false when necessary information is not found', function () { - // empty bid - expect(spec.isBidRequestValid({bidId: '', params: {}})).to.be.false; - - // empty bidId - bid.bidId = ''; - expect(spec.isBidRequestValid(bid)).to.be.false; - - // empty placementId - bid.bidId = '30b31c1838de1e'; - bid.params.placementId = ''; - expect(spec.isBidRequestValid(bid)).to.be.false; - - bid.adUnitCode = 'adunit-code'; - }); - - it('returns false when bidder not set to "adpone"', function() { - const invalidBid = { - bidder: 'enopda', - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - params: { - placementId: '1', - } - }; - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - - it('returns false when placementId is not set in params', function() { - const invalidBid = { - bidder: 'adpone', - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - params: { - } - }; - - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - describe('interpretResponse', function () { - let serverResponse; - const bidRequest = { data: {id: '1234'} }; - - beforeEach(function () { - serverResponse = { - body: { - id: '2579e20c0bb89', - seatbid: [ - { - bid: [ - { - id: '613673EF-A07C-4486-8EE9-3FC71A7DC73D', - impid: '2579e20c0bb89_0', - price: 1, - adm: '', - meta: { - adomain: [ - 'adpone.com' - ] - }, - iurl: 'https://localhost11', - crid: 'creative111', - h: 250, - w: 300, - ext: { - dspid: 6 - } - } - ], - seat: 'adpone' - } - ], - cur: 'USD' - }, - }; - }); - - it('validate_response_params', function() { - const newResponse = spec.interpretResponse(serverResponse, bidRequest); - expect(newResponse[0].id).to.be.equal('613673EF-A07C-4486-8EE9-3FC71A7DC73D'); - expect(newResponse[0].requestId).to.be.equal('1234'); - expect(newResponse[0].cpm).to.be.equal(1); - expect(newResponse[0].width).to.be.equal(300); - expect(newResponse[0].height).to.be.equal(250); - expect(newResponse[0].currency).to.be.equal('USD'); - expect(newResponse[0].netRevenue).to.be.equal(true); - expect(newResponse[0].ttl).to.be.equal(300); - expect(newResponse[0].ad).to.be.equal(''); - }); - - it('should correctly reorder the server response', function () { - const newResponse = spec.interpretResponse(serverResponse, bidRequest); - expect(newResponse.length).to.be.equal(1); - expect(newResponse[0]).to.deep.equal({ - id: '613673EF-A07C-4486-8EE9-3FC71A7DC73D', - meta: { - advertiserDomains: [ - 'adpone.com' - ] - }, - requestId: '1234', - cpm: 1, - width: 300, - height: 250, - creativeId: 'creative111', - currency: 'USD', - netRevenue: true, - ttl: 300, - ad: '' - }); - }); - - it('should not add responses if the cpm is 0 or null', function () { - serverResponse.body.seatbid[0].bid[0].price = 0; - let response = spec.interpretResponse(serverResponse, bidRequest); - expect(response).to.deep.equal([]); - - serverResponse.body.seatbid[0].bid[0].price = null; - response = spec.interpretResponse(serverResponse, bidRequest); - expect(response).to.deep.equal([]) - }); - it('should add responses if the cpm is valid', function () { - serverResponse.body.seatbid[0].bid[0].price = 0.5; - const response = spec.interpretResponse(serverResponse, bidRequest); - expect(response).to.not.deep.equal([]); - }); - }); - - describe('test onBidWon function', function () { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - it('exists and is a function', () => { - expect(spec.onBidWon).to.exist.and.to.be.a('function'); - }); - it('should return nothing', function () { - var response = spec.onBidWon({}); - expect(response).to.be.an('undefined') - expect(utils.triggerPixel.called).to.equal(true); - }); - }); -}); diff --git a/test/spec/modules/adprimeBidAdapter_spec.js b/test/spec/modules/adprimeBidAdapter_spec.js deleted file mode 100644 index a917d85d6..000000000 --- a/test/spec/modules/adprimeBidAdapter_spec.js +++ /dev/null @@ -1,471 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/adprimeBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'adprime'; - -describe('AdprimeBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://delta.adprime.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.wPlayer).to.be.an('number'); - expect(placement.hPlayer).to.be.an('number'); - expect(placement.keywords).to.be.an('array'); - expect(placement.audiences).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync.adprime.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync.adprime.com/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync.adprime.com/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/adqueryBidAdapter_spec.js b/test/spec/modules/adqueryBidAdapter_spec.js deleted file mode 100644 index fef5b65c4..000000000 --- a/test/spec/modules/adqueryBidAdapter_spec.js +++ /dev/null @@ -1,237 +0,0 @@ -import { expect } from 'chai' -import { spec } from 'modules/adqueryBidAdapter.js' -import { newBidder } from 'src/adapters/bidderFactory.js' -import * as utils from '../../../src/utils.js'; - -describe('adqueryBidAdapter', function () { - const adapter = newBidder(spec) - const bidRequest = { - bidder: 'adquery', - params: { - placementId: '6d93f2a0e5f0fe2cc3a6e9e3ade964b43b07f897', - type: 'banner300x250' - }, - mediaTypes: { - banner: { - sizes: [[300, 250]], - } - } - } - - const expectedResponse = { - 'body': { - 'data': - { - 'requestId': 1, - 'emission_id': 1, - 'eventTracker': 'https://example.com', - 'externalEmissionCodes': 'https://example.com', - 'impressionTracker': 'https://example.com', - 'viewabilityTracker': 'https://example.com', - 'clickTracker': 'https://example.com', - 'link': 'https://example.com', - 'logo': 'https://example.com', - 'medias': [ - { - 'src': 'banner/2021-04-09/938', - 'ext': 'zip', - 'type': 3, - } - ], - 'domain': 'https://example.com', - 'urlAdq': 'https://example.com', - 'creationId': 1, - 'currency': 'PLN', - 'adDomains': ['https://example.com'], - 'tag': ' ', - 'adqLib': 'https://example.com/js/example.js', - 'mediaType': {'width': 300, 'height': 250, 'name': 'banner', 'type': 'banner300x250'}, - 'cpm': 2.5, - 'meta': { - 'advertiserDomains': ['example.com'], - 'mediaType': 'banner', - } - } - } - } - describe('codes', function () { - it('should return a bidder code of adquery', function () { - expect(spec.code).to.equal('adquery') - }) - }) - - describe('isBidRequestValid', function () { - const inValidBid = Object.assign({}, bidRequest) - delete inValidBid.params - it('should return true if all params present', function () { - expect(spec.isBidRequestValid(bidRequest)).to.equal(true) - }) - - it('should return false if any parameter missing', function () { - expect(spec.isBidRequestValid(inValidBid)).to.be.false - }) - - it('should return false when sizes for banner are not specified', () => { - const bid = utils.deepClone(bidRequest); - delete bid.mediaTypes.banner.sizes; - - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }) - - describe('buildRequests', function () { - let req; - beforeEach(() => { - req = spec.buildRequests([ bidRequest ], { refererInfo: { } })[0] - }) - - let rdata - - it('should return request object', function () { - expect(req).to.not.be.null - }) - - it('should build request data', function () { - expect(req.data).to.not.be.null - }) - - it('should include one request', function () { - rdata = req.data; - expect(rdata.data).to.not.be.null - }) - - it('should include placementCode', function () { - expect(rdata.placementCode).not.be.null - }) - - it('should include qid', function () { - expect(rdata.qid).not.be.null - }) - - it('should include type', function () { - expect(rdata.type !== null).not.be.null - }) - - it('should include all publisher params', function () { - expect(rdata.type !== null && rdata.placementCode !== null).to.be.true - }) - - it('should include bidder', function () { - expect(rdata.bidder !== null).to.be.true - }) - - it('should include sizes', function () { - expect(rdata.sizes).not.be.null - }) - - it('should include version', function () { - expect(rdata.v).not.be.null - expect(rdata.v).equal('$prebid.version$') - }) - - it('should include referrer', function () { - expect(rdata.bidPageUrl).not.be.null - }) - }) - - describe('interpretResponse', function () { - it('should get the correct bid response', function () { - const result = spec.interpretResponse(expectedResponse) - expect(result).to.be.an('array') - }) - - it('validate response params', function() { - const newResponse = spec.interpretResponse(expectedResponse, bidRequest); - expect(newResponse[0].requestId).to.be.equal(1) - }); - it('handles empty bid response', function () { - const response = { - body: {} - }; - const result = spec.interpretResponse(response); - expect(result.length).to.equal(0); - }) - }) - - describe('getUserSyncs', function () { - it('should return iframe sync', function () { - const sync = spec.getUserSyncs( - { - iframeEnabled: true, - pixelEnabled: true, - }, - {}, - { - consentString: 'ALL', - gdprApplies: true, - }, - {} - ) - expect(sync.length).to.equal(1) - expect(sync[0].type === 'iframe') - expect(typeof sync[0].url === 'string') - }) - it('should return image sync', function () { - const sync = spec.getUserSyncs( - { - iframeEnabled: false, - pixelEnabled: true, - }, - {}, - { - consentString: 'ALL', - gdprApplies: true, - }, - {} - ) - expect(sync.length).to.equal(1) - expect(sync[0].type === 'image') - expect(typeof sync[0].url === 'string') - }) - - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - }); - }) - - describe('test onBidWon function', function () { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - it('exists and is a function', () => { - expect(spec.onBidWon).to.exist.and.to.be.a('function'); - }); - it('should return nothing', function () { - var response = spec.onBidWon({}); - expect(response).to.be.an('undefined') - expect(utils.triggerPixel.called).to.equal(true); - }); - }) - - describe('onTimeout', function () { - const timeoutData = [{ - timeout: null - }]; - - it('should exists and be a function', () => { - expect(spec.onTimeout).to.exist.and.to.be.a('function'); - }); - it('should include timeoutData', function () { - expect(spec.onTimeout(timeoutData)).to.be.undefined; - }) - }); - - it(`onSetTargeting is present and type function`, function () { - expect(spec.onSetTargeting).to.exist.and.to.be.a('function') - }); -}) diff --git a/test/spec/modules/adrelevantisBidAdapter_spec.js b/test/spec/modules/adrelevantisBidAdapter_spec.js deleted file mode 100644 index eb7d81dbd..000000000 --- a/test/spec/modules/adrelevantisBidAdapter_spec.js +++ /dev/null @@ -1,755 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adrelevantisBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import * as bidderFactory from 'src/adapters/bidderFactory.js'; -import { deepClone } from 'src/utils.js'; -import { config } from 'src/config.js'; - -const ENDPOINT = 'https://ssp.adrelevantis.com/prebid'; - -describe('AdrelevantisAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'adrelevantis', - 'params': { - 'placementId': '10433394' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'placementId': 0 - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - 'bidder': 'adrelevantis', - 'params': { - 'placementId': '10433394' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - } - ]; - - it('should parse out private sizes', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placementId: '10433394', - privateSizes: [300, 250] - } - } - ); - - const request = spec.buildRequests([bidRequest], {}); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].private_sizes).to.exist; - expect(payload.tags[0].private_sizes).to.deep.equal([{width: 300, height: 250}]); - }); - - it('should add source and verison to the tag', function () { - const request = spec.buildRequests(bidRequests, {}); - const payload = JSON.parse(request.data); - expect(payload.sdk).to.exist; - expect(payload.sdk).to.deep.equal({ - source: 'pbjs', - version: '$prebid.version$' - }); - }); - - it('should populate the ad_types array on all requests', function () { - ['banner', 'video', 'native'].forEach(type => { - const bidRequest = Object.assign({}, bidRequests[0]); - bidRequest.mediaTypes = {}; - bidRequest.mediaTypes[type] = {}; - - const request = spec.buildRequests([bidRequest], {}); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].ad_types).to.deep.equal([type]); - }); - }); - - it('should populate the ad_types array on outstream requests', function () { - const bidRequest = Object.assign({}, bidRequests[0]); - bidRequest.mediaTypes = {}; - bidRequest.mediaTypes.video = {context: 'outstream'}; - - const request = spec.buildRequests([bidRequest], {}); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].ad_types).to.deep.equal(['video']); - }); - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, {}); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('should attach valid video params to the tag', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placementId: '10433394', - video: { - id: 123, - minduration: 100, - foobar: 'invalid' - } - } - } - ); - - const request = spec.buildRequests([bidRequest], {}); - const payload = JSON.parse(request.data); - expect(payload.tags[0].video).to.deep.equal({ - id: 123, - minduration: 100 - }); - }); - - it('should add video property when adUnit includes a renderer', function () { - const videoData = { - mediaTypes: { - video: { - context: 'outstream', - mimes: ['video/mp4'] - } - }, - params: { - placementId: '10433394', - video: { - skippable: true, - playback_method: ['auto_play_sound_off'] - } - } - }; - - let bidRequest1 = deepClone(bidRequests[0]); - bidRequest1 = Object.assign({}, bidRequest1, videoData, { - renderer: { - url: 'http://test.renderer.url', - render: function () {} - } - }); - - let bidRequest2 = deepClone(bidRequests[0]); - bidRequest2.adUnitCode = 'adUnit_code_2'; - bidRequest2 = Object.assign({}, bidRequest2, videoData); - - const request = spec.buildRequests([bidRequest1, bidRequest2], {}); - const payload = JSON.parse(request.data); - expect(payload.tags[0].video).to.deep.equal({ - skippable: true, - playback_method: ['auto_play_sound_off'], - custom_renderer_present: true - }); - expect(payload.tags[1].video).to.deep.equal({ - skippable: true, - playback_method: ['auto_play_sound_off'] - }); - }); - - it('should attach valid user params to the tag', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placementId: '10433394', - user: { - externalUid: '123', - foobar: 'invalid' - } - } - } - ); - - const request = spec.buildRequests([bidRequest], {}); - const payload = JSON.parse(request.data); - - expect(payload.user).to.exist; - expect(payload.user).to.deep.equal({ - externalUid: '123', - }); - }); - - it('should contain hb_source value for other media', function() { - const bidRequest = Object.assign({}, - bidRequests[0], - { - mediaType: 'banner', - params: { - sizes: [[300, 250], [300, 600]], - placementId: 10433394 - } - } - ); - const request = spec.buildRequests([bidRequest], {}); - const payload = JSON.parse(request.data); - expect(payload.tags[0].hb_source).to.deep.equal(1); - }); - - it('adds context data (category and keywords) to request when set', function() { - const bidRequest = Object.assign({}, bidRequests[0]); - const ortb2 = { - site: { - keywords: 'US Open', - ext: { - data: {category: 'sports/tennis'} - } - } - }; - - const request = spec.buildRequests([bidRequest], {ortb2}); - const payload = JSON.parse(request.data); - - expect(payload.fpd.keywords).to.equal('US Open'); - expect(payload.fpd.category).to.equal('sports/tennis'); - }); - - it('should attach native params to the request', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - mediaType: 'native', - nativeParams: { - title: {required: true}, - body: {required: true}, - body2: {required: true}, - image: {required: true, sizes: [100, 100]}, - icon: {required: true}, - cta: {required: false}, - rating: {required: true}, - sponsoredBy: {required: true}, - privacyLink: {required: true}, - displayUrl: {required: true}, - address: {required: true}, - downloads: {required: true}, - likes: {required: true}, - phone: {required: true}, - price: {required: true}, - salePrice: {required: true} - } - } - ); - - const request = spec.buildRequests([bidRequest], {}); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].native.layouts[0]).to.deep.equal({ - title: {required: true}, - description: {required: true}, - desc2: {required: true}, - main_image: {required: true, sizes: [{ width: 100, height: 100 }]}, - icon: {required: true}, - ctatext: {required: false}, - rating: {required: true}, - sponsored_by: {required: true}, - privacy_link: {required: true}, - displayurl: {required: true}, - address: {required: true}, - downloads: {required: true}, - likes: {required: true}, - phone: {required: true}, - price: {required: true}, - saleprice: {required: true}, - privacy_supported: true - }); - expect(payload.tags[0].hb_source).to.equal(1); - }); - - it('should always populated tags[].sizes with 1,1 for native if otherwise not defined', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - mediaType: 'native', - nativeParams: { - image: { required: true } - } - } - ); - bidRequest.sizes = [[150, 100], [300, 250]]; - - let request = spec.buildRequests([bidRequest], {}); - let payload = JSON.parse(request.data); - expect(payload.tags[0].sizes).to.deep.equal([{width: 150, height: 100}, {width: 300, height: 250}]); - - delete bidRequest.sizes; - - request = spec.buildRequests([bidRequest], {}); - payload = JSON.parse(request.data); - - expect(payload.tags[0].sizes).to.deep.equal([{width: 1, height: 1}]); - }); - - it('should convert keyword params to proper form and attaches to request', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placementId: '10433394', - keywords: { - single: 'val', - singleArr: ['val'], - singleArrNum: [5], - multiValMixed: ['value1', 2, 'value3'], - singleValNum: 123, - emptyStr: '', - emptyArr: [''], - badValue: {'foo': 'bar'} // should be dropped - } - } - } - ); - - const request = spec.buildRequests([bidRequest], {}); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].keywords).to.deep.equal([{ - 'key': 'single', - 'value': ['val'] - }, { - 'key': 'singleArr', - 'value': ['val'] - }, { - 'key': 'singleArrNum', - 'value': ['5'] - }, { - 'key': 'multiValMixed', - 'value': ['value1', '2', 'value3'] - }, { - 'key': 'singleValNum', - 'value': ['123'] - }, { - 'key': 'emptyStr' - }, { - 'key': 'emptyArr' - }]); - }); - - it('should add payment rules to the request', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placementId: '10433394', - usePaymentRule: true - } - } - ); - - const request = spec.buildRequests([bidRequest], {}); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].use_pmt_rule).to.equal(true); - }); - - it('should add gdpr consent information to the request', function () { - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const bidderRequest = { - 'bidderCode': 'adrelevantis', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - consentString: consentString, - gdprApplies: true - } - }; - bidderRequest.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdpr_consent).to.exist; - expect(payload.gdpr_consent.consent_string).to.exist.and.to.equal(consentString); - expect(payload.gdpr_consent.consent_required).to.exist.and.to.be.true; - }); - - it('supports sending hybrid mobile app parameters', function () { - const appRequest = Object.assign({}, - bidRequests[0], - { - params: { - placementId: '10433394', - app: { - id: 'B1O2W3M4AN.com.prebid.webview', - geo: { - lat: 40.0964439, - lng: -75.3009142 - }, - device_id: { - idfa: '4D12078D-3246-4DA4-AD5E-7610481E7AE', // Apple advertising identifier - aaid: '38400000-8cf0-11bd-b23e-10b96e40000d', // Android advertising identifier - md5udid: '5756ae9022b2ea1e47d84fead75220c8', // MD5 hash of the ANDROID_ID - sha1udid: '4DFAA92388699AC6539885AEF1719293879985BF', // SHA1 hash of the ANDROID_ID - windowsadid: '750c6be243f1c4b5c9912b95a5742fc5' // Windows advertising identifier - } - } - } - } - ); - const request = spec.buildRequests([appRequest], {}); - const payload = JSON.parse(request.data); - expect(payload.app).to.exist; - expect(payload.app).to.deep.equal({ - appid: 'B1O2W3M4AN.com.prebid.webview' - }); - expect(payload.device.device_id).to.exist; - expect(payload.device.device_id).to.deep.equal({ - aaid: '38400000-8cf0-11bd-b23e-10b96e40000d', - idfa: '4D12078D-3246-4DA4-AD5E-7610481E7AE', - md5udid: '5756ae9022b2ea1e47d84fead75220c8', - sha1udid: '4DFAA92388699AC6539885AEF1719293879985BF', - windowsadid: '750c6be243f1c4b5c9912b95a5742fc5' - }); - expect(payload.device.geo).to.exist; - expect(payload.device.geo).to.deep.equal({ - lat: 40.0964439, - lng: -75.3009142 - }); - }); - - it('should add referer info to payload', function () { - const bidRequest = Object.assign({}, bidRequests[0]) - const bidderRequest = { - refererInfo: { - topmostLocation: 'http://example.com/page.html', - reachedTop: true, - numIframes: 2, - stack: [ - 'http://example.com/page.html', - 'http://example.com/iframe1.html', - 'http://example.com/iframe2.html' - ] - } - } - const request = spec.buildRequests([bidRequest], bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.referrer_detection).to.exist; - expect(payload.referrer_detection).to.deep.equal({ - rd_ref: 'http%3A%2F%2Fexample.com%2Fpage.html', - rd_top: true, - rd_ifs: 2, - rd_stk: bidderRequest.refererInfo.stack.map((url) => encodeURIComponent(url)).join(',') - }); - }); - - it('should populate coppa if set in config', function () { - const bidRequest = Object.assign({}, bidRequests[0]); - sinon.stub(config, 'getConfig') - .withArgs('coppa') - .returns(true); - - const request = spec.buildRequests([bidRequest], {}); - const payload = JSON.parse(request.data); - - expect(payload.user.coppa).to.equal(true); - - config.getConfig.restore(); - }); - }) - - describe('interpretResponse', function () { - const response = { - 'version': '3.0.0', - 'tags': [ - { - 'uuid': '3db3773286ee59', - 'tag_id': 10433394, - 'auction_id': '4534722592064951574', - 'nobid': false, - 'no_ad_url': 'http://lax1-ib.adnxs.com/no-ad', - 'timeout_ms': 10000, - 'ad_profile_id': 27079, - 'ads': [ - { - 'content_source': 'rtb', - 'ad_type': 'banner', - 'buyer_member_id': 958, - 'creative_id': 29681110, - 'media_type_id': 1, - 'media_subtype_id': 1, - 'cpm': 0.5, - 'cpm_publisher_currency': 0.5, - 'publisher_currency_code': '$', - 'client_initiated_ad_counting': true, - 'viewability': { - 'config': '' - }, - 'rtb': { - 'banner': { - 'content': '', - 'width': 300, - 'height': 250 - }, - 'trackers': [ - { - 'impression_urls': [ - 'http://lax1-ib.adnxs.com/impression' - ], - 'video_events': {} - } - ] - } - } - ] - } - ] - }; - - it('should get correct bid response', function () { - const expectedResponse = [ - { - 'requestId': '3db3773286ee59', - 'cpm': 0.5, - 'creativeId': 29681110, - 'dealId': undefined, - 'width': 300, - 'height': 250, - 'ad': '', - 'mediaType': 'banner', - 'currency': 'USD', - 'ttl': 300, - 'netRevenue': true, - 'adUnitCode': 'code', - 'adrelevantis': { - 'buyerMemberId': 958 - } - } - ]; - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - } - const result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - - it('handles nobid responses', function () { - const response = { - 'version': '0.0.1', - 'tags': [{ - 'uuid': '84ab500420319d', - 'tag_id': 5976557, - 'auction_id': '297492697822162468', - 'nobid': true - }] - }; - let bidderRequest; - - const result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(result.length).to.equal(0); - }); - - it('handles outstream video responses', function () { - const response = { - 'tags': [{ - 'uuid': '84ab500420319d', - 'ads': [{ - 'ad_type': 'video', - 'cpm': 0.500000, - 'notify_url': 'imptracker.com', - 'rtb': { - 'video': { - 'content': '' - } - }, - 'javascriptTrackers': '' - }] - }] - }; - const bidderRequest = { - bids: [{ - bidId: '84ab500420319d', - adUnitCode: 'code', - mediaTypes: { - video: { - context: 'outstream' - } - } - }] - } - - const result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(result[0]).to.have.property('vastXml'); - expect(result[0]).to.have.property('vastImpUrl'); - expect(result[0]).to.have.property('mediaType', 'video'); - }); - - it('handles instream video responses', function () { - const response = { - 'tags': [{ - 'uuid': '84ab500420319d', - 'ads': [{ - 'ad_type': 'video', - 'cpm': 0.500000, - 'notify_url': 'imptracker.com', - 'rtb': { - 'video': { - 'asset_url': 'https://sample.vastURL.com/here/vid' - } - }, - 'javascriptTrackers': '' - }] - }] - }; - const bidderRequest = { - bids: [{ - bidId: '84ab500420319d', - adUnitCode: 'code', - mediaTypes: { - video: { - context: 'instream' - } - } - }] - } - - const result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(result[0]).to.have.property('vastUrl'); - expect(result[0]).to.have.property('vastImpUrl'); - expect(result[0]).to.have.property('mediaType', 'video'); - }); - - it('handles native responses', function () { - const response1 = deepClone(response); - response1.tags[0].ads[0].ad_type = 'native'; - response1.tags[0].ads[0].rtb.native = { - 'title': 'Native Creative', - 'desc': 'Cool description great stuff', - 'desc2': 'Additional body text', - 'ctatext': 'Do it', - 'sponsored': 'AppNexus', - 'icon': { - 'width': 0, - 'height': 0, - 'url': 'https://cdn.adnxs.com/icon.png' - }, - 'main_img': { - 'width': 2352, - 'height': 1516, - 'url': 'https://cdn.adnxs.com/img.png' - }, - 'link': { - 'url': 'https://www.appnexus.com', - 'fallback_url': '', - 'click_trackers': ['https://nym1-ib.adnxs.com/click'] - }, - 'impression_trackers': ['https://example.com'], - 'rating': '5', - 'displayurl': 'https://AppNexus.com/?url=display_url', - 'likes': '38908320', - 'downloads': '874983', - 'price': '9.99', - 'saleprice': 'FREE', - 'phone': '1234567890', - 'address': '28 W 23rd St, New York, NY 10010', - 'privacy_link': 'https://appnexus.com/?url=privacy_url', - 'javascriptTrackers': '' - }; - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - } - - const result = spec.interpretResponse({ body: response1 }, {bidderRequest}); - expect(result[0].native.title).to.equal('Native Creative'); - expect(result[0].native.body).to.equal('Cool description great stuff'); - expect(result[0].native.cta).to.equal('Do it'); - expect(result[0].native.image.url).to.equal('https://cdn.adnxs.com/img.png'); - }); - - it('supports configuring outstream renderers', function () { - const outstreamResponse = deepClone(response); - outstreamResponse.tags[0].ads[0].rtb.video = {}; - outstreamResponse.tags[0].ads[0].renderer_url = 'renderer.js'; - - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - renderer: { - options: { - adText: 'configured' - } - }, - mediaTypes: { - video: { - context: 'outstream' - } - } - }] - }; - - const result = spec.interpretResponse({ body: outstreamResponse }, {bidderRequest}); - expect(result[0].renderer.config).to.deep.equal( - bidderRequest.bids[0].renderer.options - ); - }); - - it('should add deal_priority and deal_code', function() { - const responseWithDeal = deepClone(response); - responseWithDeal.tags[0].ads[0].deal_priority = 'high'; - responseWithDeal.tags[0].ads[0].deal_code = '123'; - - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - } - const result = spec.interpretResponse({ body: responseWithDeal }, {bidderRequest}); - expect(Object.keys(result[0].adrelevantis)).to.include.members(['buyerMemberId', 'dealPriority', 'dealCode']); - }); - - it('should add advertiser id', function() { - const responseAdvertiserId = deepClone(response); - responseAdvertiserId.tags[0].ads[0].advertiser_id = '123'; - - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - } - const result = spec.interpretResponse({ body: responseAdvertiserId }, {bidderRequest}); - expect(Object.keys(result[0].meta)).to.include.members(['advertiserId']); - }) - }); -}); diff --git a/test/spec/modules/adrinoBidAdapter_spec.js b/test/spec/modules/adrinoBidAdapter_spec.js deleted file mode 100644 index f86fe7126..000000000 --- a/test/spec/modules/adrinoBidAdapter_spec.js +++ /dev/null @@ -1,353 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adrinoBidAdapter.js'; -import {config} from '../../../src/config.js'; -import * as utils from '../../../src/utils.js'; - -describe('adrinoBidAdapter', function () { - afterEach(() => { - config.resetConfig(); - }); - - describe('isBidRequestValid', function () { - const validBid = { - bidder: 'adrino', - params: { - hash: 'abcdef123456' - }, - mediaTypes: { - native: { - title: { - required: true - }, - image: { - required: true, - sizes: [[300, 150], [300, 210]] - } - } - }, - adUnitCode: 'adunit-code', - bidId: '12345678901234', - bidderRequestId: '98765432109876', - auctionId: '01234567891234', - }; - - it('should return true when all mandatory parameters are there', function () { - expect(spec.isBidRequestValid(validBid)).to.equal(true); - }); - - it('should return false when there are no params', function () { - const bid = { ...validBid }; - delete bid.params; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when unsupported media type is requested', function () { - const bid = { ...validBid }; - bid.mediaTypes = { video: {} }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when hash is not a string', function () { - const bid = { ...validBid }; - bid.params.hash = 123; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildBannerRequest', function () { - const bidRequest = { - bidder: 'adrino', - params: { - hash: 'abcdef123456' - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [970, 250]] - } - }, - sizes: [[300, 250], [970, 250]], - userIdAsEids: [ - {source: 'src1.org', uids: [{id: '1234', atype: 1}]}, - {source: 'src2.org', uids: [{id: '5678', atype: 1}]} - ], - adUnitCode: 'adunit-code-2', - bidId: '12345678901234', - bidderRequestId: '98765432109876', - auctionId: '01234567891234', - }; - - it('should build the request correctly', function () { - const result = spec.buildRequests( - [ bidRequest ], - { refererInfo: { page: 'http://example.com/' } } - ); - expect(result.length).to.equal(1); - expect(result[0].method).to.equal('POST'); - expect(result[0].url).to.equal('https://prd-prebid-bidder.adrino.io/bidder/bids/'); - expect(result[0].data[0].adUnitCode).to.equal('adunit-code-2'); - expect(result[0].data[0].bidId).to.equal('12345678901234'); - expect(result[0].data[0].placementHash).to.equal('abcdef123456'); - expect(result[0].data[0].referer).to.equal('http://example.com/'); - expect(result[0].data[0].userAgent).to.equal(navigator.userAgent); - expect(result[0].data[0]).to.have.property('bannerParams'); - expect(result[0].data[0].bannerParams.sizes.length).to.equal(2); - expect(result[0].data[0]).to.have.property('eids'); - expect(result[0].data[0].eids).to.be.an('array').with.lengthOf(2); - expect(result[0].data[0].eids).to.deep.include({ - source: 'src1.org', - uids: [{id: '1234', atype: 1}] - }); - expect(result[0].data[0].eids).to.deep.include({ - source: 'src2.org', - uids: [{id: '5678', atype: 1}] - }); - }); - }); - - describe('buildNativeRequest', function () { - const bidRequest = { - bidder: 'adrino', - params: { - hash: 'abcdef123456' - }, - mediaTypes: { - native: { - title: { - required: true - }, - image: { - required: true, - sizes: [[300, 150], [300, 210]] - } - } - }, - nativeParams: { - title: { - required: true - }, - image: { - required: true, - sizes: [[300, 150], [300, 210]] - } - }, - userIdAsEids: [ - {source: 'src1.org', uids: [{id: '1234', atype: 1}]}, - {source: 'src2.org', uids: [{id: '5678', atype: 1}]} - ], - adUnitCode: 'adunit-code', - bidId: '12345678901234', - bidderRequestId: '98765432109876', - auctionId: '01234567891234', - }; - - it('should build the request correctly with custom domain', function () { - config.setConfig({adrino: { host: 'https://stg-prebid-bidder.adrino.io' }}); - const result = spec.buildRequests( - [ bidRequest ], - { refererInfo: { page: 'http://example.com/' } } - ); - expect(result.length).to.equal(1); - expect(result[0].method).to.equal('POST'); - expect(result[0].url).to.equal('https://stg-prebid-bidder.adrino.io/bidder/bids/'); - expect(result[0].data[0].adUnitCode).to.equal('adunit-code'); - expect(result[0].data[0].bidId).to.equal('12345678901234'); - expect(result[0].data[0].placementHash).to.equal('abcdef123456'); - expect(result[0].data[0].referer).to.equal('http://example.com/'); - expect(result[0].data[0].userAgent).to.equal(navigator.userAgent); - expect(result[0].data[0]).to.have.property('nativeParams'); - expect(result[0].data[0]).not.to.have.property('gdprConsent'); - expect(result[0].data[0]).to.have.property('eids'); - expect(result[0].data[0].eids).to.be.an('array').with.lengthOf(2); - expect(result[0].data[0].eids).to.deep.include({ - source: 'src1.org', - uids: [{id: '1234', atype: 1}] - }); - expect(result[0].data[0].eids).to.deep.include({ - source: 'src2.org', - uids: [{id: '5678', atype: 1}] - }); - }); - - it('should build the request correctly with gdpr', function () { - const result = spec.buildRequests( - [ bidRequest ], - { gdprConsent: { gdprApplies: true, consentString: 'abc123' }, refererInfo: { page: 'http://example.com/' } } - ); - expect(result.length).to.equal(1); - expect(result[0].method).to.equal('POST'); - expect(result[0].url).to.equal('https://prd-prebid-bidder.adrino.io/bidder/bids/'); - expect(result[0].data[0].adUnitCode).to.equal('adunit-code'); - expect(result[0].data[0].bidId).to.equal('12345678901234'); - expect(result[0].data[0].placementHash).to.equal('abcdef123456'); - expect(result[0].data[0].referer).to.equal('http://example.com/'); - expect(result[0].data[0].userAgent).to.equal(navigator.userAgent); - expect(result[0].data[0]).to.have.property('nativeParams'); - expect(result[0].data[0]).to.have.property('gdprConsent'); - expect(result[0].data[0]).to.have.property('eids'); - expect(result[0].data[0].eids).to.be.an('array').with.lengthOf(2); - expect(result[0].data[0].eids).to.deep.include({ - source: 'src1.org', - uids: [{id: '1234', atype: 1}] - }); - expect(result[0].data[0].eids).to.deep.include({ - source: 'src2.org', - uids: [{id: '5678', atype: 1}] - }); - }); - - it('should build the request correctly without gdpr', function () { - const result = spec.buildRequests( - [ bidRequest ], - { refererInfo: { page: 'http://example.com/' } } - ); - expect(result.length).to.equal(1); - expect(result[0].method).to.equal('POST'); - expect(result[0].url).to.equal('https://prd-prebid-bidder.adrino.io/bidder/bids/'); - expect(result[0].data[0].adUnitCode).to.equal('adunit-code'); - expect(result[0].data[0].bidId).to.equal('12345678901234'); - expect(result[0].data[0].placementHash).to.equal('abcdef123456'); - expect(result[0].data[0].referer).to.equal('http://example.com/'); - expect(result[0].data[0].userAgent).to.equal(navigator.userAgent); - expect(result[0].data[0]).to.have.property('nativeParams'); - expect(result[0].data[0]).not.to.have.property('gdprConsent'); - expect(result[0].data[0]).to.have.property('eids'); - expect(result[0].data[0].eids).to.be.an('array').with.lengthOf(2); - expect(result[0].data[0].eids).to.deep.include({ - source: 'src1.org', - uids: [{id: '1234', atype: 1}] - }); - expect(result[0].data[0].eids).to.deep.include({ - source: 'src2.org', - uids: [{id: '5678', atype: 1}] - }); - }); - }); - - describe('interpretResponse', function () { - it('should interpret the response correctly', function () { - const response1 = { - requestId: '31662c69728811', - mediaType: 'native', - cpm: 0.53, - currency: 'PLN', - creativeId: '859115', - netRevenue: true, - ttl: 600, - width: 1, - height: 1, - noAd: false, - testAd: false, - native: { - title: 'Ad Title', - body: 'Ad Body', - image: { - url: 'http://emisja.contentstream.pl/_/getImageII/?vid=17180728299&typ=cs_300_150&element=IMAGE&scale=1&prefix=adart&nc=1643878278955', - height: 150, - width: 300 - }, - clickUrl: 'http://emisja.contentstream.pl/_/ctr2/?u=https%3A%2F%2Fonline.efortuna.pl%2Fpage%3Fkey%3Dej0xMzUzMTM1NiZsPTE1Mjc1MzY1JnA9NTMyOTA%253D&e=znU3tABN8K4N391dmUxYfte5G9tBaDXELJVo1_-kvaTJH2XwWRw77fmfL2YjcEmrbqRQ3M0GcJ0vPWcLtZlsrf8dWrAEHNoZKAC6JMnZF_65IYhTPbQIJ-zn3ac9TU7gEZftFKksH1al7rMuieleVv9r6_DtrOk_oZcYAe4rMRQM-TiWvivJRPBchAAblE0cqyG7rCunJFpal43sxlYm4GvcBJaYHzErn5PXjEzNbd3xHjkdiap-xU9y6BbfkUZ1xIMS8QZLvwNrTXMFCSfSRN2tgVfEj7KyGdLCITHSaFtuIKT2iW2pxC7f2RtPHnzsEPXH0SgAfhA3OxZ5jkQjOZy0PsO7MiCv3sJai5ezUAOjFgayU91ZhI0Y9r2YpB1tTGIjnO23wot8PvRENlThHQ%3D%3D&ref=https%3A%2F%2Fbox.adrino.cloud%2Ftmielcarz%2Fadrino_prebid%2Ftest_page3.html%3Fpbjs_debug%3Dtrue', - privacyLink: 'https://adrino.pl/wp-content/uploads/2021/01/POLITYKA-PRYWATNOS%CC%81CI-Adrino-Mobile.pdf', - impressionTrackers: [ - 'https://prd-impression-tracker-producer.adrino.io/impression/eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ7XCJpbXByZXNzaW9uSWRcIjpcIjMxNjYyYzY5NzI4ODExXCIsXCJkYXRlXCI6WzIwMjIsMiwzXSxcInBsYWNlbWVudEhhc2hcIjpcIjk0NTVjMDQxYzlkMTI1ZmIwNDE4MWVhMGVlZTJmMmFlXCIsXCJjYW1wYWlnbklkXCI6MTc5MjUsXCJhZHZlcnRpc2VtZW50SWRcIjo5MjA3OSxcInZpc3VhbGlzYXRpb25JZFwiOjg1OTExNSxcImNwbVwiOjUzLjB9IiwiZXhwIjoxNjQzOTE2MjUxLCJpYXQiOjE2NDM5MTU2NTF9.0Y_HvInGl6Xo5xP6rDLC8lzQRGvy-wKe0blk1o8ebWyVRFiUY1JGLUeE0k3sCsPNxgdHAv-o6EcbogpUuqlMJA' - ] - } - }; - - const response2 = { - requestId: '31662c69728812', - mediaType: 'native', - cpm: 0.77, - currency: 'PLN', - creativeId: '859120', - netRevenue: true, - ttl: 600, - width: 1, - height: 1, - noAd: false, - testAd: false, - native: { - title: 'Ad Title', - body: 'Ad Body', - image: { - url: 'http://emisja.contentstream.pl/_/getImageII/?vid=17180728299&typ=cs_300_150&element=IMAGE&scale=1&prefix=adart&nc=1643878278955', - height: 150, - width: 300 - }, - clickUrl: 'http://emisja.contentstream.pl/_/ctr2/?u=https%3A%2F%2Fonline.efortuna.pl%2Fpage%3Fkey%3Dej0xMzUzMTM1NiZsPTE1Mjc1MzY1JnA9NTMyOTA%253D&e=znU3tABN8K4N391dmUxYfte5G9tBaDXELJVo1_-kvaTJH2XwWRw77fmfL2YjcEmrbqRQ3M0GcJ0vPWcLtZlsrf8dWrAEHNoZKAC6JMnZF_65IYhTPbQIJ-zn3ac9TU7gEZftFKksH1al7rMuieleVv9r6_DtrOk_oZcYAe4rMRQM-TiWvivJRPBchAAblE0cqyG7rCunJFpal43sxlYm4GvcBJaYHzErn5PXjEzNbd3xHjkdiap-xU9y6BbfkUZ1xIMS8QZLvwNrTXMFCSfSRN2tgVfEj7KyGdLCITHSaFtuIKT2iW2pxC7f2RtPHnzsEPXH0SgAfhA3OxZ5jkQjOZy0PsO7MiCv3sJai5ezUAOjFgayU91ZhI0Y9r2YpB1tTGIjnO23wot8PvRENlThHQ%3D%3D&ref=https%3A%2F%2Fbox.adrino.cloud%2Ftmielcarz%2Fadrino_prebid%2Ftest_page3.html%3Fpbjs_debug%3Dtrue', - privacyLink: 'https://adrino.pl/wp-content/uploads/2021/01/POLITYKA-PRYWATNOS%CC%81CI-Adrino-Mobile.pdf', - impressionTrackers: [ - 'https://prd-impression-tracker-producer.adrino.io/impression/eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ7XCJpbXByZXNzaW9uSWRcIjpcIjMxNjYyYzY5NzI4ODExXCIsXCJkYXRlXCI6WzIwMjIsMiwzXSxcInBsYWNlbWVudEhhc2hcIjpcIjk0NTVjMDQxYzlkMTI1ZmIwNDE4MWVhMGVlZTJmMmFlXCIsXCJjYW1wYWlnbklkXCI6MTc5MjUsXCJhZHZlcnRpc2VtZW50SWRcIjo5MjA3OSxcInZpc3VhbGlzYXRpb25JZFwiOjg1OTExNSxcImNwbVwiOjUzLjB9IiwiZXhwIjoxNjQzOTE2MjUxLCJpYXQiOjE2NDM5MTU2NTF9.0Y_HvInGl6Xo5xP6rDLC8lzQRGvy-wKe0blk1o8ebWyVRFiUY1JGLUeE0k3sCsPNxgdHAv-o6EcbogpUuqlMJA' - ] - } - }; - - const serverResponse = { - body: { bidResponses: [response1, response2] } - }; - - const result = spec.interpretResponse(serverResponse, {}); - expect(result.length).to.equal(2); - expect(result[0]).to.equal(response1); - expect(result[0].requestId).to.equal('31662c69728811'); - expect(result[1]).to.equal(response2); - expect(result[1].requestId).to.equal('31662c69728812'); - }); - - it('should return empty array of responses', function () { - const response = { - requestId: '31662c69728811', - noAd: true, - testAd: false - }; - - const serverResponse = { - body: response - }; - - const result = spec.interpretResponse(serverResponse, {}); - expect(result.length).to.equal(0); - }); - }); - - describe('onBidWon', function () { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - - it('should trigger pixel', function () { - const response = { - requestId: '31662c69728811', - mediaType: 'native', - cpm: 0.53, - currency: 'PLN', - creativeId: '859115', - netRevenue: true, - ttl: 600, - width: 1, - height: 1, - noAd: false, - testAd: false, - native: { - title: 'Ad Title', - body: 'Ad Body', - image: { - url: 'http://emisja.contentstream.pl/_/getImageII/?vid=17180728299&typ=cs_300_150&element=IMAGE&scale=1&prefix=adart&nc=1643878278955', - height: 150, - width: 300 - }, - clickUrl: 'http://emisja.contentstream.pl/_/ctr2/?u=https%3A%2F%2Fonline.efortuna.pl%2Fpage%3Fkey%3Dej0xMzUzMTM1NiZsPTE1Mjc1MzY1JnA9NTMyOTA%253D&e=znU3tABN8K4N391dmUxYfte5G9tBaDXELJVo1_-kvaTJH2XwWRw77fmfL2YjcEmrbqRQ3M0GcJ0vPWcLtZlsrf8dWrAEHNoZKAC6JMnZF_65IYhTPbQIJ-zn3ac9TU7gEZftFKksH1al7rMuieleVv9r6_DtrOk_oZcYAe4rMRQM-TiWvivJRPBchAAblE0cqyG7rCunJFpal43sxlYm4GvcBJaYHzErn5PXjEzNbd3xHjkdiap-xU9y6BbfkUZ1xIMS8QZLvwNrTXMFCSfSRN2tgVfEj7KyGdLCITHSaFtuIKT2iW2pxC7f2RtPHnzsEPXH0SgAfhA3OxZ5jkQjOZy0PsO7MiCv3sJai5ezUAOjFgayU91ZhI0Y9r2YpB1tTGIjnO23wot8PvRENlThHQ%3D%3D&ref=https%3A%2F%2Fbox.adrino.cloud%2Ftmielcarz%2Fadrino_prebid%2Ftest_page3.html%3Fpbjs_debug%3Dtrue', - privacyLink: 'https://adrino.pl/wp-content/uploads/2021/01/POLITYKA-PRYWATNOS%CC%81CI-Adrino-Mobile.pdf', - impressionTrackers: [ - 'https://prd-impression-tracker-producer.adrino.io/impression/eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJ7XCJpbXByZXNzaW9uSWRcIjpcIjMxNjYyYzY5NzI4ODExXCIsXCJkYXRlXCI6WzIwMjIsMiwzXSxcInBsYWNlbWVudEhhc2hcIjpcIjk0NTVjMDQxYzlkMTI1ZmIwNDE4MWVhMGVlZTJmMmFlXCIsXCJjYW1wYWlnbklkXCI6MTc5MjUsXCJhZHZlcnRpc2VtZW50SWRcIjo5MjA3OSxcInZpc3VhbGlzYXRpb25JZFwiOjg1OTExNSxcImNwbVwiOjUzLjB9IiwiZXhwIjoxNjQzOTE2MjUxLCJpYXQiOjE2NDM5MTU2NTF9.0Y_HvInGl6Xo5xP6rDLC8lzQRGvy-wKe0blk1o8ebWyVRFiUY1JGLUeE0k3sCsPNxgdHAv-o6EcbogpUuqlMJA' - ] - } - }; - - spec.onBidWon(response); - expect(utils.triggerPixel.callCount).to.equal(1) - }); - }); -}); diff --git a/test/spec/modules/adriverBidAdapter_spec.js b/test/spec/modules/adriverBidAdapter_spec.js deleted file mode 100644 index 75c786c07..000000000 --- a/test/spec/modules/adriverBidAdapter_spec.js +++ /dev/null @@ -1,605 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adriverBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import * as bidderFactory from 'src/adapters/bidderFactory.js'; -import { auctionManager } from 'src/auctionManager.js'; - -const ENDPOINT = 'https://pb.adriver.ru/cgi-bin/bid.cgi'; - -describe('adriverAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - bidder: 'adriver', - params: { - placementId: '55:test_placement', - siteid: 'testSiteID' - }, - adUnitCode: 'adunit-code', - sizes: [[300, 250], [300, 600], [300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userIdAsEids: [ - { - source: 'id5-sync.com', - uids: [ - { - id: '', - atype: 1, - ext: { - linkType: 0, - abTestingControlGroup: true - } - } - ] - }, - { - source: 'sharedid.org', - uids: [ - { - id: '01F4W41TMN7NBXBA0PXJMPB7GF', - atype: 1, - ext: { - third: '01F4W41TMN7NBXBA0PXJMPB7GF' - } - } - ] - } - ] - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - - describe('buildRequests', function () { - let getAdUnitsStub; - const floor = 3; - - const bidRequests = [ - { - bidder: 'adriver', - params: { - placementId: '55:test_placement', - siteid: 'testSiteID', - dealid: 'dealidTest' - }, - adUnitCode: 'adunit-code', - sizes: [[300, 250], [300, 600], [300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '04f2659e-c005-4eb1-a57c-fa93145e3843', - userId: { - adrcid: 'testCookieValue', - }, - userIdAsEids: [ - { - source: 'id5-sync.com', - uids: [ - { - id: '', - atype: 1, - ext: { - linkType: 0, - abTestingControlGroup: true - } - } - ] - }, - { - source: 'sharedid.org', - uids: [ - { - id: '01F4W41TMN7NBXBA0PXJMPB7GF', - atype: 1, - ext: { - third: '01F4W41TMN7NBXBA0PXJMPB7GF' - } - } - ] - } - ] - } - ]; - - const bidderRequest = { - 'bidderCode': 'adriver', - 'auctionId': '2cdbf766-c37e-464c-a924-d8cf2a2f7ed2', - 'bidderRequestId': '10415226a1f2ac', - 'bids': [ - { - 'bidder': 'adriver', - 'params': { - 'siteid': '216200', - 'bidfloor': 1.33, - 'placementId': 'test1' - }, - 'auctionId': '2cdbf766-c37e-464c-a924-d8cf2a2f7ed2', - 'floorData': { - 'skipped': false, - 'skipRate': 5, - 'modelVersion': 'BlackBerryZap', - 'location': 'setConfig' - }, - 'userId': { - 'id5id': { - 'uid': 'ID5-ZHMO7vyrzH4ggO1TVF8lZ31h77BjNP6pLgMwIrhvtw!ID5*wP-eG3RLeJjkl1O5yeOMcf3Ksrsq1OeqM5nQZLgPvOMAACaMv9QnPWzdhdbFYu3r', - 'ext': { - 'linkType': 2, - 'abTestingControlGroup': false - } - }, - 'sharedid': { - 'id': '01F4W41TMN7NBXBA0PXJMPB7GF', - 'third': '01F4W41TMN7NBXBA0PXJMPB7GF' - } - }, - 'userIdAsEids': [ - { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': 'ID5-ZHMO7vyrzH4ggO1TVF8lZ31h77BjNP6pLgMwIrhvtw!ID5*wP-eG3RLeJjkl1O5yeOMcf3Ksrsq1OeqM5nQZLgPvOMAACaMv9QnPWzdhdbFYu3r', - 'atype': 1, - 'ext': { - 'linkType': 2, - 'abTestingControlGroup': false - } - } - ] - }, - { - 'source': 'sharedid.org', - 'uids': [ - { - 'id': '01F4W41TMN7NBXBA0PXJMPB7GF', - 'atype': 1, - 'ext': { - 'third': '01F4W41TMN7NBXBA0PXJMPB7GF' - } - } - ] - } - ], - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 600, - 500 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-51545-0', - 'transactionId': '01dfccdf-70d0-461f-b284-9132877ebe02', - 'sizes': [ - [ - 300, - 250 - ], - [ - 600, - 500 - ] - ], - 'bidId': '2794d8415635b3', - 'bidderRequestId': '10415226a1f2ac', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'auctionStart': 1622465003758, - 'timeout': 1000, - 'refererInfo': { - 'referer': 'http://localhost:9999/integrationExamples/gpt/adUnitFloors.html', - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': [ - 'http://localhost:9999/integrationExamples/gpt/adUnitFloors.html' - ], - 'canonicalUrl': null - }, - 'start': 1622465003762 - }; - - const floorTestData = { - 'currency': 'USD', - 'floor': floor - }; - - bidRequests[0].getFloor = _ => { - return floorTestData; - }; - - beforeEach(function() { - getAdUnitsStub = sinon.stub(auctionManager, 'getAdUnits').callsFake(function() { - return []; - }); - }); - - afterEach(function() { - getAdUnitsStub.restore(); - }); - - it('should exist currency', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - - expect(payload.cur).to.exist; - }); - - it('should exist timeout', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.tmax).to.exist; - expect(payload.tmax).to.equal(1000); - }); - - it('should exist at', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - - expect(payload.at).to.exist; - expect(payload.at).to.deep.equal(1); - }); - - it('should parse imp', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - - expect(payload.imp[0]).to.exist; - expect(payload.imp[0].id).to.deep.equal('55:test_placement'); - - expect(payload.imp[0].ext).to.exist; - expect(payload.imp[0].ext.query).to.deep.equal('bn=15&custom=111=' + '30b31c1838de1e'); - - expect(payload.imp[0].banner).to.exist; - expect(payload.imp[0].banner.w).to.deep.equal(300); - expect(payload.imp[0].banner.h).to.deep.equal(250); - }); - - it('should parse pmp', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - - expect(payload.imp[0].pmp).to.exist; - - expect(payload.imp[0].pmp.deals).to.exist; - - expect(payload.imp[0].pmp.deals[0].bidfloor).to.exist; - expect(payload.imp[0].pmp.deals[0].bidfloor).to.deep.equal(3); - - expect(payload.imp[0].pmp.deals[0].bidfloorcur).to.exist; - expect(payload.imp[0].pmp.deals[0].bidfloorcur).to.deep.equal('RUB'); - }); - - const cookieValues = [ - { adrcid: 'adrcidValue' }, - { adrcid: undefined } - ] - cookieValues.forEach(cookieValue => describe('test cookie exist or not behavior', function () { - const expectedValues = [ - 'buyerid', - 'ext' - ] - - it('check adrcid if it exists', function () { - bidRequests[0].userId.adrcid = cookieValue.adrcid; - const payload = JSON.parse(spec.buildRequests(bidRequests).data); - if (cookieValue.adrcid) { - expect(Object.keys(payload.user)).to.have.members(expectedValues); - } else { - expect(payload.user.buyerid).to.equal(0); - } - }); - })); - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - }); - - describe('interpretResponse', function () { - const response = { - 'id': '221594457-1615288400-1-46-', - 'bidid': 'D8JW8XU8-L5m7qFMNQGs7i1gcuPvYMEDOKsktw6e9uLy5Eebo9HftVXb0VpKj4R2dXa93i6QmRhjextJVM4y1SqodMAh5vFOb_eVkHA', - 'seatbid': [{ - 'bid': [{ - 'id': '1', - 'impid': '/19968336/header-bid-tag-0', - 'price': 4.29, - 'h': 250, - 'w': 300, - 'adid': '7121351', - 'adomain': ['http://ikea.com'], - 'nurl': 'https://ad.adriver.ru/cgi-bin/erle.cgi?expid=D8JW8XU8-L5m7qFMNQGs7i1gcuPvYMEDOKsktw6e9uLy5Eebo9HftVXb0VpKj4R2dXa93i6QmRhjextJVM4y1SqodMAh5vFOb_eVkHA&bid=7121351&wprc=4.29&tuid=-1&custom=207=/19968336/header-bid-tag-0', - 'cid': '717570', - 'ext': '2c262a7058758d' - }] - }, { - 'bid': [{ - 'id': '1', - 'impid': '/19968336/header-bid-tag-0', - 'price': 17.67, - 'h': 600, - 'w': 300, - 'adid': '7121369', - 'adomain': ['http://ikea.com'], - 'nurl': 'https://ad.adriver.ru/cgi-bin/erle.cgi?expid=DdtToXX5cpTaMMxrJSEsOsUIXt3WmC3jOvuNI5DguDrY8edFG60Jg1M-iMkVNKQ4OiAdHSLPJLQQXMUXZfI9VbjMoGCb-zzOTPiMpshI&bid=7121369&wprc=17.67&tuid=-1&custom=207=/19968336/header-bid-tag-0', - 'cid': '717570', - 'ext': '2c262a7058758d' - }] - }], - 'cur': 'RUB' - }; - - it('should get correct bid response', function () { - const expectedResponse = [ - { - requestId: '2c262a7058758d', - cpm: 4.29, - width: 300, - height: 250, - creativeId: '/19968336/header-bid-tag-0', - currency: 'RUB', - netRevenue: true, - ttl: 3000, - meta: { - advertiserDomains: ['http://ikea.com'] - }, - ad: '' - } - ]; - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - }; - const result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - - it('handles nobid responses', function () { - const response = { - 'version': '0.0.1', - 'tags': [{ - 'uuid': '84ab500420319d', - 'tag_id': 5976557, - 'auction_id': '297492697822162468', - 'nobid': true - }] - }; - let bidderRequest; - - const result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(result.length).to.equal(0); - }); - }); - - describe('function _getFloor', function () { - const bidRequests = [ - { - bidder: 'adriver', - params: { - placementId: '55:test_placement', - siteid: 'testSiteID', - dealid: 'dealidTest', - }, - adUnitCode: 'adunit-code', - sizes: [[300, 250], [300, 600], [300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '04f2659e-c005-4eb1-a57c-fa93145e3843', - userId: { - adrcid: 'testCookieValue', - }, - userIdAsEids: [ - { - source: 'id5-sync.com', - uids: [ - { - id: '', - atype: 1, - ext: { - linkType: 0, - abTestingControlGroup: true - } - } - ] - }, - { - source: 'sharedid.org', - uids: [ - { - id: '01F4W41TMN7NBXBA0PXJMPB7GF', - atype: 1, - ext: { - third: '01F4W41TMN7NBXBA0PXJMPB7GF' - } - } - ] - } - ] - } - ]; - - const floorTestData = { - 'currency': 'RUB', - 'floor': 1.50 - }; - - const bitRequestStandard = JSON.parse(JSON.stringify(bidRequests)); - - bitRequestStandard[0].getFloor = () => { - return floorTestData; - }; - - it('valid BidRequests', function () { - const request = spec.buildRequests(bitRequestStandard); - const payload = JSON.parse(request.data); - - expect(typeof bitRequestStandard[0].getFloor).to.equal('function'); - expect(payload.imp[0].bidfloor).to.equal(1.50); - expect(payload.imp[0].bidfloorcur).to.equal('RUB'); - }); - - const bitRequestEmptyCurrency = JSON.parse(JSON.stringify(bidRequests)); - - const floorTestDataEmptyCurrency = { - 'currency': 'RUB', - 'floor': 1.50 - }; - - bitRequestEmptyCurrency[0].getFloor = () => { - return floorTestDataEmptyCurrency; - }; - - it('empty currency', function () { - const request = spec.buildRequests(bitRequestEmptyCurrency); - const payload = JSON.parse(request.data); - - expect(payload.imp[0].bidfloor).to.equal(1.50); - expect(payload.imp[0].bidfloorcur).to.equal('RUB'); - }); - - const bitRequestFloorNull = JSON.parse(JSON.stringify(bidRequests)); - - const floorTestDataFloorNull = { - 'currency': '', - 'floor': null - }; - - bitRequestFloorNull[0].getFloor = () => { - return floorTestDataFloorNull; - }; - - it('empty floor', function () { - const request = spec.buildRequests(bitRequestFloorNull); - const payload = JSON.parse(request.data); - - expect(payload.imp[0].bidfloor).to.equal(0); - }); - - const bitRequestGetFloorNotFunction = JSON.parse(JSON.stringify(bidRequests)); - - bitRequestGetFloorNotFunction[0].getFloor = 0; - - it('bid.getFloor is not a function', function () { - const request = spec.buildRequests(bitRequestGetFloorNotFunction); - const payload = JSON.parse(request.data); - - expect(payload.imp[0].bidfloor).to.equal(0); - expect(payload.imp[0].bidfloorcur).to.equal('RUB'); - }); - - const bitRequestGetFloorBySized = JSON.parse(JSON.stringify(bidRequests)); - - bitRequestGetFloorBySized[0].getFloor = (requestParams = {currency: 'USD', mediaType: '*', size: '*'}) => { - if (requestParams.size.length === 2 && requestParams.size[0] === 300 && requestParams.size[1] === 250) { - return { - 'currency': 'RUB', - 'floor': 3.33 - } - } else { - return {} - } - }; - - it('bid.getFloor get size', function () { - const request = spec.buildRequests(bitRequestGetFloorBySized); - const payload = JSON.parse(request.data); - - expect(payload.imp[0].bidfloor).to.equal(3.33); - expect(payload.imp[0].bidfloorcur).to.equal('RUB'); - expect(payload.imp[0].bidfloorcur).to.equal('RUB'); - }); - }); - - describe('user ids', function () { - const bidRequests = [ - { - bidder: 'adriver', - params: { - placementId: '55:test_placement', - siteid: 'testSiteID', - dealid: 'dealidTest', - }, - adUnitCode: 'adunit-code', - sizes: [[300, 250], [300, 600], [300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '04f2659e-c005-4eb1-a57c-fa93145e3843', - userId: { - adrcid: 'testCookieValue', - }, - userIdAsEids: [ - { - source: 'id5-sync.com', - uids: [ - { - id: '', - atype: 1, - ext: { - linkType: 0, - abTestingControlGroup: true - } - } - ] - }, - { - source: 'sharedid.org', - uids: [ - { - id: '01F4W41TMN7NBXBA0PXJMPB7GF', - atype: 1, - ext: { - third: '01F4W41TMN7NBXBA0PXJMPB7GF' - } - } - ] - } - ] - } - ]; - - it('user id id5-sync.com', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - - expect(payload.user.ext.eids[0].source).to.equal('id5-sync.com'); - expect(payload.user.ext.eids[0].uids[0].id).to.equal(''); - }); - - it('user id sharedid.org', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - - expect(payload.user.ext.eids[1].source).to.equal('sharedid.org'); - expect(payload.user.ext.eids[1].uids[0].id).to.equal('01F4W41TMN7NBXBA0PXJMPB7GF'); - }); - }); -}); diff --git a/test/spec/modules/ads_interactiveBidAdapter_spec.js b/test/spec/modules/ads_interactiveBidAdapter_spec.js deleted file mode 100644 index c16f5a5a7..000000000 --- a/test/spec/modules/ads_interactiveBidAdapter_spec.js +++ /dev/null @@ -1,517 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/ads_interactiveBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'ads_interactive'; - -describe('AdsInteractiveBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://bntb.adsinteractive.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.include.all.keys( - 'deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cstb.adsinteractive.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cstb.adsinteractive.com/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cstb.adsinteractive.com/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/adspiritBidAdapter_spec.js b/test/spec/modules/adspiritBidAdapter_spec.js deleted file mode 100644 index 004179f51..000000000 --- a/test/spec/modules/adspiritBidAdapter_spec.js +++ /dev/null @@ -1,493 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adspiritBidAdapter.js'; -import * as utils from 'src/utils.js'; -import { registerBidder } from 'src/adapters/bidderFactory.js'; -import { BANNER, NATIVE } from 'src/mediaTypes.js'; -const { getWinDimensions } = utils; -const RTB_URL = '/rtb/getbid.php?rtbprovider=prebid'; -const SCRIPT_URL = '/adasync.min.js'; - -describe('Adspirit Bidder Spec', function () { - // isBidRequestValid ---case - describe('isBidRequestValid', function () { - it('should return true if the bid request is valid', function () { - const validBid = { bidder: 'adspirit', params: { placementId: '99', host: 'test.adspirit.de' } }; - const result = spec.isBidRequestValid(validBid); - expect(result).to.be.true; - }); - - it('should return false if the bid request is invalid', function () { - const invalidBid = { bidder: 'adspirit', params: {} }; - const result = spec.isBidRequestValid(invalidBid); - expect(result).to.be.false; - }); - }); - - // getBidderHost Case - describe('getBidderHost', function () { - it('should return host for adspirit bidder', function () { - const bid = { bidder: 'adspirit', params: { host: 'test.adspirit.de' } }; - const result = spec.getBidderHost(bid); - expect(result).to.equal('test.adspirit.de'); - }); - - it('should return host for twiago bidder', function () { - const bid = { bidder: 'twiago' }; - const result = spec.getBidderHost(bid); - expect(result).to.equal('a.twiago.com'); - }); - it('should return null for unsupported bidder', function () { - const bid = { bidder: 'unsupportedBidder', params: {} }; - const result = spec.getBidderHost(bid); - expect(result).to.be.null; - }); - }); - // getScriptUrl - - describe('Adspirit Bid Adapter', function () { - describe('getScriptUrl', function () { - it('should return the correct script URL', function () { - expect(spec.getScriptUrl()).to.equal('/adasync.min.js'); - }); - }); - }); - // Test cases for buildRequests - describe('Adspirit Bidder Spec', function () { - let originalInnerWidth; - let originalInnerHeight; - let originalClientWidth; - let originalClientHeight; - - beforeEach(() => { - originalInnerWidth = window.innerWidth; - originalInnerHeight = window.innerHeight; - originalClientWidth = document.documentElement.clientWidth; - originalClientHeight = document.documentElement.clientHeight; - - Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 1024 }); - Object.defineProperty(window, 'innerHeight', { writable: true, configurable: true, value: 768 }); - Object.defineProperty(document.documentElement, 'clientWidth', { writable: true, configurable: true, value: 800 }); - Object.defineProperty(document.documentElement, 'clientHeight', { writable: true, configurable: true, value: 600 }); - }); - - afterEach(() => { - Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: originalInnerWidth }); - Object.defineProperty(window, 'innerHeight', { writable: true, configurable: true, value: originalInnerHeight }); - Object.defineProperty(document.documentElement, 'clientWidth', { writable: true, configurable: true, value: originalClientWidth }); - Object.defineProperty(document.documentElement, 'clientHeight', { writable: true, configurable: true, value: originalClientHeight }); - }); - - it('should correctly capture window and document dimensions in payload', function () { - const bidRequest = [ - { - bidId: '26c1ee0038ac11', - bidder: 'adspirit', - params: { placementId: '99', host: 'test.adspirit.de' }, - adUnitCode: 'banner-div', - mediaTypes: { - banner: { sizes: [[300, 250]] } - } - } - ]; - const mockBidderRequest = { refererInfo: { topmostLocation: 'https://test.adspirit.com' } }; - const requests = spec.buildRequests(bidRequest, mockBidderRequest); - const request = requests[0]; - const requestData = JSON.parse(request.data); - }); - - it('should correctly fall back to document dimensions if window dimensions are not available', function () { - const bidRequest = [ - { - bidId: '26c1ee0038ac11', - bidder: 'adspirit', - params: { placementId: '99', host: 'test.adspirit.de' }, - adUnitCode: 'banner-div', - mediaTypes: { - banner: { sizes: [[300, 250]] } - } - } - ]; - const mockBidderRequest = { refererInfo: { topmostLocation: 'https://test.adspirit.com' } }; - delete global.window.innerWidth; - delete global.window.innerHeight; - const requests = spec.buildRequests(bidRequest, mockBidderRequest); - const request = requests[0]; - const requestData = JSON.parse(request.data); - }); - it('should correctly add GDPR consent parameters to the request', function () { - const bidRequest = [ - { - bidId: '26c1ee0038ac11', - bidder: 'adspirit', - params: { placementId: '99', host: 'test.adspirit.de' }, - adUnitCode: 'banner-div', - mediaTypes: { - banner: { sizes: [[300, 250]] } - } - } - ]; - - const mockBidderRequest = { - refererInfo: { topmostLocation: 'https://test.adspirit.com' }, - gdprConsent: { - gdprApplies: true, - consentString: 'BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA' - } - }; - - const requests = spec.buildRequests(bidRequest, mockBidderRequest); - const request = requests[0]; - expect(request.url).to.include('&gdpr=1'); - expect(request.url).to.include('&gdpr_consent=BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA'); - const requestData = JSON.parse(request.data); - expect(requestData.regs.ext.gdpr).to.equal(1); - expect(requestData.regs.ext.gdpr_consent).to.equal(mockBidderRequest.gdprConsent.consentString); - }); - - it('should correctly include schain in the OpenRTB request if provided', function () { - const bidRequest = [ - { - bidId: '26c1ee0038ac11', - bidder: 'adspirit', - params: { placementId: '99', host: 'test.adspirit.de' }, - adUnitCode: 'banner-div', - mediaTypes: { - banner: { sizes: [[300, 250]] } - }, - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'publisher.com', - sid: '1234', - hp: 1 - } - ] - } - } - } - } - } - ]; - - const mockBidderRequest = { refererInfo: { topmostLocation: 'https://test.adspirit.com' } }; - const requests = spec.buildRequests(bidRequest, mockBidderRequest); - const request = requests[0]; - const requestData = JSON.parse(request.data); - expect(requestData.source).to.exist; - expect(requestData.source.ext).to.exist; - expect(requestData.source.ext.schain).to.deep.equal(bidRequest[0].ortb2.source.ext.schain); - }); - it('should correctly handle bidfloor values (valid, missing, and non-numeric)', function () { - const bidRequest = [ - { - bidId: 'validBidfloor', - bidder: 'adspirit', - params: { placementId: '99', host: 'test.adspirit.de', bidfloor: '1.23' }, - adUnitCode: 'banner-div', - mediaTypes: { - banner: { sizes: [[300, 250]] } - } - }, - { - bidId: 'missingBidfloor', - bidder: 'adspirit', - params: { placementId: '100', host: 'test.adspirit.de' }, - adUnitCode: 'banner-div', - mediaTypes: { - banner: { sizes: [[300, 250]] } - } - }, - { - bidId: 'invalidBidfloor', - bidder: 'adspirit', - params: { placementId: '101', host: 'test.adspirit.de', bidfloor: 'abc' }, - adUnitCode: 'banner-div', - mediaTypes: { - banner: { sizes: [[300, 250]] } - } - } - ]; - - const mockBidderRequest = { refererInfo: { topmostLocation: 'https://test.adspirit.com' } }; - const requests = spec.buildRequests(bidRequest, mockBidderRequest); - const requestData = requests.map(req => JSON.parse(req.data)); - expect(requestData[0].imp[0].bidfloor).to.equal(1.23); - expect(requestData[1].imp[0].bidfloor).to.equal(0); - expect(requestData[2].imp[0].bidfloor || 0).to.equal(0); - }); - it('should correctly add and handle banner/native media types', function () { - const bidRequest = [ - { - bidId: 'validBannerNative', - bidder: 'adspirit', - params: { placementId: '99', host: 'test.adspirit.de' }, - adUnitCode: 'test-div', - mediaTypes: { - banner: { sizes: [[300, 250]] }, - native: { - ortb: { - request: { - assets: [{ id: 1, required: 1, title: { len: 100 } }] - } - } - } - } - }, - { - bidId: 'noBanner', - bidder: 'adspirit', - params: { placementId: '100', host: 'test.adspirit.de' }, - adUnitCode: 'no-banner-div', - mediaTypes: { - banner: {} - } - }, - { - bidId: 'emptyNative', - bidder: 'adspirit', - params: { placementId: '101', host: 'test.adspirit.de' }, - adUnitCode: 'empty-native-div', - mediaTypes: { - native: { - ortb: { - request: { - assets: [] - } - } - } - } - } - ]; - - const mockBidderRequest = { refererInfo: { topmostLocation: 'https://test.adspirit.com' } }; - const requests = spec.buildRequests(bidRequest, mockBidderRequest); - const requestData = requests.map(req => JSON.parse(req.data)); - - expect(requestData[0].imp[0]).to.have.property('banner'); - expect(requestData[0].imp[0].banner.format).to.deep.equal([{ w: 300, h: 250 }]); - - expect(requestData[0].imp[0]).to.have.property('native'); - expect(JSON.parse(requestData[0].imp[0].native.request).assets).to.deep.equal([ - { id: 1, required: 1, title: { len: 100 } }, - { id: 2, required: 1, img: { type: 3, wmin: 1200, hmin: 627, mimes: ['image/png', 'image/gif', 'image/jpeg'] } }, - { id: 4, required: 1, data: { type: 2, len: 150 } }, - { id: 3, required: 0, data: { type: 12, len: 50 } }, - { id: 6, required: 0, data: { type: 1, len: 50 } }, - { id: 5, required: 0, img: { type: 1, wmin: 50, hmin: 50, mimes: ['image/png', 'image/gif', 'image/jpeg'] } } - ]); - - expect(requestData[1].imp[0]).to.not.have.property('banner'); - - expect(requestData[2].imp[0]).to.have.property('native'); - expect(JSON.parse(requestData[2].imp[0].native.request).assets).to.deep.equal([ - { id: 1, required: 1, title: { len: 100 } }, - { id: 2, required: 1, img: { type: 3, wmin: 1200, hmin: 627, mimes: ['image/png', 'image/gif', 'image/jpeg'] } }, - { id: 4, required: 1, data: { type: 2, len: 150 } }, - { id: 3, required: 0, data: { type: 12, len: 50 } }, - { id: 6, required: 0, data: { type: 1, len: 50 } }, - { id: 5, required: 0, img: { type: 1, wmin: 50, hmin: 50, mimes: ['image/png', 'image/gif', 'image/jpeg'] } } - ]); - }); - }); - - // getEids function - describe('getEids', function () { - it('should return userIdAsEids when present', function () { - const bidRequest = { - userIdAsEids: [ - { - source: 'pubcid.org', - uids: [{ id: 'test-pubcid', atype: 1 }] - } - ] - }; - const result = spec.getEids(bidRequest); - expect(result).to.deep.equal(bidRequest.userIdAsEids); - }); - - it('should return an empty array when userIdAsEids is missing', function () { - const bidRequest = {}; - const result = spec.getEids(bidRequest); - expect(result).to.deep.equal([]); - }); - }); - // interpretResponse - describe('interpretResponse', function () { - const validBidRequestMock = { - bidRequest: { - bidId: '123456', - bidder: 'adspirit', - params: { - placementId: '57', - adomain: ['test.adspirit.de'] - } - } - }; - - it('should return an empty array when serverResponse is missing', function () { - const result = spec.interpretResponse(null, validBidRequestMock); - expect(result).to.be.an('array').that.is.empty; - }); - - it('should return an empty array when serverResponse.body is missing', function () { - const result = spec.interpretResponse({}, validBidRequestMock); - expect(result).to.be.an('array').that.is.empty; - }); - - it('should correctly parse a valid banner ad response', function () { - const serverResponse = { - body: { - cpm: 2.0, - w: 728, - h: 90, - adm: '
Banner Ad Content
', - adomain: ['siva.adspirit.de'] - } - }; - - const result = spec.interpretResponse(serverResponse, validBidRequestMock); - expect(result.length).to.equal(1); - const bid = result[0]; - expect(bid).to.include({ - requestId: '123456', - cpm: 2.0, - width: 728, - height: 90, - currency: 'EUR', - netRevenue: true, - ttl: 300 - }); - - expect(bid).to.have.property('mediaType', 'banner'); - expect(bid.ad).to.include(''); - expect(bid.ad).to.include('
Banner Ad Content
'); - }); - - it('should return empty array if banner ad response has missing CPM', function () { - const serverResponse = { - body: { - w: 728, - h: 90, - adm: '
Ad Content
' - } - }; - const result = spec.interpretResponse(serverResponse, validBidRequestMock); - expect(result.length).to.equal(0); - }); - - it('should correctly handle default values for width, height, creativeId, currency, and advertiserDomains', function () { - const serverResponse = { - body: { - seatbid: [{ - bid: [{ - impid: '123456', - price: 1.8, - crid: undefined, - w: undefined, - h: undefined, - adomain: undefined - }] - }], - cur: undefined - } - }; - - const validBidRequestMock = { - bidRequest: { - bidId: '987654', - params: { placementId: '57' } - } - }; - - const result = spec.interpretResponse(serverResponse, validBidRequestMock); - expect(result.length).to.equal(1); - - const bid = result[0]; - - expect(bid.width).to.equal(1); - expect(bid.height).to.equal(1); - - expect(bid.creativeId).to.equal('123456'); - expect(bid.currency).to.equal('EUR'); - expect(bid.meta.advertiserDomains).to.deep.equal([]); - }); - - it('should correctly parse a valid native ad response, ensuring all assets are loaded dynamically with extra fields', function () { - const serverResponse = { - body: { - seatbid: [{ - bid: [{ - impid: '123456', - price: 1.5, - w: 320, - h: 50, - crid: 'creative789', - adomain: ['test.adspirit.de'], - adm: JSON.stringify({ - native: { - assets: [ - { id: 1, title: { text: 'Primary Title' } }, - { id: 4, data: { value: 'Main Description' } }, - { id: 4, data: { value: 'Extra Description' } }, - { id: 3, data: { value: 'Main CTA' } }, - { id: 3, data: { value: 'Additional CTA' } }, - { id: 2, img: { url: 'https://example.com/main-image.jpg', w: 100, h: 100 } }, - { id: 2, img: { url: 'https://example.com/extra-image.jpg', w: 200, h: 200 } }, - { id: 5, img: { url: 'https://example.com/icon-main.jpg', w: 50, h: 50 } }, - { id: 5, img: { url: 'https://example.com/icon-extra.jpg', w: 60, h: 60 } }, - { id: 6, data: { value: 'Main Sponsor' } }, - { id: 6, data: { value: 'Secondary Sponsor' } } - ], - link: { url: 'https://clickurl.com' }, - imptrackers: ['https://tracker.com/impression'] - } - }) - }] - }], - cur: 'EUR' - } - }; - - const validBidRequestMock = { - bidRequest: { - bidId: '987654', - params: { placementId: '57' } - } - }; - - const result = spec.interpretResponse(serverResponse, validBidRequestMock); - expect(result.length).to.equal(1); - - const bid = result[0]; - - expect(bid.native.title).to.equal('Primary Title'); - expect(bid.native.body).to.equal('Main Description'); - expect(bid.native['data_4_extra1']).to.equal('Extra Description'); - - expect(bid.native.cta).to.equal('Main CTA'); - expect(bid.native['data_3_extra1']).to.equal('Additional CTA'); - - expect(bid.native.sponsoredBy).to.equal('Main Sponsor'); - expect(bid.native['data_6_extra1']).to.equal('Secondary Sponsor'); - expect(bid.native.image.url).to.equal('https://example.com/main-image.jpg'); - expect(bid.native['image_2_extra1']).to.deep.equal({ - url: 'https://example.com/extra-image.jpg', - width: 200, - height: 200 - }); - - expect(bid.native.icon.url).to.equal('https://example.com/icon-main.jpg'); - expect(bid.native['image_5_extra1']).to.deep.equal({ - url: 'https://example.com/icon-extra.jpg', - width: 60, - height: 60 - }); - expect(bid.native.impressionTrackers).to.deep.equal(['https://tracker.com/impression']); - }); - }); -}); diff --git a/test/spec/modules/adstirBidAdapter_spec.js b/test/spec/modules/adstirBidAdapter_spec.js deleted file mode 100644 index d7f8efc3c..000000000 --- a/test/spec/modules/adstirBidAdapter_spec.js +++ /dev/null @@ -1,413 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/adstirBidAdapter.js'; -import * as utils from 'src/utils.js'; -import { config } from 'src/config.js'; - -describe('AdstirAdapter', function () { - describe('isBidRequestValid', function () { - it('should return true if appId is non-empty string and adSpaceNo is integer', function () { - const bid = { - params: { - appId: 'MEDIA-XXXXXX', - adSpaceNo: 6, - } - } - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should return false if appId is non-empty string, but adSpaceNo is not integer', function () { - const bid = { - params: { - appId: 'MEDIA-XXXXXX', - adSpaceNo: 'a', - } - } - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false if appId is non-empty string, but adSpaceNo is null', function () { - const bid = { - params: { - appId: 'MEDIA-XXXXXX', - adSpaceNo: null, - } - } - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false if appId is non-empty string, but adSpaceNo is undefined', function () { - const bid = { - params: { - appId: 'MEDIA-XXXXXX' - } - } - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false if adSpaceNo is integer, but appId is empty string', function () { - const bid = { - params: { - appId: '', - adSpaceNo: 6, - } - } - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false if adSpaceNo is integer, but appId is not string', function () { - const bid = { - params: { - appId: 123, - adSpaceNo: 6, - } - } - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false if adSpaceNo is integer, but appId is null', function () { - const bid = { - params: { - appId: null, - adSpaceNo: 6, - } - } - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false if adSpaceNo is integer, but appId is undefined', function () { - const bid = { - params: { - adSpaceNo: 6, - } - } - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false if params is empty', function () { - const bid = { - params: {} - } - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const validBidRequests = [ - { - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidder: 'adstir', - bidId: 'bidid1111', - params: { - appId: 'MEDIA-XXXXXX', - adSpaceNo: 1, - }, - transactionId: 'transactionid-1111', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [336, 280], - ], - } - }, - sizes: [ - [300, 250], - [336, 280], - ], - }, - { - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidder: 'adstir', - bidId: 'bidid2222', - params: { - appId: 'MEDIA-XXXXXX', - adSpaceNo: 2, - }, - transactionId: 'transactionid-2222', - mediaTypes: { - banner: { - sizes: [ - [320, 50], - [320, 100], - ], - } - }, - sizes: [ - [320, 50], - [320, 100], - ], - }, - ]; - - const bidderRequest = { - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - refererInfo: { - page: 'https://ad-stir.com/contact', - topmostLocation: 'https://ad-stir.com/contact', - reachedTop: true, - ref: 'https://test.example/q=adstir', - isAmp: false, - numIframes: 0, - stack: [ - 'https://ad-stir.com/contact', - ], - }, - }; - - it('one entry in validBidRequests corresponds to one server request object.', function () { - const requests = spec.buildRequests(validBidRequests, bidderRequest); - expect(requests.length).to.equal(validBidRequests.length); - requests.forEach(function (r, i) { - expect(r.method).to.equal('POST'); - expect(r.url).to.equal('https://ad.ad-stir.com/prebid'); - const d = JSON.parse(r.data); - expect(d.auctionId).to.equal('b06c5141-fe8f-4cdf-9d7d-54415490a917'); - - const v = validBidRequests[i]; - expect(d.appId).to.equal(v.params.appId); - expect(d.adSpaceNo).to.equal(v.params.adSpaceNo); - expect(d.bidId).to.equal(v.bidId); - expect(d.transactionId).to.equal(v.transactionId); - expect(d.mediaTypes).to.deep.equal(v.mediaTypes); - expect(d.sizes).to.deep.equal(v.sizes); - expect(d.ref.page).to.equal(bidderRequest.refererInfo.page); - expect(d.ref.tloc).to.equal(bidderRequest.refererInfo.topmostLocation); - expect(d.ref.referrer).to.equal(bidderRequest.refererInfo.ref); - expect(d.sua).to.equal(null); - expect(d.user).to.equal(null); - expect(d.gdpr).to.equal(false); - expect(d.usp).to.equal(false); - expect(d.schain).to.equal(null); - expect(d.eids).to.deep.equal([]); - }); - }); - - it('ref.page, ref.tloc and ref.referrer correspond to refererInfo', function () { - const [ request ] = spec.buildRequests([validBidRequests[0]], { - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - refererInfo: { - page: null, - topmostLocation: 'https://adserver.example/iframe1.html', - reachedTop: false, - ref: null, - isAmp: false, - numIframes: 2, - stack: [ - null, - 'https://adserver.example/iframe1.html', - 'https://adserver.example/iframe2.html' - ], - }, - }); - - const { ref } = JSON.parse(request.data); - expect(ref.page).to.equal(null); - expect(ref.tloc).to.equal('https://adserver.example/iframe1.html'); - expect(ref.referrer).to.equal(null); - }); - - it('when config.pageUrl is not set, ref.topurl equals to refererInfo.reachedTop', function () { - const bidderRequestClone = utils.deepClone(bidderRequest); - [true, false].forEach(function (reachedTop) { - bidderRequestClone.refererInfo.reachedTop = reachedTop; - const requests = spec.buildRequests(validBidRequests, bidderRequestClone); - const d = JSON.parse(requests[0].data); - expect(d.ref.topurl).to.equal(reachedTop); - }); - }); - - describe('when config.pageUrl is set, ref.topurl is always false', function () { - before(function () { - config.setConfig({ pageUrl: 'https://ad-stir.com/register' }); - }); - after(function () { - config.resetConfig(); - }); - - it('ref.topurl should be false', function () { - const bidderRequestClone = utils.deepClone(bidderRequest); - [true, false].forEach(function (reachedTop) { - bidderRequestClone.refererInfo.reachedTop = reachedTop; - const requests = spec.buildRequests(validBidRequests, bidderRequestClone); - const d = JSON.parse(requests[0].data); - expect(d.ref.topurl).to.equal(false); - }); - }); - }); - - it('gdprConsent.gdprApplies is sent', function () { - const bidderRequestClone = utils.deepClone(bidderRequest); - [true, false].forEach(function (gdprApplies) { - bidderRequestClone.gdprConsent = { gdprApplies }; - const requests = spec.buildRequests(validBidRequests, bidderRequestClone); - const d = JSON.parse(requests[0].data); - expect(d.gdpr).to.equal(gdprApplies); - }); - }); - - it('includes in the request parameters whether CCPA applies', function () { - const bidderRequestClone = utils.deepClone(bidderRequest); - const cases = [ - { uspConsent: '1---', expected: false }, - { uspConsent: '1YYY', expected: true }, - { uspConsent: '1YNN', expected: true }, - { uspConsent: '1NYN', expected: true }, - { uspConsent: '1-Y-', expected: true }, - ]; - cases.forEach(function ({ uspConsent, expected }) { - bidderRequestClone.uspConsent = uspConsent; - const requests = spec.buildRequests(validBidRequests, bidderRequestClone); - const d = JSON.parse(requests[0].data); - expect(d.usp).to.equal(expected); - }); - }); - - it('should add schain if available', function() { - const schain = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'exchange1.example', - 'sid': '1234!abcd', - 'hp': 1, - 'rid': 'bid-request-1', - 'name': 'publisher, Inc.', - 'domain': 'publisher.example' - }, - { - 'asi': 'exchange2.example', - 'sid': 'abcd', - 'hp': 1, - 'rid': 'bid-request-2', - 'name': 'intermediary', - 'domain': 'intermediary.example' - } - ] - }; - const serializedSchain = '1.0,1!exchange1.example,1234%21abcd,1,bid-request-1,publisher%2C%20Inc.,publisher.example!exchange2.example,abcd,1,bid-request-2,intermediary,intermediary.example'; - - const [ request ] = spec.buildRequests([utils.mergeDeep(utils.deepClone(validBidRequests[0]), { ortb2: { source: { ext: { schain } } } })], bidderRequest); - const d = JSON.parse(request.data); - expect(d.schain).to.deep.equal(serializedSchain); - }); - - it('should add schain even if some nodes params are blank', function() { - const schain = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'exchange1.example', - 'sid': '1234!abcd', - 'hp': 1, - }, - { - }, - { - 'asi': 'exchange2.example', - 'sid': 'abcd', - 'hp': 1, - }, - ] - }; - const serializedSchain = '1.0,1!exchange1.example,1234%21abcd,1,,,!,,,,,!exchange2.example,abcd,1,,,'; - - const [ request ] = spec.buildRequests([utils.mergeDeep(utils.deepClone(validBidRequests[0]), { ortb2: { source: { ext: { schain } } } })], bidderRequest); - const d = JSON.parse(request.data); - expect(d.schain).to.deep.equal(serializedSchain); - }); - - it('should add UA client hints to payload if available', function () { - const sua = { - browsers: [ - { - brand: 'Not?A_Brand', - version: [ - '8', - '0', - '0', - '0' - ] - }, - { - version: [ - '108', - '0', - '5359', - '40' - ] - }, - { - brand: 'Google Chrome', - version: [ - '108', - '0', - '5359', - '40' - ] - } - ], - platform: { - brand: 'Android', - version: [ - '11' - ] - }, - mobile: 1, - architecture: '', - bitness: '64', - model: 'Pixel 5', - source: 2 - } - - const validBidRequestsClone = utils.deepClone(validBidRequests); - validBidRequestsClone[0] = utils.mergeDeep(validBidRequestsClone[0], { - ortb2: { - device: { sua }, - } - }); - - const requests = spec.buildRequests(validBidRequestsClone, bidderRequest); - requests.forEach(function (r) { - const d = JSON.parse(r.data); - expect(d.sua).to.deep.equal(sua); - }); - }); - }); - - describe('interpretResponse', function () { - it('return empty array when no content', function () { - const bids = spec.interpretResponse({ body: '' }); - expect(bids).to.deep.equal([]); - }); - it('return empty array when seatbid empty', function () { - const bids = spec.interpretResponse({ body: { seatbid: [] } }); - expect(bids).to.deep.equal([]); - }); - it('return valid bids when serverResponse is valid', function () { - const serverResponse = { - 'body': { - 'seatbid': [ - { - 'bid': { - 'ad': '
test response
', - 'cpm': 5250, - 'creativeId': '5_1234ABCD', - 'currency': 'JPY', - 'height': 250, - 'meta': { - 'advertiserDomains': [ - 'adv.example' - ], - 'mediaType': 'banner', - 'networkId': 5 - }, - 'netRevenue': true, - 'requestId': '22a9457aed98a4', - 'transactionId': 'f18c078e-4d2a-4ecb-a886-2a0c52187213', - 'ttl': 60, - 'width': 300, - } - } - ] - }, - 'headers': {} - }; - const bids = spec.interpretResponse(serverResponse); - expect(bids[0]).to.deep.equal(serverResponse.body.seatbid[0].bid); - }); - }); -}); diff --git a/test/spec/modules/adtargetBidAdapter_spec.js b/test/spec/modules/adtargetBidAdapter_spec.js deleted file mode 100644 index ceaf51f9e..000000000 --- a/test/spec/modules/adtargetBidAdapter_spec.js +++ /dev/null @@ -1,353 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adtargetBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; - -const DISPLAY_REQUEST = { - 'bidder': 'adtarget', - 'params': { - 'aid': 12345 - }, - 'userId': { criteo: 2 }, - 'mediaTypes': { 'banner': { 'sizes': [300, 250] } }, - 'bidderRequestId': '7101db09af0db2', - 'auctionId': '2e41f65424c87c', - 'adUnitCode': 'adunit-code', - 'bidId': '84ab500420319d', -}; - -const VIDEO_REQUEST = { - 'bidder': 'adtarget', - 'mediaTypes': { - 'video': { - 'playerSize': [[480, 360], [640, 480]] - } - }, - 'params': { - 'aid': 12345 - }, - 'bidderRequestId': '7101db09af0db2', - 'auctionId': '2e41f65424c87c', - 'adUnitCode': 'adunit-code', - 'bidId': '84ab500420319d' -}; - -const SERVER_VIDEO_RESPONSE = { - 'source': { 'aid': 12345, 'pubId': 54321 }, - 'bids': [{ - 'vastUrl': 'https://rtb.adtarget.com/vast/?adid=44F2AEB9BFC881B3', - 'requestId': '2e41f65424c87c', - 'url': '44F2AEB9BFC881B3', - 'creative_id': 342516, - 'durationSeconds': 30, - 'cmpId': 342516, - 'height': 480, - 'cur': 'USD', - 'width': 640, - 'cpm': 0.9, - 'adomain': ['a.com'] - }] -}; -const SERVER_DISPLAY_RESPONSE = { - 'source': { 'aid': 12345, 'pubId': 54321 }, - 'bids': [{ - 'ad': '', - 'requestId': '2e41f65424c87c', - 'creative_id': 342516, - 'cmpId': 342516, - 'height': 250, - 'cur': 'USD', - 'width': 300, - 'cpm': 0.9 - }], - 'cookieURLs': ['link1', 'link2'] -}; -const SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS = { - 'source': { 'aid': 12345, 'pubId': 54321 }, - 'bids': [{ - 'ad': '', - 'requestId': '2e41f65424c87c', - 'creative_id': 342516, - 'cmpId': 342516, - 'height': 250, - 'cur': 'USD', - 'width': 300, - 'cpm': 0.9 - }], - 'cookieURLs': ['link3', 'link4'], - 'cookieURLSTypes': ['image', 'iframe'] -}; -const videoBidderRequest = { - bidderCode: 'bidderCode', - bids: [{ mediaTypes: { video: {} }, bidId: '2e41f65424c87c' }] -}; - -const displayBidderRequest = { - bidderCode: 'bidderCode', - bids: [{ bidId: '2e41f65424c87c' }] -}; - -const displayBidderRequestWithConsents = { - bidderCode: 'bidderCode', - bids: [{ bidId: '2e41f65424c87c' }], - gdprConsent: { - gdprApplies: true, - consentString: 'test' - }, - uspConsent: 'iHaveIt', - ortb2: { - source: { - ext: { - schain: { - ver: '1.0' - } - } - } - } -}; - -const videoEqResponse = [{ - vastUrl: 'https://rtb.adtarget.com/vast/?adid=44F2AEB9BFC881B3', - requestId: '2e41f65424c87c', - creativeId: 342516, - mediaType: 'video', - netRevenue: true, - currency: 'USD', - height: 480, - width: 640, - ttl: 300, - cpm: 0.9, - meta: { - advertiserDomains: ['a.com'] - } -}]; - -const displayEqResponse = [{ - requestId: '2e41f65424c87c', - creativeId: 342516, - mediaType: 'banner', - netRevenue: true, - currency: 'USD', - ad: '', - height: 250, - width: 300, - ttl: 300, - cpm: 0.9, - meta: { - advertiserDomains: [] - } -}]; - -describe('adtargetBidAdapter', () => { - const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('user syncs', () => { - describe('as image', () => { - it('should be returned if pixel enabled', () => { - const syncs = spec.getUserSyncs({ pixelEnabled: true }, [{ body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS }]); - - expect(syncs.map(s => s.url)).to.deep.equal([SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS.cookieURLs[0]]); - expect(syncs.map(s => s.type)).to.deep.equal(['image']); - }) - }) - - describe('as iframe', () => { - it('should be returned if iframe enabled', () => { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [{ body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS }]); - - expect(syncs.map(s => s.url)).to.deep.equal([SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS.cookieURLs[1]]); - expect(syncs.map(s => s.type)).to.deep.equal(['iframe']); - }) - }) - - describe('user sync', () => { - it('should not be returned if passed syncs where already used', () => { - const syncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, [{ body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS }]); - - expect(syncs).to.deep.equal([]); - }) - - it('should not be returned if pixel not set', () => { - const syncs = spec.getUserSyncs({}, [{ body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS }]); - - expect(syncs).to.be.empty; - }); - }); - describe('user syncs with both types', () => { - it('should be returned if pixel and iframe enabled', () => { - const mockedServerResponse = Object.assign({}, SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS, { 'cookieURLs': ['link5', 'link6'] }); - const syncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, [{ body: mockedServerResponse }]); - - expect(syncs.map(s => s.url)).to.deep.equal(mockedServerResponse.cookieURLs); - expect(syncs.map(s => s.type)).to.deep.equal(mockedServerResponse.cookieURLSTypes); - }); - }); - }); - - describe('isBidRequestValid', () => { - it('should return true when required params found', () => { - expect(spec.isBidRequestValid(VIDEO_REQUEST)).to.equal(true); - }); - - it('should return false when required params are not passed', () => { - const bid = Object.assign({}, VIDEO_REQUEST); - delete bid.params; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', () => { - const videoBidRequests = [VIDEO_REQUEST]; - const displayBidRequests = [DISPLAY_REQUEST]; - const videoAndDisplayBidRequests = [DISPLAY_REQUEST, VIDEO_REQUEST]; - const displayRequest = spec.buildRequests(displayBidRequests, {}); - const videoRequest = spec.buildRequests(videoBidRequests, {}); - const videoAndDisplayRequests = spec.buildRequests(videoAndDisplayBidRequests, {}); - - it('building requests as arrays', () => { - expect(videoRequest).to.be.a('array'); - expect(displayRequest).to.be.a('array'); - expect(videoAndDisplayRequests).to.be.a('array'); - }) - - it('sending as POST', () => { - const postActionMethod = 'POST' - const comparator = br => br.method === postActionMethod; - expect(videoRequest.every(comparator)).to.be.true; - expect(displayRequest.every(comparator)).to.be.true; - expect(videoAndDisplayRequests.every(comparator)).to.be.true; - }); - - it('sends correct video bid parameters', () => { - const data = videoRequest[0].data; - - const eq = { - CallbackId: '84ab500420319d', - AdType: 'video', - Aid: 12345, - Sizes: '480x360,640x480' - }; - expect(data.BidRequests[0]).to.deep.equal(eq); - }); - - it('sends correct display bid parameters', () => { - const data = displayRequest[0].data; - - const eq = { - CallbackId: '84ab500420319d', - AdType: 'display', - Aid: 12345, - Sizes: '300x250' - }; - - expect(data.BidRequests[0]).to.deep.equal(eq); - }); - - it('sends correct video and display bid parameters', () => { - const bidRequests = videoAndDisplayRequests[0].data; - const expectedBidReqs = [{ - CallbackId: '84ab500420319d', - AdType: 'display', - Aid: 12345, - Sizes: '300x250' - }, { - CallbackId: '84ab500420319d', - AdType: 'video', - Aid: 12345, - Sizes: '480x360,640x480' - }] - - expect(bidRequests.BidRequests).to.deep.equal(expectedBidReqs); - }); - - describe('publisher environment', () => { - const sandbox = sinon.createSandbox(); - sandbox.stub(config, 'getConfig').callsFake((key) => { - const config = { - 'coppa': true - }; - return config[key]; - }); - const bidRequestWithPubSettingsData = spec.buildRequests([DISPLAY_REQUEST], displayBidderRequestWithConsents)[0].data; - sandbox.restore(); - it('sets GDPR', () => { - expect(bidRequestWithPubSettingsData.GDPR).to.be.equal(1); - expect(bidRequestWithPubSettingsData.GDPRConsent).to.be.equal(displayBidderRequestWithConsents.gdprConsent.consentString); - }); - it('sets USP', () => { - expect(bidRequestWithPubSettingsData.USP).to.be.equal(displayBidderRequestWithConsents.uspConsent); - }) - it('sets Coppa', () => { - expect(bidRequestWithPubSettingsData.Coppa).to.be.equal(1); - }) - it('sets Schain', () => { - expect(bidRequestWithPubSettingsData.Schain).to.be.deep.equal(displayBidderRequestWithConsents.ortb2.source.ext.schain); - }) - it('sets UserId\'s', () => { - expect(bidRequestWithPubSettingsData.UserIds).to.be.deep.equal(DISPLAY_REQUEST.userId); - }) - }) - }); - - describe('interpretResponse', () => { - let serverResponse; - let adapterRequest; - let eqResponse; - - afterEach(() => { - serverResponse = null; - adapterRequest = null; - eqResponse = null; - }); - - it('should get correct video bid response', () => { - serverResponse = SERVER_VIDEO_RESPONSE; - adapterRequest = videoBidderRequest; - eqResponse = videoEqResponse; - - bidServerResponseCheck(); - }); - - it('should get correct display bid response', () => { - serverResponse = SERVER_DISPLAY_RESPONSE; - adapterRequest = displayBidderRequest; - eqResponse = displayEqResponse; - - bidServerResponseCheck(); - }); - - function bidServerResponseCheck() { - const result = spec.interpretResponse({ body: serverResponse }, { adapterRequest }); - - expect(result).to.deep.equal(eqResponse); - } - - function nobidServerResponseCheck() { - const noBidServerResponse = { bids: [] }; - const noBidResult = spec.interpretResponse({ body: noBidServerResponse }, { adapterRequest }); - - expect(noBidResult.length).to.equal(0); - } - - it('handles video nobid responses', () => { - adapterRequest = videoBidderRequest; - nobidServerResponseCheck(); - }); - - it('handles display nobid responses', () => { - adapterRequest = displayBidderRequest; - nobidServerResponseCheck(); - }); - }); -}); diff --git a/test/spec/modules/adtelligentBidAdapter_spec.js b/test/spec/modules/adtelligentBidAdapter_spec.js deleted file mode 100644 index bcce942f4..000000000 --- a/test/spec/modules/adtelligentBidAdapter_spec.js +++ /dev/null @@ -1,471 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/adtelligentBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import { deepClone } from 'src/utils.js'; - -const EXPECTED_ENDPOINTS = [ - 'https://ghb.adtelligent.com/v2/auction/', - 'https://ghb1.adtelligent.com/v2/auction/', - 'https://ghb2.adtelligent.com/v2/auction/', - 'https://ghb.adtelligent.com/v2/auction/' -]; -const aliasEP = { - 'janet_publisherSuffix': 'https://ghb.bidder.jmgads.com/v2/auction/', - 'streamkey': 'https://ghb.hb.streamkey.net/v2/auction/', - 'janet': 'https://ghb.bidder.jmgads.com/v2/auction/', - 'ocm': 'https://ghb.cenarius.orangeclickmedia.com/v2/auction/', - '9dotsmedia': 'https://ghb.platform.audiodots.com/v2/auction/', - 'indicue': 'https://ghb.console.indicue.com/v2/auction/', - 'stellormedia': 'https://ghb.ads.stellormedia.com/v2/auction/', -}; - -const DEFAULT_ADATPER_REQ = { bidderCode: 'adtelligent', ortb2: { source: { ext: { schain: { ver: 1 } } } } }; -const DISPLAY_REQUEST = { - 'bidder': 'adtelligent', - 'params': { - 'aid': 12345 - }, - 'userId': { criteo: 2 }, - 'mediaTypes': { 'banner': { 'sizes': [300, 250] } }, - 'bidderRequestId': '7101db09af0db2', - 'auctionId': '2e41f65424c87c', - 'adUnitCode': 'adunit-code', - 'bidId': '84ab500420319d', - 'ortb2Imp': { 'ext': { 'gpid': '12345/adunit-code' } }, -}; - -const VIDEO_REQUEST = { - 'bidder': 'adtelligent', - 'mediaTypes': { - 'video': { - 'playerSize': [[480, 360], [640, 480]] - } - }, - 'params': { - 'aid': 12345 - }, - 'bidderRequestId': '7101db09af0db2', - 'auctionId': '2e41f65424c87c', - 'adUnitCode': 'adunit-code', - 'bidId': '84ab500420319d', - 'ortb2Imp': { 'ext': { 'gpid': '12345/adunit-code' } }, -}; - -const ADPOD_REQUEST = { - 'bidder': 'adtelligent', - 'mediaTypes': { - 'video': { - 'context': 'adpod', - 'playerSize': [[640, 480]], - 'anyField': 10 - } - }, - 'params': { - 'aid': 12345 - }, - 'bidderRequestId': '7101db09af0db2', - 'auctionId': '2e41f65424c87c', - 'adUnitCode': 'adunit-code', - 'bidId': '2e41f65424c87c' -}; - -const SERVER_VIDEO_RESPONSE = { - 'source': { 'aid': 12345, 'pubId': 54321 }, - 'bids': [{ - 'vastUrl': 'http://rtb.adtelligent.com/vast/?adid=44F2AEB9BFC881B3', - 'requestId': '2e41f65424c87c', - 'url': '44F2AEB9BFC881B3', - 'creative_id': 342516, - 'durationSeconds': 30, - 'cmpId': 342516, - 'height': 480, - 'cur': 'USD', - 'width': 640, - 'cpm': 0.9, - 'adomain': ['a.com'] - }] -}; -const SERVER_OUSTREAM_VIDEO_RESPONSE = SERVER_VIDEO_RESPONSE; -const SERVER_DISPLAY_RESPONSE = { - 'source': { 'aid': 12345, 'pubId': 54321 }, - 'bids': [{ - 'ad': '', - 'adUrl': 'adUrl', - 'requestId': '2e41f65424c87c', - 'creative_id': 342516, - 'cmpId': 342516, - 'height': 250, - 'cur': 'USD', - 'width': 300, - 'cpm': 0.9 - }], - 'cookieURLs': ['link1', 'link2'] -}; -const SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS = { - 'source': { 'aid': 12345, 'pubId': 54321 }, - 'bids': [{ - 'ad': '', - 'requestId': '2e41f65424c87c', - 'creative_id': 342516, - 'cmpId': 342516, - 'height': 250, - 'cur': 'USD', - 'width': 300, - 'cpm': 0.9 - }], - 'cookieURLs': ['link3', 'link4'], - 'cookieURLSTypes': ['image', 'iframe'] -}; -const outstreamVideoBidderRequest = { - bidderCode: 'bidderCode', - bids: [{ - 'params': { - 'aid': 12345, - 'outstream': { - 'video_controls': 'show' - } - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 480] - } - }, - bidId: '2e41f65424c87c' - }] -}; -const videoBidderRequest = { - bidderCode: 'bidderCode', - bids: [{ mediaTypes: { video: {} }, bidId: '2e41f65424c87c' }] -}; - -const displayBidderRequest = { - bidderCode: 'bidderCode', - bids: [{ bidId: '2e41f65424c87c' }] -}; - -const ageVerificationData = { - id: "123456789123456789", - status: "accepted", - decisionDate: "2011-10-05T14:48:00.000Z" -}; - -const displayBidderRequestWithConsents = { - bidderCode: 'bidderCode', - bids: [{ bidId: '2e41f65424c87c' }], - gdprConsent: { - gdprApplies: true, - consentString: 'test' - }, - gppConsent: { - gppString: 'abc12345234', - applicableSections: [7, 8] - }, - uspConsent: 'iHaveIt', - ortb2: { - regs: { - ext: { - age_verification: ageVerificationData - } - } - } -}; - -const videoEqResponse = [{ - vastUrl: 'http://rtb.adtelligent.com/vast/?adid=44F2AEB9BFC881B3', - requestId: '2e41f65424c87c', - creativeId: 342516, - mediaType: 'video', - netRevenue: true, - currency: 'USD', - height: 480, - width: 640, - ttl: 300, - cpm: 0.9, - meta: { - advertiserDomains: ['a.com'] - } -}]; - -const displayEqResponse = [{ - requestId: '2e41f65424c87c', - creativeId: 342516, - mediaType: 'banner', - netRevenue: true, - currency: 'USD', - ad: '', - adUrl: 'adUrl', - height: 250, - width: 300, - ttl: 300, - cpm: 0.9, - meta: { - advertiserDomains: [] - } - -}]; - -describe('adtelligentBidAdapter', () => { - const adapter = newBidder(spec); - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('user syncs', () => { - describe('as image', () => { - it('should be returned if pixel enabled', () => { - const syncs = spec.getUserSyncs({ pixelEnabled: true }, [{ body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS }]); - - expect(syncs.map(s => s.url)).to.deep.equal([SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS.cookieURLs[0]]); - expect(syncs.map(s => s.type)).to.deep.equal(['image']); - }) - }) - - describe('as iframe', () => { - it('should be returned if iframe enabled', () => { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [{ body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS }]); - - expect(syncs.map(s => s.url)).to.deep.equal([SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS.cookieURLs[1]]); - expect(syncs.map(s => s.type)).to.deep.equal(['iframe']); - }) - }) - - describe('user sync', () => { - it('should not be returned if passed syncs where already used', () => { - const syncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, [{ body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS }]); - - expect(syncs).to.deep.equal([]); - }) - - it('should not be returned if pixel not set', () => { - const syncs = spec.getUserSyncs({}, [{ body: SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS }]); - - expect(syncs).to.be.empty; - }); - }); - describe('user syncs with both types', () => { - it('should be returned if pixel and iframe enabled', () => { - const mockedServerResponse = Object.assign({}, SERVER_DISPLAY_RESPONSE_WITH_MIXED_SYNCS, { 'cookieURLs': ['link5', 'link6'] }); - const syncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, [{ body: mockedServerResponse }]); - - expect(syncs.map(s => s.url)).to.deep.equal(mockedServerResponse.cookieURLs); - expect(syncs.map(s => s.type)).to.deep.equal(mockedServerResponse.cookieURLSTypes); - }); - }); - }); - - describe('isBidRequestValid', () => { - it('should return true when required params found', () => { - expect(spec.isBidRequestValid(VIDEO_REQUEST)).to.equal(true); - }); - - it('should return false when required params are not passed', () => { - const bid = Object.assign({}, VIDEO_REQUEST); - delete bid.params; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', () => { - const videoBidRequests = [VIDEO_REQUEST]; - const displayBidRequests = [DISPLAY_REQUEST]; - const videoAndDisplayBidRequests = [DISPLAY_REQUEST, VIDEO_REQUEST]; - const displayRequest = spec.buildRequests(displayBidRequests, DEFAULT_ADATPER_REQ); - const videoRequest = spec.buildRequests(videoBidRequests, DEFAULT_ADATPER_REQ); - const videoAndDisplayRequests = spec.buildRequests(videoAndDisplayBidRequests, DEFAULT_ADATPER_REQ); - const rotatingRequest = spec.buildRequests(displayBidRequests, DEFAULT_ADATPER_REQ); - it('rotates endpoints', () => { - const bidReqUrls = [displayRequest[0], videoRequest[0], videoAndDisplayRequests[0], rotatingRequest[0]].map(br => br.url); - expect(bidReqUrls).to.deep.equal(EXPECTED_ENDPOINTS); - }) - - it('makes correct host for aliases', () => { - for (const alias in aliasEP) { - const bidReq = deepClone(DISPLAY_REQUEST) - bidReq.bidder = alias; - const [bidderRequest] = spec.buildRequests([bidReq], { bidderCode: alias }); - expect(bidderRequest.url).to.equal(aliasEP[alias]); - } - }) - - it('building requests as arrays', () => { - expect(videoRequest).to.be.a('array'); - expect(displayRequest).to.be.a('array'); - expect(videoAndDisplayRequests).to.be.a('array'); - }) - - it('sending as POST', () => { - const postActionMethod = 'POST' - const comparator = br => br.method === postActionMethod; - expect(videoRequest.every(comparator)).to.be.true; - expect(displayRequest.every(comparator)).to.be.true; - expect(videoAndDisplayRequests.every(comparator)).to.be.true; - }); - it('forms correct ADPOD request', () => { - const pbBidReqData = spec.buildRequests([ADPOD_REQUEST], DEFAULT_ADATPER_REQ)[0].data; - const impRequest = pbBidReqData.BidRequests[0] - expect(impRequest.AdType).to.be.equal('video'); - expect(impRequest.Adpod).to.be.a('object'); - expect(impRequest.Adpod.anyField).to.be.equal(10); - }) - it('sends correct video bid parameters', () => { - const data = videoRequest[0].data; - - const eq = { - CallbackId: '84ab500420319d', - AdType: 'video', - Aid: 12345, - Sizes: '480x360,640x480', - PlacementId: 'adunit-code', - GPID: '12345/adunit-code' - }; - expect(data.BidRequests[0]).to.deep.equal(eq); - }); - - it('sends correct display bid parameters', () => { - const data = displayRequest[0].data; - - const eq = { - CallbackId: '84ab500420319d', - AdType: 'display', - Aid: 12345, - Sizes: '300x250', - PlacementId: 'adunit-code', - GPID: '12345/adunit-code' - }; - - expect(data.BidRequests[0]).to.deep.equal(eq); - }); - - it('sends correct video and display bid parameters', () => { - const bidRequests = videoAndDisplayRequests[0].data; - const expectedBidReqs = [{ - CallbackId: '84ab500420319d', - AdType: 'display', - Aid: 12345, - Sizes: '300x250', - PlacementId: 'adunit-code', - GPID: '12345/adunit-code' - }, { - CallbackId: '84ab500420319d', - AdType: 'video', - Aid: 12345, - Sizes: '480x360,640x480', - PlacementId: 'adunit-code', - GPID: '12345/adunit-code' - }] - - expect(bidRequests.BidRequests).to.deep.equal(expectedBidReqs); - }); - - describe('publisher environment', () => { - const sandbox = sinon.createSandbox(); - sandbox.stub(config, 'getConfig').callsFake((key) => { - const config = { - 'coppa': true - }; - return config[key]; - }); - const bidRequestWithPubSettingsData = spec.buildRequests([DISPLAY_REQUEST], displayBidderRequestWithConsents)[0].data; - sandbox.restore(); - it('sets GDPR', () => { - expect(bidRequestWithPubSettingsData.GDPR).to.be.equal(1); - expect(bidRequestWithPubSettingsData.GDPRConsent).to.be.equal(displayBidderRequestWithConsents.gdprConsent.consentString); - }); - it('sets GPP flags', () => { - expect(bidRequestWithPubSettingsData.GPP).to.be.equal(displayBidderRequestWithConsents.gppConsent.gppString); - expect(bidRequestWithPubSettingsData.GPPSid).to.be.equal('7,8'); - }); - it('sets USP', () => { - expect(bidRequestWithPubSettingsData.USP).to.be.equal(displayBidderRequestWithConsents.uspConsent); - }) - it('sets Coppa', () => { - expect(bidRequestWithPubSettingsData.Coppa).to.be.equal(1); - }) - it('sets Schain', () => { - expect(bidRequestWithPubSettingsData.Schain).to.be.deep.equal(DISPLAY_REQUEST.schain); - }) - it('sets UserId\'s', () => { - expect(bidRequestWithPubSettingsData.UserIds).to.be.deep.equal(DISPLAY_REQUEST.userId); - }) - it('sets AgeVerification', () => { - expect(bidRequestWithPubSettingsData.AgeVerification).to.deep.equal(ageVerificationData); - }); - }) - }); - - describe('interpretResponse', () => { - let serverResponse; - let adapterRequest; - let eqResponse; - - afterEach(() => { - serverResponse = null; - adapterRequest = null; - eqResponse = null; - }); - - it('should get correct video bid response', () => { - serverResponse = SERVER_VIDEO_RESPONSE; - adapterRequest = videoBidderRequest; - eqResponse = videoEqResponse; - - bidServerResponseCheck(); - }); - - it('should get correct display bid response', () => { - serverResponse = SERVER_DISPLAY_RESPONSE; - adapterRequest = displayBidderRequest; - eqResponse = displayEqResponse; - - bidServerResponseCheck(); - }); - - function bidServerResponseCheck() { - const result = spec.interpretResponse({ body: serverResponse }, { adapterRequest }); - - expect(result).to.deep.equal(eqResponse); - } - - function nobidServerResponseCheck() { - const noBidServerResponse = { bids: [] }; - const noBidResult = spec.interpretResponse({ body: noBidServerResponse }, { adapterRequest }); - - expect(noBidResult.length).to.equal(0); - } - - it('handles video nobid responses', () => { - adapterRequest = videoBidderRequest; - - nobidServerResponseCheck(); - }); - - it('handles display nobid responses', () => { - adapterRequest = displayBidderRequest; - - nobidServerResponseCheck(); - }); - - it('forms correct ADPOD response', () => { - const videoBids = spec.interpretResponse({ body: SERVER_VIDEO_RESPONSE }, { adapterRequest: { bids: [ADPOD_REQUEST] } }); - expect(videoBids[0].video.durationSeconds).to.be.equal(30); - expect(videoBids[0].video.context).to.be.equal('adpod'); - }) - describe('outstream setup', () => { - const videoBids = spec.interpretResponse({ body: SERVER_OUSTREAM_VIDEO_RESPONSE }, { adapterRequest: outstreamVideoBidderRequest }); - it('should return renderer with expected outstream params config', () => { - expect(!!videoBids[0].renderer).to.be.true; - expect(videoBids[0].renderer.getConfig().video_controls).to.equal('show'); - }) - }) - }); -}); diff --git a/test/spec/modules/adtrgtmeBidAdapter_spec.js b/test/spec/modules/adtrgtmeBidAdapter_spec.js deleted file mode 100644 index 702086c48..000000000 --- a/test/spec/modules/adtrgtmeBidAdapter_spec.js +++ /dev/null @@ -1,733 +0,0 @@ -import { expect } from 'chai'; -import { config } from 'src/config.js'; -import { spec } from 'modules/adtrgtmeBidAdapter.js'; - -const DEFAULT_SID = '1220291391'; -const DEFAULT_ZID = '1836455615'; -const DEFAULT_PIXEL_URL = 'https://cdn.adtarget.me/libs/1x1.gif'; -const DEFAULT_BANNER_URL = 'https://cdn.adtarget.me/libs/banner/300x250.jpg'; -const BIDDER_VERSION = '1.0.7'; -const PREBIDJS_VERSION = '$prebid.version$'; - -const createBidRequest = ({bidId, adUnitCode, bidOverride, zid, ortb2}) => { - const bR = { - auctionId: 'f3c594t-3o0ch1b0rm-ayn93c3o0ch1b0rm', - adUnitCode, - bidId, - bidder: 'adtrgtme', - mediaTypes: {}, - params: { - sid: DEFAULT_SID, - bidOverride - }, - transactionId: '5b17b67d-7704-4732-8cc9-5b1723e9bcf9', - ortb2 - }; - - bR.mediaTypes.banner = { - sizes: [[300, 250]] - }; - bR.sizes = [[300, 250]]; - - if (typeof zid === 'string') { - bR.params.zid = zid; - } - return bR; -} - -const createBidderRequest = (arr, code = 'default-code', ortb2 = {}) => { - return { - adUnitCode: code, - auctionId: 'd4c83a3b-18e4-4208-b98b-63848449c7aa', - bidderCode: 'adtrgtme', - bids: arr, - refererInfo: { - page: 'https://partner-site.com', - stack: ['https://partner-site.com'], - }, - gdprConsent: { - consentString: 'BOtmiBKOtmiBKABABAENAFAAAAACeAAA', - vendorData: {}, - gdprApplies: true - }, - timeout: 1000, - ortb2 - }; -}; - -const createRequestMock = ({bidId, adUnitCode, type, zid, bidOverride, pubIdMode, ortb2}) => { - const bR = createBidRequest({ - bidId: bidId || '84ab500420319d', - adUnitCode: adUnitCode || '/1220291391/banner', - type: type || 'banner', - zid: zid || DEFAULT_ZID, - bidOverride: bidOverride || {}, - pubIdMode: pubIdMode || false, - ortb2: ortb2 || {} - }); - return { bidRequest: bR, validBR: [bR], bidderRequest: createBidderRequest([bR], adUnitCode, ortb2) } -}; - -const createAdm = (type) => { - let ADM; - switch (type) { - case 'banner': - ADM = ` - `; - break; - default: - ADM = 'Ad is here'; - break; - }; - return ADM; -}; - -const createResponseMock = (type) => { - const sR = { - body: { - id: '5qtvluj7bk6jhzmqwu4zzulv', - seatbid: [{ - bid: [{ - id: '5qtvluj7bk6jhzmqwu4zzulv', - impid: 'y7v7iu0uljj94rbjcw9', - adm: createAdm(type), - price: 1, - w: 300, - h: 250, - crid: 'creativeid', - adomain: ['some-advertiser-domain.com'] - }], - seat: 12345 - }] - } - }; - const { validBR, bidderRequest } = createRequestMock({type}); - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - - return {sR, data, bidderRequest}; -} - -describe('Adtrgtme Bid Adapter:', () => { - it('PLACEHOLDER TO PASS GULP', () => { - expect({}).to.be.an('object'); - }); - - describe('check basic properties', () => { - it('should define bidder code', () => { - expect(spec.code).to.equal('adtrgtme') - }); - }); - - describe('getUserSyncs', () => { - const BAD_SYNC_URL = 'cdn.adtarget.me/libs/1x1.gif?image&rnd=5fr55r'; - const IMAGE_SYNC_URL = `${DEFAULT_PIXEL_URL}?image&rnd=5fr55r`; - const IFRAME_SYNC_ONE_URL = `${DEFAULT_PIXEL_URL}?iframe1&rnd=5fr55r`; - const IFRAME_SYNC_TWO_URL = `${DEFAULT_PIXEL_URL}?iframe2&rnd=5fr55r`; - - let sRs = []; - beforeEach(() => { - sRs[0] = { - body: { - ext: { - pixels: [ - ['image', BAD_SYNC_URL], - ['invalid', IMAGE_SYNC_URL], - ['image', IMAGE_SYNC_URL], - ['iframe', IFRAME_SYNC_ONE_URL], - ['iframe', IFRAME_SYNC_TWO_URL] - ] - } - } - } - }); - - after(() => { - sRs = undefined; - }); - - it('sync check bad url and type in pixels', () => { - const opt = { - iframeEnabled: true, - pixelEnabled: true - }; - const pixels = spec.getUserSyncs(opt, sRs); - expect(pixels.length).to.equal(3); - }); - - it('sync check for iframe only', () => { - const opt = { - iframeEnabled: true, - pixelEnabled: false - }; - const pixels = spec.getUserSyncs(opt, sRs); - expect(pixels.length).to.equal(2); - expect(pixels).to.deep.equal( - [ - {type: 'iframe', 'url': IFRAME_SYNC_ONE_URL}, - {type: 'iframe', 'url': IFRAME_SYNC_TWO_URL} - ] - ) - }); - - it('sync check for image only', () => { - const opt = { - iframeEnabled: false, - pixelEnabled: true - }; - const pixels = spec.getUserSyncs(opt, sRs); - expect(pixels.length).to.equal(1); - expect(pixels).to.deep.equal( - [ - {type: 'image', 'url': IMAGE_SYNC_URL} - ] - ) - }); - - it('Sync for iframe and image', () => { - const opt = { - iframeEnabled: true, - pixelEnabled: true - }; - const pixels = spec.getUserSyncs(opt, sRs); - expect(pixels.length).to.equal(3); - expect(pixels).to.deep.equal( - [ - {type: 'image', 'url': IMAGE_SYNC_URL}, - {type: 'iframe', 'url': IFRAME_SYNC_ONE_URL}, - {type: 'iframe', 'url': IFRAME_SYNC_TWO_URL} - ] - ) - }); - }); - - describe('Check if bid request is OK', () => { - const BAD_VALUE = [ - {}, - {params: {}}, - {params: {sid: 1220291391, zid: '1836455615'}}, - {params: {sid: '1220291391', zid: 'A'}}, - {params: {sid: '', zid: '1836455615'}}, - {params: {sid: '', zid: 'A'}}, - {params: {zid: ''}}, - ]; - - BAD_VALUE.forEach(value => { - it(`should determine bad bid for ${JSON.stringify(value)}`, () => { - expect(spec.isBidRequestValid(value)).to.be.false; - }); - }); - - const OK_VALUE = [ - {params: {sid: '1220291391'}}, - {params: {sid: '1220291391', zid: 1836455615}}, - {params: {sid: '1220291391', zid: '1836455615'}}, - {params: {sid: '1220291391', zid: '1836455615A'}}, - ]; - - OK_VALUE.forEach(value => { - it(`should determine OK bid for ${JSON.stringify(value)}`, () => { - expect(spec.isBidRequestValid(value)).to.be.true; - }); - }); - }); - - describe('Bidfloor support:', () => { - it('should get bidfloor from getFloor method', () => { - const { bidRequest, validBR, bidderRequest } = createRequestMock({}); - bidRequest.params.bidOverride = {cur: 'AUD'}; - bidRequest.getFloor = (floorObj) => { - return { - floor: bidRequest.floors.values[floorObj.mediaType + '|300x250'], - currency: floorObj.currency, - mediaType: floorObj.mediaType - } - }; - bidRequest.floors = { - currency: 'AUD', - values: { - 'banner|300x250': 1.111 - } - }; - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.cur).to.deep.equal(['AUD']); - expect(data.imp[0].bidfloor).is.a('number'); - expect(data.imp[0].bidfloor).to.equal(1.111); - }); - }); - - describe('Schain support:', () => { - it('should send schains', function () { - const { bidRequest, validBR, bidderRequest } = createRequestMock({}); - const globalSchain = { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'adtarget-partner.com', - sid: '1234567890', - rid: bidRequest.bidId, - hp: 1 - }] - }; - bidRequest.ortb2 = { source: { ext: { schain: globalSchain } } }; - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - const schain = data.source.schain; - expect(schain.nodes.length).to.equal(1); - expect(schain).to.equal(globalSchain); - }); - }); - - describe('Check Site obj support (ortb2):', () => { - const BAD_ORTB2_TYPES = [ null, [], 123, 'invalidID', true, false, undefined ]; - BAD_ORTB2_TYPES.forEach(key => { - it(`should remove bad site data: ${JSON.stringify(key)}`, () => { - const ortb2 = { site: key } - const { validBR, bidderRequest } = createRequestMock({ortb2}); - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.site[key]).to.be.undefined; - }); - }); - - const OK_SITE_STR = ['id', 'name', 'domain', 'page', 'ref', 'keywords']; - const OK_SITE_ARR = ['cat', 'sectioncat', 'pagecat']; - - OK_SITE_STR.forEach(key => { - it(`should allow supported site keys to be added bid request: ${JSON.stringify(key)}`, () => { - const ortb2 = { - site: { - [key]: 'some value here' - } - }; - const { validBR, bidderRequest } = createRequestMock({ortb2}); - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.site[key]).to.exist; - expect(data.site[key]).to.be.a('string'); - expect(data.site[key]).to.be.equal(ortb2.site[key]); - }); - }); - - OK_SITE_ARR.forEach(key => { - it(`should determine valid keys of the ortb2 site and append to the bid request: ${JSON.stringify(key)}`, () => { - const ortb2 = { - site: { - [key]: ['some value here'] - } - }; - const { validBR, bidderRequest } = createRequestMock({ortb2}); - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.site[key]).to.exist; - expect(data.site[key]).to.be.a('array'); - expect(data.site[key]).to.be.equal(ortb2.site[key]); - }); - }); - - const OK_CONTENT_STR = ['id', 'title', 'language']; - OK_CONTENT_STR.forEach(key => { - it(`should determine that the ortb2.site String key is ok and append to the bid request: ${JSON.stringify(key)}`, () => { - const ortb2 = { - site: { - content: { - [key]: 'some value here' - } - } - }; - const { validBR, bidderRequest } = createRequestMock({ortb2}); - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.site.content[key]).to.exist; - expect(data.site.content[key]).to.be.a('string'); - expect(data.site.content[key]).to.be.equal(ortb2.site.content[key]); - }); - }); - - const OK_CONTENT_ARR = ['cat']; - OK_CONTENT_ARR.forEach(key => { - it(`should determine that the ortb2.site key is ok and append to the bid request: ${JSON.stringify(key)}`, () => { - const ortb2 = { - site: { - content: { - [key]: ['some value here', 'something-else'] - } - } - }; - const { validBR, bidderRequest } = createRequestMock({ortb2}); - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.site.content[key]).to.be.a('array'); - expect(data.site.content[key]).to.be.equal(ortb2.site.content[key]); - }); - }); - }); - - describe('Check ortb2 user support:', () => { - const BAD_ORTB2_TYPES = [ null, [], 'unsupportedKeyName', true, false, undefined ]; - BAD_ORTB2_TYPES.forEach(key => { - it(`should not allow bad site types to be added to bid request: ${JSON.stringify(key)}`, () => { - const ortb2 = { user: key } - const { validBR, bidderRequest } = createRequestMock({ortb2}); - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.user[key]).to.be.undefined; - }); - }); - - const OK_USER_STR = ['id', 'buyeruid', 'gender', 'keywords', 'customdata']; - OK_USER_STR.forEach(key => { - it(`should allow valid keys of the user to be added to bid request: ${JSON.stringify(key)}`, () => { - const ortb2 = { - user: { - [key]: 'some value here' - } - }; - const { validBR, bidderRequest } = createRequestMock({ortb2}); - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.user[key]).to.exist; - expect(data.user[key]).to.be.a('string'); - expect(data.user[key]).to.be.equal(ortb2.user[key]); - }); - }); - - const OK_USER_OBJECTS = ['ext']; - OK_USER_OBJECTS.forEach(key => { - it(`should allow user ext to be added to the bid request: ${JSON.stringify(key)}`, () => { - const ortb2 = { - user: { - [key]: {a: '123', b: '456'} - } - }; - const { validBR, bidderRequest } = createRequestMock({ortb2}); - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.user[key]).to.exist; - expect(data.user[key]).to.be.a('object'); - expect(data.user[key].a).to.be.equal('123'); - expect(data.user[key].b).to.be.equal('456'); - config.setConfig({ortb2: {}}); - }); - }); - - it(`should allow adUnit.ortb2Imp.ext.data object to be added to the bid request`, () => { - const { validBR, bidderRequest } = createRequestMock({}) - validBR[0].ortb2Imp = { - ext: { - data: { - pbadslot: 'homepage-top-rect', - adUnitSpecificAttribute: '123' - } - } - }; - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.imp[0].ext.data).to.deep.equal(validBR[0].ortb2Imp.ext.data); - }); - it(`should allow adUnit.ortb2Imp.instl numeric boolean "1" to be added to the bid request`, () => { - const { validBR, bidderRequest } = createRequestMock({}) - validBR[0].ortb2Imp = { - instl: 1 - }; - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.imp[0].instl).to.deep.equal(validBR[0].ortb2Imp.instl); - }); - - it(`should prevent adUnit.ortb2Imp.instl boolean "true" to be added to the bid request`, () => { - const { validBR, bidderRequest } = createRequestMock({}) - validBR[0].ortb2Imp = { - instl: true - }; - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.imp[0].instl).to.not.exist; - }); - - it(`should prevent adUnit.ortb2Imp.instl boolean false to be added to the bid request`, () => { - const { validBR, bidderRequest } = createRequestMock({}) - validBR[0].ortb2Imp = { - instl: false - }; - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.imp[0].instl).to.not.exist; - }); - }); - - describe('GDPR:', () => { - it('should return request objects that do not send cookies if purpose 1 consent is not provided', () => { - const { validBR, bidderRequest } = createRequestMock({}); - bidderRequest.gdprConsent = { - consentString: 'BOtmiBKO234234tmiBKABABAEN234AFAAAAACeAAA', - apiVersion: 2, - vendorData: { - purpose: { - consents: { - '1': false - } - } - }, - gdprApplies: true - }; - const opt = spec.buildRequests(validBR, bidderRequest)[0].options; - expect(opt.withCredentials).to.be.false; - }); - }); - - describe('Endpoint & Impression request mode:', () => { - it('should route request to config override endpoint', () => { - const { validBR, bidderRequest } = createRequestMock({}); - const sid = validBR[0].params.sid; - const testOverrideEndpoint = 'http://partner-adserv-domain.com/ssp?s='; - config.setConfig({ - adtrgtme: { - endpoint: testOverrideEndpoint - } - }); - const response = spec.buildRequests(validBR, bidderRequest)[0]; - expect(response).to.deep.include( - { - method: 'POST', - url: testOverrideEndpoint + sid - }); - }); - - it('should route request to endpoint + sid', () => { - config.setConfig({ - adtrgtme: {} - }); - const { validBR, bidderRequest } = createRequestMock({}); - const sid = validBR[0].params.sid; - const response = spec.buildRequests(validBR, bidderRequest); - expect(response[0]).to.deep.include({ - method: 'POST', - url: 'https://z.cdn.adtarget.market/ssp?prebid&s=' + sid - }); - }); - - it('should return a single request object for single request mode', () => { - let { bidRequest, validBR, bidderRequest } = createRequestMock({}); - const { bidRequest: mock } = createRequestMock({bidId: '6heos7ks8z0j', zid: '98876543210', adUnitCode: 'bidder-code'}); - validBR = [bidRequest, mock]; - bidderRequest.bids = validBR; - - config.setConfig({ - adtrgtme: { - singleRequestMode: true - } - }); - - const data = spec.buildRequests(validBR, bidderRequest).data; - - expect(data.imp).to.be.an('array').with.lengthOf(2); - - expect(data.imp[0]).to.deep.include({ - id: '84ab500420319d', - ext: { - dfp_ad_unit_code: '/1220291391/banner' - } - }); - - expect(data.imp[1]).to.deep.include({ - id: '6heos7ks8z0j', - tagid: '98876543210', - ext: { - dfp_ad_unit_code: 'bidder-code' - } - }); - }); - }); - - describe('validate request filtering:', () => { - it('should return undefined when no bids', function () { - const request = spec.buildRequests([]); - expect(request).to.be.undefined; - }); - - it('buildRequests should return correct amount of objects', () => { - const { validBR, bidderRequest } = createRequestMock({}); - const response = spec.buildRequests(validBR, bidderRequest).bidderRequest; - expect(response.bids).to.be.an('array').to.have.lengthOf(1); - }); - }); - - describe('Validate request headers:', () => { - it('should return request objects with the custom headers and content type', () => { - const { validBR, bidderRequest } = createRequestMock({}); - bidderRequest.gdprConsent.gdprApplies = false; - const opt = spec.buildRequests(validBR, bidderRequest).options; - expect(opt).to.deep.equal( - { - contentType: 'application/json', - withCredentials: true - }); - }); - }); - - describe('Request data oRTB bid validation:', () => { - it('should create valid oRTB bid request object in the data field', () => { - const { validBR, bidderRequest } = createRequestMock({}); - const data = spec.buildRequests(validBR, bidderRequest).data; - expect(data.site).to.deep.include({ - id: bidderRequest.bids[0].params.sid, - page: bidderRequest.refererInfo.page - }); - - expect(data.device).to.deep.equal({ - dnt: 0, - ua: navigator.userAgent, - ip: undefined - }); - - expect(data.regs).to.deep.equal({ - 'us_privacy': '', - gdpr: 1 - }); - - expect(data.cur).to.deep.equal(['USD']); - }); - - it('should create valid oRTB imp.ext in the bid request', () => { - const { validBR, bidderRequest } = createRequestMock({}); - const data = spec.buildRequests(validBR, bidderRequest).data; - expect(data.imp[0].ext).to.deep.equal({ - dfp_ad_unit_code: '/1220291391/banner' - }); - }); - - it('should use siteId value as site.id', () => { - const { validBR, bidderRequest } = createRequestMock({pubIdMode: true}); - validBR[0].params.sid = '9876543210'; - const data = spec.buildRequests(validBR, bidderRequest).data; - expect(data.site.id).to.equal('9876543210'); - }); - - it('should use placementId value as imp.tagid when using "zid"', () => { - const { validBR, bidderRequest } = createRequestMock({}); - const TEST_ZID = '54321'; - validBR[0].params.zid = TEST_ZID; - const data = spec.buildRequests(validBR, bidderRequest).data; - expect(data.imp[0].tagid).to.deep.equal(TEST_ZID); - }); - }); - - describe('Request oRTB bid.imp validation:', () => { - it('should create valid default Banner imp', () => { - config.setConfig({ - adtrgtme: {} - }); - const { validBR, bidderRequest } = createRequestMock({}); - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.imp[0].banner).to.deep.equal({ - mimes: ['text/html', 'text/javascript', 'application/javascript', 'image/jpg'], - format: [{w: 300, h: 250}] - }); - }); - - it('should create valid Banner imp', () => { - config.setConfig({ - adtrgtme: { mode: 'banner' } - }); - const { validBR, bidderRequest } = createRequestMock({}); - const data = spec.buildRequests(validBR, bidderRequest)[0].data; - expect(data.imp[0].banner).to.deep.equal({ - mimes: ['text/html', 'text/javascript', 'application/javascript', 'image/jpg'], - format: [{w: 300, h: 250}] - }); - }); - }); - - describe('interpretResponse()', () => { - describe('for mediaTypes: "banner"', () => { - it('should insert banner object into response[0].ad', () => { - const { sR, bidderRequest } = createResponseMock('banner'); - const response = spec.interpretResponse(sR, {bidderRequest}); - expect(response[0].ad).to.equal(` - `); - expect(response[0].mediaType).to.equal('banner'); - }) - }); - - describe('Support adomains', () => { - it('should append bid-response adomain to meta.advertiserDomains', () => { - const { sR, bidderRequest } = createResponseMock('banner'); - const response = spec.interpretResponse(sR, {bidderRequest}); - expect(response[0].meta.advertiserDomains).to.be.a('array'); - expect(response[0].meta.advertiserDomains[0]).to.equal('some-advertiser-domain.com'); - }) - }); - - describe('Check response Ad ID / Creative ID', () => { - it('should use adId if it exists in the bid-response', () => { - const { sR, bidderRequest } = createResponseMock('banner'); - const adId = 'bid-response-adId'; - sR.body.seatbid[0].bid[0].adId = adId; - const response = spec.interpretResponse(sR, {bidderRequest}); - expect(response[0].adId).to.equal(adId); - }); - - it('should use impid if adId does not exist in the bid-response', () => { - const { sR, bidderRequest } = createResponseMock('banner'); - const impid = 'y7v7iu0uljj94rbjcw9'; - sR.body.seatbid[0].bid[0].impid = impid; - const response = spec.interpretResponse(sR, {bidderRequest}); - expect(response[0].adId).to.equal(impid); - }); - - it('should use crid if adId & impid do not exist in the bid-response', () => { - const { sR, bidderRequest } = createResponseMock('banner'); - const crid = 'passback-12579'; - sR.body.seatbid[0].bid[0].impid = undefined; - sR.body.seatbid[0].bid[0].crid = crid; - const response = spec.interpretResponse(sR, {bidderRequest}); - expect(response[0].adId).to.equal(crid); - }); - }); - - describe('Time To Live (ttl)', () => { - const BAD_TTL_FORMATS = ['string', [1, 2, 3], true, false, null, undefined]; - BAD_TTL_FORMATS.forEach(key => { - it('should not allow unsupported global adtrgtme.ttl formats and default to 300', () => { - const { sR, bidderRequest } = createResponseMock('banner'); - config.setConfig({ - adtrgtme: { ttl: key } - }); - const response = spec.interpretResponse(sR, {bidderRequest}); - expect(response[0].ttl).to.equal(300); - }); - - it('should not set unsupported ttl formats and check default to 300', () => { - const { sR, bidderRequest } = createResponseMock('banner'); - bidderRequest.bids[0].params.ttl = key; - const response = spec.interpretResponse(sR, {bidderRequest}); - expect(response[0].ttl).to.equal(300); - }); - }); - - const BAD_TTL_VALUES = [-1, 12345]; - BAD_TTL_VALUES.forEach(key => { - it('should not set bad global adtrgtme.ttl and check default to 300', () => { - const { sR, bidderRequest } = createResponseMock('banner'); - config.setConfig({ - adtrgtme: { ttl: key } - }); - const response = spec.interpretResponse(sR, {bidderRequest}); - expect(response[0].ttl).to.equal(300); - }); - - it('should not set bad keys.ttl values', () => { - const { sR, bidderRequest } = createResponseMock('banner'); - bidderRequest.bids[0].params.ttl = key; - const response = spec.interpretResponse(sR, {bidderRequest}); - expect(response[0].ttl).to.equal(300); - }); - }); - - it('should set gloabl ttl over params.ttl if it presents', () => { - const { sR, bidderRequest } = createResponseMock('banner'); - config.setConfig({ - adtrgtme: { ttl: 500 } - }); - bidderRequest.bids[0].params.ttl = 400; - const response = spec.interpretResponse(sR, {bidderRequest}); - expect(response[0].ttl).to.equal(500); - }); - }); - - describe('Alias support', () => { - it('should return undefined as the bidder code value', () => { - const { sR, bidderRequest } = createResponseMock('banner'); - const response = spec.interpretResponse(sR, {bidderRequest}); - expect(response[0].bidderCode).to.be.undefined; - }); - }); - }); -}); diff --git a/test/spec/modules/adtrueBidAdapter_spec.js b/test/spec/modules/adtrueBidAdapter_spec.js deleted file mode 100644 index 97e8e7cd9..000000000 --- a/test/spec/modules/adtrueBidAdapter_spec.js +++ /dev/null @@ -1,525 +0,0 @@ -import {expect} from 'chai' -import {spec} from 'modules/adtrueBidAdapter.js' -import {newBidder} from 'src/adapters/bidderFactory.js' -import * as utils from '../../../src/utils.js'; -import {config} from 'src/config.js'; - -describe('AdTrueBidAdapter', function () { - const adapter = newBidder(spec) - let bidRequests; - let bidResponses; - let bidResponses2; - beforeEach(function () { - bidRequests = [ - { - bidder: 'adtrue', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - publisherId: '1212', - zoneId: '21423', - reserve: 0 - }, - placementCode: 'adunit-code-1', - sizes: [[300, 250]], - bidId: '23acc48ad47af5', - requestId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - ortb2Imp: { - ext: { - tid: '92489f71-1bf2-49a0-adf9-000cea934729', - } - }, - ortb2: { - source: { - ext: { - schain: { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'indirectseller.com', - 'sid': '00001', - 'hp': 1 - }, - - { - 'asi': 'indirectseller-2.com', - 'sid': '00002', - 'hp': 1 - } - ] - } - } - } - } - } - ]; - bidResponses = { - body: { - id: '1610681506302', - seatbid: [ - { - bid: [ - { - id: '1', - impid: '201fb513ca24e9', - price: 2.880000114440918, - burl: 'https://hb.adtrue.com/prebid/win-notify?impid=1610681506302&wp=${AUCTION_PRICE}', - adm: '', - adid: '1610681506302', - adomain: [ - 'adtrue.com' - ], - cid: 'f6l0r6n', - crid: 'abc77au4', - attr: [], - w: 300, - h: 250 - } - ], - seat: 'adtrue', - group: 0 - } - ], - bidid: '1610681506302', - cur: 'USD', - ext: { - cookie_sync: [ - { - type: 1, - url: 'https://hb.adtrue.com/prebid/usersync?bidder=adtrue' - } - ] - } - } - }; - bidResponses2 = { - body: { - id: '1610681506302', - seatbid: [ - { - bid: [ - { - id: '1', - impid: '201fb513ca24e9', - price: 2.880000114440918, - burl: 'https://hb.adtrue.com/prebid/win-notify?impid=1610681506302&wp=${AUCTION_PRICE}', - adm: '', - adid: '1610681506302', - adomain: [ - 'adtrue.com' - ], - cid: 'f6l0r6n', - crid: 'abc77au4', - attr: [], - w: 300, - h: 250 - } - ], - seat: 'adtrue', - group: 0 - } - ], - bidid: '1610681506302', - cur: 'USD', - ext: { - cookie_sync: [ - { - type: 2, - url: 'https://hb.adtrue.com/prebid/usersync?bidder=adtrue&type=image' - }, - { - type: 1, - url: 'https://hb.adtrue.com/prebid/usersync?bidder=appnexus' - } - ] - } - } - }; - }); - - describe('.code', function () { - it('should return a bidder code of adtrue', function () { - expect(spec.code).to.equal('adtrue') - }) - }) - - describe('inherited functions', function () { - it('should exist and be a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function') - }) - }) - describe('implementation', function () { - describe('Bid validations', function () { - it('valid bid case', function () { - const validBid = { - bidder: 'adtrue', - params: { - zoneId: '21423', - publisherId: '1212' - } - }; - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(true); - }); - it('invalid bid case: publisherId not passed', function () { - const validBid = { - bidder: 'adtrue', - params: { - zoneId: '21423' - } - }; - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(false); - }); - it('valid bid case: zoneId is not passed', function () { - const validBid = { - bidder: 'adtrue', - params: { - publisherId: '1212' - } - }; - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(false); - }); - it('should return false if there are no params', () => { - const bid = { - 'bidder': 'adtrue', - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - banner: { - sizes: [[300, 250]] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false if there is no publisherId param', () => { - const bid = { - 'bidder': 'adtrue', - 'adUnitCode': 'adunit-code', - params: { - zoneId: '21423', - }, - 'mediaTypes': { - banner: { - sizes: [[300, 250]] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false if there is no zoneId param', () => { - const bid = { - 'bidder': 'adtrue', - 'adUnitCode': 'adunit-code', - params: { - publisherId: '1212', - }, - 'mediaTypes': { - banner: { - sizes: [[300, 250]] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return true if the bid is valid', () => { - const bid = { - 'bidder': 'adtrue', - 'adUnitCode': 'adunit-code', - params: { - zoneId: '21423', - publisherId: '1212', - }, - 'mediaTypes': { - banner: { - sizes: [[300, 250]] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - describe('Request formation', function () { - it('buildRequests function should not modify original bidRequests object', function () { - const originalBidRequests = utils.deepClone(bidRequests); - const request = spec.buildRequests(bidRequests, { - auctionId: 'new-auction-id' - }); - expect(bidRequests).to.deep.equal(originalBidRequests); - }); - - it('Endpoint/method checking', function () { - const request = spec.buildRequests(bidRequests, { - auctionId: 'new-auction-id' - }); - expect(request.url).to.equal('https://hb.adtrue.com/prebid/auction'); - expect(request.method).to.equal('POST'); - }); - - it('test flag not sent when adtrueTest=true is absent in page url', function () { - const request = spec.buildRequests(bidRequests, { - auctionId: 'new-auction-id' - }); - const data = JSON.parse(request.data); - expect(data.test).to.equal(undefined); - }); - it('Request params check', function () { - const request = spec.buildRequests(bidRequests, { - auctionId: 'new-auction-id' - }); - const data = JSON.parse(request.data); - expect(data.at).to.equal(1); // auction type - expect(data.cur[0]).to.equal('USD'); // currency - expect(data.site.domain).to.be.a('string'); // domain should be set - expect(data.site.publisher.id).to.equal(bidRequests[0].params.publisherId); // publisher Id - expect(data.ext.wrapper.transactionId).to.equal(bidRequests[0].ortb2Imp.ext.tid); // Prebid TransactionId - expect(data.source.tid).to.equal(bidRequests[0].ortb2Imp.ext.tid); // Prebid TransactionId - expect(data.imp[0].id).to.equal(bidRequests[0].bidId); // Prebid bid id is passed as id - expect(data.imp[0].bidfloor).to.equal(bidRequests[0].params.reserve); // reverse - expect(data.imp[0].tagid).to.equal(bidRequests[0].params.zoneId); // zoneId - expect(data.imp[0].banner.w).to.equal(300); // width - expect(data.imp[0].banner.h).to.equal(250); // height - expect(data.source.ext.schain).to.deep.equal(bidRequests[0].ortb2.source.ext.schain); - }); - it('Request params check with GDPR Consent', function () { - const bidRequest = { - gdprConsent: { - consentString: 'kjfdniwjnifwenrif3', - gdprApplies: true - } - }; - const request = spec.buildRequests(bidRequests, bidRequest); - const data = JSON.parse(request.data); - expect(data.user.ext.consent).to.equal('kjfdniwjnifwenrif3'); - expect(data.at).to.equal(1); // auction type - expect(data.cur[0]).to.equal('USD'); // currency - expect(data.site.domain).to.be.a('string'); // domain should be set - expect(data.site.publisher.id).to.equal(bidRequests[0].params.publisherId); // publisher Id - expect(data.ext.wrapper.transactionId).to.equal(bidRequests[0].ortb2Imp.ext.tid); // Prebid TransactionId - expect(data.source.tid).to.equal(bidRequests[0].ortb2Imp.ext.tid); // Prebid TransactionId - expect(data.imp[0].id).to.equal(bidRequests[0].bidId); // Prebid bid id is passed as id - expect(data.imp[0].bidfloor).to.equal(parseFloat(bidRequests[0].params.reserve)); // reverse - expect(data.imp[0].tagid).to.equal(bidRequests[0].params.zoneId); // zoneId - expect(data.imp[0].banner.w).to.equal(300); // width - expect(data.imp[0].banner.h).to.equal(250); // height - expect(data.source.ext.schain).to.deep.equal(bidRequests[0].ortb2.source.ext.schain); - }); - it('Request params check with USP/CCPA Consent', function () { - const bidRequest = { - uspConsent: '1NYN' - }; - const request = spec.buildRequests(bidRequests, bidRequest); - const data = JSON.parse(request.data); - expect(data.regs.ext.us_privacy).to.equal('1NYN');// USP/CCPAs - expect(data.at).to.equal(1); // auction type - expect(data.cur[0]).to.equal('USD'); // currency - expect(data.site.domain).to.be.a('string'); // domain should be set - expect(data.site.publisher.id).to.equal(bidRequests[0].params.publisherId); // publisher Id - expect(data.ext.wrapper.transactionId).to.equal(bidRequests[0].ortb2Imp.ext.tid); // Prebid TransactionId - expect(data.source.tid).to.equal(bidRequests[0].ortb2Imp.ext.tid); // Prebid TransactionId - expect(data.imp[0].id).to.equal(bidRequests[0].bidId); // Prebid bid id is passed as id - expect(data.imp[0].bidfloor).to.equal(parseFloat(bidRequests[0].params.reserve)); // reverse - expect(data.imp[0].tagid).to.equal(bidRequests[0].params.zoneId); // zoneId - expect(data.imp[0].banner.w).to.equal(300); // width - expect(data.imp[0].banner.h).to.equal(250); // height - expect(data.source.ext.schain).to.deep.equal(bidRequests[0].ortb2.source.ext.schain); - }); - - it('should NOT include coppa flag in bid request if coppa config is not present', () => { - const request = spec.buildRequests(bidRequests, {}); - const data = JSON.parse(request.data); - if (data.regs) { - // in case GDPR is set then data.regs will exist - expect(data.regs.coppa).to.equal(undefined); - } else { - expect(data.regs).to.equal(undefined); - } - }); - it('should include coppa flag in bid request if coppa is set to true', () => { - const sandbox = sinon.createSandbox(); - sandbox.stub(config, 'getConfig').callsFake(key => { - const config = { - 'coppa': true - }; - return config[key]; - }); - const request = spec.buildRequests(bidRequests, {}); - const data = JSON.parse(request.data); - expect(data.regs.coppa).to.equal(1); - sandbox.restore(); - }); - it('should NOT include coppa flag in bid request if coppa is set to false', () => { - const sandbox = sinon.createSandbox(); - sandbox.stub(config, 'getConfig').callsFake(key => { - const config = { - 'coppa': false - }; - return config[key]; - }); - const request = spec.buildRequests(bidRequests, {}); - const data = JSON.parse(request.data); - if (data.regs) { - // in case GDPR is set then data.regs will exist - expect(data.regs.coppa).to.equal(undefined); - } else { - expect(data.regs).to.equal(undefined); - } - sandbox.restore(); - }); - }); - }); - describe('Response checking', function () { - it('should check for valid response values', function () { - const request = spec.buildRequests(bidRequests, { - auctionId: 'new-auction-id' - }); - const data = JSON.parse(request.data); - const response = spec.interpretResponse(bidResponses, request); - expect(response).to.be.an('array').with.length.above(0); - expect(response[0].requestId).to.equal(bidResponses.body.seatbid[0].bid[0].impid); - expect(response[0].width).to.equal(bidResponses.body.seatbid[0].bid[0].w); - expect(response[0].height).to.equal(bidResponses.body.seatbid[0].bid[0].h); - if (bidResponses.body.seatbid[0].bid[0].crid) { - expect(response[0].creativeId).to.equal(bidResponses.body.seatbid[0].bid[0].crid); - } else { - expect(response[0].creativeId).to.equal(bidResponses.body.seatbid[0].bid[0].id); - } - expect(response[0].currency).to.equal('USD'); - expect(response[0].ttl).to.equal(300); - expect(response[0].meta.clickUrl).to.equal('adtrue.com'); - expect(response[0].meta.advertiserDomains[0]).to.equal('adtrue.com'); - expect(response[0].ad).to.equal(bidResponses.body.seatbid[0].bid[0].adm); - expect(response[0].partnerImpId).to.equal(bidResponses.body.seatbid[0].bid[0].id); - }); - - it('should parse native responses correctly', function () { - const nativeAdm = { - native: { - assets: [ - { id: 1, title: { text: 'Native Title' } }, - { id: 2, img: { url: 'img-url', h: 90, w: 728 } } - ], - link: { url: 'https://native.example', clicktrackers: ['https://ct.example'] }, - imptrackers: ['https://imp.example'], - jstracker: 'tracker' - } - }; - const serverResp = { - body: { - id: '2', - seatbid: [ - { - bid: [ - { - id: 'b', - impid: bidRequests[0].bidId, - price: 1, - adm: JSON.stringify(nativeAdm), - w: 728, - h: 90 - } - ], - seat: 'adtrue' - } - ], - cur: 'USD' - } - }; - const request = spec.buildRequests(bidRequests, { auctionId: 'native-auction' }); - const res = spec.interpretResponse(serverResp, request); - expect(res[0].mediaType).to.equal('native'); - expect(res[0].native.title).to.equal('Native Title'); - expect(res[0].native.image.url).to.equal('img-url'); - expect(res[0].native.clickUrl).to.equal('https://native.example'); - expect(res[0].native.clickTrackers[0]).to.equal('https://ct.example'); - expect(res[0].native.impressionTrackers[0]).to.equal('https://imp.example'); - expect(res[0].native.jstracker).to.equal('tracker'); - }); - - it('should identify video responses', function () { - const serverResp = { - body: { - id: '3', - seatbid: [ - { - bid: [ - { - id: 'v', - impid: bidRequests[0].bidId, - price: 1, - adm: '', - w: 640, - h: 480 - } - ] - } - ], - cur: 'USD' - } - }; - const request = spec.buildRequests(bidRequests, { auctionId: 'video-auction' }); - const res = spec.interpretResponse(serverResp, request); - expect(res[0].mediaType).to.equal('video'); - }); - }); - describe('getUserSyncs', function () { - let sandbox; - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - afterEach(function () { - sandbox.restore(); - }); - it('execute as per config', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, [bidResponses], undefined, undefined)).to.deep.equal([{ - type: 'iframe', - url: 'https://hb.adtrue.com/prebid/usersync?bidder=adtrue&publisherId=1212&zoneId=21423&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - // Multiple user sync output - it('execute as per config', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, [bidResponses2], undefined, undefined)).to.deep.equal([ - { - type: 'image', - url: 'https://hb.adtrue.com/prebid/usersync?bidder=adtrue&type=image&publisherId=1212&zoneId=21423&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }, - { - type: 'iframe', - url: 'https://hb.adtrue.com/prebid/usersync?bidder=appnexus&publisherId=1212&zoneId=21423&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - } - ]); - }); - - it('should include gdpr and usp values in the sync url', function () { - // build request to set zoneId and publisherId globals - spec.buildRequests(bidRequests, { auctionId: 'sync-test' }); - const syncs = spec.getUserSyncs( - { pixelEnabled: true }, - [bidResponses], - { gdprApplies: true, consentString: 'consentData' }, - '1YNN' - ); - expect(syncs[0].url).to.contain('gdpr=1'); - expect(syncs[0].url).to.contain('gdpr_consent=consentData'); - expect(syncs[0].url).to.contain('us_privacy=1YNN'); - }); - }); -}); diff --git a/test/spec/modules/aduptechBidAdapter_spec.js b/test/spec/modules/aduptechBidAdapter_spec.js deleted file mode 100644 index 2b909ebe2..000000000 --- a/test/spec/modules/aduptechBidAdapter_spec.js +++ /dev/null @@ -1,784 +0,0 @@ -import { expect } from 'chai'; -import { - BIDDER_CODE, - ENDPOINT_METHOD, - internal, - spec -} from '../../../modules/aduptechBidAdapter.js'; -import { config } from '../../../src/config.js'; -import * as utils from '../../../src/utils.js'; -import { BANNER, NATIVE } from '../../../src/mediaTypes.js' -import { newBidder } from '../../../src/adapters/bidderFactory.js'; - -describe('AduptechBidAdapter', () => { - describe('internal', () => { - describe('extractGdpr', () => { - it('should handle empty bidderRequest', () => { - expect(internal.extractGdpr(null)).to.be.null; - expect(internal.extractGdpr({})).to.be.null; - }); - - it('should extract bidderRequest.gdprConsent', () => { - const bidderRequest = { - gdprConsent: { - consentString: 'consentString', - gdprApplies: false - } - }; - - expect(internal.extractGdpr(bidderRequest)).to.deep.equal({ - consentString: bidderRequest.gdprConsent.consentString, - consentRequired: bidderRequest.gdprConsent.gdprApplies - }); - }); - - it('should handle missing bidderRequest.gdprConsent.gdprApplies', () => { - const bidderRequest = { - gdprConsent: { - consentString: 'consentString' - } - }; - - expect(internal.extractGdpr(bidderRequest)).to.deep.equal({ - consentString: bidderRequest.gdprConsent.consentString, - consentRequired: true - }); - }); - - it('should handle invalid bidderRequest.gdprConsent.gdprApplies', () => { - const bidderRequest = { - gdprConsent: { - consentString: 'consentString', - gdprApplies: 'foobar' - } - }; - - expect(internal.extractGdpr(bidderRequest)).to.deep.equal({ - consentString: bidderRequest.gdprConsent.consentString, - consentRequired: true - }); - }); - }); - - describe('extractPageUrl', () => { - let origPageUrl; - - beforeEach(() => { - // remember original pageUrl in config - origPageUrl = config.getConfig('pageUrl'); - - // unset pageUrl in config - config.setConfig({ pageUrl: null }); - }); - - afterEach(() => { - // set original pageUrl to config - config.setConfig({ pageUrl: origPageUrl }); - }); - - it('should handle empty or missing data', () => { - expect(internal.extractPageUrl(null)).to.equal(utils.getWindowSelf().location.href); - expect(internal.extractPageUrl({})).to.equal(utils.getWindowSelf().location.href); - expect(internal.extractPageUrl({ refererInfo: {} })).to.equal(utils.getWindowSelf().location.href); - expect(internal.extractPageUrl({ refererInfo: { canonicalUrl: null } })).to.equal(utils.getWindowSelf().location.href); - expect(internal.extractPageUrl({ refererInfo: { canonicalUrl: '' } })).to.equal(utils.getWindowSelf().location.href); - }); - - it('should use bidderRequest.refererInfo.page', () => { - const bidderRequest = { - refererInfo: { - page: 'http://canonical.url' - } - }; - - expect(internal.extractPageUrl(bidderRequest)).to.equal(bidderRequest.refererInfo.page); - }); - }); - - describe('extractReferrer', () => { - it('should handle empty or missing data', () => { - expect(internal.extractReferrer(null)).to.equal(utils.getWindowSelf().document.referrer); - expect(internal.extractReferrer({})).to.equal(utils.getWindowSelf().document.referrer); - expect(internal.extractReferrer({ refererInfo: {} })).to.equal(utils.getWindowSelf().document.referrer); - expect(internal.extractReferrer({ refererInfo: { referer: null } })).to.equal(utils.getWindowSelf().document.referrer); - expect(internal.extractReferrer({ refererInfo: { referer: '' } })).to.equal(utils.getWindowSelf().document.referrer); - }); - - it('hould use bidderRequest.refererInfo.ref', () => { - const bidderRequest = { - refererInfo: { - ref: 'foobar' - } - }; - - expect(internal.extractReferrer(bidderRequest)).to.equal(bidderRequest.refererInfo.ref); - }); - }); - - describe('extractParams', () => { - it('should handle empty bidRequest', () => { - expect(internal.extractParams(null)).to.be.null; - expect(internal.extractParams({})).to.be.null; - }); - - it('should extract bidRequest.params', () => { - const bidRequest = { - params: { - foo: '123', - bar: 456 - } - }; - expect(internal.extractParams(bidRequest)).to.deep.equal(bidRequest.params); - }); - }); - - describe('extractBannerConfig', () => { - it('should handle empty bidRequest', () => { - expect(internal.extractBannerConfig(null)).to.be.null; - expect(internal.extractBannerConfig({})).to.be.null; - }); - - it('should extract bidRequest.mediaTypes.banner', () => { - const bidRequest = { - mediaTypes: { - banner: { - sizes: [[12, 34], [56, 78]] - } - } - }; - expect(internal.extractBannerConfig(bidRequest)).to.deep.equal(bidRequest.mediaTypes.banner); - }); - - it('should extract bidRequest.sizes (backward compatibility)', () => { - const bidRequest = { - sizes: [[12, 34], [56, 78]] - }; - - expect(internal.extractBannerConfig(bidRequest)).to.deep.equal({sizes: bidRequest.sizes}); - }); - }); - - describe('extractNativeConfig', () => { - it('should handle empty bidRequest', () => { - expect(internal.extractNativeConfig(null)).to.be.null; - expect(internal.extractNativeConfig({})).to.be.null; - }); - - it('should extract bidRequest.mediaTypes.native', () => { - const bidRequest = { - mediaTypes: { - native: { - image: { - required: true - }, - title: { - required: true - } - } - } - }; - - expect(internal.extractNativeConfig(bidRequest)).to.deep.equal(bidRequest.mediaTypes.native); - }); - }); - - describe('getFloor', () => { - let bidRequest; - - beforeEach(() => { - bidRequest = { - getFloor: sinon.stub() - }; - }); - - it('should handle empty or invalid bidRequest', () => { - expect(internal.getFloor(null)).to.be.null; - expect(internal.getFloor({})).to.be.null; - expect(internal.getFloor({ getFloor: 'foo' })).to.be.null; - }); - - it('should detect floor via getFloor()', () => { - const result = { - floor: 1.11, - currency: 'USD' - }; - - const options = { - mediaType: BANNER, - size: '*' - } - - bidRequest.getFloor.returns(result); - - expect(internal.getFloor(bidRequest, options)).to.deep.equal(result); - expect(bidRequest.getFloor.calledOnceWith(options)).to.be.true; - }); - - it('should handle empty, invalid or faulty getFloor() results', () => { - bidRequest.getFloor - .onCall(0).returns({}) - .onCall(1).returns({ floor: 'foo' }) - .onCall(2).returns('bar') - .onCall(3).throws(new Error('baz')); - - expect(internal.getFloor(bidRequest, {})).to.be.null; - expect(internal.getFloor(bidRequest, {})).to.be.null; - expect(internal.getFloor(bidRequest, {})).to.be.null; - expect(internal.getFloor(bidRequest, {})).to.be.null; - - expect(bidRequest.getFloor.callCount).to.equal(4); - }); - }); - - describe('groupBidRequestsByPublisher', () => { - it('should handle empty bidRequests', () => { - expect(internal.groupBidRequestsByPublisher(null)).to.deep.equal({}); - expect(internal.groupBidRequestsByPublisher([])).to.deep.equal({}) - }); - - it('should group given bidRequests by params.publisher', () => { - const bidRequests = [ - { - mediaTypes: { - banner: { - sizes: [[100, 100]] - } - }, - params: { - publisher: 'publisher1', - placement: '1111' - } - }, - { - mediaTypes: { - banner: { - sizes: [[200, 200]] - } - }, - params: { - publisher: 'publisher2', - placement: '2222' - } - }, - { - mediaTypes: { - banner: { - sizes: [[300, 300]] - } - }, - params: { - publisher: 'publisher3', - placement: '3333' - } - }, - { - mediaTypes: { - banner: { - sizes: [[400, 400]] - } - }, - params: { - publisher: 'publisher1', - placement: '4444' - } - } - ]; - - expect(internal.groupBidRequestsByPublisher(bidRequests)).to.deep.equal({ - publisher1: [ - bidRequests[0], - bidRequests[3] - ], - publisher2: [ - bidRequests[1], - ], - publisher3: [ - bidRequests[2], - ], - }); - }); - }); - - describe('buildEndpointUrl', () => { - it('should build endpoint url based on given publisher code', () => { - expect(internal.buildEndpointUrl(1234)).to.be.equal('https://rtb.d.adup-tech.com/prebid/1234_bid'); - expect(internal.buildEndpointUrl('foobar')).to.be.equal('https://rtb.d.adup-tech.com/prebid/foobar_bid'); - expect(internal.buildEndpointUrl('foo bar')).to.be.equal('https://rtb.d.adup-tech.com/prebid/foo%20bar_bid'); - }); - }); - }); - - describe('spec', () => { - let adapter; - - beforeEach(() => { - adapter = newBidder(spec); - }); - - describe('code', () => { - it('should be correct', () => { - expect(adapter.getSpec().code).to.equal(BIDDER_CODE); - }); - }); - - describe('supportedMediaTypes', () => { - it('should be correct', () => { - expect(adapter.getSpec().supportedMediaTypes).to.deep.equal([BANNER, NATIVE]); - }); - }); - - describe('inherited functions', () => { - it('should exist and be a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', () => { - it('should be false on empty bid', () => { - expect(spec.isBidRequestValid(null)).to.be.false; - expect(spec.isBidRequestValid({})).to.be.false; - }); - - it('should be false if mediaTypes.banner and mediaTypes.native is missing', () => { - expect(spec.isBidRequestValid({ - params: { - publisher: 'test', - placement: '1234' - } - })).to.be.false; - }); - - it('should be false if params missing', () => { - expect(spec.isBidRequestValid({ - mediaTypes: { - banner: { - sizes: [[100, 200]] - } - }, - })).to.be.false; - }); - - it('should be false if params is invalid', () => { - expect(spec.isBidRequestValid({ - mediaTypes: { - banner: { - sizes: [[100, 200]] - } - }, - params: 'bar' - })).to.be.false; - }); - - it('should be false if params is empty', () => { - expect(spec.isBidRequestValid({ - mediaTypes: { - banner: { - sizes: [[100, 200]] - } - }, - params: {} - })).to.be.false; - }); - - it('should be false if params.publisher is missing', () => { - expect(spec.isBidRequestValid({ - mediaTypes: { - banner: { - sizes: [[100, 200]] - } - }, - params: { - placement: '1234' - } - })).to.be.false; - }); - - it('should be false if params.placement is missing', () => { - expect(spec.isBidRequestValid({ - mediaTypes: { - banner: { - sizes: [[100, 200]] - } - }, - params: { - publisher: 'test' - } - })).to.be.false; - }); - - it('should be true if mediaTypes.banner is given', () => { - expect(spec.isBidRequestValid({ - mediaTypes: { - banner: { - sizes: [[100, 200]] - } - }, - params: { - publisher: 'test', - placement: '1234' - } - })).to.be.true; - }); - - it('should be true if mediaTypes.native is given', () => { - expect(spec.isBidRequestValid({ - mediaTypes: { - native: { - image: { - required: true - }, - title: { - required: true - }, - clickUrl: { - required: true - }, - body: { - required: true - } - } - }, - params: { - publisher: 'test', - placement: '1234' - } - })).to.be.true; - }); - }); - - describe('buildRequests', () => { - it('should handle empty validBidRequests', () => { - expect(spec.buildRequests(null)).to.deep.equal([]); - expect(spec.buildRequests([])).to.deep.equal([]); - }); - - it('should build one request per publisher', () => { - const bidderRequest = { - auctionId: 'auctionId123', - refererInfo: { - page: 'http://crazy.canonical.url', - ref: 'http://crazy.referer.url' - }, - gdprConsent: { - consentString: 'consentString123', - gdprApplies: true - } - }; - - const validBidRequests = [ - { - bidId: 'bidId1', - adUnitCode: 'adUnitCode1', - ortb2Imp: { - ext: { - tid: 'transactionId1', - } - }, - mediaTypes: { - banner: { - sizes: [[100, 200], [300, 400]] - } - }, - params: { - publisher: 'publisher1', - placement: 'placement1' - } - }, - { - bidId: 'bidId2', - adUnitCode: 'adUnitCode2', - ortb2Imp: { - ext: { - tid: 'transactionId2', - } - }, - mediaTypes: { - banner: { - sizes: [[100, 200]] - } - }, - params: { - publisher: 'publisher1', - placement: 'placement2' - } - }, - { - bidId: 'bidId3', - adUnitCode: 'adUnitCode3', - ortb2Imp: { - ext: { - tid: { - transactionId: 'transactionId3', - } - } - }, - mediaTypes: { - native: { - image: { - required: true - }, - title: { - required: true - }, - clickUrl: { - required: true - }, - body: { - required: true - } - } - }, - params: { - publisher: 'publisher2', - placement: 'placement3' - } - } - ]; - - expect(spec.buildRequests(validBidRequests, bidderRequest)).to.deep.equal([ - { - url: internal.buildEndpointUrl(validBidRequests[0].params.publisher), - method: ENDPOINT_METHOD, - data: { - auctionId: bidderRequest.auctionId, - pageUrl: bidderRequest.refererInfo.page, - referrer: bidderRequest.refererInfo.ref, - gdpr: { - consentString: bidderRequest.gdprConsent.consentString, - consentRequired: bidderRequest.gdprConsent.gdprApplies - }, - imp: [ - { - bidId: validBidRequests[0].bidId, - transactionId: validBidRequests[0].ortb2Imp.ext.tid, - adUnitCode: validBidRequests[0].adUnitCode, - params: validBidRequests[0].params, - banner: validBidRequests[0].mediaTypes.banner - }, - { - bidId: validBidRequests[1].bidId, - transactionId: validBidRequests[1].ortb2Imp.ext.tid, - adUnitCode: validBidRequests[1].adUnitCode, - params: validBidRequests[1].params, - banner: validBidRequests[1].mediaTypes.banner - } - ] - } - }, - { - url: internal.buildEndpointUrl(validBidRequests[2].params.publisher), - method: ENDPOINT_METHOD, - data: { - auctionId: bidderRequest.auctionId, - pageUrl: bidderRequest.refererInfo.page, - referrer: bidderRequest.refererInfo.ref, - gdpr: { - consentString: bidderRequest.gdprConsent.consentString, - consentRequired: bidderRequest.gdprConsent.gdprApplies - }, - imp: [ - { - bidId: validBidRequests[2].bidId, - transactionId: validBidRequests[2].ortb2Imp.ext.tid, - adUnitCode: validBidRequests[2].adUnitCode, - params: validBidRequests[2].params, - native: validBidRequests[2].mediaTypes.native - } - ] - } - } - ]); - }); - - it('should build a request with floorPrices', () => { - const bidderRequest = { - auctionId: 'auctionId123', - refererInfo: { - page: 'http://crazy.canonical.url', - ref: 'http://crazy.referer.url' - }, - gdprConsent: { - consentString: 'consentString123', - gdprApplies: true - } - }; - - const bidRequest = { - bidId: 'bidId1', - adUnitCode: 'adUnitCode1', - ortb2Imp: { - ext: { - tid: 'transactionId1', - } - }, - mediaTypes: { - banner: { - sizes: [[100, 200], [300, 400]] - }, - native: { - image: { - required: true - }, - } - }, - params: { - publisher: 'publisher1', - placement: 'placement1' - }, - getFloor: sinon.stub() - .onCall(0).returns({ floor: 1.11, currency: 'USD' }) - .onCall(1).returns({ floor: 2.22, currency: 'EUR' }) - .onCall(2).returns({ floor: 3.33, currency: 'USD' }) - .onCall(3).returns({ floor: 4.44, currency: 'GBP' }) - .onCall(4).returns({ floor: 5.55, currency: 'EUR' }) - }; - - expect(spec.buildRequests([bidRequest], bidderRequest)).to.deep.equal([ - { - url: internal.buildEndpointUrl(bidRequest.params.publisher), - method: ENDPOINT_METHOD, - data: { - auctionId: bidderRequest.auctionId, - pageUrl: bidderRequest.refererInfo.page, - referrer: bidderRequest.refererInfo.ref, - gdpr: { - consentString: bidderRequest.gdprConsent.consentString, - consentRequired: bidderRequest.gdprConsent.gdprApplies - }, - imp: [ - { - bidId: bidRequest.bidId, - transactionId: bidRequest.ortb2Imp.ext.tid, - adUnitCode: bidRequest.adUnitCode, - params: bidRequest.params, - banner: { - sizes: [ - [100, 200, 1.11, 'USD'], - [300, 400, 2.22, 'EUR'], - ], - floorPrice: 3.33, - floorCurrency: 'USD' - }, - native: { - image: { - required: true - }, - floorPrice: 4.44, - floorCurrency: 'GBP' - }, - floorPrice: 5.55, - floorCurrency: 'EUR' - } - ] - } - } - ]); - - expect(bidRequest.getFloor.callCount).to.equal(5); - expect(bidRequest.getFloor.getCall(0).calledWith({ mediaType: BANNER, size: bidRequest.mediaTypes.banner.sizes[0] })).to.be.true; - expect(bidRequest.getFloor.getCall(1).calledWith({ mediaType: BANNER, size: bidRequest.mediaTypes.banner.sizes[1] })).to.be.true; - expect(bidRequest.getFloor.getCall(2).calledWith({ mediaType: BANNER, size: '*' })).to.be.true; - expect(bidRequest.getFloor.getCall(3).calledWith({ mediaType: NATIVE, size: '*' })).to.be.true; - expect(bidRequest.getFloor.getCall(4).calledWith({ mediaType: '*', size: '*' })).to.be.true; - }); - }); - - describe('interpretResponse', () => { - it('should handle empty serverResponse', () => { - expect(spec.interpretResponse(null)).to.deep.equal([]); - expect(spec.interpretResponse({})).to.deep.equal([]); - expect(spec.interpretResponse({ body: {} })).to.deep.equal([]); - expect(spec.interpretResponse({ body: { bids: [] } })).to.deep.equal([]); - }); - - it('should correctly interpret the server response', () => { - const serverResponse = { - body: { - bids: [ - { - bid: { - bidId: 'bidId1', - price: 0.12, - net: true, - currency: 'EUR', - ttl: 123 - }, - creative: { - id: 'creativeId1', - advertiserDomains: ['advertiser1.com', 'advertiser2.org'], - width: 100, - height: 200, - html: '
Hello World
' - } - }, - { - bid: { - bidId: 'bidId2', - price: 0.99, - net: false, - currency: 'USD', - ttl: 465 - }, - creative: { - id: 'creativeId2', - advertiserDomains: ['advertiser3.com'], - native: { - title: 'Ad title', - body: 'Ad description', - displayUrl: 'Ad display url', - clickUrl: 'http://click.url/ad.html', - image: { - url: 'https://image.url/ad.png', - width: 123, - height: 456 - }, - sponsoredBy: 'Ad sponsored by', - impressionTrackers: [ - 'https://impression.tracking.url/1', - 'https://impression.tracking.url/2', - ], - privacyLink: 'https://example.com/privacy', - privacyIcon: 'https://example.com/icon.png' - } - } - }, - null, // should be skipped - {} // should be skipped - ] - } - }; - - expect(spec.interpretResponse(serverResponse)).to.deep.equal([ - { - requestId: serverResponse.body.bids[0].bid.bidId, - cpm: serverResponse.body.bids[0].bid.price, - netRevenue: serverResponse.body.bids[0].bid.net, - currency: serverResponse.body.bids[0].bid.currency, - ttl: serverResponse.body.bids[0].bid.ttl, - creativeId: serverResponse.body.bids[0].creative.id, - meta: { - advertiserDomains: serverResponse.body.bids[0].creative.advertiserDomains - }, - mediaType: BANNER, - width: serverResponse.body.bids[0].creative.width, - height: serverResponse.body.bids[0].creative.height, - ad: serverResponse.body.bids[0].creative.html - }, - { - requestId: serverResponse.body.bids[1].bid.bidId, - cpm: serverResponse.body.bids[1].bid.price, - netRevenue: serverResponse.body.bids[1].bid.net, - currency: serverResponse.body.bids[1].bid.currency, - ttl: serverResponse.body.bids[1].bid.ttl, - creativeId: serverResponse.body.bids[1].creative.id, - meta: { - advertiserDomains: serverResponse.body.bids[1].creative.advertiserDomains - }, - mediaType: NATIVE, - native: serverResponse.body.bids[1].creative.native - } - ]); - }); - }); - }); -}); diff --git a/test/spec/modules/advRedAnalyticsAdapter_spec.js b/test/spec/modules/advRedAnalyticsAdapter_spec.js deleted file mode 100644 index fd56126d1..000000000 --- a/test/spec/modules/advRedAnalyticsAdapter_spec.js +++ /dev/null @@ -1,114 +0,0 @@ -import advRedAnalytics from 'modules/advRedAnalyticsAdapter.js'; -import {expect} from 'chai'; -import {server} from 'test/mocks/xhr.js'; -import {expectEvents} from '../../helpers/analytics.js'; -import { EVENTS } from 'src/constants.js'; -import sinon from 'sinon'; - -const events = require('src/events'); - -describe('AdvRed Analytics Adapter', function () { - const bidWonEvent = { - 'bidderCode': 'appnexus', - 'width': 300, - 'height': 250, - 'adId': '1ebb82ec35375e', - 'mediaType': 'banner', - 'cpm': 0.5, - 'requestId': '1582271863760569973', - 'creative_id': '96846035', - 'creativeId': '96846035', - 'ttl': 60, - 'currency': 'USD', - 'netRevenue': true, - 'auctionId': '9c7b70b9-b6ab-4439-9e71-b7b382797c18', - 'responseTimestamp': 1537521629657, - 'requestTimestamp': 1537521629331, - 'bidder': 'appnexus', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'timeToRespond': 326, - 'size': '300x250', - 'status': 'rendered', - 'eventType': 'bidWon', - 'ad': 'some ad', - 'adUrl': 'ad url' - }; - - describe('AdvRed Analytic tests', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - }); - - afterEach(function () { - advRedAnalytics.disableAnalytics(); - events.getEvents.restore(); - }); - - it('support custom endpoint', function () { - const custom_endpoint = 'custom url'; - advRedAnalytics.enableAnalytics({ - provider: 'advRed', - options: { - url: custom_endpoint, - publisherId: '1234567890' - } - }); - - expect(advRedAnalytics.getOptions().url).to.equal(custom_endpoint); - }); - - it('bid won event', function() { - const publisherId = '1234567890'; - advRedAnalytics.enableAnalytics({ - provider: 'advRed', - options: { - publisherId: publisherId - } - }); - - events.emit(EVENTS.BID_WON, bidWonEvent); - advRedAnalytics.sendEvents(); - - expect(server.requests.length).to.equal(1); - expect(server.requests[0].url).to.equal('https://api.adv.red/api/event'); - - const message = JSON.parse(server.requests[0].requestBody); - expect(message.pwId).to.exist; - expect(message.publisherId).to.equal(publisherId); - expect(message.events.length).to.equal(1); - expect(message.events[0].eventType).to.equal('bidWon'); - expect(message.events[0].ad).to.be.undefined; - expect(message.events[0].adUrl).to.be.undefined; - }); - - it('track event', function () { - sinon.spy(advRedAnalytics, 'track'); - - advRedAnalytics.enableAnalytics({ - provider: 'advRed', - options: { - publisherId: '1234567890' - } - }); - - expectEvents().to.beTrackedBy(advRedAnalytics.track); - }); - }); - - describe('pageUrl detection', function () { - afterEach(function () { - advRedAnalytics.disableAnalytics() - }); - it('check pageUrl property', function () { - advRedAnalytics.enableAnalytics({ - provider: 'advRed', - options: { - publisherId: '1234567890' - } - }); - - const message = JSON.parse(server.requests[0].requestBody); - expect(message.pageUrl).to.equal(window.top.location.href); - }); - }); -}); diff --git a/test/spec/modules/advangelistsBidAdapter_spec.js b/test/spec/modules/advangelistsBidAdapter_spec.js deleted file mode 100755 index 4a01d3759..000000000 --- a/test/spec/modules/advangelistsBidAdapter_spec.js +++ /dev/null @@ -1,117 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/advangelistsBidAdapter'; -import { BANNER, VIDEO } from 'src/mediaTypes'; - -describe('advangelistsBidAdapter', function () { - let bidRequests; - let bidRequestsVid; - - beforeEach(function () { - bidRequests = [{'bidder': 'advangelists', 'params': {'pubid': '0cf8d6d643e13d86a5b6374148a4afac', 'placement': 1234}, 'crumbs': {'pubcid': '979fde13-c71e-4ac2-98b7-28c90f99b449'}, 'mediaTypes': {'banner': {'sizes': [[300, 250]]}}, 'adUnitCode': 'div-gpt-ad-1460505748561-0', 'transactionId': 'f72931e6-2b0e-4e37-a2bc-1ea912141f81', 'sizes': [[300, 250]], 'bidId': '2aa73f571eaf29', 'bidderRequestId': '1bac84515a7af3', 'auctionId': '5dbc60fa-1aa1-41ce-9092-e6bbd4d478f7', 'src': 'client', 'bidRequestsCount': 1, 'pageurl': 'http://google.com'}]; - - bidRequestsVid = [{'bidder': 'advangelists', 'params': {'pubid': '8537f00948fc37cc03c5f0f88e198a76', 'placement': 1234}, 'crumbs': {'pubcid': '979fde13-c71e-4ac2-98b7-28c90f99b449'}, 'mediaTypes': {'video': {'playerSize': [[320, 480]], 'context': 'instream', 'skip': 1, 'mimes': ['video/mp4', 'application/javascript'], 'playbackmethod': [2, 6], 'maxduration': 30}}, 'adUnitCode': 'video1', 'transactionId': '8b060952-93f7-4863-af44-bb8796b97c42', 'sizes': [], 'bidId': '25c6ab92aa0e81', 'bidderRequestId': '1d420b73a013fc', 'auctionId': '9a69741c-34fb-474c-83e1-cfa003aaee17', 'src': 'client', 'bidRequestsCount': 1, 'pageurl': 'http://google.com'}]; - }); - - describe('spec.isBidRequestValid', function () { - it('should return true when the required params are passed for banner', function () { - const bidRequest = bidRequests[0]; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true when the required params are passed for video', function () { - const bidRequests = bidRequestsVid[0]; - expect(spec.isBidRequestValid(bidRequests)).to.equal(true); - }); - - it('should return false when no pub id params are passed', function () { - const bidRequest = bidRequests[0]; - bidRequest.params.pubid = ''; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false when no placement params are passed', function () { - const bidRequest = bidRequests[0]; - bidRequest.params.placement = ''; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false when a bid request is not passed', function () { - expect(spec.isBidRequestValid()).to.equal(false); - expect(spec.isBidRequestValid({})).to.equal(false); - }); - }); - - describe('spec.buildRequests', function () { - it('should create a POST request for each bid', function () { - const bidRequest = bidRequests[0]; - const requests = spec.buildRequests([ bidRequest ], { timeout: 1000 }); - expect(requests[0].method).to.equal('POST'); - }); - - it('should create a POST request for each bid in video request', function () { - const bidRequest = bidRequestsVid[0]; - const requests = spec.buildRequests([ bidRequest ], { timeout: 1000 }); - expect(requests[0].method).to.equal('POST'); - }); - - it('should have domain in request', function () { - const bidRequest = bidRequests[0]; - const requests = spec.buildRequests([ bidRequest ], { timeout: 1000 }); - expect(requests[0].data.site.domain).to.have.length.above(0); - }); - }); - - describe('spec.interpretResponse', function () { - describe('for banner bids', function () { - it('should return valid video bid responses', function () { - const _mediaTypes = VIDEO; - const advangelistsbidreqVid = {'bidRequest': {'mediaTypes': {'video': {'w': 320, 'h': 480}}}}; - const serverResponseVid = {'cur': 'USD', 'id': '25c6ab92aa0e81', 'seatbid': [{'seat': '3', 'bid': [{'crid': '1855', 'h': 480, 'protocol': 2, 'nurl': 'http://nep.advangelists.com/xp/evt?pp=1MO1wiaMhhq7wLRzZZwwwPkJxxKpYEnM5k5MH4qSGm1HR8rp3Nl7vDocvzZzSAvE4pnREL9mQ1kf5PDjk6E8em6DOk7vVrYUH1TYQyqCucd58PFpJNN7h30RXKHHFg3XaLuQ3PKfMuI1qZATBJ6WHcu875y0hqRdiewn0J4JsCYF53M27uwmcV0HnQxARQZZ72mPqrW95U6wgkZljziwKrICM3aBV07TU6YK5R5AyzJRuD6mtrQ2xtHlQ3jXVYKE5bvWFiUQd90t0jOGhPtYBNoOfP7uQ4ZZj4pyucxbr96orHe9PSOn9UpCSWArdx7s8lOfDpwOvbMuyGxynbStDWm38sDgd4bMHnIt762m5VMDNJfiUyX0vWzp05OsufJDVEaWhAM62i40lQZo7mWP4ipoOWLkmlaAzFIMsTcNaHAHiKKqGEOZLkCEhFNM0SLcvgN2HFRULOOIZvusq7TydOKxuXgCS91dLUDxDDDFUK83BFKlMkTxnCzkLbIR1bd9GKcr1TRryOrulyvRWAKAIhEsUzsc5QWFUhmI2dZ1eqnBQJ0c89TaPcnoaP2WipF68UgyiOstf2CBy0M34858tC5PmuQwQYwXscg6zyqDwR0i9MzGH4FkTyU5yeOlPcsA0ht6UcoCdFpHpumDrLUwAaxwGk1Nj8S6YlYYT5wNuTifDGbg22QKXzZBkUARiyVvgPn9nRtXnrd7WmiMYq596rya9RQj7LC0auQW8bHVQLEe49shsZDnAwZTWr4QuYKqgRGZcXteG7RVJe0ryBZezOq11ha9C0Lv0siNVBahOXE35Wzoq4c4BDaGpqvhaKN7pjeWLGlQR04ufWekwxiMWAvjmfgAfexBJ7HfbYNZpq__', 'adid': '61_1855', 'adomain': ['chevrolet.com'], 'price': 2, 'w': 320, 'iurl': 'https://daf37cpxaja7f.cloudfront.net/c61/creative_url_14922301369663_1.png', 'cat': ['IAB2'], 'id': '7f570b40-aca1-4806-8ea8-818ea679c82b_0', 'attr': [], 'impid': '0', 'cid': '61'}]}], 'bidid': '7f570b40-aca1-4806-8ea8-818ea679c82b'}; - const bidResponseVid = spec.interpretResponse({ body: serverResponseVid }, advangelistsbidreqVid); - delete bidResponseVid['vastUrl']; - delete bidResponseVid['ad']; - expect(bidResponseVid).to.deep.equal({ - requestId: bidRequestsVid[0].bidId, - creativeId: serverResponseVid.seatbid[0].bid[0].crid, - cpm: serverResponseVid.seatbid[0].bid[0].price, - width: serverResponseVid.seatbid[0].bid[0].w, - height: serverResponseVid.seatbid[0].bid[0].h, - mediaType: 'video', - meta: { 'advertiserDomains': serverResponseVid.seatbid[0].bid[0].adomain }, - currency: 'USD', - netRevenue: true, - ttl: 60 - }); - }); - - it('should return valid banner bid responses', function () { - const advangelistsbidreq = {bids: {}}; - bidRequests.forEach(bid => { - const _mediaTypes = (bid.mediaTypes && bid.mediaTypes.video ? VIDEO : BANNER); - advangelistsbidreq.bids[bid.bidId] = {mediaTypes: _mediaTypes, - w: _mediaTypes === BANNER ? bid.mediaTypes[_mediaTypes].sizes[0][0] : bid.mediaTypes[_mediaTypes].playerSize[0], - h: _mediaTypes === BANNER ? bid.mediaTypes[_mediaTypes].sizes[0][1] : bid.mediaTypes[_mediaTypes].playerSize[1] - - }; - }); - const serverResponse = {'id': '2aa73f571eaf29', 'seatbid': [{'bid': [{'id': '2c5e8a1a84522d', 'impid': '2c5e8a1a84522d', 'price': 0.81, 'adid': 'abcde-12345', 'nurl': '', 'adm': '
', 'iurl': '', 'cid': 'campaign1', 'crid': 'abcde-12345', 'adomain': ['chevrolet.com'], 'w': 300, 'h': 250}], 'seat': '19513bcfca8006'}], 'bidid': '19513bcfca8006', 'cur': 'USD', 'w': 300, 'h': 250}; - - const bidResponse = spec.interpretResponse({ body: serverResponse }, advangelistsbidreq); - expect(bidResponse).to.deep.equal({ - requestId: bidRequests[0].bidId, - ad: serverResponse.seatbid[0].bid[0].adm, - bidderCode: 'advangelists', - creativeId: serverResponse.seatbid[0].bid[0].crid, - cpm: serverResponse.seatbid[0].bid[0].price, - width: serverResponse.seatbid[0].bid[0].w, - height: serverResponse.seatbid[0].bid[0].h, - mediaType: 'banner', - meta: { 'advertiserDomains': serverResponse.seatbid[0].bid[0].adomain }, - currency: 'USD', - netRevenue: true, - ttl: 60 - }); - }); - }); - }); -}); diff --git a/test/spec/modules/advertisingBidAdapter_spec.js b/test/spec/modules/advertisingBidAdapter_spec.js deleted file mode 100644 index d9067f638..000000000 --- a/test/spec/modules/advertisingBidAdapter_spec.js +++ /dev/null @@ -1,1544 +0,0 @@ -import { assert, expect } from 'chai'; -import { BANNER } from 'src/mediaTypes.js'; -import { config } from 'src/config.js'; -import { spec } from 'modules/advertisingBidAdapter.js'; -import * as utils from 'src/utils.js'; - -describe('advertisingBidAdapter ', function () { - describe('isBidRequestValid', function () { - let bid; - beforeEach(function () { - bid = { - sizes: [300, 250], - params: { - seatId: 'prebid', - tagId: '1234' - } - }; - }); - - it('should return true when params placementId and seatId are truthy', function () { - bid.params.placementId = bid.params.tagId; - delete bid.params.tagId; - assert(spec.isBidRequestValid(bid)); - }); - - it('should return true when params tagId and seatId are truthy', function () { - delete bid.params.placementId; - assert(spec.isBidRequestValid(bid)); - }); - - it('should return false when sizes are missing', function () { - delete bid.sizes; - assert.isFalse(spec.isBidRequestValid(bid)); - }); - - it('should return false when the only size is unwanted', function () { - bid.sizes = [[1, 1]]; - assert.isFalse(spec.isBidRequestValid(bid)); - }); - - it('should return false when seatId param is missing', function () { - delete bid.params.seatId; - assert.isFalse(spec.isBidRequestValid(bid)); - }); - - it('should return false when both placementId param and tagId param are missing', function () { - delete bid.params.placementId; - delete bid.params.tagId; - assert.isFalse(spec.isBidRequestValid(bid)); - }); - - it('should return false when params is missing or null', function () { - assert.isFalse(spec.isBidRequestValid({ params: null })); - assert.isFalse(spec.isBidRequestValid({})); - assert.isFalse(spec.isBidRequestValid(null)); - }); - }); - - describe('impression type', function () { - const nonVideoReq = { - bidId: '9876abcd', - sizes: [[300, 250], [300, 600]], - params: { - seatId: 'prebid', - tagId: '1234', - bidfloor: '0.50' - } - }; - - const bannerReq = { - bidId: '9876abcd', - sizes: [[300, 250], [300, 600]], - params: { - seatId: 'prebid', - tagId: '1234', - bidfloor: '0.50' - }, - mediaTypes: { - banner: { - format: [ - { - w: 300, - h: 600 - } - ], - pos: 0 - } - }, - }; - - const videoReq = { - bidId: '9876abcd', - sizes: [[640, 480]], - params: { - seatId: 'prebid', - tagId: '1234', - bidfloor: '0.50' - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [ - [ - 640, - 480 - ] - ] - } - }, - }; - it('should return correct impression type video/banner', function () { - assert.isFalse(spec.isVideoBid(nonVideoReq)); - assert.isFalse(spec.isVideoBid(bannerReq)); - assert.isTrue(spec.isVideoBid(videoReq)); - }); - }); - describe('buildRequests', function () { - const validBidRequestVideo = { - bidder: 'advertising', - params: { - seatId: 'prebid', - tagId: '1234', - video: { - minduration: 30 - } - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [[640, 480]] - } - }, - adUnitCode: 'video1', - transactionId: '93e5def8-29aa-4fe8-bd3a-0298c39f189a', - sizes: [[640, 480]], - bidId: '2624fabbb078e8', - bidderRequestId: '117954d20d7c9c', - auctionId: 'defd525f-4f1e-4416-a4cb-ae53be90e706', - src: 'client', - bidRequestsCount: 1 - }; - - const bidderRequestVideo = { - bidderCode: 'advertising', - auctionId: 'VideoAuctionId124', - bidderRequestId: '117954d20d7c9c', - auctionStart: 1553624929697, - timeout: 700, - refererInfo: { - referer: 'https://localhost:9999/test/pages/video.html?pbjs_debug=true', - reachedTop: true, - numIframes: 0, - stack: ['https://localhost:9999/test/pages/video.html?pbjs_debug=true'] - }, - start: 1553624929700 - }; - - bidderRequestVideo.bids = validBidRequestVideo; - const expectedDataVideo1 = { - id: 'v2624fabbb078e8-640x480', - tagid: '1234', - video: { - w: 640, - h: 480, - pos: 0, - minduration: 30 - } - }; - - const validBidRequest = { - bidId: '9876abcd', - sizes: [[300, 250], [300, 600]], - params: { - seatId: 'prebid', - tagId: '1234', - bidfloor: '0.50' - } - }; - - const bidderRequest = { - bidderRequestId: 'xyz123', - refererInfo: { - referer: 'https://test.com/foo/bar' - } - }; - - const bidderRequestWithTimeout = { - auctionId: 'xyz123', - refererInfo: { - referer: 'https://test.com/foo/bar' - }, - timeout: 3000 - }; - - const bidderRequestWithUSPInExt = { - bidderRequestId: 'xyz123', - refererInfo: { - referer: 'https://test.com/foo/bar' - }, - ortb2: { - regs: { - ext: { - us_privacy: '1YYY' - } - } - } - }; - - const bidderRequestWithUSPInRegs = { - bidderRequestId: 'xyz123', - refererInfo: { - referer: 'https://test.com/foo/bar' - }, - ortb2: { - regs: { - us_privacy: '1YYY' - } - } - }; - - const bidderRequestWithUSPAndOthersInExt = { - bidderRequestId: 'xyz123', - refererInfo: { - referer: 'https://test.com/foo/bar' - }, - ortb2: { - regs: { - ext: { - extra: 'extra item', - us_privacy: '1YYY' - } - } - } - }; - - const validBidRequestWithUserIds = { - bidId: '9876abcd', - sizes: [[300, 250], [300, 600]], - params: { - seatId: 'prebid', - tagId: '1234', - bidfloor: '0.50' - }, - userIdAsEids: [ - { - source: 'pubcid.org', - uids: [{ - id: 'cid0032l2344jskdsl3', - atype: 1 - }] - }, - { - source: 'liveramp.com', - uids: [{ - id: 'lrv39010k42dl', - atype: 1, - ext: { - rtiPartner: 'TDID' - } - }] - }, - { - source: 'neustar.biz', - uids: [{ - id: 'neustar809-044-23njhwer3', - atype: 1 - }] - } - ] - }; - - const expectedEids = [ - { - source: 'pubcid.org', - uids: [{ - id: 'cid0032l2344jskdsl3', - atype: 1 - }] - }, - { - source: 'liveramp.com', - uids: [{ - id: 'lrv39010k42dl', - atype: 1, - ext: { - rtiPartner: 'TDID' - } - }] - }, - { - source: 'neustar.biz', - uids: [{ - id: 'neustar809-044-23njhwer3', - atype: 1 - }] - } - ]; - - const expectedDataImp1 = { - banner: { - format: [ - { - h: 250, - w: 300 - }, - { - h: 600, - w: 300 - } - ], - pos: 0 - }, - id: 'b9876abcd', - tagid: '1234', - bidfloor: 0.5 - }; - - it('should return valid request when valid bids are used', function () { - // banner test - const req = spec.buildRequests([validBidRequest], bidderRequest); - expect(req).be.an('object'); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?'); - expect(req.data).to.exist.and.to.be.an('object'); - expect(req.data.id).to.equal('xyz123'); - expect(req.data.imp).to.eql([expectedDataImp1]); - - // video test - const reqVideo = spec.buildRequests([validBidRequestVideo], bidderRequestVideo); - expect(reqVideo).be.an('object'); - expect(reqVideo).to.have.property('method', 'POST'); - expect(reqVideo).to.have.property('url'); - expect(reqVideo.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?'); - expect(reqVideo.data).to.exist.and.to.be.an('object'); - expect(reqVideo.data.imp).to.eql([expectedDataVideo1]); - }); - - it('should return no tmax', function () { - const req = spec.buildRequests([validBidRequest], bidderRequest); - expect(req.data).to.not.have.property('tmax'); - }); - - it('should return tmax equal to callback timeout', function () { - const req = spec.buildRequests([validBidRequest], bidderRequestWithTimeout); - expect(req.data.tmax).to.eql(bidderRequestWithTimeout.timeout); - }); - - it('should return multiple bids when multiple valid requests with the same seatId are used', function () { - const secondBidRequest = { - bidId: 'foobar', - sizes: [[300, 600]], - params: { - seatId: validBidRequest.params.seatId, - tagId: '5678', - bidfloor: '0.50' - } - }; - const req = spec.buildRequests([validBidRequest, secondBidRequest], bidderRequest); - expect(req).to.exist.and.be.an('object'); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?'); - expect(req.data.id).to.equal('xyz123'); - expect(req.data.imp).to.eql([expectedDataImp1, { - banner: { - format: [ - { - h: 600, - w: 300 - } - ], - pos: 0 - }, - id: 'bfoobar', - tagid: '5678', - bidfloor: 0.5 - }]); - }); - - it('should return only first bid when different seatIds are used', function () { - const mismatchedSeatBidRequest = { - bidId: 'foobar', - sizes: [[300, 250]], - params: { - seatId: 'somethingelse', - tagId: '5678', - bidfloor: '0.50' - } - }; - const req = spec.buildRequests([mismatchedSeatBidRequest, validBidRequest], bidderRequest); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('https://somethingelse.technoratimedia.com/openrtb/bids/somethingelse?'); - expect(req.data.id).to.equal('xyz123'); - expect(req.data.imp).to.eql([ - { - banner: { - format: [ - { - h: 250, - w: 300 - } - ], - pos: 0 - }, - id: 'bfoobar', - tagid: '5678', - bidfloor: 0.5 - } - ]); - }); - - it('should not use bidfloor when the value is not a number', function () { - const badFloorBidRequest = { - bidId: '9876abcd', - sizes: [[300, 250]], - params: { - seatId: 'prebid', - tagId: '1234', - bidfloor: 'abcd' - } - }; - const req = spec.buildRequests([badFloorBidRequest], bidderRequest); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?src=pbjs%2F$prebid.version$'); - expect(req.data.id).to.equal('xyz123'); - expect(req.data.imp).to.eql([ - { - banner: { - format: [ - { - h: 250, - w: 300 - } - ], - pos: 0 - }, - id: 'b9876abcd', - tagid: '1234', - } - ]); - }); - - it('should not use bidfloor when there is no value', function () { - const badFloorBidRequest = { - bidId: '9876abcd', - sizes: [[300, 250]], - params: { - seatId: 'prebid', - tagId: '1234' - } - }; - const req = spec.buildRequests([badFloorBidRequest], bidderRequest); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?src=pbjs%2F$prebid.version$'); - expect(req.data.id).to.equal('xyz123'); - expect(req.data.imp).to.eql([ - { - banner: { - format: [ - { - h: 250, - w: 300 - } - ], - pos: 0 - }, - id: 'b9876abcd', - tagid: '1234', - } - ]); - }); - - it('should use the pos given by the bid request', function () { - const newPosBidRequest = { - bidId: '9876abcd', - sizes: [[300, 250]], - params: { - seatId: 'prebid', - tagId: '1234', - pos: 1 - } - }; - const req = spec.buildRequests([newPosBidRequest], bidderRequest); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?src=pbjs%2F$prebid.version$'); - expect(req.data.id).to.equal('xyz123'); - expect(req.data.imp).to.eql([ - { - banner: { - format: [ - { - h: 250, - w: 300 - } - ], - pos: 1 - }, - id: 'b9876abcd', - tagid: '1234' - } - ]); - }); - - it('should use the default pos if none in bid request', function () { - const newPosBidRequest = { - bidId: '9876abcd', - sizes: [[300, 250]], - params: { - seatId: 'prebid', - tagId: '1234', - } - }; - const req = spec.buildRequests([newPosBidRequest], bidderRequest); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?src=pbjs%2F$prebid.version$'); - expect(req.data.id).to.equal('xyz123'); - expect(req.data.imp).to.eql([ - { - banner: { - format: [ - { - h: 250, - w: 300 - } - ], - pos: 0 - }, - id: 'b9876abcd', - tagid: '1234' - } - ]); - }); - it('should not return a request when no valid bid request used', function () { - expect(spec.buildRequests([], bidderRequest)).to.be.undefined; - expect(spec.buildRequests([validBidRequest], null)).to.be.undefined; - }); - - it('should return empty impression when there is no valid sizes in bidrequest', function () { - const validBidReqWithoutSize = { - bidId: '9876abcd', - sizes: [], - params: { - seatId: 'prebid', - tagId: '1234', - bidfloor: '0.50' - } - }; - - const validBidReqInvalidSize = { - bidId: '9876abcd', - sizes: [[300]], - params: { - seatId: 'prebid', - tagId: '1234', - bidfloor: '0.50' - } - }; - - const bidderRequest = { - auctionId: 'xyz123', - refererInfo: { - referer: 'https://test.com/foo/bar' - } - }; - - let req = spec.buildRequests([validBidReqWithoutSize], bidderRequest); - assert.isUndefined(req); - req = spec.buildRequests([validBidReqInvalidSize], bidderRequest); - assert.isUndefined(req); - }); - it('should use all the video params in the impression request', function () { - const validBidRequestVideo = { - bidder: 'advertising', - params: { - seatId: 'prebid', - tagId: '1234', - video: { - minduration: 30, - maxduration: 45, - startdelay: 1, - linearity: 1, - plcmt: 1, - mimes: ['video/mp4'], - protocols: [1], - api: 1 - } - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [[640, 480]] - } - }, - adUnitCode: 'video1', - transactionId: '93e5def8-29aa-4fe8-bd3a-0298c39f189a', - sizes: [[640, 480]], - bidId: '2624fabbb078e8', - bidderRequestId: '117954d20d7c9c', - auctionId: 'defd525f-4f1e-4416-a4cb-ae53be90e706', - src: 'client', - bidRequestsCount: 1 - }; - - const req = spec.buildRequests([validBidRequestVideo], bidderRequest); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?src=pbjs%2F$prebid.version$'); - expect(req.data.id).to.equal('xyz123'); - expect(req.data.imp).to.eql([ - { - video: { - h: 480, - pos: 0, - w: 640, - minduration: 30, - maxduration: 45, - startdelay: 1, - linearity: 1, - plcmt: 1, - mimes: ['video/mp4'], - protocols: [1], - api: 1 - }, - id: 'v2624fabbb078e8-640x480', - tagid: '1234', - } - ]); - }); - it('should move any video params in the mediaTypes object to params.video object', function () { - const validBidRequestVideo = { - bidder: 'advertising', - params: { - seatId: 'prebid', - tagId: '1234', - video: { - minduration: 30, - maxduration: 45, - protocols: [1], - api: 1 - } - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [[640, 480]], - startdelay: 1, - linearity: 1, - plcmt: 1, - mimes: ['video/mp4'] - } - }, - adUnitCode: 'video1', - transactionId: '93e5def8-29aa-4fe8-bd3a-0298c39f189a', - sizes: [[640, 480]], - bidId: '2624fabbb078e8', - bidderRequestId: '117954d20d7c9c', - auctionId: 'defd525f-4f1e-4416-a4cb-ae53be90e706', - src: 'client', - bidRequestsCount: 1 - }; - - const req = spec.buildRequests([validBidRequestVideo], bidderRequest); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?src=pbjs%2F$prebid.version$'); - expect(req.data.id).to.equal('xyz123'); - expect(req.data.imp).to.eql([ - { - video: { - h: 480, - pos: 0, - w: 640, - minduration: 30, - maxduration: 45, - startdelay: 1, - linearity: 1, - plcmt: 1, - mimes: ['video/mp4'], - protocols: [1], - api: 1 - }, - id: 'v2624fabbb078e8-640x480', - tagid: '1234', - } - ]); - }); - it('should create params.video object if not present on bid request and move any video params in the mediaTypes object to it', function () { - const validBidRequestVideo = { - bidder: 'advertising', - params: { - seatId: 'prebid', - tagId: '1234' - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [[ 640, 480 ]], - startdelay: 1, - linearity: 1, - plcmt: 1, - mimes: ['video/mp4'] - } - }, - adUnitCode: 'video1', - transactionId: '93e5def8-29aa-4fe8-bd3a-0298c39f189a', - sizes: [[ 640, 480 ]], - bidId: '2624fabbb078e8', - bidderRequestId: '117954d20d7c9c', - auctionId: 'defd525f-4f1e-4416-a4cb-ae53be90e706', - src: 'client', - bidRequestsCount: 1 - }; - - const req = spec.buildRequests([validBidRequestVideo], bidderRequest); - expect(req.data.imp).to.eql([ - { - video: { - h: 480, - pos: 0, - w: 640, - startdelay: 1, - linearity: 1, - plcmt: 1, - mimes: ['video/mp4'] - }, - id: 'v2624fabbb078e8-640x480', - tagid: '1234', - } - ]); - }); - it('should have us_privacy string in regs instead of regs.ext bidder request', function () { - const req = spec.buildRequests([validBidRequest], bidderRequestWithUSPInExt); - expect(req).be.an('object'); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?'); - expect(req.data).to.exist.and.to.be.an('object'); - expect(req.data.id).to.equal('xyz123'); - expect(req.data.regs.us_privacy).to.equal('1YYY'); - expect(req.data.regs.ext).to.not.exist; - expect(req.data.imp).to.eql([expectedDataImp1]); - }); - it('should accept us_privacy string in regs', function () { - // banner test - const req = spec.buildRequests([validBidRequest], bidderRequestWithUSPInRegs); - expect(req).be.an('object'); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?'); - expect(req.data).to.exist.and.to.be.an('object'); - expect(req.data.id).to.equal('xyz123'); - expect(req.data.regs.us_privacy).to.equal('1YYY'); - expect(req.data.regs.ext).to.not.exist; - expect(req.data.imp).to.eql([expectedDataImp1]); - }); - it('should not remove regs.ext when moving us_privacy if there are other things in regs.ext', function () { - // banner test - const req = spec.buildRequests([validBidRequest], bidderRequestWithUSPAndOthersInExt); - expect(req).be.an('object'); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?'); - expect(req.data).to.exist.and.to.be.an('object'); - expect(req.data.id).to.equal('xyz123'); - expect(req.data.regs.us_privacy).to.equal('1YYY'); - expect(req.data.regs.ext.extra).to.equal('extra item'); - expect(req.data.imp).to.eql([expectedDataImp1]); - }); - it('should contain user object when user ids are present in the bidder request', function () { - const req = spec.buildRequests([validBidRequestWithUserIds], bidderRequest); - expect(req).be.an('object'); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('https://prebid.technoratimedia.com/openrtb/bids/prebid?'); - expect(req.data).to.exist.and.to.be.an('object'); - expect(req.data.id).to.equal('xyz123'); - expect(req.data.user).be.an('object'); - expect(req.data.user).to.have.property('ext'); - expect(req.data.user.ext).to.have.property('eids'); - expect(req.data.user.ext.eids).to.eql(expectedEids); - expect(req.data.imp).to.eql([expectedDataImp1]); - }); - }); - - describe('Bid Requests with placementId should be backward compatible ', function () { - const validVideoBidReq = { - bidder: 'advertising', - params: { - seatId: 'prebid', - placementId: 'demo1', - pos: 1, - video: {} - }, - renderer: { - url: '../syncOutstreamPlayer.js' - }, - mediaTypes: { - video: { - playerSize: [[300, 250]], - context: 'outstream' - } - }, - adUnitCode: 'div-1', - transactionId: '0869f34e-090b-4b20-84ee-46ff41405a39', - sizes: [[300, 250]], - bidId: '22b3a2268d9f0e', - bidderRequestId: '1d195910597e13', - auctionId: '3375d336-2aea-4ee7-804c-6d26b621ad20', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }; - - const validBannerBidRequest = { - bidId: '9876abcd', - sizes: [[300, 250]], - params: { - seatId: 'prebid', - placementId: '1234', - } - }; - - const bidderRequest = { - refererInfo: { - referer: 'http://localhost:9999/' - }, - bidderCode: 'advertising', - auctionId: 'f8a75621-d672-4cbb-9275-3db7d74fb110' - }; - - it('should return valid bid request for banner impression', function () { - const req = spec.buildRequests([validBannerBidRequest], bidderRequest); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('//prebid.technoratimedia.com/openrtb/bids/prebid?src=pbjs%2F$prebid.version$'); - }); - - it('should return valid bid request for video impression', function () { - const req = spec.buildRequests([validVideoBidReq], bidderRequest); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('//prebid.technoratimedia.com/openrtb/bids/prebid?src=pbjs%2F$prebid.version$'); - }); - }); - - describe('Bid Requests with schain object ', function () { - const validBidReq = { - bidder: 'advertising', - params: { - seatId: 'prebid', - tagId: 'demo1', - pos: 1, - video: {} - }, - renderer: { - url: '../syncOutstreamPlayer.js' - }, - mediaTypes: { - video: { - playerSize: [[300, 250]], - context: 'outstream' - } - }, - adUnitCode: 'div-1', - transactionId: '0869f34e-090b-4b20-84ee-46ff41405a39', - sizes: [[300, 250]], - bidId: '22b3a2268d9f0e', - bidderRequestId: '1d195910597e13', - auctionId: '3375d336-2aea-4ee7-804c-6d26b621ad20', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'indirectseller.com', - sid: '00001', - hp: 1 - } - ] - } - } - } - } - }; - const bidderRequest = { - refererInfo: { - referer: 'http://localhost:9999/' - }, - bidderCode: 'advertising', - auctionId: 'f8a75621-d672-4cbb-9275-3db7d74fb110', - bidderRequestId: '16d438671bfbec', - bids: [ - { - bidder: 'advertising', - params: { - seatId: 'prebid', - tagId: 'demo1', - pos: 1, - video: {} - }, - renderer: { - url: '../syncOutstreamPlayer.js' - }, - mediaTypes: { - video: { - playerSize: [[300, 250]], - context: 'outstream' - } - }, - adUnitCode: 'div-1', - sizes: [[300, 250]], - bidId: '211c0236bb8f4e', - bidderRequestId: '16d438671bfbec', - auctionId: 'f8a75621-d672-4cbb-9275-3db7d74fb110', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'indirectseller.com', - sid: '00001', - hp: 1 - } - ] - } - } - ], - auctionStart: 1580310345205, - timeout: 1000, - start: 1580310345211 - }; - - it('should return valid bid request with schain object', function () { - const req = spec.buildRequests([validBidReq], bidderRequest); - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url'); - expect(req.url).to.contain('//prebid.technoratimedia.com/openrtb/bids/prebid?src=pbjs%2F$prebid.version$'); - expect(req.data).to.have.property('source'); - expect(req.data.source).to.have.property('ext'); - expect(req.data.source.ext).to.have.property('schain'); - }); - }); - - describe('interpretResponse', function () { - let bidResponse = { - id: '10865933907263896~9998~0', - impid: 'b9876abcd', - price: 0.13, - crid: '1022-250', - adm: '', - nurl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=k5JkFVQ1RJT05fSU1QX0lEPXYyZjczN&AUCTION_PRICE=${AUCTION_PRICE}', - w: 300, - h: 250 - }; - const bidResponse2 = { - id: '10865933907263800~9999~0', - impid: 'b9876abcd', - price: 1.99, - crid: '9993-013', - adm: '', - nurl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=OTk5OX4wJkFVQ1RJT05fU0VBVF9JR&AUCTION_PRICE=${AUCTION_PRICE}', - w: 300, - h: 600 - }; - - let bidRequest = { - data: { - id: '', - imp: [ - { - id: 'abc123', - banner: { - format: [ - { - w: 400, - h: 350 - } - ], - pos: 1 - } - } - ], - }, - method: 'POST', - options: { - contentType: 'application/json', - withCredentials: true - }, - url: 'https://prebid.technoratimedia.com/openrtb/bids/prebid?src=prebid_prebid_3.27.0-pre' - }; - let serverResponse; - beforeEach(function () { - serverResponse = { - body: { - id: 'abc123', - seatbid: [{ - seat: '9998', - bid: [], - }] - } - }; - }); - - it('should return 1 video bid when 1 bid is in the video response', function () { - bidRequest = { - data: { - id: 'abcd1234', - imp: [ - { - video: { - w: 640, - h: 480 - }, - id: 'v2da7322b2df61f' - } - ] - }, - method: 'POST', - options: { - contentType: 'application/json', - withCredentials: true - }, - url: 'https://prebid.technoratimedia.com/openrtb/bids/prebid?src=prebid_prebid_3.27.0-pre' - }; - const serverRespVideo = { - body: { - id: 'abcd1234', - seatbid: [ - { - bid: [ - { - id: '11339128001692337~9999~0', - impid: 'v2da7322b2df61f', - price: 0.45, - nurl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=${AUCTION_PRICE}', - adm: '\n\n\n\nSynacor Media Ad Server - 9999\nhttps://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=${AUCTION_PRICE}\n\n\n', - adomain: ['psacentral.org'], - cid: 'bidder-crid', - crid: 'bidder-cid', - cat: [], - w: 640, - h: 480 - } - ], - seat: '9999' - } - ] - } - }; - - // serverResponse.body.seatbid[0].bid.push(bidResponse); - const resp = spec.interpretResponse(serverRespVideo, bidRequest); - expect(resp).to.be.an('array').to.have.lengthOf(1); - expect(resp[0]).to.eql({ - requestId: '2da7322b2df61f', - cpm: 0.45, - width: 640, - height: 480, - creativeId: '9999_bidder-cid', - currency: 'USD', - netRevenue: true, - mediaType: 'video', - ad: '\n\n\n\nSynacor Media Ad Server - 9999\nhttps://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=0.45\n\n\n', - ttl: 420, - meta: { advertiserDomains: ['psacentral.org'] }, - videoCacheKey: 'QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk', - vastUrl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=0.45' - }); - }); - - it('should return 1 bid when 1 bid is in the response', function () { - serverResponse.body.seatbid[0].bid.push(bidResponse); - const resp = spec.interpretResponse(serverResponse, bidRequest); - expect(resp).to.be.an('array').to.have.lengthOf(1); - expect(resp[0]).to.eql({ - requestId: '9876abcd', - cpm: 0.13, - width: 300, - height: 250, - creativeId: '9998_1022-250', - currency: 'USD', - netRevenue: true, - mediaType: BANNER, - ad: '', - ttl: 420 - }); - }); - - it('should return 2 bids when 2 bids are in the response', function () { - serverResponse.body.seatbid[0].bid.push(bidResponse); - serverResponse.body.seatbid.push({ - seat: '9999', - bid: [bidResponse2], - }); - const resp = spec.interpretResponse(serverResponse, bidRequest); - expect(resp).to.be.an('array').to.have.lengthOf(2); - expect(resp[0]).to.eql({ - requestId: '9876abcd', - cpm: 0.13, - width: 300, - height: 250, - creativeId: '9998_1022-250', - currency: 'USD', - netRevenue: true, - mediaType: BANNER, - ad: '', - ttl: 420 - }); - - expect(resp[1]).to.eql({ - requestId: '9876abcd', - cpm: 1.99, - width: 300, - height: 600, - creativeId: '9999_9993-013', - currency: 'USD', - netRevenue: true, - mediaType: BANNER, - ad: '', - ttl: 420 - }); - }); - - it('should not return a bid when no bid is in the response', function () { - const resp = spec.interpretResponse(serverResponse, bidRequest); - expect(resp).to.be.an('array').that.is.empty; - }); - - it('should not return a bid when there is no response body', function () { - expect(spec.interpretResponse({ body: null })).to.not.exist; - expect(spec.interpretResponse({ body: 'some error text' })).to.not.exist; - }); - - it('should not include videoCacheKey property on the returned response when cache url is present in the config', function () { - const sandbox = sinon.createSandbox(); - const serverRespVideo = { - body: { - id: 'abcd1234', - seatbid: [ - { - bid: [ - { - id: '11339128001692337~9999~0', - impid: 'v2da7322b2df61f', - price: 0.45, - nurl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=${AUCTION_PRICE}', - adm: '\n\n\n\nSynacor Media Ad Server - 9999\nhttps://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=${AUCTION_PRICE}\n\n\n', - adomain: ['psacentral.org'], - cid: 'bidder-crid', - crid: 'bidder-cid', - cat: [], - w: 640, - h: 480 - } - ], - seat: '9999' - } - ] - } - }; - - sandbox.stub(config, 'getConfig').callsFake(key => { - const config = { - 'cache.url': 'faKeCacheUrl' - }; - return config[key]; - }); - - const resp = spec.interpretResponse(serverRespVideo, bidRequest); - sandbox.restore(); - expect(resp[0].videoCacheKey).to.not.exist; - }); - - it('should use video bid request height and width if not present in response', function () { - bidRequest = { - data: { - id: 'abcd1234', - imp: [ - { - video: { - w: 300, - h: 250 - }, - id: 'v2da7322b2df61f' - } - ] - }, - method: 'POST', - options: { - contentType: 'application/json', - withCredentials: true - }, - url: 'https://prebid.technoratimedia.com/openrtb/bids/prebid?src=prebid_prebid_3.27.0-pre' - }; - - const serverRespVideo = { - body: { - id: 'abcd1234', - seatbid: [ - { - bid: [ - { - id: '11339128001692337~9999~0', - impid: 'v2da7322b2df61f', - price: 0.45, - nurl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=${AUCTION_PRICE}', - adm: '\n\n\n\nSynacor Media Ad Server - 9999\nhttps://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=${AUCTION_PRICE}\n\n\n', - adomain: ['psacentral.org'], - cid: 'bidder-crid', - crid: 'bidder-cid', - cat: [] - } - ], - seat: '9999' - } - ] - } - }; - const resp = spec.interpretResponse(serverRespVideo, bidRequest); - expect(resp).to.be.an('array').to.have.lengthOf(1); - expect(resp[0]).to.eql({ - requestId: '2da7322b2df61f', - cpm: 0.45, - width: 300, - height: 250, - creativeId: '9999_bidder-cid', - currency: 'USD', - netRevenue: true, - mediaType: 'video', - ad: '\n\n\n\nSynacor Media Ad Server - 9999\nhttps://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=0.45\n\n\n', - ttl: 420, - meta: { advertiserDomains: ['psacentral.org'] }, - videoCacheKey: 'QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk', - vastUrl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=QVVDVElPTl9JRD1lOTBhYWU1My1hZDkwLTRkNDEtYTQxMC1lZDY1MjIxMDc0ZGMmQVVDVElPTl9CSURfSUQ9MTEzMzkxMjgwMDE2OTIzMzd-OTk5OX4wJkFVQ1RJT05fU0VBVF9JRD05OTk5JkFVQ1RJT05fSU1QX0lEPXYyZGE3MzIyYjJkZjYxZi02NDB4NDgwJkFDVE9SX1JFRj1ha2thLnRjcDovL2F3cy1lYXN0MUBhZHMxMy5jYXAtdXNlMS5zeW5hY29yLmNvbToyNTUxL3VzZXIvJGNMYmZiIy0xOTk4NTIzNTk3JlNFQVRfSUQ9cHJlYmlk&AUCTION_PRICE=0.45' - }); - }); - - it('should use banner bid request height and width if not present in response', function () { - bidRequest = { - data: { - id: 'abc123', - imp: [ - { - banner: { - format: [{ - w: 400, - h: 350 - }] - }, - id: 'babc123' - } - ] - }, - method: 'POST', - options: { - contentType: 'application/json', - withCredentials: true - }, - url: 'https://prebid.technoratimedia.com/openrtb/bids/prebid?src=prebid_prebid_3.27.0-pre' - }; - - bidResponse = { - id: '10865933907263896~9998~0', - impid: 'babc123', - price: 0.13, - crid: '1022-250', - adm: '', - nurl: 'https://uat-net.technoratimedia.com/openrtb/tags?ID=k5JkFVQ1RJT05fSU1QX0lEPXYyZjczN&AUCTION_PRICE=${AUCTION_PRICE}', - }; - - serverResponse.body.seatbid[0].bid.push(bidResponse); - const resp = spec.interpretResponse(serverResponse, bidRequest); - expect(resp).to.be.an('array').to.have.lengthOf(1); - expect(resp[0]).to.eql({ - requestId: 'abc123', - cpm: 0.13, - width: 400, - height: 350, - creativeId: '9998_1022-250', - currency: 'USD', - netRevenue: true, - mediaType: BANNER, - ad: '', - ttl: 420 - }); - }); - - it('should return ttl equal to DEFAULT_TTL_MAX if bid.exp and bid.ext["imds.tv"].ttl are both undefined', function() { - const br = { ...bidResponse }; - serverResponse.body.seatbid[0].bid.push(br); - const resp = spec.interpretResponse(serverResponse, bidRequest); - expect(resp).to.be.an('array').to.have.lengthOf(1); - expect(resp[0]).to.have.property('ttl'); - expect(resp[0].ttl).to.equal(420); - }); - - it('should return ttl equal to bid.ext["imds.tv"].ttl if it is defined but bid.exp is undefined', function() { - const br = { ext: { 'imds.tv': { ttl: 4321 } }, ...bidResponse }; - serverResponse.body.seatbid[0].bid.push(br); - const resp = spec.interpretResponse(serverResponse, bidRequest); - expect(resp).to.be.an('array').to.have.lengthOf(1); - expect(resp[0]).to.have.property('ttl'); - expect(resp[0].ttl).to.equal(4321); - }); - - it('should return ttl equal to bid.exp if bid.exp is less than or equal to DEFAULT_TTL_MAX and bid.ext["imds.tv"].ttl is undefined', function() { - const br = { exp: 123, ...bidResponse }; - serverResponse.body.seatbid[0].bid.push(br); - const resp = spec.interpretResponse(serverResponse, bidRequest); - expect(resp).to.be.an('array').to.have.lengthOf(1); - expect(resp[0]).to.have.property('ttl'); - expect(resp[0].ttl).to.equal(123); - }); - - it('should return ttl equal to DEFAULT_TTL_MAX if bid.exp is greater than DEFAULT_TTL_MAX and bid.ext["imds.tv"].ttl is undefined', function() { - const br = { exp: 4321, ...bidResponse }; - serverResponse.body.seatbid[0].bid.push(br); - const resp = spec.interpretResponse(serverResponse, bidRequest); - expect(resp).to.be.an('array').to.have.lengthOf(1); - expect(resp[0]).to.have.property('ttl'); - expect(resp[0].ttl).to.equal(420); - }); - - it('should return ttl equal to bid.exp if bid.exp is less than or equal to bid.ext["imds.tv"].ttl', function() { - const br = { exp: 1234, ext: { 'imds.tv': { ttl: 4321 } }, ...bidResponse }; - serverResponse.body.seatbid[0].bid.push(br); - const resp = spec.interpretResponse(serverResponse, bidRequest); - expect(resp).to.be.an('array').to.have.lengthOf(1); - expect(resp[0]).to.have.property('ttl'); - expect(resp[0].ttl).to.equal(1234); - }); - - it('should return ttl equal to bid.ext["imds.tv"].ttl if bid.exp is greater than bid.ext["imds.tv"].ttl', function() { - const br = { exp: 4321, ext: { 'imds.tv': { ttl: 1234 } }, ...bidResponse }; - serverResponse.body.seatbid[0].bid.push(br); - const resp = spec.interpretResponse(serverResponse, bidRequest); - expect(resp).to.be.an('array').to.have.lengthOf(1); - expect(resp[0]).to.have.property('ttl'); - expect(resp[0].ttl).to.equal(1234); - }); - }); - describe('getUserSyncs', function () { - it('should return an iframe usersync when iframes is enabled', function () { - const usersyncs = spec.getUserSyncs({ - iframeEnabled: true - }, null); - expect(usersyncs).to.be.an('array').with.lengthOf(1); - expect(usersyncs[0]).to.have.property('type', 'iframe'); - expect(usersyncs[0]).to.have.property('url'); - expect(usersyncs[0].url).to.contain('https://ad-cdn.technoratimedia.com/html/usersync.html'); - }); - - it('should return an image usersync when pixels are enabled', function () { - const usersyncs = spec.getUserSyncs({ - pixelEnabled: true - }, null); - expect(usersyncs).to.be.an('array').with.lengthOf(1); - expect(usersyncs[0]).to.have.property('type', 'image'); - expect(usersyncs[0]).to.have.property('url'); - expect(usersyncs[0].url).to.contain('https://sync.technoratimedia.com/services'); - }); - - it('should return an iframe usersync when both iframe and pixel are enabled', function () { - const usersyncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, null); - expect(usersyncs).to.be.an('array').with.lengthOf(1); - expect(usersyncs[0]).to.have.property('type', 'iframe'); - expect(usersyncs[0]).to.have.property('url'); - expect(usersyncs[0].url).to.contain('https://ad-cdn.technoratimedia.com/html/usersync.html'); - }); - - it('should not return a usersync when neither iframes nor pixel are enabled', function () { - const usersyncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, null); - expect(usersyncs).to.be.an('array').that.is.empty; - }); - }); - - describe('Bid Requests with price module should use if available', function () { - const validVideoBidRequest = { - bidder: 'advertising', - params: { - bidfloor: '0.50', - seatId: 'prebid', - placementId: 'demo1', - pos: 1, - video: {} - }, - renderer: { - url: '../syncOutstreamPlayer.js' - }, - mediaTypes: { - video: { - playerSize: [[300, 250]], - context: 'outstream' - } - }, - adUnitCode: 'div-1', - transactionId: '0869f34e-090b-4b20-84ee-46ff41405a39', - sizes: [[300, 250]], - bidId: '22b3a2268d9f0e', - bidderRequestId: '1d195910597e13', - auctionId: '3375d336-2aea-4ee7-804c-6d26b621ad20', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }; - - const validBannerBidRequest = { - bidId: '9876abcd', - sizes: [[300, 250]], - params: { - bidfloor: '0.50', - seatId: 'prebid', - placementId: '1234', - } - }; - - const bidderRequest = { - refererInfo: { - referer: 'http://localhost:9999/' - }, - bidderCode: 'advertising', - auctionId: 'f8a75621-d672-4cbb-9275-3db7d74fb110' - }; - - it('should return valid bidfloor using price module for banner/video impression', function () { - let bannerRequest = spec.buildRequests([validBannerBidRequest], bidderRequest); - let videoRequest = spec.buildRequests([validVideoBidRequest], bidderRequest); - - expect(bannerRequest.data.imp[0].bidfloor).to.equal(0.5); - expect(videoRequest.data.imp[0].bidfloor).to.equal(0.5); - - const priceModuleFloor = 3; - const floorResponse = { currency: 'USD', floor: priceModuleFloor }; - - validBannerBidRequest.getFloor = () => { return floorResponse; }; - validVideoBidRequest.getFloor = () => { return floorResponse; }; - - bannerRequest = spec.buildRequests([validBannerBidRequest], bidderRequest); - videoRequest = spec.buildRequests([validVideoBidRequest], bidderRequest); - - expect(bannerRequest.data.imp[0].bidfloor).to.equal(priceModuleFloor); - expect(videoRequest.data.imp[0].bidfloor).to.equal(priceModuleFloor); - }); - }); - - describe('Bid Requests with gpid or anything in bid.ext should use if available', function () { - const validVideoBidRequest = { - bidder: 'advertising', - params: { - seatId: 'prebid', - placementId: 'demo1', - pos: 1, - video: {} - }, - renderer: { - url: '../syncOutstreamPlayer.js' - }, - ortb2Imp: { - ext: { - gpid: '/1111/homepage-video', - data: { - pbadslot: '/1111/homepage-video' - } - } - }, - mediaTypes: { - video: { - playerSize: [[300, 250]], - context: 'outstream' - } - }, - adUnitCode: 'div-1', - transactionId: '0869f34e-090b-4b20-84ee-46ff41405a39', - sizes: [[300, 250]], - bidId: '22b3a2268d9f0e', - bidderRequestId: '1d195910597e13', - auctionId: '3375d336-2aea-4ee7-804c-6d26b621ad20', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }; - - const validBannerBidRequest = { - bidId: '9876abcd', - sizes: [[300, 250]], - params: { - seatId: 'prebid', - placementId: '1234', - }, - ortb2Imp: { - ext: { - gpid: '/1111/homepage-banner', - data: { - pbadslot: '/1111/homepage-banner' - } - } - } - }; - - const bidderRequest = { - refererInfo: { - referer: 'http://localhost:9999/' - }, - bidderCode: 'advertising', - auctionId: 'f8a75621-d672-4cbb-9275-3db7d74fb110' - }; - - it('should return valid gpid and pbadslot', function () { - const videoRequest = spec.buildRequests([validVideoBidRequest], bidderRequest); - const bannerRequest = spec.buildRequests([validBannerBidRequest], bidderRequest); - - expect(videoRequest.data.imp[0].ext.gpid).to.equal('/1111/homepage-video'); - expect(videoRequest.data.imp[0].ext.data.pbadslot).to.equal('/1111/homepage-video'); - expect(bannerRequest.data.imp[0].ext.gpid).to.equal('/1111/homepage-banner'); - expect(bannerRequest.data.imp[0].ext.data.pbadslot).to.equal('/1111/homepage-banner'); - }); - }); -}); diff --git a/test/spec/modules/adverxoBidAdapter_spec.js b/test/spec/modules/adverxoBidAdapter_spec.js deleted file mode 100644 index 8dea5e3a3..000000000 --- a/test/spec/modules/adverxoBidAdapter_spec.js +++ /dev/null @@ -1,749 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/adverxoBidAdapter.js'; -import {config} from 'src/config'; - -describe('Adverxo Bid Adapter', () => { - function makeBidRequestWithParams(params) { - return { - bidId: '2e9f38ea93bb9e', - bidder: 'adverxo', - adUnitCode: 'adunit-code', - mediaTypes: {banner: {sizes: [[300, 250]]}}, - params: params, - bidderRequestId: 'test-bidder-request-id' - }; - } - - const bannerBidRequests = [ - { - bidId: 'bid-banner', - bidder: 'adverxo', - adUnitCode: 'adunit-code', - userIdAsEids: [{ - 'source': 'pubcid.org', - 'uids': [{ - 'atype': 1, - 'id': '01EAJWWNEPN3CYMM5N8M5VXY22' - }] - }], - mediaTypes: {banner: {sizes: [[300, 250]]}}, - params: { - host: 'bid.example.com', - adUnitId: 1, - auth: 'authExample', - }, - bidderRequestId: 'test-bidder-request-id', - }, - ]; - - const bannerBidderRequest = { - bidderCode: 'adverxo', - bidderRequestId: 'test-bidder-request-id', - bids: bannerBidRequests, - auctionId: 'new-auction-id' - }; - - const nativeOrtbRequest = { - assets: [ - { - id: 1, - required: 1, - img: {type: 3, w: 150, h: 50} - }, - { - id: 2, - required: 1, - title: {len: 80} - }, - { - id: 3, - required: 0, - data: {type: 1} - } - ] - }; - - const nativeBidRequests = [ - { - bidId: 'bid-native', - mediaTypes: { - native: { - ortb: nativeOrtbRequest - } - }, - nativeOrtbRequest, - params: { - host: 'bid.example.com', - adUnitId: 1, - auth: 'authExample' - } - }, - ]; - - const nativeBidderRequest = { - bidderCode: 'adverxo', - bidderRequestId: 'test-bidder-request-id', - bids: nativeBidRequests, - auctionId: 'new-auction-id' - }; - - const videoInstreamBidRequests = [ - { - bidId: 'bid-video', - mediaTypes: { - video: { - context: 'instream', - playerSize: [400, 300], - w: 400, - h: 300, - minduration: 5, - maxduration: 10, - startdelay: 0, - skip: 1, - minbitrate: 200, - protocols: [1, 2, 4] - } - }, - params: { - host: 'bid.example.com', - adUnitId: 1, - auth: 'authExample' - } - } - ]; - - const videoInstreamBidderRequest = { - bidderCode: 'adverxo', - bidderRequestId: 'test-bidder-request-id', - bids: videoInstreamBidRequests, - auctionId: 'new-auction-id' - }; - - const videoOutstreamBidRequests = [ - { - bidId: 'bid-video', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [400, 300], - w: 400, - h: 300, - minduration: 5, - maxduration: 10, - startdelay: 0, - skip: 1, - minbitrate: 200, - protocols: [1, 2, 4] - } - }, - params: { - host: 'bid.example.com', - adUnitId: 1, - auth: 'authExample' - } - } - ]; - - const videoOutstreamBidderRequest = { - bidderCode: 'adverxo', - bidderRequestId: 'test-bidder-request-id', - bids: videoOutstreamBidRequests, - auctionId: 'new-auction-id' - }; - - afterEach(function () { - config.resetConfig(); - }); - - describe('isBidRequestValid', function () { - it('should validate bid request with valid params (adUnit as number)', () => { - const validBid = makeBidRequestWithParams({ - adUnitId: 1, - auth: 'authExample', - host: 'www.bidExample.com' - }); - - const isValid = spec.isBidRequestValid(validBid); - - expect(isValid).to.be.true; - }); - - it('should validate bid request with valid params (adUnit as string)', () => { - const validBid = makeBidRequestWithParams({ - adUnitId: "1", - auth: 'authExample', - host: 'www.bidExample.com' - }); - - const isValid = spec.isBidRequestValid(validBid); - - expect(isValid).to.be.true; - }); - - it('should not validate bid request with empty params', () => { - const invalidBid = makeBidRequestWithParams({}); - - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.be.false; - }); - - it('should not validate bid request with missing param(adUnitId)', () => { - const invalidBid = makeBidRequestWithParams({ - auth: 'authExample', - host: 'www.bidExample.com' - }); - - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.be.false; - }); - - it('should not validate bid request with invalid param(adUnitId)', () => { - const invalidBid = makeBidRequestWithParams({ - adUnitId: "1a", - auth: 'authExample', - host: 'www.bidExample.com' - }); - - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.be.false; - }); - - it('should not validate bid request with missing param(auth)', () => { - const invalidBid = makeBidRequestWithParams({ - adUnitId: 1, - host: 'www.bidExample.com' - }); - - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.be.false; - }); - - it('should validate bid request with missing param(host)', () => { - const invalidBid = makeBidRequestWithParams({ - adUnitId: 1, - auth: 'authExample', - }); - - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.be.true; - }); - }); - - describe('buildRequests', () => { - it('should add eids information to the request', function () { - const request = spec.buildRequests(bannerBidRequests, bannerBidderRequest)[0]; - - expect(request.data.user.ext.eids).to.exist; - expect(request.data.user.ext.eids).to.deep.equal(bannerBidRequests[0].userIdAsEids); - }); - - it('should use correct bidUrl for an alias', () => { - const bidRequests = [ - { - bidder: 'bidsmind', - mediaTypes: {banner: {sizes: [[300, 250]]}}, - params: { - adUnitId: 1, - auth: 'authExample', - } - }, - ]; - - const bidderRequest = { - bidderCode: 'bidsmind', - bids: bidRequests, - }; - - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://arcantila.com/pickpbs?id=1&auth=authExample'); - }); - - it('should use correct default bidUrl', () => { - const bidRequests = [ - { - bidder: 'adverxo', - mediaTypes: {banner: {sizes: [[300, 250]]}}, - params: { - adUnitId: 1, - auth: 'authExample', - } - }, - ]; - - const bidderRequest = { - bidderCode: 'adverxo', - bids: bidRequests - }; - - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://js.pbsadverxo.com/pickpbs?id=1&auth=authExample'); - }); - - it('should build post request for banner', () => { - const request = spec.buildRequests(bannerBidRequests, bannerBidderRequest)[0]; - - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://bid.example.com/pickpbs?id=1&auth=authExample'); - expect(request.data.device.ip).to.equal('caller'); - expect(request.data.ext.avx_add_vast_url).to.equal(1); - }); - - if (FEATURES.NATIVE) { - it('should build post request for native', () => { - const request = spec.buildRequests(nativeBidRequests, nativeBidderRequest)[0]; - - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://bid.example.com/pickpbs?id=1&auth=authExample'); - - const nativeRequest = JSON.parse(request.data.imp[0]['native'].request); - - expect(nativeRequest.assets).to.have.lengthOf(3); - - expect(nativeRequest.assets[0]).to.deep.equal({ - id: 1, - required: 1, - img: {w: 150, h: 50, type: 3} - }); - - expect(nativeRequest.assets[1]).to.deep.equal({ - id: 2, - required: 1, - title: {len: 80} - }); - - expect(nativeRequest.assets[2]).to.deep.equal({ - id: 3, - required: 0, - data: {type: 1} - }); - }); - } - - if (FEATURES.VIDEO) { - it('should build post request for video', function () { - const request = spec.buildRequests(videoInstreamBidRequests, videoInstreamBidderRequest)[0]; - - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://bid.example.com/pickpbs?id=1&auth=authExample'); - - const ortbRequest = request.data; - - expect(ortbRequest.imp).to.have.lengthOf(1); - - expect(ortbRequest.imp[0]).to.deep.equal({ - id: 'bid-video', - secure: 1, - video: { - w: 400, - h: 300, - minduration: 5, - maxduration: 10, - startdelay: 0, - skip: 1, - minbitrate: 200, - protocols: [1, 2, 4] - } - }); - }); - } - - it('should add bid floor to request', function () { - const bannerBidRequestWithFloor = { - ...bannerBidRequests[0], - getFloor: () => ({currency: 'USD', floor: 3}) - }; - - const request = spec.buildRequests([bannerBidRequestWithFloor], {})[0].data; - - expect(request.imp[0].bidfloor).to.equal(3); - expect(request.imp[0].bidfloorcur).to.equal('USD'); - }); - }); - - describe('interpretResponse', () => { - it('should return empty array if serverResponse is not defined', () => { - const bidRequest = spec.buildRequests(bannerBidRequests, bannerBidderRequest); - const bids = spec.interpretResponse(undefined, bidRequest); - - expect(bids.length).to.equal(0); - }); - - it('should interpret banner response', () => { - const bidResponse = { - body: { - id: 'bid-response', - cur: 'USD', - seatbid: [ - { - bid: [ - { - impid: 'bid-banner', - crid: 'creative-id', - cur: 'USD', - price: 2, - w: 300, - h: 250, - mtype: 1, - adomain: ['test.com'], - adm: '
' - }, - ], - seat: 'test-seat', - }, - ], - }, - }; - - const expectedBids = [ - { - cpm: 2, - creativeId: 'creative-id', - creative_id: 'creative-id', - currency: 'USD', - height: 250, - mediaType: 'banner', - meta: { - advertiserDomains: ['test.com'], - }, - netRevenue: true, - requestId: 'bid-banner', - ttl: 60, - width: 300, - ad: '
' - }, - ]; - - const request = spec.buildRequests(bannerBidRequests, bannerBidderRequest)[0]; - const bids = spec.interpretResponse(bidResponse, request); - - expect(bids).to.deep.equal(expectedBids); - }); - - it('should replace openrtb auction price macro', () => { - const bidResponse = { - body: { - id: 'bid-response', - cur: 'USD', - seatbid: [ - { - bid: [ - { - impid: 'bid-banner', - crid: 'creative-id', - cur: 'USD', - price: 2, - w: 300, - h: 250, - mtype: 1, - adomain: ['test.com'], - adm: '' - }, - ], - seat: 'test-seat', - }, - ], - }, - }; - - const request = spec.buildRequests(bannerBidRequests, bannerBidderRequest)[0]; - const bids = spec.interpretResponse(bidResponse, request); - - expect(bids[0].ad).to.equal(''); - }); - - if (FEATURES.NATIVE) { - it('should interpret native response', () => { - const bidResponse = { - body: { - id: 'native-response', - cur: 'USD', - seatbid: [ - { - bid: [ - { - impid: 'bid-native', - crid: 'creative-id', - cur: 'USD', - price: 2, - w: 300, - h: 250, - mtype: 4, - adomain: ['test.com'], - adm: '{"native":{"assets":[{"id":2,"title":{"text":"Title"}},{"id":3,"data":{"value":"Description"}},{"id":1,"img":{"url":"http://example.com?img","w":150,"h":50}}],"link":{"url":"http://example.com?link"}}}' - }, - ], - seat: 'test-seat', - }, - ], - }, - }; - - const expectedBids = [ - { - cpm: 2, - creativeId: 'creative-id', - creative_id: 'creative-id', - currency: 'USD', - height: 250, - mediaType: 'native', - meta: { - advertiserDomains: ['test.com'], - }, - netRevenue: true, - requestId: 'bid-native', - ttl: 60, - width: 300, - native: { - ortb: { - assets: [ - {id: 2, title: {text: 'Title'}}, - {id: 3, data: {value: 'Description'}}, - {id: 1, img: {url: 'http://example.com?img', w: 150, h: 50}} - ], - link: {url: 'http://example.com?link'} - } - } - } - ]; - - const request = spec.buildRequests(nativeBidRequests, nativeBidderRequest)[0]; - const bids = spec.interpretResponse(bidResponse, request); - - expect(bids).to.deep.equal(expectedBids); - }); - } - - if (FEATURES.VIDEO) { - it('should interpret video instream response', () => { - const bidResponse = { - body: { - id: 'video-response', - cur: 'USD', - seatbid: [ - { - bid: [ - { - impid: 'bid-video', - crid: 'creative-id', - cur: 'USD', - price: 2, - w: 300, - h: 250, - mtype: 2, - adomain: ['test.com'], - adm: 'vastXml', - ext: { - avx_vast_url: 'vastUrl' - } - }, - ], - seat: 'test-seat', - }, - ], - }, - }; - - const expectedBids = [ - { - cpm: 2, - creativeId: 'creative-id', - creative_id: 'creative-id', - currency: 'USD', - height: 250, - mediaType: 'video', - meta: { - advertiserDomains: ['test.com'], - }, - netRevenue: true, - playerHeight: 300, - playerWidth: 400, - requestId: 'bid-video', - ttl: 60, - vastUrl: 'vastUrl', - vastXml: 'vastXml', - width: 300 - } - ]; - - const request = spec.buildRequests(videoInstreamBidRequests, videoInstreamBidderRequest)[0]; - const bids = spec.interpretResponse(bidResponse, request); - - expect(bids).to.deep.equal(expectedBids); - }); - - it('should interpret video outstream response', () => { - const bidResponse = { - body: { - id: 'video-response', - cur: 'USD', - seatbid: [ - { - bid: [ - { - impid: 'bid-video', - crid: 'creative-id', - cur: 'USD', - price: 2, - w: 300, - h: 250, - mtype: 2, - adomain: ['test.com'], - adm: 'vastXml', - ext: { - avx_vast_url: 'vastUrl', - avx_video_renderer_url: 'videoRendererUrl', - } - }, - ], - seat: 'test-seat', - }, - ], - }, - }; - - const expectedBids = [ - { - avxVideoRendererUrl: 'videoRendererUrl', - cpm: 2, - creativeId: 'creative-id', - creative_id: 'creative-id', - currency: 'USD', - height: 250, - mediaType: 'video', - meta: { - advertiserDomains: ['test.com'], - }, - netRevenue: true, - playerHeight: 300, - playerWidth: 400, - requestId: 'bid-video', - ttl: 60, - vastUrl: 'vastUrl', - vastXml: 'vastXml', - width: 300 - } - ]; - - const request = spec.buildRequests(videoOutstreamBidRequests, videoOutstreamBidderRequest)[0]; - const bids = spec.interpretResponse(bidResponse, request); - - expect(bids[0].renderer.url).to.equal('videoRendererUrl'); - - delete (bids[0].renderer); - expect(bids).to.deep.equal(expectedBids); - }); - } - }); - - describe('getUserSyncs', () => { - const exampleUrl = 'https://example.com/usync?id=5'; - const iframeConfig = {iframeEnabled: true}; - - const responses = [{ - body: {ext: {avx_usync: [exampleUrl]}} - }]; - - const responseWithoutQueryString = [{ - body: {ext: {avx_usync: ['https://example.com/usync/sf/5']}} - }]; - - it('should not return empty list if not allowed', function () { - expect(spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, responses, undefined, undefined, undefined)).to.be.empty; - }); - - it('should not return iframe if not allowed', function () { - expect(spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: true - }, responses, undefined, undefined, undefined)).to.deep.equal([{ - type: 'image', url: `${exampleUrl}&type=image` - }]); - }); - - it('should add query string to url when missing', function () { - expect(spec.getUserSyncs(iframeConfig, responseWithoutQueryString, undefined, undefined, undefined)).to.deep.equal([{ - type: 'iframe', url: `https://example.com/usync/sf/5?type=iframe` - }]); - }); - - it('should not add parameters if not provided', function () { - expect(spec.getUserSyncs(iframeConfig, responses, undefined, undefined, undefined)).to.deep.equal([{ - type: 'iframe', url: `${exampleUrl}&type=iframe` - }]); - }); - - it('should add GDPR parameters if provided', function () { - expect(spec.getUserSyncs(iframeConfig, responses, {gdprApplies: true}, undefined, undefined)).to.deep.equal([{ - type: 'iframe', url: `${exampleUrl}&type=iframe&gdpr=1&gdpr_consent=` - }]); - - expect(spec.getUserSyncs(iframeConfig, responses, - {gdprApplies: true, consentString: 'foo?'}, undefined, undefined)).to.deep.equal([{ - type: 'iframe', url: `${exampleUrl}&type=iframe&gdpr=1&gdpr_consent=foo%3F` - }]); - - expect(spec.getUserSyncs(iframeConfig, responses, - {gdprApplies: false, consentString: 'bar'}, undefined, undefined)).to.deep.equal([{ - type: 'iframe', url: `${exampleUrl}&type=iframe&gdpr=0&gdpr_consent=bar` - }]); - }); - - it('should add CCPA parameters if provided', function () { - expect(spec.getUserSyncs(iframeConfig, responses, undefined, 'foo?', undefined)).to.deep.equal([{ - type: 'iframe', url: `${exampleUrl}&type=iframe&us_privacy=foo%3F` - }]); - }); - - it('should not apply if not gppConsent.gppString', function () { - const gppConsent = {gppString: '', applicableSections: [123]}; - const result = spec.getUserSyncs(iframeConfig, responses, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${exampleUrl}&type=iframe` - }]); - }); - - it('should not apply if not gppConsent.applicableSections', function () { - const gppConsent = {gppString: '', applicableSections: undefined}; - const result = spec.getUserSyncs(iframeConfig, responses, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${exampleUrl}&type=iframe` - }]); - }); - - it('should not apply if empty gppConsent.applicableSections', function () { - const gppConsent = {gppString: '', applicableSections: []}; - const result = spec.getUserSyncs(iframeConfig, responses, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${exampleUrl}&type=iframe` - }]); - }); - - it('should apply if all above are available', function () { - const gppConsent = {gppString: 'foo?', applicableSections: [123]}; - const result = spec.getUserSyncs(iframeConfig, responses, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${exampleUrl}&type=iframe&gpp=foo%3F&gpp_sid=123` - }]); - }); - - it('should support multiple sections', function () { - const gppConsent = {gppString: 'foo', applicableSections: [123, 456]}; - const result = spec.getUserSyncs(iframeConfig, responses, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${exampleUrl}&type=iframe&gpp=foo&gpp_sid=123%2C456` - }]); - }); - }); -}); diff --git a/test/spec/modules/adxcgAnalyticsAdapter_spec.js b/test/spec/modules/adxcgAnalyticsAdapter_spec.js deleted file mode 100644 index 9efa1085a..000000000 --- a/test/spec/modules/adxcgAnalyticsAdapter_spec.js +++ /dev/null @@ -1,207 +0,0 @@ -import adxcgAnalyticsAdapter from 'modules/adxcgAnalyticsAdapter.js'; -import { expect } from 'chai'; -import adapterManager from 'src/adapterManager.js'; -import { server } from 'test/mocks/xhr.js'; -import { EVENTS } from 'src/constants.js'; - -const events = require('src/events'); - -describe('adxcg analytics adapter', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - }); - - afterEach(function () { - events.getEvents.restore(); - }); - - describe('track', function () { - const initOptions = { - publisherId: '42' - }; - - const auctionTimestamp = 1496510254313; - - // prepare general auction - request and response - const bidRequest = { - 'bidderCode': 'appnexus', - 'bids': [{ - 'params': { - 'placementId': '10433394' - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'transactionId': '2f481ff1-8d20-4c28-8e36-e384e9e3eec6', - 'sizes': '300x250,300x600', - 'bidId': '2eddfdc0c791dc', - 'auctionId': 'a5b849e5-87d7-4205-8300-d063084fcfb7' - } - ] - }; - - const bidResponse = { - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '2eddfdc0c791dc', - 'mediaType': 'banner', - 'source': 'client', - 'requestId': '2eddfdc0c791dc', - 'cpm': 0.5, - 'creativeId': 29681110, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'auctionId': 'a5b849e5-87d7-4205-8300-d063084fcfb7', - 'responseTimestamp': 1522265866110, - 'requestTimestamp': 1522265863600, - 'bidder': 'appnexus', - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'timeToRespond': 2510, - 'size': '300x250' - }; - - // what we expect after general auction - const expectedAfterBid = { - 'bidRequests': [ - { - 'bidderCode': 'appnexus', - 'bids': [ - { - 'transactionId': '2f481ff1-8d20-4c28-8e36-e384e9e3eec6', - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'bidId': '2eddfdc0c791dc', - 'sizes': '300x250,300x600', - 'params': { - 'placementId': '10433394' - } - } - ] - } - ], - 'bidResponses': [ - { - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'bidderCode': 'appnexus', - 'statusMessage': 'Bid available', - 'mediaType': 'banner', - 'renderedSize': '300x250', - 'cpm': 0.5, - 'currency': 'USD', - 'netRevenue': true, - 'timeToRespond': 2510, - 'bidId': '2eddfdc0c791dc', - 'creativeId': '29681110' - } - ], - 'auctionInit': {}, - 'bidTimeout': [ - 'bidderOne', - 'bidderTwo' - ] - }; - - // lets simulate that some bidders timeout - const bidTimeoutArgsV1 = [ - { - bidId: '2baa51527bd015', - bidder: 'bidderOne', - adUnitCode: '/19968336/header-bid-tag-0', - auctionId: '66529d4c-8998-47c2-ab3e-5b953490b98f' - }, - { - bidId: '6fe3b4c2c23092', - bidder: 'bidderTwo', - adUnitCode: '/19968336/header-bid-tag-0', - auctionId: '66529d4c-8998-47c2-ab3e-5b953490b98f' - } - ]; - - // now simulate some WIN and RENDERING - const wonRequest = { - 'adId': '4587fec4900b81', - 'mediaType': 'banner', - 'requestId': '4587fec4900b81', - 'cpm': 1.962, - 'creativeId': 2126, - 'currency': 'EUR', - 'netRevenue': true, - 'ttl': 302, - 'auctionId': '914bedad-b145-4e46-ba58-51365faea6cb', - 'statusMessage': 'Bid available', - 'responseTimestamp': 1530628534437, - 'requestTimestamp': 1530628534219, - 'bidder': 'testbidder4', - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'timeToRespond': 218, - 'size': '300x250', - 'status': 'rendered' - }; - - const wonExpect = { - 'bidWons': [{ - 'bidderCode': 'testbidder4', - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'mediaType': 'banner', - 'renderedSize': '300x250', - 'cpm': 1.962, - 'currency': 'EUR', - 'netRevenue': true, - 'timeToRespond': 218, - 'bidId': '4587fec4900b81', - 'statusMessage': 'Bid available', - 'status': 'rendered', - 'creativeId': '2126' - }] - }; - - adapterManager.registerAnalyticsAdapter({ - code: 'adxcg', - adapter: adxcgAnalyticsAdapter - }); - - beforeEach(function () { - adapterManager.enableAnalytics({ - provider: 'adxcg', - options: initOptions - }); - }); - - afterEach(function () { - adxcgAnalyticsAdapter.disableAnalytics(); - }); - - it('builds and sends auction data', function () { - // Step 1: Send auction init event - events.emit(EVENTS.AUCTION_INIT, { - timestamp: auctionTimestamp - }); - - // Step 2: Send bid requested event - events.emit(EVENTS.BID_REQUESTED, bidRequest); - - // Step 3: Send bid response event - events.emit(EVENTS.BID_RESPONSE, bidResponse); - - // Step 4: Send bid time out event - events.emit(EVENTS.BID_TIMEOUT, bidTimeoutArgsV1); - - // Step 5: Send auction end event - events.emit(EVENTS.AUCTION_END, {}); - - expect(server.requests.length).to.equal(1); - - const realAfterBid = JSON.parse(server.requests[0].requestBody); - - expect(realAfterBid).to.deep.equal(expectedAfterBid); - - expect(realAfterBid.bidTimeout).to.deep.equal(['bidderOne', 'bidderTwo']); - - // Step 6: Send auction bid won event - events.emit(EVENTS.BID_WON, wonRequest); - - expect(server.requests.length).to.equal(2); - const winEventData = JSON.parse(server.requests[1].requestBody); - - expect(winEventData).to.deep.equal(wonExpect); - }); - }); -}); diff --git a/test/spec/modules/adxcgBidAdapter_spec.js b/test/spec/modules/adxcgBidAdapter_spec.js deleted file mode 100644 index 0f14bad94..000000000 --- a/test/spec/modules/adxcgBidAdapter_spec.js +++ /dev/null @@ -1,576 +0,0 @@ -// jshint esversion: 6, es3: false, node: true -/* eslint dot-notation:0, quote-props:0 */ -import {assert, expect} from 'chai'; -import {spec} from 'modules/adxcgBidAdapter.js'; -import {config} from 'src/config.js'; - -import {addFPDToBidderRequest} from '../../helpers/fpd.js'; - -const utils = require('src/utils'); - -describe('Adxcg adapter', function () { - const bids = []; - - describe('getUserSyncs', function () { - const usersyncUrl = 'https://usersync-url.com'; - beforeEach(() => { - config.setConfig( - { - adxcg: { - usersyncUrl: usersyncUrl, - } - } - ) - }) - after(() => { - config.resetConfig() - }) - - it('should return user sync if pixel enabled with adxcg config', function () { - const ret = spec.getUserSyncs({ pixelEnabled: true }) - expect(ret).to.deep.equal([{ type: 'image', url: usersyncUrl }]) - }) - - it('should not return user sync if pixel disabled', function () { - const ret = spec.getUserSyncs({ pixelEnabled: false }) - expect(ret).to.be.an('array').that.is.empty - }) - - it('should not return user sync if url is not set', function () { - config.resetConfig() - const ret = spec.getUserSyncs({ pixelEnabled: true }) - expect(ret).to.be.an('array').that.is.empty - }) - - it('should pass GDPR consent', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, { gdprApplies: true, consentString: 'foo' }, undefined)).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?gdpr=1&gdpr_consent=foo` - }]); - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, { gdprApplies: false, consentString: 'foo' }, undefined)).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?gdpr=0&gdpr_consent=foo` - }]); - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, { gdprApplies: true, consentString: undefined }, undefined)).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?gdpr=1&gdpr_consent=` - }]); - }); - - it('should pass US consent', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, undefined, '1NYN')).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?us_privacy=1NYN` - }]); - }); - - it('should pass GDPR and US consent', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, { gdprApplies: true, consentString: 'foo' }, '1NYN')).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?gdpr=1&gdpr_consent=foo&us_privacy=1NYN` - }]); - }); - }); - - describe('onBidWon', function () { - beforeEach(function () { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function () { - utils.triggerPixel.restore(); - }); - - it('Should trigger pixel if bid nurl', function () { - const bid = { - nurl: 'http://example.com/win/${AUCTION_PRICE}', - cpm: 2.1, - originalCpm: 1.1, - } - spec.onBidWon(bid); - expect(utils.triggerPixel.callCount).to.equal(1) - }) - }) - - it('should return just to have at least 1 karma test ok', function () { - assert(true); - }); -}); - -describe('adxcg v8 oRtbConverter Adapter Tests', function () { - const slotConfigs = [{ - placementCode: '/DfpAccount1/slot1', - mediaTypes: { - banner: { - sizes: [[728, 90], [160, 600]] - } - }, - bidId: 'bid12345', - params: { - adzoneid: '77' - } - }, { - placementCode: '/DfpAccount2/slot2', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - bidId: 'bid23456', - params: { - adzoneid: '77' - } - }]; - const nativeOrtbRequest = { - assets: [{ - id: 1, - required: 1, - img: { - type: 3, - w: 150, - h: 50, - } - }, - { - id: 2, - required: 1, - title: { - len: 80 - } - }, - { - id: 3, - required: 0, - data: { - type: 1 - } - }] - }; - const nativeSlotConfig = [{ - placementCode: '/DfpAccount1/slot3', - bidId: 'bid12345', - mediaTypes: { - native: { - ortb: nativeOrtbRequest - } - }, - nativeOrtbRequest, - params: { - - adzoneid: '77' - } - }]; - const videoSlotConfig = [{ - placementCode: '/DfpAccount1/slotVideo', - bidId: 'bid12345', - mediaTypes: { - video: { - playerSize: [400, 300], - w: 400, - h: 300, - minduration: 5, - maxduration: 10, - startdelay: 0, - skip: 1, - minbitrate: 200, - protocols: [1, 2, 4] - } - }, - params: { - adzoneid: '77' - } - }]; - const additionalParamsConfig = [{ - placementCode: '/DfpAccount1/slot1', - mediaTypes: { - banner: { - sizes: [[1, 1]] - } - }, - bidId: 'bid12345', - params: { - adzoneid: '77', - extra_key1: 'extra_val1', - extra_key2: 12345, - extra_key3: { - key1: 'val1', - key2: 23456, - }, - extra_key4: [1, 2, 3] - } - }]; - - const schainParamsSlotConfig = [{ - placementCode: '/DfpAccount1/slot1', - mediaTypes: { - banner: { - sizes: [[1, 1]] - } - }, - bidId: 'bid12345', - params: { - adzoneid: '77', - bcat: ['IAB-1', 'IAB-20'], - battr: [1, 2, 3], - bidfloor: 1.5, - badv: ['cocacola.com', 'lays.com'] - }, - schain: { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'exchange1.com', - 'sid': '1234', - 'hp': 1, - 'rid': 'bid-request-1', - 'name': 'publisher', - 'domain': 'publisher.com' - } - ] - }, - }]; - - let bidderRequest; - - beforeEach(() => { - return addFPDToBidderRequest({ - refererInfo: { - page: 'https://publisher.com/home', - ref: 'https://referrer' - } - }).then(br => { bidderRequest = br }); - }) - - it('Verify build request', function () { - const request = spec.buildRequests(slotConfigs, bidderRequest); - expect(request.url).to.equal('https://pbc.adxcg.net/rtb/ortb/pbc?adExchangeId=1'); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - // site object - expect(ortbRequest.site).to.not.equal(null); - expect(ortbRequest.site.publisher).to.not.equal(null); - expect(ortbRequest.site.page).to.equal('https://publisher.com/home'); - expect(ortbRequest.imp).to.have.lengthOf(2); - // device object - expect(ortbRequest.device).to.not.equal(null); - expect(ortbRequest.device.ua).to.equal(navigator.userAgent); - // slot 1 - expect(ortbRequest.imp[0].banner).to.not.equal(null); - expect(ortbRequest.imp[0].banner.format).to.deep.eq([{ 'w': 728, 'h': 90 }, { 'w': 160, 'h': 600 }]); - // slot 2 - expect(ortbRequest.imp[1].banner).to.not.equal(null); - expect(ortbRequest.imp[1].banner.format).to.deep.eq([{ 'w': 728, 'h': 90 }]); - }); - - it('Verify parse response', function () { - const request = spec.buildRequests(slotConfigs, bidderRequest); - const ortbRequest = request.data; - const ortbResponse = { - seatbid: [{ - bid: [{ - impid: ortbRequest.imp[0].id, - price: 1.25, - adm: 'This is an Ad', - crid: 'Creative#123', - mtype: 1, - w: 300, - h: 250, - exp: 20, - adomain: ['advertiser.com'] - }] - }] - }; - const bids = spec.interpretResponse({ body: ortbResponse }, request); - expect(bids).to.have.lengthOf(1); - // verify first bid - const bid = bids[0]; - expect(bid.cpm).to.equal(1.25); - expect(bid.ad).to.equal('This is an Ad'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creative_id).to.equal('Creative#123'); - expect(bid.creativeId).to.equal('Creative#123'); - expect(bid.netRevenue).to.equal(true); - expect(bid.currency).to.equal('EUR'); - expect(bid.ttl).to.equal(20); - expect(bid.meta).to.not.be.null; - expect(bid.meta.advertiserDomains).to.eql(['advertiser.com']); - }); - - it('Verify full passback', function () { - const request = spec.buildRequests(slotConfigs, bidderRequest); - const bids = spec.interpretResponse({ body: null }, request) - expect(bids).to.have.lengthOf(0); - }); - - if (FEATURES.NATIVE) { - it('Verify Native request', function () { - const request = spec.buildRequests(nativeSlotConfig, bidderRequest); - expect(request.url).to.equal('https://pbc.adxcg.net/rtb/ortb/pbc?adExchangeId=1'); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - // native impression - expect(ortbRequest.imp[0].tagid).to.equal('77'); - expect(ortbRequest.imp[0].banner).to.be.undefined; - const nativePart = ortbRequest.imp[0]['native']; - expect(nativePart).to.not.equal(null); - expect(nativePart.request).to.not.equal(null); - // native request assets - const nativeRequest = JSON.parse(ortbRequest.imp[0]['native'].request); - expect(nativeRequest).to.not.equal(null); - expect(nativeRequest.assets).to.have.lengthOf(3); - // image asset - expect(nativeRequest.assets[0].id).to.equal(1); - expect(nativeRequest.assets[0].required).to.equal(1); - expect(nativeRequest.assets[0].title).to.be.undefined; - expect(nativeRequest.assets[0].img).to.not.equal(null); - expect(nativeRequest.assets[0].img.w).to.equal(150); - expect(nativeRequest.assets[0].img.h).to.equal(50); - expect(nativeRequest.assets[0].img.type).to.equal(3); - // title asset - expect(nativeRequest.assets[1].id).to.equal(2); - expect(nativeRequest.assets[1].required).to.equal(1); - expect(nativeRequest.assets[1].title).to.not.equal(null); - expect(nativeRequest.assets[1].title.len).to.equal(80); - // data asset - expect(nativeRequest.assets[2].id).to.equal(3); - expect(nativeRequest.assets[2].required).to.equal(0); - expect(nativeRequest.assets[2].title).to.be.undefined; - expect(nativeRequest.assets[2].data).to.not.equal(null); - expect(nativeRequest.assets[2].data.type).to.equal(1); - }); - - it('Verify Native response', function () { - const request = spec.buildRequests(nativeSlotConfig, bidderRequest); - expect(request.url).to.equal('https://pbc.adxcg.net/rtb/ortb/pbc?adExchangeId=1'); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - const nativeResponse = { - assets: [ - { id: 1, img: { type: 3, url: 'https://images.cdn.brand.com/123' } }, - { id: 2, title: { text: 'Ad Title' } }, - { id: 3, data: { type: 1, value: 'Sponsored By: Brand' } } - ], - link: { url: 'https://brand.clickme.com/' }, - imptrackers: ['https://imp1.trackme.com/', 'https://imp1.contextweb.com/'] - - }; - const ortbResponse = { - seatbid: [{ - bid: [{ - impid: ortbRequest.imp[0].id, - price: 1.25, - adm: JSON.stringify(nativeResponse), - mtype: 4 - }] - }] - }; - const bids = spec.interpretResponse({ body: ortbResponse }, request); - // verify bid - const bid = bids[0]; - expect(bid.cpm).to.equal(1.25); - expect(bid.requestId).to.equal('bid12345'); - expect(bid.ad).to.be.undefined; - expect(bid.mediaType).to.equal('native'); - expect(bid['native']).to.not.be.null; - expect(bid['native'].ortb).to.not.be.null; - const nativeBid = bid['native'].ortb; - expect(nativeBid.assets).to.have.lengthOf(3); - expect(nativeBid.assets[0].id).to.equal(1); - expect(nativeBid.assets[0].img).to.not.be.null; - expect(nativeBid.assets[0].img.type).to.equal(3); - expect(nativeBid.assets[0].img.url).to.equal('https://images.cdn.brand.com/123'); - expect(nativeBid.assets[1].id).to.equal(2); - expect(nativeBid.assets[1].title).to.not.be.null; - expect(nativeBid.assets[1].title.text).to.equal('Ad Title'); - expect(nativeBid.assets[2].id).to.equal(3); - expect(nativeBid.assets[2].data).to.not.be.null; - expect(nativeBid.assets[2].data.type).to.equal(1); - expect(nativeBid.assets[2].data.value).to.equal('Sponsored By: Brand'); - expect(nativeBid.link).to.not.be.null; - expect(nativeBid.link.url).to.equal('https://brand.clickme.com/'); - expect(nativeBid.imptrackers).to.have.lengthOf(2); - expect(nativeBid.imptrackers[0]).to.equal('https://imp1.trackme.com/'); - expect(nativeBid.imptrackers[1]).to.equal('https://imp1.contextweb.com/'); - }); - } - - it('Verifies bidder code', function () { - expect(spec.code).to.equal('adxcg'); - }); - - it('Verifies bidder aliases', function () { - expect(spec.aliases).to.have.lengthOf(1); - expect(spec.aliases[0]).to.equal('mediaopti'); - }); - - it('Verifies supported media types', function () { - expect(spec.supportedMediaTypes).to.have.lengthOf(3); - expect(spec.supportedMediaTypes[0]).to.equal('banner'); - expect(spec.supportedMediaTypes[1]).to.equal('native'); - expect(spec.supportedMediaTypes[2]).to.equal('video'); - }); - - if (FEATURES.VIDEO) { - it('Verify Video request', function () { - const request = spec.buildRequests(videoSlotConfig, bidderRequest); - expect(request.url).to.equal('https://pbc.adxcg.net/rtb/ortb/pbc?adExchangeId=1'); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - expect(ortbRequest).to.not.equal(null); - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].video).to.not.be.null; - expect(ortbRequest.imp[0].native).to.be.undefined; - expect(ortbRequest.imp[0].banner).to.be.undefined; - expect(ortbRequest.imp[0].video.w).to.equal(400); - expect(ortbRequest.imp[0].video.h).to.equal(300); - expect(ortbRequest.imp[0].video.minduration).to.equal(5); - expect(ortbRequest.imp[0].video.maxduration).to.equal(10); - expect(ortbRequest.imp[0].video.startdelay).to.equal(0); - expect(ortbRequest.imp[0].video.skip).to.equal(1); - expect(ortbRequest.imp[0].video.minbitrate).to.equal(200); - expect(ortbRequest.imp[0].video.protocols).to.eql([1, 2, 4]); - }); - } - - it('Verify extra parameters', function () { - let request = spec.buildRequests(additionalParamsConfig, bidderRequest); - let ortbRequest = request.data; - expect(ortbRequest).to.not.equal(null); - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].ext).to.not.equal(null); - expect(ortbRequest.imp[0].ext.prebid).to.not.equal(null); - expect(ortbRequest.imp[0].ext.prebid).to.not.be.null; - expect(ortbRequest.imp[0].ext.prebid.extra_key1).to.equal('extra_val1'); - expect(ortbRequest.imp[0].ext.prebid.extra_key2).to.equal(12345); - expect(ortbRequest.imp[0].ext.prebid.extra_key3).to.not.be.null; - expect(ortbRequest.imp[0].ext.prebid.extra_key3.key1).to.equal('val1'); - expect(ortbRequest.imp[0].ext.prebid.extra_key3.key2).to.equal(23456); - expect(ortbRequest.imp[0].ext.prebid.extra_key4).to.eql([1, 2, 3]); - expect(Object.keys(ortbRequest.imp[0].ext.prebid)).to.eql(['adzoneid', 'extra_key1', 'extra_key2', 'extra_key3', 'extra_key4']); - // attempting with a configuration with no unknown params. - request = spec.buildRequests(videoSlotConfig, bidderRequest); - ortbRequest = request.data; - expect(ortbRequest).to.not.equal(null); - expect(ortbRequest.imp).to.have.lengthOf(1); - // expect(ortbRequest.imp[0].ext).to.be.undefined; - }); - - it('Verify user level first party data', function () { - const bidderRequest = { - refererInfo: { - page: 'https://publisher.com/home', - ref: 'https://referrer' - }, - gdprConsent: { - gdprApplies: true, - consentString: 'serialized_gdpr_data' - }, - ortb2: { - user: { - yob: 1985, - gender: 'm', - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - } - } - }; - const request = spec.buildRequests(slotConfigs, bidderRequest); - const ortbRequest = request.data; - expect(ortbRequest).to.not.equal(null); - expect(ortbRequest.user).to.not.equal(null); - }); - - it('Verify site level first party data', function () { - const bidderRequest = { - ortb2: { - site: { - content: { - data: [{ - name: 'www.iris.com', - ext: { - segtax: 500, - cids: ['iris_c73g5jq96mwso4d8'] - } - }] - }, - page: 'http://pub.com/news', - ref: 'http://google.com', - publisher: { - domain: 'pub.com' - } - } - } - }; - const request = spec.buildRequests(slotConfigs, bidderRequest); - const ortbRequest = request.data; - expect(ortbRequest).to.not.equal(null); - expect(ortbRequest.site).to.not.equal(null); - expect(ortbRequest.site).to.deep.equal({ - content: { - data: [{ - name: 'www.iris.com', - ext: { - segtax: 500, - cids: ['iris_c73g5jq96mwso4d8'] - } - }] - }, - page: 'http://pub.com/news', - ref: 'http://google.com', - publisher: { - domain: 'pub.com' - } - }); - }); - - it('Verify impression/slot level first party data', function () { - const bidderRequests = [{ - placementCode: '/DfpAccount1/slot1', - mediaTypes: { - banner: { - sizes: [[1, 1]] - } - }, - bidId: 'bid12345', - params: { - adzoneid: '77', - extra_key1: 'extra_val1', - extra_key2: 12345 - }, - ortb2Imp: { - ext: { - data: { - pbadslot: 'homepage-top-rect', - adUnitSpecificAttribute: '123' - } - } - } - }]; - const request = spec.buildRequests(bidderRequests, bidderRequest); - const ortbRequest = request.data; - expect(ortbRequest).to.not.equal(null); - expect(ortbRequest.imp).to.not.equal(null); - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].ext).to.not.equal(null); - expect(ortbRequest.imp[0].ext).to.deep.equal({ - prebid: { - adzoneid: '77', - extra_key1: 'extra_val1', - extra_key2: 12345 - }, - data: { - pbadslot: 'homepage-top-rect', - adUnitSpecificAttribute: '123' - } - }); - }); - - it('Verify bid request timeouts', function () { - const mkRequest = (bidderRequest) => spec.buildRequests(slotConfigs, bidderRequest).data; - // assert default is used when no bidderRequest.timeout value is available - expect(mkRequest(bidderRequest).tmax).to.equal(500) - - // assert bidderRequest value is used when available - expect(mkRequest(Object.assign({}, { timeout: 6000 }, bidderRequest)).tmax).to.equal(6000) - }); -}); diff --git a/test/spec/modules/adxpremiumAnalyticsAdapter_spec.js b/test/spec/modules/adxpremiumAnalyticsAdapter_spec.js deleted file mode 100644 index 479cd601e..000000000 --- a/test/spec/modules/adxpremiumAnalyticsAdapter_spec.js +++ /dev/null @@ -1,415 +0,0 @@ -import adxpremiumAnalyticsAdapter, { testSend } from 'modules/adxpremiumAnalyticsAdapter.js'; - -import { expect } from 'chai'; -import adapterManager from 'src/adapterManager.js'; -import { server } from 'test/mocks/xhr.js'; -import { EVENTS } from 'src/constants.js'; - -const events = require('src/events'); - -describe('AdxPremium analytics adapter', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - }); - - afterEach(function () { - events.getEvents.restore(); - }); - - describe('track', function () { - const initOptions = { - pubId: 123, - sid: 's2' - }; - - const auctionInit = { - 'auctionId': 'c4f0cce0-264c-483a-b2f4-8ac2248a896b', - 'timestamp': 1589707613899, - 'auctionStatus': 'inProgress', - 'adUnits': [ - { - 'code': 'div-gpt-ad-1533155193780-2', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ] - ] - } - }, - 'bids': [ - { - 'bidder': 'luponmedia', - 'params': { - 'siteId': 303522, - 'keyId': '4o2c4' - }, - 'crumbs': { - 'pubcid': 'aebbdfa9-3e0f-49b6-ad87-437aaa88db2d' - } - } - ], - 'sizes': [ - [ - 300, - 250 - ] - ], - 'transactionId': 'f68c54c2-0814-4ae5-95f5-09f6dd9dc1ef' - } - ], - 'adUnitCodes': [ - 'div-gpt-ad-1533155193780-2' - ], - 'labels': [ - 'BA' - ], - 'bidderRequests': [ - { - 'bidderCode': 'luponmedia', - 'auctionId': 'c4f0cce0-264c-483a-b2f4-8ac2248a896b', - 'bidderRequestId': '18c49b05a23645', - 'bids': [ - { - 'bidder': 'luponmedia', - 'params': { - 'siteId': 303522, - 'keyId': '4o2c4' - }, - 'crumbs': { - 'pubcid': 'aebbdfa9-3e0f-49b6-ad87-437aaa88db2d' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1533155193780-2', - 'transactionId': 'f68c54c2-0814-4ae5-95f5-09f6dd9dc1ef', - 'sizes': [ - [ - 300, - 250 - ] - ], - 'bidId': '284f8e1469246a', - 'bidderRequestId': '18c49b05a23645', - 'auctionId': 'c4f0cce0-264c-483a-b2f4-8ac2248a896b', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'novi.ba', - 'sid': '199424', - 'hp': 1 - } - ] - } - } - ], - 'auctionStart': 1589707613899, - 'timeout': 2000, - 'refererInfo': { - 'page': 'https://test.com/article/176067', - 'reachedTop': true, - 'numIframes': 0, - 'stack': [ - 'https://test.com/article/176067' - ] - }, - 'gdprConsent': {} - } - ], - 'noBids': [], - 'bidsReceived': [], - 'winningBids': [], - 'timeout': 2000, - 'config': { - 'pubId': 4444, - 'sid': 's2' - } - }; - - // requests & responses - const bidRequest = { - 'bidderCode': 'luponmedia', - 'auctionId': 'c4f0cce0-264c-483a-b2f4-8ac2248a896b', - 'bidderRequestId': '18c49b05a23645', - 'bids': [ - { - 'bidder': 'luponmedia', - 'params': { - 'siteId': 303522, - 'keyId': '4o2c4' - }, - 'crumbs': { - 'pubcid': 'aebbdfa9-3e0f-49b6-ad87-437aaa88db2d' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1533155193780-2', - 'transactionId': 'f68c54c2-0814-4ae5-95f5-09f6dd9dc1ef', - 'sizes': [ - [ - 300, - 250 - ] - ], - 'bidId': '284f8e1469246a', - 'bidderRequestId': '18c49b05a23645', - 'auctionId': 'c4f0cce0-264c-483a-b2f4-8ac2248a896b', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - }, - { - 'bidder': 'luponmedia', - 'params': { - 'siteId': 303522, - 'keyId': '4o2c5' - }, - 'crumbs': { - 'pubcid': 'aebbdfa9-3e0f-49b6-ad87-437aaa88db2d' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1533155193780-3', - 'transactionId': 'f68c54c2-0814-4ae5-95f5-09f6dd9dc1ef', - 'sizes': [ - [ - 300, - 250 - ] - ], - 'bidId': '284f8e1469246b', - 'bidderRequestId': '18c49b05a23645', - 'auctionId': 'c4f0cce0-264c-483a-b2f4-8ac2248a896b', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - } - ], - 'auctionStart': 1589707613899, - 'timeout': 2000, - 'refererInfo': { - 'page': 'https://test.com/article/176067', - 'reachedTop': true, - 'numIframes': 0, - 'stack': [ - 'https://test.com/article/176067' - ] - }, - 'start': 1589707613908 - }; - - const bidResponse = { - 'bidderCode': 'luponmedia', - 'width': 300, - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '3b40e0da8968f5', - 'requestId': '284f8e1469246a', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 0.43, - 'creativeId': '443801010', - 'currency': 'USD', - 'netRevenue': false, - 'ttl': 300, - 'referrer': '', - 'ad': " ", - 'originalCpm': '0.43', - 'originalCurrency': 'USD', - 'auctionId': 'c4f0cce0-264c-483a-b2f4-8ac2248a896b', - 'responseTimestamp': 1589707615188, - 'requestTimestamp': 1589707613908, - 'bidder': 'luponmedia', - 'adUnitCode': 'div-gpt-ad-1533155193780-2', - 'timeToRespond': 1280, - 'pbLg': '0.00', - 'pbMg': '0.40', - 'pbHg': '0.43', - 'pbAg': '0.40', - 'pbDg': '0.43', - 'pbCg': '0.43', - 'size': '300x250', - 'adserverTargeting': { - 'hb_bidder': 'luponmedia', - 'hb_adid': '3b40e0da8968f5', - 'hb_pb': '0.43', - 'hb_size': '300x250', - 'hb_source': 'client', - 'hb_format': 'banner' - } - }; - - // what we expect after general auction - - let expectedAfterBidData = JSON.parse(atob('eyJwdWJsaXNoZXJfaWQiOjEyMywiYXVjdGlvbl9pZCI6ImM0ZjBjY2UwLTI2NGMtNDgzYS1iMmY0LThhYzIyNDhhODk2YiIsInJlZmVyZXIiOiJodHRwczovL3Rlc3QuY29tL2FydGljbGUvMTc2MDY3Iiwic2NyZWVuX3Jlc29sdXRpb24iOiIxNDQweDkwMCIsImRldmljZV90eXBlIjoiZGVza3RvcCIsImdlbyI6bnVsbCwiZXZlbnRzIjpbeyJ0eXBlIjoiVElNRU9VVCIsImJpZGRlcl9jb2RlIjoibHVwb25tZWRpYSIsImV2ZW50X3RpbWVzdGFtcCI6MTU4OTcwNzYxMzkwOCwiYmlkX2dwdF9jb2RlcyI6eyJkaXYtZ3B0LWFkLTE1MzMxNTUxOTM3ODAtMiI6W1szMDAsMjUwXV0sImRpdi1ncHQtYWQtMTUzMzE1NTE5Mzc4MC0zIjpbWzMwMCwyNTBdXX19XX0=')); - expectedAfterBidData['screen_resolution'] = window.screen.width + 'x' + window.screen.height; - expectedAfterBidData = btoa(JSON.stringify(expectedAfterBidData)); - - const expectedAfterBid = { - 'query': 'mutation {createEvent(input: {event: {eventData: "' + expectedAfterBidData + '"}}) {event {createTime } } }' - }; - - // what we expect after timeout - - let expectedAfterTimeoutData = JSON.parse(atob('eyJwdWJsaXNoZXJfaWQiOjEyMywiYXVjdGlvbl9pZCI6ImM0ZjBjY2UwLTI2NGMtNDgzYS1iMmY0LThhYzIyNDhhODk2YiIsInJlZmVyZXIiOiJodHRwczovL3Rlc3QuY29tL2FydGljbGUvMTc2MDY3Iiwic2NyZWVuX3Jlc29sdXRpb24iOiIxNDQweDkwMCIsImRldmljZV90eXBlIjoiZGVza3RvcCIsImdlbyI6bnVsbCwiZXZlbnRzIjpbeyJ0eXBlIjoiVElNRU9VVCIsImJpZGRlcl9jb2RlIjoibHVwb25tZWRpYSIsImV2ZW50X3RpbWVzdGFtcCI6MTU4OTcwNzYxMzkwOCwiYmlkX2dwdF9jb2RlcyI6eyJkaXYtZ3B0LWFkLTE1MzMxNTUxOTM3ODAtMiI6W1szMDAsMjUwXV0sImRpdi1ncHQtYWQtMTUzMzE1NTE5Mzc4MC0zIjpbWzMwMCwyNTBdXX19XX0=')); - expectedAfterTimeoutData['screen_resolution'] = window.screen.width + 'x' + window.screen.height; - expectedAfterTimeoutData = btoa(JSON.stringify(expectedAfterTimeoutData)); - - const expectedAfterTimeout = { - 'query': 'mutation {createEvent(input: {event: {eventData: "' + expectedAfterTimeoutData + '"}}) {event {createTime } } }' - }; - - // lets simulate that some bidders timeout - const bidTimeoutArgsV1 = [ - { - 'bidId': '284f8e1469246b', - 'bidder': 'luponmedia', - 'adUnitCode': 'div-gpt-ad-1533155193780-3', - 'auctionId': 'c4f0cce0-264c-483a-b2f4-8ac2248a896b' - } - ]; - - // now simulate some WIN and RENDERING - const wonRequest = { - 'bidderCode': 'luponmedia', - 'width': 300, - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '3b40e0da8968f5', - 'requestId': '284f8e1469246a', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 0.43, - 'creativeId': '443801010', - 'currency': 'USD', - 'netRevenue': false, - 'ttl': 300, - 'referrer': '', - 'ad': " ", - 'originalCpm': '0.43', - 'originalCurrency': 'USD', - 'auctionId': 'c4f0cce0-264c-483a-b2f4-8ac2248a896b', - 'responseTimestamp': 1589707615188, - 'requestTimestamp': 1589707613908, - 'bidder': 'luponmedia', - 'adUnitCode': 'div-gpt-ad-1533155193780-2', - 'timeToRespond': 1280, - 'pbLg': '0.00', - 'pbMg': '0.40', - 'pbHg': '0.43', - 'pbAg': '0.40', - 'pbDg': '0.43', - 'pbCg': '0.43', - 'size': '300x250', - 'adserverTargeting': { - 'hb_bidder': 'luponmedia', - 'hb_adid': '3b40e0da8968f5', - 'hb_pb': '0.43', - 'hb_size': '300x250', - 'hb_source': 'client', - 'hb_format': 'banner' - }, - 'status': 'rendered', - 'params': [ - { - 'siteId': 303522, - 'keyId': '4o2c4' - } - ] - }; - - let wonExpectData = JSON.parse(atob('eyJwdWJsaXNoZXJfaWQiOjEyMywiYXVjdGlvbl9pZCI6ImM0ZjBjY2UwLTI2NGMtNDgzYS1iMmY0LThhYzIyNDhhODk2YiIsInJlZmVyZXIiOiJodHRwczovL3Rlc3QuY29tL2FydGljbGUvMTc2MDY3Iiwic2NyZWVuX3Jlc29sdXRpb24iOiIxNDQweDkwMCIsImRldmljZV90eXBlIjoiZGVza3RvcCIsImdlbyI6bnVsbCwiZXZlbnRzIjpbeyJ0eXBlIjoiVElNRU9VVCIsImJpZGRlcl9jb2RlIjoibHVwb25tZWRpYSIsImV2ZW50X3RpbWVzdGFtcCI6MTU4OTcwNzYxMzkwOCwiYmlkX2dwdF9jb2RlcyI6eyJkaXYtZ3B0LWFkLTE1MzMxNTUxOTM3ODAtMiI6W1szMDAsMjUwXV0sImRpdi1ncHQtYWQtMTUzMzE1NTE5Mzc4MC0zIjpbWzMwMCwyNTBdXX19LHsidHlwZSI6IlJFU1BPTlNFIiwiYmlkZGVyX2NvZGUiOiJsdXBvbm1lZGlhIiwiZXZlbnRfdGltZXN0YW1wIjoxNTg5NzA3NjE1MTg4LCJzaXplIjoiMzAweDI1MCIsImdwdF9jb2RlIjoiZGl2LWdwdC1hZC0xNTMzMTU1MTkzNzgwLTIiLCJjdXJyZW5jeSI6IlVTRCIsImNyZWF0aXZlX2lkIjoiNDQzODAxMDEwIiwidGltZV90b19yZXNwb25kIjoxMjgwLCJjcG0iOjAuNDMsImlzX3dpbm5pbmciOmZhbHNlfV19')); - wonExpectData['screen_resolution'] = window.screen.width + 'x' + window.screen.height; - wonExpectData = btoa(JSON.stringify(wonExpectData)); - - const wonExpect = { - 'query': 'mutation {createEvent(input: {event: {eventData: "' + wonExpectData + '"}}) {event {createTime } } }' - }; - - adapterManager.registerAnalyticsAdapter({ - code: 'adxpremium', - adapter: adxpremiumAnalyticsAdapter - }); - - beforeEach(function () { - adapterManager.enableAnalytics({ - provider: 'adxpremium', - options: initOptions - }); - }); - - afterEach(function () { - adxpremiumAnalyticsAdapter.disableAnalytics(); - }); - - it('builds and sends auction data', function () { - // Step 1: Send auction init event - events.emit(EVENTS.AUCTION_INIT, auctionInit); - - // Step 2: Send bid requested event - events.emit(EVENTS.BID_REQUESTED, bidRequest); - - // Step 3: Send bid response event - events.emit(EVENTS.BID_RESPONSE, bidResponse); - - // Step 4: Send bid time out event - events.emit(EVENTS.BID_TIMEOUT, bidTimeoutArgsV1); - - // Step 5: Send auction end event - events.emit(EVENTS.AUCTION_END, {}); - - testSend(); - - expect(server.requests.length).to.equal(2); - - const realAfterBid = JSON.parse(server.requests[0].requestBody); - - expect(realAfterBid).to.deep.equal(expectedAfterBid); - - // expect after timeout - expect(realAfterBid).to.deep.equal(expectedAfterTimeout); - - // Step 6: Send auction bid won event - events.emit(EVENTS.BID_WON, wonRequest); - - expect(server.requests.length).to.equal(3); - const winEventData = JSON.parse(server.requests[1].requestBody); - - expect(winEventData).to.deep.equal(wonExpect); - }); - }); -}); diff --git a/test/spec/modules/adyoulikeBidAdapter_spec.js b/test/spec/modules/adyoulikeBidAdapter_spec.js deleted file mode 100644 index 337bd6fea..000000000 --- a/test/spec/modules/adyoulikeBidAdapter_spec.js +++ /dev/null @@ -1,1014 +0,0 @@ -import { expect } from 'chai'; - -import { spec } from 'modules/adyoulikeBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; - -describe('Adyoulike Adapter', function () { - const canonicalUrl = 'https://canonical.url/?t=%26'; - const referrerUrl = 'http://referrer.url/?param=value'; - const pageUrl = 'http://page.url/?param=value'; - const domain = 'domain:123'; - const defaultDC = 'hb-api'; - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - consentString: consentString, - gdprApplies: true - }, - refererInfo: {location: referrerUrl, canonicalUrl, domain, topmostLocation: 'fakePageURL'}, - ortb2: {site: {page: pageUrl, ref: referrerUrl}} - }; - const bidRequestWithEmptyPlacement = [ - { - 'bidId': 'bid_id_0', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-0', - 'params': {}, - 'sizes': '300x250', - 'mediaTypes': - { 'banner': - {'sizes': ['300x250', '300x600'] - } - } - } - ]; - const bidRequestWithEmptySizes = { - 'bids': [ - { - 'bidId': 'bid_id_0', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-0', - 'params': { - 'placement': 'placement_0' - }, - 'ortb2Imp': { - 'ext': { - 'tid': 'bid_id_0_transaction_id' - } - }, - } - ], - }; - - const bidRequestWithSinglePlacement = [ - { - 'bidId': 'bid_id_0', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-0', - 'params': { - 'placement': 'placement_0' - }, - 'sizes': '300x250', - 'mediaTypes': - { 'banner': - {'sizes': ['300x250'] - }, - 'native': - { 'image': { - 'required': true, - }, - 'title': { - 'required': true, - 'len': 80 - }, - 'cta': { - 'required': false - }, - 'sponsoredBy': { - 'required': true - }, - 'clickUrl': { - 'required': true - }, - 'privacyIcon': { - 'required': false - }, - 'privacyLink': { - 'required': false - }, - 'body': { - 'required': true - }, - 'icon': { - 'required': true, - 'sizes': [] - } - }, - }, - 'ortb2': { - 'source': { - 'ext': { - 'schain': { - validation: 'strict', - config: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'indirectseller.com', - sid: '00001', - hp: 1 - } - ] - } - } - } - } - }, - ortb2Imp: { - ext: { - tid: 'bid_id_0_transaction_id' - } - } - } - ]; - - const bidRequestWithMultipleMediatype = [ - { - 'bidId': 'bid_id_0', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-0', - 'params': { - 'placement': 'placement_0' - }, - 'sizes': '300x250', - 'mediaTypes': { - 'banner': { - 'sizes': ['640x480'] - }, - 'video': { - 'playerSize': [640, 480], - 'context': 'outstream' - }, - 'native': { - 'image': { - 'required': true, - }, - 'title': { - 'required': true, - 'len': 80 - }, - 'cta': { - 'required': false - }, - } - }, - ortb2Imp: { - ext: { - tid: 'bid_id_0_transaction_id' - } - }, - } - ]; - - const bidRequestWithVideo = [ - { - 'bidId': 'bid_id_0', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-0', - 'params': { - 'placement': 'placement_0' - }, - 'sizes': '300x250', - 'mediaTypes': - { - 'video': { - 'context': 'instream', - 'playerSize': [[ 640, 480 ]] - } - }, - ortb2Imp: { - ext: { - tid: 'bid_id_0_transaction_id' - } - }, - } - ]; - - const bidRequestWithNativeImageType = [ - { - 'bidId': 'bid_id_0', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-0', - 'params': { - 'placement': 'placement_0' - }, - 'sizes': '300x250', - 'mediaTypes': - { - 'native': { - 'type': 'image', - 'additional': { - 'will': 'be', - 'sent': ['300x250'] - } - }, - }, - ortb2Imp: { - ext: { - tid: 'bid_id_0_transaction_id' - } - }, - } - ]; - - const sentBidNative = { - 'bid_id_0': { - 'PlacementID': 'e622af275681965d3095808561a1e510', - 'TransactionID': 'e8355240-d976-4cd5-a493-640656fe08e8', - 'AvailableSizes': '', - 'Native': { - 'image': { - 'required': true, - 'sizes': [] - }, - 'title': { - 'required': true, - 'len': 80 - }, - 'cta': { - 'required': false - }, - 'sponsoredBy': { - 'required': true - }, - 'clickUrl': { - 'required': true - }, - 'privacyIcon': { - 'required': false - }, - 'privacyLink': { - 'required': false - }, - 'body': { - 'required': true - }, - 'icon': { - 'required': true, - 'sizes': [] - } - } - } - }; - - const sentBidVideo = { - 'bid_id_0': { - 'PlacementID': 'e622af275681965d3095808561a1e510', - 'TransactionID': 'e8355240-d976-4cd5-a493-640656fe08e8', - 'AvailableSizes': '', - 'Video': { - playerSize: [640, 480] - } - } - }; - - const sentNativeImageType = { - 'additional': { - 'sent': [ - '300x250' - ], - 'will': 'be' - }, - 'body': { - 'required': false - }, - 'clickUrl': { - 'required': true - }, - 'cta': { - 'required': false - }, - 'icon': { - 'required': false - }, - 'image': { - 'required': true - }, - 'sponsoredBy': { - 'required': true - }, - 'title': { - 'required': true - }, - 'type': 'image' - }; - - const bidRequestWithDCPlacement = [ - { - 'bidId': 'bid_id_0', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-0', - 'params': { - 'placement': 'placement_0', - 'DC': 'fra01' - }, - 'sizes': '300x250', - 'mediaTypes': - { 'banner': - {'sizes': ['300x250'] - } - }, - ortb2Imp: { - ext: { - tid: 'bid_id_0_transaction_id' - } - }, - } - ]; - - const bidRequestMultiPlacements = [ - { - 'bidId': 'bid_id_0', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-0', - 'params': { - 'placement': 'placement_0' - }, - 'sizes': '300x250', - 'mediaTypes': - { 'banner': - {'sizes': ['300x250'] - } - }, - ortb2Imp: { - ext: { - tid: 'bid_id_0_transaction_id' - } - }, - }, - { - 'bidId': 'bid_id_1', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-1', - 'params': { - 'placement': 'placement_1' - }, - 'sizes': [[300, 600]], - 'mediaTypes': - { 'banner': - {'sizes': ['300x600'] - } - }, - ortb2Imp: { - ext: { - tid: 'bid_id_1_transaction_id' - } - }, - }, - { - 'bidId': 'bid_id_2', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-2', - 'params': {}, - 'sizes': '300x400', - ortb2Imp: { - ext: { - tid: 'bid_id_2_transaction_id' - } - }, - }, - { - 'bidId': 'bid_id_3', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-3', - 'params': { - 'placement': 'placement_3' - }, - ortb2Imp: { - ext: { - tid: 'bid_id_3_transaction_id' - } - }, - } - ]; - - const requestDataOnePlacement = { - 'bid_id_0': - { 'PlacementID': 'e622af275681965d3095808561a1e510', - 'TransactionID': '1bca18cc-c0fe-439b-88c2-8247d3448f22', - 'Width': 300, - 'Height': 600, - 'AvailableSizes': '300x600' - } - } - - const requestDataMultiPlacement = { - 'bid_id_0': - { 'PlacementID': 'e622af275681965d3095808561a1e510', - 'TransactionID': '1bca18cc-c0fe-439b-88c2-8247d3448f22', - 'Width': 300, - 'Height': 600, - 'AvailableSizes': '300x600' - }, - 'bid_id_1': - { 'PlacementID': 'e622af275681965d3095808561a1e510', - 'TransactionID': 'e63b2d86-ca60-4167-9cf1-497607079634', - 'Width': 400, - 'Height': 250, - 'AvailableSizes': '300x250' - } - } - - const responseWithEmptyPlacement = [ - { - 'Placement': 'placement_0' - } - ]; - - const testMetaObject = { - 'networkId': 123, - 'advertiserId': '3', - 'advertiserName': 'foobar', - 'advertiserDomains': ['foobar.com'], - 'brandId': '345', - 'brandName': 'Foo', - 'primaryCatId': '34', - 'secondaryCatIds': ['IAB-222', 'IAB-333'], - 'mediaType': 'banner' - }; - const admSample = "\u003cscript id=\"ayl-prebid-a11a121205932e75e622af275681965d\"\u003e\n(function(){\n\twindow.isPrebid = true\n\tvar prebidResults = /*PREBID*/{\"OnEvents\": {\"CLICK\": [{\"Kind\": \"PIXEL_URL\",\"Url\": \"https://testPixelCLICK.com/fake\"}],\"IMPRESSION\": [{\"Kind\": \"PIXEL_URL\",\"Url\": \"https://testPixelIMP.com/fake\"}, {\"Kind\": \"JAVASCRIPT_URL\",\"Url\": \"https://testJsIMP.com/fake.js\"}]},\"Disabled\": false,\"Attempt\": \"a11a121205932e75e622af275681965d\",\"ApiPrefix\": \"https://fo-api.omnitagjs.com/fo-api\",\"TrackingPrefix\": \"https://tracking.omnitagjs.com/tracking\",\"DynamicPrefix\": \"https://tag-dyn.omnitagjs.com/fo-dyn\",\"StaticPrefix\": \"https://fo-static.omnitagjs.com/fo-static\",\"BlobPrefix\": \"https://fo-api.omnitagjs.com/fo-api/blobs\",\"SspPrefix\": \"https://fo-ssp.omnitagjs.com/fo-ssp\",\"VisitorPrefix\": \"https://visitor.omnitagjs.com/visitor\",\"Trusted\": true,\"Placement\": \"e622af275681965d3095808561a1e510\",\"PlacementAccess\": \"ALL\",\"Site\": \"6e2df7a92203c3c7a25561ed63f25a27\",\"Lang\": \"EN\",\"SiteLogo\": null,\"HasSponsorImage\": true,\"ResizeIframe\": true,\"IntegrationConfig\": {\"Kind\": \"WIDGET\",\"Widget\": {\"ExtraStyleSheet\": \"\",\"Placeholders\": {\"Body\": {\"Color\": {\"R\": 77,\"G\": 21,\"B\": 82,\"A\": 100},\"BackgroundColor\": {\"R\": 255,\"G\": 255,\"B\": 255,\"A\": 100},\"FontFamily\": \"Lato\",\"Width\": \"100%\",\"Align\": \"\",\"BoxShadow\": true},\"CallToAction\": {\"Color\": {\"R\": 26,\"G\": 157,\"B\": 212,\"A\": 100}},\"Description\": {\"Length\": 130},\"Image\": {\"Width\": 600,\"Height\": 600,\"Lowres\": false,\"Raw\": false},\"Size\": {\"Height\": \"250px\",\"Width\": \"300px\"},\"Title\": {\"Color\": {\"R\": 219,\"G\": 181,\"B\": 255,\"A\": 100}}},\"Selector\": {\"Kind\": \"CSS\",\"Css\": \"#ayl-prebid-a11a121205932e75e622af275681965d\"},\"Insertion\": \"AFTER\",\"ClickFormat\": true,\"Creative20\": true,\"WidgetKind\": \"CREATIVE_TEMPLATE_4\"}},\"Legal\": \"Sponsored\",\"ForcedCampaign\": \"f1c80d4bb5643c222ae8de75e9b2f991\",\"ForcedTrack\": \"\",\"ForcedCreative\": \"\",\"ForcedSource\": \"\",\"DisplayMode\": \"DEFAULT\",\"Campaign\": \"f1c80d4bb5643c222ae8de75e9b2f991\",\"CampaignAccess\": \"ALL\",\"CampaignKind\": \"AD_TRAFFIC\",\"DataSource\": \"LOCAL\",\"DataSourceUrl\": \"\",\"DataSourceOnEventsIsolated\": false,\"DataSourceWithoutCookie\": false,\"Content\": {\"Preview\": {\"Thumbnail\": {\"Image\": {\"Kind\": \"EXTERNAL\",\"Data\": {\"External\": {\"Url\": \"https://tag-dyn.omnitagjs.com/fo-dyn/native/preview/image?key=fd4362d35bb174d6f1c80d4bb5643c22\\u0026kind=INTERNAL\\u0026ztop=0.000000\\u0026zleft=0.000000\\u0026zwidth=0.333333\\u0026zheight=1.000000\\u0026width=[width]\\u0026height=[height]\"}},\"ZoneTop\": 0,\"ZoneLeft\": 0,\"ZoneWidth\": 1,\"ZoneHeight\": 1,\"Smart\": false,\"NoTransform\": false,\"Quality\": \"NORMAL\"}},\"Text\": {\"CALLTOACTION\": \"Click here to learn more\",\"DESCRIPTION\": \"Considérant l'extrémité conjoncturelle, il serait bon d'anticiper toutes les voies de bon sens.\",\"SPONSOR\": \"Tested by\",\"TITLE\": \"Adserver Traffic Redirect Internal\"},\"Sponsor\": {\"Name\": \"QA Team\",\"Logo\": {\"Resource\": {\"Kind\": \"EXTERNAL\",\"Data\": {\"External\": {\"Url\": \"https://fo-static.omnitagjs.com/fo-static/native/images/info-ayl.svg\"}},\"ZoneTop\": 0,\"ZoneLeft\": 0,\"ZoneWidth\": 1,\"ZoneHeight\": 1,\"Smart\": false,\"NoTransform\": false,\"Quality\": \"NORMAL\"}}},\"Credit\": {\"Logo\": {\"Resource\": {\"Kind\": \"EXTERNAL\",\"Data\": {\"External\": {\"Url\": \"https://fo-static.omnitagjs.com/fo-static/native/images/info-ayl.png\"}},\"ZoneTop\": 0,\"ZoneLeft\": 0,\"ZoneWidth\": 1,\"ZoneHeight\": 1,\"Smart\": false,\"NoTransform\": false,\"Quality\": \"NORMAL\"}},\"Url\": \"https://blobs.omnitagjs.com/adchoice/\"}},\"Landing\": {\"Url\": \"https://www.w3.org/People/mimasa/test/xhtml/entities/entities-11.xhtml#lat1\",\"LegacyTracking\": false},\"ViewButtons\": {\"Close\": {\"Skip\": 6000}},\"InternalContentFields\": {\"AnimatedImage\": false}},\"AdDomain\": \"adyoulike.com\",\"Opener\": \"REDIRECT\",\"PerformUITriggers\": [\"CLICK\"],\"RedirectionTarget\": \"TAB\"}/*PREBID*/;\n\tvar insertAds = function insertAds() {\insertAds();\n\t}\n})();\n\u003c/script\u003e"; - const responseWithSinglePlacement = [ - { - 'BidID': 'bid_id_0', - 'Placement': 'placement_0', - 'Ad': admSample, - 'Price': 0.5, - 'Height': 600, - 'Meta': testMetaObject - } - ]; - - const responseWithSingleNative = [{ - 'BidID': 'bid_id_0', - 'Placement': 'placement_0', - 'Native': { - 'body': 'Considérant l\'extrémité conjoncturelle, il serait bon d\'anticiper toutes les voies de bon sens.', - 'cta': 'Click here to learn more', - 'clickUrl': 'https://tracking.omnitagjs.com/tracking/ar?event_kind=CLICK&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991&url=https%3A%2F%2Fwww.w3.org%2FPeople%2Fmimasa%2Ftest%2Fxhtml%2Fentities%2Fentities-11.xhtml%23lat1', - 'image': { - 'height': 600, - 'url': 'https://blobs.omnitagjs.com/blobs/f1/f1c80d4bb5643c22/fd4362d35bb174d6f1c80d4bb5643c22', - 'width': 300 - }, - 'icon': { - 'height': 50, - 'url': 'https://fo-static.omnitagjs.com/fo-static/native/images/info-ayl.svg', - 'width': 50, - }, - 'privacyIcon': 'https://fo-static.omnitagjs.com/fo-static/native/images/info-ayl.png', - 'privacyLink': 'https://blobs.omnitagjs.com/adchoice/', - 'sponsoredBy': 'QA Team', - 'title': 'Adserver Traffic Redirect Internal', - 'impressionTrackers': [ - 'https://testPixelIMP.com/fake', - 'https://tracking.omnitagjs.com/tracking/pixel?event_kind=IMPRESSION&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991', - 'https://tracking.omnitagjs.com/tracking/pixel?event_kind=INSERTION&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991', - ], - 'javascriptTrackers': [ - 'https://testJsIMP.com/fake.js' - ], - 'clickTrackers': [ - 'https://testPixelCLICK.com/fake' - ] - }, - 'Price': 0.5, - 'Height': 600, - }]; - - const nativeResult = [{ - cpm: 0.5, - creativeId: undefined, - currency: 'USD', - netRevenue: true, - requestId: 'bid_id_0', - ttl: 3600, - mediaType: 'native', - native: { - body: 'Considérant l\'extrémité conjoncturelle, il serait bon d\'anticiper toutes les voies de bon sens.', - clickTrackers: [ - 'https://testPixelCLICK.com/fake' - ], - clickUrl: 'https://tracking.omnitagjs.com/tracking/ar?event_kind=CLICK&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991&url=https%3A%2F%2Fwww.w3.org%2FPeople%2Fmimasa%2Ftest%2Fxhtml%2Fentities%2Fentities-11.xhtml%23lat1', - cta: 'Click here to learn more', - image: { - height: 600, - url: 'https://blobs.omnitagjs.com/blobs/f1/f1c80d4bb5643c22/fd4362d35bb174d6f1c80d4bb5643c22', - width: 300, - }, - icon: { - height: 50, - url: 'https://fo-static.omnitagjs.com/fo-static/native/images/info-ayl.svg', - width: 50, - }, - impressionTrackers: [ - 'https://testPixelIMP.com/fake', - 'https://tracking.omnitagjs.com/tracking/pixel?event_kind=IMPRESSION&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991', - 'https://tracking.omnitagjs.com/tracking/pixel?event_kind=INSERTION&attempt=a11a121205932e75e622af275681965d&campaign=f1c80d4bb5643c222ae8de75e9b2f991' - ], - javascriptTrackers: [ - 'https://testJsIMP.com/fake.js' - ], - privacyIcon: 'https://fo-static.omnitagjs.com/fo-static/native/images/info-ayl.png', - privacyLink: 'https://blobs.omnitagjs.com/adchoice/', - sponsoredBy: 'QA Team', - title: 'Adserver Traffic Redirect Internal', - }, - meta: testMetaObject - }]; - - const responseWithSingleVideo = [{ - 'BidID': 'bid_id_0', - 'Placement': 'placement_0', - 'Vast': 'PFZBU1Q+RW1wdHkgc2FtcGxlPC92YXN0Pg==', - 'Price': 0.5, - 'Height': 300, - 'Width': 530 - }]; - - const videoResult = [{ - cpm: 0.5, - creativeId: undefined, - currency: 'USD', - height: 300, - netRevenue: true, - requestId: 'bid_id_0', - ttl: 3600, - mediaType: 'video', - meta: { - advertiserDomains: [] - }, - vastXml: 'Empty sample', - width: 530 - }]; - - const responseWithMultiplePlacements = [ - { - 'BidID': 'bid_id_0', - 'Placement': 'placement_0', - 'Ad': 'placement_0', - 'Price': 0.5, - 'Height': 0, // test with wrong value - 'Width': 300 - }, - { - 'BidID': 'bid_id_1', - 'Placement': 'placement_1', - 'Ad': 'placement_1', - 'Price': 0.6, - 'Height': 250 - // 'Width' test with missing value - } - ]; - const adapter = newBidder(spec); - - const getEndpoint = (dc = defaultDC) => `https://${dc}.omnitagjs.com/hb-api/prebid`; - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidId': 'bid_id_1', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-1', - 'params': { - 'placement': 'placement_1' - }, - 'sizes': [[300, 600]], - 'transactionId': 'bid_id_1_transaction_id' - }; - - const bidWSize = { - 'bidId': 'bid_id_1', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-1', - 'params': { - 'placement': 'placement_1', - 'size': [250, 300], - }, - 'transactionId': 'bid_id_1_transaction_id' - }; - - const nativeBid = { - 'bidId': 'bid_id_1', - 'bidder': 'adyoulike', - 'placementCode': 'adunit/hb-1', - 'params': { - 'placement': 'placement_1' - }, - mediaTypes: { - native: { - - } - }, - 'transactionId': 'bid_id_1_transaction_id' - }; - - it('should return true when required params found', function () { - expect(!!spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when required params found with size in bid params', function () { - expect(!!spec.isBidRequestValid(bidWSize)).to.equal(true); - }); - - it('should return true when required params found for native ad', function () { - expect(!!spec.isBidRequestValid(nativeBid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.sizes; - - expect(!!spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'placement': 0 - }; - expect(!!spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('Should expand short native image config type', function() { - const request = spec.buildRequests(bidRequestWithNativeImageType, bidderRequest); - const payload = JSON.parse(request.data); - - expect(request.url).to.contain(getEndpoint()); - expect(request.method).to.equal('POST'); - expect(request.url).to.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl)); - expect(request.url).to.contains('RefererUrl=' + encodeURIComponent(referrerUrl)); - expect(request.url).to.contains('PageUrl=' + encodeURIComponent(pageUrl)); - expect(request.url).to.contains('PageReferrer=' + encodeURIComponent(referrerUrl)); - - expect(payload.Version).to.equal('1.0'); - expect(payload.Bids['bid_id_0'].PlacementID).to.be.equal('placement_0'); - expect(payload.PageRefreshed).to.equal(false); - expect(payload.Bids['bid_id_0'].TransactionID).to.be.equal('bid_id_0_transaction_id'); - expect(payload.Bids['bid_id_0'].Native).deep.equal(sentNativeImageType); - }); - - it('Should target video enpoint for video mediatype', function() { - const request = spec.buildRequests(bidRequestWithVideo, bidderRequest); - expect(request.url).to.contain(getEndpoint()); - }); - - it('should add gdpr/usp consent information and SChain to the request', function () { - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const uspConsentData = '1YCC'; - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - consentString: consentString, - gdprApplies: true - }, - 'uspConsent': uspConsentData - }; - - bidderRequest.bids = bidRequestWithSinglePlacement; - - const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdprConsent).to.exist; - expect(payload.gdprConsent.consentString).to.exist.and.to.equal(consentString); - expect(payload.gdprConsent.consentRequired).to.exist.and.to.be.true; - expect(payload.uspConsent).to.exist.and.to.equal(uspConsentData); - expect(payload.Bids.bid_id_0.SChain).to.exist.and.to.deep.equal(bidRequestWithSinglePlacement[0].ortb2.source.ext.schain); - }); - - it('should not set a default value for gdpr consentRequired', function () { - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const uspConsentData = '1YCC'; - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - consentString: consentString - }, - 'uspConsent': uspConsentData - }; - - bidderRequest.bids = bidRequestWithSinglePlacement; - - const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdprConsent).to.exist; - expect(payload.gdprConsent.consentString).to.exist.and.to.equal(consentString); - expect(payload.gdprConsent.consentRequired).to.be.null; - }); - - it('should add eids eids information to the request', function () { - const bidRequest = bidRequestWithSinglePlacement; - bidRequest[0].userIdAsEids = [{ - 'source': 'pubcid.org', - 'uids': [{ - 'atype': 1, - 'id': '01EAJWWNEPN3CYMM5N8M5VXY22' - }] - }] - - const request = spec.buildRequests(bidRequest, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.eids).to.exist; - expect(payload.eids).to.deep.equal(bidRequest[0].userIdAsEids); - }); - - it('sends bid request to endpoint with single placement', function () { - const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest); - const payload = JSON.parse(request.data); - - expect(request.url).to.contain(getEndpoint()); - expect(request.method).to.equal('POST'); - expect(request.url).to.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl)); - expect(request.url).to.contains('RefererUrl=' + encodeURIComponent(referrerUrl)); - expect(request.url).to.contains('PageUrl=' + encodeURIComponent(pageUrl)); - expect(request.url).to.contains('PageReferrer=' + encodeURIComponent(referrerUrl)); - - expect(payload.Version).to.equal('1.0'); - expect(payload.Bids['bid_id_0'].PlacementID).to.be.equal('placement_0'); - expect(payload.PageRefreshed).to.equal(false); - expect(payload.Bids['bid_id_0'].TransactionID).to.be.equal('bid_id_0_transaction_id'); - expect(payload.ortb2).to.deep.equal({site: {page: pageUrl, ref: referrerUrl}}); - }); - - it('sends bid request to endpoint with single placement without canonical', function () { - const request = spec.buildRequests(bidRequestWithSinglePlacement, {...bidderRequest, refererInfo: {...bidderRequest.refererInfo, canonicalUrl: null}}); - const payload = JSON.parse(request.data); - - expect(request.url).to.contain(getEndpoint()); - expect(request.method).to.equal('POST'); - - expect(request.url).to.not.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl)); - expect(payload.Version).to.equal('1.0'); - expect(payload.Bids['bid_id_0'].PlacementID).to.be.equal('placement_0'); - expect(payload.PageRefreshed).to.equal(false); - expect(payload.pbjs_version).to.equal('$prebid.version$'); - expect(payload.Bids['bid_id_0'].TransactionID).to.be.equal('bid_id_0_transaction_id'); - }); - - it('sends bid request to endpoint with single placement multiple mediatype', function () { - const request = spec.buildRequests(bidRequestWithSinglePlacement, {...bidderRequest, refererInfo: {...bidderRequest.refererInfo, canonicalUrl: null}}); - const payload = JSON.parse(request.data); - - expect(request.url).to.contain(getEndpoint()); - expect(request.method).to.equal('POST'); - - expect(request.url).to.not.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl)); - expect(payload.Version).to.equal('1.0'); - expect(payload.Bids['bid_id_0'].PlacementID).to.be.equal('placement_0'); - expect(payload.PageRefreshed).to.equal(false); - expect(payload.pbjs_version).to.equal('$prebid.version$'); - expect(payload.Bids['bid_id_0'].TransactionID).to.be.equal('bid_id_0_transaction_id'); - }); - - it('sends bid request to endpoint with multiple placements', function () { - const request = spec.buildRequests(bidRequestMultiPlacements, bidderRequest); - const payload = JSON.parse(request.data); - expect(request.url).to.contain(getEndpoint()); - expect(request.method).to.equal('POST'); - - expect(request.url).to.contains('CanonicalUrl=' + encodeURIComponent(canonicalUrl)); - expect(request.url).to.contains('RefererUrl=' + encodeURIComponent(referrerUrl)); - - expect(payload.Version).to.equal('1.0'); - - expect(payload.Bids['bid_id_0'].PlacementID).to.be.equal('placement_0'); - expect(payload.Bids['bid_id_1'].PlacementID).to.be.equal('placement_1'); - expect(payload.Bids['bid_id_3'].PlacementID).to.be.equal('placement_3'); - - expect(payload.Bids['bid_id_0'].TransactionID).to.be.equal('bid_id_0_transaction_id'); - expect(payload.Bids['bid_id_1'].TransactionID).to.be.equal('bid_id_1_transaction_id'); - expect(payload.Bids['bid_id_3'].TransactionID).to.be.equal('bid_id_3_transaction_id'); - expect(payload.PageRefreshed).to.equal(false); - expect(payload.pbjs_version).to.equal('$prebid.version$'); - }); - - it('sends bid request to endpoint setted by parameters', function () { - const request = spec.buildRequests(bidRequestWithDCPlacement, bidderRequest); - const payload = JSON.parse(request.data); - - expect(request.url).to.contain(getEndpoint(`${defaultDC}-fra01`)); - }); - }); - // - describe('interpretResponse', function () { - let serverResponse; - - beforeEach(function () { - serverResponse = { - body: {} - } - }); - - it('handles 204 responses', function () { - serverResponse.body = ''; - const result = spec.interpretResponse(serverResponse, []); - expect(result).deep.equal([]); - }); - - it('handles nobid responses', function () { - const response = [{ - BidID: '123dfsdf', - Attempt: '32344fdse1', - Placement: '12df1' - }]; - serverResponse.body = response; - const result = spec.interpretResponse(serverResponse, []); - expect(result).deep.equal([]); - }); - - it('receive reponse with single placement', function () { - serverResponse.body = responseWithSinglePlacement; - const result = spec.interpretResponse(serverResponse, {data: '{"Bids":' + JSON.stringify(requestDataOnePlacement) + '}'}); - - expect(result.length).to.equal(1); - expect(result[0].cpm).to.equal(0.5); - expect(result[0].ad).to.equal(admSample); - expect(result[0].width).to.equal(300); - expect(result[0].height).to.equal(600); - expect(result[0].meta).to.deep.equal(testMetaObject); - }); - - it('receive reponse with multiple placement', function () { - serverResponse.body = responseWithMultiplePlacements; - const result = spec.interpretResponse(serverResponse, {data: '{"Bids":' + JSON.stringify(requestDataMultiPlacement) + '}'}); - - expect(result.length).to.equal(2); - - expect(result[0].cpm).to.equal(0.5); - expect(result[0].ad).to.equal('placement_0'); - expect(result[0].width).to.equal(300); - expect(result[0].height).to.equal(600); - - expect(result[1].cpm).to.equal(0.6); - expect(result[1].ad).to.equal('placement_1'); - expect(result[1].width).to.equal(400); - expect(result[1].height).to.equal(250); - }); - - it('receive reponse with Native from ad markup', function () { - serverResponse.body = responseWithSinglePlacement; - const result = spec.interpretResponse(serverResponse, {data: '{"Bids":' + JSON.stringify(sentBidNative) + '}'}); - - expect(result.length).to.equal(1); - - expect(result).to.deep.equal(nativeResult); - }); - - it('receive reponse with Native ad', function () { - serverResponse.body = responseWithSingleNative; - const result = spec.interpretResponse(serverResponse, {data: '{"Bids":' + JSON.stringify(sentBidNative) + '}'}); - - expect(result.length).to.equal(1); - - const noMeta = [...nativeResult]; - const metaBackup = noMeta[0].meta; - - // this test should return default meta object - noMeta[0].meta = { advertiserDomains: [] }; - - expect(result).to.deep.equal(noMeta); - }); - - it('receive Vast reponse with Video ad', function () { - serverResponse.body = responseWithSingleVideo; - const result = spec.interpretResponse(serverResponse, {data: '{"Bids":' + JSON.stringify(sentBidVideo) + '}'}); - - expect(result.length).to.equal(1); - expect(result).to.deep.equal(videoResult); - }); - - it('should expose gvlid', function() { - expect(spec.gvlid).to.equal(259) - }) - }); - - describe('getUserSyncs', function () { - const syncurl_iframe = 'https://visitor.omnitagjs.com/visitor/isync?uid=19340f4f097d16f41f34fc0274981ca4'; - - const emptySync = []; - - describe('with iframe enabled', function() { - const userSyncConfig = { iframeEnabled: true }; - - it('should not add parameters if not provided', function() { - expect(spec.getUserSyncs(userSyncConfig, {}, undefined, undefined)).to.deep.equal([{ - type: 'iframe', url: `${syncurl_iframe}` - }]); - }); - - it('should add GDPR parameters if provided', function() { - expect(spec.getUserSyncs(userSyncConfig, {}, {gdprApplies: true, consentString: undefined}, undefined)).to.deep.equal([{ - type: 'iframe', url: `${syncurl_iframe}&gdpr=1&gdpr_consent=` - }]); - - expect(spec.getUserSyncs(userSyncConfig, {}, {gdprApplies: true, consentString: 'foo?'}, undefined)).to.deep.equal([{ - type: 'iframe', url: `${syncurl_iframe}&gdpr=1&gdpr_consent=foo%3F` - }]); - expect(spec.getUserSyncs(userSyncConfig, {}, {gdprApplies: false, consentString: 'bar'}, undefined)).to.deep.equal([{ - type: 'iframe', url: `${syncurl_iframe}&gdpr=0&gdpr_consent=bar` - }]); - }); - - it('should add CCPA parameters if provided', function() { - expect(spec.getUserSyncs(userSyncConfig, {}, undefined, 'foo?')).to.deep.equal([{ - type: 'iframe', url: `${syncurl_iframe}&us_privacy=foo%3F` - }]); - }); - - describe('COPPA', function() { - let sandbox; - - this.beforeEach(function() { - sandbox = sinon.createSandbox(); - }); - - this.afterEach(function() { - sandbox.restore(); - }); - - it('should add coppa parameters if provided', function() { - sandbox.stub(config, 'getConfig').callsFake(key => { - const config = { - 'coppa': true - }; - return config[key]; - }); - - expect(spec.getUserSyncs(userSyncConfig, {}, undefined, undefined)).to.deep.equal([{ - type: 'iframe', url: `${syncurl_iframe}&coppa=1` - }]); - }); - }); - - describe('GPP', function() { - it('should not apply if not gppConsent.gppString', function() { - const gppConsent = { gppString: '', applicableSections: [123] }; - const result = spec.getUserSyncs(userSyncConfig, {}, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${syncurl_iframe}` - }]); - }); - - it('should not apply if not gppConsent.applicableSections', function() { - const gppConsent = { gppString: '', applicableSections: undefined }; - const result = spec.getUserSyncs(userSyncConfig, {}, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${syncurl_iframe}` - }]); - }); - - it('should not apply if empty gppConsent.applicableSections', function() { - const gppConsent = { gppString: '', applicableSections: [] }; - const result = spec.getUserSyncs(userSyncConfig, {}, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${syncurl_iframe}` - }]); - }); - - it('should apply if all above are available', function() { - const gppConsent = { gppString: 'foo?', applicableSections: [123] }; - const result = spec.getUserSyncs(userSyncConfig, {}, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${syncurl_iframe}&gpp=foo%3F&gpp_sid=123` - }]); - }); - - it('should support multiple sections', function() { - const gppConsent = { gppString: 'foo', applicableSections: [123, 456] }; - const result = spec.getUserSyncs(userSyncConfig, {}, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${syncurl_iframe}&gpp=foo&gpp_sid=123%2C456` - }]); - }); - }); - }); - - describe('with iframe disabled', function() { - const userSyncConfig = { iframeEnabled: false }; - - it('should return empty list of syncs', function() { - expect(spec.getUserSyncs(userSyncConfig, {}, undefined, undefined)).to.deep.equal(emptySync); - expect(spec.getUserSyncs(userSyncConfig, {}, {gdprApplies: true, consentString: 'foo'}, 'bar')).to.deep.equal(emptySync); - }); - }); - }); -}); diff --git a/test/spec/modules/afpBidAdapter_spec.js b/test/spec/modules/afpBidAdapter_spec.js deleted file mode 100644 index 48c9fc1c7..000000000 --- a/test/spec/modules/afpBidAdapter_spec.js +++ /dev/null @@ -1,309 +0,0 @@ -import cloneDeep from 'lodash/cloneDeep' -import unset from 'lodash/unset' -import { expect } from 'chai' -import { BANNER, VIDEO } from '../../../src/mediaTypes.js' -import { - spec, - IN_IMAGE_BANNER_TYPE, - IN_IMAGE_MAX_BANNER_TYPE, - IN_CONTENT_BANNER_TYPE, - IN_CONTENT_VIDEO_TYPE, - OUT_CONTENT_VIDEO_TYPE, - IN_CONTENT_STORY_TYPE, - ACTION_SCROLLER_TYPE, - ACTION_SCROLLER_LIGHT_TYPE, - JUST_BANNER_TYPE, - BIDDER_CODE, - SSP_ENDPOINT, - REQUEST_METHOD, - TEST_PAGE_URL, - IS_DEV, mediaTypeByPlaceType -} from 'modules/afpBidAdapter.js' - -const placeId = '613221112871613d1517d181' -const bidId = '2a67c5577ff6a5' -const transactionId = '7e8515a2-2ed9-4733-b976-6c2596a03287' -const imageUrl = 'https://rtbinsight.ru/content/images/size/w1000/2021/05/ximage-30.png.pagespeed.ic.IfuX4zAEPP.png' -const placeContainer = '#container' -const imageWidth = 600 -const imageHeight = 400 -const pageUrl = IS_DEV ? TEST_PAGE_URL : 'referer' -const sizes = [[imageWidth, imageHeight]] -const bidderRequest = { - refererInfo: { referer: pageUrl }, -} -const mediaTypeBanner = { [BANNER]: {sizes: [[imageWidth, imageHeight]]} } -const mediaTypeVideo = { [VIDEO]: {playerSize: [[imageWidth, imageHeight]]} } -const commonParams = { - placeId, - placeContainer, -} -const commonParamsForInImage = Object.assign({}, commonParams, { - imageUrl, - imageWidth, - imageHeight, -}) -const configByPlaceType = { - get [IN_IMAGE_BANNER_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeBanner, - params: Object.assign({}, commonParamsForInImage, { - placeType: IN_IMAGE_BANNER_TYPE - }), - }) - }, - get [IN_IMAGE_MAX_BANNER_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeBanner, - params: Object.assign({}, commonParamsForInImage, { - placeType: IN_IMAGE_MAX_BANNER_TYPE - }), - }) - }, - get [IN_CONTENT_BANNER_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeBanner, - params: Object.assign({}, commonParams, { - placeType: IN_CONTENT_BANNER_TYPE - }), - }) - }, - get [IN_CONTENT_VIDEO_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeVideo, - params: Object.assign({}, commonParams, { - placeType: IN_CONTENT_VIDEO_TYPE - }), - }) - }, - get [OUT_CONTENT_VIDEO_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeVideo, - params: Object.assign({}, commonParams, { - placeType: OUT_CONTENT_VIDEO_TYPE - }), - }) - }, - get [IN_CONTENT_STORY_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeBanner, - params: Object.assign({}, commonParams, { - placeType: IN_CONTENT_STORY_TYPE - }), - }) - }, - get [ACTION_SCROLLER_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeBanner, - params: Object.assign({}, commonParams, { - placeType: ACTION_SCROLLER_TYPE - }), - }) - }, - get [ACTION_SCROLLER_LIGHT_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeBanner, - params: Object.assign({}, commonParams, { - placeType: ACTION_SCROLLER_LIGHT_TYPE - }), - }) - }, - get [JUST_BANNER_TYPE]() { - return cloneDeep({ - mediaTypes: mediaTypeBanner, - params: Object.assign({}, commonParams, { - placeType: JUST_BANNER_TYPE - }), - }) - }, -} -const getTransformedConfig = ({mediaTypes, params}) => { - return { - params: params, - sizes, - bidId, - bidder: BIDDER_CODE, - mediaTypes: mediaTypes, - ortb2Imp: { - ext: { - tid: transactionId - } - } - } -} -const validBidRequests = Object.keys(configByPlaceType).map(key => getTransformedConfig(configByPlaceType[key])) - -describe('AFP Adapter', function() { - describe('isBidRequestValid method', function() { - describe('returns true', function() { - describe('when config has all mandatory params', () => { - Object.keys(configByPlaceType).forEach(placeType => { - it(`and ${placeType} config has the correct value`, function() { - const isBidRequestValid = spec.isBidRequestValid(configByPlaceType[placeType]) - expect(isBidRequestValid).to.equal(true) - }) - }) - }) - }) - describe('returns false', function() { - const checkMissingParams = (placesTypes, missingParams) => - placesTypes.forEach(placeType => - missingParams.forEach(missingParam => { - const config = configByPlaceType[placeType] - it(`${placeType} does not have the ${missingParam}.`, function() { - unset(config, missingParam) - const isBidRequestValid = spec.isBidRequestValid(config) - expect(isBidRequestValid).to.equal(false) - }) - }) - ) - - describe('when params are not correct', function() { - checkMissingParams(Object.keys(configByPlaceType), ['params.placeId', 'params.placeType']) - checkMissingParams([IN_IMAGE_BANNER_TYPE, IN_IMAGE_MAX_BANNER_TYPE], - ['params.imageUrl', 'params.imageWidth', 'params.imageHeight']) - - it('does not have a the correct placeType.', function() { - const config = configByPlaceType[IN_IMAGE_BANNER_TYPE] - config.params.placeType = 'something' - const isBidRequestValid = spec.isBidRequestValid(config) - expect(isBidRequestValid).to.equal(false) - }) - }) - describe('when video mediaType object is not correct.', function() { - checkMissingParams([IN_CONTENT_VIDEO_TYPE, OUT_CONTENT_VIDEO_TYPE], - [`mediaTypes.${VIDEO}.playerSize`, `mediaTypes.${VIDEO}`]) - checkMissingParams([ - IN_IMAGE_BANNER_TYPE, - IN_IMAGE_MAX_BANNER_TYPE, - IN_CONTENT_BANNER_TYPE, - IN_CONTENT_STORY_TYPE, - ACTION_SCROLLER_TYPE, - ACTION_SCROLLER_LIGHT_TYPE, - JUST_BANNER_TYPE - ], [`mediaTypes.${BANNER}.sizes`, `mediaTypes.${BANNER}`]) - }) - }) - }) - - describe('buildRequests method', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest) - - it('Url should be correct', function() { - expect(request.url).to.equal(SSP_ENDPOINT) - }) - - it('Method should be correct', function() { - expect(request.method).to.equal(REQUEST_METHOD) - }) - - describe('Common data request should be correct', function() { - it('pageUrl should be correct', function() { - expect(request.data.pageUrl).to.equal(pageUrl) - }) - it('bidRequests should be array', function() { - expect(Array.isArray(request.data.bidRequests)).to.equal(true) - }) - - request.data.bidRequests.forEach((bid, index) => { - describe(`bid with ${validBidRequests[index].params.placeType} should be correct`, function() { - it('bidId should be correct', function() { - expect(bid.bidId).to.equal(bidId) - }) - it('placeId should be correct', function() { - expect(bid.placeId).to.equal(placeId) - }) - it('transactionId should be correct', function() { - expect(bid.transactionId).to.equal(transactionId) - }) - it('sizes should be correct', function() { - expect(bid.sizes).to.equal(sizes) - }) - - if ([IN_IMAGE_BANNER_TYPE, IN_IMAGE_MAX_BANNER_TYPE].includes(validBidRequests[index].params.placeType)) { - it('imageUrl should be correct', function() { - expect(bid.imageUrl).to.equal(imageUrl) - }) - it('imageWidth should be correct', function() { - expect(bid.imageWidth).to.equal(Math.floor(imageWidth)) - }) - it('imageHeight should be correct', function() { - expect(bid.imageHeight).to.equal(Math.floor(imageHeight)) - }) - } - }) - }) - }) - }) - - describe('interpretResponse method', function() { - it('should return a void array, when the server response are not correct.', function() { - const request = { data: JSON.stringify({}) } - const serverResponse = { - body: {} - } - const bids = spec.interpretResponse(serverResponse, request) - expect(Array.isArray(bids)).to.equal(true) - expect(bids.length).to.equal(0) - }) - it('should return a void array, when the server response have not got bids.', function() { - const request = { data: JSON.stringify({}) } - const serverResponse = { body: { bids: [] } } - const bids = spec.interpretResponse(serverResponse, request) - expect(Array.isArray(bids)).to.equal(true) - expect(bids.length).to.equal(0) - }) - describe('when the server response return a bids', function() { - Object.keys(configByPlaceType).forEach(placeType => { - it(`should return a bid with ${placeType} placeType`, function() { - const cpm = 10 - const currency = 'RUB' - const creativeId = '123' - const netRevenue = true - const width = sizes[0][0] - const height = sizes[0][1] - const adSettings = { - content: 'html' - } - const placeSettings = { - placeType, - } - const request = spec.buildRequests([validBidRequests[0]], bidderRequest) - const serverResponse = { - body: { - bids: [ - { - bidId, - cpm, - currency, - creativeId, - netRevenue, - width, - height, - adSettings, - placeSettings, - } - ] - } - } - const bids = spec.interpretResponse(serverResponse, request) - expect(bids.length).to.equal(1) - expect(bids[0].requestId).to.equal(bidId) - expect(bids[0].meta.mediaType).to.equal(mediaTypeByPlaceType[placeSettings.placeType]) - expect(bids[0].cpm).to.equal(cpm) - expect(bids[0].width).to.equal(width) - expect(bids[0].height).to.equal(height) - expect(bids[0].currency).to.equal(currency) - expect(bids[0].netRevenue).to.equal(netRevenue) - - if (mediaTypeByPlaceType[placeSettings.placeType] === BANNER) { - expect(typeof bids[0].ad).to.equal('string') - } else if (mediaTypeByPlaceType[placeSettings.placeType] === VIDEO) { - expect(typeof bids[0].vastXml).to.equal('string') - expect(typeof bids[0].renderer).to.equal('object') - } - }) - }) - }) - }) -}) diff --git a/test/spec/modules/agmaAnalyticsAdapter_spec.js b/test/spec/modules/agmaAnalyticsAdapter_spec.js deleted file mode 100644 index 2a9b830d1..000000000 --- a/test/spec/modules/agmaAnalyticsAdapter_spec.js +++ /dev/null @@ -1,421 +0,0 @@ -import adapterManager, { gdprDataHandler } from '../../../src/adapterManager.js'; -import agmaAnalyticsAdapter, { - getTiming, - getOrtb2Data, - getPayload, -} from '../../../modules/agmaAnalyticsAdapter.js'; - -import { expect } from 'chai'; -import * as events from '../../../src/events.js'; -import { EVENTS } from '../../../src/constants.js'; -import * as utils from 'src/utils.js'; -import { server } from '../../mocks/xhr.js'; -import { config } from 'src/config.js'; - -const INGEST_URL = 'https://pbc.agma-analytics.de/v1'; -const extendedKey = [ - 'auctionIds', - 'code', - 'domain', - 'extended', - 'gdprApplies', - 'gdprConsentString', - 'language', - 'ortb2', - 'pageUrl', - 'pageViewId', - 'prebidVersion', - 'referrer', - 'screenHeight', - 'screenWidth', - 'deviceWidth', - 'deviceHeight', - 'scriptVersion', - 'timestamp', - 'timezoneOffset', - 'timing', - 'triggerEvent', - 'userIdsAsEids', -]; -const nonExtendedKey = [ - 'auctionIds', - 'code', - 'domain', - 'gdprApplies', - 'ortb2', - 'pageUrl', - 'pageViewId', - 'prebidVersion', - 'scriptVersion', - 'timing', - 'triggerEvent', -]; - -describe('AGMA Analytics Adapter', () => { - let agmaConfig, sandbox, clock; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - clock = sandbox.useFakeTimers(); - sandbox.stub(events, 'getEvents').returns([]); - agmaConfig = { - options: { - code: 'test', - }, - }; - }); - - afterEach(() => { - sandbox.restore(); - }); - - describe('configuration', () => { - it('registers itself with the adapter manager', () => { - const adapter = adapterManager.getAnalyticsAdapter('agma'); - expect(adapter).to.exist; - expect(adapter.gvlid).to.equal(1122); - }); - }); - - describe('getPayload', () => { - it('should use non extended payload with no consent info', () => { - sandbox.stub(gdprDataHandler, 'getConsentData').callsFake(() => null) - const payload = getPayload([utils.generateUUID()], { - code: 'test', - }); - - expect(payload).to.have.all.keys([...nonExtendedKey, 'debug']); - }); - - it('should use non extended payload when agma is not in the TC String', () => { - sandbox.stub(gdprDataHandler, 'getConsentData').callsFake(() => ({ - vendorData: { - vendor: { - consents: { - 1122: false, - }, - }, - }, - })); - const payload = getPayload([utils.generateUUID()], { - code: 'test', - }); - expect(payload).to.have.all.keys([...nonExtendedKey, 'debug']); - }); - - it('should use extended payload when agma is in the TC String', () => { - sandbox.stub(gdprDataHandler, 'getConsentData').callsFake(() => ({ - vendorData: { - vendor: { - consents: { - 1122: true, - }, - }, - }, - })); - const payload = getPayload([utils.generateUUID()], { - code: 'test', - }); - expect(payload).to.have.all.keys([...extendedKey, 'debug']); - }); - }); - - describe('getTiming', () => { - let originalPerformance; - let originalWindowPerformanceNow; - - beforeEach(() => { - originalPerformance = global.performance; - originalWindowPerformanceNow = window.performance.now; - }); - - afterEach(() => { - global.performance = originalPerformance; - window.performance.now = originalWindowPerformanceNow; - }); - - it('returns TTFB using Timing API V2', () => { - global.performance = { - getEntriesByType: sinon - .stub() - .returns([{ responseStart: 100, startTime: 50 }]), - now: sinon.stub().returns(150), - }; - - const result = getTiming(); - - expect(result).to.deep.equal({ ttfb: 50, elapsedTime: 150 }); - }); - - it('returns TTFB using Timing API V1 when V2 is not available', () => { - global.performance = { - getEntriesByType: sinon.stub().throws(), - timing: { responseStart: 150, fetchStart: 50 }, - now: sinon.stub().returns(200), - }; - - const result = getTiming(); - - expect(result).to.deep.equal({ ttfb: 100, elapsedTime: 200 }); - }); - - it('returns null when Timing API is not available', () => { - global.performance = { - getEntriesByType: sinon.stub().throws(), - timing: undefined, - }; - - const result = getTiming(); - - expect(result).to.be.null; - }); - - it('returns ttfb as 0 if calculated value is negative', () => { - global.performance = { - getEntriesByType: sinon - .stub() - .returns([{ responseStart: 50, startTime: 150 }]), - now: sinon.stub().returns(200), - }; - - const result = getTiming(); - - expect(result).to.deep.equal({ ttfb: 0, elapsedTime: 200 }); - }); - - it('returns ttfb as 0 if calculated value exceeds performance.now()', () => { - global.performance = { - getEntriesByType: sinon - .stub() - .returns([{ responseStart: 50, startTime: 0 }]), - now: sinon.stub().returns(40), - }; - - const result = getTiming(); - - expect(result).to.deep.equal({ ttfb: 0, elapsedTime: 40 }); - }); - }); - - describe('getOrtb2Data', () => { - it('returns site and user from options when available', () => { - sandbox.stub(config, 'getConfig').callsFake((key) => { - return {}; - }); - - const ortb2 = { - user: 'user', - site: 'site', - }; - - const result = getOrtb2Data({ - ortb2, - }); - - expect(result).to.deep.equal(ortb2); - }); - - it('returns a combination of data from options and pGlobal.readConfig', () => { - sandbox.stub(config, 'getConfig').callsFake((key) => { - return { - ortb2: { - site: { - foo: 'bar', - }, - }, - }; - }); - - const ortb2 = { - user: 'user', - }; - const result = getOrtb2Data({ - ortb2, - }); - - expect(result).to.deep.equal({ - site: { - foo: 'bar', - }, - user: 'user', - }); - }); - }); - - it('can be overwritten with a global agma variable', () => { - sandbox.stub(utils, 'getWindowSelf').returns({ - agma: { - ortb2: { - site: { - domain: 'overwritten.com', - }, - }, - }, - }); - - const ortb2 = { - site: { - domain: 'initial.com' - } - }; - - const result = getOrtb2Data({ - ortb2, - }); - - expect(result).to.deep.equal({ - user: undefined, - site: { - domain: 'overwritten.com', - } - }); - }); - - describe('Event Payload', () => { - beforeEach(() => { - agmaAnalyticsAdapter.enableAnalytics({ - ...agmaConfig, - }); - server.respondWith('POST', INGEST_URL, [ - 200, - { - 'Content-Type': 'application/json', - 'Access-Control-Allow-Origin': '*', - }, - '', - ]); - }); - - afterEach(() => { - agmaAnalyticsAdapter.auctionIds = []; - if (agmaAnalyticsAdapter.timer) { - clearTimeout(agmaAnalyticsAdapter.timer); - } - agmaAnalyticsAdapter.disableAnalytics(); - }); - - it('should only send once per minute', () => { - sandbox.stub(gdprDataHandler, 'getConsentData').callsFake(() => ({ - gdprApplies: true, - consentString: 'consentDataString', - vendorData: { - vendor: { - consents: { - 1122: true, - }, - }, - }, - })); - const auction = { - auctionId: utils.generateUUID(), - }; - - events.emit(EVENTS.AUCTION_INIT, { - auctionId: utils.generateUUID('1'), - auction, - }); - - clock.tick(200); - - events.emit(EVENTS.AUCTION_INIT, { - auctionId: utils.generateUUID('2'), - auction, - }); - events.emit(EVENTS.AUCTION_INIT, { - auctionId: utils.generateUUID('3'), - auction, - }); - events.emit(EVENTS.AUCTION_INIT, { - auctionId: utils.generateUUID('4'), - auction, - }); - - clock.tick(900); - - const [request] = server.requests; - const requestBody = JSON.parse(request.requestBody); - expect(request.url).to.equal(INGEST_URL); - expect(requestBody).to.have.all.keys(extendedKey); - expect(requestBody.triggerEvent).to.equal(EVENTS.AUCTION_INIT); - expect(server.requests).to.have.length(1); - }); - - it('should send the extended payload with consent', () => { - sandbox.stub(gdprDataHandler, 'getConsentData').callsFake(() => ({ - gdprApplies: true, - consentString: 'consentDataString', - vendorData: { - vendor: { - consents: { - 1122: true, - }, - }, - }, - })); - const auction = { - auctionId: utils.generateUUID(), - }; - - events.emit(EVENTS.AUCTION_INIT, auction); - clock.tick(1100); - - const [request] = server.requests; - const requestBody = JSON.parse(request.requestBody); - expect(request.url).to.equal(INGEST_URL); - expect(requestBody).to.have.all.keys(extendedKey); - expect(requestBody.triggerEvent).to.equal(EVENTS.AUCTION_INIT); - expect(requestBody.deviceWidth).to.equal(screen.width); - expect(requestBody.deviceHeight).to.equal(screen.height); - expect(server.requests).to.have.length(1); - expect(agmaAnalyticsAdapter.auctionIds).to.have.length(0); - }); - - it('should send the non extended payload with no explicit consent', () => { - sandbox.stub(gdprDataHandler, 'getConsentData').callsFake(() => ({ - gdprApplies: true, - consentString: 'consentDataString', - })); - - const auction = { - auctionId: utils.generateUUID(), - }; - - events.emit(EVENTS.AUCTION_INIT, auction); - clock.tick(1000); - - const [request] = server.requests; - const requestBody = JSON.parse(request.requestBody); - expect(request.url).to.equal(INGEST_URL); - expect(requestBody.triggerEvent).to.equal(EVENTS.AUCTION_INIT); - expect(server.requests).to.have.length(1); - expect(agmaAnalyticsAdapter.auctionIds).to.have.length(0); - }); - - it('should set the trigger Event', () => { - sandbox.stub(gdprDataHandler, 'getConsentData').callsFake(() => null); - agmaAnalyticsAdapter.disableAnalytics(); - agmaAnalyticsAdapter.enableAnalytics({ - provider: 'agma', - options: { - code: 'test', - triggerEvent: EVENTS.AUCTION_END - }, - }); - const auction = { - auctionId: utils.generateUUID(), - }; - - events.emit(EVENTS.AUCTION_INIT, auction); - events.emit(EVENTS.AUCTION_END, auction); - clock.tick(1000); - - const [request] = server.requests; - const requestBody = JSON.parse(request.requestBody); - expect(request.url).to.equal(INGEST_URL); - expect(requestBody.auctionIds).to.have.length(1); - expect(requestBody.triggerEvent).to.equal(EVENTS.AUCTION_END); - expect(server.requests).to.have.length(1); - expect(agmaAnalyticsAdapter.auctionIds).to.have.length(0); - }); - }); -}); diff --git a/test/spec/modules/aidemBidAdapter_spec.js b/test/spec/modules/aidemBidAdapter_spec.js deleted file mode 100644 index 979d2cb92..000000000 --- a/test/spec/modules/aidemBidAdapter_spec.js +++ /dev/null @@ -1,697 +0,0 @@ -import {expect} from 'chai'; -import {setEndPoints, spec} from 'modules/aidemBidAdapter.js'; -import * as utils from '../../../src/utils.js'; -import {deepSetValue} from '../../../src/utils.js'; -import {server} from '../../mocks/xhr.js'; -import {config} from '../../../src/config.js'; -import {NATIVE} from '../../../src/mediaTypes.js'; - -// Full banner + Full Video + Basic Banner + Basic Video -const VALID_BIDS = [ - { - bidder: 'aidem', - params: { - siteId: '301491', - publisherId: '3021491', - placementId: '13144370', - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - } - }, - }, - { - bidder: 'aidem', - params: { - siteId: '301491', - publisherId: '3021491', - placementId: '13144370', - }, - mediaTypes: { - video: { - context: 'instream', - minduration: 7, - maxduration: 30, - playerSize: [640, 480], - mimes: ['video/mp4'], - protocols: [2] - } - }, - }, -] - -const INVALID_BIDS = [ - { - bidder: 'aidem', - params: { - siteId: '3014912' - } - }, - { - bidder: 'aidem', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - } - }, - params: { - siteId: '3014912', - } - }, - { - bidder: 'aidem', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - } - }, - params: { - publisherId: '3014912', - } - }, - { - bidder: 'aidem', - params: { - siteId: '3014912', - member: '301e4912' - } - }, - { - bidder: 'aidem', - params: { - siteId: '3014912', - invCode: '3014912' - } - }, - { - bidder: 'aidem', - mediaType: NATIVE, - params: { - siteId: '3014912' - } - }, - { - bidder: 'aidem', - mediaTypes: { - banner: {} - }, - }, - { - bidder: 'aidem', - mediaTypes: { - video: { - placement: 1, - minduration: 7, - maxduration: 30, - mimes: ['video/mp4'], - protocols: [2] - } - }, - params: { - siteId: '301491', - placementId: '13144370', - }, - }, - { - bidder: 'aidem', - mediaTypes: { - video: { - minduration: 7, - maxduration: 30, - playerSize: [640, 480], - mimes: ['video/mp4'], - protocols: [2] - } - }, - params: { - siteId: '301491', - placementId: '13144370', - }, - }, - { - bidder: 'aidem', - mediaTypes: { - video: { - minduration: 7, - maxduration: 30, - playerSize: [640, 480], - mimes: ['video/mp4'], - protocols: [2], - placement: 1 - } - }, - params: { - siteId: '301491', - placementId: '13144370', - video: { - size: [480, 40] - } - }, - }, -] - -const DEFAULT_VALID_BANNER_REQUESTS = [ - { - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '2705bfae8ea667', - bidder: 'aidem', - bidderRequestId: '1bbb7854dfa0d8', - mediaTypes: { - banner: { - sizes: [ - [ 300, 250 ], - [ 300, 600 ] - ] - } - }, - params: { - siteId: '1', - placementId: '13144370', - }, - src: 'client', - transactionId: 'db739693-9b4a-4669-9945-8eab938783cc' - } -]; - -const DEFAULT_VALID_VIDEO_REQUESTS = [ - { - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '2705bfae8ea667', - bidder: 'aidem', - bidderRequestId: '1bbb7854dfa0d8', - mediaTypes: { - video: { - minduration: 7, - maxduration: 30, - playerSize: [640, 480], - mimes: ['video/mp4'], - protocols: [2] - } - }, - params: { - siteId: '1', - placementId: '13144370', - }, - src: 'client', - transactionId: 'db739693-9b4a-4669-9945-8eab938783cc' - } -]; - -const VALID_BIDDER_REQUEST = { - auctionId: '19c97f22-5bd1-4b16-a128-80f75fb0a8a0', - bidderCode: 'aidem', - bidderRequestId: '1bbb7854dfa0d8', - bids: [ - { - params: { - placementId: '13144370', - siteId: '23434', - publisherId: '7689670753', - }, - } - ], - refererInfo: { - page: 'test-page', - domain: 'test-domain', - ref: 'test-referer' - }, -} - -const VALID_GDPR_BIDDER_REQUEST = { - auctionId: '19c97f22-5bd1-4b16-a128-80f75fb0a8a0', - bidderCode: 'aidem', - bidderRequestId: '1bbb7854dfa0d8', - bids: [ - { - params: { - placementId: '13144370', - siteId: '23434', - publisherId: '7689670753', - }, - } - ], - refererInfo: { - page: 'test-page', - domain: 'test-domain', - ref: 'test-referer' - }, - gdprConsent: { - consentString: 'test-gdpr-string' - } -} - -const VALID_USP_BIDDER_REQUEST = { - auctionId: '19c97f22-5bd1-4b16-a128-80f75fb0a8a0', - bidderCode: 'aidem', - bidderRequestId: '1bbb7854dfa0d8', - bids: [ - { - params: { - placementId: '13144370', - siteId: '23434', - publisherId: '7689670753', - }, - } - ], - refererInfo: { - page: 'test-page', - domain: 'test-domain', - ref: 'test-referer' - }, - uspConsent: '1YYY' -} - -const SERVER_RESPONSE_BANNER = { - 'id': '19c97f22-5bd1-4b16-a128-80f75fb0a8a0', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'beeswax/aidem', - 'impid': '2705bfae8ea667', - 'price': 0.00875, - 'burl': 'imp_burl', - 'adm': 'creativity_banner', - 'adid': '2:64:162:1001', - 'adomain': [ - 'aidem.com' - ], - 'cid': '64', - 'crid': 'aidem-1001', - 'cat': [], - 'w': 300, - 'h': 250, - 'mtype': 1 - } - ], - 'seat': 'aidemdsp', - 'group': 0 - } - ], - 'cur': 'USD' -} - -const SERVER_RESPONSE_VIDEO = { - 'id': '19c97f22-5bd1-4b16-a128-80f75fb0a8a0', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'beeswax/aidem', - 'impid': '2705bfae8ea667', - 'price': 0.00875, - 'burl': 'imp_burl', - 'adm': 'creativity_banner', - 'adid': '2:64:162:1001', - 'adomain': [ - 'aidem.com' - ], - 'cid': '64', - 'crid': 'aidem-1001', - 'cat': [], - 'w': 300, - 'h': 250, - 'mtype': 2 - } - ], - 'seat': 'aidemdsp', - 'group': 0 - } - ], - 'cur': 'USD' -} - -const WIN_NOTICE = { - burl: 'burl' -} - -const ERROR_NOTICE = { - 'message': 'Prebid.js: Server call for aidem failed.', - 'url': 'http%3A%2F%2Flocalhost%3A9999%2FintegrationExamples%2Fgpt%2Fhello_world.html%3Fpbjs_debug%3Dtrue', - 'auctionId': 'b57faab7-23f7-4b63-90db-67b259d20db7', - 'bidderRequestId': '1c53857d1ce616', - 'timeout': 1000, - 'bidderCode': 'aidem', - metrics: { - getMetrics() { - return { - - } - } - } -} - -describe('Aidem adapter', () => { - describe('isBidRequestValid', () => { - it('should return true for each valid bid requests', function () { - // spec.isBidRequestValid() - VALID_BIDS.forEach((value, index) => { - expect(spec.isBidRequestValid(value)).to.be.true - }) - }); - - it('should return false for each invalid bid requests', function () { - // spec.isBidRequestValid() - INVALID_BIDS.forEach((value, index) => { - expect(spec.isBidRequestValid(value)).to.be.false - }) - }); - - it('should return true if valid banner sizes are specified in params as single array', function () { - // spec.isBidRequestValid() - const validBannerRequest = utils.deepClone(VALID_BIDS[0]) - deepSetValue(validBannerRequest.params, 'banner.size', [300, 250]) - expect(spec.isBidRequestValid(validBannerRequest)).to.be.true - }); - - it('should return true if valid banner sizes are specified in params as array of array', function () { - // spec.isBidRequestValid() - const validBannerRequest = utils.deepClone(VALID_BIDS[0]) - deepSetValue(validBannerRequest.params, 'banner.size', [[300, 600]]) - expect(spec.isBidRequestValid(validBannerRequest)).to.be.true - }); - - it('should return true if valid video sizes are specified in params as single array', function () { - // spec.isBidRequestValid() - const validVideoRequest = utils.deepClone(VALID_BIDS[1]) - deepSetValue(validVideoRequest.params, 'video.size', [640, 480]) - expect(spec.isBidRequestValid(validVideoRequest)).to.be.true - }); - - it('BANNER: should return true if rateLimit is 1', function () { - // spec.isBidRequestValid() - const validBannerRequest = utils.deepClone(VALID_BIDS[0]) - deepSetValue(validBannerRequest.params, 'rateLimit', 1) - expect(spec.isBidRequestValid(validBannerRequest)).to.be.true - }); - - it('BANNER: should return false if rateLimit is 0', function () { - // spec.isBidRequestValid() - const validBannerRequest = utils.deepClone(VALID_BIDS[0]) - deepSetValue(validBannerRequest.params, 'rateLimit', 0) - expect(spec.isBidRequestValid(validBannerRequest)).to.be.false - }); - - it('BANNER: should return false if rateLimit is not between 0 and 1', function () { - // spec.isBidRequestValid() - const validBannerRequest = utils.deepClone(VALID_BIDS[0]) - deepSetValue(validBannerRequest.params, 'rateLimit', 1.2) - expect(spec.isBidRequestValid(validBannerRequest)).to.be.false - }); - - it('BANNER: should return false if rateLimit is not a number', function () { - // spec.isBidRequestValid() - const validBannerRequest = utils.deepClone(VALID_BIDS[0]) - deepSetValue(validBannerRequest.params, 'rateLimit', '0.5') - expect(spec.isBidRequestValid(validBannerRequest)).to.be.false - }); - - it('VIDEO: should return true if rateLimit is 1', function () { - // spec.isBidRequestValid() - const validVideoRequest = utils.deepClone(VALID_BIDS[1]) - deepSetValue(validVideoRequest.params, 'rateLimit', 1) - expect(spec.isBidRequestValid(validVideoRequest)).to.be.true - }); - - it('VIDEO: should return false if rateLimit is 0', function () { - // spec.isBidRequestValid() - const validVideoRequest = utils.deepClone(VALID_BIDS[1]) - deepSetValue(validVideoRequest.params, 'rateLimit', 0) - expect(spec.isBidRequestValid(validVideoRequest)).to.be.false - }); - - it('VIDEO: should return false if rateLimit is not between 0 and 1', function () { - // spec.isBidRequestValid() - const validBannerRequest = utils.deepClone(VALID_BIDS[1]) - deepSetValue(validBannerRequest.params, 'rateLimit', 1.2) - expect(spec.isBidRequestValid(validBannerRequest)).to.be.false - }); - - it('VIDEO: should return false if rateLimit is not a number', function () { - // spec.isBidRequestValid() - const validBannerRequest = utils.deepClone(VALID_BIDS[1]) - deepSetValue(validBannerRequest.params, 'rateLimit', '0.5') - expect(spec.isBidRequestValid(validBannerRequest)).to.be.false - }); - }); - - describe('buildRequests', () => { - it('should match server requirements', () => { - const requests = spec.buildRequests(DEFAULT_VALID_BANNER_REQUESTS, VALID_BIDDER_REQUEST); - expect(requests).to.be.an('object'); - expect(requests.method).to.be.a('string') - expect(requests.data).to.be.a('object') - expect(requests.options).to.be.an('object').that.have.a.property('withCredentials') - }); - - it('should have a well formatted banner payload', () => { - const {data} = spec.buildRequests(DEFAULT_VALID_BANNER_REQUESTS, VALID_BIDDER_REQUEST); - expect(data).to.be.a('object').that.has.all.keys( - 'id', 'imp', 'regs', 'site', 'environment', 'at', 'test' - ) - expect(data.imp).to.be.a('array').that.has.lengthOf(DEFAULT_VALID_BANNER_REQUESTS.length) - - expect(data.imp[0]).to.be.a('object').that.has.all.keys( - 'banner', 'id', 'tagId', 'secure' - ) - expect(data.imp[0].banner).to.be.a('object').that.has.all.keys( - 'format', 'topframe' - ) - }); - - if (FEATURES.VIDEO) { - it('should have a well formatted video payload', () => { - const {data} = spec.buildRequests(DEFAULT_VALID_VIDEO_REQUESTS, VALID_BIDDER_REQUEST); - expect(data).to.be.a('object').that.has.all.keys( - 'id', 'imp', 'regs', 'site', 'environment', 'at', 'test' - ) - expect(data.imp).to.be.a('array').that.has.lengthOf(DEFAULT_VALID_VIDEO_REQUESTS.length) - - expect(data.imp[0]).to.be.a('object').that.has.all.keys( - 'video', 'id', 'tagId', 'secure' - ) - expect(data.imp[0].video).to.be.a('object').that.has.all.keys( - 'mimes', 'minduration', 'maxduration', 'protocols', 'w', 'h' - ) - }); - } - - it('should hav wpar keys in environment object', function () { - const {data} = spec.buildRequests(DEFAULT_VALID_VIDEO_REQUESTS, VALID_BIDDER_REQUEST); - expect(data).to.have.property('environment') - expect(data.environment).to.be.a('object').that.have.property('wpar') - expect(data.environment.wpar).to.be.a('object').that.has.keys('innerWidth', 'innerHeight') - }); - }) - - describe('interpretResponse', () => { - it('should return a valid bid array with a banner bid', () => { - const {data} = spec.buildRequests(DEFAULT_VALID_BANNER_REQUESTS, VALID_BIDDER_REQUEST) - const bids = spec.interpretResponse({body: SERVER_RESPONSE_BANNER}, { data }) - expect(bids).to.be.a('array').that.has.lengthOf(1) - bids.forEach(value => { - expect(value).to.be.a('object').that.has.all.keys( - 'ad', 'cpm', 'creativeId', 'currency', 'height', 'mediaType', 'meta', 'netRevenue', 'requestId', 'ttl', 'width', 'burl', 'seatBidId', 'creative_id' - ) - }) - }); - - if (FEATURES.VIDEO) { - it('should return a valid bid array with a video bid', () => { - const {data} = spec.buildRequests(DEFAULT_VALID_VIDEO_REQUESTS, VALID_BIDDER_REQUEST) - const bids = spec.interpretResponse({body: SERVER_RESPONSE_VIDEO}, { data }) - expect(bids).to.be.a('array').that.has.lengthOf(1) - bids.forEach(value => { - expect(value).to.be.a('object').that.has.all.keys( - 'vastUrl', 'vastXml', 'playerHeight', 'playerWidth', 'cpm', 'creativeId', 'currency', 'height', 'mediaType', 'meta', 'netRevenue', 'requestId', 'ttl', 'width', 'burl', 'seatBidId', 'creative_id' - ) - }) - }); - } - - it('should return a valid bid array with netRevenue', () => { - const {data} = spec.buildRequests(DEFAULT_VALID_VIDEO_REQUESTS, VALID_BIDDER_REQUEST) - const bids = spec.interpretResponse({body: SERVER_RESPONSE_VIDEO}, { data }) - expect(bids).to.be.a('array').that.has.lengthOf(1) - expect(bids[0].netRevenue).to.be.true - }); - - // it('should return an empty bid array if one of seatbid entry is missing price property', () => { - // const response = utils.deepClone(SERVER_RESPONSE_BANNER) - // delete response.body.bid[0].price - // const interpreted = spec.interpretResponse(response) - // expect(interpreted).to.be.a('array').that.has.lengthOf(0) - // }); - - // it('should return an empty bid array if one of seatbid entry is missing adm property', () => { - // const response = utils.deepClone(SERVER_RESPONSE_BANNER) - // delete response.body.bid[0].adm - // const interpreted = spec.interpretResponse(response) - // expect(interpreted).to.be.a('array').that.has.lengthOf(0) - // }); - }) - - describe('onBidWon', () => { - it(`should exists and type function`, function () { - expect(spec.onBidWon).to.exist.and.to.be.a('function') - }); - - it(`should send a win notice`, function () { - spec.onBidWon(WIN_NOTICE); - expect(server.requests.length).to.equal(1); - }); - }); - - // describe('onBidderError', () => { - // it(`should exists and type function`, function () { - // expect(spec.onBidderError).to.exist.and.to.be.a('function') - // }); - // - // it(`should send a valid error notice`, function () { - // spec.onBidderError({ bidderRequest: ERROR_NOTICE }) - // expect(server.requests.length).to.equal(1); - // const body = JSON.parse(server.requests[0].requestBody) - // expect(body).to.be.a('object').that.has.all.keys('message', 'auctionId', 'bidderRequestId', 'url', 'metrics') - // // const { bids } = JSON.parse(server.requests[0].requestBody) - // // expect(bids).to.be.a('array').that.has.lengthOf(1) - // // _each(bids, (bid) => { - // // expect(bid).to.be.a('object').that.has.all.keys('adUnitCode', 'auctionId', 'bidId', 'bidderRequestId', 'transactionId', 'metrics') - // // }) - // }); - // }); - - describe('setEndPoints', () => { - it(`should exists and type function`, function () { - expect(setEndPoints).to.exist.and.to.be.a('function') - }); - - it(`should not modify default endpoints`, function () { - const endpoints = setEndPoints() - const requestURL = new URL(endpoints.request) - expect(requestURL.host).to.equal('zero.aidemsrv.com') - expect(decodeURIComponent(requestURL.pathname)).to.equal('/prebidjs/ortb/v2.6/bid/request') - }); - - it(`should not change request endpoint`, function () { - const endpoints = setEndPoints('default') - const requestURL = new URL(endpoints.request) - expect(decodeURIComponent(requestURL.pathname)).to.equal('/prebidjs/ortb/v2.6/bid/request') - }); - - it(`should change to local env`, function () { - const endpoints = setEndPoints('local') - const requestURL = new URL(endpoints.request) - - expect(requestURL.host).to.equal('127.0.0.1:8787') - }); - - it(`should add a path prefix`, function () { - const endpoints = setEndPoints('local', '/path') - const requestURL = new URL(endpoints.request) - - expect(decodeURIComponent(requestURL.pathname)).to.equal('/path/prebidjs/ortb/v2.6/bid/request') - }); - - it(`should add a path prefix and change request endpoint`, function () { - const endpoints = setEndPoints('local', '/path') - const requestURL = new URL(endpoints.request) - - expect(decodeURIComponent(requestURL.pathname)).to.equal('/path/prebidjs/ortb/v2.6/bid/request') - }); - }); - - describe('config', () => { - beforeEach(() => { - config.setConfig({ - aidem: { - env: 'main' - } - }); - }) - - it(`should not override default endpoints`, function () { - config.setConfig({ - aidem: { - env: 'unknown', - path: '/test' - } - }); - const { url } = spec.buildRequests(DEFAULT_VALID_BANNER_REQUESTS, VALID_BIDDER_REQUEST); - const requestURL = new URL(url) - expect(requestURL.host).to.equal('zero.aidemsrv.com') - }); - - it(`should set local endpoints`, function () { - config.setConfig({ - aidem: { - env: 'local', - path: '/test' - } - }); - const { url } = spec.buildRequests(DEFAULT_VALID_BANNER_REQUESTS, VALID_BIDDER_REQUEST); - const requestURL = new URL(url) - expect(requestURL.host).to.equal('127.0.0.1:8787') - }); - - it(`should set coppa`, function () { - config.setConfig({ - coppa: true - }); - const { data } = spec.buildRequests(DEFAULT_VALID_BANNER_REQUESTS, VALID_BIDDER_REQUEST); - expect(data.regs.coppa_applies).to.equal(true) - }); - - it(`should set gdpr to true`, function () { - // config.setConfig({ - // consentManagement: { - // gdpr: { - // consentData: { - // getTCData: { - // tcString: 'test-gdpr-string' - // } - // } - // }, - // } - // }); - const { data } = spec.buildRequests(DEFAULT_VALID_BANNER_REQUESTS, VALID_GDPR_BIDDER_REQUEST); - expect(data.regs.gdpr_applies).to.equal(true) - }); - - it(`should set usp_consent string`, function () { - // config.setConfig({ - // consentManagement: { - // usp: { - // cmpApi: 'static', - // consentData: { - // getUSPData: { - // uspString: '1YYY' - // } - // } - // } - // } - // }); - const { data } = spec.buildRequests(DEFAULT_VALID_BANNER_REQUESTS, VALID_USP_BIDDER_REQUEST); - expect(data.regs.us_privacy).to.equal('1YYY') - }); - - it(`should not set usp_consent string`, function () { - // config.setConfig({ - // consentManagement: { - // usp: { - // cmpApi: 'iab', - // consentData: { - // getUSPData: { - // uspString: '1YYY' - // } - // } - // } - // } - // }); - const { data } = spec.buildRequests(DEFAULT_VALID_BANNER_REQUESTS, VALID_BIDDER_REQUEST); - expect(data.regs.us_privacy).to.undefined - }); - }); -}); diff --git a/test/spec/modules/airgridRtdProvider_spec.js b/test/spec/modules/airgridRtdProvider_spec.js deleted file mode 100644 index 3e885dbe5..000000000 --- a/test/spec/modules/airgridRtdProvider_spec.js +++ /dev/null @@ -1,93 +0,0 @@ -import {config} from 'src/config.js'; -import {deepAccess} from 'src/utils.js'; -import * as agRTD from 'modules/airgridRtdProvider.js'; -import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; - -const MATCHED_AUDIENCES = ['travel', 'sport']; -const RTD_CONFIG = { - auctionDelay: 250, - dataProviders: [ - { - name: 'airgrid', - waitForIt: true, - params: { - apiKey: 'key123', - accountId: 'sdk', - publisherId: 'pub123', - bidders: ['pubmatic'], - }, - }, - ], -}; - -describe('airgrid RTD Submodule', function () { - let getDataFromLocalStorageStub; - - beforeEach(function () { - config.resetConfig(); - getDataFromLocalStorageStub = sinon.stub( - agRTD.storage, - 'getDataFromLocalStorage' - ); - }); - - afterEach(function () { - getDataFromLocalStorageStub.restore(); - }); - - describe('Initialise module', function () { - it('should initialise and return true', function () { - expect(agRTD.airgridSubmodule.init(RTD_CONFIG.dataProviders[0])).to.equal( - true - ); - expect(loadExternalScriptStub.called).to.be.true - }); - - it('should attach script to DOM with correct config', function () { - agRTD.attachScriptTagToDOM(RTD_CONFIG); - expect(window.edktInitializor.invoked).to.be.true; - expect(window.edktInitializor.apiKey).to.equal( - RTD_CONFIG.dataProviders[0].params.apiKey - ); - expect(window.edktInitializor.accountId).to.equal( - RTD_CONFIG.dataProviders[0].params.accountId - ); - expect(window.edktInitializor.publisherId).to.equal( - RTD_CONFIG.dataProviders[0].params.publisherId - ); - }); - }); - - describe('Get matched audiences', function () { - it('gets matched audiences from local storage', function () { - getDataFromLocalStorageStub - .withArgs(agRTD.AG_AUDIENCE_IDS_KEY) - .returns(JSON.stringify(MATCHED_AUDIENCES)); - - const audiences = agRTD.getMatchedAudiencesFromStorage(); - expect(audiences).to.have.members(MATCHED_AUDIENCES); - }); - }); - - describe('Add matched audiences', function () { - it('sets bidder specific ORTB2 config', function () { - getDataFromLocalStorageStub - .withArgs(agRTD.AG_AUDIENCE_IDS_KEY) - .returns(JSON.stringify(MATCHED_AUDIENCES)); - const audiences = agRTD.getMatchedAudiencesFromStorage(); - - const bidderOrtb2 = {}; - - agRTD.setAudiencesAsBidderOrtb2({ortb2Fragments: {bidder: bidderOrtb2}}, RTD_CONFIG.dataProviders[0], audiences); - - const bidders = RTD_CONFIG.dataProviders[0].params.bidders - - bidders.forEach((bidder) => { - const ortb2 = bidderOrtb2[bidder]; - MATCHED_AUDIENCES.forEach((audience) => { - expect(ortb2.user.data[0].segment.find(segment => segment.id === audience)).to.exist; - }) - }); - }); - }); -}); diff --git a/test/spec/modules/ajaBidAdapter_spec.js b/test/spec/modules/ajaBidAdapter_spec.js deleted file mode 100644 index b9acda490..000000000 --- a/test/spec/modules/ajaBidAdapter_spec.js +++ /dev/null @@ -1,293 +0,0 @@ -import { spec } from 'modules/ajaBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; - -const ENDPOINT = 'https://ad.as.amanad.adtdp.com/v2/prebid'; - -describe('AjaAdapter', function () { - const adapter = newBidder(spec); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'aja', - 'params': { - 'asi': '123456' - }, - 'adUnitCode': 'adunit', - 'sizes': [[300, 250]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'asi': 0 - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - bidder: 'aja', - params: { - asi: '123456' - }, - adUnitCode: 'adunit', - sizes: [[300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - ortb2: { - device: { - sua: { - source: 2, - platform: { - brand: 'Android', - version: ['8', '0', '0'] - }, - browsers: [ - {brand: 'Not_A Brand', version: ['99', '0', '0', '0']}, - {brand: 'Google Chrome', version: ['109', '0', '5414', '119']}, - {brand: 'Chromium', version: ['109', '0', '5414', '119']} - ], - mobile: 1, - model: 'SM-G955U', - bitness: '64', - architecture: '' - }, - ext: { - cdep: 'example_label_1' - } - }, - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'exchange1.com', - sid: '1234', - hp: 1, - rid: 'bid-request-1', - name: 'publisher', - domain: 'publisher.com' - }, - { - asi: 'exchange2.com', - sid: 'abcd', - hp: 1, - rid: 'bid-request-2', - name: 'intermediary', - domain: 'intermediary.com' - } - ] - } - } - } - }, - ortb2Imp: { - ext: { - tid: 'cea1eb09-d970-48dc-8585-634d3a7b0544', - gpid: '/1111/homepage#300x250' - } - }, - - } - ]; - const serializedSchain = encodeURIComponent('1.0,1!exchange1.com,1234,1,bid-request-1,publisher,publisher.com!exchange2.com,abcd,1,bid-request-2,intermediary,intermediary.com') - - const bidderRequest = { - refererInfo: { - page: 'https://hoge.com' - } - }; - - it('sends bid request to ENDPOINT via GET', function () { - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(requests[0].url).to.equal(ENDPOINT); - expect(requests[0].method).to.equal('GET'); - expect(requests[0].data).to.equal(`asi=123456&skt=5&gpid=%2F1111%2Fhomepage%23300x250&tid=cea1eb09-d970-48dc-8585-634d3a7b0544&cdep=example_label_1&prebid_id=30b31c1838de1e&prebid_ver=$prebid.version$&page_url=https%3A%2F%2Fhoge.com&schain=${serializedSchain}&ad_format_ids=2&sua=%7B%22source%22%3A2%2C%22platform%22%3A%7B%22brand%22%3A%22Android%22%2C%22version%22%3A%5B%228%22%2C%220%22%2C%220%22%5D%7D%2C%22browsers%22%3A%5B%7B%22brand%22%3A%22Not_A%20Brand%22%2C%22version%22%3A%5B%2299%22%2C%220%22%2C%220%22%2C%220%22%5D%7D%2C%7B%22brand%22%3A%22Google%20Chrome%22%2C%22version%22%3A%5B%22109%22%2C%220%22%2C%225414%22%2C%22119%22%5D%7D%2C%7B%22brand%22%3A%22Chromium%22%2C%22version%22%3A%5B%22109%22%2C%220%22%2C%225414%22%2C%22119%22%5D%7D%5D%2C%22mobile%22%3A1%2C%22model%22%3A%22SM-G955U%22%2C%22bitness%22%3A%2264%22%2C%22architecture%22%3A%22%22%7D&`); - }); - }); - - describe('buildRequests with UserModule', function () { - const bidRequests = [ - { - bidder: 'aja', - params: { - asi: '123456' - }, - adUnitCode: 'adunit', - sizes: [[300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userIdAsEids: [ - { - source: 'pubcid.org', - uids: [{ - id: 'some-random-id-value', - atype: 1 - }] - } - ] - } - ]; - - const bidderRequest = { - refererInfo: { - page: 'https://hoge.com' - } - }; - - it('sends bid request to ENDPOINT via GET', function () { - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(requests[0].url).to.equal(ENDPOINT); - expect(requests[0].method).to.equal('GET'); - expect(requests[0].data).to.equal('asi=123456&skt=5&prebid_id=30b31c1838de1e&prebid_ver=$prebid.version$&page_url=https%3A%2F%2Fhoge.com&ad_format_ids=2&eids=%7B%22eids%22%3A%5B%7B%22source%22%3A%22pubcid.org%22%2C%22uids%22%3A%5B%7B%22id%22%3A%22some-random-id-value%22%2C%22atype%22%3A1%7D%5D%7D%5D%7D&'); - }); - }); - - describe('interpretResponse', function () { - it('should get correct banner bid response', function () { - const response = { - 'is_ad_return': true, - 'ad': { - 'ad_type': 1, - 'prebid_id': '51ef8751f9aead', - 'price': 12.34, - 'currency': 'USD', - 'creative_id': '123abc', - 'banner': { - 'w': 300, - 'h': 250, - 'tag': '
', - 'imps': [ - 'https://as.amanad.adtdp.com/v1/imp' - ], - 'adomain': [ - 'www.example.com' - ] - }, - }, - 'syncs': [ - 'https://example.com' - ] - }; - - const expectedResponse = [ - { - 'requestId': '51ef8751f9aead', - 'cpm': 12.34, - 'creativeId': '123abc', - 'dealId': undefined, - 'width': 300, - 'height': 250, - 'ad': '
', - 'mediaType': 'banner', - 'currency': 'USD', - 'ttl': 300, - 'netRevenue': true, - 'meta': { - 'advertiserDomains': [ - 'www.example.com' - ] - } - } - ]; - - let bidderRequest; - const result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - - it('handles nobid responses', function () { - const response = { - 'is_ad_return': false, - 'ad': {} - }; - - let bidderRequest; - const result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(result.length).to.equal(0); - }); - }); - - describe('getUserSyncs', function () { - const bidResponse1 = { - body: { - 'is_ad_return': true, - 'ad': { /* ad body */ }, - 'syncs': [ - 'https://example.test/pixel/1' - ], - 'sync_htmls': [ - 'https://example.test/iframe/1' - ] - } - }; - - const bidResponse2 = { - body: { - 'is_ad_return': true, - 'ad': { /* ad body */ }, - 'syncs': [ - 'https://example.test/pixel/2' - ] - } - }; - - it('should use a sync url from first response (pixel and iframe)', function () { - const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, [bidResponse1, bidResponse2]); - expect(syncs).to.deep.equal([ - { - type: 'image', - url: 'https://example.test/pixel/1' - }, - { - type: 'iframe', - url: 'https://example.test/iframe/1' - } - ]); - }); - - it('handle empty response (e.g. timeout)', function () { - const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, []); - expect(syncs).to.deep.equal([]); - }); - - it('returns empty syncs when not pixel enabled and not iframe enabled', function () { - const syncs = spec.getUserSyncs({ pixelEnabled: false, iframeEnabled: false }, [bidResponse1]); - expect(syncs).to.deep.equal([]); - }); - - it('returns pixel syncs when pixel enabled and not iframe enabled', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: false }, [bidResponse1]); - expect(syncs).to.deep.equal([ - { - type: 'image', - url: 'https://example.test/pixel/1' - } - ]); - }); - - it('returns iframe syncs when not pixel enabled and iframe enabled', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: false, iframeEnabled: true }, [bidResponse1]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://example.test/iframe/1' - } - ]); - }); - }); -}); diff --git a/test/spec/modules/akceloBidAdapter_spec.js b/test/spec/modules/akceloBidAdapter_spec.js deleted file mode 100644 index 5c519ea98..000000000 --- a/test/spec/modules/akceloBidAdapter_spec.js +++ /dev/null @@ -1,263 +0,0 @@ -import { converter, spec } from 'modules/akceloBidAdapter.js'; -import * as utils from '../../../src/utils.js'; -import { deepClone } from '../../../src/utils.js'; -import sinon from 'sinon'; - -describe('Akcelo bid adapter tests', () => { - let sandBox; - - beforeEach(() => { - sandBox = sinon.createSandbox(); - sandBox.stub(utils, 'logError'); - }); - - afterEach(() => sandBox.restore()); - - const DEFAULT_BANNER_BID_REQUESTS = [ - { - adUnitCode: 'div-banner-id', - bidId: 'bid-123', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - }, - }, - bidder: 'akcelo', - params: { - siteId: 123, - adUnitId: 456, - }, - requestId: 'request-123', - } - ]; - - const DEFAULT_BANNER_BIDDER_REQUEST = { - bidderCode: 'akcelo', - bids: DEFAULT_BANNER_BID_REQUESTS, - }; - - const SAMPLE_RESPONSE = { - body: { - id: '12h712u7-k22g-8124-ab7a-h268s22dy271', - seatbid: [ - { - bid: [ - { - id: '1bh7jku7-ko2g-8654-ab72-h268abcde271', - impid: 'bid-123', - price: 0.6565, - adm: '

AD

', - adomain: ['abc.com'], - cid: '1242512', - crid: '535231', - w: 300, - h: 600, - mtype: 1, - ext: { - prebid: { - type: 'banner', - } - } - }, - ], - seat: '4212', - }, - ], - cur: 'EUR', - }, - }; - - describe('isBidRequestValid', () => { - it('should return true if params.siteId and params.adUnitId are set', () => { - const bidRequest = { - params: { - siteId: 123, - adUnitId: 456, - }, - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false if params.siteId is missing', () => { - const bidRequest = { - params: { - adUnitId: 456, - }, - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false if params.adUnitId is missing', () => { - const bidRequest = { - params: { - siteId: 123, - }, - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); - - describe('buildRequests', () => { - it('should build correct requests using ORTB converter', () => { - const request = spec.buildRequests( - DEFAULT_BANNER_BID_REQUESTS, - DEFAULT_BANNER_BIDDER_REQUEST - ); - const dataFromConverter = converter.toORTB({ - bidderRequest: DEFAULT_BANNER_BIDDER_REQUEST, - bidRequests: DEFAULT_BANNER_BID_REQUESTS, - }); - expect(request[0]).to.deep.equal({ - data: { ...dataFromConverter, id: request[0].data.id }, - method: 'POST', - url: 'https://s2s.sportslocalmedia.com/openrtb2/auction', - }); - }); - - it('should add site.publisher.ext.prebid.parentAccount to request object when siteId is defined', () => { - const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0]; - expect(request.data.site.publisher.ext.prebid.parentAccount).to.equal(123); - }); - - it('should not add site.publisher.ext.prebid.parentAccount to request object when siteId is not defined', () => { - const bidRequests = [ - { ...DEFAULT_BANNER_BID_REQUESTS[0], params: { adUnitId: 456 } }, - ]; - const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests }; - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.site.publisher.ext.prebid.parentAccount).to.be.undefined; - }); - - it('should add ext.akcelo to imp object when siteId and adUnitId are defined', () => { - const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0]; - expect(request.data.imp[0].ext.akcelo).to.deep.equal({ - siteId: 123, - adUnitId: 456, - }); - }); - - it('should not add ext.akcelo.siteId to imp object when siteId is not defined', () => { - const bidRequests = [ - { ...DEFAULT_BANNER_BID_REQUESTS[0], params: { adUnitId: 456 } }, - ]; - const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests }; - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.imp[0].ext.akcelo.siteId).to.be.undefined; - expect(utils.logError.calledOnce).to.equal(true); - expect(utils.logError.args[0][0]).to.equal('Missing parameter : siteId') - }); - - it('should not add ext.akcelo.adUnitId to imp object when adUnitId is not defined', () => { - const bidRequests = [ - { ...DEFAULT_BANNER_BID_REQUESTS[0], params: { siteId: 123 } }, - ]; - const bidderRequest = { ...DEFAULT_BANNER_BIDDER_REQUEST, bids: bidRequests }; - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.imp[0].ext.akcelo.adUnitId).to.be.undefined; - expect(utils.logError.calledOnce).to.equal(true); - expect(utils.logError.args[0][0]).to.equal('Missing parameter : adUnitId') - }); - - it('should add ext.akcelo.test=1 to imp object when param akcelo_demo is true', () => { - sandBox.stub(utils, 'getParameterByName').callsFake(() => 'true'); - const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0]; - expect(request.data.imp[0].ext.akcelo.test).to.equal(1); - }); - - it('should not add ext.akcelo.test to imp object when param akcelo_demo is not true', () => { - sandBox.stub(utils, 'getParameterByName').callsFake(() => 'something_else'); - const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0]; - expect(request.data.imp[0].ext.akcelo.test).to.be.undefined; - }); - - it('should not add ext.akcelo.test to imp object when param akcelo_demo is not defined', () => { - const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0]; - expect(request.data.imp[0].ext.akcelo.test).to.be.undefined; - }); - }); - - describe('interpretResponse', () => { - it('should return data returned by ORTB converter', () => { - const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0]; - const bids = spec.interpretResponse(SAMPLE_RESPONSE, request); - const responseFromConverter = converter.fromORTB({ - request: request.data, - response: SAMPLE_RESPONSE.body, - }); - expect(bids).to.deep.equal(responseFromConverter.bids); - }); - - it('should find the media type from bid.mtype if possible', () => { - const serverResponse = deepClone(SAMPLE_RESPONSE); - serverResponse.body.seatbid[0].bid[0].mtype = 2; - const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0]; - const bids = spec.interpretResponse(serverResponse, request); - expect(bids[0].mediaType).to.equal('video'); - }); - - it('should find the media type from bid.ext.prebid.type if mtype is not defined', () => { - const serverResponse = deepClone(SAMPLE_RESPONSE); - delete serverResponse.body.seatbid[0].bid[0].mtype; - const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0]; - const bids = spec.interpretResponse(serverResponse, request); - expect(bids[0].mediaType).to.equal('banner'); - }); - - it('should skip the bid if bid.mtype and bid.ext.prebid.type are not defined', () => { - const serverResponse = deepClone(SAMPLE_RESPONSE); - delete serverResponse.body.seatbid[0].bid[0].mtype; - delete serverResponse.body.seatbid[0].bid[0].ext.prebid.type; - const request = spec.buildRequests(DEFAULT_BANNER_BID_REQUESTS, DEFAULT_BANNER_BIDDER_REQUEST)[0]; - const bids = spec.interpretResponse(serverResponse, request); - expect(bids).to.be.empty; - }); - }); - - describe('getUserSyncs', () => { - it('should return an empty array if iframe sync is not enabled', () => { - const syncs = spec.getUserSyncs({}, [SAMPLE_RESPONSE], null, null); - expect(syncs).to.deep.equal([]); - }); - - it('should return an array with iframe url', () => { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [SAMPLE_RESPONSE], null, null); - expect(syncs).to.deep.equal([{ - type: 'iframe', - url: 'https://ads.sportslocalmedia.com/load-cookie.html?endpoint=akcelo' - }]); - }); - - it('should return an array with iframe URL and GDPR parameters', () => { - const gdprConsent = { gdprApplies: true, consentString: 'the_gdpr_consent' }; - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [SAMPLE_RESPONSE], gdprConsent, null); - expect(syncs[0].url).to.contain('?endpoint=akcelo&gdpr=1&gdpr_consent=the_gdpr_consent'); - }); - - it('should return an array with iframe URL containing empty GDPR parameters when GDPR does not apply', () => { - const gdprConsent = { gdprApplies: false }; - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [SAMPLE_RESPONSE], gdprConsent, null); - expect(syncs[0].url).to.contain('?endpoint=akcelo&gdpr=0&gdpr_consent='); - }); - - it('should URI encode the GDPR consent string', () => { - const gdprConsent = { gdprApplies: true, consentString: 'the_gdpr_consent==' }; - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [SAMPLE_RESPONSE], gdprConsent, null); - expect(syncs[0].url).to.contain('?endpoint=akcelo&gdpr=1&gdpr_consent=the_gdpr_consent%3D%3D'); - }); - - it('should return an array with iframe URL containing USP parameters when USP is defined', () => { - const uspConsent = 'the_usp_consent'; - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [SAMPLE_RESPONSE], null, uspConsent); - expect(syncs[0].url).to.contain('?endpoint=akcelo&us_privacy=the_usp_consent'); - }); - - it('should URI encode the USP consent string', () => { - const uspConsent = 'the_usp_consent=='; - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [SAMPLE_RESPONSE], null, uspConsent); - expect(syncs[0].url).to.contain('?endpoint=akcelo&us_privacy=the_usp_consent%3D%3D'); - }); - }); -}); diff --git a/test/spec/modules/alkimiBidAdapter_spec.js b/test/spec/modules/alkimiBidAdapter_spec.js deleted file mode 100644 index a6949d5c5..000000000 --- a/test/spec/modules/alkimiBidAdapter_spec.js +++ /dev/null @@ -1,240 +0,0 @@ -import { expect } from 'chai' -import { ENDPOINT, spec } from 'modules/alkimiBidAdapter.js' -import { newBidder } from 'src/adapters/bidderFactory.js' - -const REQUEST = { - 'bidId': '456', - 'bidder': 'alkimi', - 'sizes': [[300, 250]], - 'adUnitCode': 'bannerAdUnitCode', - 'ortb2Imp': { - 'ext': { - 'gpid': '/111/banner#300x250', - 'tid': 'e64782a4-8e68-4c38-965b-80ccf115d46a' - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]] - } - }, - 'params': { - bidFloor: 0.1, - token: 'e64782a4-8e68-4c38-965b-80ccf115d46f' - }, - 'userIdAsEids': [{ - 'source': 'criteo.com', - 'uids': [{ - 'id': 'test', - 'atype': 1 - }] - }, { - 'source': 'pubcid.org', - 'uids': [{ - 'id': 'test', - 'atype': 1 - }] - }], - 'ortb2': { - 'source': { - 'ext': { - 'schain': { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'alkimi-onboarding.com', - sid: '00001', - hp: 1 - }] - } - } - } - } -} - -const BIDDER_BANNER_RESPONSE = { - 'prebidResponse': [{ - 'ad': '
test
', - 'requestId': 'e64782a4-8e68-4c38-965b-80ccf115d46d', - 'cpm': 900.5, - 'currency': 'USD', - 'width': 640, - 'height': 480, - 'ttl': 300, - 'creativeId': 1, - 'netRevenue': true, - 'winUrl': 'http://test.com', - 'mediaType': 'banner', - 'adomain': ['test.com'] - }] -} - -const BIDDER_VIDEO_RESPONSE = { - 'prebidResponse': [{ - 'ad': 'vast', - 'requestId': 'e64782a4-8e68-4c38-965b-80ccf115d46z', - 'cpm': 800.4, - 'currency': 'USD', - 'width': 1024, - 'height': 768, - 'ttl': 200, - 'creativeId': 2, - 'netRevenue': true, - 'winUrl': 'http://test.com?price=${AUCTION_PRICE}', - 'mediaType': 'video', - 'adomain': ['test.com'] - }] -} - -const BIDDER_NO_BID_RESPONSE = '' - -describe('alkimiBidAdapter', function () { - const adapter = newBidder(spec) - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function') - }) - }) - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(REQUEST)).to.equal(true) - }) - - it('should return false when required params are not passed', function () { - let bid = JSON.parse(JSON.stringify(REQUEST)) - delete bid.params.token - expect(spec.isBidRequestValid(bid)).to.equal(false) - - bid = JSON.parse(JSON.stringify(REQUEST)) - delete bid.params - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - }) - - describe('buildRequests', function () { - const bidRequests = [REQUEST] - const requestData = { - refererInfo: { - page: 'http://test.com/path.html' - }, - gdprConsent: { - consentString: 'test-consent', - vendorData: {}, - gdprApplies: true - }, - uspConsent: 'uspConsent', - ortb2: { - site: { - keywords: 'test1, test2', - cat: ['IAB2'], - pagecat: ['IAB3'], - sectioncat: ['IAB4'] - }, - at: 2, - bcat: ['BSW1', 'BSW2'], - wseat: ['16', '165'] - } - } - - it('should return a properly formatted request with eids defined', function () { - const bidderRequest = spec.buildRequests(bidRequests, requestData) - expect(bidderRequest.data.eids).to.deep.equal(REQUEST.userIdAsEids) - }) - - it('should return a properly formatted request with gdpr defined', function () { - const bidderRequest = spec.buildRequests(bidRequests, requestData) - expect(bidderRequest.data.gdprConsent.consentRequired).to.equal(true) - expect(bidderRequest.data.gdprConsent.consentString).to.equal('test-consent') - }) - - it('should return a properly formatted request with uspConsent defined', function () { - const bidderRequest = spec.buildRequests(bidRequests, requestData) - expect(bidderRequest.data.uspConsent).to.equal('uspConsent') - }) - - it('sends bid request to ENDPOINT via POST', function () { - const bidderRequest = spec.buildRequests(bidRequests, requestData) - expect(bidderRequest.method).to.equal('POST') - expect(bidderRequest.data.requestId).to.not.equal(undefined) - expect(bidderRequest.data.referer).to.equal('http://test.com/path.html') - expect(bidderRequest.data.schain).to.deep.equal({ ver: '1.0', complete: 1, nodes: [{ asi: 'alkimi-onboarding.com', sid: '00001', hp: 1 }] }) - expect(bidderRequest.data.signRequest.bids).to.deep.contains({ token: 'e64782a4-8e68-4c38-965b-80ccf115d46f', bidFloor: 0.1, sizes: [{ width: 300, height: 250 }], playerSizes: [], impMediaTypes: ['Banner'], adUnitCode: 'bannerAdUnitCode', instl: undefined, exp: undefined, banner: { sizes: [[300, 250]] }, video: undefined, ext: { gpid: '/111/banner#300x250', tid: 'e64782a4-8e68-4c38-965b-80ccf115d46a' } }) - expect(bidderRequest.data.signRequest.randomUUID).to.equal(undefined) - expect(bidderRequest.data.bidIds).to.deep.contains('456') - expect(bidderRequest.data.signature).to.equal(undefined) - expect(bidderRequest.data.ortb2).to.deep.contains({ at: 2, wseat: ['16', '165'], bcat: ['BSW1', 'BSW2'], site: { keywords: 'test1, test2', cat: ['IAB2'], pagecat: ['IAB3'], sectioncat: ['IAB4'] } }) - expect(bidderRequest.options.customHeaders).to.deep.equal({ 'Rtb-Direct': true }) - expect(bidderRequest.options.contentType).to.equal('application/json') - expect(bidderRequest.url).to.equal(ENDPOINT) - }) - - it('sends bidFloor when configured', () => { - const requestWithFloor = Object.assign({}, REQUEST); - requestWithFloor.getFloor = function (arg) { - if (arg.currency === 'USD' && arg.mediaType === 'banner' && JSON.stringify(arg.size) === JSON.stringify([300, 250])) { - return { currency: 'USD', floor: 0.3 } - } - } - const bidderRequestFloor = spec.buildRequests([requestWithFloor], requestData); - expect(bidderRequestFloor.data.signRequest.bids[0].bidFloor).to.be.equal(0.3); - }); - }) - - describe('interpretResponse', function () { - it('handles banner request : should get correct bid response', function () { - const result = spec.interpretResponse({ body: BIDDER_BANNER_RESPONSE }, {}) - - expect(result[0]).to.have.property('ad').equal('
test
') - expect(result[0]).to.have.property('requestId').equal('e64782a4-8e68-4c38-965b-80ccf115d46d') - expect(result[0]).to.have.property('cpm').equal(900.5) - expect(result[0]).to.have.property('currency').equal('USD') - expect(result[0]).to.have.property('width').equal(640) - expect(result[0]).to.have.property('height').equal(480) - expect(result[0]).to.have.property('ttl').equal(300) - expect(result[0]).to.have.property('creativeId').equal(1) - expect(result[0]).to.have.property('netRevenue').equal(true) - expect(result[0]).to.have.property('winUrl').equal('http://test.com') - expect(result[0]).to.have.property('mediaType').equal('banner') - expect(result[0].meta).to.exist.property('advertiserDomains') - expect(result[0].meta).to.have.property('advertiserDomains').lengthOf(1) - }) - - it('handles video request : should get correct bid response', function () { - const result = spec.interpretResponse({ body: BIDDER_VIDEO_RESPONSE }, {}) - - expect(result[0]).to.have.property('ad').equal('vast') - expect(result[0]).to.have.property('requestId').equal('e64782a4-8e68-4c38-965b-80ccf115d46z') - expect(result[0]).to.have.property('cpm').equal(800.4) - expect(result[0]).to.have.property('currency').equal('USD') - expect(result[0]).to.have.property('width').equal(1024) - expect(result[0]).to.have.property('height').equal(768) - expect(result[0]).to.have.property('ttl').equal(200) - expect(result[0]).to.have.property('creativeId').equal(2) - expect(result[0]).to.have.property('netRevenue').equal(true) - expect(result[0]).to.have.property('winUrl').equal('http://test.com?price=${AUCTION_PRICE}') - expect(result[0]).to.have.property('mediaType').equal('video') - expect(result[0]).to.have.property('vastUrl').equal('http://test.com?price=800.4') - expect(result[0].meta).to.exist.property('advertiserDomains') - expect(result[0].meta).to.have.property('advertiserDomains').lengthOf(1) - }) - - it('handles no bid response : should get empty array', function () { - let result = spec.interpretResponse({ body: undefined }, {}) - expect(result).to.deep.equal([]) - - result = spec.interpretResponse({ body: BIDDER_NO_BID_RESPONSE }, {}) - expect(result).to.deep.equal([]) - }) - }) - - describe('onBidWon', function () { - it('handles banner win: should get true', function () { - const win = BIDDER_BANNER_RESPONSE.prebidResponse[0] - const bidWonResult = spec.onBidWon(win) - - expect(bidWonResult).to.equal(true) - }) - }) -}) diff --git a/test/spec/modules/ampliffyBidAdapter_spec.js b/test/spec/modules/ampliffyBidAdapter_spec.js deleted file mode 100644 index 4c1a17047..000000000 --- a/test/spec/modules/ampliffyBidAdapter_spec.js +++ /dev/null @@ -1,453 +0,0 @@ -import { - parseXML, - isAllowedToBidUp, - spec, - getDefaultParams, - mergeParams, - paramsToQueryString, setCurrentURL -} from 'modules/ampliffyBidAdapter.js'; -import {expect} from 'chai'; -import {BANNER, VIDEO} from 'src/mediaTypes'; -import {newBidder} from 'src/adapters/bidderFactory'; - -describe('Ampliffy bid adapter Test', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - // Global definitions for all tests - const xmlStr = ` - - - - ]]> - - - - ES - `; - const xml = new window.DOMParser().parseFromString(xmlStr, 'text/xml'); - const companion = xml.getElementsByTagName('Companion')[0]; - const htmlResource = companion.getElementsByTagName('HTMLResource')[0]; - const htmlContent = document.createElement('html'); - htmlContent.innerHTML = htmlResource.textContent; - - describe('Is allowed to bid up', function () { - it('Should return true using a URL that is in domainMap', () => { - const allowedToBidUp = isAllowedToBidUp(htmlContent, 'https://testSports.com?id=131313&text=aaaaa&foo=foo'); - expect(allowedToBidUp).to.be.true; - }) - - it('Should return false using an url that is not in domainMap', () => { - const allowedToBidUp = isAllowedToBidUp(htmlContent, 'https://test.com'); - expect(allowedToBidUp).to.be.false; - }) - - it('Should return false using an url that is excluded.', () => { - const allowedToBidUp = isAllowedToBidUp(htmlContent, 'https://www.no-allowed.com/busqueda/sexo/sexo?test=1#item1'); - expect(allowedToBidUp).to.be.false; - }) - }) - - describe('Helper functions', function () { - it('Should default params not to be null', () => { - const defaultParams = getDefaultParams(); - - expect(defaultParams).not.to.be.null; - }) - it('Should the merge two object params into a new object', () => { - const params1 = { - 'hello': 'world', - 'ampTest': 'this will be replaced' - } - const params2 = { - 'test': 1, - 'ampTest': 'This will be replace the param with the same name in other array' - } - const allParams = mergeParams(params1, params2); - - const paramsComplete = - { - 'hello': 'world', - 'ampTest': 'This will be replace the param with the same name in other array', - 'test': 1, - } - expect(allParams).not.to.be.null; - expect(JSON.stringify(allParams)).to.equal(JSON.stringify(paramsComplete)); - }) - it('Params to QueryString', () => { - const params = { - 'test': 1, - 'ampTest': 'ret', - 'empty': null, - 'quoteMark': '?', - 'test1': undefined - } - const queryString = paramsToQueryString(params); - - expect(queryString).not.to.be.null; - expect(queryString).to.equal('test=1&Test=ret&empty"eMark=%3F'); - }) - }) - - describe('isBidRequestValid', function () { - it('Should return true when required params found', function () { - const bidRequest = { - bidder: 'ampliffy', - params: { - server: 'bidder.ampliffy.com', - placementId: 1235465798, - format: 'all' - }, - mediaTypes: { - banner: { - sizes: [1, 1] - } - }, - } - expect(spec.isBidRequestValid(bidRequest)).to.be.true; - }) - it('Should return false when param format is display but mediaTypes are for video', function () { - const bidRequest = { - bidder: 'ampliffy', - params: { - server: 'bidder.ampliffy.com', - placementId: 1235465798, - format: 'display' - }, - mediaTypes: { - video: { - sizes: [1, 1] - } - }, - } - expect(spec.isBidRequestValid(bidRequest)).to.be.false; - }) - it('Should return false when param format is video but mediaTypes are for banner', function () { - const bidRequest = { - bidder: 'ampliffy', - params: { - server: 'bidder.ampliffy.com', - placementId: 1235465798, - format: 'video' - }, - mediaTypes: { - banner: { - sizes: [1, 1] - } - }, - } - expect(spec.isBidRequestValid(bidRequest)).to.be.false; - }) - it('Should return true when param format is video and mediaTypes are for video', function () { - const bidRequest = { - bidder: 'ampliffy', - params: { - server: 'bidder.ampliffy.com', - placementId: 1235465798, - format: 'video' - }, - mediaTypes: { - video: { - sizes: [1, 1] - } - }, - } - expect(spec.isBidRequestValid(bidRequest)).to.be.true; - }) - it('Should return true when param format is display and mediaTypes are for banner', function () { - const bidRequest = { - bidder: 'ampliffy', - params: { - server: 'bidder.ampliffy.com', - placementId: 1235465798, - format: 'display' - }, - mediaTypes: { - banner: { - sizes: [1, 1] - } - }, - } - expect(spec.isBidRequestValid(bidRequest)).to.be.true; - }) - it('Should return true when param format is all and mediaTypes are for banner', function () { - const bidRequest = { - bidder: 'ampliffy', - params: { - server: 'bidder.ampliffy.com', - placementId: 1235465798, - format: 'all' - }, - mediaTypes: { - banner: { - sizes: [1, 1] - } - }, - } - expect(spec.isBidRequestValid(bidRequest)).to.be.true; - }) - it('Should return true when param format is all and mediaTypes are for video', function () { - const bidRequest = { - bidder: 'ampliffy', - params: { - server: 'bidder.ampliffy.com', - placementId: 1235465798, - format: 'all' - }, - mediaTypes: { - video: { - sizes: [1, 1] - } - }, - } - expect(spec.isBidRequestValid(bidRequest)).to.be.true; - }) - it('Should return false without placementId param', function () { - const bidRequest = { - bidder: 'ampliffy', - params: {} - } - expect(spec.isBidRequestValid(bidRequest)).to.be.false; - }) - it('Should return false without param object', function () { - const bidRequest = { - bidder: 'ampliffy', - } - expect(spec.isBidRequestValid(bidRequest)).to.be.false; - }) - }); - - describe('Build request function', function () { - const bidderRequest = { - 'bidderCode': 'ampliffy', - 'auctionId': 'c4a771bf-1791-4513-82b3-96c48d19ddff', - 'bidderRequestId': '1134bdcbe47f25', - 'bids': [{ - 'bidder': 'ampliffy', - 'params': { - 'placementId': 1235465798, - 'type': 'bidder.', - 'region': 'alan-development.k8s.', - 'adnetwork': 'ampliffy.com', - 'SERVER': 'bidder.ampliffy.com' - }, - 'crumbs': {'pubcid': '29844d69-c4e5-4b00-8602-6dd09815363a'}, - 'ortb2Imp': {'ext': {'data': {'pbadslot': 'video1'}}}, - 'mediaTypes': { - 'video': { - 'context': 'instream', - 'playerSize': [[640, 480]], - 'mimes': ['video/mp4'], - 'protocols': [1, 2, 3, 4, 5, 6, 7, 8], - 'playbackmethod': [2], - 'skip': 1 - } - }, - 'adUnitCode': 'video1', - 'transactionId': 'f85c1b10-bad3-4c3f-a2bb-2c484c405bc9', - 'sizes': [[640, 480]], - 'bidId': '2bc71d9c058842', - 'bidderRequestId': '1134bdcbe47f25', - 'auctionId': 'c4a771bf-1791-4513-82b3-96c48d19ddff', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - }], - 'auctionStart': 1644029483655, - 'timeout': 3000, - 'refererInfo': { - 'referer': 'http://localhost:9999/integrationExamples/gpt/hello_world_video.html?pbjs_debug=true', - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': ['http://localhost:9999/integrationExamples/gpt/hello_world_video.html?pbjs_debug=true'], - 'canonicalUrl': null - }, - 'start': 1644029483708 - } - const validBidRequests = [ - { - 'bidder': 'ampliffy', - 'params': { - 'placementId': 1235465798, - 'type': 'bidder.', - 'region': 'alan-development.k8s.', - 'adnetwork': 'ampliffy.com', - 'SERVER': 'bidder.ampliffy.com' - }, - 'crumbs': {'pubcid': '29844d69-c4e5-4b00-8602-6dd09815363a'}, - 'ortb2Imp': {'ext': {'data': {'pbadslot': 'video1'}}}, - 'mediaTypes': { - 'video': { - 'context': 'instream', - 'playerSize': [[640, 480]], - 'mimes': ['video/mp4'], - 'protocols': [1, 2, 3, 4, 5, 6, 7, 8], - 'playbackmethod': [2], - 'skip': 1 - } - }, - 'adUnitCode': 'video1', - 'transactionId': 'f85c1b10-bad3-4c3f-a2bb-2c484c405bc9', - 'sizes': [[640, 480]], - 'bidId': '2bc71d9c058842', - 'bidderRequestId': '1134bdcbe47f25', - 'auctionId': 'c4a771bf-1791-4513-82b3-96c48d19ddff', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ]; - it('Should return one or more bid requests', function () { - expect(spec.buildRequests(validBidRequests, bidderRequest).length).to.be.greaterThan(0); - }); - }) - describe('Interpret response', function () { - const bidRequest = { - bidRequest: { - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: '469bb2e2-351f-4d01-b782-cdbca5e3e0ed', - bidId: '2d40b8dcd02ade', - bidRequestsCount: 1, - bidder: 'ampliffy', - bidderRequestId: '128c07edc4680f', - bidderRequestsCount: 1, - bidderWinsCount: 0, - crumbs: { - pubcid: '29844d69-c4e5-4b00-8602-6dd09815363a' - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ] - } - }, - ortb2Imp: {ext: {}}, - params: {placementId: 13144370}, - sizes: [ - [300, 250], - [300, 600] - ], - src: 'client', - transactionId: '103b2b58-6ed1-45e9-9486-c942d6042e3' - }, - data: {bidId: '2d40b8dcd02ade'}, - method: 'GET', - url: 'https://test.com', - }; - - it('Should extract a CPM and currency from the xml', () => { - const cpmData = parseXML(xml); - expect(cpmData).to.not.be.a('null'); - expect(cpmData.cpm).to.equal('.23'); - expect(cpmData.currency).to.equal('USD'); - }); - - it('It should return no ads when the CPM is less than zero.', () => { - const xmlStr1 = ` - - - - - - - - -
-
-
-
- - - ]]> -
-
- - ES -
-
-
`; - const serverResponse = { - 'body': xmlStr1, - } - const bidResponses = spec.interpretResponse(serverResponse, bidRequest); - expect(bidResponses.length).to.equal(0); - }) - - it('It should return no ads when the creative url is not in the xml', () => { - const xmlStr1 = ` - - - - - - - - -
-
-
-
- - ]]> - - - ES - - - `; - const serverResponse = { - 'body': xmlStr1, - } - const bidResponses = spec.interpretResponse(serverResponse, bidRequest); - expect(bidResponses.length).to.equal(0); - }) - it('It should return a banner ad.', () => { - const serverResponse = { - 'body': xmlStr, - } - setCurrentURL('https://www.sports.com'); - const bidResponses = spec.interpretResponse(serverResponse, bidRequest); - expect(bidResponses.length).greaterThan(0); - expect(bidResponses[0].mediaType).to.be.equal(BANNER); - expect(bidResponses[0].ad).not.to.be.null; - }) - it('It should return a video ad.', () => { - const serverResponse = { - 'body': xmlStr, - } - setCurrentURL('https://www.sports.com'); - bidRequest.bidRequest.mediaTypes = { - video: { - sizes: [ - [300, 250], - [300, 600] - ] - } - } - const bidResponses = spec.interpretResponse(serverResponse, bidRequest); - expect(bidResponses.length).greaterThan(0); - expect(bidResponses[0].mediaType).to.be.equal(VIDEO); - expect(bidResponses[0].vastUrl).not.to.be.null; - }) - }); -}); diff --git a/test/spec/modules/amxBidAdapter_spec.js b/test/spec/modules/amxBidAdapter_spec.js deleted file mode 100644 index d1e88b35a..000000000 --- a/test/spec/modules/amxBidAdapter_spec.js +++ /dev/null @@ -1,849 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/amxBidAdapter.js'; -import { createEidsArray } from 'modules/userId/eids.js'; -import { BANNER, VIDEO } from 'src/mediaTypes.js'; -import { config } from 'src/config.js'; -import { server } from 'test/mocks/xhr.js'; -import * as utils from 'src/utils.js'; -import { getGlobal } from '../../../src/prebidGlobal.js'; - -import {getGlobalVarName} from '../../../src/buildOptions.js'; - -const sampleRequestId = '82c91e127a9b93e'; -const sampleDisplayAd = ``; -const sampleDisplayCRID = '78827819'; -// minimal example vast -const sampleVideoAd = (addlImpression) => - ` -00:00:15${addlImpression} -`.replace(/\n+/g, ''); - -const sampleFPD = { - site: { - keywords: 'sample keywords', - ext: { - data: { - pageType: 'article', - }, - }, - }, - user: { - gender: 'O', - yob: 1982, - }, -}; - -const sampleBidderRequest = { - gdprConsent: { - gdprApplies: true, - consentString: utils.getUniqueIdentifierStr(), - vendorData: {}, - }, - gppConsent: { - gppString: 'example', - applicableSections: 'example', - }, - - auctionId: null, - - uspConsent: '1YYY', - refererInfo: { - reachedTop: true, - numIframes: 10, - stack: ['https://www.prebid.org'], - canonicalUrl: 'https://prebid.org', - location: 'https://www.prebid.org', - site: 'prebid.org', - topmostLocation: 'https://www.prebid.org', - page: 'https://www.prebid.org/the/link/to/the/page', - }, - ortb2: sampleFPD, -}; - -const sampleImpExt = { - testKey: 'testValue', -}; - -const sampleBidRequestBase = { - bidder: spec.code, - params: { - endpoint: 'https://httpbin.org/post', - }, - ortb2Imp: { - ext: sampleImpExt, - }, - sizes: [[320, 50]], - getFloor(params) { - if ( - params.size == null || - params.currency == null || - params.mediaType == null - ) { - throw new Error( - `getFloor called with incomplete params: ${JSON.stringify(params)}` - ); - } - return { - floor: 0.5, - currency: 'USD', - }; - }, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]], - }, - }, - adUnitCode: 'div-gpt-ad-example', - transactionId: utils.getUniqueIdentifierStr(), - bidId: sampleRequestId, - - auctionId: null, -}; - -const schainConfig = { - ver: '1.0', - nodes: [ - { - asi: 'greatnetwork.exchange', - sid: '000001', - hp: 1, - rid: 'bid_request_1', - domain: 'publisher.com', - }, - ], -}; - -const sampleBidRequestVideo = { - ...sampleBidRequestBase, - bidId: sampleRequestId + '_video', - sizes: [[300, 150]], - ortb2: { source: { ext: { schain: schainConfig } } }, - mediaTypes: { - [VIDEO]: { - sizes: [[360, 250]], - context: 'adpod', - adPodDurationSec: 90, - contentMode: 'live', - }, - }, -}; - -const sampleServerResponse = { - p: { - hreq: [ - 'https://1x1.a-mo.net/hbx/g_sync?partner=test', - 'https://1x1.a-mo.net/hbx/g_syncf?__st=iframe', - ], - }, - r: { - [sampleRequestId]: [ - { - b: [ - { - adid: '78827819', - adm: sampleDisplayAd, - adomain: ['example.com'], - crid: sampleDisplayCRID, - h: 600, - id: '2014691335735134254', - impid: '1', - exp: 90, - price: 0.25, - w: 300, - }, - { - adid: '222976952', - adm: sampleVideoAd(''), - adomain: ['example.com'], - crid: sampleDisplayCRID, - ext: {}, - h: 1, - id: '7735706981389902829', - impid: '1', - exp: 90, - price: 0.25, - w: 1, - }, - ], - }, - ], - }, -}; - -describe('AmxBidAdapter', () => { - describe('isBidRequestValid', () => { - it('endpoint must be an optional string', () => { - expect(spec.isBidRequestValid({ params: { endpoint: 1 } })).to.equal( - false - ); - expect(spec.isBidRequestValid({ params: { endpoint: 'test' } })).to.equal( - true - ); - }); - - it('tagId is an optional string', () => { - expect(spec.isBidRequestValid({ params: { tagId: 1 } })).to.equal(false); - expect(spec.isBidRequestValid({ params: { tagId: 'test' } })).to.equal( - true - ); - }); - - it('testMode is an optional truthy value', () => { - expect(spec.isBidRequestValid({ params: { testMode: 1 } })).to.equal( - true - ); - expect(spec.isBidRequestValid({ params: { testMode: 'true' } })).to.equal( - true - ); - // ignore invalid values (falsy) - expect( - spec.isBidRequestValid({ - params: { testMode: 'non-truthy-invalid-value' }, - }) - ).to.equal(true); - expect(spec.isBidRequestValid({ params: { testMode: false } })).to.equal( - true - ); - }); - - it('none of the params are required', () => { - expect(spec.isBidRequestValid({})).to.equal(true); - }); - }); - describe('getUserSync', () => { - it('Will perform an iframe sync even if there is no server response..', () => { - const syncs = spec.getUserSyncs({ iframeEnabled: true }); - expect(syncs).to.eql([ - { - type: 'iframe', - url: 'https://prebid.a-mo.net/isyn?gdpr_consent=&gdpr=0&us_privacy=&gpp=&gpp_sid=', - }, - ]); - }); - - it('will return valid syncs from a server response', () => { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [ - { body: sampleServerResponse }, - ]); - expect(syncs.length).to.equal(2); - expect(syncs[0].type).to.equal('image'); - expect(syncs[1].type).to.equal('iframe'); - }); - - it('will filter out iframe syncs based on options', () => { - const syncs = spec.getUserSyncs({ iframeEnabled: false }, [ - { body: sampleServerResponse }, - { body: sampleServerResponse }, - ]); - expect(syncs.length).to.equal(2); - expect(syncs).to.satisfy((allSyncs) => - allSyncs.every((sync) => sync.type === 'image') - ); - }); - }); - - describe('buildRequests', () => { - it('will default to prebid.a-mo.net endpoint', () => { - const { url } = spec.buildRequests([], sampleBidderRequest); - expect(url).to.equal('https://prebid.a-mo.net/a/c'); - }); - - it('will read the prebid version & global', () => { - const { - data: { V: prebidVersion, vg: prebidGlobal }, - } = spec.buildRequests( - [ - { - ...sampleBidRequestBase, - params: { - testMode: true, - }, - }, - ], - sampleBidderRequest - ); - expect(prebidVersion).to.equal('$prebid.version$'); - expect(prebidGlobal).to.equal(getGlobalVarName()); - }); - - it('reads test mode from the first bid request', () => { - const { data } = spec.buildRequests( - [ - { - ...sampleBidRequestBase, - params: { - testMode: true, - }, - }, - ], - sampleBidderRequest - ); - expect(data.tm).to.equal(true); - }); - - it('will attach additional referrer info data', () => { - const { data } = spec.buildRequests( - [sampleBidRequestBase], - sampleBidderRequest - ); - expect(data.ri.r).to.equal( - sampleBidderRequest.refererInfo.topmostLocation - ); - expect(data.ri.t).to.equal(sampleBidderRequest.refererInfo.reachedTop); - expect(data.ri.l).to.equal(sampleBidderRequest.refererInfo.numIframes); - expect(data.ri.s).to.equal(sampleBidderRequest.refererInfo.stack); - expect(data.ri.c).to.equal(sampleBidderRequest.refererInfo.canonicalUrl); - }); - - it('if prebid is in an iframe, will use the frame url as domain, if the topmost is not avialable', () => { - const { data } = spec.buildRequests([sampleBidRequestBase], { - ...sampleBidderRequest, - refererInfo: { - location: null, - topmostLocation: null, - ref: 'http://search-traffic-source.com', - }, - }); - expect(data.do).to.equal('localhost'); - expect(data.re).to.equal('http://search-traffic-source.com'); - }); - - it('if prebid is in an iframe, will use the topmost url as domain', () => { - const { data } = spec.buildRequests([sampleBidRequestBase], { - ...sampleBidderRequest, - refererInfo: { - location: null, - topmostLocation: 'http://top-site.com', - ref: 'http://search-traffic-source.com', - }, - }); - expect(data.do).to.equal('top-site.com'); - expect(data.re).to.equal('http://search-traffic-source.com'); - }); - - it('handles GDPR, USP Consent, COPPA, and GPP', () => { - const { data } = spec.buildRequests( - [sampleBidRequestBase], - sampleBidderRequest - ); - delete data.m; // don't deal with 'm' in this test - expect(data.gs).to.equal(sampleBidderRequest.gdprConsent.gdprApplies); - expect(data.gc).to.equal(sampleBidderRequest.gdprConsent.consentString); - expect(data.usp).to.equal(sampleBidderRequest.uspConsent); - expect(data.gpp).to.equal(sampleBidderRequest.gppConsent); - expect(data.cpp).to.equal(0); - }); - - it('will forward bid request count & wins count data', () => { - const bidderRequestsCount = Math.floor(Math.random() * 100); - const bidderWinsCount = Math.floor(Math.random() * 100); - const { data } = spec.buildRequests( - [ - { - ...sampleBidRequestBase, - bidderRequestsCount, - bidderWinsCount, - }, - ], - sampleBidderRequest - ); - - expect(data.brc).to.equal(bidderRequestsCount); - expect(data.bwc).to.equal(bidderWinsCount); - expect(data.trc).to.equal(0); - }); - - it('will attach sync configuration', () => { - const request = () => - spec.buildRequests([sampleBidRequestBase], sampleBidderRequest); - - const setConfig = (filterSettings) => - config.setConfig({ - userSync: { - syncsPerBidder: 2, - syncDelay: 2300, - syncEnabled: true, - filterSettings, - }, - }); - - const test = (filterSettings) => { - setConfig(filterSettings); - return request().data.sync; - }; - - const base = { d: 2300, l: 2, e: true }; - - const tests = [ - [undefined, { ...base, t: 0 }], - [ - { - image: { - bidders: '*', - filter: 'include', - }, - iframe: { - bidders: '*', - filter: 'include', - }, - }, - { ...base, t: 3 }, - ], - [ - { - image: { - bidders: ['amx'], - }, - iframe: { - bidders: '*', - filter: 'include', - }, - }, - { ...base, t: 3 }, - ], - [ - { - image: { - bidders: ['other'], - }, - iframe: { - bidders: '*', - }, - }, - { ...base, t: 2 }, - ], - [ - { - image: { - bidders: ['amx'], - }, - iframe: { - bidders: ['amx'], - filter: 'exclude', - }, - }, - { ...base, t: 1 }, - ], - ]; - - for (let i = 0, l = tests.length; i < l; i++) { - const [result, expected] = tests[i]; - expect(test(result), `input: ${JSON.stringify(result)}`).to.deep.equal( - expected - ); - } - }); - - it('will forward first-party data', () => { - const { data } = spec.buildRequests( - [sampleBidRequestBase], - sampleBidderRequest - ); - expect(data.fpd2).to.deep.equal(sampleFPD); - }); - - it('will collect & forward RTI user IDs', () => { - const randomRTI = `greatRTI${Math.floor(Math.random() * 100)}`; - const userId = { - criteoId: 'sample-criteo', - digitrustid: { data: { id: 'sample-digitrust' } }, - id5id: { uid: 'sample-id5' }, - idl_env: 'sample-liveramp', - lipb: { lipbid: 'sample-liveintent' }, - netId: 'sample-netid', - parrableId: { eid: 'sample-parrable' }, - pubcid: 'sample-pubcid', - [randomRTI]: 'sample-unknown', - tdid: 'sample-ttd', - }; - - const eids = createEidsArray(userId); - const bid = { - ...sampleBidRequestBase, - userIdAsEids: eids, - }; - - const { data } = spec.buildRequests([bid, bid], sampleBidderRequest); - expect(data.eids).to.deep.equal(eids); - }); - - it('can build a banner request', () => { - const { method, url, data } = spec.buildRequests( - [ - sampleBidRequestBase, - { - ...sampleBidRequestBase, - bidId: sampleRequestId + '_2', - params: { - ...sampleBidRequestBase.params, - adUnitId: '', - tagId: 'example', - }, - }, - ], - sampleBidderRequest - ); - - expect(url).to.equal(sampleBidRequestBase.params.endpoint); - expect(method).to.equal('POST'); - expect(Object.keys(data.m).length).to.equal(2); - expect(data.m[sampleRequestId]).to.deep.equal({ - av: true, - au: 'div-gpt-ad-example', - vd: {}, - ms: [[[320, 50]], [[300, 250]], []], - aw: 300, - sc: {}, - ah: 250, - tf: 0, - f: 0.5, - vr: false, - rtb: { - ext: sampleImpExt, - }, - }); - expect(data.m[sampleRequestId + '_2']).to.deep.equal({ - av: true, - aw: 300, - au: 'div-gpt-ad-example', - sc: {}, - ms: [[[320, 50]], [[300, 250]], []], - i: 'example', - ah: 250, - vd: {}, - tf: 0, - f: 0.5, - vr: false, - rtb: { - ext: sampleImpExt, - }, - }); - }); - - it('can build a video request', () => { - const { data } = spec.buildRequests( - [ - { - ...sampleBidRequestVideo, - params: { - ...sampleBidRequestVideo.params, - adUnitId: 'custom-auid', - }, - }, - ], - sampleBidderRequest - ); - expect(Object.keys(data.m).length).to.equal(1); - expect(data.m[sampleRequestId + '_video']).to.deep.equal({ - au: 'custom-auid', - ms: [[[300, 150]], [], [[360, 250]]], - av: true, - aw: 360, - ah: 250, - sc: schainConfig, - vd: { - sizes: [[360, 250]], - context: 'adpod', - adPodDurationSec: 90, - contentMode: 'live', - }, - tf: 0, - f: 0.5, - rtb: { - ext: sampleImpExt, - }, - vr: true, - }); - }); - }); - - describe('interpretResponse', () => { - const baseBidResponse = { - requestId: sampleRequestId, - cpm: 0.25, - creativeId: sampleDisplayCRID, - currency: 'USD', - netRevenue: true, - meta: { - advertiserDomains: ['example.com'], - }, - }; - - const baseRequest = { - data: { - m: { - [sampleRequestId]: { - aw: 300, - ah: 250, - }, - }, - }, - }; - - it('will handle a nobid response', () => { - const parsed = spec.interpretResponse({ body: '' }, baseRequest); - expect(parsed).to.eql([]); - }); - - const cases = [ - [ - 'pbjs.bidderSettings', - (conf) => { - const before = getGlobal().bidderSettings; - getGlobal().bidderSettings = conf; - return before; - }, - (before) => { - getGlobal().bidderSettings = before; - }, - ], - [ - 'setConfig / bidderSettings (legacy)', - (conf) => { - const before = config.getConfig(); - config.setConfig({ - bidderSettings: conf, - }); - - return before; - }, - (before) => { - config.setConfig(before); - }, - ], - ]; - - cases.forEach(([name, setup, teardown]) => { - it(`will read an bidderCode override from bid.ext.prebid.meta, set with ${name}`, () => { - const currentConfig = setup({ - amx: { - allowAlternateBidderCodes: true, - }, - }); - const parsed = spec.interpretResponse( - { - body: { - ...sampleServerResponse, - r: { - [sampleRequestId]: [ - { - ...sampleServerResponse.r[sampleRequestId][0], - b: [ - { - ...sampleServerResponse.r[sampleRequestId][0].b[0], - ext: { - bc: 'amx-pmp', - ds: 'example', - dsp: 'example-dsp', - }, - }, - ], - }, - ], - }, - }, - }, - baseRequest - ); - - teardown(currentConfig); - expect(parsed.length).to.equal(1); // we removed one - - // we should have display, video, display - expect(parsed[0]).to.deep.equal({ - ...baseBidResponse, - meta: { - ...baseBidResponse.meta, - mediaType: BANNER, - demandSource: 'example', - networkId: 'example-dsp', - }, - mediaType: BANNER, - bidderCode: 'amx-pmp', - width: 300, - height: 600, // from the bid itself - ttl: 90, - ad: sampleDisplayAd, - }); - }); - }); - - it('can parse a display ad', () => { - const parsed = spec.interpretResponse( - { body: sampleServerResponse }, - baseRequest - ); - expect(parsed.length).to.equal(2); - - // we should have display, video, display - expect(parsed[0]).to.deep.equal({ - ...baseBidResponse, - meta: { - ...baseBidResponse.meta, - mediaType: BANNER, - }, - mediaType: BANNER, - width: 300, - height: 600, // from the bid itself - ttl: 90, - ad: sampleDisplayAd, - }); - }); - - it('can parse a video ad', () => { - const parsed = spec.interpretResponse( - { body: sampleServerResponse }, - baseRequest - ); - expect(parsed.length).to.equal(2); - expect(parsed[1]).to.deep.equal({ - ...baseBidResponse, - meta: { - ...baseBidResponse.meta, - mediaType: VIDEO, - }, - mediaType: VIDEO, - vastXml: sampleVideoAd(''), - width: 300, - height: 250, - ttl: 90, - }); - }); - }); - - describe('analytics methods', () => { - let firedPixels = []; - let _Image = window.Image; - before(() => { - _Image = window.Image; - window.Image = class FakeImage { - _src = ''; - - get src() { - return this._src; - } - - set src(value) { - this._src = value; - firedPixels.push(value); - } - }; - }); - - beforeEach(() => { - firedPixels = []; - }); - - after(() => { - window.Image = _Image; - }); - - it('will fire an event for onSetTargeting', () => { - spec.onSetTargeting({ - bidder: 'example', - width: 300, - height: 250, - adId: 'ad-id', - mediaType: BANNER, - cpm: 1.23, - requestId: utils.getUniqueIdentifierStr(), - adUnitCode: 'div-gpt-ad', - adserverTargeting: { - hb_pb: '1.23', - hb_adid: 'ad-id', - hb_bidder: 'example', - }, - }); - expect(firedPixels.length).to.equal(1); - expect(firedPixels[0]).to.match(/\/hbx\/g_pbst/); - try { - const parsed = new URL(firedPixels[0]); - const nestedData = parsed.searchParams.get('c2'); - expect(nestedData).to.equal( - utils.formatQS({ - hb_pb: '1.23', - hb_adid: 'ad-id', - hb_bidder: 'example', - }) - ); - } catch (e) { - // unsupported browser; try testing for string - const pixel = firedPixels[0]; - expect(pixel).to.have.string(encodeURIComponent('hb_pb=1.23')); - expect(pixel).to.have.string(encodeURIComponent('hb_adid=ad-id')); - } - }); - - it('will log an event for timeout', () => { - // this will use sendBeacon.. - spec.onTimeout([ - { - bidder: 'example', - bidId: 'test-bid-id', - adUnitCode: 'div-gpt-ad', - ortb2: { - site: { - ref: 'https://example.com', - }, - }, - params: { - tagId: 'tag-id', - }, - timeout: 300, - auctionId: utils.getUniqueIdentifierStr(), - }, - ]); - - const [request] = server.requests; - request.respond(204, { 'Content-Type': 'text/html' }, null); - expect(request.url).to.equal('https://1x1.a-mo.net/e'); - - if (typeof Request !== 'undefined' && 'keepalive' in Request.prototype) { - expect(request.fetch.request.keepalive).to.equal(true); - } - - const { c: common, e: events } = JSON.parse(request.requestBody); - expect(common).to.deep.equal({ - V: '$prebid.version$', - vg: getGlobalVarName(), - U: null, - re: 'https://example.com', - }); - - expect(events.length).to.equal(1); - const [event] = events; - expect(event.n).to.equal('g_pbto'); - expect(event.A).to.equal('example'); - expect(event.mid).to.equal('tag-id'); - expect(event.cn).to.equal(300); - expect(event.bid).to.equal('test-bid-id'); - expect(event.a).to.equal('div-gpt-ad'); - }); - - it('will log an event for prebid win', () => { - spec.onBidWon({ - bidder: 'example', - adId: 'test-ad-id', - width: 300, - height: 250, - mediaType: VIDEO, - cpm: 1.34, - adUnitCode: 'div-gpt-ad', - timeout: 300, - auctionId: utils.getUniqueIdentifierStr(), - }); - expect(firedPixels.length).to.equal(1); - expect(firedPixels[0]).to.match(/\/hbx\/g_pbwin/); - - const pixel = firedPixels[0]; - try { - const url = new URL(pixel); - expect(url.searchParams.get('C')).to.equal('1'); - expect(url.searchParams.get('np')).to.equal('1.34'); - } catch (e) { - expect(pixel).to.have.string('C=1'); - expect(pixel).to.have.string('np=1.34'); - } - }); - }); -}); diff --git a/test/spec/modules/aniviewBidAdapter_spec.js b/test/spec/modules/aniviewBidAdapter_spec.js deleted file mode 100644 index d86902b47..000000000 --- a/test/spec/modules/aniviewBidAdapter_spec.js +++ /dev/null @@ -1,426 +0,0 @@ -import { spec } from 'modules/aniviewBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -const { expect } = require('chai'); - -const PUBLISHER_ID_1 = 'publisher_id_1'; -const CHANNEL_ID_1 = 'channel_id_1'; -const PUBLISHER_ID_2 = 'publisher_id_2'; -const CHANNEL_ID_2 = 'channel_id_2'; -const BID_ID_1 = 'bid_id_1'; -const BID_ID_2 = 'bid_id_2'; -const BIDDER_REQUEST_ID = 'bidder_request_id'; -const CUSTOM_DOMAIN = 'example.com'; - -const BASE_URL = 'https://' + CUSTOM_DOMAIN + '/track' + - '?rtbbp=10' + - '&cpm=${AUCTION_PRICE}' + - '&aucid=${AUCTION_ID}' + - '&aucbid=${AUCTION_BID_ID}' + - '&limid=${AUCTION_IMP_ID}' + - '&aucseid=${AUCTION_SEAT_ID}' + - '&aucadid=${AUCTION_AD_ID}'; -const LURL = `${BASE_URL}&e=AV_M40&rcd=\${AUCTION_LOSS}`; -const NURL = `${BASE_URL}&e=AV_M4`; - -const VIDEO_VAST = `` -const BANNER_VAST = VIDEO_VAST; -const BANNER_HTML = '

HTML BANNER

'; - -const CURRENCY = 'USD'; -const PRICE = 10; -const FLOOR_PRICE = PRICE * 0.5; -const TTL = 600; - -const VIDEO_SIZE = { width: 640, height: 360 }; -const BANNER_SIZE = { width: 250, height: 250 }; - -const CUSTOM_RENDERER_URL = `https://${CUSTOM_DOMAIN}/script/6.1/prebidRenderer.js`; -const DEFAULT_RENDERER_URL = `https://player.aniview.com/script/6.1/prebidRenderer.js`; - -const REPLACEMENT_1 = '12345'; - -const MOCK = { - bidRequest: () => ({ - bidderCode: 'aniview', - auctionId: null, - bidderRequestId: BIDDER_REQUEST_ID, - bids: [ - { - bidder: 'aniview', - params: { - AV_PUBLISHERID: PUBLISHER_ID_1, - AV_CHANNELID: CHANNEL_ID_1, - playerDomain: CUSTOM_DOMAIN, - }, - mediaTypes: { - video: { - playerSize: [[VIDEO_SIZE.width, VIDEO_SIZE.height]], - context: 'outstream', - mimes: ['video/mpeg', 'video/mp4', 'application/javascript'], - } - }, - bidId: BID_ID_1, - bidderRequestId: BIDDER_REQUEST_ID, - sizes: [[VIDEO_SIZE.width, VIDEO_SIZE.height]], - }, - { - bidder: 'aniview', - params: { - AV_PUBLISHERID: PUBLISHER_ID_2, - AV_CHANNELID: CHANNEL_ID_2, - playerDomain: CUSTOM_DOMAIN, - replacements: { - AV_CDIM1: REPLACEMENT_1, - }, - }, - mediaTypes: { - video: { - playerSize: [[VIDEO_SIZE.width, VIDEO_SIZE.height]], - context: 'outstream', - mimes: ['video/mpeg', 'video/mp4', 'application/javascript'], - } - }, - bidId: BID_ID_2, - bidderRequestId: BIDDER_REQUEST_ID, - sizes: [[VIDEO_SIZE.width, VIDEO_SIZE.height]], - floorData: { - currency: CURRENCY, - floor: FLOOR_PRICE, - }, - getFloor: _ => ({ - currency: CURRENCY, - floor: FLOOR_PRICE, - }), - }, - ], - auctionStart: 1722343584268, - timeout: 1_000, - start: 1722343584269, - ortb2: { - source: {}, - site: { - page: 'http://localhost:8080/', - ref: 'http://localhost:8080/', - domain: 'http://localhost:8080', - publisher: { - domain: 'http://localhost:8080', - } - }, - device: { - w: 1800, - h: 1169, - language: 'en', - }, - }, - }), - - bidderResponse: () => ({ - body: { - id: 'bidder_response_id', - bidid: 'bidder_response_bid_id', - cur: CURRENCY, - ext: { - aniview: { - sync: [ - { url: 'https://iframe-1.example.com/sync', e: 'sync', pr: '14', t: 3 }, - { url: 'https://iframe-2.example.com/sync', e: 'sync', pr: '28', t: 3 }, - { url: 'https://image.example.com/sync', e: 'sync', pr: 'abc12', t: 1 } - ] - } - }, - seatbid: [ - { - seat: '', - bid: [ - { - adm: VIDEO_VAST, - adomain: [''], - id: 'seatbid_bid_id_1', - impid: BID_ID_1, - lurl: LURL, - nurl: NURL, - price: PRICE, - } - ] - } - ] - }, - }) -} - -describe('Aniview Bid Adapter', function () { - const adapter = newBidder(spec); - - describe('Inherited function', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - let videoBidRequest; - - beforeEach(() => { - videoBidRequest = MOCK.bidRequest(); - }); - - it('should return `true` when required params found', function () { - expect(spec.isBidRequestValid(videoBidRequest.bids[0])).to.be.true; - }); - - it('should return `false` when required params are wrong', function () { - videoBidRequest.bids[0].params = { something: 'is wrong' }; - - expect(spec.isBidRequestValid(videoBidRequest.bids[0])).to.be.false; - }); - }); - - describe('buildRequests', function () { - let videoBidRequest; - - beforeEach(() => { - videoBidRequest = MOCK.bidRequest(); - }); - - it('should return expected request object', function () { - const bidRequest = spec.buildRequests(videoBidRequest.bids, videoBidRequest); - - expect(bidRequest).to.exist.and.to.be.a('array').and.to.have.lengthOf(2); - - const { url, method, data } = bidRequest[0]; - const { ext, imp } = data; - - expect(url).equal('https://rtb.aniview.com/sspRTB2'); - expect(method).equal('POST'); - expect(imp[0].tagid).equal(CHANNEL_ID_1); - expect(imp[0].id).equal(videoBidRequest.bids[0].bidId); - expect(ext.aniview.pbjs).equal(1); - }); - - it('should have floor data inside imp', function () { - const bidRequest = spec.buildRequests(videoBidRequest.bids, videoBidRequest); - const imp = bidRequest[1].data.imp[0]; - - expect(imp.bidfloor).equal(FLOOR_PRICE); - expect(imp.bidfloorcur).equal(CURRENCY); - }); - - it('should have replacements in request', function () { - const bidRequest = spec.buildRequests(videoBidRequest.bids, videoBidRequest); - const { replacements } = bidRequest[1].data.ext.aniview; - - expect(replacements.AV_CDIM1).equal(REPLACEMENT_1); - }); - - it('should not have floor data in imp if getFloor returns empty object', function () { - videoBidRequest.bids[1].getFloor = () => ({}); - - const bidRequest = spec.buildRequests(videoBidRequest.bids, videoBidRequest); - const imp = bidRequest[1].data.imp[0]; - - expect(imp.bidfloor).not.exist; - expect(imp.bidfloorcur).not.exist; - }); - - it('should have vastUrl if adm is not provided but nurl is', function () { - const bidRequests = spec.buildRequests(videoBidRequest.bids, videoBidRequest); - const bidderResponse = MOCK.bidderResponse(); - - delete bidderResponse.body.seatbid[0].bid[0].adm - - const bids = spec.interpretResponse(bidderResponse, bidRequests[0]); - const bid = bids[0]; - - expect(bid.vastXml).to.not.exist; - expect(bid.vastUrl).to.exist.and.to.not.have.string('${AUCTION_PRICE}'); - expect(bid.vastUrl).to.have.string('cpm=' + PRICE); - }); - - it('should use dev environment', function () { - const DEV_ENDPOINT = 'https://dev.aniview.com/sspRTB2'; - videoBidRequest.bids[0].params.dev = { endpoint: DEV_ENDPOINT }; - - const bidRequest = spec.buildRequests(videoBidRequest.bids, videoBidRequest); - - expect(bidRequest[0].url).to.equal(DEV_ENDPOINT); - }); - }); - - describe('interpretResponse', function () { - describe('Video format', function () { - let bidRequests, bidderResponse; - - beforeEach(function() { - const videoBidRequest = MOCK.bidRequest(); - - bidRequests = spec.buildRequests(videoBidRequest.bids, videoBidRequest); - bidderResponse = MOCK.bidderResponse(); - }); - - it('should return empty bids array for empty response', function () { - const emptyResponse = bidderResponse.body = {}; - const bids = spec.interpretResponse(emptyResponse, bidRequests[0]); - - expect(bids).to.be.empty; - }); - - it('should return valid bids array', function () { - const bids = spec.interpretResponse(bidderResponse, bidRequests[0]); - const bid = bids[0]; - - expect(bids.length).to.greaterThan(0); - expect(bid.vastXml).to.exist.and.to.not.have.string('${AUCTION_PRICE}'); - expect(bid.vastXml).to.have.string('cpm=' + PRICE); - expect(bid.vastUrl).to.not.exist; - expect(bid.requestId).to.equal(bidRequests[0].data.imp[0].id); - expect(bid.cpm).to.equal(PRICE); - expect(bid.ttl).to.equal(TTL); - expect(bid.currency).to.equal(CURRENCY); - expect(bid.netRevenue).to.equal(true); - expect(bid.mediaType).to.equal('video'); - expect(bid.meta.advertiserDomains).to.be.an('array'); - expect(bid.creativeId).to.exist; - expect(bid.width).to.exist; - expect(bid.height).to.exist; - }); - - it('should return bid without required properties if cpm less or equal 0', function () { - bidderResponse.body.seatbid[0].bid[0].price = 0; - - const bids = spec.interpretResponse(bidderResponse, bidRequests[0]); - const bid = bids[0]; - - expect(bid.renderer).to.not.exist; - expect(bid.ad).to.not.exist; - }); - - it('should return empty bids array if no bids in response', function () { - bidderResponse.body.seatbid[0].bid = []; - - const bids = spec.interpretResponse(bidderResponse, bidRequests[0]); - - expect(bids).to.exist.and.to.be.a('array').and.to.have.lengthOf(0); - }); - - it('should add renderer if outstream context', function () { - const bid = spec.interpretResponse(bidderResponse, bidRequests[0])[0]; - - expect(bid.renderer.url).to.equal(CUSTOM_RENDERER_URL); - expect(bid.renderer.config.AV_PUBLISHERID).to.equal(PUBLISHER_ID_1); - expect(bid.renderer.config.AV_CHANNELID).to.equal(CHANNEL_ID_1); - expect(bid.renderer.loaded).to.equal(false); - expect(bid.width).to.equal(VIDEO_SIZE.width); - expect(bid.height).to.equal(VIDEO_SIZE.height); - }); - - it('should use default renderer domain', function () { - delete bidRequests[0].bids[0].params.playerDomain; - - const bid = spec.interpretResponse(bidderResponse, bidRequests[0])[0]; - - expect(bid.renderer.url).to.equal(DEFAULT_RENDERER_URL); - }); - - it('should not add renderer if context is not outstream', function () { - bidRequests[0].bids[0].mediaTypes.video.context = 'instream'; - - const bid = spec.interpretResponse(bidderResponse, bidRequests[0])[0]; - - expect(bidRequests[0].bids[0].mediaTypes.video.context).to.be.not.equal('outstream'); - expect(bid.renderer).to.not.exist; - }); - }); - - describe('Banner format', function () { - let bidRequests, bidderResponse; - - beforeEach(function() { - const bannerBidRequest = MOCK.bidRequest(); - - // Converting video bid request to banner bid request - - delete bannerBidRequest.bids[0].mediaTypes.video; - - bannerBidRequest.bids[0].sizes = [[BANNER_SIZE.width, BANNER_SIZE.height]]; - bannerBidRequest.bids[0].mediaTypes.banner = { - sizes: [ - [BANNER_SIZE.width, BANNER_SIZE.height], - [BANNER_SIZE.width * 2, BANNER_SIZE.height], - ], - }; - - bidRequests = spec.buildRequests(bannerBidRequest.bids, bannerBidRequest); - bidderResponse = MOCK.bidderResponse(); - }); - - it('should return valid banner bids (HTML)', function () { - bidderResponse.body.seatbid[0].bid[0].adm = BANNER_HTML; - - const bid = spec.interpretResponse(bidderResponse, bidRequests[0])[0]; - - expect(bid.ad).to.exist; - expect(bid.cpm).to.equal(PRICE); - expect(bid.width).to.equal(BANNER_SIZE.width); - expect(bid.height).to.equal(BANNER_SIZE.height); - expect(bid.renderer).to.not.exist; - }); - - it('should return valid banner bids (VAST) with renderer', function () { - bidderResponse.body.seatbid[0].bid[0].adm = BANNER_VAST; - - const bid = spec.interpretResponse(bidderResponse, bidRequests[0])[0]; - - expect(bid.ad).to.exist; - expect(bid.ad).to.not.have.string('${AUCTION_PRICE}'); - expect(bid.ad).to.have.string('cpm=' + PRICE); - expect(bid.cpm).to.equal(PRICE); - expect(bid.width).to.equal(BANNER_SIZE.width); - expect(bid.height).to.equal(BANNER_SIZE.height); - expect(bid.renderer.url).to.equal(CUSTOM_RENDERER_URL); - expect(bid.renderer.config.AV_PUBLISHERID).to.equal(PUBLISHER_ID_1); - expect(bid.renderer.config.AV_CHANNELID).to.equal(CHANNEL_ID_1); - expect(bid.renderer.loaded).to.equal(false); - }); - }); - }); - - describe('getUserSyncs', function () { - let bidRequest, bidderResponse; - - beforeEach(function() { - const videoBidRequest = MOCK.bidRequest(); - - bidRequest = spec.buildRequests(videoBidRequest.bids, videoBidRequest); - bidderResponse = MOCK.bidderResponse(); - }); - - it('should get syncs from response', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }, [bidderResponse]); - - expect(syncs).to.be.a('array').and.to.have.lengthOf(3); - }); - - it('should get only pixel syncs from response', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: false, pixelEnabled: true }, [bidderResponse]); - - expect(syncs).to.be.a('array').and.to.have.lengthOf(1); - expect(syncs[0].type).to.equal('image'); - }); - - it('should return empty array of syncs if no syncs in response', function () { - delete bidderResponse.body.ext.aniview.sync - - const syncs = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: false }, [bidderResponse]); - - expect(syncs).to.be.a('array').and.to.have.lengthOf(0); - }); - - it('should return empty array of syncs if no body in response', function () { - delete bidderResponse.body - - const syncs = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }, [bidderResponse]); - - expect(syncs).to.be.a('array').and.to.have.lengthOf(0); - }); - }); -}); diff --git a/test/spec/modules/anonymisedRtdProvider_spec.js b/test/spec/modules/anonymisedRtdProvider_spec.js deleted file mode 100644 index 91d3fe1bf..000000000 --- a/test/spec/modules/anonymisedRtdProvider_spec.js +++ /dev/null @@ -1,324 +0,0 @@ -import {config} from 'src/config.js'; -import {getRealTimeData, anonymisedRtdSubmodule, storage} from 'modules/anonymisedRtdProvider.js'; -import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; - -describe('anonymisedRtdProvider', function() { - let getDataFromLocalStorageStub; - - const testReqBidsConfigObj = { - adUnits: [ - { - bids: ['bid1', 'bid2'] - } - ] - }; - - const onDone = function() { return true }; - - const cmoduleConfig = { - 'name': 'anonymised', - 'params': { - 'cohortStorageKey': 'cohort_ids' - } - } - - beforeEach(function() { - config.resetConfig(); - getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage') - }); - - afterEach(function () { - getDataFromLocalStorageStub.restore(); - }); - - describe('anonymisedRtdSubmodule', function() { - it('successfully instantiates', function () { - expect(anonymisedRtdSubmodule.init()).to.equal(true); - }); - it('should load external script when params.tagConfig.clientId is set', function () { - const rtdConfig = { - params: { - tagConfig: { - clientId: 'testId' - } - } - }; - anonymisedRtdSubmodule.init(rtdConfig, {}); - expect(loadExternalScriptStub.called).to.be.true; - }); - it('should not load external script when params.tagConfig.clientId is not set', function () { - const rtdConfig = { - params: { - tagConfig: {} - } - }; - anonymisedRtdSubmodule.init(rtdConfig, {}); - expect(loadExternalScriptStub.called).to.be.false; - }); - it('should not load external script when params.tagConfig is not defined', function () { - const rtdConfig = { - params: {} - }; - anonymisedRtdSubmodule.init(rtdConfig, {}); - expect(loadExternalScriptStub.called).to.be.false; - }); - it('should not load external script when params.tagConfig.clientId is empty string', function () { - const rtdConfig = { - params: { - tagConfig: { - clientId: ' ' - } - } - }; - anonymisedRtdSubmodule.init(rtdConfig, {}); - expect(loadExternalScriptStub.called).to.be.false; - }); - it('should not load external script when params.tagConfig.clientId is not a string', function () { - const rtdConfig = { - params: { - tagConfig: { - clientId: 123 - } - } - }; - anonymisedRtdSubmodule.init(rtdConfig, {}); - expect(loadExternalScriptStub.called).to.be.false; - }); - it('should load external script with correct attributes', function () { - const rtdConfig = { - params: { - tagConfig: { - clientId: 'testId' - } - } - }; - anonymisedRtdSubmodule.init(rtdConfig, {}); - const expected = 'https://static.anonymised.io/light/loader.js?ref=prebid'; - const expectedTagConfig = { - idw_client_id: 'testId' - }; - - expect(loadExternalScriptStub.args[0][0]).to.deep.equal(expected); - expect(loadExternalScriptStub.args[0][5]).to.deep.equal(expectedTagConfig); - }); - it('should not load external script when it is already loaded', function () { - const rtdConfig = { - params: { - tagConfig: { - clientId: 'testId' - } - } - }; - const script = document.createElement('script'); - script.src = 'https://static.anonymised.io/light/loader.js?random=quary'; - document.body.appendChild(script); - anonymisedRtdSubmodule.init(rtdConfig, {}); - expect(loadExternalScriptStub.called).to.be.false; - }); - it('should load external script from tagUrl when it is set', function () { - const rtdConfig = { - params: { - tagUrl: 'https://example.io/loader.js', - tagConfig: { - clientId: 'testId' - } - } - }; - anonymisedRtdSubmodule.init(rtdConfig, {}); - const expected = 'https://example.io/loader.js'; - - expect(loadExternalScriptStub.args[0][0]).to.deep.equal(expected); - }); - it('should not load external script from tagUrl when it is already loaded', function () { - const rtdConfig = { - params: { - tagUrl: 'https://example.io/loader.js', - tagConfig: { - clientId: 'testId' - } - } - }; - const script = document.createElement('script'); - script.src = 'https://example.io/loader.js'; - document.body.appendChild(script); - anonymisedRtdSubmodule.init(rtdConfig, {}); - expect(loadExternalScriptStub.called).to.be.false; - }); - }); - - describe('Get Real-Time Data', function() { - it('gets rtd from local storage and set to ortb2.user.data', function() { - const rtdConfig = { - params: { - cohortStorageKey: 'cohort_ids', - bidders: ['smartadserver'], - segtax: 503 - } - }; - - const bidConfig = { - ortb2Fragments: { - global: {} - } - }; - - const rtdUserObj1 = { - name: 'anonymised.io', - ext: { - segtax: 503 - }, - segment: [ - { - id: 'TCZPQOWPEJG3MJOTUQUF793A' - }, - { - id: '93SUG3H540WBJMYNT03KX8N3' - } - ] - }; - - getDataFromLocalStorageStub.withArgs('cohort_ids') - .returns(JSON.stringify(['TCZPQOWPEJG3MJOTUQUF793A', '93SUG3H540WBJMYNT03KX8N3'])); - - getRealTimeData(bidConfig, () => {}, rtdConfig, {}); - expect(bidConfig.ortb2Fragments.global.user.data).to.deep.include.members([rtdUserObj1]); - expect(bidConfig.ortb2Fragments.global.user.keywords).to.be.undefined; - }); - - it('gets rtd from local storage and set to ortb2.user.keywords for appnexus bidders parameter', function() { - const rtdConfig = { - params: { - cohortStorageKey: 'cohort_ids', - bidders: ['smartadserver', 'appnexus'], - segtax: 503 - } - }; - - const bidConfig = { - ortb2Fragments: { - global: {} - } - }; - - const rtdUserObj1 = { - name: 'anonymised.io', - ext: { - segtax: 503 - }, - segment: [ - { - id: 'TCZPQOWPEJG3MJOTUQUF793A' - }, - { - id: '93SUG3H540WBJMYNT03KX8N3' - } - ] - }; - - getDataFromLocalStorageStub.withArgs('cohort_ids') - .returns(JSON.stringify(['TCZPQOWPEJG3MJOTUQUF793A', '93SUG3H540WBJMYNT03KX8N3'])); - - getRealTimeData(bidConfig, () => {}, rtdConfig, {}); - expect(bidConfig.ortb2Fragments.global.user.data).to.deep.include.members([rtdUserObj1]); - expect(bidConfig.ortb2Fragments.global.user.keywords).to.include('perid=TCZPQOWPEJG3MJOTUQUF793A'); - expect(bidConfig.ortb2Fragments.global.user.keywords).to.include('perid=93SUG3H540WBJMYNT03KX8N3'); - }); - - it('gets rtd from local storage and set to ortb2.user.data if `bidders` parameter undefined', function() { - const rtdConfig = { - params: { - cohortStorageKey: 'cohort_ids', - segtax: 503 - } - }; - - const bidConfig = { - ortb2Fragments: { - global: {} - } - }; - - const rtdUserObj1 = { - name: 'anonymised.io', - ext: { - segtax: 503 - }, - segment: [ - { - id: 'TCZPQOWPEJG3MJOTUQUF793A' - }, - { - id: '93SUG3H540WBJMYNT03KX8N3' - } - ] - }; - - getDataFromLocalStorageStub.withArgs('cohort_ids') - .returns(JSON.stringify(['TCZPQOWPEJG3MJOTUQUF793A', '93SUG3H540WBJMYNT03KX8N3'])); - - getRealTimeData(bidConfig, () => {}, rtdConfig, {}); - expect(bidConfig.ortb2Fragments.global.user.data).to.deep.include.members([rtdUserObj1]); - expect(bidConfig.ortb2Fragments.global.user.keywords).to.be.undefined; - }); - - it('do not set rtd if `cohortStorageKey` parameter undefined', function() { - const rtdConfig = { - params: { - bidders: ['smartadserver'] - } - }; - - const bidConfig = { - ortb2Fragments: { - global: {} - } - }; - - getDataFromLocalStorageStub.withArgs('cohort_ids') - .returns(JSON.stringify(['randomsegmentid'])); - - getRealTimeData(bidConfig, () => {}, rtdConfig, {}); - expect(bidConfig.ortb2Fragments.global.user).to.be.undefined; - }); - - it('do not set rtd if local storage empty', function() { - const rtdConfig = { - params: { - cohortStorageKey: 'cohort_ids', - segtax: 503 - } - }; - - const bidConfig = {}; - - getDataFromLocalStorageStub.withArgs('cohort_ids') - .returns(null); - - expect(config.getConfig().ortb2).to.be.undefined; - getRealTimeData(bidConfig, () => {}, rtdConfig, {}); - expect(config.getConfig().ortb2).to.be.undefined; - }); - - it('do not set rtd if local storage has incorrect value', function() { - const rtdConfig = { - params: { - cohortStorageKey: 'cohort_ids', - segtax: 503 - } - }; - - const bidConfig = {}; - - getDataFromLocalStorageStub.withArgs('cohort_ids') - .returns('wrong cohort ids value'); - - expect(config.getConfig().ortb2).to.be.undefined; - getRealTimeData(bidConfig, () => {}, rtdConfig, {}); - expect(config.getConfig().ortb2).to.be.undefined; - }); - - it('should initialize and return with config', function () { - expect(getRealTimeData(testReqBidsConfigObj, onDone, cmoduleConfig)).to.equal(undefined) - }); - }); -}); diff --git a/test/spec/modules/anyclipBidAdapter_spec.js b/test/spec/modules/anyclipBidAdapter_spec.js deleted file mode 100644 index a25c285e6..000000000 --- a/test/spec/modules/anyclipBidAdapter_spec.js +++ /dev/null @@ -1,449 +0,0 @@ -import {expect} from 'chai'; -import {config} from 'src/config.js'; -import {spec} from 'modules/anyclipBidAdapter.js'; -import {deepClone} from 'src/utils'; -import {getBidFloor} from '../../../libraries/xeUtils/bidderUtils.js'; - -const ENDPOINT = 'https://prebid.anyclip.com'; - -const defaultRequest = { - tmax: 0, - adUnitCode: 'test', - bidId: '1', - requestId: 'qwerty', - ortb2: { - source: { - tid: 'auctionId' - } - }, - ortb2Imp: { - ext: { - tid: 'tr1', - } - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 200] - ] - } - }, - bidder: 'anyclip', - params: { - publisherId: 'anyclip', - supplyTagId: '40', - ext: {} - }, - bidRequestsCount: 1 -}; - -const defaultRequestVideo = deepClone(defaultRequest); -defaultRequestVideo.mediaTypes = { - video: { - playerSize: [640, 480], - context: 'instream', - skipppable: true - } -}; - -const videoBidderRequest = { - bidderCode: 'anyclip', - bids: [{mediaTypes: {video: {}}, bidId: 'qwerty'}] -}; - -const displayBidderRequest = { - bidderCode: 'anyclip', - bids: [{bidId: 'qwerty'}] -}; - -describe('anyclipBidAdapter', () => { - describe('isBidRequestValid', function () { - it('should return false when request params is missing', function () { - const invalidRequest = deepClone(defaultRequest); - delete invalidRequest.params; - expect(spec.isBidRequestValid(invalidRequest)).to.equal(false); - }); - - it('should return false when required publisherId param is missing', function () { - const invalidRequest = deepClone(defaultRequest); - delete invalidRequest.params.publisherId; - expect(spec.isBidRequestValid(invalidRequest)).to.equal(false); - }); - - it('should return false when required supplyTagId param is missing', function () { - const invalidRequest = deepClone(defaultRequest); - delete invalidRequest.params.supplyTagId; - expect(spec.isBidRequestValid(invalidRequest)).to.equal(false); - }); - - it('should return false when video.playerSize is missing', function () { - const invalidRequest = deepClone(defaultRequestVideo); - delete invalidRequest.mediaTypes.video.playerSize; - expect(spec.isBidRequestValid(invalidRequest)).to.equal(false); - }); - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(defaultRequest)).to.equal(true); - }); - }); - - describe('buildRequests', function () { - beforeEach(function () { - config.resetConfig(); - }); - - it('should send request with correct structure', function () { - const request = spec.buildRequests([defaultRequest], {}); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal(ENDPOINT + '/bid'); - expect(request.options).to.have.property('contentType').and.to.equal('application/json'); - expect(request).to.have.property('data'); - }); - - it('should build basic request structure', function () { - const request = JSON.parse(spec.buildRequests([defaultRequest], {}).data)[0]; - expect(request).to.have.property('tmax').and.to.equal(defaultRequest.tmax); - expect(request).to.have.property('bidId').and.to.equal(defaultRequest.bidId); - expect(request).to.have.property('auctionId').and.to.equal(defaultRequest.ortb2.source.tid); - expect(request).to.have.property('transactionId').and.to.equal(defaultRequest.ortb2Imp.ext.tid); - expect(request).to.have.property('tz').and.to.equal(new Date().getTimezoneOffset()); - expect(request).to.have.property('bc').and.to.equal(1); - expect(request).to.have.property('banner').and.to.deep.equal({sizes: [[300, 250], [300, 200]]}); - expect(request).to.have.property('gdprConsent').and.to.deep.equal({}); - expect(request).to.have.property('userEids').and.to.deep.equal([]); - expect(request).to.have.property('usPrivacy').and.to.equal(''); - expect(request).to.have.property('sizes').and.to.deep.equal(['300x250', '300x200']); - expect(request).to.have.property('ext').and.to.deep.equal({}); - expect(request).to.have.property('env').and.to.deep.equal({ - publisherId: 'anyclip', - supplyTagId: '40', - floor: null - }); - expect(request).to.have.property('device').and.to.deep.equal({ - ua: navigator.userAgent, - lang: navigator.language - }); - }); - - it('should build request with schain', function () { - const schainRequest = deepClone(defaultRequest); - const bidderRequest = { - ortb2: { - source: { - ext: { - schain: { - ver: '1.0' - } - } - } - } - }; - const request = JSON.parse(spec.buildRequests([schainRequest], bidderRequest).data)[0]; - expect(request).to.have.property('schain').and.to.deep.equal({ - ver: '1.0' - }); - }); - - it('should build request with location', function () { - const bidderRequest = { - refererInfo: { - page: 'page', - location: 'location', - domain: 'domain', - ref: 'ref', - isAmp: false - } - }; - const request = JSON.parse(spec.buildRequests([defaultRequest], bidderRequest).data)[0]; - expect(request).to.have.property('location'); - const location = request.location; - expect(location).to.have.property('page').and.to.equal('page'); - expect(location).to.have.property('location').and.to.equal('location'); - expect(location).to.have.property('domain').and.to.equal('domain'); - expect(location).to.have.property('ref').and.to.equal('ref'); - expect(location).to.have.property('isAmp').and.to.equal(false); - }); - - it('should build request with ortb2 info', function () { - const ortb2Request = deepClone(defaultRequest); - ortb2Request.ortb2 = { - site: { - name: 'name' - } - }; - const request = JSON.parse(spec.buildRequests([ortb2Request], {}).data)[0]; - expect(request).to.have.property('ortb2').and.to.deep.equal({ - site: { - name: 'name' - } - }); - }); - - it('should build request with ortb2Imp info', function () { - const ortb2ImpRequest = deepClone(defaultRequest); - ortb2ImpRequest.ortb2Imp = { - ext: { - data: { - pbadslot: 'home1', - adUnitSpecificAttribute: '1' - } - } - }; - const request = JSON.parse(spec.buildRequests([ortb2ImpRequest], {}).data)[0]; - expect(request).to.have.property('ortb2Imp').and.to.deep.equal({ - ext: { - data: { - pbadslot: 'home1', - adUnitSpecificAttribute: '1' - } - } - }); - }); - - it('should build request with valid bidfloor', function () { - const bfRequest = deepClone(defaultRequest); - bfRequest.getFloor = () => ({floor: 5, currency: 'USD'}); - const request = JSON.parse(spec.buildRequests([bfRequest], {}).data)[0].env; - expect(request).to.have.property('floor').and.to.equal(5); - }); - - it('should build request with usp consent data if applies', function () { - const bidderRequest = { - uspConsent: '1YA-' - }; - const request = JSON.parse(spec.buildRequests([defaultRequest], bidderRequest).data)[0]; - expect(request).to.have.property('usPrivacy').and.equals('1YA-'); - }); - - it('should build request with extended ids', function () { - const idRequest = deepClone(defaultRequest); - idRequest.userIdAsEids = [ - {source: 'adserver.org', uids: [{id: 'TTD_ID_FROM_USER_ID_MODULE', atype: 1, ext: {rtiPartner: 'TDID'}}]}, - {source: 'pubcid.org', uids: [{id: 'pubCommonId_FROM_USER_ID_MODULE', atype: 1}]} - ]; - const request = JSON.parse(spec.buildRequests([idRequest], {}).data)[0]; - expect(request).to.have.property('userEids').and.deep.equal(idRequest.userIdAsEids); - }); - - it('should build request with video', function () { - const request = JSON.parse(spec.buildRequests([defaultRequestVideo], {}).data)[0]; - expect(request).to.have.property('video').and.to.deep.equal({ - playerSize: [640, 480], - context: 'instream', - skipppable: true - }); - expect(request).to.have.property('sizes').and.to.deep.equal(['640x480']); - }); - }); - - describe('interpretResponse', function () { - it('should return empty bids', function () { - const serverResponse = { - body: { - data: null - } - }; - - const invalidResponse = spec.interpretResponse(serverResponse, {}); - expect(invalidResponse).to.be.an('array').that.is.empty; - }); - - it('should interpret valid response', function () { - const serverResponse = { - body: { - data: [{ - requestId: 'qwerty', - cpm: 1, - currency: 'USD', - width: 300, - height: 250, - ttl: 600, - meta: { - advertiserDomains: ['anyclip'] - }, - ext: { - pixels: [ - ['iframe', 'surl1'], - ['image', 'surl2'], - ] - } - }] - } - }; - - const validResponse = spec.interpretResponse(serverResponse, {bidderRequest: displayBidderRequest}); - const bid = validResponse[0]; - expect(validResponse).to.be.an('array').that.is.not.empty; - expect(bid.requestId).to.equal('qwerty'); - expect(bid.cpm).to.equal(1); - expect(bid.currency).to.equal('USD'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.ttl).to.equal(600); - expect(bid.meta).to.deep.equal({advertiserDomains: ['anyclip']}); - }); - - it('should interpret valid banner response', function () { - const serverResponse = { - body: { - data: [{ - requestId: 'qwerty', - cpm: 1, - currency: 'USD', - width: 300, - height: 250, - ttl: 600, - mediaType: 'banner', - creativeId: 'xe-demo-banner', - ad: 'ad', - meta: {} - }] - } - }; - - const validResponseBanner = spec.interpretResponse(serverResponse, {bidderRequest: displayBidderRequest}); - const bid = validResponseBanner[0]; - expect(validResponseBanner).to.be.an('array').that.is.not.empty; - expect(bid.mediaType).to.equal('banner'); - expect(bid.creativeId).to.equal('xe-demo-banner'); - expect(bid.ad).to.equal('ad'); - }); - - it('should interpret valid video response', function () { - const serverResponse = { - body: { - data: [{ - requestId: 'qwerty', - cpm: 1, - currency: 'USD', - width: 600, - height: 480, - ttl: 600, - mediaType: 'video', - creativeId: 'xe-demo-video', - ad: 'vast-xml', - meta: {} - }] - } - }; - - const validResponseBanner = spec.interpretResponse(serverResponse, {bidderRequest: videoBidderRequest}); - const bid = validResponseBanner[0]; - expect(validResponseBanner).to.be.an('array').that.is.not.empty; - expect(bid.mediaType).to.equal('video'); - expect(bid.creativeId).to.equal('xe-demo-video'); - expect(bid.ad).to.equal('vast-xml'); - }); - }); - - describe('getUserSyncs', function () { - it('shoukd handle no params', function () { - const opts = spec.getUserSyncs({}, []); - expect(opts).to.be.an('array').that.is.empty; - }); - - it('should return empty if sync is not allowed', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: false}); - expect(opts).to.be.an('array').that.is.empty; - }); - - it('should allow iframe sync', function () { - const opts = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: false}, [{ - body: { - data: [{ - requestId: 'qwerty', - ext: { - pixels: [ - ['iframe', 'surl1?a=b'], - ['image', 'surl2?a=b'], - ] - } - }] - } - }]); - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('iframe'); - expect(opts[0].url).to.equal('surl1?a=b&us_privacy=&gdpr=0&gdpr_consent='); - }); - - it('should allow pixel sync', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [{ - body: { - data: [{ - requestId: 'qwerty', - ext: { - pixels: [ - ['iframe', 'surl1?a=b'], - ['image', 'surl2?a=b'], - ] - } - }] - } - }]); - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('image'); - expect(opts[0].url).to.equal('surl2?a=b&us_privacy=&gdpr=0&gdpr_consent='); - }); - - it('should allow pixel sync and parse consent params', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [{ - body: { - data: [{ - requestId: 'qwerty', - ext: { - pixels: [ - ['iframe', 'surl1?a=b'], - ['image', 'surl2?a=b'], - ] - } - }] - } - }], { - gdprApplies: 1, - consentString: '1YA-' - }); - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('image'); - expect(opts[0].url).to.equal('surl2?a=b&us_privacy=&gdpr=1&gdpr_consent=1YA-'); - }); - }); - - describe('getBidFloor', function () { - it('should return null when getFloor is not a function', () => { - const bid = {getFloor: 2}; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when getFloor doesnt return an object', () => { - const bid = {getFloor: () => 2}; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when floor is not a number', () => { - const bid = { - getFloor: () => ({floor: 'string', currency: 'USD'}) - }; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when currency is not USD', () => { - const bid = { - getFloor: () => ({floor: 5, currency: 'EUR'}) - }; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return floor value when everything is correct', () => { - const bid = { - getFloor: () => ({floor: 5, currency: 'USD'}) - }; - const result = getBidFloor(bid); - expect(result).to.equal(5); - }); - }); -}); diff --git a/test/spec/modules/apacdexBidAdapter_spec.js b/test/spec/modules/apacdexBidAdapter_spec.js deleted file mode 100644 index 7bcbcac5e..000000000 --- a/test/spec/modules/apacdexBidAdapter_spec.js +++ /dev/null @@ -1,734 +0,0 @@ -import { expect } from 'chai' -import { spec, validateGeoObject, getDomain } from '../../../modules/apacdexBidAdapter.js' -import { newBidder } from 'src/adapters/bidderFactory.js' -import { userSync } from '../../../src/userSync.js'; -import { config } from 'src/config.js'; -import { deepClone } from 'src/utils.js'; - -describe('ApacdexBidAdapter', function () { - const adapter = newBidder(spec) - - describe('.code', function () { - it('should return a bidder code of apacdex', function () { - expect(spec.code).to.equal('apacdex') - }) - }) - - describe('inherited functions', function () { - it('should exist and be a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function') - }) - }) - - describe('.isBidRequestValid', function () { - it('should return false if there are no params', () => { - const bid = { - 'bidder': 'apacdex', - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if there is no siteId or placementId param', () => { - const bid = { - 'bidder': 'apacdex', - 'adUnitCode': 'adunit-code', - params: { - site_id: '1a2b3c4d5e6f1a2b3c4d', - placement_id: 'plcm12345678', - }, - 'mediaTypes': { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if there is no mediaTypes', () => { - const bid = { - 'bidder': 'apacdex', - 'adUnitCode': 'adunit-code', - params: { - siteId: '1a2b3c4d5e6f1a2b3c4d' - }, - 'mediaTypes': { - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true if the bid is valid', () => { - const bid = { - 'bidder': 'apacdex', - 'adUnitCode': 'adunit-code', - params: { - siteId: '1a2b3c4d5e6f1a2b3c4d' - }, - 'mediaTypes': { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - describe('banner', () => { - it('should return false if there are no banner sizes', () => { - const bid = { - 'bidder': 'apacdex', - 'adUnitCode': 'adunit-code', - params: { - siteId: '1a2b3c4d5e6f1a2b3c4d' - }, - 'mediaTypes': { - banner: { - - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true if there is banner sizes', () => { - const bid = { - 'bidder': 'apacdex', - 'adUnitCode': 'adunit-code', - params: { - siteId: '1a2b3c4d5e6f1a2b3c4d' - }, - 'mediaTypes': { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - - describe('video', () => { - it('should return false if there is no playerSize defined in the video mediaType', () => { - const bid = { - 'bidder': 'apacdex', - 'adUnitCode': 'adunit-code', - params: { - siteId: '1a2b3c4d5e6f1a2b3c4d', - sizes: [[300, 250], [300, 600]] - }, - 'mediaTypes': { - video: { - context: 'instream' - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true if there is playerSize defined on the video mediaType', () => { - const bid = { - 'bidder': 'apacdex', - 'adUnitCode': 'adunit-code', - params: { - siteId: '1a2b3c4d5e6f1a2b3c4d', - }, - 'mediaTypes': { - video: { - context: 'instream', - playerSize: [[640, 480]] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - }); - - describe('.buildRequests', function () { - beforeEach(function () { - sinon.stub(userSync, 'canBidderRegisterSync'); - }); - afterEach(function () { - userSync.canBidderRegisterSync.restore(); - }); - const bidRequest = [{ - 'ortb2': { - 'source': { - 'ext': { - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'indirectseller.com', - 'sid': '00001', - 'hp': 1 - }, - { - 'asi': 'indirectseller-2.com', - 'sid': '00002', - 'hp': 0 - }, - ] - } - } - } - }, - 'bidder': 'apacdex', - 'params': { - 'siteId': '1a2b3c4d5e6f1a2b3c4d' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'targetKey': 0, - 'bidId': '30b31c1838de1f', - 'userIdAsEids': [{ - 'source': 'criteo.com', - 'uids': [{ - 'id': 'p0cCLF9JazY1ZUFjazJRb3NKbEprVTcwZ0IwRUlGalBjOG9laUZNbFJ0ZGpOSnVFbE9VMjBNMzNBTzladGt4cUVGQzBybDY2Y1FqT1dkUkFsMmJIWDRHNjlvNXJjbiUyQlZDd1dOTmt6VlV2TDhRd0F0RTlBcmpyZU5WRHBPU25GQXpyMnlT', - 'atype': 1 - }] - }, { - 'source': 'pubcid.org', - 'uids': [{ - 'id': '2ae366c2-2576-45e5-bd21-72ed10598f17', - 'atype': 1 - }] - }], - }, - { - 'bidder': 'apacdex', - 'params': { - 'ad_unit': '/7780971/sparks_prebid_LB', - 'sizes': [[300, 250], [300, 600]], - 'referrer': 'overrides_top_window_location' - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[120, 600], [300, 600], [160, 600]], - 'targetKey': 1, - 'bidId': '30b31c1838de1e', - }]; - - const bidderRequests = { - 'gdprConsent': { - 'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - 'vendorData': {}, - 'gdprApplies': true - }, - 'refererInfo': { - 'numIframes': 0, - 'reachedTop': true, - 'referer': 'https://example.com', - 'stack': ['https://example.com'] - }, - uspConsent: 'someCCPAString' - }; - - it('should return a properly formatted request', function () { - const bidRequests = spec.buildRequests(bidRequest, bidderRequests) - expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/pbjs') - expect(bidRequests.method).to.equal('POST') - expect(bidRequests.bidderRequests).to.eql(bidRequest); - }) - - it('should return a properly formatted request with GDPR applies set to true', function () { - const bidRequests = spec.buildRequests(bidRequest, bidderRequests) - expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/pbjs') - expect(bidRequests.method).to.equal('POST') - expect(bidRequests.data.gdpr.gdprApplies).to.equal(true) - expect(bidRequests.data.gdpr.consentString).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==') - }) - - it('should return a properly formatted request with GDPR applies set to false', function () { - bidderRequests.gdprConsent.gdprApplies = false; - const bidRequests = spec.buildRequests(bidRequest, bidderRequests) - expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/pbjs') - expect(bidRequests.method).to.equal('POST') - expect(bidRequests.data.gdpr.gdprApplies).to.equal(false) - expect(bidRequests.data.gdpr.consentString).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==') - }) - it('should return a properly formatted request with GDPR applies set to false with no consent_string param', function () { - const bidderRequests = { - 'gdprConsent': { - 'consentString': undefined, - 'vendorData': {}, - 'gdprApplies': false - }, - 'refererInfo': { - 'numIframes': 0, - 'reachedTop': true, - 'referer': 'https://example.com', - 'stack': ['https://example.com'] - } - }; - const bidRequests = spec.buildRequests(bidRequest, bidderRequests) - expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/pbjs') - expect(bidRequests.method).to.equal('POST') - expect(bidRequests.data.gdpr.gdprApplies).to.equal(false) - expect(bidRequests.data.gdpr).to.not.include.keys('consentString') - }) - it('should return a properly formatted request with GDPR applies set to true with no consentString param', function () { - const bidderRequests = { - 'gdprConsent': { - 'consentString': undefined, - 'vendorData': {}, - 'gdprApplies': true - }, - 'refererInfo': { - 'numIframes': 0, - 'reachedTop': true, - 'referer': 'https://example.com', - 'stack': ['https://example.com'] - } - }; - const bidRequests = spec.buildRequests(bidRequest, bidderRequests) - expect(bidRequests.url).to.equal('https://useast.quantumdex.io/auction/pbjs') - expect(bidRequests.method).to.equal('POST') - expect(bidRequests.data.gdpr.gdprApplies).to.equal(true) - expect(bidRequests.data.gdpr).to.not.include.keys('consentString') - }) - it('should return a properly formatted request with schain defined', function () { - const bidRequests = spec.buildRequests(bidRequest, bidderRequests); - expect(bidRequests.data.schain).to.deep.equal(bidRequest[0].ortb2.source.ext.schain) - }); - it('should return a properly formatted request with eids defined', function () { - const bidRequests = spec.buildRequests(bidRequest, bidderRequests); - expect(bidRequests.data.eids).to.deep.equal(bidRequest[0].userIdAsEids) - }); - it('should return a properly formatted request with us_privacy included', function () { - const bidRequests = spec.buildRequests(bidRequest, bidderRequests); - expect(bidRequests.data.us_privacy).to.equal('someCCPAString'); - }); - it('should attach bidFloor param when either bid param floorPrice or getFloor function exists', function () { - const getFloorResponse = { currency: 'USD', floor: 3 }; - let singleBidRequest; let request; let payload = null; - - // 1 -> floorPrice not defined, getFloor not defined > empty - singleBidRequest = deepClone(bidRequest[0]); - request = spec.buildRequests([singleBidRequest], bidderRequests); - payload = request.data; - expect(payload.bids[0].bidFloor).to.not.exist; - - // 2 -> floorPrice is defined, getFloor not defined > floorPrice is used - singleBidRequest = deepClone(bidRequest[0]); - singleBidRequest.params = { - 'siteId': '1890909', - 'floorPrice': 0.5 - }; - request = spec.buildRequests([singleBidRequest], bidderRequests); - payload = request.data - expect(payload.bids[0].bidFloor).to.exist.and.to.equal(0.5); - - // 3 -> floorPrice is defined, getFloor is defined > getFloor is used - singleBidRequest = deepClone(bidRequest[0]); - singleBidRequest.params = { - 'siteId': '1890909', - 'floorPrice': 0.5 - }; - singleBidRequest.getFloor = () => getFloorResponse; - request = spec.buildRequests([singleBidRequest], bidderRequests); - payload = request.data - expect(payload.bids[0].bidFloor).to.exist.and.to.equal(3); - - // 4 -> floorPrice not defined, getFloor is defined > getFloor is used - singleBidRequest = deepClone(bidRequest[0]); - singleBidRequest.getFloor = () => getFloorResponse; - request = spec.buildRequests([singleBidRequest], bidderRequests); - payload = request.data - expect(payload.bids[0].bidFloor).to.exist.and.to.equal(3); - }); - describe('debug test', function () { - beforeEach(function () { - config.setConfig({ debug: true }); - }); - afterEach(function () { - config.setConfig({ debug: false }); - }); - it('should return a properly formatted request with pbjs_debug is true', function () { - const bidRequests = spec.buildRequests(bidRequest, bidderRequests); - expect(bidRequests.data.test).to.equal(1); - }); - }); - }); - - describe('.interpretResponse', function () { - const bidRequests = { - 'method': 'POST', - 'url': 'https://useast.quantumdex.io/auction/pbjs', - 'withCredentials': true, - 'data': { - 'device': { - 'ua': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36', - 'height': 937, - 'width': 1920, - 'dnt': 0, - 'language': 'vi' - }, - 'site': { - 'id': '343', - 'page': 'https://www.example.com/page', - 'referrer': '', - 'hostname': 'www.example.com' - } - }, - 'bidderRequests': [ - { - 'bidder': 'apacdex', - 'params': { - 'siteId': '343' - }, - 'crumbs': { - 'pubcid': 'c2b2ba08-9954-4850-8ee5-2bf4a2b35eff' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[160, 600], [120, 600]] - } - }, - 'adUnitCode': 'vi_3431035_1', - 'transactionId': '994d8404-4a28-4c43-98d8-a38dbb061910', - 'sizes': [[160, 600], [120, 600]], - 'bidId': '3000aa31c41a29c21', - 'bidderRequestId': '299926b3d3628cdd7', - 'auctionId': '22445943-a0aa-4c63-a413-4deb64fcff1c', - 'src': 'client', - 'bidRequestsCount': 41, - 'bidderRequestsCount': 41, - 'bidderWinsCount': 0, - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'freegames66.com', - 'sid': '343', - 'hp': 1 - } - ] - } - }, - { - 'bidder': 'apacdex', - 'params': { - 'siteId': '343' - }, - 'crumbs': { - 'pubcid': 'c2b2ba08-9954-4850-8ee5-2bf4a2b35eff' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [250, 250], [200, 200], [180, 150]] - } - }, - 'adUnitCode': 'vi_3431033_1', - 'transactionId': '800fe87e-bfec-43a5-ace0-c4e2373ff4b5', - 'sizes': [[300, 250], [250, 250], [200, 200], [180, 150]], - 'bidId': '30024615be22ef66a', - 'bidderRequestId': '299926b3d3628cdd7', - 'auctionId': '22445943-a0aa-4c63-a413-4deb64fcff1c', - 'src': 'client', - 'bidRequestsCount': 41, - 'bidderRequestsCount': 41, - 'bidderWinsCount': 0, - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'freegames66.com', - 'sid': '343', - 'hp': 1 - } - ] - } - }, - { - 'bidder': 'apacdex', - 'params': { - 'siteId': '343' - }, - 'crumbs': { - 'pubcid': 'c2b2ba08-9954-4850-8ee5-2bf4a2b35eff' - }, - 'mediaTypes': { - 'video': { - 'playerSize': [[640, 480]], - 'context': 'instream', - 'mimes': [ - 'video/mp4', - 'video/x-flv', - 'video/x-ms-wmv', - 'application/vnd.apple.mpegurl', - 'application/x-mpegurl', - 'video/3gpp', - 'video/mpeg', - 'video/ogg', - 'video/quicktime', - 'video/webm', - 'video/x-m4v', - 'video/ms-asf', - 'video/x-msvideo' - ], - 'protocols': [1, 2, 3, 4, 5, 6], - 'playbackmethod': [6], - 'maxduration': 120, - 'linearity': 1, - 'api': [2] - } - }, - 'adUnitCode': 'vi_3431909', - 'transactionId': '33d83d87-43cc-499b-aabe-5c22eb6acfbb', - 'sizes': [[640, 480]], - 'bidId': '1854b40107d6745c', - 'bidderRequestId': '1840763b6bda185d', - 'auctionId': 'df495de0-5d42-471f-a501-73bcd7254b80', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'freegames66.com', - 'sid': '343', - 'hp': 1 - } - ] - } - } - ] - }; - - const serverResponse = { - 'body': { - 'bids': [ - { - 'requestId': '3000aa31c41a29c21', - 'cpm': 1.07, - 'width': 160, - 'height': 600, - 'ad': `
Apacdex AD
`, - 'ttl': 500, - 'creativeId': '1234abcd', - 'netRevenue': true, - 'currency': 'USD', - 'dealId': 'apacdex', - 'mediaType': 'banner', - 'meta': { - 'advertiserDomains': ['https://example.com'] - } - }, - { - 'requestId': '30024615be22ef66a', - 'cpm': 1, - 'width': 300, - 'height': 250, - 'ad': `
Apacdex AD
`, - 'ttl': 500, - 'creativeId': '1234abcd', - 'netRevenue': true, - 'currency': 'USD', - 'dealId': 'apacdex', - 'mediaType': 'banner', - 'meta': { - 'advertiserDomains': ['https://example.com'] - } - }, - { - 'requestId': '1854b40107d6745c', - 'cpm': 1.25, - 'width': 300, - 'height': 250, - 'vastXml': 'apacdex', - 'ttl': 500, - 'creativeId': '30292e432662bd5f86d90774b944b038', - 'netRevenue': true, - 'currency': 'USD', - 'dealId': 'apacdex', - 'mediaType': 'video', - 'meta': { - 'advertiserDomains': ['https://example.com'] - } - } - ], - 'pixel': [{ - 'url': 'https://example.com/pixel.png', - 'type': 'image' - }] - } - }; - - const prebidResponse = [ - { - 'requestId': '3000aa31c41a29c21', - 'cpm': 1.07, - 'width': 160, - 'height': 600, - 'ad': `
Apacdex AD
`, - 'ttl': 500, - 'creativeId': '1234abcd', - 'netRevenue': true, - 'currency': 'USD', - 'dealId': 'apacdex', - 'mediaType': 'banner' - }, - { - 'requestId': '30024615be22ef66a', - 'cpm': 1, - 'width': 300, - 'height': 250, - 'ad': `
Apacdex AD
`, - 'ttl': 500, - 'creativeId': '1234abcd', - 'netRevenue': true, - 'currency': 'USD', - 'dealId': 'apacdex', - 'mediaType': 'banner' - }, - { - 'requestId': '1854b40107d6745c', - 'cpm': 1.25, - 'width': 300, - 'height': 250, - 'vastXml': 'apacdex', - 'ttl': 500, - 'creativeId': '30292e432662bd5f86d90774b944b038', - 'netRevenue': true, - 'currency': 'USD', - 'dealId': 'apacdex', - 'mediaType': 'video' - } - ]; - - it('should map bidResponse to prebidResponse', function () { - const response = spec.interpretResponse(serverResponse, bidRequests); - response.forEach((resp, i) => { - expect(resp.requestId).to.equal(prebidResponse[i].requestId); - expect(resp.cpm).to.equal(prebidResponse[i].cpm); - expect(resp.width).to.equal(prebidResponse[i].width); - expect(resp.height).to.equal(prebidResponse[i].height); - expect(resp.ttl).to.equal(prebidResponse[i].ttl); - expect(resp.creativeId).to.equal(prebidResponse[i].creativeId); - expect(resp.netRevenue).to.equal(prebidResponse[i].netRevenue); - expect(resp.currency).to.equal(prebidResponse[i].currency); - expect(resp.dealId).to.equal(prebidResponse[i].dealId); - if (resp.mediaType === 'video') { - expect(resp.vastXml.indexOf('apacdex')).to.be.greaterThan(0); - } - if (resp.mediaType === 'banner') { - expect(resp.ad.indexOf('Apacdex AD')).to.be.greaterThan(0); - } - expect(resp.meta.advertiserDomains).to.deep.equal(['https://example.com']); - }); - }); - }); - - describe('.getUserSyncs', function () { - const bidResponse = [{ - 'body': { - 'pixel': [{ - 'url': 'https://pixel-test', - 'type': 'image' - }] - } - }]; - - it('should return one sync pixel', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, bidResponse)).to.deep.equal([{ - type: 'image', - url: 'https://pixel-test' - }]); - }); - it('should return an empty array when sync is enabled but there are no bidResponses', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, [])).to.have.length(0); - }); - - it('should return an empty array when sync is enabled but no sync pixel returned', function () { - const pixel = Object.assign({}, bidResponse); - delete pixel[0].body.pixel; - expect(spec.getUserSyncs({ pixelEnabled: true }, bidResponse)).to.have.length(0); - }); - - it('should return an empty array', function () { - expect(spec.getUserSyncs({ pixelEnabled: false }, bidResponse)).to.have.length(0); - expect(spec.getUserSyncs({ pixelEnabled: true }, [])).to.have.length(0); - }); - }); - - describe('validateGeoObject', function () { - it('should return true if the geo object is valid', () => { - const geoObject = { - lat: 123.5624234, - lon: 23.6712341, - accuracy: 20 - }; - expect(validateGeoObject(geoObject)).to.equal(true); - }); - - it('should return false if the geo object is not plain object', () => { - const geoObject = [{ - lat: 123.5624234, - lon: 23.6712341, - accuracy: 20 - }]; - expect(validateGeoObject(geoObject)).to.equal(false); - }); - - it('should return false if the geo object is missing lat attribute', () => { - const geoObject = { - lon: 23.6712341, - accuracy: 20 - }; - expect(validateGeoObject(geoObject)).to.equal(false); - }); - - it('should return false if the geo object is missing lon attribute', () => { - const geoObject = { - lat: 123.5624234, - accuracy: 20 - }; - expect(validateGeoObject(geoObject)).to.equal(false); - }); - - it('should return false if the geo object is missing accuracy attribute', () => { - const geoObject = { - lat: 123.5624234, - lon: 23.6712341 - }; - expect(validateGeoObject(geoObject)).to.equal(false); - }); - }); -}); diff --git a/test/spec/modules/appStockSSPBidAdapter_spec.js b/test/spec/modules/appStockSSPBidAdapter_spec.js deleted file mode 100644 index 7ee7d739d..000000000 --- a/test/spec/modules/appStockSSPBidAdapter_spec.js +++ /dev/null @@ -1,534 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/appStockSSPBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; -import { config } from '../../../src/config.js'; -import { USERSYNC_DEFAULT_CONFIG } from '../../../src/userSync.js'; - -const bidder = 'appStockSSP'; - -describe('AppStockSSPBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - region: 'eu', - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - region: 'eu', - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid EU URL', function () { - bids[0].params.region = 'eu'; - serverRequest = spec.buildRequests(bids, bidderRequest); - expect(serverRequest.url).to.equal('https://ortb-eu.al-ad.com/pbjs'); - }); - - it('Returns valid EAST URL', function () { - bids[0].params.region = 'us-east'; - serverRequest = spec.buildRequests(bids, bidderRequest); - expect(serverRequest.url).to.equal('https://lb.al-ad.com/pbjs'); - }); - - it('Returns valid APAC URL', function () { - bids[0].params.region = 'apac'; - serverRequest = spec.buildRequests(bids, bidderRequest); - expect(serverRequest.url).to.equal('https://ortb-apac.al-ad.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://csync.al-ad.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://csync.al-ad.com/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://csync.al-ad.com/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/appierAnalyticsAdapter_spec.js b/test/spec/modules/appierAnalyticsAdapter_spec.js deleted file mode 100644 index e380672b7..000000000 --- a/test/spec/modules/appierAnalyticsAdapter_spec.js +++ /dev/null @@ -1,705 +0,0 @@ -import { - appierAnalyticsAdapter, getCpmInUsd, parseBidderCode, parseAdUnitCode, - ANALYTICS_VERSION, BIDDER_STATUS -} from 'modules/appierAnalyticsAdapter.js'; -import {expect} from 'chai'; -const events = require('src/events'); -const constants = require('src/constants.js'); - -const affiliateId = 'WhctHaViHtI'; -const configId = 'd9cc9a9be9b240eda17cf1c9a8a4b29c'; -const serverUrl = 'https://analytics.server.url/v1'; -const autoPick = 'none'; -const predictionId = '2a91ca5de54a4a2e89950af439f7a27f'; -const auctionId = 'b0b39610-b941-4659-a87c-de9f62d3e13e'; - -describe('Appier Prebid AnalyticsAdapter Testing', function () { - describe('event tracking and message cache manager', function () { - beforeEach(function () { - const configOptions = { - affiliateId: affiliateId, - configId: configId, - server: serverUrl, - autoPick: autoPick, - predictionId: predictionId, - sampling: 0, - adSampling: 1, - }; - - appierAnalyticsAdapter.enableAnalytics({ - provider: 'appierAnalytics', - options: configOptions - }); - }); - - afterEach(function () { - appierAnalyticsAdapter.disableAnalytics(); - }); - - describe('#getCpmInUsd()', function() { - it('should get bid cpm as currency is USD', function() { - const receivedBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_1', - bidder: 'appier', - bidderCode: 'APPIER', - requestId: 'a1b2c3d4', - timeToRespond: 72, - cpm: 0.1, - currency: 'USD', - originalCpm: 0.1, - originalCurrency: 'USD', - ad: 'fake ad1' - }, - ] - const result = getCpmInUsd(receivedBids[0]); - expect(result).to.equal(0.1); - }); - }); - - describe('#parseBidderCode()', function() { - it('should get lower case bidder code from bidderCode field value', function() { - const receivedBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_1', - bidder: 'appier', - bidderCode: 'APPIER', - requestId: 'a1b2c3d4', - timeToRespond: 72, - cpm: 0.1, - currency: 'USD', - originalCpm: 0.1, - originalCurrency: 'USD', - ad: 'fake ad1' - }, - ]; - const result = parseBidderCode(receivedBids[0]); - expect(result).to.equal('appier'); - }); - it('should get lower case bidder code from bidder field value as bidderCode field is missing', function() { - const receivedBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_1', - bidder: 'APPIER', - bidderCode: '', - requestId: 'a1b2c3d4', - timeToRespond: 72, - cpm: 0.1, - currency: 'USD', - originalCpm: 0.1, - originalCurrency: 'USD', - ad: 'fake ad1' - }, - ]; - const result = parseBidderCode(receivedBids[0]); - expect(result).to.equal('appier'); - }); - }); - - describe('#parseAdUnitCode()', function() { - it('should get lower case adUnit code from adUnitCode field value', function() { - const receivedBids = [ - { - auctionId: auctionId, - adUnitCode: 'ADUNIT', - bidder: 'appier', - bidderCode: 'APPIER', - requestId: 'a1b2c3d4', - timeToRespond: 72, - cpm: 0.1, - currency: 'USD', - originalCpm: 0.1, - originalCurrency: 'USD', - ad: 'fake ad1' - }, - ]; - const result = parseAdUnitCode(receivedBids[0]); - expect(result).to.equal('adunit'); - }); - }); - - describe('#getCachedAuction()', function() { - const existing = {timeoutBids: [{}]}; - appierAnalyticsAdapter.cachedAuctions['test_auction_id'] = existing; - - it('should get the existing cached object if it exists', function() { - const result = appierAnalyticsAdapter.getCachedAuction('test_auction_id'); - - expect(result).to.equal(existing); - }); - - it('should create a new object and store it in the cache on cache miss', function() { - const result = appierAnalyticsAdapter.getCachedAuction('no_such_id'); - - expect(result).to.deep.include({ - timeoutBids: [], - }); - }); - }); - - describe('when formatting JSON payload sent to backend', function() { - const receivedBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_1', - bidder: 'appier', - bidderCode: 'appier', - requestId: 'a1b2c3d4', - timeToRespond: 72, - cpm: 0.1, - currency: 'USD', - originalCpm: 0.1, - originalCurrency: 'USD', - ad: 'fake ad1' - }, - { - auctionId: auctionId, - adUnitCode: 'adunit_1', - bidder: 'reippa', - bidderCode: 'reippa', - requestId: 'b2c3d4e5', - timeToRespond: 100, - cpm: 0.08, - currency: 'USD', - originalCpm: 0.08, - originalCurrency: 'USD', - ad: 'fake ad2' - }, - { - auctionId: auctionId, - adUnitCode: 'adunit_2', - bidder: 'appier', - bidderCode: 'appier', - requestId: 'c3d4e5f6', - timeToRespond: 120, - cpm: 0.09, - currency: 'USD', - originalCpm: 0.09, - originalCurrency: 'USD', - ad: 'fake ad3' - }, - ]; - const highestCpmBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_1', - bidder: 'appier', - bidderCode: 'appier', - // No requestId - timeToRespond: 72, - cpm: 0.1, - currency: 'USD', - originalCpm: 0.1, - originalCurrency: 'USD', - ad: 'fake ad1' - } - ]; - const noBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_2', - bidder: 'appier', - bidderCode: 'appier', - bidId: 'a1b2c3d4', - } - ]; - const timeoutBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_2', - bidder: 'reippa', - bidderCode: 'reippa', - bidId: '00123d4c', - } - ]; - const withoutOriginalCpmBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_2', - bidder: 'appier', - bidderCode: 'appier', - requestId: 'c3d4e5f6', - timeToRespond: 120, - cpm: 0.29, - currency: 'USD', - originalCpm: '', - originalCurrency: 'USD', - ad: 'fake ad3' - }, - ]; - const withoutOriginalCurrencyBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_2', - bidder: 'appier', - bidderCode: 'appier', - requestId: 'c3d4e5f6', - timeToRespond: 120, - cpm: 0.09, - currency: 'USD', - originalCpm: 0.09, - originalCurrency: '', - ad: 'fake ad3' - }, - ]; - function assertHavingRequiredMessageFields(message) { - expect(message).to.include({ - version: ANALYTICS_VERSION, - auctionId: auctionId, - affiliateId: affiliateId, - configId: configId, - // referrer: window.location.href, - sampling: 0, - adSampling: 1, - prebid: '$prebid.version$', - // autoPick: 'manual', - }); - } - - describe('#createCommonMessage', function() { - it('should correctly serialize some common fields', function() { - const message = appierAnalyticsAdapter.createCommonMessage(auctionId); - - assertHavingRequiredMessageFields(message); - }); - }); - - describe('#serializeBidResponse', function() { - it('should handle BID properly and serialize bid price related fields', function() { - const result = appierAnalyticsAdapter.serializeBidResponse(receivedBids[0], BIDDER_STATUS.BID); - - expect(result).to.include({ - prebidWon: false, - isTimeout: false, - status: BIDDER_STATUS.BID, - time: 72, - cpm: 0.1, - currency: 'USD', - originalCpm: 0.1, - originalCurrency: 'USD', - cpmUsd: 0.1, - }); - }); - - it('should handle NO_BID properly and set status to noBid', function() { - const result = appierAnalyticsAdapter.serializeBidResponse(noBids[0], BIDDER_STATUS.NO_BID); - - expect(result).to.include({ - prebidWon: false, - isTimeout: false, - status: BIDDER_STATUS.NO_BID, - }); - }); - - it('should handle BID_WON properly and serialize bid price related fields', function() { - const result = appierAnalyticsAdapter.serializeBidResponse(receivedBids[0], BIDDER_STATUS.BID_WON); - - expect(result).to.include({ - prebidWon: true, - isTimeout: false, - status: BIDDER_STATUS.BID_WON, - time: 72, - cpm: 0.1, - currency: 'USD', - originalCpm: 0.1, - originalCurrency: 'USD', - cpmUsd: 0.1, - }); - }); - - it('should handle TIMEOUT properly and set status to timeout and isTimeout to true', function() { - const result = appierAnalyticsAdapter.serializeBidResponse(noBids[0], BIDDER_STATUS.TIMEOUT); - - expect(result).to.include({ - prebidWon: false, - isTimeout: true, - status: BIDDER_STATUS.TIMEOUT, - }); - }); - - it('should handle BID_WON properly and fill originalCpm field with cpm in missing originalCpm case', function() { - const result = appierAnalyticsAdapter.serializeBidResponse(withoutOriginalCpmBids[0], BIDDER_STATUS.BID_WON); - - expect(result).to.include({ - prebidWon: true, - isTimeout: false, - status: BIDDER_STATUS.BID_WON, - time: 120, - cpm: 0.29, - currency: 'USD', - originalCpm: 0.29, - originalCurrency: 'USD', - cpmUsd: 0.29, - }); - }); - - it('should handle BID_WON properly and fill originalCurrency field with currency in missing originalCurrency case', function() { - const result = appierAnalyticsAdapter.serializeBidResponse(withoutOriginalCurrencyBids[0], BIDDER_STATUS.BID_WON); - expect(result).to.include({ - prebidWon: true, - isTimeout: false, - status: BIDDER_STATUS.BID_WON, - time: 120, - cpm: 0.09, - currency: 'USD', - originalCpm: 0.09, - originalCurrency: 'USD', - cpmUsd: 0.09, - }); - }); - }); - - describe('#addBidResponseToMessage()', function() { - it('should add a bid response in the output message, grouped by adunit_id and bidder', function() { - const message = { - adUnits: {} - }; - appierAnalyticsAdapter.addBidResponseToMessage(message, noBids[0], BIDDER_STATUS.NO_BID); - - expect(message.adUnits).to.deep.include({ - 'adunit_2': { - 'appier': { - prebidWon: false, - isTimeout: false, - status: BIDDER_STATUS.NO_BID, - } - } - }); - }); - }); - - describe('#createBidMessage()', function() { - it('should format auction message sent to the backend', function() { - const args = { - auctionId: auctionId, - timestamp: 1234567890, - timeout: 3000, - auctionEnd: 1234567990, - adUnitCodes: ['adunit_1', 'adunit_2'], - bidsReceived: receivedBids, - noBids: noBids - }; - - const result = appierAnalyticsAdapter.createBidMessage(args, highestCpmBids, timeoutBids); - - assertHavingRequiredMessageFields(result); - expect(result).to.deep.include({ - auctionElapsed: 100, - timeout: 3000, - adUnits: { - 'adunit_1': { - 'appier': { - prebidWon: true, - isTimeout: false, - status: BIDDER_STATUS.BID, - time: 72, - cpm: 0.1, - currency: 'USD', - originalCpm: 0.1, - originalCurrency: 'USD', - cpmUsd: 0.1, - }, - 'reippa': { - prebidWon: false, - isTimeout: false, - status: BIDDER_STATUS.BID, - time: 100, - cpm: 0.08, - currency: 'USD', - originalCpm: 0.08, - originalCurrency: 'USD', - cpmUsd: 0.08, - } - }, - 'adunit_2': { - // this bid result exists in both bid and noBid arrays and should be treated as bid - 'appier': { - prebidWon: false, - isTimeout: false, - time: 120, - cpm: 0.09, - currency: 'USD', - originalCpm: 0.09, - originalCurrency: 'USD', - cpmUsd: 0.09, - status: BIDDER_STATUS.BID, - }, - 'reippa': { - prebidWon: false, - isTimeout: true, - status: BIDDER_STATUS.TIMEOUT, - } - } - } - }); - }); - }); - - describe('#createImpressionMessage()', function() { - it('should format message sent to the backend with the bid result', function() { - const bid = receivedBids[0]; - const result = appierAnalyticsAdapter.createImpressionMessage(bid); - - assertHavingRequiredMessageFields(result); - expect(result.adUnits).to.deep.include({ - 'adunit_1': { - 'appier': { - prebidWon: true, - isTimeout: false, - status: BIDDER_STATUS.BID_WON, - time: 72, - cpm: 0.1, - currency: 'USD', - originalCpm: 0.1, - originalCurrency: 'USD', - cpmUsd: 0.1, - } - } - }); - }); - }); - - describe('#createCreativeMessage()', function() { - it('should generate message sent to the backend with ad html grouped by adunit and bidder', function() { - const result = appierAnalyticsAdapter.createCreativeMessage(auctionId, receivedBids); - - assertHavingRequiredMessageFields(result); - expect(result.adUnits).to.deep.include({ - 'adunit_1': { - 'appier': { - ad: 'fake ad1' - }, - 'reippa': { - ad: 'fake ad2' - }, - }, - 'adunit_2': { - 'appier': { - ad: 'fake ad3' - } - } - }); - }); - }); - describe('#handleBidTimeout()', function() { - it('should cached the timeout bid as BID_TIMEOUT event was triggered', function() { - appierAnalyticsAdapter.cachedAuctions['test_timeout_auction_id'] = { 'timeoutBids': [] }; - const args = [{ - auctionId: 'test_timeout_auction_id', - timestamp: 1234567890, - timeout: 3000, - auctionEnd: 1234567990, - bidsReceived: receivedBids, - noBids: noBids - }]; - - appierAnalyticsAdapter.handleBidTimeout(args); - const result = appierAnalyticsAdapter.getCachedAuction('test_timeout_auction_id'); - expect(result).to.deep.include({ - timeoutBids: [{ - auctionId: 'test_timeout_auction_id', - timestamp: 1234567890, - timeout: 3000, - auctionEnd: 1234567990, - bidsReceived: receivedBids, - noBids: noBids - }] - }); - }); - }); - describe('#handleBidWon()', function() { - it('should call createImpressionMessage once as BID_WON event was triggered', function() { - sinon.spy(appierAnalyticsAdapter, 'createImpressionMessage'); - const receivedBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_1', - bidder: 'appier', - bidderCode: 'appier', - requestId: 'a1b2c3d4', - timeToRespond: 72, - cpm: 0.1, - currency: 'USD', - originalCpm: 0.1, - originalCurrency: 'USD', - ad: 'fake ad1' - }, - ] - - appierAnalyticsAdapter.handleBidWon(receivedBids[0]); - sinon.assert.callCount(appierAnalyticsAdapter.createImpressionMessage, 1); - appierAnalyticsAdapter.createImpressionMessage.restore(); - }); - }); - }); - }); - - describe('Appier Analytics Adapter track handler ', function () { - const configOptions = { - affiliateId: affiliateId, - configId: configId, - server: serverUrl, - autoPick: autoPick, - sampling: 1, - adSampling: 1, - }; - - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - appierAnalyticsAdapter.enableAnalytics({ - provider: 'appierAnalytics', - options: configOptions - }); - }); - - afterEach(function () { - appierAnalyticsAdapter.disableAnalytics(); - events.getEvents.restore(); - }); - - it('should call handleBidWon as BID_WON trigger event', function() { - sinon.spy(appierAnalyticsAdapter, 'handleBidWon'); - events.emit(constants.EVENTS.BID_WON, {}); - sinon.assert.callCount(appierAnalyticsAdapter.handleBidWon, 1); - appierAnalyticsAdapter.handleBidWon.restore(); - }); - - it('should call handleBidTimeout as BID_TIMEOUT trigger event', function() { - sinon.spy(appierAnalyticsAdapter, 'handleBidTimeout'); - events.emit(constants.EVENTS.BID_TIMEOUT, {}); - sinon.assert.callCount(appierAnalyticsAdapter.handleBidTimeout, 1); - appierAnalyticsAdapter.handleBidTimeout.restore(); - }); - - it('should call handleAuctionEnd as AUCTION_END trigger event', function() { - sinon.spy(appierAnalyticsAdapter, 'handleAuctionEnd'); - events.emit(constants.EVENTS.AUCTION_END, {}); - sinon.assert.callCount(appierAnalyticsAdapter.handleAuctionEnd, 1); - appierAnalyticsAdapter.handleAuctionEnd.restore(); - }); - - it('should call createCreativeMessage as AUCTION_END trigger event in adSampled is true', function() { - const configOptions = { - options: { - affiliateId: affiliateId, - configId: configId, - server: serverUrl, - autoPick: autoPick, - sampling: 1, - adSampling: 1, - adSampled: true, - } - }; - const args = { - auctionId: 'test_timeout_auction_id', - timestamp: 1234567890, - timeout: 3000, - auctionEnd: 1234567990, - }; - appierAnalyticsAdapter.initConfig(configOptions); - sinon.stub(appierAnalyticsAdapter, 'sendEventMessage').returns({}); - sinon.stub(appierAnalyticsAdapter, 'createBidMessage').returns({}); - sinon.spy(appierAnalyticsAdapter, 'createCreativeMessage'); - events.emit(constants.EVENTS.AUCTION_END, args); - sinon.assert.callCount(appierAnalyticsAdapter.createCreativeMessage, 1); - appierAnalyticsAdapter.sendEventMessage.restore(); - appierAnalyticsAdapter.createBidMessage.restore(); - appierAnalyticsAdapter.createCreativeMessage.restore(); - }); - }); - - describe('enableAnalytics and config parser', function () { - const configOptions = { - affiliateId: affiliateId, - configId: configId, - server: serverUrl, - autoPick: autoPick, - sampling: 0, - adSampling: 1, - }; - - beforeEach(function () { - appierAnalyticsAdapter.enableAnalytics({ - provider: 'appierAnalytics', - options: configOptions - }); - }); - - afterEach(function () { - appierAnalyticsAdapter.disableAnalytics(); - }); - - it('should parse config correctly with optional values', function () { - expect(appierAnalyticsAdapter.getAnalyticsOptions().options).to.deep.equal(configOptions); - expect(appierAnalyticsAdapter.getAnalyticsOptions().affiliateId).to.equal(configOptions.affiliateId); - expect(appierAnalyticsAdapter.getAnalyticsOptions().configId).to.equal(configOptions.configId); - expect(appierAnalyticsAdapter.getAnalyticsOptions().server).to.equal(configOptions.server); - expect(appierAnalyticsAdapter.getAnalyticsOptions().autoPick).to.equal(configOptions.autoPick); - expect(appierAnalyticsAdapter.getAnalyticsOptions().sampled).to.equal(false); - expect(appierAnalyticsAdapter.getAnalyticsOptions().adSampled).to.equal(true); - }); - - it('should not enable Analytics when affiliateId is missing', function () { - const configOptions = { - options: { - configId: configId - } - }; - const validConfig = appierAnalyticsAdapter.initConfig(configOptions); - expect(validConfig).to.equal(false); - }); - - it('should use DEFAULT_SERVER when server is missing', function () { - const configOptions = { - options: { - configId: configId, - affiliateId: affiliateId - } - }; - appierAnalyticsAdapter.initConfig(configOptions); - expect(appierAnalyticsAdapter.getAnalyticsOptions().server).to.equal('https://prebid-analytics.c.appier.net/v1'); - }); - - it('should use null when autoPick is missing', function () { - const configOptions = { - options: { - configId: configId, - affiliateId: affiliateId - } - }; - appierAnalyticsAdapter.initConfig(configOptions); - expect(appierAnalyticsAdapter.getAnalyticsOptions().autoPick).to.equal(null); - }); - - it('should not enable Analytics when configId is missing', function () { - const configOptions = { - options: { - affiliateId: affiliateId - } - }; - const validConfig = appierAnalyticsAdapter.initConfig(configOptions); - expect(validConfig).to.equal(false); - }); - - it('should fall back to default value when sampling factor is not number', function () { - const configOptions = { - options: { - affiliateId: affiliateId, - configId: configId, - sampling: 'string', - adSampling: 'string' - } - }; - appierAnalyticsAdapter.enableAnalytics({ - provider: 'appierAnalytics', - options: configOptions - }); - - expect(appierAnalyticsAdapter.getAnalyticsOptions().sampled).to.equal(false); - expect(appierAnalyticsAdapter.getAnalyticsOptions().adSampled).to.equal(true); - }); - }); -}); diff --git a/test/spec/modules/appierBidAdapter_spec.js b/test/spec/modules/appierBidAdapter_spec.js deleted file mode 100644 index 93f95fbd1..000000000 --- a/test/spec/modules/appierBidAdapter_spec.js +++ /dev/null @@ -1,178 +0,0 @@ -import { expect } from 'chai'; -import { spec, API_SERVERS_MAP, ADAPTER_VERSION } from 'modules/appierBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; - -describe('AppierAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'appier', - 'params': { - 'hzid': 'abcd' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - - it('should return true when required params zoneId found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required param zoneId is missing', function () { - const invalidBid = Object.assign({}, bid); - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when required param zoneId has wrong type', function () { - const invalidBid = Object.assign({}, bid); - invalidBid.params = { - 'hzid': null - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function() { - it('should return an empty list when there are no bid requests', function() { - const fakeBidRequests = []; - const fakeBidderRequest = {}; - expect(spec.buildRequests(fakeBidRequests, fakeBidderRequest)).to.be.an('array').that.is.empty; - }); - - it('should generate a POST bid request with method, url, and data fields', function() { - const bid = { - 'bidder': 'appier', - 'params': { - 'hzid': 'abcd' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - const fakeBidRequests = [bid]; - const fakeBidderRequest = { - refererInfo: { - legacy: { - 'referer': 'fakeReferer', - 'reachedTop': true, - 'numIframes': 1, - 'stack': [] - } - } - }; - - const builtRequests = spec.buildRequests(fakeBidRequests, fakeBidderRequest); - expect(builtRequests.length).to.equal(1); - expect(builtRequests[0].method).to.equal('POST'); - expect(builtRequests[0].url).match(/v1\/prebid\/bid/); - expect(builtRequests[0].data).deep.equal({ - 'bids': fakeBidRequests, - 'refererInfo': fakeBidderRequest.refererInfo.legacy, - 'version': ADAPTER_VERSION - }); - }); - }); - - describe('interpretResponse', function() { - const bid = { - 'bidder': 'appier', - 'params': { - 'hzid': 'abcd' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - const fakeBidRequests = [bid]; - - it('should return an empty aray to indicate no valid bids', function() { - const fakeServerResponse = {}; - - const bidResponses = spec.interpretResponse(fakeServerResponse, fakeBidRequests); - - expect(bidResponses).is.an('array').that.is.empty; - }); - - it('should generate correct response array for bidder', function() { - const fakeBidResult = { - 'requestId': '30b31c1838de1e', - 'cpm': 0.0029346001, - 'creativeId': 'Idl0P0d5S3Ca5kVWcia-wQ', - 'width': 300, - 'height': 250, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'ad': '
fake html
', - 'appierParams': { - 'hzid': 'test_hzid' - } - }; - const fakeServerResponse = { - headers: [], - body: [fakeBidResult] - }; - - const bidResponses = spec.interpretResponse(fakeServerResponse, fakeBidRequests); - expect(bidResponses).deep.equal([fakeBidResult]); - }); - }); - - describe('getApiServer', function() { - it('should use the server specified by setConfig(appier.server)', function() { - config.setConfig({ - 'appier': {'server': 'fake_server'} - }); - - const server = spec.getApiServer(); - - expect(server).equals('fake_server'); - }); - - it('should retrieve a farm specific hostname if server is not specpfied', function() { - config.setConfig({ - 'appier': {'farm': 'tw'} - }); - - const server = spec.getApiServer(); - - expect(server).equals(API_SERVERS_MAP['tw']); - }); - - it('if farm is not recognized, use the default farm', function() { - config.setConfig({ - 'appier': {'farm': 'no_this_farm'} - }); - - const server = spec.getApiServer(); - - expect(server).equals(API_SERVERS_MAP['default']); - }); - - it('if farm is not specified, use the default farm', function() { - config.setConfig({ - 'appier': {} - }); - - const server = spec.getApiServer(); - - expect(server).equals(API_SERVERS_MAP['default']); - }); - }); -}); diff --git a/test/spec/modules/appnexusBidAdapter_spec.js b/test/spec/modules/appnexusBidAdapter_spec.js deleted file mode 100644 index f4a00bfb2..000000000 --- a/test/spec/modules/appnexusBidAdapter_spec.js +++ /dev/null @@ -1,2522 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/appnexusBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { auctionManager } from 'src/auctionManager.js'; -import { deepClone } from 'src/utils.js'; -import * as utils from 'src/utils.js'; -import { config } from 'src/config.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -const ENDPOINT = 'https://ib.adnxs.com/ut/v3/prebid'; - -describe('AppNexusAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - function expectKeywords(actual, expected) { - expect(actual.length).to.equal(expected.length); - actual.forEach(el => { - const match = expected.find(ob => ob.key === el.key); - if (el.value) { - expect(el.value).to.have.members(match.value); - } else { - expect(match.value).to.not.exist; - } - }) - } - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'appnexus', - 'params': { - 'placementId': '10433394' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when required params found', function () { - const bid1 = deepClone(bid); - bid1.params = { - 'placement_id': 123423 - } - expect(spec.isBidRequestValid(bid1)).to.equal(true); - }); - - it('should return true when required params found', function () { - const bid1 = deepClone(bid); - bid1.params = { - 'member': '1234', - 'invCode': 'ABCD' - }; - - expect(spec.isBidRequestValid(bid1)).to.equal(true); - }); - - it('should return true when required params found', function () { - const bid1 = deepClone(bid); - bid1.params = { - 'member': '1234', - 'inv_code': 'ABCD' - }; - - expect(spec.isBidRequestValid(bid1)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'placementId': 0 - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'placement_id': 0 - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - let getAdUnitsStub; - const bidRequests = [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': '10433394' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'transactionId': '04f2659e-c005-4eb1-a57c-fa93145e3843' - } - ]; - - beforeEach(function () { - getAdUnitsStub = sinon.stub(auctionManager, 'getAdUnits').callsFake(function () { - return []; - }); - }); - - afterEach(function () { - getAdUnitsStub.restore(); - }); - - it('should parse out private sizes', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placementId: '10433394', - privateSizes: [300, 250] - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].private_sizes).to.exist; - expect(payload.tags[0].private_sizes).to.deep.equal([{ width: 300, height: 250 }]); - }); - - it('should parse out private sizes', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placementId: '10433394', - private_sizes: [300, 250] - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].private_sizes).to.exist; - expect(payload.tags[0].private_sizes).to.deep.equal([{ width: 300, height: 250 }]); - }); - - it('should add position in request', function () { - // set from bid.params - let bidRequest = deepClone(bidRequests[0]); - bidRequest.params.position = 'above'; - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].position).to.exist; - expect(payload.tags[0].position).to.deep.equal(1); - - // set from mediaTypes.banner.pos = 1 - bidRequest = deepClone(bidRequests[0]); - bidRequest.mediaTypes = { - banner: { pos: 1 } - }; - - const request2 = spec.buildRequests([bidRequest]); - const payload2 = JSON.parse(request2.data); - - expect(payload2.tags[0].position).to.exist; - expect(payload2.tags[0].position).to.deep.equal(1); - - // set from mediaTypes.video.pos = 3 - bidRequest = deepClone(bidRequests[0]); - bidRequest.mediaTypes = { - video: { pos: 3 } - }; - - const request3 = spec.buildRequests([bidRequest]); - const payload3 = JSON.parse(request3.data); - - expect(payload3.tags[0].position).to.exist; - expect(payload3.tags[0].position).to.deep.equal(2); - - // bid.params trumps mediatypes - bidRequest = deepClone(bidRequests[0]); - bidRequest.params.position = 'above'; - bidRequest.mediaTypes = { - banner: { pos: 3 } - }; - - const request4 = spec.buildRequests([bidRequest]); - const payload4 = JSON.parse(request4.data); - - expect(payload4.tags[0].position).to.exist; - expect(payload4.tags[0].position).to.deep.equal(1); - }); - - it('should add publisher_id in request', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placementId: '10433394', - publisherId: '1231234' - } - }); - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].publisher_id).to.exist; - expect(payload.tags[0].publisher_id).to.deep.equal(1231234); - expect(payload.publisher_id).to.exist; - expect(payload.publisher_id).to.deep.equal(1231234); - }); - - it('should add publisher_id in request', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placement_id: '10433394', - publisher_id: '1231234' - } - }); - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].publisher_id).to.exist; - expect(payload.tags[0].publisher_id).to.deep.equal(1231234); - expect(payload.publisher_id).to.exist; - expect(payload.publisher_id).to.deep.equal(1231234); - }); - - it('should add source and verison to the tag', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.sdk).to.exist; - expect(payload.sdk).to.deep.equal({ - source: 'pbjs', - version: '$prebid.version$' - }); - }); - - it('should populate the ad_types array on all requests', function () { - const adUnits = [{ - code: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bids: [{ - bidder: 'appnexus', - params: { - placement_id: '10433394' - } - }], - transactionId: '04f2659e-c005-4eb1-a57c-fa93145e3843' - }]; - - const types = ['banner']; - if (FEATURES.NATIVE) { - types.push('native'); - } - - if (FEATURES.VIDEO) { - types.push('video'); - } - - types.forEach(type => { - getAdUnitsStub.callsFake(function (...args) { - return adUnits; - }); - - const bidRequest = Object.assign({}, bidRequests[0]); - bidRequest.mediaTypes = {}; - bidRequest.mediaTypes[type] = {}; - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].ad_types).to.deep.equal([type]); - - if (type === 'banner') { - delete adUnits[0].mediaTypes; - } - }); - }); - - it('should not populate the ad_types array when adUnit.mediaTypes is undefined', function () { - const bidRequest = Object.assign({}, bidRequests[0]); - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].ad_types).to.not.exist; - }); - - if (FEATURES.VIDEO) { - it('should populate the ad_types array on outstream requests', function () { - const bidRequest = Object.assign({}, bidRequests[0]); - bidRequest.mediaTypes = {}; - bidRequest.mediaTypes.video = { context: 'outstream' }; - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].ad_types).to.deep.equal(['video']); - expect(payload.tags[0].hb_source).to.deep.equal(1); - }); - - it('should attach valid video params to the tag', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placementId: '10433394', - video: { - id: 123, - minduration: 100, - foobar: 'invalid' - } - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - expect(payload.tags[0].video).to.deep.equal({ - id: 123, - minduration: 100 - }); - expect(payload.tags[0].hb_source).to.deep.equal(1); - }); - - it('should include ORTB video values when matching video params were not all set', function () { - const bidRequest = deepClone(bidRequests[0]); - bidRequest.params = { - placementId: '1234235', - video: { - skippable: true, - playback_method: ['auto_play_sound_off', 'auto_play_sound_unknown'], - context: 'outstream' - } - }; - bidRequest.mediaTypes = { - video: { - playerSize: [640, 480], - context: 'outstream', - mimes: ['video/mp4'], - skip: 0, - minduration: 5, - api: [1, 5, 6], - playbackmethod: [2, 4] - } - }; - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].video).to.deep.equal({ - minduration: 5, - playback_method: 2, - skippable: true, - context: 4 - }); - expect(payload.tags[0].video_frameworks).to.deep.equal([1, 4]) - }); - - it('should include ORTB video values when video params is empty - case 1', function () { - const bidRequest = deepClone(bidRequests[0]); - bidRequest.mediaTypes = { - video: { - playerSize: [640, 480], - context: 'outstream', - placement: 3, - mimes: ['video/mp4'], - skip: 0, - minduration: 5, - api: [1, 5, 6], - playbackmethod: [2, 4] - } - }; - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].video).to.deep.equal({ - minduration: 5, - playback_method: 2, - skippable: false, - context: 4 - }); - expect(payload.tags[0].video_frameworks).to.deep.equal([1, 4]) - }); - - it('should include ORTB video values when video params is empty - case 2', function () { - const bidRequest = deepClone(bidRequests[0]); - bidRequest.mediaTypes = { - video: { - playerSize: [640, 480], - context: 'outstream', - plcmt: 2, - startdelay: 0, - mimes: ['video/mp4'], - skip: 1, - minduration: 5, - api: [1, 5, 6], - playbackmethod: [2, 4] - } - }; - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].video).to.deep.equal({ - minduration: 5, - playback_method: 2, - skippable: true, - context: 8 - }); - expect(payload.tags[0].video_frameworks).to.deep.equal([1, 4]) - }); - - it('should include ORTB video values when video params is empty - case 1', function () { - const bidRequest = deepClone(bidRequests[0]); - bidRequest.mediaTypes = { - video: { - playerSize: [640, 480], - context: 'outstream', - mimes: ['video/mp4'], - startdelay: 0, - skip: 0, - minduration: 5, - api: [1, 5, 6], - playbackmethod: [2, 4] - } - }; - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].video).to.deep.equal({ - minduration: 5, - playback_method: 2, - skippable: false, - context: 1 - }); - expect(payload.tags[0].video_frameworks).to.deep.equal([1, 4]) - }); - - it('should convert and include ORTB2 device data when available', function () { - const bidRequest = deepClone(bidRequests[0]); - const bidderRequest = { - ortb2: { - device: { - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - }, - }, - }; - - const expectedDeviceResult = { - useragent: bidderRequest.ortb2.device.ua, - devicetype: 'Mobile/Tablet - General', - make: bidderRequest.ortb2.device.make, - model: bidderRequest.ortb2.device.model, - os: bidderRequest.ortb2.device.os, - os_version: bidderRequest.ortb2.device.osv, - w: bidderRequest.ortb2.device.w, - h: bidderRequest.ortb2.device.h, - }; - - const request = spec.buildRequests([bidRequest], bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.device).to.deep.equal(expectedDeviceResult); - }); - - it('should add video property when adUnit includes a renderer', function () { - const videoData = { - mediaTypes: { - video: { - context: 'outstream', - mimes: ['video/mp4'] - } - }, - params: { - placementId: '10433394', - video: { - skippable: true, - playback_method: ['auto_play_sound_off'] - } - } - }; - - let bidRequest1 = deepClone(bidRequests[0]); - bidRequest1 = Object.assign({}, bidRequest1, videoData, { - renderer: { - url: 'https://test.renderer.url', - render: function () { } - } - }); - - let bidRequest2 = deepClone(bidRequests[0]); - bidRequest2.adUnitCode = 'adUnit_code_2'; - bidRequest2 = Object.assign({}, bidRequest2, videoData); - - const request = spec.buildRequests([bidRequest1, bidRequest2]); - const payload = JSON.parse(request.data); - expect(payload.tags[0].video).to.deep.equal({ - skippable: true, - playback_method: 2, - custom_renderer_present: true - }); - expect(payload.tags[1].video).to.deep.equal({ - skippable: true, - playback_method: 2 - }); - }); - - it('should duplicate adpod placements into batches and set correct maxduration', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { placementId: '14542875' } - }, - { - mediaTypes: { - video: { - context: 'adpod', - playerSize: [640, 480], - adPodDurationSec: 300, - durationRangeSec: [15, 30], - } - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload1 = JSON.parse(request[0].data); - const payload2 = JSON.parse(request[1].data); - - // 300 / 15 = 20 total - expect(payload1.tags.length).to.equal(15); - expect(payload2.tags.length).to.equal(5); - - expect(payload1.tags[0]).to.deep.equal(payload1.tags[1]); - expect(payload1.tags[0].video.maxduration).to.equal(30); - - expect(payload2.tags[0]).to.deep.equal(payload1.tags[1]); - expect(payload2.tags[0].video.maxduration).to.equal(30); - }); - - it('should round down adpod placements when numbers are uneven', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { placementId: '14542875' } - }, - { - mediaTypes: { - video: { - context: 'adpod', - playerSize: [640, 480], - adPodDurationSec: 123, - durationRangeSec: [45], - } - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - expect(payload.tags.length).to.equal(2); - }); - - it('should duplicate adpod placements when requireExactDuration is set', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { placementId: '14542875' } - }, - { - mediaTypes: { - video: { - context: 'adpod', - playerSize: [640, 480], - adPodDurationSec: 300, - durationRangeSec: [15, 30], - requireExactDuration: true, - } - } - } - ); - - // 20 total placements with 15 max impressions = 2 requests - const request = spec.buildRequests([bidRequest]); - expect(request.length).to.equal(2); - - // 20 spread over 2 requests = 15 in first request, 5 in second - const payload1 = JSON.parse(request[0].data); - const payload2 = JSON.parse(request[1].data); - expect(payload1.tags.length).to.equal(15); - expect(payload2.tags.length).to.equal(5); - - // 10 placements should have max/min at 15 - // 10 placemenst should have max/min at 30 - const payload1tagsWith15 = payload1.tags.filter(tag => tag.video.maxduration === 15); - const payload1tagsWith30 = payload1.tags.filter(tag => tag.video.maxduration === 30); - expect(payload1tagsWith15.length).to.equal(10); - expect(payload1tagsWith30.length).to.equal(5); - - // 5 placemenst with min/max at 30 were in the first request - // so 5 remaining should be in the second - const payload2tagsWith30 = payload2.tags.filter(tag => tag.video.maxduration === 30); - expect(payload2tagsWith30.length).to.equal(5); - }); - - it('should set durations for placements when requireExactDuration is set and numbers are uneven', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { placementId: '14542875' } - }, - { - mediaTypes: { - video: { - context: 'adpod', - playerSize: [640, 480], - adPodDurationSec: 105, - durationRangeSec: [15, 30, 60], - requireExactDuration: true, - } - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - expect(payload.tags.length).to.equal(7); - - const tagsWith15 = payload.tags.filter(tag => tag.video.maxduration === 15); - const tagsWith30 = payload.tags.filter(tag => tag.video.maxduration === 30); - const tagsWith60 = payload.tags.filter(tag => tag.video.maxduration === 60); - expect(tagsWith15.length).to.equal(3); - expect(tagsWith30.length).to.equal(3); - expect(tagsWith60.length).to.equal(1); - }); - - it('should break adpod request into batches', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { placementId: '14542875' } - }, - { - mediaTypes: { - video: { - context: 'adpod', - playerSize: [640, 480], - adPodDurationSec: 225, - durationRangeSec: [5], - } - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload1 = JSON.parse(request[0].data); - const payload2 = JSON.parse(request[1].data); - const payload3 = JSON.parse(request[2].data); - - expect(payload1.tags.length).to.equal(15); - expect(payload2.tags.length).to.equal(15); - expect(payload3.tags.length).to.equal(15); - }); - - it('should contain hb_source value for adpod', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { placementId: '14542875' } - }, - { - mediaTypes: { - video: { - context: 'adpod', - playerSize: [640, 480], - adPodDurationSec: 300, - durationRangeSec: [15, 30], - } - } - } - ); - const request = spec.buildRequests([bidRequest])[0]; - const payload = JSON.parse(request.data); - expect(payload.tags[0].hb_source).to.deep.equal(7); - }); - } // VIDEO - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('should attach valid user params to the tag', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placement_id: '10433394', - user: { - externalUid: '123', - segments: [123, { id: 987, value: 876 }], - foobar: 'invalid' - } - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.user).to.exist; - expect(payload.user).to.deep.equal({ - external_uid: '123', - segments: [{ id: 123 }, { id: 987, value: 876 }] - }); - }); - - it('should add debug params from query', function () { - const getParamStub = sinon.stub(utils, 'getParameterByName').callsFake(function(par) { - if (par === 'apn_debug_dongle') return 'abcdef'; - if (par === 'apn_debug_member_id') return '1234'; - if (par === 'apn_debug_timeout') return '1000'; - - return ''; - }); - - const bidRequest = deepClone(bidRequests[0]); - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.debug).to.exist.and.to.deep.equal({ - 'dongle': 'abcdef', - 'enabled': true, - 'member_id': 1234, - 'debug_timeout': 1000 - }); - - getParamStub.restore(); - }); - - it('should attach reserve param when either bid param or getFloor function exists', function () { - const getFloorResponse = { currency: 'USD', floor: 3 }; - let request; let payload = null; - const bidRequest = deepClone(bidRequests[0]); - - // 1 -> reserve not defined, getFloor not defined > empty - request = spec.buildRequests([bidRequest]); - payload = JSON.parse(request.data); - - expect(payload.tags[0].reserve).to.not.exist; - - // 2 -> reserve is defined, getFloor not defined > reserve is used - bidRequest.params = { - 'placement_id': '10433394', - 'reserve': 0.5 - }; - request = spec.buildRequests([bidRequest]); - payload = JSON.parse(request.data); - - expect(payload.tags[0].reserve).to.exist.and.to.equal(0.5); - - // 3 -> reserve is defined, getFloor is defined > getFloor is used - bidRequest.getFloor = () => getFloorResponse; - - request = spec.buildRequests([bidRequest]); - payload = JSON.parse(request.data); - - expect(payload.tags[0].reserve).to.exist.and.to.equal(3); - }); - - it('should contain hb_source value for other media', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - mediaType: 'banner', - params: { - sizes: [[300, 250], [300, 600]], - placement_id: 13144370 - } - } - ); - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - expect(payload.tags[0].hb_source).to.deep.equal(1); - }); - - it('adds brand_category_exclusion to request when set', function () { - const bidRequest = Object.assign({}, bidRequests[0]); - sinon - .stub(config, 'getConfig') - .withArgs('adpod.brandCategoryExclusion') - .returns(true); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.brand_category_uniqueness).to.equal(true); - - config.getConfig.restore(); - }); - - it('adds auction level keywords and ortb2 keywords to request when set', function () { - const bidRequest = Object.assign({}, bidRequests[0]); - sinon - .stub(config, 'getConfig') - .withArgs('appnexusAuctionKeywords') - .returns({ - gender: 'm', - music: ['rock', 'pop'], - test: '', - tools: 'power' - }); - - const bidderRequest = { - ortb2: { - site: { - keywords: 'power tools, drills, tools=industrial', - content: { - keywords: 'video, source=streaming' - } - }, - user: { - keywords: 'tools=home,renting' - }, - app: { - keywords: 'app=iphone 11', - content: { - keywords: 'appcontent=home repair, dyi' - } - } - } - }; - - const request = spec.buildRequests([bidRequest], bidderRequest); - const payload = JSON.parse(request.data); - - expectKeywords(payload.keywords, [{ - 'key': 'gender', - 'value': ['m'] - }, { - 'key': 'music', - 'value': ['rock', 'pop'] - }, { - 'key': 'test' - }, { - 'key': 'tools', - 'value': ['power', 'industrial', 'home'] - }, { - 'key': 'power tools' - }, { - 'key': 'drills' - }, { - 'key': 'video' - }, { - 'key': 'source', - 'value': ['streaming'] - }, { - 'key': 'renting' - }, { - 'key': 'app', - 'value': ['iphone 11'] - }, { - 'key': 'appcontent', - 'value': ['home repair'] - }, { - 'key': 'dyi' - }]); - - config.getConfig.restore(); - }); - - it('adds ortb2 segments to auction request as keywords', function() { - const bidRequest = Object.assign({}, bidRequests[0]); - const bidderRequest = { - ortb2: { - site: { - keywords: 'drill', - content: { - data: [{ - name: 'siteseg1', - ext: { - segtax: 540 - }, - segment: [{ - id: 's123', - }, { - id: 's234' - }] - }, { - name: 'sitseg2', - ext: { - segtax: 1 - }, - segment: [{ - id: 'unknown' - }] - }, { - name: 'siteseg3', - ext: { - segtax: 526 - }, - segment: [{ - id: 'dog' - }] - }] - } - }, - user: { - data: [{ - name: 'userseg1', - ext: { - segtax: 526 - }, - segment: [{ - id: 'cat' - }] - }] - } - } - }; - const request = spec.buildRequests([bidRequest], bidderRequest); - const payload = JSON.parse(request.data); - - expectKeywords(payload.keywords, [{ - 'key': 'drill' - }, { - 'key': '1plusX', - 'value': ['cat', 'dog'] - }, { - 'key': 'perid', - 'value': ['s123', 's234'] - }]); - }); - - if (FEATURES.NATIVE) { - it('should attach native params to the request', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - mediaType: 'native', - nativeParams: { - title: { required: true }, - body: { required: true }, - body2: { required: true }, - image: { required: true, sizes: [100, 100] }, - icon: { required: true }, - cta: { required: false }, - rating: { required: true }, - sponsoredBy: { required: true }, - privacyLink: { required: true }, - displayUrl: { required: true }, - address: { required: true }, - downloads: { required: true }, - likes: { required: true }, - phone: { required: true }, - price: { required: true }, - salePrice: { required: true } - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].native.layouts[0]).to.deep.equal({ - title: { required: true }, - description: { required: true }, - desc2: { required: true }, - main_image: { required: true, sizes: [{ width: 100, height: 100 }] }, - icon: { required: true }, - ctatext: { required: false }, - rating: { required: true }, - sponsored_by: { required: true }, - privacy_link: { required: true }, - displayurl: { required: true }, - address: { required: true }, - downloads: { required: true }, - likes: { required: true }, - phone: { required: true }, - price: { required: true }, - saleprice: { required: true }, - privacy_supported: true - }); - expect(payload.tags[0].hb_source).to.equal(1); - }); - - it('should always populated tags[].sizes with 1,1 for native if otherwise not defined', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - mediaType: 'native', - nativeParams: { - image: { required: true } - } - } - ); - bidRequest.sizes = [[150, 100], [300, 250]]; - - let request = spec.buildRequests([bidRequest]); - let payload = JSON.parse(request.data); - expect(payload.tags[0].sizes).to.deep.equal([{ width: 150, height: 100 }, { width: 300, height: 250 }]); - - delete bidRequest.sizes; - - request = spec.buildRequests([bidRequest]); - payload = JSON.parse(request.data); - - expect(payload.tags[0].sizes).to.deep.equal([{ width: 1, height: 1 }]); - }); - } - - it('should convert keyword params (when there are no ortb keywords) to proper form and attaches to request', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placement_id: '10433394', - keywords: { - single: 'val', - singleArr: ['val'], - singleArrNum: [5], - multiValMixed: ['value1', 2, 'value3'], - singleValNum: 123, - emptyStr: '', - emptyArr: [''], - badValue: { 'foo': 'bar' } // should be dropped - } - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expectKeywords(payload.tags[0].keywords, [ - { - 'key': 'single', - 'value': ['val'] - }, { - 'key': 'singleArr', - 'value': ['val'] - }, { - 'key': 'singleArrNum', - 'value': ['5'] - }, { - 'key': 'multiValMixed', - 'value': ['value1', '2', 'value3'] - }, { - 'key': 'singleValNum', - 'value': ['123'] - }, { - 'key': 'emptyStr' - }, { - 'key': 'emptyArr' - } - ]) - }); - - it('should convert adUnit ortb2 keywords (when there are no bid param keywords) to proper form and attaches to request', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - ortb2Imp: { - ext: { - data: { - keywords: 'ortb2=yes,ortb2test, multiValMixed=4, singleValNum=456' - } - } - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expectKeywords(payload.tags[0].keywords, [{ - 'key': 'ortb2', - 'value': ['yes'] - }, { - 'key': 'ortb2test' - }, { - 'key': 'multiValMixed', - 'value': ['4'] - }, { - 'key': 'singleValNum', - 'value': ['456'] - }]); - }); - - it('should convert keyword params and adUnit ortb2 keywords to proper form and attaches to request', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placementId: '10433394', - keywords: { - single: 'val', - singleArr: ['val'], - singleArrNum: [5], - multiValMixed: ['value1', 2, 'value3'], - singleValNum: 123, - emptyStr: '', - emptyArr: [''], - badValue: { 'foo': 'bar' } // should be dropped - } - }, - ortb2Imp: { - ext: { - data: { - keywords: 'ortb2=yes,ortb2test, multiValMixed=4, singleValNum=456' - } - } - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expectKeywords(payload.tags[0].keywords, [{ - 'key': 'single', - 'value': ['val'] - }, { - 'key': 'singleArr', - 'value': ['val'] - }, { - 'key': 'singleArrNum', - 'value': ['5'] - }, { - 'key': 'multiValMixed', - 'value': ['value1', '2', 'value3', '4'] - }, { - 'key': 'singleValNum', - 'value': ['123', '456'] - }, { - 'key': 'emptyStr' - }, { - 'key': 'emptyArr' - }, { - 'key': 'ortb2', - 'value': ['yes'] - }, { - 'key': 'ortb2test' - }]); - }); - - it('should add payment rules to the request', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placementId: '10433394', - usePaymentRule: true - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].use_pmt_rule).to.equal(true); - }); - - it('should add payment rules to the request', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placement_id: '10433394', - use_payment_rule: true - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].use_pmt_rule).to.equal(true); - }); - - it('should add preferred gpid to the request', function () { - const testGpid = '/12345/my-gpt-tag-0'; - const bidRequest = deepClone(bidRequests[0]); - bidRequest.ortb2Imp = { ext: { gpid: testGpid } }; - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].gpid).to.exist.and.equal(testGpid); - }); - - it('should add backup gpid to the request', function () { - const testGpid = '/12345/my-gpt-tag-0'; - const bidRequest = deepClone(bidRequests[0]); - bidRequest.ortb2Imp = { ext: { data: {}, gpid: testGpid } }; - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].gpid).to.exist.and.equal(testGpid); - }); - - it('should add tid to the request', function () { - const testTid = '1234test'; - const bidRequest = deepClone(bidRequests[0]); - bidRequest.ortb2Imp = { ext: { tid: testTid } }; - // bidRequest.ortb2 = { source: { tid: testTid } }; - - const bidderRequest = { - 'bidderCode': 'appnexus', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - ortb2: { - source: { - tid: testTid - } - } - }; - bidderRequest.bids = [bidRequest]; - - const request = spec.buildRequests([bidRequest], bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].tid).to.exist.and.equal(testTid); - expect(payload.source.tid).to.exist.and.equal(testTid); - }); - - it('should add gdpr consent information to the request', function () { - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const bidderRequest = { - 'bidderCode': 'appnexus', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - consentString: consentString, - gdprApplies: true, - addtlConsent: '1~7.12.35.62.66.70.89.93.108' - } - }; - bidderRequest.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.options).to.deep.equal({ withCredentials: true }); - const payload = JSON.parse(request.data); - - expect(payload.gdpr_consent).to.exist; - expect(payload.gdpr_consent.consent_string).to.exist.and.to.equal(consentString); - expect(payload.gdpr_consent.consent_required).to.exist.and.to.be.true; - expect(payload.gdpr_consent.addtl_consent).to.exist.and.to.deep.equal([7, 12, 35, 62, 66, 70, 89, 93, 108]); - }); - - it('should add us privacy string to payload', function () { - const consentString = '1YA-'; - const bidderRequest = { - 'bidderCode': 'appnexus', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'uspConsent': consentString - }; - bidderRequest.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.us_privacy).to.exist; - expect(payload.us_privacy).to.exist.and.to.equal(consentString); - }); - - it('should add gpp information to the request via bidderRequest.gppConsent', function () { - const consentString = 'abc1234'; - const bidderRequest = { - 'bidderCode': 'appnexus', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gppConsent': { - 'gppString': consentString, - 'applicableSections': [8] - } - }; - bidderRequest.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.privacy).to.exist; - expect(payload.privacy.gpp).to.equal(consentString); - expect(payload.privacy.gpp_sid).to.deep.equal([8]); - }); - - it('should add gpp information to the request via bidderRequest.ortb2.regs', function () { - const consentString = 'abc1234'; - const bidderRequest = { - 'bidderCode': 'appnexus', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'ortb2': { - 'regs': { - 'gpp': consentString, - 'gpp_sid': [7] - } - } - }; - bidderRequest.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.privacy).to.exist; - expect(payload.privacy.gpp).to.equal(consentString); - expect(payload.privacy.gpp_sid).to.deep.equal([7]); - }); - - it('should add dsa information to the request via bidderRequest.ortb2.regs.ext.dsa', function () { - const bidderRequest = { - 'bidderCode': 'appnexus', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'ortb2': { - 'regs': { - 'ext': { - 'dsa': { - 'dsarequired': 1, - 'pubrender': 0, - 'datatopub': 1, - 'transparency': [{ - 'domain': 'good-domain', - 'dsaparams': [1, 2] - }, { - 'domain': 'bad-setup', - 'dsaparams': ['1', 3] - }] - } - } - } - } - }; - bidderRequest.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.dsa).to.exist; - expect(payload.dsa.dsarequired).to.equal(1); - expect(payload.dsa.pubrender).to.equal(0); - expect(payload.dsa.datatopub).to.equal(1); - expect(payload.dsa.transparency).to.deep.equal([{ - 'domain': 'good-domain', - 'dsaparams': [1, 2] - }]); - }); - - it('supports sending hybrid mobile app parameters', function () { - const appRequest = Object.assign({}, - bidRequests[0], - { - params: { - placementId: '10433394', - app: { - id: 'B1O2W3M4AN.com.prebid.webview', - geo: { - lat: 40.0964439, - lng: -75.3009142 - }, - device_id: { - idfa: '4D12078D-3246-4DA4-AD5E-7610481E7AE', // Apple advertising identifier - aaid: '38400000-8cf0-11bd-b23e-10b96e40000d', // Android advertising identifier - md5udid: '5756ae9022b2ea1e47d84fead75220c8', // MD5 hash of the ANDROID_ID - sha1udid: '4DFAA92388699AC6539885AEF1719293879985BF', // SHA1 hash of the ANDROID_ID - windowsadid: '750c6be243f1c4b5c9912b95a5742fc5' // Windows advertising identifier - } - } - } - } - ); - const request = spec.buildRequests([appRequest]); - const payload = JSON.parse(request.data); - expect(payload.app).to.exist; - expect(payload.app).to.deep.equal({ - appid: 'B1O2W3M4AN.com.prebid.webview' - }); - expect(payload.device.device_id).to.exist; - expect(payload.device.device_id).to.deep.equal({ - aaid: '38400000-8cf0-11bd-b23e-10b96e40000d', - idfa: '4D12078D-3246-4DA4-AD5E-7610481E7AE', - md5udid: '5756ae9022b2ea1e47d84fead75220c8', - sha1udid: '4DFAA92388699AC6539885AEF1719293879985BF', - windowsadid: '750c6be243f1c4b5c9912b95a5742fc5' - }); - expect(payload.device.geo).to.exist; - expect(payload.device.geo).to.deep.equal({ - lat: 40.0964439, - lng: -75.3009142 - }); - }); - - it('should add referer info to payload', function () { - const bidRequest = Object.assign({}, bidRequests[0]); - const bidderRequest = { - refererInfo: { - topmostLocation: 'https://example.com/page.html', - reachedTop: true, - numIframes: 2, - stack: [ - 'https://example.com/page.html', - 'https://example.com/iframe1.html', - 'https://example.com/iframe2.html' - ] - } - } - const request = spec.buildRequests([bidRequest], bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.referrer_detection).to.exist; - expect(payload.referrer_detection).to.deep.equal({ - rd_ref: 'https%3A%2F%2Fexample.com%2Fpage.html', - rd_top: true, - rd_ifs: 2, - rd_stk: bidderRequest.refererInfo.stack.map((url) => encodeURIComponent(url)).join(',') - }); - }); - - it('if defined, should include publisher pageUrl to normal referer info in payload', function () { - const bidRequest = Object.assign({}, bidRequests[0]); - - const bidderRequest = { - refererInfo: { - canonicalUrl: 'https://mypub.override.com/test/page.html', - topmostLocation: 'https://example.com/page.html', - reachedTop: true, - numIframes: 2, - stack: [ - 'https://example.com/page.html', - 'https://example.com/iframe1.html', - 'https://example.com/iframe2.html' - ] - } - } - const request = spec.buildRequests([bidRequest], bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.referrer_detection).to.exist; - expect(payload.referrer_detection).to.deep.equal({ - rd_ref: 'https%3A%2F%2Fexample.com%2Fpage.html', - rd_top: true, - rd_ifs: 2, - rd_stk: bidderRequest.refererInfo.stack.map((url) => encodeURIComponent(url)).join(','), - rd_can: 'https://mypub.override.com/test/page.html' - }); - }); - - it('should populate schain if available', function () { - const bidRequest = Object.assign({}, bidRequests[0], { - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - 'asi': 'blob.com', - 'sid': '001', - 'hp': 1 - } - ] - } - } - } - } - }); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - expect(payload.schain).to.deep.equal({ - ver: '1.0', - complete: 1, - nodes: [ - { - 'asi': 'blob.com', - 'sid': '001', - 'hp': 1 - } - ] - }); - }); - - it('should populate coppa if set in config', function () { - const bidRequest = Object.assign({}, bidRequests[0]); - sinon.stub(config, 'getConfig') - .withArgs('coppa') - .returns(true); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.user.coppa).to.equal(true); - - config.getConfig.restore(); - }); - - describe('ast_override_div', function () { - let getParamStub; - const bidRequest = Object.assign({}, bidRequests[0]); - const bidRequest2 = deepClone(bidRequests[0]); - bidRequest2.adUnitCode = 'adUnit_code_2'; - const bidRequest3 = deepClone(bidRequests[0]); - bidRequest3.adUnitCode = 'adUnit_code_3'; - - before(function () { - getParamStub = sinon.stub(utils, 'getParameterByName'); - }); - - it('should set forced creative id if one adUnitCode passed', function () { - getParamStub.callsFake(function(par) { - if (par === 'ast_override_div') return 'adunit-code:1234'; - return ''; - }); - - const request = spec.buildRequests([bidRequest, bidRequest2]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].force_creative_id).to.deep.equal(1234); - expect(payload.tags[1].force_creative_id).to.not.exist; - }); - - it('should set forced creative id if `ast_override_div` is set to override multiple adUnitCode', function () { - getParamStub.callsFake(function(par) { - if (par === 'ast_override_div') return 'adunit-code:1234,adUnit_code_2:5678'; - return ''; - }); - - const request = spec.buildRequests([bidRequest, bidRequest2, bidRequest3]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].force_creative_id).to.deep.equal(1234); - expect(payload.tags[1].force_creative_id).to.deep.equal(5678); - expect(payload.tags[2].force_creative_id).to.not.exist; - }); - - it('should not set forced creative id if `ast_override_div` is missing creativeId', function () { - getParamStub.callsFake(function(par) { - if (par === 'ast_override_div') return 'adunit-code'; - return ''; - }); - - const request = spec.buildRequests([bidRequest, bidRequest2]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].force_creative_id).to.not.exist; - expect(payload.tags[1].force_creative_id).to.not.exist; - }); - - it('should not set forced creative id if `ast_override_div` is in the wrong format', function () { - getParamStub.callsFake(function(par) { - if (par === 'ast_override_div') return 'adunit-code;adUnit_code_2:5678'; - return ''; - }); ; - - const request = spec.buildRequests([bidRequest, bidRequest2]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].force_creative_id).to.not.exist; - expect(payload.tags[1].force_creative_id).to.not.exist; - }); - - it('should not set forced creative id if `ast_override_div` is missing', function () { - getParamStub.callsFake(function(par) { - return ''; - }); ; - - const request = spec.buildRequests([bidRequest, bidRequest2]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].force_creative_id).to.not.exist; - expect(payload.tags[1].force_creative_id).to.not.exist; - }); - - after(function () { - getParamStub.restore(); - }); - }); - - it('should set the X-Is-Test customHeader if test flag is enabled', function () { - const bidRequest = Object.assign({}, bidRequests[0]); - sinon.stub(config, 'getConfig') - .withArgs('apn_test') - .returns(true); - - const request = spec.buildRequests([bidRequest]); - expect(request.options.customHeaders).to.deep.equal({ 'X-Is-Test': 1 }); - - config.getConfig.restore(); - }); - - it('should always set withCredentials: true on the request.options', function () { - const bidRequest = Object.assign({}, bidRequests[0]); - const request = spec.buildRequests([bidRequest]); - expect(request.options.withCredentials).to.equal(true); - }); - - it('should set simple domain variant if purpose 1 consent is not given', function () { - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const bidderRequest = { - 'bidderCode': 'appnexus', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - consentString: consentString, - gdprApplies: true, - apiVersion: 2, - vendorData: { - purpose: { - consents: { - 1: false - } - } - } - } - }; - bidderRequest.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).to.equal('https://ib.adnxs-simple.com/ut/v3/prebid'); - }); - - it('should populate eids when supported userIds are available', function () { - const bidRequest = Object.assign({}, bidRequests[0], { - userIdAsEids: [{ - source: 'adserver.org', - uids: [{ id: 'sample-userid' }] - }, { - source: 'criteo.com', - uids: [{ id: 'sample-criteo-userid' }] - }, { - source: 'netid.de', - uids: [{ id: 'sample-netId-userid' }] - }, { - source: 'liveramp.com', - uids: [{ id: 'sample-idl-userid' }] - }, { - source: 'uidapi.com', - uids: [{ id: 'sample-uid2-value' }] - }, { - source: 'puburl.com', - uids: [{ id: 'pubid1' }] - }, { - source: 'puburl2.com', - uids: [{ id: 'pubid2' }, { id: 'pubid2-123' }] - }] - }); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - expect(payload.eids).to.deep.include({ - source: 'adserver.org', - id: 'sample-userid', - rti_partner: 'TDID' - }); - - expect(payload.eids).to.deep.include({ - source: 'criteo.com', - id: 'sample-criteo-userid', - }); - - expect(payload.eids).to.deep.include({ - source: 'netid.de', - id: 'sample-netId-userid', - }); - - expect(payload.eids).to.deep.include({ - source: 'liveramp.com', - id: 'sample-idl-userid' - }); - - expect(payload.eids).to.deep.include({ - source: 'uidapi.com', - id: 'sample-uid2-value', - rti_partner: 'UID2' - }); - - expect(payload.eids).to.deep.include({ - source: 'puburl.com', - id: 'pubid1' - }); - - expect(payload.eids).to.deep.include({ - source: 'puburl2.com', - id: 'pubid2' - }); - expect(payload.eids).to.deep.include({ - source: 'puburl2.com', - id: 'pubid2-123' - }); - }); - - it('should populate iab_support object at the root level if omid support is detected', function () { - let request, payload; - - if (FEATURES.VIDEO) { - // with bid.params.frameworks - const bidRequest_A = Object.assign({}, bidRequests[0], { - params: { - frameworks: [1, 2, 5, 6], - video: { - frameworks: [1, 2, 5, 6] - } - } - }); - request = spec.buildRequests([bidRequest_A]); - payload = JSON.parse(request.data); - expect(payload.iab_support).to.be.an('object'); - expect(payload.iab_support).to.deep.equal({ - omidpn: 'Appnexus', - omidpv: '$prebid.version$' - }); - expect(payload.tags[0].banner_frameworks).to.be.an('array'); - expect(payload.tags[0].banner_frameworks).to.deep.equal([1, 2, 5, 6]); - expect(payload.tags[0].video_frameworks).to.be.an('array'); - expect(payload.tags[0].video_frameworks).to.deep.equal([1, 2, 5, 6]); - expect(payload.tags[0].video.frameworks).to.not.exist; - } - - // without bid.params.frameworks - const bidRequest_B = Object.assign({}, bidRequests[0]); - request = spec.buildRequests([bidRequest_B]); - payload = JSON.parse(request.data); - expect(payload.iab_support).to.not.exist; - expect(payload.tags[0].banner_frameworks).to.not.exist; - expect(payload.tags[0].video_frameworks).to.not.exist; - - if (FEATURES.VIDEO) { - // with video.frameworks but it is not an array - const bidRequest_C = Object.assign({}, bidRequests[0], { - params: { - video: { - frameworks: "'1', '2', '3', '6'" - } - } - }); - request = spec.buildRequests([bidRequest_C]); - payload = JSON.parse(request.data); - expect(payload.iab_support).to.not.exist; - expect(payload.tags[0].banner_frameworks).to.not.exist; - expect(payload.tags[0].video_frameworks).to.not.exist; - } - }); - }) - - describe('interpretResponse', function () { - let bidderSettingsStorage; - - before(function () { - bidderSettingsStorage = getGlobal().bidderSettings; - }); - - after(function () { - getGlobal().bidderSettings = bidderSettingsStorage; - }); - - const response = { - 'version': '3.0.0', - 'tags': [ - { - 'uuid': '3db3773286ee59', - 'tag_id': 10433394, - 'auction_id': '4534722592064951574', - 'nobid': false, - 'no_ad_url': 'https://lax1-ib.adnxs.com/no-ad', - 'timeout_ms': 10000, - 'ad_profile_id': 27079, - 'ads': [ - { - 'content_source': 'rtb', - 'ad_type': 'banner', - 'buyer_member_id': 958, - 'creative_id': 29681110, - 'media_type_id': 1, - 'media_subtype_id': 1, - 'cpm': 0.5, - 'cpm_publisher_currency': 0.5, - 'publisher_currency_code': '$', - 'client_initiated_ad_counting': true, - 'viewability': { - 'config': '' - }, - 'dsa': { - 'behalf': 'test-behalf', - 'paid': 'test-paid', - 'transparency': [{ - 'domain': 'good-domain', - 'params': [1, 2, 3] - }], - 'adrender': 1 - }, - 'rtb': { - 'banner': { - 'content': '', - 'width': 300, - 'height': 250 - }, - 'trackers': [ - { - 'impression_urls': [ - 'https://lax1-ib.adnxs.com/impression', - 'https://www.test.com/tracker' - ], - 'video_events': {} - } - ] - } - } - ] - } - ] - }; - - it('should get correct bid response', function () { - const expectedResponse = [ - { - 'adId': '3a1f23123e', - 'requestId': '3db3773286ee59', - 'cpm': 0.5, - 'creativeId': 29681110, - 'dealId': undefined, - 'width': 300, - 'height': 250, - 'ad': '', - 'mediaType': 'banner', - 'currency': 'USD', - 'ttl': 300, - 'netRevenue': true, - 'adUnitCode': 'code', - 'appnexus': { - 'buyerMemberId': 958 - }, - 'meta': { - 'dchain': { - 'ver': '1.0', - 'complete': 0, - 'nodes': [{ - 'bsid': '958' - }] - }, - 'dsa': { - 'behalf': 'test-behalf', - 'paid': 'test-paid', - 'transparency': [{ - 'domain': 'good-domain', - 'params': [1, 2, 3] - }], - 'adrender': 1 - } - } - } - ]; - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - }; - const result = spec.interpretResponse({ body: response }, { bidderRequest }); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - - it('should reject 0 cpm bids', function () { - const zeroCpmResponse = deepClone(response); - zeroCpmResponse.tags[0].ads[0].cpm = 0; - - const bidderRequest = { - bidderCode: 'appnexus' - }; - - const result = spec.interpretResponse({ body: zeroCpmResponse }, { bidderRequest }); - expect(result.length).to.equal(0); - }); - - it('should allow 0 cpm bids if allowZeroCpmBids setConfig is true', function () { - getGlobal().bidderSettings = { - appnexus: { - allowZeroCpmBids: true - } - }; - - const zeroCpmResponse = deepClone(response); - zeroCpmResponse.tags[0].ads[0].cpm = 0; - - const bidderRequest = { - bidderCode: 'appnexus', - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - }; - - const result = spec.interpretResponse({ body: zeroCpmResponse }, { bidderRequest }); - expect(result.length).to.equal(1); - expect(result[0].cpm).to.equal(0); - }); - - it('handles nobid responses', function () { - const response = { - 'version': '0.0.1', - 'tags': [{ - 'uuid': '84ab500420319d', - 'tag_id': 5976557, - 'auction_id': '297492697822162468', - 'nobid': true - }] - }; - let bidderRequest; - - const result = spec.interpretResponse({ body: response }, { bidderRequest }); - expect(result.length).to.equal(0); - }); - - if (FEATURES.VIDEO) { - it('handles outstream video responses', function () { - const response = { - 'tags': [{ - 'uuid': '84ab500420319d', - 'ads': [{ - 'ad_type': 'video', - 'cpm': 0.500000, - 'notify_url': 'imptracker.com', - 'rtb': { - 'video': { - 'content': '' - } - }, - 'javascriptTrackers': '' - }] - }] - }; - const bidderRequest = { - bids: [{ - bidId: '84ab500420319d', - adUnitCode: 'code', - mediaTypes: { - video: { - context: 'outstream' - } - } - }] - } - - const result = spec.interpretResponse({ body: response }, { bidderRequest }); - expect(result[0]).to.have.property('vastXml'); - expect(result[0]).to.have.property('vastImpUrl'); - expect(result[0]).to.have.property('mediaType', 'video'); - }); - - it('handles instream video responses', function () { - const response = { - 'tags': [{ - 'uuid': '84ab500420319d', - 'ads': [{ - 'ad_type': 'video', - 'cpm': 0.500000, - 'notify_url': 'imptracker.com', - 'rtb': { - 'video': { - 'asset_url': 'https://sample.vastURL.com/here/vid' - } - }, - 'javascriptTrackers': '' - }] - }] - }; - const bidderRequest = { - bids: [{ - bidId: '84ab500420319d', - adUnitCode: 'code', - mediaTypes: { - video: { - context: 'instream' - } - } - }] - } - - const result = spec.interpretResponse({ body: response }, { bidderRequest }); - expect(result[0]).to.have.property('vastUrl'); - expect(result[0]).to.have.property('vastImpUrl'); - expect(result[0]).to.have.property('mediaType', 'video'); - }); - - it('handles adpod responses', function () { - const response = { - 'tags': [{ - 'uuid': '84ab500420319d', - 'ads': [{ - 'ad_type': 'video', - 'brand_category_id': 10, - 'cpm': 0.500000, - 'notify_url': 'imptracker.com', - 'rtb': { - 'video': { - 'asset_url': 'https://sample.vastURL.com/here/adpod', - 'duration_ms': 30000, - } - }, - 'viewability': { - 'config': '' - } - }] - }] - }; - - const bidderRequest = { - bids: [{ - bidId: '84ab500420319d', - adUnitCode: 'code', - mediaTypes: { - video: { - context: 'adpod' - } - } - }] - }; - - const result = spec.interpretResponse({ body: response }, { bidderRequest }); - expect(result[0]).to.have.property('vastUrl'); - expect(result[0].video.context).to.equal('adpod'); - expect(result[0].video.durationSeconds).to.equal(30); - }); - } - - if (FEATURES.NATIVE) { - const BASE_NATIVE = { - 'title': 'Native Creative', - 'desc': 'Cool description great stuff', - 'desc2': 'Additional body text', - 'ctatext': 'Do it', - 'sponsored': 'AppNexus', - 'icon': { - 'width': 0, - 'height': 0, - 'url': 'https://cdn.adnxs.com/icon.png' - }, - 'main_img': { - 'width': 2352, - 'height': 1516, - 'url': 'https://cdn.adnxs.com/img.png' - }, - 'link': { - 'url': 'https://www.appnexus.com', - 'fallback_url': '', - 'click_trackers': ['https://nym1-ib.adnxs.com/click'] - }, - 'impression_trackers': ['https://example.com'], - 'rating': '5', - 'displayurl': 'https://AppNexus.com/?url=display_url', - 'likes': '38908320', - 'downloads': '874983', - 'price': '9.99', - 'saleprice': 'FREE', - 'phone': '1234567890', - 'address': '28 W 23rd St, New York, NY 10010', - 'privacy_link': 'https://appnexus.com/?url=privacy_url', - 'javascriptTrackers': '', - 'video': { - 'content': '' - } - }; - - it('handles native responses', function () { - const response1 = deepClone(response); - response1.tags[0].ads[0].ad_type = 'native'; - response1.tags[0].ads[0].rtb.native = BASE_NATIVE; - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - } - - const result = spec.interpretResponse({ body: response1 }, { bidderRequest }); - expect(result[0].native.title).to.equal('Native Creative'); - expect(result[0].native.body).to.equal('Cool description great stuff'); - expect(result[0].native.body2).to.equal('Additional body text'); - expect(result[0].native.cta).to.equal('Do it'); - expect(result[0].native.image.url).to.equal('https://cdn.adnxs.com/img.png'); - // Video is technically not a base Prebid native field, so it should be included as part of the ext - // But it's also included here for backwards compatibility if people read the bid directly - expect(result[0].native.video.content).to.equal(''); - }); - - it('handles custom native fields as ext', function () { - const response1 = deepClone(response); - response1.tags[0].ads[0].ad_type = 'native'; - response1.tags[0].ads[0].rtb.native = { - ...BASE_NATIVE, - // 'video' is included in base native - 'title1': 'Custom Title 1', - 'title2': 'Custom Title 2', - 'title3': 'Custom Title 3', - 'title4': 'Custom Title 4', - 'title5': 'Custom Title 5', - // Not to be confused with Prebid's base native body & body2 - 'body1': 'Custom Body 1', - 'body2': 'Custom Body 2', - 'body3': 'Custom Body 3', - 'body4': 'Custom Body 4', - 'body5': 'Custom Body 5', - 'image1': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/custom_image_1.jpg?[fullhash]', - 'height': 627, - 'width': 1200, - }, - 'image2': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/custom_image_2.jpg?[fullhash]', - 'height': 627, - 'width': 1200, - }, - 'image3': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/custom_image_3.jpg?[fullhash]', - 'height': 627, - 'width': 1200, - }, - 'image4': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/custom_image_4.jpg?[fullhash]', - 'height': 627, - 'width': 1200, - }, - 'image5': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/custom_image_5.jpg?[fullhash]', - 'height': 627, - 'width': 1200, - }, - 'icon1': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'icon2': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'icon3': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'icon4': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'icon5': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'socialicon1': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'socialicon2': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'socialicon3': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'socialicon4': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'socialicon5': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'socialurl1': 'https://www.xandr.com/platform/monetize/#socialUrl1', - 'socialurl2': 'https://www.xandr.com/platform/monetize/#socialUrl2', - 'socialurl3': 'https://www.xandr.com/platform/monetize/#socialUrl3', - 'socialurl4': 'https://www.xandr.com/platform/monetize/#socialUrl4', - 'socialurl5': 'https://www.xandr.com/platform/monetize/#socialUrl5', - 'displayurl1': 'https://www.xandr.com/platform/monetize/#displayUrl1', - 'displayurl2': 'https://www.xandr.com/platform/monetize/#displayUrl2', - 'displayurl3': 'https://www.xandr.com/platform/monetize/#displayUrl3', - 'displayurl4': 'https://www.xandr.com/platform/monetize/#displayUrl4', - 'displayurl5': 'https://www.xandr.com/platform/monetize/#displayUrl5', - 'ctatext1': 'Custom CTA 1', - 'ctatext2': 'Custom CTA 2', - 'ctatext3': 'Custom CTA 3', - 'ctatext4': 'Custom CTA 4', - 'ctatext5': 'Custom CTA 5', - }; - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - } - - const result = spec.interpretResponse({ body: response1 }, { bidderRequest }); - expect(result[0].native.ext).to.deep.equal({ - 'video': { - 'content': '' - }, - 'customTitle1': 'Custom Title 1', - 'customTitle2': 'Custom Title 2', - 'customTitle3': 'Custom Title 3', - 'customTitle4': 'Custom Title 4', - 'customTitle5': 'Custom Title 5', - 'customBody1': 'Custom Body 1', - 'customBody2': 'Custom Body 2', - 'customBody3': 'Custom Body 3', - 'customBody4': 'Custom Body 4', - 'customBody5': 'Custom Body 5', - 'customImage1': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/custom_image_1.jpg?[fullhash]', - 'height': 627, - 'width': 1200, - }, - 'customImage2': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/custom_image_2.jpg?[fullhash]', - 'height': 627, - 'width': 1200, - }, - 'customImage3': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/custom_image_3.jpg?[fullhash]', - 'height': 627, - 'width': 1200, - }, - 'customImage4': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/custom_image_4.jpg?[fullhash]', - 'height': 627, - 'width': 1200, - }, - 'customImage5': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/custom_image_5.jpg?[fullhash]', - 'height': 627, - 'width': 1200, - }, - 'customIcon1': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'customIcon2': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'customIcon3': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'customIcon4': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'customIcon5': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'customSocialIcon1': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'customSocialIcon2': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'customSocialIcon3': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'customSocialIcon4': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'customSocialIcon5': { - 'url': 'https://monetize.xandr.com/creative-ui/assets/logo.jpg?[fullhash]', - 'height': 128, - 'width': 128, - }, - 'customSocialUrl1': 'https://www.xandr.com/platform/monetize/#socialUrl1', - 'customSocialUrl2': 'https://www.xandr.com/platform/monetize/#socialUrl2', - 'customSocialUrl3': 'https://www.xandr.com/platform/monetize/#socialUrl3', - 'customSocialUrl4': 'https://www.xandr.com/platform/monetize/#socialUrl4', - 'customSocialUrl5': 'https://www.xandr.com/platform/monetize/#socialUrl5', - 'customDisplayUrl1': 'https://www.xandr.com/platform/monetize/#displayUrl1', - 'customDisplayUrl2': 'https://www.xandr.com/platform/monetize/#displayUrl2', - 'customDisplayUrl3': 'https://www.xandr.com/platform/monetize/#displayUrl3', - 'customDisplayUrl4': 'https://www.xandr.com/platform/monetize/#displayUrl4', - 'customDisplayUrl5': 'https://www.xandr.com/platform/monetize/#displayUrl5', - 'customCta1': 'Custom CTA 1', - 'customCta2': 'Custom CTA 2', - 'customCta3': 'Custom CTA 3', - 'customCta4': 'Custom CTA 4', - 'customCta5': 'Custom CTA 5', - }); - }); - } - - if (FEATURES.VIDEO) { - it('supports configuring outstream renderers', function () { - const outstreamResponse = deepClone(response); - outstreamResponse.tags[0].ads[0].rtb.video = {}; - outstreamResponse.tags[0].ads[0].renderer_url = 'renderer.js'; - - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - renderer: { - options: { - adText: 'configured' - } - }, - mediaTypes: { - video: { - context: 'outstream' - } - } - }] - }; - - const result = spec.interpretResponse({ body: outstreamResponse }, { bidderRequest }); - expect(result[0].renderer.config).to.deep.equal( - bidderRequest.bids[0].renderer.options - ); - }); - - it('should add deal_priority and deal_code', function () { - const responseWithDeal = deepClone(response); - responseWithDeal.tags[0].ads[0].ad_type = 'video'; - responseWithDeal.tags[0].ads[0].deal_priority = 5; - responseWithDeal.tags[0].ads[0].deal_code = '123'; - responseWithDeal.tags[0].ads[0].rtb.video = { - duration_ms: 1500, - player_width: 640, - player_height: 340, - }; - - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code', - mediaTypes: { - video: { - context: 'adpod' - } - } - }] - } - const result = spec.interpretResponse({ body: responseWithDeal }, { bidderRequest }); - expect(Object.keys(result[0].appnexus)).to.include.members(['buyerMemberId', 'dealPriority', 'dealCode']); - expect(result[0].video.dealTier).to.equal(5); - }); - } - - it('should add advertiser id', function () { - const responseAdvertiserId = deepClone(response); - responseAdvertiserId.tags[0].ads[0].advertiser_id = '123'; - - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - } - const result = spec.interpretResponse({ body: responseAdvertiserId }, { bidderRequest }); - expect(Object.keys(result[0].meta)).to.include.members(['advertiserId']); - }); - - it('should add brand id', function () { - const responseBrandId = deepClone(response); - responseBrandId.tags[0].ads[0].brand_id = 123; - - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - } - const result = spec.interpretResponse({ body: responseBrandId }, { bidderRequest }); - expect(Object.keys(result[0].meta)).to.include.members(['brandId']); - }); - - it('should add advertiserDomains', function () { - const responseAdvertiserId = deepClone(response); - responseAdvertiserId.tags[0].ads[0].adomain = '123'; - - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - } - const result = spec.interpretResponse({ body: responseAdvertiserId }, { bidderRequest }); - expect(Object.keys(result[0].meta)).to.include.members(['advertiserDomains']); - expect(result[0].meta.advertiserDomains).to.deep.equal(['123']); - }); - }); - - describe('getUserSyncs', function() { - let syncOptions, gdprConsent; - - beforeEach(() => { - gdprConsent = { - gdprApplies: true, - consentString: 'CPJl4C8PJl4C8OoAAAENAwCMAP_AAH_AAAAAAPgAAAAIAPgAAAAIAAA.IGLtV_T9fb2vj-_Z99_tkeYwf95y3p-wzhheMs-8NyZeH_B4Wv2MyvBX4JiQKGRgksjLBAQdtHGlcTQgBwIlViTLMYk2MjzNKJrJEilsbO2dYGD9Pn8HT3ZCY70-vv__7v3ff_3g', - vendorData: { - purpose: { - consents: { - '1': true - } - } - } - } - }); - - describe('pixel', function () { - beforeEach(() => { - syncOptions = { pixelEnabled: true }; - }); - - it('pixelEnabled on', function () { - const result = spec.getUserSyncs(syncOptions, [], gdprConsent, null); - expect(result).to.have.length(1); - expect(result[0].type).to.equal('image'); - expect(result[0].url).to.equal('https://px.ads.linkedin.com/setuid?partner=appNexus'); - }); - - it('pixelEnabled off', function () { - syncOptions.pixelEnabled = false; - const result = spec.getUserSyncs(syncOptions, [], gdprConsent, null); - expect(result).to.be.undefined; - }); - }); - - describe('iframe', function () { - beforeEach(() => { - syncOptions = { iframeEnabled: true }; - }); - - it('iframeEnabled on with gdpr purpose 1 on', function () { - const result = spec.getUserSyncs(syncOptions, [], gdprConsent, null); - expect(result).to.have.length(1); - expect(result[0].type).to.equal('iframe'); - expect(result[0].url).to.equal('https://acdn.adnxs.com/dmp/async_usersync.html'); - }); - - it('iframeEnabled on with gdpr purpose1 off', function () { - gdprConsent.vendorData.purpose.consents['1'] = false - - const result = spec.getUserSyncs(syncOptions, [], gdprConsent, null); - expect(result).to.be.undefined; - }); - - it('iframeEnabled on without gdpr', function () { - const result = spec.getUserSyncs(syncOptions, [], null, null); - expect(result).to.have.length(1); - expect(result[0].type).to.equal('iframe'); - expect(result[0].url).to.equal('https://acdn.adnxs.com/dmp/async_usersync.html'); - }); - - it('iframeEnabled off', function () { - syncOptions.iframeEnabled = false; - const result = spec.getUserSyncs(syncOptions, [], gdprConsent, null); - expect(result).to.be.undefined; - }); - }); - }); -}); diff --git a/test/spec/modules/appushBidAdapter_spec.js b/test/spec/modules/appushBidAdapter_spec.js deleted file mode 100644 index b6c535c46..000000000 --- a/test/spec/modules/appushBidAdapter_spec.js +++ /dev/null @@ -1,383 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/appushBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'appush' - -describe('AppushBidAdapter', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner', - } - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo', - } - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative', - } - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com' - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://hb.appush.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.include.all.keys( - 'deviceWidth', - 'deviceHeight', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - - it('Returns empty data if no valid requests are passed', function () { - serverRequest = spec.buildRequests([], bidderRequest); - const data = serverRequest.data; - expect(data.placements).to.be.an('array').that.is.empty; - }); - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); -}); diff --git a/test/spec/modules/apstreamBidAdapter_spec.js b/test/spec/modules/apstreamBidAdapter_spec.js deleted file mode 100644 index de13e45b6..000000000 --- a/test/spec/modules/apstreamBidAdapter_spec.js +++ /dev/null @@ -1,327 +0,0 @@ -// jshint esversion: 6, es3: false, node: true -import {assert, expect} from 'chai'; -import {config} from 'src/config.js'; -import {spec} from 'modules/apstreamBidAdapter.js'; -import * as utils from 'src/utils.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -const validBidRequests = [{ - bidId: 'bidId', - adUnitCode: '/id/site1/header-ad', - sizes: [[980, 120], [980, 180]], - mediaTypes: { - banner: { - sizes: [[980, 120], [980, 180]] - } - }, - params: { - publisherId: '1234' - } -}]; - -describe('AP Stream adapter', function() { - describe('isBidRequestValid', function() { - const bid = { - bidder: 'apstream', - mediaTypes: { - banner: { - sizes: [300, 250] - } - }, - params: { - } - }; - - let mockConfig; - beforeEach(function () { - getGlobal().bidderSettings = { - apstream: { - storageAllowed: true - } - }; - mockConfig = { - apstream: { - publisherId: '4321' - } - }; - sinon.stub(config, 'getConfig').callsFake((key) => { - return utils.deepAccess(mockConfig, key); - }); - }); - - afterEach(function () { - getGlobal().bidderSettings = {}; - config.getConfig.restore(); - }); - - it('should return true when publisherId is configured and one media type', function() { - bid.params.publisherId = '1234'; - assert(spec.isBidRequestValid(bid)) - }); - - it('should return false when publisherId is configured and two media types', function() { - bid.mediaTypes.video = {sizes: [300, 250]}; - assert.isFalse(spec.isBidRequestValid(bid)) - }); - - it('should return true when publisherId is configured via config', function() { - delete bid.mediaTypes.video; - delete bid.params.publisherId; - assert.isTrue(spec.isBidRequestValid(bid)) - }); - }); - - describe('buildRequests', function() { - it('should send request with correct structure', function() { - const request = spec.buildRequests(validBidRequests, { })[0]; - - assert.equal(request.method, 'GET'); - assert.deepEqual(request.options, {withCredentials: false}); - assert.ok(request.data); - }); - - it('should send request with different endpoints', function() { - const validTwoBidRequests = [ - ...validBidRequests, - ...[{ - bidId: 'bidId2', - adUnitCode: '/id/site1/header-ad', - sizes: [[980, 980], [980, 900]], - mediaTypes: { - banner: { - sizes: [[980, 980], [980, 900]] - } - }, - params: { - publisherId: '1234', - endpoint: 'site2.com' - } - }] - ]; - - const request = spec.buildRequests(validTwoBidRequests, {}); - assert.isArray(request); - assert.lengthOf(request, 2); - assert.equal(request[1].data.bids, 'bidId2:t=b,s=980x980_980x900,c=/id/site1/header-ad'); - }); - - it('should send request with adUnit code', function() { - const adunitCodeValidBidRequests = [ - { - ...validBidRequests[0], - ...{ - params: { - code: 'Site1_Leaderboard' - } - } - } - ]; - - const request = spec.buildRequests(adunitCodeValidBidRequests, { })[0]; - assert.equal(request.data.bids, 'bidId:t=b,s=980x120_980x180,c=Site1_Leaderboard'); - }); - - it('should send request with adUnit id', function() { - const adunitIdValidBidRequests = [ - { - ...validBidRequests[0], - ...{ - params: { - adunitId: '12345' - } - } - } - ]; - - const request = spec.buildRequests(adunitIdValidBidRequests, { })[0]; - assert.equal(request.data.bids, 'bidId:t=b,s=980x120_980x180,u=12345'); - }); - - it('should send request with different media type', function() { - const types = { - 'audio': 'a', - 'banner': 'b', - 'native': 'n', - 'video': 'v' - } - Object.keys(types).forEach(key => { - const adunitIdValidBidRequests = [ - { - ...validBidRequests[0], - ...{ - mediaTypes: { - [key]: { - sizes: [300, 250] - } - } - } - } - ]; - - const request = spec.buildRequests(adunitIdValidBidRequests, { })[0]; - assert.equal(request.data.bids, `bidId:t=${types[key]},s=980x120_980x180,c=/id/site1/header-ad`); - }) - }); - - describe('gdpr', function() { - let mockConfig; - - beforeEach(function () { - mockConfig = { - consentManagement: { - cmpApi: 'iab' - } - }; - sinon.stub(config, 'getConfig').callsFake((key) => { - return utils.deepAccess(mockConfig, key); - }); - }); - - afterEach(function () { - config.getConfig.restore(); - }); - - it('should send GDPR Consent data', function() { - const bidderRequest = { - gdprConsent: { - gdprApplies: true, - consentString: 'consentDataString', - vendorData: { - vendorConsents: { - '394': true - } - } - } - }; - - const request = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - assert.equal(request.iab_consent, bidderRequest.gdprConsent.consentString); - }); - }); - - describe('dsu', function() { - it('should pass DSU from local storage if set', function() { - const bidderRequest = { - gdprConsent: { - gdprApplies: true, - consentString: 'consentDataString', - vendorData: { - vendorConsents: { - '394': true - } - } - } - }; - - const request = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - assert.isNotEmpty(request.dsu); - }); - }); - }); - - describe('dsu config', function() { - let mockConfig; - beforeEach(function () { - mockConfig = { - apstream: { - noDsu: true - } - }; - sinon.stub(config, 'getConfig').callsFake((key) => { - return utils.deepAccess(mockConfig, key); - }); - }); - - afterEach(function () { - config.getConfig.restore(); - }); - - it('should not send DSU if it is disabled in config', function() { - const request = spec.buildRequests(validBidRequests, { })[0]; - - assert.equal(request.data.dsu, ''); - }); - }); - - describe('interpretResponse', function () { - it('should return empty array if no body in response', function () { - const serverResponse = {}; - const bidRequest = {}; - - assert.isEmpty(spec.interpretResponse(serverResponse, bidRequest)); - }); - - it('should map server response', function () { - const serverResponse = { - body: [ - { - bidId: 123, - bidDetails: { - cpm: 1.23, - width: 980, - height: 300, - currency: 'DKK', - netRevenue: 'true', - creativeId: '1234', - dealId: '99008', - ad: '

Buy our something!

', - ttl: 360 - } - } - ] - }; - const bidRequest = {}; - - const response = spec.interpretResponse(serverResponse, bidRequest); - - const expected = { - requestId: 123, - cpm: 1.23, - width: 980, - height: 300, - currency: 'DKK', - creativeId: '1234', - netRevenue: 'true', - dealId: '99008', - ad: '

Buy our something!

', - ttl: 360 - }; - - assert.deepEqual(response[0], expected); - }); - - it('should add pixels to ad', function () { - const serverResponse = { - body: [ - { - bidId: 123, - bidDetails: { - cpm: 1.23, - width: 980, - height: 300, - currency: 'DKK', - creativeId: '1234', - netRevenue: 'true', - dealId: '99008', - ad: '

Buy our something!

', - ttl: 360, - noticeUrls: [ - 'site1', - 'site2' - ], - impressionScripts: [ - 'url_to_script' - ] - } - } - ] - }; - const bidRequest = {}; - - const response = spec.interpretResponse(serverResponse, bidRequest); - - assert.match(response[0].ad, /site1/); - assert.match(response[0].ad, /site2/); - }); - }); -}); diff --git a/test/spec/modules/arcspanRtdProvider_spec.js b/test/spec/modules/arcspanRtdProvider_spec.js deleted file mode 100644 index 9c2b35985..000000000 --- a/test/spec/modules/arcspanRtdProvider_spec.js +++ /dev/null @@ -1,187 +0,0 @@ -import { arcspanSubmodule } from 'modules/arcspanRtdProvider.js'; -import { expect } from 'chai'; -import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; - -describe('arcspanRtdProvider', function () { - describe('init', function () { - afterEach(function () { - window.arcobj1 = undefined; - window.arcobj2 = undefined; - }); - - it('successfully initializes with a valid silo ID', function () { - expect(arcspanSubmodule.init(getGoodConfig())).to.equal(true); - expect(loadExternalScriptStub.called).to.be.ok; - expect(loadExternalScriptStub.args[0][0]).to.deep.equal('https://silo13.p7cloud.net/as.js'); - loadExternalScriptStub.resetHistory(); - }); - - it('fails to initialize with a missing silo ID', function () { - expect(arcspanSubmodule.init(getBadConfig())).to.equal(false); - expect(loadExternalScriptStub.called).to.be.not.ok; - loadExternalScriptStub.resetHistory(); - }); - - it('drops localhost script for test silo', function () { - expect(arcspanSubmodule.init(getTestConfig())).to.equal(true); - expect(loadExternalScriptStub.called).to.be.ok; - expect(loadExternalScriptStub.args[0][0]).to.deep.equal('https://localhost:8080/as.js'); - loadExternalScriptStub.resetHistory(); - }); - }); - - describe('alterBidRequests', function () { - afterEach(function () { - window.arcobj1 = undefined; - window.arcobj2 = undefined; - }); - - it('alters the bid request 1', function () { - setIAB({ - raw: { - images: [ - 'Religion & Spirituality', - 'Medical Health>Substance Abuse', - 'Religion & Spirituality>Astrology', - 'Medical Health', - 'Events & Attractions', - ], - }, - codes: { - images: ['IAB23-10', 'IAB7', 'IAB7-42', 'IAB15-1'], - }, - newcodes: { - images: ['150', '453', '311', '456', '286'], - }, - }); - - var reqBidsConfigObj = {}; - reqBidsConfigObj.ortb2Fragments = {}; - reqBidsConfigObj.ortb2Fragments.global = {}; - arcspanSubmodule.getBidRequestData(reqBidsConfigObj, function () { - expect(reqBidsConfigObj.ortb2Fragments.global.site.name).to.equal( - 'arcspan' - ); - expect(reqBidsConfigObj.ortb2Fragments.global.site.keywords).to.equal( - 'Religion & Spirituality,Medical Health>Substance Abuse,Religion & Spirituality>Astrology,Medical Health,Events & Attractions' - ); - expect(reqBidsConfigObj.ortb2Fragments.global.site.content.data[0].ext.segtax).to.equal(6); - expect(reqBidsConfigObj.ortb2Fragments.global.site.cat).to.eql([ - 'IAB23_10', - 'IAB7', - 'IAB7_42', - 'IAB15_1', - ]); - expect(reqBidsConfigObj.ortb2Fragments.global.site.sectioncat).to.eql([ - 'IAB23_10', - 'IAB7', - 'IAB7_42', - 'IAB15_1' - ]); - expect(reqBidsConfigObj.ortb2Fragments.global.site.pagecat).to.eql([ - 'IAB23_10', - 'IAB7', - 'IAB7_42', - 'IAB15_1', - ]); - expect(reqBidsConfigObj.ortb2Fragments.global.site.content.data[0].segment).to.eql([ - { id: '150' }, - { id: '453' }, - { id: '311' }, - { id: '456' }, - { id: '286' } - ]); - }); - }); - - it('alters the bid request 2', function () { - setIAB({ - raw: { text: ['Sports', 'Sports>Soccer'] }, - codes: { text: ['IAB17', 'IAB17-44'] }, - newcodes: { text: ['483', '533'] }, - }); - - var reqBidsConfigObj = {}; - reqBidsConfigObj.ortb2Fragments = {}; - reqBidsConfigObj.ortb2Fragments.global = {}; - arcspanSubmodule.getBidRequestData(reqBidsConfigObj, function () { - expect(reqBidsConfigObj.ortb2Fragments.global.site.name).to.equal( - 'arcspan' - ); - expect(reqBidsConfigObj.ortb2Fragments.global.site.keywords).to.equal( - 'Sports,Sports>Soccer' - ); - expect(reqBidsConfigObj.ortb2Fragments.global.site.content.data[0].ext.segtax).to.equal(6); - expect(reqBidsConfigObj.ortb2Fragments.global.site.cat).to.eql([ - 'IAB17', - 'IAB17_44', - ]); - expect(reqBidsConfigObj.ortb2Fragments.global.site.sectioncat).to.eql([ - 'IAB17', - 'IAB17_44' - ]); - expect(reqBidsConfigObj.ortb2Fragments.global.site.pagecat).to.eql([ - 'IAB17', - 'IAB17_44', - ]); - expect(reqBidsConfigObj.ortb2Fragments.global.site.content.data[0].segment).to.eql([ - { id: '483' }, - { id: '533' } - ]); - }); - }); - }); -}); - -function getGoodConfig() { - return { - name: 'arcspan', - waitForIt: true, - params: { - silo: 13, - }, - }; -} - -function getBadConfig() { - return { - name: 'arcspan', - waitForIt: true, - params: { - notasilo: 1, - }, - }; -} - -function getTestConfig() { - return { - name: 'arcspan', - waitForIt: true, - params: { - silo: 'test', - }, - }; -} - -function setIAB(vjson) { - window.arcobj2 = {}; - window.arcobj2.cat = 0; - if (typeof vjson.codes !== 'undefined') { - window.arcobj2.cat = 1; - if (typeof vjson.codes.images !== 'undefined') { - vjson.codes.images.forEach(function f(e, i) { - vjson.codes.images[i] = e.replace('-', '_'); - }); - } - if (typeof vjson.codes.text !== 'undefined') { - vjson.codes.text.forEach(function f(e, i) { - vjson.codes.text[i] = e.replace('-', '_'); - }); - } - window.arcobj2.sampled = 1; - window.arcobj1 = {}; - window.arcobj1.page_iab_codes = vjson.codes; - window.arcobj1.page_iab = vjson.raw; - window.arcobj1.page_iab_newcodes = vjson.newcodes; - } -} diff --git a/test/spec/modules/asealBidAdapter_spec.js b/test/spec/modules/asealBidAdapter_spec.js deleted file mode 100644 index 07e8f30e1..000000000 --- a/test/spec/modules/asealBidAdapter_spec.js +++ /dev/null @@ -1,212 +0,0 @@ -import { expect } from 'chai'; -import { - spec, - BIDDER_CODE, - API_ENDPOINT, - HEADER_AOTTER_VERSION, - WEB_SESSION_ID_KEY, storage -} from 'modules/asealBidAdapter.js'; -import { getRefererInfo } from 'src/refererDetection.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import * as utils from 'src/utils.js'; - -const TEST_CLIENT_ID = 'TEST_CLIENT_ID'; -const TEST_WEB_SESSION_ID = 'TEST_WEB_SESSION_ID'; - -describe('asealBidAdapter', () => { - const adapter = newBidder(spec); - - let localStorageIsEnabledStub; - let getDataFromLocalStorageStub; - let sandbox; - let w; - - beforeEach((done) => { - localStorageIsEnabledStub = sinon.stub(storage, 'localStorageIsEnabled'); - getDataFromLocalStorageStub = sinon.stub( - storage, - 'getDataFromLocalStorage' - ); - - w = { - document: { - title: 'Aseal', - referrer: 'https://aseal.in/', - href: 'https://aseal.in/', - }, - location: { - href: 'https://aseal.in/', - }, - }; - - sandbox = sinon.createSandbox(); - sandbox.stub(utils, 'getWindowTop').returns(w); - sandbox.stub(utils, 'getWindowSelf').returns(w); - done(); - }); - - afterEach(() => { - localStorageIsEnabledStub.restore(); - getDataFromLocalStorageStub.restore(); - sandbox.restore(); - config.resetConfig(); - }); - - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', () => { - const bid = { - bidder: 'aseal', - params: { - placeUid: '123', - }, - }; - - it('should return true when required params found', () => { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required param placeUid is not passed', () => { - bid.params = { - placeUid: '', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when required param placeUid is wrong type', () => { - bid.params = { - placeUid: null, - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when required params are not passed', () => { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', () => { - it('should return an empty array when there are no bid requests', () => { - const bidRequests = []; - const request = spec.buildRequests(bidRequests); - - expect(request).to.be.an('array').that.is.empty; - }); - - it('should send `x-aotter-clientid` header as empty string when user not set config `clientId`', () => { - const bidRequests = [ - { - bidder: BIDDER_CODE, - params: { - placeUid: '123', - }, - }, - ]; - - const bidderRequest = {}; - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - - expect(request.options.customHeaders['x-aotter-clientid']).equal(''); - }); - - it('should send bid requests to ENDPOINT via POST', () => { - const bidRequests = [ - { - bidder: BIDDER_CODE, - params: { - placeUid: '123', - }, - }, - ]; - - const bidderRequest = { - refererInfo: getRefererInfo(), - }; - - config.setConfig({ - aseal: { - clientId: TEST_CLIENT_ID, - }, - }); - - localStorageIsEnabledStub.returns(true); - getDataFromLocalStorageStub - .withArgs(WEB_SESSION_ID_KEY) - .returns(TEST_WEB_SESSION_ID); - - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - - utils.getWindowTop.restore(); - utils.getWindowSelf.restore(); - - sandbox.stub(utils, 'getWindowTop').returns(w); - sandbox.stub(utils, 'getWindowSelf').returns(w); - - const payload = { - meta: { - dr: w.document.referrer, - drs: w.document.referrer, - drt: w.document.referrer, - dt: w.document.title, - dl: w.location.href, - }, - }; - - expect(request.url).to.equal(API_ENDPOINT); - expect(request.method).to.equal('POST'); - expect(request.options).deep.equal({ - contentType: 'application/json', - withCredentials: true, - customHeaders: { - 'x-aotter-clientid': TEST_CLIENT_ID, - 'x-aotter-version': HEADER_AOTTER_VERSION, - }, - }); - expect(request.data.bids).deep.equal(bidRequests); - expect(request.data.payload).deep.equal(payload); - expect(request.data.device).deep.equal({ - webSessionId: TEST_WEB_SESSION_ID, - }); - }); - }); - - describe('interpretResponse', () => { - it('should return an empty array when there are no bids', () => { - const serverResponse = {}; - const response = spec.interpretResponse(serverResponse); - - expect(response).is.an('array').that.is.empty; - }); - - it('should get correct bid response', () => { - const serverResponse = { - body: [ - { - requestId: '2ef08f145b7a4f', - cpm: 3, - width: 300, - height: 250, - creativeId: '123abc', - dealId: '123abc', - currency: 'USD', - netRevenue: false, - mediaType: 'banner', - ttl: 300, - ad: '', - }, - ], - }; - const response = spec.interpretResponse(serverResponse); - - expect(response).deep.equal(serverResponse.body); - }); - }); -}); diff --git a/test/spec/modules/asoBidAdapter_spec.js b/test/spec/modules/asoBidAdapter_spec.js deleted file mode 100644 index e0fffee68..000000000 --- a/test/spec/modules/asoBidAdapter_spec.js +++ /dev/null @@ -1,493 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/asoBidAdapter.js'; -import {BANNER, NATIVE, VIDEO} from 'src/mediaTypes.js'; -import {OUTSTREAM} from 'src/video.js'; -import {addFPDToBidderRequest} from '../../helpers/fpd.js'; -import {parseUrl} from '../../../src/utils.js'; - -import 'modules/priceFloors.js'; -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; - -describe('Adserver.Online bidding adapter', function () { - const bannerRequest = { - bidder: 'aso', - params: { - zone: 1 - }, - adUnitCode: 'adunit-banner', - bidId: 'bid-banner', - mediaTypes: { - [BANNER]: { - sizes: [ - [300, 250], - [240, 400], - ] - } - }, - userIdAsEids: [{ - source: 'src1', - uids: [ - { - id: 'id123...' - } - ] - }] - }; - - const videoRequest = { - bidder: 'aso', - params: { - zone: 2 - }, - adUnitCode: 'adunit-video', - bidId: 'bid-video', - mediaTypes: { - [VIDEO]: { - context: OUTSTREAM, - playerSize: [[640, 480]], - protocols: [1, 2], - mimes: ['video/mp4'], - } - } - }; - - const nativeOrtbRequest = { - assets: [ - { - id: 0, - required: 1, - title: { - len: 140 - } - }, - { - id: 1, - required: 1, - img: { - type: 3, - w: 300, - h: 600 - } - }] - }; - - const nativeRequest = { - bidder: 'aso', - params: { - zone: 3 - }, - adUnitCode: 'adunit-native', - bidId: 'bid-native', - mediaTypes: { - [NATIVE]: { - ortb: { - ...nativeOrtbRequest - } - } - }, - nativeOrtbRequest - }; - - const gdprConsent = { - gdprApplies: true, - consentString: 'consentString', - vendorData: { - purpose: { - consents: { - 1: true, - 2: true, - 3: false - } - } - } - }; - - const gdprNotApplies = { - gdprApplies: false, - consentString: '', - vendorData: { - purpose: {} - } - }; - - let bidderRequest; - - beforeEach(() => { - return addFPDToBidderRequest({ - refererInfo: { - page: 'https://example.com/page.html', - topmostLocation: 'https://example.com/page.html', - reachedTop: true, - numIframes: 1, - stack: [ - 'https://example.com/page.html', - 'https://example.com/iframe1.html' - ] - } - }).then(br => { bidderRequest = br }); - }) - - const uspConsent = 'usp_consent'; - - describe('isBidRequestValid', function () { - it('should return true when required params found in bidVideo', function () { - expect(spec.isBidRequestValid(videoRequest)).to.be.true - }); - - it('should return true when required params found in bidBanner', function () { - expect(spec.isBidRequestValid(bannerRequest)).to.be.true - }); - - it('should return false when required params not found', function () { - expect(spec.isBidRequestValid({})).to.be.false; - }); - - it('should return false when required params are not passed', function () { - const bid = Object.assign({}, bannerRequest); - delete bid.params; - bid.params = {}; - expect(spec.isBidRequestValid(bid)).to.be.false - }); - - it('should return false when required zone param not found', function () { - const bid = JSON.parse(JSON.stringify(videoRequest)); - delete bid.params.zone; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - }); - - describe('requests builder', function () { - it('should add bid floor', function () { - const bidRequest = Object.assign({}, bannerRequest); - - bidRequest.getFloor = () => { - return { - currency: 'USD', - floor: 0.5 - } - }; - - const payload = spec.buildRequests([bidRequest], bidderRequest)[0].data; - - expect(payload.imp[0].bidfloor).to.equal(0.5); - expect(payload.imp[0].bidfloorcur).to.equal('USD'); - }); - - it('endpoint is valid', function () { - const requests = spec.buildRequests([bannerRequest], bidderRequest); - expect(requests).to.have.lengthOf(1); - const request = requests[0]; - - expect(request).to.exist; - expect(request.method).to.equal('POST'); - const parsedUrl = parseUrl(request.url); - expect(parsedUrl.hostname).to.equal('srv.aso1.net'); - expect(parsedUrl.pathname).to.equal('/prebid/bidder'); - - const query = parsedUrl.search; - expect(query.pbjs).to.contain('$prebid.version$'); - expect(query.zid).to.equal('1'); - }); - - it('creates a valid banner request', function () { - const requests = spec.buildRequests([bannerRequest], bidderRequest); - expect(requests).to.have.lengthOf(1); - const request = requests[0]; - - expect(request).to.exist; - expect(request.data).to.exist; - - const payload = request.data; - - expect(payload.site).to.exist; - expect(payload.site.page).to.equal('https://example.com/page.html'); - - expect(payload.device).to.exist; - expect(payload.device.w).to.equal(window.screen.width); - expect(payload.device.h).to.equal(window.screen.height); - - expect(payload.imp).to.have.lengthOf(1); - - expect(payload.imp[0].tagid).to.equal('adunit-banner'); - expect(payload.imp[0].banner).to.not.null; - expect(payload.imp[0].banner.format).to.have.lengthOf(2); - expect(payload.imp[0].banner.format[0].w).to.equal(300); - expect(payload.imp[0].banner.format[0].h).to.equal(250); - expect(payload.imp[0].banner.format[1].w).to.equal(240); - expect(payload.imp[0].banner.format[1].h).to.equal(400); - }); - - if (FEATURES.VIDEO) { - it('creates a valid video request', function () { - const requests = spec.buildRequests([videoRequest], bidderRequest); - expect(requests).to.have.lengthOf(1); - const request = requests[0]; - - expect(request).to.exist; - expect(request.data).to.not.be.empty; - - const payload = request.data; - - expect(payload.site).to.exist; - expect(payload.site.page).to.equal('https://example.com/page.html'); - - expect(payload.device).to.exist; - expect(payload.device.w).to.equal(window.screen.width); - expect(payload.device.h).to.equal(window.screen.height); - - expect(payload.imp).to.have.lengthOf(1); - - expect(payload.imp[0].tagid).to.equal('adunit-video'); - expect(payload.imp[0].video).to.exist; - - expect(payload.imp[0].video.w).to.equal(640); - expect(payload.imp[0].video.h).to.equal(480); - expect(payload.imp[0].banner).to.not.exist; - }); - } - - if (FEATURES.NATIVE) { - it('creates a valid native request', function () { - const requests = spec.buildRequests([nativeRequest], bidderRequest); - expect(requests).to.have.lengthOf(1); - const request = requests[0]; - - expect(request).to.exist; - expect(request.data).to.not.be.empty; - - const payload = request.data; - - expect(payload.site).to.exist; - expect(payload.site.page).to.equal('https://example.com/page.html'); - - expect(payload.device).to.exist; - expect(payload.device.w).to.equal(window.screen.width); - expect(payload.device.h).to.equal(window.screen.height); - - expect(payload.imp).to.have.lengthOf(1); - - expect(payload.imp[0].tagid).to.equal('adunit-native'); - expect(payload.imp[0].native).to.exist; - expect(payload.imp[0].native.request).to.exist; - }); - } - }); - - describe('GDPR/USP compliance', function () { - it('should send GDPR/USP consent data if it applies', function () { - bidderRequest.gdprConsent = gdprConsent; - bidderRequest.uspConsent = uspConsent; - - return addFPDToBidderRequest(bidderRequest).then(bidderRequest => { - const requests = spec.buildRequests([bannerRequest], bidderRequest); - expect(requests).to.have.lengthOf(1); - const request = requests[0]; - - expect(request.data).to.not.be.empty; - - const payload = request.data; - - expect(payload.user.ext.consent).to.equal('consentString'); - expect(payload.regs.ext.us_privacy).to.equal(uspConsent); - expect(payload.regs.ext.gdpr).to.equal(1); - }) - }); - - it('should not send GDPR/USP consent data if it does not apply', function () { - bidderRequest.gdprConsent = null; - bidderRequest.uspConsent = null; - - return addFPDToBidderRequest(bidderRequest).then(bidderRequest => { - const requests = spec.buildRequests([bannerRequest], bidderRequest); - expect(requests).to.have.lengthOf(1); - const request = requests[0]; - - expect(request.data).to.not.be.empty; - - const payload = request.data; - - expect(payload).to.not.have.nested.property('regs.ext.gdpr'); - expect(payload).to.not.have.nested.property('user.ext.consent'); - expect(payload).to.not.have.nested.property('regs.ext.us_privacy'); - }); - }); - }); - - describe('response handler', function () { - const bannerResponse = { - body: { - seatbid: [{ - bid: [ - { - impid: 'bid-banner', - price: 0.3, - crid: 321, - adm: '', - w: 300, - h: 250, - adomain: ['example.com'], - ext: { - prebid: { - type: 'banner' - } - } - } - ] - }], - cur: 'USD', - ext: { - user_syncs: [ - { - url: 'sync_url', - type: 'iframe' - } - ] - } - }, - }; - - const videoResponse = { - body: { - seatbid: [{ - bid: [ - { - impid: 'bid-video', - price: 0.5, - crid: 123, - adm: '', - adomain: ['example.com'], - w: 640, - h: 480, - ext: { - prebid: { - type: 'video' - } - } - } - ] - }], - cur: 'USD' - }, - }; - - const nativeResponse = { - body: { - seatbid: [{ - bid: [ - { - impid: 'bid-native', - price: 0.5, - crid: 123, - adm: JSON.stringify({ - assets: [ - {id: 0, title: {text: 'Title'}}, - {id: 1, img: {type: 3, url: 'https://img'}}, - ], - }), - adomain: ['example.com'], - ext: { - prebid: { - type: 'native' - } - } - } - ] - }], - cur: 'USD' - }, - }; - - it('handles banner responses', function () { - const request = spec.buildRequests([bannerRequest], bidderRequest)[0]; - const bids = spec.interpretResponse(bannerResponse, request); - - expect(bids).to.have.lengthOf(1); - - expect(bids[0]).to.exist; - expect(bids[0].width).to.equal(300); - expect(bids[0].height).to.equal(250); - expect(bids[0].mediaType).to.equal(BANNER); - expect(bids[0].creativeId).to.equal(321); - expect(bids[0].cpm).to.be.within(0.1, 0.5); - expect(bids[0].ad).to.equal(''); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[0].ttl).to.equal(300); - expect(bids[0].dealId).to.not.exist; - expect(bids[0].meta.advertiserDomains[0]).to.equal('example.com'); - }); - - if (FEATURES.VIDEO) { - it('handles video responses', function () { - const request = spec.buildRequests([videoRequest], bidderRequest)[0]; - const bids = spec.interpretResponse(videoResponse, request); - expect(bids).to.have.lengthOf(1); - - expect(bids[0].width).to.equal(640); - expect(bids[0].height).to.equal(480); - expect(bids[0].mediaType).to.equal(VIDEO); - expect(bids[0].creativeId).to.equal(123); - expect(bids[0].cpm).to.equal(0.5); - expect(bids[0].vastXml).to.equal(''); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[0].ttl).to.equal(300); - }); - } - - if (FEATURES.NATIVE) { - it('handles native responses', function () { - const request = spec.buildRequests([nativeRequest], bidderRequest)[0]; - const bids = spec.interpretResponse(nativeResponse, request); - expect(bids).to.have.lengthOf(1); - - expect(bids[0].mediaType).to.equal(NATIVE); - expect(bids[0].creativeId).to.equal(123); - expect(bids[0].cpm).to.equal(0.5); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[0].ttl).to.equal(300); - - expect(bids[0].native.ortb.assets).to.have.lengthOf(2); - }); - } - - it('handles empty responses', function () { - const response = []; - const bidderRequest = {}; - - const result = spec.interpretResponse(response, bidderRequest); - expect(result.length).to.equal(0); - }); - - describe('getUserSyncs', function () { - const syncOptions = { - iframeEnabled: true - }; - - it('should return iframe sync option', function () { - const syncs = spec.getUserSyncs(syncOptions, [bannerResponse], gdprConsent, uspConsent); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.equal( - 'sync_url?gdpr=1&consents_str=consentString&consents=1%2C2&us_privacy=usp_consent' - ); - }); - - it('should return iframe sync option - gdpr not applies', function () { - const syncs = spec.getUserSyncs(syncOptions, [bannerResponse], gdprNotApplies, uspConsent); - expect(syncs).to.have.lengthOf(1); - - expect(syncs[0].url).to.equal( - 'sync_url?us_privacy=usp_consent' - ); - }); - - it('should return no sync option', function () { - const syncs = spec.getUserSyncs(syncOptions, [videoResponse], gdprNotApplies, uspConsent); - expect(syncs).to.have.lengthOf(0); - }); - }); - }); -}); diff --git a/test/spec/modules/asteriobidAnalyticsAdapter_spec.js b/test/spec/modules/asteriobidAnalyticsAdapter_spec.js deleted file mode 100644 index e8a1cca53..000000000 --- a/test/spec/modules/asteriobidAnalyticsAdapter_spec.js +++ /dev/null @@ -1,151 +0,0 @@ -import asteriobidAnalytics, {storage} from 'modules/asteriobidAnalyticsAdapter.js'; -import {expect} from 'chai'; -import {server} from 'test/mocks/xhr.js'; -import * as utils from 'src/utils.js'; -import {expectEvents} from '../../helpers/analytics.js'; -import { EVENTS } from 'src/constants.js'; - -const events = require('src/events'); - -describe('AsterioBid Analytics Adapter', function () { - const bidWonEvent = { - 'bidderCode': 'appnexus', - 'width': 300, - 'height': 250, - 'adId': '1ebb82ec35375e', - 'mediaType': 'banner', - 'cpm': 0.5, - 'requestId': '1582271863760569973', - 'creative_id': '96846035', - 'creativeId': '96846035', - 'ttl': 60, - 'currency': 'USD', - 'netRevenue': true, - 'auctionId': '9c7b70b9-b6ab-4439-9e71-b7b382797c18', - 'responseTimestamp': 1537521629657, - 'requestTimestamp': 1537521629331, - 'bidder': 'appnexus', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'timeToRespond': 326, - 'size': '300x250', - 'status': 'rendered', - 'eventType': 'bidWon', - 'ad': 'some ad', - 'adUrl': 'ad url' - }; - - describe('AsterioBid Analytic tests', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - }); - - afterEach(function () { - asteriobidAnalytics.disableAnalytics(); - events.getEvents.restore(); - }); - - it('support custom endpoint', function () { - const custom_url = 'custom url'; - asteriobidAnalytics.enableAnalytics({ - provider: 'asteriobid', - options: { - url: custom_url, - bundleId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' - } - }); - - expect(asteriobidAnalytics.getOptions().url).to.equal(custom_url); - }); - - it('bid won event', function() { - const bundleId = 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'; - asteriobidAnalytics.enableAnalytics({ - provider: 'asteriobid', - options: { - bundleId: bundleId - } - }); - - events.emit(EVENTS.BID_WON, bidWonEvent); - asteriobidAnalytics.flush(); - - expect(server.requests.length).to.equal(1); - expect(server.requests[0].url).to.equal('https://endpt.asteriobid.com/endpoint'); - expect(server.requests[0].requestBody.substring(0, 2)).to.equal('1:'); - - const pmEvents = JSON.parse(server.requests[0].requestBody.substring(2)); - expect(pmEvents.pageViewId).to.exist; - expect(pmEvents.bundleId).to.equal(bundleId); - expect(pmEvents.ver).to.equal(1); - expect(pmEvents.events.length).to.equal(1); - expect(pmEvents.events[0].eventType).to.equal('bidWon'); - expect(pmEvents.events[0].ad).to.be.undefined; - expect(pmEvents.events[0].adUrl).to.be.undefined; - }); - - it('track event without errors', function () { - sinon.spy(asteriobidAnalytics, 'track'); - - asteriobidAnalytics.enableAnalytics({ - provider: 'asteriobid', - options: { - bundleId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' - } - }); - - expectEvents().to.beTrackedBy(asteriobidAnalytics.track); - }); - }); - - describe('build utm tag data', function () { - let getDataFromLocalStorageStub; - this.timeout(4000) - beforeEach(function () { - getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); - getDataFromLocalStorageStub.withArgs('pm_utm_source').returns('utm_source'); - getDataFromLocalStorageStub.withArgs('pm_utm_medium').returns('utm_medium'); - getDataFromLocalStorageStub.withArgs('pm_utm_campaign').returns('utm_camp'); - getDataFromLocalStorageStub.withArgs('pm_utm_term').returns(''); - getDataFromLocalStorageStub.withArgs('pm_utm_content').returns(''); - }); - afterEach(function () { - getDataFromLocalStorageStub.restore(); - asteriobidAnalytics.disableAnalytics() - }); - it('should build utm data from local storage', function () { - asteriobidAnalytics.enableAnalytics({ - provider: 'asteriobid', - options: { - bundleId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' - } - }); - - const pmEvents = JSON.parse(server.requests[0].requestBody.substring(2)); - - expect(pmEvents.utmTags.utm_source).to.equal('utm_source'); - expect(pmEvents.utmTags.utm_medium).to.equal('utm_medium'); - expect(pmEvents.utmTags.utm_campaign).to.equal('utm_camp'); - expect(pmEvents.utmTags.utm_term).to.equal(''); - expect(pmEvents.utmTags.utm_content).to.equal(''); - }); - }); - - describe('build page info', function () { - afterEach(function () { - asteriobidAnalytics.disableAnalytics() - }); - it('should build page info', function () { - asteriobidAnalytics.enableAnalytics({ - provider: 'asteriobid', - options: { - bundleId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' - } - }); - - const pmEvents = JSON.parse(server.requests[0].requestBody.substring(2)); - - expect(pmEvents.pageInfo.domain).to.equal(window.location.hostname); - expect(pmEvents.pageInfo.referrerDomain).to.equal(utils.parseUrl(document.referrer).hostname); - }); - }); -}); diff --git a/test/spec/modules/astraoneBidAdapter_spec.js b/test/spec/modules/astraoneBidAdapter_spec.js deleted file mode 100644 index 80d6dcdf6..000000000 --- a/test/spec/modules/astraoneBidAdapter_spec.js +++ /dev/null @@ -1,216 +0,0 @@ -import { expect } from 'chai' -import { spec } from 'modules/astraoneBidAdapter.js' - -function getSlotConfigs(mediaTypes, params) { - return { - params: params, - sizes: [], - bidId: '2df8c0733f284e', - bidder: 'astraone', - mediaTypes: mediaTypes, - ortb2Imp: { - ext: { - tid: '31a58515-3634-4e90-9c96-f86196db1459' - } - } - } -} - -describe('AstraOne Adapter', function() { - describe('isBidRequestValid method', function() { - const PLACE_ID = '5f477bf94d506ebe2c4240f3'; - const IMAGE_URL = 'https://creative.astraone.io/files/default_image-1-600x400.jpg'; - - describe('returns true', function() { - describe('when banner slot config has all mandatory params', () => { - describe('and placement has the correct value', function() { - const createBannerSlotConfig = placement => { - return getSlotConfigs( - { banner: {} }, - { - placeId: PLACE_ID, - imageUrl: IMAGE_URL, - placement - } - ) - } - const placements = ['inImage']; - placements.forEach(placement => { - it('should be ' + placement, function() { - const isBidRequestValid = spec.isBidRequestValid( - createBannerSlotConfig(placement) - ) - expect(isBidRequestValid).to.equal(true) - }) - }) - }) - }) - }) - describe('returns false', function() { - describe('when params are not correct', function() { - function createSlotconfig(params) { - return getSlotConfigs({ banner: {} }, params) - } - it('does not have the placeId.', function() { - const isBidRequestValid = spec.isBidRequestValid( - createSlotconfig({ - imageUrl: IMAGE_URL, - placement: 'inImage' - }) - ) - expect(isBidRequestValid).to.equal(false) - }) - it('does not have the imageUrl.', function() { - const isBidRequestValid = spec.isBidRequestValid( - createSlotconfig({ - placeId: PLACE_ID, - placement: 'inImage' - }) - ) - expect(isBidRequestValid).to.equal(false) - }) - it('does not have the placement.', function() { - const isBidRequestValid = spec.isBidRequestValid( - createSlotconfig({ - placeId: PLACE_ID, - imageUrl: IMAGE_URL, - }) - ) - expect(isBidRequestValid).to.equal(false) - }) - it('does not have a the correct placement.', function() { - const isBidRequestValid = spec.isBidRequestValid( - createSlotconfig({ - placeId: PLACE_ID, - imageUrl: IMAGE_URL, - placement: 'something' - }) - ) - expect(isBidRequestValid).to.equal(false) - }) - }) - }) - }) - - describe('buildRequests method', function() { - const bidderRequest = { - refererInfo: { referer: 'referer' } - } - const mandatoryParams = { - placeId: '5af45ad34d506ee7acad0c26', - imageUrl: 'https://creative.astraone.io/files/default_image-1-600x400.jpg', - placement: 'inImage' - } - const validBidRequests = [ - getSlotConfigs({ banner: {} }, mandatoryParams) - ] - it('Url params should be correct ', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest) - expect(request.method).to.equal('POST') - expect(request.url).to.equal('https://ssp.astraone.io/auction/prebid') - }) - - it('Common data request should be correct', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - expect(Array.isArray(data.bidRequests)).to.equal(true) - data.bidRequests.forEach(bid => { - expect(bid.placeId).to.equal('5af45ad34d506ee7acad0c26') - expect(typeof bid.imageUrl).to.equal('string') - }) - }) - - describe('GDPR params', function() { - describe('when there are not consent management platform', function() { - it('cmp should be false', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - expect(data.cmp).to.equal(false) - }) - }) - describe('when there are consent management platform', function() { - it('cmps should be true and ga should not sended, when gdprApplies is undefined', function() { - bidderRequest['gdprConsent'] = { - gdprApplies: undefined, - consentString: 'consentString' - } - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - expect(data.cmp).to.equal(true) - expect(Object.keys(data).indexOf('data')).to.equal(-1) - expect(data.cs).to.equal('consentString') - }) - it('cmps should be true and all gdpr parameters should be sended, when there are gdprApplies', function() { - bidderRequest['gdprConsent'] = { - gdprApplies: true, - consentString: 'consentString' - } - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - expect(data.cmp).to.equal(true) - expect(data.ga).to.equal(true) - expect(data.cs).to.equal('consentString') - }) - }) - }) - - describe('BidRequests params', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - const bidRequests = data.bidRequests - it('should request a Banner', function() { - const bannerBid = bidRequests[0] - expect(bannerBid.bidId).to.equal('2df8c0733f284e') - expect(bannerBid.transactionId).to.equal('31a58515-3634-4e90-9c96-f86196db1459') - expect(bannerBid.placeId).to.equal('5af45ad34d506ee7acad0c26') - }) - }) - }) - - describe('interpret response method', function() { - it('should return a void array, when the server response have not got bids.', function() { - const serverResponse = { - body: [] - } - const bids = spec.interpretResponse(serverResponse) - expect(Array.isArray(bids)).to.equal(true) - expect(bids.length).to.equal(0) - }) - describe('when the server response return a bid', function() { - describe('the bid is a banner', function() { - it('should return a banner bid', function() { - const serverResponse = { - body: { - bids: [ - { - bidId: '2df8c0733f284e', - price: 0.5, - currency: 'USD', - content: { - content: 'html', - actionUrls: {}, - seanceId: '123123' - }, - width: 100, - height: 100, - ttl: 360 - } - ] - } - } - const bids = spec.interpretResponse(serverResponse) - expect(bids.length).to.equal(1) - expect(bids[0].requestId).to.equal('2df8c0733f284e') - expect(bids[0].creativeId).to.equal('123123') - expect(bids[0].cpm).to.equal(0.5) - expect(bids[0].width).to.equal(100) - expect(bids[0].height).to.equal(100) - expect(bids[0].currency).to.equal('USD') - expect(bids[0].netRevenue).to.equal(true) - expect(typeof bids[0].ad).to.equal('string') - expect(typeof bids[0].content).to.equal('object') - }) - }) - }) - }) -}) diff --git a/test/spec/modules/atsAnalyticsAdapter_spec.js b/test/spec/modules/atsAnalyticsAdapter_spec.js deleted file mode 100644 index 4b8b908a7..000000000 --- a/test/spec/modules/atsAnalyticsAdapter_spec.js +++ /dev/null @@ -1,278 +0,0 @@ -import atsAnalyticsAdapter, {parseBrowser, analyticsUrl} from '../../../modules/atsAnalyticsAdapter.js'; -import { expect } from 'chai'; -import adapterManager from 'src/adapterManager.js'; -import {server} from '../../mocks/xhr.js'; - -import {getCoreStorageManager, getStorageManager} from '../../../src/storageManager.js'; - -import {EVENTS} from 'src/constants.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -const utils = require('src/utils'); -const events = require('src/events'); - -const storage = getCoreStorageManager(); -let sandbox; -let clock; -const now = new Date(); - -describe('ats analytics adapter', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - storage.setCookie('_lr_env_src_ats', 'true', 'Thu, 01 Jan 1970 00:00:01 GMT'); - sandbox = sinon.createSandbox(); - clock = sandbox.useFakeTimers(now.getTime()); - }); - - afterEach(function () { - events.getEvents.restore(); - atsAnalyticsAdapter.getUserAgent.restore(); - atsAnalyticsAdapter.disableAnalytics(); - Math.random.restore(); - sandbox.restore(); - clock.restore(); - }); - - describe('track', function () { - it('builds and sends request and response data', function () { - sinon.stub(Math, 'random').returns(0.99); - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); - - now.setTime(now.getTime() + 3600000); - storage.setCookie('_lr_env_src_ats', 'true', now.toUTCString()); - storage.setCookie('_lr_sampling_rate', '10', now.toUTCString()); - - this.timeout(2100); - - const initOptions = { - pid: '10433394' - }; - const auctionTimestamp = 1496510254326; - - // prepare general auction - request - const bidRequest = { - 'bidderCode': 'appnexus', - 'auctionStart': 1580739265161, - 'bids': [{ - 'bidder': 'appnexus', - 'params': { - 'placementId': '10433394' - }, - 'userId': { - 'idl_env': 'AmThEbO1ssIWjrNdU4noT4ZFBILSVBBYHbipOYt_JP40e5nZdXns2g' - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'transactionId': '2f481ff1-8d20-4c28-8e36-e384e9e3eec6', - 'sizes': '300x250,300x600', - 'bidId': '30c77d079cdf17' - }], - 'refererInfo': { - 'referer': 'https://example.com/dev' - }, - 'auctionId': 'a5b849e5-87d7-4205-8300-d063084fcfb7' - }; - // prepare general auction - response - const bidResponse = { - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '2eddfdc0c791dc', - 'mediaType': 'banner', - 'source': 'client', - 'requestId': '30c77d079cdf17', - 'cpm': 0.5, - 'creativeId': 29681110, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'auctionId': 'a5b849e5-87d7-4205-8300-d063084fcfb7', - 'responseTimestamp': 1580739791978, - 'requestTimestamp': 1580739265164, - 'bidder': 'appnexus', - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'timeToRespond': 2510, - 'size': '300x250' - }; - - // what we expect after general auction - const expectedAfterBid = { - 'Data': [{ - 'has_envelope': true, - 'adapter_version': 3, - 'bidder': 'appnexus', - 'bid_id': '30c77d079cdf17', - 'auction_id': 'a5b849e5-87d7-4205-8300-d063084fcfb7', - 'user_browser': parseBrowser(), - 'user_platform': navigator.platform, - 'auction_start': '2020-02-03T14:14:25.161Z', - 'domain': window.location.hostname, - 'envelope_source': true, - 'pid': '10433394', - 'response_time_stamp': '2020-02-03T14:23:11.978Z', - 'currency': 'USD', - 'cpm': 0.5, - 'net_revenue': true, - 'bid_won': true - }] - }; - - const wonRequest = { - 'adId': '2eddfdc0c791dc', - 'mediaType': 'banner', - 'requestId': '30c77d079cdf17', - 'cpm': 0.5, - 'creativeId': 29681110, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'auctionId': 'a5b849e5-87d7-4205-8300-d063084fcfb7', - 'statusMessage': 'Bid available', - 'responseTimestamp': 1633525319061, - 'requestTimestamp': 1633525319258, - 'bidder': 'appnexus', - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'size': '300x250', - 'status': 'rendered' - }; - - // lets simulate that some bidders timeout - const bidTimeoutArgsV1 = [ - { - bidId: '2baa51527bd015', - bidder: 'bidderOne', - adUnitCode: '/19968336/header-bid-tag-0', - auctionId: '66529d4c-8998-47c2-ab3e-5b953490b98f' - }, - { - bidId: '6fe3b4c2c23092', - bidder: 'bidderTwo', - adUnitCode: '/19968336/header-bid-tag-0', - auctionId: '66529d4c-8998-47c2-ab3e-5b953490b98f' - } - ]; - - adapterManager.registerAnalyticsAdapter({ - code: 'atsAnalytics', - adapter: atsAnalyticsAdapter - }); - - adapterManager.enableAnalytics({ - provider: 'atsAnalytics', - options: initOptions - }); - - // Step 1: Send auction init event - events.emit(EVENTS.AUCTION_INIT, { - timestamp: auctionTimestamp - }); - // Step 2: Send bid requested event - events.emit(EVENTS.BID_REQUESTED, bidRequest); - - // Step 3: Send bid response event - events.emit(EVENTS.BID_RESPONSE, bidResponse); - - // Step 4: Send bid time out event - events.emit(EVENTS.BID_TIMEOUT, bidTimeoutArgsV1); - - // Step 5: Send auction end event - events.emit(EVENTS.AUCTION_END, {}); - // Step 6: Send bid won event - events.emit(EVENTS.BID_WON, wonRequest); - - sandbox.stub(getGlobal(), 'getAllWinningBids').callsFake((key) => { - return [wonRequest] - }); - - clock.tick(2000); - - const requests = server.requests.filter(req => { - return req.url.indexOf(analyticsUrl) > -1; - }); - - expect(requests.length).to.equal(1); - - const realAfterBid = JSON.parse(requests[0].requestBody); - - // Step 7: assert real data after bid and expected data - expect(realAfterBid['Data']).to.deep.equal(expectedAfterBid['Data']); - - // check that the publisher ID is configured via options - expect(atsAnalyticsAdapter.context.pid).to.equal(initOptions.pid); - }) - it('check browser is safari', function () { - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); - sinon.stub(Math, 'random').returns(0.99); - const browser = parseBrowser(); - expect(browser).to.equal('Safari'); - }) - it('check browser is chrome', function () { - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/80.0.3987.95 Mobile/15E148 Safari/604.1'); - sinon.stub(Math, 'random').returns(0.99); - const browser = parseBrowser(); - expect(browser).to.equal('Chrome'); - }) - it('check browser is edge', function () { - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.74 Safari/537.36 Edg/79.0.309.43'); - sinon.stub(Math, 'random').returns(0.99); - const browser = parseBrowser(); - expect(browser).to.equal('Microsoft Edge'); - }) - it('check browser is firefox', function () { - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (iPhone; CPU OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) FxiOS/23.0 Mobile/15E148 Safari/605.1.15'); - sinon.stub(Math, 'random').returns(0.99); - const browser = parseBrowser(); - expect(browser).to.equal('Firefox'); - }) - it('check browser is unknown', function () { - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns(undefined); - sinon.stub(Math, 'random').returns(0.99); - const browser = parseBrowser(); - expect(browser).to.equal('Unknown'); - }) - it('should not fire analytics request if sampling rate is 0', function () { - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); - sinon.stub(Math, 'random').returns(0.99); - const result = atsAnalyticsAdapter.shouldFireRequest(0); - expect(result).to.equal(false); - }) - it('should fire analytics request', function () { - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); - sinon.stub(Math, 'random').returns(0.99); - // publisher can try to pass anything they want but we will set sampling rate to 100, which means we will have 1% of requests - const result = atsAnalyticsAdapter.shouldFireRequest(8); - expect(result).to.equal(true); - }) - it('should not fire analytics request if math random is something other then 0.99', function () { - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); - sinon.stub(Math, 'random').returns(0.98); - // publisher can try to pass anything they want but we will set sampling rate to 100, which means we will have 1% of requests - const result = atsAnalyticsAdapter.shouldFireRequest(10); - expect(result).to.equal(false); - }) - - it('should set cookie value to 10 for _lr_sampling_rate', function () { - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); - sinon.stub(Math, 'random').returns(0.99); - atsAnalyticsAdapter.setSamplingCookie(10); - const samplingRate = storage.getCookie('_lr_sampling_rate'); - expect(samplingRate).to.equal('10'); - }) - - it('should set cookie value to 0 for _lr_sampling_rate', function () { - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); - sinon.stub(Math, 'random').returns(0.99); - atsAnalyticsAdapter.setSamplingCookie(0); - const samplingRate = storage.getCookie('_lr_sampling_rate'); - expect(samplingRate).to.equal('0'); - }) - - it('enable analytics', function () { - sandbox.stub(utils, 'logError'); - sinon.stub(atsAnalyticsAdapter, 'getUserAgent').returns('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_5) AppleWebKit/536.25 (KHTML, like Gecko) Version/6.0 Safari/536.25'); - sinon.stub(Math, 'random').returns(0.99); - atsAnalyticsAdapter.enableAnalytics({ - options: {} - }); - expect(utils.logError.called).to.equal(true); - }) - }) -}) diff --git a/test/spec/modules/audiencerunBidAdapter_spec.js b/test/spec/modules/audiencerunBidAdapter_spec.js deleted file mode 100644 index 56fdaef63..000000000 --- a/test/spec/modules/audiencerunBidAdapter_spec.js +++ /dev/null @@ -1,337 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/audiencerunBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; - -const ENDPOINT = 'https://d.audiencerun.com/prebid'; - -const BID_SERVER_RESPONSE = { - body: { - bid: [ - { - bidId: '51ef8751f9aead', - zoneId: '12345abcde', - crid: '5678', - cpm: 8.0219519, - currency: 'USD', - w: 728, - h: 90, - isNet: false, - buying_type: 'rtb', - syncUrl: 'https://ac.audiencerun.com/f/sync.html', - adm: '', - adomain: ['example.com'], - }, - ], - }, -}; - -describe('AudienceRun bid adapter tests', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - bidder: 'audiencerun', - params: { - zoneId: '12345abcde', - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - }, - }, - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - creativeId: 'er2ee', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when zoneId is valid', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - zoneId: '12345abcde', - }; - - expect(spec.isBidRequestValid(invalidBid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - - invalidBid.params = {}; - - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - bidder: 'audiencerun', - bidId: '51ef8751f9aead', - params: { - zoneId: '12345abcde', - }, - adUnitCode: 'div-gpt-ad-1460505748561-0', - transactionId: 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - mediaTypes: { - banner: { - sizes: [ - [320, 50], - [300, 250], - [300, 600], - ], - }, - }, - bidderRequestId: '418b37f85e772c', - auctionId: '18fd8b8b0bd757', - bidRequestsCount: 1, - }, - ]; - const bidRequest = bidRequests[0]; - - it('sends a valid bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, { - gdprConsent: { - consentString: - 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true, - }, - refererInfo: { - canonicalUrl: undefined, - page: 'https://example.com', - topmostLocation: 'https://example.com', - numIframes: 0, - reachedTop: true, - }, - }); - - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - - const payload = JSON.parse(request.data); - expect(payload.gdpr).to.exist; - - expect(payload.bids) - .to.exist.and.to.be.an('array') - .and.to.have.lengthOf(1); - expect(payload.referer).to.exist; - - const bid = payload.bids[0]; - expect(bid).to.exist; - expect(bid).to.have.property('bidId'); - expect(bid).to.have.property('zoneId'); - expect(bid).to.have.property('sizes'); - expect(bid.sizes[0].w).to.be.a('number'); - expect(bid.sizes[0].h).to.be.a('number'); - }); - - it('should send GDPR to endpoint and honor gdprApplies value', function () { - const consentString = 'bogusConsent'; - const bidderRequest = { - gdprConsent: { - consentString: consentString, - gdprApplies: true, - }, - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.gdpr).to.exist; - expect(payload.gdpr.consent).to.equal(consentString); - expect(payload.gdpr.applies).to.equal(true); - - const bidderRequest2 = { - gdprConsent: { - consentString: consentString, - gdprApplies: false, - }, - }; - - const request2 = spec.buildRequests(bidRequests, bidderRequest2); - const payload2 = JSON.parse(request2.data); - - expect(payload2.gdpr).to.exist; - expect(payload2.gdpr.consent).to.equal(consentString); - expect(payload2.gdpr.applies).to.equal(false); - }); - - it('should use the auctionUrl passed from bid params', function () { - const bid = Object.assign({}, bidRequest, { - params: { - zoneId: '12345abcde', - auctionUrl: 'https://auction.url.audiencerun.com', - }, - }); - const request = spec.buildRequests([bid]); - - expect(request.url).to.exist; - expect(request.url).to.equal('https://auction.url.audiencerun.com'); - }); - - it('should use a bidfloor with a 0 value', function () { - const bid = Object.assign({}, bidRequest); - const request = spec.buildRequests([bid]); - const payload = JSON.parse(request.data); - expect(payload.bids[0].bidfloor).to.exist.and.to.equal(0); - }); - - it('should use bidfloor param value', function () { - const bid = Object.assign({}, bidRequest, { - params: { - bidfloor: 0.2, - }, - }); - const request = spec.buildRequests([bid]); - const payload = JSON.parse(request.data); - expect(payload.bids[0].bidfloor).to.exist.and.to.equal(0.2); - }); - - it('should use floors module value', function () { - const bid = Object.assign({}, bidRequest, { - params: { - bidfloor: 0.5, - }, - }); - bid.getFloor = () => { - return { floor: 1, currency: 'USD' }; - }; - const request = spec.buildRequests([bid]); - const payload = JSON.parse(request.data); - expect(payload.bids[0].bidfloor).to.exist.and.to.equal(1); - }); - - it('should add userid eids information to the request', function () { - const bid = Object.assign({}, bidRequest); - bid.userIdAsEids = [ - { - source: 'pubcid.org', - uids: [ - { - atype: 1, - id: '01EAJWWNEPN3CYMM5N8M5VXY22', - }, - ], - }, - ]; - - const request = spec.buildRequests([bid]); - const payload = JSON.parse(request.data); - - expect(payload.userId).to.exist; - expect(payload.userId).to.deep.equal(bid.userIdAsEids); - }); - - it('should add schain object if available', function() { - const bid = Object.assign({}, bidRequest) - bid.ortb2 = { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'directseller.com', - sid: '00001', - rid: 'BidRequest1', - hp: 1, - }, - ], - } - } - } - }; - - const request = spec.buildRequests([bid]); - const payload = JSON.parse(request.data); - - expect(payload.schain).to.exist; - expect(payload.schain).to.deep.equal({ - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'directseller.com', - sid: '00001', - rid: 'BidRequest1', - hp: 1, - }, - ], - }); - }) - }); - - describe('interpretResponse', function () { - const expectedResponse = [ - { - requestId: '51ef8751f9aead', - cpm: 8.0219519, - width: '728', - height: '90', - creativeId: '5678', - currency: 'USD', - netRevenue: false, - ttl: 300, - ad: '', - mediaType: 'banner', - meta: { - advertiserDomains: ['example.com'], - }, - }, - ]; - - it('should get the correct bid response by display ad', function () { - const result = spec.interpretResponse(BID_SERVER_RESPONSE); - expect(Object.keys(result[0])).to.have.members( - Object.keys(expectedResponse[0]) - ); - }); - - it('should handle empty bid response', function () { - const response = { - body: {}, - }; - const result = spec.interpretResponse(response); - expect(result.length).to.equal(0); - }); - }); - - describe('getUserSyncs', function () { - const serverResponses = [BID_SERVER_RESPONSE]; - const syncOptions = { iframeEnabled: true }; - - it('should return empty if no server responses', function () { - const syncs = spec.getUserSyncs(syncOptions, []); - expect(syncs).to.deep.equal([]); - }); - - it('should return user syncs', function () { - const syncs = spec.getUserSyncs(syncOptions, serverResponses); - expect(syncs).to.deep.equal([ - { type: 'iframe', url: 'https://ac.audiencerun.com/f/sync.html' }, - ]); - }); - }); - - describe('onTimeout', function () { - it('should exists and be a function', () => { - expect(spec.onTimeout).to.exist.and.to.be.a('function'); - }); - }); -}); diff --git a/test/spec/modules/automatadAnalyticsAdapter_spec.js b/test/spec/modules/automatadAnalyticsAdapter_spec.js deleted file mode 100644 index 9a7e6b13a..000000000 --- a/test/spec/modules/automatadAnalyticsAdapter_spec.js +++ /dev/null @@ -1,620 +0,0 @@ -import * as events from 'src/events'; -import * as utils from 'src/utils.js'; - -import spec, {self as exports} from 'modules/automatadAnalyticsAdapter.js'; - -import { EVENTS } from 'src/constants.js'; -import { expect } from 'chai'; - -const obj = { - auctionInitHandler: (args) => {}, - bidResponseHandler: (args) => {}, - bidderDoneHandler: (args) => {}, - bidWonHandler: (args) => {}, - noBidHandler: (args) => {}, - auctionDebugHandler: (args) => {}, - bidderTimeoutHandler: (args) => {}, - bidRequestedHandler: (args) => {}, - bidRejectedHandler: (args) => {} -} - -const { - AUCTION_DEBUG, - BID_REQUESTED, - BID_REJECTED, - AUCTION_INIT, - BIDDER_DONE, - BID_RESPONSE, - BID_TIMEOUT, - BID_WON, - NO_BID -} = EVENTS - -const CONFIG_WITH_DEBUG = { - provider: 'atmtdAnalyticsAdapter', - options: { - publisherID: '230', - siteID: '421' - }, - includeEvents: [AUCTION_DEBUG, AUCTION_INIT, BIDDER_DONE, BID_RESPONSE, BID_TIMEOUT, NO_BID, BID_WON, BID_REQUESTED, BID_REJECTED] -} - -describe('Automatad Analytics Adapter', () => { - var sandbox, clock; - - describe('Adapter Setup Configuration', () => { - beforeEach(() => { - sandbox = sinon.createSandbox(); - sandbox.stub(utils, 'logMessage') - sandbox.stub(events, 'getEvents').returns([]); - sandbox.stub(utils, 'logError'); - }); - afterEach(() => { - sandbox.restore(); - }); - - it('Should log error and return false if nothing is passed as the param in the enable analytics call', () => { - spec.enableAnalytics() - - expect(utils.logError.called).to.equal(true) - }); - - it('Should log error and return false if object type is not passed as the param in the enable analytics call', () => { - spec.enableAnalytics('hello world') - - expect(utils.logError.called).to.equal(true) - }); - - it('Should log error and return false if options is not defined in the enable analytics call', () => { - spec.enableAnalytics({ - provider: 'atmtdAnalyticsAdapter' - }) - - expect(utils.logError.called).to.equal(true) - }); - it('Should log error and return false if pub id is not defined in the enable analytics call', () => { - spec.enableAnalytics({ - provider: 'atmtdAnalyticsAdapter', - options: { - siteID: '230' - } - }) - - expect(utils.logError.called).to.equal(true) - }); - it('Should log error and return false if pub id is not defined in the enable analytics call', () => { - spec.enableAnalytics({ - provider: 'atmtdAnalyticsAdapter', - options: { - publisherID: '230' - } - }) - - expect(utils.logError.called).to.equal(true) - }); - it('Should successfully configure the adapter and set global log debug messages flag to false', () => { - spec.enableAnalytics({ - provider: 'atmtdAnalyticsAdapter', - options: { - publisherID: '230', - siteID: '421', - logDebug: false - } - }); - expect(utils.logError.called).to.equal(false) - expect(utils.logMessage.called).to.equal(true) - spec.disableAnalytics(); - }); - it('Should successfully configure the adapter and set global log debug messages flag to true', () => { - sandbox.stub(exports, 'initializeQueue').callsFake(() => {}); - sandbox.stub(exports, 'addGPTHandlers').callsFake(() => {}); - const config = { - provider: 'atmtdAnalyticsAdapter', - options: { - publisherID: '230', - siteID: '410', - logDebug: true - } - } - - spec.enableAnalytics(config) - expect(utils.logError.called).to.equal(false) - expect(exports.initializeQueue.called).to.equal(true) - expect(exports.addGPTHandlers.called).to.equal(true) - expect(utils.logMessage.called).to.equal(true) - spec.disableAnalytics(); - }); - }); - - describe('Behaviour of the adapter when the sdk has loaded', () => { - before(() => { - spec.enableAnalytics(CONFIG_WITH_DEBUG); - - global.window.atmtdAnalytics = obj - exports.qBeingUsed = false - exports.qTraversalComplete = undefined - Object.keys(obj).forEach((fn) => sandbox.spy(global.window.atmtdAnalytics, fn)) - }) - beforeEach(() => { - sandbox = sinon.createSandbox(); - sandbox.stub(events, 'getEvents').returns([]); - sandbox.stub(utils, 'logMessage'); - sandbox.stub(utils, 'logError'); - }); - afterEach(() => { - sandbox.restore(); - }); - after(() => { - const handlers = global.window.atmtdAnalytics - Object.keys(handlers).forEach((handler) => global.window.atmtdAnalytics[handler].resetHistory()) - global.window.atmtdAnalytics = undefined; - spec.disableAnalytics(); - exports.qBeingUsed = false - exports.qTraversalComplete = undefined - }) - - it('Should call the auctionInitHandler when the auction init event is fired', () => { - events.emit(AUCTION_INIT, {type: AUCTION_INIT}) - expect(global.window.atmtdAnalytics.auctionInitHandler.called).to.equal(true) - }); - - it('Should call the bidRequested when the bidRequested event is fired', () => { - events.emit(BID_REQUESTED, {type: BID_REQUESTED}) - expect(global.window.atmtdAnalytics.bidRequestedHandler.called).to.equal(true) - }); - - it('Should call the bidRejected when the bidRejected event is fired', () => { - events.emit(BID_REJECTED, {type: BID_REJECTED}) - expect(global.window.atmtdAnalytics.bidRejectedHandler.called).to.equal(true) - }); - - it('Should call the bidResponseHandler when the bidResponse event is fired', () => { - events.emit(BID_RESPONSE, {type: BID_RESPONSE}) - expect(global.window.atmtdAnalytics.bidResponseHandler.called).to.equal(true) - }); - - it('Should call the bidderDoneHandler when the bidderDone event is fired', () => { - events.emit(BIDDER_DONE, {type: BIDDER_DONE}) - expect(global.window.atmtdAnalytics.bidderDoneHandler.called).to.equal(true) - }); - - it('Should call the bidWonHandler when the bidWon event is fired', () => { - events.emit(BID_WON, {type: BID_WON}) - expect(global.window.atmtdAnalytics.bidWonHandler.called).to.equal(true) - }); - - it('Should call the noBidHandler when the noBid event is fired', () => { - events.emit(NO_BID, {type: NO_BID}) - expect(global.window.atmtdAnalytics.noBidHandler.called).to.equal(true) - }); - - it('Should call the bidTimeoutHandler when the bidTimeout event is fired', () => { - events.emit(BID_TIMEOUT, {type: BID_TIMEOUT}) - expect(global.window.atmtdAnalytics.bidderTimeoutHandler.called).to.equal(true) - }); - - it('Should call the auctionDebugHandler when the auctionDebug event is fired', () => { - events.emit(AUCTION_DEBUG, {type: AUCTION_DEBUG}) - expect(global.window.atmtdAnalytics.auctionDebugHandler.called).to.equal(true) - }); - }); - - describe('Behaviour of the adapter when the SDK has not loaded', () => { - before(() => { - spec.enableAnalytics(CONFIG_WITH_DEBUG); - }) - beforeEach(() => { - sandbox = sinon.createSandbox(); - sandbox.stub(events, 'getEvents').returns([]); - sandbox.stub(utils, 'logMessage'); - sandbox.stub(utils, 'logError'); - - global.window.atmtdAnalytics = undefined - exports.__atmtdAnalyticsQueue.length = 0 - sandbox.stub(exports.__atmtdAnalyticsQueue, 'push').callsFake((args) => { - Array.prototype.push.apply(exports.__atmtdAnalyticsQueue, [args]); - }) - }); - afterEach(() => { - sandbox.restore(); - }); - after(() => { - spec.disableAnalytics(); - }) - - it('Should push to the que when the auctionInit event is fired', () => { - events.emit(AUCTION_INIT, {type: AUCTION_INIT}) - expect(exports.__atmtdAnalyticsQueue.push.called).to.equal(true) - expect(exports.__atmtdAnalyticsQueue).to.be.an('array').to.have.lengthOf(1) - expect(exports.__atmtdAnalyticsQueue[0]).to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue[0][0]).to.equal(AUCTION_INIT) - expect(exports.__atmtdAnalyticsQueue[0][1].type).to.equal(AUCTION_INIT) - }); - - it('Should push to the que when the bidResponse event is fired', () => { - events.emit(BID_RESPONSE, {type: BID_RESPONSE}) - expect(exports.__atmtdAnalyticsQueue.push.called).to.equal(true) - expect(exports.__atmtdAnalyticsQueue).to.be.an('array').to.have.lengthOf(1) - expect(exports.__atmtdAnalyticsQueue[0]).to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue[0][0]).to.equal(BID_RESPONSE) - expect(exports.__atmtdAnalyticsQueue[0][1].type).to.equal(BID_RESPONSE) - }); - - it('Should push to the que when the bidRequested event is fired', () => { - events.emit(BID_REQUESTED, {type: BID_REQUESTED}) - expect(exports.__atmtdAnalyticsQueue.push.called).to.equal(true) - expect(exports.__atmtdAnalyticsQueue).to.be.an('array').to.have.lengthOf(1) - expect(exports.__atmtdAnalyticsQueue[0]).to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue[0][0]).to.equal(BID_REQUESTED) - expect(exports.__atmtdAnalyticsQueue[0][1].type).to.equal(BID_REQUESTED) - }); - - it('Should push to the que when the bidRejected event is fired', () => { - events.emit(BID_REJECTED, {type: BID_REJECTED}) - expect(exports.__atmtdAnalyticsQueue.push.called).to.equal(true) - expect(exports.__atmtdAnalyticsQueue).to.be.an('array').to.have.lengthOf(1) - expect(exports.__atmtdAnalyticsQueue[0]).to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue[0][0]).to.equal(BID_REJECTED) - expect(exports.__atmtdAnalyticsQueue[0][1].type).to.equal(BID_REJECTED) - }); - - it('Should push to the que when the bidderDone event is fired', () => { - events.emit(BIDDER_DONE, {type: BIDDER_DONE}) - expect(exports.__atmtdAnalyticsQueue.push.called).to.equal(true) - expect(exports.__atmtdAnalyticsQueue).to.be.an('array').to.have.lengthOf(1) - expect(exports.__atmtdAnalyticsQueue[0]).to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue[0][0]).to.equal(BIDDER_DONE) - expect(exports.__atmtdAnalyticsQueue[0][1].type).to.equal(BIDDER_DONE) - }); - - it('Should push to the que when the bidWon event is fired', () => { - events.emit(BID_WON, {type: BID_WON}) - expect(exports.__atmtdAnalyticsQueue.push.called).to.equal(true) - expect(exports.__atmtdAnalyticsQueue).to.be.an('array').to.have.lengthOf(1) - expect(exports.__atmtdAnalyticsQueue[0]).to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue[0][0]).to.equal(BID_WON) - expect(exports.__atmtdAnalyticsQueue[0][1].type).to.equal(BID_WON) - }); - - it('Should push to the que when the noBid event is fired', () => { - events.emit(NO_BID, {type: NO_BID}) - expect(exports.__atmtdAnalyticsQueue.push.called).to.equal(true) - expect(exports.__atmtdAnalyticsQueue).to.be.an('array').to.have.lengthOf(1) - expect(exports.__atmtdAnalyticsQueue[0]).to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue[0][0]).to.equal(NO_BID) - expect(exports.__atmtdAnalyticsQueue[0][1].type).to.equal(NO_BID) - }); - - it('Should push to the que when the auctionDebug is fired', () => { - events.emit(AUCTION_DEBUG, {type: AUCTION_DEBUG}) - expect(exports.__atmtdAnalyticsQueue.push.called).to.equal(true) - expect(exports.__atmtdAnalyticsQueue).to.be.an('array').to.have.lengthOf(1) - expect(exports.__atmtdAnalyticsQueue[0]).to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue[0][0]).to.equal(AUCTION_DEBUG) - expect(exports.__atmtdAnalyticsQueue[0][1].type).to.equal(AUCTION_DEBUG) - }); - - it('Should push to the que when the bidderTimeout event is fired', () => { - events.emit(BID_TIMEOUT, {type: BID_TIMEOUT}) - expect(exports.__atmtdAnalyticsQueue.push.called).to.equal(true) - expect(exports.__atmtdAnalyticsQueue).to.be.an('array').to.have.lengthOf(1) - expect(exports.__atmtdAnalyticsQueue[0]).to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue[0][0]).to.equal(BID_TIMEOUT) - expect(exports.__atmtdAnalyticsQueue[0][1].type).to.equal(BID_TIMEOUT) - }); - }); - - describe('Behaviour of the adapter when the SDK has loaded midway', () => { - before(() => { - spec.enableAnalytics(CONFIG_WITH_DEBUG); - }) - beforeEach(() => { - sandbox = sinon.createSandbox(); - - global.window.atmtdAnalytics = undefined - - exports.qBeingUsed = undefined - exports.qTraversalComplete = undefined - exports.queuePointer = 0 - exports.retryCount = 0 - exports.__atmtdAnalyticsQueue.length = 0 - - clock = sandbox.useFakeTimers(); - - sandbox.spy(exports.__atmtdAnalyticsQueue, 'push') - }); - afterEach(() => { - sandbox.restore(); - }); - after(() => { - spec.disableAnalytics(); - }) - - it('Should push to the que when the auctionInit event is fired and push to the que even after SDK has loaded after auctionInit event', () => { - events.emit(BID_RESPONSE, {type: BID_RESPONSE}) - expect(exports.__atmtdAnalyticsQueue.push.called).to.equal(true) - expect(exports.__atmtdAnalyticsQueue).to.be.an('array').to.have.lengthOf(1) - expect(exports.__atmtdAnalyticsQueue[0]).to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue[0][0]).to.equal(BID_RESPONSE) - expect(exports.__atmtdAnalyticsQueue[0][1].type).to.equal(BID_RESPONSE) - expect(exports.qBeingUsed).to.equal(true) - expect(exports.qTraversalComplete).to.equal(undefined) - global.window.atmtdAnalytics = obj - events.emit(BID_RESPONSE, {type: BID_RESPONSE}) - expect(exports.__atmtdAnalyticsQueue.push.calledTwice).to.equal(true) - expect(exports.__atmtdAnalyticsQueue).to.be.an('array').to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue[1]).to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue[1][0]).to.equal(BID_RESPONSE) - expect(exports.__atmtdAnalyticsQueue[1][1].type).to.equal(BID_RESPONSE) - expect(exports.qBeingUsed).to.equal(true) - expect(exports.qTraversalComplete).to.equal(undefined) - }); - - it('Should push to the que when the auctionInit event is fired and push to the analytics adapter handler after the que is processed', () => { - expect(exports.qBeingUsed).to.equal(undefined) - events.emit(AUCTION_INIT, {type: AUCTION_INIT}) - global.window.atmtdAnalytics = {...obj} - const handlers = global.window.atmtdAnalytics - Object.keys(handlers).forEach((handler) => global.window.atmtdAnalytics[handler].resetHistory()) - expect(exports.__atmtdAnalyticsQueue.push.called).to.equal(true) - expect(exports.__atmtdAnalyticsQueue).to.be.an('array').to.have.lengthOf(1) - expect(exports.__atmtdAnalyticsQueue[0]).to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue[0][0]).to.equal(AUCTION_INIT) - expect(exports.__atmtdAnalyticsQueue[0][1].type).to.equal(AUCTION_INIT) - expect(exports.qBeingUsed).to.equal(true) - expect(exports.qTraversalComplete).to.equal(undefined) - expect(global.window.atmtdAnalytics.auctionInitHandler.callCount).to.equal(0) - clock.tick(2000) - expect(exports.qBeingUsed).to.equal(true) - expect(exports.qTraversalComplete).to.equal(undefined) - events.emit(NO_BID, {type: NO_BID}) - expect(exports.__atmtdAnalyticsQueue).to.be.an('array').to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue.push.calledTwice).to.equal(true) - clock.tick(1500) - expect(exports.qBeingUsed).to.equal(false) - expect(exports.qTraversalComplete).to.equal(true) - events.emit(BID_RESPONSE, {type: BID_RESPONSE}) - expect(exports.__atmtdAnalyticsQueue).to.be.an('array').to.have.lengthOf(2) - expect(exports.__atmtdAnalyticsQueue.push.calledTwice).to.equal(true) - expect(exports.__atmtdAnalyticsQueue.push.calledThrice).to.equal(false) - expect(global.window.atmtdAnalytics.auctionInitHandler.calledOnce).to.equal(true) - expect(global.window.atmtdAnalytics.noBidHandler.calledOnce).to.equal(true) - expect(global.window.atmtdAnalytics.bidResponseHandler.calledOnce).to.equal(true) - }); - }); - - describe('Process Events from Que when SDK still has not loaded', () => { - before(() => { - spec.enableAnalytics({ - provider: 'atmtdAnalyticsAdapter', - options: { - publisherID: '230', - siteID: '421' - } - }); - global.window.atmtdAnalytics = undefined - - sandbox.stub(exports.__atmtdAnalyticsQueue, 'push').callsFake((args) => { - Array.prototype.push.apply(exports.__atmtdAnalyticsQueue, [args]); - }) - exports.queuePointer = 0; - exports.retryCount = 0; - }) - beforeEach(() => { - sandbox = sinon.createSandbox(); - sandbox.stub(events, 'getEvents').returns([]); - sandbox.spy(exports, 'prettyLog') - sandbox.spy(exports, 'processEvents') - - clock = sandbox.useFakeTimers(); - exports.__atmtdAnalyticsQueue.length = 0 - }); - afterEach(() => { - sandbox.restore(); - exports.queuePointer = 0; - exports.retryCount = 0; - spec.disableAnalytics(); - }) - - it('Should retry processing auctionInit in certain intervals', () => { - expect(exports.queuePointer).to.equal(0) - expect(exports.retryCount).to.equal(0) - const que = [[AUCTION_INIT, {type: AUCTION_INIT}]] - exports.__atmtdAnalyticsQueue.push(que[0]) - exports.processEvents() - expect(exports.prettyLog.getCall(0).args[0]).to.equal('status') - expect(exports.prettyLog.getCall(0).args[1]).to.equal(`Que has been inactive for a while. Adapter starting to process que now... Trial Count = 1`) - expect(exports.prettyLog.getCall(1).args[0]).to.equal('warn') - expect(exports.prettyLog.getCall(1).args[1]).to.equal(`Adapter failed to process event as aggregator has not loaded. Retrying in 1500ms ...`) - clock.tick(1510) - expect(exports.prettyLog.getCall(2).args[0]).to.equal('status') - expect(exports.prettyLog.getCall(2).args[1]).to.equal(`Que has been inactive for a while. Adapter starting to process que now... Trial Count = 2`) - expect(exports.prettyLog.getCall(3).args[0]).to.equal('warn') - expect(exports.prettyLog.getCall(3).args[1]).to.equal(`Adapter failed to process event as aggregator has not loaded. Retrying in 3000ms ...`) - clock.tick(3010) - expect(exports.prettyLog.getCall(4).args[0]).to.equal('status') - expect(exports.prettyLog.getCall(4).args[1]).to.equal(`Que has been inactive for a while. Adapter starting to process que now... Trial Count = 3`) - expect(exports.prettyLog.getCall(5).args[0]).to.equal('warn') - expect(exports.prettyLog.getCall(5).args[1]).to.equal(`Adapter failed to process event as aggregator has not loaded. Retrying in 5000ms ...`) - clock.tick(5010) - expect(exports.prettyLog.getCall(6).args[0]).to.equal('status') - expect(exports.prettyLog.getCall(6).args[1]).to.equal(`Que has been inactive for a while. Adapter starting to process que now... Trial Count = 4`) - expect(exports.prettyLog.getCall(7).args[0]).to.equal('warn') - expect(exports.prettyLog.getCall(7).args[1]).to.equal(`Adapter failed to process event as aggregator has not loaded. Retrying in 10000ms ...`) - clock.tick(10010) - expect(exports.prettyLog.getCall(8).args[0]).to.equal('error') - expect(exports.prettyLog.getCall(8).args[1]).to.equal(`Aggregator still hasn't loaded. Processing que stopped`) - expect(exports.queuePointer).to.equal(0) - expect(exports.processEvents.callCount).to.equal(5) - }) - - it('Should retry processing slotRenderEnded in certain intervals', () => { - expect(exports.queuePointer).to.equal(0) - expect(exports.retryCount).to.equal(0) - const que = [['slotRenderEnded', {type: 'slotRenderEnded'}]] - exports.__atmtdAnalyticsQueue.push(que[0]) - exports.processEvents() - expect(exports.prettyLog.getCall(0).args[0]).to.equal('status') - expect(exports.prettyLog.getCall(0).args[1]).to.equal(`Que has been inactive for a while. Adapter starting to process que now... Trial Count = 1`) - expect(exports.prettyLog.getCall(1).args[0]).to.equal('warn') - expect(exports.prettyLog.getCall(1).args[1]).to.equal(`Adapter failed to process event as aggregator has not loaded. Retrying in 1500ms ...`) - clock.tick(1510) - expect(exports.prettyLog.getCall(2).args[0]).to.equal('status') - expect(exports.prettyLog.getCall(2).args[1]).to.equal(`Que has been inactive for a while. Adapter starting to process que now... Trial Count = 2`) - expect(exports.prettyLog.getCall(3).args[0]).to.equal('warn') - expect(exports.prettyLog.getCall(3).args[1]).to.equal(`Adapter failed to process event as aggregator has not loaded. Retrying in 3000ms ...`) - clock.tick(3010) - expect(exports.prettyLog.getCall(4).args[0]).to.equal('status') - expect(exports.prettyLog.getCall(4).args[1]).to.equal(`Que has been inactive for a while. Adapter starting to process que now... Trial Count = 3`) - expect(exports.prettyLog.getCall(5).args[0]).to.equal('warn') - expect(exports.prettyLog.getCall(5).args[1]).to.equal(`Adapter failed to process event as aggregator has not loaded. Retrying in 5000ms ...`) - clock.tick(5010) - expect(exports.prettyLog.getCall(6).args[0]).to.equal('status') - expect(exports.prettyLog.getCall(6).args[1]).to.equal(`Que has been inactive for a while. Adapter starting to process que now... Trial Count = 4`) - expect(exports.prettyLog.getCall(7).args[0]).to.equal('warn') - expect(exports.prettyLog.getCall(7).args[1]).to.equal(`Adapter failed to process event as aggregator has not loaded. Retrying in 10000ms ...`) - clock.tick(10010) - expect(exports.prettyLog.getCall(8).args[0]).to.equal('error') - expect(exports.prettyLog.getCall(8).args[1]).to.equal(`Aggregator still hasn't loaded. Processing que stopped`) - expect(exports.queuePointer).to.equal(0) - expect(exports.processEvents.callCount).to.equal(5) - }) - - it('Should retry processing impressionViewable in certain intervals', () => { - expect(exports.queuePointer).to.equal(0) - expect(exports.retryCount).to.equal(0) - const que = [['impressionViewable', {type: 'impressionViewable'}]] - exports.__atmtdAnalyticsQueue.push(que[0]) - exports.processEvents() - expect(exports.prettyLog.getCall(0).args[0]).to.equal('status') - expect(exports.prettyLog.getCall(0).args[1]).to.equal(`Que has been inactive for a while. Adapter starting to process que now... Trial Count = 1`) - expect(exports.prettyLog.getCall(1).args[0]).to.equal('warn') - expect(exports.prettyLog.getCall(1).args[1]).to.equal(`Adapter failed to process event as aggregator has not loaded. Retrying in 1500ms ...`) - clock.tick(1510) - expect(exports.prettyLog.getCall(2).args[0]).to.equal('status') - expect(exports.prettyLog.getCall(2).args[1]).to.equal(`Que has been inactive for a while. Adapter starting to process que now... Trial Count = 2`) - expect(exports.prettyLog.getCall(3).args[0]).to.equal('warn') - expect(exports.prettyLog.getCall(3).args[1]).to.equal(`Adapter failed to process event as aggregator has not loaded. Retrying in 3000ms ...`) - clock.tick(3010) - expect(exports.prettyLog.getCall(4).args[0]).to.equal('status') - expect(exports.prettyLog.getCall(4).args[1]).to.equal(`Que has been inactive for a while. Adapter starting to process que now... Trial Count = 3`) - expect(exports.prettyLog.getCall(5).args[0]).to.equal('warn') - expect(exports.prettyLog.getCall(5).args[1]).to.equal(`Adapter failed to process event as aggregator has not loaded. Retrying in 5000ms ...`) - clock.tick(5010) - expect(exports.prettyLog.getCall(6).args[0]).to.equal('status') - expect(exports.prettyLog.getCall(6).args[1]).to.equal(`Que has been inactive for a while. Adapter starting to process que now... Trial Count = 4`) - expect(exports.prettyLog.getCall(7).args[0]).to.equal('warn') - expect(exports.prettyLog.getCall(7).args[1]).to.equal(`Adapter failed to process event as aggregator has not loaded. Retrying in 10000ms ...`) - clock.tick(10010) - expect(exports.prettyLog.getCall(8).args[0]).to.equal('error') - expect(exports.prettyLog.getCall(8).args[1]).to.equal(`Aggregator still hasn't loaded. Processing que stopped`) - expect(exports.queuePointer).to.equal(0) - expect(exports.processEvents.callCount).to.equal(5) - }) - }); - - describe('Process Events from Que when SDK has loaded', () => { - before(() => { - spec.enableAnalytics({ - provider: 'atmtdAnalyticsAdapter', - options: { - publisherID: '230', - siteID: '421' - } - }); - sandbox = sinon.createSandbox(); - const obj = { - auctionInitHandler: (args) => {}, - bidResponseHandler: (args) => {}, - bidderDoneHandler: (args) => {}, - bidWonHandler: (args) => {}, - noBidHandler: (args) => {}, - auctionDebugHandler: (args) => {}, - bidderTimeoutHandler: (args) => {}, - impressionViewableHandler: (args) => {}, - slotRenderEndedGPTHandler: (args) => {}, - bidRequestedHandler: (args) => {}, - bidRejectedHandler: (args) => {} - } - - global.window.atmtdAnalytics = obj; - - Object.keys(obj).forEach((fn) => sandbox.spy(global.window.atmtdAnalytics, fn)) - sandbox.stub(events, 'getEvents').returns([]); - sandbox.spy(exports, 'prettyLog') - exports.retryCount = 0; - exports.queuePointer = 0; - exports.__atmtdAnalyticsQueue = [ - [AUCTION_INIT, {type: AUCTION_INIT}], - [BID_RESPONSE, {type: BID_RESPONSE}], - [BID_REQUESTED, {type: BID_REQUESTED}], - [BID_REJECTED, {type: BID_REJECTED}], - [NO_BID, {type: NO_BID}], - [BID_WON, {type: BID_WON}], - [BIDDER_DONE, {type: BIDDER_DONE}], - [AUCTION_DEBUG, {type: AUCTION_DEBUG}], - [BID_TIMEOUT, {type: BID_TIMEOUT}], - ['slotRenderEnded', {type: 'slotRenderEnded'}], - ['impressionViewable', {type: 'impressionViewable'}] - ] - }); - afterEach(() => { - sandbox.restore(); - }) - after(() => { - spec.disableAnalytics(); - }) - - it('Should make calls to appropriate SDK event handlers', () => { - exports.processEvents() - expect(exports.prettyLog.getCall(0).args[0]).to.equal('status') - expect(exports.prettyLog.getCall(0).args[1]).to.equal(`Que has been inactive for a while. Adapter starting to process que now... Trial Count = 1`) - expect(exports.retryCount).to.equal(0) - expect(exports.prettyLog.callCount).to.equal(1) - expect(exports.queuePointer).to.equal(exports.__atmtdAnalyticsQueue.length) - expect(global.window.atmtdAnalytics.auctionInitHandler.calledOnce).to.equal(true) - expect(global.window.atmtdAnalytics.bidResponseHandler.calledOnce).to.equal(true) - expect(global.window.atmtdAnalytics.bidRejectedHandler.calledOnce).to.equal(true) - expect(global.window.atmtdAnalytics.bidRequestedHandler.calledOnce).to.equal(true) - expect(global.window.atmtdAnalytics.noBidHandler.calledOnce).to.equal(true) - expect(global.window.atmtdAnalytics.bidWonHandler.calledOnce).to.equal(true) - expect(global.window.atmtdAnalytics.auctionDebugHandler.calledOnce).to.equal(true) - expect(global.window.atmtdAnalytics.bidderTimeoutHandler.calledOnce).to.equal(true) - expect(global.window.atmtdAnalytics.bidderDoneHandler.calledOnce).to.equal(true) - expect(global.window.atmtdAnalytics.slotRenderEndedGPTHandler.calledOnce).to.equal(true) - expect(global.window.atmtdAnalytics.impressionViewableHandler.calledOnce).to.equal(true) - }) - }); - - describe('Prettylog fn tests', () => { - beforeEach(() => { - sandbox = sinon.createSandbox() - sandbox.spy(utils, 'logInfo') - sandbox.spy(utils, 'logError') - exports.isLoggingEnabled = true - }) - - afterEach(() => { - sandbox.restore() - }) - - it('Should call logMessage once in normal mode', () => { - exports.prettyLog('status', 'Hello world') - expect(utils.logInfo.callCount).to.equal(1) - }) - - it('Should call logMessage twice in group mode and have the cb called', () => { - const spy = sandbox.spy() - exports.prettyLog('status', 'Hello world', true, spy) - expect(utils.logInfo.callCount).to.equal(2) - expect(spy.called).to.equal(true) - }) - - it('Should call logMessage twice in group mode and have the cb which throws an error', () => { - const spy = sandbox.stub().throws() - exports.prettyLog('status', 'Hello world', true, spy) - expect(utils.logInfo.callCount).to.equal(2) - expect(utils.logError.called).to.equal(true) - }) - }); -}); diff --git a/test/spec/modules/automatadBidAdapter_spec.js b/test/spec/modules/automatadBidAdapter_spec.js deleted file mode 100644 index 050563d72..000000000 --- a/test/spec/modules/automatadBidAdapter_spec.js +++ /dev/null @@ -1,242 +0,0 @@ -import { expect } from 'chai' -import { spec } from 'modules/automatadBidAdapter.js' -import { newBidder } from 'src/adapters/bidderFactory.js' - -describe('automatadBidAdapter', function () { - const adapter = newBidder(spec) - - const bidRequestRequiredParams = { - bidder: 'automatad', - params: {siteId: '123ad'}, - mediaTypes: { - banner: { - sizes: [[300, 600]], - } - }, - adUnitCode: 'some-ad-unit-code', - transactionId: '1465569e-52cc-4c36-88a1-7174cfef4b44', - sizes: [[300, 600]], - bidId: '123abc', - bidderRequestId: '3213887463c059', - auctionId: 'abc-123', - src: 'client', - bidRequestsCount: 1 - } - - const bidRequestAllParams = { - bidder: 'automatad', - params: {siteId: '123ad', placementId: '123abc345'}, - mediaTypes: { - banner: { - sizes: [[300, 600]], - } - }, - adUnitCode: 'some-ad-unit-code', - transactionId: '1465569e-52cc-4c36-88a1-7174cfef4b44', - sizes: [[300, 600]], - bidId: '123abc', - bidderRequestId: '3213887463c059', - auctionId: 'abc-123', - src: 'client', - bidRequestsCount: 1 - } - - const expectedResponse = [{ - 'body': { - 'id': 'abc-123', - 'seatbid': [ - { - 'bid': [ - { - 'bidId': '123', - 'adm': '', - 'adomain': [ - 'someAdDomain' - ], - 'crid': 123, - 'h': 600, - 'id': 'bid1', - 'impid': '1', - 'nurl': 'https://example/win', - 'price': 0.5, - 'w': 300 - } - ] - } - ] - } - }] - - describe('codes', function () { - it('should return a bidder code of automatad', function () { - expect(spec.code).to.equal('automatad') - }) - it('should alias atd', function () { - expect(spec.aliases.length > 0 && spec.aliases[0] === 'atd').to.be.true - }) - }) - - describe('isBidRequestValid', function () { - const inValidBid = Object.assign({}, bidRequestRequiredParams) - delete inValidBid.params - it('should return true if all params present', function () { - expect(spec.isBidRequestValid(bidRequestAllParams)).to.equal(true) - }) - - it('should return true if only required params present', function() { - expect(spec.isBidRequestValid(bidRequestRequiredParams)).to.equal(true) - }) - - it('should return false if any parameter missing', function () { - expect(spec.isBidRequestValid(inValidBid)).to.be.false - }) - }) - - describe('buildRequests', function () { - const req = spec.buildRequests([ bidRequestRequiredParams ], { refererInfo: { } }) - let rdata - - it('should have withCredentials option as true', function() { - expect(req.options.withCredentials).to.equal(true) - }) - - it('should return request object', function () { - expect(req).to.not.be.null - }) - - it('should build request data', function () { - expect(req.data).to.not.be.null - }) - - it('should include one request', function () { - rdata = JSON.parse(req.data) - expect(rdata.imp.length).to.equal(1) - }) - - it('should include siteId', function () { - const r = rdata.imp[0] - expect(r.siteId !== null).to.be.true - }) - - it('should include media types', function () { - const r = rdata.imp[0] - expect(r.media_types !== null).to.be.true - }) - - it('should include adunit code', function () { - const r = rdata.imp[0] - expect(r.adUnitCode !== null).to.be.true - }) - }) - - describe('interpretResponse', function () { - it('should get the correct bid response', function () { - const result = spec.interpretResponse(expectedResponse[0]) - expect(result).to.be.an('array').that.is.not.empty - expect(result[0].meta.advertiserDomains[0]).to.equal('someAdDomain'); - }) - - it('should interpret multiple bids in seatbid', function () { - const multipleBidResponse = [{ - 'body': { - 'id': 'abc-321', - 'seatbid': [ - { - 'bid': [ - { - 'adm': '', - 'adomain': [ - 'someAdDomain' - ], - 'crid': 123, - 'h': 600, - 'id': 'bid1', - 'impid': 'imp1', - 'nurl': 'https://example/win', - 'price': 0.5, - 'w': 300 - } - ] - }, { - 'bid': [ - { - 'adm': '', - 'adomain': [ - 'someAdDomain' - ], - 'crid': 321, - 'h': 600, - 'id': 'bid1', - 'impid': 'imp2', - 'nurl': 'https://example/win', - 'price': 0.5, - 'w': 300 - } - ] - } - ] - } - }] - const result = spec.interpretResponse(multipleBidResponse[0]).map(bid => { - const {requestId} = bid; - return [ requestId ]; - }); - - assert.equal(result.length, 2); - assert.deepEqual(result, [[ 'imp1' ], [ 'imp2' ]]); - }) - - it('handles empty bid response', function () { - const response = { - body: '' - } - const result = spec.interpretResponse(response) - expect(result.length).to.equal(0) - }) - }) - - describe('onTimeout', function () { - const timeoutData = { - 'bidId': '123', - 'bidder': 'automatad', - 'adUnitCode': 'div-13', - 'auctionId': '1232', - 'params': [ - { - 'siteId': 'test', - 'placementId': 'test123' - } - ], - 'timeout': 1000 - } - - it('should exists and be a function', function () { - expect(spec.onTimeout).to.exist.and.to.be.a('function'); - }); - - it('should include timeoutData', function () { - expect(spec.onTimeout(timeoutData)).to.be.undefined; - }) - }); - - describe('onBidWon', function () { - const serverResponses = spec.interpretResponse(expectedResponse[0]) - const wonbid = serverResponses[0] - let ajaxStub - - beforeEach(() => { - ajaxStub = sinon.stub(spec, 'ajaxCall') - }) - - afterEach(() => { - ajaxStub.restore() - }) - - it('Returns true is nurl is good/not blank', function () { - expect(wonbid.nurl).to.not.equal('') - expect(spec.onBidWon(wonbid)).to.be.true - expect(ajaxStub.calledOnce).to.equal(true) - expect(ajaxStub.firstCall.args[0].indexOf('https://')).to.equal(0) - }) - }) -}) diff --git a/test/spec/modules/axisBidAdapter_spec.js b/test/spec/modules/axisBidAdapter_spec.js deleted file mode 100644 index 069e18340..000000000 --- a/test/spec/modules/axisBidAdapter_spec.js +++ /dev/null @@ -1,481 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/axisBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'axis'; - -describe('AxisBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]], - pos: 1 - } - }, - params: { - integration: '000000', - token: '000000' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60, - pos: 1 - } - }, - params: { - integration: '000000', - token: '000000' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - integration: '000000', - token: '000000' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - site: { - cat: ['IAB24'] - }, - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://prebid.axis-marketplace.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'iabCat', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.iabCat).to.have.lengthOf(1); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.integration).to.be.a('string'); - expect(placement.token).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - expect(placement.pos).to.be.within(0, 7); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - expect(placement.pos).to.be.within(0, 7); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.property('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - width: 300, - height: 250, - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta', 'width', 'height'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.property('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.property('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.axis-marketplace.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.axis-marketplace.com/image?pbjs=1&ccpa=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.axis-marketplace.com/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/axonixBidAdapter_spec.js b/test/spec/modules/axonixBidAdapter_spec.js deleted file mode 100644 index 5fd28204d..000000000 --- a/test/spec/modules/axonixBidAdapter_spec.js +++ /dev/null @@ -1,351 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/axonixBidAdapter'; -import { newBidder } from 'src/adapters/bidderFactory'; -import * as utils from 'src/utils'; - -describe('AxonixBidAdapter', function () { - const adapter = newBidder(spec); - - const SUPPLY_ID_1 = '91fd110a-5685-11eb-8db6-a7e0eeefbbc7'; - const SUPPLY_ID_2 = '22de2092-568b-11eb-bae3-cfa975dc72aa'; - const REGION_1 = 'us-east-1'; - const REGION_2 = 'eu-west-1'; - - const BANNER_REQUEST = { - adUnitCode: 'ad_code', - bidId: 'abcd1234', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 200] - ] - } - }, - bidder: 'axonix', - params: { - supplyId: SUPPLY_ID_1, - region: REGION_1 - }, - requestId: 'q4owht8ofqi3ulwsd', - transactionId: 'fvpq3oireansdwo' - }; - - const VIDEO_REQUEST = { - adUnitCode: 'ad_code', - bidId: 'abcd1234', - mediaTypes: { - video: { - context: 'outstream', - mimes: ['video/mp4'], - playerSize: [400, 300], - renderer: { - url: 'https://url.com', - backupOnly: true, - render: () => true - }, - } - }, - bidder: 'axonix', - params: { - supplyId: SUPPLY_ID_1, - region: REGION_1 - }, - requestId: 'q4owht8ofqi3ulwsd', - transactionId: 'fvpq3oireansdwo' - }; - - const BIDDER_REQUEST = { - bidderCode: 'axonix', - auctionId: '18fd8b8b0bd757', - bidderRequestId: '418b37f85e772c', - timeout: 3000, - gdprConsent: { - consentString: 'BOKAVy4OKAVy4ABAB8AAAAAZ+A==', - gdprApplies: true - }, - refererInfo: { - page: 'https://www.prebid.org', - canonicalUrl: 'https://www.prebid.org/the/link/to/the/page' - } - }; - - const BANNER_RESPONSE = { - body: [{ - requestId: 'f08b3a8dcff747eabada295dcf94eee0', - cpm: 6, - currency: 'USD', - width: 300, - height: 250, - ad: '', - creativeId: 'abc', - netRevenue: false, - meta: { - networkId: 'nid', - advertiserDomains: [ - 'https://the.url' - ], - secondaryCatIds: [ - 'IAB1' - ], - mediaType: 'banner' - }, - nurl: 'https://win.url' - }] - }; - - const VIDEO_RESPONSE = { - body: [{ - requestId: 'f08b3a8dcff747eabada295dcf94eee0', - cpm: 6, - currency: 'USD', - width: 300, - height: 250, - ad: '', - creativeId: 'abc', - netRevenue: false, - meta: { - networkId: 'nid', - advertiserDomains: [ - 'https://the.url' - ], - secondaryCatIds: [ - 'IAB1' - ], - mediaType: 'video' - }, - nurl: 'https://win.url' - }] - }; - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const validBids = [ - { - bidder: 'axonix', - params: { - supplyId: SUPPLY_ID_1, - region: REGION_1 - }, - }, - { - bidder: 'axonix', - params: { - supplyId: SUPPLY_ID_2, - region: REGION_2 - }, - future_parameter: { - future: 'ididid' - } - }, - ]; - - const invalidBids = [ - { - bidder: 'axonix', - params: {}, - }, - { - bidder: 'axonix', - }, - ]; - - it('should accept valid bids', function () { - for (const bid of validBids) { - expect(spec.isBidRequestValid(bid)).to.equal(true); - } - }); - - it('should reject invalid bids', function () { - for (const bid of invalidBids) { - expect(spec.isBidRequestValid(bid)).to.equal(false); - } - }); - }); - - describe('buildRequests: can handle banner ad requests', function () { - it('creates ServerRequests with the correct data', function () { - const [request] = spec.buildRequests([BANNER_REQUEST], BIDDER_REQUEST); - - expect(request).to.have.property('url', `https://openrtb-${REGION_1}.axonix.com/supply/prebid/${SUPPLY_ID_1}`); - expect(request).to.have.property('method', 'POST'); - expect(request).to.have.property('data'); - - const { data } = request; - expect(data.app).to.be.undefined; - - expect(data).to.have.property('site'); - expect(data.site).to.have.property('page', 'https://www.prebid.org'); - - expect(data).to.have.property('validBidRequest', BANNER_REQUEST); - expect(data).to.have.property('connectionType').to.exist; - expect(data).to.have.property('effectiveType').to.exist; - expect(data).to.have.property('devicetype', 2); - expect(data).to.have.property('bidfloor', 0); - expect(data).to.have.property('dnt', 0); - expect(data).to.have.property('language').to.be.a('string'); - expect(data).to.have.property('prebidVersion').to.be.a('string'); - expect(data).to.have.property('screenHeight').to.be.a('number'); - expect(data).to.have.property('screenWidth').to.be.a('number'); - expect(data).to.have.property('tmax').to.be.a('number'); - expect(data).to.have.property('ua').to.be.a('string'); - }); - - it('creates ServerRequests pointing to the correct region and endpoint if it changes', function () { - const bannerRequests = [utils.deepClone(BANNER_REQUEST), utils.deepClone(BANNER_REQUEST)]; - bannerRequests[0].params.endpoint = 'https://the.url'; - bannerRequests[1].params.endpoint = 'https://the.other.url'; - - const requests = spec.buildRequests(bannerRequests, BIDDER_REQUEST); - - requests.forEach((request, index) => { - expect(request).to.have.property('url', bannerRequests[index].params.endpoint); - }); - }); - - it('creates ServerRequests pointing to default endpoint if missing', function () { - const bannerRequests = [utils.deepClone(BANNER_REQUEST), utils.deepClone(BANNER_REQUEST)]; - bannerRequests[1].params.supplyId = SUPPLY_ID_2; - bannerRequests[1].params.region = REGION_2; - - const requests = spec.buildRequests(bannerRequests, BIDDER_REQUEST); - expect(requests[0]).to.have.property('url', `https://openrtb-${REGION_1}.axonix.com/supply/prebid/${SUPPLY_ID_1}`); - expect(requests[1]).to.have.property('url', `https://openrtb-${REGION_2}.axonix.com/supply/prebid/${SUPPLY_ID_2}`); - }); - - it('creates ServerRequests pointing to default region if missing', function () { - const bannerRequest = utils.deepClone(BANNER_REQUEST); - delete bannerRequest.params.region; - - const requests = spec.buildRequests([bannerRequest], BIDDER_REQUEST); - expect(requests[0]).to.have.property('url', `https://openrtb-${REGION_1}.axonix.com/supply/prebid/${SUPPLY_ID_1}`); - }); - }); - - describe('buildRequests: can handle video ad requests', function () { - it('creates ServerRequests with the correct data', function () { - const [request] = spec.buildRequests([VIDEO_REQUEST], BIDDER_REQUEST); - - expect(request).to.have.property('url', `https://openrtb-${REGION_1}.axonix.com/supply/prebid/${SUPPLY_ID_1}`); - expect(request).to.have.property('method', 'POST'); - expect(request).to.have.property('data'); - - const { data } = request; - expect(data.app).to.be.undefined; - - expect(data).to.have.property('site'); - expect(data.site).to.have.property('page', 'https://www.prebid.org'); - - expect(data).to.have.property('validBidRequest', VIDEO_REQUEST); - expect(data).to.have.property('connectionType').to.exist; - expect(data).to.have.property('effectiveType').to.exist; - expect(data).to.have.property('devicetype', 2); - expect(data).to.have.property('bidfloor', 0); - expect(data).to.have.property('dnt', 0); - expect(data).to.have.property('language').to.be.a('string'); - expect(data).to.have.property('prebidVersion').to.be.a('string'); - expect(data).to.have.property('screenHeight').to.be.a('number'); - expect(data).to.have.property('screenWidth').to.be.a('number'); - expect(data).to.have.property('tmax').to.be.a('number'); - expect(data).to.have.property('ua').to.be.a('string'); - }); - - it('creates ServerRequests pointing to the correct region and endpoint if it changes', function () { - const videoRequests = [utils.deepClone(VIDEO_REQUEST), utils.deepClone(VIDEO_REQUEST)]; - videoRequests[0].params.endpoint = 'https://the.url'; - videoRequests[1].params.endpoint = 'https://the.other.url'; - - const requests = spec.buildRequests(videoRequests, BIDDER_REQUEST); - - requests.forEach((request, index) => { - expect(request).to.have.property('url', videoRequests[index].params.endpoint); - }); - }); - - it('creates ServerRequests pointing to default endpoint if missing', function () { - const videoRequests = [utils.deepClone(VIDEO_REQUEST), utils.deepClone(VIDEO_REQUEST)]; - videoRequests[1].params.supplyId = SUPPLY_ID_2; - videoRequests[1].params.region = REGION_2; - - const requests = spec.buildRequests(videoRequests, BIDDER_REQUEST); - expect(requests[0]).to.have.property('url', `https://openrtb-${REGION_1}.axonix.com/supply/prebid/${SUPPLY_ID_1}`); - expect(requests[1]).to.have.property('url', `https://openrtb-${REGION_2}.axonix.com/supply/prebid/${SUPPLY_ID_2}`); - }); - - it('creates ServerRequests pointing to default region if missing', function () { - const videoRequest = utils.deepClone(VIDEO_REQUEST); - delete videoRequest.params.region; - - const requests = spec.buildRequests([videoRequest], BIDDER_REQUEST); - expect(requests[0]).to.have.property('url', `https://openrtb-${REGION_1}.axonix.com/supply/prebid/${SUPPLY_ID_1}`); - }); - }); - - describe('interpretResponse', function () { - it('considers corner cases', function() { - expect(spec.interpretResponse(null)).to.be.an('array').that.is.empty; - expect(spec.interpretResponse()).to.be.an('array').that.is.empty; - }); - - it('ignores unparseable responses', function() { - expect(spec.interpretResponse('invalid')).to.be.an('array').that.is.empty; - expect(spec.interpretResponse(['invalid'])).to.be.an('array').that.is.empty; - expect(spec.interpretResponse({ body: [{ invalid: 'object' }] })).to.be.an('array').that.is.empty; - }); - - it('parses banner responses', function () { - const response = spec.interpretResponse(BANNER_RESPONSE); - - expect(response).to.be.an('array').that.is.not.empty; - expect(response[0]).to.equal(BANNER_RESPONSE.body[0]); - }); - - it('parses 1 video responses', function () { - const response = spec.interpretResponse(VIDEO_RESPONSE); - - expect(response).to.be.an('array').that.is.not.empty; - expect(response[0]).to.equal(VIDEO_RESPONSE.body[0]); - }); - }); - - describe('onBidWon', function () { - beforeEach(function () { - sinon.stub(utils, 'triggerPixel'); - }); - - afterEach(function () { - utils.triggerPixel.restore(); - }); - - it('called once', function () { - spec.onBidWon(BANNER_RESPONSE.body[0]); - expect(utils.triggerPixel.calledOnce).to.equal(true); - }); - - it('called false', function () { - spec.onBidWon({ cpm: '2.21' }); - expect(utils.triggerPixel.called).to.equal(false); - }); - - it('when there is no notification expected server side, none is called', function () { - var response = spec.onBidWon({}); - expect(utils.triggerPixel.called).to.equal(false); - expect(response).to.be.an('undefined') - }); - }); - - describe('onTimeout', function () { - it('banner response', () => { - spec.onTimeout(spec.interpretResponse(BANNER_RESPONSE)); - }); - - it('video response', () => { - spec.onTimeout(spec.interpretResponse(VIDEO_RESPONSE)); - }); - }); -}); diff --git a/test/spec/modules/azerionedgeRtdProvider_spec.js b/test/spec/modules/azerionedgeRtdProvider_spec.js deleted file mode 100644 index 82f4bb46c..000000000 --- a/test/spec/modules/azerionedgeRtdProvider_spec.js +++ /dev/null @@ -1,198 +0,0 @@ -import { config } from 'src/config.js'; -import * as azerionedgeRTD from 'modules/azerionedgeRtdProvider.js'; -import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; - -describe('Azerion Edge RTD submodule', function () { - const STORAGE_KEY = 'ht-pa-v1-a'; - const USER_AUDIENCES = [ - { id: '1', visits: 123 }, - { id: '2', visits: 456 }, - ]; - const IMPROVEDIGITAL_GVLID = '253'; - const key = 'publisher123'; - const bidders = ['appnexus', 'improvedigital']; - const process = { key: 'value' }; - const dataProvider = { name: 'azerionedge', waitForIt: true }; - const userConsent = {gdpr: {gdprApplies: 'gdpr-applies', consentString: 'consent-string'}, usp: 'usp'}; - - const resetAll = () => { - window.azerionPublisherAudiences.resetHistory(); - loadExternalScriptStub.resetHistory(); - } - - let reqBidsConfigObj; - let storageStub; - - beforeEach(function () { - config.resetConfig(); - reqBidsConfigObj = { ortb2Fragments: { bidder: {} } }; - window.azerionPublisherAudiences = sinon.spy(); - storageStub = sinon.stub(azerionedgeRTD.storage, 'getDataFromLocalStorage'); - }); - - afterEach(function () { - delete window.azerionPublisherAudiences; - storageStub.restore(); - }); - - describe('initialisation', function () { - let returned; - - beforeEach(function () { - returned = azerionedgeRTD.azerionedgeSubmodule.init(dataProvider, userConsent); - }); - - it('should have the correct gvlid', () => { - expect(azerionedgeRTD.azerionedgeSubmodule.gvlid).to.equal(IMPROVEDIGITAL_GVLID); - }); - - it('should return true', function () { - expect(returned).to.equal(true); - }); - - it('should load external script', function () { - expect(loadExternalScriptStub.called).to.be.true; - }); - - it('should load external script with default versioned url', function () { - const expected = 'https://edge.hyth.io/js/v1/azerion-edge.min.js'; - expect(loadExternalScriptStub.args[0][0]).to.deep.equal(expected); - }); - - [ - ['gdprApplies', userConsent.gdpr.gdprApplies], - ['gdprConsent', userConsent.gdpr.consentString], - ['uspConsent', userConsent.usp], - ].forEach(([key, value]) => { - it(`should call azerionPublisherAudiencesStub with ${key}:${value}`, function () { - expect(window.azerionPublisherAudiences.args[0][0]).to.include({[key]: value}); - }); - }); - - describe('with key', function () { - beforeEach(function () { - resetAll(); - const config = { ...dataProvider, params: { key } }; - returned = azerionedgeRTD.azerionedgeSubmodule.init(config, userConsent); - }); - - it('should return true', function () { - expect(returned).to.equal(true); - }); - - it('should load external script with publisher id url', function () { - const expected = `https://edge.hyth.io/js/v1/${key}/azerion-edge.min.js`; - expect(loadExternalScriptStub.args[0][0]).to.deep.equal(expected); - }); - }); - - describe('with process configuration', function () { - beforeEach(function () { - resetAll(); - const config = { ...dataProvider, params: { process } }; - returned = azerionedgeRTD.azerionedgeSubmodule.init(config, userConsent); - }); - - it('should return true', function () { - expect(returned).to.equal(true); - }); - - [ - ['gdprApplies', userConsent.gdpr.gdprApplies], - ['gdprConsent', userConsent.gdpr.consentString], - ['uspConsent', userConsent.usp], - ...Object.entries(process), - ].forEach(([key, value]) => { - it(`should call azerionPublisherAudiencesStub with ${key}:${value}`, function () { - expect(window.azerionPublisherAudiences.args[0][0]).to.include({[key]: value}); - }); - }); - }); - }); - - describe('gets audiences', function () { - let callbackStub; - - beforeEach(function () { - callbackStub = sinon.mock(); - }); - - describe('with empty storage', function () { - beforeEach(function () { - azerionedgeRTD.azerionedgeSubmodule.getBidRequestData( - reqBidsConfigObj, - callbackStub, - dataProvider - ); - }); - - it('does not apply audiences to bidders', function () { - expect(reqBidsConfigObj.ortb2Fragments.bidder).to.deep.equal({}); - }); - - it('calls callback anyway', function () { - expect(callbackStub.called).to.be.true; - }); - }); - - describe('with populate storage', function () { - beforeEach(function () { - storageStub - .withArgs(STORAGE_KEY) - .returns(JSON.stringify(USER_AUDIENCES)); - azerionedgeRTD.azerionedgeSubmodule.getBidRequestData( - reqBidsConfigObj, - callbackStub, - dataProvider - ); - }); - - it('does apply audiences to bidder', function () { - const segments = - reqBidsConfigObj.ortb2Fragments.bidder['improvedigital'].user.data[0] - .segment; - expect(segments).to.deep.equal([{ id: '1' }, { id: '2' }]); - }); - - it('calls callback always', function () { - expect(callbackStub.called).to.be.true; - }); - }); - }); - - describe('sets audiences in bidder', function () { - const audiences = USER_AUDIENCES.map(({ id }) => id); - const expected = { - user: { - data: [ - { - ext: { segtax: 4 }, - name: 'azerionedge', - segment: [{ id: '1' }, { id: '2' }], - }, - ], - }, - }; - - it('for improvedigital by default', function () { - azerionedgeRTD.setAudiencesToBidders( - reqBidsConfigObj, - dataProvider, - audiences - ); - expect( - reqBidsConfigObj.ortb2Fragments.bidder['improvedigital'] - ).to.deep.equal(expected); - }); - - bidders.forEach((bidder) => { - it(`for ${bidder}`, function () { - const config = { ...dataProvider, params: { bidders } }; - azerionedgeRTD.setAudiencesToBidders(reqBidsConfigObj, config, audiences); - expect(reqBidsConfigObj.ortb2Fragments.bidder[bidder]).to.deep.equal( - expected - ); - }); - }); - }); -}); diff --git a/test/spec/modules/beachfrontBidAdapter_spec.js b/test/spec/modules/beachfrontBidAdapter_spec.js deleted file mode 100644 index a881928a0..000000000 --- a/test/spec/modules/beachfrontBidAdapter_spec.js +++ /dev/null @@ -1,1037 +0,0 @@ -import { expect } from 'chai'; -import { spec, VIDEO_ENDPOINT, BANNER_ENDPOINT, OUTSTREAM_SRC, DEFAULT_MIMES } from 'modules/beachfrontBidAdapter.js'; -import { parseUrl } from 'src/utils.js'; - -describe('BeachfrontAdapter', function () { - let bidRequests; - - beforeEach(function () { - bidRequests = [ - { - bidder: 'beachfront', - params: { - bidfloor: 2.00, - appId: '3b16770b-17af-4d22-daff-9606bdf2c9c3' - }, - adUnitCode: 'div-gpt-ad-1460505748561-0', - bidId: '25186806a41eab', - bidderRequestId: '15bdd8d4a0ebaf', - auctionId: 'f17d62d0-e3e3-48d0-9f73-cb4ea358a309' - }, { - bidder: 'beachfront', - params: { - bidfloor: 1.00, - appId: '11bc5dd5-7421-4dd8-c926-40fa653bec76' - }, - adUnitCode: 'div-gpt-ad-1460505748561-1', - bidId: '365088ee6d649d', - bidderRequestId: '15bdd8d4a0ebaf', - auctionId: 'f17d62d0-e3e3-48d0-9f73-cb4ea358a309' - } - ]; - }); - - describe('spec.isBidRequestValid', function () { - it('should return true when the required params are passed', function () { - const bidRequest = bidRequests[0]; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false when the "bidfloor" param is missing', function () { - const bidRequest = bidRequests[0]; - bidRequest.params = { - appId: '11bc5dd5-7421-4dd8-c926-40fa653bec76' - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false when the "appId" param is missing', function () { - const bidRequest = bidRequests[0]; - bidRequest.params = { - bidfloor: 5.00 - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false when no bid params are passed', function () { - const bidRequest = bidRequests[0]; - bidRequest.params = {}; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false when a bid request is not passed', function () { - expect(spec.isBidRequestValid()).to.equal(false); - expect(spec.isBidRequestValid({})).to.equal(false); - }); - - describe('for multi-format bids', function () { - it('should return true when the required params are passed for video', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - video: {} - }; - bidRequest.params = { - video: { - bidfloor: 1.00, - appId: '3b16770b-17af-4d22-daff-9606bdf2c9c3' - } - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false when the required params are missing for video', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - video: {} - }; - bidRequest.params = { - banner: { - bidfloor: 1.00, - appId: '3b16770b-17af-4d22-daff-9606bdf2c9c3' - } - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return true when the required params are passed for banner', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - banner: {} - }; - bidRequest.params = { - banner: { - bidfloor: 1.00, - appId: '3b16770b-17af-4d22-daff-9606bdf2c9c3' - } - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false when the required params are missing for banner', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - banner: {} - }; - bidRequest.params = { - video: { - bidfloor: 1.00, - appId: '3b16770b-17af-4d22-daff-9606bdf2c9c3' - } - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); - }); - - describe('spec.buildRequests', function () { - describe('for video bids', function () { - it('should attach the bid request object', function () { - bidRequests[0].mediaTypes = { video: {} }; - bidRequests[1].mediaTypes = { video: {} }; - const requests = spec.buildRequests(bidRequests, {}); - expect(requests[0].bidRequest).to.equal(bidRequests[0]); - expect(requests[1].bidRequest).to.equal(bidRequests[1]); - }); - - it('should create a POST request for each bid', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { video: {} }; - const requests = spec.buildRequests([ bidRequest ], {}); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(VIDEO_ENDPOINT + bidRequest.params.appId); - }); - - it('should attach request data', function () { - const width = 640; - const height = 480; - const bidRequest = bidRequests[0]; - bidRequest.params.tagid = '7cd7a7b4-ef3f-4aeb-9565-3627f255fa10'; - bidRequest.mediaTypes = { - video: { - playerSize: [ width, height ] - } - }; - const topLocation = parseUrl('http://www.example.com?foo=bar', { decodeSearchAsString: true }); - const bidderRequest = { - refererInfo: { - page: topLocation.href - } - }; - const requests = spec.buildRequests([ bidRequest ], bidderRequest); - const data = requests[0].data; - expect(data.isPrebid).to.equal(true); - expect(data.appId).to.equal(bidRequest.params.appId); - expect(data.domain).to.equal(document.location.hostname); - expect(data.id).to.be.a('string'); - expect(data.imp[0].video).to.deep.contain({ w: width, h: height, mimes: DEFAULT_MIMES }); - expect(data.imp[0].bidfloor).to.equal(bidRequest.params.bidfloor); - expect(data.imp[0].tagid).to.equal(bidRequest.params.tagid); - expect(data.site).to.deep.equal({ page: topLocation.href, domain: topLocation.hostname }); - expect(data.device).to.deep.contain({ ua: navigator.userAgent, language: navigator.language, js: 1 }); - expect(data.cur).to.deep.equal(['USD']); - }); - - it('must read from the floors module if available', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { video: {} }; - bidRequest.getFloor = () => ({ currency: 'USD', floor: 1.16 }); - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.imp[0].bidfloor).to.equal(1.16); - }); - - it('must use the bid floor param if no value is returned from the floors module', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { video: {} }; - bidRequest.getFloor = () => ({}); - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.imp[0].bidfloor).to.equal(bidRequest.params.bidfloor); - }); - - it('must parse bid size from a nested array', function () { - const width = 640; - const height = 480; - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - video: { - playerSize: [[ width, height ]] - } - }; - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.imp[0].video).to.deep.contain({ w: width, h: height }); - }); - - it('must parse bid size from a string', function () { - const width = 640; - const height = 480; - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - video: { - playerSize: `${width}x${height}` - } - }; - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.imp[0].video).to.deep.contain({ w: width, h: height }); - }); - - it('must handle an empty bid size', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - video: { - playerSize: [] - } - }; - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.imp[0].video).to.deep.contain({ w: undefined, h: undefined }); - }); - - it('must fall back to the size on the bid object', function () { - const width = 640; - const height = 480; - const bidRequest = bidRequests[0]; - bidRequest.sizes = [ width, height ]; - bidRequest.mediaTypes = { video: {} }; - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.imp[0].video).to.deep.contain({ w: width, h: height }); - }); - - it('must set video params from the standard object', function () { - const bidRequest = bidRequests[0]; - const mimes = ['video/webm']; - const playbackmethod = 2; - const maxduration = 30; - const plcmt = 4; - const skip = 1; - bidRequest.mediaTypes = { - video: { mimes, playbackmethod, maxduration, plcmt, skip } - }; - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.imp[0].video).to.deep.contain({ mimes, playbackmethod, maxduration, plcmt, skip }); - }); - - it('must override video params from the bidder object', function () { - const bidRequest = bidRequests[0]; - const mimes = ['video/webm']; - const playbackmethod = 2; - const maxduration = 30; - const plcmt = 4; - const skip = 1; - bidRequest.mediaTypes = { video: { plcmt: 3, skip: 0 } }; - bidRequest.params.video = { mimes, playbackmethod, maxduration, plcmt, skip }; - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.imp[0].video).to.deep.contain({ mimes, playbackmethod, maxduration, plcmt, skip }); - }); - - it('must add US privacy data to the request', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { video: {} }; - const uspConsent = '2112YYZ'; - const bidderRequest = { uspConsent }; - const requests = spec.buildRequests([ bidRequest ], bidderRequest); - const data = requests[0].data; - expect(data.regs.ext.us_privacy).to.equal(uspConsent); - }); - - it('must add GDPR consent data to the request', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { video: {} }; - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const bidderRequest = { - gdprConsent: { - gdprApplies: true, - consentString - } - }; - const requests = spec.buildRequests([ bidRequest ], bidderRequest); - const data = requests[0].data; - expect(data.regs.ext.gdpr).to.equal(1); - expect(data.user.ext.consent).to.equal(consentString); - }); - - it('must add GPP consent data to the request', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { video: {} }; - const gppString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const applicableSections = [1, 2, 3]; - const bidderRequest = { - gppConsent: { - gppString, - applicableSections - } - }; - const requests = spec.buildRequests([ bidRequest ], bidderRequest); - const data = requests[0].data; - expect(data.regs.gpp).to.equal(gppString); - expect(data.regs.gpp_sid).to.deep.equal(applicableSections); - }); - - it('must add schain data to the request', () => { - const schain = { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'directseller.com', - sid: '00001', - rid: 'BidRequest1', - hp: 1 - } - ] - }; - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { video: {} }; - bidRequest.ortb2 = { source: { ext: { schain: schain } } }; - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.source.ext.schain).to.deep.equal(schain); - }); - - it('must add supported user IDs to the request', () => { - const userId = { - tdid: '54017816', - idl_env: '13024996', - uid2: { id: '45843401' }, - hadronId: { hadronId: '60314917', auSeg: ['segment1', 'segment2'] } - }; - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { video: {} }; - bidRequest.userId = userId; - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.user.ext.eids).to.deep.equal([ - { - source: 'adserver.org', - uids: [{ - id: userId.tdid, - ext: { - rtiPartner: 'TDID' - } - }] - }, - { - source: 'liveramp.com', - uids: [{ - id: userId.idl_env, - ext: { - rtiPartner: 'idl' - } - }] - }, - { - source: 'uidapi.com', - uids: [{ - id: userId.uid2.id, - ext: { - rtiPartner: 'UID2' - } - }] - }, - { - source: 'audigent.com', - uids: [{ - id: userId.hadronId, - atype: 1, - }] - } - ]); - }); - }); - - describe('for banner bids', function () { - it('should attach the bid requests array', function () { - bidRequests[0].mediaTypes = { banner: {} }; - bidRequests[1].mediaTypes = { banner: {} }; - const requests = spec.buildRequests(bidRequests, {}); - expect(requests[0].bidRequest).to.deep.equal(bidRequests); - }); - - it('should create a single POST request for all bids', function () { - bidRequests[0].mediaTypes = { banner: {} }; - bidRequests[1].mediaTypes = { banner: {} }; - const requests = spec.buildRequests(bidRequests, {}); - expect(requests.length).to.equal(1); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(BANNER_ENDPOINT); - }); - - it('should attach request data', function () { - const width = 300; - const height = 250; - const bidRequest = bidRequests[0]; - bidRequest.params.tagid = '7cd7a7b4-ef3f-4aeb-9565-3627f255fa10'; - bidRequest.mediaTypes = { - banner: { - sizes: [ width, height ] - } - }; - const topLocation = parseUrl('http://www.example.com?foo=bar', { decodeSearchAsString: true }); - const bidderRequest = { - refererInfo: { - page: topLocation.href - } - }; - const requests = spec.buildRequests([ bidRequest ], bidderRequest); - const data = requests[0].data; - expect(data.slots).to.deep.equal([ - { - slot: bidRequest.adUnitCode, - id: bidRequest.params.appId, - bidfloor: bidRequest.params.bidfloor, - tagid: bidRequest.params.tagid, - sizes: [{ w: width, h: height }] - } - ]); - expect(data.page).to.equal(topLocation.href); - expect(data.domain).to.equal(topLocation.hostname); - expect(data.search).to.equal(topLocation.search); - expect(data.ua).to.equal(navigator.userAgent); - }); - - it('must read from the floors module if available', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { banner: {} }; - bidRequest.getFloor = () => ({ currency: 'USD', floor: 1.16 }); - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.slots[0].bidfloor).to.equal(1.16); - }); - - it('must use the bid floor param if no value is returned from the floors module', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { banner: {} }; - bidRequest.getFloor = () => ({}); - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.slots[0].bidfloor).to.equal(bidRequest.params.bidfloor); - }); - - it('must parse bid size from a nested array', function () { - const width = 300; - const height = 250; - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - banner: { - sizes: [[ width, height ]] - } - }; - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.slots[0].sizes).to.deep.equal([ - { w: width, h: height } - ]); - }); - - it('must parse bid size from a string', function () { - const width = 300; - const height = 250; - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - banner: { - sizes: `${width}x${height}` - } - }; - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.slots[0].sizes).to.deep.equal([ - { w: width, h: height } - ]); - }); - - it('must handle an empty bid size', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - banner: { - sizes: [] - } - }; - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.slots[0].sizes).to.deep.equal([]); - }); - - it('must fall back to the size on the bid object', function () { - const width = 300; - const height = 250; - const bidRequest = bidRequests[0]; - bidRequest.sizes = [ width, height ]; - bidRequest.mediaTypes = { banner: {} }; - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.slots[0].sizes).to.deep.contain({ w: width, h: height }); - }); - - it('must add US privacy data to the request', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { banner: {} }; - const uspConsent = '2112YYZ'; - const bidderRequest = { uspConsent }; - const requests = spec.buildRequests([ bidRequest ], bidderRequest); - const data = requests[0].data; - expect(data.usPrivacy).to.equal(uspConsent); - }); - - it('must add GDPR consent data to the request', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { banner: {} }; - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const bidderRequest = { - gdprConsent: { - gdprApplies: true, - consentString - } - }; - const requests = spec.buildRequests([ bidRequest ], bidderRequest); - const data = requests[0].data; - expect(data.gdpr).to.equal(1); - expect(data.gdprConsent).to.equal(consentString); - }); - - it('must add GPP consent data to the request', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { banner: {} }; - const gppString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const applicableSections = [1, 2, 3]; - const bidderRequest = { - gppConsent: { - gppString, - applicableSections - } - }; - const requests = spec.buildRequests([ bidRequest ], bidderRequest); - const data = requests[0].data; - expect(data.gpp).to.equal(gppString); - expect(data.gppSid).to.deep.equal(applicableSections); - }); - - it('must add schain data to the request', () => { - const schain = { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'directseller.com', - sid: '00001', - rid: 'BidRequest1', - hp: 1 - } - ] - }; - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { banner: {} }; - bidRequest.ortb2 = { source: { ext: { schain: schain } } }; - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.schain).to.deep.equal(schain); - }); - - it('must add supported user IDs to the request', () => { - const userId = { - tdid: '54017816', - idl_env: '13024996', - uid2: { id: '45843401' }, - hadronId: { hadronId: '60314917', auSeg: ['segment1', 'segment2'] } - }; - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { banner: {} }; - bidRequest.userId = userId; - const requests = spec.buildRequests([ bidRequest ], {}); - const data = requests[0].data; - expect(data.tdid).to.equal(userId.tdid); - expect(data.idl).to.equal(userId.idl_env); - expect(data.uid2).to.equal(userId.uid2.id); - expect(data.hadronid).to.equal(userId.hadronId); - }); - }); - - describe('with first-party data', function () { - it('must add first-party data to the video bid request', function () { - const ortb2 = { - site: { - keywords: 'test keyword' - }, - user: { - data: 'some user data' - } - }; - - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { video: {} }; - const bidderRequest = { - refererInfo: { - page: 'http://example.com/page.html' - }, - ortb2 - }; - const requests = spec.buildRequests([ bidRequest ], bidderRequest); - const data = requests[0].data; - expect(data.user.data).to.equal('some user data'); - expect(data.site.keywords).to.equal('test keyword'); - expect(data.site.page).to.equal('http://example.com/page.html'); - expect(data.site.domain).to.equal('example.com'); - }); - - it('must add first-party data to the banner bid request', function () { - const ortb2 = { - site: { - keywords: 'test keyword' - }, - user: { - data: 'some user data' - } - }; - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { banner: {} }; - const requests = spec.buildRequests([ bidRequest ], {ortb2}); - const data = requests[0].data; - expect(data.ortb2.user.data).to.equal('some user data'); - expect(data.ortb2.site.keywords).to.equal('test keyword'); - }); - }); - - describe('for multi-format bids', function () { - it('should create a POST request for each bid format', function () { - const width = 300; - const height = 250; - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - video: { - playerSize: [ width, height ] - }, - banner: { - sizes: [ width, height ] - } - }; - bidRequest.params = { - video: { - bidfloor: 2.00, - appId: '11bc5dd5-7421-4dd8-c926-40fa653bec76' - }, - banner: { - bidfloor: 1.00, - appId: '3b16770b-17af-4d22-daff-9606bdf2c9c3' - } - }; - const requests = spec.buildRequests([ bidRequest ], {}); - expect(requests.length).to.equal(2); - expect(requests[0].url).to.contain(VIDEO_ENDPOINT); - expect(requests[1].url).to.contain(BANNER_ENDPOINT); - }); - - it('must parse bid sizes for each bid format', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - video: { - playerSize: [ 640, 360 ] - }, - banner: { - sizes: [ 300, 250 ] - } - }; - bidRequest.params = { - video: { - bidfloor: 2.00, - appId: '11bc5dd5-7421-4dd8-c926-40fa653bec76' - }, - banner: { - bidfloor: 1.00, - appId: '3b16770b-17af-4d22-daff-9606bdf2c9c3' - } - }; - const requests = spec.buildRequests([ bidRequest ], {}); - expect(requests[0].data.imp[0].video).to.deep.contain({ w: 640, h: 360 }); - expect(requests[1].data.slots[0].sizes).to.deep.equal([{ w: 300, h: 250 }]); - }); - }); - }); - - describe('spec.interpretResponse', function () { - describe('for video bids', function () { - it('should return no bids if the response is not valid', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { video: {} }; - const bidResponse = spec.interpretResponse({ body: null }, { bidRequest }); - expect(bidResponse.length).to.equal(0); - }); - - it('should return no bids if the response "bidPrice" is missing', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { video: {} }; - const serverResponse = { - url: 'http://reachms.bfmio.com/getmu?aid=bid:19c4a196-fb21-4c81-9a1a-ecc5437a39da' - }; - const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); - expect(bidResponse.length).to.equal(0); - }); - - it('should return a valid video bid response', function () { - const width = 640; - const height = 480; - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - video: { - playerSize: [ width, height ] - } - }; - const serverResponse = { - bidPrice: 5.00, - url: 'http://reachms.bfmio.com/getmu?aid=bid:19c4a196-fb21-4c81-9a1a-ecc5437a39da', - vast: '', - crid: '123abc' - }; - const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); - expect(bidResponse).to.deep.equal({ - requestId: bidRequest.bidId, - cpm: serverResponse.bidPrice, - creativeId: serverResponse.crid, - vastUrl: serverResponse.url, - vastXml: serverResponse.vast, - width: width, - height: height, - renderer: null, - meta: { mediaType: 'video', advertiserDomains: [] }, - mediaType: 'video', - currency: 'USD', - netRevenue: true, - ttl: 300 - }); - }); - - it('should return only vast url if the response type is "nurl"', () => { - const width = 640; - const height = 480; - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - video: { - playerSize: [ width, height ] - } - }; - bidRequest.params.video = { responseType: 'nurl' }; - const serverResponse = { - bidPrice: 5.00, - url: 'http://reachms.bfmio.com/getmu?aid=bid:19c4a196-fb21-4c81-9a1a-ecc5437a39da', - vast: '', - crid: '123abc' - }; - const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); - expect(bidResponse.vastUrl).to.equal(serverResponse.url); - expect(bidResponse.vastXml).to.equal(undefined); - }); - - it('should return only vast xml if the response type is "adm"', () => { - const width = 640; - const height = 480; - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - video: { - playerSize: [ width, height ] - } - }; - bidRequest.params.video = { responseType: 'adm' }; - const serverResponse = { - bidPrice: 5.00, - url: 'http://reachms.bfmio.com/getmu?aid=bid:19c4a196-fb21-4c81-9a1a-ecc5437a39da', - vast: '', - crid: '123abc' - }; - const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); - expect(bidResponse.vastUrl).to.equal(undefined); - expect(bidResponse.vastXml).to.equal(serverResponse.vast); - }); - - it('should return a renderer for outstream video bids', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - video: { - context: 'outstream' - } - }; - const serverResponse = { - bidPrice: 5.00, - url: 'http://reachms.bfmio.com/getmu?aid=bid:19c4a196-fb21-4c81-9a1a-ecc5437a39da', - crid: '123abc' - }; - const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); - expect(bidResponse.renderer).to.deep.contain({ - id: bidRequest.bidId, - url: OUTSTREAM_SRC - }); - expect(bidResponse.renderer.render).to.be.a('function'); - }); - - it('should return meta data for the bid response', () => { - const width = 640; - const height = 480; - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { - video: { - playerSize: [ width, height ] - } - }; - const serverResponse = { - bidPrice: 5.00, - url: 'http://reachms.bfmio.com/getmu?aid=bid:19c4a196-fb21-4c81-9a1a-ecc5437a39da', - meta: { - advertiserDomains: ['example.com'], - advertiserId: '123' - } - }; - const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); - expect(bidResponse.meta).to.deep.equal({ - mediaType: 'video', - advertiserDomains: ['example.com'], - advertiserId: '123' - }); - }); - }); - - describe('for banner bids', function () { - it('should return no bids if the response is not valid', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { banner: {} }; - const bidResponse = spec.interpretResponse({ body: null }, { bidRequest }); - expect(bidResponse.length).to.equal(0); - }); - - it('should return no bids if the response is empty', function () { - const bidRequest = bidRequests[0]; - bidRequest.mediaTypes = { banner: {} }; - const bidResponse = spec.interpretResponse({ body: [] }, { bidRequest }); - expect(bidResponse.length).to.equal(0); - }); - - it('should return valid banner bid responses', function () { - bidRequests[0].mediaTypes = { - banner: { - sizes: [[ 300, 250 ], [ 728, 90 ]] - } - }; - bidRequests[1].mediaTypes = { - banner: { - sizes: [[ 300, 600 ], [ 200, 200 ]] - } - }; - const serverResponse = [{ - slot: bidRequests[0].adUnitCode, - adm: '
', - crid: 'crid_1', - price: 3.02, - w: 728, - h: 90 - }, { - slot: bidRequests[1].adUnitCode, - adm: '
', - crid: 'crid_2', - price: 3.06, - w: 300, - h: 600 - }]; - const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest: bidRequests }); - expect(bidResponse.length).to.equal(2); - for (let i = 0; i < bidRequests.length; i++) { - expect(bidResponse[ i ]).to.deep.equal({ - requestId: bidRequests[ i ].bidId, - bidderCode: spec.code, - ad: serverResponse[ i ].adm, - creativeId: serverResponse[ i ].crid, - cpm: serverResponse[ i ].price, - width: serverResponse[ i ].w, - height: serverResponse[ i ].h, - meta: { mediaType: 'banner', advertiserDomains: [] }, - mediaType: 'banner', - currency: 'USD', - netRevenue: true, - ttl: 300 - }); - } - }); - - it('should return meta data for the bid response', () => { - bidRequests[0].mediaTypes = { - banner: { - sizes: [[ 300, 250 ], [ 728, 90 ]] - } - }; - const serverResponse = [{ - slot: bidRequests[0].adUnitCode, - adm: '
', - crid: 'crid_1', - price: 3.02, - w: 728, - h: 90, - meta: { - advertiserDomains: ['example.com'], - advertiserId: '123' - } - }]; - const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest: bidRequests }); - expect(bidResponse[0].meta).to.deep.equal({ - mediaType: 'banner', - advertiserDomains: ['example.com'], - advertiserId: '123' - }); - }); - }); - }); - - describe('spec.getUserSyncs', function () { - describe('for video bids', function () { - let bidResponse; - - beforeEach(function () { - bidResponse = { - bidPrice: 5.00, - url: 'http://reachms.bfmio.com/getmu?aid=bid:19c4a196-fb21-4c81-9a1a-ecc5437a39da', - crid: '123abc' - }; - }); - - it('should return an iframe user sync if iframes are enabled', function () { - const syncOptions = { - iframeEnabled: true, - pixelEnabled: true - }; - const serverResponses = [{ - body: bidResponse - }]; - const userSyncs = spec.getUserSyncs(syncOptions, serverResponses); - expect(userSyncs.length).to.equal(1); - expect(userSyncs[0].type).to.equal('iframe'); - }); - - it('should return an image user sync if iframes are disabled', function () { - const syncOptions = { - iframeEnabled: false, - pixelEnabled: true - }; - const serverResponses = [{ - body: bidResponse - }]; - const userSyncs = spec.getUserSyncs(syncOptions, serverResponses); - expect(userSyncs.length).to.equal(1); - expect(userSyncs[0].type).to.equal('image'); - }); - - it('should not return user syncs if none are enabled', function () { - const syncOptions = { - iframeEnabled: false, - pixelEnabled: false - }; - const serverResponses = [{ - body: bidResponse - }]; - const userSyncs = spec.getUserSyncs(syncOptions, serverResponses); - expect(userSyncs).to.deep.equal([]); - }); - }); - - describe('for banner bids', function () { - let bidResponse; - - beforeEach(function () { - bidResponse = { - slot: bidRequests[0].adUnitCode, - adm: '
', - crid: 'crid_1', - price: 3.02, - w: 728, - h: 90 - }; - }); - - it('should return user syncs defined the bid response', function () { - const syncUrl = 'https://sync.bfmio.com/sync_iframe?ifpl=5&ifg=1&id=test&gdpr=0&gc=&gce=0'; - const syncOptions = { - iframeEnabled: true, - pixelEnabled: true - }; - const serverResponses = [{ - body: [ - { sync: syncUrl }, - bidResponse - ] - }]; - const userSyncs = spec.getUserSyncs(syncOptions, serverResponses); - expect(userSyncs).to.deep.equal([ - { type: 'iframe', url: syncUrl } - ]); - }); - - it('should not return user syncs if iframes are disabled', function () { - const syncUrl = 'https://sync.bfmio.com/sync_iframe?ifpl=5&ifg=1&id=test&gdpr=0&gc=&gce=0'; - const syncOptions = { - iframeEnabled: false, - pixelEnabled: true - }; - const serverResponses = [{ - body: [ - { sync: syncUrl }, - bidResponse - ] - }]; - const userSyncs = spec.getUserSyncs(syncOptions, serverResponses); - expect(userSyncs).to.deep.equal([]); - }); - - it('should not return user syncs if there are none in the bid response', function () { - const syncOptions = { - iframeEnabled: true, - pixelEnabled: true - }; - const serverResponses = [{ - body: [ - bidResponse - ] - }]; - const userSyncs = spec.getUserSyncs(syncOptions, serverResponses); - expect(userSyncs).to.deep.equal([]); - }); - }); - }); -}); diff --git a/test/spec/modules/bedigitechBidAdapter_spec.js b/test/spec/modules/bedigitechBidAdapter_spec.js deleted file mode 100644 index 2454efa63..000000000 --- a/test/spec/modules/bedigitechBidAdapter_spec.js +++ /dev/null @@ -1,136 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/bedigitechBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { BANNER } from 'src/mediaTypes.js'; - -describe('BedigitechAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - bidder: 'bedigitech', - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - params: { - placementId: 309, - }, - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'masterId': 0 - }; - - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [{ - bidder: 'bedigitech', - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - params: { - placementId: 309, - }, - }]; - - it('sends bid request to url via GET', function () { - const request = spec.buildRequests(bidRequests)[0]; - expect(request.method).to.equal('GET'); - expect(request.url).to.equal('https://bid.bedigitech.com/bid/pub_bid.php'); - }); - - it('should attach pid to url', function () { - const request = spec.buildRequests(bidRequests)[0]; - expect(request.data.pid).to.equal(309); - }); - }); - - describe('interpretResponse', function () { - const response = { - 'body': [ - { - 'ad': '%3C!--%20Creative%20--%3E', - 'cpm': '5.0', - 'crid': '0af345b42983cc4bc0', - 'currency': 'USD', - 'height': 250, - 'id': 'bedigitechMyidfdfdf', - 'netRevenue': true, - 'requestTime': 1686306237, - 'timeToRespond': 300, - 'ttl': 300, - 'width': 300 - } - ], - 'headers': { - 'get': function() {} - } - }; - - it('should get correct bid responseiiiiii', function () { - const expectedResponse = [ - { - 'ad': '%3C!--%20Creative%20--%3E', - 'cpm': '5.0', - 'creativeId': '0af345b42983cc4bc0', - 'currency': 'USD', - 'height': 250, - 'id': 'bedigitechMyidfdfdf', - 'meta': { - 'mediaType': BANNER, - }, - 'netRevenue': true, - 'requestId': 'bedigitechMyidfdfdf', - 'requestTimestamp': 1686306237, - 'timeToRespond': 300, - 'ttl': 300, - 'width': 300, - 'bidderCode': 'bedigitech', - } - ]; - const result = spec.interpretResponse(response); - expect(result).to.have.lengthOf(1); - const resultKeys = Object.keys(result[0]); - expect(resultKeys.sort()).to.deep.equal(Object.keys(expectedResponse[0]).sort()); - resultKeys.forEach(function(k) { - if (k === 'ad') { - expect(result[0][k]).to.match(/$/); - } else if (k === 'meta') { - expect(result[0][k]).to.deep.equal(expectedResponse[0][k]); - } else { - if (k !== 'requestId') { - expect(result[0][k]).to.equal(expectedResponse[0][k]); - } - } - }); - }); - }); -}); diff --git a/test/spec/modules/beopBidAdapter_spec.js b/test/spec/modules/beopBidAdapter_spec.js deleted file mode 100644 index 08e14b761..000000000 --- a/test/spec/modules/beopBidAdapter_spec.js +++ /dev/null @@ -1,452 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/beopBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import { setConfig as setCurrencyConfig } from '../../../modules/currency.js'; -import { addFPDToBidderRequest } from '../../helpers/fpd.js'; -const utils = require('src/utils'); - -const ENDPOINT = 'https://hb.collectiveaudience.co/bid'; - -const validBid = { - 'bidder': 'beop', - 'params': { - 'accountId': '5a8af500c9e77c00017e4cad' - }, - 'adUnitCode': 'bellow-article', - 'mediaTypes': { - 'banner': { - 'sizes': [[1, 1]] - } - }, - 'getFloor': () => { - return { - currency: 'USD', - floor: 10, - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'transactionId': '04f2659e-c005-4eb1-a57c-fa93145e3843', - 'creativeId': 'er2ee' -}; - -describe('BeOp Bid Adapter tests', () => { - afterEach(function () { - config.setConfig({}); - }); - - const adapter = newBidder(spec); - - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function() { - it('should return true when accountId params found', function () { - expect(spec.isBidRequestValid(validBid)).to.equal(true); - }); - - it('should return true if no accountId but networkId', function () { - const bid = Object.assign({}, validBid); - delete bid.params; - bid.params = { - 'networkId': '5a8af500c9e77c00017e4aaa' - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false if neither account or network id param found', function () { - const bid = Object.assign({}, validBid); - delete bid.params; - bid.params = { - 'someId': '5a8af500c9e77c00017e4aaa' - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if account Id param is not an ObjectId', function () { - const bid = Object.assign({}, validBid); - delete bid.params; - bid.params = { - 'someId': '12345' - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if there is no banner media type', function () { - const bid = Object.assign({}, validBid); - delete bid.mediaTypes; - bid.mediaTypes = { - 'native': { - 'sizes': [[1, 1]] - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = []; - bidRequests.push(validBid); - - it('should build the request', function () { - const bidderRequest = { - refererInfo: { - page: 'https://example.com' - } - }; - setCurrencyConfig({ adServerCurrency: 'USD' }) - - return addFPDToBidderRequest(bidderRequest).then(res => { - const request = spec.buildRequests(bidRequests, res); - const payload = JSON.parse(request.data); - const url = request.url; - expect(url).to.equal(ENDPOINT); - expect(payload.pid).to.exist; - expect(payload.pid).to.equal('5a8af500c9e77c00017e4cad'); - expect(payload.gdpr_applies).to.exist; - expect(payload.gdpr_applies).to.equals(false); - expect(payload.slts[0].name).to.exist; - expect(payload.slts[0].name).to.equal('bellow-article'); - expect(payload.slts[0].flr).to.equal(10); - setCurrencyConfig({}); - }); - }); - - it('should call the endpoint with GDPR consent and pageURL info if found', function () { - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const bidderRequest = - { - 'gdprConsent': - { - 'gdprApplies': true, - 'consentString': consentString - }, - 'refererInfo': - { - 'canonicalUrl': 'test.te' - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.gdpr_applies).to.exist; - expect(payload.gdpr_applies).to.equals(true); - expect(payload.tc_string).to.exist; - expect(payload.tc_string).to.equal('BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='); - expect(payload.url).to.exist; - // check that the protocol is added correctly - expect(payload.url).to.equal('http://test.te'); - }); - - it('should call the endpoint with bpsegs (stringified) data if any or [] if none', function () { - const bidderRequest = - { - 'ortb2': { - 'user': { - 'ext': { - 'bpsegs': ['axed', 'axec', 1234], - 'data': { - 'permutive': [1234, 5678, 910] - } - } - } - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.bpsegs).to.exist; - expect(payload.bpsegs).to.include('axed'); - expect(payload.bpsegs).to.include('axec'); - expect(payload.bpsegs).to.include('1234'); - expect(payload.bpsegs).to.include('1234'); - expect(payload.bpsegs).to.include('5678'); - expect(payload.bpsegs).to.include('910'); - expect(payload.bpsegs).to.not.include('1'); - - const bidderRequest2 = - { - 'ortb2': {} - }; - - const request2 = spec.buildRequests(bidRequests, bidderRequest2); - const payload2 = JSON.parse(request2.data); - expect(payload2.bpsegs).to.exist; - expect(payload2.bpsegs).to.be.empty; - }); - - it('should not prepend the protocol in page url if already present', function () { - const bidderRequest = { - 'refererInfo': { - 'canonicalUrl': 'https://test.te' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.url).to.exist; - expect(payload.url).to.equal('https://test.te'); - }); - }); - - describe('interpretResponse', function() { - const serverResponse = { - 'body': { - 'bids': [ - { - 'requestId': 'aaaa', - 'cpm': 1.0, - 'currency': 'EUR', - 'creativeId': '60f691be1515670a2a09aea2', - 'netRevenue': true, - 'width': 1, - 'height': 1, - 'ad': '
', - 'meta': { - 'advertiserId': '60f691be1515670a2a09aea1' - } - } - ] - } - } - it('should interpret the response by pushing it in the bids elem', function () { - const response = spec.interpretResponse(serverResponse, validBid); - - expect(response[0].ad).to.exist; - expect(response[0].requestId).to.exist; - expect(response[0].requestId).to.equal('aaaa'); - }); - }); - - describe('timeout and bid won pixel trigger', function () { - let triggerPixelStub; - - beforeEach(function () { - triggerPixelStub = sinon.stub(utils, 'triggerPixel'); - }); - - afterEach(function () { - utils.triggerPixel.restore(); - }); - - it('should call triggerPixel utils function when timed out is filled', function () { - spec.onTimeout({}); - spec.onTimeout(); - spec.onTimeout(null); - spec.onTimeout([]); - expect(triggerPixelStub.getCall(0)).to.be.null; - spec.onTimeout([{ - bidder: 'beop', - bidId: 'abc123', - params: { accountId: '5a8af500c9e77c00017e4cad' }, - adUnitCode: 'div-1', - timeout: 2000, - auctionId: 'some-auction-id' - }]); - expect(triggerPixelStub.getCall(0)).to.not.be.null; - expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.include('https://t.collectiveaudience.co'); - expect(triggerPixelStub.getCall(0).args[0]).to.include('se_ca=bid'); - expect(triggerPixelStub.getCall(0).args[0]).to.include('se_ac=timeout'); - expect(triggerPixelStub.getCall(0).args[0]).to.include('pid=5a8af500c9e77c00017e4cad'); - }); - - it('should call triggerPixel for each entry in the timeout array', function () { - const timeoutData = [ - { - bidder: 'beop', - bidId: 'abc123', - params: { accountId: '5a8af500c9e77c00017e4cad' }, - adUnitCode: 'div-1', - timeout: 3000, - auctionId: 'auction-1' - }, - { - bidder: 'beop', - bidId: 'def456', - params: { accountId: '5a8af500c9e77c00017e4cad' }, - adUnitCode: 'div-2', - timeout: 3000, - auctionId: 'auction-2' - } - ]; - - spec.onTimeout(timeoutData); - - expect(triggerPixelStub.callCount).to.equal(2); - const firstCall = triggerPixelStub.getCall(0).args[0]; - const secondCall = triggerPixelStub.getCall(1).args[0]; - - expect(firstCall).to.include('se_ac=timeout'); - expect(firstCall).to.include('bid=abc123'); - expect(secondCall).to.include('bid=def456'); - }); - it('should call triggerPixel utils function on bid won', function () { - spec.onBidWon({}); - spec.onBidWon(); - expect(triggerPixelStub.getCall(0)).to.be.null; - spec.onBidWon({params: {accountId: '5a8af500c9e77c00017e4cad'}, cpm: 1.2}); - expect(triggerPixelStub.getCall(0)).to.not.be.null; - expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.include('https://t.collectiveaudience.co'); - expect(triggerPixelStub.getCall(0).args[0]).to.include('se_ca=bid'); - expect(triggerPixelStub.getCall(0).args[0]).to.include('se_ac=won'); - expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.include('pid=5a8af500c9e77c00017e4cad'); - }); - it('should call triggerPixel utils function on bid won and work even if params is an array', function () { - spec.onBidWon({}); - spec.onBidWon(); - expect(triggerPixelStub.getCall(0)).to.be.null; - spec.onBidWon({params: [{accountId: '5a8af500c9e77c00017e4cad'}], cpm: 1.2}); - expect(triggerPixelStub.getCall(0)).to.not.be.null; - expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.include('https://t.collectiveaudience.co'); - expect(triggerPixelStub.getCall(0).args[0]).to.include('se_ca=bid'); - expect(triggerPixelStub.getCall(0).args[0]).to.include('se_ac=won'); - expect(triggerPixelStub.getCall(0).args[0]).to.exist.and.to.include('pid=5a8af500c9e77c00017e4cad'); - }); - }); - - describe('Ensure keywords is always array of string', function () { - let bidRequests = []; - afterEach(function () { - bidRequests = []; - }); - - it('should work with keywords as an array', function () { - const bid = Object.assign({}, validBid); - bid.params.keywords = ['a', 'b']; - bidRequests.push(bid); - config.setConfig({ - currency: { adServerCurrency: 'USD' } - }); - const request = spec.buildRequests(bidRequests, {}); - const payload = JSON.parse(request.data); - const url = request.url; - expect(payload.kwds).to.exist; - expect(payload.kwds).to.include('a'); - expect(payload.kwds).to.include('b'); - }); - - it('should work with keywords as a string', function () { - const bid = Object.assign({}, validBid); - bid.params.keywords = 'list of keywords'; - bidRequests.push(bid); - config.setConfig({ - currency: { adServerCurrency: 'USD' } - }); - const request = spec.buildRequests(bidRequests, {}); - const payload = JSON.parse(request.data); - const url = request.url; - expect(payload.kwds).to.exist; - expect(payload.kwds).to.include('list of keywords'); - }); - - it('should work with keywords as a string containing a comma', function () { - const bid = Object.assign({}, validBid); - bid.params.keywords = 'list, of, keywords'; - bidRequests.push(bid); - config.setConfig({ - currency: { adServerCurrency: 'USD' } - }); - const request = spec.buildRequests(bidRequests, {}); - const payload = JSON.parse(request.data); - const url = request.url; - expect(payload.kwds).to.exist; - expect(payload.kwds).to.include('list'); - expect(payload.kwds).to.include('of'); - expect(payload.kwds).to.include('keywords'); - }) - }) - - describe('Ensure eids are get', function() { - let bidRequests = []; - afterEach(function () { - bidRequests = []; - }); - - it(`should get eids from bid`, function () { - const bid = Object.assign({}, validBid); - bid.userIdAsEids = [{source: 'provider.com', uids: [{id: 'someid', atype: 1, ext: {whatever: true}}]}]; - bidRequests.push(bid); - - const request = spec.buildRequests(bidRequests, {}); - const payload = JSON.parse(request.data); - expect(payload.eids).to.exist; - expect(payload.eids[0].source).to.equal('provider.com'); - }); - }) - - describe('Ensure first party cookie is well managed', function () { - const bidRequests = []; - - it(`should generate a new uuid`, function () { - const bid = Object.assign({}, validBid); - bidRequests.push(bid); - const request = spec.buildRequests(bidRequests, {}); - const payload = JSON.parse(request.data); - expect(payload.fg).to.exist; - }) - }) - describe('getUserSyncs', function () { - it('should return iframe sync when iframeEnabled and syncFrame provided', function () { - const syncOptions = { iframeEnabled: true, pixelEnabled: false }; - const serverResponses = [{ body: { sync_frames: ['https://example.com/sync_frame', 'https://example2.com/sync_second'] } }]; - - const syncs = spec.getUserSyncs(syncOptions, serverResponses); - - expect(syncs).to.have.length(2); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.equal('https://example.com/sync_frame'); - }); - - it('should return pixel syncs when pixelEnabled and syncPixels provided', function () { - const syncOptions = { iframeEnabled: false, pixelEnabled: true }; - const serverResponses = [{ - body: { - sync_pixels: [ - 'https://example.com/pixel1', - 'https://example.com/pixel2' - ] - } - }]; - - const syncs = spec.getUserSyncs(syncOptions, serverResponses); - - expect(syncs).to.have.length(2); - expect(syncs[0].type).to.equal('image'); - expect(syncs[0].url).to.equal('https://example.com/pixel1'); - expect(syncs[1].url).to.equal('https://example.com/pixel2'); - }); - - it('should return both iframe and pixel syncs when both options are enabled', function () { - const syncOptions = { iframeEnabled: true, pixelEnabled: true }; - const serverResponses = [{ - body: { - sync_frames: ['https://example.com/sync_frame'], - sync_pixels: ['https://example.com/pixel1'] - } - }]; - - const syncs = spec.getUserSyncs(syncOptions, serverResponses); - - expect(syncs).to.have.length(2); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[1].type).to.equal('image'); - }); - - it('should return empty array when no serverResponses', function () { - const syncOptions = { iframeEnabled: true, pixelEnabled: true }; - const syncs = spec.getUserSyncs(syncOptions, []); - expect(syncs).to.be.an('array').that.is.empty; - }); - - it('should return empty array when no syncFrame or syncPixels provided', function () { - const syncOptions = { iframeEnabled: true, pixelEnabled: true }; - const serverResponses = [{ body: {} }]; - const syncs = spec.getUserSyncs(syncOptions, serverResponses); - expect(syncs).to.be.an('array').that.is.empty; - }); - }); -}); diff --git a/test/spec/modules/betweenBidAdapter_spec.js b/test/spec/modules/betweenBidAdapter_spec.js deleted file mode 100644 index 857779ca3..000000000 --- a/test/spec/modules/betweenBidAdapter_spec.js +++ /dev/null @@ -1,365 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/betweenBidAdapter.js'; - -describe('betweenBidAdapterTests', function () { - it('validate_pub_params', function () { - expect(spec.isBidRequestValid({ - bidder: 'between', - params: { - w: 240, - h: 400, - s: 1112 - } - })).to.equal(true); - }); - it('validate_generated_params', function () { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - params: {w: 240, h: 400, s: 1112}, - sizes: [[240, 400]] - }] - const request = spec.buildRequests(bidRequestData); - const req_data = JSON.parse(request.data)[0].data; - expect(req_data.bidid).to.equal('bid1234'); - }); - - it('validate_video_params', function () { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - params: {w: 240, h: 400, s: 1112}, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [970, 250], - maxd: 123, - mind: 234, - codeType: 'unknown code type' - } - }, - }]; - const request = spec.buildRequests(bidRequestData); - const req_data = JSON.parse(request.data)[0].data; - - expect(req_data.mediaType).to.equal(2); - expect(req_data.maxd).to.equal(123); - expect(req_data.mind).to.equal(234); - expect(req_data.pos).to.equal('atf'); - expect(req_data.codeType).to.equal('inpage'); - }); - - it('validate itu param', function() { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - params: { - w: 240, - h: 400, - s: 1112, - itu: 'https://something.url' - }, - sizes: [[240, 400]] - }]; - - const request = spec.buildRequests(bidRequestData); - const req_data = JSON.parse(request.data)[0].data; - - expect(req_data.itu).to.equal('https://something.url'); - }); - it('validate cur param', function() { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - params: { - w: 240, - h: 400, - s: 1112, - cur: 'THX' - }, - sizes: [[240, 400]] - }]; - - const request = spec.buildRequests(bidRequestData); - const req_data = JSON.parse(request.data)[0].data; - - expect(req_data.cur).to.equal('THX'); - }); - it('validate default cur USD', function() { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - params: { - w: 240, - h: 400, - s: 1112 - }, - sizes: [[240, 400]] - }]; - - const request = spec.buildRequests(bidRequestData); - const req_data = JSON.parse(request.data)[0].data; - - expect(req_data.cur).to.equal('USD'); - }); - it('validate subid param', function() { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - params: { - w: 240, - h: 400, - s: 1112, - subid: 1138, - }, - sizes: [[240, 400]] - }]; - - const request = spec.buildRequests(bidRequestData); - const req_data = JSON.parse(request.data)[0].data; - - expect(req_data.subid).to.equal(1138); - }); - - it('validate eids parameter', function() { - const USER_ID_DATA = [ - { - source: 'admixer.net', - uids: [ - { id: '5706411dc1c54268ac2ed668b27f92a3', atype: 3 } - ] - } - ]; - - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - params: { - w: 240, - h: 400, - s: 1112, - }, - sizes: [[240, 400]], - userIdAsEids: USER_ID_DATA, - }]; - - const request = spec.buildRequests(bidRequestData); - const req_data = JSON.parse(request.data)[0].data; - - expect(req_data.eids).to.have.deep.members(USER_ID_DATA); - }); - - it('validate eids parameter, if userIdAsEids = undefined', function() { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - params: { - w: 240, - h: 400, - s: 1112, - }, - sizes: [[240, 400]], - userIdAsEids: undefined - }]; - - const request = spec.buildRequests(bidRequestData); - const req_data = JSON.parse(request.data)[0].data; - - expect(req_data.eids).to.have.deep.members([]); - }); - - it('validate click3rd param', function() { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - params: { - w: 240, - h: 400, - s: 1112, - click3rd: 'https://something.url', - }, - sizes: [[240, 400]] - }]; - - const request = spec.buildRequests(bidRequestData); - const req_data = JSON.parse(request.data)[0].data; - - expect(req_data.click3rd).to.equal('https://something.url'); - }); - it('validate pubdata param', function() { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - params: { - w: 240, - h: 400, - s: 1112, - pubdata: { - param: '&test=tset' - }, - }, - sizes: [[240, 400]] - }]; - - const request = spec.buildRequests(bidRequestData); - const req_data = JSON.parse(request.data)[0].data; - - expect(req_data['pubside_macro[param]']).to.equal('%26test%3Dtset'); - }); - it('validate gdprConsent', function() { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - params: { - w: 240, - h: 400, - s: 1112, - }, - sizes: [[240, 400]] - }]; - const bidderRequest = { - gdprConsent: { - consentString: 'BOtGbjbOtGbjbBQABBENC3-AAAAtR7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4u_1vf99yfm1-7etr3tp_87ues2_Xur__79__3z3_9pxP78k89r7337Ew_v-_v-b7JCON_IA', - gdprApplies: true - } - } - - const request = spec.buildRequests(bidRequestData, bidderRequest); - const req_data = JSON.parse(request.data)[0].data; - - expect(req_data.gdprApplies).to.equal(bidderRequest.gdprConsent.gdprApplies); - expect(req_data.consentString).to.equal(bidderRequest.gdprConsent.consentString); - }); - it('validate_response_params', function () { - const serverResponse = { - body: [{ - bidid: 'bid1234', - cpm: 1.12, - w: 240, - h: 400, - currency: 'USD', - ad: 'Ad html' - }] - }; - const bids = spec.interpretResponse(serverResponse); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(1.12); - expect(bid.currency).to.equal('USD'); - expect(bid.width).to.equal(240); - expect(bid.height).to.equal(400); - expect(bid.netRevenue).to.equal(true); - expect(bid.requestId).to.equal('bid1234'); - expect(bid.ad).to.equal('Ad html'); - }); - it('validate_response_params', function () { - const serverResponse = { - body: [{ - bidid: 'bid1234', - w: 240, - h: 400, - currency: 'USD', - ad: 'Ad html' - }] - }; - const bids = spec.interpretResponse(serverResponse); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(0); - expect(bid.currency).to.equal('USD'); - expect(bid.width).to.equal(240); - expect(bid.height).to.equal(400); - expect(bid.netRevenue).to.equal(true); - expect(bid.requestId).to.equal('bid1234'); - expect(bid.ad).to.equal('Ad html'); - }); - - it('validate_response_video_params', function () { - const serverResponse = { - body: [{ - mediaType: 2, - vastXml: 'vastXml', - }] - }; - const bids = spec.interpretResponse(serverResponse); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.mediaType).to.equal(2); - expect(bid.vastXml).to.equal('vastXml'); - }); - - it('validate response params without currency', function () { - const serverResponse = { - body: [{ - bidid: 'bid1234', - w: 240, - h: 400, - ad: 'Ad html' - }] - }; - const bids = spec.interpretResponse(serverResponse); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.currency).to.equal('USD'); - }); - it('check getUserSyncs', function() { - const syncs = spec.getUserSyncs({}, {}); - expect(syncs).to.be.an('array').that.to.have.lengthOf(2); - expect(syncs[0]).to.deep.equal({type: 'iframe', url: 'https://ads.betweendigital.com/sspmatch-iframe'}); - expect(syncs[1]).to.deep.equal({type: 'image', url: 'https://ads.betweendigital.com/sspmatch'}); - }); - - it('check sizes', function() { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'between', - mediaTypes: { - banner: { - sizes: [[970, 250], [240, 400], [728, 90]] - } - }, - params: { - s: 1112, - }, - }]; - - const request = spec.buildRequests(bidRequestData); - const req_data = JSON.parse(request.data)[0].data; - - expect(req_data.sizes).to.deep.equal(['970x250', '240x400', '728x90']) - }); - - it('check adomain', function() { - const serverResponse = { - body: [{ - bidid: 'bid1234', - cpm: 1.12, - w: 240, - h: 400, - currency: 'USD', - ad: 'Ad html', - adomain: ['domain1.com', 'domain2.com'] - }] - }; - const bids = spec.interpretResponse(serverResponse); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.meta.advertiserDomains).to.deep.equal(['domain1.com', 'domain2.com']); - }); - it('check server response without adomain', function() { - const serverResponse = { - body: [{ - bidid: 'bid1234', - cpm: 1.12, - w: 240, - h: 400, - currency: 'USD', - ad: 'Ad html', - }] - }; - const bids = spec.interpretResponse(serverResponse); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.meta.advertiserDomains).to.deep.equal([]); - }); -}); diff --git a/test/spec/modules/beyondmediaBidAdapter_spec.js b/test/spec/modules/beyondmediaBidAdapter_spec.js deleted file mode 100644 index 79bf88cb6..000000000 --- a/test/spec/modules/beyondmediaBidAdapter_spec.js +++ /dev/null @@ -1,466 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/beyondmediaBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'beyondmedia'; - -describe('AndBeyondMediaBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://backend.andbeyond.media/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cookies.andbeyond.media/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cookies.andbeyond.media/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cookies.andbeyond.media/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/bidResponseFilter_spec.js b/test/spec/modules/bidResponseFilter_spec.js index 6251fe352..e6ae0b180 100644 --- a/test/spec/modules/bidResponseFilter_spec.js +++ b/test/spec/modules/bidResponseFilter_spec.js @@ -11,6 +11,9 @@ import {addBidResponse} from '../../../src/auction.js'; describe('bidResponseFilter', () => { let mockAuctionIndex + before(() => { + addBidResponse.removeAll(); + }); beforeEach(() => { mockAuctionIndex = { getBidRequest: () => { diff --git a/test/spec/modules/biddoBidAdapter_spec.js b/test/spec/modules/biddoBidAdapter_spec.js deleted file mode 100644 index 25986b340..000000000 --- a/test/spec/modules/biddoBidAdapter_spec.js +++ /dev/null @@ -1,172 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/biddoBidAdapter.js'; - -describe('biddo bid adapter tests', function () { - describe('bid requests', function () { - it('should accept valid bid', function () { - const validBid = { - bidder: 'biddo', - params: {zoneId: 123}, - }; - - expect(spec.isBidRequestValid(validBid)).to.equal(true); - }); - - it('should reject invalid bid', function () { - const invalidBid = { - bidder: 'biddo', - params: {}, - }; - - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should correctly build payload string', function () { - const bidRequests = [{ - bidder: 'biddo', - params: {zoneId: 123}, - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - bidId: '23acc48ad47af5', - auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: '92489f71-1bf2-49a0-adf9-000cea934729', - }]; - const payload = spec.buildRequests(bidRequests)[0].data; - - expect(payload).to.contain('ctype=div'); - expect(payload).to.contain('pzoneid=123'); - expect(payload).to.contain('width=300'); - expect(payload).to.contain('height=250'); - }); - - it('should support multiple bids', function () { - const bidRequests = [{ - bidder: 'biddo', - params: {zoneId: 123}, - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - bidId: '23acc48ad47af5', - auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: '92489f71-1bf2-49a0-adf9-000cea934729', - }, { - bidder: 'biddo', - params: {zoneId: 321}, - mediaTypes: { - banner: { - sizes: [[728, 90]], - }, - }, - bidId: '23acc48ad47af52', - auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba992', - bidderRequestId: '1c56ad30b9b8ca82', - transactionId: '92489f71-1bf2-49a0-adf9-000cea9347292', - }]; - const payload = spec.buildRequests(bidRequests); - - expect(payload).to.be.lengthOf(2); - }); - - it('should support multiple sizes', function () { - const bidRequests = [{ - bidder: 'biddo', - params: {zoneId: 123}, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - bidId: '23acc48ad47af5', - auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: '92489f71-1bf2-49a0-adf9-000cea934729', - }]; - const payload = spec.buildRequests(bidRequests); - - expect(payload).to.be.lengthOf(2); - }); - }); - - describe('bid responses', function () { - it('should return complete bid response', function () { - const serverResponse = { - body: { - banner: { - hash: '1c56ad30b9b8ca8', - }, - hb: { - cpm: 0.5, - netRevenue: false, - adomains: ['securepubads.g.doubleclick.net'], - }, - template: { - html: '', - }, - }, - }; - const bidderRequest = { - bidId: '23acc48ad47af5', - params: { - requestedSizes: [300, 250], - }, - }; - - const bids = spec.interpretResponse(serverResponse, {bidderRequest}); - - expect(bids).to.be.lengthOf(1); - expect(bids[0].requestId).to.equal('23acc48ad47af5'); - expect(bids[0].creativeId).to.equal('1c56ad30b9b8ca8'); - expect(bids[0].width).to.equal(300); - expect(bids[0].height).to.equal(250); - expect(bids[0].ttl).to.equal(600); - expect(bids[0].cpm).to.equal(0.5); - expect(bids[0].netRevenue).to.equal(false); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].meta.advertiserDomains).to.be.lengthOf(1); - expect(bids[0].meta.advertiserDomains[0]).to.equal('securepubads.g.doubleclick.net'); - }); - - it('should return empty bid response', function () { - const serverResponse = { - body: {}, - }; - const bidderRequest = { - bidId: '23acc48ad47af5', - params: { - requestedSizes: [300, 250], - }, - }; - - const bids = spec.interpretResponse(serverResponse, {bidderRequest}); - - expect(bids).to.be.lengthOf(0); - }); - - it('should return empty bid response 2', function () { - const serverResponse = { - body: { - template: { - html: '', - } - }, - }; - const bidderRequest = { - bidId: '23acc48ad47af5', - params: { - requestedSizes: [300, 250], - }, - }; - - const bids = spec.interpretResponse(serverResponse, {bidderRequest}); - - expect(bids).to.be.lengthOf(0); - }); - }); -}); diff --git a/test/spec/modules/bidfuseBidAdapter_spec.js b/test/spec/modules/bidfuseBidAdapter_spec.js deleted file mode 100644 index 95c84dcdf..000000000 --- a/test/spec/modules/bidfuseBidAdapter_spec.js +++ /dev/null @@ -1,552 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/bidfuseBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; -import { config } from "../../../src/config.ts"; - -const bidder = 'bidfuse'; - -describe('BidfuseBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - const serverResponse = { - body: { - cid: 'testcid123', - results: [{ - 'ad': '', - 'price': 0.8, - 'creativeId': '12610997325162499419', - 'exp': 30, - 'width': 300, - 'height': 250, - 'advertiserDomains': ['securepubads.g.doubleclick.net'] - }] - } - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://bn.bidfuse.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('getUserSyncs', function () { - it('should have valid user sync with iframeEnabled', function () { - const result = spec.getUserSyncs({iframeEnabled: true}, [serverResponse]); - - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://syncbf.bidfuse.com/iframe?pbjs=1&coppa=0' - }]); - }); - - it('should have valid user sync with cid on response', function () { - const result = spec.getUserSyncs({iframeEnabled: true}, [serverResponse]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://syncbf.bidfuse.com/iframe?pbjs=1&coppa=0' - }]); - }); - - it('should have valid user sync with pixelEnabled', function () { - const result = spec.getUserSyncs({pixelEnabled: true}, [serverResponse]); - - expect(result).to.deep.equal([{ - 'url': 'https://syncbf.bidfuse.com/image?pbjs=1&coppa=0', - 'type': 'image' - }]); - }); - - it('should have valid user sync with coppa 1 on response', function () { - config.setConfig({ - coppa: 1 - }); - const result = spec.getUserSyncs({iframeEnabled: true}, [serverResponse]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://syncbf.bidfuse.com/iframe?pbjs=1&coppa=1' - }]); - }); - - it('should generate url with consent data', function () { - const gdprConsent = { - gdprApplies: true, - consentString: 'consent_string' - }; - const uspConsent = 'usp_string'; - const gppConsent = { - gppString: 'gpp_string', - applicableSections: [7] - } - - const result = spec.getUserSyncs({pixelEnabled: true}, [serverResponse], gdprConsent, uspConsent, gppConsent); - - expect(result).to.deep.equal([{ - 'url': 'https://syncbf.bidfuse.com/image?pbjs=1&gdpr=1&gdpr_consent=consent_string&gpp=gpp_string&gpp_sid=7&coppa=1', - 'type': 'image' - }]); - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); -}); diff --git a/test/spec/modules/bidmaticBidAdapter_spec.js b/test/spec/modules/bidmaticBidAdapter_spec.js deleted file mode 100644 index dfce07648..000000000 --- a/test/spec/modules/bidmaticBidAdapter_spec.js +++ /dev/null @@ -1,433 +0,0 @@ -import { expect } from 'chai'; -import { bidToTag, remapBidRequest, prepareBidRequests, createBid, parseResponseBody, getResponseSyncs, getUserSyncsFn, spec } from 'modules/bidmaticBidAdapter.js'; -import { config } from 'src/config.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { deepClone } from 'src/utils.js'; -import { BANNER, VIDEO } from 'src/mediaTypes.js'; - -describe('bidmaticBidAdapter', function () { - const adapter = newBidder(spec); - const URL = 'https://adapter.bidmatic.io/bdm/auction'; - - const DEFAULT_BID_REQUEST = { - 'bidder': 'bidmatic', - 'params': { - 'source': 123456 - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 600]] - } - }, - 'adUnitCode': 'test-div', - "ortb2Imp": { - "ext": { - "gpid": "123456/test-div" - } - }, - 'bidId': 'bid123456', - 'bidderRequestId': 'req123456', - 'auctionId': 'auct123456', - 'schain': { ver: '1.0' }, - 'userId': { id1: 'value1' }, - }; - - const VIDEO_BID_REQUEST = { - 'bidder': 'bidmatic', - 'params': { - 'source': 123456 - }, - "ortb2Imp": { - "ext": { - "gpid": "123456/test-div-video" - } - }, - 'mediaTypes': { - 'video': { - 'playerSize': [[640, 480]] - } - }, - 'adUnitCode': 'test-div-video', - 'bidId': 'bid123456-video', - 'bidderRequestId': 'req123456', - 'auctionId': 'auct123456', - }; - - const BID_RESPONSE = { - 'bids': [{ - 'requestId': 'bid123456', - 'cmpId': 'creative123', - 'height': 250, - 'width': 300, - 'cpm': 0.5, - 'ad': '
test ad
', - 'cur': 'USD', - 'adomain': ['advertiser.com'] - }], - 'cookieURLs': ['https://sync.bidmatic.com/sync1', 'https://sync.bidmatic.com/sync2'], - 'cookieURLSTypes': ['iframe', 'image'] - }; - - const VIDEO_BID_RESPONSE = { - 'bids': [{ - 'requestId': 'bid123456-video', - 'cmpId': 'creative123', - 'height': 480, - 'width': 640, - 'cpm': 0.5, - 'vastUrl': 'https://vast.bidmatic.com/vast.xml', - 'cur': 'USD', - 'adomain': ['advertiser.com'] - }], - 'cookieURLs': ['https://sync.bidmatic.com/sync1'] - }; - - const BID_REQUEST_PARAMS = { - 'bidderCode': 'bidmatic', - 'bidderRequestId': 'req123456', - 'auctionId': 'auct123456', - 'timeout': 1000, - 'refererInfo': { - 'page': 'https://example.com' - }, - 'bids': [DEFAULT_BID_REQUEST] - }; - - const CONSENTS_PARAMS = { - 'gdprConsent': { - 'gdprApplies': true, - 'consentString': 'CONSENT_STRING', - }, - 'gppConsent': { - 'gppString': 'GPP_STRING', - 'applicableSections': [1, 2, 3] - }, - 'uspConsent': 'USP_STRING', - 'ortb2': { - 'regs': { - 'coppa': 1, - 'gpp': 'GPP_FROM_ORTB2', - 'gpp_sid': [1, 2, 3], - 'ext': { - 'age_verification': { 'id': 'age123' } - } - } - } - }; - - const BID_REQUEST_WITH_CONSENT = { - ...BID_REQUEST_PARAMS, - ...CONSENTS_PARAMS - }; - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(DEFAULT_BID_REQUEST)).to.equal(true); - }); - - it('should return false when source is not a number', function () { - const bid = deepClone(DEFAULT_BID_REQUEST); - bid.params.source = '123456'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when params are missing', function () { - const bid = deepClone(DEFAULT_BID_REQUEST); - delete bid.params; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('prepareBidRequests', function () { - it('should prepare banner bid request correctly', function () { - const result = prepareBidRequests(DEFAULT_BID_REQUEST); - - expect(result).includes({ - 'CallbackId': 'bid123456', - 'Aid': 123456, - 'AdType': 'display', - 'PlacementId': 'test-div', - 'Sizes': '300x250,300x600', - 'GPID': '123456/test-div', - }); - }); - - it('should prepare video bid request correctly', function () { - const result = prepareBidRequests(VIDEO_BID_REQUEST); - - expect(result).includes({ - 'CallbackId': 'bid123456-video', - 'Aid': 123456, - 'AdType': 'video', - 'PlacementId': 'test-div-video', - 'Sizes': '640x480', - 'GPID': '123456/test-div-video', - }); - }); - }); - - describe('remapBidRequest', function () { - it('should remap bid request with basic params', function () { - const result = remapBidRequest([DEFAULT_BID_REQUEST], BID_REQUEST_PARAMS); - - expect(result).includes({ - 'Domain': 'https://example.com', - 'Tmax': 1000, - 'Coppa': 0 - }); - expect(result.Schain).to.deep.equal({ ver: '1.0' }); - expect(result.UserIds).to.deep.equal({ id1: 'value1' }); - }); - - it('should remap bid request with consent params', function () { - const result = remapBidRequest([DEFAULT_BID_REQUEST], BID_REQUEST_WITH_CONSENT); - - expect(result).to.include({ - 'Domain': 'https://example.com', - 'USP': 'USP_STRING', - 'GPP': 'GPP_STRING', - 'GPPSid': '1,2,3', - 'GDPRConsent': 'CONSENT_STRING', - 'GDPR': 1, - 'Coppa': 1 - }); - expect(result.AgeVerification).to.deep.equal({ id: 'age123' }); - }); - }); - - describe('bidToTag', function () { - it('should convert bid requests to tag format', function () { - const { tag, bids } = bidToTag([DEFAULT_BID_REQUEST], BID_REQUEST_PARAMS); - - expect(tag).to.be.an('object'); - expect(bids).to.be.an('array'); - expect(bids.length).to.equal(1); - expect(bids[0]).includes({ - 'CallbackId': 'bid123456', - 'Aid': 123456, - 'AdType': 'display', - 'PlacementId': 'test-div', - 'Sizes': '300x250,300x600', - 'GPID': '123456/test-div', - }); - }); - }); - - describe('buildRequests', function () { - it('should build banner request correctly', function () { - const requests = spec.buildRequests([DEFAULT_BID_REQUEST], BID_REQUEST_PARAMS); - - expect(requests).to.be.an('array'); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal(URL); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].data).to.have.property('BidRequests'); - expect(requests[0].data.BidRequests.length).to.equal(1); - }); - - it('should chunk bid requests according to adapter settings', function () { - const sandbox = sinon.createSandbox(); - sandbox.stub(config, 'getConfig').returns({ chunkSize: 2 }); - - const requests = spec.buildRequests([ - DEFAULT_BID_REQUEST, - deepClone(DEFAULT_BID_REQUEST), - deepClone(DEFAULT_BID_REQUEST) - ], BID_REQUEST_PARAMS); - - expect(requests.length).to.equal(2); - expect(requests[0].data.BidRequests.length).to.equal(2); - expect(requests[1].data.BidRequests.length).to.equal(1); - - sandbox.restore(); - }); - }); - - describe('createBid', function () { - it('should create banner bid correctly', function () { - const bid = createBid(BID_RESPONSE.bids[0], { mediaTypes: { banner: {} } }); - - expect(bid).to.deep.include({ - requestId: 'bid123456', - creativeId: 'creative123', - height: 250, - width: 300, - cpm: 0.5, - currency: 'USD', - netRevenue: true, - mediaType: BANNER, - ttl: 300, - ad: '
test ad
' - }); - - expect(bid.meta.advertiserDomains).to.deep.equal(['advertiser.com']); - }); - - it('should create video bid correctly', function () { - const bid = createBid(VIDEO_BID_RESPONSE.bids[0], { mediaTypes: { video: {} } }); - - expect(bid).to.deep.include({ - requestId: 'bid123456-video', - creativeId: 'creative123', - height: 480, - width: 640, - cpm: 0.5, - currency: 'USD', - netRevenue: true, - mediaType: VIDEO, - ttl: 300, - vastUrl: 'https://vast.bidmatic.com/vast.xml' - }); - }); - }); - - describe('parseResponseBody', function () { - it('should parse valid response', function () { - const result = parseResponseBody(BID_RESPONSE, { bids: [DEFAULT_BID_REQUEST] }); - - expect(result).to.be.an('array'); - expect(result.length).to.equal(1); - expect(result[0]).to.have.property('requestId', 'bid123456'); - }); - - it('should return empty array for invalid response', function () { - const result = parseResponseBody({}, { bids: [DEFAULT_BID_REQUEST] }); - expect(result).to.be.an('array'); - expect(result.length).to.equal(0); - }); - - it('should return empty array when bid request does not match', function () { - const result = parseResponseBody({ - bids: [{ requestId: 'non-matching-id' }] - }, { bids: [DEFAULT_BID_REQUEST] }); - - expect(result).to.be.an('array'); - expect(result.length).to.equal(0); - }); - }); - - describe('getResponseSyncs', function () { - it('should return image syncs when pixels enabled', function () { - const syncOptions = { pixelEnabled: true }; - const bid = { - cookieURLSTypes: ['image'], - cookieURLs: ['https://sync.bidmatic.com/pixel'] - }; - - const result = getResponseSyncs(syncOptions, bid); - - expect(result).to.be.an('array'); - expect(result.length).to.equal(1); - expect(result[0].type).to.equal('image'); - expect(result[0].url).to.equal('https://sync.bidmatic.com/pixel'); - }); - - it('should return iframe syncs when iframes enabled', function () { - const syncOptions = { iframeEnabled: true }; - const bid = { - cookieURLSTypes: ['iframe'], - cookieURLs: ['https://sync.bidmatic.com/iframe'] - }; - - const result = getResponseSyncs(syncOptions, bid); - - expect(result).to.be.an('array'); - expect(result.length).to.equal(1); - expect(result[0].type).to.equal('iframe'); - expect(result[0].url).to.equal('https://sync.bidmatic.com/iframe'); - }); - - it('should not return syncs when already done', function () { - const syncOptions = { iframeEnabled: true }; - const bid = { - cookieURLSTypes: ['iframe'], - cookieURLs: ['https://sync.bidmatic.com/sync-done'] - }; - - let result = getResponseSyncs(syncOptions, bid); - expect(result.length).to.equal(1); - - result = getResponseSyncs(syncOptions, bid); - expect(result.length).to.equal(0); - }); - - it('should use default type image when type not specified', function () { - const syncOptions = { pixelEnabled: true }; - const bid = { - cookieURLs: ['https://sync.bidmatic.com/new-pixel'] - }; - - const result = getResponseSyncs(syncOptions, bid); - - expect(result.length).to.equal(1); - expect(result[0].type).to.equal('image'); - }); - }); - - describe('getUserSyncsFn', function () { - it('should return empty array when no syncs enabled', function () { - const result = getUserSyncsFn({}, []); - expect(result).to.be.undefined; - }); - - it('should return empty array for invalid responses', function () { - const result = getUserSyncsFn({ pixelEnabled: true }, [{ body: null }]); - expect(result).to.be.an('array'); - expect(result.length).to.equal(0); - }); - - it('should collect syncs from multiple responses', function () { - const syncOptions = { pixelEnabled: true, iframeEnabled: true }; - const serverResponses = [ - { body: { cookieURLs: ['https://sync1.bidmatic.com/pixel'] } }, - { body: [ - { cookieURLs: ['https://sync2.bidmatic.com/iframe'], cookieURLSTypes: ['iframe'] } - ]} - ]; - - const result = getUserSyncsFn(syncOptions, serverResponses); - - expect(result).to.be.an('array'); - expect(result.length).to.equal(2); - }); - }); - - describe('interpretResponse', function () { - it('should interpret banner response correctly', function () { - const result = spec.interpretResponse({ body: BID_RESPONSE }, { adapterRequest: { bids: [DEFAULT_BID_REQUEST] } }); - - expect(result).to.be.an('array'); - expect(result.length).to.equal(1); - expect(result[0].requestId).to.equal('bid123456'); - expect(result[0].mediaType).to.equal(BANNER); - }); - - it('should interpret video response correctly', function () { - const result = spec.interpretResponse({ body: VIDEO_BID_RESPONSE }, { adapterRequest: { bids: [VIDEO_BID_REQUEST] } }); - - expect(result).to.be.an('array'); - expect(result.length).to.equal(1); - expect(result[0].requestId).to.equal('bid123456-video'); - expect(result[0].mediaType).to.equal(VIDEO); - }); - - it('should handle array of responses', function () { - const result = spec.interpretResponse({ body: [BID_RESPONSE] }, { adapterRequest: { bids: [DEFAULT_BID_REQUEST] } }); - - expect(result).to.be.an('array'); - expect(result.length).to.equal(1); - }); - - it('should return empty array for empty response', function () { - const result = spec.interpretResponse({ body: { bids: [] } }, { adapterRequest: { bids: [DEFAULT_BID_REQUEST] } }); - expect(result).to.be.an('array'); - expect(result.length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/bidscubeBidAdapter_spec.js b/test/spec/modules/bidscubeBidAdapter_spec.js deleted file mode 100644 index 26cf19fc3..000000000 --- a/test/spec/modules/bidscubeBidAdapter_spec.js +++ /dev/null @@ -1,226 +0,0 @@ -import { expect } from 'chai' -import { spec } from '../../../modules/bidscubeBidAdapter.js' -import { deepStrictEqual, notEqual, ok, strictEqual } from 'assert' - -describe('BidsCubeAdapter', () => { - const bid = { - bidId: '9ec5b177515ee2e5', - bidder: 'bidscube', - params: { - placementId: 0, - traffic: 'banner', - allParams: '{}' - } - } - - describe('isBidRequestValid', () => { - it('Should return true if there are bidId, params and placementId parameters present', () => { - strictEqual(true, spec.isBidRequestValid(bid)) - }) - - it('Should return false if at least one of parameters is not present', () => { - const b = { ...bid } - delete b.params.placementId - strictEqual(false, spec.isBidRequestValid(b)) - }) - }) - - describe('buildRequests', () => { - const serverRequest = spec.buildRequests([bid]) - - it('Creates a ServerRequest object with method, URL and data', () => { - ok(serverRequest) - ok(serverRequest.method) - ok(serverRequest.url) - ok(serverRequest.data) - }) - - it('Returns POST method', () => { - strictEqual('POST', serverRequest.method) - }) - - it('Returns valid URL', () => { - strictEqual('https://supply.bidscube.com/?c=o&m=multi', serverRequest.url) - }) - - it('Returns valid data if array of bids is valid', () => { - const { data } = serverRequest - strictEqual('object', typeof data) - deepStrictEqual(['deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements'], Object.keys(data)) - strictEqual('number', typeof data.deviceWidth) - strictEqual('number', typeof data.deviceHeight) - strictEqual('string', typeof data.language) - strictEqual('string', typeof data.host) - strictEqual('string', typeof data.page) - notEqual(-1, [0, 1].indexOf(data.secure)) - - const placement = data.placements[0] - deepStrictEqual(['placementId', 'bidId', 'traffic', 'allParams'], Object.keys(placement)) - strictEqual(0, placement.placementId) - strictEqual('9ec5b177515ee2e5', placement.bidId) - strictEqual('banner', placement.traffic) - strictEqual('{"bidId":"9ec5b177515ee2e5","bidder":"bidscube","params":{"placementId":0,"traffic":"banner","allParams":"{}"}}', placement.allParams) - }) - - it('Returns empty data if no valid requests are passed', () => { - const { placements } = spec.buildRequests([]).data - - expect(spec.buildRequests([]).data.placements).to.be.an('array') - strictEqual(0, placements.length) - }) - }) - - describe('interpretResponse', () => { - const validData = [ - { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '9ec5b177515ee2e5', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['test.com'] - } - }] - }, - { - body: [{ - vastUrl: 'bidscube.com', - mediaType: 'video', - cpm: 0.5, - requestId: '9ec5b177515ee2e5', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['test.com'] - } - }] - }, - { - body: [{ - mediaType: 'native', - clickUrl: 'bidscube.com', - title: 'Test', - image: 'bidscube.com', - creativeId: '2', - impressionTrackers: ['bidscube.com'], - ttl: 120, - cpm: 0.4, - requestId: '9ec5b177515ee2e5', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['test.com'] - } - }] - } - ] - - for (const obj of validData) { - const { mediaType } = obj.body[0] - - it(`Should interpret ${mediaType} response`, () => { - const response = spec.interpretResponse(obj) - - expect(response).to.be.an('array') - strictEqual(1, response.length) - - const copy = { ...obj.body[0] } - deepStrictEqual(copy, response[0]) - }) - } - - for (const obj of validData) { - it(`Should interpret response has meta.advertiserDomains`, () => { - const response = spec.interpretResponse(obj) - - expect(response[0]['meta']['advertiserDomains']).to.be.an('array') - expect(response[0]['meta']['advertiserDomains'][0]).to.be.an('string') - }) - } - - const invalidData = [ - { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '9ec5b177515ee2e5', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }, - { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '9ec5b177515ee2e5', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }, - { - body: [{ - mediaType: 'native', - clickUrl: 'bidscube.com', - title: 'Test', - impressionTrackers: ['bidscube.com'], - ttl: 120, - requestId: '9ec5b177515ee2e5', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - } - ] - - for (const obj of invalidData) { - const { mediaType } = obj.body[0] - - it(`Should return an empty array if invalid ${mediaType} response is passed `, () => { - const response = spec.interpretResponse(obj) - - expect(response).to.be.an('array') - strictEqual(0, response.length) - }) - } - - it('Should return an empty array if invalid response is passed', () => { - const response = spec.interpretResponse({ - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }) - - expect(response).to.be.an('array') - strictEqual(0, response.length) - }) - }) - - describe('getUserSyncs', () => { - it('Returns valid URL and type', () => { - const expectedResult = [{ type: 'image', url: 'https://supply.bidscube.com/?c=o&m=cookie' }] - deepStrictEqual(expectedResult, spec.getUserSyncs()) - }) - }) -}) diff --git a/test/spec/modules/bidtheatreBidAdapter_spec.js b/test/spec/modules/bidtheatreBidAdapter_spec.js deleted file mode 100644 index 351f59680..000000000 --- a/test/spec/modules/bidtheatreBidAdapter_spec.js +++ /dev/null @@ -1,266 +0,0 @@ -import { expect } from 'chai'; -import { spec, ENDPOINT_URL, BIDDER_CODE, DEFAULT_CURRENCY } from 'modules/bidtheatreBidAdapter.js'; -import { BANNER, VIDEO } from 'src/mediaTypes.js'; -import { deepClone } from 'src/utils.js'; - -const VALID_PUBLISHER_ID = '73b20b3a-12a0-4869-b54e-8d42b55786ee'; -const STATIC_IMP_ID = '3263e5dec855c5'; -const BID_PRICE = 5.112871170043945; -const AUCTION_PRICE_MACRO = '${AUCTION_PRICE}'; - -const BANNER_BID_REQUEST = [ - { - 'bidder': BIDDER_CODE, - 'params': { - 'publisherId': VALID_PUBLISHER_ID - }, - 'bidId': STATIC_IMP_ID, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 980, - 240 - ] - ] - } - }, - 'sizes': [ - [ - 980, - 240 - ] - ] - } -]; - -const BANNER_BIDDER_REQUEST = {'bidderCode': BIDDER_CODE, 'bids': BANNER_BID_REQUEST}; - -const BANNER_BID_RESPONSE = { - 'cur': 'USD', - 'seatbid': [ - { - 'seat': '5', - 'bid': [ - { - 'ext': { - 'usersync_urls': [ - 'https://match.adsby.bidtheatre.com/usersync?gdpr=1&gdpr_consent=CONSENT_STRING' - ] - }, - 'crid': '1915538', - 'h': 240, - 'adm': "", - 'mtype': 1, - 'adid': '1915538', - 'adomain': [ - 'bidtheatre.com' - ], - 'price': BID_PRICE, - 'cat': [ - 'IAB3-1' - ], - 'w': 980, - 'id': STATIC_IMP_ID, - 'impid': STATIC_IMP_ID, - 'cid': 'c154375' - } - ] - } - ] -}; - -const VIDEO_BID_REQUEST = [ - { - 'bidder': BIDDER_CODE, - 'params': { - 'publisherId': VALID_PUBLISHER_ID - }, - 'bidId': STATIC_IMP_ID, - 'mediaTypes': { - 'video': { - 'playerSize': [ - [ - 1280, - 720 - ] - ], - 'context': 'instream' - } - }, - 'sizes': [[1280, 720]] - } -]; - -const VIDEO_BIDDER_REQUEST = {'bidderCode': BIDDER_CODE, 'bids': VIDEO_BID_REQUEST}; - -const VIDEO_BID_RESPONSE = { - 'cur': 'USD', - 'seatbid': [ - { - 'seat': '5', - 'bid': [ - { - 'ext': { - 'usersync_urls': [ - 'https://match.adsby.bidtheatre.com/usersync?gdpr=0&gdpr_consent=' - ] - }, - 'crid': '1922926', - 'h': 720, - 'mtype': 2, - 'nurl': 'https://adsby.bidtheatre.com/video?z=27025;a=1922926;ex=36;es=http%3A%2F%2F127.0.0.1%3A8080;eb=3672319;xs=940400838;so=1;tag=unspec_1280_720;kuid=05914b22-88cb-4c5d-9f7c-f133fdf9669a;wp=${AUCTION_PRICE};su=127.0.0.1%3A8080;iab=vast2;dealId=;ma=eyJjZCI6ZmFsc2UsInN0IjozLCJtbGF0Ijo1OS4yNywibW9yZyI6InRlbGlhIG5ldHdvcmsgc2VydmljZXMiLCJtbHNjb3JlIjowLjg2MDcwMDU0NzY5NTE1OTksIm16aXAiOiIxMjggMzUiLCJiaXAiOiI4MS4yMjcuODIuMjgiLCJhZ2lkIjozNTYyNzAyLCJtbG1vZGVsIjoibWFzdGVyX21sX2Nsa181MzYiLCJ1YSI6Ik1vemlsbGFcLzUuMCAoTWFjaW50b3NoOyBJbnRlbCBNYWMgT1MgWCAxMF8xNV83KSBBcHBsZVdlYktpdFwvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hyb21lXC8xMzAuMC4wLjAgU2FmYXJpXC81MzcuMzYiLCJtbG9uIjoxOC4xMywibXJlZ2lvbiI6ImFiIiwiZHQiOjEsIm1jaXR5Ijoic2thcnBuYWNrIiwicGFnZXVybCI6Imh0dHA6XC9cLzEyNy4wLjAuMTo4MDgwXC92aWRlby5odG1sP3BianNfZGVidWc9dHJ1ZSIsImltcGlkIjoieDM2X2FzeC1iLXMyXzQxNDMzMTA0MTIyMzUyNTU3NDgiLCJtY291bnRyeSI6InN3ZSIsInRzIjoxNzMxNTA3NTY5Njg3fQ%3D%3D;cd=0;cb0=;impId=x36_asx-b-s2_4143310412235255748;gdpr=1;gdpr_consent=CP-S4UAP-S4UACGABBENAzEsAP_gAEPgAAAAKKtV_H__bW1r8X73aft0eY1P9_j77sQxBhfJE-4FzLvW_JwXx2ExNA36tqIKmRIEu3bBIQNlHJDUTVCgaogVryDMakWcoTNKJ6BkiFMRO2dYCF5vmwtj-QKY5vr993dx2D-t_dv83dzyz4VHn3a5_2e0WJCdA58tDfv9bROb-9IPd_58v4v0_F_rE2_eT1l_tevp7D9-ct87_XW-9_fff79Ll9-goqAWYaFRAHWBISEGgYRQIAVBWEBFAgAAABIGiAgBMGBTsDAJdYSIAQAoABggBAACjIAEAAAEACEQAQAFAgAAgECgABAAgEAgAIGAAEAFgIBAACA6BCmBBAoFgAkZkRCmBCFAkEBLZUIJAECCuEIRZ4AEAiJgoAAAAACsAAQFgsDiSQEqEggS4g2gAAIAEAghAqEEnJgACBI2WoPBE2jK0gDQ04SAAAAA.YAAAAAAAAAAA', - 'adid': '1922926', - 'adomain': [ - 'bidtheatre.com' - ], - 'price': BID_PRICE, - 'cat': [ - 'IAB3-1' - ], - 'w': 1280, - 'id': STATIC_IMP_ID, - 'impid': STATIC_IMP_ID, - 'cid': 'c154375' - } - ] - } - ] -} - -describe('BidtheatreAdapter', function () { - describe('isBidRequestValid', function () { - const bid = { - 'bidder': BIDDER_CODE, - 'params': { - 'publisherId': VALID_PUBLISHER_ID - }, - 'sizes': [[980, 240]] - }; - - it('should return true when required param found and of correct type', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required param is not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when required param of incorrect data type', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'publisherId': 12345 - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when required param of incorrect length', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'publisherId': '73b20b3a-12a0-4869-b54e-8d42b55786e' - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('should include correct http method, correct url and existing data', function () { - const request = spec.buildRequests(BANNER_BID_REQUEST, BANNER_BIDDER_REQUEST); - expect(request[0].method).to.equal('POST'); - expect(request[0].url).to.equal(ENDPOINT_URL); - expect(request[0].data).to.exist; - }); - - it('should include required bid param in request', function () { - const request = spec.buildRequests(BANNER_BID_REQUEST, BANNER_BIDDER_REQUEST); - const data = request[0].data; - expect(data.imp[0].ext.bidder.publisherId).to.equal(VALID_PUBLISHER_ID); - }); - - it('should include imp array in request', function () { - const request = spec.buildRequests(BANNER_BID_REQUEST, BANNER_BIDDER_REQUEST); - const data = request[0].data; - expect(data).to.have.property('imp').that.is.an('array').with.lengthOf.at.least(1); - expect(data.imp[0]).to.be.an('object'); - }); - }); - - describe('interpretResponse', function () { - it('should have exactly one bid in banner response', function () { - const request = spec.buildRequests(BANNER_BID_REQUEST, BANNER_BIDDER_REQUEST); - const bids = spec.interpretResponse({body: BANNER_BID_RESPONSE}, request[0]); - expect(bids).to.be.an('array').with.lengthOf(1); - expect(bids[0]).to.be.an('object'); - }); - - it('should have currency set to USD in banner response', function () { - const request = spec.buildRequests(BANNER_BID_REQUEST, BANNER_BIDDER_REQUEST); - const bids = spec.interpretResponse({body: BANNER_BID_RESPONSE}, request[0]); - expect(bids[0].currency).to.be.a('string').and.to.equal(DEFAULT_CURRENCY); - }); - - it('should have ad in response and auction price macros replaced in banner response', function () { - const request = spec.buildRequests(BANNER_BID_REQUEST, BANNER_BIDDER_REQUEST); - const bids = spec.interpretResponse({body: BANNER_BID_RESPONSE}, request[0]); - const ad = bids[0].ad; - expect(ad).to.exist; - expect(ad).to.be.a('string'); - expect(ad).to.include('&wp=' + BID_PRICE + '&'); - expect(ad).to.not.include(AUCTION_PRICE_MACRO); - }); - - if (FEATURES.VIDEO) { - it('should have exactly one bid in video response', function () { - const request = spec.buildRequests(VIDEO_BID_REQUEST, VIDEO_BIDDER_REQUEST); - const bids = spec.interpretResponse({body: VIDEO_BID_RESPONSE}, request[0]); - expect(bids).to.be.an('array').with.lengthOf(1); - expect(bids[0]).to.be.an('object'); - }); - - it('should have currency set to USD in video response', function () { - const request = spec.buildRequests(VIDEO_BID_REQUEST, VIDEO_BIDDER_REQUEST); - const bids = spec.interpretResponse({body: VIDEO_BID_RESPONSE}, request[0]); - expect(bids[0].currency).to.be.a('string').and.to.equal(DEFAULT_CURRENCY); - }); - - it('should have vastUrl in response and auction price macros replaced in video response', function () { - const request = spec.buildRequests(VIDEO_BID_REQUEST, VIDEO_BIDDER_REQUEST); - const bids = spec.interpretResponse({body: VIDEO_BID_RESPONSE}, request[0]); - const vastUrl = bids[0].vastUrl; - expect(vastUrl).to.exist; - expect(vastUrl).to.be.a('string'); - expect(vastUrl).to.include(';wp=' + BID_PRICE + ';'); - expect(vastUrl).to.not.include(AUCTION_PRICE_MACRO); - }); - } - }); - - describe('getUserSyncs', function () { - const bidResponse = deepClone(BANNER_BID_RESPONSE); - const bidResponseSyncURL = bidResponse.seatbid[0].bid[0].ext.usersync_urls[0]; - - const gdprConsent = { - gdprApplies: true, - consentString: 'CONSENT_STRING' - }; - - it('should return empty when pixel is disallowed', function () { - expect(spec.getUserSyncs({ pixelEnabled: false }, bidResponse, gdprConsent)).to.be.empty; - }); - - it('should return empty when no server response is present', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, [], gdprConsent)).to.be.empty; - }); - - it('should return usersync url when pixel is allowed and present in bid response', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, [{body: bidResponse}], gdprConsent)).to.deep.equal([{ type: 'image', url: bidResponseSyncURL }]); - }); - }); -}); diff --git a/test/spec/modules/big-richmediaBidAdapter_spec.js b/test/spec/modules/big-richmediaBidAdapter_spec.js deleted file mode 100644 index ffddad000..000000000 --- a/test/spec/modules/big-richmediaBidAdapter_spec.js +++ /dev/null @@ -1,273 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/big-richmediaBidAdapter.js'; -import { auctionManager } from 'src/auctionManager.js'; -import * as bidderFactory from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import { deepClone } from 'src/utils.js'; - -describe('bigRichMediaAdapterTests', function () { - before(function () { - config.setConfig({ - bigRichmedia: { - publisherId: '123ABC' - } - }); - }); - - after(function () { - config.resetConfig(); - }); - - describe('bidRequestValidity', function () { - const bid = { - 'bidder': 'bigRichmedia', - 'params': { - 'placementId': '10433394' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - - it('bidRequest with zoneId and deliveryUrl params', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('bidRequest with no params is not valid', function () { - const localBid = Object.assign({}, bid); - localBid.params = {}; - expect(spec.isBidRequestValid(localBid)).to.equal(false); - }); - }); - - describe('bidRequest', function () { - let getAdUnitsStub; - const bidRequests = [ - { - 'bidder': 'bigRichmedia', - 'params': { - 'placementId': '10433394' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 600], [1800, 1000]] - } - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600], [1800, 1000]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'transactionId': '04f2659e-c005-4eb1-a57c-fa93145e3843' - } - ]; - - beforeEach(function() { - getAdUnitsStub = sinon.stub(auctionManager, 'getAdUnits').callsFake(function() { - return []; - }); - }); - - afterEach(function() { - getAdUnitsStub.restore(); - }); - - it('should have skin size', function () { - const bidRequest = Object.assign({}, - bidRequests[0], - { - params: { - placementId: '10433394', - format: 'skin' - } - } - ); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].sizes).to.exist; - expect(payload.tags[0].sizes).to.have.lengthOf(3); - }); - - if (FEATURES.VIDEO) { - it('should build video bid request', function() { - const bidRequest = deepClone(bidRequests[0]); - bidRequest.params = { - placementId: '1234235', - video: { - skippable: true, - playback_method: ['auto_play_sound_off', 'auto_play_sound_unknown'], - context: 'outstream', - format: 'sticky-top' - } - }; - bidRequest.mediaTypes = { - video: { - playerSize: [640, 480], - context: 'outstream', - mimes: ['video/mp4'], - skip: 0, - minduration: 5, - api: [1, 5, 6], - playbackmethod: [2, 4] - } - }; - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.tags[0].video).to.deep.equal({ - minduration: 5, - playback_method: 2, - skippable: true, - context: 4 - }); - expect(payload.tags[0].video_frameworks).to.deep.equal([1, 4]) - }); - } - }); - - describe('interpretResponse', function () { - const response = { - 'version': '3.0.0', - 'tags': [ - { - 'uuid': '3db3773286ee59', - 'tag_id': 10433394, - 'auction_id': '4534722592064951574', - 'nobid': false, - 'no_ad_url': 'https://lax1-ib.adnxs.com/no-ad', - 'timeout_ms': 10000, - 'ad_profile_id': 27079, - 'ads': [ - { - 'content_source': 'rtb', - 'ad_type': 'banner', - 'buyer_member_id': 958, - 'creative_id': 29681110, - 'media_type_id': 1, - 'media_subtype_id': 1, - 'cpm': 0.5, - 'cpm_publisher_currency': 0.5, - 'publisher_currency_code': '$', - 'client_initiated_ad_counting': true, - 'viewability': { - 'config': '' - }, - 'rtb': { - 'banner': { - 'content': '', - 'width': 300, - 'height': 250 - }, - 'trackers': [ - { - 'impression_urls': [ - 'https://lax1-ib.adnxs.com/impression', - 'https://www.test.com/tracker' - ], - 'video_events': {} - } - ] - } - } - ] - } - ] - }; - - it('should get correct bid response', function () { - const expectedResponse = [ - { - 'adId': '3a1f23123e', - 'requestId': '3db3773286ee59', - 'cpm': 0.5, - 'creativeId': 29681110, - 'dealId': undefined, - 'width': 300, - 'height': 250, - 'ad': '', - 'mediaType': 'banner', - 'currency': 'USD', - 'ttl': 300, - 'netRevenue': true, - 'adUnitCode': 'code', - 'appnexus': { - 'buyerMemberId': 958 - }, - 'meta': { - 'dchain': { - 'ver': '1.0', - 'complete': 0, - 'nodes': [{ - 'bsid': '958' - }] - } - } - } - ]; - const bidderRequest = { - bids: [{ - bidId: '3db3773286ee59', - adUnitCode: 'code' - }] - }; - const result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - - if (FEATURES.VIDEO) { - it('handles outstream video responses', function () { - const response = { - 'tags': [{ - 'uuid': '84ab500420319d', - 'ads': [{ - 'ad_type': 'video', - 'cpm': 0.500000, - 'notify_url': 'imptracker.com', - 'rtb': { - 'video': { - 'content': '' - } - }, - 'javascriptTrackers': '' - }] - }] - }; - const bidderRequest = { - bids: [{ - bidId: '84ab500420319d', - adUnitCode: 'code', - mediaTypes: { - video: { - context: 'outstream' - } - } - }] - } - - const result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(result[0]).not.to.have.property('vastXml'); - expect(result[0]).not.to.have.property('vastUrl'); - expect(result[0]).to.have.property('width', 1); - expect(result[0]).to.have.property('height', 1); - expect(result[0]).to.have.property('mediaType', 'banner'); - }); - } - }); - - describe('getUserSyncs', function() { - const syncOptions = { - syncEnabled: false - }; - - it('should not return sync', function() { - const serverResponse = [{ body: '' }]; - const result = spec.getUserSyncs(syncOptions, serverResponse); - expect(result).to.be.undefined; - }); - }); -}); diff --git a/test/spec/modules/bitmediaBidAdapter_spec.js b/test/spec/modules/bitmediaBidAdapter_spec.js deleted file mode 100644 index 537ae3835..000000000 --- a/test/spec/modules/bitmediaBidAdapter_spec.js +++ /dev/null @@ -1,499 +0,0 @@ -import {expect} from 'chai'; -import {spec, STORAGE, ENDPOINT_URL} from 'modules/bitmediaBidAdapter.js'; -import * as utils from 'src/utils.js'; -import {config} from 'src/config.js'; -import {BANNER} from '../../../src/mediaTypes.js'; - -describe('Bitmedia Bid Adapter', function () { - const createBidRequest = (sandbox, overrides = {}) => { - return Object.assign({ - bidder: 'bitmedia', - params: { - adUnitID: 'test-ad-unit-id', - currency: 'USD' - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'bid123', - auctionId: 'auction123', - transactionId: 'transaction123', - adUnitCode: 'adunit123', - sizes: [[300, 250], [300, 600]], - getFloor: sandbox.stub().returns({ - currency: 'USD', - floor: 0.4 - }) - }, overrides); - } - - const createBidderRequest = (overrides = {}) => { - return Object.assign({ - refererInfo: { - page: 'https://example.com/page.html', - domain: 'example.com', - referer: 'https://google.com' - }, - timeout: 2000, - bidderCode: 'bitmedia', - auctionId: 'auction123', - ortb2: { - site: { - domain: 'publisher.com', - page: 'https://publisher.com/homepage.html', - publisher: { - domain: 'publisher.com' - } - }, - device: { - ua: 'custom-user-agent', - language: 'fr' - } - } - }, overrides); - } - // Helper function to stub storage for user ID - const stubStorage = (sandbox, userIdInLocalStorage = null, userIdInCookies = null) => { - sandbox.stub(STORAGE, 'hasLocalStorage').returns(true); - sandbox.stub(STORAGE, 'getDataFromLocalStorage') - .withArgs('bitmedia_fid') - .returns(userIdInLocalStorage); - - sandbox.stub(STORAGE, 'cookiesAreEnabled').returns(true); - sandbox.stub(STORAGE, 'getCookie') - .withArgs('bitmedia_fid') - .returns(userIdInCookies); - - if (userIdInLocalStorage || userIdInCookies) { - const encodedFid = userIdInLocalStorage || userIdInCookies; - sandbox.stub(window, 'atob') - .withArgs(encodedFid) - .returns(`{"fid":"user123"}`); - } - } - - describe('isBidRequestValid', function () { - let bid; - beforeEach(function () { - bid = { - bidder: 'bitmedia', - params: { - adUnitID: 'test-ad-unit-id', - currency: 'USD' - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - } - }; - }); - - it('should return true when required params found and sizes are valid', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false if adUnitID is missing', function () { - delete bid.params.adUnitID; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if currency is invalid', function () { - bid.params.currency = 'EUR'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if no valid sizes provided', function () { - bid.mediaTypes.banner.sizes = [[123, 456], [789, 101]]; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if mediaTypes.banner is missing', function () { - delete bid.mediaTypes.banner; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if banner sizes are not an array', function () { - bid.mediaTypes.banner.sizes = '300x250'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if bid params are missing', function () { - delete bid.params; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - let sandbox; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - - // Stub generateUUID to return a fixed value for testing - sandbox.stub(utils, 'generateUUID').returns('test-generated-uuid'); - - // Stub config.getConfig for bidderTimeout - sandbox.stub(config, 'getConfig').withArgs('bidderTimeout').returns(30); - }); - - afterEach(function () { - sandbox.restore(); - }); - describe('when building the request', function () { - let bidRequests; - let bidderRequest; - let requests; - let request; - let data; - - beforeEach(function () { - bidRequests = [createBidRequest(sandbox,)]; - bidderRequest = createBidderRequest(); - stubStorage(sandbox, null, 'encodedFidString'); // User ID in cookies - - requests = spec.buildRequests(bidRequests, bidderRequest); - request = requests[0]; - data = request.data; - }); - - it('should return an array with one request', function () { - expect(requests).to.be.an('array').with.lengthOf(1); - }); - - it('should have method POST and the correct URL', function () { - expect(request.method).to.equal('POST'); - expect(request.url).to.equal(`${ENDPOINT_URL}${bidRequests[0].params.adUnitID}`); - }); - - it('should have the correct request options', function () { - expect(request.options).to.deep.equal({ - withCredentials: false, - crossOrigin: true - }); - }); - - it('should have the correct request data structure', function () { - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('id', 'imp', 'site', 'device', 'cur', 'tmax', 'ext', 'user'); - }); - - it('should include the generated UUID in the request data', function () { - expect(data.id).to.equal('test-generated-uuid'); - }); - - it('should include the correct impressions in the request data', function () { - expect(data.imp).to.be.an('array').with.lengthOf(2); - - const expectedImp1 = { - id: 'bid123', - tagid: 'test-ad-unit-id', - banner: { - w: 300, - h: 250 - }, - bidfloor: 0.4, - bidfloorcur: 'USD' - }; - - const expectedImp2 = { - id: 'bid123', - tagid: 'test-ad-unit-id', - banner: { - w: 300, - h: 600 - }, - bidfloor: 0.4, - bidfloorcur: 'USD' - }; - - expect(data.imp[0]).to.deep.equal(expectedImp1); - expect(data.imp[1]).to.deep.equal(expectedImp2); - }); - - it('should include the correct site information', function () { - expect(data.site).to.deep.equal({ - domain: 'publisher.com', - page: 'https://publisher.com/homepage.html', - publisher: { - domain: 'publisher.com' - } - }); - }); - - it('should include the correct device information', function () { - expect(data.device).to.deep.equal({ - ua: 'custom-user-agent', - language: 'fr' - }); - }); - - it('should include the default currency', function () { - expect(data.cur).to.deep.equal(['USD']); - }); - - it('should include the correct timeout (tmax)', function () { - expect(data.tmax).to.equal(2000); - }); - - it('should include the ext field with adapter_version and prebid_version as strings', function () { - expect(data.ext.adapter_version).to.be.a('string'); - expect(data.ext.prebid_version).to.be.a('string'); - }); - - it('should include the user ID when present in cookies', function () { - expect(data.user).to.deep.equal({ - id: 'user123' - }); - }); - }); - - describe('when some invalid sizes are provided', function () { - let bidRequests; - let bidderRequest; - let requests; - let request; - let data; - - beforeEach(function () { - bidRequests = [createBidRequest(sandbox, { - mediaTypes: { - banner: { - sizes: [[300, 600], [888, 888]], - }, - }, - sizes: [[300, 600], [888, 888]], - })]; - bidderRequest = createBidderRequest(); - stubStorage(sandbox, null, null); - - requests = spec.buildRequests(bidRequests, bidderRequest); - request = requests[0]; - data = request.data; - }); - - it('should not build imp with invalid size', function () { - expect(data.imp).to.be.an('array').with.lengthOf(1); - }); - }); - - describe('when user ID is absent', function () { - let bidRequests; - let bidderRequest; - let requests; - let data; - - beforeEach(function () { - bidRequests = [createBidRequest(sandbox,)]; - bidderRequest = createBidderRequest(); - stubStorage(sandbox, null, null); - - requests = spec.buildRequests(bidRequests, bidderRequest); - data = requests[0].data; - }); - - it('should not include user ID in the request data', function () { - expect(data.user).to.be.undefined; - }); - }); - - describe('when getFloor is not available', function () { - let bidRequests; - let bidderRequest; - let requests; - let imp; - - beforeEach(function () { - bidRequests = [createBidRequest(sandbox, { - getFloor: undefined - })]; - bidderRequest = createBidderRequest(); - - requests = spec.buildRequests(bidRequests, bidderRequest); - imp = requests[0].data.imp; - }); - - it('should not include bidfloor in imp objects', function () { - imp.forEach(impression => { - expect(impression).to.not.have.property('bidfloor'); - expect(impression).to.not.have.property('bidfloorcur'); - }); - }); - }); - - describe('when different bid floors are provided per size', function () { - let bidRequests; - let bidderRequest; - let requests; - let imp; - - beforeEach(function () { - const getFloorStub = sinon.stub(); - getFloorStub.withArgs({currency: 'USD', mediaType: 'banner', size: [300, 250]}).returns({ - currency: 'USD', - floor: 0.5 - }); - getFloorStub.withArgs({currency: 'USD', mediaType: 'banner', size: [300, 600]}).returns({ - currency: 'USD', - floor: 0.7 - }); - - bidRequests = [createBidRequest(sandbox, { - getFloor: getFloorStub - })]; - bidderRequest = createBidderRequest(); - - requests = spec.buildRequests(bidRequests, bidderRequest); - imp = requests[0].data.imp; - }); - - it('should include the correct bidfloor per impression', function () { - expect(imp[0].bidfloor).to.equal(0.5); - expect(imp[0].banner).to.deep.equal({w: 300, h: 250}); - expect(imp[1].bidfloor).to.equal(0.7); - expect(imp[1].banner).to.deep.equal({w: 300, h: 600}); - }); - }); - - describe('when bid floor data is invalid', function () { - let bidRequests; - let bidderRequest; - let requests; - let imp; - - beforeEach(function () { - const invalidGetFloor = sinon.stub().returns({ - currency: 'USD', - floor: 'invalid' - }); - bidRequests = [createBidRequest(sandbox, { - getFloor: invalidGetFloor - })]; - bidderRequest = createBidderRequest(); - - requests = spec.buildRequests(bidRequests, bidderRequest); - imp = requests[0].data.imp; - }); - - it('should not include bidfloor when floor value is invalid', function () { - imp.forEach(impression => { - expect(impression).to.not.have.property('bidfloor'); - expect(impression).to.not.have.property('bidfloorcur'); - }); - }); - }); - }); - - describe('interpretResponse', function () { - let sandbox; - let bidRequests; - let bidderRequest; - let requests; - beforeEach(function () { - sandbox = sinon.createSandbox(); - sandbox.stub(utils, 'generateUUID').returns('test-generated-uuid'); - bidRequests = [createBidRequest(sandbox,)]; - bidderRequest = createBidderRequest(); - stubStorage(sandbox, null, null); // No user ID for simplicity - - requests = spec.buildRequests(bidRequests, bidderRequest); - }); - - afterEach(function () { - sandbox.restore(); - }); - - it('should return bids with all required keys when server response has valid bids', function () { - const request = requests[0]; - - const serverResponse = { - body: { - id: request.data.id, - seatbid: [ - { - bid: [ - { - impid: request.data.imp[0].id, - price: 1.5, - w: request.data.imp[0].banner.w, - h: request.data.imp[0].banner.h, - adm: '
Ad Content
', - crid: 'creative123', - adomain: ['example.com'], - nurl: 'https://example.com/win', - exp: 360, - }, - ], - }, - ], - cur: 'USD', - }, - }; - - const bids = spec.interpretResponse(serverResponse, request); - - expect(bids).to.be.an('array').with.lengthOf(1); - const bid = bids[0]; - expect(bid).to.include.all.keys( - 'requestId', - 'cpm', - 'currency', - 'width', - 'height', - 'ad', - 'ttl', - 'creativeId', - 'netRevenue', - 'meta', - 'nurl', - 'mediaType' - ); - expect(bid.mediaType).to.equal(BANNER); - expect(bid.ttl).to.equal(360); - expect(bid.nurl).to.equal('https://example.com/win'); - }); - - it('should return an empty array when server response is empty', function () { - const serverResponse = {body: {}}; - const bidRequest = {}; - - const bids = spec.interpretResponse(serverResponse, bidRequest); - - expect(bids).to.be.an('array').that.is.empty; - }); - }); - - describe('onBidWon', function () { - let sandbox; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - - afterEach(function () { - sandbox.restore(); - }); - - it('exists and is a function', () => { - expect(spec.onBidWon).to.exist.and.to.be.a('function'); - }); - - it('should return nothing and trigger a pixel with nurl', function () { - const bid = { - nurl: 'https://example.com/win', - }; - - const triggerPixelSpy = sandbox.spy(utils, 'triggerPixel'); - - const response = spec.onBidWon(bid); - - expect(response).to.be.undefined; - - expect(triggerPixelSpy.calledOnce).to.equal(true); - - expect(triggerPixelSpy.calledWith(bid.nurl)).to.equal(true); - }); - }); -}); diff --git a/test/spec/modules/blastoBidAdapter_spec.js b/test/spec/modules/blastoBidAdapter_spec.js deleted file mode 100644 index d0cd8e22b..000000000 --- a/test/spec/modules/blastoBidAdapter_spec.js +++ /dev/null @@ -1,310 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/blastoBidAdapter'; -import 'modules/priceFloors.js'; -import { newBidder } from 'src/adapters/bidderFactory'; -import { config } from '../../../src/config.js'; -import { addFPDToBidderRequest } from '../../helpers/fpd.js'; - -// load modules that register ORTB processors -import 'src/prebid.js'; -import 'modules/currency.js'; -import 'modules/userId/index.js'; -import 'modules/multibid/index.js'; - -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; - -const SIMPLE_BID_REQUEST = { - bidder: 'blasto', - params: { - accountId: 'testAccountId', - sourceId: 'testSourceId', - host: 'USE', - }, - mediaTypes: { - banner: { - sizes: [ - [320, 250], - [300, 600], - ], - }, - }, - adUnitCode: 'div-gpt-ad-1499748733608-0', - transactionId: 'f183e871-fbed-45f0-a427-c8a63c4c01eb', - bidId: '33e9500b21129f', - bidderRequestId: '2772c1e566670b', - auctionId: '192721e36a0239', - sizes: [[300, 250], [160, 600]], - gdprConsent: { - apiVersion: 2, - consentString: 'CONSENT', - vendorData: { purpose: { consents: { 1: true } } }, - gdprApplies: true, - addtlConsent: '1~1.35.41.101', - }, -} - -const BANNER_BID_REQUEST = { - bidder: 'blasto', - params: { - accountId: 'testAccountId', - sourceId: 'testSourceId', - host: 'USE', - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - }, - }, - adUnitCode: '/adunit-code/test-path', - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - transactionId: 'test-transactionId-1', - code: 'banner_example', - timeout: 1000, -} - -const VIDEO_BID_REQUEST = { - placementCode: '/DfpAccount1/slotVideo', - bidId: 'test-bid-id-2', - mediaTypes: { - video: { - playerSize: [400, 300], - w: 400, - h: 300, - minduration: 5, - maxduration: 10, - startdelay: 0, - skip: 1, - minbitrate: 200, - protocols: [1, 2, 4] - } - }, - bidder: 'blasto', - params: { - accountId: '123', - sourceId: '123', - host: 'USE', - }, - adUnitCode: '/adunit-code/test-path', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - transactionId: 'test-transactionId-1', - timeout: 1000, -} - -const NATIVE_BID_REQUEST = { - code: 'native_example', - mediaTypes: { - native: { - title: { - required: true, - len: 800 - }, - image: { - required: true, - len: 80 - }, - sponsoredBy: { - required: true - }, - clickUrl: { - required: true - }, - privacyLink: { - required: false - }, - body: { - required: true - }, - icon: { - required: true, - sizes: [50, 50] - } - } - }, - bidder: 'blasto', - params: { - accountId: 'testAccountId', - sourceId: 'testSourceId', - host: 'USE', - }, - adUnitCode: '/adunit-code/test-path', - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - transactionId: 'test-transactionId-1', - timeout: 1000, - uspConsent: 'uspConsent' -}; - -const bidderRequest = { - refererInfo: { - page: 'https://publisher.com/home', - ref: 'https://referrer' - } -}; - -const gdprConsent = { - apiVersion: 2, - consentString: 'CONSENT', - vendorData: { purpose: { consents: { 1: true } } }, - gdprApplies: true, - addtlConsent: '1~1.35.41.101', -} - -describe('blastoAdapter', function () { - const adapter = newBidder(spec); - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('with user privacy regulations', function () { - it('should send the Coppa "required" flag set to "1" in the request', async function () { - sinon.stub(config, 'getConfig') - .withArgs('coppa') - .returns(true); - const serverRequest = spec.buildRequests([SIMPLE_BID_REQUEST], await addFPDToBidderRequest(bidderRequest)); - expect(serverRequest.data.regs.coppa).to.equal(1); - config.getConfig.restore(); - }); - - it('should send the GDPR Consent data in the request', async function () { - const serverRequest = spec.buildRequests([SIMPLE_BID_REQUEST], await addFPDToBidderRequest({ - ...bidderRequest, - gdprConsent - })); - expect(serverRequest.data.regs.ext.gdpr).to.exist.and.to.equal(1); - expect(serverRequest.data.user.ext.consent).to.equal('CONSENT'); - }); - - it('should send the CCPA data in the request', async function () { - const serverRequest = spec.buildRequests([SIMPLE_BID_REQUEST], await addFPDToBidderRequest({...bidderRequest, ...{uspConsent: '1YYY'}})); - expect(serverRequest.data.regs.ext.us_privacy).to.equal('1YYY'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(BANNER_BID_REQUEST)).to.equal(true); - }); - - it('should return false when accountID/sourceId is missing', function () { - const localbid = Object.assign({}, BANNER_BID_REQUEST); - delete localbid.params.accountId; - delete localbid.params.sourceId; - expect(spec.isBidRequestValid(BANNER_BID_REQUEST)).to.equal(false); - }); - }); - - describe('build request', function () { - it('should return an empty array when no bid requests', async function () { - const bidRequest = spec.buildRequests([], await addFPDToBidderRequest(bidderRequest)); - expect(bidRequest).to.be.an('array'); - expect(bidRequest.length).to.equal(0); - }); - - it('should return a valid bid request object', async function () { - const request = spec.buildRequests([SIMPLE_BID_REQUEST], await addFPDToBidderRequest(bidderRequest)); - expect(request).to.not.equal('array'); - expect(request.data).to.be.an('object'); - expect(request.method).to.equal('POST'); - expect(request.url).to.not.equal(''); - expect(request.url).to.not.equal(undefined); - expect(request.url).to.not.equal(null); - - expect(request.data.site).to.have.property('page'); - expect(request.data.site).to.have.property('domain'); - expect(request.data).to.have.property('id'); - expect(request.data).to.have.property('imp'); - expect(request.data).to.have.property('device'); - }); - - it('should return a valid bid BANNER request object', async function () { - const request = spec.buildRequests([BANNER_BID_REQUEST], await addFPDToBidderRequest(bidderRequest)); - expect(request.data.imp[0].banner).to.exist; - expect(request.data.imp[0].banner.format[0].w).to.be.an('number'); - expect(request.data.imp[0].banner.format[0].h).to.be.an('number'); - }); - - if (FEATURES.VIDEO) { - it('should return a valid bid VIDEO request object', async function () { - const request = spec.buildRequests([VIDEO_BID_REQUEST], await addFPDToBidderRequest(bidderRequest)); - expect(request.data.imp[0].video).to.exist; - expect(request.data.imp[0].video.w).to.be.an('number'); - expect(request.data.imp[0].video.h).to.be.an('number'); - }); - } - - it('should return a valid bid NATIVE request object', async function () { - const request = spec.buildRequests([NATIVE_BID_REQUEST], await addFPDToBidderRequest(bidderRequest)); - expect(request.data.imp[0]).to.be.an('object'); - }); - }) - - describe('interpretResponse', function () { - let bidRequests, bidderRequest; - beforeEach(function () { - bidRequests = [{ - 'bidId': '28ffdk2B952532', - 'bidder': 'blasto', - 'userId': { - 'freepassId': { - 'userIp': '172.21.0.1', - 'userId': '123', - 'commonId': 'commonIdValue' - } - }, - 'adUnitCode': 'adunit-code', - 'params': { - 'publisherId': 'publisherIdValue' - } - }]; - bidderRequest = {}; - }); - - it('Empty response must return empty array', function () { - const emptyResponse = null; - const response = spec.interpretResponse(emptyResponse, BANNER_BID_REQUEST); - - expect(response).to.be.an('array').that.is.empty; - }) - - it('Should interpret banner response', function () { - const serverResponse = { - body: { - 'cur': 'USD', - 'seatbid': [{ - 'bid': [{ - 'impid': '28ffdk2B952532', - 'price': 97, - 'adm': '', - 'w': 300, - 'h': 250, - 'crid': 'creative0' - }] - }] - } - }; - it('should interpret server response', async function () { - const bidRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse(serverResponse, bidRequest); - expect(bids).to.be.an('array'); - const bid = bids[0]; - expect(bid).to.be.an('object'); - expect(bid.currency).to.equal('USD'); - expect(bid.cpm).to.equal(97); - expect(bid.ad).to.equal(ad) - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creativeId).to.equal('creative0'); - }); - }) - }); -}); diff --git a/test/spec/modules/bliinkBidAdapter_spec.js b/test/spec/modules/bliinkBidAdapter_spec.js deleted file mode 100644 index 885a50e0c..000000000 --- a/test/spec/modules/bliinkBidAdapter_spec.js +++ /dev/null @@ -1,1196 +0,0 @@ -import { expect } from 'chai'; -import { - spec, - buildBid, - BLIINK_ENDPOINT_ENGINE, - getMetaList, - BLIINK_ENDPOINT_COOKIE_SYNC_IFRAME, - getEffectiveConnectionType, - getUserIds, - GVL_ID, -} from 'modules/bliinkBidAdapter.js'; -import * as utils from 'src/utils.js'; -import { config } from 'src/config.js'; - -/** - * @description Mockup bidRequest - * @return {{ - * bidderWinsCount: number, - * adUnitCode: string, - * bidder: string, - * src: string, - * bidRequestsCount: number, - * params: {tagId: string, placement: string}, - * bidId: string, - * transactionId: string, - * auctionId: string, - * bidderRequestId: string, - * bidderRequestsCount: number, - * mediaTypes: {banner: {sizes: number[][]}}, - * sizes: number[][], - * crumbs: {pubcid: string}, - * ortb2Imp: {ext: {data: {pbadslot: string}}}}} - */ - -const w = (utils.canAccessWindowTop()) ? utils.getWindowTop() : utils.getWindowSelf(); -const connectionType = getEffectiveConnectionType(); -let domLoadingDuration = utils.getDomLoadingDuration(w).toString(); -const getConfigBid = (placement) => { - return { - adUnitCode: '/19968336/test', - auctionId: '6752b51c-dcd4-4001-85dc-885ab5c504cf', - bidId: '2def0c5b2a7f6e', - bidRequestsCount: 1, - bidder: 'bliink', - bidderRequestId: '1592eb20088b18', - bidderRequestsCount: 1, - bidderWinsCount: 0, - crumbs: { - pubcid: '55ffadc5-051f-428d-8ecc-dc585e0bde0d', - }, - sizes: [[300, 250]], - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - ortb2Imp: { - ext: { - data: { - pbadslot: '/19968336/test', - }, - }, - }, - domLoadingDuration, - ect: connectionType, - params: { - placement: placement, - tagId: '14f30eca-85d2-11e8-9eed-0242ac120007', - videoUrl: 'https://www.example.com/advideo.mp4', - imageUrl: 'https://www.example.com/adimage.jpg', - }, - src: 'client', - transactionId: 'cc6678c4-9746-4082-b9e2-d8065d078ebf', - }; -}; -const getConfigBannerBid = () => { - return { - creative: { - banner: { - adm: '', - height: 250, - width: 300, - }, - media_type: 'banner', - creativeId: 125, - }, - price: 1, - id: '810', - token: 'token', - mode: 'rtb', - extras: { - deal_id: '34567erty', - transaction_id: '2def0c5b2a7f6e', - }, - currency: 'EUR', - }; -}; -const getConfigVideoBid = () => { - return { - creative: { - video: { - content: '', - height: 250, - width: 300, - }, - media_type: 'video', - creativeId: 0, - }, - price: 1, - id: '8121', - token: 'token', - mode: 'rtb', - extras: { - deal_id: '34567ertyRTY', - transaction_id: '2def0c5b2a7f6e', - }, - currency: 'EUR', - }; -}; - -/** - * @description Mockup response from engine.bliink.io/xxxx - * @return { - * { - * viewability_percent_in_view: number, - * viewability_duration: number, - * ad_id: number, - * id: number, - * category: number, - * type: number, - * content: { - * creative: { - * adm: string - * } - * } - * } - * } - * } - */ -const getConfigCreative = () => { - return { - ad: '', - mediaType: 'banner', - cpm: 4, - currency: 'EUR', - creativeId: '34567erty', - width: 300, - height: 250, - ttl: 300, - netRevenue: true, - }; -}; - -const getConfigCreativeVideo = (isNoVast) => { - return { - mediaType: 'video', - vastXml: isNoVast ? '' : '', - cpm: 0, - currency: 'EUR', - creativeId: '34567ertyaza', - requestId: '6a204ce130280d', - width: 300, - height: 250, - ttl: 300, - netRevenue: true, - }; -}; - -/** - * @description Mockup BuildRequest function - * @return {{bidderRequestId: string, bidderCode: string, bids: {bidderWinsCount: number, adUnitCode: string, bidder: string, src: string, bidRequestsCount: number, params: {tagId: string, placement: string}, bidId: string, transactionId: string, auctionId: string, bidderRequestId: string, bidderRequestsCount: number, mediaTypes: {banner: {sizes: number[][]}}, sizes: number[][], crumbs: {pubcid: string}, ortb2Imp: {ext: {data: {pbadslot: string}}}}[], refererInfo: {referer: string, canonicalUrl: null, isAmp: boolean, reachedTop: boolean, numIframes: number}}} - */ -const getConfigBuildRequest = (placement) => { - const buildRequest = { - bidderRequestId: '164ddfd207e94d', - bidderCode: 'bliink', - bids: [getConfigBid(placement)], - refererInfo: { - canonicalUrl: null, - isAmp: false, - numIframes: 0, - reachedTop: true, - page: 'http://localhost:9999/integrationExamples/gpt/bliink-adapter.html?pbjs_debug=true', - }, - }; - - if (!placement) { - return buildRequest; - } - - return Object.assign(buildRequest, { - params: { - bids: [getConfigBid(placement)], - placement: placement, - }, - }); -}; - -/** - * @description Mockup response from API - * @param noAd - * @return {{mode: string, message: string}|{headers: {}, body: {mode: string, creative: {viewability_percent_in_view: number, viewability_duration: number, ad_id: number, adm: string, id: number, category: number, type: number}, token: string}}} - */ -const getConfigInterpretResponse = (noAd = false) => { - if (noAd) { - return { - message: 'invalid tag', - mode: 'no-ad', - }; - } - - return { - body: { - ...getConfigCreative(), - mode: 'ad', - transactionId: '2def0c5b2a7f6e', - token: - 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MjgxNzA4MzEsImlhdCI6MTYyNzU2NjAzMSwiaXNzIjoiYmxpaW5rIiwiZGF0YSI6eyJ0eXBlIjoiYWQtc2VydmVyIiwidHJhbnNhY3Rpb25JZCI6IjM1YmU1NDNjLTNkZTQtNGQ1Yy04N2NjLWIzYzEyOGZiYzU0MCIsIm5ldHdvcmtJZCI6MjEsInNpdGVJZCI6NTksInRhZ0lkIjo1OSwiY29va2llSWQiOiJjNGU4MWVhOS1jMjhmLTQwZDItODY1ZC1hNjQzZjE1OTcyZjUiLCJldmVudElkIjozLCJ0YXJnZXRpbmciOnsicGxhdGZvcm0iOiJXZWJzaXRlIiwiaXAiOiI3OC4xMjIuNzUuNzIiLCJ0aW1lIjoxNjI3NTY2MDMxLCJsb2NhdGlvbiI6eyJsYXRpdHVkZSI6NDguOTczOSwibG9uZ2l0dWRlIjozLjMxMTMsInJlZ2lvbiI6IkhERiIsImNvdW50cnkiOiJGUiIsImNpdHkiOiJTYXVsY2hlcnkiLCJ6aXBDb2RlIjoiMDIzMTAiLCJkZXBhcnRtZW50IjoiMDIifSwiY2l0eSI6IlNhdWxjaGVyeSIsImNvdW50cnkiOiJGUiIsImRldmljZU9zIjoibWFjT1MiLCJkZXZpY2VQbGF0Zm9ybSI6IldlYnNpdGUiLCJyYXdVc2VyQWdlbnQiOiJNb3ppbGxhLzUuMCAoTWFjaW50b3NoOyBJbnRlbCBNYWMgT1MgWCAxMF8xNV83KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWUvOTEuMC40NDcyLjEyNCBTYWZhcmkvNTM3LjM2In0sImdkcHIiOnsiaGFzQ29uc2VudCI6dHJ1ZX0sIndpbiI6ZmFsc2UsImFkSWQiOjU2NDgsImFkdmVydGlzZXJJZCI6MSwiY2FtcGFpZ25JZCI6MSwiY3JlYXRpdmVJZCI6MjgyNSwiZXJyb3IiOmZhbHNlfX0.-UefQH4G0k-RJGemBYffs-KL7EEwma2Wuwgk2xnpij8', - }, - headers: {}, - }; -}; - -/** - * @description Mockup response from API for RTB creative - * @param noAd - * @return {{body: string} | {mode: string, message: string}} - */ -const getConfigInterpretResponseRTB = (noAd = false, isInvalidVast = false) => { - if (noAd) { - return { - message: 'invalid tag', - mode: 'no-ad', - }; - } - - const validVast = ` - - - - BLIINK - https://vast.bliink.io/p/508379d0-9f65-4198-8ba5-f61f2b51224f.xml - https://e.api.bliink.io/e?name=vast-error&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzQwMzA1MjcsImlhdCI6MTYzMzQyNTcyNywiaXNzIjoiYmxpaW5rIiwiZGF0YSI6eyJ0eXBlIjoiYWQtc2VydmVyIiwidHJhbnNhY3Rpb25JZCI6ImE2NjJjZGJmLTkzNDYtNDI0MS1iMTU0LTJhOTc2OTg0NjNmOSIsIm5ldHdvcmtJZCI6MjUsInNpdGVJZCI6MTQzLCJ0YWdJZCI6MTI3MSwiY29va2llSWQiOiIwNWFhN2UwMi05MzgzLTQ1NGYtOTJmZC1jOTE2YWNlMmUyZjYiLCJldmVudElkIjozLCJ0YXJnZXRpbmciOnsicGxhdGZvcm0iOiJXZWJzaXRlIiwicmVmZXJyZXIiOiJodHRwOi8vbG9jYWxob3N0OjgxODEvaW50ZWdyYXRpb25FeGFtcGxlcy9ncHQvYmxpaW5rLWluc3RyZWFtLmh0bWwiLCJwYWdlVXJsIjoiaHR0cDovL2xvY2FsaG9zdDo4MTgxL2ludGVncmF0aW9uRXhhbXBsZXMvZ3B0L2JsaWluay1pbnN0cmVhbS5odG1sIiwiaXAiOiIzMS4zOS4xNDEuMTQwIiwidGltZSI6MTYzMzQyNTcyNywibG9jYXRpb24iOnsibGF0aXR1ZGUiOjQ4Ljk0MjIsImxvbmdpdHVkZSI6Mi41MDM5LCJyZWdpb24iOiJJREYiLCJjb3VudHJ5IjoiRlIiLCJjaXR5IjoiQXVsbmF5LXNvdXMtQm9pcyIsInppcENvZGUiOiI5MzYwMCIsImRlcGFydG1lbnQiOiI5MyJ9LCJjaXR5IjoiQXVsbmF5LXNvdXMtQm9pcyIsImNvdW50cnkiOiJGUiIsImRldmljZU9zIjoibWFjT1MiLCJkZXZpY2VQbGF0Zm9ybSI6IldlYnNpdGUiLCJyYXdVc2VyQWdlbnQiOiJNb3ppbGxhLzUuMCAoTWFjaW50b3NoOyBJbnRlbCBNYWMgT1MgWCAxMF8xNV83KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWUvOTMuMC40NTc3LjYzIFNhZmFyaS81MzcuMzYiLCJjb250ZW50Q2xhc3NpZmljYXRpb24iOnsiYnJhbmRzYWZlIjpmYWxzZX19LCJnZHByIjp7Imhhc0NvbnNlbnQiOnRydWV9LCJ3aW4iOmZhbHNlLCJhZElkIjo1NzkzLCJhZHZlcnRpc2VySWQiOjEsImNhbXBhaWduSWQiOjEsImNyZWF0aXZlSWQiOjExOTQsImVycm9yIjpmYWxzZX19.nJSJPKovg0_jSHtLdrMPDqesAIlFKCuXPXYxpsyWBDw - https://e.api.bliink.io/e?name=impression&token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MzQwMzA1MjcsImlhdCI6MTYzMzQyNTcyNywiaXNzIjoiYmxpaW5rIiwiZGF0YSI6eyJ0eXBlIjoiYWQtc2VydmVyIiwidHJhbnNhY3Rpb25JZCI6ImE2NjJjZGJmLTkzNDYtNDI0MS1iMTU0LTJhOTc2OTg0NjNmOSIsIm5ldHdvcmtJZCI6MjUsInNpdGVJZCI6MTQzLCJ0YWdJZCI6MTI3MSwiY29va2llSWQiOiIwNWFhN2UwMi05MzgzLTQ1NGYtOTJmZC1jOTE2YWNlMmUyZjYiLCJldmVudElkIjozLCJ0YXJnZXRpbmciOnsicGxhdGZvcm0iOiJXZWJzaXRlIiwicmVmZXJyZXIiOiJodHRwOi8vbG9jYWxob3N0OjgxODEvaW50ZWdyYXRpb25FeGFtcGxlcy9ncHQvYmxpaW5rLWluc3RyZWFtLmh0bWwiLCJwYWdlVXJsIjoiaHR0cDovL2xvY2FsaG9zdDo4MTgxL2ludGVncmF0aW9uRXhhbXBsZXMvZ3B0L2JsaWluay1pbnN0cmVhbS5odG1sIiwiaXAiOiIzMS4zOS4xNDEuMTQwIiwidGltZSI6MTYzMzQyNTcyNywibG9jYXRpb24iOnsibGF0aXR1ZGUiOjQ4Ljk0MjIsImxvbmdpdHVkZSI6Mi41MDM5LCJyZWdpb24iOiJJREYiLCJjb3VudHJ5IjoiRlIiLCJjaXR5IjoiQXVsbmF5LXNvdXMtQm9pcyIsInppcENvZGUiOiI5MzYwMCIsImRlcGFydG1lbnQiOiI5MyJ9LCJjaXR5IjoiQXVsbmF5LXNvdXMtQm9pcyIsImNvdW50cnkiOiJGUiIsImRldmljZU9zIjoibWFjT1MiLCJkZXZpY2VQbGF0Zm9ybSI6IldlYnNpdGUiLCJyYXdVc2VyQWdlbnQiOiJNb3ppbGxhLzUuMCAoTWFjaW50b3NoOyBJbnRlbCBNYWMgT1MgWCAxMF8xNV83KSBBcHBsZVdlYktpdC81MzcuMzYgKEtIVE1MLCBsaWtlIEdlY2tvKSBDaHJvbWUvOTMuMC40NTc3LjYzIFNhZmFyaS81MzcuMzYiLCJjb250ZW50Q2xhc3NpZmljYXRpb24iOnsiYnJhbmRzYWZlIjpmYWxzZX19LCJnZHByIjp7Imhhc0NvbnNlbnQiOnRydWV9LCJ3aW4iOmZhbHNlLCJhZElkIjo1NzkzLCJhZHZlcnRpc2VySWQiOjEsImNhbXBhaWduSWQiOjEsImNyZWF0aXZlSWQiOjExOTQsImVycm9yIjpmYWxzZX19.nJSJPKovg0_jSHtLdrMPDqesAIlFKCuXPXYxpsyWBDw - 1EUR - - - - `; - const invalidVast = ` - - - - - - `; - - return { - body: { - bids: [ - { - creative: { - video: { - content: isInvalidVast ? invalidVast : validVast, - height: 250, - width: 300, - }, - media_type: 'video', - creativeId: 0, - }, - price: 0, - id: '8121', - token: 'token', - mode: 'rtb', - extras: { - deal_id: '34567ertyaza', - transaction_id: '2def0c5b2a7f6e', - }, - currency: 'EUR', - }, - ], - userSyncs: [], - }, - }; -}; - -/** - * - * - * - * @description Below start tests for utils fonctions - * - * - * - */ - -const testsGetMetaList = [ - { - title: 'Should return empty array if there are no parameters', - args: { - fn: getMetaList(), - }, - want: [], - }, - { - title: 'Should return list of metas with name associated', - args: { - fn: getMetaList('test'), - }, - want: [ - { - key: 'name', - value: 'test', - }, - { - key: 'name*', - value: 'test', - }, - { - key: 'itemprop*', - value: 'test', - }, - { - key: 'property', - value: `'og:${'test'}'`, - }, - { - key: 'property', - value: `'twitter:${'test'}'`, - }, - { - key: 'property', - value: `'article:${'test'}'`, - }, - ], - }, -]; - -describe('BLIINK Adapter getMetaList', function () { - for (const test of testsGetMetaList) { - it(test.title, () => { - const res = test.args.fn; - expect(res).to.eql(test.want); - }); - } -}); -const GetUserIds = [ - { - title: 'Should return undefined if there are no parameters', - args: { - fn: getUserIds(), - }, - want: undefined, - }, - { - title: 'Should return eids if exists', - args: { - fn: getUserIds([{ userIdAsEids: [ - { - 'source': 'criteo.com', - 'uids': [ - { - 'id': 'testId', - 'atype': 1 - } - ] - } - ] }]), - }, - want: [ - { - 'source': 'criteo.com', - 'uids': [ - { - 'id': 'testId', - 'atype': 1 - } - ] - } - ], - }, -]; - -describe('BLIINK Adapter getUserIds', function () { - for (const test of GetUserIds) { - it(test.title, () => { - const res = test.args.fn; - expect(res).to.eql(test.want); - }); - } -}); - -/** - * @description Array of tests used in describe function below - * @type {[{args: {fn: (string|Document)}, want: string, title: string}, {args: {fn: (string|Document)}, want: string, title: string}]} - */ - -/** - * - * - * - * @description End tests for utils fonctions - * - * - * - */ - -/** - * @description Array of tests used in describe function below - * @type {[{args: {fn}, want: boolean, title: string}, {args: {fn}, want: boolean, title: string}, {args: {fn}, want: boolean, title: string}]} - */ -const testsIsBidRequestValid = [ - { - title: 'isBidRequestValid format not valid', - args: { - fn: spec.isBidRequestValid({}), - }, - want: false, - }, - { - title: 'isBidRequestValid does not receive any bid', - args: { - fn: spec.isBidRequestValid(), - }, - want: false, - }, - { - title: 'isBidRequestValid Receive a valid bid', - args: { - fn: spec.isBidRequestValid(getConfigBid('banner')), - }, - want: true, - }, -]; - -describe('BLIINK Adapter isBidRequestValid', function () { - for (const test of testsIsBidRequestValid) { - it(test.title, () => { - const res = test.args.fn; - expect(res).to.eql(test.want); - }); - } -}); - -const vastXml = - getConfigInterpretResponseRTB().body.bids[0].creative.video.content; - -const testsInterpretResponse = [ - { - title: 'Should construct bid for video instream', - args: { - fn: spec.interpretResponse(getConfigInterpretResponseRTB(false)), - }, - want: [ - { - cpm: 0, - currency: 'EUR', - height: 250, - width: 300, - creativeId: '34567ertyaza', - mediaType: 'video', - netRevenue: true, - requestId: '2def0c5b2a7f6e', - ttl: 300, - vastXml, - vastUrl: - 'data:text/xml;charset=utf-8;base64,' + - btoa(vastXml.replace(/\\"/g, '"')), - }, - ], - }, - { - title: 'ServerResponse with message: invalid tag, return empty array', - args: { - fn: spec.interpretResponse(getConfigInterpretResponse(true)), - }, - want: [], - }, - { - title: 'ServerResponse with mediaType banner', - args: { - fn: spec.interpretResponse({ body: { bids: [getConfigBannerBid()] } }), - }, - want: [ - { - ad: '', - cpm: 1, - creativeId: '34567erty', - currency: 'EUR', - height: 250, - mediaType: 'banner', - netRevenue: true, - requestId: '2def0c5b2a7f6e', - ttl: 300, - width: 300, - }, - ], - }, - { - title: 'ServerResponse with unhandled mediaType, return empty array', - args: { - fn: spec.interpretResponse({ - body: { - bids: [ - { - ...getConfigBannerBid(), - creative: { - unknown: { - adm: '', - height: 250, - width: 300, - }, - media_type: 'unknown', - creativeId: 125, - requestId: '2def0c5b2a7f6e', - }, - }, - ], - }, - }), - }, - want: [], - }, -]; - -describe('BLIINK Adapter interpretResponse', function () { - for (const test of testsInterpretResponse) { - it(test.title, () => { - const res = test.args.fn; - - if (res) { - expect(res).to.eql(test.want); - } - }); - } -}); - -/** - * @description Array of tests used in describe function below - * @type {[ - * {args: - * {fn: { - * cpm: number, - * netRevenue: boolean, - * ad, requestId, - * meta: {mediaType}, - * width: number, - * currency: string, - * ttl: number, - * creativeId: number, - * height: number - * } - * }, want, title: string}]} - */ - -const testsBuildBid = [ - { - title: 'Should return null if no bid passed in parameters', - args: { - fn: buildBid(), - }, - want: null, - }, - { - title: 'Input data must respect the output model', - args: { - fn: buildBid( - { id: 1, test: '123' }, - { id: 2, test: '345' }, - false, - false - ), - }, - want: null, - }, - { - title: 'input data respect the output model for video', - args: { - fn: buildBid(getConfigVideoBid('video'), getConfigCreativeVideo()), - }, - want: { - requestId: getConfigBid('video').bidId, - cpm: 1, - currency: 'EUR', - mediaType: 'video', - width: 300, - height: 250, - creativeId: getConfigVideoBid().extras.deal_id, - netRevenue: true, - vastXml: getConfigCreativeVideo().vastXml, - vastUrl: - 'data:text/xml;charset=utf-8;base64,' + - btoa(getConfigCreativeVideo().vastXml.replace(/\\"/g, '"')), - ttl: 300, - }, - }, - { - title: 'use default height width output model for video', - args: { - fn: buildBid( - { - ...getConfigVideoBid('video'), - creative: { - video: { - content: '', - height: null, - width: null, - }, - media_type: 'video', - creativeId: getConfigVideoBid().extras.deal_id, - requestId: '2def0c5b2a7f6e', - }, - }, - getConfigCreativeVideo() - ), - }, - want: { - requestId: getConfigBid('video').bidId, - cpm: 1, - currency: 'EUR', - mediaType: 'video', - width: 1, - height: 1, - creativeId: getConfigVideoBid().extras.deal_id, - netRevenue: true, - vastXml: getConfigCreativeVideo().vastXml, - vastUrl: - 'data:text/xml;charset=utf-8;base64,' + - btoa(getConfigCreativeVideo().vastXml.replace(/\\"/g, '"')), - ttl: 300, - }, - }, - { - title: 'input data respect the output model for banner', - args: { - fn: buildBid(getConfigBannerBid()), - }, - want: { - requestId: getConfigBid('banner').bidId, - cpm: 1, - currency: 'EUR', - mediaType: 'banner', - width: 300, - height: 250, - creativeId: getConfigCreative().creativeId, - ad: getConfigBannerBid().creative.banner.adm, - ttl: 300, - netRevenue: true, - }, - }, -]; - -describe('BLIINK Adapter buildBid', function () { - for (const test of testsBuildBid) { - it(test.title, () => { - const res = test.args.fn; - expect(res).to.eql(test.want); - }); - } -}); - -/** - * @description Array of tests used in describe function below - * @type {[{args: {fn}, want, title: string}]} - */ -const testsBuildRequests = [ - { - title: 'Should not build request, no bidder request exist', - args: { - fn: spec.buildRequests(), - }, - want: null, - }, - { - title: 'Should build request if bidderRequest exist', - args: { - fn: spec.buildRequests([], getConfigBuildRequest('banner')), - }, - want: { - method: 'POST', - url: BLIINK_ENDPOINT_ENGINE, - data: { - domLoadingDuration, - ect: connectionType, - keywords: '', - pageDescription: '', - pageTitle: '', - pageUrl: - 'http://localhost:9999/integrationExamples/gpt/bliink-adapter.html', - tags: [ - { - transactionId: '2def0c5b2a7f6e', - refresh: window.bliinkBid['14f30eca-85d2-11e8-9eed-0242ac120007'] || undefined, - id: '14f30eca-85d2-11e8-9eed-0242ac120007', - imageUrl: 'https://www.example.com/adimage.jpg', - videoUrl: 'https://www.example.com/advideo.mp4', - mediaTypes: ['banner'], - sizes: [ - { - h: 250, - w: 300, - }, - ], - }, - ], - }, - }, - }, - { - title: 'Should build request width GDPR configuration', - args: { - fn: spec.buildRequests( - [], - Object.assign(getConfigBuildRequest('banner'), { - gdprConsent: { - gdprApplies: true, - consentString: 'XXXX', - }, - }) - ), - }, - want: { - method: 'POST', - url: BLIINK_ENDPOINT_ENGINE, - data: { - domLoadingDuration, - ect: connectionType, - gdpr: true, - gdprConsent: 'XXXX', - pageDescription: '', - pageTitle: '', - keywords: '', - pageUrl: - 'http://localhost:9999/integrationExamples/gpt/bliink-adapter.html', - tags: [ - { - transactionId: '2def0c5b2a7f6e', - refresh: window.bliinkBid['14f30eca-85d2-11e8-9eed-0242ac120007'] || undefined, - id: '14f30eca-85d2-11e8-9eed-0242ac120007', - imageUrl: 'https://www.example.com/adimage.jpg', - videoUrl: 'https://www.example.com/advideo.mp4', - mediaTypes: ['banner'], - sizes: [ - { - h: 250, - w: 300, - }, - ], - }, - ], - }, - }, - }, - { - title: 'Should build request width uspConsent if exists', - args: { - fn: spec.buildRequests( - [], - Object.assign(getConfigBuildRequest('banner'), { - gdprConsent: { - gdprApplies: true, - consentString: 'XXXX', - }, - uspConsent: 'uspConsent', - }) - ), - }, - want: { - method: 'POST', - url: BLIINK_ENDPOINT_ENGINE, - data: { - domLoadingDuration, - ect: connectionType, - gdpr: true, - uspConsent: 'uspConsent', - gdprConsent: 'XXXX', - pageDescription: '', - pageTitle: '', - keywords: '', - pageUrl: - 'http://localhost:9999/integrationExamples/gpt/bliink-adapter.html', - tags: [ - { - transactionId: '2def0c5b2a7f6e', - refresh: window.bliinkBid['14f30eca-85d2-11e8-9eed-0242ac120007'] || undefined, - id: '14f30eca-85d2-11e8-9eed-0242ac120007', - imageUrl: 'https://www.example.com/adimage.jpg', - videoUrl: 'https://www.example.com/advideo.mp4', - mediaTypes: ['banner'], - sizes: [ - { - h: 250, - w: 300, - }, - ], - }, - ], - }, - }, - }, - { - title: 'Should build request width schain if exists', - args: { - fn: spec.buildRequests( - [ - { - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'ssp.test', - sid: '00001', - hp: 1, - }, - ], - } - } - } - }, - }, - ], - Object.assign(getConfigBuildRequest('banner'), { - gdprConsent: { - gdprApplies: true, - consentString: 'XXXX', - }, - }) - ), - }, - want: { - method: 'POST', - url: BLIINK_ENDPOINT_ENGINE, - data: { - domLoadingDuration, - ect: connectionType, - gdpr: true, - gdprConsent: 'XXXX', - pageDescription: '', - pageTitle: '', - keywords: '', - pageUrl: - 'http://localhost:9999/integrationExamples/gpt/bliink-adapter.html', - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'ssp.test', - sid: '00001', - hp: 1, - }, - ], - }, - tags: [ - { - transactionId: '2def0c5b2a7f6e', - refresh: window.bliinkBid['14f30eca-85d2-11e8-9eed-0242ac120007'] || undefined, - id: '14f30eca-85d2-11e8-9eed-0242ac120007', - imageUrl: 'https://www.example.com/adimage.jpg', - videoUrl: 'https://www.example.com/advideo.mp4', - mediaTypes: ['banner'], - sizes: [ - { - h: 250, - w: 300, - }, - ], - }, - ], - }, - }, - }, - { - title: 'Should build request with eids if exists', - args: { - fn: spec.buildRequests( - [ - { - userIdAsEids: [ - { - 'source': 'criteo.com', - 'uids': [ - { - 'id': 'vG4RRF93V05LRlJUTVVOQTJJJTJGbG1rZWxEeDVvc0NXWE42TzJqU2hG', - 'atype': 1 - } - ] - }, - { - 'source': 'netid.de', - 'uids': [ - { - 'id': 'fH5A3n2O8_CZZyPoJVD-eabc6ECb7jhxCicsds7qSg', - 'atype': 1 - } - ] - } - ], - }, - ], - Object.assign(getConfigBuildRequest('banner'), { - gdprConsent: { - gdprApplies: true, - consentString: 'XXXX', - }, - }) - ), - }, - want: { - method: 'POST', - url: BLIINK_ENDPOINT_ENGINE, - data: { - domLoadingDuration, - ect: connectionType, - gdpr: true, - gdprConsent: 'XXXX', - pageDescription: '', - pageTitle: '', - keywords: '', - pageUrl: - 'http://localhost:9999/integrationExamples/gpt/bliink-adapter.html', - eids: [ - { - 'source': 'criteo.com', - 'uids': [ - { - 'id': 'vG4RRF93V05LRlJUTVVOQTJJJTJGbG1rZWxEeDVvc0NXWE42TzJqU2hG', - 'atype': 1 - } - ] - }, - { - 'source': 'netid.de', - 'uids': [ - { - 'id': 'fH5A3n2O8_CZZyPoJVD-eabc6ECb7jhxCicsds7qSg', - 'atype': 1 - } - ] - } - ], - tags: [ - { - transactionId: '2def0c5b2a7f6e', - refresh: window.bliinkBid['14f30eca-85d2-11e8-9eed-0242ac120007'] || undefined, - id: '14f30eca-85d2-11e8-9eed-0242ac120007', - imageUrl: 'https://www.example.com/adimage.jpg', - videoUrl: 'https://www.example.com/advideo.mp4', - mediaTypes: ['banner'], - sizes: [ - { - h: 250, - w: 300, - }, - ], - }, - ], - }, - }, - }, -]; - -describe('BLIINK Adapter buildRequests', function () { - for (const test of testsBuildRequests) { - it(test.title, () => { - const res = test.args.fn; - expect(res).to.eql(test.want); - }); - } -}); - -const getSyncOptions = (pixelEnabled = true, iframeEnabled = false) => { - return { - pixelEnabled, - iframeEnabled, - }; -}; - -const getServerResponses = () => { - return [ - { - body: { - bids: [], - userSyncs: [ - { - type: 'script', - url: 'https://prg.smartadserver.com/ac?out=js&nwid=3392&siteid=305791&pgname=rg&fmtid=81127&tgt=[sas_target]&visit=m&tmstp=[timestamp]&clcturl=[countgo]', - }, - { - type: 'image', - url: 'https://sync.smartadserver.com/getuid?nwid=3392&consentString=XXX&url=https%3A%2F%2Fcookiesync.api.bliink.io%2Fcookiesync%3Fpartner%3Dsmart%26uid%3D%5Bsas_uid%5D', - }, - ], - }, - }, - ]; -}; - -const getGdprConsent = () => { - return { - gdprApplies: 1, - consentString: 'XXX', - apiVersion: 2, - }; -}; - -const testsGetUserSyncs = [ - { - title: 'Should not have gdprConsent exist', - args: { - fn: spec.getUserSyncs( - getSyncOptions(), - getServerResponses(), - getGdprConsent() - ), - }, - want: [ - { - type: 'script', - url: 'https://prg.smartadserver.com/ac?out=js&nwid=3392&siteid=305791&pgname=rg&fmtid=81127&tgt=[sas_target]&visit=m&tmstp=[timestamp]&clcturl=[countgo]', - }, - { - type: 'image', - url: 'https://sync.smartadserver.com/getuid?nwid=3392&consentString=XXX&url=https%3A%2F%2Fcookiesync.api.bliink.io%2Fcookiesync%3Fpartner%3Dsmart%26uid%3D%5Bsas_uid%5D', - }, - ], - }, - { - title: 'Should return iframe cookie sync if iframeEnabled', - args: { - fn: spec.getUserSyncs( - getSyncOptions(true, true), - getServerResponses(), - getGdprConsent() - ), - }, - want: [ - { - type: 'iframe', - url: `${BLIINK_ENDPOINT_COOKIE_SYNC_IFRAME}?gdpr=${ - getGdprConsent().gdprApplies - }&coppa=0&gdprConsent=${getGdprConsent().consentString}&apiVersion=${ - getGdprConsent().apiVersion - }`, - }, - ], - }, - { - title: 'ccpa', - args: { - fn: spec.getUserSyncs( - getSyncOptions(true, true), - getServerResponses(), - getGdprConsent(), - 'ccpa-consent' - ), - }, - want: [ - { - type: 'iframe', - url: `${BLIINK_ENDPOINT_COOKIE_SYNC_IFRAME}?gdpr=${ - getGdprConsent().gdprApplies - }&coppa=0&uspConsent=ccpa-consent&gdprConsent=${ - getGdprConsent().consentString - }&apiVersion=${getGdprConsent().apiVersion}`, - }, - ], - }, - { - title: 'Should output sync if no gdprConsent', - args: { - fn: spec.getUserSyncs(getSyncOptions(), getServerResponses()), - }, - want: getServerResponses()[0].body.userSyncs, - }, - { - title: 'Should output empty array if no pixelEnabled', - args: { - fn: spec.getUserSyncs({}, getServerResponses()), - }, - want: [], - }, -]; - -describe('BLIINK Adapter getUserSyncs', function () { - for (const test of testsGetUserSyncs) { - it(test.title, () => { - const res = test.args.fn; - expect(res).to.eql(test.want); - }); - } -}); - -describe('BLIINK Adapter keywords & coppa true', function () { - let querySelectorStub; - let configStub; - let originalTitle; - - beforeEach(() => { - window.bliinkBid = {}; - const metaElement = document.createElement('meta'); - metaElement.name = 'keywords'; - metaElement.content = 'Bliink, Saber, Prebid'; - sinon.stub(utils, 'getDomLoadingDuration').returns(0); - domLoadingDuration = '0'; - configStub = sinon.stub(config, 'getConfig'); - configStub.withArgs('coppa').returns(true); - querySelectorStub = sinon.stub(document, 'querySelector').returns(metaElement); - originalTitle = document.title; - document.title = ''; - }); - - afterEach(() => { - querySelectorStub.restore(); - configStub.restore(); - utils.getDomLoadingDuration.restore(); - document.title = originalTitle; - }); - - it('Should build request with keyword and coppa true if exist', () => { - expect( - spec.buildRequests( - [], - Object.assign(getConfigBuildRequest('banner'), { - gdprConsent: { - gdprApplies: true, - consentString: 'XXXX', - }, - }) - ) - ).to.eql({ - method: 'POST', - url: BLIINK_ENDPOINT_ENGINE, - data: { - domLoadingDuration, - ect: getEffectiveConnectionType(), - gdpr: true, - coppa: 1, - gdprConsent: 'XXXX', - pageDescription: 'Bliink, Saber, Prebid', - pageTitle: '', - keywords: 'Bliink,Saber,Prebid', - pageUrl: - 'http://localhost:9999/integrationExamples/gpt/bliink-adapter.html', - tags: [ - { - transactionId: '2def0c5b2a7f6e', - id: '14f30eca-85d2-11e8-9eed-0242ac120007', - imageUrl: 'https://www.example.com/adimage.jpg', - videoUrl: 'https://www.example.com/advideo.mp4', - mediaTypes: ['banner'], - refresh: window.bliinkBid['14f30eca-85d2-11e8-9eed-0242ac120007'] || undefined, - sizes: [ - { - h: 250, - w: 300, - }, - ], - }, - ], - }, - }); - }); -}); - -describe('getEffectiveConnectionType', () => { - let navigatorStub; - - beforeEach(() => { - if ('connection' in navigator) { - navigatorStub = sinon.stub(navigator, 'connection').value({ - effectiveType: undefined, - }); - } - }); - - afterEach(() => { - if (navigatorStub) { - navigatorStub.restore(); - } - }); - if (navigatorStub) { - it('should return "unsupported" when effective connection type is undefined', () => { - const result = getEffectiveConnectionType(); - expect(result).to.equal('unsupported'); - }); - } -}); - -it('should expose gvlid', function () { - expect(spec.gvlid).to.equal(GVL_ID); -}); diff --git a/test/spec/modules/blockthroughBidAdapter_spec.js b/test/spec/modules/blockthroughBidAdapter_spec.js deleted file mode 100644 index f0778eba7..000000000 --- a/test/spec/modules/blockthroughBidAdapter_spec.js +++ /dev/null @@ -1,207 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/blockthroughBidAdapter.js'; -import { BANNER } from '../../../src/mediaTypes.js'; -// load modules that register ORTB processors -import 'src/prebid.js'; -import 'modules/currency.js'; -import 'modules/userId/index.js'; -import 'modules/multibid/index.js'; -import 'modules/priceFloors.js'; -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; -import 'modules/consentManagementGpp.js'; -import 'modules/tcfControl.js'; -import 'modules/gppControl_usnat.js'; - -describe('BT Bid Adapter', () => { - const ENDPOINT_URL = 'https://pbs.btloader.com/openrtb2/auction'; - const validBidRequests = [ - { - bidId: '2e9f38ea93bb9e', - bidder: 'blockthrough', - adUnitCode: 'adunit-code', - mediaTypes: { [BANNER]: { sizes: [[300, 250]] } }, - params: { - bidderA: { - pubId: '11111', - }, - }, - bidderRequestId: 'test-bidder-request-id', - }, - ]; - const bidderRequest = { - bidderCode: 'blockthrough', - bidderRequestId: 'test-bidder-request-id', - bids: validBidRequests, - }; - - describe('isBidRequestValid', function () { - it('should validate bid request with valid params', () => { - const validBid = { - params: { - pubmatic: { - publisherId: 55555, - }, - }, - sizes: [[300, 250]], - bidId: '123', - adUnitCode: 'leaderboard', - }; - - const isValid = spec.isBidRequestValid(validBid); - - expect(isValid).to.be.true; - }); - - it('should not validate bid request with invalid params', () => { - const invalidBid = { - params: {}, - sizes: [[300, 250]], - bidId: '123', - adUnitCode: 'leaderboard', - }; - - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.be.false; - }); - }); - - describe('buildRequests', () => { - it('should build post request when ortb2 fields are present', () => { - const impExtParams = { - bidderA: { - pubId: '11111', - }, - }; - - const requests = spec.buildRequests(validBidRequests, bidderRequest); - - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(ENDPOINT_URL); - expect(requests[0].data).to.exist; - expect(requests[0].data.ext.prebid.channel).to.deep.equal({ - name: 'pbjs', - version: '$prebid.version$', - }); - expect(requests[0].data.imp[0].ext).to.deep.equal(impExtParams); - }); - }); - - describe('interpretResponse', () => { - it('should return empty array if serverResponse is not defined', () => { - const bidRequest = spec.buildRequests(validBidRequests, bidderRequest); - const bids = spec.interpretResponse(undefined, bidRequest); - - expect(bids.length).to.equal(0); - }); - - it('should return bids array when serverResponse is defined and seatbid array is not empty', () => { - const bidResponse = { - body: { - id: 'bid-response', - cur: 'USD', - seatbid: [ - { - bid: [ - { - impid: '2e9f38ea93bb9e', - crid: 'creative-id', - cur: 'USD', - price: 2, - w: 300, - h: 250, - mtype: 1, - adomain: ['test.com'], - }, - ], - seat: 'test-seat', - }, - ], - }, - }; - - const expectedBids = [ - { - btBidderCode: 'test-seat', - cpm: 2, - creativeId: 'creative-id', - creative_id: 'creative-id', - currency: 'USD', - height: 250, - mediaType: 'banner', - meta: { - advertiserDomains: ['test.com'], - }, - netRevenue: true, - requestId: '2e9f38ea93bb9e', - ttl: 60, - width: 300, - }, - ]; - - const request = spec.buildRequests(validBidRequests, bidderRequest)[0]; - const bids = spec.interpretResponse(bidResponse, request); - - expect(bids).to.deep.equal(expectedBids); - }); - }); - - describe('getUserSyncs', () => { - const SYNC_URL = 'https://cdn.btloader.com/user_sync.html'; - - it('should return an empty array if no sync options are provided', () => { - const syncs = spec.getUserSyncs({}, [], null, null, null); - - expect(syncs).to.deep.equal([]); - }); - - it('should return an empty array if no server responses are provided', () => { - const syncs = spec.getUserSyncs( - { iframeEnabled: true }, - [], - null, - null, - null - ); - - expect(syncs).to.deep.equal([]); - }); - - it('should pass consent parameters and bidder codes in sync URL if they are provided', () => { - const gdprConsent = { - gdprApplies: true, - consentString: 'GDPRConsentString123', - }; - const gppConsent = { - gppString: 'GPPString123', - applicableSections: ['sectionA'], - }; - const us_privacy = '1YNY'; - const expectedSyncUrl = new URL(SYNC_URL); - expectedSyncUrl.searchParams.set('bidders', 'pubmatic,ix'); - expectedSyncUrl.searchParams.set('gdpr', 1); - expectedSyncUrl.searchParams.set( - 'gdpr_consent', - gdprConsent.consentString - ); - expectedSyncUrl.searchParams.set('gpp', gppConsent.gppString); - expectedSyncUrl.searchParams.set('gpp_sid', 'sectionA'); - expectedSyncUrl.searchParams.set('us_privacy', us_privacy); - const syncs = spec.getUserSyncs( - { iframeEnabled: true }, - [ - { body: { ext: { responsetimemillis: { pubmatic: 123 } } } }, - { body: { ext: { responsetimemillis: { pubmatic: 123, ix: 123 } } } }, - ], - gdprConsent, - us_privacy, - gppConsent - ); - - expect(syncs).to.deep.equal([ - { type: 'iframe', url: expectedSyncUrl.href }, - ]); - }); - }); -}); diff --git a/test/spec/modules/blueBidAdapter_spec.js b/test/spec/modules/blueBidAdapter_spec.js deleted file mode 100755 index cc373c6c2..000000000 --- a/test/spec/modules/blueBidAdapter_spec.js +++ /dev/null @@ -1,164 +0,0 @@ -import { expect } from 'chai'; -import sinon from 'sinon'; -import { spec, storage } from 'modules/blueBidAdapter.js'; - -const BIDDER_CODE = 'blue'; -const ENDPOINT_URL = 'https://bidder-us-east-1.getblue.io/engine/?src=prebid'; -const GVLID = 620; -const CURRENCY = 'USD'; - -describe('blueBidAdapter:', function () { - let sandbox; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - - afterEach(function () { - sandbox.restore(); - }); - - describe('isBidRequestValid:', function () { - it('should return true for valid bid requests', function () { - const validBid = { - params: { - placementId: '12345', - publisherId: '67890', - }, - }; - expect(spec.isBidRequestValid(validBid)).to.be.true; - }); - - it('should return false for invalid bid requests', function () { - const invalidBid = { - params: { - placementId: '12345', - }, - }; - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests:', function () { - let validBidRequests; - let bidderRequest; - - beforeEach(function () { - validBidRequests = [ - { - bidId: 'bid1', - params: { - placementId: '12345', - publisherId: '67890', - }, - getFloor: () => ({ currency: CURRENCY, floor: 1.5 }), - }, - ]; - - bidderRequest = { - refererInfo: { - page: 'https://example.com', - }, - }; - - sandbox.stub(storage, 'getDataFromLocalStorage').returns('testBuyerId'); - }); - - it('should build a valid OpenRTB request', function () { - const [request] = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal(ENDPOINT_URL); - expect(request.options.contentType).to.equal('application/json'); - - const ortbRequest = request.data; - expect(ortbRequest.ext.gvlid).to.equal(GVLID); - expect(ortbRequest.imp[0].bidfloor).to.equal(1.5); - expect(ortbRequest.imp[0].bidfloorcur).to.equal(CURRENCY); - }); - - it('should omit bidfloor if getFloor is not implemented', function () { - validBidRequests[0].getFloor = undefined; - - const [request] = spec.buildRequests(validBidRequests, bidderRequest); - const ortbRequest = request.data; - - expect(ortbRequest.imp[0].bidfloor).to.be.undefined; - }); - - it('should convert from fromORTB', function () { - const response = { - id: 'response-id-123456', - cur: 'USD', - bidid: '2rgRKcbHfDyX6ZU4zuPuf38h000', - seatbid: [ - { - bid: [ - { - id: '2rgRKcbHfDyX6ZU4zuPuf521444:0', - impid: '3b948a96652621', - price: 2, - adomain: ['example.com'], - adid: '0', - adm: '', - iurl: 'https://ads.bluemsusercontent.com/v1/ad-container?acc=306850905425&ad=2pMGbaJioMDwMIESvwlCUekrdNA', - h: 600, - w: 300, - nurl: 'https://bid-notice.rtb.bluems.com/v1/bid:won?winPrice=${AUCTION_PRICE}&accountId=306850905425&adId=2pMGbaJioMDwMIESvwlCUekrdNA&campaignId=2Xzb0pyfcOibtp9A5XsUSkzj2IT&exchangeId=prebid&tagId=13144370&impressionId=3b948a96652621&bidId=2rgRKcbHfDyX6ZU4zuPuf38hDB8%3A0&bidPrice=2&bidFloor=2&height=600&width=300®ion=us-east-1&targetId=2rgH24MVckzSou4IpTyUa5l3Ija¤cy=USD&campaignCurrency=USD&campaignCurrencyConversionFactor=1&publisherId=13144370&domain=d3fef36u6k6muh.cloudfront.net', - lurl: 'https://bid-notice.rtb.bluems.com/v1/bid:lost?winPrice=${AUCTION_PRICE}&marketBidRatio=${AUCTION_MBR}&lossReasonCode=${AUCTION_LOSS}&accountId=306850905425&adId=2pMGbaJioMDwMIESvwlCUekrdNA&campaignId=2Xzb0pyfcOibtp9A5XsUSkzj2IT&exchangeId=prebid&tagId=13144370&impressionId=3b948a96652621&bidId=2rgRKcbHfDyX6ZU4zuPuf38hDB8%3A0&bidPrice=2&bidFloor=2&height=600&width=300®ion=us-east-1&targetId=2rgH24MVckzSou4IpTyUa5l3Ija¤cy=USD&campaignCurrency=USD&campaignCurrencyConversionFactor=1&publisherId=13144370&domain=d3fef36u6k6muh.cloudfront.net', - burl: 'https://bid-notice.rtb.bluems.com/v1/bid:charged?winPrice=${AUCTION_PRICE}&accountId=306850905425&adId=2pMGbaJioMDwMIESvwlCUekrdNA&campaignId=2Xzb0pyfcOibtp9A5XsUSkzj2IT&exchangeId=prebid&tagId=13144370&impressionId=3b948a96652621&bidId=2rgRKcbHfDyX6ZU4zuPuf38hDB8%3A0&bidPrice=2&bidFloor=2&height=600&width=300®ion=us-east-1&targetId=2rgH24MVckzSou4IpTyUa5l3Ija¤cy=USD&campaignCurrency=USD&campaignCurrencyConversionFactor=1&publisherId=13144370&domain=d3fef36u6k6muh.cloudfront.net', - exp: 60, - ext: { - blue: { - accountId: '306850900000', - campaignId: '2Xzb0pyfcOibtp9A5X8546254528', - adId: '2pMGbaJioMDwMIESvwlCUlkojug', - region: 'us-east-1', - targetId: '2rgH24MVckzSou4IpTyUalakush', - }, - }, - }, - ], - seat: '1', - }, - ], - }; - const request = { - id: '10bb57ee-712f-43e9-9769-b26d03lklkih', - bidder: BIDDER_CODE, - params: { - source: 886409, - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - }, - }, - adUnitCode: 'div-gpt-ad-1460505iosakju-0', - transactionId: '7d79850b-70aa-4c0f-af95-c1d524sskjkjh', - sizes: [ - [300, 250], - [300, 600], - ], - bidId: '2eb89f0f062afe', - bidderRequestId: '1ae6c8e18f8462', - auctionId: '1286637c-51bc-4fdd-8e35-2435elklklka', - ortb2: {}, - }; - - const [ortbReq] = spec.buildRequests([request], { - bids: [request], - }); - - const ortbResponse = spec.interpretResponse( - { body: response }, - { data: ortbReq.data } - ); - - expect(ortbResponse.length).to.eq(1); - expect(ortbResponse[0].mediaType).to.eq('banner'); - }); - }); -}); diff --git a/test/spec/modules/blueconicRtdProvider_spec.js b/test/spec/modules/blueconicRtdProvider_spec.js deleted file mode 100644 index 4fe85d8a9..000000000 --- a/test/spec/modules/blueconicRtdProvider_spec.js +++ /dev/null @@ -1,135 +0,0 @@ -import {config} from 'src/config.js'; -import {RTD_LOCAL_NAME, addRealTimeData, getRealTimeData, blueconicSubmodule, storage} from 'modules/blueconicRtdProvider.js'; - -describe('blueconicRtdProvider', function() { - let getDataFromLocalStorageStub; - beforeEach(function() { - config.resetConfig(); - getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); - }); - - afterEach(function () { - getDataFromLocalStorageStub.restore(); - }); - - describe('blueconicSubmodule', function() { - it('successfully instantiates', function () { - expect(blueconicSubmodule.init()).to.equal(true); - }); - }); - - describe('Add Blueconic Real-Time Data', function() { - it('merges ortb2Fragment data', function() { - const setConfigUserObj1 = { - name: 'www.dataprovider1.com', - ext: {segtax: 1}, - segment: [{id: '1776'}] - }; - const setConfigUserObj2 = { - name: 'www.dataprovider2.com', - ext: {segtax: 1}, - segment: [{id: '1914'} - ] - }; - - const bidConfig = { - ortb2Fragments: { - global: { - user: { - data: [setConfigUserObj1, setConfigUserObj2] - } - } - } - }; - - const rtdUserObj1 = { - name: 'www.dataprovider4.com', - ext: {segtax: 1}, - segment: [{id: '1918'}, {id: '1939'} - ] - }; - - const rtd = { - ortb2: { - user: { - data: [rtdUserObj1] - } - } - }; - - addRealTimeData(bidConfig.ortb2Fragments.global, rtd); - - const ortb2Config = bidConfig.ortb2Fragments.global; - expect(ortb2Config.user.data).to.deep.include.members([setConfigUserObj1, setConfigUserObj2, rtdUserObj1]); - }); - - it('merges data without duplication', function() { - const userObj1 = { - name: 'www.dataprovider1.com', - ext: {segtax: 1}, - segment: [{id: '1776'} - ] - }; - - const userObj2 = { - ext: {segtax: 1}, - name: 'www.dataprovider2.com', - segment: [{id: '1914' - }] - }; - - const bidConfig = { - ortb2Fragments: - { - global: { - user: { - data: [userObj1, userObj2] - } - } - } - }; - - const rtd = { - ortb2: { - user: { - data: [userObj1] - } - } - }; - - addRealTimeData(bidConfig.ortb2Fragments.global, rtd); - - const ortb2Config = bidConfig.ortb2Fragments.global; - - expect(ortb2Config.user.data).to.deep.include.members([userObj1, userObj2]); - expect(bidConfig.ortb2Fragments.global.user.data).to.have.lengthOf(2); - }); - }); - - describe('Get BlueConic Real-Time Data', function() { - it('gets rtd from local storage cache', function() { - const rtdConfig = { - params: { - requestParams: { - publisherId: 'Publisher1', - coppa: true - }} - }; - - const bidConfig = {ortb2Fragments: {global: {}}}; - - const rtdUserObj1 = { - name: 'blueconic', - ext: {segtax: 1}, - segment: [{id: 'bf23d802-931d-4619-8266-ce9a6328aa2a'}], - bidId: '1234' - }; - - const cachedRtd = {ext: {segtax: 1}, 'segment': [{id: 'bf23d802-931d-4619-8266-ce9a6328aa2a'}], 'bidId': '1234'} - getDataFromLocalStorageStub.withArgs(RTD_LOCAL_NAME).returns(JSON.stringify(cachedRtd)); - - getRealTimeData(bidConfig, () => {}, rtdConfig, {}); - expect(bidConfig.ortb2Fragments.global.user.data).to.deep.include.members([rtdUserObj1]); - }); - }); -}); diff --git a/test/spec/modules/bmsBidAdapter_spec.js b/test/spec/modules/bmsBidAdapter_spec.js deleted file mode 100755 index 44112032d..000000000 --- a/test/spec/modules/bmsBidAdapter_spec.js +++ /dev/null @@ -1,165 +0,0 @@ -import { expect } from 'chai'; -import sinon from 'sinon'; -import { spec, storage } from 'modules/bmsBidAdapter.js'; - -const BIDDER_CODE = 'bms'; -const ENDPOINT_URL = - 'https://api.prebid.int.us-east-1.bluems.com/v1/bid?exchangeId=prebid'; -const GVLID = 1105; -const CURRENCY = 'USD'; - -describe('bmsBidAdapter:', function () { - let sandbox; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - - afterEach(function () { - sandbox.restore(); - }); - - describe('isBidRequestValid:', function () { - it('should return true for valid bid requests', function () { - const validBid = { - params: { - placementId: '12345', - publisherId: '67890', - }, - }; - expect(spec.isBidRequestValid(validBid)).to.be.true; - }); - - it('should return false for invalid bid requests', function () { - const invalidBid = { - params: { - placementId: '12345', - }, - }; - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests:', function () { - let validBidRequests; - let bidderRequest; - - beforeEach(function () { - validBidRequests = [ - { - bidId: 'bid1', - params: { - placementId: '12345', - publisherId: '67890', - }, - getFloor: () => ({ currency: CURRENCY, floor: 1.5 }), - }, - ]; - - bidderRequest = { - refererInfo: { - page: 'https://example.com', - }, - }; - - sandbox.stub(storage, 'getDataFromLocalStorage').returns('testBuyerId'); - }); - - it('should build a valid OpenRTB request', function () { - const [request] = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal(ENDPOINT_URL); - expect(request.options.contentType).to.equal('text/plain'); - const ortbRequest = JSON.parse(request.data); - - expect(ortbRequest.ext.gvlid).to.equal(GVLID); - expect(ortbRequest.imp[0].bidfloor).to.equal(1.5); - expect(ortbRequest.imp[0].bidfloorcur).to.equal(CURRENCY); - }); - - it('should omit bidfloor if getFloor is not implemented', function () { - validBidRequests[0].getFloor = undefined; - - const [request] = spec.buildRequests(validBidRequests, bidderRequest); - const ortbRequest = JSON.parse(request.data); - - expect(ortbRequest.imp[0].bidfloor).to.be.undefined; - }); - - it('should convert from fromORTB', function () { - const response = { - id: 'response-id-123456', - cur: 'USD', - bidid: '2rgRKcbHfDyX6ZU4zuPuf38h000', - seatbid: [ - { - bid: [ - { - id: '2rgRKcbHfDyX6ZU4zuPuf521444:0', - impid: '3b948a96652621', - price: 2, - adomain: ['example.com'], - adid: '0', - adm: '', - iurl: 'https://ads.bluemsusercontent.com/v1/ad-container?acc=306850905425&ad=2pMGbaJioMDwMIESvwlCUekrdNA', - h: 600, - w: 300, - nurl: 'https://bid-notice.rtb.bluems.com/v1/bid:won?winPrice=${AUCTION_PRICE}&accountId=306850905425&adId=2pMGbaJioMDwMIESvwlCUekrdNA&campaignId=2Xzb0pyfcOibtp9A5XsUSkzj2IT&exchangeId=prebid&tagId=13144370&impressionId=3b948a96652621&bidId=2rgRKcbHfDyX6ZU4zuPuf38hDB8%3A0&bidPrice=2&bidFloor=2&height=600&width=300®ion=us-east-1&targetId=2rgH24MVckzSou4IpTyUa5l3Ija¤cy=USD&campaignCurrency=USD&campaignCurrencyConversionFactor=1&publisherId=13144370&domain=d3fef36u6k6muh.cloudfront.net', - lurl: 'https://bid-notice.rtb.bluems.com/v1/bid:lost?winPrice=${AUCTION_PRICE}&marketBidRatio=${AUCTION_MBR}&lossReasonCode=${AUCTION_LOSS}&accountId=306850905425&adId=2pMGbaJioMDwMIESvwlCUekrdNA&campaignId=2Xzb0pyfcOibtp9A5XsUSkzj2IT&exchangeId=prebid&tagId=13144370&impressionId=3b948a96652621&bidId=2rgRKcbHfDyX6ZU4zuPuf38hDB8%3A0&bidPrice=2&bidFloor=2&height=600&width=300®ion=us-east-1&targetId=2rgH24MVckzSou4IpTyUa5l3Ija¤cy=USD&campaignCurrency=USD&campaignCurrencyConversionFactor=1&publisherId=13144370&domain=d3fef36u6k6muh.cloudfront.net', - burl: 'https://bid-notice.rtb.bluems.com/v1/bid:charged?winPrice=${AUCTION_PRICE}&accountId=306850905425&adId=2pMGbaJioMDwMIESvwlCUekrdNA&campaignId=2Xzb0pyfcOibtp9A5XsUSkzj2IT&exchangeId=prebid&tagId=13144370&impressionId=3b948a96652621&bidId=2rgRKcbHfDyX6ZU4zuPuf38hDB8%3A0&bidPrice=2&bidFloor=2&height=600&width=300®ion=us-east-1&targetId=2rgH24MVckzSou4IpTyUa5l3Ija¤cy=USD&campaignCurrency=USD&campaignCurrencyConversionFactor=1&publisherId=13144370&domain=d3fef36u6k6muh.cloudfront.net', - exp: 60, - ext: { - bms: { - accountId: '306850900000', - campaignId: '2Xzb0pyfcOibtp9A5X8546254528', - adId: '2pMGbaJioMDwMIESvwlCUlkojug', - region: 'us-east-1', - targetId: '2rgH24MVckzSou4IpTyUalakush', - }, - }, - }, - ], - seat: '1', - }, - ], - }; - const request = { - id: '10bb57ee-712f-43e9-9769-b26d03lklkih', - bidder: BIDDER_CODE, - params: { - source: 886409, - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - }, - }, - adUnitCode: 'div-gpt-ad-1460505iosakju-0', - transactionId: '7d79850b-70aa-4c0f-af95-c1d524sskjkjh', - sizes: [ - [300, 250], - [300, 600], - ], - bidId: '2eb89f0f062afe', - bidderRequestId: '1ae6c8e18f8462', - auctionId: '1286637c-51bc-4fdd-8e35-2435elklklka', - ortb2: {}, - }; - - const [ortbReq] = spec.buildRequests([request], { - bids: [request], - }); - - const ortbResponse = spec.interpretResponse( - { body: response }, - { data: ortbReq.data } - ); - - expect(ortbResponse.length).to.eq(1); - expect(ortbResponse[0].mediaType).to.eq('banner'); - }); - }); -}); diff --git a/test/spec/modules/bmtmBidAdapter_spec.js b/test/spec/modules/bmtmBidAdapter_spec.js deleted file mode 100644 index 4af4332f3..000000000 --- a/test/spec/modules/bmtmBidAdapter_spec.js +++ /dev/null @@ -1,327 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/bmtmBidAdapter.js'; - -const BIDDER_CODE = 'bmtm'; -const PLACEMENT_ID = 329; - -describe('brightMountainMediaBidAdapter_spec', function () { - const bidBanner = { - bidId: '2dd581a2b6281d', - bidder: BIDDER_CODE, - bidderRequestId: '145e1d6a7837c9', - params: { - placement_id: PLACEMENT_ID - }, - placementCode: 'placementid_0', - auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e62', - getFloor: function () { - return { - currency: 'USD', - floor: 0.5, - } - }, - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'directseller.com', - sid: '00001', - rid: 'BidRequest1', - hp: 1 - } - ] - } - } - } - }, - userIdAsEids: [ - { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': 'ID5-ZHMOaW5vh_TJhKVSaTWmuoTpwqjGGwx5v0WbaSV8yw', - 'atype': 1, - 'ext': { - 'linkType': 2 - } - } - ] - }, - { - 'source': 'pubcid.org', - 'uids': [ - { - 'id': '00000000000000000000000000', - 'atype': 1 - } - ] - } - ] - }; - - const bidVideo = { - bidId: '2dd581a2b6281d', - bidder: BIDDER_CODE, - bidderRequestId: '145e1d6a7837c9', - params: { - placement_id: PLACEMENT_ID - }, - placementCode: 'placementid_0', - auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', - mediaTypes: { - video: { - playerSizes: [[300, 250]], - context: 'outstream', - skip: 0, - playbackmethod: [1, 2], - mimes: ['video/mp4'] - } - }, - transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e62', - }; - - const bidderRequest = { - bidderCode: BIDDER_CODE, - auctionId: 'fffffff-ffff-ffff-ffff-ffffffffffff', - bidderRequestId: 'ffffffffffffff', - start: 1472239426002, - auctionStart: 1472239426000, - timeout: 5000, - uspConsent: '1YN-', - refererInfo: { - referer: 'http://www.example.com', - reachedTop: true, - }, - gdprConsent: { - consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==', - gdprApplies: true - }, - bids: [bidBanner], - }; - - describe('isBidRequestValid', function () { - it('Should return true when when required params found', function () { - expect(spec.isBidRequestValid(bidBanner)).to.be.true; - }); - it('Should return false when required params are not passed', function () { - bidBanner.params = {}; - expect(spec.isBidRequestValid(bidBanner)).to.be.false; - }); - }); - - describe('buildRequests', function () { - const request = spec.buildRequests([bidBanner], bidderRequest)[0]; - const data = JSON.parse(request.data); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(request).to.exist; - expect(request.method).to.exist; - expect(request.url).to.exist; - expect(request.data).to.exist; - expect(request.method).to.be.a('string'); - expect(request.url).to.be.a('string'); - expect(request.data).to.be.an('string'); - }); - - it('Returns valid data if array of bids is valid', function () { - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('at', 'site', 'device', 'cur', 'tmax', 'regs', 'user', 'source', 'imp', 'id'); - expect(data.at).to.be.a('number'); - expect(data.site).to.be.an('object'); - expect(data.device).to.be.an('object'); - expect(data.cur).to.be.an('array'); - expect(data.tmax).to.be.a('number'); - expect(data.regs).to.be.an('object'); - expect(data.user).to.be.an('object'); - expect(data.source).to.be.an('object'); - expect(data.imp).to.be.an('array'); - expect(data.id).to.be.a('string'); - }); - - it('Sends bidfloor param if present', function () { - expect(data.imp[0].bidfloor).to.equal(0.5); - }); - - it('Sends regs info if exists', function () { - expect(data.regs.ext.gdpr).to.exist.and.to.be.a('number'); - expect(data.regs.ext.gdprConsentString).to.exist.and.to.be.a('string'); - expect(data.regs.ext.us_privacy).to.exist.and.to.be.a('string'); - }); - - it('Sends schain info if exists', function () { - expect(data.source.ext).to.be.an('object'); - }); - - it('sends userId info if exists', function () { - expect(data.user.ext).to.have.property('eids'); - expect(data.user.ext.eids).to.not.equal(null).and.to.not.be.undefined; - expect(data.user.ext.eids.length).to.greaterThan(0); - for (const index in data.user.ext.eids) { - const eid = data.user.ext.eids[index]; - expect(eid.source).to.not.equal(null).and.to.not.be.undefined; - expect(eid.uids).to.not.equal(null).and.to.not.be.undefined; - for (const uidsIndex in eid.uids) { - const uid = eid.uids[uidsIndex]; - expect(uid.id).to.not.equal(null).and.to.not.be.undefined; - } - } - }); - - it('Returns valid data if array of bids is valid for banner', function () { - expect(data).to.be.an('object'); - expect(data).to.have.property('imp'); - expect(data.imp.length).to.greaterThan(0); - expect(data.imp[0]).to.have.property('banner'); - expect(data.imp[0].banner).to.be.an('object'); - expect(data.imp[0].banner.h).to.exist.and.to.be.a('number'); - expect(data.imp[0].banner.w).to.exist.and.to.be.a('number'); - }); - - it('Returns valid data if array of bids is valid for video', function () { - bidderRequest.bids = [bidVideo]; - const serverRequest = spec.buildRequests([bidVideo], bidderRequest)[0]; - const data = JSON.parse(serverRequest.data); - expect(data).to.be.an('object'); - expect(data).to.have.property('imp'); - expect(data.imp.length).to.greaterThan(0); - expect(data.imp[0]).to.have.property('video'); - expect(data.imp[0].video).to.be.an('object'); - expect(data.imp[0].video.h).to.exist.and.to.be.a('number'); - expect(data.imp[0].video.w).to.exist.and.to.be.a('number'); - }); - }); - - describe('interpretResponse', function () { - const resObjectBanner = { - 'id': '2763-05f22da29b3ffb6-6959', - 'bidid': 'e5b41111bec9e4a4e94b85d082f8fb08', - 'seatbid': [ - { - 'bid': [ - { - 'id': '9550c3e641761cfbf2a4dd672b50ddb9', - 'impid': '968', - 'price': 0.3, - 'w': 300, - 'h': 250, - 'nurl': 'https://example.com/?w=nr&pf=${AUCTION_PRICE}&type=b&uq=483531c101942cbb270cd088b2eec43f', - 'adomain': [ - 'example.com' - ], - 'cid': '3845_105654', - 'crid': '3845_305654', - 'adm': '

Test Ad

', - 'adid': '17794c46ca26', - 'iurl': 'https://example.com/?t=preview2&k=17794c46ca26' - } - ], - 'seat': '3845' - } - ], - 'cur': 'USD' - }; - - const resObjectVideo = { - 'id': '2763-05f22da29b3ffb6-6959', - 'bidid': 'e5b41111bec9e4a4e94b85d082f8fb08', - 'seatbid': [ - { - 'bid': [ - { - 'id': '9550c3e641761cfbf2a4dd672b50ddb9', - 'impid': '968', - 'price': 0.3, - 'w': 300, - 'h': 250, - 'nurl': 'https://example.com/?w=nr&pf=${AUCTION_PRICE}&type=b&uq=483531c101942cbb270cd088b2eec43f', - 'adomain': [ - 'example.com' - ], - 'cid': '3845_105654', - 'crid': '3845_305654', - 'adm': '', - 'adid': '17794c46ca26', - 'iurl': 'https://example.com/?t=preview2&k=17794c46ca26' - } - ], - 'seat': '3845' - } - ], - 'cur': 'USD' - }; - - it('Returns an array of valid response if response object is valid for banner', function () { - const bidResponse = spec.interpretResponse({ - body: resObjectBanner - }, { bidRequest: bidBanner }); - - expect(bidResponse).to.be.an('array').that.is.not.empty; - for (let i = 0; i < bidResponse.length; i++) { - const dataItem = bidResponse[i]; - expect(dataItem.requestId).to.be.a('string'); - expect(dataItem.cpm).to.be.a('number'); - expect(dataItem.width).to.be.a('number'); - expect(dataItem.height).to.be.a('number'); - expect(dataItem.ad).to.be.a('string'); - expect(dataItem.ttl).to.be.a('number'); - expect(dataItem.creativeId).to.be.a('string'); - expect(dataItem.netRevenue).to.be.a('boolean'); - expect(dataItem.currency).to.be.a('string'); - expect(dataItem.mediaType).to.be.a('string'); - expect(dataItem.meta.advertiserDomains[0]).to.be.a('string'); - } - }); - - it('Returns an array of valid response if response object is valid for video', function () { - const bidResponse = spec.interpretResponse({ - body: resObjectVideo - }, { bidRequest: bidVideo }); - - expect(bidResponse).to.be.an('array').that.is.not.empty; - for (let i = 0; i < bidResponse.length; i++) { - const dataItem = bidResponse[i]; - expect(dataItem.requestId).to.be.a('string'); - expect(dataItem.cpm).to.be.a('number'); - expect(dataItem.width).to.be.a('number'); - expect(dataItem.height).to.be.a('number'); - expect(dataItem.vastXml).to.be.a('string'); - expect(dataItem.ttl).to.be.a('number'); - expect(dataItem.creativeId).to.be.a('string'); - expect(dataItem.netRevenue).to.be.a('boolean'); - expect(dataItem.currency).to.be.a('string'); - expect(dataItem.mediaType).to.be.a('string'); - expect(dataItem.meta.advertiserDomains[0]).to.be.a('string'); - } - }); - - it('Returns an empty array if invalid response is passed', function () { - const bidResponse = spec.interpretResponse({ - body: '' - }, { bidRequest: bidBanner }); - expect(bidResponse).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function () { - const syncoptionsIframe = { - 'iframeEnabled': 'true' - } - it('should return iframe sync option', function () { - expect(spec.getUserSyncs(syncoptionsIframe)).to.be.an('array').with.lengthOf(1); - expect(spec.getUserSyncs(syncoptionsIframe)[0].type).to.exist; - expect(spec.getUserSyncs(syncoptionsIframe)[0].url).to.exist; - expect(spec.getUserSyncs(syncoptionsIframe)[0].type).to.equal('iframe') - expect(spec.getUserSyncs(syncoptionsIframe)[0].url).to.equal('https://console.brightmountainmedia.com:8443/cookieSync') - }); - }); -}); diff --git a/test/spec/modules/boldwinBidAdapter_spec.js b/test/spec/modules/boldwinBidAdapter_spec.js deleted file mode 100644 index 5d8c7fab9..000000000 --- a/test/spec/modules/boldwinBidAdapter_spec.js +++ /dev/null @@ -1,469 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/boldwinBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'boldwin'; - -describe('BoldwinBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://ssp.videowalldirect.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.wPlayer).to.be.an('number'); - expect(placement.hPlayer).to.be.an('number'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync.videowalldirect.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync.videowalldirect.com/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync.videowalldirect.com/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/brainxBidAdapter_spec.js b/test/spec/modules/brainxBidAdapter_spec.js deleted file mode 100644 index baa7152fc..000000000 --- a/test/spec/modules/brainxBidAdapter_spec.js +++ /dev/null @@ -1,132 +0,0 @@ -// import or require modules necessary for the test, e.g.: -import { expect } from 'chai'; // may prefer 'assert' in place of 'expect' -import { spec } from 'modules/brainxBidAdapter.js'; -import utils, { deepClone } from '../../../src/utils.js'; -// import adapter from 'src/adapters/'; -import { BANNER, NATIVE, VIDEO } from 'src/mediaTypes.js'; - -describe('Brain-X Aapater', function () { - describe('isBidRequestValid', function () { - it('undefined bid should return false', function () { - expect(spec.isBidRequestValid()).to.be.false; - }); - - it('null bid should return false', function () { - expect(spec.isBidRequestValid(null)).to.be.false; - }); - - it('bid.params should be set', function () { - expect(spec.isBidRequestValid({})).to.be.false; - }); - - it('bid.params.pubId should be set', function () { - expect(spec.isBidRequestValid({ - params: { pubId: 'F7B53DBC-85C1-4685-9A06-9CF4B6261FA3', endpoint: 'http://adx-engine-gray.tec-do.cn/bid' } - })).to.be.false; - }); - }) - - // describe('isBidRequestValid', function () { - // it('Test the banner request processing function', function () { - // const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - // expect(request).to.not.be.empty; - // const payload = request.data; - // expect(payload).to.not.be.empty; - // }); - // it('Test the video request processing function', function () { - // const request = spec.buildRequests(videoRequest, videoRequest[0]); - // expect(request).to.not.be.empty; - // const payload = request.data; - // expect(payload).to.not.be.empty; - // }); - // it('Test the param', function () { - // const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - // const payload = JSON.parse(request.data); - // expect(payload.imp[0].tagid).to.eql(videoRequest[0].params.tagid); - // expect(payload.imp[0].bidfloor).to.eql(videoRequest[0].params.bidfloor); - // }); - // }) - - describe('interpretResponse', function () { - it('Test banner interpretResponse', function () { - const serverResponse = { - body: { - 'bidid': 'a82042c055b04e539ec6876112c10ced1729663902983', - 'cur': 'USD', - 'id': '28f8f1f525372a', - 'seatbid': [ - { - 'bid': [ - { - 'adid': '76797', - 'adm': "
\n \n
\n
\n \n \n
\n
\n\n", - 'adomain': [ - 'taobao.com' - ], - 'bundle': 'com.taobao', - 'burl': 'https://adx-event-server.bidtrail.top/billing?s=Eid0ZWMxNDk4NDQzODk3MjcwOTU1MzAwNzM3YjczMTQwMTA4ODk5ODQaDjI4ZjhmMWY1MjUzNzJhIKkCKgbmtYvor5U6DmxvY2FsaG9zdDo5OTk5Qgl1bmRlZmluZWRKA0hLR1ADYAFoAXADeAOAAQKKAQpjb20udGFvYmFvlQEX2U49nQEX2U49pQEX2U49ugEqCO4HEiUI7gcSCFRlY2RvRFNQGA01F9lOPTgBQBVKC1RlY2RvRFNQX1NHwAHuB8gBjcqCwKsy0AEC-gGbAmh0dHBzOi8vbm90aWNlLXNnLmJpZHRyYWlsLnRvcC93aW4_YmlkX2lkPWE4MjA0MmMwNTViMDRlNTM5ZWM2ODc2MTEyYzEwY2VkMTcyOTY2MzkwMjk4MyZjYW1wYWlnbl9pZD00MjgmYWRfZ3JvdXBfaWQ9OTc2MSZhZF9pZD03Njc5NyZjcmVhdGl2ZV9pZD02NTI2JmFmZmlsaWF0ZV9pZD0yOTcmYnVuZGxlPSZmaXJzdF9zc3A9YnJhaW54LnRlY2gmcHVibGlzaF9pZD0mb3M9QW5kcm9pZCZ0YWdfaWQ9dW5kZWZpbmVkJmJpZF9zdWNjZXNzX3ByaWNlPTAuMDUwNSZzaWduPWUzODQyNjhiYzAzYzhmYmOSAgp0YW9iYW8uY29togILYnJhaW54LnRlY2ioAgGyAgdhbmRyb2lkwAICygICc2fQAgHYAo3hlcWrMuACjeGVxasy&v=P-1b7JJWs-uUQ68A37V4xDLplU0&auction_price=${AUCTION_PRICE}', - 'cat': [ - 'IAB18-5' - ], - 'cid': '428', - 'crid': 'D06g1RVGMEnC+9Le4SZMJw==', - 'h': 480, - 'id': 'a82042c055b04e539ec6876112c10ced1729663902983', - 'impid': '3c1dd9e1700358', - 'iurl': 'https://creative.bidtrail.top/png/2/20f24c10f21e/091b422e3014033e57acffcf2a5c71dbb17383ec15ac9421', - 'lurl': 'https://notice-sg.bidtrail.top/loss?bid_id=a82042c055b04e539ec6876112c10ced1729663902983&sign=e384268bc03c8fbc&campaign_id=428&ad_group_id=9761&ad_id=76797&creative_id=6526&affiliate_id=297&loss_code=${AUCTION_LOSS}', - 'nurl': 'https://adx-event-server.bidtrail.top/winnotice?s=Eid0ZWMxNDk4NDQzODk3MjcwOTU1MzAwNzM3YjczMTQwMTA4ODk5ODQaDjI4ZjhmMWY1MjUzNzJhIKkCKgbmtYvor5U6DmxvY2FsaG9zdDo5OTk5Qgl1bmRlZmluZWRKA0hLR1ADYAFoAXADeAOAAQKKAQpjb20udGFvYmFvlQEX2U49nQEX2U49pQEX2U49ugEqCO4HEiUI7gcSCFRlY2RvRFNQGA01F9lOPTgBQBVKC1RlY2RvRFNQX1NHwAHuB8gBjcqCwKsy0AEB-gGbAmh0dHBzOi8vbm90aWNlLXNnLmJpZHRyYWlsLnRvcC93aW4_YmlkX2lkPWE4MjA0MmMwNTViMDRlNTM5ZWM2ODc2MTEyYzEwY2VkMTcyOTY2MzkwMjk4MyZjYW1wYWlnbl9pZD00MjgmYWRfZ3JvdXBfaWQ9OTc2MSZhZF9pZD03Njc5NyZjcmVhdGl2ZV9pZD02NTI2JmFmZmlsaWF0ZV9pZD0yOTcmYnVuZGxlPSZmaXJzdF9zc3A9YnJhaW54LnRlY2gmcHVibGlzaF9pZD0mb3M9QW5kcm9pZCZ0YWdfaWQ9dW5kZWZpbmVkJmJpZF9zdWNjZXNzX3ByaWNlPTAuMDUwNSZzaWduPWUzODQyNjhiYzAzYzhmYmOSAgp0YW9iYW8uY29togILYnJhaW54LnRlY2ioAgGyAgdhbmRyb2lkwAICygICc2fQAgHYAo3hlcWrMuACjeGVxasy&v=jFUg_b6F14d50JL-M6UE5Jc8VuA&auction_price=${AUCTION_PRICE}', - 'price': 0.0505, - 'w': 320 - } - ], - 'group': 0, - 'seat': 'agency' - } - ] - } - }; - - const bidResponses = spec.interpretResponse(serverResponse, { - originalBidRequest: { - auctionId: '3eedbf83-7d1d-423c-be27-39e4af687040', - auctionStart: 1729663900819, - adUnitCode: 'dev-1', - bidId: '28f8f1f525372a', - bidder: 'brainx', - mediaTypes: { banner: { sizes: [[300, 250]] } }, - params: { - pubId: 'F7B53DBC-85C1-4685-9A06-9CF4B6261FA3', - endpoint: 'http://adx-engine-gray.tec-do.cn/bid' - }, - src: 'client' - } - }); - - expect(bidResponses).to.be.an('array').that.is.not.empty; - - const bid = serverResponse.body.seatbid[0].bid[0]; - const bidResponse = bidResponses[0]; - - expect(bidResponse.mediaType).to.equal(BANNER); - expect(bidResponse.requestId).to.equal(bid.impid); - expect(bidResponse.cpm).to.equal(parseFloat(bid.price).toFixed(2)) - expect(bidResponse.currency).to.equal(serverResponse.body.cur); - expect(bidResponse.creativeId).to.equal(bid.crid || bid.id); - expect(bidResponse.netRevenue).to.be.true; - expect(bidResponse.nurl).to.equal(bid.nurl); - expect(bidResponse.lurl).to.equal(bid.lurl); - - expect(bidResponse.meta).to.be.an('object'); - expect(bidResponse.meta.mediaType).to.equal(BANNER); - expect(bidResponse.meta.primaryCatId).to.equal('IAB18-5'); - // expect(bidResponse.meta.secondaryCatIds).to.deep.equal(['IAB8']); - expect(bidResponse.meta.advertiserDomains).to.deep.equal(bid.adomain); - expect(bidResponse.meta.clickUrl).to.equal(bid.adomain[0]); - - expect(bidResponse.ad).to.equal(bid.adm); - expect(bidResponse.width).to.equal(bid.w); - expect(bidResponse.height).to.equal(bid.h); - }); - }); -}); diff --git a/test/spec/modules/brandmetricsRtdProvider_spec.js b/test/spec/modules/brandmetricsRtdProvider_spec.js deleted file mode 100644 index 6bc521b21..000000000 --- a/test/spec/modules/brandmetricsRtdProvider_spec.js +++ /dev/null @@ -1,259 +0,0 @@ -import * as brandmetricsRTD from '../../../modules/brandmetricsRtdProvider.js'; -import {config} from 'src/config.js'; -import * as events from '../../../src/events.js'; -import * as sinon from 'sinon'; - -const VALID_CONFIG = { - name: 'brandmetrics', - waitForIt: true, - params: { - scriptId: '00000000-0000-0000-0000-000000000000', - bidders: ['ozone'] - } -}; - -const NO_BIDDERS_CONFIG = { - name: 'brandmetrics', - waitForIt: true, - params: { - scriptId: '00000000-0000-0000-0000-000000000000' - } -}; - -const NO_SCRIPTID_CONFIG = { - name: 'brandmetrics', - waitForIt: true -}; - -const USER_CONSENT = { - gdpr: { - vendorData: { - vendor: { - consents: { - 422: true - } - }, - purpose: { - consents: { - 1: true, - 7: true - } - } - }, - gdprApplies: true - } -}; - -const NO_TCF_CONSENT = { - gdpr: { - vendorData: { - vendor: { - consents: { - 422: false - } - }, - purpose: { - consents: { - 1: false, - 7: false - } - } - }, - gdprApplies: true - } -}; - -const NO_USP_CONSENT = { - usp: '1NYY' -}; - -const UNDEFINED_USER_CONSENT = {}; - -function mockSurveyLoaded(surveyConf) { - const commands = window._brandmetrics || []; - commands.forEach(command => { - if (command.cmd === '_addeventlistener') { - const conf = command.val; - if (conf.event === 'surveyloaded') { - conf.handler(surveyConf); - } - } - }); -} - -function mockCreativeInView(creativeInViewConf) { - const commands = window._brandmetrics || []; - commands.forEach(command => { - if (command.cmd === '_addeventlistener') { - const conf = command.val; - if (conf.event === 'creative_in_view') { - conf.handler(creativeInViewConf); - } - } - }) -} - -describe('BrandmetricsRTD module', () => { - beforeEach(function () { - const scriptTags = document.getElementsByTagName('script'); - for (let i = 0; i < scriptTags.length; i++) { - if (scriptTags[i].src.indexOf('brandmetrics') !== -1) { - scriptTags[i].remove(); - } - } - }); - - it('should init and return true', () => { - expect(brandmetricsRTD.brandmetricsSubmodule.init(VALID_CONFIG, USER_CONSENT)).to.equal(true); - }); - - it('should init and return true even if bidders is not included', () => { - expect(brandmetricsRTD.brandmetricsSubmodule.init(NO_BIDDERS_CONFIG, USER_CONSENT)).to.equal(true); - }); - - it('should init even if script- id is not configured', () => { - expect(brandmetricsRTD.brandmetricsSubmodule.init(NO_SCRIPTID_CONFIG, USER_CONSENT)).to.equal(true); - }); - - it('should not init when there is no TCF- consent', () => { - expect(brandmetricsRTD.brandmetricsSubmodule.init(VALID_CONFIG, NO_TCF_CONSENT)).to.equal(false); - }); - - it('should not init when there is no usp- consent', () => { - expect(brandmetricsRTD.brandmetricsSubmodule.init(VALID_CONFIG, NO_USP_CONSENT)).to.equal(false); - }); - - it('should init if there are no consent- objects defined', () => { - expect(brandmetricsRTD.brandmetricsSubmodule.init(VALID_CONFIG, UNDEFINED_USER_CONSENT)).to.equal(true); - }); -}); - -describe('getBidRequestData', () => { - beforeEach(function () { - config.resetConfig() - }) - - it('should set targeting keys for specified bidders', () => { - const bidderOrtb2 = {}; - brandmetricsRTD.brandmetricsSubmodule.getBidRequestData({ortb2Fragments: {bidder: bidderOrtb2}}, () => { - const expected = VALID_CONFIG.params.bidders - - expected.forEach(exp => { - expect(bidderOrtb2[exp].user.ext.data.mockTargetKey).to.equal('mockMeasurementId') - }) - }, VALID_CONFIG); - - mockSurveyLoaded({ - available: true, - conf: { - displayOption: { - type: 'pbjs', - targetKey: 'mockTargetKey' - } - }, - survey: { - measurementId: 'mockMeasurementId' - } - }); - }); - - it('should only set targeting keys when the brandmetrics survey- type is "pbjs"', () => { - mockSurveyLoaded({ - available: true, - conf: { - displayOption: { - type: 'dfp', - targetKey: 'mockTargetKey' - } - }, - survey: { - measurementId: 'mockMeasurementId' - } - }); - - const bidderOrtb2 = {}; - brandmetricsRTD.brandmetricsSubmodule.getBidRequestData({ortb2Fragments: {bidder: bidderOrtb2}}, () => {}, VALID_CONFIG); - expect(Object.keys(bidderOrtb2).length).to.equal(0) - }); - - it('should use a default targeting key name if the brandmetrics- configuration does not include one', () => { - mockSurveyLoaded({ - available: true, - conf: { - displayOption: { - type: 'pbjs', - } - }, - survey: { - measurementId: 'mockMeasurementId' - } - }); - - const bidderOrtb2 = {}; - brandmetricsRTD.brandmetricsSubmodule.getBidRequestData({ortb2Fragments: {bidder: bidderOrtb2}}, () => {}, VALID_CONFIG); - - const expected = VALID_CONFIG.params.bidders - - expected.forEach(exp => { - expect(bidderOrtb2[exp].user.ext.data.brandmetrics_survey).to.equal('mockMeasurementId') - }) - }); - - describe('billable events', () => { - let sandbox; - let eventsEmitSpy; - - before(() => { - sandbox = sinon.createSandbox(); - eventsEmitSpy = sandbox.spy(events, ['emit']); - }); - - beforeEach(() => { - eventsEmitSpy.resetHistory(); - }) - - afterEach(() => { - sandbox.restore(); - }); - - it('should emit billable event from prebid events', () => { - const expectedEvent = { - vendor: 'brandmetrics', - type: 'creative_in_view', - measurementId: 'mockMeasurementId', - auctionId: 'mockAuctionId', - transactionId: 'mockTransactionId' - }; - - mockCreativeInView({ - mid: expectedEvent.measurementId, - source: { - type: 'pbj', - data: { - auctionId: expectedEvent.auctionId, - transactionId: expectedEvent.transactionId - }, - } - }); - - expect(eventsEmitSpy.callCount).to.equal(1); - - const event = eventsEmitSpy.getCalls()[0].args[1]; - delete event['billingId']; - - expect(event).to.deep.equal(expectedEvent); - }); - - it('should not emit billable event from non prebid- sources', () => { - mockCreativeInView({ - mid: 'mockMeasurementId', - source: { - type: 'gpt', - data: {}, - } - }); - - expect(eventsEmitSpy.callCount).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/braveBidAdapter_spec.js b/test/spec/modules/braveBidAdapter_spec.js deleted file mode 100644 index 92a235a92..000000000 --- a/test/spec/modules/braveBidAdapter_spec.js +++ /dev/null @@ -1,363 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/braveBidAdapter.js'; - -const request_native = { - code: 'brave-native-prebid', - mediaTypes: { - native: { - title: { - required: true, - len: 800 - }, - image: { - required: true, - len: 80 - }, - sponsoredBy: { - required: true - }, - clickUrl: { - required: true - }, - privacyLink: { - required: false - }, - body: { - required: true - }, - icon: { - required: true, - sizes: [50, 50] - } - } - }, - bidder: 'brave', - params: { - placementId: 'to0QI2aPgkbBZq6vgf0oHitouZduz0qw' - } -}; - -const request_banner = { - code: 'brave-prebid', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - bidder: 'brave', - params: { - placementId: 'to0QI2aPgkbBZq6vgf0oHitouZduz0qw' - } -} - -const bidRequest = { - gdprConsent: { - consentString: 'HFIDUYFIUYIUYWIPOI87392DSU', - gdprApplies: true - }, - uspConsent: 'uspConsentString', - bidderRequestId: 'testid', - refererInfo: { - referer: 'testdomain.com' - }, - timeout: 700 -} - -const request_video = { - code: 'brave-video-prebid', - mediaTypes: { video: { - minduration: 1, - maxduration: 999, - boxingallowed: 1, - skip: 0, - mimes: [ - 'application/javascript', - 'video/mp4' - ], - playerSize: [[768, 1024]], - protocols: [ - 2, 3 - ], - linearity: 1, - api: [ - 1, - 2 - ] - } - }, - - bidder: 'brave', - params: { - placementId: 'to0QI2aPgkbBZq6vgf0oHitouZduz0qw' - } - -} - -const response_banner = { - id: 'request_id', - bidid: 'request_imp_id', - seatbid: [{ - bid: [{ - id: 'bid_id', - impid: 'request_imp_id', - price: 5, - adomain: ['example.com'], - adm: 'admcode', - crid: 'crid', - ext: { - mediaType: 'banner' - } - }] - }] -}; - -const response_video = { - id: 'request_id', - bidid: 'request_imp_id', - seatbid: [{ - bid: [{ - id: 'bid_id', - impid: 'request_imp_id', - price: 5, - adomain: ['example.com'], - adm: 'admcode', - crid: 'crid', - ext: { - mediaType: 'video' - } - }], - }], -}; - -const imgData = { - url: `https://example.com/image`, - w: 1200, - h: 627 -}; - -const response_native = { - id: 'request_id', - bidid: 'request_imp_id', - seatbid: [{ - bid: [{ - id: 'bid_id', - impid: 'request_imp_id', - price: 5, - adomain: ['example.com'], - adm: { native: - { - assets: [ - {id: 1, title: 'dummyText'}, - {id: 3, image: imgData}, - { - id: 5, - data: {value: 'organization.name'} - } - ], - link: {url: 'example.com'}, - imptrackers: ['tracker1.com', 'tracker2.com', 'tracker3.com'], - jstracker: 'tracker1.com' - } - }, - crid: 'crid', - ext: { - mediaType: 'native' - } - }], - }], -}; - -describe('BraveBidAdapter', function() { - describe('isBidRequestValid', function() { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(request_banner)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const bid = Object.assign({}, request_banner); - bid.params = { - 'IncorrectParam': 0 - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('build Native Request', function () { - const request = spec.buildRequests([request_native], bidRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(request).to.exist; - expect(request.method).to.exist; - expect(request.url).to.exist; - expect(request.data).to.exist; - }); - - it('sends bid request to our endpoint via POST', function () { - expect(request.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(request.url).to.equal('https://point.braveglobal.tv/?t=2&partner=to0QI2aPgkbBZq6vgf0oHitouZduz0qw'); - }); - - it('Returns empty data if no valid requests are passed', function () { - const serverRequest = spec.buildRequests([]); - expect(serverRequest).to.be.an('array').that.is.empty; - }); - }); - - describe('build Banner Request', function () { - const request = spec.buildRequests([request_banner], bidRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(request).to.exist; - expect(request.method).to.exist; - expect(request.url).to.exist; - expect(request.data).to.exist; - }); - - it('sends bid request to our endpoint via POST', function () { - expect(request.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(request.url).to.equal('https://point.braveglobal.tv/?t=2&partner=to0QI2aPgkbBZq6vgf0oHitouZduz0qw'); - }); - }); - - describe('build Video Request', function () { - const request = spec.buildRequests([request_video], bidRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(request).to.exist; - expect(request.method).to.exist; - expect(request.url).to.exist; - expect(request.data).to.exist; - }); - - it('sends bid request to our endpoint via POST', function () { - expect(request.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(request.url).to.equal('https://point.braveglobal.tv/?t=2&partner=to0QI2aPgkbBZq6vgf0oHitouZduz0qw'); - }); - }); - - describe('interpretResponse', function () { - it('Empty response must return empty array', function() { - const emptyResponse = null; - const response = spec.interpretResponse(emptyResponse); - - expect(response).to.be.an('array').that.is.empty; - }) - - it('Should interpret banner response', function () { - const bannerResponse = { - body: response_banner - } - - const expectedBidResponse = { - requestId: response_banner.seatbid[0].bid[0].impid, - cpm: response_banner.seatbid[0].bid[0].price, - width: response_banner.seatbid[0].bid[0].w, - height: response_banner.seatbid[0].bid[0].h, - ttl: response_banner.ttl || 1200, - currency: response_banner.cur || 'USD', - netRevenue: true, - creativeId: response_banner.seatbid[0].bid[0].crid, - dealId: response_banner.seatbid[0].bid[0].dealid, - mediaType: 'banner', - ad: response_banner.seatbid[0].bid[0].adm - } - - const bannerResponses = spec.interpretResponse(bannerResponse); - - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType'); - expect(dataItem.requestId).to.equal(expectedBidResponse.requestId); - expect(dataItem.cpm).to.equal(expectedBidResponse.cpm); - expect(dataItem.ad).to.equal(expectedBidResponse.ad); - expect(dataItem.ttl).to.equal(expectedBidResponse.ttl); - expect(dataItem.creativeId).to.equal(expectedBidResponse.creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(expectedBidResponse.currency); - expect(dataItem.width).to.equal(expectedBidResponse.width); - expect(dataItem.height).to.equal(expectedBidResponse.height); - }); - - it('Should interpret video response', function () { - const videoResponse = { - body: response_video - } - - const expectedBidResponse = { - requestId: response_video.seatbid[0].bid[0].impid, - cpm: response_video.seatbid[0].bid[0].price, - width: response_video.seatbid[0].bid[0].w, - height: response_video.seatbid[0].bid[0].h, - ttl: response_video.ttl || 1200, - currency: response_video.cur || 'USD', - netRevenue: true, - creativeId: response_video.seatbid[0].bid[0].crid, - dealId: response_video.seatbid[0].bid[0].dealid, - mediaType: 'video', - vastXml: response_video.seatbid[0].bid[0].adm - } - - const videoResponses = spec.interpretResponse(videoResponse); - - expect(videoResponses).to.be.an('array').that.is.not.empty; - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'vastXml', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType'); - expect(dataItem.requestId).to.equal(expectedBidResponse.requestId); - expect(dataItem.cpm).to.equal(expectedBidResponse.cpm); - expect(dataItem.vastXml).to.equal(expectedBidResponse.vastXml) - expect(dataItem.ttl).to.equal(expectedBidResponse.ttl); - expect(dataItem.creativeId).to.equal(expectedBidResponse.creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(expectedBidResponse.currency); - expect(dataItem.width).to.equal(expectedBidResponse.width); - expect(dataItem.height).to.equal(expectedBidResponse.height); - }); - - it('Should interpret native response', function () { - const nativeResponse = { - body: response_native - } - - const expectedBidResponse = { - requestId: response_native.seatbid[0].bid[0].impid, - cpm: response_native.seatbid[0].bid[0].price, - width: response_native.seatbid[0].bid[0].w, - height: response_native.seatbid[0].bid[0].h, - ttl: response_native.ttl || 1200, - currency: response_native.cur || 'USD', - netRevenue: true, - creativeId: response_native.seatbid[0].bid[0].crid, - dealId: response_native.seatbid[0].bid[0].dealid, - mediaType: 'native', - native: {clickUrl: response_native.seatbid[0].bid[0].adm.native.link.url} - } - - const nativeResponses = spec.interpretResponse(nativeResponse); - - expect(nativeResponses).to.be.an('array').that.is.not.empty; - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'native', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType'); - expect(dataItem.requestId).to.equal(expectedBidResponse.requestId); - expect(dataItem.cpm).to.equal(expectedBidResponse.cpm); - expect(dataItem.native.clickUrl).to.equal(expectedBidResponse.native.clickUrl) - expect(dataItem.ttl).to.equal(expectedBidResponse.ttl); - expect(dataItem.creativeId).to.equal(expectedBidResponse.creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(expectedBidResponse.currency); - expect(dataItem.width).to.equal(expectedBidResponse.width); - expect(dataItem.height).to.equal(expectedBidResponse.height); - }); - }); -}) diff --git a/test/spec/modules/bridBidAdapter_spec.js b/test/spec/modules/bridBidAdapter_spec.js deleted file mode 100644 index 4819f8174..000000000 --- a/test/spec/modules/bridBidAdapter_spec.js +++ /dev/null @@ -1,173 +0,0 @@ -import { spec } from '../../../modules/bridBidAdapter.js' -import { SYNC_URL } from '../../../libraries/targetVideoUtils/constants.js'; -import { deepClone } from '../../../src/utils.js'; - -describe('Brid Bid Adapter', function() { - const videoRequest = [{ - bidder: 'brid', - params: { - placementId: 12345, - }, - mediaTypes: { - video: { - playerSize: [[640, 360]], - context: 'instream', - playbackmethod: [1, 2, 3, 4] - } - } - }]; - - it('Test the bid validation function', function() { - const validBid = spec.isBidRequestValid(videoRequest[0]); - const invalidBid = spec.isBidRequestValid(null); - - expect(validBid).to.be.true; - expect(invalidBid).to.be.false; - }); - - it('Test the request processing function', function () { - const request = spec.buildRequests(videoRequest, videoRequest[0]); - expect(request).to.not.be.empty; - - const payload = JSON.parse(request[0].data); - expect(payload).to.not.be.empty; - expect(payload.sdk).to.deep.equal({ - source: 'pbjs', - version: '$prebid.version$' - }); - expect(payload.imp[0].ext.prebid.storedrequest.id).to.equal(12345); - }); - - it('Test the request schain sending', function() { - const globalSchain = { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'examplewebsite.com', - sid: '00001', - hp: 1 - }] - }; - - const videoRequestCloned = deepClone(videoRequest); - videoRequestCloned[0].ortb2 = { source: { ext: { schain: globalSchain } } }; - - const request = spec.buildRequests(videoRequestCloned, videoRequestCloned[0]); - expect(request).to.not.be.empty; - - const payload = JSON.parse(request[0].data); - expect(payload).to.not.be.empty; - expect(payload.source.ext.schain).to.exist; - expect(payload.source.ext.schain).to.deep.equal(globalSchain); - }); - - it('Test nobid responses', function () { - const responseBody = { - 'id': 'test-id', - 'cur': 'USD', - 'seatbid': [], - 'nbr': 0 - }; - const bidderRequest = null; - - const bidResponse = spec.interpretResponse({ body: responseBody }, {bidderRequest}); - - expect(bidResponse.length).to.equal(0); - }); - - it('Test the response parsing function', function () { - const responseBody = { - 'id': 'test-id', - 'cur': 'USD', - 'seatbid': [{ - 'bid': [{ - 'id': '5044997188309660254', - 'price': 5, - 'adm': 'test ad', - 'adid': '97517771', - 'crid': '97517771', - 'adomain': ['domain.com'], - 'w': 640, - 'h': 480 - }], - 'seat': 'bidder' - }] - }; - const bidderRequest = { - bidderCode: 'brid', - bidderRequestId: '22edbae2733bf6', - bids: videoRequest - }; - - const bidResponse = spec.interpretResponse({ body: responseBody }, {bidderRequest}); - expect(bidResponse).to.not.be.empty; - - const bid = bidResponse[0]; - expect(bid).to.not.be.empty; - expect(bid.ad).to.equal('test ad'); - expect(bid.cpm).to.equal(5); - expect(bid.width).to.equal(640); - expect(bid.height).to.equal(480); - expect(bid.currency).to.equal('USD'); - }); - - it('Test GDPR and USP consents are present in the request', function () { - const gdprConsentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const uspConsentString = '1YA-'; - const bidderRequest = { - 'bidderCode': 'brid', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'uspConsent': uspConsentString, - 'gdprConsent': { - consentString: gdprConsentString, - gdprApplies: true, - addtlConsent: '1~7.12.35.62.66.70.89.93.108' - } - }; - bidderRequest.bids = videoRequest; - - const request = spec.buildRequests(videoRequest, bidderRequest); - const payload = JSON.parse(request[0].data); - - expect(payload.user.ext.consent).to.equal(gdprConsentString); - expect(payload.regs.ext.us_privacy).to.equal(uspConsentString); - expect(payload.regs.ext.gdpr).to.equal(1); - }); - - it('Test GDPR is not present', function () { - const uspConsentString = '1YA-'; - const bidderRequest = { - 'bidderCode': 'brid', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'uspConsent': uspConsentString - }; - bidderRequest.bids = videoRequest; - - const request = spec.buildRequests(videoRequest, bidderRequest); - const payload = JSON.parse(request[0].data); - - expect(payload.regs.ext.gdpr).to.be.undefined; - expect(payload.regs.ext.us_privacy).to.equal(uspConsentString); - }); - - it('Test userSync have only one object and it should have a property type=iframe', function () { - const userSync = spec.getUserSyncs({ iframeEnabled: true }); - expect(userSync).to.be.an('array'); - expect(userSync.length).to.be.equal(1); - expect(userSync[0]).to.have.property('type'); - expect(userSync[0].type).to.be.equal('iframe'); - }); - - it('Test userSync valid sync url for iframe', function () { - const [userSync] = spec.getUserSyncs({ iframeEnabled: true }, {}, {consentString: 'anyString'}); - expect(userSync.url).to.contain(SYNC_URL + 'load-cookie.html?endpoint=brid&gdpr=0&gdpr_consent=anyString'); - expect(userSync.type).to.be.equal('iframe'); - }); - - it('Test userSyncs iframeEnabled=false', function () { - const userSyncs = spec.getUserSyncs({iframeEnabled: false}); - expect(userSyncs).to.have.lengthOf(0); - }); -}); diff --git a/test/spec/modules/bridgewellBidAdapter_spec.js b/test/spec/modules/bridgewellBidAdapter_spec.js deleted file mode 100644 index 3802d9761..000000000 --- a/test/spec/modules/bridgewellBidAdapter_spec.js +++ /dev/null @@ -1,1344 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/bridgewellBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; - -const userId = { - 'criteoId': 'vYlICF9oREZlTHBGRVdrJTJCUUJnc3U2ckNVaXhrV1JWVUZVSUxzZmJlcnJZR0ZxbVhFRnU5bDAlMkJaUWwxWTlNcmdEeHFrJTJGajBWVlV4T3lFQ0FyRVcxNyUyQlIxa0lLSlFhcWJpTm9PSkdPVkx0JTJCbzlQRTQlM0Q', - 'pubcid': '074864cb-3705-430e-9ff7-48ccf3c21b94', - 'sharedid': {'id': '01F61MX53D786DSB2WYD38ZVM7', 'third': '01F61MX53D786DSB2WYD38ZVM7'}, - 'uid2': {'id': 'eb33b0cb-8d35-1234-b9c0-1a31d4064777'}, -} -const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] -}]; - -describe('bridgewellBidAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - const validTag = { - 'bidder': 'bridgewell', - 'params': { - 'ChannelID': 'CLJgEAYYvxUiBXBlbm55KgkIrAIQ-gEaATk' - }, - }; - expect(spec.isBidRequestValid(validTag)).to.equal(true); - }); - - it('should return true when required params found', function () { - const validTag = { - 'bidder': 'bridgewell', - 'params': { - 'cid': 1234 - }, - }; - expect(spec.isBidRequestValid(validTag)).to.equal(true); - }); - - it('should return false when required params not found', function () { - const invalidTag = { - 'bidder': 'bridgewell', - 'params': {}, - }; - expect(spec.isBidRequestValid(invalidTag)).to.equal(false); - }); - - it('should return false when required params are empty', function () { - const invalidTag = { - 'bidder': 'bridgewell', - 'params': { - 'ChannelID': '', - }, - }; - expect(spec.isBidRequestValid(invalidTag)).to.equal(false); - }); - - it('should return false when required params are empty', function () { - const invalidTag = { - 'bidder': 'bridgewell', - 'params': { - 'cid': '', - }, - }; - expect(spec.isBidRequestValid(invalidTag)).to.equal(false); - }); - - it('should return false when required param cid is not a number', function () { - const invalidTag = { - 'bidder': 'bridgewell', - 'params': { - 'cid': 'bad_cid', - }, - }; - expect(spec.isBidRequestValid(invalidTag)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - 'bidder': 'bridgewell', - 'params': { - 'ChannelID': 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ', - }, - 'adUnitCode': 'adunit-code-2', - 'mediaTypes': { - 'banner': { - 'sizes': [728, 90] - } - }, - 'bidId': '3150ccb55da321', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'userId': userId, - 'userIdAsEids': userIdAsEids, - }, - { - 'bidder': 'bridgewell', - 'params': { - 'ChannelID': 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ', - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [1, 1], - 'mediaTypes': { - 'native': { - 'title': { - 'required': true, - 'len': 15 - }, - 'body': { - 'required': true - }, - 'image': { - 'required': true, - 'sizes': [150, 150] - }, - 'icon': { - 'required': true, - 'sizes': [50, 50] - }, - 'clickUrl': { - 'required': true - }, - 'cta': { - 'required': true - }, - 'sponsoredBy': { - 'required': true - } - } - }, - 'bidId': '3150ccb55da321', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'userId': userId, - 'userIdAsEids': userIdAsEids, - } - ]; - - it('should attach valid params to the tag', function () { - const bidderRequest = { - refererInfo: { - page: 'https://www.bridgewell.com/', - legacy: { - referer: 'https://www.bridgewell.com/', - } - } - } - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - - expect(payload).to.be.an('object'); - expect(payload.adUnits).to.be.an('array'); - expect(payload.url).to.exist.and.to.equal('https://www.bridgewell.com/'); - for (let i = 0, max_i = payload.adUnits.length; i < max_i; i++) { - const u = payload.adUnits[i]; - expect(u).to.have.property('ChannelID').that.is.a('string'); - expect(u).to.not.have.property('cid'); - expect(u).to.have.property('adUnitCode').and.to.equal('adunit-code-2'); - expect(u).to.have.property('requestId').and.to.equal('3150ccb55da321'); - expect(u).to.have.property('userIds'); - expect(u.userIds).to.deep.equal(userId); - expect(u).to.have.property('userIdAsEids'); - expect(u.userIdAsEids).to.deep.equal(userIdAsEids); - } - }); - - it('should attach valid params to the tag, part2', function() { - const bidderRequest = { - refererInfo: { - page: 'https://www.bridgewell.com/', - legacy: { - referer: 'https://www.bridgewell.com/' - } - } - } - const bidRequests2 = [ - { - 'bidder': 'bridgewell', - 'params': { - 'cid': 1234, - }, - 'adUnitCode': 'adunit-code-2', - 'mediaTypes': { - 'banner': { - 'sizes': [728, 90] - } - }, - 'bidId': '3150ccb55da321', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'userId': userId, - 'userIdAsEids': userIdAsEids, - }, - ]; - - const request = spec.buildRequests(bidRequests2, bidderRequest); - const payload = request.data; - - expect(payload).to.be.an('object'); - expect(payload.adUnits).to.be.an('array'); - expect(payload.url).to.exist.and.to.equal('https://www.bridgewell.com/'); - for (let i = 0, max_i = payload.adUnits.length; i < max_i; i++) { - const u = payload.adUnits[i]; - expect(u).to.have.property('cid').that.is.a('number'); - expect(u).to.not.have.property('ChannelID'); - expect(u).to.have.property('adUnitCode').and.to.equal('adunit-code-2'); - expect(u).to.have.property('requestId').and.to.equal('3150ccb55da321'); - expect(u).to.have.property('userIds'); - expect(u.userIds).to.deep.equal(userId); - expect(u).to.have.property('userIdAsEids'); - expect(u.userIdAsEids).to.deep.equal(userIdAsEids); - } - }); - - it('should attach validBidRequests to the tag', function () { - const bidderRequest = { - refererInfo: { - page: 'https://www.bridgewell.com/', - legacy: { - referer: 'https://www.bridgewell.com/', - } - } - } - - const request = spec.buildRequests(bidRequests, bidderRequest); - const validBidRequests = request.validBidRequests; - expect(validBidRequests).to.deep.equal(bidRequests); - }); - }); - - describe('interpretResponse', function () { - const nativeBidRequests = { - validBidRequests: [ - { - 'bidder': 'bridgewell', - 'params': { - 'ChannelID': 'CgUxMjMzOBIBNiIGcGVubnkzKggI2AUQWhoBOQ', - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [1, 1], - 'mediaTypes': { - 'native': { - 'title': { - 'required': true, - 'len': 15 - }, - 'body': { - 'required': true - }, - 'image': { - 'required': true, - 'sizes': [150, 150] - }, - 'icon': { - 'required': true, - 'sizes': [50, 50] - }, - 'clickUrl': { - 'required': true - }, - 'cta': { - 'required': true - }, - 'sponsoredBy': { - 'required': true - } - } - }, - 'bidId': '3150ccb55da321', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }, - ] - }; - - const nativeServerResponses = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'adomain': ['response.com'], - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'https://img.scupio.com/test/test-image.jpg', - 'width': 150, - 'height': 150 - }, - 'title': 'test-title', - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - 'width': 50, - 'height': 50 - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const bannerBidRequests = { - validBidRequests: [ - { - 'mediaTypes': { - 'banner': { - 'sizes': [300, 250] - } - }, - 'bidId': '3150ccb55da321', - }, - ] - }; - - const bannerServerResponses = [ - { - 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', - 'bidder_code': 'bridgewell', - 'cpm': 5.0, - 'width': 300, - 'height': 250, - 'adomain': ['response.com'], - 'mediaType': 'banner', - 'ad': '
test 300x250
', - 'ttl': 360, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - it('should return all required parameters', function () { - const result = spec.interpretResponse({ 'body': nativeServerResponses }, nativeBidRequests); - - expect(result[0].requestId).to.equal('3150ccb55da321'); - expect(result[0].cpm).to.equal(7.0); - expect(result[0].width).to.equal(1); - expect(result[0].height).to.equal(1); - expect(result[0].ttl).to.equal(400); - expect(result[0].creativeId).to.equal('0e4048d3-5c74-4380-a21a-00ba35629f7d'); - expect(result[0].netRevenue).to.equal(true); - expect(result[0].currency).to.equal('NTD'); - expect(result[0].mediaType).to.equal('native'); - expect(result[0].native.image.url).to.equal('https://img.scupio.com/test/test-image.jpg'); - expect(String(result[0].meta.advertiserDomains)).to.equal('response.com'); - }); - - it('should return all required parameters banner', function () { - const result = spec.interpretResponse({ 'body': bannerServerResponses }, bannerBidRequests); - - expect(result[0].requestId).to.equal('3150ccb55da321'); - expect(result[0].cpm).to.equal(5.0); - expect(result[0].width).to.equal(300); - expect(result[0].height).to.equal(250); - expect(result[0].ttl).to.equal(360); - expect(result[0].creativeId).to.equal('e5b10774-32bf-4931-85ee-05095e8cff21'); - expect(result[0].netRevenue).to.equal(true); - expect(result[0].currency).to.equal('NTD'); - expect(result[0].mediaType).to.equal('banner'); - expect(result[0].ad).to.equal('
test 300x250
'); - expect(String(result[0].meta.advertiserDomains)).to.equal('response.com'); - }); - - it('should give up bid if server response is undefined', function () { - let result = spec.interpretResponse({ 'body': undefined }, bannerBidRequests); - - expect(result).to.deep.equal([]); - }); - - it('should give up bid if request sizes is missing', function () { - const request = { - validBidRequests: [ - { - 'mediaTypes': { - 'banner': {} - }, - 'bidId': '3150ccb55da321', - }, - ] - }; - const result = spec.interpretResponse({ 'body': bannerServerResponses }, request); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if response sizes is invalid', function () { - const request = { - validBidRequests: [ - { - 'mediaTypes': { - 'banner': { - 'sizes': [728, 90] - } - }, - 'bidId': '3150ccb55da321', - }, - ] - }; - const result = spec.interpretResponse({ 'body': bannerServerResponses }, request); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if cpm is missing', function () { - const response = [ - { - 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', - 'bidder_code': 'bridgewell', - 'width': 300, - 'height': 250, - 'mediaType': 'banner', - 'ad': '
test 300x250
', - 'ttl': 360, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, bannerBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if width or height is missing', function () { - const response = [ - { - 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', - 'bidder_code': 'bridgewell', - 'cpm': 5.0, - 'mediaType': 'banner', - 'ad': '
test 300x250
', - 'ttl': 360, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, bannerBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if ad is missing', function () { - const response = [ - { - 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', - 'bidder_code': 'bridgewell', - 'cpm': 5.0, - 'width': 300, - 'height': 250, - 'mediaType': 'banner', - 'ttl': 360, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, bannerBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if revenue mode is missing', function () { - const response = [ - { - 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', - 'bidder_code': 'bridgewell', - 'cpm': 5.0, - 'width': 300, - 'height': 250, - 'mediaType': 'banner', - 'ad': '
test 300x250
', - 'ttl': 360, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, bannerBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if currency is missing', function () { - const response = [ - { - 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', - 'bidder_code': 'bridgewell', - 'cpm': 5.0, - 'width': 300, - 'height': 250, - 'mediaType': 'banner', - 'ad': '
test 300x250
', - 'ttl': 360, - 'netRevenue': true, - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, bannerBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if mediaType is missing', function () { - const response = [ - { - 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', - 'bidder_code': 'bridgewell', - 'cpm': 5.0, - 'width': 300, - 'height': 250, - 'ad': '
test 300x250
', - 'ttl': 360, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, bannerBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if mediaType is not support', function () { - const responses = [ - { - 'id': 'e5b10774-32bf-4931-85ee-05095e8cff21', - 'bidder_code': 'bridgewell', - 'cpm': 5.0, - 'width': 300, - 'height': 250, - 'mediaType': 'superNiceAd', - 'ad': '
test 300x250
', - 'ttl': 360, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': responses }, bannerBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if property native of mediaType native is missing', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native title is missing', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'https://img.scupio.com/test/test-image.jpg', - 'width': 150, - 'height': 150 - }, - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - 'width': 50, - 'height': 50 - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native title is too long', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'https://img.scupio.com/test/test-image.jpg', - 'width': 150, - 'height': 150 - }, - 'title': 'test-titletest-title', - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - 'width': 50, - 'height': 50 - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native body is missing', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'https://img.scupio.com/test/test-image.jpg', - 'width': 150, - 'height': 150 - }, - 'title': 'test-title', - 'sponsoredBy': 'test-sponsoredBy', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - 'width': 50, - 'height': 50 - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native image url is missing', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': { - 'width': 150, - 'height': 150 - }, - 'title': 'test-title', - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - 'width': 50, - 'height': 50 - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native image is missing', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'title': 'test-title', - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - 'width': 50, - 'height': 50 - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native image is empty', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': {}, - 'title': 'test-title', - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - 'width': 50, - 'height': 50 - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native image sizes is missing', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'https://img.scupio.com/test/test-image.jpg' - }, - 'title': 'test-title', - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - 'width': 50, - 'height': 50 - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native sponsoredBy is missing', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'https://img.scupio.com/test/test-image.jpg', - 'width': 150, - 'height': 150 - }, - 'title': 'test-title', - 'body': 'test-body', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - 'width': 50, - 'height': 50 - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native icon is missing', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'https://img.scupio.com/test/test-image.jpg', - 'width': 150, - 'height': 150 - }, - 'title': 'test-title', - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native icon url is missing', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'https://img.scupio.com/test/test-image.jpg', - 'width': 150, - 'height': 150 - }, - 'title': 'test-title', - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'icon': { - 'width': 50, - 'height': 50 - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native icon sizes is missing', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'https://img.scupio.com/test/test-image.jpg', - 'width': 150, - 'height': 150 - }, - 'title': 'test-title', - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native clickUrl is missing', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'https://img.scupio.com/test/test-image.jpg', - 'width': 150, - 'height': 150 - }, - 'title': 'test-title', - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - 'width': 50, - 'height': 50 - }, - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native clickTrackers is missing', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'https://img.scupio.com/test/test-image.jpg', - 'width': 150, - 'height': 150 - }, - 'title': 'test-title', - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - 'width': 50, - 'height': 50 - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native clickTrackers is empty', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'https://img.scupio.com/test/test-image.jpg', - 'width': 150, - 'height': 150 - }, - 'title': 'test-title', - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - 'width': 50, - 'height': 50 - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': [], - 'impressionTrackers': ['https://img.scupio.com/test-impressionTracker'] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native impressionTrackers is missing', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'https://img.scupio.com/test/test-image.jpg', - 'width': 150, - 'height': 150 - }, - 'title': 'test-title', - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - 'width': 50, - 'height': 50 - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should give up bid if native impressionTrackers is empty', function () { - const response = [ - { - 'id': '0e4048d3-5c74-4380-a21a-00ba35629f7d', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 1, - 'height': 1, - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'https://img.scupio.com/test/test-image.jpg', - 'width': 150, - 'height': 150 - }, - 'title': 'test-title', - 'sponsoredBy': 'test-sponsoredBy', - 'body': 'test-body', - 'icon': { - 'url': 'https://img.scupio.com/test/test-icon.jpg', - 'width': 50, - 'height': 50 - }, - 'clickUrl': 'https://img.scupio.com/test-clickUrl', - 'clickTrackers': ['https://img.scupio.com/test-clickTracker'], - 'impressionTrackers': [] - }, - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, - ]; - - const result = spec.interpretResponse({ 'body': response }, nativeBidRequests); - expect(result).to.deep.equal([]); - }); - - it('should contain every request bid id in responses', function () { - const request = { - validBidRequests: [ - { - 'mediaTypes': { - 'banner': { - 'sizes': [300, 250] - } - }, - 'bidId': '3150ccb55da321', - }, - { - 'mediaTypes': { - 'banner': { - 'sizes': [300, 250] - } - }, - 'bidId': '3150ccb55da322', - } - ], - }; - const response = [{ - 'id': '0cd250f4-f40e-4a78-90f5-5168eb0a97e9', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 300, - 'height': 250, - 'mediaType': 'banner', - 'ad': '
test 300x250
', - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, { - 'id': '8a740063-6820-45e4-b01f-34ce9b38e858', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 300, - 'height': 250, - 'mediaType': 'banner', - 'ad': '
test 300x250
', - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }]; - const result = spec.interpretResponse({ 'body': response }, request); - const actualBidId = result.map(obj => obj.requestId); - const expectedBidId = ['3150ccb55da321', '3150ccb55da322']; - - expect(actualBidId).to.include(expectedBidId[0]).and.to.include(expectedBidId[1]); - }); - - it('should have 2 consumed responses when two requests with same sizes are given', function () { - const request = { - validBidRequests: [ - { - 'mediaTypes': { - 'banner': { - 'sizes': [300, 250] - } - }, - 'bidId': '3150ccb55da321', - }, - { - 'mediaTypes': { - 'banner': { - 'sizes': [300, 250] - } - }, - 'bidId': '3150ccb55da322', - } - ], - }; - const response = [{ - 'id': '0cd250f4-f40e-4a78-90f5-5168eb0a97e9', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 300, - 'height': 250, - 'mediaType': 'banner', - 'ad': '
test 300x250
', - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, { - 'id': '8a740063-6820-45e4-b01f-34ce9b38e858', - 'bidder_code': 'bridgewell', - 'cpm': 7.0, - 'width': 300, - 'height': 250, - 'mediaType': 'banner', - 'ad': '
test 300x250
', - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }]; - const reducer = function(accumulator, currentValue) { - if (currentValue.consumed) accumulator++; - return accumulator; - }; - - spec.interpretResponse({ 'body': response }, request); - expect(response.reduce(reducer, 0)).to.equal(2); - }); - - it('should use adUnitCode to build bidResponses', function () { - const request = { - validBidRequests: [ - { - 'adUnitCode': 'div-gpt-ad-1564632520056-0', - 'bidId': '3150ccb55da321', - }, - { - 'adUnitCode': 'div-gpt-ad-1564632520056-1', - 'bidId': '3150ccb55da322', - } - ], - }; - const response = [{ - 'id': '0cd250f4-f40e-4a78-90f5-5168eb0a97e9', - 'bidder_code': 'bridgewell', - 'adUnitCode': 'div-gpt-ad-1564632520056-0', - 'cpm': 7.0, - 'width': 300, - 'height': 250, - 'mediaType': 'banner', - 'ad': '
test 300x250
', - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, { - 'id': '8a740063-6820-45e4-b01f-34ce9b38e858', - 'bidder_code': 'bridgewell', - 'adUnitCode': 'div-gpt-ad-1564632520056-1', - 'cpm': 7.0, - 'width': 300, - 'height': 250, - 'mediaType': 'banner', - 'ad': '
test 300x250
', - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }]; - const result = spec.interpretResponse({ 'body': response }, request); - const actualBidId = result.map(obj => obj.requestId); - const expectedBidId = ['3150ccb55da321', '3150ccb55da322']; - - expect(actualBidId).to.include(expectedBidId[0]).and.to.include(expectedBidId[1]); - }); - - it('should use size to match when adUnitCode is empty string in server response', function () { - const request = { - validBidRequests: [ - { - 'mediaTypes': { - 'banner': { - 'sizes': [300, 250] - } - }, - 'adUnitCode': 'div-gpt-ad-1564632520056-0', - 'bidId': '3150ccb55da321', - }, - { - 'mediaTypes': { - 'banner': { - 'sizes': [300, 250] - } - }, - 'adUnitCode': 'div-gpt-ad-1564632520056-1', - 'bidId': '3150ccb55da322', - } - ], - }; - const response = [{ - 'id': '0cd250f4-f40e-4a78-90f5-5168eb0a97e9', - 'bidder_code': 'bridgewell', - 'adUnitCode': '', - 'cpm': 7.0, - 'width': 300, - 'height': 250, - 'mediaType': 'banner', - 'ad': '
test 300x250
', - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }, { - 'id': '8a740063-6820-45e4-b01f-34ce9b38e858', - 'bidder_code': 'bridgewell', - 'adUnitCode': '', - 'cpm': 7.0, - 'width': 300, - 'height': 250, - 'mediaType': 'banner', - 'ad': '
test 300x250
', - 'ttl': 400, - 'netRevenue': true, - 'currency': 'NTD' - }]; - const result = spec.interpretResponse({ 'body': response }, request); - const actualBidId = result.map(obj => obj.requestId); - const expectedBidId = ['3150ccb55da321', '3150ccb55da322']; - - expect(actualBidId).to.include(expectedBidId[0]).and.to.include(expectedBidId[1]); - }); - }); -}); diff --git a/test/spec/modules/browsiAnalyticsAdapter_spec.js b/test/spec/modules/browsiAnalyticsAdapter_spec.js deleted file mode 100644 index 6e7098b4d..000000000 --- a/test/spec/modules/browsiAnalyticsAdapter_spec.js +++ /dev/null @@ -1,321 +0,0 @@ -import browsiAnalytics, { setStaticData, getStaticData } from '../../../modules/browsiAnalyticsAdapter.js'; - -import adapterManager from '../../../src/adapterManager.js'; -import { expect } from 'chai'; -import { EVENTS } from '../../../src/constants.js'; -import { server } from '../../../test/mocks/xhr.js'; -import { getGlobal } from '../../../src/prebidGlobal.js'; -import * as utils from '../../../src/utils.js'; - -const events = require('src/events'); - -describe('browsi analytics adapter', function () { - const timestamp = 1740559971388; - const auctionId = 'abe18da6-cee1-438b-9013-dc5a62c9d4a8'; - - const auctionEnd = { - 'auctionId': auctionId, - 'timestamp': 1740559969178, - 'auctionEnd': 1740559971388, - 'auctionStatus': 'completed', - 'adUnits': [ - { - 'code': 'realtid_mobile-mobil-1_:r1:', - 'sizes': [[300, 250], [320, 100], [320, 160], [320, 320]], - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [320, 100], [320, 160], [320, 320]] - } - }, - 'bids': [ - { - 'bidder': 'bidderA', - 'auctionId': 'abe18da6-cee1-438b-9013-dc5a62c9d4a8', - 'ortb2Imp': { - 'ext': { - 'data': { - 'browsi': { - 'scrollDepth': 0.4, - 'density': 0.6, - 'numberOfAds': 3, - 'lcp': 2.5, - 'cls': 0.08, - 'inp': 150, - 'viewability': 0.66, - 'revenue': 0.44, - 'adLocation': 1220 - } - } - } - }, - }, - { - 'bidder': 'adprofitadform', - 'auctionId': 'abe18da6-cee1-438b-9013-dc5a62c9d4a8', - }, - { - 'bidder': 'bidderB', - 'auctionId': 'abe18da6-cee1-438b-9013-dc5a62c9d4a8', - 'ortb2Imp': { - 'ext': { - 'data': { - 'browsi': { - 'scrollDepth': 0.4, - 'density': 0.6, - 'numberOfAds': 3, - 'lcp': 2.5, - 'cls': 0.08, - 'inp': 150, - 'viewability': 0.66, - 'revenue': 0.44, - 'adLocation': 1220 - } - } - } - }, - }, - ], - 'lwPName': 'realtid_mobile-mobil-1', - 'adUnitId': '974f76d1-02af-4bb9-93d8-6aa8d4f81f30', - 'transactionId': '39fe8024-758e-4dbc-82c8-656cfba1d06b', - 'adserverTargeting': { - 'browsiViewability': [ - '0.60' - ], - 'browsiScroll': [ - '0.40' - ], - 'browsiRevenue': [ - 'medium' - ] - } - }, - { - 'code': 'realtid_mobile-mobil-2_:r2:', - 'sizes': [[300, 250], [320, 100], [320, 160], [320, 320], [320, 400], [320, 480]], - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [320, 100], [320, 160], [320, 320], [320, 400], [320, 480]] - } - }, - 'bids': [ - { - 'bidder': 'bidderA', - 'auctionId': 'abe18da6-cee1-438b-9013-dc5a62c9d4a8', - 'ortb2Imp': { - 'ext': { - 'data': { - 'browsi': { - 'scrollDepth': 0.4, - 'density': 0.6, - 'numberOfAds': 3, - 'lcp': 2.5, - 'cls': 0.08, - 'inp': 150 - } - } - } - }, - }, - { - 'bidder': 'tmapubmatic', - 'auctionId': 'abe18da6-cee1-438b-9013-dc5a62c9d4a8', - }, - { - 'bidder': 'adprofitadform', - 'auctionId': 'abe18da6-cee1-438b-9013-dc5a62c9d4a8', - }, - ], - 'lwPName': 'realtid_mobile-mobil-2', - 'adUnitId': '644e15c8-4ee4-4205-9bf0-72dd22f8a678', - 'transactionId': '2299ea95-cd7e-492d-952f-38a637afff81', - 'adserverTargeting': { - 'browsiScroll': [ - '0.40' - ], - 'browsiRevenue': [ - 'no fill' - ] - } - } - ], - 'adUnitCodes': [ - 'realtid_mobile-mobil-1_:r1:', - 'realtid_mobile-mobil-2_:r2:' - ] - } - const browsiInit = { - 'moduleName': 'browsi', - 't': 1740559969178, - 'pvid': '123456', - 'pk': 'pub_key', - 'sk': 'site_key', - } - const dataSet1 = { - moduleName: 'browsi', - pvid: '123456', - d: 'MOBILE', - g: 'IL', - aid: 'article_123', - es: true, - sk: 'site_key', - pk: 'pub_key', - t: 1740559969178 - } - const dataSet2 = { - moduleName: 'browsi', - pvid: '123456', - d: 'DESKTOP', - g: 'IL', - aid: 'article_321', - es: false, - sk: 'site_key', - pk: 'pub_key', - t: 1740559969178 - } - - let sandbox; - - before(() => { - sandbox = sinon.createSandbox(); - sandbox.stub(utils, 'timestamp').returns(timestamp); - - adapterManager.registerAnalyticsAdapter({ - code: 'browsi', - adapter: browsiAnalytics - }); - }); - after(() => { - sandbox.restore(); - }); - - beforeEach(() => { - sandbox.stub(events, 'getEvents').returns([]); - browsiAnalytics.enableAnalytics({ - provider: 'browsi', - options: {} - }); - browsiAnalytics._staticData = undefined; - }); - afterEach(() => { - events.getEvents.restore(); - browsiAnalytics.disableAnalytics(); - }); - - it('should send auction data', function () { - setStaticData(dataSet1); - - events.emit(EVENTS.AUCTION_END, auctionEnd); - expect(server.requests.length).to.equal(1); - - const request = server.requests[0]; - const { protocol, hostname, pathname, search } = utils.parseUrl(request.url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('events.browsiprod.com'); - expect(pathname).to.equal('/events/v2/rtd_demand'); - expect(search).to.deep.equal({ 'p': '123456' }); - - const body = JSON.parse(request.requestBody); - expect(body.length).to.equal(1); - - const event = body[0]; - expect(event.to).to.equal(timestamp - dataSet1.t); - expect(event.pvid).to.equal(dataSet1.pvid); - expect(event.pk).to.equal(dataSet1.pk); - expect(event.sk).to.equal(dataSet1.sk); - expect(event.geo).to.equal(dataSet1.g); - expect(event.dp).to.equal(dataSet1.d); - expect(event.aid).to.equal(dataSet1.aid); - expect(event.pbv).to.equal(getGlobal().version); - expect(event.url).to.equal(encodeURIComponent(window.location.href)); - expect(event.et).to.equal('auction_data_sent'); - expect(event.aucid).to.equal(auctionId); - expect(event.ad_units).to.have.length(2); - - expect(event.ad_units[0].plid).to.equal('realtid_mobile-mobil-1_:r1:'); - expect(event.ad_units[0].au).to.be.null; - expect(event.ad_units[0].pbd).to.deep.equal(['bidderA', 'bidderB']); - expect(event.ad_units[0].dpc).to.equal(9); - expect(event.ad_units[0].rtm).to.deep.equal({ - 'scrollDepth': 0.4, - 'density': 0.6, - 'numberOfAds': 3, - 'lcp': 2.5, - 'cls': 0.08, - 'inp': 150, - 'viewability': 0.66, - 'revenue': 0.44, - 'adLocation': 1220 - }); - expect(event.ad_units[1].plid).to.equal('realtid_mobile-mobil-2_:r2:'); - expect(event.ad_units[1].au).to.be.null; - expect(event.ad_units[1].pbd).to.deep.equal(['bidderA']); - expect(event.ad_units[1].dpc).to.equal(6); - expect(event.ad_units[1].rtm).to.deep.equal({ - 'scrollDepth': 0.4, - 'density': 0.6, - 'numberOfAds': 3, - 'lcp': 2.5, - 'cls': 0.08, - 'inp': 150 - }); - }); - it('should send auction data without rtm data', function () { - setStaticData(dataSet2); - - events.emit(EVENTS.AUCTION_END, auctionEnd); - expect(server.requests.length).to.equal(1); - - const request = server.requests[0]; - const body = JSON.parse(request.requestBody); - expect(body.length).to.equal(1); - - const event = body[0]; - expect(event.ad_units[0].rtm).to.not.exist; - expect(event.ad_units[1].rtm).to.not.exist; - }); - it('should send rtd init event', function () { - events.emit(EVENTS.BROWSI_INIT, browsiInit); - expect(server.requests.length).to.equal(1); - - const request = server.requests[0]; - const { protocol, hostname, pathname, search } = utils.parseUrl(request.url); - expect(protocol).to.equal('https'); - expect(hostname).to.equal('events.browsiprod.com'); - expect(pathname).to.equal('/events/v2/rtd_supply'); - expect(search).to.deep.equal({ 'p': '123456' }); - - const body = JSON.parse(request.requestBody); - expect(body.length).to.equal(1); - - const event = body[0]; - expect(event.et).to.equal('rtd_init'); - expect(event.to).to.equal(timestamp - dataSet1.t); - expect(event.pvid).to.equal(dataSet1.pvid); - expect(event.pk).to.equal(dataSet1.pk); - expect(event.sk).to.equal(dataSet1.sk); - expect(event.pbv).to.equal(getGlobal().version); - expect(event.url).to.equal(encodeURIComponent(window.location.href)); - }); - it('should not send rtd init event if module name is not browsi', function () { - events.emit(EVENTS.BROWSI_INIT, { moduleName: 'not_browsi' }); - expect(server.requests.length).to.equal(0); - }); - it('should not set static data if module name is not browsi', function () { - events.emit(EVENTS.BROWSI_DATA, { moduleName: 'not_browsi' }); - expect(browsiAnalytics._staticData).to.equal(undefined); - }); - it('should set static data', function () { - events.emit(EVENTS.BROWSI_DATA, dataSet2); - expect(getStaticData()).to.deep.equal({ - pvid: '123456', - device: 'DESKTOP', - geo: 'IL', - aid: 'article_321', - es: false, - sk: 'site_key', - pk: 'pub_key', - t: 1740559969178 - }); - }); -}); diff --git a/test/spec/modules/browsiBidAdapter_spec.js b/test/spec/modules/browsiBidAdapter_spec.js deleted file mode 100644 index a4f1778af..000000000 --- a/test/spec/modules/browsiBidAdapter_spec.js +++ /dev/null @@ -1,218 +0,0 @@ -import {ENDPOINT, spec} from 'modules/browsiBidAdapter.js'; -import {config} from 'src/config.js'; -import {VIDEO, BANNER} from 'src/mediaTypes.js'; - -const {expect} = require('chai'); -const DATA = 'brwvidtag'; -const ADAPTER = '__bad'; - -describe('browsi Bid Adapter Test', function () { - describe('isBidRequestValid', function () { - let mediaTypes; - let bid; - beforeEach(function () { - mediaTypes = {}; - mediaTypes[VIDEO] = {}; - bid = { - 'params': { - 'pubId': '1234567', - 'tagId': '1' - }, - 'mediaTypes': mediaTypes - }; - }); - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should return false when missing pubId', function () { - delete bid.params.pubId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false when missing tagId', function () { - delete bid.params.tagId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false when missing params', function () { - delete bid.params; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false when params have invalid type', function () { - bid.params.tagId = 1; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false when video mediaType is missing', function () { - delete bid.mediaTypes[VIDEO]; - bid.mediaTypes[BANNER] = {} - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - let bidRequest; - let bidderRequest; - beforeEach(function () { - window[DATA] = {} - window[DATA][ADAPTER] = {index: 0}; - bidRequest = [ - { - 'params': { - 'pubId': 'browiPubId1', - 'tagId': '2' - }, - 'adUnitCode': 'adUnitCode1', - 'auctionId': 'auctionId1', - 'sizes': [640, 480], - 'bidId': '12345678', - 'requestId': '1234567-3456-4562-7689-98765434A', - ortb2Imp: { - ext: { - tid: '1234567-3456-4562-7689-98765434B', - } - }, - 'ortb2': { - 'source': { - 'ext': { - 'schain': {} - } - } - }, - 'mediaTypes': {video: {playerSize: [640, 480]}} - } - ]; - bidderRequest = { - 'bidderRequestId': 'bidderRequestId1', - 'refererInfo': { - 'canonicalUrl': null, - 'page': 'https://browsi.com', - 'domain': 'browsi.com', - 'ref': null, - 'numIframes': 0, - 'reachedTop': true, - 'isAmp': false, - 'stack': ['https://browsi.com'] - }, - 'gdprConsent': { - consentString: 'BOtmiBKOtmiBKABABAENAFAAAAACeAAA', - gdprApplies: true - }, - 'uspConsent': '1YYY' - }; - }); - afterEach(function() { - window[DATA] = undefined; - config.resetConfig(); - }); - it('should return an array of requests with single request', function () { - const requests = spec.buildRequests(bidRequest, bidderRequest); - expect(requests.length).to.equal(1); - const request = requests[0]; - const inputRequest = bidRequest[0]; - const requestToExpect = { - method: 'POST', - url: ENDPOINT, - data: { - requestId: bidderRequest.bidderRequestId, - bidId: inputRequest.bidId, - timeout: 3000, - baData: window[DATA][ADAPTER], - referer: bidderRequest.refererInfo.page, - gdpr: bidderRequest.gdprConsent, - ccpa: bidderRequest.uspConsent, - sizes: inputRequest.sizes, - video: {playerSize: [640, 480]}, - aUCode: inputRequest.adUnitCode, - aID: inputRequest.auctionId, - tID: inputRequest.ortb2Imp.ext.tid, - schain: inputRequest.ortb2?.source?.ext?.schain, - params: inputRequest.params - } - } - assert.deepEqual(request, requestToExpect); - }); - it('should pass on timeout in bidderRequest', function() { - bidderRequest.timeout = 8000; - const requests = spec.buildRequests(bidRequest, bidderRequest); - expect(requests[0].data.timeout).to.equal(8000); - }); - it('should pass timeout in config', function() { - config.setConfig({'bidderTimeout': 6000}); - const requests = spec.buildRequests(bidRequest, bidderRequest); - expect(requests[0].data.timeout).to.equal(6000); - }); - }); - - describe('interpretResponse', function () { - const bidRequest = { - 'url': ENDPOINT, - 'data': { - 'bidId': 'bidId1', - } - }; - const serverResponse = {}; - serverResponse.body = { - bidId: 'bidId1', - w: 300, - h: 250, - vXml: 'vastXml', - vUrl: 'vastUrl', - cpm: 1, - cur: 'USD', - ttl: 10000, - someExtraParams: 8, - } - - it('should return a valid response', function () { - const bidResponses = spec.interpretResponse(serverResponse, bidRequest); - expect(bidResponses.length).to.equal(1); - const actualBidResponse = bidResponses[0]; - const expectedBidResponse = { - requestId: bidRequest.data.bidId, - bidId: 'bidId1', - width: 300, - height: 250, - vastXml: 'vastXml', - vastUrl: 'vastUrl', - cpm: 1, - currency: 'USD', - ttl: 10000, - someExtraParams: 8, - mediaType: VIDEO - }; - - assert.deepEqual(actualBidResponse, expectedBidResponse); - }); - }); - - describe('getUserSyncs', function () { - const bidResponse = { - userSyncs: [ - {url: 'syncUrl1', type: 'image'}, - {url: 'http://syncUrl2', type: 'iframe'} - ] - } - const serverResponse = [ - {body: bidResponse} - ]; - it('should return iframe type userSync', function () { - const userSyncs = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: false}, serverResponse[0]); - expect(userSyncs.length).to.equal(1); - const userSync = userSyncs[0]; - expect(userSync.url).to.equal('http://syncUrl2'); - expect(userSync.type).to.equal('iframe'); - }); - it('should return image type userSyncs', function () { - const userSyncs = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, serverResponse[0]); - const userSync = userSyncs[0]; - expect(userSync.url).to.equal('http://syncUrl1'); - expect(userSync.type).to.equal('image'); - }); - it('should handle multiple server responses', function () { - const userSyncs = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, serverResponse); - expect(userSyncs.length).to.equal(1); - }); - it('should return empty userSyncs', function () { - const userSyncs = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: false}, serverResponse); - expect(userSyncs.length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/browsiRtdProvider_spec.js b/test/spec/modules/browsiRtdProvider_spec.js deleted file mode 100644 index 202732202..000000000 --- a/test/spec/modules/browsiRtdProvider_spec.js +++ /dev/null @@ -1,522 +0,0 @@ -import * as browsiRTD from '../../../modules/browsiRtdProvider.js'; -import * as browsiUtils from '../../../libraries/browsiUtils/browsiUtils.js'; -import * as utils from '../../../src/utils.js' -import * as events from '../../../src/events.js'; -import * as sinon from 'sinon'; -import * as mockGpt from 'test/spec/integration/faker/googletag.js'; -import * as Global from '../../../src/prebidGlobal.js'; - -describe('browsi Real time data sub module', function () { - const conf = { - 'auctionDelay': 250, - dataProviders: [{ - 'name': 'browsi', - 'params': { - 'url': 'testUrl.com', - 'siteKey': 'testKey', - 'pubKey': 'testPub', - 'keyName': 'bv' - } - }] - }; - const auction = { - adUnits: [ - { - code: 'adMock', - transactionId: 1 - }, - { - code: 'hasPrediction', - transactionId: 1 - } - ] - }; - const msPerDay = 24 * 60 * 60 * 1000; - - let sandbox; - let eventsEmitSpy; - let timestampStub; - - before(() => { - sandbox = sinon.createSandbox(); - eventsEmitSpy = sandbox.spy(events, ['emit']); - timestampStub = sandbox.stub(utils, 'timestamp'); - sandbox.stub(Global, 'getGlobal').callsFake(() => { - return { - enableAnalytics: () => { }, - } - }); - }); - - after(() => { - sandbox.restore(); - }); - - it('should init and return true', function () { - browsiRTD.collectData(); - expect(browsiRTD.browsiSubmodule.init(conf.dataProviders[0])).to.equal(true) - }); - - it('should create browsi script', function () { - const script = browsiRTD.addBrowsiTag('scriptUrl.com'); - expect(script.getAttribute('data-sitekey')).to.equal('testKey'); - expect(script.getAttribute('data-pubkey')).to.equal('testPub'); - expect(script.async).to.equal(true); - expect(script.prebidData.kn).to.equal(conf.dataProviders[0].params.keyName); - }); - - it('should return correct macro values', function () { - const slot = mockGpt.makeSlot({ code: '/123/abc', divId: 'browsiAd_1' }); - - slot.setTargeting('test', ['test', 'value']); - // slot getTargeting doesn't act like GPT so we can't expect real value - const macroResult = browsiUtils.getMacroId({ p: '/' }, slot); - expect(macroResult).to.equal('/123/abc/NA'); - - const macroResultB = browsiUtils.getMacroId({}, slot); - expect(macroResultB).to.equal('browsiAd_1'); - - const macroResultC = browsiUtils.getMacroId({ p: '', s: { s: 0, e: 1 } }, slot); - expect(macroResultC).to.equal('/'); - }); - - describe('should return data to RTD module', function () { - it('should return empty if no ad units defined', function () { - browsiRTD.setBrowsiData({}); - expect(browsiRTD.browsiSubmodule.getTargetingData([], null, null, auction)).to.eql({}); - }); - it('should return empty if GAM is not defined', function () { - mockGpt.makeSlot({ code: 'slot1', divId: 'slot1' }); - const data = { - plc: { 'slot1': { viewability: { 0: 0.234 } } }, - pmd: undefined, - sg: false - }; - browsiRTD.setBrowsiData(data); - expect(browsiRTD.browsiSubmodule.getTargetingData(['slotId'], null, null, auction)).to.eql({}); - }); - it('should return empty if viewability key is not defined', function () { - mockGpt.makeSlot({ code: 'slot2', divId: 'slot2' }); - const data = { - plc: { 'slot2': { someKey: { 0: 0.234 } } }, - pmd: undefined, - sg: true - }; - browsiRTD.setBrowsiData(data); - expect(browsiRTD.browsiSubmodule.getTargetingData(['slot2'], null, null, auction)).to.eql({ 'slot2': {} }); - }); - it('should return all predictions from server', function () { - mockGpt.makeSlot({ code: 'slot3', divId: 'slot3' }); - const data = { - pg: { scrollDepth: 0.456 }, - plc: { 'slot3': { viewability: { 0: 0.234 }, revenue: { 0: 0.567 } } }, - pmd: undefined, - sg: true - }; - browsiRTD.setBrowsiData(data); - expect(browsiRTD.browsiSubmodule.getTargetingData(['slot3'], null, null, auction)).to.eql({ - 'slot3': { bv: '0.20', browsiRevenue: 'medium', browsiScroll: '0.40' } - }); - }); - it('should return the available prediction', function () { - mockGpt.makeSlot({ code: 'slot4', divId: 'slot4' }); - const data = { - pg: { scrollDepth: 0.456 }, - plc: { 'slot4': { someKey: { 0: 0.234 } } }, - pmd: undefined, - sg: true - }; - browsiRTD.setBrowsiData(data); - expect(browsiRTD.browsiSubmodule.getTargetingData(['slot4'], null, null, auction)).to.eql({ 'slot4': { browsiScroll: '0.40' } }); - }); - }) - - describe('should return matching prediction', function () { - const predictions = { - 0: 0.123, - 1: 0.254, - 3: 0, - 4: 0.8 - } - const singlePrediction = { - 0: 0.123 - } - const numbericPrediction = 0.456; - it('should return raw value if valid', function () { - expect(browsiRTD.getCurrentData(predictions, 0)).to.equal(0.123); - expect(browsiRTD.getCurrentData(predictions, 1)).to.equal(0.254); - }) - it('should return 0 for prediction = 0', function () { - expect(browsiRTD.getCurrentData(predictions, 3)).to.equal(0); - }) - it('should return -1 for invalid params', function () { - expect(browsiRTD.getCurrentData(null, 3)).to.equal(-1); - expect(browsiRTD.getCurrentData(predictions, null)).to.equal(-1); - }) - it('should return prediction according to object keys length ', function () { - expect(browsiRTD.getCurrentData(singlePrediction, 0)).to.equal(0.123); - expect(browsiRTD.getCurrentData(singlePrediction, 1)).to.equal(-1); - expect(browsiRTD.getCurrentData(singlePrediction, 2)).to.equal(-1); - expect(browsiRTD.getCurrentData(predictions, 4)).to.equal(0.8); - expect(browsiRTD.getCurrentData(predictions, 5)).to.equal(0.8); - expect(browsiRTD.getCurrentData(predictions, 8)).to.equal(0.8); - }) - it('should return prediction if it is a number', function () { - expect(browsiRTD.getCurrentData(numbericPrediction, 0)).to.equal(0.456); - }) - }) - - describe('should handle bid request data', function () { - const data = { - plc: { - 'adUnit1': { keyA: { 0: 0.234 } }, - 'adUnit2': { keyB: { 0: 0.134 } } - }, - pr: ['bidder1'], - pmd: undefined - } - const fakeAdUnits = [ - { - code: 'adUnit1', - bids: [ - { bidder: 'bidder1' }, - { bidder: 'bidder2' } - ] - }, - { - code: 'adUnit2', - bids: [ - { bidder: 'bidder1' }, - { bidder: 'bidder2' } - ] - } - ] - before(async () => { - browsiRTD.setBrowsiData(data); - browsiRTD.browsiSubmodule.getBidRequestData({ adUnits: fakeAdUnits }, () => { }, {}, null); - }); - it('should set bidder params with prediction values', function () { - expect(utils.deepAccess(fakeAdUnits[0].bids[0], 'ortb2Imp.ext.data.browsi')).to.eql({ keyA: 0.234 }); - expect(utils.deepAccess(fakeAdUnits[1].bids[0], 'ortb2Imp.ext.data.browsi')).to.eql({ keyB: 0.134 }); - }) - it('should not set bidder params if bidder is not in pr', function () { - expect(utils.deepAccess(fakeAdUnits[0].bids[1], 'ortb2Imp.ext.data.browsi')).to.eql(undefined); - expect(utils.deepAccess(fakeAdUnits[1].bids[1], 'ortb2Imp.ext.data.browsi')).to.eql(undefined); - }) - }) - - describe('should not set bid request data', function () { - const data = { - plc: { - 'adUnit1': { keyA: { 0: 0.234 } }, - 'adUnit2': { keyB: { 0: 0.134 } } - }, - pr: [], - pmd: undefined - } - const fakeAdUnits = [ - { - code: 'adUnit1', - bids: [ - { bidder: 'bidder1' }, - { bidder: 'bidder2' } - ] - }, - { - code: 'adUnit2', - bids: [ - { bidder: 'bidder1' }, - { bidder: 'bidder2' } - ] - } - ] - before(() => { - browsiRTD.setBrowsiData(data); - browsiRTD.browsiSubmodule.getBidRequestData({ adUnits: fakeAdUnits }, () => { }, {}, null); - }); - it('should not set bidder params if pr is empty', function () { - expect(utils.deepAccess(fakeAdUnits[0].bids[0], 'ortb2Imp.ext.data.browsi')).to.eql(undefined); - expect(utils.deepAccess(fakeAdUnits[1].bids[0], 'ortb2Imp.ext.data.browsi')).to.eql(undefined); - expect(utils.deepAccess(fakeAdUnits[0].bids[1], 'ortb2Imp.ext.data.browsi')).to.eql(undefined); - expect(utils.deepAccess(fakeAdUnits[1].bids[1], 'ortb2Imp.ext.data.browsi')).to.eql(undefined); - }) - }) - - describe('should emit ad request billable event', function () { - before(() => { - const data = { - p: { - 'adUnit1': { ps: { 0: 0.234 } }, - 'adUnit2': { ps: { 0: 0.134 } } - }, - pmd: undefined, - bet: 'AD_REQUEST' - }; - browsiRTD.setBrowsiData(data); - }) - beforeEach(() => { - eventsEmitSpy.resetHistory(); - }) - it('should send one event per ad unit code', function () { - const auction = { - adUnits: [ - { - code: 'a', - transactionId: 1 - }, - { - code: 'b', - transactionId: 2 - }, - { - code: 'a', - transactionId: 3 - }, - ] - }; - - browsiRTD.browsiSubmodule.getTargetingData(['a', 'b'], null, null, auction); - expect(eventsEmitSpy.callCount).to.equal(2); - }) - it('should send events only for received ad unit codes', function () { - const auction = { - adUnits: [ - { - code: 'a', - transactionId: 1 - }, - { - code: 'b', - transactionId: 2 - }, - { - code: 'c', - transactionId: 3 - }, - ] - }; - - browsiRTD.browsiSubmodule.getTargetingData(['a'], null, null, auction); - expect(eventsEmitSpy.callCount).to.equal(1); - browsiRTD.browsiSubmodule.getTargetingData(['b'], null, null, auction); - expect(eventsEmitSpy.callCount).to.equal(2); - }) - it('should use 1st transaction ID in case of twin ad unit codes', function () { - const auction = { - auctionId: '123', - adUnits: [ - { - code: 'a', - transactionId: 1 - }, - { - code: 'a', - transactionId: 3 - }, - ] - }; - - const expectedCall = { - vendor: 'browsi', - type: 'adRequest', - transactionId: 1, - auctionId: '123' - } - - browsiRTD.browsiSubmodule.getTargetingData(['a'], null, null, auction); - const callArguments = eventsEmitSpy.getCalls()[0].args[1]; - // billing id is random, we can't check its value - delete callArguments['billingId']; - expect(callArguments).to.eql(expectedCall); - }) - }) - - describe('should emit pageveiw billable event', function () { - beforeEach(() => { - eventsEmitSpy.resetHistory(); - }) - it('should send event if type is correct', function () { - browsiRTD.sendPageviewEvent('PAGEVIEW') - const pageViewEvent = new CustomEvent('browsi_pageview', {}); - window.dispatchEvent(pageViewEvent); - const expectedCall = { - vendor: 'browsi', - type: 'pageview', - } - - expect(eventsEmitSpy.callCount).to.equal(1); - const callArguments = eventsEmitSpy.getCalls()[0].args[1]; - // billing id is random, we can't check its value - delete callArguments['billingId']; - expect(callArguments).to.eql(expectedCall); - }) - it('should not send event if type is incorrect', function () { - browsiRTD.sendPageviewEvent('AD_REQUEST'); - browsiRTD.sendPageviewEvent('INACTIVE'); - browsiRTD.sendPageviewEvent(undefined); - expect(eventsEmitSpy.callCount).to.equal(0); - }) - }) - - describe('set targeting - invalid params', function () { - const random = Math.floor(Math.random() * 10) + 1; - it('should return false if key is undefined', function () { - expect(browsiUtils.setKeyValue(undefined, random)).to.equal(false); - }) - it('should return false if key is not string', function () { - expect(browsiUtils.setKeyValue(1, random)).to.equal(false); - }) - }) - - describe('set targeting - valid params', function () { - let slot; - const splitKey = 'splitTest'; - const random = Math.floor(Math.random() * 10) + 1; - before(() => { - mockGpt.reset(); - window.googletag.pubads().clearTargeting(); - slot = mockGpt.makeSlot({ code: '/123/split', divId: 'split' }); - browsiUtils.setKeyValue(splitKey, random); - window.googletag.cmd.forEach(cmd => cmd()); - }) - it('should place numeric key value on all slots', function () { - const targetingValue = window.googletag.pubads().getTargeting(splitKey); - expect(targetingValue).to.be.an('array').that.is.not.empty; - expect(targetingValue[0]).to.be.a('string'); - }) - }) - - describe('should get latest avg highest bid', function () { - it('should return lahb', function () { - const currentTimestemp = new Date().getTime(); - const storageTimestemp = currentTimestemp - (msPerDay); - - const diffInMilliseconds = Math.abs(storageTimestemp - currentTimestemp); - const diffInDays = diffInMilliseconds / msPerDay; - - const lahb = { - avg: 0.02, - smp: 3, - time: storageTimestemp - }; - - timestampStub.returns(currentTimestemp); - - expect(browsiUtils.getLahb(lahb, currentTimestemp)).to.deep.equal({ avg: 0.02, age: diffInDays }); - }); - }) - - describe('should get recent avg highest bid', function () { - it('should return rahb', function () { - const currentTimestemp = new Date().getTime(); - const oneDayAgoTimestemp = currentTimestemp - (msPerDay); - const twoDayAgoTimestemp = currentTimestemp - (2 * msPerDay); - const rahb = { - [currentTimestemp]: { 'sum': 20, 'smp': 8 }, - [oneDayAgoTimestemp]: { 'sum': 25, 'smp': 10 }, - [twoDayAgoTimestemp]: { 'sum': 30, 'smp': 12 } - }; - expect(browsiUtils.getRahb(rahb, currentTimestemp)).to.deep.equal({ avg: 2.5 }); - }); - it('should return rahb without timestamps older than a week', function () { - const currentTimestemp = new Date().getTime(); - const oneDayAgoTimestemp = currentTimestemp - (msPerDay); - const twoDayAgoTimestemp = currentTimestemp - (2 * msPerDay); - const twoWeekAgoTimestemp = currentTimestemp - (14 * msPerDay); - const rahb = { - [currentTimestemp]: { 'sum': 20, 'smp': 8 }, - [oneDayAgoTimestemp]: { 'sum': 25, 'smp': 10 }, - [twoDayAgoTimestemp]: { 'sum': 30, 'smp': 12 }, - [twoWeekAgoTimestemp]: { 'sum': 35, 'smp': 20 } - }; - const expected = { - [currentTimestemp]: { 'sum': 20, 'smp': 8 }, - [oneDayAgoTimestemp]: { 'sum': 25, 'smp': 10 }, - [twoDayAgoTimestemp]: { 'sum': 30, 'smp': 12 }, - }; - expect(browsiUtils.getRahbByTs(rahb, currentTimestemp)).to.deep.equal(expected); - }); - it('should return an empty object if all timestamps are older than a week', function () { - const currentTimestemp = new Date().getTime(); - const eightDaysAgoTimestemp = currentTimestemp - (8 * msPerDay); - const twoWeekAgoTimestemp = currentTimestemp - (14 * msPerDay); - const rahb = { - [eightDaysAgoTimestemp]: { 'sum': 20, 'smp': 8 }, - [twoWeekAgoTimestemp]: { 'sum': 25, 'smp': 10 } - }; - expect(browsiUtils.getRahbByTs(rahb, currentTimestemp)).to.deep.equal({}); - }); - }) - - describe('should get avg highest bid metrics', function () { - const currentTimestemp = new Date().getTime(); - const oneDayAgoTimestemp = currentTimestemp - (msPerDay); - const twoWeekAgoTimestemp = currentTimestemp - (14 * msPerDay); - - const uahb = { avg: 0.2991556234740213, smp: 28 }; - const lahb = { avg: 0.02, smp: 3, time: oneDayAgoTimestemp }; - const rahb = { [currentTimestemp]: { sum: 20, smp: 8 }, [oneDayAgoTimestemp]: { sum: 25, smp: 10 }, }; - - const getExpected = function (bus) { - return { - uahb: +bus.uahb?.avg.toFixed(3), - rahb: +(2.5).toFixed(3), - lahb: +bus.lahb?.avg.toFixed(3), - lbsa: +(1).toFixed(3), - } - } - - before(() => { - timestampStub.returns(currentTimestemp); - browsiRTD.setTimestamp(); - }); - it('should return undefined if bus is not defined', function () { - expect(browsiUtils.getHbm(undefined)).to.equal(undefined); - }); - it('should return metrics if bus is defined', function () { - const bus = { uahb, lahb, rahb }; - expect(browsiUtils.getHbm(bus, currentTimestemp)).to.deep.equal({ - uahb: getExpected(bus).uahb, - rahb: getExpected(bus).rahb, - lahb: getExpected(bus).lahb, - lbsa: getExpected(bus).lbsa - }); - }); - it('should return metrics without lahb if its not defined', function () { - const bus = { uahb, rahb }; - expect(browsiUtils.getHbm(bus, currentTimestemp)).to.deep.equal({ - uahb: getExpected(bus).uahb, - rahb: getExpected(bus).rahb, - lahb: undefined, - lbsa: undefined - }); - }); - it('should return metrics without rahb if its not defined', function () { - const bus = { uahb, lahb }; - expect(browsiUtils.getHbm(bus, currentTimestemp)).to.deep.equal({ - uahb: getExpected(bus).uahb, - rahb: undefined, - lahb: getExpected(bus).lahb, - lbsa: getExpected(bus).lbsa - }); - }); - it('should return metrics without uahb if its not defined', function () { - const bus = { lahb, rahb }; - expect(browsiUtils.getHbm(bus, currentTimestemp)).to.deep.equal({ - uahb: undefined, - rahb: getExpected(bus).rahb, - lahb: getExpected(bus).lahb, - lbsa: getExpected(bus).lbsa - }); - }); - it('should return metrics without rahb if timestamps are older than a week', function () { - const bus = { uahb, lahb, rahb: { [twoWeekAgoTimestemp]: { sum: 25, smp: 10 } } }; - expect(browsiUtils.getHbm(bus, currentTimestemp)).to.deep.equal({ - uahb: getExpected(bus).uahb, - rahb: undefined, - lahb: getExpected(bus).lahb, - lbsa: getExpected(bus).lbsa - }); - }); - }) -}); diff --git a/test/spec/modules/bucksenseBidAdapter_spec.js b/test/spec/modules/bucksenseBidAdapter_spec.js deleted file mode 100644 index 533dc2f01..000000000 --- a/test/spec/modules/bucksenseBidAdapter_spec.js +++ /dev/null @@ -1,145 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/bucksenseBidAdapter.js'; - -describe('Bucksense Adapter', function() { - const BIDDER_CODE = 'bucksense'; - const BID_ID = '12345'; - const PLACE_ID = '1000'; - - function getValidBidObject() { - return { - bidder: BIDDER_CODE, - params: { - placementId: PLACE_ID, - } - } - }; - - describe('isBidRequestValid', function() { - var bid; - - beforeEach(function() { - bid = getValidBidObject(); - }); - - it('returns true when valid bid request is sent', function() { - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - - it('returns true when valid test bid request is sent', function() { - bid.params['test'] = 1; - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - - it('returns false when params not set', function() { - delete bid.params; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - }); - - describe('buildRequests', function() { - var bid, bidRequestObj; - - beforeEach(function() { - bid = getValidBidObject(); - bidRequestObj = { - 'bidderCode': 'bucksense', - 'auctionId': '73540558-86cb-4eef-895f-bf99c5353bd7', - 'bidderRequestId': '1feebcb5938c7e', - 'bids': [ - { - 'bidder': 'bucksense', - 'params': { - 'placementId': 1000 - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ [ 300, 250 ], [ 300, 600 ] ] - } - }, - 'adUnitCode': 'test-div', - 'transactionId': '52b3ed07-2a09-4f58-a426-75acc7602c96', - 'sizes': [ [ 300, 250 ], [ 300, 600 ] ], - 'bidId': '22aecdacdcd773', - 'bidderRequestId': '1feebcb5938c7e', - 'auctionId': '73540558-86cb-4eef-895f-bf99c5353bd7', - 'src': 'client', - 'bidRequestsCount': 1 - } - ], - 'auctionStart': 1557176022728, - 'timeout': 1000, - 'refererInfo': { - 'referer': 'https://stefanod.hera.pe/prebid/?pbjs_debug=true', - 'reachedTop': true, - 'numIframes': 0, - 'stack': [ - 'https://stefanod.hera.pe/prebid/?pbjs_debug=true' - ] - }, - 'start': 1557176022731 - }; - }); - - it('should build a very basic request', function() { - var request = spec.buildRequests([bid], bidRequestObj); - expect(request[0].method).to.equal('POST'); - }); - - it('bidRequest data', function () { - var request = spec.buildRequests([bid], bidRequestObj); - expect(request[0].data).to.exist; - }); - }); - - describe('interpretResponse', function() { - var serverResponse; - var serverRequest; - - beforeEach(function() { - serverRequest = { - 'method': 'POST', - 'url': 'https://prebid.bksn.se/prebidjs/', - 'data': { - 'pub_id': 'prebid.org', - 'pl_id': '1000', - 'secure': 0, - 'href': 'https://prebid.org/developers.html', - 'bid_id': '27aaf8e96d9fd5', - 'params': { - 'placementId': '1000' - }, - 'sizes': [ [ 300, 250 ], [ 300, 600 ] ] - } - }; - - serverResponse = { - body: { - 'requestId': '', - 'cpm': 0.3, - 'width': 300, - 'height': 250, - 'ttl': 360, - 'creativeId': 'creative002', - 'currency': 'USD', - 'netRevenue': false, - 'ad': '
', - 'meta': { - 'advertiserDomains': ['http://www.bucksense.com/'] - } - } - }; - }); - - it('should return an array of bid responses', function() { - var responses = spec.interpretResponse(serverResponse, serverRequest); - expect(responses).to.be.an('array').with.length(1); - }); - - it('should return an array of bid responses', function() { - serverResponse = {}; - var responses = spec.interpretResponse(serverResponse, serverRequest); - expect(responses).to.be.an('array').with.length(0); - }); - }); -}); diff --git a/test/spec/modules/buzzoolaBidAdapter_spec.js b/test/spec/modules/buzzoolaBidAdapter_spec.js deleted file mode 100644 index 5bb60cd12..000000000 --- a/test/spec/modules/buzzoolaBidAdapter_spec.js +++ /dev/null @@ -1,413 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/buzzoolaBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import '../../../src/prebid.js'; -import {executeRenderer, Renderer} from '../../../src/Renderer.js'; -import {deepClone} from '../../../src/utils.js'; - -const ENDPOINT = 'https://exchange.buzzoola.com/ssp/prebidjs'; -const RENDERER_SRC = 'https://tube.buzzoola.com/new/build/buzzlibrary.js'; - -const INVALID_BIDS = [{ - 'bidder': 'buzzoola', - 'mediaTypes': {'banner': {'sizes': [[240, 400], [300, 600]]}}, - 'sizes': [[240, 400], [300, 600]] -}, { - 'bidder': 'buzzoola', - 'params': {'placementId': 417846}, - 'sizes': [[240, 400], [300, 600]] -}, { - 'bidder': 'buzzoola', - 'mediaTypes': { - 'video': { - 'playerSize': [[640, 380]], - 'mimes': ['video/mp4'], - 'minduration': 1, - 'maxduration': 2 - } - } -}, { - 'bidder': 'buzzoola', - 'params': {'placementId': 417845} -}]; - -const BANNER_BID = { - 'bidder': 'buzzoola', - 'params': {'placementId': 417846}, - 'mediaTypes': {'banner': {'sizes': [[240, 400], [300, 600]]}}, - 'sizes': [[240, 400], [300, 600]], - 'bidId': '2a11641ada3c6a' -}; - -const BANNER_BID_REQUEST = { - bidderCode: 'buzzoola', - bids: [BANNER_BID] -}; - -const BANNER_RESPONSE = [{ - 'requestId': '2a11641ada3c6a', - 'cpm': 5.583115, - 'width': 240, - 'height': 400, - 'creativeId': '11773', - 'dealId': '', - 'currency': 'RUB', - 'netRevenue': true, - 'ttl': 10800, - 'ad': '
', - 'mediaType': 'banner', - 'meta': { - 'advertiserDomains': [ - 'buzzoola.com' - ] - } -}]; - -const REQUIRED_BANNER_FIELDS = [ - 'requestId', - 'cpm', - 'width', - 'height', - 'ad', - 'ttl', - 'creativeId', - 'netRevenue', - 'currency', - 'mediaType', - 'meta' -]; - -const VIDEO_BID = { - 'bidder': 'buzzoola', - 'params': {'placementId': 417845}, - 'mediaTypes': { - 'video': { - 'context': 'instream', - 'playerSize': [[640, 380]], - 'mimes': ['video/mp4'], - 'minduration': 1, - 'maxduration': 2 - } - }, - 'bidId': '325a54271dc40a' -}; - -const VIDEO_BID_REQUEST = { - bidderCode: 'buzzoola', - bids: [VIDEO_BID] -}; - -const VIDEO_RESPONSE = [{ - 'requestId': '325a54271dc40a', - 'cpm': 5.528554074074074, - 'width': 640, - 'height': 480, - 'creativeId': '11774', - 'dealId': '', - 'currency': 'RUB', - 'netRevenue': true, - 'ttl': 10800, - 'ad': '{"crs":[{"advertiser_id":165,"title":"qa//PrebidJStestVideoURL","description":"qa//PrebidJStest","duration":0,"ya_id":"55038886","raw_content":"{\\"main_content\\": \\"https://tube.buzzoola.com/xstatic/o42/mcaug/2.mp4\\"}","content":{"main_content":"https://tube.buzzoola.com/xstatic/o42/mcaug/2.mp4"},"content_type":"video_url","sponsor_link":"","sponsor_name":"","overlay":"","overlay_start_after":0,"overlay_close_after":0,"action_button_title":"","tracking_url":{},"iframe_domains":[],"soc_share_url":"https://tube.buzzoola.com/share.html","player_show_skip_button_before_play":false,"player_show_skip_button_seconds":5,"player_show_title":true,"player_data_attributes":{"expandable":"default","overroll":"default"},"click_event_view":"default","share_panel_position":"left","auto_play":true,"logo_url":{},"share_buttons":["vkontakte","facebook","twitter","moimir","odnoklassniki","embed"],"player_show_panels":false,"thumbnail":"","tracking_js":{},"click_event_url":"https://exchange.buzzoola.com/event/f9382ceb-49c2-4683-50d8-5c516c53cd69/14795a96-6261-49dc-7241-207333ab1490/m7JVQI9Y7J35_gEDugNO2bIiP2qTqPKfuLrqqh_LoJu0tD6PoLEglMXUBzVpSg75c-unsaijXpIERGosa1adogXgqjDml4Pm/click/0/","vpaid_js_url":"https://tube.buzzoola.com/new/js/lib/vpaid_js_proxy.js","skip_clickthru":false,"landing_link_text":"","sound_enabled_by_default":false,"landing_link_position":"right","displayed_price":"","js_wrapper_url":"","enable_moat":false,"branding_template":"","event_url":"https://exchange.buzzoola.com/event/f9382ceb-49c2-4683-50d8-5c516c53cd69/14795a96-6261-49dc-7241-207333ab1490/m7JVQI9Y7J35_gEDugNO2bIiP2qTqPKfuLrqqh_LoJu0tD6PoLEglMXUBzVpSg75c-unsaijXpIERGosa1adogXgqjDml4Pm/","resend_event_url":"https://exchange.buzzoola.com/resend_event/f9382ceb-49c2-4683-50d8-5c516c53cd69/14795a96-6261-49dc-7241-207333ab1490/m7JVQI9Y7J35_gEDugNO2bIiP2qTqPKfuLrqqh_LoJu0tD6PoLEglMXUBzVpSg75c-unsaijXpIERGosa1adogXgqjDml4Pm/","creative_hash":"m7JVQI9Y7J35_gEDugNO2bIiP2qTqPKfuLrqqh_LoJu0tD6PoLEglMXUBzVpSg75c-unsaijXpIERGosa1adogXgqjDml4Pm","custom_html":"","custom_js":"","height":0,"width":0,"campaign_id":5758,"line_item_id":17319,"creative_id":11774,"extra":{"imp_id":"14795a96-6261-49dc-7241-207333ab1490","rtime":"2019-08-27 13:58:36"},"subcontent":"vast","auction_settings":{"price":"4.6158956756756755","currency":"RUB","event_name":"player_seen","time_slice":0},"hash_to_embed":"kbDH64c7yFYkSu0KCwSkoUD2bNHAnUTHBERqLGtWnaIF4Kow5peD5g","need_ad":false}],"tracking_urls":{"ctor":["https://www.tns-counter.ru/V13a****buzzola_com/ru/CP1251/tmsec=buzzola_total/1322650417245790778","https://www.tns-counter.ru/V13a****buzzoola_kz/ru/UTF-8/tmsec=buzzoola_video/5395765100939533275","https://buzzoolaru.solution.weborama.fr/fcgi-bin/dispatch.fcgi?a.A=ev&a.si=3071&a.te=37&a.aap=1&a.agi=862&a.evn=PrebidJS.test&g.ra=4581478478720298652","https://x01.aidata.io/0.gif?pid=BUZZOOLA&id=dbdb5b13-e719-4987-7f6a-a882322bbfce","https://top-fwz1.mail.ru/counter?id=3026769","https://www.tns-counter.ru/V13a****buzzola_com/ru/UTF-8/tmsec=buzzola_inread/542059452789128996","https://dm.hybrid.ai/match?id=111&vid=dbdb5b13-e719-4987-7f6a-a882322bbfce","https://px.adhigh.net/p/cm/buzzoola?u=dbdb5b13-e719-4987-7f6a-a882322bbfce","https://ssp1.rtb.beeline.ru/userbind?src=buz&ssp_user_id=dbdb5b13-e719-4987-7f6a-a882322bbfce","https://sync.upravel.com/image?source=buzzoola&id=dbdb5b13-e719-4987-7f6a-a882322bbfce","https://relap.io/api/partners/bzcs.gif?uid=dbdb5b13-e719-4987-7f6a-a882322bbfce","https://x.bidswitch.net/sync?ssp=sspicyads","https://inv-nets.admixer.net/adxcm.aspx?ssp=3C5173FC-CA30-4692-9116-009C19CB1BF9&rurl=%2F%2Fexchange.buzzoola.com%2Fcookiesync%2Fdsp%2Fadmixer-video%2F%24%24visitor_cookie%24%24","https://sync.datamind.ru/cookie/accepter?source=buzzoola&id=dbdb5b13-e719-4987-7f6a-a882322bbfce","https://dmp.vihub.ru/match?sysid=buz&redir=no&uid=dbdb5b13-e719-4987-7f6a-a882322bbfce","https://ad.adriver.ru/cgi-bin/rle.cgi?sid=1&ad=608223&bt=21&pid=2551979&bid=6150299&bn=6150299&rnd=1279444531737367663","https://reichelcormier.bid/point/?method=match&type=ssp&key=4677290772f9000878093d69c199bfba&id=3509&extUid=dbdb5b13-e719-4987-7f6a-a882322bbfce","https://sync.republer.com/match?src=buzzoola&id=dbdb5b13-e719-4987-7f6a-a882322bbfce","https://sm.rtb.mts.ru/p?id=dbdb5b13-e719-4987-7f6a-a882322bbfce&ssp=buzzoola","https://cm.mgid.com/m?cdsp=371151&adu=https%3A%2F%2Fexchange.buzzoola.com%2Fcookiesync%2Fdsp%2Fmarketgid-native%2F%7Bmuidn%7D","https://dmp.gotechnology.io/dmp/syncsspdmp?sspid=122258"]},"tracking_js":{"ctor":["https://buzzoola.fraudscore.mobi/dooJ9sheeeDaZ3fe.js?s=268671&l=417845"]},"placement":{"placement_id":417845,"unit_type":"inread","unit_settings":{"align":"left","autoplay_enable_sound":false,"creatives_amount":1,"debug_mode":false,"expandable":"never","sound_control":"default","target":"","width":"100%"},"unit_settings_list":["width","sound_control","debug_mode","target","creatives_amount","expandable","container_height","align","height"]},"uuid":"dbdb5b13-e719-4987-7f6a-a882322bbfce","auction_id":"f9382ceb-49c2-4683-50d8-5c516c53cd69","env":"prod"}', - 'vastUrl': 'https://exchange.buzzoola.com/prebid/adm/6cfa2ee1-f001-4fab-5582-a62eaee46205/m7JVQI9Y7J35_gEDugNO2bIiP2qTqPKfuLrqqh_LoJu0tD6PoLEglMXUBzVpSg75R6wziBhL0JAERGosa1adogXgqjDml4Pm/?auction_id=92702ce1-2328-4c7a-57aa-41c738e8bb75', - 'mediaType': 'video', - 'meta': { - 'advertiserDomains': [ - 'buzzoola.com' - ] - } -}]; - -const RENDERER_DATA = { - data: JSON.parse(VIDEO_RESPONSE[0].ad) -}; -RENDERER_DATA.data.placement.unit_settings.width = '' + VIDEO_RESPONSE[0].width; -RENDERER_DATA.data.placement.unit_settings.height = RENDERER_DATA.data.placement.unit_settings.container_height = '' + VIDEO_RESPONSE[0].height; - -const REQUIRED_VIDEO_FIELDS = [ - 'requestId', - 'cpm', - 'width', - 'height', - 'ad', - 'ttl', - 'creativeId', - 'netRevenue', - 'currency', - 'vastUrl', - 'mediaType', - 'meta' -]; - -const NATIVE_BID = { - 'bidder': 'buzzoola', - 'params': {'placementId': 417845}, - 'mediaTypes': { - 'native': { - 'image': { - 'required': true, - 'sizes': [640, 134] - }, - 'title': { - 'required': true, - 'len': 80 - }, - 'sponsoredBy': { - 'required': true - }, - 'clickUrl': { - 'required': true - }, - 'privacyLink': { - 'required': false - }, - 'body': { - 'required': true - }, - 'icon': { - 'required': true, - 'sizes': [50, 50] - } - } - }, - 'bidId': '22a42cd3522c6f' -}; - -const NATIVE_BID_REQUEST = { - bidderCode: 'buzzoola', - bids: [NATIVE_BID] -}; - -const NATIVE_RESPONSE = [{ - 'requestId': '22a42cd3522c6f', - 'cpm': 6.553015238095238, - 'width': 600, - 'height': 300, - 'creativeId': '17970', - 'dealId': '', - 'currency': 'RUB', - 'netRevenue': true, - 'ttl': 10800, - 'ad': 'https://tube.buzzoola.com/xstatic/o42/stoloto/6', - 'mediaType': 'native', - 'native': { - 'body': 'В 1388-м тираже «Русского лото» джекпот', - 'clickTrackers': [ - 'https://exchange.buzzoola.com/event/6cee890f-1878-4a37-46b3-0107b6c590ae/a1aedc5b-50f2-4a7c-6d24-e235bb1f87ed/m7JVQI9Y7J35_gEDugNO2bIiP2qTqPKfuLrqqh_LoJu0tD6PoLEglMXUBzVpSg75c-unsaijXpJwP8cy-zNH8GX-_nWFkILh/click/' - ], - 'clickUrl': 'https://ad.doubleclick.net/ddm/trackclk/N250204.3446512BUZZOOLA/B25801892.303578321;dc_trk_aid=496248119;dc_trk_cid=151207455;dc_lat=;dc_rdid=;tag_for_child_directed_treatment=;tfua=;ltd=?https://stoloto.onelink.me/mEJM?pid=Buzzoola_mb4&c=rl_10_05_2021&is_retargeting=true&af_ios_url=https%3A%2F%2Fapps.apple.com%2Fru%2Fapp%2F%25D1%2581%25D1%2582%25D0%25BE%25D0%25BB%25D0%25BE%25D1%2582%25D0%25BE-%25D1%2583-%25D0%25BD%25D0%25B0%25D1%2581-%25D0%25B2%25D1%258B%25D0%25B8%25D0%25B3%25D1%2580%25D1%258B%25D0%25B2%25D0%25B0%25D1%258E%25D1%2582%2Fid579961527&af_android_url=https%3A%2F%2Fgalaxystore.samsung.com%2Fdetail%2Fru.stoloto.mobile&af_dp=stolotoone%3A%2F%2Fgames&af_web_dp=https%3A%2F%2Fwww.stoloto.ru%2Fruslotto%2Fgame%3Flastdraw%3Fad%3Dbuzzoola_app_dx_rl_10_05_2021%26utm_source%3Dbuzzoola_app_dx%26utm_medium%3Dcpm%26utm_campaign%3Drl_10_05_2021%26utm_content%3Dbuzzoola_app_dx_mob_native_ios_mb4%26utm_term%3D__6ple2-9znjyg_', - 'icon': { - 'height': '100', - 'url': 'https://tube.buzzoola.com/xstatic/o42/stoloto/logo3.png', - 'width': '100' - }, - 'image': { - 'height': '450', - 'url': 'https://tube.buzzoola.com/xstatic/o42/stoloto/6/16x9.png', - 'width': '800' - }, - 'impressionTrackers': [ - 'https://exchange.buzzoola.com/event/6cee890f-1878-4a37-46b3-0107b6c590ae/a1aedc5b-50f2-4a7c-6d24-e235bb1f87ed/m7JVQI9Y7J35_gEDugNO2bIiP2qTqPKfuLrqqh_LoJu0tD6PoLEglMXUBzVpSg75c-unsaijXpJwP8cy-zNH8GX-_nWFkILh/ctor/', - 'https://exchange.buzzoola.com/event/6cee890f-1878-4a37-46b3-0107b6c590ae/a1aedc5b-50f2-4a7c-6d24-e235bb1f87ed/m7JVQI9Y7J35_gEDugNO2bIiP2qTqPKfuLrqqh_LoJu0tD6PoLEglMXUBzVpSg75c-unsaijXpJwP8cy-zNH8GX-_nWFkILh/impression/?price=${AUCTION_PRICE}&cur=${AUCTION_CURRENCY}', - 'https://exchange.buzzoola.com/event/6cee890f-1878-4a37-46b3-0107b6c590ae/a1aedc5b-50f2-4a7c-6d24-e235bb1f87ed/m7JVQI9Y7J35_gEDugNO2bIiP2qTqPKfuLrqqh_LoJu0tD6PoLEglMXUBzVpSg75c-unsaijXpJwP8cy-zNH8GX-_nWFkILh/player_seen/', - 'https://cr.frontend.weborama.fr/cr?key=mailru&url=https%3A%2F%2Fad.mail.ru%2Fcm.gif%3Fp%3D68%26id%3D%7BWEBO_CID%7D' - ], - 'sponsoredBy': 'Buzzoola', - 'title': 'Test PrebidJS Native' - }, - 'meta': { - 'advertiserDomains': [ - 'buzzoola.com' - ] - } -}]; - -const REQUIRED_NATIVE_FIELDS = [ - 'requestId', - 'cpm', - 'width', - 'height', - 'ad', - 'native', - 'ttl', - 'creativeId', - 'netRevenue', - 'currency', - 'mediaType', - 'meta' -]; - -describe('buzzoolaBidAdapter', () => { - const adapter = newBidder(spec); - - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', () => { - it('should return true when required params found', () => { - expect(spec.isBidRequestValid(VIDEO_BID)).to.be.true; - }); - - it('should return false when required params are not passed', () => { - INVALID_BIDS.forEach(bid => { - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - }); - }); - - describe('buildRequests', () => { - const videoBidRequests = [VIDEO_BID]; - const bannerBidRequests = [BANNER_BID]; - const nativeBidRequests = [NATIVE_BID]; - - const bannerRequest = spec.buildRequests(bannerBidRequests, BANNER_BID_REQUEST); - const nativeRequest = spec.buildRequests(nativeBidRequests, NATIVE_BID_REQUEST); - const videoRequest = spec.buildRequests(videoBidRequests, VIDEO_BID_REQUEST); - - it('sends bid request to ENDPOINT via POST', () => { - expect(videoRequest.method).to.equal('POST'); - expect(bannerRequest.method).to.equal('POST'); - expect(nativeRequest.method).to.equal('POST'); - }); - - it('sends bid request to correct ENDPOINT', () => { - expect(videoRequest.url).to.equal(ENDPOINT); - expect(bannerRequest.url).to.equal(ENDPOINT); - expect(nativeRequest.url).to.equal(ENDPOINT); - }); - - it('sends correct video bid parameters', () => { - expect(videoRequest.data).to.deep.equal(VIDEO_BID_REQUEST); - }); - - it('sends correct banner bid parameters', () => { - expect(bannerRequest.data).to.deep.equal(BANNER_BID_REQUEST); - }); - - it('sends correct native bid parameters', () => { - expect(nativeRequest.data).to.deep.equal(NATIVE_BID_REQUEST); - }); - }); - - describe('interpretResponse', () => { - const noBidServerResponse = []; - const emptyResponse = ''; - - function nobidServerResponseCheck(request, response = noBidServerResponse) { - const noBidResult = spec.interpretResponse({body: response}, {data: request}); - - expect(noBidResult.length).to.equal(0); - } - - function bidServerResponseCheck(response, request, fields) { - const result = spec.interpretResponse({body: response}, {data: request}); - - expect(result).to.deep.equal(response); - result.forEach(bid => { - fields.forEach(field => { - expect(bid).to.have.own.property(field); - }) - }); - } - - it('handles video nobid responses', () => { - nobidServerResponseCheck(VIDEO_BID_REQUEST); - }); - - it('handles banner nobid responses', () => { - nobidServerResponseCheck(BANNER_BID_REQUEST); - }); - - it('handles native nobid responses', () => { - nobidServerResponseCheck(NATIVE_BID_REQUEST); - }); - - it('handles video empty responses', () => { - nobidServerResponseCheck(VIDEO_BID_REQUEST, emptyResponse); - }); - - it('handles banner empty responses', () => { - nobidServerResponseCheck(BANNER_BID_REQUEST, emptyResponse); - }); - - it('handles native empty responses', () => { - nobidServerResponseCheck(NATIVE_BID_REQUEST, emptyResponse); - }); - - it('should get correct video bid response', () => { - bidServerResponseCheck(VIDEO_RESPONSE, VIDEO_BID_REQUEST, REQUIRED_VIDEO_FIELDS); - }); - - it('should get correct banner bid response', () => { - bidServerResponseCheck(BANNER_RESPONSE, BANNER_BID_REQUEST, REQUIRED_BANNER_FIELDS); - }); - - it('should get correct native bid response', () => { - bidServerResponseCheck(NATIVE_RESPONSE, NATIVE_BID_REQUEST, REQUIRED_NATIVE_FIELDS); - }); - }); - - describe('outstream renderer', () => { - let result; - let renderer; - - before(() => { - const adContainer = document.createElement('div'); - adContainer.id = 'adUnitCode'; - document.body.appendChild(adContainer); - - const outstreamVideoBid = deepClone(VIDEO_BID); - outstreamVideoBid.mediaTypes.video.context = 'outstream'; - - const outstreamVideoRequest = deepClone(VIDEO_BID_REQUEST); - outstreamVideoRequest.bids = [outstreamVideoBid]; - - const scriptElement = document.createElement('div'); - - const scriptStub = sinon.stub(document, 'createElement'); - scriptStub.withArgs('script').returns(scriptElement); - - result = spec.interpretResponse({body: VIDEO_RESPONSE}, {data: outstreamVideoRequest})[0]; - renderer = result.renderer; - - result.adUnitCode = 'adUnitCode'; - - if (scriptElement.onload) { - scriptElement.onload(); - } - - scriptStub.restore(); - }); - - it('should add renderer for outstream video', () => { - expect(result).to.have.own.property('renderer'); - }); - - it('should be instance of Renderer', () => { - expect(renderer).to.be.instanceof(Renderer); - }); - - it('should have valid src', () => { - expect(renderer.url).to.equal(RENDERER_SRC); - }); - - it('should create player instance', () => { - window.Buzzoola = { - Core: { - install: () => {} - } - }; - const spy = sinon.spy(window.Buzzoola.Core, 'install'); - executeRenderer(renderer, result); - renderer.callback(); - expect(spy.called).to.be.true; - - const spyCall = spy.getCall(0); - - expect(spyCall.args[0]).to.be.instanceof(Element); - expect(spyCall.args[1]).to.deep.equal(RENDERER_DATA); - }); - }); -}); diff --git a/test/spec/modules/byDataAnalyticsAdapter_spec.js b/test/spec/modules/byDataAnalyticsAdapter_spec.js deleted file mode 100644 index 862a0ee79..000000000 --- a/test/spec/modules/byDataAnalyticsAdapter_spec.js +++ /dev/null @@ -1,192 +0,0 @@ -import ascAdapter from 'modules/byDataAnalyticsAdapter'; -import { expect } from 'chai'; -import {EVENTS} from 'src/constants.js'; - -const adapterManager = require('src/adapterManager').default; -const events = require('src/events'); -const auctionId = 'b70ef967-5c5b-4602-831e-f2cf16e59af2'; -const initOptions = { - clientId: 'asc00000', - logFrequency: 1, -}; -const userData = { - 'uid': '271a8-2b86-f4a4-f59bc', - 'cid': 'asc00000', - 'pid': 'www.letsrun.com', - 'os': 'Macintosh', - 'osv': 10.157, - 'br': 'Chrome', - 'brv': 103, - 'ss': { - 'width': 1792, - 'height': 1120 - }, - 'de': 'Desktop', - 'tz': 'Asia/Calcutta' -}; -const bidTimeoutArgs = [{ - auctionId, - bidId: '12e90cb5ddc5dea', - bidder: 'appnexus', - adUnitCode: 'div-gpt-ad-mrec1' -}]; -const noBidArgs = { - adUnitCode: 'div-gpt-ad-mrec1', - auctionId, - bidId: '14480e9832f2d2b', - bidder: 'appnexus', - bidderRequestId: '13b87b6c20d3636', - mediaTypes: {banner: {sizes: [[300, 250], [250, 250]]}}, - sizes: [[300, 250], [250, 250]], - src: 'client', - transactionId: 'c8ee3914-1ee0-4ce6-9126-748d5692188c' -} -const bidWonArgs = { - auctionId, - adUnitCode: 'div-gpt-ad-mrec1', - size: '300x250', - requestId: '15c86b6c10d3746', - bidder: 'appnexus', - timeToRespond: 114, - currency: 'USD', - mediaType: 'display', - cpm: 0.50 -} - -const auctionEndArgs = { - adUnitCodes: ['div-gpt-ad-mrec1'], - adUnits: [{ - code: 'div-gpt-ad-mrec1', - mediaTypes: {banner: {sizes: [[300, 250], [250, 250]]}}, - sizes: [[300, 250], [250, 250]], - bids: [{bidder: 'appnexus', params: {placementId: '19305195'}}], - transactionId: 'c8ee3914-1ee0-4ce6-9126-748d5692188c' - }], - auctionEnd: 1627973487504, - auctionId, - auctionStatus: 'completed', - timestamp: 1627973484504, - bidsReceived: [], - bidderRequests: [{ - auctionId, - auctionStart: 1627973484504, - bidderCode: 'appnexus', - bidderRequestId: '13b87b6c20d3636', - bids: [ - { - adUnitCode: 'div-gpt-ad-mrec1', - auctionId, - bidId: '14480e9832f2d2b', - bidder: 'appnexus', - bidderRequestId: '13b87b6c20d3636', - src: 'client', - mediaTypes: {banner: {sizes: [[300, 250], [250, 250]]}}, - sizes: [[300, 250], [250, 250]], - transactionId: 'c8ee3914-1ee0-4ce6-9126-748d5692188c' - } - ] - }] -} -const expectedDataArgs = { - visitor_data: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIyNzFhOC0yYjg2LWY0YTQtZjU5YmMiLCJjaWQiOiJhc2MwMDAwMCIsInBpZCI6Ind3dy5sZXRzcnVuLmNvbSIsIm9zIjoiTWFjaW50b3NoIiwib3N2IjoxMC4xNTcsImJyIjoiQ2hyb21lIiwiYnJ2IjoxMDMsInNzIjp7IndpZHRoIjoxNzkyLCJoZWlnaHQiOjExMjB9LCJkZSI6IkRlc2t0b3AiLCJ0eiI6IkFzaWEvQ2FsY3V0dGEifQ.Oj3qnh--t06XO-foVmrMJCGqFfOBed09A-f7LZX5rtfBf4w1_RNRZ4F3on4TMPLonSa7GgzbcEfJS9G_amnleQ', - aid: auctionId, - as: 1627973484504, - auctionData: [ { - au: 'div-gpt-ad-mrec1', - auc: 'div-gpt-ad-mrec1', - aus: '300x250', - bidadv: 'appnexus', - bid: '14480e9832f2d2b', - inb: 1, - ito: 0, - ipwb: 0, - iwb: 0, - mt: 'display', - }, { - au: 'div-gpt-ad-mrec1', - auc: 'div-gpt-ad-mrec1', - aus: '250x250', - bidadv: 'appnexus', - bid: '14480e9832f2d2b', - inb: 1, - ito: 0, - ipwb: 0, - iwb: 0, - mt: 'display', - }] -} -const expectedBidWonArgs = { - visitor_data: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOiIyNzFhOC0yYjg2LWY0YTQtZjU5YmMiLCJjaWQiOiJhc2MwMDAwMCIsInBpZCI6Ind3dy5sZXRzcnVuLmNvbSIsIm9zIjoiTWFjaW50b3NoIiwib3N2IjoxMC4xNTcsImJyIjoiQ2hyb21lIiwiYnJ2IjoxMDMsInNzIjp7IndpZHRoIjoxNzkyLCJoZWlnaHQiOjExMjB9LCJkZSI6IkRlc2t0b3AiLCJ0eiI6IkFzaWEvQ2FsY3V0dGEifQ.Oj3qnh--t06XO-foVmrMJCGqFfOBed09A-f7LZX5rtfBf4w1_RNRZ4F3on4TMPLonSa7GgzbcEfJS9G_amnleQ', - aid: auctionId, - as: '', - auctionData: [{ - au: 'div-gpt-ad-mrec1', - auc: 'div-gpt-ad-mrec1', - aus: '300x250', - bid: '15c86b6c10d3746', - bidadv: 'appnexus', - br_pb_mg: 0.50, - br_tr: 114, - bradv: 'appnexus', - brid: '15c86b6c10d3746', - brs: '300x250', - cur: 'USD', - inb: 0, - ito: 0, - ipwb: 1, - iwb: 1, - mt: 'display', - }] -} - -describe('byData Analytics Adapter ', () => { - beforeEach(() => { - sinon.stub(events, 'getEvents').returns([]); - }); - afterEach(() => { - events.getEvents.restore(); - }); - - describe('enableAnalytics ', function () { - beforeEach(() => { - sinon.spy(ascAdapter, 'track'); - }); - afterEach(() => { - ascAdapter.disableAnalytics(); - ascAdapter.track.restore(); - }); - it('should init with correct options', function () { - ascAdapter.enableAnalytics(initOptions) - // Step 1: Initialize adapter - adapterManager.enableAnalytics({ - provider: 'bydata', - options: initOptions - }); - expect(ascAdapter.initOptions).to.have.property('clientId', 'asc00000'); - expect(ascAdapter.initOptions).to.have.property('logFrequency', 1); - }); - }); - - describe('track-events', function () { - before(() => { - ascAdapter.enableAnalytics(initOptions) - // Step 1: Initialize adapter - adapterManager.enableAnalytics({ - provider: 'bydata', - options: initOptions - }); - }); - it('sends and formatted auction data ', function () { - events.emit(EVENTS.BID_TIMEOUT, bidTimeoutArgs); - events.emit(EVENTS.NO_BID, noBidArgs); - events.emit(EVENTS.BID_WON, bidWonArgs) - var userToken = ascAdapter.getVisitorData(userData); - var newAuData = ascAdapter.dataProcess(auctionEndArgs); - var newBwData = ascAdapter.getBidWonData(bidWonArgs); - newAuData['visitor_data'] = userToken; - newBwData['visitor_data'] = userToken; - expect(newAuData).to.deep.equal(expectedDataArgs); - expect(newBwData).to.deep.equal(expectedBidWonArgs); - }); - }); -}); diff --git a/test/spec/modules/c1xBidAdapter_spec.js b/test/spec/modules/c1xBidAdapter_spec.js deleted file mode 100644 index a325e4377..000000000 --- a/test/spec/modules/c1xBidAdapter_spec.js +++ /dev/null @@ -1,189 +0,0 @@ -import { expect } from 'chai'; -import { newBidder } from 'src/adapters/bidderFactory'; -import { c1xAdapter } from '../../../modules/c1xBidAdapter.js'; - -const ENDPOINT = 'https://hb-stg.c1exchange.com/ht'; -const BIDDER_CODE = 'c1x'; - -describe('C1XAdapter', () => { - const adapter = newBidder(c1xAdapter); - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - describe('isBidRequestValid', () => { - const bid = { - 'bidder': BIDDER_CODE, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'params': { - 'placementId': 'div-gpt-ad-1654594619717-0' - } - }; - it('should return true when required params found', function () { - expect(c1xAdapter.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when placementId not passed correctly', function () { - bid.params.placementId = undefined; - expect(c1xAdapter.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when require params are not passed', function () { - const invalidBid = Object.assign({}, bid); - invalidBid.params = {}; - expect(c1xAdapter.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - describe('buildRequests', () => { - const bidRequests = [ - { - 'bidder': BIDDER_CODE, - 'params': { - 'placementId': 'div-gpt-ad-1654594619717-0', - 'dealId': '1233' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 250], [300, 600] - ] - } - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - } - ]; - const parseRequest = (data) => { - const parsedData = '{"' + data.replace(/=|&/g, (foundChar) => { - if (foundChar === '=') return '":"'; - else if (foundChar === '&') return '","'; - }) + '"}' - return parsedData; - }; - it('sends bid request to ENDPOINT via GET', () => { - const request = c1xAdapter.buildRequests(bidRequests); - expect(request[0].url).to.contain(ENDPOINT); - expect(request[0].method).to.equal('GET'); - }); - it('should generate correct bid Id tag', () => { - const request = c1xAdapter.buildRequests(bidRequests)[0]; - expect(request.bids[0].adUnitCode).to.equal('adunit-code'); - expect(request.bids[0].bidId).to.equal('30b31c1838de1e'); - }); - it('should convert params to proper form and attach to request', () => { - const request = c1xAdapter.buildRequests(bidRequests)[0]; - const originalPayload = parseRequest(request.data); - const payloadObj = JSON.parse(originalPayload); - expect(payloadObj.adunits).to.equal('1'); - expect(payloadObj.a1s).to.equal('300x250,300x600'); - expect(payloadObj.a1).to.equal('adunit-code'); - expect(payloadObj.a1d).to.equal('1233'); - }); - it('should convert floor price to proper form and attach to request', () => { - const bidRequest = Object.assign({}, - bidRequests[0], - { - 'params': { - 'placementId': 'div-gpt-ad-1654594619717-0', - 'dealId': '1233', - 'floorPriceMap': { - '300x250': 4.35 - } - } - }); - const request = c1xAdapter.buildRequests([bidRequest])[0]; - const originalPayload = parseRequest(request.data); - const payloadObj = JSON.parse(originalPayload); - expect(payloadObj.a1p).to.equal('4.35'); - }); - it('should convert pageurl to proper form and attach to request', () => { - const bidRequest = Object.assign({}, - bidRequests[0], - { - 'params': { - 'placementId': 'div-gpt-ad-1654594619717-0', - 'dealId': '1233', - 'pageurl': 'http://c1exchange.com/' - } - }); - - const bidderRequest = { - 'bidderCode': 'c1x' - } - bidderRequest.bids = bidRequests; - const request = c1xAdapter.buildRequests([bidRequest], bidderRequest)[0]; - const originalPayload = parseRequest(request.data); - const payloadObj = JSON.parse(originalPayload); - expect(payloadObj.pageurl).to.equal('http://c1exchange.com/'); - }); - - it('should convert GDPR Consent to proper form and attach to request', () => { - const consentString = 'BOP2gFWOQIFovABABAENBGAAAAAAMw'; - const bidderRequest = { - 'bidderCode': 'c1x', - 'gdprConsent': { - 'consentString': consentString, - 'gdprApplies': true - } - } - bidderRequest.bids = bidRequests; - - const request = c1xAdapter.buildRequests(bidRequests, bidderRequest)[0]; - const originalPayload = parseRequest(request.data); - const payloadObj = JSON.parse(originalPayload); - expect(payloadObj['consent_string']).to.equal('BOP2gFWOQIFovABABAENBGAAAAAAMw'); - expect(payloadObj['consent_required']).to.equal('true'); - }); - }); - - describe('interpretResponse', () => { - const response = { - 'bid': true, - 'cpm': 1.5, - 'ad': '', - 'width': 300, - 'height': 250, - 'crid': '8888', - 'adId': 'c1x-test', - 'bidType': 'GROSS_BID' - }; - it('should get correct bid response', () => { - const expectedResponse = [ - { - width: 300, - height: 250, - cpm: 1.5, - ad: '', - creativeId: '8888', - currency: 'USD', - ttl: 300, - netRevenue: false, - requestId: 'yyyy' - } - ]; - const bidderRequest = {}; - bidderRequest.bids = [ - { - adUnitCode: 'c1x-test', - bidId: 'yyyy' - } - ]; - const result = c1xAdapter.interpretResponse({ body: [response] }, bidderRequest); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - it('handles nobid responses', () => { - const response = { - bid: false, - adId: 'c1x-test' - }; - const bidderRequest = {}; - const result = c1xAdapter.interpretResponse({ body: [response] }, bidderRequest); - expect(result.length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/cadent_aperture_mxBidAdapter_spec.js b/test/spec/modules/cadent_aperture_mxBidAdapter_spec.js deleted file mode 100644 index de33d5ff6..000000000 --- a/test/spec/modules/cadent_aperture_mxBidAdapter_spec.js +++ /dev/null @@ -1,871 +0,0 @@ -import * as utils from 'src/utils.js'; - -import { expect } from 'chai'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { spec } from 'modules/cadent_aperture_mxBidAdapter.js'; - -describe('cadent_aperture_mx Adapter', function () { - describe('callBids', function () { - const adapter = newBidder(spec); - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - describe('banner request validity', function () { - const bid = { - 'bidder': 'cadent_aperture_mx', - 'params': { - 'tagid': '25251' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]] - } - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c2501de1e', - 'bidderRequestId': '22edbae3120bf6', - 'auctionId': '1d1a01234a475' - }; - const badBid = { - 'bidder': 'cadent_aperture_mx', - 'params': { - 'tagid': '25251' - }, - 'mediaTypes': { - 'banner': { - } - }, - 'adUnitCode': 'adunit-code', - 'bidId': '30b31c2501de1e', - 'bidderRequestId': '22edbae3120bf6', - 'auctionId': '1d1a01234a475' - }; - const noBid = {}; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - expect(spec.isBidRequestValid(badBid)).to.equal(false); - expect(spec.isBidRequestValid(noBid)).to.equal(false); - }); - }); - - describe('video request validity', function () { - const bid = { - 'bidder': 'cadent_aperture_mx', - 'params': { - 'tagid': '25251', - 'video': {} - }, - 'mediaTypes': { - 'video': { - 'context': 'instream', - 'playerSize': [640, 480] - } - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c2501de1e', - 'bidderRequestId': '22edbae3120bf6', - 'auctionId': '1d1a01234a475' - }; - const noInstreamBid = { - 'bidder': 'cadent_aperture_mx', - 'params': { - 'tagid': '25251', - 'video': { - 'protocols': [1, 7] - } - }, - 'mediaTypes': { - 'video': { - 'context': 'something_random' - } - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c2501de1e', - 'bidderRequestId': '22edbae3120bf6', - 'auctionId': '1d1a01234a475' - }; - - const outstreamBid = { - 'bidder': 'cadent_aperture_mx', - 'params': { - 'tagid': '25251', - 'video': {} - }, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'playerSize': [640, 480] - } - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c2501de1e', - 'bidderRequestId': '22edbae3120bf6', - 'auctionId': '1d1a01234a475' - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - expect(spec.isBidRequestValid(noInstreamBid)).to.equal(false); - expect(spec.isBidRequestValid(outstreamBid)).to.equal(true); - }); - - it('should contain tagid param', function () { - expect(spec.isBidRequestValid({ - bidder: 'cadent_aperture_mx', - params: {}, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - })).to.equal(false); - expect(spec.isBidRequestValid({ - bidder: 'cadent_aperture_mx', - params: { - tagid: '' - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - })).to.equal(false); - expect(spec.isBidRequestValid({ - bidder: 'cadent_aperture_mx', - params: { - tagid: '123' - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - })).to.equal(true); - }); - }); - }); - - describe('buildRequests', function () { - const bidderRequest = { - 'bidderCode': 'cadent_aperture_mx', - 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', - 'bidderRequestId': '22edbae3120bf6', - 'timeout': 1500, - 'refererInfo': { - 'numIframes': 0, - 'reachedTop': true, - 'page': 'https://example.com/index.html?pbjs_debug=true', - 'domain': 'example.com', - 'ref': 'https://referrer.com' - }, - 'bids': [{ - 'bidder': 'cadent_aperture_mx', - 'params': { - 'tagid': '25251' - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 250], - [300, 600] - ] - } - }, - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c2501de1e', - 'auctionId': 'e19f1eff-8b27-42a6-888d-9674e5a6130c', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'ortb2Imp': { - 'ext': { - 'tid': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ed', - }, - }, - }] - }; - let request = spec.buildRequests(bidderRequest.bids, bidderRequest); - - describe('non-gpp tests', function() { - it('sends bid request to ENDPOINT via POST', function () { - expect(request.method).to.equal('POST'); - }); - - it('contains the correct options', function () { - expect(request.options.withCredentials).to.equal(true); - }); - - it('contains a properly formatted endpoint url', function () { - const url = request.url.split('?'); - const queryParams = url[1].split('&'); - expect(queryParams[0]).to.match(new RegExp('^t=\d*', 'g')); - expect(queryParams[1]).to.match(new RegExp('^ts=\d*', 'g')); - }); - - it('builds bidfloor value from bid param when getFloor function does not exist', function () { - const bidRequestWithFloor = utils.deepClone(bidderRequest.bids); - bidRequestWithFloor[0].params.bidfloor = 1; - const requestWithFloor = spec.buildRequests(bidRequestWithFloor, bidderRequest); - const data = JSON.parse(requestWithFloor.data); - expect(data.imp[0].bidfloor).to.equal(bidRequestWithFloor[0].params.bidfloor); - }); - - it('builds bidfloor value from getFloor function when it exists', function () { - const floorResponse = { currency: 'USD', floor: 3 }; - const bidRequestWithGetFloor = utils.deepClone(bidderRequest.bids); - bidRequestWithGetFloor[0].getFloor = () => floorResponse; - const requestWithGetFloor = spec.buildRequests(bidRequestWithGetFloor, bidderRequest); - const data = JSON.parse(requestWithGetFloor.data); - expect(data.imp[0].bidfloor).to.equal(3); - }); - - it('builds bidfloor value from getFloor when both floor and getFloor function exists', function () { - const floorResponse = { currency: 'USD', floor: 3 }; - const bidRequestWithBothFloors = utils.deepClone(bidderRequest.bids); - bidRequestWithBothFloors[0].params.bidfloor = 1; - bidRequestWithBothFloors[0].getFloor = () => floorResponse; - const requestWithBothFloors = spec.buildRequests(bidRequestWithBothFloors, bidderRequest); - const data = JSON.parse(requestWithBothFloors.data); - expect(data.imp[0].bidfloor).to.equal(3); - }); - - it('empty bidfloor value when floor and getFloor is not defined', function () { - const bidRequestWithoutFloor = utils.deepClone(bidderRequest.bids); - const requestWithoutFloor = spec.buildRequests(bidRequestWithoutFloor, bidderRequest); - const data = JSON.parse(requestWithoutFloor.data); - expect(data.imp[0].bidfloor).to.not.exist; - }); - - it('builds request properly', function () { - const data = JSON.parse(request.data); - expect(Array.isArray(data.imp)).to.equal(true); - expect(data.id).to.equal(bidderRequest.auctionId); - expect(data.imp.length).to.equal(1); - expect(data.imp[0].id).to.equal('30b31c2501de1e'); - expect(data.imp[0].tid).to.equal('d7b773de-ceaa-484d-89ca-d9f51b8d61ed'); - expect(data.imp[0].tagid).to.equal('25251'); - expect(data.imp[0].secure).to.equal(0); - expect(data.imp[0].vastXml).to.equal(undefined); - }); - - it('populates id even when auctionId is not available', function () { - // addressing https://github.com/prebid/Prebid.js/issues/9781 - bidderRequest.auctionId = null; - request = spec.buildRequests(bidderRequest.bids, bidderRequest); - - const data = JSON.parse(request.data); - expect(data.id).not.to.be.null; - expect(data.id).not.to.equal(bidderRequest.auctionId); - }); - - it('properly sends site information and protocol', function () { - request = spec.buildRequests(bidderRequest.bids, bidderRequest); - request = JSON.parse(request.data); - expect(request.site).to.have.property('domain', 'example.com'); - expect(request.site).to.have.property('page', 'https://example.com/index.html?pbjs_debug=true'); - expect(request.site).to.have.property('ref', 'https://referrer.com'); - }); - - it('builds correctly formatted request banner object', function () { - const bidRequestWithBanner = utils.deepClone(bidderRequest.bids); - const request = spec.buildRequests(bidRequestWithBanner, bidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].video).to.equal(undefined); - expect(data.imp[0].banner).to.exist.and.to.be.a('object'); - expect(data.imp[0].banner.w).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[0][0]); - expect(data.imp[0].banner.h).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[0][1]); - expect(data.imp[0].banner.format[0].w).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[0][0]); - expect(data.imp[0].banner.format[0].h).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[0][1]); - expect(data.imp[0].banner.format[1].w).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[1][0]); - expect(data.imp[0].banner.format[1].h).to.equal(bidRequestWithBanner[0].mediaTypes.banner.sizes[1][1]); - }); - - it('builds correctly formatted request video object for instream', function () { - const bidRequestWithVideo = utils.deepClone(bidderRequest.bids); - bidRequestWithVideo[0].mediaTypes = { - video: { - context: 'instream', - playerSize: [[640, 480]] - }, - }; - bidRequestWithVideo[0].params.video = {}; - const request = spec.buildRequests(bidRequestWithVideo, bidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].video).to.exist.and.to.be.a('object'); - expect(data.imp[0].video.w).to.equal(bidRequestWithVideo[0].mediaTypes.video.playerSize[0][0]); - expect(data.imp[0].video.h).to.equal(bidRequestWithVideo[0].mediaTypes.video.playerSize[0][1]); - }); - - it('builds correctly formatted request video object for outstream', function () { - const bidRequestWithOutstreamVideo = utils.deepClone(bidderRequest.bids); - bidRequestWithOutstreamVideo[0].mediaTypes = { - video: { - context: 'outstream', - playerSize: [[640, 480]] - }, - }; - bidRequestWithOutstreamVideo[0].params.video = {}; - const request = spec.buildRequests(bidRequestWithOutstreamVideo, bidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].video).to.exist.and.to.be.a('object'); - expect(data.imp[0].video.w).to.equal(bidRequestWithOutstreamVideo[0].mediaTypes.video.playerSize[0][0]); - expect(data.imp[0].video.h).to.equal(bidRequestWithOutstreamVideo[0].mediaTypes.video.playerSize[0][1]); - }); - - it('shouldn\'t contain a user obj without GDPR information', function () { - let request = spec.buildRequests(bidderRequest.bids, bidderRequest) - request = JSON.parse(request.data) - expect(request).to.not.have.property('user'); - }); - - it('should have the right gdpr info when enabled', function () { - const consentString = 'OIJSZsOAFsABAB8EMXZZZZZ+A=='; - const gdprBidderRequest = utils.deepClone(bidderRequest); - gdprBidderRequest.gdprConsent = { - 'consentString': consentString, - 'gdprApplies': true - }; - let request = spec.buildRequests(gdprBidderRequest.bids, gdprBidderRequest); - - request = JSON.parse(request.data) - expect(request.regs.ext).to.have.property('gdpr', 1); - expect(request.user.ext).to.have.property('consent', consentString); - }); - - it('should\'t contain consent string if gdpr isn\'t applied', function () { - const nonGdprBidderRequest = utils.deepClone(bidderRequest); - nonGdprBidderRequest.gdprConsent = { - 'gdprApplies': false - }; - let request = spec.buildRequests(nonGdprBidderRequest.bids, nonGdprBidderRequest); - request = JSON.parse(request.data) - expect(request.regs.ext).to.have.property('gdpr', 0); - expect(request).to.not.have.property('user'); - }); - - it('should add us privacy info to request', function() { - const uspBidderRequest = utils.deepClone(bidderRequest); - const consentString = '1YNN'; - uspBidderRequest.uspConsent = consentString; - let request = spec.buildRequests(uspBidderRequest.bids, uspBidderRequest); - request = JSON.parse(request.data); - expect(request.us_privacy).to.exist; - expect(request.us_privacy).to.exist.and.to.equal(consentString); - }); - - it('should add schain object to request', function() { - const schainBidderRequest = utils.deepClone(bidderRequest); - schainBidderRequest.bids[0].ortb2 = { - source: { - ext: { - schain: { - 'complete': 1, - 'ver': '1.0', - 'nodes': [ - { - 'asi': 'testing.com', - 'sid': 'abc', - 'hp': 1 - } - ] - } - } - } - }; - let request = spec.buildRequests(schainBidderRequest.bids, schainBidderRequest); - request = JSON.parse(request.data); - expect(request.source.ext.schain).to.exist; - expect(request.source.ext.schain).to.have.property('complete', 1); - expect(request.source.ext.schain).to.have.property('ver', '1.0'); - expect(request.source.ext.schain.nodes[0].asi).to.equal(schainBidderRequest.bids[0].ortb2.source.ext.schain.nodes[0].asi); - }); - - it('should add liveramp identitylink id to request', () => { - const idl_env = '123'; - const bidRequestWithID = utils.deepClone(bidderRequest); - bidRequestWithID.userId = { idl_env }; - let requestWithID = spec.buildRequests(bidRequestWithID.bids, bidRequestWithID); - requestWithID = JSON.parse(requestWithID.data); - expect(requestWithID.user.ext.eids[0]).to.deep.equal({ - source: 'liveramp.com', - uids: [{ - id: idl_env, - ext: { - rtiPartner: 'idl' - } - }] - }); - }); - - it('should add gpid to request if present in ext.gpid', () => { - const gpid = '/12345/my-gpt-tag-0'; - const bid = utils.deepClone(bidderRequest.bids[0]); - bid.ortb2Imp = { ext: { gpid, data: { adserver: { adslot: gpid + '1' }, pbadslot: gpid + '2' } } }; - let requestWithGPID = spec.buildRequests([bid], bidderRequest); - requestWithGPID = JSON.parse(requestWithGPID.data); - expect(requestWithGPID.imp[0].ext.gpid).to.exist.and.equal(gpid); - }); - - it('should add gpid to request if present in ext.data.adserver.adslot', () => { - const gpid = '/12345/my-gpt-tag-0'; - const bid = utils.deepClone(bidderRequest.bids[0]); - bid.ortb2Imp = { ext: { data: { adserver: { adslot: gpid }, pbadslot: gpid + '1' } } }; - let requestWithGPID = spec.buildRequests([bid], bidderRequest); - requestWithGPID = JSON.parse(requestWithGPID.data); - expect(requestWithGPID.imp[0].ext.gpid).to.exist.and.equal(gpid); - }); - - it('should add gpid to request if present in ext.data.pbadslot', () => { - const gpid = '/12345/my-gpt-tag-0'; - const bid = utils.deepClone(bidderRequest.bids[0]); - bid.ortb2Imp = { ext: { data: {}, gpid } }; - let requestWithGPID = spec.buildRequests([bid], bidderRequest); - requestWithGPID = JSON.parse(requestWithGPID.data); - expect(requestWithGPID.imp[0].ext.gpid).to.exist.and.equal(gpid); - }); - - it('should add UID 2.0 to request', () => { - const uid2 = { id: '456' }; - const bidRequestWithUID = utils.deepClone(bidderRequest); - bidRequestWithUID.userId = { uid2 }; - let requestWithUID = spec.buildRequests(bidRequestWithUID.bids, bidRequestWithUID); - requestWithUID = JSON.parse(requestWithUID.data); - expect(requestWithUID.user.ext.eids[0]).to.deep.equal({ - source: 'uidapi.com', - uids: [{ - id: uid2.id, - ext: { - rtiPartner: 'UID2' - } - }] - }); - }); - }); - - describe('gpp tests', function() { - describe('when gppConsent is not present on bid request', () => { - it('should return request with no gpp or gpp_sid properties', function() { - const gppCompliantBidderRequest = utils.deepClone(bidderRequest); - - let request = spec.buildRequests(gppCompliantBidderRequest.bids, gppCompliantBidderRequest); - request = JSON.parse(request.data); - expect(request?.regs?.gpp).to.be.undefined; - expect(request?.regs?.gpp_sid).to.be.undefined; - }); - }); - - describe('when gppConsent is present on bid request', () => { - describe('gppString', () => { - describe('is not defined on request', () => { - it('should return request with gpp undefined', () => { - const gppCompliantBidderRequest = utils.deepClone(bidderRequest); - - let request = spec.buildRequests(gppCompliantBidderRequest.bids, gppCompliantBidderRequest); - request = JSON.parse(request.data); - expect(request?.regs?.gpp).to.be.undefined; - }); - }); - - describe('is defined on request', () => { - it('should return request with gpp set correctly', () => { - const gppCompliantBidderRequest = utils.deepClone(bidderRequest); - const gppString = 'abcdefgh'; - gppCompliantBidderRequest.gppConsent = { - gppString - } - - let request = spec.buildRequests(gppCompliantBidderRequest.bids, gppCompliantBidderRequest); - request = JSON.parse(request.data); - expect(request.regs.gpp).to.exist.and.to.equal(gppString); - }); - }); - }); - - describe('applicableSections', () => { - describe('is not defined on request', () => { - it('should return request with gpp_sid undefined', () => { - const gppCompliantBidderRequest = utils.deepClone(bidderRequest); - - let request = spec.buildRequests(gppCompliantBidderRequest.bids, gppCompliantBidderRequest); - request = JSON.parse(request.data); - expect(request?.regs?.gpp_sid).to.be.undefined; - }); - }); - - describe('is defined on request', () => { - it('should return request with gpp_sid set correctly', () => { - const gppCompliantBidderRequest = utils.deepClone(bidderRequest); - const applicableSections = [8]; - gppCompliantBidderRequest.gppConsent = { - applicableSections - } - - let request = spec.buildRequests(gppCompliantBidderRequest.bids, gppCompliantBidderRequest); - request = JSON.parse(request.data); - expect(request.regs.gpp_sid).to.deep.equal(applicableSections); - }); - }); - }); - }); - }); - }); - - describe('interpretResponse', function () { - const bid = { - 'bidder': 'cadent_aperture_mx', - 'params': { - 'tagid': '25251', - 'video': {} - }, - 'mediaTypes': { - 'video': { - 'context': 'instream', - 'playerSize': [640, 480] - } - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '30b31c2501de1e', - 'bidderRequestId': '22edbae3120bf6', - 'auctionId': '1d1a01234a475' - }; - - const bid_outstream = { - 'bidderRequest': { - 'bids': [{ - 'bidder': 'cadent_aperture_mx', - 'params': { - 'tagid': '25251', - 'video': {} - }, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'playerSize': [640, 480] - } - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '987654321cba', - 'bidderRequestId': '22edbae3120bf6', - 'auctionId': '1d1a01234a475' - }, { - 'bidder': 'cadent_aperture_mx', - 'params': { - 'tagid': '25252', - 'video': {} - }, - 'mediaTypes': { - 'video': { - 'context': 'instream', - 'playerSize': [640, 480] - } - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '987654321dcb', - 'bidderRequestId': '22edbae3120bf6', - 'auctionId': '1d1a01234a475' - }] - } - }; - - const serverResponse = { - 'id': '12819a18-56e1-4256-b836-b69a10202668', - 'seatbid': [{ - 'bid': [{ - 'adid': '123456abcde', - 'adm': '', - 'crid': '3434abab34', - 'h': 250, - 'id': '987654321cba', - 'price': 0.5, - 'ttl': 300, - 'w': 300, - 'adomain': ['example.com'] - }], - 'seat': '1356' - }, { - 'bid': [{ - 'adid': '123456abcdf', - 'adm': '', - 'crid': '3434abab35', - 'h': 600, - 'id': '987654321dcb', - 'price': 0.5, - 'ttl': 300, - 'w': 300 - }] - }] - }; - - const expectedResponse = [{ - 'requestId': '12819a18-56e1-4256-b836-b69a10202668', - 'cpm': 0.5, - 'width': 300, - 'height': 250, - 'creativeId': '3434abab34', - 'dealId': null, - 'currency': 'USD', - 'netRevneue': true, - 'mediaType': 'banner', - 'ad': '', - 'ttl': 300, - 'meta': { - 'advertiserDomains': ['example.com'] - } - }, { - 'requestId': '12819a18-56e1-4256-b836-b69a10202668', - 'cpm': 0.7, - 'width': 300, - 'height': 600, - 'creativeId': '3434abab35', - 'dealId': null, - 'currency': 'USD', - 'netRevneue': true, - 'mediaType': 'banner', - 'ad': '', - 'ttl': 300 - }]; - - it('should properly format bid response', function () { - const result = spec.interpretResponse({ - body: serverResponse - }); - expect(Object.keys(result[0]).length).to.equal(Object.keys(expectedResponse[0]).length); - expect(Object.keys(result[0]).requestId).to.equal(Object.keys(expectedResponse[0]).requestId); - expect(Object.keys(result[0]).bidderCode).to.equal(Object.keys(expectedResponse[0]).bidderCode); - expect(Object.keys(result[0]).cpm).to.equal(Object.keys(expectedResponse[0]).cpm); - expect(Object.keys(result[0]).creativeId).to.equal(Object.keys(expectedResponse[0]).creativeId); - expect(Object.keys(result[0]).width).to.equal(Object.keys(expectedResponse[0]).width); - expect(Object.keys(result[0]).height).to.equal(Object.keys(expectedResponse[0]).height); - expect(Object.keys(result[0]).ttl).to.equal(Object.keys(expectedResponse[0]).ttl); - expect(Object.keys(result[0]).adId).to.equal(Object.keys(expectedResponse[0]).adId); - expect(Object.keys(result[0]).currency).to.equal(Object.keys(expectedResponse[0]).currency); - expect(Object.keys(result[0]).netRevenue).to.equal(Object.keys(expectedResponse[0]).netRevenue); - expect(Object.keys(result[0]).ad).to.equal(Object.keys(expectedResponse[0]).ad); - }); - - it('should return multiple bids', function () { - const result = spec.interpretResponse({ - body: serverResponse - }); - expect(Array.isArray(result.seatbid)) - - const ad0 = result[0]; - const ad1 = result[1]; - expect(ad0.ad).to.equal(serverResponse.seatbid[0].bid[0].adm); - expect(ad0.cpm).to.equal(serverResponse.seatbid[0].bid[0].price); - expect(ad0.creativeId).to.equal(serverResponse.seatbid[0].bid[0].crid); - expect(ad0.currency).to.equal('USD'); - expect(ad0.netRevenue).to.equal(true); - expect(ad0.requestId).to.equal(serverResponse.seatbid[0].bid[0].id); - expect(ad0.ttl).to.equal(300); - - expect(ad1.ad).to.equal(serverResponse.seatbid[1].bid[0].adm); - expect(ad1.cpm).to.equal(serverResponse.seatbid[1].bid[0].price); - expect(ad1.creativeId).to.equal(serverResponse.seatbid[1].bid[0].crid); - expect(ad1.currency).to.equal('USD'); - expect(ad1.netRevenue).to.equal(true); - expect(ad1.requestId).to.equal(serverResponse.seatbid[1].bid[0].id); - expect(ad1.ttl).to.equal(300); - }); - - it('returns a banner bid for non-xml creatives', function () { - const result = spec.interpretResponse({ - body: serverResponse - }, { bidRequest: bid } - ); - const ad0 = result[0]; - const ad1 = result[1]; - expect(ad0.mediaType).to.equal('banner'); - expect(ad0.ad.indexOf(''; - vastServerResponse.seatbid[1].bid[0].adm = ''; - - const result = spec.interpretResponse({ - body: vastServerResponse - }, { bidRequest: bid } - ); - const ad0 = result[0]; - const ad1 = result[1]; - expect(ad0.mediaType).to.equal('video'); - expect(ad0.ad.indexOf(' -1).to.equal(true); - expect(ad0.vastXml).to.equal(vastServerResponse.seatbid[0].bid[0].adm); - expect(ad0.ad).to.exist.and.to.be.a('string'); - expect(ad1.mediaType).to.equal('video'); - expect(ad1.ad.indexOf(' -1).to.equal(true); - expect(ad1.vastXml).to.equal(vastServerResponse.seatbid[1].bid[0].adm); - expect(ad1.ad).to.exist.and.to.be.a('string'); - }); - - it('returns a renderer for outstream video creatives', function () { - const vastServerResponse = utils.deepClone(serverResponse); - vastServerResponse.seatbid[0].bid[0].adm = ''; - vastServerResponse.seatbid[1].bid[0].adm = ''; - const result = spec.interpretResponse({body: vastServerResponse}, bid_outstream); - const ad0 = result[0]; - const ad1 = result[1]; - expect(ad0.renderer).to.exist.and.to.be.a('object'); - expect(ad0.renderer.url).to.equal('https://js.brealtime.com/outstream/1.30.0/bundle.js'); - expect(ad0.renderer.id).to.equal('987654321cba'); - expect(ad1.renderer).to.equal(undefined); - }); - - it('handles nobid responses', function () { - const serverResponse = { - 'bids': [] - }; - - const result = spec.interpretResponse({ - body: serverResponse - }); - expect(result.length).to.equal(0); - }); - - it('should not throw an error when decoding an improperly encoded adm', function () { - const badAdmServerResponse = utils.deepClone(serverResponse); - badAdmServerResponse.seatbid[0].bid[0].adm = '\\<\\/script\\>'; - badAdmServerResponse.seatbid[1].bid[0].adm = '%3F%%3Dcadent%3C3prebid'; - - assert.doesNotThrow(() => spec.interpretResponse({ - body: badAdmServerResponse - })); - }); - - it('returns valid advertiser domains', function () { - const bidResponse = utils.deepClone(serverResponse); - const result = spec.interpretResponse({body: bidResponse}); - expect(result[0].meta.advertiserDomains).to.deep.equal(expectedResponse[0].meta.advertiserDomains); - // case where adomains are not in request - expect(result[1].meta).to.not.exist; - }); - }); - - describe('getUserSyncs', function () { - it('should register the iframe sync url', function () { - const syncs = spec.getUserSyncs({ - iframeEnabled: true - }); - expect(syncs).to.not.be.an('undefined'); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.equal('https://biddr.brealtime.com/check.html') - }); - - it('should pass gdpr params', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, { - gdprApplies: false, consentString: 'test' - }); - expect(syncs).to.not.be.an('undefined'); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.contains('gdpr=0'); - expect(syncs[0].url).to.equal('https://biddr.brealtime.com/check.html?gdpr=0&gdpr_consent=test') - }); - - it('should pass us_privacy string', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, {}, { - consentString: 'test', - }); - expect(syncs).to.not.be.an('undefined'); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.contains('usp=test'); - }); - - it('should pass us_privacy and gdpr strings', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, - { - gdprApplies: true, - consentString: 'test' - }, - { - consentString: 'test' - }); - expect(syncs).to.not.be.an('undefined'); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.contains('gdpr=1'); - expect(syncs[0].url).to.contains('usp=test'); - expect(syncs[0].url).to.equal('https://biddr.brealtime.com/check.html?gdpr=1&gdpr_consent=test&usp=test') - }); - - it('should pass gpp string and section id', function() { - const syncs = spec.getUserSyncs({iframeEnabled: true}, {}, {}, {}, { - gppString: 'abcdefgs', - applicableSections: [1, 2, 4] - }); - expect(syncs).to.not.be.an('undefined'); - expect(syncs[0].url).to.contains('gpp=abcdefgs') - expect(syncs[0].url).to.contains('gpp_sid=1,2,4') - }); - - it('should pass us_privacy and gdpr string and gpp string', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, - { - gdprApplies: true, - consentString: 'test' - }, - { - consentString: 'test' - }, - { - gppString: 'abcdefgs', - applicableSections: [1, 2, 4] - } - ); - expect(syncs).to.not.be.an('undefined'); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.contains('gdpr=1'); - expect(syncs[0].url).to.contains('usp=test'); - expect(syncs[0].url).to.contains('gpp=abcdefgs'); - expect(syncs[0].url).to.equal('https://biddr.brealtime.com/check.html?gdpr=1&gdpr_consent=test&usp=test&gpp=abcdefgs&gpp_sid=1,2,4'); - }); - }); -}); diff --git a/test/spec/modules/carodaBidAdapter_spec.js b/test/spec/modules/carodaBidAdapter_spec.js deleted file mode 100644 index 063294410..000000000 --- a/test/spec/modules/carodaBidAdapter_spec.js +++ /dev/null @@ -1,505 +0,0 @@ -// jshint esversion: 6, es3: false, node: true -import { assert } from 'chai'; -import { spec } from 'modules/carodaBidAdapter.js'; -import { config } from 'src/config.js'; -import { createEidsArray } from 'modules/userId/eids.js'; -import { setConfig as setCurrencyConfig } from '../../../modules/currency.js'; -import { addFPDToBidderRequest } from '../../helpers/fpd.js'; - -describe('Caroda adapter', function () { - let bids = []; - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'caroda', - 'params': { - 'ctok': 'adf232eef344' - } - }; - - it('should return true when required params found', function () { - assert(spec.isBidRequestValid(bid)); - - bid.params = { - ctok: 'adf232eef344', - placementId: 'someplacement' - }; - assert(spec.isBidRequestValid(bid)); - }); - - it('should return false when required params are missing', function () { - bid.params = {}; - assert.isFalse(spec.isBidRequestValid(bid)); - - bid.params = { - placementId: 'someplacement' - }; - assert.isFalse(spec.isBidRequestValid(bid)); - }); - }); - - describe('buildRequests', function () { - beforeEach(function () { - config.resetConfig(); - delete window.carodaPageViewId; - }); - it('should send request with minimal structure', function () { - const validBidRequests = [{ - bid_id: 'bidId', - params: { - 'ctok': 'adf232eef344' - } - }]; - window.top.carodaPageViewId = 12345; - const request = spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } })[0]; - assert.equal(request.method, 'POST'); - assert.equal(request.url, 'https://prebid.caroda.io/api/hb?entry_id=12345'); - assert.equal(request.options, undefined); - const data = JSON.parse(request.data) - assert.equal(data.ctok, 'adf232eef344'); - assert.ok(data.site); - assert.ok(data.hb_version); - assert.ok(data.device); - assert.equal(data.price_type, 'net'); - }); - - it('should add test to request, if test is set in parameters', function () { - const validBidRequests = [{ - bid_id: 'bidId', - params: { - 'ctok': 'adf232eef344', - 'test': 1 - } - }]; - window.top.carodaPageViewId = 12345; - const request = spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } })[0]; - const data = JSON.parse(request.data) - assert.equal(data.test, 1); - }); - - it('should add placement_id to request when available', function () { - const validBidRequests = [{ - bid_id: 'bidId', - params: { - 'ctok': 'adf232eef344', - 'placementId': 'opzafe342f' - } - }]; - window.top.carodaPageViewId = 12345; - const request = spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } })[0]; - const data = JSON.parse(request.data); - assert.equal(data.placement_id, 'opzafe342f'); - }); - - it('should send info about device', function () { - config.setConfig({ - device: { w: 100, h: 100 } - }); - const validBidRequests = [{ - bid_id: 'bidId', - params: { 'ctok': 'adf232eef344' } - }]; - const data = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } })[0].data); - assert.equal(data.device.ua, navigator.userAgent); - assert.equal(data.device.w, 100); - assert.equal(data.device.h, 100); - }); - - it('should pass supply chain object', function () { - const validBidRequests = [{ - bid_id: 'bidId', - params: {}, - ortb2: { - source: { - ext: { - schain: { - validation: 'strict', - config: { - ver: '1.0' - } - } - } - } - } - }]; - - const data = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } })[0].data); - assert.deepEqual(data.schain, { - validation: 'strict', - config: { - ver: '1.0' - } - }); - }); - - it('should send app info', function () { - config.setConfig({ - app: { id: 'appid' }, - }); - const ortb2 = { app: { name: 'appname' } }; - const validBidRequests = [{ - bid_id: 'bidId', - params: { mid: '1000' }, - ortb2 - }]; - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' }, ortb2 })[0].data); - assert.equal(request.app.id, 'appid'); - assert.equal(request.app.name, 'appname'); - assert.equal(request.site, undefined); - }); - - it('should send info about the site', function () { - config.setConfig({ - site: { - id: '123123', - publisher: { - domain: 'publisher.domain.com' - } - }, - }); - const ortb2 = { - site: { - publisher: { - name: 'publisher\'s name' - } - } - }; - const validBidRequests = [{ - bid_id: 'bidId', - params: { mid: '1000' }, - ortb2 - }]; - const refererInfo = { page: 'page' }; - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo, ortb2 })[0].data); - - assert.deepEqual(request.site, { - page: refererInfo.page, - publisher: { - domain: 'publisher.domain.com', - name: 'publisher\'s name' - }, - id: '123123' - }); - }); - - it('should send correct priceType value', function () { - const validBidRequests = [{ - bid_id: 'bidId', - params: { priceType: 'gross' } - }]; - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } })[0].data); - - assert.equal(request.price_type, 'gross'); - }); - - it('should send currency if defined', function () { - setCurrencyConfig({ adServerCurrency: 'EUR' }); - const validBidRequests = [{ params: {} }]; - const bidderRequest = { refererInfo: { page: 'page' } }; - return addFPDToBidderRequest(bidderRequest).then(res => { - const request = JSON.parse(spec.buildRequests(validBidRequests, res)[0].data); - assert.deepEqual(request.currency, 'EUR'); - setCurrencyConfig({}); - }); - }); - - it('should pass extended ids', function () { - const validBidRequests = [{ - bid_id: 'bidId', - params: {}, - userIdAsEids: [ - { source: 'adserver.org', uids: [ { id: 'TTD_ID_FROM_USER_ID_MODULE', atype: 1, ext: { rtiPartner: 'TDID' } } ] }, - { source: 'pubcid.org', uids: [ { id: 'pubCommonId_FROM_USER_ID_MODULE', atype: 1 } ] } - ] - }]; - - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } })[0].data); - assert.deepEqual(request.user.eids, validBidRequests[0].userIdAsEids); - }); - - describe('user privacy', function () { - it('should send GDPR Consent data to adform if gdprApplies', function () { - const validBidRequests = [{ bid_id: 'bidId', params: { test: 1 } }]; - const bidderRequest = { gdprConsent: { gdprApplies: true, consentString: 'consentDataString' }, refererInfo: { page: 'page' } }; - const request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest)[0].data); - - assert.equal(request.privacy.gdpr_consent, bidderRequest.gdprConsent.consentString); - assert.equal(request.privacy.gdpr, bidderRequest.gdprConsent.gdprApplies); - assert.equal(typeof request.privacy.gdpr, 'number'); - }); - - it('should send gdpr as number', function () { - const validBidRequests = [{ bid_id: 'bidId', params: { test: 1 } }]; - const bidderRequest = { gdprConsent: { gdprApplies: true, consentString: 'consentDataString' }, refererInfo: { page: 'page' } }; - const request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest)[0].data); - - assert.equal(typeof request.privacy.gdpr, 'number'); - assert.equal(request.privacy.gdpr, 1); - }); - - it('should send CCPA Consent data', function () { - const validBidRequests = [{ bid_id: 'bidId', params: { test: 1 } }]; - let bidderRequest = { uspConsent: '1YA-', refererInfo: { page: 'page' } }; - let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest)[0].data); - - assert.equal(request.privacy.us_privacy, '1YA-'); - - bidderRequest = { uspConsent: '1YA-', gdprConsent: { gdprApplies: true, consentString: 'consentDataString' }, refererInfo: { page: 'page' } }; - request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest)[0].data); - - assert.equal(request.privacy.us_privacy, '1YA-'); - assert.equal(request.privacy.gdpr_consent, 'consentDataString'); - assert.equal(request.privacy.gdpr, 1); - }); - - it('should not set coppa when coppa is not provided or is set to false', function () { - config.setConfig({ - }); - const validBidRequests = [{ bid_id: 'bidId', params: { test: 1 } }]; - const bidderRequest = { gdprConsent: { gdprApplies: true, consentString: 'consentDataString' }, refererInfo: { page: 'page' } }; - let request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest)[0].data); - - assert.equal(request.privacy.coppa, undefined); - - config.setConfig({ - coppa: false - }); - request = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest)[0].data); - - assert.equal(request.privacy.coppa, undefined); - }); - it('should set coppa to 1 when coppa is provided with value true', function () { - config.setConfig({ - coppa: true - }); - const validBidRequests = [{ bid_id: 'bidId', params: { test: 1 } }]; - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } })[0].data); - - assert.equal(request.privacy.coppa, 1); - }); - }); - - describe('bids', function () { - it('should be able to handle multiple bids', function () { - const validBidRequests = [{ - bid_id: 'bidId', - params: { ctok: 'ctok1' } - }, { - bid_id: 'bidId2', - params: { ctok: 'ctok2' } - }]; - const request = spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } }); - assert.equal(request.length, 2); - const data = request.map(r => JSON.parse(r.data)); - assert.equal(data[0].ctok, 'ctok1'); - assert.equal(data[1].ctok, 'ctok2'); - }); - - describe('price floors', function () { - it('should not add if floors module not configured', function () { - const validBidRequests = [{ bid_id: 'bidId', params: {ctok: 'ctok1'}, mediaTypes: {video: {}} }]; - const imp = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } })[0].data); - assert.equal(imp.bidfloor, undefined); - assert.equal(imp.bidfloorcur, undefined); - }); - - it('should not add if floor price not defined', function () { - const validBidRequests = [ getBidWithFloor() ]; - const imp = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } })[0].data); - assert.equal(imp.bidfloor, undefined); - assert.equal(imp.bidfloorcur, 'EUR'); - }); - - it('should request floor price in adserver currency', function () { - const validBidRequests = [ getBidWithFloor() ]; - setCurrencyConfig({ adServerCurrency: 'DKK' }); - const bidderRequest = { refererInfo: { page: 'page' } }; - return addFPDToBidderRequest(bidderRequest).then(res => { - const imp = JSON.parse(spec.buildRequests(validBidRequests, res)[0].data); - assert.equal(imp.bidfloor, undefined); - assert.equal(imp.bidfloorcur, 'DKK'); - setCurrencyConfig({}); - }); - }); - - it('should add correct floor values', function () { - const expectedFloors = [ 1, 1.3, 0.5 ]; - const validBidRequests = expectedFloors.map(getBidWithFloor); - const imps = spec - .buildRequests(validBidRequests, { refererInfo: { page: 'page' } }) - .map(r => JSON.parse(r.data)); - expectedFloors.forEach((floor, index) => { - assert.equal(imps[index].bidfloor, floor); - assert.equal(imps[index].bidfloorcur, 'EUR'); - }); - }); - - function getBidWithFloor(floor) { - return { - params: { ctok: 'ctok1' }, - mediaTypes: { video: {} }, - getFloor: ({ currency }) => { - return { - currency: currency, - floor - }; - } - }; - } - }); - - describe('multiple media types', function () { - it('should use all configured media types for bidding', function () { - const validBidRequests = [{ - bid_id: 'bidId', - params: { ctok: 'ctok1' }, - mediaTypes: { - banner: { - sizes: [[100, 100], [200, 300]] - }, - video: {} - } - }, { - bid_id: 'bidId2', - params: { ctok: 'ctok1' }, - mediaTypes: { - video: {}, - native: {} - } - }]; - const [ first, second ] = spec - .buildRequests(validBidRequests, { refererInfo: { page: 'page' } }) - .map(r => JSON.parse(r.data)); - - assert.ok(first.banner); - assert.ok(first.video); - - assert.ok(second.video); - assert.equal(second.banner, undefined); - }); - }); - - describe('banner', function () { - it('should convert sizes to openrtb format', function () { - const validBidRequests = [{ - bid_id: 'bidId', - params: { mid: 1000 }, - mediaTypes: { - banner: { - sizes: [[100, 100], [200, 300]] - } - } - }]; - const { banner } = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } })[0].data); - assert.deepEqual(banner, { - format: [ { w: 100, h: 100 }, { w: 200, h: 300 } ] - }); - }); - }); - - describe('video', function () { - it('should pass video mediatype config', function () { - const validBidRequests = [{ - bid_id: 'bidId', - params: { mid: 1000 }, - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'outstream', - mimes: ['video/mp4'] - } - } - }]; - const { video } = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { page: 'page' } })[0].data); - assert.deepEqual(video, { - playerSize: [640, 480], - context: 'outstream', - mimes: ['video/mp4'] - }); - }); - }); - }); - }); - - describe('interpretResponse', function () { - it('should return if no body in response', function () { - const serverResponse = {}; - const bidRequest = {}; - assert.ok(!spec.interpretResponse(serverResponse, bidRequest)); - }); - const basicBidResponse = () => ({ - bid_id: 'bidId', - cpm: 10, - creative_id: '12345', - currency: 'CZK', - w: 100, - h: 100, - ad: ' ({ - data: {}, - bids: [ - { - bid_id: 'bidId1', - params: { ctok: 'ctok1' } - }, - { - bid_id: 'bidId2', - params: { ctok: 'ctok2' } - } - ] - }); - it('should parse a typical ok response', function () { - const serverResponse = { - body: { ok: { value: JSON.stringify([basicBidResponse()]) } } - }; - bids = spec.interpretResponse(serverResponse, bidRequest()); - assert.equal(bids.length, 1); - assert.deepEqual(bids[0], - { - requestId: 'bidId', - cpm: 10, - creativeId: '12345', - ttl: 300, - netRevenue: true, - currency: 'CZK', - width: 100, - height: 100, - meta: { - advertiserDomains: [] - }, - ad: 'TEST', - adomain: ['clickonometrics.com'], - crid: '221', - w: 300, - h: 250, - ext: { - type: 'standard' - } - }, - { - id: '2e56e1af51a5d8_222', - impid: '2e56e1af51a5d8', - price: 5.68, - adid: '222', - adm: '', - adomain: ['clickonometrics.com'], - crid: '222', - w: 640, - h: 480, - ext: { - type: 'video' - } - } - ] - } - ], - cur: 'PLN', - ext: { - ttl: 5, - usersync: [ - { - type: 'image', - url: 'http://foo.sync?param=1' - }, - { - type: 'iframe', - url: 'http://foo.sync?param=2' - } - ] - } - }; - - describe('interpretResponse', function () { - it('Valid bid response - multi', function () { - const bidResponses = [ - { - requestId: '2e56e1af51a5d7', - cpm: 8.1, - width: 300, - height: 250, - creativeId: '221', - netRevenue: false, - ttl: 5, - currency: 'PLN', - ad: '', - meta: { - advertiserDomains: ['clickonometrics.com'] - } - }, - { - requestId: '2e56e1af51a5d8', - cpm: 5.68, - width: 640, - height: 480, - creativeId: '222', - netRevenue: false, - ttl: 5, - currency: 'PLN', - vastXml: '', - meta: { - advertiserDomains: ['clickonometrics.com'] - } - } - ]; - expect(spec.interpretResponse({body: response})).to.deep.have.same.members(bidResponses); - }); - - it('Valid bid response - single', function () { - delete response.seatbid[0].bid[1]; - const bidResponses = [ - { - requestId: '2e56e1af51a5d7', - cpm: 8.1, - width: 300, - height: 250, - creativeId: '221', - netRevenue: false, - ttl: 5, - currency: 'PLN', - ad: '', - meta: { - advertiserDomains: ['clickonometrics.com'] - } - } - ]; - expect(spec.interpretResponse({body: response})).to.deep.have.same.members(bidResponses); - }); - - it('Empty bid response', function () { - expect(spec.interpretResponse({})).to.be.empty; - }); - }); - - describe('getUserSyncs', function () { - it('Valid syncs - all', function () { - const syncOptions = { - iframeEnabled: true, - pixelEnabled: true - }; - - const expectedSyncs = [ - { - type: 'image', - url: 'http://foo.sync?param=1' - }, - { - type: 'iframe', - url: 'http://foo.sync?param=2' - } - ]; - expect(spec.getUserSyncs(syncOptions, [{body: response}])).to.deep.have.same.members(expectedSyncs); - }); - - it('Valid syncs - only image', function () { - const syncOptions = { - iframeEnabled: false, - pixelEnabled: true - }; - const expectedSyncs = [ - { - type: 'image', url: 'http://foo.sync?param=1' - } - ]; - expect(spec.getUserSyncs(syncOptions, [{body: response}])).to.deep.have.same.members(expectedSyncs); - }); - - it('Valid syncs - only iframe', function () { - const syncOptions = {iframeEnabled: true, pixelEnabled: false}; - const expectedSyncs = [ - { - type: 'iframe', url: 'http://foo.sync?param=2' - } - ]; - expect(spec.getUserSyncs(syncOptions, [{body: response}])).to.deep.have.same.members(expectedSyncs); - }); - - it('Valid syncs - empty', function () { - const syncOptions = {iframeEnabled: true, pixelEnabled: true}; - response.ext.usersync = {}; - expect(spec.getUserSyncs(syncOptions, [{body: response}])).to.be.empty; - }); - }); - - describe('mediaTypesVideoParams', function () { - it('Valid video mediaTypes', function () { - const bids = [ - { - adUnitCode: 'video', - auctionId: '0b9de793-8eda-481e-a548-c187d58b28d9', - bidId: '3u94t90ut39tt3t', - bidder: 'ccx', - bidderRequestId: '23ur20r239r2r', - mediaTypes: { - video: { - playerSize: [[640, 480]], - protocols: [2, 3, 5, 6], - mimes: ['video/mp4', 'video/x-flv'], - playbackmethod: [1, 2, 3, 4], - skip: 1, - skipafter: 5 - } - }, - params: { - placementId: 608 - }, - sizes: [[640, 480]], - transactionId: 'aefddd38-cfa0-48ab-8bdd-325de4bab5f9' - } - ]; - - const imps = [ - { - video: { - w: 640, - h: 480, - protocols: [2, 3, 5, 6], - mimes: ['video/mp4', 'video/x-flv'], - playbackmethod: [1, 2, 3, 4], - skip: 1, - skipafter: 5 - }, - id: '3u94t90ut39tt3t', - secure: 1, - ext: { - pid: 608 - } - } - ]; - - const bidsClone = utils.deepClone(bids); - - const response = spec.buildRequests(bidsClone, {'bids': bidsClone}); - const data = JSON.parse(response.data); - - expect(data.imp).to.deep.have.same.members(imps); - }); - }); - - describe('FLEDGE', function () { - it('should properly build a request when FLEDGE is enabled', async function () { - const bidderRequest = { - paapi: { - enabled: true - } - }; - const bids = [ - { - adUnitCode: 'banner', - auctionId: '0b9de793-8eda-481e-a548-aaaaaaaaaaa1', - bidId: '2e56e1af51ccc1', - bidder: 'ccx', - bidderRequestId: '17e7b9f58accc1', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 609 - }, - sizes: [[300, 250]], - transactionId: 'befddd38-cfa0-48ab-8bdd-bbbbbbbbbbb1', - ortb2Imp: { - ext: { - ae: 1 - } - } - } - ]; - - const ortbRequest = spec.buildRequests(bids, await addFPDToBidderRequest(bidderRequest)); - const data = JSON.parse(ortbRequest.data); - expect(data.imp[0].ext.ae).to.equal(1); - }); - - it('should properly build a request when FLEDGE is disabled', async function () { - const bidderRequest = { - paapi: { - enabled: false - } - }; - const bids = [ - { - adUnitCode: 'banner', - auctionId: '0b9de793-8eda-481e-a548-aaaaaaaaaaa2', - bidId: '2e56e1af51ccc2', - bidder: 'ccx', - bidderRequestId: '17e7b9f58accc2', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 610 - }, - sizes: [[300, 250]], - transactionId: 'befddd38-cfa0-48ab-8bdd-bbbbbbbbbbb2', - ortb2Imp: { - ext: { - ae: 1 - } - } - } - ]; - - const ortbRequest = spec.buildRequests(bids, await addFPDToBidderRequest(bidderRequest)); - const data = JSON.parse(ortbRequest.data); - expect(data.imp[0].ext.ae).to.be.undefined; - }); - }); -}); diff --git a/test/spec/modules/chromeAiRtdProvider_spec.js b/test/spec/modules/chromeAiRtdProvider_spec.js deleted file mode 100644 index c723eac63..000000000 --- a/test/spec/modules/chromeAiRtdProvider_spec.js +++ /dev/null @@ -1,393 +0,0 @@ -import * as chromeAiRtdProvider from 'modules/chromeAiRtdProvider.js'; -import * as utils from 'src/utils.js'; -import { config } from 'src/config.js'; -import * as storageManager from 'src/storageManager.js'; - -describe('Chrome AI RTD Provider', function() { - // Set up sandbox for all stubs - const sandbox = sinon.createSandbox(); - // Mock storage manager - const mockStorage = { - hasLocalStorage: sinon.stub(), - localStorageIsEnabled: sinon.stub(), - getDataFromLocalStorage: sinon.stub(), - setDataInLocalStorage: sinon.stub() - }; - - // Mock page URL for testing - const mockPageUrl = 'https://example.com/test-page'; - - // Mock Chrome AI API instances - let mockLanguageDetectorInstance; - let mockSummarizerInstance; - - // Mock API availability status - let mockLanguageDetectorAvailability; - let mockSummarizerAvailability; - - // Original globals - let originalLanguageDetector; - let originalSummarizer; - - // Stubs - let logMessageStub, logErrorStub; // Removed deepAccessStub, deepSetValueStub - let mockTopDocument; - let querySelectorStub; - - beforeEach(function() { - // Reset sandbox for each test - sandbox.reset(); - - // Save original globals - originalLanguageDetector = self.LanguageDetector; - originalSummarizer = self.Summarizer; - - // Create stubs - logMessageStub = sandbox.stub(utils, 'logMessage'); - logErrorStub = sandbox.stub(utils, 'logError'); - - // Stub storage manager - sandbox.stub(chromeAiRtdProvider, 'storage').get(() => mockStorage); - mockStorage.hasLocalStorage.returns(true); - mockStorage.localStorageIsEnabled.returns(true); - mockStorage.getDataFromLocalStorage.returns(null); // Default to no data - mockStorage.setDataInLocalStorage.returns(true); - - // Stub document properties - querySelectorStub = sandbox.stub(); - mockTopDocument = { - body: { textContent: 'Default page body text for testing.' }, - title: 'Test Page Title', - querySelector: querySelectorStub - }; - querySelectorStub.withArgs('article').returns(null); // Default: no article found - - sandbox.stub(utils, 'getWindowTop').returns({ - location: { href: mockPageUrl }, - document: mockTopDocument - }); - - // Create mock instances - mockLanguageDetectorInstance = { - detect: sandbox.stub().resolves([{ detectedLanguage: 'en', confidence: 0.9 }]), - ready: Promise.resolve(), - addEventListener: sandbox.stub() - }; - - mockSummarizerInstance = { - summarize: sandbox.stub().resolves('Test summary'), - ready: Promise.resolve(), - addEventListener: sandbox.stub() - }; - - // Reset mock availability to default values - mockLanguageDetectorAvailability = 'available'; - mockSummarizerAvailability = 'available'; - - // Mock global Chrome AI API constructors and their methods - // LanguageDetector - const MockLanguageDetectorFn = function() { /* This constructor body isn't called by the module */ }; - Object.defineProperty(MockLanguageDetectorFn, 'name', { value: 'LanguageDetector', configurable: true }); - MockLanguageDetectorFn.availability = sandbox.stub().resolves('available'); // Default to 'available' - MockLanguageDetectorFn.create = sandbox.stub().resolves(mockLanguageDetectorInstance); - self.LanguageDetector = MockLanguageDetectorFn; - - // Summarizer - const MockSummarizerFn = function() { /* This constructor body isn't called by the module */ }; - Object.defineProperty(MockSummarizerFn, 'name', { value: 'Summarizer', configurable: true }); - MockSummarizerFn.availability = sandbox.stub().resolves('available'); // Default to 'available' - MockSummarizerFn.create = sandbox.stub().resolves(mockSummarizerInstance); - self.Summarizer = MockSummarizerFn; - }); - - afterEach(function() { - // Restore original globals - if (originalLanguageDetector) { - self.LanguageDetector = originalLanguageDetector; - } else { - delete self.LanguageDetector; - } - - if (originalSummarizer) { - self.Summarizer = originalSummarizer; - } else { - delete self.Summarizer; - } - - // Restore sandbox - sandbox.restore(); - }); - - // Test basic module structure - describe('Module Structure', function() { - it('should have required methods', function() { - expect(chromeAiRtdProvider.chromeAiSubmodule.name).to.equal('chromeAi'); - expect(typeof chromeAiRtdProvider.chromeAiSubmodule.init).to.equal('function'); - expect(typeof chromeAiRtdProvider.chromeAiSubmodule.getBidRequestData).to.equal('function'); - }); - - it('should have the correct module name', function() { - expect(chromeAiRtdProvider.chromeAiSubmodule.name).to.equal('chromeAi'); - }); - - it('should have the correct constants', function() { - expect(chromeAiRtdProvider.CONSTANTS).to.be.an('object'); - expect(chromeAiRtdProvider.CONSTANTS.SUBMODULE_NAME).to.equal('chromeAi'); - expect(chromeAiRtdProvider.CONSTANTS.STORAGE_KEY).to.equal('chromeAi_detected_data'); - expect(chromeAiRtdProvider.CONSTANTS.MIN_TEXT_LENGTH).to.be.a('number'); - }); - }); - - // Test initialization - describe('Initialization (init function)', function() { - beforeEach(function() { - // Simulate empty localStorage for init tests - mockStorage.getDataFromLocalStorage.withArgs(chromeAiRtdProvider.CONSTANTS.STORAGE_KEY).returns(null); - // Reset call history for setDataInLocalStorage if needed, or ensure it's clean - mockStorage.setDataInLocalStorage.resetHistory(); - }); - - afterEach(function() { - // Clean up localStorage stubs if necessary, or reset to default behavior - mockStorage.getDataFromLocalStorage.withArgs(chromeAiRtdProvider.CONSTANTS.STORAGE_KEY).returns(null); // Reset to default for other describe blocks - mockStorage.setDataInLocalStorage.resetHistory(); - }); - - it('should handle LanguageDetector API unavailability (when availability() returns unavailable)', function() { - // Ensure LanguageDetector constructor itself is available (which it is by beforeEach setup) - // Configure its availability() method to return 'unavailable' for this test - sandbox.stub(chromeAiRtdProvider, 'getPrioritizedLanguageData').returns(null); - self.LanguageDetector.availability.resolves('unavailable'); - return chromeAiRtdProvider.chromeAiSubmodule.init({ params: { languageDetector: { enabled: true } } }).then(function(result) { - // The init might still resolve to true if other features (like summarizer if enabled & available) initialize successfully. - // We are checking that the specific error for LanguageDetector being unavailable is logged. - expect(logErrorStub.calledWith(sinon.match('ChromeAI-Rtd-Provider: LanguageDetector is unavailable.'))).to.be.true; - }); - }); - - it('should attempt language detection if no prior language data (default config)', async function() { - // Ensure getPrioritizedLanguageData returns null to force detection path - sandbox.stub(chromeAiRtdProvider, 'getPrioritizedLanguageData').returns(null); - - // Ensure getPageText returns valid text for detection - mockTopDocument.querySelector.withArgs('article').returns(null); - mockTopDocument.body.textContent = 'Sufficiently long text for detection.'; - - await chromeAiRtdProvider.chromeAiSubmodule.init({}); // Initialize with default config - - expect(logMessageStub.calledWith(sinon.match('Initializing with config'))).to.be.true; - // Check that the actual language detection was attempted - expect(mockLanguageDetectorInstance.detect.called).to.be.true; - }); - - it('should handle Summarizer API unavailability (when availability() returns unavailable)', function() { - self.Summarizer.availability.resolves('unavailable'); - - return chromeAiRtdProvider.chromeAiSubmodule.init({ params: { summarizer: { enabled: true } } }).then(function(result) { - expect(logErrorStub.calledWith(sinon.match('ChromeAI-Rtd-Provider: Summarizer is unavailable.'))).to.be.true; - // Init might still resolve to true if other features initialize successfully. - }); - }); - - it('should attempt model download if Summarizer availability is "after-download"', function() { - self.Summarizer.availability.resolves('after-download'); - - return chromeAiRtdProvider.chromeAiSubmodule.init({ params: { summarizer: { enabled: true } } }).then(() => { - expect(self.Summarizer.create.called).to.be.true; - expect(mockSummarizerInstance.addEventListener.calledWith('downloadprogress', sinon.match.func)).to.be.true; - }); - }); - - it('should return a promise', function() { - const result = chromeAiRtdProvider.chromeAiSubmodule.init({}); - expect(result).to.be.an.instanceof(Promise); - return result; // Ensure Mocha waits for the promise - }); - - it('should initialize with custom config', function() { - const customConfig = { - params: { - languageDetector: { - enabled: true, - ortb2Path: 'custom.language.path', - confidence: 0.7 - }, - summarizer: { - enabled: true, - ortb2Path: 'custom.keywords.path', - cacheInLocalStorage: true - } - } - }; - - return chromeAiRtdProvider.chromeAiSubmodule.init(customConfig).then(function(result) { - expect(typeof result).to.equal('boolean'); - expect(logMessageStub.calledWith(sinon.match('Initializing with config'))).to.be.true; - }); - }); - - it('should handle disabled features in config', function() { - const disabledConfig = { - params: { - languageDetector: { enabled: false }, - summarizer: { enabled: false } - } - }; - - return chromeAiRtdProvider.chromeAiSubmodule.init(disabledConfig).then(function(result) { - expect(result).to.be.true; - expect(logMessageStub.calledWith(sinon.match('Language detection disabled by config'))).to.be.true; - expect(logMessageStub.calledWith(sinon.match('Summarizer disabled by config.'))).to.be.true; - }); - }); - }); - - // Test storage functions - describe('Storage Functions', function() { - beforeEach(function() { - mockStorage.getDataFromLocalStorage.resetHistory(); - mockStorage.setDataInLocalStorage.resetHistory(); - mockStorage.setDataInLocalStorage.returns(true); // Default success - }); - - describe('chromeAiRtdProvider._getChromeAiDataFromLocalStorage', function() { - it('should return null if localStorage is not available', function() { - mockStorage.hasLocalStorage.returns(false); - expect(chromeAiRtdProvider._getChromeAiDataFromLocalStorage(mockPageUrl)).to.be.null; - }); - - it('should return null if localStorage is not enabled', function() { - mockStorage.localStorageIsEnabled.returns(false); - expect(chromeAiRtdProvider._getChromeAiDataFromLocalStorage(mockPageUrl)).to.be.null; - }); - - it('should return null if no data in localStorage for the URL', function() { - mockStorage.getDataFromLocalStorage.withArgs(chromeAiRtdProvider.CONSTANTS.STORAGE_KEY).returns(JSON.stringify({ 'other/url': {} })); - expect(chromeAiRtdProvider._getChromeAiDataFromLocalStorage(mockPageUrl)).to.be.null; - }); - }); - describe('chromeAiRtdProvider.storeDetectedKeywords', function() { - it('should return false if keywords are not provided or empty', function() { - expect(chromeAiRtdProvider.storeDetectedKeywords(null, mockPageUrl)).to.be.false; - expect(chromeAiRtdProvider.storeDetectedKeywords([], mockPageUrl)).to.be.false; - expect(logMessageStub.calledWith(sinon.match('No valid keywords array to store'))).to.be.true; - }); - }); - }); - - // Test language detection main function - describe('chromeAiRtdProvider.detectLanguage (main function)', function() { - it('should detect language using Chrome AI API', async function() { - const result = await chromeAiRtdProvider.detectLanguage('This is a test text'); - expect(result).to.deep.equal({ language: 'en', confidence: 0.9 }); - expect(mockLanguageDetectorInstance.detect.calledOnceWith('This is a test text')).to.be.true; - }); - - it('should return null if API is not available', async function() { - self.LanguageDetector.create.resolves(null); // Simulate API creation failure - const result = await chromeAiRtdProvider.detectLanguage('This is a test text'); - expect(result).to.be.null; - }); - - it('should return null if confidence is below threshold', async function() { - mockLanguageDetectorInstance.detect.resolves([{ detectedLanguage: 'en', confidence: 0.5 }]); - // Need to re-init to pick up the new default config confidence if it changed, or set it explicitly - await chromeAiRtdProvider.chromeAiSubmodule.init({ params: { languageDetector: { confidence: 0.8 } } }); - const result = await chromeAiRtdProvider.detectLanguage('This is a test text'); - expect(result).to.be.null; - }); - }); - // Test getBidRequestData - describe('getBidRequestData', function() { - let reqBidsConfigObj; - let onDoneSpy; - - beforeEach(async function() { - // Initialize the module with a config that enables both features for these tests - await chromeAiRtdProvider.chromeAiSubmodule.init({ - params: { - languageDetector: { enabled: true, ortb2Path: 'site.content.language' }, - summarizer: { enabled: true, ortb2Path: 'site.content.ext.keywords', cacheInLocalStorage: false } - } - }); - - reqBidsConfigObj = { - adUnits: [{ code: 'adunit1' }], - ortb2Fragments: { - global: {} - } - }; - onDoneSpy = sinon.spy(); - // Reset stubs that might be called by getBidRequestData indirectly via init or helper functions - logMessageStub.resetHistory(); - }); - - it('should call the callback function', function() { - chromeAiRtdProvider.chromeAiSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy); - expect(onDoneSpy.calledOnce).to.be.true; - }); - - it('should ensure ortb2Fragments.global exists', function() { - delete reqBidsConfigObj.ortb2Fragments.global; - chromeAiRtdProvider.chromeAiSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy); - expect(reqBidsConfigObj.ortb2Fragments.global).to.be.an('object'); - }); - - it('should not enrich language if already present in auction ORTB2', function() { - // Set language directly in ortb2Fragments for this test case - utils.deepSetValue(reqBidsConfigObj.ortb2Fragments.global, 'site.content.language', 'es'); - - chromeAiRtdProvider.chromeAiSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy); - - // Verify that the language was not changed - expect(utils.deepAccess(reqBidsConfigObj.ortb2Fragments.global, 'site.content.language')).to.equal('es'); - expect(logMessageStub.calledWith(sinon.match('Lang already in auction ORTB2 at path'))).to.be.true; - }); - - it('should enrich with detected keywords if not in auction ORTB2', async function() { - mockSummarizerInstance.summarize.resolves('newly detected summary'); - await chromeAiRtdProvider.chromeAiSubmodule.init({ // Re-init to trigger summarizer with mocks - params: { - summarizer: { enabled: true, ortb2Path: 'site.content.ext.keywords', cacheInLocalStorage: false }, - languageDetector: { enabled: false } // Disable lang to isolate test - } - }); - - chromeAiRtdProvider.chromeAiSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy); - expect(utils.deepAccess(reqBidsConfigObj.ortb2Fragments.global, 'site.content.ext.keywords')).to.deep.equal(['newly detected summary']); - }); - - it('should not enrich keywords if already present in auction ORTB2', function() { - // Set keywords directly in ortb2Fragments for this test case - utils.deepSetValue(reqBidsConfigObj.ortb2Fragments.global, 'site.content.ext.keywords', ['existing', 'keywords']); - - chromeAiRtdProvider.chromeAiSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy); - - // Verify that keywords were not changed - expect(utils.deepAccess(reqBidsConfigObj.ortb2Fragments.global, 'site.content.ext.keywords')).to.deep.equal(['existing', 'keywords']); - expect(logMessageStub.calledWith(sinon.match('Keywords already present in auction_ortb2 at path'))).to.be.true; - }); - - it('should handle language detection disabled', function() { - chromeAiRtdProvider.chromeAiSubmodule.init({ params: { languageDetector: { enabled: false } } }); // Re-init with lang disabled - chromeAiRtdProvider.chromeAiSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy); - expect(logMessageStub.calledWith(sinon.match('Language detection disabled, no lang enrichment.'))).to.be.true; - const langPath = chromeAiRtdProvider.CONSTANTS.DEFAULT_CONFIG.languageDetector.ortb2Path; - // Check that language was not set by trying to access it; it should be undefined or its original value if any - // This is a bit indirect. If we could spy on deepSetValue, it would be cleaner. - // For now, we assume if it's not set to the detected value, the non-enrichment path was taken. - // A more robust check would be to ensure no new properties were added if it was initially empty. - expect(utils.deepAccess(reqBidsConfigObj.ortb2Fragments.global, langPath)).to.be.undefined; - }); - - it('should handle summarizer disabled', function() { - chromeAiRtdProvider.chromeAiSubmodule.init({ params: { summarizer: { enabled: false } } }); // Re-init with summarizer disabled - chromeAiRtdProvider.chromeAiSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy); - expect(logMessageStub.calledWith(sinon.match('Summarizer disabled, no keyword enrichment.'))).to.be.true; - // Check that no keyword enrichment was attempted - const keywordPath = chromeAiRtdProvider.CONSTANTS.DEFAULT_CONFIG.summarizer.ortb2Path; // or the configured one - // Verify that keywords were not set by checking the path - expect(utils.deepAccess(reqBidsConfigObj.ortb2Fragments.global, keywordPath)).to.be.undefined; - }); - }); -}); diff --git a/test/spec/modules/chtnwBidAdapter_spec.js b/test/spec/modules/chtnwBidAdapter_spec.js deleted file mode 100644 index 70e39c440..000000000 --- a/test/spec/modules/chtnwBidAdapter_spec.js +++ /dev/null @@ -1,108 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/chtnwBidAdapter.js'; -import * as utils from '../../../src/utils.js'; - -describe('ChtnwAdapter', function () { - describe('isBidRequestValid', function () { - const bid = { - code: 'adunit-code', - bidder: 'chtnw', - params: { - placementId: '38EL412LO82XR9O6' - }, - sizes: [ - [300, 250] - ], - }; - - it('should return true when required params found', function () { - const bidRequest = utils.deepClone(bid); - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false when required params are missing', function () { - const bidRequest = utils.deepClone(bid); - delete bidRequest.params; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [{ - code: 'adunit-code', - bidder: 'chtnw', - params: { - placementId: '38EL412LO82XR9O6' - }, - sizes: [ - [300, 250] - ], - }]; - - let request; - before(() => { - request = spec.buildRequests(bidRequests); - }) - - it('Returns POST method', function () { - expect(request.method).to.equal('POST'); - }); - - it('Returns general data valid', function () { - const data = request.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('bids'); - expect(data).to.have.property('uuid'); - expect(data).to.have.property('device'); - expect(data).to.have.property('site'); - }); - }); - - describe('interpretResponse', function () { - const responseBody = [{ - 'requestId': 'test', - 'cpm': 0.5, - 'currency': 'USD', - 'width': 300, - 'height': 250, - 'netRevenue': true, - 'ttl': 60, - 'creativeId': 'AD', - 'ad': '

AD

', - 'mediaType': 'banner', - 'meta': { - 'advertiserDomains': [ - 'www.example.com' - ] - } - }]; - - it('handles empty bid response', function () { - const response = { - body: responseBody - }; - const result = spec.interpretResponse(response); - expect(result.length).to.not.equal(0); - expect(result[0].meta.advertiserDomains).to.be.an('array'); - }); - - it('handles empty bid response', function () { - const response = { - body: [] - }; - const result = spec.interpretResponse(response); - expect(result.length).to.equal(0); - }); - }); - - describe('getUserSyncs', function () { - it('should register type is image', function () { - const syncOptions = { - 'pixelEnabled': 'true' - } - const userSync = spec.getUserSyncs(syncOptions); - expect(userSync[0].type).to.equal('image'); - expect(userSync[0].url).to.have.string('ssp'); - }); - }); -}); diff --git a/test/spec/modules/cleanioRtdProvider_spec.js b/test/spec/modules/cleanioRtdProvider_spec.js deleted file mode 100644 index 99e52c154..000000000 --- a/test/spec/modules/cleanioRtdProvider_spec.js +++ /dev/null @@ -1,211 +0,0 @@ -import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; -import * as utils from '../../../src/utils.js'; -import * as hook from '../../../src/hook.js' -import * as events from '../../../src/events.js'; -import { EVENTS } from '../../../src/constants.js'; - -import { __CLEANIO_TEST__ } from '../../../modules/cleanioRtdProvider.js'; -import { MODULE_TYPE_RTD } from '../../../src/activities/modules.js'; - -const { - readConfig, - ConfigError, - pageInitStepPreloadScript, - pageInitStepProtectPage, - bidWrapStepAugmentHtml, - bidWrapStepProtectByWrapping, - beforeInit, -} = __CLEANIO_TEST__; - -sinon.assert.expose(chai.assert, { prefix: 'sinon' }); - -const fakeScriptURL = 'https://example.com/script.js'; - -function makeFakeBidResponse() { - return { - ad: 'hello ad', - bidderCode: 'BIDDER', - creativeId: 'CREATIVE', - cpm: 1.23, - }; -} - -describe('clean.io RTD module', function () { - describe('readConfig()', function() { - it('should throw ConfigError on invalid configurations', function() { - expect(() => readConfig({})).to.throw(ConfigError); - expect(() => readConfig({ params: {} })).to.throw(ConfigError); - expect(() => readConfig({ params: { protectionMode: 'bids' } })).to.throw(ConfigError); - expect(() => readConfig({ params: { cdnUrl: 'abc' } })).to.throw(ConfigError); - expect(() => readConfig({ params: { cdnUrl: 'abc', protectionMode: 'bids' } })).to.throw(ConfigError); - expect(() => readConfig({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: '123' } })).to.throw(ConfigError); - }); - - it('should accept valid configurations', function() { - expect(() => readConfig({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: 'full' } })).to.not.throw(); - expect(() => readConfig({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: 'bids' } })).to.not.throw(); - expect(() => readConfig({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: 'bids-nowait' } })).to.not.throw(); - }); - }); - - describe('Module initialization step', function() { - let insertElementStub; - beforeEach(function() { - insertElementStub = sinon.stub(utils, 'insertElement'); - }); - afterEach(function() { - utils.insertElement.restore(); - }); - - it('pageInitStepPreloadScript() should insert link/preload element', function() { - pageInitStepPreloadScript(fakeScriptURL); - - sinon.assert.calledOnce(insertElementStub); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.tagName === 'LINK')); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.rel === 'preload')); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.as === 'script')); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.href === fakeScriptURL)); - }); - - it('pageInitStepProtectPage() should insert script element', function() { - pageInitStepProtectPage(fakeScriptURL, 'clean.io'); - - sinon.assert.calledOnce(loadExternalScriptStub); - sinon.assert.calledWith(loadExternalScriptStub, fakeScriptURL, MODULE_TYPE_RTD, 'clean.io'); - }); - }); - - function ensurePrependToBidResponse(fakeBidResponse) { - expect(fakeBidResponse).to.have.own.property('ad').which.is.a('string'); - expect(fakeBidResponse.ad).to.contain(''); - } - - function ensureWrapBidResponse(fakeBidResponse, scriptUrl) { - expect(fakeBidResponse).to.have.own.property('ad').which.is.a('string'); - expect(fakeBidResponse.ad).to.contain(`src="${scriptUrl}"`); - expect(fakeBidResponse.ad).to.contain('agent.put(ad)'); - } - - describe('Bid processing step', function() { - it('bidWrapStepAugmentHtml() should prepend bid-specific information in a comment', function() { - const fakeBidResponse = makeFakeBidResponse(); - bidWrapStepAugmentHtml(fakeBidResponse); - ensurePrependToBidResponse(fakeBidResponse); - }); - - it('bidWrapStepProtectByWrapping() should wrap payload into a script tag', function() { - const fakeBidResponse = makeFakeBidResponse(); - bidWrapStepProtectByWrapping(fakeScriptURL, 0, fakeBidResponse); - ensureWrapBidResponse(fakeBidResponse, fakeScriptURL); - }); - }); - - describe('Submodule execution', function() { - let submoduleStub; - let insertElementStub; - beforeEach(function () { - submoduleStub = sinon.stub(hook, 'submodule'); - insertElementStub = sinon.stub(utils, 'insertElement'); - }); - afterEach(function () { - utils.insertElement.restore(); - submoduleStub.restore(); - }); - - function getModule() { - beforeInit(); - - expect(submoduleStub.calledOnceWith('realTimeData')).to.equal(true); - - const registeredSubmoduleDefinition = submoduleStub.getCall(0).args[1]; - expect(registeredSubmoduleDefinition).to.be.an('object'); - expect(registeredSubmoduleDefinition).to.have.own.property('name', 'clean.io'); - expect(registeredSubmoduleDefinition).to.have.own.property('init').that.is.a('function'); - expect(registeredSubmoduleDefinition).to.have.own.property('onBidResponseEvent').that.is.a('function'); - - return registeredSubmoduleDefinition; - } - - it('should register clean.io RTD submodule provider', function () { - getModule(); - }); - - it('should refuse initialization with incorrect parameters', function () { - const { init } = getModule(); - expect(init({ params: { cdnUrl: 'abc', protectionMode: 'full' } }, {})).to.equal(false); // too short distribution name - sinon.assert.notCalled(loadExternalScriptStub); - }); - - it('should initialize in full (page) protection mode', function () { - const { init, onBidResponseEvent } = getModule(); - expect(init({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: 'full' } }, {})).to.equal(true); - sinon.assert.calledOnce(loadExternalScriptStub); - sinon.assert.calledWith(loadExternalScriptStub, 'https://abc1234567890.cloudfront.net/script.js', MODULE_TYPE_RTD, 'clean.io'); - - const fakeBidResponse = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse, {}, {}); - ensurePrependToBidResponse(fakeBidResponse); - }); - - it('should iniitalize in bids (frame) protection mode', function () { - const { init, onBidResponseEvent } = getModule(); - expect(init({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: 'bids' } }, {})).to.equal(true); - sinon.assert.calledOnce(insertElementStub); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.tagName === 'LINK')); - - const fakeBidResponse = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse, {}, {}); - ensureWrapBidResponse(fakeBidResponse, 'https://abc1234567890.cloudfront.net/script.js'); - }); - - it('should respect preload status in bids-nowait protection mode', function () { - const { init, onBidResponseEvent } = getModule(); - expect(init({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: 'bids-nowait' } }, {})).to.equal(true); - sinon.assert.calledOnce(insertElementStub); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.tagName === 'LINK')); - const preloadLink = insertElementStub.getCall(0).args[0]; - expect(preloadLink).to.have.property('onload').which.is.a('function'); - expect(preloadLink).to.have.property('onerror').which.is.a('function'); - - const fakeBidResponse1 = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse1, {}, {}); - ensurePrependToBidResponse(fakeBidResponse1); - - // Simulate successful preloading - preloadLink.onload(); - - const fakeBidResponse2 = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse2, {}, {}); - ensureWrapBidResponse(fakeBidResponse2, 'https://abc1234567890.cloudfront.net/script.js'); - - // Simulate error - preloadLink.onerror(); - - // Now we should fallback to just prepending - const fakeBidResponse3 = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse3, {}, {}); - ensurePrependToBidResponse(fakeBidResponse3); - }); - - it('should send billable event per bid won event', function () { - const { init } = getModule(); - expect(init({ params: { cdnUrl: 'https://abc1234567890.cloudfront.net/script.js', protectionMode: 'full' } }, {})).to.equal(true); - - const eventCounter = { registerCleanioBillingEvent: function() {} }; - sinon.spy(eventCounter, 'registerCleanioBillingEvent'); - - events.on(EVENTS.BILLABLE_EVENT, (evt) => { - if (evt.vendor === 'clean.io') { - eventCounter.registerCleanioBillingEvent() - } - }); - - events.emit(EVENTS.BID_WON, {}); - events.emit(EVENTS.BID_WON, {}); - events.emit(EVENTS.BID_WON, {}); - events.emit(EVENTS.BID_WON, {}); - - sinon.assert.callCount(eventCounter.registerCleanioBillingEvent, 4); - }); - }); -}); diff --git a/test/spec/modules/clickforceBidAdapter_spec.js b/test/spec/modules/clickforceBidAdapter_spec.js deleted file mode 100644 index 42b0f6e50..000000000 --- a/test/spec/modules/clickforceBidAdapter_spec.js +++ /dev/null @@ -1,201 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/clickforceBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; - -describe('ClickforceAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'clickforce', - 'params': { - 'zone': '6682' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250] - ], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'someIncorrectParam': 0 - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [{ - 'bidder': 'clickforce', - 'params': { - 'zone': '6682' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250] - ], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - }]; - - const request = spec.buildRequests(bidRequests); - - it('sends bid request to our endpoint via POST', function () { - expect(request.method).to.equal('POST'); - }); - }); - - describe('interpretResponse', function () { - const response = [{ - 'cpm': 0.5, - 'width': '300', - 'height': '250', - 'callback_uid': '220ed41385952a', - 'type': 'Default Ad', - 'tag': '', - 'creativeId': '1f99ac5c3ef10a4097499a5686b30aff-6682', - 'requestId': '220ed41385952a', - 'currency': 'USD', - 'ttl': 60, - 'netRevenue': true, - 'zone': '6682', - 'adomain': [ - 'www.example.com' - ] - }]; - - const response1 = [{ - 'cpm': 0.0625, - 'width': '3', - 'height': '3', - 'callback_uid': '2e27ec595bf1a', - 'type': 'public Bid', - 'tag': { - 'content': { - 'title': 'title', - 'content': 'content', - 'advertiser': 'advertiser', - 'button_text': 'button_text', - 'image': 'image', - 'icon': 'icon' - }, - 'cu': ['cu'], - 'iu': ['iu'], - 'p': '6878:11062:32586:8380573788dad9b9fc17edde444c4dcf:2795' - }, - 'creativeId': '8380573788dad9b9fc17edde444c4dcf-6878', - 'requestId': '2e27ec595bf1a', - 'currency': 'USD', - 'ttl': 60, - 'netRevenue': true, - 'zone': '6878' - }]; - - const expectedResponse = [{ - 'requestId': '220ed41385952a', - 'cpm': 0.5, - 'width': '300', - 'height': '250', - 'creativeId': '1f99ac5c3ef10a4097499a5686b30aff-6682', - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 60, - 'ad': '', - 'mediaType': 'banner', - 'meta': { - 'advertiserDomains': [ - 'www.example.com' - ] - } - }]; - - const expectedResponse1 = [{ - 'requestId': '2e27ec595bf1a', - 'cpm': 0.0625, - 'width': '3', - 'height': '3', - 'creativeId': '8380573788dad9b9fc17edde444c4dcf-6878', - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 60, - 'mediaType': 'native', - 'native': { - 'image': { - 'url': 'image', - 'width': 1600, - 'height': 900 - }, - 'title': 'title', - 'sponsoredBy': 'advertiser', - 'body': 'content', - 'icon': { - 'url': 'icon', - 'width': 900, - 'height': 900 - }, - 'clickUrl': 'cu', - 'impressionTrackers': ['iu'] - }, - 'meta': { - 'advertiserDomains': [] - } - }]; - - it('should get the correct bid response by display ad', function () { - let bidderRequest; - const result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - - it('should get the correct bid response by native ad', function () { - let bidderRequest; - const result = spec.interpretResponse({ body: response1 }, {bidderRequest}); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse1[0])); - }); - - it('handles empty bid response', function () { - const response = { - body: {} - }; - const result = spec.interpretResponse(response); - expect(result.length).to.equal(0); - }); - }); - - describe('getUserSyncs function', function () { - it('should register type is iframe', function () { - const syncOptions = { - 'iframeEnabled': 'true' - } - const userSync = spec.getUserSyncs(syncOptions); - expect(userSync[0].type).to.equal('iframe'); - expect(userSync[0].url).to.equal('https://cdn.holmesmind.com/js/capmapping.htm'); - }); - - it('should register type is image', function () { - const syncOptions = { - 'pixelEnabled': 'true' - } - const userSync = spec.getUserSyncs(syncOptions); - expect(userSync[0].type).to.equal('image'); - expect(userSync[0].url).to.equal('https://c.holmesmind.com/cm'); - }); - }); -}); diff --git a/test/spec/modules/codefuelBidAdapter_spec.js b/test/spec/modules/codefuelBidAdapter_spec.js deleted file mode 100644 index 4e891c8ce..000000000 --- a/test/spec/modules/codefuelBidAdapter_spec.js +++ /dev/null @@ -1,326 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/codefuelBidAdapter.js'; -import {config} from 'src/config.js'; -import * as utils from 'src/utils.js'; -import {server} from 'test/mocks/xhr'; - -const USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/92.0.4515.159 Safari/537.36'; -const DEFAULT_USER_AGENT = window.navigator.userAgent; -const setUADefault = () => { window.navigator.__defineGetter__('userAgent', function () { return DEFAULT_USER_AGENT }) }; -const setUAMock = () => { window.navigator.__defineGetter__('userAgent', function () { return USER_AGENT }) }; - -describe('Codefuel Adapter', function () { - let sandbox; - beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - afterEach(() => { - sandbox.restore(); - }) - describe('Bid request and response', function () { - const commonBidRequest = { - bidder: 'codefuel', - params: { - publisher: { - id: 'publisher-id' - }, - }, - bidId: '2d6815a92ba1ba', - auctionId: '12043683-3254-4f74-8934-f941b085579e', - } - const nativeBidRequestParams = { - nativeParams: { - image: { - required: true, - sizes: [ - 120, - 100 - ], - sendId: true - }, - title: { - required: true, - sendId: true - }, - sponsoredBy: { - required: false - } - }, - } - - const displayBidRequestParams = { - sizes: [ - [ - 300, - 250 - ] - ] - } - - describe('isBidRequestValid', function () { - before(() => { - config.setConfig({ - codefuel: { - bidderUrl: 'https://bidder-url.com', - } - } - ) - }) - after(() => { - config.resetConfig() - }) - - it('should fail when bid is invalid', function () { - const bid = { - bidder: 'codefuel', - params: { - publisher: { - id: 'publisher-id', - } - }, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - it('should not succeed when bid contains native params', function () { - const bid = { - bidder: 'codefuel', - params: { - publisher: { - id: 'publisher-id', - } - }, - ...nativeBidRequestParams, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - it('should not succeed when bid contains only sizes', function () { - const bid = { - bidder: 'codefuel', - params: { - publisher: { - id: 'publisher-id', - } - }, - ...displayBidRequestParams, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - it('should fail if publisher id is not set', function () { - const bid = { - bidder: 'codefuel', - ...nativeBidRequestParams, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - - it('should fail if bidder url is not set', function () { - const bid = { - bidder: 'codefuel', - params: { - publisher: { - id: 'publisher-id', - } - }, - ...nativeBidRequestParams, - } - config.resetConfig() - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - }) - - describe('buildRequests', function () { - before(() => { - setUAMock() - config.setConfig({ - codefuel: { - bidderUrl: 'https://bidder-url.com', - } - } - ) - }) - after(() => { - config.resetConfig() - setUADefault() - }) - - const commonBidderRequest = { - timeout: 500, - bidderRequestId: 'mock-uuid', - auctionId: '12043683-3254-4f74-8934-f941b085579e', - refererInfo: { - page: 'https://example.com/', - domain: 'example.com' - } - } - - it('should build display request', function () { - const bidRequest = { - ...commonBidRequest, - ...displayBidRequestParams, - } - const expectedData = { - cur: [ - 'USD' - ], - device: { - devicetype: 2, - ua: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/92.0.4515.159 Safari/537.36' - }, - id: 'mock-uuid', - imp: [ - { - banner: { - format: [ - { - h: 250, - w: 300 - } - ] - }, - id: '1' - } - ], - site: { - domain: 'example.com', - page: 'https://example.com/', - publisher: { - id: 'publisher-id' - } - }, - source: { - fd: 1 - }, - tmax: 500 - } - const res = spec.buildRequests([bidRequest], commonBidderRequest) - expect(res.url).to.equal('https://ai-p-codefuel-ds-rtb-us-east-1-k8s.seccint.com/prebid') - expect(res.data).to.deep.equal(expectedData) - }) - - it('should pass bidder timeout', function () { - const bidRequest = { - ...commonBidRequest, - } - const bidderRequest = { - ...commonBidderRequest, - timeout: 500 - } - const res = spec.buildRequests([bidRequest], bidderRequest) - const resData = res.data - expect(resData.tmax).to.equal(500) - }); - }) - - describe('interpretResponse', function () { - it('should return empty array if no valid bids', function () { - const res = spec.interpretResponse({}, []) - expect(res).to.be.an('array').that.is.empty - }); - - it('should interpret display response', function () { - const serverResponse = { - body: { - id: '6b2eedc8-8ff5-46ef-adcf-e701b508943e', - seatbid: [ - { - bid: [ - { - id: 'd90fe7fa-28d7-11eb-8ce4-462a842a7cf9', - impid: '1', - price: 1.1, - nurl: 'http://example.com/win/${AUCTION_PRICE}', - adm: '
ad
', - adomain: [ - 'example.com' - ], - cid: '3865084', - crid: '29998660', - cat: [ - 'IAB10-2' - ], - w: 300, - h: 250 - } - ], - seat: 'acc-6536' - } - ], - bidid: 'd90fe7fa-28d7-11eb-8ce4-13d94bfa26f9', - cur: 'USD' - } - } - const request = { - bids: [ - { - ...commonBidRequest, - ...displayBidRequestParams - } - ] - } - const expectedRes = [ - { - requestId: request.bids[0].bidId, - cpm: 1.1, - creativeId: '29998660', - ttl: 360, - netRevenue: true, - currency: 'USD', - mediaType: 'banner', - ad: '
ad
', - width: 300, - height: 250, - meta: {'advertiserDomains': []} - } - ] - - const res = spec.interpretResponse(serverResponse, request) - expect(res).to.deep.equal(expectedRes) - }); - }) - }) - - describe('getUserSyncs', function () { - const usersyncUrl = 'https://usersync-url.com'; - beforeEach(() => { - config.setConfig({ - codefuel: { - usersyncUrl: usersyncUrl, - } - } - ) - }) - after(() => { - config.resetConfig() - }) - - it('should not return user sync if pixel enabled with codefuel config', function () { - const ret = spec.getUserSyncs({pixelEnabled: true}) - expect(ret).to.be.an('array').that.is.empty - }) - - it('should not return user sync if pixel disabled', function () { - const ret = spec.getUserSyncs({pixelEnabled: false}) - expect(ret).to.be.an('array').that.is.empty - }) - - it('should not return user sync if url is not set', function () { - config.resetConfig() - const ret = spec.getUserSyncs({pixelEnabled: true}) - expect(ret).to.be.an('array').that.is.empty - }) - - it('should not pass GDPR consent', function() { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, undefined)).to.to.be.an('array').that.is.empty - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: false, consentString: 'foo'}, undefined)).to.be.an('array').that.is.empty - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: true, consentString: undefined}, undefined)).to.be.an('array').that.is.empty - }); - - it('should not pass US consent', function() { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, undefined, '1NYN')).to.be.an('array').that.is.empty - }); - - it('should pass GDPR and US consent', function() { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, '1NYN')).to.be.an('array').that.is.empty - }); - }) -}) diff --git a/test/spec/modules/cointrafficBidAdapter_spec.js b/test/spec/modules/cointrafficBidAdapter_spec.js deleted file mode 100644 index e90216d96..000000000 --- a/test/spec/modules/cointrafficBidAdapter_spec.js +++ /dev/null @@ -1,341 +0,0 @@ -import sinon from 'sinon' -import { expect } from 'chai'; -import { spec } from 'modules/cointrafficBidAdapter.js'; -import { config } from 'src/config.js' -import * as utils from 'src/utils.js' - -/** - * @typedef {import('../src/adapters/bidderFactory.js').BidRequest} BidRequest - * @typedef {import('../src/adapters/bidderFactory.js').BidderRequest} BidderRequest - */ - -const ENDPOINT_URL = 'https://apps-pbd.ctraffic.io/pb/tmp'; - -describe('cointrafficBidAdapter', function () { - describe('isBidRequestValid', function () { - /** @type {BidRequest} */ - const bidRequest = { - bidder: 'cointraffic', - params: { - placementId: 'testPlacementId' - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250] - ], - bidId: 'bidId12345', - bidderRequestId: 'bidderRequestId12345', - auctionId: 'auctionId12345' - }; - - it('should return true where required params found', function () { - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - }); - - describe('buildRequests', function () { - /** @type {BidRequest[]} */ - const bidRequests = [ - { - bidder: 'cointraffic', - params: { - placementId: 'testPlacementId' - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250] - ], - bidId: 'bidId12345', - bidderRequestId: 'bidderRequestId12345', - auctionId: 'auctionId12345' - }, - { - bidder: 'cointraffic', - params: { - placementId: 'testPlacementId' - }, - adUnitCode: 'adunit-code2', - sizes: [ - [300, 250] - ], - bidId: 'bidId67890"', - bidderRequestId: 'bidderRequestId67890', - auctionId: 'auctionId12345' - } - ]; - - /** @type {BidderRequest} */ - const bidderRequest = { - refererInfo: { - numIframes: 0, - reachedTop: true, - referer: 'https://example.com', - stack: [ - 'https://example.com' - ] - } - }; - - it('replaces currency with EUR if there is no currency provided', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request[0].data.currency).to.equal('EUR'); - expect(request[1].data.currency).to.equal('EUR'); - }); - - it('replaces currency with EUR if there is no currency provided', function () { - const getConfigStub = sinon.stub(config, 'getConfig').callsFake( - arg => arg === 'currency.bidderCurrencyDefault.cointraffic' ? 'USD' : 'EUR' - ); - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request[0].data.currency).to.equal('USD'); - expect(request[1].data.currency).to.equal('USD'); - - getConfigStub.restore(); - }); - - it('throws an error if currency provided in params is not allowed', function () { - const utilsMock = sinon.mock(utils) - utilsMock.expects('logError').twice() - const getConfigStub = sinon.stub(config, 'getConfig').callsFake( - arg => arg === 'currency.bidderCurrencyDefault.cointraffic' ? 'BTC' : 'EUR' - ); - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request[0]).to.undefined; - expect(request[1]).to.undefined; - - utilsMock.restore() - getConfigStub.restore(); - }); - - it('sends bid request to our endpoint via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request[0].method).to.equal('POST'); - expect(request[1].method).to.equal('POST'); - }); - - it('attaches source and version to endpoint URL as query params', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request[0].url).to.equal(ENDPOINT_URL); - expect(request[1].url).to.equal(ENDPOINT_URL); - }); - }); - - describe('interpretResponse', function () { - it('should get the correct bid response', function () { - /** @type {BidRequest[]} */ - const bidRequest = [{ - method: 'POST', - url: ENDPOINT_URL, - data: { - placementId: 'testPlacementId', - device: 'desktop', - currency: 'EUR', - sizes: ['300x250'], - bidId: 'bidId12345', - referer: 'www.example.com' - } - }]; - - const serverResponse = { - body: { - requestId: 'bidId12345', - cpm: 3.9, - currency: 'EUR', - netRevenue: true, - width: 300, - height: 250, - creativeId: 'creativeId12345', - ttl: 90, - ad: '

I am an ad

', - mediaType: 'banner', - adomain: ['test.com'] - } - }; - - const expectedResponse = [{ - requestId: 'bidId12345', - cpm: 3.9, - currency: 'EUR', - netRevenue: true, - width: 300, - height: 250, - creativeId: 'creativeId12345', - ttl: 90, - ad: '

I am an ad

', - meta: { - mediaType: 'banner', - advertiserDomains: [ - 'test.com', - ] - } - }]; - - const result = spec.interpretResponse(serverResponse, bidRequest[0]); - expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); - }); - - it('should get the correct bid response without advertiser domains specified', function () { - /** @type {BidRequest[]} */ - const bidRequest = [{ - method: 'POST', - url: ENDPOINT_URL, - data: { - placementId: 'testPlacementId', - device: 'desktop', - currency: 'EUR', - sizes: ['300x250'], - bidId: 'bidId12345', - referer: 'www.example.com' - } - }]; - - const serverResponse = { - body: { - requestId: 'bidId12345', - cpm: 3.9, - currency: 'EUR', - netRevenue: true, - width: 300, - height: 250, - creativeId: 'creativeId12345', - ttl: 90, - ad: '

I am an ad

', - mediaType: 'banner', - } - }; - - const expectedResponse = [{ - requestId: 'bidId12345', - cpm: 3.9, - currency: 'EUR', - netRevenue: true, - width: 300, - height: 250, - creativeId: 'creativeId12345', - ttl: 90, - ad: '

I am an ad

', - meta: { - mediaType: 'banner', - advertiserDomains: [] - } - }]; - - const result = spec.interpretResponse(serverResponse, bidRequest[0]); - expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); - }); - - it('should get the correct bid response with different currency', function () { - /** @type {BidRequest[]} */ - const bidRequest = [{ - method: 'POST', - url: ENDPOINT_URL, - data: { - placementId: 'testPlacementId', - device: 'desktop', - currency: 'USD', - sizes: ['300x250'], - bidId: 'bidId12345', - referer: 'www.example.com' - } - }]; - - const serverResponse = { - body: { - requestId: 'bidId12345', - cpm: 3.9, - currency: 'USD', - netRevenue: true, - width: 300, - height: 250, - creativeId: 'creativeId12345', - ttl: 90, - ad: '

I am an ad

', - mediaType: 'banner', - adomain: ['test.com'] - } - }; - - const expectedResponse = [{ - requestId: 'bidId12345', - cpm: 3.9, - currency: 'USD', - netRevenue: true, - width: 300, - height: 250, - creativeId: 'creativeId12345', - ttl: 90, - ad: '

I am an ad

', - meta: { - mediaType: 'banner', - advertiserDomains: [ - 'test.com', - ] - } - }]; - - const getConfigStub = sinon.stub(config, 'getConfig').returns('USD'); - - const result = spec.interpretResponse(serverResponse, bidRequest[0]); - expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); - - getConfigStub.restore(); - }); - - it('should get empty bid response requested currency is not available', function () { - /** @type {BidRequest[]} */ - const bidRequest = [{ - method: 'POST', - url: ENDPOINT_URL, - data: { - placementId: 'testPlacementId', - device: 'desktop', - currency: 'BTC', - sizes: ['300x250'], - bidId: 'bidId12345', - referer: 'www.example.com' - } - }]; - - const serverResponse = {}; - - const expectedResponse = []; - - const getConfigStub = sinon.stub(config, 'getConfig').returns('BTC'); - - const result = spec.interpretResponse(serverResponse, bidRequest[0]); - expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); - - getConfigStub.restore(); - }); - - it('should get empty bid response if no server response', function () { - /** @type {BidRequest[]} */ - const bidRequest = [{ - method: 'POST', - url: ENDPOINT_URL, - data: { - placementId: 'testPlacementId', - device: 'desktop', - currency: 'EUR', - sizes: ['300x250'], - bidId: 'bidId12345', - referer: 'www.example.com' - } - }]; - - const serverResponse = {}; - - const expectedResponse = []; - - const result = spec.interpretResponse(serverResponse, bidRequest[0]); - expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); - }); - }); -}); diff --git a/test/spec/modules/coinzillaBidAdapter_spec.js b/test/spec/modules/coinzillaBidAdapter_spec.js deleted file mode 100644 index 08d6c8aed..000000000 --- a/test/spec/modules/coinzillaBidAdapter_spec.js +++ /dev/null @@ -1,123 +0,0 @@ -import {assert, expect} from 'chai'; -import {spec} from 'modules/coinzillaBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; - -const ENDPOINT_URL = 'https://request.czilladx.com/serve/request.php'; - -describe('coinzillaBidAdapter', function () { - const adapter = newBidder(spec); - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'coinzilla', - 'params': { - placementId: 'testPlacementId' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250] - ], - 'bidId': '1234asdf1234', - 'bidderRequestId': '1234asdf1234asdf', - 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf120' - }; - it('should return true where required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - describe('buildRequests', function () { - const bidRequests = [ - { - 'bidder': 'coinzilla', - 'params': { - placementId: 'testPlacementId' - }, - 'sizes': [ - [300, 250] - ], - 'bidId': '23beaa6af6cdde', - 'bidderRequestId': '19c0c1efdf37e7', - 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', - }, - { - 'bidder': 'coinzilla', - 'params': { - placementId: 'testPlacementId' - }, - 'adUnitCode': 'adunit-code2', - 'sizes': [ - [300, 250] - ], - 'bidId': '382091349b149f"', - 'bidderRequestId': '1f9c98192de251', - 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', - } - ]; - - const bidderRequests = { - 'refererInfo': { - 'numIframes': 0, - 'reachedTop': true, - 'referer': 'https://example.com', - 'stack': ['https://example.com'] - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequests); - it('sends bid request to our endpoint via POST', function () { - expect(request[0].method).to.equal('POST'); - expect(request[1].method).to.equal('POST'); - }); - it('attaches source and version to endpoint URL as query params', function () { - expect(request[0].url).to.equal(ENDPOINT_URL); - expect(request[1].url).to.equal(ENDPOINT_URL); - }); - }); - - describe('interpretResponse', function () { - const bidRequest = [ - { - 'method': 'POST', - 'url': ENDPOINT_URL, - 'data': { - 'placementId': 'testPlacementId', - 'width': '300', - 'height': '200', - 'bidId': 'bidId123', - 'referer': 'www.example.com' - } - } - ]; - const serverResponse = { - body: { - 'ad': '

I am an ad

', - 'cpm': 4.2, - 'creativeId': '12345asdfg', - 'currency': 'EUR', - 'statusMessage': 'Bid available', - 'requestId': 'bidId123', - 'width': 300, - 'height': 250, - 'netRevenue': true, - 'mediaType': 'banner', - 'advertiserDomain': ['none.com'] - } - }; - it('should get the correct bid response', function () { - const expectedResponse = [{ - 'requestId': 'bidId123', - 'cpm': 4.2, - 'width': 300, - 'height': 250, - 'creativeId': '12345asdfg', - 'currency': 'EUR', - 'netRevenue': true, - 'ttl': 3000, - 'ad': '

I am an ad

', - 'mediaType': 'banner', - 'meta': {'advertiserDomains': ['none.com']} - }]; - const result = spec.interpretResponse(serverResponse, bidRequest[0]); - expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); - }); - }); -}); diff --git a/test/spec/modules/colombiaBidAdapter_spec.js b/test/spec/modules/colombiaBidAdapter_spec.js deleted file mode 100644 index c4e00351f..000000000 --- a/test/spec/modules/colombiaBidAdapter_spec.js +++ /dev/null @@ -1,278 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/colombiaBidAdapter'; -import { newBidder } from 'src/adapters/bidderFactory'; -import * as ajaxLib from 'src/ajax.js'; - -const HOST_NAME = document.location.protocol + '//' + window.location.host; -const ENDPOINT = 'https://ade.clmbtech.com/cde/prebid.htm'; - -describe('colombiaBidAdapter', function () { - const adapter = newBidder(spec); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'colombia', - 'params': { - placementId: '307466' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250] - ], - 'bidId': '23beaa6af6cdde', - 'bidderRequestId': '19c0c1efdf37e7', - 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when placementId not passed correctly', function () { - bid.params.placementId = ''; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when require params are not passed', function () { - const invalidBid = Object.assign({}, bid); - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - 'bidder': 'colombia', - 'params': { - placementId: '307466' - }, - 'adUnitCode': 'adunit-code1', - 'sizes': [ - [300, 250] - ], - 'bidId': '23beaa6af6cdde', - 'bidderRequestId': '19c0c1efdf37e7', - 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', - }, - { - 'bidder': 'colombia', - 'params': { - placementId: '307466' - }, - 'adUnitCode': 'adunit-code2', - 'sizes': [ - [300, 250] - ], - 'bidId': '382091349b149f"', - 'bidderRequestId': '"1f9c98192de2511"', - 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', - } - ]; - const bidderRequest = { - refererInfo: { - numIframes: 0, - reachedTop: true, - referer: 'http://example.com', - stack: ['http://example.com'] - } - }; - - const request = spec.buildRequests(bidRequests); - it('sends bid request to our endpoint via POST', function () { - expect(request[0].method).to.equal('POST'); - }); - - it('attaches source and version to endpoint URL as query params', function () { - expect(request[0].url).to.equal(ENDPOINT); - }); - }); - - describe('interpretResponse', function () { - const bidRequest = [ - { - 'method': 'POST', - 'url': 'https://ade.clmbtech.com/cde/prebid.htm', - 'data': { - 'v': 'hb1', - 'p': '307466', - 'w': '300', - 'h': '250', - 'cb': 12892917383, - 'r': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836', - 'uid': '23beaa6af6cdde', - 't': 'i', - } - } - ]; - - const serverResponse = [{ - 'ad': '
This is test case for colombia adapter
', - 'cpm': 3.14, - 'creativeId': '6b958110-612c-4b03-b6a9-7436c9f746dc-1sk24', - 'currency': 'USD', - 'requestId': '23beaa6af6cdde', - 'width': 728, - 'height': 90, - 'netRevenue': true, - 'ttl': 600, - 'dealid': '', - 'referrer': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836' - }]; - - it('should get the correct bid response', function () { - const expectedResponse = [{ - 'requestId': '23beaa6af6cdde', - 'cpm': 3.14, - 'width': 728, - 'height': 90, - 'creativeId': '6b958110-612c-4b03-b6a9-7436c9f746dc-1sk24', - 'dealId': '', - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'referrer': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836', - 'ad': '
This is test case for colombia adapter
' - }]; - const result = spec.interpretResponse(serverResponse, bidRequest[0]); - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); - }); - - it('handles empty bid response', function () { - const response = { - body: { - 'uid': '23beaa6af6cdde', - 'height': 0, - 'creativeId': '', - 'statusMessage': 'Bid returned empty or error response', - 'width': 0, - 'cpm': 0 - } - }; - const result = spec.interpretResponse(response, bidRequest[0]); - expect(result.length).to.equal(0); - }); - }); - describe('onBidWon', function () { - let ajaxStub; - beforeEach(() => { - ajaxStub = sinon.stub(ajaxLib, 'ajax'); - }); - - afterEach(() => { - ajaxStub.restore(); - }); - - it('should call ajax with correct URL and encoded evtData when event 500 is present', function () { - const bid = { - eventTrackers: [{ - event: 500, - method: 500, - url: 'https://ade.clmbtech.com/cde/bidNotify.htm' - }], - ext: { - evtData: 'd_1_%7B%22iId%22%3A%22abc123-impr-id%22%2C%22aId%22%3A%22ad5678%22%2C%22ci%22%3A%22call-id-789%22%2C%22fpc%22%3A%22some-fpc-value%22%2C%22prebid%22%3A1%7D' - } - }; - spec.onBidWon(bid); - expect(ajaxStub.calledOnce).to.be.true; - const [url, , data, options] = ajaxStub.firstCall.args; - expect(url).to.equal('https://ade.clmbtech.com/cde/bidNotify.htm'); - const parsedPayload = JSON.parse(data); - expect(parsedPayload).to.deep.equal({ - bidNotifyType: 1, - evt: 'd_1_%7B%22iId%22%3A%22abc123-impr-id%22%2C%22aId%22%3A%22ad5678%22%2C%22ci%22%3A%22call-id-789%22%2C%22fpc%22%3A%22some-fpc-value%22%2C%22prebid%22%3A1%7D' - }); - expect(options).to.deep.include({ - method: 'POST', - withCredentials: false - }); - }); - it('should not call ajax if eventTrackers is missing or event 500 not present', function () { - spec.onBidWon({}); - spec.onBidWon({ eventTrackers: [{ event: 200 }] }); - - expect(ajaxStub.notCalled).to.be.true; - }); - }); - describe('onTimeout', function () { - let ajaxStub; - - beforeEach(function () { - ajaxStub = sinon.stub(ajaxLib, 'ajax'); - }); - - afterEach(function () { - ajaxStub.restore(); - }); - - it('should call ajax with correct payload and pubAdCodeNames from gpid', function () { - const timeoutData = [ - { - ortb2Imp: { - ext: { - gpid: 'abc#123' - } - } - }, - { - ortb2Imp: { - ext: { - gpid: 'def#456' - } - } - }, - { - ortb2Imp: { - ext: { - gpid: 'ghi#789' - } - } - } - ]; - - spec.onTimeout(timeoutData); - - expect(ajaxStub.calledOnce).to.be.true; - - const [url, , data, options] = ajaxStub.firstCall.args; - - expect(url).to.equal('https://ade.clmbtech.com/cde/bidNotify.htm'); - - const parsedPayload = JSON.parse(data); - expect(parsedPayload).to.deep.equal({ - bidNotifyType: 2, - pubAdCodeNames: 'abc,def,ghi' - }); - - expect(options).to.deep.include({ - method: 'POST', - withCredentials: false - }); - }); - - it('should not call ajax if timeoutData is null or empty', function () { - spec.onTimeout(null); - spec.onTimeout([]); - - expect(ajaxStub.notCalled).to.be.true; - }); - - it('should skip entries without valid gpid', function () { - const timeoutData = [ - { ortb2Imp: { ext: { gpid: 'valid#123' } } }, - { ortb2Imp: { ext: {} } }, - { ortb2Imp: {} }, - {}, - ]; - - spec.onTimeout(timeoutData); - - expect(ajaxStub.calledOnce).to.be.true; - const [, , data] = ajaxStub.firstCall.args; - const parsed = JSON.parse(data); - - expect(parsed.pubAdCodeNames).to.equal('valid'); - }); - }); -}); diff --git a/test/spec/modules/colossussspBidAdapter_spec.js b/test/spec/modules/colossussspBidAdapter_spec.js deleted file mode 100644 index 9c92661fd..000000000 --- a/test/spec/modules/colossussspBidAdapter_spec.js +++ /dev/null @@ -1,459 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/colossussspBidAdapter.js'; - -describe('ColossussspAdapter', function () { - const bid = { - bidId: '2dd581a2b6281d', - bidder: 'colossusssp', - bidderRequestId: '145e1d6a7837c9', - params: { - placement_id: 0, - group_id: 0 - }, - placementCode: 'placementid_0', - auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - ortb2Imp: { - ext: { - tid: '3bb2f6da-87a6-4029-aeb0-bfe951372e62', - gpid: '/19968336/prebid_cache_video_adunit', - data: {} - } - }, - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'example.com', - sid: '0', - hp: 1, - rid: 'bidrequestid', - // name: 'alladsallthetime', - domain: 'example.com' - } - ] - } - } - } - } - }; - const bidderRequest = { - bidderCode: 'colossus', - auctionId: 'fffffff-ffff-ffff-ffff-ffffffffffff', - bidderRequestId: 'ffffffffffffff', - start: 1472239426002, - auctionStart: 1472239426000, - timeout: 5000, - uspConsent: '1YN-', - gdprConsent: { - consentString: 'xxx', - gdprApplies: 1 - }, - refererInfo: { - referer: 'http://www.example.com', - reachedTop: true, - }, - ortb2: { - app: { - name: 'myappname', - keywords: 'power tools, drills', - content: { - data: [ - { - name: 'www.dataprovider1.com', - ext: { - segtax: 6 - }, - segment: [ - { - id: '687' - }, - { - id: '123' - } - ] - }, - { - name: 'www.dataprovider1.com', - ext: { - segtax: 7 - }, - segment: [ - { - id: '456' - }, - { - id: '789' - } - ] - } - ] - } - }, - site: { - name: 'example', - domain: 'page.example.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'], - page: 'https://page.example.com/here.html', - ref: 'https://ref.example.com', - keywords: 'power tools, drills', - search: 'drill', - content: { - userrating: '4', - data: [{ - name: 'www.dataprovider1.com', - ext: { - segtax: 7, - cids: ['iris_c73g5jq96mwso4d8'] - }, - segment: [ - { id: '687' }, - { id: '123' } - ] - }] - }, - ext: { - data: { - pageType: 'article', - category: 'repair' - } - } - }, - user: { - yob: 1985, - gender: 'm', - keywords: 'a,b', - data: [{ - name: 'dataprovider.com', - ext: { segtax: 4 }, - segment: [ - { id: '1' } - ] - }], - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - } - }, - bids: [bid] - } - - describe('isBidRequestValid', function () { - it('Should return true when placement_id can be cast to a number', function () { - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - it('Should return false when placement_id is not a number', function () { - bid.params.placement_id = 'aaa'; - delete bid.params.group_id; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests([bid], bidderRequest); - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://colossusssp.com/?c=o&m=multi'); - }); - it('Should contain ccpa', function () { - expect(serverRequest.data.ccpa).to.be.an('string') - }) - - it('Returns valid data if array of bids is valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements', 'ccpa', 'gdpr_consent', 'gdpr_require', 'userObj', 'siteObj', 'appObj'); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - const placements = data['placements']; - for (let i = 0; i < placements.length; i++) { - const placement = placements[i]; - expect(placement).to.have.all.keys('placementId', 'groupId', 'eids', 'bidId', 'traffic', 'sizes', 'schain', 'floor', 'gpid', 'tid'); - expect(placement.schain).to.be.an('object') - expect(placement.placementId).to.be.a('number'); - expect(placement.groupId).to.be.a('number'); - expect(placement.bidId).to.be.a('string'); - expect(placement.traffic).to.be.a('string'); - expect(placement.sizes).to.be.an('array'); - expect(placement.floor).to.be.an('object'); - expect(placement.gpid).to.be.an('string'); - expect(placement.tid).to.be.an('string'); - } - }); - - it('Returns valid video data if array of bids is valid', function () { - const videoBid = { - ...bid, - params: { - placement_id: 0, - }, - mediaTypes: { - video: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - } - } - const serverRequest = spec.buildRequests([videoBid], bidderRequest); - - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'language', 'secure', 'host', 'page', 'placements', 'ccpa', 'gdpr_consent', 'gdpr_require', 'userObj', 'siteObj', 'appObj'); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - const placements = data['placements']; - for (let i = 0; i < placements.length; i++) { - const placement = placements[i]; - expect(placement).to.have.all.keys('placementId', 'groupId', 'eids', 'bidId', 'traffic', 'schain', 'floor', 'gpid', 'sizes', - 'playerSize', 'minduration', 'maxduration', 'mimes', 'protocols', 'startdelay', 'placement', 'skip', 'skipafter', - 'minbitrate', 'maxbitrate', 'delivery', 'playbackmethod', 'api', 'linearity', 'tid' - ); - expect(placement.schain).to.be.an('object') - expect(placement.placementId).to.be.a('number'); - expect(placement.bidId).to.be.a('string'); - expect(placement.traffic).to.be.a('string'); - expect(placement.floor).to.be.an('object'); - expect(placement.gpid).to.be.an('string'); - expect(placement.sizes).to.be.an('array'); - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - expect(placement.tid).to.be.an('string'); - } - }); - - it('Returns empty data if no valid requests are passed', function () { - serverRequest = spec.buildRequests([], bidderRequest); - const data = serverRequest.data; - expect(data.placements).to.be.an('array').that.is.empty; - }); - }); - - describe('buildRequests with user ids', function () { - var clonedBid = JSON.parse(JSON.stringify(bid)); - clonedBid.userId = {} - clonedBid.userId.idl_env = 'idl_env123'; - clonedBid.userId.tdid = 'tdid123'; - clonedBid.userId.id5id = { uid: 'id5id123' }; - clonedBid.userId.uid2 = { id: 'uid2id123' }; - clonedBid.userIdAsEids = [ - { - 'source': 'pubcid.org', - 'uids': [ - { - 'id': '4679e98e-1d83-4718-8aba-aa88hhhaaa', - 'atype': 1 - } - ] - }, - { - 'source': 'adserver.org', - 'uids': [ - { - 'id': 'e804908e-57b4-4f46-a097-08be44321e79', - 'atype': 1, - 'ext': { - 'rtiPartner': 'TDID' - } - } - ] - }, - { - 'source': 'neustar.biz', - 'uids': [ - { - 'id': 'E1:Bvss1x8hXM2zHeqiqj2umJUziavSvLT6E_ORri5fDCsZb-5sfD18oNWycTmdx6QBNdbURBVv466hLJiKSwHCaTxvROo8smjqj6GfvlKfzQI', - 'atype': 1 - } - ] - } - ]; - const serverRequest = spec.buildRequests([clonedBid], bidderRequest); - it('Returns valid data if array of bids is valid', function () { - const data = serverRequest.data; - const placements = data['placements']; - expect(data).to.be.an('object'); - for (let i = 0; i < placements.length; i++) { - const placement = placements[i]; - expect(placement).to.have.property('eids') - expect(placement.eids).to.be.an('array') - expect(placement.eids.length).to.be.equal(7) - for (const index in placement.eids) { - const v = placement.eids[index]; - expect(v).to.have.all.keys('source', 'uids') - expect(v.source).to.be.oneOf(['pubcid.org', 'adserver.org', 'neustar.biz', 'identityLink', 'id5-sync.com', 'adserver.org', 'uidapi.com']) - expect(v.uids).to.be.an('array'); - expect(v.uids.length).to.be.equal(1) - expect(v.uids[0]).to.have.property('id') - } - } - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests([bid], bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests([bid], bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - const resObject = { - body: [{ - requestId: '123', - mediaType: 'banner', - cpm: 0.3, - width: 320, - height: 50, - ad: '

Hello ad

', - ttl: 1000, - creativeId: '123asd', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - let serverResponses = spec.interpretResponse(resObject); - it('Returns an array of valid server responses if response object is valid', function () { - expect(serverResponses).to.be.an('array').that.is.not.empty; - for (let i = 0; i < serverResponses.length; i++) { - const dataItem = serverResponses[i]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'mediaType', 'meta'); - expect(dataItem.requestId).to.be.a('string'); - expect(dataItem.cpm).to.be.a('number'); - expect(dataItem.width).to.be.a('number'); - expect(dataItem.height).to.be.a('number'); - expect(dataItem.ad).to.be.a('string'); - expect(dataItem.ttl).to.be.a('number'); - expect(dataItem.creativeId).to.be.a('string'); - expect(dataItem.netRevenue).to.be.a('boolean'); - expect(dataItem.currency).to.be.a('string'); - expect(dataItem.mediaType).to.be.a('string'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - } - it('Returns an empty array if invalid response is passed', function () { - serverResponses = spec.interpretResponse('invalid_response'); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - const videoResObject = { - body: [{ - requestId: '123', - mediaType: 'video', - cpm: 0.3, - width: 320, - height: 50, - vastUrl: '', - ttl: 1000, - creativeId: '123asd', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - let videoServerResponses = spec.interpretResponse(videoResObject); - it('Returns an array of valid server video responses if response object is valid', function () { - expect(videoServerResponses).to.be.an('array').that.is.not.empty; - for (let i = 0; i < videoServerResponses.length; i++) { - const dataItem = videoServerResponses[i]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'mediaType', 'meta'); - expect(dataItem.requestId).to.be.a('string'); - expect(dataItem.cpm).to.be.a('number'); - expect(dataItem.width).to.be.a('number'); - expect(dataItem.height).to.be.a('number'); - expect(dataItem.vastUrl).to.be.a('string'); - expect(dataItem.ttl).to.be.a('number'); - expect(dataItem.creativeId).to.be.a('string'); - expect(dataItem.netRevenue).to.be.a('boolean'); - expect(dataItem.currency).to.be.a('string'); - expect(dataItem.mediaType).to.be.a('string'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - } - it('Returns an empty array if invalid response is passed', function () { - videoServerResponses = spec.interpretResponse('invalid_response'); - expect(videoServerResponses).to.be.an('array').that.is.empty; - }); - }); - }); - - describe('onBidWon', function () { - it('should make an ajax call', function () { - const bid = { - nurl: 'http://example.com/win', - }; - expect(spec.onBidWon(bid)).to.equals(undefined); - }); - }) - - describe('getUserSyncs', function () { - const userSync = spec.getUserSyncs({}, {}, { consentString: 'xxx', gdprApplies: 1 }, { consentString: '1YN-' }); - it('Returns valid URL and type', function () { - expect(userSync).to.be.an('array').with.lengthOf(1); - expect(userSync[0].type).to.exist; - expect(userSync[0].url).to.exist; - expect(userSync[0].type).to.be.equal('image'); - expect(userSync[0].url).to.be.equal('https://sync.colossusssp.com/image?pbjs=1&gdpr=0&gdpr_consent=xxx&ccpa_consent=1YN-&coppa=0'); - }); - }); -}); diff --git a/test/spec/modules/compassBidAdapter_spec.js b/test/spec/modules/compassBidAdapter_spec.js deleted file mode 100644 index 8d0e1cc57..000000000 --- a/test/spec/modules/compassBidAdapter_spec.js +++ /dev/null @@ -1,517 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/compassBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; -import { config } from '../../../src/config.js'; - -const bidder = 'compass'; - -describe('CompassBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://sa-lb.deliverimp.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = config.runWithBidder(bidder, () => spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {})); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sa-cs.deliverimp.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = config.runWithBidder(bidder, () => spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - })); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sa-cs.deliverimp.com/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = config.runWithBidder(bidder, () => spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - })); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sa-cs.deliverimp.com/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/conceptxBidAdapter_spec.js b/test/spec/modules/conceptxBidAdapter_spec.js deleted file mode 100644 index 8e9bd2f8c..000000000 --- a/test/spec/modules/conceptxBidAdapter_spec.js +++ /dev/null @@ -1,124 +0,0 @@ -// import or require modules necessary for the test, e.g.: -import { expect } from 'chai'; // may prefer 'assert' in place of 'expect' -import { spec } from 'modules/conceptxBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -// import { config } from 'src/config.js'; - -describe('conceptxBidAdapter', function () { - const URL = 'https://conceptx.cncpt-central.com/openrtb'; - - const ENDPOINT_URL = `${URL}`; - const ENDPOINT_URL_CONSENT = `${URL}?gdpr_applies=true&consentString=ihaveconsented`; - const adapter = newBidder(spec); - - const bidderRequests = [ - { - bidId: '123', - bidder: 'conceptx', - params: { - site: 'example', - adunit: 'some-id-3' - }, - mediaTypes: { - banner: { - sizes: [[930, 180]], - } - }, - } - ] - - const singleBidRequest = { - bid: [ - { - bidId: '123', - } - ] - } - - const serverResponse = { - body: { - 'bidResponses': [ - { - 'ads': [ - { - 'referrer': 'http://localhost/prebidpage_concept_bidder.html', - 'ttl': 360, - 'html': '

DUMMY

', - 'requestId': '214dfadd1f8826', - 'cpm': 46, - 'currency': 'DKK', - 'width': 930, - 'height': 180, - 'creativeId': 'FAKE-ID', - 'meta': { - 'mediaType': 'banner' - }, - 'netRevenue': true, - 'destinationUrls': { - 'destination': 'https://concept.dk' - } - } - ], - 'matchedAdCount': 1, - 'targetId': '214dfadd1f8826' - } - ] - } - } - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bidderRequests[0])).to.equal(true); - }); - }); - - describe('buildRequests', function () { - it('Test requests', function () { - const request = spec.buildRequests(bidderRequests, {}); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('data'); - const bid = JSON.parse(request[0].data).adUnits[0] - expect(bid.site).to.equal('example'); - expect(bid.adunit).to.equal('some-id-3'); - expect(JSON.stringify(bid.dimensions)).to.equal(JSON.stringify([ - [930, 180]])); - }); - }); - - describe('user privacy', function () { - it('should NOT send GDPR Consent data if gdprApplies equals undefined', function () { - const request = spec.buildRequests(bidderRequests, { gdprConsent: { gdprApplies: undefined, consentString: 'iDoNotConsent' } }); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expect(request[0].url).to.equal(ENDPOINT_URL); - }); - it('should send GDPR Consent data if gdprApplies', function () { - const request = spec.buildRequests(bidderRequests, { gdprConsent: { gdprApplies: true, consentString: 'ihaveconsented' } }); - expect(request.length).to.equal(1); - expect(request[0]).to.have.property('url') - expect(request[0].url).to.equal(ENDPOINT_URL_CONSENT); - }); - }); - - describe('interpretResponse', function () { - it('should return valid response when passed valid server response', function () { - const interpretedResponse = spec.interpretResponse(serverResponse, singleBidRequest); - const ad = serverResponse.body.bidResponses[0].ads[0] - expect(interpretedResponse).to.have.lengthOf(1); - expect(interpretedResponse[0].cpm).to.equal(ad.cpm); - expect(interpretedResponse[0].width).to.equal(Number(ad.width)); - expect(interpretedResponse[0].height).to.equal(Number(ad.height)); - expect(interpretedResponse[0].creativeId).to.equal(ad.creativeId); - expect(interpretedResponse[0].currency).to.equal(ad.currency); - expect(interpretedResponse[0].netRevenue).to.equal(true); - expect(interpretedResponse[0].ad).to.equal(ad.html); - expect(interpretedResponse[0].ttl).to.equal(360); - }); - }); -}); diff --git a/test/spec/modules/concertAnalyticsAdapter_spec.js b/test/spec/modules/concertAnalyticsAdapter_spec.js deleted file mode 100644 index 639011ac4..000000000 --- a/test/spec/modules/concertAnalyticsAdapter_spec.js +++ /dev/null @@ -1,151 +0,0 @@ -import concertAnalytics from 'modules/concertAnalyticsAdapter.js'; -import { expect } from 'chai'; -import {expectEvents} from '../../helpers/analytics.js'; -import { EVENTS } from 'src/constants.js'; -import { server } from 'test/mocks/xhr.js'; - -import sinon from 'sinon'; -const adapterManager = require('src/adapterManager').default; -const events = require('src/events'); - -describe('ConcertAnalyticsAdapter', function() { - let sandbox; - let clock; - const timestamp = 1896134400; - const auctionId = '9f894496-10fe-4652-863d-623462bf82b8'; - const timeout = 1000; - - before(function () { - sandbox = sinon.createSandbox(); - clock = sandbox.useFakeTimers(1896134400); - }); - - after(function () { - clock.restore(); - sandbox.restore(); - }); - - describe('track', function() { - beforeEach(function () { - sandbox.stub(events, 'getEvents').returns([]); - - adapterManager.enableAnalytics({ - provider: 'concert' - }); - }); - - afterEach(function () { - events.getEvents.restore(); - concertAnalytics.eventsStorage = []; - concertAnalytics.disableAnalytics(); - }); - - it('should catch all events', function() { - sandbox.spy(concertAnalytics, 'track'); - expectEvents().to.beTrackedBy(concertAnalytics.track); - }); - - it('should report data for BID_RESPONSE, BID_WON events', function() { - fireBidEvents(events); - clock.tick(3000 + 1000); - - const eventsToReport = ['bidResponse', 'bidWon']; - for (let i = 0; i < concertAnalytics.eventsStorage.length; i++) { - expect(eventsToReport.indexOf(concertAnalytics.eventsStorage[i].event)).to.be.above(-1); - } - - for (let i = 0; i < eventsToReport.length; i++) { - expect(concertAnalytics.eventsStorage.some(function(event) { - return event.event === eventsToReport[i] - })).to.equal(true); - } - }); - - it('should report data in the shape expected by analytics endpoint', function() { - fireBidEvents(events); - clock.tick(3000 + 1000); - - const requiredFields = ['event', 'concert_rid', 'adId', 'auctionId', 'creativeId', 'position', 'url', 'cpm', 'width', 'height', 'timeToRespond']; - - for (var i = 0; i < requiredFields.length; i++) { - expect(concertAnalytics.eventsStorage[0]).to.have.property(requiredFields[i]); - } - }); - }); - - const adUnits = [{ - code: 'desktop_leaderboard_variable', - sizes: [[1030, 590]], - mediaTypes: { - banner: { - sizes: [[1030, 590]] - } - }, - bids: [ - { - bidder: 'concert', - params: { - partnerId: 'test_partner' - } - } - ] - }]; - - const bidResponse = { - 'bidderCode': 'concert', - 'width': 1030, - 'height': 590, - 'statusMessage': 'Bid available', - 'adId': '642f13fe18ab7dc', - 'requestId': '4062fba2e039919', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 6, - 'ad': '', - 'ttl': 360, - 'creativeId': '138308483085|62bac030-a5d3-11ea-b3be-55590c8153a5', - 'netRevenue': false, - 'currency': 'USD', - 'originalCpm': 6, - 'originalCurrency': 'USD', - 'auctionId': '9f894496-10fe-4652-863d-623462bf82b8', - 'responseTimestamp': 1591213790366, - 'requestTimestamp': 1591213790017, - 'bidder': 'concert', - 'adUnitCode': 'desktop_leaderboard_variable', - 'timeToRespond': 349, - 'status': 'rendered', - 'params': [ - { - 'partnerId': 'cst' - } - ] - } - - const bidWon = { - 'adId': '642f13fe18ab7dc', - 'mediaType': 'banner', - 'requestId': '4062fba2e039919', - 'cpm': 6, - 'creativeId': '138308483085|62bac030-a5d3-11ea-b3be-55590c8153a5', - 'currency': 'USD', - 'netRevenue': false, - 'ttl': 360, - 'auctionId': '9f894496-10fe-4652-863d-623462bf82b8', - 'statusMessage': 'Bid available', - 'responseTimestamp': 1591213790366, - 'requestTimestamp': 1591213790017, - 'bidder': 'concert', - 'adUnitCode': 'desktop_leaderboard_variable', - 'sizes': [[1030, 590]], - 'size': [1030, 590] - } - - function fireBidEvents(events) { - events.emit(EVENTS.AUCTION_INIT, { timestamp, auctionId, timeout, adUnits }); - events.emit(EVENTS.BID_REQUESTED, { bidder: 'concert' }); - events.emit(EVENTS.BID_RESPONSE, bidResponse); - events.emit(EVENTS.AUCTION_END, {}); - events.emit(EVENTS.BID_WON, bidWon); - } -}); diff --git a/test/spec/modules/concertBidAdapter_spec.js b/test/spec/modules/concertBidAdapter_spec.js deleted file mode 100644 index 6c842e58d..000000000 --- a/test/spec/modules/concertBidAdapter_spec.js +++ /dev/null @@ -1,308 +0,0 @@ -import { expect } from 'chai'; -import sinon from 'sinon'; -import { spec, storage } from 'modules/concertBidAdapter.js'; -import { hook } from 'src/hook.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -describe('ConcertAdapter', function () { - let bidRequests; - let bidRequest; - let bidResponse; - let element; - let sandbox; - - before(function () { - hook.ready(); - }); - - beforeEach(function () { - element = { - x: 0, - y: 0, - width: 0, - height: 0, - getBoundingClientRect: () => { - return { - width: element.width, - height: element.height, - - left: element.x, - top: element.y, - right: element.x + element.width, - bottom: element.y + element.height - }; - } - }; - - getGlobal().bidderSettings = { - concert: { - storageAllowed: true - } - }; - - bidRequests = [ - { - bidder: 'concert', - params: { - partnerId: 'foo', - slotType: 'fizz' - }, - adUnitCode: 'desktop_leaderboard_variable', - bidId: 'foo', - ortb2Imp: { - ext: { - tid: '' - } - }, - sizes: [[1030, 590]] - } - ]; - - bidRequest = { - refererInfo: { - page: 'https://www.google.com' - }, - uspConsent: '1YN-', - gdprConsent: {}, - gppConsent: {} - }; - - bidResponse = { - body: { - bids: [ - { - bidId: '16d2e73faea32d9', - cpm: '6', - width: '1030', - height: '590', - ad: '', - ttl: '360', - creativeId: '123349|a7d62700-a4bf-11ea-829f-ad3b0b7a9383', - netRevenue: false, - currency: 'USD' - } - ] - } - } - - sandbox = sinon.createSandbox(); - sandbox.stub(document, 'getElementById').withArgs('desktop_leaderboard_variable').returns(element) - }); - - afterEach(function () { - getGlobal().bidderSettings = {}; - sandbox.restore(); - }); - - describe('spec.isBidRequestValid', function() { - it('should return when it received all the required params', function() { - const bid = bidRequests[0]; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when partner id is missing', function() { - const bid = { - bidder: 'concert', - params: {} - } - - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('spec.buildRequests', function() { - it('should build a payload object with the shape expected by server', function() { - const request = spec.buildRequests(bidRequests, bidRequest); - const payload = JSON.parse(request.data); - expect(payload).to.have.property('meta'); - expect(payload).to.have.property('slots'); - - const metaRequiredFields = [ - 'prebidVersion', - 'pageUrl', - 'screen', - 'debug', - 'uid', - 'optedOut', - 'adapterVersion', - 'uspConsent', - 'gdprConsent', - 'gppConsent', - 'browserLanguage', - 'tdid' - ]; - const slotsRequiredFields = ['name', 'bidId', 'transactionId', 'sizes', 'partnerId', 'slotType']; - - metaRequiredFields.forEach(function(field) { - expect(payload.meta).to.have.property(field); - }); - slotsRequiredFields.forEach(function(field) { - expect(payload.slots[0]).to.have.property(field); - }); - }); - - it('should not generate uid if the user has opted out', function() { - storage.setDataInLocalStorage('c_nap', 'true'); - const request = spec.buildRequests(bidRequests, bidRequest); - const payload = JSON.parse(request.data); - - expect(payload.meta.uid).to.equal(false); - }); - - it('should generate uid if the user has not opted out', function() { - storage.removeDataFromLocalStorage('c_nap'); - const request = spec.buildRequests(bidRequests, bidRequest); - const payload = JSON.parse(request.data); - - expect(payload.meta.uid).to.not.equal(false); - }); - - it('should not generate uid if USP consent disallows', function() { - storage.removeDataFromLocalStorage('c_nap'); - const request = spec.buildRequests(bidRequests, { ...bidRequest, uspConsent: '1YY' }); - const payload = JSON.parse(request.data); - - expect(payload.meta.uid).to.equal(false); - }); - - it('should use sharedid if it exists', function() { - storage.removeDataFromLocalStorage('c_nap'); - const bidRequestsWithSharedId = [{ - ...bidRequests[0], - userIdAsEids: [{ - source: 'sharedid.org', - uids: [{ id: '123abc' }] - }] - }]; - const request = spec.buildRequests(bidRequestsWithSharedId, bidRequest); - const payload = JSON.parse(request.data); - - expect(payload.meta.uid).to.equal('123abc'); - }); - - it('should grab uid from local storage if it exists and sharedid does not', function() { - storage.setDataInLocalStorage('vmconcert_uid', 'foo'); - storage.removeDataFromLocalStorage('c_nap'); - const request = spec.buildRequests(bidRequests, bidRequest); - const payload = JSON.parse(request.data); - - expect(payload.meta.uid).to.equal('foo'); - }); - - it('should add uid2 to eids list if available', function() { - bidRequests[0].userIdAsEids = [{ - source: 'uidapi.com', - uids: [{ id: 'uid123', atype: 3 }] - }]; - - const request = spec.buildRequests(bidRequests, bidRequest); - const payload = JSON.parse(request.data); - const meta = payload.meta - - expect(meta.eids.length).to.equal(1); - expect(meta.eids[0].uids[0].id).to.equal('uid123') - expect(meta.eids[0].uids[0].atype).to.equal(3) - }) - - it('should return empty eids list if none are available', function() { - const request = spec.buildRequests(bidRequests, bidRequest); - const payload = JSON.parse(request.data); - const meta = payload.meta - - expect(meta.eids.length).to.equal(0); - }); - - it('should return x/y offset coordiantes when element is present', function() { - Object.assign(element, { x: 100, y: 0, width: 400, height: 400 }) - const request = spec.buildRequests(bidRequests, bidRequest); - const payload = JSON.parse(request.data); - const slot = payload.slots[0]; - - expect(slot.offsetCoordinates.x).to.equal(100) - expect(slot.offsetCoordinates.y).to.equal(0) - }) - - it('should not pass along tdid if the user has opted out', function() { - storage.setDataInLocalStorage('c_nap', 'true'); - const request = spec.buildRequests(bidRequests, bidRequest); - const payload = JSON.parse(request.data); - - expect(payload.meta.tdid).to.be.null; - }); - - it('should not pass along tdid if USP consent disallows', function() { - storage.removeDataFromLocalStorage('c_nap'); - const request = spec.buildRequests(bidRequests, { ...bidRequest, uspConsent: '1YY' }); - const payload = JSON.parse(request.data); - - expect(payload.meta.tdid).to.be.null; - }); - - it('should pass along tdid if the user has not opted out', function() { - storage.removeDataFromLocalStorage('c_nap', 'true'); - const tdid = '123abc'; - const bidRequestsWithTdid = [{ - ...bidRequests[0], - userIdAsEids: [{ - source: 'adserver.org', - uids: [{ id: tdid }] - }] - }]; - const request = spec.buildRequests(bidRequestsWithTdid, bidRequest); - const payload = JSON.parse(request.data); - expect(payload.meta.tdid).to.equal(tdid); - }); - - it('should use pubcId if it exists and sharedId does not', function() { - storage.removeDataFromLocalStorage('c_nap'); - const bidRequestsWithPubcId = [{ - ...bidRequests[0], - userIdAsEids: [{ - source: 'pubcid.org', - uids: [{ id: 'pubcid123' }] - }] - }]; - const request = spec.buildRequests(bidRequestsWithPubcId, bidRequest); - const payload = JSON.parse(request.data); - - expect(payload.meta.uid).to.equal('pubcid123'); - }); - }); - - describe('spec.interpretResponse', function() { - it('should return bids in the shape expected by prebid', function() { - const bids = spec.interpretResponse(bidResponse, bidRequest); - const requiredFields = ['requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'meta', 'creativeId', 'netRevenue', 'currency']; - - requiredFields.forEach(function(field) { - expect(bids[0]).to.have.property(field); - }); - }); - - it('should include dealId when present in bidResponse', function() { - const bids = spec.interpretResponse({ - body: { - bids: [ - { ...bidResponse.body.bids[0], dealid: 'CON-123' } - ] - } - }, bidRequest); - expect(bids[0]).to.have.property('dealId'); - }); - - it('should exclude dealId when absent in bidResponse', function() { - const bids = spec.interpretResponse(bidResponse, bidRequest); - expect(bids[0]).to.not.have.property('dealId'); - }); - - it('should return empty bids if there is no response from server', function() { - const bids = spec.interpretResponse({ body: null }, bidRequest); - expect(bids).to.have.lengthOf(0); - }); - - it('should return empty bids if there are no bids from the server', function() { - const bids = spec.interpretResponse({ body: {bids: []} }, bidRequest); - expect(bids).to.have.lengthOf(0); - }); - }); -}); diff --git a/test/spec/modules/condorxBidAdapter_spec.js b/test/spec/modules/condorxBidAdapter_spec.js deleted file mode 100644 index 62dfb631b..000000000 --- a/test/spec/modules/condorxBidAdapter_spec.js +++ /dev/null @@ -1,553 +0,0 @@ -import { expect } from 'chai'; -import { bidderSpec as adapterSpec } from 'modules/condorxBidAdapter.js'; -import * as utils from 'src/utils.js'; - -describe('CondorX Bid Adapter Tests', function () { - let basicBidRequests; - let nativeBidData; - let ortbBidRequests; - const defaultRequestParams = { - widget: 274572, - website: 195491, - url: 'current url' - }; - - beforeEach(function () { - basicBidRequests = [ - { - bidder: 'condorx', - params: defaultRequestParams, - bidId: 'test-bid-id-1', - sizes: [[300, 250]] - } - ]; - - nativeBidData = [ - { - bidder: 'condorx', - params: defaultRequestParams, - bidId: 'test-bid-id-2', - sizes: [[100, 100]], - nativeParams: { - title: { - required: true, - len: 100 - }, - image: { - required: true, - sizes: [100, 100] - }, - sponsoredBy: { - required: true - } - } - } - ]; - - ortbBidRequests = [ - { - bidder: 'condorx', - params: { - ...defaultRequestParams, - useOpenRTB: true - }, - bidId: 'test-bid-id-3', - sizes: [[300, 250]] - } - ]; - }); - - describe('Bid Size Validation', function () { - const bid = { - bidder: 'condorx', - params: defaultRequestParams - }; - - it('should accept 300x250 size', function () { - bid.sizes = [[300, 250]]; - const isValid = adapterSpec.isBidRequestValid(bid); - expect(isValid).to.be.true; - }); - - it('should accept 100x100 size', function () { - bid.sizes = [[100, 100]]; - const isValid = adapterSpec.isBidRequestValid(bid); - expect(isValid).to.be.true; - }); - - it('should accept 600x600 size', function () { - bid.sizes = [[600, 600]]; - const isValid = adapterSpec.isBidRequestValid(bid); - expect(isValid).to.be.true; - }); - - it('should accept any valid size', function () { - bid.sizes = [[728, 90]]; - const isValid = adapterSpec.isBidRequestValid(bid); - expect(isValid).to.be.true; - }); - - it('should reject invalid size', function () { - bid.sizes = [[0, 0]]; - const isValid = adapterSpec.isBidRequestValid(bid); - expect(isValid).to.be.false; - }); - - it('should reject negative size', function () { - bid.sizes = [[-1, -1]]; - const isValid = adapterSpec.isBidRequestValid(bid); - expect(isValid).to.be.false; - }); - }); - - describe('Bid Request Validation', function () { - it('should validate a correct bid request', function () { - const validBid = { - bidder: 'condorx', - params: defaultRequestParams, - sizes: [[300, 250]] - }; - const isValid = adapterSpec.isBidRequestValid(validBid); - expect(isValid).to.be.true; - }); - - it('should validate a correct OpenRTB bid request', function () { - const validOrtbBid = { - bidder: 'condorx', - params: { - ...defaultRequestParams, - useOpenRTB: true - }, - sizes: [[300, 250]] - }; - const isValid = adapterSpec.isBidRequestValid(validOrtbBid); - expect(isValid).to.be.true; - }); - - it('should invalidate an empty params bid request', function () { - const invalidBid = { - bidder: 'condorx', - params: {} - }; - const isValid = adapterSpec.isBidRequestValid(invalidBid); - expect(isValid).to.be.false; - }); - - it('should invalidate a bid request with invalid parameters', function () { - const invalidBid = { - bidder: 'condorx', - params: { - widget: '55765a', - website: 195491, - url: 'current url' - }, - sizes: [[300, 250]] - }; - const isValid = adapterSpec.isBidRequestValid(invalidBid); - expect(isValid).to.be.false; - }); - }); - - describe('OpenRTB Format Support', function () { - let bidderRequest; - - beforeEach(function () { - bidderRequest = { - auctionId: 'test-auction-id', - bids: ortbBidRequests, - ortb2: { - site: { - page: 'https://condorx.io' - } - }, - refererInfo: { - page: 'https://condorx.io' - } - }; - }); - - it('should build OpenRTB request when useOpenRTB is true', function () { - const request = adapterSpec.buildRequests(ortbBidRequests, bidderRequest)[0]; - expect(request.method).to.equal('POST'); - expect(request.url).to.include('/openrtb.json'); - expect(request.data).to.be.an('object'); - }); - - it('should build correct OpenRTB endpoint URL', function () { - const request = adapterSpec.buildRequests(ortbBidRequests, bidderRequest)[0]; - const expectedBase64 = btoa('195491_274572'); - expect(request.url).to.equal(`https://api.condorx.io/cxb/${expectedBase64}/openrtb.json`); - }); - - it('should include ortbRequest in request object', function () { - const request = adapterSpec.buildRequests(ortbBidRequests, bidderRequest)[0]; - expect(request.ortbRequest).to.exist; - expect(request.ortbRequest).to.be.an('object'); - }); - - it('should parse JSON data in OpenRTB request', function () { - const request = adapterSpec.buildRequests(ortbBidRequests, bidderRequest)[0]; - const ortbData = request.data; - expect(ortbData).to.have.property('id'); - expect(ortbData).to.have.property('imp'); - expect(ortbData.imp).to.be.an('array'); - expect(ortbData.imp[0]).to.have.property('ext'); - expect(ortbData.imp[0].ext).to.have.property('widget', 274572); - expect(ortbData.imp[0].ext).to.have.property('website', 195491); - }); - - it('should use legacy format when useOpenRTB is false', function () { - const request = adapterSpec.buildRequests(basicBidRequests, bidderRequest)[0]; - expect(request.method).to.equal('GET'); - expect(request.url).to.include('https://api.condorx.io/cxb/get.json'); - expect(request.data).to.equal(''); - }); - - it('should return OpenRTB request format when useOpenRTB is true', function () { - const request = adapterSpec.buildRequests(ortbBidRequests, bidderRequest)[0]; - expect(request.method).to.equal('POST'); - expect(request.url).to.include('/openrtb.json'); - expect(request.data).to.be.an('object'); - expect(request.ortbRequest).to.exist; - }); - }); - - describe('First Party Data (ORTB2)', function () { - let bidderRequest; - - beforeEach(function () { - bidderRequest = { - auctionId: 'test-auction-id', - bids: ortbBidRequests, - ortb2: { - site: { - page: 'https://condorx.io' - } - }, - refererInfo: { - page: 'https://condorx.io' - } - }; - }); - - it('should pass user data in OpenRTB request', function () { - bidderRequest.ortb2.user = { - id: 'user123', - buyeruid: 'buyer456', - yob: 1990 - }; - - const request = adapterSpec.buildRequests(ortbBidRequests, bidderRequest)[0]; - const ortbData = request.data; - - expect(ortbData.user.id).to.equal('user123'); - expect(ortbData.user.buyeruid).to.equal('buyer456'); - expect(ortbData.user.yob).to.equal(1990); - }); - - it('should pass device data in OpenRTB request', function () { - bidderRequest.ortb2.device = { - ua: 'Mozilla/5.0 Test Browser', - language: 'en-US', - devicetype: 1, - make: 'Apple', - model: 'iPhone' - }; - - const request = adapterSpec.buildRequests(ortbBidRequests, bidderRequest)[0]; - const ortbData = request.data; - - expect(ortbData.device.ua).to.equal('Mozilla/5.0 Test Browser'); - expect(ortbData.device.language).to.equal('en-US'); - expect(ortbData.device.devicetype).to.equal(1); - expect(ortbData.device.make).to.equal('Apple'); - expect(ortbData.device.model).to.equal('iPhone'); - }); - - it('should pass site data in OpenRTB request', function () { - bidderRequest.ortb2.site = { - page: 'https://condorx.io/test-page', - domain: 'condorx.io', - cat: ['IAB1'], - keywords: 'test,keywords' - }; - - const request = adapterSpec.buildRequests(ortbBidRequests, bidderRequest)[0]; - const ortbData = request.data; - - expect(ortbData.site.page).to.equal('https://condorx.io/test-page'); - expect(ortbData.site.domain).to.equal('condorx.io'); - expect(ortbData.site.cat).to.deep.equal(['IAB1']); - expect(ortbData.site.keywords).to.equal('test,keywords'); - }); - - it('should pass custom extensions in OpenRTB request', function () { - bidderRequest.ortb2.ext = { - pageType: 'article', - customData: 'test-value' - }; - - const request = adapterSpec.buildRequests(ortbBidRequests, bidderRequest)[0]; - const ortbData = request.data; - - expect(ortbData.ext.pageType).to.equal('article'); - expect(ortbData.ext.customData).to.equal('test-value'); - }); - - it('should pass blocked categories and domains', function () { - bidderRequest.ortb2.bcat = ['IAB25', 'IAB26']; - bidderRequest.ortb2.badv = ['blocked-advertiser.com']; - - const request = adapterSpec.buildRequests(ortbBidRequests, bidderRequest)[0]; - const ortbData = request.data; - - expect(ortbData.bcat).to.deep.equal(['IAB25', 'IAB26']); - expect(ortbData.badv).to.deep.equal(['blocked-advertiser.com']); - }); - }); - - describe('Bid Floor Support', function () { - it('should include bid floor in request URL when provided in params', function () { - const bidWithFloor = { - bidder: 'condorx', - params: { - ...defaultRequestParams, - bidfloor: 0.75 - }, - sizes: [[300, 250]] - }; - const request = adapterSpec.buildRequests([bidWithFloor])[0]; - const urlParams = new URL(request.url).searchParams; - expect(urlParams.get('bf')).to.equal('0.75'); - }); - - it('should include -1 bid floor when no floor is provided', function () { - const bidWithoutFloor = { - bidder: 'condorx', - params: defaultRequestParams, - sizes: [[300, 250]] - }; - const request = adapterSpec.buildRequests([bidWithoutFloor])[0]; - const urlParams = new URL(request.url).searchParams; - expect(urlParams.get('bf')).to.equal('-1'); - }); - - it('should prioritize params.bidfloor over getFloor function', function () { - const bidWithBothFloors = { - bidder: 'condorx', - params: { - ...defaultRequestParams, - bidfloor: 0.5 - }, - sizes: [[300, 250]], - getFloor: function() { - return { floor: 1.25 }; - } - }; - const request = adapterSpec.buildRequests([bidWithBothFloors])[0]; - const urlParams = new URL(request.url).searchParams; - expect(urlParams.get('bf')).to.equal('0.5'); - }); - - it('should handle getFloor function errors gracefully', function () { - const bidWithErrorFloor = { - bidder: 'condorx', - params: defaultRequestParams, - sizes: [[300, 250]], - getFloor: function() { - throw new Error('Floor error'); - } - }; - const request = adapterSpec.buildRequests([bidWithErrorFloor])[0]; - const urlParams = new URL(request.url).searchParams; - expect(urlParams.get('bf')).to.equal('-1'); - }); - - it('should handle invalid bidfloor params', function () { - const bidWithInvalidFloor = { - bidder: 'condorx', - params: { - ...defaultRequestParams, - bidfloor: 'invalid' - }, - sizes: [[300, 250]] - }; - const request = adapterSpec.buildRequests([bidWithInvalidFloor])[0]; - const urlParams = new URL(request.url).searchParams; - expect(urlParams.get('bf')).to.equal('-1'); - }); - }); - - describe('Request Building and HTTP Calls', function () { - it('should verify the API HTTP method', function () { - const request = adapterSpec.buildRequests(basicBidRequests)[0]; - expect(request.url).to.include('https://api.condorx.io/cxb/get.json'); - expect(request.method).to.equal('GET'); - }); - - it('should not mutate the original bid object', function () { - const originalBidRequests = utils.deepClone(basicBidRequests); - const request = adapterSpec.buildRequests(basicBidRequests); - expect(basicBidRequests).to.deep.equal(originalBidRequests); - }); - - it('should maintain the integrity of the native bid object', function () { - const originalBidRequests = utils.deepClone(nativeBidData); - const request = adapterSpec.buildRequests(nativeBidData); - expect(nativeBidData).to.deep.equal(originalBidRequests); - }); - - it('should correctly extract and validate request parameters', function () { - const request = adapterSpec.buildRequests(basicBidRequests)[0]; - const urlParams = new URL(request.url).searchParams; - expect(parseInt(urlParams.get('wg'))).to.exist.and.to.equal(basicBidRequests[0].params.widget); - expect(parseInt(urlParams.get('w'))).to.exist.and.to.equal(basicBidRequests[0].params.website); - }); - - it('should validate the custom URL parameter', function () { - const customUrl = 'https://condorx.io/custom-page'; - basicBidRequests[0].params.url = customUrl; - const request = adapterSpec.buildRequests(basicBidRequests)[0]; - const urlParams = new URL(request.url).searchParams; - expect(urlParams.get('u')).to.exist.and.to.equal(customUrl); - }); - }); - - describe('Response Validation', function () { - let nativeResponseData; - let bannerResponseData; - let ortbResponseData; - - beforeEach(() => { - const baseResponse = { - tiles: [ - { - postId: '12345', - imageUrl: 'https://cdn.condorx.io/img/condorx_logo_500.jpg', - domain: 'condorx.test', - title: 'Test title', - clickUrl: '//click.test', - pcpm: 0.5, - url: '//url.test', - displayName: 'Test sponsoredBy', - trackers: { - impressionPixels: ['//impression.test'], - viewPixels: ['//view.test'], - } - } - ], - imageWidth: 300, - imageHeight: 250, - ireqId: 'condorx121212', - widgetViewPixel: '//view.pixel', - }; - - nativeResponseData = { - ...baseResponse, - pbtypeId: 1, - }; - - bannerResponseData = { - ...baseResponse, - pbtypeId: 2, - widget: { - config: '{"css":".__condorx_banner_title{display:block!important;}"}' - }, - }; - - ortbResponseData = { - id: 'response-123', - seatbid: [{ - bid: [{ - id: 'bid-123', - impid: 'condorx121212', - price: 0.5, - adm: '
Test Banner Ad
', - w: 300, - h: 250, - crid: '12345', - adomain: ['condorx.test'] - }] - }], - cur: 'USD' - }; - }); - - it('should return an empty array for missing response', function () { - const result = adapterSpec.interpretResponse({}, []); - expect(result).to.be.an('array').that.is.empty; - }); - - it('should return an empty array for no bids', function () { - const noBidsResponse = { - tiles: [], - imageWidth: 300, - imageHeight: 250, - ireqId: 'condorx121212', - pbtypeId: 2, - widgetViewPixel: '//view.pixel', - }; - const request = adapterSpec.buildRequests(basicBidRequests)[0]; - const result = adapterSpec.interpretResponse({ body: noBidsResponse }, request); - expect(result).to.be.an('array').that.is.empty; - }); - - it('should correctly interpret a native response', function () { - const expectedNativeResult = [ - { - requestId: 'condorx121212', - cpm: 0.5, - width: 300, - height: 250, - netRevenue: true, - currency: 'USD', - creativeId: '12345', - ttl: 360, - meta: { - advertiserDomains: ['condorx.test'] - }, - native: { - title: 'Test title', - body: '', - image: { - url: 'https://cdn.condorx.io/img/condorx_logo_500.jpg', - width: 300, - height: 250 - }, - privacyLink: '', - clickUrl: '//click.test', - displayUrl: '//url.test', - cta: '', - sponsoredBy: 'Test sponsoredBy', - impressionTrackers: ['//impression.test', '//view.test', '//view.pixel'], - }, - } - ]; - const request = adapterSpec.buildRequests(basicBidRequests)[0]; - const result = adapterSpec.interpretResponse({ body: nativeResponseData }, request); - expect(result).to.deep.equal(expectedNativeResult); - }); - - it('should correctly interpret a banner response', function () { - const expectedBannerResult = [ - { - requestId: 'condorx121212', - cpm: 0.5, - width: 300, - height: 250, - netRevenue: true, - currency: 'USD', - creativeId: '12345', - ttl: 360, - meta: { - advertiserDomains: ['condorx.test'] - }, - ad: ``, - } - ]; - const request = adapterSpec.buildRequests(basicBidRequests)[0]; - const result = adapterSpec.interpretResponse({ body: bannerResponseData }, request); - expect(result).to.deep.equal(expectedBannerResult); - }); - }); -}); diff --git a/test/spec/modules/confiantRtdProvider_spec.js b/test/spec/modules/confiantRtdProvider_spec.js deleted file mode 100644 index 4557d79cf..000000000 --- a/test/spec/modules/confiantRtdProvider_spec.js +++ /dev/null @@ -1,120 +0,0 @@ -import * as utils from '../../../src/utils.js'; -import * as hook from '../../../src/hook.js' -import * as events from '../../../src/events.js'; -import { EVENTS } from '../../../src/constants.js'; - -import confiantModule from '../../../modules/confiantRtdProvider.js'; - -const { - injectConfigScript, - setupPage, - subscribeToConfiantCommFrame, - registerConfiantSubmodule -} = confiantModule; - -describe('Confiant RTD module', function () { - describe('setupPage()', function() { - let logErrorStub; - beforeEach(function() { - logErrorStub = sinon.stub(utils, 'logError'); - }); - afterEach(function() { - logErrorStub.restore(); - }); - - it('should return false if propertId is not present in config', function() { - expect(setupPage({})).to.be.false; - expect(setupPage({ params: {} })).to.be.false; - expect(setupPage({ params: { propertyId: '' } })).to.be.false; - expect(logErrorStub.callCount).to.equal(3); - }); - - it('should return true if expected parameters are present', function() { - expect(setupPage({ params: { propertyId: 'clientId' } })).to.be.true; - expect(logErrorStub.callCount).to.equal(0); - }); - }); - - describe('Module initialization', function() { - let insertElementStub; - beforeEach(function() { - insertElementStub = sinon.stub(utils, 'insertElement'); - }); - afterEach(function() { - utils.insertElement.restore(); - }); - - it('should subscribe to rovided Window object', function () { - const mockWindow = { addEventListener: sinon.spy() }; - - subscribeToConfiantCommFrame(mockWindow); - - sinon.assert.calledOnce(mockWindow.addEventListener); - }); - - it('should fire BillableEvent as a result for message in comm window', function() { - let listenerCallback; - const mockWindow = { addEventListener: (a, cb) => (listenerCallback = cb) }; - let billableEventsCounter = 0; - const propertyId = 'fff'; - - events.on(EVENTS.BILLABLE_EVENT, (e) => { - if (e.vendor === 'confiant') { - billableEventsCounter++; - expect(e.type).to.equal('impression'); - expect(e.billingId).to.be.a('number'); - expect(e.auctionId).to.equal('auctionId'); - expect(e.transactionId).to.equal('transactionId'); - } - }); - - subscribeToConfiantCommFrame(mockWindow, propertyId); - listenerCallback({ - data: { - type: 'cnft:reportBillableEvent:' + propertyId, - auctionId: 'auctionId', - transactionId: 'transactionId' - } - }); - listenerCallback({ - data: { - type: 'cnft:reportBillableEvent:' + propertyId, - auctionId: 'auctionId', - transactionId: 'transactionId' - } - }); - - expect(billableEventsCounter).to.equal(2); - }); - }); - - describe('Sumbodule execution', function() { - let submoduleStub; - let insertElementStub; - beforeEach(function () { - submoduleStub = sinon.stub(hook, 'submodule'); - insertElementStub = sinon.stub(utils, 'insertElement'); - }); - afterEach(function () { - utils.insertElement.restore(); - submoduleStub.restore(); - }); - - function initModule() { - registerConfiantSubmodule(); - - expect(submoduleStub.calledOnceWith('realTimeData')).to.equal(true); - - const registeredSubmoduleDefinition = submoduleStub.getCall(0).args[1]; - expect(registeredSubmoduleDefinition).to.be.an('object'); - expect(registeredSubmoduleDefinition).to.have.own.property('name', 'confiant'); - expect(registeredSubmoduleDefinition).to.have.own.property('init').that.is.a('function'); - - return registeredSubmoduleDefinition; - } - - it('should register Confiant submodule', function () { - initModule(); - }); - }); -}); diff --git a/test/spec/modules/connatixBidAdapter_spec.js b/test/spec/modules/connatixBidAdapter_spec.js deleted file mode 100644 index e5d51e428..000000000 --- a/test/spec/modules/connatixBidAdapter_spec.js +++ /dev/null @@ -1,1105 +0,0 @@ -import { expect } from 'chai'; -import sinon from 'sinon'; -import { - _getBidRequests, - _canSelectViewabilityContainer as connatixCanSelectViewabilityContainer, - detectViewability as connatixDetectViewability, - getBidFloor as connatixGetBidFloor, - _getMinSize as connatixGetMinSize, - _getViewability as connatixGetViewability, - hasQueryParams as connatixHasQueryParams, - _isViewabilityMeasurable as connatixIsViewabilityMeasurable, - readFromAllStorages as connatixReadFromAllStorages, - saveOnAllStorages as connatixSaveOnAllStorages, - spec, - storage -} from '../../../modules/connatixBidAdapter.js'; -import adapterManager from '../../../src/adapterManager.js'; -import * as ajax from '../../../src/ajax.js'; -import { ADPOD, BANNER, VIDEO } from '../../../src/mediaTypes.js'; -import * as utils from '../../../src/utils.js'; -import * as winDimensions from '../../../src/utils/winDimensions.js'; - -const BIDDER_CODE = 'connatix'; - -describe('connatixBidAdapter', function () { - let bid; - - function mockBidRequest() { - const mediaTypes = { - banner: { - sizes: [16, 9], - } - }; - return { - bidId: 'testing', - bidder: 'connatix', - params: { - placementId: '30e91414-545c-4f45-a950-0bec9308ff22' - }, - mediaTypes - }; - }; - - function addVideoToBidMock(bid) { - const mediaTypes = { - video: { - context: 'instream', - w: 1280, - h: 720, - playerSize: [1280, 720], - placement: 1, - plcmt: 1, - api: [1, 2], - mimes: ['video/mp4', 'application/javascript'], - minduration: 30, - maxduration: 60, - startdelay: 0, - } - } - - bid.mediaTypes = mediaTypes; - } - - describe('connatixGetMinSize', () => { - it('should return the smallest size based on area', () => { - const sizes = [ - { w: 300, h: 250 }, - { w: 728, h: 90 }, - { w: 160, h: 600 } - ]; - const result = connatixGetMinSize(sizes); - expect(result).to.deep.equal({ w: 728, h: 90 }); - }); - - it('should handle an array with one size', () => { - const sizes = [{ w: 300, h: 250 }]; - const result = connatixGetMinSize(sizes); - expect(result).to.deep.equal({ w: 300, h: 250 }); - }); - - it('should handle empty array', () => { - const sizes = []; - const result = connatixGetMinSize(sizes); - expect(result).to.be.undefined; - }); - }); - - describe('_isIframe', () => { - let querySelectorStub; - - beforeEach(() => { - querySelectorStub = sinon.stub(window.top.document, 'querySelector'); - }); - - afterEach(() => { - querySelectorStub.restore(); - }); - - it('should return true when window.top.document.querySelector does not throw an error', () => { - querySelectorStub.returns({}); - expect(connatixCanSelectViewabilityContainer()).to.be.true; - }); - - it('should return false when window.top.document.querySelector throws an error', () => { - querySelectorStub.throws(new Error('test error')); - expect(connatixCanSelectViewabilityContainer()).to.be.false; - }); - }); - - describe('_isViewabilityMeasurable', () => { - let querySelectorStub; - - beforeEach(() => { - querySelectorStub = sinon.stub(window.top.document, 'querySelector'); - }); - - afterEach(() => { - querySelectorStub.restore(); - }); - - it('should return false if the element is null or undefined', () => { - expect(connatixIsViewabilityMeasurable(null)).to.be.false; - expect(connatixIsViewabilityMeasurable(undefined)).to.be.false; - }); - - it('should return false if _isIframe returns true', () => { - querySelectorStub.throws(new Error('test error')); - - const element = document.createElement('div'); - expect(connatixIsViewabilityMeasurable(element)).to.be.false; - }); - - it('should return true if _isIframe returns false', () => { - querySelectorStub.returns(document.createElement('div')) - - const element = document.createElement('div'); - expect(connatixIsViewabilityMeasurable(element)).to.be.true; - }); - }); - - describe('_getViewability', () => { - let element; - let getBoundingClientRectStub; - let topWinMock; - - beforeEach(() => { - element = document.createElement('div'); - getBoundingClientRectStub = sinon.stub(element, 'getBoundingClientRect'); - - topWinMock = { - document: { - visibilityState: 'visible' - }, - innerWidth: 800, - innerHeight: 600 - }; - }); - - afterEach(() => { - getBoundingClientRectStub.restore(); - }); - - it('should return 0 if the document is not visible', () => { - topWinMock.document.visibilityState = 'hidden'; - - const viewability = connatixGetViewability(element, topWinMock); - - expect(viewability).to.equal(0); - }); - - it('should return 100% if the element is fully in view', () => { - const boundingBox = { left: 100, top: 100, right: 300, bottom: 300, width: 200, height: 200 }; - getBoundingClientRectStub.returns(boundingBox); - - const viewability = connatixGetViewability(element, topWinMock); - - expect(viewability).to.equal(100); - }); - - it('should return the correct percentage if the element is partially in view', () => { - const boundingBox = { left: 700, top: 500, right: 900, bottom: 700, width: 200, height: 200 }; - getBoundingClientRectStub.returns(boundingBox); - const getWinDimensionsStub = sinon.stub(winDimensions, 'getWinDimensions'); - getWinDimensionsStub.returns({ innerWidth: topWinMock.innerWidth, innerHeight: topWinMock.innerHeight}); - - const viewability = connatixGetViewability(element, topWinMock); - - expect(viewability).to.equal(25); // 100x100 / 200x200 = 0.25 -> 25% - getWinDimensionsStub.restore(); - }); - - it('should return 0% if the element is not in view', () => { - const getWinDimensionsStub = sinon.stub(winDimensions, 'getWinDimensions'); - getWinDimensionsStub.returns({ innerWidth: topWinMock.innerWidth, innerHeight: topWinMock.innerHeight}); - const boundingBox = { left: 900, top: 700, right: 1100, bottom: 900, width: 200, height: 200 }; - getBoundingClientRectStub.returns(boundingBox); - - const viewability = connatixGetViewability(element, topWinMock); - - expect(viewability).to.equal(0); - getWinDimensionsStub.restore(); - }); - - it('should use provided width and height if element dimensions are zero', () => { - const boundingBox = { left: 100, top: 100, right: 100, bottom: 100, width: 0, height: 0 }; - getBoundingClientRectStub.returns(boundingBox); - - const dimensions = { w: 200, h: 200 }; - const viewability = connatixGetViewability(element, topWinMock, dimensions); - - expect(viewability).to.equal(100); // Element fully in view with provided dimensions - }); - }); - - describe('detectViewability', () => { - let element; - let getBoundingClientRectStub; - let topWinMock; - let querySelectorStub; - let getElementByIdStub; - - beforeEach(() => { - element = document.createElement('div'); - getBoundingClientRectStub = sinon.stub(element, 'getBoundingClientRect'); - - topWinMock = { - document: { - visibilityState: 'visible' - }, - innerWidth: 800, - innerHeight: 600 - }; - - querySelectorStub = sinon.stub(window.top.document, 'querySelector'); - getElementByIdStub = sinon.stub(document, 'getElementById'); - }); - - afterEach(() => { - getBoundingClientRectStub.restore(); - querySelectorStub.restore(); - getElementByIdStub.restore(); - }); - - it('should return 100% viewability when the element is fully within view and has a valid viewabilityContainerIdentifier', () => { - const bid = { - params: { viewabilityContainerIdentifier: '#validElement' }, - adUnitCode: 'adUnitCode123', - mediaTypes: { banner: { sizes: [[300, 250]] } }, - sizes: [[300, 250]] - }; - - getBoundingClientRectStub.returns({ - left: 100, - top: 100, - right: 400, - bottom: 350, - width: 300, - height: 250 - }); - - querySelectorStub.withArgs('#validElement').returns(element); - getElementByIdStub.returns(null); - - const result = connatixDetectViewability(bid); - - // Expected calculation: the element is fully in view, so 100% viewability - expect(result).to.equal(100); - }); - - it('should fall back to using bid sizes and adUnitCode when the viewabilityContainerIdentifier is invalid or was not provided', () => { - const bid = { - params: { viewabilityContainerIdentifier: '#invalidElement' }, - adUnitCode: 'adUnitCode123', - mediaTypes: { banner: { sizes: [[300, 250]] } }, - sizes: [[300, 250]] - }; - - getBoundingClientRectStub.returns({ - left: 200, - top: 100, - right: 500, - bottom: 350, - width: 300, - height: 250 - }); - - querySelectorStub.withArgs('#invalidElement').returns(null); - getElementByIdStub.withArgs('adUnitCode123').returns(element); - - const result = connatixDetectViewability(bid); - - expect(result).to.equal(100); // Full viewability - }); - - it('should use the adUnitCode as a fallback when querying an element fails due to a browser error, and return 100% viewability because adUnitCode container is fully in view', () => { - const bid = { - params: { viewabilityContainerIdentifier: '#invalidElement' }, - adUnitCode: 'adUnitCode123', - sizes: [[300, 250]] - }; - - // Simulate an error when querying the element - querySelectorStub.withArgs('#invalidElement').throws(new Error('Query failed')); - - getBoundingClientRectStub.returns({ - left: 100, - top: 100, - right: 400, - bottom: 350, - width: 300, - height: 250 - }); - - // The fallback should use the adUnitCode to find the element - getElementByIdStub.withArgs('adUnitCode123').returns(element); - - const result = connatixDetectViewability(bid); - - expect(result).to.equal(100); // Expect the fallback to work and return 100% viewability - }); - - it('should return null when querying the element by the provided identifier fails and the adUnitCode viewability container is unavailable', () => { - const bid = { - params: { viewabilityContainerIdentifier: '#invalidElement' }, - adUnitCode: 'adUnitCode123', - sizes: [[300, 250]] - }; - - // Simulate an error when querying the element - querySelectorStub.withArgs('#invalidElement').throws(new Error('Query failed')); - - getBoundingClientRectStub.returns({ - left: 100, - top: 100, - right: 400, - bottom: 350, - width: 300, - height: 250 - }); - - const result = connatixDetectViewability(bid); - - expect(result).to.equal(null); - }); - }); - - describe('_getBidRequests', function () { - let bid; - - // Mock a bid request similar to the one already used in connatixBidAdapter tests - function mockBidRequest() { - const mediaTypes = { - banner: { - sizes: [16, 9], - } - }; - return { - bidId: 'testing', - bidder: 'connatix', - params: { - placementId: '30e91414-545c-4f45-a950-0bec9308ff22', - viewabilityContainerIdentifier: 'viewabilityId', - }, - mediaTypes, - sizes: [300, 250] - }; - } - - it('should map valid bid requests and include the expected fields', function () { - bid = mockBidRequest(); - - const result = _getBidRequests([bid]); - - expect(result).to.have.lengthOf(1); - expect(result[0]).to.have.property('bidId', bid.bidId); - expect(result[0]).to.have.property('mediaTypes', bid.mediaTypes); - expect(result[0]).to.have.property('sizes', bid.sizes); - expect(result[0]).to.have.property('placementId', bid.params.placementId); - expect(result[0]).to.have.property('hasViewabilityContainerId', true); - }); - - it('should set hasViewabilityContainerId to false when viewabilityContainerIdentifier is absent', function () { - bid = mockBidRequest(); - delete bid.params.viewabilityContainerIdentifier; - - const result = _getBidRequests([bid]); - - expect(result[0]).to.have.property('hasViewabilityContainerId', false); - }); - - it('should call getBidFloor for each bid and return the correct floor value', function () { - bid = mockBidRequest(); - const floorValue = 5; - - // Mock getFloor method on bid - bid.getFloor = function() { - return { floor: floorValue }; - }; - - const result = _getBidRequests([bid]); - - expect(result[0]).to.have.property('floor', floorValue); - }); - - it('should return floor as 0 if getBidFloor throws an error', function () { - bid = mockBidRequest(); - - // Mock getFloor method to throw an error - bid.getFloor = function() { - throw new Error('error'); - }; - - const result = _getBidRequests([bid]); - - expect(result[0]).to.have.property('floor', 0); - }); - }); - - describe('onTimeout', function () { - let ajaxStub; - - beforeEach(() => { - ajaxStub = sinon.stub(spec, 'triggerEvent') - }) - - afterEach(() => { - ajaxStub.restore() - }); - - it('call event if bidder is connatix', () => { - const result = spec.onTimeout([{ - bidder: 'connatix', - timeout: 500, - }]); - expect(ajaxStub.calledOnce).to.equal(true); - - const data = ajaxStub.firstCall.args[0]; - expect(data.type).to.equal('Timeout'); - expect(data.timeout).to.equal(500); - }); - - it('timeout event is not triggered if bidder is not connatix', () => { - const result = spec.onTimeout([{ - bidder: 'otherBidder', - timeout: 500, - }]); - expect(ajaxStub.notCalled).to.equal(true); - }); - }); - - describe('onBidWon', function () { - let ajaxStub; - - beforeEach(() => { - ajaxStub = sinon.stub(spec, 'triggerEvent'); - }); - - afterEach(() => { - ajaxStub.restore(); - }); - - it('calls triggerEvent with correct data when bidWinData is provided', () => { - const bidWinData = { - bidder: 'connatix', - cpm: 2.5, - requestId: 'abc123', - bidId: 'dasdas-dsawda-dwaddw-dwdwd', - adUnitCode: 'adunit_1', - timeToRespond: 300, - auctionId: 'auction_456', - }; - - spec.onBidWon(bidWinData); - expect(ajaxStub.calledOnce).to.equal(true); - - const eventData = ajaxStub.firstCall.args[0]; - expect(eventData.type).to.equal('BidWon'); - expect(eventData.bestBidBidder).to.equal('connatix'); - expect(eventData.bestBidPrice).to.equal(2.5); - expect(eventData.requestId).to.equal('abc123'); - expect(eventData.bidId).to.equal('dasdas-dsawda-dwaddw-dwdwd'); - expect(eventData.adUnitCode).to.equal('adunit_1'); - expect(eventData.timeToRespond).to.equal(300); - expect(eventData.auctionId).to.equal('auction_456'); - }); - - it('does not call triggerEvent if bidWinData is null', () => { - spec.onBidWon(null); - expect(ajaxStub.notCalled).to.equal(true); - }); - - it('does not call triggerEvent if bidWinData is undefined', () => { - spec.onBidWon(undefined); - expect(ajaxStub.notCalled).to.equal(true); - }); - }); - - describe('triggerEvent', function () { - let ajaxStub; - - beforeEach(() => { - ajaxStub = sinon.stub(ajax, 'ajax'); - }); - - afterEach(() => { - ajaxStub.restore(); - }); - - it('should call ajax with the correct parameters', () => { - const data = { type: 'BidWon', bestBidBidder: 'bidder1', bestBidPrice: 1.5, requestId: 'req123', adUnitCode: 'ad123', timeToRespond: 250, auctionId: 'auc123', context: {} }; - spec.triggerEvent(data); - - expect(ajaxStub.calledOnce).to.equal(true); - const [url, _, payload, options] = ajaxStub.firstCall.args; - expect(url).to.equal('https://capi.connatix.com/tr/am'); - expect(payload).to.equal(JSON.stringify(data)); - expect(options.method).to.equal('POST'); - expect(options.withCredentials).to.equal(false); - }); - }); - - describe('isBidRequestValid', function () { - this.beforeEach(function () { - bid = mockBidRequest(); - }); - - it('Should return true if all required fileds are present', function () { - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - it('Should return false if bidId is missing', function () { - delete bid.bidId; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - it('Should return false if params object is missing', function () { - delete bid.params; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - it('Should return false if placementId is missing from params', function () { - delete bid.params.placementId; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - it('Should return false if mediaTypes is missing', function () { - delete bid.mediaTypes; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - it('Should return false if both banner and video are missing from mediaTypes', function () { - delete bid.mediaTypes.banner; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - it('Should return false if sizes is missing from banner object', function () { - delete bid.mediaTypes.banner.sizes; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - it('Should return false if sizes is not an array', function () { - bid.mediaTypes.banner.sizes = 'test'; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - it('Should return false if sizes is an empty array', function () { - bid.mediaTypes.banner.sizes = []; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - it('Should return true if video is set correctly', function () { - addVideoToBidMock(bid); - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - it('Should return false if context is set to adpod on video media type', function() { - addVideoToBidMock(bid); - bid.mediaTypes.video.context = ADPOD; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - it('Should return true if add an extra field was added to the bidRequest', function () { - bid.params.test = 1; - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - }); - - describe('buildRequests', function () { - let serverRequest; - let setCookieStub, setDataInLocalStorageStub; - const bidderRequest = { - refererInfo: { - canonicalUrl: '', - numIframes: 0, - reachedTop: true, - referer: 'http://example.com', - stack: ['http://example.com'] - }, - gdprConsent: { - consentString: 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - vendorData: {}, - gdprApplies: true - }, - uspConsent: '1YYY', - gppConsent: { - gppString: 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - applicableSections: [7] - }, - ortb2: { - site: { - data: { - pageType: 'article' - } - } - } - }; - - this.beforeEach(function () { - const mockIdentityProviderData = { mockKey: 'mockValue' }; - const CNX_IDS_EXPIRY = 24 * 30 * 60 * 60 * 1000; - setCookieStub = sinon.stub(storage, 'setCookie'); - setDataInLocalStorageStub = sinon.stub(storage, 'setDataInLocalStorage'); - connatixSaveOnAllStorages('test_ids_cnx', mockIdentityProviderData, CNX_IDS_EXPIRY); - - bid = mockBidRequest(); - serverRequest = spec.buildRequests([bid], bidderRequest); - }) - - this.afterEach(function() { - setCookieStub.restore(); - setDataInLocalStorageStub.restore(); - }); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://capi.connatix.com/rtb/hba'); - }); - it('Returns request payload', function () { - expect(serverRequest.data).to.not.empty; - }); - it('Validate request payload', function () { - expect(serverRequest.data.bidRequests[0].bidId).to.equal(bid.bidId); - expect(serverRequest.data.bidRequests[0].placementId).to.equal(bid.params.placementId); - expect(serverRequest.data.bidRequests[0].floor).to.equal(0); - expect(serverRequest.data.bidRequests[0].mediaTypes).to.equal(bid.mediaTypes); - expect(serverRequest.data.bidRequests[0].sizes).to.equal(bid.mediaTypes.sizes); - expect(serverRequest.data.refererInfo).to.equal(bidderRequest.refererInfo); - expect(serverRequest.data.gdprConsent).to.equal(bidderRequest.gdprConsent); - expect(serverRequest.data.uspConsent).to.equal(bidderRequest.uspConsent); - expect(serverRequest.data.gppConsent).to.equal(bidderRequest.gppConsent); - expect(serverRequest.data.ortb2).to.equal(bidderRequest.ortb2); - expect(serverRequest.data.identityProviderData).to.deep.equal({ mockKey: 'mockValue' }); - }); - }); - - describe('interpretResponse', function () { - const CustomerId = '99f20d18-c4b4-4a28-3d8e-d43e2c8cb4ac'; - const PlayerId = 'e4984e88-9ff4-45a3-8b9d-33aabcad634f'; - const Bid = {Cpm: 0.1, RequestId: '2f897340c4eaa3', Ttl: 86400, CustomerId, PlayerId}; - - let serverResponse; - this.beforeEach(function () { - serverResponse = { - body: { - Bids: [ Bid ] - }, - headers: function() { } - }; - }); - - it('Should return an empty array if Bids is null', function () { - serverResponse.body.Bids = null; - - const response = spec.interpretResponse(serverResponse); - expect(response).to.be.an('array').that.is.empty; - }); - - it('Should return an empty array if Bids is empty array', function () { - serverResponse.body.Bids = []; - const response = spec.interpretResponse(serverResponse); - expect(response).to.be.an('array').that.is.empty; - }); - - it('Should return one bid response for one bid', function() { - const bidResponses = spec.interpretResponse(serverResponse); - expect(bidResponses.length).to.equal(1); - }); - - it('Should contains the same values as in the serverResponse', function() { - const bidResponses = spec.interpretResponse(serverResponse); - - const [ bidResponse ] = bidResponses; - expect(bidResponse.requestId).to.equal(serverResponse.body.Bids[0].RequestId); - expect(bidResponse.cpm).to.equal(serverResponse.body.Bids[0].Cpm); - expect(bidResponse.ttl).to.equal(serverResponse.body.Bids[0].Ttl); - expect(bidResponse.currency).to.equal('USD'); - expect(bidResponse.mediaType).to.equal(BANNER); - expect(bidResponse.netRevenue).to.be.true; - }); - - it('Should return n bid responses for n bids', function() { - serverResponse.body.Bids = [ { ...Bid }, { ...Bid } ]; - - const firstBidCpm = 4; - serverResponse.body.Bids[0].Cpm = firstBidCpm; - - const secondBidCpm = 13; - serverResponse.body.Bids[1].Cpm = secondBidCpm; - - const bidResponses = spec.interpretResponse(serverResponse); - expect(bidResponses.length).to.equal(2); - - expect(bidResponses[0].cpm).to.equal(firstBidCpm); - expect(bidResponses[1].cpm).to.equal(secondBidCpm); - }); - - it('Should contain specific values for banner bids', function () { - const adHtml = 'ad html' - serverResponse.body.Bids = [ { ...Bid, Ad: adHtml } ]; - - const bidResponses = spec.interpretResponse(serverResponse); - const [ bidResponse ] = bidResponses; - - expect(bidResponse.vastXml).to.be.undefined; - expect(bidResponse.ad).to.equal(adHtml); - expect(bidResponse.mediaType).to.equal(BANNER); - }); - - it('Should contain specific values for video bids', function () { - const adVastXml = 'ad vast xml' - serverResponse.body.Bids = [ { ...Bid, VastXml: adVastXml } ]; - - const bidResponses = spec.interpretResponse(serverResponse); - const [ bidResponse ] = bidResponses; - - expect(bidResponse.ad).to.be.undefined; - expect(bidResponse.vastXml).to.equal(adVastXml); - expect(bidResponse.mediaType).to.equal(VIDEO); - }); - }); - - describe('getUserSyncs', function() { - const CustomerId = '99f20d18-c4b4-4a28-3d8e-d43e2c8cb4ac'; - const PlayerId = 'e4984e88-9ff4-45a3-8b9d-33aabcad634f'; - const UserSyncEndpoint = 'https://connatix.com/sync' - const UserSyncEndpointWithParams = 'https://connatix.com/sync?param1=value1' - const Bid = {Cpm: 0.1, RequestId: '2f897340c4eaa3', Ttl: 86400, CustomerId, PlayerId}; - - const serverResponse = { - body: { - UserSyncEndpoint, - Bids: [ Bid ] - }, - headers: function() { } - }; - const serverResponse2 = { - body: { - UserSyncEndpoint: UserSyncEndpointWithParams, - Bids: [ Bid ] - }, - headers: function() { } - }; - - it('Should return an empty array when iframeEnabled: false', function () { - expect(spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [], {}, {}, {})).to.be.an('array').that.is.empty; - }); - it('Should return an empty array when serverResponses is emprt array', function () { - expect(spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, [], {}, {}, {})).to.be.an('array').that.is.empty; - }); - it('Should return an empty array when iframeEnabled: true but serverResponses in an empty array', function () { - expect(spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [serverResponse], {}, {}, {})).to.be.an('array').that.is.empty; - }); - it('Should return an empty array when iframeEnabled: true but serverResponses in an not defined or null', function () { - expect(spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, undefined, {}, {}, {})).to.be.an('array').that.is.empty; - expect(spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, null, {}, {}, {})).to.be.an('array').that.is.empty; - }); - it('Should return one user sync object when iframeEnabled is true and serverResponses is not an empry array', function () { - expect(spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, [serverResponse], {}, {}, {})).to.be.an('array').that.is.not.empty; - }); - it('Should return a list containing a single object having type: iframe and url: syncUrl', function () { - const userSyncList = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, [serverResponse], undefined, undefined, undefined); - const { type, url } = userSyncList[0]; - expect(type).to.equal('iframe'); - expect(url).to.equal(UserSyncEndpoint); - }); - it('Should append gdpr: 0 if gdprConsent object is provided but gdprApplies field is not provided', function () { - const userSyncList = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [serverResponse], - {}, - undefined, - undefined - ); - const { url } = userSyncList[0]; - expect(url).to.equal(`${UserSyncEndpoint}?gdpr=0`); - }); - it('Should append gdpr having the value of gdprApplied if gdprConsent object is present and have gdprApplies field', function () { - const userSyncList = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [serverResponse], - {gdprApplies: true}, - undefined, - undefined - ); - const { url } = userSyncList[0]; - expect(url).to.equal(`${UserSyncEndpoint}?gdpr=1`); - }); - it('Should append gdpr_consent if gdprConsent object is present and have gdprApplies field', function () { - const userSyncList = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [serverResponse], - {gdprApplies: true, consentString: 'alabala'}, - undefined, - undefined - ); - const { url } = userSyncList[0]; - expect(url).to.equal(`${UserSyncEndpoint}?gdpr=1&gdpr_consent=alabala`); - }); - it('Should encodeURI gdpr_consent corectly', function () { - const userSyncList = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [serverResponse], - {gdprApplies: true, consentString: 'test&2'}, - undefined, - undefined - ); - const { url } = userSyncList[0]; - expect(url).to.equal(`${UserSyncEndpoint}?gdpr=1&gdpr_consent=test%262`); - }); - it('Should append usp_consent to the url if uspConsent is provided', function () { - const userSyncList = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [serverResponse], - {gdprApplies: true, consentString: 'test&2'}, - '1YYYN', - undefined - ); - const { url } = userSyncList[0]; - expect(url).to.equal(`${UserSyncEndpoint}?gdpr=1&gdpr_consent=test%262&us_privacy=1YYYN`); - }); - it('Should not modify the sync url if gppConsent param is provided', function () { - const userSyncList = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [serverResponse], - {gdprApplies: true, consentString: 'test&2'}, - '1YYYN', - {consent: '1'} - ); - const { url } = userSyncList[0]; - expect(url).to.equal(`${UserSyncEndpoint}?gdpr=1&gdpr_consent=test%262&us_privacy=1YYYN`); - }); - it('Should correctly append all consents to the sync url if the url contains query params', function () { - const userSyncList = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [serverResponse2], - {gdprApplies: true, consentString: 'test&2'}, - '1YYYN', - {consent: '1'} - ); - const { url } = userSyncList[0]; - expect(url).to.equal(`${UserSyncEndpointWithParams}&gdpr=1&gdpr_consent=test%262&us_privacy=1YYYN`); - }); - }); - - describe('userIdAsEids', function() { - let validBidRequests; - - this.beforeEach(function () { - bid = mockBidRequest(); - validBidRequests = [bid]; - }) - - it('Connatix adapter reads EIDs from Prebid user models and adds it to Request', function() { - validBidRequests[0].userIdAsEids = [{ - 'source': 'adserver.org', - 'uids': [{ - 'id': 'TTD_ID_FROM_USER_ID_MODULE', - 'atype': 1, - 'ext': { - 'stype': 'ppuid', - 'rtiPartner': 'TDID' - } - }] - }, - { - 'source': 'pubserver.org', - 'uids': [{ - 'id': 'TDID_FROM_USER_ID_MODULE', - 'atype': 1 - }] - }]; - const serverRequest = spec.buildRequests(validBidRequests, {}); - expect(serverRequest.data.userIdList).to.deep.equal(validBidRequests[0].userIdAsEids); - }); - }); - - describe('isConnatix', function () { - let aliasRegistryStub; - - beforeEach(() => { - aliasRegistryStub = sinon.stub(adapterManager, 'aliasRegistry').value({}); - }); - - afterEach(() => { - aliasRegistryStub.restore(); - }); - - it('should return false if aliasName is undefined or null', () => { - expect(spec.isConnatix(undefined)).to.be.false; - expect(spec.isConnatix(null)).to.be.false; - }); - - it('should return true if aliasName matches BIDDER_CODE', () => { - const aliasName = BIDDER_CODE; - expect(spec.isConnatix(aliasName)).to.be.true; - }); - - it('should return true if aliasName is mapped to BIDDER_CODE in aliasRegistry', () => { - const aliasName = 'connatixAlias'; - aliasRegistryStub.value({ 'connatixAlias': BIDDER_CODE }); - expect(spec.isConnatix(aliasName)).to.be.true; - }); - - it('should return false if aliasName does not match BIDDER_CODE', () => { - const aliasName = 'otherBidder'; - expect(spec.isConnatix(aliasName)).to.be.false; - }); - - it('should return false if aliasName is mapped to a different bidder in aliasRegistry', () => { - const aliasName = 'someOtherAlias'; - aliasRegistryStub.value({ 'someOtherAlias': 'otherBidder' }); - expect(spec.isConnatix(aliasName)).to.be.false; - }); - }); - - describe('getBidFloor', function () { - this.beforeEach(function () { - bid = mockBidRequest(); - }); - - it('Should return 0 if both getFloor method and bidfloor param from bid are absent.', function () { - const floor = connatixGetBidFloor(bid); - expect(floor).to.equal(0); - }); - - it('Should return the value of the bidfloor parameter if the getFloor method is not defined but the bidfloor parameter is defined', function () { - const floorValue = 3; - bid.params.bidfloor = floorValue; - - const floor = connatixGetBidFloor(bid); - expect(floor).to.equal(floorValue); - }); - - it('Should return the value of the getFloor method if the getFloor method is defined but the bidfloor parameter is not defined', function () { - const floorValue = 7; - bid.getFloor = function() { - return { floor: floorValue }; - }; - - const floor = connatixGetBidFloor(bid); - expect(floor).to.equal(floorValue); - }); - - it('Should return the value of the getFloor method if both getFloor method and bidfloor parameter are defined', function () { - const floorParamValue = 3; - bid.params.bidfloor = floorParamValue; - - const floorMethodValue = 7; - bid.getFloor = function() { - return { floor: floorMethodValue }; - }; - - const floor = connatixGetBidFloor(bid); - expect(floor).to.equal(floorMethodValue); - }); - - it('Should return 0 if the getFloor method is defined and it crash when call it', function () { - bid.getFloor = function() { - throw new Error('error'); - }; - const floor = connatixGetBidFloor(bid); - expect(floor).to.equal(0); - }); - }); - describe('getUserSyncs with message event listener', function() { - const CNX_IDS_EXPIRY = 24 * 30 * 60 * 60 * 1000; - const CNX_IDS_LOCAL_STORAGE_COOKIES_KEY = 'cnx_user_ids'; - const ALL_PROVIDERS_RESOLVED_EVENT = 'cnx_all_identity_providers_resolved'; - - const mockData = { - data: { - supplementalEids: [{ provider: 2, group: 1, eidsList: ['123', '456'] }] - } - }; - - function messageHandler(event) { - if (!event.data || event.origin !== 'https://cds.connatix.com' || !event.data.cnx) { - return; - } - - const { message, data } = event.data.cnx; - - if (message === ALL_PROVIDERS_RESOLVED_EVENT) { - window.removeEventListener('message', messageHandler); - event.stopImmediatePropagation(); - } - - if (message === ALL_PROVIDERS_RESOLVED_EVENT || message === IDENTITY_PROVIDER_COLLECTION_UPDATED_EVENT) { - if (data) { - connatixSaveOnAllStorages(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY, data, CNX_IDS_EXPIRY); - } - } - } - - let sandbox; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - sandbox.stub(storage, 'setCookie'); - sandbox.stub(storage, 'setDataInLocalStorage'); - sandbox.stub(window, 'removeEventListener'); - sandbox.stub(storage, 'cookiesAreEnabled').returns(true); - sandbox.stub(storage, 'localStorageIsEnabled').returns(true); - sandbox.stub(storage, 'getCookie'); - sandbox.stub(storage, 'getDataFromLocalStorage'); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('Should set a cookie and save to local storage when a valid message is received', () => { - const fakeEvent = { - data: { cnx: { message: 'cnx_all_identity_providers_resolved', data: mockData } }, - origin: 'https://cds.connatix.com', - stopImmediatePropagation: sinon.spy() - }; - - messageHandler(fakeEvent); - - expect(fakeEvent.stopImmediatePropagation.calledOnce).to.be.true; - expect(window.removeEventListener.calledWith('message', messageHandler)).to.be.true; - expect(storage.setCookie.calledWith(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY, JSON.stringify(mockData), sinon.match.string)).to.be.true; - expect(storage.setDataInLocalStorage.calledWith(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY, JSON.stringify(mockData))).to.be.true; - - storage.getCookie.returns(JSON.stringify(mockData)); - storage.getDataFromLocalStorage.returns(JSON.stringify(mockData)); - - const retrievedData = connatixReadFromAllStorages(CNX_IDS_LOCAL_STORAGE_COOKIES_KEY); - expect(retrievedData).to.deep.equal(mockData); - }); - - it('Should not do anything when there is no data in the payload', () => { - const fakeEvent = { - data: null, - origin: 'https://cds.connatix.com', - stopImmediatePropagation: sinon.spy() - }; - - messageHandler(fakeEvent); - - expect(fakeEvent.stopImmediatePropagation.notCalled).to.be.true; - expect(window.removeEventListener.notCalled).to.be.true; - expect(storage.setCookie.notCalled).to.be.true; - expect(storage.setDataInLocalStorage.notCalled).to.be.true; - }); - - it('Should not do anything when the origin is invalid', () => { - const fakeEvent = { - data: { cnx: { message: 'cnx_all_identity_providers_resolved', data: mockData } }, - origin: 'https://notConnatix.com', - stopImmediatePropagation: sinon.spy() - }; - - messageHandler(fakeEvent); - - expect(fakeEvent.stopImmediatePropagation.notCalled).to.be.true; - expect(window.removeEventListener.notCalled).to.be.true; - expect(storage.setCookie.notCalled).to.be.true; - expect(storage.setDataInLocalStorage.notCalled).to.be.true; - }); - }); - describe('connatixHasQueryParams', () => { - it('Should return false if there is no query param in the url', () => { - const url = 'http://example.com' - const result = connatixHasQueryParams(url); - expect(result).to.equal(false); - }); - - it('Should return true if there is one query param in the url', () => { - const url = 'http://example.com?query1=value1' - const result = connatixHasQueryParams(url); - expect(result).to.equal(true); - }); - - it('Should return true if there is multiple query params in the url', () => { - const url = 'http://example.com?query1=value1&query2=value2' - const result = connatixHasQueryParams(url); - expect(result).to.equal(true); - }); - - it('Should return false if the url is invalid', () => { - const url = 'example' - const result = connatixHasQueryParams(url); - expect(result).to.equal(false); - }); - }); -}); diff --git a/test/spec/modules/connectadBidAdapter_spec.js b/test/spec/modules/connectadBidAdapter_spec.js deleted file mode 100644 index 724f4eb93..000000000 --- a/test/spec/modules/connectadBidAdapter_spec.js +++ /dev/null @@ -1,794 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/connectadBidAdapter.js'; -import { config } from 'src/config.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import assert from 'assert'; - -describe('ConnectAd Adapter', function () { - let bidRequests; - let bidderRequest; - let bidRequestsUserIds; - - beforeEach(function () { - bidRequests = [ - { - bidder: 'conntectad', - params: { - siteId: 123456, - networkId: 123456, - bidfloor: 0.50 - }, - adUnitCode: '/19968336/header-bid-tag-1', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - } - }, - bidId: '2f95c00074b931', - auctionId: 'e76cbb58-f3e1-4ad9-9f4c-718c1919d0df', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: 'e76cbb58-f3e1-4ad9-9f4c-718c1919d0df', - ortb2Imp: { - ext: { - tid: '601bda1a-01a9-4de9-b8f3-649d3bdd0d8f', - gpid: '/12345/homepage-leftnav' - } - }, - } - ]; - - bidRequestsUserIds = [{ - bidder: 'conntectad', - params: { - siteId: 123456, - networkId: 123456 - }, - adUnitCode: '/19968336/header-bid-tag-1', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - } - }, - bidId: '2f95c00074b931', - auctionId: 'e76cbb58-f3e1-4ad9-9f4c-718c1919d0df', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: 'e76cbb58-f3e1-4ad9-9f4c-718c1919d0df', - userIdAsEids: [ - { - 'source': 'pubcid.org', - 'uids': [ - { - 'atype': 1, - 'id': '123456' - } - ] - } - ] - }]; - - bidderRequest = { - timeout: 3000, - gdprConsent: { - gdprApplies: true, - consentString: 'consentDataString', - vendorData: {} - } - } - }); - - afterEach(function () { - config.resetConfig(); - }); - - describe('inherited functions', function () { - it('should exists and is a function', function () { - const adapter = newBidder(spec); - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('implementation', function () { - describe('for requests', function () { - it('should accept bid', function () { - const validBid = { - bidder: 'connectad', - params: { - siteId: 123456, - networkId: 123456 - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - } - }; - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(true); - }); - - it('should reject if missing sizes', function () { - const invalidBid = { - bidder: 'connectad', - params: { - siteId: 123456, - } - }; - const isValid = spec.isBidRequestValid(invalidBid); - expect(isValid).to.equal(false); - }); - - it('should return true when optional bidFloor params found for an ad', function () { - const validBid = { - bidder: 'connectad', - params: { - siteId: 123456, - networkId: 123456, - bidfloor: 0.20 - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - } - }; - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(true) - }); - - it('should reject if missing siteId/networkId', function () { - const invalidBid = { - bidder: 'connectad', - params: {}, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - } - } - }; - const isValid = spec.isBidRequestValid(invalidBid); - expect(isValid).to.equal(false); - }); - - it('should reject if missing networkId', function () { - const invalidBid = { - bidder: 'connectad', - params: { - siteId: 123456 - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - } - } - }; - const isValid = spec.isBidRequestValid(invalidBid); - expect(isValid).to.equal(false); - }); - - it('should contain SiteId and NetworkId', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - expect(requestparse.placements[0].siteId).to.equal(123456); - expect(requestparse.placements[0].networkId).to.equal(123456); - }); - - it('should process floors module if available', function() { - const floorInfo = { - currency: 'USD', - floor: 5.20 - }; - bidRequests[0].getFloor = () => floorInfo; - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - expect(requestparse.placements[0].bidfloor).to.equal(5.20); - }); - - it('should be bidfloor if no floormodule is available', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - expect(requestparse.placements[0].bidfloor).to.equal(0.50); - }); - - it('should have 0 bidfloor value', function() { - const request = spec.buildRequests(bidRequestsUserIds, bidderRequest); - const requestparse = JSON.parse(request.data); - expect(requestparse.placements[0].bidfloor).to.equal(0); - }); - - it('should contain gdpr info', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - - expect(requestparse.user.ext.gdpr).to.equal(1); - expect(requestparse.user.ext.consent).to.equal('consentDataString'); - }); - - it('should build a request if Consent but no gdprApplies', function () { - const localbidderRequest = { - timeout: 3000, - gdprConsent: { - gdprApplies: false, - consentString: 'consentDataString', - }, - } - const request = spec.buildRequests(bidRequests, localbidderRequest); - const requestparse = JSON.parse(request.data); - - expect(requestparse.placements[0].siteId).to.equal(123456); - expect(requestparse.user.ext.consent).to.equal('consentDataString'); - }); - - it('should build a request if gdprConsent empty', function () { - const localbidderRequest = { - timeout: 3000, - gdprConsent: {} - } - const request = spec.buildRequests(bidRequests, localbidderRequest); - const requestparse = JSON.parse(request.data); - - expect(requestparse.placements[0].siteId).to.equal(123456); - }); - - it('should have CCPA Consent if defined', function () { - const uspConsent = '1YYN' - bidderRequest.uspConsent = uspConsent - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - - expect(requestparse.user.ext.us_privacy).to.equal(uspConsent); - }); - - it('should not have CCPA Consent if not defined', function () { - bidderRequest.uspConsent = undefined - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - expect(requestparse.user.ext.us_privacy).to.be.undefined; - }); - - it('should not include schain when not provided', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - expect(requestparse).to.not.have.property('source.ext.schain'); - }); - - it('should submit coppa if set in config', function () { - sinon.stub(config, 'getConfig') - .withArgs('coppa') - .returns(true); - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - expect(requestparse.regs.coppa).to.equal(1); - config.getConfig.restore(); - }); - - it('should not set coppa when coppa is not provided or is set to false', function () { - sinon.stub(config, 'getConfig') - .withArgs('coppa') - .returns(false); - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - assert.equal(requestparse.regs.coppa, undefined); - config.getConfig.restore(); - }); - - it('should send all UserData data', function () { - const request = spec.buildRequests(bidRequestsUserIds, bidderRequest); - const requestparse = JSON.parse(request.data); - expect(requestparse.user.ext.eids).to.be.an('array'); - expect(requestparse.user.ext.eids[0].uids[0].id).to.equal('123456'); - }); - - it('should include DSA signals', function () { - const dsa = { - dsarequired: 3, - pubrender: 0, - datatopub: 2, - transparency: [ - { - domain: 'domain1.com', - dsaparams: [1] - }, - { - domain: 'domain2.com', - dsaparams: [1, 2] - } - ] - }; - - let bidRequest = { - ortb2: { - regs: { - ext: { - dsa - } - } - } - }; - const request = spec.buildRequests(bidRequests, bidRequest); - const data = JSON.parse(request.data); - assert.deepEqual(data.regs.ext.dsa, dsa); - }); - - it('should pass auction level tid', function() { - const bidRequest = Object.assign([], bidRequests); - - const localBidderRequest = { - ...bidderRequest, - ortb2: { - source: { - tid: '9XSL9B79XM' - } - } - } - - const request = spec.buildRequests(bidRequest, localBidderRequest); - const data = JSON.parse(request.data); - expect(data.source?.tid).to.equal('9XSL9B79XM') - }); - - it('should pass gpid', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - expect(requestparse.placements[0].gpid).to.equal('/12345/homepage-leftnav'); - }); - - it('should pass impression level tid', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - expect(requestparse.placements[0].tid).to.equal('601bda1a-01a9-4de9-b8f3-649d3bdd0d8f'); - }); - - it('should pass first party data', function() { - const bidRequest = Object.assign([], bidRequests); - - const localBidderRequest = { - ...bidderRequest, - ortb2: { - bcat: ['IAB1', 'IAB2-1'], - badv: ['xyz.com', 'zyx.com'], - site: { ext: { data: 'some site data' } }, - device: { ext: { data: 'some device data' } }, - user: { ext: { data: 'some user data' } }, - regs: { ext: { data: 'some regs data' } } - } - }; - - const request = spec.buildRequests(bidRequest, localBidderRequest); - const data = JSON.parse(request.data); - expect(data.bcat).to.deep.equal(localBidderRequest.ortb2.bcat); - expect(data.badv).to.deep.equal(localBidderRequest.ortb2.badv); - expect(data.site).to.nested.include({'ext.data': 'some site data'}); - expect(data.device).to.nested.include({'ext.data': 'some device data'}); - expect(data.user).to.nested.include({'ext.data': 'some user data'}); - expect(data.regs).to.nested.include({'ext.data': 'some regs data'}); - }); - - it('should accept tmax from global config if not set by requestBids method', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - - expect(requestparse.tmax).to.deep.equal(3000); - }); - - it('should populate schain', function () { - const bidRequest = Object.assign({}, bidRequests[0], { - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - 'asi': 'reseller1.com', - 'sid': 'absc1', - 'hp': 1 - } - ] - } - } - } - } - }); - - const request = spec.buildRequests([bidRequest], bidderRequest); - const requestparse = JSON.parse(request.data); - expect(requestparse.source.ext.schain).to.deep.equal({ - ver: '1.0', - complete: 1, - nodes: [ - { - 'asi': 'reseller1.com', - 'sid': 'absc1', - 'hp': 1 - } - ] - }); - }); - }); - - describe('GPP Implementation', function() { - it('should check with GPP Consent', function () { - const bidRequest = { - gppConsent: { - 'gppString': 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', - 'fullGppData': { - 'sectionId': 3, - 'gppVersion': 1, - 'sectionList': [ - 5, - 7 - ], - 'applicableSections': [ - 5 - ], - 'gppString': 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', - 'pingData': { - 'cmpStatus': 'loaded', - 'gppVersion': '1.0', - 'cmpDisplayStatus': 'visible', - 'supportedAPIs': [ - 'tcfca', - 'usnat', - 'usca', - 'usva', - 'usco', - 'usut', - 'usct' - ], - 'cmpId': 31 - }, - 'eventName': 'sectionChange' - }, - 'applicableSections': [ - 5 - ], - 'apiVersion': 1 - } - }; - const request = spec.buildRequests(bidRequests, bidRequest); - const data = JSON.parse(request.data); - expect(data.regs.gpp).to.equal('DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN'); - expect(data.regs.gpp_sid[0]).to.equal(5); - }); - - it('should check without GPP Consent', function () { - const bidRequest = {}; - const request = spec.buildRequests(bidRequests, bidRequest); - const data = JSON.parse(request.data); - expect(data.regs.gpp).to.equal(undefined); - }); - - it('should check with GPP Consent read from OpenRTB2', function () { - const bidRequest = { - ortb2: { - regs: { - 'gpp': 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', - 'gpp_sid': [ - 5 - ] - } - } - }; - const request = spec.buildRequests(bidRequests, bidRequest); - const data = JSON.parse(request.data); - expect(data.regs.gpp).to.equal('DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN'); - expect(data.regs.gpp_sid[0]).to.equal(5); - }); - }); - - describe('bid responses', function () { - it('should return complete bid response with adomain', function () { - const ADOMAINS = ['connectad.io']; - - const serverResponse = { - body: { - decisions: { - '2f95c00074b931': { - adId: '0', - adomain: ['connectad.io'], - contents: [ - { - body: '<<<---- Creative --->>>' - } - ], - height: '250', - width: '300', - pricing: { - clearPrice: 11.899999999999999 - } - } - } - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - - expect(bids).to.be.lengthOf(1); - expect(bids[0].cpm).to.equal(11.899999999999999); - expect(bids[0].width).to.equal('300'); - expect(bids[0].height).to.equal('250'); - expect(bids[0].ad).to.have.length.above(1); - expect(bids[0].meta.advertiserDomains).to.deep.equal(ADOMAINS); - }); - - it('should process meta response object', function () { - const ADOMAINS = ['connectad.io']; - const dsa = { - behalf: 'Advertiser', - paid: 'Advertiser', - transparency: [{ - domain: 'dsp1domain.com', - dsaparams: [1, 2] - }], - adrender: 1 - }; - - const serverResponse = { - body: { - decisions: { - '2f95c00074b931': { - adId: '0', - adomain: ['connectad.io'], - contents: [ - { - body: '<<<---- Creative --->>>' - } - ], - height: '250', - width: '300', - dsa: dsa, - category: 'IAB123', - pricing: { - clearPrice: 11.899999999999999 - } - } - } - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - - expect(bids).to.be.lengthOf(1); - expect(bids[0].cpm).to.equal(11.899999999999999); - expect(bids[0].width).to.equal('300'); - expect(bids[0].height).to.equal('250'); - expect(bids[0].ad).to.have.length.above(1); - expect(bids[0].meta.advertiserDomains).to.deep.equal(ADOMAINS); - expect(bids[0].meta.dsa).to.equal(dsa); - expect(bids[0].meta.primaryCatId).to.equal('IAB123'); - }); - - it('should return complete bid response with empty adomain', function () { - const ADOMAINS = []; - - const serverResponse = { - body: { - decisions: { - '2f95c00074b931': { - adId: '0', - contents: [ - { - body: '<<<---- Creative --->>>' - } - ], - height: '250', - width: '300', - pricing: { - clearPrice: 11.899999999999999 - } - } - } - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - - expect(bids).to.be.lengthOf(1); - expect(bids[0].cpm).to.equal(11.899999999999999); - expect(bids[0].width).to.equal('300'); - expect(bids[0].height).to.equal('250'); - expect(bids[0].ad).to.have.length.above(1); - expect(bids[0].meta.advertiserDomains).to.deep.equal(ADOMAINS); - }); - - it('should return empty bid response', function () { - const serverResponse = { - body: { - decisions: [] - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - expect(bids).to.be.lengthOf(0); - }); - - it('should return empty bid response on incorrect size', function () { - const serverResponse = { - body: { - decisions: { - '2f95c00074b931': { - adId: '0', - contents: [ - { - body: '<<<---- Creative --->>>' - } - ], - height: '160', - width: '600', - pricing: { - clearPrice: 0 - } - } - } - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - expect(bids).to.be.lengthOf(0); - }); - - it('should return empty bid response on 0 cpm', function () { - const serverResponse = { - body: { - decisions: { - '2f95c00074b931': { - adId: '0', - contents: [ - { - body: '<<<---- Creative --->>>' - } - ], - height: '300', - width: '250', - pricing: { - clearPrice: 0 - } - } - } - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - expect(bids).to.be.lengthOf(0); - }); - - it('should process a deal id', function () { - const serverResponse = { - body: { - decisions: { - '2f95c00074b931': { - adId: '0', - dealid: 'ABC90210', - contents: [ - { - body: '<<<---- Creative --->>>' - } - ], - height: '300', - width: '250', - pricing: { - clearPrice: 11.899999999999999 - } - } - } - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - expect(bids).to.be.lengthOf(1); - expect(bids[0].dealid).to.equal('ABC90210'); - }); - }); - }); - - describe('GPP Sync', function() { - it('should concatenate gppString and applicableSections values in the returned image url', () => { - const gppConsent = { gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', applicableSections: [5] }; - const result = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, undefined, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'image', - url: `https://sync.connectad.io/ImageSyncer?gpp=DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN&gpp_sid=5&` - }]); - }); - - it('should concatenate gppString and applicableSections values in the returned iFrame url', () => { - const gppConsent = { gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', applicableSections: [5, 6] }; - const result = spec.getUserSyncs({iframeEnabled: true}, undefined, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', - url: `https://sync.connectad.io/iFrameSyncer?gpp=DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN&gpp_sid=5%2C6&` - }]); - }); - - it('should return url without Gpp consent if gppConsent is undefined', () => { - const result = spec.getUserSyncs({iframeEnabled: true}, undefined, undefined, undefined, undefined); - expect(result).to.deep.equal([{ - type: 'iframe', - url: `https://sync.connectad.io/iFrameSyncer?` - }]); - }); - - it('should return iFrame url without Gpp consent if gppConsent.gppString is undefined', () => { - const gppConsent = { applicableSections: ['5'] }; - const result = spec.getUserSyncs({iframeEnabled: true}, undefined, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', - url: `https://sync.connectad.io/iFrameSyncer?` - }]); - }); - }); - - describe('getUserSyncs', () => { - const testParams = [ - { - name: 'iframe/no gdpr or ccpa', - arguments: [{ iframeEnabled: true, pixelEnabled: false }, {}, null], - expect: { - type: 'iframe', - pixels: ['https://sync.connectad.io/iFrameSyncer?'] - } - }, - { - name: 'iframe/gdpr', - arguments: [{ iframeEnabled: true, pixelEnabled: false }, {}, {gdprApplies: true, consentString: '234234'}], - expect: { - type: 'iframe', - pixels: ['https://sync.connectad.io/iFrameSyncer?gdpr=1&gdpr_consent=234234&'] - } - }, - { - name: 'iframe/ccpa', - arguments: [{ iframeEnabled: true, pixelEnabled: true }, {}, null, 'YN12'], - expect: { - type: 'iframe', - pixels: ['https://sync.connectad.io/iFrameSyncer?us_privacy=YN12&'] - } - }, - { - name: 'iframe/ccpa & gdpr', - arguments: [{ iframeEnabled: true, pixelEnabled: false }, {}, {gdprApplies: true, consentString: '234234'}, 'YN12'], - expect: { - type: 'iframe', - pixels: ['https://sync.connectad.io/iFrameSyncer?gdpr=1&gdpr_consent=234234&us_privacy=YN12&'] - } - }, - { - name: 'image/ccpa & gdpr', - arguments: [{ iframeEnabled: false, pixelEnabled: true }, {}, {gdprApplies: true, consentString: '234234'}, 'YN12'], - expect: { - type: 'image', - pixels: ['https://sync.connectad.io/ImageSyncer?gdpr=1&gdpr_consent=234234&us_privacy=YN12&'] - } - }, - { - name: 'image/gdpr', - arguments: [{ iframeEnabled: false, pixelEnabled: true }, {}, {gdprApplies: true, consentString: '234234'}], - expect: { - type: 'image', - pixels: ['https://sync.connectad.io/ImageSyncer?gdpr=1&gdpr_consent=234234&'] - } - }, - { - name: 'should prioritize iframe over image for user sync', - arguments: [{ iframeEnabled: true, pixelEnabled: true }, {}, null], - expect: { - type: 'iframe', - pixels: ['https://sync.connectad.io/iFrameSyncer?'] - } - } - ]; - - for (let i = 0; i < testParams.length; i++) { - const currParams = testParams[i]; - it(currParams.name, function () { - const result = spec.getUserSyncs.apply(this, currParams.arguments); - expect(result).to.have.lengthOf(currParams.expect.pixels.length); - for (let ix = 0; ix < currParams.expect.pixels.length; ix++) { - expect(result[ix].url).to.equal(currParams.expect.pixels[ix]); - expect(result[ix].type).to.equal(currParams.expect.type); - } - }); - } - }); -}); diff --git a/test/spec/modules/consumableBidAdapter_spec.js b/test/spec/modules/consumableBidAdapter_spec.js deleted file mode 100644 index 51db64019..000000000 --- a/test/spec/modules/consumableBidAdapter_spec.js +++ /dev/null @@ -1,819 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/consumableBidAdapter.js'; -import {createBid} from 'src/bidfactory.js'; -import {config} from 'src/config.js'; -import {deepClone} from 'src/utils.js'; -import { createEidsArray } from 'modules/userId/eids.js'; - -const ENDPOINT = 'https://e.serverbid.com/api/v2'; -const SMARTSYNC_CALLBACK = 'serverbidCallBids'; - -const BIDDER_REQUEST_1 = { - bidderCode: 'consumable', - auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - bidRequest: [ - { - bidder: 'consumable', - params: { - networkId: '9969', - siteId: '730181', - unitId: '123456', - unitName: 'cnsmbl-unit' - }, - placementCode: 'header-bid-tag-1', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: '23acc48ad47af5', - auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: '92489f71-1bf2-49a0-adf9-000cea934729' - } - ], - gdprConsent: { - consentString: 'consent-test', - gdprApplies: false - }, - gppConsent: { - applicableSections: [1, 2], - gppString: 'consent-string' - }, - refererInfo: { - referer: 'http://example.com/page.html', - reachedTop: true, - numIframes: 2, - stack: [ - 'http://example.com/page.html', - 'http://example.com/iframe1.html', - 'http://example.com/iframe2.html' - ] - }, - ortb2: { - device: { - language: 'en' - }, - source: { - ext: { - schain: { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'indirectseller.com', - 'sid': '00001', - 'hp': 1 - }, - { - 'asi': 'indirectseller-2.com', - 'sid': '00002', - 'hp': 2 - }, - ] - } - } - } - } -}; - -const BIDDER_REQUEST_2 = { - bidderCode: 'consumable', - auctionId: 'a4713c32-3762-4798-b342-4ab810ca770d', - bidderRequestId: '109f2a181342a9', - bidRequest: [ - { - bidder: 'consumable', - params: { - networkId: 9969, - siteId: 730181, - unitId: 123456, - unitName: 'cnsmbl-unit' - }, - placementCode: 'div-gpt-ad-1487778092495-0', - mediaTypes: { - banner: { - sizes: [ - [728, 90], - [970, 90] - ] - } - }, - bidId: '2b0f82502298c9', - bidderRequestId: '109f2a181342a9', - auctionId: 'a4713c32-3762-4798-b342-4ab810ca770d' - }, - { - bidder: 'consumable', - params: { - networkId: 9969, - siteId: 730181, - unitId: 123456, - unitName: 'cnsmbl-unit' - }, - placementCode: 'div-gpt-ad-1487778092495-0', - mediaTypes: { - banner: { - sizes: [ - [728, 90], - [970, 90] - ] - } - }, - bidId: '123', - bidderRequestId: '109f2a181342a9', - auctionId: 'a4713c32-3762-4798-b342-4ab810ca770d' - } - ], - gdprConsent: { - consentString: 'consent-test', - gdprApplies: true - }, - refererInfo: { - referer: 'http://example.com/page.html', - reachedTop: true, - numIframes: 2, - stack: [ - 'http://example.com/page.html', - 'http://example.com/iframe1.html', - 'http://example.com/iframe2.html' - ] - }, - ortb2: { - device: { - language: 'en' - } - } -}; - -const BIDDER_REQUEST_VIDEO = { - bidderCode: 'consumable', - auctionId: 'a4713c32-3762-4798-b342-4ab810ca770d', - bidderRequestId: '109f2a181342a9', - bidRequest: [ - { - bidder: 'consumable', - params: { - networkId: 9969, - siteId: 730181, - unitId: 123456, - unitName: 'cnsmbl-unit' - }, - placementCode: 'div-gpt-ad-1487778092495-0', - mediaTypes: { - video: { - playerSize: [188, 106], - context: 'instream', - mimes: ['application/javascript', 'application/x-mpegurl', 'video/3gpp', 'video/mp4', 'video/mpeg', 'video/ogg', 'video/webm', 'video/x-m4v', 'video/x-ms-asf', 'video/x-ms-wmv', 'video/x-msvideo'], - minduration: 0, - maxduration: 120, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - api: [1, 2], - linearity: 1 - } - }, - bidId: '6202d555b2f94537', - bidderRequestId: '109f2a181342a9', - auctionId: 'a4713c32-3762-4798-b342-4ab810ca770d' - } - ], - gdprConsent: { - consentString: 'consent-test', - gdprApplies: true - }, - refererInfo: { - referer: 'http://example.com/page.html', - reachedTop: true, - numIframes: 2, - stack: [ - 'http://example.com/page.html', - 'http://example.com/iframe1.html', - 'http://example.com/iframe2.html' - ] - }, - ortb2: { - device: { - language: 'en' - } - } -}; - -const BIDDER_REQUEST_EMPTY = { - bidderCode: 'consumable', - auctionId: 'b06458ef-4fe5-4a0b-a61b-bccbcedb7b11', - bidderRequestId: '8c8006750b10fd', - bidRequest: [], - gdprConsent: { - consentString: 'consent-test', - gdprApplies: false - }, - ortb2: { - device: { - language: 'en' - } - } -}; - -const AD_SERVER_RESPONSE = { - 'headers': null, - 'body': { - 'user': { 'key': 'ue1-2d33e91b71e74929b4aeecc23f4376f1' }, - 'pixels': [{ 'type': 'image', 'url': '//sync.serverbid.com/ss/' }], - 'decisions': { - '2b0f82502298c9': { - 'adId': 2364764, - 'creativeId': 1950991, - 'flightId': 2788300, - 'campaignId': 542982, - 'clickUrl': 'https://e.serverbid.com/r', - 'impressionUrl': 'https://e.serverbid.com/i.gif', - 'contents': [{ - 'type': 'html', - 'body': '', - 'data': { - 'height': 90, - 'width': 728, - 'imageUrl': 'https://static.adzerk.net/Advertisers/b0ab77db8a7848c8b78931aed022a5ef.gif', - 'fileName': 'b0ab77db8a7848c8b78931aed022a5ef.gif' - }, - 'template': 'image' - }], - 'height': 90, - 'width': 728, - 'events': [], - 'pricing': {'price': 0.5, 'clearPrice': 0.5, 'revenue': 0.0005, 'rateType': 2, 'eCPM': 0.5} - }, - '123': { - 'adId': 2364764, - 'creativeId': 1950991, - 'flightId': 2788300, - 'campaignId': 542982, - 'clickUrl': 'https://e.serverbid.com/r', - 'impressionUrl': 'https://e.serverbid.com/i.gif', - 'contents': [{ - 'type': 'html', - 'body': '', - 'data': { - 'height': 90, - 'width': 728, - 'imageUrl': 'https://static.adzerk.net/Advertisers/b0ab77db8a7848c8b78931aed022a5ef.gif', - 'fileName': 'b0ab77db8a7848c8b78931aed022a5ef.gif' - }, - 'template': 'image' - }], - 'height': 90, - 'width': 728, - 'events': [], - 'pricing': {'price': 0.5, 'clearPrice': 0.5, 'revenue': 0.0005, 'rateType': 2, 'eCPM': 0.5} - } - } - } -}; - -const AD_SERVER_RESPONSE_2 = { - 'headers': null, - 'body': { - 'user': { 'key': 'ue1-2d33e91b71e74929b4aeecc23f4376f1' }, - 'pixels': [{ 'type': 'image', 'url': '//sync.serverbid.com/ss/' }], - 'bdr': 'notcx', - 'decisions': { - '2b0f82502298c9': { - 'adId': 2364764, - 'creativeId': 1950991, - 'flightId': 2788300, - 'campaignId': 542982, - 'clickUrl': 'https://e.serverbid.com/r', - 'impressionUrl': 'https://e.serverbid.com/i.gif', - 'contents': [{ - 'type': 'html', - 'body': '', - 'data': { - 'height': 90, - 'width': 728, - 'imageUrl': 'https://static.adzerk.net/Advertisers/b0ab77db8a7848c8b78931aed022a5ef.gif', - 'fileName': 'b0ab77db8a7848c8b78931aed022a5ef.gif' - }, - 'template': 'image' - }], - 'height': 90, - 'width': 728, - 'events': [], - 'pricing': {'price': 0.5, 'clearPrice': 0.5, 'revenue': 0.0005, 'rateType': 2, 'eCPM': 0.5}, - 'mediaType': 'banner', - 'cats': ['IAB1', 'IAB2', 'IAB3'], - 'networkId': 1234567, - }, - '123': { - 'adId': 2364764, - 'creativeId': 1950991, - 'flightId': 2788300, - 'campaignId': 542982, - 'clickUrl': 'https://e.serverbid.com/r', - 'impressionUrl': 'https://e.serverbid.com/i.gif', - 'contents': [{ - 'type': 'html', - 'body': '', - 'data': { - 'height': 90, - 'width': 728, - 'imageUrl': 'https://static.adzerk.net/Advertisers/b0ab77db8a7848c8b78931aed022a5ef.gif', - 'fileName': 'b0ab77db8a7848c8b78931aed022a5ef.gif' - }, - 'template': 'image' - }], - 'height': 90, - 'width': 728, - 'events': [], - 'pricing': {'price': 0.5, 'clearPrice': 0.5, 'revenue': 0.0005, 'rateType': 2, 'eCPM': 0.5}, - 'mediaType': 'banner', - 'cats': ['IAB1', 'IAB2'], - 'networkId': 2345678, - } - } - } -}; - -const AD_SERVER_RESPONSE_VIDEO_1 = { - 'headers': null, - 'body': { - 'user': { 'key': 'ue1-2d33e91b71e74929b4aeecc23f4376f1' }, - 'pixels': [{ 'type': 'image', 'url': '//sync.serverbid.com/ss/' }], - 'decisions': { - '6202d555b2f94537': { - 'adId': 3866158402, - 'creativeId': 'C1-somo-test-video', - 'width': 640, - 'height': 480, - 'pricing': { - 'clearPrice': 1.58 - }, - 'vastUrl': 'https://x.serverbid.com/rtb/v?auc=217c051d06b011ed9cbc72b17f01ec03&sc=1.575&s=22&a=9dcab16d340d664310c2135a76989fe946a9d46e5d5f24ff5e2f17bffbb7704a43638bd3f600951e&n=9&r=0&t=1658158906595', - 'uuid': 'f1e7287514ce11ed9c1de2b3ba87449a', - 'bidderName': 'consumable', - 'adomain': ['consumabletv.com'], - 'cats': ['IAB3-1'], - 'mediaType': 'video', - 'networkId': 1 - } - } - } -}; - -const AD_SERVER_RESPONSE_VIDEO_2 = { - 'headers': null, - 'body': { - 'user': { 'key': 'ue1-2d33e91b71e74929b4aeecc23f4376f1' }, - 'pixels': [{ 'type': 'image', 'url': '//sync.serverbid.com/ss/' }], - 'decisions': { - '6202d555b2f94537': { - 'adId': 3866158402, - 'creativeId': 'C1-somo-test-video', - 'width': 640, - 'height': 480, - 'pricing': { - 'clearPrice': 1.58 - }, - 'vastXml': '', - 'uuid': 'f1e7287514ce11ed9c1de2b3ba87449a', - 'bidderName': 'consumable', - 'adomain': ['consumabletv.com'], - 'cats': ['IAB3-1'], - 'mediaType': 'video', - 'networkId': 1 - } - } - } -}; - -const BUILD_REQUESTS_OUTPUT = { - method: 'POST', - url: 'https://e.serverbid.com/api/v2', - data: '', - bidRequest: BIDDER_REQUEST_2.bidRequest, - bidderRequest: BIDDER_REQUEST_2 -}; - -const BUILD_REQUESTS_VIDEO_OUTPUT = { - method: 'POST', - url: 'https://e.serverbid.com/api/v2', - data: '', - bidRequest: BIDDER_REQUEST_VIDEO.bidRequest, - bidderRequest: BIDDER_REQUEST_VIDEO -}; - -describe('Consumable BidAdapter', function () { - const adapter = spec; - - describe('bid request validation', function () { - it('should accept valid bid requests', function () { - const bid = { - bidder: 'consumable', - params: { - networkId: '9969', - siteId: '123', - unitId: '123456', - unitName: 'cnsmbl-unit' - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should accept valid bid requests with extra fields', function () { - const bid = { - bidder: 'consumable', - params: { - networkId: '9969', - siteId: '123', - unitId: '123456', - unitName: 'cnsmbl-unit', - zoneId: '123' - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should reject bid requests without siteId', function () { - const bid = { - bidder: 'consumable', - params: { - networkId: '9969', - unitId: '123456', - unitName: 'cnsmbl-unit' - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should reject bid requests without networkId', function () { - const bid = { - bidder: 'consumable', - params: { - siteId: '9969', - unitId: '123456', - unitName: 'cnsmbl-unit' - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests validation', function () { - it('creates request data', function () { - const request = spec.buildRequests(BIDDER_REQUEST_1.bidRequest, BIDDER_REQUEST_1); - - expect(request).to.exist.and.to.be.a('object'); - }); - - it('request to consumable should contain a url', function () { - const request = spec.buildRequests(BIDDER_REQUEST_1.bidRequest, BIDDER_REQUEST_1); - - expect(request.url).to.have.string('serverbid.com'); - }); - - it('requires valid bids to make request', function () { - const request = spec.buildRequests(BIDDER_REQUEST_EMPTY.bidRequest, BIDDER_REQUEST_EMPTY); - expect(request.bidRequest).to.be.empty; - }); - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(BIDDER_REQUEST_1.bidRequest, BIDDER_REQUEST_1); - - expect(request.method).to.have.string('POST'); - }); - - it('passes through bidderRequest', function () { - const request = spec.buildRequests(BIDDER_REQUEST_1.bidRequest, BIDDER_REQUEST_1); - - expect(request.bidderRequest).to.equal(BIDDER_REQUEST_1); - }); - - it('should contain schain if it exists in the bidRequest', function () { - const request = spec.buildRequests(BIDDER_REQUEST_1.bidRequest, BIDDER_REQUEST_1); - const data = JSON.parse(request.data); - - expect(data.schain).to.deep.equal(BIDDER_REQUEST_1.ortb2.source.ext.schain) - }); - - it('should not contain schain if it does not exist in the bidRequest', function () { - const request = spec.buildRequests(BIDDER_REQUEST_2.bidRequest, BIDDER_REQUEST_2); - const data = JSON.parse(request.data); - - expect(data.schain).to.be.undefined; - }); - - it('should contain coppa if configured', function () { - config.setConfig({ coppa: true }); - const request = spec.buildRequests(BIDDER_REQUEST_1.bidRequest, BIDDER_REQUEST_1); - const data = JSON.parse(request.data); - - expect(data.coppa).to.be.true; - }); - - it('should not contain coppa if not configured', function () { - config.setConfig({ coppa: false }); - const request = spec.buildRequests(BIDDER_REQUEST_1.bidRequest, BIDDER_REQUEST_1); - const data = JSON.parse(request.data); - - expect(data.coppa).to.be.undefined; - }); - - it('should contain video object for video requests', function () { - const request = spec.buildRequests(BIDDER_REQUEST_VIDEO.bidRequest, BIDDER_REQUEST_VIDEO); - const data = JSON.parse(request.data); - - expect(data.placements[0].video).to.deep.equal(BIDDER_REQUEST_VIDEO.bidRequest[0].mediaTypes.video); - }); - - it('sets bidfloor param if present', function () { - const bidderRequest1 = deepClone(BIDDER_REQUEST_1); - const bidderRequest2 = deepClone(BIDDER_REQUEST_2); - bidderRequest1.bidRequest[0].params.bidFloor = 0.05; - bidderRequest2.bidRequest[0].getFloor = function() { - return { - currency: 'USD', - floor: 0.15 - } - }; - const request1 = spec.buildRequests(bidderRequest1.bidRequest, BIDDER_REQUEST_1); - const data1 = JSON.parse(request1.data); - const request2 = spec.buildRequests(bidderRequest2.bidRequest, BIDDER_REQUEST_2); - const data2 = JSON.parse(request2.data); - - expect(data1.placements[0].bidfloor).to.equal(0.05); - expect(data2.placements[0].bidfloor).to.equal(0.15); - }); - it('should contain the language param', function () { - const request = spec.buildRequests(BIDDER_REQUEST_1.bidRequest, BIDDER_REQUEST_1); - const data = JSON.parse(request.data); - - expect(data.lang).to.equal('en'); - }); - }); - describe('interpretResponse validation', function () { - it('response should have valid bidderCode', function () { - const bidRequest = spec.buildRequests(BIDDER_REQUEST_2.bidRequest, BIDDER_REQUEST_2); - const bid = createBid(bidRequest.bidRequest[0]); - - expect(bid.bidderCode).to.equal('consumable'); - }); - - it('response should include objects for all bids', function () { - const bids = spec.interpretResponse(AD_SERVER_RESPONSE, BUILD_REQUESTS_OUTPUT); - expect(bids.length).to.equal(2); - }); - - it('registers bids', function () { - const bids = spec.interpretResponse(AD_SERVER_RESPONSE_2, BUILD_REQUESTS_OUTPUT); - bids.forEach(b => { - expect(b).to.have.property('cpm'); - expect(b.cpm).to.be.above(0); - expect(b).to.have.property('requestId'); - expect(b).to.have.property('unitId'); - expect(b).to.have.property('unitName'); - expect(b).to.have.property('cpm'); - expect(b).to.have.property('width'); - expect(b).to.have.property('height'); - expect(b).to.have.property('ad'); - expect(b).to.have.property('currency', 'USD'); - expect(b).to.have.property('creativeId'); - expect(b).to.have.property('ttl', 30); - expect(b).to.have.property('netRevenue', true); - expect(b).to.have.property('referrer'); - expect(b.meta).to.have.property('advertiserDomains'); - expect(b.meta).to.have.property('primaryCatId'); - expect(b.meta).to.have.property('secondaryCatIds'); - expect(b.meta).to.have.property('networkId'); - expect(b.meta).to.have.property('mediaType'); - }); - }); - - it('registers video bids with vastUrl', function () { - const bids = spec.interpretResponse(AD_SERVER_RESPONSE_VIDEO_1, BUILD_REQUESTS_VIDEO_OUTPUT); - - bids.forEach(b => { - expect(b.mediaType).to.equal('video'); - expect(b.meta).to.have.property('mediaType', 'video'); - expect(b.vastUrl).to.equal('https://x.serverbid.com/rtb/v?auc=217c051d06b011ed9cbc72b17f01ec03&sc=1.575&s=22&a=9dcab16d340d664310c2135a76989fe946a9d46e5d5f24ff5e2f17bffbb7704a43638bd3f600951e&n=9&r=0&t=1658158906595'); - expect(b.vastXml).to.be.undefined; - expect(b.videoCacheKey).to.equal('f1e7287514ce11ed9c1de2b3ba87449a'); - }); - }) - - it('registers video bids with vastXml', function () { - const bids = spec.interpretResponse(AD_SERVER_RESPONSE_VIDEO_2, BUILD_REQUESTS_VIDEO_OUTPUT); - - bids.forEach(b => { - expect(b.mediaType).to.equal('video'); - expect(b.meta).to.have.property('mediaType', 'video'); - expect(b.vastXml).to.equal(''); - expect(b.vastUrl).to.be.undefined; - expect(b.ad).to.equal(''); - expect(b.videoCacheKey).to.equal('f1e7287514ce11ed9c1de2b3ba87449a'); - }); - }) - - it('handles nobid responses', function () { - const EMPTY_RESP = Object.assign({}, AD_SERVER_RESPONSE, {'body': {'decisions': null}}) - const bids = spec.interpretResponse(EMPTY_RESP, BUILD_REQUESTS_OUTPUT); - - expect(bids).to.be.empty; - }); - - it('handles no server response', function () { - const bids = spec.interpretResponse(null, BUILD_REQUESTS_OUTPUT); - - expect(bids).to.be.empty; - }); - }); - describe('getUserSyncs', function () { - const syncOptions = {'iframeEnabled': true}; - - it('handles empty sync options', function () { - const opts = spec.getUserSyncs({}); - - expect(opts).to.be.undefined; - }); - - it('should return a sync url if iframe syncs are enabled', function () { - const opts = spec.getUserSyncs(syncOptions); - - expect(opts.length).to.equal(1); - }); - - it('should return a sync url if iframe syncs are enabled and server response is empty', function () { - const opts = spec.getUserSyncs(syncOptions, []); - - expect(opts.length).to.equal(1); - }); - - it('should return a sync url if iframe syncs are enabled and server response does not contain a bdr attribute', function () { - const opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE]); - - expect(opts.length).to.equal(1); - }); - - it('should return a sync url if iframe syncs are enabled and server response contains a bdr attribute that is not cx', function () { - const opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE_2]); - - expect(opts.length).to.equal(1); - }); - - it('should return a sync url if iframe syncs are enabled and GDPR applies', function () { - const gdprConsent = { - consentString: 'GDPR_CONSENT_STRING', - gdprApplies: true, - } - const opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE], gdprConsent); - - expect(opts.length).to.equal(1); - expect(opts[0].url).to.equal('https://sync.serverbid.com/ss/730181.html?gdpr=1&gdpr_consent=GDPR_CONSENT_STRING'); - }) - - it('should return a sync url if iframe syncs are enabled and GDPR is undefined', function () { - const gdprConsent = { - consentString: 'GDPR_CONSENT_STRING', - gdprApplies: undefined, - } - const opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE], gdprConsent); - - expect(opts.length).to.equal(1); - expect(opts[0].url).to.equal('https://sync.serverbid.com/ss/730181.html?gdpr=0&gdpr_consent=GDPR_CONSENT_STRING'); - }) - - it('should return a sync url if iframe syncs are enabled and has GPP consent with applicable sections', function () { - const gppConsent = { - applicableSections: [1, 2], - gppString: 'GPP_CONSENT_STRING' - } - const opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE], {}, '', gppConsent); - - expect(opts.length).to.equal(1); - expect(opts[0].url).to.equal('https://sync.serverbid.com/ss/730181.html?gpp=GPP_CONSENT_STRING&gpp_sid=1%2C2'); - }) - - it('should return a sync url if iframe syncs are enabled and has GPP consent without applicable sections', function () { - const gppConsent = { - applicableSections: [], - gppString: 'GPP_CONSENT_STRING' - } - const opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE], {}, '', gppConsent); - - expect(opts.length).to.equal(1); - expect(opts[0].url).to.equal('https://sync.serverbid.com/ss/730181.html?gpp=GPP_CONSENT_STRING'); - }) - - it('should return a sync url if iframe syncs are enabled and USP applies', function () { - const uspConsent = 'USP_CONSENT_STRING'; - const opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE], {}, uspConsent); - - expect(opts.length).to.equal(1); - expect(opts[0].url).to.equal('https://sync.serverbid.com/ss/730181.html?us_privacy=USP_CONSENT_STRING'); - }) - - it('should return a sync url if iframe syncs are enabled, GDPR and USP applies', function () { - const gdprConsent = { - consentString: 'GDPR_CONSENT_STRING', - gdprApplies: true, - } - const uspConsent = 'USP_CONSENT_STRING'; - const opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE], gdprConsent, uspConsent); - - expect(opts.length).to.equal(1); - expect(opts[0].url).to.equal('https://sync.serverbid.com/ss/730181.html?gdpr=1&gdpr_consent=GDPR_CONSENT_STRING&us_privacy=USP_CONSENT_STRING'); - }) - - it('should return a sync url if pixel syncs are enabled and some are returned from the server', function () { - const syncOptions = {'pixelEnabled': true}; - const opts = spec.getUserSyncs(syncOptions, [AD_SERVER_RESPONSE]); - - expect(opts.length).to.equal(1); - }); - }); - describe('unifiedId from userId module', function() { - let sandbox, bidderRequest; - beforeEach(() => { - sandbox = sinon.createSandbox(); - bidderRequest = deepClone(BIDDER_REQUEST_1); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('Request should have EIDs', function() { - bidderRequest.bidRequest[0].userId = {}; - bidderRequest.bidRequest[0].userId.tdid = 'TTD_ID'; - bidderRequest.bidRequest[0].userIdAsEids = [{ - 'source': 'adserver.org', - 'uids': [{ - 'id': 'TTD_ID_FROM_USER_ID_MODULE', - 'atype': 1, - 'ext': { - 'rtiPartner': 'TDID' - } - }] - }]; - const request = spec.buildRequests(bidderRequest.bidRequest, BIDDER_REQUEST_1); - const data = JSON.parse(request.data); - expect(data.user.eids).to.deep.equal(bidderRequest.bidRequest[0].userIdAsEids); - }); - - it('Request should remove non-objects for userIdAsEids', function () { - bidderRequest.bidRequest[0].userId = {}; - bidderRequest.bidRequest[0].userId.tdid = 'TTD_ID'; - bidderRequest.bidRequest[0].userIdAsEids = [ - { - source: 'adserver.org', - uids: [ - { - id: 'TTD_ID_FROM_USER_ID_MODULE', - atype: 1, - ext: { - rtiPartner: 'TDID', - }, - }, - ], - }, - 'RANDOM_IDENTIFIER_STRING' - ]; - const scrubbedEids = [ - { - source: 'adserver.org', - uids: [ - { - id: 'TTD_ID_FROM_USER_ID_MODULE', - atype: 1, - ext: { - rtiPartner: 'TDID', - }, - }, - ], - }, - ]; - const request = spec.buildRequests( - bidderRequest.bidRequest, - BIDDER_REQUEST_1 - ); - const data = JSON.parse(request.data); - expect(data.user.eids).to.deep.equal( - scrubbedEids - ); - }); - - it('Request should NOT have adsrvrOrgId params if userId is NOT object', function() { - const request = spec.buildRequests(bidderRequest.bidRequest, BIDDER_REQUEST_1); - const data = JSON.parse(request.data); - expect(data.user.eids).to.deep.equal(undefined); - }); - - it('Request should NOT have adsrvrOrgId params if userId.tdid is NOT string', function() { - bidderRequest.bidRequest[0].userId = { - tdid: 1234 - }; - const request = spec.buildRequests(bidderRequest.bidRequest, BIDDER_REQUEST_1); - const data = JSON.parse(request.data); - expect(data.user.eids).to.deep.equal(undefined); - }); - }); -}); diff --git a/test/spec/modules/contentexchangeBidAdapter_spec.js b/test/spec/modules/contentexchangeBidAdapter_spec.js deleted file mode 100644 index 12a4c6c5d..000000000 --- a/test/spec/modules/contentexchangeBidAdapter_spec.js +++ /dev/null @@ -1,516 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/contentexchangeBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'contentexchange'; - -describe('ContentexchangeBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://eu2.adnetwork.agency/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync2.adnetwork.agency/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync2.adnetwork.agency/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync2.adnetwork.agency/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/contxtfulBidAdapter_spec.js b/test/spec/modules/contxtfulBidAdapter_spec.js deleted file mode 100644 index f0695130b..000000000 --- a/test/spec/modules/contxtfulBidAdapter_spec.js +++ /dev/null @@ -1,1008 +0,0 @@ -import { spec, safeStringify } from 'modules/contxtfulBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import * as ajax from 'src/ajax.js'; -const VERSION = 'v1'; -const CUSTOMER = 'CUSTOMER'; -const BIDDER_ENDPOINT = 'prebid.receptivity.io'; -const RX_FROM_API = { ReceptivityState: 'Receptive', test_info: 'rx_from_engine' }; - -describe('contxtful bid adapter', function () { - const adapter = newBidder(spec); - let sandbox; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - - afterEach(function () { - sandbox.restore(); - }); - - describe('SafeStringify function', function () { - it('should stringify normal objects successfully', function () { - const normalObject = { name: 'test', value: 123, active: true }; - const result = safeStringify(normalObject); - expect(result).to.equal('{"name":"test","value":123,"active":true}'); - }); - - it('should handle arrays correctly', function () { - const array = [1, 2, 'three', { nested: true }]; - const result = safeStringify(array); - expect(result).to.equal('[1,2,"three",{"nested":true}]'); - }); - - it('should handle circular references', function () { - const objA = { name: 'A' }; - const objB = { name: 'B', ref: objA }; - objA.ref = objB; // Create circular reference - - const result = safeStringify(objA); - expect(result).to.be.a('string'); - expect(result).to.include('[Circular]'); - expect(result).to.include('"name":"A"'); - }); - - it('should handle functions by omitting them (standard JSON.stringify behavior)', function () { - const objWithFunction = { - name: 'test', - method: function () { return 'hello'; }, - arrow: () => 'world' - }; - - const result = safeStringify(objWithFunction); - expect(result).to.equal('{"name":"test"}'); - expect(result).to.not.include('[Function]'); - }); - - it('should handle undefined values by omitting them (standard JSON.stringify behavior)', function () { - const objWithUndefined = { - name: 'test', - undefinedValue: undefined, - nullValue: null - }; - - const result = safeStringify(objWithUndefined); - expect(result).to.equal('{"name":"test","nullValue":null}'); - expect(result).to.not.include('[Undefined]'); - }); - - it('should handle mixed complex objects', function () { - const complexObj = { - string: 'test', - number: 42, - boolean: true, - nullVal: null, - undefinedVal: undefined, - func: function () { return 'test'; }, - nested: { - array: [1, 2, function () { }], - date: new Date('2023-01-01') - } - }; - - const result = safeStringify(complexObj); - expect(result).to.be.a('string'); - expect(result).to.include('"string":"test"'); - expect(result).to.include('"number":42'); - // Functions and undefined values are omitted by standard JSON.stringify - expect(result).to.not.include('[Function]'); - expect(result).to.not.include('[Undefined]'); - }); - - it('should handle nested circular references', function () { - const parent = { name: 'parent', children: [] }; - const child1 = { name: 'child1', parent: parent }; - const child2 = { name: 'child2', parent: parent }; - parent.children.push(child1, child2); - - const result = safeStringify(parent); - expect(result).to.be.a('string'); - expect(result).to.include('[Circular]'); - expect(result).to.include('"name":"parent"'); - }); - - it('should handle empty objects and arrays', function () { - expect(safeStringify({})).to.equal('{}'); - expect(safeStringify([])).to.equal('[]'); - }); - - it('should handle primitive values', function () { - expect(safeStringify('string')).to.equal('"string"'); - expect(safeStringify(123)).to.equal('123'); - expect(safeStringify(true)).to.equal('true'); - expect(safeStringify(null)).to.equal('null'); - }); - - it('should handle Date objects', function () { - const date = new Date('2023-01-01T00:00:00.000Z'); - const result = safeStringify(date); - expect(result).to.include('2023-01-01'); - }); - - it('should handle bigint values by converting them to strings', function () { - const objWithBigInt = { - name: 'test', - bigNumber: BigInt('12345678901234567890'), - regularNumber: 123 - }; - - const result = safeStringify(objWithBigInt); - expect(result).to.include('"bigNumber":"12345678901234567890"'); - expect(result).to.include('"name":"test"'); - expect(result).to.include('"regularNumber":123'); - }); - - it('should handle objects with toJSON methods', function () { - const objWithToJSON = { - name: 'test', - toJSON: function () { - return { serialized: true }; - } - }; - - const result = safeStringify(objWithToJSON); - expect(result).to.equal('{"serialized":true}'); - }); - - it('should fall back to safeJSONEncode for completely unstringifiable objects', function () { - // Mock an object that breaks JSON.stringify even with replacer - const problematicObj = {}; - Object.defineProperty(problematicObj, 'problematic', { - get: function () { - throw new Error('Cannot access this property'); - }, - enumerable: true - }); - - const result = safeStringify(problematicObj); - // Should not throw and should return a string - expect(result).to.be.a('string'); - }); - - it('should handle browser Window objects safely', function () { - const objWithWindow = { - name: 'test', - windowRef: window - }; - - const result = safeStringify(objWithWindow); - expect(result).to.include('[Browser Object]'); - expect(result).to.include('"name":"test"'); - }); - - it('should handle objects with inaccessible properties', function () { - const problematicObj = { - name: 'test', - safeData: 'value', - normalProperty: 'normal' - }; - - // Instead of testing property access errors (which can break entire stringify), - // let's test that the function handles objects that contain browser objects - // which should be converted to [Inaccessible Object] or [Browser Object] - if (typeof window !== 'undefined') { - problematicObj.browserRef = window; - } - - const result = safeStringify(problematicObj); - expect(result).to.be.a('string'); - expect(result).to.include('"name":"test"'); - expect(result).to.include('"safeData":"value"'); - expect(result).to.include('"normalProperty":"normal"'); - - if (typeof window !== 'undefined') { - expect(result).to.include('[Browser Object]'); - } - }); - - it('should handle mixed problematic objects', function () { - const mixedObj = { - normal: 'value', - windowRef: window, - circular: null - }; - mixedObj.circular = mixedObj; // Create circular reference - - const result = safeStringify(mixedObj); - expect(result).to.include('[Browser Object]'); - expect(result).to.include('[Circular]'); - expect(result).to.include('"normal":"value"'); - }); - - it('should handle IMA3 video renderer objects safely', function () { - // Simulate the IMA3 video renderer object with simpler structure - const ima3RendererObj = { - url: "https://imasdk.googleapis.com/js/sdkloader/ima3.js", - renderNow: false, - cmd: [null], - someData: "test" - }; - - // Add a simple browser object reference that should be detected - if (typeof window !== 'undefined') { - ima3RendererObj.windowRef = window; - } - - const result = safeStringify(ima3RendererObj); - expect(result).to.be.a('string'); - expect(result).to.include('"url":"https://imasdk.googleapis.com/js/sdkloader/ima3.js"'); - expect(result).to.include('"renderNow":false'); - expect(result).to.include('"someData":"test"'); - if (typeof window !== 'undefined') { - expect(result).to.include('[Browser Object]'); // for window reference - } - }); - - it('should handle complex nested objects with mixed browser elements', function () { - const complexBidData = { - bidId: 'test-bid-123', - adUnitCode: 'div-ad-unit', - cpm: 1.25, - currency: 'USD', - renderer: { - url: "https://imasdk.googleapis.com/js/sdkloader/ima3.js", - renderNow: false, - cmd: [null] - }, - sizes: [[300, 250], [728, 90]] - }; - - // Add browser objects that should be detected by current implementation - if (typeof window !== 'undefined') { - complexBidData.windowContext = window; - } - if (typeof document !== 'undefined') { - complexBidData.documentRef = document; - } - - const result = safeStringify(complexBidData); - expect(result).to.be.a('string'); - expect(result).to.include('"bidId":"test-bid-123"'); - expect(result).to.include('"cpm":1.25'); - if (typeof window !== 'undefined' || typeof document !== 'undefined') { - expect(result).to.include('[Browser Object]'); - } - }); - - it('should handle additional browser objects safely', function () { - const objWithBrowserObjects = { - name: 'test' - }; - - // Only test browser objects that are detected by current implementation - if (typeof window !== 'undefined') { - objWithBrowserObjects.windowRef = window; - } - if (typeof document !== 'undefined') { - objWithBrowserObjects.documentRef = document; - } - - const result = safeStringify(objWithBrowserObjects); - expect(result).to.be.a('string'); - expect(result).to.include('"name":"test"'); - - // Current implementation only detects Window, Document, HTMLElement, Node - // It doesn't detect navigator, location, etc. as browser objects - if (typeof window !== 'undefined' || typeof document !== 'undefined') { - expect(result).to.include('[Browser Object]'); - } - }); - - it('should handle event objects and DOM-related objects', function () { - const objWithDOMObjects = { - bidId: 'test-123', - data: 'normal-data' - }; - - // Add DOM element if available in test environment - if (typeof document !== 'undefined') { - const div = document.createElement('div'); - objWithDOMObjects.element = div; - } - - // Simulate an event object - if (typeof Event !== 'undefined') { - try { - objWithDOMObjects.event = new Event('click'); - } catch (e) { - // Some test environments might not support Event constructor - objWithDOMObjects.event = { type: 'click', target: null }; - } - } - - const result = safeStringify(objWithDOMObjects); - expect(result).to.be.a('string'); - expect(result).to.include('"bidId":"test-123"'); - expect(result).to.include('"data":"normal-data"'); - }); - - it('should handle storage and web API objects safely', function () { - const objWithWebAPIs = { - name: 'test-data', - normalArray: [1, 2, 3] - }; - - // Add storage references if available - if (typeof globalThis.localStorage !== 'undefined') { - objWithWebAPIs.storage = globalThis.localStorage; - } - - // Add Blob if available - if (typeof Blob !== 'undefined') { - try { - objWithWebAPIs.blob = new Blob(['test'], { type: 'text/plain' }); - } catch (e) { - // Fallback if Blob not available in test environment - } - } - - const result = safeStringify(objWithWebAPIs); - expect(result).to.be.a('string'); - expect(result).to.include('"name":"test-data"'); - expect(result).to.include('"normalArray":[1,2,3]'); - // Should handle browser objects without throwing - expect(result).to.not.throw; - }); - - it('should detect browser objects using parent hierarchies and duck typing', function () { - const testObj = { - normalData: 'safe-value', - number: 42 - }; - - // Add various types of browser objects that should be caught by parent classes - if (typeof document !== 'undefined') { - testObj.element = document.createElement('div'); // HTMLElement -> EventTarget - testObj.textNode = document.createTextNode('test'); // Text -> Node - } - - // Add objects that should be caught by duck typing (constructor name patterns) - const mockObjects = []; - - // Mock HTMLCanvasElement (constructor name contains 'HTML' and 'Canvas') - function HTMLCanvasElement() {} - const mockCanvas = Object.create(HTMLCanvasElement.prototype); - Object.defineProperty(mockCanvas, 'constructor', { value: HTMLCanvasElement }); - testObj.mockCanvas = mockCanvas; - - // Mock CSSStyleDeclaration (constructor name contains 'CSS') - function CSSStyleDeclaration() {} - const mockStyle = Object.create(CSSStyleDeclaration.prototype); - Object.defineProperty(mockStyle, 'constructor', { value: CSSStyleDeclaration }); - testObj.mockStyle = mockStyle; - - const result = safeStringify(testObj); - expect(result).to.be.a('string'); - expect(result).to.include('"normalData":"safe-value"'); - expect(result).to.include('"number":42'); - expect(result).to.include('[Browser Object]'); - - // Should not contain the actual browser object data - expect(result).to.not.include('HTMLCanvasElement'); - expect(result).to.not.include('CSSStyleDeclaration'); - }); - - it('should detect objects with browser-like properties using duck typing', function () { - const testObj = { - safeData: 'value' - }; - - // Add actual browser objects that the current implementation can detect - if (typeof document !== 'undefined') { - const div = document.createElement('div'); - testObj.element = div; // HTMLElement should be detected - } - - if (typeof window !== 'undefined') { - testObj.windowRef = window; // Window should be detected - } - - const result = safeStringify(testObj); - expect(result).to.be.a('string'); - expect(result).to.include('"safeData":"value"'); - - // Only expect [Browser Object] if we actually added detectable browser objects - if (typeof document !== 'undefined' || typeof window !== 'undefined') { - expect(result).to.include('[Browser Object]'); - } - }); - - it('should exclude specified keys when keysToExclude parameter is provided', function () { - const testObj = { - bidId: 'test-123', - cpm: 1.25, - renderer: { - url: 'https://example.com/renderer.js', - handlers: { onLoad: function() {} } - }, - ad: '
Ad content
', - meta: { - advertiserDomains: ['example.com'] - } - }; - - const result = safeStringify(testObj, ['renderer']); - expect(result).to.be.a('string'); - expect(result).to.include('"bidId":"test-123"'); - expect(result).to.include('"cpm":1.25'); - expect(result).to.include('"ad":"
Ad content
"'); - expect(result).to.include('[Excluded]'); // renderer should be excluded - expect(result).to.not.include('https://example.com/renderer.js'); - }); - - it('should exclude multiple keys when multiple keys are specified', function () { - const testObj = { - bidId: 'test-456', - renderer: { url: 'renderer.js' }, - ad: '', - privateData: 'sensitive', - normalData: 'safe' - }; - - const result = safeStringify(testObj, ['renderer', 'privateData']); - expect(result).to.be.a('string'); - expect(result).to.include('"bidId":"test-456"'); - expect(result).to.include('"normalData":"safe"'); - expect(result).to.include('[Excluded]'); // Both excluded keys should show this - expect(result).to.not.include('renderer.js'); - expect(result).to.not.include('sensitive'); - // ad should still be included since it's not in exclude list - expect(result).to.include('"ad":""'); - }); - - it('should exclude keys at any nesting level', function () { - const testObj = { - bid: { - id: 'test-789', - renderer: { - url: 'nested-renderer.js', - config: { timeout: 5000 } - }, - meta: { - renderer: 'should also be excluded' - } - }, - topLevel: 'value' - }; - - const result = safeStringify(testObj, ['renderer']); - expect(result).to.be.a('string'); - expect(result).to.include('"id":"test-789"'); - expect(result).to.include('"topLevel":"value"'); - expect(result).to.include('[Excluded]'); // Both renderer keys should be excluded - expect(result).to.not.include('nested-renderer.js'); - expect(result).to.not.include('should also be excluded'); - }); - - it('should work correctly when keysToExclude is empty array', function () { - const testObj = { - bidId: 'test-empty', - renderer: { url: 'renderer.js' }, - normalData: 'value' - }; - - const result = safeStringify(testObj, []); - expect(result).to.be.a('string'); - expect(result).to.include('"bidId":"test-empty"'); - expect(result).to.include('"normalData":"value"'); - expect(result).to.include('renderer.js'); // Should not be excluded - expect(result).to.not.include('[Excluded]'); - }); - - it('should work correctly when keysToExclude parameter is not provided', function () { - const testObj = { - bidId: 'test-no-param', - renderer: { url: 'renderer.js' }, - normalData: 'value' - }; - - const result = safeStringify(testObj); // No second parameter - expect(result).to.be.a('string'); - expect(result).to.include('"bidId":"test-no-param"'); - expect(result).to.include('"normalData":"value"'); - expect(result).to.include('renderer.js'); // Should not be excluded - expect(result).to.not.include('[Excluded]'); - }); - - it('should combine key exclusion with browser object detection', function () { - const testObj = { - bidId: 'test-combined', - renderer: { - url: 'renderer.js', - windowRef: window, - handlers: {} - }, - windowRef: window, - normalData: 'safe' - }; - - const result = safeStringify(testObj, ['renderer']); - expect(result).to.be.a('string'); - expect(result).to.include('"bidId":"test-combined"'); - expect(result).to.include('"normalData":"safe"'); - expect(result).to.include('[Excluded]'); // renderer key excluded - expect(result).to.include('[Browser Object]'); // top-level windowRef detected as browser object - expect(result).to.not.include('renderer.js'); - }); - }); - - describe('is a functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('valid code', function () { - it('should return the bidder code of contxtful', function () { - expect(spec.code).to.eql('contxtful'); - }); - }); - - const bidRequests = - [ - { - bidder: 'contxtful', - bidId: 'bId1', - custom_param_1: 'value_1', - transactionId: 'tId1', - params: { - bcat: ['cat1', 'cat2'], - badv: ['adv1', 'adv2'], - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ] - }, - }, - ortb2Imp: { - ext: { - tid: 't-id-test-1', - gpid: 'gpid-id-unitest-1' - }, - }, - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'schain-seller-1.com', - sid: '00001', - hp: 1, - }, - ], - }, - getFloor: () => ({ currency: 'CAD', floor: 10 }), - } - ]; - - const expectedReceptivityData = { - rx: RX_FROM_API, - params: { - ev: VERSION, - ci: CUSTOMER, - }, - }; - - const bidderRequest = { - refererInfo: { - ref: 'https://my-referer-custom.com', - }, - ortb2: { - source: { - tid: 'auction-id', - }, - property_1: 'string_val_1', - regs: { - coppa: 1, - ext: { - us_privacy: '12345' - } - }, - user: { - data: [ - { - name: 'contxtful', - ext: expectedReceptivityData - } - ], - ext: { - eids: [ - { - source: 'id5-sync.com', - uids: [ - { - atype: 1, - id: 'fake-id5id', - }, - ] - } - ] - } - } - - }, - timeout: 1234, - uspConsent: '12345' - }; - - describe('valid configuration', function () { - const theories = [ - [ - null, - 'contxfulBidAdapter: contxtful.version should be a non-empty string', - 'null object for config', - ], - [ - {}, - 'contxfulBidAdapter: contxtful.version should be a non-empty string', - 'empty object for config', - ], - [ - { customer: CUSTOMER }, - 'contxfulBidAdapter: contxtful.version should be a non-empty string', - 'customer only in config', - ], - [ - { version: VERSION }, - 'contxfulBidAdapter: contxtful.customer should be a non-empty string', - 'version only in config', - ], - [ - { customer: CUSTOMER, version: '' }, - 'contxfulBidAdapter: contxtful.version should be a non-empty string', - 'empty string for version', - ], - [ - { customer: '', version: VERSION }, - 'contxfulBidAdapter: contxtful.customer should be a non-empty string', - 'empty string for customer', - ], - [ - { customer: '', version: '' }, - 'contxfulBidAdapter: contxtful.version should be a non-empty string', - 'empty string for version & customer', - ], - ]; - - theories.forEach(([params, expectedErrorMessage, description]) => { - it('detects invalid configuration and throws the expected error (' + description + ')', () => { - config.setConfig({ - contxtful: params - }); - expect(() => spec.buildRequests(bidRequests, { - auctionId: 'new-auction-id' - })).to.throw( - expectedErrorMessage - ); - }); - }); - - it('uses a valid configuration and returns the right url', () => { - config.setConfig({ - contxtful: { customer: CUSTOMER, version: VERSION } - }); - const bidRequest = spec.buildRequests(bidRequests); - expect(bidRequest.url).to.eq('https://' + BIDDER_ENDPOINT + `/${VERSION}/prebid/${CUSTOMER}/bid`) - }); - - it('will take specific ortb2 configuration parameters and returns it in ortb2 object', () => { - config.setConfig({ - contxtful: { customer: CUSTOMER, version: VERSION }, - }); - const bidRequest = spec.buildRequests(bidRequests, bidderRequest); - expect(bidRequest.data.ortb2.property_1).to.equal('string_val_1'); - }); - }); - - describe('valid bid request', function () { - config.setConfig({ - contxtful: { customer: CUSTOMER, version: VERSION }, - }); - const bidRequest = spec.buildRequests(bidRequests, bidderRequest); - - it('will return a data property containing properties ortb2, bidRequests, bidderRequest and config', () => { - expect(bidRequest.data).not.to.be.undefined; - expect(bidRequest.data.ortb2).not.to.be.undefined; - expect(bidRequest.data.bidRequests).not.to.be.undefined; - expect(bidRequest.data.bidderRequest).not.to.be.undefined; - expect(bidRequest.data.config).not.to.be.undefined; - }); - - it('will take custom parameters in the bid request and within the bidRequests array', () => { - expect(bidRequest.data.bidRequests[0].custom_param_1).to.equal('value_1') - }); - - it('will return any supply chain parameters within the bidRequests array', () => { - expect(bidRequest.data.bidRequests[0].schain.ver).to.equal('1.0'); - }); - - it('will return floor request within the bidFloor parameter in the bidRequests array', () => { - expect(bidRequest.data.bidRequests[0].bidFloor.currency).to.equal('CAD'); - expect(bidRequest.data.bidRequests[0].bidFloor.floor).to.equal(10); - }); - - it('will return the usp string in the uspConsent parameter within the bidderRequest property', () => { - expect(bidRequest.data.bidderRequest.uspConsent).to.equal('12345'); - }); - - it('will contains impressions array on ortb2.imp object for all ad units', () => { - expect(bidRequest.data.ortb2.imp.length).to.equal(1); - expect(bidRequest.data.ortb2.imp[0].id).to.equal('bId1'); - }); - - it('will contains the registration on ortb2.regs object', () => { - expect(bidRequest.data.ortb2.regs).not.to.be.undefined; - expect(bidRequest.data.ortb2.regs.coppa).to.equal(1); - expect(bidRequest.data.ortb2.regs.ext.us_privacy).to.equal('12345') - }) - - it('will contains the eids modules within the ortb2.user.ext.eids', () => { - expect(bidRequest.data.ortb2.user.ext.eids).not.to.be.undefined; - expect(bidRequest.data.ortb2.user.ext.eids[0].source).to.equal('id5-sync.com'); - expect(bidRequest.data.ortb2.user.ext.eids[0].uids[0].id).to.equal('fake-id5id'); - }); - - it('will contains the receptivity value within the ortb2.user.data with contxtful name', () => { - const obtained_receptivity_data = bidRequest.data.ortb2.user.data.filter(function (userData) { - return userData.name === 'contxtful'; - }); - expect(obtained_receptivity_data.length).to.equal(1); - expect(obtained_receptivity_data[0].ext).to.deep.equal(expectedReceptivityData); - }); - - it('will contains ortb2Imp of the bid request within the ortb2.imp.ext', () => { - const first_imp = bidRequest.data.ortb2.imp[0]; - expect(first_imp.ext).not.to.be.undefined; - expect(first_imp.ext.tid).to.equal('t-id-test-1'); - expect(first_imp.ext.gpid).to.equal('gpid-id-unitest-1'); - }); - }); - - describe('valid bid request with no floor module', () => { - const noFloorsBidRequests = - [ - { - bidder: 'contxtful', - bidId: 'bId1', - transactionId: 'tId1', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ] - }, - }, - }, - { - bidder: 'contxtful', - bidId: 'bId2', - transactionId: 'tId2', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ] - }, - }, - params: { - bidfloor: 54 - } - }, - ]; - - config.setConfig({ - contxtful: { customer: CUSTOMER, version: VERSION }, - }); - - const bidRequest = spec.buildRequests(noFloorsBidRequests, bidderRequest); - it('will contains default value of floor if the bid request do not contains floor function', () => { - expect(bidRequest.data.bidRequests[0].bidFloor.currency).to.equal('USD'); - expect(bidRequest.data.bidRequests[0].bidFloor.floor).to.equal(0); - }); - - it('will take the param.bidfloor as floor value if possible', () => { - expect(bidRequest.data.bidRequests[1].bidFloor.currency).to.equal('USD'); - expect(bidRequest.data.bidRequests[1].bidFloor.floor).to.equal(54); - }); - }); - - describe('valid bid response', () => { - const bidResponse = [ - { - 'requestId': 'arequestId', - 'originalCpm': 1.5, - 'cpm': 1.35, - 'currency': 'CAD', - 'width': 300, - 'height': 600, - 'creativeId': 'creativeid', - 'netRevenue': true, - 'ttl': 300, - 'ad': '', - 'mediaType': 'banner', - 'syncs': [ - { - 'url': 'mysyncurl.com?qparam1=qparamv1&qparam2=qparamv2' - } - ] - } - ]; - config.setConfig({ - contxtful: { customer: CUSTOMER, version: VERSION }, - }); - - const bidRequest = spec.buildRequests(bidRequests, bidderRequest); - - it('will interpret response correcly', () => { - const bids = spec.interpretResponse({ body: bidResponse }, bidRequest); - expect(bids).not.to.be.undefined; - expect(bids).to.have.lengthOf(1); - expect(bids).to.deep.equal(bidResponse); - }); - - it('will return empty response if bid response is empty', () => { - const bids = spec.interpretResponse({ body: [] }, bidRequest); - expect(bids).to.have.lengthOf(0); - }) - - it('will trigger user sync if enable pixel mode', () => { - const syncOptions = { - pixelEnabled: true - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [{ body: bidResponse }]); - expect(userSyncs).to.deep.equal([ - { - 'url': 'mysyncurl.com/image?pbjs=1&coppa=0&qparam1=qparamv1&qparam2=qparamv2', - 'type': 'image' - } - ]); - }); - - it('will trigger user sync if enable iframe mode', () => { - const syncOptions = { - iframeEnabled: true - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [{ body: bidResponse }]); - expect(userSyncs).to.deep.equal([ - { - 'url': 'mysyncurl.com/iframe?pbjs=1&coppa=0&qparam1=qparamv1&qparam2=qparamv2', - 'type': 'iframe' - } - ]); - }); - - describe('no sync option', () => { - it('will return image sync if no sync options', () => { - const userSyncs = spec.getUserSyncs({}, [{ body: bidResponse }]); - expect(userSyncs).to.deep.equal([ - { - 'url': 'mysyncurl.com/image?pbjs=1&coppa=0&qparam1=qparamv1&qparam2=qparamv2', - 'type': 'image' - } - ]); - }); - it('will return empty value if no server response', () => { - const userSyncs = spec.getUserSyncs({}, []); - expect(userSyncs).to.have.lengthOf(0); - const userSyncs2 = spec.getUserSyncs({}, null); - expect(userSyncs2).to.have.lengthOf(0); - }); - }); - - it('will return empty value if no server response', () => { - const syncOptions = { - iframeEnabled: true - }; - - const userSyncs = spec.getUserSyncs(syncOptions, []); - expect(userSyncs).to.have.lengthOf(0); - const userSyncs2 = spec.getUserSyncs(syncOptions, null); - expect(userSyncs2).to.have.lengthOf(0); - }); - - describe('onTimeout callback', () => { - it('will always call server with sendBeacon available', () => { - config.setConfig({ - contxtful: { customer: CUSTOMER, version: VERSION }, - }); - - const beaconStub = sandbox.stub(ajax, 'sendBeacon').returns(true); - const ajaxStub = sandbox.stub(ajax, 'ajax'); - expect(spec.onTimeout({ 'customData': 'customvalue' })).to.not.throw; - expect(beaconStub.called).to.be.true; - expect(ajaxStub.called).to.be.false; - }); - - it('will always call server with sendBeacon not available', () => { - config.setConfig({ - contxtful: { customer: CUSTOMER, version: VERSION }, - }); - - const ajaxStub = sandbox.stub(ajax, 'ajax'); - const beaconStub = sandbox.stub(ajax, 'sendBeacon').returns(false); - expect(spec.onTimeout({ 'customData': 'customvalue' })).to.not.throw; - expect(beaconStub.called).to.be.true; - expect(beaconStub.returned(false)).to.be.true; - expect(ajaxStub.calledOnce).to.be.true; - }); - }); - - describe('on onBidderError callback', () => { - it('will always call server', () => { - config.setConfig({ - contxtful: { customer: CUSTOMER, version: VERSION }, - }); - - const ajaxStub = sandbox.stub(ajax, 'ajax'); - const beaconStub = sandbox.stub(ajax, 'sendBeacon').returns(false); - spec.onBidderError({ 'customData': 'customvalue' }); - expect(ajaxStub.calledOnce).to.be.true; - expect(beaconStub.returned(false)).to.be.true; - }); - }); - - describe('on onBidWon callback', () => { - it('will always call server', () => { - config.setConfig({ - contxtful: { customer: CUSTOMER, version: VERSION }, - }); - - const ajaxStub = sandbox.stub(ajax, 'ajax'); - const beaconStub = sandbox.stub(ajax, 'sendBeacon').returns(false); - spec.onBidWon({ 'customData': 'customvalue' }); - expect(ajaxStub.calledOnce).to.be.true; - expect(beaconStub.returned(false)).to.be.true; - }); - - it('will call the server even if payload contains circular reference', () => { - config.setConfig({ - contxtful: { customer: CUSTOMER, version: VERSION }, - }); - - const ajaxStub = sandbox.stub(ajax, 'ajax'); - const beaconStub = sandbox.stub(ajax, 'sendBeacon').returns(false); - const payload = { - adata: "hello" - }; - payload.ref = payload - spec.onBidWon(payload); - expect(ajaxStub.calledOnce).to.be.true; - expect(beaconStub.returned(false)).to.be.true; - }) - }); - - describe('on onBidBillable callback', () => { - it('will always call server when sampling rate is configured to be 1.0', () => { - config.setConfig({ - contxtful: { customer: CUSTOMER, version: VERSION, sampling: { onBidBillable: 1.0 } }, - }); - const ajaxStub = sandbox.stub(ajax, 'ajax'); - const beaconStub = sandbox.stub(ajax, 'sendBeacon').returns(false); - spec.onBidBillable({ 'customData': 'customvalue' }); - expect(ajaxStub.calledOnce).to.be.true; - expect(beaconStub.returned(false)).to.be.true; - }); - }); - - describe('on onAdRenderSucceeded callback', () => { - it('will always call server when sampling rate is configured to be 1.0', () => { - config.setConfig({ - contxtful: { customer: CUSTOMER, version: VERSION, sampling: { onAdRenderSucceeded: 1.0 } }, - }); - const ajaxStub = sandbox.stub(ajax, 'ajax'); - const beaconStub = sandbox.stub(ajax, 'sendBeacon').returns(false); - spec.onAdRenderSucceeded({ 'customData': 'customvalue' }); - expect(ajaxStub.calledOnce).to.be.true; - expect(beaconStub.returned(false)).to.be.true; - }); - }); - }); -}); diff --git a/test/spec/modules/contxtfulRtdProvider_spec.js b/test/spec/modules/contxtfulRtdProvider_spec.js deleted file mode 100644 index ea57527f8..000000000 --- a/test/spec/modules/contxtfulRtdProvider_spec.js +++ /dev/null @@ -1,1051 +0,0 @@ -import { contxtfulSubmodule, extractParameters } from '../../../modules/contxtfulRtdProvider.js'; -import { expect } from 'chai'; -import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; -import { getStorageManager } from '../../../src/storageManager.js'; -import { MODULE_TYPE_UID } from '../../../src/activities/modules.js'; -import * as events from '../../../src/events.js'; -import * as utils from 'src/utils.js'; -import * as gptUtils from '../../../libraries/gptUtils/gptUtils.js' -import Sinon from 'sinon'; -import { deepClone, getWinDimensions } from '../../../src/utils.js'; - -const MODULE_NAME = 'contxtful'; - -const VERSION = 'v1'; -const CUSTOMER = 'CUSTOMER'; -const SM = 'SM'; -const CONTXTFUL_CONNECTOR_ENDPOINT = `https://api.receptivity.io/${VERSION}/prebid/${CUSTOMER}/connector/rxConnector.js`; - -const RX_FROM_SESSION_STORAGE = { ReceptivityState: 'Receptive', test_info: 'rx_from_session_storage' }; -const RX_FROM_API = { ReceptivityState: 'Receptive', test_info: 'rx_from_engine' }; - -const RX_API_MOCK = { receptivity: sinon.stub(), receptivityBatched: sinon.stub() }; -const RX_API_MOCK_WITH_BUNDLE = { receptivity: sinon.stub(), receptivityBatched: sinon.stub(), getOrtb2Fragment: sinon.stub() } - -const RX_CONNECTOR_MOCK = { - fetchConfig: sinon.stub(), - rxApiBuilder: sinon.stub(), -}; - -const TIMEOUT = 10; -const RX_CONNECTOR_IS_READY_EVENT = new CustomEvent('rxConnectorIsReady', { detail: { [CUSTOMER]: RX_CONNECTOR_MOCK }, bubbles: true }); - -function buildInitConfig(version, customer) { - return { - name: 'contxtful', - params: { - version: version, - customer: customer, - hostname: 'api.receptivity.io', - bidders: ['mock-bidder-code'], - adServerTargeting: true, - }, - }; -} - -function fakeGetElementById(width, height, x, y) { - const obj = { x, y, width, height }; - - return { - ...obj, - getBoundingClientRect: () => { - return { - width: obj.width, - height: obj.height, - left: obj.x, - top: obj.y, - right: obj.x + obj.width, - bottom: obj.y + obj.height - }; - } - }; -} - -describe('contxtfulRtdProvider', function () { - const sandbox = sinon.createSandbox(); - let loadExternalScriptTag; - let eventsEmitSpy; - - const storage = getStorageManager({ moduleType: MODULE_TYPE_UID, moduleName: MODULE_NAME }); - - beforeEach(() => { - loadExternalScriptTag = document.createElement('script'); - loadExternalScriptStub.callsFake((_url, _moduleName) => loadExternalScriptTag); - - RX_API_MOCK.receptivity.resetHistory(); - RX_API_MOCK.receptivity.callsFake(() => RX_FROM_API); - - RX_API_MOCK.receptivityBatched.resetHistory(); - RX_API_MOCK.receptivityBatched.callsFake((bidders) => bidders.reduce((accumulator, bidder) => { accumulator[bidder] = RX_FROM_API; return accumulator; }, {})); - - RX_API_MOCK_WITH_BUNDLE.receptivity.resetHistory(); - RX_API_MOCK_WITH_BUNDLE.receptivity.callsFake(() => RX_FROM_API); - - RX_API_MOCK_WITH_BUNDLE.receptivityBatched.resetHistory(); - RX_API_MOCK_WITH_BUNDLE.receptivityBatched.callsFake((bidders) => bidders.reduce((accumulator, bidder) => { accumulator[bidder] = RX_FROM_API; return accumulator; }, {})); - - RX_API_MOCK_WITH_BUNDLE.getOrtb2Fragment.resetHistory(); - RX_API_MOCK_WITH_BUNDLE.getOrtb2Fragment.callsFake((bidders, reqBidsConfigObj) => { - const bidderObj = bidders.reduce((accumulator, bidder) => { accumulator[bidder] = { user: { data: [{ name: MODULE_NAME, value: RX_FROM_API }] } }; return accumulator; }, {}); - return { global: { user: { site: { id: 'globalsiteId' } } }, bidder: bidderObj } - } - ); - - RX_CONNECTOR_MOCK.fetchConfig.resetHistory(); - RX_CONNECTOR_MOCK.fetchConfig.callsFake((tagId) => new Promise((resolve, reject) => resolve({ tag_id: tagId }))); - - RX_CONNECTOR_MOCK.rxApiBuilder.resetHistory(); - RX_CONNECTOR_MOCK.rxApiBuilder.callsFake((_config) => new Promise((resolve, reject) => resolve(RX_API_MOCK))); - - eventsEmitSpy = sandbox.spy(events, ['emit']); - - sandbox.stub(utils, 'generateUUID').returns(SM); - - const tagId = CUSTOMER; - sessionStorage.clear(); - }); - - afterEach(function () { - delete window.Contxtful; - sandbox.restore(); - }); - - describe('extractParameters', () => { - const { - params: { customer, version }, - } = buildInitConfig(VERSION, CUSTOMER); - const theories = [ - [ - null, - 'params.version should be a non-empty string', - 'null object for config', - ], - [ - {}, - 'params.version should be a non-empty string', - 'empty object for config', - ], - [ - { customer }, - 'params.version should be a non-empty string', - 'customer only in config', - ], - [ - { version }, - 'params.customer should be a non-empty string', - 'version only in config', - ], - [ - { customer, version: '' }, - 'params.version should be a non-empty string', - 'empty string for version', - ], - [ - { customer: '', version }, - 'params.customer should be a non-empty string', - 'empty string for customer', - ], - [ - { customer: '', version: '' }, - 'params.version should be a non-empty string', - 'empty string for version & customer', - ], - ]; - - theories.forEach(([params, expectedErrorMessage, _description]) => { - const config = { name: 'contxtful', params }; - it('detects invalid configuration and throws the expected error', () => { - expect(() => extractParameters(config)).to.throw( - expectedErrorMessage - ); - }); - }); - }); - - describe('extractParameters', function () { - it('detects invalid configuration and returns false', () => { - expect(contxtfulSubmodule.init({})).to.be.false; - }); - }); - - describe('init', function () { - it('uses a valid configuration and returns true when initializing', () => { - const config = buildInitConfig(VERSION, CUSTOMER); - expect(contxtfulSubmodule.init(config)).to.be.true; - }); - - it('loads a RX connector script asynchronously', (done) => { - contxtfulSubmodule.init(buildInitConfig(VERSION, CUSTOMER)); - - setTimeout(() => { - expect(loadExternalScriptStub.calledOnce).to.be.true; - expect(loadExternalScriptStub.args[0][0]).to.equal( - CONTXTFUL_CONNECTOR_ENDPOINT - ); - - done(); - }, TIMEOUT); - }); - }); - - describe('init', function () { - it('returns true when initializing', () => { - loadExternalScriptStub.callsFake((url, moduleCode, callback, doc, attributes) => { - return { addEventListener: (type, listener) => { } }; - }); - const config = buildInitConfig(VERSION, CUSTOMER); - expect(contxtfulSubmodule.init(config)).to.be.true; - }); - }); - - describe('init', function () { - it('uses the RX API to get receptivity', (done) => { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - window.dispatchEvent(RX_CONNECTOR_IS_READY_EVENT); - - setTimeout(() => { - contxtfulSubmodule.getTargetingData(['ad-slot'], config); - expect(RX_API_MOCK.receptivity.callCount, 'receptivity 42').to.be.equal(1); - expect(RX_API_MOCK.receptivity.firstCall.returnValue, 'receptivity').to.be.equal(RX_FROM_API); - done(); - }, TIMEOUT); - }); - }); - - describe('init', function () { - it('gets the RX API returned by an external script', (done) => { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - window.dispatchEvent(RX_CONNECTOR_IS_READY_EVENT); - - setTimeout(() => { - contxtfulSubmodule.getTargetingData(['ad-slot'], config); - expect(RX_CONNECTOR_MOCK.fetchConfig.callCount, 'fetchConfig').at.least(1); - expect(RX_CONNECTOR_MOCK.rxApiBuilder.callCount, 'rxApiBuilder').at.least(1); - done(); - }, TIMEOUT); - }); - }); - - describe('init', function () { - it('detect that initial receptivity is not dispatched and it does not initialize receptivity value', (done) => { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - - setTimeout(() => { - const targetingData = contxtfulSubmodule.getTargetingData(['ad-slot'], config); - expect(targetingData).to.deep.equal({}); - done(); - }, TIMEOUT); - }); - }); - - describe('init', function () { - const theories = [ - [new Event('initialReceptivity'), 'event without details'], - [new CustomEvent('initialReceptivity', {}), 'custom event without details'], - [new CustomEvent('initialReceptivity', { detail: {} }), 'custom event with invalid details'], - [new CustomEvent('initialReceptivity', { detail: { ReceptivityState: '' } }), 'custom event with details without ReceptivityState'], - ]; - - theories.forEach(([initialReceptivityEvent, _description]) => { - it('figures out that initial receptivity is invalid and it does not initialize receptivity value', (done) => { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - loadExternalScriptTag.dispatchEvent(initialReceptivityEvent); - - setTimeout(() => { - const targetingData = contxtfulSubmodule.getTargetingData(['ad-slot'], config); - expect(targetingData).to.deep.equal({}); - done(); - }, TIMEOUT); - }); - }) - }); - - describe('getTargetingData', function () { - const theories = [ - [undefined, {}, 'undefined ad-slots'], - [[], {}, 'empty ad-slots'], - [ - ['ad-slot'], - { 'ad-slot': RX_FROM_API }, - 'single ad-slot', - ], - [ - ['ad-slot-1', 'ad-slot-2'], - { - 'ad-slot-1': RX_FROM_API, - 'ad-slot-2': RX_FROM_API, - }, - 'many ad-slots', - ], - ]; - - theories.forEach(([adUnits, expected, description]) => { - it('adds receptivity to the ad units using the RX API', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - window.dispatchEvent(RX_CONNECTOR_IS_READY_EVENT); - - setTimeout(() => { - const targetingData = contxtfulSubmodule.getTargetingData(adUnits, config); - expect(targetingData, description).to.deep.equal(expected, description); - done(); - }, TIMEOUT); - }); - }); - }); - - describe('getTargetingData', function () { - const theories = [ - [undefined, {}, 'undefined ad-slots'], - [[], {}, 'empty ad-slots'], - [ - ['ad-slot'], - {}, - 'single ad-slot', - ], - [ - ['ad-slot-1', 'ad-slot-2'], - { - }, - 'many ad-slots', - ], - ]; - - theories.forEach(([adUnits, expected, description]) => { - it('honours "adServerTargeting" and the RX API is not called', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - config.params.adServerTargeting = false; - contxtfulSubmodule.init(config); - window.dispatchEvent(RX_CONNECTOR_IS_READY_EVENT); - - setTimeout(() => { - const _ = contxtfulSubmodule.getTargetingData(adUnits, config); - expect(RX_API_MOCK.receptivity.callCount).to.be.equal(0); - done(); - }, TIMEOUT); - }); - - it('honours adServerTargeting and it does not add receptivity to the ad units', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - config.params.adServerTargeting = false; - contxtfulSubmodule.init(config); - window.dispatchEvent(RX_CONNECTOR_IS_READY_EVENT); - - setTimeout(() => { - const targetingData = contxtfulSubmodule.getTargetingData(adUnits, config); - expect(targetingData, description).to.deep.equal(expected); - done(); - }, TIMEOUT); - }); - }); - }); - - describe('getTargetingData', function () { - const theories = [ - [undefined, {}, 'undefined ad-slots'], - [[], {}, 'empty ad-slots'], - [ - ['ad-slot'], - { 'ad-slot': RX_FROM_SESSION_STORAGE }, - 'single ad-slot', - ], - [ - ['ad-slot-1', 'ad-slot-2'], - { - 'ad-slot-1': RX_FROM_SESSION_STORAGE, - 'ad-slot-2': RX_FROM_SESSION_STORAGE, - }, - 'many ad-slots', - ], - ]; - - theories.forEach(([adUnits, expected, _description]) => { - it('uses non-expired info from session storage and adds receptivity to the ad units using session storage', function (done) { - // Simulate that there was a write to sessionStorage in the past. - storage.setDataInSessionStorage(CUSTOMER, JSON.stringify({ exp: new Date().getTime() + 1000, rx: RX_FROM_SESSION_STORAGE })) - - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - - const targetingData = contxtfulSubmodule.getTargetingData(adUnits, config); - expect(targetingData).to.deep.equal(expected); - - done(); - }); - }); - }); - - describe('getTargetingData', function () { - const theories = [ - [undefined, {}, 'undefined ad-slots'], - [[], {}, 'empty ad-slots'], - [ - ['ad-slot'], - {}, - 'single ad-slot', - ], - [ - ['ad-slot-1', 'ad-slot-2'], - { - }, - 'many ad-slots', - ], - ]; - - theories.forEach(([adUnits, expected, _description]) => { - it('ignores expired info from session storage and does not forward the info to ad units', function (done) { - // Simulate that there was a write to sessionStorage in the past. - storage.setDataInSessionStorage(CUSTOMER, JSON.stringify({ exp: new Date().getTime() - 100, rx: RX_FROM_SESSION_STORAGE })); - - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - - const targetingData = contxtfulSubmodule.getTargetingData(adUnits, config); - expect(targetingData).to.deep.equal(expected); - - done(); - }); - }); - }); - - describe('getBidRequestData', function () { - it('calls once the onDone callback', function (done) { - contxtfulSubmodule.init(buildInitConfig(VERSION, CUSTOMER)); - window.dispatchEvent(RX_CONNECTOR_IS_READY_EVENT); - - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, buildInitConfig(VERSION, CUSTOMER)); - expect(onDoneSpy.calledOnce).to.be.true; - done(); - }, TIMEOUT); - }); - }); - - describe('getBidRequestData', function () { - it('does not write receptivity to the global OpenRTB 2 fragment', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - window.dispatchEvent(RX_CONNECTOR_IS_READY_EVENT); - - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - - setTimeout(() => { - const onDone = () => 42; - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDone, config); - expect(reqBidsConfigObj.ortb2Fragments.global).to.deep.equal({}); - done(); - }, TIMEOUT); - }); - }); - - describe('getBidRequestData', function () { - it('writes receptivity to the configured bidder OpenRTB 2 fragments', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - window.dispatchEvent(RX_CONNECTOR_IS_READY_EVENT); - - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - - const expectedData = { - name: 'contxtful', - ext: { - rx: RX_FROM_API, - params: { - ev: config.params?.version, - ci: config.params?.customer, - }, - }, - }; - - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const data = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0]; - - expect(data.name).to.deep.equal(expectedData.name); - expect(data.ext.rx).to.deep.equal(expectedData.ext.rx); - expect(data.ext.params).to.deep.equal(expectedData.ext.params); - done(); - }, TIMEOUT); - }); - }); - - describe('getBidRequestData', function () { - it('uses non-expired info from session storage and adds receptivity to the reqBidsConfigObj', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - - // Simulate that there was a write to sessionStorage in the past. - const bidder = config.params.bidders[0]; - - storage.setDataInSessionStorage(`${config.params.customer}_${bidder}`, JSON.stringify({ exp: new Date().getTime() + 1000, rx: RX_FROM_SESSION_STORAGE })); - - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - - contxtfulSubmodule.init(config); - - // Since the RX_CONNECTOR_IS_READY_EVENT event was not dispatched, the RX engine is not loaded. - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, () => { }, config); - - setTimeout(() => { - const ortb2BidderFragment = reqBidsConfigObj.ortb2Fragments.bidder[bidder]; - const userData = ortb2BidderFragment.user.data; - const contxtfulData = userData[0]; - - expect(contxtfulData.name).to.be.equal('contxtful'); - expect(contxtfulData.ext.rx).to.deep.equal(RX_FROM_SESSION_STORAGE); - expect(contxtfulData.ext.params).to.deep.equal({ - ev: config.params.version, - ci: config.params.customer, - }); - - done(); - }, TIMEOUT); - }); - }); - - describe('getBidRequestData', function () { - it('uses the RX API', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - window.dispatchEvent(RX_CONNECTOR_IS_READY_EVENT); - - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - - setTimeout(() => { - expect(RX_CONNECTOR_MOCK.fetchConfig.callCount).at.least(1); - expect(RX_CONNECTOR_MOCK.rxApiBuilder.callCount).at.least(1); - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - expect(onDoneSpy.callCount).to.equal(1); - expect(RX_API_MOCK.receptivityBatched.callCount).to.equal(1); - done(); - }, TIMEOUT); - }); - }); - - describe('getBidRequestData', function () { - it('adds receptivity to the reqBidsConfigObj', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - window.dispatchEvent(RX_CONNECTOR_IS_READY_EVENT); - - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - - const expectedData = { - name: 'contxtful', - ext: { - rx: RX_FROM_API, - sm: SM, - params: { - ev: config.params?.version, - ci: config.params?.customer, - }, - }, - }; - - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const data = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0]; - - expect(data.name).to.deep.equal(expectedData.name); - expect(data.ext.rx).to.deep.equal(expectedData.ext.rx); - expect(data.ext.sm).to.deep.equal(expectedData.ext.sm); - expect(data.ext.params).to.deep.equal(expectedData.ext.params); - done(); - }, TIMEOUT); - }); - - it('does not change the sm', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - window.dispatchEvent(RX_CONNECTOR_IS_READY_EVENT); - - const firstReqBidsConfigObj = { - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - - const secondReqBidsConfigObj = deepClone(firstReqBidsConfigObj); - - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(firstReqBidsConfigObj, onDoneSpy, config); - contxtfulSubmodule.getBidRequestData(secondReqBidsConfigObj, onDoneSpy, config); - - const firstData = firstReqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0]; - const secondData = secondReqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0]; - - expect(firstData.ext.sm).to.equal(secondData.ext.sm); - - done(); - }, TIMEOUT); - }); - - describe('before rxApi is loaded', function () { - const moveEventTheories = [ - [ - new PointerEvent('pointermove', { clientX: 1, clientY: 2 }), - { x: 1, y: 2 }, - 'pointer move', - ] - ]; - - moveEventTheories.forEach(([event, expected, _description]) => { - it('adds move event', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - - window.dispatchEvent(event); - - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const ext = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0].ext; - - const events = JSON.parse(atob(ext.events)); - - expect(events.ui.position.x).to.be.deep.equal(expected.x); - expect(events.ui.position.y).to.be.deep.equal(expected.y); - expect(Sinon.match.number.test(events.ui.position.timestampMs)).to.be.true; - done(); - }, TIMEOUT); - }); - }); - - it('adds screen event', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - - // Cannot change the window size from JS - // So we take the current size as expectation - const { innerHeight: height, innerWidth: width } = getWinDimensions() - - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const ext = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0].ext; - - const events = JSON.parse(atob(ext.events)); - - expect(events.ui.screen.topLeft).to.be.deep.equal({ x: 0, y: 0 }, 'screen top left'); - expect(events.ui.screen.width).to.be.deep.equal(width, 'screen width'); - expect(events.ui.screen.height).to.be.deep.equal(height, 'screen height'); - expect(Sinon.match.number.test(events.ui.screen.timestampMs), 'screen timestamp').to.be.true; - done(); - }, TIMEOUT); - }); - }); - }); - - describe('when there is no ad units', function () { - it('adds empty ad unit positions', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const ext = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0].ext; - const pos = JSON.parse(atob(ext.pos)); - - expect(Object.keys(pos).length).to.be.equal(0); - done(); - }, TIMEOUT); - }); - }); - - describe('when there are ad units', function () { - it('return empty objects for ad units that we can\'t get position of', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - const reqBidsConfigObj = { - adUnits: [ - { code: 'code1' }, - { code: 'code2' } - ], - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const ext = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0].ext; - const pos = JSON.parse(atob(ext.pos)); - - expect(Object.keys(pos).length).to.be.equal(0); - done(); - }, TIMEOUT); - }); - - it('returns the IAB position if the ad unit div id cannot be bound but property pos can be found in the ad unit', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - const reqBidsConfigObj = { - adUnits: [ - { code: 'code1', mediaTypes: { banner: { pos: 4 } } }, - { code: 'code2', mediaTypes: { banner: { pos: 5 } } }, - { code: 'code3', mediaTypes: { banner: { pos: 0 } } }, - ], - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const ext = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0].ext; - const pos = JSON.parse(atob(ext.pos)); - - expect(Object.keys(pos).length).to.be.equal(3); - expect(pos['code1'].p).to.be.equal(4); - expect(pos['code2'].p).to.be.equal(5); - expect(pos['code3'].p).to.be.equal(0); - done(); - }, TIMEOUT); - }) - - function getFakeRequestBidConfigObj() { - return { - adUnits: [ - { code: 'code1', ortb2Imp: { ext: { data: { divId: 'divId1' } } } }, - { code: 'code2', ortb2Imp: { ext: { data: { divId: 'divId2' } } } } - ], - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - } - - function InitDivStubPositions(config, withIframe, isVisible, forceGetElementById = true) { - const fakeElem = fakeGetElementById(100, 100, 30, 30); - if (isVisible) { - fakeElem.checkVisibility = function () { return true }; - sandbox.stub(window.top, 'getComputedStyle').returns({ display: 'block' }); - } else { - fakeElem.checkVisibility = function () { return false }; - sandbox.stub(window.top, 'getComputedStyle').returns({ display: 'none' }); - } - - if (withIframe) { - const ws = { - frameElement: { - getBoundingClientRect: () => fakeElem.getBoundingClientRect() - }, - document: { - getElementById: (id) => fakeElem, - - } - } - sandbox.stub(utils, 'getWindowSelf').returns(window.top); - sandbox.stub(utils, 'inIframe').returns(true); - sandbox.stub(fakeElem, 'checkVisibility').returns(isVisible); - } else { - sandbox.stub(utils, 'inIframe').returns(false); - sandbox.stub(fakeElem, 'checkVisibility').returns(isVisible); - } - if (forceGetElementById) { - sandbox.stub(window.top.document, 'getElementById').returns(fakeElem); - } - contxtfulSubmodule.init(config); - } - - describe('when the div id cannot be found, we should try with GPT method', function () { - it('returns an empty list if gpt not find the div', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - const reqBidsConfigObj = { - adUnits: [ - { code: 'code1' }, - { code: 'code2' } - ], - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - InitDivStubPositions(config, false, true, false); - const fakeElem = fakeGetElementById(100, 100, 30, 30); - sandbox.stub(window.top.document, 'getElementById').returns(function (id) { - if (id === 'code1' || id === 'code2') { - return undefined; - } else { - return fakeElem; - } - }); - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const ext = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0].ext; - const pos = JSON.parse(atob(ext.pos)); - - expect(Object.keys(pos).length).to.be.equal(0); - done(); - }, TIMEOUT); - }) - - it('returns object visibility and position if gpt not found but the div id is the ad unit code', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - const reqBidsConfigObj = { - adUnits: [ - { code: 'code1' }, - { code: 'code2' } - ], - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - InitDivStubPositions(config, false, true); - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const ext = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0].ext; - const pos = JSON.parse(atob(ext.pos)); - - expect(Object.keys(pos).length).to.be.equal(2); - expect(pos['code1'].p.x).to.be.equal(30); - expect(pos['code1'].p.y).to.be.equal(30); - expect(pos['code1'].v).to.be.equal(true); - done(); - }, TIMEOUT); - }); - - it('returns object visibility and position if gpt finds the div', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - const reqBidsConfigObj = { - adUnits: [ - { code: 'code1' }, - { code: 'code2' } - ], - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - InitDivStubPositions(config, false, true); - sandbox.stub(gptUtils, 'getGptSlotInfoForAdUnitCode').returns({ divId: 'div1' }); - - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const ext = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0].ext; - const pos = JSON.parse(atob(ext.pos)); - - expect(Object.keys(pos).length).to.be.equal(2); - expect(pos['code1'].p.x).to.be.equal(30); - expect(pos['code1'].p.y).to.be.equal(30); - expect(pos['code1'].v).to.be.equal(true); - done(); - }, TIMEOUT); - }); - }); - - describe('when we get object visibility and position for ad units that we can get div id', function () { - const config = buildInitConfig(VERSION, CUSTOMER); - - describe('when we are not in an iframe', function () { - it('return object visibility true if element is visible', function (done) { - const reqBidsConfigObj = getFakeRequestBidConfigObj(); - InitDivStubPositions(config, false, true); - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const ext = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0].ext; - const pos = JSON.parse(atob(ext.pos)); - - expect(Object.keys(pos).length).to.be.equal(2); - expect(pos['code1'].p.x).to.be.equal(30); - expect(pos['code1'].p.y).to.be.equal(30); - expect(pos['code1'].v).to.be.equal(true); - done(); - }, TIMEOUT); - }); - - it('return object visibility false if element is not visible', function (done) { - const reqBidsConfigObj = getFakeRequestBidConfigObj(); - InitDivStubPositions(config, false, false); - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const ext = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0].ext; - const pos = JSON.parse(atob(ext.pos)); - - expect(Object.keys(pos).length).to.be.equal(2); - expect(pos['code1'].v).to.be.equal(false); - expect(pos['code2'].v).to.be.equal(false); - done(); - }, TIMEOUT); - }); - }); - - describe('when we are in an iframe', function () { - it('return object visibility true if element is visible', function (done) { - const reqBidsConfigObj = getFakeRequestBidConfigObj(); - InitDivStubPositions(config, true, true) - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const ext = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0].ext; - const pos = JSON.parse(atob(ext.pos)); - - expect(Object.keys(pos).length).to.be.equal(2); - expect(pos['code1'].p.x).to.be.equal(30); - expect(pos['code1'].p.y).to.be.equal(30); - expect(pos['code1'].v).to.be.equal(true); - done(); - }, TIMEOUT); - }); - - it('return object visibility false if element is not visible', function (done) { - const reqBidsConfigObj = getFakeRequestBidConfigObj(); - InitDivStubPositions(config, true, false); - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const ext = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0].ext; - const pos = JSON.parse(atob(ext.pos)); - - expect(Object.keys(pos).length).to.be.equal(2); - expect(pos['code1'].v).to.be.equal(false); - done(); - }, TIMEOUT); - }); - }); - }); - }); - - describe('after rxApi is loaded', function () { - it('should add event', function (done) { - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - window.dispatchEvent(RX_CONNECTOR_IS_READY_EVENT); - - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - - const ext = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]].user.data[0].ext; - - const events = ext.events; - - expect(events).to.be.not.undefined; - done(); - }, TIMEOUT); - }); - }) - - describe('when rxConnector contains getOrtb2Fragment function', () => { - it('should just take whatever it contains and merge to the fragment', function (done) { - RX_CONNECTOR_MOCK.rxApiBuilder.resetHistory(); - RX_CONNECTOR_MOCK.rxApiBuilder.callsFake((_config) => new Promise((resolve, reject) => resolve(RX_API_MOCK_WITH_BUNDLE))); - - const config = buildInitConfig(VERSION, CUSTOMER); - contxtfulSubmodule.init(config); - window.dispatchEvent(RX_CONNECTOR_IS_READY_EVENT); - - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - bidder: {}, - }, - }; - - setTimeout(() => { - const onDoneSpy = sinon.spy(); - contxtfulSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, config); - const global = reqBidsConfigObj.ortb2Fragments.global; - const bidder = reqBidsConfigObj.ortb2Fragments.bidder[config.params.bidders[0]]; - - const globalExpected = { user: { site: { id: 'globalsiteId' } } }; - const bidderExpected = { user: { data: [{ name: MODULE_NAME, value: RX_FROM_API }] } }; - expect(RX_API_MOCK_WITH_BUNDLE.getOrtb2Fragment.callCount).to.equal(1); - expect(global).to.deep.equal(globalExpected); - expect(bidder).to.deep.equal(bidderExpected); - done(); - }, TIMEOUT); - }) - }) -}); diff --git a/test/spec/modules/conversantBidAdapter_spec.js b/test/spec/modules/conversantBidAdapter_spec.js deleted file mode 100644 index ac19bcd10..000000000 --- a/test/spec/modules/conversantBidAdapter_spec.js +++ /dev/null @@ -1,749 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/conversantBidAdapter.js'; -import * as utils from 'src/utils.js'; -import {deepAccess} from 'src/utils'; -// load modules that register ORTB processors -import 'src/prebid.js' -import 'modules/currency.js'; -import 'modules/userId/index.js'; // handles eids -import 'modules/priceFloors.js'; -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; -import {hook} from '../../../src/hook.js' -import {BANNER} from '../../../src/mediaTypes.js'; - -describe('Conversant adapter tests', function() { - const siteId = '108060'; - const versionPattern = /^\d+\.\d+\.\d+(.)*$/; - const bidRequests = [ - // banner with single size - { - bidder: 'conversant', - params: { - site_id: siteId, - position: 1, - tag_id: 'tagid-1', - bidfloor: 0.5 - }, - mediaTypes: { - banner: { - sizes: [[300, 250]], - } - }, - placementCode: 'pcode000', - transactionId: 'tx000', - bidId: 'bid000', - bidderRequestId: '117d765b87bed38', - auctionId: 'req000' - }, - - // banner with sizes in mediaTypes.banner.sizes - { - bidder: 'conversant', - params: { - site_id: siteId - }, - mediaTypes: { - banner: { - sizes: [[728, 90], [468, 60]] - } - }, - placementCode: 'pcode001', - transactionId: 'tx001', - bidId: 'bid001', - bidderRequestId: '117d765b87bed38', - auctionId: 'req000' - }, - // banner with tag id and position - { - bidder: 'conversant', - params: { - site_id: siteId, - position: 2, - tag_id: '' - }, - mediaTypes: { - banner: { - sizes: [[300, 600], [160, 600]], - } - }, - placementCode: 'pcode002', - transactionId: 'tx002', - bidId: 'bid002', - bidderRequestId: '117d765b87bed38', - auctionId: 'req000' - }, - // video with single size - { - bidder: 'conversant', - params: { - site_id: siteId, - api: [2], - protocols: [1, 2], - mimes: ['video/mp4', 'video/x-flv'], - maxduration: 30 - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [632, 499], - pos: 3 - } - }, - placementCode: 'pcode003', - transactionId: 'tx003', - bidId: 'bid003', - bidderRequestId: '117d765b87bed38', - auctionId: 'req000' - }, - // video with playerSize - { - bidder: 'conversant', - params: { - site_id: siteId, - maxduration: 30, - api: [2, 3] - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [1024, 768], - api: [1, 2], - protocols: [1, 2, 3], - mimes: ['video/mp4', 'video/x-flv'] - } - }, - placementCode: 'pcode004', - transactionId: 'tx004', - bidId: 'bid004', - bidderRequestId: '117d765b87bed38', - auctionId: 'req000' - }, - // video without sizes - { - bidder: 'conversant', - params: { - site_id: siteId, - position: 2, - }, - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mp4', 'video/x-flv'], - pos: 7, - } - }, - placementCode: 'pcode005', - transactionId: 'tx005', - bidId: 'bid005', - bidderRequestId: '117d765b87bed38', - auctionId: 'req000' - }, - // banner with first party data - { - bidder: 'conversant', - params: { - site_id: siteId - }, - mediaTypes: { - banner: { - sizes: [[300, 600], [160, 600]], - } - }, - ortb2Imp: { - instl: 1, - ext: { - data: { - pbadslot: 'homepage-top-rect' - } - } - }, - placementCode: 'pcode006', - transactionId: 'tx006', - bidId: 'bid006', - bidderRequestId: '117d765b87bed38', - auctionId: 'req000' - } - ]; - - const bidResponses = { - body: { - id: 'req000', - seatbid: [{ - bid: [{ - nurl: 'notify000', - adm: 'markup000', - crid: '1000', - impid: 'bid000', - price: 0.99, - w: 300, - h: 250, - adomain: ['https://example.com'], - id: 'bid000' - }, { - impid: 'bid001', - price: 0.00000, - id: 'bid001' - }, { - nurl: 'notify002', - adm: 'markup002', - crid: '1002', - impid: 'bid002', - price: 2.99, - w: 300, - h: 600, - adomain: ['https://example.com'], - id: 'bid002' - }, { - nurl: 'notify003', - adm: 'markup003', - crid: '1003', - impid: 'bid003', - price: 3.99, - adomain: ['https://example.com'], - id: 'bid003' - }, { - nurl: 'notify004', - adm: '', - crid: '1004', - impid: 'bid004', - price: 4.99, - adomain: ['https://example.com'], - id: 'bid004' - }] - }] - }, - headers: {} - }; - - before(() => { - // ortbConverter depends on other modules to be setup to work as expected so run hook.ready to register some - // submodules so functions like setOrtbSourceExtSchain and setOrtbUserExtEids are available - hook.ready(); - }); - - it('Verify basic properties', function() { - expect(spec.code).to.equal('conversant'); - expect(spec.aliases).to.be.an('array').with.lengthOf(2); - expect(spec.aliases[0]).to.equal('cnvr'); - expect(spec.aliases[1]).to.equal('epsilon'); - expect(spec.supportedMediaTypes).to.be.an('array').with.lengthOf(3); - expect(spec.supportedMediaTypes[1]).to.equal('video'); - }); - - it('Verify isBidRequestValid', function() { - expect(spec.isBidRequestValid({})).to.be.false; - expect(spec.isBidRequestValid({params: {}})).to.be.false; - expect(spec.isBidRequestValid({params: {site_id: '123'}})).to.be.true; - bidRequests.forEach((bid) => { - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - - const simpleVideo = JSON.parse(JSON.stringify(bidRequests[3])); - simpleVideo.params.site_id = 123; - expect(spec.isBidRequestValid(simpleVideo)).to.be.false; - simpleVideo.params.site_id = siteId; - simpleVideo.params.mimes = [1, 2, 3]; - expect(spec.isBidRequestValid(simpleVideo)).to.be.false; - simpleVideo.params.mimes = 'bad type'; - expect(spec.isBidRequestValid(simpleVideo)).to.be.false; - delete simpleVideo.params.mimes; - expect(spec.isBidRequestValid(simpleVideo)).to.be.true; - }); - - describe('Verify buildRequest', function() { - let page, bidderRequest, request, payload; - before(() => { - page = 'http://test.com?a=b&c=123'; - // ortbConverter uses the site/device information from the ortb2 object passed in the bidderRequest object - bidderRequest = { - refererInfo: { - page: page - }, - ortb2: { - source: { - tid: 'tid000' - }, - site: { - mobile: 0, - page: page, - }, - device: { - w: screen.width, - h: screen.height, - dnt: 0, - ua: navigator.userAgent - } - } - }; - request = spec.buildRequests(bidRequests, bidderRequest); - payload = request.data; - }); - - it('Verify common elements', function() { - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://web.hb.ad.cpe.dotomi.com/cvx/client/hb/ortb/25'); - - expect(payload).to.have.property('id'); - expect(payload.source).to.have.property('tid', 'tid000'); - expect(payload).to.have.property('at', 1); - expect(payload).to.have.property('imp'); - expect(payload.imp).to.be.an('array').with.lengthOf(bidRequests.length); - - expect(payload).to.have.property('site'); - expect(payload.site).to.have.property('id', siteId); - expect(payload.site).to.have.property('mobile').that.is.oneOf([0, 1]); - - expect(payload.site).to.have.property('page', page); - - expect(payload).to.have.property('device'); - expect(payload.device).to.have.property('w', screen.width); - expect(payload.device).to.have.property('h', screen.height); - expect(payload.device).to.have.property('dnt').that.is.oneOf([0, 1]); - expect(payload.device).to.have.property('ua', navigator.userAgent); - - expect(payload).to.not.have.property('user'); // there should be no user by default - expect(payload).to.not.have.property('tmax'); // there should be no user by default - }); - - it('Simple banner', () => { - expect(payload.imp[0]).to.have.property('id', 'bid000'); - expect(payload.imp[0]).to.have.property('secure', 1); - expect(payload.imp[0]).to.have.property('bidfloor', 0.5); - expect(payload.imp[0]).to.have.property('displaymanager', 'Prebid.js'); - expect(payload.imp[0]).to.have.property('displaymanagerver').that.matches(versionPattern); - expect(payload.imp[0]).to.have.property('tagid', 'tagid-1'); - expect(payload.imp[0]).to.have.property('banner'); - expect(payload.imp[0].banner).to.have.property('pos', 1); - expect(payload.imp[0].banner).to.have.property('format'); - expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}]); - expect(payload.imp[0]).to.not.have.property('video'); - }); - - it('Banner multiple sizes', () => { - expect(payload.imp[1]).to.have.property('id', 'bid001'); - expect(payload.imp[1]).to.have.property('secure', 1); - expect(payload.imp[1]).to.have.property('bidfloor', 0); - expect(payload.imp[1]).to.have.property('displaymanager', 'Prebid.js'); - expect(payload.imp[1]).to.have.property('displaymanagerver').that.matches(versionPattern); - expect(payload.imp[1]).to.not.have.property('tagid'); - expect(payload.imp[1]).to.have.property('banner'); - expect(payload.imp[1].banner).to.not.have.property('pos'); - expect(payload.imp[1].banner).to.have.property('format'); - expect(payload.imp[1].banner.format).to.deep.equal([{w: 728, h: 90}, {w: 468, h: 60}]); - }); - - it('Banner with tagid and position', () => { - expect(payload.imp[2]).to.have.property('id', 'bid002'); - expect(payload.imp[2]).to.have.property('secure', 1); - expect(payload.imp[2]).to.have.property('bidfloor', 0); - expect(payload.imp[2]).to.have.property('displaymanager', 'Prebid.js'); - expect(payload.imp[2]).to.have.property('displaymanagerver').that.matches(versionPattern); - expect(payload.imp[2]).to.have.property('banner'); - expect(payload.imp[2].banner).to.have.property('pos', 2); - expect(payload.imp[2].banner).to.have.property('format'); - expect(payload.imp[2].banner.format).to.deep.equal([{w: 300, h: 600}, {w: 160, h: 600}]); - }); - - if (FEATURES.VIDEO) { - it('Simple video', () => { - expect(payload.imp[3]).to.have.property('id', 'bid003'); - expect(payload.imp[3]).to.have.property('secure', 1); - expect(payload.imp[3]).to.have.property('bidfloor', 0); - expect(payload.imp[3]).to.have.property('displaymanager', 'Prebid.js'); - expect(payload.imp[3]).to.have.property('displaymanagerver').that.matches(versionPattern); - expect(payload.imp[3]).to.not.have.property('tagid'); - expect(payload.imp[3]).to.have.property('video'); - expect(payload.imp[3].video).to.have.property('pos', 3); - expect(payload.imp[3].video).to.have.property('w', 632); - expect(payload.imp[3].video).to.have.property('h', 499); - expect(payload.imp[3].video).to.have.property('mimes'); - expect(payload.imp[3].video.mimes).to.deep.equal(['video/mp4', 'video/x-flv']); - expect(payload.imp[3].video).to.have.property('protocols'); - expect(payload.imp[3].video.protocols).to.deep.equal([1, 2]); - expect(payload.imp[3].video).to.have.property('api'); - expect(payload.imp[3].video.api).to.deep.equal([2]); - expect(payload.imp[3].video).to.have.property('maxduration', 30); - expect(payload.imp[3]).to.not.have.property('banner'); - }); - - it('Video with playerSize', () => { - expect(payload.imp[4]).to.have.property('id', 'bid004'); - expect(payload.imp[4]).to.have.property('secure', 1); - expect(payload.imp[4]).to.have.property('bidfloor', 0); - expect(payload.imp[4]).to.have.property('displaymanager', 'Prebid.js'); - expect(payload.imp[4]).to.have.property('displaymanagerver').that.matches(versionPattern); - expect(payload.imp[4]).to.not.have.property('tagid'); - expect(payload.imp[4]).to.have.property('video'); - expect(payload.imp[4].video).to.not.have.property('pos'); - expect(payload.imp[4].video).to.have.property('w', 1024); - expect(payload.imp[4].video).to.have.property('h', 768); - expect(payload.imp[4].video).to.have.property('mimes'); - expect(payload.imp[4].video.mimes).to.deep.equal(['video/mp4', 'video/x-flv']); - expect(payload.imp[4].video).to.have.property('protocols'); - expect(payload.imp[4].video.protocols).to.deep.equal([1, 2, 3]); - expect(payload.imp[4].video).to.have.property('api'); - expect(payload.imp[4].video.api).to.deep.equal([1, 2, 3]); - expect(payload.imp[4].video).to.have.property('maxduration', 30); - }); - - it('Video without sizes', () => { - expect(payload.imp[5]).to.have.property('id', 'bid005'); - expect(payload.imp[5]).to.have.property('secure', 1); - expect(payload.imp[5]).to.have.property('bidfloor', 0); - expect(payload.imp[5]).to.have.property('displaymanager', 'Prebid.js'); - expect(payload.imp[5]).to.have.property('displaymanagerver').that.matches(versionPattern); - expect(payload.imp[5]).to.not.have.property('tagid'); - expect(payload.imp[5]).to.have.property('video'); - expect(payload.imp[5].video).to.have.property('pos', 2); - expect(payload.imp[5].video).to.not.have.property('w'); - expect(payload.imp[5].video).to.not.have.property('h'); - expect(payload.imp[5].video).to.have.property('mimes'); - expect(payload.imp[5].video.mimes).to.deep.equal(['video/mp4', 'video/x-flv']); - expect(payload.imp[5].video).to.not.have.property('protocols'); - expect(payload.imp[5].video).to.not.have.property('api'); - expect(payload.imp[5].video).to.not.have.property('maxduration'); - expect(payload.imp[5]).to.not.have.property('banner'); - }); - } - - it('With FPD', () => { - expect(payload.imp[6]).to.have.property('id', 'bid006'); - expect(payload.imp[6]).to.have.property('banner'); - expect(payload.imp[6]).to.not.have.property('video'); - expect(payload.imp[6]).to.have.property('instl'); - expect(payload.imp[6]).to.have.property('ext'); - expect(payload.imp[6].ext).to.have.property('data'); - expect(payload.imp[6].ext.data).to.have.property('pbadslot'); - }); - }); - - it('Verify timeout', () => { - const bidderRequest = { timeout: 9999 }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - expect(payload.tmax).equals(bidderRequest.timeout); - }); - - it('Verify first party data', () => { - const bidderRequest = { - refererInfo: {page: 'http://test.com?a=b&c=123'}, - ortb2: {site: {content: {series: 'MySeries', season: 'MySeason', episode: 3, title: 'MyTitle'}}} - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - expect(payload.site).to.have.property('content'); - expect(payload.site.content).to.have.property('series'); - expect(payload.site.content).to.have.property('season'); - expect(payload.site.content).to.have.property('episode'); - expect(payload.site.content).to.have.property('title'); - }); - - it('Verify currency', () => { - const bidderRequest = { timeout: 9999, ortb2: {cur: ['EUR']} }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - expect(payload.cur).deep.equal(['USD']); - }) - - it('Verify supply chain data', () => { - const bidderRequest = {refererInfo: {page: 'http://test.com?a=b&c=123'}}; - const schain = {complete: 1, ver: '1.0', nodes: [{asi: 'bidderA.com', sid: '00001', hp: 1}]}; - - // Add schain to bidderRequest - bidderRequest.ortb2 = { - source: { - ext: {schain: schain} - } - }; - - const bidsWithSchain = bidRequests.map((bid) => { - return Object.assign({ - ortb2: { - source: { - ext: {schain: schain} - } - } - }, bid); - }); - const request = spec.buildRequests(bidsWithSchain, bidderRequest); - const payload = request.data; - expect(deepAccess(payload, 'source.ext.schain.nodes')).to.exist; - expect(payload.source.ext.schain.nodes[0].asi).equals(schain.nodes[0].asi); - }); - - it('Verify override url', function() { - const testUrl = 'https://someurl?name=value'; - const request = spec.buildRequests([{params: {white_label_url: testUrl}}], {}); - expect(request.url).to.equal(testUrl); - }); - - describe('Verify interpretResponse', function() { - let bid, request, response; - - before(() => { - request = spec.buildRequests(bidRequests, {}); - response = spec.interpretResponse(bidResponses, request).bids; - }); - - it('Banner', function() { - expect(response).to.be.an('array').with.lengthOf(4); - bid = response[0]; - expect(bid).to.have.property('requestId', 'bid000'); - expect(bid).to.have.property('cpm', 0.99); - expect(bid).to.have.property('creativeId', '1000'); - expect(bid).to.have.property('width', 300); - expect(bid).to.have.property('height', 250); - expect(bid.meta.advertiserDomains).to.deep.equal(['https://example.com']); - expect(bid).to.have.property('ad', '
markup000'); - expect(bid).to.have.property('ttl', 300); - expect(bid).to.have.property('netRevenue', true); - }); - - // There is no bid001 because cpm is $0 - - it('Banner multiple sizes', function() { - bid = response[1]; - expect(bid).to.have.property('requestId', 'bid002'); - expect(bid).to.have.property('cpm', 2.99); - expect(bid).to.have.property('creativeId', '1002'); - expect(bid).to.have.property('width', 300); - expect(bid).to.have.property('height', 600); - expect(bid).to.have.property('ad', '
markup002'); - expect(bid).to.have.property('ttl', 300); - expect(bid).to.have.property('netRevenue', true); - }); - - if (FEATURES.VIDEO) { - it('Video', function () { - bid = response[2]; - expect(bid).to.have.property('requestId', 'bid003'); - expect(bid).to.have.property('cpm', 3.99); - expect(bid).to.have.property('creativeId', '1003'); - expect(bid).to.have.property('playerWidth', 632); - expect(bid).to.have.property('playerHeight', 499); - expect(bid).to.have.property('vastUrl', 'notify003'); - expect(bid).to.have.property('vastXml', 'markup003'); - expect(bid).to.have.property('mediaType', 'video'); - expect(bid).to.have.property('ttl', 300); - expect(bid).to.have.property('netRevenue', true); - }); - - it('Empty Video', function() { - bid = response[3]; - expect(bid).to.have.property('vastXml', ''); - }); - } - }); - - describe('Verify Native Ads', function () { - let request, response; - - const nativeOrtbRequest = { - ver: '1.2', - assets: [ - { id: 1, required: 1, title: { len: 80 } }] - }; - const nativeBidRequests = [{ - bidder: 'conversant', - params: { - site_id: 10806 - }, - adUnitCode: 'adunit', - mediaTypes: { - banner: { sizes: [[300, 250]] }, - native: { - ...nativeOrtbRequest - }, - }, - nativeOrtbRequest, - bidId: '0', - bidderRequestId: 'requestId', - }]; - - const nativeMarkup = JSON.stringify({ - native: { - assets: [ - {id: 1, title: {text: 'TextValue!'}}, - {id: 5, data: {value: 'Epsilon'}}, - ], - link: { url: 'https://www.epsilon.com/us', }, } - }); - - const nativeBidResponse = { - body: { - bidId: 'requestId', - seatbid: [{ - bid: [{ - impid: '0', - price: 0.25, - mtype: 4, - adm: nativeMarkup - }] - }], - cur: 'USD' - } - }; - - if (FEATURES.NATIVE) { - it('Request', function () { - request = spec.buildRequests(nativeBidRequests, {}); - const payload = request.data; - const native = JSON.parse(payload.imp[0].native.request); - expect(native).to.deep.equal(nativeBidRequests[0].nativeOrtbRequest); - }); - it('Response', function () { - response = spec.interpretResponse(nativeBidResponse, request); - const result = response.bids[0]; - expect(result.ad).to.equal(nativeMarkup); - expect(result.mediaType).to.equal(BANNER); - expect(result.cpm).to.equal(nativeBidResponse.body.seatbid[0].bid[0].price); - }); - } - }) - - describe('Extended ID', function() { - it('Verify unifiedid and liveramp', function() { - // clone bidRequests - const requests = utils.deepClone(bidRequests); - - const eidArray = [{'source': 'pubcid.org', 'uids': [{'id': '112233', 'atype': 1}]}, {'source': 'liveramp.com', 'uids': [{'id': '334455', 'atype': 3}]}]; - - // construct http post payload - const payload = spec.buildRequests(requests, {ortb2: {user: {ext: {eids: eidArray}}}}).data; - expect(payload).to.have.deep.nested.property('user.ext.eids', [ - {source: 'pubcid.org', uids: [{id: '112233', atype: 1}]}, - {source: 'liveramp.com', uids: [{id: '334455', atype: 3}]} - ]); - }); - }); - - describe('price floor module', function() { - let bidRequest; - beforeEach(function() { - bidRequest = [utils.deepClone(bidRequests[0])]; - delete bidRequest[0].params.bidfloor; - }); - - it('obtain floor from getFloor', function() { - bidRequest[0].getFloor = () => { - return { - currency: 'USD', - floor: 3.21 - }; - }; - - const payload = spec.buildRequests(bidRequest, {}).data; - expect(payload.imp[0]).to.have.property('bidfloor', 3.21); - }); - - it('obtain floor from params', function() { - bidRequest[0].getFloor = () => { - return { - currency: 'USD', - floor: 3.21 - }; - }; - bidRequest[0].params.bidfloor = 0.6; - - const payload = spec.buildRequests(bidRequest, {}).data; - expect(payload.imp[0]).to.have.property('bidfloor', 0.6); - }); - - it('unsupported currency', function() { - bidRequest[0].getFloor = () => { - return { - currency: 'EUR', - floor: 1.23 - }; - }; - - const payload = spec.buildRequests(bidRequest, {}).data; - expect(payload.imp[0]).to.have.property('bidfloor', 0); - }); - - it('bad floor value', function() { - bidRequest[0].getFloor = () => { - return { - currency: 'USD', - floor: 'test' - }; - }; - - const payload = spec.buildRequests(bidRequest, {}).data; - expect(payload.imp[0]).to.have.property('bidfloor', 0); - }); - - it('empty floor object', function() { - bidRequest[0].getFloor = () => { - return {}; - }; - - const payload = spec.buildRequests(bidRequest, {}).data; - expect(payload.imp[0]).to.have.property('bidfloor', 0); - }); - - it('undefined floor result', function() { - bidRequest[0].getFloor = () => {}; - - const payload = spec.buildRequests(bidRequest, {}).data; - expect(payload.imp[0]).to.have.property('bidfloor', 0); - }); - }); - - describe('getUserSyncs', function() { - const syncurl_iframe = 'https://sync.dotomi.com:8080/iframe'; - const syncurl_image = 'https://sync.dotomi.com:8080/pixel'; - const cnvrResponse = {ext: {psyncs: [syncurl_image], fsyncs: [syncurl_iframe]}}; - let sandbox; - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - afterEach(function() { - sandbox.restore(); - }); - - it('empty params', function() { - expect(spec.getUserSyncs({ iframeEnabled: true }, [], undefined, undefined)) - .to.deep.equal([]); - expect(spec.getUserSyncs({ iframeEnabled: true }, [{body: {ext: {}}}], undefined, undefined)) - .to.deep.equal([]); - expect(spec.getUserSyncs({ iframeEnabled: true }, [{body: cnvrResponse}], undefined, undefined)) - .to.deep.equal([{ type: 'iframe', url: syncurl_iframe }]); - expect(spec.getUserSyncs({ pixelEnabled: true }, [{body: cnvrResponse}], undefined, undefined)) - .to.deep.equal([{ type: 'image', url: syncurl_image }]); - expect(spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, [{body: cnvrResponse}], undefined, undefined)) - .to.deep.equal([{type: 'iframe', url: syncurl_iframe}, {type: 'image', url: syncurl_image}]); - }); - - it('URL building', function() { - expect(spec.getUserSyncs({pixelEnabled: true}, [{body: {ext: {psyncs: [`${syncurl_image}?sid=1234`]}}}], undefined, undefined)) - .to.deep.equal([{type: 'image', url: `${syncurl_image}?sid=1234`}]); - expect(spec.getUserSyncs({pixelEnabled: true}, [{body: {ext: {psyncs: [`${syncurl_image}?sid=1234`]}}}], undefined, '1NYN')) - .to.deep.equal([{type: 'image', url: `${syncurl_image}?sid=1234&us_privacy=1NYN`}]); - }); - - it('GDPR', function() { - expect(spec.getUserSyncs({ iframeEnabled: true }, [{body: cnvrResponse}], {gdprApplies: true, consentString: 'consentstring'}, undefined)) - .to.deep.equal([{ type: 'iframe', url: `${syncurl_iframe}?gdpr=1&gdpr_consent=consentstring` }]); - expect(spec.getUserSyncs({ iframeEnabled: true }, [{body: cnvrResponse}], {gdprApplies: false, consentString: 'consentstring'}, undefined)) - .to.deep.equal([{ type: 'iframe', url: `${syncurl_iframe}?gdpr=0&gdpr_consent=consentstring` }]); - expect(spec.getUserSyncs({ iframeEnabled: true }, [{body: cnvrResponse}], {gdprApplies: true, consentString: undefined}, undefined)) - .to.deep.equal([{ type: 'iframe', url: `${syncurl_iframe}?gdpr=1&gdpr_consent=` }]); - - expect(spec.getUserSyncs({ pixelEnabled: true }, [{body: cnvrResponse}], {gdprApplies: true, consentString: 'consentstring'}, undefined)) - .to.deep.equal([{ type: 'image', url: `${syncurl_image}?gdpr=1&gdpr_consent=consentstring` }]); - expect(spec.getUserSyncs({ pixelEnabled: true }, [{body: cnvrResponse}], {gdprApplies: false, consentString: 'consentstring'}, undefined)) - .to.deep.equal([{ type: 'image', url: `${syncurl_image}?gdpr=0&gdpr_consent=consentstring` }]); - expect(spec.getUserSyncs({ pixelEnabled: true }, [{body: cnvrResponse}], {gdprApplies: true, consentString: undefined}, undefined)) - .to.deep.equal([{ type: 'image', url: `${syncurl_image}?gdpr=1&gdpr_consent=` }]); - }); - - it('US_Privacy', function() { - expect(spec.getUserSyncs({ iframeEnabled: true }, [{body: cnvrResponse}], undefined, '1NYN')) - .to.deep.equal([{ type: 'iframe', url: `${syncurl_iframe}?us_privacy=1NYN` }]); - expect(spec.getUserSyncs({ pixelEnabled: true }, [{body: cnvrResponse}], undefined, '1NYN')) - .to.deep.equal([{ type: 'image', url: `${syncurl_image}?us_privacy=1NYN` }]); - }); - }); -}); diff --git a/test/spec/modules/copper6sspBidAdapter_spec.js b/test/spec/modules/copper6sspBidAdapter_spec.js deleted file mode 100644 index 3c32750cb..000000000 --- a/test/spec/modules/copper6sspBidAdapter_spec.js +++ /dev/null @@ -1,519 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/copper6sspBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'copper6ssp'; - -describe('Copper6SSPBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://endpoint.copper6.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys( - 'deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - expect(bidderRequest).to.have.property('ortb2'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://сsync.copper6.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://сsync.copper6.com/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://сsync.copper6.com/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/cpmstarBidAdapter_spec.js b/test/spec/modules/cpmstarBidAdapter_spec.js deleted file mode 100755 index c1c773d50..000000000 --- a/test/spec/modules/cpmstarBidAdapter_spec.js +++ /dev/null @@ -1,237 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/cpmstarBidAdapter.js'; -import { deepClone } from 'src/utils.js'; -import { config } from 'src/config.js'; - -const valid_bid_requests = [{ - 'bidder': 'cpmstar', - 'params': { - 'placementId': '57' - }, - 'sizes': [[300, 250]], - 'bidId': 'bidId' -}]; - -const bidderRequest = { - refererInfo: { - referer: 'referer', - reachedTop: false, - } -}; - -const serverResponse = { - body: [{ - creatives: [{ - cpm: 1, - width: 0, - height: 0, - currency: 'USD', - netRevenue: true, - ttl: 1, - creativeid: '1234', - requestid: '11123', - code: 'no idea', - media: 'banner', - } - ], - syncs: [{ type: 'image', url: 'https://server.cpmstar.com/pixel.aspx' }] - }] -}; - -describe('Cpmstar Bid Adapter', function () { - describe('isBidRequestValid', function () { - it('should return true since the bid is valid', - function () { - var bid = { params: { placementId: 123456 } }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }) - - it('should return false since the bid is invalid', function () { - var bid = { params: { placementId: '' } }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }) - - it('should return a valid player size', function () { - var bid = { - mediaTypes: { - video: { - playerSize: [[960, 540]] - } - } - } - expect(spec.getPlayerSize(bid)[0]).to.equal(960); - expect(spec.getPlayerSize(bid)[1]).to.equal(540); - }) - - it('should return a default player size', function () { - var bid = { - mediaTypes: { - video: { - playerSize: null - } - } - } - expect(spec.getPlayerSize(bid)[0]).to.equal(640); - expect(spec.getPlayerSize(bid)[1]).to.equal(440); - }) - }); - - describe('buildRequests', function () { - it('should produce a valid production request', function () { - var requests = spec.buildRequests(valid_bid_requests, bidderRequest); - expect(requests[0]).to.have.property('method'); - expect(requests[0]).to.have.property('url'); - expect(requests[0]).to.have.property('bidRequest'); - expect(requests[0].url).to.include('https://server.cpmstar.com/view.aspx'); - }); - it('should produce a valid staging request', function () { - var stgReq = deepClone(valid_bid_requests); - stgReq[0].params.endpoint = 'staging'; - var requests = spec.buildRequests(stgReq, bidderRequest); - expect(requests[0]).to.have.property('method'); - expect(requests[0]).to.have.property('url'); - expect(requests[0]).to.have.property('bidRequest'); - expect(requests[0].url).to.include('https://staging.server.cpmstar.com/view.aspx'); - }); - it('should produce a valid dev request', function () { - var devReq = deepClone(valid_bid_requests); - devReq[0].params.endpoint = 'dev'; - var requests = spec.buildRequests(devReq, bidderRequest); - expect(requests[0]).to.have.property('method'); - expect(requests[0]).to.have.property('url'); - expect(requests[0]).to.have.property('bidRequest'); - expect(requests[0].url).to.include('https://dev.server.cpmstar.com/view.aspx'); - }); - it('should produce a request with support for GDPR', function () { - var gdpr_bidderRequest = deepClone(bidderRequest); - gdpr_bidderRequest.gdprConsent = { - consentString: 'consentString', - gdprApplies: true - }; - var requests = spec.buildRequests(valid_bid_requests, gdpr_bidderRequest); - expect(requests[0]).to.have.property('url'); - expect(requests[0].url).to.include('gdpr_consent=consentString'); - expect(requests[0].url).to.include('gdpr=1'); - }); - it('should produce a request with support for USP', function () { - var usp_bidderRequest = deepClone(bidderRequest); - usp_bidderRequest.uspConsent = '1YYY'; - var requests = spec.buildRequests(valid_bid_requests, usp_bidderRequest); - expect(requests[0]).to.have.property('url'); - expect(requests[0].url).to.include('us_privacy=1YYY'); - }); - it('should produce a request with support for COPPA', function () { - sinon.stub(config, 'getConfig').withArgs('coppa').returns(true); - var requests = spec.buildRequests(valid_bid_requests, bidderRequest); - config.getConfig.restore(); - expect(requests[0]).to.have.property('url'); - expect(requests[0].url).to.include('tfcd=1'); - }); - }); - - it('should produce a request with support for OpenRTB SupplyChain', function () { - var reqs = deepClone(valid_bid_requests); - reqs[0].ortb2 = { - source: { - ext: { - schain: { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'exchange1.com', - 'sid': '1234', - 'hp': 1 - }, - { - 'asi': 'exchange2.com', - 'sid': 'abcd', - 'hp': 1 - } - ] - } - } - } - }; - var requests = spec.buildRequests(reqs, bidderRequest); - expect(requests[0]).to.have.property('url'); - expect(requests[0].url).to.include('&schain=1.0%2C1%21exchange1.com%2C1234%2C1%2C%2C%2C%21exchange2.com%2Cabcd%2C1%2C%2C%2C'); - }); - - describe('interpretResponse', function () { - const request = { - bidRequest: { - mediaType: 'BANNER' - } - }; - - it('should return a valid bidresponse array', function () { - var r = spec.interpretResponse(serverResponse, request) - var c = serverResponse.body[0].creatives[0]; - expect(r[0].length).to.not.equal(0); - expect(r[0].requestId).equal(c.requestid); - expect(r[0].creativeId).equal(c.creativeid); - expect(r[0].cpm).equal(c.cpm); - expect(r[0].width).equal(c.width); - expect(r[0].height).equal(c.height); - expect(r[0].currency).equal(c.currency); - expect(r[0].netRevenue).equal(c.netRevenue); - expect(r[0].ttl).equal(c.ttl); - expect(r[0].ad).equal(c.code); - }); - - it('should return a valid bidresponse array from a non-array-body', function () { - var r = spec.interpretResponse({ body: serverResponse.body[0] }, request) - var c = serverResponse.body[0].creatives[0]; - expect(r[0].length).to.not.equal(0); - expect(r[0].requestId).equal(c.requestid); - expect(r[0].creativeId).equal(c.creativeid); - expect(r[0].cpm).equal(c.cpm); - expect(r[0].width).equal(c.width); - expect(r[0].height).equal(c.height); - expect(r[0].currency).equal(c.currency); - expect(r[0].netRevenue).equal(c.netRevenue); - expect(r[0].ttl).equal(c.ttl); - expect(r[0].ad).equal(c.code); - }); - - it('should return undefined due to an invalid cpm value', function () { - var badServer = deepClone(serverResponse); - badServer.body[0].creatives[0].cpm = 0; - var c = spec.interpretResponse(badServer, request); - expect(c).to.be.undefined; - }); - - it('should return undefined due to a bad response', function () { - var badServer = deepClone(serverResponse); - badServer.body[0].creatives[0].code = null; - var c = spec.interpretResponse(badServer, request); - expect(c).to.be.undefined; - }); - - it('should return a valid response with a dealId', function () { - var dealServer = deepClone(serverResponse); - dealServer.body[0].creatives[0].dealId = 'deal'; - expect(spec.interpretResponse(dealServer, request)[0].dealId).to.equal('deal'); - }); - }); - - describe('getUserSyncs', function () { - var sres = [deepClone(serverResponse)]; - - it('should return a valid pixel sync', function () { - var syncs = spec.getUserSyncs({ pixelEnabled: true }, sres); - expect(syncs.length).equal(1); - expect(syncs[0].type).equal('image'); - expect(syncs[0].url).equal('https://server.cpmstar.com/pixel.aspx'); - }); - - it('should return a valid iframe sync', function () { - sres[0].body[0].syncs[0].type = 'iframe'; - var syncs = spec.getUserSyncs({ iframeEnabled: true }, sres); - expect(syncs.length).equal(1); - expect(syncs[0].type).equal('iframe'); - expect(syncs[0].url).equal('https://server.cpmstar.com/pixel.aspx'); - }); - }); -}); diff --git a/test/spec/modules/craftBidAdapter_spec.js b/test/spec/modules/craftBidAdapter_spec.js deleted file mode 100644 index 92aa10309..000000000 --- a/test/spec/modules/craftBidAdapter_spec.js +++ /dev/null @@ -1,169 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/craftBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import {config} from 'src/config.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -describe('craftAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - before(function() { - getGlobal().bidderSettings = { - craft: { - storageAllowed: true - } - }; - this.windowContext = window.context; - window.context = null; - }); - - after(function() { - getGlobal().bidderSettings = {}; - window.context = this.windowContext; - }); - const bid = { - bidder: 'craft', - params: { - sitekey: 'craft-prebid-example', - placementId: '1234abcd' - }, - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when params.sitekey not found', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - placementId: '1234abcd' - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when params.placementId not found', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - sitekey: 'craft-prebid-example' - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when AMP cotext found', function () { - window.context = { - pageViewId: 'xxx' - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - before(function () { - getGlobal().bidderSettings = { - craft: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - const bidRequests = [{ - bidder: 'craft', - params: { - 'sitekey': 'craft-prebid-example', - 'placementId': '1234abcd' - }, - adUnitCode: '/21998384947/prebid-example', - sizes: [[300, 250]], - bidId: '0396fae4eb5f47', - bidderRequestId: '4a859978b5d4bd', - auctionId: '8720f980-4639-4150-923a-e96da2f1de36', - transactionId: 'e0c52da2-c008-491c-a910-c6765d948700', - }]; - const bidderRequest = { - refererInfo: { - topmostLocation: 'https://www.gacraft.jp/publish/craft-prebid-example.html' - } - }; - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://gacraft.jp/prebid-v3/craft-prebid-example'); - const data = JSON.parse(request.data); - expect(data.tags).to.deep.equals([{ - sitekey: 'craft-prebid-example', - placementId: '1234abcd', - uid: null, - sizes: [[300, 250]], - primary_size: [300, 250], - uuid: '0396fae4eb5f47' - }]); - expect(data.referrer_detection).to.deep.equals({ - rd_ref: 'https://www.gacraft.jp/publish/craft-prebid-example.html' - }); - }); - }); - - describe('interpretResponse', function() { - const serverResponse = { - body: { - tags: [{ - uuid: '0396fae4eb5f47', - bid_key: '72038482-c4c3-4055-9e7e-0579585bb421', - won_url: 'https://www.gacraft.jp/publish/won', - ads: [{ - content_source: 'rtb', - ad_type: 'banner', - creative_id: 9999, - cpm: 10.01, - deal_id: '8DEF60EFDFB5', - rtb: { - banner: { - content: '', - width: 300, - height: 250 - }, - } - }] - }], - } - }; - const bidderRequest = { - bids: [{ - bidId: '0396fae4eb5f47', - adUnitCode: 'craft-prebid-example' - }] - }; - it('should get correct bid response', function() { - const bids = spec.interpretResponse(serverResponse, {bidderRequest: bidderRequest}); - expect(bids).to.have.lengthOf(1); - expect(bids[0]).to.deep.equals({ - _adUnitCode: 'craft-prebid-example', - _bidKey: '72038482-c4c3-4055-9e7e-0579585bb421', - _prebidWon: 'https://www.gacraft.jp/publish/won', - ad: '', - cpm: 10.01, - creativeId: 9999, - currency: 'JPY', - dealId: '8DEF60EFDFB5', - height: 250, - mediaType: 'banner', - meta: null, - netRevenue: true, - requestId: '0396fae4eb5f47', - ttl: 360, - width: 300, - }); - }); - }); -}); diff --git a/test/spec/modules/criteoBidAdapter_spec.js b/test/spec/modules/criteoBidAdapter_spec.js deleted file mode 100644 index f6f6d31fe..000000000 --- a/test/spec/modules/criteoBidAdapter_spec.js +++ /dev/null @@ -1,2849 +0,0 @@ -import {expect} from 'chai'; -import {spec, storage} from 'modules/criteoBidAdapter.js'; -import * as utils from 'src/utils.js'; -import * as refererDetection from 'src/refererDetection.js'; -import * as ajax from 'src/ajax.js'; -import {config} from '../../../src/config.js'; -import {BANNER, NATIVE, VIDEO} from '../../../src/mediaTypes.js'; -import {addFPDToBidderRequest} from '../../helpers/fpd.js'; -import 'modules/userId/index.js'; -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; -import 'modules/consentManagementGpp.js'; - -import {hook} from '../../../src/hook.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -describe('The Criteo bidding adapter', function () { - let sandbox, ajaxStub, logWarnStub; - - beforeEach(function () { - getGlobal().bidderSettings = { - criteo: { - storageAllowed: true - } - }; - // Remove FastBid to avoid side effects - localStorage.removeItem('criteo_fast_bid'); - sandbox = sinon.createSandbox(); - logWarnStub = sandbox.stub(utils, 'logWarn'); - ajaxStub = sandbox.stub(ajax, 'ajax'); - }); - - afterEach(function () { - getGlobal().bidderSettings = {}; - global.Criteo = undefined; - try { - sandbox?.restore(); - } catch (e) { - // sinon sandbox restore may fail if a stubbed object went undefined - // catch and ignore to avoid breaking unrelated tests - // finding the bad stub is proving to be extremely difficult - /* eslint-disable no-console */ - console.error('sandbox restore error:', e); - /* eslint-enable no-console */ - } - }); - - describe('getUserSyncs in pixel mode', function () { - const syncOptions = { - pixelEnabled: true - }; - - it('should not trigger sync if publisher did not enable pixel based syncs', function () { - const userSyncs = spec.getUserSyncs({ - iframeEnabled: false - }, undefined, undefined, undefined); - - expect(userSyncs).to.eql([]); - }); - - it('should not trigger sync if purpose one is not granted', function () { - const gdprConsent = { - gdprApplies: true, - consentString: 'ABC', - vendorData: { - purpose: { - consents: { - 1: false - } - } - } - }; - const userSyncs = spec.getUserSyncs(syncOptions, undefined, gdprConsent, undefined); - - expect(userSyncs).to.eql([]); - }); - - it('should trigger sync with consent data', function () { - const usPrivacy = 'usp_string'; - - const gppConsent = { - gppString: 'gpp_string', - applicableSections: [ 1, 2 ] - }; - - const gdprConsent = { - gdprApplies: true, - consentString: 'ABC', - vendorData: { - purpose: { - consents: { - 1: true - } - } - } - }; - - const userSyncs = spec.getUserSyncs(syncOptions, undefined, gdprConsent, usPrivacy, gppConsent); - - expect(userSyncs).to.eql([{ - type: 'image', - url: 'https://ssp-sync.criteo.com/user-sync/redirect?profile=207&gdprapplies=true&gdpr=ABC&ccpa=usp_string&gpp=gpp_string&gpp_sid=1&gpp_sid=2' - }]); - }); - }); - - describe('getUserSyncs in iframe mode', function () { - const syncOptionsIframeEnabled = { - iframeEnabled: true - }; - - const expectedHash = { - cw: true, - lsw: true, - origin: 'criteoPrebidAdapter', - requestId: '123456', - tld: 'www.abc.com', - topUrl: 'www.abc.com', - version: '$prebid.version$'.replace(/\./g, '_'), - }; - - let sandbox, - randomStub, - getConfigStub, - getRefererInfoStub, - cookiesAreEnabledStub, - localStorageIsEnabledStub, - getCookieStub, - setCookieStub, - getDataFromLocalStorageStub, - setDataInLocalStorageStub, - removeDataFromLocalStorageStub, - triggerPixelStub; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - getConfigStub = sandbox.stub(config, 'getConfig'); - getConfigStub.withArgs('criteo.fastBidVersion').returns('none'); - - randomStub = sandbox.stub(Math, 'random'); - randomStub.returns(123456); - - getRefererInfoStub = sandbox.stub(refererDetection, 'getRefererInfo'); - getRefererInfoStub.returns({ - domain: 'www.abc.com' - }); - - cookiesAreEnabledStub = sandbox.stub(storage, 'cookiesAreEnabled'); - cookiesAreEnabledStub.returns(true); - localStorageIsEnabledStub = sandbox.stub(storage, 'localStorageIsEnabled'); - localStorageIsEnabledStub.returns(true); - - getCookieStub = sandbox.stub(storage, 'getCookie'); - setCookieStub = sandbox.stub(storage, 'setCookie'); - getDataFromLocalStorageStub = sandbox.stub(storage, 'getDataFromLocalStorage'); - setDataInLocalStorageStub = sandbox.stub(storage, 'setDataInLocalStorage'); - removeDataFromLocalStorageStub = sandbox.stub(storage, 'removeDataFromLocalStorage'); - - triggerPixelStub = sandbox.stub(utils, 'triggerPixel'); - }); - - afterEach(function () { - sandbox?.restore(); - }); - - it('should not trigger sync if publisher did not enable iframe based syncs', function () { - const userSyncs = spec.getUserSyncs({ - iframeEnabled: false - }, undefined, undefined, undefined); - - expect(userSyncs).to.eql([]); - }); - - it('should not trigger sync if purpose one is not granted', function () { - const gdprConsent = { - gdprApplies: true, - consentString: 'ABC', - vendorData: { - purpose: { - consents: { - 1: false - } - } - } - }; - const userSyncs = spec.getUserSyncs(syncOptionsIframeEnabled, undefined, gdprConsent, undefined); - - expect(userSyncs).to.eql([]); - }); - - it('forwards ids from cookies', function () { - const cookieData = { - 'cto_bundle': 'a', - 'cto_optout': 'b' - }; - - const expectedHashWithCookieData = { - ...expectedHash, - ...{ - bundle: cookieData['cto_bundle'], - optoutCookie: cookieData['cto_optout'] - } - }; - - getCookieStub.callsFake(cookieName => cookieData[cookieName]); - - const userSyncs = spec.getUserSyncs(syncOptionsIframeEnabled, undefined, undefined, undefined); - - expect(userSyncs).to.eql([{ - type: 'iframe', - url: `https://gum.criteo.com/syncframe?origin=criteoPrebidAdapter&topUrl=www.abc.com&gpp=#${JSON.stringify(expectedHashWithCookieData, Object.keys(expectedHashWithCookieData).sort()).replace(/"/g, '%22')}` - }]); - }); - - it('forwards ids from local storage', function () { - const localStorageData = { - 'cto_bundle': 'a', - 'cto_optout': 'b' - }; - - const expectedHashWithLocalStorageData = { - ...expectedHash, - ...{ - bundle: localStorageData['cto_bundle'], - optoutCookie: localStorageData['cto_optout'] - } - }; - - getDataFromLocalStorageStub.callsFake(localStorageName => localStorageData[localStorageName]); - - const userSyncs = spec.getUserSyncs(syncOptionsIframeEnabled, undefined, undefined, undefined); - - expect(userSyncs).to.eql([{ - type: 'iframe', - url: `https://gum.criteo.com/syncframe?origin=criteoPrebidAdapter&topUrl=www.abc.com&gpp=#${JSON.stringify(expectedHashWithLocalStorageData, Object.keys(expectedHashWithLocalStorageData).sort()).replace(/"/g, '%22')}` - }]); - }); - - it('forwards gdpr data', function () { - const gdprConsent = { - gdprApplies: true, - consentString: 'ABC', - vendorData: { - purpose: { - consents: { - 1: true - } - } - } - }; - const userSyncs = spec.getUserSyncs(syncOptionsIframeEnabled, undefined, gdprConsent, undefined); - - expect(userSyncs).to.eql([{ - type: 'iframe', - url: `https://gum.criteo.com/syncframe?origin=criteoPrebidAdapter&topUrl=www.abc.com&gdpr=1&gdpr_consent=ABC&gpp=#${JSON.stringify(expectedHash).replace(/"/g, '%22')}` - }]); - }); - - it('forwards usp data', function () { - const userSyncs = spec.getUserSyncs(syncOptionsIframeEnabled, undefined, undefined, 'ABC'); - - expect(userSyncs).to.eql([{ - type: 'iframe', - url: `https://gum.criteo.com/syncframe?origin=criteoPrebidAdapter&topUrl=www.abc.com&us_privacy=ABC&gpp=#${JSON.stringify(expectedHash).replace(/"/g, '%22')}` - }]); - }); - - it('should delete user data when calling onDataDeletionRequest', () => { - const cookieData = { - 'cto_bundle': 'a' - }; - const lsData = { - 'cto_bundle': 'a' - } - getCookieStub.callsFake(cookieName => cookieData[cookieName]); - setCookieStub.callsFake((cookieName, value, expires) => cookieData[cookieName] = value); - getDataFromLocalStorageStub.callsFake(name => lsData[name]); - removeDataFromLocalStorageStub.callsFake(name => lsData[name] = ''); - spec.onDataDeletionRequest([]); - expect(getCookieStub.calledOnce).to.equal(true); - expect(setCookieStub.calledOnce).to.equal(true); - expect(getDataFromLocalStorageStub.calledOnce).to.equal(true); - expect(removeDataFromLocalStorageStub.calledOnce).to.equal(true); - expect(cookieData.cto_bundle).to.equal(''); - expect(lsData.cto_bundle).to.equal(''); - expect(ajaxStub.calledOnce).to.equal(true); - }); - - it('should not call API when calling onDataDeletionRequest with no id', () => { - const cookieData = { - 'cto_bundle': '' - }; - const lsData = { - 'cto_bundle': '' - } - getCookieStub.callsFake(cookieName => cookieData[cookieName]); - setCookieStub.callsFake((cookieName, value, expires) => cookieData[cookieName] = value); - getDataFromLocalStorageStub.callsFake(name => lsData[name]); - removeDataFromLocalStorageStub.callsFake(name => lsData[name] = ''); - spec.onDataDeletionRequest([]); - expect(getCookieStub.calledOnce).to.be.true; - expect(setCookieStub.called).to.be.false; - expect(getDataFromLocalStorageStub.calledOnce).to.be.true - expect(removeDataFromLocalStorageStub.called).to.be.false; - expect(ajaxStub.called).to.be.false; - }); - - it('should trigger sync pixel from iframe response', function (done) { - const userSyncs = spec.getUserSyncs(syncOptionsIframeEnabled, undefined, undefined, undefined); - - const event = new MessageEvent('message', { - data: { - requestId: '123456', - callbacks: [ - 'https://example.com/pixel1', - 'https://example.com/pixel2' - ] - }, - origin: 'https://gum.criteo.com' - }); - - window.dispatchEvent(event); - setTimeout(() => { - expect(triggerPixelStub.calledTwice).to.be.true; - expect(triggerPixelStub.firstCall.calledWith('https://example.com/pixel1')).to.be.true; - expect(triggerPixelStub.secondCall.calledWith('https://example.com/pixel2')).to.be.true; - - done(); - }, 0); - }); - - it('should write cookie only on TLD+1 level', function(done) { - const cookies = {}; - - const userSyncs = spec.getUserSyncs(syncOptionsIframeEnabled, undefined, undefined, undefined); - - setCookieStub.callsFake((name, value, expires, _, domain) => { - if (domain !== '.com') { - cookies[name] = value; - } - }); - - getCookieStub.callsFake((name) => cookies[name]); - - const event = new MessageEvent('message', { - data: { - requestId: '123456', - bundle: 'bundle' - }, - origin: 'https://gum.criteo.com' - }); - - window.dispatchEvent(event); - setTimeout(() => { - expect(setCookieStub.calledWith('cto_bundle', 'bundle', sinon.match.string, null, '.com')).to.be.true; - expect(setCookieStub.calledWith('cto_bundle', 'bundle', sinon.match.string, null, '.abc.com')).to.be.true; - expect(setCookieStub.calledWith('cto_bundle', 'bundle', sinon.match.string, null, '.www.abc.com')).to.be.false; - expect(cookies).to.deep.equal({ 'cto_bundle': 'bundle' }); - - done(); - }, 0); - }); - }); - - describe('isBidRequestValid', function () { - it('should return false when given an invalid bid', function () { - const bid = { - bidder: 'criteo', - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equal(false); - }); - - it('should return true when given a zoneId bid', function () { - const bid = { - bidder: 'criteo', - params: { - zoneId: 123, - }, - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equal(true); - }); - - it('should return true when given a networkId bid', function () { - const bid = { - bidder: 'criteo', - params: { - networkId: 456, - }, - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equal(true); - }); - - it('should return true when given a mixed bid with both a zoneId and a networkId', function () { - const bid = { - bidder: 'criteo', - params: { - zoneId: 123, - networkId: 456, - }, - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equal(true); - }); - - it('should return true when given a valid video bid request using mix custom bidder video parameters', function () { - expect(spec.isBidRequestValid({ - bidder: 'criteo', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 480], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - networkId: 456, - video: { - skip: 1, - placement: 1, - playbackmethod: 1 - } - }, - })).to.equal(true); - - expect(spec.isBidRequestValid({ - bidder: 'criteo', - mediaTypes: { - video: { - context: 'outstream', - mimes: ['video/mpeg'], - playerSize: [640, 480], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - networkId: 456, - video: { - skip: 1, - placement: 2, - playbackmethod: 1 - } - }, - })).to.equal(true); - }); - - it('should return true when given a valid video bid request using only mediaTypes.video parameters', function () { - expect(spec.isBidRequestValid({ - bidder: 'criteo', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 480], - protocols: [5, 6], - maxduration: 30, - api: [1, 2], - skip: 1, - placement: 1, - minduration: 0, - playbackmethod: 1, - startdelay: 0, - plcmt: 1 - } - }, - params: { - networkId: 456 - }, - })).to.equal(true); - }); - - it('should return false when given an invalid video bid request', function () { - expect(spec.isBidRequestValid({ - bidder: 'criteo', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - networkId: 456, - video: { - skip: 1, - placement: 1, - playbackmethod: 1 - } - }, - })).to.equal(false); - - expect(spec.isBidRequestValid({ - bidder: 'criteo', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - networkId: 456, - video: { - skip: 1, - placement: 1, - playbackmethod: 1 - } - }, - })).to.equal(false); - - expect(spec.isBidRequestValid({ - bidder: 'criteo', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 480], - maxduration: 30, - api: [1, 2] - } - }, - params: { - networkId: 456, - video: { - skip: 1, - placement: 1, - playbackmethod: 1 - } - }, - })).to.equal(false); - - expect(spec.isBidRequestValid({ - bidder: 'criteo', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 480], - protocols: [5, 6], - api: [1, 2] - } - }, - params: { - networkId: 456, - video: { - skip: 1, - placement: 1, - playbackmethod: 1 - } - }, - })).to.equal(false); - - expect(spec.isBidRequestValid({ - bidder: 'criteo', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 480], - protocols: [5, 6], - maxduration: 30 - } - }, - params: { - networkId: 456, - video: { - skip: 1, - placement: 1, - playbackmethod: 1 - } - }, - })).to.equal(false); - - expect(spec.isBidRequestValid({ - bidder: 'criteo', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 480], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - networkId: 456, - video: { - placement: 1, - playbackmethod: 1 - } - }, - })).to.equal(false); - - expect(spec.isBidRequestValid({ - bidder: 'criteo', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 480], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - networkId: 456, - video: { - skip: 1, - playbackmethod: 1 - } - }, - })).to.equal(false); - - expect(spec.isBidRequestValid({ - bidder: 'criteo', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 480], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - networkId: 456, - video: { - skip: 1, - placement: 1 - } - }, - })).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const refererUrl = 'https://criteo.com?pbt_debug=1&pbt_nolog=1'; - const bidderRequest = { - refererInfo: { - page: refererUrl, - topmostLocation: refererUrl - }, - timeout: 3000, - gdprConsent: { - gdprApplies: true, - consentString: 'consentDataString', - vendorData: { - vendorConsents: { - '91': 1 - }, - }, - apiVersion: 1, - }, - }; - const defaultBidRequests = [{ - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { sizes: [[728, 90]] } - }, - params: {} - }] - - let sandbox, localStorageIsEnabledStub, bidderConfigStub; - - before(() => { - hook.ready(); - }); - - this.beforeEach(function () { - sandbox = sinon.createSandbox(); - localStorageIsEnabledStub = sandbox.stub(storage, 'localStorageIsEnabled'); - bidderConfigStub = sandbox.stub(config, "getBidderConfig") - localStorageIsEnabledStub.returns(true); - }); - - afterEach(function () { - sandbox?.restore(); - config.resetConfig(); - }); - - it('should properly build a request using random uuid as auction id', async function () { - // Re‐use the sandbox from beforeEach instead of creating a new one - const generateUUIDStub = sandbox.stub(utils, 'generateUUID'); - generateUUIDStub.returns('def'); - - const minimalBidderRequest = {}; - const bidRequests = [{ - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { sizes: [[728, 90]] } - }, - params: {} - }]; - - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(minimalBidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.id).to.equal('def'); - }); - - it('should properly transmit source.tid if available', async function () { - const bidderRequest = { - ortb2: { - source: { - tid: 'abc' - } - } - }; - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: {} - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.source.tid).to.equal('abc'); - }); - - it('should properly transmit tmax if available', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - transactionId: 'transaction-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: {} - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.tmax).to.equal(bidderRequest.timeout); - }); - - it('should properly transmit bidId if available', async function () { - const bidderRequest = {}; - const bidRequests = [ - { - bidId: 'bidId', - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: {} - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.imp[0].id).to.equal('bidId'); - }); - - it('should properly build a zoneId request', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - ortb2Imp: { - ext: { - tid: 'transaction-123', - }, - }, - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123, - publisherSubId: '123', - integrationMode: 'amp' - }, - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request.url).to.match(/^https:\/\/grid-bidder\.criteo\.com\/openrtb_2_5\/pbjs\/auction\/request\?profileId=207&av=\d+&wv=[^&]+&cb=\d+&lsavail=[01]&im=1&debug=[01]&nolog=[01]$/); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - expect(ortbRequest.site.page).to.equal(refererUrl); - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].tagid).to.equal('bid-123'); - expect(ortbRequest.imp[0].banner.format).to.have.lengthOf(1); - expect(ortbRequest.imp[0].banner.format[0].w).to.equal(728); - expect(ortbRequest.imp[0].banner.format[0].h).to.equal(90); - expect(ortbRequest.imp[0].ext.bidder.zoneid).to.equal(123); - expect(ortbRequest.user.ext.consent).to.equal('consentDataString'); - expect(ortbRequest.regs.ext.gdpr).to.equal(1); - expect(ortbRequest.regs.ext.gdprversion).to.equal(1); - }); - - it('should properly forward eids', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: {} - }, - ]; - const br = { - ...bidderRequest, - ortb2: { - user: { - ext: { - eids: [ - { - source: 'criteo.com', - uids: [{ - id: 'abc', - atype: 1 - }] - } - ] - } - } - } - } - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(br)); - const ortbRequest = request.data; - expect(ortbRequest.user.ext.eids).to.deep.equal([ - { - source: 'criteo.com', - uids: [{ - id: 'abc', - atype: 1 - }] - } - ]); - }); - - if (FEATURES.NATIVE) { - it('should properly build a native request without assets', async function () { - const bidRequests = [ - { - mediaTypes: { - native: {} - }, - params: {} - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.imp[0].native.request_native).to.not.be.null; - expect(ortbRequest.imp[0].native.request_native.assets).to.be.undefined; - }); - } - - if (FEATURES.NATIVE) { - it('should properly build a native request with assets', async function () { - const assets = [{ - required: 1, - id: 1, - img: { - type: 3, - wmin: 100, - hmin: 100, - } - }, - { - required: 1, - id: 2, - title: { - len: 140, - } - }, - { - required: 1, - id: 3, - data: { - type: 1, - } - }, - { - required: 0, - id: 4, - data: { - type: 2, - } - }, - { - required: 0, - id: 5, - img: { - type: 1, - wmin: 20, - hmin: 20, - } - }]; - const bidRequests = [ - { - mediaTypes: { - native: {} - }, - nativeOrtbRequest: { - assets: assets - }, - params: {} - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.imp[0].native.request_native).to.not.be.null; - expect(ortbRequest.imp[0].native.request_native.assets).to.deep.equal(assets); - }); - } - - it('should properly build a networkId request', async function () { - const bidderRequest = { - refererInfo: { - page: refererUrl, - topmostLocation: refererUrl, - }, - timeout: 3000, - gdprConsent: { - gdprApplies: false, - consentString: undefined, - vendorData: { - vendorConsents: { - '1': 0 - }, - }, - }, - }; - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - ortb2Imp: { - ext: { - tid: 'transaction-123', - }, - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [728, 90]] - } - }, - params: { - networkId: 456, - }, - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request.url).to.match(/^https:\/\/grid-bidder\.criteo\.com\/openrtb_2_5\/pbjs\/auction\/request\?profileId=207&av=\d+&wv=[^&]+&cb=\d+&lsavail=[01]&debug=[01]&nolog=[01]&networkId=456$/); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - expect(ortbRequest.site.page).to.equal(refererUrl); - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].tagid).to.equal('bid-123'); - expect(ortbRequest.imp[0].banner.format).to.have.lengthOf(2); - expect(ortbRequest.imp[0].banner.format[0].w).to.equal(300); - expect(ortbRequest.imp[0].banner.format[0].h).to.equal(250); - expect(ortbRequest.imp[0].banner.format[1].w).to.equal(728); - expect(ortbRequest.imp[0].banner.format[1].h).to.equal(90); - expect(ortbRequest.user?.ext?.consent).to.equal(undefined); - expect(ortbRequest.regs.ext.gdpr).to.equal(0); - }); - - it('should properly build a mixed request with both a zoneId and a networkId', async function () { - const bidderRequest = { - refererInfo: { - page: refererUrl, - topmostLocation: refererUrl, - }, - timeout: 3000 - }; - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - ortb2Imp: { - ext: { - tid: 'transaction-123', - }, - }, - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123, - }, - }, - { - bidder: 'criteo', - adUnitCode: 'bid-234', - ortb2Imp: { - ext: { - tid: 'transaction-234', - }, - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [728, 90]] - } - }, - params: { - networkId: 456, - }, - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request.url).to.match(/^https:\/\/grid-bidder\.criteo\.com\/openrtb_2_5\/pbjs\/auction\/request\?profileId=207&av=\d+&wv=[^&]+&cb=\d+&lsavail=[01]&debug=[01]&nolog=[01]&networkId=456$/); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - expect(ortbRequest.site.page).to.equal(refererUrl); - expect(ortbRequest.imp).to.have.lengthOf(2); - expect(ortbRequest.imp[0].tagid).to.equal('bid-123'); - expect(ortbRequest.imp[0].banner.format).to.have.lengthOf(1); - expect(ortbRequest.imp[0].banner.format[0].w).to.equal(728); - expect(ortbRequest.imp[0].banner.format[0].h).to.equal(90); - expect(ortbRequest.imp[0].ext.tid).to.equal('transaction-123'); - expect(ortbRequest.imp[0].ext.bidder.zoneid).to.equal(123); - expect(ortbRequest.imp[1].tagid).to.equal('bid-234'); - expect(ortbRequest.imp[1].banner.format).to.have.lengthOf(2); - expect(ortbRequest.imp[1].banner.format[0].w).to.equal(300); - expect(ortbRequest.imp[1].banner.format[0].h).to.equal(250); - expect(ortbRequest.imp[1].banner.format[1].w).to.equal(728); - expect(ortbRequest.imp[1].banner.format[1].h).to.equal(90); - expect(ortbRequest.imp[1].ext.tid).to.equal('transaction-234'); - expect(ortbRequest.user?.ext?.consent).to.equal(undefined); - }); - - it('should properly build a request with undefined gdpr consent fields when they are not provided', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123, - }, - }, - ]; - const bidderRequest = { - timeout: 3000, - gdprConsent: {}, - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.user?.ext?.consent).to.equal(undefined); - expect(ortbRequest.regs?.ext?.gdpr).to.equal(undefined); - }); - - it('should properly build a request with ccpa consent field', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123, - }, - }, - ]; - const bidderRequest = { - timeout: 3000, - uspConsent: '1YNY', - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.regs.ext.us_privacy).to.equal('1YNY'); - }); - - it('should properly build a request with overridden tmax', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123, - }, - }, - ]; - const bidderRequest = { - timeout: 1234 - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.tmax).to.equal(1234); - }); - - it('should properly build a request with device sua field', async function () { - const sua = { - platform: { - brand: 'abc' - } - } - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123, - }, - }, - ]; - const bidderRequest = { - timeout: 3000, - uspConsent: '1YNY', - ortb2: { - device: { - sua: sua - } - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.device.ext.sua).not.to.be.null; - expect(ortbRequest.device.ext.sua.platform.brand).to.equal('abc'); - }); - - it('should properly build a request with gpp consent field', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123, - }, - }, - ]; - const ortb2 = { - regs: { - gpp: 'gpp_consent_string', - gpp_sid: [0, 1, 2], - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest({...bidderRequest, ortb2})).data; - expect(ortbRequest.regs.ext.gpp).to.equal('gpp_consent_string'); - expect(ortbRequest.regs.ext.gpp_sid).to.deep.equal([0, 1, 2]); - }); - - it('should properly build a request with dsa object', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123, - }, - }, - ]; - const dsa = { - required: 3, - pubrender: 0, - datatopub: 2, - transparency: [{ - domain: 'platform1domain.com', - params: [1] - }, { - domain: 'SSP2domain.com', - params: [1, 2] - }] - }; - const ortb2 = { - regs: { - ext: { - dsa: dsa - } - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest({...bidderRequest, ortb2})).data; - expect(ortbRequest.regs.ext.dsa).to.deep.equal(dsa); - }); - - it('should properly build a request with schain object', function () { - const expectedSchain = { - someProperty: 'someValue' - }; - const bidRequests = [ - { - bidder: 'criteo', - ortb2: { - source: { - ext: {schain: expectedSchain} - } - }, - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123, - }, - }, - ]; - - // Create a modified bidderRequest with schain - const modifiedBidderRequest = { - ...bidderRequest, - ortb2: { - source: { - ext: {schain: expectedSchain} - } - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, modifiedBidderRequest).data; - expect(ortbRequest.source.ext.schain).to.deep.equal(expectedSchain); - }); - - it('should properly build a request with bcat field', async function () { - const bcat = ['IAB1', 'IAB2']; - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123, - }, - }, - ]; - const bidderRequest = { - ortb2: { - bcat - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.bcat).to.deep.equal(bcat); - }); - - it('should properly build a request with badv field', async function () { - const badv = ['ford.com']; - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123, - }, - }, - ]; - const bidderRequest = { - ortb2: { - badv - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.badv).to.deep.equal(badv); - }); - - it('should properly build a request with bapp field', async function () { - const bapp = ['com.foo.mygame']; - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123, - }, - }, - ]; - const bidderRequest = { - ortb2: { - bapp - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.bapp).to.deep.equal(bapp); - }); - - if (FEATURES.VIDEO) { - it('should properly build a video request', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - sizes: [[640, 480]], - mediaTypes: { - video: { - context: 'inbanner', - playerSize: [640, 480], - mimes: ['video/mp4', 'video/x-flv'], - maxduration: 30, - api: [1, 2], - protocols: [2, 3], - plcmt: 3, - w: 640, - h: 480, - linearity: 1, - skipmin: 30, - skipafter: 30, - minbitrate: 10000, - maxbitrate: 48000, - delivery: [1, 2, 3], - pos: 1, - playbackend: 1, - adPodDurationSec: 30, - durationRangeSec: [1, 30], - } - }, - params: { - zoneId: 123, - video: { - skip: 1, - minduration: 5, - startdelay: 5, - playbackmethod: [1, 3], - placement: 2 - } - }, - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request.url).to.match(/^https:\/\/grid-bidder\.criteo\.com\/openrtb_2_5\/pbjs\/auction\/request\?profileId=207&av=\d+&wv=[^&]+&cb=\d+&lsavail=[01]&debug=[01]&nolog=[01]$/); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].video.mimes).to.deep.equal(['video/mp4', 'video/x-flv']); - expect(ortbRequest.imp[0].video.maxduration).to.equal(30); - expect(ortbRequest.imp[0].video.api).to.deep.equal([1, 2]); - expect(ortbRequest.imp[0].video.protocols).to.deep.equal([2, 3]); - expect(ortbRequest.imp[0].video.skip).to.equal(1); - expect(ortbRequest.imp[0].video.minduration).to.equal(5); - expect(ortbRequest.imp[0].video.startdelay).to.equal(5); - expect(ortbRequest.imp[0].video.playbackmethod).to.deep.equal([1, 3]); - expect(ortbRequest.imp[0].video.placement).to.equal(2); - expect(ortbRequest.imp[0].video.w).to.equal(640); - expect(ortbRequest.imp[0].video.h).to.equal(480); - expect(ortbRequest.imp[0].video.linearity).to.equal(1); - expect(ortbRequest.imp[0].video.skipmin).to.equal(30); - expect(ortbRequest.imp[0].video.skipafter).to.equal(30); - expect(ortbRequest.imp[0].video.minbitrate).to.equal(10000); - expect(ortbRequest.imp[0].video.maxbitrate).to.equal(48000); - expect(ortbRequest.imp[0].video.delivery).to.deep.equal([1, 2, 3]); - expect(ortbRequest.imp[0].video.pos).to.equal(1); - expect(ortbRequest.imp[0].video.playbackend).to.equal(1); - expect(ortbRequest.imp[0].video.ext.context).to.equal('inbanner'); - expect(ortbRequest.imp[0].video.ext.playersizes).to.deep.equal(['640x480']); - expect(ortbRequest.imp[0].video.ext.plcmt).to.equal(3); - expect(ortbRequest.imp[0].video.ext.poddur).to.equal(30); - expect(ortbRequest.imp[0].video.ext.rqddurs).to.deep.equal([1, 30]); - }); - } - - if (FEATURES.VIDEO) { - it('should properly build a video request with more than one player size', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - sizes: [[640, 480], [800, 600]], - mediaTypes: { - video: { - playerSize: [[640, 480], [800, 600]], - mimes: ['video/mp4', 'video/x-flv'], - maxduration: 30, - api: [1, 2], - protocols: [2, 3] - } - }, - params: { - zoneId: 123, - video: { - skip: 1, - minduration: 5, - startdelay: 5, - playbackmethod: [1, 3], - placement: 2 - } - }, - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request.url).to.match(/^https:\/\/grid-bidder\.criteo\.com\/openrtb_2_5\/pbjs\/auction\/request\?profileId=207&av=\d+&wv=[^&]+&cb=\d+&lsavail=[01]&debug=[01]&nolog=[01]$/); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - expect(ortbRequest.imp[0].video.mimes).to.deep.equal(['video/mp4', 'video/x-flv']); - expect(ortbRequest.imp[0].video.maxduration).to.equal(30); - expect(ortbRequest.imp[0].video.api).to.deep.equal([1, 2]); - expect(ortbRequest.imp[0].video.protocols).to.deep.equal([2, 3]); - expect(ortbRequest.imp[0].video.skip).to.equal(1); - expect(ortbRequest.imp[0].video.minduration).to.equal(5); - expect(ortbRequest.imp[0].video.startdelay).to.equal(5); - expect(ortbRequest.imp[0].video.playbackmethod).to.deep.equal([1, 3]); - expect(ortbRequest.imp[0].video.placement).to.equal(2); - expect(ortbRequest.imp[0].video.w).to.equal(640); - expect(ortbRequest.imp[0].video.h).to.equal(480); - expect(ortbRequest.imp[0].video.ext.playersizes).to.deep.equal(['640x480', '800x600']); - expect(ortbRequest.imp[0].ext.bidder.zoneid).to.equal(123); - }); - } - - if (FEATURES.VIDEO) { - it('should properly build a video request when mediaTypes.video.skip=0', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - sizes: [[300, 250]], - mediaTypes: { - video: { - playerSize: [[300, 250]], - mimes: ['video/mp4', 'video/MPV', 'video/H264', 'video/webm', 'video/ogg'], - minduration: 1, - maxduration: 30, - playbackmethod: [2, 3, 4, 5, 6], - api: [1, 2, 3, 4, 5, 6], - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 0 - } - }, - params: { - networkId: 456 - } - } - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request.url).to.match(/^https:\/\/grid-bidder\.criteo\.com\/openrtb_2_5\/pbjs\/auction\/request\?profileId=207&av=\d+&wv=[^&]+&cb=\d+&lsavail=[01]&debug=[01]&nolog=[01]&networkId=456$/); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - expect(ortbRequest.imp[0].video.mimes).to.deep.equal(['video/mp4', 'video/MPV', 'video/H264', 'video/webm', 'video/ogg']); - expect(ortbRequest.imp[0].video.minduration).to.equal(1); - expect(ortbRequest.imp[0].video.maxduration).to.equal(30); - expect(ortbRequest.imp[0].video.playbackmethod).to.deep.equal([2, 3, 4, 5, 6]); - expect(ortbRequest.imp[0].video.api).to.deep.equal([1, 2, 3, 4, 5, 6]); - expect(ortbRequest.imp[0].video.protocols).to.deep.equal([1, 2, 3, 4, 5, 6, 7, 8]); - expect(ortbRequest.imp[0].video.skip).to.equal(0); - expect(ortbRequest.imp[0].video.w).to.equal(300); - expect(ortbRequest.imp[0].video.h).to.equal(250); - expect(ortbRequest.imp[0].video.ext.playersizes).to.deep.equal(['300x250']); - }); - } - - it('should properly build a request without first party data', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123 - } - }, - ]; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest({ - ...bidderRequest, - ortb2: {} - })).data; - expect(ortbRequest.site.page).to.equal(refererUrl); - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].tagid).to.equal('bid-123'); - expect(ortbRequest.imp[0].banner.format).to.have.lengthOf(1); - expect(ortbRequest.imp[0].banner.format[0].w).to.equal(728); - expect(ortbRequest.imp[0].banner.format[0].h).to.equal(90); - expect(ortbRequest.imp[0].ext.bidder.zoneid).to.equal(123); - expect(ortbRequest.user.ext.consent).to.equal('consentDataString'); - expect(ortbRequest.regs.ext.gdpr).to.equal(1); - expect(ortbRequest.regs.ext.gdprversion).to.equal(1); - }); - - it('should properly build a request with first party data', async function () { - const siteData = { - keywords: ['power tools'], - content: { - data: [{ - name: 'some_provider', - ext: { - segtax: 3 - }, - segment: [ - {'id': '1001'}, - {'id': '1002'} - ] - }] - }, - ext: { - data: { - pageType: 'article' - } - } - }; - const userData = { - gender: 'M', - data: [{ - name: 'some_provider', - ext: { - segtax: 3 - }, - segment: [ - {'id': '1001'}, - {'id': '1002'} - ] - }], - ext: { - data: { - registered: true - } - } - }; - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123, - ext: { - bidfloor: 0.75 - } - }, - ortb2Imp: { - ext: { - data: { - someContextAttribute: 'abc' - } - } - } - }, - ]; - - const ortb2 = { - site: siteData, - user: userData - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest({...bidderRequest, ortb2})).data; - expect(ortbRequest.user).to.deep.equal({...userData, ext: {...userData.ext, consent: 'consentDataString'}}); - expect(ortbRequest.site).to.deep.equal({ - ...siteData, - page: refererUrl, - domain: 'criteo.com', - publisher: {...ortbRequest.site.publisher, domain: 'criteo.com'} - }); - expect(ortbRequest.imp[0].ext.bidfloor).to.equal(0.75); - expect(ortbRequest.imp[0].ext.data.someContextAttribute).to.equal('abc') - }); - - it('should properly build a request when coppa flag is true', async function () { - const bidRequests = []; - const bidderRequest = {}; - config.setConfig({coppa: true}); - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.regs.coppa).to.equal(1); - }); - - it('should properly build a request when coppa flag is false', async function () { - const bidRequests = []; - const bidderRequest = {}; - config.setConfig({coppa: false}); - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.regs.coppa).to.equal(0); - }); - - it('should properly build a request when coppa flag is not defined', async function () { - const bidRequests = []; - const bidderRequest = {}; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.regs?.coppa).to.be.undefined; - }); - - it('should properly build a banner request with floors', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[300, 250], [728, 90]] - } - }, - params: { - networkId: 456, - }, - - getFloor: inputParams => { - if (inputParams.mediaType === BANNER && inputParams.size[0] === 300 && inputParams.size[1] === 250) { - return { - currency: 'USD', - floor: 1.0 - }; - } else if (inputParams.mediaType === BANNER && inputParams.size[0] === 728 && inputParams.size[1] === 90) { - return { - currency: 'USD', - floor: 2.0 - }; - } else { - return {} - } - } - }, - ]; - const bidderRequest = {}; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].ext.floors).to.deep.equal({ - 'banner': { - '300x250': {'currency': 'USD', 'floor': 1}, - '728x90': {'currency': 'USD', 'floor': 2} - } - }); - }); - - it('should properly build a request with static floors', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[300, 250], [728, 90]] - } - }, - params: { - networkId: 456, - bidFloor: 1, - bidFloorCur: 'EUR' - }, - }, - ]; - const bidderRequest = {}; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].ext.floors).to.deep.equal({ - 'banner': { - '300x250': {'currency': 'EUR', 'floor': 1}, - '728x90': {'currency': 'EUR', 'floor': 1} - } - }); - }); - - it('should properly build a video request with several player sizes with floors', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - video: { - playerSize: [[300, 250], [728, 90]] - } - }, - params: { - networkId: 456, - }, - - getFloor: inputParams => { - if (inputParams.mediaType === VIDEO && inputParams.size[0] === 300 && inputParams.size[1] === 250) { - return { - currency: 'USD', - floor: 1.0 - }; - } else if (inputParams.mediaType === VIDEO && inputParams.size[0] === 728 && inputParams.size[1] === 90) { - return { - currency: 'USD', - floor: 2.0 - }; - } else { - return {} - } - } - }, - ]; - const bidderRequest = {}; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].ext.floors).to.deep.equal({ - 'video': { - '300x250': {'currency': 'USD', 'floor': 1}, - '728x90': {'currency': 'USD', 'floor': 2} - } - }); - }); - - if (FEATURES.VIDEO && FEATURES.NATIVE) { - it('should properly build a multi format request with floors', async function () { - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[300, 250], [728, 90]] - }, - video: { - playerSize: [640, 480], - }, - native: {} - }, - params: { - networkId: 456, - }, - ortb2Imp: { - ext: { - data: { - someContextAttribute: 'abc' - } - } - }, - - getFloor: inputParams => { - if (inputParams.mediaType === BANNER && inputParams.size[0] === 300 && inputParams.size[1] === 250) { - return { - currency: 'USD', - floor: 1.0 - }; - } else if (inputParams.mediaType === BANNER && inputParams.size[0] === 728 && inputParams.size[1] === 90) { - return { - currency: 'USD', - floor: 2.0 - }; - } else if (inputParams.mediaType === VIDEO && inputParams.size[0] === 640 && inputParams.size[1] === 480) { - return { - currency: 'EUR', - floor: 3.2 - }; - } else if (inputParams.mediaType === NATIVE && inputParams.size === '*') { - return { - currency: 'YEN', - floor: 4.99 - }; - } else { - return {} - } - } - }, - ]; - const bidderRequest = {}; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].banner).not.to.be.null; - expect(ortbRequest.imp[0].video).not.to.be.null; - expect(ortbRequest.imp[0].native.request_native).not.to.be.null; - expect(ortbRequest.imp[0].ext.data.someContextAttribute).to.deep.equal('abc'); - expect(ortbRequest.imp[0].ext.floors).to.deep.equal({ - 'banner': { - '300x250': {'currency': 'USD', 'floor': 1}, - '728x90': {'currency': 'USD', 'floor': 2} - }, - 'video': { - '640x480': {'currency': 'EUR', 'floor': 3.2} - }, - 'native': { - '*': {'currency': 'YEN', 'floor': 4.99} - } - }); - }); - } - - it('should properly build a request when imp.rwdd is present', async function () { - const bidderRequest = {}; - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123 - }, - ortb2Imp: { - rwdd: 1 - } - }, - ]; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].ext.rwdd).to.equal(1); - }); - - it('should properly build a request when imp.rwdd is false', async function () { - const bidderRequest = {}; - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123 - }, - ortb2Imp: { - rwdd: 0 - } - }, - ]; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].ext?.rwdd).to.equal(0); - }); - - it('should properly build a request when FLEDGE is enabled', async function () { - const bidderRequest = { - paapi: { - enabled: true - } - }; - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123 - }, - ortb2Imp: { - ext: { - igs: { - ae: 1 - } - } - } - }, - ]; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].ext.igs.ae).to.equal(1); - }); - - it('should properly build a request when FLEDGE is disabled', async function () { - const bidderRequest = { - paapi: { - enabled: false - }, - }; - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123 - }, - ortb2Imp: { - ext: { - igs: { - ae: 1 - } - } - } - }, - ]; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].ext.igs?.ae).to.be.undefined; - }); - - it('should properly transmit the pubid and slot uid if available', async function () { - const bidderRequest = { - ortb2: { - site: { - publisher: { - id: 'pub-777' - } - } - } - }; - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - ortb2Imp: { - ext: { - tid: 'transaction-123', - }, - }, - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - zoneId: 123, - }, - }, - { - bidder: 'criteo', - adUnitCode: 'bid-234', - ortb2Imp: { - ext: { - tid: 'transaction-234', - }, - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [728, 90]] - } - }, - params: { - networkId: 456, - pubid: 'pub-888', - uid: 888 - }, - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.site.publisher.id).to.equal('pub-888'); - expect(ortbRequest.imp[0].ext.bidder.uid).to.be.undefined; - expect(ortbRequest.imp[1].ext.bidder.uid).to.equal(888); - }); - - it('should properly transmit device.ext.cdep if available', async function () { - const bidderRequest = { - ortb2: { - device: { - ext: { - cdep: 'cookieDeprecationLabel' - } - } - } - }; - const bidRequests = []; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.device.ext.cdep).to.equal('cookieDeprecationLabel'); - }); - - it('should interpret correctly gzip configuration given as a string', async function() { - bidderConfigStub.returns({criteo: {gzipEnabled: 'false'}}); - - const request = spec.buildRequests(defaultBidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request.options.endpointCompression).to.be.false; - }); - - it('should interpret correctly gzip configuration given as a boolean', async function () { - bidderConfigStub.returns({criteo: {gzipEnabled: false}}); - - const request = spec.buildRequests(defaultBidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request.options.endpointCompression).to.be.false; - }); - - it('should default to true when it receives an invalid configuration', async function () { - bidderConfigStub.returns({criteo: {gzipEnabled: 'randomString'}}); - - const request = spec.buildRequests(defaultBidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request.options.endpointCompression).to.be.true; - }) - }); - - describe('interpretResponse', function () { - const refererUrl = 'https://criteo.com?pbt_debug=1&pbt_nolog=1'; - const bidderRequest = { - refererInfo: { - page: refererUrl, - topmostLocation: refererUrl - }, - timeout: 3000, - gdprConsent: { - gdprApplies: true, - consentString: 'consentDataString', - vendorData: { - vendorConsents: { - '91': 1 - }, - }, - apiVersion: 1, - }, - }; - - function mockResponse(winningBidId, mediaType) { - return { - id: 'test-requestId', - seatbid: [ - { - seat: 'criteo', - bid: [ - { - id: 'test-bidderId', - impid: winningBidId, - price: 1.23, - adomain: ['criteo.com'], - bundle: '', - iurl: 'http://some_image/', - cid: '123456', - crid: 'test-crId', - dealid: 'deal-code', - w: 728, - h: 90, - adm: 'test-ad', - adm_native: mediaType === NATIVE ? { - ver: '1.2', - assets: [ - { - id: 10, - title: { - text: 'Some product' - } - }, - { - id: 11, - img: { - type: 3, - url: 'https://main_image_url.com', - w: 400, - h: 400 - } - }, - { - id: 12, - data: { - value: 'Some product' - } - }, - { - id: 13, - data: { - value: '1,499 TL' - } - }, - { - id: 15, - data: { - value: 'CTA' - }, - link: { - url: 'https://cta_url.com' - } - }, - { - id: 17, - img: { - type: 1, - url: 'https://main_image_url.com', - w: 200, - h: 200 - }, - link: { - url: 'https://icon_image_url.com' - } - }, - { - id: 16, - data: { - value: 'Some brand' - } - } - ], - eventtrackers: [ - { - event: 1, - method: 1, - url: 'https://eventtrackers.com' - }, - { - event: 1, - method: 1, - url: 'https://test_in_isolation.criteo.com/tpd?dd=HTlW9l9xTEZqRHVlSHFiSWx5Q2VQMlEwSTJhNCUyQkxNazQ1Y29LR3ZmS2VTSDFsUGdkRHNoWjQ2UWp0SGtVZ1RTbHI0TFRpTlVqNWxiUkZOeGVFNjVraW53R0loRVJQNDJOY2R1eWxVdjBBQ1BEdVFvTyUyRlg3aWJaeUFha3UyemNNVGpmJTJCS1prc0FwRjZRJTJCQ2dpaFBJeVhZRmQlMkZURVZocUFRdm03OTdFZHZSbURNZWt4Uzh2M1NSUUxmTmhaTnNnRXd4VkZlOTdJOXdnNGZjaVolMkZWYmdYVjJJMkQ0eGxQaFIwQmVtWk1sQ09tNXlGY0Nwc09GTDladzExJTJGVExGNXJsdGpneERDeTMlMkJuNUlUcEU4NDFLMTZPc2ZoWFUwMmpGbDFpVjBPZUVtTlEwaWNOeHRyRFYyenRKd0lpJTJGTTElMkY1WGZ3Smo3aTh0bUJzdzZRdlZUSXppanNkamo3ekZNZjhKdjl2VDJ5eHV1YnVzdmdRdk5iWnprNXVFMVdmbGs0QU1QY0ozZQ' - } - ], - privacy: 'https://cta_url.com', - ext: { - privacy: { - imageurl: 'https://icon_image_url.com', - clickurl: 'https://cta_url.com', - longlegaltext: '' - } - } - } : undefined, - ext: { - mediatype: mediaType, - displayurl: mediaType === VIDEO ? 'http://test-ad' : undefined, - dsa: { - adrender: 1 - }, - meta: { - networkName: 'Criteo' - }, - videoPlayerType: mediaType === VIDEO ? 'RadiantMediaPlayer' : undefined, - videoPlayerConfig: mediaType === VIDEO ? {} : undefined, - cur: 'CUR' - } - } - ] - } - ] - }; - } - - it('should return an empty array when parsing an empty bid response', async function () { - const bidRequests = []; - const response = {}; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse(response, request); - expect(bids).to.have.lengthOf(0); - }); - - it('should return an empty array when parsing a well-formed no bid response', async function () { - const bidRequests = []; - const response = {seatbid: []}; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.have.lengthOf(0); - }); - - it('should properly parse a banner bid response', async function () { - const bidRequests = [{ - adUnitCode: 'test-requestId', - bidId: 'test-bidId', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - networkId: 456, - } - }]; - const response = mockResponse('test-bidId', BANNER); - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.have.lengthOf(1); - expect(bids[0].mediaType).to.equal(BANNER); - expect(bids[0].requestId).to.equal('test-bidId'); - expect(bids[0].seatBidId).to.equal('test-bidderId') - expect(bids[0].cpm).to.equal(1.23); - expect(bids[0].currency).to.equal('CUR'); - expect(bids[0].width).to.equal(728); - expect(bids[0].height).to.equal(90); - expect(bids[0].ad).to.equal('test-ad'); - expect(bids[0].creativeId).to.equal('test-crId'); - expect(bids[0].dealId).to.equal('deal-code'); - expect(bids[0].meta.advertiserDomains[0]).to.equal('criteo.com'); - expect(bids[0].meta.networkName).to.equal('Criteo'); - expect(bids[0].meta.dsa.adrender).to.equal(1); - }); - - if (FEATURES.VIDEO) { - it('should properly parse a bid response with a video', async function () { - const bidRequests = [{ - adUnitCode: 'test-requestId', - bidId: 'test-bidId', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 480], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - zoneId: 123, - }, - }]; - const response = mockResponse('test-bidId', VIDEO); - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.have.lengthOf(1); - expect(bids[0].mediaType).to.equal(VIDEO); - expect(bids[0].requestId).to.equal('test-bidId'); - expect(bids[0].seatBidId).to.equal('test-bidderId') - expect(bids[0].cpm).to.equal(1.23); - expect(bids[0].currency).to.equal('CUR'); - expect(bids[0].vastUrl).to.equal('http://test-ad'); - expect(bids[0].vastXml).to.equal('test-ad'); - expect(bids[0].playerWidth).to.equal(640); - expect(bids[0].playerHeight).to.equal(480); - expect(bids[0].renderer).to.equal(undefined); - }); - } - - if (FEATURES.VIDEO) { - it('should properly parse a bid response with an outstream video', async function () { - const bidRequests = [{ - adUnitCode: 'test-requestId', - bidId: 'test-bidId', - mediaTypes: { - video: { - context: 'outstream', - mimes: ['video/mpeg'], - playerSize: [640, 480], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - networkId: 456, - }, - }]; - const response = mockResponse('test-bidId', VIDEO); - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.have.lengthOf(1); - expect(bids[0].mediaType).to.equal(VIDEO); - expect(bids[0].requestId).to.equal('test-bidId'); - expect(bids[0].seatBidId).to.equal('test-bidderId') - expect(bids[0].cpm).to.equal(1.23); - expect(bids[0].currency).to.equal('CUR'); - expect(bids[0].vastUrl).to.equal('http://test-ad'); - expect(bids[0].vastXml).to.equal('test-ad'); - expect(bids[0].playerWidth).to.equal(640); - expect(bids[0].playerHeight).to.equal(480); - expect(bids[0].renderer.url).to.equal('https://static.criteo.net/js/ld/publishertag.renderer.js'); - expect(typeof bids[0].renderer.config.documentResolver).to.equal('function'); - expect(typeof bids[0].renderer._render).to.equal('function'); - }); - } - - if (FEATURES.NATIVE) { - it('should properly parse a native bid response', async function () { - const bidRequests = [{ - adUnitCode: 'test-requestId', - bidId: 'test-bidId', - params: { - zoneId: '123', - }, - native: true, - }]; - const response = mockResponse('test-bidId', NATIVE); - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.have.lengthOf(1); - expect(bids[0].mediaType).to.equal(NATIVE); - expect(bids[0].requestId).to.equal('test-bidId'); - expect(bids[0].seatBidId).to.equal('test-bidderId') - expect(bids[0].cpm).to.equal(1.23); - expect(bids[0].currency).to.equal('CUR'); - expect(bids[0].width).to.equal(728); - expect(bids[0].height).to.equal(90); - expect(bids[0].ad).to.equal(undefined); - expect(bids[0].native.ortb).not.to.be.null; - expect(bids[0].native.ortb).to.equal(response.seatbid[0].bid[0].adm); // adm_native field was moved to adm - expect(bids[0].creativeId).to.equal('test-crId'); - expect(bids[0].dealId).to.equal('deal-code'); - expect(bids[0].meta.advertiserDomains[0]).to.equal('criteo.com'); - expect(bids[0].meta.networkName).to.equal('Criteo'); - expect(bids[0].meta.dsa.adrender).to.equal(1); - }); - } - - it('should properly parse a bid response when banner win with twin ad units', async function () { - const bidRequests = [{ - adUnitCode: 'test-requestId', - bidId: 'test-bidId', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 480], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - networkId: 456, - }, - }, { - adUnitCode: 'test-requestId', - bidId: 'test-bidId2', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - networkId: 456, - } - }]; - const response = mockResponse('test-bidId2', BANNER); - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.have.lengthOf(1); - expect(bids[0].mediaType).to.equal(BANNER); - expect(bids[0].requestId).to.equal('test-bidId2'); - expect(bids[0].seatBidId).to.equal('test-bidderId') - expect(bids[0].cpm).to.equal(1.23); - expect(bids[0].currency).to.equal('CUR'); - expect(bids[0].width).to.equal(728); - expect(bids[0].height).to.equal(90); - expect(bids[0].ad).to.equal('test-ad'); - expect(bids[0].creativeId).to.equal('test-crId'); - expect(bids[0].dealId).to.equal('deal-code'); - expect(bids[0].meta.advertiserDomains[0]).to.equal('criteo.com'); - expect(bids[0].meta.networkName).to.equal('Criteo'); - expect(bids[0].meta.dsa.adrender).to.equal(1); - }); - - if (FEATURES.VIDEO) { - it('should properly parse a bid response when video win with twin ad units', async function () { - const bidRequests = [{ - adUnitCode: 'test-requestId', - bidId: 'test-bidId', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 480], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - zoneId: '123' - }, - }, { - adUnitCode: 'test-requestId', - bidId: 'test-bidId2', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - networkId: 456, - } - }]; - const response = mockResponse('test-bidId', VIDEO); - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.have.lengthOf(1); - expect(bids[0].mediaType).to.equal(VIDEO); - expect(bids[0].requestId).to.equal('test-bidId'); - expect(bids[0].seatBidId).to.equal('test-bidderId') - expect(bids[0].cpm).to.equal(1.23); - expect(bids[0].currency).to.equal('CUR'); - expect(bids[0].vastUrl).to.equal('http://test-ad'); - expect(bids[0].vastXml).to.equal('test-ad'); - expect(bids[0].playerWidth).to.equal(640); - expect(bids[0].playerHeight).to.equal(480); - expect(bids[0].renderer).to.equal(undefined); - }); - } - - if (FEATURES.NATIVE) { - it('should properly parse a bid response when native win with twin ad units', async function () { - const bidRequests = [{ - adUnitCode: 'test-requestId', - bidId: 'test-bidId', - mediaTypes: { - native: {} - }, - params: { - networkId: 456, - }, - }, { - adUnitCode: 'test-requestId', - bidId: 'test-bidId2', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - networkId: 456, - } - }]; - const response = mockResponse('test-bidId', NATIVE); - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.have.lengthOf(1); - expect(bids[0].mediaType).to.equal(NATIVE); - expect(bids[0].requestId).to.equal('test-bidId'); - expect(bids[0].seatBidId).to.equal('test-bidderId') - expect(bids[0].cpm).to.equal(1.23); - expect(bids[0].currency).to.equal('CUR'); - expect(bids[0].width).to.equal(728); - expect(bids[0].height).to.equal(90); - expect(bids[0].ad).to.equal(undefined); - expect(bids[0].native.ortb).not.to.be.null; - expect(bids[0].native.ortb).to.equal(response.seatbid[0].bid[0].adm); // adm_native field was moved to adm - expect(bids[0].creativeId).to.equal('test-crId'); - expect(bids[0].dealId).to.equal('deal-code'); - expect(bids[0].meta.advertiserDomains[0]).to.equal('criteo.com'); - expect(bids[0].meta.networkName).to.equal('Criteo'); - expect(bids[0].meta.dsa.adrender).to.equal(1); - }); - } - - it('should properly parse a bid response with FLEDGE auction configs', async function () { - const auctionConfig1 = { - auctionSignals: {}, - decisionLogicUrl: 'https://grid-mercury.criteo.com/fledge/decision', - interestGroupBuyers: ['https://first-buyer-domain.com', 'https://second-buyer-domain.com'], - perBuyerSignals: { - 'https://first-buyer-domain.com': { - foo: 'bar', - }, - 'https://second-buyer-domain.com': { - foo: 'baz' - }, - }, - perBuyerTimeout: { - '*': 500, - 'buyer1': 100, - 'buyer2': 200 - }, - perBuyerGroupLimits: { - '*': 60, - 'buyer1': 300, - 'buyer2': 400 - }, - seller: 'https://seller-domain.com', - sellerTimeout: 500, - sellerSignals: { - foo: 'bar', - foo2: 'bar2', - floor: 1, - currency: 'USD', - perBuyerTimeout: { - 'buyer1': 100, - 'buyer2': 200 - }, - perBuyerGroupLimits: { - 'buyer1': 300, - 'buyer2': 400 - }, - }, - sellerCurrency: 'USD', - }; - const auctionConfig2 = { - auctionSignals: {}, - decisionLogicUrl: 'https://grid-mercury.criteo.com/fledge/decision', - interestGroupBuyers: ['https://first-buyer-domain.com', 'https://second-buyer-domain.com'], - perBuyerSignals: { - 'https://first-buyer-domain.com': { - foo: 'bar', - }, - 'https://second-buyer-domain.com': { - foo: 'baz' - }, - }, - perBuyerTimeout: { - '*': 500, - 'buyer1': 100, - 'buyer2': 200 - }, - perBuyerGroupLimits: { - '*': 60, - 'buyer1': 300, - 'buyer2': 400 - }, - seller: 'https://seller-domain.com', - sellerTimeout: 500, - sellerSignals: { - foo: 'bar', - floor: 1, - perBuyerTimeout: { - 'buyer1': 100, - 'buyer2': 200 - }, - perBuyerGroupLimits: { - 'buyer1': 300, - 'buyer2': 400 - }, - }, - sellerCurrency: '???' - }; - const bidRequests = [ - { - bidId: 'test-bidId', - bidder: 'criteo', - adUnitCode: 'bid-123', - transactionId: 'transaction-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - bidFloor: 1, - bidFloorCur: 'EUR' - } - }, - { - bidId: 'test-bidId-2', - bidder: 'criteo', - adUnitCode: 'bid-123', - transactionId: 'transaction-123', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - params: { - bidFloor: 1, - bidFloorCur: 'EUR' - } - }, - ]; - const response = { - ext: { - igi: [{ - impid: 'test-bidId', - igs: [{ - impid: 'test-bidId', - bidId: 'test-bidId', - config: auctionConfig1 - }] - }, { - impid: 'test-bidId-2', - igs: [{ - impid: 'test-bidId-2', - bidId: 'test-bidId-2', - config: auctionConfig2 - }] - }] - }, - }; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const interpretedResponse = spec.interpretResponse({body: response}, request); - expect(interpretedResponse).to.have.property('bids'); - expect(interpretedResponse).to.have.property('paapi'); - expect(interpretedResponse.bids).to.have.lengthOf(0); - expect(interpretedResponse.paapi).to.have.lengthOf(2); - expect(interpretedResponse.paapi[0]).to.deep.equal({ - bidId: 'test-bidId', - impid: 'test-bidId', - config: auctionConfig1, - }); - expect(interpretedResponse.paapi[1]).to.deep.equal({ - bidId: 'test-bidId-2', - impid: 'test-bidId-2', - config: auctionConfig2, - }); - }); - - [{ - hasBidResponseLevelPafData: true, - hasBidResponseBidLevelPafData: true, - shouldContainsBidMetaPafData: true - }, - { - hasBidResponseLevelPafData: false, - hasBidResponseBidLevelPafData: true, - shouldContainsBidMetaPafData: false - }, - { - hasBidResponseLevelPafData: true, - hasBidResponseBidLevelPafData: false, - shouldContainsBidMetaPafData: false - }, - { - hasBidResponseLevelPafData: false, - hasBidResponseBidLevelPafData: false, - shouldContainsBidMetaPafData: false - }].forEach(testCase => - it('should properly forward or not meta paf data', async () => { - const bidPafContentId = 'abcdef'; - const pafTransmission = { - version: '12' - }; - const bidRequests = [{ - bidId: 'test-bidId', - adUnitCode: 'adUnitId', - sizes: [[300, 250]], - params: { - networkId: 456, - } - }]; - const response = { - id: 'test-requestId', - seatbid: [{ - seat: 'criteo', - bid: [ - { - id: 'test-bidderId', - impid: 'test-bidId', - w: 728, - h: 90, - ext: { - mediatype: BANNER, - paf: testCase.hasBidResponseBidLevelPafData ? { - content_id: bidPafContentId - } : undefined - } - } - ] - }], - ext: (testCase.hasBidResponseLevelPafData ? { - paf: { - transmission: pafTransmission - } - } : undefined) - }; - - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - - expect(bids).to.have.lengthOf(1); - - const expectedBidMetaPafData = { - paf: { - content_id: bidPafContentId, - transmission: pafTransmission - } - }; - - if (testCase.shouldContainsBidMetaPafData) { - expect(bids[0].meta).to.deep.equal(expectedBidMetaPafData); - } else { - expect(bids[0].meta).not.to.deep.equal(expectedBidMetaPafData); - } - }) - ) - }); - - describe('when pubtag prebid adapter is not available', function () { - it('should not warn if sendId is provided on required fields for native bidRequest', async () => { - const bidderRequest = {}; - const bidRequestsWithSendId = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - sizes: [[728, 90]], - mediaTypes: { - native: {} - }, - nativeOrtbRequest: { - assets: [{ - required: 1, - id: 1, - img: { - type: 3, - wmin: 100, - hmin: 100, - } - }] - }, - params: { - zoneId: 123, - publisherSubId: '123' - }, - nativeParams: { - image: { - sendId: true - }, - icon: { - sendId: true - }, - clickUrl: { - sendId: true - }, - displayUrl: { - sendId: true - }, - privacyLink: { - sendId: true - }, - privacyIcon: { - sendId: true - } - } - } - ]; - - const request = spec.buildRequests(bidRequestsWithSendId, await addFPDToBidderRequest(bidderRequest)); - expect(logWarnStub.withArgs('Criteo: all native assets containing URL should be sent as placeholders with sendId(icon, image, clickUrl, displayUrl, privacyLink, privacyIcon)').notCalled).to.be.true; - }); - - it('should warn only once if sendId is not provided on required fields for native bidRequest', async () => { - const bidderRequest = {}; - const bidRequests = [ - { - bidder: 'criteo', - adUnitCode: 'bid-123', - mediaTypes: { - native: {} - }, - nativeOrtbRequest: { - assets: [{ - required: 1, - id: 1, - img: { - type: 3, - wmin: 100, - hmin: 100, - } - }] - }, - params: { - zoneId: 123, - publisherSubId: '123' - }, - }, - { - bidder: 'criteo', - adUnitCode: 'bid-456', - transactionId: 'transaction-456', - mediaTypes: { - native: {} - }, - nativeOrtbRequest: { - assets: [{ - required: 1, - id: 1, - img: { - type: 3, - wmin: 100, - hmin: 100, - } - }] - }, - params: { - zoneId: 456, - publisherSubId: '456' - }, - }, - ]; - - const nativeParamsWithoutSendId = [ - { - nativeParams: { - image: { - sendId: false - }, - } - }, - { - nativeParams: { - icon: { - sendId: false - }, - } - }, - { - nativeParams: { - clickUrl: { - sendId: false - }, - } - }, - { - nativeParams: { - displayUrl: { - sendId: false - }, - } - }, - { - nativeParams: { - privacyLink: { - sendId: false - }, - } - }, - { - nativeParams: { - privacyIcon: { - sendId: false - }, - } - } - ]; - - for (const nativeParams of nativeParamsWithoutSendId) { - let transformedBidRequests = {...bidRequests}; - transformedBidRequests = [Object.assign(transformedBidRequests[0], nativeParams), Object.assign(transformedBidRequests[1], nativeParams)]; - spec.buildRequests(transformedBidRequests, await addFPDToBidderRequest(bidderRequest)); - } - expect(logWarnStub.withArgs('Criteo: all native assets containing URL should be sent as placeholders with sendId(icon, image, clickUrl, displayUrl, privacyLink, privacyIcon)').callCount).to.equal(nativeParamsWithoutSendId.length * bidRequests.length); - }); - }); -}); diff --git a/test/spec/modules/cwireBidAdapter_spec.js b/test/spec/modules/cwireBidAdapter_spec.js deleted file mode 100644 index 3cbf8a631..000000000 --- a/test/spec/modules/cwireBidAdapter_spec.js +++ /dev/null @@ -1,484 +0,0 @@ -import { expect } from "chai"; -import { newBidder } from "../../../src/adapters/bidderFactory.js"; -import { BID_ENDPOINT, spec, storage } from "../../../modules/cwireBidAdapter.js"; -import { deepClone, logInfo } from "../../../src/utils.js"; -import * as utils from "src/utils.js"; -import sinon, { stub } from "sinon"; -import { config } from "../../../src/config.js"; -import * as autoplayLib from "../../../libraries/autoplayDetection/autoplay.js"; - -describe("C-WIRE bid adapter", () => { - config.setConfig({ debug: true }); - let sandbox; - const adapter = newBidder(spec); - const bidRequests = [ - { - bidder: "cwire", - params: { - pageId: "4057", - placementId: "ad-slot-bla", - }, - adUnitCode: "adunit-code", - sizes: [ - [300, 250], - [300, 600], - ], - bidId: "30b31c1838de1e", - bidderRequestId: "22edbae2733bf6", - auctionId: "1d1a030790a475", - transactionId: "04f2659e-c005-4eb1-a57c-fa93145e3843", - }, - ]; - const response = { - body: { - cwid: "2ef90743-7936-4a82-8acf-e73382a64e94", - hash: "17112D98BBF55D3A", - bids: [ - { - html: "

Hello world

", - cpm: 100, - currency: "CHF", - dimensions: [1, 1], - netRevenue: true, - creativeId: "3454", - requestId: "2c634d4ca5ccfb", - placementId: 177, - transactionId: "b4b32618-1350-4828-b6f0-fbb5c329e9a4", - ttl: 360, - }, - ], - }, - }; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - - afterEach(function () { - sandbox.restore(); - }); - describe("inherited functions", function () { - it("exists and is a function", function () { - expect(adapter.callBids).to.exist.and.to.be.a("function"); - expect(spec.isBidRequestValid).to.exist.and.to.be.a("function"); - expect(spec.buildRequests).to.exist.and.to.be.a("function"); - expect(spec.interpretResponse).to.exist.and.to.be.a("function"); - }); - }); - describe("buildRequests", function () { - it("sends bid request to ENDPOINT via POST", function () { - const request = spec.buildRequests(bidRequests); - expect(request.url).to.equal(BID_ENDPOINT); - expect(request.method).to.equal("POST"); - }); - }); - describe("buildRequests with given creative", function () { - let utilsStub; - - beforeEach(function () { - utilsStub = stub(utils, "getParameterByName").callsFake(function () { - return "str-str"; - }); - }); - - afterEach(function () { - utilsStub.restore(); - }); - - it("should add creativeId if url parameter given", function () { - // set from bid.params - const bidRequest = deepClone(bidRequests[0]); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - expect(payload.cwcreative).to.exist; - expect(payload.cwcreative).to.deep.equal("str-str"); - }); - }); - - describe("buildRequests reads adUnit offsetWidth and offsetHeight", function () { - beforeEach(function () { - const documentStub = sandbox.stub(document, "getElementById"); - documentStub.withArgs(`${bidRequests[0].adUnitCode}`).returns({ - offsetWidth: 200, - offsetHeight: 250, - getBoundingClientRect() { - return { width: 200, height: 250 }; - }, - }); - }); - it("width and height should be set", function () { - const bidRequest = deepClone(bidRequests[0]); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - const el = document.getElementById(`${bidRequest.adUnitCode}`); - - logInfo(JSON.stringify(payload)); - - expect(el).to.exist; - expect(payload.slots[0].cwExt.dimensions.width).to.equal(200); - expect(payload.slots[0].cwExt.dimensions.height).to.equal(250); - expect(payload.slots[0].cwExt.style.maxHeight).to.not.exist; - expect(payload.slots[0].cwExt.style.maxWidth).to.not.exist; - }); - afterEach(function () { - sandbox.restore(); - }); - }); - describe("buildRequests reads style attributes", function () { - beforeEach(function () { - const documentStub = sandbox.stub(document, "getElementById"); - documentStub.withArgs(`${bidRequests[0].adUnitCode}`).returns({ - style: { - maxWidth: "400px", - maxHeight: "350px", - }, - getBoundingClientRect() { - return { width: 0, height: 0 }; - }, - }); - }); - it("css maxWidth should be set", function () { - const bidRequest = deepClone(bidRequests[0]); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - const el = document.getElementById(`${bidRequest.adUnitCode}`); - - logInfo(JSON.stringify(payload)); - - expect(el).to.exist; - expect(payload.slots[0].cwExt.style.maxWidth).to.eq("400px"); - expect(payload.slots[0].cwExt.style.maxHeight).to.eq("350px"); - }); - afterEach(function () { - sandbox.restore(); - }); - }); - - describe("buildRequests reads feature flags", function () { - beforeEach(function () { - sandbox.stub(utils, "getParameterByName").callsFake(function () { - return "feature1,feature2"; - }); - }); - - it("read from url parameter", function () { - const bidRequest = deepClone(bidRequests[0]); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - logInfo(JSON.stringify(payload)); - - expect(payload.featureFlags).to.exist; - expect(payload.featureFlags).to.include.members(["feature1", "feature2"]); - }); - afterEach(function () { - sandbox.restore(); - }); - }); - - describe("buildRequests reads cwgroups flag", function () { - beforeEach(function () { - sandbox.stub(utils, "getParameterByName").callsFake(function () { - return "group1,group2"; - }); - }); - - it("read from url parameter", function () { - const bidRequest = deepClone(bidRequests[0]); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - logInfo(JSON.stringify(payload)); - - expect(payload.refgroups).to.exist; - expect(payload.refgroups).to.include.members(["group1", "group2"]); - }); - afterEach(function () { - sandbox.restore(); - }); - }); - - describe("buildRequests reads debug flag", function () { - beforeEach(function () { - sandbox.stub(utils, "getParameterByName").callsFake(function () { - return "true"; - }); - }); - - it("read from url parameter", function () { - const bidRequest = deepClone(bidRequests[0]); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - logInfo(JSON.stringify(payload)); - - expect(payload.debug).to.exist; - expect(payload.debug).to.equal(true); - }); - afterEach(function () { - sandbox.restore(); - }); - }); - - describe("buildRequests reads cw_id from Localstorage", function () { - before(function () { - sandbox.stub(storage, "localStorageIsEnabled").callsFake(() => true); - sandbox.stub(storage, "setDataInLocalStorage"); - sandbox - .stub(storage, "getDataFromLocalStorage") - .callsFake((key) => "taerfagerg"); - }); - - it("cw_id is set", function () { - const bidRequest = deepClone(bidRequests[0]); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - logInfo(JSON.stringify(payload)); - - expect(payload.cwid).to.exist; - expect(payload.cwid).to.equal("taerfagerg"); - }); - afterEach(function () { - sandbox.restore(); - }); - }); - - describe("buildRequests maps flattens params for legacy compat", function () { - beforeEach(function () { - const documentStub = sandbox.stub(document, "getElementById"); - documentStub.withArgs(`${bidRequests[0].adUnitCode}`).returns({ - getBoundingClientRect() { - return { width: 0, height: 0 }; - }, - }); - }); - it("pageId flattened", function () { - const bidRequest = deepClone(bidRequests[0]); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - logInfo(JSON.stringify(payload)); - - expect(payload.slots[0].pageId).to.exist; - }); - afterEach(function () { - sandbox.restore(); - }); - }); - - describe("pageId and placementId are required params", function () { - it("invalid request", function () { - const bidRequest = deepClone(bidRequests[0]); - delete bidRequest.params; - - const valid = spec.isBidRequestValid(bidRequest); - expect(valid).to.be.false; - }); - - it("valid request", function () { - const bidRequest = deepClone(bidRequests[0]); - bidRequest.params.pageId = 42; - bidRequest.params.placementId = 42; - - const valid = spec.isBidRequestValid(bidRequest); - expect(valid).to.be.true; - }); - - it("cwcreative must be of type string", function () { - const bidRequest = deepClone(bidRequests[0]); - bidRequest.params.pageId = 42; - bidRequest.params.placementId = 42; - - const valid = spec.isBidRequestValid(bidRequest); - expect(valid).to.be.true; - }); - - it("build request adds pageId", function () { - const bidRequest = deepClone(bidRequests[0]); - - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.slots[0].pageId).to.exist; - }); - }); - - describe("process serverResponse", function () { - it("html to ad mapping", function () { - const bidResponse = deepClone(response); - const bids = spec.interpretResponse(bidResponse, {}); - - expect(bids[0].ad).to.exist; - }); - }); - - describe("add user-syncs", function () { - it("empty user-syncs if no consent given", function () { - const userSyncs = spec.getUserSyncs({}, {}, {}, {}); - - expect(userSyncs).to.be.empty; - }); - it("empty user-syncs if no syncOption enabled", function () { - const gdprConsent = { - vendorData: { - purpose: { - consents: 1, - }, - }, - gdprApplies: false, - consentString: "testConsentString", - }; - const userSyncs = spec.getUserSyncs({}, {}, gdprConsent, {}); - - expect(userSyncs).to.be.empty; - }); - - it("user-syncs with enabled pixel option", function () { - const gdprConsent = { - vendorData: { - purpose: { - consents: 1, - }, - }, - gdprApplies: false, - consentString: "testConsentString", - }; - const synOptions = { pixelEnabled: true, iframeEnabled: true }; - const userSyncs = spec.getUserSyncs(synOptions, {}, gdprConsent, {}); - - expect(userSyncs[0].type).to.equal("image"); - expect(userSyncs[0].url).to.equal( - "https://ib.adnxs.com/getuid?https://prebid.cwi.re/v1/cookiesync?xandrId=$UID&gdpr=0&gdpr_consent=testConsentString" - ); - }); - - it("user-syncs with enabled iframe option", function () { - const gdprConsent = { - vendorData: { - purpose: { - consents: { - 1: true, - }, - }, - }, - gdprApplies: true, - consentString: "abc123", - }; - const synOptions = { iframeEnabled: true }; - const userSyncs = spec.getUserSyncs(synOptions, {}, gdprConsent, {}); - - expect(userSyncs[0].type).to.equal("iframe"); - expect(userSyncs[0].url).to.equal( - "https://ib.adnxs.com/getuid?https://prebid.cwi.re/v1/cookiesync?xandrId=$UID&gdpr=1&gdpr_consent=abc123" - ); - }); - }); - - describe("buildRequests includes autoplay", function () { - afterEach(function () { - sandbox.restore(); - }); - - it("should include autoplay: true when autoplay is enabled", function () { - sandbox.stub(autoplayLib, "isAutoplayEnabled").returns(true); - - const bidRequest = deepClone(bidRequests[0]); - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.slots[0].params.autoplay).to.equal(true); - }); - - it("should include autoplay: false when autoplay is disabled", function () { - sandbox.stub(autoplayLib, "isAutoplayEnabled").returns(false); - - const bidRequest = deepClone(bidRequests[0]); - const request = spec.buildRequests([bidRequest]); - const payload = JSON.parse(request.data); - - expect(payload.slots[0].params.autoplay).to.equal(false); - }); - }); - - describe("buildRequests with floor", function () { - it("should include floor in params when getFloor is defined", function () { - const bid = { - bidId: "123", - adUnitCode: "test-div", - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - params: { - pageId: 4057, - placementId: "abc123", - }, - getFloor: function ({ currency, mediaType, size }) { - expect(currency).to.equal("USD"); - expect(mediaType).to.equal("*"); - expect(size).to.equal("*"); - return { - currency: "USD", - floor: 1.23, - }; - }, - }; - - const bidderRequest = { - refererInfo: { - page: "https://example.com", - }, - }; - - const request = spec.buildRequests([bid], bidderRequest); - - const payload = JSON.parse(request.data); - const slot = payload.slots[0]; - - expect(slot.params).to.have.property("floor"); - expect(slot.params.floor).to.deep.equal({ - currency: "USD", - floor: 1.23, - }); - }); - - it("should not include floor in params if getFloor is not defined", function () { - const bid = { - bidId: "456", - adUnitCode: "test-div", - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - params: { - pageId: 4057, - placementId: "abc123", - }, - // no getFloor - }; - - const bidderRequest = { - refererInfo: { - page: "https://example.com", - }, - }; - - const request = spec.buildRequests([bid], bidderRequest); - const payload = JSON.parse(request.data); - const slot = payload.slots[0]; - - expect(slot.params.floor).to.deep.equal({}); - }); - }); -}); diff --git a/test/spec/modules/dailyhuntBidAdapter_spec.js b/test/spec/modules/dailyhuntBidAdapter_spec.js deleted file mode 100644 index e42621e7d..000000000 --- a/test/spec/modules/dailyhuntBidAdapter_spec.js +++ /dev/null @@ -1,403 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/dailyhuntBidAdapter.js'; - -const PROD_PREBID_ENDPOINT_URL = 'https://pbs.dailyhunt.in/openrtb2/auction?partner=dailyhunt'; -const PROD_PREBID_TEST_ENDPOINT_URL = 'https://qa-pbs-van.dailyhunt.in/openrtb2/auction?partner=dailyhunt'; - -const _encodeURIComponent = function (a) { - if (!a) { return } - let b = window.encodeURIComponent(a); - b = b.replace(/'/g, '%27'); - return b; -} - -describe('DailyhuntAdapter', function () { - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'dailyhunt', - 'params': { - placement_id: 1, - publisher_id: 1, - partner_name: 'dailyhunt' - } - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - describe('buildRequests', function() { - const bidRequests = [ - { - bidder: 'dailyhunt', - params: { - placement_id: 1, - publisher_id: 1, - partner_name: 'dailyhunt', - bidfloor: 0.1, - device: { - ip: '47.9.247.217' - }, - site: { - cat: ['1', '2', '3'] - } - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - adUnitCode: 'adunit-code', - sizes: [[300, 50]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '04f2659e-c005-4eb1-a57c-fa93145e3843' - } - ]; - const nativeBidRequests = [ - { - bidder: 'dailyhunt', - params: { - placement_id: 1, - publisher_id: 1, - partner_name: 'dailyhunt', - }, - nativeParams: { - title: { - required: true, - len: 80 - }, - image: { - required: true, - sizes: [150, 50] - }, - }, - mediaTypes: { - native: { - title: { - required: true - }, - } - }, - adUnitCode: 'adunit-code', - sizes: [[300, 250], [300, 50]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '04f2659e-c005-4eb1-a57c-fa93145e3843' - } - ]; - const videoBidRequests = [ - { - bidder: 'dailyhunt', - params: { - placement_id: 1, - publisher_id: 1, - partner_name: 'dailyhunt' - }, - nativeParams: { - video: { - context: 'instream' - } - }, - mediaTypes: { - video: { - context: 'instream' - } - }, - adUnitCode: 'adunit-code', - sizes: [[300, 250], [300, 50]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '04f2659e-c005-4eb1-a57c-fa93145e3843' - } - ]; - const bidderRequest = { - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'bidderCode': 'dailyhunt', - 'bids': [ - { - ...bidRequests[0] - } - ], - 'refererInfo': { - 'referer': 'http://m.dailyhunt.in/' - } - }; - const nativeBidderRequest = { - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'bidderCode': 'dailyhunt', - 'bids': [ - { - ...nativeBidRequests[0] - } - ], - 'refererInfo': { - 'referer': 'http://m.dailyhunt.in/' - } - }; - const videoBidderRequest = { - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'bidderCode': 'dailyhunt', - 'bids': [ - { - ...videoBidRequests[0] - } - ], - 'refererInfo': { - 'referer': 'http://m.dailyhunt.in/' - } - }; - - it('sends display bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.url).to.equal(PROD_PREBID_ENDPOINT_URL); - expect(request.method).to.equal('POST'); - }); - - it('sends native bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(nativeBidRequests, nativeBidderRequest)[0]; - expect(request.url).to.equal(PROD_PREBID_ENDPOINT_URL); - expect(request.method).to.equal('POST'); - }); - - it('sends video bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(videoBidRequests, videoBidderRequest)[0]; - expect(request.url).to.equal(PROD_PREBID_ENDPOINT_URL); - expect(request.method).to.equal('POST'); - }); - }); - describe('interpretResponse', function () { - const bidResponses = { - id: 'da32def7-6779-403c-ada7-0b201dbc9744', - seatbid: [ - { - bid: [ - { - id: 'id1', - impid: 'banner-impid', - price: 1.4, - adm: 'adm', - adid: '66658', - crid: 'asd5ddbf014cac993.66466212', - dealid: 'asd5ddbf014cac993.66466212', - w: 300, - h: 250, - nurl: 'winUrl', - ext: { - prebid: { - type: 'banner' - } - } - }, - { - id: '5caccc1f-94a6-4230-a1f9-6186ee65da99', - impid: 'video-impid', - price: 1.4, - nurl: 'winUrl', - adm: 'adm', - adid: '980', - crid: '2394', - w: 300, - h: 250, - ext: { - prebid: { - 'type': 'video' - }, - bidder: { - cacheKey: 'cache_key', - vastUrl: 'vastUrl' - } - } - }, - { - id: '74973faf-cce7-4eff-abd0-b59b8e91ca87', - impid: 'native-impid', - price: 50, - nurl: 'winUrl', - adm: '{"native":{"ver":"1.2","assets":[{"id":1,"required":1,"title":{"text":"Discover Amazing Products Today!"}},{"id":2,"required":1,"img":{"type":3,"url":"https://cdn.prod.website-files.com/64aabfa2adf7363205ea0135/67c168c650acb91b6ce4dfdf_%EC%8D%B8%EB%84%A4%EC%9D%BC_EN.webp","w":600,"h":315}},{"id":3,"data":{"label":"CTA","value":"Click Here To Visit Site","type":12}}],"link":{"url":"https://dailyhunt.in/news/india/english/for+you?launch=true&mode=pwa"},"imptrackers":["https://example.com/impression"]}}', - adid: '968', - crid: '2370', - w: 300, - h: 250, - ext: { - prebid: { - type: 'native' - }, - bidder: null - } - }, - { - id: '5caccc1f-94a6-4230-a1f9-6186ee65da99', - impid: 'video-outstream-impid', - price: 1.4, - nurl: 'winUrl', - adm: 'adm', - adid: '980', - crid: '2394', - w: 300, - h: 250, - ext: { - prebid: { - 'type': 'video' - }, - bidder: { - cacheKey: 'cache_key', - vastUrl: 'vastUrl' - } - } - }, - ], - seat: 'dailyhunt' - } - ], - ext: { - responsetimemillis: { - dailyhunt: 119 - } - } - }; - - it('should get correct bid response', function () { - const expectedResponse = [ - { - requestId: '1', - cpm: 1.4, - creativeId: 'asd5ddbf014cac993.66466212', - width: 300, - height: 250, - ttl: 360, - netRevenue: true, - currency: 'USD', - ad: 'adm', - mediaType: 'banner', - winUrl: 'winUrl', - adomain: 'dailyhunt' - }, - { - requestId: '2', - cpm: 1.4, - creativeId: '2394', - width: 300, - height: 250, - ttl: 360, - netRevenue: true, - currency: 'USD', - mediaType: 'video', - winUrl: 'winUrl', - adomain: 'dailyhunt', - videoCacheKey: 'cache_key', - vastUrl: 'vastUrl', - }, - { - requestId: '3', - cpm: 1.4, - creativeId: '2370', - width: 300, - height: 250, - ttl: 360, - netRevenue: true, - currency: 'USD', - mediaType: 'native', - winUrl: 'winUrl', - adomain: 'dailyhunt', - native: { - clickUrl: "https://dailyhunt.in/news/india/english/for+you?launch=true&mode=pwa", - clickTrackers: [], - impressionTrackers: ["https://example.com/impression"], - javascriptTrackers: [], - title: "Discover Amazing Products Today!", - cta: "Click Here To Visit Site", - image: { - height: 315, - url: "https://cdn.prod.website-files.com/64aabfa2adf7363205ea0135/67c168c650acb91b6ce4dfdf_%EC%8D%B8%EB%84%A4%EC%9D%BC_EN.webp", - width: 600, - }, - } - }, - { - requestId: '4', - cpm: 1.4, - creativeId: '2394', - width: 300, - height: 250, - ttl: 360, - netRevenue: true, - currency: 'USD', - mediaType: 'video', - winUrl: 'winUrl', - adomain: 'dailyhunt', - vastXml: 'adm', - }, - ]; - const bidderRequest = { - bids: [ - { - bidId: 'banner-impid', - adUnitCode: 'code1', - requestId: '1' - }, - { - bidId: 'video-impid', - adUnitCode: 'code2', - requestId: '2', - mediaTypes: { - video: { - context: 'instream' - } - } - }, - { - bidId: 'native-impid', - adUnitCode: 'code3', - requestId: '3' - }, - { - bidId: 'video-outstream-impid', - adUnitCode: 'code4', - requestId: '4', - mediaTypes: { - video: { - context: 'outstream' - } - } - }, - ] - } - const result = spec.interpretResponse({ body: bidResponses }, bidderRequest); - result.forEach((r, i) => { - expect(Object.keys(r)).to.have.members(Object.keys(expectedResponse[i])); - }); - }); - }) - describe('onBidWon', function () { - it('should hit win url when bid won', function () { - const bid = { - requestId: '1', - cpm: 1.4, - creativeId: 'asd5ddbf014cac993.66466212', - width: 300, - height: 250, - ttl: 360, - netRevenue: true, - currency: 'USD', - ad: 'adm', - mediaType: 'banner', - winUrl: 'winUrl' - }; - expect(spec.onBidWon(bid)).to.equal(undefined); - }); - }) -}) diff --git a/test/spec/modules/dailymotionBidAdapter_spec.js b/test/spec/modules/dailymotionBidAdapter_spec.js deleted file mode 100644 index d4cafe831..000000000 --- a/test/spec/modules/dailymotionBidAdapter_spec.js +++ /dev/null @@ -1,2404 +0,0 @@ -import { config } from 'src/config.js'; -import { expect } from 'chai'; -import { spec } from 'modules/dailymotionBidAdapter.js'; -import { BANNER, VIDEO } from '../../../src/mediaTypes.js'; - -describe('dailymotionBidAdapterTests', () => { - // Validate that isBidRequestValid only validates requests with apiKey - it('validates isBidRequestValid', () => { - expect(config.runWithBidder('dailymotion', () => spec.isBidRequestValid())).to.be.false; - - const bidWithEmptyApi = { - params: { - apiKey: '', - }, - mediaTypes: { - [VIDEO]: { - context: 'instream', - }, - }, - }; - - expect(config.runWithBidder('dailymotion', () => spec.isBidRequestValid(bidWithEmptyApi))).to.be.false; - - const bidWithApi = { - params: { - apiKey: 'test_api_key', - }, - mediaTypes: { - [VIDEO]: { - context: 'instream', - }, - }, - }; - - expect(config.runWithBidder('dailymotion', () => spec.isBidRequestValid(bidWithApi))).to.be.true; - - const bidWithEmptyMediaTypes = { - params: { - apiKey: '', - }, - }; - - expect(config.runWithBidder('dailymotion', () => spec.isBidRequestValid(bidWithEmptyMediaTypes))).to.be.false; - - const bidWithEmptyVideoAdUnit = { - params: { - apiKey: '', - }, - mediaTypes: { - [VIDEO]: {}, - }, - }; - - expect(config.runWithBidder('dailymotion', () => spec.isBidRequestValid(bidWithEmptyVideoAdUnit))).to.be.false; - - const bidWithBannerMediaType = { - params: { - apiKey: 'test_api_key', - }, - mediaTypes: { - [BANNER]: {}, - }, - }; - - expect(config.runWithBidder('dailymotion', () => spec.isBidRequestValid(bidWithBannerMediaType))).to.be.false; - - const bidWithOutstreamContext = { - params: { - apiKey: 'test_api_key', - }, - mediaTypes: { - video: { - context: 'outstream', - }, - }, - }; - - expect(config.runWithBidder('dailymotion', () => spec.isBidRequestValid(bidWithOutstreamContext))).to.be.false; - }); - - // Validate request generation - it('validates buildRequests', () => { - const bidRequestData = [{ - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - playbackmethod: [3], - plcmt: 1, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1, - skipafter: 5, - skipmin: 10, - startdelay: 0, - w: 1280, - h: 720, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - dmTs: '123456', - video: { - description: 'this is a test video', - duration: 556, - iabcat1: ['IAB-1'], - iabcat2: ['6', '17'], - id: '54321', - lang: 'FR', - private: false, - tags: 'tag_1,tag_2,tag_3', - title: 'test video', - url: 'https://test.com/test', - topics: 'topic_1, topic_2', - livestream: 1, - isCreatedForKids: true, - videoViewsInSession: 2, - autoplay: true, - playerName: 'dailymotion', - playerVolume: 8, - }, - }, - }]; - - const bidderRequestData = { - refererInfo: { - page: 'https://publisher.com', - }, - uspConsent: '1YN-', - gdprConsent: { - apiVersion: 2, - consentString: 'xxx', - gdprApplies: true, - }, - gppConsent: { - gppString: 'xxx', - applicableSections: [5], - }, - ortb2: { - regs: { - coppa: 1, - }, - site: { - content: { - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '200' }], - }, - ], - }, - }, - }, - }; - - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - all: { - bidders: '*', - filter: 'include' - } - } - } - }); - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - const { data: reqData } = request; - - expect(request.options.withCredentials).to.eql(false); - expect(request.url).to.equal('https://pb.dmxleo.com'); - - expect(reqData.pbv).to.eql('$prebid.version$'); - expect(reqData.userSyncEnabled).to.be.true; - expect(reqData.bidder_request).to.eql({ - refererInfo: bidderRequestData.refererInfo, - uspConsent: bidderRequestData.uspConsent, - gdprConsent: bidderRequestData.gdprConsent, - gppConsent: bidderRequestData.gppConsent, - }); - expect(reqData.config.api_key).to.eql(bidRequestData[0].params.apiKey); - expect(reqData.config.ts).to.eql(bidRequestData[0].params.dmTs); - expect(reqData.request.auctionId).to.eql(bidRequestData[0].auctionId); - expect(reqData.request.bidId).to.eql(bidRequestData[0].bidId); - expect(reqData.request.mediaTypes.video).to.eql(bidRequestData[0].mediaTypes.video); - expect(reqData.video_metadata).to.eql({ - description: bidRequestData[0].params.video.description, - iabcat1: ['IAB-1'], - iabcat2: bidRequestData[0].params.video.iabcat2, - id: bidRequestData[0].params.video.id, - lang: bidRequestData[0].params.video.lang, - private: bidRequestData[0].params.video.private, - tags: bidRequestData[0].params.video.tags, - title: bidRequestData[0].params.video.title, - url: bidRequestData[0].params.video.url, - topics: bidRequestData[0].params.video.topics, - duration: bidRequestData[0].params.video.duration, - livestream: !!bidRequestData[0].params.video.livestream, - isCreatedForKids: bidRequestData[0].params.video.isCreatedForKids, - context: { - siteOrAppCat: [], - siteOrAppContentCat: [], - videoViewsInSession: bidRequestData[0].params.video.videoViewsInSession, - autoplay: bidRequestData[0].params.video.autoplay, - playerName: bidRequestData[0].params.video.playerName, - playerVolume: bidRequestData[0].params.video.playerVolume, - }, - }); - }); - - it('validates buildRequests with global consent', () => { - const bidRequestData = [{ - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - playbackmethod: [3], - plcmt: 1, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1, - skipafter: 5, - skipmin: 10, - startdelay: 0, - w: 1280, - h: 720, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - video: { - description: 'this is a test video', - duration: 556, - iabcat1: ['IAB-1'], - iabcat2: ['6', '17'], - id: '54321', - lang: 'FR', - private: false, - tags: 'tag_1,tag_2,tag_3', - title: 'test video', - url: 'https://test.com/test', - topics: 'topic_1, topic_2', - livestream: 1, - isCreatedForKids: true, - videoViewsInSession: 2, - autoplay: true, - playerName: 'dailymotion', - playerVolume: 8, - }, - }, - }]; - - const bidderRequestData = { - refererInfo: { - page: 'https://publisher.com', - }, - uspConsent: '1YN-', - gdprConsent: { - apiVersion: 2, - consentString: 'xxx', - gdprApplies: true, - vendorData: { - hasGlobalConsent: true - } - }, - gppConsent: { - gppString: 'xxx', - applicableSections: [5], - }, - ortb2: { - regs: { - coppa: 1, - }, - site: { - content: { - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '200' }], - }, - ], - }, - }, - }, - }; - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - expect(request.options.withCredentials).to.eql(true); - }); - - it('validates buildRequests without gdpr applying', () => { - const bidRequestData = [{ - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - playbackmethod: [3], - plcmt: 1, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1, - skipafter: 5, - skipmin: 10, - startdelay: 0, - w: 1280, - h: 720, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - video: { - description: 'this is a test video', - duration: 556, - iabcat1: ['IAB-1'], - iabcat2: ['6', '17'], - id: '54321', - lang: 'FR', - private: false, - tags: 'tag_1,tag_2,tag_3', - title: 'test video', - url: 'https://test.com/test', - topics: 'topic_1, topic_2', - livestream: 1, - isCreatedForKids: true, - videoViewsInSession: 2, - autoplay: true, - playerName: 'dailymotion', - playerVolume: 8, - }, - }, - }]; - - const bidderRequestData = { - refererInfo: { - page: 'https://publisher.com', - }, - uspConsent: '1YN-', - gdprConsent: { - apiVersion: 2, - consentString: 'xxx', - gdprApplies: false, - }, - gppConsent: { - gppString: 'xxx', - applicableSections: [5], - }, - ortb2: { - regs: { - coppa: 1, - }, - site: { - content: { - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '200' }], - }, - ], - }, - }, - }, - }; - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - expect(request.options.withCredentials).to.eql(true); - }); - - it('validates buildRequests with detailed consent without legitimate interest', () => { - const bidRequestData = [{ - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - playbackmethod: [3], - plcmt: 1, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1, - skipafter: 5, - skipmin: 10, - startdelay: 0, - w: 1280, - h: 720, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - video: { - description: 'this is a test video', - duration: 556, - iabcat1: ['IAB-1'], - iabcat2: ['6', '17'], - id: '54321', - lang: 'FR', - private: false, - tags: 'tag_1,tag_2,tag_3', - title: 'test video', - url: 'https://test.com/test', - topics: 'topic_1, topic_2', - livestream: 1, - isCreatedForKids: true, - videoViewsInSession: 2, - autoplay: true, - playerName: 'dailymotion', - playerVolume: 8, - }, - }, - }]; - - const bidderRequestData = { - refererInfo: { - page: 'https://publisher.com', - }, - uspConsent: '1YN-', - gdprConsent: { - apiVersion: 2, - consentString: 'xxx', - gdprApplies: true, - vendorData: { - hasGlobalConsent: false, - purpose: { - consents: { - 1: true, - 2: true, - 3: true, - 4: true, - 7: true, - 9: true, - 10: true, - }, - }, - vendor: { - consents: { - 573: true - } - }, - }, - }, - gppConsent: { - gppString: 'xxx', - applicableSections: [5], - }, - ortb2: { - regs: { - coppa: 1, - }, - site: { - content: { - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '200' }], - }, - ], - }, - }, - }, - }; - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - expect(request.options.withCredentials).to.eql(false); - }); - - it('validates buildRequests with detailed consent, with legitimate interest', () => { - const bidRequestData = [{ - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - playbackmethod: [3], - plcmt: 1, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1, - skipafter: 5, - skipmin: 10, - startdelay: 0, - w: 1280, - h: 720, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - video: { - description: 'this is a test video', - duration: 556, - iabcat1: ['IAB-1'], - iabcat2: ['6', '17'], - id: '54321', - lang: 'FR', - private: false, - tags: 'tag_1,tag_2,tag_3', - title: 'test video', - url: 'https://test.com/test', - topics: 'topic_1, topic_2', - livestream: 1, - isCreatedForKids: true, - videoViewsInSession: 2, - autoplay: true, - playerName: 'dailymotion', - playerVolume: 8, - }, - }, - }]; - - const bidderRequestData = { - refererInfo: { - page: 'https://publisher.com', - }, - uspConsent: '1YN-', - gdprConsent: { - apiVersion: 2, - consentString: 'xxx', - gdprApplies: true, - vendorData: { - hasGlobalConsent: false, - purpose: { - consents: { - 1: true, - 3: true, - 4: true, - }, - legitimateInterests: { - 2: true, - 7: true, - 9: true, - 10: true, - }, - }, - vendor: { - consents: { - 573: true - } - }, - }, - }, - gppConsent: { - gppString: 'xxx', - applicableSections: [5], - }, - ortb2: { - regs: { - coppa: 1, - }, - site: { - content: { - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '200' }], - }, - ], - }, - }, - }, - }; - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - expect(request.options.withCredentials).to.eql(true); - }); - - it('validates buildRequests with detailed consent and legitimate interest but publisher forces consent', () => { - const bidRequestData = [{ - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - playbackmethod: [3], - plcmt: 1, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1, - skipafter: 5, - skipmin: 10, - startdelay: 0, - w: 1280, - h: 720, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - video: { - description: 'this is a test video', - duration: 556, - iabcat1: ['IAB-1'], - iabcat2: ['6', '17'], - id: '54321', - lang: 'FR', - private: false, - tags: 'tag_1,tag_2,tag_3', - title: 'test video', - url: 'https://test.com/test', - topics: 'topic_1, topic_2', - livestream: 1, - isCreatedForKids: true, - videoViewsInSession: 2, - autoplay: true, - playerName: 'dailymotion', - playerVolume: 8, - }, - }, - }]; - - const bidderRequestData = { - refererInfo: { - page: 'https://publisher.com', - }, - uspConsent: '1YN-', - gdprConsent: { - apiVersion: 2, - consentString: 'xxx', - gdprApplies: true, - vendorData: { - hasGlobalConsent: false, - publisher: { - restrictions: { - 2: { 573: 1 }, - 7: { 573: 1 }, - 9: { 573: 1 }, - 10: { 573: 1 }, - }, - }, - purpose: { - consents: { - 1: true, - 3: true, - 4: true, - }, - legitimateInterests: { - 2: true, - 7: true, - 9: true, - 10: true, - }, - }, - vendor: { - consents: { - 573: true - } - }, - }, - }, - gppConsent: { - gppString: 'xxx', - applicableSections: [5], - }, - ortb2: { - regs: { - coppa: 1, - }, - site: { - content: { - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '200' }], - }, - ], - }, - }, - }, - }; - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - expect(request.options.withCredentials).to.eql(false); - }); - - it('validates buildRequests with detailed consent, no legitimate interest and publisher forces consent', () => { - const bidRequestData = [{ - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - playbackmethod: [3], - plcmt: 1, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1, - skipafter: 5, - skipmin: 10, - startdelay: 0, - w: 1280, - h: 720, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - video: { - description: 'this is a test video', - duration: 556, - iabcat1: ['IAB-1'], - iabcat2: ['6', '17'], - id: '54321', - lang: 'FR', - private: false, - tags: 'tag_1,tag_2,tag_3', - title: 'test video', - url: 'https://test.com/test', - topics: 'topic_1, topic_2', - livestream: 1, - isCreatedForKids: true, - videoViewsInSession: 2, - autoplay: true, - playerName: 'dailymotion', - playerVolume: 8, - }, - }, - }]; - - const bidderRequestData = { - refererInfo: { - page: 'https://publisher.com', - }, - uspConsent: '1YN-', - gdprConsent: { - apiVersion: 2, - consentString: 'xxx', - gdprApplies: true, - vendorData: { - hasGlobalConsent: false, - publisher: { - restrictions: { - 2: { 573: 1 }, - 7: { 573: 1 }, - 9: { 573: 1 }, - 10: { 573: 1 }, - }, - }, - purpose: { - consents: { - 1: true, - 2: true, - 3: true, - 4: true, - 7: true, - 9: true, - 10: true, - }, - }, - vendor: { - consents: { - 573: true - } - }, - }, - }, - gppConsent: { - gppString: 'xxx', - applicableSections: [5], - }, - ortb2: { - regs: { - coppa: 1, - }, - site: { - content: { - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '200' }], - }, - ], - }, - }, - }, - }; - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - expect(request.options.withCredentials).to.eql(true); - }); - - it('validates buildRequests with detailed consent but publisher full restriction on purpose 1', () => { - const bidRequestData = [{ - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - playbackmethod: [3], - plcmt: 1, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1, - skipafter: 5, - skipmin: 10, - startdelay: 0, - w: 1280, - h: 720, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - video: { - description: 'this is a test video', - duration: 556, - iabcat1: ['IAB-1'], - iabcat2: ['6', '17'], - id: '54321', - lang: 'FR', - private: false, - tags: 'tag_1,tag_2,tag_3', - title: 'test video', - url: 'https://test.com/test', - topics: 'topic_1, topic_2', - xid: 'x123456', - livestream: 1, - isCreatedForKids: true, - videoViewsInSession: 2, - autoplay: true, - playerVolume: 8, - }, - }, - }]; - - const bidderRequestData = { - refererInfo: { - page: 'https://publisher.com', - }, - uspConsent: '1YN-', - gdprConsent: { - apiVersion: 2, - consentString: 'xxx', - gdprApplies: true, - vendorData: { - hasGlobalConsent: false, - publisher: { - restrictions: { - 1: { - 573: 0, - }, - }, - }, - purpose: { - consents: { - 1: true, - 2: true, - 3: true, - 4: true, - 7: true, - 9: true, - 10: true, - }, - }, - vendor: { - consents: { - 573: true - } - }, - }, - }, - gppConsent: { - gppString: 'xxx', - applicableSections: [5], - }, - ortb2: { - regs: { - coppa: 1, - }, - site: { - content: { - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '200' }], - }, - ], - }, - }, - }, - }; - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - expect(request.options.withCredentials).to.eql(false); - }); - - it('validates buildRequests with detailed consent but publisher restriction 2 on consent purpose 1', () => { - const bidRequestData = [{ - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - playbackmethod: [3], - plcmt: 1, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1, - skipafter: 5, - skipmin: 10, - startdelay: 0, - w: 1280, - h: 720, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - video: { - description: 'this is a test video', - duration: 556, - iabcat1: ['IAB-1'], - iabcat2: ['6', '17'], - id: '54321', - lang: 'FR', - private: false, - tags: 'tag_1,tag_2,tag_3', - title: 'test video', - url: 'https://test.com/test', - topics: 'topic_1, topic_2', - xid: 'x123456', - livestream: 1, - isCreatedForKids: true, - videoViewsInSession: 2, - autoplay: true, - playerVolume: 8, - }, - }, - }]; - - const bidderRequestData = { - refererInfo: { - page: 'https://publisher.com', - }, - uspConsent: '1YN-', - gdprConsent: { - apiVersion: 2, - consentString: 'xxx', - gdprApplies: true, - vendorData: { - hasGlobalConsent: false, - publisher: { - restrictions: { - 1: { - 573: 2, - }, - }, - }, - purpose: { - consents: { - 1: true, - 3: true, - 4: true, - }, - legitimateInterests: { - 2: true, - 7: true, - 9: true, - 10: true, - }, - }, - vendor: { - consents: { - 573: true - } - }, - }, - }, - gppConsent: { - gppString: 'xxx', - applicableSections: [5], - }, - ortb2: { - regs: { - coppa: 1, - }, - site: { - content: { - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '200' }], - }, - ], - }, - }, - }, - }; - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - expect(request.options.withCredentials).to.eql(false); - }); - - it('validates buildRequests with detailed consent, legitimate interest and publisher restriction on purpose 1', () => { - const bidRequestData = [{ - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - playbackmethod: [3], - plcmt: 1, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1, - skipafter: 5, - skipmin: 10, - startdelay: 0, - w: 1280, - h: 720, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - video: { - description: 'this is a test video', - duration: 556, - iabcat1: ['IAB-1'], - iabcat2: ['6', '17'], - id: '54321', - lang: 'FR', - private: false, - tags: 'tag_1,tag_2,tag_3', - title: 'test video', - url: 'https://test.com/test', - topics: 'topic_1, topic_2', - xid: 'x123456', - livestream: 1, - isCreatedForKids: true, - videoViewsInSession: 2, - autoplay: true, - playerVolume: 8, - }, - }, - }]; - - const bidderRequestData = { - refererInfo: { - page: 'https://publisher.com', - }, - uspConsent: '1YN-', - gdprConsent: { - apiVersion: 2, - consentString: 'xxx', - gdprApplies: true, - vendorData: { - hasGlobalConsent: false, - publisher: { - restrictions: { - 1: { - 573: 1, - }, - }, - }, - purpose: { - consents: { - 1: true, - 3: true, - 4: true, - }, - legitimateInterests: { - 2: true, - 7: true, - 9: true, - 10: true, - }, - }, - vendor: { - consents: { - 573: true - } - }, - }, - }, - gppConsent: { - gppString: 'xxx', - applicableSections: [5], - }, - ortb2: { - regs: { - coppa: 1, - }, - site: { - content: { - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '200' }], - }, - ], - }, - }, - }, - }; - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - expect(request.options.withCredentials).to.eql(true); - }); - - it('validates buildRequests with detailed consent and legitimate interest but publisher restriction on legitimate interest 2', () => { - const bidRequestData = [{ - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - playbackmethod: [3], - plcmt: 1, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1, - skipafter: 5, - skipmin: 10, - startdelay: 0, - w: 1280, - h: 720, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - video: { - description: 'this is a test video', - duration: 556, - iabcat1: ['IAB-1'], - iabcat2: ['6', '17'], - id: '54321', - lang: 'FR', - private: false, - tags: 'tag_1,tag_2,tag_3', - title: 'test video', - url: 'https://test.com/test', - topics: 'topic_1, topic_2', - xid: 'x123456', - livestream: 1, - isCreatedForKids: true, - videoViewsInSession: 2, - autoplay: true, - playerVolume: 8, - }, - }, - }]; - - const bidderRequestData = { - refererInfo: { - page: 'https://publisher.com', - }, - uspConsent: '1YN-', - gdprConsent: { - apiVersion: 2, - consentString: 'xxx', - gdprApplies: true, - vendorData: { - hasGlobalConsent: false, - publisher: { - restrictions: { - 2: { - 573: 2, - }, - }, - }, - purpose: { - consents: { - 1: true, - 3: true, - 4: true, - }, - legitimateInterests: { - 2: true, - 7: true, - 9: true, - 10: true, - }, - }, - vendor: { - consents: { - 573: true - } - }, - }, - }, - gppConsent: { - gppString: 'xxx', - applicableSections: [5], - }, - ortb2: { - regs: { - coppa: 1, - }, - site: { - content: { - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '200' }], - }, - ], - }, - }, - }, - }; - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - expect(request.options.withCredentials).to.eql(true); - }); - - it('validates buildRequests with insufficient consent', () => { - const bidRequestData = [{ - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - playbackmethod: [3], - plcmt: 1, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1, - skipafter: 5, - skipmin: 10, - startdelay: 0, - w: 1280, - h: 720, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - video: { - description: 'this is a test video', - duration: 556, - iabcat1: ['IAB-1'], - iabcat2: ['6', '17'], - id: '54321', - lang: 'FR', - private: false, - tags: 'tag_1,tag_2,tag_3', - title: 'test video', - url: 'https://test.com/test', - topics: 'topic_1, topic_2', - livestream: 1, - isCreatedForKids: true, - videoViewsInSession: 2, - autoplay: true, - playerName: 'dailymotion', - playerVolume: 8, - }, - }, - }]; - - const bidderRequestData = { - refererInfo: { - page: 'https://publisher.com', - }, - uspConsent: '1YN-', - gdprConsent: { - apiVersion: 2, - consentString: 'xxx', - gdprApplies: true, - vendorData: { - hasGlobalConsent: false, - purpose: { - consents: { - 1: true, - 3: true, - 4: true, - }, - }, - vendor: { - consents: { - 573: true - } - }, - }, - }, - gppConsent: { - gppString: 'xxx', - applicableSections: [5], - }, - ortb2: { - regs: { - coppa: 1, - }, - site: { - content: { - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '200' }], - }, - ], - }, - }, - }, - }; - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - expect(request.options.withCredentials).to.eql(false); - }); - - it('validates buildRequests with content values from App', () => { - const bidRequestData = [{ - getFloor: () => ({ currency: 'USD', floor: 3 }), - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - playbackmethod: [3], - plcmt: 1, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1, - skipafter: 5, - skipmin: 10, - startdelay: 0, - w: 1280, - h: 720, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - video: { - description: 'this is a test video', - iabcat2: ['6', '17'], - id: '54321', - lang: 'FR', - private: false, - tags: 'tag_1,tag_2,tag_3', - title: 'test video', - url: 'https://test.com/test', - topics: 'topic_1, topic_2', - livestream: 1, - // Test invalid values - isCreatedForKids: 'false', - videoViewsInSession: -1, - autoplay: 'true', - playerName: 'dailymotion', - playerVolume: 12, - }, - }, - }]; - - const bidderRequestData = { - timeout: 4242, - refererInfo: { - page: 'https://publisher.com', - }, - uspConsent: '1YN-', - gdprConsent: { - apiVersion: 2, - consentString: 'xxx', - gdprApplies: true, - }, - gppConsent: { - gppString: 'xxx', - applicableSections: [5], - }, - ortb2: { - bcat: ['IAB-1'], - badv: ['bcav-1'], - regs: { - coppa: 1, - }, - device: { - lmt: 1, - ifa: 'xxx', - devicetype: 2, - make: 'make', - model: 'model', - os: 'os', - osv: 'osv', - language: 'language', - geo: { - country: 'country', - region: 'region', - city: 'city', - zip: 'zip', - metro: 'metro' - }, - ext: { - atts: 2, - ifa_type: 'ifa_type' - }, - }, - app: { - bundle: 'app-bundle', - storeurl: 'https://play.google.com/store/apps/details?id=app-bundle', - content: { - len: 556, - cattax: 3, - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 4 }, - segment: [{ id: 'IAB-1' }], - }, - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '200' }], - }, - ], - }, - }, - }, - }; - - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - iframe: { - bidders: ['dailymotion'], - filter: 'include' - } - } - } - }); - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - const { data: reqData } = request; - - expect(request.url).to.equal('https://pb.dmxleo.com'); - - expect(reqData.pbv).to.eql('$prebid.version$'); - - const expectedOrtb = { - 'app': { - 'bundle': 'app-bundle', - 'content': { - 'cattax': 3, - 'data': [ - { - 'ext': { - 'segtax': 4 - }, - 'name': 'dataprovider.com', - 'segment': [ - { - 'id': 'IAB-1' - } - ] - }, - { - 'ext': { - 'segtax': 5 - }, - 'name': 'dataprovider.com', - 'segment': [ - { - 'id': '200' - } - ], - } - ], - 'len': 556, - }, - 'storeurl': 'https://play.google.com/store/apps/details?id=app-bundle', - }, - 'badv': [ - 'bcav-1' - ], - 'bcat': [ - 'IAB-1' - ], - 'device': { - 'devicetype': 2, - 'ext': { - 'atts': 2, - 'ifa_type': 'ifa_type' - }, - 'geo': { - 'city': 'city', - 'country': 'country', - 'metro': 'metro', - 'region': 'region', - 'zip': 'zip', - }, - 'ifa': 'xxx', - 'language': 'language', - 'lmt': 1, - 'make': 'make', - 'model': 'model', - 'os': 'os', - 'osv': 'osv', - }, - 'imp': [{ - 'bidfloor': 3, - 'bidfloorcur': 'USD', - 'id': 123456, - 'secure': 1, - ...(FEATURES.VIDEO ? { - 'video': { - 'api': [ - 2, - 7 - ], - 'h': 720, - 'maxduration': 30, - 'mimes': [ - 'video/mp4' - ], - 'minduration': 5, - 'playbackmethod': [ - 3 - ], - 'plcmt': 1, - 'protocols': [ - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8 - ], - 'skip': 1, - 'skipafter': 5, - 'skipmin': 10, - 'startdelay': 0, - 'w': 1280, - } - } : {}), - } - ], - 'regs': { - 'coppa': 1, - }, - 'test': 0, - 'tmax': 4242, - } - - expect(reqData.ortb.id).to.be.not.empty; - delete reqData.ortb.id; // ortb id is generated randomly - expect(reqData.ortb).to.eql(expectedOrtb); - expect(reqData.userSyncEnabled).to.be.true; - expect(reqData.bidder_request).to.eql({ - refererInfo: bidderRequestData.refererInfo, - uspConsent: bidderRequestData.uspConsent, - gdprConsent: bidderRequestData.gdprConsent, - gppConsent: bidderRequestData.gppConsent, - }); - expect(reqData.config.api_key).to.eql(bidRequestData[0].params.apiKey); - expect(reqData.request.auctionId).to.eql(bidRequestData[0].auctionId); - expect(reqData.request.bidId).to.eql(bidRequestData[0].bidId); - - expect(reqData.request.mediaTypes.video).to.eql(bidRequestData[0].mediaTypes.video); - - expect(reqData.video_metadata).to.eql({ - description: bidRequestData[0].params.video.description, - iabcat1: ['IAB-1'], - iabcat2: bidRequestData[0].params.video.iabcat2, - id: bidRequestData[0].params.video.id, - lang: bidRequestData[0].params.video.lang, - private: bidRequestData[0].params.video.private, - tags: bidRequestData[0].params.video.tags, - title: bidRequestData[0].params.video.title, - url: bidRequestData[0].params.video.url, - topics: bidRequestData[0].params.video.topics, - // Overriden through bidder params - duration: bidderRequestData.ortb2.app.content.len, - livestream: !!bidRequestData[0].params.video.livestream, - isCreatedForKids: null, - context: { - siteOrAppCat: [], - siteOrAppContentCat: [], - videoViewsInSession: null, - autoplay: null, - playerName: 'dailymotion', - playerVolume: null, - }, - }); - }); - - it('validates buildRequests with fallback values on ortb2 (gpp, iabcat2, id...)', () => { - const bidRequestData = [{ - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - startdelay: 0, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - video: { - description: 'this is a test video', - duration: 556, - private: false, - title: 'test video', - topics: 'topic_1, topic_2', - isCreatedForKids: false, - videoViewsInSession: 10, - autoplay: false, - playerName: 'dailymotion', - playerVolume: 0, - }, - }, - }]; - - const bidderRequestData = { - refererInfo: { - page: 'https://publisher.com', - }, - uspConsent: '1YN-', - gdprConsent: { - apiVersion: 2, - consentString: 'xxx', - gdprApplies: true, - }, - ortb2: { - tmax: 31416, - regs: { - gpp: 'xxx', - gpp_sid: [5], - coppa: 0, - }, - site: { - cat: ['IAB-1'], - content: { - id: '54321', - language: 'FR', - keywords: 'tag_1,tag_2,tag_3', - title: 'test video', - url: 'https://test.com/test', - livestream: 1, - cat: ['IAB-2'], - cattax: 1, - data: [ - undefined, // Undefined to check proper handling of edge cases - {}, // Empty object to check proper handling of edge cases - { ext: {} }, // Empty ext to check proper handling of edge cases - { - name: 'dataprovider.com', - ext: { segtax: 22 }, // Invalid segtax to check proper handling of edge cases - segment: [{ id: '400' }], - }, - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: undefined, // Invalid segment to check proper handling of edge cases - }, - { - name: 'dataprovider.com', - ext: { segtax: 4 }, - segment: undefined, // Invalid segment to check proper handling of edge cases - }, - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: 2222 }], // Invalid segment id to check proper handling of edge cases - }, - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '6' }], - }, - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '6' }], // Check that same cat won't be duplicated - }, - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '17' }, { id: '20' }], - }, - ], - }, - }, - }, - }; - - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - image: { - bidders: ['dailymotion'], - filter: 'include' - }, - iframe: { - bidders: ['dailymotion'], - filter: 'exclude', - }, - } - } - }); - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - const { data: reqData } = request; - - expect(request.url).to.equal('https://pb.dmxleo.com'); - - const expectedOrtb = { - 'imp': [{ - 'id': 123456, - 'secure': 1, - ...(FEATURES.VIDEO ? { - 'video': { - 'api': [ - 2, - 7 - ], - 'startdelay': 0, - } - } : {}) - } - ], - 'regs': { - 'coppa': 0, - 'gpp': 'xxx', - 'gpp_sid': [ - 5 - ], - }, - 'site': { - 'cat': [ - 'IAB-1', - ], - 'content': { - 'cat': [ - 'IAB-2', - ], - 'cattax': 1, - 'data': [ - undefined, - {}, - { - 'ext': {} - }, - { - 'ext': { - 'segtax': 22 - }, - 'name': 'dataprovider.com', - 'segment': [ - { - 'id': '400' - } - ] - }, - { - 'ext': { - 'segtax': 5 - }, - 'name': 'dataprovider.com', - 'segment': undefined - }, - { - 'ext': { - 'segtax': 4 - }, - 'name': 'dataprovider.com', - 'segment': undefined - }, - { - 'ext': { - 'segtax': 5 - }, - 'name': 'dataprovider.com', - 'segment': [ - { - 'id': 2222 - } - ] - }, - { - 'ext': { - 'segtax': 5 - }, - 'name': 'dataprovider.com', - 'segment': [ - { - 'id': '6' - } - ] - }, - { - 'ext': { - 'segtax': 5 - }, - 'name': 'dataprovider.com', - 'segment': [ - { - 'id': '6' - } - ] - }, - { - 'ext': { - 'segtax': 5 - }, - 'name': 'dataprovider.com', - 'segment': [ - { - 'id': '17' - }, - { - 'id': '20' - } - ] - } - ], - 'id': '54321', - 'keywords': 'tag_1,tag_2,tag_3', - 'language': 'FR', - 'livestream': 1, - 'title': 'test video', - 'url': 'https://test.com/test', - } - }, - 'test': 0, - 'tmax': 31416 - } - - expect(reqData.pbv).to.eql('$prebid.version$'); - expect(reqData.ortb.id).to.be.not.empty; - delete reqData.ortb.id; // ortb id is generated randomly - expect(reqData.ortb).to.eql(expectedOrtb); - - expect(reqData.userSyncEnabled).to.be.true; - expect(reqData.bidder_request).to.eql({ - refererInfo: bidderRequestData.refererInfo, - uspConsent: bidderRequestData.uspConsent, - gdprConsent: bidderRequestData.gdprConsent, - gppConsent: { - gppString: bidderRequestData.ortb2.regs.gpp, - applicableSections: bidderRequestData.ortb2.regs.gpp_sid, - }, - }); - expect(reqData.config.api_key).to.eql(bidRequestData[0].params.apiKey); - expect(reqData.request.auctionId).to.eql(bidRequestData[0].auctionId); - expect(reqData.request.bidId).to.eql(bidRequestData[0].bidId); - - expect(reqData.request.mediaTypes.video).to.eql({ - ...bidRequestData[0].mediaTypes.video, - mimes: [], - minduration: 0, - maxduration: 0, - playbackmethod: [], - plcmt: undefined, - protocols: [], - skip: 0, - skipafter: 0, - skipmin: 0, - w: 0, - h: 0, - }); - - expect(reqData.video_metadata).to.eql({ - description: bidRequestData[0].params.video.description, - iabcat1: ['IAB-2'], - iabcat2: ['6', '17', '20'], - id: bidderRequestData.ortb2.site.content.id, - lang: bidderRequestData.ortb2.site.content.language, - private: bidRequestData[0].params.video.private, - tags: bidderRequestData.ortb2.site.content.keywords, - title: bidderRequestData.ortb2.site.content.title, - url: bidderRequestData.ortb2.site.content.url, - topics: bidRequestData[0].params.video.topics, - duration: bidRequestData[0].params.video.duration, - livestream: !!bidderRequestData.ortb2.site.content.livestream, - isCreatedForKids: bidRequestData[0].params.video.isCreatedForKids, - context: { - siteOrAppCat: bidderRequestData.ortb2.site.cat, - siteOrAppContentCat: bidderRequestData.ortb2.site.content.cat, - videoViewsInSession: bidRequestData[0].params.video.videoViewsInSession, - autoplay: bidRequestData[0].params.video.autoplay, - playerName: bidRequestData[0].params.video.playerName, - playerVolume: bidRequestData[0].params.video.playerVolume, - }, - }); - }); - - it('validates buildRequests - with default values on empty bid & bidder request', () => { - const bidRequestDataWithApi = [{ - params: { - apiKey: 'test_api_key', - }, - }]; - - config.setConfig({ - userSync: { - syncEnabled: false, - } - }); - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestDataWithApi, {}), - ); - - const { data: reqData } = request; - - expect(request.url).to.equal('https://pb.dmxleo.com'); - expect(reqData.config.api_key).to.eql(bidRequestDataWithApi[0].params.apiKey); - expect(reqData.pbv).to.eql('$prebid.version$'); - - expect(reqData.ortb.id).to.be.not.empty; - delete reqData.ortb.id; // ortb id is generated randomly - expect(reqData.ortb).to.eql({ - 'imp': [ - { - 'id': undefined, - 'secure': 1 - }, - ], - 'test': 0 - }); - expect(reqData.userSyncEnabled).to.be.false; - expect(reqData.bidder_request).to.eql({ - gdprConsent: { - apiVersion: 1, - consentString: '', - gdprApplies: false, - }, - refererInfo: { - page: '', - }, - uspConsent: '', - gppConsent: { - gppString: '', - applicableSections: [], - }, - }); - - expect(reqData.request).to.eql({ - auctionId: '', - bidId: '', - adUnitCode: '', - mediaTypes: { - video: { - api: [], - mimes: [], - minduration: 0, - maxduration: 0, - playbackmethod: [], - plcmt: undefined, - protocols: [], - skip: 0, - skipafter: 0, - skipmin: 0, - startdelay: undefined, - w: 0, - h: 0, - }, - }, - sizes: [], - }); - - expect(reqData.video_metadata).to.eql({ - description: '', - duration: 0, - iabcat1: [], - iabcat2: [], - id: '', - lang: '', - private: false, - tags: '', - title: '', - url: '', - topics: '', - livestream: false, - isCreatedForKids: null, - context: { - siteOrAppCat: [], - siteOrAppContentCat: [], - videoViewsInSession: null, - autoplay: null, - playerName: '', - playerVolume: null, - }, - }); - }); - - describe('validates buildRequests for video metadata iabcat1 and iabcat2', () => { - let bidRequestData; - let bidderRequestData; - let request; - - beforeEach(() => { - bidRequestData = [{ - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: 123456, - adUnitCode: 'preroll', - mediaTypes: { - video: { - api: [2, 7], - startdelay: 0, - }, - }, - sizes: [[1920, 1080]], - params: { - apiKey: 'test_api_key', - video: { - iabcat1: ['video-params-iabcat1'], - iabcat2: ['video-params-iabcat2'], - }, - }, - }]; - - bidderRequestData = { - timeout: 4242, - refererInfo: { - page: 'https://publisher.com', - }, - ortb2: { - site: { - content: { - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 4 }, - segment: [{ id: '1' }], - }, - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '6' }], - }, - { - name: 'dataprovider.com', - ext: { segtax: 5 }, - segment: [{ id: '17' }, { id: '20' }], - }, - ] - }, - } - } - }; - - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - image: { - bidders: ['dailymotion'], - filter: 'include' - }, - iframe: { - bidders: ['dailymotion'], - filter: 'exclude', - }, - }, - }, - }); - - [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - }); - - it('get iabcat1 and iabcat 2 from params video', () => { - expect(request.data.video_metadata.iabcat1).to.eql(bidRequestData[0].params.video.iabcat1); - expect(request.data.video_metadata.iabcat2).to.eql(bidRequestData[0].params.video.iabcat2); - }) - - it('get iabcat1 from content.cat and iabcat2 from data.segment', () => { - const iabCatTestsCases = [[], null, {}]; - - iabCatTestsCases.forEach((iabCat) => { - bidRequestData[0].params.video.iabcat1 = iabCat; - bidRequestData[0].params.video.iabcat2 = iabCat; - bidderRequestData.ortb2.site.content.cat = ['video-content-cat']; - bidderRequestData.ortb2.site.content.cattax = 1; - - [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - expect(request.data.video_metadata.iabcat1).to.eql(bidderRequestData.ortb2.site.content.cat); - expect(request.data.video_metadata.iabcat2).to.eql(['6', '17', '20']); - }) - }) - - it('get iabcat2 from content.cat and iabcat1 from data.segment', () => { - const iabCatTestsCases = [[], null, {}]; - const cattaxV2 = [2, 5, 6]; - - cattaxV2.forEach((cattax) => { - iabCatTestsCases.forEach((iabCat) => { - bidRequestData[0].params.video.iabcat1 = iabCat; - bidRequestData[0].params.video.iabcat2 = iabCat; - bidderRequestData.ortb2.site.content.cat = ['video-content-cat']; - bidderRequestData.ortb2.site.content.cattax = cattax; - - [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - expect(request.data.video_metadata.iabcat1).to.eql(['1']); - expect(request.data.video_metadata.iabcat2).to.eql(bidderRequestData.ortb2.site.content.cat); - }) - }) - }) - - it('get iabcat1 and iabcat2 from data.segmnet', () => { - const contentCatTestCases = [[], null, {}]; - const cattaxTestCases = [1, 2, 5, 6]; - - cattaxTestCases.forEach((cattax) => { - contentCatTestCases.forEach((contentCat) => { - bidRequestData[0].params.video.iabcat1 = []; - bidRequestData[0].params.video.iabcat2 = []; - bidderRequestData.ortb2.site.content.cat = contentCat; - bidderRequestData.ortb2.site.content.cattax = cattax; - - [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequestData, bidderRequestData), - ); - - expect(request.data.video_metadata.iabcat1).to.eql(['1']); - expect(request.data.video_metadata.iabcat2).to.eql(['6', '17', '20']); - }) - }) - }) - }); - - it('validates buildRequests - with null floor as object for getFloor function', () => { - const bidRequest = [{ - params: { - apiKey: 'test_api_key', - }, - getFloor: () => null - }]; - - config.setConfig({ - userSync: { - syncEnabled: false, - } - }); - - const [request] = config.runWithBidder( - 'dailymotion', - () => spec.buildRequests(bidRequest, {}), - ); - - const { data: reqData } = request; - - expect(reqData.ortb.id).to.be.not.empty; - delete reqData.ortb.id; // ortb id is generated randomly - expect(reqData.ortb).to.eql({ - 'imp': [ - { - 'id': undefined, - 'secure': 1 - }, - ], - 'test': 0 - }); - }) - - it('validates buildRequests - with empty/undefined validBidRequests', () => { - expect(spec.buildRequests([], {})).to.have.lengthOf(0); - - expect(spec.buildRequests(undefined, {})).to.have.lengthOf(0); - }); - - it('validates interpretResponse', () => { - const serverResponse = { - body: { - ad: 'https://fakecacheserver/cache?uuid=1234', - cacheId: '1234', - cpm: 20.0, - creativeId: '5678', - currency: 'USD', - dealId: 'deal123', - nurl: 'https://bid/nurl', - requestId: 'test_requestid', - vastUrl: 'https://fakecacheserver/cache?uuid=1234', - }, - }; - - const bids = spec.interpretResponse(serverResponse); - expect(bids).to.have.lengthOf(1); - - const [bid] = bids; - expect(bid).to.eql(serverResponse.body); - }); - - it('validates interpretResponse - without bid (no cpm)', () => { - const serverResponse = { - body: { - requestId: 'test_requestid', - }, - }; - - const bids = spec.interpretResponse(serverResponse); - expect(bids).to.have.lengthOf(0); - }); - - it('validates interpretResponse - with empty/undefined serverResponse', () => { - expect(spec.interpretResponse({})).to.have.lengthOf(0); - - expect(spec.interpretResponse(undefined)).to.have.lengthOf(0); - }); - - it('validates getUserSyncs', () => { - // Nothing sent in getUserSyncs - expect(config.runWithBidder('dailymotion', () => spec.getUserSyncs())).to.eql([]); - - // No server response - { - const responses = []; - const syncOptions = { iframeEnabled: true, pixelEnabled: true }; - - expect(config.runWithBidder( - 'dailymotion', - () => spec.getUserSyncs(syncOptions, responses), - )).to.eql([]); - } - - // No permissions - { - const responses = [{ body: { userSyncs: [{ url: 'https://usersyncurl.com', type: 'image' }] } }]; - const syncOptions = { iframeEnabled: false, pixelEnabled: false }; - - expect(config.runWithBidder( - 'dailymotion', - () => spec.getUserSyncs(syncOptions, responses), - )).to.eql([]); - } - - // Has permissions but no userSyncs urls - { - const responses = [{}]; - const syncOptions = { iframeEnabled: false, pixelEnabled: true }; - - expect(config.runWithBidder( - 'dailymotion', - () => spec.getUserSyncs(syncOptions, responses), - )).to.eql([]); - } - - // Return userSyncs urls for pixels - { - const responses = [{ - body: { - userSyncs: [ - { url: 'https://usersyncurl.com', type: 'image' }, - { url: 'https://usersyncurl2.com', type: 'image' }, - { url: 'https://usersyncurl3.com', type: 'iframe' } - ], - } - }]; - - const syncOptions = { iframeEnabled: false, pixelEnabled: true }; - - expect(config.runWithBidder( - 'dailymotion', - () => spec.getUserSyncs(syncOptions, responses), - )).to.eql([ - { type: 'image', url: 'https://usersyncurl.com' }, - { type: 'image', url: 'https://usersyncurl2.com' }, - ]); - } - - // Return userSyncs urls for iframes - { - const responses = [{ - body: { - userSyncs: [ - { url: 'https://usersyncurl.com', type: 'image' }, - { url: 'https://usersyncurl2.com', type: 'image' }, - { url: 'https://usersyncurl3.com', type: 'iframe' } - ], - } - }]; - - const syncOptions = { iframeEnabled: true, pixelEnabled: true }; - - expect(config.runWithBidder( - 'dailymotion', - () => spec.getUserSyncs(syncOptions, responses), - )).to.eql([ - { type: 'iframe', url: 'https://usersyncurl3.com' }, - ]); - } - }); -}); diff --git a/test/spec/modules/datablocksBidAdapter_spec.js b/test/spec/modules/datablocksBidAdapter_spec.js deleted file mode 100644 index 9e2b311e5..000000000 --- a/test/spec/modules/datablocksBidAdapter_spec.js +++ /dev/null @@ -1,533 +0,0 @@ -import { expect } from 'chai'; -import { spec, BotClientTests } from '../../../modules/datablocksBidAdapter.js'; - -import { getStorageManager } from '../../../src/storageManager.js'; -import {deepClone} from '../../../src/utils.js'; - -const bid = { - bidId: '2dd581a2b6281d', - bidder: 'datablocks', - bidderRequestId: '145e1d6a7837c9', - params: { - source_id: 7560, - host: 'v5demo.datablocks.net' - }, - adUnitCode: '/19968336/header-bid-tag-0', - auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - sizes: [ - [300, 250] - ], - transactionId: '1ccbee15-f6f6-46ce-8998-58fe5542e8e1' -}; - -const bid2 = { - bidId: '2dd581a2b624324g', - bidder: 'datablocks', - bidderRequestId: '145e1d6a7837543', - params: { - source_id: 7560, - host: 'v5demo.datablocks.net' - }, - adUnitCode: '/19968336/header-bid-tag-0', - auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', - mediaTypes: { - banner: { - sizes: - [728, 90] - } - }, - transactionId: '1ccbee15-f6f6-46ce-8998-58fe55425432' -}; - -const nativeBid = { - adUnitCode: '/19968336/header-bid-tag-0', - auctionId: '160c78a4-f808-410f-b682-d8728f3a79ee', - bidId: '332045ee374a99', - bidder: 'datablocks', - bidderRequestId: '15d9012765e36c', - mediaTypes: { - native: { - title: { - required: true - }, - body: { - required: true - }, - image: { - required: true - } - } - }, - nativeParams: { - title: { - required: true - }, - body: { - required: true, - data: { - len: 250 - } - }, - image: { - required: true, - sizes: [728, 90] - } - }, - params: { - source_id: 7560, - host: 'v5demo.datablocks.net' - }, - transactionId: '0a4e9788-4def-4b94-bc25-564d7cac99f6' -} - -const bidderRequest = { - auctionId: '8bfef1be-d3ac-4d18-8859-754c7b4cf017', - auctionStart: Date.now(), - biddeCode: 'datablocks', - bidderRequestId: '10c47a5fc3c41', - bids: [bid, bid2, nativeBid], - refererInfo: { - numIframes: 0, - reachedTop: true, - referer: 'https://7560.v5demo.datablocks.net/test', - stack: ['https://7560.v5demo.datablocks.net/test'] - }, - start: Date.now(), - timeout: 10000 -}; - -const res_object = { - body: { - 'id': '10c47a5fc3c41', - 'bidid': '217868445-30021-19053-0', - 'seatbid': [ - { - 'id': '22621593137287', - 'impid': '1', - 'adm': 'John is great', - 'adomain': ['medianet.com'], - 'price': 0.430000, - 'cid': '2524568', - 'adid': '0', - 'crid': '0', - 'cat': [], - 'w': 300, - 'h': 250, - 'ext': { - 'type': 'CPM', - 'mtype': 'banner' - } - }, - { - 'id': '22645215457415', - 'impid': '2', - 'adm': 'john is the best', - 'adomain': ['td.com'], - 'price': 0.580000, - 'cid': '2524574', - 'adid': '0', - 'crid': '0', - 'cat': [], - 'w': 728, - 'h': 90, - 'ext': { - 'type': 'CPM', - 'mtype': 'banner' - } - }, - - { - 'id': '22645215457416', - 'impid': '3', - 'adm': '{"native":{"ver":"1.2","assets":[{"id":1,"required":1,"title":{"text":"John is amazing"}},{"id":5,"required":1,"data":{"value":"Sponsored by John"}},{"id":3,"required":1,"img":{"url":"https://example.image.com/", "h":"360", "w":"360"}}],"link":{"url":"https://click.example.com/c/264597/?fcid=29699699045816"},"imptrackers":["https://impression.example.com/i/264597/?fcid=29699699045816"]}}', - 'adomain': ['td.com'], - 'price': 10.00, - 'cid': '2524574', - 'adid': '0', - 'crid': '0', - 'cat': [], - 'ext': { - 'type': 'CPM', - 'mtype': 'native' - } - } - ], - 'cur': 'USD', - 'ext': { - 'version': '1.2.93', - 'buyerid': '1234567', - 'syncs': [ - { - 'type': 'iframe', - 'url': 'https://s.0cf.io' - }, - { - 'type': 'image', - 'url': 'https://us.dblks.net/set_uid/' - } - ] - } - } -} - -const bid_request = { - method: 'POST', - url: 'https://prebid.datablocks.net/openrtb/?sid=2523014', - options: { - withCredentials: true - }, - data: { - 'id': 'c09c6e47-8bdb-4884-a46d-93165322b368', - 'imp': [{ - 'id': '1', - 'tagid': '/19968336/header-bid-tag-0', - 'placement_id': 0, - 'secure': true, - 'banner': { - 'w': 300, - 'h': 250, - 'format': [{ - 'w': 300, - 'h': 250 - }, { - 'w': 300, - 'h': 600 - }] - } - }, { - 'id': '2', - 'tagid': '/19968336/header-bid-tag-1', - 'placement_id': 12345, - 'secure': true, - 'banner': { - 'w': 729, - 'h': 90, - 'format': [{ - 'w': 729, - 'h': 90 - }, { - 'w': 970, - 'h': 250 - }] - } - }, { - 'id': '3', - 'tagid': '/19968336/prebid_multiformat_test', - 'placement_id': 0, - 'secure': true, - 'native': { - 'ver': '1.2', - 'request': { - 'assets': [{ - 'required': 1, - 'id': 1, - 'title': {} - }, { - 'required': 1, - 'id': 3, - 'img': { - 'type': 3 - } - }, { - 'required': 1, - 'id': 5, - 'data': { - 'type': 1 - } - }], - 'context': 1, - 'plcmttype': 1, - 'ver': '1.2' - } - } - }], - 'site': { - 'domain': 'test.datablocks.net', - 'page': 'https://test.datablocks.net/index.html', - 'schain': {}, - 'ext': { - 'p_domain': 'https://test.datablocks.net', - 'rt': true, - 'frames': 0, - 'stack': ['https://test.datablocks.net/index.html'], - 'timeout': 3000 - }, - 'keywords': 'HTML, CSS, JavaScript' - }, - 'device': { - 'ip': 'peer', - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.82 Safari/537.36', - 'js': 1, - 'language': 'en', - 'buyerid': '1234567', - 'ext': { - 'pb_eids': [{ - 'source': 'criteo.com', - 'uids': [{ - 'id': 'test', - 'atype': 1 - }] - }], - 'syncs': { - '1000': 'db_4044853', - '1001': true - }, - 'coppa': 0, - 'gdpr': {}, - 'usp': {}, - 'client_info': { - 'wiw': 2560, - 'wih': 1281, - 'saw': 2560, - 'sah': 1417, - 'scd': 24, - 'sw': 2560, - 'sh': 1440, - 'whl': 4, - 'wxo': 0, - 'wyo': 0, - 'wpr': 2, - 'is_bot': false, - 'is_hid': false, - 'vs': 'hidden' - }, - 'fpd': {} - } - } - } -} - -describe('DatablocksAdapter', function() { - before(() => { - // stub out queue metric to avoid it polluting the global xhr mock during other tests - sinon.stub(spec, 'queue_metric').callsFake(() => null); - }); - - after(() => { - spec.queue_metric.restore(); - }); - - describe('All needed functions are available', function() { - it(`isBidRequestValid is present and type function`, function () { - expect(spec.isBidRequestValid).to.exist.and.to.be.a('function') - }); - - it(`buildRequests is present and type function`, function () { - expect(spec.buildRequests).to.exist.and.to.be.a('function') - }); - - it(`getUserSyncs is present and type function`, function () { - expect(spec.getUserSyncs).to.exist.and.to.be.a('function') - }); - - it(`onBidWon is present and type function`, function () { - expect(spec.onBidWon).to.exist.and.to.be.a('function') - }); - - it(`onSetTargeting is present and type function`, function () { - expect(spec.onSetTargeting).to.exist.and.to.be.a('function') - }); - - it(`interpretResponse is present and type function`, function () { - expect(spec.interpretResponse).to.exist.and.to.be.a('function') - }); - - it(`store_dbid is present and type function`, function () { - expect(spec.store_dbid).to.exist.and.to.be.a('function') - }); - - it(`get_dbid is present and type function`, function () { - expect(spec.get_dbid).to.exist.and.to.be.a('function') - }); - - it(`store_syncs is present and type function`, function () { - expect(spec.store_syncs).to.exist.and.to.be.a('function') - }); - - it(`get_syncs is present and type function`, function () { - expect(spec.get_syncs).to.exist.and.to.be.a('function') - }); - - it(`queue_metric is present and type function`, function () { - expect(spec.queue_metric).to.exist.and.to.be.a('function') - }); - - it(`send_metrics is present and type function`, function () { - expect(spec.send_metrics).to.exist.and.to.be.a('function') - }); - - it(`get_client_info is present and type function`, function () { - expect(spec.get_client_info).to.exist.and.to.be.a('function') - }); - - it(`get_viewability is present and type function`, function () { - expect(spec.get_viewability).to.exist.and.to.be.a('function') - }); - }); - - describe('get / store dbid', function() { - it('Should return true / undefined', function() { - expect(spec.store_dbid('12345')).to.be.true; - expect(spec.get_dbid()).to.be.a('string'); - }); - }) - - describe('get / store syncs', function() { - it('Should return true / array', function() { - expect(spec.store_syncs([{id: 1, uid: 'test'}])).to.be.true; - expect(spec.get_syncs()).to.be.a('object'); - }); - }) - - describe('get_viewability', function() { - it('Should return undefined', function() { - expect(spec.get_viewability()).to.equal(undefined); - }); - }) - - describe('get client info', function() { - it('Should return object', function() { - const client_info = spec.get_client_info() - expect(client_info).to.be.a('object'); - expect(client_info).to.have.all.keys('wiw', 'wih', 'saw', 'sah', 'scd', 'sw', 'sh', 'whl', 'wxo', 'wyo', 'wpr', 'is_bot', 'is_hid', 'vs'); - }); - - it('bot test should return boolean', function() { - const bot_test = new BotClientTests(); - expect(bot_test.doTests()).to.be.a('boolean'); - }); - }) - - describe('isBidRequestValid', function() { - it('Should return true when source_id and Host are set', function() { - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - it('Should return false when host/source_id is not set', function() { - const moddedBid = deepClone(bid); - delete moddedBid.params.source_id; - expect(spec.isBidRequestValid(moddedBid)).to.be.false; - }); - - it('Should return true when viewability reporting is opted out', function() { - const moddedBid = Object.assign({}, bid); - moddedBid.params.vis_optout = true; - spec.isBidRequestValid(moddedBid); - expect(spec.db_obj.vis_optout).to.be.true; - }); - }) - - describe('getUserSyncs', function() { - it('Should return array of syncs', function() { - expect(spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, [res_object], {gdprApplies: true, gdpr: 1, gdpr_consent: 'consent_string'}, {})).to.be.an('array'); - }); - }); - - describe('onSetTargeting', function() { - it('Should return undefined', function() { - expect(spec.onSetTargeting()).to.equal(undefined); - }); - }); - - describe('onBidWon', function() { - it('Should return undefined', function() { - const won_bid = {params: [{source_id: 1}], requestId: 1, adUnitCode: 'unit', auctionId: 1, size: '300x250', cpm: 10, adserverTargeting: {hb_pb: 10}, timeToRespond: 10, ttl: 10}; - expect(spec.onBidWon(won_bid)).to.equal(undefined); - }); - }); - - describe('buildRequests', function() { - let request; - before(() => { - request = spec.buildRequests([bid, bid2, nativeBid], bidderRequest); - expect(request).to.exist; - }) - - it('Returns POST method', function() { - expect(request.method).to.exist; - expect(request.method).to.equal('POST'); - }); - - it('Returns valid URL', function() { - expect(request.url).to.exist; - expect(request.url).to.equal('https://v5demo.datablocks.net/openrtb/?sid=7560'); - }); - - it('Creates an array of request objects', function() { - expect(request.data.imp).to.be.an('array').that.is.not.empty; - }); - - it('Should be a valid openRTB request', function() { - const data = request.data; - - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('device', 'imp', 'site', 'id'); - expect(data.id).to.be.a('string'); - expect(data.imp).to.be.a('array'); - expect(data.device.ip).to.equal('peer'); - - const imps = data['imp']; - imps.forEach((imp, index) => { - const curBid = bidderRequest.bids[index]; - if (imp.banner) { - expect(imp.banner).to.be.a('object'); - expect(imp).to.have.all.keys('banner', 'id', 'secure', 'tagid', 'placement_id', 'ortb2', 'floor'); - } else if (imp.native) { - expect(imp).to.have.all.keys('native', 'id', 'secure', 'tagid', 'placement_id', 'ortb2', 'floor'); - expect(imp.native).to.have.all.keys('request', 'ver'); - expect(imp.native.request).to.be.a('object'); - } else { - expect(true).to.equal(false); - } - - expect(imp.id).to.be.a('string'); - expect(imp.id).to.equal(curBid.bidId); - expect(imp.tagid).to.be.a('string'); - expect(imp.tagid).to.equal(curBid.adUnitCode); - expect(imp.secure).to.equal(false); - }) - }); - - it('Returns empty data if no valid requests are passed', function() { - const test_request = spec.buildRequests([]); - expect(test_request).to.be.an('array').that.is.empty; - }); - }); - - describe('interpretResponse', function() { - const response = spec.interpretResponse(res_object, bid_request); - - it('Returns an array of valid server responses if response object is valid', function() { - expect(response).to.be.an('array').that.is.not.empty; - - response.forEach(bid => { - expect(parseInt(bid.requestId)).to.be.a('number').greaterThan(0); - expect(bid.cpm).to.be.a('number'); - expect(bid.creativeId).to.be.a('string'); - expect(bid.currency).to.be.a('string'); - expect(bid.netRevenue).to.be.a('boolean'); - expect(bid.ttl).to.be.a('number'); - expect(bid.mediaType).to.be.a('string'); - - if (bid.mediaType === 'banner') { - expect(bid.width).to.be.a('number'); - expect(bid.height).to.be.a('number'); - expect(bid.ad).to.be.a('string'); - } else if (bid.mediaType === 'native') { - expect(bid.native).to.be.a('object'); - } - }) - - it('Returns an empty array if invalid response is passed', function() { - serverResponses = spec.interpretResponse('invalid_response'); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - }); -}); diff --git a/test/spec/modules/datawrkzAnalyticsAdapter_spec.js b/test/spec/modules/datawrkzAnalyticsAdapter_spec.js deleted file mode 100644 index 630c189a1..000000000 --- a/test/spec/modules/datawrkzAnalyticsAdapter_spec.js +++ /dev/null @@ -1,178 +0,0 @@ -import analyticsAdapter from "modules/datawrkzAnalyticsAdapter.js"; -import adapterManager from "src/adapterManager.js"; -import { EVENTS } from "src/constants.js"; - -const { - AUCTION_INIT, - BID_REQUESTED, - BID_RESPONSE, - BID_TIMEOUT, - BID_WON, - AUCTION_END, - AD_RENDER_SUCCEEDED, - AD_RENDER_FAILED -} = EVENTS; - -describe("DatawrkzAnalyticsAdapter", function () { - let sandbox; - let fetchStub; - - const auctionId = "auction_123"; - const adUnitCode = "div-gpt-ad-001"; - const bidder = "appnexus"; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - fetchStub = sandbox.stub(window, "fetch"); - - adapterManager.enableAnalytics({ provider: "datawrkzanalytics" }); - }); - - afterEach(function () { - sandbox.restore(); - analyticsAdapter.disableAnalytics(); - }); - - it("should track AUCTION_INIT", function () { - analyticsAdapter.track({ eventType: AUCTION_INIT, args: { auctionId } }); - }); - - it("should track BID_REQUESTED", function () { - analyticsAdapter.track({ eventType: AUCTION_INIT, args: { auctionId } }); - - analyticsAdapter.track({ - eventType: BID_REQUESTED, - args: { auctionId, bids: [{ adUnitCode, bidder }] }, - }); - }); - - it("should track BID_RESPONSE", function () { - analyticsAdapter.track({ eventType: AUCTION_INIT, args: { auctionId } }); - - analyticsAdapter.track({ - eventType: BID_REQUESTED, - args: { auctionId, bids: [{ adUnitCode, bidder }] }, - }); - - analyticsAdapter.track({ - eventType: BID_RESPONSE, - args: { - auctionId, - adUnitCode, - bidder, - cpm: 1.2, - currency: "USD", - timeToRespond: 120, - }, - }); - }); - - it("should track BID_TIMEOUT", function () { - analyticsAdapter.track({ eventType: AUCTION_INIT, args: { auctionId } }); - - analyticsAdapter.track({ - eventType: BID_REQUESTED, - args: { auctionId, bids: [{ adUnitCode, bidder }] }, - }); - - analyticsAdapter.track({ - eventType: BID_TIMEOUT, - args: { auctionId, adUnitCode, bidder }, - }); - }); - - it("should track BID_WON", function () { - analyticsAdapter.track({ eventType: AUCTION_INIT, args: { auctionId } }); - - analyticsAdapter.track({ - eventType: BID_REQUESTED, - args: { auctionId, bids: [{ adUnitCode, bidder }] }, - }); - - analyticsAdapter.track({ - eventType: BID_WON, - args: { auctionId, adUnitCode, bidder, cpm: 2.5 }, - }); - }); - - it("should send data on AUCTION_END", function () { - const clock = sinon.useFakeTimers(); - - analyticsAdapter.track({ eventType: AUCTION_INIT, args: { auctionId } }); - analyticsAdapter.track({ - eventType: BID_REQUESTED, - args: { auctionId, bids: [{ adUnitCode, bidder }] }, - }); - analyticsAdapter.track({ - eventType: BID_RESPONSE, - args: { - auctionId, - adUnitCode, - bidder, - cpm: 1.5, - currency: "USD", - timeToRespond: 300, - }, - }); - analyticsAdapter.track({ eventType: AUCTION_END, args: { auctionId } }); - - clock.tick(2000); // Fast-forward time by 2 seconds - - sinon.assert.calledOnce(fetchStub); - - const [url, options] = fetchStub.firstCall.args; - expect(url).to.equal("https://prebid-api.highr.ai/analytics"); - expect(options.method).to.equal("POST"); - expect(options.headers["Content-Type"]).to.equal("application/json"); - - const body = JSON.parse(options.body); - expect(body.auctionId).to.equal(auctionId); - expect(body.adunits[0].code).to.equal(adUnitCode); - expect(body.adunits[0].bids[0].bidder).to.equal(bidder); - - clock.restore(); - }); - - it("should send AD_RENDER_SUCCEEDED event", function () { - analyticsAdapter.track({ - eventType: AD_RENDER_SUCCEEDED, - args: { - bid: { adId: "ad123", bidderCode: bidder, cpm: 2.0 }, - adId: "ad123", - doc: "" - } - }); - - sinon.assert.calledOnce(fetchStub); - const [url, options] = fetchStub.firstCall.args; - const payload = JSON.parse(options.body); - - expect(payload.eventType).to.equal(AD_RENDER_SUCCEEDED); - expect(payload.bidderCode).to.equal("appnexus"); - expect(payload.successDoc).to.be.a("string"); - expect(payload.failureReason).to.be.null; - expect(payload.failureMessage).to.be.null; - }); - - it("should send AD_RENDER_FAILED event", function () { - analyticsAdapter.track({ - eventType: AD_RENDER_FAILED, - args: { - bid: { adId: "ad124", bidderCode: bidder, cpm: 1.5 }, - adId: "ad124", - reason: "network", - message: "Render failed due to network error" - } - }); - - sinon.assert.calledOnce(fetchStub); - const [url, options] = fetchStub.firstCall.args; - const payload = JSON.parse(options.body); - - expect(payload.eventType).to.equal(AD_RENDER_FAILED); - expect(payload.bidderCode).to.equal("appnexus"); - expect(payload.successDoc).to.be.null; - expect(payload.failureReason).to.equal("network"); - expect(payload.failureMessage).to.equal("Render failed due to network error"); - }); -}); diff --git a/test/spec/modules/datawrkzBidAdapter_spec.js b/test/spec/modules/datawrkzBidAdapter_spec.js deleted file mode 100644 index ad513c20b..000000000 --- a/test/spec/modules/datawrkzBidAdapter_spec.js +++ /dev/null @@ -1,652 +0,0 @@ -import { expect } from 'chai'; -import { config } from 'src/config.js'; -import { spec } from 'modules/datawrkzBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; - -const BIDDER_CODE = 'datawrkz'; -const ENDPOINT_URL = 'https://at.datawrkz.com/exchange/openrtb23/'; -const SITE_ID = 'site_id'; -const FINAL_URL = ENDPOINT_URL + SITE_ID + '?hb=1'; - -describe('datawrkzAdapterTests', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': BIDDER_CODE, - 'params': { - 'site_id': SITE_ID, - 'bidfloor': '1.0' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when params not found', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when required site_id param not found', function () { - const invalidBid = Object.assign({}, bid); - invalidBid.params = {'bidfloor': '1.0'} - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when adunit is adpod video', function () { - const invalidBid = Object.assign({}, bid); - invalidBid.params = {'bidfloor': '1.0', 'site_id': SITE_ID}; - invalidBid.mediaTypes = { - 'video': { - 'context': 'adpod' - } - } - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const consentString = '1YA-'; - const bidderRequest = { - 'bidderCode': 'datawrkz', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'uspConsent': consentString, - 'gdprConsent': {'gdprApplies': true}, - }; - const bannerBidRequests = [{ - 'bidder': BIDDER_CODE, - 'params': {'site_id': SITE_ID, 'bidfloor': 1.00}, - 'mediaTypes': {'banner': {'sizes': [[300, 250], [300, 600]]}}, - 'adUnitCode': 'adUnitCode', - 'transactionId': 'transactionId', - 'sizes': [[300, 250], [300, 600]], - 'bidId': 'bidId', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId', - }]; - const bannerBidRequestsSingleArraySlotAndDeals = [{ - 'bidder': BIDDER_CODE, - 'params': {'site_id': SITE_ID, 'bidfloor': 1.00, 'deals': [{id: 'deal_1'}, {id: 'deal_2'}]}, - 'mediaTypes': {'banner': {}}, - 'adUnitCode': 'adUnitCode', - 'transactionId': 'transactionId', - 'sizes': [300, 250], - 'bidId': 'bidId', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId', - }]; - const nativeBidRequests = [{ - 'bidder': BIDDER_CODE, - 'params': {'site_id': SITE_ID, 'bidfloor': 1.00}, - 'mediaTypes': {'native': { - 'title': {'required': true, 'len': 80}, - 'image': {'required': true, 'sizes': [[300, 250]]}, - 'icon': {'required': true, 'sizes': [[50, 50]]}, - 'sponsoredBy': {'required': true}, - 'cta': {'required': true}, - 'body': {'required': true, 'len': 100} - }}, - 'adUnitCode': 'adUnitCode', - 'transactionId': 'transactionId', - 'bidId': 'bidId', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId', - }]; - const nativeBidRequestsSingleArraySlotAndDeals = [{ - 'bidder': BIDDER_CODE, - 'params': {'site_id': SITE_ID, 'bidfloor': 1.00, 'deals': [{id: 'deal_1'}, {id: 'deal_2'}]}, - 'mediaTypes': {'native': { - 'title': {'len': 80}, - 'image': {'sizes': [300, 250]}, - 'icon': {'sizes': [50, 50]}, - 'sponsoredBy': {}, - 'cta': {}, - 'body': {'len': 100} - }}, - 'adUnitCode': 'adUnitCode', - 'transactionId': 'transactionId', - 'bidId': 'bidId', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId', - }]; - const instreamVideoBidRequests = [{ - 'bidder': BIDDER_CODE, - 'params': {'site_id': SITE_ID, 'bidfloor': 1.00}, - 'mediaTypes': {'video': {'context': 'instream', 'playerSize': [[640, 480]]}}, - 'adUnitCode': 'adUnitCode', - 'transactionId': 'transactionId', - 'bidId': 'bidId', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId', - }]; - const instreamVideoBidRequestsSingleArraySlotAndDeals = [{ - 'bidder': BIDDER_CODE, - 'params': {'site_id': SITE_ID, 'bidfloor': 1.00, 'deals': [{id: 'deal_1'}, {id: 'deal_2'}]}, - 'mediaTypes': {'video': {'context': 'instream', 'playerSize': [640, 480]}}, - 'adUnitCode': 'adUnitCode', - 'transactionId': 'transactionId', - 'bidId': 'bidId', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId', - }]; - const outstreamVideoBidRequests = [{ - 'bidder': BIDDER_CODE, - 'params': {'site_id': SITE_ID, 'bidfloor': 1.00}, - 'mediaTypes': {'video': {'context': 'outstream', 'playerSize': [[640, 480]], 'mimes': ['video/mp4', 'video/x-flv']}}, - 'adUnitCode': 'adUnitCode', - 'transactionId': 'transactionId', - 'bidId': 'bidId', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId', - }]; - const outstreamVideoBidRequestsSingleArraySlotAndDeals = [{ - 'bidder': BIDDER_CODE, - 'params': {'site_id': SITE_ID, 'bidfloor': 1.00, 'deals': [{id: 'deal_1'}, {id: 'deal_2'}]}, - 'mediaTypes': {'video': {'context': 'outstream', 'playerSize': [640, 480], 'mimes': ['video/mp4', 'video/x-flv']}}, - 'adUnitCode': 'adUnitCode', - 'transactionId': 'transactionId', - 'bidId': 'bidId', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId', - }]; - const bidRequestsWithNoMediaType = [{ - 'bidder': BIDDER_CODE, - 'params': {'site_id': SITE_ID, 'bidfloor': 1.00}, - 'adUnitCode': 'adUnitCode', - 'transactionId': 'transactionId', - 'bidId': 'bidId', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId', - }]; - - it('empty bid requests', function () { - const requests = spec.buildRequests([], bidderRequest); - assert.lengthOf(requests, 0); - }); - - it('mediaTypes missing in bid request', function () { - const requests = spec.buildRequests(bidRequestsWithNoMediaType, bidderRequest); - assert.lengthOf(requests, 0); - }); - - it('invalid media type in bid request', function () { - bidRequestsWithNoMediaType[0].mediaTypes = {'test': {}}; - const requests = spec.buildRequests(bidRequestsWithNoMediaType, bidderRequest); - assert.lengthOf(requests, 0); - }); - - it('size missing in bid request for banner', function () { - delete bidRequestsWithNoMediaType[0].mediaTypes.test; - bidRequestsWithNoMediaType[0].mediaTypes.banner = {}; - const requests = spec.buildRequests(bidRequestsWithNoMediaType, bidderRequest); - assert.lengthOf(requests, 0); - }); - - it('size array empty in bid request for banner', function () { - bidRequestsWithNoMediaType[0].mediaTypes.banner.sizes = []; - const requests = spec.buildRequests(bidRequestsWithNoMediaType, bidderRequest); - assert.lengthOf(requests, 0); - }); - - it('banner bidRequest with slot size as 2 dimensional array', function () { - sinon.stub(config, 'getConfig').withArgs('coppa').returns(true); - const requests = spec.buildRequests(bannerBidRequests, bidderRequest); - config.getConfig.restore(); - const payload = JSON.parse(requests[0].data); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(FINAL_URL); - expect(payload.imp).to.exist; - expect(payload).to.nested.include({'imp[0].banner.w': 300}); - expect(payload).to.nested.include({'imp[0].banner.h': 250}); - expect(payload).to.nested.include({'regs.ext.us_privacy': consentString}); - expect(payload).to.nested.include({'regs.ext.gdpr': '1'}); - expect(payload).to.nested.include({'regs.coppa': '1'}); - expect(requests[0].bidRequest).to.exist; - expect(requests[0].bidRequest.requestedMediaType).to.equal('banner'); - }); - - it('banner bidRequest with deals and slot size as 1 dimensional array', function () { - const requests = spec.buildRequests(bannerBidRequestsSingleArraySlotAndDeals, bidderRequest); - const payload = JSON.parse(requests[0].data); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(FINAL_URL); - expect(payload.imp).to.exist; - expect(payload).to.nested.include({'imp[0].banner.w': 300}); - expect(payload).to.nested.include({'imp[0].banner.h': 250}); - expect(payload).to.nested.include({'imp[0].pmp.deals[0].id': 'deal_1'}); - expect(payload).to.nested.include({'imp[0].pmp.deals[1].id': 'deal_2'}); - expect(requests[0].bidRequest).to.exist; - expect(requests[0].bidRequest.requestedMediaType).to.equal('banner'); - }); - - it('native bidRequest fields with slot size as 2 dimensional array', function () { - sinon.stub(config, 'getConfig').withArgs('coppa').returns(true); - const requests = spec.buildRequests(nativeBidRequests, bidderRequest); - config.getConfig.restore(); - const payload = JSON.parse(requests[0].data); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(FINAL_URL); - expect(payload.imp[0].native.request).to.exist; - expect(payload).to.nested.include({'regs.ext.us_privacy': consentString}); - expect(payload).to.nested.include({'regs.ext.gdpr': '1'}); - expect(payload).to.nested.include({'regs.coppa': '1'}); - expect(requests[0].bidRequest).to.exist; - expect(requests[0].bidRequest.requestedMediaType).to.equal('native'); - }); - - it('native bidRequest fields with deals and slot size as 1 dimensional array', function () { - const requests = spec.buildRequests(nativeBidRequestsSingleArraySlotAndDeals, bidderRequest); - const payload = JSON.parse(requests[0].data); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(FINAL_URL); - expect(payload.imp).to.exist; - expect(payload.imp[0].native.request).to.exist; - expect(payload).to.nested.include({'imp[0].pmp.deals[0].id': 'deal_1'}); - expect(payload).to.nested.include({'imp[0].pmp.deals[1].id': 'deal_2'}); - expect(requests[0].bidRequest).to.exist; - expect(requests[0].bidRequest.requestedMediaType).to.equal('native'); - }); - - it('instream video bidRequest fields with slot size as 2 dimensional array', function () { - sinon.stub(config, 'getConfig').withArgs('coppa').returns(true); - const requests = spec.buildRequests(instreamVideoBidRequests, bidderRequest); - config.getConfig.restore(); - const payload = JSON.parse(requests[0].data); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(FINAL_URL); - expect(payload).to.nested.include({'regs.ext.us_privacy': consentString}); - expect(payload).to.nested.include({'regs.ext.gdpr': '1'}); - expect(payload).to.nested.include({'regs.coppa': '1'}); - expect(requests[0].bidRequest).to.exist; - expect(requests[0].bidRequest.requestedMediaType).to.equal('video'); - }); - - it('instream video bidRequest with deals and slot size as 1 dimensional array', function () { - const requests = spec.buildRequests(instreamVideoBidRequestsSingleArraySlotAndDeals, bidderRequest); - const payload = JSON.parse(requests[0].data); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(FINAL_URL); - expect(requests[0].bidRequest).to.exist; - expect(requests[0].bidRequest.requestedMediaType).to.equal('video'); - }); - - it('outstream video bidRequest fields with slot size as 2 dimensional array', function () { - sinon.stub(config, 'getConfig').withArgs('coppa').returns(true); - const requests = spec.buildRequests(outstreamVideoBidRequests, bidderRequest); - config.getConfig.restore(); - const payload = JSON.parse(requests[0].data); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(FINAL_URL); - expect(payload).to.nested.include({'imp[0].video.w': 640}); - expect(payload).to.nested.include({'imp[0].video.h': 480}); - expect(payload).to.nested.include({'regs.ext.us_privacy': consentString}); - expect(payload).to.nested.include({'regs.ext.gdpr': '1'}); - expect(payload).to.nested.include({'regs.coppa': '1'}); - expect(requests[0].bidRequest).to.exist; - expect(requests[0].bidRequest.requestedMediaType).to.equal('video'); - }); - - it('outstream video bidRequest fields with deals and slot size as 1 dimensional array', function () { - const requests = spec.buildRequests(outstreamVideoBidRequestsSingleArraySlotAndDeals, bidderRequest); - const payload = JSON.parse(requests[0].data); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(FINAL_URL); - expect(payload).to.nested.include({'imp[0].video.w': 640}); - expect(payload).to.nested.include({'imp[0].video.h': 480}); - expect(payload).to.nested.include({'imp[0].pmp.deals[0].id': 'deal_1'}); - expect(payload).to.nested.include({'imp[0].pmp.deals[1].id': 'deal_2'}); - expect(requests[0].bidRequest).to.exist; - expect(requests[0].bidRequest.requestedMediaType).to.equal('video'); - }); - }); - - describe('interpretResponse', function () { - const bidRequest = { - 'bidder': BIDDER_CODE, - 'params': {'site_id': SITE_ID, 'bidfloor': 1.00}, - 'mediaTypes': {'banner': {'sizes': [[300, 250], [300, 600]]}}, - 'adUnitCode': 'adUnitCode', - 'transactionId': 'transactionId', - 'sizes': [[300, 250], [300, 600]], - 'bidId': 'bidId', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId', - 'requestedMediaType': 'banner' - }; - const nativeBidRequest = { - 'bidder': BIDDER_CODE, - 'params': {'site_id': SITE_ID, 'bidfloor': 1.00}, - 'mediaTypes': {'native': { - 'title': {'required': true, 'len': 80}, - 'image': {'required': true, 'sizes': [300, 250]}, - 'icon': {'required': true, 'sizes': [50, 50]}, - 'sponsoredBy': {'required': true}, - 'cta': {'required': true}, - 'body': {'required': true} - }}, - 'adUnitCode': 'adUnitCode', - 'transactionId': 'transactionId', - 'bidId': 'bidId', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId', - 'requestedMediaType': 'native', - 'assets': [ - {'id': 1, 'required': 1, 'title': {'len': 80}}, - {'id': 2, 'required': 1, 'img': {'type': 3, 'w': 300, 'h': 250}}, - {'id': 3, 'required': 1, 'img': {'type': 1, 'w': 50, 'h': 50}}, - {'id': 4, 'required': 1, 'data': {'type': 1}}, - {'id': 5, 'required': 1, 'data': {'type': 12}}, - {'id': 6, 'required': 1, 'data': {'type': 2, 'len': 100}} - ] - }; - const instreamVideoBidRequest = { - 'bidder': BIDDER_CODE, - 'params': {'site_id': SITE_ID, 'bidfloor': 1.00}, - 'mediaTypes': {'video': {'context': 'instream', 'playerSize': [640, 480]}}, - 'adUnitCode': 'adUnitCode', - 'transactionId': 'transactionId', - 'bidId': 'bidId', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId', - 'requestedMediaType': 'video' - }; - const outstreamVideoBidRequest = { - 'bidder': BIDDER_CODE, - 'params': {'site_id': SITE_ID, - 'bidfloor': 1.00, - 'outstreamType': 'slider_top_left', - 'outstreamConfig': - {'ad_unit_audio': 1, 'show_player_close_button_after': 5, 'hide_player_control': 0}}, - 'mediaTypes': {'video': {'context': 'outstream', 'playerSize': [640, 480]}}, - 'adUnitCode': 'adUnitCode', - 'transactionId': 'transactionId', - 'bidId': 'bidId', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId', - 'requestedMediaType': 'video' - }; - const request = { - 'method': 'POST', - 'url': FINAL_URL, - 'data': '', - bidRequest - }; - - it('check empty response', function () { - const result = spec.interpretResponse({}, request); - expect(result).to.deep.equal([]); - }); - - it('check if id missing in response', function () { - const serverResponse = {'body': {'seatbid': [{}]}, 'headers': {}}; - const result = spec.interpretResponse(serverResponse, request); - expect(result).to.deep.equal([]); - }); - - it('check if seatbid present in response', function () { - const serverResponse = {'body': {'id': 'id'}, 'headers': {}}; - const result = spec.interpretResponse(serverResponse, request); - expect(result).to.deep.equal([]); - }); - - it('check empty array response seatbid', function () { - const serverResponse = {'body': {'id': 'id', 'seatbid': []}, 'headers': {}}; - const result = spec.interpretResponse(serverResponse, request); - expect(result).to.deep.equal([]); - }); - - it('check bid present in seatbid', function () { - const serverResponse = {'body': {'id': 'id', 'seatbid': [{}]}, 'headers': {}}; - const result = spec.interpretResponse(serverResponse, request); - expect(result).to.have.lengthOf(0); - }); - - it('check empty array bid in seatbid', function () { - const serverResponse = {'body': {'id': 'id', 'seatbid': [{'bid': []}]}, 'headers': {}}; - const result = spec.interpretResponse(serverResponse, request); - expect(result).to.have.lengthOf(0); - }); - - it('banner response missing bid price', function () { - const serverResponse = {'body': {'id': 'id', 'seatbid': [{'bid': [{'id': 1}]}]}, 'headers': {}}; - const result = spec.interpretResponse(serverResponse, request); - expect(result).to.have.lengthOf(1); - expect(result[0].requestId).to.equal('bidId'); - expect(result[0].bidderCode).to.equal(request.bidRequest.bidder); - }); - - it('banner response', function () { - const serverResponse = { - 'body': { - 'id': 'id', - 'seatbid': [ - { - 'bid': [ - { - 'id': '1', - 'price': 1, - 'w': 300, - 'h': 250, - 'adm': 'test adm', - 'nurl': 'url' - } - ] - } - ] - }, - 'headers': {} - }; - const result = spec.interpretResponse(serverResponse, request); - expect(result).to.have.lengthOf(1); - expect(result[0].requestId).to.equal('bidId'); - expect(result[0].cpm).to.equal(1); - expect(result[0].size).to.equal(bidRequest.mediaTypes.banner.sizes); - expect(result[0].width).to.equal(300); - expect(result[0].height).to.equal(250); - expect(result[0].ad).to.equal(decodeURIComponent(serverResponse.body.seatbid[0].bid[0].adm + '')); - expect(result[0].creativeId).to.equal('1'); - expect(result[0].bidderCode).to.equal(request.bidRequest.bidder); - expect(result[0].mediaType).to.equal('banner'); - }); - - it('native response missing bid price', function () { - request.bidRequest = nativeBidRequest; - const serverResponse = { - 'body': { - 'id': 'id', - 'seatbid': [ - { - 'bid': [ - { - 'id': '1', - 'w': 300, - 'h': 250, - 'adm': '{"native": {"link": {"url": "test_url"}, "imptrackers": [], "assets": [' + - '{"id": 1, "title": {"text": "Test title"}},' + - '{"id": 2, "img": {"type": 3,"url": "https://test/image", "w": 300, "h": 250}},' + - '{"id": 3, "img": {"type": 1, "url": "https://test/icon", "w": 50, "h": 50}},' + - '{"id": 4, "data": {"type": 1, "value": "Test sponsored by"}},' + - '{"id": 5, "data": {"type": 12, "value": "Test CTA"}},' + - '{"id": 6, "data": {"type": 2, "value": "Test body"}}]}}' - } - ] - } - ] - }, - 'headers': {} - }; - const result = spec.interpretResponse(serverResponse, request); - expect(result).to.have.lengthOf(1); - expect(result[0].requestId).to.equal('bidId'); - expect(result[0].bidderCode).to.equal(request.bidRequest.bidder); - }); - - it('native response', function () { - request.bidRequest = nativeBidRequest; - const serverResponse = { - 'body': { - 'id': 'id', - 'seatbid': [ - { - 'bid': [ - { - 'id': '1', - 'price': 1, - 'w': 300, - 'h': 250, - 'adm': '{"native": {"link": {"url": "test_url"}, "imptrackers": ["tracker1", "tracker2"], "assets": [' + - '{"id": 1, "title": {"text": "Test title"}},' + - '{"id": 2, "img": {"type": 3,"url": "https://test/image", "w": 300, "h": 250}},' + - '{"id": 3, "img": {"type": 1, "url": "https://test/icon", "w": 50, "h": 50}},' + - '{"id": 4, "data": {"type": 1, "value": "Test sponsored by"}},' + - '{"id": 5, "data": {"type": 12, "value": "Test CTA"}},' + - '{"id": 6, "data": {"type": 2, "value": "Test body"}}]}}' - } - ] - } - ] - }, - 'headers': {} - }; - - const result = spec.interpretResponse(serverResponse, request); - expect(result).to.have.lengthOf(1); - expect(result[0].requestId).to.equal('bidId'); - expect(result[0].cpm).to.equal(1); - expect(result[0].native.clickUrl).to.equal('test_url'); - expect(result[0].native.impressionTrackers).to.have.lengthOf(2); - expect(result[0].native.title).to.equal('Test title'); - expect(result[0].native.image.url).to.equal('https://test/image'); - expect(result[0].native.icon.url).to.equal('https://test/icon'); - expect(result[0].native.sponsored).to.equal('Test sponsored by'); - expect(result[0].native.cta).to.equal('Test CTA'); - expect(result[0].native.desc).to.equal('Test body'); - expect(result[0].creativeId).to.equal('1'); - expect(result[0].bidderCode).to.equal(request.bidRequest.bidder); - expect(result[0].mediaType).to.equal('native'); - }); - - it('video response missing bid price', function () { - request.bidRequest = instreamVideoBidRequest; - const serverResponse = { - 'body': { - 'id': 'id', - 'seatbid': [ - { - 'bid': [ - { - 'id': '1', - 'w': 640, - 'h': 480, - 'adm': '', - 'ext': { - 'vast_url': 'vast_url' - } - } - ] - } - ] - }, - 'headers': {} - }; - const result = spec.interpretResponse(serverResponse, request); - expect(result).to.have.lengthOf(1); - expect(result[0].requestId).to.equal('bidId'); - expect(result[0].bidderCode).to.equal(request.bidRequest.bidder); - }); - - it('instream video response', function () { - request.bidRequest = instreamVideoBidRequest; - const serverResponse = { - 'body': { - 'id': 'id', - 'seatbid': [ - { - 'bid': [ - { - 'id': '1', - 'price': 1, - 'w': 640, - 'h': 480, - 'adm': '', - 'ext': { - 'vast_url': 'test_vast_url?kcid=123&kaid=12&protocol=3' - } - } - ] - } - ] - }, - 'headers': {} - }; - - const result = spec.interpretResponse(serverResponse, request); - expect(result).to.have.lengthOf(1); - expect(result[0].requestId).to.equal('bidId'); - expect(result[0].cpm).to.equal(1); - expect(result[0].width).to.equal(640); - expect(result[0].height).to.equal(480); - expect(result[0].vastUrl).to.equal('test_vast_url?kcid=123&kaid=12&protocol=3'); - expect(result[0].adserverTargeting.hb_kcid).to.equal('123'); - expect(result[0].adserverTargeting.hb_kaid).to.equal('12'); - expect(result[0].adserverTargeting.hb_protocol).to.equal('3'); - expect(result[0].creativeId).to.equal('1'); - expect(result[0].bidderCode).to.equal(request.bidRequest.bidder); - expect(result[0].mediaType).to.equal('video'); - }); - - it('outstream video response', function () { - request.bidRequest = outstreamVideoBidRequest; - const serverResponse = { - 'body': { - 'id': 'id', - 'seatbid': [ - { - 'bid': [ - { - 'id': '1', - 'price': 1, - 'w': 640, - 'h': 480, - 'adm': '', - 'ext': { - 'vast_url': 'vast_url' - } - } - ] - } - ] - }, - 'headers': {} - }; - const result = spec.interpretResponse(serverResponse, request); - expect(result).to.have.lengthOf(1); - expect(result[0].requestId).to.equal('bidId'); - expect(result[0].cpm).to.equal(1); - expect(result[0].width).to.equal(640); - expect(result[0].height).to.equal(480); - expect(result[0].outstreamType).to.equal('slider_top_left'); - expect(result[0].ad).to.equal(''); - expect(result[0].renderer).to.exist; - expect(result[0].creativeId).to.equal('1'); - expect(result[0].bidderCode).to.equal(request.bidRequest.bidder); - expect(result[0].mediaType).to.equal('video'); - }); - }); -}); diff --git a/test/spec/modules/deepintentBidAdapter_spec.js b/test/spec/modules/deepintentBidAdapter_spec.js deleted file mode 100644 index ead1c8ecc..000000000 --- a/test/spec/modules/deepintentBidAdapter_spec.js +++ /dev/null @@ -1,519 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/deepintentBidAdapter.js'; -import * as utils from '../../../src/utils.js'; - -describe('Deepintent adapter', function () { - let request, videoBidRequests; - let bannerResponse, videoBidResponse, invalidResponse; - - beforeEach(function () { - request = [ - { - bidder: 'deepintent', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - tagId: '100013', - w: 728, - h: 90, - pos: 1, - user: { - id: 'di_testuid', - buyeruid: 'di_testbuyeruid', - yob: 2002, - gender: 'F' - }, - custom: { - 'position': 'right-box' - } - } - } - ]; - videoBidRequests = - [ - { - code: 'video1', - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'instream' - } - }, - bidder: 'deepintent', - bidId: '22bddb28db77d', - params: { - tagId: '100013', - video: { - mimes: ['video/mp4', 'video/x-flv'], - skippable: true, - testwrongparam: 3, - testwrongparam1: 'wrong', - minduration: 5, - maxduration: 30, - startdelay: 5, - playbackmethod: [1, 3], - api: [1, 2], - protocols: [2, 3], - battr: [13, 14], - minbitrate: 10, - maxbitrate: 10 - } - } - } - ]; - bannerResponse = { - 'body': { - 'id': '303e1fae-9677-41e2-9a92-15a23445363f', - 'seatbid': [{ - 'bid': [{ - 'id': '11447bb1-a266-470d-b0d7-8810f5b1b75f', - 'impid': 'a7e92b9b-d9db-4de8-9c3f-f90737335445', - 'price': 0.6, - 'adid': '10001', - 'adm': "\r\n", - 'adomain': ['deepintent.com'], - 'cid': '103389', - 'crid': '13665', - 'w': 300, - 'h': 250, - 'dealId': 'dee_12312stdszzsx' - }], - 'seat': '10000' - }], - 'bidid': '0b08b09f-aaa1-4c14-b1c8-7debb1a7c1cd' - } - }; - invalidResponse = { - 'body': { - 'id': '303e1fae-9677-41e2-9a92-15a23445363f', - 'seatbid': [{ - 'bid': [{ - 'id': '11447bb1-a266-470d-b0d7-8810f5b1b75f', - 'impid': 'a7e92b9b-d9db-4de8-9c3f-f90737335445', - 'price': 0.6, - 'adid': '10001', - 'adm': 'invalid response', - 'adomain': ['deepintent.com'], - 'cid': '103389', - 'crid': '13665', - 'w': 300, - 'h': 250, - 'dealId': 'dee_12312stdszzsx' - }], - 'seat': '10000' - }], - 'bidid': '0b08b09f-aaa1-4c14-b1c8-7debb1a7c1cd' - } - }; - videoBidResponse = { - 'body': { - 'id': '93D3BAD6-E2E2-49FB-9D89-920B1761C865', - 'seatbid': [{ - 'bid': [{ - 'id': '74858439-49D7-4169-BA5D-44A046315B2F', - 'impid': '22bddb28db77d', - 'price': 1.3, - 'adm': 'Acudeo CompatibleVAST 2.0 Instream Test 1VAST 2.0 Instream Test 1https://dsptracker.com/{PSPM}00:00:04https://www.deepintent.com', - 'h': 250, - 'w': 300, - 'ext': { - 'deal_channel': 6 - } - }] - }] - } - }; - }); - - describe('validations', function () { - it('validBid : tagId is passed', function () { - const bid = { - bidder: 'deepintent', - params: { - tagId: '1232' - } - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equals(true); - }); - it('invalidBid : tagId is not passed', function () { - const bid = { - bidder: 'deepintent', - params: { - h: 200, - w: 300 - } - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equals(false); - }); - it('invalidBid : tagId is not a string', function () { - const bid = { - bidder: 'deepintent', - params: { - tagId: 12345 - } - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equals(false); - }); - it('should check for context if video is present', function() { - const bid = { - bidder: 'deepintent', - params: { - tagId: '12345', - video: { - mimes: ['video/mp4', 'video/x-flv'], - skippable: true, - } - }, - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'instream' - } - }, - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equal(true); - }); - it('should error out if context is not present and is Video', function() { - const bid = { - bidder: 'deepintent', - params: { - tagId: '12345', - video: { - mimes: ['video/mp4', 'video/x-flv'], - skippable: true, - } - }, - mediaTypes: { - video: { - playerSize: [640, 480] - } - }, - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equal(false); - }) - }); - describe('request check', function () { - it('unmutaable bid request check', function () { - const oRequest = utils.deepClone(request); - const bidRequest = spec.buildRequests(request); - expect(request).to.deep.equal(oRequest); - }); - it('bidder connection check', function () { - const bRequest = spec.buildRequests(request); - expect(bRequest.url).to.equal('https://prebid.deepintent.com/prebid'); - expect(bRequest.method).to.equal('POST'); - expect(bRequest.options.contentType).to.equal('application/json'); - }); - it('bid request check : Device', function () { - const bRequest = spec.buildRequests(request); - const data = JSON.parse(bRequest.data); - expect(data.device.ua).to.be.a('string'); - expect(data.device.js).to.equal(1); - expect(data.device.dnt).to.be.a('number'); - expect(data.device.h).to.be.a('number'); - expect(data.device.w).to.be.a('number'); - }); - it('bid request check : Impression', function () { - const bRequest = spec.buildRequests(request); - const data = JSON.parse(bRequest.data); - expect(data.at).to.equal(1); // auction type - expect(data.imp[0].id).to.equal(request[0].bidId); - expect(data.imp[0].tagid).to.equal('100013'); - }); - it('bid request check : ad size', function () { - const bRequest = spec.buildRequests(request); - const data = JSON.parse(bRequest.data); - expect(data.imp[0].banner).to.be.a('object'); - expect(data.imp[0].banner.w).to.equal(300); - expect(data.imp[0].banner.h).to.equal(250); - }); - it('bid request check : custom params', function () { - const bRequest = spec.buildRequests(request); - const data = JSON.parse(bRequest.data); - expect(data.imp[0].ext).to.be.a('object'); - expect(data.imp[0].ext.deepintent.position).to.equal('right-box'); - }); - it('bid request check: position check', function () { - const bRequest = spec.buildRequests(request); - const data = JSON.parse(bRequest.data); - expect(data.imp[0].banner.pos).to.equal(1); - }); - it('bid request check: displaymanager check', function() { - const bRequest = spec.buildRequests(request); - const data = JSON.parse(bRequest.data); - expect(data.imp[0].displaymanager).to.equal('di_prebid'); - expect(data.imp[0].displaymanagerver).to.equal('1.0.0'); - }); - it('bid request check: bidfloor check', function() { - const requestClone = utils.deepClone(request); - let bRequest = spec.buildRequests(requestClone); - let data = JSON.parse(bRequest.data); - expect(data.imp[0].bidfloor).to.not.exist; - - requestClone[0].params.bidfloor = 0; - bRequest = spec.buildRequests(requestClone); - data = JSON.parse(bRequest.data); - expect(data.imp[0].bidfloor).to.equal(0); - - requestClone[0].params.bidfloor = 1.2; - bRequest = spec.buildRequests(requestClone); - data = JSON.parse(bRequest.data); - expect(data.imp[0].bidfloor).to.equal(1.2); - }); - it('bid request check: user object check', function () { - const bRequest = spec.buildRequests(request); - const data = JSON.parse(bRequest.data); - expect(data.user).to.be.a('object'); - expect(data.user.id).to.equal('di_testuid'); - expect(data.user.buyeruid).to.equal('di_testbuyeruid'); - expect(data.user.yob).to.equal(2002); - expect(data.user.gender).to.equal('F'); - }); - it('bid request check: CCPA Check', function () { - const bidRequest = { - uspConsent: '1NYN' - }; - const bRequest = spec.buildRequests(request, bidRequest); - const data = JSON.parse(bRequest.data); - expect(data.regs.ext.us_privacy).to.equal('1NYN'); - const bidRequest2 = {}; - const bRequest2 = spec.buildRequests(request, bidRequest2); - const data2 = JSON.parse(bRequest2.data); - expect(data2.regs).to.equal(undefined); - }); - it('bid Request check: GDPR Check', function () { - const bidRequest = { - gdprConsent: { - consentString: 'kjfdnidasd123sadsd', - gdprApplies: true - } - }; - const bRequest = spec.buildRequests(request, bidRequest); - const data = JSON.parse(bRequest.data); - expect(data.user.ext.consent).to.equal('kjfdnidasd123sadsd'); - expect(data.regs.ext.gdpr).to.equal(1); - const bidRequest2 = {}; - const bRequest2 = spec.buildRequests(request, bidRequest2); - const data2 = JSON.parse(bRequest2.data); - expect(data2.regs).to.equal(undefined); - expect(data2.user.ext).to.equal(undefined); - }); - it('bid request check: Video params check ', function() { - const bRequest = spec.buildRequests(videoBidRequests); - const data = JSON.parse(bRequest.data); - expect(data.imp[0].video).to.be.a('object'); - expect(data.imp[0].video.minduration).to.be.a('number'); - expect(data.imp[0].video.maxduration).to.be.a('number'); - expect(data.imp[0].video.startdelay).to.be.a('number'); - expect(data.imp[0].video.playbackmethod).to.be.an('array'); - expect(data.imp[0].video.api).to.be.an('array'); - expect(data.imp[0].video.protocols).to.be.an('array'); - expect(data.imp[0].video.battr).to.be.an('array'); - expect(data.imp[0].video.minbitrate).to.be.a('number'); - expect(data.imp[0].video.maxbitrate).to.be.a('number'); - expect(data.imp[0].video.w).to.be.a('number'); - }); - it('bid request param check : invalid video params', function() { - const bRequest = spec.buildRequests(videoBidRequests); - const data = JSON.parse(bRequest.data); - expect(data.imp[0].video).to.be.a('object'); - expect(data.imp[0].video.testwrongparam).to.equal(undefined); - expect(data.imp[0].video.testwrongparam1).to.equal(undefined); - }); - }); - describe('user sync check', function () { - it('user sync url check', function () { - const syncOptions = { - iframeEnabled: true - }; - const userSync = spec.getUserSyncs(syncOptions); - expect(userSync).to.be.an('array').with.length.above(0); - expect(userSync[0].type).to.equal('iframe'); - expect(userSync[0].url).to.equal('https://cdn.deepintent.com/syncpixel.html'); - }); - }); - describe('response check', function () { - it('bid response check: valid bid response', function () { - const bRequest = spec.buildRequests(request); - const data = JSON.parse(bRequest.data); - const bResponse = spec.interpretResponse(bannerResponse, request); - expect(bResponse).to.be.an('array').with.length.above(0); - expect(bResponse[0].requestId).to.equal(bannerResponse.body.seatbid[0].bid[0].impid); - expect(bResponse[0].width).to.equal(bannerResponse.body.seatbid[0].bid[0].w); - expect(bResponse[0].height).to.equal(bannerResponse.body.seatbid[0].bid[0].h); - expect(bResponse[0].currency).to.equal('USD'); - expect(bResponse[0].netRevenue).to.equal(false); - expect(bResponse[0].mediaType).to.equal('banner'); - expect(bResponse[0].meta.advertiserDomains).to.deep.equal(['deepintent.com']); - expect(bResponse[0].ttl).to.equal(300); - expect(bResponse[0].creativeId).to.equal(bannerResponse.body.seatbid[0].bid[0].crid); - expect(bResponse[0].dealId).to.equal(bannerResponse.body.seatbid[0].bid[0].dealId); - }); - it('bid response check: valid video bid response', function() { - const request = spec.buildRequests(videoBidRequests); - const response = spec.interpretResponse(videoBidResponse, request); - expect(response[0].mediaType).to.equal('video'); - expect(response[0].vastXml).to.not.equal(undefined); - }); - it('invalid bid response check ', function() { - const bRequest = spec.buildRequests(request); - const response = spec.interpretResponse(invalidResponse, bRequest); - expect(response[0].mediaType).to.equal(undefined); - }); - it('invalid bid response check ', function() { - const bRequest = spec.buildRequests(videoBidRequests); - const response = spec.interpretResponse(invalidResponse, bRequest); - expect(response[0].mediaType).to.equal(undefined); - }); - }); - describe('GPP and coppa', function() { - it('Request params check with GPP Consent', function () { - const bidderReq = {gppConsent: {gppString: 'gpp-string-test', applicableSections: [5]}}; - const bRequest = spec.buildRequests(request, bidderReq); - const data = JSON.parse(bRequest.data); - expect(data.regs.gpp).to.equal('gpp-string-test'); - expect(data.regs.gpp_sid[0]).to.equal(5); - }); - it('Request params check with GPP Consent read from ortb2', function () { - const bidderReq = { - ortb2: { - regs: { - gpp: 'gpp-test-string', - gpp_sid: [5] - } - } - }; - const bRequest = spec.buildRequests(request, bidderReq); - const data = JSON.parse(bRequest.data); - expect(data.regs.gpp).to.equal('gpp-test-string'); - expect(data.regs.gpp_sid[0]).to.equal(5); - }); - it('should include coppa flag in bid request if coppa is set to true', () => { - const bidderReq = {ortb2: {regs: {coppa: 1}}}; - const bRequest = spec.buildRequests(request, bidderReq); - const data = JSON.parse(bRequest.data); - expect(data.regs.coppa).to.equal(1); - }); - }); - describe('deals functionality', function() { - it('should add PMP deals when valid deals array is provided', function() { - const requestWithDeals = [{ - bidder: 'deepintent', - bidId: 'test-bid-id', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - tagId: '100013', - deals: ['deal1234', 'deal5678'] - } - }]; - - const bRequest = spec.buildRequests(requestWithDeals); - const data = JSON.parse(bRequest.data); - - expect(data.imp[0].pmp).to.be.an('object'); - expect(data.imp[0].pmp.private_auction).to.equal(0); - expect(data.imp[0].pmp.deals).to.be.an('array').with.length(2); - expect(data.imp[0].pmp.deals[0].id).to.equal('deal1234'); - expect(data.imp[0].pmp.deals[1].id).to.equal('deal5678'); - }); - - it('should filter out invalid deal IDs and handle edge cases', function() { - const requestWithMixedDeals = [{ - bidder: 'deepintent', - bidId: 'test-bid-id', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - tagId: '100013', - deals: ['abc', 'valid_deal', 12345, null, 'xy'] - } - }]; - - const bRequest = spec.buildRequests(requestWithMixedDeals); - const data = JSON.parse(bRequest.data); - - expect(data.imp[0].pmp.deals).to.be.an('array').with.length(1); - expect(data.imp[0].pmp.deals[0].id).to.equal('valid_deal'); - }); - - it('should not add pmp when deals is not a valid array', function() { - const requestWithInvalidDeals = [{ - bidder: 'deepintent', - bidId: 'test-bid-id', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - tagId: '100013', - deals: 'not-an-array' - } - }]; - - const bRequest = spec.buildRequests(requestWithInvalidDeals); - const data = JSON.parse(bRequest.data); - - expect(data.imp[0].pmp).to.be.undefined; - }); - - it('should add and clean deal custom targeting', function() { - const requestWithDctr = [{ - bidder: 'deepintent', - bidId: 'test-bid-id', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - tagId: '100013', - dctr: ' key1=val1 | key2=val2 | | key3=val3 ' - } - }]; - - const bRequest = spec.buildRequests(requestWithDctr); - const data = JSON.parse(bRequest.data); - - expect(data.imp[0].ext.key_val).to.equal('key1=val1|key2=val2|key3=val3'); - }); - - it('should handle both deals and dctr together', function() { - const requestWithBoth = [{ - bidder: 'deepintent', - bidId: 'test-bid-id', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - tagId: '100013', - deals: ['deal1234'], - dctr: 'key1=val1|key2=val2' - } - }]; - - const bRequest = spec.buildRequests(requestWithBoth); - const data = JSON.parse(bRequest.data); - - expect(data.imp[0].pmp.deals[0].id).to.equal('deal1234'); - expect(data.imp[0].ext.key_val).to.equal('key1=val1|key2=val2'); - }); - }); -}); diff --git a/test/spec/modules/deltaprojectsBidAdapter_spec.js b/test/spec/modules/deltaprojectsBidAdapter_spec.js deleted file mode 100644 index 30f709f0a..000000000 --- a/test/spec/modules/deltaprojectsBidAdapter_spec.js +++ /dev/null @@ -1,394 +0,0 @@ -import { expect } from 'chai'; -import { - BIDDER_CODE, - BIDDER_ENDPOINT_URL, - spec, USERSYNC_URL, - getBidFloor -} from 'modules/deltaprojectsBidAdapter.js'; - -const BID_REQ_REFER = 'http://example.com/page?param=val'; -const BID_REQ_DOMAIN = 'example.com' - -describe('deltaprojectsBidAdapter', function() { - describe('isBidRequestValid', function () { - function makeBid() { - return { - bidder: BIDDER_CODE, - params: { - publisherId: '12345' - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250], - ], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - }; - } - - it('should return true when bidder set correctly', function () { - expect(spec.isBidRequestValid(makeBid())).to.equal(true); - }); - - it('should return false when bid request is null', function () { - expect(spec.isBidRequestValid(undefined)).to.equal(false); - }); - - it('should return false when publisher id is not set', function () { - const bid = makeBid(); - delete bid.params.publisherId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const BIDREQ = { - bidder: BIDDER_CODE, - params: { - tagId: '403370', - siteId: 'example.com', - }, - sizes: [ - [300, 250], - ], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - } - const bidRequests = [BIDREQ]; - const bannerRequest = spec.buildRequests(bidRequests, {refererInfo: { page: BID_REQ_REFER, domain: BID_REQ_DOMAIN }})[0]; - const bannerRequestBody = bannerRequest.data; - - it('send bid request with test tag if it is set in the param', function () { - const TEST_TAG = 1; - const bidRequest = Object.assign({}, BIDREQ, { - params: { ...BIDREQ.params, test: TEST_TAG }, - }); - const bidderRequest = { refererInfo: { referer: BID_REQ_REFER } }; - const request = spec.buildRequests([bidRequest], bidderRequest)[0]; - expect(request.data.test).to.equal(TEST_TAG); - }); - - it('send bid request with correct timeout', function () { - const TMAX = 10; - const bidderRequest = { refererInfo: { referer: BID_REQ_REFER }, timeout: TMAX }; - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.tmax).to.equal(TMAX); - }); - - it('send bid request to the correct endpoint URL', function () { - expect(bannerRequest.url).to.equal(BIDDER_ENDPOINT_URL); - }); - - it('sends bid request to our endpoint via POST', function () { - expect(bannerRequest.method).to.equal('POST'); - }); - - it('sends screen dimensions', function () { - expect(bannerRequestBody.device.w).to.equal(screen.width); - expect(bannerRequestBody.device.h).to.equal(screen.height); - }); - - it('includes the ad size in the bid request', function () { - expect(bannerRequestBody.imp[0].banner.format[0].w).to.equal(BIDREQ.sizes[0][0]); - expect(bannerRequestBody.imp[0].banner.format[0].h).to.equal(BIDREQ.sizes[0][1]); - }); - - it('sets domain and href correctly', function () { - expect(bannerRequestBody.site.domain).to.equal(BIDREQ.params.siteId); - expect(bannerRequestBody.site.page).to.equal(BID_REQ_REFER); - }); - - const gdprBidRequests = [{ - bidder: BIDDER_CODE, - params: { - tagId: '403370', - siteId: 'example.com' - }, - sizes: [ - [300, 250] - ], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475' - }]; - const consentString = 'BOJ/P2HOJ/P2HABABMAAAAAZ+A=='; - - const GDPR_REQ_REFERER = 'http://localhost:9876/' - function getGdprRequestBody(gdprApplies, consentString) { - const gdprRequest = spec.buildRequests(gdprBidRequests, { - gdprConsent: { - gdprApplies: gdprApplies, - consentString: consentString, - }, - refererInfo: { - referer: GDPR_REQ_REFERER, - }, - })[0]; - return gdprRequest.data; - } - - it('should handle gdpr applies being present and true', function() { - const gdprRequestBody = getGdprRequestBody(true, consentString); - expect(gdprRequestBody.regs.ext.gdpr).to.equal(1); - expect(gdprRequestBody.user.ext.consent).to.equal(consentString); - }) - - it('should handle gdpr applies being present and false', function() { - const gdprRequestBody = getGdprRequestBody(false, consentString); - expect(gdprRequestBody.regs.ext.gdpr).to.equal(0); - expect(gdprRequestBody.user.ext.consent).to.equal(consentString); - }) - - it('should handle gdpr applies being undefined', function() { - const gdprRequestBody = getGdprRequestBody(undefined, consentString); - expect(gdprRequestBody.regs).to.deep.equal({ext: {}}); - expect(gdprRequestBody.user.ext.consent).to.equal(consentString); - }) - - it('should handle gdpr consent being undefined', function() { - const gdprRequest = spec.buildRequests(gdprBidRequests, {refererInfo: { referer: GDPR_REQ_REFERER }})[0]; - const gdprRequestBody = gdprRequest.data; - expect(gdprRequestBody.regs).to.deep.equal({ ext: {} }); - expect(gdprRequestBody.user).to.deep.equal({ ext: {} }); - }) - }); - - describe('interpretResponse', function () { - const bidRequests = [ - { - bidder: BIDDER_CODE, - params: { - tagId: '403370', - siteId: 'example.com', - currency: 'USD', - }, - sizes: [ - [300, 250], - ], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - }, - ]; - const request = spec.buildRequests(bidRequests, {refererInfo: { referer: BID_REQ_REFER }})[0]; - function makeResponse() { - return { - body: { - id: '5e5c23a5ba71e78', - seatbid: [ - { - bid: [ - { - id: '6vmb3isptf', - crid: 'deltaprojectscreative', - impid: '322add653672f68', - price: 1.22, - adm: '', - attr: [5], - h: 90, - nurl: 'http://nurl', - w: 728, - } - ], - seat: 'MOCK' - } - ], - bidid: '5e5c23a5ba71e78', - cur: 'USD' - } - }; - } - const expectedBid = { - requestId: '322add653672f68', - cpm: 1.22, - width: 728, - height: 90, - creativeId: 'deltaprojectscreative', - dealId: null, - currency: 'USD', - netRevenue: true, - mediaType: 'banner', - ttl: 60, - ad: '
' - }; - - it('should get incorrect bid response if response body is missing', function () { - const response = makeResponse(); - delete response.body; - const result = spec.interpretResponse(response, request); - expect(result.length).to.equal(0); - }); - - it('should get incorrect bid response if id or seat id of response body is missing', function () { - const response1 = makeResponse(); - delete response1.body.id; - const result1 = spec.interpretResponse(response1, request); - expect(result1.length).to.equal(0); - - const response2 = makeResponse(); - delete response2.body.seatbid; - const result2 = spec.interpretResponse(response2, request); - expect(result2.length).to.equal(0); - }); - - it('should get the correct bid response', function () { - const result = spec.interpretResponse(makeResponse(), request); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal(expectedBid); - }); - - it('should handle a missing crid', function () { - const noCridResponse = makeResponse(); - delete noCridResponse.body.seatbid[0].bid[0].crid; - const fallbackCrid = noCridResponse.body.seatbid[0].bid[0].id; - const noCridResult = Object.assign({}, expectedBid, {'creativeId': fallbackCrid}); - const result = spec.interpretResponse(noCridResponse, request); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal(noCridResult); - }); - - it('should handle a missing nurl', function () { - const noNurlResponse = makeResponse(); - delete noNurlResponse.body.seatbid[0].bid[0].nurl; - const noNurlResult = Object.assign({}, expectedBid); - noNurlResult.ad = ''; - const result = spec.interpretResponse(noNurlResponse, request); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal(noNurlResult); - }); - - it('handles empty bid response', function () { - const response = { - body: { - id: '5e5c23a5ba71e78', - seatbid: [] - } - }; - const result = spec.interpretResponse(response, request); - expect(result.length).to.equal(0); - }); - - it('should keep custom properties', () => { - const customProperties = {test: 'a test message', param: {testParam: 1}}; - const expectedResult = Object.assign({}, expectedBid, {[spec.code]: customProperties}); - const response = makeResponse(); - response.body.seatbid[0].bid[0].ext = customProperties; - const result = spec.interpretResponse(response, request); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal(expectedResult); - }); - }); - - describe('onBidWon', function () { - const OPEN_RTB_RESP = { - body: { - id: 'abc', - seatbid: [ - { - bid: [ - { - 'id': 'abc*123*456', - 'impid': 'xxxxxxx', - 'price': 46.657196, - 'adm': '', - 'w': 300, - 'h': 250, - 'crid': 'creative0' - }] - }] - } - }; - it('should interpret server response', async function () { - const bidRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse(serverResponse, bidRequest); - expect(bids).to.be.an('array'); - const bid = bids[0]; - expect(bid).to.be.an('object'); - expect(bid.currency).to.equal('USD'); - expect(bid.cpm).to.equal(97); - expect(bid.ad).to.equal(ad) - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creativeId).to.equal('creative0'); - }); - }) - }); -}); diff --git a/test/spec/modules/eskimiBidAdapter_spec.js b/test/spec/modules/eskimiBidAdapter_spec.js deleted file mode 100644 index a6c987aa7..000000000 --- a/test/spec/modules/eskimiBidAdapter_spec.js +++ /dev/null @@ -1,307 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/eskimiBidAdapter.js'; -import * as utils from 'src/utils'; - -const BANNER_BID = { - bidder: 'eskimi', - params: { - placementId: 1003000 - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ], - }, - }, - adUnitCode: 'adUnitCode1', - bidId: 'bidId', - bidderRequestId: 'bidderRequestId', - auctionId: 'auctionId-56a2-4f71-9098-720a68f2f708', -}; - -const VIDEO_BID = { - bidder: 'eskimi', - params: { - placementId: 1003000 - }, - mediaTypes: { - video: { - context: 'outstream', - api: [1, 2, 4, 6], - mimes: ['video/mp4'], - playbackmethod: [2, 4, 6], - playerSize: [[1024, 768]], - protocols: [3, 4, 7, 8, 10], - plcmt: 1, - minduration: 0, - maxduration: 60, - startdelay: 0 - }, - }, - adUnitCode: 'adUnitCode1', - bidId: 'bidId', - bidderRequestId: 'bidderRequestId', - auctionId: 'auctionId-56a2-4f71-9098-720a68f2f708', -}; - -const BIDDER_REQUEST = { - auctionId: 'auctionId-56a2-4f71-9098-720a68f2f708', - bidderRequestId: 'bidderRequestId', - timeout: 3000, - refererInfo: { - page: 'https://hello-world-page.com/', - domain: 'hello-world-page.com', - ref: 'http://example-domain.com/foo', - } -}; - -const BANNER_BID_RESPONSE = { - 'id': 'bidderRequestId', - 'bidId': 'bidid', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'id', - 'impid': 'bidId', - 'price': 0.18, - 'adm': '', - 'adid': '144762342', - 'burl': 'http://0.0.0.0:8181/burl', - 'adomain': [ - 'https://dummydomain.com' - ], - 'cid': 'cid', - 'crid': 'crid', - 'iurl': 'iurl', - 'cat': [], - 'w': 300, - 'h': 250 - } - ] - } - ], - 'cur': 'USD' -}; - -const VIDEO_BID_RESPONSE = { - 'id': 'bidderRequestId', - 'bidid': 'bidid', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'id', - 'impid': 'bidId', - 'price': 1.09, - 'adid': '144762342', - 'burl': 'http://0.0.0.0:8181/burl', - 'adm': '', - 'adomain': [ - 'https://dummydomain.com' - ], - 'cid': 'cid', - 'crid': 'crid', - 'iurl': 'iurl', - 'cat': [], - 'h': 768, - 'w': 1024 - } - ] - } - ], - 'cur': 'USD' -}; - -describe('Eskimi bid adapter', function () { - describe('isBidRequestValid()', function () { - it('should accept request if placementId is passed', function () { - const bid = { - bidder: 'eskimi', - params: { - placementId: 123 - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should reject requests without params', function () { - const bid = { - bidder: 'eskimi', - params: {} - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when required params found', () => { - expect(spec.isBidRequestValid(BANNER_BID)).to.equal(true); - expect(spec.isBidRequestValid(VIDEO_BID)).to.equal(true); - }); - }); - - describe('buildRequests()', function () { - it('should have gdpr data if applicable', function () { - const bid = utils.deepClone(BANNER_BID); - - const req = Object.assign({}, BIDDER_REQUEST, { - gdprConsent: { - consentString: 'consentString', - gdprApplies: true, - } - }); - const request = spec.buildRequests([bid], req)[0]; - - const payload = request.data; - expect(payload.user.ext).to.have.property('consent', req.gdprConsent.consentString); - expect(payload.regs.ext).to.have.property('gdpr', 1); - }); - - it('should properly forward ORTB blocking params', function () { - let bid = utils.deepClone(BANNER_BID); - bid = utils.mergeDeep(bid, { - params: {bcat: ['IAB1-1'], badv: ['example.com'], bapp: ['com.example']}, - mediaTypes: {banner: {battr: [1]}} - }); - - const [request] = spec.buildRequests([bid], BIDDER_REQUEST); - - expect(request).to.exist.and.to.be.an('object'); - const payload = request.data; - expect(payload).to.have.deep.property('bcat', ['IAB1-1']); - expect(payload).to.have.deep.property('badv', ['example.com']); - expect(payload).to.have.deep.property('bapp', ['com.example']); - expect(payload.imp[0].banner).to.have.deep.property('battr', [1]); - }); - - context('when mediaType is banner', function () { - it('should build correct request for banner bid with both w, h', () => { - const bid = utils.deepClone(BANNER_BID); - - const [request] = spec.buildRequests([bid], BIDDER_REQUEST); - const requestData = request.data; - - expect(requestData.imp[0].banner.w).to.equal(300); - expect(requestData.imp[0].banner.h).to.equal(250); - }); - - it('should create request data', function () { - const bid = utils.deepClone(BANNER_BID); - - const [request] = spec.buildRequests([bid], BIDDER_REQUEST); - expect(request).to.exist.and.to.be.a('object'); - const payload = request.data; - expect(payload.imp[0]).to.have.property('id', bid.bidId); - }); - }); - - context('when mediaType is video', function () { - it('should return false when there is no video in mediaTypes', () => { - const bid = utils.deepClone(VIDEO_BID); - delete bid.mediaTypes.video; - - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should reutrn false if player size is not set', () => { - const bid = utils.deepClone(VIDEO_BID); - delete bid.mediaTypes.video.playerSize; - - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should use bidder video params if they are set', () => { - const videoBidWithParams = utils.deepClone(VIDEO_BID); - const bidderVideoParams = { - api: [1, 2], - mimes: ['video/mp4', 'video/x-flv'], - playbackmethod: [3, 4], - protocols: [5, 6], - plcmt: 1, - minduration: 0, - maxduration: 60, - w: 1024, - h: 768, - startdelay: 0 - }; - - videoBidWithParams.params.video = bidderVideoParams; - - const requests = spec.buildRequests([videoBidWithParams], BIDDER_REQUEST); - const request = requests[0].data; - - expect(request.imp[0]).to.deep.include({ - video: { - ...bidderVideoParams, - w: videoBidWithParams.mediaTypes.video.playerSize[0][0], - h: videoBidWithParams.mediaTypes.video.playerSize[0][1], - }, - }); - }); - }); - }); - - describe('interpretResponse()', function () { - context('when mediaType is banner', function () { - it('should correctly interpret valid banner response', function () { - const bid = utils.deepClone(BANNER_BID); - const [request] = spec.buildRequests([bid], BIDDER_REQUEST); - const response = utils.deepClone(BANNER_BID_RESPONSE); - - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.be.an('array').that.is.not.empty; - - expect(bids[0].mediaType).to.equal('banner'); - expect(bids[0].burl).to.equal(BANNER_BID_RESPONSE.seatbid[0].bid[0].burl); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].requestId).to.equal(BANNER_BID_RESPONSE.seatbid[0].bid[0].impid); - expect(bids[0].cpm).to.equal(BANNER_BID_RESPONSE.seatbid[0].bid[0].price); - expect(bids[0].width).to.equal(BANNER_BID_RESPONSE.seatbid[0].bid[0].w); - expect(bids[0].height).to.equal(BANNER_BID_RESPONSE.seatbid[0].bid[0].h); - expect(bids[0].ad).to.equal(BANNER_BID_RESPONSE.seatbid[0].bid[0].adm); - expect(bids[0].creativeId).to.equal(BANNER_BID_RESPONSE.seatbid[0].bid[0].crid); - expect(bids[0].meta.advertiserDomains[0]).to.equal('https://dummydomain.com'); - expect(bids[0].ttl).to.equal(30); - expect(bids[0].netRevenue).to.equal(true); - }); - - it('should handle empty bid response', function () { - const bid = utils.deepClone(BANNER_BID); - - const request = spec.buildRequests([bid], BIDDER_REQUEST)[0]; - const EMPTY_RESP = Object.assign({}, BANNER_BID_RESPONSE, {'body': {}}); - const bids = spec.interpretResponse(EMPTY_RESP, request); - expect(bids).to.be.empty; - }); - }); - if (FEATURES.VIDEO) { - context('when mediaType is video', function () { - it('should correctly interpret valid instream video response', () => { - const bid = utils.deepClone(VIDEO_BID); - - const [request] = spec.buildRequests([bid], BIDDER_REQUEST); - const bids = spec.interpretResponse({body: VIDEO_BID_RESPONSE}, request); - expect(bids).to.be.an('array').that.is.not.empty; - - expect(bids[0].mediaType).to.equal('video'); - expect(bids[0].burl).to.equal(VIDEO_BID_RESPONSE.seatbid[0].bid[0].burl); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].requestId).to.equal(VIDEO_BID_RESPONSE.seatbid[0].bid[0].impid); - expect(bids[0].cpm).to.equal(VIDEO_BID_RESPONSE.seatbid[0].bid[0].price); - expect(bids[0].width).to.equal(VIDEO_BID_RESPONSE.seatbid[0].bid[0].w); - expect(bids[0].height).to.equal(VIDEO_BID_RESPONSE.seatbid[0].bid[0].h); - expect(bids[0].vastXml).to.equal(VIDEO_BID_RESPONSE.seatbid[0].bid[0].adm); - expect(bids[0].creativeId).to.equal(VIDEO_BID_RESPONSE.seatbid[0].bid[0].crid); - expect(bids[0].meta.advertiserDomains[0]).to.equal('https://dummydomain.com'); - expect(bids[0].ttl).to.equal(30); - expect(bids[0].netRevenue).to.equal(true); - }); - }); - } - }); -}); diff --git a/test/spec/modules/etargetBidAdapter_spec.js b/test/spec/modules/etargetBidAdapter_spec.js deleted file mode 100644 index c00856d4f..000000000 --- a/test/spec/modules/etargetBidAdapter_spec.js +++ /dev/null @@ -1,476 +0,0 @@ -import {assert, expect} from 'chai'; -import {spec} from 'modules/etargetBidAdapter.js'; -import { BANNER, VIDEO } from 'src/mediaTypes.js'; -import { deepClone } from 'src/utils.js'; - -describe('etarget adapter', function () { - let serverResponse, bidRequest, bidResponses; - let bids = []; - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'etarget', - 'params': { - 'refid': '55410', - 'country': '1' - } - }; - - it('should return true when required params found', function () { - assert(spec.isBidRequestValid(bid)); - }); - }); - - describe('buildRequests', function () { - it('should pass multiple bids via single request', function () { - const request = spec.buildRequests(bids); - const parsedUrl = parseUrl(request.url); - assert.lengthOf(parsedUrl.items, 7); - }); - - it('should be an object', function () { - const request = spec.buildRequests(bids); - assert.isNotNull(request.metaData); - }); - - it('should handle global request parameters', function () { - const parsedUrl = parseUrl(spec.buildRequests([bids[0]]).url); - assert.equal(parsedUrl.path, 'https://sk.search.etargetnet.com/hb'); - }); - - it('should set correct request method', function () { - const request = spec.buildRequests([bids[0]]); - assert.equal(request.method, 'POST'); - }); - - it('should attach floor param when either bid param or getFloor function exists', function () { - // let getFloorResponse = { currency: 'EUR', floor: 5 }; - let request = null; - const bidRequest = deepClone(bids[0]); - - // floor param has to be NULL - request = spec.buildRequests([bidRequest]); - assert.equal(typeof request.floors, 'undefined'); - }); - - it('should correctly form bid items', function () { - const bidList = bids; - const request = spec.buildRequests(bidList); - const parsedUrl = parseUrl(request.url); - assert.deepEqual(parsedUrl.items, [ - { - refid: '1', - country: '1', - transactionId: '5f33781f-9552-4ca1', - url: 'some// there' - }, - { - refid: '2', - country: '1', - someVar: 'someValue', - pt: 'gross', - transactionId: '5f33781f-9552-4iuy' - }, - { - refid: '3', - country: '1', - pdom: 'home', - transactionId: '5f33781f-9552-7ev3' - }, - { - refid: '3', - country: '1', - pdom: 'home', - transactionId: '5f33781f-9552-7ev3' - }, - { - refid: '3', - country: '1', - pdom: 'home', - transactionId: '5f33781f-9552-7ev3' - }, - { - refid: '5', - country: '1', - pt: 'net', - transactionId: '5f33781f-9552-7ev3', - }, - { - refid: '6', - country: '1', - pt: 'gross', - transactionId: '5f33781f-9552-7ev3' - } - ]); - }); - - it('should not change original validBidRequests object', function () { - var resultBids = JSON.parse(JSON.stringify(bids[0])); - const request = spec.buildRequests([bids[0]]); - assert.deepEqual(resultBids, bids[0]); - }); - - describe('gdpr', function () { - it('should send GDPR Consent data to etarget if gdprApplies', function () { - const resultBids = JSON.parse(JSON.stringify(bids[0])); - const request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: true, consentString: 'concentDataString'}}); - const parsedUrl = parseUrl(request.url).query; - - assert.equal(parsedUrl.gdpr, 'true'); - assert.equal(parsedUrl.gdpr_consent, 'concentDataString'); - }); - - it('should not send GDPR Consent data to etarget if gdprApplies is false or undefined', function () { - const resultBids = JSON.parse(JSON.stringify(bids[0])); - let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: false, consentString: 'concentDataString'}}); - const parsedUrl = parseUrl(request.url).query; - - assert.ok(!parsedUrl.gdpr); - assert.ok(!parsedUrl.gdpr_consent); - - request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: undefined, consentString: 'concentDataString'}}); - assert.ok(!parsedUrl.gdpr); - assert.ok(!parsedUrl.gdpr_consent); - }); - - it('should return GDPR Consent data with request data', function () { - let request = spec.buildRequests([bids[0]], {gdprConsent: {gdprApplies: true, consentString: 'concentDataString'}}); - - assert.deepEqual(request.gdpr, { - gdpr: true, - gdpr_consent: 'concentDataString' - }); - - request = spec.buildRequests([bids[0]]); - assert.ok(!request.gdpr); - }); - }); - }); - - describe('interpretResponse', function () { - it('should respond with empty response when there is empty serverResponse', function () { - const result = spec.interpretResponse({ body: {} }, {}); - assert.deepEqual(result, []); - }); - it('should respond with empty response when response from server is not banner', function () { - serverResponse.body[0].response = 'not banner'; - serverResponse.body = [serverResponse.body[0]]; - bidRequest.bids = [bidRequest.bids[0]]; - const result = spec.interpretResponse(serverResponse, bidRequest); - - assert.deepEqual(result, []); - }); - it('should interpret server response correctly with one bid', function () { - serverResponse.body = [serverResponse.body[0]]; - bidRequest.bids = [bidRequest.bids[0]]; - const result = spec.interpretResponse(serverResponse, bidRequest)[0]; - - assert.equal(result.requestId, '2a0cf4e'); - assert.equal(result.cpm, 13.9); - assert.equal(result.width, 300); - assert.equal(result.height, 250); - assert.equal(result.currency, 'EUR'); - assert.equal(result.netRevenue, true); - assert.isNotNull(result.reason); - assert.equal(result.ttl, 360); - assert.equal(result.ad, ''); - }); - - it('should set correct netRevenue', function () { - serverResponse.body = [serverResponse.body[0]]; - bidRequest.bids = [bidRequest.bids[1]]; - bidRequest.netRevenue = 'net'; - const result = spec.interpretResponse(serverResponse, bidRequest)[0]; - - assert.equal(result.netRevenue, true); - }); - - it('should create bid response item for every requested item', function () { - const result = spec.interpretResponse(serverResponse, bidRequest); - assert.lengthOf(result, 5); - }); - - it('should create bid response with vast xml', function () { - const result = spec.interpretResponse(serverResponse, bidRequest)[3]; - assert.equal(result.vastXml, ''); - }); - - it('should create bid response with vast url', function () { - const result = spec.interpretResponse(serverResponse, bidRequest)[4]; - assert.equal(result.vastUrl, 'vast://url'); - }); - - it('should set mediaType on bid response', function () { - const expected = [ BANNER, BANNER, BANNER, VIDEO, VIDEO ]; - const result = spec.interpretResponse(serverResponse, bidRequest); - for (let i = 0; i < result.length; i++) { - assert.equal(result[i].mediaType, expected[i]); - } - }); - - it('should set default netRevenue as gross', function () { - bidRequest.netRevenue = 'gross'; - const result = spec.interpretResponse(serverResponse, bidRequest); - for (let i = 0; i < result.length; i++) { - assert.equal(result[i].netRevenue, true); - } - }); - - it('should set gdpr if it exist in bidRequest', function () { - bidRequest.gdpr = { - gdpr: true, - gdpr_consent: 'ERW342EIOWT34234KMGds' - }; - let result = spec.interpretResponse(serverResponse, bidRequest); - for (let i = 0; i < result.length; i++) { - assert.equal(result[i].gdpr, true); - assert.equal(result[i].gdpr_consent, 'ERW342EIOWT34234KMGds'); - }; - - bidRequest.gdpr = undefined; - result = spec.interpretResponse(serverResponse, bidRequest); - for (let i = 0; i < result.length; i++) { - assert.ok(!result[i].gdpr); - assert.ok(!result[i].gdpr_consent); - }; - }); - - describe('verifySizes', function () { - it('should respond with empty response when sizes doesn\'t match', function () { - serverResponse.body[0].response = 'banner'; - serverResponse.body[0].width = 100; - serverResponse.body[0].height = 150; - - serverResponse.body = [serverResponse.body[0]]; - bidRequest.bids = [bidRequest.bids[0]]; - const result = spec.interpretResponse(serverResponse, bidRequest); - - assert.equal(serverResponse.body.length, 1); - assert.equal(serverResponse.body[0].response, 'banner'); - assert.deepEqual(result, []); - }); - it('should respond with empty response when sizes as a strings doesn\'t match', function () { - serverResponse.body[0].response = 'banner'; - serverResponse.body[0].width = 100; - serverResponse.body[0].height = 150; - - serverResponse.body = [serverResponse.body[0]]; - bidRequest.bids = [bidRequest.bids[0]]; - - bidRequest.bids[0].sizes = [['101', '150']]; - const result = spec.interpretResponse(serverResponse, bidRequest); - - assert.equal(serverResponse.body.length, 1); - assert.equal(serverResponse.body[0].response, 'banner'); - assert.deepEqual(result, []); - }); - it('should support size dimensions as a strings', function () { - serverResponse.body[0].response = 'banner'; - serverResponse.body[0].width = 300; - serverResponse.body[0].height = 600; - - serverResponse.body = [serverResponse.body[0]]; - bidRequest.bids = [bidRequest.bids[0]]; - - bidRequest.bids[0].sizes = [['300', '250'], ['250', '300'], ['300', '600'], ['600', '300']] - const result = spec.interpretResponse(serverResponse, bidRequest); - - assert.equal(result[0].width, 300); - assert.equal(result[0].height, 600); - }); - }) - }); - - beforeEach(function () { - const sizes = [[250, 300], [300, 250], [300, 600]]; - const placementCode = ['div-01', 'div-02', 'div-03', 'div-04', 'div-05']; - const params = [{refid: 1, country: 1, url: 'some// there'}, {refid: 2, country: 1, someVar: 'someValue', pt: 'gross'}, {refid: 3, country: 1, pdom: 'home'}, {refid: 5, country: 1, pt: 'net'}, {refid: 6, country: 1, pt: 'gross'}]; - bids = [ - { - adUnitCode: placementCode[0], - auctionId: '7aefb970-2045', - bidId: '2a0cf4e', - bidder: 'etarget', - bidderRequestId: '1ab8d9', - params: params[0], - tid: 45, - placementCode: placementCode[0], - sizes: [[300, 250], [250, 300], [300, 600], [600, 300]], - ortb2Imp: { - ext: { - tid: '5f33781f-9552-4ca1' - } - } - }, - { - adUnitCode: placementCode[1], - auctionId: '7aefb970-2045', - bidId: '2a0cf5b', - bidder: 'etarget', - bidderRequestId: '1ab8d9', - params: params[1], - placementCode: placementCode[1], - sizes: [[300, 250], [250, 300], [300, 600], [600, 300]], - ortb2Imp: { - ext: { - tid: '5f33781f-9552-4iuy' - } - } - }, - { - adUnitCode: placementCode[2], - auctionId: '7aefb970-2045', - bidId: '2a0cf6n', - bidder: 'etarget', - bidderRequestId: '1ab8d9', - params: params[2], - placementCode: placementCode[2], - sizes: [[300, 250], [250, 300], [300, 600], [600, 300]], - ortb2Imp: { - ext: { - tid: '5f33781f-9552-7ev3' - } - } - }, - { - adUnitCode: placementCode[3], - auctionId: '7aefb970-2045', - bidId: '2a0cf6n', - bidder: 'etarget', - bidderRequestId: '1ab8d9', - params: params[2], - placementCode: placementCode[2], - sizes: [], - ortb2Imp: { - ext: { - tid: '5f33781f-9552-7ev3' - } - } - }, - { - adUnitCode: placementCode[4], - auctionId: '7aefb970-2045', - bidId: '2a0cf6n', - bidder: 'etarget', - bidderRequestId: '1ab8d9', - params: params[2], - placementCode: placementCode[2], - sizes: [], - ortb2Imp: { - ext: { - tid: '5f33781f-9552-7ev3' - } - } - }, - { - adUnitCode: placementCode[4], - auctionId: '7aefb970-2045', - bidId: '2a0cf6n', - bidder: 'etarget', - bidderRequestId: '1ab8d9', - params: params[3], - placementCode: placementCode[2], - sizes: [], - ortb2Imp: { - ext: { - tid: '5f33781f-9552-7ev3' - } - } - }, - { - adUnitCode: placementCode[4], - auctionId: '7aefb970-2045', - bidId: '2a0cf6n', - bidder: 'etarget', - bidderRequestId: '1ab8d9', - params: params[4], - placementCode: placementCode[2], - sizes: [], - ortb2Imp: { - ext: { - tid: '5f33781f-9552-7ev3' - } - } - } - ]; - serverResponse = { - body: [ - { - banner: '', - deal_id: '123abc', - height: 250, - response: 'banner', - width: 300, - win_bid: 13.9, - win_cur: 'EUR' - }, - { - banner: '', - deal_id: '123abc', - height: 300, - response: 'banner', - width: 250, - win_bid: 13.9, - win_cur: 'EUR' - }, - { - banner: '', - deal_id: '123abc', - height: 300, - response: 'banner', - width: 600, - win_bid: 10, - win_cur: 'EUR' - }, - { - deal_id: '123abc', - height: 300, - response: 'video', - width: 600, - win_bid: 10, - win_cur: 'EUR', - vast_content: '' - }, - { - deal_id: '123abc', - height: 300, - response: 'video', - width: 600, - win_bid: 10, - win_cur: 'EUR', - vast_link: 'vast://url' - } - ], - headers: {} - }; - bidRequest = { - bidder: 'etarget', - bids: bids, - method: 'POST', - url: 'url', - netRevenue: 'net' - }; - }); -}); - -function parseUrl(url) { - const parts = url.split('/'); - const query = parts.pop().split('&'); - return { - path: parts.join('/'), - items: query - .filter((i) => !~i.indexOf('=')) - .map((i) => atob(decodeURIComponent(i)) - .split('&') - .reduce(toObject, {})), - query: query - .filter((i) => ~i.indexOf('=')) - .map((i) => i.replace('?', '')) - .reduce(toObject, {}) - }; -} - -function toObject(cache, string) { - const keyValue = string.split('='); - cache[keyValue[0]] = keyValue[1]; - return cache; -} diff --git a/test/spec/modules/exadsBidAdapter_spec.js b/test/spec/modules/exadsBidAdapter_spec.js deleted file mode 100644 index ca24dad39..000000000 --- a/test/spec/modules/exadsBidAdapter_spec.js +++ /dev/null @@ -1,632 +0,0 @@ -import { expect } from 'chai'; -import { spec, imps } from 'modules/exadsBidAdapter.js'; -import { BANNER, NATIVE, VIDEO } from '../../../src/mediaTypes.js'; - -describe('exadsBidAdapterTest', function () { - const bidder = 'exads'; - - const partners = { - ORTB_2_4: 'ortb_2_4' - }; - - const imageBanner = { - mediaTypes: { - banner: { - sizes: [300, 250] - } - }, - bidder: bidder, - params: { - zoneId: 5147485, - fid: '829a896f011475d505a0d89cfdd1af8d9cdb07ff', - partner: partners.ORTB_2_4, - siteId: '12345', - siteName: 'your-site.com', - catIab: ['IAB25-3'], - userIp: '0.0.0.0', - userId: '', - country: 'IRL', - impressionId: '123456', - keywords: 'lifestyle, humour', - bidfloor: 0.00000011, - bidfloorcur: 'EUR', - bcat: ['IAB25', 'IAB7-39', 'IAB8-18', 'IAB8-5', 'IAB9-9'], - badv: ['first.com', 'second.com'], - mimes: ['image/jpg'], - endpoint: 'test.com', - dsa: { - dsarequired: 3, - pubrender: 0, - datatopub: 2 - }, - } - }; - - const native = { - mediaTypes: { - native: { - ortb: { - assets: [{ - id: 3, - required: 1, - title: { - len: 124 - } - }, - { - id: 2, - data: { - type: 1, - len: 50 - } - }, - { - id: 1, - required: 1, - img: { - type: 3, - w: 300, - h: 300, - } - }] - } - }, - }, - bidder: bidder, - params: { - zoneId: 5147485, - fid: '829a896f011475d505a0d89cfdd1af8d9cdb07ff', - partner: partners.ORTB_2_4, - siteId: '12345', - siteName: 'your-site.com', - catIab: ['IAB25-3'], - userIp: '0.0.0.0', - userId: '', - country: 'IRL', - impressionId: '123456', - keywords: 'lifestyle, humour', - bidfloor: 0.00000011, - bidfloorcur: 'EUR', - native: { - plcmtcnt: 4, - }, - dsa: { - pubrender: 0, - datatopub: 2 - }, - endpoint: 'test.com' - } - }; - - const instream = { - mediaTypes: { - video: { - mimes: ['video/mp4'], - protocols: [3, 6], - } - }, - bidder: bidder, - params: { - zoneId: 5147485, - fid: '829a896f011475d505a0d89cfdd1af8d9cdb07ff', - partner: partners.ORTB_2_4, - siteId: '12345', - siteName: 'your-site.com', - catIab: ['IAB25-3'], - userIp: '0.0.0.0', - userId: '', - country: 'IRL', - impressionId: '123456', - keywords: 'lifestyle, humour', - bidfloor: 0.00000011, - bidfloorcur: 'EUR', - imp: { - ext: { - video_cta: 0 - } - }, - dsa: { - datatopub: 2 - }, - endpoint: 'test.com', - } - }; - - describe('while validating bid request', function () { - it('should check the validity of bidRequest with all mandatory params for banner ad-format', function () { - expect(spec.isBidRequestValid(imageBanner)).to.equal(true); - }); - - it('should check the validity of a bidRequest with all mandatory params for native ad-format', function () { - expect(spec.isBidRequestValid(native)); - }); - - it('should check the validity of a bidRequest with all mandatory params for instream ad-format', function () { - expect(spec.isBidRequestValid(instream)).to.equal(true); - }); - - it('should check the validity of a bidRequest with wrong partner', function () { - expect(spec.isBidRequestValid({ - ...imageBanner, - params: { - ...imageBanner.params, - partner: 'not_ortb_2_4' - } - })).to.eql(false); - }); - - it('should check the validity of a bidRequest without params', function () { - expect(spec.isBidRequestValid({ - bidder: bidder, - params: { } - })).to.equal(false); - }); - }); - - describe('while building bid request for banner ad-format', function () { - const bidRequests = [imageBanner]; - - it('should make a bidRequest by HTTP method', function () { - const requests = spec.buildRequests(bidRequests, {}); - requests.forEach(function(requestItem) { - expect(requestItem.method).to.equal('POST'); - }); - }); - }); - - describe('while building bid request for native ad-format', function () { - const bidRequests = [native]; - - it('should make a bidRequest by HTTP method', function () { - const requests = spec.buildRequests(bidRequests, {}); - requests.forEach(function(requestItem) { - expect(requestItem.method).to.equal('POST'); - }); - }); - }); - - describe('while building bid request for instream ad-format', function () { - const bidRequests = [instream]; - - it('should make a bidRequest by HTTP method', function () { - const requests = spec.buildRequests(bidRequests, {}); - requests.forEach(function(requestItem) { - expect(requestItem.method).to.equal('POST'); - }); - }); - }); - - describe('while interpreting bid response', function () { - beforeEach(() => { - imps.set('270544423272657', { adPartner: 'ortb_2_4', mediaType: null }); - }); - - it('should test the banner interpretResponse', function () { - const serverResponse = { - body: { - 'id': '2d2a496527398e', - 'seatbid': [ - { - 'bid': [ - { - 'id': '8f7fa506af97bc193e7bf099d8ed6930bd50aaf1', - 'impid': '270544423272657', - 'price': 0.0045000000000000005, - 'adm': '\n\n', - 'ext': { - 'btype': 1, - 'asset_mime_type': [ - 'image/jpeg', - 'image/jpg' - ] - }, - 'nurl': 'http://your-ad-network.com/', - 'cid': '6260389', - 'crid': '89453173', - 'adomain': [ - 'test.com' - ], - 'w': 300, - 'h': 250, - 'attr': [ - 12 - ] - } - ] - } - ], - 'cur': 'USD' - } - }; - - const bidResponses = spec.interpretResponse(serverResponse, { - data: JSON.stringify({ - 'id': '2d2a496527398e', - 'at': 1, - 'imp': [ - { - 'id': '270544423272657', - 'bidfloor': 1.1e-7, - 'bidfloorcur': 'EUR', - 'banner': { - 'w': 300, - 'h': 250 - } - } - ], - 'site': { - 'id': '12345', - 'domain': 'your-ad-network.com', - 'cat': [ - 'IAB25-3' - ], - 'page': 'https://your-ad-network.com/prebidJS-client-RTB-banner.html', - 'keywords': 'lifestyle, humour' - }, - 'device': { - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36', - 'ip': '95.233.216.174', - 'geo': { - 'country': 'ITA' - }, - 'language': 'en', - 'os': 'MacOS', - 'js': 0, - 'ext': { - 'remote_addr': '', - 'x_forwarded_for': '', - 'accept_language': 'en-GB' - } - }, - 'user': { - 'id': '' - }, - 'ext': { - 'sub': 0 - } - }) - }); - - expect(bidResponses).to.be.an('array').that.is.not.empty; - - const bid = serverResponse.body.seatbid[0].bid[0]; - const bidResponse = bidResponses[0]; - - expect(bidResponse.mediaType).to.equal(BANNER); - expect(bidResponse.width).to.equal(bid.w); - expect(bidResponse.height).to.equal(bid.h); - }); - - it('should test the native interpretResponse', function () { - const serverResponse = { - body: { - 'id': '21dea1fc6c3e1b', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'cedc93987cd4a1e08fdfe97de97482d1ecc503ee', - 'impid': '270544423272657', - 'price': 0.0045000000000000005, - 'adm': '{"native":{"link":{"url":"https:\\/\\/your-ad-network.com"},"eventtrackers":[{"event":1,"method":1,"url":"https:\\/\\/your-ad-network.com"}],"assets":[{"id":1,"title":{"text":"Title"}},{"id":2,"data":{"value":"Description"}},{"id":3,"img":{"url":"https:\\/\\/your-ad-network.com\\/32167\\/f85ee87ea23.jpg"}}]}}', - 'ext': { - 'btype': 1, - 'asset_mime_type': [ - 'image/jpeg', - 'image/jpg' - ] - }, - 'nurl': 'http://your-ad-network.com', - 'cid': '6260393', - 'crid': '89453189', - 'adomain': [ - 'test.com' - ], - 'w': 300, - 'h': 300, - 'attr': [] - } - ] - } - ], - 'cur': 'USD' - } - }; - - const bidResponses = spec.interpretResponse(serverResponse, { - data: JSON.stringify({ - 'id': '21dea1fc6c3e1b', - 'at': 1, - 'imp': [ - { - 'id': '270544423272657', - 'bidfloor': 1.1e-7, - 'bidfloorcur': 'EUR', - 'native': { - 'request': '{"native":{"ver":"1.2","context":1,"contextsubtype":10,"plcmttype":4,"plcmtcnt":4,"assets":[{"id":1,"required":1,"title":{"len":124}},{"id":2,"data":{"type":1,"len":50}},{"id":3,"required":1,"img":{"type":3,"w":300,"h":300,"wmin":300,"hmin":300}}]}}', - 'ver': '1.2' - } - } - ], - 'site': { - 'id': '12345', - 'domain': 'your-ad-network.com', - 'cat': [ - 'IAB25-3' - ], - 'page': 'https://your-ad-network.com/prebidJS-client-RTB-native.html' - }, - 'device': { - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36', - 'ip': '95.233.216.174', - 'geo': { - 'country': 'ITA' - }, - 'language': 'en', - 'os': 'MacOS', - 'js': 0, - 'ext': { - 'remote_addr': '', - 'x_forwarded_for': '', - 'accept_language': 'en-GB' - } - }, - 'user': { - 'id': '' - }, - 'ext': { - 'sub': 0 - } - }) - }); - - expect(bidResponses).to.be.an('array').that.is.not.empty; - - const bidResponse = bidResponses[0]; - - expect(bidResponse.mediaType).to.equal(NATIVE); - }); - - it('should test the InStream Video interpretResponse', function () { - const serverResponse = { - body: { - 'id': '2218abc7ebca97', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'd2d2063517b126252f56e22767c53f936ff40411', - 'impid': '270544423272657', - 'price': 0.12474000000000002, - 'adm': '\n\n \n \n your-ad-network.com\n \n \n \n \n \n \n 00:00:20.32\n \n \n \n \n \n \n \n \n \n \n \n \n test.com\n \n \n \n \n \n \n \n \n\n', - 'ext': { - 'btype': 1, - 'asset_mime_type': [ - 'video/mp4' - ] - }, - 'nurl': 'http://your-ad-network.com', - 'cid': '6260395', - 'crid': '89453191', - 'adomain': [ - 'test.com' - ], - 'w': 0, - 'h': 0, - 'attr': [] - } - ] - } - ], - 'cur': 'USD' - } - }; - - const bidResponses = spec.interpretResponse(serverResponse, { - data: JSON.stringify({ - 'id': '2218abc7ebca97', - 'at': 1, - 'imp': [ - { - 'id': '270544423272657', - 'video': { - 'mimes': [ - 'video/mp4' - ] - }, - 'protocols': [ - 3, - 6 - ], - 'ext': { - 'video_cta': 0 - } - } - ], - 'site': { - 'id': '12345', - 'domain': 'your-ad-network.com', - 'cat': [ - 'IAB25-3' - ], - 'page': 'https://your-ad-network.com/prebidJS-client-RTB-InStreamVideo.html', - 'keywords': 'lifestyle, humour' - }, - 'device': { - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36', - 'ip': '95.233.216.174', - 'geo': { - 'country': 'ITA' - }, - 'language': 'en', - 'os': 'MacOS', - 'js': 0, - 'ext': { - 'remote_addr': '', - 'x_forwarded_for': '', - 'accept_language': 'en-GB' - } - }, - 'user': { - 'id': '' - }, - 'ext': { - 'sub': 0 - } - }) - }); - - expect(bidResponses).to.be.an('array').that.is.not.empty; - - const bidResponse = bidResponses[0]; - - expect(bidResponse.mediaType).to.equal(VIDEO); - }); - }); - - describe('checking dsa information', function() { - it('should add dsa information to the request via bidderRequest.params.dsa', function () { - const bidRequests = [imageBanner]; - - const requests = spec.buildRequests(bidRequests, {}); - - requests.forEach(function(requestItem) { - const payload = JSON.parse(requestItem.data); - - expect(payload.regs.ext.dsa).to.exist; - expect(payload.regs.ext.dsa.dsarequired).to.equal(3); - expect(payload.regs.ext.dsa.pubrender).to.equal(0); - expect(payload.regs.ext.dsa.datatopub).to.equal(2); - }); - }); - - it('should test the dsa interpretResponse', function () { - const dsaResponse = { - 'behalf': '...', - 'paid': '...', - 'transparency': [ - { - 'params': [ - 2 - ] - } - ], - 'adrender': 0 - }; - - const serverResponse = { - body: { - 'id': '2d2a496527398e', - 'seatbid': [ - { - 'bid': [ - { - 'id': '8f7fa506af97bc193e7bf099d8ed6930bd50aaf1', - 'impid': '270544423272657', - 'price': 0.0045000000000000005, - 'adm': '\n\n', - 'ext': { - 'btype': 1, - 'asset_mime_type': [ - 'image/jpeg', - 'image/jpg' - ], - 'dsa': dsaResponse - }, - 'nurl': 'http://your-ad-network.com/', - 'cid': '6260389', - 'crid': '89453173', - 'adomain': [ - 'test.com' - ], - 'w': 300, - 'h': 250, - 'attr': [ - 12 - ] - } - ] - } - ], - 'cur': 'USD' - } - }; - - const bidResponses = spec.interpretResponse(serverResponse, { - data: JSON.stringify({ - 'id': '2d2a496527398e', - 'at': 1, - 'imp': [ - { - 'id': '270544423272657', - 'bidfloor': 1.1e-7, - 'bidfloorcur': 'EUR', - 'banner': { - 'w': 300, - 'h': 250 - } - } - ], - 'site': { - 'id': '12345', - 'domain': 'your-ad-network.com', - 'cat': [ - 'IAB25-3' - ], - 'page': 'https://your-ad-network.com/prebidJS-client-RTB-banner.html', - 'keywords': 'lifestyle, humour' - }, - 'device': { - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36', - 'ip': '95.233.216.174', - 'geo': { - 'country': 'ITA' - }, - 'language': 'en', - 'os': 'MacOS', - 'js': 0, - 'ext': { - 'remote_addr': '', - 'x_forwarded_for': '', - 'accept_language': 'en-GB' - } - }, - 'user': { - 'id': '' - }, - 'ext': { - 'sub': 0 - }, - 'regs': { - 'ext': { - 'dsa': { - 'dsarequired': 3, - 'pubrender': 0, - 'datatopub': 2 - } - } - } - }) - }); - - expect(bidResponses).to.be.an('array').that.is.not.empty; - const bidResponse = bidResponses[0]; - expect(bidResponse.meta).to.exist; - expect(bidResponse.meta.dsa).to.exist; - expect(bidResponse.meta.dsa).equal(dsaResponse); - }); - }); - - describe('on getting the win event', function() { - it('should not create nurl request if bid is undefined', function() { - const result = spec.onBidWon({}); - expect(result).to.be.undefined; - }); - }); - - describe('checking timeut', function () { - it('should exists and be a function', () => { - expect(spec.onTimeout).to.exist.and.to.be.a('function'); - }); - }); -}); diff --git a/test/spec/modules/excoBidAdapter_spec.js b/test/spec/modules/excoBidAdapter_spec.js deleted file mode 100644 index 986f3716d..000000000 --- a/test/spec/modules/excoBidAdapter_spec.js +++ /dev/null @@ -1,401 +0,0 @@ -import { expect } from 'chai'; -import { spec as adapter, AdapterHelpers, SID, ENDPOINT, BIDDER_CODE } from 'modules/excoBidAdapter'; -import { BANNER, VIDEO } from '../../../src/mediaTypes.js'; -import { config } from '../../../src/config.js'; -import sinon from 'sinon'; - -describe('ExcoBidAdapter', function () { - const helpers = new AdapterHelpers(); - - const BID = { - bidId: '1731e91fa1236fd', - adUnitCode: '300x250', - bidder: BIDDER_CODE, - params: { - accountId: 'accountId', - publisherId: 'publisherId', - tagId: 'tagId', - }, - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - transactionId: 'transactionId', - sizes: [[300, 250]], - bidderRequestId: '1677eaa35e64f46', - auctionId: 'auctionId', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - }; - - const BIDDER_REQUEST = { - bidderCode: BIDDER_CODE, - auctionId: 'auctionId', - bidderRequestId: '1677eaa35e64f46', - bids: [BID], - gdprConsent: { - consentString: 'consent_string', - gdprApplies: true, - }, - gppString: 'gpp_string', - gppSid: [7], - uspConsent: 'consent_string', - refererInfo: { - page: 'https://www.greatsite.com', - ref: 'https://www.somereferrer.com', - }, - ortb2: { - site: { - content: { - language: 'en', - }, - }, - device: { - w: 1309, - h: 1305, - dnt: 0, - ua: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36', - language: 'en', - sua: { - source: 1, - platform: { brand: 'Windows' }, - browsers: [ - { brand: 'Not(A:Brand', version: ['99'] }, - { brand: 'Google Chrome', version: ['133'] }, - { brand: 'Chromium', version: ['133'] }, - ], - mobile: 0, - }, - } - }, - }; - - const BID_SERVER_RESPONSE = { - body: { - ext: { - usersync: { - exco: { - status: 'none', - syncs: [ - { - url: 'https://example.com/sync.gif', - type: 'image' - }, - { - url: 'https://example.com/sync.html', - type: 'iframe' - } - ] - } - } - } - } - }; - - let BUILT_REQ = null; - - describe('isBidRequestValid', function () { - it('should return false if accountId is missing', function () { - const bid = { ...BID, params: { publisherId: 'publisherId', tagId: 'tagId' } }; - expect(adapter.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false if publisherId is missing', function () { - const bid = { ...BID, params: { accountId: 'accountId', tagId: 'tagId' } }; - expect(adapter.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false if tagId is missing', function () { - const bid = { ...BID, params: { accountId: 'accountId', publisherId: 'publisherId' } }; - expect(adapter.isBidRequestValid(bid)).to.be.false; - }); - - it('should return true if all required params are present', function () { - expect(adapter.isBidRequestValid(BID)).to.be.true; - }); - }); - - describe('buildRequests', function () { - let sandbox; - before(function () { - sandbox = sinon.createSandbox(); - sandbox.stub(Date, 'now').returns(1000); - }); - - it('should build request', function () { - config.setConfig({ - bidderTimeout: 3000, - enableTIDs: true, - }); - - const requests = adapter.buildRequests([BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - - const req = requests[0]; - expect(req.method).to.equal('POST'); - expect(req.url).to.equal(ENDPOINT); - - const ext = req.data.ext[BIDDER_CODE] || {}; - expect(ext.pbversion).to.equal('$prebid.version$'); - expect(ext.sid).to.equal(SID); - - BUILT_REQ = req; - }); - - after(function () { - sandbox.restore(); - }); - }); - - describe('interpretResponse', function () { - const SERVER_RESPONSE = { - body: { - id: 'b1ec10d0-a1af-44e5-8a85-cb7b1652fe81', - seatbid: [ - { - bid: [ - { - id: 'b7b6eddb-9924-425e-aa52-5eba56689abe', - impid: BID.bidId, - cpm: 10.56, - adm: '', - lurl: 'https://ads-ssp-stg.hit.buzz/loss?loss=${AUCTION_LOSS}&min_to_win=${AUCTION_MIN_TO_WIN}', - nurl: 'http://example.com/win/1234', - adomain: ['crest.com'], - iurl: 'https://thetradedesk-t-general.s3.amazonaws.com/AdvertiserLogos/qrr9d3g.png', - crid: 'h6bvt3rl', - w: 300, - h: 250, - mtype: 2, - creativeId: 'h6bvt3rl', - netRevenue: true, - mediaType: BANNER, - ext: { - advid: 37981, - bidtype: 1, - dspid: 377, - origbidcpm: 0, - origbidcur: 'USD', - wDSPByrId: '3000', - }, - currency: 'USD', - }, - ], - }, - ], - } - }; - - it('should return an array of interpreted banner responses', function () { - const responses = adapter.interpretResponse(SERVER_RESPONSE, BUILT_REQ); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - seatBidId: 'b7b6eddb-9924-425e-aa52-5eba56689abe', - mediaType: BANNER, - requestId: BID.bidId, - cpm: 10.56, - width: 300, - height: 250, - adapterCode: BIDDER_CODE, - bidderCode: BIDDER_CODE, - creativeId: 'h6bvt3rl', - creative_id: 'h6bvt3rl', - ttl: 3000, - eventtrackers: [], - meta: { - advertiserDomains: [ - 'crest.com' - ], - mediaType: BANNER - }, - ad: '
', - netRevenue: true, - nurl: 'http://example.com/win/1234', - currency: 'USD', - adUrl: undefined, - }); - }); - - it('should return empty array when there is no response', function () { - const responses = adapter.interpretResponse(null, BUILT_REQ); - expect(responses).to.have.length(0); - }); - - it('should return empty array when there is no ad', function () { - const responses = adapter.interpretResponse({ price: 1, ad: '' }, BUILT_REQ); - expect(responses).to.have.length(0); - }); - - it('should return empty array when there is no price', function () { - const responses = adapter.interpretResponse({ - price: null, - ad: 'great ad', - }, BUILT_REQ); - expect(responses).to.have.length(0); - }); - }); - - describe('getUserSyncs', function () { - const serverResponses = [BID_SERVER_RESPONSE]; - - it('should return empty if no server responses', function () { - const syncs = adapter.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }, []); - expect(syncs).to.deep.equal([]); - }); - - it('should return iframe only user syncs', function () { - const syncs = adapter.getUserSyncs({ iframeEnabled: true, pixelEnabled: false }, serverResponses); - expect(syncs).to.deep.equal([ - { type: 'iframe', url: 'https://example.com/sync.html' }, - ]); - }); - - it('should return pixels only user syncs', function () { - const syncs = adapter.getUserSyncs({ iframeEnabled: false, pixelEnabled: true }, serverResponses); - expect(syncs).to.deep.equal([ - { type: 'image', url: 'https://example.com/sync.gif' }, - ]); - }); - }); - - describe('onTimeout', function () { - let stubbedFetch; - const bid = { - bidder: adapter.code, - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - params: { - accountId: 'accountId', - publisherId: 'publisherId', - tagId: 'tagId', - }, - metrics: { - timeSince: () => 500, - }, - ortb2: {} - }; - - beforeEach(function() { - stubbedFetch = sinon.stub(window, 'fetch'); - }); - afterEach(function() { - stubbedFetch.restore(); - }); - - it('should exists and be a function', () => { - expect(adapter.onTimeout).to.exist.and.to.be.a('function'); - }); - - it('Should create event url', function() { - const pixelUrl = helpers.getEventUrl([bid], 'mcd_bidder_auction_timeout'); - adapter.onTimeout([bid]); - expect(stubbedFetch.calledWith(pixelUrl)).to.be.true; - }); - - it('Should trigger event url', function() { - adapter.onTimeout([bid]); - expect(stubbedFetch.callCount).to.equal(1); - }); - }); - - describe('onBidWon', function() { - let stubbedFetch; - - beforeEach(function() { - stubbedFetch = sinon.stub(window, 'fetch'); - }); - afterEach(function() { - stubbedFetch.restore(); - }); - - it('should exists and be a function', () => { - expect(adapter.onBidWon).to.exist.and.to.be.a('function'); - }); - - it('Should trigger nurl pixel', function() { - const bid = { - bidder: adapter.code, - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - nurl: 'http://example.com/win/1234', - mediaType: VIDEO, - params: { - accountId: 'accountId', - publisherId: 'publisherId', - tagId: 'tagId', - } - }; - - adapter.onBidWon(bid); - expect(stubbedFetch.callCount).to.equal(1); - }); - - it('Should trigger nurl pixel with correct parameters', function() { - const bid = { - bidder: adapter.code, - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - nurl: 'http://example.com/win/1234?ad_auction_won', - mediaType: VIDEO, - params: { - accountId: 'accountId', - publisherId: 'publisherId', - tagId: 'tagId', - } - }; - - adapter.onBidWon(bid); - - expect(stubbedFetch.callCount).to.equal(1); - expect(stubbedFetch.firstCall.args[0]).to.contain('ext_auction_won'); - }); - - it('Should not trigger pixel if no bid nurl', function() { - const bid = { - bidder: adapter.code, - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - params: { - accountId: 'accountId', - publisherId: 'publisherId', - tagId: 'tagId', - } - }; - - adapter.onBidWon(bid); - expect(stubbedFetch.callCount).to.equal(0); - }); - }); - - describe('isDebugEnabled', function () { - let originalConfig; - - beforeEach(function () { - originalConfig = config.getConfig('debug'); - }); - - afterEach(function () { - config.setConfig({ debug: originalConfig }); - }); - - it('should return true if debug is enabled in config', function () { - config.setConfig({ debug: true }); - expect(helpers.isDebugEnabled()).to.be.true; - }); - - it('should return false if debug is disabled in config', function () { - config.setConfig({ debug: false }); - expect(helpers.isDebugEnabled()).to.be.false; - }); - - it('should return true if URL contains exco_debug=true', function () { - expect(helpers.isDebugEnabled('https://example.com?exco_debug=true')).to.be.true; - }); - - it('should return false if URL does not contain exco_debug=true', function () { - expect(helpers.isDebugEnabled('https://example.com')).to.be.false; - }); - }); -}); diff --git a/test/spec/modules/experianRtdProvider_spec.js b/test/spec/modules/experianRtdProvider_spec.js deleted file mode 100644 index 556851e35..000000000 --- a/test/spec/modules/experianRtdProvider_spec.js +++ /dev/null @@ -1,365 +0,0 @@ -import { - EXPERIAN_RTID_DATA_KEY, - EXPERIAN_RTID_EXPIRATION_KEY, - EXPERIAN_RTID_STALE_KEY, - SUBMODULE_NAME, - experianRtdObj, - experianRtdSubmodule, EXPERIAN_RTID_NO_TRACK_KEY -} from '../../../modules/experianRtdProvider.js'; -import { getStorageManager } from '../../../src/storageManager.js'; -import { MODULE_TYPE_RTD } from '../../../src/activities/modules.js'; -import { safeJSONParse, timestamp } from '../../../src/utils.js'; -import {server} from '../../mocks/xhr.js'; - -describe('Experian realtime module', () => { - const sandbox = sinon.createSandbox(); - let requests; - - const storage = getStorageManager({ moduleType: MODULE_TYPE_RTD, moduleName: SUBMODULE_NAME }) - beforeEach(() => { - requests = server.requests; - storage.removeDataFromLocalStorage(EXPERIAN_RTID_DATA_KEY, null) - storage.removeDataFromLocalStorage(EXPERIAN_RTID_EXPIRATION_KEY, null) - storage.removeDataFromLocalStorage(EXPERIAN_RTID_STALE_KEY, null) - storage.removeDataFromLocalStorage(EXPERIAN_RTID_NO_TRACK_KEY, null) - }) - afterEach(() => { - sandbox.restore(); - }) - // Bid request config - const reqBidsConfigObj = { - adUnits: [{ - bids: [ - { bidder: 'appnexus' } - ] - }] - }; - describe('init', () => { - it('succeeds when params have accountId', () => { - const initResult = experianRtdSubmodule.init({ params: { accountId: 'ZylatYg' } }) - expect(initResult).to.be.true; - }) - - it('fails when params don\'t have accountId', () => { - const initResult = experianRtdSubmodule.init({ }) - expect(initResult).to.be.false; - }) - }) - - describe('getBidRequestData', () => { - describe('when local storage has data, isn\'t no track, isn\'t stale and isn\'t expired', () => { - beforeEach(() => { - const now = timestamp() - storage.setDataInLocalStorage(EXPERIAN_RTID_DATA_KEY, JSON.stringify([ - { - bidder: 'pubmatic', - data: { - key: 'pubmatic-encryption-key-1', - data: 'IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg==' - } - }, - { - bidder: 'sovrn', - data: { - key: 'sovrn-encryption-key-1', - data: 'IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg==' - } - } - ]), null) - - storage.setDataInLocalStorage(EXPERIAN_RTID_EXPIRATION_KEY, new Date(now + 100000).toISOString(), null) - storage.setDataInLocalStorage(EXPERIAN_RTID_STALE_KEY, new Date(now + 50000).toISOString(), null) - }) - it('doesn\'t request data envelope, and alters bids', () => { - const bidsConfig = { - ortb2Fragments: { - bidder: {} - } - } - const moduleConfig = { params: { accountId: 'ZylatYg', bidders: ['pubmatic', 'sovrn'] } } - const dataEnvelopeSpy = sandbox.spy(experianRtdObj, 'requestDataEnvelope') - const alterBidsSpy = sandbox.spy(experianRtdObj, 'alterBids') - experianRtdSubmodule.getBidRequestData(bidsConfig, sinon.stub, moduleConfig) - sandbox.assert.calledWithExactly(alterBidsSpy, bidsConfig, moduleConfig) - expect(dataEnvelopeSpy.called).to.be.false; - }) - }) - - describe('when local storage has data but it is stale', () => { - beforeEach(() => { - const now = timestamp() - storage.setDataInLocalStorage(EXPERIAN_RTID_DATA_KEY, JSON.stringify([ - { - bidder: 'pubmatic', - data: { - key: 'pubmatic-encryption-key-1', - data: 'IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg==' - } - }, - { - bidder: 'sovrn', - data: { - key: 'sovrn-encryption-key-1', - data: 'IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg==' - } - } - ]), null) - - storage.setDataInLocalStorage(EXPERIAN_RTID_EXPIRATION_KEY, new Date(now + 100000).toISOString(), null) - storage.setDataInLocalStorage(EXPERIAN_RTID_STALE_KEY, new Date(now - 50000).toISOString(), null) - }) - it('it requests data envelope and alters bids', () => { - const bidsConfig = { - ortb2Fragments: { - bidder: {} - } - } - const userConsent = {gdpr: {}, uspConsent: {}} - const moduleConfig = { params: { accountId: 'ZylatYg', bidders: ['pubmatic', 'sovrn'] } } - const dataEnvelopeSpy = sandbox.spy(experianRtdObj, 'requestDataEnvelope') - const alterBidsSpy = sandbox.spy(experianRtdObj, 'alterBids') - experianRtdSubmodule.getBidRequestData(bidsConfig, sinon.stub, moduleConfig, userConsent) - sandbox.assert.calledWithExactly(alterBidsSpy, bidsConfig, moduleConfig) - sandbox.assert.calledWithExactly(dataEnvelopeSpy, moduleConfig, userConsent) - }) - }) - describe('when local storage has data but it is expired', () => { - beforeEach(() => { - const now = timestamp() - storage.setDataInLocalStorage(EXPERIAN_RTID_DATA_KEY, JSON.stringify([ - { - bidder: 'pubmatic', - data: { - key: 'pubmatic-encryption-key-1', - data: 'IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg==' - } - }, - { - bidder: 'sovrn', - data: { - key: 'sovrn-encryption-key-1', - data: 'IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg==' - } - } - ]), null) - - storage.setDataInLocalStorage(EXPERIAN_RTID_EXPIRATION_KEY, new Date(now - 50000).toISOString(), null) - storage.setDataInLocalStorage(EXPERIAN_RTID_STALE_KEY, new Date(now - 100000).toISOString(), null) - }) - it('requests data envelope, and doesn\'t alter bids', () => { - const bidsConfig = { - ortb2Fragments: { - bidder: {} - } - } - const userConsent = {gdpr: {}, uspConsent: {}} - const moduleConfig = { params: { accountId: 'ZylatYg', bidders: ['pubmatic', 'sovrn'] } } - const dataEnvelopeSpy = sandbox.spy(experianRtdObj, 'requestDataEnvelope') - const alterBidsSpy = sandbox.spy(experianRtdObj, 'alterBids') - experianRtdSubmodule.getBidRequestData(bidsConfig, sinon.stub, moduleConfig, userConsent) - sandbox.assert.calledWithExactly(dataEnvelopeSpy, moduleConfig, userConsent) - expect(alterBidsSpy.called).to.be.false; - }) - }) - describe('when local storage has no data envelope', () => { - it('requests data envelope, and doesn\'t alter bids', () => { - const bidsConfig = { - ortb2Fragments: { - bidder: {} - } - } - const userConsent = {gdpr: {}, uspConsent: {}} - const moduleConfig = { params: { accountId: 'ZylatYg', bidders: ['pubmatic', 'sovrn'] } } - const dataEnvelopeSpy = sandbox.spy(experianRtdObj, 'requestDataEnvelope') - const alterBidsSpy = sandbox.spy(experianRtdObj, 'alterBids') - experianRtdSubmodule.getBidRequestData(bidsConfig, sinon.stub, moduleConfig, userConsent) - sandbox.assert.calledWithExactly(dataEnvelopeSpy, moduleConfig, userConsent) - expect(alterBidsSpy.called).to.be.false; - }) - }) - describe('when local storage has no track and is expired', () => { - beforeEach(() => { - const now = timestamp() - storage.setDataInLocalStorage(EXPERIAN_RTID_NO_TRACK_KEY, 'no_track', null) - - storage.setDataInLocalStorage(EXPERIAN_RTID_EXPIRATION_KEY, new Date(now - 50000).toISOString(), null) - storage.setDataInLocalStorage(EXPERIAN_RTID_STALE_KEY, new Date(now - 100000).toISOString(), null) - }) - it('requests data envelope, and doesn\'t alter bids', () => { - const bidsConfig = { - ortb2Fragments: { - bidder: {} - } - } - const userConsent = {gdpr: {}, uspConsent: {}} - const moduleConfig = { params: { accountId: 'ZylatYg', bidders: ['pubmatic', 'sovrn'] } } - const dataEnvelopeSpy = sandbox.spy(experianRtdObj, 'requestDataEnvelope') - const alterBidsSpy = sandbox.spy(experianRtdObj, 'alterBids') - experianRtdSubmodule.getBidRequestData(bidsConfig, sinon.stub, moduleConfig, userConsent) - sandbox.assert.calledWithExactly(dataEnvelopeSpy, moduleConfig, userConsent) - expect(alterBidsSpy.called).to.be.false; - }) - }) - - describe('when local storage has no track and is stale', () => { - beforeEach(() => { - const now = timestamp() - storage.setDataInLocalStorage(EXPERIAN_RTID_NO_TRACK_KEY, 'no_track', null) - - storage.setDataInLocalStorage(EXPERIAN_RTID_EXPIRATION_KEY, new Date(now + 100000).toISOString(), null) - storage.setDataInLocalStorage(EXPERIAN_RTID_STALE_KEY, new Date(now - 50000).toISOString(), null) - }) - it('requests data envelope, and doesn\'t alter bids', () => { - const bidsConfig = { - ortb2Fragments: { - bidder: {} - } - } - const userConsent = {gdpr: {}, uspConsent: {}} - const moduleConfig = { params: { accountId: 'ZylatYg', bidders: ['pubmatic', 'sovrn'] } } - const dataEnvelopeSpy = sandbox.spy(experianRtdObj, 'requestDataEnvelope') - const alterBidsSpy = sandbox.spy(experianRtdObj, 'alterBids') - experianRtdSubmodule.getBidRequestData(bidsConfig, sinon.stub, moduleConfig, userConsent) - sandbox.assert.calledWithExactly(dataEnvelopeSpy, moduleConfig, userConsent) - expect(alterBidsSpy.called).to.be.false; - }) - }) - - describe('when local storage has no track and isn\'t expired or stale', () => { - beforeEach(() => { - const now = timestamp() - storage.setDataInLocalStorage(EXPERIAN_RTID_NO_TRACK_KEY, 'no_track', null) - - storage.setDataInLocalStorage(EXPERIAN_RTID_EXPIRATION_KEY, new Date(now + 100000).toISOString(), null) - storage.setDataInLocalStorage(EXPERIAN_RTID_STALE_KEY, new Date(now + 50000).toISOString(), null) - }) - it('doesn\'t alter bids and doesn\'t request data envelope', () => { - const bidsConfig = { - ortb2Fragments: { - bidder: {} - } - } - const userConsent = {gdpr: {}, uspConsent: {}} - const moduleConfig = { params: { accountId: 'ZylatYg', bidders: ['pubmatic', 'sovrn'] } } - const dataEnvelopeSpy = sandbox.spy(experianRtdObj, 'requestDataEnvelope') - const alterBidsSpy = sandbox.spy(experianRtdObj, 'alterBids') - experianRtdSubmodule.getBidRequestData(bidsConfig, sinon.stub, moduleConfig, userConsent) - expect(alterBidsSpy.called).to.be.false; - expect(dataEnvelopeSpy.called).to.be.false; - }) - }) - }) - - describe('alterBids', () => { - describe('data envelope has every bidder from config', () => { - beforeEach(() => { - const now = timestamp() - storage.setDataInLocalStorage(EXPERIAN_RTID_DATA_KEY, JSON.stringify([ - { - bidder: 'pubmatic', - data: { - key: 'pubmatic-encryption-key-1', - data: 'IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg==' - } - }, - { - bidder: 'sovrn', - data: { - key: 'sovrn-encryption-key-1', - data: 'IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg==' - } - } - ]), null) - - storage.setDataInLocalStorage(EXPERIAN_RTID_EXPIRATION_KEY, new Date(now + 100000).toISOString(), null) - storage.setDataInLocalStorage(EXPERIAN_RTID_STALE_KEY, new Date(now + 50000).toISOString(), null) - }) - - it('alters bids for the bidders in the module config', () => { - const bidsConfig = { - ortb2Fragments: { - bidder: {} - } - } - const moduleConfig = { params: { accountId: 'ZylatYg', bidders: ['pubmatic'] } } - experianRtdObj.alterBids(bidsConfig, moduleConfig); - expect(bidsConfig.ortb2Fragments.bidder).to.deep.equal({pubmatic: { - experianRtidKey: 'pubmatic-encryption-key-1', - experianRtidData: 'IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg==' - }}) - }) - }) - describe('data envelope is missing bidders from config', () => { - beforeEach(() => { - const now = timestamp() - storage.setDataInLocalStorage(EXPERIAN_RTID_DATA_KEY, JSON.stringify([ - { - bidder: 'sovrn', - data: { - key: 'sovrn-encryption-key-1', - data: 'IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg==' - } - } - ]), null) - - storage.setDataInLocalStorage(EXPERIAN_RTID_EXPIRATION_KEY, new Date(now + 100000).toISOString(), null) - storage.setDataInLocalStorage(EXPERIAN_RTID_STALE_KEY, new Date(now + 50000).toISOString(), null) - }) - - it('alters bids for the bidders in the module config', () => { - const bidsConfig = { - ortb2Fragments: { - bidder: {} - } - } - const moduleConfig = { params: { accountId: 'ZylatYg', bidders: ['pubmatic', 'sovrn'] } } - experianRtdObj.alterBids(bidsConfig, moduleConfig); - expect(bidsConfig.ortb2Fragments.bidder).to.deep.equal({ - sovrn: { - experianRtidKey: 'sovrn-encryption-key-1', - experianRtidData: 'IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg==' - }}) - }) - }) - }) - - describe('requestDataEnvelope', () => { - it('sends request to experian rtd and stores response', () => { - const moduleConfig = { params: { accountId: 'ZylatYg', bidders: ['pubmatic', 'sovrn'] } } - experianRtdObj.requestDataEnvelope(moduleConfig, { gdpr: { gdprApplies: 0, consentString: 'wow' }, uspConsent: '1YYY' }) - requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - '{"staleAt":"2023-06-01T00:00:00","expiresAt":"2023-06-03T00:00:00","status":"ok","data":[{"bidder":"pubmatic","data":{"key":"pubmatic-encryption-key-1","data":"IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg=="}},{"bidder":"sovrn","data":{"key":"sovrn-encryption-key-1","data":"IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg=="}}]}' - ) - - expect(requests[0].url).to.equal('https://rtid.tapad.com/acc/ZylatYg/ids?gdpr=0&gdpr_consent=wow&us_privacy=1YYY') - expect(safeJSONParse(storage.getDataFromLocalStorage(EXPERIAN_RTID_DATA_KEY, null))).to.deep.equal([{bidder: 'pubmatic', data: {key: 'pubmatic-encryption-key-1', data: 'IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg=='}}, {bidder: 'sovrn', data: {key: 'sovrn-encryption-key-1', data: 'IkhlbGxvLCB3b3JsZC4gSGVsbG8sIHdvcmxkLiBIZWxsbywgd29ybGQuIg=='}}]) - expect(storage.getDataFromLocalStorage(EXPERIAN_RTID_STALE_KEY)).to.equal('2023-06-01T00:00:00') - expect(storage.getDataFromLocalStorage(EXPERIAN_RTID_EXPIRATION_KEY)).to.equal('2023-06-03T00:00:00') - }) - }) - - describe('extractConsentQueryString', () => { - describe('when userConsent is empty', () => { - it('returns undefined', () => { - expect(experianRtdObj.extractConsentQueryString({})).to.be.undefined - }) - }) - - describe('when userConsent exists', () => { - it('builds query string', () => { - expect( - experianRtdObj.extractConsentQueryString({}, { gdpr: { gdprApplies: 1, consentString: 'this-is-something' }, uspConsent: '1YYY' }) - ).to.equal('?gdpr=1&gdpr_consent=this-is-something&us_privacy=1YYY') - }) - }) - - describe('when config.ids exists', () => { - it('builds query string', () => { - expect(experianRtdObj.extractConsentQueryString({ params: { accountId: 'ZylatYg', ids: { maid: ['424', '2982'], hem: 'my-hem' } } }, { gdpr: { gdprApplies: 1, consentString: 'this-is-something' }, uspConsent: '1YYY' })) - .to.equal('?gdpr=1&gdpr_consent=this-is-something&us_privacy=1YYY&id.maid=424&id.maid=2982&id.hem=my-hem') - }) - }) - }) -}) diff --git a/test/spec/modules/fanBidAdapter_spec.js b/test/spec/modules/fanBidAdapter_spec.js deleted file mode 100644 index 04fbf5d7f..000000000 --- a/test/spec/modules/fanBidAdapter_spec.js +++ /dev/null @@ -1,349 +0,0 @@ -import { spec } from 'modules/fanBidAdapter.js'; -import { BANNER, VIDEO } from 'src/mediaTypes.js'; -import * as utils from 'src/utils.js'; -import { config } from 'src/config.js'; -import { expect } from 'chai'; -import sinon from 'sinon'; - -describe('freedomadnetworkAdapter', function() { - const BIDDER_CODE = 'freedomadnetwork'; - const DEFAULT_CURRENCY = 'USD'; - const DEFAULT_TTL = 300; - - let validBidRequestBanner; - let validBidRequestVideo; - let bidderRequest; - - beforeEach(function() { - // A minimal valid banner bid request - validBidRequestBanner = { - bidder: BIDDER_CODE, - params: { - placementId: 'placement123', - network: 'test' - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - adUnitCode: 'adunit-code-banner', - auctionId: 'auction-1', - bidId: 'bid-1', - bidderRequestId: 'br-1', - auctionStart: Date.now() - }; - - // A minimal valid video bid request - validBidRequestVideo = { - bidder: BIDDER_CODE, - params: { - placementId: 'placementVideo', - network: 'fan', - bidFloor: 1.5, - bidFloorCur: 'USD' - }, - mediaTypes: { - video: { - mimes: ['video/mp4'], - playerSize: [[640, 480]] - } - }, - adUnitCode: 'adunit-code-video', - auctionId: 'auction-2', - bidId: 'bid-2', - bidderRequestId: 'br-2', - auctionStart: Date.now() - }; - - // Stub bidderRequest used by buildRequests - bidderRequest = { - refererInfo: { referer: 'http://example.com' }, - auctionId: 'auction-1', - timeout: 3000, - gdprConsent: null, - uspConsent: null, - gppConsent: null - }; - - // Reset any config overrides - config.setConfig({}); - }); - - describe('isBidRequestValid', function() { - it('should return true when required params for banner are present', function() { - expect(spec.isBidRequestValid(validBidRequestBanner)).to.be.true; - }); - - it('should return true when required params for video are present', function() { - expect(spec.isBidRequestValid(validBidRequestVideo)).to.be.true; - }); - - it('should return false when params object is missing', function() { - const bid = Object.assign({}, validBidRequestBanner, { params: null }); - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false when placementId is missing', function() { - const bid = Object.assign({}, validBidRequestBanner, { params: {} }); - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false when network param is invalid', function() { - const bid = Object.assign({}, validBidRequestBanner, { - params: { - placementId: 'placement123', - network: 'invalidNetwork' - } - }); - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false when mediaTypes is unsupported', function() { - const bid = Object.assign({}, validBidRequestBanner, { - mediaTypes: { native: {} } - }); - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false when video params missing required fields', function() { - const badVideoBid1 = JSON.parse(JSON.stringify(validBidRequestVideo)); - delete badVideoBid1.mediaTypes.video.mimes; - expect(spec.isBidRequestValid(badVideoBid1)).to.be.false; - - const badVideoBid2 = JSON.parse(JSON.stringify(validBidRequestVideo)); - delete badVideoBid2.mediaTypes.video.playerSize; - expect(spec.isBidRequestValid(badVideoBid2)).to.be.false; - }); - }); - - describe('buildRequests', function() { - it('should group bids by network and produce valid HTTP requests', function() { - // Create two bids, one to 'test' network, one to FAN - const bidTest = JSON.parse(JSON.stringify(validBidRequestBanner)); - const bidFan = JSON.parse(JSON.stringify(validBidRequestBanner)); - bidFan.params.network = 'fan'; - bidFan.params.placementId = 'placement456'; - bidFan.bidId = 'bid-3'; - - const requests = spec.buildRequests([bidTest, bidFan], bidderRequest); - - // Expect two separate requests (one per network) - expect(requests).to.have.lengthOf(2); - - // Find the request for 'test' - const reqTest = requests.find(r => r.url === 'http://localhost:8001/ortb'); - expect(reqTest).to.exist; - expect(reqTest.method).to.equal('POST'); - expect(reqTest.options.contentType).to.equal('text/plain'); - expect(reqTest.options.withCredentials).to.be.false; - - // The data payload should have 'imp' array with one impression - expect(reqTest.data.imp).to.be.an('array').with.lengthOf(1); - const impTest = reqTest.data.imp[0]; - expect(impTest.tagid).to.equal('placement123'); - - // Source.tid must equal auctionId - expect(reqTest.data.source.tid).to.equal(bidderRequest.auctionId); - expect(reqTest.data.at).to.equal(1); - expect(reqTest.data.cur).to.deep.equal([DEFAULT_CURRENCY]); - expect(reqTest.data.ext.prebid.channel).to.equal(BIDDER_CODE); - expect(reqTest.data.ext.prebid.version).to.exist; - - // Find the request for FAN - const reqFan = requests.find(r => r.url === 'https://srv.freedomadnetwork.com/ortb'); - expect(reqFan).to.exist; - expect(reqFan.method).to.equal('POST'); - expect(reqFan.data.imp[0].tagid).to.equal('placement456'); - - // Validate bidfloor and bidfloorcur were set for video - const videoBid = validBidRequestVideo; - const reqVideo = spec.buildRequests([videoBid], bidderRequest)[0]; - const impVideo = reqVideo.data.imp[0]; - expect(impVideo.bidfloor).to.equal(0); - expect(impVideo.bidfloorcur).to.equal(videoBid.params.bidFloorCur); - }); - - describe('PriceFloors module support', function () { - it('should get default bid floor', function () { - const bidTest = JSON.parse(JSON.stringify(validBidRequestBanner)); - const requests = spec.buildRequests([bidTest], bidderRequest); - - const data = requests[0].data; - expect(data.imp[0].banner).to.exist; - expect(data.imp[0].bidfloor).to.equal(0); - }); - - it('should not add bid floor if getFloor fails', function () { - const bidTest = JSON.parse(JSON.stringify(validBidRequestBanner)); - bidTest.getFloor = () => { - return false; - }; - - const requests = spec.buildRequests([bidTest], bidderRequest); - - const data = requests[0].data; - expect(data.imp[0].banner).to.exist; - expect(data.imp[0].bidfloor).to.not.exist; - }); - - it('should get the floor when bid have several mediaTypes', function () { - const bidTest = JSON.parse(JSON.stringify(validBidRequestBanner)); - - bidTest.mediaTypes.video = { - playerSize: [600, 480], - }; - - const requests = spec.buildRequests([bidTest], bidderRequest); - - const data = requests[0].data; - expect(data.imp[0].banner).to.exist; - expect(data.imp[0].bidfloor).to.equal(0); - }); - }); - }); - - describe('interpretResponse', function() { - it('should return an empty array when response body is missing', function() { - const builtRequests = spec.buildRequests([validBidRequestBanner], bidderRequest); - const fakeRequest = builtRequests[0]; - - const result = spec.interpretResponse({ body: null }, fakeRequest); - expect(result).to.be.an('array').and.have.lengthOf(0); - }); - - it('should return proper bid objects for a valid ORTB response', function() { - const builtRequests = spec.buildRequests([validBidRequestBanner], bidderRequest); - const fakeRequest = builtRequests[0]; - - const ortbResponse = { - id: fakeRequest.data.id, - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: '123', - impid: fakeRequest.data.imp[0].id, - price: 2.5, - adm: '
Ad
', - w: 300, - h: 250, - crid: 'cr123', - mtype: 1, - } - ] - } - ], - }; - - const serverResponse = { body: ortbResponse }; - const bidResponses = spec.interpretResponse(serverResponse, fakeRequest); - - expect(bidResponses).to.be.an('array').with.lengthOf(1); - - const bid = bidResponses[0]; - expect(bid.requestId).to.equal('bid-1'); - expect(bid.cpm).to.equal(2.5); - expect(bid.ad).to.equal('
Ad
'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creativeId).to.equal('cr123'); - expect(bid.currency).to.equal('USD'); - expect(bid.ttl).to.equal(300); - }); - }); - - describe('getUserSyncs', function() { - const gdprConsent = { gdprApplies: true, consentString: 'CONSENT123' }; - const uspConsent = '1YNN'; - const gppConsent = { gppString: 'GPPSTRING', applicableSections: [6, 7] }; - - it('should return empty array when syncOptions disabled', function() { - const syncs = spec.getUserSyncs({ iframeEnabled: false, pixelEnabled: false }, [], gdprConsent, uspConsent, gppConsent); - expect(syncs).to.deep.equal([]); - }); - - it('should return iframe and image sync URLs without duplicates', function() { - const serverResponses = [{ - body: { - ext: { - sync: { - iframe: [{ url: 'https://sync.iframe/endpoint' }], - image: [{ url: 'https://sync.image/endpoint' }] - } - } - } - }, { - body: { - ext: { - sync: { - iframe: [{ url: 'https://sync.iframe/endpoint' }], // duplicate - image: [{ url: 'https://sync.image/endpoint2' }] - } - } - } - }]; - - const syncOptions = { iframeEnabled: true, pixelEnabled: true }; - const syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent, gppConsent); - - // Should have exactly three sync entries (unique URLs) - expect(syncs).to.have.lengthOf(3); - - // Validate type and URL parameters for GDPR and US Privacy - const iframeSync = syncs.find(s => s.type === 'iframe' && s.url.startsWith('https://sync.iframe/endpoint')); - expect(iframeSync).to.exist; - expect(iframeSync.url).to.match(/gdpr=1/); - expect(iframeSync.url).to.match(/gdpr_consent=CONSENT123/); - expect(iframeSync.url).to.match(/us_privacy=1YNN/); - expect(iframeSync.url).to.match(/gpp=GPPSTRING/); - // The comma in '6,7' will be percent-encoded as '%2C' - expect(iframeSync.url).to.match(/gpp_sid=6%2C7/); - - const imageSync1 = syncs.find(s => s.type === 'image' && s.url.startsWith('https://sync.image/endpoint')); - expect(imageSync1).to.exist; - const imageSync2 = syncs.find(s => s.type === 'image' && s.url.startsWith('https://sync.image/endpoint2')); - expect(imageSync2).to.exist; - }); - }); - - describe('Win Events', function() { - let triggerPixelStub; - - beforeEach(function() { - triggerPixelStub = sinon.stub(utils, 'triggerPixel'); - }); - - afterEach(function() { - triggerPixelStub.restore(); - }); - - it('onBidWon should fire nurl and win tracking pixel', function() { - const fakeBid = { - requestId: 'req123', - auctionId: 'auc123', - cpm: 5.0, - currency: 'USD', - creativeId: 'creative123', - nurl: 'https://win.nurl/track?bid=req123', - meta: { - libertas: { - pxl: [ - {url: 'https://pxl.nurl/track?bid=req456', type: 0} - ], - }, - }, - }; - - spec.onBidWon(fakeBid); - - // First call: nurl - expect(triggerPixelStub.calledWith('https://win.nurl/track?bid=req123')).to.be.true; - - // Second call: win tracking URL must start with base - const winCallArgs = triggerPixelStub.getCall(1).args[0]; - expect(winCallArgs).to.match(/^https:\/\/pxl\.nurl\/track\?bid=req456/); - }); - }); -}); diff --git a/test/spec/modules/feedadBidAdapter_spec.js b/test/spec/modules/feedadBidAdapter_spec.js deleted file mode 100644 index dbabb4dd5..000000000 --- a/test/spec/modules/feedadBidAdapter_spec.js +++ /dev/null @@ -1,629 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/feedadBidAdapter.js'; -import {BANNER, NATIVE, VIDEO} from '../../../src/mediaTypes.js'; -import {server} from 'test/mocks/xhr.js'; - -const CODE = 'feedad'; -const EXPECTED_ADAPTER_VERSION = '1.0.6'; - -describe('FeedAdAdapter', function () { - describe('Public API', function () { - it('should have the FeedAd bidder code', function () { - expect(spec.code).to.equal(CODE); - }); - it('should only support video and banner ads', function () { - expect(spec.supportedMediaTypes).to.be.a('array'); - expect(spec.supportedMediaTypes).to.include(BANNER); - expect(spec.supportedMediaTypes).not.to.include(VIDEO); - expect(spec.supportedMediaTypes).not.to.include(NATIVE); - }); - it('should export the BidderSpec functions', function () { - expect(spec.isBidRequestValid).to.be.a('function'); - expect(spec.buildRequests).to.be.a('function'); - expect(spec.interpretResponse).to.be.a('function'); - expect(spec.onTimeout).to.be.a('function'); - expect(spec.onBidWon).to.be.a('function'); - }); - it('should export the TCF vendor ID', function () { - expect(spec.gvlid).to.equal(781); - }) - }); - - describe('isBidRequestValid', function () { - it('should detect missing params', function () { - const result = spec.isBidRequestValid({ - bidder: 'feedad', - sizes: [] - }); - expect(result).to.equal(false); - }); - it('should detect missing client token', function () { - const result = spec.isBidRequestValid({ - bidder: 'feedad', - sizes: [], - params: {placementId: 'placement'} - }); - expect(result).to.equal(false); - }); - it('should detect zero length client token', function () { - const result = spec.isBidRequestValid({ - bidder: 'feedad', - sizes: [], - params: {clientToken: '', placementId: 'placement'} - }); - expect(result).to.equal(false); - }); - it('should detect missing placement id', function () { - const result = spec.isBidRequestValid({ - bidder: 'feedad', - sizes: [], - params: {clientToken: 'clientToken'} - }); - expect(result).to.equal(false); - }); - it('should detect zero length placement id', function () { - const result = spec.isBidRequestValid({ - bidder: 'feedad', - sizes: [], - params: {clientToken: 'clientToken', placementId: ''} - }); - expect(result).to.equal(false); - }); - it('should detect too long placement id', function () { - var placementId = ''; - for (var i = 0; i < 300; i++) { - placementId += 'a'; - } - const result = spec.isBidRequestValid({ - bidder: 'feedad', - sizes: [], - params: {clientToken: 'clientToken', placementId} - }); - expect(result).to.equal(false); - }); - it('should detect invalid placement id', function () { - [ - 'placement id with spaces', - 'some|id', - 'PLACEMENTID', - 'placeme:ntId' - ].forEach(id => { - const result = spec.isBidRequestValid({ - bidder: 'feedad', - sizes: [], - params: {clientToken: 'clientToken', placementId: id} - }); - expect(result).to.equal(false); - }); - }); - it('should accept valid parameters', function () { - const result = spec.isBidRequestValid({ - bidder: 'feedad', - sizes: [], - params: {clientToken: 'clientToken', placementId: 'placement-id'} - }); - expect(result).to.equal(true); - }); - }); - - describe('buildRequests', function () { - const bidderRequest = { - refererInfo: { - page: 'the referer' - }, - some: 'thing' - }; - - it('should accept empty lists', function () { - const result = spec.buildRequests([], bidderRequest); - expect(result).to.be.empty; - }); - it('should filter native media types', function () { - const bid = { - code: 'feedad', - mediaTypes: { - native: { - sizes: [[300, 250], [300, 600]], - } - }, - params: {clientToken: 'clientToken', placementId: 'placement-id'} - }; - const result = spec.buildRequests([bid], bidderRequest); - expect(result).to.be.empty; - }); - it('should filter video media types without outstream context', function () { - const bid = { - code: 'feedad', - mediaTypes: { - video: { - context: 'instream' - } - }, - params: {clientToken: 'clientToken', placementId: 'placement-id'} - }; - const result = spec.buildRequests([bid], bidderRequest); - expect(result).to.be.empty; - }); - it('should pass through outstream video media', function () { - const bid = { - code: 'feedad', - mediaTypes: { - video: { - context: 'outstream' - } - }, - params: {clientToken: 'clientToken', placementId: 'placement-id'} - }; - const result = spec.buildRequests([bid], bidderRequest); - expect(result.data.bids).to.be.lengthOf(1); - expect(result.data.bids[0]).to.deep.equal(bid); - }); - it('should pass through banner media', function () { - const bid = { - code: 'feedad', - mediaTypes: { - banner: { - sizes: [[320, 250]] - } - }, - params: {clientToken: 'clientToken', placementId: 'placement-id'} - }; - const result = spec.buildRequests([bid], bidderRequest); - expect(result.data.bids).to.be.lengthOf(1); - expect(result.data.bids[0]).to.deep.equal(bid); - }); - it('should pass through additional bid parameters', function () { - const bid = { - code: 'feedad', - mediaTypes: { - banner: { - sizes: [[320, 250]] - } - }, - params: {clientToken: 'clientToken', placementId: 'placement-id', another: 'parameter', more: 'parameters'} - }; - const result = spec.buildRequests([bid], bidderRequest); - expect(result.data.bids).to.be.lengthOf(1); - expect(result.data.bids[0].params.another).to.equal('parameter'); - expect(result.data.bids[0].params.more).to.equal('parameters'); - }); - it('should detect empty media types', function () { - const bid = { - code: 'feedad', - mediaTypes: { - banner: undefined, - video: undefined, - native: undefined - }, - params: {clientToken: 'clientToken', placementId: 'placement-id'} - }; - const result = spec.buildRequests([bid], bidderRequest); - expect(result).to.be.empty; - }); - it('should use POST', function () { - const bid = { - code: 'feedad', - mediaTypes: { - banner: { - sizes: [[320, 250]] - } - }, - params: {clientToken: 'clientToken', placementId: 'placement-id'} - }; - const result = spec.buildRequests([bid], bidderRequest); - expect(result.method).to.equal('POST'); - }); - it('should use the correct URL', function () { - const bid = { - code: 'feedad', - mediaTypes: { - banner: { - sizes: [[320, 250]] - } - }, - params: {clientToken: 'clientToken', placementId: 'placement-id'} - }; - const result = spec.buildRequests([bid], bidderRequest); - expect(result.url).to.equal('https://api.feedad.com/1/prebid/web/bids'); - }); - it('should specify the content type explicitly', function () { - const bid = { - code: 'feedad', - mediaTypes: { - banner: { - sizes: [[320, 250]] - } - }, - params: {clientToken: 'clientToken', placementId: 'placement-id'} - }; - const result = spec.buildRequests([bid], bidderRequest); - expect(result.options).to.deep.equal({ - contentType: 'application/json' - }) - }); - it('should include the bidder request', function () { - const bid = { - code: 'feedad', - mediaTypes: { - banner: { - sizes: [[320, 250]] - } - }, - params: {clientToken: 'clientToken', placementId: 'placement-id'} - }; - const result = spec.buildRequests([bid, bid, bid], bidderRequest); - expect(result.data).to.deep.include(bidderRequest); - }); - it('should detect missing bidder request parameter', function () { - const bid = { - code: 'feedad', - mediaTypes: { - banner: { - sizes: [[320, 250]] - } - }, - params: {clientToken: 'clientToken', placementId: 'placement-id'} - }; - const result = spec.buildRequests([bid, bid, bid]); - expect(result).to.be.empty; - }); - it('should not include GDPR data if the bidder request has none available', function () { - const bid = { - code: 'feedad', - mediaTypes: { - banner: { - sizes: [[320, 250]] - } - }, - params: {clientToken: 'clientToken', placementId: 'placement-id'} - }; - const result = spec.buildRequests([bid], bidderRequest); - expect(result.data.gdprApplies).to.be.undefined; - expect(result.data.consentIabTcf).to.be.undefined; - }); - it('should include GDPR data if the bidder requests contains it', function () { - const bid = { - code: 'feedad', - mediaTypes: { - banner: { - sizes: [[320, 250]] - } - }, - params: {clientToken: 'clientToken', placementId: 'placement-id'} - }; - const request = Object.assign({}, bidderRequest, { - gdprConsent: { - consentString: 'the consent string', - gdprApplies: true - } - }); - const result = spec.buildRequests([bid], request); - expect(result.data.gdprApplies).to.equal(request.gdprConsent.gdprApplies); - expect(result.data.consentIabTcf).to.equal(request.gdprConsent.consentString); - }); - it('should include adapter and prebid version', function () { - const bid = { - code: 'feedad', - mediaTypes: { - banner: { - sizes: [[320, 250]] - } - }, - params: {clientToken: 'clientToken', placementId: 'placement-id'} - }; - const result = spec.buildRequests([bid], bidderRequest); - expect(result.data.bids[0].params.prebid_adapter_version).to.equal(EXPECTED_ADAPTER_VERSION); - expect(result.data.bids[0].params.prebid_sdk_version).to.equal('$prebid.version$'); - }); - }); - - describe('interpretResponse', function () { - it('should convert string bodies to JSON', function () { - const body = [{ - ad: 'bar', - }]; - const result = spec.interpretResponse({body: JSON.stringify(body)}); - expect(result).to.deep.equal(body); - }); - - it('should pass through object bodies', function () { - const body = [{ - ad: 'bar', - }]; - const result = spec.interpretResponse({body}); - expect(result).to.deep.equal(body); - }); - - it('should pass through only bodies with ad fields', function () { - const bid1 = { - ad: 'bar', - other: 'field', - some: 'thing' - }; - const bid2 = { - foo: 'bar' - }; - const bid3 = { - ad: 'ad html', - }; - const body = [bid1, bid2, bid3]; - const result = spec.interpretResponse({body: JSON.stringify(body)}); - expect(result).to.deep.equal([bid1, bid3]); - }); - - it('should remove extension fields from bid responses', function () { - const bid = { - ext: {}, - ad: 'ad html', - cpm: 100 - }; - const result = spec.interpretResponse({body: JSON.stringify([bid])}); - expect(result[0]).not.to.haveOwnProperty('ext'); - }); - - it('should return an empty array if the response is not an array', function () { - const bid = {}; - const result = spec.interpretResponse({body: JSON.stringify(bid)}); - expect(result).to.deep.equal([]); - }); - }); - - describe('getUserSyncs', function () { - const pixelSync1 = {type: 'image', url: 'the pixel url 1'}; - const pixelSync2 = {type: 'image', url: 'the pixel url 2'}; - const iFrameSync1 = {type: 'iframe', url: 'the iFrame url 1'}; - const iFrameSync2 = {type: 'iframe', url: 'the iFrame url 2'}; - const response1 = { - body: [{ - ext: { - pixels: [pixelSync1, pixelSync2], - iframes: [iFrameSync1] - }, - }] - }; - const response2 = { - body: [{ - ext: { - pixels: [pixelSync1], - iframes: [iFrameSync1], - } - }, { - ext: { - pixels: [pixelSync2], - iframes: [iFrameSync2], - } - }] - }; - it('should pass through the syncs out of the extension fields of the server response', function () { - const result = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, [response1]) - expect(result).to.deep.equal([ - pixelSync1, - pixelSync2, - iFrameSync1, - ]); - }); - - it('should concat the syncs of all responses', function () { - const result = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, [response1, response2]); - expect(result).to.deep.equal([ - pixelSync1, - pixelSync2, - iFrameSync1, - iFrameSync2, - ]); - }); - - it('should concat the syncs of all bids', function () { - const result = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, [response2]); - expect(result).to.deep.equal([ - pixelSync1, - iFrameSync1, - pixelSync2, - iFrameSync2, - ]); - }); - - it('should filter out duplicates', function () { - const result = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, [response1, response1]); - expect(result).to.deep.equal([ - pixelSync1, - pixelSync2, - iFrameSync1, - ]); - }); - - it('should not include iFrame syncs if the option is disabled', function () { - const result = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [response1]); - expect(result).to.deep.equal([ - pixelSync1, - pixelSync2, - ]); - }); - - it('should not include pixel syncs if the option is disabled', function () { - const result = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: false}, [response1]); - expect(result).to.deep.equal([ - iFrameSync1, - ]); - }); - - it('should not include any syncs if the sync options are disabled or missing', function () { - const result = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: false}, [response1]); - expect(result).to.deep.equal([]); - }); - - it('should handle empty responses', function () { - const result = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, []) - expect(result).to.deep.equal([]); - }); - - it('should not throw if the server response is weird', function () { - const responses = [ - {body: null}, - {body: 'null'}, - {body: 1234}, - {body: {}}, - {body: [{}, 123]}, - ]; - expect(() => spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, responses)).to.not.throw(); - }); - - it('should return empty array if the body extension is null', function () { - const response = {body: [{ext: null}]}; - const result = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, [response]); - expect(result).to.deep.equal([]); - }); - }); - - describe('event tracking calls', function () { - const clientToken = 'clientToken'; - const placementId = 'placement id'; - const auctionId = 'the auction id'; - const bidId = 'the bid id'; - const transactionId = 'the transaction id'; - const referer = 'the referer'; - const bidderRequest = { - refererInfo: { - page: referer - }, - some: 'thing' - }; - const bid = { - 'bidder': 'feedad', - 'params': { - 'clientToken': 'fupp', - 'placementId': 'prebid-test' - }, - 'crumbs': { - 'pubcid': '6254a85f-bded-489a-9736-83c45d45ef1d' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - ortb2Imp: { - ext: { - tid: transactionId - } - }, - 'sizes': [ - [ - 300, - 250 - ] - ], - 'bidId': bidId, - 'bidderRequestId': '10739fe6fe2127', - 'auctionId': '5ac67dff-d971-4b56-84a3-345a87a1f786', - 'src': 'client', - 'bidRequestsCount': 1 - }; - const timeoutData = { - 'bidId': bidId, - 'bidder': 'feedad', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'auctionId': auctionId, - 'params': [ - { - 'clientToken': clientToken, - 'placementId': placementId - } - ], - 'timeout': 3000 - }; - const bidWonData = { - 'bidderCode': 'feedad', - 'width': 300, - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '3a4529aa05114d', - 'requestId': bidId, - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 0.5, - 'ad': 'ad content', - 'ttl': 60, - 'creativeId': 'feedad-21-0', - 'netRevenue': true, - 'currency': 'EUR', - 'auctionId': auctionId, - 'responseTimestamp': 1558365914596, - 'requestTimestamp': 1558365914506, - 'bidder': 'feedad', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'timeToRespond': 90, - 'pbLg': '0.50', - 'pbMg': '0.50', - 'pbHg': '0.50', - 'pbAg': '0.50', - 'pbDg': '0.50', - 'pbCg': '', - 'size': '300x250', - 'adserverTargeting': { - 'hb_bidder': 'feedad', - 'hb_adid': '3a4529aa05114d', - 'hb_pb': '0.50', - 'hb_size': '300x250', - 'hb_source': 'client', - 'hb_format': 'banner' - }, - 'status': 'rendered', - 'params': [ - { - 'clientToken': clientToken, - 'placementId': placementId - } - ] - }; - const cases = [ - ['onTimeout', timeoutData, 'prebid_bidTimeout'], - ['onBidWon', bidWonData, 'prebid_bidWon'], - ]; - - cases.forEach(([name, data, eventKlass]) => { - const subject = spec[name]; - describe(name + ' handler', function () { - it('should do nothing on empty data', function () { - subject(undefined); - subject(null); - expect(server.requests.length).to.equal(0); - }); - - it('should do nothing when bid metadata is not set', function () { - subject(data); - expect(server.requests.length).to.equal(0); - }); - - it('should send tracking params when correct metadata was set', function () { - spec.buildRequests([bid], bidderRequest); - const expectedData = { - app_hybrid: false, - client_token: clientToken, - placement_id: placementId, - klass: eventKlass, - prebid_auction_id: auctionId, - prebid_bid_id: bidId, - prebid_transaction_id: transactionId, - referer, - prebid_adapter_version: EXPECTED_ADAPTER_VERSION, - prebid_sdk_version: '$prebid.version$', - }; - subject(data); - expect(server.requests.length).to.equal(1); - const call = server.requests[0]; - expect(call.url).to.equal('https://api.feedad.com/1/prebid/web/events'); - expect(JSON.parse(call.requestBody)).to.deep.equal(expectedData); - expect(call.method).to.equal('POST'); - expect(call.requestHeaders).to.include({'Content-Type': 'application/json'}); - }) - }); - }); - }); -}); diff --git a/test/spec/modules/finativeBidAdapter_spec.js b/test/spec/modules/finativeBidAdapter_spec.js deleted file mode 100644 index ebb3e9e7a..000000000 --- a/test/spec/modules/finativeBidAdapter_spec.js +++ /dev/null @@ -1,174 +0,0 @@ -// jshint esversion: 6, es3: false, node: true -import {assert, expect} from 'chai'; -import {spec} from 'modules/finativeBidAdapter.js'; -import { NATIVE } from 'src/mediaTypes.js'; -import { config } from 'src/config.js'; - -describe('Finative adapter', function () { - let serverResponse, bidRequest, bidResponses; - const bid = { - 'bidder': 'finative', - 'params': { - 'adUnitId': '1uyo' - } - }; - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - assert(spec.isBidRequestValid(bid)); - }); - - it('should return false when AdUnitId is not set', function () { - delete bid.params.adUnitId; - assert.isFalse(spec.isBidRequestValid(bid)); - }); - }); - - describe('buildRequests', function () { - it('should send request with correct structure', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: {} - }]; - - const request = spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }); - - assert.equal(request.method, 'POST'); - assert.ok(request.data); - }); - - it('should have default request structure', function () { - const keys = 'site,device,cur,imp,user,regs'.split(','); - const validBidRequests = [{ - bidId: 'bidId', - params: {} - }]; - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); - const data = Object.keys(request); - - assert.deepEqual(keys, data); - }); - - it('Verify the device', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: {} - }]; - const request = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data); - - assert.equal(request.device.ua, navigator.userAgent); - }); - - it('Verify native asset ids', function () { - const validBidRequests = [{ - bidId: 'bidId', - params: {}, - nativeParams: { - body: { - required: true, - len: 350 - }, - image: { - required: true - }, - title: { - required: true - }, - sponsoredBy: { - required: true - }, - cta: { - required: true - }, - icon: { - required: true - } - } - }]; - - const assets = JSON.parse(spec.buildRequests(validBidRequests, { refererInfo: { referer: 'page' } }).data).imp[0].native.request.assets; - - assert.equal(assets[0].id, 1); - assert.equal(assets[1].id, 3); - assert.equal(assets[2].id, 0); - assert.equal(assets[3].id, 2); - assert.equal(assets[4].id, 4); - assert.equal(assets[5].id, 5); - }); - }); - - describe('interpretResponse', function () { - const goodResponse = { - body: { - cur: 'EUR', - id: '4b516b80-886e-4ec0-82ae-9209e6d625fb', - seatbid: [ - { - seat: 'finative', - bid: [{ - adm: { - native: { - assets: [ - {id: 0, title: {text: 'this is a title'}} - ], - imptrackers: ['https://domain.for/imp/tracker?price=${AUCTION_PRICE}'], - link: { - clicktrackers: ['https://domain.for/imp/tracker?price=${AUCTION_PRICE}'], - url: 'https://domain.for/ad/' - } - } - }, - impid: 1, - price: 0.55 - }] - } - ] - } - }; - const badResponse = { body: { - cur: 'EUR', - id: '4b516b80-886e-4ec0-82ae-9209e6d625fb', - seatbid: [] - }}; - - const bidRequest = { - data: {}, - bids: [{ bidId: 'bidId1' }] - }; - - it('should return null if body is missing or empty', function () { - const result = spec.interpretResponse(badResponse, bidRequest); - assert.equal(result.length, 0); - - delete badResponse.body - - const result1 = spec.interpretResponse(badResponse, bidRequest); - assert.equal(result.length, 0); - }); - - it('should return the correct params', function () { - const result = spec.interpretResponse(goodResponse, bidRequest); - const bid = goodResponse.body.seatbid[0].bid[0]; - - assert.deepEqual(result[0].currency, goodResponse.body.cur); - assert.deepEqual(result[0].requestId, bidRequest.bids[0].bidId); - assert.deepEqual(result[0].cpm, bid.price); - assert.deepEqual(result[0].creativeId, bid.crid); - assert.deepEqual(result[0].mediaType, 'native'); - }); - - it('should return the correct tracking links', function () { - const result = spec.interpretResponse(goodResponse, bidRequest); - const bid = goodResponse.body.seatbid[0].bid[0]; - const regExpPrice = new RegExp('price=' + bid.price); - - result[0].native.clickTrackers.forEach(function (clickTracker) { - assert.ok(clickTracker.search(regExpPrice) > -1); - }); - - result[0].native.impressionTrackers.forEach(function (impTracker) { - assert.ok(impTracker.search(regExpPrice) > -1); - }); - }); - }); -}); diff --git a/test/spec/modules/fintezaAnalyticsAdapter_spec.js b/test/spec/modules/fintezaAnalyticsAdapter_spec.js deleted file mode 100644 index eaf5b5f40..000000000 --- a/test/spec/modules/fintezaAnalyticsAdapter_spec.js +++ /dev/null @@ -1,235 +0,0 @@ -import fntzAnalyticsAdapter from 'modules/fintezaAnalyticsAdapter.js'; -import { expect } from 'chai'; -import { parseUrl } from 'src/utils.js'; -import { server } from 'test/mocks/xhr.js'; -import { EVENTS } from 'src/constants.js'; - -const adapterManager = require('src/adapterManager').default; -const events = require('src/events'); - -function setCookie(name, value, expires) { - document.cookie = name + '=' + value + - '; path=/' + - (expires ? ('; expires=' + expires.toUTCString()) : '') + - '; SameSite=Lax'; -} - -describe('finteza analytics adapter', function () { - const clientId = 'fntz-client-32145'; - const uniqCookie = '5045380421580287382'; - - beforeEach(function () { - setCookie('_fz_uniq', uniqCookie); - sinon.stub(events, 'getEvents').returns([]); - sinon.spy(fntzAnalyticsAdapter, 'track'); - - adapterManager.registerAnalyticsAdapter({ - code: 'finteza', - adapter: fntzAnalyticsAdapter - }); - - adapterManager.enableAnalytics({ - provider: 'finteza', - options: { - id: clientId, // Client ID (required) - bidRequestTrack: 'Bid Request %BIDDER%', - bidResponseTimeTrack: 'Bid Response Time %bidder%', - bidResponsePriceTrack: 'Bid Response Price %bidder%', - bidTimeoutTrack: 'Bid Timeout %Bidder%', - bidWonTrack: 'Bid Won %BIDDER%', - } - }); - }); - - afterEach(function () { - setCookie('_fz_uniq', '', new Date(0)); - events.getEvents.restore(); - fntzAnalyticsAdapter.track.restore(); - fntzAnalyticsAdapter.disableAnalytics(); - }); - - describe('track', () => { - describe('bid request', () => { - it('builds and sends request data', function () { - const bidderCode = 'Bidder789'; - const pauctionId = '5018eb39-f900-4370-b71e-3bb5b48d324f'; - - const bidRequest = { - bidderCode: bidderCode, - auctionId: pauctionId, - bidderRequestId: '1a6fc81528d0f6', - bids: [{ - bidder: bidderCode, - placementCode: 'container-1', - bidId: '208750227436c1', - bidderRequestId: '1a6fc81528d0f6', - auctionId: pauctionId, - startTime: 1509369418389, - sizes: [[300, 250]], - }], - auctionStart: 1509369418387, - timeout: 3000, - start: 1509369418389 - }; - - // Emit the events with the "real" arguments - events.emit(EVENTS.BID_REQUESTED, bidRequest); - - expect(server.requests.length).to.equal(1); - - expect(server.requests[0].method).to.equal('GET'); - expect(server.requests[0].withCredentials).to.equal(true); - - const url = parseUrl(server.requests[0].url); - - expect(url.protocol).to.equal('https'); - expect(url.hostname).to.equal('content.mql5.com'); - expect(url.pathname).to.equal('/tr'); - expect(url.search.id).to.equal(clientId); - expect(url.search.fz_uniq).to.equal(uniqCookie); - expect(decodeURIComponent(url.search.event)).to.equal(`Bid Request ${bidderCode.toUpperCase()}`); - - sinon.assert.callCount(fntzAnalyticsAdapter.track, 1); - }); - }); - - describe('bid response', () => { - it('builds and sends response data', function () { - const bidderCode = 'Bidder789'; - const pauctionId = '5018eb39-f900-4370-b71e-3bb5b48d324f'; - - const timeToRespond = 443; - const cpm = 0.015; - - const bidResponse = { - bidderCode: bidderCode, - adId: '208750227436c1', - cpm: cpm, - auctionId: pauctionId, - responseTimestamp: 1509369418832, - requestTimestamp: 1509369418389, - bidder: bidderCode, - timeToRespond: timeToRespond, - size: '300x250', - width: 300, - height: 250, - }; - - // Emit the events with the "real" arguments - events.emit(EVENTS.BID_RESPONSE, bidResponse); - - expect(server.requests[0].method).to.equal('GET'); - expect(server.requests[0].withCredentials).to.equal(true); - - expect(server.requests.length).to.equal(2); - - let url = parseUrl(server.requests[0].url); - - expect(url.protocol).to.equal('https'); - expect(url.hostname).to.equal('content.mql5.com'); - expect(url.pathname).to.equal('/tr'); - expect(url.search.id).to.equal(clientId); - expect(url.search.fz_uniq).to.equal(uniqCookie); - expect(decodeURIComponent(url.search.event)).to.equal(`Bid Response Price ${bidderCode.toLowerCase()}`); - expect(url.search.value).to.equal(String(cpm)); - expect(url.search.unit).to.equal('usd'); - - expect(server.requests[1].method).to.equal('GET'); - expect(server.requests[1].withCredentials).to.equal(true); - - url = parseUrl(server.requests[1].url); - - expect(url.protocol).to.equal('https'); - expect(url.hostname).to.equal('content.mql5.com'); - expect(url.pathname).to.equal('/tr'); - expect(url.search.id).to.equal(clientId); - expect(url.search.fz_uniq).to.equal(uniqCookie); - expect(decodeURIComponent(url.search.event)).to.equal(`Bid Response Time ${bidderCode.toLowerCase()}`); - expect(url.search.value).to.equal(String(timeToRespond)); - expect(url.search.unit).to.equal('ms'); - - sinon.assert.callCount(fntzAnalyticsAdapter.track, 1); - }); - }); - - describe('bid won', () => { - it('builds and sends bid won data', function () { - const bidderCode = 'Bidder789'; - const pauctionId = '5018eb39-f900-4370-b71e-3bb5b48d324f'; - - const cpm = 0.015; - - const bidWon = { - bidderCode: bidderCode, - cpm: cpm, - adId: 'adIdData', - ad: 'adContent', - auctionId: pauctionId, - width: 300, - height: 250 - } - - // Emit the events with the "real" arguments - events.emit(EVENTS.BID_WON, bidWon); - - expect(server.requests[0].method).to.equal('GET'); - expect(server.requests[0].withCredentials).to.equal(true); - - expect(server.requests.length).to.equal(1); - - const url = parseUrl(server.requests[0].url); - - expect(url.protocol).to.equal('https'); - expect(url.hostname).to.equal('content.mql5.com'); - expect(url.pathname).to.equal('/tr'); - expect(url.search.id).to.equal(clientId); - expect(url.search.fz_uniq).to.equal(uniqCookie); - expect(decodeURIComponent(url.search.event)).to.equal(`Bid Won ${bidderCode.toUpperCase()}`); - expect(url.search.value).to.equal(String(cpm)); - expect(url.search.unit).to.equal('usd'); - - // 1 Finteza event + 1 Clean.io event - sinon.assert.callCount(fntzAnalyticsAdapter.track, 2); - }); - }); - - describe('bid timeout', () => { - it('builds and sends timeout data', function () { - const bidderCode = 'biDDer789'; - const pauctionId = '5018eb39-f900-4370-b71e-3bb5b48d324f'; - - const timeout = 2540; - - const bidTimeout = [ - { - bidId: '208750227436c1', - bidder: bidderCode, - auctionId: pauctionId, - timeout: timeout, - } - ]; - - // Emit the events with the "real" arguments - events.emit(EVENTS.BID_TIMEOUT, bidTimeout); - - expect(server.requests[0].method).to.equal('GET'); - expect(server.requests[0].withCredentials).to.equal(true); - - expect(server.requests.length).to.equal(1); - - const url = parseUrl(server.requests[0].url); - - expect(url.protocol).to.equal('https'); - expect(url.hostname).to.equal('content.mql5.com'); - expect(url.pathname).to.equal('/tr'); - expect(url.search.id).to.equal(clientId); - expect(url.search.fz_uniq).to.equal(uniqCookie); - expect(decodeURIComponent(url.search.event)).to.equal(`Bid Timeout Bidder789`); - expect(url.search.value).to.equal(String(timeout)); - expect(url.search.unit).to.equal('ms'); - - sinon.assert.callCount(fntzAnalyticsAdapter.track, 1); - }); - }); - }); -}); diff --git a/test/spec/modules/flippBidAdapter_spec.js b/test/spec/modules/flippBidAdapter_spec.js deleted file mode 100644 index e7867c8b4..000000000 --- a/test/spec/modules/flippBidAdapter_spec.js +++ /dev/null @@ -1,178 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/flippBidAdapter'; -import {newBidder} from 'src/adapters/bidderFactory'; -const ENDPOINT = 'https://gateflipp.flippback.com/flyer-locator-service/client_bidding'; -describe('flippAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - bidder: 'flipp', - params: { - publisherNameIdentifier: 'random', - siteId: 1234, - zoneIds: [1, 2, 3, 4], - } - }; - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - invalidBid.params = { siteId: 1234 } - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [{ - bidder: 'flipp', - params: { - siteId: 1234, - }, - adUnitCode: '/10000/unit_code', - sizes: [[300, 600]], - mediaTypes: {banner: {sizes: [[300, 600]]}}, - bidId: '237f4d1a293f99', - bidderRequestId: '1a857fa34c1c96', - auctionId: 'a297d1aa-7900-4ce4-a0aa-caa8d46c4af7', - transactionId: '00b2896c-2731-4f01-83e4-7a3ad5da13b6', - }]; - const bidderRequest = { - refererInfo: { - referer: 'http://example.com' - } - }; - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.method).to.equal('POST'); - }); - - it('sends bid request to ENDPOINT with query parameter', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).to.equal(ENDPOINT); - }); - }); - - describe('interpretResponse', function() { - it('should get correct bid response', function() { - const bidRequest = { - method: 'POST', - url: ENDPOINT, - data: { - placements: [{ - divName: 'slot', - networkId: 12345, - siteId: 12345, - adTypes: [12345], - count: 1, - prebid: { - requestId: '237f4d1a293f99', - publisherNameIdentifier: 'bid.params.publisherNameIdentifier', - height: 600, - width: 300, - }, - user: '10462725-da61-4d3a-beff-6d05239e9a6e"', - }], - url: 'http://example.com', - }, - }; - - const serverResponse = { - body: { - 'decisions': { - 'inline': [{ - 'bidCpm': 1, - 'adId': 262838368, - 'height': 600, - 'width': 300, - 'storefront': { 'flyer_id': 5435567 }, - 'prebid': { - 'requestId': '237f4d1a293f99', - 'cpm': 1.11, - 'creative': 'Returned from server', - }, - 'contents': { - 'data': { - 'customData': { - 'compactHeight': 600, - 'standardHeight': 1800 - } - } - } - }] - }, - 'location': {'city': 'Oakville'}, - }, - }; - - const expectedResponse = [ - { - bidderCode: 'flipp', - requestId: '237f4d1a293f99', - currency: 'USD', - cpm: 1.11, - netRevenue: true, - width: 300, - height: 1800, - creativeId: 262838368, - ttl: 30, - ad: 'Returned from server', - } - ]; - - const result = spec.interpretResponse(serverResponse, bidRequest); - expect(result).to.have.lengthOf(1); - expect(result).to.deep.have.same.members(expectedResponse); - }); - - it('should get empty bid response when no ad is returned', function() { - const bidRequest = { - method: 'POST', - url: ENDPOINT, - data: { - placements: [{ - divName: 'slot', - networkId: 12345, - siteId: 12345, - adTypes: [12345], - count: 1, - prebid: { - requestId: '237f4d1a293f99', - publisherNameIdentifier: 'bid.params.publisherNameIdentifier', - height: 600, - width: 300, - }, - user: '10462725-da61-4d3a-beff-6d05239e9a6e"', - }], - url: 'http://example.com', - }, - }; - - const serverResponse = { - body: { - 'decisions': { - 'inline': [] - }, - 'location': {'city': 'Oakville'}, - }, - }; - - const result = spec.interpretResponse(serverResponse, bidRequest); - expect(result).to.have.lengthOf(0); - expect(result).to.deep.have.same.members([]); - }) - - it('should get empty response when bid server returns 204', function() { - expect(spec.interpretResponse({})).to.be.empty; - }); - }); -}); diff --git a/test/spec/modules/fluctBidAdapter_spec.js b/test/spec/modules/fluctBidAdapter_spec.js deleted file mode 100644 index e96a41b51..000000000 --- a/test/spec/modules/fluctBidAdapter_spec.js +++ /dev/null @@ -1,664 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/fluctBidAdapter'; -import {newBidder} from 'src/adapters/bidderFactory'; -import {config} from 'src/config'; - -describe('fluctAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - bidder: 'fluct', - params: { - dfpUnitCode: '/1000/dfp_unit_code', - tagId: '10000:100000001', - groupId: '1000000002', - } - }; - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return true when dfpUnitCode is not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - tagId: '10000:100000001', - groupId: '1000000002', - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(true); - }); - - it('should return false when groupId is not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - dfpUnitCode: '/1000/dfp_unit_code', - tagId: '10000:100000001', - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - let sb; - - beforeEach(function () { - sb = sinon.createSandbox(); - }); - - afterEach(function () { - sb.restore(); - }); - - const bidRequests = [{ - bidder: 'fluct', - params: { - dfpUnitCode: '/100000/unit_code', - tagId: '10000:100000001', - groupId: '1000000002', - }, - adUnitCode: '/10000/unit_code', - sizes: [[300, 250], [336, 280]], - bidId: '237f4d1a293f99', - bidderRequestId: '1a857fa34c1c96', - auctionId: 'a297d1aa-7900-4ce4-a0aa-caa8d46c4af7', - transactionId: '00b2896c-2731-4f01-83e4-7a3ad5da13b6', - }]; - const bidderRequest = { - refererInfo: { - page: 'http://example.com' - } - }; - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.method).to.equal('POST'); - }); - - it('sends bid request to ENDPOINT with query parameter', function () { - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.url).to.equal('https://hb.adingo.jp/prebid?dfpUnitCode=%2F100000%2Funit_code&tagId=10000%3A100000001&groupId=1000000002'); - }); - - it('includes data.page by default', function () { - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.page).to.eql('http://example.com'); - }); - - it('sends no transactionId by default', function () { - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.transactionId).to.eql(undefined); - }); - - it('sends ortb2Imp.ext.tid as transactionId', function () { - const request = spec.buildRequests(bidRequests.map((req) => ({ - ...req, - ortb2Imp: { - ext: { - tid: 'tid', - } - }, - })), bidderRequest)[0]; - expect(request.data.transactionId).to.eql('tid'); - }); - - it('sends no gpid by default', function () { - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.gpid).to.eql(undefined); - }); - - it('sends ortb2Imp.ext.gpid as gpid', function () { - const request = spec.buildRequests(bidRequests.map((req) => ({ - ...req, - ortb2Imp: { - ext: { - gpid: 'gpid', - data: { - pbadslot: 'data-pbadslot', - adserver: { - adslot: 'data-adserver-adslot', - }, - }, - }, - }, - })), bidderRequest)[0]; - expect(request.data.gpid).to.eql('gpid'); - }); - - it('sends ortb2Imp.ext.gpid as gpid', function () { - const request = spec.buildRequests(bidRequests.map((req) => ({ - ...req, - ortb2Imp: { - ext: { - gpid: 'data-pbadslot', - data: { - adserver: { - adslot: 'data-adserver-adslot', - }, - }, - }, - }, - })), bidderRequest)[0]; - expect(request.data.gpid).to.eql('data-pbadslot'); - }); - - it('sends ortb2Imp.ext.data.adserver.adslot as gpid', function () { - const request = spec.buildRequests(bidRequests.map((req) => ({ - ...req, - ortb2Imp: { - ext: { - data: { - adserver: { - adslot: 'data-adserver-adslot', - }, - }, - }, - }, - })), bidderRequest)[0]; - expect(request.data.gpid).to.eql('data-adserver-adslot'); - }); - - it('includes data.user.eids = [] by default', function () { - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.user.eids).to.eql([]); - }); - - it('includes no data.params.kv by default', function () { - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.params.kv).to.eql(undefined); - }); - - it('includes no data.schain by default', function () { - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.schain).to.eql(undefined); - }); - - it('includes no data.regs by default', function () { - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.regs).to.eql(undefined); - }); - - it('includes filtered user.eids if any exists', function () { - const bidRequests2 = bidRequests.map( - (bidReq) => Object.assign({}, bidReq, { - userIdAsEids: [ - { - source: 'foobar.com', - uids: [ - { id: 'foobar-id' }, - ], - }, - { - source: 'adserver.org', - uids: [ - { id: 'tdid' } - ], - }, - { - source: 'criteo.com', - uids: [ - { id: 'criteo-id' }, - ], - }, - { - source: 'intimatemerger.com', - uids: [ - { id: 'imuid' }, - ], - }, - { - source: 'liveramp.com', - uids: [ - { id: 'idl-env' }, - ], - }, - ], - }) - ); - const request = spec.buildRequests(bidRequests2, bidderRequest)[0]; - expect(request.data.user.eids).to.eql([ - { - source: 'foobar.com', - uids: [ - { id: 'foobar-id' }, - ], - }, - { - source: 'adserver.org', - uids: [ - { id: 'tdid' }, - ], - }, - { - source: 'criteo.com', - uids: [ - { id: 'criteo-id' }, - ], - }, - { - source: 'intimatemerger.com', - uids: [ - { id: 'imuid' }, - ], - }, - { - source: 'liveramp.com', - uids: [ - { id: 'idl-env' }, - ], - }, - ]); - }); - - it('includes user.data if any exists', function () { - const bidderRequest2 = Object.assign({}, bidderRequest, { - ortb2: { - user: { - data: [ - { - name: 'a1mediagroup.com', - ext: { - segtax: 900, - }, - segment: [ - { id: 'seg-1' }, - { id: 'seg-2' }, - ], - }, - ], - ext: { - eids: [ - { - source: 'a1mediagroup.com', - uids: [ - { id: 'aud-1' } - ], - }, - ], - }, - }, - }, - }); - const request = spec.buildRequests(bidRequests, bidderRequest2)[0]; - expect(request.data.user).to.eql({ - data: [ - { - name: 'a1mediagroup.com', - ext: { - segtax: 900, - }, - segment: [ - { id: 'seg-1' }, - { id: 'seg-2' }, - ], - }, - ], - eids: [ - { - source: 'a1mediagroup.com', - uids: [ - { id: 'aud-1' } - ], - }, - ], - }); - }); - - it('includes data.params.kv if any exists', function () { - const bidRequests2 = bidRequests.map( - (bidReq) => Object.assign({}, bidReq, { - params: { - kv: { - imsids: ['imsid1', 'imsid2'] - } - } - }) - ); - const request = spec.buildRequests(bidRequests2, bidderRequest)[0]; - expect(request.data.params.kv).to.eql({ - imsids: ['imsid1', 'imsid2'] - }); - }); - - it('includes data.schain if any exists', function () { - // this should be done by schain.js - const bidRequests2 = bidRequests.map( - (bidReq) => Object.assign({}, bidReq, { - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'example.com', - sid: 'publisher-id', - hp: 1 - } - ] - } - } - } - } - }) - ); - const request = spec.buildRequests(bidRequests2, bidderRequest)[0]; - expect(request.data.schain).to.eql({ - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'example.com', - sid: 'publisher-id', - hp: 1 - } - ] - }); - }); - - it('includes data.regs.gdpr if bidderRequest.gdprConsent exists', function () { - const request = spec.buildRequests( - bidRequests, - Object.assign({}, bidderRequest, { - gdprConsent: { - consentString: 'gdpr-consent-string', - gdprApplies: true, - }, - }), - )[0]; - expect(request.data.regs.gdpr).to.eql({ - consent: 'gdpr-consent-string', - gdprApplies: 1, - }); - }); - - it('includes data.regs.us_privacy if bidderRequest.uspConsent exists', function () { - const request = spec.buildRequests( - bidRequests, - Object.assign({}, bidderRequest, { - uspConsent: 'usp-consent-string', - }), - )[0]; - expect(request.data.regs.us_privacy).to.eql({ - consent: 'usp-consent-string', - }); - }); - - it('includes data.regs.coppa if config.getConfig("coppa") is true', function () { - const cfg = { - coppa: true, - }; - sb.stub(config, 'getConfig').callsFake(key => cfg[key]); - - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.regs.coppa).to.eql(1); - }); - - it('includes data.regs.gpp.string and data.regs.gpp.sid if bidderRequest.gppConsent exists', function () { - const request = spec.buildRequests( - bidRequests, - Object.assign({}, bidderRequest, { - gppConsent: { - gppString: 'gpp-consent-string', - applicableSections: [1, 2, 3], - }, - }), - )[0]; - expect(request.data.regs.gpp.string).to.eql('gpp-consent-string'); - expect(request.data.regs.gpp.sid).to.eql([1, 2, 3]); - }); - - it('includes data.regs.gpp.string and data.regs.gpp.sid if bidderRequest.ortb2.regs.gpp exists', function () { - const request = spec.buildRequests( - bidRequests, - Object.assign({}, bidderRequest, { - ortb2: { - regs: { - gpp: 'gpp-consent-string', - gpp_sid: [1, 2, 3], - }, - }, - }), - )[0]; - expect(request.data.regs.gpp.string).to.eql('gpp-consent-string'); - expect(request.data.regs.gpp.sid).to.eql([1, 2, 3]); - }); - - it('sends no instl as instl = 0', function () { - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.instl).to.eql(0); - }) - - it('sends ortb2Imp.instl as instl = 0', function () { - const request = spec.buildRequests(bidRequests.map((req) => ({ - ...req, - ortb2Imp: { - instl: 0, - }, - })), bidderRequest)[0]; - expect(request.data.instl).to.eql(0); - }); - - it('sends ortb2Imp.instl as instl', function () { - const request = spec.buildRequests(bidRequests.map((req) => ({ - ...req, - ortb2Imp: { - instl: 1, - }, - })), bidderRequest)[0]; - expect(request.data.instl).to.eql(1); - }); - }); - - describe('should interpretResponse', function() { - const callBeaconSnippet = ''; - - it('should get correct bid response', function() { - const bidRequest = { - bidder: 'fluct', - params: { - dfpUnitCode: '/10000/unit_code', - tagid: '10000:100000001', - groupId: '1000000002', - }, - adUnitCode: '/10000/unit_code', - sizes: [[300, 250], [336, 280]], - bidId: '237f4d1a293f99', - bidderRequestId: '1a857fa34c1c96', - auctionId: 'a297d1aa-7900-4ce4-a0aa-caa8d46c4af7', - transactionId: '00b2896c-2731-4f01-83e4-7a3ad5da13b6', - }; - - const serverResponse = { - body: { - id: '237f4d1a293f99', - cur: 'JPY', - seatbid: [{ - bid: [{ - price: 100, - w: 300, - h: 250, - adm: '', - burl: 'https://i.adingo.jp/?test=1&et=hb&bidid=237f4d1a293f99', - crid: 'test_creative', - adomain: ['test_adomain'], - }] - }], - usersyncs: [ - { - 'type': 'image', - 'url': 'https://cs.adingo.jp/sync', - }, - ], - } - }; - - const expectedResponse = [ - { - requestId: '237f4d1a293f99', - currency: 'JPY', - cpm: 100, - netRevenue: true, - width: 300, - height: 250, - creativeId: 'test_creative', - ttl: 300, - ad: '' + callBeaconSnippet, - meta: { - advertiserDomains: ['test_adomain'], - }, - } - ]; - - const result = spec.interpretResponse(serverResponse, bidRequest); - expect(result).to.have.lengthOf(1); - expect(result).to.deep.have.same.members(expectedResponse); - }); - - it('should get correct bid response with dealId', function() { - const bidRequest = { - bidder: 'fluct', - params: { - dfpUnitCode: '/10000/unit_code', - tagid: '10000:100000001', - groupId: '1000000002' - }, - adUnitCode: '/10000/unit_code', - sizes: [[300, 250], [336, 280]], - bidId: '237f4d1a293f99', - bidderRequestId: '1a857fa34c1c96', - auctionId: 'a297d1aa-7900-4ce4-a0aa-caa8d46c4af7', - transactionId: '00b2896c-2731-4f01-83e4-7a3ad5da13b6', - }; - - const serverResponse = { - body: { - id: '237f4d1a293f99', - cur: 'JPY', - seatbid: [{ - bid: [{ - price: 100, - w: 300, - h: 250, - adm: '', - burl: 'https://i.adingo.jp/?test=1&et=hb&bidid=237f4d1a293f99', - crid: 'test_creative', - dealid: 'test_deal', - }] - }] - } - }; - - const expectedResponse = [ - { - requestId: '237f4d1a293f99', - currency: 'JPY', - cpm: 100, - netRevenue: true, - width: 300, - height: 250, - creativeId: 'test_creative', - ttl: 300, - ad: '' + callBeaconSnippet, - dealId: 'test_deal', - meta: { - advertiserDomains: [], - }, - } - ]; - - const result = spec.interpretResponse(serverResponse, bidRequest); - expect(result).to.have.lengthOf(1); - expect(result).to.deep.have.same.members(expectedResponse); - }); - - it('should get empty response when bid server returns 204', function() { - expect(spec.interpretResponse({})).to.be.empty; - }); - }); - - describe('getUserSyncs', function () { - const syncOptions = {}; - const serverResponse = { - body: { - usersyncs: [ - { - type: 'image', - url: 'https://cs.adingo.jp/foo', - }, - { - type: 'image', - url: 'https://cs.adingo.jp/bar', - }, - { - type: 'iframe', - url: 'https://cs.adingo.jp/buz', - }, - ], - }, - }; - - it('returns no user syncs if syncOption.pixelEnabled !== true and syncOption.iframeEnabled !== true', function () { - const actual = spec.getUserSyncs( - syncOptions, - [serverResponse], - ); - - expect(actual).to.eql([]); - }); - - it('returns user syncs if syncOption.pixelEnabled === true', function () { - const actual = spec.getUserSyncs( - Object.assign({}, syncOptions, { - pixelEnabled: true, - }), - [serverResponse], - ); - - expect(actual).to.eql([ - { - type: 'image', - url: 'https://cs.adingo.jp/foo', - }, - { - type: 'image', - url: 'https://cs.adingo.jp/bar', - }, - ]); - }); - - it('returns user syncs if syncOption.iframeEnabled === true', function () { - const actual = spec.getUserSyncs( - Object.assign({}, syncOptions, { - iframeEnabled: true, - }), - [serverResponse], - ); - - expect(actual).to.eql([ - { - type: 'iframe', - url: 'https://cs.adingo.jp/buz', - }, - ]); - }); - }); -}); diff --git a/test/spec/modules/freeWheelAdserverVideo_spec.js b/test/spec/modules/freeWheelAdserverVideo_spec.js index 3da5b411e..020aabed1 100644 --- a/test/spec/modules/freeWheelAdserverVideo_spec.js +++ b/test/spec/modules/freeWheelAdserverVideo_spec.js @@ -3,6 +3,7 @@ import { adpodUtils } from 'modules/freeWheelAdserverVideo.js'; import { auctionManager } from 'src/auctionManager.js'; import { config } from 'src/config.js'; import { server } from 'test/mocks/xhr.js'; +import 'modules/adpod.js'; describe('freeWheel adserver module', function() { let amStub; @@ -226,9 +227,9 @@ describe('freeWheel adserver module', function() { ); expect(targeting['preroll_1'].length).to.equal(3); - expect(targeting['preroll_1']).to.deep.include({'hb_pb_cat_dur': 'tier6_395_15s'}); - expect(targeting['preroll_1']).to.deep.include({'hb_pb_cat_dur': 'tier7_395_15s'}); - expect(targeting['preroll_1']).to.deep.include({'hb_cache_id': '123'}); + expect(targeting['preroll_1']).to.deep.include({'oa_pb_cat_dur': 'tier6_395_15s'}); + expect(targeting['preroll_1']).to.deep.include({'oa_pb_cat_dur': 'tier7_395_15s'}); + expect(targeting['preroll_1']).to.deep.include({'oa_cache_id': '123'}); }); it('should apply minDealTier to bids if configured', function() { @@ -247,14 +248,14 @@ describe('freeWheel adserver module', function() { const tier2Bid = createBid(10, 'preroll_1', 15, 'tier2_395_15s', '123', '395'); tier2Bid['video']['dealTier'] = 2 - tier2Bid['adserverTargeting']['hb_pb'] = '10.00' + tier2Bid['adserverTargeting']['oa_pb'] = '10.00' const tier7Bid = createBid(11, 'preroll_1', 45, 'tier7_395_15s', '123', '395'); tier7Bid['video']['dealTier'] = 7 - tier7Bid['adserverTargeting']['hb_pb'] = '11.00' + tier7Bid['adserverTargeting']['oa_pb'] = '11.00' const bid = createBid(15, 'preroll_1', 15, '15.00_395_90s', '123', '395'); - bid['adserverTargeting']['hb_pb'] = '15.00' + bid['adserverTargeting']['oa_pb'] = '15.00' const bidsReceived = [ tier2Bid, @@ -276,10 +277,10 @@ describe('freeWheel adserver module', function() { ); expect(targeting['preroll_1'].length).to.equal(3); - expect(targeting['preroll_1']).to.deep.include({'hb_pb_cat_dur': 'tier7_395_15s'}); - expect(targeting['preroll_1']).to.deep.include({'hb_pb_cat_dur': '15.00_395_90s'}); - expect(targeting['preroll_1']).to.not.include({'hb_pb_cat_dur': 'tier2_395_15s'}); - expect(targeting['preroll_1']).to.deep.include({'hb_cache_id': '123'}); + expect(targeting['preroll_1']).to.deep.include({'oa_pb_cat_dur': 'tier7_395_15s'}); + expect(targeting['preroll_1']).to.deep.include({'oa_pb_cat_dur': '15.00_395_90s'}); + expect(targeting['preroll_1']).to.not.include({'oa_pb_cat_dur': 'tier2_395_15s'}); + expect(targeting['preroll_1']).to.deep.include({'oa_cache_id': '123'}); }) }); @@ -331,14 +332,14 @@ function createBid(cpm, adUnitCode, durationBucket, priceIndustryDuration, uuid, 'pbCg': '', 'size': '640x360', 'adserverTargeting': { - 'hb_bidder': 'appnexus', - 'hb_adid': '28f24ced14586c', - 'hb_pb': '5.00', - 'hb_size': '640x360', - 'hb_source': 'client', - 'hb_format': 'video', - 'hb_pb_cat_dur': priceIndustryDuration, - 'hb_cache_id': uuid + 'oa_bidder': 'appnexus', + 'oa_adid': '28f24ced14586c', + 'oa_pb': '5.00', + 'oa_size': '640x360', + 'oa_source': 'client', + 'oa_format': 'video', + 'oa_pb_cat_dur': priceIndustryDuration, + 'oa_cache_id': uuid }, 'customCacheKey': `${priceIndustryDuration}_${uuid}`, 'meta': { diff --git a/test/spec/modules/freepassBidAdapter_spec.js b/test/spec/modules/freepassBidAdapter_spec.js deleted file mode 100644 index b36639f57..000000000 --- a/test/spec/modules/freepassBidAdapter_spec.js +++ /dev/null @@ -1,222 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/freepassBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; - -describe('FreePass adapter', function () { - const adapter = newBidder(spec); - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - bidder: 'freepass', - userIdAsEids: [{ - source: 'freepass.jp', - uids: [{ - id: 'commonIdValue', - ext: { - userId: 'fpid', - ip: '172.21.0.1' - } - }] - }], - adUnitCode: 'adunit-code', - params: { - publisherId: 'publisherIdValue' - } - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when adUnitCode is missing', function () { - const localBid = Object.assign({}, bid); - delete localBid.adUnitCode; - expect(spec.isBidRequestValid(localBid)).to.equal(false); - }); - - it('should return false when params.publisherId is missing', function () { - const localBid = Object.assign({}, bid); - delete localBid.params.publisherId; - expect(spec.isBidRequestValid(localBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - let bidRequests, bidderRequest; - beforeEach(function () { - bidRequests = [{ - 'bidder': 'freepass', - 'userIdAsEids': [{ - source: 'freepass.jp', - uids: [{ - id: 'commonIdValue', - ext: { - userId: '56c4c789-71ce-46f5-989e-9e543f3d5f96', - ip: '172.21.0.1' - } - }] - }], - 'adUnitCode': 'adunit-code', - 'params': { - 'publisherId': 'publisherIdValue' - } - }]; - bidderRequest = {}; - }); - - it('should return an empty array when no bid requests', function () { - const bidRequest = spec.buildRequests([], bidderRequest); - expect(bidRequest).to.be.an('array'); - expect(bidRequest.length).to.equal(0); - }); - - it('should handle missing userIdAsEids gracefully', function () { - const localBidRequests = [JSON.parse(JSON.stringify(bidRequests[0]))]; - delete localBidRequests[0].userIdAsEids; - expect(() => spec.buildRequests(localBidRequests, bidderRequest)).to.not.throw(); - }); - - it('should return a valid bid request object', function () { - const bidRequest = spec.buildRequests(bidRequests, bidderRequest); - expect(bidRequest).to.be.an('object'); - expect(bidRequest.data).to.be.an('object'); - expect(bidRequest.method).to.equal('POST'); - expect(bidRequest.url).to.not.equal(''); - expect(bidRequest.url).to.not.equal(undefined); - expect(bidRequest.url).to.not.equal(null); - }); - - it('should add user id to user information', function () { - const bidRequest = spec.buildRequests(bidRequests, bidderRequest); - const ortbData = bidRequest.data; - expect(ortbData.user).to.be.an('object'); - expect(ortbData.user.id).to.equal('56c4c789-71ce-46f5-989e-9e543f3d5f96'); - }); - - it('should add freepass commonId to extended user information', function () { - const bidRequest = spec.buildRequests(bidRequests, bidderRequest); - const ortbData = bidRequest.data; - expect(ortbData.user).to.be.an('object'); - expect(ortbData.user.ext).to.be.an('object'); - expect(ortbData.user.ext.fuid).to.equal('commonIdValue'); - }); - - it('should skip freepass commonId when not available', function () { - const localBidRequests = [JSON.parse(JSON.stringify(bidRequests[0]))]; - localBidRequests[0].userIdAsEids[0].uids[0].id = undefined; - const bidRequest = spec.buildRequests(localBidRequests, bidderRequest); - const ortbData = bidRequest.data; - expect(ortbData.user).to.be.an('object'); - expect(ortbData.user.ext).to.be.an('object'); - expect(ortbData.user.ext.fuid).to.be.undefined; - }); - - it('should add IP information to extended device information', function () { - const bidRequest = spec.buildRequests(bidRequests, bidderRequest); - const ortbData = bidRequest.data; - expect(ortbData.device).to.be.an('object'); - expect(ortbData.device.ip).to.equal('172.21.0.1'); - expect(ortbData.device.ext).to.be.an('object'); - expect(ortbData.device.ext.is_accurate_ip).to.equal(1); - }); - - it('should skip IP information when not available', function () { - const localBidRequests = [JSON.parse(JSON.stringify(bidRequests[0]))]; - delete localBidRequests[0].userIdAsEids[0].uids[0].ext.ip; - const bidRequest = spec.buildRequests(localBidRequests, bidderRequest); - const ortbData = bidRequest.data; - expect(ortbData.device).to.be.an('object'); - expect(ortbData.device.ip).to.be.undefined; - expect(ortbData.device.ext).to.be.an('object'); - expect(ortbData.device.ext.is_accurate_ip).to.equal(0); - }); - - it('it should add publisher related information w/o publisherUrl', function () { - const bidRequest = spec.buildRequests(bidRequests, bidderRequest); - const ortbData = bidRequest.data; - expect(ortbData.site).to.be.an('object'); - expect(ortbData.site.publisher.id).to.equal('publisherIdValue'); - // publisher.domain is optional - expect(ortbData.site.publisher.domain).to.be.undefined; - }); - - it('it should add publisher related information w/ publisherUrl', function () { - const PUBLISHER_URL = 'publisherUrlValue'; - const localBidRequests = [Object.assign({}, bidRequests[0])]; - localBidRequests[0].params.publisherUrl = PUBLISHER_URL; - const bidRequest = spec.buildRequests(localBidRequests, bidderRequest); - const ortbData = bidRequest.data; - expect(ortbData.site).to.be.an('object'); - expect(ortbData.site.publisher.id).to.equal('publisherIdValue'); - // publisher.domain is optional. set when given - expect(ortbData.site.publisher.domain).to.equal(PUBLISHER_URL); - }); - - it('it should imp.tagId from adUnitCode', function () { - const bidRequest = spec.buildRequests(bidRequests, bidderRequest); - const ortbData = bidRequest.data; - expect(ortbData.imp[0].tagId).to.equal('adunit-code'); - }); - }); - - describe('interpretResponse', function () { - let bidRequests, bidderRequest; - beforeEach(function () { - bidRequests = [{ - 'bidId': '28ffdf2a952532', - 'bidder': 'freepass', - 'userIdAsEids': [{ - source: 'freepass.jp', - uids: [{ - id: 'commonIdValue', - ext: { - userId: '56c4c789-71ce-46f5-989e-9e543f3d5f96', - ip: '172.21.0.1' - } - }] - }], - 'adUnitCode': 'adunit-code', - 'params': { - 'publisherId': 'publisherIdValue' - } - }]; - bidderRequest = {}; - }); - - const ad = ''; - const serverResponse = { - body: { - 'cur': 'JPY', - 'seatbid': [{ - 'bid': [{ - 'impid': '28ffdf2a952532', - 'price': 97, - 'adm': ad, - 'w': 300, - 'h': 250, - 'crid': 'creative0' - }] - }] - } - }; - it('should interpret server response', function () { - const bidRequest = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, bidRequest); - expect(bids).to.be.an('array'); - - const bid = bids[0]; - expect(bid).to.be.an('object'); - expect(bid.currency).to.equal('JPY'); - expect(bid.cpm).to.equal(97); - expect(bid.ad).to.equal(ad) - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creativeId).to.equal('creative0'); - }); - }); -}); diff --git a/test/spec/modules/fwsspBidAdapter_spec.js b/test/spec/modules/fwsspBidAdapter_spec.js deleted file mode 100644 index cf43712c6..000000000 --- a/test/spec/modules/fwsspBidAdapter_spec.js +++ /dev/null @@ -1,1200 +0,0 @@ -const { expect } = require('chai'); -const { spec, getSDKVersion, formatAdHTML, getBidFloor } = require('modules/fwsspBidAdapter'); - -describe('fwsspBidAdapter', () => { - describe('isBidRequestValid', () => { - it('should return true when all required params are present', () => { - const bid = { - params: { - serverUrl: 'https://example.com/ad/g/1', - networkId: '42015', - profile: '42015:js_allinone_profile', - siteSectionId: 'js_allinone_demo_site_section', - videoAssetId: '0' - } - }; - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - - it('should return false when serverUrl is missing', () => { - const bid = { - params: { - networkId: '42015', - profile: '42015:js_allinone_profile', - siteSectionId: 'js_allinone_demo_site_section', - videoAssetId: '0' - } - }; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false when networkId is missing', () => { - const bid = { - params: { - serverUrl: 'https://example.com/ad/g/1', - profile: '42015:js_allinone_profile', - siteSectionId: 'js_allinone_demo_site_section', - videoAssetId: '0' - } - }; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false when profile is missing', () => { - const bid = { - params: { - serverUrl: 'https://example.com/ad/g/1', - networkId: '42015', - siteSectionId: 'js_allinone_demo_site_section', - videoAssetId: '0' - } - }; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false when siteSectionId is missing', () => { - const bid = { - params: { - serverUrl: 'https://example.com/ad/g/1', - networkId: '42015', - profile: '42015:js_allinone_profile', - videoAssetId: '0' - } - }; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false when videoAssetId is missing', () => { - const bid = { - params: { - serverUrl: 'https://example.com/ad/g/1', - networkId: '42015', - profile: '42015:js_allinone_profile', - siteSectionId: 'js_allinone_demo_site_section' - } - }; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - }); - - describe('buildRequestsForBanner', () => { - const getBidRequests = () => { - return [{ - 'bidder': 'fwssp', - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 250], [300, 600] - ] - } - }, - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [{ - 'asi': 'example.com', - 'sid': '0', - 'hp': 1, - 'rid': 'bidrequestid', - 'domain': 'example.com' - }] - }, - 'params': { - 'bidfloor': 2.00, - 'bidfloorcur': 'EUR', - 'serverUrl': 'https://example.com/ad/g/1', - 'networkId': '42015', - 'profile': '42015:js_allinone_profile', - 'siteSectionId': 'js_allinone_demo_site_section', - 'flags': '+play', - 'videoAssetId': '0', - 'timePosition': 120, - 'adRequestKeyValues': { - '_fw_player_width': '1920', - '_fw_player_height': '1080' - } - } - }] - }; - - const bidderRequest = { - gdprConsent: { - consentString: 'consentString', - gdprApplies: true - }, - uspConsent: 'uspConsentString', - gppConsent: { - gppString: 'gppString', - applicableSections: [8] - }, - refererInfo: { - page: 'www.test.com' - } - }; - - it('should build a valid server request', () => { - const requests = spec.buildRequests(getBidRequests(), bidderRequest); - expect(requests).to.be.an('array').that.is.not.empty; - const request = requests[0]; - expect(request.method).to.equal('GET'); - expect(request.url).to.equal('https://example.com/ad/g/1'); - - const actualDataString = request.data; - expect(actualDataString).to.include('nw=42015'); - expect(actualDataString).to.include('resp=vast4'); - expect(actualDataString).to.include('prof=42015%3Ajs_allinone_profile'); - expect(actualDataString).to.include('csid=js_allinone_demo_site_section'); - expect(actualDataString).to.include('caid=0'); - expect(actualDataString).to.include('pvrn='); - expect(actualDataString).to.include('vprn='); - expect(actualDataString).to.include('flag=%2Bplay%2Bfwssp%2Bemcr%2Bnucr%2Baeti%2Brema%2Bexvt%2Bfwpbjs'); - expect(actualDataString).to.include('mode=on-demand'); - expect(actualDataString).to.include(`vclr=js-7.11.0-prebid-${pbjs.version};`); - expect(actualDataString).to.include('_fw_player_width=1920'); - expect(actualDataString).to.include('_fw_player_height=1080'); - expect(actualDataString).to.include('_fw_gdpr_consent=consentString'); - expect(actualDataString).to.include('_fw_gdpr=true'); - expect(actualDataString).to.include('_fw_us_privacy=uspConsentString'); - expect(actualDataString).to.include('gpp=gppString'); - expect(actualDataString).to.include('gpp_sid=8'); - expect(actualDataString).to.include('tpos=0'); - expect(actualDataString).to.include('ptgt=a'); - expect(actualDataString).to.include('slid=Preroll_1'); - expect(actualDataString).to.include('slau=preroll'); - expect(actualDataString).to.not.include('mind'); - expect(actualDataString).to.not.include('maxd;'); - // schain check - const expectedEncodedSchainString = encodeURIComponent('{"ver":"1.0","complete":1,"nodes":[{"asi":"example.com","sid":"0","hp":1,"rid":"bidrequestid","domain":"example.com"}]}'); - expect(actualDataString).to.include(expectedEncodedSchainString); - }); - - it('should construct the full adrequest URL correctly', () => { - const requests = spec.buildRequests(getBidRequests(), bidderRequest); - expect(requests).to.be.an('array').that.is.not.empty; - const request = requests[0]; - const expectedUrl = `https://example.com/ad/g/1?nw=42015&resp=vast4&prof=42015%3Ajs_allinone_profile&csid=js_allinone_demo_site_section&caid=0&flag=%2Bplay%2Bfwssp%2Bemcr%2Bnucr%2Baeti%2Brema%2Bexvt%2Bfwpbjs&mode=on-demand&vclr=js-7.11.0-prebid-${pbjs.version};_fw_player_width=1920&_fw_player_height=1080&_fw_bidfloor=2&_fw_bidfloorcur=EUR&_fw_gdpr_consent=consentString&_fw_gdpr=true&_fw_us_privacy=uspConsentString&gpp=gppString&gpp_sid=8&schain=%7B%22ver%22%3A%221.0%22%2C%22complete%22%3A1%2C%22nodes%22%3A%5B%7B%22asi%22%3A%22example.com%22%2C%22sid%22%3A%220%22%2C%22hp%22%3A1%2C%22rid%22%3A%22bidrequestid%22%2C%22domain%22%3A%22example.com%22%7D%5D%7D;tpos=0&ptgt=a&slid=Preroll_1&slau=preroll;`; - const actualUrl = `${request.url}?${request.data}`; - // Remove pvrn and vprn from both URLs before comparing - const cleanUrl = (url) => url.replace(/&pvrn=[^&]*/g, '').replace(/&vprn=[^&]*/g, ''); - expect(cleanUrl(actualUrl)).to.equal(cleanUrl(expectedUrl)); - }); - - it('should return the correct width and height when _fw_player_width and _fw_player_height are not present in adRequestKeyValues', () => { - const bidRequests = [{ - 'bidder': 'fwssp', - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 600] - ] - } - }, - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'params': { - 'bidfloor': 2.00, - 'serverUrl': 'https://example.com/ad/g/1', - 'networkId': '42015', - 'profile': '42015:js_allinone_profile', - 'siteSectionId': 'js_allinone_demo_site_section', - } - }]; - const request = spec.buildRequests(bidRequests); - const payload = request[0].data; - expect(payload).to.include('_fw_player_width=300'); - expect(payload).to.include('_fw_player_height=600'); - }); - - it('should return image type userSyncs with gdprConsent', () => { - const syncOptions = { - 'pixelEnabled': true - } - const userSyncs = spec.getUserSyncs(syncOptions, null, bidderRequest.gdprConsent, null, null); - expect(userSyncs).to.deep.equal([{ - type: 'image', - url: 'https://ads.stickyadstv.com/auto-user-sync?gdpr=1&gdpr_consent=consentString' - }]); - }); - - it('should return iframe type userSyncs with gdprConsent, uspConsent, gppConsent', () => { - const syncOptions = { - 'iframeEnabled': true - } - const userSyncs = spec.getUserSyncs(syncOptions, null, bidderRequest.gdprConsent, bidderRequest.uspConsent, bidderRequest.gppConsent); - expect(userSyncs).to.deep.equal([{ - type: 'iframe', - url: 'https://ads.stickyadstv.com/auto-user-sync?gdpr=1&gdpr_consent=consentString&us_privacy=uspConsentString&gpp=gppString&gpp_sid[]=8' - }]); - }); - - it('should use schain from ortb2, prioritizing source.schain', () => { - const bidRequests = getBidRequests(); - const bidderRequest2 = { ...bidderRequest } - const schain1 = { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'test1.com', - sid: '0', - hp: 1, - rid: 'bidrequestid1', - domain: 'test1.com' - }] - }; - const schain2 = { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'test2.com', - sid: '0', - hp: 2, - rid: 'bidrequestid2', - domain: 'test2.com' - }] - }; - - bidderRequest2.ortb2 = { - source: { - schain: schain1, - ext: { - schain: schain2 - } - } - }; - - const requests = spec.buildRequests(bidRequests, bidderRequest2); - const request = requests[0]; - - // schain check - const expectedEncodedSchainString = encodeURIComponent(JSON.stringify(schain1)); - expect(request.data).to.include(expectedEncodedSchainString); - }); - - it('should use schain from ortb2.source.ext, if source.schain is not available', () => { - const bidRequests = getBidRequests(); - const bidderRequest2 = { ...bidderRequest } - const schain2 = { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'test2.com', - sid: '0', - hp: 2, - rid: 'bidrequestid2', - domain: 'test2.com' - }] - }; - - bidderRequest2.ortb2 = { - source: { - ext: { - schain: schain2 - } - } - }; - - const requests = spec.buildRequests(bidRequests, bidderRequest2); - const request = requests[0]; - - // schain check - const expectedEncodedSchainString = encodeURIComponent(JSON.stringify(schain2)); - expect(request.data).to.include(expectedEncodedSchainString); - }); - }); - - describe('buildRequestsForVideo', () => { - const getBidRequests = () => { - return [{ - 'bidder': 'fwssp', - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'video': { - 'playerSize': [300, 600], - 'minduration': 30, - 'maxduration': 60, - } - }, - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [{ - 'asi': 'example.com', - 'sid': '0', - 'hp': 1, - 'rid': 'bidrequestid', - 'domain': 'example.com' - }] - }, - 'params': { - 'bidfloor': 2.00, - 'serverUrl': 'https://example.com/ad/g/1', - 'networkId': '42015', - 'profile': '42015:js_allinone_profile', - 'siteSectionId': 'js_allinone_demo_site_section', - 'flags': '+play', - 'videoAssetId': '0', - 'mode': 'live', - 'timePosition': 120, - 'tpos': 300, - 'slid': 'Midroll', - 'slau': 'midroll', - 'adRequestKeyValues': { - '_fw_player_width': '1920', - '_fw_player_height': '1080' - }, - 'gdpr_consented_providers': 'test_providers' - } - }] - }; - - const bidderRequest = { - gdprConsent: { - consentString: 'consentString', - gdprApplies: true - }, - uspConsent: 'uspConsentString', - gppConsent: { - gppString: 'gppString', - applicableSections: [8] - }, - ortb2: { - regs: { - gpp: 'test_ortb2_gpp', - gpp_sid: 'test_ortb2_gpp_sid' - }, - site: { - content: { - id: 'test_content_id', - title: 'test_content_title' - } - } - }, - refererInfo: { - page: 'http://www.test.com' - } - }; - - it('should return context and placement with default values', () => { - const request = spec.buildRequests(getBidRequests()); - const payload = request[0].data; - expect(payload).to.include('_fw_video_context=&'); ; - expect(payload).to.include('_fw_placement_type=null&'); - expect(payload).to.include('_fw_plcmt_type=null;'); - }); - - it('should assign placement and context when format is inbanner', () => { - const bidRequest = getBidRequests()[0]; - bidRequest.params.format = 'inbanner'; - bidRequest.mediaTypes.video.plcmt = 'test-plcmt-type'; - const request = spec.buildRequests([bidRequest]); - const payload = request[0].data; - expect(payload).to.include('_fw_video_context=In-Banner&'); ; - expect(payload).to.include('_fw_placement_type=2&'); - expect(payload).to.include('_fw_plcmt_type=test-plcmt-type;'); - }); - - it('should build a valid server request', () => { - const requests = spec.buildRequests(getBidRequests(), bidderRequest); - expect(requests).to.be.an('array').that.is.not.empty; - const request = requests[0]; - expect(request.method).to.equal('GET'); - expect(request.url).to.equal('https://example.com/ad/g/1'); - - const actualDataString = request.data; - - expect(actualDataString).to.include('nw=42015'); - expect(actualDataString).to.include('resp=vast4'); - expect(actualDataString).to.include('prof=42015%3Ajs_allinone_profile'); - expect(actualDataString).to.include('csid=js_allinone_demo_site_section'); - expect(actualDataString).to.include('caid=0'); - expect(actualDataString).to.include('pvrn='); - expect(actualDataString).to.include('vprn='); - expect(actualDataString).to.include('flag=%2Bplay%2Bfwssp%2Bemcr%2Bnucr%2Baeti%2Brema%2Bexvt%2Bfwpbjs'); - expect(actualDataString).to.include('mode=live'); - expect(actualDataString).to.include(`vclr=js-7.11.0-prebid-${pbjs.version};`); - expect(actualDataString).to.include('_fw_player_width=1920'); - expect(actualDataString).to.include('_fw_player_height=1080'); - expect(actualDataString).to.include('_fw_gdpr_consent=consentString'); - expect(actualDataString).to.include('_fw_gdpr=true'); - expect(actualDataString).to.include('_fw_us_privacy=uspConsentString'); - expect(actualDataString).to.include('gpp=gppString'); - expect(actualDataString).to.include('gpp_sid=8'); - - expect(actualDataString).to.include('loc=http%3A%2F%2Fwww.test.com'); - expect(actualDataString).to.include('tpos=300'); - expect(actualDataString).to.include('ptgt=a'); - expect(actualDataString).to.include('slid=Midroll'); - expect(actualDataString).to.include('slau=midroll'); - expect(actualDataString).to.include('mind=30'); - expect(actualDataString).to.include('maxd=60;'); - // schain check - const expectedEncodedSchainString = encodeURIComponent('{"ver":"1.0","complete":1,"nodes":[{"asi":"example.com","sid":"0","hp":1,"rid":"bidrequestid","domain":"example.com"}]}'); - expect(actualDataString).to.include(expectedEncodedSchainString); - }); - - it('should construct the full adrequest URL correctly', () => { - const requests = spec.buildRequests(getBidRequests(), bidderRequest); - expect(requests).to.be.an('array').that.is.not.empty; - const request = requests[0]; - - const expectedUrl = `https://example.com/ad/g/1?nw=42015&resp=vast4&prof=42015%3Ajs_allinone_profile&csid=js_allinone_demo_site_section&caid=0&flag=%2Bplay%2Bfwssp%2Bemcr%2Bnucr%2Baeti%2Brema%2Bexvt%2Bfwpbjs&mode=live&vclr=js-7.11.0-prebid-${pbjs.version};_fw_player_width=1920&_fw_player_height=1080&_fw_bidfloor=2&_fw_bidfloorcur=USD&_fw_gdpr_consent=consentString&_fw_gdpr=true&_fw_gdpr_consented_providers=test_providers&_fw_us_privacy=uspConsentString&gpp=gppString&gpp_sid=8&_fw_prebid_content=%7B%22id%22%3A%22test_content_id%22%2C%22title%22%3A%22test_content_title%22%7D&schain=%7B%22ver%22%3A%221.0%22%2C%22complete%22%3A1%2C%22nodes%22%3A%5B%7B%22asi%22%3A%22example.com%22%2C%22sid%22%3A%220%22%2C%22hp%22%3A1%2C%22rid%22%3A%22bidrequestid%22%2C%22domain%22%3A%22example.com%22%7D%5D%7D&loc=http%3A%2F%2Fwww.test.com&_fw_video_context=&_fw_placement_type=null&_fw_plcmt_type=null;tpos=300&ptgt=a&slid=Midroll&slau=midroll&mind=30&maxd=60;`; - const actualUrl = `${request.url}?${request.data}`; - // Remove pvrn and vprn from both URLs before comparing - const cleanUrl = (url) => url.replace(/&pvrn=[^&]*/g, '').replace(/&vprn=[^&]*/g, ''); - expect(cleanUrl(actualUrl)).to.equal(cleanUrl(expectedUrl)); - }); - - it('should use otrb2 gpp if gpp not in bidder request', () => { - const bidderRequest2 = { - ortb2: { - regs: { - gpp: 'test_ortb2_gpp', - gpp_sid: 'test_ortb2_gpp_sid' - }, - site: { - content: { - id: 'test_content_id', - title: 'test_content_title' - } - } - } - }; - - const requests = spec.buildRequests(getBidRequests(), bidderRequest2); - expect(requests).to.be.an('array').that.is.not.empty; - const request = requests[0]; - const expectedUrl = `https://example.com/ad/g/1?nw=42015&resp=vast4&prof=42015%3Ajs_allinone_profile&csid=js_allinone_demo_site_section&caid=0&flag=%2Bplay%2Bfwssp%2Bemcr%2Bnucr%2Baeti%2Brema%2Bexvt%2Bfwpbjs&mode=live&vclr=js-7.11.0-prebid-${pbjs.version};_fw_player_width=1920&_fw_player_height=1080&_fw_bidfloor=2&_fw_bidfloorcur=USD&_fw_gdpr_consented_providers=test_providers&gpp=test_ortb2_gpp&gpp_sid=test_ortb2_gpp_sid&_fw_prebid_content=%7B%22id%22%3A%22test_content_id%22%2C%22title%22%3A%22test_content_title%22%7D&schain=%7B%22ver%22%3A%221.0%22%2C%22complete%22%3A1%2C%22nodes%22%3A%5B%7B%22asi%22%3A%22example.com%22%2C%22sid%22%3A%220%22%2C%22hp%22%3A1%2C%22rid%22%3A%22bidrequestid%22%2C%22domain%22%3A%22example.com%22%7D%5D%7D&_fw_video_context=&_fw_placement_type=null&_fw_plcmt_type=null;tpos=300&ptgt=a&slid=Midroll&slau=midroll&mind=30&maxd=60;`; - const actualUrl = `${request.url}?${request.data}`; - // Remove pvrn and vprn from both URLs before comparing - const cleanUrl = (url) => url.replace(/&pvrn=[^&]*/g, '').replace(/&vprn=[^&]*/g, ''); - expect(cleanUrl(actualUrl)).to.equal(cleanUrl(expectedUrl)); - }); - - it('should get bidfloor value from params if no getFloor method', () => { - const request = spec.buildRequests(getBidRequests()); - const payload = request[0].data; - expect(payload).to.include('_fw_bidfloor=2'); - expect(payload).to.include('_fw_bidfloorcur=USD'); - }); - - it('should return image type userSyncs with gdprConsent', () => { - const syncOptions = { - 'pixelEnabled': true - } - const userSyncs = spec.getUserSyncs(syncOptions, null, bidderRequest.gdprConsent, null, null); - expect(userSyncs).to.deep.equal([{ - type: 'image', - url: 'https://ads.stickyadstv.com/auto-user-sync?gdpr=1&gdpr_consent=consentString' - }]); - }); - - it('should return iframe type userSyncs with gdprConsent, uspConsent, gppConsent', () => { - const syncOptions = { - 'iframeEnabled': true - } - const userSyncs = spec.getUserSyncs(syncOptions, null, bidderRequest.gdprConsent, bidderRequest.uspConsent, bidderRequest.gppConsent); - expect(userSyncs).to.deep.equal([{ - type: 'iframe', - url: 'https://ads.stickyadstv.com/auto-user-sync?gdpr=1&gdpr_consent=consentString&us_privacy=uspConsentString&gpp=gppString&gpp_sid[]=8' - }]); - }); - }); - - describe('buildRequestsForVideoWithContextAndPlacement', () => { - it('should return input context and placement', () => { - const bidRequests = [{ - 'bidder': 'fwssp', - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'placement': 2, - 'plcmt': 3, - 'playerSize': [300, 600], - 'minduration': 30, - 'maxduration': 60, - } - }, - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'params': { - 'bidfloor': 2.00, - 'serverUrl': 'https://example.com/ad/g/1', - 'networkId': '42015', - 'profile': '42015:js_allinone_profile', - 'siteSectionId': 'js_allinone_demo_site_section', - 'flags': '+play', - 'videoAssetId': '0', - 'mode': 'live', - 'vclr': 'js-7.11.0-prebid-', - 'timePosition': 120, - } - }]; - const request = spec.buildRequests(bidRequests); - const payload = request[0].data; - expect(payload).to.include('_fw_video_context=outstream'); ; - expect(payload).to.include('_fw_placement_type=2'); - expect(payload).to.include('_fw_plcmt_type=3'); - }); - }); - - describe('getSDKVersion', () => { - it('should return the default sdk version when sdkVersion is missing', () => { - const bid = { - params: { - sdkVersion: '' - } - }; - expect(getSDKVersion(bid)).to.equal('7.11.0'); - }); - - it('should return the correct sdk version when sdkVersion is higher than the default', () => { - const bid = { - params: { - sdkVersion: '7.11.0' - } - }; - expect(getSDKVersion(bid)).to.equal('7.11.0'); - }); - - it('should return the default sdk version when sdkVersion is lower than the default', () => { - const bid = { - params: { - sdkVersion: '7.9.0' - } - }; - expect(getSDKVersion(bid)).to.equal('7.11.0'); - }); - - it('should return the default sdk version when sdkVersion is an invalid string', () => { - const bid = { - params: { - sdkVersion: 'abcdef' - } - }; - expect(getSDKVersion(bid)).to.equal('7.11.0'); - }); - - it('should return the correct sdk version when sdkVersion starts with v', () => { - const bid = { - params: { - sdkVersion: 'v7.11.0' - } - }; - expect(getSDKVersion(bid)).to.equal('7.11.0'); - }); - }); - - describe('formatAdHTML', () => { - it('should return the ad markup in formatAdHTML, with default value of false for showMuteButton and true for isMuted', () => { - const expectedAdHtml = -`
- -
`; - - const bidRequest = { - params: {}, - adUnitCode: 'test' - } - const actualAdHtml = formatAdHTML(bidRequest, [640, 480], ''); - expect(actualAdHtml).to.deep.equal(expectedAdHtml) - }); - - it('should take bid request showMuteButton, isMuted, and playerParams', () => { - const expectedAdHtml = -`
- -
`; - - const bidRequest = { - params: { - showMuteButton: true, - isMuted: false, - playerParams: { 'test-param': 'test-value' } - }, - adUnitCode: 'test' - } - const actualAdHtml = formatAdHTML(bidRequest, [640, 480], ''); - expect(actualAdHtml).to.deep.equal(expectedAdHtml) - }); - - it('should generate html with the AdManager stg url when env param has value fo stg in bid request', () => { - const expectedAdHtml = -`
- -
`; - - const bidRequest = { - params: { - env: 'stg' - }, - adUnitCode: 'test' - } - const actualAdHtml = formatAdHTML(bidRequest, [640, 480], ''); - expect(actualAdHtml).to.deep.equal(expectedAdHtml) - }); - - it('should use the correct version when sdkVersion is in bid params', () => { - const expectedAdHtml = -`
- -
`; - - const bidRequest = { - params: { - env: 'stg', - sdkVersion: '7.11.0' - }, - adUnitCode: 'test' - } - const actualAdHtml = formatAdHTML(bidRequest, [640, 480], ''); - expect(actualAdHtml).to.deep.equal(expectedAdHtml) - }); - }); - - describe('interpretResponseForBanner', () => { - const getBidRequests = () => { - return [{ - 'bidder': 'fwssp', - 'params': { - 'serverUrl': 'https://fwmrm.com/ad/g/1', - 'sdkVersion': '' - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 600] - ] - } - }, - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }] - }; - - const response = '' + - '' + - ' ' + - ' Adswizz' + - ' ' + - ' https://ads.stickyadstv.com/auto-user-sync?dealId=NRJ-PRO-12008' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' 00:00:09' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' ' + - ' 0.2000' + - ' ' + - ' ' + - ' ' + - ''; - - it('should get correct bid response', () => { - const request = spec.buildRequests(getBidRequests()); - const result = spec.interpretResponse(response, request[0]); - - expect(result[0].meta.advertiserDomains).to.deep.equal([]); - expect(result[0].dealId).to.equal('NRJ-PRO-00008'); - expect(result[0].campaignId).to.equal('SMF-WOW-55555'); - expect(result[0].bannerId).to.equal('12345'); - expect(result[0].requestId).to.equal('30b31c1838de1e'); - expect(result[0].cpm).to.equal('0.2000'); - expect(result[0].width).to.equal(300); - expect(result[0].height).to.equal(600); - expect(result[0].creativeId).to.equal('[28517153]'); - expect(result[0].currency).to.equal('EUR'); - expect(result[0].netRevenue).to.equal(true); - expect(result[0].ttl).to.equal(360); - }); - - it('handles nobid responses', () => { - const request = spec.buildRequests(getBidRequests()); - const response = ''; - const result = spec.interpretResponse(response, request[0]); - expect(result.length).to.equal(0); - }); - }); - - describe('getBidFloor function tests', () => { - const mockConfig = { - getConfig: (key) => { - if (key === 'floors.data.currency') return 'EUR'; - return null; - } - }; - - it('should use params.bidfloor and params.bidfloorcur when getFloor method is not available', () => { - const bidRequest = { - params: { - bidfloor: 1.5, - bidfloorcur: 'GBP' - } - }; - const result = getBidFloor(bidRequest, mockConfig); - expect(result.floor).to.equal(1.5); - expect(result.currency).to.equal('GBP'); - }); - - it('should use default values when params are missing and no getFloor method', () => { - const bidRequest = { - params: {} - }; - const result = getBidFloor(bidRequest, mockConfig); - expect(result.floor).to.equal(0); - expect(result.currency).to.equal('USD'); - }); - - it('should use getFloor method when available for banner mediaType', () => { - const bidRequest = { - params: { - bidfloor: 1.0, - bidfloorcur: 'USD' - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - getFloor: () => ({ - floor: 2.5, - currency: 'EUR' - }) - }; - const result = getBidFloor(bidRequest, mockConfig); - expect(result.floor).to.equal(2.5); - expect(result.currency).to.equal('EUR'); - }); - - it('should use getFloor method when available for video mediaType', () => { - const bidRequest = { - params: { - bidfloor: 1.0, - bidfloorcur: 'USD' - }, - mediaTypes: { - video: { - playerSize: [640, 480] - } - }, - getFloor: () => ({ - floor: 3.0, - currency: 'JPY' - }) - }; - const result = getBidFloor(bidRequest, mockConfig); - expect(result.floor).to.equal(3.0); - expect(result.currency).to.equal('JPY'); - }); - - it('should fallback to params when getFloor throws an error', () => { - const bidRequest = { - params: { - bidfloor: 1.75, - bidfloorcur: 'CAD' - }, - getFloor: () => { - throw new Error('getFloor error'); - } - }; - const result = getBidFloor(bidRequest, mockConfig); - expect(result.floor).to.equal(1.75); - expect(result.currency).to.equal('CAD'); - }); - - it('should fallback to params when getFloor returns invalid floor value', () => { - const bidRequest = { - params: { - bidfloor: 2.0, - bidfloorcur: 'AUD' - }, - getFloor: () => ({ - floor: 'invalid', - currency: 'EUR' - }) - }; - const result = getBidFloor(bidRequest, mockConfig); - expect(result.floor).to.equal(2.0); - expect(result.currency).to.equal('AUD'); - }); - - it('should use getFloor currency when floor is valid but currency is from getFloor', () => { - const bidRequest = { - params: { - bidfloor: 1.0 - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - getFloor: () => ({ - floor: 2.25, - currency: 'CHF' - }) - }; - const result = getBidFloor(bidRequest, mockConfig); - expect(result.floor).to.equal(2.25); - expect(result.currency).to.equal('CHF'); - }); - }); - - describe('bidfloor integration in buildRequests', () => { - it('should include bidfloor values from getBidFloor in banner requests', () => { - const bidRequests = [{ - 'bidder': 'fwssp', - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]] - } - }, - 'bidId': '30b31c1838de1e', - 'params': { - 'serverUrl': 'https://example.com/ad/g/1', - 'networkId': '42015', - 'profile': '42015:js_allinone_profile', - 'siteSectionId': 'js_allinone_demo_site_section', - 'videoAssetId': '0', - 'bidfloor': 1.25, - 'bidfloorcur': 'GBP' - } - }]; - - const request = spec.buildRequests(bidRequests); - const payload = request[0].data; - expect(payload).to.include('_fw_bidfloor=1.25'); - expect(payload).to.include('_fw_bidfloorcur=GBP'); - }); - - it('should include bidfloor values from getFloor method when available', () => { - const bidRequests = [{ - 'bidder': 'fwssp', - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'video': { - 'playerSize': [640, 480] - } - }, - 'bidId': '30b31c1838de1e', - 'params': { - 'serverUrl': 'https://example.com/ad/g/1', - 'networkId': '42015', - 'profile': '42015:js_allinone_profile', - 'siteSectionId': 'js_allinone_demo_site_section', - 'videoAssetId': '0', - 'bidfloor': 1.0, - 'bidfloorcur': 'USD' - }, - getFloor: () => ({ - floor: 2.75, - currency: 'EUR' - }) - }]; - - const request = spec.buildRequests(bidRequests); - const payload = request[0].data; - expect(payload).to.include('_fw_bidfloor=2.75'); - expect(payload).to.include('_fw_bidfloorcur=EUR'); - }); - - it('should handle zero bidfloor values correctly', () => { - const bidRequests = [{ - 'bidder': 'fwssp', - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]] - } - }, - 'bidId': '30b31c1838de1e', - 'params': { - 'serverUrl': 'https://example.com/ad/g/1', - 'networkId': '42015', - 'profile': '42015:js_allinone_profile', - 'siteSectionId': 'js_allinone_demo_site_section', - 'videoAssetId': '0' - }, - getFloor: () => ({ - floor: 0, - currency: 'USD' - }) - }]; - - const request = spec.buildRequests(bidRequests); - const payload = request[0].data; - expect(payload).to.include('_fw_bidfloor=0'); - expect(payload).to.include('_fw_bidfloorcur=USD'); - }); - - it('should include default bidfloor values when no floor configuration exists', () => { - const bidRequests = [{ - 'bidder': 'fwssp', - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]] - } - }, - 'bidId': '30b31c1838de1e', - 'params': { - 'serverUrl': 'https://example.com/ad/g/1', - 'networkId': '42015', - 'profile': '42015:js_allinone_profile', - 'siteSectionId': 'js_allinone_demo_site_section', - 'videoAssetId': '0' - } - }]; - - const request = spec.buildRequests(bidRequests); - const payload = request[0].data; - expect(payload).to.include('_fw_bidfloor=0'); - expect(payload).to.include('_fw_bidfloorcur=USD'); - }); - }); -}); diff --git a/test/spec/modules/gameraRtdProvider_spec.js b/test/spec/modules/gameraRtdProvider_spec.js deleted file mode 100644 index 63029d855..000000000 --- a/test/spec/modules/gameraRtdProvider_spec.js +++ /dev/null @@ -1,223 +0,0 @@ -import { submodule } from 'src/hook.js'; -import { getGlobal } from 'src/prebidGlobal.js'; -import * as utils from 'src/utils.js'; -import { subModuleObj } from 'modules/gameraRtdProvider.js'; - -describe('gameraRtdProvider', function () { - let logErrorSpy; - - beforeEach(function () { - logErrorSpy = sinon.spy(utils, 'logError'); - }); - - afterEach(function () { - logErrorSpy.restore(); - }); - - describe('subModuleObj', function () { - it('should have the correct module name', function () { - expect(subModuleObj.name).to.equal('gamera'); - }); - - it('successfully instantiates and returns true', function () { - expect(subModuleObj.init()).to.equal(true); - }); - }); - - describe('getBidRequestData', function () { - const reqBidsConfigObj = { - adUnits: [{ - code: 'test-div', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - ortb2Imp: { - ext: { - data: { - pbadslot: 'homepage-top-rect', - adUnitSpecificAttribute: '123', - } - } - }, - bids: [{ bidder: 'test' }] - }], - ortb2Fragments: { - global: { - site: { - name: 'example', - domain: 'page.example.com', - // OpenRTB 2.5 spec / Content Taxonomy - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'], - - page: 'https://page.example.com/here.html', - ref: 'https://ref.example.com', - keywords: 'power tools, drills', - search: 'drill', - content: { - userrating: '4', - data: [{ - name: 'www.dataprovider1.com', // who resolved the segments - ext: { - segtax: 7, // taxonomy used to encode the segments - cids: ['iris_c73g5jq96mwso4d8'] - }, - // the bare minimum are the IDs. These IDs are the ones from the new IAB Content Taxonomy v3 - segment: [{ id: '687' }, { id: '123' }] - }] - }, - ext: { - data: { // fields that aren't part of openrtb 2.6 - pageType: 'article', - category: 'repair' - } - } - }, - // this is where the user data is placed - user: { - keywords: 'a,b', - data: [{ - name: 'dataprovider.com', - ext: { - segtax: 4 - }, - segment: [{ - id: '1' - }] - }], - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - } - } - } - }; - - let callback; - - beforeEach(function () { - callback = sinon.spy(); - window.gamera = undefined; - }); - - it('should queue command when gamera.getPrebidSegments is not available', function () { - subModuleObj.getBidRequestData(reqBidsConfigObj, callback); - - expect(window.gamera).to.exist; - expect(window.gamera.cmd).to.be.an('array'); - expect(window.gamera.cmd.length).to.equal(1); - expect(callback.called).to.be.false; - - // our callback should be executed if command queue is flushed - window.gamera.cmd.forEach(command => command()); - expect(callback.calledOnce).to.be.true; - }); - - it('should call enrichAuction directly when gamera.getPrebidSegments is available', function () { - window.gamera = { - getPrebidSegments: () => ({}) - }; - - subModuleObj.getBidRequestData(reqBidsConfigObj, callback); - - expect(callback.calledOnce).to.be.true; - }); - - it('should handle errors gracefully', function () { - window.gamera = { - getPrebidSegments: () => { - throw new Error('Test error'); - } - }; - - subModuleObj.getBidRequestData(reqBidsConfigObj, callback); - - expect(logErrorSpy.calledWith('gameraRtdProvider', 'Error getting segments:')).to.be.true; - expect(callback.calledOnce).to.be.true; - }); - - describe('segment enrichment', function () { - const mockSegments = { - user: { - data: [{ - name: 'gamera.ai', - ext: { - segtax: 4, - }, - segment: [{ id: 'user-1' }] - }] - }, - site: { - keywords: 'gamera,article,keywords', - content: { - data: [{ - name: 'gamera.ai', - ext: { - segtax: 7, - }, - segment: [{ id: 'site-1' }] - }] - } - }, - adUnits: { - 'test-div': { - key: 'value', - ext: { - data: { - gameraSegment: 'ad-1', - } - } - } - } - }; - - beforeEach(function () { - window.gamera = { - getPrebidSegments: () => mockSegments - }; - }); - - it('should enrich ortb2Fragments with user data', function () { - subModuleObj.getBidRequestData(reqBidsConfigObj, callback); - - expect(reqBidsConfigObj.ortb2Fragments.global.user.data).to.deep.include(mockSegments.user.data[0]); - - // check if existing attributes are not overwritten - expect(reqBidsConfigObj.ortb2Fragments.global.user.data[0].ext.segtax).to.equal(4); - expect(reqBidsConfigObj.ortb2Fragments.global.user.data[0].segment[0].id).to.equal('1'); - expect(reqBidsConfigObj.ortb2Fragments.global.user.keywords).to.equal('a,b'); - expect(reqBidsConfigObj.ortb2Fragments.global.user.ext.data.registered).to.equal(true); - }); - - it('should enrich ortb2Fragments with site data', function () { - subModuleObj.getBidRequestData(reqBidsConfigObj, callback); - - expect(reqBidsConfigObj.ortb2Fragments.global.site.content.data).to.deep.include(mockSegments.site.content.data[0]); - expect(reqBidsConfigObj.ortb2Fragments.global.site.keywords).to.equal('gamera,article,keywords'); - - // check if existing attributes are not overwritten - expect(reqBidsConfigObj.ortb2Fragments.global.site.content.data[0].ext.segtax).to.equal(7); - expect(reqBidsConfigObj.ortb2Fragments.global.site.content.data[0].segment[0].id).to.equal('687'); - expect(reqBidsConfigObj.ortb2Fragments.global.site.ext.data.category).to.equal('repair'); - expect(reqBidsConfigObj.ortb2Fragments.global.site.content.userrating).to.equal('4'); - }); - - it('should enrich adUnits with segment data', function () { - subModuleObj.getBidRequestData(reqBidsConfigObj, callback); - - expect(reqBidsConfigObj.adUnits[0].ortb2Imp.key).to.equal('value'); - expect(reqBidsConfigObj.adUnits[0].ortb2Imp.ext.data.gameraSegment).to.equal('ad-1'); - - // check if existing attributes are not overwritten - expect(reqBidsConfigObj.adUnits[0].ortb2Imp.ext.data.adUnitSpecificAttribute).to.equal('123'); - expect(reqBidsConfigObj.adUnits[0].ortb2Imp.ext.data.pbadslot).to.equal('homepage-top-rect'); - }); - }); - }); -}); diff --git a/test/spec/modules/gammaBidAdapter_spec.js b/test/spec/modules/gammaBidAdapter_spec.js deleted file mode 100644 index bff11ded9..000000000 --- a/test/spec/modules/gammaBidAdapter_spec.js +++ /dev/null @@ -1,107 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/gammaBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; - -describe('gammaBidAdapter', function() { - const adapter = newBidder(spec); - - const bid = { - 'bidder': 'gamma', - 'params': { - siteId: '1398219351', - zoneId: '1398219417', - region: 'SGP' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250] - ], - 'bidId': '23beaa6af6cdde', - 'bidderRequestId': '19c0c1efdf37e7', - 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', - }; - const bidArray = [bid]; - - describe('isBidRequestValid', () => { - it('should return true when required params found', () => { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when require params are not passed', () => { - const invalidBid = Object.assign({}, bid); - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when params not passed correctly', () => { - bid.params.siteId = ''; - bid.params.zoneId = ''; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', () => { - it('should attempt to send bid requests to the endpoint via GET', () => { - const requests = spec.buildRequests(bidArray); - requests.forEach(function(requestItem) { - expect(requestItem.method).to.equal('GET'); - expect(requestItem.url).to.match(new RegExp(`hb.gammaplatform.com`)); - }); - }); - }); - - describe('interpretResponse', () => { - let serverResponse; - - beforeEach(() => { - serverResponse = { - body: { - 'id': '23beaa6af6cdde', - 'bid': '5611802021800040585', - 'type': 'banner', - 'cur': 'USD', - 'seatbid': [{ - 'seat': '5611802021800040585', - 'bid': [{ - 'id': '1515999070', - 'impid': '1', - 'price': 0.45, - 'adm': '', - 'adid': '1515999070', - 'dealid': 'gax-paj2qarjf2g', - 'h': 250, - 'w': 300, - 'adomain': ['testdomain.com'] - }] - }] - } - }; - }) - - it('should get the correct bid response', () => { - const expectedResponse = [{ - 'requestId': '23beaa6af6cdde', - 'cpm': 0.45, - 'width': 300, - 'height': 250, - 'creativeId': '1515999070', - 'dealId': 'gax-lvpjgs5b9k4n', - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'ad': '', - 'meta': {'advertiserDomains': ['testdomain.com']} - }]; - const result = spec.interpretResponse(serverResponse); - expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); - }); - - it('handles empty bid response', () => { - const response = { - body: {} - }; - const result = spec.interpretResponse(response); - expect(result.length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/gamoshiBidAdapter_spec.js b/test/spec/modules/gamoshiBidAdapter_spec.js deleted file mode 100644 index c57000b4d..000000000 --- a/test/spec/modules/gamoshiBidAdapter_spec.js +++ /dev/null @@ -1,702 +0,0 @@ -import {expect} from 'chai'; -import {spec, helper} from 'modules/gamoshiBidAdapter.js'; -import * as utils from 'src/utils.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; - -const supplyPartnerId = '123'; -const adapter = newBidder(spec); - -describe('GamoshiAdapter', () => { - let sandBox; - let schainConfig, - bidRequest, - bannerBidRequest, - bannerRequestWithEids, - videoBidRequest, - rtbResponse, - videoResponse, - gdprConsent; - - beforeEach(() => { - sandBox = sinon.createSandbox(); - sandBox.stub(utils, 'logError'); - sandBox.stub(utils, 'logWarn'); - schainConfig = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'indirectseller.com', - 'sid': '00001', - 'hp': 1 - }, - - { - 'asi': 'indirectseller-2.com', - 'sid': '00002', - 'hp': 2 - } - ] - }; - - bidRequest = { - 'adUnitCode': 'adunit-code', - 'auctionId': '1d1a030790a475', - 'mediaTypes': { - banner: {} - }, - 'params': { - 'supplyPartnerId': supplyPartnerId - }, - 'sizes': [[300, 250], [300, 600]], - ortb2Imp: { - ext: { - tid: 'a123456789', - } - }, - refererInfo: {referer: 'http://examplereferer.com'}, - gdprConsent: { - consentString: 'some string', - gdprApplies: true - }, - ortb2: { - source: { - ext: { - schain: schainConfig - } - } - }, - uspConsent: 'gamoshiCCPA', - } - bannerBidRequest = { - 'adUnitCode': 'adunit-code', - 'auctionId': 'auction-id-12345', - 'mediaTypes': { - banner: {} - }, - 'params': { - 'supplyPartnerId': supplyPartnerId - }, - 'sizes': [[300, 250], [300, 600]], - 'transactionId': '1d1a030790a475', - 'bidId': 'request-id-12345', - refererInfo: {referer: 'http://examplereferer.com'} - }; - - bannerRequestWithEids = { - 'adUnitCode': 'adunit-code', - 'auctionId': 'auction-id-12345', - 'mediaTypes': { - banner: {} - }, - 'params': { - 'supplyPartnerId': supplyPartnerId - }, - userIdAsEids: [ - { - source: '1.test.org', - uids: [{ - id: '11111', - atype: 1, - }] - }, - { - source: '2.test.org', - uids: [{ - id: '11111', - atype: 1, - }] - } - ], - 'sizes': [[300, 250], [300, 600]], - 'transactionId': '1d1a030790a475', - 'bidId': 'request-id-12345', - refererInfo: {referer: 'http://examplereferer.com'} - }; - - videoBidRequest = { - 'adUnitCode': 'adunit-code', - 'auctionId': 'auction-id-12345', - 'mediaTypes': { - video: {} - }, - 'params': { - 'supplyPartnerId': supplyPartnerId - }, - 'sizes': [[300, 250], [300, 600]], - 'transactionId': 'a123456789', - 'bidId': '111', - refererInfo: {referer: 'http://examplereferer.com'} - }; - rtbResponse = { - 'id': 'request-id-12345', - 'bidid': 'bid-id-12345', - 'cur': 'USD', - 'ext': { - 'utrk': [ - {'type': 'iframe', 'url': '//rtb.gamoshi.io/user/sync/1?gdpr=[GDPR]&consent=[CONSENT]&usp=[US_PRIVACY]'}, - {'type': 'image', 'url': '//rtb.gamoshi.io/user/sync/2'} - ] - }, - 'seatbid': [ - { - 'seat': 'seat1', - 'group': 0, - 'bid': [ - { - 'id': '0', - 'impid': '1', - 'price': 2.016, - 'adid': '579ef31bfa788b9d2000d562', - 'nurl': 'https://rtb.gamoshi.io/pix/monitoring/win_notice/imp_5b05b9fde4b09084267a556f/im.gif?r=imp_5b05b9fde4b09084267a556f&i=1&a=579ef31bfa788b9d2000d562&b=0', - 'adm': '↵↵↵↵↵↵↵↵↵↵↵↵↵↵↵↵↵↵↵↵↵', - 'adomain': ['aaa.com'], - 'cid': '579ef268fa788b9d2000d55c', - 'crid': '579ef31bfa788b9d2000d562', - 'attr': [], - 'h': 600, - 'w': 120, - 'ext': { - 'vast_url': 'http://my.vast.com', - 'utrk': [ - {'type': 'iframe', 'url': '//p.partner1.io/user/sync/1'} - ] - } - } - ] - }, - { - 'seat': 'seat2', - 'group': 0, - 'bid': [ - { - 'id': '1', - 'impid': '1', - 'price': 3, - 'adid': '542jlhdfd2112jnjf3x', - 'nurl': 'https://rtb.gamoshi.io/pix/monitoring/win_notice/imp_5b05b9fde4b09084267a556f/im.gif?r=imp_5b05b9fde4b09084267a556f&i=1&a=579ef31bfa788b9d2000d562&b=0', - 'adm': ' ', - 'adomain': ['bbb.com'], - 'cid': 'fgdlwjh2498ydjhg1', - 'crid': 'kjh34297ydh2133d', - 'attr': [], - 'h': 250, - 'w': 300, - 'ext': { - 'utrk': [ - {'type': 'image', 'url': '//p.partner2.io/user/sync/1'} - ] - } - } - ] - } - ] - }; - - videoResponse = { - 'id': 'request-id-12345', - 'bidid': 'bid-id-12345', - 'cur': 'USD', - 'seatbid': [ - { - 'seat': '3668', - 'group': 0, - 'bid': [ - { - 'id': 'gb_1', - 'impid': '1', - 'price': 5.0, - 'adid': '1274', - 'nurl': 'https://rtb.gamoshi.io/pix/1275/win_notice/imp_5c24924de4b0d106447af333/im.gif?r=imp_5c24924de4b0d106447af333&i=afbb5852-7cea-4a81-aa9a-a41aab505c23&a=1274&b=gb_1', - 'adomain': [], - 'adm': '\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n', - 'cid': '3668', - 'crid': '1274', - 'cat': [], - 'attr': [], - 'h': 250, - 'w': 300, - 'ext': { - 'vast_url': 'https://rtb.gamoshi.io/pix/1275/vast_o/imp_5c24924de4b0d106447af333/im.xml?r=imp_5c24924de4b0d106447af333&i=afbb5852-7cea-4a81-aa9a-a41aab505c23&a=1274&b=gb_1&w=300&h=250&vatu=aHR0cHM6Ly9zdGF0aWMuZ2FtYmlkLmlvL2RlbW8vdmFzdC54bWw&vwarv', - 'imptrackers': [ - 'https://rtb.gamoshi.io/pix/1275/imp/imp_5c24924de4b0d106447af333/im.gif?r=imp_5c24924de4b0d106447af333&i=afbb5852-7cea-4a81-aa9a-a41aab505c23&a=1274&b=gb_1'] - } - } - ] - } - ], - 'ext': { - 'utrk': [{ - 'type': 'image', - 'url': 'https://rtb.gamoshi.io/pix/1275/scm?cb=1545900621675&gdpr=[GDPR]&consent=[CONSENT]&us_privacy=[US_PRIVACY]' - }] - } - }; - - gdprConsent = { - gdprApplies: true, - consentString: 'consent string' - }; - }); - - afterEach(() => { - sandBox.restore() - config.resetConfig(); - }); - - describe('helper.getBidFloor', () => { - it('should return null when getFloor is not a function and no bidfloor param', () => { - const bid = { params: {} }; - expect(helper.getBidFloor(bid)).to.equal(null); - }); - - it('should return bidfloor param when getFloor is not a function', () => { - const bid = { params: { bidfloor: 1.5 } }; - expect(helper.getBidFloor(bid)).to.equal(1.5); - }); - - it('should use getFloor function with currency support', () => { - const bid = { - params: {}, - getFloor: () => ({ currency: 'EUR', floor: 2.0 }) - }; - expect(helper.getBidFloor(bid, 'EUR')).to.equal(2.0); - }); - - it('should return null when getFloor returns invalid currency', () => { - const bid = { - params: {}, - getFloor: () => ({ currency: 'USD', floor: 2.0 }) - }; - expect(helper.getBidFloor(bid, 'EUR')).to.equal(null); - }); - - it('should return null when getFloor returns invalid floor', () => { - const bid = { - params: {}, - getFloor: () => ({ currency: 'USD', floor: NaN }) - }; - expect(helper.getBidFloor(bid, 'USD')).to.equal(null); - }); - }); - - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', () => { - it('should validate supply-partner ID', () => { - expect(spec.isBidRequestValid({params: {}})).to.equal(false); - expect(spec.isBidRequestValid({params: {supplyPartnerId: 123}})).to.equal(true); - expect(spec.isBidRequestValid({params: {supplyPartnerId: '123'}})).to.equal(true); - expect(spec.isBidRequestValid({params: {supply_partner_id: 123}})).to.equal(true); - expect(spec.isBidRequestValid({params: {supply_partner_id: '123'}})).to.equal(true); - expect(spec.isBidRequestValid({params: {inventory_id: 123}})).to.equal(true); - expect(spec.isBidRequestValid({params: {inventory_id: '123'}})).to.equal(true); - expect(spec.isBidRequestValid({params: {inventory_id: 'kukuk1212'}})).to.equal(false); - }); - - it('should validate RTB endpoint', () => { - expect(spec.isBidRequestValid({params: {supplyPartnerId: '123'}})).to.equal(true); // RTB endpoint has a default - expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', rtbEndpoint: 123}})).to.equal(false); - expect(spec.isBidRequestValid({ - params: { - supplyPartnerId: '123', - rtbEndpoint: 'https://some.url.com' - } - })).to.equal(true); - }); - - it('should validate bid floor', () => { - // bidfloor can be omitted - should be valid - expect(spec.isBidRequestValid({params: {supplyPartnerId: '123'}})).to.equal(true); - - // bidfloor as string should be invalid - expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', bidfloor: '123'}})).to.equal(true); - - // bidfloor as zero should be invalid (not positive) - expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', bidfloor: 0}})).to.equal(false); - - // bidfloor as negative number should be invalid - expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', bidfloor: -0.5}})).to.equal(false); - - // bidfloor as positive number should be valid - expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', bidfloor: 0.1}})).to.equal(true); - expect(spec.isBidRequestValid({params: {supplyPartnerId: '123', bidfloor: 1.5}})).to.equal(true); - // - // const getFloorResponse = {currency: 'USD', floor: 5}; - // let testBidRequest = deepClone(bidRequest); - // let request = spec.buildRequests([testBidRequest], bidRequest)[0]; - // - // // 1. getBidFloor not exist AND bidfloor not exist - return 0 - // let payload = request.data; - // expect(payload.imp[0].bidfloor).to.exist.and.equal(0); - // - // // 2. getBidFloor not exist AND bidfloor exist - use bidfloor property - // testBidRequest = deepClone(bidRequest); - // testBidRequest.params = { - // 'bidfloor': 0.3 - // }; - // request = spec.buildRequests([testBidRequest], bidRequest)[0]; - // payload = request.data; - // expect(payload.imp[0].bidfloor).to.exist.and.to.equal(0.3) - // - // // 3. getBidFloor exist AND bidfloor not exist - use getFloor method - // testBidRequest = deepClone(bidRequest); - // testBidRequest.getFloor = () => getFloorResponse; - // request = spec.buildRequests([testBidRequest], bidRequest)[0]; - // payload = request.data; - // expect(payload.imp[0].bidfloor).to.exist.and.to.equal(5) - // - // // 4. getBidFloor exist AND bidfloor exist -> use getFloor method - // testBidRequest = deepClone(bidRequest); - // testBidRequest.getFloor = () => getFloorResponse; - // testBidRequest.params = { - // 'bidfloor': 0.3 - // }; - // request = spec.buildRequests([testBidRequest], bidRequest)[0]; - // payload = request.data; - // expect(payload.imp[0].bidfloor).to.exist.and.to.equal(5) - }); - }); - - describe('buildRequests', () => { - it('returns an array', () => { - let response; - response = spec.buildRequests([]); - expect(Array.isArray(response)).to.equal(true); - expect(response.length).to.equal(0); - response = spec.buildRequests([bidRequest], bidRequest); - expect(Array.isArray(response)).to.equal(true); - expect(response.length).to.equal(1); - const adUnit1 = Object.assign({}, utils.deepClone(bidRequest), {auctionId: '1', adUnitCode: 'a'}); - const adUnit2 = Object.assign({}, utils.deepClone(bidRequest), {auctionId: '1', adUnitCode: 'b'}); - response = spec.buildRequests([adUnit1, adUnit2], bidRequest); - expect(Array.isArray(response)).to.equal(true); - expect(response.length).to.equal(2); - }); - - it('targets correct endpoint', () => { - let response; - response = spec.buildRequests([bidRequest], bidRequest)[0]; - expect(response.method).to.equal('POST'); - expect(response.url).to.match(new RegExp(`^https://rtb\\.gamoshi\\.io/r/${supplyPartnerId}/bidr\\?rformat=open_rtb&reqformat=rtb_json&bidder=prebid$`, 'g')); - const bidRequestWithEndpoint = utils.deepClone(bidRequest); - bidRequestWithEndpoint.params.rtbEndpoint = 'https://rtb2.gamoshi.io/a12'; - response = spec.buildRequests([bidRequestWithEndpoint], bidRequest)[0]; - expect(response.url).to.match(new RegExp(`^https://rtb2\\.gamoshi\\.io/a12/r/${supplyPartnerId}/bidr\\?rformat=open_rtb&reqformat=rtb_json&bidder=prebid$`, 'g')); - }); - - it('builds request correctly', () => { - let bidRequest2 = utils.deepClone(bidRequest); - Object.assign(bidRequest2.refererInfo, { - page: 'http://www.test.com/page.html', - domain: 'www.test.com', - ref: 'http://referrer.com' - }) - let response = spec.buildRequests([bidRequest], bidRequest2)[0]; - - expect(response.data.imp.length).to.equal(1); - expect(response.data.imp[0].tagid).to.equal(bidRequest.adUnitCode); - expect(response.data.imp[0].bidfloor).to.equal(0); - expect(response.data.imp[0].bidfloorcur).to.equal('USD'); - expect(response.data.ext.gamoshi.supplyPartnerId).to.equal(supplyPartnerId); - const bidRequestWithInstlEquals1 = utils.deepClone(bidRequest); - bidRequestWithInstlEquals1.params.instl = 1; - response = spec.buildRequests([bidRequestWithInstlEquals1], bidRequest2)[0]; - expect(response.data.imp[0].instl).to.equal(bidRequestWithInstlEquals1.params.instl); - const bidRequestWithBidfloorEquals1 = utils.deepClone(bidRequest); - bidRequestWithBidfloorEquals1.params.bidfloor = 1; - response = spec.buildRequests([bidRequestWithBidfloorEquals1], bidRequest2)[0]; - expect(response.data.imp[0].bidfloor).to.equal(bidRequestWithBidfloorEquals1.params.bidfloor); - }); - - it('builds request banner object correctly', () => { - let response; - const bidRequestWithBanner = utils.deepClone(bidRequest); - - bidRequestWithBanner.mediaTypes = { - banner: { - sizes: [[300, 250], [120, 600]] - } - }; - response = spec.buildRequests([bidRequestWithBanner], bidRequest)[0]; - expect(response.data.imp[0].banner.w).to.equal(bidRequestWithBanner.mediaTypes.banner.sizes[0][0]); - expect(response.data.imp[0].banner.h).to.equal(bidRequestWithBanner.mediaTypes.banner.sizes[0][1]); - const bidRequestWithPosEquals1 = utils.deepClone(bidRequestWithBanner); - bidRequestWithPosEquals1.params.pos = 1; - response = spec.buildRequests([bidRequestWithPosEquals1], bidRequest)[0]; - expect(response.data.imp[0].banner.pos).to.equal(bidRequestWithPosEquals1.params.pos); - }); - - it('builds request video object correctly', () => { - const bidRequestWithVideo = utils.deepClone(videoBidRequest); - bidRequestWithVideo.mediaTypes = { - video: { - playerSize: [[302, 252]], - mimes: ['video/mpeg'], - pos: 0, - playbackmethod: 1, - minduration: 30, - plcmt: 1, - startdelay: 1, - } - }; - let request = spec.buildRequests([bidRequestWithVideo], videoBidRequest)[0]; - expect(request.data.imp[0].video.w).to.equal(bidRequestWithVideo.mediaTypes.video.playerSize[0][0]); - expect(request.data.imp[0].video.h).to.equal(bidRequestWithVideo.mediaTypes.video.playerSize[0][1]); - expect(request.data.imp[0].video.pos).to.equal(0); - expect(request.data.imp[0].video.mimes[0]).to.equal(bidRequestWithVideo.mediaTypes.video.mimes[0]); - expect(request.data.imp[0].video.skip).to.not.exist; - expect(request.data.imp[0].video.plcmt).to.equal(1); - expect(request.data.imp[0].video.minduration).to.equal(30); - expect(request.data.imp[0].video.playbackmethod).to.equal(1); - expect(request.data.imp[0].video.startdelay).to.equal(1); - bidRequestWithVideo.mediaTypes = { - video: { - playerSize: [302, 252], - mimes: ['video/mpeg'], - skip: 1, - plcmt: 1, - minduration: 1, - playbackmethod: 1, - startdelay: 1, - }, - }; - request = spec.buildRequests([bidRequestWithVideo], bidRequest)[0]; - expect(request.data.imp[0].video.w).to.equal(bidRequestWithVideo.mediaTypes.video.playerSize[0]); - expect(request.data.imp[0].video.h).to.equal(bidRequestWithVideo.mediaTypes.video.playerSize[1]); - bidRequestWithVideo.mediaTypes.video.pos = 1; - request = spec.buildRequests([bidRequestWithVideo], bidRequest)[0]; - expect(request.data.imp[0].video.pos).to.equal(1); - }); - - it('builds request video object correctly with context', () => { - const bidRequestWithVideo = utils.deepClone(bidRequest); - bidRequestWithVideo.mediaTypes = { - video: { - context: 'instream', - mimes: ['video/mpeg'], - skip: 1, - plcmt: 1, - minduration: 1, - playbackmethod: 1, - startdelay: 1, - } - }; - let resultingRequest = spec.buildRequests([bidRequestWithVideo], bidRequest)[0]; - expect(resultingRequest.data.imp[0].video.ext.context).to.equal('instream'); - - const bidRequestWithPosEquals1 = utils.deepClone(bidRequestWithVideo); - bidRequestWithPosEquals1.mediaTypes.video.context = 'outstream'; - resultingRequest = spec.buildRequests([bidRequestWithPosEquals1], bidRequest)[0]; - expect(resultingRequest.data.imp[0].video.ext.context).to.equal('outstream'); - - const bidRequestWithPosEquals2 = utils.deepClone(bidRequestWithVideo); - bidRequestWithPosEquals2.mediaTypes.video.context = null; - resultingRequest = spec.buildRequests([bidRequestWithPosEquals2], bidRequest)[0]; - expect(resultingRequest.data.imp[0].video?.ext.context).to.equal(null); - }); - - it('builds request video object correctly with multi-dimensions size array', () => { - let resultingRequest; - const bidRequestWithVideo = utils.deepClone(videoBidRequest); - bidRequestWithVideo.mediaTypes.video = { - playerSize: [[304, 254], [305, 255]], - mimes: ['video/mpeg'], - skip: 1, - plcmt: 1, - minduration: 1, - playbackmethod: 1, - startdelay: 1, - }; - resultingRequest = spec.buildRequests([bidRequestWithVideo], videoBidRequest)[0]; - expect(resultingRequest.data.imp[0].video.plcmt).to.equal(1); - const bidRequestWithPosEquals1 = utils.deepClone(bidRequestWithVideo); - bidRequestWithPosEquals1.mediaTypes.video.plcmt = 4; - resultingRequest = spec.buildRequests([bidRequestWithPosEquals1], bidRequest)[0]; - expect(resultingRequest.data.imp[0].video.plcmt).to.equal(4); - }); - - it('builds request with standard ORTB GDPR handling', () => { - let response = spec.buildRequests([bidRequest], bidRequest)[0]; - // GDPR is now handled by standard ORTB converter through bidderRequest.ortb2 - // We just verify the request is built without custom GDPR extensions - expect(response.data.ext.gamoshi.supplyPartnerId).to.equal(supplyPartnerId); - }); - - it('handles error when supplyPartnerId is missing', () => { - const invalidBidRequest = utils.deepClone(bidRequest); - delete invalidBidRequest.params.supplyPartnerId; - - const response = spec.buildRequests([invalidBidRequest], bidRequest); - expect(response.length).to.equal(0); - expect(utils.logError.calledWith('Gamoshi: supplyPartnerId is required')).to.be.true; - }); - - it('handles error when ORTB conversion fails', () => { - const invalidBidRequest = utils.deepClone(bidRequest); - // Create a scenario that would cause ORTB conversion to fail - invalidBidRequest.mediaTypes = null; - const response = spec.buildRequests([invalidBidRequest], bidRequest); - expect(response.length).to.equal(0); - }); - }); - - describe('interpretResponse', () => { - it('returns an empty array on missing response', () => { - let response = spec.interpretResponse(undefined, {bidRequest: bannerBidRequest}); - expect(Array.isArray(response)).to.equal(true); - expect(response.length).to.equal(0); - - response = spec.interpretResponse({}, {bidRequest: bannerBidRequest}); - expect(Array.isArray(response)).to.equal(true); - expect(response.length).to.equal(0); - - // const invalidResponse = {body: 'invalid string response'}; - // response = spec.interpretResponse(invalidResponse, {bidRequest: bannerBidRequest}); - // expect(Array.isArray(response)).to.equal(true); - // expect(response.length).to.equal(0); - // expect(utils.logError.calledWith('Gamoshi: Invalid response format')).to.be.true; - // - // const malformedResponse = {body: {seatbid: 'invalid'}}; - // response = spec.interpretResponse(malformedResponse, {bidRequest: bannerBidRequest}); - // - // expect(Array.isArray(response)).to.equal(true); - // expect(response.length).to.equal(0); - // - // const emptyResponse = {body: {}}; - // response = spec.interpretResponse(emptyResponse, {bidRequest: bannerBidRequest}); - // expect(Array.isArray(response)).to.equal(true); - // expect(response.length).to.equal(0); - }); - - it('aggregates banner bids from all seat bids', () => { - const mockOrtbRequest = { - imp: [{ id: '1', tagid: bannerBidRequest.adUnitCode }] - }; - const response = spec.interpretResponse({body: rtbResponse}, {data: mockOrtbRequest, bidRequest: bannerBidRequest}); - expect(Array.isArray(response)).to.equal(true); - // The ORTB converter handles response processing, just verify it returns an array - }); - - it('aggregates video bids from all seat bids', () => { - const mockOrtbRequest = { - imp: [{ id: '1', tagid: videoBidRequest.adUnitCode }] - }; - const response = spec.interpretResponse({body: videoResponse}, {data: mockOrtbRequest, bidRequest: videoBidRequest}); - expect(Array.isArray(response)).to.equal(true); - // The ORTB converter handles response processing, just verify it returns an array - }); - - it('aggregates user-sync pixels', () => { - const response = spec.getUserSyncs({}, [{body: rtbResponse}]); - expect(Array.isArray(response)).to.equal(true); - expect(response.length).to.equal(4); - expect(response[0].type).to.equal(rtbResponse.ext.utrk[0].type); - expect(response[0].url).to.equal('//rtb.gamoshi.io/user/sync/1?gdpr=0&consent=&usp='); - expect(response[1].type).to.equal(rtbResponse.ext.utrk[1].type); - expect(response[1].url).to.equal('//rtb.gamoshi.io/user/sync/2'); - expect(response[2].type).to.equal(rtbResponse.seatbid[0].bid[0].ext.utrk[0].type); - expect(response[2].url).to.equal('//p.partner1.io/user/sync/1'); - expect(response[3].type).to.equal(rtbResponse.seatbid[1].bid[0].ext.utrk[0].type); - expect(response[3].url).to.equal('//p.partner2.io/user/sync/1'); - }); - - it('supports configuring outstream renderers', () => { - const videoRequest = utils.deepClone(videoBidRequest); - videoRequest.mediaTypes.video.context = 'outstream'; - const mockOrtbRequest = { - imp: [{ id: '1', tagid: videoRequest.adUnitCode }] - }; - const result = spec.interpretResponse({body: videoResponse}, {data: mockOrtbRequest, bidRequest: videoRequest}); - expect(Array.isArray(result)).to.equal(true); - }); - - it('validates in/existing of gdpr consent', () => { - let result = spec.getUserSyncs({}, [{body: videoResponse}], gdprConsent, 'gamoshiCCPA'); - // print result - - expect(result).to.be.an('array'); - expect(result.length).to.equal(1); - expect(result[0].type).to.equal('image'); - expect(result[0].url).to.equal('https://rtb.gamoshi.io/pix/1275/scm?cb=1545900621675&gdpr=1&consent=consent%20string&us_privacy=gamoshiCCPA'); - - gdprConsent.gdprApplies = false; - result = spec.getUserSyncs({}, [{body: videoResponse}], gdprConsent, 'gamoshiCCPA'); - expect(result).to.be.an('array'); - expect(result.length).to.equal(1); - expect(result[0].type).to.equal('image'); - expect(result[0].url).to.equal('https://rtb.gamoshi.io/pix/1275/scm?cb=1545900621675&gdpr=0&consent=&us_privacy=gamoshiCCPA'); - - videoResponse.ext.utrk[0].url = 'https://rtb.gamoshi.io/pix/1275/scm'; - result = spec.getUserSyncs({}, [{body: videoResponse}], gdprConsent); - expect(result).to.be.an('array'); - expect(result.length).to.equal(1); - expect(result[0].type).to.equal('image'); - expect(result[0].url).to.equal('https://rtb.gamoshi.io/pix/1275/scm'); - }); - - it('validates existence of gdpr, gdpr consent and usp consent', () => { - let result = spec.getUserSyncs({}, [{body: videoResponse}], gdprConsent, 'gamoshiCCPA'); - expect(result).to.be.an('array'); - expect(result.length).to.equal(1); - expect(result[0].type).to.equal('image'); - expect(result[0].url).to.equal('https://rtb.gamoshi.io/pix/1275/scm?cb=1545900621675&gdpr=1&consent=consent%20string&us_privacy=gamoshiCCPA'); - - gdprConsent.gdprApplies = false; - result = spec.getUserSyncs({}, [{body: videoResponse}], gdprConsent, ''); - expect(result).to.be.an('array'); - expect(result.length).to.equal(1); - expect(result[0].type).to.equal('image'); - expect(result[0].url).to.equal('https://rtb.gamoshi.io/pix/1275/scm?cb=1545900621675&gdpr=0&consent=&us_privacy='); - - videoResponse.ext.utrk[0].url = 'https://rtb.gamoshi.io/pix/1275/scm'; - result = spec.getUserSyncs({}, [{body: videoResponse}], gdprConsent); - expect(result).to.be.an('array'); - expect(result.length).to.equal(1); - expect(result[0].type).to.equal('image'); - expect(result[0].url).to.equal('https://rtb.gamoshi.io/pix/1275/scm'); - }); - - it('handles invalid response format gracefully', () => { - const invalidResponse = { body: 'invalid string response' }; - const response = spec.interpretResponse(invalidResponse, { bidRequest: bannerBidRequest }); - expect(Array.isArray(response)).to.equal(true); - expect(response.length).to.equal(0); - // expect(utils.logError.calledWith('Gamoshi: Invalid response format or empty seatbid array')).to.be.true; - }); - - it('handles ORTB converter errors gracefully', () => { - const malformedResponse = { body: { seatbid: 'invalid' } }; - const response = spec.interpretResponse(malformedResponse, { bidRequest: bannerBidRequest }); - expect(Array.isArray(response)).to.equal(true); - expect(response.length).to.equal(0); - }); - - it('enhances video bids with metadata from bid.ext.video', () => { - const videoResponseWithMeta = utils.deepClone(videoResponse); - videoResponseWithMeta.seatbid[0].bid[0].ext.video = { - duration: 30, - bitrate: 1000, - protocol: 'VAST 3.0' - }; - const mockOrtbRequest = { - imp: [{ id: '1', tagid: videoBidRequest.adUnitCode }] - }; - const response = spec.interpretResponse({body: videoResponseWithMeta}, {data: mockOrtbRequest, bidRequest: videoBidRequest}); - expect(Array.isArray(response)).to.equal(true); - }); - - it('returns empty array when ORTB converter returns non-array', () => { - // Mock a scenario where ORTB converter returns undefined or null - const emptyResponse = { body: {} }; - const response = spec.interpretResponse(emptyResponse, { bidRequest: bannerBidRequest }); - expect(Array.isArray(response)).to.equal(true); - expect(response.length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/genericAnalyticsAdapter_spec.js b/test/spec/modules/genericAnalyticsAdapter_spec.js deleted file mode 100644 index 72ec0e10d..000000000 --- a/test/spec/modules/genericAnalyticsAdapter_spec.js +++ /dev/null @@ -1,287 +0,0 @@ -import {defaultHandler, GenericAnalytics} from '../../../modules/genericAnalyticsAdapter.js'; -import * as events from 'src/events.js'; -import {EVENTS} from 'src/constants.js'; - -const {AUCTION_INIT, BID_RESPONSE} = EVENTS; - -describe('Generic analytics', () => { - describe('adapter', () => { - let adapter, sandbox, clock; - beforeEach(() => { - sandbox = sinon.createSandbox(); - sandbox.stub(events, 'getEvents').returns([]); - clock = sandbox.useFakeTimers(); - adapter = new GenericAnalytics(); - }); - - afterEach(() => { - adapter.disableAnalytics(); - sandbox.restore(); - clock.runAll(); - clock.restore(); - }); - - describe('configuration', () => { - it('should be accepted if valid', () => { - adapter.enableAnalytics({ - options: { - url: 'mock', - method: 'GET', - batchSize: 123, - batchDelay: 321 - } - }); - expect(adapter.enabled).to.be.true; - }); - - describe('should not work if', () => { - afterEach(function() { - expect(adapter.enabled).to.equal(false, this.currentTest.title); - }); - - it('neither handler nor url are specified', () => { - adapter.enableAnalytics({}); - }); - - ['batchSize', 'batchDelay', 'handler'].forEach(option => { - it(`${option} is not valid`, () => { - adapter.enableAnalytics({ - options: { - url: 'mock', - [option]: false - } - }); - }); - }); - - it('method is not GET or POST', () => { - adapter.enableAnalytics({ - options: { - url: 'mock', - method: 'PATCH' - } - }); - }); - - it('events is not an object', () => { - adapter.enableAnalytics({ - options: { - url: 'mock', - events: null - } - }); - }); - - it('events\' properties are not functions', () => { - adapter.enableAnalytics({ - options: { - url: 'mock', - events: { - mockEvent: null - } - } - }); - }); - }); - }); - - describe('when handler is specified', () => { - let handler; - beforeEach(() => { - handler = sinon.stub(); - }); - - it('should collect events in batches, and call handler', () => { - adapter.enableAnalytics({ - options: { - handler, - batchSize: 2 - } - }); - events.emit(AUCTION_INIT, {i: 0}); - sinon.assert.notCalled(handler); - events.emit(BID_RESPONSE, {i: 0}); - sinon.assert.calledWith(handler, sinon.match((arg) => { - return sinon.match({eventType: AUCTION_INIT, args: {i: 0}}).test(arg[0]) && - sinon.match({eventType: BID_RESPONSE, args: {i: 0}}).test(arg[1]); - })); - }); - - it('should not choke if handler throws', () => { - adapter.enableAnalytics({ - options: { - handler, - batchSize: 1 - } - }); - handler.throws(new Error()); - events.emit(AUCTION_INIT, {i: 0}); - let recv; - handler.resetHistory(); - handler.resetBehavior(); - handler.callsFake((arg) => { - recv = arg; - }); - events.emit(BID_RESPONSE, {i: 1}); - sinon.assert.match(recv, [sinon.match({eventType: BID_RESPONSE, args: {i: 1}})]) - }); - - it('should not cause infinite recursion, if handler triggers more events', () => { - let i = 0; - handler.callsFake(() => { - if (i <= 100) { - i++; - events.emit(BID_RESPONSE, {}); - } - }); - adapter.enableAnalytics({ - options: { - handler, - } - }); - events.emit(AUCTION_INIT, {}); - expect(i >= 100).to.be.false; - }); - - it('should send incomplete batch after batchDelay', () => { - adapter.enableAnalytics({ - options: { - batchDelay: 100, - batchSize: 2, - handler - } - }); - [0, 1, 2].forEach(i => events.emit(BID_RESPONSE, {i})); - sinon.assert.calledOnce(handler); - clock.tick(100); - sinon.assert.calledTwice(handler); - }); - - it('does not send empty batches', () => { - adapter.enableAnalytics({ - options: { - batchDelay: 100, - batchSize: 2, - handler - } - }); - [0, 1, 2].forEach(i => events.emit(BID_RESPONSE, {i})); - sinon.assert.calledOnce(handler); - clock.tick(50); - events.emit(BID_RESPONSE, {i: 3}); - sinon.assert.calledTwice(handler); - clock.tick(100); - sinon.assert.calledTwice(handler); - }); - - describe('and options.events is specified', () => { - it('filters out other events', () => { - adapter.enableAnalytics({ - options: { - handler, - events: { - bidResponse(bid) { - return bid; - } - } - } - }); - events.emit(AUCTION_INIT, {}); - sinon.assert.notCalled(handler); - }); - - it('transforms event data', () => { - adapter.enableAnalytics({ - options: { - handler, - events: { - bidResponse(bid) { - return { - extra: 'data', - prop: bid.prop - } - } - } - } - }); - events.emit(BID_RESPONSE, {prop: 'value', i: 0}); - sinon.assert.calledWith(handler, sinon.match(data => sinon.match({extra: 'data', prop: 'value'}).test(data[0]))); - }); - - it('does not choke if an event handler throws', () => { - adapter.enableAnalytics({ - options: { - handler, - events: { - bidResponse(bid) { - return bid; - }, - auctionInit(auction) { - throw new Error(); - } - } - } - }); - events.emit(AUCTION_INIT, {}); - events.emit(BID_RESPONSE, {i: 0}); - sinon.assert.calledOnce(handler); - sinon.assert.calledWith(handler, sinon.match(data => sinon.match({i: 0}).test(data[0]))); - }); - - it('filters out events when their handler returns undefined', () => { - adapter.enableAnalytics({ - options: { - handler, - events: { - auctionInit(auction) { - return auction; - }, - bidResponse(bid) {} - } - } - }); - events.emit(AUCTION_INIT, {i: 0}); - events.emit(BID_RESPONSE, {i: 1}); - sinon.assert.calledOnce(handler); - sinon.assert.calledWith(handler, sinon.match(data => sinon.match({i: 0}).test(data[0]))); - }); - }); - }); - }); - - describe('default handler', () => { - const url = 'mock-url'; - - let ajax; - beforeEach(() => { - ajax = sinon.stub(); - }); - - Object.entries({ - 'GET': (data) => JSON.parse(data.data), - 'POST': (data) => JSON.parse(data) - }).forEach(([method, parse]) => { - describe(`when HTTP method is ${method}`, () => { - it('should send single event when batchSize is 1', () => { - const handler = defaultHandler({url, method, batchSize: 1, ajax}); - const payload = {i: 0}; - handler([payload, {}]); - sinon.assert.calledWith(ajax, url, sinon.match.any, - sinon.match(data => sinon.match(payload).test(parse(data))), - {method, keepalive: true} - ); - }); - - it('should send multiple events when batchSize is greater than 1', () => { - const handler = defaultHandler({url, method, batchSize: 10, ajax}); - const payload = [{i: 0}, {i: 1}]; - handler(payload); - sinon.assert.calledWith(ajax, url, sinon.match.any, - sinon.match(data => sinon.match(payload).test(parse(data))), - {method, keepalive: true} - ); - }); - }); - }); - }); -}); diff --git a/test/spec/modules/geoedgeRtdProvider_spec.js b/test/spec/modules/geoedgeRtdProvider_spec.js deleted file mode 100644 index 7374f739b..000000000 --- a/test/spec/modules/geoedgeRtdProvider_spec.js +++ /dev/null @@ -1,174 +0,0 @@ -import * as utils from '../../../src/utils.js'; -import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; -import * as geoedgeRtdModule from '../../../modules/geoedgeRtdProvider.js'; -import { server } from '../../../test/mocks/xhr.js'; -import * as events from '../../../src/events.js'; -import { EVENTS } from '../../../src/constants.js'; - -const { - geoedgeSubmodule, - getClientUrl, - getInPageUrl, - htmlPlaceholder, - setWrapper, - getMacros, - WRAPPER_URL, - preloadClient, - markAsLoaded -} = geoedgeRtdModule; - -const key = '123123123'; -function makeConfig(gpt) { - return { - name: 'geoedge', - params: { - wap: false, - key, - bidders: { - bidderA: true, - bidderB: false - }, - gpt - } - }; -} - -function mockBid(bidderCode) { - return { - ad: '', - adId: '1234', - cpm: '1.00', - width: 300, - height: 250, - bidderCode, - requestId: utils.getUniqueIdentifierStr(), - creativeId: 'id', - currency: 'USD', - netRevenue: true, - ttl: 360 - }; -} - -function mockMessageFromClient(key) { - return { - key, - impression: true, - adId: 1234, - type: 'impression' - }; -} - -const mockWrapper = `${htmlPlaceholder}`; - -describe('Geoedge RTD module', function () { - describe('submodule', function () { - describe('name', function () { - it('should be geoedge', function () { - expect(geoedgeSubmodule.name).to.equal('geoedge'); - }); - }); - describe('init', function () { - before(function () { - sinon.spy(geoedgeRtdModule, 'preloadClient'); - }); - after(function () { - geoedgeRtdModule.preloadClient.restore(); - }); - it('should return false when missing params or key', function () { - const missingParams = geoedgeSubmodule.init({}); - const missingKey = geoedgeSubmodule.init({ params: {} }); - expect(missingParams || missingKey).to.equal(false); - }); - it('should return true when params are ok', function () { - expect(geoedgeSubmodule.init(makeConfig(false))).to.equal(true); - }); - it('should fetch the wrapper', function () { - geoedgeSubmodule.init(makeConfig(false)); - const request = server.requests[0]; - const isWrapperRequest = request && request.url && request.url && request.url === WRAPPER_URL; - expect(isWrapperRequest).to.equal(true); - }); - it('should call preloadClient', function () { - expect(preloadClient.called); - }); - it('should emit billable events with applicable winning bids', function (done) { - let counter = 0; - events.on(EVENTS.BILLABLE_EVENT, function (event) { - if (event.vendor === geoedgeSubmodule.name && event.type === 'impression') { - counter += 1; - } - expect(counter).to.equal(1); - done(); - }); - window.postMessage(mockMessageFromClient(key), '*'); - }); - it('should load the in page code when gpt params is true', function () { - geoedgeSubmodule.init(makeConfig(true)); - const isInPageUrl = arg => arg === getInPageUrl(key); - expect(loadExternalScriptStub.calledWith(sinon.match(isInPageUrl))).to.equal(true); - }); - it('should set the window.grumi config object when gpt params is true', function () { - const hasGrumiObj = typeof window.grumi === 'object'; - expect(hasGrumiObj && window.grumi.key === key && window.grumi.fromPrebid).to.equal(true); - }); - }); - describe('preloadClient', function () { - let iframe; - preloadClient(key); - const loadExternalScriptCall = loadExternalScriptStub.getCall(0); - it('should create an invisible iframe and insert it to the DOM', function () { - iframe = document.getElementById('grumiFrame'); - expect(iframe && iframe.style.display === 'none'); - }); - it('should assign params object to the iframe\'s window', function () { - const grumi = iframe.contentWindow.grumi; - expect(grumi.key).to.equal(key); - }); - it('should preload the client into the iframe', function () { - const isClientUrl = arg => arg === getClientUrl(key); - expect(loadExternalScriptCall.calledWithMatch(isClientUrl)).to.equal(true); - }); - }); - describe('setWrapper', function () { - it('should set the wrapper', function () { - setWrapper(mockWrapper); - expect(geoedgeRtdModule.wrapper).to.equal(mockWrapper); - }); - }); - describe('getMacros', function () { - it('return a dictionary of macros replaced with values from bid object', function () { - const bid = mockBid('testBidder'); - const dict = getMacros(bid, key); - const hasCpm = dict['%_hbCpm!'] === bid.cpm; - const hasCurrency = dict['%_hbCurrency!'] === bid.currency; - expect(hasCpm && hasCurrency); - }); - it('return a dictionary of macros replaced with values from overrides object if provided', function () { - const bid = mockBid('testBidder'); - window.grumi.overrides = { site: 'test-overrides' }; - const overrides = window.grumi.overrides; - const dict = getMacros(bid, key); - const siteOveridden = dict['%%SITE%%'] === overrides.site; - expect(siteOveridden); - }); - }); - describe('onBidResponseEvent', function () { - const bidFromA = mockBid('bidderA'); - it('should wrap bid html when bidder is configured', function () { - geoedgeSubmodule.onBidResponseEvent(bidFromA, makeConfig(false)); - expect(bidFromA.ad.indexOf('')).to.equal(0); - }); - it('should not wrap bid html when bidder is not configured', function () { - const bidFromB = mockBid('bidderB'); - geoedgeSubmodule.onBidResponseEvent(bidFromB, makeConfig(false)); - expect(bidFromB.ad.indexOf('')).to.equal(-1); - }); - it('should only muatate the bid ad porperty', function () { - const copy = Object.assign({}, bidFromA); - delete copy.ad; - const equalsOriginal = Object.keys(copy).every(key => copy[key] === bidFromA[key]); - expect(equalsOriginal).to.equal(true); - }); - }); - }); -}); diff --git a/test/spec/modules/geolocationRtdProvider_spec.js b/test/spec/modules/geolocationRtdProvider_spec.js deleted file mode 100644 index 26a9eef1e..000000000 --- a/test/spec/modules/geolocationRtdProvider_spec.js +++ /dev/null @@ -1,123 +0,0 @@ -import {expect} from 'chai'; -import {geolocationSubmodule} from 'modules/geolocationRtdProvider.js'; -import * as activityRules from 'src/activities/rules.js'; -import 'src/prebid.js'; -import {PbPromise} from '../../../src/utils/promise.js'; -import {ACTIVITY_TRANSMIT_PRECISE_GEO} from '../../../src/activities/activities.js'; - -describe('Geolocation RTD Provider', function () { - let sandbox; - - before(() => { - if (!navigator.permissions) { - navigator.permissions = {mock: true, query: false} - } - }); - - after(() => { - if (navigator.permissions.mock) { - delete navigator.permissions; - } - }); - - beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - - afterEach(() => { - sandbox.restore(); - }) - - describe('Geolocation not supported', function() { - Object.entries({ - 'permissions.query': () => sandbox.stub(navigator.permissions, 'query').value(undefined), - 'permissions': () => sandbox.stub(navigator, 'permissions').value(undefined), - }).forEach(([t, setup]) => { - describe(`${t} not available`, () => { - beforeEach(setup); - it('init should return false', function () { - expect(geolocationSubmodule.init({})).is.false; - }); - }); - }); - }); - - describe('Geolocation supported', function() { - let clock, rtdConfig, permState, permGiven, onDone; - - beforeEach(() => { - onDone = sinon.stub(); - permState = 'prompt'; - rtdConfig = {params: {}}; - clock = sandbox.useFakeTimers({ - now: 11000, - shouldClearNativeTimers: true - }); - sandbox.stub(navigator.geolocation, 'getCurrentPosition').value((cb) => { - cb({coords: {latitude: 1, longitude: 2}, timestamp: 1000}); - }); - permGiven = new Promise((resolve) => { - sandbox.stub(navigator.permissions, 'query').value(() => { - permGiven = Promise.resolve({ - state: permState, - }) - return permGiven; - }); - }) - geolocationSubmodule.init(rtdConfig); - }); - - afterEach(() => { - clock.runAll(); - clock.restore(); - }); - - it('init should return true', function () { - expect(geolocationSubmodule.init({})).is.true; - }); - - Object.entries({ - 'not necessary, requestPermission not set': [undefined, 'granted'], - 'not necessary, requestPermission = false': [false, 'granted'], - 'required, with requestPermission = true': [true, 'prompt'] - }).forEach(([t, [requestPermission, navPerm]]) => { - describe(`when browser permission is ${t}`, () => { - beforeEach(() => { - permState = navPerm; - rtdConfig.params.requestPermission = requestPermission; - }); - - it(`should set geolocation`, async () => { - const requestBidObject = {ortb2Fragments: {global: {}}}; - geolocationSubmodule.getBidRequestData(requestBidObject, onDone, rtdConfig); - await permGiven; - clock.tick(300); - expect(onDone.called).to.be.true; - expect(requestBidObject.ortb2Fragments.global.device.geo).to.eql({ - type: 1, - lat: 1, - lon: 2, - lastfix: 10 - }) - }) - }) - }) - - Object.entries({ - 'transmitPreciseGeo is denied': () => sandbox.stub(activityRules, 'isActivityAllowed').callsFake(activity => activity !== ACTIVITY_TRANSMIT_PRECISE_GEO), - 'permissions are required, but requestPermission is not set': () => { delete rtdConfig.params.requestPermission; permState = 'prompt' }, - 'permissions are required, but requestPermission is false': () => { rtdConfig.params.requestPermission = false; permState = 'prompt' } - }).forEach(([t, setup]) => { - describe(`when ${t}`, () => { - beforeEach(setup); - - it(`should NOT set geo`, () => { - const req = {ortb2Fragments: {global: {}}}; - geolocationSubmodule.getBidRequestData(req, onDone, rtdConfig); - clock.tick(300); - expect(req.ortb2Fragments.global.device?.geo).to.not.exist; - }) - }) - }); - }); -}); diff --git a/test/spec/modules/getintentBidAdapter_spec.js b/test/spec/modules/getintentBidAdapter_spec.js deleted file mode 100644 index 35788f6f9..000000000 --- a/test/spec/modules/getintentBidAdapter_spec.js +++ /dev/null @@ -1,220 +0,0 @@ -import { expect } from 'chai' -import { spec } from 'modules/getintentBidAdapter.js' -import {deepClone} from 'src/utils'; - -describe('GetIntent Adapter Tests:', function () { - const bidRequests = [{ - bidId: 'bid12345', - params: { - pid: 'p1000', - tid: 't1000' - }, - sizes: [[300, 250]] - }, - { - bidId: 'bid54321', - params: { - pid: 'p1000', - tid: 't1000' - }, - sizes: [[50, 50], [100, 100]] - }]; - const videoBidRequest = { - mediaTypes: { - video: { - protocols: [1, 2, 3], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - minbitrate: 500, - maxbitrate: 1000, - api: [2], - skip: 1 - } - }, - bidId: 'bid789', - params: { - pid: 'p1001', - tid: 't1001', - }, - sizes: [300, 250], - mediaType: 'video' - }; - const videoBidRequestWithVideoParams = { - mediaTypes: { - video: { - protocols: [1, 2, 3], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - minbitrate: 500, - maxbitrate: 1000, - api: [2], - skip: 0 - } - }, - bidId: 'bid789', - params: { - pid: 'p1001', - tid: 't1001', - video: { - mimes: ['video/mp4', 'application/javascript'], - max_dur: 20, - api: [1, 2], - skippable: 'ALLOW' - } - }, - sizes: [300, 250], - mediaType: 'video' - }; - - it('Verify build request', function () { - const serverRequests = spec.buildRequests(bidRequests); - let serverRequest = serverRequests[0]; - expect(serverRequest.url).to.equal('https://px.adhigh.net/rtb/direct_banner'); - expect(serverRequest.method).to.equal('GET'); - expect(serverRequest.data.bid_id).to.equal('bid12345'); - expect(serverRequest.data.pid).to.equal('p1000'); - expect(serverRequest.data.tid).to.equal('t1000'); - expect(serverRequest.data.size).to.equal('300x250'); - expect(serverRequest.data.is_video).to.equal(false); - serverRequest = serverRequests[1]; - expect(serverRequest.data.size).to.equal('50x50,100x100'); - }); - - it('Verify build video request', function () { - const serverRequests = spec.buildRequests([videoBidRequest]); - const serverRequest = serverRequests[0]; - expect(serverRequest.url).to.equal('https://px.adhigh.net/rtb/direct_vast'); - expect(serverRequest.method).to.equal('GET'); - expect(serverRequest.data.bid_id).to.equal('bid789'); - expect(serverRequest.data.pid).to.equal('p1001'); - expect(serverRequest.data.tid).to.equal('t1001'); - expect(serverRequest.data.size).to.equal('300x250'); - expect(serverRequest.data.is_video).to.equal(true); - expect(serverRequest.data.protocols).to.equal('1,2,3'); - expect(serverRequest.data.mimes).to.equal('video/mp4'); - expect(serverRequest.data.min_dur).to.equal(5); - expect(serverRequest.data.max_dur).to.equal(30); - expect(serverRequest.data.min_btr).to.equal(500); - expect(serverRequest.data.max_btr).to.equal(1000); - expect(serverRequest.data.api).to.equal('2'); - expect(serverRequest.data.skippable).to.equal('ALLOW'); - }); - - it('Verify build video request with video params', function () { - const serverRequests = spec.buildRequests([videoBidRequestWithVideoParams]); - const serverRequest = serverRequests[0]; - expect(serverRequest.url).to.equal('https://px.adhigh.net/rtb/direct_vast'); - expect(serverRequest.method).to.equal('GET'); - expect(serverRequest.data.bid_id).to.equal('bid789'); - expect(serverRequest.data.pid).to.equal('p1001'); - expect(serverRequest.data.tid).to.equal('t1001'); - expect(serverRequest.data.size).to.equal('300x250'); - expect(serverRequest.data.is_video).to.equal(true); - expect(serverRequest.data.mimes).to.equal('video/mp4,application/javascript'); - expect(serverRequest.data.max_dur).to.equal(20); - expect(serverRequest.data.api).to.equal('1,2'); - expect(serverRequest.data.skippable).to.equal('ALLOW'); - }); - - it('Verify bid floor without price floors module', function() { - const bidRequestWithFloor = deepClone(bidRequests[0]); - bidRequestWithFloor.params.floor = 10 - bidRequestWithFloor.params.cur = 'USD' - - const serverRequests = spec.buildRequests([bidRequestWithFloor]); - const serverRequest = serverRequests[0]; - expect(serverRequest.data.cur).to.equal('USD'); - expect(serverRequest.data.floor).to.equal(10); - }); - - it('Verify bid floor with price floors module', function() { - const bidRequestWithFloor = deepClone(bidRequests[0]); - bidRequestWithFloor.params.floor = 10 - bidRequestWithFloor.params.cur = 'USD' - const getFloorResponse = {floor: 5, currency: 'EUR'}; - bidRequestWithFloor.getFloor = () => getFloorResponse; - - const serverRequests = spec.buildRequests([bidRequestWithFloor]); - const serverRequest = serverRequests[0]; - expect(serverRequest.data.cur).to.equal('EUR'); - expect(serverRequest.data.floor).to.equal(5); - }); - - it('Verify parse response', function () { - const serverResponse = { - body: { - bid_id: 'bid12345', - cpm: 2.25, - currency: 'USD', - size: '300x250', - creative_id: '1000', - ad: 'Ad markup' - }, - headers: { - } - }; - const bids = spec.interpretResponse(serverResponse); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(2.25); - expect(bid.currency).to.equal('USD'); - expect(bid.creativeId).to.equal('1000'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.requestId).to.equal('bid12345'); - expect(bid.mediaType).to.equal('banner'); - expect(bid.ad).to.equal('Ad markup'); - }); - - it('Verify parse video response', function () { - const serverResponse = { - body: { - bid_id: 'bid789', - cpm: 3.25, - currency: 'USD', - size: '300x250', - creative_id: '2000', - vast_url: 'https://vast.xml/url' - }, - headers: { - } - }; - const bids = spec.interpretResponse(serverResponse); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(3.25); - expect(bid.currency).to.equal('USD'); - expect(bid.creativeId).to.equal('2000'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.requestId).to.equal('bid789'); - expect(bid.mediaType).to.equal('video'); - expect(bid.vastUrl).to.equal('https://vast.xml/url'); - }); - - it('Verify bidder code', function () { - expect(spec.code).to.equal('getintent'); - }); - - it('Verify bidder aliases', function () { - expect(spec.aliases).to.have.lengthOf(1); - expect(spec.aliases[0]).to.equal('getintentAdapter'); - }); - - it('Verify supported media types', function () { - expect(spec.supportedMediaTypes).to.have.lengthOf(2); - expect(spec.supportedMediaTypes[0]).to.equal('video'); - expect(spec.supportedMediaTypes[1]).to.equal('banner'); - }); - - it('Verify if bid request valid', function () { - expect(spec.isBidRequestValid(bidRequests[0])).to.equal(true); - expect(spec.isBidRequestValid(bidRequests[1])).to.equal(true); - expect(spec.isBidRequestValid({})).to.equal(false); - expect(spec.isBidRequestValid({ params: {} })).to.equal(false); - expect(spec.isBidRequestValid({ params: { test: 123 } })).to.equal(false); - expect(spec.isBidRequestValid({ params: { pid: 111, tid: 222 } })).to.equal(true); - }); -}); diff --git a/test/spec/modules/gjirafaBidAdapter_spec.js b/test/spec/modules/gjirafaBidAdapter_spec.js deleted file mode 100644 index 214468277..000000000 --- a/test/spec/modules/gjirafaBidAdapter_spec.js +++ /dev/null @@ -1,185 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/gjirafaBidAdapter'; - -describe('gjirafaAdapterTest', () => { - describe('bidRequestValidity', () => { - it('bidRequest with propertyId and placementId', () => { - expect(spec.isBidRequestValid({ - bidder: 'gjirafa', - params: { - propertyId: '{propertyId}', - placementId: '{placementId}' - } - })).to.equal(true); - }); - - it('bidRequest without propertyId', () => { - expect(spec.isBidRequestValid({ - bidder: 'gjirafa', - params: { - placementId: '{placementId}' - } - })).to.equal(false); - }); - - it('bidRequest without placementId', () => { - expect(spec.isBidRequestValid({ - bidder: 'gjirafa', - params: { - propertyId: '{propertyId}', - } - })).to.equal(false); - }); - - it('bidRequest without propertyId or placementId', () => { - expect(spec.isBidRequestValid({ - bidder: 'gjirafa', - params: {} - })).to.equal(false); - }); - }); - - describe('bidRequest', () => { - const bidRequests = [{ - 'bidder': 'gjirafa', - 'params': { - 'propertyId': '{propertyId}', - 'placementId': '{placementId}', - 'data': { - 'catalogs': [{ - 'catalogId': 1, - 'items': ['1', '2', '3'] - }], - 'inventory': { - 'category': ['category1', 'category2'], - 'query': ['query'] - } - } - }, - 'adUnitCode': 'hb-leaderboard', - 'transactionId': 'b6b889bb-776c-48fd-bc7b-d11a1cf0425e', - 'sizes': [[728, 90]], - 'bidId': '10bdc36fe0b48c8', - 'bidderRequestId': '70deaff71c281d', - 'auctionId': 'f9012acc-b6b7-4748-9098-97252914f9dc' - }]; - - it('bidRequest HTTP method', () => { - const requests = spec.buildRequests(bidRequests); - requests.forEach(function (requestItem) { - expect(requestItem.method).to.equal('POST'); - }); - }); - - it('bidRequest url', () => { - const endpointUrl = 'https://central.gjirafa.com/bid'; - const requests = spec.buildRequests(bidRequests); - requests.forEach(function (requestItem) { - expect(requestItem.url).to.match(new RegExp(`${endpointUrl}`)); - }); - }); - - it('bidRequest data', () => { - const requests = spec.buildRequests(bidRequests); - requests.forEach(function (requestItem) { - expect(requestItem.data).to.exist; - }); - }); - - it('bidRequest sizes', () => { - const requests = spec.buildRequests(bidRequests); - requests.forEach(function (requestItem) { - expect(requestItem.data.placements).to.exist; - expect(requestItem.data.placements.length).to.equal(1); - expect(requestItem.data.placements[0].sizes).to.equal('728x90'); - }); - }); - - it('bidRequest data param', () => { - const requests = spec.buildRequests(bidRequests); - requests.forEach((requestItem) => { - expect(requestItem.data.data).to.exist; - expect(requestItem.data.data.catalogs).to.exist; - expect(requestItem.data.data.inventory).to.exist; - expect(requestItem.data.data.catalogs.length).to.equal(1); - expect(requestItem.data.data.catalogs[0].items.length).to.equal(3); - expect(Object.keys(requestItem.data.data.inventory).length).to.equal(2); - expect(requestItem.data.data.inventory.category.length).to.equal(2); - expect(requestItem.data.data.inventory.query.length).to.equal(1); - }); - }); - }); - - describe('interpretResponse', () => { - const bidRequest = { - 'method': 'POST', - 'url': 'https://central.gjirafa.com/bid', - 'data': { - 'sizes': '728x90', - 'adUnitId': 'hb-leaderboard', - 'placementId': '{placementId}', - 'propertyId': '{propertyId}', - 'pageViewGuid': '{pageViewGuid}', - 'url': 'http://localhost:9999/integrationExamples/gpt/hello_world.html?pbjs_debug=true', - 'requestid': '26ee8fe87940da7', - 'bidid': '2962dbedc4768bf' - } - }; - - const bidResponse = { - body: [{ - 'CPM': 1, - 'Width': 728, - 'Height': 90, - 'Referrer': 'http://localhost:9999/integrationExamples/gpt/hello_world.html?pbjs_debug=true', - 'Ad': '
Test ad
', - 'CreativeId': '123abc', - 'NetRevenue': false, - 'Currency': 'EUR', - 'TTL': 360, - 'ADomain': ['somedomain.com'] - }], - headers: {} - }; - - it('all keys present', () => { - const result = spec.interpretResponse(bidResponse, bidRequest); - - const keys = [ - 'requestId', - 'cpm', - 'width', - 'height', - 'creativeId', - 'currency', - 'netRevenue', - 'ttl', - 'referrer', - 'ad', - 'vastUrl', - 'mediaType', - 'meta' - ]; - - const resultKeys = Object.keys(result[0]); - resultKeys.forEach(function (key) { - expect(keys.indexOf(key) !== -1).to.equal(true); - }); - }) - - it('all values correct', () => { - const result = spec.interpretResponse(bidResponse, bidRequest); - - expect(result[0].cpm).to.equal(1); - expect(result[0].width).to.equal(728); - expect(result[0].height).to.equal(90); - expect(result[0].creativeId).to.equal('123abc'); - expect(result[0].currency).to.equal('EUR'); - expect(result[0].netRevenue).to.equal(false); - expect(result[0].ttl).to.equal(360); - expect(result[0].referrer).to.equal('http://localhost:9999/integrationExamples/gpt/hello_world.html?pbjs_debug=true'); - expect(result[0].ad).to.equal('
Test ad
'); - expect(result[0].meta.advertiserDomains).to.deep.equal(['somedomain.com']); - }) - }); -}); diff --git a/test/spec/modules/glomexBidAdapter_spec.js b/test/spec/modules/glomexBidAdapter_spec.js deleted file mode 100644 index 8c53db8d6..000000000 --- a/test/spec/modules/glomexBidAdapter_spec.js +++ /dev/null @@ -1,144 +0,0 @@ -import { expect } from 'chai' -import { spec } from 'modules/glomexBidAdapter.js' -import { newBidder } from 'src/adapters/bidderFactory.js' - -const REQUEST = { - bidder: 'glomex', - params: { - integrationId: 'abcdefg', - playlistId: 'defghjk' - }, - bidderRequestId: '143346cf0f1732', - auctionId: '2e41f65424c87c', - adUnitCode: 'adunit-code', - bidId: '2d925f27f5079f', - sizes: [640, 360] -} - -const BIDDER_REQUEST = { - auctionId: '2d921234f5079f', - refererInfo: { - isAmp: true, - numIframes: 0, - reachedTop: true, - topmostLocation: 'https://glomex.com' - }, - gdprConsent: { - gdprApplies: true, - consentString: 'CO5asbJO5asbJE-AAAENAACAAAAAAAAAAAYgAAAAAAAA.IAAA' - } -} - -const RESPONSE = { - bids: [ - { - id: '2d925f27f5079f', - cpm: 3.5, - width: 640, - height: 360, - creativeId: 'creative-1j75x4ln1kk6m1ius', - dealId: 'deal-1j75x4ln1kk6m1iut', - currency: 'EUR', - netRevenue: true, - ttl: 300, - ad: '', - adomain: ['glomex.com'] - } - ] -} -describe('glomexBidAdapter', function () { - const adapter = newBidder(spec) - - it('should expose gvlid', function() { - expect(spec.gvlid).to.equal(967) - }); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function') - }) - }) - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - const request = { - 'params': { - 'integrationId': 'abcdefg' - } - } - expect(spec.isBidRequestValid(request)).to.equal(true) - }) - - it('should return false when required params are not passed', function () { - expect(spec.isBidRequestValid({})).to.equal(false) - }) - }) - - describe('buildRequests', function () { - const bidRequests = [REQUEST] - const request = spec.buildRequests(bidRequests, BIDDER_REQUEST) - - it('sends bid request to ENDPOINT via POST', function () { - expect(request.method).to.equal('POST') - }) - - it('returns a list of valid requests', function () { - expect(request.validBidRequests).to.eql([REQUEST]) - }) - - it('sends params.integrationId', function () { - expect(request.validBidRequests[0].params.integrationId).to.eql(REQUEST.params.integrationId) - }) - - it('sends params.playlistId', function () { - expect(request.validBidRequests[0].params.playlistId).to.eql(REQUEST.params.playlistId) - }) - - it('sends refererInfo', function () { - const expected = { - ...BIDDER_REQUEST.refererInfo, - referer: BIDDER_REQUEST.refererInfo.topmostLocation - } - delete expected.topmostLocation; - expect(request.data.refererInfo).to.eql(expected) - }) - - it('sends gdprConsent', function () { - expect(request.data.gdprConsent).to.eql(BIDDER_REQUEST.gdprConsent) - }) - - it('sends the auctionId', function () { - expect(request.data.auctionId).to.eql(BIDDER_REQUEST.auctionId) - }) - }) - - describe('interpretResponse', function () { - it('handles nobid responses', function () { - expect(spec.interpretResponse({body: {}}, {validBidRequests: []}).length).to.equal(0) - expect(spec.interpretResponse({body: []}, {validBidRequests: []}).length).to.equal(0) - }) - - it('handles the server response', function () { - const result = spec.interpretResponse( - { - body: RESPONSE - }, - { - validBidRequests: [REQUEST] - } - ) - - expect(result[0].requestId).to.equal('2d925f27f5079f') - expect(result[0].cpm).to.equal(3.5) - expect(result[0].width).to.equal(640) - expect(result[0].height).to.equal(360) - expect(result[0].creativeId).to.equal('creative-1j75x4ln1kk6m1ius') - expect(result[0].dealId).to.equal('deal-1j75x4ln1kk6m1iut') - expect(result[0].currency).to.equal('EUR') - expect(result[0].netRevenue).to.equal(true) - expect(result[0].ttl).to.equal(300) - expect(result[0].ad).to.equal('') - expect(result[0].meta.advertiserDomains).to.deep.equal(['glomex.com']) - }) - }) -}) diff --git a/test/spec/modules/gmosspBidAdapter_spec.js b/test/spec/modules/gmosspBidAdapter_spec.js deleted file mode 100644 index b3d0c20f3..000000000 --- a/test/spec/modules/gmosspBidAdapter_spec.js +++ /dev/null @@ -1,193 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/gmosspBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import * as utils from 'src/utils.js'; - -const ENDPOINT = 'https://sp.gmossp-sp.jp/hb/prebid/query.ad'; - -describe('GmosspAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - bidder: 'gmossp', - params: { - sid: '123456' - } - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - bidder: 'gmossp', - params: { - sid: '123456' - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250], - [320, 50], - [320, 100], - ], - bidId: '2b84475b5b636e', - bidderRequestId: '1f4001782ac16c', - auctionId: 'aba03555-4802-4c45-9f15-05ffa8594cff', - ortb2Imp: { - ext: { - tid: '791e9d84-af92-4903-94da-24c7426d9d0c', - } - }, - userId: { - imuid: 'h.0a4749e7ffe09fa6', - pubcid: '1111', - idl_env: '1111', - } - } - ]; - - it('sends bid request to ENDPOINT via GET', function () { - const bidderRequest = { - refererInfo: { - topmostLocation: 'https://hoge.com' - } - }; - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(requests[0].url).to.equal(ENDPOINT); - expect(requests[0].method).to.equal('GET'); - expect(requests[0].data).to.equal('tid=791e9d84-af92-4903-94da-24c7426d9d0c&bid=2b84475b5b636e&ver=$prebid.version$&sid=123456&im_uid=h.0a4749e7ffe09fa6&shared_id=1111&idl_env=1111&url=https%3A%2F%2Fhoge.com' + '&ref=' + encodeURIComponent(document.referrer) + '&cur=JPY&dnt=0&'); - }); - - it('should use fallback if refererInfo.referer in bid request is empty and im_uid ,shared_id, idl_env cookie is empty', function () { - const bidderRequest = { - refererInfo: { - topmostLocation: '' - }, - }; - bidRequests[0].userId.imuid = ''; - bidRequests[0].userId.pubcid = ''; - bidRequests[0].userId.idl_env = ''; - - const requests = spec.buildRequests(bidRequests, bidderRequest); - const result = 'tid=791e9d84-af92-4903-94da-24c7426d9d0c&bid=2b84475b5b636e&ver=$prebid.version$&sid=123456&ref=' + encodeURIComponent(document.referrer) + '&cur=JPY&dnt=0&'; - expect(requests[0].data).to.equal(result); - }); - }); - - describe('interpretResponse', function () { - const bidderRequests = [ - { - bidder: 'gmossp', - params: { - sid: '123456' - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250], - [320, 50], - [320, 100], - ], - bidId: '2b84475b5b636e', - bidderRequestId: '1f4001782ac16c', - auctionId: 'aba03555-4802-4c45-9f15-05ffa8594cff', - transactionId: '791e9d84-af92-4903-94da-24c7426d9d0c' - } - ]; - - it('should get correct banner bid response', function () { - const response = { - bid: '2b84475b5b636e', - price: 20, - w: 300, - h: 250, - adomains: [ - 'test.com' - ], - ad: '
', - creativeId: '985ec572b32be309.76973017', - cur: 'JPY', - dealId: '', - imps: [ - 'https://sp.gmossp-sp.jp/hb/prebid/imp.ad' - ], - syncs: [ - 'https://sync.dsp.reemo-ad.jp' - ], - ttl: 300 - }; - - const expectedResponse = [ - { - requestId: '2b84475b5b636e', - cpm: 20, - currency: 'JPY', - width: 300, - height: 250, - meta: { - advertiserDomains: [ - 'test.com' - ] - }, - ad: '
', - creativeId: '985ec572b32be309.76973017', - netRevenue: true, - ttl: 300 - } - ]; - - const result = spec.interpretResponse({ body: response }, bidderRequests); - expect(result).to.have.lengthOf(1); - - response.imps.forEach(impTracker => { - const tracker = utils.createTrackPixelHtml(impTracker); - expectedResponse[0].ad += tracker; - }); - - expect(result).to.deep.have.same.members(expectedResponse); - }); - - it('handles nobid responses', function () { - const response = ''; - - const result = spec.interpretResponse({ body: response }, bidderRequests); - expect(result.length).to.equal(0); - }); - }); - - describe('getUserSyncs', function () { - const bidResponse = { - body: { - ad: {}, - syncs: [ - 'https://hoge.com' - ] - } - }; - it('should return returns pixel syncs', function () { - const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, [bidResponse]); - expect(syncs).to.deep.equal([ - { - type: 'image', - url: 'https://hoge.com' - } - ]) - }) - }); -}); diff --git a/test/spec/modules/gnetBidAdapter_spec.js b/test/spec/modules/gnetBidAdapter_spec.js deleted file mode 100644 index 11cc740a6..000000000 --- a/test/spec/modules/gnetBidAdapter_spec.js +++ /dev/null @@ -1,162 +0,0 @@ -import { - expect -} from 'chai'; -import { - spec -} from 'modules/gnetBidAdapter.js'; -import { - newBidder -} from 'src/adapters/bidderFactory.js'; - -const ENDPOINT = 'https://service.gnetrtb.com/api/adrequest'; - -describe('gnetAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - bidder: 'gnet', - params: { - websiteId: '1', adunitId: '1' - } - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('onBidWon', function () { - const bid = { - requestId: '29d5b1d3a520f8' - }; - - it('return success adserver won bid endpoint', () => { - const result = spec.onBidWon(bid); - assert.ok(result); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [{ - bidder: 'gnet', - params: { - websiteId: '1', adunitId: '1' - }, - adUnitCode: '/150790500/4_ZONA_IAB_300x250_5', - sizes: [ - [300, 250], - ], - bidId: '2a19afd5173318', - bidderRequestId: '1f4001782ac16c', - auctionId: 'aba03555-4802-4c45-9f15-05ffa8594cff', - ortb2Imp: { - ext: { - tid: '894bdff6-61ec-4bec-a5a9-f36a5bfccef5', - } - }, - gftuid: null - }]; - - const bidderRequest = { - refererInfo: { - page: 'https://gnetrtb.com' - } - }; - - it('sends bid request to ENDPOINT via POST', function () { - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(requests[0].url).to.equal(ENDPOINT); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].data).to.equal(JSON.stringify({ - 'referer': 'https://gnetrtb.com', - 'adUnitCode': '/150790500/4_ZONA_IAB_300x250_5', - 'bidId': '2a19afd5173318', - 'transactionId': '894bdff6-61ec-4bec-a5a9-f36a5bfccef5', - 'gftuid': null, - 'sizes': ['300x250'], - 'params': { - 'websiteId': '1', 'adunitId': '1' - } - })); - }); - }); - - describe('interpretResponse', function () { - const bidderRequests = [{ - bidder: 'gnet', - params: { - clientId: '123456' - }, - adUnitCode: '/150790500/4_ZONA_IAB_300x250_5', - sizes: [ - [300, 250], - ], - bidId: '2a19afd5173318', - bidderRequestId: '1f4001782ac16c', - auctionId: 'aba03555-4802-4c45-9f15-05ffa8594cff', - transactionId: '894bdff6-61ec-4bec-a5a9-f36a5bfccef5' - }]; - - it('should get correct banner bid response', function () { - const response = { - bids: [ - { - bidId: '2a19afd5173318', - cpm: 0.1, - currency: 'BRL', - width: 300, - height: 250, - ad: '

I am an ad

', - creativeId: '173560700', - } - ] - }; - - const expectedResponse = [ - { - requestId: '2a19afd5173318', - cpm: 0.1, - currency: 'BRL', - width: 300, - height: 250, - ad: '

I am an ad

', - ttl: 300, - meta: { - advertiserDomains: [] - }, - creativeId: '173560700', - netRevenue: true - } - ]; - - const result = spec.interpretResponse({ - body: response - }, bidderRequests); - expect(result).to.have.lengthOf(1); - expect(result).to.deep.have.same.members(expectedResponse); - }); - - it('handles nobid responses', function () { - const response = ''; - - const result = spec.interpretResponse({ - body: response - }, bidderRequests); - expect(result.length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/goldbachBidAdapter_spec.js b/test/spec/modules/goldbachBidAdapter_spec.js deleted file mode 100644 index ac1207f6d..000000000 --- a/test/spec/modules/goldbachBidAdapter_spec.js +++ /dev/null @@ -1,561 +0,0 @@ -import { expect } from 'chai'; -import sinon from 'sinon'; -import { spec, storage } from 'modules/goldbachBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { deepClone } from 'src/utils.js'; -import { BANNER, VIDEO, NATIVE } from 'src/mediaTypes.js'; -import { OUTSTREAM } from 'src/video.js'; -import { addFPDToBidderRequest } from '../../helpers/fpd.js'; -import * as ajaxLib from 'src/ajax.js'; - -const BIDDER_NAME = 'goldbach' -const ENDPOINT = 'https://goldlayer-api.prod.gbads.net/openrtb/2.5/auction'; -const ENDPOINT_COOKIESYNC = 'https://goldlayer-api.prod.gbads.net/cookiesync'; - -/* Eids */ -const eids = [ - { - source: 'goldbach.com', - uids: [ - { - id: '0d862e87-14e9-47a4-9e9b-886b7d7a9d1b', - atype: 1, - ext: { stype: 'ppuid' } - } - ] - }, - { - source: 'niceid.live', - uids: [ - { - id: '0d862e87-14e9-47a4-9e9b-886b7d7a9d1a', - atype: 1, - ext: { stype: 'ppuid' } - } - ] - }, - { - source: 'otherid.live', - uids: [ - { - id: '0d862e87-14e9-47a4-9e9b-886b7d7a9d1a', - atype: 1, - ext: { stype: 'other-id' } - } - ] - } -]; - -const validNativeObject = { - link: { - url: 'https://example.com/cta', - }, - imptrackers: [ - 'https://example.com/impression1', - 'https://example.com/impression2', - ], - assets: [ - { - id: 1, - title: { - text: 'Amazing Product - Do not Miss Out!', - }, - }, - { - id: 2, - img: { - url: 'https://example.com/main-image.jpg', - w: 300, - h: 250, - }, - }, - { - id: 3, - img: { - url: 'https://example.com/icon-image.jpg', - w: 50, - h: 50, - }, - }, - { - id: 4, - data: { - value: 'This is the description of the product or service being advertised.', - }, - }, - { - id: 5, - data: { - value: 'Sponsored by some brand', - }, - }, - { - id: 6, - data: { - value: 'Buy Now', - }, - }, - ], -}; - -/* Minimal validBidRequests */ -const validBidRequests = [ - { - bidder: BIDDER_NAME, - adUnitCode: 'au-1', - adUnitId: 'c3400db6-c4c5-465e-bf67-1545751944b7', - auctionId: '7570fb24-810d-4c26-9f9c-acd0b6977f60', - bidId: '3d52a1909b972a', - bidderRequestId: '2b63a1826ab946', - userIdAsEids: eids, - mediaTypes: { - [BANNER]: { - sizes: [[300, 50], [300, 250], [300, 600], [320, 50], [320, 480], [320, 64], [320, 160], [320, 416], [336, 280]] - } - }, - sizes: [[300, 50], [300, 250], [300, 600], [320, 50], [320, 480], [320, 64], [320, 160], [320, 416], [336, 280]], - params: { - publisherId: 'de-publisher.ch-ios', - slotId: '/46753895/publisher.ch/inside-full-content-pos1/pbjs-test', - customTargeting: { language: 'de' } - } - }, - { - bidder: BIDDER_NAME, - adUnitCode: 'au-2', - adUnitId: 'c3400db6-c4c5-465e-bf67-1545751944b8', - auctionId: '7570fb24-810d-4c26-9f9c-acd0b6977f60', - bidId: '3d52a1909b972b', - bidderRequestId: '2b63a1826ab946', - userIdAsEids: eids, - mediaTypes: { - [VIDEO]: { - playerSize: [[640, 480]], - context: OUTSTREAM, - protocols: [1, 2], - mimes: ['video/mp4'] - } - }, - params: { - publisherId: 'de-publisher.ch-ios', - slotId: '/46753895/publisher.ch/inside-full-content-pos1/pbjs-test/video', - customTargeting: { - language: 'de' - } - } - }, - { - bidder: BIDDER_NAME, - adUnitCode: 'au-3', - adUnitId: 'c3400db6-c4c5-465e-bf67-1545751944b9', - auctionId: '7570fb24-810d-4c26-9f9c-acd0b6977f60', - bidId: '3d52a1909b972c', - bidderRequestId: '2b63a1826ab946', - userIdAsEids: eids, - mediaTypes: { - [NATIVE]: { - title: { - required: true, - len: 50 - }, - image: { - required: true, - sizes: [300, 157] - }, - icon: { - required: true, - sizes: [30, 30] - }, - body: { - required: true, - len: 150 - }, - cta: { - required: true, - len: 15 - }, - sponsoredBy: { - required: true, - len: 25 - }, - } - }, - params: { - publisherId: 'de-publisher.ch-ios', - slotId: '/46753895/publisher.ch/inside-full-content-pos1/pbjs-test/native', - customTargeting: { - language: 'de' - } - } - } -]; - -/* Minimal bidderRequest */ -const validBidderRequest = { - bidderCode: BIDDER_NAME, - auctionId: '7570fb24-810d-4c26-9f9c-acd0b6977f60', - bidderRequestId: '7570fb24-811d-4c26-9f9c-acd0b6977f61', - bids: validBidRequests, - gdprConsent: { - gdprApplies: true, - consentString: 'CONSENT' - }, - timeout: 3000 -}; - -/* OpenRTB response from auction endpoint */ -const validOrtbBidResponse = { - id: '3d52a1909b972a', - seatbid: [ - { - bid: [ - { - id: '3d52a1909b972a', - impid: '3d52a1909b972a', - price: 0.5, - adm: '
creative
', - crid: 'creative-id', - w: 300, - h: 250, - ext: { - origbidcur: 'USD', - prebid: { - type: 'banner' - } - } - }, - { - id: '3d52a1909b972b', - impid: '3d52a1909b972b', - price: 0.5, - adm: '
creative
', - crid: 'creative-id', - w: 640, - h: 480, - ext: { - origbidcur: 'USD', - prebid: { - type: 'video' - } - } - }, - { - id: '3d52a1909b972c', - impid: '3d52a1909b972c', - price: 0.5, - adm: validNativeObject, - crid: 'creative-id', - ext: { - origbidcur: 'USD', - prebid: { - type: 'native' - } - } - } - ] - } - ], - cur: 'USD', - ext: { - prebid: { - targeting: { - hb_bidder: 'appnexus', - hb_pb: '0.50', - hb_adid: '3d52a1909b972a', - hb_deal: 'deal-id', - hb_size: '300x250' - } - } - } -}; - -describe('GoldbachBidAdapter', function () { - const adapter = newBidder(spec); - let sandbox; - let ajaxStub; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - ajaxStub = sandbox.stub(ajaxLib, 'ajax'); - sandbox.stub(Math, 'random').returns(0); - }); - - afterEach(() => { - ajaxStub.restore(); - sandbox.restore(); - }); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - bidder: BIDDER_NAME, - params: { - publisherId: 'de-publisher.ch-ios', - slotId: '/46753895/publisher.ch/inside-full-content-pos1/pbjs-test', - customTargeting: { language: 'de' } - }, - adUnitCode: '/46753895/publisher.ch/inside-full-content-pos1/pbjs-test', - sizes: [[300, 250], [300, 600]] - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - publisherId: undefined - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('should use defined endpoint', function () { - const bidRequests = deepClone(validBidRequests); - const bidderRequest = deepClone(validBidderRequest); - - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).to.equal(ENDPOINT); - }) - - it('should parse all bids to a valid openRTB request', function () { - const bidRequests = deepClone(validBidRequests); - const bidderRequest = deepClone(validBidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - - expect(payload.imp).to.exist; - expect(Array.isArray(payload.imp)).to.be.true; - expect(payload.imp.length).to.equal(3); - expect(payload.imp[0].ext.goldbach.slotId).to.equal(bidRequests[0].params.slotId); - expect(Array.isArray(payload.imp[0][BANNER].format)).to.be.true; - expect(payload.imp[0][BANNER].format.length).to.equal(bidRequests[0].sizes.length); - expect(payload.imp[1].ext.goldbach.slotId).to.equal(bidRequests[1].params.slotId); - }); - - if (FEATURES.VIDEO) { - it('should parse all video bids to valid video imps (use video player size)', async function () { - const bidRequests = deepClone(validBidRequests); - const bidderRequest = deepClone(validBidderRequest); - const request = spec.buildRequests([bidRequests[1]], await addFPDToBidderRequest(bidderRequest)); - const payload = request.data; - - expect(payload.imp.length).to.equal(1); - expect(payload.imp[0][VIDEO]).to.exist; - expect(payload.imp[0][VIDEO].w).to.equal(640); - expect(payload.imp[0][VIDEO].h).to.equal(480); - }); - } - - it('should set custom config on request', function () { - const bidRequests = deepClone(validBidRequests); - const bidderRequest = deepClone(validBidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - - expect(payload.ext.goldbach.publisherId).to.equal(bidRequests[0].params.publisherId); - }); - - it('should set gdpr on request', function () { - const bidRequests = deepClone(validBidRequests); - const bidderRequest = deepClone(validBidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - - expect(!!payload.regs.ext.gdpr).to.equal(bidderRequest.gdprConsent.gdprApplies); - expect(payload.user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString); - }); - - it('should set custom targeting on request', function () { - const bidRequests = deepClone(validBidRequests); - const bidderRequest = deepClone(validBidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - - expect(payload.imp[0].ext.goldbach.targetings).to.exist; - expect(payload.imp[0].ext.goldbach.targetings).to.deep.equal(bidRequests[0].params.customTargeting); - }); - }); - - describe('interpretResponse', function () { - it('should map response to valid bids (amount)', function () { - const bidRequest = spec.buildRequests(validBidRequests, validBidderRequest); - const bidResponse = deepClone({body: validOrtbBidResponse}); - const response = spec.interpretResponse(bidResponse, bidRequest); - - expect(response).to.exist; - expect(response.length).to.equal(3); - expect(response.filter(bid => bid.requestId === validBidRequests[0].bidId).length).to.equal(1) - expect(response.filter(bid => bid.requestId === validBidRequests[1].bidId).length).to.equal(1) - }); - - if (FEATURES.VIDEO) { - it('should attach a custom video renderer ', function () { - const bidRequest = spec.buildRequests(validBidRequests, validBidderRequest); - const bidResponse = deepClone({body: validOrtbBidResponse}); - bidResponse.body.seatbid[0].bid[1].adm = ''; - bidResponse.body.seatbid[0].bid[1].ext = { prebid: { type: 'video', meta: { type: 'video_outstream' } } }; - const response = spec.interpretResponse(bidResponse, bidRequest); - - expect(response).to.exist; - expect(response.filter(bid => !!bid.renderer).length).to.equal(1); - }); - - it('should set the player accordingly to config', function () { - const bidRequest = spec.buildRequests(validBidRequests, validBidderRequest); - const bidResponse = deepClone({body: validOrtbBidResponse}); - bidResponse.body.seatbid[0].bid[1].adm = ''; - bidResponse.body.seatbid[0].bid[1].ext = { prebid: { type: 'video', meta: { type: 'video_outstream' } } }; - validBidRequests[1].mediaTypes.video.playbackmethod = 1; - const response = spec.interpretResponse(bidResponse, bidRequest); - const renderer = response.find(bid => !!bid.renderer); - renderer?.renderer?.render(); - - expect(response).to.exist; - expect(response.filter(bid => !!bid.renderer).length).to.equal(1); - expect(renderer.renderer.config.documentResolver).to.exist; - }); - } - - it('should not attach a custom video renderer when VAST url/xml is missing', function () { - const bidRequest = spec.buildRequests(validBidRequests, validBidderRequest); - const bidResponse = deepClone({body: validOrtbBidResponse}); - bidResponse.body.seatbid[0].bid[1].adm = undefined; - bidResponse.body.seatbid[0].bid[1].ext = { prebid: { type: 'video', meta: { type: 'video_outstream' } } }; - const response = spec.interpretResponse(bidResponse, bidRequest); - - expect(response).to.exist; - expect(response.filter(bid => !!bid.renderer).length).to.equal(0); - }); - }); - - describe('getUserSyncs', function () { - it('user-syncs with enabled pixel option', function () { - const gdprConsent = { - vendorData: { - purpose: { - consents: 1 - } - }}; - const syncOptions = {pixelEnabled: true, iframeEnabled: true}; - const userSyncs = spec.getUserSyncs(syncOptions, {}, gdprConsent, {}); - - expect(userSyncs[0].type).to.equal('image'); - expect(userSyncs[0].url).to.contain(`https://ib.adnxs.com/getuid?${ENDPOINT_COOKIESYNC}`); - expect(userSyncs[0].url).to.contain('xandrId=$UID'); - }); - - it('user-syncs with enabled iframe option', function () { - const gdprConsent = { - vendorData: { - purpose: { - consents: 1 - } - }}; - const syncOptions = {iframeEnabled: true}; - const userSyncs = spec.getUserSyncs(syncOptions, {}, gdprConsent, {}); - - expect(userSyncs[0].type).to.equal('iframe'); - expect(userSyncs[0].url).to.contain(`https://ib.adnxs.com/getuid?${ENDPOINT_COOKIESYNC}`); - expect(userSyncs[0].url).to.contain('xandrId=$UID'); - }); - - it('user-syncs use gdpr signal', function () { - const gdprConsent = { - gdprApplies: true, - consentString: 'CPwk-qEPwk-qEH6AAAENCZCMAP_AAH_AAAAAI7Nd_X__bX9n-_7_6ft0eY1f9_r37uQzDhfNs-8F3L_W_LwX32E7NF36tq4KmR4ku1bBIQNtHMnUDUmxaolVrzHsak2cpyNKJ_JkknsZe2dYGF9Pn9lD-YKZ7_5_9_f52T_9_9_-39z3_9f___dv_-__-vjf_599n_v9fV_78_Kf9______-____________8Edmu_r__tr-z_f9_9P26PMav-_1793IZhwvm2feC7l_rfl4L77Cdmi79W1cFTI8SXatgkIG2jmTqBqTYtUSq15j2NSbOU5GlE_kyST2MvbOsDC-nz-yh_MFM9_8_-_v87J_-_-__b-57_-v___u3__f__Xxv_8--z_3-vq_9-flP-_______f___________-AA.II7Nd_X__bX9n-_7_6ft0eY1f9_r37uQzDhfNs-8F3L_W_LwX32E7NF36tq4KmR4ku1bBIQNtHMnUDUmxaolVrzHsak2cpyNKJ_JkknsZe2dYGF9Pn9lD-YKZ7_5_9_f52T_9_9_-39z3_9f___dv_-__-vjf_599n_v9fV_78_Kf9______-____________8A', - vendorData: { - purpose: { - consents: { '1': true } - } - } - }; - const synOptions = {pixelEnabled: true, iframeEnabled: true}; - const userSyncs = spec.getUserSyncs(synOptions, {}, gdprConsent, {}); - expect(userSyncs[0].url).to.contain(`https://ib.adnxs.com/getuid?${ENDPOINT_COOKIESYNC}`); - expect(userSyncs[0].url).to.contain('xandrId=$UID'); - expect(userSyncs[0].url).to.contain(`gdpr_consent=${gdprConsent.consentString}`); - expect(userSyncs[0].url).to.contain(`gdpr=1`); - }) - }); - - describe('getUserSyncs storage', function () { - beforeEach(function () { - sandbox.stub(storage, 'setDataInLocalStorage'); - sandbox.stub(storage, 'setCookie'); - }); - - afterEach(function () { - sandbox.restore(); - }); - - it('should retrieve a uid in userSync call from localStorage', function () { - sandbox.stub(storage, 'localStorageIsEnabled').callsFake(() => true); - sandbox.stub(storage, 'getDataFromLocalStorage').callsFake((key) => 'goldbach_uid'); - const gdprConsent = { vendorData: { purpose: { consents: 1 } } }; - const syncOptions = { iframeEnabled: true }; - const userSyncs = spec.getUserSyncs(syncOptions, {}, gdprConsent, {}); - expect(userSyncs[0].url).to.contain('goldbach_uid'); - }); - - it('should retrieve a uid in userSync call from cookie', function () { - sandbox.stub(storage, 'cookiesAreEnabled').callsFake(() => true); - sandbox.stub(storage, 'getCookie').callsFake((key) => 'goldbach_uid'); - const gdprConsent = { vendorData: { purpose: { consents: 1 } } }; - const syncOptions = { iframeEnabled: true }; - const userSyncs = spec.getUserSyncs(syncOptions, {}, gdprConsent, {}); - expect(userSyncs[0].url).to.contain('goldbach_uid'); - }); - }); - - describe('sendLogs', function () { - it('should not send logs when percentage is not met', function () { - Math.random.returns(1); - spec.onTimeout([]); - expect(ajaxStub.calledOnce).to.be.false; - }); - }); - - describe('onTimeout', function () { - it('should send logs on timeout', function () { - spec.onTimeout([]); - expect(ajaxStub.calledOnce).to.be.true; - }); - }); - - describe('onBidWon', function () { - it('should send logs on won', function () { - spec.onBidWon([]); - expect(ajaxStub.calledOnce).to.be.true; - }); - }); - - describe('onSetTargeting', function () { - it('should send logs on targeting', function () { - spec.onSetTargeting([]); - expect(ajaxStub.calledOnce).to.be.true; - }); - }); - - describe('onBidderError', function () { - it('should send logs on bidder error', function () { - spec.onBidderError([]); - expect(ajaxStub.calledOnce).to.be.true; - }); - }); - - describe('onAdRenderSucceeded', function () { - it('should send logs on render succeeded', function () { - spec.onAdRenderSucceeded([]); - expect(ajaxStub.calledOnce).to.be.true; - }); - }); -}); diff --git a/test/spec/modules/goldfishAdsRtdProvider_spec.js b/test/spec/modules/goldfishAdsRtdProvider_spec.js deleted file mode 100755 index acbba5190..000000000 --- a/test/spec/modules/goldfishAdsRtdProvider_spec.js +++ /dev/null @@ -1,163 +0,0 @@ -import { - goldfishAdsSubModule, - manageCallbackResponse, -} from 'modules/goldfishAdsRtdProvider.js'; -import { getStorageManager } from '../../../src/storageManager.js'; -import { expect } from 'chai'; -import { server } from 'test/mocks/xhr.js'; -import { config as _config } from 'src/config.js'; -import { DATA_STORAGE_KEY, MODULE_NAME, MODULE_TYPE, getStorageData, updateUserData } from '../../../modules/goldfishAdsRtdProvider.js'; - -const responseHeader = { 'Content-Type': 'application/json' }; - -const sampleConfig = { - name: 'golfishAds', - waitForIt: true, - params: { - key: 'testkey' - } -}; - -const sampleAdUnits = [ - { - code: 'one-div-id', - mediaTypes: { - banner: { - sizes: [970, 250] - } - }, - bids: [ - { - bidder: 'appnexus', - params: { - placementId: 12345370, - } - }] - }, - { - code: 'two-div-id', - mediaTypes: { - banner: { sizes: [300, 250] } - }, - bids: [ - { - bidder: 'appnexus', - params: { - placementId: 12345370, - } - }] - }]; - -const sampleOutputData = [1, 2, 3] - -describe('goldfishAdsRtdProvider is a RTD provider that', function () { - describe('has a method `init` that', function () { - it('exists', function () { - expect(goldfishAdsSubModule.init).to.be.a('function'); - }); - it('returns false missing config params', function () { - const config = { - name: 'goldfishAds', - waitForIt: true, - }; - const value = goldfishAdsSubModule.init(config); - expect(value).to.equal(false); - }); - it('returns false if missing providers param', function () { - const config = { - name: 'goldfishAds', - waitForIt: true, - params: {} - }; - const value = goldfishAdsSubModule.init(config); - expect(value).to.equal(false); - }); - it('returns false if wrong providers param included', function () { - const config = { - name: 'goldfishAds', - waitForIt: true, - params: { - account: 'test' - } - }; - const value = goldfishAdsSubModule.init(config); - expect(value).to.equal(false); - }); - it('returns true if good providers param included', function () { - const config = { - name: 'goldfishAds', - waitForIt: true, - params: { - key: 'testkey' - } - }; - const value = goldfishAdsSubModule.init(config); - expect(value).to.equal(true); - }); - }); - - describe('has a method `getBidRequestData` that', function () { - it('exists', function () { - expect(goldfishAdsSubModule.getBidRequestData).to.be.a('function'); - }); - - it('send correct request', function () { - const callback = sinon.spy(); - let request; - const reqBidsConfigObj = { adUnits: sampleAdUnits }; - goldfishAdsSubModule.getBidRequestData(reqBidsConfigObj, callback, sampleConfig); - request = server.requests[0]; - request.respond(200, responseHeader, JSON.stringify(sampleOutputData)); - expect(request.url).to.be.include(`?key=testkey`); - }); - }); - - describe('has a manageCallbackResponse that', function () { - it('properly transforms the response', function () { - const response = { response: '[\"1\", \"2\", \"3\"]' }; - const output = manageCallbackResponse(response); - expect(output.name).to.be.equal('goldfishads.com'); - }); - }); - - describe('has an updateUserData that', function () { - it('properly transforms the response', function () { - const userData = { - segment: [{id: '1'}, {id: '2'}], - ext: { - segtax: 4, - } - }; - const reqBidsConfigObj = { ortb2Fragments: { bidder: { appnexus: { user: { data: [] } } } } }; - const output = updateUserData(userData, reqBidsConfigObj); - expect(output.ortb2Fragments.bidder.appnexus.user.data[0].segment).to.be.length(2); - expect(output.ortb2Fragments.bidder.appnexus.user.data[0].segment[0].id).to.be.eql('1'); - }); - }); - - describe('uses Local Storage to ', function () { - const sandbox = sinon.createSandbox(); - const storage = getStorageManager({ moduleType: MODULE_TYPE, moduleName: MODULE_NAME }) - beforeEach(() => { - storage.setDataInLocalStorage(DATA_STORAGE_KEY, JSON.stringify({ - targeting: { - name: 'goldfishads.com', - segment: [{id: '1'}, {id: '2'}], - ext: { - segtax: 4, - } - }, - expiry: new Date().getTime() + 1000 * 60 * 60 * 24 * 30, - })); - }); - afterEach(() => { - sandbox.restore(); - }); - it('get data from local storage', function () { - const output = getStorageData(); - expect(output.name).to.be.equal('goldfishads.com'); - expect(output.segment).to.be.length(2); - expect(output.ext.segtax).to.be.equal(4); - }); - }); -}); diff --git a/test/spec/modules/greenbidsAnalyticsAdapter_spec.js b/test/spec/modules/greenbidsAnalyticsAdapter_spec.js deleted file mode 100644 index fb5924155..000000000 --- a/test/spec/modules/greenbidsAnalyticsAdapter_spec.js +++ /dev/null @@ -1,453 +0,0 @@ -import { - greenbidsAnalyticsAdapter, - isSampled, - ANALYTICS_VERSION, BIDDER_STATUS -} from 'modules/greenbidsAnalyticsAdapter.js'; -import { - generateUUID -} from '../../../src/utils.js'; -import * as utils from 'src/utils.js'; -import { expect } from 'chai'; -import sinon from 'sinon'; - -const events = require('src/events'); -const constants = require('src/constants.js'); - -const pbuid = 'pbuid-AA778D8A796AEA7A0843E2BBEB677766'; -const auctionId = 'b0b39610-b941-4659-a87c-de9f62d3e13e'; - -describe('Greenbids Prebid AnalyticsAdapter Testing', function () { - describe('enableAnalytics and config parser', function () { - const configOptions = { - pbuid: pbuid, - greenbidsSampling: 1, - }; - beforeEach(function () { - greenbidsAnalyticsAdapter.enableAnalytics({ - provider: 'greenbidsAnalytics', - options: configOptions - }); - }); - - afterEach(function () { - greenbidsAnalyticsAdapter.disableAnalytics(); - }); - - it('should parse config correctly with optional values', function () { - expect(greenbidsAnalyticsAdapter.getAnalyticsOptions().options).to.deep.equal(configOptions); - expect(greenbidsAnalyticsAdapter.getAnalyticsOptions().pbuid).to.equal(configOptions.pbuid); - }); - - it('should not enable Analytics when pbuid is missing', function () { - const configOptions = { - options: { - } - }; - const validConfig = greenbidsAnalyticsAdapter.initConfig(configOptions); - expect(validConfig).to.equal(false); - }); - }); - - describe('event tracking and message cache manager', function () { - beforeEach(function () { - const configOptions = { - pbuid: pbuid, - greenbidsSampling: 1, - }; - - greenbidsAnalyticsAdapter.enableAnalytics({ - provider: 'greenbidsAnalytics', - options: configOptions - }); - }); - - afterEach(function () { - greenbidsAnalyticsAdapter.disableAnalytics(); - }); - - describe('#getCachedAuction()', function () { - const existing = { timeoutBids: [{}] }; - greenbidsAnalyticsAdapter.cachedAuctions['test_auction_id'] = existing; - - it('should get the existing cached object if it exists', function () { - const result = greenbidsAnalyticsAdapter.getCachedAuction('test_auction_id'); - - expect(result).to.equal(existing); - }); - - it('should create a new object and store it in the cache on cache miss', function () { - const result = greenbidsAnalyticsAdapter.getCachedAuction('no_such_id'); - - expect(result).to.deep.include({ - timeoutBids: [], - }); - }); - }); - - describe('when formatting JSON payload sent to backend', function () { - const receivedBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit-1', - bidder: 'greenbids', - bidderCode: 'greenbids', - requestId: 'a1b2c3d4', - timeToRespond: 72, - cpm: 0.1, - currency: 'USD', - ad: 'fake ad1' - }, - { - auctionId: auctionId, - adUnitCode: 'adunit-1', - bidder: 'greenbidsx', - bidderCode: 'greenbidsx', - requestId: 'b2c3d4e5', - timeToRespond: 100, - cpm: 0.08, - currency: 'USD', - ad: 'fake ad2', - params: {'placement ID': 12784} - }, - { - auctionId: auctionId, - adUnitCode: 'adunit-2', - bidder: 'greenbids', - bidderCode: 'greenbids', - requestId: 'c3d4e5f6', - timeToRespond: 120, - cpm: 0.09, - currency: 'USD', - ad: 'fake ad3' - }, - ]; - const noBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit-2', - bidder: 'greenbids', - bidderCode: 'greenbids', - bidId: 'a1b2c3d4', - } - ]; - const timeoutBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit-2', - bidder: 'greenbids', - bidderCode: 'greenbids', - bidId: '00123d4c', - } - ]; - function assertHavingRequiredMessageFields(message) { - expect(message).to.include({ - version: ANALYTICS_VERSION, - auctionId: auctionId, - pbuid: pbuid, - referrer: window.location.href, - sampling: 1, - prebid: '$prebid.version$', - }); - } - - describe('#createCommonMessage', function () { - it('should correctly serialize some common fields', function () { - const message = greenbidsAnalyticsAdapter.createCommonMessage(auctionId); - - assertHavingRequiredMessageFields(message); - }); - }); - - describe('#serializeBidResponse', function () { - it('should handle BID properly with timeout false and hasBid true', function () { - const result = greenbidsAnalyticsAdapter.serializeBidResponse(receivedBids[0], BIDDER_STATUS.BID); - - expect(result).to.include({ - bidder: 'greenbids', - isTimeout: false, - hasBid: true, - }); - }); - - it('should handle NO_BID properly and set hasBid to false', function () { - const result = greenbidsAnalyticsAdapter.serializeBidResponse(noBids[0], BIDDER_STATUS.NO_BID); - - expect(result).to.include({ - bidder: 'greenbids', - isTimeout: false, - hasBid: false, - }); - }); - - it('should handle TIMEOUT properly and set isTimeout to true', function () { - const result = greenbidsAnalyticsAdapter.serializeBidResponse(noBids[0], BIDDER_STATUS.TIMEOUT); - - expect(result).to.include({ - bidder: 'greenbids', - isTimeout: true, - hasBid: false, - }); - }); - }); - - describe('#addBidResponseToMessage()', function () { - it('should add a bid response in the output message, grouped by adunit_id and bidder', function () { - const message = { - adUnits: [ - { - code: 'adunit-2', - bidders: [] - } - ] - }; - greenbidsAnalyticsAdapter.addBidResponseToMessage(message, noBids[0], BIDDER_STATUS.NO_BID); - - expect(message.adUnits[0]).to.deep.include({ - code: 'adunit-2', - bidders: [ - { - bidder: 'greenbids', - isTimeout: false, - hasBid: false, - params: {} - } - ] - }); - }); - }); - - describe('#createBidMessage()', function () { - it('should format auction message sent to the backend', function () { - const args = { - auctionId: auctionId, - timestamp: 1234567890, - timeout: 3000, - auctionEnd: 1234567990, - adUnitCodes: ['adunit-1', 'adunit-2'], - adUnits: [ - { - code: 'adunit-1', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - }, - } - }, - { - code: 'adunit-2', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - }, - video: { - context: 'instream', - mimes: ['video/mp4'], - playerSize: [[640, 480]], - skip: 1, - protocols: [1, 2, 3, 4] - }, - }, - ortb2Imp: { - ext: { - data: { - adunitDFP: 'adunitcustomPathExtension' - } - } - } - }, - ], - bidsReceived: receivedBids, - noBids: noBids - }; - - sinon.stub(greenbidsAnalyticsAdapter, 'getCachedAuction').returns({ timeoutBids: timeoutBids }); - const result = greenbidsAnalyticsAdapter.createBidMessage(args, timeoutBids); - greenbidsAnalyticsAdapter.getCachedAuction.restore(); - assertHavingRequiredMessageFields(result); - expect(result).to.deep.include({ - auctionElapsed: 100, - adUnits: [ - { - code: 'adunit-1', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - ortb2Imp: {}, - bidders: [ - { - bidder: 'greenbids', - isTimeout: false, - hasBid: true, - params: {}, - cpm: 0.1, - currency: 'USD', - }, - { - bidder: 'greenbidsx', - isTimeout: false, - hasBid: true, - params: { 'placement ID': 12784 }, - cpm: 0.08, - currency: 'USD', - } - ] - }, - { - code: 'adunit-2', - ortb2Imp: { - ext: { - data: { - adunitDFP: 'adunitcustomPathExtension' - } - } - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - }, - video: { - context: 'instream', - mimes: ['video/mp4'], - playerSize: [[640, 480]], - skip: 1, - protocols: [1, 2, 3, 4] - } - }, - bidders: [ - { - bidder: 'greenbids', - isTimeout: true, - hasBid: true, - cpm: 0.09, - currency: 'USD', - params: {} - } - ] - } - ], - }); - }); - }); - - describe('#handleBidTimeout()', function () { - it('should cached the timeout bid as BID_TIMEOUT event was triggered', function () { - greenbidsAnalyticsAdapter.cachedAuctions['test_timeout_auction_id'] = { 'timeoutBids': [] }; - const args = [{ - auctionId: 'test_timeout_auction_id', - timestamp: 1234567890, - timeout: 3000, - auctionEnd: 1234567990, - bidsReceived: receivedBids, - noBids: noBids, - }]; - - greenbidsAnalyticsAdapter.handleBidTimeout(args); - const result = greenbidsAnalyticsAdapter.getCachedAuction('test_timeout_auction_id'); - expect(result).to.deep.include({ - timeoutBids: [{ - auctionId: 'test_timeout_auction_id', - timestamp: 1234567890, - timeout: 3000, - auctionEnd: 1234567990, - bidsReceived: receivedBids, - noBids: noBids - }] - }); - }); - }); - }); - }); - - describe('greenbids Analytics Adapter track handler ', function () { - const configOptions = { - pbuid: pbuid, - greenbidsSampling: 1, - }; - - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - greenbidsAnalyticsAdapter.enableAnalytics({ - provider: 'greenbidsAnalytics', - options: configOptions - }); - }); - - afterEach(function () { - greenbidsAnalyticsAdapter.disableAnalytics(); - events.getEvents.restore(); - }); - - it('should call handleAuctionInit as AUCTION_INIT trigger event', function () { - sinon.spy(greenbidsAnalyticsAdapter, 'handleAuctionInit'); - events.emit(constants.EVENTS.AUCTION_INIT, { auctionId: 'auctionId' }); - sinon.assert.callCount(greenbidsAnalyticsAdapter.handleAuctionInit, 1); - greenbidsAnalyticsAdapter.handleAuctionInit.restore(); - }); - - it('should call handleBidTimeout as BID_TIMEOUT trigger event', function () { - sinon.spy(greenbidsAnalyticsAdapter, 'handleBidTimeout'); - events.emit(constants.EVENTS.BID_TIMEOUT, { auctionId: 'auctionId' }); - sinon.assert.callCount(greenbidsAnalyticsAdapter.handleBidTimeout, 1); - greenbidsAnalyticsAdapter.handleBidTimeout.restore(); - }); - - it('should call handleAuctionEnd as AUCTION_END trigger event', function () { - sinon.spy(greenbidsAnalyticsAdapter, 'handleAuctionEnd'); - events.emit(constants.EVENTS.AUCTION_END, { auctionId: 'auctionId' }); - sinon.assert.callCount(greenbidsAnalyticsAdapter.handleAuctionEnd, 1); - greenbidsAnalyticsAdapter.handleAuctionEnd.restore(); - }); - - it('should call handleBillable as BILLABLE_EVENT trigger event', function () { - sinon.spy(greenbidsAnalyticsAdapter, 'handleBillable'); - events.emit(constants.EVENTS.BILLABLE_EVENT, { - type: 'auction', - billingId: generateUUID(), - auctionId: 'auctionId', - vendor: 'greenbidsRtdProvider' - }); - sinon.assert.callCount(greenbidsAnalyticsAdapter.handleBillable, 1); - greenbidsAnalyticsAdapter.handleBillable.restore(); - }); - }); - - describe('isSampled', function () { - it('should return true for invalid sampling rates', function () { - expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', -1, 0.0)).to.be.true; - expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 1.2, 0.0)).to.be.true; - }); - - it('should return determinist falsevalue for valid sampling rate given the predifined id and rate', function () { - expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.0001, 0.0)).to.be.false; - }); - - it('should return determinist true value for valid sampling rate given the predifined id and rate', function () { - expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.9999, 0.0)).to.be.true; - }); - - it('should return determinist true value for valid sampling rate given the predifined id and rate when we split to non exploration first', function () { - expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.9999, 0.0, 1.0)).to.be.true; - }); - - it('should return determinist false value for valid sampling rate given the predifined id and rate when we split to non exploration first', function () { - expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.0001, 0.0, 1.0)).to.be.false; - }); - }); - - describe('isSampled when analytic isforced', function () { - before(() => { - if (utils.getParameterByName.restore) { - utils.getParameterByName.restore(); - } - sinon.stub(utils, 'getParameterByName').callsFake(par => par === 'greenbids_force_sampling' ? true : undefined); - }); - it('should return determinist true when sampling flag activated', function () { - expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.0001, 0.0)).to.be.true; - }); - after(() => { - utils.getParameterByName.restore(); - }); - }); -}); diff --git a/test/spec/modules/greenbidsBidAdapter_specs.js b/test/spec/modules/greenbidsBidAdapter_specs.js deleted file mode 100644 index 7caf68677..000000000 --- a/test/spec/modules/greenbidsBidAdapter_specs.js +++ /dev/null @@ -1,1051 +0,0 @@ -import { expect } from 'chai'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { spec } from 'modules/greenbidsBidAdapter.js'; -const ENDPOINT = 'https://d.greenbids.ai/hb/bid-request'; -const AD_SCRIPT = '"'; - -describe('greenbidsBidAdapter', () => { - const adapter = newBidder(spec); - let sandbox; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - - afterEach(function () { - sandbox.restore(); - }); - - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'greenbids', - 'params': { - 'placementId': 4242 - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'creativeId': 'er2ee', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not found', function () { - const bidNonGbCompatible = { - 'bidder': 'greenbids', - }; - expect(spec.isBidRequestValid(bidNonGbCompatible)).to.equal(false); - }); - - it('should return false when the placement is not a number', function () { - const bidNonGbCompatible = { - 'bidder': 'greenbids', - 'params': { - 'placementId': 'toto' - }, - }; - expect(spec.isBidRequestValid(bidNonGbCompatible)).to.equal(false); - }); - }) - describe('buildRequests', function () { - it('should send bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('should not send auctionId in bid request ', function () { - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.data[0].auctionId).to.not.exist - }); - - it('should send US Privacy to endpoint', function () { - const usPrivacy = 'OHHHFCP1' - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'uspConsent': usPrivacy - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.us_privacy).to.exist; - expect(payload.us_privacy).to.equal(usPrivacy); - }); - - it('should send GPP values to endpoint when available and valid', function () { - const consentString = 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN'; - const applicableSectionIds = [7, 8]; - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gppConsent': { - 'gppString': consentString, - 'applicableSections': applicableSectionIds - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gpp).to.exist; - expect(payload.gpp.consentString).to.equal(consentString); - expect(payload.gpp.applicableSectionIds).to.have.members(applicableSectionIds); - }); - - it('should send default GPP values to endpoint when available but invalid', function () { - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gppConsent': { - 'gppString': undefined, - 'applicableSections': ['a'] - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gpp).to.exist; - expect(payload.gpp.consentString).to.equal(''); - expect(payload.gpp.applicableSectionIds).to.have.members([]); - }); - - it('should not set the GPP object in the request sent to the endpoint when not present', function () { - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000 - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gpp).to.not.exist; - }); - - it('should send GDPR to endpoint', function () { - const consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - 'consentString': consentString, - 'gdprApplies': true, - 'vendorData': { - 'isServiceSpecific': true - }, - 'apiVersion': 2 - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdpr_iab).to.exist; - expect(payload.gdpr_iab.consent).to.equal(consentString); - expect(payload.gdpr_iab.status).to.equal(12); - expect(payload.gdpr_iab.apiVersion).to.equal(2); - }); - - it('should add referer info to payload', function () { - const bidRequest = Object.assign({}, bidRequests[0]) - const bidderRequest = { - refererInfo: { - page: 'https://example.com/page.html', - reachedTop: true, - numIframes: 2 - } - } - const request = spec.buildRequests([bidRequest], bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.referrer).to.exist; - expect(payload.referrer).to.deep.equal('https://example.com/page.html') - }); - - const originalConnection = window.navigator.connection; - const mockConnection = { downlink: 10 }; - - const setNavigatorConnection = (connection) => { - Object.defineProperty(window.navigator, 'connection', { - value: connection, - configurable: true, - }); - }; - - try { - setNavigatorConnection(mockConnection); - - const requestWithConnection = spec.buildRequests(bidRequests, bidderRequestDefault); - const payloadWithConnection = JSON.parse(requestWithConnection.data); - - expect(payloadWithConnection.networkBandwidth).to.exist; - expect(payloadWithConnection.networkBandwidth).to.deep.equal(mockConnection.downlink.toString()); - - setNavigatorConnection(undefined); - - const requestWithoutConnection = spec.buildRequests(bidRequests, bidderRequestDefault); - const payloadWithoutConnection = JSON.parse(requestWithoutConnection.data); - - expect(payloadWithoutConnection.networkBandwidth).to.exist; - expect(payloadWithoutConnection.networkBandwidth).to.deep.equal(''); - } finally { - setNavigatorConnection(originalConnection); - } - - it('should add pageReferrer info to payload', function () { - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.pageReferrer).to.exist; - expect(payload.pageReferrer).to.deep.equal(document.referrer); - }); - - it('should add width info to payload', function () { - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - const deviceWidth = screen.width - - expect(payload.deviceWidth).to.exist; - expect(payload.deviceWidth).to.deep.equal(deviceWidth); - }); - - it('should add height info to payload', function () { - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - const deviceHeight = screen.height - - expect(payload.deviceHeight).to.exist; - expect(payload.deviceHeight).to.deep.equal(deviceHeight); - }); - - it('should add pixelRatio info to payload', function () { - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - const pixelRatio = window.top.devicePixelRatio - - expect(payload.devicePixelRatio).to.exist; - expect(payload.devicePixelRatio).to.deep.equal(pixelRatio); - }); - - it('should add screenOrientation info to payload', function () { - const originalScreenOrientation = window.top.screen.orientation; - - const mockScreenOrientation = (type) => { - Object.defineProperty(window.top.screen, 'orientation', { - value: { type }, - configurable: true, - }); - }; - - try { - const mockType = 'landscape-primary'; - mockScreenOrientation(mockType); - - const requestWithOrientation = spec.buildRequests(bidRequests, bidderRequestDefault); - const payloadWithOrientation = JSON.parse(requestWithOrientation.data); - - expect(payloadWithOrientation.screenOrientation).to.exist; - expect(payloadWithOrientation.screenOrientation).to.deep.equal(mockType); - - mockScreenOrientation(undefined); - - const requestWithoutOrientation = spec.buildRequests(bidRequests, bidderRequestDefault); - const payloadWithoutOrientation = JSON.parse(requestWithoutOrientation.data); - - expect(payloadWithoutOrientation.screenOrientation).to.not.exist; - } finally { - Object.defineProperty(window.top.screen, 'orientation', { - value: originalScreenOrientation, - configurable: true, - }); - } - }); - - it('should add historyLength info to payload', function () { - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.historyLength).to.exist; - expect(payload.historyLength).to.deep.equal(window.top.history.length); - }); - - it('should add viewportHeight info to payload', function () { - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.viewportHeight).to.exist; - expect(payload.viewportHeight).to.deep.equal(window.top.visualViewport.height); - }); - - it('should add viewportWidth info to payload', function () { - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.viewportWidth).to.exist; - expect(payload.viewportWidth).to.deep.equal(window.top.visualViewport.width); - }); - - it('should add viewportHeight info to payload', function () { - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.viewportHeight).to.exist; - expect(payload.viewportHeight).to.deep.equal(window.top.visualViewport.height); - }); - - it('should add ortb2 device data to payload', function () { - const ortb2DeviceBidderRequest = { - ...bidderRequestDefault, - ...{ - ortb2: { - device: { - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - ext: { fiftyonedegrees_deviceId: '17595-133085-133468-18092' }, - }, - }, - }, - }; - const request = spec.buildRequests(bidRequests, ortb2DeviceBidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.device).to.deep.equal(ortb2DeviceBidderRequest.ortb2.device); - }); - - it('should add hardwareConcurrency info to payload', function () { - const originalHardwareConcurrency = window.top.navigator.hardwareConcurrency; - - const mockHardwareConcurrency = (value) => { - Object.defineProperty(window.top.navigator, 'hardwareConcurrency', { - value, - configurable: true, - }); - }; - - try { - const mockValue = 8; - mockHardwareConcurrency(mockValue); - - const requestWithHardwareConcurrency = spec.buildRequests(bidRequests, bidderRequestDefault); - const payloadWithHardwareConcurrency = JSON.parse(requestWithHardwareConcurrency.data); - - expect(payloadWithHardwareConcurrency.hardwareConcurrency).to.exist; - expect(payloadWithHardwareConcurrency.hardwareConcurrency).to.deep.equal(mockValue); - - mockHardwareConcurrency(undefined); - - const requestWithoutHardwareConcurrency = spec.buildRequests(bidRequests, bidderRequestDefault); - const payloadWithoutHardwareConcurrency = JSON.parse(requestWithoutHardwareConcurrency.data); - - expect(payloadWithoutHardwareConcurrency.hardwareConcurrency).to.not.exist; - } finally { - Object.defineProperty(window.top.navigator, 'hardwareConcurrency', { - value: originalHardwareConcurrency, - configurable: true, - }); - } - }); - - it('should add deviceMemory info to payload', function () { - const originalDeviceMemory = window.top.navigator.deviceMemory; - - const mockDeviceMemory = (value) => { - Object.defineProperty(window.top.navigator, 'deviceMemory', { - value, - configurable: true, - }); - }; - - try { - const mockValue = 4; - mockDeviceMemory(mockValue); - - const requestWithDeviceMemory = spec.buildRequests(bidRequests, bidderRequestDefault); - const payloadWithDeviceMemory = JSON.parse(requestWithDeviceMemory.data); - - expect(payloadWithDeviceMemory.deviceMemory).to.exist; - expect(payloadWithDeviceMemory.deviceMemory).to.deep.equal(mockValue); - - mockDeviceMemory(undefined); - - const requestWithoutDeviceMemory = spec.buildRequests(bidRequests, bidderRequestDefault); - const payloadWithoutDeviceMemory = JSON.parse(requestWithoutDeviceMemory.data); - - expect(payloadWithoutDeviceMemory.deviceMemory).to.not.exist; - } finally { - Object.defineProperty(window.top.navigator, 'deviceMemory', { - value: originalDeviceMemory, - configurable: true, - }); - } - }); - }); - - describe('pageTitle', function () { - it('should add pageTitle info to payload based on document title', function () { - const testText = 'This is a title'; - sandbox.stub(window.top.document, 'title').value(testText); - - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.pageTitle).to.exist; - expect(payload.pageTitle).to.deep.equal(testText); - }); - - it('should add pageTitle info to payload based on open-graph title', function () { - const testText = 'This is a title from open-graph'; - sandbox.stub(window.top.document, 'title').value(''); - sandbox.stub(window.top.document, 'querySelector').withArgs('meta[property="og:title"]').returns({ content: testText }); - - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.pageTitle).to.exist; - expect(payload.pageTitle).to.deep.equal(testText); - }); - - it('should add pageTitle info to payload sliced on 300 first characters', function () { - const testText = Array(500).join('a'); - sandbox.stub(window.top.document, 'title').value(testText); - - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.pageTitle).to.exist; - expect(payload.pageTitle).to.have.length(300); - }); - - it('should add pageTitle info to payload when fallbacking from window.top', function () { - const testText = 'This is a fallback title'; - sandbox.stub(window.top.document, 'querySelector').throws(); - sandbox.stub(document, 'title').value(testText); - - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.pageTitle).to.exist; - expect(payload.pageTitle).to.deep.equal(testText); - }); - }); - - describe('pageDescription', function () { - it('should add pageDescription info to payload based on open-graph description', function () { - const testText = 'This is a description'; - sandbox.stub(window.top.document, 'querySelector').withArgs('meta[name="description"]').returns({ content: testText }); - - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.pageDescription).to.exist; - expect(payload.pageDescription).to.deep.equal(testText); - }); - - it('should add pageDescription info to payload based on open-graph description', function () { - const testText = 'This is a description from open-graph'; - sandbox.stub(window.top.document, 'querySelector').withArgs('meta[property="og:description"]').returns({ content: testText }); - - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.pageDescription).to.exist; - expect(payload.pageDescription).to.deep.equal(testText); - }); - - it('should add pageDescription info to payload sliced on 300 first characters', function () { - const testText = Array(500).join('a'); - sandbox.stub(window.top.document, 'querySelector').withArgs('meta[name="description"]').returns({ content: testText }); - - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.pageDescription).to.exist; - expect(payload.pageDescription).to.have.length(300); - }); - - it('should add pageDescription info to payload when fallbacking from window.top', function () { - const testText = 'This is a fallback description'; - sandbox.stub(window.top.document, 'querySelector').throws(); - sandbox.stub(document, 'querySelector').withArgs('meta[name="description"]').returns({ content: testText }); - - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.pageDescription).to.exist; - expect(payload.pageDescription).to.deep.equal(testText); - }); - - it('should add timeToFirstByte info to payload for Navigation Timing V2', function () { - // Mock `performance` object with Navigation Timing V2 data - const mockPerformance = { - getEntriesByType: () => [ - { requestStart: 100, responseStart: 150 }, - ], - }; - - // Override the global performance object - const originalPerformance = window.performance; - window.performance = mockPerformance; - - // Execute the code - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - // Calculate expected TTFB for V2 - const ttfbExpected = Math.round( - mockPerformance.getEntriesByType('navigation')[0].responseStart - - mockPerformance.getEntriesByType('navigation')[0].requestStart - ).toString(); - - // Assertions - expect(payload.timeToFirstByte).to.exist; - expect(payload.timeToFirstByte).to.deep.equal(ttfbExpected); - - // Restore the original performance object - window.performance = originalPerformance; - }); - - it('should add timeToFirstByte info to payload for Navigation Timing V1', function () { - // Mock `performance` object with Navigation Timing V1 data - const mockPerformance = { - timing: { - requestStart: 100, - responseStart: 150, - }, - getEntriesByType: () => [], - }; - - // Override the global performance object - const originalPerformance = window.performance; - window.performance = mockPerformance; - - // Execute the code - const request = spec.buildRequests(bidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - // Calculate expected TTFB for V1 - const ttfbExpected = ( - mockPerformance.timing.responseStart - mockPerformance.timing.requestStart - ).toString(); - - // Assertions - expect(payload.timeToFirstByte).to.exist; - expect(payload.timeToFirstByte).to.deep.equal(ttfbExpected); - - // Restore the original performance object - window.performance = originalPerformance; - }); - - it('should send GDPR to endpoint with 11 status', function () { - const consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - 'consentString': consentString, - 'gdprApplies': true, - 'vendorData': { - 'isServiceSpecific': false, - }, - 'apiVersion': 2 - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdpr_iab).to.exist; - expect(payload.gdpr_iab.consent).to.equal(consentString); - expect(payload.gdpr_iab.status).to.equal(11); - expect(payload.gdpr_iab.apiVersion).to.equal(2); - }); - - it('should send GDPR TCF2 to endpoint with 12 status', function () { - const consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - 'consentString': consentString, - 'gdprApplies': true, - 'vendorData': { - 'isServiceSpecific': true - }, - 'apiVersion': 2 - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdpr_iab).to.exist; - expect(payload.gdpr_iab.consent).to.equal(consentString); - expect(payload.gdpr_iab.status).to.equal(12); - expect(payload.gdpr_iab.apiVersion).to.equal(2); - }); - - it('should send GDPR to endpoint with 22 status', function () { - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - 'consentString': undefined, - 'gdprApplies': undefined, - 'vendorData': undefined, - 'apiVersion': 2 - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdpr_iab).to.exist; - expect(payload.gdpr_iab.consent).to.equal(''); - expect(payload.gdpr_iab.status).to.equal(22); - expect(payload.gdpr_iab.apiVersion).to.equal(2); - }); - - it('should send GDPR to endpoint with 0 status', function () { - const consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - 'consentString': consentString, - 'gdprApplies': false, - 'vendorData': { - 'hasGlobalScope': false - }, - 'apiVersion': 2 - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdpr_iab).to.exist; - expect(payload.gdpr_iab.consent).to.equal(consentString); - expect(payload.gdpr_iab.status).to.equal(0); - expect(payload.gdpr_iab.apiVersion).to.equal(2); - }); - - it('should send GDPR to endpoint with 0 status when gdprApplies = false (vendorData = undefined)', function () { - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - 'consentString': undefined, - 'gdprApplies': false, - 'vendorData': undefined, - 'apiVersion': 2 - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdpr_iab).to.exist; - expect(payload.gdpr_iab.consent).to.equal(''); - expect(payload.gdpr_iab.status).to.equal(0); - expect(payload.gdpr_iab.apiVersion).to.equal(2); - }); - - it('should send GDPR to endpoint with 12 status when apiVersion = 0', function () { - const consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - 'consentString': consentString, - 'gdprApplies': true, - 'vendorData': { - 'isServiceSpecific': true - }, - 'apiVersion': 0 - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdpr_iab).to.exist; - expect(payload.gdpr_iab.consent).to.equal(consentString); - expect(payload.gdpr_iab.status).to.equal(12); - expect(payload.gdpr_iab.apiVersion).to.equal(0); - }); - - it('should add schain info to payload if available', function () { - const bidRequest = Object.assign({}, bidRequests[0], { - schain: { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'example.com', - sid: '00001', - hp: 1 - }] - } - }); - - const request = spec.buildRequests([bidRequest], bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.schain).to.exist; - expect(payload.schain).to.deep.equal({ - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'example.com', - sid: '00001', - hp: 1 - }] - }); - }); - - it('should add userAgentClientHints info to payload if available', function () { - const sua = { - source: 2, - platform: { - brand: 'macOS', - version: ['12', '4', '0'] - }, - browsers: [ - { - brand: 'Chromium', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Google Chrome', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Not;A=Brand', - version: ['99', '0', '0', '0'] - } - ], - mobile: 0, - model: '', - bitness: '64', - architecture: 'x86' - } - - const bidRequest = Object.assign({}, bidRequests[0], { - ortb2: { - device: { - sua: sua - } - } - }); - - const requestWithUserAgentClientHints = spec.buildRequests([bidRequest], bidderRequestDefault); - const payload = JSON.parse(requestWithUserAgentClientHints.data); - - expect(payload.userAgentClientHints).to.exist; - expect(payload.userAgentClientHints).to.deep.equal(sua); - - const defaultRequest = spec.buildRequests(bidRequests, bidderRequestDefault); - expect(JSON.parse(defaultRequest.data).userAgentClientHints).to.not.exist; - }); - - it('should use good mediaTypes banner sizes', function () { - const mediaTypesBannerSize = { - 'mediaTypes': { - 'banner': { - 'sizes': [300, 250] - } - } - }; - checkMediaTypesSizes(mediaTypesBannerSize, '300x250'); - }); - }); - - describe('Global Placement Id', function () { - const bidRequests = [ - { - 'bidder': 'greenbids', - 'params': { - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'creativeId': 'er2ee', - 'deviceWidth': 1680 - }, - { - 'bidder': 'greenbids', - 'params': { - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1f', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'creativeId': 'er2ef', - 'deviceWidth': 1680 - } - ]; - - it('should add gpid if ortb2Imp.ext.gpid is present and is non empty', function () { - const updatedBidRequests = bidRequests.map(function (bidRequest, index) { - return { - ...bidRequest, - ortb2Imp: { - ext: { - gpid: '1111/home-left-' + index - } - } - }; - } - ); - const request = spec.buildRequests(updatedBidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - expect(payload.data[0].gpid).to.equal('1111/home-left-0'); - expect(payload.data[1].gpid).to.equal('1111/home-left-1'); - }); - - it('should not add gpid if ortb2Imp.ext.gpid is present but empty', function () { - const updatedBidRequests = bidRequests.map(bidRequest => ({ - ...bidRequest, - ortb2Imp: { - ext: { - gpid: '' - } - } - })); - - const request = spec.buildRequests(updatedBidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - payload.data.forEach(bid => { - expect(bid).not.to.have.property('gpid'); - }); - }); - - it('should not add gpid if ortb2Imp.ext.gpid is not present', function () { - const updatedBidRequests = bidRequests.map(bidRequest => ({ - ...bidRequest, - ortb2Imp: { - ext: { - } - } - })); - - const request = spec.buildRequests(updatedBidRequests, bidderRequestDefault); - const payload = JSON.parse(request.data); - - payload.data.forEach(bid => { - expect(bid).not.to.have.property('gpid'); - }); - }); - - it('should add dsa info to payload if available', function () { - const bidRequestWithDsa = Object.assign({}, bidderRequestDefault, { - ortb2: { - regs: { - ext: { - dsa: { - dsarequired: '1', - pubrender: '2', - datatopub: '3', - transparency: [{ - domain: 'test.com', - dsaparams: [1, 2, 3] - }] - } - } - } - } - }); - - const requestWithDsa = spec.buildRequests(bidRequests, bidRequestWithDsa); - const payload = JSON.parse(requestWithDsa.data); - - expect(payload.dsa).to.exist; - expect(payload.dsa).to.deep.equal( - { - dsarequired: '1', - pubrender: '2', - datatopub: '3', - transparency: [{ - domain: 'test.com', - dsaparams: [1, 2, 3] - }] - } - ); - - const defaultRequest = spec.buildRequests(bidRequests, bidderRequestDefault); - expect(JSON.parse(defaultRequest.data).dsa).to.not.exist; - }); - }); - - describe('interpretResponse', function () { - it('should get correct bid responses', function () { - const bids = { - 'body': { - 'responses': [{ - 'ad': AD_SCRIPT, - 'cpm': 0.5, - 'currency': 'USD', - 'height': 250, - 'bidId': '3ede2a3fa0db94', - 'ttl': 360, - 'width': 300, - 'creativeId': 'er2ee', - 'placementId': 4242 - }, { - 'ad': AD_SCRIPT, - 'cpm': 0.5, - 'currency': 'USD', - 'height': 200, - 'bidId': '4fef3b4gb1ec15', - 'ttl': 360, - 'width': 350, - 'creativeId': 'fs3ff', - 'placementId': 4242, - 'dealId': 'ABC_123', - 'ext': { - 'dsa': { - 'behalf': 'some-behalf', - 'paid': 'some-paid', - 'transparency': [{ - 'domain': 'test.com', - 'dsaparams': [1, 2, 3] - }], - 'adrender': 1 - } - } - }] - } - }; - const expectedResponse = [ - { - 'cpm': 0.5, - 'width': 300, - 'height': 250, - 'currency': 'USD', - 'netRevenue': true, - 'meta': { - advertiserDomains: [] - }, - 'ttl': 360, - 'ad': AD_SCRIPT, - 'requestId': '3ede2a3fa0db94', - 'creativeId': 'er2ee', - 'placementId': 4242 - }, { - 'cpm': 0.5, - 'width': 350, - 'height': 200, - 'currency': 'USD', - 'netRevenue': true, - 'meta': { - advertiserDomains: [], - dsa: { - behalf: 'some-behalf', - paid: 'some-paid', - transparency: [{ - domain: 'test.com', - dsaparams: [1, 2, 3] - }], - adrender: 1 - } - }, - 'ttl': 360, - 'ad': AD_SCRIPT, - 'requestId': '4fef3b4gb1ec15', - 'creativeId': 'fs3ff', - 'placementId': 4242, - 'dealId': 'ABC_123' - } - ] - ; - - const result = spec.interpretResponse(bids); - expect(result).to.eql(expectedResponse); - }); - - it('handles nobid responses', function () { - const bids = { - 'body': { - 'responses': [] - } - }; - - const result = spec.interpretResponse(bids); - expect(result.length).to.equal(0); - }); - }); -}); - -const bidderRequestDefault = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000 -}; - -const bidRequests = [ - { - 'bidder': 'greenbids', - 'params': { - 'placementId': 4242 - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'creativeId': 'er2ee', - 'deviceWidth': 1680 - } -]; - -function checkMediaTypesSizes(mediaTypes, expectedSizes) { - const bidRequestWithBannerSizes = Object.assign(bidRequests[0], mediaTypes); - const requestWithBannerSizes = spec.buildRequests([bidRequestWithBannerSizes], bidderRequestDefault); - const payloadWithBannerSizes = JSON.parse(requestWithBannerSizes.data); - - return payloadWithBannerSizes.data.forEach(bid => { - if (Array.isArray(expectedSizes)) { - expect(JSON.stringify(bid.sizes)).to.equal(JSON.stringify(expectedSizes)); - } else { - expect(bid.sizes[0]).to.equal(expectedSizes); - } - }); -} diff --git a/test/spec/modules/greenbidsRtdProvider_spec.js b/test/spec/modules/greenbidsRtdProvider_spec.js deleted file mode 100644 index 0074600df..000000000 --- a/test/spec/modules/greenbidsRtdProvider_spec.js +++ /dev/null @@ -1,357 +0,0 @@ -import { expect } from 'chai'; -import sinon from 'sinon'; -import { - deepClone, -} from '../../../src/utils.js'; -import { - greenbidsSubmodule -} from 'modules/greenbidsRtdProvider.js'; -import { server } from '../../mocks/xhr.js'; -import * as events from '../../../src/events.js'; -import { EVENTS } from '../../../src/constants.js'; - -describe('greenbidsRtdProvider', () => { - const endPoint = 't.greenbids.ai'; - - const SAMPLE_MODULE_CONFIG = { - params: { - pbuid: '12345', - timeout: 200, - targetTPR: 0.95 - } - }; - - const SAMPLE_REQUEST_BIDS_CONFIG_OBJ = { - adUnits: [ - { - code: 'adUnit1', - bids: [ - { bidder: 'appnexus', params: {} }, - { bidder: 'rubicon', params: {} }, - { bidder: 'ix', params: {} } - ] - }, - { - code: 'adUnit2', - bids: [ - { bidder: 'appnexus', params: {} }, - { bidder: 'rubicon', params: {} }, - { bidder: 'openx', params: {} } - ] - }] - }; - - const SAMPLE_RESPONSE_ADUNITS_NOT_EXPLORED = [ - { - code: 'adUnit1', - bidders: { - 'appnexus': true, - 'rubicon': false, - 'ix': true - }, - isExploration: false - }, - { - code: 'adUnit2', - bidders: { - 'appnexus': false, - 'rubicon': true, - 'openx': true - }, - isExploration: false - - }]; - - const SAMPLE_RESPONSE_ADUNITS_EXPLORED = [ - { - code: 'adUnit1', - bidders: { - 'appnexus': true, - 'rubicon': false, - 'ix': true - }, - isExploration: true - }, - { - code: 'adUnit2', - bidders: { - 'appnexus': false, - 'rubicon': true, - 'openx': true - }, - isExploration: true - - }]; - - describe('init', () => { - it('should return true and set rtdOptions if pbuid is present', () => { - const result = greenbidsSubmodule.init(SAMPLE_MODULE_CONFIG); - expect(result).to.be.true; - }); - - it('should return false if pbuid is not present', () => { - const result = greenbidsSubmodule.init({ params: {} }); - expect(result).to.be.false; - }); - }); - - describe('updateAdUnitsBasedOnResponse', () => { - it('should update ad units based on response if not exploring', () => { - const adUnits = JSON.parse(JSON.stringify(SAMPLE_REQUEST_BIDS_CONFIG_OBJ.adUnits)); - greenbidsSubmodule.updateAdUnitsBasedOnResponse(adUnits, SAMPLE_RESPONSE_ADUNITS_NOT_EXPLORED); - - expect(adUnits[0].bids).to.have.length(2); - expect(adUnits[1].bids).to.have.length(2); - }); - - it('should not update ad units based on response if exploring', () => { - const adUnits = JSON.parse(JSON.stringify(SAMPLE_REQUEST_BIDS_CONFIG_OBJ.adUnits)); - greenbidsSubmodule.updateAdUnitsBasedOnResponse(adUnits, SAMPLE_RESPONSE_ADUNITS_EXPLORED); - - expect(adUnits[0].bids).to.have.length(3); - expect(adUnits[1].bids).to.have.length(3); - expect(adUnits[0].ortb2Imp.ext.greenbids.greenbidsId).to.be.a.string; - expect(adUnits[1].ortb2Imp.ext.greenbids.greenbidsId).to.be.a.string; - expect(adUnits[0].ortb2Imp.ext.greenbids.greenbidsId).to.equal(adUnits[0].ortb2Imp.ext.greenbids.greenbidsId); - expect(adUnits[0].ortb2Imp.ext.greenbids.keptInAuction).to.deep.equal(SAMPLE_RESPONSE_ADUNITS_EXPLORED[0].bidders); - expect(adUnits[1].ortb2Imp.ext.greenbids.keptInAuction).to.deep.equal(SAMPLE_RESPONSE_ADUNITS_EXPLORED[1].bidders); - expect(adUnits[0].ortb2Imp.ext.greenbids.isExploration).to.equal(SAMPLE_RESPONSE_ADUNITS_EXPLORED[0].isExploration); - expect(adUnits[1].ortb2Imp.ext.greenbids.isExploration).to.equal(SAMPLE_RESPONSE_ADUNITS_EXPLORED[1].isExploration); - }); - }); - - describe('findMatchingAdUnit', () => { - it('should find matching ad unit by code', () => { - const matchingAdUnit = greenbidsSubmodule.findMatchingAdUnit(SAMPLE_RESPONSE_ADUNITS_NOT_EXPLORED, 'adUnit1'); - expect(matchingAdUnit).to.deep.equal(SAMPLE_RESPONSE_ADUNITS_NOT_EXPLORED[0]); - }); - it('should return undefined if no matching ad unit is found', () => { - const matchingAdUnit = greenbidsSubmodule.findMatchingAdUnit(SAMPLE_RESPONSE_ADUNITS_NOT_EXPLORED, 'nonexistent'); - expect(matchingAdUnit).to.be.undefined; - }); - }); - - describe('removeFalseBidders', () => { - it('should remove bidders with false value', () => { - const adUnit = JSON.parse(JSON.stringify(SAMPLE_REQUEST_BIDS_CONFIG_OBJ.adUnits[0])); - const matchingAdUnit = SAMPLE_RESPONSE_ADUNITS_NOT_EXPLORED[0]; - greenbidsSubmodule.removeFalseBidders(adUnit, matchingAdUnit); - expect(adUnit.bids).to.have.length(2); - expect(adUnit.bids.map((bid) => bid.bidder)).to.not.include('rubicon'); - }); - }); - - describe('getFalseBidders', () => { - it('should return an array of false bidders', () => { - const bidders = { - appnexus: true, - rubicon: false, - ix: true, - openx: false - }; - const falseBidders = greenbidsSubmodule.getFalseBidders(bidders); - expect(falseBidders).to.have.length(2); - expect(falseBidders).to.include('rubicon'); - expect(falseBidders).to.include('openx'); - }); - }); - - describe('getBidRequestData', () => { - it('Callback is called if the server responds a 200 within the time limit', (done) => { - const requestBids = deepClone(SAMPLE_REQUEST_BIDS_CONFIG_OBJ); - const callback = sinon.stub(); - - greenbidsSubmodule.getBidRequestData(requestBids, callback, SAMPLE_MODULE_CONFIG); - - setTimeout(() => { - server.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(SAMPLE_RESPONSE_ADUNITS_NOT_EXPLORED) - ); - }, 50); - - setTimeout(() => { - const requestUrl = new URL(server.requests[0].url); - expect(requestUrl.host).to.be.eq(endPoint); - expect(requestBids.greenbidsId).to.be.a.string; - expect(requestBids.adUnits[0].bids).to.have.length(2); - expect(requestBids.adUnits[0].bids.map((bid) => bid.bidder)).to.not.include('rubicon'); - expect(requestBids.adUnits[0].bids.map((bid) => bid.bidder)).to.include('ix'); - expect(requestBids.adUnits[0].bids.map((bid) => bid.bidder)).to.include('appnexus'); - expect(requestBids.adUnits[1].bids).to.have.length(2); - expect(requestBids.adUnits[1].bids.map((bid) => bid.bidder)).to.not.include('appnexus'); - expect(requestBids.adUnits[1].bids.map((bid) => bid.bidder)).to.include('rubicon'); - expect(requestBids.adUnits[1].bids.map((bid) => bid.bidder)).to.include('openx'); - expect(callback.calledOnce).to.be.true; - done(); - }, 60); - }); - }); - - describe('getBidRequestData', () => { - it('Nothing changes if the server times out but still the callback is called', (done) => { - const requestBids = deepClone(SAMPLE_REQUEST_BIDS_CONFIG_OBJ); - const callback = sinon.stub(); - - greenbidsSubmodule.getBidRequestData(requestBids, callback, SAMPLE_MODULE_CONFIG); - - setTimeout(() => { - server.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify(SAMPLE_RESPONSE_ADUNITS_NOT_EXPLORED) - ); - done(); - }, 300); - - setTimeout(() => { - const requestUrl = new URL(server.requests[0].url); - expect(requestUrl.host).to.be.eq(endPoint); - expect(requestBids.greenbidsId).to.be.a.string; - expect(requestBids.adUnits[0].bids).to.have.length(3); - expect(requestBids.adUnits[1].bids).to.have.length(3); - expect(callback.calledOnce).to.be.true; - }, 200); - }); - }); - - describe('getBidRequestData', () => { - it('callback is called if the server responds a 500 error within the time limit and no changes are made', (done) => { - const requestBids = deepClone(SAMPLE_REQUEST_BIDS_CONFIG_OBJ); - const callback = sinon.stub(); - - greenbidsSubmodule.getBidRequestData(requestBids, callback, SAMPLE_MODULE_CONFIG); - - setTimeout(() => { - server.requests[0].respond( - 500, - { 'Content-Type': 'application/json' }, - JSON.stringify({ 'failure': 'fail' }) - ); - }, 50); - - setTimeout(() => { - const requestUrl = new URL(server.requests[0].url); - expect(requestUrl.host).to.be.eq(endPoint); - expect(requestBids.greenbidsId).to.be.a.string; - expect(requestBids.adUnits[0].bids).to.have.length(3); - expect(requestBids.adUnits[1].bids).to.have.length(3); - expect(callback.calledOnce).to.be.true; - done(); - }, 60); - }); - }); - - describe('stripAdUnits', function () { - it('should strip all properties except bidder from each bid in adUnits', function () { - const adUnits = - [ - { - bids: [ - { bidder: 'bidder1', otherProp: 'value1' }, - { bidder: 'bidder2', otherProp: 'value2' } - ], - mediaTypes: { 'banner': { prop: 'value3' } } - } - ]; - const expectedOutput = [ - { - bids: [ - { bidder: 'bidder1' }, - { bidder: 'bidder2' } - ], - mediaTypes: { 'banner': { prop: 'value3' } } - } - ]; - - // Perform the test - const output = greenbidsSubmodule.stripAdUnits(adUnits); - expect(output).to.deep.equal(expectedOutput); - }); - - it('should strip all properties except bidder from each bid in adUnits but keep ortb2Imp', function () { - const adUnits = - [ - { - bids: [ - { bidder: 'bidder1', otherProp: 'value1' }, - { bidder: 'bidder2', otherProp: 'value2' } - ], - mediaTypes: { 'banner': { prop: 'value3' } }, - ortb2Imp: { - ext: { - greenbids: { - greenbidsId: 'test' - } - } - } - } - ]; - const expectedOutput = [ - { - bids: [ - { bidder: 'bidder1' }, - { bidder: 'bidder2' } - ], - mediaTypes: { 'banner': { prop: 'value3' } }, - ortb2Imp: { - ext: { - greenbids: { - greenbidsId: 'test' - } - } - } - } - ]; - - // Perform the test - const output = greenbidsSubmodule.stripAdUnits(adUnits); - expect(output).to.deep.equal(expectedOutput); - }); - }); - - describe('onAuctionInitEvent', function () { - it('should not emit billable event if greenbids hasn\'t set the adunit.ext value', function () { - sinon.spy(events, 'emit'); - greenbidsSubmodule.onAuctionInitEvent({ - auctionId: 'test', - adUnits: [ - { - bids: [ - { bidder: 'bidder1', otherProp: 'value1' }, - { bidder: 'bidder2', otherProp: 'value2' } - ], - mediaTypes: { 'banner': { prop: 'value3' } }, - } - ] - }); - sinon.assert.callCount(events.emit, 0); - events.emit.restore(); - }); - - it('should emit billable event if greenbids has set the adunit.ext value', function (done) { - let counter = 0; - events.on(EVENTS.BILLABLE_EVENT, function (event) { - if (event.vendor === 'greenbidsRtdProvider' && event.type === 'auction') { - counter += 1; - } - expect(counter).to.equal(1); - done(); - }); - greenbidsSubmodule.onAuctionInitEvent({ - auctionId: 'test', - adUnits: [ - { - bids: [ - { bidder: 'bidder1', otherProp: 'value1' }, - { bidder: 'bidder2', otherProp: 'value2' } - ], - mediaTypes: { 'banner': { prop: 'value3' } }, - ortb2Imp: { ext: { greenbids: { greenbidsId: 'b0b39610-b941-4659-a87c-de9f62d3e13e' } } } - } - ] - }); - }); - }); -}); diff --git a/test/spec/modules/gridBidAdapter_spec.js b/test/spec/modules/gridBidAdapter_spec.js deleted file mode 100644 index 9fbc66c79..000000000 --- a/test/spec/modules/gridBidAdapter_spec.js +++ /dev/null @@ -1,1696 +0,0 @@ -import { expect } from 'chai'; -import { spec, resetUserSync, getSyncUrl, storage } from 'modules/gridBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import {ENDPOINT_DOMAIN, ENDPOINT_PROTOCOL} from '../../../modules/adpartnerBidAdapter.js'; - -describe('TheMediaGrid Adapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'grid', - 'params': { - 'uid': '1' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'uid': 0 - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - function parseRequest(data) { - return JSON.parse(data); - } - const bidderRequest = { - refererInfo: { page: 'https://example.com' }, - bidderRequestId: '22edbae2733bf6', - transactionId: '1239bd74-4511-4335-af21-e828852e25d7', - timeout: 3000, - auctionId: '9e2dfbfe-00c7-4f5e-9850-4044df3229c7', - ortb2: { - source: { - tid: '9e2dfbfe-00c7-4f5e-9850-4044df3229c7', - } - } - }; - const referrer = encodeURIComponent(bidderRequest.refererInfo.page); - const bidRequests = [ - { - 'bidder': 'grid', - 'params': { - 'uid': '1', - 'bidFloor': 1.25 - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 600]] - } - }, - 'bidId': '42dbe3a7168a6a', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '9e2dfbfe-00c7-4f5e-9850-4044df3229c7', - transactionId: '1239bd74-4511-4335-af21-e828852e25d7', - ortb2Imp: { - ext: { - tid: '1239bd74-4511-4335-af21-e828852e25d7', - } - } - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '2' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '9e2dfbfe-00c7-4f5e-9850-4044df3229c7', - transactionId: '1239bd74-4511-4335-af21-e828852e25d7', - ortb2Imp: { - ext: { - tid: '1239bd74-4511-4335-af21-e828852e25d7', - } - } - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '11' - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[728, 90]], - 'mediaTypes': { - 'video': { - 'playerSize': [[400, 600]], - 'mimes': ['video/mp4', 'video/webm', 'application/javascript', 'video/ogg'] - } - }, - 'bidId': '3150ccb55da321', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '9e2dfbfe-00c7-4f5e-9850-4044df3229c7', - transactionId: '1239bd74-4511-4335-af21-e828852e25d7', - ortb2Imp: { - ext: { - tid: '1239bd74-4511-4335-af21-e828852e25d7', - } - } - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '3' - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[728, 90]], - 'mediaTypes': { - 'video': { - 'playerSize': [[400, 600]], - 'protocols': [1, 2, 3] - }, - 'banner': { - 'sizes': [[728, 90]] - } - }, - 'bidId': '3150ccb55da321', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '9e2dfbfe-00c7-4f5e-9850-4044df3229c7', - transactionId: '1239bd74-4511-4335-af21-e828852e25d7', - ortb2Imp: { - ext: { - tid: '1239bd74-4511-4335-af21-e828852e25d7', - } - } - } - ]; - - it('should be content categories and genre', function () { - const site = { - cat: ['IAB2'], - pagecat: ['IAB2-2'], - content: { - genre: 'Adventure' - } - }; - const [request] = spec.buildRequests([bidRequests[0]], {...bidderRequest, ortb2: {site}}); - const payload = parseRequest(request.data); - expect(payload.site.cat).to.deep.equal([...site.cat, ...site.pagecat]); - expect(payload.site.content.genre).to.deep.equal(site.content.genre); - }); - - it('should attach valid params to the tag', function () { - const fpdUserIdVal = '0b0f84a1-1596-4165-9742-2e1a7dfac57f'; - const getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage').callsFake( - arg => arg === 'tmguid' ? fpdUserIdVal : null); - - const [request] = spec.buildRequests([bidRequests[0]], bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload).to.deep.equal({ - 'id': bidderRequest.bidderRequestId, - 'site': { - 'page': referrer - }, - 'tmax': bidderRequest.timeout, - 'source': { - 'tid': bidderRequest.ortb2.source.tid, - 'ext': {'wrapper': 'Prebid_js', 'wrapper_version': '$prebid.version$'} - }, - 'user': { - 'id': fpdUserIdVal - }, - 'imp': [{ - 'id': bidRequests[0].bidId, - 'tagid': bidRequests[0].params.uid, - 'ext': {'divid': bidRequests[0].adUnitCode}, - 'bidfloor': bidRequests[0].params.bidFloor, - 'banner': { - 'w': 300, - 'h': 250, - 'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}] - } - }] - }); - - getDataFromLocalStorageStub.restore(); - }); - - it('make possible to process request without mediaTypes', function () { - const fpdUserIdVal = '0b0f84a1-1596-4165-9742-2e1a7dfac57f'; - const getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage').callsFake( - arg => arg === 'tmguid' ? fpdUserIdVal : null); - - const [request] = spec.buildRequests([bidRequests[0], bidRequests[1]], bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload).to.deep.equal({ - 'id': bidderRequest.bidderRequestId, - 'site': { - 'page': referrer - }, - 'tmax': bidderRequest.timeout, - 'source': { - 'tid': bidderRequest.auctionId, - 'ext': {'wrapper': 'Prebid_js', 'wrapper_version': '$prebid.version$'} - }, - 'user': { - 'id': fpdUserIdVal - }, - 'imp': [{ - 'id': bidRequests[0].bidId, - 'tagid': bidRequests[0].params.uid, - 'ext': {'divid': bidRequests[0].adUnitCode}, - 'bidfloor': bidRequests[0].params.bidFloor, - 'banner': { - 'w': 300, - 'h': 250, - 'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}] - } - }, { - 'id': bidRequests[1].bidId, - 'tagid': bidRequests[1].params.uid, - 'ext': {'divid': bidRequests[1].adUnitCode}, - 'banner': { - 'w': 300, - 'h': 250, - 'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}] - } - }] - }); - - getDataFromLocalStorageStub.restore(); - }); - - it('should attach valid params to the video tag', function () { - const fpdUserIdVal = '0b0f84a1-1596-4165-9742-2e1a7dfac57f'; - const getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage').callsFake( - arg => arg === 'tmguid' ? fpdUserIdVal : null); - - const [request] = spec.buildRequests(bidRequests.slice(0, 3), bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload).to.deep.equal({ - 'id': bidderRequest.bidderRequestId, - 'site': { - 'page': referrer - }, - 'tmax': bidderRequest.timeout, - 'source': { - 'tid': bidderRequest.auctionId, - 'ext': {'wrapper': 'Prebid_js', 'wrapper_version': '$prebid.version$'} - }, - 'user': { - 'id': fpdUserIdVal - }, - 'imp': [{ - 'id': bidRequests[0].bidId, - 'tagid': bidRequests[0].params.uid, - 'ext': {'divid': bidRequests[0].adUnitCode}, - 'bidfloor': bidRequests[0].params.bidFloor, - 'banner': { - 'w': 300, - 'h': 250, - 'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}] - } - }, { - 'id': bidRequests[1].bidId, - 'tagid': bidRequests[1].params.uid, - 'ext': {'divid': bidRequests[1].adUnitCode}, - 'banner': { - 'w': 300, - 'h': 250, - 'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}] - } - }, { - 'id': bidRequests[2].bidId, - 'tagid': bidRequests[2].params.uid, - 'ext': {'divid': bidRequests[2].adUnitCode}, - 'video': { - 'w': 400, - 'h': 600, - 'mimes': ['video/mp4', 'video/webm', 'application/javascript', 'video/ogg'] - } - }] - }); - - getDataFromLocalStorageStub.restore(); - }); - - it('should attach valid params to the tags with multiRequest', function () { - const fpdUserIdVal = '0b0f84a1-1596-4165-9742-2e1a7dfac57f'; - const getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage').callsFake( - arg => arg === 'tmguid' ? fpdUserIdVal : null); - - const bidMultiRequests = bidRequests.slice(0, 3).map((bidReq) => ({ - ...bidReq, - params: { ...bidReq.params, multiRequest: true } - })); - bidMultiRequests[1].params.pubid = 'some_pub_id'; - bidMultiRequests[2].params.source = 'jwp'; - const requests = spec.buildRequests(bidMultiRequests, bidderRequest); - requests.forEach((request, i) => { - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - const banner = bidMultiRequests[i].mediaTypes ? bidRequests[i].mediaTypes.banner : { sizes: bidMultiRequests[i].sizes }; - const video = bidMultiRequests[i].mediaTypes && bidMultiRequests[i].mediaTypes.video; - const source = bidMultiRequests[i].params.source; - const url = `https://grid.bidswitch.net/hbjson?no_mapping=1${source ? `&sp=${source}` : ''}`; - expect(request.url).to.equal(url); - expect(payload).to.deep.equal({ - 'id': bidderRequest.bidderRequestId, - 'site': { - 'page': referrer, - ...(bidMultiRequests[i].params.pubid && { 'publisher': { 'id': bidMultiRequests[i].params.pubid } }) - }, - 'tmax': bidderRequest.timeout, - 'source': { - 'tid': bidderRequest.auctionId, - 'ext': {'wrapper': 'Prebid_js', 'wrapper_version': '$prebid.version$'} - }, - 'user': { - 'id': fpdUserIdVal - }, - 'imp': [{ - 'id': bidMultiRequests[i].bidId, - 'tagid': bidMultiRequests[i].params.uid, - 'ext': {'divid': bidMultiRequests[i].adUnitCode}, - ...(bidMultiRequests[i].params.bidFloor && { 'bidfloor': bidMultiRequests[i].params.bidFloor }), - ...(banner && { banner: { - 'w': banner.sizes[0][0], - 'h': banner.sizes[0][1], - 'format': banner.sizes.map(([w, h]) => ({ w, h })) - }}), - ...(video && { video: { - 'w': video.playerSize[0][0], - 'h': video.playerSize[0][1], - 'mimes': video.mimes - }}) - }] - }); - }); - - getDataFromLocalStorageStub.restore(); - }); - - it('should support mixed mediaTypes', function () { - const fpdUserIdVal = '0b0f84a1-1596-4165-9742-2e1a7dfac57f'; - const getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage').callsFake( - arg => arg === 'tmguid' ? fpdUserIdVal : null); - - const [request] = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload).to.deep.equal({ - 'id': bidderRequest.bidderRequestId, - 'site': { - 'page': referrer - }, - 'tmax': bidderRequest.timeout, - 'source': { - 'tid': bidderRequest.auctionId, - 'ext': {'wrapper': 'Prebid_js', 'wrapper_version': '$prebid.version$'} - }, - 'user': { - 'id': fpdUserIdVal - }, - 'imp': [{ - 'id': bidRequests[0].bidId, - 'tagid': bidRequests[0].params.uid, - 'ext': {'divid': bidRequests[0].adUnitCode}, - 'bidfloor': bidRequests[0].params.bidFloor, - 'banner': { - 'w': 300, - 'h': 250, - 'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}] - } - }, { - 'id': bidRequests[1].bidId, - 'tagid': bidRequests[1].params.uid, - 'ext': {'divid': bidRequests[1].adUnitCode}, - 'banner': { - 'w': 300, - 'h': 250, - 'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}] - } - }, { - 'id': bidRequests[2].bidId, - 'tagid': bidRequests[2].params.uid, - 'ext': {'divid': bidRequests[2].adUnitCode}, - 'video': { - 'w': 400, - 'h': 600, - 'mimes': ['video/mp4', 'video/webm', 'application/javascript', 'video/ogg'], - } - }, { - 'id': bidRequests[3].bidId, - 'tagid': bidRequests[3].params.uid, - 'ext': {'divid': bidRequests[3].adUnitCode}, - 'banner': { - 'w': 728, - 'h': 90, - 'format': [{'w': 728, 'h': 90}] - }, - 'video': { - 'w': 400, - 'h': 600, - 'protocols': [1, 2, 3] - } - }] - }); - - getDataFromLocalStorageStub.restore(); - }); - - it('if gdprConsent is present payload must have gdpr params', function () { - const gdprBidderRequest = Object.assign({gdprConsent: {consentString: 'AAA', gdprApplies: true}}, bidderRequest); - const [request] = spec.buildRequests(bidRequests, gdprBidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload).to.have.property('user'); - expect(payload.user).to.have.property('ext'); - expect(payload.user.ext).to.have.property('consent', 'AAA'); - expect(payload).to.have.property('regs'); - expect(payload.regs).to.have.property('ext'); - expect(payload.regs.ext).to.have.property('gdpr', 1); - }); - - it('if usPrivacy is present payload must have us_privacy param', function () { - const bidderRequestWithUSP = Object.assign({uspConsent: '1YNN'}, bidderRequest); - const [request] = spec.buildRequests(bidRequests, bidderRequestWithUSP); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload).to.have.property('regs'); - expect(payload.regs).to.have.property('ext'); - expect(payload.regs.ext).to.have.property('us_privacy', '1YNN'); - }); - - it('should add gpp information to the request via bidderRequest.gppConsent', function () { - const consentString = 'abc1234'; - const gppBidderRequest = Object.assign({gppConsent: {gppString: consentString, applicableSections: [8]}}, bidderRequest); - - const [request] = spec.buildRequests(bidRequests, gppBidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.regs).to.exist; - expect(payload.regs.gpp).to.equal(consentString); - expect(payload.regs.gpp_sid).to.deep.equal([8]); - }); - - it('should add gpp information to the request via bidderRequest.ortb2.regs.gpp', function () { - const consentString = 'abc1234'; - const gppBidderRequest = { - ...bidderRequest, - ortb2: { - regs: {gpp: consentString, gpp_sid: [8]}, - ...bidderRequest.ortb2 - } - }; - - const [request] = spec.buildRequests(bidRequests, gppBidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.regs).to.exist; - expect(payload.regs.gpp).to.equal(consentString); - expect(payload.regs.gpp_sid).to.deep.equal([8]); - }); - - it('if userId is present payload must have user.ext param with right keys', function () { - const eids = [ - { - source: 'pubcid.org', - uids: [{ - id: 'some-random-id-value', - atype: 1 - }] - }, - { - source: 'adserver.org', - uids: [{ - id: 'some-random-id-value', - atype: 1, - ext: { - rtiPartner: 'TDID' - } - }] - } - ]; - const bidRequestsWithUserIds = bidRequests.map((bid) => { - return Object.assign({ - userIdAsEids: eids - }, bid); - }); - const [request] = spec.buildRequests(bidRequestsWithUserIds, bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload).to.have.property('user'); - expect(payload.user).to.have.property('ext'); - expect(payload.user.ext.eids).to.deep.equal(eids); - }); - - it('if userId is present payload must have user.ext param with right keys', function () { - const ortb2UserExtDevice = { - screenWidth: 1200, - screenHeight: 800, - language: 'ru' - }; - const ortb2 = {user: {ext: {device: ortb2UserExtDevice}}}; - - const [request] = spec.buildRequests(bidRequests, {...bidderRequest, ortb2}); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload).to.have.property('user'); - expect(payload.user).to.have.property('ext'); - expect(payload.user.ext.device).to.deep.equal(ortb2UserExtDevice); - }); - - it('if schain is present payload must have source.ext.schain param', function () { - const schain = { - complete: 1, - nodes: [ - { - asi: 'indirectseller.com', - sid: '00001', - hp: 1 - } - ] - }; - const bidRequestsWithSChain = bidRequests.map((bid) => { - return Object.assign({ - ortb2: { - source: { - ext: { - schain: schain - } - } - } - }, bid); - }); - const [request] = spec.buildRequests(bidRequestsWithSChain, bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload).to.have.property('source'); - expect(payload.source).to.have.property('ext'); - expect(payload.source.ext).to.have.property('schain'); - expect(payload.source.ext.schain).to.deep.equal(schain); - }); - - it('if content and segment is present in jwTargeting, payload must have right params', function () { - const jsContent = {id: 'test_jw_content_id'}; - const jsSegments = ['test_seg_1', 'test_seg_2']; - const bidRequestsWithJwTargeting = bidRequests.map((bid) => { - return Object.assign({ - rtd: { - jwplayer: { - targeting: { - segments: jsSegments, - content: jsContent - } - } - } - }, bid); - }); - const [request] = spec.buildRequests(bidRequestsWithJwTargeting, bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload).to.have.property('site'); - expect(payload.site.content).to.deep.equal(jsContent); - }); - - it('should contain the keyword values if it present in ortb2.(site/user)', function () { - const ortb2 = { - user: {'keywords': 'foo,any'}, - site: {'keywords': 'bar'} - }; - const keywords = { - 'site': { - 'somePublisher': [ - { - 'name': 'someName', - 'brandsafety': ['disaster'], - 'topic': ['stress', 'fear'] - } - ] - }, - 'user': { - 'formatedPublisher': [ - { - 'name': 'fomatedName', - 'segments': [ - { 'name': 'segName1', 'value': 'segVal1' }, - { 'name': 'segName2', 'value': 'segVal2' } - ] - } - ] - } - }; - const bidRequestWithKW = { ...bidRequests[0], params: { ...bidRequests[0].params, keywords } } - const [request] = spec.buildRequests([bidRequestWithKW], {...bidderRequest, ortb2}); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload.ext.keywords).to.deep.equal({ - 'site': { - 'somePublisher': [ - { - 'name': 'someName', - 'segments': [ - { 'name': 'brandsafety', 'value': 'disaster' }, - { 'name': 'topic', 'value': 'stress' }, - { 'name': 'topic', 'value': 'fear' } - ] - } - ], - 'ortb2': [ - { - 'name': 'keywords', - 'segments': [ - { 'name': 'keywords', 'value': 'bar' } - ] - } - ] - }, - 'user': { - 'formatedPublisher': [ - { - 'name': 'fomatedName', - 'segments': [ - { 'name': 'segName1', 'value': 'segVal1' }, - { 'name': 'segName2', 'value': 'segVal2' } - ] - } - ], - 'ortb2': [ - { - 'name': 'keywords', - 'segments': [ - { 'name': 'keywords', 'value': 'foo' }, - { 'name': 'keywords', 'value': 'any' } - ] - } - ] - } - }); - }); - - it('should have user.data filled from config ortb2.user.data', function () { - const userData = [ - { - name: 'someName', - segment: [1, 2, { anyKey: 'anyVal' }, 'segVal', { id: 'segId' }, { value: 'segValue' }, { id: 'segId2', name: 'segName' }] - }, - { - name: 'permutive.com', - segment: [1, 2, 'segVal', { id: 'segId' }, { anyKey: 'anyVal' }, { value: 'segValue' }, { id: 'segId2', name: 'segName' }] - }, - { - someKey: 'another data' - } - ]; - const ortb2 = {user: {data: userData}}; - const [request] = spec.buildRequests([bidRequests[0]], {...bidderRequest, ortb2}); - const payload = parseRequest(request.data); - expect(payload.user.data).to.deep.equal(userData); - }); - - it('should have site.content.data filled from config ortb2.site.content.data', function () { - const contentData = [ - { - 'name': 'someName', - 'ext': { - 'segtax': 7 - }, - 'segments': [ - { 'id': 'segId1' }, - { 'id': 'segId2' } - ] - } - ]; - const ortb2 = {site: { content: { data: contentData } }}; - const [request] = spec.buildRequests([bidRequests[0]], {...bidderRequest, ortb2}); - const payload = parseRequest(request.data); - expect(payload.site.content.data).to.deep.equal(contentData); - }); - - it('should have right value in user.data', function () { - const userData = [ - { - name: 'someName', - segment: [1, 2, { anyKey: 'anyVal' }, 'segVal', { id: 'segId' }, { value: 'segValue' }, { id: 'segId2', name: 'segName' }] - }, - { - name: 'permutive.com', - segment: [1, 2, 'segVal', { id: 'segId' }, { anyKey: 'anyVal' }, { value: 'segValue' }, { id: 'segId2', name: 'segName' }] - }, - { - someKey: 'another data' - } - ]; - const ortb2 = {user: {data: userData}}; - - const jsContent = {id: 'test_jw_content_id'}; - const jsSegments = ['test_seg_1', 'test_seg_2']; - const bidRequestsWithJwTargeting = Object.assign({}, bidRequests[0], { - rtd: { - jwplayer: { - targeting: { - segments: jsSegments, - content: jsContent - } - } - } - }); - const [request] = spec.buildRequests([bidRequestsWithJwTargeting], {...bidderRequest, ortb2}); - const payload = parseRequest(request.data); - expect(payload.user.data).to.deep.equal(userData); - }); - - it('should have site.content.id filled from config ortb2.site.content.id', function () { - const contentId = 'jw_abc'; - const ortb2 = {site: {content: {id: contentId}}}; - const [request] = spec.buildRequests([bidRequests[0]], {...bidderRequest, ortb2}); - const payload = parseRequest(request.data); - expect(payload.site.content.id).to.equal(contentId); - }); - - it('should contain regs.coppa if coppa is true in config', function () { - const getConfigStub = sinon.stub(config, 'getConfig').callsFake( - arg => arg === 'coppa' ? true : null); - const [request] = spec.buildRequests([bidRequests[0]], bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload).to.have.property('regs'); - expect(payload.regs).to.have.property('coppa', 1); - getConfigStub.restore(); - }); - it('should contain imp[].ext.data.adserver if available', function() { - const ortb2Imp = [{ - ext: { - data: { - adserver: { - name: 'ad_server_name', - adslot: '/111111/slot' - }, - pbadslot: '/111111/slot' - } - } - }, { - ext: { - gpid: '/222222/slot', - data: { - adserver: { - name: 'ad_server_name', - } - } - } - }, { - ext: { - gpid: '/333333/slot' - } - }]; - const bidRequestsWithOrtb2Imp = bidRequests.slice(0, 3).map((bid, ind) => { - return Object.assign({}, bid, ortb2Imp[ind] ? { ortb2Imp: {...bid.ortb2Imp, ...ortb2Imp[ind]} } : {}); - }); - const [request] = spec.buildRequests(bidRequestsWithOrtb2Imp, bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload.imp[0].ext).to.deep.equal({ - divid: bidRequests[0].adUnitCode, - data: ortb2Imp[0].ext.data, - gpid: ortb2Imp[0].ext.data.adserver.adslot - }); - expect(payload.imp[1].ext).to.deep.equal({ - divid: bidRequests[1].adUnitCode, - data: ortb2Imp[1].ext.data, - gpid: ortb2Imp[1].ext.gpid - }); - expect(payload.imp[2].ext).to.deep.equal({ - divid: bidRequests[2].adUnitCode, - gpid: ortb2Imp[2].ext.gpid - }); - }); - - it('should prioritize gpid over adslot', function() { - const ortb2Imp = [{ - ext: { - data: { - adserver: { - adslot: 'adslot' - } - } - } - }, { - ext: { - data: { - adserver: { - adslot: 'adslot' - }, - }, - gpid: 'pbadslot' - } - }]; - const bidRequestsWithOrtb2Imp = bidRequests.slice(0, 2).map((bid, ind) => { - return Object.assign({}, bid, ortb2Imp[ind] ? { ortb2Imp: {...bid.ortb2Imp, ...ortb2Imp[ind]} } : {}); - }); - const [request] = spec.buildRequests(bidRequestsWithOrtb2Imp, bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload.imp[0].ext.gpid).to.equal(ortb2Imp[0].ext.data.adserver.adslot); - expect(payload.imp[1].ext.gpid).to.equal(ortb2Imp[1].ext.gpid); - }); - - it('should prioritize gpid over pbadslot and adslot', function() { - const ortb2Imp = [{ - ext: { - gpid: 'gpid', - data: { - adserver: { - adslot: 'adslot' - }, - pbadslot: 'pbadslot' - } - } - }, { - ext: { - gpid: 'gpid', - data: { - adserver: { - adslot: 'adslot' - } - } - } - }, { - ext: { - gpid: 'gpid', - data: { - pbadslot: 'pbadslot' - } - } - }]; - const bidRequestsWithOrtb2Imp = bidRequests.slice(0, 3).map((bid, ind) => { - return Object.assign({}, bid, ortb2Imp[ind] ? { ortb2Imp: {...bid.ortb2Imp, ...ortb2Imp[ind]} } : {}); - }); - const [request] = spec.buildRequests(bidRequestsWithOrtb2Imp, bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload.imp[0].ext.gpid).to.equal(ortb2Imp[0].ext.gpid); - expect(payload.imp[1].ext.gpid).to.equal(ortb2Imp[1].ext.gpid); - expect(payload.imp[2].ext.gpid).to.equal(ortb2Imp[2].ext.gpid); - }); - - it('should contain imp[].instl if available', function() { - const ortb2Imp = [{ - instl: 1 - }, { - instl: 2, - ext: { - data: { - adserver: { - name: 'ad_server_name', - adslot: '/222222/slot' - }, - pbadslot: '/222222/slot' - } - } - }]; - const bidRequestsWithOrtb2Imp = bidRequests.slice(0, 3).map((bid, ind) => { - return Object.assign({}, bid, ortb2Imp[ind] ? { ortb2Imp: ortb2Imp[ind] } : {}); - }); - const [request] = spec.buildRequests(bidRequestsWithOrtb2Imp, bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload.imp[0].instl).to.equal(1); - expect(payload.imp[1].instl).to.equal(2); - expect(payload.imp[2].instl).to.be.undefined; - }); - - it('all id must be a string', function() { - const fpdUserIdNumVal = 2345543345; - const getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage').callsFake( - arg => arg === 'tmguid' ? fpdUserIdNumVal : null); - const bidRequestWithNumId = { - 'bidder': 'grid', - 'params': { - 'uid': 1, - }, - 'adUnitCode': 1233, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 600]] - } - }, - 'bidId': 123123123, - 'bidderRequestId': 345345345, - 'auctionId': 654645, - }; - const bidderRequestWithNumId = { - refererInfo: {page: 'https://example.com'}, - bidderRequestId: 345345345, - timeout: 3000, - ortb2: { - source: { - tid: 654645 - } - } - }; - const parsedReferrer = encodeURIComponent(bidderRequestWithNumId.refererInfo.page); - const [request] = spec.buildRequests([bidRequestWithNumId], bidderRequestWithNumId); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload).to.deep.equal({ - 'id': '345345345', - 'site': { - 'page': parsedReferrer - }, - 'tmax': bidderRequestWithNumId.timeout, - 'source': { - 'tid': '654645', - 'ext': {'wrapper': 'Prebid_js', 'wrapper_version': '$prebid.version$'} - }, - 'user': { - 'id': '2345543345' - }, - 'imp': [{ - 'id': '123123123', - 'tagid': '1', - 'ext': {'divid': '1233'}, - 'banner': { - 'w': 300, - 'h': 250, - 'format': [{'w': 300, 'h': 250}, {'w': 300, 'h': 600}] - } - }] - }); - - getDataFromLocalStorageStub.restore(); - }) - - it('tmax should be set as integer', function() { - let [request] = spec.buildRequests([bidRequests[0]], {...bidderRequest, timeout: '10'}); - let payload = parseRequest(request.data); - expect(payload.tmax).to.equal(10); - [request] = spec.buildRequests([bidRequests[0]], {...bidderRequest, timeout: 'ddqwdwdq'}); - payload = parseRequest(request.data); - expect(payload.tmax).to.equal(null); - }) - - it('should add ORTB2 device data to the request', function () { - const bidderRequestWithDevice = { - ...bidderRequest, - ...{ - ortb2: { - device: { - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - }, - }, - }, - }; - - const [request] = spec.buildRequests([bidRequests[0]], bidderRequestWithDevice); - const payload = parseRequest(request.data); - - expect(payload.device).to.deep.equal(bidderRequestWithDevice.ortb2.device); - }); - - describe('floorModule', function () { - const floorTestData = { - 'currency': 'USD', - 'floor': 1.50 - }; - const bidRequest = Object.assign({ - getFloor: (_) => { - return floorTestData; - } - }, bidRequests[1]); - it('should return the value from getFloor if present', function () { - const [request] = spec.buildRequests([bidRequest], bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload.imp[0].bidfloor).to.equal(floorTestData.floor); - }); - it('should return the getFloor.floor value if it is greater than bidfloor', function () { - const bidfloor = 0.80; - const bidRequestsWithFloor = { ...bidRequest }; - bidRequestsWithFloor.params = Object.assign({bidFloor: bidfloor}, bidRequestsWithFloor.params); - const [request] = spec.buildRequests([bidRequestsWithFloor], bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload.imp[0].bidfloor).to.equal(floorTestData.floor); - }); - it('should return the bidfloor value if it is greater than getFloor.floor', function () { - const bidfloor = 1.80; - const bidRequestsWithFloor = { ...bidRequest }; - bidRequestsWithFloor.params = Object.assign({bidFloor: bidfloor}, bidRequestsWithFloor.params); - const [request] = spec.buildRequests([bidRequestsWithFloor], bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload.imp[0].bidfloor).to.equal(bidfloor); - }); - it('should return the bidfloor string value if it is greater than getFloor.floor', function () { - const bidfloor = '1.80'; - const bidRequestsWithFloor = { ...bidRequest }; - bidRequestsWithFloor.params = Object.assign({bidFloor: bidfloor}, bidRequestsWithFloor.params); - const [request] = spec.buildRequests([bidRequestsWithFloor], bidderRequest); - expect(request.data).to.be.an('string'); - const payload = parseRequest(request.data); - expect(payload.imp[0].bidfloor).to.equal(1.80); - }); - }); - }); - - describe('interpretResponse', function () { - const responses = [ - {'bid': [{'impid': '659423fff799cb', 'adid': '13_14_4353', 'price': 1.15, 'adm': '
test content 1
', 'auid': 1, 'h': 250, 'w': 300, 'dealid': 11}], 'seat': '1'}, - {'bid': [{'impid': '4dff80cc4ee346', 'adid': '13_15_6454', 'price': 0.5, 'adm': '
test content 2
', 'auid': 2, 'h': 600, 'w': 300}], 'seat': '1'}, - {'bid': [{'impid': '5703af74d0472a', 'adid': '13_16_7654', 'price': 0.15, 'adm': '
test content 3
', 'auid': 1, 'h': 90, 'w': 728}], 'seat': '1'}, - {'bid': [{'impid': '2344da98f78b42', 'adid': '13_17_5433', 'price': 0, 'auid': 3, 'h': 250, 'w': 300}], 'seat': '1'}, - {'bid': [{'price': 0, 'adid': '13_18_34645', 'adm': '
test content 5
', 'h': 250, 'w': 300}], 'seat': '1'}, - undefined, - {'bid': [], 'seat': '1'}, - {'seat': '1'}, - ]; - - it('should get correct bid response', function () { - const bidRequests = [ - { - 'bidder': 'grid', - 'params': { - 'uid': '1' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '659423fff799cb', - 'bidderRequestId': '5f2009617a7c0a', - 'auctionId': '1cbd2feafe5e8b', - } - ]; - const [request] = spec.buildRequests(bidRequests); - const expectedResponse = [ - { - 'requestId': '659423fff799cb', - 'cpm': 1.15, - 'creativeId': '13_14_4353', - 'dealId': 11, - 'width': 300, - 'height': 250, - 'ad': '
test content 1
', - 'currency': 'USD', - 'mediaType': 'banner', - 'netRevenue': true, - 'ttl': 360, - 'meta': { - advertiserDomains: [] - }, - } - ]; - - const result = spec.interpretResponse({'body': {'seatbid': [responses[0]]}}, request); - expect(result).to.deep.equal(expectedResponse); - }); - - it('should get correct multi bid response', function () { - const bidRequests = [ - { - 'bidder': 'grid', - 'params': { - 'uid': '1' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '659423fff799cb', - 'bidderRequestId': '2c2bb1972df9a', - 'auctionId': '1fa09aee5c8c99', - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '2' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '4dff80cc4ee346', - 'bidderRequestId': '2c2bb1972df9a', - 'auctionId': '1fa09aee5c8c99', - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '1' - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[728, 90]], - 'bidId': '5703af74d0472a', - 'bidderRequestId': '2c2bb1972df9a', - 'auctionId': '1fa09aee5c8c99', - } - ]; - const [request] = spec.buildRequests(bidRequests); - const expectedResponse = [ - { - 'requestId': '659423fff799cb', - 'cpm': 1.15, - 'creativeId': '13_14_4353', - 'dealId': 11, - 'width': 300, - 'height': 250, - 'ad': '
test content 1
', - 'currency': 'USD', - 'mediaType': 'banner', - 'netRevenue': true, - 'ttl': 360, - 'meta': { - advertiserDomains: [] - }, - }, - { - 'requestId': '4dff80cc4ee346', - 'cpm': 0.5, - 'creativeId': '13_15_6454', - 'dealId': undefined, - 'width': 300, - 'height': 600, - 'ad': '
test content 2
', - 'currency': 'USD', - 'mediaType': 'banner', - 'netRevenue': true, - 'ttl': 360, - 'meta': { - advertiserDomains: [] - }, - }, - { - 'requestId': '5703af74d0472a', - 'cpm': 0.15, - 'creativeId': '13_16_7654', - 'dealId': undefined, - 'width': 728, - 'height': 90, - 'ad': '
test content 3
', - 'currency': 'USD', - 'mediaType': 'banner', - 'netRevenue': true, - 'ttl': 360, - 'meta': { - advertiserDomains: [] - }, - } - ]; - - const result = spec.interpretResponse({'body': {'seatbid': responses.slice(0, 3)}}, request); - expect(result).to.deep.equal(expectedResponse); - }); - - it('should get correct video bid response', function () { - const bidRequests = [ - { - 'bidder': 'grid', - 'params': { - 'uid': '11' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '659423fff799cb', - 'bidderRequestId': '5f2009617a7c0a', - 'auctionId': '1cbd2feafe5e8b', - 'mediaTypes': { - 'video': { - 'context': 'instream' - } - } - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '12' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '2bc598e42b6a', - 'bidderRequestId': '5f2009617a7c0a', - 'auctionId': '1cbd2feafe5e8b', - 'mediaTypes': { - 'video': { - 'context': 'instream' - } - } - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '13' - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '23312a43bc42', - 'bidderRequestId': '5f2009617a7c0a', - 'auctionId': '1cbd2feafe5e8b', - 'mediaTypes': { - 'video': { - 'context': 'instream' - } - } - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '14' - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '112432ab4f34', - 'bidderRequestId': '5f2009617a7c0a', - 'auctionId': '1cbd2feafe5e8b', - 'mediaTypes': { - 'video': { - 'context': 'instream' - } - } - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '15' - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[300, 250], [300, 600]], - 'bidId': 'a74b342f8cd', - 'bidderRequestId': '5f2009617a7c0a', - 'auctionId': '1cbd2feafe5e8b', - 'mediaTypes': { - 'video': { - 'context': 'instream' - } - } - } - ]; - const response = [ - {'bid': [{'impid': '659423fff799cb', 'adid': '35_56_6454', 'price': 1.15, 'adm': '\n<\/Ad>\n<\/VAST>', 'auid': 11, content_type: 'video', w: 300, h: 600}], 'seat': '2'}, - {'bid': [{'impid': '2bc598e42b6a', 'adid': '35_57_2344', 'price': 1.00, 'adm': '\n<\/Ad>\n<\/VAST>', content_type: 'video'}], 'seat': '2'}, - {'bid': [{'impid': '23312a43bc42', 'adid': '35_58_5345', 'price': 2.00, 'nurl': 'https://some_test_vast_url.com', 'auid': 13, content_type: 'video', 'adomain': ['example.com'], w: 300, h: 600}], 'seat': '2'}, - {'bid': [{'impid': '112432ab4f34', 'adid': '35_59_56756', 'price': 1.80, 'adm': '\n<\/Ad>\n<\/VAST>', 'nurl': 'https://wrong_url.com', 'auid': 14, content_type: 'video', 'adomain': ['example.com'], w: 300, h: 600}], 'seat': '2'}, - {'bid': [{'impid': 'a74b342f8cd', 'adid': '35_60_523452', 'price': 1.50, 'nurl': '', 'auid': 15, content_type: 'video'}], 'seat': '2'} - ]; - const [request] = spec.buildRequests(bidRequests); - const expectedResponse = [ - { - 'requestId': '659423fff799cb', - 'cpm': 1.15, - 'creativeId': '35_56_6454', - 'dealId': undefined, - 'width': 300, - 'height': 600, - 'currency': 'USD', - 'mediaType': 'video', - 'netRevenue': true, - 'ttl': 360, - 'meta': { - advertiserDomains: [] - }, - 'vastXml': '\n<\/Ad>\n<\/VAST>', - 'adResponse': { - 'content': '\n<\/Ad>\n<\/VAST>' - } - }, - { - 'requestId': '2bc598e42b6a', - 'cpm': 1.00, - 'creativeId': '35_57_2344', - 'dealId': undefined, - 'width': undefined, - 'height': undefined, - 'currency': 'USD', - 'mediaType': 'video', - 'netRevenue': true, - 'ttl': 360, - 'meta': { - advertiserDomains: [] - }, - 'vastXml': '\n<\/Ad>\n<\/VAST>', - 'adResponse': { - 'content': '\n<\/Ad>\n<\/VAST>' - } - }, - { - 'requestId': '23312a43bc42', - 'cpm': 2.00, - 'creativeId': '35_58_5345', - 'dealId': undefined, - 'width': 300, - 'height': 600, - 'currency': 'USD', - 'mediaType': 'video', - 'netRevenue': true, - 'ttl': 360, - 'meta': { - advertiserDomains: ['example.com'] - }, - 'vastUrl': 'https://some_test_vast_url.com', - }, - { - 'requestId': '112432ab4f34', - 'cpm': 1.80, - 'creativeId': '35_59_56756', - 'dealId': undefined, - 'width': 300, - 'height': 600, - 'currency': 'USD', - 'mediaType': 'video', - 'netRevenue': true, - 'ttl': 360, - 'meta': { - advertiserDomains: ['example.com'] - }, - 'vastXml': '\n<\/Ad>\n<\/VAST>', - 'adResponse': { - 'content': '\n<\/Ad>\n<\/VAST>' - } - }, - ]; - - const result = spec.interpretResponse({'body': {'seatbid': response}}, request); - expect(result).to.deep.equal(expectedResponse); - }); - - it('handles wrong and nobid responses', function () { - const bidRequests = [ - { - 'bidder': 'grid', - 'params': { - 'uid': '3' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '300bfeb0d7190gf', - 'bidderRequestId': '2c2bb1972d23af', - 'auctionId': '1fa09aee5c84d34', - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '4' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '300bfeb0d71321', - 'bidderRequestId': '2c2bb1972d23af', - 'auctionId': '1fa09aee5c84d34', - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '5' - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[728, 90]], - 'bidId': '300bfeb0d7183bb', - 'bidderRequestId': '2c2bb1972d23af', - 'auctionId': '1fa09aee5c84d34', - } - ]; - const [request] = spec.buildRequests(bidRequests); - const result = spec.interpretResponse({'body': {'seatbid': responses.slice(2)}}, request); - expect(result.length).to.equal(0); - }); - - it('complicated case', function () { - const fullResponse = [ - {'bid': [{'impid': '2164be6358b9', 'adid': '32_52_7543', 'price': 1.15, 'adm': '
test content 1
', 'auid': 1, 'h': 250, 'w': 300, dealid: 11, 'ext': {'dsa': {'adrender': 1}}}], 'seat': '1'}, - {'bid': [{'impid': '4e111f1b66e4', 'adid': '32_54_4535', 'price': 0.5, 'adm': '
test content 2
', 'auid': 2, 'h': 600, 'w': 300, dealid: 12}], 'seat': '1'}, - {'bid': [{'impid': '26d6f897b516', 'adid': '32_53_75467', 'price': 0.15, 'adm': '
test content 3
', 'auid': 1, 'h': 90, 'w': 728}], 'seat': '1'}, - {'bid': [{'impid': '326bde7fbf69', 'adid': '32_54_12342', 'price': 0.15, 'adm': '
test content 4
', 'auid': 1, 'h': 600, 'w': 300}], 'seat': '1'}, - {'bid': [{'impid': '2234f233b22a', 'adid': '32_55_987686', 'price': 0.5, 'adm': '
test content 5
', 'auid': 2, 'h': 600, 'w': 350}], 'seat': '1'}, - ]; - const bidRequests = [ - { - 'bidder': 'grid', - 'params': { - 'uid': '1' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '2164be6358b9', - 'bidderRequestId': '106efe3247', - 'auctionId': '32a1f276cb87cb8', - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '1' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '326bde7fbf69', - 'bidderRequestId': '106efe3247', - 'auctionId': '32a1f276cb87cb8', - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '2' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '4e111f1b66e4', - 'bidderRequestId': '106efe3247', - 'auctionId': '32a1f276cb87cb8', - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '1' - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[728, 90]], - 'bidId': '26d6f897b516', - 'bidderRequestId': '106efe3247', - 'auctionId': '32a1f276cb87cb8', - }, - { - 'bidder': 'grid', - 'params': { - 'uid': '2' - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[728, 90]], - 'bidId': '1751cd90161', - 'bidderRequestId': '106efe3247', - 'auctionId': '32a1f276cb87cb8', - } - ]; - const [request] = spec.buildRequests(bidRequests); - const expectedResponse = [ - { - 'requestId': '2164be6358b9', - 'cpm': 1.15, - 'creativeId': '32_52_7543', - 'dealId': 11, - 'width': 300, - 'height': 250, - 'ad': '
test content 1
', - 'currency': 'USD', - 'mediaType': 'banner', - 'netRevenue': true, - 'ttl': 360, - 'meta': { - dsa: { - adrender: 1 - }, - advertiserDomains: [] - }, - }, - { - 'requestId': '4e111f1b66e4', - 'cpm': 0.5, - 'creativeId': '32_54_4535', - 'dealId': 12, - 'width': 300, - 'height': 600, - 'ad': '
test content 2
', - 'currency': 'USD', - 'mediaType': 'banner', - 'netRevenue': true, - 'ttl': 360, - 'meta': { - advertiserDomains: [] - }, - }, - { - 'requestId': '26d6f897b516', - 'cpm': 0.15, - 'creativeId': '32_53_75467', - 'dealId': undefined, - 'width': 728, - 'height': 90, - 'ad': '
test content 3
', - 'currency': 'USD', - 'mediaType': 'banner', - 'netRevenue': true, - 'ttl': 360, - 'meta': { - advertiserDomains: [] - }, - }, - { - 'requestId': '326bde7fbf69', - 'cpm': 0.15, - 'creativeId': '32_54_12342', - 'dealId': undefined, - 'width': 300, - 'height': 600, - 'ad': '
test content 4
', - 'currency': 'USD', - 'mediaType': 'banner', - 'netRevenue': true, - 'ttl': 360, - 'meta': { - advertiserDomains: [] - }, - } - ]; - - const result = spec.interpretResponse({'body': {'seatbid': fullResponse}}, request); - expect(result).to.deep.equal(expectedResponse); - }); - - it('response with ext.bidder.grid.demandSource', function () { - const bidRequests = [ - { - 'bidder': 'grid', - 'params': { - 'uid': '1' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '26d6f897b516', - 'bidderRequestId': '5f2009617a7c0a', - 'auctionId': '1cbd2feafe5e8b', - } - ]; - const serverResponse = { - 'bid': [ - { - 'impid': '26d6f897b516', - 'price': 1.15, - 'adm': '
test content 1
', - 'auid': 1, - 'adid': '234_6454_3453', - 'h': 250, - 'w': 300, - 'dealid': 11, - 'ext': { - 'bidder': { - 'grid': { - 'demandSource': 'someValue' - } - } - } - } - ], - 'seat': '1' - }; - const [request] = spec.buildRequests(bidRequests); - const expectedResponse = [ - { - 'requestId': '26d6f897b516', - 'cpm': 1.15, - 'creativeId': '234_6454_3453', - 'dealId': 11, - 'width': 300, - 'height': 250, - 'ad': '
test content 1
', - 'currency': 'USD', - 'mediaType': 'banner', - 'netRevenue': true, - 'ttl': 360, - 'meta': { - advertiserDomains: [], - demandSource: 'someValue' - }, - 'adserverTargeting': { - 'hb_ds': 'someValue' - } - } - ]; - - const result = spec.interpretResponse({'body': {'seatbid': [serverResponse]}}, request); - expect(result).to.deep.equal(expectedResponse); - }); - }); - - describe('onDataDeletionRequest', function() { - let ajaxStub; - beforeEach(function() { - ajaxStub = sinon.stub(spec, 'ajaxCall'); - }); - - it('should send right request on onDataDeletionRequest call', function() { - spec.onDataDeletionRequest([{}]); - expect(ajaxStub.calledOnce).to.equal(true); - expect(ajaxStub.firstCall.args[0]).to.equal('https://media.grid.bidswitch.net/uspapi_delete_c2s'); - }); - }); - - describe('user sync', function () { - const syncUrl = getSyncUrl(); - - beforeEach(function () { - resetUserSync(); - }); - - it('should register the Emily iframe', function () { - const syncs = spec.getUserSyncs({ - pixelEnabled: true - }); - - expect(syncs).to.deep.equal({type: 'image', url: syncUrl}); - }); - - it('should not register the Emily iframe more than once', function () { - let syncs = spec.getUserSyncs({ - pixelEnabled: true - }); - expect(syncs).to.deep.equal({type: 'image', url: syncUrl}); - - // when called again, should still have only been called once - syncs = spec.getUserSyncs(); - expect(syncs).to.equal(undefined); - }); - - it('should pass gdpr params if consent is true', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, { - gdprApplies: true, consentString: 'foo' - })).to.deep.equal({ - type: 'image', url: `${syncUrl}&gdpr=1&gdpr_consent=foo` - }); - }); - - it('should pass gdpr params if consent is false', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, { - gdprApplies: false, consentString: 'foo' - })).to.deep.equal({ - type: 'image', url: `${syncUrl}&gdpr=0&gdpr_consent=foo` - }); - }); - - it('should pass gdpr param gdpr_consent only when gdprApplies is undefined', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, { - consentString: 'foo' - })).to.deep.equal({ - type: 'image', url: `${syncUrl}&gdpr_consent=foo` - }); - }); - - it('should pass no params if gdpr consentString is not defined', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {})).to.deep.equal({ - type: 'image', url: syncUrl - }); - }); - - it('should pass no params if gdpr consentString is a number', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, { - consentString: 0 - })).to.deep.equal({ - type: 'image', url: syncUrl - }); - }); - - it('should pass no params if gdpr consentString is null', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, { - consentString: null - })).to.deep.equal({ - type: 'image', url: syncUrl - }); - }); - - it('should pass no params if gdpr consentString is a object', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, { - consentString: {} - })).to.deep.equal({ - type: 'image', url: syncUrl - }); - }); - - it('should pass no params if gdpr is not defined', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, undefined)).to.deep.equal({ - type: 'image', url: syncUrl - }); - }); - - it('should pass usPrivacy param if it is available', function() { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, {}, '1YNN')).to.deep.equal({ - type: 'image', url: `${syncUrl}&us_privacy=1YNN` - }); - }); - }); -}); diff --git a/test/spec/modules/growadsBidAdapter_spec.js b/test/spec/modules/growadsBidAdapter_spec.js deleted file mode 100644 index 75c5d241a..000000000 --- a/test/spec/modules/growadsBidAdapter_spec.js +++ /dev/null @@ -1,228 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/growadsBidAdapter.js'; -import * as utils from '../../../src/utils.js'; -import {BANNER, NATIVE} from '../../../src/mediaTypes.js'; - -describe('GrowAdvertising Adapter', function() { - const ZONE_ID = 'unique-zone-id'; - const serverResponseBanner = { - body: { - status: 'success', - width: 300, - height: 250, - creativeId: 'ULqaukILu0RnMa0FyidOtkji4Po3qbgQ9ceRVGlhjLLKnrrLAATmGNCwtE99Ems8', - ad: '', - cpm: 1, - ttl: 180, - currency: 'USD', - type: BANNER, - } - }; - const serverResponseNative = { - body: { - status: 'success', - width: 400, - height: 300, - creativeId: 'ULqaukILu0RnMa0FyidOtkji4Po3qbgQ9ceRVGlhjLLKnrrLAATmGNCwtE99Ems9', - cpm: 2, - ttl: 180, - currency: 'USD', - native: { - title: 'Test title', - body: 'Test body', - body2: null, - sponsoredBy: 'Sponsored by', - cta: null, - clickUrl: 'https://example.org', - image: { - width: 400, - height: 300, - url: 'https://image.source.com/img', - } - }, - type: NATIVE - } - }; - let bidRequests = []; - - beforeEach(function () { - bidRequests = [ - { - bidder: 'growads', - params: { - zoneId: ZONE_ID, - maxCPM: 5, - minCPM: 1 - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - }, - { - bidder: 'growads', - params: { - zoneId: ZONE_ID, - }, - mediaTypes: { - native: { - title: { - required: true - }, - image: { - required: true - }, - sponsoredBy: { - required: true - } - }, - }, - } - ]; - }); - - describe('implementation', function () { - describe('for requests', function () { - it('should accept valid bid', function () { - const validBid = { - bidder: 'growads', - params: { - zoneId: ZONE_ID - } - }; - - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(true); - }); - - it('should reject null zoneId bid', function () { - const zoneNullBid = { - bidder: 'growads', - params: { - zoneId: null - } - }; - - const isValid = spec.isBidRequestValid(zoneNullBid); - expect(isValid).to.equal(false); - }); - - it('should reject absent zoneId bid', function () { - const absentZoneBid = { - bidder: 'growads', - params: { - param: ZONE_ID - } - }; - - const isValid = spec.isBidRequestValid(absentZoneBid); - expect(isValid).to.equal(false); - }); - - it('should use custom domain', function () { - const validBid = { - bidder: 'growads', - params: { - zoneId: ZONE_ID, - domain: 'test.subdomain.growadvertising.com', - }, - }; - - const requests = spec.buildRequests([validBid]); - expect(requests[0].url).to.have.string('test.subdomain.'); - }); - - it('should use default domain', function () { - const validBid = { - bidder: 'growads', - params: { - zoneId: ZONE_ID, - }, - }; - - const requests = spec.buildRequests([validBid]); - expect(requests[0].url).to.have.string('portal.growadvertising.com'); - }); - - it('should increment zone index', function () { - const validBids = [ - { - bidder: 'growads', - params: { - zoneId: ZONE_ID, - }, - }, - { - bidder: 'growads', - params: { - zoneId: ZONE_ID, - }, - } - ]; - - const requests = spec.buildRequests(validBids); - expect(requests[0].data).to.include({i: 0}); - expect(requests[1].data).to.include({i: 1}); - }); - }); - - describe('bid responses', function () { - describe(BANNER, function () { - it('should return complete bid response banner', function () { - const bids = spec.interpretResponse(serverResponseBanner, {bidRequest: bidRequests[0]}); - - expect(bids).to.be.lengthOf(1); - expect(bids[0].bidderCode).to.equal('growads'); - expect(bids[0].cpm).to.equal(1); - expect(bids[0].width).to.equal(300); - expect(bids[0].height).to.equal(250); - expect(bids[0].creativeId).to.have.length.above(1); - expect(bids[0].ad).to.have.length.above(1); - expect(bids[0].mediaType).to.equal(BANNER); - }); - - it('should return empty bid on incorrect size', function () { - const response = utils.mergeDeep(serverResponseBanner, { - body: { - width: 150, - height: 150 - } - }); - - const bids = spec.interpretResponse(response, {bidRequest: bidRequests[0]}); - expect([]).to.be.lengthOf(0); - }); - - it('should return empty bid on incorrect CPM', function () { - const response = utils.mergeDeep(serverResponseBanner, { - body: { - cpm: 10 - } - }); - - const bids = spec.interpretResponse(response, {bidRequest: bidRequests[0]}); - expect([]).to.be.lengthOf(0); - }); - }); - - describe(NATIVE, function () { - it('should return complete bid response banner', function () { - const bids = spec.interpretResponse(serverResponseNative, {bidRequest: bidRequests[1]}); - - expect(bids).to.be.lengthOf(1); - expect(bids[0].bidderCode).to.equal('growads'); - expect(bids[0].cpm).to.equal(2); - expect(bids[0].width).to.equal(400); - expect(bids[0].height).to.equal(300); - expect(bids[0].creativeId).to.have.length.above(1); - expect(bids[0]).property('native'); - expect(bids[0].native.title).to.have.length.above(1); - expect(bids[0].native.body).to.have.length.above(1); - expect(bids[0].native).property('image'); - expect(bids[0].mediaType).to.equal(NATIVE); - }); - }); - }); - }); -}); diff --git a/test/spec/modules/growthCodeAnalyticsAdapter_spec.js b/test/spec/modules/growthCodeAnalyticsAdapter_spec.js deleted file mode 100644 index 266bc104f..000000000 --- a/test/spec/modules/growthCodeAnalyticsAdapter_spec.js +++ /dev/null @@ -1,69 +0,0 @@ -import adapterManager from '../../../src/adapterManager.js'; -import growthCodeAnalyticsAdapter from '../../../modules/growthCodeAnalyticsAdapter.js'; -import { expect } from 'chai'; -import * as events from '../../../src/events.js'; -import { EVENTS } from '../../../src/constants.js'; -import { generateUUID } from '../../../src/utils.js'; -import { server } from 'test/mocks/xhr.js'; - -describe('growthCode analytics adapter', () => { - beforeEach(() => { - growthCodeAnalyticsAdapter.enableAnalytics({ - provider: 'growthCodeAnalytics', - options: { - pid: 'TEST01', - trackEvents: [ - 'auctionInit', - 'auctionEnd', - 'bidAdjustment', - 'bidTimeout', - 'bidTimeout', - 'bidRequested', - 'bidResponse', - 'setTargeting', - 'requestBids', - 'addAdUnits', - 'noBid', - 'bidWon', - 'bidderDone'] - } - }); - }); - - afterEach(() => { - growthCodeAnalyticsAdapter.disableAnalytics(); - }); - - it('registers itself with the adapter manager', () => { - const adapter = adapterManager.getAnalyticsAdapter('growthCodeAnalytics'); - expect(adapter).to.exist; - expect(adapter.adapter).to.equal(growthCodeAnalyticsAdapter); - }); - - it('tolerates undefined or empty config', () => { - growthCodeAnalyticsAdapter.enableAnalytics(undefined); - growthCodeAnalyticsAdapter.enableAnalytics({}); - }); - - it('sends auction end events to the backend', () => { - const auction = { - auctionId: generateUUID(), - adUnits: [{ - code: 'usr1234', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600], [728, 90]] - } - }, - adUnitCodes: ['usr1234'] - }], - }; - events.emit(EVENTS.AUCTION_END, auction); - assert(server.requests.length > 0) - const body = JSON.parse(server.requests[0].requestBody); - var eventTypes = []; - body.events.forEach(e => eventTypes.push(e.eventType)); - assert(eventTypes.length > 0) - growthCodeAnalyticsAdapter.disableAnalytics(); - }); -}); diff --git a/test/spec/modules/growthCodeRtdProvider_spec.js b/test/spec/modules/growthCodeRtdProvider_spec.js deleted file mode 100644 index 47213a3dd..000000000 --- a/test/spec/modules/growthCodeRtdProvider_spec.js +++ /dev/null @@ -1,127 +0,0 @@ -import {config} from 'src/config.js'; -import {growthCodeRtdProvider} from '../../../modules/growthCodeRtdProvider.js'; -import sinon from 'sinon'; -import * as ajaxLib from 'src/ajax.js'; - -const sampleConfig = { - name: 'growthCodeRtd', - waitForIt: true, - params: { - pid: 'TEST01', - } -} - -describe('growthCodeRtdProvider', function() { - beforeEach(function() { - config.resetConfig(); - }); - - afterEach(function () { - }); - - describe('growthCodeRtdSubmodule', function() { - it('test bad config instantiates', function () { - const ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(() => { - return (url, cbObj) => { - cbObj.success('{"status":"ok","version":"1.0.0","results":1,"items":[{"bidder":"client_a","attachment_point":"data","parameters":"{\\"client_a\\":{\\"user\\":{\\"ext\\":{\\"data\\":{\\"eids\\":[{\\"source\\":\\"\\",\\"uids\\":[{\\"id\\":\\"4254074976bb6a6d970f5f693bd8a75c\\",\\"atype\\":3,\\"ext\\":{\\"stype\\":\\"hemmd5\\"}},{\\"id\\":\\"d0ee291572ffcfba0bf7edb2b1c90ca7c32d255e5040b8b50907f5963abb1898\\",\\"atype\\":3,\\"ext\\":{\\"stype\\":\\"hemsha256\\"}}]}]}}}}}"}],"expires_at":1685029931}') - } - }); - expect(growthCodeRtdProvider.init(null, null)).to.equal(false); - ajaxStub.restore() - }); - it('successfully instantiates', function () { - const ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(() => { - return (url, cbObj) => { - cbObj.success('{"status":"ok","version":"1.0.0","results":1,"items":[{"bidder":"client_a","attachment_point":"data","parameters":"{\\"client_a\\":{\\"user\\":{\\"ext\\":{\\"data\\":{\\"eids\\":[{\\"source\\":\\"\\",\\"uids\\":[{\\"id\\":\\"4254074976bb6a6d970f5f693bd8a75c\\",\\"atype\\":3,\\"ext\\":{\\"stype\\":\\"hemmd5\\"}},{\\"id\\":\\"d0ee291572ffcfba0bf7edb2b1c90ca7c32d255e5040b8b50907f5963abb1898\\",\\"atype\\":3,\\"ext\\":{\\"stype\\":\\"hemsha256\\"}}]}]}}}}}"}],"expires_at":1685029931}') - } - }); - expect(growthCodeRtdProvider.init(sampleConfig, null)).to.equal(true); - ajaxStub.restore() - }); - it('successfully instantiates (cached)', function () { - const ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(() => { - return (url, cbObj) => { - cbObj.success('{"status":"ok","version":"1.0.0","results":1,"items":[{"bidder":"client_a","attachment_point":"data","parameters":"{\\"client_a\\":{\\"user\\":{\\"ext\\":{\\"data\\":{\\"eids\\":[{\\"source\\":\\"\\",\\"uids\\":[{\\"id\\":\\"4254074976bb6a6d970f5f693bd8a75c\\",\\"atype\\":3,\\"ext\\":{\\"stype\\":\\"hemmd5\\"}},{\\"id\\":\\"d0ee291572ffcfba0bf7edb2b1c90ca7c32d255e5040b8b50907f5963abb1898\\",\\"atype\\":3,\\"ext\\":{\\"stype\\":\\"hemsha256\\"}}]}]}}}}}"}],"expires_at":1685029931}') - } - }); - const localStoreItem = '[{"bidder":"client_a","attachment_point":"data","parameters":"{\\"client_a\\":{\\"user\\":{\\"ext\\":{\\"data\\":{\\"eids\\":[{\\"source\\":\\"\\",\\"uids\\":[{\\"id\\":\\"4254074976bb6a6d970f5f693bd8a75c\\",\\"atype\\":3,\\"ext\\":{\\"stype\\":\\"hemmd5\\"}},{\\"id\\":\\"d0ee291572ffcfba0bf7edb2b1c90ca7c32d255e5040b8b50907f5963abb1898\\",\\"atype\\":3,\\"ext\\":{\\"stype\\":\\"hemsha256\\"}}]}]}}}}}"}]' - expect(growthCodeRtdProvider.callServer(sampleConfig, localStoreItem, '1965949885', null)).to.equal(true); - ajaxStub.restore() - }); - it('successfully instantiates (cached,expire)', function () { - const ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(() => { - return (url, cbObj) => { - cbObj.success('{"status":"ok","version":"1.0.0","results":1,"items":[{"bidder":"client_a","attachment_point":"data","parameters":"{\\"client_a\\":{\\"user\\":{\\"ext\\":{\\"data\\":{\\"eids\\":[{\\"source\\":\\"\\",\\"uids\\":[{\\"id\\":\\"4254074976bb6a6d970f5f693bd8a75c\\",\\"atype\\":3,\\"ext\\":{\\"stype\\":\\"hemmd5\\"}},{\\"id\\":\\"d0ee291572ffcfba0bf7edb2b1c90ca7c32d255e5040b8b50907f5963abb1898\\",\\"atype\\":3,\\"ext\\":{\\"stype\\":\\"hemsha256\\"}}]}]}}}}}"}],"expires_at":1685029931}') - } - }); - const localStoreItem = '[{"bidder":"client_a","attachment_point":"data","parameters":"{\\"client_a\\":{\\"user\\":{\\"ext\\":{\\"data\\":{\\"eids\\":[{\\"source\\":\\"\\",\\"uids\\":[{\\"id\\":\\"4254074976bb6a6d970f5f693bd8a75c\\",\\"atype\\":3,\\"ext\\":{\\"stype\\":\\"hemmd5\\"}},{\\"id\\":\\"d0ee291572ffcfba0bf7edb2b1c90ca7c32d255e5040b8b50907f5963abb1898\\",\\"atype\\":3,\\"ext\\":{\\"stype\\":\\"hemsha256\\"}}]}]}}}}}"}]' - expect(growthCodeRtdProvider.callServer(sampleConfig, localStoreItem, '1679188732', null)).to.equal(true); - ajaxStub.restore() - }); - - it('test no items response', function () { - const ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(() => { - return (url, cbObj) => { - cbObj.success('{}') - } - }); - expect(growthCodeRtdProvider.callServer(sampleConfig, null, '1679188732', null)).to.equal(true); - ajaxStub.restore(); - }); - - it('ajax error response', function () { - const ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(() => { - return (url, cbObj) => { - cbObj.error(); - } - }); - expect(growthCodeRtdProvider.callServer(sampleConfig, null, '1679188732', null)).to.equal(true); - ajaxStub.restore(); - }); - - it('test alterBid data merge into ortb2 data (bidder)', function() { - const gcData = - { - 'client_a': - { - 'user': - {'ext': - {'data': - {'eids': [ - {'source': 'test.com', - 'uids': [ - { - 'id': '4254074976bb6a6d970f5f693bd8a75c', - 'atype': 3, - 'ext': { - 'stype': 'hemmd5'} - }, { - 'id': 'd0ee291572ffcfba0bf7edb2b1c90ca7c32d255e5040b8b50907f5963abb1898', - 'atype': 3, - 'ext': { - 'stype': 'hemsha256' - } - } - ] - } - ] - } - } - } - } - }; - - const payload = [ - { - 'bidder': 'client_a', - 'attachment_point': 'data', - 'parameters': JSON.stringify(gcData) - }] - - const bidConfig = {ortb2Fragments: {bidder: {}}}; - growthCodeRtdProvider.addData(bidConfig, payload) - - expect(bidConfig.ortb2Fragments.bidder).to.deep.equal(gcData) - }); - }); -}); diff --git a/test/spec/modules/gumgumBidAdapter_spec.js b/test/spec/modules/gumgumBidAdapter_spec.js deleted file mode 100644 index 1ceaf4f26..000000000 --- a/test/spec/modules/gumgumBidAdapter_spec.js +++ /dev/null @@ -1,1153 +0,0 @@ -import { BANNER, VIDEO } from 'src/mediaTypes.js'; - -import { config } from 'src/config.js'; -import { expect } from 'chai'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { spec } from 'modules/gumgumBidAdapter.js'; - -const ENDPOINT = 'https://g2.gumgum.com/hbid/imp'; -const JCSI = { t: 0, rq: 8, pbv: '$prebid.version$' } - -describe('gumgumAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'gumgum', - 'params': { - 'inScreen': '10433394', - 'bidfloor': 0.05 - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - sizes: [[300, 250], [300, 600], [1, 1]] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - - it('should return true when required params found', function () { - const zoneBid = { ...bid, params: { 'zone': '123' } }; - const pubIdBid = { ...bid, params: { 'pubId': 123 } }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - expect(spec.isBidRequestValid(zoneBid)).to.equal(true); - expect(spec.isBidRequestValid(pubIdBid)).to.equal(true); - }); - - it('should return true when required params found', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'inSlot': '789' - }; - - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when inslot sends sizes and trackingid', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'inSlot': '789', - 'sizes': [[0, 1], [2, 3], [4, 5], [6, 7]] - }; - - expect(spec.isBidRequestValid(invalidBid)).to.equal(true); - }); - - it('should return false when no unit type is specified', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'placementId': 0 - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when bidfloor is not a number', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'inSlot': '789', - 'bidfloor': '0.50' - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false if invalid request id is found', function () { - const bidRequest = { - id: 12345, - sizes: [[300, 250], [1, 1]], - url: ENDPOINT, - method: 'GET', - pi: 3, - data: { t: '10433394' } - }; - let body; - spec.interpretResponse({ body }, bidRequest); // empty response - expect(spec.isBidRequestValid(bid)).to.be.equal(false); - }); - }); - - describe('buildRequests', function () { - const sizesArray = [[300, 250], [300, 600]]; - const bidderRequest = { - ortb2: { - site: { - content: { - data: [{ - name: 'www.iris.com', - ext: { - segtax: 500, - cids: ['iris_c73g5jq96mwso4d8'] - } - }], - url: 'http://pub.com/news', - }, - page: 'http://pub.com/news', - ref: 'http://google.com', - publisher: { - id: 'p10000', - domain: 'pub.com' - } - } - } - }; - - const bidRequests = [ - { - gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', - gppSid: [7], - bidder: 'gumgum', - params: { - inSlot: 9 - }, - mediaTypes: { - banner: { - sizes: sizesArray - } - }, - userId: { - id5id: { - uid: 'uid-string', - ext: { - linkType: 2 - } - } - }, - pubProvidedId: [ - { - uids: [ - { - ext: { - stype: 'ppuid', - }, - id: 'aac4504f-ef89-401b-a891-ada59db44336', - }, - ], - source: 'sonobi.com', - }, - { - uids: [ - { - ext: { - stype: 'ppuid', - }, - id: 'y-zqTHmW9E2uG3jEETC6i6BjGcMhPXld2F~A', - }, - ], - source: 'aol.com', - }, - ], - adUnitCode: 'adunit-code', - sizes: sizesArray, - bidId: '30b31c1838de1e', - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'exchange1.com', - sid: '1234', - hp: 1, - rid: 'bid-request-1', - name: 'publisher', - domain: 'publisher.com' - }, - { - asi: 'exchange2.com', - sid: 'abcd', - hp: 1, - rid: 'bid-request-2', - name: 'intermediary', - domain: 'intermediary.com' - } - ] - } - } - } - } - } - ]; - const vidMediaTypes = { - video: { - playerSize: [640, 480], - context: 'instream', - minduration: 1, - maxduration: 2, - linearity: 1, - startdelay: 1, - placement: 123456, - plcmt: 3, - protocols: [1, 2] - } - }; - const zoneParam = { 'zone': '123a' }; - const pubIdParam = { 'pubId': 123 }; - - it('should set aun if the adUnitCode is available', function () { - const request = { ...bidRequests[0] }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.aun).to.equal(bidRequests[0].adUnitCode); - expect(bidRequest.data.displaymanager).to.equal('Prebid.js - gumgum'); - expect(bidRequest.data.displaymanagerver).to.equal(JCSI.pbv); - }); - it('should set pubProvidedId if the uid and pubProvidedId are available', function () { - const request = { ...bidRequests[0] }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.pubProvidedId).to.equal(JSON.stringify(bidRequests[0].userId.pubProvidedId)); - }); - it('should set id5Id and id5IdLinkType if the uid and linkType are available', function () { - const request = { ...bidRequests[0] }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.id5Id).to.equal(bidRequests[0].userId.id5id.uid); - expect(bidRequest.data.id5IdLinkType).to.equal(bidRequests[0].userId.id5id.ext.linkType); - }); - - it('should set pubId param if found', function () { - const request = { ...bidRequests[0], params: pubIdParam }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.pubId).to.equal(pubIdParam.pubId); - }); - - it('should set t param when zone param is found', function () { - const request = { ...bidRequests[0], params: zoneParam }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.t).to.equal(zoneParam.zone); - }); - - it('should send the banner dimension with the greatest width or height for slot ads', function () { - const legacyRequest = { ...bidRequests[0] }; - const slotZoneRequest = { ...bidRequests[0], params: { ...zoneParam, slot: 9 } } - const slotPubIdRequest = { ...bidRequests[0], params: { ...pubIdParam, slot: 9 } } - const legacyBidRequest = spec.buildRequests([legacyRequest])[0]; - const slotZoneBidRequest = spec.buildRequests([slotZoneRequest])[0]; - const slotPubIdBidRequest = spec.buildRequests([slotPubIdRequest])[0]; - expect(legacyBidRequest.data.maxw).to.equal(300); - expect(legacyBidRequest.data.maxh).to.equal(600); - expect(slotZoneBidRequest.data.maxw).to.equal(300); - expect(slotZoneBidRequest.data.maxh).to.equal(600); - expect(slotPubIdBidRequest.data.maxw).to.equal(300); - expect(slotPubIdBidRequest.data.maxh).to.equal(600); - }); - - // if slot ID is set up incorrectly by a pub, we should send the invalid ID to be - // invalidated by ad server instead of trying to force integer type. forcing - // integer type can result in incorrect slot IDs that correlate to the incorrect pub ID - it('should send params.slot or params.inSlot as string when configured incorrectly', function () { - const invalidSlotId = '9gkal1cn'; - const slotRequest = { ...bidRequests[0] }; - const legacySlotRequest = { ...bidRequests[0] }; - let req; - let legReq; - - slotRequest.params.slot = invalidSlotId; - legacySlotRequest.params.inSlot = invalidSlotId; - - req = spec.buildRequests([slotRequest])[0]; - legReq = spec.buildRequests([legacySlotRequest])[0]; - - expect(req.data.si).to.equal(invalidSlotId); - expect(legReq.data.si).to.equal(invalidSlotId); - }); - - it('should set the iriscat param when found', function () { - const request = { ...bidRequests[0], params: { iriscat: 'abc123' } } - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data).to.have.property('iriscat'); - }); - it('should set the irisid param when found iris_c73g5jq96mwso4d8', function() { - const request = { ...bidRequests[0], params: { irisid: 'abc123' } }; - const bidRequest = spec.buildRequests([request], bidderRequest)[0]; - expect(bidRequest.data).to.have.property('irisid', 'iris_c73g5jq96mwso4d8'); - }); - it('should set the curl param if present', function() { - const request = { ...bidRequests[0] }; - const bidRequest = spec.buildRequests([request], bidderRequest)[0]; - expect(bidRequest.data).to.have.property('curl', 'http://pub.com/news'); - }); - it('should not set the iriscat param when not found', function () { - const request = { ...bidRequests[0] } - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data).to.not.have.property('iriscat'); - }); - it('should not set the irisid param when not found', function () { - const request = { ...bidRequests[0] } - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data).to.not.have.property('irisid'); - }); - - it('should not set the irisid param when not of type string', function () { - const request = { ...bidRequests[0], params: { irisid: 123456 } } - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data).to.not.have.property('irisid'); - }); - - it('should set the global placement id (gpid) if in adserver property', function () { - const req = { ...bidRequests[0], - ortb2Imp: { - ext: { - gpid: '/17037559/jeusol/jeusol_D_1', - data: { - adserver: { - name: 'test', - adslot: 123456 - } - } - } - } } - const bidRequest = spec.buildRequests([req])[0]; - expect(bidRequest.data).to.have.property('gpid'); - expect(bidRequest.data.gpid).to.equal('/17037559/jeusol/jeusol_D_1'); - }); - it('should set ae value to 1 for PAAPI', function () { - const req = { ...bidRequests[0], - ortb2Imp: { - ext: { - ae: 1, - data: { - adserver: { - name: 'test', - adslot: 123456 - } - } - } - } } - const bidRequest = spec.buildRequests([req])[0]; - expect(bidRequest.data).to.have.property('ae'); - expect(bidRequest.data.ae).to.equal(true); - }); - - it('should set the global placement id (gpid) if in gpid property', function () { - const gpid = 'abc123' - const req = { ...bidRequests[0], ortb2Imp: { ext: { data: {}, gpid } } } - const bidRequest = spec.buildRequests([req])[0]; - expect(bidRequest.data).to.have.property('gpid'); - expect(bidRequest.data.gpid).to.equal(gpid); - }); - - it('should set the global placement id (gpid) if media type is video', function () { - const gpid = 'cde456' - const req = { ...bidRequests[0], ortb2Imp: { ext: { data: {}, gpid } }, params: zoneParam, mediaTypes: vidMediaTypes } - const bidRequest = spec.buildRequests([req])[0]; - expect(bidRequest.data).to.have.property('gpid'); - expect(bidRequest.data.gpid).to.equal(gpid); - }); - - it('should set the bid floor if getFloor module is not present but static bid floor is defined', function () { - const req = { ...bidRequests[0], params: { bidfloor: 42 } } - const bidRequest = spec.buildRequests([req])[0]; - expect(bidRequest.data).to.have.property('fp'); - expect(bidRequest.data.fp).to.equal(42); - }); - - describe('product id', function () { - it('should set the correct pi param if native param is found', function () { - const request = { ...bidRequests[0], params: { ...zoneParam, native: 2 } }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.pi).to.equal(5); - }); - it('should set the correct pi param for video', function () { - const request = { ...bidRequests[0], params: zoneParam, mediaTypes: vidMediaTypes }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.pi).to.equal(7); - }); - it('should set the correct pi param for invideo', function () { - const invideo = { video: { ...vidMediaTypes.video, linearity: 2 } }; - const request = { ...bidRequests[0], params: zoneParam, mediaTypes: invideo }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.pi).to.equal(6); - }); - it('should set the correct pi param if slot param is found', function () { - const request = { ...bidRequests[0], params: { ...zoneParam, slot: '123s' } }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.pi).to.equal(3); - }); - it('should set the correct pi param if product param is found and is equal to skins', function () { - const request = { ...bidRequests[0], params: { ...zoneParam, product: 'Skins' } }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.pi).to.equal(8); - }); - it('should default the pi param to 2 if only zone or pubId param is found', function () { - const zoneRequest = { ...bidRequests[0], params: zoneParam }; - const pubIdRequest = { ...bidRequests[0], params: pubIdParam }; - const zoneBidRequest = spec.buildRequests([zoneRequest])[0]; - const pubIdBidRequest = spec.buildRequests([pubIdRequest])[0]; - expect(zoneBidRequest.data.pi).to.equal(2); - expect(pubIdBidRequest.data.pi).to.equal(2); - }); - }); - - it('should return a defined sizes field for video', function () { - const request = { ...bidRequests[0], mediaTypes: vidMediaTypes, params: { 'videoPubID': 123 } }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.sizes).to.equal(vidMediaTypes.video.playerSize); - }); - it('should handle multiple sizes for inslot', function () { - const mediaTypes = { banner: { sizes: [[300, 250], [300, 600]] } } - const request = { ...bidRequests[0], mediaTypes }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.bf).to.equal('300x250,300x600'); - }); - describe('floorModule', function () { - const floorTestData = { - 'currency': 'USD', - 'floor': 1.50 - }; - bidRequests[0].getFloor = _ => { - return floorTestData; - }; - it('should return the value from getFloor if present', function () { - const request = spec.buildRequests(bidRequests)[0]; - expect(request.data.fp).to.equal(floorTestData.floor); - }); - it('should return the getFloor.floor value if it is greater than bidfloor', function () { - const bidfloor = 0.80; - const request = { ...bidRequests[0] }; - request.params.bidfloor = bidfloor; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.fp).to.equal(floorTestData.floor); - }); - it('should return the bidfloor value if it is greater than getFloor.floor', function () { - const bidfloor = 1.80; - const request = { ...bidRequests[0] }; - request.params.bidfloor = bidfloor; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.fp).to.equal(bidfloor); - }); - it('should return a floor currency', function () { - const request = spec.buildRequests(bidRequests)[0]; - expect(request.data.fpc).to.equal(floorTestData.currency); - }) - }); - - it('sends bid request to ENDPOINT via GET', function () { - const request = spec.buildRequests(bidRequests)[0]; - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('GET'); - expect(request.id).to.equal('30b31c1838de1e'); - }); - it('should set t and fp parameters in bid request if inScreen request param is found', function () { - const request = Object.assign({}, bidRequests[0]); - delete request.params; - request.params = { - 'inScreen': '10433394', - 'bidfloor': 0.05 - }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.pi).to.equal(2); - expect(bidRequest.data).to.include.any.keys('t'); - expect(bidRequest.data).to.include.any.keys('fp'); - }); - it('should set iriscat parameter if iriscat param is found and is of type string', function () { - const iriscat = 'segment'; - const request = { ...bidRequests[0] }; - request.params = { ...request.params, iriscat }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.iriscat).to.equal(iriscat); - }); - it('should not send iriscat parameter if iriscat param is not found', function () { - const request = { ...bidRequests[0] }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.iriscat).to.be.undefined; - }); - it('should not send iriscat parameter if iriscat param is not of type string', function () { - const iriscat = 123; - const request = { ...bidRequests[0] }; - request.params = { ...request.params, iriscat }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.iriscat).to.be.undefined; - }); - it('should send pubId if inScreenPubID param is specified', function () { - const request = Object.assign({}, bidRequests[0]); - delete request.params; - request.params = { - 'inScreenPubID': 123 - }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data).to.include.any.keys('pubId'); - expect(bidRequest.data.pubId).to.equal(request.params.inScreenPubID); - expect(bidRequest.data).to.not.include.any.keys('t'); - }); - it('should send pubId if videoPubID param is specified', function () { - const request = { ...bidRequests[0], mediaTypes: vidMediaTypes, params: { 'videoPubID': 123 } }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data).to.include.any.keys('pubId'); - expect(bidRequest.data.pubId).to.equal(request.params.videoPubID); - expect(bidRequest.data).to.not.include.any.keys('t'); - }); - it('should set a ni parameter in bid request if ICV request param is found', function () { - const request = Object.assign({}, bidRequests[0]); - delete request.params; - request.params = { - 'ICV': '10433395' - }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.pi).to.equal(5); - expect(bidRequest.data).to.include.any.keys('ni'); - }); - it('should add parameters associated with video if video request param is found', function () { - const videoVals = { - playerSize: [640, 480], - context: 'instream', - minduration: 1, - maxduration: 2, - linearity: 1, - startdelay: 1, - placement: 123456, - plcmt: 3, - protocols: [1, 2], - skip: 1, - api: [1, 2], - mimes: ['video/mp4', 'video/webm'], - playbackmethod: [1, 2], - playbackend: 2 - }; - const request = Object.assign({}, bidRequests[0]); - delete request.params; - request.mediaTypes = { - video: videoVals - }; - request.params = { - 'video': '10433395' - }; - const bidRequest = spec.buildRequests([request])[0]; - // 7 is video product line - expect(bidRequest.data.pi).to.eq(7); - expect(bidRequest.data.mind).to.eq(videoVals.minduration); - expect(bidRequest.data.maxd).to.eq(videoVals.maxduration); - expect(bidRequest.data.li).to.eq(videoVals.linearity); - expect(bidRequest.data.sd).to.eq(videoVals.startdelay); - expect(bidRequest.data.pt).to.eq(videoVals.placement); - expect(bidRequest.data.vplcmt).to.eq(videoVals.plcmt); - expect(bidRequest.data.pr).to.eq(videoVals.protocols.join(',')); - expect(bidRequest.data.viw).to.eq(videoVals.playerSize[0].toString()); - expect(bidRequest.data.vih).to.eq(videoVals.playerSize[1].toString()); - expect(bidRequest.data.skip).to.eq(videoVals.skip); - expect(bidRequest.data.api).to.eq(videoVals.api.join(',')); - expect(bidRequest.data.mimes).to.eq(videoVals.mimes.join(',')); - expect(bidRequest.data.pbm).to.eq(videoVals.playbackmethod.join(',')); - expect(bidRequest.data.pbe).to.eq(videoVals.playbackend); - }); - it('should add parameters associated with invideo if invideo request param is found', function () { - const inVideoVals = { - playerSize: [640, 480], - context: 'instream', - minduration: 1, - maxduration: 2, - linearity: 1, - startdelay: 1, - placement: 123456, - plcmt: 3, - protocols: [1, 2], - skip: 1, - api: [1, 2], - mimes: ['video/mp4', 'video/webm'], - playbackmethod: [6], - playbackend: 1 - }; - const request = Object.assign({}, bidRequests[0]); - delete request.params; - request.mediaTypes = { - video: inVideoVals - }; - request.params = { - 'inVideo': '10433395' - }; - const bidRequest = spec.buildRequests([request])[0]; - // 6 is invideo product line - expect(bidRequest.data.pi).to.eq(6); - expect(bidRequest.data.mind).to.eq(inVideoVals.minduration); - expect(bidRequest.data.maxd).to.eq(inVideoVals.maxduration); - expect(bidRequest.data.li).to.eq(inVideoVals.linearity); - expect(bidRequest.data.sd).to.eq(inVideoVals.startdelay); - expect(bidRequest.data.pt).to.eq(inVideoVals.placement); - expect(bidRequest.data.vplcmt).to.eq(inVideoVals.plcmt); - expect(bidRequest.data.pr).to.eq(inVideoVals.protocols.join(',')); - expect(bidRequest.data.viw).to.eq(inVideoVals.playerSize[0].toString()); - expect(bidRequest.data.vih).to.eq(inVideoVals.playerSize[1].toString()); - expect(bidRequest.data.skip).to.eq(inVideoVals.skip); - expect(bidRequest.data.api).to.eq(inVideoVals.api.join(',')); - expect(bidRequest.data.mimes).to.eq(inVideoVals.mimes.join(',')); - expect(bidRequest.data.pbm).to.eq(inVideoVals.playbackmethod.join(',')); - expect(bidRequest.data.pbe).to.eq(inVideoVals.playbackend); - }); - it('should not add additional parameters depending on params field', function () { - const request = spec.buildRequests(bidRequests)[0]; - expect(request.data).to.not.include.any.keys('ni'); - expect(request.data).to.not.include.any.keys('t'); - expect(request.data).to.not.include.any.keys('eAdBuyId'); - expect(request.data).to.not.include.any.keys('adBuyId'); - }); - it('should set pubProvidedId if the uid and pubProvidedId are available', function () { - const request = { ...bidRequests[0] }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.pubProvidedId).to.equal(JSON.stringify(bidRequests[0].userId.pubProvidedId)); - }); - - it('should add gdpr consent parameters if gdprConsent is present', function () { - const gdprConsent = { consentString: 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', gdprApplies: true }; - const fakeBidRequest = { gdprConsent: gdprConsent }; - const bidRequest = spec.buildRequests(bidRequests, fakeBidRequest)[0]; - expect(bidRequest.data.gdprApplies).to.eq(1); - expect(bidRequest.data.gdprConsent).to.eq('BOJ/P2HOJ/P2HABABMAAAAAZ+A=='); - }); - it('should handle gdprConsent is present but values are undefined case', function () { - const gdprConsent = { consent_string: undefined, gdprApplies: undefined }; - const fakeBidRequest = { gdprConsent: gdprConsent }; - const bidRequest = spec.buildRequests(bidRequests, fakeBidRequest)[0]; - expect(bidRequest.data).to.not.include.any.keys('gdprConsent') - }); - it('should add gpp parameters if gppConsent is present', function () { - const gppConsent = { gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', applicableSections: [7] } - const fakeBidRequest = { gppConsent: gppConsent }; - const bidRequest = spec.buildRequests(bidRequests, fakeBidRequest)[0]; - expect(bidRequest.data.gppString).to.equal(gppConsent.gppString); - expect(bidRequest.data.gppSid).to.equal(gppConsent.applicableSections.join(',')); - expect(bidRequest.data.gppString).to.eq('DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN'); - }); - it('should handle ortb2 parameters', function () { - const ortb2 = { - regs: { - gpp: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', - gpp_sid: [7] - } - } - const fakeBidRequest = { gppConsent: ortb2 }; - const bidRequest = spec.buildRequests(bidRequests, fakeBidRequest)[0]; - expect(bidRequest.data.gpp).to.eq(fakeBidRequest[0]) - }); - it('should handle gppConsent is present but values are undefined case', function () { - const gppConsent = { gppString: undefined, applicableSections: undefined } - const fakeBidRequest = { gppConsent: gppConsent }; - const bidRequest = spec.buildRequests(bidRequests, fakeBidRequest)[0]; - expect(bidRequest.data.gppString).to.equal(''); - expect(bidRequest.data.gppSid).to.equal(''); - }); - it('should handle ortb2 undefined parameters', function () { - const ortb2 = { - regs: { - gpp: undefined, - gpp_sid: undefined - } - } - const fakeBidRequest = { gppConsent: ortb2 }; - const bidRequest = spec.buildRequests(bidRequests, fakeBidRequest)[0]; - expect(bidRequest.data.gppString).to.eq('') - expect(bidRequest.data.gppSid).to.eq('') - }); - it('should add DSA information to payload if available', function () { - // Define the sample ORTB2 object with DSA information - const ortb2 = { - regs: { - ext: { - dsa: { - dsarequired: '1', - pubrender: '2', - datatopub: '3', - transparency: [{ - domain: 'test.com', - dsaparams: [1, 2, 3] - }] - } - } - } - }; - const fakeBidRequest = { ortb2 }; - // Call the buildRequests function to generate the bid request - const [bidRequest] = spec.buildRequests(bidRequests, fakeBidRequest); - // Assert that the DSA information in the bid request matches the provided ORTB2 data - expect(bidRequest.data.dsa).to.deep.equal(JSON.stringify(fakeBidRequest.ortb2.regs.ext.dsa)); - }); - it('should not set coppa parameter if coppa config is set to false', function () { - config.setConfig({ - coppa: false - }); - const bidRequest = spec.buildRequests(bidRequests)[0]; - expect(bidRequest.data.coppa).to.eq(undefined); - }); - it('should set coppa parameter to 1 if coppa config is set to true', function () { - config.setConfig({ - coppa: true - }); - const bidRequest = spec.buildRequests(bidRequests)[0]; - expect(bidRequest.data.coppa).to.eq(1); - }); - it('should add uspConsent parameter if it is present in the bidderRequest', function () { - const noUspBidRequest = spec.buildRequests(bidRequests)[0]; - const uspConsentObj = { uspConsent: '1YYY' }; - const bidRequest = spec.buildRequests(bidRequests, uspConsentObj)[0]; - expect(noUspBidRequest.data).to.not.include.any.keys('uspConsent'); - expect(bidRequest.data).to.include.any.keys('uspConsent'); - expect(bidRequest.data.uspConsent).to.eq(uspConsentObj.uspConsent); - }); - it('should add a tdid parameter if request contains unified id from TradeDesk', function () { - const unifiedId = { - 'userId': { - 'tdid': 'tradedesk-id' - } - } - const request = Object.assign(unifiedId, bidRequests[0]); - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.tdid).to.eq(unifiedId.userId.tdid); - }); - it('should not add a tdid parameter if unified id is not found', function () { - const request = spec.buildRequests(bidRequests)[0]; - expect(request.data).to.not.include.any.keys('tdid'); - }); - it('should send IDL envelope ID if available', function () { - const idl_env = 'abc123'; - const request = { ...bidRequests[0], userId: { idl_env } }; - const bidRequest = spec.buildRequests([request])[0]; - - expect(bidRequest.data).to.have.property('idl_env'); - expect(bidRequest.data.idl_env).to.equal(idl_env); - }); - it('should not send IDL envelope if not available', function () { - const request = { ...bidRequests[0] }; - const bidRequest = spec.buildRequests([request])[0]; - - expect(bidRequest.data).to.not.have.property('idl_env'); - }); - it('should add a uid2 parameter if request contains uid2 id', function () { - const uid2 = { id: 'sample-uid2' }; - const request = { ...bidRequests[0], userId: { uid2 } }; - const bidRequest = spec.buildRequests([request])[0]; - - expect(bidRequest.data).to.have.property('uid2'); - expect(bidRequest.data.uid2).to.equal(uid2.id); - }); - it('should not add uid2 parameter if uid2 id is not found', function () { - const request = { ...bidRequests[0] }; - const bidRequest = spec.buildRequests([request])[0]; - - expect(bidRequest.data).to.not.have.property('uid2'); - }); - it('should send schain parameter in serialized form', function () { - const serializedForm = '1.0,1!exchange1.com,1234,1,bid-request-1,publisher,publisher.com!exchange2.com,abcd,1,bid-request-2,intermediary,intermediary.com' - const request = spec.buildRequests(bidRequests)[0]; - expect(request.data).to.include.any.keys('schain'); - expect(request.data.schain).to.eq(serializedForm); - }); - it('should send ns parameter if browser contains navigator.connection property', function () { - const bidRequest = spec.buildRequests(bidRequests)[0]; - const connection = window.navigator && window.navigator.connection; - if (connection) { - const downlink = connection.downlink || connection.bandwidth; - expect(bidRequest.data).to.include.any.keys('ns'); - expect(bidRequest.data.ns).to.eq(Math.round(downlink * 1024)); - } else { - expect(bidRequest.data).to.not.include.any.keys('ns'); - } - }); - it('adds jcsi param with correct keys', function () { - const expectedKeys = Object.keys(JCSI).sort(); - const jcsi = JSON.stringify(JCSI); - const bidRequest = spec.buildRequests(bidRequests)[0]; - const actualKeys = Object.keys(JSON.parse(bidRequest.data.jcsi)).sort(); - expect(actualKeys).to.eql(expectedKeys); - expect(bidRequest.data.jcsi).to.eq(jcsi); - }); - it('should include the local time and timezone offset', function () { - const bidRequest = spec.buildRequests(bidRequests)[0]; - expect(!!bidRequest.data.lt).to.be.true; - }); - - it('should handle no gg params', function () { - const bidRequest = spec.buildRequests(bidRequests, { refererInfo: { page: 'https://www.prebid.org/?param1=foo¶m2=bar¶m3=baz' } })[0]; - - // no params are in object - expect(bidRequest.data.hasOwnProperty('eAdBuyId')).to.be.false; - expect(bidRequest.data.hasOwnProperty('adBuyId')).to.be.false; - expect(bidRequest.data.hasOwnProperty('ggdeal')).to.be.false; - }); - - it('should handle encrypted ad buy id', function () { - const bidRequest = spec.buildRequests(bidRequests, { refererInfo: { page: 'https://www.prebid.org/?param1=foo&ggad=bar¶m3=baz' } })[0]; - - // correct params are in object - expect(bidRequest.data.hasOwnProperty('eAdBuyId')).to.be.true; - expect(bidRequest.data.hasOwnProperty('adBuyId')).to.be.false; - expect(bidRequest.data.hasOwnProperty('ggdeal')).to.be.false; - - // params are stripped from pu property - expect(bidRequest.data.pu.includes('ggad')).to.be.false; - }); - - it('should handle unencrypted ad buy id', function () { - const bidRequest = spec.buildRequests(bidRequests, { refererInfo: { page: 'https://www.prebid.org/?param1=foo&ggad=123¶m3=baz' } })[0]; - - // correct params are in object - expect(bidRequest.data.hasOwnProperty('eAdBuyId')).to.be.false; - expect(bidRequest.data.hasOwnProperty('adBuyId')).to.be.true; - expect(bidRequest.data.hasOwnProperty('ggdeal')).to.be.false; - - // params are stripped from pu property - expect(bidRequest.data.pu.includes('ggad')).to.be.false; - }); - - it('should handle multiple gg params', function () { - const bidRequest = spec.buildRequests(bidRequests, { refererInfo: { page: 'https://www.prebid.org/?ggdeal=foo&ggad=bar¶m3=baz' } })[0]; - - // correct params are in object - expect(bidRequest.data.hasOwnProperty('eAdBuyId')).to.be.true; - expect(bidRequest.data.hasOwnProperty('adBuyId')).to.be.false; - expect(bidRequest.data.hasOwnProperty('ggdeal')).to.be.true; - - // params are stripped from pu property - expect(bidRequest.data.pu.includes('ggad')).to.be.false; - expect(bidRequest.data.pu.includes('ggdeal')).to.be.false; - }); - - it('should handle ORTB2 device data', function () { - const suaObject = { - source: 2, - platform: { - brand: 'macOS', - version: ['15', '5', '0'] - }, - browsers: [ - { - brand: 'Google Chrome', - version: ['137', '0', '7151', '41'] - }, - { - brand: 'Chromium', - version: ['137', '0', '7151', '41'] - }, - { - brand: 'Not/A)Brand', - version: ['24', '0', '0', '0'] - } - ], - mobile: 0, - model: '', - architecture: 'arm' - }; - const ortb2 = { - device: { - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - ext: {fiftyonedegrees_deviceId: '17595-133085-133468-18092'}, - ip: '127.0.0.1', - ipv6: '51dc:5e20:fd6a:c955:66be:03b4:dfa3:35b2', - sua: suaObject - - }, - }; - - const bidRequest = spec.buildRequests(bidRequests, { ortb2 })[0]; - - expect(bidRequest.data.dnt).to.equal(ortb2.device.dnt); - expect(bidRequest.data.ua).to.equal(ortb2.device.ua); - expect(bidRequest.data.lang).to.equal(ortb2.device.language); - expect(bidRequest.data.dt).to.equal(ortb2.device.devicetype); - expect(bidRequest.data.make).to.equal(ortb2.device.make); - expect(bidRequest.data.model).to.equal(ortb2.device.model); - expect(bidRequest.data.os).to.equal(ortb2.device.os); - expect(bidRequest.data.osv).to.equal(ortb2.device.osv); - expect(bidRequest.data.foddid).to.equal(ortb2.device.ext.fiftyonedegrees_deviceId); - expect(bidRequest.data.ip).to.equal(ortb2.device.ip); - expect(bidRequest.data.ipv6).to.equal(ortb2.device.ipv6); - expect(bidRequest.data).to.have.property('sua'); - expect(() => JSON.parse(bidRequest.data.sua)).to.not.throw(); - expect(JSON.parse(bidRequest.data.sua)).to.deep.equal(suaObject); - }); - - it('should set tId from ortb2Imp.ext.tid if available', function () { - const ortb2Imp = { ext: { tid: 'test-tid-1' } }; - const request = { ...bidRequests[0], ortb2Imp }; - const bidRequest = spec.buildRequests([request])[0]; - expect(bidRequest.data.tId).to.equal('test-tid-1'); - }); - - it('should set tId from bidderRequest.ortb2.source.tid if ortb2Imp.ext.tid is not available', function () { - const ortb2 = { source: { tid: 'test-tid-2' } }; - const fakeBidRequest = { ortb2 }; - const bidRequest = spec.buildRequests(bidRequests, fakeBidRequest)[0]; - expect(bidRequest.data.tId).to.equal('test-tid-2'); - }); - - it('should set tId to an empty string if neither ortb2Imp.ext.tid nor bidderRequest.ortb2.source.tid are available', function () { - const bidRequest = spec.buildRequests(bidRequests)[0]; - expect(bidRequest.data.tId).to.equal(''); - }) - }) - - describe('interpretResponse', function () { - const metaData = { adomain: ['advertiser.com'], mediaType: BANNER } - const serverResponse = { - ad: { - id: 29593, - width: 300, - height: 250, - ipd: 2000, - markup: '

I am an ad

', - ii: true, - du: null, - price: 0, - zi: 0, - impurl: 'http://g2.gumgum.com/ad/view', - clsurl: 'http://g2.gumgum.com/ad/close' - }, - pag: { - t: 'ggumtest', - pvid: 'aa8bbb65-427f-4689-8cee-e3eed0b89eec', - css: 'html { overflow-y: auto }', - js: 'console.log("environment", env);' - }, - jcsi: { t: 0, rq: 8 }, - thms: 10000, - meta: metaData - } - const bidRequest = { - id: 12345, - sizes: [[300, 250], [1, 1]], - url: ENDPOINT, - method: 'GET', - pi: 3 - } - const expectedMetaData = { advertiserDomains: ['advertiser.com'], mediaType: BANNER }; - const expectedResponse = { - ad: '

I am an ad

', - cpm: 0, - creativeId: 29593, - currency: 'USD', - height: '250', - netRevenue: true, - requestId: 12345, - width: '300', - mediaType: BANNER, - ttl: 60, - meta: expectedMetaData - }; - - it('should get correct bid response', function () { - expect(spec.interpretResponse({ body: serverResponse }, bidRequest)).to.deep.equal([expectedResponse]); - }); - - it('should set a default value for advertiserDomains if adomain is not found', function () { - const meta = { ...metaData }; - delete meta.adomain; - - const response = { ...serverResponse, meta }; - const expectedMeta = { ...expectedMetaData, advertiserDomains: [] }; - const expected = { ...expectedResponse, meta: expectedMeta }; - - expect(spec.interpretResponse({ body: response }, bidRequest)).to.deep.equal([expected]); - }); - - it('should set a default value for meta.mediaType if mediaType is not found in the response', function () { - const meta = { ...metaData }; - delete meta.mediaType; - const response = { ...serverResponse, meta }; - const expected = { ...expectedResponse }; - - expect(spec.interpretResponse({ body: response }, bidRequest)).to.deep.equal([expected]); - }); - - it('should pass correct currency if found in bid response', function () { - const cur = 'EURO'; - const response = { ...serverResponse }; - response.ad.cur = cur; - - const expected = { ...expectedResponse }; - expected.currency = cur; - - expect(spec.interpretResponse({ body: response }, bidRequest)).to.deep.equal([expected]); - }); - - it('handles nobid responses', function () { - const response = { - 'ad': {}, - 'pag': { - 't': 'ggumtest', - 'pvid': 'aa8bbb65-427f-4689-8cee-e3eed0b89eec', - 'css': 'html { overflow-y: auto }', - 'js': 'console.log("environment", env);' - }, - 'thms': 10000 - } - const result = spec.interpretResponse({ body: response }, bidRequest); - expect(result.length).to.equal(0); - }); - - it('handles empty response', function () { - let body; - const result = spec.interpretResponse({ body }, bidRequest); - expect(result.length).to.equal(0); - }); - - describe('bidResponse width and height', function () { - it('uses response maxw and maxh for when found in bidresponse', function () { - const maxSlotAdResponse = { ...serverResponse.ad, maxw: 300, maxh: 600 }; - const result = spec.interpretResponse({ body: { ...serverResponse, ad: maxSlotAdResponse } }, bidRequest)[0]; - expect(result.width).to.equal(maxSlotAdResponse.maxw.toString()); - expect(result.height).to.equal(maxSlotAdResponse.maxh.toString()); - }); - - it('returns 1x1 when eligible product and size are available', function () { - const bidRequest = { - id: 12346, - sizes: [[300, 250], [1, 1]], - url: ENDPOINT, - method: 'GET', - data: { - pi: 5, - t: 'ggumtest' - } - } - const serverResponse = { - 'ad': { - 'id': 2065333, - 'height': 90, - 'ipd': 2000, - 'markup': '

Hello

', - 'ii': true, - 'du': null, - 'price': 1, - 'zi': 0, - 'impurl': 'http://g2.gumgum.com/ad/view', - 'clsurl': 'http://g2.gumgum.com/ad/close' - }, - 'pag': { - 't': 'ggumtest', - 'pvid': 'aa8bbb65-427f-4689-8cee-e3eed0b89eec', - }, - 'thms': 10000 - } - const result = spec.interpretResponse({ body: serverResponse }, bidRequest); - expect(result[0].width).to.equal('1'); - expect(result[0].height).to.equal('1'); - }); - - it('uses request size that nearest matches response size for in-screen', function () { - const request = { ...bidRequest }; - const body = { ...serverResponse }; - const expectedSize = [300, 50]; - let result; - - request.pi = 2; - request.sizes.unshift(expectedSize); - - // typical ad server response values for in-screen - body.ad.width = 300; - body.ad.height = 100; - - result = spec.interpretResponse({ body }, request)[0]; - - expect(result.width = expectedSize[0]); - expect(result.height = expectedSize[1]); - }) - - it('request size that matches response size for in-slot', function () { - const request = { ...bidRequest }; - const body = { ...serverResponse }; - const expectedSize = [[ 320, 50 ], [300, 600], [300, 250]]; - let result; - request.pi = 3; - body.ad.width = 300; - body.ad.height = 600; - result = spec.interpretResponse({ body }, request)[0]; - expect(result.width = expectedSize[1][0]); - expect(result.height = expectedSize[1][1]); - }) - - it('defaults to use bidRequest sizes', function () { - const { ad, jcsi, pag, thms, meta } = serverResponse - const noAdSizes = { ...ad } - delete noAdSizes.width - delete noAdSizes.height - const responseWithoutSizes = { jcsi, pag, thms, meta, ad: noAdSizes } - const request = { ...bidRequest, sizes: [[100, 200]] } - const result = spec.interpretResponse({ body: responseWithoutSizes }, request)[0]; - - expect(result.width).to.equal(request.sizes[0][0].toString()) - expect(result.height).to.equal(request.sizes[0][1].toString()) - }); - }); - - it('updates jcsi object when the server response jcsi prop is found', function () { - const response = Object.assign({ cw: 'AD_JSON' }, serverResponse); - const bidResponse = spec.interpretResponse({ body: response }, bidRequest)[0].ad; - const decodedResponse = JSON.parse(atob(bidResponse)); - expect(decodedResponse.jcsi).to.eql(JCSI); - }); - - it('sets the correct mediaType depending on product', function () { - const bannerBidResponse = spec.interpretResponse({ body: serverResponse }, bidRequest)[0]; - const invideoBidResponse = spec.interpretResponse({ body: serverResponse }, { ...bidRequest, data: { pi: 6 } })[0]; - const videoBidResponse = spec.interpretResponse({ body: serverResponse }, { ...bidRequest, data: { pi: 7 } })[0]; - expect(bannerBidResponse.mediaType).to.equal(BANNER); - expect(invideoBidResponse.mediaType).to.equal(VIDEO); - expect(videoBidResponse.mediaType).to.equal(VIDEO); - }); - - it('sets a vastXml property if mediaType is video', function () { - const videoBidResponse = spec.interpretResponse({ body: serverResponse }, { ...bidRequest, data: { pi: 7 } })[0]; - expect(videoBidResponse.vastXml).to.exist; - }); - }) - describe('getUserSyncs', function () { - const syncOptions = { - 'iframeEnabled': 'true' - } - const response = { - 'pxs': { - 'scr': [ - { - 't': 'i', - 'u': 'https://c.gumgum.com/images/pixel.gif' - }, - { - 't': 'f', - 'u': 'https://www.nytimes.com/' - } - ] - } - } - const result = spec.getUserSyncs(syncOptions, [{ body: response }]); - expect(result[0].type).to.equal('image') - expect(result[1].type).to.equal('iframe') - }) -}); diff --git a/test/spec/modules/h12mediaBidAdapter_spec.js b/test/spec/modules/h12mediaBidAdapter_spec.js deleted file mode 100644 index a4e5a7926..000000000 --- a/test/spec/modules/h12mediaBidAdapter_spec.js +++ /dev/null @@ -1,439 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/h12mediaBidAdapter'; -import {newBidder} from 'src/adapters/bidderFactory'; -import {clearCache} from '../../../libraries/boundingClientRect/boundingClientRect.js'; - -describe('H12 Media Adapter', function () { - const DEFAULT_CURRENCY = 'USD'; - const DEFAULT_TTL = 360; - const DEFAULT_NET_REVENUE = false; - const adapter = newBidder('spec'); - - const validBid = { - adUnitCode: 'div-gpt-ad-1460505748561-0', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - } - }, - bidder: 'h12media', - bidId: '1c5e8a1a84522d', - bidderRequestId: '1d0c4017f02458', - auctionId: '9adc85ed-43ee-4a78-816b-52b7e578f313', - params: { - pubid: 123321, - pubsubid: 'pubsubtestid', - }, - }; - - const validBid2 = { - adUnitCode: 'div-gpt-ad-1460505748561-1', - mediaTypes: { - banner: {} - }, - bidder: 'h12media', - bidId: '2c5e8a1a84522d', - bidderRequestId: '2d0c4017f02458', - auctionId: '9adc85ed-43ee-4a78-816b-52b7e578f314', - params: { - pubid: 123321, - size: '100x200' - }, - }; - - const invalidBid = { - adUnitCode: 'div-gpt-ad-1460505748561-2', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - } - }, - bidder: 'h12media', - bidId: '3c5e8a1a84522d', - bidderRequestId: '3d0c4017f02458', - auctionId: '9adc85ed-43ee-4a78-816b-52b7e578f315', - }; - - const bidderRequest = { - refererInfo: { - referer: 'https://localhost' - }, - gdprConsent: { - gdprApplies: 1, - consentString: 'concentDataString', - vendorData: { - vendorConsents: { - '90': 1 - }, - }, - }, - uspConsent: 'consentUspString' - }; - - const serverResponse = { - currency: 'EUR', - netRevenue: true, - ttl: 500, - bid: { - bidId: validBid.bidId, - cpm: 0.33, - width: 300, - height: 600, - creativeId: '335566', - ad: '
my ad
', - meta: { - advertiserId: '54321', - advertiserName: 'My advertiser', - advertiserDomains: ['test.com'] - } - }, - usersync: [ - {url: 'https://cookiesync.3rdpartypartner.com/?3rdparty_partner_user_id={user_id}&partner_id=h12media&gdpr_applies={gdpr}&gdpr_consent_string={gdpr_cs}', type: 'image'}, - {url: 'https://cookiesync.3rdpartypartner.com/?3rdparty_partner_user_id={user_id}&partner_id=h12media&gdpr_applies={gdpr}&gdpr_consent_string={gdpr_cs}', type: 'iframe'} - ], - }; - - const serverResponse2 = { - bid: { - bidId: validBid2.bidId, - cpm: 0.33, - width: 300, - height: 600, - creativeId: '335566', - ad: '
my ad 2
', - } - }; - - function removeElement(id) { - if (document.getElementById(id)) { - document.body.removeChild(document.getElementById(id)); - } - } - - function createElement(id) { - const div = document.createElement('div'); - div.id = id; - div.style.width = '50px'; - div.style.height = '50px'; - if (frameElement) { - frameElement.style.width = '100px'; - frameElement.style.height = '100px'; - } - div.style.background = 'black'; - document.body.appendChild(div); - return div; - } - function createElementVisible(id) { - const element = createElement(id); - sandbox.stub(element, 'getBoundingClientRect').returns({ - x: 10, - y: 10, - }); - return element; - } - function createElementInvisible(id) { - const element = document.createElement('div'); - element.id = id; - document.body.appendChild(element); - element.style.display = 'none'; - return element; - } - - function createElementHidden(id) { - const element = createElement(id); - document.body.appendChild(element); - element.style.visibility = 'hidden'; - sandbox.stub(element, 'getBoundingClientRect').returns({ - x: 100, - y: 100, - }); - return element; - } - - let sandbox; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - sandbox.stub(frameElement, 'getBoundingClientRect').returns({ - left: 10, - top: 10, - }); - clearCache(); - }); - - afterEach(function () { - removeElement(validBid.adUnitCode); - removeElement(validBid2.adUnitCode); - removeElement(invalidBid.adUnitCode); - sandbox.restore(); - }); - - after(function() { - sandbox.resetHistory(); - sandbox.resetBehavior(); - }) - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when bid is valid', function () { - expect(spec.isBidRequestValid(validBid)).to.equal(true); - }); - - it('should return false when bid does not have pubid parameter', function () { - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('should return adUnit size', function () { - createElementVisible(validBid.adUnitCode); - createElementVisible(validBid2.adUnitCode); - const requests = spec.buildRequests([validBid, validBid2], bidderRequest); - const requestsData = requests[0].data.bidrequest; - - expect(requestsData).to.include({adunitSize: validBid.mediaTypes.banner.sizes}); - }); - - it('should return empty bid size', function () { - createElementVisible(validBid.adUnitCode); - createElementVisible(validBid2.adUnitCode); - const requests = spec.buildRequests([validBid, validBid2], bidderRequest); - const requestsData2 = requests[1].data.bidrequest; - - expect(requestsData2).to.deep.include({adunitSize: []}); - }); - - it('should return pubsubid from params', function () { - createElementVisible(validBid.adUnitCode); - createElementVisible(validBid2.adUnitCode); - const requests = spec.buildRequests([validBid, validBid2], bidderRequest); - const requestsData = requests[0].data.bidrequest; - const requestsData2 = requests[1].data.bidrequest; - - expect(requestsData).to.include({pubsubid: 'pubsubtestid'}); - expect(requestsData2).to.include({pubsubid: ''}); - }); - - it('should return empty for incorrect pubsubid from params', function () { - createElementVisible(validBid.adUnitCode); - createElementVisible(validBid2.adUnitCode); - const bidWithPub = {...validBid}; - bidWithPub.params.pubsubid = 'iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii'; // More than 32 chars - const requests = spec.buildRequests([bidWithPub], bidderRequest); - const requestsData = requests[0].data.bidrequest; - - expect(requestsData).to.include({pubsubid: ''}); - }); - - it('should return bid size from params', function () { - createElementVisible(validBid.adUnitCode); - createElementVisible(validBid2.adUnitCode); - const requests = spec.buildRequests([validBid, validBid2], bidderRequest); - const requestsData = requests[0].data.bidrequest; - const requestsData2 = requests[1].data.bidrequest; - - expect(requestsData).to.include({size: ''}); - expect(requestsData2).to.include({size: validBid2.params.size}); - }); - - it('should return GDPR info', function () { - createElementVisible(validBid.adUnitCode); - createElementVisible(validBid2.adUnitCode); - const requests = spec.buildRequests([validBid, validBid2], bidderRequest); - const requestsData = requests[0].data; - const requestsData2 = requests[1].data; - - expect(requestsData).to.include({gdpr: true, gdpr_cs: bidderRequest.gdprConsent.consentString}); - expect(requestsData2).to.include({gdpr: true, gdpr_cs: bidderRequest.gdprConsent.consentString}); - }); - - it('should not have error on empty GDPR', function () { - createElementVisible(validBid.adUnitCode); - createElementVisible(validBid2.adUnitCode); - const bidderRequestWithoutGDRP = {...bidderRequest, gdprConsent: null}; - const requests = spec.buildRequests([validBid, validBid2], bidderRequestWithoutGDRP); - const requestsData = requests[0].data; - const requestsData2 = requests[1].data; - - expect(requestsData).to.include({gdpr: false}); - expect(requestsData2).to.include({gdpr: false}); - }); - - it('should not have error on empty USP', function () { - createElementVisible(validBid.adUnitCode); - createElementVisible(validBid2.adUnitCode); - const bidderRequestWithoutUSP = {...bidderRequest, uspConsent: null}; - const requests = spec.buildRequests([validBid, validBid2], bidderRequestWithoutUSP); - const requestsData = requests[0].data; - const requestsData2 = requests[1].data; - - expect(requestsData).to.include({usp: false}); - expect(requestsData2).to.include({usp: false}); - }); - - it('should create single POST', function () { - createElementVisible(validBid.adUnitCode); - createElementVisible(validBid2.adUnitCode); - const requests = spec.buildRequests([validBid, validBid2], bidderRequest); - - expect(requests[0].method).to.equal('POST'); - expect(requests[1].method).to.equal('POST'); - }); - }); - - describe('creative viewability', function () { - it('should return coords', function () { - createElementVisible(validBid.adUnitCode); - const requests = spec.buildRequests([validBid], bidderRequest); - const requestsData = requests[0].data.bidrequest; - - expect(requestsData).to.deep.include({coords: {x: 10, y: 10}}); - }); - - it('should define iframe', function () { - createElementVisible(validBid.adUnitCode); - createElementVisible(validBid2.adUnitCode); - const requests = spec.buildRequests([validBid, validBid2], bidderRequest); - const requestsData = requests[0].data; - const requestsData2 = requests[1].data; - - expect(requestsData).to.include({isiframe: true}); - expect(requestsData2).to.include({isiframe: true}); - }); - - it('should define visible element', function () { - createElementVisible(validBid.adUnitCode); - const requests = spec.buildRequests([validBid], bidderRequest); - const requestsData = requests[0].data.bidrequest; - - expect(requestsData).to.include({ishidden: false}); - }); - - it('should define invisible element', function () { - createElementInvisible(validBid.adUnitCode); - const requests = spec.buildRequests([validBid], bidderRequest); - const requestsData = requests[0].data.bidrequest; - - expect(requestsData).to.include({ishidden: true}); - }); - - it('should define hidden element', function () { - createElementHidden(validBid.adUnitCode); - const requests = spec.buildRequests([validBid], bidderRequest); - const requestsData = requests[0].data.bidrequest; - - expect(requestsData).to.include({ishidden: true}); - }); - }); - - describe('interpretResponse', function () { - it('should return no bids if the response is not valid', function () { - const bidResponse = spec.interpretResponse({ body: null }, validBid); - - expect(bidResponse.length).to.equal(0); - }); - - it('should return no bids if the response is empty', function () { - const bidResponse = spec.interpretResponse({ body: [] }, { validBid }); - - expect(bidResponse).to.be.empty; - }); - - it('should return valid bid responses', function () { - createElementVisible(validBid.adUnitCode); - createElementVisible(validBid2.adUnitCode); - const request = spec.buildRequests([validBid, validBid2], bidderRequest); - const bidResponse = spec.interpretResponse({body: serverResponse}, request[0]); - - expect(bidResponse[0]).to.deep.include({ - requestId: validBid.bidId, - ad: serverResponse.bid.ad, - mediaType: 'banner', - creativeId: serverResponse.bid.creativeId, - cpm: serverResponse.bid.cpm, - width: serverResponse.bid.width, - height: serverResponse.bid.height, - currency: 'EUR', - netRevenue: true, - ttl: 500, - meta: serverResponse.bid.meta, - pubid: validBid.params.pubid - }); - }); - - it('should return default bid params', function () { - createElementVisible(validBid.adUnitCode); - createElementVisible(validBid2.adUnitCode); - const request = spec.buildRequests([validBid, validBid2], bidderRequest); - const bidResponse = spec.interpretResponse({body: serverResponse2}, request[0]); - - expect(bidResponse[0]).to.deep.include({ - requestId: validBid2.bidId, - ad: serverResponse2.bid.ad, - mediaType: 'banner', - creativeId: serverResponse2.bid.creativeId, - cpm: serverResponse2.bid.cpm, - width: serverResponse2.bid.width, - height: serverResponse2.bid.height, - meta: serverResponse2.bid.meta, - pubid: validBid2.params.pubid, - currency: DEFAULT_CURRENCY, - netRevenue: DEFAULT_NET_REVENUE, - ttl: DEFAULT_TTL, - }); - }); - }); - - describe('getUserSyncs', function () { - let syncOptions - beforeEach(function () { - syncOptions = { - enabledBidders: ['h12media'], - pixelEnabled: true, - iframeEnabled: true - } - }); - - it('should success with usersync pixel url', function () { - const result = { - type: 'image', - url: `https://cookiesync.3rdpartypartner.com/?3rdparty_partner_user_id={user_id}&partner_id=h12media&gdpr_applies=${bidderRequest.gdprConsent.gdprApplies}&gdpr_consent_string=${bidderRequest.gdprConsent.consentString}`, - }; - const syncs = spec.getUserSyncs(syncOptions, [{body: serverResponse}], bidderRequest.gdprConsent); - - expect(syncs).to.deep.include(result); - }); - - it('should success with usersync iframe url', function () { - const result = { - type: 'iframe', - url: `https://cookiesync.3rdpartypartner.com/?3rdparty_partner_user_id={user_id}&partner_id=h12media&gdpr_applies=${bidderRequest.gdprConsent.gdprApplies}&gdpr_consent_string=${bidderRequest.gdprConsent.consentString}`, - }; - const syncs = spec.getUserSyncs(syncOptions, [{body: serverResponse}], bidderRequest.gdprConsent); - - expect(syncs).to.deep.include(result); - }); - - it('should success without GDRP', function () { - const result = { - type: 'iframe', - url: `https://cookiesync.3rdpartypartner.com/?3rdparty_partner_user_id={user_id}&partner_id=h12media&gdpr_applies=false&gdpr_consent_string=`, - }; - - expect(spec.getUserSyncs(syncOptions, [{body: serverResponse}], null)).to.deep.include(result); - }); - - it('should success without usersync url', function () { - expect(spec.getUserSyncs(syncOptions, [{body: serverResponse2}], bidderRequest.gdprConsent)).to.deep.equal([]); - }); - - it('should return empty usersync on empty response', function () { - expect(spec.getUserSyncs(syncOptions, [{body: {}}])).to.deep.equal([]); - }); - }); -}); diff --git a/test/spec/modules/hadronAnalyticsAdapter_spec.js b/test/spec/modules/hadronAnalyticsAdapter_spec.js deleted file mode 100644 index 68e5bc3ae..000000000 --- a/test/spec/modules/hadronAnalyticsAdapter_spec.js +++ /dev/null @@ -1,60 +0,0 @@ -import adapterManager from '../../../src/adapterManager.js'; -import hadronAnalyticsAdapter from '../../../modules/hadronAnalyticsAdapter.js'; -import { expect } from 'chai'; -import * as events from '../../../src/events.js'; -import { EVENTS } from '../../../src/constants.js'; -import { generateUUID } from '../../../src/utils.js'; -import { server } from 'test/mocks/xhr.js'; - -describe('Hadron analytics adapter', () => { - beforeEach(() => { - hadronAnalyticsAdapter.enableAnalytics({ - options: { - partnerId: 12349, - eventsToTrack: ['auctionInit', 'auctionEnd', 'bidWon', - 'bidderDone', 'requestBids', 'addAdUnits', 'setTargeting', 'adRenderFailed', - 'bidResponse', 'bidTimeout', 'bidRequested', 'bidAdjustment', 'nonExistingEvent' - ], - } - }); - }); - - afterEach(() => { - hadronAnalyticsAdapter.disableAnalytics(); - }); - - it('registers itself with the adapter manager', () => { - const adapter = adapterManager.getAnalyticsAdapter('hadronAnalytics'); - expect(adapter).to.exist; - expect(adapter.gvlid).to.be.a('number'); - expect(adapter.adapter).to.equal(hadronAnalyticsAdapter); - }); - - it('tolerates undefined or empty config', () => { - hadronAnalyticsAdapter.enableAnalytics(undefined); - hadronAnalyticsAdapter.enableAnalytics({}); - }); - - it('sends auction end events to the backend', () => { - const auction = { - auctionId: generateUUID(), - adUnits: [{ - code: 'usr1234', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600], [728, 90]] - } - }, - adUnitCodes: ['usr1234'] - }], - }; - events.emit(EVENTS.AUCTION_END, auction); - assert(server.requests.length > 0) - const body = JSON.parse(server.requests[0].requestBody); - var eventTypes = []; - body.events.forEach(e => eventTypes.push(e.eventType)); - assert(eventTypes.length > 0) - assert(eventTypes.indexOf(EVENTS.AUCTION_END) > -1); - hadronAnalyticsAdapter.disableAnalytics(); - }); -}); diff --git a/test/spec/modules/hadronRtdProvider_spec.js b/test/spec/modules/hadronRtdProvider_spec.js deleted file mode 100644 index 8f535c37c..000000000 --- a/test/spec/modules/hadronRtdProvider_spec.js +++ /dev/null @@ -1,756 +0,0 @@ -import {config} from 'src/config.js'; -import { - HADRONID_LOCAL_NAME, - RTD_LOCAL_NAME, - addRealTimeData, - getRealTimeData, - hadronSubmodule, - storage -} from 'modules/hadronRtdProvider.js'; -import {server} from 'test/mocks/xhr.js'; - -const responseHeader = {'Content-Type': 'application/json'}; - -describe('hadronRtdProvider', function () { - let getDataFromLocalStorageStub; - - beforeEach(function () { - config.resetConfig(); - getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); - }); - - afterEach(function () { - getDataFromLocalStorageStub.restore(); - }); - - describe('hadronSubmodule', function () { - it('successfully instantiates', function () { - expect(hadronSubmodule.init()).to.equal(true); - }); - }); - - describe('Add Real-Time Data', function () { - it('merges ortb2 data', function () { - const rtdConfig = {}; - - const setConfigUserObj1 = { - name: 'www.dataprovider1.com', - ext: {taxonomyname: 'iab_audience_taxonomy'}, - segment: [{ - id: '1776' - }] - }; - - const setConfigUserObj2 = { - name: 'www.dataprovider2.com', - ext: {taxonomyname: 'iab_audience_taxonomy'}, - segment: [{ - id: '1914' - }] - }; - - const setConfigSiteObj1 = { - name: 'www.dataprovider3.com', - ext: { - taxonomyname: 'iab_audience_taxonomy' - }, - segment: [ - { - id: '1812' - }, - { - id: '1955' - } - ] - } - - const bidConfig = { - ortb2Fragments: { - global: { - user: { - data: [setConfigUserObj1, setConfigUserObj2] - }, - site: { - content: { - data: [setConfigSiteObj1] - } - } - } - } - }; - - const rtdUserObj1 = { - name: 'www.dataprovider4.com', - ext: { - taxonomyname: 'iab_audience_taxonomy' - }, - segment: [ - { - id: '1918' - }, - { - id: '1939' - } - ] - }; - - const rtdSiteObj1 = { - name: 'www.dataprovider5.com', - ext: { - taxonomyname: 'iab_audience_taxonomy' - }, - segment: [ - { - id: '1945' - }, - { - id: '2003' - } - ] - }; - - const rtd = { - ortb2: { - user: { - data: [rtdUserObj1] - }, - site: { - content: { - data: [rtdSiteObj1] - } - } - } - }; - - addRealTimeData(bidConfig, rtd, rtdConfig); - - const ortb2Config = bidConfig.ortb2Fragments.global; - - expect(ortb2Config.user.data).to.deep.include.members([setConfigUserObj1, setConfigUserObj2, rtdUserObj1]); - expect(ortb2Config.site.content.data).to.deep.include.members([setConfigSiteObj1, rtdSiteObj1]); - }); - - it('merges ortb2 data without duplication', function () { - const rtdConfig = {}; - - const userObj1 = { - name: 'www.dataprovider1.com', - ext: {taxonomyname: 'iab_audience_taxonomy'}, - segment: [{ - id: '1776' - }] - }; - - const userObj2 = { - name: 'www.dataprovider2.com', - ext: {taxonomyname: 'iab_audience_taxonomy'}, - segment: [{ - id: '1914' - }] - }; - - const siteObj1 = { - name: 'www.dataprovider3.com', - ext: { - taxonomyname: 'iab_audience_taxonomy' - }, - segment: [ - { - id: '1812' - }, - { - id: '1955' - } - ] - } - - const bidConfig = { - ortb2Fragments: { - global: { - user: { - data: [userObj1, userObj2] - }, - site: { - content: { - data: [siteObj1] - } - } - } - } - }; - - const rtd = { - ortb2: { - user: { - data: [userObj1] - }, - site: { - content: { - data: [siteObj1] - } - } - } - }; - - addRealTimeData(bidConfig, rtd, rtdConfig); - - const ortb2Config = bidConfig.ortb2Fragments.global; - - expect(ortb2Config.user.data).to.deep.include.members([userObj1, userObj2]); - expect(ortb2Config.site.content.data).to.deep.include.members([siteObj1]); - expect(ortb2Config.user.data).to.have.lengthOf(2); - expect(ortb2Config.site.content.data).to.have.lengthOf(1); - }); - - it('merges bidder-specific ortb2 data', function () { - const rtdConfig = {}; - - const configUserObj1 = { - name: 'www.dataprovider1.com', - ext: {segtax: 3}, - segment: [{ - id: '1776' - }] - }; - - const configUserObj2 = { - name: 'www.dataprovider2.com', - ext: {segtax: 3}, - segment: [{ - id: '1914' - }] - }; - - const configUserObj3 = { - name: 'www.dataprovider1.com', - ext: {segtax: 3}, - segment: [{ - id: '2003' - }] - }; - - const configSiteObj1 = { - name: 'www.dataprovider3.com', - ext: { - segtax: 1 - }, - segment: [ - { - id: '1812' - }, - { - id: '1955' - } - ] - }; - - const configSiteObj2 = { - name: 'www.dataprovider3.com', - ext: { - segtax: 1 - }, - segment: [ - { - id: '1812' - } - ] - }; - - const bidConfig = { - ortb2Fragments: { - bidder: { - adbuzz: { - user: { - data: [configUserObj1, configUserObj2] - }, - site: { - content: { - data: [configSiteObj1] - } - } - }, - pubvisage: { - user: { - data: [configUserObj3] - }, - site: { - content: { - data: [configSiteObj2] - } - } - } - } - } - }; - - const rtdUserObj1 = { - name: 'www.dataprovider4.com', - ext: { - segtax: 501 - }, - segment: [ - { - id: '1918' - }, - { - id: '1939' - } - ] - }; - - const rtdUserObj2 = { - name: 'www.dataprovider2.com', - ext: { - segtax: 502 - }, - segment: [ - { - id: '1939' - } - ] - }; - - const rtdSiteObj1 = { - name: 'www.dataprovider5.com', - ext: { - segtax: 1 - }, - segment: [ - { - id: '441' - }, - { - id: '442' - } - ] - }; - - const rtdSiteObj2 = { - name: 'www.dataprovider6.com', - ext: { - segtax: 2 - }, - segment: [ - { - id: '676' - } - ] - }; - - const rtd = { - ortb2b: { - adbuzz: { - ortb2: { - user: { - data: [rtdUserObj1] - }, - site: { - content: { - data: [rtdSiteObj1] - } - } - } - }, - pubvisage: { - ortb2: { - user: { - data: [rtdUserObj2] - }, - site: { - content: { - data: [rtdSiteObj2] - } - } - } - } - } - }; - - addRealTimeData(bidConfig, rtd, rtdConfig); - - let ortb2Config = bidConfig.ortb2Fragments.bidder.adbuzz; - - expect(ortb2Config.user.data).to.deep.include.members([configUserObj1, configUserObj2, rtdUserObj1]); - expect(ortb2Config.site.content.data).to.deep.include.members([configSiteObj1, rtdSiteObj1]); - - ortb2Config = bidConfig.ortb2Fragments.bidder.pubvisage; - - expect(ortb2Config.user.data).to.deep.include.members([configUserObj3, rtdUserObj2]); - expect(ortb2Config.site.content.data).to.deep.include.members([configSiteObj2, rtdSiteObj2]); - }); - - it('merges bidder-specific ortb2 data without duplication', function () { - const rtdConfig = {}; - - const userObj1 = { - name: 'www.dataprovider1.com', - ext: {segtax: 3}, - segment: [{ - id: '1776' - }] - }; - - const userObj2 = { - name: 'www.dataprovider2.com', - ext: {segtax: 3}, - segment: [{ - id: '1914' - }] - }; - - const userObj3 = { - name: 'www.dataprovider1.com', - ext: {segtax: 3}, - segment: [{ - id: '2003' - }] - }; - - const siteObj1 = { - name: 'www.dataprovider3.com', - ext: { - segtax: 1 - }, - segment: [ - { - id: '1812' - }, - { - id: '1955' - } - ] - }; - - const siteObj2 = { - name: 'www.dataprovider3.com', - ext: { - segtax: 1 - }, - segment: [ - { - id: '1812' - } - ] - }; - - const bidConfig = { - ortb2Fragments: { - bidder: { - adbuzz: { - user: { - data: [userObj1, userObj2] - }, - site: { - content: { - data: [siteObj1] - } - } - }, - pubvisage: { - user: { - data: [userObj3] - }, - site: { - content: { - data: [siteObj2] - } - } - } - } - } - }; - - const rtd = { - ortb2b: { - adbuzz: { - ortb2: { - user: { - data: [userObj1] - }, - site: { - content: { - data: [siteObj1] - } - } - } - }, - pubvisage: { - ortb2: { - user: { - data: [userObj2, userObj3] - }, - site: { - content: { - data: [siteObj1, siteObj2] - } - } - } - } - } - }; - - addRealTimeData(bidConfig, rtd, rtdConfig); - - let ortb2Config = bidConfig.ortb2Fragments.bidder.adbuzz; - - expect(ortb2Config.user.data).to.deep.include.members([userObj1]); - expect(ortb2Config.site.content.data).to.deep.include.members([siteObj1]); - - expect(ortb2Config.user.data).to.have.lengthOf(2); - expect(ortb2Config.site.content.data).to.have.lengthOf(1); - - ortb2Config = bidConfig.ortb2Fragments.bidder.pubvisage; - - expect(ortb2Config.user.data).to.deep.include.members([userObj3, userObj3]); - expect(ortb2Config.site.content.data).to.deep.include.members([siteObj1, siteObj2]); - - expect(ortb2Config.user.data).to.have.lengthOf(2); - expect(ortb2Config.site.content.data).to.have.lengthOf(2); - }); - - it('allows publisher defined rtd ortb2 logic', function () { - const rtdConfig = { - params: { - handleRtd: function (bidConfig, rtd, rtdConfig, pbConfig) { - if (String(rtd.ortb2.user.data[0].segment[0].id) === '1776') { - pbConfig.setConfig({ortb2: rtd.ortb2}); - } else { - pbConfig.setConfig({ortb2: {}}); - } - } - } - }; - - const bidConfig = {}; - - const rtdUserObj1 = { - name: 'www.dataprovider.com', - ext: {taxonomyname: 'iab_audience_taxonomy'}, - segment: [{ - id: '1776' - }] - }; - - let rtd = { - ortb2: { - user: { - data: [rtdUserObj1] - } - } - }; - - config.resetConfig(); - - let pbConfig = config.getConfig(); - addRealTimeData(bidConfig, rtd, rtdConfig); - expect(config.getConfig().ortb2.user.data).to.deep.include.members([rtdUserObj1]); - - const rtdUserObj2 = { - name: 'www.audigent.com', - ext: { - segtax: '1', - taxprovider: '1' - }, - segment: [{ - id: 'pubseg1' - }] - }; - - rtd = { - ortb2: { - user: { - data: [rtdUserObj2] - } - } - }; - - config.resetConfig(); - - pbConfig = config.getConfig(); - addRealTimeData(bidConfig, rtd, rtdConfig); - expect(config.getConfig().ortb2).to.deep.equal({}); - }); - - it('allows publisher defined adunit logic', function () { - const rtdConfig = { - params: { - handleRtd: function (bidConfig, rtd, rtdConfig, pbConfig) { - var adUnits = bidConfig.adUnits; - for (var i = 0; i < adUnits.length; i++) { - var adUnit = adUnits[i]; - for (var j = 0; j < adUnit.bids.length; j++) { - var bid = adUnit.bids[j]; - if (bid.bidder === 'adBuzz') { - for (var k = 0; k < rtd.adBuzz.length; k++) { - bid.adBuzzData.segments.adBuzz.push(rtd.adBuzz[k]); - } - } else if (bid.bidder === 'trueBid') { - for (var m = 0; m < rtd.trueBid.length; m++) { - bid.trueBidSegments.push(rtd.trueBid[m]); - } - } - } - } - } - } - }; - - const bidConfig = { - adUnits: [ - { - bids: [ - { - bidder: 'adBuzz', - adBuzzData: { - segments: { - adBuzz: [ - { - id: 'adBuzzSeg1' - } - ] - } - } - }, - { - bidder: 'trueBid', - trueBidSegments: [] - } - ] - } - ] - }; - - const rtd = { - adBuzz: [{id: 'adBuzzSeg2'}, {id: 'adBuzzSeg3'}], - trueBid: [{id: 'truebidSeg1'}, {id: 'truebidSeg2'}, {id: 'truebidSeg3'}] - }; - - addRealTimeData(bidConfig, rtd, rtdConfig); - - expect(bidConfig.adUnits[0].bids[0].adBuzzData.segments.adBuzz[0].id).to.equal('adBuzzSeg1'); - expect(bidConfig.adUnits[0].bids[0].adBuzzData.segments.adBuzz[1].id).to.equal('adBuzzSeg2'); - expect(bidConfig.adUnits[0].bids[0].adBuzzData.segments.adBuzz[2].id).to.equal('adBuzzSeg3'); - expect(bidConfig.adUnits[0].bids[1].trueBidSegments[0].id).to.equal('truebidSeg1'); - expect(bidConfig.adUnits[0].bids[1].trueBidSegments[1].id).to.equal('truebidSeg2'); - expect(bidConfig.adUnits[0].bids[1].trueBidSegments[2].id).to.equal('truebidSeg3'); - }); - }); - - describe('Get Real-Time Data', function () { - it('gets rtd from local storage cache', function () { - const rtdConfig = { - params: { - segmentCache: true - } - }; - - const bidConfig = {ortb2Fragments: {global: {}}}; - - const rtdUserObj1 = { - name: 'www.dataprovider3.com', - ext: { - taxonomyname: 'iab_audience_taxonomy' - }, - segment: [ - { - id: '1918' - }, - { - id: '1939' - } - ] - }; - - const cachedRtd = { - rtd: { - ortb2: { - user: { - data: [rtdUserObj1] - } - } - } - }; - - getDataFromLocalStorageStub.withArgs(RTD_LOCAL_NAME).returns(JSON.stringify(cachedRtd)); - getRealTimeData(bidConfig, () => { - expect(bidConfig.ortb2Fragments.global.user.data).to.deep.include.members([rtdUserObj1]); - }, rtdConfig, {}); - }); - - it('gets real-time data via async request', function () { - const setConfigSiteObj1 = { - name: 'www.audigent.com', - ext: { - segtax: '1', - taxprovider: '1' - }, - segment: [ - { - id: 'pubseg1' - }, - { - id: 'pubseg2' - } - ] - } - - const rtdConfig = { - params: { - segmentCache: false, - usePubHadron: true, - requestParams: { - publisherId: 'testPub1' - } - } - }; - - const bidConfig = { - ortb2Fragments: { - global: { - site: { - content: { - data: [setConfigSiteObj1] - } - } - } - } - }; - - const rtdUserObj1 = { - name: 'www.audigent.com', - ext: { - segtax: '1', - taxprovider: '1' - }, - segment: [ - { - id: 'pubseg1' - }, - { - id: 'pubseg2' - } - ] - }; - - const data = { - rtd: { - ortb2: { - user: { - data: [rtdUserObj1] - } - } - } - }; - - getDataFromLocalStorageStub.withArgs(HADRONID_LOCAL_NAME).returns('testHadronId1'); - getRealTimeData(bidConfig, () => { - const request = server.requests[0]; - const postData = JSON.parse(request.requestBody); - expect(postData.config).to.have.deep.property('publisherId', 'testPub1'); - expect(postData.userIds).to.have.deep.property('hadronId', 'testHadronId1'); - request.respond(200, responseHeader, JSON.stringify(data)); - expect(bidConfig.ortb2Fragments.global.user.data).to.deep.include.members([rtdUserObj1]); - }, rtdConfig, {}); - }); - }); -}); diff --git a/test/spec/modules/holidBidAdapter_spec.js b/test/spec/modules/holidBidAdapter_spec.js deleted file mode 100644 index 671427d34..000000000 --- a/test/spec/modules/holidBidAdapter_spec.js +++ /dev/null @@ -1,216 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/holidBidAdapter.js'; - -describe('holidBidAdapterTests', () => { - const bidderRequest = { - bidderRequestId: 'test-id' - }; - - const bidRequestData = { - bidder: 'holid', - adUnitCode: 'test-div', - bidId: 'bid-id', - params: { adUnitID: '12345' }, - mediaTypes: { banner: {} }, - sizes: [[300, 250]], - ortb2: { - site: { - publisher: { - domain: 'https://foo.bar', - } - }, - regs: { - gdpr: 1, - }, - user: { - ext: { - consent: 'G4ll0p1ng_Un1c0rn5', - } - }, - device: { - h: 410, - w: 1860, - } - } - }; - - describe('isBidRequestValid', () => { - const bid = JSON.parse(JSON.stringify(bidRequestData)); - - it('should return true', () => { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', () => { - const bid = JSON.parse(JSON.stringify(bidRequestData)); - delete bid.params.adUnitID; - - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', () => { - const bid = JSON.parse(JSON.stringify(bidRequestData)); - const request = spec.buildRequests([bid], bidderRequest); - const payload = JSON.parse(request[0].data); - - it('should include id in request', () => { - expect(payload.id).to.equal('test-id'); - }); - - it('should include ext in imp', () => { - expect(payload.imp[0].ext).to.deep.equal({ - prebid: { storedrequest: { id: '12345' } }, - }); - }); - - it('should include ext in request', () => { - expect(payload.ext).to.deep.equal({ - prebid: { storedrequest: { id: '12345' } }, - }); - }); - - it('should include banner format in imp', () => { - expect(payload.imp[0].banner).to.deep.equal({ - format: [{ w: 300, h: 250 }], - }); - }); - - it('should include ortb2 first party data', () => { - expect(payload.device.w).to.equal(1860); - expect(payload.device.h).to.equal(410); - expect(payload.user.ext.consent).to.equal('G4ll0p1ng_Un1c0rn5'); - expect(payload.regs.gdpr).to.equal(1); - }); - }); - - describe('interpretResponse', () => { - // Add impid: 'bid-id' so requestId matches bidRequestData.bidId - const serverResponse = { - body: { - id: 'test-id', - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: 'testbidid', - impid: 'bid-id', - price: 0.4, - adm: 'test-ad', - adid: 789456, - crid: 1234, - w: 300, - h: 250, - }, - ], - }, - ], - }, - }; - - const interpretedResponse = spec.interpretResponse(serverResponse, bidRequestData); - - it('should interpret response', () => { - expect(interpretedResponse[0].requestId).to.equal(bidRequestData.bidId); - expect(interpretedResponse[0].cpm).to.equal( - serverResponse.body.seatbid[0].bid[0].price - ); - expect(interpretedResponse[0].ad).to.equal( - serverResponse.body.seatbid[0].bid[0].adm - ); - expect(interpretedResponse[0].creativeId).to.equal( - serverResponse.body.seatbid[0].bid[0].crid - ); - expect(interpretedResponse[0].width).to.equal( - serverResponse.body.seatbid[0].bid[0].w - ); - expect(interpretedResponse[0].height).to.equal( - serverResponse.body.seatbid[0].bid[0].h - ); - expect(interpretedResponse[0].currency).to.equal(serverResponse.body.cur); - }); - }); - - describe('getUserSyncs', () => { - it('should return user sync', () => { - const optionsType = { - iframeEnabled: true, - pixelEnabled: true, - }; - const serverResponse = [ - { - body: { - ext: { - responsetimemillis: { - 'test seat 1': 2, - 'test seat 2': 1, - }, - }, - }, - }, - ]; - const gdprConsent = { - gdprApplies: 1, - consentString: 'dkj49Sjmfjuj34as:12jaf90123hufabidfy9u23brfpoig', - }; - const uspConsent = 'mkjvbiniwot4827obfoy8sdg8203gb'; - - // Updated 'usp_consent' to 'us_privacy' to match adapter code - const expectedUserSyncs = [ - { - type: 'image', - url: 'https://track.adform.net/Serving/TrackPoint/?pm=2992097&lid=132720821', - }, - { - type: 'iframe', - url: 'https://null.holid.io/sync.html?bidders=%5B%22test%20seat%201%22%2C%22test%20seat%202%22%5D&gdpr=1&gdpr_consent=dkj49Sjmfjuj34as%3A12jaf90123hufabidfy9u23brfpoig&us_privacy=mkjvbiniwot4827obfoy8sdg8203gb&type=iframe', - }, - ]; - - const userSyncs = spec.getUserSyncs( - optionsType, - serverResponse, - gdprConsent, - uspConsent - ); - - expect(userSyncs).to.deep.equal(expectedUserSyncs); - }); - - it('should return base user syncs when responsetimemillis is not defined', () => { - const optionsType = { - iframeEnabled: true, - pixelEnabled: true, - }; - const serverResponse = [ - { - body: { - ext: {}, - }, - }, - ]; - const gdprConsent = { - gdprApplies: 1, - consentString: 'dkj49Sjmfjuj34as:12jaf90123hufabidfy9u23brfpoig', - }; - const uspConsent = 'mkjvbiniwot4827obfoy8sdg8203gb'; - - const expectedUserSyncs = [ - { - type: 'image', - url: 'https://track.adform.net/Serving/TrackPoint/?pm=2992097&lid=132720821', - }, - ]; - - const userSyncs = spec.getUserSyncs( - optionsType, - serverResponse, - gdprConsent, - uspConsent - ); - - expect(userSyncs).to.deep.equal(expectedUserSyncs); - }); - }); -}); diff --git a/test/spec/modules/humansecurityMalvDefenseRtdProvider_spec.js b/test/spec/modules/humansecurityMalvDefenseRtdProvider_spec.js deleted file mode 100644 index 4b9c66fd2..000000000 --- a/test/spec/modules/humansecurityMalvDefenseRtdProvider_spec.js +++ /dev/null @@ -1,211 +0,0 @@ -import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; -import * as utils from '../../../src/utils.js'; -import * as hook from '../../../src/hook.js' -import * as events from '../../../src/events.js'; -import { EVENTS } from '../../../src/constants.js'; - -import { __TEST__ } from '../../../modules/humansecurityMalvDefenseRtdProvider.js'; -import { MODULE_TYPE_RTD } from '../../../src/activities/modules.js'; - -const { - readConfig, - ConfigError, - pageInitStepPreloadScript, - pageInitStepProtectPage, - bidWrapStepAugmentHtml, - bidWrapStepProtectByWrapping, - beforeInit -} = __TEST__; - -sinon.assert.expose(chai.assert, { prefix: 'sinon' }); - -const fakeScriptURL = 'https://example.com/script.js'; - -function makeFakeBidResponse() { - return { - ad: 'hello ad', - bidderCode: 'BIDDER', - creativeId: 'CREATIVE', - cpm: 1.23, - }; -} - -describe('humansecurityMalvDefense RTD module', function () { - describe('readConfig()', function() { - it('should throw ConfigError on invalid configurations', function() { - expect(() => readConfig({})).to.throw(ConfigError); - expect(() => readConfig({ params: {} })).to.throw(ConfigError); - expect(() => readConfig({ params: { protectionMode: 'bids' } })).to.throw(ConfigError); - expect(() => readConfig({ params: { cdnUrl: 'abc' } })).to.throw(ConfigError); - expect(() => readConfig({ params: { cdnUrl: 'abc', protectionMode: 'bids' } })).to.throw(ConfigError); - expect(() => readConfig({ params: { cdnUrl: 'https://cadmus.script.ac/abc1234567890/script.js', protectionMode: '123' } })).to.throw(ConfigError); - }); - - it('should accept valid configurations', function() { - expect(() => readConfig({ params: { cdnUrl: 'https://cadmus.script.ac/abc1234567890/script.js', protectionMode: 'full' } })).to.not.throw(); - expect(() => readConfig({ params: { cdnUrl: 'https://cadmus.script.ac/abc1234567890/script.js', protectionMode: 'bids' } })).to.not.throw(); - expect(() => readConfig({ params: { cdnUrl: 'https://cadmus.script.ac/abc1234567890/script.js', protectionMode: 'bids-nowait' } })).to.not.throw(); - }); - }); - - describe('Module initialization step', function() { - let insertElementStub; - beforeEach(function() { - insertElementStub = sinon.stub(utils, 'insertElement'); - }); - afterEach(function() { - utils.insertElement.restore(); - }); - - it('pageInitStepPreloadScript() should insert link/preload element', function() { - pageInitStepPreloadScript(fakeScriptURL); - - sinon.assert.calledOnce(insertElementStub); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.tagName === 'LINK')); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.rel === 'preload')); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.as === 'script')); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.href === fakeScriptURL)); - }); - - it('pageInitStepProtectPage() should insert script element', function() { - pageInitStepProtectPage(fakeScriptURL, 'humansecurityMalvDefense'); - - sinon.assert.calledOnce(loadExternalScriptStub); - sinon.assert.calledWith(loadExternalScriptStub, fakeScriptURL, MODULE_TYPE_RTD, 'humansecurityMalvDefense'); - }); - }); - - function ensurePrependToBidResponse(fakeBidResponse) { - expect(fakeBidResponse).to.have.own.property('ad').which.is.a('string'); - expect(fakeBidResponse.ad).to.contain(''); - } - - function ensureWrapBidResponse(fakeBidResponse, scriptUrl) { - expect(fakeBidResponse).to.have.own.property('ad').which.is.a('string'); - expect(fakeBidResponse.ad).to.contain(`src="${scriptUrl}"`); - expect(fakeBidResponse.ad).to.contain('agent.put(ad)'); - } - - describe('Bid processing step', function() { - it('bidWrapStepAugmentHtml() should prepend bid-specific information in a comment', function() { - const fakeBidResponse = makeFakeBidResponse(); - bidWrapStepAugmentHtml(fakeBidResponse); - ensurePrependToBidResponse(fakeBidResponse); - }); - - it('bidWrapStepProtectByWrapping() should wrap payload into a script tag', function() { - const fakeBidResponse = makeFakeBidResponse(); - bidWrapStepProtectByWrapping(fakeScriptURL, 0, fakeBidResponse); - ensureWrapBidResponse(fakeBidResponse, fakeScriptURL); - }); - }); - - describe('Submodule execution', function() { - let submoduleStub; - let insertElementStub; - beforeEach(function () { - submoduleStub = sinon.stub(hook, 'submodule'); - insertElementStub = sinon.stub(utils, 'insertElement'); - }); - afterEach(function () { - utils.insertElement.restore(); - submoduleStub.restore(); - }); - - function getModule() { - beforeInit('humansecurityMalvDefense'); - - expect(submoduleStub.calledOnceWith('realTimeData')).to.equal(true); - - const registeredSubmoduleDefinition = submoduleStub.getCall(0).args[1]; - expect(registeredSubmoduleDefinition).to.be.an('object'); - expect(registeredSubmoduleDefinition).to.have.own.property('name', 'humansecurityMalvDefense'); - expect(registeredSubmoduleDefinition).to.have.own.property('init').that.is.a('function'); - expect(registeredSubmoduleDefinition).to.have.own.property('onBidResponseEvent').that.is.a('function'); - - return registeredSubmoduleDefinition; - } - - it('should register humansecurityMalvDefense RTD submodule provider', function () { - getModule(); - }); - - it('should refuse initialization with incorrect parameters', function () { - const { init } = getModule(); - expect(init({ params: { cdnUrl: 'abc', protectionMode: 'full' } }, {})).to.equal(false); // too short distribution name - sinon.assert.notCalled(loadExternalScriptStub); - }); - - it('should initialize in full (page) protection mode', function () { - const { init, onBidResponseEvent } = getModule(); - expect(init({ params: { cdnUrl: 'https://cadmus.script.ac/abc1234567890/script.js', protectionMode: 'full' } }, {})).to.equal(true); - sinon.assert.calledOnce(loadExternalScriptStub); - sinon.assert.calledWith(loadExternalScriptStub, 'https://cadmus.script.ac/abc1234567890/script.js', MODULE_TYPE_RTD, 'humansecurityMalvDefense'); - - const fakeBidResponse = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse, {}, {}); - ensurePrependToBidResponse(fakeBidResponse); - }); - - it('should iniitalize in bids (frame) protection mode', function () { - const { init, onBidResponseEvent } = getModule(); - expect(init({ params: { cdnUrl: 'https://cadmus.script.ac/abc1234567890/script.js', protectionMode: 'bids' } }, {})).to.equal(true); - sinon.assert.calledOnce(insertElementStub); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.tagName === 'LINK')); - - const fakeBidResponse = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse, {}, {}); - ensureWrapBidResponse(fakeBidResponse, 'https://cadmus.script.ac/abc1234567890/script.js'); - }); - - it('should respect preload status in bids-nowait protection mode', function () { - const { init, onBidResponseEvent } = getModule(); - expect(init({ params: { cdnUrl: 'https://cadmus.script.ac/abc1234567890/script.js', protectionMode: 'bids-nowait' } }, {})).to.equal(true); - sinon.assert.calledOnce(insertElementStub); - sinon.assert.calledWith(insertElementStub, sinon.match(elem => elem.tagName === 'LINK')); - const preloadLink = insertElementStub.getCall(0).args[0]; - expect(preloadLink).to.have.property('onload').which.is.a('function'); - expect(preloadLink).to.have.property('onerror').which.is.a('function'); - - const fakeBidResponse1 = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse1, {}, {}); - ensurePrependToBidResponse(fakeBidResponse1); - - // Simulate successful preloading - preloadLink.onload(); - - const fakeBidResponse2 = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse2, {}, {}); - ensureWrapBidResponse(fakeBidResponse2, 'https://cadmus.script.ac/abc1234567890/script.js'); - - // Simulate error - preloadLink.onerror(); - - // Now we should fallback to just prepending - const fakeBidResponse3 = makeFakeBidResponse(); - onBidResponseEvent(fakeBidResponse3, {}, {}); - ensurePrependToBidResponse(fakeBidResponse3); - }); - - it('should send billable event per bid won event', function () { - const { init } = getModule(); - expect(init({ params: { cdnUrl: 'https://cadmus.script.ac/abc1234567890/script.js', protectionMode: 'full' } }, {})).to.equal(true); - - const eventCounter = { registerHumansecurityMalvDefenseBillingEvent: function() {} }; - sinon.spy(eventCounter, 'registerHumansecurityMalvDefenseBillingEvent'); - - events.on(EVENTS.BILLABLE_EVENT, (evt) => { - if (evt.vendor === 'humansecurityMalvDefense') { - eventCounter.registerHumansecurityMalvDefenseBillingEvent() - } - }); - - events.emit(EVENTS.BID_WON, {}); - events.emit(EVENTS.BID_WON, {}); - events.emit(EVENTS.BID_WON, {}); - events.emit(EVENTS.BID_WON, {}); - - sinon.assert.callCount(eventCounter.registerHumansecurityMalvDefenseBillingEvent, 4); - }); - }); -}); diff --git a/test/spec/modules/humansecurityRtdProvider_spec.js b/test/spec/modules/humansecurityRtdProvider_spec.js deleted file mode 100644 index c6ad163c5..000000000 --- a/test/spec/modules/humansecurityRtdProvider_spec.js +++ /dev/null @@ -1,210 +0,0 @@ -import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; - -import * as utils from '../../../src/utils.js'; -import * as hook from '../../../src/hook.js'; -import * as refererDetection from '../../../src/refererDetection.js'; - -import { __TEST__ } from '../../../modules/humansecurityRtdProvider.js'; - -const { - SUBMODULE_NAME, - SCRIPT_URL, - main, - load, - onImplLoaded, - onImplMessage, - onGetBidRequestData -} = __TEST__; - -describe('humansecurity RTD module', function () { - let sandbox; - - const stubUuid = 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee'; - const sonarStubId = `sonar_${stubUuid}`; - const stubWindow = { [sonarStubId]: undefined }; - - beforeEach(function() { - sandbox = sinon.createSandbox(); - sandbox.stub(utils, 'getWindowSelf').returns(stubWindow); - sandbox.stub(utils, 'generateUUID').returns(stubUuid); - sandbox.stub(refererDetection, 'getRefererInfo').returns({ domain: 'example.com' }); - }); - afterEach(function() { - sandbox.restore(); - }); - - describe('Initialization step', function () { - let sandbox2; - let connectSpy; - beforeEach(function() { - sandbox2 = sinon.createSandbox(); - connectSpy = sandbox.spy(); - // Once the impl script is loaded, it registers the API using session ID - sandbox2.stub(stubWindow, sonarStubId).value({ connect: connectSpy }); - }); - afterEach(function () { - sandbox2.restore(); - }); - - it('should accept valid configurations', function () { - // Default configuration - empty - expect(() => load({})).to.not.throw(); - expect(() => load({ params: {} })).to.not.throw(); - // Configuration with clientId - expect(() => load({ params: { clientId: 'customer123' } })).to.not.throw(); - }); - - it('should throw an Error on invalid configuration', function () { - expect(() => load({ params: { clientId: 123 } })).to.throw(); - expect(() => load({ params: { clientId: 'abc.def' } })).to.throw(); - expect(() => load({ params: { clientId: '1' } })).to.throw(); - expect(() => load({ params: { clientId: '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ' } })).to.throw(); - }); - - it('should insert implementation script', () => { - load({ }); - - expect(loadExternalScriptStub.calledOnce).to.be.true; - - const args = loadExternalScriptStub.getCall(0).args; - expect(args[0]).to.be.equal(`${SCRIPT_URL}?r=example.com`); - expect(args[2]).to.be.equal(SUBMODULE_NAME); - expect(args[3]).to.be.equal(onImplLoaded); - expect(args[4]).to.be.equal(null); - expect(args[5]).to.be.deep.equal({ 'data-sid': 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee' }); - }); - - it('should insert external script element with "customerId" info from config', () => { - load({ params: { clientId: 'customer123' } }); - - expect(loadExternalScriptStub.calledOnce).to.be.true; - - const args = loadExternalScriptStub.getCall(0).args; - expect(args[0]).to.be.equal(`${SCRIPT_URL}?r=example.com&c=customer123`); - }); - - it('should connect to the implementation script once it loads', function () { - load({ }); - - expect(loadExternalScriptStub.calledOnce).to.be.true; - expect(connectSpy.calledOnce).to.be.true; - - const args = connectSpy.getCall(0).args; - expect(args[0]).to.haveOwnProperty('cmd'); // pbjs global - expect(args[0]).to.haveOwnProperty('que'); - expect(args[1]).to.be.equal(onImplMessage); - }); - }); - - describe('Bid enrichment step', function () { - const hmnsData = { 'v1': 'sometoken' }; - - let sandbox2; - let callbackSpy; - let reqBidsConfig; - beforeEach(function() { - sandbox2 = sinon.createSandbox(); - callbackSpy = sandbox2.spy(); - reqBidsConfig = { ortb2Fragments: { bidder: {}, global: {} } }; - }); - afterEach(function () { - sandbox2.restore(); - }); - - it('should add empty device.ext.hmns to global ortb2 when data is yet to be received from the impl script', () => { - load({ }); - - onGetBidRequestData(reqBidsConfig, callbackSpy, { params: {} }, {}); - - expect(callbackSpy.calledOnce).to.be.true; - expect(reqBidsConfig.ortb2Fragments.global).to.have.own.property('device'); - expect(reqBidsConfig.ortb2Fragments.global.device).to.have.own.property('ext'); - expect(reqBidsConfig.ortb2Fragments.global.device.ext).to.have.own.property('hmns').which.is.an('object').that.deep.equals({}); - }); - - it('should add the default device.ext.hmns to global ortb2 when no "hmns" data was yet received', () => { - load({ }); - - onImplMessage({ type: 'info', data: 'not a hmns message' }); - onGetBidRequestData(reqBidsConfig, callbackSpy, { params: {} }, {}); - - expect(callbackSpy.calledOnce).to.be.true; - expect(reqBidsConfig.ortb2Fragments.global).to.have.own.property('device'); - expect(reqBidsConfig.ortb2Fragments.global.device).to.have.own.property('ext'); - expect(reqBidsConfig.ortb2Fragments.global.device.ext).to.have.own.property('hmns').which.is.an('object').that.deep.equals({}); - }); - - it('should add device.ext.hmns with received tokens to global ortb2 when the data was received', () => { - load({ }); - - onImplMessage({ type: 'hmns', data: hmnsData }); - onGetBidRequestData(reqBidsConfig, callbackSpy, { params: {} }, {}); - - expect(callbackSpy.calledOnce).to.be.true; - expect(reqBidsConfig.ortb2Fragments.global).to.have.own.property('device'); - expect(reqBidsConfig.ortb2Fragments.global.device).to.have.own.property('ext'); - expect(reqBidsConfig.ortb2Fragments.global.device.ext).to.have.own.property('hmns').which.is.an('object').that.deep.equals(hmnsData); - }); - - it('should update device.ext.hmns with new data', () => { - load({ }); - - onImplMessage({ type: 'hmns', data: { 'v1': 'should be overwritten' } }); - onImplMessage({ type: 'hmns', data: hmnsData }); - onGetBidRequestData(reqBidsConfig, callbackSpy, { params: {} }, {}); - - expect(callbackSpy.calledOnce).to.be.true; - expect(reqBidsConfig.ortb2Fragments.global).to.have.own.property('device'); - expect(reqBidsConfig.ortb2Fragments.global.device).to.have.own.property('ext'); - expect(reqBidsConfig.ortb2Fragments.global.device.ext).to.have.own.property('hmns').which.is.an('object').that.deep.equals(hmnsData); - }); - }); - - describe('Sumbodule execution', function() { - let sandbox2; - let submoduleStub; - beforeEach(function() { - sandbox2 = sinon.createSandbox(); - submoduleStub = sandbox2.stub(hook, 'submodule'); - }); - afterEach(function () { - sandbox2.restore(); - }); - - function getModule() { - main(); - - expect(submoduleStub.calledOnceWith('realTimeData')).to.equal(true); - - const submoduleDef = submoduleStub.getCall(0).args[1]; - expect(submoduleDef).to.be.an('object'); - expect(submoduleDef).to.have.own.property('name', SUBMODULE_NAME); - expect(submoduleDef).to.have.own.property('init').that.is.a('function'); - expect(submoduleDef).to.have.own.property('getBidRequestData').that.is.a('function'); - - return submoduleDef; - } - - it('should register humansecurity RTD submodule provider', function () { - getModule(); - }); - - it('should refuse initialization on invalid customer id configuration', function () { - const { init } = getModule(); - expect(init({ params: { clientId: 123 } })).to.equal(false); - expect(loadExternalScriptStub.notCalled).to.be.true; - }); - - it('should commence initialization on valid initialization', function () { - const { init } = getModule(); - expect(init({ params: { clientId: 'customer123' } })).to.equal(true); - expect(loadExternalScriptStub.calledOnce).to.be.true; - }); - - it('should commence initialization on default initialization', function () { - const { init } = getModule(); - expect(init({ })).to.equal(true); - expect(loadExternalScriptStub.calledOnce).to.be.true; - }); - }); -}); diff --git a/test/spec/modules/hybridBidAdapter_spec.js b/test/spec/modules/hybridBidAdapter_spec.js deleted file mode 100644 index a0d479fb4..000000000 --- a/test/spec/modules/hybridBidAdapter_spec.js +++ /dev/null @@ -1,343 +0,0 @@ -import { expect } from 'chai' -import { spec } from 'modules/hybridBidAdapter.js' - -function getSlotConfigs(mediaTypes, params) { - return { - params: params, - sizes: [], - bidId: '2df8c0733f284e', - bidder: 'hybrid', - mediaTypes: mediaTypes, - ortb2Imp: { - ext: { - tid: '31a58515-3634-4e90-9c96-f86196db1459' - } - } - } -} - -describe('Hybrid.ai Adapter', function() { - const PLACE_ID = '5af45ad34d506ee7acad0c26'; - const bidderRequest = { - refererInfo: { page: 'referer' } - } - const bannerMandatoryParams = { - placeId: PLACE_ID, - placement: 'banner' - } - const videoMandatoryParams = { - placeId: PLACE_ID, - placement: 'video' - } - const inImageMandatoryParams = { - placeId: PLACE_ID, - placement: 'inImage', - imageUrl: 'https://hybrid.ai/images/image.jpg' - } - const validBidRequests = [ - getSlotConfigs({ banner: {} }, bannerMandatoryParams), - getSlotConfigs({ video: {playerSize: [[640, 480]], context: 'outstream'} }, videoMandatoryParams), - getSlotConfigs({ banner: {sizes: [0, 0]} }, inImageMandatoryParams) - ] - describe('isBidRequestValid method', function() { - describe('returns true', function() { - describe('when banner slot config has all mandatory params', () => { - describe('and banner placement has the correct value', function() { - const slotConfig = getSlotConfigs( - {banner: {}}, - { - placeId: PLACE_ID, - placement: 'banner' - } - ) - const isBidRequestValid = spec.isBidRequestValid(slotConfig) - expect(isBidRequestValid).to.equal(true) - }) - describe('and In-Image placement has the correct value', function() { - const slotConfig = getSlotConfigs( - { - banner: { - sizes: [[0, 0]] - } - }, - { - placeId: PLACE_ID, - placement: 'inImage', - imageUrl: 'imageUrl' - } - ) - const isBidRequestValid = spec.isBidRequestValid(slotConfig) - expect(isBidRequestValid).to.equal(true) - }) - describe('when video slot has all mandatory params.', function() { - it('should return true, when video mediatype object are correct.', function() { - const slotConfig = getSlotConfigs( - { - video: { - context: 'instream', - playerSize: [[640, 480]] - } - }, - { - placeId: PLACE_ID, - placement: 'video' - } - ) - const isBidRequestValid = spec.isBidRequestValid(slotConfig) - expect(isBidRequestValid).to.equal(true) - }) - }) - }) - }) - describe('returns false', function() { - describe('when params are not correct', function() { - function createSlotconfig(params) { - return getSlotConfigs({ banner: {} }, params) - } - it('does not have the placeId.', function() { - const isBidRequestValid = spec.isBidRequestValid( - createSlotconfig({ - placement: 'banner' - }) - ) - expect(isBidRequestValid).to.equal(false) - }) - it('does not have the placement.', function() { - const isBidRequestValid = spec.isBidRequestValid( - createSlotconfig({ - placeId: PLACE_ID - }) - ) - expect(isBidRequestValid).to.equal(false) - }) - it('does not have the imageUrl.', function() { - const isBidRequestValid = spec.isBidRequestValid( - createSlotconfig({ - placeId: PLACE_ID, - placement: 'inImage' - }) - ) - expect(isBidRequestValid).to.equal(false) - }) - it('does not have a the correct placement.', function() { - const isBidRequestValid = spec.isBidRequestValid( - createSlotconfig({ - placeId: PLACE_ID, - placement: 'something' - }) - ) - expect(isBidRequestValid).to.equal(false) - }) - }) - describe('when video mediaType object is not correct.', function() { - function createVideoSlotconfig(mediaType) { - return getSlotConfigs(mediaType, { - placeId: PLACE_ID, - placement: 'video' - }) - } - it('is a void object', function() { - const isBidRequestValid = spec.isBidRequestValid( - createVideoSlotconfig({ video: {} }) - ) - expect(isBidRequestValid).to.equal(false) - }) - it('does not have playerSize.', function() { - const isBidRequestValid = spec.isBidRequestValid( - createVideoSlotconfig({ video: { context: 'instream' } }) - ) - expect(isBidRequestValid).to.equal(false) - }) - it('does not have context', function() { - const isBidRequestValid = spec.isBidRequestValid( - createVideoSlotconfig({ - video: { - playerSize: [[640, 480]] - } - }) - ) - expect(isBidRequestValid).to.equal(false) - }) - }) - }) - }) - it('Url params should be correct ', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest) - expect(request.method).to.equal('POST') - expect(request.url).to.equal('https://hbe198.hybrid.ai/prebidhb') - }) - - describe('buildRequests method', function() { - it('Common data request should be correct', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - expect(Array.isArray(data.bidRequests)).to.equal(true) - expect(data.url).to.equal('referer') - data.bidRequests.forEach(bid => { - expect(bid.bidId).to.equal('2df8c0733f284e') - expect(bid.placeId).to.equal(PLACE_ID) - expect(bid.transactionId).to.equal('31a58515-3634-4e90-9c96-f86196db1459') - }) - }) - - describe('GDPR params', function() { - describe('when there are not consent management platform', function() { - it('cmp should be false', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - expect(data.cmp).to.equal(false) - }) - }) - describe('when there are consent management platform', function() { - it('cmps should be true and ga should not sended, when gdprApplies is undefined', function() { - bidderRequest['gdprConsent'] = { - gdprApplies: undefined, - consentString: 'consentString' - } - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - expect(data.cmp).to.equal(true) - expect(Object.keys(data).indexOf('data')).to.equal(-1) - expect(data.cs).to.equal('consentString') - }) - it('cmps should be true and all gdpr parameters should be sended, when there are gdprApplies', function() { - bidderRequest['gdprConsent'] = { - gdprApplies: true, - consentString: 'consentString' - } - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - expect(data.cmp).to.equal(true) - expect(data.ga).to.equal(true) - expect(data.cs).to.equal('consentString') - }) - }) - }) - - describe('BidRequests params', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest) - const data = JSON.parse(request.data) - const bidRequests = data.bidRequests - it('should request a Banner', function() { - const bannerBid = bidRequests[0] - expect(bannerBid.placement).to.equal(spec.placementTypes[bannerMandatoryParams.placement]) - }) - it('should request a Video', function() { - const bannerBid = bidRequests[1] - expect(bannerBid.placement).to.equal(spec.placementTypes[videoMandatoryParams.placement]) - }) - }) - }) - - describe('interpret response method', function() { - it('should return a void array, when the server response are not correct.', function() { - const request = { data: JSON.stringify({}) } - const serverResponse = { - body: {} - } - const bids = spec.interpretResponse(serverResponse, request) - expect(typeof bids).to.equal('object') - expect(bids.length).to.equal(0) - }) - it('should return a void array, when the server response have not got bids.', function() { - const request = { data: JSON.stringify({}) } - const serverResponse = { body: { bids: [] } } - const bids = spec.interpretResponse(serverResponse, request) - expect(typeof bids).to.equal('object') - expect(bids.length).to.equal(0) - }) - describe('when the server response return a bid', function() { - describe('the bid is a banner', function() { - it('should return a banner bid', function() { - const request = spec.buildRequests([validBidRequests[0]], bidderRequest) - const serverResponse = { - body: { - bids: [ - { - bidId: '2df8c0733f284e', - price: 0.5, - currency: 'USD', - content: 'html', - width: 100, - height: 100, - advertiserDomains: ['hybrid.ai'] - } - ] - } - } - const bids = spec.interpretResponse(serverResponse, request) - expect(bids.length).to.equal(1) - expect(bids[0].requestId).to.equal('2df8c0733f284e') - expect(bids[0].mediaType).to.equal(spec.supportedMediaTypes[0]) - expect(bids[0].cpm).to.equal(0.5) - expect(bids[0].width).to.equal(100) - expect(bids[0].height).to.equal(100) - expect(bids[0].currency).to.equal('USD') - expect(bids[0].netRevenue).to.equal(true) - expect(bids[0].meta.advertiserDomains).to.deep.equal(['hybrid.ai']) - expect(typeof bids[0].ad).to.equal('string') - }) - it('should return a In-Image bid', function() { - const request = spec.buildRequests([validBidRequests[2]], bidderRequest) - const serverResponse = { - body: { - bids: [ - { - bidId: '2df8c0733f284e', - price: 0.5, - currency: 'USD', - content: 'html', - inImage: { - actionUrls: {} - }, - width: 100, - height: 100, - ttl: 360 - } - ] - } - } - const bids = spec.interpretResponse(serverResponse, request) - expect(bids.length).to.equal(1) - expect(bids[0].requestId).to.equal('2df8c0733f284e') - expect(bids[0].cpm).to.equal(0.5) - expect(bids[0].width).to.equal(100) - expect(bids[0].height).to.equal(100) - expect(bids[0].currency).to.equal('USD') - expect(bids[0].netRevenue).to.equal(true) - expect(typeof bids[0].ad).to.equal('string') - }) - }) - describe('the bid is a video', function() { - it('should return a video bid', function() { - const request = spec.buildRequests([validBidRequests[1]], bidderRequest) - const serverResponse = { - body: { - bids: [ - { - bidId: '2df8c0733f284e', - price: 0.5, - currency: 'USD', - content: 'html', - width: 100, - height: 100, - transactionId: '31a58515-3634-4e90-9c96-f86196db1459' - } - ] - } - } - const bids = spec.interpretResponse(serverResponse, request) - expect(bids.length).to.equal(1) - expect(bids[0].requestId).to.equal('2df8c0733f284e') - expect(bids[0].mediaType).to.equal(spec.supportedMediaTypes[1]) - expect(bids[0].cpm).to.equal(0.5) - expect(bids[0].width).to.equal(100) - expect(bids[0].height).to.equal(100) - expect(bids[0].currency).to.equal('USD') - expect(bids[0].netRevenue).to.equal(true) - expect(typeof bids[0].vastXml).to.equal('string') - }) - }) - }) - }) -}) diff --git a/test/spec/modules/hypelabBidAdapter_spec.js b/test/spec/modules/hypelabBidAdapter_spec.js deleted file mode 100644 index d6c79a957..000000000 --- a/test/spec/modules/hypelabBidAdapter_spec.js +++ /dev/null @@ -1,326 +0,0 @@ -import { expect } from 'chai'; -import sinon from 'sinon'; -import { server } from '../../mocks/xhr.js'; -import { getWinDimensions } from '../../../src/utils.js'; -import { getBoundingClientRect } from '../../../libraries/boundingClientRect/boundingClientRect.js'; - -import { - mediaSize, - spec, - BIDDER_CODE, - ENDPOINT_URL, - REQUEST_ROUTE, -} from 'modules/hypelabBidAdapter.js'; - -import { BANNER } from 'src/mediaTypes.js'; - -const mockValidBidRequest = { - bidder: 'hypelab', - params: { - property_slug: 'prebid', - placement_slug: 'test_placement', - uuid: '', - sdk_version: '0.1.0', - provider_name: 'react', - provider_version: '0.3.1', - }, - userIds: [], - mediaTypes: { - banner: { - sizes: [[728, 90]], - }, - }, - adUnitCode: 'test-div', - sizes: [[728, 90]], - bidId: '24d2b2c86c5e19', - bidderRequestId: '1d1f40b509f18', - auctionId: '3bf3b1fb-cb0a-4ee8-90ef-69b8e6e56dbd', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, -}; - -const mockValidBidRequests = [mockValidBidRequest]; - -const mockServerResponse = { - body: { - status: 'success', - data: { - currency: 'USD', - campaign_slug: '9dbe230882', - creative_set_slug: '842984f045', - creative_set: { - image: { - url: 'https://cloudfront.net/up/asset/12345', - height: 90, - width: 728, - }, - }, - cpm: 1.5, - html: "\n \n \n \n Ad\n \n \n \n \n \n \n \n \n \n \n ", - advertiser_domains: ['ogx.com'], - media_type: 'banner', - ttl: 360, - }, - }, -}; - -const mockBidderRequest = { - bidderCode: 'hypelab', - auctionId: '4462005b-ba06-49a9-a95d-0209c22f4606', - bidderRequestId: '1bf399761210ad', - bids: mockValidBidRequests, - auctionStart: 1684983987435, - timeout: 2000, - refererInfo: { - topmostLocation: 'https://example.com/hello_world.html', - location: 'https://example.com/hello_world.html', - canonicalUrl: null, - page: 'https://example.com/hello_world.html', - domain: null, - ref: null, - }, -}; - -const mockBidRequest = { - method: 'POST', - url: 'https://api.hypelab.com/v1/prebid_requests', - options: { - contentType: 'application/json', - withCredentials: false, - }, - data: { - property_slug: 'prebid', - placement_slug: 'test_placement', - provider_version: '0.0.1', - provider_name: 'prebid', - location: 'https://example.com', - sdk_version: '7.51.0-pre', - sizes: [[728, 90]], - wids: [], - uuid: 'tmp_c5abf809-47d6-40b9-8274-372c6d816dd8', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - floor: null, - dpr: 1, - wp: { ada: false, bnb: false, eth: false, sol: false, tron: false }, - wpfs: { ada: [], bnb: [], eth: [], sol: [], tron: [] }, - vp: [1920, 1080], - pp: [240, 360], - }, - bidId: '2e02b562f700ae', -}; - -describe('hypelabBidAdapter', function () { - describe('mediaSize', function () { - it('when given an invalid media object', function () { - expect(mediaSize({})).to.eql({ width: 0, height: 0 }); - }); - - it('when given a valid media object', function () { - expect( - mediaSize({ creative_set: { image: { width: 728, height: 90 } } }) - ).to.eql({ width: 728, height: 90 }); - }); - }); - - describe('isBidRequestValid', function () { - it('when given an invalid bid request', function () { - expect(spec.isBidRequestValid({})).to.equal(false); - }); - - it('when given a valid bid request', function () { - expect(spec.isBidRequestValid(mockValidBidRequest)).to.equal(true); - }); - }); - - describe('Bidder code valid', function () { - it('should match BIDDER_CODE', function () { - expect(spec.code).to.equal(BIDDER_CODE); - }); - }); - - describe('Media types valid', function () { - it('should contain BANNER', function () { - expect(spec.supportedMediaTypes).to.contain(BANNER); - }); - }); - - describe('Bid request valid', function () { - it('should validate correctly', function () { - expect(spec.isBidRequestValid(mockValidBidRequest)).to.equal(true); - }); - }); - - describe('buildRequests', () => { - it('returns a valid request', function () { - const result = spec.buildRequests( - mockValidBidRequests, - mockBidderRequest - ); - expect(result).to.be.an('array'); - - const first = result[0] || {}; - expect(first).to.be.an('object'); - expect(first.method).to.equal('POST'); - expect(first.url).to.be.a('string'); - expect(first.url).to.equal(ENDPOINT_URL + REQUEST_ROUTE); - - const data = first.data || {}; - expect(data).to.be.an('object'); - expect(data.property_slug).to.be.a('string'); - expect(data.placement_slug).to.be.a('string'); - expect(data.bidRequestsCount).to.be.a('number'); - expect(data.bidderRequestsCount).to.be.a('number'); - expect(data.bidderWinsCount).to.be.a('number'); - expect(data.dpr).to.be.a('number'); - expect(data.location).to.be.a('string'); - expect(data.floor).to.equal(null); - expect(data.dpr).to.equal(1); - expect(data.wp).to.deep.equal({ - ada: false, - bnb: false, - eth: false, - sol: false, - tron: false, - }); - expect(data.wpfs).to.deep.equal({ - ada: [], - bnb: [], - eth: [], - sol: [], - tron: [], - }); - const winDimensions = getWinDimensions(); - expect(data.vp).to.deep.equal([ - Math.max( - winDimensions?.document.documentElement.clientWidth || 0, - winDimensions?.innerWidth || 0 - ), - Math.max( - winDimensions?.document.documentElement.clientHeight || 0, - winDimensions?.innerHeight || 0 - ), - ]); - expect(data.pp).to.deep.equal(null); - }); - - it('should set uuid to the first id in userIdAsEids', () => { - mockValidBidRequests[0].userIdAsEids = [ - { - source: 'pubcid.org', - uids: [ - { - id: 'pubcid_id', - }, - ], - }, - { - source: 'criteo.com', - uids: [ - { - id: 'criteo_id', - }, - ], - }, - ]; - - const result = spec.buildRequests( - mockValidBidRequests, - mockBidderRequest - ); - - const data = result[0].data || {}; - expect(data.uuid).to.be.eq('pubcid_id'); - }); - }); - - describe('interpretResponse', () => { - it('successfully interpret a valid response', function () { - const result = spec.interpretResponse(mockServerResponse, mockBidRequest); - - expect(result).to.be.an('array'); - const data = result[0] || {}; - expect(data).to.be.an('object'); - expect(data.requestId).to.be.a('string'); - expect(data.cpm).to.be.a('number'); - expect(data.width).to.be.a('number'); - expect(data.height).to.be.a('number'); - expect(data.creativeId).to.be.a('string'); - expect(data.currency).to.be.a('string'); - expect(data.netRevenue).to.be.a('boolean'); - expect(data.referrer).to.be.a('string'); - expect(data.ttl).to.be.a('number'); - expect(data.ad).to.be.a('string'); - expect(data.mediaType).to.be.a('string'); - expect(data.meta.advertiserDomains).to.be.an('array'); - expect(data.meta.advertiserDomains[0]).to.be.a('string'); - }); - - it('should return a blank array if cpm is not set', () => { - mockServerResponse.body.data.cpm = undefined; - const result = spec.interpretResponse(mockServerResponse, mockBidRequest); - expect(result).to.eql([]); - }); - }); - - describe('report', () => { - it('returns if REPORTING_ROUTE is not set', () => { - spec.REPORTING_ROUTE = ''; - expect(spec.report('test', {})).to.be.undefined; - }); - - it('makes a POST request if REPORTING_ROUTE is set', () => { - spec.report('test', {}, '/v1/events'); - - expect(server.requests[0].url).to.equals( - 'https://api.hypelab.com/v1/events' - ); - }); - }); - - describe('callbacks', () => { - const bid = {}; - let reportStub; - - beforeEach(() => (reportStub = sinon.stub(spec, 'report'))); - afterEach(() => reportStub.restore()); - - describe('onTimeout', () => { - it('should call report with the correct data', () => { - spec.onTimeout(bid); - - expect(reportStub.calledOnce).to.be.true; - expect(reportStub.getCall(0).args).to.eql(['timeout', bid]); - }); - }); - - describe('onSetTargeting', () => { - it('should call report with the correct data', () => { - spec.onSetTargeting(bid); - - expect(reportStub.calledOnce).to.be.true; - expect(reportStub.getCall(0).args).to.eql(['setTargeting', bid]); - }); - }); - - describe('onBidWon', () => { - it('should call report with the correct data', () => { - spec.onBidWon(bid); - - expect(reportStub.calledOnce).to.be.true; - expect(reportStub.getCall(0).args).to.eql(['bidWon', bid]); - }); - }); - - describe('onBidderError', () => { - it('should call report with the correct data', () => { - spec.onBidderError(bid); - - expect(reportStub.calledOnce).to.be.true; - expect(reportStub.getCall(0).args).to.eql(['bidderError', bid]); - }); - }); - }); -}); diff --git a/test/spec/modules/iasRtdProvider_spec.js b/test/spec/modules/iasRtdProvider_spec.js deleted file mode 100644 index 9425e8d98..000000000 --- a/test/spec/modules/iasRtdProvider_spec.js +++ /dev/null @@ -1,380 +0,0 @@ -import { iasSubModule, iasTargeting, injectImpressionData, injectBrandSafetyData } from 'modules/iasRtdProvider.js'; -import { expect } from 'chai'; -import { server } from 'test/mocks/xhr.js'; - -const responseHeader = { 'Content-Type': 'application/json' }; - -describe('iasRtdProvider is a RTD provider that', function () { - it('has the correct module name', function () { - expect(iasSubModule.name).to.equal('ias'); - }); - describe('has a method `init` that', function () { - it('exists', function () { - expect(iasSubModule.init).to.be.a('function'); - }); - it('returns false missing config params', function () { - const config = { - name: 'ias', - waitForIt: true, - }; - const value = iasSubModule.init(config); - expect(value).to.equal(false); - }); - it('returns false missing pubId param', function () { - const config = { - name: 'ias', - waitForIt: true, - params: {} - }; - const value = iasSubModule.init(config); - expect(value).to.equal(false); - }); - it('returns true with only the pubId param', function () { - const config = { - name: 'ias', - waitForIt: true, - params: { - pubId: '123456' - } - }; - const value = iasSubModule.init(config); - expect(value).to.equal(true); - }); - it('returns true with the pubId and keyMappings params', function () { - const config = { - name: 'ias', - waitForIt: true, - params: { - pubId: '123456', - keyMappings: { - 'id': 'ias_id' - } - } - }; - const value = iasSubModule.init(config); - expect(value).to.equal(true); - }); - it('returns true with the pubId, keyMappings and adUnitPath params', function () { - const config = { - name: 'ias', - waitForIt: true, - params: { - pubId: '123456', - keyMappings: { - 'id': 'ias_id' - }, - adUnitPath: { 'one-div-id': '/012345/ad/unit/path' } - } - }; - const value = iasSubModule.init(config); - expect(value).to.equal(true); - }); - it('returns true with the pubId and adUnitPath params with multiple keys', function () { - const config = { - name: 'ias', - waitForIt: true, - params: { - pubId: '123456', - keyMappings: { - 'id': 'ias_id' - }, - adUnitPath: { - 'one-div-id': '/012345/ad/unit/path', - 'another-div-id': '/012345/ad/unit/path', - 'third-div-id': '/012345/another/ad/unit/path' - } - } - }; - const value = iasSubModule.init(config); - expect(value).to.equal(true); - }); - it('returns true with the pubId and adUnitPath params with empty values', function () { - const config = { - name: 'ias', - waitForIt: true, - params: { - pubId: '123456', - keyMappings: { - 'id': 'ias_id' - }, - adUnitPath: { - 'one-div-id': '/012345/ad/unit/path', - 'another-div-id': '', - 'third-div-id': '' - } - } - }; - const value = iasSubModule.init(config); - expect(value).to.equal(true); - }); - }); - describe('has a method `getBidRequestData` that', function () { - it('exists', function () { - expect(iasSubModule.getBidRequestData).to.be.a('function'); - }); - it('verify config params', function () { - expect(config.name).to.not.be.undefined; - expect(config.name).to.equal('ias'); - expect(config.params.pubId).to.not.be.undefined; - expect(config.params).to.have.property('pubId'); - }); - it('invoke method', function () { - const callback = sinon.spy(); - let request; - const adUnitsOriginal = adUnits; - iasSubModule.getBidRequestData({ adUnits: adUnits }, callback, config); - request = server.requests[0]; - request.respond(200, responseHeader, JSON.stringify(data)); - expect(request.url).to.be.include(`https://pixel.adsafeprotected.com/services/pub?anId=1234`); - expect(request.url).to.be.include('url=https%253A%252F%252Fintegralads.com%252Ftest') - expect(adUnits).to.length(2); - expect(adUnits[0]).to.be.eq(adUnitsOriginal[0]); - const targetingKeys = Object.keys(iasTargeting); - const dataKeys = Object.keys(data); - expect(targetingKeys.length).to.equal(dataKeys.length); - expect(targetingKeys['fr']).to.be.eq(dataKeys['fr']); - expect(targetingKeys['brandSafety']).to.be.eq(dataKeys['brandSafety']); - expect(targetingKeys['ias-kw']).to.be.eq(dataKeys['ias-kw']); - expect(targetingKeys['slots']).to.be.eq(dataKeys['slots']); - }); - }); - - describe('has a method `getTargetingData` that', function () { - it('exists', function () { - expect(iasSubModule.getTargetingData).to.be.a('function'); - }); - describe('invoke method', function () { - it('returns a targeting object with the right shape', function () { - const targeting = iasSubModule.getTargetingData(adUnitsCode, config); - expect(adUnitsCode).to.length(2); - expect(targeting).to.be.not.null; - expect(targeting).to.be.not.empty; - expect(targeting['one-div-id']).to.be.not.null; - }); - it('returns the right keys', function () { - const targeting = iasSubModule.getTargetingData(adUnitsCode, config); - const targetingKeys = Object.keys(targeting['one-div-id']); - expect(targetingKeys.length).to.equal(10); - expect(targetingKeys).to.include('adt', 'adt key missing from the targeting object'); - expect(targetingKeys).to.include('alc', 'alc key missing from the targeting object'); - expect(targetingKeys).to.include('dlm', 'dlm key missing from the targeting object'); - expect(targetingKeys).to.include('drg', 'drg key missing from the targeting object'); - expect(targetingKeys).to.include('hat', 'hat key missing from the targeting object'); - expect(targetingKeys).to.include('off', 'off key missing from the targeting object'); - expect(targetingKeys).to.include('vio', 'vio key missing from the targeting object'); - expect(targetingKeys).to.include('fr', 'fr key missing from the targeting object'); - expect(targetingKeys).to.include('ias-kw', 'ias-kw key missing from the targeting object'); - expect(targetingKeys).to.not.include('id', 'id key present in the targeting object, should have been renamed to ias_id'); - expect(targetingKeys).to.include('ias_id', 'ias_id key missing from the targeting object'); - }); - it('returns the right values', function () { - const targeting = iasSubModule.getTargetingData(adUnitsCode, config); - expect(targeting['one-div-id']['adt']).to.be.eq('veryLow'); - expect(targeting['one-div-id']['alc']).to.be.eq('veryLow'); - expect(targeting['one-div-id']['dlm']).to.be.eq('veryLow'); - expect(targeting['one-div-id']['drg']).to.be.eq('veryLow'); - expect(targeting['one-div-id']['hat']).to.be.eq('veryLow'); - expect(targeting['one-div-id']['off']).to.be.eq('veryLow'); - expect(targeting['one-div-id']['vio']).to.be.eq('veryLow'); - expect(targeting['one-div-id']['fr']).to.be.eq('false'); - expect(targeting['one-div-id']['ias_id']).to.be.eq('4813f7a2-1f22-11ec-9bfd-0a1107f94461'); - }); - it('it merges response data', function () { - const callback = sinon.spy(); - - iasSubModule.getBidRequestData({ - adUnits: [ - { code: 'adunit-1' }, - { code: 'adunit-2' }, - ], - }, callback, config); - - let request = server.requests[0]; - request.respond(200, responseHeader, JSON.stringify(mergeRespData1)); - - const targeting1 = iasSubModule.getTargetingData(['adunit-1', 'adunit-2'], config); - - expect(targeting1['adunit-1']['adt']).to.be.eq('veryLow'); - expect(targeting1['adunit-1']['fr']).to.be.eq('false'); - expect(targeting1['adunit-1']['ias_id']).to.be.eq('id1'); - - expect(targeting1['adunit-2']['adt']).to.be.eq('veryLow'); - expect(targeting1['adunit-2']['fr']).to.be.eq('false'); - expect(targeting1['adunit-2']['ias_id']).to.be.eq('id2'); - - iasSubModule.getBidRequestData({ - adUnits: [ - { code: 'adunit-2' }, - { code: 'adunit-3' }, - ], - }, callback, config); - - request = server.requests[1]; - request.respond(200, responseHeader, JSON.stringify(mergeRespData2)); - - const targeting2 = iasSubModule.getTargetingData(['adunit-3', 'adunit-1', 'adunit-2'], config); - - expect(targeting2['adunit-1']['adt']).to.be.eq('high'); - expect(targeting2['adunit-1']['fr']).to.be.eq('true'); - expect(targeting2['adunit-1']['ias_id']).to.be.eq('id1'); - - expect(targeting2['adunit-2']['adt']).to.be.eq('high'); - expect(targeting2['adunit-2']['fr']).to.be.eq('true'); - expect(targeting2['adunit-2']['ias_id']).to.be.eq('id2'); - - expect(targeting2['adunit-3']['adt']).to.be.eq('high'); - expect(targeting2['adunit-3']['fr']).to.be.eq('true'); - expect(targeting2['adunit-3']['ias_id']).to.be.eq('id3'); - }); - }); - }) - describe('injectImpressionData', function () { - it('should inject impression data into adUnits ortb2Imp object', function () { - const adUnits = [ - { code: 'leaderboard-flex-hp', ortb2Imp: { ext: { data: {} } } } - ]; - const impressionData = { - 'leaderboard-flex-hp': { - id: '03690e2f-4ae8-11f0-bdbb-c2443b7c428c', - vw: ['40', '50', '60', '70'], - grm: ['40', '50', '60'], - pub: ['40', '50', '60'] - } - }; - const fraudData = "false"; - injectImpressionData(impressionData, fraudData, adUnits); - expect(adUnits[0].ortb2Imp.ext.data.ias_id).to.equal('03690e2f-4ae8-11f0-bdbb-c2443b7c428c'); - expect(adUnits[0].ortb2Imp.ext.data.vw).to.deep.equal(['40', '50', '60', '70']); - expect(adUnits[0].ortb2Imp.ext.data.grm).to.deep.equal(['40', '50', '60']); - expect(adUnits[0].ortb2Imp.ext.data.pub).to.deep.equal(['40', '50', '60']); - expect(adUnits[0].ortb2Imp.ext.data.fr).to.equal('false'); - }); - it('should inject impression data with fraud true', function () { - const adUnits = [ - { code: 'leaderboard-flex-hp', ortb2Imp: { ext: { data: {} } } } - ]; - const impressionData = { - 'leaderboard-flex-hp': { - id: '03690e2f-4ae8-11f0-bdbb-c2443b7c428c', - vw: ['40', '50', '60', '70'], - grm: ['40', '50', '60'], - pub: ['40', '50', '60'] - } - }; - const fraudData = "true"; - injectImpressionData(impressionData, fraudData, adUnits); - expect(adUnits[0].ortb2Imp.ext.data.ias_id).to.equal('03690e2f-4ae8-11f0-bdbb-c2443b7c428c'); - expect(adUnits[0].ortb2Imp.ext.data.vw).to.deep.equal(['40', '50', '60', '70']); - expect(adUnits[0].ortb2Imp.ext.data.grm).to.deep.equal(['40', '50', '60']); - expect(adUnits[0].ortb2Imp.ext.data.pub).to.deep.equal(['40', '50', '60']); - expect(adUnits[0].ortb2Imp.ext.data.fr).to.equal('true'); - }); - it('should not modify adUnits if impressionData is missing', function () { - const adUnits = [ - { code: 'adunit-1', ortb2Imp: { ext: { data: {} } } } - ]; - injectImpressionData(null, true, adUnits); - expect(adUnits[0].ortb2Imp.ext.data).to.deep.equal({}); - }); - }); - - describe('injectBrandSafetyData', function () { - it('should inject brandSafety data', function () { - const ortb2Fragments = { global: { site: {} } }; - const adUnits = [ - { bids: [{ bidder: 'pubmatic', params: {} }] } - ]; - const brandSafetyData = { - adt: 'veryLow', - alc: 'veryLow', - dlm: 'veryLow', - drg: 'veryLow', - hat: 'high', - off: 'veryLow', - vio: 'veryLow' - }; - injectBrandSafetyData(brandSafetyData, ortb2Fragments, adUnits); - expect(ortb2Fragments.global.site.ext.data['ias-brand-safety']).to.deep.equal({ - adt: 'veryLow', - alc: 'veryLow', - dlm: 'veryLow', - drg: 'veryLow', - hat: 'high', - off: 'veryLow', - vio: 'veryLow' - }); - // Also assert that each key/value is present at the top level of ext.data - Object.entries(brandSafetyData).forEach(([key, value]) => { - expect(ortb2Fragments.global.site.ext.data[key]).to.equal(value); - }); - }); - }); -}); - -const config = { - name: 'ias', - waitForIt: true, - params: { - pubId: 1234, - keyMappings: { - 'id': 'ias_id' - }, - pageUrl: 'https://integralads.com/test', - adUnitPath: { - 'one-div-id': '/012345/ad/unit/path' - } - } -}; - -const adUnitsCode = ['one-div-id', 'two-div-id']; - -const adUnits = [ - { - code: 'one-div-id', - mediaTypes: { - banner: { - sizes: [970, 250] - } - }, - bids: [ - { - bidder: 'appnexus', - params: { - placementId: 12345370, - } - }] - }, - { - code: 'two-div-id', - mediaTypes: { - banner: { sizes: [300, 250] } - }, - bids: [ - { - bidder: 'appnexus', - params: { - placementId: 12345370, - } - }] - }]; - -const data = { - brandSafety: { adt: 'veryLow', alc: 'veryLow', dlm: 'veryLow', drg: 'veryLow', hat: 'veryLow', off: 'veryLow', vio: 'veryLow' }, - custom: { 'ias-kw': ['IAS_5995_KW', 'IAS_7066_KW', 'IAS_7232_KW', 'IAS_7364_KW', 'IAS_3894_KW', 'IAS_6535_KW', 'IAS_6153_KW', 'IAS_5238_KW', 'IAS_7393_KW', 'IAS_1499_KW', 'IAS_7376_KW', 'IAS_1035_KW', 'IAS_6566_KW', 'IAS_1058_KW', 'IAS_11338_724_KW', 'IAS_7301_KW', 'IAS_15969_725_KW', 'IAS_6358_KW', 'IAS_710_KW', 'IAS_5445_KW', 'IAS_3822_KW', 'IAS_4901_KW', 'IAS_5806_KW', 'IAS_460_KW', 'IAS_11461_702_KW', 'IAS_5681_KW', 'IAS_17609_1240_KW', 'IAS_6634_KW', 'IAS_5597_KW'] }, - fr: 'false', - slots: { 'one-div-id': { id: '4813f7a2-1f22-11ec-9bfd-0a1107f94461' } } -}; - -const mergeRespData1 = { - brandSafety: { adt: 'veryLow' }, - custom: { 'ias-kw': ['IAS_5995_KW'] }, - fr: 'false', - slots: { 'adunit-1': { id: 'id1' }, 'adunit-2': { id: 'id2' } } -}; - -const mergeRespData2 = { - brandSafety: { adt: 'high' }, - custom: { 'ias-kw': ['IAS_5995_KW'] }, - fr: 'true', - slots: { 'adunit-2': { id: 'id2' }, 'adunit-3': { id: 'id3' } } -}; diff --git a/test/spec/modules/id5AnalyticsAdapter_spec.js b/test/spec/modules/id5AnalyticsAdapter_spec.js deleted file mode 100644 index 17b0ccb93..000000000 --- a/test/spec/modules/id5AnalyticsAdapter_spec.js +++ /dev/null @@ -1,457 +0,0 @@ -import adapterManager from '../../../src/adapterManager.js'; -import id5AnalyticsAdapter from '../../../modules/id5AnalyticsAdapter.js'; -import { expect } from 'chai'; -import * as events from '../../../src/events.js'; -import { EVENTS } from '../../../src/constants.js'; -import { generateUUID } from '../../../src/utils.js'; -import {server} from '../../mocks/xhr.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -const CONFIG_URL = 'https://api.id5-sync.com/analytics/12349/pbjs'; -const INGEST_URL = 'https://test.me/ingest'; - -describe('ID5 analytics adapter', () => { - let config; - - beforeEach(() => { - config = { - options: { - partnerId: 12349, - } - }; - }); - - it('registers itself with the adapter manager', () => { - const adapter = adapterManager.getAnalyticsAdapter('id5Analytics'); - expect(adapter).to.exist; - expect(adapter.gvlid).to.be.a('number'); - expect(adapter.adapter).to.equal(id5AnalyticsAdapter); - }); - - it('tolerates undefined or empty config', () => { - id5AnalyticsAdapter.enableAnalytics(undefined); - id5AnalyticsAdapter.enableAnalytics({}); - }); - - it('calls configuration endpoint', () => { - server.respondWith('GET', CONFIG_URL, [200, - { - 'Content-Type': 'application/json', - 'Access-Control-Allow-Origin': '*' - }, - `{ "sampling": 0, "ingestUrl": "${INGEST_URL}" }` - ]); - id5AnalyticsAdapter.enableAnalytics(config); - server.respond(); - - expect(server.requests).to.have.length(1); - - id5AnalyticsAdapter.disableAnalytics(); - }); - - it('does not call configuration endpoint when partner id is missing', () => { - id5AnalyticsAdapter.enableAnalytics({}); - server.respond(); - - expect(server.requests).to.have.length(0); - - id5AnalyticsAdapter.disableAnalytics(); - }); - - describe('after configuration', () => { - let auction; - - beforeEach(() => { - server.respondWith('GET', CONFIG_URL, [200, - { - 'Content-Type': 'application/json', - 'Access-Control-Allow-Origin': '*' - }, - `{ "sampling": 1, "ingestUrl": "${INGEST_URL}" }` - ]); - - server.respondWith('POST', INGEST_URL, [200, - { - 'Content-Type': 'application/json', - 'Access-Control-Allow-Origin': '*' - }, - '' - ]); - - auction = { - auctionId: generateUUID(), - adUnits: [{ - 'code': 'user-728', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600], [728, 90]] - } - }, - adUnitCodes: ['user-728'] - }], - }; - }); - - afterEach(() => { - id5AnalyticsAdapter.disableAnalytics(); - }); - - it('sends auction end events to the backend', () => { - id5AnalyticsAdapter.enableAnalytics(config); - server.respond(); - events.emit(EVENTS.AUCTION_END, auction); - server.respond(); - - // Why 3? 1: config, 2: tcfEnforcement, 3: auctionEnd - // tcfEnforcement? yes, tcfControl module emits in reaction to auctionEnd - expect(server.requests).to.have.length(3); - - const body1 = JSON.parse(server.requests[1].requestBody); - expect(body1.source).to.equal('pbjs'); - expect(body1.event).to.equal('tcf2Enforcement'); - expect(body1.partnerId).to.equal(12349); - expect(body1.meta).to.be.a('object'); - expect(body1.meta.pbjs).to.equal(getGlobal().version); - expect(body1.meta.sampling).to.equal(1); - expect(body1.meta.tz).to.be.a('number'); - - const body2 = JSON.parse(server.requests[2].requestBody); - expect(body2.source).to.equal('pbjs'); - expect(body2.event).to.equal('auctionEnd'); - expect(body2.partnerId).to.equal(12349); - expect(body2.meta).to.be.a('object'); - expect(body2.meta.pbjs).to.equal(getGlobal().version); - expect(body2.meta.sampling).to.equal(1); - expect(body2.meta.tz).to.be.a('number'); - expect(body2.payload).to.eql(auction); - }); - - it('filters unwanted IDs from the events it sends', () => { - auction.adUnits[0].bids = [{ - 'bidder': 'appnexus', - 'params': { - 'placementId': '16618951' - }, - 'userId': { - 'criteoId': '_h_y_19IMUhMZG1TOTRReHFNc29TekJ3TzQ3elhnRU81ayUyQjhiRkdJJTJGaTFXJTJCdDRnVmN4S0FETUhQbXdmQWg0M3g1NWtGbGolMkZXalclMkJvWjJDOXFDSk1HU3ZKaVElM0QlM0Q', - 'id5id': { - 'uid': 'ID5-ZHMOQ99ulpk687Fd9xVwzxMsYtkQIJnI-qm3iWdtww!ID5*FSycZQy7v7zWXiKbEpPEWoB3_UiWdPGzh554ncYDvOkAAA3rajiR0yNrFAU7oDTu', - 'ext': { 'linkType': 1 } - }, - 'tdid': '888a6042-8f99-483b-aa26-23c44bc9166b' - }, - 'userIdAsEids': [{ - 'source': 'criteo.com', - 'uids': [{ - 'id': '_h_y_19IMUhMZG1TOTRReHFNc29TekJ3TzQ3elhnRU81ayUyQjhiRkdJJTJGaTFXJTJCdDRnVmN4S0FETUhQbXdmQWg0M3g1NWtGbGolMkZXalclMkJvWjJDOXFDSk1HU3ZKaVElM0QlM0Q', - 'atype': 1 - }] - }, { - 'source': 'id5-sync.com', - 'uids': [{ - 'id': 'ID5-ZHMOQ99ulpk687Fd9xVwzxMsYtkQIJnI-qm3iWdtww!ID5*FSycZQy7v7zWXiKbEpPEWoB3_UiWdPGzh554ncYDvOkAAA3rajiR0yNrFAU7oDTu', - 'atype': 1, - 'ext': { 'linkType': 1 } - }] - }] - }]; - - auction.bidderRequests = [{ - 'bidderCode': 'appnexus', - 'auctionId': 'e8d15df4-d89c-44c9-8b36-812f75cbf227', - 'bidderRequestId': '1451a3c759c60359', - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': '16824712' - }, - 'userId': { - 'id5id': { - 'uid': 'ID5-ZHMOQ99ulpk687Fd9xVwzxMsYtkQIJnI-qm3iWdtww!ID5*CmuuahP8jbPJGRCUDdT2VZ8wz0eJM8O8mNlKktlEjuYAABFEjc2c9faqDencf2hR', - 'ext': { - 'linkType': 1 - } - }, - 'sharedid': { - 'id': '01F6J4T72MRFYVWTN65WFA0H7N', - 'third': '01F6J4T72MRFYVWTN65WFA0H7N' - }, - 'tdid': '0e45f56b-ad09-4c91-b090-8bd03e0d0754' - }, - 'userIdAsEids': [ - { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': 'ID5-ZHMOQ99ulpk687Fd9xVwzxMsYtkQIJnI-qm3iWdtww!ID5*CmuuahP8jbPJGRCUDdT2VZ8wz0eJM8O8mNlKktlEjuYAABFEjc2c9faqDencf2hR', - 'atype': 1, - 'ext': { - 'linkType': 1 - } - } - ] - }, - { - 'source': 'sharedid.org', - 'uids': [ - { - 'id': '01F6J4T72MRFYVWTN65WFA0H7N', - 'atype': 1, - 'ext': { - 'third': '01F6J4T72MRFYVWTN65WFA0H7N' - } - } - ] - }, - { - 'source': 'adserver.org', - 'uids': [ - { - 'id': '0e45f56b-ad09-4c91-b090-8bd03e0d0754', - 'atype': 1, - 'ext': { - 'rtiPartner': 'TDID' - } - } - ] - } - ], - 'ortb2Imp': { - 'ext': { - 'data': { - 'adserver': { - 'name': 'gam', - 'adslot': '/6783/Kiwi/portail' - }, - 'pbadslot': '/6783/Kiwi/portail' - } - } - }, - 'adUnitCode': 'btf_leaderboard', - 'transactionId': '3ce8216e-7898-4a22-86ba-01519b62bfce', - 'sizes': [ - [ - 728, - 90 - ] - ], - 'bidId': '146661c05209a56e', - 'bidderRequestId': '1451a3c759c60359', - 'auctionId': 'e8d15df4-d89c-44c9-8b36-812f75cbf227', - 'src': 'client', - 'bidRequestsCount': 2, - 'bidderRequestsCount': 2, - 'bidderWinsCount': 0 - } - ], - 'auctionStart': 1621959214757, - 'timeout': 2000, - 'refererInfo': { - 'referer': 'https://www.blog.com/?pbjs_debug=true', - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': [ - 'https://www.blog.com/?pbjs_debug=true' - ], - 'canonicalUrl': null - }, - 'gdprConsent': { - 'consentString': 'CPGw1WAPGw1WAAHABBENBbCsAP_AAH_AAAAAH3tf_X__b3_j-_59__t0eY1f9_7_v-0zjhfdt-8N2f_X_L8X42M7vF36pq4KuR4Eu3LBIQdlHOHcTUmw6okVrTPsbk2Mr7NKJ7PEmnMbe2dYGH9_n93TuZKY7__8___z__-v_v____f_r-3_3__59X---_e_V399zLv9__3__9gfaASYal8AF2JY4Mk0aVQogQhWEh0AoAKKAYWiawgZXBTsrgI9QQMAEJqAjAiBBiCjFgEAAgEASERASAHggEQBEAgABACpAQgAI2AQWAFgYBAAKAaFiBFAEIEhBkcFRymBARItFBPZWAJRd7GmEIZRYAUCj-iowEShBAsDISFg4AAA.f_gAD_gAAAAA', - 'vendorData': { - 'cmpId': 7, - 'cmpVersion': 1, - 'gdprApplies': true, - 'tcfPolicyVersion': 2, - 'eventStatus': 'useractioncomplete', - 'cmpStatus': 'loaded', - 'listenerId': 47, - 'tcString': 'CPGw1WAPGw1WAAHABBENBbCsAP_AAH_AAAAAH3tf_X__b3_j-_59__t0eY1f9_7_v-0zjhfdt-8N2f_X_L8X42M7vF36pq4KuR4Eu3LBIQdlHOHcTUmw6okVrTPsbk2Mr7NKJ7PEmnMbe2dYGH9_n93TuZKY7__8___z__-v_v____f_r-3_3__59X---_e_V399zLv9__3__9gfaASYal8AF2JY4Mk0aVQogQhWEh0AoAKKAYWiawgZXBTsrgI9QQMAEJqAjAiBBiCjFgEAAgEASERASAHggEQBEAgABACpAQgAI2AQWAFgYBAAKAaFiBFAEIEhBkcFRymBARItFBPZWAJRd7GmEIZRYAUCj-iowEShBAsDISFg4AAA.f_gAD_gAAAAA', - }, - 'gdprApplies': true, - 'addtlConsent': '1~7.12.35.62.66.70.89.93.108.122.144.149.153.162.167.184.196.221.241.253.259.272.311.317.323.326.338.348.350.415.440.448.449.482.486.491.494.495.540.571.574.585.587.588.590.725.733.780.817.839.864.867.932.938.981.986.1031.1033.1051.1092.1097.1126.1127.1170.1171.1186.1201.1204.1205.1211.1215.1230.1232.1236.1248.1276.1290.1301.1313.1344.1364.1365.1415.1419.1428.1449.1451.1509.1558.1564.1570.1577.1591.1651.1669.1712.1716.1720.1721.1725.1733.1753.1765.1799.1810.1834.1842.1870.1878.1889.1896.1911.1922.1929.2012.2072.2078.2079.2109.2177.2202.2253.2290.2299.2316.2357.2373.2526.2531.2571.2572.2575.2628.2663.2677.2776.2778.2779.2985.3033.3052.3154', - 'apiVersion': 2 - }, - 'start': 1621959214763 - }]; - - auction.bidsReceived = [{ - 'bidderCode': 'appnexus', - 'width': 728, - 'height': 90, - 'statusMessage': 'Bid available', - 'adId': '99e7838aa7f1c4f', - 'requestId': '21e0b32208ee9a', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 0.020601, - 'creativeId': 209272535, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'adUnitCode': 'user-728', - 'appnexus': { - 'buyerMemberId': 11563 - }, - 'meta': { - 'advertiserId': 4388779 - }, - 'ad': 'stuff i am not interested in', - 'originalCpm': 0.020601, - 'originalCurrency': 'USD', - 'auctionId': 'c7694dbb-a583-4a73-a933-b16f1f821ba4', - // Make sure cleanup is resilient - 'someNullObject': null, - 'someUndefinedProperty': undefined - }]; - - id5AnalyticsAdapter.enableAnalytics(config); - server.respond(); - events.emit(EVENTS.AUCTION_END, auction); - server.respond(); - - expect(server.requests).to.have.length(3); - - const body = JSON.parse(server.requests[2].requestBody); - expect(body.event).to.equal('auctionEnd'); - expect(body.payload.adUnits[0].bids[0].userId).to.eql({ - 'criteoId': '__ID5_REDACTED__', - 'id5id': { - 'uid': '__ID5_REDACTED__', - 'ext': { - 'linkType': 1 - } - }, - 'tdid': '__ID5_REDACTED__' - }); - expect(body.payload.bidderRequests[0].bids[0].userId).to.eql({ - 'sharedid': '__ID5_REDACTED__', - 'id5id': { - 'uid': '__ID5_REDACTED__', - 'ext': { - 'linkType': 1 - } - }, - 'tdid': '__ID5_REDACTED__' - }); - body.payload.adUnits[0].bids[0].userIdAsEids.forEach((userId) => { - expect(userId.uids[0].id).to.equal('__ID5_REDACTED__'); - if (userId.uids[0].ext) { - expect(userId.uids[0].ext).to.equal('__ID5_REDACTED__'); - } - }); - body.payload.bidderRequests[0].bids[0].userIdAsEids.forEach((userId) => { - expect(userId.uids[0].id).to.equal('__ID5_REDACTED__'); - if (userId.uids[0].ext) { - expect(userId.uids[0].ext).to.equal('__ID5_REDACTED__'); - } - }); - expect(body.payload.bidsReceived[0].ad).to.equal(undefined); - expect(body.payload.bidsReceived[0].requestId).to.equal('21e0b32208ee9a'); - }); - - it('can override events to collect if configured to do so', () => { - server.respondWith('GET', CONFIG_URL, [200, - { - 'Content-Type': 'application/json', - 'Access-Control-Allow-Origin': '*' - }, - `{ "sampling": 1, "ingestUrl": "${INGEST_URL}", "eventsToTrack": ["tcf2Enforcement"] }` - ]); - id5AnalyticsAdapter.enableAnalytics(config); - server.respond(); - events.emit(EVENTS.AUCTION_END, auction); - server.respond(); - - expect(server.requests).to.have.length(2); - const body1 = JSON.parse(server.requests[1].requestBody); - expect(body1.event).to.equal('tcf2Enforcement'); - }); - - it('can extend cleanup rules from server side', () => { - auction.bidsReceived = [{ - 'bidderCode': 'appnexus', - 'width': 728, - 'height': 90, - 'statusMessage': 'Bid available', - 'adId': '99e7838aa7f1c4f', - 'requestId': '21e0b32208ee9a', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 0.020601, - 'creativeId': 209272535, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'adUnitCode': 'user-728', - 'appnexus': { - 'buyerMemberId': 11563 - }, - 'meta': { - 'advertiserId': 4388779 - }, - 'ad': 'stuff i am not interested in', - 'originalCpm': 0.020601, - 'originalCurrency': 'USD', - 'auctionId': 'c7694dbb-a583-4a73-a933-b16f1f821ba4' - }, { - 'bidderCode': 'ix', - 'width': 728, - 'height': 90, - 'statusMessage': 'Bid available', - 'adId': '228f725de4a9ff09', - 'requestId': '225a42b4a8ec7287', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 0.06, - 'netRevenue': true, - 'currency': 'USD', - 'creativeId': '8838044', - 'ad': 'lots of HTML code', - 'ttl': 300, - 'meta': { - 'networkId': 85, - 'brandId': 822, - 'brandName': 'Microsoft Brands', - 'advertiserDomains': [ - 'microsoftstore.com' - ] - }, - 'originalCpm': 0.06, - 'originalCurrency': 'USD', - 'auctionId': 'fe28ce44-61bb-4ed8-be3c-3e801dfddcb9', - 'responseTimestamp': 1621954632648, - 'requestTimestamp': 1621954632498, - 'bidder': 'ix', - 'adUnitCode': 'sticky_footer', - 'timeToRespond': 150, - 'pbLg': '0.00', - 'pbCg': '0.06', - 'size': '728x90', - 'adserverTargeting': { - 'hb_bidder': 'ix', - } - }]; - server.respondWith('GET', CONFIG_URL, [200, - { - 'Content-Type': 'application/json', - 'Access-Control-Allow-Origin': '*' - }, - `{ "sampling": 1, "ingestUrl": "${INGEST_URL}", "additionalCleanupRules": {"auctionEnd": [{"match":["bidsReceived", "*", "requestId"],"apply":"erase"}]} }` - ]); - id5AnalyticsAdapter.enableAnalytics(config); - server.respond(); - events.emit(EVENTS.AUCTION_END, auction); - server.respond(); - - expect(server.requests).to.have.length(3); - const body = JSON.parse(server.requests[2].requestBody); - expect(body.event).to.equal('auctionEnd'); - expect(body.payload.bidsReceived[0].requestId).to.equal(undefined); - expect(body.payload.bidsReceived[1].requestId).to.equal(undefined); - expect(body.payload.bidsReceived[0].bidderCode).to.equal('appnexus'); - expect(body.payload.bidsReceived[1].bidderCode).to.equal('ix'); - }); - }); -}); diff --git a/test/spec/modules/idxBidAdapter_spec.js b/test/spec/modules/idxBidAdapter_spec.js deleted file mode 100644 index 709fb8c59..000000000 --- a/test/spec/modules/idxBidAdapter_spec.js +++ /dev/null @@ -1,103 +0,0 @@ -import { expect } from 'chai' -import { spec } from 'modules/idxBidAdapter.js' - -const BIDDER_CODE = 'idx' -const ENDPOINT_URL = 'https://dev-event.dxmdp.com/rest/api/v1/bid' -const DEFAULT_PRICE = 1 -const DEFAULT_CURRENCY = 'USD' -const DEFAULT_BANNER_WIDTH = 300 -const DEFAULT_BANNER_HEIGHT = 250 - -describe('idxBidAdapter', function () { - describe('isBidRequestValid', function () { - const validBid = { - bidder: BIDDER_CODE, - mediaTypes: { - banner: { - sizes: [[DEFAULT_BANNER_WIDTH, DEFAULT_BANNER_HEIGHT]] - } - } - } - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(validBid)).to.equal(true) - }) - - it('should return false when required params are not passed', function () { - const bid = Object.assign({}, validBid) - bid.mediaTypes = {} - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - }) - describe('buildRequests', function () { - const bidRequests = [ - { - bidder: BIDDER_CODE, - bidId: 'asdf12345', - mediaTypes: { - banner: { - sizes: [[DEFAULT_BANNER_WIDTH, DEFAULT_BANNER_HEIGHT]] - } - }, - } - ] - const bidderRequest = { - bidderCode: BIDDER_CODE, - bidderRequestId: '12345asdf', - bids: [ - { - ...bidRequests[0] - } - ], - } - - it('sends video bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest) - expect(request.url).to.equal(ENDPOINT_URL) - expect(request.method).to.equal('POST') - }) - }) - describe('interpretResponse', function () { - it('should get correct bid response', function () { - const response = { - id: 'f6adb85f-4e19-45a0-b41e-2a5b9a48f23a', - seatbid: [ - { - bid: [ - { - id: '123', - impid: 'b4f290d7-d4ab-4778-ab94-2baf06420b22', - price: DEFAULT_PRICE, - adm: 'hi', - cid: 'test_cid', - crid: 'test_banner_crid', - w: DEFAULT_BANNER_WIDTH, - h: DEFAULT_BANNER_HEIGHT, - adomain: [], - } - ], - seat: BIDDER_CODE - } - ], - } - - const expectedResponse = [ - { - requestId: 'b4f290d7-d4ab-4778-ab94-2baf06420b22', - cpm: DEFAULT_PRICE, - width: DEFAULT_BANNER_WIDTH, - height: DEFAULT_BANNER_HEIGHT, - creativeId: 'test_banner_crid', - ad: 'hi', - currency: DEFAULT_CURRENCY, - netRevenue: true, - ttl: 300, - meta: { advertiserDomains: [] }, - } - ] - const result = spec.interpretResponse({ body: response }) - - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])) - }) - }) -}) diff --git a/test/spec/modules/illuminBidAdapter_spec.js b/test/spec/modules/illuminBidAdapter_spec.js deleted file mode 100644 index 05b803d5f..000000000 --- a/test/spec/modules/illuminBidAdapter_spec.js +++ /dev/null @@ -1,760 +0,0 @@ -import {expect} from 'chai'; -import { - spec as adapter, - createDomain, - storage -} from 'modules/illuminBidAdapter.js'; -import * as utils from 'src/utils.js'; -import {version} from 'package.json'; -import {useFakeTimers} from 'sinon'; -import {BANNER, VIDEO} from '../../../src/mediaTypes.js'; -import {config} from '../../../src/config.js'; -import { - hashCode, - extractPID, - extractCID, - extractSubDomain, - getStorageItem, - setStorageItem, - tryParseJSON, - getUniqueDealId, -} from '../../../libraries/vidazooUtils/bidderUtils.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -export const TEST_ID_SYSTEMS = ['criteoId', 'id5id', 'idl_env', 'lipb', 'netId', 'pubcid', 'tdid', 'pubProvidedId']; - -const SUB_DOMAIN = 'exchange'; - -const BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': 'div-gpt-ad-12345-0', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '59db6b3b4ffaa70004f45cdc', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1, - 'ext': { - 'param1': 'loremipsum', - 'param2': 'dolorsitamet' - } - }, - 'placementCode': 'div-gpt-ad-1460505748561-0', - 'sizes': [[300, 250], [300, 600]], - 'bidderRequestId': '1fdb5ff1b6eaa7', - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'requestId': 'b0777d85-d061-450e-9bc7-260dd54bbb7a', - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'mediaTypes': [BANNER], - 'ortb2Imp': { - 'ext': { - 'gpid': '0123456789', - 'tid': 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf' - } - } -}; - -const VIDEO_BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': '63550ad1ff6642d368cba59dh5884270560', - 'bidderRequestId': '12a8ae9ada9c13', - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '635509f7ff6642d368cb9837', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1 - }, - 'sizes': [[545, 307]], - 'mediaTypes': { - 'video': { - 'playerSize': [[545, 307]], - 'context': 'instream', - 'mimes': [ - 'video/mp4', - 'application/javascript' - ], - 'protocols': [2, 3, 5, 6], - 'maxduration': 60, - 'minduration': 0, - 'startdelay': 0, - 'linearity': 1, - 'api': [2], - 'placement': 1 - } - }, - 'ortb2Imp': { - 'ext': { - 'gpid': '0123456789', - 'tid': '56e184c6-bde9-497b-b9b9-cf47a61381ee' - } - } -} - -const ORTB2_DEVICE = { - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - ext: {fiftyonedegrees_deviceId: '17595-133085-133468-18092'}, -}; - -const BIDDER_REQUEST = { - 'gdprConsent': { - 'consentString': 'consent_string', - 'gdprApplies': true - }, - 'gppString': 'gpp_string', - 'gppSid': [7], - 'uspConsent': 'consent_string', - 'refererInfo': { - 'page': 'https://www.greatsite.com', - 'ref': 'https://www.somereferrer.com' - }, - 'ortb2': { - 'site': { - 'content': { - 'language': 'en' - } - }, - 'regs': { - 'gpp': 'gpp_string', - 'gpp_sid': [7], - 'coppa': 0 - }, - 'device': ORTB2_DEVICE, - } -}; - -const SERVER_RESPONSE = { - body: { - cid: 'testcid123', - results: [{ - 'ad': '', - 'price': 0.8, - 'creativeId': '12610997325162499419', - 'exp': 30, - 'width': 300, - 'height': 250, - 'advertiserDomains': ['securepubads.g.doubleclick.net'], - 'cookies': [{ - 'src': 'https://sync.com', - 'type': 'iframe' - }, { - 'src': 'https://sync.com', - 'type': 'img' - }] - }] - } -}; - -const VIDEO_SERVER_RESPONSE = { - body: { - 'cid': '635509f7ff6642d368cb9837', - 'results': [{ - 'ad': '', - 'advertiserDomains': ['illumin.com'], - 'exp': 60, - 'width': 545, - 'height': 307, - 'mediaType': 'video', - 'creativeId': '12610997325162499419', - 'price': 2, - 'cookies': [] - }] - } -}; - -const ORTB2_OBJ = { - "device": ORTB2_DEVICE, - "regs": {"coppa": 0, "gpp": "gpp_string", "gpp_sid": [7]}, - "site": {"content": {"language": "en"} - } -}; - -const REQUEST = { - data: { - width: 300, - height: 250, - bidId: '2d52001cabd527' - } -}; - -function getTopWindowQueryParams() { - try { - const parsedUrl = utils.parseUrl(window.top.document.URL, {decodeSearchAsString: true}); - return parsedUrl.search; - } catch (e) { - return ''; - } -} - -describe('IlluminBidAdapter', function () { - before(() => config.resetConfig()); - after(() => config.resetConfig()); - - describe('validtae spec', function () { - it('exists and is a function', function () { - expect(adapter.isBidRequestValid).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.buildRequests).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.interpretResponse).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.getUserSyncs).to.exist.and.to.be.a('function'); - }); - - it('exists and is a string', function () { - expect(adapter.code).to.exist.and.to.be.a('string'); - }); - - it('exists and contains media types', function () { - expect(adapter.supportedMediaTypes).to.exist.and.to.be.an('array').with.length(2); - expect(adapter.supportedMediaTypes).to.contain.members([BANNER, VIDEO]); - }); - }); - - describe('validate bid requests', function () { - it('should require cId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - pId: 'pid' - } - }); - expect(isValid).to.be.false; - }); - - it('should require pId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid' - } - }); - expect(isValid).to.be.false; - }); - - it('should validate correctly', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid', - pId: 'pid' - } - }); - expect(isValid).to.be.true; - }); - }); - - describe('build requests', function () { - let sandbox; - before(function () { - getGlobal().bidderSettings = { - illumin: { - storageAllowed: true - } - }; - sandbox = sinon.createSandbox(); - sandbox.stub(Date, 'now').returns(1000); - }); - - it('should build video request', function () { - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - config.setConfig({ - bidderTimeout: 3000, - enableTIDs: true - }); - const requests = adapter.buildRequests([VIDEO_BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/635509f7ff6642d368cb9837`, - data: { - adUnitCode: '63550ad1ff6642d368cba59dh5884270560', - bidFloor: 0.1, - bidId: '2d52001cabd527', - bidderVersion: adapter.version, - bidderRequestId: '12a8ae9ada9c13', - cb: 1000, - gdpr: 1, - gdprConsent: 'consent_string', - usPrivacy: 'consent_string', - gppString: 'gpp_string', - gppSid: [7], - transactionId: '56e184c6-bde9-497b-b9b9-cf47a61381ee', - prebidVersion: version, - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - publisherId: '59ac17c192832d0011283fe3', - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - res: `${window.top.screen.width}x${window.top.screen.height}`, - schain: VIDEO_BID.schain, - sizes: ['545x307'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - uqs: getTopWindowQueryParams(), - mediaTypes: { - video: { - api: [2], - context: 'instream', - linearity: 1, - maxduration: 60, - mimes: [ - 'video/mp4', - 'application/javascript' - ], - minduration: 0, - placement: 1, - playerSize: [[545, 307]], - protocols: [2, 3, 5, 6], - startdelay: 0 - } - }, - gpid: '0123456789', - cat: [], - contentData: [], - contentLang: 'en', - isStorageAllowed: true, - pagecat: [], - ortb2: ORTB2_OBJ, - ortb2Imp: VIDEO_BID.ortb2Imp, - userData: [], - coppa: 0 - } - }); - }); - - it('should build banner request for each size', function () { - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - config.setConfig({ - bidderTimeout: 3000, - enableTIDs: true - }); - const requests = adapter.buildRequests([BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/59db6b3b4ffaa70004f45cdc`, - data: { - gdprConsent: 'consent_string', - gdpr: 1, - gppString: 'gpp_string', - gppSid: [7], - usPrivacy: 'consent_string', - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - bidderRequestId: '1fdb5ff1b6eaa7', - transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - sizes: ['300x250', '300x600'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - cb: 1000, - bidFloor: 0.1, - bidId: '2d52001cabd527', - adUnitCode: 'div-gpt-ad-12345-0', - publisherId: '59ac17c192832d0011283fe3', - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - bidderVersion: adapter.version, - prebidVersion: version, - schain: BID.schain, - res: `${window.top.screen.width}x${window.top.screen.height}`, - mediaTypes: [BANNER], - gpid: '0123456789', - uqs: getTopWindowQueryParams(), - 'ext.param1': 'loremipsum', - 'ext.param2': 'dolorsitamet', - cat: [], - contentData: [], - contentLang: 'en', - isStorageAllowed: true, - pagecat: [], - ortb2: ORTB2_OBJ, - ortb2Imp: BID.ortb2Imp, - userData: [], - coppa: 0 - } - }); - }); - - after(function () { - getGlobal().bidderSettings = {}; - sandbox.restore(); - }); - }); - describe('getUserSyncs', function () { - it('should have valid user sync with iframeEnabled', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.illumin.com/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - - it('should have valid user sync with cid on response', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.illumin.com/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - - it('should have valid user sync with pixelEnabled', function () { - const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE]); - - expect(result).to.deep.equal([{ - 'url': 'https://sync.illumin.com/api/sync/image/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0', - 'type': 'image' - }]); - }) - - it('should have valid user sync with coppa on response', function () { - config.setConfig({ - coppa: 1 - }); - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.illumin.com/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=1' - }]); - }); - }); - - describe('interpret response', function () { - it('should return empty array when there is no response', function () { - const responses = adapter.interpretResponse(null); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no ad', function () { - const responses = adapter.interpretResponse({price: 1, ad: ''}); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no price', function () { - const responses = adapter.interpretResponse({price: null, ad: 'great ad'}); - expect(responses).to.be.empty; - }); - - it('should return an array of interpreted banner responses', function () { - const responses = adapter.interpretResponse(SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 0.8, - width: 300, - height: 250, - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 30, - ad: '', - meta: { - advertiserDomains: ['securepubads.g.doubleclick.net'] - } - }); - }); - - it('should get meta from response metaData', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - serverResponse.body.results[0].metaData = { - advertiserDomains: ['illumin.com'], - agencyName: 'Agency Name', - }; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses[0].meta).to.deep.equal({ - advertiserDomains: ['illumin.com'], - agencyName: 'Agency Name' - }); - }); - - it('should return an array of interpreted video responses', function () { - const responses = adapter.interpretResponse(VIDEO_SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 2, - width: 545, - height: 307, - mediaType: 'video', - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 60, - vastXml: '', - meta: { - advertiserDomains: ['illumin.com'] - } - }); - }); - - it('should take default TTL', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - delete serverResponse.body.results[0].exp; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0].ttl).to.equal(300); - }); - }); - - describe('user id system', function () { - TEST_ID_SYSTEMS.forEach((idSystemProvider) => { - const id = Date.now().toString(); - const bid = utils.deepClone(BID); - - const userId = (function () { - switch (idSystemProvider) { - case 'lipb': - return {lipbid: id}; - case 'id5id': - return {uid: id}; - default: - return id; - } - })(); - - bid.userId = { - [idSystemProvider]: userId - }; - - it(`should include 'uid.${idSystemProvider}' in request params`, function () { - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data[`uid.${idSystemProvider}`]).to.equal(id); - }); - }); - // testing bid.userIdAsEids handling - it("should include user ids from bid.userIdAsEids (length=1)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - }) - it("should include user ids from bid.userIdAsEids (length=2)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - }, - { - "source": "rwdcntrl.net", - "uids": [{"id": "fakeid6f35197d5c", "atype": 1}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - expect(requests[0].data['uid.rwdcntrl.net']).to.equal("fakeid6f35197d5c"); - }) - // testing user.ext.eid handling - it("should include user ids from user.ext.eid (length=1)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - }) - it("should include user ids from user.ext.eid (length=2)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - }, - { - "source": "adserver.org", - "uids": [{"id": "fakeid495ff1"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - expect(requests[0].data['uid.adserver.org']).to.equal("fakeid495ff1"); - }) - }); - - describe('alternate param names extractors', function () { - it('should return undefined when param not supported', function () { - const cid = extractCID({'c_id': '1'}); - const pid = extractPID({'p_id': '1'}); - const subDomain = extractSubDomain({'sub_domain': 'prebid'}); - expect(cid).to.be.undefined; - expect(pid).to.be.undefined; - expect(subDomain).to.be.undefined; - }); - - it('should return value when param supported', function () { - const cid = extractCID({'cId': '1'}); - const pid = extractPID({'pId': '2'}); - const subDomain = extractSubDomain({'subDomain': 'prebid'}); - expect(cid).to.be.equal('1'); - expect(pid).to.be.equal('2'); - expect(subDomain).to.be.equal('prebid'); - }); - }); - - describe('unique deal id', function () { - before(function () { - getGlobal().bidderSettings = { - illumin: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - const key = 'myKey'; - let uniqueDealId; - beforeEach(() => { - uniqueDealId = getUniqueDealId(storage, key, 0); - }) - - it('should get current unique deal id', function (done) { - // waiting some time so `now` will become past - setTimeout(() => { - const current = getUniqueDealId(storage, key); - expect(current).to.be.equal(uniqueDealId); - done(); - }, 200); - }); - - it('should get new unique deal id on expiration', function (done) { - setTimeout(() => { - const current = getUniqueDealId(storage, key, 100); - expect(current).to.not.be.equal(uniqueDealId); - done(); - }, 200) - }); - }); - - describe('storage utils', function () { - before(function () { - getGlobal().bidderSettings = { - illumin: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - it('should get value from storage with create param', function () { - const now = Date.now(); - const clock = useFakeTimers({ - shouldAdvanceTime: true, - now - }); - setStorageItem(storage, 'myKey', 2020); - const {value, created} = getStorageItem(storage, 'myKey'); - expect(created).to.be.equal(now); - expect(value).to.be.equal(2020); - expect(typeof value).to.be.equal('number'); - expect(typeof created).to.be.equal('number'); - clock.restore(); - }); - - it('should get external stored value', function () { - const value = 'superman' - window.localStorage.setItem('myExternalKey', value); - const item = getStorageItem(storage, 'myExternalKey'); - expect(item).to.be.equal(value); - }); - - it('should parse JSON value', function () { - const data = JSON.stringify({event: 'send'}); - const {event} = tryParseJSON(data); - expect(event).to.be.equal('send'); - }); - - it('should get original value on parse fail', function () { - const value = 21; - const parsed = tryParseJSON(value); - expect(typeof parsed).to.be.equal('number'); - expect(parsed).to.be.equal(value); - }); - }); -}); diff --git a/test/spec/modules/imRtdProvider_spec.js b/test/spec/modules/imRtdProvider_spec.js deleted file mode 100644 index b06afc5a8..000000000 --- a/test/spec/modules/imRtdProvider_spec.js +++ /dev/null @@ -1,209 +0,0 @@ -import { - imRtdSubmodule, - storage, - getBidderFunction, - getCustomBidderFunction, - setRealTimeData, - getRealTimeData, - getApiCallback, - imUidLocalName, - imVidCookieName, - imRtdLocalName -} from 'modules/imRtdProvider.js' -import { timestamp } from '../../../src/utils.js' - -describe('imRtdProvider', function () { - let getLocalStorageStub; - let getCookieStub; - - const testReqBidsConfigObj = { - adUnits: [ - { - bids: ['test1', 'test2'] - } - ] - }; - const onDone = function() { return true }; - const moduleConfig = { - params: { - cid: 5126, - setGptKeyValues: true, - maxSegments: 2 - } - } - - beforeEach(function (done) { - getLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); - getCookieStub = sinon.stub(storage, 'getCookie'); - done(); - }); - - afterEach(function () { - getLocalStorageStub.restore(); - getCookieStub.restore(); - }); - - describe('imRtdSubmodule', function () { - it('should initialise and return true', function () { - expect(imRtdSubmodule.init()).to.equal(true) - }) - }) - - describe('getBidderFunction', function () { - const assumedBidder = [ - 'pubmatic', - 'fluct' - ]; - assumedBidder.forEach(bidderName => { - it(`should return bidderFunction with assumed bidder: ${bidderName}`, function () { - expect(getBidderFunction(bidderName)).to.exist.and.to.be.a('function'); - }); - - it(`should return bid with correct key data: ${bidderName}`, function () { - const bid = {bidder: bidderName}; - expect(getBidderFunction(bidderName)(bid, {'im_segments': ['12345', '67890']}, {params: {}})).to.equal(bid); - }); - it(`should return bid without data: ${bidderName}`, function () { - const bid = {bidder: bidderName}; - expect(getBidderFunction(bidderName)(bid, '', {params: {}})).to.equal(bid); - }); - }); - it(`should return null with unexpected bidder`, function () { - expect(getBidderFunction('test')).to.equal(null); - }); - describe('fluct bidder function', function () { - it('should return a bid w/o im_segments if not any exists', function () { - const bid = {bidder: 'fluct'}; - expect(getBidderFunction('fluct')(bid, '', {params: {}})).to.eql(bid); - }); - it('should return a bid w/ im_segments if any exists', function () { - const bid = { - bidder: 'fluct', - params: { - kv: { - foo: ['foo1'] - } - } - }; - expect(getBidderFunction('fluct')( - bid, - {im_segments: ['12345', '67890', '09876']}, - {params: {maxSegments: 2}} - )) - .to.eql( - { - bidder: 'fluct', - params: { - kv: { - foo: ['foo1'], - imsids: ['12345', '67890'] - } - } - } - ); - }); - }); - }) - - describe('getCustomBidderFunction', function () { - it('should return config function', function () { - const config = { - params: { - overwrites: { - testBidder: function() { - return 'testString'; - } - } - } - }; - const bidder = 'testBidder' - expect(getCustomBidderFunction(config, bidder)).to.exist.and.to.be.a('function'); - expect(getCustomBidderFunction(config, bidder)()).to.equal('testString'); - }) - it('should return null when overwrites falsy', function () { - const config = { - params: { - overwrites: { - testBidder: null - } - } - }; - const bidder = 'testBidder' - expect(getCustomBidderFunction(config, bidder)).to.equal(null); - }) - }) - - describe('processBidderFunction', function () { - - }) - - describe('setRealTimeData', function () { - it('should return true when empty params', function () { - expect(setRealTimeData({adUnits: []}, {params: {}}, {im_segments: []})).to.equal(undefined) - }); - it('should return true when overwrites and bid params', function () { - const config = { - params: { - overwrites: { - testBidder: function() { return true } - } - } - }; - expect(setRealTimeData(testReqBidsConfigObj, config, {im_segments: []})).to.equal(undefined) - }); - }) - - describe('getRealTimeData', function () { - it('should initialise and return when empty params', function () { - expect(getRealTimeData({}, function() {}, {})).to.equal(undefined) - }); - - it('should initialise and return with config', function () { - expect(getRealTimeData(testReqBidsConfigObj, onDone, moduleConfig)).to.equal(undefined) - }); - - it('should return the uid when sids(rtd) not expired', function () { - getLocalStorageStub.withArgs(imUidLocalName).returns('testUid'); - getLocalStorageStub.withArgs(imRtdLocalName).returns('testSids'); - getCookieStub.withArgs(imVidCookieName).returns('testUid'); - getLocalStorageStub.withArgs(`${imRtdLocalName}_mt`).returns(new Date(timestamp()).toUTCString()); - expect(getRealTimeData(testReqBidsConfigObj, onDone, moduleConfig)).to.equal(undefined) - }); - - it('should return the uid when it exists uid, sids(rtd), vid in storages and sids(rtd) expired', function () { - getLocalStorageStub.withArgs(imUidLocalName).returns('testUid'); - getLocalStorageStub.withArgs(imRtdLocalName).returns('testSids'); - getCookieStub.withArgs(imVidCookieName).returns('testUid'); - getLocalStorageStub.withArgs(`${imRtdLocalName}_mt`).returns(0); - expect(getRealTimeData(testReqBidsConfigObj, onDone, moduleConfig)).to.equal(undefined) - }); - - it('should return the uid when uid not expired', function () { - getLocalStorageStub.withArgs(imUidLocalName).returns('testUid'); - getLocalStorageStub.withArgs(imRtdLocalName).returns('testSids'); - getCookieStub.withArgs(imVidCookieName).returns('testUid'); - getLocalStorageStub.withArgs(`${imUidLocalName}_mt`).returns(new Date(timestamp()).toUTCString()); - expect(getRealTimeData(testReqBidsConfigObj, onDone, moduleConfig)).to.equal(undefined) - }); - }) - - describe('getApiCallback', function () { - it('should return success and error functions', function () { - const res = getApiCallback(testReqBidsConfigObj, false, moduleConfig); - expect(res.success).to.exist.and.to.be.a('function'); - expect(res.error).to.exist.and.to.be.a('function'); - }); - - it('should return "undefined" success', function () { - const res = getApiCallback(testReqBidsConfigObj, false, moduleConfig); - const successResponse = '{"uid": "testid", "segments": "testsegment", "vid": "testvid"}'; - expect(res.success(successResponse, {status: 200})).to.equal(undefined); - expect(res.error()).to.equal(undefined); - }); - - it('should return "undefined" catch error response', function () { - const res = getApiCallback(testReqBidsConfigObj, false, moduleConfig); - expect(res.success('error response', {status: 400})).to.equal(undefined); - }); - }) -}) diff --git a/test/spec/modules/impactifyBidAdapter_spec.js b/test/spec/modules/impactifyBidAdapter_spec.js deleted file mode 100644 index 464bf4f59..000000000 --- a/test/spec/modules/impactifyBidAdapter_spec.js +++ /dev/null @@ -1,563 +0,0 @@ -import { expect } from 'chai'; -import { spec, STORAGE, STORAGE_KEY } from 'modules/impactifyBidAdapter.js'; -import * as utils from 'src/utils.js'; -import sinon from 'sinon'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -const BIDDER_CODE = 'impactify'; -const BIDDER_ALIAS = ['imp']; -const DEFAULT_CURRENCY = 'USD'; -const DEFAULT_VIDEO_WIDTH = 640; -const DEFAULT_VIDEO_HEIGHT = 480; -const ORIGIN = 'https://sonic.impactify.media'; -const LOGGER_URI = 'https://logger.impactify.media'; -const AUCTIONURI = '/bidder'; -const COOKIESYNCURI = '/static/cookie_sync.html'; -const GVLID = 606; - -var gdprData = { - 'consentString': 'BOh7mtYOh7mtYAcABBENCU-AAAAncgPIXJiiAoao0PxBFkgCAC8ACIAAQAQQAAIAAAIAAAhBGAAAQAQAEQgAAAAAAABAAAAAAAAAAAAAAACAAAAAAAACgAAAAABAAAAQAAAAAAA', - 'gdprApplies': true -}; - -describe('ImpactifyAdapter', function () { - let getLocalStorageStub; - let localStorageIsEnabledStub; - let sandbox; - - beforeEach(function () { - getGlobal().bidderSettings = { - impactify: { - storageAllowed: true - } - }; - sinon.stub(document.body, 'appendChild'); - sandbox = sinon.createSandbox(); - getLocalStorageStub = sandbox.stub(STORAGE, 'getDataFromLocalStorage'); - localStorageIsEnabledStub = sandbox.stub(STORAGE, 'localStorageIsEnabled'); - }); - - afterEach(function () { - getGlobal().bidderSettings = {}; - document.body.appendChild.restore(); - sandbox.restore(); - }); - - describe('isBidRequestValid', function () { - const validBids = [ - { - bidder: 'impactify', - params: { - appId: 'example.com', - format: 'screen', - style: 'inline' - } - }, - { - bidder: 'impactify', - params: { - appId: 'example.com', - format: 'display', - style: 'static' - } - } - ]; - - const videoBidRequests = [ - { - bidder: 'impactify', - params: { - appId: '1', - format: 'screen', - style: 'inline' - }, - mediaTypes: { - video: { - context: 'instream' - } - }, - adUnitCode: 'adunit-code', - sizes: [[DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT]], - bidId: '123456789', - bidderRequestId: '987654321', - auctionId: '19ab94a9-b0d7-4ed7-9f80-ad0c033cf1b1', - transactionId: 'f7b2c372-7a7b-11eb-9439-0242ac130002', - userId: { - pubcid: '87a0327b-851c-4bb3-a925-0c7be94548f5' - }, - userIdAsEids: [ - { - source: 'pubcid.org', - uids: [ - { - id: '87a0327b-851c-4bb3-a925-0c7be94548f5', - atype: 1 - } - ] - } - ] - } - ]; - const videoBidderRequest = { - bidderRequestId: '98845765110', - auctionId: '165410516454', - bidderCode: 'impactify', - bids: [ - { - ...videoBidRequests[0] - } - ], - refererInfo: { - referer: 'https://impactify.io' - } - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(validBids[0])).to.equal(true); - expect(spec.isBidRequestValid(validBids[1])).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const bid = Object.assign({}, validBids[0]); - delete bid.params; - bid.params = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - - const bid2 = Object.assign({}, validBids[1]); - delete bid2.params; - bid2.params = {}; - expect(spec.isBidRequestValid(bid2)).to.equal(false); - }); - - it('should return false when appId is missing', () => { - const bid = utils.deepClone(validBids[0]); - delete bid.params.appId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - - const bid2 = utils.deepClone(validBids[1]); - delete bid2.params.appId; - expect(spec.isBidRequestValid(bid2)).to.equal(false); - }); - - it('should return false when appId is not a string', () => { - const bid = utils.deepClone(validBids[0]); - const bid2 = utils.deepClone(validBids[1]); - - bid.params.appId = 123; - bid2.params.appId = 123; - expect(spec.isBidRequestValid(bid)).to.equal(false); - expect(spec.isBidRequestValid(bid2)).to.equal(false); - - bid.params.appId = false; - bid2.params.appId = false; - expect(spec.isBidRequestValid(bid)).to.equal(false); - expect(spec.isBidRequestValid(bid2)).to.equal(false); - - bid.params.appId = void (0); - bid2.params.appId = void (0); - expect(spec.isBidRequestValid(bid)).to.equal(false); - expect(spec.isBidRequestValid(bid2)).to.equal(false); - - bid.params.appId = {}; - bid2.params.appId = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - expect(spec.isBidRequestValid(bid2)).to.equal(false); - }); - - it('should return false when format is missing', () => { - const bid = utils.deepClone(validBids[0]); - delete bid.params.format; - - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when format is not a string', () => { - const bid = utils.deepClone(validBids[0]); - const bid2 = utils.deepClone(validBids[1]); - - bid.params.format = 123; - bid2.params.format = 123; - expect(spec.isBidRequestValid(bid)).to.equal(false); - expect(spec.isBidRequestValid(bid)).to.equal(false); - - bid.params.format = false; - bid2.params.format = false; - expect(spec.isBidRequestValid(bid)).to.equal(false); - expect(spec.isBidRequestValid(bid2)).to.equal(false); - - bid.params.format = void (0); - bid2.params.format = void (0); - expect(spec.isBidRequestValid(bid)).to.equal(false); - expect(spec.isBidRequestValid(bid2)).to.equal(false); - - bid.params.format = {}; - bid2.params.format = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - expect(spec.isBidRequestValid(bid2)).to.equal(false); - }); - - it('should return false when format is not equals to screen or display', () => { - const bid = utils.deepClone(validBids[0]); - if (bid.params.format !== 'screen' && bid.params.format !== 'display') { - expect(spec.isBidRequestValid(bid)).to.equal(false); - } - - const bid2 = utils.deepClone(validBids[1]); - if (bid2.params.format !== 'screen' && bid2.params.format !== 'display') { - expect(spec.isBidRequestValid(bid2)).to.equal(false); - } - }); - - it('should return false when style is missing', () => { - const bid = utils.deepClone(validBids[0]); - delete bid.params.style; - - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when style is not a string', () => { - const bid = utils.deepClone(validBids[0]); - - bid.params.style = 123; - expect(spec.isBidRequestValid(bid)).to.equal(false); - - bid.params.style = false; - expect(spec.isBidRequestValid(bid)).to.equal(false); - - bid.params.style = void (0); - expect(spec.isBidRequestValid(bid)).to.equal(false); - - bid.params.style = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - describe('buildRequests', function () { - const videoBidRequests = [ - { - bidder: 'impactify', - params: { - appId: '1', - format: 'screen', - style: 'inline' - }, - mediaTypes: { - video: { - context: 'instream' - } - }, - adUnitCode: 'adunit-code', - sizes: [[DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT]], - bidId: '123456789', - bidderRequestId: '987654321', - auctionId: '19ab94a9-b0d7-4ed7-9f80-ad0c033cf1b1', - transactionId: 'f7b2c372-7a7b-11eb-9439-0242ac130002', - userId: { - pubcid: '87a0327b-851c-4bb3-a925-0c7be94548f5' - }, - userIdAsEids: [ - { - source: 'pubcid.org', - uids: [ - { - id: '87a0327b-851c-4bb3-a925-0c7be94548f5', - atype: 1 - } - ] - } - ] - } - ]; - const videoBidderRequest = { - bidderRequestId: '98845765110', - auctionId: '165410516454', - bidderCode: 'impactify', - bids: [ - { - ...videoBidRequests[0] - } - ], - refererInfo: { - referer: 'https://impactify.io' - } - }; - - it('should pass bidfloor', function () { - videoBidRequests[0].getFloor = function () { - return { - currency: 'USD', - floor: 1.23, - } - } - - const res = spec.buildRequests(videoBidRequests, videoBidderRequest); - const resData = JSON.parse(res.data) - expect(resData.imp[0].bidfloor).to.equal(1.23) - }); - - it('sends video bid request to ENDPOINT via POST', function () { - localStorageIsEnabledStub.returns(true); - - getLocalStorageStub.returns('testValue'); - - const request = spec.buildRequests(videoBidRequests, videoBidderRequest); - - expect(request.url).to.equal(ORIGIN + AUCTIONURI); - expect(request.method).to.equal('POST'); - expect(request.options.customHeaders['x-impact']).to.equal('testValue'); - }); - - it('should set header value from localstorage correctly', function () { - localStorageIsEnabledStub.returns(true); - getLocalStorageStub.returns('testValue'); - - const request = spec.buildRequests(videoBidRequests, videoBidderRequest); - expect(request.options.customHeaders).to.be.an('object'); - expect(request.options.customHeaders['x-impact']).to.equal('testValue'); - }); - - it('should set header value to empty if localstorage is not enabled', function () { - localStorageIsEnabledStub.returns(false); - - const request = spec.buildRequests(videoBidRequests, videoBidderRequest); - expect(request.options.customHeaders).to.be.undefined; - }); - }); - describe('interpretResponse', function () { - it('should get correct bid response', function () { - const response = { - id: '19ab94a9-b0d7-4ed7-9f80-ad0c033cf1b1', - seatbid: [ - { - bid: [ - { - id: '65820304700829014', - impid: '462c08f20d428', - price: 3.40, - adm: '', - adid: '97517771', - iurl: 'https://fra1-ib.adnxs.com/cr?id=97517771', - cid: '9325', - crid: '97517771', - w: 1, - h: 1, - hash: 'test', - expiry: 166192938, - meta: { 'advertiserDomains': ['testdomain.com'] }, - ext: { - prebid: { - 'type': 'video' - }, - bidder: { - prebid: { - type: 'video', - video: { - duration: 30, - primary_category: '' - } - }, - bidder: { - appnexus: { - brand_id: 182979, - auction_id: '8657683934873599656', - bidder_id: 2, - bid_ad_type: 1, - creative_info: { - video: { - duration: 30, - mimes: [ - 'video/x-flv', - 'video/mp4', - 'video/webm' - ] - } - } - } - } - } - } - } - ], - seat: 'impactify' - } - ], - cur: DEFAULT_CURRENCY, - ext: { - responsetimemillis: { - impactify: 114 - }, - prebid: { - auctiontimestamp: 1614587024591 - } - } - }; - const bidderRequest = { - bids: [ - { - bidId: '462c08f20d428', - adUnitCode: '/19968336/header-bid-tag-1', - auctionId: '19ab94a9-b0d7-4ed7-9f80-ad0c033cf1b1', - bidder: 'impactify', - sizes: [[DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT]], - mediaTypes: { - video: { - context: 'outstream' - } - } - }, - ] - } - const expectedResponse = [ - { - id: '65820304700829014', - requestId: '462c08f20d428', - cpm: 3.40, - currency: DEFAULT_CURRENCY, - netRevenue: true, - ad: '', - width: 1, - height: 1, - hash: 'test', - expiry: 166192938, - meta: { 'advertiserDomains': ['testdomain.com'] }, - ttl: 300, - creativeId: '97517771' - } - ]; - const result = spec.interpretResponse({ body: response }, bidderRequest); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - }); - describe('getUserSyncs', function () { - const videoBidRequests = [ - { - bidder: 'impactify', - params: { - appId: '1', - format: 'screen', - style: 'inline' - }, - mediaTypes: { - video: { - context: 'instream' - } - }, - adUnitCode: 'adunit-code', - sizes: [[DEFAULT_VIDEO_WIDTH, DEFAULT_VIDEO_HEIGHT]], - bidId: '123456789', - bidderRequestId: '987654321', - auctionId: '19ab94a9-b0d7-4ed7-9f80-ad0c033cf1b1', - transactionId: 'f7b2c372-7a7b-11eb-9439-0242ac130002' - } - ]; - const videoBidderRequest = { - bidderRequestId: '98845765110', - auctionId: '165410516454', - bidderCode: 'impactify', - bids: [ - { - ...videoBidRequests[0] - } - ], - refererInfo: { - referer: 'https://impactify.io' - } - }; - const validResponse = { - id: '19ab94a9-b0d7-4ed7-9f80-ad0c033cf1b1', - seatbid: [ - { - bid: [ - { - id: '65820304700829014', - impid: '462c08f20d428', - price: 3.40, - adm: '', - adid: '97517771', - iurl: 'https://fra1-ib.adnxs.com/cr?id=97517771', - cid: '9325', - crid: '97517771', - w: 1, - h: 1, - hash: 'test', - expiry: 166192938, - meta: { 'advertiserDomains': ['testdomain.com'] }, - ext: { - prebid: { - 'type': 'video' - }, - bidder: { - prebid: { - type: 'video', - video: { - duration: 30, - primary_category: '' - } - }, - bidder: { - appnexus: { - brand_id: 182979, - auction_id: '8657683934873599656', - bidder_id: 2, - bid_ad_type: 1, - creative_info: { - video: { - duration: 30, - mimes: [ - 'video/x-flv', - 'video/mp4', - 'video/webm' - ] - } - } - } - } - } - } - } - ], - seat: 'impactify' - } - ], - cur: DEFAULT_CURRENCY, - ext: { - responsetimemillis: { - impactify: 114 - }, - prebid: { - auctiontimestamp: 1614587024591 - } - } - }; - it('should return empty response if server response is false', function () { - const result = spec.getUserSyncs('bad', false, gdprData); - expect(result).to.be.empty; - }); - it('should return empty response if server response is empty', function () { - const result = spec.getUserSyncs('bad', [], gdprData); - expect(result).to.be.empty; - }); - it('should append the various values if they exist', function () { - const result = spec.getUserSyncs({ iframeEnabled: true }, validResponse, gdprData); - expect(result[0].url).to.include('gdpr=1'); - expect(result[0].url).to.include('gdpr_consent=BOh7mtYOh7mtYAcABBENCU-AAAAncgPIXJiiAoao0PxBFkgCAC8ACIAAQAQQAAIAAAIAAAhBGAAAQAQAEQgAAAAAAABAAAAAAAAAAAAAAACAAAAAAAACgAAAAABAAAAQAAAAAAA'); - }); - }); - - describe('On winning bid', function () { - const bid = { - ad: '', - cpm: '2' - }; - const result = spec.onBidWon(bid); - assert.ok(result); - }); - - describe('On bid Time out', function () { - const bid = { - ad: '', - cpm: '2' - }; - const result = spec.onTimeout(bid); - assert.ok(result); - }); -}) diff --git a/test/spec/modules/improvedigitalBidAdapter_spec.js b/test/spec/modules/improvedigitalBidAdapter_spec.js deleted file mode 100644 index 4d5038b79..000000000 --- a/test/spec/modules/improvedigitalBidAdapter_spec.js +++ /dev/null @@ -1,1382 +0,0 @@ -import {expect} from 'chai'; -import {CONVERTER, spec} from 'modules/improvedigitalBidAdapter.js'; -import {config} from 'src/config.js'; -import {deepClone} from 'src/utils.js'; -import {BANNER, NATIVE, VIDEO} from '../../../src/mediaTypes.js'; -import {deepSetValue} from '../../../src/utils.js'; -// load modules that register ORTB processors -import 'src/prebid.js'; -import 'modules/currency.js'; -import 'modules/userId/index.js'; -import 'modules/multibid/index.js'; -import 'modules/priceFloors.js'; -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; -import {decorateAdUnitsWithNativeParams} from '../../../src/native.js'; -import {hook} from '../../../src/hook.js'; -import {addFPDToBidderRequest} from '../../helpers/fpd.js'; -import * as prebidGlobal from 'src/prebidGlobal.js'; - -describe('Improve Digital Adapter Tests', function () { - const METHOD = 'POST'; - const AD_SERVER_BASE_URL = 'https://ad.360yield.com'; - const BASIC_ADS_BASE_URL = 'https://ad.360yield-basic.com'; - const PB_ENDPOINT = 'pb'; - const AD_SERVER_URL = `${AD_SERVER_BASE_URL}/${PB_ENDPOINT}`; - const BASIC_ADS_URL = `${BASIC_ADS_BASE_URL}/${PB_ENDPOINT}`; - const EXTEND_URL = 'https://pbs.360yield.com/openrtb2/auction'; - const IFRAME_SYNC_URL = 'https://hb.360yield.com/prebid-universal-creative/load-cookie.html'; - const INSTREAM_TYPE = 1; - const OUTSTREAM_TYPE = 3; - - const simpleBidRequest = { - bidder: 'improvedigital', - params: { - publisherId: 1234, - placementId: 1053688 - }, - adUnitCode: 'div-gpt-ad-1499748733608-0', - transactionId: 'f183e871-fbed-45f0-a427-c8a63c4c01eb', - bidId: '33e9500b21129f', - bidderRequestId: '2772c1e566670b', - auctionId: '192721e36a0239', - mediaTypes: { - banner: { - sizes: [[300, 250], [160, 600]] - } - }, - sizes: [[300, 250], [160, 600]] - }; - - const extendBidRequest = deepClone(simpleBidRequest); - extendBidRequest.params.extend = true; - - const videoParams = { - skip: 1, - skipmin: 5, - skipafter: 30 - } - - const instreamBidRequest = { - bidder: 'improvedigital', - params: { - publisherId: 1234, - placementId: 123456 - }, - adUnitCode: 'video1', - transactionId: 'vf183e871-fbed-45f0-a427-c8a63c4c01eb', - bidId: '33e9500b21129f', - bidderRequestId: 'v2772c1e566670b', - auctionId: 'v192721e36a0239', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480] - } - } - }; - - const outstreamBidRequest = deepClone(instreamBidRequest); - outstreamBidRequest.mediaTypes = { - video: { - context: 'outstream', - playerSize: [640, 480] - } - }; - - const nativeBidRequest = deepClone(simpleBidRequest); - nativeBidRequest.mediaTypes = { native: {} }; - nativeBidRequest.nativeParams = { - title: {required: true}, - body: {required: true} - }; - - const multiFormatBidRequest = deepClone(simpleBidRequest); - multiFormatBidRequest.mediaTypes = { - banner: { - sizes: [[300, 250], [160, 600]] - }, - native: {}, - video: { - context: 'outstream', - playerSize: [640, 480] - } - }; - - multiFormatBidRequest.nativeParams = { - body: { - required: true - } - }; - - const bidderRequest = { - ortb2: { - source: { - tid: 'mock-tid' - } - }, - bids: [simpleBidRequest], - }; - - const extendBidderRequest = { - bids: [extendBidRequest], - }; - - const instreamBidderRequest = { - bids: [instreamBidRequest], - }; - - const outstreamBidderRequest = { - bids: [outstreamBidRequest], - }; - - const multiFormatBidderRequest = { - bids: [multiFormatBidRequest], - }; - - const nativeBidderRequest = { - bids: [nativeBidRequest], - }; - - const gdprConsent = { - apiVersion: 2, - consentString: 'CONSENT', - vendorData: { purpose: { consents: { 1: true } } }, - gdprApplies: true, - addtlConsent: '1~1.35.41.101', - }; - - const bidderRequestGdpr = { - bids: [simpleBidRequest], - gdprConsent - }; - - const bidderRequestReferrer = { - bids: [simpleBidRequest], - refererInfo: { - page: 'https://blah.com/test.html', - domain: 'blah.com' - }, - }; - - function updateNativeParams(bidRequests) { - bidRequests = deepClone(bidRequests); - decorateAdUnitsWithNativeParams(bidRequests); - return bidRequests; - } - - function formatPublisherUrl(baseUrl, publisherId) { - return `${baseUrl}/${publisherId}/${PB_ENDPOINT}`; - } - - before(() => { - hook.ready(); - }); - - describe('isBidRequestValid', function () { - it('should return false when no bid', function () { - expect(spec.isBidRequestValid()).to.equal(false); - }); - - it('should return false when no bid.params', function () { - const bid = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when only one of placementId or publisherId is present', function () { - let bid = { - params: { - publisherId: 1234 - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - bid = { - params: { - placementId: 1234 - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when both placementId and publisherId are passed', function () { - expect(spec.isBidRequestValid(simpleBidRequest)).to.equal(true); - }); - }); - - describe('buildRequests', function () { - let getConfigStub = null; - let getGlobalStub = null; - - afterEach(function () { - if (getConfigStub) { - getConfigStub.restore(); - getConfigStub = null; - } - - if (getGlobalStub) { - getGlobalStub.restore(); - getGlobalStub = null; - } - }); - - it('should make a well-formed request objects', async function () { - const request = spec.buildRequests([simpleBidRequest], await addFPDToBidderRequest(bidderRequest))[0]; - expect(request).to.be.an('object'); - expect(request.method).to.equal(METHOD); - expect(request.options).to.be.an('object'); - expect(request.options.endpointCompression).to.equal(true); - expect(request.url).to.equal(formatPublisherUrl(AD_SERVER_BASE_URL, 1234)); - - const payload = JSON.parse(request.data); - expect(payload).to.be.an('object'); - expect(payload.id).to.be.a('string'); - expect(payload.tmax).not.to.exist; - expect(payload.regs).to.not.exist; - expect(payload.schain).to.not.exist; - sinon.assert.match(payload.source, {tid: 'mock-tid'}) - expect(payload.device).to.be.an('object'); - expect(payload.user).to.not.exist; - sinon.assert.match(payload.imp, [ - sinon.match({ - id: '33e9500b21129f', - secure: 1, - ext: { - bidder: { - placementId: 1053688, - } - }, - banner: { - format: [ - {w: 300, h: 250}, - {w: 160, h: 600}, - ] - } - }) - ]); - }); - - it('should make a well-formed request object for multi-format ad unit', function () { - const request = spec.buildRequests(updateNativeParams([multiFormatBidRequest]), multiFormatBidderRequest)[0]; - expect(request).to.be.an('object'); - expect(request.method).to.equal(METHOD); - expect(request.options).to.be.an('object'); - expect(request.options.endpointCompression).to.equal(true); - expect(request.url).to.equal(formatPublisherUrl(AD_SERVER_BASE_URL, 1234)); - - const payload = JSON.parse(request.data); - expect(payload).to.be.an('object'); - sinon.assert.match(payload.imp, [ - sinon.match({ - id: '33e9500b21129f', - secure: 1, - ext: { - bidder: { - placementId: 1053688, - } - }, - ...(FEATURES.VIDEO && { - video: { - w: 640, - h: 480, - mimes: ['video/mp4'], - } - }), - banner: { - format: [ - {w: 300, h: 250}, - {w: 160, h: 600}, - ] - } - }) - ]); - if (FEATURES.NATIVE) { - sinon.assert.match(payload.imp[0], { - native: { - ver: '1.2' - }, - }) - const nativeReq = JSON.parse(payload.imp[0].native.request); - sinon.assert.match(nativeReq, { - eventtrackers: [ - {event: 1, methods: [1, 2]}, - ], - 'assets': [ - sinon.match({'required': 1, 'data': {'type': 2}}) - ] - }); - } - }); - - if (FEATURES.NATIVE) { - it('should make a well-formed native request', function () { - const payload = JSON.parse(spec.buildRequests(updateNativeParams([nativeBidRequest]), {})[0].data); - const nativeReq = JSON.parse(payload.imp[0].native.request); - sinon.assert.match(nativeReq, { - eventtrackers: [ - {event: 1, methods: [1, 2]}, - ], - assets: [ - sinon.match({required: 1, title: {len: 140}}), - sinon.match({required: 1, data: {type: 2}}) - ] - }) - }); - - it('should not make native request when nativeOrtbRequest is undefined', function () { - const requests = updateNativeParams([nativeBidRequest]); - delete requests[0].nativeOrtbRequest; - const payload = JSON.parse(spec.buildRequests(requests, {})[0].data); - expect(payload.imp[0].native).to.not.exist; - }); - - it('should not make native request when no assets', function () { - const requests = updateNativeParams([{...nativeBidRequest, nativeParams: {}}]) - const payload = JSON.parse(spec.buildRequests(requests, {})[0].data); - expect(payload.imp[0].native).to.not.exist; - }); - } - - it('should add keyValues', function () { - const bidRequest = Object.assign({}, simpleBidRequest); - const keyValues = { - testKey: [ - 'testValue' - ] - }; - bidRequest.params.keyValues = keyValues; - const payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest)[0].data); - expect(payload.imp[0].ext.bidder.keyValues).to.deep.equal(keyValues); - }); - - it('should add currency', function () { - config.setConfig({currency: {adServerCurrency: 'JPY'}}); - try { - const bidRequest = Object.assign({}, simpleBidRequest); - const payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest)[0].data); - expect(payload.cur).to.deep.equal(['JPY']); - } finally { - config.resetConfig(); - } - }); - - it('should add bid floor correctly', function () { - getGlobalStub = sinon.stub(prebidGlobal, 'getGlobal').returns({ - convertCurrency: (cpm, from, to) => { - const conversionKeys = { 'EUR-USD': 1.75 }; - const conversionRate = conversionKeys[`${from}-${to}`]; - if (!conversionRate) { - throw new Error(`No conversion rate found for ${from}-${to}`); - } - return cpm * conversionRate; - } - }); - const bidRequest = deepClone(simpleBidRequest); - - // Floor price currency shouldn't be populated without a floor price - let payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest)[0].data); - expect(payload.imp[0].bidfloorcur).to.not.exist; - - // Default floor price currency - bidRequest.params.bidFloor = 0.05; - payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest)[0].data); - expect(payload.imp[0].bidfloor).to.equal(0.05); - expect(payload.imp[0].bidfloorcur).to.equal('USD'); - - // Floor price sent as is when currency cannot be converted to default bid adapter currency - bidRequest.params.bidFloorCur = 'UAH'; - bidRequest.params.bidFloor = 0.05; - payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest)[0].data); - expect(payload.imp[0].bidfloor).to.equal(0.05); - expect(payload.imp[0].bidfloorcur).to.equal('UAH'); - - // Floor price currency converted to default bid adapter currency - bidRequest.params.bidFloorCur = 'eUR'; - payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest)[0].data); - expect(payload.imp[0].bidfloor).to.equal(0.08750000000000001); - expect(payload.imp[0].bidfloorcur).to.equal('USD'); - - // getFloor defined -> use it over bidFloor - const getFloorResponse = { currency: 'USD', floor: 3 }; - bidRequest.getFloor = () => getFloorResponse; - payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest)[0].data); - expect(payload.imp[0].bidfloor).to.equal(3); - expect(payload.imp[0].bidfloorcur).to.equal('USD'); - }); - - it('should add GDPR consent string', async function () { - const bidRequest = Object.assign({}, simpleBidRequest); - const payload = JSON.parse(spec.buildRequests([bidRequest], await addFPDToBidderRequest(bidderRequestGdpr))[0].data); - expect(payload.regs.ext.gdpr).to.exist.and.to.equal(1); - expect(payload.user.ext.consent).to.equal('CONSENT'); - expect(payload.user.ext.ConsentedProvidersSettings.consented_providers).to.exist.and.to.deep.equal('1~1.35.41.101'); - }); - - it('should not add consented providers when empty', async function () { - const bidderRequestGdprEmptyAddtl = deepClone(bidderRequestGdpr); - bidderRequestGdprEmptyAddtl.gdprConsent.addtlConsent = '1~'; - const bidRequest = Object.assign({}, simpleBidRequest); - const payload = JSON.parse(spec.buildRequests([bidRequest], await addFPDToBidderRequest(bidderRequestGdprEmptyAddtl))[0].data); - expect(payload.user.ext.consented_providers_settings).to.not.exist; - }); - - it('should add ConsentedProvidersSettings when extend mode enabled', async function () { - const bidRequest = deepClone(extendBidRequest); - const payload = JSON.parse(spec.buildRequests([bidRequest], await addFPDToBidderRequest(bidderRequestGdpr))[0].data); - expect(payload.regs.ext.gdpr).to.exist.and.to.equal(1); - expect(payload.user.ext.consent).to.equal('CONSENT'); - expect(payload.user.ext.ConsentedProvidersSettings.consented_providers).to.exist.and.to.equal('1~1.35.41.101'); - expect(payload.user.ext.consented_providers_settings).to.not.exist; - }); - - it('should add CCPA consent string', async function () { - const bidRequest = Object.assign({}, simpleBidRequest); - const request = spec.buildRequests([bidRequest], await addFPDToBidderRequest({...bidderRequest, ...{ uspConsent: '1YYY' }})); - const payload = JSON.parse(request[0].data); - expect(payload.regs.ext.us_privacy).to.equal('1YYY'); - }); - - it('should add COPPA flag', async function () { - getConfigStub = sinon.stub(config, 'getConfig'); - getConfigStub.withArgs('coppa').returns(true); - let bidRequest = Object.assign({}, simpleBidRequest); - let payload = JSON.parse(spec.buildRequests([bidRequest], await addFPDToBidderRequest(bidderRequestGdpr))[0].data); - expect(payload.regs.coppa).to.equal(1); - getConfigStub.withArgs('coppa').returns(false); - bidRequest = Object.assign({}, simpleBidRequest); - payload = JSON.parse(spec.buildRequests([bidRequest], await addFPDToBidderRequest(bidderRequestGdpr))[0].data); - expect(payload.regs.coppa).to.equal(0); - }); - - it('should add referrer', async function () { - const bidRequest = Object.assign({}, simpleBidRequest); - const request = spec.buildRequests([bidRequest], await addFPDToBidderRequest(bidderRequestReferrer))[0]; - const payload = JSON.parse(request.data); - expect(payload.site.page).to.equal('https://blah.com/test.html'); - }); - - it('should add timeout', function () { - const bidderRequestTimeout = deepClone(bidderRequest); - // Int - bidderRequestTimeout.timeout = 300; - const bidRequest = Object.assign({}, simpleBidRequest); - let request = spec.buildRequests([bidRequest], bidderRequestTimeout)[0]; - expect(JSON.parse(request.data).tmax).to.equal(300); - - // String - bidderRequestTimeout.timeout = '500'; - request = spec.buildRequests([bidRequest], bidderRequestTimeout)[0]; - expect(JSON.parse(request.data).tmax).to.equal(500); - }); - - it('should not add video params for banner', function () { - const bidRequest = deepClone(simpleBidRequest); - bidRequest.params.video = videoParams; - const request = spec.buildRequests([bidRequest], bidderRequest)[0]; - const payload = JSON.parse(request.data); - expect(payload.imp[0].video).to.not.exist; - }); - - if (FEATURES.VIDEO) { - it('should set video params for instream', function() { - const bidRequest = deepClone(instreamBidRequest); - delete bidRequest.mediaTypes.video.playerSize; - const videoParams = { - mimes: ['video/mp4'], - skip: 1, - skipmin: 5, - skipafter: 30, - minduration: 15, - maxduration: 60, - startdelay: 5, - minbitrate: 500, - maxbitrate: 2000, - w: 1024, - h: 640 - }; - bidRequest.params.video = videoParams; - const request = spec.buildRequests([bidRequest], bidderRequest)[0]; - const payload = JSON.parse(request.data); - expect(payload.imp[0].video).to.deep.include(videoParams); - }); - - it('should set video playerSize over video params', () => { - const bidRequest = deepClone(instreamBidRequest); - bidRequest.params.video = { - w: 1024, h: 640 - } - const request = spec.buildRequests([bidRequest], bidderRequest)[0]; - const payload = JSON.parse(request.data); - expect(payload.imp[0].video.h).equal(480); - expect(payload.imp[0].video.w).equal(640); - }); - - it('should ignore invalid/unexpected video params', function() { - const bidRequest = deepClone(instreamBidRequest); - // 1 - const videoTest = { - skip: 1, - skipmin: 5, - skipafter: 30 - } - const videoTestInvParam = Object.assign({}, videoTest); - videoTestInvParam.blah = 1; - bidRequest.params.video = videoTestInvParam; - const request = spec.buildRequests([bidRequest], {})[0]; - const payload = JSON.parse(request.data); - expect(payload.imp[0].video.blah).not.to.exist; - }); - - it('should set video params for outstream', function() { - const bidRequest = deepClone(outstreamBidRequest); - bidRequest.params.video = videoParams; - const request = spec.buildRequests([bidRequest], {})[0]; - const payload = JSON.parse(request.data); - expect(payload.imp[0].video).to.deep.equal({...{ - mimes: ['video/mp4'], - w: bidRequest.mediaTypes.video.playerSize[0], - h: bidRequest.mediaTypes.video.playerSize[1], - }, - ...videoParams}); - }); - // - it('should set video params for multi-format', function() { - const bidRequest = deepClone(multiFormatBidRequest); - bidRequest.params.video = videoParams; - const request = spec.buildRequests([bidRequest], {})[0]; - const payload = JSON.parse(request.data); - const testVideoParams = Object.assign({ - w: 640, - h: 480, - mimes: ['video/mp4'], - }, videoParams); - expect(payload.imp[0].video).to.deep.equal(testVideoParams); - }); - } - - it('should add schain', function () { - const schain = '{"ver":"1.0","complete":1,"nodes":[{"asi":"headerlift.com","sid":"xyz","hp":1}]}'; - const bidRequest = Object.assign({}, simpleBidRequest); - - // Add schain to both locations in the bid - bidRequest.ortb2 = { - source: { - ext: {schain: schain} - } - }; - - // Add schain to bidderRequest as well - const modifiedBidderRequest = { - ...bidderRequestReferrer, - ortb2: { - source: { - ext: {schain: schain} - } - } - }; - - const request = spec.buildRequests([bidRequest], modifiedBidderRequest)[0]; - const payload = JSON.parse(request.data); - expect(payload.source.ext.schain).to.equal(schain); - }); - - it('should add eids', function () { - const eids = [ - { - source: 'id5-sync.com', - uids: [{ - atype: 1, - id: '1111' - }] - } - ]; - const expectedUserObject = { ext: { eids: [{ - source: 'id5-sync.com', - uids: [{ - atype: 1, - id: '1111' - }] - }]}}; - const request = spec.buildRequests([simpleBidRequest], { - ...bidderRequestReferrer, - ortb2: {user: {ext: {eids: eids}}} - })[0]; - const payload = JSON.parse(request.data); - expect(payload.user).to.deep.equal(expectedUserObject); - }); - - it('should return 2 requests', function () { - const requests = spec.buildRequests([ - simpleBidRequest, - instreamBidRequest - ], bidderRequest); - expect(requests).to.be.an('array'); - expect(requests.length).to.equal(2); - }); - - it('should return one request in a single request mode', function () { - getConfigStub = sinon.stub(config, 'getConfig'); - getConfigStub.withArgs('improvedigital.singleRequest').returns(true); - const requests = spec.buildRequests([ simpleBidRequest, instreamBidRequest ], bidderRequest); - expect(requests).to.be.an('array'); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal(formatPublisherUrl(AD_SERVER_BASE_URL, 1234)); - const request = JSON.parse(requests[0].data); - expect(request.imp.length).to.equal(2); - expect(request.imp[0].banner).to.exist; - if (FEATURES.VIDEO) { expect(request.imp[1].video).to.exist; } - }); - - it('should create one request per endpoint in a single request mode', function () { - getConfigStub = sinon.stub(config, 'getConfig'); - getConfigStub.withArgs('improvedigital.singleRequest').returns(true); - const requests = spec.buildRequests([ extendBidRequest, simpleBidRequest, instreamBidRequest ], bidderRequest); - expect(requests).to.be.an('array'); - expect(requests.length).to.equal(2); - expect(requests[0].url).to.equal(EXTEND_URL); - expect(requests[1].url).to.equal(formatPublisherUrl(AD_SERVER_BASE_URL, 1234)); - const adServerRequest = JSON.parse(requests[1].data); - expect(adServerRequest.imp.length).to.equal(2); - expect(adServerRequest.imp[0].banner).to.exist; - if (FEATURES.VIDEO) { expect(adServerRequest.imp[1].video).to.exist; } - }); - - it('should set Prebid sizes in bid request', function () { - const request = spec.buildRequests([simpleBidRequest], bidderRequest)[0]; - const payload = JSON.parse(request.data); - sinon.assert.match(payload.imp[0].banner, { - format: [ - { w: 300, h: 250 }, - { w: 160, h: 600 } - ] - }); - }); - - it('should not add single size filter when using Prebid sizes', function () { - const bidRequest = Object.assign({}, simpleBidRequest); - const size = { - w: 800, - h: 600 - }; - bidRequest.params.size = size; - const request = spec.buildRequests([bidRequest], bidderRequest)[0]; - const payload = JSON.parse(request.data); - sinon.assert.match(payload.imp[0].banner, { - format: [ - { w: 300, h: 250 }, - { w: 160, h: 600 } - ] - }); - }); - - it('should not set site when app is defined in FPD', function () { - const ortb2 = {app: {content: 'XYZ'}}; - const request = spec.buildRequests([simpleBidRequest], {...bidderRequest, ortb2})[0]; - const payload = JSON.parse(request.data); - expect(payload.site).does.not.exist; - expect(payload.app).does.exist; - expect(payload.app.content).does.exist.and.equal('XYZ'); - }); - - it('should set correct site params', async function () { - let request = spec.buildRequests([simpleBidRequest], await addFPDToBidderRequest(bidderRequestReferrer))[0]; - let payload = JSON.parse(request.data); - expect(payload.site.content).does.not.exist; - expect(payload.site.page).does.exist.and.equal('https://blah.com/test.html'); - expect(payload.site.domain).does.exist.and.equal('blah.com'); - - const ortb2 = {site: {content: 'ZZZ'}}; - request = spec.buildRequests([simpleBidRequest], await addFPDToBidderRequest({...bidderRequestReferrer, ortb2}))[0]; - payload = JSON.parse(request.data); - expect(payload.site.content).does.exist.and.equal('ZZZ'); - expect(payload.site.page).does.exist.and.equal('https://blah.com/test.html'); - expect(payload.site.domain).does.exist.and.equal('blah.com'); - }); - - it('should call basic ads endpoint when no consent for purpose 1', function () { - const consent = deepClone(gdprConsent); - deepSetValue(consent, 'vendorData.purpose.consents.1', false); - const bidderRequestWithConsent = deepClone(bidderRequest); - bidderRequestWithConsent.gdprConsent = consent; - const request = spec.buildRequests([simpleBidRequest], bidderRequestWithConsent)[0]; - expect(request.url).to.equal(formatPublisherUrl(BASIC_ADS_BASE_URL, 1234)); - }); - - it('should set extend params when extend mode enabled from global configuration', function () { - getConfigStub = sinon.stub(config, 'getConfig'); - const bannerRequest = deepClone(simpleBidRequest); - const keyValues = { testKey: [ 'testValue' ] }; - bannerRequest.params.keyValues = keyValues; - - getConfigStub.withArgs('improvedigital.extend').returns(true); - const requests = spec.buildRequests([bannerRequest, instreamBidRequest], bidderRequest); - expect(requests[0].method).to.equal(METHOD); - expect(requests[0].url).to.equal(EXTEND_URL); - expect(requests[1].url).to.equal(EXTEND_URL); - // banner - let payload = JSON.parse(requests[0].data); - expect(payload.imp[0].ext.bidder).to.not.exist; - expect(payload.imp[0].ext.prebid.bidder.improvedigital).to.deep.equal({ - placementId: 1053688, - publisherId: 1234, - keyValues - }); - expect(payload.imp[0].ext.prebid.storedrequest.id).to.equal('1053688'); - // video - payload = JSON.parse(requests[1].data); - expect(payload.imp[0].ext.bidder).to.not.exist; - expect(payload.imp[0].ext.prebid.bidder.improvedigital.placementId).to.equal(123456); - expect(payload.imp[0].ext.prebid.storedrequest.id).to.equal('123456'); - }); - - it('should add max_bids param in imp.ext objects when bidLimit is specified in the bidderRequest', function () { - const bidderRequestDeepClone = deepClone(bidderRequest); - bidderRequestDeepClone.bidLimit = 3; - const requests = spec.buildRequests([simpleBidRequest, instreamBidRequest], bidderRequestDeepClone); - // banner - let payload = JSON.parse(requests[0].data); - expect(payload.imp[0].ext.max_bids).to.equal(3); - // video - payload = JSON.parse(requests[1].data); - expect(payload.imp[0].ext.max_bids).to.equal(3); - }); - - it('should not add max_bids param in imp.ext objects when bidLimit is not specified in the bidderRequest', function () { - const requests = spec.buildRequests([simpleBidRequest, instreamBidRequest], bidderRequest); - // banner - let payload = JSON.parse(requests[0].data); - expect(payload.imp[0].ext.max_bids).to.not.exist; - // video - payload = JSON.parse(requests[1].data); - expect(payload.imp[0].ext.max_bids).to.not.exist; - }); - - it('should set extend url when extend mode enabled in adunit params', function () { - const bidRequest = deepClone(extendBidRequest); - let request = spec.buildRequests([bidRequest], { bids: [bidRequest] })[0]; - expect(request.url).to.equal(EXTEND_URL); - - getConfigStub = sinon.stub(config, 'getConfig'); - - // adunit param takes precedence over the global config - getConfigStub.withArgs('improvedigital.extend').returns(false); - request = spec.buildRequests([bidRequest], { bids: [bidRequest] })[0]; - expect(request.url).to.equal(EXTEND_URL); - - bidRequest.params.extend = false; - getConfigStub.withArgs('improvedigital.extend').returns(true); - request = spec.buildRequests([bidRequest], { bids: [bidRequest] })[0]; - expect(request.url).to.equal(formatPublisherUrl(AD_SERVER_BASE_URL, 1234)); - - const requests = spec.buildRequests([bidRequest, instreamBidRequest], { bids: [bidRequest, instreamBidRequest] }); - expect(requests.length).to.equal(2); - expect(requests[0].url).to.equal(formatPublisherUrl(AD_SERVER_BASE_URL, 1234)); - expect(requests[1].url).to.equal(EXTEND_URL); - }); - - it('should add publisherId to request URL when available in request params', function() { - const bidRequest = deepClone(simpleBidRequest); - bidRequest.params.publisherId = 1000; - let request = spec.buildRequests([bidRequest], bidderRequest)[0]; - expect(request).to.be.an('object'); - sinon.assert.match(request, { - method: METHOD, - url: formatPublisherUrl(AD_SERVER_BASE_URL, 1000), - bidderRequest - }); - - const bidRequest2 = deepClone(simpleBidRequest) - bidRequest2.params.publisherId = 1002; - - const bidRequest3 = deepClone(extendBidRequest) - bidRequest3.params.publisherId = 1002; - - const request1 = spec.buildRequests([bidRequest, bidRequest2], bidderRequest)[0]; - expect(request1.url).to.equal(formatPublisherUrl(AD_SERVER_BASE_URL, 1000)); - const request2 = spec.buildRequests([bidRequest, bidRequest2], bidderRequest)[1]; - expect(request2.url).to.equal(formatPublisherUrl(AD_SERVER_BASE_URL, 1002)); - const request3 = spec.buildRequests([bidRequest, bidRequest3], bidderRequest)[1]; - expect(request3.url).to.equal(EXTEND_URL); - - // Enable single request mode - getConfigStub = sinon.stub(config, 'getConfig'); - getConfigStub.withArgs('improvedigital.singleRequest').returns(true); - try { - spec.buildRequests([bidRequest, bidRequest2], bidderRequest); - } catch (e) { - expect(e.name).to.exist.equal('Error') - expect(e.message).to.exist.equal(`All Improve Digital placements in a single call must have the same publisherId. Please check your 'params.publisherId' or turn off the single request mode.`) - } - - bidRequest2.params.publisherId = null; - request = spec.buildRequests([bidRequest, bidRequest2], bidderRequest)[0]; - expect(request.url).to.equal(formatPublisherUrl(AD_SERVER_BASE_URL, 1000)); - - const consent = deepClone(gdprConsent); - deepSetValue(consent, 'vendorData.purpose.consents.1', false); - const bidderRequestWithConsent = deepClone(bidderRequest); - bidderRequestWithConsent.gdprConsent = consent; - request = spec.buildRequests([bidRequest], bidderRequestWithConsent)[0]; - expect(request.url).to.equal(formatPublisherUrl(BASIC_ADS_BASE_URL, 1000)); - - deepSetValue(consent, 'vendorData.purpose.consents.1', true); - bidderRequestWithConsent.gdprConsent = consent; - request = spec.buildRequests([bidRequest], bidderRequestWithConsent)[0]; - expect(request.url).to.equal(formatPublisherUrl(AD_SERVER_BASE_URL, 1000)); - }); - }); - - const serverResponse = { - 'body': { - 'id': '99f9a9e6-5126-425b-822c-8b4edad2a719', - 'cur': 'EUR', - 'seatbid': [ - { - 'bid': [ - { - 'ext': { - 'improvedigital': { - 'line_item_id': 320896, - 'bidder_id': 0, - 'brand_name': '', - 'buying_type': 'classic', - 'agency_id': '0' - } - }, - 'crid': '510265', - 'price': 1.9200543539802946, - 'id': '35adfe19-d6e9-46b9-9f7d-20da7026b965', - 'w': 728, - 'impid': '33e9500b21129f', - 'h': 90, - 'adm': '  ', - 'cid': '123159' - } - ], - 'seat': 'improvedigital' - } - ], - ext: { - improvedigital: { - sync: [ - 'https://link1', - 'https://link2', - 'https://link3', - ] - } - } - } - }; - - const serverResponseTwoBids = { - 'body': { - 'id': '99f9a9e6-5126-425b-822c-8b4edad2a719', - 'cur': 'EUR', - 'seatbid': [ - { - 'bid': [ - { - 'ext': { - 'improvedigital': { - 'line_item_id': 320896, - 'bidder_id': 0, - 'brand_name': '', - 'buying_type': 'classic', - 'agency_id': '0' - } - }, - 'crid': '510265', - 'price': 1.9200543539802946, - 'id': '35adfe19-d6e9-46b9-9f7d-20da7026b965', - 'w': 728, - 'impid': '33e9500b21129f', - 'h': 90, - 'adm': '  ', - 'cid': '123159' - }, - { - 'ext': { - 'improvedigital': { - 'line_item_id': 320896, - 'bidder_id': 0, - 'brand_name': '', - 'buying_type': 'classic', - 'agency_id': '0' - } - }, - 'crid': '479163', - 'price': 1.9200543539802946, - 'id': '83c8d524-0955-4d0c-b558-4c9f3600e09b', - 'w': 300, - 'impid': '33e9500b21129f', - 'h': 250, - 'adm': '  ', - 'cid': '123159' - } - ], - 'seat': 'improvedigital_improvedigital' - } - ], - ext: { - improvedigital: { - sync: [ - 'https://link1', - 'https://link2', - 'https://link4', - ] - } - } - } - }; - - const serverResponseNative = { - body: { - 'id': '8201e669-bbbf-4f61-b9a2-4cb854033c82', - 'cur': 'EUR', - 'seatbid': [ - { - 'bid': [ - { - 'ext': { - 'improvedigital': { - 'line_item_id': 411331, - 'bidder_id': 0, - 'brand_name': '', - 'buying_type': 'classic', - 'agency_id': '0', - 'is_net': true - } - }, - 'crid': '544456', - 'id': '52098fad-20c1-476b-a4fa-41e275e5a4a5', - 'price': 1.8600000000000003, - 'adm': "{\"ver\":\"1.1\",\"imptrackers\":[\"https://secure.adnxs.com/imptr?id=52311&t=2\",\"https://euw-ice.360yield.com/imp_pixel?ic=hcUBlCANx1FabHBf6FR2gC7UO4xEyXahdZAn0-B5qL-bb3A74BJ1smyWIyW7IWcC0SOjSXzVpevTHXxTqJ.sf.Qhahyy6tSo.0j1QWfXlH8sM4-8vKWjMjw-x.IrJJNlwkQ0s1CdwcwTefcLXm5l2E-W19VhACuV7f3mgrZMNjiSw.SjJAfyPC3SIyAMRjYfj53UmjriQ46T7lhmkqxK8wHmksYCdbZc3PZESk8NWl28sxdjNvnYYCFMcJbeav.LOLabyTXfwy-1cEPbQs.IKMRZIKaqccTDPV3wOtzbNv0jQzatd3Nnv-PGFQcjQ-GW3i27W04Fws4kodpFSn-B6VwZAjzLzoyd5gBncyRnAyCplEbgHU5sZ1IyKHWjgCl3ZtRIK5vqrRD5D-xqgSnOi7-phG.CqZWDZ4bMDSfQg2ZnbvUTyGKcEl0WR59dW5izTMV4Fjizcrvr5T-t.zMbGwz.hGnmLIyhTqh.IcwW.GiDLVExlDlix5S1LXIWVsSyrQ==\"],\"assets\":[{\"id\":1,\"data\":{\"value\":\"ImproveDigital\",\"type\":1}},{\"id\":3,\"data\":{\"value\":\"Test content.\",\"type\":2}},{\"id\":0,\"title\":{\"text\":\"Sample Prebid Test Title\"}}],\"link\":{\"url\":\"https://euw-ice.360yield.com/click/hcUBlHOV7YhVse8RyBa0ajjyPa9Vt17e4g-1m3cRj3E67vq-RYux.SiUeAmBfNBcoOqkUc6A15AWmi4yFu5K-BdkaYjildyyk7fNLyR6hWr411kv4vrFwm5jrIBceuHS6K8oN69f.uCo8zGTdR2TbSlldwcpahQPlufZU.6VaMsu4IC53uEiUT5vb7kAw6TTlxuGBNq6zaGryiWEV2.N3YYJDTyYPh8tv-ZFyeFZFm0Gnjv.xWbC.70JcRUVU9UelQaPsTpTWYTXBhJt84YJUw1-GNtaLNVLSjjZbVoA2fsMti5p6OBmF.7u39on2OPgvseIkSmge7Pqg63pRqdP75hp.DAEk6OkcN1jGnwP2DSbvpaSbin5lVqjfO0B-wnQgfQTCUtM5v4JmkNweLhUf9Q-x.nPKLW5SccEk9ZFXzY2-1wpT3PWm8Tix3NRscLPZub9wHzL..pl6ip8cQ9hp16UjwT4H6RMAxL0R7bl-h2pAicGAzYmuO7ntRESKUoIWA==//http%3A%2F%2Fquantum-advertising.com%2Ffr%2F\"},\"jstracker\":\"\"}", - 'impid': '33e9500b21129f', - 'cid': '196108' - } - ], - 'seat': 'improvedigital' - } - ] - } - }; - - const serverResponseVideo = { - 'body': { - 'id': '8ed20675-8934-430c-b645-1ccd17b35839', - 'cur': 'EUR', - 'seatbid': [ - { - 'bid': [ - { - 'ext': { - 'improvedigital': { - 'line_item_id': 321329, - 'bidder_id': 0, - 'brand_name': '', - 'buying_type': 'classic', - 'agency_id': '0' - } - }, - 'crid': '484367', - 'price': 9.600271769901472, - 'id': 'b131fd7b-5759-4b72-800e-60e69291e7d9', - 'adomain': [ - 'improvedigital.com' - ], - 'impid': '33e9500b21129f', - 'adm': '', - 'w': 640, - 'h': 480, - 'cid': '123159' - } - ], - 'seat': 'improvedigital' - } - ], - } - }; - - const serverResponseRazr = { - body: { - 'id': '2adac6a5fe04df', - 'cur': 'EUR', - 'ext': { - 'improvedigital': { - 'sync': [ - 'https://d5p.de17a.com/getuid/improve_digital?publisher_user_id=ce26f11e-567a-4eb7-bf94-51752e293ca5&publisher_dsp_id=61&publisher_call_type=redirect&gdpr=1&gdpr_consent=CPU22FrPU22FrAcABBENCDCsAP_AAH_AAChQIltf_X__b3_j-_5_f_t0eY1P9_7_v-0zjhfdt-8N3f_X_L8X42M7vF36pq4KuR4Eu3LBIQdlHOHcTUmw6okVrzPsbk2cr7NKJ7PEmnMbO2dYGH9_n93TuZKY7______z_v-v_v____f_7-3_3__5_3---_e_V_99zLv9____39nP___9v-_9_____4IhgEmGpeQBdmWODJtGlUKIEYVhIdAKACigGFoisIHVwU7K4CfUELABCagJwIgQYgowYBAAIJAEhEQEgB4IBEARAIAAQAqwEIACNgEFgBYGAQACgGhYgRQBCBIQZHBUcpgQFSLRQT2ViCUHexphCGWeBFAo_oqEBGs0QLAyEhYOY4AkBLxZIHmKF8gAAAAA.f_gAD_gAAAAA&publisher_redirecturl=https://euw-ice.360yield.com/match' - ] - } - }, - 'seatbid': [ - { - 'bid': [ - { - 'ext': { - 'improvedigital': { - 'line_item_id': 410573, - 'bidder_id': 0, - 'brand_name': '', - 'buying_type': 'classic', - 'agency_id': '0' - } - }, - 'crid': '544063', - 'price': 1.9199364935359489, - 'id': '1fcf4dd8-a783-48ed-b59c-8fc8eeccb024', - 'adomain': [ - 'improvedigital.com' - ], - 'w': 970, - 'impid': '33e9500b21129f', - 'h': 250, - 'adm': '\n\n\n\n\n\n\n\n ', - 'cid': '187354' - } - ], - 'seat': 'improvedigital' - } - ] - } - }; - - describe('interpretResponse', function () { - const expectedBid = [ - { - requestId: '33e9500b21129f', - cpm: 1.9200543539802946, - currency: 'EUR', - width: 728, - height: 90, - ttl: 300, - ad: '  ', - creativeId: '510265', - dealId: 320896, - netRevenue: false, - mediaType: BANNER, - } - ]; - - const multiFormatExpectedBid = [ - Object.assign({}, expectedBid[0], { - ad: '  ', - }) - ]; - - const expectedTwoBids = [ - expectedBid[0], - { - requestId: '33e9500b21129f', - cpm: 1.9200543539802946, - currency: 'EUR', - width: 300, - height: 250, - ttl: 300, - ad: '  ', - creativeId: '479163', - dealId: 320896, - netRevenue: false, - mediaType: BANNER, - } - ]; - - const expectedBidInstreamVideo = [ - { - requestId: '33e9500b21129f', - cpm: 9.600271769901472, - currency: 'EUR', - ttl: 300, - vastXml: '', - creativeId: '484367', - dealId: 321329, - netRevenue: false, - mediaType: VIDEO, - meta: { - advertiserDomains: ['improvedigital.com'], - } - } - ]; - - const expectedBidOutstreamVideo = deepClone(expectedBidInstreamVideo); - expectedBidOutstreamVideo[0].adResponse = { - content: expectedBidOutstreamVideo[0].vastXml - }; - - function makeRequest(bidderRequest) { - return { - ortbRequest: CONVERTER.toORTB({bidderRequest}) - } - } - - function expectMatch(actual, expected) { - sinon.assert.match(actual, expected.map(i => sinon.match(i))); - } - - it('should return a well-formed display bid', function () { - const bids = spec.interpretResponse(serverResponse, makeRequest(bidderRequest)); - expectMatch(bids, expectedBid); - }); - - it('should return a well-formed display bid for multi-format ad unit', function () { - const bids = spec.interpretResponse(serverResponse, makeRequest(multiFormatBidderRequest)); - - expectMatch(bids, multiFormatExpectedBid); - }); - - it('should return two bids', function () { - const bids = spec.interpretResponse(serverResponseTwoBids, makeRequest(bidderRequest)); - expectMatch(bids, expectedTwoBids); - }); - - it('should set dealId correctly', function () { - const request = makeRequest(bidderRequest); - const response = deepClone(serverResponse); - let bids; - - delete response.body.seatbid[0].bid[0].ext.improvedigital.line_item_id; - response.body.seatbid[0].bid[0].ext.improvedigital.buying_type = 'deal_id'; - bids = spec.interpretResponse(response, request); - expect(bids[0].dealId).to.not.exist; - - response.body.seatbid[0].bid[0].ext.improvedigital.line_item_id = 268515; - delete response.body.seatbid[0].bid[0].ext.improvedigital.buying_type; - bids = spec.interpretResponse(response, request); - expect(bids[0].dealId).to.not.exist; - - response.body.seatbid[0].bid[0].ext.improvedigital.line_item_id = 268515; - response.body.seatbid[0].bid[0].ext.improvedigital.buying_type = 'rtb'; - bids = spec.interpretResponse(response, request); - expect(bids[0].dealId).to.not.exist; - - response.body.seatbid[0].bid[0].ext.improvedigital.line_item_id = 268515; - response.body.seatbid[0].bid[0].ext.improvedigital.buying_type = 'classic'; - bids = spec.interpretResponse(response, request); - expect(bids[0].dealId).to.equal(268515); - - response.body.seatbid[0].bid[0].ext.improvedigital.line_item_id = 268515; - response.body.seatbid[0].bid[0].ext.improvedigital.buying_type = 'deal_id'; - bids = spec.interpretResponse(response, request); - expect(bids[0].dealId).to.equal(268515); - }); - - it('should set deal type targeting KV for PG', function () { - const request = makeRequest(bidderRequest); - const response = deepClone(serverResponse); - let bids; - - response.body.seatbid[0].bid[0].ext.improvedigital.pg = 1; - bids = spec.interpretResponse(response, request); - expect(bids[0].adserverTargeting.hb_deal_type_improve).to.equal('pg'); - }); - - it('should set currency', function () { - const response = deepClone(serverResponse); - response.body.cur = 'EUR'; - const bids = spec.interpretResponse(response, makeRequest(bidderRequest)); - expect(bids[0].currency).to.equal('EUR'); - }); - - it('should return empty array for bad response or no price', function () { - const request = makeRequest(bidderRequest); - let response = deepClone(serverResponse); - let bids; - - // Price missing or 0 - response.body.seatbid[0].bid[0].price = 0; - bids = spec.interpretResponse(response, request); - expect(bids).to.deep.equal([]); - delete response.body.seatbid[0].bid[0]; - bids = spec.interpretResponse(response, request); - expect(bids).to.deep.equal([]); - response.body.seatbid[0].bid[0] = []; - bids = spec.interpretResponse(response, request); - expect(bids).to.deep.equal([]); - - // errorCode present - response = deepClone(serverResponse); - response.body.seatbid[0].bid[0].errorCode = undefined; - bids = spec.interpretResponse(response, request); - expect(bids).to.deep.equal([]); - - // adm and native missing - response = deepClone(serverResponse); - delete response.body.seatbid[0].bid[0].adm; - bids = spec.interpretResponse(response, request); - expect(bids).to.deep.equal([]); - response.body.seatbid[0].bid[0].adm = null; - bids = spec.interpretResponse(response, request); - expect(bids).to.deep.equal([]); - }); - - it('should set netRevenue', function () { - const response = deepClone(serverResponse); - response.body.seatbid[0].bid[0].ext.improvedigital.is_net = true; - const bids = spec.interpretResponse(response, makeRequest(bidderRequest)); - expect(bids[0].netRevenue).to.equal(true); - }); - - it('should set advertiserDomains', function () { - const adomain = ['domain.com']; - const response = deepClone(serverResponse); - response.body.seatbid[0].bid[0].adomain = adomain; - const bids = spec.interpretResponse(response, makeRequest(bidderRequest)); - expect(bids[0].meta.advertiserDomains).to.equal(adomain); - }); - // - // Native ads - if (FEATURES.NATIVE) { - it('should return a well-formed native ad bid', function () { - const reqBids = updateNativeParams(nativeBidderRequest.bids); - const request = makeRequest({ - ...nativeBidderRequest, - reqBids - }) - const bids = spec.interpretResponse(serverResponseNative, request); - expect(bids[0].native.ortb).to.eql(JSON.parse(serverResponseNative.body.seatbid[0].bid[0].adm)) - }); - - it('should return a well-formed native bid for multi-format ad unit', function () { - const bids = spec.interpretResponse(serverResponseNative, makeRequest(multiFormatBidderRequest)); - expect(bids[0].mediaType).to.equal(NATIVE); - }); - } - - // Video - if (FEATURES.VIDEO) { - it('should return a well-formed instream video bid', function () { - const bids = spec.interpretResponse(serverResponseVideo, makeRequest(instreamBidderRequest)); - expectMatch(bids, expectedBidInstreamVideo); - }); - - it('should return a well-formed outstream video bid', function () { - const bids = spec.interpretResponse(serverResponseVideo, makeRequest(outstreamBidderRequest)); - expect(bids[0].renderer).to.exist; - expectMatch(bids, expectedBidOutstreamVideo); - }); - - it('should return a well-formed outstream video bid for multi-format ad unit', function () { - const request = makeRequest(multiFormatBidderRequest); - const videoResponse = deepClone(serverResponseVideo); - let bids = spec.interpretResponse(videoResponse, request); - expect(bids[0].renderer).to.exist; - expectMatch(bids, expectedBidOutstreamVideo); - - videoResponse.body.seatbid[0].bid[0].adm = ' JSON.parse(decodedBidderRequestData)).to.not.throw(); - }); - }); - - describe('interpretResponse', function () { - const bannerServerResponse = { - body: { - slotBidId: '2faedf3e89d123', - cpm: 0.5, - adWidth: 300, - adHeight: 250, - ad: '
Banner Ad
', - mediaType: BANNER, - netRevenue: true, - currency: 'USD', - advertiserDomains: ['example.com'] - } - }; - const videoServerResponse = { - body: { - slotBidId: '2faedf3e89d124', - cpm: 1.0, - adWidth: 640, - adHeight: 480, - ad: 'Test VAST', - mediaType: VIDEO, - netRevenue: true, - currency: 'USD', - rUrl: 'https://example.com/vast.xml', - advertiserDomains: ['example.com'] - } - }; - const instreamVideoServerResponse = { - body: { - slotBidId: '2faedf3e89d125', - cpm: 1.5, - adWidth: 640, - adHeight: 480, - ad: 'Test Instream VAST', - mediaType: VIDEO, - netRevenue: true, - currency: 'USD', - ttl: 300, - advertiserDomains: ['example.com'] - } - }; - - const bidderRequest = { - refererInfo: { - page: 'https://someurl.com' - }, - data: { - bidderRequestData: JSON.stringify({ - bids: [videoBidRequest] - }) - } - }; - - const instreamBidderRequest = { - refererInfo: { - page: 'https://someurl.com' - }, - data: { - bidderRequestData: JSON.stringify({ - bids: [instreamVideoBidRequest] - }) - } - }; - - it('should handle banner response', function () { - const bidResponses = spec.interpretResponse(bannerServerResponse, bidderRequest); - expect(bidResponses).to.have.lengthOf(1); - const bid = bidResponses[0]; - expect(bid.requestId).to.equal('2faedf3e89d123'); - expect(bid.cpm).to.equal(0.5); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.ad).to.equal('
Banner Ad
'); - expect(bid.mediaType).to.equal(BANNER); - expect(bid.meta.advertiserDomains).to.deep.equal(['example.com']); - }); - - it('should handle outstream video response', function () { - const bidResponses = spec.interpretResponse(videoServerResponse, bidderRequest); - expect(bidResponses).to.have.lengthOf(1); - const bid = bidResponses[0]; - expect(bid.requestId).to.equal('2faedf3e89d124'); - expect(bid.cpm).to.equal(1.0); - expect(bid.width).to.equal(640); - expect(bid.height).to.equal(480); - expect(bid.vastXml).to.equal('Test VAST'); - expect(bid.renderer).to.exist; - expect(bid.mediaType).to.equal(VIDEO); - expect(bid.meta.advertiserDomains).to.deep.equal(['example.com']); - }); - - it('should handle instream video response', function () { - const bidResponses = spec.interpretResponse(instreamVideoServerResponse, instreamBidderRequest); - expect(bidResponses).to.have.lengthOf(1); - const bid = bidResponses[0]; - expect(bid.requestId).to.equal('2faedf3e89d125'); - expect(bid.cpm).to.equal(1.5); - expect(bid.width).to.equal(640); - expect(bid.height).to.equal(480); - expect(bid.vastUrl).to.equal('Test Instream VAST'); - expect(bid.mediaType).to.equal(VIDEO); - expect(bid.ttl).to.equal(300); - expect(bid.renderer).to.not.exist; - expect(bid.meta.advertiserDomains).to.deep.equal(['example.com']); - }); - }); -}); diff --git a/test/spec/modules/inmobiBidAdapter_spec.js b/test/spec/modules/inmobiBidAdapter_spec.js deleted file mode 100644 index 9b22cd173..000000000 --- a/test/spec/modules/inmobiBidAdapter_spec.js +++ /dev/null @@ -1,1961 +0,0 @@ -import { expect } from 'chai'; -import { - spec, -} from 'modules/inmobiBidAdapter.js'; -import * as utils from 'src/utils.js'; -import * as ajax from 'src/ajax.js'; -import { BANNER, NATIVE, VIDEO } from '../../../src/mediaTypes.js'; -import { hook } from '../../../src/hook.js'; -import { config } from '../../../src/config.js'; -import { addFPDToBidderRequest } from '../../helpers/fpd.js'; -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; -import 'modules/consentManagementGpp.js'; -import 'modules/priceFloors.js'; -import sinon from 'sinon'; - -// constants -const GVLID = 333; -export const ADAPTER_VERSION = 1.0; -const BIDDER_CODE = 'inmobi'; -export const EVENT_ENDPOINT = 'https://sync.inmobi.com'; - -describe('The inmobi bidding adapter', function () { - let utilsMock, sandbox, ajaxStub, fetchStub; ; - - beforeEach(function () { - // mock objects - utilsMock = sinon.mock(utils); - sandbox = sinon.createSandbox(); - ajaxStub = sandbox.stub(ajax, 'ajax'); - fetchStub = sinon.stub(global, 'fetch').resolves(new Response('OK')); - }); - - afterEach(function () { - utilsMock.restore(); - sandbox.restore(); - ajaxStub.restore(); - fetchStub.restore(); - }); - - describe('onBidWon', function () { - // existence test - it('onBidWon function should be defined', function () { - expect(spec.onBidWon).to.exist.and.to.be.a('function'); - }); - - it('It should invoke onBidWon, resolving the eventType and domain', function () { - const bid = { - bidder: 'inmobi', - width: 300, - height: 250, - adId: '330a22bdea4cac1', - mediaType: 'banner', - cpm: 0.28, - ad: 'inmobiAd', - requestId: '418b37f85e772c1', - adUnitCode: 'div-gpt-ad-1460505748561-01', - size: '350x250', - adserverTargeting: { - hb_bidder: 'prebid', - hb_adid: '330a22bdea4cac1', - hb_pb: '0.20', - hb_size: '350x250' - }, - meta: { - loggingPercentage: 100 - } - }; - spec.onBidWon(bid); - // expected url and payload - const expectedUrl = `${EVENT_ENDPOINT}/report/onBidWon`; - const expectedPayload = JSON.stringify({ - domain: location.hostname, - eventPayload: bid.meta - }); - // assert statements - expect(fetchStub.callCount).to.be.equal(1); - const fetchArgs = fetchStub.getCall(0).args; - /* - index fetch parameter - 0 -> URL - 1 -> options (method, headers, body, etc.) - */ - expect(fetchArgs[0]).to.equal(expectedUrl); - const actualPayload = fetchArgs[1]?.body; - expect(actualPayload).to.equal(expectedPayload); - expect(fetchArgs[1]).to.deep.include({ - method: 'POST', - credentials: 'include', - keepalive: true, - }); - expect(fetchArgs[1]?.headers).to.deep.equal({ - 'Content-Type': 'text/plain', - }); - }); - - it('onBidWon should not be called when loggingPercentage is set to 0', function () { - const bid = { - bidder: 'inmobi', - width: 300, - height: 250, - adId: '330a22bdea4cac1', - mediaType: 'banner', - cpm: 0.28, - ad: 'inmobiAd', - requestId: '418b37f85e772c1', - adUnitCode: 'div-gpt-ad-1460505748561-01', - size: '350x250', - adserverTargeting: { - hb_bidder: 'prebid', - hb_adid: '330a22bdea4cac1', - hb_pb: '0.20', - hb_size: '350x250' - }, - meta: { - loggingPercentage: 0 - } - }; - spec.onBidWon(bid); - // expected url and payload - const expectedUrl = `${EVENT_ENDPOINT}/report/onBidWon`; - const expectedPayload = JSON.stringify({ - domain: location.hostname, - eventPayload: bid.meta - }); - // assert statements - expect(fetchStub.callCount).to.be.equal(0); - }); - - it('onBidWon should not be called if the bid data is null', function () { - // Call onBidWon with null data - spec.onBidWon(null); - // Assert that ajax was not called since bid data is null - expect(fetchStub.callCount).to.be.equal(0); - }); - }); - - describe('onBidderError', function () { - it('onBidderError function should be defined', function () { - expect(spec.onBidderError).to.exist.and.to.be.a('function'); - }); - - it('onBidderError should not be called if the bid data is null', function () { - // Call onBidError with null data - spec.onBidderError(null); - // Assert that ajax was not called since bid data is null - expect(fetchStub.callCount).to.be.equal(0); - }); - - it('onBidderError should be called with the eventType', function () { - const bid = { - error: 'error', // Assuming this will be a mock or reference to an actual XMLHttpRequest object - bidderRequest: { - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - auctionStart: 1579746300522, - bidder: 'inmobi', - bidderRequestId: '15246a574e859f' - } - }; - spec.onBidderError(bid); - // expected url and payload - const expectedUrl = `${EVENT_ENDPOINT}/report/onBidderError`; - const expectedPayload = JSON.stringify({ - domain: location.hostname, - eventPayload: bid - }); - // assert statements - expect(fetchStub.callCount).to.be.equal(1); - const fetchArgs = fetchStub.getCall(0).args; - /* - index fetch parameter - 0 -> URL - 1 -> options (method, headers, body, etc.) - */ - expect(fetchArgs[0]).to.equal(expectedUrl); - const actualPayload = fetchArgs[1]?.body; - expect(actualPayload).to.equal(expectedPayload); - expect(fetchArgs[1]).to.deep.include({ - method: 'POST', - credentials: 'include', - keepalive: true, - }); - expect(fetchArgs[1]?.headers).to.deep.equal({ - 'Content-Type': 'text/plain', - }); - }); - }); - - describe('onAdRenderSucceeded', function () { - // existence test - it('onAdRenderSucceeded function should be defined', function () { - expect(spec.onAdRenderSucceeded).to.exist.and.to.be.a('function'); - }); - - it('should invoke onAdRenderSucceeded, resolving the eventType and domain', function () { - const bid = { - bidder: 'inmobi', - width: 300, - height: 250, - adId: '330a22bdea4cac1', - mediaType: 'banner', - cpm: 0.28, - ad: 'inmobiAd', - requestId: '418b37f85e772c1', - adUnitCode: 'div-gpt-ad-1460505748561-01', - size: '350x250', - adserverTargeting: { - hb_bidder: 'prebid', - hb_adid: '330a22bdea4cac1', - hb_pb: '0.20', - hb_size: '350x250' - }, - meta: { - loggingPercentage: 100 - } - }; - spec.onAdRenderSucceeded(bid); - // expected url and payload - const expectedUrl = `${EVENT_ENDPOINT}/report/onAdRenderSucceeded`; - const expectedPayload = JSON.stringify({ - domain: location.hostname, - eventPayload: bid.meta - }); - // assert statements - expect(fetchStub.callCount).to.be.equal(1); - const fetchArgs = fetchStub.getCall(0).args; - /* - index fetch parameter - 0 -> URL - 1 -> options (method, headers, body, etc.) - */ - expect(fetchArgs[0]).to.equal(expectedUrl); - const actualPayload = fetchArgs[1]?.body; - expect(actualPayload).to.equal(expectedPayload); - expect(fetchArgs[1]).to.deep.include({ - method: 'POST', - credentials: 'include', - keepalive: true, - }); - expect(fetchArgs[1]?.headers).to.deep.equal({ - 'Content-Type': 'text/plain', - }); - }); - - it('onAdRenderSucceeded should not be called when loggingPercentage is 0', function () { - const bid = { - bidder: 'inmobi', - width: 300, - height: 250, - adId: '330a22bdea4cac1', - mediaType: 'banner', - cpm: 0.28, - ad: 'inmobiAd', - requestId: '418b37f85e772c1', - adUnitCode: 'div-gpt-ad-1460505748561-01', - size: '350x250', - adserverTargeting: { - hb_bidder: 'prebid', - hb_adid: '330a22bdea4cac1', - hb_pb: '0.20', - hb_size: '350x250' - }, - meta: { - loggingPercentage: 0 - } - }; - spec.onAdRenderSucceeded(bid); - // expected url and payload - const expectedUrl = `${EVENT_ENDPOINT}/report/onAdRenderSucceeded`; - const expectedPayload = JSON.stringify({ - domain: location.hostname, - eventPayload: bid.meta - }); - // assert statements - expect(fetchStub.callCount).to.be.equal(0); - }); - - it('onAdRenderSucceeded should not be called if the bid data is null', function () { - // Call onAdRenderSucceeded with null data - spec.onAdRenderSucceeded(null); - // Assert that ajax was not called since bid data is null - expect(fetchStub.callCount).to.be.equal(0); - }); - }); - - describe('onTimeout', function () { - // existence test - it('onTimeout function should be defined', function () { - expect(spec.onTimeout).to.exist.and.to.be.a('function'); - }); - - it('should invoke onTimeout, resolving the eventType and domain', function () { - const bid = [ - { - bidder: 'inmobi', - bidId: '51ef8751f9aead1', - adUnitCode: 'div-gpt-ad-14605057481561-0', - timeout: 3000, - auctionId: '18fd8b8b0bd7517' - } - ]; - spec.onTimeout(bid); - // expected url and payload - const expectedUrl = `${EVENT_ENDPOINT}/report/onTimeout`; - const expectedPayload = JSON.stringify({ - domain: location.hostname, - eventPayload: bid - }); - // assert statements - expect(fetchStub.callCount).to.be.equal(1); - const fetchArgs = fetchStub.getCall(0).args; - /* - index fetch parameter - 0 -> URL - 1 -> options (method, headers, body, etc.) - */ - expect(fetchArgs[0]).to.equal(expectedUrl); - const actualPayload = fetchArgs[1]?.body; - expect(actualPayload).to.equal(expectedPayload); - expect(fetchArgs[1]).to.deep.include({ - method: 'POST', - credentials: 'include', - keepalive: true, - }); - expect(fetchArgs[1]?.headers).to.deep.equal({ - 'Content-Type': 'text/plain', - }); - }); - - it('onTimeout should not be called if the bid data is null', function () { - // Call onTimeout with null data - spec.onTimeout(null); - // Assert that ajax was not called since bid data is null - expect(fetchStub.callCount).to.be.equal(0); - }); - }); - - describe('onSetTargeting', function () { - // existence test - it('The onSetTargeting function should be defined', function () { - expect(spec.onSetTargeting).to.exist.and.to.be.a('function'); - }); - - it('should invoke onSetTargeting, resolving the eventType and domain', function () { - const bid = { - bidder: 'inmobi', - width: 300, - height: 250, - adId: '330a22bdea4cac1', - mediaType: 'banner', - cpm: 0.28, - ad: 'inmobiAd', - requestId: '418b37f85e7721c', - adUnitCode: 'div-gpt-ad-1460505748561-01', - size: '350x250', - adserverTargeting: { - hb_bidder: 'prebid', - hb_adid: '330a22bdea4cac1', - hb_pb: '0.20', - hb_size: '350x250' - }, - meta: { - loggingPercentage: 100 - } - }; - spec.onSetTargeting(bid); - // expected url and payload - const expectedUrl = `${EVENT_ENDPOINT}/report/onSetTargeting`; - const expectedPayload = JSON.stringify({ - domain: location.hostname, - eventPayload: bid.meta - }); - // assert statements - expect(fetchStub.callCount).to.be.equal(1); - const fetchArgs = fetchStub.getCall(0).args; - /* - index fetch parameter - 0 -> URL - 1 -> options (method, headers, body, etc.) - */ - expect(fetchArgs[0]).to.equal(expectedUrl); - const actualPayload = fetchArgs[1]?.body; - expect(actualPayload).to.equal(expectedPayload); - expect(fetchArgs[1]).to.deep.include({ - method: 'POST', - credentials: 'include', - keepalive: true, - }); - expect(fetchArgs[1]?.headers).to.deep.equal({ - 'Content-Type': 'text/plain', - }); - }); - - it('onSetTargeting should not be called when loggingPercentage is 0', function () { - const bid = { - bidder: 'inmobi', - width: 300, - height: 250, - adId: '330a22bdea4cac1', - mediaType: 'banner', - cpm: 0.28, - ad: 'inmobiAd', - requestId: '418b37f85e7721c', - adUnitCode: 'div-gpt-ad-1460505748561-01', - size: '350x250', - adserverTargeting: { - hb_bidder: 'prebid', - hb_adid: '330a22bdea4cac1', - hb_pb: '0.20', - hb_size: '350x250' - }, - meta: { - loggingPercentage: 0 - } - }; - spec.onSetTargeting(bid); - // expected url and payload - const expectedUrl = `${EVENT_ENDPOINT}/report/onSetTargeting`; - const expectedPayload = JSON.stringify({ - domain: location.hostname, - eventPayload: bid.meta - }); - // assert statements - expect(fetchStub.callCount).to.be.equal(0); - }); - - it('onSetTargeting should not be called if the bid data is null', function () { - // Call onSetTargeting with null data - spec.onSetTargeting(null); - // Assert that ajax was not called since bid data is null - expect(fetchStub.callCount).to.be.equal(0); - }); - }); - - describe('isBidRequestValid', function () { - it('should return false when an invalid bid is provided', function () { - const bid = { - bidder: 'inmobi', - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equal(false); - }); - - it('should return true when the bid contains a PLC', function () { - const bid = { - bidder: 'inmobi', - params: { - plc: '123a', - }, - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equal(true); - }); - }); - - describe('buildRequests', function () { - before(() => { - hook.ready(); - }) - afterEach(function () { - config.resetConfig(); - }); - const bidderRequest = { - refererInfo: { - page: 'inmobi', - topmostLocation: 'inmobi' - }, - timeout: 3000, - gdprConsent: { - gdprApplies: true, - consentString: 'consentDataString', - vendorData: { - vendorConsents: { - '333': 1 - }, - }, - apiVersion: 1, - }, - }; - - it('request should build with correct plc', async function () { - const bidRequests = [ - { - bidId: 'bidId', - bidder: 'inmobi', - adUnitCode: 'bid-12', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '123' - } - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.imp[0].ext.bidder.plc).to.deep.equal('123'); - }); - - it('request should build with correct imp', async function () { - const expectedMetric = { - url: 'https://inmobi.com' - } - const bidRequests = [{ - bidId: 'bidId', - bidder: 'inmobi', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - ortb2Imp: { - instl: 1, - metric: expectedMetric, - ext: { - gpid: 'gpid_inmobi' - }, - rwdd: 1 - }, - params: { - plc: '123ai', - bidfloor: 4.66, - bidfloorcur: 'USD' - } - }]; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].id).to.deep.equal('bidId'); - expect(ortbRequest.imp[0].tagid).to.deep.equal('impId'); - expect(ortbRequest.imp[0].instl).to.equal(1); - expect(ortbRequest.imp[0].bidfloor).to.equal(4.66); - expect(ortbRequest.imp[0].bidfloorcur).to.equal('USD'); - expect(ortbRequest.imp[0].metric).to.deep.equal(expectedMetric); - expect(ortbRequest.imp[0].secure).to.equal(0); - expect(ortbRequest.imp[0].ext.gpid).to.equal('gpid_inmobi'); - expect(ortbRequest.imp[0].rwdd).to.equal(1); - }); - - it('request should build with proper site data', async function () { - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '1234a', - }, - }, - ]; - const ortb2 = { - site: { - name: 'raapchikgames.com', - domain: 'raapchikgames.com', - keywords: 'test1, test2', - cat: ['IAB2'], - pagecat: ['IAB3'], - sectioncat: ['IAB4'], - page: 'https://raapchikgames.com', - ref: 'inmobi.com', - privacypolicy: 1, - content: { - url: 'https://raapchikgames.com/games1' - } - } - }; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest({...bidderRequest, ortb2})).data; - expect(ortbRequest.site.domain).to.equal('raapchikgames.com'); - expect(ortbRequest.site.publisher.domain).to.equal('inmobi'); - expect(ortbRequest.site.page).to.equal('https://raapchikgames.com'); - expect(ortbRequest.site.name).to.equal('raapchikgames.com'); - expect(ortbRequest.site.keywords).to.equal('test1, test2'); - expect(ortbRequest.site.cat).to.deep.equal(['IAB2']); - expect(ortbRequest.site.pagecat).to.deep.equal(['IAB3']); - expect(ortbRequest.site.sectioncat).to.deep.equal(['IAB4']); - expect(ortbRequest.site.ref).to.equal('inmobi.com'); - expect(ortbRequest.site.privacypolicy).to.equal(1); - expect(ortbRequest.site.content.url).to.equal('https://raapchikgames.com/games1') - }); - - it('request should build with proper device data', async function () { - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '1234a', - }, - }, - ]; - const ortb2 = { - device: { - dnt: 0, - ua: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36', - ip: '195.199.250.144', - h: 919, - w: 1920, - language: 'hu', - lmt: 1, - js: 1, - connectiontype: 0, - hwv: '5S', - model: 'iphone', - mccmnc: '310-005', - geo: { - lat: 40.0964439, - lon: -75.3009142 - } - } - }; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest({...bidderRequest, ortb2})).data; - expect(ortbRequest.device.dnt).to.equal(0); - expect(ortbRequest.device.lmt).to.equal(1); - expect(ortbRequest.device.js).to.equal(1); - expect(ortbRequest.device.connectiontype).to.equal(0); - expect(ortbRequest.device.ua).to.equal('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36'); - expect(ortbRequest.device.ip).to.equal('195.199.250.144'); - expect(ortbRequest.device.h).to.equal(919); - expect(ortbRequest.device.w).to.equal(1920); - expect(ortbRequest.device.language).to.deep.equal('hu'); - expect(ortbRequest.device.hwv).to.deep.equal('5S'); - expect(ortbRequest.device.model).to.deep.equal('iphone'); - expect(ortbRequest.device.mccmnc).to.deep.equal('310-005'); - expect(ortbRequest.device.geo.lat).to.deep.equal(40.0964439); - expect(ortbRequest.device.geo.lon).to.deep.equal(-75.3009142); - }); - - it('should properly build a request with source object', async function () { - const expectedSchain = {id: 'prebid'}; - const ortb2 = { - source: { - pchain: 'inmobi', - schain: expectedSchain - } - }; - const bidRequests = [ - { - bidder: 'inmobi', - bidId: 'bidId', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '124', - }, - }, - ]; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest({...bidderRequest, ortb2})).data; - expect(ortbRequest.source.ext.schain).to.deep.equal(expectedSchain); - expect(ortbRequest.source.pchain).to.equal('inmobi'); - }); - - it('should properly user object', async function () { - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '123' - } - }, - ]; - const br = { - ...bidderRequest, - ortb2: { - user: { - yob: 2002, - keyowrds: 'test test', - gender: 'M', - customdata: 'test no', - geo: { - lat: 40.0964439, - lon: -75.3009142 - }, - ext: { - eids: [ - { - source: 'inmobi.com', - uids: [{ - id: 'iid', - atype: 1 - }] - } - ] - } - } - } - } - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(br)); - const ortbRequest = request.data; - expect(ortbRequest.user.yob).to.deep.equal(2002); - expect(ortbRequest.user.keyowrds).to.deep.equal('test test'); - expect(ortbRequest.user.gender).to.deep.equal('M'); - expect(ortbRequest.user.customdata).to.deep.equal('test no'); - expect(ortbRequest.user.geo.lat).to.deep.equal(40.0964439); - expect(ortbRequest.user.geo.lon).to.deep.equal(-75.3009142); - expect(ortbRequest.user.ext.eids).to.deep.equal([ - { - source: 'inmobi.com', - uids: [{ - id: 'iid', - atype: 1 - }] - } - ]); - }); - - it('should properly build a request regs object', async function () { - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '1234a', - }, - }, - ]; - const ortb2 = { - regs: { - coppa: 1, - gpp: 'gpp_consent_string', - gpp_sid: [0, 1, 2], - us_privacy: 'yes us privacy applied' - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest({...bidderRequest, ortb2})).data; - expect(ortbRequest.regs.coppa).to.equal(1); - expect(ortbRequest.regs.ext.gpp).to.equal('gpp_consent_string'); - expect(ortbRequest.regs.ext.gpp_sid).to.deep.equal([0, 1, 2]); - expect(ortbRequest.regs.ext.us_privacy).to.deep.equal('yes us privacy applied'); - }); - - it('gdpr test', async function () { - // using privacy params from global bidder Request - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '1234a', - }, - }, - ]; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.regs.ext.gdpr).to.deep.equal(1); - expect(ortbRequest.user.ext.consent).to.equal('consentDataString'); - }); - - it('should properly set tmax if available', async function () { - // using tmax from global bidder Request - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'bid-1', - transactionId: 'trans-1', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '123' - } - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.tmax).to.equal(bidderRequest.timeout); - }); - - it('should properly build a request with bcat field', async function () { - const bcat = ['IAB1', 'IAB2']; - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '123a', - }, - }, - ]; - const bidderRequest = { - ortb2: { - bcat - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.bcat).to.deep.equal(bcat); - }); - - it('should properly build a request with badv field', async function () { - const badv = ['ford.com']; - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '12ea', - }, - }, - ]; - const bidderRequest = { - ortb2: { - badv - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.badv).to.deep.equal(badv); - }); - - it('should properly build a request with bapp field', async function () { - const bapp = ['raapchik.com']; - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '123a', - }, - }, - ]; - const bidderRequest = { - ortb2: { - bapp - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.bapp).to.deep.equal(bapp); - }); - - it('banner request test', async function () { - const bidderRequest = {}; - const bidRequests = [ - { - bidId: 'bidId', - bidder: 'inmobi', - adUnitCode: 'bid-12', - mediaTypes: { - banner: { - sizes: [[320, 50]], - pos: 1, - topframe: 0, - } - }, - params: { - plc: '123' - }, - ortb2Imp: { - banner: { - api: [1, 2], - mimes: ['image/jpg', 'image/gif'] - } - } - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.imp[0].banner).not.to.be.null; - expect(ortbRequest.imp[0].banner.format[0].w).to.equal(320); - expect(ortbRequest.imp[0].banner.format[0].h).to.equal(50); - expect(ortbRequest.imp[0].banner.pos).to.equal(1); - expect(ortbRequest.imp[0].banner.topframe).to.equal(0); - expect(ortbRequest.imp[0].banner.api).to.deep.equal([1, 2]); - expect(ortbRequest.imp[0].banner.mimes).to.deep.equal(['image/jpg', 'image/gif']); - }); - - it('banner request test with sizes > 1', async function () { - const bidderRequest = {}; - const bidRequests = [ - { - bidId: 'bidId', - bidder: 'inmobi', - adUnitCode: 'bid-12', - mediaTypes: { - banner: { - sizes: [[320, 50], [720, 50]] - } - }, - params: { - plc: '123' - } - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.imp[0].banner).not.to.be.null; - expect(ortbRequest.imp[0].banner.format[0].w).to.equal(320); - expect(ortbRequest.imp[0].banner.format[0].h).to.equal(50); - expect(ortbRequest.imp[0].banner.format[1].w).to.equal(720); - expect(ortbRequest.imp[0].banner.format[1].h).to.equal(50); - }); - - if (FEATURES.VIDEO) { - it('video request test', async function () { - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'bid-123', - sizes: [[640, 360]], - mediaTypes: { - video: { - context: 'inbanner', - playerSize: [640, 360], - mimes: ['video/mp4', 'video/x-flv'], - maxduration: 30, - api: [1, 2], - protocols: [2, 3], - plcmt: 3, - w: 640, - h: 360, - linearity: 1, - skipmin: 30, - skipafter: 30, - minbitrate: 10000, - maxbitrate: 48000, - delivery: [1, 2, 3], - pos: 1, - playbackend: 1, - adPodDurationSec: 30, - durationRangeSec: [1, 30], - skip: 1, - minduration: 5, - startdelay: 5, - playbackmethod: [1, 3], - placement: 2 - } - }, - params: { - plc: '123' - }, - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].video.skip).to.equal(1); - expect(ortbRequest.imp[0].video.minduration).to.equal(5); - expect(ortbRequest.imp[0].video.startdelay).to.equal(5); - expect(ortbRequest.imp[0].video.playbackmethod).to.deep.equal([1, 3]); - expect(ortbRequest.imp[0].video.placement).to.equal(2); - expect(ortbRequest.imp[0].video.mimes).to.deep.equal(['video/mp4', 'video/x-flv']); - expect(ortbRequest.imp[0].video.maxduration).to.equal(30); - expect(ortbRequest.imp[0].video.api).to.deep.equal([1, 2]); - expect(ortbRequest.imp[0].video.protocols).to.deep.equal([2, 3]); - expect(ortbRequest.imp[0].video.plcmt).to.equal(3); - expect(ortbRequest.imp[0].video.w).to.equal(640); - expect(ortbRequest.imp[0].video.h).to.equal(360); - expect(ortbRequest.imp[0].video.linearity).to.equal(1); - expect(ortbRequest.imp[0].video.skipmin).to.equal(30); - expect(ortbRequest.imp[0].video.skipafter).to.equal(30); - expect(ortbRequest.imp[0].video.minbitrate).to.equal(10000); - expect(ortbRequest.imp[0].video.maxbitrate).to.equal(48000); - expect(ortbRequest.imp[0].video.delivery).to.deep.equal([1, 2, 3]); - expect(ortbRequest.imp[0].video.pos).to.equal(1); - expect(ortbRequest.imp[0].video.playbackend).to.equal(1); - }); - } - - if (FEATURES.VIDEO) { - it('video request with player size > 1 ', async function () { - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'bid-123', - sizes: [[640, 360], [480, 320]], - mediaTypes: { - video: { - context: 'inbanner', - playerSize: [[640, 360], [480, 320]], - mimes: ['video/mp4', 'video/x-flv'], - maxduration: 30, - api: [1, 2], - protocols: [2, 3], - plcmt: 3, - w: 640, - h: 360, - linearity: 1, - skipmin: 30, - skipafter: 30, - minbitrate: 10000, - maxbitrate: 48000, - delivery: [1, 2, 3], - pos: 1, - playbackend: 1, - adPodDurationSec: 30, - durationRangeSec: [1, 30], - skip: 1, - minduration: 5, - startdelay: 5, - playbackmethod: [1, 3], - placement: 2 - } - }, - params: { - plc: '123' - }, - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].video.w).to.be.equal(640); - expect(ortbRequest.imp[0].video.h).to.be.equal(360); - }); - } - - if (FEATURES.VIDEO) { - it('video request test when skip is 0', async function () { - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'bid-123', - sizes: [[640, 360]], - mediaTypes: { - video: { - context: 'inbanner', - playerSize: [640, 360], - mimes: ['video/mp4', 'video/x-flv'], - maxduration: 30, - api: [1, 2], - protocols: [2, 3], - plcmt: 3, - w: 640, - h: 360, - linearity: 1, - skipmin: 30, - skipafter: 30, - minbitrate: 10000, - maxbitrate: 48000, - delivery: [1, 2, 3], - pos: 1, - playbackend: 1, - adPodDurationSec: 30, - durationRangeSec: [1, 30], - skip: 0, - minduration: 5, - startdelay: 5, - playbackmethod: [1, 3], - placement: 2 - } - }, - params: { - plc: '123' - }, - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].video.skip).to.equal(0); - }); - } - - if (FEATURES.NATIVE) { - it('native request test without assests', async function () { - const bidRequests = [ - { - mediaTypes: { - native: {} - }, - params: { - 'plc': '123a' - } - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.imp[0].native).to.be.undefined; - }); - } - - if (FEATURES.NATIVE) { - it('native request with assets', async function () { - const assets = [{ - required: 1, - id: 1, - img: { - type: 3, - wmin: 100, - hmin: 100, - } - }, - { - required: 1, - id: 2, - title: { - len: 140, - } - }, - { - required: 1, - id: 3, - data: { - type: 1, - } - }]; - const bidRequests = [ - { - mediaTypes: { - native: {} - }, - nativeOrtbRequest: { - assets: assets - }, - params: {} - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - - expect(ortbRequest.imp[0].native.request).to.not.be.null; - const nativeRequest = JSON.parse(ortbRequest.imp[0].native.request); - expect(nativeRequest).to.have.property('assets'); - expect(nativeRequest.assets).to.deep.equal(assets); - }); - } - - it('should properly build a request when coppa flag is true', async function () { - const bidRequests = []; - const bidderRequest = {}; - config.setConfig({coppa: true}); - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.regs.coppa).to.equal(1); - }); - - it('should properly build a request when coppa flag is false', async function () { - const bidRequests = []; - const bidderRequest = {}; - config.setConfig({coppa: false}); - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.regs.coppa).to.equal(0); - }); - - it('should properly build a request when coppa flag is not defined', async function () { - const bidRequests = []; - const bidderRequest = {}; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.regs?.coppa).to.be.undefined; - }); - - it('build a banner request with bidFloor', async function () { - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50], [720, 90]] - } - }, - params: { - plc: '123a', - bidfloor: 1, - bidfloorcur: 'USD' - } - } - ]; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].bidfloor).to.deep.equal(1); - expect(ortbRequest.imp[0].bidfloorcur).to.deep.equal('USD'); - }); - - it('build a banner request with getFloor', async function () { - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '123a' - }, - getFloor: inputParams => { - return {currency: 'USD', floor: 1.23, size: '*', mediaType: '*'}; - } - } - ]; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].bidfloor).equal(1.23); - expect(ortbRequest.imp[0].bidfloorcur).equal('USD'); - }); - - if (FEATURES.VIDEO) { - it('build a video request with bidFloor', async function () { - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'impId', - mediaTypes: { - video: { - playerSize: [[480, 320], [720, 480]] - } - }, - params: { - plc: '123a', - bidfloor: 1, - bidfloorcur: 'USD' - } - } - ]; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].bidfloor).to.equal(1); - expect(ortbRequest.imp[0].bidfloorcur).to.equal('USD'); - }); - } - - if (FEATURES.VIDEO) { - it('build a video request with getFloor', async function () { - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'impId', - mediaTypes: { - video: { - playerSize: [[480, 320], [720, 480]] - } - }, - params: { - plc: '123a' - }, - getFloor: inputParams => { - return {currency: 'USD', floor: 1.23, size: '*', mediaType: '*'}; - } - } - ]; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].bidfloor).to.equal(1.23); - expect(ortbRequest.imp[0].bidfloorcur).to.equal('USD'); - }); - } - - if (FEATURES.NATIVE && FEATURES.VIDEO) { - it('build a mutli format request with getFloor', async function () { - const assets = [{ - required: 1, - id: 1, - img: { - type: 3, - wmin: 100, - hmin: 100, - } - }, - { - required: 1, - id: 2, - title: { - len: 140, - } - }, - { - required: 1, - id: 3, - data: { - type: 1, - } - }]; - const bidRequests = [ - { - bidder: 'inmobi', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50], [720, 90]] - }, - video: { - playerSize: [640, 480], - }, - native: {} - }, - nativeOrtbRequest: { - assets: assets - }, - params: { - plc: '12456' - }, - getFloor: inputParams => { - return {currency: 'USD', floor: 1.23, size: '*', mediaType: '*'}; - } - }, - ]; - const bidderRequest = {}; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].banner).not.to.be.undefined; - expect(ortbRequest.imp[0].video).not.to.be.undefined; - expect(ortbRequest.imp[0].native.request).not.to.be.undefined; - expect(ortbRequest.imp[0].bidfloor).to.deep.equal(1.23); - expect(ortbRequest.imp[0].bidfloorcur).to.deep.equal('USD'); - }); - } - - if (FEATURES.VIDEO) { - it('build a multi imp request', async function () { - const bidRequests = [{ - adUnitCode: 'impId', - bidId: 'bidId', - mediaTypes: { - video: { - context: 'inbanner', - playerSize: [640, 360], - mimes: ['video/mp4', 'video/x-flv'], - maxduration: 30, - api: [1, 2], - protocols: [2, 3], - plcmt: 3, - w: 640, - h: 360, - linearity: 1, - skipmin: 30, - skipafter: 30, - minbitrate: 10000, - maxbitrate: 48000, - delivery: [1, 2, 3], - pos: 1, - playbackend: 1, - adPodDurationSec: 30, - durationRangeSec: [1, 30], - skip: 1, - minduration: 5, - startdelay: 5, - playbackmethod: [1, 3], - placement: 2 - } - }, - params: { - plc: '123' - }, - }, { - adUnitCode: 'impId', - bidId: 'bidId2', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '123', - } - }]; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp).to.have.lengthOf(2); - expect(ortbRequest.imp[0].video.skip).to.equal(1); - expect(ortbRequest.imp[0].video.minduration).to.equal(5); - expect(ortbRequest.imp[0].video.startdelay).to.equal(5); - expect(ortbRequest.imp[0].video.playbackmethod).to.deep.equal([1, 3]); - expect(ortbRequest.imp[0].video.placement).to.equal(2); - // banner test - expect(ortbRequest.imp[1].banner).not.to.be.undefined; - }); - } - - if (FEATURES.VIDEO) { - it('build a multi format request', async function () { - const bidRequests = [{ - adUnitCode: 'impId', - bidId: 'bidId', - mediaTypes: { - video: { - context: 'inbanner', - playerSize: [640, 360], - mimes: ['video/mp4', 'video/x-flv'], - maxduration: 30, - api: [1, 2], - protocols: [2, 3], - plcmt: 3, - w: 640, - h: 360, - linearity: 1, - skipmin: 30, - skipafter: 30, - minbitrate: 10000, - maxbitrate: 48000, - delivery: [1, 2, 3], - pos: 1, - playbackend: 1, - adPodDurationSec: 30, - durationRangeSec: [1, 30], - skip: 1, - minduration: 5, - startdelay: 5, - playbackmethod: [1, 3], - placement: 2 - }, - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '123' - }, - }]; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].video.skip).to.equal(1); - expect(ortbRequest.imp[0].video.minduration).to.equal(5); - expect(ortbRequest.imp[0].video.startdelay).to.equal(5); - expect(ortbRequest.imp[0].video.playbackmethod).to.deep.equal([1, 3]); - expect(ortbRequest.imp[0].video.placement).to.equal(2); - // banner test - expect(ortbRequest.imp[0].banner).not.to.be.undefined; - }); - } - }); - - describe('getUserSyncs', function () { - const syncEndPoint = 'https://sync.inmobi.com/prebidjs?'; - - it('should return empty if iframe disabled and pixelEnabled is false', function () { - const res = spec.getUserSyncs({}); - expect(res).to.deep.equal([]); - }); - - it('should return user sync if iframe enabled is true', function () { - const res = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }); - expect(res).to.deep.equal([{ type: 'iframe', url: syncEndPoint }]); - }); - - it('should return user sync if iframe enabled is true and gdpr not present', function () { - const res = spec.getUserSyncs({ iframeEnabled: true }, {}, { gdprApplies: false }); - expect(res).to.deep.equal([{ type: 'iframe', url: `${syncEndPoint}` }]); - }); - - it('should return user sync if iframe enabled is true and gdpr = 1 and gdpr consent present', function () { - const res = spec.getUserSyncs({ iframeEnabled: true }, {}, { gdprApplies: true, consentString: 'GDPR_CONSENT' }); - expect(res).to.deep.equal([{ type: 'iframe', url: `${syncEndPoint}gdpr=1&gdpr_consent=GDPR_CONSENT` }]); - }); - - it('should return user sync if iframe enabled is true and gdpr = 1 , gdpr consent present and usp_consent present', function () { - const res = spec.getUserSyncs({ iframeEnabled: true }, {}, { gdprApplies: true, consentString: 'GDPR_CONSENT' }, 'USP_CONSENT'); - expect(res).to.deep.equal([{ type: 'iframe', url: `${syncEndPoint}gdpr=1&gdpr_consent=GDPR_CONSENT&us_privacy=USP_CONSENT` }]); - }); - - it('should return user sync if iframe enabled is true usp_consent present and gppConsent present', function () { - const res = spec.getUserSyncs({ iframeEnabled: true }, {}, { gdprApplies: false, consentString: undefined }, 'USP_CONSENT', { gppString: 'GPP_STRING', applicableSections: [32, 51] }); - expect(res).to.deep.equal([{ type: 'iframe', url: `${syncEndPoint}us_privacy=USP_CONSENT&gpp=GPP_STRING&gpp_sid=32%2C51` }]); - }); - - const responses = [{ - body: { - ext: { - prebidjs: { - urls: [ - { - url: 'https://sync.inmobi.com/prebidjs' - }, - { - url: 'https://eus.rubiconproject.com/usync.html?p=test' - } - ] - } - } - } - }]; - - it('should return urls from response when iframe enabled is false and pixel enabled', function () { - const res = spec.getUserSyncs({ iframeEnabled: false, pixelEnabled: true }, responses); - expect(res).to.deep.equal([ - { type: 'image', url: 'https://sync.inmobi.com/prebidjs' }, - { type: 'image', url: 'https://eus.rubiconproject.com/usync.html?p=test' } - ]) - }); - - it('should return urls from response when iframe enabled is false and pixel enabled and empty responses', function () { - const responses = []; - const res = spec.getUserSyncs({ iframeEnabled: false, pixelEnabled: true }, responses); - expect(res).to.deep.equal([ - { type: 'image', url: `${syncEndPoint}` } - ]) - }); - - it('should return urls from response when iframe enabled is false and pixel enabled and no response', function () { - const responses = undefined; - const res = spec.getUserSyncs({ iframeEnabled: false, pixelEnabled: true }, responses); - expect(res).to.deep.equal([ - { type: 'image', url: `${syncEndPoint}` } - ]) - }); - - it('should return urls from response when iframe enabled is false and all consent parameters present', function () { - const res = spec.getUserSyncs({ iframeEnabled: false, pixelEnabled: true }, responses, { gdprApplies: true, consentString: 'GDPR_CONSENT' }, 'USP_CONSENT', { gppString: 'GPP_STRING', applicableSections: [32, 51] }); - expect(res).to.deep.equal([ - { type: 'image', url: 'https://sync.inmobi.com/prebidjs?gdpr=1&gdpr_consent=GDPR_CONSENT&us_privacy=USP_CONSENT&gpp=GPP_STRING&gpp_sid=32%2C51' }, - { type: 'image', url: 'https://eus.rubiconproject.com/usync.html?p=test&gdpr=1&gdpr_consent=GDPR_CONSENT&us_privacy=USP_CONSENT&gpp=GPP_STRING&gpp_sid=32%2C51' } - ]) - }); - }); - - describe('interpretResponse', function () { - const bidderRequest = { - refererInfo: { - page: 'https://raapchikgames.com', - topmostLocation: 'https://raapchikgames.com' - }, - timeout: 3000, - gdprConsent: { - gdprApplies: true, - consentString: 'consentDataString', - vendorData: { - vendorConsents: { - '333': 1 - }, - }, - apiVersion: 1, - }, - }; - function mockResponse(winningBidId, mediaType) { - return { - id: '95d08af8-2d50-4d75-a411-8ecd9224970e', - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: '20dd72ed-930f-1000-e56f-07c37a793f30', - impid: winningBidId, - price: 1.1645, - adomain: ['advertiserDomain.sandbox.inmobi.com'], - crid: '88b37efcd5f34d368e60317c706942a4ef6f6976eb394046958fd0e8a7b75301', - w: 320, - h: 50, - adm: 'test-ad', - mtype: mediaType, - nurl: 'https://et-l.w.inmobi.com/c.asm/', - api: 3, - cat: [], - ext: { - loggingPercentage: 100, - prebid: { - meta: { - advertiserDomains: ['advertiserDomain.sandbox.inmobi.com'], - networkName: 'inmobi' - } - } - } - } - ] - } - ], - ext: { - prebidjs: { - urls: [ - { url: 'https://sync.inmobi.com/prebidjs' }, - { url: 'https://eus.rubiconproject.com/usync.html?p=test' } - ] - } - } - }; - }; - - function mockResponseNative(winningBidId, mediaType) { - return { - id: '95d08af8-2d50-4d75-a411-8ecd9224970e', - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: '20dd72ed-930f-1000-e56f-07c37a793f30', - impid: winningBidId, - price: 1.1645, - adomain: ['advertiserDomain.sandbox.inmobi.com'], - crid: '88b37efcd5f34d368e60317c706942a4ef6f6976eb394046958fd0e8a7b75301', - w: 320, - h: 50, - adm: '{"native":{"ver":"1.2","assets":[{"img":{"w":100,"h":100,"type":3,"url":"https://supply.inmobicdn.net/sandbox-prod-assets/Native_testAd.png"},"id":1,"required":1},{"id":2,"title":{"len":140,"text":"Native-Title-InMobi-Sandbox"},"required":1},{"data":{"type":1,"value":""},"id":3,"required":1},{"data":{"type":2,"value":"InMobi native test - Subtitle"},"id":4,"required":0},{"img":{"w":20,"h":20,"type":1,"url":"https://supply.inmobicdn.net/sandbox-prod-assets/inmobi-Logo-150x150.png"},"id":5,"required":0}],"link":{"clicktrackers":["https://c-eus.w.inmobi.com/"],"url":"https://www.inmobi.com"},"eventtrackers":[{"method":1,"event":1,"url":"https://et-eus.w.inmobi.com/"}]}}', - mtype: mediaType, - nurl: 'https://et-l.w.inmobi.com/c.asm/', - api: 3, - cat: [], - ext: { - loggingPercentage: 100, - prebid: { - meta: { - advertiserDomains: ['advertiserDomain.sandbox.inmobi.com'], - networkName: 'inmobi' - } - } - } - } - ] - } - ], - ext: { - prebidjs: { - urls: [ - { url: 'https://sync.inmobi.com/prebidjs' }, - { url: 'https://eus.rubiconproject.com/usync.html?p=test' } - ] - } - } - }; - }; - - it('returns an empty array when bid response is empty', async function () { - const bidRequests = []; - const response = {}; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse(response, request); - expect(bids).to.have.lengthOf(0); - }); - - it('should return an empty array when there is no bid response', async function () { - const bidRequests = []; - const response = {seatbid: []}; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.have.lengthOf(0); - }); - - it('return banner response', async function () { - const bidRequests = [{ - adUnitCode: 'impId', - bidId: 'bidId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '124a', - } - }]; - const response = mockResponse('bidId', 1); - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.have.length(1); - expect(bids[0].currency).to.deep.equal('USD'); - expect(bids[0].mediaType).to.deep.equal('banner'); - expect(bids[0].requestId).to.deep.equal('bidId'); - expect(bids[0].seatBidId).to.deep.equal('20dd72ed-930f-1000-e56f-07c37a793f30'); - expect(bids[0].cpm).to.equal(1.1645); - expect(bids[0].width).to.equal(320); - expect(bids[0].height).to.equal(50); - expect(bids[0].creativeId).to.deep.equal('88b37efcd5f34d368e60317c706942a4ef6f6976eb394046958fd0e8a7b75301'); - expect(bids[0].meta.loggingPercentage).to.equal(100); - expect(bids[0].meta.advertiserDomains[0]).to.deep.equal('advertiserDomain.sandbox.inmobi.com'); - expect(bids[0].meta.prebid.meta.networkName).to.deep.equal('inmobi'); - }); - - it('bid response when banner wins among two ad units', async function () { - const bidRequests = [{ - adUnitCode: 'impId', - bidId: 'bidId', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 320], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - plc: '123', - }, - }, { - adUnitCode: 'impId', - bidId: 'bidId2', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '123', - } - }]; - const response = mockResponse('bidId2', 1); - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids[0].currency).to.deep.equal('USD'); - expect(bids[0].mediaType).to.deep.equal('banner'); - expect(bids[0].requestId).to.deep.equal('bidId2'); - expect(bids[0].seatBidId).to.deep.equal('20dd72ed-930f-1000-e56f-07c37a793f30'); - expect(bids[0].cpm).to.equal(1.1645); - expect(bids[0].width).to.equal(320); - expect(bids[0].height).to.equal(50); - expect(bids[0].creativeId).to.deep.equal('88b37efcd5f34d368e60317c706942a4ef6f6976eb394046958fd0e8a7b75301'); - expect(bids[0].meta.loggingPercentage).to.equal(100); - expect(bids[0].meta.advertiserDomains[0]).to.deep.equal('advertiserDomain.sandbox.inmobi.com'); - expect(bids[0].meta.prebid.meta.networkName).to.deep.equal('inmobi'); - }); - - if (FEATURES.VIDEO) { - it('return instream video response', async function () { - const bidRequests = [{ - adUnitCode: 'impId', - bidId: 'bidId', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 320], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - plc: '123a1', - }, - }]; - const response = mockResponse('bidId', 2); - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.have.lengthOf(1); - expect(bids[0].mediaType).to.equal(VIDEO); - expect(bids[0].currency).to.deep.equal('USD'); - expect(bids[0].requestId).to.deep.equal('bidId'); - expect(bids[0].seatBidId).to.deep.equal('20dd72ed-930f-1000-e56f-07c37a793f30'); - expect(bids[0].cpm).to.equal(1.1645); - expect(bids[0].playerWidth).to.equal(640); - expect(bids[0].playerHeight).to.equal(320); - expect(bids[0].creativeId).to.deep.equal('88b37efcd5f34d368e60317c706942a4ef6f6976eb394046958fd0e8a7b75301'); - expect(bids[0].meta.loggingPercentage).to.equal(100); - expect(bids[0].meta.advertiserDomains[0]).to.deep.equal('advertiserDomain.sandbox.inmobi.com'); - expect(bids[0].meta.prebid.meta.networkName).to.deep.equal('inmobi'); - expect(bids[0].vastUrl).to.equal('https://et-l.w.inmobi.com/c.asm/'); - expect(bids[0].vastXml).to.equal('test-ad'); - }); - } - - if (FEATURES.VIDEO) { - it('return video outstream response', async function () { - const bidRequests = [{ - adUnitCode: 'impId', - bidId: 'bidId', - mediaTypes: { - video: { - context: 'outstream', - mimes: ['video/mpeg'], - playerSize: [640, 320], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - plc: '123a1', - }, - }]; - const response = mockResponse('bidId', 2); - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.have.lengthOf(1); - expect(bids[0].mediaType).to.equal(VIDEO); - expect(bids[0].currency).to.deep.equal('USD'); - expect(bids[0].requestId).to.deep.equal('bidId'); - expect(bids[0].seatBidId).to.deep.equal('20dd72ed-930f-1000-e56f-07c37a793f30'); - expect(bids[0].cpm).to.equal(1.1645); - expect(bids[0].playerWidth).to.equal(640); - expect(bids[0].playerHeight).to.equal(320); - expect(bids[0].creativeId).to.deep.equal('88b37efcd5f34d368e60317c706942a4ef6f6976eb394046958fd0e8a7b75301'); - expect(bids[0].meta.loggingPercentage).to.equal(100); - expect(bids[0].meta.advertiserDomains[0]).to.deep.equal('advertiserDomain.sandbox.inmobi.com'); - expect(bids[0].meta.prebid.meta.networkName).to.deep.equal('inmobi'); - expect(bids[0].vastUrl).to.equal('https://et-l.w.inmobi.com/c.asm/'); - expect(bids[0].vastXml).to.equal('test-ad'); - }); - } - - if (FEATURES.VIDEO) { - it('bid response when video wins among two ad units', async function () { - const bidRequests = [{ - adUnitCode: 'impId', - bidId: 'bidId', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 320], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - plc: '123', - }, - }, { - adUnitCode: 'impId', - bidId: 'bidId2', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '123', - } - }]; - const response = mockResponse('bidId', 2); - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.have.lengthOf(1); - expect(bids[0].mediaType).to.equal(VIDEO); - expect(bids[0].currency).to.deep.equal('USD'); - expect(bids[0].requestId).to.deep.equal('bidId'); - expect(bids[0].seatBidId).to.deep.equal('20dd72ed-930f-1000-e56f-07c37a793f30'); - expect(bids[0].cpm).to.equal(1.1645); - expect(bids[0].playerWidth).to.equal(640); - expect(bids[0].playerHeight).to.equal(320); - expect(bids[0].creativeId).to.deep.equal('88b37efcd5f34d368e60317c706942a4ef6f6976eb394046958fd0e8a7b75301'); - expect(bids[0].meta.loggingPercentage).to.equal(100); - expect(bids[0].meta.advertiserDomains[0]).to.deep.equal('advertiserDomain.sandbox.inmobi.com'); - expect(bids[0].meta.prebid.meta.networkName).to.deep.equal('inmobi'); - expect(bids[0].vastUrl).to.equal('https://et-l.w.inmobi.com/c.asm/'); - expect(bids[0].vastXml).to.equal('test-ad'); - }); - } - - if (FEATURES.NATIVE) { - it('should correctly parse a native bid response', async function () { - const bidRequests = [{ - adUnitCode: 'impId', - bidId: 'bidId', - params: { - plc: '123', - }, - native: true, - bidder: 'inmobi', - mediaTypes: { - native: { - image: { - required: true, - sizes: [120, 60], - sendId: true, - } - } - } - }]; - const response = mockResponseNative('bidId', 4); - const expectedAdmNativeOrtb = JSON.parse(response.seatbid[0].bid[0].adm).native; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - - expect(bids).to.have.lengthOf(1); - expect(bids[0].mediaType).to.equal(NATIVE); - // testing - expect(bids[0].requestId).to.deep.equal('bidId'); - expect(bids[0].seatBidId).to.deep.equal('20dd72ed-930f-1000-e56f-07c37a793f30') - expect(bids[0].cpm).to.deep.equal(1.1645); - expect(bids[0].currency).to.deep.equal('USD'); - expect(bids[0].width).to.deep.equal(320); - expect(bids[0].height).to.deep.equal(50); - expect(bids[0].ad).to.equal(undefined); - expect(bids[0].native.ortb).not.to.be.null; - expect(bids[0].native.ortb).to.deep.equal(expectedAdmNativeOrtb); - expect(bids[0].creativeId).to.deep.equal('88b37efcd5f34d368e60317c706942a4ef6f6976eb394046958fd0e8a7b75301'); - expect(bids[0].meta.advertiserDomains[0]).to.deep.equal('advertiserDomain.sandbox.inmobi.com'); - expect(bids[0].meta.prebid.meta.networkName).to.deep.equal('inmobi'); - }); - } - - if (FEATURES.NATIVE) { - it('should correctly parse a native bid response when there are two ad units', async function () { - const bidRequests = [{ - adUnitCode: 'impId', - bidId: 'bidId', - params: { - plc: '123', - }, - native: true, - bidder: 'inmobi', - mediaTypes: { - native: { - image: { - required: true, - sizes: [120, 60], - sendId: true, - } - } - } - }, - { - adUnitCode: 'impId', - bidId: 'bidId2', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - plc: '123', - } - }]; - const response = mockResponseNative('bidId', 4); - const expectedAdmNativeOrtb = JSON.parse(response.seatbid[0].bid[0].adm).native; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse({body: response}, request); - expect(bids).to.have.lengthOf(1); - expect(bids[0].mediaType).to.equal(NATIVE); - // testing - expect(bids[0].requestId).to.deep.equal('bidId'); - expect(bids[0].seatBidId).to.deep.equal('20dd72ed-930f-1000-e56f-07c37a793f30') - expect(bids[0].cpm).to.deep.equal(1.1645); - expect(bids[0].currency).to.deep.equal('USD'); - expect(bids[0].width).to.deep.equal(320); - expect(bids[0].height).to.deep.equal(50); - expect(bids[0].ad).to.equal(undefined); - expect(bids[0].native.ortb).not.to.be.null; - expect(bids[0].native.ortb).to.deep.equal(expectedAdmNativeOrtb); - expect(bids[0].creativeId).to.deep.equal('88b37efcd5f34d368e60317c706942a4ef6f6976eb394046958fd0e8a7b75301'); - expect(bids[0].meta.advertiserDomains[0]).to.deep.equal('advertiserDomain.sandbox.inmobi.com'); - expect(bids[0].meta.prebid.meta.networkName).to.deep.equal('inmobi'); - }); - } - }); -}); diff --git a/test/spec/modules/innityBidAdapter_spec.js b/test/spec/modules/innityBidAdapter_spec.js deleted file mode 100644 index 5a4689bc9..000000000 --- a/test/spec/modules/innityBidAdapter_spec.js +++ /dev/null @@ -1,130 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/innityBidAdapter.js'; - -describe('innityAdapterTest', () => { - describe('bidRequestValidity', () => { - it('bidRequest with pub ID and zone ID param', () => { - expect(spec.isBidRequestValid({ - bidder: 'innity', - params: { - 'pub': 267, - 'zone': 62546 - }, - })).to.equal(true); - }); - - it('bidRequest with no required params', () => { - expect(spec.isBidRequestValid({ - bidder: 'innity', - params: { - }, - })).to.equal(false); - }); - }); - - describe('bidRequest', () => { - const bidRequests = [{ - 'bidder': 'innity', - 'params': { - 'pub': 267, - 'zone': 62546 - }, - 'adUnitCode': '/19968336/header-bid-tag-0', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'sizes': [300, 250], - 'bidId': '51ef8751f9aead', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757' - }]; - - const bidderRequest = { - refererInfo: { - page: 'https://refererExample.com' - } - }; - - it('bidRequest HTTP method', () => { - const requests = spec.buildRequests(bidRequests, bidderRequest); - requests.forEach(function(requestItem) { - expect(requestItem.method).to.equal('GET'); - }); - }); - - it('bidRequest with complete data', () => { - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(requests[0].data.pub).to.equal(267); - expect(requests[0].data.zone).to.equal(62546); - expect(requests[0].data.width).to.equal('300'); - expect(requests[0].data.height).to.equal('250'); - expect(requests[0].data.url).to.equal(encodeURIComponent('https://refererExample.com')); - expect(requests[0].data.callback_uid).to.equal('51ef8751f9aead'); - }); - - it('bidRequest without referer URL', () => { - delete bidderRequest.refererInfo; - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(requests[0].data.url).to.equal(''); - }); - }); - - describe('interpretResponse', () => { - const bidRequest = { - 'method': 'GET', - 'url': 'https://as.innity.com/synd/?', - 'data': { - 'ver': 2, - 'hb': 1, - 'output': 'js', - 'pub': 267, - 'zone': 62546, - 'width': '300', - 'height': '250', - 'callback': 'json', - 'callback_uid': '51ef8751f9aead', - 'url': 'https://refererExample.com', - 'cb': '', - } - }; - - const advDomains = ['advertiserExample.com']; - - const bidResponse = { - body: { - 'cpm': 100, - 'width': '300', - 'height': '250', - 'creative_id': '148186', - 'callback_uid': '51ef8751f9aead', - 'tag': '', - 'adomain': advDomains, - }, - headers: {} - }; - - it('result is correct', () => { - const result = spec.interpretResponse(bidResponse, bidRequest); - expect(result[0].requestId).to.equal('51ef8751f9aead'); - expect(result[0].cpm).to.equal(1); - expect(result[0].width).to.equal('300'); - expect(result[0].height).to.equal('250'); - expect(result[0].creativeId).to.equal('148186'); - expect(result[0].currency).to.equal('USD'); - expect(result[0].ttl).to.equal(60); - expect(result[0].ad).to.equal(''); - expect(result[0].meta.advertiserDomains).to.equal(advDomains); - }); - - it('result with no advertiser domain', () => { - bidResponse.body.adomain = []; - const result = spec.interpretResponse(bidResponse, bidRequest); - expect(result[0].meta.advertiserDomains.length).to.equal(0); - expect(result[0].meta.advertiserDomains).to.deep.equal([]); - }); - - it('result with no bids', () => { - bidResponse.body = {}; - const result = spec.interpretResponse(bidResponse, bidRequest); - expect(result).to.deep.equal([]); - }); - }); -}); diff --git a/test/spec/modules/insticatorBidAdapter_spec.js b/test/spec/modules/insticatorBidAdapter_spec.js deleted file mode 100644 index cee99ca8c..000000000 --- a/test/spec/modules/insticatorBidAdapter_spec.js +++ /dev/null @@ -1,1214 +0,0 @@ -import { expect } from 'chai'; -import { spec, storage } from '../../../modules/insticatorBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js' -import { getWinDimensions } from '../../../src/utils.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -const USER_ID_KEY = 'hb_insticator_uid'; -const USER_ID_DUMMY_VALUE = '74f78609-a92d-4cf1-869f-1b244bbfb5d2'; -const USER_ID_STUBBED = '12345678-1234-1234-1234-123456789abc'; - -const utils = require('src/utils.js'); - -describe('InsticatorBidAdapter', function () { - const adapter = newBidder(spec); - - const bidderRequestId = '22edbae2733bf6'; - const bidRequest = { - bidder: 'insticator', - adUnitCode: 'adunit-code', - params: { - adUnitId: '1a2b3c4d5e6f1a2b3c4d', - user: { - yob: 1984, - gender: 'M' - }, - }, - sizes: [[300, 250], [300, 600]], - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - pos: 4, - }, - video: { - mimes: [ - 'video/mp4', - 'video/mpeg', - ], - w: 250, - h: 300, - placement: 2, - }, - }, - bidId: '30b31c1838de1e', - ortb2Imp: { - instl: 1, - ext: { - gpid: '1111/homepage' - } - }, - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'insticator.com', - sid: '00001', - hp: 1, - rid: bidderRequestId - } - ] - } - } - } - }, - userIdAsEids: [ - { - source: 'criteo.com', - uids: [ - { - id: '123', - atype: 1 - } - ] - } - ], - }; - - let bidderRequest = { - bidderRequestId, - ortb2: { - source: { - tid: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', - }, - }, - timeout: 300, - gdprApplies: 1, - gdprConsent: { - consentString: 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - vendorData: {}, - gdprApplies: true - }, - refererInfo: { - numIframes: 0, - reachedTop: true, - page: 'https://example.com', - domain: 'example.com', - ref: 'https://referrer.com', - stack: ['https://example.com'] - }, - }; - - describe('.code', function () { - it('should return a bidder code of insticator', function () { - expect(spec.code).to.equal('insticator') - }) - }) - - describe('inherited functions', function () { - it('should exist and be a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function') - }) - }) - - describe('isBidRequestValid', function () { - it('should return true if the bid is valid', function () { - expect(spec.isBidRequestValid(bidRequest)).to.be.true; - }); - - it('should return false if there is no adUnitId param', () => { - expect(spec.isBidRequestValid({ ...bidRequest, ...{ params: {} } })).to.be.false; - }); - - it('should return false if there is no mediaTypes', () => { - expect(spec.isBidRequestValid({ ...bidRequest, ...{ mediaTypes: {} } })).to.be.false; - }); - - it('should return false if there are no banner sizes and no sizes', () => { - bidRequest.mediaTypes.banner = {}; - expect(spec.isBidRequestValid({ ...bidRequest, ...{ sizes: {} } })).to.be.false; - }); - - it('should return true if there is sizes and no banner sizes', () => { - expect(spec.isBidRequestValid(bidRequest)).to.be.true; - }); - - it('should return true if there is banner sizes and no sizes', () => { - bidRequest.mediaTypes.banner.sizes = [[300, 250], [300, 600]]; - expect(spec.isBidRequestValid({ ...bidRequest, ...{ sizes: {} } })).to.be.true; - }); - - it('should return true if there is video and video sizes', () => { - expect(spec.isBidRequestValid({ - ...bidRequest, - ...{ - mediaTypes: { - video: { - mimes: [ - 'video/mp4', - 'video/mpeg', - ], - w: 250, - h: 300, - }, - } - } - })).to.be.true; - }); - - it('should return false if there is no video sizes', () => { - expect(spec.isBidRequestValid({ - ...bidRequest, - ...{ - mediaTypes: { - video: {}, - } - } - })).to.be.false; - }); - - it('should return true if video object is absent/undefined', () => { - expect(spec.isBidRequestValid({ - ...bidRequest, - ...{ - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - } - } - })).to.be.true; - }) - - it('should return false if video plcmt is not a number', () => { - expect(spec.isBidRequestValid({ - ...bidRequest, - ...{ - mediaTypes: { - video: { - mimes: [ - 'video/mp4', - 'video/mpeg', - ], - w: 250, - h: 300, - plcmt: 'NaN', - }, - } - } - })).to.be.false; - }); - - it('should return true if playerSize is present instead of w and h', () => { - expect(spec.isBidRequestValid({ - ...bidRequest, - ...{ - mediaTypes: { - video: { - mimes: [ - 'video/mp4', - 'video/mpeg', - ], - playerSize: [250, 300], - plcmt: 1, - }, - } - } - })).to.be.true; - }); - - it('should return true if optional video fields are valid', () => { - expect(spec.isBidRequestValid({ - ...bidRequest, - ...{ - mediaTypes: { - video: { - mimes: [ - 'video/mp4', - 'video/mpeg', - ], - playerSize: [250, 300], - placement: 1, - startdelay: 1, - skip: 1, - skipmin: 1, - skipafter: 1, - minduration: 1, - maxduration: 1, - api: [1, 2], - protocols: [2], - battr: [1, 2], - playbackmethod: [1, 2], - playbackend: 1, - delivery: [1, 2], - pos: 1, - }, - } - } - })).to.be.true; - }); - - it('should return false if video min duration > max duration', () => { - expect(spec.isBidRequestValid({ - ...bidRequest, - ...{ - mediaTypes: { - video: { - mimes: [ - 'video/mp4', - 'video/mpeg', - ], - playerSize: [250, 300], - placement: 1, - minduration: 5, - maxduration: 4, - }, - } - } - })).to.be.false; - }); - - it('should return true when video bidder params override bidRequest video params', () => { - expect(spec.isBidRequestValid({ - ...bidRequest, - ...{ - mediaTypes: { - video: { - mimes: [ - 'video/mp4', - 'video/mpeg', - ], - playerSize: [250, 300], - plcmt: 1, - }, - } - }, - params: { - ...bidRequest.params, - video: { - mimes: [ - 'video/mp4', - 'video/mpeg', - 'video/x-flv', - 'video/webm', - ], - plcmt: 2, - }, - } - })).to.be.true; - }); - }); - - describe('buildRequests', function () { - let getDataFromLocalStorageStub, localStorageIsEnabledStub; - let getCookieStub, cookiesAreEnabledStub; - let sandbox; - let serverRequests, serverRequest; - - beforeEach(() => { - getGlobal().bidderSettings = { - insticator: { - storageAllowed: true - } - }; - getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); - localStorageIsEnabledStub = sinon.stub(storage, 'localStorageIsEnabled'); - getCookieStub = sinon.stub(storage, 'getCookie'); - cookiesAreEnabledStub = sinon.stub(storage, 'cookiesAreEnabled'); - - sandbox = sinon.createSandbox(); - sandbox.stub(utils, 'generateUUID').returns(USER_ID_STUBBED); - }); - - afterEach(() => { - sandbox.restore(); - getDataFromLocalStorageStub.restore(); - localStorageIsEnabledStub.restore(); - getCookieStub.restore(); - cookiesAreEnabledStub.restore(); - getGlobal().bidderSettings = {}; - }); - - before(() => { - serverRequests = spec.buildRequests([bidRequest], bidderRequest); - serverRequest = serverRequests[0]; - }) - - it('should create a request', function () { - expect(serverRequests).to.have.length(1); - }); - - it('should create a request object with method, URL, options and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.options).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('should return POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('should return valid URL', function () { - expect(serverRequest.url).to.equal('https://ex.ingage.tech/v1/openrtb'); - }); - - it('should return valid options', function () { - expect(serverRequest.options).to.be.an('object'); - expect(serverRequest.options.contentType).to.equal('application/json'); - expect(serverRequest.options.withCredentials).to.be.true; - }); - - it('should return valid data if array of bids is valid', function () { - localStorageIsEnabledStub.returns(true); - cookiesAreEnabledStub.returns(false); - localStorage.setItem(USER_ID_KEY, USER_ID_DUMMY_VALUE); - - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('id', 'tmax', 'source', 'site', 'device', 'regs', 'user', 'imp', 'ext'); - expect(data.id).to.equal(bidderRequest.bidderRequestId); - expect(data.tmax).to.equal(bidderRequest.timeout); - expect(data.source).to.have.all.keys('fd', 'tid', 'ext'); - expect(data.source.fd).to.equal(1); - expect(data.source.tid).to.equal(bidderRequest.ortb2.source.tid); - expect(data.source.ext).to.have.property('schain').to.deep.equal({ - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'insticator.com', - sid: '00001', - hp: 1, - rid: bidderRequest.bidderRequestId - } - ] - }); - expect(data.site).to.be.an('object'); - expect(data.site.domain).not.to.be.empty; - expect(data.site.page).not.to.be.empty; - expect(data.site.ref).to.equal(bidderRequest.refererInfo.ref); - expect(data.device).to.be.an('object'); - expect(data.device.w).to.equal(getWinDimensions().innerWidth); - expect(data.device.h).to.equal(getWinDimensions().innerHeight); - expect(data.device.js).to.equal(1); - expect(data.device.ext).to.be.an('object'); - expect(data.device.ext.localStorage).to.equal(true); - expect(data.device.ext.cookies).to.equal(false); - expect(data.regs).to.be.an('object'); - expect(data.regs.ext.gdpr).to.equal(1); - expect(data.regs.ext.gdprConsentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.user).to.be.an('object'); - expect(data.user).to.have.property('yob'); - expect(data.user.yob).to.equal(1984); - expect(data.user).to.have.property('gender'); - expect(data.user.gender).to.equal('M'); - expect(data.user.ext).to.have.property('eids'); - expect(data.user.ext.eids).to.deep.equal([ - { - source: 'criteo.com', - uids: [ - { - id: '123', - atype: 1 - } - ] - } - ]); - expect(data.imp).to.be.an('array').that.have.lengthOf(1); - expect(data.imp).to.deep.equal([{ - id: bidRequest.bidId, - tagid: bidRequest.adUnitCode, - instl: 1, - secure: 0, - banner: { - format: [ - { w: 300, h: 250 }, - { w: 300, h: 600 } - ] - }, - video: { - mimes: [ - 'video/mp4', - 'video/mpeg', - ], - h: 300, - w: 250, - placement: 2, - }, - ext: { - gpid: bidRequest.ortb2Imp.ext.gpid, - insticator: { - adUnitId: bidRequest.params.adUnitId, - }, - prebid: { - bidder: { - insticator: { - adUnitId: bidRequest.params.adUnitId, - } - } - } - } - }]); - expect(data.ext).to.be.an('object'); - expect(data.ext.insticator).to.be.an('object') - expect(data.ext.insticator).to.deep.equal({ - adapter: { - vendor: 'prebid', - prebid: '$prebid.version$' - } - }); - }); - - it('should generate new userId if not valid user is stored', function () { - localStorageIsEnabledStub.returns(true); - localStorage.setItem(USER_ID_KEY, 'fake-user-id'); - - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - - expect(data.user.id).to.equal(USER_ID_STUBBED); - }); - - it('should return with coppa regs object if no gdprConsent is passed', function () { - const requests = spec.buildRequests([bidRequest], { ...bidderRequest, ...{ gdprConsent: false } }); - const data = JSON.parse(requests[0].data); - expect(data.regs).to.be.an('object'); - expect(data.regs.coppa).to.be.oneOf([0, 1]); - }); - - it('should return with us_privacy string if uspConsent is passed', function () { - const requests = spec.buildRequests([bidRequest], { ...bidderRequest, ...{ uspConsent: '1YNN' } }); - const data = JSON.parse(requests[0].data); - expect(data.regs).to.be.an('object'); - expect(data.regs.ext).to.be.an('object'); - expect(data.regs.ext.us_privacy).to.equal('1YNN'); - expect(data.regs.ext.ccpa).to.equal('1YNN'); - }); - - it('should return with gpp if gppConsent is passed', function () { - const requests = spec.buildRequests([bidRequest], { ...bidderRequest, ...{ gppConsent: { gppString: '1YNN', applicableSections: ['1', '2'] } } }); - const data = JSON.parse(requests[0].data); - expect(data.regs).to.be.an('object'); - expect(data.regs.ext).to.be.an('object'); - expect(data.regs.ext.gppSid).to.deep.equal(['1', '2']); - }); - - it('should create the request with dsa data and return with dsa object', function() { - const dsa = { - dsarequired: 2, - pubrender: 1, - datatopub: 2, - transparency: [{ - domain: 'google.com', - dsaparams: [1, 2] - }] - } - const bidRequestWithDsa = { - ...bidderRequest, - ortb2: { - regs: { - ext: { - dsa: dsa - } - } - } - } - const requests = spec.buildRequests([bidRequest], {...bidRequestWithDsa}); - const data = JSON.parse(requests[0].data); - expect(data.regs).to.be.an('object'); - expect(data.regs.ext).to.be.an('object'); - expect(data.regs.ext.dsa).to.deep.equal(dsa); - }); - - it('should return empty array if no valid requests are passed', function () { - expect(spec.buildRequests([], bidderRequest)).to.be.an('array').that.have.lengthOf(0); - }); - - it('should have bidder params override bidRequest mediatypes', function () { - const tempBiddRequest = { - ...bidRequest, - params: { - ...bidRequest.params, - video: { - mimes: [ - 'video/mp4', - 'video/mpeg', - 'video/x-flv', - 'video/webm', - 'video/ogg', - ], - plcmt: 4, - w: 640, - h: 480, - } - } - } - const requests = spec.buildRequests([tempBiddRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.imp[0].video.mimes).to.deep.equal([ - 'video/mp4', - 'video/mpeg', - 'video/x-flv', - 'video/webm', - 'video/ogg', - ]) - expect(data.imp[0].video.placement).to.equal(2); - expect(data.imp[0].video.plcmt).to.equal(4); - expect(data.imp[0].video.w).to.equal(640); - expect(data.imp[0].video.h).to.equal(480); - }); - - it('should have bidder bidfloor from the request', function () { - const tempBiddRequest = { - ...bidRequest, - params: { - ...bidRequest.params, - floor: 0.5, - }, - } - const requests = spec.buildRequests([tempBiddRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.imp[0].bidfloor).to.equal(0.5); - expect(data.imp[0].bidfloorcur).to.equal('USD'); - }); - - it('should have bidder bidfloorcur from the request', function () { - const expectedFloor = 1.5; - const currency = 'USD'; - const tempBiddRequest = { - ...bidRequest, - params: { - ...bidRequest.params, - floor: 0.5, - currency: 'USD', - }, - } - tempBiddRequest.getFloor = () => ({ floor: expectedFloor, currency }) - - const requests = spec.buildRequests([tempBiddRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.imp[0].bidfloor).to.equal(1.5); - expect(data.imp[0].bidfloorcur).to.equal('USD'); - }); - - it('should have 1 floor for banner 300x250 and 1.5 for 300x600', function () { - const tempBiddRequest = { - ...bidRequest, - params: { - ...bidRequest.params, - }, - mediaTypes: { - banner: { - sizes: [[300, 250]], - format: [{ w: 300, h: 250 }] - }, - }, - } - tempBiddRequest.getFloor = (params) => { - return { floor: params.size[1] === 250 ? 1 : 1.5, currency: 'USD' } - } - - const requests = spec.buildRequests([tempBiddRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.imp[0].bidfloor).to.equal(1); - - tempBiddRequest.mediaTypes.banner.format = [ { w: 300, h: 600 }, - ]; - const request2 = spec.buildRequests([tempBiddRequest], bidderRequest); - const data2 = JSON.parse(request2[0].data); - expect(data2.imp[0].bidfloor).to.equal(1.5); - }); - - it('should have 4 floor for video 300x250 and 4.5 for 300x600', function () { - const tempBiddRequest = { - ...bidRequest, - params: { - ...bidRequest.params, - }, - mediaTypes: { - video: { - mimes: [ - 'video/mp4', - 'video/mpeg', - ], - w: 300, - h: 250, - placement: 2, - }, - }, - } - tempBiddRequest.getFloor = (params) => { - return { floor: params.size[1] === 250 ? 4 : 4.5, currency: 'USD' } - } - - const requests = spec.buildRequests([tempBiddRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.imp[0].bidfloor).to.equal(4); - - tempBiddRequest.mediaTypes.video.w = 300; - tempBiddRequest.mediaTypes.video.h = 600; - const request2 = spec.buildRequests([tempBiddRequest], bidderRequest); - const data2 = JSON.parse(request2[0].data); - expect(data2.imp[0].bidfloor).to.equal(4.5); - }); - - it('should have sites first party data if present in bidderRequest ortb2', function () { - bidderRequest = { - ...bidderRequest, - ortb2: { - ...bidderRequest.ortb2, - site: { - keywords: 'keyword1,keyword2', - search: 'search', - content: { - title: 'title', - keywords: 'keyword3,keyword4', - genre: 'rock' - }, - cat: ['IAB1', 'IAB2'] - } - } - } - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data).to.have.property('site'); - expect(data.site).to.have.property('keywords'); - expect(data.site.keywords).to.equal('keyword1,keyword2'); - expect(data.site).to.have.property('search'); - expect(data.site.search).to.equal('search'); - expect(data.site).to.have.property('content'); - expect(data.site.content).to.have.property('title'); - expect(data.site.content.title).to.equal('title'); - expect(data.site.content).to.have.property('keywords'); - expect(data.site.content.keywords).to.equal('keyword3,keyword4'); - expect(data.site.content).to.have.property('genre'); - expect(data.site.content.genre).to.equal('rock'); - expect(data.site).to.have.property('cat'); - expect(data.site.cat).to.deep.equal(['IAB1', 'IAB2']); - }); - - it('should have device.sua if present in bidderRequest ortb2', function () { - bidderRequest = { - ...bidderRequest, - ortb2: { - ...bidderRequest.ortb2, - device: { - ...bidderRequest.ortb2.device, - sua: {} - } - } - } - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data).to.have.property('device'); - expect(data.device).to.have.property('sua'); - }) - - it('should use param bid_endpoint_request_url for request endpoint if present', function () { - const tempBiddRequest = { - ...bidRequest, - params: { - ...bidRequest.params, - bid_endpoint_request_url: 'https://example.com' - } - } - const requests = spec.buildRequests([tempBiddRequest], bidderRequest); - expect(requests[0].url).to.equal('https://example.com'); - }); - - it('should have user keywords if present in bidrequest', function () { - const tempBiddRequest = { - ...bidRequest, - params: { - ...bidRequest.params, - user: { - keywords: 'keyword1,keyword2' - } - } - } - const requests = spec.buildRequests([tempBiddRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.user).to.have.property('keywords'); - expect(data.user.keywords).to.equal('keyword1,keyword2'); - }); - - it('should remove video params if they are invalid', function () { - const tempBiddRequest = { - ...bidRequest, - mediaTypes: { - ...bidRequest.mediaTypes, - video: { - mimes: [ - 'video/mp4', - 'video/mpeg', - 'video/x-flv', - 'video/webm', - 'video/ogg', - ], - protocols: 'NaN', - w: '300', - h: '250', - } - } - } - const requests = spec.buildRequests([tempBiddRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.imp[0].video).to.not.have.property('plcmt'); - }); - - it('should have user consent and gdpr string if gdprConsent is passed', function () { - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.regs).to.be.an('object'); - expect(data.regs.ext).to.be.an('object'); - expect(data.regs.ext.gdpr).to.equal(1); - expect(data.regs.ext.gdprConsentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.user.ext).to.have.property('consent'); - expect(data.user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString); - }); - - it('should have one or more privacy policies if present in bidrequest, like gpp, gdpr and us_privacy', function () { - const requests = spec.buildRequests([bidRequest], { ...bidderRequest, ...{ uspConsent: '1YNN' } }); - const data = JSON.parse(requests[0].data); - expect(data.regs.ext).to.have.property('gdpr'); - expect(data.regs.ext).to.have.property('us_privacy'); - expect(data.regs.ext).to.have.property('gppSid'); - }); - - it('should return true if publisherId is absent', () => { - expect(spec.isBidRequestValid(bidRequest)).to.be.true; - }) - - it('should have publisher object with id in site object, if publisherId present in params', function () { - const tempBiddRequest = { - ...bidRequest, - } - tempBiddRequest.params = { - ...tempBiddRequest.params, - publisherId: '86dd03a1-053f-4e3e-90e7-389070a0c62c' - } - const requests = spec.buildRequests([tempBiddRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.site.publisher).to.be.an('object'); - expect(data.site.publisher.id).to.equal(tempBiddRequest.params.publisherId) - }); - - it('should have publisher object should be empty, if publisherId is empty string', function () { - const tempBiddRequest = { - ...bidRequest, - } - tempBiddRequest.params = { - ...tempBiddRequest.params, - publisherId: '' - } - const requests = spec.buildRequests([tempBiddRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.site.publisher).to.not.an('object'); - }); - }); - - describe('interpretResponse', function () { - const bidRequests = { - method: 'POST', - url: 'https://ex.ingage.tech/v1/openrtb', - options: { - contentType: 'application/json', - withCredentials: true, - }, - data: '', - bidderRequest: { - bidderRequestId: '22edbae2733bf6', - auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', - timeout: 300, - bids: [ - { - bidder: 'insticator', - params: { - adUnitId: '1a2b3c4d5e6f1a2b3c4d' - }, - adUnitCode: 'adunit-code-1', - sizes: [[300, 250], [300, 600]], - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'bid1', - }, - { - bidder: 'insticator', - params: { - adUnitId: '1a2b3c4d5e6f1a2b3c4d' - }, - adUnitCode: 'adunit-code-2', - sizes: [[120, 600], [300, 600], [160, 600]], - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'bid2', - }, - { - bidder: 'insticator', - params: { - adUnitId: '1a2b3c4d5e6f1a2b3c4d' - }, - adUnitCode: 'adunit-code-3', - sizes: [[120, 600], [300, 600], [160, 600]], - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'bid3', - } - ] - } - }; - - const bidResponse = { - body: { - id: '22edbae2733bf6', - bidid: 'foo9876', - cur: 'USD', - seatbid: [ - { - seat: 'some-dsp', - bid: [ - { - impid: 'bid1', - crid: 'crid1', - price: 0.5, - w: 300, - h: 200, - adm: 'adm1', - exp: 60, - adomain: ['test1.com'], - ext: { - meta: { - test: 1 - } - } - }, - { - impid: 'bid2', - crid: 'crid2', - price: 1.5, - w: 600, - h: 200, - adm: 'adm2', - adomain: ['test2.com'], - }, - { - impid: 'bid3', - crid: 'crid3', - price: 5.0, - w: 300, - h: 200, - adm: 'adm3', - adomain: ['test3.com'], - } - ], - }, - ] - } - }; - - const prebidResponse = [ - { - requestId: 'bid1', - creativeId: 'crid1', - cpm: 0.5, - currency: 'USD', - netRevenue: true, - ttl: 60, - width: 300, - height: 200, - mediaType: 'banner', - ad: 'adm1', - adUnitCode: 'adunit-code-1', - meta: { - advertiserDomains: ['test1.com'], - test: 1 - } - }, - { - requestId: 'bid2', - creativeId: 'crid2', - cpm: 1.5, - currency: 'USD', - netRevenue: true, - ttl: 300, - width: 600, - height: 200, - mediaType: 'banner', - meta: { - advertiserDomains: [ - 'test2.com' - ] - }, - ad: 'adm2', - adUnitCode: 'adunit-code-2', - }, - { - requestId: 'bid3', - creativeId: 'crid3', - cpm: 5.0, - currency: 'USD', - netRevenue: true, - ttl: 300, - width: 300, - height: 200, - mediaType: 'banner', - meta: { - advertiserDomains: [ - 'test3.com' - ] - }, - ad: 'adm3', - adUnitCode: 'adunit-code-3', - }, - ]; - - it('should map bidResponse to prebidResponse', function () { - const response = spec.interpretResponse(bidResponse, bidRequests); - response.forEach((resp, i) => { - expect(resp).to.deep.equal(prebidResponse[i]); - }); - }); - - it('should return empty response if bidderRequestId is invalid', function () { - const response = Object.assign({}, bidResponse); - response.body.id = 'fake-id'; - expect(spec.interpretResponse(response, bidRequests)).to.have.length(0); - }); - - it('should return empty response if there is no seatbid array in response', function () { - const response = Object.assign({}, bidResponse); - delete response.body.seatbid; - expect(spec.interpretResponse(response, bidRequests)).to.have.length(0); - }); - }); - - describe('getUserSyncs', function () { - const bidResponse = [{ - body: { - ext: { - sync: [{ - code: 'so', - delay: 0 - }] - } - } - }]; - - it('should return one user sync', function () { - expect(spec.getUserSyncs({}, bidResponse)).to.deep.equal([{ - code: 'so', - delay: 0 - }]); - }) - - it('should return an empty array when sync is enabled but there are no bidResponses', function () { - expect(spec.getUserSyncs({}, [])).to.have.length(0); - }) - - it('should return an empty array when sync is enabled but no sync ext returned', function () { - const response = Object.assign({}, bidResponse[0]); - delete response.body.ext.sync; - expect(spec.getUserSyncs({}, [response])).to.have.length(0); - }) - }); - - describe('Response with video Instream', function () { - const bidRequestVid = { - method: 'POST', - url: 'https://ex.ingage.tech/v1/openrtb', - options: { - contentType: 'application/json', - withCredentials: true, - }, - data: '', - bidderRequest: { - bidderRequestId: '22edbae2733bf6', - auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', - timeout: 300, - bids: [ - { - bidder: 'insticator', - params: { - adUnitId: '1a2b3c4d5e6f1a2b3c4d' - }, - adUnitCode: 'adunit-code-1', - mediaTypes: { - video: { - mimes: [ - 'video/mp4', - 'video/mpeg', - ], - playerSize: [[250, 300]], - placement: 2, - plcmt: 2, - } - }, - bidId: 'bid1', - } - ] - } - }; - - const bidResponseVid = { - body: { - id: '22edbae2733bf6', - bidid: 'foo9876', - cur: 'USD', - seatbid: [ - { - seat: 'some-dsp', - bid: [ - { - ad: '', - impid: 'bid1', - crid: 'crid1', - price: 0.5, - w: 300, - h: 250, - adm: '', - exp: 60, - adomain: ['test1.com'], - ext: { - meta: { - test: 1 - } - }, - } - ], - }, - ] - } - }; - const bidRequestWithVideo = utils.deepClone(bidRequestVid); - - it('should have related properties for video Instream', function() { - const serverResponseWithInstream = utils.deepClone(bidResponseVid); - serverResponseWithInstream.body.seatbid[0].bid[0].vastXml = ''; - serverResponseWithInstream.body.seatbid[0].bid[0].mediaType = 'video'; - const bidResponse = spec.interpretResponse(serverResponseWithInstream, bidRequestWithVideo)[0]; - expect(bidResponse).to.have.any.keys('mediaType', 'vastXml', 'vastUrl'); - expect(bidResponse).to.have.property('mediaType', 'video'); - expect(bidResponse.width).to.equal(300); - expect(bidResponse.height).to.equal(250); - expect(bidResponse).to.have.property('vastXml', ''); - expect(bidResponse.vastUrl).to.match(/^data:text\/xml;charset=utf-8;base64,[\w+/=]+$/) - }); - }) - - describe(`Response with DSA data`, function() { - const bidRequestDsa = { - method: 'POST', - url: 'https://ex.ingage.tech/v1/openrtb', - options: { - contentType: 'application/json', - withCredentials: true, - }, - data: '', - bidderRequest: { - bidderRequestId: '22edbae2733bf6', - auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', - timeout: 300, - bids: [ - { - bidder: 'insticator', - params: { - adUnitId: '1a2b3c4d5e6f1a2b3c4d' - }, - adUnitCode: 'adunit-code-1', - mediaTypes: { - video: { - mimes: [ - 'video/mp4', - 'video/mpeg', - ], - playerSize: [[250, 300]], - placement: 2, - plcmt: 2, - } - }, - bidId: 'bid1', - } - ], - ortb2: { - regs: { - ext: { - dsa: { - dsarequired: 2, - pubrender: 1, - datatopub: 2, - transparency: [{ - domain: 'google.com', - dsaparams: [1, 2] - }] - } - }} - }, - } - }; - - const bidResponseDsa = { - body: { - id: '22edbae2733bf6', - bidid: 'foo9876', - cur: 'USD', - seatbid: [ - { - seat: 'some-dsp', - bid: [ - { - ad: '', - impid: 'bid1', - crid: 'crid1', - price: 0.5, - w: 300, - h: 250, - adm: '', - exp: 60, - adomain: ['test1.com'], - ext: { - meta: { - test: 1, - }, - dsa: { - behalf: 'Advertiser', - paid: 'Advertiser', - transparency: [{ - domain: 'google.com', - dsaparams: [1, 2] - }], - adrender: 1 - } - }, - } - ], - }, - ] - } - }; - const bidRequestWithDsa = utils.deepClone(bidRequestDsa); - it('should have related properties for DSA data', function() { - const serverResponseWithDsa = utils.deepClone(bidResponseDsa); - const bidResponse = spec.interpretResponse(serverResponseWithDsa, bidRequestWithDsa)[0]; - expect(bidResponse).to.have.any.keys('ext'); - expect(bidResponse.ext.dsa).to.have.property('behalf', 'Advertiser'); - expect(bidResponse.ext.dsa).to.have.property('paid', 'Advertiser'); - expect(bidResponse.ext.dsa).to.have.property('adrender', 1); - }); - }); -}); diff --git a/test/spec/modules/integr8BidAdapter_spec.js b/test/spec/modules/integr8BidAdapter_spec.js deleted file mode 100644 index fbabda9c6..000000000 --- a/test/spec/modules/integr8BidAdapter_spec.js +++ /dev/null @@ -1,226 +0,0 @@ -import { expect } from 'chai'; -import { spec, getBidFloor } from 'modules/integr8BidAdapter'; - -describe('integr8AdapterTest', () => { - describe('bidRequestValidity', () => { - it('bidRequest with propertyId and placementId', () => { - expect(spec.isBidRequestValid({ - bidder: 'integr8', - params: { - propertyId: '{propertyId}', - placementId: '{placementId}' - } - })).to.equal(true); - }); - - it('bidRequest without propertyId', () => { - expect(spec.isBidRequestValid({ - bidder: 'integr8', - params: { - placementId: '{placementId}' - } - })).to.equal(false); - }); - - it('bidRequest without placementId', () => { - expect(spec.isBidRequestValid({ - bidder: 'integr8', - params: { - propertyId: '{propertyId}', - } - })).to.equal(false); - }); - - it('bidRequest without propertyId or placementId', () => { - expect(spec.isBidRequestValid({ - bidder: 'integr8', - params: {} - })).to.equal(false); - }); - }); - - describe('bidRequest', () => { - const bidRequests = [{ - 'bidder': 'integr8', - 'params': { - 'propertyId': '{propertyId}', - 'placementId': '{placementId}', - 'data': { - 'catalogs': [{ - 'catalogId': '699229', - 'items': ['1', '2', '3'] - }], - 'inventory': { - 'category': ['category1', 'category2'], - 'query': ['query'] - } - } - }, - 'adUnitCode': 'hb-leaderboard', - 'transactionId': 'b6b889bb-776c-48fd-bc7b-d11a1cf0425e', - 'sizes': [[728, 90]], - 'bidId': '10bdc36fe0b48c8', - 'bidderRequestId': '70deaff71c281d', - 'auctionId': 'f9012acc-b6b7-4748-9098-97252914f9dc' - }]; - - it('bidRequest HTTP method', () => { - const requests = spec.buildRequests(bidRequests); - requests.forEach(function (requestItem) { - expect(requestItem.method).to.equal('POST'); - }); - }); - - it('bidRequest url', () => { - const endpointUrl = 'https://central.sea.integr8.digital/bid'; - const requests = spec.buildRequests(bidRequests); - requests.forEach(function (requestItem) { - expect(requestItem.url).to.match(new RegExp(`${endpointUrl}`)); - }); - }); - - it('bidRequest data', () => { - const requests = spec.buildRequests(bidRequests); - requests.forEach(function (requestItem) { - expect(requestItem.data).to.exist; - }); - }); - - it('bidRequest sizes', () => { - const requests = spec.buildRequests(bidRequests); - requests.forEach(function (requestItem) { - expect(requestItem.data.placements).to.exist; - expect(requestItem.data.placements.length).to.equal(1); - expect(requestItem.data.placements[0].sizes).to.equal('728x90'); - }); - }); - - it('bidRequest data param', () => { - const requests = spec.buildRequests(bidRequests); - requests.forEach((requestItem) => { - expect(requestItem.data.data).to.exist; - expect(requestItem.data.data.catalogs).to.exist; - expect(requestItem.data.data.inventory).to.exist; - expect(requestItem.data.data.catalogs.length).to.equal(1); - expect(requestItem.data.data.catalogs[0].items.length).to.equal(3); - expect(Object.keys(requestItem.data.data.inventory).length).to.equal(2); - expect(requestItem.data.data.inventory.category.length).to.equal(2); - expect(requestItem.data.data.inventory.query.length).to.equal(1); - }); - }); - }); - - describe('interpretResponse', () => { - const bidRequest = { - 'method': 'POST', - 'url': 'https://central.sea.integr8.digital/bid', - 'data': { - 'sizes': '728x90', - 'adUnitId': 'hb-leaderboard', - 'placementId': '{placementId}', - 'propertyId': '{propertyId}', - 'pageViewGuid': '{pageViewGuid}', - 'url': 'http://localhost:9999/integrationExamples/gpt/hello_world.html?pbjs_debug=true', - 'requestid': '26ee8fe87940da7', - 'bidid': '2962dbedc4768bf' - } - }; - - const bidResponse = { - body: [{ - 'CPM': 1, - 'Width': 728, - 'Height': 90, - 'Referrer': 'http://localhost:9999/integrationExamples/gpt/hello_world.html?pbjs_debug=true', - 'Ad': '
Test ad
', - 'CreativeId': '123abc', - 'NetRevenue': false, - 'Currency': 'EUR', - 'TTL': 360, - 'ADomain': ['somedomain.com'] - }], - headers: {} - }; - - it('all keys present', () => { - const result = spec.interpretResponse(bidResponse, bidRequest); - - const keys = [ - 'requestId', - 'cpm', - 'width', - 'height', - 'creativeId', - 'currency', - 'netRevenue', - 'ttl', - 'referrer', - 'ad', - 'vastUrl', - 'mediaType', - 'meta' - ]; - - const resultKeys = Object.keys(result[0]); - resultKeys.forEach(function (key) { - expect(keys.indexOf(key) !== -1).to.equal(true); - }); - }) - - it('all values correct', () => { - const result = spec.interpretResponse(bidResponse, bidRequest); - - expect(result[0].cpm).to.equal(1); - expect(result[0].width).to.equal(728); - expect(result[0].height).to.equal(90); - expect(result[0].creativeId).to.equal('123abc'); - expect(result[0].currency).to.equal('EUR'); - expect(result[0].netRevenue).to.equal(false); - expect(result[0].ttl).to.equal(360); - expect(result[0].referrer).to.equal('http://localhost:9999/integrationExamples/gpt/hello_world.html?pbjs_debug=true'); - expect(result[0].ad).to.equal('
Test ad
'); - expect(result[0].meta.advertiserDomains).to.deep.equal(['somedomain.com']); - }) - }); - - describe('floor pricing', () => { - it('should return null when getFloor is not a function', () => { - const bid = { getFloor: 2 }; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when getFloor doesnt return an object', () => { - const bid = { getFloor: () => 2 }; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when floor is not a number', () => { - const bid = { - getFloor: () => ({ floor: 'string', currency: 'EUR' }) - }; - - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when currency is not EUR', () => { - const bid = { - getFloor: () => ({ floor: 5, currency: 'USD' }) - }; - - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return floor value when everything is correct', () => { - const bid = { - getFloor: () => ({ floor: 5, currency: 'EUR' }) - }; - - const result = getBidFloor(bid); - expect(result).to.equal(5); - }); - }); -}); diff --git a/test/spec/modules/intentIqAnalyticsAdapter_spec.js b/test/spec/modules/intentIqAnalyticsAdapter_spec.js deleted file mode 100644 index 76ecabf34..000000000 --- a/test/spec/modules/intentIqAnalyticsAdapter_spec.js +++ /dev/null @@ -1,657 +0,0 @@ -import { expect } from 'chai'; -import iiqAnalyticsAnalyticsAdapter from 'modules/intentIqAnalyticsAdapter.js'; -import * as utils from 'src/utils.js'; -import { server } from 'test/mocks/xhr.js'; -import { config } from 'src/config.js'; -import { EVENTS } from 'src/constants.js'; -import * as events from 'src/events.js'; -import { getStorageManager } from 'src/storageManager.js'; -import sinon from 'sinon'; -import { REPORTER_ID, preparePayload } from '../../../modules/intentIqAnalyticsAdapter.js'; -import {FIRST_PARTY_KEY, PREBID, VERSION} from '../../../libraries/intentIqConstants/intentIqConstants.js'; -import * as detectBrowserUtils from '../../../libraries/intentIqUtils/detectBrowserUtils.js'; -import {getReferrer, appendVrrefAndFui} from '../../../libraries/intentIqUtils/getRefferer.js'; -import { gppDataHandler, uspDataHandler, gdprDataHandler } from '../../../src/consentHandler.js'; - -const partner = 10; -const defaultData = '{"pcid":"f961ffb1-a0e1-4696-a9d2-a21d815bd344", "group": "A"}'; -const version = VERSION; -const REPORT_ENDPOINT = 'https://reports.intentiq.com/report'; -const REPORT_ENDPOINT_GDPR = 'https://reports-gdpr.intentiq.com/report'; -const REPORT_SERVER_ADDRESS = 'https://test-reports.intentiq.com/report'; - -const storage = getStorageManager({ moduleType: 'analytics', moduleName: 'iiqAnalytics' }); - -const getUserConfig = () => [ - { - 'name': 'intentIqId', - 'params': { - 'partner': partner, - 'unpack': null, - 'manualWinReportEnabled': false, - }, - 'storage': { - 'type': 'html5', - 'name': 'intentIqId', - 'expires': 60, - 'refreshInSeconds': 14400 - } - } -]; - -const getUserConfigWithReportingServerAddress = () => [ - { - 'name': 'intentIqId', - 'params': { - 'partner': partner, - 'unpack': null, - 'manualWinReportEnabled': false, - 'reportingServerAddress': REPORT_SERVER_ADDRESS - }, - 'storage': { - 'type': 'html5', - 'name': 'intentIqId', - 'expires': 60, - 'refreshInSeconds': 14400 - } - } -]; - -const wonRequest = { - 'bidderCode': 'pubmatic', - 'width': 728, - 'height': 90, - 'statusMessage': 'Bid available', - 'adId': '23caeb34c55da51', - 'requestId': '87615b45ca4973', - 'transactionId': '5e69fd76-8c86-496a-85ce-41ae55787a50', - 'auctionId': '0cbd3a43-ff45-47b8-b002-16d3946b23bf', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 5, - 'currency': 'USD', - 'ttl': 300, - 'referrer': '', - 'adapterCode': 'pubmatic', - 'originalCpm': 5, - 'originalCurrency': 'USD', - 'responseTimestamp': 1669644710345, - 'requestTimestamp': 1669644710109, - 'bidder': 'testbidder', - 'timeToRespond': 236, - 'pbLg': '5.00', - 'pbMg': '5.00', - 'pbHg': '5.00', - 'pbAg': '5.00', - 'pbDg': '5.00', - 'pbCg': '', - 'size': '728x90', - 'status': 'rendered' -}; - -describe('IntentIQ tests all', function () { - let logErrorStub; - let getWindowSelfStub; - let getWindowTopStub; - let getWindowLocationStub; - let detectBrowserStub; - - beforeEach(function () { - logErrorStub = sinon.stub(utils, 'logError'); - sinon.stub(config, 'getConfig').withArgs('userSync.userIds').returns(getUserConfig()); - sinon.stub(events, 'getEvents').returns([]); - iiqAnalyticsAnalyticsAdapter.enableAnalytics({ - provider: 'iiqAnalytics', - }); - iiqAnalyticsAnalyticsAdapter.initOptions = { - lsValueInitialized: false, - partner: null, - fpid: null, - userGroup: null, - currentGroup: null, - dataInLs: null, - eidl: null, - lsIdsInitialized: false, - manualWinReportEnabled: false, - domainName: null - }; - if (iiqAnalyticsAnalyticsAdapter.track.restore) { - iiqAnalyticsAnalyticsAdapter.track.restore(); - } - sinon.spy(iiqAnalyticsAnalyticsAdapter, 'track'); - }); - - afterEach(function () { - logErrorStub.restore(); - if (getWindowSelfStub) getWindowSelfStub.restore(); - if (getWindowTopStub) getWindowTopStub.restore(); - if (getWindowLocationStub) getWindowLocationStub.restore(); - if (detectBrowserStub) detectBrowserStub.restore(); - config.getConfig.restore(); - events.getEvents.restore(); - iiqAnalyticsAnalyticsAdapter.disableAnalytics(); - if (iiqAnalyticsAnalyticsAdapter.track.restore) { - iiqAnalyticsAnalyticsAdapter.track.restore(); - } - localStorage.clear(); - server.reset(); - }); - - it('should send POST request with payload in request body if reportMethod is POST', function () { - const [userConfig] = getUserConfig(); - userConfig.params.reportMethod = 'POST'; - - config.getConfig.restore(); - sinon.stub(config, 'getConfig').withArgs('userSync.userIds').returns([userConfig]); - - localStorage.setItem(FIRST_PARTY_KEY, defaultData); - - events.emit(EVENTS.BID_WON, wonRequest); - - const request = server.requests[0]; - - const expectedData = preparePayload(wonRequest); - const expectedPayload = `["${btoa(JSON.stringify(expectedData))}"]`; - - expect(request.method).to.equal('POST'); - expect(request.requestBody).to.equal(expectedPayload); - }); - - it('should send GET request with payload in query string if reportMethod is NOT provided', function () { - const [userConfig] = getUserConfig(); - config.getConfig.restore(); - sinon.stub(config, 'getConfig').withArgs('userSync.userIds').returns([userConfig]); - - localStorage.setItem(FIRST_PARTY_KEY, defaultData); - events.emit(EVENTS.BID_WON, wonRequest); - - const request = server.requests[0]; - - expect(request.method).to.equal('GET'); - - const url = new URL(request.url); - const payloadEncoded = url.searchParams.get('payload'); - const decoded = JSON.parse(atob(JSON.parse(payloadEncoded)[0])); - - const expected = preparePayload(wonRequest); - - expect(decoded.partnerId).to.equal(expected.partnerId); - expect(decoded.adType).to.equal(expected.adType); - expect(decoded.prebidAuctionId).to.equal(expected.prebidAuctionId); - }); - - it('IIQ Analytical Adapter bid win report', function () { - localStorage.setItem(FIRST_PARTY_KEY, defaultData); - getWindowLocationStub = sinon.stub(utils, 'getWindowLocation').returns({href: 'http://localhost:9876'}); - const expectedVrref = getWindowLocationStub().href; - events.emit(EVENTS.BID_WON, wonRequest); - - expect(server.requests.length).to.be.above(0); - const request = server.requests[0]; - const parsedUrl = new URL(request.url); - const vrref = parsedUrl.searchParams.get('vrref'); - expect(request.url).to.contain(REPORT_ENDPOINT + '?pid=' + partner + '&mct=1'); - expect(request.url).to.contain(`&jsver=${version}`); - expect(`&vrref=${decodeURIComponent(vrref)}`).to.contain(`&vrref=${expectedVrref}`); - expect(request.url).to.contain('&payload='); - expect(request.url).to.contain('iiqid=f961ffb1-a0e1-4696-a9d2-a21d815bd344'); - }); - - it('should include adType in payload when present in BID_WON event', function () { - localStorage.setItem(FIRST_PARTY_KEY, defaultData); - getWindowLocationStub = sinon.stub(utils, 'getWindowLocation').returns({ href: 'http://localhost:9876/' }); - const bidWonEvent = { ...wonRequest, mediaType: 'video' }; - - events.emit(EVENTS.BID_WON, bidWonEvent); - - const request = server.requests[0]; - const urlParams = new URL(request.url); - const payloadEncoded = urlParams.searchParams.get('payload'); - const payloadDecoded = JSON.parse(atob(JSON.parse(payloadEncoded)[0])); - - expect(server.requests.length).to.be.above(0); - expect(payloadDecoded).to.have.property('adType', bidWonEvent.mediaType); - }); - - it('should include adType in payload when present in reportExternalWin event', function () { - getWindowLocationStub = sinon.stub(utils, 'getWindowLocation').returns({ href: 'http://localhost:9876/' }); - const externalWinEvent = { cpm: 1, currency: 'USD', adType: 'banner' }; - const [userConfig] = getUserConfig(); - userConfig.params.manualWinReportEnabled = true; - config.getConfig.restore(); - sinon.stub(config, 'getConfig').withArgs('userSync.userIds').returns([userConfig]); - - const partnerId = userConfig.params.partner; - - events.emit(EVENTS.BID_REQUESTED); - - window[`intentIqAnalyticsAdapter_${partnerId}`].reportExternalWin(externalWinEvent); - - const request = server.requests[0]; - const urlParams = new URL(request.url); - const payloadEncoded = urlParams.searchParams.get('payload'); - const payloadDecoded = JSON.parse(atob(JSON.parse(payloadEncoded)[0])); - - expect(server.requests.length).to.be.above(0); - expect(payloadDecoded).to.have.property('adType', externalWinEvent.adType); - }); - - it('should send report to report-gdpr address if gdpr is detected', function () { - const gppStub = sinon.stub(gppDataHandler, 'getConsentData').returns({ gppString: '{"key1":"value1","key2":"value2"}' }); - const uspStub = sinon.stub(uspDataHandler, 'getConsentData').returns('1NYN'); - const gdprStub = sinon.stub(gdprDataHandler, 'getConsentData').returns({ consentString: 'gdprConsent' }); - - events.emit(EVENTS.BID_WON, wonRequest); - - expect(server.requests.length).to.be.above(0); - const request = server.requests[0]; - - expect(request.url).to.contain(REPORT_ENDPOINT_GDPR); - gppStub.restore(); - uspStub.restore(); - gdprStub.restore(); - }); - - it('should initialize with default configurations', function () { - expect(iiqAnalyticsAnalyticsAdapter.initOptions.lsValueInitialized).to.be.false; - }); - - it('should handle BID_WON event with group configuration from local storage', function () { - localStorage.setItem(FIRST_PARTY_KEY, '{"pcid":"testpcid", "group": "B"}'); - const expectedVrref = encodeURIComponent('http://localhost:9876/'); - - events.emit(EVENTS.BID_WON, wonRequest); - - expect(server.requests.length).to.be.above(0); - const request = server.requests[0]; - expect(request.url).to.contain('https://reports.intentiq.com/report?pid=' + partner + '&mct=1'); - expect(request.url).to.contain(`&jsver=${version}`); - expect(request.url).to.contain(`&vrref=${expectedVrref}`); - expect(request.url).to.contain('iiqid=testpcid'); - }); - - it('should handle BID_WON event with default group configuration', function () { - localStorage.setItem(FIRST_PARTY_KEY, defaultData); - const defaultDataObj = JSON.parse(defaultData) - - events.emit(EVENTS.BID_WON, wonRequest); - - expect(server.requests.length).to.be.above(0); - const request = server.requests[0]; - const dataToSend = preparePayload(wonRequest); - const base64String = btoa(JSON.stringify(dataToSend)); - const payload = encodeURIComponent(JSON.stringify([base64String])); - const expectedUrl = appendVrrefAndFui(REPORT_ENDPOINT + - `?pid=${partner}&mct=1&iiqid=${defaultDataObj.pcid}&agid=${REPORTER_ID}&jsver=${version}&source=pbjs&uh=&gdpr=0`, iiqAnalyticsAnalyticsAdapter.initOptions.domainName - ); - const urlWithPayload = expectedUrl + `&payload=${payload}`; - - expect(request.url).to.equal(urlWithPayload); - expect(dataToSend.pcid).to.equal(defaultDataObj.pcid) - }); - - it('should send CMP data in report if available', function () { - const uspData = '1NYN'; - const gppData = { gppString: '{"key1":"value1","key2":"value2"}' }; - const gdprData = { consentString: 'gdprConsent' }; - - const gppStub = sinon.stub(gppDataHandler, 'getConsentData').returns(gppData); - const uspStub = sinon.stub(uspDataHandler, 'getConsentData').returns(uspData); - const gdprStub = sinon.stub(gdprDataHandler, 'getConsentData').returns(gdprData); - - getWindowLocationStub = sinon.stub(utils, 'getWindowLocation').returns({ href: 'http://localhost:9876/' }); - - events.emit(EVENTS.BID_WON, wonRequest); - - expect(server.requests.length).to.be.above(0); - const request = server.requests[0]; - - expect(request.url).to.contain(`&us_privacy=${encodeURIComponent(uspData)}`); - expect(request.url).to.contain(`&gpp=${encodeURIComponent(gppData.gppString)}`); - expect(request.url).to.contain(`&gdpr_consent=${encodeURIComponent(gdprData.consentString)}`); - expect(request.url).to.contain(`&gdpr=1`); - gppStub.restore(); - uspStub.restore(); - gdprStub.restore(); - }); - - it('should not send request if manualWinReportEnabled is true', function () { - iiqAnalyticsAnalyticsAdapter.initOptions.manualWinReportEnabled = true; - events.emit(EVENTS.BID_WON, wonRequest); - expect(server.requests.length).to.equal(1); - }); - - it('should read data from local storage', function () { - localStorage.setItem(FIRST_PARTY_KEY, '{"group": "A"}'); - localStorage.setItem(FIRST_PARTY_KEY + '_' + partner, '{"data":"testpcid", "eidl": 10}'); - events.emit(EVENTS.BID_WON, wonRequest); - expect(iiqAnalyticsAnalyticsAdapter.initOptions.dataInLs).to.equal('testpcid'); - expect(iiqAnalyticsAnalyticsAdapter.initOptions.eidl).to.equal(10); - expect(iiqAnalyticsAnalyticsAdapter.initOptions.currentGroup).to.equal('A'); - }); - - it('should handle initialization values from local storage', function () { - localStorage.setItem(FIRST_PARTY_KEY, '{"pcid":"testpcid", "group": "B"}'); - localStorage.setItem(FIRST_PARTY_KEY + '_' + partner, '{"data":"testpcid"}'); - events.emit(EVENTS.BID_WON, wonRequest); - expect(iiqAnalyticsAnalyticsAdapter.initOptions.currentGroup).to.equal('B'); - expect(iiqAnalyticsAnalyticsAdapter.initOptions.fpid).to.be.not.null; - }); - - it('should handle reportExternalWin', function () { - events.emit(EVENTS.BID_REQUESTED); - iiqAnalyticsAnalyticsAdapter.initOptions.manualWinReportEnabled = true; - localStorage.setItem(FIRST_PARTY_KEY, '{"pcid":"testpcid", "group": "B"}'); - localStorage.setItem(FIRST_PARTY_KEY + '_' + partner, '{"data":"testpcid"}'); - expect(window[`intentIqAnalyticsAdapter_${partner}`].reportExternalWin).to.be.a('function'); - expect(window[`intentIqAnalyticsAdapter_${partner}`].reportExternalWin({cpm: 1, currency: 'USD'})).to.equal(false); - }); - - it('should return window.location.href when window.self === window.top', function () { - // Stub helper functions - getWindowSelfStub = sinon.stub(utils, 'getWindowSelf').returns(window); - getWindowTopStub = sinon.stub(utils, 'getWindowTop').returns(window); - getWindowLocationStub = sinon.stub(utils, 'getWindowLocation').returns({ href: 'http://localhost:9876/' }); - - const referrer = getReferrer(); - expect(referrer).to.equal('http://localhost:9876/'); - }); - - it('should return window.top.location.href when window.self !== window.top and access is successful', function () { - // Stub helper functions to simulate iframe - getWindowSelfStub = sinon.stub(utils, 'getWindowSelf').returns({}); - getWindowTopStub = sinon.stub(utils, 'getWindowTop').returns({ location: { href: 'http://example.com/' } }); - - const referrer = getReferrer(); - - expect(referrer).to.equal('http://example.com/'); - }); - - it('should return an empty string and log an error when accessing window.top.location.href throws an error', function () { - // Stub helper functions to simulate error - getWindowSelfStub = sinon.stub(utils, 'getWindowSelf').returns({}); - getWindowTopStub = sinon.stub(utils, 'getWindowTop').throws(new Error('Access denied')); - - const referrer = getReferrer(); - expect(referrer).to.equal(''); - expect(logErrorStub.calledOnce).to.be.true; - expect(logErrorStub.firstCall.args[0]).to.contain('Error accessing location: Error: Access denied'); - }); - - it('should not send request if the browser is in blacklist (chrome)', function () { - const USERID_CONFIG_BROWSER = [...getUserConfig()]; - USERID_CONFIG_BROWSER[0].params.browserBlackList = 'ChrOmE'; - - config.getConfig.restore(); - sinon.stub(config, 'getConfig').withArgs('userSync.userIds').returns(USERID_CONFIG_BROWSER); - detectBrowserStub = sinon.stub(detectBrowserUtils, 'detectBrowser').returns('chrome'); - - localStorage.setItem(FIRST_PARTY_KEY, defaultData); - events.emit(EVENTS.BID_WON, wonRequest); - - expect(server.requests.length).to.equal(0); - }); - - it('should send request if the browser is not in blacklist (safari)', function () { - const USERID_CONFIG_BROWSER = [...getUserConfig()]; - USERID_CONFIG_BROWSER[0].params.browserBlackList = 'chrome,firefox'; - - config.getConfig.restore(); - sinon.stub(config, 'getConfig').withArgs('userSync.userIds').returns(USERID_CONFIG_BROWSER); - detectBrowserStub = sinon.stub(detectBrowserUtils, 'detectBrowser').returns('safari'); - - localStorage.setItem(FIRST_PARTY_KEY, defaultData); - events.emit(EVENTS.BID_WON, wonRequest); - - expect(server.requests.length).to.be.above(0); - const request = server.requests[0]; - expect(request.url).to.contain(`https://reports.intentiq.com/report?pid=${partner}&mct=1`); - expect(request.url).to.contain(`&jsver=${version}`); - expect(request.url).to.contain(`&vrref=${encodeURIComponent('http://localhost:9876/')}`); - expect(request.url).to.contain('&payload='); - expect(request.url).to.contain('iiqid=f961ffb1-a0e1-4696-a9d2-a21d815bd344'); - }); - - it('should send request in reportingServerAddress no gdpr', function () { - const USERID_CONFIG_BROWSER = [...getUserConfigWithReportingServerAddress()]; - USERID_CONFIG_BROWSER[0].params.browserBlackList = 'chrome,firefox'; - - config.getConfig.restore(); - sinon.stub(config, 'getConfig').withArgs('userSync.userIds').returns(USERID_CONFIG_BROWSER); - detectBrowserStub = sinon.stub(detectBrowserUtils, 'detectBrowser').returns('safari'); - - localStorage.setItem(FIRST_PARTY_KEY, defaultData); - events.emit(EVENTS.BID_WON, wonRequest); - - expect(server.requests.length).to.be.above(0); - const request = server.requests[0]; - expect(request.url).to.contain(REPORT_SERVER_ADDRESS); - }); - - it('should include source parameter in report URL', function () { - localStorage.setItem(FIRST_PARTY_KEY, JSON.stringify(defaultData)); - - events.emit(EVENTS.BID_WON, wonRequest); - const request = server.requests[0]; - - expect(server.requests.length).to.be.above(0); - expect(request.url).to.include(`&source=${PREBID}`); - }); - - it('should use correct key if siloEnabled is true', function () { - const siloEnabled = true; - const USERID_CONFIG = [...getUserConfig()]; - USERID_CONFIG[0].params.siloEnabled = siloEnabled; - - config.getConfig.restore(); - sinon.stub(config, 'getConfig').withArgs('userSync.userIds').returns(USERID_CONFIG); - - localStorage.setItem(FIRST_PARTY_KEY, `${FIRST_PARTY_KEY}${siloEnabled ? '_p_' + partner : ''}`); - events.emit(EVENTS.BID_WON, wonRequest); - - expect(server.requests.length).to.be.above(0); - const request = server.requests[0]; - expect(request.url).to.contain(REPORT_ENDPOINT + '?pid=' + partner + '&mct=1'); - }); - - it('should send additionalParams in report if valid and small enough', function () { - const userConfig = getUserConfig(); - userConfig[0].params.additionalParams = [{ - parameterName: 'general', - parameterValue: 'Lee', - destination: [0, 0, 1] - }]; - - config.getConfig.restore(); - sinon.stub(config, 'getConfig').withArgs('userSync.userIds').returns(userConfig); - - localStorage.setItem(FIRST_PARTY_KEY, defaultData); - events.emit(EVENTS.BID_WON, wonRequest); - - const request = server.requests[0]; - expect(request.url).to.include('general=Lee'); - }); - - it('should not send additionalParams in report if value is too large', function () { - const longVal = 'x'.repeat(5000000); - const userConfig = getUserConfig(); - userConfig[0].params.additionalParams = [{ - parameterName: 'general', - parameterValue: longVal, - destination: [0, 0, 1] - }]; - - config.getConfig.restore(); - sinon.stub(config, 'getConfig').withArgs('userSync.userIds').returns(userConfig); - - localStorage.setItem(FIRST_PARTY_KEY, defaultData); - events.emit(EVENTS.BID_WON, wonRequest); - - const request = server.requests[0]; - expect(request.url).not.to.include('general'); - }); - it('should include spd parameter from LS in report URL', function () { - const spdObject = { foo: 'bar', value: 42 }; - const expectedSpdEncoded = encodeURIComponent(JSON.stringify(spdObject)); - - localStorage.setItem(FIRST_PARTY_KEY, JSON.stringify({...defaultData, spd: spdObject})); - getWindowLocationStub = sinon.stub(utils, 'getWindowLocation').returns({ href: 'http://localhost:9876/' }); - - events.emit(EVENTS.BID_WON, wonRequest); - - const request = server.requests[0]; - - expect(server.requests.length).to.be.above(0); - expect(request.url).to.include(`&spd=${expectedSpdEncoded}`); - }); - - it('should include spd parameter string from LS in report URL', function () { - const spdObject = 'server provided data'; - const expectedSpdEncoded = encodeURIComponent(spdObject); - - localStorage.setItem(FIRST_PARTY_KEY, JSON.stringify({...defaultData, spd: spdObject})); - getWindowLocationStub = sinon.stub(utils, 'getWindowLocation').returns({ href: 'http://localhost:9876/' }); - - events.emit(EVENTS.BID_WON, wonRequest); - - const request = server.requests[0]; - - expect(server.requests.length).to.be.above(0); - expect(request.url).to.include(`&spd=${expectedSpdEncoded}`); - }); - - const testCasesVrref = [ - { - description: 'domainName matches window.top.location.href', - getWindowSelf: {}, - getWindowTop: { location: { href: 'http://example.com/page' } }, - getWindowLocation: { href: 'http://example.com/page' }, - domainName: 'example.com', - expectedVrref: encodeURIComponent('http://example.com/page'), - shouldContainFui: false - }, - { - description: 'domainName does not match window.top.location.href', - getWindowSelf: {}, - getWindowTop: { location: { href: 'http://anotherdomain.com/page' } }, - getWindowLocation: { href: 'http://anotherdomain.com/page' }, - domainName: 'example.com', - expectedVrref: encodeURIComponent('example.com'), - shouldContainFui: false - }, - { - description: 'domainName is missing, only fui=1 is returned', - getWindowSelf: {}, - getWindowTop: { location: { href: '' } }, - getWindowLocation: { href: '' }, - domainName: null, - expectedVrref: '', - shouldContainFui: true - }, - { - description: 'domainName is missing', - getWindowSelf: {}, - getWindowTop: { location: { href: 'http://example.com/page' } }, - getWindowLocation: { href: 'http://example.com/page' }, - domainName: null, - expectedVrref: encodeURIComponent('http://example.com/page'), - shouldContainFui: false - }, - ]; - - testCasesVrref.forEach(({ description, getWindowSelf, getWindowTop, getWindowLocation, domainName, expectedVrref, shouldContainFui }) => { - it(`should append correct vrref when ${description}`, function () { - getWindowSelfStub = sinon.stub(utils, 'getWindowSelf').returns(getWindowSelf); - getWindowTopStub = sinon.stub(utils, 'getWindowTop').returns(getWindowTop); - getWindowLocationStub = sinon.stub(utils, 'getWindowLocation').returns(getWindowLocation); - - const url = 'https://reports.intentiq.com/report?pid=10'; - const modifiedUrl = appendVrrefAndFui(url, domainName); - const urlObj = new URL(modifiedUrl); - - const vrref = encodeURIComponent(urlObj.searchParams.get('vrref') || ''); - const fui = urlObj.searchParams.get('fui'); - - expect(vrref).to.equal(expectedVrref); - expect(urlObj.searchParams.has('fui')).to.equal(shouldContainFui); - if (shouldContainFui) { - expect(fui).to.equal('1'); - } - }); - }); - - const adUnitConfigTests = [ - { - adUnitConfig: 1, - description: 'should extract adUnitCode first (adUnitConfig = 1)', - event: { adUnitCode: 'adUnitCode-123', placementId: 'placementId-456' }, - expectedPlacementId: 'adUnitCode-123' - }, - { - adUnitConfig: 1, - description: 'should extract placementId if there is no adUnitCode (adUnitConfig = 1)', - event: { placementId: 'placementId-456' }, - expectedPlacementId: 'placementId-456' - }, - { - adUnitConfig: 2, - description: 'should extract placementId first (adUnitConfig = 2)', - event: { adUnitCode: 'adUnitCode-123', placementId: 'placementId-456' }, - expectedPlacementId: 'placementId-456' - }, - { - adUnitConfig: 2, - description: 'should extract adUnitCode if there is no placementId (adUnitConfig = 2)', - event: { adUnitCode: 'adUnitCode-123', }, - expectedPlacementId: 'adUnitCode-123' - }, - { - adUnitConfig: 3, - description: 'should extract only adUnitCode (adUnitConfig = 3)', - event: { adUnitCode: 'adUnitCode-123', placementId: 'placementId-456' }, - expectedPlacementId: 'adUnitCode-123' - }, - { - adUnitConfig: 4, - description: 'should extract only placementId (adUnitConfig = 4)', - event: { adUnitCode: 'adUnitCode-123', placementId: 'placementId-456' }, - expectedPlacementId: 'placementId-456' - }, - { - adUnitConfig: 1, - description: 'should return empty placementId if neither adUnitCode or placementId exist', - event: {}, - expectedPlacementId: '' - }, - { - adUnitConfig: 1, - description: 'should extract placementId from params array if no top-level adUnitCode or placementId exist (adUnitConfig = 1)', - event: { - params: [{ someKey: 'value' }, { placementId: 'nested-placementId' }] - }, - expectedPlacementId: 'nested-placementId' - } - ]; - - adUnitConfigTests.forEach(({ adUnitConfig, description, event, expectedPlacementId }) => { - it(description, function () { - const [userConfig] = getUserConfig(); - userConfig.params.adUnitConfig = adUnitConfig; - - config.getConfig.restore(); - sinon.stub(config, 'getConfig').withArgs('userSync.userIds').returns([userConfig]); - - const testEvent = { ...wonRequest, ...event }; - events.emit(EVENTS.BID_WON, testEvent); - - const request = server.requests[0]; - const urlParams = new URL(request.url); - const encodedPayload = urlParams.searchParams.get('payload'); - const decodedPayload = JSON.parse(atob(JSON.parse(encodedPayload)[0])); - - expect(server.requests.length).to.be.above(0); - expect(encodedPayload).to.exist; - expect(decodedPayload).to.have.property('placementId', expectedPlacementId); - }); - }); -}); diff --git a/test/spec/modules/intenzeBidAdapter_spec.js b/test/spec/modules/intenzeBidAdapter_spec.js deleted file mode 100644 index 330c207b8..000000000 --- a/test/spec/modules/intenzeBidAdapter_spec.js +++ /dev/null @@ -1,416 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/intenzeBidAdapter'; -import { config } from 'src/config.js'; - -const NATIVE_BID_REQUEST = { - code: 'native_example', - mediaTypes: { - native: { - title: { - required: true, - len: 800 - }, - image: { - required: true, - len: 80 - }, - sponsoredBy: { - required: true - }, - clickUrl: { - required: true - }, - privacyLink: { - required: false - }, - body: { - required: true - }, - icon: { - required: true, - sizes: [50, 50] - } - } - }, - bidder: 'intenze', - params: { - placementId: 'hash', - accountId: 'accountId' - }, - timeout: 1000 - -}; - -const BANNER_BID_REQUEST = { - code: 'banner_example', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ] - } - }, - bidder: 'intenze', - params: { - placementId: 'hash', - accountId: 'accountId' - }, - timeout: 1000, - gdprConsent: { - consentString: 'BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA', - gdprApplies: 1, - }, - uspConsent: 'uspConsent' -} - -const bidRequest = { - refererInfo: { - referer: 'test.com' - } -} - -const VIDEO_BID_REQUEST = { - code: 'video1', - sizes: [640, 480], - mediaTypes: { - video: { - minduration: 0, - maxduration: 999, - boxingallowed: 1, - skip: 0, - mimes: [ - 'application/javascript', - 'video/mp4' - ], - w: 1920, - h: 1080, - protocols: [ - 2 - ], - linearity: 1, - api: [ - 1, - 2 - ] - } - }, - - bidder: 'intenze', - params: { - placementId: 'hash', - accountId: 'accountId' - }, - timeout: 1000 - -} - -const BANNER_BID_RESPONSE = { - id: 'request_id', - bidid: 'request_imp_id', - seatbid: [{ - bid: [{ - id: 'bid_id', - impid: 'request_imp_id', - price: 5, - adomain: ['example.com'], - adm: 'admcode', - crid: 'crid', - ext: { - mediaType: 'banner' - } - }], - }], -}; - -const VIDEO_BID_RESPONSE = { - id: 'request_id', - bidid: 'request_imp_id', - seatbid: [{ - bid: [{ - id: 'bid_id', - impid: 'request_imp_id', - price: 5, - adomain: ['example.com'], - adm: 'admcode', - crid: 'crid', - ext: { - mediaType: 'video', - vastUrl: 'http://example.vast', - } - }], - }], -}; - -const imgData = { - url: `https://example.com/image`, - w: 1200, - h: 627 -}; - -const NATIVE_BID_RESPONSE = { - id: 'request_id', - bidid: 'request_imp_id', - seatbid: [{ - bid: [{ - id: 'bid_id', - impid: 'request_imp_id', - price: 5, - adomain: ['example.com'], - adm: { - native: { - assets: [{ - id: 0, - title: 'dummyText' - }, - { - id: 3, - image: imgData - }, - { - id: 5, - data: { - value: 'organization.name' - } - } - ], - link: { - url: 'example.com' - }, - imptrackers: ['tracker1.com', 'tracker2.com', 'tracker3.com'], - jstracker: 'tracker1.com' - } - }, - crid: 'crid', - ext: { - mediaType: 'native' - } - }], - }], -}; - -describe('IntenzeAdapter', function () { - describe('with COPPA', function () { - beforeEach(function () { - sinon.stub(config, 'getConfig') - .withArgs('coppa') - .returns(true); - }); - afterEach(function () { - config.getConfig.restore(); - }); - - it('should send the Coppa "required" flag set to "1" in the request', function () { - const serverRequest = spec.buildRequests([BANNER_BID_REQUEST]); - expect(serverRequest.data[0].regs.coppa).to.equal(1); - }); - }); - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(NATIVE_BID_REQUEST)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const bid = Object.assign({}, NATIVE_BID_REQUEST); - delete bid.params; - bid.params = { - 'IncorrectParam': 0 - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('build Native Request', function () { - const request = spec.buildRequests([NATIVE_BID_REQUEST], bidRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(request).to.exist; - expect(request.method).to.exist; - expect(request.url).to.exist; - expect(request.data).to.exist; - }); - - it('sends bid request to our endpoint via POST', function () { - expect(request.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(request.url).to.equal('https://lb-east.intenze.co/bid?pass=accountId&integration=prebidjs'); - }); - - it('Returns empty data if no valid requests are passed', function () { - const serverRequest = spec.buildRequests([]); - expect(serverRequest).to.be.an('array').that.is.empty; - }); - }); - - describe('build Banner Request', function () { - const request = spec.buildRequests([BANNER_BID_REQUEST]); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(request).to.exist; - expect(request.method).to.exist; - expect(request.url).to.exist; - expect(request.data).to.exist; - }); - - it('check consent and ccpa string is set properly', function () { - expect(request.data[0].regs.ext.gdpr).to.equal(1); - expect(request.data[0].user.ext.consent).to.equal(BANNER_BID_REQUEST.gdprConsent.consentString); - expect(request.data[0].regs.ext.us_privacy).to.equal(BANNER_BID_REQUEST.uspConsent); - }); - - it('sends bid request to our endpoint via POST', function () { - expect(request.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(request.url).to.equal('https://lb-east.intenze.co/bid?pass=accountId&integration=prebidjs'); - }); - }); - - describe('build Video Request', function () { - const request = spec.buildRequests([VIDEO_BID_REQUEST]); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(request).to.exist; - expect(request.method).to.exist; - expect(request.url).to.exist; - expect(request.data).to.exist; - }); - - it('sends bid request to our endpoint via POST', function () { - expect(request.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(request.url).to.equal('https://lb-east.intenze.co/bid?pass=accountId&integration=prebidjs'); - }); - }); - - describe('interpretResponse', function () { - it('Empty response must return empty array', function () { - const emptyResponse = null; - const response = spec.interpretResponse(emptyResponse); - - expect(response).to.be.an('array').that.is.empty; - }) - - it('Should interpret banner response', function () { - const bannerResponse = { - body: [BANNER_BID_RESPONSE] - } - - const expectedBidResponse = { - requestId: BANNER_BID_RESPONSE.id, - cpm: BANNER_BID_RESPONSE.seatbid[0].bid[0].price, - width: BANNER_BID_RESPONSE.seatbid[0].bid[0].w, - height: BANNER_BID_RESPONSE.seatbid[0].bid[0].h, - ttl: BANNER_BID_RESPONSE.ttl || 1200, - currency: BANNER_BID_RESPONSE.cur || 'USD', - netRevenue: true, - creativeId: BANNER_BID_RESPONSE.seatbid[0].bid[0].crid, - dealId: BANNER_BID_RESPONSE.seatbid[0].bid[0].dealid, - mediaType: 'banner', - meta: BANNER_BID_RESPONSE.seatbid[0].bid[0].adomain, - ad: BANNER_BID_RESPONSE.seatbid[0].bid[0].adm - } - - const bannerResponses = spec.interpretResponse(bannerResponse); - - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(expectedBidResponse.requestId); - expect(dataItem.cpm).to.equal(expectedBidResponse.cpm); - expect(dataItem.ad).to.equal(expectedBidResponse.ad); - expect(dataItem.ttl).to.equal(expectedBidResponse.ttl); - expect(dataItem.creativeId).to.equal(expectedBidResponse.creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.meta).to.have.property('advertiserDomains', expectedBidResponse.meta); - expect(dataItem.currency).to.equal(expectedBidResponse.currency); - expect(dataItem.width).to.equal(expectedBidResponse.width); - expect(dataItem.height).to.equal(expectedBidResponse.height); - }); - - it('Should interpret video response', function () { - const videoResponse = { - body: [VIDEO_BID_RESPONSE] - } - - const expectedBidResponse = { - requestId: VIDEO_BID_RESPONSE.id, - cpm: VIDEO_BID_RESPONSE.seatbid[0].bid[0].price, - width: VIDEO_BID_RESPONSE.seatbid[0].bid[0].w, - height: VIDEO_BID_RESPONSE.seatbid[0].bid[0].h, - ttl: VIDEO_BID_RESPONSE.ttl || 1200, - currency: VIDEO_BID_RESPONSE.cur || 'USD', - netRevenue: true, - creativeId: VIDEO_BID_RESPONSE.seatbid[0].bid[0].crid, - dealId: VIDEO_BID_RESPONSE.seatbid[0].bid[0].dealid, - mediaType: 'video', - meta: VIDEO_BID_RESPONSE.seatbid[0].bid[0].adomain, - vastXml: VIDEO_BID_RESPONSE.seatbid[0].bid[0].adm, - vastUrl: VIDEO_BID_RESPONSE.seatbid[0].bid[0].ext.vastUrl - } - - const videoResponses = spec.interpretResponse(videoResponse); - - expect(videoResponses).to.be.an('array').that.is.not.empty; - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'vastXml', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(expectedBidResponse.requestId); - expect(dataItem.cpm).to.equal(expectedBidResponse.cpm); - expect(dataItem.vastXml).to.equal(expectedBidResponse.vastXml); - expect(dataItem.ttl).to.equal(expectedBidResponse.ttl); - expect(dataItem.creativeId).to.equal(expectedBidResponse.creativeId); - expect(dataItem.meta).to.have.property('advertiserDomains', expectedBidResponse.meta); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(expectedBidResponse.currency); - expect(dataItem.width).to.equal(expectedBidResponse.width); - expect(dataItem.height).to.equal(expectedBidResponse.height); - }); - - it('Should interpret native response', function () { - const nativeResponse = { - body: [NATIVE_BID_RESPONSE] - } - - const expectedBidResponse = { - requestId: NATIVE_BID_RESPONSE.id, - cpm: NATIVE_BID_RESPONSE.seatbid[0].bid[0].price, - width: NATIVE_BID_RESPONSE.seatbid[0].bid[0].w, - height: NATIVE_BID_RESPONSE.seatbid[0].bid[0].h, - ttl: NATIVE_BID_RESPONSE.ttl || 1200, - currency: NATIVE_BID_RESPONSE.cur || 'USD', - netRevenue: true, - creativeId: NATIVE_BID_RESPONSE.seatbid[0].bid[0].crid, - dealId: NATIVE_BID_RESPONSE.seatbid[0].bid[0].dealid, - meta: NATIVE_BID_RESPONSE.seatbid[0].bid[0].adomain, - mediaType: 'native', - native: { - clickUrl: NATIVE_BID_RESPONSE.seatbid[0].bid[0].adm.native.link.url - } - } - - const nativeResponses = spec.interpretResponse(nativeResponse); - - expect(nativeResponses).to.be.an('array').that.is.not.empty; - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'native', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(expectedBidResponse.requestId); - expect(dataItem.cpm).to.equal(expectedBidResponse.cpm); - expect(dataItem.native.clickUrl).to.equal(expectedBidResponse.native.clickUrl); - expect(dataItem.ttl).to.equal(expectedBidResponse.ttl); - expect(dataItem.meta).to.have.property('advertiserDomains', expectedBidResponse.meta); - expect(dataItem.creativeId).to.equal(expectedBidResponse.creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(expectedBidResponse.currency); - expect(dataItem.width).to.equal(expectedBidResponse.width); - expect(dataItem.height).to.equal(expectedBidResponse.height); - }); - }); -}) diff --git a/test/spec/modules/interactiveOffersBidAdapter_spec.js b/test/spec/modules/interactiveOffersBidAdapter_spec.js deleted file mode 100644 index 300e800bc..000000000 --- a/test/spec/modules/interactiveOffersBidAdapter_spec.js +++ /dev/null @@ -1,43 +0,0 @@ -import { expect } from 'chai'; -import {spec} from 'modules/interactiveOffersBidAdapter.js'; - -describe('Interactive Offers Prebbid.js Adapter', function() { - describe('isBidRequestValid function', function() { - const bid = {bidder: 'interactiveOffers', params: {partnerId: '100', tmax: 300}, mediaTypes: {banner: {sizes: [[300, 250]]}}, adUnitCode: 'pageAd01', transactionId: '16526f30-3be2-43f6-ab37-f1ab1f2ac25d', sizes: [[300, 250]], bidId: '227faa83f86546', bidderRequestId: '1eb79bc9dd44a', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', src: 'client', bidRequestsCount: 1, bidderRequestsCount: 1, bidderWinsCount: 0}; - - it('returns true if all the required params are present and properly formatted', function() { - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - - it('returns false if any if the required params is missing', function() { - bid.params = {}; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('returns false if any if the required params is not properly formatted', function() { - bid.params = {partnerid: '100', tmax: 250}; - expect(spec.isBidRequestValid(bid)).to.be.false; - bid.params = {partnerId: '100', tmax: '+250'}; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - }); - describe('buildRequests function', function() { - const validBidRequests = [{bidder: 'interactiveOffers', params: {partnerId: '100', tmax: 300}, mediaTypes: {banner: {sizes: [[300, 250]]}}, adUnitCode: 'pageAd01', transactionId: '16526f30-3be2-43f6-ab37-f1ab1f2ac25d', sizes: [[300, 250]], bidId: '227faa83f86546', bidderRequestId: '1eb79bc9dd44a', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', src: 'client', bidRequestsCount: 1, bidderRequestsCount: 1, bidderWinsCount: 0}]; - const bidderRequest = {bidderCode: 'interactiveOffers', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', bidderRequestId: '1eb79bc9dd44a', bids: [{bidder: 'interactiveOffers', params: {partnerId: '100', tmax: 300}, mediaTypes: {banner: {sizes: [[300, 250]]}}, adUnitCode: 'pageAd01', transactionId: '16526f30-3be2-43f6-ab37-f1ab1f2ac25d', sizes: [[300, 250]], bidId: '227faa83f86546', bidderRequestId: '1eb79bc9dd44a', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', src: 'client', bidRequestsCount: 1, bidderRequestsCount: 1, bidderWinsCount: 0}], timeout: 5000, refererInfo: {referer: 'http://www.google.com', reachedTop: true, isAmp: false, numIframes: 0, stack: ['http://www.google.com'], canonicalUrl: null}}; - - it('returns a Prebid.js request object with a valid json string at the "data" property', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.length.above(0); - }); - }); - describe('interpretResponse function', function() { - const openRTBResponse = {body: [{cur: 'USD', id: '2052afa35febb79baa9893cc3ae8b83b89740df65fe98b1bd358dbae6e912801', seatbid: [{seat: 1493, bid: [{ext: {tagid: '227faa83f86546'}, crid: '24477', adm: '', nurl: '', adid: '1138', adomain: ['url.com'], price: '1.53', w: 300, h: 250, iurl: 'http://url.com', cat: ['IAB13-11'], id: '5507ced7a39c06942d3cb260197112ba712e4180', attr: [], impid: 1, cid: '13280'}]}], 'bidid': '0959b9d58ba71b3db3fa29dce3b117c01fc85de0'}], 'headers': {}}; - const prebidRequest = {method: 'POST', url: 'https://url.com', data: '{"id": "1aad860c-e04b-482b-acac-0da55ed491c8", "site": {"id": "url.com", "name": "url.com", "domain": "url.com", "page": "http://url.com", "ref": "http://url.com", "publisher": {"id": 100, "name": "http://url.com", "domain": "url.com"}, "content": {"language": "pt-PT"}}, "source": {"fd": 0, "tid": "1aad860c-e04b-482b-acac-0da55ed491c8", "pchain": ""}, "device": {"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 11_2_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36", "language": "pt-PT"}, "user": {}, "imp": [{"id":1, "secure": 0, "tagid": "227faa83f86546", "banner": {"pos": 0, "w": 300, "h": 250, "format": [{"w": 300, "h": 250}]}}], "tmax": 300}', bidderRequest: {bidderCode: 'interactiveOffers', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', bidderRequestId: '1eb79bc9dd44a', bids: [{bidder: 'interactiveOffers', params: {partnerId: '100', tmax: 300}, mediaTypes: {banner: {sizes: [[300, 250]]}}, adUnitCode: 'pageAd01', transactionId: '16526f30-3be2-43f6-ab37-f1ab1f2ac25d', sizes: [[300, 250]], bidId: '227faa83f86546', bidderRequestId: '1eb79bc9dd44a', auctionId: '1aad860c-e04b-482b-acac-0da55ed491c8', src: 'client', bidRequestsCount: 1, bidderRequestsCount: 1, bidderWinsCount: 0}], timeout: 5000, refererInfo: {referer: 'http://url.com', reachedTop: true, isAmp: false, numIframes: 0, stack: ['http://url.com'], canonicalUrl: null}}}; - - it('returns an array of Prebid.js response objects', function() { - const prebidResponses = spec.interpretResponse(openRTBResponse, prebidRequest); - expect(prebidResponses).to.not.be.empty; - expect(prebidResponses[0].meta.advertiserDomains[0]).to.equal('url.com'); - }); - }); -}); diff --git a/test/spec/modules/intersectionRtdProvider_spec.js b/test/spec/modules/intersectionRtdProvider_spec.js deleted file mode 100644 index d2885810b..000000000 --- a/test/spec/modules/intersectionRtdProvider_spec.js +++ /dev/null @@ -1,164 +0,0 @@ -import {config as _config, config} from 'src/config.js'; -import { expect } from 'chai'; -import * as events from 'src/events.js'; -import * as prebidGlobal from 'src/prebidGlobal.js'; -import { intersectionSubmodule } from 'modules/intersectionRtdProvider.js'; -import * as utils from 'src/utils.js'; -import {getGlobal} from 'src/prebidGlobal.js'; -import 'src/prebid.js'; - -describe('Intersection RTD Provider', function () { - let sandbox; - let placeholder; - const pbjs = getGlobal(); - const adUnit = { - code: 'ad-slot-1', - mediaTypes: { - banner: { - sizes: [ [300, 250] ] - } - }, - bids: [ - { - bidder: 'fake' - } - ] - }; - const providerConfig = {name: 'intersection', waitForIt: true}; - const rtdConfig = {realTimeData: {auctionDelay: 200, dataProviders: [providerConfig]}} - describe('IntersectionObserver not supported', function() { - beforeEach(function() { - sandbox = sinon.createSandbox(); - }); - afterEach(function() { - sandbox.restore(); - sandbox = undefined; - }); - it('init should return false', function () { - sandbox.stub(window, 'IntersectionObserver').value(undefined); - expect(intersectionSubmodule.init({})).is.false; - }); - }); - describe('IntersectionObserver supported', function() { - beforeEach(function() { - sandbox = sinon.createSandbox(); - placeholder = createDiv(); - append(); - const __config = {}; - sandbox.stub(_config, 'getConfig').callsFake(function (path) { - return utils.deepAccess(__config, path); - }); - sandbox.stub(_config, 'setConfig').callsFake(function (obj) { - utils.mergeDeep(__config, obj); - }); - sandbox.stub(window, 'IntersectionObserver').callsFake(function (cb) { - return { - observe(el) { - cb([ - { - target: el, - intersectionRatio: 1, - isIntersecting: true, - time: Date.now(), - boundingClientRect: {left: 0, top: 0, right: 0, bottom: 0, width: 0, height: 0, x: 0, y: 0}, - intersectionRect: {left: 0, top: 0, right: 0, bottom: 0, width: 0, height: 0, x: 0, y: 0}, - rootRect: {left: 0, top: 0, right: 0, bottom: 0, width: 0, height: 0, x: 0, y: 0} - } - ]); - }, - unobserve() {}, - disconnect() {} - }; - }); - }); - afterEach(function() { - sandbox.restore(); - remove(); - sandbox = undefined; - placeholder = undefined; - pbjs.removeAdUnit(); - }); - it('init should return true', function () { - expect(intersectionSubmodule.init({})).is.true; - }); - it('should set intersection. (request with "adUnitCodes")', function(done) { - pbjs.addAdUnits([utils.deepClone(adUnit)]); - config.setConfig(rtdConfig); - const onDone = sandbox.stub(); - const requestBidObject = {adUnitCodes: [adUnit.code]}; - intersectionSubmodule.init({}); - intersectionSubmodule.getBidRequestData( - requestBidObject, - onDone, - providerConfig - ); - setTimeout(function() { - expect(pbjs.adUnits[0].bids[0]).to.have.property('intersection'); - done(); - }, 200); - }); - it('should set intersection. (request with "adUnits")', function(done) { - config.setConfig(rtdConfig); - const onDone = sandbox.stub(); - const requestBidObject = {adUnits: [utils.deepClone(adUnit)]}; - intersectionSubmodule.init(); - intersectionSubmodule.getBidRequestData( - requestBidObject, - onDone, - providerConfig - ); - setTimeout(function() { - expect(requestBidObject.adUnits[0].bids[0]).to.have.property('intersection'); - done(); - }, 200); - }); - it('should set intersection. (request all)', function(done) { - pbjs.addAdUnits([utils.deepClone(adUnit)]); - config.setConfig(rtdConfig); - const onDone = sandbox.stub(); - const requestBidObject = {}; - intersectionSubmodule.init({}); - intersectionSubmodule.getBidRequestData( - requestBidObject, - onDone, - providerConfig - ); - setTimeout(function() { - expect(pbjs.adUnits[0].bids[0]).to.have.property('intersection'); - done(); - }, 200); - }); - it('should call done due timeout', function(done) { - config.setConfig(rtdConfig); - remove(); - const onDone = sandbox.stub(); - const requestBidObject = {adUnits: [utils.deepClone(adUnit)]}; - intersectionSubmodule.init({}); - intersectionSubmodule.getBidRequestData( - requestBidObject, - onDone, - {...providerConfig, test: 1} - ); - setTimeout(function() { - sinon.assert.calledOnce(onDone); - expect(requestBidObject.adUnits[0].bids[0]).to.not.have.property('intersection'); - done(); - }, 300); - }); - }); - function createDiv() { - const div = document.createElement('div'); - div.id = adUnit.code; - return div; - } - function append() { - if (placeholder) { - document.body.appendChild(placeholder); - } - } - function remove() { - if (placeholder && placeholder.parentElement) { - placeholder.parentElement.removeChild(placeholder); - } - } -}); diff --git a/test/spec/modules/invamiaBidAdapter_spec.js b/test/spec/modules/invamiaBidAdapter_spec.js deleted file mode 100644 index 2f8f0612e..000000000 --- a/test/spec/modules/invamiaBidAdapter_spec.js +++ /dev/null @@ -1,172 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/invamiaBidAdapter.js'; - -describe('invamia bid adapter tests', function () { - describe('bid requests', function () { - it('should accept valid bid', function () { - const validBid = { - bidder: 'invamia', - params: {zoneId: 123}, - }; - - expect(spec.isBidRequestValid(validBid)).to.equal(true); - }); - - it('should reject invalid bid', function () { - const invalidBid = { - bidder: 'invamia', - params: {}, - }; - - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should correctly build payload string', function () { - const bidRequests = [{ - bidder: 'invamia', - params: {zoneId: 123}, - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - bidId: '23acc48ad47af5', - auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: '92489f71-1bf2-49a0-adf9-000cea934729', - }]; - const payload = spec.buildRequests(bidRequests)[0].data; - - expect(payload).to.contain('ctype=div'); - expect(payload).to.contain('pzoneid=123'); - expect(payload).to.contain('width=300'); - expect(payload).to.contain('height=250'); - }); - - it('should support multiple bids', function () { - const bidRequests = [{ - bidder: 'invamia', - params: {zoneId: 123}, - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - bidId: '23acc48ad47af5', - auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: '92489f71-1bf2-49a0-adf9-000cea934729', - }, { - bidder: 'invamia', - params: {zoneId: 321}, - mediaTypes: { - banner: { - sizes: [[728, 90]], - }, - }, - bidId: '23acc48ad47af52', - auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba992', - bidderRequestId: '1c56ad30b9b8ca82', - transactionId: '92489f71-1bf2-49a0-adf9-000cea9347292', - }]; - const payload = spec.buildRequests(bidRequests); - - expect(payload).to.be.lengthOf(2); - }); - - it('should support multiple sizes', function () { - const bidRequests = [{ - bidder: 'invamia', - params: {zoneId: 123}, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - bidId: '23acc48ad47af5', - auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: '92489f71-1bf2-49a0-adf9-000cea934729', - }]; - const payload = spec.buildRequests(bidRequests); - - expect(payload).to.be.lengthOf(2); - }); - }); - - describe('bid responses', function () { - it('should return complete bid response', function () { - const serverResponse = { - body: { - banner: { - hash: '1c56ad30b9b8ca8', - }, - hb: { - cpm: 0.5, - netRevenue: false, - adomains: ['securepubads.g.doubleclick.net'], - }, - template: { - html: '', - }, - }, - }; - const bidderRequest = { - bidId: '23acc48ad47af5', - params: { - requestedSizes: [300, 250], - }, - }; - - const bids = spec.interpretResponse(serverResponse, {bidderRequest}); - - expect(bids).to.be.lengthOf(1); - expect(bids[0].requestId).to.equal('23acc48ad47af5'); - expect(bids[0].creativeId).to.equal('1c56ad30b9b8ca8'); - expect(bids[0].width).to.equal(300); - expect(bids[0].height).to.equal(250); - expect(bids[0].ttl).to.equal(600); - expect(bids[0].cpm).to.equal(0.5); - expect(bids[0].netRevenue).to.equal(false); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].meta.advertiserDomains).to.be.lengthOf(1); - expect(bids[0].meta.advertiserDomains[0]).to.equal('securepubads.g.doubleclick.net'); - }); - - it('should return empty bid response', function () { - const serverResponse = { - body: {}, - }; - const bidderRequest = { - bidId: '23acc48ad47af5', - params: { - requestedSizes: [300, 250], - }, - }; - - const bids = spec.interpretResponse(serverResponse, {bidderRequest}); - - expect(bids).to.be.lengthOf(0); - }); - - it('should return empty bid response 2', function () { - const serverResponse = { - body: { - template: { - html: '', - } - }, - }; - const bidderRequest = { - bidId: '23acc48ad47af5', - params: { - requestedSizes: [300, 250], - }, - }; - - const bids = spec.interpretResponse(serverResponse, {bidderRequest}); - - expect(bids).to.be.lengthOf(0); - }); - }); -}); diff --git a/test/spec/modules/invibesBidAdapter_spec.js b/test/spec/modules/invibesBidAdapter_spec.js deleted file mode 100644 index 2e04551a4..000000000 --- a/test/spec/modules/invibesBidAdapter_spec.js +++ /dev/null @@ -1,1539 +0,0 @@ -import {expect} from 'chai'; -import { config } from 'src/config.js'; -import {spec, resetInvibes, stubDomainOptions, readGdprConsent, storage} from 'modules/invibesBidAdapter.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -describe('invibesBidAdapter:', function () { - const BIDDER_CODE = 'invibes'; - const PLACEMENT_ID = '12345'; - const ENDPOINT = 'https://bid.videostep.com/Bid/VideoAdContent'; - const SYNC_ENDPOINT = 'https://k.r66net.com/GetUserSync'; - - const bidRequests = [ - { - bidId: 'b1', - bidder: BIDDER_CODE, - bidderRequestId: 'r1', - params: { - placementId: PLACEMENT_ID, - disableUserSyncs: false - - }, - adUnitCode: 'test-div1', - auctionId: 'a1', - sizes: [ - [300, 250], - [400, 300], - [125, 125] - ], - transactionId: 't1' - }, { - bidId: 'b2', - bidder: BIDDER_CODE, - bidderRequestId: 'r2', - params: { - placementId: 'abcde', - disableUserSyncs: false - }, - adUnitCode: 'test-div2', - auctionId: 'a2', - sizes: [ - [300, 250], - [400, 300] - ], - transactionId: 't2' - } - ]; - - const bidRequestsWithDuplicatedplacementId = [ - { - bidId: 'b1', - bidder: BIDDER_CODE, - bidderRequestId: 'r1', - params: { - placementId: PLACEMENT_ID, - disableUserSyncs: false - - }, - adUnitCode: 'test-div1', - auctionId: 'a1', - sizes: [ - [300, 250], - [400, 300], - [125, 125] - ], - transactionId: 't1' - }, { - bidId: 'b2', - bidder: BIDDER_CODE, - bidderRequestId: 'r2', - params: { - placementId: PLACEMENT_ID, - disableUserSyncs: false - }, - adUnitCode: 'test-div2', - auctionId: 'a2', - sizes: [ - [300, 250], - [400, 300] - ], - transactionId: 't2' - } - ]; - - const bidRequestsWithUniquePlacementId = [ - { - bidId: 'b1', - bidder: BIDDER_CODE, - bidderRequestId: 'r1', - params: { - placementId: 'PLACEMENT_ID_1', - disableUserSyncs: false - - }, - adUnitCode: 'test-div1', - auctionId: 'a1', - sizes: [ - [300, 250], - [400, 300], - [125, 125] - ], - transactionId: 't1' - }, { - bidId: 'b2', - bidder: BIDDER_CODE, - bidderRequestId: 'r2', - params: { - placementId: 'PLACEMENT_ID_2', - disableUserSyncs: false - }, - adUnitCode: 'test-div2', - auctionId: 'a2', - sizes: [ - [300, 250], - [400, 300] - ], - transactionId: 't2' - } - ]; - - const bidRequestsWithUserId = [ - { - bidId: 'b1', - bidder: BIDDER_CODE, - bidderRequestId: 'r1', - params: { - placementId: PLACEMENT_ID - }, - adUnitCode: 'test-div1', - auctionId: 'a1', - sizes: [ - [300, 250], - [400, 300], - [125, 125] - ], - transactionId: 't1', - userId: { - pubcid: 'pub-cid-code', - pubProvidedId: 'pub-provided-id' - } - }, { - bidId: 'b2', - bidder: BIDDER_CODE, - bidderRequestId: 'r2', - params: { - placementId: 'abcde' - }, - adUnitCode: 'test-div2', - auctionId: 'a2', - sizes: [ - [300, 250], - [400, 300] - ], - transactionId: 't2' - } - ]; - - const bidderRequestWithPageInfo = { - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - }, - auctionStart: Date.now() - } - - const StubbedPersistence = function (initialValue) { - var value = initialValue; - return { - load: function () { - const str = value || ''; - try { - return JSON.parse(str); - } catch (e) { - } - }, - save: function (obj) { - value = JSON.stringify(obj); - } - } - }; - - const SetBidderAccess = function() { - config.setConfig({ - deviceAccess: true - }); - getGlobal().bidderSettings = { - invibes: { - storageAllowed: true - } - }; - } - - let sandbox; - - beforeEach(function () { - resetInvibes(); - getGlobal().bidderSettings = { - invibes: { - storageAllowed: true - } - }; - document.cookie = ''; - this.cStub1 = sinon.stub(console, 'info'); - sandbox = sinon.createSandbox(); - }); - - afterEach(function () { - getGlobal().bidderSettings = {}; - this.cStub1.restore(); - sandbox.restore(); - }); - - describe('isBidRequestValid:', function () { - context('valid bid request:', function () { - it('returns true when bidder params.placementId is set', function () { - const validBid = { - bidder: BIDDER_CODE, - params: { - placementId: PLACEMENT_ID - } - } - - expect(spec.isBidRequestValid(validBid)).to.be.true; - }) - }); - - context('invalid bid request:', function () { - it('returns false when no params', function () { - const invalidBid = { - bidder: BIDDER_CODE - } - - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - - it('returns false when placementId is not set', function () { - const invalidBid = { - bidder: BIDDER_CODE, - params: { - id: '5' - } - } - - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - - it('returns true when bid response was previously received', function () { - const validBid = { - bidder: BIDDER_CODE, - params: { - placementId: PLACEMENT_ID - } - } - - top.window.invibes.bidResponse = {prop: 'prop'}; - expect(spec.isBidRequestValid(validBid)).to.be.true; - }); - }); - }); - - describe('buildRequests', function () { - it('sends preventPageViewEvent as false on first call', function () { - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(request.data.preventPageViewEvent).to.be.false; - }); - - it('sends isPlacementRefresh as false when the placement ids are used for the first time', function () { - const request = spec.buildRequests(bidRequestsWithUniquePlacementId, bidderRequestWithPageInfo); - expect(request.data.isPlacementRefresh).to.be.false; - }); - - it('sends preventPageViewEvent as true on 2nd call', function () { - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(request.data.preventPageViewEvent).to.be.true; - }); - - it('sends isPlacementRefresh as true on multi requests on the same placement id', function () { - const request = spec.buildRequests(bidRequestsWithDuplicatedplacementId, bidderRequestWithPageInfo); - expect(request.data.isPlacementRefresh).to.be.true; - }); - - it('sends isInfiniteScrollPage as false initially', function () { - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(request.data.isInfiniteScrollPage).to.be.false; - }); - - it('sends isPlacementRefresh as true on multi requests multiple calls with the same placement id from second call', function () { - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(request.data.isInfiniteScrollPage).to.be.false; - const duplicatedRequest = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(duplicatedRequest.data.isPlacementRefresh).to.be.true; - }); - - it('sends bid request to ENDPOINT via GET', function () { - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('GET'); - }); - - it('generates a visitId of length 32', function () { - spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(top.window.invibes.visitId.length).to.equal(32); - }); - - it('sends bid request to custom endpoint via GET', function () { - const request = spec.buildRequests([{ - bidId: 'b1', - bidder: BIDDER_CODE, - params: { - placementId: 'placement', - customEndpoint: 'sub.domain.com/Bid/VideoAdContent' - }, - adUnitCode: 'test-div1' - }], bidderRequestWithPageInfo); - expect(request.url).to.equal('sub.domain.com/Bid/VideoAdContent'); - expect(request.method).to.equal('GET'); - }); - - it('sends bid request to default endpoint when no placement', function () { - const request = spec.buildRequests([{ - bidId: 'b1', - bidder: BIDDER_CODE, - params: { - }, - adUnitCode: 'test-div1' - }], bidderRequestWithPageInfo); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('GET'); - }); - - it('sends bid request to default endpoint when null placement', function () { - const request = spec.buildRequests([{ - bidId: 'b1', - bidder: BIDDER_CODE, - params: { - placementId: null - }, - adUnitCode: 'test-div1' - }], bidderRequestWithPageInfo); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('GET'); - }); - - it('sends bid request to default endpoint 1 via GET', function () { - const request = spec.buildRequests([{ - bidId: 'b1', - bidder: BIDDER_CODE, - params: { - placementId: 'placement' - }, - adUnitCode: 'test-div1' - }], bidderRequestWithPageInfo); - expect(request.url).to.equal('https://bid.videostep.com/Bid/VideoAdContent'); - expect(request.method).to.equal('GET'); - }); - - it('sends bid request to network id endpoint 1 via GET', function () { - const request = spec.buildRequests([{ - bidId: 'b1', - bidder: BIDDER_CODE, - params: { - placementId: 'placement', - domainId: 1001 - }, - adUnitCode: 'test-div1' - }], bidderRequestWithPageInfo); - expect(request.url).to.equal('https://bid.videostep.com/Bid/VideoAdContent'); - expect(request.method).to.equal('GET'); - }); - - it('sends bid request to network id endpoint 2 via GET', function () { - const request = spec.buildRequests([{ - bidId: 'b1', - bidder: BIDDER_CODE, - params: { - placementId: 'placement', - domainId: 1002 - }, - adUnitCode: 'test-div1' - }], bidderRequestWithPageInfo); - expect(request.url).to.equal('https://bid2.videostep.com/Bid/VideoAdContent'); - expect(request.method).to.equal('GET'); - }); - - it('sends bid request to network id by placement 1 via GET', function () { - const request = spec.buildRequests([{ - bidId: 'b1', - bidder: BIDDER_CODE, - params: { - placementId: 'infeed_ivbs1' - }, - adUnitCode: 'test-div1' - }], bidderRequestWithPageInfo); - expect(request.url).to.equal('https://bid.videostep.com/Bid/VideoAdContent'); - expect(request.method).to.equal('GET'); - }); - - it('sends bid request to network id by placement 2 via GET', function () { - const request = spec.buildRequests([{ - bidId: 'b1', - bidder: BIDDER_CODE, - params: { - placementId: 'infeed_ivbs2' - }, - adUnitCode: 'test-div1' - }], bidderRequestWithPageInfo); - expect(request.url).to.equal('https://bid2.videostep.com/Bid/VideoAdContent'); - expect(request.method).to.equal('GET'); - }); - - it('sends bid request to network id by placement 10 via GET', function () { - const request = spec.buildRequests([{ - bidId: 'b1', - bidder: BIDDER_CODE, - params: { - placementId: 'infeed_ivbs10' - }, - adUnitCode: 'test-div1' - }], bidderRequestWithPageInfo); - expect(request.url).to.equal('https://bid10.videostep.com/Bid/VideoAdContent'); - expect(request.method).to.equal('GET'); - }); - - it('sends cookies with the bid request', function () { - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(request.options.withCredentials).to.equal(true); - }); - - it('has location, html id, placement and width/height', function () { - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - const parsedData = request.data; - expect(parsedData.location).to.exist; - expect(parsedData.videoAdHtmlId).to.exist; - expect(parsedData.vId).to.exist; - expect(parsedData.width).to.exist; - expect(parsedData.height).to.exist; - }); - - it('has location not cut off', function () { - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - const parsedData = request.data; - expect(parsedData.location).to.contain('?'); - expect(parsedData.location).to.equal('https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue'); - }); - - it('has capped ids if local storage variable is correctly formatted', function () { - top.window.invibes.optIn = 1; - top.window.invibes.purposes = [true, false, false, false, false, false, false, false, false, false]; - localStorage.ivvcap = '{"9731":[1,1768600800000]}'; - SetBidderAccess(); - - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - - expect(request.data.capCounts).to.equal('9731=1'); - }); - - it('does not have capped ids if local storage variable is correctly formatted but no opt in', function () { - const bidderRequest = { - auctionStart: Date.now(), - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - purpose: { - consents: { - 1: false, - 2: false, - 3: false, - 4: false, - 5: false, - 6: false, - 7: false, - 8: false, - 9: false, - 10: false - } - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - - localStorage.ivvcap = '{"9731":[1,1768600800000]}'; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.capCounts).to.equal(''); - }); - - it('does not have capped ids if local storage variable is incorrectly formatted', function () { - localStorage.ivvcap = ':[1,1574334216992]}'; - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(request.data.capCounts).to.equal(''); - }); - - it('does not have capped ids if local storage variable is expired', function () { - localStorage.ivvcap = '{"9731":[1,1574330064104]}'; - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(request.data.capCounts).to.equal(''); - }); - - it('sends query string params from localstorage 1', function () { - localStorage.ivbs = JSON.stringify({bvci: 1}); - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(request.data.bvci).to.equal(1); - }); - - it('sends query string params from localstorage 2', function () { - localStorage.ivbs = JSON.stringify({invibbvlog: true}); - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(request.data.invibbvlog).to.equal(true); - }); - - it('does not send query string params from localstorage if unknwon', function () { - localStorage.ivbs = JSON.stringify({someparam: true}); - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(request.data.someparam).to.be.undefined; - }); - - it('sends all Placement Ids', function () { - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(JSON.parse(request.data.bidParamsJson).placementIds).to.contain(bidRequests[0].params.placementId); - expect(JSON.parse(request.data.bidParamsJson).placementIds).to.contain(bidRequests[1].params.placementId); - }); - - it('sends all adUnitCodes', function () { - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(JSON.parse(request.data.bidParamsJson).adUnitCodes).to.contain(bidRequests[0].adUnitCode); - expect(JSON.parse(request.data.bidParamsJson).adUnitCodes).to.contain(bidRequests[1].adUnitCode); - }); - - it('sends all Placement Ids and userId', function () { - const request = spec.buildRequests(bidRequestsWithUserId, bidderRequestWithPageInfo); - expect(JSON.parse(request.data.bidParamsJson).userId).to.exist; - }); - - it('sends undefined lid when no cookie', function () { - sandbox.stub(storage, 'getDataFromLocalStorage').returns(null); - sandbox.stub(storage, 'getCookie').returns(null); - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(request.data.lId).to.be.undefined; - }); - - it('sends pushed cids if they exist', function () { - top.window.invibes.pushedCids = { 981: [] }; - const request = spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - expect(request.data.pcids).to.contain(981); - }); - - it('sends lid when comes on cookie', function () { - top.window.invibes.optIn = 1; - top.window.invibes.purposes = [true, false, false, false, false, false, false, false, false, false]; - global.document.cookie = 'ivbsdid={"id":"dvdjkams6nkq","cr":' + Date.now() + ',"hc":0}'; - const bidderRequest = { - gdprConsent: { - vendorData: { - vendorConsents: { - 436: true - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - SetBidderAccess(); - - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.lId).to.exist; - }); - - it('does not send handIid when it doesnt exist in cookie', function () { - top.window.invibes.optIn = 1; - top.window.invibes.purposes = [true, false, false, false, false, false, false, false, false, false]; - sandbox.stub(storage, 'getCookie').returns(null) - const bidderRequest = { - gdprConsent: { - vendorData: { - vendorConsents: { - 436: true - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - SetBidderAccess(); - - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.handIid).to.not.exist; - }); - - it('sends handIid when comes on cookie', function () { - top.window.invibes.optIn = 1; - top.window.invibes.purposes = [true, false, false, false, false, false, false, false, false, false]; - global.document.cookie = 'handIid=abcdefghijkk'; - const bidderRequest = { - gdprConsent: { - vendorData: { - vendorConsents: { - 436: true - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - SetBidderAccess(); - - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.handIid).to.equal('abcdefghijkk'); - }); - - it('should send purpose 1', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendor: {consents: {436: true}}, - purpose: { - consents: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true, - 6: true, - 7: true, - 8: true, - 9: true, - 10: true - } - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.purposes.split(',')[0]).to.equal('true'); - }); - - it('should send purpose 2 & 7', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendor: {consents: {436: true}}, - purpose: { - consents: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true, - 6: true, - 7: true, - 8: true, - 9: true, - 10: true - } - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.purposes.split(',')[1] && request.data.purposes.split(',')[6]).to.equal('true'); - }); - - it('should send purpose 9', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendor: {consents: {436: true}}, - purpose: { - consents: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true, - 6: true, - 7: true, - 8: true, - 9: true, - 10: true - } - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.purposes.split(',')[9]).to.equal('true'); - }); - - it('should send legitimateInterests 2 & 7', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendor: {consents: {436: true}}, - purpose: { - consents: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true, - 6: true, - 7: true, - 8: true, - 9: true, - 10: true - }, - legitimateInterests: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true, - 6: true, - 7: true, - 8: true, - 9: true, - 10: true - } - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.li.split(',')[1] && request.data.li.split(',')[6]).to.equal('true'); - }); - it('should send oi = 1 when vendorData is null (calculation will be performed by ADWEB)', function () { - const bidderRequest = { - gdprConsent: { - vendorData: null - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(0); - }); - - it('should send oi = 2 when consent was approved on tcf v2', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendor: {consents: {436: true}}, - purpose: { - consents: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true, - 6: true, - 7: true, - 8: true, - 9: true, - 10: true - } - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(2); - }); - it('should send oi = 0 when vendor consents for invibes are false on tcf v2', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendor: {consents: {436: false}}, - purpose: { - consents: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true, - 6: true, - 7: true, - 8: true, - 9: true, - 10: true - } - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(0); - }); - it('should send oi = 2 when vendor consent for invibes are false and vendor legitimate interest for invibes are true on tcf v2', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendor: {consents: {436: false}, legitimateInterests: {436: true}}, - purpose: { - consents: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true, - 6: true, - 7: true, - 8: true, - 9: true, - 10: true - } - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(2); - }); - it('should send oi = 0 when vendor consents and legitimate interests for invibes are false on tcf v2', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendor: {consents: {436: false}, legitimateInterests: {436: false}}, - purpose: { - consents: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true, - 6: true, - 7: true, - 8: true, - 9: true, - 10: true - } - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(0); - }); - it('should send oi = 0 when purpose consents is null', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendor: {consents: {436: false}}, - purpose: {} - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(0); - }); - - it('should send oi = 2 when purpose consents weren\'t approved on tcf v2', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendor: {consents: {436: true}}, - purpose: { - consents: { - 1: true, - 2: false, - 3: false, - 4: true, - 5: true, - 6: true, - 7: true, - 8: true, - 9: true, - 10: true - } - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(2); - }); - - it('should send oi = 2 when purpose consents are less then 10 on tcf v2', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendor: {consents: {436: true}}, - purpose: { - consents: { - 1: true, - 2: false, - 3: false, - 4: true, - 5: true - } - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(2); - }); - - it('should send oi = 4 when vendor consents are null on tcf v2', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendor: {consents: null}, - purpose: { - consents: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true, - 6: true, - 7: true, - 8: true, - 9: true, - 10: true - } - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(4); - }); - - it('should send oi = 4 when vendor consents for invibes is null on tcf v2', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendor: {consents: {436: null}}, - purpose: { - consents: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true, - 6: true, - 7: true, - 8: true, - 9: true, - 10: true - } - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(4); - }); - - it('should send oi = 4 when vendor consents for invibes is null on tcf v1', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendorConsents: {436: null}, - purposeConsents: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(4); - }); - - it('should send oi = 4 when vendor consents consents are null on tcf v1', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendorConsents: null, - purposeConsents: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(4); - }); - - it('should send oi = 2 when gdpr doesn\'t apply or has global consent', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: false, - hasGlobalConsent: true, - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(2); - }); - - it('should send oi = 2 when consent was approved on tcf v1', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendorConsents: {436: true}, - purposeConsents: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(2); - }); - - it('should send oi = 2 when purpose consents weren\'t approved on tcf v1', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendorConsents: {436: true}, - purposeConsents: { - 1: false, - 2: false, - 3: true, - 4: true, - 5: true - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(2); - }); - - it('should send oi = 2 when purpose consents are less then 5 on tcf v1', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendorConsents: {436: true}, - purposeConsents: { - 1: false, - 2: false, - 3: true - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(2); - }); - - it('should send oi = 0 when vendor consents for invibes are false on tcf v1', function () { - const bidderRequest = { - gdprConsent: { - vendorData: { - gdprApplies: true, - hasGlobalConsent: false, - vendorConsents: {436: false}, - purposeConsents: { - 1: true, - 2: true, - 3: true, - 4: true, - 5: true - } - } - }, - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.oi).to.equal(0); - }); - }); - - describe('interpretResponse', function () { - const response = { - Ads: [{ - BidPrice: 0.5, - VideoExposedId: 123 - }], - BidModel: { - BidVersion: 1, - PlacementId: '12345', - AuctionStartTime: Date.now(), - CreativeHtml: '' - } - }; - - const expectedResponse = [{ - requestId: bidRequests[0].bidId, - cpm: 0.5, - width: 400, - height: 300, - creativeId: 123, - currency: 'EUR', - netRevenue: true, - ttl: 300, - ad: ` - - - - - `, - meta: {} - }]; - - const multiResponse = { - MultipositionEnabled: true, - AdPlacements: [{ - Ads: [{ - BidPrice: 0.5, - VideoExposedId: 123 - }], - BidModel: { - BidVersion: 1, - PlacementId: '12345', - AuctionStartTime: Date.now(), - CreativeHtml: '' - } - }] - }; - - const invalidResponse = { - AdPlacements: [{ - Ads: [{ - BidPrice: 0.5, - VideoExposedId: 123 - }] - }] - }; - - const responseWithMeta = { - Ads: [{ - BidPrice: 0.5, - VideoExposedId: 123 - }], - BidModel: { - BidVersion: 1, - PlacementId: '12345', - AuctionStartTime: Date.now(), - CreativeHtml: '', - Meta: { - advertiserDomains: ['theadvertiser.com', 'theadvertiser_2.com'], - advertiserName: 'theadvertiser' - } - } - }; - - const responseWithAdUnit = { - Ads: [{ - BidPrice: 0.5, - VideoExposedId: 123 - }], - BidModel: { - BidVersion: 1, - PlacementId: '12345_test-div1', - AuctionStartTime: Date.now(), - CreativeHtml: '' - }, - UseAdUnitCode: true - }; - - var buildResponse = function(placementId, cid, blcids, creativeId, ShouldSetLId) { - if (ShouldSetLId) { - return { - MultipositionEnabled: true, - AdPlacements: [{ - Ads: [{ - BidPrice: 0.5, - VideoExposedId: creativeId, - Cid: cid, - Blcids: blcids - }], - BidModel: { - BidVersion: 1, - PlacementId: placementId, - AuctionStartTime: Date.now(), - CreativeHtml: '' - } - }], - ShouldSetLId: true, - LId: 'dvdjkams6nkq' - } - } - - return { - MultipositionEnabled: true, - AdPlacements: [{ - Ads: [{ - BidPrice: 0.5, - VideoExposedId: creativeId, - Cid: cid, - Blcids: blcids - }], - BidModel: { - BidVersion: 1, - PlacementId: placementId, - AuctionStartTime: Date.now(), - CreativeHtml: '' - } - }] - }; - }; - - context('when the response is not valid', function () { - it('handles response with no bids requested', function () { - const emptyResult = spec.interpretResponse({body: response}); - expect(emptyResult).to.be.empty; - }); - - it('handles empty response', function () { - const emptyResult = spec.interpretResponse(null, {bidRequests}); - expect(emptyResult).to.be.empty; - }); - - it('handles response with bidding is not configured', function () { - const emptyResult = spec.interpretResponse({body: {Ads: [{BidPrice: 1}]}}, {bidRequests}); - expect(emptyResult).to.be.empty; - }); - - it('handles response with no ads are received', function () { - const emptyResult = spec.interpretResponse({ - body: { - BidModel: {PlacementId: '12345'}, - AdReason: 'No ads' - } - }, {bidRequests}); - expect(emptyResult).to.be.empty; - }); - - it('handles response with no ads are received - no ad reason', function () { - const emptyResult = spec.interpretResponse({body: {BidModel: {PlacementId: '12345'}}}, {bidRequests}); - expect(emptyResult).to.be.empty; - }); - - it('handles response when no placement Id matches', function () { - const emptyResult = spec.interpretResponse({ - body: { - BidModel: {PlacementId: '123456'}, - Ads: [{BidPrice: 1}] - } - }, {bidRequests}); - expect(emptyResult).to.be.empty; - }); - - it('handles response when placement Id is not present', function () { - const emptyResult = spec.interpretResponse({BidModel: {}, Ads: [{BidPrice: 1}]}, {bidRequests}); - expect(emptyResult).to.be.empty; - }); - - it('handles response when bid model is missing', function () { - const emptyResult = spec.interpretResponse(invalidResponse); - expect(emptyResult).to.be.empty; - }); - }); - - context('when the multiresponse is valid', function () { - it('responds with a valid multiresponse bid', function () { - const result = spec.interpretResponse({body: multiResponse}, {bidRequests}); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - - it('responds with a valid singleresponse bid', function () { - const result = spec.interpretResponse({body: response}, {bidRequests}); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - - it('does not make multiple bids', function () { - const result = spec.interpretResponse({body: response}, {bidRequests}); - const secondResult = spec.interpretResponse({body: response}, {bidRequests}); - expect(secondResult).to.be.empty; - }); - - it('bids using the adUnitCode', function () { - const result = spec.interpretResponse({body: responseWithAdUnit}, {bidRequests}); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - }); - - context('when the response has meta', function () { - it('responds with a valid bid, with the meta info', function () { - const result = spec.interpretResponse({body: responseWithMeta}, {bidRequests}); - expect(result[0].meta.advertiserName).to.equal('theadvertiser'); - expect(result[0].meta.advertiserDomains).to.contain('theadvertiser.com'); - expect(result[0].meta.advertiserDomains).to.contain('theadvertiser_2.com'); - }); - }); - - context('AdWeb generates LIDs', function() { - it('works when no LID is not sent from AdWeb', function() { - var firstResponse = buildResponse('12345', 1, [], 123); - - var firstResult = spec.interpretResponse({body: firstResponse}, {bidRequests}); - expect(firstResult[0].creativeId).to.equal(123); - }); - - it('sets lid when AdWeb sends it', function() { - var firstResponse = buildResponse('12345', 1, [], 123, true); - - spec.interpretResponse({body: firstResponse}, {bidRequests}); - expect(global.document.cookie.indexOf('ivbsdid')).to.greaterThanOrEqual(0); - }); - }); - - context('in multiposition context, with conflicting ads', function() { - it('registers the second ad when no conflict', function() { - var firstResponse = buildResponse('12345', 1, [1], 123); - var secondResponse = buildResponse('abcde', 2, [2], 456); - - var firstResult = spec.interpretResponse({body: firstResponse}, {bidRequests}); - var secondResult = spec.interpretResponse({body: secondResponse}, {bidRequests}); - expect(secondResult[0].creativeId).to.equal(456); - }); - - it('registers the second ad when no conflict - empty arrays', function() { - var firstResponse = buildResponse('12345', 1, [], 123); - var secondResponse = buildResponse('abcde', 2, [], 456); - - var firstResult = spec.interpretResponse({body: firstResponse}, {bidRequests}); - var secondResult = spec.interpretResponse({body: secondResponse}, {bidRequests}); - expect(secondResult[0].creativeId).to.equal(456); - }); - - it('doesnt register the second ad when it is blacklisted by the first', function() { - var firstResponse = buildResponse('12345', 1, [2], 123); - var secondResponse = buildResponse('abcde', 2, [], 456); - - var firstResult = spec.interpretResponse({body: firstResponse}, {bidRequests}); - var secondResult = spec.interpretResponse({body: secondResponse}, {bidRequests}); - expect(secondResult).to.be.empty; - }); - - it('doesnt register the second ad when it is blacklisting the first', function() { - var firstResponse = buildResponse('12345', 1, [], 123); - var secondResponse = buildResponse('abcde', 2, [1], 456); - - var firstResult = spec.interpretResponse({body: firstResponse}, {bidRequests}); - var secondResult = spec.interpretResponse({body: secondResponse}, {bidRequests}); - expect(secondResult).to.be.empty; - }); - - it('doesnt register the second ad when it has same ids as the first', function() { - var firstResponse = buildResponse('12345', 1, [1], 123); - var secondResponse = buildResponse('abcde', 1, [1], 456); - - var firstResult = spec.interpretResponse({body: firstResponse}, {bidRequests}); - var secondResult = spec.interpretResponse({body: secondResponse}, {bidRequests}); - expect(secondResult).to.be.empty; - }); - }); - }); - - describe('getUserSyncs', function () { - it('returns undefined if disableUserSyncs not passed as bid request param ', function () { - spec.buildRequests(bidRequestsWithUserId, bidderRequestWithPageInfo); - const response = spec.getUserSyncs({iframeEnabled: true}); - expect(response).to.equal(undefined); - }); - - it('returns an iframe if enabled', function () { - spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - - const response = spec.getUserSyncs({iframeEnabled: true}); - expect(response.type).to.equal('iframe'); - expect(response.url).to.include(SYNC_ENDPOINT); - }); - - it('returns an iframe with params if enabled', function () { - top.window.invibes.optIn = 1; - spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - - const response = spec.getUserSyncs({iframeEnabled: true}); - expect(response.type).to.equal('iframe'); - expect(response.url).to.include(SYNC_ENDPOINT); - expect(response.url).to.include('optIn'); - }); - - it('returns an iframe with params including if enabled', function () { - top.window.invibes.optIn = 1; - spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - - global.document.cookie = 'ivbsdid={"id":"dvdjkams6nkq","cr":' + Date.now() + ',"hc":0}'; - SetBidderAccess(); - - const response = spec.getUserSyncs({iframeEnabled: true}); - expect(response.type).to.equal('iframe'); - expect(response.url).to.include(SYNC_ENDPOINT); - expect(response.url).to.include('optIn'); - expect(response.url).to.include('ivbsdid'); - }); - - it('returns an iframe with params including if enabled read from LocalStorage', function () { - spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - top.window.invibes.optIn = 1; - - localStorage.ivbsdid = 'dvdjkams6nkq'; - SetBidderAccess(); - - const response = spec.getUserSyncs({iframeEnabled: true}); - expect(response.type).to.equal('iframe'); - expect(response.url).to.include(SYNC_ENDPOINT); - expect(response.url).to.include('optIn'); - expect(response.url).to.include('ivbsdid'); - }); - - it('returns undefined if iframe not enabled ', function () { - spec.buildRequests(bidRequests, bidderRequestWithPageInfo); - - const response = spec.getUserSyncs({iframeEnabled: false}); - expect(response).to.equal(undefined); - }); - - it('uses uspConsent when no gdprConsent', function () { - const bidderRequest = { - uspConsent: '1YNY', - refererInfo: { - page: 'https://randomWeb.com?someFakePara=fakeValue&secondParam=secondValue' - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(top.window.invibes.optIn).to.equal(2); - expect(top.window.invibes.GdprModuleInstalled).to.be.false; - expect(top.window.invibes.UspModuleInstalled).to.be.true; - var index; - for (index = 0; index < top.window.invibes.purposes.length; ++index) { - expect(top.window.invibes.purposes[index]).to.be.true; - } - for (index = 0; index < top.window.invibes.legitimateInterests.length; ++index) { - expect(top.window.invibes.legitimateInterests[index]).to.be.true; - } - expect(request.data.tc).to.not.exist; - expect(request.data.uspc).to.equal(bidderRequest.uspConsent); - }); - }); -}); diff --git a/test/spec/modules/invisiblyAnalyticsAdapter_spec.js b/test/spec/modules/invisiblyAnalyticsAdapter_spec.js deleted file mode 100644 index 71182d146..000000000 --- a/test/spec/modules/invisiblyAnalyticsAdapter_spec.js +++ /dev/null @@ -1,574 +0,0 @@ -import invisiblyAdapter from 'modules/invisiblyAnalyticsAdapter.js'; -import { expect } from 'chai'; -import {expectEvents} from '../../helpers/analytics.js'; -import {server} from '../../mocks/xhr.js'; -import { EVENTS, STATUS } from 'src/constants.js'; -const events = require('src/events'); - -describe('Invisibly Analytics Adapter test suite', function () { - let xhr; - let requests = []; - const BID1 = { - width: 980, - height: 240, - cpm: 1.1, - timeToRespond: 200, - bidId: '2ecff0db240757', - requestId: '2ecff0db240757', - adId: '2ecff0db240757', - auctionId: '25c6d7f5-699a-4bfc-87c9-996f915341fa', - adUnitCode: '/19968336/header-bid-tag-0', - adserverTargeting: { - hb_bidder: 'testBidder', - hb_adid: '2ecff0db240757', - hb_pb: 1.2, - hb_size: '640x480', - hb_source: 'client', - }, - getStatusCode() { - return STATUS.GOOD; - }, - }; - - const BID2 = Object.assign({}, BID1, { - width: 300, - height: 250, - cpm: 2.2, - timeToRespond: 300, - bidId: '3ecff0db240757', - requestId: '3ecff0db240757', - adId: '3ecff0db240757', - }); - - const BID3 = { - bidId: '4ecff0db240757', - requestId: '4ecff0db240757', - adId: '4ecff0db240757', - auctionId: '25c6d7f5-699a-4bfc-87c9-996f915341fa', - adUnitCode: '/19968336/header-bid-tag1', - adserverTargeting: { - hb_bidder: 'testBidder', - hb_adid: '3bd4ebb1c900e2', - hb_pb: '1.500', - hb_size: '728x90', - hb_source: 'server', - }, - getStatusCode() { - return STATUS.GOOD; - }, - }; - - const MOCK = { - config: { - provider: 'invisiblyAnalytics', - options: { - bundleId: '', - account: 'invisibly', - }, - }, - AUCTION_INIT: { - auctionId: '25c6d7f5-699a-4bfc-87c9-996f915341fa', - }, - BID_REQUESTED: { - bidder: 'mockBidder', - auctionId: '25c6d7f5-699a-4bfc-87c9-996f915341fa', - bidderRequestId: '1be65d7958826a', - bids: [ - { - bidder: 'mockBidder', - adUnitCode: 'panorama_d_1', - bidId: '2ecff0db240757', - }, - { - bidder: 'mockBidder', - adUnitCode: 'box_d_1', - bidId: '3ecff0db240757', - }, - { - bidder: 'mockBidder', - adUnitCode: 'box_d_2', - bidId: '4ecff0db240757', - }, - ], - start: 1519149562216, - }, - BID_RESPONSE: [BID1, BID2], - AUCTION_END: { - auctionId: 'test_timeout_auction_id', - timestamp: 1234567890, - timeout: 3000, - auctionEnd: 1234567990, - }, - BID_WON: { - bidderCode: 'appnexus', - width: 300, - height: 250, - adId: '1ebb82ec35375e', - mediaType: 'banner', - cpm: 0.5, - requestId: '1582271863760569973', - creative_id: '96846035', - creativeId: '96846035', - ttl: 60, - currency: 'USD', - netRevenue: true, - auctionId: '9c7b70b9-b6ab-4439-9e71-b7b382797c18', - responseTimestamp: 1537521629657, - requestTimestamp: 1537521629331, - bidder: 'appnexus', - adUnitCode: 'div-gpt-ad-1460505748561-0', - timeToRespond: 326, - size: '300x250', - status: 'rendered', - eventType: 'bidWon', - ad: 'some ad', - adUrl: 'ad url', - }, - BIDDER_DONE: { - bidderCode: 'mockBidder', - bids: [BID1, BID2, BID3], - }, - BID_TIMEOUT: [ - { - bidId: '2ecff0db240757', - auctionId: '25c6d7f5-699a-4bfc-87c9-996f915341fa', - }, - ], - BID_ADJUSTMENT: { - ad: 'html', - adId: '298bf14ecbafb', - cpm: 1.01, - creativeId: '2249:92806132', - currency: 'USD', - height: 250, - mediaType: 'banner', - requestId: '298bf14ecbafb', - size: '300x250', - source: 'client', - status: 'rendered', - statusMessage: 'Bid available', - timeToRespond: 421, - ttl: 300, - width: 300, - }, - NO_BID: { - testKey: false, - }, - SET_TARGETING: { - [BID1.adUnitCode]: BID1.adserverTargeting, - [BID3.adUnitCode]: BID3.adserverTargeting, - }, - REQUEST_BIDS: { - call: 'request', - }, - ADD_AD_UNITS: { call: 'addAdUnits' }, - AD_RENDER_FAILED: { call: 'adRenderFailed' }, - INVALID_EVENT: { - mockKey: 'this event should not emit', - }, - }; - - describe('Invisibly Analytic tests specs', function () { - beforeEach(function () { - requests = server.requests; - sinon.stub(events, 'getEvents').returns([]); - sinon.spy(invisiblyAdapter, 'track'); - }); - - afterEach(function () { - invisiblyAdapter.disableAnalytics(); - events.getEvents.restore(); - invisiblyAdapter.track.restore(); - }); - - describe('Send all events as & when they are captured', function () { - beforeEach(function () { - invisiblyAdapter.weightedFilter.filter = true; - }); - // specs to test invisibly account input to enableAnaylitcs - describe('monitor enableAnalytics method', function () { - it('should catch all events triggered with invisibly account config', function () { - invisiblyAdapter.enableAnalytics({ - provider: 'invisiblyAnalytics', - options: { - account: 'invisibly', - }, - }); - - expectEvents().to.beTrackedBy(invisiblyAdapter.track); - }); - - it('should not catch events triggered without invisibly account config', function () { - invisiblyAdapter.enableAnalytics({ - provider: 'invisiblyAnalytics', - options: {}, - }); - - events.emit(EVENTS.AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(EVENTS.AUCTION_END, MOCK.AUCTION_END); - events.emit(EVENTS.BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(EVENTS.BID_RESPONSE, MOCK.BID_RESPONSE); - events.emit(EVENTS.BID_WON, MOCK.BID_WON); - invisiblyAdapter.flush(); - sinon.assert.callCount(invisiblyAdapter.track, 0); - }); - // spec to test custom api endpoint - it('support custom endpoint', function () { - const custom_url = 'custom url'; - invisiblyAdapter.enableAnalytics({ - provider: 'invisiblyAnalytics', - options: { - url: custom_url, - bundleId: 'xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx', - account: 'invisibly', - }, - }); - expect(invisiblyAdapter.getOptions().url).to.equal(custom_url); - }); - }); - - // spec for auction init event - it('auction init event', function () { - invisiblyAdapter.enableAnalytics(MOCK.config); - events.emit(EVENTS.AUCTION_INIT, MOCK.AUCTION_INIT); - invisiblyAdapter.flush(); - - const invisiblyEvents = JSON.parse( - requests[1].requestBody.substring(0) - ); - // pageView is default event initially hence expecting 2 requests - expect(requests.length).to.equal(2); - expect(requests[1].url).to.equal( - 'https://api.pymx5.com/v1/sites/events' - ); - expect(invisiblyEvents.event_data.auctionId).to.equal( - MOCK.AUCTION_INIT.auctionId - ); - expect(invisiblyEvents.event_data.pageViewId).to.exist; - expect(invisiblyEvents.event_type).to.equal('PREBID_auctionInit'); - expect(invisiblyEvents.event_data.ver).to.equal(1); - }); - - // spec for bid adjustment event - it('bid adjustment event', function () { - invisiblyAdapter.enableAnalytics(MOCK.config); - events.emit(EVENTS.BID_ADJUSTMENT, MOCK.BID_ADJUSTMENT); - invisiblyAdapter.flush(); - - const invisiblyEvents = JSON.parse( - requests[0].requestBody.substring(0) - ); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal( - 'https://api.pymx5.com/v1/sites/events' - ); - expect(invisiblyEvents.event_data.pageViewId).to.exist; - expect(invisiblyEvents.event_data.ver).to.equal(1); - expect(invisiblyEvents.event_type).to.equal('PREBID_bidAdjustment'); - expect(invisiblyEvents.event_data.bidders.cpm).to.equal( - MOCK.BID_ADJUSTMENT.cpm - ); - sinon.assert.callCount(invisiblyAdapter.track, 1); - }); - - // spec for bid timeout event - it('bid timeout event', function () { - invisiblyAdapter.enableAnalytics(MOCK.config); - events.emit(EVENTS.BID_TIMEOUT, MOCK.BID_TIMEOUT); - invisiblyAdapter.flush(); - - const invisiblyEvents = JSON.parse( - requests[0].requestBody.substring(0) - ); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal( - 'https://api.pymx5.com/v1/sites/events' - ); - expect(invisiblyEvents.event_data.pageViewId).to.exist; - expect(invisiblyEvents.event_data.ver).to.equal(1); - expect(invisiblyEvents.event_type).to.equal('PREBID_bidTimeout'); - expect(invisiblyEvents.event_data.bidders.bidId).to.equal( - MOCK.BID_TIMEOUT.bidId - ); - sinon.assert.callCount(invisiblyAdapter.track, 1); - }); - - // spec for bid requested event - it('bid requested event', function () { - invisiblyAdapter.enableAnalytics(MOCK.config); - events.emit(EVENTS.BID_REQUESTED, MOCK.BID_REQUESTED); - invisiblyAdapter.flush(); - - const invisiblyEvents = JSON.parse( - requests[0].requestBody.substring(0) - ); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal( - 'https://api.pymx5.com/v1/sites/events' - ); - expect(invisiblyEvents.event_data.pageViewId).to.exist; - expect(invisiblyEvents.event_data.ver).to.equal(1); - expect(invisiblyEvents.event_type).to.equal('PREBID_bidRequested'); - expect(invisiblyEvents.event_data.auctionId).to.equal( - MOCK.BID_REQUESTED.auctionId - ); - sinon.assert.callCount(invisiblyAdapter.track, 1); - }); - - // spec for bid response event - it('bid response event', function () { - invisiblyAdapter.enableAnalytics(MOCK.config); - events.emit(EVENTS.BID_RESPONSE, MOCK.BID_RESPONSE); - invisiblyAdapter.flush(); - - const invisiblyEvents = JSON.parse( - requests[0].requestBody.substring(0) - ); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal( - 'https://api.pymx5.com/v1/sites/events' - ); - expect(invisiblyEvents.event_data.pageViewId).to.exist; - expect(invisiblyEvents.event_data.ver).to.equal(1); - expect(invisiblyEvents.event_type).to.equal('PREBID_bidResponse'); - expect(invisiblyEvents.event_data.cpm).to.equal(MOCK.BID_REQUESTED.cpm); - sinon.assert.callCount(invisiblyAdapter.track, 1); - }); - - // spec for no bid event - it('no bid event', function () { - invisiblyAdapter.enableAnalytics(MOCK.config); - events.emit(EVENTS.NO_BID, MOCK.NO_BID); - invisiblyAdapter.flush(); - - const invisiblyEvents = JSON.parse( - requests[0].requestBody.substring(0) - ); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal( - 'https://api.pymx5.com/v1/sites/events' - ); - expect(invisiblyEvents.event_data.pageViewId).to.exist; - expect(invisiblyEvents.event_data.ver).to.equal(1); - expect(invisiblyEvents.event_type).to.equal('PREBID_noBid'); - expect(invisiblyEvents.event_data.noBid.testKey).to.equal( - MOCK.NO_BID.testKey - ); - sinon.assert.callCount(invisiblyAdapter.track, 1); - }); - - // spec for bid won event - it('bid won event', function () { - invisiblyAdapter.enableAnalytics(MOCK.config); - events.emit(EVENTS.BID_WON, MOCK.BID_WON); - invisiblyAdapter.flush(); - - const invisiblyEvents = JSON.parse( - requests[0].requestBody.substring(0) - ); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal( - 'https://api.pymx5.com/v1/sites/events' - ); - expect(invisiblyEvents.event_data.pageViewId).to.exist; - expect(invisiblyEvents.event_data.ver).to.equal(1); - expect(invisiblyEvents.event_type).to.equal('PREBID_bidWon'); - }); - - // spec for bidder done event - it('bidder done event', function () { - invisiblyAdapter.enableAnalytics(MOCK.config); - events.emit(EVENTS.BIDDER_DONE, MOCK.BIDDER_DONE); - invisiblyAdapter.flush(); - - const invisiblyEvents = JSON.parse( - requests[0].requestBody.substring(0) - ); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal( - 'https://api.pymx5.com/v1/sites/events' - ); - expect(invisiblyEvents.event_data.pageViewId).to.exist; - expect(invisiblyEvents.event_data.ver).to.equal(1); - expect(invisiblyEvents.event_type).to.equal('PREBID_bidderDone'); - expect(invisiblyEvents.event_data.bidderCode).to.equal( - MOCK.BIDDER_DONE.bidderCode - ); - expect(invisiblyEvents.event_data.bids.length).to.equal( - MOCK.BIDDER_DONE.bids.length - ); - sinon.assert.callCount(invisiblyAdapter.track, 1); - }); - - // spec for set targeting event - it('set targeting event', function () { - invisiblyAdapter.enableAnalytics(MOCK.config); - events.emit(EVENTS.SET_TARGETING, MOCK.SET_TARGETING); - invisiblyAdapter.flush(); - - const invisiblyEvents = JSON.parse( - requests[0].requestBody.substring(0) - ); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal( - 'https://api.pymx5.com/v1/sites/events' - ); - expect(invisiblyEvents.event_data.pageViewId).to.exist; - expect(invisiblyEvents.event_data.ver).to.equal(1); - expect(invisiblyEvents.event_type).to.equal('PREBID_setTargeting'); - expect( - invisiblyEvents.event_data.targetings[BID1.adUnitCode] - ).to.deep.equal(BID1.adserverTargeting); - expect( - invisiblyEvents.event_data.targetings[BID3.adUnitCode] - ).to.deep.equal(BID3.adserverTargeting); - sinon.assert.callCount(invisiblyAdapter.track, 1); - }); - - // spec for request bids event - it('request bids event', function () { - invisiblyAdapter.enableAnalytics(MOCK.config); - events.emit(EVENTS.REQUEST_BIDS, MOCK.REQUEST_BIDS); - invisiblyAdapter.flush(); - - const invisiblyEvents = JSON.parse( - requests[0].requestBody.substring(0) - ); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal( - 'https://api.pymx5.com/v1/sites/events' - ); - expect(invisiblyEvents.event_data.pageViewId).to.exist; - expect(invisiblyEvents.event_data.ver).to.equal(1); - expect(invisiblyEvents.event_type).to.equal('PREBID_requestBids'); - expect(invisiblyEvents.event_data.call).to.equal( - MOCK.REQUEST_BIDS.call - ); - sinon.assert.callCount(invisiblyAdapter.track, 1); - }); - - // spec for add ad units event - it('add ad units event', function () { - invisiblyAdapter.enableAnalytics(MOCK.config); - events.emit(EVENTS.ADD_AD_UNITS, MOCK.ADD_AD_UNITS); - invisiblyAdapter.flush(); - - const invisiblyEvents = JSON.parse( - requests[0].requestBody.substring(0) - ); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal( - 'https://api.pymx5.com/v1/sites/events' - ); - expect(invisiblyEvents.event_data.pageViewId).to.exist; - expect(invisiblyEvents.event_data.ver).to.equal(1); - expect(invisiblyEvents.event_type).to.equal('PREBID_addAdUnits'); - expect(invisiblyEvents.event_data.call).to.equal( - MOCK.ADD_AD_UNITS.call - ); - sinon.assert.callCount(invisiblyAdapter.track, 1); - }); - - // spec for ad render failed event - it('ad render failed event', function () { - invisiblyAdapter.enableAnalytics(MOCK.config); - events.emit(EVENTS.AD_RENDER_FAILED, MOCK.AD_RENDER_FAILED); - invisiblyAdapter.flush(); - - const invisiblyEvents = JSON.parse( - requests[0].requestBody.substring(0) - ); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal( - 'https://api.pymx5.com/v1/sites/events' - ); - expect(invisiblyEvents.event_data.pageViewId).to.exist; - expect(invisiblyEvents.event_data.ver).to.equal(1); - expect(invisiblyEvents.event_type).to.equal('PREBID_adRenderFailed'); - expect(invisiblyEvents.event_data.call).to.equal( - MOCK.AD_RENDER_FAILED.call - ); - sinon.assert.callCount(invisiblyAdapter.track, 1); - }); - - // spec for auction end event - it('auction end event', function () { - invisiblyAdapter.enableAnalytics(MOCK.config); - events.emit(EVENTS.AUCTION_END, MOCK.AUCTION_END); - invisiblyAdapter.flush(); - - const invisiblyEvents = JSON.parse( - requests[0].requestBody.substring(0) - ); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal( - 'https://api.pymx5.com/v1/sites/events' - ); - expect(invisiblyEvents.event_data.pageViewId).to.exist; - expect(invisiblyEvents.event_data.ver).to.equal(1); - expect(invisiblyEvents.event_type).to.equal('PREBID_auctionEnd'); - expect(invisiblyEvents.event_data.auctionId).to.equal( - MOCK.AUCTION_END.auctionId - ); - }); - - // should not call sendEvent for events not supported by the adapter - it('it should not call sendEvent for this event emit', function () { - sinon.spy(invisiblyAdapter, 'sendEvent'); - invisiblyAdapter.enableAnalytics(MOCK.config); - events.emit(EVENTS.INVALID_EVENT, MOCK.INVALID_EVENT); - invisiblyAdapter.flush(); - - expect(requests.length).to.equal(0); - sinon.assert.callCount(invisiblyAdapter.track, 0); - sinon.assert.callCount(invisiblyAdapter.sendEvent, 0); - }); - - // spec to emit all events - it('track all event without errors', function () { - invisiblyAdapter.enableAnalytics(MOCK.config); - - expectEvents([ - EVENTS.AUCTION_INIT, - EVENTS.AUCTION_END, - EVENTS.BID_ADJUSTMENT, - EVENTS.BID_TIMEOUT, - EVENTS.BID_REQUESTED, - EVENTS.BID_RESPONSE, - EVENTS.NO_BID, - EVENTS.BID_WON, - EVENTS.BIDDER_DONE, - EVENTS.SET_TARGETING, - EVENTS.REQUEST_BIDS, - EVENTS.ADD_AD_UNITS, - EVENTS.AD_RENDER_FAILED - ]).to.beTrackedBy(invisiblyAdapter.track); - }); - }); - - describe('Should not send any event even if they are caputured', function () { - beforeEach(function () { - invisiblyAdapter.weightedFilter.filter = false; - }); - it('it should not send any event', function () { - invisiblyAdapter.enableAnalytics({ - provider: 'invisiblyAnalytics', - options: { - account: 'invisibly', - }, - }); - - events.emit(EVENTS.AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(EVENTS.AUCTION_END, MOCK.AUCTION_END); - events.emit(EVENTS.BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(EVENTS.BID_RESPONSE, MOCK.BID_RESPONSE); - events.emit(EVENTS.BID_WON, MOCK.BID_WON); - invisiblyAdapter.flush(); - - sinon.assert.callCount(invisiblyAdapter.sendEvent, 0); - sinon.assert.callCount(invisiblyAdapter.track, 0); - expect(requests.length).to.equal(0); - }); - }); - }); -}); diff --git a/test/spec/modules/ipromBidAdapter_spec.js b/test/spec/modules/ipromBidAdapter_spec.js deleted file mode 100644 index 3a1a6c972..000000000 --- a/test/spec/modules/ipromBidAdapter_spec.js +++ /dev/null @@ -1,197 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/ipromBidAdapter.js'; - -describe('iPROM Adapter', function () { - let bidRequests; - let bidderRequest; - - beforeEach(function () { - bidRequests = [ - { - bidder: 'iprom', - params: { - id: '1234', - dimension: '300x250', - }, - adUnitCode: '/19966331/header-bid-tag-1', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - } - }, - bidId: '29a72b151f7bd3', - auctionId: 'e36abb27-g3b1-1ad6-8a4c-701c8919d3hh', - bidderRequestId: '2z76da40m1b3cb8', - transactionId: 'j51lhf58-1ad6-g3b1-3j6s-912c9493g0gu' - } - ]; - - bidderRequest = { - timeout: 3000, - refererInfo: { - legacy: { - referer: 'https://adserver.si/index.html', - reachedTop: true, - numIframes: 1, - stack: [ - 'https://adserver.si/index.html', - 'https://adserver.si/iframe1.html', - ] - } - } - } - }); - - describe('validating bids', function () { - it('should accept valid bid', function () { - const validBid = { - bidder: 'iprom', - params: { - id: '1234', - dimension: '300x250', - }, - }; - - const isValid = spec.isBidRequestValid(validBid); - - expect(isValid).to.equal(true); - }); - - it('should reject bid if missing dimension and id', function () { - const invalidBid = { - bidder: 'iprom', - params: {} - }; - - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.equal(false); - }); - - it('should reject bid if missing dimension', function () { - const invalidBid = { - bidder: 'iprom', - params: { - id: '1234', - } - }; - - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.equal(false); - }); - - it('should reject bid if dimension is not a string', function () { - const invalidBid = { - bidder: 'iprom', - params: { - id: '1234', - dimension: 404, - } - }; - - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.equal(false); - }); - - it('should reject bid if missing id', function () { - const invalidBid = { - bidder: 'iprom', - params: { - dimension: '300x250', - } - }; - - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.equal(false); - }); - - it('should reject bid if id is not a string', function () { - const invalidBid = { - bidder: 'iprom', - params: { - id: 1234, - dimension: '300x250', - } - }; - - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.equal(false); - }); - }); - - describe('building requests', function () { - it('should go to correct endpoint', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.method).to.exist; - expect(request.method).to.equal('POST'); - expect(request.url).to.exist; - expect(request.url).to.equal('https://core.iprom.net/programmatic'); - }); - - it('should add referer info', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - - expect(requestparse.referer).to.exist; - expect(requestparse.referer.referer).to.equal('https://adserver.si/index.html'); - }); - - it('should add adapter version', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - - expect(requestparse.version).to.exist; - }); - - it('should contain id and dimension', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - const requestparse = JSON.parse(request.data); - - expect(requestparse.bids[0].params.id).to.equal('1234'); - expect(requestparse.bids[0].params.dimension).to.equal('300x250'); - }); - }); - - describe('handling responses', function () { - it('should return complete bid response', function () { - const serverResponse = { - body: [{ - requestId: '29a72b151f7bd3', - cpm: 0.5, - width: '300', - height: '250', - creativeId: 1234, - ad: 'Iprom Header bidding example', - aDomains: ['https://example.com'], - } - ]}; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - - expect(bids).to.be.lengthOf(1); - expect(bids[0].requestId).to.equal('29a72b151f7bd3'); - expect(bids[0].cpm).to.equal(0.5); - expect(bids[0].width).to.equal('300'); - expect(bids[0].height).to.equal('250'); - expect(bids[0].ad).to.have.length.above(1); - expect(bids[0].meta.advertiserDomains).to.deep.equal(['https://example.com']); - }); - - it('should return empty bid response', function () { - const emptyServerResponse = { - body: [] - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(emptyServerResponse, request); - - expect(bids).to.be.lengthOf(0); - }); - }); -}); diff --git a/test/spec/modules/iqxBidAdapter_spec.js b/test/spec/modules/iqxBidAdapter_spec.js deleted file mode 100644 index 8ca6fce84..000000000 --- a/test/spec/modules/iqxBidAdapter_spec.js +++ /dev/null @@ -1,438 +0,0 @@ -import {expect} from 'chai'; -import {config} from 'src/config.js'; -import {spec} from 'modules/iqxBidAdapter.js'; -import {deepClone} from 'src/utils'; -import {getBidFloor} from '../../../libraries/xeUtils/bidderUtils.js'; - -const ENDPOINT = 'https://pbjs.iqzonertb.live'; - -const defaultRequest = { - tmax: 0, - adUnitCode: 'test', - bidId: '1', - requestId: 'qwerty', - ortb2: { - source: { - tid: 'auctionId' - } - }, - ortb2Imp: { - ext: { - tid: 'tr1', - } - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 200] - ] - } - }, - bidder: 'iqx', - params: { - env: 'iqx', - pid: '40', - ext: {} - }, - bidRequestsCount: 1 -}; - -const defaultRequestVideo = deepClone(defaultRequest); -defaultRequestVideo.mediaTypes = { - video: { - playerSize: [640, 480], - context: 'instream', - skipppable: true - } -}; -describe('iqxBidAdapter', () => { - describe('isBidRequestValid', function () { - it('should return false when request params is missing', function () { - const invalidRequest = deepClone(defaultRequest); - delete invalidRequest.params; - expect(spec.isBidRequestValid(invalidRequest)).to.equal(false); - }); - - it('should return false when required env param is missing', function () { - const invalidRequest = deepClone(defaultRequest); - delete invalidRequest.params.env; - expect(spec.isBidRequestValid(invalidRequest)).to.equal(false); - }); - - it('should return false when required pid param is missing', function () { - const invalidRequest = deepClone(defaultRequest); - delete invalidRequest.params.pid; - expect(spec.isBidRequestValid(invalidRequest)).to.equal(false); - }); - - it('should return false when video.playerSize is missing', function () { - const invalidRequest = deepClone(defaultRequestVideo); - delete invalidRequest.mediaTypes.video.playerSize; - expect(spec.isBidRequestValid(invalidRequest)).to.equal(false); - }); - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(defaultRequest)).to.equal(true); - }); - }); - - describe('buildRequests', function () { - beforeEach(function () { - config.resetConfig(); - }); - - it('should send request with correct structure', function () { - const request = spec.buildRequests([defaultRequest], {}); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal(ENDPOINT + '/bid'); - expect(request.options).to.have.property('contentType').and.to.equal('application/json'); - expect(request).to.have.property('data'); - }); - - it('should build basic request structure', function () { - const request = JSON.parse(spec.buildRequests([defaultRequest], {}).data)[0]; - expect(request).to.have.property('tmax').and.to.equal(defaultRequest.tmax); - expect(request).to.have.property('bidId').and.to.equal(defaultRequest.bidId); - expect(request).to.have.property('auctionId').and.to.equal(defaultRequest.ortb2.source.tid); - expect(request).to.have.property('transactionId').and.to.equal(defaultRequest.ortb2Imp.ext.tid); - expect(request).to.have.property('tz').and.to.equal(new Date().getTimezoneOffset()); - expect(request).to.have.property('bc').and.to.equal(1); - expect(request).to.have.property('floor').and.to.equal(null); - expect(request).to.have.property('banner').and.to.deep.equal({sizes: [[300, 250], [300, 200]]}); - expect(request).to.have.property('gdprConsent').and.to.deep.equal({}); - expect(request).to.have.property('userEids').and.to.deep.equal([]); - expect(request).to.have.property('usPrivacy').and.to.equal(''); - expect(request).to.have.property('sizes').and.to.deep.equal(['300x250', '300x200']); - expect(request).to.have.property('ext').and.to.deep.equal({}); - expect(request).to.have.property('env').and.to.deep.equal({ - env: 'iqx', - pid: '40' - }); - expect(request).to.have.property('device').and.to.deep.equal({ - ua: navigator.userAgent, - lang: navigator.language - }); - }); - - it('should build request with schain', function () { - const schainRequest = deepClone(defaultRequest); - const bidderRequest = { - ortb2: { - source: { - ext: { - schain: { - ver: '1.0' - } - } - } - } - }; - const request = JSON.parse(spec.buildRequests([schainRequest], bidderRequest).data)[0]; - expect(request).to.have.property('schain').and.to.deep.equal({ - ver: '1.0' - }); - }); - - it('should build request with location', function () { - const bidderRequest = { - refererInfo: { - page: 'page', - location: 'location', - domain: 'domain', - ref: 'ref', - isAmp: false - } - }; - const request = JSON.parse(spec.buildRequests([defaultRequest], bidderRequest).data)[0]; - expect(request).to.have.property('location'); - const location = request.location; - expect(location).to.have.property('page').and.to.equal('page'); - expect(location).to.have.property('location').and.to.equal('location'); - expect(location).to.have.property('domain').and.to.equal('domain'); - expect(location).to.have.property('ref').and.to.equal('ref'); - expect(location).to.have.property('isAmp').and.to.equal(false); - }); - - it('should build request with ortb2 info', function () { - const ortb2Request = deepClone(defaultRequest); - ortb2Request.ortb2 = { - site: { - name: 'name' - } - }; - const request = JSON.parse(spec.buildRequests([ortb2Request], {}).data)[0]; - expect(request).to.have.property('ortb2').and.to.deep.equal({ - site: { - name: 'name' - } - }); - }); - - it('should build request with ortb2Imp info', function () { - const ortb2ImpRequest = deepClone(defaultRequest); - ortb2ImpRequest.ortb2Imp = { - ext: { - data: { - pbadslot: 'home1', - adUnitSpecificAttribute: '1' - } - } - }; - const request = JSON.parse(spec.buildRequests([ortb2ImpRequest], {}).data)[0]; - expect(request).to.have.property('ortb2Imp').and.to.deep.equal({ - ext: { - data: { - pbadslot: 'home1', - adUnitSpecificAttribute: '1' - } - } - }); - }); - - it('should build request with valid bidfloor', function () { - const bfRequest = deepClone(defaultRequest); - bfRequest.getFloor = () => ({floor: 5, currency: 'USD'}); - const request = JSON.parse(spec.buildRequests([bfRequest], {}).data)[0]; - expect(request).to.have.property('floor').and.to.equal(5); - }); - - it('should build request with usp consent data if applies', function () { - const bidderRequest = { - uspConsent: '1YA-' - }; - const request = JSON.parse(spec.buildRequests([defaultRequest], bidderRequest).data)[0]; - expect(request).to.have.property('usPrivacy').and.equals('1YA-'); - }); - - it('should build request with extended ids', function () { - const idRequest = deepClone(defaultRequest); - idRequest.userIdAsEids = [ - {source: 'adserver.org', uids: [{id: 'TTD_ID_FROM_USER_ID_MODULE', atype: 1, ext: {rtiPartner: 'TDID'}}]}, - {source: 'pubcid.org', uids: [{id: 'pubCommonId_FROM_USER_ID_MODULE', atype: 1}]} - ]; - const request = JSON.parse(spec.buildRequests([idRequest], {}).data)[0]; - expect(request).to.have.property('userEids').and.deep.equal(idRequest.userIdAsEids); - }); - - it('should build request with video', function () { - const request = JSON.parse(spec.buildRequests([defaultRequestVideo], {}).data)[0]; - expect(request).to.have.property('video').and.to.deep.equal({ - playerSize: [640, 480], - context: 'instream', - skipppable: true - }); - expect(request).to.have.property('sizes').and.to.deep.equal(['640x480']); - }); - }); - - describe('interpretResponse', function () { - it('should return empty bids', function () { - const serverResponse = { - body: { - data: null - } - }; - - const invalidResponse = spec.interpretResponse(serverResponse, {}); - expect(invalidResponse).to.be.an('array').that.is.empty; - }); - - it('should interpret valid response', function () { - const serverResponse = { - body: { - data: [{ - requestId: 'qwerty', - cpm: 1, - currency: 'USD', - width: 300, - height: 250, - ttl: 600, - meta: { - advertiserDomains: ['iqx'] - }, - ext: { - pixels: [ - ['iframe', 'surl1'], - ['image', 'surl2'], - ] - } - }] - } - }; - - const validResponse = spec.interpretResponse(serverResponse, {bidderRequest: defaultRequest}); - const bid = validResponse[0]; - expect(validResponse).to.be.an('array').that.is.not.empty; - expect(bid.requestId).to.equal('qwerty'); - expect(bid.cpm).to.equal(1); - expect(bid.currency).to.equal('USD'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.ttl).to.equal(600); - expect(bid.meta).to.deep.equal({advertiserDomains: ['iqx']}); - }); - - it('should interpret valid banner response', function () { - const serverResponse = { - body: { - data: [{ - requestId: 'qwerty', - cpm: 1, - currency: 'USD', - width: 300, - height: 250, - ttl: 600, - mediaType: 'banner', - creativeId: 'xe-demo-banner', - ad: 'ad', - meta: {} - }] - } - }; - - const validResponseBanner = spec.interpretResponse(serverResponse, {bidderRequest: defaultRequest}); - const bid = validResponseBanner[0]; - expect(validResponseBanner).to.be.an('array').that.is.not.empty; - expect(bid.mediaType).to.equal('banner'); - expect(bid.creativeId).to.equal('xe-demo-banner'); - expect(bid.ad).to.equal('ad'); - }); - - it('should interpret valid video response', function () { - const serverResponse = { - body: { - data: [{ - requestId: 'qwerty', - cpm: 1, - currency: 'USD', - width: 600, - height: 480, - ttl: 600, - mediaType: 'video', - creativeId: 'xe-demo-video', - ad: 'vast-xml', - meta: {} - }] - } - }; - - const validResponseBanner = spec.interpretResponse(serverResponse, {bidderRequest: defaultRequestVideo}); - const bid = validResponseBanner[0]; - expect(validResponseBanner).to.be.an('array').that.is.not.empty; - expect(bid.mediaType).to.equal('video'); - expect(bid.creativeId).to.equal('xe-demo-video'); - expect(bid.ad).to.equal('vast-xml'); - }); - }); - - describe('getUserSyncs', function () { - it('shoukd handle no params', function () { - const opts = spec.getUserSyncs({}, []); - expect(opts).to.be.an('array').that.is.empty; - }); - - it('should return empty if sync is not allowed', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: false}); - expect(opts).to.be.an('array').that.is.empty; - }); - - it('should allow iframe sync', function () { - const opts = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: false}, [{ - body: { - data: [{ - requestId: 'qwerty', - ext: { - pixels: [ - ['iframe', 'surl1?a=b'], - ['image', 'surl2?a=b'], - ] - } - }] - } - }]); - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('iframe'); - expect(opts[0].url).to.equal('surl1?a=b&us_privacy=&gdpr=0&gdpr_consent='); - }); - - it('should allow pixel sync', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [{ - body: { - data: [{ - requestId: 'qwerty', - ext: { - pixels: [ - ['iframe', 'surl1?a=b'], - ['image', 'surl2?a=b'], - ] - } - }] - } - }]); - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('image'); - expect(opts[0].url).to.equal('surl2?a=b&us_privacy=&gdpr=0&gdpr_consent='); - }); - - it('should allow pixel sync and parse consent params', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [{ - body: { - data: [{ - requestId: 'qwerty', - ext: { - pixels: [ - ['iframe', 'surl1?a=b'], - ['image', 'surl2?a=b'], - ] - } - }] - } - }], { - gdprApplies: 1, - consentString: '1YA-' - }); - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('image'); - expect(opts[0].url).to.equal('surl2?a=b&us_privacy=&gdpr=1&gdpr_consent=1YA-'); - }); - }); - - describe('getBidFloor', function () { - it('should return null when getFloor is not a function', () => { - const bid = {getFloor: 2}; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when getFloor doesnt return an object', () => { - const bid = {getFloor: () => 2}; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when floor is not a number', () => { - const bid = { - getFloor: () => ({floor: 'string', currency: 'USD'}) - }; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when currency is not USD', () => { - const bid = { - getFloor: () => ({floor: 5, currency: 'EUR'}) - }; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return floor value when everything is correct', () => { - const bid = { - getFloor: () => ({floor: 5, currency: 'USD'}) - }; - const result = getBidFloor(bid); - expect(result).to.equal(5); - }); - }); -}); diff --git a/test/spec/modules/iqzoneBidAdapter_spec.js b/test/spec/modules/iqzoneBidAdapter_spec.js deleted file mode 100644 index c14b85b2c..000000000 --- a/test/spec/modules/iqzoneBidAdapter_spec.js +++ /dev/null @@ -1,515 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/iqzoneBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'iqzone'; - -describe('IQZoneBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://smartssp-us-east.iqzone.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.iqzone.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.iqzone.com/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.iqzone.com/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/ivsBidAdapter_spec.js b/test/spec/modules/ivsBidAdapter_spec.js deleted file mode 100644 index e8db6009e..000000000 --- a/test/spec/modules/ivsBidAdapter_spec.js +++ /dev/null @@ -1,195 +0,0 @@ -import { spec, converter } from 'modules/ivsBidAdapter.js'; -import { assert } from 'chai'; -import { deepClone } from '../../../src/utils.js'; - -describe('ivsBidAdapter', function () { - describe('isBidRequestValid()', function () { - const validBid = { - bidder: 'ivs', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480], - mimes: ['video/mp4'] - } - }, - params: { - bidderDomain: 'https://www.example.com', - publisherId: '3001234' - } - }; - - it('should return true for a valid bid', function () { - assert.isTrue(spec.isBidRequestValid(validBid)); - }); - - it('should return false if publisherId info is missing', function () { - const bid = deepClone(validBid); - delete bid.params.publisherId; - assert.isFalse(spec.isBidRequestValid(bid)); - }); - - it('should return false for empty video parameters', function () { - const bid = deepClone(validBid); - delete bid.mediaTypes.video; - assert.isFalse(spec.isBidRequestValid(bid)); - }); - - it('should return false for non instream context', function () { - const bid = deepClone(validBid); - bid.mediaTypes.video.context = 'outstream'; - assert.isFalse(spec.isBidRequestValid(bid)); - }); - }); - - describe('buildRequests()', function () { - let validBidRequests, validBidderRequest; - - beforeEach(function () { - validBidRequests = [{ - bidder: 'ivs', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480], - mimes: ['video/mp4'] - }, - adUnitCode: 'video1', - transactionId: '1f420478-a3cd-452d-8e33-ac851e7bfba6', - bidId: '2d986cea00fd01', - bidderRequestId: '1022d594d79bf5', - auctionId: '835eacc9-cfe7-4fa2-8738-ab4b5c4f26d2' - }, - params: { - bidderDomain: 'https://www.example.com', - publisherId: '3001234' - } - }]; - - validBidderRequest = { - bidderCode: 'ivs', - auctionId: '409bd13d-d0be-43c4-9c4f-e6f81ecff475', - bidderRequestId: '17bfe74bd98e68', - refererInfo: { - domain: 'example.com', - page: 'https://www.example.com/test.html', - }, - bids: [{ - bidder: 'ivs', - params: { - publisherId: '3001234' - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [[640, 480]], - mimes: ['video/mp4'] - } - }, - adUnitCode: 'video1', - transactionId: '91b1977f-d05c-45c3-af1f-69b4e7d11e86', - sizes: [ - [640, 480] - ], - }], - ortb2: { - site: { - publisher: { - domain: 'example.com', - } - } - } - }; - }); - - it('should return a validate bid request', function () { - const bidRequest = spec.buildRequests(validBidRequests, validBidderRequest); - assert.equal(bidRequest.method, 'POST'); - assert.deepEqual(bidRequest.options, { contentType: 'application/json' }); - assert.ok(bidRequest.data); - }); - - it('should contain the required parameters', function () { - const bidRequest = spec.buildRequests(validBidRequests, validBidderRequest); - const bidderRequest = bidRequest.data; - assert.ok(bidderRequest.site); - assert.lengthOf(bidderRequest.imp, 1); - }); - }); - - describe('interpretResponse()', function () { - let serverResponse, bidderRequest, request; - - beforeEach(function () { - serverResponse = { - body: { - id: '635ba1ed-68ba-47b4-bcec-4a86565f25f9', - seatbid: [{ - bid: [{ - crid: 3715, - id: 'bca9823d-ca7a-4dac-b292-0e1fae5948f8', - impid: '200d1ca23b15a6', - price: 1.5, - nurl: 'https://a.ivstracker.net/dev/getvastxml?ad_creativeid=3715&domain=localhost%3A9999&ip=136.158.51.114&pageurl=http%3A%2F%2Flocalhost%3A9999%2Ftest%2Fpages%2Fivs.html&spid=3001234&adplacement=&brand=unknown&device=desktop&adsclientid=A45-fd46289e-dc60-4be2-a637-4bc8eb953ddf&clientid=3b5e435f-0351-4ba0-bd2d-8d6f3454c5ed&uastring=Mozilla%2F5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_15_7)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F109.0.0.0%20Safari%2F537.36' - }] - }], - cur: 'USD' - }, - headers: {} - }; - - bidderRequest = { - bidderCode: 'ivs', - auctionId: '635ba1ed-68ba-47b4-bcec-4a86565f25f9', - bidderRequestId: '1def3e1d03f5a', - bids: [{ - bidder: 'ivs', - params: { - publisherId: '3001234' - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [ - [640, 480] - ], - mimes: ['video/mp4'] - } - }, - adUnitCode: 'video1', - transactionId: '89e5a3e7-df30-4ed6-a130-edfa91941e67', - bidId: '200d1ca23b15a6', - bidderRequestId: '1def3e1d03f5a', - auctionId: '635ba1ed-68ba-47b4-bcec-4a86565f25f9' - }], - }; - - request = { data: converter.toORTB({ bidderRequest }) }; - }); - - if (FEATURES.VIDEO) { - it('should match parsed server response', function () { - const results = spec.interpretResponse(serverResponse, request); - const expected = { - mediaType: 'video', - playerWidth: 640, - playerHeight: 480, - vastUrl: 'https://a.ivstracker.net/dev/getvastxml?ad_creativeid=3715&domain=localhost%3A9999&ip=136.158.51.114&pageurl=http%3A%2F%2Flocalhost%3A9999%2Ftest%2Fpages%2Fivs.html&spid=3001234&adplacement=&brand=unknown&device=desktop&adsclientid=A45-fd46289e-dc60-4be2-a637-4bc8eb953ddf&clientid=3b5e435f-0351-4ba0-bd2d-8d6f3454c5ed&uastring=Mozilla%2F5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_15_7)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F109.0.0.0%20Safari%2F537.36', - requestId: '200d1ca23b15a6', - seatBidId: 'bca9823d-ca7a-4dac-b292-0e1fae5948f8', - cpm: 1.5, - currency: 'USD', - creativeId: 3715, - ttl: 360, - }; - - expect(results.length).to.equal(1); - sinon.assert.match(results[0], expected); - }); - } - - it('should return empty when no response', function () { - assert.ok(!spec.interpretResponse({}, request)); - }); - }); -}); diff --git a/test/spec/modules/ixBidAdapter_spec.js b/test/spec/modules/ixBidAdapter_spec.js deleted file mode 100644 index 032571de5..000000000 --- a/test/spec/modules/ixBidAdapter_spec.js +++ /dev/null @@ -1,5592 +0,0 @@ -import * as utils from 'src/utils.js'; -import { config } from 'src/config.js'; -import { expect } from 'chai'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { spec, storage, FEATURE_TOGGLES, LOCAL_STORAGE_FEATURE_TOGGLES_KEY, REQUESTED_FEATURE_TOGGLES, combineImps, bidToVideoImp, bidToNativeImp, deduplicateImpExtFields, removeSiteIDs, addDeviceInfo, getDivIdFromAdUnitCode } from '../../../modules/ixBidAdapter.js'; -import { deepAccess, deepClone } from '../../../src/utils.js'; -import * as ajaxLib from 'src/ajax.js'; -import * as gptUtils from '../../../libraries/gptUtils/gptUtils.js'; - -describe('IndexexchangeAdapter', function () { - const IX_SECURE_ENDPOINT = 'https://htlb.casalemedia.com/openrtb/pbjs'; - - FEATURE_TOGGLES.REQUESTED_FEATURE_TOGGLES = ['test1', 'test2']; - - const SAMPLE_SCHAIN = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'indirectseller.com', - 'sid': '00001', - 'hp': 1 - }, - { - 'asi': 'indirectseller-2.com', - 'sid': '00002', - 'hp': 2 - } - ] - }; - const LARGE_SET_OF_SIZES = [ - [300, 250], - [600, 410], - [336, 280], - [400, 300], - [320, 50], - [360, 360], - [250, 250], - [320, 250], - [400, 250], - [387, 359], - [300, 50], - [372, 250], - [320, 320], - [412, 412], - [327, 272], - [312, 260], - [384, 320], - [335, 250], - [366, 305], - [374, 250], - [375, 375], - [272, 391], - [364, 303], - [414, 414], - [366, 375], - [272, 360], - [364, 373], - [366, 359], - [320, 100], - [360, 250], - [468, 60], - [480, 300], - [600, 400], - [600, 300], - [33, 28], - [40, 30], - [32, 5], - [36, 36], - [25, 25], - [320, 25], - [400, 25], - [387, 35], - [300, 5], - [372, 20], - [320, 32], - [412, 41], - [327, 27], - [312, 26], - [384, 32], - [335, 25], - [366, 30], - [374, 25], - [375, 37], - [272, 31], - [364, 303], - [414, 41], - [366, 35], - [272, 60], - [364, 73], - [366, 59], - [320, 10], - [360, 25], - [468, 6], - [480, 30], - [600, 40], - [600, 30] - ]; - - const ONE_VIDEO = [ - { - bidder: 'ix', - params: { - siteId: '456', - video: { - skippable: false, - mimes: [ - 'video/mp4', - 'video/webm' - ], - minduration: 0, - maxduration: 60, - protocols: [2] - }, - size: [400, 100] - }, - sizes: [[400, 100]], - mediaTypes: { - video: { - context: 'instream', - playerSize: [[400, 100]] - } - }, - ortb2Imp: { - ext: { - tid: '173f49a8-7549-4218-a23c-e7ba59b47230' - } - }, - adUnitCode: 'div-gpt-ad-1460505748562-0', - transactionId: '173f49a8-7549-4218-a23c-e7ba59b47230', - bidId: '1a2b3c4e', - bidderRequestId: '11a22b33c44e', - auctionId: '1aa2bb3cc4de', - ortb2: { - source: { - ext: { - schain: SAMPLE_SCHAIN - } - } - } - } - ]; - - const ONE_BANNER = [ - { - bidder: 'ix', - params: { - siteId: '123', - size: [300, 250] - }, - sizes: [[300, 250]], - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - ortb2Imp: { - ext: { - tid: '173f49a8-7549-4218-a23c-e7ba59b47229' - } - }, - adUnitCode: 'div-gpt-ad-1460505748561-0', - transactionId: '173f49a8-7549-4218-a23c-e7ba59b47229', - bidId: '1a2b3c4d', - bidderRequestId: '11a22b33c44d', - auctionId: '1aa2bb3cc4dd', - ortb2: { - source: { - ext: { - schain: SAMPLE_SCHAIN - } - } - } - } - ]; - - const DEFAULT_BANNER_VALID_BID = [ - { - bidder: 'ix', - params: { - siteId: '123', - size: [300, 250] - }, - sizes: [[300, 250], [300, 600]], - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - pos: 0 - } - }, - ortb2Imp: { - ext: { - tid: '173f49a8-7549-4218-a23c-e7ba59b47229' - } - }, - adUnitCode: 'div-gpt-ad-1460505748561-0', - transactionId: '173f49a8-7549-4218-a23c-e7ba59b47229', - bidId: '1a2b3c4d', - bidderRequestId: '11a22b33c44d', - auctionId: '1aa2bb3cc4dd', - ortb2: { - source: { - ext: { - schain: SAMPLE_SCHAIN - } - } - } - } - ]; - - const DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED = [ - { - bidder: 'ix', - params: { - siteId: '123', - size: [300, 250] - }, - sizes: [[300, 250], [300, 600]], - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - pos: 0 - } - }, - ortb2Imp: { - ext: { - tid: '173f49a8-7549-4218-a23c-e7ba59b47229', - ae: 1 // Fledge enabled - }, - }, - adUnitCode: 'div-fledge-ad-1460505748561-0', - transactionId: '173f49a8-7549-4218-a23c-e7ba59b47229', - bidId: '1a2b3c4d', - bidderRequestId: '11a22b33c44d', - auctionId: '1aa2bb3cc4dd', - ortb2: { - source: { - ext: { - schain: SAMPLE_SCHAIN - } - } - } - } - ]; - - const DEFAULT_BANNER_VALID_BID_PARAM_NO_SIZE = [ - { - bidder: 'ix', - params: { - siteId: '123' - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - ortb2Imp: { - ext: { - tid: '173f49a8-7549-4218-a23c-e7ba59b47229' - } - }, - adUnitCode: 'div-gpt-ad-1460505748561-0', - transactionId: '173f49a8-7549-4218-a23c-e7ba59b47229', - bidId: '1a2b3c4d', - bidderRequestId: '11a22b33c44d', - auctionId: '1aa2bb3cc4dd', - ortb2: { - source: { - ext: { - schain: SAMPLE_SCHAIN - } - } - } - } - ]; - - const DEFAULT_VIDEO_VALID_BID_NO_VIDEO_PARAMS = [ - { - bidder: 'ix', - params: { - siteId: '456' - }, - sizes: [400, 100], - mediaTypes: { - video: { - context: 'instream', - playerSize: [[400, 100]], - mimes: [ - 'video/mp4', - 'video/webm' - ], - minduration: 0, - maxduration: 60, - protocols: [2] - } - }, - ortb2Imp: { - ext: { - tid: '173f49a8-7549-4218-a23c-e7ba59b47230' - } - }, - adUnitCode: 'div-gpt-ad-1460505748562-0', - transactionId: '173f49a8-7549-4218-a23c-e7ba59b47230', - bidId: '1a2b3c4e', - bidderRequestId: '11a22b33c44e', - auctionId: '1aa2bb3cc4de', - ortb2: { - source: { - ext: { - schain: SAMPLE_SCHAIN - } - } - } - } - ]; - - const DEFAULT_VIDEO_VALID_BID = [ - { - bidder: 'ix', - params: { - siteId: '456', - video: { - skippable: false, - mimes: [ - 'video/mp4', - 'video/webm' - ], - minduration: 0, - maxduration: 60, - protocols: [2] - }, - size: [400, 100] - }, - sizes: [[400, 100], [200, 400]], - mediaTypes: { - video: { - context: 'instream', - playerSize: [[400, 100], [200, 400]] - } - }, - ortb2Imp: { - ext: { - tid: '173f49a8-7549-4218-a23c-e7ba59b47230' - } - }, - adUnitCode: 'div-gpt-ad-1460505748562-0', - transactionId: '173f49a8-7549-4218-a23c-e7ba59b47230', - bidId: '1a2b3c4e', - bidderRequestId: '11a22b33c44e', - auctionId: '1aa2bb3cc4de', - ortb2: { - source: { - ext: { - schain: SAMPLE_SCHAIN - } - } - } - } - ]; - - const DEFAULT_VIDEO_VALID_BID_MEDIUM_SIZE = [ - { - bidder: 'ix', - params: { - siteId: '456', - video: { - skippable: false, - mimes: [ - 'video/mp4', - 'video/webm' - ], - minduration: 0, - maxduration: 60, - protocols: [2] - }, - size: [640, 480] - }, - sizes: [[640, 480], [200, 400]], - mediaTypes: { - video: { - context: 'instream', - playerSize: [[640, 480], [200, 400]] - } - }, - ortb2Imp: { - ext: { - tid: '173f49a8-7549-4218-a23c-e7ba59b47230' - } - }, - adUnitCode: 'div-gpt-ad-1460505748562-0', - transactionId: '173f49a8-7549-4218-a23c-e7ba59b47230', - bidId: '1a2b3c4e', - bidderRequestId: '11a22b33c44e', - auctionId: '1aa2bb3cc4de', - ortb2: { - source: { - ext: { - schain: SAMPLE_SCHAIN - } - } - } - } - ]; - - const DEFAULT_MULTIFORMAT_BANNER_VALID_BID = [ - { - bidder: 'ix', - params: { - tagId: '123', - siteId: '123', - size: [300, 250], - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[600, 700]] - }, - banner: { - sizes: [[300, 250], [300, 600], [400, 500]] - } - }, - ortb2Imp: { - ext: { - tid: '173f49a8-7549-4218-a23c-e7ba59b47230', - data: { - pbadslot: 'div-gpt-ad-1460505748562-0' - } - } - }, - adUnitCode: 'div-gpt-ad-1460505748562-0', - transactionId: '173f49a8-7549-4218-a23c-e7ba59b47230', - bidId: '1a2b3c4e', - bidderRequestId: '11a22b33c44e', - auctionId: '1aa2bb3cc4de', - ortb2: { - source: { - ext: { - schain: SAMPLE_SCHAIN - } - } - } - } - ]; - - const DEFAULT_MULTIFORMAT_VIDEO_VALID_BID = [ - { - bidder: 'ix', - params: { - tagId: '123', - siteId: '456', - video: { - skippable: false, - mimes: [ - 'video/mp4', - 'video/webm' - ], - minduration: 0, - maxduration: 60, - protocols: [1] - }, - size: [300, 250] - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[300, 250]] - }, - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - ortb2Imp: { - ext: { - tid: '273f49a8-7549-4218-a23c-e7ba59b47230', - data: { - pbadslot: 'div-gpt-ad-1460505748562-1' - } - } - }, - adUnitCode: 'div-gpt-ad-1460505748562-1', - transactionId: '273f49a8-7549-4218-a23c-e7ba59b47230', - bidId: '1a2b3c4e', - bidderRequestId: '11a22b33c44e', - auctionId: '1aa2bb3cc4de', - ortb2: { - source: { - ext: { - schain: SAMPLE_SCHAIN - } - } - } - } - ]; - - const DEFAULT_MULTIFORMAT_VALID_BID = [ - { - bidder: 'ix', - params: { - tagId: '123', - siteId: '456', - video: { - siteId: '1111' - }, - banner: { - siteId: '2222' - }, - native: { - siteId: '3333' - }, - size: [300, 250] - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[300, 250]], - skippable: false, - mimes: [ - 'video/mp4', - 'video/webm' - ], - minduration: 0, - maxduration: 60, - protocols: [1] - }, - banner: { - sizes: [[300, 250], [300, 600]] - }, - native: { - icon: { - required: false - }, - title: { - len: 25, - required: true - }, - body: { - required: true - }, - image: { - required: true - }, - sponsoredBy: { - required: true - } - } - }, - ortb2Imp: { - ext: { - tid: '273f49a8-7549-4218-a23c-e7ba59b47230', - data: { - pbadslot: 'div-gpt-ad-1460505748562-0' - } - } - }, - nativeOrtbRequest: { - assets: [{id: 0, required: 0, img: {type: 1}}, {id: 1, required: 1, title: {len: 140}}, {id: 2, required: 1, data: {type: 2}}, {id: 3, required: 1, img: {type: 3}}, {id: 4, required: false, video: {mimes: ['video/mp4', 'video/webm'], minduration: 0, maxduration: 120, protocols: [2, 3, 5, 6]}}] - }, - adUnitCode: 'div-gpt-ad-1460505748562-0', - transactionId: '273f49a8-7549-4218-a23c-e7ba59b47230', - bidId: '1a2b3c4e', - bidderRequestId: '11a22b33c44e', - auctionId: '1aa2bb3cc4de', - ortb2: { - source: { - ext: { - schain: SAMPLE_SCHAIN - } - } - } - } - ]; - - const DEFAULT_NATIVE_VALID_BID = [ - { - bidder: 'ix', - params: { - siteId: '123', - size: [300, 250] - }, - sizes: [[300, 250], [300, 600]], - mediaTypes: { - native: { - icon: { - required: false - }, - title: { - len: 25, - required: true - }, - body: { - required: true - }, - image: { - required: true - }, - video: { - required: false, - mimes: ['video/mp4', 'video/webm'], - minduration: 0, - maxduration: 120, - protocols: [2, 3, 5, 6] - }, - sponsoredBy: { - required: true - } - } - }, - nativeOrtbRequest: { - assets: [{ id: 0, required: 0, img: { type: 1 } }, { id: 1, required: 1, title: { len: 140 } }, { id: 2, required: 1, data: { type: 2 } }, { id: 3, required: 1, img: { type: 3 } }, { id: 4, required: false, video: { mimes: ['video/mp4', 'video/webm'], minduration: 0, maxduration: 120, protocols: [2, 3, 5, 6] } }] - }, - adUnitCode: 'div-gpt-ad-1460505748563-0', - transactionId: '173f49a8-7549-4218-a23c-e7ba59b47231', - bidId: '1a2b3c4f', - bidderRequestId: '11a22b33c44f', - auctionId: '1aa2bb3cc4df', - ortb2: { - source: { - ext: { - schain: SAMPLE_SCHAIN - } - } - } - } - ]; - - const DEFAULT_MULTIFORMAT_NATIVE_VALID_BID = [ - { - bidder: 'ix', - params: { - siteId: '123', - size: [300, 250], - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600], [400, 500]] - }, - native: { - title: { - required: true - }, - body: { - required: true - }, - image: { - required: true - }, - sponsoredBy: { - required: true - }, - icon: { - required: false - } - } - }, - nativeOrtbRequest: { - assets: [{ id: 0, required: 0, img: { type: 1 } }, { id: 1, required: 1, title: { len: 140 } }, { id: 2, required: 1, data: { type: 2 } }, { id: 3, required: 1, img: { type: 3 } }, { id: 4, required: false, video: { mimes: ['video/mp4', 'video/webm'], minduration: 0, maxduration: 120, protocols: [2, 3, 5, 6] } }] - }, - adUnitCode: 'div-gpt-ad-1460505748562-0', - transactionId: '173f49a8-7549-4218-a23c-e7ba59b47230', - bidId: '1a2b3c4e', - bidderRequestId: '11a22b33c44e', - auctionId: '1aa2bb3cc4de', - ortb2: { - source: { - ext: { - schain: SAMPLE_SCHAIN - } - } - } - } - ]; - - const DEFAULT_NATIVE_IMP = { - request: '{"assets":[{"id":0,"required":0,"img":{"type":1}},{"id":1,"required":1,"title":{"len":140}},{"id":2,"required":1,"data":{"type":2}},{"id":3,"required":1,"img":{"type":3}},{"id":4,"required":false,"video":{"mimes":["video/mp4","video/webm"],"minduration":0,"maxduration":120,"protocols":[2,3,5,6]}}],"eventtrackers":[{"event":1,"methods":[1,2]}],"privacy":1}', - ver: '1.2' - } - - const DEFAULT_BANNER_BID_RESPONSE = { - cur: 'USD', - id: '11a22b33c44d', - seatbid: [ - { - bid: [ - { - crid: '12345', - adomain: ['www.abc.com'], - adid: '14851455', - impid: '1a2b3c4d', - cid: '3051266', - price: 100, - w: 300, - h: 250, - id: '1', - ext: { - dspid: 50, - pricelevel: '_100', - advbrandid: 303325, - advbrand: 'OECTA', - ibv: true - }, - adm: '' - } - ], - seat: '3970' - } - ] - }; - - const DEFAULT_BANNER_BID_RESPONSE_WITH_DSA = { - cur: 'USD', - id: '11a22b33c44d', - seatbid: [ - { - bid: [ - { - crid: '12345', - adomain: ['www.abc.com'], - adid: '14851455', - impid: '1a2b3c4d', - cid: '3051266', - price: 100, - w: 300, - h: 250, - id: '1', - ext: { - dspid: 50, - pricelevel: '_100', - advbrandid: 303325, - advbrand: 'OECTA', - dsa: { - behalf: 'Advertiser', - paid: 'Advertiser', - transparency: [{ - domain: 'dsp1domain.com', - dsaparams: [1, 2] - }], - 'adrender': 1 - } - }, - adm: '' - } - ], - seat: '3970' - } - ] - }; - - const DEFAULT_BANNER_BID_RESPONSE_WITHOUT_ADOMAIN = { - cur: 'USD', - id: '11a22b33c44d', - seatbid: [ - { - bid: [ - { - crid: '12345', - adid: '14851455', - impid: '1a2b3c4d', - cid: '3051266', - price: 100, - w: 300, - h: 250, - id: '1', - ext: { - dspid: 50, - pricelevel: '_100', - advbrandid: 303325, - advbrand: 'OECTA' - }, - adm: '' - } - ], - seat: '3970' - } - ] - }; - - const DEFAULT_VIDEO_BID_RESPONSE = { - cur: 'USD', - id: '1aa2bb3cc4de', - seatbid: [ - { - bid: [ - { - crid: '12346', - adomain: ['www.abcd.com'], - adid: '14851456', - impid: '1a2b3c4e', - cid: '3051267', - price: 110, - id: '2', - ext: { - vasturl: 'www.abcd.com/vast', - errorurl: 'www.abcd.com/error', - dspid: 51, - pricelevel: '_110', - advbrandid: 303326, - advbrand: 'OECTB' - } - } - ], - seat: '3971' - } - ], - ext: { - videoplayerurl: 'https://test.com/video-renderer.js' - } - }; - - const DEFAULT_VIDEO_BID_RESPONSE_WITH_XML_ADM = { - cur: 'USD', - id: '1aa2bb3cc4de', - seatbid: [ - { - bid: [ - { - crid: '12346', - adomain: ['www.abcd.com'], - adid: '14851456', - impid: '1a2b3c4e', - cid: '3051267', - price: 110, - id: '2', - mtype: 2, - adm: ' Test In-Stream Video blah"}}],"link":{"url":"https://play.google.com/store/apps/details?id=de.autodoc.gmbh","clicktrackers":["https://click.liftoff.io/v1/campaign_click/blah"]},"eventtrackers":[{"event":1,"method":1,"url":"https://impression-europe.liftoff.io/index/impression"},{"event":1,"method":1,"url":"https://a701.casalemedia.com/impression/v1"}],"privacy":"https://privacy.link.com"}}' - } - ], - seat: '3970' - } - ] - }; - - const DEFAULT_OPTION = { - gdprConsent: { - gdprApplies: true, - consentString: '3huaa11=qu3198ae', - vendorData: {} - }, - refererInfo: { - page: 'https://www.prebid.org', - canonicalUrl: 'https://www.prebid.org/the/link/to/the/page' - }, - ortb2: { - site: { - page: 'https://www.prebid.org' - }, - source: { - tid: 'mock-tid' - } - } - }; - - const DEFAULT_OPTION_FLEDGE_ENABLED_GLOBALLY = { - gdprConsent: { - gdprApplies: true, - consentString: '3huaa11=qu3198ae', - vendorData: {} - }, - refererInfo: { - page: 'https://www.prebid.org', - canonicalUrl: 'https://www.prebid.org/the/link/to/the/page' - }, - ortb2: { - site: { - page: 'https://www.prebid.org' - }, - source: { - tid: 'mock-tid' - } - }, - paapi: { - enabled: true - }, - }; - - const DEFAULT_OPTION_FLEDGE_ENABLED = { - gdprConsent: { - gdprApplies: true, - consentString: '3huaa11=qu3198ae', - vendorData: {} - }, - refererInfo: { - page: 'https://www.prebid.org', - canonicalUrl: 'https://www.prebid.org/the/link/to/the/page' - }, - ortb2: { - site: { - page: 'https://www.prebid.org' - }, - source: { - tid: 'mock-tid' - } - }, - paapi: { - enabled: true - } - }; - - const DEFAULT_IDENTITY_RESPONSE = { - IdentityIp: { - responsePending: false, - data: { - source: 'identityinc.com', - uids: [ - { - id: 'identityid', - atype: 1 - } - ] - } - } - }; - - const DEFAULT_USERID_DATA = { - idl_env: '1234-5678-9012-3456', // Liveramp - netId: 'testnetid123', // NetId - IDP: 'userIDP000', // IDP - fabrickId: 'fabrickId9000', // FabrickId - // so structured because when calling createEidsArray, UID2's getValue func takes .id to set in uids - uid2: { id: 'testuid2' }, // UID 2.0 - // similar to uid2, but id5's getValue takes .uid - id5id: { uid: 'testid5id' }, // ID5 - imuid: 'testimuid', - '33acrossId': { envelope: 'v1.5fs.1000.fjdiosmclds' }, - 'criteoID': { envelope: 'testcriteoID' }, - 'euidID': { envelope: 'testeuid' }, - pairId: {envelope: 'testpairId'} - }; - - const DEFAULT_USERID_PAYLOAD = [ - { - source: 'liveramp.com', - uids: [{ - id: DEFAULT_USERID_DATA.idl_env, - ext: { - rtiPartner: 'idl' - } - }] - }, { - source: 'netid.de', - uids: [{ - id: DEFAULT_USERID_DATA.netId, - ext: { - rtiPartner: 'NETID' - } - }] - }, { - source: 'neustar.biz', - uids: [{ - id: DEFAULT_USERID_DATA.fabrickId, - ext: { - rtiPartner: 'fabrickId' - } - }] - }, { - source: 'zeotap.com', - uids: [{ - id: DEFAULT_USERID_DATA.IDP, - ext: { - rtiPartner: 'zeotapIdPlus' - } - }] - }, { - source: 'uidapi.com', - uids: [{ - id: DEFAULT_USERID_DATA.uid2.id, - ext: { - rtiPartner: 'UID2' - } - }] - }, { - source: 'id5-sync.com', - uids: [{ - id: DEFAULT_USERID_DATA.id5id.uid - }] - }, { - source: 'intimatemerger.com', - uids: [{ - id: DEFAULT_USERID_DATA.imuid - }] - }, { - source: '33across.com', - uids: [{ - id: DEFAULT_USERID_DATA['33acrossId'].envelope - }] - }, { - source: 'criteo.com', - uids: [{ - id: DEFAULT_USERID_DATA['criteoID'].envelope - }] - }, { - source: 'euid.eu', - uids: [{ - id: DEFAULT_USERID_DATA['euidID'].envelope - }] - }, { - source: 'google.com', - uids: [{ - id: DEFAULT_USERID_DATA['pairId'].envelope - }] - } - ]; - - const DEFAULT_USERIDASEIDS_DATA = DEFAULT_USERID_PAYLOAD; - - const DEFAULT_USERID_BID_DATA = { - lotamePanoramaId: 'bd738d136bdaa841117fe9b331bb4' - }; - - const extractPayload = function (bidRequest) { return bidRequest.data } - - const generateEid = function (numEid) { - const eids = []; - - for (let i = 1; i <= numEid; i++) { - const newEid = { - source: `eid_source_${i}.com`, - uids: [{ - id: `uid_id_${i}`, - }] - }; - - eids.push(newEid); - } - - return eids; - } - - describe('inherited functions', function () { - it('should exists and is a function', function () { - const adapter = newBidder(spec); - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('getUserSync tests', function () { - before(() => { - // TODO (dgirardi): the assertions in this block rely on - // global state (consent and siteId) set up in the SOT - // this is an outsider's attempt to recreate that state more explicitly after shuffling around setup code - // in this test suite - - // please make your preconditions explicit; - // also, please, avoid global state if possible. - - spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION); - }) - - it('UserSync test : check type = iframe, check usermatch URL', function () { - const syncOptions = { - 'iframeEnabled': true - } - const userSync = spec.getUserSyncs(syncOptions, []); - expect(userSync[0].type).to.equal('iframe'); - const USER_SYNC_URL = 'https://js-sec.indexww.com/um/ixmatch.html'; - expect(userSync[0].url).to.equal(USER_SYNC_URL); - }); - - it('When iframeEnabled = false, default to img', function () { - const syncOptions = { - 'iframeEnabled': false, - } - const userSync = spec.getUserSyncs(syncOptions, []); - expect(userSync[0].type).to.equal('image'); - const USER_SYNC_URL = 'https://dsum.casalemedia.com/pbusermatch?origin=prebid&site_id=123&p=1&i=0&gdpr=1&gdpr_consent=3huaa11=qu3198ae&us_privacy='; - expect(userSync[0].url).to.equal(USER_SYNC_URL); - }); - - it('UserSync test : check type = pixel, check usermatch URL, no exchange data, only drop 1', function () { - const syncOptions = { - 'pixelEnabled': true - } - config.setConfig({ - userSync: { - pixelEnabled: true, - syncsPerBidder: 3 - } - }) - const userSync = spec.getUserSyncs(syncOptions, []); - expect(userSync[0].type).to.equal('image'); - const USER_SYNC_URL = 'https://dsum.casalemedia.com/pbusermatch?origin=prebid&site_id=123&p=1&i=0&gdpr=1&gdpr_consent=3huaa11=qu3198ae&us_privacy='; - expect(userSync[0].url).to.equal(USER_SYNC_URL); - }); - - it('UserSync test : check type = pixel, check usermatch URL with override set to 0', function () { - const syncOptions = { - 'pixelEnabled': true - } - config.setConfig({ - userSync: { - pixelEnabled: true, - syncsPerBidder: 3 - } - }); - const userSync = spec.getUserSyncs(syncOptions, [{ 'body': { 'ext': { 'publishersyncsperbidderoverride': 0 } } }]); - expect(userSync.length).to.equal(0); - }); - - it('UserSync test : check type = pixel, check usermatch URL with override set', function () { - const syncOptions = { - 'pixelEnabled': true - } - config.setConfig({ - userSync: { - pixelEnabled: true, - syncsPerBidder: 3 - } - }); - const userSync = spec.getUserSyncs(syncOptions, [{ 'body': { 'ext': { 'publishersyncsperbidderoverride': 2 } } }]); - expect(userSync[0].type).to.equal('image'); - const USER_SYNC_URL_0 = 'https://dsum.casalemedia.com/pbusermatch?origin=prebid&site_id=123&p=2&i=0&gdpr=1&gdpr_consent=3huaa11=qu3198ae&us_privacy='; - const USER_SYNC_URL_1 = 'https://dsum.casalemedia.com/pbusermatch?origin=prebid&site_id=123&p=2&i=1&gdpr=1&gdpr_consent=3huaa11=qu3198ae&us_privacy='; - expect(userSync[0].url).to.equal(USER_SYNC_URL_0); - expect(userSync[1].url).to.equal(USER_SYNC_URL_1); - expect(userSync.length).to.equal(2); - }); - - it('UserSync test : check type = pixel, check usermatch URL with override greater than publisher syncs per bidder , use syncsperbidder', function () { - const syncOptions = { - 'pixelEnabled': true - } - config.setConfig({ - userSync: { - pixelEnabled: true, - syncsPerBidder: 3 - } - }); - const userSync = spec.getUserSyncs(syncOptions, [{ 'body': { 'ext': { 'publishersyncsperbidderoverride': 4 } } }]); - expect(userSync[0].type).to.equal('image'); - const USER_SYNC_URL_0 = 'https://dsum.casalemedia.com/pbusermatch?origin=prebid&site_id=123&p=3&i=0&gdpr=1&gdpr_consent=3huaa11=qu3198ae&us_privacy='; - const USER_SYNC_URL_1 = 'https://dsum.casalemedia.com/pbusermatch?origin=prebid&site_id=123&p=3&i=1&gdpr=1&gdpr_consent=3huaa11=qu3198ae&us_privacy='; - const USER_SYNC_URL_2 = 'https://dsum.casalemedia.com/pbusermatch?origin=prebid&site_id=123&p=3&i=2&gdpr=1&gdpr_consent=3huaa11=qu3198ae&us_privacy='; - expect(userSync[0].url).to.equal(USER_SYNC_URL_0); - expect(userSync[1].url).to.equal(USER_SYNC_URL_1); - expect(userSync[2].url).to.equal(USER_SYNC_URL_2); - expect(userSync.length).to.equal(3); - }); - - it('UserSync test : check type = pixel, syncsPerBidder = 0, still use override', function () { - const syncOptions = { - 'pixelEnabled': true - } - config.setConfig({ - userSync: { - pixelEnabled: true, - syncsPerBidder: 0 - } - }); - const userSync = spec.getUserSyncs(syncOptions, [{ 'body': { 'ext': { 'publishersyncsperbidderoverride': 2 } } }]); - expect(userSync[0].type).to.equal('image'); - const USER_SYNC_URL_0 = 'https://dsum.casalemedia.com/pbusermatch?origin=prebid&site_id=123&p=2&i=0&gdpr=1&gdpr_consent=3huaa11=qu3198ae&us_privacy='; - const USER_SYNC_URL_1 = 'https://dsum.casalemedia.com/pbusermatch?origin=prebid&site_id=123&p=2&i=1&gdpr=1&gdpr_consent=3huaa11=qu3198ae&us_privacy='; - expect(userSync[0].url).to.equal(USER_SYNC_URL_0); - expect(userSync[1].url).to.equal(USER_SYNC_URL_1); - expect(userSync.length).to.equal(2); - }); - }); - - describe('isBidRequestValid', function () { - it('should return false if outstream player size is less than 144x144 and IX renderer is preferred', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.mediaTypes.video.context = 'outstream'; - bid.mediaTypes.video.w = [[300, 143]]; - expect(spec.isBidRequestValid(bid)).to.equal(false); - bid.mediaTypes.video.w = [[143, 300]]; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if outstream video w & h is less than 144x144 and IX renderer is preferred', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.mediaTypes.video.context = 'outstream'; - bid.mediaTypes.video.playerSize = [[300, 250]]; - bid.mediaTypes.video.w = 300; - bid.mediaTypes.video.h = 142; - expect(spec.isBidRequestValid(bid)).to.equal(false); - bid.mediaTypes.video.h = 300; - bid.mediaTypes.video.w = 142; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true if outstream player size is less than 300x250 and IX renderer is not preferred', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.mediaTypes.video.renderer = { - url: 'test', - render: () => { } - }; - bid.mediaTypes.video.context = 'outstream'; - bid.mediaTypes.video.playerSize = [[300, 249]]; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when required params found for a banner, video or native ad', function () { - expect(spec.isBidRequestValid(DEFAULT_BANNER_VALID_BID[0])).to.equal(true); - expect(spec.isBidRequestValid(DEFAULT_VIDEO_VALID_BID[0])).to.equal(true); - expect(spec.isBidRequestValid(DEFAULT_NATIVE_VALID_BID[0])).to.equal(true); - }); - - it('should return true when optional bidFloor params found for an ad', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.params.bidFloor = 50; - bid.params.bidFloorCur = 'USD'; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when siteID is number', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.params.siteId = 123; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when siteID is missing', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - delete bid.params.siteId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return True when size is missing ', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - delete bid.params.size; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when size array is wrong length', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.params.size = [ - 300, - 250, - 250 - ]; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when size array is array of strings', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.params.size = ['300', '250']; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when mediaTypes.banner does not have sizes', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.mediaTypes = { - banner: { - size: [[300, 250]] - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when mediaTypes.video.playerSize does not include params.size', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.mediaTypes = { - video: { - playerSize: [[300, 250]] - } - }; - bid.params.size = [100, 200]; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when mediaTypes.video.playerSize includes params.size', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.mediaTypes = { - video: { - playerSize: [[300, 250], [200, 300]] - } - }; - bid.params.size = [[300, 250]]; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when bid.params.size is missing', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - delete bid.params.size; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when minduration is missing', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - delete bid.params.video.minduration; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when mediaType is native', function () { - const bid = utils.deepClone(DEFAULT_NATIVE_VALID_BID[0]); - delete bid.params.mediaTypes; - bid.mediaType = 'native'; - bid.sizes = [[300, 250]]; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when mediaType is missing and has sizes', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - delete bid.mediaTypes; - bid.sizes = [[300, 250]]; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when mediaType is banner', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - delete bid.mediaTypes; - bid.mediaType = 'banner'; - bid.sizes = [[300, 250]]; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when mediaType is video', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - delete bid.mediaTypes; - bid.mediaType = 'video'; - bid.sizes = [[400, 100]]; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true for banner bid when there are multiple mediaTypes (banner, outstream)', function () { - const bid = utils.deepClone(DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0]); - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true for video bid when there are multiple mediaTypes (banner, outstream)', function () { - const bid = utils.deepClone(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0]); - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('shoult return true for native bid when there are multiple mediaTypes (banner, native)', function () { - const bid = utils.deepClone(DEFAULT_MULTIFORMAT_NATIVE_VALID_BID[0]); - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - - it('should return false when there is only bidFloor', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.params.bidFloor = 50; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when there is only bidFloorCur', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.params.bidFloorCur = 'USD'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when bidFloor is string', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.params.bidFloor = '50'; - bid.params.bidFloorCur = 'USD'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when bidFloorCur is number', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.params.bidFloor = 50; - bid.params.bidFloorCur = 70; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when required video properties are missing on both adunit & param levels', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - delete bid.params.video.mimes; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when required video properties are at the adunit level', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - delete bid.params.video.mimes; - bid.mediaTypes.video.mimes = ['video/mp4']; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true if protocols exists but protocol doesn\'t', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - expect(spec.isBidRequestValid(bid)).to.equal(true); - delete bid.params.video.protocols; - bid.mediaTypes.video.protocols = 1; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true if protocol exists but protocols doesn\'t', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - delete bid.params.video.protocols; - bid.params.video.protocol = 1; - expect(spec.isBidRequestValid(bid)).to.equal(true); - delete bid.params.video.protocol; - bid.mediaTypes.video.protocol = 1; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false if both protocol/protocols are missing', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - delete bid.params.video.protocols; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should fail if native openRTB object contains no valid assets', function () { - const bid = utils.deepClone(DEFAULT_NATIVE_VALID_BID[0]); - bid.nativeOrtbRequest = {} - expect(spec.isBidRequestValid(bid)).to.be.false; - - bid.nativeOrtbRequest = { assets: [] } - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - }); - - describe('buildRequestsIdentity', function () { - let request; - let payload; - let testCopy; - - beforeEach(function () { - window.headertag = {}; - window.headertag.getIdentityInfo = function () { - return testCopy; - }; - request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION)[0]; - payload = extractPayload(request); - }); - - afterEach(function () { - delete window.headertag; - }); - - describe('buildRequestSingleRTI', function () { - before(function () { - testCopy = JSON.parse(JSON.stringify(DEFAULT_IDENTITY_RESPONSE)); - }); - - it('payload should have correct format and value (single identity partner)', function () { - expect(payload.user).to.exist; - expect(payload.user.eids).to.exist; - expect(payload.user.eids).to.be.an('array'); - expect(payload.user.eids).to.have.lengthOf(1); - }); - - it('identity data in impression should have correct format and value (single identity partner)', function () { - const impression = payload.user.eids; - expect(impression).to.be.an('array'); - expect(impression).to.have.lengthOf(1); - expect(impression[0].source).to.equal(testCopy.IdentityIp.data.source); - expect(impression[0].uids).to.be.an('array'); - expect(impression[0].uids).to.have.lengthOf(1); - expect(impression[0].uids[0].id).to.equal(testCopy.IdentityIp.data.uids[0].id); - expect(impression[0].uids[0].atype).to.exist; - expect(impression[0].uids[0].atype).to.equal(testCopy.IdentityIp.data.uids[0].atype); - }); - }); - - describe('buildRequestMultipleIds', function () { - before(function () { - testCopy = JSON.parse(JSON.stringify(DEFAULT_IDENTITY_RESPONSE)); - testCopy.IdentityIp.data.uids.push( - { - id: '1234567' - }, - { - id: '2019-04-01TF2:34:41' - } - ); - }); - - it('payload should have correct format and value (single identity w/ multi ids)', function () { - expect(payload.user).to.exist; - expect(payload.user.eids).to.exist; - expect(payload.user.eids).to.be.an('array'); - expect(payload.user.eids).to.have.lengthOf(1); - }); - - it('identity data in impression should have correct format and value (single identity w/ multi ids)', function () { - const impression = payload.user.eids; - - expect(impression[0].source).to.equal(testCopy.IdentityIp.data.source); - expect(impression[0].uids).to.have.lengthOf(3); - }); - }); - - describe('buildRequestMultipleRTI', function () { - before(function () { - testCopy = JSON.parse(JSON.stringify(DEFAULT_IDENTITY_RESPONSE)); - testCopy.JackIp = { - responsePending: false, - data: { - source: 'jackinc.com', - uids: [ - { - id: 'jackid' - } - ] - } - } - testCopy.GenericIp = { - responsePending: false, - data: { - source: 'genericip.com', - uids: [ - { - id: 'genericipenvelope' - } - ] - } - } - }); - - it('payload should have correct format and value (multiple identity partners)', function () { - expect(payload.user).to.exist; - expect(payload.user.eids).to.exist; - expect(payload.user.eids).to.be.an('array'); - expect(payload.user.eids).to.have.lengthOf(3); - }); - - it('identity data in impression should have correct format and value (multiple identity partners)', function () { - const impression = payload.user.eids; - - expect(impression[0].source).to.equal(testCopy.IdentityIp.data.source); - expect(impression[0].uids).to.have.lengthOf(1); - - expect(impression[1].source).to.equal(testCopy.JackIp.data.source); - expect(impression[1].uids).to.have.lengthOf(1); - - expect(impression[2].source).to.equal(testCopy.GenericIp.data.source); - expect(impression[2].uids).to.have.lengthOf(1); - }); - }); - - describe('buildRequestNoData', function () { - beforeEach(function () { - testCopy = JSON.parse(JSON.stringify(DEFAULT_IDENTITY_RESPONSE)); - }); - - it('payload should not have any user eids with an undefined identity data response', function () { - window.headertag.getIdentityInfo = function () { - return undefined; - }; - request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION)[0]; - payload = extractPayload(request); - - expect(payload.user).to.exist; - expect(payload.user.eids).to.not.exist; - }); - - it('payload should have user eids if least one partner data is available', function () { - testCopy.GenericIp = { - responsePending: true, - data: {} - } - request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION)[0]; - payload = extractPayload(request); - - expect(payload.user).to.exist; - expect(payload.user.eids).to.exist; - }); - - it('payload should not have any user eids if identity data is pending for all partners', function () { - testCopy.IdentityIp.responsePending = true; - request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION)[0]; - payload = extractPayload(request); - - expect(payload.user).to.exist; - expect(payload.user.eids).to.not.exist; - }); - - it('payload should not have any user eids if identity data is pending or not available for all partners', function () { - testCopy.IdentityIp.responsePending = false; - testCopy.IdentityIp.data = {}; - request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION)[0]; - payload = extractPayload(request); - - expect(payload.user).to.exist; - expect(payload.user.eids).to.not.exist; - }); - }); - }); - - describe('buildRequestsUserId', function () { - let validIdentityResponse; - let validUserIdPayload; - const serverResponse = { - body: { - ext: { - pbjs_allow_all_eids: { - activated: true - } - } - } - }; - - beforeEach(function () { - window.headertag = {}; - window.headertag.getIdentityInfo = function () { - return validIdentityResponse; - }; - }); - - afterEach(function () { - delete window.headertag; - validIdentityResponse = {} - }); - - it('IX adapter reads supported user modules from Prebid and adds it to Video', function () { - const cloneValidBid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); - cloneValidBid[0].userIdAsEids = utils.deepClone(DEFAULT_USERIDASEIDS_DATA); - const request = spec.buildRequests(cloneValidBid, DEFAULT_OPTION)[0]; - const payload = extractPayload(request); - expect(payload.user.eids).to.have.lengthOf(11); - expect(payload.user.eids).to.have.deep.members(DEFAULT_USERID_PAYLOAD); - }); - - it('IX adapter filters eids from prebid past the maximum eid limit', function () { - const cloneValidBid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); - const eid_sent_from_prebid = generateEid(55); - cloneValidBid[0].userIdAsEids = utils.deepClone(eid_sent_from_prebid); - const request = spec.buildRequests(cloneValidBid, DEFAULT_OPTION)[0]; - const payload = extractPayload(request); - expect(payload.user.eids).to.have.lengthOf(50); - const eid_accepted = eid_sent_from_prebid.slice(0, 50); - expect(payload.user.eids).to.have.deep.members(eid_accepted); - expect(payload.ext.ixdiag.eidLength).to.equal(55); - }); - - it('IX adapter filters eids from IXL past the maximum eid limit', function () { - validIdentityResponse = { - MerkleIp: { - responsePending: false, - data: { - source: 'merkle.com', - uids: [{ - id: '1234-5678-9012-3456', - ext: { - keyID: '1234-5678', - enc: 1 - } - }] - } - }, - LiveIntentIp: { - responsePending: false, - data: { - source: 'liveintent.com', - uids: [{ - id: '1234-5678-9012-3456', - ext: { - keyID: '1234-5678', - rtiPartner: 'LDID', - enc: 1 - } - }] - } - } - }; - const cloneValidBid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); - const eid_sent_from_prebid = generateEid(49); - cloneValidBid[0].userIdAsEids = utils.deepClone(eid_sent_from_prebid); - const request = spec.buildRequests(cloneValidBid, DEFAULT_OPTION)[0]; - const payload = extractPayload(request); - expect(payload.user.eids).to.have.lengthOf(50); - eid_sent_from_prebid.push({ - source: 'merkle.com', - uids: [{ - id: '1234-5678-9012-3456', - ext: { - keyID: '1234-5678', - enc: 1 - } - }] - }) - expect(payload.user.eids).to.have.deep.members(eid_sent_from_prebid); - expect(payload.ext.ixdiag.eidLength).to.equal(49); - }); - - it('Has incoming eids with no uid', function () { - const cloneValidBid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); - const eid_sent_from_prebid = [ - { - source: 'catijah.org' - }, - { - source: 'bagel.com' - } - ]; - cloneValidBid[0].userIdAsEids = utils.deepClone(eid_sent_from_prebid); - const request = spec.buildRequests(cloneValidBid, DEFAULT_OPTION)[0]; - const payload = extractPayload(request); - expect(payload.user.eids).to.be.undefined - expect(payload.ext.ixdiag.eidLength).to.equal(2); - }); - - it('We continue to send in IXL identity info and Prebid takes precedence over IXL', function () { - validIdentityResponse = { - AdserverOrgIp: { - responsePending: false, - data: { - source: 'adserver.org', - uids: [ - { - id: '1234-5678-9012-3456', - ext: { - rtiPartner: 'TDID' - } - }, - { - id: 'FALSE', - ext: { - rtiPartner: 'TDID_LOOKUP' - } - }, - { - id: '2020-06-24T14:43:48.860Z', - ext: { - rtiPartner: 'TDID_CREATED_AT' - } - } - ] - } - }, - MerkleIp: { - responsePending: false, - data: { - source: 'merkle.com', - uids: [{ - id: '1234-5678-9012-3456', - ext: { - keyID: '1234-5678', - enc: 1 - } - }] - } - }, - LiveRampIp: { - source: 'liveramp.com', - uids: [ - { - id: '0000-1234-4567-8901', - ext: { - rtiPartner: 'idl' - } - } - ] - }, - NetIdIp: { - source: 'netid.de', - uids: [ - { - id: 'testnetid', - ext: { - rtiPartner: 'NETID' - } - } - ] - }, - NeustarIp: { - source: 'neustar.biz', - uids: [ - { - id: 'testfabrick', - ext: { - rtiPartner: 'fabrickId' - } - } - ] - }, - ZeotapIp: { - source: 'zeotap.com', - uids: [ - { - id: 'testzeotap', - ext: { - rtiPartner: 'zeotapIdPlus' - } - } - ] - } - }; - - const cloneValidBid = utils.deepClone(DEFAULT_BANNER_VALID_BID); - cloneValidBid[0].userIdAsEids = utils.deepClone(DEFAULT_USERIDASEIDS_DATA); - - const request = spec.buildRequests(cloneValidBid, DEFAULT_OPTION)[0]; - const payload = extractPayload(request); - - validUserIdPayload = utils.deepClone(DEFAULT_USERID_PAYLOAD); - validUserIdPayload.push({ - source: 'merkle.com', - uids: [{ - id: '1234-5678-9012-3456', - ext: { - keyID: '1234-5678', - enc: 1 - } - }] - }) - validUserIdPayload.push({ - source: 'adserver.org', - uids: [ - { - id: '1234-5678-9012-3456', - ext: { - rtiPartner: 'TDID' - } - }, - { - id: 'FALSE', - ext: { - rtiPartner: 'TDID_LOOKUP' - } - }, - { - id: '2020-06-24T14:43:48.860Z', - ext: { - rtiPartner: 'TDID_CREATED_AT' - } - } - ] - }) - - expect(payload.user).to.exist; - expect(payload.user.eids).to.have.lengthOf(13); - - expect(payload.user.eids).to.have.deep.members(validUserIdPayload); - }); - - it('IXL and Prebid are mutually exclusive', function () { - validIdentityResponse = { - LiveIntentIp: { - responsePending: false, - data: { - source: 'liveintent.com', - uids: [{ - id: '1234-5678-9012-3456', - ext: { - keyID: '1234-5678', - rtiPartner: 'LDID', - enc: 1 - } - }] - } - } - }; - - const cloneValidBid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); - cloneValidBid[0].userIdAsEids = utils.deepClone(DEFAULT_USERIDASEIDS_DATA); - - const request = spec.buildRequests(cloneValidBid, DEFAULT_OPTION)[0]; - - validUserIdPayload = utils.deepClone(DEFAULT_USERID_PAYLOAD); - validUserIdPayload.push({ - source: 'liveintent.com', - uids: [{ - id: '1234-5678-9012-3456', - ext: { - keyID: '1234-5678', - rtiPartner: 'LDID', - enc: 1 - } - }] - }); - - const payload = extractPayload(request); - expect(payload.user.eids).to.have.lengthOf(12); - expect(payload.user.eids).to.have.deep.members(validUserIdPayload); - }); - }); - - describe('First party data', function () { - it('should not set ixdiag.fpd value if not defined', function () { - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2: {} })[0]; - const r = extractPayload(request); - - expect(r.ext.ixdiag.fpd).to.be.undefined; - }); - - it('should set ixdiag.fpd value if it exists using ortb2', function () { - const ortb2 = { - site: { - ext: { - data: { - pageType: 'article' - } - } - } - }; - - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2 })[0]; - const r = extractPayload(request); - - expect(r.ext.ixdiag.fpd).to.exist; - }); - - it('should set ixdiag.tmax value from bidderRequest overriding global config bidderTimeout', function () { - config.setConfig({ - bidderTimeout: 250 - }); - - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { timeout: 1234 })[0]; - const r = extractPayload(request); - - expect(r.ext.ixdiag.tmax).to.equal(1234); - }); - - it('should not set ixdiag.tmax value if bidderTimeout is undefined', function () { - config.setConfig({ - bidderTimeout: null - }) - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID)[0]; - const r = extractPayload(request); - - expect(r.ext.ixdiag.tmax).to.be.undefined - }); - - it('should set ixdiag.imps to number of impressions', function () { - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID)[0]; - const r = extractPayload(request); - - expect(r.ext.ixdiag.imps).to.equal(1); - }); - - it('should not send information that is not part of openRTB spec v2.5 using ortb2', function () { - const ortb2 = { - site: { - keywords: 'power tools, drills', - search: 'drill', - testProperty: 'test_string' - }, - user: { - keywords: ['a'], - testProperty: 'test_string' - } - }; - - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2 })[0]; - const r = extractPayload(request); - - expect(r.site.keywords).to.exist; - expect(r.site.search).to.exist; - expect(r.site.testProperty).to.be.undefined; - expect(r.user.keywords).to.exist; - expect(r.user.testProperty).to.be.undefined; - }); - - it('should set dsa field when defined', function () { - const dsa = { - dsarequired: 3, - pubrender: 0, - datatopub: 2, - transparency: [{ - domain: 'domain.com', - dsaparams: [1] - }] - } - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2: {regs: { - ext: { - dsa: deepClone(dsa) - } - } - }})[0]; - const r = extractPayload(request); - - expect(r.regs.ext.dsa.dsarequired).to.equal(dsa.dsarequired); - expect(r.regs.ext.dsa.pubrender).to.equal(dsa.pubrender); - expect(r.regs.ext.dsa.datatopub).to.equal(dsa.datatopub); - expect(r.regs.ext.dsa.transparency).to.be.an('array'); - expect(r.regs.ext.dsa.transparency).to.have.deep.members(dsa.transparency); - }); - it('should not set dsa fields when fields arent appropriately defined', function () { - const dsa = { - dsarequired: '3', - pubrender: '0', - datatopub: '2', - transparency: 20 - } - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2: {regs: { - ext: { - dsa: deepClone(dsa) - } - } - }})[0]; - const r = extractPayload(request); - - expect(r.regs).to.be.undefined; - }); - it('should not set dsa transparency when fields arent appropriately defined', function () { - const dsa = { - transparency: [{ - domain: 3, - dsaparams: [1] - }, - { - domain: 'domain.com', - dsaparams: 'params' - }, - { - domain: 'domain.com', - dsaparams: ['1'] - }] - } - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2: {regs: { - ext: { - dsa: deepClone(dsa) - } - } - }})[0]; - const r = extractPayload(request); - - expect(r.regs).to.be.undefined; - }); - it('should set gpp and gpp_sid field when defined', function () { - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2: {regs: {gpp: 'gpp', gpp_sid: [1]}} })[0]; - const r = extractPayload(request); - - expect(r.regs.gpp).to.equal('gpp'); - expect(r.regs.gpp_sid).to.be.an('array'); - expect(r.regs.gpp_sid).to.include(1); - }); - it('should not set gpp, gpp_sid and dsa field when not defined', function () { - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2: {regs: {}} })[0]; - const r = extractPayload(request); - - expect(r.regs).to.be.undefined; - }); - it('should not set gpp and gpp_sid field when fields arent strings or array defined', function () { - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2: {regs: {gpp: 1, gpp_sid: 'string'}} })[0]; - const r = extractPayload(request); - - expect(r.regs).to.be.undefined; - }); - it('should set gpp info from module when it exists', function () { - const options = { - gppConsent: { - gppString: 'gpp', - applicableSections: [1] - } - }; - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options); - const r = extractPayload(request[0]); - - expect(r.regs.gpp).to.equal('gpp'); - expect(r.regs.gpp_sid).to.be.an('array'); - expect(r.regs.gpp_sid).to.include(1); - }); - - it('should add adunit specific data to imp ext for banner', function () { - const AD_UNIT_CODE = '/19968336/some-adunit-path'; - const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID); - validBids[0].ortb2Imp = { - ext: { - data: { - adserver: { - name: 'gam banner', - adslot: AD_UNIT_CODE - } - } - } - }; - const requests = spec.buildRequests(validBids, DEFAULT_OPTION); - const imp = extractPayload(requests[0]).imp[0]; - expect(deepAccess(imp, 'ext.data.adserver.name')).to.equal('gam banner'); - expect(deepAccess(imp, 'ext.data.adserver.adslot')).to.equal(AD_UNIT_CODE); - }); - - it('should add adunit specific data to imp ext for native', function () { - const AD_UNIT_CODE = '/19968336/some-adunit-path'; - const validBids = utils.deepClone(DEFAULT_NATIVE_VALID_BID); - validBids[0].ortb2Imp = { - ext: { - data: { - adserver: { - name: 'gam native', - adslot: AD_UNIT_CODE - } - } - } - }; - const requests = spec.buildRequests(validBids, DEFAULT_OPTION); - const imp = extractPayload(requests[0]).imp[0]; - expect(deepAccess(imp, 'ext.data.adserver.name')).to.equal('gam native'); - expect(deepAccess(imp, 'ext.data.adserver.adslot')).to.equal(AD_UNIT_CODE); - }); - - it('should add adunit specific data to imp ext for video', function () { - const AD_UNIT_CODE = '/19968336/some-adunit-path'; - const validBids = utils.deepClone(DEFAULT_VIDEO_VALID_BID); - validBids[0].ortb2Imp = { - ext: { - data: { - adserver: { - name: 'gam video', - adslot: AD_UNIT_CODE - } - } - } - }; - const requests = spec.buildRequests(validBids, DEFAULT_OPTION); - const imp = extractPayload(requests[0]).imp[0]; - expect(deepAccess(imp, 'ext.data.adserver.name')).to.equal('gam video'); - expect(deepAccess(imp, 'ext.data.adserver.adslot')).to.equal(AD_UNIT_CODE); - }); - }); - - describe('buildRequests', function () { - const bidWithoutSchain = utils.deepClone(DEFAULT_BANNER_VALID_BID); - if (bidWithoutSchain[0].ortb2 && bidWithoutSchain[0].ortb2.source && bidWithoutSchain[0].ortb2.source.ext) { - delete bidWithoutSchain[0].ortb2.source.ext.schain; - } - const GPID = '/19968336/some-adunit-path'; - let request, requestUrl, requestMethod, payloadData, requestWithoutSchain, payloadWithoutSchain; - - before(() => { - request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION)[0]; - requestUrl = request.url; - requestMethod = request.method; - payloadData = request.data; - requestWithoutSchain = spec.buildRequests(bidWithoutSchain, DEFAULT_OPTION)[0]; - payloadWithoutSchain = extractPayload(requestWithoutSchain); - }); - - it('request should be made to IX endpoint with POST method and siteId in query param', function () { - expect(requestMethod).to.equal('POST'); - expect(requestUrl).to.equal(IX_SECURE_ENDPOINT + '?s=' + DEFAULT_BANNER_VALID_BID[0].params.siteId); - }); - - it('request made to IX endpoint with POST method should have correct options fields set', function () { - expect(request.options.contentType).to.equal('text/plain') - expect(request.options.withCredentials).to.equal(true) - }); - - it('auction type should be set correctly', function () { - const at = payloadData.at; - expect(at).to.equal(1); - }) - - it('should send dfp_adunit_code in request if ortb2Imp.ext.data.adserver.adslot exists', function () { - const AD_UNIT_CODE = '/19968336/some-adunit-path'; - const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID); - validBids[0].ortb2Imp = { - ext: { - data: { - adserver: { - name: 'gam', - adslot: AD_UNIT_CODE - } - } - } - }; - const requests = spec.buildRequests(validBids, DEFAULT_OPTION); - const { ext: { dfp_ad_unit_code } } = extractPayload(requests[0]).imp[0]; - expect(dfp_ad_unit_code).to.equal(AD_UNIT_CODE); - }); - - it('should send gpid in request if ortb2Imp.ext.gpid exists', function () { - const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID); - validBids[0].ortb2Imp = { - ext: { - gpid: GPID - } - }; - const requests = spec.buildRequests(validBids, DEFAULT_OPTION); - const { ext: { gpid } } = extractPayload(requests[0]).imp[0]; - expect(gpid).to.equal(GPID); - }); - - it('should send gpid in request if ortb2Imp.ext.gpid exists when no size present', function () { - const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID_PARAM_NO_SIZE); - validBids[0].ortb2Imp = { - ext: { - gpid: GPID - } - }; - const requests = spec.buildRequests(validBids, DEFAULT_OPTION); - const { ext: { gpid } } = extractPayload(requests[0]).imp[0]; - expect(gpid).to.equal(GPID); - }); - - it('should not send dfp_adunit_code in request if ortb2Imp.ext.data.adserver.adslot does not exists', function () { - const GPID = '/19968336/some-adunit-path'; - const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID); - validBids[0].ortb2Imp = { - ext: { - gpid: GPID - } - }; - const requests = spec.buildRequests(validBids, DEFAULT_OPTION); - const imp = extractPayload(requests[0]).imp[0]; - expect(deepAccess(imp, 'ext.dfp_ad_unit_code')).to.not.exist; - }); - - it('should not send gpid in request if ortb2Imp.ext.gpid does not exists', function () { - const AD_UNIT_CODE = '/19968336/some-adunit-path'; - const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID); - validBids[0].ortb2Imp = { - ext: { - data: { - adserver: { - name: 'gam', - adslot: AD_UNIT_CODE - } - } - } - }; - const requests = spec.buildRequests(validBids, DEFAULT_OPTION); - const imp = extractPayload(requests[0]).imp[0]; - expect(deepAccess(imp, 'ext.gpid')).to.not.exist; - }); - - it('should send gpid & dfp_adunit_code if they exist in ortb2Imp.ext', function () { - const AD_UNIT_CODE = '/1111/home'; - const GPID = '/1111/home-left'; - const validBids = utils.deepClone(DEFAULT_BANNER_VALID_BID); - validBids[0].ortb2Imp = { - ext: { - gpid: GPID, - data: { - adserver: { - name: 'gam', - adslot: AD_UNIT_CODE - } - } - } - }; - const requests = spec.buildRequests(validBids, DEFAULT_OPTION); - const imp = extractPayload(requests[0]).imp[0]; - expect(deepAccess(imp, 'ext.gpid')).to.equal(GPID); - expect(deepAccess(imp, 'ext.dfp_ad_unit_code')).to.equal(AD_UNIT_CODE); - }); - - it('payload should have correct format and value', function () { - const payload = payloadData; - expect(payload.id).to.equal(DEFAULT_BANNER_VALID_BID[0].bidderRequestId); - expect(payload.id).to.be.a('string'); - expect(payload.site.page).to.equal(DEFAULT_OPTION.refererInfo.page); - expect(payload.site.ref).to.equal(document.referrer); - expect(payload.ext.source).to.equal('prebid'); - expect(payload.source.ext.schain).to.deep.equal(SAMPLE_SCHAIN); - expect(payload.imp).to.be.an('array'); - expect(payload.imp).to.have.lengthOf(1); - expect(payload.source.tid).to.equal(DEFAULT_OPTION.ortb2.source.tid); - }); - - it('payload should have correct format and value for r.id when bidderRequestId is a number ', function () { - const bidWithIntId = utils.deepClone(DEFAULT_BANNER_VALID_BID); - bidWithIntId[0].bidderRequestId = 123456; - - request = spec.buildRequests(bidWithIntId, DEFAULT_OPTION)[0]; - - const payload = extractPayload(request); - expect(bidWithIntId[0].bidderRequestId).to.be.a('number'); - expect(payload.id).to.equal(bidWithIntId[0].bidderRequestId.toString()); - expect(payload.id).to.be.a('string'); - }); - - it('payload should have correct format and value for r.id when bidderRequestId is a number ', function () { - const bidWithIntId = utils.deepClone(DEFAULT_BANNER_VALID_BID); - bidWithIntId[0].bidderRequestId = 123456; - - request = spec.buildRequests(bidWithIntId, DEFAULT_OPTION)[0]; - - const payload = extractPayload(request); - expect(bidWithIntId[0].bidderRequestId).to.be.a('number'); - expect(payload.id).to.equal(bidWithIntId[0].bidderRequestId.toString()); - expect(payload.id).to.be.a('string'); - }); - - it('payload should not include schain when not provided', function () { - const payload = payloadWithoutSchain; - - const actualSchain = (((payload || {}).source || {}).ext || {}).schain; - expect(actualSchain).to.not.exist; - }); - - it('impression should have correct format and value', function () { - const impression = payloadData.imp[0]; - const sidValue = DEFAULT_BANNER_VALID_BID[0].params.id; - - expect(impression.id).to.equal(DEFAULT_BANNER_VALID_BID[0].bidId); - expect(impression.banner.format).to.be.length(2); - expect(impression.banner.topframe).to.be.oneOf([0, 1]); - expect(impression.banner.pos).to.equal(0); - expect(impression.ext.tid).to.equal(DEFAULT_BANNER_VALID_BID[0].transactionId); - expect(impression.ext.sid).to.equal(sidValue); - - impression.banner.format.map(({ w, h, ext }, index) => { - const size = DEFAULT_BANNER_VALID_BID[0].mediaTypes.banner.sizes[index]; - - expect(w).to.equal(size[0]); - expect(h).to.equal(size[1]); - expect(ext.siteID).to.equal(DEFAULT_BANNER_VALID_BID[0].params.siteId); - }); - }); - - it('payload should have imp[].banner.format[].ext.siteID as string ', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.params.siteId = 1234; - - request = spec.buildRequests([bid], DEFAULT_OPTION)[0]; - - const payload = extractPayload(request); - payload.imp[0].banner.format.forEach((imp) => { - expect(imp.ext.siteID).to.be.a('string'); - }); - }); - - it('multi-configured size params should have the correct imp[].banner.format[].ext.siteID', function () { - const bid1 = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - const bid2 = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid1.params.siteId = 1234; - bid1.bidId = '27fc897708d826'; - bid2.params.siteId = 4321; - bid2.bidId = '34df030c33dc68'; - bid2.params.size = [300, 600]; - request = spec.buildRequests([bid1, bid2], DEFAULT_OPTION)[0]; - - const payload = extractPayload(request); - expect(payload.imp[0].banner.format[0].ext.siteID).to.equal('1234'); - expect(payload.imp[0].banner.format[1].ext.siteID).to.equal('4321'); - }); - - it('multi-configured size params should be added to the imp[].banner.format[] array', function () { - const bid1 = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - const bid2 = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid1.params.siteId = 1234; - bid1.bidId = '27fc897708d826'; - bid2.params.siteId = 4321; - bid2.bidId = '34df030c33dc68'; - bid2.params.size = [300, 600]; - request = spec.buildRequests([bid1, bid2], DEFAULT_OPTION)[0]; - - const payload = extractPayload(request); - expect(payload.imp[0].banner.format.length).to.equal(2); - expect(`${payload.imp[0].banner.format[0].w}x${payload.imp[0].banner.format[0].h}`).to.equal('300x250'); - expect(`${payload.imp[0].banner.format[1].w}x${payload.imp[0].banner.format[1].h}`).to.equal('300x600'); - }); - - describe('build requests with price floors', () => { - const highFloor = 4.5; - const lowFloor = 3.5; - const currency = 'USD'; - - it('video impression should contain floors from priceFloors module', function () { - const bid = utils.deepClone(ONE_VIDEO[0]); - const expectedFloor = 3.25; - bid.getFloor = () => ({ floor: expectedFloor, currency }); - const request = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(request).imp[0]; - - expect(impression.bidfloor).to.equal(expectedFloor); - expect(impression.bidfloorcur).to.equal(currency); - expect(impression.ext.fl).to.equal('p'); - }); - - it('banner impression should contain floors from priceFloors module', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]) - const expectedFloor = 3.25; - bid.getFloor = () => ({ floor: expectedFloor, currency }); - const request = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(request).imp[0]; - - expect(impression.bidfloor).to.equal(expectedFloor); - expect(impression.bidfloorcur).to.equal(currency); - expect(impression.banner.format[0].ext.fl).to.equal('p'); - }); - - it('should default to ix floors when priceFloors Module is not implemented', function () { - const bid = utils.deepClone(ONE_BANNER[0]); - bid.params.bidFloor = highFloor; - bid.params.bidFloorCur = 'USD' - const request = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(request).imp[0]; - - expect(impression.bidfloor).to.equal(highFloor); - expect(impression.bidfloorcur).to.equal(bid.params.bidFloorCur); - expect(impression.banner.format[0].ext.fl).to.equal('x'); - }); - - it('should prioritize priceFloors Module over IX param floors', function () { - const bid = utils.deepClone(ONE_BANNER[0]); - bid.params.bidFloor = lowFloor; - bid.params.bidFloorCur = 'USD'; - const expectedFloor = highFloor; - bid.getFloor = () => ({ floor: expectedFloor, currency }); - const requestBidFloor = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(requestBidFloor).imp[0]; - - expect(impression.bidfloor).to.equal(highFloor); - expect(impression.bidfloorcur).to.equal(bid.params.bidFloorCur); - expect(impression.banner.format[0].ext.fl).to.equal('p'); - }); - - it('impression should have bidFloor and bidFloorCur if configured', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.params.bidFloor = 50; - bid.params.bidFloorCur = 'USD'; - const requestBidFloor = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(requestBidFloor).imp[0]; - - expect(impression.bidfloor).to.equal(bid.params.bidFloor); - expect(impression.bidfloorcur).to.equal(bid.params.bidFloorCur); - expect(impression.banner.format[0].ext.fl).to.equal('x'); - }); - - it('banner multi size impression should have bidFloor both in imp and format ext objects', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.params.bidFloor = 50; - bid.params.bidFloorCur = 'USD'; - const requestBidFloor = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(requestBidFloor).imp[0]; - - expect(impression.bidfloor).to.equal(bid.params.bidFloor); - expect(impression.bidfloorcur).to.equal(bid.params.bidFloorCur); - expect(impression.banner.format[0].ext.bidfloor).to.equal(50); - }); - - it('missing sizes impressions should contain floors from priceFloors module ', function () { - const bid = utils.deepClone(ONE_BANNER[0]); - bid.mediaTypes.banner.sizes.push([500, 400]) - - const expectedFloor = 3.25; - bid.getFloor = () => ({ floor: expectedFloor, currency }); - - sinon.spy(bid, 'getFloor'); - - const requestBidFloor = spec.buildRequests([bid], {})[0]; - expect(bid.getFloor.getCall(0).args[0].mediaType).to.equal('banner'); - expect(bid.getFloor.getCall(0).args[0].size[0]).to.equal(300); - expect(bid.getFloor.getCall(0).args[0].size[1]).to.equal(250); - - expect(bid.getFloor.getCall(1).args[0].mediaType).to.equal('banner'); - expect(bid.getFloor.getCall(1).args[0].size[0]).to.equal(500); - expect(bid.getFloor.getCall(1).args[0].size[1]).to.equal(400); - - const impression = extractPayload(requestBidFloor).imp[0]; - expect(impression.bidfloor).to.equal(expectedFloor); - expect(impression.bidfloorcur).to.equal(currency); - }); - - it('banner impressions should have pricefloors in AdUnit', function () { - const bid = utils.deepClone(ONE_BANNER[0]); - - const expectedFloor = 4.3; - bid.floors = { - currency: 'USD', - schema: { - delimiter: '|', - fields: ['mediaType', 'size'] - }, - values: { - 'banner|300x250': expectedFloor, - 'banner|600x500': 6.5, - 'banner|*': 7.5 - } - }; - bid.getFloor = () => ({ floor: expectedFloor, currency }); - - sinon.spy(bid, 'getFloor'); - - const requestBidFloor = spec.buildRequests([bid], {})[0]; - expect(bid.getFloor.getCall(0).args[0].mediaType).to.equal('banner'); - expect(bid.getFloor.getCall(0).args[0].size[0]).to.equal(300); - expect(bid.getFloor.getCall(0).args[0].size[1]).to.equal(250); - - const impression = extractPayload(requestBidFloor).imp[0]; - expect(impression.bidfloor).to.equal(expectedFloor); - expect(impression.bidfloorcur).to.equal(currency); - }); - }); - - it('impression should have sid if id is configured as number', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.params.id = 50; - const requestBidFloor = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(requestBidFloor).imp[0]; - - expect(impression.id).to.equal(DEFAULT_BANNER_VALID_BID[0].bidId); - expect(impression.banner.format[0].w).to.equal(DEFAULT_BANNER_VALID_BID[0].params.size[0]); - expect(impression.banner.format[0].h).to.equal(DEFAULT_BANNER_VALID_BID[0].params.size[1]); - expect(impression.banner.topframe).to.be.oneOf([0, 1]); - expect(impression.banner.format[0].ext.siteID).to.equal(DEFAULT_BANNER_VALID_BID[0].params.siteId); - expect(impression.ext.sid).to.equal('50'); - }); - - it('impression should have sid if id is configured as string', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.params.id = 'abc'; - const requestBidFloor = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(requestBidFloor).imp[0]; - - expect(impression.id).to.equal(DEFAULT_BANNER_VALID_BID[0].bidId); - expect(impression.banner.format[0].w).to.equal(DEFAULT_BANNER_VALID_BID[0].params.size[0]); - expect(impression.banner.format[0].h).to.equal(DEFAULT_BANNER_VALID_BID[0].params.size[1]); - expect(impression.banner.topframe).to.be.oneOf([0, 1]); - expect(impression.banner.format[0].ext.siteID).to.equal(DEFAULT_BANNER_VALID_BID[0].params.siteId); - expect(impression.ext.sid).to.equal('abc'); - }); - - describe('first party data', () => { - beforeEach(() => { - config.resetConfig(); - }); - - it('should add first party data to page url in bid request if it exists in config', function () { - config.setConfig({ - ix: { - firstPartyData: { - ab: 123, - cd: '123#ab', - 'e/f': 456, - 'h?g': '456#cd' - } - } - }); - - const requestWithFirstPartyData = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION)[0]; - const pageUrl = extractPayload(requestWithFirstPartyData).site.page; - const expectedPageUrl = DEFAULT_OPTION.ortb2.site.page + '/?ab=123&cd=123%23ab&e%2Ff=456&h%3Fg=456%23cd'; - expect(pageUrl).to.equal(expectedPageUrl); - }); - - it('should set device sua if available in fpd and request size does not exceed limit', function () { - const ortb2 = { - device: { - sua: { - platform: { - brand: 'macOS', - version: [ '12', '6', '1' ] - }, - browsers: [ - { - brand: 'Chromium', - version: [ '107', '0', '5249', '119' ] - }, - { - brand: 'Google Chrome', - version: [ '107', '0', '5249', '119' ] - }, - ], - mobile: 0, - model: '' - } - }}; - - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2 })[0]; - const payload = extractPayload(request); - expect(payload.device.sua.platform.brand).to.equal('macOS') - expect(payload.device.sua.mobile).to.equal(0) - }); - - it('should not set device sua if not available in fpd', function () { - const ortb2 = { - device: {}}; - - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2 })[0]; - const payload = extractPayload(request); - expect(payload.device.h).to.exist; - expect(payload.device.w).to.exist; - }); - - it('should not set first party data if it is not an object', function () { - config.setConfig({ - ix: { - firstPartyData: 500 - } - }); - - const requestFirstPartyDataNumber = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION)[0]; - const pageUrl = extractPayload(requestFirstPartyDataNumber).site.page; - - expect(pageUrl).to.equal(DEFAULT_OPTION.refererInfo.page); - }); - - it('should not set first party or timeout if it is not present', function () { - config.setConfig({ - ix: {} - }); - - const requestWithoutConfig = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION)[0]; - const pageUrl = extractPayload(requestWithoutConfig).site.page; - - expect(pageUrl).to.equal(DEFAULT_OPTION.refererInfo.page); - expect(requestWithoutConfig.data.t).to.be.undefined; - }); - - it('should not set first party or timeout if it is setConfig is not called', function () { - const requestWithoutConfig = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION)[0]; - const pageUrl = extractPayload(requestWithoutConfig).site.page; - - expect(pageUrl).to.equal(DEFAULT_OPTION.refererInfo.page); - expect(requestWithoutConfig.data.t).to.be.undefined; - }); - - it('should no longer set timeout even if publisher set it through setConfig', function () { - config.setConfig({ - ix: { - timeout: 500 - } - }); - const requestWithTimeout = spec.buildRequests(DEFAULT_BANNER_VALID_BID, {})[0]; - - expect(requestWithTimeout.data.t).to.be.undefined; - }); - - it('should no longer set timeout even if timeout is a string', function () { - config.setConfig({ - ix: { - timeout: '500' - } - }); - const requestStringTimeout = spec.buildRequests(DEFAULT_BANNER_VALID_BID, {})[0]; - - expect(requestStringTimeout.data.t).to.be.undefined; - }); - }); - - describe('getIxFirstPartyDataPageUrl', () => { - beforeEach(() => { - config.setConfig({ ix: { firstPartyData: { key1: 'value1', key2: 'value2' } } }); - }); - - afterEach(() => { - config.resetConfig(); - }); - - it('should return the modified URL with first party data query parameters appended', () => { - const requestWithIXFirstPartyData = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION)[0]; - const pageUrl = extractPayload(requestWithIXFirstPartyData).site.page; - expect(pageUrl).to.equal('https://www.prebid.org/?key1=value1&key2=value2'); - }); - - it('should return the modified URL with first party data query parameters appended but not duplicated', () => { - const bidderRequest = deepClone(DEFAULT_OPTION); - bidderRequest.ortb2.site.page = 'https://www.prebid.org/?key1=value1' - const requestWithIXFirstPartyData = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION)[0]; - const pageUrl = extractPayload(requestWithIXFirstPartyData).site.page; - expect(pageUrl).to.equal('https://www.prebid.org/?key1=value1&key2=value2'); - }); - - it('should not overwrite existing query parameters with first party data', () => { - config.setConfig({ ix: { firstPartyData: { key1: 'value1', key2: 'value2' } } }); - const bidderRequest = deepClone(DEFAULT_OPTION); - bidderRequest.ortb2.site.page = 'https://www.prebid.org/?key1=existingValue1' - const requestWithIXFirstPartyData = spec.buildRequests(DEFAULT_BANNER_VALID_BID, bidderRequest)[0]; - const pageUrl = extractPayload(requestWithIXFirstPartyData).site.page; - expect(pageUrl).to.equal('https://www.prebid.org/?key1=existingValue1&key2=value2'); - }); - - it('should return the original URL if no first party data is available', () => { - config.setConfig({ ix: {} }); - const requestWithIXFirstPartyData = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION)[0]; - const pageUrl = extractPayload(requestWithIXFirstPartyData).site.page; - expect(pageUrl).to.equal('https://www.prebid.org'); - }); - - it('should return the original URL referer page url if ortb2 does not exist', () => { - config.setConfig({ ix: {} }); - const bidderRequest = deepClone(DEFAULT_OPTION); - delete bidderRequest.ortb2; - bidderRequest.refererInfo.page = 'https://example.com'; - const requestWithIXFirstPartyData = spec.buildRequests(DEFAULT_BANNER_VALID_BID, bidderRequest)[0]; - const pageUrl = extractPayload(requestWithIXFirstPartyData).site.page; - expect(pageUrl).to.equal('https://example.com'); - }); - - it('should use referer URL if the provided ortb2.site.page URL is not valid', () => { - config.setConfig({ ix: { firstPartyData: { key1: 'value1', key2: 'value2' } } }); - const bidderRequest = deepClone(DEFAULT_OPTION); - bidderRequest.ortb2.site.page = 'www.invalid-url*&?.com'; - bidderRequest.refererInfo.page = 'https://www.prebid.org'; - const requestWithIXFirstPartyData = spec.buildRequests(DEFAULT_BANNER_VALID_BID, bidderRequest)[0]; - const pageUrl = extractPayload(requestWithIXFirstPartyData).site.page; - expect(pageUrl).to.equal('https://www.prebid.org/?key1=value1&key2=value2'); - }); - }); - - describe('request should contain both banner and video requests', function () { - let request; - before(() => { - request = spec.buildRequests([DEFAULT_BANNER_VALID_BID[0], DEFAULT_VIDEO_VALID_BID[0]], {}); - }); - - it('should have banner request', () => { - const bannerImpression = extractPayload(request[0]).imp[0]; - const sidValue = DEFAULT_BANNER_VALID_BID[0].params.id; - - expect(extractPayload(request[0]).imp).to.have.lengthOf(1); - expect(bannerImpression.id).to.equal(DEFAULT_BANNER_VALID_BID[0].bidId); - - expect(bannerImpression.banner.format).to.be.length(2); - expect(bannerImpression.banner.topframe).to.be.oneOf([0, 1]); - expect(bannerImpression.ext.sid).to.equal(sidValue); - - bannerImpression.banner.format.map(({ w, h, ext }, index) => { - const size = DEFAULT_BANNER_VALID_BID[0].mediaTypes.banner.sizes[index]; - - expect(w).to.equal(size[0]); - expect(h).to.equal(size[1]); - expect(ext.siteID).to.equal(DEFAULT_BANNER_VALID_BID[0].params.siteId); - }); - }); - - it('should have video request', () => { - const videoImpression = extractPayload(request[1]).imp[0]; - - expect(videoImpression.id).to.equal(DEFAULT_VIDEO_VALID_BID[0].bidId); - expect(videoImpression.video.w).to.equal(DEFAULT_VIDEO_VALID_BID[0].params.size[0]); - expect(videoImpression.video.h).to.equal(DEFAULT_VIDEO_VALID_BID[0].params.size[1]); - }); - }); - - describe('video request should set displaymanager', () => { - it('ix renderer preferrered', () => { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); - bid[0].mediaTypes.video.context = 'outstream'; - bid[0].mediaTypes.video.w = [[300, 143]]; - if (bid[0].ortb2 && bid[0].ortb2.source && bid[0].ortb2.source.ext) { - delete bid[0].ortb2.source.ext.schain; - } - const request = spec.buildRequests(bid); - const videoImpression = extractPayload(request[0]).imp[0]; - expect(videoImpression.displaymanager).to.equal('ix'); - }); - it('ix renderer not preferrered', () => { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); - bid[0].mediaTypes.video.context = 'outstream'; - bid[0].mediaTypes.video.w = [[300, 143]]; - bid[0].mediaTypes.video.renderer = { - url: 'http://publisherplayer.js', - render: () => { } - }; - if (bid[0].ortb2 && bid[0].ortb2.source && bid[0].ortb2.source.ext) { - delete bid[0].ortb2.source.ext.schain; - } - const request = spec.buildRequests(bid); - const videoImpression = extractPayload(request[0]).imp[0]; - expect(videoImpression.displaymanager).to.equal('http://publisherplayer.js'); - }); - it('ix renderer not preferrered - bad url', () => { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); - bid[0].mediaTypes.video.context = 'outstream'; - bid[0].mediaTypes.video.w = [[300, 143]]; - bid[0].mediaTypes.video.renderer = { - url: 'publisherplayer.js', - render: () => { } - }; - if (bid[0].ortb2 && bid[0].ortb2.source && bid[0].ortb2.source.ext) { - delete bid[0].ortb2.source.ext.schain; - } - const request = spec.buildRequests(bid); - const videoImpression = extractPayload(request[0]).imp[0]; - expect(videoImpression.displaymanager).to.be.undefined; - }); - it('renderer url provided and is ix renderer', () => { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); - bid[0].mediaTypes.video.context = 'outstream'; - bid[0].mediaTypes.video.w = [[300, 143]]; - bid[0].mediaTypes.video.renderer = { - url: 'http://js-sec.indexww.rendererplayer.com', - render: () => { } - }; - if (bid[0].ortb2 && bid[0].ortb2.source && bid[0].ortb2.source.ext) { - delete bid[0].ortb2.source.ext.schain; - } - const request = spec.buildRequests(bid); - const videoImpression = extractPayload(request[0]).imp[0]; - expect(videoImpression.displaymanager).to.equal('ix'); - }); - it('renderer url undefined and is ix renderer', () => { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); - bid[0].mediaTypes.video.context = 'outstream'; - bid[0].mediaTypes.video.w = [[300, 143]]; - bid[0].mediaTypes.video.renderer = { - render: () => { } - }; - if (bid[0].ortb2 && bid[0].ortb2.source && bid[0].ortb2.source.ext) { - delete bid[0].ortb2.source.ext.schain; - } - const request = spec.buildRequests(bid); - const videoImpression = extractPayload(request[0]).imp[0]; - expect(videoImpression.displaymanager).to.be.undefined; - }); - it('schain', () => { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID); - bid[0].mediaTypes.video.context = 'outstream'; - bid[0].mediaTypes.video.w = [[300, 143]]; - bid[0].ortb2 = { - source: { - ext: { - schain: SAMPLE_SCHAIN - } - } - }; - const request = spec.buildRequests(bid); - const videoImpression = extractPayload(request[0]).imp[0]; - expect(videoImpression.displaymanager).to.equal('pbjs_wrapper'); - }); - }); - - describe('request should contain both banner and native requests', function () { - let request; - before(() => { - request = spec.buildRequests([DEFAULT_BANNER_VALID_BID[0], DEFAULT_NATIVE_VALID_BID[0]]); - }) - - it('should have banner request', () => { - const bannerImpression = extractPayload(request[0]).imp[0]; - const sidValue = DEFAULT_BANNER_VALID_BID[0].params.id; - - expect(extractPayload(request[0]).imp).to.have.lengthOf(1); - expect(bannerImpression.id).to.equal(DEFAULT_BANNER_VALID_BID[0].bidId); - - expect(bannerImpression.banner.format).to.be.length(2); - expect(bannerImpression.banner.topframe).to.be.oneOf([0, 1]); - expect(bannerImpression.ext.sid).to.equal(sidValue); - - bannerImpression.banner.format.map(({ w, h, ext }, index) => { - const size = DEFAULT_BANNER_VALID_BID[0].mediaTypes.banner.sizes[index]; - - expect(w).to.equal(size[0]); - expect(h).to.equal(size[1]); - expect(ext.siteID).to.equal(DEFAULT_BANNER_VALID_BID[0].params.siteId); - }); - }); - - it('should have native request', () => { - const nativeImpression = extractPayload(request[1]).imp[0]; - - expect(request[1].data.hasOwnProperty('v')).to.equal(false); - expect(nativeImpression.id).to.equal(DEFAULT_NATIVE_VALID_BID[0].bidId); - expect(nativeImpression.native).to.deep.equal(DEFAULT_NATIVE_IMP); - }); - }); - - it('single request under 8k size limit for large ad unit', function () { - const options = {}; - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.mediaTypes.banner.sizes = LARGE_SET_OF_SIZES; - const requests = spec.buildRequests([bid], options); - - const reqSize = `${requests[0].url}?${utils.parseQueryStringParameters(requests[0].data)}`.length; - expect(requests).to.be.an('array'); - expect(requests).to.have.lengthOf(1); - expect(reqSize).to.be.lessThan(8000); - expect(requests[0].data.sn).to.be.undefined; - }); - - it('1 request, one larger than url size, no splitting', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.mediaTypes.banner.sizes = LARGE_SET_OF_SIZES; - bid.params.siteId = '124'; - bid.adUnitCode = 'div-gpt-1' - bid.transactionId = '152e36d1-1241-4242-t35e-y1dv34d12315'; - bid.bidId = '2f6g5s5e'; - - const requests = spec.buildRequests([bid, DEFAULT_BANNER_VALID_BID[0]], DEFAULT_OPTION); - expect(requests).to.be.an('array'); - expect(requests).to.have.lengthOf(1); - }); - - it('6 ad units should generate only 1 requests', function () { - const bid1 = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid1.mediaTypes.banner.sizes = LARGE_SET_OF_SIZES; - bid1.params.siteId = '121'; - bid1.adUnitCode = 'div-gpt-1' - bid1.transactionId = 'tr1'; - bid1.bidId = '2f6g5s5e'; - - const bid2 = utils.deepClone(bid1); - bid2.transactionId = 'tr2'; - - const bid3 = utils.deepClone(bid1); - bid3.transactionId = 'tr3'; - - const bid4 = utils.deepClone(bid1); - bid4.transactionId = 'tr4'; - - const bid5 = utils.deepClone(bid1); - bid5.transactionId = 'tr5'; - - const bid6 = utils.deepClone(bid1); - bid6.transactionId = 'tr6'; - - const requests = spec.buildRequests([bid1, bid2, bid3, bid4, bid5, bid6], DEFAULT_OPTION); - - expect(requests).to.be.an('array'); - expect(requests).to.have.lengthOf(1); - - for (var i = 0; i < requests.length; i++) { - const reqSize = `${requests[i].url}?${utils.parseQueryStringParameters(requests[i].data)}`.length; - expect(reqSize).to.be.lessThan(8000); - const payload = extractPayload(requests[i]); - expect(payload.source.ext.schain).to.deep.equal(SAMPLE_SCHAIN); - } - }); - - it('multiple ad units in one request', function () { - const bid1 = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid1.mediaTypes.banner.sizes = [[300, 250], [300, 600], [100, 200]]; - bid1.params.siteId = '121'; - bid1.adUnitCode = 'div-gpt-1' - bid1.transactionId = 'tr1'; - bid1.bidId = '2f6g5s5e'; - - const bid2 = utils.deepClone(bid1); - bid2.adUnitCode = 'div-gpt-2' - bid2.transactionId = 'tr2'; - bid2.mediaTypes.banner.sizes = [[220, 221], [222, 223], [300, 250]]; - const bid3 = utils.deepClone(bid1); - bid3.adUnitCode = 'div-gpt-3' - bid3.transactionId = 'tr3'; - bid3.mediaTypes.banner.sizes = [[330, 331], [332, 333], [300, 250]]; - - const requests = spec.buildRequests([bid1, bid2, bid3], DEFAULT_OPTION); - - expect(requests).to.be.an('array'); - expect(requests).to.have.lengthOf(1); - - const impressions = extractPayload(requests[0]).imp; - expect(impressions).to.be.an('array'); - expect(impressions).to.have.lengthOf(3); - expect(requests[0].data.sn).to.be.undefined; - }); - - it('request should contain the extra banner ad sizes that IX is not configured for using the first site id in the ad unit', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.sizes.push([336, 280], [970, 90]); - bid.mediaTypes.banner.sizes.push([336, 280], [970, 90]); - const bid2 = utils.deepClone(bid); - bid2.params.siteId = '124'; - bid2.params.size = [300, 600]; - bid2.params.bidId = '2b3c4d5e'; - - const request = spec.buildRequests([bid, bid2], DEFAULT_OPTION)[0]; - const impression = extractPayload(request).imp[0]; - const sidValue = bid.params.id; - - expect(impression.id).to.equal(bid.bidId); - expect(impression.banner.format).to.be.length(bid.mediaTypes.banner.sizes.length); - expect(impression.banner.topframe).to.be.oneOf([0, 1]); - expect(impression.ext.sid).to.equal(sidValue); - - impression.banner.format.map(({ w, h, ext }, index) => { - const size = bid.mediaTypes.banner.sizes[index]; - - expect(w).to.equal(size[0]); - expect(h).to.equal(size[1]); - expect(ext.siteID).to.equal(index === 1 ? bid2.params.siteId : bid.params.siteId); - }); - }); - - it('request should contain the extra banner ad sizes and their corresponding site ids when there is multiple ad units', function () { - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.params.siteId = '124'; - bid.adUnitCode = 'div-gpt-ad-156456451554-1' - bid.transactionId = '152e36d1-1241-4242-t35e-y1dv34d12315'; - bid.bidId = '2f6g5s5e'; - bid.params.size = [336, 280] - bid.sizes = [[336, 280], [970, 90]] - bid.mediaTypes.banner.sizes = [[336, 280], [970, 90]] - - const bids = [DEFAULT_BANNER_VALID_BID[0], bid]; - const request = spec.buildRequests(bids, DEFAULT_OPTION)[0]; - - const impressions = extractPayload(request).imp; - expect(impressions).to.be.an('array'); - expect(impressions).to.have.lengthOf(2); - expect(request.data.sn).to.be.undefined; - - impressions.map((impression, impressionIndex) => { - const firstSizeObject = bids[impressionIndex].mediaTypes.banner.sizes[0]; - const sidValue = bids[impressionIndex].params.id; - - expect(impression.banner.format).to.be.length(2); - expect(impression.banner.topframe).to.be.oneOf([0, 1]); - expect(impression.ext.sid).to.equal(sidValue); - - impression.banner.format.map(({ w, h, ext }, index) => { - const size = bids[impressionIndex].mediaTypes.banner.sizes[index]; - - expect(w).to.equal(size[0]); - expect(h).to.equal(size[1]); - expect(ext.siteID).to.equal(bids[impressionIndex].params.siteId); - }); - }); - }); - - it('request should not contain the extra video ad sizes that IX is not configured for', function () { - const request = spec.buildRequests(DEFAULT_VIDEO_VALID_BID, DEFAULT_OPTION); - const impressions = extractPayload(request[0]).imp; - - expect(impressions).to.be.an('array'); - expect(impressions).to.have.lengthOf(1); - }); - - describe('detect missing sizes', function () { - it('request should always contain missing sizes', function () { - const bid1 = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid1.mediaTypes.banner.sizes = LARGE_SET_OF_SIZES; - - const requests = spec.buildRequests([bid1, DEFAULT_BANNER_VALID_BID[0]], DEFAULT_OPTION); - - const impressions = extractPayload(requests[0]).imp; - - expect(impressions).to.be.an('array'); - expect(impressions).to.have.lengthOf(1); - }); - }); - }); - - describe('buildRequestVideo', function () { - let request, payloadData; - before(() => { - request = spec.buildRequests(DEFAULT_VIDEO_VALID_BID, DEFAULT_OPTION); - payloadData = request[0].data; - }) - - it('auction type should be set correctly', function () { - const at = payloadData.at; - expect(at).to.equal(1); - }) - - it('impression should have correct format and value', function () { - const impression = payloadData.imp[0]; - - expect(impression.id).to.equal(DEFAULT_VIDEO_VALID_BID[0].bidId); - expect(impression.video.w).to.equal(DEFAULT_VIDEO_VALID_BID[0].params.size[0]); - expect(impression.video.h).to.equal(DEFAULT_VIDEO_VALID_BID[0].params.size[1]); - expect(impression.video.placement).to.equal(1); - expect(impression.video.minduration).to.exist; - expect(impression.video.minduration).to.equal(0); - expect(impression.video.mimes[0]).to.equal('video/mp4'); - expect(impression.video.mimes[1]).to.equal('video/webm'); - - expect(impression.video.skippable).to.equal(false); - }); - - it('should not use default placement values when placement is defined at adUnit level', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.mediaTypes.video.context = 'outstream'; - bid.mediaTypes.video.placement = 2; - const request = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(request).imp[0]; - - expect(impression.id).to.equal(DEFAULT_VIDEO_VALID_BID[0].bidId); - expect(impression.video.placement).to.equal(2); - }); - - it('should use plcmt value when set in video.params', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.params.video.plcmt = 2; - const request = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(request).imp[0]; - - expect(impression.id).to.equal(DEFAULT_VIDEO_VALID_BID[0].bidId); - expect(impression.video.plcmt).to.equal(2); - }); - - it('invalid plcmt value when set in video.params', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.params.video.plcmt = 5; - const request = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(request).imp[0]; - - expect(impression.id).to.equal(DEFAULT_VIDEO_VALID_BID[0].bidId); - expect(impression.video.plcmt).to.be.undefined; - }); - - it('invalid plcmt value string when set in video.params', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.params.video.plcmt = '4'; - const request = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(request).imp[0]; - - expect(impression.id).to.equal(DEFAULT_VIDEO_VALID_BID[0].bidId); - expect(impression.video.plcmt).to.be.undefined; - }); - - it('should set imp.ext.sid for video imps if params.id exists', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.params.id = 50; - const request = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(request).imp[0]; - - expect(impression.ext.sid).to.equal('50'); - }); - - it('should set correct default placement, if context is instream', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.mediaTypes.video.context = 'instream'; - const request = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(request).imp[0]; - - expect(impression.id).to.equal(DEFAULT_VIDEO_VALID_BID[0].bidId); - expect(impression.video.placement).to.equal(1); - }); - - it('should set correct default placement, if context is outstream', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.mediaTypes.video.context = 'outstream'; - const request = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(request).imp[0]; - - expect(impression.id).to.equal(DEFAULT_VIDEO_VALID_BID[0].bidId); - expect(impression.video.placement).to.equal(3); - expect(extractPayload(request).ext.ixdiag.vpd).to.equal(true); - }); - - it('should handle unexpected context', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.mediaTypes.video.context = 'not-valid'; - const request = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(request).imp[0]; - expect(impression.video.placement).to.be.undefined; - }); - - it('should not override video properties if they are already configured at the params video level', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.mediaTypes.video.context = 'outstream'; - bid.mediaTypes.video.protocols = [1]; - bid.mediaTypes.video.mimes = ['video/override']; - const request = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(request).imp[0]; - - expect(impression.video.protocols[0]).to.equal(2); - expect(impression.video.mimes[0]).to.not.equal('video/override'); - }); - - it('should not add video adunit level properties in imp object if they are not allowlisted', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.mediaTypes.video.context = 'outstream'; - bid.mediaTypes.video.random = true; - const request = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(request).imp[0]; - - expect(impression.video.random).to.not.exist; - }); - - it('should add allowlisted adunit level video properties in imp object if they are not configured at params level', function () { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.mediaTypes.video.context = 'outstream'; - delete bid.params.video.protocols; - delete bid.params.video.mimes; - bid.mediaTypes.video.protocols = [6]; - bid.mediaTypes.video.mimes = ['video/mp4']; - bid.mediaTypes.video.api = 2; - bid.mediaTypes.video.pos = 0; - const request = spec.buildRequests([bid], {})[0]; - const impression = extractPayload(request).imp[0]; - - expect(impression.video.protocols[0]).to.equal(6); - expect(impression.video.api).to.equal(2); - expect(impression.video.pos).to.equal(0); - expect(impression.video.mimes[0]).to.equal('video/mp4'); - }); - - it('should send gpid in request if ortb2Imp.ext.gpid exists', function () { - const GPID = '/19968336/some-adunit-path'; - const validBids = utils.deepClone(DEFAULT_VIDEO_VALID_BID); - validBids[0].ortb2Imp = { - ext: { - gpid: GPID - } - }; - const requests = spec.buildRequests(validBids, DEFAULT_OPTION); - const { ext: { gpid } } = extractPayload(requests[0]).imp[0]; - expect(gpid).to.equal(GPID); - }); - - it('should build video request when if video obj is not provided at params level', () => { - const request = spec.buildRequests([DEFAULT_VIDEO_VALID_BID_NO_VIDEO_PARAMS[0]], {}); - const videoImpression = extractPayload(request[0]).imp[0]; - - expect(videoImpression.id).to.equal(DEFAULT_VIDEO_VALID_BID_NO_VIDEO_PARAMS[0].bidId); - expect(videoImpression.video.w).to.equal(DEFAULT_VIDEO_VALID_BID_NO_VIDEO_PARAMS[0].mediaTypes.video.playerSize[0][0]); - expect(videoImpression.video.h).to.equal(DEFAULT_VIDEO_VALID_BID_NO_VIDEO_PARAMS[0].mediaTypes.video.playerSize[0][1]); - }); - - it('should set different placement for floating ad units', () => { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.mediaTypes.video.context = 'outstream'; - bid.params.video.playerConfig = { - floatOnScroll: true - }; - - const request = spec.buildRequests([bid]); - const videoImpression = extractPayload(request[0]).imp[0]; - - expect(videoImpression.video.placement).to.eq(5); - }) - }); - - describe('buildRequestNative', function () { - it('should build request with expected params', function () { - const request = spec.buildRequests(DEFAULT_NATIVE_VALID_BID, DEFAULT_OPTION)[0]; - - expect(request.data).to.exist; - expect(request.method).to.equal('POST') - }); - - it('should send gpid in request if ortb2Imp.ext.gpid exists', function () { - const GPID = '/19968336/some-adunit-path'; - const bids = utils.deepClone(DEFAULT_NATIVE_VALID_BID); - bids[0].ortb2Imp = { - ext: { - gpid: GPID - } - }; - const requests = spec.buildRequests(bids, DEFAULT_OPTION); - const { ext: { gpid } } = extractPayload(requests[0]).imp[0]; - expect(gpid).to.equal(GPID); - }); - - it('should build request with required asset properties with default values', function () { - const request = spec.buildRequests(DEFAULT_NATIVE_VALID_BID, DEFAULT_OPTION); - const nativeImpression = extractPayload(request[0]).imp[0]; - - expect(request[0].data.hasOwnProperty('v')).to.equal(false); - expect(nativeImpression.id).to.equal(DEFAULT_NATIVE_VALID_BID[0].bidId); - expect(nativeImpression.native).to.deep.equal(DEFAULT_NATIVE_IMP); - }); - - it('should set imp.ext.sid for native imps if params.id exist', function () { - const bid = utils.deepClone(DEFAULT_NATIVE_VALID_BID); - bid[0].params.id = 'abc' - const request = spec.buildRequests(bid, DEFAULT_OPTION); - const nativeImpression = extractPayload(request[0]).imp[0]; - - expect(nativeImpression.id).to.equal(DEFAULT_NATIVE_VALID_BID[0].bidId); - expect(nativeImpression.ext.sid).to.equal('abc'); - }); - - it('should build request with given asset properties', function () { - const bid = utils.deepClone(DEFAULT_NATIVE_VALID_BID) - bid[0].nativeOrtbRequest = { - assets: [{ id: 0, required: 0, title: { len: 140 } }, { id: 1, required: 0, video: { mimes: ['javascript'], minduration: 10, maxduration: 60, protocols: [1] } }] - } - const request = spec.buildRequests(bid, DEFAULT_OPTION); - const nativeImpression = extractPayload(request[0]).imp[0]; - expect(nativeImpression.native).to.deep.equal({ request: '{"assets":[{"id":0,"required":0,"title":{"len":140}},{"id":1,"required":0,"video":{"mimes":["javascript"],"minduration":10,"maxduration":60,"protocols":[1]}}],"eventtrackers":[{"event":1,"methods":[1,2]}],"privacy":1}', ver: '1.2' }); - }); - - it('should build request with all possible Prebid asset properties', function () { - const bid = utils.deepClone(DEFAULT_NATIVE_VALID_BID) - bid[0].nativeOrtbRequest = { - 'ver': '1.2', - 'assets': [ - { - 'id': 0, - 'required': 0, - 'title': { - 'len': 140 - } - }, - { - 'id': 1, - 'required': 0, - 'data': { - 'type': 2 - } - }, - { - 'id': 2, - 'required': 0, - 'data': { - 'type': 10 - } - }, - { - 'id': 3, - 'required': 0, - 'data': { - 'type': 1 - } - }, - { - 'id': 4, - 'required': 0, - 'img': { - 'type': 1 - } - }, - { - 'id': 5, - 'required': 0, - 'img': { - 'type': 3 - } - }, - { - 'id': 6, - 'required': 0 - }, - { - 'id': 7, - 'required': 0, - 'data': { - 'type': 11 - } - }, - { - 'id': 8, - 'required': 0 - }, - { - 'id': 9, - 'required': 0 - }, - { - 'id': 10, - 'required': 0, - 'data': { - 'type': 12 - } - }, - { - 'id': 11, - 'required': 0, - 'data': { - 'type': 3 - } - }, - { - 'id': 12, - 'required': 0, - 'data': { - 'type': 5 - } - }, - { - 'id': 13, - 'required': 0, - 'data': { - 'type': 4 - } - }, - { - 'id': 14, - 'required': 0, - 'data': { - 'type': 6 - } - }, - { - 'id': 15, - 'required': 0, - 'data': { - 'type': 7 - } - }, - { - 'id': 16, - 'required': 0, - 'data': { - 'type': 9 - } - }, - { - 'id': 17, - 'required': 0, - 'data': { - 'type': 8 - } - } - ] - } - const request = spec.buildRequests(bid, DEFAULT_OPTION); - const nativeImpression = extractPayload(request[0]).imp[0]; - expect(nativeImpression.native).to.deep.equal({ request: '{"ver":"1.2","assets":[{"id":0,"required":0,"title":{"len":140}},{"id":1,"required":0,"data":{"type":2}},{"id":2,"required":0,"data":{"type":10}},{"id":3,"required":0,"data":{"type":1}},{"id":4,"required":0,"img":{"type":1}},{"id":5,"required":0,"img":{"type":3}},{"id":6,"required":0},{"id":7,"required":0,"data":{"type":11}},{"id":8,"required":0},{"id":9,"required":0},{"id":10,"required":0,"data":{"type":12}},{"id":11,"required":0,"data":{"type":3}},{"id":12,"required":0,"data":{"type":5}},{"id":13,"required":0,"data":{"type":4}},{"id":14,"required":0,"data":{"type":6}},{"id":15,"required":0,"data":{"type":7}},{"id":16,"required":0,"data":{"type":9}},{"id":17,"required":0,"data":{"type":8}}],"eventtrackers":[{"event":1,"methods":[1,2]}],"privacy":1}', ver: '1.2' }); - }) - }); - - describe('buildRequestMultiFormat', function () { - it('only banner bidder params set', function () { - const request = spec.buildRequests(DEFAULT_MULTIFORMAT_BANNER_VALID_BID, {}) - const bannerImpression = extractPayload(request[0]).imp[0]; - expect(extractPayload(request[0]).imp).to.have.lengthOf(1); - expect(bannerImpression.id).to.equal(DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0].bidId); - expect(bannerImpression.banner.format[0].w).to.equal(DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0].params.size[0]); - expect(bannerImpression.banner.format[0].h).to.equal(DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0].params.size[1]); - }); - - describe('only video bidder params set', function () { - it('should generate video impression', function () { - const request = spec.buildRequests(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID, {}); - const videoImp = extractPayload(request[1]).imp[0]; - expect(extractPayload(request[1]).imp).to.have.lengthOf(1); - expect(videoImp.id).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].bidId); - expect(videoImp.video.w).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].params.size[0]); - expect(videoImp.video.h).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].params.size[1]); - }); - }); - - describe('both banner and video bidder params set', function () { - const bids = [DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0], DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0]]; - let request; - before(() => { - request = spec.buildRequests(bids, {}); - }) - - it('should return valid banner requests', function () { - const impressions = extractPayload(request[0]).imp; - - expect(impressions).to.have.lengthOf(2); - - impressions.map((impression, index) => { - const bid = bids[index]; - - expect(impression.id).to.equal(bid.bidId); - expect(impression.banner.format).to.be.length(bid.mediaTypes.banner.sizes.length); - expect(impression.banner.topframe).to.be.oneOf([0, 1]); - - impression.banner.format.map(({ w, h, ext }, index) => { - const size = bid.mediaTypes.banner.sizes[index]; - - expect(w).to.equal(size[0]); - expect(h).to.equal(size[1]); - expect(ext.siteID).to.equal(bid.params.siteId); - }); - }); - }); - - it('should return valid banner and video requests', function () { - const videoImpression = extractPayload(request[1]).imp[0]; - - expect(extractPayload(request[1]).imp).to.have.lengthOf(1); - expect(videoImpression.id).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].bidId); - expect(videoImpression.video.w).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].mediaTypes.video.playerSize[0][0]); - expect(videoImpression.video.h).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].mediaTypes.video.playerSize[0][1]); - }); - - it('should contain all correct IXdiag properties', function () { - const diagObj = extractPayload(request[0]).ext.ixdiag; - expect(diagObj.iu).to.equal(0); - expect(diagObj.nu).to.equal(0); - expect(diagObj.ou).to.equal(2); - expect(diagObj.ren).to.equal(true); - expect(diagObj.mfu).to.equal(2); - expect(diagObj.allu).to.equal(2); - expect(diagObj.version).to.equal('$prebid.version$'); - expect(diagObj.url).to.equal('http://localhost:9876/context.html') - expect(diagObj.tagid).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].params.tagId) - expect(diagObj.adunitcode).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].adUnitCode) - }); - }); - - describe('siteId overrides', function () { - it('should use siteId override', function () { - const validBids = DEFAULT_MULTIFORMAT_VALID_BID; - const request = spec.buildRequests(validBids, {}); - const bannerImps = request[0].data.imp[0]; - const videoImps = request[1].data.imp[0]; - const nativeImps = request[2].data.imp[0]; - expect(videoImps.ext.siteID).to.equal('1111'); - bannerImps.banner.format.map(({ ext }) => { - expect(ext.siteID).to.equal('2222'); - }); - expect(nativeImps.ext.siteID).to.equal('3333'); - }); - - it('should use default siteId if overrides are not provided', function () { - const validBids = DEFAULT_MULTIFORMAT_VALID_BID; - delete validBids[0].params.banner; - delete validBids[0].params.video; - delete validBids[0].params.native; - const request = spec.buildRequests(validBids, {}); - const bannerImps = request[0].data.imp[0]; - const videoImps = request[1].data.imp[0]; - const nativeImps = request[2].data.imp[0]; - expect(videoImps.ext.siteID).to.equal('456'); - bannerImps.banner.format.map(({ ext }) => { - expect(ext.siteID).to.equal('456'); - }); - expect(nativeImps.ext.siteID).to.equal('456'); - }); - }); - }); - - describe('buildRequestFledge', function () { - it('impression should have ae=1 in ext when fledge module is enabled and ae is set in ad unit', function () { - const bidderRequest = deepClone(DEFAULT_OPTION_FLEDGE_ENABLED); - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED[0]); - const requestBidFloor = spec.buildRequests([bid], bidderRequest)[0]; - const impression = extractPayload(requestBidFloor).imp[0]; - - expect(impression.ext.ae).to.equal(1); - }); - - it('impression should have ae=1 in ext when request has paapi.enabled = true and ext.ae = 1', function () { - const bidderRequest = deepClone(DEFAULT_OPTION_FLEDGE_ENABLED); - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED[0]); - const requestBidFloor = spec.buildRequests([bid], bidderRequest)[0]; - const impression = extractPayload(requestBidFloor).imp[0]; - - expect(impression.ext.ae).to.equal(1); - }); - - it('impression should not have ae=1 in ext when fledge module is enabled globally through setConfig but overidden at ad unit level', function () { - const bidderRequest = deepClone(DEFAULT_OPTION_FLEDGE_ENABLED); - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - const requestBidFloor = spec.buildRequests([bid], bidderRequest)[0]; - const impression = extractPayload(requestBidFloor).imp[0]; - - expect(impression.ext.ae).to.be.undefined; - }); - - it('impression should not have ae=1 in ext when fledge module is disabled', function () { - const bidderRequest = deepClone(DEFAULT_OPTION); - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - const requestBidFloor = spec.buildRequests([bid], bidderRequest)[0]; - const impression = extractPayload(requestBidFloor).imp[0]; - - expect(impression.ext.ae).to.be.undefined; - }); - - it('should contain correct IXdiag ae property for Fledge', function () { - const bid = DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED[0]; - const bidderRequestWithFledgeEnabled = deepClone(DEFAULT_OPTION_FLEDGE_ENABLED); - const request = spec.buildRequests([bid], bidderRequestWithFledgeEnabled); - const diagObj = extractPayload(request[0]).ext.ixdiag; - expect(diagObj.ae).to.equal(true); - }); - - it('should log warning for non integer auction environment in ad unit for fledge', () => { - const logWarnSpy = sinon.spy(utils, 'logWarn'); - const bid = DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED[0]; - bid.ortb2Imp.ext.ae = 'malformed' - const bidderRequestWithFledgeEnabled = deepClone(DEFAULT_OPTION_FLEDGE_ENABLED); - spec.buildRequests([bid], bidderRequestWithFledgeEnabled); - expect(logWarnSpy.calledWith('error setting auction environment flag - must be an integer')).to.be.true; - logWarnSpy.restore(); - }); - - it('impression should have paapi extension when passed', function () { - const bidderRequest = deepClone(DEFAULT_OPTION_FLEDGE_ENABLED); - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED[0]); - bid.ortb2Imp.ext.ae = 1 - bid.ortb2Imp.ext.paapi = { - requestedSize: { - width: 300, - height: 250 - } - } - const requestBidFloor = spec.buildRequests([bid], bidderRequest)[0]; - const impression = extractPayload(requestBidFloor).imp[0]; - expect(impression.ext.paapi.requestedSize.width).to.equal(300); - expect(impression.ext.paapi.requestedSize.height).to.equal(250); - }); - }); - - describe('integration through exchangeId and externalId', function () { - const expectedExchangeId = 123456; - // create banner bids with externalId but no siteId as bidder param - const bannerBids = utils.deepClone(DEFAULT_BANNER_VALID_BID); - delete bannerBids[0].params.siteId; - bannerBids[0].params.externalId = 'exteranl_id_1'; - - beforeEach(() => { - config.setConfig({ exchangeId: expectedExchangeId }); - spec.resetSiteID(); - }); - - afterEach(() => { - config.resetConfig(); - }); - - it('when exchangeId and externalId set but no siteId, isBidRequestValid should return true', function () { - const bid = utils.deepClone(bannerBids[0]); - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('when neither exchangeId nor siteId set, isBidRequestValid should return false', function () { - config.resetConfig(); - const bid = utils.deepClone(bannerBids[0]); - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('when exchangeId and externalId set with banner impression but no siteId, bidrequest sent to endpoint with p param and externalID inside imp.ext', function () { - const requests = spec.buildRequests(bannerBids, DEFAULT_OPTION); - const payload = extractPayload(requests[0]); - - const expectedURL = IX_SECURE_ENDPOINT + '?p=' + expectedExchangeId; - expect(requests[0].url).to.equal(expectedURL); - expect(payload.imp[0].ext.externalID).to.equal(bannerBids[0].params.externalId); - expect(payload.imp[0].banner.format[0].ext).to.be.undefined; - expect(payload.imp[0].ext.siteID).to.be.undefined; - }); - - it('when exchangeId and externalId set with video impression, bidrequest sent to endpoint with p param and externalID inside imp.ext', function () { - const validBids = utils.deepClone(DEFAULT_VIDEO_VALID_BID); - delete validBids[0].params.siteId; - validBids[0].params.externalId = 'exteranl_id_1'; - - const requests = spec.buildRequests(validBids, DEFAULT_OPTION); - const payload = extractPayload(requests[0]); - - const expectedURL = IX_SECURE_ENDPOINT + '?p=' + expectedExchangeId; - expect(requests[0].url).to.equal(expectedURL); - expect(payload.imp[0].ext.externalID).to.equal(validBids[0].params.externalId); - expect(payload.imp[0].ext.siteID).to.be.undefined; - }); - - it('when exchangeId and externalId set beside siteId, bidrequest sent to endpoint with both p param and s param and externalID inside imp.ext and siteID inside imp.banner.format.ext', function () { - bannerBids[0].params.siteId = '1234'; - const requests = spec.buildRequests(bannerBids, DEFAULT_OPTION); - const payload = extractPayload(requests[0]); - - const expectedURL = IX_SECURE_ENDPOINT + '?s=' + bannerBids[0].params.siteId + '&p=' + expectedExchangeId; - expect(requests[0].url).to.equal(expectedURL); - expect(payload.imp[0].ext.externalID).to.equal(bannerBids[0].params.externalId); - expect(payload.imp[0].banner.format[0].ext.externalID).to.be.undefined; - expect(payload.imp[0].ext.siteID).to.be.undefined; - expect(payload.imp[0].banner.format[0].ext.siteID).to.equal(bannerBids[0].params.siteId); - }); - - it('when exchangeId and siteId set, but no externalId, bidrequest sent to exchange', function () { - bannerBids[0].params.siteId = '1234'; - delete bannerBids[0].params.externalId; - const requests = spec.buildRequests(bannerBids, DEFAULT_OPTION); - const payload = extractPayload(requests[0]); - - const expectedURL = IX_SECURE_ENDPOINT + '?s=' + bannerBids[0].params.siteId + '&p=' + expectedExchangeId; - expect(requests[0].url).to.equal(expectedURL); - expect(payload.imp[0].ext.externalID).to.be.undefined; - expect(payload.imp[0].banner.format[0].ext.siteID).to.equal(bannerBids[0].params.siteId); - }); - }); - - describe('interpretResponse', function () { - // generate bidderRequest with real buildRequest logic for intepretResponse testing - let bannerBidderRequest - let videoBidderRequest - let nativeBidderRequest - - beforeEach(() => { - bannerBidderRequest = spec.buildRequests(DEFAULT_BANNER_VALID_BID, {})[0] - videoBidderRequest = spec.buildRequests(DEFAULT_VIDEO_VALID_BID_MEDIUM_SIZE, {})[0] - nativeBidderRequest = spec.buildRequests(DEFAULT_NATIVE_VALID_BID, {})[0] - }); - - it('should get correct bid response for banner ad', function () { - const expectedParse = [ - { - requestId: '1a2b3c4d', - cpm: 1, - creativeId: '12345', - width: 300, - height: 250, - mediaType: 'banner', - ad: '', - currency: 'USD', - ttl: 300, - netRevenue: true, - meta: { - networkId: 50, - brandId: 303325, - brandName: 'OECTA', - advertiserDomains: ['www.abc.com'] - }, - ext: { - ibv: true - } - } - ]; - const result = spec.interpretResponse({ body: DEFAULT_BANNER_BID_RESPONSE }, bannerBidderRequest); - expect(result[0]).to.deep.equal(expectedParse[0]); - }); - - it('should get correct bid response for banner ad with dsa signals', function () { - const expectedParse = [ - { - requestId: '1a2b3c4d', - cpm: 1, - creativeId: '12345', - width: 300, - height: 250, - mediaType: 'banner', - ad: '', - currency: 'USD', - ttl: 300, - netRevenue: true, - meta: { - networkId: 50, - brandId: 303325, - brandName: 'OECTA', - advertiserDomains: ['www.abc.com'], - dsa: { - behalf: 'Advertiser', - paid: 'Advertiser', - transparency: [{ - domain: 'dsp1domain.com', - dsaparams: [1, 2] - }], - 'adrender': 1 - } - } - } - ]; - const result = spec.interpretResponse({ body: DEFAULT_BANNER_BID_RESPONSE_WITH_DSA }, bannerBidderRequest); - expect(result[0]).to.deep.equal(expectedParse[0]); - }); - - it('should get correct bid response for banner ad with missing adomain', function () { - const expectedParse = [ - { - requestId: '1a2b3c4d', - cpm: 1, - creativeId: '12345', - width: 300, - height: 250, - mediaType: 'banner', - ad: '', - currency: 'USD', - ttl: 300, - netRevenue: true, - meta: { - networkId: 50, - brandId: 303325, - brandName: 'OECTA' - } - } - ]; - const result = spec.interpretResponse({ body: DEFAULT_BANNER_BID_RESPONSE_WITHOUT_ADOMAIN }, bannerBidderRequest); - expect(result[0]).to.deep.equal(expectedParse[0]); - }); - - it('should set creativeId to default value if not provided', function () { - const bidResponse = utils.deepClone(DEFAULT_BANNER_BID_RESPONSE); - delete bidResponse.seatbid[0].bid[0].crid; - const expectedParse = [ - { - requestId: '1a2b3c4d', - cpm: 1, - creativeId: '-', - width: 300, - height: 250, - mediaType: 'banner', - ad: '', - currency: 'USD', - ttl: 300, - netRevenue: true, - meta: { - networkId: 50, - brandId: 303325, - brandName: 'OECTA', - advertiserDomains: ['www.abc.com'] - } - } - ]; - const result = spec.interpretResponse({ body: bidResponse }, bannerBidderRequest); - }); - - it('should set Japanese price correctly', function () { - const bidResponse = utils.deepClone(DEFAULT_BANNER_BID_RESPONSE); - bidResponse.cur = 'JPY'; - const expectedParse = [ - { - requestId: '1a2b3c4d', - cpm: 100, - creativeId: '12345', - width: 300, - height: 250, - mediaType: 'banner', - ad: '', - currency: 'JPY', - ttl: 300, - netRevenue: true, - meta: { - networkId: 50, - brandId: 303325, - brandName: 'OECTA', - advertiserDomains: ['www.abc.com'] - }, - ext: { - ibv: true - } - } - ]; - const result = spec.interpretResponse({ body: bidResponse }, bannerBidderRequest); - expect(result[0]).to.deep.equal(expectedParse[0]); - }); - - it('should prioritize bid[].dealid over bid[].ext.dealid ', function () { - const bidResponse = utils.deepClone(DEFAULT_BANNER_BID_RESPONSE); - bidResponse.seatbid[0].bid[0].ext.dealid = 'ext-deal'; - bidResponse.seatbid[0].bid[0].dealid = 'outter-deal'; - const expectedParse = [ - { - requestId: '1a2b3c4d', - cpm: 1, - creativeId: '12345', - width: 300, - height: 250, - mediaType: 'banner', - ad: '', - currency: 'USD', - ttl: 300, - netRevenue: true, - dealId: 'outter-deal', - meta: { - networkId: 50, - brandId: 303325, - brandName: 'OECTA', - advertiserDomains: ['www.abc.com'] - } - } - ]; - const result = spec.interpretResponse({ body: bidResponse }, bannerBidderRequest); - - expect(result[0].dealId).to.equal(expectedParse[0].dealId); - }); - - it('should not set bid[].dealid if dealid is not present', function () { - const bidResponse = utils.deepClone(DEFAULT_BANNER_BID_RESPONSE); - const expectedParse = [ - { - requestId: '1a2b3c4d', - cpm: 1, - creativeId: '12345', - width: 300, - height: 250, - mediaType: 'banner', - ad: '', - currency: 'USD', - ttl: 300, - netRevenue: true, - meta: { - networkId: 50, - brandId: 303325, - brandName: 'OECTA', - advertiserDomains: ['www.abc.com'] - }, - ext: { - ibv: true - } - } - ]; - const result = spec.interpretResponse({ body: bidResponse }, bannerBidderRequest); - expect(result[0]).to.deep.equal(expectedParse[0]); - }); - - it('should use set bid[].ext.dealid if bid[].dealid is not present', function () { - const bidResponse = utils.deepClone(DEFAULT_BANNER_BID_RESPONSE); - bidResponse.seatbid[0].bid[0].ext.dealid = 'ext-deal'; - const expectedParse = [ - { - requestId: '1a2b3c4d', - cpm: 1, - creativeId: '12345', - width: 300, - height: 250, - mediaType: 'banner', - ad: '', - currency: 'USD', - ttl: 300, - dealId: 'ext-deal', - netRevenue: true, - meta: { - networkId: 50, - brandId: 303325, - brandName: 'OECTA', - advertiserDomains: ['www.abc.com'] - } - } - ]; - const result = spec.interpretResponse({ body: bidResponse }, bannerBidderRequest); - expect(result[0].dealId).to.deep.equal(expectedParse[0].dealId); - }); - - it('should get correct bid response for video ad', function () { - const expectedParse = [ - { - requestId: '1a2b3c4e', - cpm: 1.1, - creativeId: '12346', - mediaType: 'video', - mediaTypes: { - video: { - context: 'instream', - playerSize: [ - [ - 400, - 100 - ] - ] - } - }, - width: 640, - height: 480, - currency: 'USD', - ttl: 3600, - netRevenue: true, - vastUrl: 'www.abcd.com/vast', - meta: { - networkId: 51, - brandId: 303326, - brandName: 'OECTB', - advertiserDomains: ['www.abcd.com'] - } - } - ]; - const result = spec.interpretResponse({ body: DEFAULT_VIDEO_BID_RESPONSE }, { - data: videoBidderRequest.data, validBidRequests: ONE_VIDEO - }); - - expect(result[0]).to.deep.equal(expectedParse[0]); - }); - - it('should set bid[].renderer if renderer not defined at mediaType.video level', function () { - const bid = spec.interpretResponse({ body: DEFAULT_VIDEO_BID_RESPONSE }, { - data: videoBidderRequest.data, validBidRequests: DEFAULT_MULTIFORMAT_BANNER_VALID_BID - }); - expect(bid[0].renderer).to.exist; - }); - - it('should set renderer URL by parsing video response', function () { - const bid = spec.interpretResponse({ body: DEFAULT_VIDEO_BID_RESPONSE }, { - data: videoBidderRequest.data, validBidRequests: DEFAULT_MULTIFORMAT_BANNER_VALID_BID - }); - expect(bid[0].renderer.url).to.equal(DEFAULT_VIDEO_BID_RESPONSE.ext.videoplayerurl); - }); - - it('should not set bid[].renderer if renderer defined at mediaType.video level', function () { - const outstreamAdUnit = utils.deepClone(DEFAULT_MULTIFORMAT_BANNER_VALID_BID); - outstreamAdUnit[0].mediaTypes.video.renderer = { - url: 'test', - render: function () { } - }; - const bid = spec.interpretResponse({ body: DEFAULT_VIDEO_BID_RESPONSE }, { - data: videoBidderRequest.data, validBidRequests: outstreamAdUnit - }); - expect(bid[0].renderer).to.be.undefined; - }); - - it('should not set bid[].renderer if renderer defined at the ad unit level', function () { - const outstreamAdUnit = utils.deepClone(DEFAULT_MULTIFORMAT_BANNER_VALID_BID); - outstreamAdUnit[0].renderer = { - url: 'test', - render: function () { } - }; - const bid = spec.interpretResponse({ body: DEFAULT_VIDEO_BID_RESPONSE }, { - data: videoBidderRequest.data, validBidRequests: outstreamAdUnit - }); - expect(bid[0].renderer).to.be.undefined; - }); - - it('should set bid[].renderer if ad unit renderer is invalid', function () { - const outstreamAdUnit = utils.deepClone(DEFAULT_MULTIFORMAT_BANNER_VALID_BID); - outstreamAdUnit[0].mediaTypes.video.renderer = { - url: 'test' - }; - const bid = spec.interpretResponse({ body: DEFAULT_VIDEO_BID_RESPONSE }, { - data: videoBidderRequest.data, validBidRequests: outstreamAdUnit - }); - expect(bid[0].renderer).to.exist; - }); - - it('should set bid[].renderer if ad unit renderer is a backup', function () { - const outstreamAdUnit = utils.deepClone(DEFAULT_MULTIFORMAT_BANNER_VALID_BID); - outstreamAdUnit[0].mediaTypes.video.renderer = { - url: 'test', - render: function () { }, - backupOnly: true - }; - const bid = spec.interpretResponse({ body: DEFAULT_VIDEO_BID_RESPONSE }, { - data: videoBidderRequest.data, validBidRequests: outstreamAdUnit - }); - expect(bid[0].renderer).to.exist; - }); - - it('should get correct bid response for video ad and set bid.vastXml when mtype is 2 (video)', function () { - const expectedParse = [ - { - requestId: '1a2b3c4e', - cpm: 1.1, - creativeId: '12346', - mediaType: 'video', - mediaTypes: { - video: { - context: 'instream', - playerSize: [ - [ - 400, - 100 - ] - ] - } - }, - width: 640, - height: 480, - currency: 'USD', - ttl: 3600, - netRevenue: true, - vastXml: ' Test In-Stream Video blah' - } - } - ], - 'eventtrackers': [ - { - 'event': 1, - 'method': 1, - 'url': 'https://impression-europe.liftoff.io/index/impression' - }, - { - 'event': 1, - 'method': 1, - 'url': 'https://a701.casalemedia.com/impression/v1' - } - ], - 'link': { - 'clicktrackers': [ - 'https://click.liftoff.io/v1/campaign_click/blah' - ], - 'url': 'https://play.google.com/store/apps/details?id=de.autodoc.gmbh' - }, - 'privacy': 'https://privacy.link.com', - 'ver': '1.2' - } - }, - ttl: 3600 - } - ]; - const result = spec.interpretResponse({ body: DEFAULT_NATIVE_BID_RESPONSE }, nativeBidderRequest); - expect(result[0]).to.deep.equal(expectedParse[0]); - }); - - describe('Auction config response', function () { - let bidderRequestWithFledgeEnabled; - let serverResponseWithoutFledgeConfigs; - let serverResponseWithFledgeConfigs; - let serverResponseWithMalformedAuctionConfig; - let serverResponseWithMalformedAuctionConfigs; - - beforeEach(() => { - bidderRequestWithFledgeEnabled = spec.buildRequests(DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED, {})[0]; - bidderRequestWithFledgeEnabled.paapi = {enabled: true}; - - serverResponseWithoutFledgeConfigs = { - body: { - ...DEFAULT_BANNER_BID_RESPONSE - } - }; - - serverResponseWithFledgeConfigs = { - body: { - ...DEFAULT_BANNER_BID_RESPONSE, - ext: { - protectedAudienceAuctionConfigs: [ - { - bidId: '59f219e54dc2fc', - config: { - seller: 'https://seller.test.indexexchange.com', - decisionLogicUrl: 'https://seller.test.indexexchange.com/decision-logic.js', - interestGroupBuyers: ['https://buyer.test.indexexchange.com'], - sellerSignals: { - callbackURL: 'https://test.com/ig/v1/ck74j8bcvc9c73a8eg6g' - }, - perBuyerSignals: { - 'https://buyer.test.indexexchange.com': {} - } - } - } - ] - } - } - }; - - serverResponseWithMalformedAuctionConfig = { - body: { - ...DEFAULT_BANNER_BID_RESPONSE, - ext: { - protectedAudienceAuctionConfigs: ['malformed'] - } - } - }; - - serverResponseWithMalformedAuctionConfigs = { - body: { - ...DEFAULT_BANNER_BID_RESPONSE, - ext: { - protectedAudienceAuctionConfigs: 'malformed' - } - } - }; - }); - - it('should correctly interpret response with auction configs', () => { - const result = spec.interpretResponse(serverResponseWithFledgeConfigs, bidderRequestWithFledgeEnabled); - const expectedOutput = [ - { - bidId: '59f219e54dc2fc', - config: { - ...serverResponseWithFledgeConfigs.body.ext.protectedAudienceAuctionConfigs[0].config, - perBuyerSignals: { - 'https://buyer.test.indexexchange.com': {} - } - } - } - ]; - expect(result.paapi).to.deep.equal(expectedOutput); - }); - - it('should correctly interpret response without auction configs', () => { - const result = spec.interpretResponse(serverResponseWithoutFledgeConfigs, bidderRequestWithFledgeEnabled); - expect(result.paapi).to.be.undefined; - }); - - it('should handle malformed auction configs gracefully', () => { - const result = spec.interpretResponse(serverResponseWithMalformedAuctionConfig, bidderRequestWithFledgeEnabled); - expect(result.paapi).to.be.empty; - }); - - it('should log warning for malformed auction configs', () => { - const logWarnSpy = sinon.spy(utils, 'logWarn'); - spec.interpretResponse(serverResponseWithMalformedAuctionConfig, bidderRequestWithFledgeEnabled); - expect(logWarnSpy.calledWith('Malformed auction config detected:', 'malformed')).to.be.true; - logWarnSpy.restore(); - }); - - it('should return bids when protected audience auction conigs is malformed', () => { - const result = spec.interpretResponse(serverResponseWithMalformedAuctionConfigs, bidderRequestWithFledgeEnabled); - expect(result.paapi).to.be.undefined; - expect(result.length).to.be.greaterThan(0); - }); - }); - - describe('interpretResponse when server response is empty', function() { - let serverResponseWithoutBody; - let serverResponseWithoutSeatbid; - let bidderRequestWithFledgeEnabled; - let bidderRequestWithoutFledgeEnabled; - - beforeEach(() => { - serverResponseWithoutBody = {}; - - serverResponseWithoutSeatbid = { - body: {} - }; - - bidderRequestWithFledgeEnabled = spec.buildRequests(DEFAULT_BANNER_VALID_BID_WITH_FLEDGE_ENABLED, {})[0]; - bidderRequestWithFledgeEnabled.paapi = {enabled: true}; - - bidderRequestWithoutFledgeEnabled = spec.buildRequests(DEFAULT_BANNER_VALID_BID, {})[0]; - }); - - it('should return empty bids when response does not have body', function () { - let result = spec.interpretResponse(serverResponseWithoutBody, bidderRequestWithFledgeEnabled); - expect(result).to.deep.equal([]); - result = spec.interpretResponse(serverResponseWithoutBody, bidderRequestWithoutFledgeEnabled); - expect(result).to.deep.equal([]); - }); - - it('should return empty bids when response body does not have seatbid', function () { - let result = spec.interpretResponse(serverResponseWithoutSeatbid, bidderRequestWithFledgeEnabled); - expect(result).to.deep.equal([]); - result = spec.interpretResponse(serverResponseWithoutSeatbid, bidderRequestWithoutFledgeEnabled); - expect(result).to.deep.equal([]); - }); - }); - }); - - describe('bidrequest consent', function () { - it('should have consent info if gdprApplies and consentString exist', function () { - const validBidWithConsent = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION); - const requestWithConsent = extractPayload(validBidWithConsent[0]); - - expect(requestWithConsent.regs.ext.gdpr).to.equal(1); - expect(requestWithConsent.user.ext.consent).to.equal('3huaa11=qu3198ae'); - }); - - it('should not have consent field if consentString is undefined', function () { - const options = { - gdprConsent: { - gdprApplies: true, - vendorData: {} - } - }; - const validBidWithConsent = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options); - const requestWithConsent = extractPayload(validBidWithConsent[0]); - - expect(requestWithConsent.regs.ext.gdpr).to.equal(1); - expect(requestWithConsent.user).to.be.undefined; - }); - - it('should not have gdpr field if gdprApplies is undefined', function () { - const options = { - gdprConsent: { - consentString: '3huaa11=qu3198ae', - vendorData: {} - } - }; - const validBidWithConsent = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options); - const requestWithConsent = extractPayload(validBidWithConsent[0]); - - expect(requestWithConsent.regs).to.be.undefined; - expect(requestWithConsent.user.ext.consent).to.equal('3huaa11=qu3198ae'); - }); - - it('should not have consent info if options.gdprConsent is undefined', function () { - const options = {}; - const validBidWithConsent = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options); - const requestWithConsent = extractPayload(validBidWithConsent[0]); - - expect(requestWithConsent.regs).to.be.undefined; - expect(requestWithConsent.user).to.be.undefined; - }); - - it('should have us_privacy if uspConsent is defined', function () { - const options = { - uspConsent: '1YYN' - }; - const validBidWithUspConsent = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options); - const requestWithUspConsent = extractPayload(validBidWithUspConsent[0]); - - expect(requestWithUspConsent.regs.ext.us_privacy).to.equal('1YYN'); - }); - - it('should not have us_privacy if uspConsent undefined', function () { - const options = {}; - const validBidWithUspConsent = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options); - const requestWithUspConsent = extractPayload(validBidWithUspConsent[0]); - - expect(requestWithUspConsent.regs).to.be.undefined; - }); - - it('should have both gdpr and us_privacy if both are defined', function () { - const options = { - gdprConsent: { - gdprApplies: true, - vendorData: {} - }, - uspConsent: '1YYN' - }; - const validBidWithConsent = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options); - const requestWithConsent = extractPayload(validBidWithConsent[0]); - expect(requestWithConsent.regs.ext.gdpr).to.equal(1); - expect(requestWithConsent.regs.ext.us_privacy).to.equal('1YYN'); - }); - - it('should contain `consented_providers_settings.addtl_consent` & consent on user.ext when both are provided', function () { - const options = { - gdprConsent: { - consentString: '3huaa11=qu3198ae', - addtlConsent: '1~1.35.41.101', - } - }; - - const validBidWithConsent = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options); - const requestWithConsent = extractPayload(validBidWithConsent[0]); - expect(requestWithConsent.user.ext.consented_providers_settings.addtl_consent).to.equal('1~1.35.41.101'); - expect(requestWithConsent.user.ext.consent).to.equal('3huaa11=qu3198ae'); - }); - - it('should not contain `consented_providers_settings.addtl_consent` on user.ext when consent is not provided', function () { - const options = { - gdprConsent: { - addtlConsent: '1~1.35.41.101', - } - }; - - const validBidWithConsent = spec.buildRequests(DEFAULT_BANNER_VALID_BID, options); - const requestWithConsent = extractPayload(validBidWithConsent[0]); - expect(utils.deepAccess(requestWithConsent, 'user.ext.consented_providers_settings.addtl_consent')).to.not.exist; - expect(utils.deepAccess(requestWithConsent, 'user.ext.consent')).to.not.exist; - }); - - it('should set coppa to 1 in config when enabled', () => { - config.setConfig({ coppa: true }) - const bid = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION); - const r = extractPayload(bid[0]); - - expect(r.regs.coppa).to.equal(1); - }); - it('should not set coppa in config when disabled', () => { - config.setConfig({ coppa: false }) - const bid = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION); - const r = extractPayload(bid[0]); - - expect(r.regs.coppa).to.be.undefined; - }); - it('should not set coppa when not specified in config', () => { - config.resetConfig(); - const bid = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION); - const r = extractPayload(bid[0]); - - expect(r.regs.coppa).to.be.undefined; - }); - }); - - describe('Features', () => { - let localStorageValues = {}; - let sandbox = sinon.createSandbox(); - let setDataInLocalStorageStub; - let getDataFromLocalStorageStub; - let removeDataFromLocalStorageStub; - const serverResponse = { - body: { - ext: { - features: { - test: { - activated: false - } - } - } - } - }; - - beforeEach(() => { - localStorageValues = {}; - sandbox = sinon.createSandbox(); - setDataInLocalStorageStub = sandbox.stub(storage, 'setDataInLocalStorage').callsFake((key, value) => localStorageValues[key] = value); - getDataFromLocalStorageStub = sandbox.stub(storage, 'getDataFromLocalStorage').callsFake((key) => localStorageValues[key]); - removeDataFromLocalStorageStub = sandbox.stub(storage, 'removeDataFromLocalStorage').callsFake((key) => delete localStorageValues[key]); - }); - - afterEach(() => { - setDataInLocalStorageStub.restore(); - getDataFromLocalStorageStub.restore(); - removeDataFromLocalStorageStub.restore(); - serverResponse.body.ext.features = { - test: { - activated: false - } - }; - localStorageValues = {}; - sandbox.restore(); - }); - - it('should store features in internal cache', () => { - FEATURE_TOGGLES.setFeatureToggles(serverResponse); - expect(FEATURE_TOGGLES.isFeatureEnabled('test')).to.be.false; - }); - - it('should retrieve features from internal cache', () => { - const feature = { - ext: { - features: { - test: { - activated: true - } - } - } - } - FEATURE_TOGGLES.setFeatureToggles(feature); - feature.ext.features.test.activated = false; - FEATURE_TOGGLES.featureToggles = { - features: feature.ext.features - }; - expect(FEATURE_TOGGLES.isFeatureEnabled('test')).to.be.false; - }); - - it('should store features in localstorage when enabled', () => { - sandbox.stub(storage, 'localStorageIsEnabled').returns(true); - serverResponse.body.ext.features.test.activated = true; - FEATURE_TOGGLES.setFeatureToggles(serverResponse); - - const lsData = JSON.parse(storage.getDataFromLocalStorage(LOCAL_STORAGE_FEATURE_TOGGLES_KEY)); - expect(lsData.features.test.activated).to.be.true; - }); - - it('should retrieve features from localstorage when enabled', () => { - sandbox.stub(storage, 'localStorageIsEnabled').returns(true); - serverResponse.body.ext.features.test.activated = true; - FEATURE_TOGGLES.setFeatureToggles(serverResponse); - FEATURE_TOGGLES.featureToggles = {}; - FEATURE_TOGGLES.getFeatureToggles(LOCAL_STORAGE_FEATURE_TOGGLES_KEY); - expect(FEATURE_TOGGLES.isFeatureEnabled('test')).to.be.true; - }); - - it('should remove features from after expiry', () => { - sandbox.stub(storage, 'localStorageIsEnabled').returns(true); - const expiryTime = new Date(); - localStorageValues = { - expiry: expiryTime.setHours(expiryTime.getHours() - 2), - features: { - test: { - activated: true - } - } - } - FEATURE_TOGGLES.getFeatureToggles(LOCAL_STORAGE_FEATURE_TOGGLES_KEY); - expect(FEATURE_TOGGLES.isFeatureEnabled('test')).to.be.false; - expect(FEATURE_TOGGLES.featureToggles).to.deep.equal({}); - }); - - it('6 ad units should generate only 1 request if buildRequestV2 FT is enabled', function () { - sandbox.stub(storage, 'localStorageIsEnabled').returns(true); - serverResponse.body.ext.features.pbjs_use_buildRequestV2 = { - activated: true - }; - FEATURE_TOGGLES.setFeatureToggles(serverResponse); - - const bid1 = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid1.mediaTypes.banner.sizes = LARGE_SET_OF_SIZES; - bid1.params.siteId = '121'; - bid1.adUnitCode = 'div-gpt-1' - bid1.transactionId = 'tr1'; - bid1.bidId = '2f6g5s5e'; - - const bid2 = utils.deepClone(bid1); - bid2.transactionId = 'tr2'; - - const bid3 = utils.deepClone(bid1); - bid3.transactionId = 'tr3'; - - const bid4 = utils.deepClone(bid1); - bid4.transactionId = 'tr4'; - - const bid5 = utils.deepClone(bid1); - bid5.transactionId = 'tr5'; - - const bid6 = utils.deepClone(bid1); - bid6.transactionId = 'tr6'; - - const requests = spec.buildRequests([bid1, bid2, bid3, bid4, bid5, bid6], DEFAULT_OPTION); - - expect(requests).to.be.an('array'); - // buildRequestv2 enabled causes only 1 requests to get generated. - expect(requests).to.have.lengthOf(1); - for (const request of requests) { - expect(request.method).to.equal('POST'); - } - }); - - it('1 request with 2 ad units, buildRequestV2 enabled', function () { - sandbox.stub(storage, 'localStorageIsEnabled').returns(true); - serverResponse.body.ext.features.pbjs_use_buildRequestV2 = { - activated: true - }; - FEATURE_TOGGLES.setFeatureToggles(serverResponse); - - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - bid.mediaTypes.banner.sizes = LARGE_SET_OF_SIZES; - bid.params.siteId = '124'; - bid.adUnitCode = 'div-gpt-1' - bid.transactionId = '152e36d1-1241-4242-t35e-y1dv34d12315'; - bid.bidId = '2f6g5s5e'; - - const requests = spec.buildRequests([bid, DEFAULT_BANNER_VALID_BID[0]], DEFAULT_OPTION); - expect(requests).to.be.an('array'); - expect(requests).to.have.lengthOf(1); - }); - - it('request should have requested feature toggles when local storage is enabled', function () { - sandbox.stub(storage, 'localStorageIsEnabled').returns(true); - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - const requests = spec.buildRequests([bid, DEFAULT_BANNER_VALID_BID[0]], DEFAULT_OPTION); - const r = extractPayload(requests[0]); - expect(r.ext.features).to.exist; - expect(Object.keys(r.ext.features).length).to.equal(FEATURE_TOGGLES.REQUESTED_FEATURE_TOGGLES.length); - }); - - it('request should have requested feature toggles when local storage is not enabled', function () { - sandbox.stub(storage, 'localStorageIsEnabled').returns(false); - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - const requests = spec.buildRequests([bid, DEFAULT_BANNER_VALID_BID[0]], DEFAULT_OPTION); - const r = extractPayload(requests[0]); - expect(r.ext.features).to.exist; - expect(Object.keys(r.ext.features).length).to.equal(FEATURE_TOGGLES.REQUESTED_FEATURE_TOGGLES.length); - }); - - it('request should not have any feature toggles when there is no requested feature toggle', function () { - sandbox.stub(storage, 'localStorageIsEnabled').returns(true); - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - FEATURE_TOGGLES.REQUESTED_FEATURE_TOGGLES = [] - const requests = spec.buildRequests([bid, DEFAULT_BANNER_VALID_BID[0]], DEFAULT_OPTION); - const r = extractPayload(requests[0]); - expect(r.ext.features).to.be.undefined; - }); - - it('request should not have any feature toggles when there is no requested feature toggle and local storage not enabled', function () { - sandbox.stub(storage, 'localStorageIsEnabled').returns(false); - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - const requests = spec.buildRequests([bid, DEFAULT_BANNER_VALID_BID[0]], DEFAULT_OPTION); - const r = extractPayload(requests[0]); - FEATURE_TOGGLES.REQUESTED_FEATURE_TOGGLES = [] - expect(r.ext.features).to.be.undefined; - }); - - it('correct activation status of requested feature toggles when local storage not enabled', function () { - sandbox.stub(storage, 'localStorageIsEnabled').returns(false); - const bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - FEATURE_TOGGLES.REQUESTED_FEATURE_TOGGLES = ['test1'] - const requests = spec.buildRequests([bid, DEFAULT_BANNER_VALID_BID[0]], DEFAULT_OPTION); - const r = extractPayload(requests[0]); - expect(r.ext.features).to.deep.equal({ - [FEATURE_TOGGLES.REQUESTED_FEATURE_TOGGLES[0]]: { activated: false } - }); - }); - - it('correct activation status of requested feature toggles', function () { - sandbox.stub(storage, 'localStorageIsEnabled').returns(true); - serverResponse.body.ext.features = { - [FEATURE_TOGGLES.REQUESTED_FEATURE_TOGGLES[0]]: { - activated: true - } - } - FEATURE_TOGGLES.setFeatureToggles(serverResponse); - let bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - let requests = spec.buildRequests([bid, DEFAULT_BANNER_VALID_BID[0]], DEFAULT_OPTION); - let r = extractPayload(requests[0]); - expect(r.ext.features).to.deep.equal({ - [FEATURE_TOGGLES.REQUESTED_FEATURE_TOGGLES[0]]: { activated: true } - }); - - serverResponse.body.ext.features = { - [FEATURE_TOGGLES.REQUESTED_FEATURE_TOGGLES[0]]: { - activated: false - } - } - FEATURE_TOGGLES.setFeatureToggles(serverResponse); - bid = utils.deepClone(DEFAULT_BANNER_VALID_BID[0]); - requests = spec.buildRequests([bid, DEFAULT_BANNER_VALID_BID[0]], DEFAULT_OPTION); - r = extractPayload(requests[0]); - expect(r.ext.features).to.deep.equal({ - [FEATURE_TOGGLES.REQUESTED_FEATURE_TOGGLES[0]]: { activated: false } - }); - }); - - describe('multiformat tests with enable multiformat ft enabled', () => { - let ftStub; - let validBids; - beforeEach(() => { - ftStub = sinon.stub(FEATURE_TOGGLES, 'isFeatureEnabled').callsFake((ftName) => { - if (ftName === 'pbjs_enable_multiformat') { - return true; - } - return false; - }); - validBids = DEFAULT_MULTIFORMAT_VALID_BID; - }); - - afterEach(() => { - ftStub.restore(); - validBids = DEFAULT_MULTIFORMAT_VALID_BID; - }); - - it('banner multiformat request, should generate banner imp', () => { - const request = spec.buildRequests(DEFAULT_MULTIFORMAT_BANNER_VALID_BID, {}) - const imp = extractPayload(request[0]).imp[0]; - const bannerImpression = imp.banner - expect(request).to.have.lengthOf(1); - expect(extractPayload(request[0]).imp).to.have.lengthOf(1); - expect(imp.id).to.equal(DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0].bidId); - expect(bannerImpression.format[0].w).to.equal(DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0].params.size[0]); - expect(bannerImpression.format[0].h).to.equal(DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0].params.size[1]); - }); - it('should generate video impression', () => { - const request = spec.buildRequests(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID, {}); - const imp = extractPayload(request[0]).imp[0]; - const videoImp = imp.video - expect(request).to.have.lengthOf(1); - expect(extractPayload(request[0]).imp).to.have.lengthOf(1); - expect(imp.id).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].bidId); - expect(videoImp.w).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].params.size[0]); - expect(videoImp.h).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].params.size[1]); - }); - it('different ad units, should only have 1 request', () => { - const bids = [DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0], DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0]]; - const request = spec.buildRequests(bids, {}); - expect(request).to.have.lengthOf(1); - }); - it('should return valid banner requests', function () { - const bids = [DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0], DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0]]; - const request = spec.buildRequests(bids, {}); - const impressions = extractPayload(request[0]).imp; - expect(impressions).to.have.lengthOf(2); - - expect(impressions[0].id).to.equal(bids[0].bidId); - expect(impressions[0].banner.format).to.be.length(bids[0].mediaTypes.banner.sizes.length); - expect(impressions[0].banner.topframe).to.be.oneOf([0, 1]); - expect(impressions[0].ext.siteID).to.equal('123'); - expect(impressions[1].ext.siteID).to.equal('456'); - impressions[0].banner.format.map(({ w, h, ext }, index) => { - const size = bids[0].mediaTypes.banner.sizes[index]; - - expect(w).to.equal(size[0]); - expect(h).to.equal(size[1]); - expect(ext.siteID).to.be.undefined; - }); - - impressions[1].banner.format.map(({ w, h, ext }, index) => { - const size = bids[1].mediaTypes.banner.sizes[index]; - - expect(w).to.equal(size[0]); - expect(h).to.equal(size[1]); - expect(ext.siteID).to.be.undefined; - }); - }); - it('banner / native multiformat request, only 1 request expect 1 imp', () => { - const request = spec.buildRequests(DEFAULT_MULTIFORMAT_NATIVE_VALID_BID, {}); - expect(request).to.have.lengthOf(1); - const imp = extractPayload(request[0]).imp[0]; - expect(extractPayload(request[0]).imp).to.have.lengthOf(1); - expect(imp.banner).to.exist; - expect(imp.native).to.exist; - }); - - it('should return valid banner and video requests', function () { - const bids = [DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0], DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0]]; - const request = spec.buildRequests(bids, {}); - const videoImpression = extractPayload(request[0]).imp[1]; - - expect(extractPayload(request[0]).imp).to.have.lengthOf(2); - expect(videoImpression.id).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].bidId); - expect(videoImpression.video.w).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].mediaTypes.video.playerSize[0][0]); - expect(videoImpression.video.h).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].mediaTypes.video.playerSize[0][1]); - }); - - it('multiformat banner / video - bid floors', function () { - const bids = [DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0], DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0]]; - bids[0].params.bidFloor = 2.35; - bids[0].params.bidFloorCur = 'USD'; - const adunitcode = bids[1].adUnitCode; - bids[1].adUnitCode = bids[0].adUnitCode; - bids[1].params.bidFloor = 2.05; - bids[1].params.bidFloorCur = 'USD'; - const request = spec.buildRequests(bids, {}); - - expect(extractPayload(request[0]).imp).to.have.lengthOf(1); - expect(extractPayload(request[0]).imp[0].bidfloor).to.equal(2.05); - expect(extractPayload(request[0]).imp[0].bidfloorcur).to.equal('USD'); - expect(extractPayload(request[0]).imp[0].video.ext.bidfloor).to.equal(2.05); - expect(extractPayload(request[0]).imp[0].banner.format[0].ext.bidfloor).to.equal(2.35); - bids[1].adUnitCode = adunitcode; - }); - - it('multiformat banner / native - bid floors', function () { - const bids = [DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0], DEFAULT_MULTIFORMAT_NATIVE_VALID_BID[0]]; - bids[0].params.bidFloor = 2.35; - bids[0].params.bidFloorCur = 'USD'; - const adunitcode = bids[1].adUnitCode; - bids[1].adUnitCode = bids[0].adUnitCode; - bids[1].params.bidFloor = 2.05; - bids[1].params.bidFloorCur = 'USD'; - const request = spec.buildRequests(bids, {}); - - expect(extractPayload(request[0]).imp).to.have.lengthOf(1); - expect(extractPayload(request[0]).imp[0].bidfloor).to.equal(2.05); - expect(extractPayload(request[0]).imp[0].bidfloorcur).to.equal('USD'); - expect(extractPayload(request[0]).imp[0].native.ext.bidfloor).to.equal(2.05); - bids[1].adUnitCode = adunitcode; - }); - - it('multiformat banner / native - bid floors, banner imp less', function () { - const bids = [DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0], DEFAULT_MULTIFORMAT_NATIVE_VALID_BID[0]]; - bids[0].params.bidFloor = 2.05; - bids[0].params.bidFloorCur = 'USD'; - const adunitcode = bids[1].adUnitCode; - bids[1].adUnitCode = bids[0].adUnitCode; - bids[1].params.bidFloor = 2.35; - bids[1].params.bidFloorCur = 'USD'; - const request = spec.buildRequests(bids, {}); - - expect(extractPayload(request[0]).imp).to.have.lengthOf(1); - expect(extractPayload(request[0]).imp[0].bidfloor).to.equal(2.05); - expect(extractPayload(request[0]).imp[0].bidfloorcur).to.equal('USD'); - expect(extractPayload(request[0]).imp[0].native.ext.bidfloor).to.equal(2.35); - bids[1].adUnitCode = adunitcode; - }); - - it('should return valid banner and video requests, different adunit, creates multiimp request', function () { - const bid = DEFAULT_MULTIFORMAT_VALID_BID[0] - bid.bidId = '1abcdef' - const bids = [DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0], bid]; - const request = spec.buildRequests(bids, {}); - expect(request).to.have.lengthOf(1); - expect(extractPayload(request[0]).imp).to.have.lengthOf(2); - }); - - it('should return valid video requests, different adunit, creates multiimp request', function () { - const bid = DEFAULT_BANNER_VALID_BID[0] - bid.bidId = '1abcdef' - const bids = [DEFAULT_VIDEO_VALID_BID[0], bid]; - const request = spec.buildRequests(bids, {}); - expect(request).to.have.lengthOf(1); - expect(extractPayload(request[0]).imp).to.have.lengthOf(2); - }); - - it('should contain all correct IXdiag properties', function () { - const bids = [DEFAULT_MULTIFORMAT_BANNER_VALID_BID[0], DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0]]; - const request = spec.buildRequests(bids, {}); - const diagObj = extractPayload(request[0]).ext.ixdiag; - expect(diagObj.iu).to.equal(0); - expect(diagObj.nu).to.equal(0); - expect(diagObj.ou).to.equal(2); - expect(diagObj.ren).to.equal(true); - expect(diagObj.mfu).to.equal(2); - expect(diagObj.allu).to.equal(2); - expect(diagObj.version).to.equal('$prebid.version$'); - expect(diagObj.url).to.equal('http://localhost:9876/context.html') - expect(diagObj.tagid).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].params.tagId) - expect(diagObj.adunitcode).to.equal(DEFAULT_MULTIFORMAT_VIDEO_VALID_BID[0].adUnitCode) - }); - - it('should use siteId override for multiformat', function () { - validBids[0].params = { - tagId: '123', - siteId: '456', - size: [300, 250], - video: { - siteId: '1111' - }, - banner: { - siteId: '2222' - }, - native: { - siteId: '3333' - } - } - const request = spec.buildRequests(validBids, {}); - const imp = request[0].data.imp[0]; - expect(imp.ext.siteID).to.equal('2222'); - expect(imp.video.ext.siteID).to.be.undefined; - imp.banner.format.map(({ ext }) => { - expect(ext.siteID).to.be.undefined; - }); - expect(imp.native.ext.siteID).to.be.undefined; - }); - - it('should use default siteId if overrides are not provided for multiformat', function () { - const bids = validBids; - delete bids[0].params.banner; - delete bids[0].params.video; - delete bids[0].params.native; - const request = spec.buildRequests(bids, {}); - const imp = request[0].data.imp[0] - expect(imp.video.ext.siteID).to.be.undefined; - imp.banner.format.map(({ ext }) => { - expect(ext.siteID).to.be.undefined; - }); - expect(imp.native.ext.siteID).to.be.undefined; - expect(imp.ext.siteID).to.equal('456'); - }); - }); - }); - - describe('combine imps test', function () { - it('base test', function () { - const imps = [ - { - 'b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7': { - 'tid': 'b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7', - 'adUnitCode': 'div-gpt-v1', - 'missingImps': [ - { - 'id': '2e46cbd7d4e046', - 'ext': { - 'siteID': '12345' - }, - 'banner': { - 'w': 300, - 'h': 250, - 'topframe': 1 - } - } - ], - 'missingCount': 1 - } - }, - { - 'b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7': { - 'ixImps': [ - { - 'id': '2e46cbd7d4e046', - 'ext': { - 'siteID': '12345', - 'tid': 'b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7' - }, - 'video': { - 'skipppable': false, - 'playback_methods': [ - 'auto_play_sound_off' - ], - 'minduration': 0, - 'maxduration': 30, - 'mimes': [ - 'video/mp4', - 'video/x-flv' - ], - 'placement': 1, - 'playerSize': [ - [ - 640, - 480 - ] - ], - 'protocols': [ - 6 - ], - 'w': 640, - 'h': 480, - 'ext': { - 'siteID': '12345', - 'tid': 'b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7' - } - } - }, - ], - 'adUnitCode': 'div-gpt-v1' - } - }, - { - 'b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7': { - 'tid': 'b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7', - 'adUnitCode': 'div-gpt-v1', - 'missingImps': [ - { - 'id': '2e46cbd7d4e046', - 'ext': { - 'siteID': '12345' - }, - 'banner': { - 'w': 300, - 'h': 250, - 'topframe': 1 - } - } - ], - 'missingCount': 1 - } - } - ] - const result = combineImps(imps); - expect(result['b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7'].ixImps.length).to.equal(1) - expect(result['b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7'].missingImps.length).to.equal(2); - }); - it('switch order', function () { - const imps = [ - { - 'b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7': { - 'ixImps': [ - { - 'id': '2e46cbd7d4e046', - 'ext': { - 'siteID': '12345', - 'tid': 'b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7' - }, - 'video': { - 'skipppable': false, - 'playback_methods': [ - 'auto_play_sound_off' - ], - 'minduration': 0, - 'maxduration': 30, - 'mimes': [ - 'video/mp4', - 'video/x-flv' - ], - 'placement': 1, - 'playerSize': [ - [ - 640, - 480 - ] - ], - 'protocols': [ - 6 - ], - 'w': 640, - 'h': 480, - 'ext': { - 'siteID': '12345', - 'tid': 'b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7' - } - } - }, - ], - 'adUnitCode': 'div-gpt-v1' - } - }, - { - 'b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7': { - 'tid': 'b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7', - 'adUnitCode': 'div-gpt-v1', - 'missingImps': [ - { - 'id': '2e46cbd7d4e046', - 'ext': { - 'siteID': '12345' - }, - 'banner': { - 'w': 300, - 'h': 250, - 'topframe': 1 - } - } - ], - 'missingCount': 1 - } - } - ] - const result = combineImps(imps) - expect(result['b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7'].missingImps.length).to.equal(1); - expect(result['b8c6b5d5-76a1-4a90-b635-0c7eae1bfaa7'].ixImps.length).to.equal(1); - }); - }); - - describe('apply floors test', function () { - it('video test', function() { - const bid = utils.deepClone(DEFAULT_VIDEO_VALID_BID[0]); - bid.params.bidFloor = 50; - bid.params.bidFloorCur = 'USD'; - const imp = bidToVideoImp(bid); - expect(imp.video.ext.bidfloor).to.equal(50); - expect(imp.bidfloor).to.equal(50); - expect(imp.bidfloorcur).to.equal('USD'); - expect(imp.video.ext.fl).to.equal('x'); - }); - it('native test', function() { - const bid = utils.deepClone(DEFAULT_NATIVE_VALID_BID[0]); - bid.params.bidFloor = 50; - bid.params.bidFloorCur = 'USD'; - const imp = bidToNativeImp(bid); - expect(imp.native.ext.bidfloor).to.equal(50); - expect(imp.bidfloor).to.equal(50); - expect(imp.bidfloorcur).to.equal('USD'); - expect(imp.native.ext.fl).to.equal('x'); - }); - }); - - describe('deduplicateImpExtFields', () => { - it('should remove duplicate keys from banner.ext', () => { - const input = { - imp: [ - { - banner: { - ext: { - key1: 'value1', - key2: 'value2', - key3: 'value3', - key4: 'value4', // duplicate value - }, - }, - video: { - ext: { - key4: 'value4', // duplicate value - } - }, - ext: { - key4: 'value4' - } - }, - ], - }; - - const expectedOutput = { - imp: [ - { - banner: { - ext: { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - }, - ext: { - key4: 'value4' - }, - video: { - ext: {} - }, - }, - ], - }; - - const result = deduplicateImpExtFields(input); - expect(result).to.deep.equal(expectedOutput); - }); - - it('should remove duplicate keys from banner.format[].ext', () => { - const input = { - imp: [ - { - banner: { - format: [ - { - ext: { - key1: 'value1', - key2: 'value2', - key3: 'value3', - key4: 'value4', // duplicate value - }, - }, - ], - }, - video: { - ext: { - key4: 'value4', // duplicate value - } - }, - ext: { - key4: 'value4' - } - }, - ], - }; - - const expectedOutput = { - imp: [ - { - banner: { - format: [ - { - ext: { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - }, - ], - }, - video: { - ext: {} - }, - ext: { - key4: 'value4' - } - }, - ], - }; - - const result = deduplicateImpExtFields(input); - expect(result).to.deep.equal(expectedOutput); - }); - - it('should remove duplicate keys from video.ext', () => { - const input = { - imp: [ - { - video: { - ext: { - key1: 'value1', - key2: 'value2', - key3: 'value3', - key4: 'value4', // duplicate value - }, - }, - banner: { - ext: { - key1: 'value1', - } - }, - ext: { - key4: 'value4' - } - }, - ], - }; - - const expectedOutput = { - imp: [ - { - video: { - ext: { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - }, - banner: { - ext: { - key1: 'value1', - } - }, - ext: { - key4: 'value4' - } - }, - ], - }; - - const result = deduplicateImpExtFields(input); - expect(result).to.deep.equal(expectedOutput); - }); - - it('should remove duplicate keys from native.ext', () => { - const input = { - imp: [ - { - native: { - ext: { - key1: 'value1', - key2: 'value2', - key3: 'value3', - key4: 'value4', // duplicate value - }, - }, - banner: { - ext: { - key1: 'value1', - } - }, - ext: { - key4: 'value4' - } - }, - ], - }; - - const expectedOutput = { - imp: [ - { - native: { - ext: { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - }, - banner: { - ext: { - key1: 'value1', - } - }, - ext: { - key4: 'value4' - } - } - ], - }; - - const result = deduplicateImpExtFields(input); - expect(result).to.deep.equal(expectedOutput); - }); - - it('should return the input unchanged when there is no imp.ext', () => { - const input = { - imp: [ - { - banner: { - ext: { - key1: 'value1', - key2: 'value2', - key3: 'value3', - }, - }, - video: { - ext: { - key4: 'value4', - key5: 'value5', - key6: 'value6', - }, - }, - native: { - ext: { - key7: 'value7', - key8: 'value8', - key9: 'value9', - }, - }, - }, - ], - }; - - const result = deduplicateImpExtFields(input); - expect(result).to.deep.equal(input); - }); - }); - - describe('removeSiteIDs', () => { - it('should remove siteIDs from banner / video / native format', () => { - const request = { - imp: [ - { - banner: { - format: [ - { - ext: { - siteID: '123' - } - }, - { - ext: { - siteID: '123' - } - } - ], - ext: { - siteID: '123' - } - }, - video: { - ext: { - siteID: '123' - } - }, - native: { - ext: { - siteID: '123' - } - }, - ext: { - siteID: '123' - } - } - ] - }; - - const expected = { - ext: { - ixdiag: { - usid: true - } - }, - imp: [ - { - banner: { - format: [ - { - ext: {} - }, - { - ext: {} - } - ], - ext: {} - }, - video: { - ext: {} - }, - native: { - ext: {} - }, - ext: { - 'siteID': '123' - } - } - ] - }; - - expect(removeSiteIDs(request)).to.deep.equal(expected); - }); - - it('should not modify the request when imp.ext is not present', () => { - const request = { - imp: [ - { - banner: { - ext: { - siteID: '123' - } - } - } - ] - }; - - const expected = { - imp: [ - { - banner: { - ext: { - siteID: '123' - } - }, - } - ] - }; - - expect(removeSiteIDs(request)).to.deep.equal(expected); - }); - }); - - describe('addDeviceInfo', () => { - it('should add device to request when device already exists', () => { - let r = { - device: { - ip: '127.0.0.1' - } - } - r = addDeviceInfo(r); - expect(r.device.w).to.exist; - expect(r.device.h).to.exist; - }); - - it('should add device to request when device doesnt exist', () => { - let r = {} - r = addDeviceInfo(r); - expect(r.device.w).to.exist; - expect(r.device.h).to.exist; - }); - - it('should add device.ip if available in fpd', () => { - const ortb2 = { - device: { - ip: '192.168.1.1', - ipv6: '2001:0db8:85a3:0000:0000:8a2e:0370:7334' - }}; - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2 })[0]; - const payload = extractPayload(request); - expect(payload.device.ip).to.equal('192.168.1.1') - expect(payload.device.ipv6).to.equal('2001:0db8:85a3:0000:0000:8a2e:0370:7334') - }); - - it('should not add device.ip if neither ip nor ipv6 exists', () => { - const ortb2 = {device: {}}; - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2 })[0]; - const payload = extractPayload(request); - expect(payload.device.ip).to.be.undefined; - expect(payload.device.ip6).to.be.undefined; - }); - - it('should add device.geo if available in fpd', () => { - const ortb2 = { - device: { - geo: { - lat: 1, - lon: 2, - lastfix: 1, - type: 1 - } - } - }; - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2 })[0]; - const payload = extractPayload(request); - expect(payload.device.geo.lat).to.equal(1); - expect(payload.device.geo.lon).to.equal(2); - expect(payload.device.geo.lastfix).to.equal(1); - expect(payload.device.geo.type).to.equal(1); - }); - - it('should not add device.geo if it does not exist', () => { - const ortb2 = {device: {}}; - const request = spec.buildRequests(DEFAULT_BANNER_VALID_BID, { ortb2 })[0]; - const payload = extractPayload(request); - expect(payload.device.geo).to.be.undefined; - }); - }); - - describe('getDivIdFromAdUnitCode', () => { - it('returns adUnitCode when element exists', () => { - const adUnitCode = 'div-ad1'; - const el = document.createElement('div'); - el.id = adUnitCode; - document.body.appendChild(el); - expect(getDivIdFromAdUnitCode(adUnitCode)).to.equal(adUnitCode); - document.body.removeChild(el); - }); - - it('retrieves divId from GPT once and caches result', () => { - const adUnitCode = 'div-ad2'; - const stub = sinon.stub(gptUtils, 'getGptSlotInfoForAdUnitCode').returns({divId: 'gpt-div'}); - const first = getDivIdFromAdUnitCode(adUnitCode); - const second = getDivIdFromAdUnitCode(adUnitCode); - expect(first).to.equal('gpt-div'); - expect(second).to.equal('gpt-div'); - expect(stub.calledOnce).to.be.true; - stub.restore(); - }); - }); - - describe('fetch requests', function () { - let ajaxStub; - - beforeEach(function () { - ajaxStub = sinon.stub(ajaxLib, 'ajaxBuilder').callsFake(() => { - return sinon.spy(function (url, callback, data, options) { - callback.success('OK'); - }); - }); - }); - - afterEach(function () { - ajaxStub.restore(); - }); - - it('should send the correct headers in the actual fetch call', function (done) { - const requests = spec.buildRequests(DEFAULT_BANNER_VALID_BID, DEFAULT_OPTION); - const request = requests[0]; - const ajax = ajaxLib.ajaxBuilder(); - - ajax( - request.url, - { - success: () => { - try { - sinon.assert.calledOnce(ajaxStub); - const ajaxCall = ajaxStub.returnValues[0]; - sinon.assert.calledOnce(ajaxCall); - const [calledUrl, callback, calledData, calledOptions] = ajaxCall.getCall(0).args; - - expect(calledUrl).to.equal(request.url); - expect(calledData).to.equal(request.data); - - expect(calledOptions.contentType).to.equal('text/plain'); - expect(calledOptions.withCredentials).to.be.true; - - done(); - } catch (err) { - done(err); - } - }, - error: (err) => done(err || new Error('Ajax request failed')), - }, - request.data, - request.options - ); - }); - }); -}); diff --git a/test/spec/modules/jixieBidAdapter_spec.js b/test/spec/modules/jixieBidAdapter_spec.js deleted file mode 100644 index bd56aee71..000000000 --- a/test/spec/modules/jixieBidAdapter_spec.js +++ /dev/null @@ -1,781 +0,0 @@ -import { expect } from 'chai'; -import { spec, internal as jixieaux, storage } from 'modules/jixieBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import { deepClone } from 'src/utils.js'; - -describe('jixie Adapter', function () { - const pageurl_ = 'https://testdomain.com/testpage.html'; - const domain_ = 'https://testdomain.com'; - const device_ = 'desktop'; - const timeout_ = 1000; - const currency_ = 'USD'; - const keywords_ = ''; - - /** - * Basic - */ - const adapter = newBidder(spec); - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - /** - * isBidRequestValid - */ - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'jixie', - 'params': { - 'unit': 'prebidsampleunit' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params obj does not exist', function () { - const bid0 = Object.assign({}, bid); - delete bid0.params; - expect(spec.isBidRequestValid(bid0)).to.equal(false); - }); - - it('should return false when params obj does not contain unit property', function () { - const bid1 = Object.assign({}, bid); - bid1.params = { rubbish: '' }; - expect(spec.isBidRequestValid(bid1)).to.equal(false); - }); - });// describe - - /** - * buildRequests - */ - describe('buildRequests', function () { - const adUnitCode0_ = 'adunit-code-0'; - const adUnitCode1_ = 'adunit-code-1'; - const adUnitCode2_ = 'adunit-code-2'; - - const bidId0_ = '22a9eb5004cf082'; - const bidId1_ = '230fceb12fd754f'; - const bidId2_ = '24dbe5c4fb80ed8'; - - const bidderRequestId_ = '2131ce076eeaa1b'; - const auctionId_ = '26d68819-d6ce-4a2c-a4d3-f1a97b159d66'; - - const clientIdTest1_ = '1aba6a40-f711-11e9-868c-53a2ae972xxx'; - const sessionIdTest1_ = '1594782644-1aba6a40-f711-11e9-868c-53a2ae972xxx'; - const jxtokoTest1_ = 'eyJJRCI6ImFiYyJ9'; - const jxifoTest1_ = 'fffffbbbbbcccccaaaaae890606aaaaa'; - const jxtdidTest1_ = '222223d1-1111-2222-3333-b9f129299999'; - const jxcompTest1_ = 'AAAAABBBBBCCCCCDDDDDEEEEEUkkZPQfifpkPnnlJhtsa4o+gf4nfqgN5qHiTVX73ymTSbLT9jz1nf+Q7QdxNh9nTad9UaN5pzfHMt/rs1woQw72c1ip+8heZXPfKGZtZP7ldJesYhlo3/0FVcL/wl9ZlAo1jYOEfHo7Y9zFzNXABbbbbb=='; - const ckname1Val_ = 'ckckname1'; - const ckname2Val_ = 'ckckname2'; - const refJxEids_ = { - 'pubid1': ckname1Val_, - 'pubid2': ckname2Val_, - '_jxtoko': jxtokoTest1_, - '_jxifo': jxifoTest1_, - '_jxtdid': jxtdidTest1_, - '_jxcomp': jxcompTest1_ - }; - - // to serve as the object that prebid will call jixie buildRequest with: (param2) - const bidderRequest_ = { - refererInfo: {referer: pageurl_}, - auctionId: auctionId_, - timeout: timeout_ - }; - // to serve as the object that prebid will call jixie buildRequest with: (param1) - const bidRequests_ = [ - { - 'bidder': 'jixie', - 'params': { - 'unit': 'prebidsampleunit' - }, - 'sizes': [[300, 250], [300, 600]], - 'adUnitCode': adUnitCode0_, - 'bidId': bidId0_, - 'bidderRequestId': bidderRequestId_, - 'auctionId': auctionId_, - 'ortb2Imp': { - 'ext': { - 'gpid': 'SUPERNEWS#DESKTOP#div-gpt-ad-Top_1-1' - } - } - }, - { - 'bidder': 'jixie', - 'params': { - 'unit': 'prebidsampleunit' - }, - 'sizes': [[300, 250]], - 'mediaTypes': { - 'video': { - 'playerSize': [640, 360] - }, - 'banner': { - 'sizes': [[300, 250]] - } - }, - 'adUnitCode': adUnitCode1_, - 'bidId': bidId1_, - 'bidderRequestId': bidderRequestId_, - 'auctionId': auctionId_, - 'ortb2Imp': { - 'ext': { - 'gpid': 'SUPERNEWS#DESKTOP#div-gpt-ad-Top_1-2' - } - } - }, - { - 'bidder': 'jixie', - 'params': { - 'unit': 'prebidsampleunit' - }, - 'sizes': [[300, 250], [300, 600]], - 'mediaTypes': { - 'video': { - 'playerSize': [640, 360] - }, - 'banner': { - 'sizes': [[300, 250], [300, 600]] - } - }, - 'adUnitCode': adUnitCode2_, - 'bidId': bidId2_, - 'bidderRequestId': bidderRequestId_, - 'auctionId': auctionId_, - 'ortb2Imp': { - 'ext': { - 'gpid': 'SUPERNEWS#DESKTOP#div-gpt-ad-Top_1-3' - } - } - } - ]; - - // To serve as a reference to check against the bids array portion of the blob that the call to - // buildRequest returns - const refBids_ = [ - { - 'bidId': bidId0_, - 'adUnitCode': adUnitCode0_, - 'sizes': [[300, 250], [300, 600]], - 'params': { - 'unit': 'prebidsampleunit' - }, - 'gpid': 'SUPERNEWS#DESKTOP#div-gpt-ad-Top_1-1' - }, - { - 'bidId': bidId1_, - 'adUnitCode': adUnitCode1_, - 'mediaTypes': { - 'video': { - 'playerSize': [640, 360] - }, - 'banner': { - 'sizes': [[300, 250]] - } - }, - 'sizes': [[300, 250]], - 'params': { - 'unit': 'prebidsampleunit' - }, - 'gpid': 'SUPERNEWS#DESKTOP#div-gpt-ad-Top_1-2' - }, - { - 'bidId': bidId2_, - 'adUnitCode': adUnitCode2_, - 'mediaTypes': { - 'video': { - 'playerSize': [640, 360] - }, - 'banner': { - 'sizes': [[300, 250], [300, 600]] - } - }, - 'sizes': [[300, 250], [300, 600]], - 'params': { - 'unit': 'prebidsampleunit' - }, - 'gpid': 'SUPERNEWS#DESKTOP#div-gpt-ad-Top_1-3' - } - ]; - - const testJixieCfg_ = { - genids: [ - { id: 'pubid1', ck: 'ckname1' }, - { id: 'pubid2', ck: 'ckname2' }, - { id: '_jxtoko' }, - { id: '_jxifo' }, - { id: '_jxtdid' }, - { id: '_jxcomp' } - ] - }; - - it('should attach valid params to the adserver endpoint (1)', function () { - // this one we do not intercept the cookie stuff so really don't know - // what will be in there. so we do not check here (using expect) - // The next next below we check - const request = spec.buildRequests(bidRequests_, bidderRequest_); - it('sends bid request to ENDPOINT via POST', function () { - expect(request.method).to.equal('POST') - }) - expect(request.data).to.be.an('string'); - const payload = JSON.parse(request.data); - expect(payload).to.have.property('timeout', timeout_); - expect(payload).to.have.property('currency', currency_); - expect(payload).to.have.property('bids').that.deep.equals(refBids_); - });// it - - it('should attach valid params to the adserver endpoint (2)', function () { - // similar to above test case but here we force some clientid sessionid values - // and domain, pageurl - // get the interceptors ready: - const getConfigStub = sinon.stub(config, 'getConfig'); - getConfigStub.callsFake(function fakeFn(prop) { - if (prop === 'jixie') { - return testJixieCfg_; - } - return null; - }); - - const getCookieStub = sinon.stub(storage, 'getCookie'); - const getLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); - getCookieStub - .withArgs('ckname1') - .returns(ckname1Val_); - getCookieStub - .withArgs('ckname2') - .returns(ckname2Val_); - getCookieStub - .withArgs('_jxtoko') - .returns(jxtokoTest1_); - getCookieStub - .withArgs('_jxtoko') - .returns(jxtokoTest1_); - getCookieStub - .withArgs('_jxifo') - .returns(jxifoTest1_); - getCookieStub - .withArgs('_jxtdid') - .returns(jxtdidTest1_); - getCookieStub - .withArgs('_jxcomp') - .returns(jxcompTest1_); - getCookieStub - .withArgs('_jxx') - .returns(clientIdTest1_); - getCookieStub - .withArgs('_jxxs') - .returns(sessionIdTest1_); - getLocalStorageStub - .withArgs('_jxx') - .returns(clientIdTest1_); - getLocalStorageStub - .withArgs('_jxxs') - .returns(sessionIdTest1_ - ); - const miscDimsStub = sinon.stub(jixieaux, 'getMiscDims'); - miscDimsStub - .returns({ device: device_, pageurl: pageurl_, domain: domain_, mkeywords: keywords_ }); - - // actual api call: - const request = spec.buildRequests(bidRequests_, bidderRequest_); - it('sends bid request to ENDPOINT via POST', function () { - expect(request.method).to.equal('POST') - }) - - expect(request.data).to.be.an('string'); - const payload = JSON.parse(request.data); - expect(payload).to.have.property('client_id_c', clientIdTest1_); - expect(payload).to.have.property('client_id_ls', clientIdTest1_); - expect(payload).to.have.property('session_id_c', sessionIdTest1_); - expect(payload).to.have.property('session_id_ls', sessionIdTest1_); - expect(payload).to.have.property('jxeids').that.deep.equals(refJxEids_); - expect(payload).to.have.property('device', device_); - expect(payload).to.have.property('domain', domain_); - expect(payload).to.have.property('pageurl', pageurl_); - expect(payload).to.have.property('mkeywords', keywords_); - expect(payload).to.have.property('timeout', timeout_); - expect(payload).to.have.property('currency', currency_); - expect(payload).to.have.property('bids').that.deep.equals(refBids_); - - // unwire interceptors - getCookieStub.restore(); - getLocalStorageStub.restore(); - getConfigStub.restore(); - miscDimsStub.restore(); - });// it - - it('it should popular the pricegranularity when info is available', function () { - const content = { - 'ranges': [{ - 'max': 12, - 'increment': 0.5 - }, - { - 'max': 5, - 'increment': 0.1 - }], - precision: 1 - }; - const getConfigStub = sinon.stub(config, 'getConfig'); - getConfigStub.callsFake(function fakeFn(prop) { - if (prop === 'priceGranularity') { - return content; - } - return null; - }); - - const oneSpecialBidReq = Object.assign({}, bidRequests_[0]); - const request = spec.buildRequests([oneSpecialBidReq], bidderRequest_); - const payload = JSON.parse(request.data); - getConfigStub.restore(); - expect(payload.pricegranularity).to.deep.include(content); - }); - - it('it should popular the device info when it is available', function () { - const getConfigStub = sinon.stub(config, 'getConfig'); - const content = {w: 500, h: 400}; - getConfigStub.callsFake(function fakeFn(prop) { - if (prop === 'device') { - return content; - } - return null; - }); - const oneSpecialBidReq = Object.assign({}, bidRequests_[0]); - const request = spec.buildRequests([oneSpecialBidReq], bidderRequest_); - const payload = JSON.parse(request.data); - getConfigStub.restore(); - expect(payload.device).to.have.property('ua', navigator.userAgent); - expect(payload.device).to.deep.include(content); - }); - - it('schain info should be accessible when available', function () { - const schain = { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'ssp.test', - sid: '00001', - hp: 1 - }] - }; - const oneSpecialBidReq = Object.assign({}, bidRequests_[0], { - ortb2: { - source: { - ext: { - schain: schain - } - } - } - }); - const request = spec.buildRequests([oneSpecialBidReq], bidderRequest_); - const payload = JSON.parse(request.data); - expect(payload.schain).to.deep.equal(schain); - expect(payload.schain).to.deep.include(schain); - }); - - it('it should populate the floor info when available', function () { - const oneSpecialBidReq = deepClone(bidRequests_[0]); - let request; let payload = null; - // 1 floor is not set - request = spec.buildRequests([oneSpecialBidReq], bidderRequest_); - payload = JSON.parse(request.data); - expect(payload.bids[0].bidFloor).to.not.exist; - - // 2 floor is set - const getFloorResponse = { currency: 'USD', floor: 2.1 }; - oneSpecialBidReq.getFloor = () => getFloorResponse; - request = spec.buildRequests([oneSpecialBidReq], bidderRequest_); - payload = JSON.parse(request.data); - expect(payload.bids[0].bidFloor).to.exist.and.to.equal(2.1); - }); - - it('it should populate the aid field when available', function () { - const oneSpecialBidReq = deepClone(bidRequests_[0]); - // 1 aid is not set in the jixie config - let request = spec.buildRequests([oneSpecialBidReq], bidderRequest_); - let payload = JSON.parse(request.data); - expect(payload.aid).to.eql(''); - - // 2 aid is set in the jixie config - const getConfigStub = sinon.stub(config, 'getConfig'); - getConfigStub.callsFake(function fakeFn(prop) { - if (prop === 'jixie') { - return { aid: '11223344556677889900' }; - } - return null; - }); - request = spec.buildRequests([oneSpecialBidReq], bidderRequest_); - payload = JSON.parse(request.data); - expect(payload.aid).to.exist.and.to.equal('11223344556677889900'); - getConfigStub.restore(); - }); - - it('should populate eids when supported userIds are available', function () { - const oneSpecialBidReq = Object.assign({}, bidRequests_[0], { - userIdAsEids: [ - { - 'source': 'adserver.org', - 'uids': [ - { - 'id': '11111111-2222-3333-4444-555555555555', - 'atype': 1, - 'ext': { - 'rtiPartner': 'TDID' - } - } - ] - }, - { - 'source': 'uidapi.com', - 'uids': [ - { - 'id': 'AbCdEfGhIjKlMnO9qdQBW7qtMw8f1WTUvtkHe6u+fqLfhbtsqrJ697Z6YoI3IB9klGUv1wvlFIbwH7ELDlqQBGtj8AC1v7fMJ/Q45E7W90dts7UQLTDMLNmtHBRDXVb0Fpas4Vh3yN1jGVQNhzXC/RpGIVtZE8dCxcjfa7VfcTNcvxxxxx==', - 'atype': 3 - } - ] - }, - { - 'source': 'puburl1.com', - 'uids': [ - { - 'id': 'pubid1', - 'atype': 1, - 'ext': { - 'stype': 'ppuid' - } - } - ] - }, - { - 'source': 'puburl2.com', - 'uids': [ - { - 'id': 'pubid2' - } - ] - }, - ], - }); - const request = spec.buildRequests([oneSpecialBidReq], bidderRequest_); - const payload = JSON.parse(request.data); - expect(payload.eids).to.eql(oneSpecialBidReq.userIdAsEids); - }); - });// describe - - /** - * interpretResponse: - */ - const JX_OTHER_OUTSTREAM_RENDERER_URL = 'https://scripts.jixie.media/dummyscript.js'; - const JX_OUTSTREAM_RENDERER_URL = 'https://scripts.jixie.media/jxhbrenderer.1.1.min.js'; - - const mockVastXml_ = `JXADSERVERAlway%20Live%20Prebid%20CreativeHybrid in-stream00:00:10`; - const responseBody_ = { - 'bids': [ - // video (vast tag url) returned here - { - 'jxBidId': '62847e4c696edcb-028d5dee-2c83-44e3-bed1-b75002475cdf', - 'requestId': '62847e4c696edcb', - 'cpm': 2.19, - 'width': 640, - 'height': 360, - 'ttl': 300, - 'adUnitCode': 'demoslot3-div', - 'netRevenue': true, - 'currency': 'USD', - 'creativeId': 'jixie522', - 'meta': { - 'networkId': 123, - 'networkName': 'network123', - 'agencyId': 123, - 'agencyName': 'agency123', - 'advertiserId': 123, - 'advertiserName': 'advertiser123', - 'brandId': 123, - 'brandName': 'brand123', - 'primaryCatId': 1, - 'secondaryCatIds': [ - 2, - 3, - 4 - ], - 'mediaType': 'VIDEO' - }, - 'vastUrl': 'https://ad.jixie.io/v1/video?creativeid=522' - }, - // display ad returned here: This one there is advertiserDomains - // in the response . Will be checked in the unit tests below - { - 'jxBidId': '600c9ae6fda1acb-028d5dee-2c83-44e3-bed1-b75002475cdf', - 'requestId': '600c9ae6fda1acb', - 'cpm': 1.999, - 'width': 300, - 'height': 250, - 'ttl': 300, - 'adUnitCode': 'demoslot1-div', - 'netRevenue': true, - 'currency': 'USD', - 'creativeId': 'jixie520', - 'meta': { - 'networkId': 123, - 'networkName': 'network123', - 'agencyId': 123, - 'agencyName': 'agency123', - 'advertiserId': 123, - 'advertiserName': 'advertiser123', - 'advertiserDomains': [ - 'advdom1', - 'advdom2', - 'advdom3' - ], - 'brandId': 123, - 'brandName': 'brand123', - 'primaryCatId': 1, - 'secondaryCatIds': [ - 2, - 3, - 4 - ], - 'mediaType': 'BANNER' - }, - 'ad': '
' - }, - // outstream, jx non-default renderer specified: - { - 'jxBidId': '99bc539c81b00ce-028d5dee-2c83-44e3-bed1-b75002475cdf', - 'requestId': '99bc539c81b00ce', - 'cpm': 2.99, - 'width': 640, - 'height': 360, - 'ttl': 300, - 'netRevenue': true, - 'currency': 'USD', - 'creativeId': 'jixie521', - 'adUnitCode': 'demoslot4-div', - 'osplayer': 'jixie', - 'osparams': { - 'script': JX_OTHER_OUTSTREAM_RENDERER_URL - }, - 'vastXml': mockVastXml_ - }, - // outstream, jx default renderer: - { - 'jxBidId': '61bc539c81b00ce-028d5dee-2c83-44e3-bed1-b75002475cdf', - 'requestId': '61bc539c81b00ce', - 'cpm': 1.99, - 'width': 640, - 'height': 360, - 'ttl': 300, - 'netRevenue': true, - 'currency': 'USD', - 'creativeId': 'jixie521', - 'meta': { - 'networkId': 123, - 'networkName': 'network123', - 'agencyId': 123, - 'agencyName': 'agency123', - 'advertiserId': 123, - 'advertiserName': 'advertiser123', - 'brandId': 123, - 'brandName': 'brand123', - 'primaryCatId': 1, - 'secondaryCatIds': [ - 2, - 3, - 4 - ], - 'mediaType': 'VIDEO' - }, - 'adUnitCode': 'demoslot2-div', - 'osplayer': 'jixie', - 'osparams': {}, - 'vastXml': mockVastXml_ - } - ], - 'setids': { - 'client_id': '43aacc10-f643-11ea-8a10-c5fe2d394e7e', - 'session_id': '1600057934-43aacc10-f643-11ea-8a10-c5fe2d394e7e' - }, - }; - const requestObj_ = - { - 'method': 'POST', - 'url': 'http://localhost:8080/v2/hbpost', - 'data': '{"auctionid":"028d5dee-2c83-44e3-bed1-b75002475cdf","timeout":1000,"currency":"USD","timestamp":1600057934665,"device":"desktop","domain":"mock.com","pageurl":"https://mock.com/tests/jxprebidtest_pbjs.html","bids":[{"bidId":"600c9ae6fda1acb","adUnitCode":"demoslot1-div","mediaTypes":{"banner":{"sizes":[[300,250],[300,600],[728,90]]}},"params":{"unit":"prebidsampleunit"}},{"bidId":"61bc539c81b00ce","adUnitCode":"demoslot2-div","mediaTypes":{"video":{"playerSize":[[640,360]],"context":"outstream"}},"params":{"unit":"prebidsampleunit"}},{"bidId":"99bc539c81b00ce","adUnitCode":"demoslot4-div","mediaTypes":{"video":{"playerSize":[[640,360]],"context":"outstream"}},"params":{"unit":"prebidsampleunit"}},{"bidId":"62847e4c696edcb","adUnitCode":"demoslot3-div","mediaTypes":{"video":{"playerSize":[[640,360]],"context":"instream"}},"params":{"unit":"prebidsampleunit"}},{"bidId":"6360235ab01d2cd","adUnitCode":"woo-div","mediaTypes":{"video":{"context":"outstream","playerSize":[[640,360]]}},"params":{"unit":"80b76fc951e161d7c019d21b6639e408"}},{"bidId":"64d9724c7a5e512","adUnitCode":"test-div","mediaTypes":{"video":{"context":"outstream","playerSize":[[300,250]]}},"params":{"unit":"80b76fc951e161d7c019d21b6639e408"}},{"bidId":"65bea7e80fed44b","adUnitCode":"test-div","mediaTypes":{"banner":{"sizes":[[300,250],[300,600],[728,90]]}},"params":{"unit":"7854f723e932b951b6c51fc80b23a410"}},{"bidId":"6642054c4ba1b7f","adUnitCode":"div-banner-native-1","mediaTypes":{"banner":{"sizes":[[640,360]]},"video":{"context":"outstream","sizes":[[640,361]],"playerSize":[[640,360]]},"native":{"type":"image"}},"params":{"unit":"632e7695f0910ce0fa74c19859060a04"}},{"bidId":"675ecf4b44db228","adUnitCode":"div-banner-native-2","mediaTypes":{"banner":{"sizes":[[300,250]]},"native":{"title":{"required":true},"image":{"required":true},"sponsoredBy":{"required":true}}},"params":{"unit":"1000008-b1Q2UMQfZx"}},{"bidId":"68f2dbf5dc23f94","adUnitCode":"div-Top-MediumRectangle","mediaTypes":{"banner":{"sizes":[[300,250],[300,100],[320,50]]}},"params":{"unit":"1000008-b1Q2UMQfZx"}},{"bidId":"6991cf107bb7f1a","adUnitCode":"div-Middle-MediumRectangle","mediaTypes":{"banner":{"sizes":[[300,250],[300,100],[320,50]]}},"params":{"unit":"1000008-b1Q2UMQfZx"}},{"bidId":"706be1b011eac83","adUnitCode":"div-Inside-MediumRectangle","mediaTypes":{"banner":{"sizes":[[300,600],[300,250],[300,100],[320,480]]}},"params":{"unit":"1000008-b1Q2UMQfZx"}}],"client_id_c":"ebd0dea0-f5c8-11ea-a2c7-a5b37aa7fe95","client_id_ls":"ebd0dea0-f5c8-11ea-a2c7-a5b37aa7fe95","session_id_c":"","session_id_ls":"1600005388-ebd0dea0-f5c8-11ea-a2c7-a5b37aa7fe95"}', - 'currency': 'USD' - }; - - describe('interpretResponse', function () { - it('handles nobid responses', function () { - expect(spec.interpretResponse({body: {}}, {validBidRequests: []}).length).to.equal(0) - expect(spec.interpretResponse({body: []}, {validBidRequests: []}).length).to.equal(0) - }); - - it('should get correct bid response', function () { - const setCookieSpy = sinon.spy(storage, 'setCookie'); - const setLocalStorageSpy = sinon.spy(storage, 'setDataInLocalStorage'); - const result = spec.interpretResponse({body: responseBody_}, requestObj_) - expect(setLocalStorageSpy.calledWith('_jxx', '43aacc10-f643-11ea-8a10-c5fe2d394e7e')).to.equal(true); - expect(setLocalStorageSpy.calledWith('_jxxs', '1600057934-43aacc10-f643-11ea-8a10-c5fe2d394e7e')).to.equal(true); - expect(setCookieSpy.calledWith('_jxxs', '1600057934-43aacc10-f643-11ea-8a10-c5fe2d394e7e')).to.equal(true); - expect(setCookieSpy.calledWith('_jxx', '43aacc10-f643-11ea-8a10-c5fe2d394e7e')).to.equal(true); - - // video ad with vastUrl returned by adserver - expect(result[0].requestId).to.equal('62847e4c696edcb') - expect(result[0].cpm).to.equal(2.19) - expect(result[0].width).to.equal(640) - expect(result[0].height).to.equal(360) - expect(result[0].creativeId).to.equal('jixie522') - expect(result[0].currency).to.equal('USD') - expect(result[0].netRevenue).to.equal(true) - expect(result[0].ttl).to.equal(300) - expect(result[0].vastUrl).to.include('https://ad.jixie.io/v1/video?creativeid=') - // We will always make sure the meta->advertiserDomains property is there - // If no info it is an empty array. - expect(result[0].meta.advertiserDomains.length).to.equal(0) - - // display ad - expect(result[1].requestId).to.equal('600c9ae6fda1acb') - expect(result[1].cpm).to.equal(1.999) - expect(result[1].width).to.equal(300) - expect(result[1].height).to.equal(250) - expect(result[1].creativeId).to.equal('jixie520') - expect(result[1].currency).to.equal('USD') - expect(result[1].netRevenue).to.equal(true) - expect(result[1].ttl).to.equal(300) - expect(result[1].ad).to.include('jxoutstream') - expect(result[1].meta.advertiserDomains.length).to.equal(3) - - // should pick up about using alternative outstream renderer - expect(result[2].requestId).to.equal('99bc539c81b00ce') - expect(result[2].cpm).to.equal(2.99) - expect(result[2].width).to.equal(640) - expect(result[2].height).to.equal(360) - expect(result[2].creativeId).to.equal('jixie521') - expect(result[2].currency).to.equal('USD') - expect(result[2].netRevenue).to.equal(true) - expect(result[2].ttl).to.equal(300) - expect(result[2].vastXml).to.include('') - expect(result[2].renderer.id).to.equal('demoslot4-div') - expect(result[2].meta.advertiserDomains.length).to.equal(0) - expect(result[2].renderer.url).to.equal(JX_OTHER_OUTSTREAM_RENDERER_URL); - - // should know to use default outstream renderer - expect(result[3].requestId).to.equal('61bc539c81b00ce') - expect(result[3].cpm).to.equal(1.99) - expect(result[3].width).to.equal(640) - expect(result[3].height).to.equal(360) - expect(result[3].creativeId).to.equal('jixie521') - expect(result[3].currency).to.equal('USD') - expect(result[3].netRevenue).to.equal(true) - expect(result[3].ttl).to.equal(300) - expect(result[3].vastXml).to.include('') - expect(result[3].renderer.id).to.equal('demoslot2-div') - expect(result[3].meta.advertiserDomains.length).to.equal(0) - expect(result[3].renderer.url).to.equal(JX_OUTSTREAM_RENDERER_URL) - - setLocalStorageSpy.restore(); - setCookieSpy.restore(); - });// it - });// describe - - /** - * onBidWon - */ - describe('onBidWon', function() { - let ajaxStub; - let miscDimsStub; - beforeEach(function() { - miscDimsStub = sinon.stub(jixieaux, 'getMiscDims'); - ajaxStub = sinon.stub(jixieaux, 'ajax'); - - miscDimsStub - .returns({ device: device_, pageurl: pageurl_, domain: domain_, mkeywords: keywords_ }); - }) - - afterEach(function() { - miscDimsStub.restore(); - ajaxStub.restore(); - }) - - const TRACKINGURL_ = 'https://abc.com/sync?action=bidwon'; - - it('Should fire if the adserver trackingUrl flag says so', function() { - spec.onBidWon({ trackingUrl: TRACKINGURL_ }) - expect(jixieaux.ajax.calledWith(TRACKINGURL_)).to.equal(true); - }) - }); // describe - - describe('getUserSyncs', function () { - it('it should favour iframe over pixel if publisher allows iframe usersync', function () { - const syncOptions = { - 'iframeEnabled': true, - 'pixelEnabled': true, - } - const response = { - 'userSyncs': [ - { - 'uf': 'https://syncstuff.jixie.io/', - 'up': 'https://syncstuff.jixie.io/image.gif' - }, - { - 'up': 'https://syncstuff.jixie.io/image1.gif' - } - ] - } - const result = spec.getUserSyncs(syncOptions, [{ body: response }]); - expect(result[0].type).to.equal('iframe') - expect(result[1].type).to.equal('image') - }) - - it('it should pick pixel if publisher not allow iframe', function () { - const syncOptions = { - 'iframeEnabled': false, - 'pixelEnabled': true, - } - const response = { - 'userSyncs': [ - { - 'uf': 'https://syncstuff.jixie.io/', - 'up': 'https://syncstuff.jixie.io/image.gif' - }, - { - 'up': 'https://syncstuff.jixie.io/image1.gif' - } - ] - } - const result = spec.getUserSyncs(syncOptions, [{ body: response }]); - expect(result[0].type).to.equal('image') - expect(result[1].type).to.equal('image') - }) - - it('it should return nothing if pub only allow pixel but all usersyncs are iframe only', function () { - const syncOptions = { - 'iframeEnabled': false, - 'pixelEnabled': true, - } - const response = { - 'userSyncs': [ - { - 'uf': 'https://syncstuff.jixie.io/', - }, - { - 'uf': 'https://syncstuff2.jixie.io/', - } - ] - } - const result = spec.getUserSyncs(syncOptions, [{ body: response }]); - expect(result.length).to.equal(0) - }) - }) -}); diff --git a/test/spec/modules/justpremiumBidAdapter_spec.js b/test/spec/modules/justpremiumBidAdapter_spec.js deleted file mode 100644 index 21cd488e7..000000000 --- a/test/spec/modules/justpremiumBidAdapter_spec.js +++ /dev/null @@ -1,227 +0,0 @@ -import { expect } from 'chai' -import { spec } from 'modules/justpremiumBidAdapter.js' - -describe('justpremium adapter', function () { - let sandbox; - - beforeEach(function() { - sandbox = sinon.createSandbox(); - }); - - afterEach(function() { - sandbox.restore(); - }); - - const schainConfig = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'indirectseller.com', - 'sid': '00001', - 'hp': 1 - } - ] - } - - const adUnits = [ - { - adUnitCode: 'div-gpt-ad-1471513102552-1', - bidder: 'justpremium', - crumbs: { - pubcid: '0000000' - }, - userId: { - tdid: '1111111', - id5id: { - uid: '2222222' - }, - digitrustid: { - data: { - id: '3333333' - } - } - }, - params: { - zone: 28313, - allow: ['lb', 'wp'] - }, - ortb2: { - source: { - ext: { - schain: schainConfig - } - } - } - }, - { - adUnitCode: 'div-gpt-ad-1471513102552-2', - bidder: 'justpremium', - params: { - zone: 32831, - exclude: ['sa'] - } - }, - ] - - const bidderRequest = { - uspConsent: '1YYN', - refererInfo: { - referer: 'https://justpremium.com' - } - } - - const serverResponses = [ - { - 'body': { - 'bid': {}, - 'pass': { - '141952': true - }, - 'deals': {}, - 'pxs': [ - { - 'url': 'https://url.com', - 'type': 'image' - } - ] - } - } - ] - - describe('isBidRequestValid', function () { - it('Verifies bidder code', function () { - expect(spec.code).to.equal('justpremium') - }) - - it('Verify build request', function () { - expect(spec.isBidRequestValid({bidder: 'justpremium', params: {}})).to.equal(false) - expect(spec.isBidRequestValid({})).to.equal(false) - expect(spec.isBidRequestValid(adUnits[0])).to.equal(true) - expect(spec.isBidRequestValid(adUnits[1])).to.equal(true) - }) - }) - - describe('buildRequests', function () { - it('Verify build request and parameters', function () { - const request = spec.buildRequests(adUnits, bidderRequest) - expect(request.method).to.equal('POST') - expect(request.url).to.match(/pre.ads.justpremium.com\/v\/2.0\/t\/xhr/) - - const jpxRequest = JSON.parse(request.data) - expect(jpxRequest).to.not.equal(null) - expect(jpxRequest.zone).to.not.equal('undefined') - expect(bidderRequest.refererInfo.referer).to.equal('https://justpremium.com') - expect(jpxRequest.schain).to.deep.equal(schainConfig) - expect(jpxRequest.sw).to.equal(window.top.screen.width) - expect(jpxRequest.sh).to.equal(window.top.screen.height) - expect(jpxRequest.ww).to.equal(window.top.innerWidth) - expect(jpxRequest.wh).to.equal(window.top.innerHeight) - expect(jpxRequest.c).to.not.equal('undefined') - expect(jpxRequest.id).to.equal(adUnits[0].params.zone) - expect(jpxRequest.mediaTypes && jpxRequest.mediaTypes.banner && jpxRequest.mediaTypes.banner.sizes).to.not.equal('undefined') - expect(jpxRequest.version.prebid).to.equal('$prebid.version$') - expect(jpxRequest.version.jp_adapter).to.equal('1.8.3') - expect(jpxRequest.pubcid).to.equal('0000000') - expect(jpxRequest.uids.tdid).to.equal('1111111') - expect(jpxRequest.uids.id5id.uid).to.equal('2222222') - expect(jpxRequest.uids.digitrustid.data.id).to.equal('3333333') - expect(jpxRequest.us_privacy).to.equal('1YYN') - expect(jpxRequest.ggExt).to.be.null - }) - }) - - describe('interpretResponse', function () { - const request = spec.buildRequests(adUnits, bidderRequest) - it('Verify server response', function () { - const response = { - 'bid': { - '28313': [{ - 'id': 3213123, - 'height': 250, - 'width': 970, - 'price': 0.52, - 'format': 'lb', - 'adm': 'creative code', - 'adomain': ['justpremium.com'], - 'ext': { - 'pg': true - } - }] - }, - 'pass': { - '28313': false - }, - 'deals': {} - } - - const expectedResponse = [ - { - requestId: '319a5029c362f4', - creativeId: 3213123, - width: 970, - height: 250, - ad: 'creative code', - cpm: 0.52, - netRevenue: true, - currency: 'USD', - ttl: 60000, - format: 'lb', - meta: { - advertiserDomains: ['justpremium.com'] - }, - adserverTargeting: { - 'hb_deal_justpremium': 'jp_pg' - } - } - ] - - const result = spec.interpretResponse({body: response}, request) - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])) - - expect(result[0]).to.not.equal(null) - expect(result[0].width).to.equal(970) - expect(result[0].height).to.equal(250) - expect(result[0].ad).to.equal('creative code') - expect(result[0].cpm).to.equal(0.52) - expect(result[0].currency).to.equal('USD') - expect(result[0].ttl).to.equal(60000) - expect(result[0].creativeId).to.equal(3213123) - expect(result[0].netRevenue).to.equal(true) - expect(result[0].format).to.equal('lb') - expect(result[0].meta.advertiserDomains[0]).to.equal('justpremium.com') - expect(result[0].adserverTargeting).to.deep.equal({'hb_deal_justpremium': 'jp_pg'}) - }) - - it('Verify wrong server response', function () { - const response = { - 'bid': { - '28313': [] - }, - 'pass': { - '28313': true - } - } - - const result = spec.interpretResponse({body: response}, request) - expect(result.length).to.equal(0) - }) - }) - - describe('getUserSyncs', function () { - it('Verifies sync options for iframe', function () { - const options = spec.getUserSyncs({iframeEnabled: true}, {}, {gdprApplies: true, consentString: 'BOOgjO9OOgjO9APABAENAi-AAAAWd'}, '1YYN') - expect(options).to.not.be.undefined - expect(options[0].type).to.equal('iframe') - expect(options[0].url).to.match(/\/\/pre.ads.justpremium.com\/v\/1.0\/t\/sync/) - expect(options[0].url).to.match(/&consentString=BOOgjO9OOgjO9APABAENAi-AAAAWd/) - expect(options[0].url).to.match(/&usPrivacy=1YYN/) - }) - it('Returns array of user sync pixels', function () { - const options = spec.getUserSyncs({pixelEnabled: true}, serverResponses) - expect(options).to.not.be.undefined - expect(Array.isArray(options)).to.be.true - expect(options[0].type).to.equal('image') - }) - }) -}) diff --git a/test/spec/modules/jwplayerBidAdapter_spec.js b/test/spec/modules/jwplayerBidAdapter_spec.js deleted file mode 100644 index ae4569192..000000000 --- a/test/spec/modules/jwplayerBidAdapter_spec.js +++ /dev/null @@ -1,418 +0,0 @@ -import { expect, assert } from 'chai'; -import { spec } from 'modules/jwplayerBidAdapter.js'; - -describe('jwplayerBidAdapter', function() { - beforeEach(function() { - this.defaultBidderRequest = { - gdprConsent: { - consentString: 'testConsentString', - gdprApplies: true - }, - uspConsent: 'testCCPA', - refererInfo: { - referer: 'https://example.com' - }, - ortb2: { - site: { - domain: 'page.example.com', - page: 'https://examplepage.com', - content: { - url: 'media.mp4', - id: 'testMediaId', - title: 'testTile', - data: [{ - name: 'jwplayer.com', - segment: [{ - id: '00000000' - }, { - id: '88888888' - }, { - id: '80808080' - }], - ext: { - segtax: 502, - cids: ['testMediaId', 'externalTestId'], - } - }], - ext: { - description: 'testDescription' - } - } - } - }, - timeout: 1000 - } - }); - - it('should use jwplayer bidder code', function () { - expect(spec.code).to.equal('jwplayer'); - }); - - it('should use jwplayer GVLID code', function () { - expect(spec.gvlid).to.equal(1046); - }); - - it('should support VIDEO media type only', function () { - expect(spec.supportedMediaTypes).to.have.length(1); - expect(spec.supportedMediaTypes[0]).to.equal('video'); - }); - - describe('isBidRequestValid', function() { - it('should be invalid when bidRequest is undefined', function() { - assert(spec.isBidRequestValid() === false); - }); - - it('should be invalid when bidRequest is null', function() { - assert(spec.isBidRequestValid(null) === false); - }); - - it('should be invalid when the bidRequest has no params', function() { - assert(spec.isBidRequestValid({}) === false); - }); - - it('should be invalid when the bid request only includes a publisher ID', function() { - assert(spec.isBidRequestValid({params: {publisherId: 'foo'}}) === false); - }); - - it('should be invalid when the bid request only includes a placement ID', function() { - assert(spec.isBidRequestValid({params: {placementId: 'foo'}}) === false); - }); - - it('should be invalid when the bid request only includes a site ID', function() { - assert(spec.isBidRequestValid({params: {siteId: 'foo'}}) === false); - }); - - it('should be valid when the bid includes a placement ID, a publisher ID and a site ID', function() { - assert(spec.isBidRequestValid({params: {placementId: 'foo', publisherId: 'bar', siteId: 'siteId '}}) === true); - }); - }); - - describe('buildRequests', function() { - it('should return undefined when bidRequests is undefined', function () { - expect(spec.buildRequests()).to.be.undefined; - }); - - it('should return undefined when bidRequests is null', function () { - expect(spec.buildRequests(null)).to.be.undefined; - }); - - it('should return undefined when ortb site.content.url is absent', function () { - const request = spec.buildRequests({}, { - ortb2: { - site: { - content: { - url: null, - } - } - } - }); - - expect(request).to.be.undefined; - }); - - it('should build a valid request when bid request is complete', function() { - const incomingBidRequests = [ - { - bidder: 'jwplayer', - params: { - placementId: 'testPlacementId', - publisherId: 'testPublisherId', - siteId: 'testSiteId', - bidFloor: 10, - currency: 'EUR', - }, - mediaTypes: { - video: { - pos: 3, - w: 640, - h: 480, - context: 'instream', - mimes: [ - 'video/mp4', - 'application/javascript' - ], - protocols: [2, 3, 5, 6], - maxduration: 60, - minduration: 3, - startdelay: 0, - linearity: 1, - placement: 1, - plcmt: 1, - skip: 1, - skipafter: 4, - minbitrate: 500, - maxbitrate: 1000, - api: [2], - delivery: [2], - playbackmethod: [1], - playbackend: 2 - } - }, - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'publisher.com', - sid: '00001', - hp: 1 - } - ] - } - } - } - }, - bidRequestsCount: 1, - adUnitCode: 'testAdUnitCode', - bidId: 'testBidId' - } - ]; - - const outgoingBidRequests = spec.buildRequests(incomingBidRequests, this.defaultBidderRequest); - - outgoingBidRequests.forEach(serverRequest => { - expect(serverRequest.url).to.equal('https://vpb-server.jwplayer.com/openrtb2/auction'); - expect(serverRequest.method).to.equal('POST'); - - const openrtbRequest = JSON.parse(serverRequest.data); - - expect(openrtbRequest.id).to.equal('testBidId'); - - expect(openrtbRequest.imp[0].id).to.equal('testAdUnitCode'); - expect(openrtbRequest.imp[0].video.w).to.equal(640); - expect(openrtbRequest.imp[0].video.h).to.equal(480); - expect(openrtbRequest.imp[0].video.mimes).to.deep.equal(['video/mp4', 'application/javascript']); - expect(openrtbRequest.imp[0].video.protocols).to.deep.equal([2, 3, 5, 6]); - expect(openrtbRequest.imp[0].video.api).to.deep.equal([2]); - expect(openrtbRequest.imp[0].video.startdelay).to.equal(0); - expect(openrtbRequest.imp[0].video.placement).to.equal(1); - expect(openrtbRequest.imp[0].video.plcmt).to.equal(1); - expect(openrtbRequest.imp[0].video.pos).to.equal(3); - expect(openrtbRequest.imp[0].video.minduration).to.equal(3); - expect(openrtbRequest.imp[0].video.maxduration).to.equal(60); - expect(openrtbRequest.imp[0].video.skip).to.equal(1); - expect(openrtbRequest.imp[0].video.skipafter).to.equal(4); - expect(openrtbRequest.imp[0].video.minbitrate).to.equal(500); - expect(openrtbRequest.imp[0].video.maxbitrate).to.equal(1000); - expect(openrtbRequest.imp[0].video.delivery).to.deep.equal([2]); - expect(openrtbRequest.imp[0].video.playbackmethod).to.deep.equal([1]); - expect(openrtbRequest.imp[0].video.playbackend).to.equal(2); - expect(openrtbRequest.imp[0].video.linearity).to.equal(1); - - expect(openrtbRequest.imp[0].bidfloor).to.equal(10); - expect(openrtbRequest.imp[0].bidfloorcur).to.equal('EUR'); - - expect(openrtbRequest.imp[0].ext.prebid.bidder.jwplayer.placementId).to.equal('testPlacementId'); - - expect(openrtbRequest.site.domain).to.equal('page.example.com'); - expect(openrtbRequest.site.page).to.equal('https://examplepage.com'); - expect(openrtbRequest.site.ref).to.equal('https://example.com'); - - expect(openrtbRequest.site.publisher.ext.jwplayer.publisherId).to.equal('testPublisherId'); - expect(openrtbRequest.site.publisher.ext.jwplayer.siteId).to.equal('testSiteId'); - - expect(openrtbRequest.site.content.url).to.equal('media.mp4'); - expect(openrtbRequest.site.content.id).to.equal('testMediaId'); - expect(openrtbRequest.site.content.title).to.equal('testTile'); - expect(openrtbRequest.site.content.ext.description).to.equal('testDescription'); - expect(openrtbRequest.site.content.data.length).to.equal(1); - const datum = openrtbRequest.site.content.data[0]; - expect(datum.name).to.equal('jwplayer.com'); - expect(datum.segment).to.deep.equal([{ - id: '00000000' - }, { - id: '88888888' - }, { - id: '80808080' - }]); - expect(datum.ext.segtax).to.equal(502); - expect(datum.ext.cids).to.deep.equal(['testMediaId', 'externalTestId']); - - expect(openrtbRequest.device.ua).to.equal(navigator.userAgent); - expect(openrtbRequest.device.w).to.not.be.undefined; - expect(openrtbRequest.device.h).to.not.be.undefined; - expect(openrtbRequest.device.dnt).to.not.be.undefined; - expect(openrtbRequest.device.js).to.equal(1); - expect(openrtbRequest.device.language).to.not.be.undefined; - - expect(openrtbRequest.user.ext.consent).to.equal('testConsentString'); - - expect(openrtbRequest.regs.ext.gdpr).to.equal(1); - expect(openrtbRequest.regs.ext.us_privacy).to.equal('testCCPA'); - - expect(openrtbRequest.source.schain).to.deep.equal({ - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'publisher.com', - sid: '00001', - hp: 1 - } - ] - }); - - expect(openrtbRequest.tmax).to.equal(1000); - }); - }); - }); - - describe('interpretResponse', function() { - const serverResponse = { - body: { - id: 'test-request-id', - cur: 'USD', - seatbid: [{ - bid: [{ - id: 'testId', - impid: 'test-imp-id', - price: 5.000, - adid: 'test-creative-id', - adm: 'test-ad-xml', - adomain: ['prebid.com'], - cat: ['test-iab-category'], - w: 200, - h: 150, - dealid: 'test-deal-id' - }], - seat: 1000 - }] - } - }; - - const bidResponses = spec.interpretResponse(serverResponse); - - expect(bidResponses).to.have.length(1); - const bid = bidResponses[0]; - expect(bid.requestId).to.equal('test-request-id'); - expect(bid.cpm).to.equal(5); - expect(bid.currency).to.equal('USD'); - expect(bid.width).to.equal(200); - expect(bid.height).to.equal(150); - expect(bid.creativeId).to.equal('test-creative-id'); - expect(bid.vastXml).to.equal('test-ad-xml'); - expect(bid.netRevenue).to.equal(false); - expect(bid.ttl).to.equal(3600); - expect(bid.ad).to.equal('test-ad-xml'); - expect(bid.dealId).to.equal('test-deal-id'); - - expect(bid.meta).to.not.be.undefined; - - expect(bid.meta.advertiserDomains).to.have.length(1); - expect(bid.meta.advertiserDomains[0]).to.equal('prebid.com'); - - expect(bid.meta.mediaType).to.equal('video'); - - expect(bid.meta.primaryCatId).to.have.length(1); - expect(bid.meta.primaryCatId[0]).to.equal('test-iab-category'); - }); - - describe('getUserSyncs', function() { - const consentString = 'test_consent_string'; - const baseGdprConsent = { - gdprApplies: true, - vendorData: { - purpose: { - consents: { - 1: true - } - } - } - }; - - const expectedBaseUrl = 'https://ib.adnxs.com/getuid?https://vpb-server.jwplayer.com/setuid?bidder=jwplayer&uid=$UID&f=i'; - - it('should return empty when Purpose 1 consent is not granted', function() { - expect(spec.getUserSyncs({}, {})).to.be.empty; - expect(spec.getUserSyncs({}, {}, {})).to.be.empty; - expect(spec.getUserSyncs({}, {}, { gdprApplies: false })).to.be.empty; - expect(spec.getUserSyncs({}, {}, { - gdprApplies: true, - vendorData: { - purpose: { - consents: { - 1: false - } - } - } - })).to.be.empty; - }); - - it('should return iframe when enabled', function () { - const userSyncs = spec.getUserSyncs({ iframeEnabled: true }, {}, baseGdprConsent); - expect(userSyncs.length).to.equal(1); - const sync = userSyncs[0]; - expect(sync.type).to.equal('iframe'); - expect(sync.url).to.equal(expectedBaseUrl); - }); - - it('should return image when enabled', function () { - const userSyncs = spec.getUserSyncs({ pixelEnabled: true }, {}, baseGdprConsent); - expect(userSyncs.length).to.equal(1); - const sync = userSyncs[0]; - expect(sync.type).to.equal('image'); - expect(sync.url).to.equal(expectedBaseUrl); - }); - - it('should return both iframe and image when enabled', function () { - const userSyncs = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }, {}, baseGdprConsent); - expect(userSyncs.length).to.equal(2); - - const iframeSync = userSyncs[0]; - expect(iframeSync.type).to.equal('iframe'); - expect(iframeSync.url).to.equal(expectedBaseUrl); - - const imageSync = userSyncs[1]; - expect(imageSync.type).to.equal('image'); - expect(imageSync.url).to.equal(expectedBaseUrl); - }); - - it('should include gdpr consent query params in sync redirect url', function () { - const expectedUrl = expectedBaseUrl + '&gdpr=1&gdpr_consent=' + consentString; - const gdprConsent = Object.assign({ }, baseGdprConsent, { consentString }); - const userSyncs = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }, {}, gdprConsent); - expect(userSyncs.length).to.equal(2); - - const iframeSync = userSyncs[0]; - expect(iframeSync.type).to.equal('iframe'); - expect(iframeSync.url).to.equal(expectedUrl); - - const imageSync = userSyncs[1]; - expect(imageSync.type).to.equal('image'); - expect(imageSync.url).to.equal(expectedUrl); - }); - - it('should include gdpr 0 in consent query params when gdprApplies is false', function () { - const expectedUrl = expectedBaseUrl + '&gdpr=0&gdpr_consent=' + consentString; - const gdprConsent = Object.assign({ }, baseGdprConsent, { consentString, gdprApplies: false }); - const userSyncs = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }, {}, gdprConsent); - expect(userSyncs.length).to.equal(2); - - const iframeSync = userSyncs[0]; - expect(iframeSync.type).to.equal('iframe'); - expect(iframeSync.url).to.equal(expectedUrl); - - const imageSync = userSyncs[1]; - expect(imageSync.type).to.equal('image'); - expect(imageSync.url).to.equal(expectedUrl); - }); - - it('should include gdpr 0 in consent query params when gdprApplies is not a bool', function () { - const expectedUrl = expectedBaseUrl + '&gdpr=0&gdpr_consent=' + consentString; - const gdprConsent = Object.assign({ }, baseGdprConsent, { consentString, gdprApplies: 1 }); - const userSyncs = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }, {}, gdprConsent); - expect(userSyncs.length).to.equal(2); - - const iframeSync = userSyncs[0]; - expect(iframeSync.type).to.equal('iframe'); - expect(iframeSync.url).to.equal(expectedUrl); - - const imageSync = userSyncs[1]; - expect(imageSync.type).to.equal('image'); - expect(imageSync.url).to.equal(expectedUrl); - }); - }); -}); diff --git a/test/spec/modules/jwplayerRtdProvider_spec.js b/test/spec/modules/jwplayerRtdProvider_spec.js deleted file mode 100644 index e60d346de..000000000 --- a/test/spec/modules/jwplayerRtdProvider_spec.js +++ /dev/null @@ -1,1856 +0,0 @@ -import { - addOrtbSiteContent, - addTargetingToBid, - enrichAdUnits, - extractPublisherParams, - fetchTargetingForMediaId, - fetchTargetingInformation, - formatTargetingResponse, - getContentData, - getContentId, - getContentSegments, - getVatFromCache, - getVatFromPlayer, - setOverrides, - getPlayer, - jwplayerSubmodule -} from 'modules/jwplayerRtdProvider.js'; -import {server} from 'test/mocks/xhr.js'; -import {deepClone} from '../../../src/utils.js'; - -describe('jwplayerRtdProvider', function() { - const testIdForSuccess = 'test_id_for_success'; - const testIdForFailure = 'test_id_for_failure'; - const validSegments = ['test_seg_1', 'test_seg_2']; - const responseHeader = {'Content-Type': 'application/json'}; - - describe('Fetch targeting for mediaID tests', function () { - let request; - - describe('Fetch succeeds', function () { - beforeEach(function () { - fetchTargetingForMediaId(testIdForSuccess); - request = server.requests[0]; - }); - - afterEach(function () { - server.respond(); - }); - - it('should reach out to media endpoint', function () { - expect(request.url).to.be.eq(`https://cdn.jwplayer.com/v2/media/${testIdForSuccess}`); - }); - - it('should write to cache when successful', function () { - request.respond( - 200, - responseHeader, - JSON.stringify({ - playlist: [ - { - file: 'test.mp4', - jwpseg: validSegments, - title: 'test', - description: 'this is a test' - } - ] - }) - ); - - const targetingInfo = getVatFromCache(testIdForSuccess); - - const validTargeting = { - segments: validSegments, - mediaID: testIdForSuccess, - mediaUrl: 'test.mp4', - title: 'test', - description: 'this is a test' - }; - - expect(targetingInfo).to.deep.equal(validTargeting); - }); - - it('should obtain file from sources', function () { - request.respond( - 200, - responseHeader, - JSON.stringify({ - playlist: [ - { - sources: [{ - label: 'missing file', - }, { - file: 'source.mp4', - label: 'valid file' - }], - jwpseg: validSegments, - title: 'test', - description: 'this is a test' - } - ] - }) - ); - - const targetingInfo = getVatFromCache(testIdForSuccess); - - const validTargeting = { - segments: validSegments, - mediaID: testIdForSuccess, - mediaUrl: 'source.mp4', - title: 'test', - description: 'this is a test' - }; - - expect(targetingInfo).to.deep.equal(validTargeting); - }); - }); - - describe('Fetch fails', function () { - beforeEach(function () { - fetchTargetingForMediaId(testIdForFailure); - request = server.requests[0] - }); - - it('should not write to cache when response is malformed', function() { - request.respond('{]'); - const targetingInfo = getVatFromCache(testIdForFailure); - expect(targetingInfo).to.be.null; - }); - - it('should not write to cache when playlist is absent', function() { - request.respond({}); - const targetingInfo = getVatFromCache(testIdForFailure); - expect(targetingInfo).to.be.null; - }); - - it('should not write to cache when playlist is empty', function() { - request.respond( - 200, - responseHeader, - JSON.stringify({ - playlist: [] - }) - ); - const targetingInfo = getVatFromCache(testIdForFailure); - expect(targetingInfo).to.be.null; - }); - - it('should not write to cache when request errors', function() { - request.error(); - const targetingInfo = getVatFromCache(testIdForFailure); - expect(targetingInfo).to.be.null; - }); - }); - }); - - describe('Format targeting response', function () { - it('should exclude segment key when absent', function () { - const targeting = formatTargetingResponse({ mediaID: 'test' }); - expect(targeting).to.not.have.property('segments'); - }); - - it('should exclude content block when mediaId is absent', function () { - const targeting = formatTargetingResponse({ segments: ['test'] }); - expect(targeting).to.not.have.property('content'); - }); - - it('should return proper format', function () { - const segments = ['123']; - const mediaID = 'test'; - const expectedContentId = 'jw_' + mediaID; - const expectedContent = { - id: expectedContentId - }; - const targeting = formatTargetingResponse({ - segments, - mediaID - }); - expect(targeting).to.have.deep.property('segments', segments); - expect(targeting).to.have.deep.property('content', expectedContent); - }); - }); - - describe('Get VAT from player', function () { - const mediaIdWithSegment = 'media_ID_1'; - const mediaIdNoSegment = 'media_ID_2'; - const mediaIdForCurrentItem = 'media_ID_current'; - const mediaIdNotCached = 'media_test_ID'; - - const validPlayerID = 'player_test_ID_valid'; - const invalidPlayerID = 'player_test_ID_invalid'; - - it('returns null when jwplayer.js is absent from page', function () { - const targeting = getVatFromPlayer(invalidPlayerID, mediaIdNotCached); - expect(targeting).to.be.null; - }); - - describe('When jwplayer.js is on page', function () { - const playlistItemWithSegmentMock = { - mediaid: mediaIdWithSegment, - title: 'Media With Segment', - description: 'The media has segments', - file: 'mediaWithSegments.mp4', - jwpseg: validSegments - }; - - const targetingForMediaWithSegment = { - segments: validSegments, - mediaID: mediaIdWithSegment, - title: 'Media With Segment', - description: 'The media has segments', - mediaUrl: 'mediaWithSegments.mp4', - }; - - const playlistItemNoSegmentMock = { - mediaid: mediaIdNoSegment, - title: 'Media Without Segment', - description: 'The media has no segments', - file: 'mediaWithoutSegments.mp4', - }; - - const currentItemSegments = ['test_seg_3', 'test_seg_4']; - const currentPlaylistItemMock = { - mediaid: mediaIdForCurrentItem, - jwpseg: currentItemSegments, - title: 'Current Item', - description: 'The current playlist item', - file: 'currentItem.mp4', - }; - const targetingForCurrentItem = { - segments: currentItemSegments, - mediaID: mediaIdForCurrentItem, - title: 'Current Item', - description: 'The current playlist item', - mediaUrl: 'currentItem.mp4', - }; - - const playerInstanceMock = { - getPlaylist: function () { - return [playlistItemWithSegmentMock, playlistItemNoSegmentMock]; - }, - - getPlaylistItem: function () { - return currentPlaylistItemMock; - } - }; - - const jwplayerMock = function(playerID) { - if (playerID === validPlayerID) { - return playerInstanceMock; - } else { - return {}; - } - }; - - beforeEach(function () { - window.jwplayer = jwplayerMock; - }); - - it('returns null when player ID does not match player on page', function () { - const targeting = getVatFromPlayer(invalidPlayerID, mediaIdNotCached); - expect(targeting).to.be.null; - }); - - it('returns targeting when media ID matches a playlist item', function () { - const targeting = getVatFromPlayer(validPlayerID, mediaIdWithSegment); - expect(targeting).to.deep.equal(targetingForMediaWithSegment); - }); - - it('caches item when media ID matches a valid playist item', function () { - getVatFromPlayer(validPlayerID, mediaIdWithSegment); - const vat = getVatFromCache(mediaIdWithSegment); - expect(vat).to.deep.equal(targetingForMediaWithSegment); - }); - - it('returns targeting of current item when media ID is missing', function () { - const targeting = getVatFromPlayer(validPlayerID); - expect(targeting).to.deep.equal(targetingForCurrentItem); - }); - - it('caches metadata from the current item', function () { - getVatFromPlayer(validPlayerID); - - window.jwplayer = null; - const targeting = getVatFromCache(mediaIdForCurrentItem); - expect(targeting).to.deep.equal(targetingForCurrentItem); - }); - - it('returns undefined segments when segments are absent', function () { - const targeting = getVatFromPlayer(validPlayerID, mediaIdNoSegment); - expect(targeting.segments).to.be.undefined; - expect(targeting.mediaID).to.equal(mediaIdNoSegment); - expect(targeting.title).to.equal('Media Without Segment'); - expect(targeting.description).to.equal('The media has no segments'); - expect(targeting.mediaUrl).to.equal('mediaWithoutSegments.mp4'); - }); - - describe('Get Bid Request Data', function () { - it('executes immediately while request is active if player has item', function () { - const bidRequestSpy = sinon.spy(); - - fetchTargetingForMediaId(mediaIdWithSegment); - - const bid = {}; - const adUnit = { - ortb2Imp: { - ext: { - data: { - jwTargeting: { - mediaID: mediaIdWithSegment, - playerDivId: validPlayerID - } - } - } - }, - bids: [ - bid - ] - }; - const expectedContentId = 'jw_' + mediaIdWithSegment; - const expectedTargeting = { - segments: validSegments, - content: { - id: expectedContentId - } - }; - jwplayerSubmodule.getBidRequestData({ adUnits: [adUnit] }, bidRequestSpy); - expect(bidRequestSpy.calledOnce).to.be.true; - expect(bid.rtd.jwplayer).to.have.deep.property('targeting', expectedTargeting); - server.respond(); - expect(bidRequestSpy.calledOnce).to.be.true; - }); - - it('includes backwards support for playerID when playerDivId is not set', function () { - const bidRequestSpy = sinon.spy(); - - fetchTargetingForMediaId(mediaIdWithSegment); - - const bid = {}; - const adUnit = { - ortb2Imp: { - ext: { - data: { - jwTargeting: { - mediaID: mediaIdWithSegment, - playerID: validPlayerID - } - } - } - }, - bids: [ - bid - ] - }; - const expectedContentId = 'jw_' + mediaIdWithSegment; - const expectedTargeting = { - segments: validSegments, - content: { - id: expectedContentId - } - }; - jwplayerSubmodule.getBidRequestData({ adUnits: [adUnit] }, bidRequestSpy); - expect(bidRequestSpy.calledOnce).to.be.true; - expect(bid.rtd.jwplayer).to.have.deep.property('targeting', expectedTargeting); - server.respond(); - expect(bidRequestSpy.calledOnce).to.be.true; - }); - }); - }); - }); - - describe('Enrich ad units', function () { - const contentIdForSuccess = 'jw_' + testIdForSuccess; - const expectedTargetingForSuccess = { - segments: validSegments, - content: { - id: contentIdForSuccess - } - }; - let bidRequestSpy; - let clock; - - beforeEach(function () { - bidRequestSpy = sinon.spy(); - - clock = sinon.useFakeTimers(); - }); - - afterEach(function () { - clock.restore(); - server.respond(); - }); - - it('adds targeting when pending request succeeds', function () { - fetchTargetingForMediaId(testIdForSuccess); - const bids = [ - { - id: 'bid1' - }, - { - id: 'bid2' - } - ]; - const adUnit = { - ortb2Imp: { - ext: { - data: { - jwTargeting: { - mediaID: testIdForSuccess - } - } - } - }, - bids - }; - - enrichAdUnits([adUnit]); - const bid1 = bids[0]; - const bid2 = bids[1]; - expect(bid1).to.not.have.property('rtd'); - expect(bid2).to.not.have.property('rtd'); - - const request = server.requests[0]; - request.respond( - 200, - responseHeader, - JSON.stringify({ - playlist: [ - { - file: 'test.mp4', - jwpseg: validSegments - } - ] - }) - ); - - expect(bid1.rtd.jwplayer).to.have.deep.property('targeting', expectedTargetingForSuccess); - expect(bid2.rtd.jwplayer).to.have.deep.property('targeting', expectedTargetingForSuccess); - }); - - it('immediately adds cached targeting', function () { - fetchTargetingForMediaId(testIdForSuccess); - const bids = [ - { - id: 'bid1' - }, - { - id: 'bid2' - } - ]; - const adUnit = { - ortb2Imp: { - ext: { - data: { - jwTargeting: { - mediaID: testIdForSuccess - } - } - } - }, - bids - }; - const request = server.requests[0]; - request.respond( - 200, - responseHeader, - JSON.stringify({ - playlist: [ - { - file: 'test.mp4', - jwpseg: validSegments - } - ] - }) - ); - - enrichAdUnits([adUnit]); - const bid1 = bids[0]; - const bid2 = bids[1]; - expect(bid1.rtd.jwplayer).to.have.deep.property('targeting', expectedTargetingForSuccess); - expect(bid2.rtd.jwplayer).to.have.deep.property('targeting', expectedTargetingForSuccess); - }); - - it('adds content block when segments are absent and no request is pending', function () { - const expectedTargetingForFailure = { - content: { - id: 'jw_' + testIdForFailure - } - }; - const bids = [ - { - id: 'bid1' - }, - { - id: 'bid2' - } - ]; - const adUnit = { - ortb2Imp: { - ext: { - data: { - jwTargeting: { - mediaID: testIdForFailure - } - } - } - }, - bids - }; - - enrichAdUnits([adUnit]); - const bid1 = bids[0]; - const bid2 = bids[1]; - expect(bid1.rtd.jwplayer).to.have.deep.property('targeting', expectedTargetingForFailure); - expect(bid2.rtd.jwplayer).to.have.deep.property('targeting', expectedTargetingForFailure); - }); - - it('should write to config', function () { - fetchTargetingForMediaId(testIdForSuccess); - const bids = [ - { - id: 'bid1' - }, - { - id: 'bid2' - } - ]; - const adUnit = { - ortb2Imp: { - ext: { - data: { - jwTargeting: { - mediaID: testIdForSuccess - } - } - } - }, - bids - }; - - const ortb2Fragments = {global: {}}; - enrichAdUnits([adUnit], ortb2Fragments); - const bid1 = bids[0]; - const bid2 = bids[1]; - expect(bid1).to.not.have.property('rtd'); - expect(bid2).to.not.have.property('rtd'); - - const request = server.requests[0]; - request.respond( - 200, - responseHeader, - JSON.stringify({ - playlist: [ - { - file: 'test.mp4', - jwpseg: validSegments, - title: 'test title', - description: 'test description', - } - ] - }) - ); - - expect(ortb2Fragments.global).to.have.property('site'); - expect(ortb2Fragments.global.site).to.have.property('content'); - expect(ortb2Fragments.global.site.content).to.have.property('id', 'jw_' + testIdForSuccess); - expect(ortb2Fragments.global.site.content).to.have.property('url', 'test.mp4'); - expect(ortb2Fragments.global.site.content).to.have.property('title', 'test title'); - expect(ortb2Fragments.global.site.content.ext).to.have.property('description', 'test description'); - expect(ortb2Fragments.global.site.content).to.have.property('data'); - const data = ortb2Fragments.global.site.content.data; - expect(data).to.have.length(1); - const datum = data[0]; - expect(datum).to.have.property('name', 'jwplayer.com'); - expect(datum).to.have.property('ext'); - expect(datum.ext).to.have.property('segtax', 502); - expect(datum.segment).to.have.length(2); - const segment1 = datum.segment[0]; - const segment2 = datum.segment[1]; - expect(segment1).to.have.property('id', 'test_seg_1'); - expect(segment2).to.have.property('id', 'test_seg_2'); - }); - - it('should remove obsolete jwplayer data', function () { - fetchTargetingForMediaId(testIdForSuccess); - const bids = [ - { - id: 'bid1' - } - ]; - const adUnit = { - ortb2Imp: { - ext: { - data: { - jwTargeting: { - mediaID: testIdForSuccess - } - } - } - }, - bids - }; - - const ortb2Fragments = { - global: { - site: { - content: { - id: 'randomContentId', - data: [{ - name: 'random', - segment: [{id: 'random'}] - }, { - name: 'jwplayer.com', - segment: [{id: 'randomJwPlayer'}] - }, { - name: 'random2', - segment: [{id: 'random2'}] - }] - } - } - } - }; - - enrichAdUnits([adUnit], ortb2Fragments); - const bid1 = bids[0]; - expect(bid1).to.not.have.property('rtd'); - - const request = server.requests[0]; - request.respond( - 200, - responseHeader, - JSON.stringify({ - playlist: [ - { - file: 'test.mp4', - jwpseg: validSegments - } - ] - }) - ); - - expect(ortb2Fragments.global).to.have.property('site'); - expect(ortb2Fragments.global.site).to.have.property('content'); - expect(ortb2Fragments.global.site.content).to.have.property('id', 'randomContentId'); - expect(ortb2Fragments.global.site.content).to.have.property('data'); - const data = ortb2Fragments.global.site.content.data; - expect(data).to.have.length(3); - - const randomDatum = data[0]; - expect(randomDatum).to.have.property('name', 'random'); - expect(randomDatum.segment).to.deep.equal([{id: 'random'}]); - - const randomDatum2 = data[1]; - expect(randomDatum2).to.have.property('name', 'random2'); - expect(randomDatum2.segment).to.deep.equal([{id: 'random2'}]); - - const jwplayerDatum = data[2]; - expect(jwplayerDatum).to.have.property('name', 'jwplayer.com'); - expect(jwplayerDatum).to.have.property('ext'); - expect(jwplayerDatum.ext).to.have.property('segtax', 502); - expect(jwplayerDatum.segment).to.have.length(2); - const segment1 = jwplayerDatum.segment[0]; - const segment2 = jwplayerDatum.segment[1]; - expect(segment1).to.have.property('id', 'test_seg_1'); - expect(segment2).to.have.property('id', 'test_seg_2'); - }); - }); - - describe('Extract Publisher Params', function () { - const config = { mediaID: 'test' }; - - it('should exclude adUnits that do not support instream video and do not specify jwTargeting', function () { - const oustreamAdUnit = { mediaTypes: { video: { context: 'outstream' } } }; - const oustreamTargeting = extractPublisherParams(oustreamAdUnit, config); - expect(oustreamTargeting).to.be.undefined; - - const bannerAdUnit = { mediaTypes: { banner: {} } }; - const bannerTargeting = extractPublisherParams(bannerAdUnit, config); - expect(bannerTargeting).to.be.undefined; - - const targeting = extractPublisherParams({}, config); - expect(targeting).to.be.undefined; - }); - - it('should include ad unit when media type is video and is instream', function () { - const adUnit = { mediaTypes: { video: { context: 'instream' } } }; - const targeting = extractPublisherParams(adUnit, config); - expect(targeting).to.deep.equal(config); - }); - - it('should include banner ad units that specify jwTargeting', function() { - const adUnit = { mediaTypes: { banner: {} }, ortb2Imp: { ext: { data: { jwTargeting: {} } } } }; - const targeting = extractPublisherParams(adUnit, config); - expect(targeting).to.deep.equal(config); - }); - - it('should include outstream ad units that specify jwTargeting', function() { - const adUnit = { mediaTypes: { video: { context: 'outstream' } }, ortb2Imp: { ext: { data: { jwTargeting: {} } } } }; - const targeting = extractPublisherParams(adUnit, config); - expect(targeting).to.deep.equal(config); - }); - - it('should fallback to config when empty jwTargeting is defined in ad unit', function () { - const adUnit = { ortb2Imp: { ext: { data: { jwTargeting: {} } } } }; - const targeting = extractPublisherParams(adUnit, config); - expect(targeting).to.deep.equal(config); - }); - - it('should prioritize adUnit properties ', function () { - const expectedMediaID = 'test_media_id'; - const expectedPlayerID = 'test_player_id'; - const config = { playerDivId: 'bad_id', mediaID: 'bad_id' }; - - const adUnit = { ortb2Imp: { ext: { data: { jwTargeting: { mediaID: expectedMediaID, playerDivId: expectedPlayerID } } } } }; - const targeting = extractPublisherParams(adUnit, config); - expect(targeting).to.have.property('mediaID', expectedMediaID); - expect(targeting).to.have.property('playerDivId', expectedPlayerID); - }); - - it('should use config properties as fallbacks', function () { - const expectedMediaID = 'test_media_id'; - const expectedPlayerID = 'test_player_id'; - const config = { playerDivId: expectedPlayerID, mediaID: 'bad_id' }; - - const adUnit = { ortb2Imp: { ext: { data: { jwTargeting: { mediaID: expectedMediaID } } } } }; - const targeting = extractPublisherParams(adUnit, config); - expect(targeting).to.have.property('mediaID', expectedMediaID); - expect(targeting).to.have.property('playerDivId', expectedPlayerID); - }); - - it('should return undefined when Publisher Params are absent', function () { - const targeting = extractPublisherParams({}, null); - expect(targeting).to.be.undefined; - }) - }); - - describe('Get content id', function() { - it('prefixes jw_ to the media id', function () { - const mediaId = 'mediaId'; - const contentId = getContentId(mediaId); - expect(contentId).to.equal('jw_mediaId'); - }); - - it('returns undefined when media id is empty', function () { - let contentId = getContentId(); - expect(contentId).to.be.undefined; - contentId = getContentId(''); - expect(contentId).to.be.undefined; - contentId = getContentId(null); - expect(contentId).to.be.undefined; - }); - }); - - describe('Get Content Segments', function () { - it('returns undefined when segments are empty', function () { - let contentSegments = getContentSegments(null); - expect(contentSegments).to.be.undefined; - contentSegments = getContentSegments(undefined); - expect(contentSegments).to.be.undefined; - contentSegments = getContentSegments([]); - expect(contentSegments).to.be.undefined; - }); - - it('returns proper format', function () { - const segment1 = 'segment1'; - const segment2 = 'segment2'; - const segment3 = 'segment3'; - const contentSegments = getContentSegments([segment1, segment2, segment3]); - expect(contentSegments[0]).to.deep.equal({ id: segment1 }); - expect(contentSegments[1]).to.deep.equal({ id: segment2 }); - expect(contentSegments[2]).to.deep.equal({ id: segment3 }); - }); - }); - - describe('Get Content Data', function () { - it('should return proper format', function () { - const testMediaId = 'test_media_id'; - const testSegments = [{ id: 1 }, { id: 2 }]; - const contentData = getContentData(testMediaId, testSegments); - expect(contentData).to.have.property('name', 'jwplayer.com'); - expect(contentData.ext).to.have.property('segtax', 502); - expect(contentData).to.have.property('cids'); - expect(contentData.cids).to.have.length(1); - expect(contentData.cids[0]).to.equal(testMediaId); - expect(contentData.ext).to.have.property('cids'); - expect(contentData.ext.cids).to.have.length(1); - expect(contentData.ext.cids[0]).to.equal(testMediaId); - expect(contentData.segment).to.deep.equal(testSegments); - }); - - it('should only set segtax and segment when segments are provided', function () { - const testMediaId = 'test_media_id'; - const contentData = getContentData(testMediaId); - expect(contentData).to.have.property('name', 'jwplayer.com'); - expect(contentData.ext.segtax).to.be.undefined; - expect(contentData).to.have.property('cids'); - expect(contentData.cids).to.have.length(1); - expect(contentData.cids[0]).to.equal(testMediaId); - expect(contentData.ext).to.have.property('cids'); - expect(contentData.ext.cids).to.have.length(1); - expect(contentData.ext.cids[0]).to.equal(testMediaId); - expect(contentData.segment).to.be.undefined; - }); - - it('should only set cids when a media id is provided', function () { - const testSegments = [{ id: 1 }, { id: 2 }]; - const contentData = getContentData(null, testSegments); - expect(contentData).to.have.property('name', 'jwplayer.com'); - expect(contentData.ext).to.have.property('segtax', 502); - expect(contentData).to.not.have.property('cids'); - expect(contentData.ext).to.not.have.property('cids'); - expect(contentData.segment).to.deep.equal(testSegments); - }); - - it('should return undefined when no params are provided', function () { - expect(getContentData()).to.be.undefined; - }); - }); - - describe(' Add Ortb Site Content', function () { - beforeEach(() => { - setOverrides({ - overrideContentId: 'whenEmpty', - overrideContentUrl: 'whenEmpty', - overrideContentTitle: 'whenEmpty', - overrideContentDescription: 'whenEmpty' - }); - }); - - it('should maintain object structure when id and data params are empty', function () { - const ortb2 = { - site: { - content: { - id: 'randomId' - }, - random: { - random_sub: 'randomSub' - } - }, - app: { - content: { - id: 'appId' - } - } - } - const copy = deepClone(ortb2); - addOrtbSiteContent(copy); - expect(copy).to.eql(ortb2); - }); - - it('should create a structure compliant with the oRTB 2 spec', function() { - const ortb2 = {} - const expectedId = 'expectedId'; - const expectedUrl = 'expectedUrl'; - const expectedTitle = 'expectedTitle'; - const expectedDescription = 'expectedDescription'; - const expectedData = { datum: 'datum' }; - addOrtbSiteContent(ortb2, expectedId, expectedData, expectedTitle, expectedDescription, expectedUrl); - expect(ortb2).to.have.nested.property('site.content.id', expectedId); - expect(ortb2).to.have.nested.property('site.content.url', expectedUrl); - expect(ortb2).to.have.nested.property('site.content.title', expectedTitle); - expect(ortb2).to.have.nested.property('site.content.ext.description', expectedDescription); - expect(ortb2).to.have.nested.property('site.content.data'); - expect(ortb2.site.content.data[0]).to.be.deep.equal(expectedData); - }); - - it('should respect existing structure when adding adding fields', function () { - const ortb2 = { - site: { - content: { - id: 'oldId', - ext: { - random_field: 'randomField' - } - }, - random: { - random_sub: 'randomSub' - }, - }, - app: { - content: { - id: 'appId' - } - } - }; - - const newId = 'newId'; - const expectedUrl = 'expectedUrl'; - const expectedTitle = 'expectedTitle'; - const expectedDescription = 'expectedDescription'; - const expectedData = { datum: 'datum' }; - addOrtbSiteContent(ortb2, newId, expectedData, expectedTitle, expectedDescription, expectedUrl); - expect(ortb2).to.have.nested.property('site.random.random_sub', 'randomSub'); - expect(ortb2).to.have.nested.property('app.content.id', 'appId'); - expect(ortb2).to.have.nested.property('site.content.ext.random_field', 'randomField'); - expect(ortb2).to.have.nested.property('site.content.id', 'oldId'); - expect(ortb2).to.have.nested.property('site.content.url', expectedUrl); - expect(ortb2).to.have.nested.property('site.content.title', expectedTitle); - expect(ortb2).to.have.nested.property('site.content.ext.description', expectedDescription); - expect(ortb2).to.have.nested.property('site.content.data'); - expect(ortb2.site.content.data[0]).to.be.deep.equal(expectedData); - }); - - it('should set content id by default when absent from ortb2', function () { - const ortb2 = {}; - const expectedId = 'expectedId'; - addOrtbSiteContent(ortb2, expectedId); - expect(ortb2).to.have.nested.property('site.content.id', expectedId); - }); - - it('should keep old content id by default', function () { - const ortb2 = { - site: { - content: { - id: 'oldId' - } - } - }; - - addOrtbSiteContent(ortb2, 'newId'); - expect(ortb2).to.have.nested.property('site.content.id', 'oldId'); - }); - - it('should keep previous content id when new value is not available', function () { - const previousId = 'oldId'; - const ortb2 = { - site: { - content: { - id: previousId, - data: [{ datum: 'first_datum' }] - } - } - }; - - addOrtbSiteContent(ortb2, null, { datum: 'new_datum' }); - expect(ortb2).to.have.nested.property('site.content.id', previousId); - }); - - it('should override content id when override is always', function () { - setOverrides({ - overrideContentId: 'always', - }); - - const ortb2 = { - site: { - content: { - id: 'oldId' - } - } - }; - - const expectedId = 'expectedId'; - addOrtbSiteContent(ortb2, expectedId); - expect(ortb2).to.have.nested.property('site.content.id', expectedId); - }); - - it('should keep previous content id when override is always and new value is not available', function () { - setOverrides({ - overrideContentId: 'always', - }); - - const ortb2 = { - site: { - content: { - id: 'oldId' - } - } - }; - - addOrtbSiteContent(ortb2); - expect(ortb2).to.have.nested.property('site.content.id', 'oldId'); - }); - - it('should populate content id when override is whenEmpty and value is empty', function () { - setOverrides({ - overrideContentId: 'whenEmpty', - }); - - const ortb2 = { - site: { - content: { - } - } - }; - - addOrtbSiteContent(ortb2, 'newId'); - expect(ortb2).to.have.nested.property('site.content.id', 'newId'); - }); - - it('should keep previous content id when override is whenEmpty and value is already populated', function () { - setOverrides({ - overrideContentId: 'whenEmpty', - }); - - const ortb2 = { - site: { - content: { - id: 'oldId' - } - } - }; - - addOrtbSiteContent(ortb2, 'newId'); - expect(ortb2).to.have.nested.property('site.content.id', 'oldId'); - }); - - it('should keep previous content id when override is whenEmpty and new value is not available', function () { - setOverrides({ - overrideContentId: 'whenEmpty', - }); - - const ortb2 = { - site: { - content: { - } - } - }; - - addOrtbSiteContent(ortb2); - expect(ortb2.site.content.id).to.be.undefined; - }); - - it('should keep previous content id when overrideContentId is set to never', function () { - setOverrides({ - overrideContentId: 'never', - }); - - const ortb2 = { - site: { - content: { - id: 'oldId' - } - } - }; - - addOrtbSiteContent(ortb2, 'newId'); - expect(ortb2).to.have.nested.property('site.content.id', 'oldId'); - }); - - it('should not populate content id when override is set to never', function () { - setOverrides({ - overrideContentId: 'never', - }); - - const ortb2 = { - site: { - content: {} - } - }; - - addOrtbSiteContent(ortb2, 'newId'); - expect(ortb2.site.content.id).to.be.undefined; - }); - - it('should set content data', function () { - const ortb2 = {}; - const expectedData = { datum: 'datum' }; - addOrtbSiteContent(ortb2, null, expectedData); - expect(ortb2).to.have.nested.property('site.content.data'); - expect(ortb2.site.content.data).to.have.length(1); - expect(ortb2.site.content.data[0]).to.be.deep.equal(expectedData); - }); - - it('should append content data', function () { - const ortb2 = { - site: { - content: { - data: [{ datum: 'first_datum' }] - } - } - }; - - const expectedData = { datum: 'datum' }; - addOrtbSiteContent(ortb2, null, expectedData); - expect(ortb2).to.have.nested.property('site.content.data'); - expect(ortb2.site.content.data).to.have.length(2); - expect(ortb2.site.content.data.pop()).to.be.deep.equal(expectedData); - }); - - it('should keep previous data when not set', function () { - const expectedId = 'expectedId'; - const expectedData = { datum: 'first_datum' }; - const ortb2 = { - site: { - content: { - data: [expectedData] - } - } - }; - - addOrtbSiteContent(ortb2, expectedId); - expect(ortb2).to.have.nested.property('site.content.data'); - expect(ortb2.site.content.data).to.have.length(1); - expect(ortb2.site.content.data[0]).to.be.deep.equal(expectedData); - expect(ortb2).to.have.nested.property('site.content.id', expectedId); - }); - - it('should set content title by default when absent from ortb2', function () { - const ortb2 = {}; - const expectedTitle = 'expectedTitle'; - addOrtbSiteContent(ortb2, null, null, expectedTitle); - expect(ortb2).to.have.nested.property('site.content.title', expectedTitle); - }); - - it('should keep previous content title by default when already defined', function () { - const ortb2 = { - site: { - content: { - title: 'oldTitle' - } - } - }; - - addOrtbSiteContent(ortb2, null, null, 'newTitle'); - expect(ortb2).to.have.nested.property('site.content.title', 'oldTitle'); - }); - - it('should keep previous content title by default when new value is not available', function () { - const ortb2 = { - site: { - content: { - title: 'oldTitle', - data: [{ datum: 'first_datum' }] - } - } - }; - - addOrtbSiteContent(ortb2, null, { datum: 'new_datum' }); - expect(ortb2).to.have.nested.property('site.content.title', 'oldTitle'); - }); - - it('should override content title when override is always', function () { - setOverrides({ - overrideContentTitle: 'always', - }); - - const ortb2 = { - site: { - content: { - title: 'oldTitle' - } - } - }; - - addOrtbSiteContent(ortb2, null, null, 'newTitle'); - expect(ortb2).to.have.nested.property('site.content.title', 'newTitle'); - }); - - it('should keep previous content title when override is always and new value is not available', function () { - setOverrides({ - overrideContentTitle: 'always', - }); - - const ortb2 = { - site: { - content: { - title: 'oldTitle' - } - } - }; - - addOrtbSiteContent(ortb2); - expect(ortb2).to.have.nested.property('site.content.title', 'oldTitle'); - }); - - it('should populate content title when override is whenEmpty and value is empty', function () { - setOverrides({ - overrideContentTitle: 'whenEmpty', - }); - - const ortb2 = { - site: { - content: { - } - } - }; - - addOrtbSiteContent(ortb2, null, null, 'newTitle'); - expect(ortb2).to.have.nested.property('site.content.title', 'newTitle'); - }); - - it('should keep previous content title when override is whenEmpty and value is already populated', function () { - setOverrides({ - overrideContentTitle: 'whenEmpty', - }); - - const ortb2 = { - site: { - content: { - title: 'oldTitle' - } - } - }; - - addOrtbSiteContent(ortb2, null, null, 'newTitle'); - expect(ortb2).to.have.nested.property('site.content.title', 'oldTitle'); - }); - - it('should keep previous content title when override is whenEmpty and new value is not available', function () { - setOverrides({ - overrideContentTitle: 'whenEmpty', - }); - - const ortb2 = { - site: { - content: { - } - } - }; - - addOrtbSiteContent(ortb2); - expect(ortb2.site.content.title).to.be.undefined; - }); - - it('should keep previous content title when override is set to never', function () { - setOverrides({ - overrideContentTitle: 'never', - }); - - const ortb2 = { - site: { - content: { - title: 'oldTitle' - } - } - }; - - addOrtbSiteContent(ortb2, null, null, 'newTitle'); - expect(ortb2).to.have.nested.property('site.content.title', 'oldTitle'); - }); - - it('should not populate content title when override is set to never', function () { - setOverrides({ - overrideContentTitle: 'never', - }); - - const ortb2 = { - site: { - content: {} - } - }; - - addOrtbSiteContent(ortb2, null, null, 'newTitle'); - expect(ortb2.site.content.title).to.be.undefined; - }); - - it('should set content description by default when absent from ortb2', function () { - const ortb2 = {}; - const expectedDescription = 'expectedDescription'; - addOrtbSiteContent(ortb2, null, null, null, expectedDescription); - expect(ortb2).to.have.nested.property('site.content.ext.description', expectedDescription); - }); - - it('should keep previous content description by default when already defined', function () { - const ortb2 = { - site: { - content: { - ext: { - description: 'oldDescription' - } - } - } - }; - - addOrtbSiteContent(ortb2, null, null, null, 'newDescription'); - expect(ortb2).to.have.nested.property('site.content.ext.description', 'oldDescription'); - }); - - it('should override content description when override is always', function () { - setOverrides({ - overrideContentDescription: 'always', - }); - - const ortb2 = { - site: { - content: { - ext: { - description: 'oldDescription' - } - } - } - }; - - addOrtbSiteContent(ortb2, null, null, null, 'newDescription'); - expect(ortb2).to.have.nested.property('site.content.ext.description', 'newDescription'); - }); - - it('should keep previous content description when override is always and new value is not available', function () { - setOverrides({ - overrideContentDescription: 'always', - }); - - const ortb2 = { - site: { - content: { - ext: { - description: 'oldDescription' - } - } - } - }; - - addOrtbSiteContent(ortb2); - expect(ortb2).to.have.nested.property('site.content.ext.description', 'oldDescription'); - }); - - it('should populate content description when override is whenEmpty and value is empty', function () { - setOverrides({ - overrideContentDescription: 'whenEmpty', - }); - - const ortb2 = { - site: { - content: { - } - } - }; - - addOrtbSiteContent(ortb2, null, null, null, 'newDescription'); - expect(ortb2).to.have.nested.property('site.content.ext.description', 'newDescription'); - }); - - it('should keep previous content description when override is whenEmpty and value is already populated', function () { - setOverrides({ - overrideContentDescription: 'whenEmpty', - }); - - const ortb2 = { - site: { - content: { - ext: { - description: 'oldDescription' - } - } - } - }; - - addOrtbSiteContent(ortb2, null, null, null, 'newDescription'); - expect(ortb2).to.have.nested.property('site.content.ext.description', 'oldDescription'); - }); - - it('should keep previous content description when override is whenEmpty and new value is not available', function () { - setOverrides({ - overrideContentDescription: 'whenEmpty', - }); - - const ortb2 = { - site: { - content: { - } - } - }; - - addOrtbSiteContent(ortb2); - expect(ortb2.site.content.ext).to.be.undefined; - }); - - it('should keep previous content description when override is set to never', function () { - setOverrides({ - overrideContentDescription: 'never', - }); - - const ortb2 = { - site: { - content: { - ext: { - description: 'oldDescription' - } - } - } - }; - - addOrtbSiteContent(ortb2, null, null, null, 'newDescription'); - expect(ortb2).to.have.nested.property('site.content.ext.description', 'oldDescription'); - }); - - it('should not populate content description when override is set to never', function () { - setOverrides({ - overrideContentDescription: 'never', - }); - - const ortb2 = { - site: { - content: {} - } - }; - - addOrtbSiteContent(ortb2); - expect(ortb2.site.content.ext).to.be.undefined; - }); - - it('should set content url by default when absent from ortb2', function () { - const ortb2 = {}; - const expectedUrl = 'expectedUrl'; - addOrtbSiteContent(ortb2, null, null, null, null, expectedUrl); - expect(ortb2).to.have.nested.property('site.content.url', expectedUrl); - }); - - it('should keep previous content url by default when new value is not available', function () { - const ortb2 = { - site: { - content: { - url: 'oldUrl', - data: [{ datum: 'first_datum' }] - } - } - }; - - addOrtbSiteContent(ortb2, null, { datum: 'new_datum' }); - expect(ortb2).to.have.nested.property('site.content.url', 'oldUrl'); - }); - - it('should keep previous content url by default when already defined', function () { - const ortb2 = { - site: { - content: { - url: 'oldUrl', - } - } - }; - - addOrtbSiteContent(ortb2, null, null, null, null, 'newUrl'); - expect(ortb2).to.have.nested.property('site.content.url', 'oldUrl'); - }); - - it('should override content url when override is always', function () { - setOverrides({ - overrideContentUrl: 'always', - }); - - const ortb2 = { - site: { - content: { - url: 'oldUrl', - } - } - }; - - const expectedUrl = 'expectedUrl'; - addOrtbSiteContent(ortb2, null, null, null, null, expectedUrl); - expect(ortb2).to.have.nested.property('site.content.url', expectedUrl); - }); - - it('should keep previous content url when override is always and new value is not available', function () { - setOverrides({ - overrideContentUrl: 'always', - }); - - const ortb2 = { - site: { - content: { - url: 'oldUrl', - } - } - }; - - addOrtbSiteContent(ortb2); - expect(ortb2).to.have.nested.property('site.content.url', 'oldUrl'); - }); - - it('should populate content url when override is whenEmpty and value is empty', function () { - setOverrides({ - overrideContentUrl: 'whenEmpty', - }); - - const ortb2 = { - site: { - content: { - } - } - }; - - const expectedUrl = 'expectedUrl'; - addOrtbSiteContent(ortb2, null, null, null, null, expectedUrl); - expect(ortb2).to.have.nested.property('site.content.url', expectedUrl); - }); - - it('should keep previous content url when override is whenEmpty and value is already populated', function () { - setOverrides({ - overrideContentUrl: 'whenEmpty', - }); - - const ortb2 = { - site: { - content: { - url: 'oldUrl', - } - } - }; - - addOrtbSiteContent(ortb2, null, null, null, null, 'newUrl'); - expect(ortb2).to.have.nested.property('site.content.url', 'oldUrl'); - }); - - it('should keep previous content url when override is whenEmpty and new value is not available', function () { - setOverrides({ - overrideContentUrl: 'whenEmpty', - }); - - const ortb2 = { - site: { - content: { - } - } - }; - - addOrtbSiteContent(ortb2); - expect(ortb2.site.content.url).to.be.undefined; - }); - - it('should keep previous content url when override is set to never', function () { - setOverrides({ - overrideContentUrl: 'never', - }); - - const ortb2 = { - site: { - content: { - url: 'oldUrl', - } - } - }; - - addOrtbSiteContent(ortb2, null, null, null, null, 'newUrl'); - expect(ortb2).to.have.nested.property('site.content.url', 'oldUrl'); - }); - - it('should not populate content url when override is set to never', function () { - setOverrides({ - overrideContentUrl: 'never', - }); - - const ortb2 = { - site: { - content: {} - } - }; - - addOrtbSiteContent(ortb2, null, null, null, null, 'newUrl'); - expect(ortb2.site.content.url).to.be.undefined; - }); - }); - - describe('Add Targeting to Bid', function () { - const targeting = {foo: 'bar'}; - - it('creates realTimeData when absent from Bid', function () { - const targeting = {foo: 'bar'}; - const bid = {}; - addTargetingToBid(bid, targeting); - expect(bid).to.have.property('rtd'); - expect(bid).to.have.nested.property('rtd.jwplayer.targeting', targeting); - }); - - it('adds to existing realTimeData', function () { - const otherRtd = { - targeting: { - seg: 'rtd seg' - } - }; - - const bid = { - rtd: { - otherRtd - } - }; - - addTargetingToBid(bid, targeting); - expect(bid).to.have.property('rtd'); - const rtd = bid.rtd; - expect(rtd).to.have.property('jwplayer'); - expect(rtd).to.have.nested.property('jwplayer.targeting', targeting); - - expect(rtd).to.have.deep.property('otherRtd', otherRtd); - }); - - it('adds to existing realTimeData.jwplayer', function () { - const otherInfo = { seg: 'rtd seg' }; - const bid = { - rtd: { - jwplayer: { - otherInfo - } - } - }; - addTargetingToBid(bid, targeting); - - expect(bid).to.have.property('rtd'); - const rtd = bid.rtd; - expect(rtd).to.have.property('jwplayer'); - expect(rtd).to.have.nested.property('jwplayer.otherInfo', otherInfo); - expect(rtd).to.have.nested.property('jwplayer.targeting', targeting); - }); - - it('overrides existing jwplayer.targeting', function () { - const otherInfo = { seg: 'rtd seg' }; - const bid = { - rtd: { - jwplayer: { - targeting: { - otherInfo - } - } - } - }; - addTargetingToBid(bid, targeting); - - expect(bid).to.have.property('rtd'); - const rtd = bid.rtd; - expect(rtd).to.have.property('jwplayer'); - expect(rtd).to.have.nested.property('jwplayer.targeting', targeting); - }); - - it('creates jwplayer when absent from realTimeData', function () { - const bid = { rtd: {} }; - addTargetingToBid(bid, targeting); - - expect(bid).to.have.property('rtd'); - const rtd = bid.rtd; - expect(rtd).to.have.property('jwplayer'); - expect(rtd).to.have.nested.property('jwplayer.targeting', targeting); - }); - }); - - describe('Player detection', function () { - const playerInstanceMock = { - getPlaylist: () => [], - getPlaylistItem: () => ({}) - }; - - beforeEach(function () { - window.jwplayer = sinon.stub(); - }); - - afterEach(function () { - delete window.jwplayer; - }); - - it('should fail if jwplayer global does not exist', function () { - delete window.jwplayer; - expect(getPlayer('divId')).to.be.undefined; - }); - - it('should return the player instance for the specified div id', function () { - window.jwplayer.returns(playerInstanceMock); - const player = getPlayer('divId'); - expect(player).to.deep.equal(playerInstanceMock); - }); - - it('should request a player when the div id does not match a player on the page and only 1 player is in the DOM', function () { - const playerDomElement = document.createElement('div'); - playerDomElement.className = 'jwplayer'; - document.body.appendChild(playerDomElement); - - window.jwplayer.withArgs('invalidDivId').returns(undefined); - window.jwplayer.returns(playerInstanceMock); - - const playerInstance = getPlayer('invalidDivId'); - - expect(playerInstance).to.deep.equal(playerInstanceMock); - - document.body.removeChild(playerDomElement); - }); - - it('should fail when the div id does not match a player on the page, and multiple players are instantiated', function () { - const firstPlayerDomElement = document.createElement('div'); - const secondPlayerDomElement = document.createElement('div'); - firstPlayerDomElement.className = 'jwplayer'; - secondPlayerDomElement.className = 'jwplayer'; - document.body.appendChild(firstPlayerDomElement); - document.body.appendChild(secondPlayerDomElement); - - window.jwplayer.withArgs('invalidDivId').returns(undefined); - window.jwplayer.returns(playerInstanceMock); - - const playerInstance = getPlayer('invalidDivId'); - - expect(playerInstance).to.be.undefined; - - document.body.removeChild(firstPlayerDomElement); - document.body.removeChild(secondPlayerDomElement); - }); - }); - - describe('jwplayerSubmodule', function () { - it('successfully instantiates', function () { - expect(jwplayerSubmodule.init()).to.equal(true); - }); - - describe('Get Bid Request Data', function () { - const validMediaIDs = ['media_ID_1', 'media_ID_2', 'media_ID_3']; - let bidRequestSpy; - let clock; - let bidReqConfig; - - beforeEach(function () { - bidReqConfig = { - adUnits: [ - { - ortb2Imp: { - ext: { - data: { - jwTargeting: { - mediaID: validMediaIDs[0] - } - } - } - }, - bids: [ - {}, {} - ] - }, - { - ortb2Imp: { - ext: { - data: { - jwTargeting: { - mediaID: validMediaIDs[1] - } - } - } - }, - bids: [ - {}, {} - ] - } - ] - }; - - bidRequestSpy = sinon.spy(); - - clock = sinon.useFakeTimers(); - }); - - afterEach(function () { - clock.restore(); - server.respond(); - }); - - it('executes callback immediately when ad units are missing', function () { - jwplayerSubmodule.getBidRequestData({ adUnits: [] }, bidRequestSpy); - expect(bidRequestSpy.calledOnce).to.be.true; - }); - - it('executes callback immediately when no requests are pending', function () { - fetchTargetingInformation({ - mediaIDs: [] - }); - jwplayerSubmodule.getBidRequestData(bidReqConfig, bidRequestSpy); - expect(bidRequestSpy.calledOnce).to.be.true; - }); - - it('executes callback only after requests in adUnit complete', function() { - fetchTargetingInformation({ - mediaIDs: validMediaIDs - }); - jwplayerSubmodule.getBidRequestData(bidReqConfig, bidRequestSpy); - expect(bidRequestSpy.notCalled).to.be.true; - - const req1 = server.requests[0]; - const req2 = server.requests[1]; - const req3 = server.requests[2]; - - req1.respond(); - expect(bidRequestSpy.notCalled).to.be.true; - - req2.respond(); - expect(bidRequestSpy.calledOnce).to.be.true; - - req3.respond(); - expect(bidRequestSpy.calledOnce).to.be.true; - }); - - it('sets targeting data in proper structure', function () { - const bid = {}; - const adUnitWithMediaId = { - ortb2Imp: { - ext: { - data: { - jwTargeting: { - mediaID: testIdForSuccess - } - } - } - }, - bids: [ - bid - ] - }; - const adUnitEmpty = { - code: 'test_ad_unit_empty' - }; - const expectedContentId = 'jw_' + testIdForSuccess; - const expectedTargeting = { - segments: validSegments, - content: { - id: expectedContentId - } - }; - jwplayerSubmodule.getBidRequestData({ adUnits: [adUnitWithMediaId, adUnitEmpty] }, bidRequestSpy); - expect(bidRequestSpy.calledOnce).to.be.true; - expect(bid.rtd.jwplayer).to.have.deep.property('targeting', expectedTargeting); - }); - - it('excludes segments when absent', function () { - const adUnitCode = 'test_ad_unit'; - const bid = {}; - const adUnit = { - ortb2Imp: { - ext: { - data: { - jwTargeting: { - mediaID: testIdForFailure - } - } - } - }, - bids: [ bid ] - }; - const expectedContentId = 'jw_' + adUnit.ortb2Imp.ext.data.jwTargeting.mediaID; - const expectedTargeting = { - content: { - id: expectedContentId - } - }; - - jwplayerSubmodule.getBidRequestData({ adUnits: [ adUnit ] }, bidRequestSpy); - expect(bidRequestSpy.calledOnce).to.be.true; - expect(bid.rtd.jwplayer.targeting).to.not.have.property('segments'); - expect(bid.rtd.jwplayer.targeting).to.not.have.property('segments'); - expect(bid.rtd.jwplayer).to.have.deep.property('targeting', expectedTargeting); - }); - - it('does not modify bid when jwTargeting block is absent', function () { - const adUnitCode = 'test_ad_unit'; - const bid1 = {}; - const bid2 = {}; - const bid3 = {}; - const adUnitWithMediaId = { - code: adUnitCode, - mediaID: testIdForSuccess, - bids: [ bid1 ] - }; - const adUnitEmpty = { - code: 'test_ad_unit_empty', - bids: [ bid2 ] - }; - - const adUnitEmptyfpd = { - code: 'test_ad_unit_empty_fpd', - ortb2Imp: { - ext: { - id: 'sthg' - } - }, - bids: [ bid3 ] - }; - - jwplayerSubmodule.getBidRequestData({ adUnits: [adUnitWithMediaId, adUnitEmpty, adUnitEmptyfpd] }, bidRequestSpy); - expect(bidRequestSpy.calledOnce).to.be.true; - expect(bid1).to.not.have.property('rtd'); - expect(bid2).to.not.have.property('rtd'); - expect(bid3).to.not.have.property('rtd'); - }); - }); - }); -}); diff --git a/test/spec/modules/kargoAnalyticsAdapter_spec.js b/test/spec/modules/kargoAnalyticsAdapter_spec.js deleted file mode 100644 index 35b621077..000000000 --- a/test/spec/modules/kargoAnalyticsAdapter_spec.js +++ /dev/null @@ -1,42 +0,0 @@ -import kargoAnalyticsAdapter from 'modules/kargoAnalyticsAdapter.js'; -import { expect } from 'chai'; -import { server } from 'test/mocks/xhr.js'; -import { EVENTS } from 'src/constants.js'; -const events = require('src/events'); - -describe('Kargo Analytics Adapter', function () { - const adapterConfig = { - provider: 'kargoAnalytics', - }; - - after(function () { - kargoAnalyticsAdapter.disableAnalytics(); - }); - - describe('main test flow', function () { - beforeEach(function () { - kargoAnalyticsAdapter.enableAnalytics(adapterConfig); - sinon.stub(events, 'getEvents').returns([]); - }); - - afterEach(function () { - events.getEvents.restore(); - }); - - it('bid response data should send one request with auction ID, auction timeout, and response time', function() { - const bidResponse = { - bidder: 'kargo', - auctionId: '66529d4c-8998-47c2-ab3e-5b953490b98f', - timeToRespond: 192, - }; - - events.emit(EVENTS.AUCTION_INIT, { - timeout: 1000 - }); - events.emit(EVENTS.BID_RESPONSE, bidResponse); - - expect(server.requests.length).to.equal(1); - expect(server.requests[0].url).to.equal('https://krk.kargo.com/api/v1/event/auction-data?aid=66529d4c-8998-47c2-ab3e-5b953490b98f&ato=1000&rt=192&it=0'); - }); - }); -}); diff --git a/test/spec/modules/kargoBidAdapter_spec.js b/test/spec/modules/kargoBidAdapter_spec.js deleted file mode 100644 index c376b4442..000000000 --- a/test/spec/modules/kargoBidAdapter_spec.js +++ /dev/null @@ -1,2141 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/kargoBidAdapter.js'; -import { config } from 'src/config.js'; -import { getStorageManager } from 'src/storageManager.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; -const utils = require('src/utils'); -const STORAGE = getStorageManager({bidderCode: 'kargo'}); - -describe('kargo adapter tests', function() { - let bid; let outstreamBid; let testBids; let sandbox; let clock; let frozenNow = new Date(); let oldBidderSettings; - - const topUrl = 'https://random.com/this/is/a/url'; - const domain = 'random.com'; - const referer = 'https://random.com/'; - - const defaultBidParams = Object.freeze({ - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - getFloor: () => {}, - ortb2: { - device: { - w: 1720, - h: 1000, - dnt: 0, - language: 'en', - ua: 'Mozilla/5.0' - }, - site: { - domain: domain, - mobile: 0, - page: topUrl, - publisher: { - domain: domain - }, - ref: referer - }, - source: { - tid: 'random-tid' - } - }, - ortb2Imp: { - ext: { - data: { - pbadslot: '/1234/prebid/slot/path' - }, - gpid: '/1234/prebid/slot/path', - } - }, - userId: { - tdid: 'random-tdid' - }, - userIdAsEids: [ - { - source: 'adquery.io', - uids: [ { - id: 'adquery-id', - atype: 1 - } ] - }, - { - source: 'criteo.com', - uids: [ { - id: 'criteo-id', - atype: 1 - } ] - }, - { - source: 'adserver.org', - uids: [ { - id: 'adserver-id', - atype: 1, - ext: { rtiPartner: 'TDID' } - } ] - }, - ], - floorData: { - floorMin: 1 - }, - schain: { - validation: 'strict', - config: { - ver: '1.0', - complete: 1, - nodes: [ { - asi: 'indirectseller.com', - sid: '00001', - hp: 1, - } ] - } - }, - }); - - const minimumBidParams = Object.freeze({ - params: { - placementId: 'foobar' - }, - mediaTypes: { - banner: { sizes: [ [1, 1] ] } - } - }); - - const validCrbIds = { - 2: '82fa2555-5969-4614-b4ce-4dcf1080e9f9', - 16: 'VoxIk8AoJz0AAEdCeyAAAAC2&502', - 23: 'd2a855a5-1b1c-4300-940e-a708fa1f1bde', - 24: 'VoxIk8AoJz0AAEdCeyAAAAC2&502', - 25: '5ee24138-5e03-4b9d-a953-38e833f2849f', - '2_80': 'd2a855a5-1b1c-4300-940e-a708fa1f1bde', - '2_93': '5ee24138-5e03-4b9d-a953-38e833f2849f' - }; - const validCrbIdsLs = { - 2: '82fa2555-5969-4614-b4ce-4dcf1080e9f9', - 16: 'VoxIk8AoJz0AAEdCeyAAAAC2&502', - 23: 'd2a855a5-1b1c-4300-940e-a708fa1f1bde', - 25: '5ee24138-5e03-4b9d-a953-38e833f2849f', - '2_80': 'd2a855a5-1b1c-4300-940e-a708fa1f1bde', - '2_93': '5ee24138-5e03-4b9d-a953-38e833f2849f' - }; - function buildCrbValue(isCookie, withIds, withTdid, withLexId, withClientId, optOut) { - const value = { - expireTime: Date.now() + 60000, - lastSyncedAt: Date.now() - 60000, - optOut, - }; - const locationString = isCookie ? 'cookie' : 'localstorage'; - - if (withIds) { - if (isCookie) { - value.syncIds = validCrbIds; - } else { - value.syncIds = validCrbIdsLs; - } - } - if (withTdid) { - value.tdID = `test-tdid-cerberus-${locationString}`; - } - if (withLexId) { - value.lexId = `test-lexid-cerberus-${locationString}`; - } - if (withClientId) { - value.clientId = `test-clientid-cerberus-${locationString}`; - } - - const b64Value = btoa(JSON.stringify(value)); - if (isCookie) { - return JSON.stringify({ v: b64Value }); - } - return b64Value; - } - - beforeEach(function() { - oldBidderSettings = getGlobal().bidderSettings; - getGlobal().bidderSettings = { - kargo: { storageAllowed: true } - }; - - bid = { - ...defaultBidParams, - bidder: 'kargo', - params: { - placementId: 'displayPlacement' - }, - mediaTypes: { - banner: { - sizes: [ [970, 250], [1, 1] ] - } - }, - adUnitCode: 'displayAdunitCode', - sizes: [ [300, 250], [300, 600] ], - bidId: 'randomBidId', - bidderRequestId: 'randomBidderRequestId', - auctionId: 'randomAuctionId' - }; - - outstreamBid = { - ...defaultBidParams, - bidder: 'kargo', - params: { - placementId: 'instreamPlacement' - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480], - api: [ 1, 2 ], - linearity: 1, - maxduration: 60, - mimes: [ 'video/mp4', 'video/webm', 'application/javascript' ], - minduration: 0, - placement: 1, - playbackmethod: [ 1, 2, 3 ], - plcmt: 1, - protocols: [ 2, 3, 5 ], - skip: 1 - } - }, - adUnitCode: 'instreamAdunitCode', - sizes: [ [300, 250], [300, 600] ], - bidId: 'randomBidId2', - bidderRequestId: 'randomBidderRequestId2', - auctionId: 'randomAuctionId2' - }; - - testBids = [{ ...minimumBidParams }]; - - sandbox = sinon.createSandbox(); - clock = sinon.useFakeTimers(frozenNow.getTime()); - }); - - afterEach(function() { - sandbox.restore(); - clock.restore(); - getGlobal().bidderSettings = oldBidderSettings; - }); - - describe('gvlid', function() { - it('exposes the gvlid (global vendor list ID) of 972', function() { - expect(spec.gvlid).to.exist.and.equal(972); - }); - }); - - describe('code', function() { - it('exposes the code kargo', function() { - expect(spec.code).to.exist.and.equal('kargo'); - }); - }); - - describe('isBidRequestValid', function() { - it('fails when the bid object is undefined', function() { - expect(spec.isBidRequestValid()).to.equal(false); - }); - - it('fails when the bid object has no keys at all', function() { - expect(spec.isBidRequestValid({})).to.equal(false); - }); - - it('fails when the bid includes params but not a placement ID', function() { - expect(spec.isBidRequestValid({ params: {} })).to.equal(false); - }); - - it('passes when the bid includes a placement ID', function () { - expect(spec.isBidRequestValid({ params: { placementId: 'foo' } })).to.equal(true); - }); - - it('passes when the bid includes a placement ID and other keys', function() { - expect(spec.isBidRequestValid({ params: { placementId: 'foo', other: 'value' } })).to.equal(true); - }); - - it('passes when the full bid information is provided', function() { - expect(spec.isBidRequestValid(bid)).to.equal(true); - expect(spec.isBidRequestValid(outstreamBid)).to.equal(true); - }); - }); - - describe('buildRequests', function() { - let bids; - let bidderRequest; - let undefinedCurrency; - let noAdServerCurrency; - let nonUSDAdServerCurrency; - let cookies = []; - let localStorageItems = []; - let session_id = null; - - before(function() { - sinon.spy(spec, 'buildRequests'); - }); - - beforeEach(function() { - undefinedCurrency = false; - noAdServerCurrency = false; - nonUSDAdServerCurrency = false; - sandbox.stub(config, 'getConfig').callsFake(function (key) { - if (key === 'currency') { - if (undefinedCurrency) return undefined; - - if (noAdServerCurrency) return {}; - - if (nonUSDAdServerCurrency) return { adServerCurrency: 'EUR' }; - - return { adServerCurrency: 'USD' }; - } - - if (key === 'debug') return true; - if (key === 'deviceAccess') return true; - throw new Error(`Config stub incomplete, missing key "${key}"`); - }); - - bids = [ - bid, - outstreamBid - ]; - - bidderRequest = { - bidderCode: 'kargo', - auctionId: 'test-auction-id', - bidderRequestId: 'test-request-id', - bids, - ortb2: defaultBidParams.ortb2, - refererInfo: { - canonicalUrl: topUrl, - domain, - isAmp: false, - location: topUrl, - numIframes: 0, - page: topUrl, - reachedTop: true, - ref: referer, - stack: [ topUrl ], - topmostLocation: topUrl, - }, - start: Date.now(), - timeout: 2500, - }; - }); - afterEach(function() { - cookies.forEach(key => document.cookie = `${key}=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/`); - cookies = []; - - localStorageItems.forEach(key => localStorage.removeItem(key)); - localStorageItems = []; - }); - - function getPayloadFromTestBids(testBids) { - const request = spec.buildRequests(testBids, { ...bidderRequest, bids: testBids }); - const payload = request.data; - if (session_id === null) session_id = spec._getSessionId(); - - expect(payload).to.exist; - expect(payload.imp).to.have.length(testBids.length); - expect(payload.requestCount).to.equal(spec.buildRequests.callCount - 1); - expect(payload.sid).to.equal(session_id); - - return payload; - } - - function setCookieValue(name, value) { - cookies.push(name); - document.cookie = `${encodeURIComponent(name)}=${encodeURIComponent(value)}; max-age-in-seconds=1000; path=/`; - } - - function setLocalStorageValue(name, value) { - localStorageItems.push(name); - localStorage.setItem(name, value); - } - - const crbValues = { - valid: buildCrbValue(true, true, true, true, true, false), - validLs: buildCrbValue(false, true, true, true, true, false), - invalidB64: 'crbValue', - invalidB64Ls: 'crbValueLs', - invalidJson: 'eyJ0ZXN0OiJ2YWx1ZSJ9', - invalidJsonLs: 'eyJ0ZXN0OiJ2YWx1ZSJ9', - }; - function setCrb( - setCookie = 'valid', - setLocalStorage = 'valid' - ) { - if (crbValues.hasOwnProperty(setCookie)) { - setCookieValue('krg_crb', crbValues[setCookie]); - } - if (crbValues.hasOwnProperty(`${setLocalStorage}Ls`)) { - setLocalStorageValue('krg_crb', crbValues[`${setLocalStorage}Ls`]); - } - } - - it('exists and produces an object', function() { - const request = spec.buildRequests(bids, bidderRequest); - expect(request).to.exist.and.to.be.an('object'); - }); - - it('produces a POST request with a payload', function() { - const request = spec.buildRequests(bids, bidderRequest); - expect(request.method).to.exist.and.equal('POST'); - expect(request.url).to.exist.and.equal('https://krk2.kargo.com/api/v1/prebid'); - - const payload = request.data; - expect(payload).to.exist; - expect(payload.imp).to.have.length(2); - - // Display bid - const bidImp = payload.imp[0]; - expect(bidImp.id).to.equal('randomBidId'); - expect(bidImp.banner).to.deep.equal({ sizes: [ [970, 250], [1, 1] ] }); - expect(bidImp.video).to.be.undefined; - expect(bidImp.bidRequestCount).to.equal(1); - expect(bidImp.bidderRequestCount).to.equal(1); - expect(bidImp.code).to.equal('displayAdunitCode'); - expect(bidImp.ext.ortb2Imp).to.deep.equal(defaultBidParams.ortb2Imp); - expect(bidImp.fpd).to.deep.equal({ gpid: '/1234/prebid/slot/path' }); - expect(bidImp.pid).to.equal('displayPlacement'); - - // Video bid - const videoBidImp = payload.imp[1]; - expect(videoBidImp.id).to.equal('randomBidId2'); - expect(videoBidImp.banner).to.be.undefined; - expect(videoBidImp.video).to.deep.equal(outstreamBid.mediaTypes.video); - expect(videoBidImp.bidRequestCount).to.equal(1); - expect(videoBidImp.bidderRequestCount).to.equal(1); - expect(videoBidImp.code).to.equal('instreamAdunitCode'); - expect(videoBidImp.ext.ortb2Imp).to.deep.equal(defaultBidParams.ortb2Imp); - expect(videoBidImp.fpd).to.deep.equal({ gpid: '/1234/prebid/slot/path' }); - expect(videoBidImp.pid).to.equal('instreamPlacement'); - - // User - expect(payload.user).to.be.an('object'); - expect(payload.user.crbIDs).to.deep.equal({}); - expect(payload.user.data).to.deep.equal([]); - expect(payload.user.sharedIDEids).to.deep.equal(defaultBidParams.userIdAsEids); - - // General keys - expect(payload.aid).to.equal('randomAuctionId'); - expect(payload.device).to.deep.equal({ size: [ window.screen.width, window.screen.height ] }); - expect(payload.ext.ortb2).to.deep.equal(defaultBidParams.ortb2); - expect(payload.pbv).to.equal('$prebid.version$'); - expect(payload.requestCount).to.equal(spec.buildRequests.callCount - 1); - expect(payload.sid).to.be.a('string').with.length(36); - expect(payload.timeout).to.equal(2500); - expect(payload.url).to.equal(topUrl); - expect(payload.ts).to.be.a('number'); - }); - - it('copies the ortb2 object from the first bid request if present', function() { - let payload; - payload = getPayloadFromTestBids([{ - ...minimumBidParams, - ortb2: { - user: { - key: 'value' - } - } - }]); - expect(payload.ext.ortb2).to.deep.equal({ - user: { key: 'value' } - }); - - payload = getPayloadFromTestBids(testBids); - expect(payload.ext.ortb2).to.be.undefined; - - payload = getPayloadFromTestBids([{ - ...minimumBidParams, - ortb2: { - user: { - key: 'value' - } - } - }, { - ...minimumBidParams, - ortb2: { - site: { - key2: 'value2' - } - } - }]); - expect(payload.ext.ortb2).to.deep.equal({ - user: { key: 'value' } - } - ); - }); - - it('clones ortb2 and removes user.ext.eids without mutating original input', function () { - const ortb2WithEids = { - user: { - ext: { - eids: [{ source: 'adserver.org', uids: [{ id: 'abc', atype: 1 }] }], - other: 'data' - }, - gender: 'M' - }, - site: { - domain: 'example.com', - page: 'https://example.com/page' - }, - source: { - tid: 'test-tid' - } - }; - - const expectedClonedOrtb2 = { - user: { - ext: { - other: 'data' - }, - gender: 'M' - }, - site: { - domain: 'example.com', - page: 'https://example.com/page' - }, - source: { - tid: 'test-tid' - } - }; - - const testBid = { - ...minimumBidParams, - ortb2: utils.deepClone(ortb2WithEids) - }; - - const payload = getPayloadFromTestBids([testBid]); - - // Confirm eids were removed from the payload - expect(payload.ext.ortb2.user.ext.eids).to.be.undefined; - - // Confirm original object was not mutated - expect(testBid.ortb2.user.ext.eids).to.exist.and.be.an('array'); - - // Confirm the rest of the ortb2 object is intact - expect(payload.ext.ortb2).to.deep.equal(expectedClonedOrtb2); - }); - - it('copies the refererInfo object from bidderRequest if present', function() { - let payload; - payload = getPayloadFromTestBids(testBids); - expect(payload.ext.refererInfo).to.deep.equal({ - canonicalUrl: 'https://random.com/this/is/a/url', - domain: 'random.com', - isAmp: false, - location: 'https://random.com/this/is/a/url', - numIframes: 0, - page: 'https://random.com/this/is/a/url', - reachedTop: true, - ref: 'https://random.com/', - stack: [ - 'https://random.com/this/is/a/url' - ], - topmostLocation: 'https://random.com/this/is/a/url' - }); - - delete bidderRequest.refererInfo - payload = getPayloadFromTestBids(testBids); - expect(payload.ext).to.be.undefined; - }); - - it('pulls the site category from the first bids ortb2 object', function() { - let payload; - payload = getPayloadFromTestBids([{ - ...minimumBidParams, - ortb2: { site: { cat: 'test-cat' } } - }]); - expect(payload.site).to.deep.equal({ cat: 'test-cat' }); - - payload = getPayloadFromTestBids(testBids); - expect(payload.site).to.be.undefined; - - payload = getPayloadFromTestBids([{ - ...minimumBidParams, - ortb2: { site: { cat: 'test-cat' } } - }, { - ...minimumBidParams, - ortb2: { site: { cat: 'test-cat-2' } } - }]); - expect(payload.site).to.deep.equal({ cat: 'test-cat' }); - }); - - it('pulls the schain from the first bid if it is populated', function() { - let payload; - payload = getPayloadFromTestBids(testBids); - expect(payload.schain).to.be.undefined; - - payload = getPayloadFromTestBids([{ - ...minimumBidParams, - schain: {} - }, { - ...minimumBidParams, - ortb2: { - source: { - ext: { - schain: { - complete: 1, - nodes: [{ - asi: 'test-page.com', - hp: 1, - rid: '57bdd953-6e57-4d5b-9351-ed67ca238890', - sid: '8190248274' - }] - } - } - } - } - }]); - expect(payload.schain).to.be.undefined; - - payload = getPayloadFromTestBids([{ - ...minimumBidParams, - ortb2: { - source: { - ext: { - schain: { - complete: 1, - nodes: [{ - asi: 'test-page.com', - hp: 1, - rid: '57bdd953-6e57-4d5b-9351-ed67ca238890', - sid: '8190248274' - }] - } - } - } - } - }, { - ...minimumBidParams, - ortb2: { - source: { - ext: { - schain: { - complete: 1, - nodes: [{ - asi: 'test-page-2.com', - hp: 1, - rid: 'other-rid', - sid: 'other-sid' - }] - } - } - } - } - }]); - expect(payload.schain).to.deep.equal({ - complete: 1, - nodes: [{ - asi: 'test-page.com', - hp: 1, - rid: '57bdd953-6e57-4d5b-9351-ed67ca238890', - sid: '8190248274' - }] - }); - }); - - it('does not send currency if it is not defined', function() { - undefinedCurrency = true; - const payload = getPayloadFromTestBids(testBids); - expect(payload.cur).to.be.undefined; - }); - - it('does not send currency if it is missing', function() { - noAdServerCurrency = true; - const payload = getPayloadFromTestBids(testBids); - expect(payload.cur).to.be.undefined; - }); - - it('does not send currency if it is USD', function() { - const payload = getPayloadFromTestBids(testBids); - expect(payload.cur).to.be.undefined; - }); - - it('provides the currency if it is not USD', function() { - nonUSDAdServerCurrency = true; - const payload = getPayloadFromTestBids(testBids); - expect(payload.cur).to.equal('EUR'); - }); - - it('provides the social canvas segments and URL if provided', function() { - let payload; - payload = getPayloadFromTestBids([{ - ...minimumBidParams, - }, { - ...minimumBidParams, - params: { - ...minimumBidParams.params, - socialCanvas: { - segments: ['segment_1', 'segment_2', 'segment_3'], - url: 'https://socan.url' - } - } - }]); - expect(payload.socan).to.be.undefined; - - payload = getPayloadFromTestBids([{ - ...minimumBidParams, - params: { - ...minimumBidParams.params, - socialCanvas: null - } - }, { - ...minimumBidParams, - params: { - ...minimumBidParams.params, - socialCanvas: { - segments: ['segment_1', 'segment_2', 'segment_3'], - url: 'https://socan.url' - } - } - }]); - expect(payload.socan).to.be.undefined; - - payload = getPayloadFromTestBids([{ - ...minimumBidParams, - params: { - ...minimumBidParams.params, - socialCanvas: { - segments: ['segment_1', 'segment_2', 'segment_3'], - url: 'https://socan.url' - } - } - }, { - ...minimumBidParams, - params: { - ...minimumBidParams.params, - socialCanvas: { - segments: ['segment_4', 'segment_5', 'segment_6'], - url: 'https://socan.url/new' - } - } - }]); - expect(payload.socan).to.deep.equal({ - segments: ['segment_1', 'segment_2', 'segment_3'], - url: 'https://socan.url' - }); - }); - - describe('imp', function() { - it('handles slots with different combinations of formats', function() { - const testBids = [ - // Banner and Outstream - { - ...bid, - params: { - inventoryCode: 'banner_outstream_test', - floor: 1.0, - video: { - mimes: [ 'video/mp4' ], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 380] - }, - banner: { - sizes: [ [970, 250], [1, 1] ] - } - }, - adUnitCode: 'adunit-code-banner-outstream', - sizes: [ [300, 250], [300, 600], [1, 1, 1], ['flex'] ], - bidId: 'banner-outstream-bid-id', - bidderRequestId: 'kargo-request-id', - auctionId: 'kargo-auction-id', - }, - // Banner and Native - { - ...bid, - params: { - inventoryCode: 'banner_outstream_test', - floor: 1.0, - video: { - mimes: [ 'video/mp4' ], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - banner: { - sizes: [ [970, 250], [1, 1] ] - }, - native: {} - }, - adUnitCode: 'adunit-code-banner-outstream', - sizes: [ [300, 250], [300, 600], [1, 1, 1], ['flex'] ], - bidId: 'banner-outstream-bid-id', - bidderRequestId: 'kargo-request-id', - auctionId: 'kargo-auction-id', - }, - // Native and Outstream - { - ...bid, - params: { - inventoryCode: 'banner_outstream_test', - floor: 1.0, - video: { - mimes: [ 'video/mp4' ], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 380] - }, - native: {}, - }, - adUnitCode: 'adunit-code-banner-outstream', - sizes: [ [300, 250], [300, 600], [1, 1, 1], ['flex'] ], - bidId: 'banner-outstream-bid-id', - bidderRequestId: 'kargo-request-id', - auctionId: 'kargo-auction-id', - }, - // Banner and Native and Outstream - { - ...bid, - params: { - inventoryCode: 'banner_outstream_test', - floor: 1.0, - video: { - mimes: [ 'video/mp4' ], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 380] - }, - banner: { - sizes: [ [970, 250], [1, 1] ] - }, - native: {}, - }, - adUnitCode: 'adunit-code-banner-outstream', - sizes: [ [300, 250], [300, 600], [1, 1, 1], ['flex'] ], - bidId: 'banner-outstream-bid-id', - bidderRequestId: 'kargo-request-id', - auctionId: 'kargo-auction-id', - }, - ]; - - const payload = getPayloadFromTestBids(testBids); - - const bannerImp = { - sizes: [ [970, 250], [1, 1] ] - }; - const videoImp = { - context: 'outstream', - playerSize: [640, 380] - }; - const nativeImp = {}; - - // Banner and Outstream - expect(payload.imp[0].banner).to.deep.equal(bannerImp); - expect(payload.imp[0].video).to.deep.equal(videoImp); - expect(payload.imp[0].native).to.be.undefined; - // Banner and Native - expect(payload.imp[1].banner).to.deep.equal(bannerImp); - expect(payload.imp[1].video).to.be.undefined; - expect(payload.imp[1].native).to.deep.equal(nativeImp); - // Native and Outstream - expect(payload.imp[2].banner).to.be.undefined; - expect(payload.imp[2].video).to.deep.equal(videoImp); - expect(payload.imp[2].native).to.deep.equal(nativeImp); - // Banner and Native and Outstream - expect(payload.imp[3].banner).to.deep.equal(bannerImp); - expect(payload.imp[3].video).to.deep.equal(videoImp); - expect(payload.imp[3].native).to.deep.equal(nativeImp); - }); - - it('pulls gpid from ortb2Imp.ext.gpid', function () { - const gpidGpid = 'ortb2Imp.ext.gpid-gpid'; - const testBids = [ - { - ...minimumBidParams, - ortb2Imp: { - ext: { - gpid: gpidGpid, - data: {} - } - } - }, - { - ...minimumBidParams, - ortb2Imp: { - ext: { - gpid: gpidGpid, - data: {}, - } - } - }, - { - ...minimumBidParams, - ortb2Imp: { - ext: { - data: {} - } - } - }, - { - ...minimumBidParams, - ortb2Imp: { - ext: { - gpid: null, - data: { - pbadslot: null - } - } - } - }, - { ...minimumBidParams } - ]; - - const payload = getPayloadFromTestBids(testBids); - - // Both present - expect(payload.imp[0].fpd).to.deep.equal({ gpid: gpidGpid }); - // Only ext.gpid - expect(payload.imp[1].fpd).to.deep.equal({ gpid: gpidGpid }); - // Neither present - expect(payload.imp[3].fpd).to.be.undefined; - expect(payload.imp[4].fpd).to.be.undefined; - }); - - it('includes bidRequestCount, bidderRequestCount, and bidderWinsCount if they are greater than 0', function() { - const testBids = [ - { - ...minimumBidParams, - bidRequestsCount: 1, - bidderRequestsCount: 0, - bidderWinsCount: 0, - }, - { - ...minimumBidParams, - bidRequestsCount: 0, - bidderRequestsCount: 2, - bidderWinsCount: 0, - }, - { - ...minimumBidParams, - bidRequestsCount: 0, - bidderRequestsCount: 0, - bidderWinsCount: 3, - }, - { - ...minimumBidParams, - bidRequestsCount: 4, - bidderRequestsCount: 1, - bidderWinsCount: 3, - }, - ]; - - [ 0, null, false, 'foobar' ].forEach(value => testBids.push({ - ...minimumBidParams, - bidRequestsCount: value, - bidderRequestsCount: value, - bidderWinsCount: value - })); - - const payload = getPayloadFromTestBids(testBids); - - // bidRequestCount - expect(payload.imp[0].bidRequestCount).to.equal(1); - expect(payload.imp[0].bidderRequestCount).to.be.undefined; - expect(payload.imp[0].bidderWinCount).to.be.undefined; - // bidderRequestCount - expect(payload.imp[1].bidRequestCount).to.be.undefined; - expect(payload.imp[1].bidderRequestCount).to.equal(2); - expect(payload.imp[1].bidderWinCount).to.be.undefined; - // bidderWinCount - expect(payload.imp[2].bidRequestCount).to.be.undefined; - expect(payload.imp[2].bidderRequestCount).to.be.undefined; - expect(payload.imp[2].bidderWinCount).to.equal(3); - // all - expect(payload.imp[3].bidRequestCount).to.equal(4); - expect(payload.imp[3].bidderRequestCount).to.equal(1); - expect(payload.imp[3].bidderWinCount).to.equal(3); - // none - for (let i = 4; i < payload.imp.length; i++) { - expect(payload.imp[i].bidRequestCount).to.be.undefined; - expect(payload.imp[i].bidderRequestCount).to.be.undefined; - expect(payload.imp[i].bidderWinCount).to.be.undefined; - } - }); - - it('queries the getFloor function to retrieve the floor and validates it', function() { - const testBids = []; - - [ - { currency: 'USD', floor: 1.99 }, - { currency: 'USD', floor: '1.99' }, - { currency: 'EUR', floor: 1.99 }, - { currency: 'USD', floor: 'foo' }, - { currency: 'USD', floor: null }, - { currency: 'USD', floor: true }, - { currency: 'USD', floor: false }, - { currency: 'USD', floor: {} }, - { currency: 'USD', floor: [] }, - ].forEach(floorValue => testBids.push({ - ...minimumBidParams, - getFloor: () => floorValue - })); - - const payload = getPayloadFromTestBids(testBids); - - // Valid floor - expect(payload.imp[0].floor).to.equal(1.99); - // Valid floor but string - expect(payload.imp[1].floor).to.equal('1.99'); // @TODO - convert this to a number? - // Non-USD valid floor - expect(payload.imp[2].floor).to.be.undefined; - // Invalid floor - for (let i = 3; i < payload.imp.length; i++) { - expect(payload.imp[i].floor).to.be.undefined; - } - }); - - it('calls getFloor with the right values', function() { - const testBids = [ - { - ...minimumBidParams, - getFloor: () => ({ currency: 'USD', value: 0.5 }) - } - ]; - sinon.spy(testBids[0], 'getFloor'); - - getPayloadFromTestBids(testBids); - - expect(testBids[0].getFloor.calledWith({ - currency: 'USD', - mediaType: '*', - size: '*' - })).to.be.true; - }); - }); - - describe('cerberus', function() { - it('retrieves CRB from localStorage and cookies', function() { - setCrb('valid', 'valid'); - - const payload = getPayloadFromTestBids(testBids, bidderRequest); - - expect(payload.rawCRB).to.equal(crbValues.valid); - expect(payload.rawCRBLocalStorage).to.equal(crbValues.validLs); - expect(payload.user.crbIDs).to.deep.equal(validCrbIdsLs); - expect(payload.user.tdID).to.equal('test-tdid-cerberus-localstorage'); - expect(payload.user.kargoID).to.equal('test-lexid-cerberus-localstorage'); - expect(payload.user.clientID).to.equal('test-clientid-cerberus-localstorage'); - expect(payload.user.optOut).to.equal(false); - }); - - it('retrieves CRB from localStorage if cookie is missing', function() { - setCrb(false, 'valid'); - - const payload = getPayloadFromTestBids(testBids, bidderRequest); - - expect(payload.rawCRB).to.be.undefined; - expect(payload.rawCRBLocalStorage).to.equal(crbValues.validLs); - expect(payload.user.crbIDs).to.deep.equal(validCrbIdsLs); - expect(payload.user.tdID).to.equal('test-tdid-cerberus-localstorage'); - expect(payload.user.kargoID).to.equal('test-lexid-cerberus-localstorage'); - expect(payload.user.clientID).to.equal('test-clientid-cerberus-localstorage'); - expect(payload.user.optOut).to.equal(false); - }); - - it('retrieves CRB from cookies if localstorage is missing', function() { - setCrb('valid', false); - - const payload = getPayloadFromTestBids(testBids, bidderRequest); - - expect(payload.rawCRB).to.equal(crbValues.valid); - expect(payload.rawCRBLocalStorage).to.be.undefined; - expect(payload.user.crbIDs).to.deep.equal(validCrbIds); - expect(payload.user.tdID).to.equal('test-tdid-cerberus-cookie'); - expect(payload.user.kargoID).to.equal('test-lexid-cerberus-cookie'); - expect(payload.user.clientID).to.equal('test-clientid-cerberus-cookie'); - expect(payload.user.optOut).to.equal(false); - }); - - it('retrieves CRB from cookies if localstorage is not functional', function() { - // Safari does not allow stubbing localStorage methods directly. - // Stub the storage manager instead so all browsers behave consistently. - sandbox.stub(STORAGE, 'getDataFromLocalStorage').throws(); - setCrb('valid', 'invalid'); - - const payload = getPayloadFromTestBids(testBids, bidderRequest); - - expect(payload.rawCRB).to.equal(crbValues.valid); - expect(payload.rawCRBLocalStorage).to.be.undefined; - expect(payload.user.crbIDs).to.deep.equal(validCrbIds); - expect(payload.user.tdID).to.equal('test-tdid-cerberus-cookie'); - expect(payload.user.kargoID).to.equal('test-lexid-cerberus-cookie'); - expect(payload.user.clientID).to.equal('test-clientid-cerberus-cookie'); - expect(payload.user.optOut).to.equal(false); - }); - - it('does not fail if CRB is missing', function() { - const payload = getPayloadFromTestBids(testBids, bidderRequest); - - expect(payload.rawCRB).to.be.undefined; - expect(payload.rawCRBLocalStorage).to.be.undefined; - expect(payload.user.crbIDs).to.deep.equal({}); - expect(payload.user.tdID).to.be.undefined; - expect(payload.user.kargoID).to.be.undefined; - expect(payload.user.clientID).to.be.undefined; - expect(payload.user.optOut).to.be.undefined; - }); - - it('fails gracefully if the CRB is invalid base 64 cookie', function() { - setCrb('invalidB64', false); - - const payload = getPayloadFromTestBids(testBids, bidderRequest); - - expect(payload.rawCRB).to.equal(crbValues.invalidB64); - expect(payload.rawCRBLocalStorage).to.be.undefined; - expect(payload.user.crbIDs).to.deep.equal({}); - expect(payload.user.tdID).to.be.undefined; - expect(payload.user.kargoID).to.be.undefined; - expect(payload.user.clientID).to.be.undefined; - expect(payload.user.optOut).to.be.undefined; - }); - - it('fails gracefully if the CRB is invalid base 64 localStorage', function() { - setCrb(false, 'invalidB64'); - - const payload = getPayloadFromTestBids(testBids, bidderRequest); - - expect(payload.rawCRB).to.be.undefined; - expect(payload.rawCRBLocalStorage).to.equal(crbValues.invalidB64Ls); - expect(payload.user.crbIDs).to.deep.equal({}); - expect(payload.user.tdID).to.be.undefined; - expect(payload.user.kargoID).to.be.undefined; - expect(payload.user.clientID).to.be.undefined; - expect(payload.user.optOut).to.be.undefined; - }); - - [ - [ 'valid', 'invalidB64', 'cookie' ], - [ 'valid', 'invalidJson', 'cookie' ], - [ 'invalidB64', 'invalidJson', 'none' ], - [ 'invalidB64', 'invalidB64', 'none' ], - [ 'invalidB64', 'valid', 'localStorage' ], - [ 'invalidJson', 'invalidJson', 'none' ], - [ 'invalidJson', 'invalidB64', 'none' ], - [ 'invalidJson', 'valid', 'localStorage' ], - ].forEach(config => { - it(`uses ${config[2]} if the cookie is ${config[0]} and localStorage is ${config[1]}`, function() { - setCrb(config[0], config[1]); - const payload = getPayloadFromTestBids(testBids, bidderRequest); - - expect(payload.rawCRB).to.equal(crbValues[config[0]]); - expect(payload.rawCRBLocalStorage).to.equal(crbValues[`${config[1]}Ls`]); - if (config[2] === 'cookie') { - expect(payload.user.crbIDs).to.deep.equal(validCrbIds); - expect(payload.user.tdID).to.equal('test-tdid-cerberus-cookie'); - expect(payload.user.kargoID).to.equal('test-lexid-cerberus-cookie'); - expect(payload.user.clientID).to.equal('test-clientid-cerberus-cookie'); - expect(payload.user.optOut).to.equal(false); - } else if (config[2] === 'localStorage') { - expect(payload.user.crbIDs).to.deep.equal(validCrbIdsLs); - expect(payload.user.tdID).to.equal('test-tdid-cerberus-localstorage'); - expect(payload.user.kargoID).to.equal('test-lexid-cerberus-localstorage'); - expect(payload.user.clientID).to.equal('test-clientid-cerberus-localstorage'); - expect(payload.user.optOut).to.equal(false); - } else { - expect(payload.user.crbIDs).to.deep.equal({}); - expect(payload.user.tdID).to.be.undefined; - expect(payload.user.kargoID).to.be.undefined; - expect(payload.user.clientID).to.be.undefined; - expect(payload.user.optOut).to.be.undefined; - } - }); - }); - - it('uses the tdID from cerberus to populate the tdID field', function() { - setCrb('valid', 'valid'); - const payload = getPayloadFromTestBids(testBids, bidderRequest); - - expect(payload.user.tdID).to.equal('test-tdid-cerberus-localstorage'); - }); - - it('uses the lexId from cerberus to populate the kargoID field', function() { - setCrb('valid', 'valid'); - const payload = getPayloadFromTestBids(testBids, bidderRequest); - - expect(payload.user.kargoID).to.equal('test-lexid-cerberus-localstorage'); - }); - - it('uses the clientId from cerberus to populate the clientID field', function() { - setCrb('valid', 'valid'); - const payload = getPayloadFromTestBids(testBids, bidderRequest); - - expect(payload.user.clientID).to.equal('test-clientid-cerberus-localstorage'); - }); - - it('uses the optOut from cerberus to populate the clientID field', function() { - setCrb('valid', 'valid'); - let payload; - payload = getPayloadFromTestBids(testBids, bidderRequest); - - expect(payload.user.optOut).to.equal(false); - - setLocalStorageValue('krg_crb', buildCrbValue(false, true, true, true, true, true)); - payload = getPayloadFromTestBids(testBids, bidderRequest); - - expect(payload.user.optOut).to.equal(true); - }); - }); - - describe('user', function() { - it('fetches the trade desk id from the adapter if present', function() { - const payload = getPayloadFromTestBids([{ - ...minimumBidParams, - userId: { - tdid: 'test-tdid-module' - } - }]); - - expect(payload.user.tdID).to.equal('test-tdid-module'); - }); - - it('fetches the trade desk id from cerberus if present', function() { - setLocalStorageValue('krg_crb', btoa(JSON.stringify({ tdID: 'test-tdid-crb' }))); - - const payload = getPayloadFromTestBids([{ - ...minimumBidParams, - }]); - - expect(payload.user.tdID).to.equal('test-tdid-crb'); - }); - - it('fetches the trade desk id from the adapter if adapter and cerberus are present', function() { - setLocalStorageValue('krg_crb', buildCrbValue(false, true, true, true, true, false)); - - const payload = getPayloadFromTestBids([{ - ...minimumBidParams, - userId: { - tdid: 'test-tdid-module' - } - }]); - - expect(payload.user.tdID).to.equal('test-tdid-module'); - }); - - it('does not set kargoId if it is not present', function() { - const payload = getPayloadFromTestBids([{ ...minimumBidParams }]); - - expect(payload.user.lexId).to.be.undefined; - }); - - it('does not populate usp, gdpr, or gpp if they are not present', function() { - const payload = getPayloadFromTestBids([{ ...minimumBidParams }]); - - expect(payload.user.usp).to.be.undefined; - expect(payload.user.gdpr).to.be.undefined; - expect(payload.user.gpp).to.be.undefined; - }); - - it('fetches usp from the bidder request if present', function() { - bidderRequest.uspConsent = '1---'; - const payload = getPayloadFromTestBids([{ ...minimumBidParams }]); - - expect(payload.user.usp).to.equal('1---'); - }); - - it('fetches gpp from the bidder request if present', function() { - bidderRequest.gppConsent = { - consentString: 'gppString', - applicableSections: [-1] - }; - const payload = getPayloadFromTestBids([{ ...minimumBidParams }]); - - expect(payload.user.gpp).to.deep.equal({ - gppString: 'gppString', - applicableSections: [-1] - }); - }); - - it('does not send empty gpp values', function() { - bidderRequest.gppConsent = { - consentString: '', - applicableSections: '' - }; - const payload = getPayloadFromTestBids([{ ...minimumBidParams }]); - - expect(payload.user.gpp).to.be.undefined; - }); - - it('fetches gdpr consent from the bidder request if present', function() { - bidderRequest.gdprConsent = { - consentString: 'gdpr-consent-string', - gdprApplies: true - }; - const payload = getPayloadFromTestBids([{ ...minimumBidParams }]); - - expect(payload.user.gdpr).to.deep.equal({ - consent: 'gdpr-consent-string', - applies: true - }); - }); - - it('handles malformed gdpr applies from the bidder request', function() { - [ - ['true', true], - ['false', true], - ['1', true], - [1, true], - [0, false], - ['0', true], - ['y', true], - ['yes', true], - ['n', true], - ['no', true], - [null, false], - [{}, true], - ].forEach(testValue => { - bidderRequest.gdprConsent = { gdprApplies: testValue[0] }; - const payload = getPayloadFromTestBids([{ ...minimumBidParams }]); - expect(payload.user.gdpr, `Value - ${JSON.stringify(testValue[0])}`).to.deep.equal({ - consent: '', - applies: testValue[1] - }); - }); - }); - - it('passes the user.data from the first bid request if availabale', function() { - let payload; - payload = getPayloadFromTestBids([{ - ...minimumBidParams, - }, { - ...minimumBidParams, - ortb2: { user: { data: { test: 'value' } } } - }]); - expect(payload.user.data).to.deep.equal([]); - - payload = getPayloadFromTestBids([{ - ...minimumBidParams, - ortb2: { user: { data: { test: 'value' } } } - }, { - ...minimumBidParams, - ortb2: { user: { data: { test2: 'value2' } } } - }]); - expect(payload.user.data).to.deep.equal({ - test: 'value' - }); - }); - - it('fails gracefully if there is no localStorage', function() { - sandbox.stub(STORAGE, 'getDataFromLocalStorage').throws(); - localStorage.removeItem('krg_crb'); - document.cookie = 'krg_crb=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; - const payload = getPayloadFromTestBids(testBids); - expect(payload.user).to.deep.equal({ - crbIDs: {}, - data: [] - }); - }); - }); - - describe('sua', function() { - it('is not provided if not present in the first valid bid', function() { - const payload = getPayloadFromTestBids([ - ...testBids, - { - ...minimumBidParams, - ortb2: { device: { sua: { - platform: { - brand: 'macOS', - version: ['12', '6', '0'] - }, - browsers: [ - { - brand: 'Chromium', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Google Chrome', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Not;A=Brand', - version: ['99', '0', '0', '0'] - } - ], - mobile: 1, - model: 'model', - source: 1, - } } } - } - ]); - expect(payload.device.sua).to.be.undefined; - }); - - it('is provided if present in the first valid bid', function() { - const payload = getPayloadFromTestBids([ - { - ...minimumBidParams, - ortb2: { device: { sua: { - platform: { - brand: 'macOS', - version: ['12', '6', '0'] - }, - browsers: [ - { - brand: 'Chromium', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Google Chrome', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Not;A=Brand', - version: ['99', '0', '0', '0'] - } - ], - mobile: 1, - model: 'model', - source: 1, - } } } - }, - { - ...minimumBidParams, - ortb2: { device: { sua: { - platform: { - brand: 'macOS2', - version: ['122', '6', '0'] - }, - browsers: [ - { - brand: 'Chromium2', - version: ['1062', '0', '5249', '119'] - }, - { - brand: 'Google Chrome2', - version: ['102', '0', '5249', '119'] - }, - { - brand: 'Not;A=Brand2', - version: ['992', '0', '0', '0'] - } - ], - mobile: 2, - model: 'model2', - source: 2, - } } } - } - ]); - expect(payload.device.sua).to.deep.equal({ - platform: { - brand: 'macOS', - version: ['12', '6', '0'] - }, - browsers: [ - { - brand: 'Chromium', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Google Chrome', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Not;A=Brand', - version: ['99', '0', '0', '0'] - } - ], - mobile: 1, - model: 'model', - source: 1, - }); - }); - - it('does not send non-mapped attributes', function() { - const payload = getPayloadFromTestBids([{...minimumBidParams, - ortb2: { device: { sua: { - other: 'value', - objectMissing: { - key: 'value' - }, - platform: { - brand: 'macOS', - version: ['12', '6', '0'] - }, - browsers: [ - { - brand: 'Chromium', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Google Chrome', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Not;A=Brand', - version: ['99', '0', '0', '0'] - } - ], - mobile: 1, - model: 'model', - source: 1, - } } } - }]); - expect(payload.device.sua).to.deep.equal({ - platform: { - brand: 'macOS', - version: ['12', '6', '0'] - }, - browsers: [ - { - brand: 'Chromium', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Google Chrome', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Not;A=Brand', - version: ['99', '0', '0', '0'] - } - ], - mobile: 1, - model: 'model', - source: 1, - }); - }); - - it('does not send non-truthy values or empty strings', function() { - [ - false, - 0, - null, - '', - ' ', - ' ', - ].forEach(value => { - const payload = getPayloadFromTestBids([{...minimumBidParams, - ortb2: { device: { sua: { - platform: value, - browsers: [ - { - brand: 'Chromium', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Google Chrome', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Not;A=Brand', - version: ['99', '0', '0', '0'] - } - ], - mobile: 1, - model: 'model', - source: 1, - } } } - }]); - expect(payload.device.sua, `Value - ${JSON.stringify(value)}`).to.deep.equal({ - browsers: [ - { - brand: 'Chromium', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Google Chrome', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Not;A=Brand', - version: ['99', '0', '0', '0'] - } - ], - mobile: 1, - model: 'model', - source: 1, - }); - }); - }); - - it('does not send 0 for mobile or source', function() { - const payload = getPayloadFromTestBids([{ - ...minimumBidParams, - ortb2: { device: { sua: { - platform: { - brand: 'macOS', - version: ['12', '6', '0'] - }, - browsers: [ - { - brand: 'Chromium', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Google Chrome', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Not;A=Brand', - version: ['99', '0', '0', '0'] - } - ], - mobile: 0, - model: 'model', - source: 0, - } } } - }]); - expect(payload.device.sua).to.deep.equal({ - platform: { - brand: 'macOS', - version: ['12', '6', '0'] - }, - browsers: [ - { - brand: 'Chromium', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Google Chrome', - version: ['106', '0', '5249', '119'] - }, - { - brand: 'Not;A=Brand', - version: ['99', '0', '0', '0'] - } - ], - model: 'model', - }); - }); - }); - - describe('page', function() { - it('pulls the page ID from localStorage', function() { - setLocalStorageValue('pageViewId', 'test-page-id'); - const payload = getPayloadFromTestBids(testBids); - expect(payload.page).to.deep.equal({ - id: 'test-page-id' - }); - }); - - it('pulls the page timestamp from localStorage', function() { - setLocalStorageValue('pageViewTimestamp', '123456789'); - const payload = getPayloadFromTestBids(testBids); - expect(payload.page).to.deep.equal({ - timestamp: 123456789 - }); - }); - - it('pulls the page ID from localStorage', function() { - setLocalStorageValue('pageViewUrl', 'https://test-url.com'); - const payload = getPayloadFromTestBids(testBids); - expect(payload.page).to.deep.equal({ - url: 'https://test-url.com' - }); - }); - - it('pulls all 3 together', function() { - setLocalStorageValue('pageViewId', 'test-page-id'); - setLocalStorageValue('pageViewTimestamp', '123456789'); - setLocalStorageValue('pageViewUrl', 'https://test-url.com'); - const payload = getPayloadFromTestBids(testBids); - expect(payload.page).to.deep.equal({ - id: 'test-page-id', - timestamp: 123456789, - url: 'https://test-url.com' - }); - }); - - it('fails gracefully without localStorage', function() { - sandbox.stub(STORAGE, 'getDataFromLocalStorage').throws(); - localStorage.removeItem('krg_crb'); - document.cookie = 'krg_crb=; expires=Thu, 01 Jan 1970 00:00:00 GMT; path=/'; - const payload = getPayloadFromTestBids(testBids); - expect(payload.page).to.be.undefined; - }); - }); - }); - - describe('interpretResponse', function() { - const response = Object.freeze({ body: { - 1: { - id: 'foo', - cpm: 3, - adm: '
', - width: 320, - height: 50, - metadata: {}, - creativeID: 'bar' - }, - 2: { - id: 'bar', - cpm: 2.5, - adm: '
', - width: 300, - height: 250, - targetingCustom: 'dmpmptest1234', - metadata: { - landingPageDomain: ['https://foobar.com'] - }, - creativeID: 'foo' - }, - 3: { - id: 'bar', - cpm: 2.5, - adm: '
', - width: 300, - height: 250, - creativeID: 'foo' - }, - 4: { - id: 'bar', - cpm: 2.5, - adm: '
', - width: 300, - height: 250, - mediaType: 'banner', - metadata: {}, - creativeID: 'foo', - currency: 'EUR' - }, - 5: { - id: 'bar', - cpm: 2.5, - adm: '', - width: 300, - height: 250, - mediaType: 'video', - metadata: {}, - creativeID: 'foo', - currency: 'EUR' - }, - 6: { - id: 'bar', - cpm: 2.5, - adm: '', - admUrl: 'https://foobar.com/vast_adm', - width: 300, - height: 250, - mediaType: 'video', - metadata: {}, - creativeID: 'foo', - currency: 'EUR' - } - }}); - const bidderRequest = Object.freeze({ - currency: 'USD', - bids: [{ - bidId: 1, - params: { - placementId: 'foo' - } - }, { - bidId: 2, - params: { - placementId: 'bar' - } - }, { - bidId: 3, - params: { - placementId: 'bar' - } - }, { - bidId: 4, - params: { - placementId: 'bar' - } - }, { - bidId: 5, - params: { - placementId: 'bar' - } - }, { - bidId: 6, - params: { - placementId: 'bar' - } - }] - }); - - it('returns an empty array if the response body is empty or not an object', function() { - [ - '', - undefined, - false, - true, - null, - [], - {}, - 1234, - ].forEach(value => { - const bids = spec.interpretResponse({ body: value }, bidderRequest); - expect(bids, `Value - ${JSON.stringify(value)}`).to.deep.equal([]); - }); - }); - - it('returns bid response for various objects', function() { - const bids = spec.interpretResponse(response, bidderRequest); - expect(bids).to.have.length(Object.keys(response.body).length); - expect(bids[0]).to.deep.equal({ - ad: '
', - cpm: 3, - creativeId: 'bar', - currency: 'USD', - dealId: undefined, - height: 50, - mediaType: 'banner', - meta: { - mediaType: 'banner' - }, - netRevenue: true, - requestId: '1', - ttl: 300, - width: 320, - }); - expect(bids[1]).to.deep.equal({ - requestId: '2', - ad: '
', - cpm: 2.5, - width: 300, - height: 250, - ttl: 300, - creativeId: 'foo', - dealId: 'dmpmptest1234', - netRevenue: true, - currency: 'USD', - mediaType: 'banner', - meta: { - mediaType: 'banner', - clickUrl: 'https://foobar.com', - advertiserDomains: ['https://foobar.com'] - } - }); - expect(bids[2]).to.deep.equal({ - requestId: '3', - ad: '
', - cpm: 2.5, - width: 300, - height: 250, - ttl: 300, - creativeId: 'foo', - dealId: undefined, - netRevenue: true, - currency: 'USD', - mediaType: 'banner', - meta: { - mediaType: 'banner' - } - }); - expect(bids[3]).to.deep.equal({ - requestId: '4', - ad: '
', - cpm: 2.5, - width: 300, - height: 250, - ttl: 300, - creativeId: 'foo', - dealId: undefined, - netRevenue: true, - currency: 'EUR', - mediaType: 'banner', - meta: { - mediaType: 'banner' - } - }); - expect(bids[4]).to.deep.equal({ - requestId: '5', - cpm: 2.5, - width: 300, - height: 250, - vastXml: '', - ttl: 300, - creativeId: 'foo', - dealId: undefined, - netRevenue: true, - currency: 'EUR', - mediaType: 'video', - meta: { - mediaType: 'video' - } - }); - expect(bids[5]).to.deep.equal({ - requestId: '6', - cpm: 2.5, - width: 300, - height: 250, - vastUrl: 'https://foobar.com/vast_adm', - ttl: 300, - creativeId: 'foo', - dealId: undefined, - netRevenue: true, - currency: 'EUR', - mediaType: 'video', - meta: { - mediaType: 'video' - } - }); - }); - - it('adds landingPageDomain data', function() { - const response = spec.interpretResponse({ body: { 0: { - metadata: { - landingPageDomain: [ - 'https://foo.com', - 'https://bar.com' - ] - } - } } }, {}); - expect(response[0].meta).to.deep.equal({ - mediaType: 'banner', - clickUrl: 'https://foo.com', - advertiserDomains: [ 'https://foo.com', 'https://bar.com' ] - }); - }); - - it('should return paapi if provided in bid response', function () { - const auctionConfig = { - seller: 'https://kargo.com', - decisionLogicUrl: 'https://kargo.com/decision_logic.js', - interestGroupBuyers: ['https://some_buyer.com'], - perBuyerSignals: { - 'https://some_buyer.com': { a: 1 } - } - } - - const body = response.body; - for (const key in body) { - if (body.hasOwnProperty(key)) { - if (key % 2 !== 0) { // Add auctionConfig to every other object - body[key].auctionConfig = auctionConfig; - } - } - } - - const result = spec.interpretResponse(response, bidderRequest); - - // Test properties of bidResponses - result.bids.forEach(bid => { - expect(bid).to.have.property('requestId'); - expect(bid).to.have.property('cpm'); - expect(bid).to.have.property('width'); - expect(bid).to.have.property('height'); - expect(bid).to.have.property('ttl'); - expect(bid).to.have.property('creativeId'); - expect(bid.netRevenue).to.be.true; - expect(bid).to.have.property('meta').that.is.an('object'); - }); - - // Test properties of paapi - expect(result.paapi).to.have.lengthOf(3); - - const expectedBidIds = ['1', '3', '5']; // Expected bidIDs - result.paapi.forEach(config => { - expect(config).to.have.property('bidId'); - expect(expectedBidIds).to.include(config.bidId); - - expect(config).to.have.property('config').that.is.an('object'); - expect(config.config).to.have.property('seller', 'https://kargo.com'); - expect(config.config).to.have.property('decisionLogicUrl', 'https://kargo.com/decision_logic.js'); - expect(config.config.interestGroupBuyers).to.be.an('array').that.includes('https://some_buyer.com'); - expect(config.config.perBuyerSignals).to.have.property('https://some_buyer.com').that.deep.equals({ a: 1 }); - }); - }); - }); - - describe('getUserSyncs', function() { - let crb = {}; - const clientId = 'random-client-id-string'; - const baseUrl = 'https://crb.kargo.com/api/v1/initsyncrnd/random-client-id-string?seed=3205e885-8d37-4139-b47e-f82cff268000&gdpr=0&gdpr_consent=&us_privacy=&gpp=&gpp_sid='; - - function buildSyncUrls(baseUrl = 'https://crb.kargo.com/api/v1/initsyncrnd/random-client-id-string?seed=3205e885-8d37-4139-b47e-f82cff268000&gdpr=0&gdpr_consent=&us_privacy=&gpp=&gpp_sid=') { - const syncs = []; - - syncs.push({ - type: 'iframe', - url: baseUrl - }); - - return syncs; - } - - function getUserSyncs(gdpr, usp, gpp) { - return spec.getUserSyncs( - { iframeEnabled: true }, - null, - gdpr, - usp, - gpp - ); - } - - beforeEach(function() { - crb = { clientId }; - sandbox.stub(spec, '_getCrb').callsFake(function() { return crb; }); - - // Makes the seed in the URLs predictable - sandbox.stub(utils, 'generateUUID').returns('3205e885-8d37-4139-b47e-f82cff268000'); - }); - - it('returns user syncs when an ID is present', function() { - expect(getUserSyncs()).to.deep.equal(buildSyncUrls()); - }); - - it('returns no syncs if there is no user ID', function() { - delete crb.clientId; - expect(getUserSyncs()).to.deep.equal([]); - }); - - it('returns no syncs if there is no usp consent', function() { - expect(getUserSyncs(undefined, '1YYY')).to.deep.equal([]); - }); - - it('returns no syncs if iframe syncing is not allowed', function() { - expect(spec.getUserSyncs({ iframeEnabled: false }, null, undefined, undefined, undefined)) - .to.deep.equal([]); - expect(spec.getUserSyncs({}, null, undefined, undefined, undefined)) - .to.deep.equal([]); - }); - - it('includes the US privacy string in the sync URL if present', function() { - [ - '0---', - '1---', - '1NNN', - 'invalid', - 1234, - ].forEach(value => expect(getUserSyncs(undefined, value), `Value - ${value}`) - .to.deep.equal(buildSyncUrls(baseUrl.replace(/us_privacy=/, `us_privacy=${value}`)))); - }); - - it('includes gdpr information if provided', function() { - [ - { gdprApplies: true, consentString: 'test-consent-string', ga: '1', cs: 'test-consent-string' }, - { gdprApplies: false, consentString: 'test-consent-string', ga: '0', cs: 'test-consent-string' }, - { gdprApplies: true, ga: '1', cs: '' }, - { gdprApplies: false, ga: '0', cs: '' }, - { ga: '0', cs: '' }, - ].forEach(value => expect(getUserSyncs(value), `Value - ${value}`) - .to.deep.equal(buildSyncUrls(baseUrl - .replace(/gdpr=\d/, `gdpr=${value.ga}`) - .replace(/gdpr_consent=/, `gdpr_consent=${value.cs}`)))); - }); - - it('handles malformed gdpr information', function() { - [ - null, - false, - true, - 1, - '1', - 'test-applies', - [], - {} - ].forEach(value => expect(getUserSyncs(value), `Value - ${JSON.stringify(value)}`) - .to.deep.equal(buildSyncUrls(baseUrl))); - }); - - it('includes gpp information if provided', function() { - [ - { applicableSections: [-1], consentString: 'test-consent-string', as: '-1', cs: 'test-consent-string' }, - { applicableSections: [1, 2, 3], consentString: 'test-consent-string', as: '1,2,3', cs: 'test-consent-string' }, - { applicableSections: [-1], as: '-1', cs: '' }, - { applicableSections: false, consentString: 'test-consent-string', as: '', cs: 'test-consent-string' }, - { applicableSections: null, consentString: 'test-consent-string', as: '', cs: 'test-consent-string' }, - { applicableSections: {}, consentString: 'test-consent-string', as: '', cs: 'test-consent-string' }, - { applicableSections: [], consentString: 'test-consent-string', as: '', cs: 'test-consent-string' }, - { as: '', cs: '' }, - ].forEach(value => expect(getUserSyncs(undefined, undefined, value), `Value - ${value}`) - .to.deep.equal(buildSyncUrls(baseUrl - .replace(/gpp=/, `gpp=${value.cs}`) - .replace(/gpp_sid=/, `gpp_sid=${value.as}`)))); - }); - - it('handles malformed gpp information', function() { - [ - null, - false, - true, - 1, - '1', - 'test-applies', - [], - {} - ].forEach(value => expect(getUserSyncs(undefined, undefined, value), `Value - ${JSON.stringify(value)}`) - .to.deep.equal(buildSyncUrls(baseUrl))); - }); - - it('includes all 3 if provided', function() { - expect(getUserSyncs( - { gdprApplies: true, consentString: 'test-gdpr-consent' }, - '1---', - { applicableSections: [1, 2, 3], consentString: 'test-gpp-consent' } - )).to.deep.equal(buildSyncUrls(baseUrl - .replace(/gdpr=\d/, 'gdpr=1') - .replace(/gdpr_consent=/, 'gdpr_consent=test-gdpr-consent') - .replace(/us_privacy=/, 'us_privacy=1---') - .replace(/gpp=/, 'gpp=test-gpp-consent') - .replace(/gpp_sid=/, 'gpp_sid=1,2,3'))); - }); - }); - - describe('supportedMediaTypes', function() { - it('exposes video and banner', function() { - expect(spec.supportedMediaTypes).to.deep.equal([ 'banner', 'video' ]); - }); - }); - - describe('onTimeout', function () { - let fetchStub; - - beforeEach(function () { - fetchStub = sinon.stub(global, 'fetch').resolves(); // Stub fetch globally - }); - - afterEach(function () { - fetchStub.restore(); // Restore the original fetch function - }); - - it('does not call fetch if timeout data is not provided', function () { - spec.onTimeout(null); - expect(fetchStub.callCount).to.equal(0); - }); - - it('calls fetch with the correct URLs if timeout data is provided', function () { - spec.onTimeout([ - { auctionId: 'test-auction-id', timeout: 400 }, - { auctionId: 'test-auction-id-2', timeout: 100 }, - { auctionId: 'test-auction-id-3', timeout: 450 }, - { auctionId: 'test-auction-id-4', timeout: 500 }, - ]); - - expect(fetchStub.calledWith( - 'https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id&ato=400', - { method: 'GET', keepalive: true } - )).to.be.true; - - expect(fetchStub.calledWith( - 'https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-2&ato=100', - { method: 'GET', keepalive: true } - )).to.be.true; - - expect(fetchStub.calledWith( - 'https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-3&ato=450', - { method: 'GET', keepalive: true } - )).to.be.true; - - expect(fetchStub.calledWith( - 'https://krk2.kargo.com/api/v1/event/timeout?aid=test-auction-id-4&ato=500', - { method: 'GET', keepalive: true } - )).to.be.true; - }); - }); -}); diff --git a/test/spec/modules/kimberliteBidAdapter_spec.js b/test/spec/modules/kimberliteBidAdapter_spec.js deleted file mode 100644 index af1e027ca..000000000 --- a/test/spec/modules/kimberliteBidAdapter_spec.js +++ /dev/null @@ -1,260 +0,0 @@ -import { spec, ENDPOINT_URL, expandAuctionMacros } from 'modules/kimberliteBidAdapter.js'; -import { assert } from 'chai'; -import { BANNER, VIDEO } from '../../../src/mediaTypes.js'; - -const BIDDER_CODE = 'kimberlite'; - -describe('kimberliteBidAdapter', function () { - const sizes = [[640, 480]]; - - describe('isBidRequestValid', function () { - let bidRequests; - - beforeEach(function () { - bidRequests = [ - { - mediaTypes: { - [BANNER]: { - sizes: [[320, 240]] - } - }, - params: { - placementId: 'test-placement' - } - }, - { - mediaTypes: { - [VIDEO]: { - mimes: ['video/mp4'] - } - }, - params: { - placementId: 'test-placement' - } - } - ]; - }); - - it('pass on valid banner bidRequest', function () { - assert.isTrue(spec.isBidRequestValid(bidRequests[0])); - }); - - it('fails on missed placementId', function () { - delete bidRequests[0].params.placementId; - assert.isFalse(spec.isBidRequestValid(bidRequests[0])); - }); - - it('fails on empty banner', function () { - delete bidRequests[0].mediaTypes.banner; - assert.isFalse(spec.isBidRequestValid(bidRequests[0])); - }); - - it('fails on empty banner.sizes', function () { - delete bidRequests[0].mediaTypes.banner.sizes; - assert.isFalse(spec.isBidRequestValid(bidRequests[0])); - }); - - it('fails on empty request', function () { - assert.isFalse(spec.isBidRequestValid()); - }); - - it('pass on valid video bidRequest', function () { - assert.isTrue(spec.isBidRequestValid(bidRequests[1])); - }); - - it('fails on missed video.mimes', function () { - delete bidRequests[1].mediaTypes.video.mimes; - assert.isFalse(spec.isBidRequestValid(bidRequests[1])); - }); - }); - - describe('buildRequests', function () { - let bidRequests, bidderRequest; - - beforeEach(function () { - bidRequests = [ - { - mediaTypes: { - [BANNER]: {sizes: sizes} - }, - params: { - placementId: 'test-placement' - } - }, - { - mediaTypes: { - [VIDEO]: { - mimes: ['video/mp4'], - } - }, - params: { - placementId: 'test-placement' - } - } - ]; - - bidderRequest = { - refererInfo: { - domain: 'example.com', - page: 'https://www.example.com/test.html', - } - }; - }); - - it('valid bid request', function () { - const bidRequest = spec.buildRequests(bidRequests, bidderRequest); - - assert.equal(bidRequest.method, 'POST'); - assert.equal(bidRequest.url, ENDPOINT_URL); - assert.ok(bidRequest.data); - - const requestData = bidRequest.data; - expect(requestData.site.page).to.equal(bidderRequest.refererInfo.page); - expect(requestData.site.publisher.domain).to.equal(bidderRequest.refererInfo.domain); - - expect(requestData.imp).to.be.an('array').and.is.not.empty; - - expect(requestData.ext).to.be.an('Object').and.have.all.keys('prebid'); - expect(requestData.ext.prebid).to.be.an('Object').and.have.all.keys('ver', 'adapterVer'); - - const impBannerData = requestData.imp[0]; - expect(impBannerData.banner).is.to.be.an('Object').and.have.all.keys(['format', 'topframe']); - - const bannerData = impBannerData.banner; - expect(bannerData.format).to.be.an('array').and.is.not.empty; - - const formatData = bannerData.format[0]; - expect(formatData).to.be.an('Object').and.have.all.keys('w', 'h'); - - assert.equal(formatData.w, sizes[0][0]); - assert.equal(formatData.h, sizes[0][1]); - - if (FEATURES.VIDEO) { - const impVideoData = requestData.imp[1]; - expect(impVideoData.video).is.to.be.an('Object').and.have.all.keys(['mimes']); - - const videoData = impVideoData.video; - expect(videoData.mimes).to.be.an('array').and.is.not.empty; - expect(videoData.mimes[0]).to.be.a('string').that.equals('video/mp4'); - } - }); - }); - - describe('interpretResponse', function () { - let bidderResponse, bidderRequest, bidRequest, expectedBids; - - const requestId = '07fba8b0-8812-4dc6-b91e-4a525d81729c'; - const bannerAdm = 'landing'; - const videoAdm = 'http://video-test.landing.com?p=${AUCTION_PRICE}&c=${AUCTION_CURRENCY}test vast'; - const nurl = 'http://nurl.landing.com?p=${AUCTION_PRICE}&c=${AUCTION_CURRENCY}'; - const nurlPixel = `
`; - - const currencies = [ - undefined, - 'USD' - ]; - - currencies.forEach(function(currency) { - beforeEach(function () { - bidderResponse = { - body: { - id: requestId, - seatbid: [{ - bid: [ - { - crid: 1, - impid: 1, - price: 1, - adm: bannerAdm, - nurl: nurl - }, - { - crid: 2, - impid: 2, - price: 1, - adm: videoAdm - } - ] - }] - } - }; - - bidderRequest = { - refererInfo: { - domain: 'example.com', - page: 'https://www.example.com/test.html', - }, - bids: [ - { - bidId: 1, - mediaTypes: { - banner: {sizes: sizes} - }, - params: { - placementId: 'test-placement' - } - }, - { - bidId: 2, - mediaTypes: { - video: { - mimes: ['video/mp4'] - } - }, - params: { - placementId: 'test-placement' - } - } - ] - }; - - expectedBids = [ - { - mediaType: 'banner', - requestId: 1, - cpm: 1, - creative_id: 1, - creativeId: 1, - ttl: 300, - netRevenue: true, - ad: nurlPixel + bannerAdm, - meta: {} - }, - { - mediaType: 'video', - requestId: 2, - cpm: 1, - creative_id: 2, - creativeId: 2, - ttl: 300, - netRevenue: true, - vastXml: videoAdm, - meta: {} - }, - ]; - - if (currency) { - expectedBids[0].currency = expectedBids[1].currency = bidderResponse.body.cur = currency; - } - - bidRequest = spec.buildRequests(bidderRequest.bids, bidderRequest); - }); - - it('pass on valid request', function () { - const bids = spec.interpretResponse(bidderResponse, bidRequest); - expectedBids[0].ad = expandAuctionMacros(expectedBids[0].ad, expectedBids[0].cpm, bidderResponse.body.cur); - assert.deepEqual(bids[0], expectedBids[0]); - if (FEATURES.VIDEO) { - expectedBids[1].vastXml = - expandAuctionMacros(expectedBids[1].vastXml, expectedBids[1].cpm, bidderResponse.body.cur); - assert.deepEqual(bids[1], expectedBids[1]); - } - }); - - it('fails on empty response', function () { - const bids = spec.interpretResponse({body: ''}, bidRequest); - assert.empty(bids); - }); - }); - }); -}); diff --git a/test/spec/modules/kiviadsBidAdapter_spec.js b/test/spec/modules/kiviadsBidAdapter_spec.js deleted file mode 100644 index d7f9a233c..000000000 --- a/test/spec/modules/kiviadsBidAdapter_spec.js +++ /dev/null @@ -1,518 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/kiviadsBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'kiviads'; -const adUrl = 'https://lb.kiviads.com/pbjs'; -const syncUrl = 'https://sync.kiviads.com'; - -describe('KiviAdsBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal(adUrl); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal(`${syncUrl}/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0`) - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal(`${syncUrl}/image?pbjs=1&ccpa_consent=1---&coppa=0`) - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal(`${syncUrl}/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0`) - }); - }); -}); diff --git a/test/spec/modules/koblerBidAdapter_spec.js b/test/spec/modules/koblerBidAdapter_spec.js deleted file mode 100644 index 187ccf945..000000000 --- a/test/spec/modules/koblerBidAdapter_spec.js +++ /dev/null @@ -1,789 +0,0 @@ -import {expect} from 'chai'; -import {pageViewId, spec} from 'modules/koblerBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import {config} from 'src/config.js'; -import * as utils from 'src/utils.js'; -import {getRefererInfo} from 'src/refererDetection.js'; -import { setConfig as setCurrencyConfig } from '../../../modules/currency.js'; -import { addFPDToBidderRequest } from '../../helpers/fpd.js'; - -function createBidderRequest(auctionId, timeout, pageUrl, gdprVendorData = {}) { - const gdprConsent = { - consentString: 'BOtmiBKOtmiBKABABAENAFAAAAACeAAA', - apiVersion: 2, - vendorData: gdprVendorData, - gdprApplies: true - }; - return { - bidderRequestId: 'mock-uuid', - auctionId: auctionId || 'c1243d83-0bed-4fdb-8c76-42b456be17d0', - timeout: timeout || 2000, - refererInfo: { - page: pageUrl || 'example.com' - }, - gdprConsent: gdprConsent - }; -} - -function createValidBidRequest(params, bidId, sizes) { - const validBidRequest = { - adUnitCode: 'adunit-code', - bidId: bidId || '22c4871113f461', - bidder: 'kobler', - bidderRequestId: '15246a574e859f', - bidRequestsCount: 1, - bidderRequestsCount: 1, - mediaTypes: { - banner: { - sizes: sizes || [[300, 250], [320, 100]] - } - }, - transactionTd: '04314114-15bd-4638-8664-bdb8bdc60bff' - }; - if (params) { - validBidRequest.params = params; - } - return validBidRequest; -} - -describe('KoblerAdapter', function () { - let sandbox; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - - afterEach(() => { - sandbox.restore() - }); - - describe('inherited functions', function () { - it('exists and is a function', function () { - const adapter = newBidder(spec); - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should not accept a request without bidId as valid', function () { - const bid = { - params: { - someParam: 'abc' - } - }; - - const result = spec.isBidRequestValid(bid); - - expect(result).to.be.false; - }); - - it('should not accept a request without mediaTypes and sizes as valid', function () { - const bid = { - bidId: 'e11768e8-3b71-4453-8698-0a2feb866589' - }; - - const result = spec.isBidRequestValid(bid); - - expect(result).to.be.false; - }); - - it('should not accept a request without mediaTypes and string sizes as valid', function () { - const bid = { - bidId: 'e11768e8-3b71-4453-8698-0a2feb866589', - sizes: 'string' - }; - - const result = spec.isBidRequestValid(bid); - - expect(result).to.be.false; - }); - - it('should not accept a request without mediaTypes and empty sizes as valid', function () { - const bid = { - bidId: 'e11768e8-3b71-4453-8698-0a2feb866589', - sizes: [] - }; - - const result = spec.isBidRequestValid(bid); - - expect(result).to.be.false; - }); - - it('should not accept a request without mediaTypes.banner and sizes as valid', function () { - const bid = { - bidId: 'e11768e8-3b71-4453-8698-0a2feb866589', - mediaTypes: {} - }; - - const result = spec.isBidRequestValid(bid); - - expect(result).to.be.false; - }); - - it('should not accept a request without mediaTypes.banner and empty sizes as valid', function () { - const bid = { - bidId: 'e11768e8-3b71-4453-8698-0a2feb866589', - sizes: [], - mediaTypes: {} - }; - - const result = spec.isBidRequestValid(bid); - - expect(result).to.be.false; - }); - - it('should not accept a request without sizes and string mediaTypes.banner as valid', function () { - const bid = { - bidId: 'e11768e8-3b71-4453-8698-0a2feb866589', - mediaTypes: { - banner: 'string' - } - }; - - const result = spec.isBidRequestValid(bid); - - expect(result).to.be.false; - }); - - it('should not accept a request without sizes and mediaTypes.banner.sizes as valid', function () { - const bid = { - bidId: 'e11768e8-3b71-4453-8698-0a2feb866589', - mediaTypes: { - banner: {} - } - }; - - const result = spec.isBidRequestValid(bid); - - expect(result).to.be.false; - }); - - it('should not accept a request without sizes and string mediaTypes.banner.sizes as valid', function () { - const bid = { - bidId: 'e11768e8-3b71-4453-8698-0a2feb866589', - mediaTypes: { - banner: { - sizes: 'string' - } - } - }; - - const result = spec.isBidRequestValid(bid); - - expect(result).to.be.false; - }); - - it('should not accept a request without sizes and empty mediaTypes.banner.sizes as valid', function () { - const bid = { - bidId: 'e11768e8-3b71-4453-8698-0a2feb866589', - mediaTypes: { - banner: { - sizes: [] - } - } - }; - - const result = spec.isBidRequestValid(bid); - - expect(result).to.be.false; - }); - - it('should accept a request with bidId and sizes as valid', function () { - const bid = { - bidId: 'e11768e8-3b71-4453-8698-0a2feb866589', - sizes: [[5, 5]] - }; - - const result = spec.isBidRequestValid(bid); - - expect(result).to.be.true; - }); - - it('should accept a request with bidId and mediaTypes.banner.sizes as valid', function () { - const bid = { - bidId: 'e11768e8-3b71-4453-8698-0a2feb866589', - mediaTypes: { - banner: { - sizes: [[0, 0]] - } - } - }; - - const result = spec.isBidRequestValid(bid); - - expect(result).to.be.true; - }); - }); - - describe('buildRequests', function () { - it('should read data from bidder request', function () { - const testUrl = 'kobler.no'; - const auctionId = '8319af54-9795-4642-ba3a-6f57d6ff9100'; - const timeout = 5000; - const validBidRequests = [createValidBidRequest()]; - const bidderRequest = createBidderRequest(auctionId, timeout, testUrl); - - const result = spec.buildRequests(validBidRequests, bidderRequest); - const openRtbRequest = JSON.parse(result.data); - - expect(openRtbRequest.tmax).to.be.equal(timeout); - expect(openRtbRequest.id).to.exist; - expect(openRtbRequest.site.page).to.be.equal(testUrl); - }); - - it('should handle missing consent from bidder request', function () { - const testUrl = 'kobler.no'; - const auctionId = 'f3d41a92-104a-4ff7-8164-29197cfbf4af'; - const timeout = 5000; - const validBidRequests = [createValidBidRequest()]; - const bidderRequest = createBidderRequest(auctionId, timeout, testUrl, { - purpose: { - consents: { - 1: false, - 2: false - } - } - }); - - const result = spec.buildRequests(validBidRequests, bidderRequest); - const openRtbRequest = JSON.parse(result.data); - - expect(openRtbRequest.tmax).to.be.equal(timeout); - expect(openRtbRequest.id).to.exist; - expect(openRtbRequest.site.page).to.be.equal(testUrl); - expect(openRtbRequest.ext.kobler.tcf_purpose_2_given).to.be.equal(false); - expect(openRtbRequest.ext.kobler.tcf_purpose_3_given).to.be.equal(false); - }); - - it('should reuse the same page view ID on subsequent calls', function () { - const testUrl = 'kobler.no'; - const auctionId1 = '8319af54-9795-4642-ba3a-6f57d6ff9100'; - const auctionId2 = 'e19f2d0c-602d-4969-96a1-69a22d483f47'; - const timeout = 5000; - const validBidRequests = [createValidBidRequest()]; - const bidderRequest1 = createBidderRequest(auctionId1, timeout, testUrl); - const bidderRequest2 = createBidderRequest(auctionId2, timeout, testUrl); - - const openRtbRequest1 = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest1).data); - expect(openRtbRequest1.ext.kobler.page_view_id).to.be.equal(pageViewId); - const openRtbRequest2 = JSON.parse(spec.buildRequests(validBidRequests, bidderRequest2).data); - expect(openRtbRequest2.ext.kobler.page_view_id).to.be.equal(pageViewId); - }); - - it('should read data from valid bid requests', function () { - const firstSize = [400, 800]; - const secondSize = [450, 950]; - const sizes = [firstSize, secondSize]; - const bidId = '3a56a019-4835-4f75-811c-76fac6853a2c'; - const validBidRequests = [ - createValidBidRequest( - undefined, - bidId, - sizes - ) - ]; - const bidderRequest = createBidderRequest(); - - const result = spec.buildRequests(validBidRequests, bidderRequest); - const openRtbRequest = JSON.parse(result.data); - - expect(openRtbRequest.imp.length).to.be.equal(1); - expect(openRtbRequest.imp[0].id).to.be.equal(bidId); - expect(openRtbRequest.imp[0].banner.w).to.be.equal(firstSize[0]); - expect(openRtbRequest.imp[0].banner.h).to.be.equal(firstSize[1]); - expect(openRtbRequest.imp[0].banner.format.length).to.be.equal(2); - expect(openRtbRequest.imp[0].banner.format[0].w).to.be.equal(firstSize[0]); - expect(openRtbRequest.imp[0].banner.format[0].h).to.be.equal(firstSize[1]); - expect(openRtbRequest.imp[0].banner.format[1].w).to.be.equal(secondSize[0]); - expect(openRtbRequest.imp[0].banner.format[1].h).to.be.equal(secondSize[1]); - }); - - it('should use 0x0 as default size', function () { - const validBidRequests = [ - createValidBidRequest( - undefined, - undefined, - [] - ) - ]; - const bidderRequest = createBidderRequest(); - - const result = spec.buildRequests(validBidRequests, bidderRequest); - const openRtbRequest = JSON.parse(result.data); - - expect(openRtbRequest.imp.length).to.be.equal(1); - expect(openRtbRequest.imp[0].banner.w).to.be.equal(0); - expect(openRtbRequest.imp[0].banner.h).to.be.equal(0); - expect(openRtbRequest.imp[0].banner.format.length).to.be.equal(1); - expect(openRtbRequest.imp[0].banner.format[0].w).to.be.equal(0); - expect(openRtbRequest.imp[0].banner.format[0].h).to.be.equal(0); - }); - - it('should read test from valid bid requests', function () { - const validBidRequests = [ - createValidBidRequest( - { - test: true - } - ) - ]; - const bidderRequest = createBidderRequest(); - - const result = spec.buildRequests(validBidRequests, bidderRequest); - expect(result.url).to.be.equal('https://bid-service.dev.essrtb.com/bid/prebid_rtb_call'); - - const openRtbRequest = JSON.parse(result.data); - expect(openRtbRequest.site.page).to.be.equal('example.com'); - expect(openRtbRequest.test).to.be.equal(1); - }); - - it('should not read pageUrl from config when not testing', function () { - config.setConfig({ - pageUrl: 'https://testing-url.com' - }); - const validBidRequests = [ - createValidBidRequest() - ]; - const bidderRequest = createBidderRequest( - 'f85d61cc-ed11-4b6c-aefb-87943263cedb', - 2000, - 'https://non-testing-url.net' - ); - - const result = spec.buildRequests(validBidRequests, bidderRequest); - expect(result.url).to.be.equal('https://bid.essrtb.com/bid/prebid_rtb_call'); - - const openRtbRequest = JSON.parse(result.data); - expect(openRtbRequest.site.page).to.be.equal('https://non-testing-url.net'); - expect(openRtbRequest.test).to.be.equal(0); - }); - - it('should read floorPrice from valid bid requests', function () { - const floorPrice = 4.343; - const validBidRequests = [ - createValidBidRequest( - { - floorPrice: floorPrice - } - ) - ]; - const bidderRequest = createBidderRequest(); - - const result = spec.buildRequests(validBidRequests, bidderRequest); - const openRtbRequest = JSON.parse(result.data); - - expect(openRtbRequest.imp.length).to.be.equal(1); - expect(openRtbRequest.imp[0].bidfloor).to.be.equal(floorPrice); - }); - - it('should read dealIds from valid bid requests', function () { - const dealIds1 = ['78214682234823']; - const dealIds2 = ['89913861235234', '27368423545328640']; - const validBidRequests = [ - createValidBidRequest( - { - dealIds: dealIds1 - } - ), - createValidBidRequest( - { - dealIds: dealIds2 - } - ) - ]; - const bidderRequest = createBidderRequest(); - - const result = spec.buildRequests(validBidRequests, bidderRequest); - const openRtbRequest = JSON.parse(result.data); - - expect(openRtbRequest.imp.length).to.be.equal(2); - expect(openRtbRequest.imp[0].pmp.deals.length).to.be.equal(1); - expect(openRtbRequest.imp[0].pmp.deals[0].id).to.be.equal(dealIds1[0]); - expect(openRtbRequest.imp[1].pmp.deals.length).to.be.equal(2); - expect(openRtbRequest.imp[1].pmp.deals[0].id).to.be.equal(dealIds2[0]); - expect(openRtbRequest.imp[1].pmp.deals[1].id).to.be.equal(dealIds2[1]); - }); - - it('should read floor price using floors module', function () { - const floorPriceFor580x400 = 6.5148; - const floorPriceForAnySize = 4.2343; - const validBidRequests = [ - createValidBidRequest(undefined, '98efe127-f926-4dde-b988-db8e5dba5a76', [[580, 400]]), - createValidBidRequest(undefined, 'c7698d4a-94f4-4a6b-a928-7e1facfbf752', []) - ]; - validBidRequests.forEach(validBidRequest => { - validBidRequest.getFloor = function (params) { - let floorPrice; - if (utils.isArray(params.size) && params.size[0] === 580 && params.size[1] === 400) { - floorPrice = floorPriceFor580x400; - } else if (params.size === '*') { - floorPrice = floorPriceForAnySize - } else { - floorPrice = 0 - } - return { - currency: params.currency, - floor: floorPrice - } - } - }) - const bidderRequest = createBidderRequest(); - - const result = spec.buildRequests(validBidRequests, bidderRequest); - const openRtbRequest = JSON.parse(result.data); - - expect(openRtbRequest.imp.length).to.be.equal(2); - expect(openRtbRequest.imp[0].id).to.be.equal('98efe127-f926-4dde-b988-db8e5dba5a76'); - expect(openRtbRequest.imp[0].bidfloor).to.be.equal(floorPriceFor580x400); - expect(openRtbRequest.imp[1].id).to.be.equal('c7698d4a-94f4-4a6b-a928-7e1facfbf752'); - expect(openRtbRequest.imp[1].bidfloor).to.be.equal(floorPriceForAnySize); - }); - - it('should create whole OpenRTB request', function () { - const validBidRequests = [ - createValidBidRequest( - { - floorPrice: 5.6234, - dealIds: ['623472534328234'] - }, - '953ee65d-d18a-484f-a840-d3056185a060', - [[400, 600]] - ), - createValidBidRequest( - { - floorPrice: 3.2543, - dealIds: ['92368234753283', '263845832942'] - }, - '8320bf79-9d90-4a17-87c6-5d505706a921', - [[400, 500], [200, 250], [300, 350]] - ), - createValidBidRequest( - undefined, - 'd0de713b-32e3-4191-a2df-a007f08ffe72', - [[800, 900]] - ) - ]; - const bidderRequest = createBidderRequest( - '9ff580cf-e10e-4b66-add7-40ac0c804e21', - 4500, - 'bid.kobler.no', - { - purpose: { - consents: { - 1: false, - 2: true, - 3: false - } - }, - publisher: { - restrictions: { - '2': { - // require consent - '11': 1 - } - } - } - } - ); - - const result = spec.buildRequests(validBidRequests, bidderRequest); - const openRtbRequest = JSON.parse(result.data); - - const expectedOpenRtbRequest = { - id: 'mock-uuid', - at: 1, - tmax: 4500, - cur: ['USD'], - imp: [ - { - id: '953ee65d-d18a-484f-a840-d3056185a060', - banner: { - format: [ - { - w: 400, - h: 600 - } - ], - w: 400, - h: 600 - }, - bidfloor: 5.6234, - bidfloorcur: 'USD', - pmp: { - deals: [ - { - id: '623472534328234' - } - ] - } - }, - { - id: '8320bf79-9d90-4a17-87c6-5d505706a921', - banner: { - format: [ - { - w: 400, - h: 500 - }, - { - w: 200, - h: 250 - }, - { - w: 300, - h: 350 - } - ], - w: 400, - h: 500 - }, - bidfloor: 3.2543, - bidfloorcur: 'USD', - pmp: { - deals: [ - { - id: '92368234753283' - }, - { - id: '263845832942' - } - ] - } - }, - { - id: 'd0de713b-32e3-4191-a2df-a007f08ffe72', - banner: { - format: [ - { - w: 800, - h: 900 - } - ], - w: 800, - h: 900 - }, - bidfloor: 0, - bidfloorcur: 'USD', - pmp: {} - } - ], - device: { - devicetype: 2, - ua: navigator.userAgent - }, - site: { - page: 'bid.kobler.no' - }, - test: 0, - ext: { - kobler: { - tcf_purpose_2_given: true, - tcf_purpose_3_given: false, - page_view_id: pageViewId - } - } - }; - - expect(openRtbRequest).to.deep.equal(expectedOpenRtbRequest); - }); - }); - - describe('interpretResponse', function () { - it('should handle empty body', function () { - const responseWithEmptyBody = { - body: undefined - }; - const bids = spec.interpretResponse(responseWithEmptyBody) - - expect(bids.length).to.be.equal(0); - }); - - it('should generate bids from OpenRTB response', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'NOK' - } - }); - const responseWithTwoBids = { - body: { - seatbid: [ - { - bid: [ - { - impid: '6194ddef-89a4-404f-9efd-6b718fc23308', - price: 7.981, - nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=sdhfusdaobfadslf234324&sp=${AUCTION_PRICE}&sp_cur=${AUCTION_PRICE_CURRENCY}&asp=${AD_SERVER_PRICE}&asp_cur=${AD_SERVER_PRICE_CURRENCY}', - crid: 'edea9b03-3a57-41aa-9c00-abd673e22006', - cid: '572', - dealid: '', - w: 320, - h: 250, - adm: '', - adomain: [ - 'https://kobler.no' - ] - }, - { - impid: '2ec0b40f-d3ca-4ba5-8ce3-48290565690f', - price: 6.71234, - nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=nbashgufvishdafjk23432&sp=${AUCTION_PRICE}&sp_cur=${AUCTION_PRICE_CURRENCY}&asp=${AD_SERVER_PRICE}&asp_cur=${AD_SERVER_PRICE_CURRENCY}', - crid: 'fa2d5af7-2678-4204-9023-44c526160742', - dealid: '2783483223432342', - cid: '800', - w: 580, - h: 400, - adm: '', - adomain: [ - 'https://bid.kobler.no' - ] - } - ] - } - ], - cur: 'USD' - } - }; - const bids = spec.interpretResponse(responseWithTwoBids, {}) - - const expectedBids = [ - { - requestId: '6194ddef-89a4-404f-9efd-6b718fc23308', - cpm: 7.981, - currency: 'USD', - width: 320, - height: 250, - creativeId: 'edea9b03-3a57-41aa-9c00-abd673e22006', - dealId: '', - netRevenue: true, - ttl: 600, - ad: '', - nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=sdhfusdaobfadslf234324&sp=${AUCTION_PRICE}&sp_cur=${AUCTION_PRICE_CURRENCY}&asp=${AD_SERVER_PRICE}&asp_cur=${AD_SERVER_PRICE_CURRENCY}', - cid: '572', - meta: { - advertiserDomains: [ - 'https://kobler.no' - ] - } - }, - { - requestId: '2ec0b40f-d3ca-4ba5-8ce3-48290565690f', - cpm: 6.71234, - currency: 'USD', - width: 580, - height: 400, - creativeId: 'fa2d5af7-2678-4204-9023-44c526160742', - dealId: '2783483223432342', - netRevenue: true, - ttl: 600, - ad: '', - nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=nbashgufvishdafjk23432&sp=${AUCTION_PRICE}&sp_cur=${AUCTION_PRICE_CURRENCY}&asp=${AD_SERVER_PRICE}&asp_cur=${AD_SERVER_PRICE_CURRENCY}', - cid: '800', - meta: { - advertiserDomains: [ - 'https://bid.kobler.no' - ] - } - } - ]; - expect(bids).to.deep.equal(expectedBids); - }); - }); - - describe('onBidWon', function () { - beforeEach(function () { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function () { - utils.triggerPixel.restore(); - }); - - it('Should not trigger pixel if bid does not contain nurl', function () { - spec.onBidWon({}); - - expect(utils.triggerPixel.called).to.be.false; - }); - - it('Should not trigger pixel if nurl is empty', function () { - spec.onBidWon({ - nurl: '' - }); - - expect(utils.triggerPixel.called).to.be.false; - }); - - it('Should trigger pixel with replaced nurl if nurl is not empty', function () { - setCurrencyConfig({ adServerCurrency: 'NOK' }); - const validBidRequests = [{ params: {} }]; - const refererInfo = { page: 'page' }; - const bidderRequest = { refererInfo }; - return addFPDToBidderRequest(bidderRequest).then(res => { - JSON.parse(spec.buildRequests(validBidRequests, res).data); - const bids = spec.interpretResponse({ body: { seatbid: [{ bid: [{ - originalCpm: 1.532, - price: 8.341, - currency: 'NOK', - nurl: 'https://atag.essrtb.com/serve/prebid_win_notification?payload=sdhfusdaobfadslf234324&sp=${AUCTION_PRICE}&sp_cur=${AUCTION_PRICE_CURRENCY}&asp=${AD_SERVER_PRICE}&asp_cur=${AD_SERVER_PRICE_CURRENCY}', - }]}]}}, { bidderRequest: res }); - const bidToWon = bids[0]; - bidToWon.adserverTargeting = { - hb_pb: 8 - } - spec.onBidWon(bidToWon); - - expect(utils.triggerPixel.callCount).to.be.equal(1); - expect(utils.triggerPixel.firstCall.args[0]).to.be.equal( - 'https://atag.essrtb.com/serve/prebid_win_notification?payload=sdhfusdaobfadslf234324&sp=8.341&sp_cur=NOK&asp=8&asp_cur=NOK' - ); - setCurrencyConfig({}); - }); - }); - }); - - describe('onTimeout', function () { - beforeEach(function () { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function () { - utils.triggerPixel.restore(); - }); - - it('Should not trigger pixel if timeout data is not array', function () { - spec.onTimeout(null); - - expect(utils.triggerPixel.called).to.be.false; - }); - - it('Should not trigger pixel if timeout data is empty', function () { - spec.onTimeout([]); - - expect(utils.triggerPixel.called).to.be.false; - }); - - it('Should trigger pixel with query parameters if timeout data not empty', function () { - spec.onTimeout([ - { - adUnitCode: 'adunit-code', - bidId: 'ef236c6c-e934-406b-a877-d7be8e8a839a', - timeout: 100, - params: [], - }, - { - adUnitCode: 'adunit-code-2', - bidId: 'ca4121c8-9a4a-46ba-a624-e9b64af206f2', - timeout: 100, - params: [], - } - ]); - - expect(utils.triggerPixel.callCount).to.be.equal(2); - expect(utils.triggerPixel.getCall(0).args[0]).to.be.equal( - 'https://bid.essrtb.com/notify/prebid_timeout?ad_unit_code=adunit-code&' + - 'bid_id=ef236c6c-e934-406b-a877-d7be8e8a839a&timeout=100&page_url=' + encodeURIComponent(getRefererInfo().page) - ); - expect(utils.triggerPixel.getCall(1).args[0]).to.be.equal( - 'https://bid.essrtb.com/notify/prebid_timeout?ad_unit_code=adunit-code-2&' + - 'bid_id=ca4121c8-9a4a-46ba-a624-e9b64af206f2&timeout=100&page_url=' + encodeURIComponent(getRefererInfo().page) - ); - }); - }); -}); diff --git a/test/spec/modules/krushmediaBidAdapter_spec.js b/test/spec/modules/krushmediaBidAdapter_spec.js deleted file mode 100644 index 98bdbcbb8..000000000 --- a/test/spec/modules/krushmediaBidAdapter_spec.js +++ /dev/null @@ -1,518 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/krushmediaBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'krushmedia'; - -describe('KrushmediabBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - key: 783 - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - key: 783 - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - key: 783 - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://ads4.krushmedia.com/?c=rtb&m=hb'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.key).to.be.equal(783); - expect(placement.traffic).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.traffic === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.traffic) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.wPlayer).to.be.an('number'); - expect(placement.hPlayer).to.be.an('number'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.traffic).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.traffic === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.traffic) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.wPlayer).to.be.an('number'); - expect(placement.hPlayer).to.be.an('number'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.krushmedia.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.krushmedia.com/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.krushmedia.com/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/kubientBidAdapter_spec.js b/test/spec/modules/kubientBidAdapter_spec.js deleted file mode 100644 index 4a162e857..000000000 --- a/test/spec/modules/kubientBidAdapter_spec.js +++ /dev/null @@ -1,507 +0,0 @@ -import { expect, assert } from 'chai'; -import { spec } from 'modules/kubientBidAdapter.js'; -import { BANNER, VIDEO } from '../../../src/mediaTypes.js'; -import {config} from '../../../src/config.js'; - -function encodeQueryData(data) { - return Object.keys(data).map(function(key) { - return [key, data[key]].map(encodeURIComponent).join('='); - }).join('&'); -} - -describe('KubientAdapter', function () { - const bidBanner = { - bidId: '2dd581a2b6281d', - bidder: 'kubient', - bidderRequestId: '145e1d6a7837c9', - params: { - zoneid: '5678' - }, - getFloor: function(params) { - return { - floor: 0, - currency: 'USD' - }; - }, - auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e62', - ortb2: { - source: { - ext: { - schain: { - ver: '1.1', - complete: 1, - nodes: [ - { - asi: 'example.com', - sid: '0', - hp: 1, - rid: 'bidrequestid', - domain: 'example.com' - } - ] - } - } - } - } - }; - const bidVideo = { - bidId: '1dd581a2b6281d', - bidder: 'kubient', - bidderRequestId: '245e1d6a7837c9', - params: { - zoneid: '5676' - }, - getFloor: function(params) { - return { - floor: 1.0, - currency: 'USD' - }; - }, - auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d1', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480], - mimes: ['video/mp4'], - protocols: [1] - } - }, - transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e61', - ortb2: { - source: { - ext: { - schain: { - ver: '1.1', - complete: 1, - nodes: [ - { - asi: 'example.com', - sid: '0', - hp: 1, - rid: 'bidrequestid', - domain: 'example.com' - } - ] - } - } - } - } - }; - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const uspConsentData = '1YCC'; - const bidderRequest = { - bidderCode: 'kubient', - auctionId: 'fffffff-ffff-ffff-ffff-ffffffffffff', - bidderRequestId: 'ffffffffffffff', - start: 1472239426002, - auctionStart: 1472239426000, - timeout: 5000, - refererInfo: { - page: 'http://www.example.com', - reachedTop: true, - }, - gdprConsent: { - consentString: consentString, - gdprApplies: true - }, - uspConsent: uspConsentData - }; - describe('buildRequestBanner', function () { - beforeEach(function () { - config.resetConfig(); - }); - it('Creates Banner 1 ServerRequest object with method, URL and data', function () { - config.setConfig({'coppa': false}); - const serverRequests = spec.buildRequests([bidBanner], Object.assign({}, bidderRequest, {bids: [bidBanner]})); - expect(serverRequests).to.be.an('array'); - for (let i = 0; i < serverRequests.length; i++) { - const serverRequest = serverRequests[i]; - expect(serverRequest.method).to.be.a('string'); - expect(serverRequest.url).to.be.a('string'); - expect(serverRequest.data).to.be.a('string'); - expect(serverRequest.method).to.equal('POST'); - expect(serverRequest.url).to.equal('https://kssp.kbntx.ch/kubprebidjs'); - const data = JSON.parse(serverRequest.data); - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('v', 'requestId', 'adSlots', 'gdpr', 'referer', 'tmax', 'consent', 'consentGiven', 'uspConsent'); - expect(data.v).to.exist.and.to.be.a('string'); - expect(data.requestId).to.exist.and.to.be.a('string'); - expect(data.referer).to.be.a('string'); - expect(data.tmax).to.exist.and.to.be.a('number'); - expect(data.gdpr).to.exist.and.to.be.within(0, 1); - expect(data.consent).to.equal(consentString); - expect(data.uspConsent).to.exist.and.to.equal(uspConsentData); - for (let j = 0; j < data['adSlots'].length; j++) { - const adSlot = data['adSlots'][i]; - expect(adSlot).to.have.all.keys('bidId', 'zoneId', 'banner', 'schain'); - expect(adSlot.bidId).to.be.a('string').and.to.equal(bidBanner.bidId); - expect(adSlot.zoneId).to.be.a('string').and.to.equal(bidBanner.params.zoneid); - expect(adSlot.schain).to.be.an('object'); - expect(adSlot.banner).to.be.an('object'); - } - } - }); - }); - describe('buildRequestVideo', function () { - beforeEach(function () { - config.resetConfig(); - }); - it('Creates Video 1 ServerRequest object with method, URL and data', function () { - config.setConfig({'coppa': false}); - const serverRequests = spec.buildRequests([bidVideo], Object.assign({}, bidderRequest, {bids: [bidVideo]})); - expect(serverRequests).to.be.an('array'); - for (let i = 0; i < serverRequests.length; i++) { - const serverRequest = serverRequests[i]; - expect(serverRequest.method).to.be.a('string'); - expect(serverRequest.url).to.be.a('string'); - expect(serverRequest.data).to.be.a('string'); - expect(serverRequest.method).to.equal('POST'); - expect(serverRequest.url).to.equal('https://kssp.kbntx.ch/kubprebidjs'); - const data = JSON.parse(serverRequest.data); - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('v', 'requestId', 'adSlots', 'gdpr', 'referer', 'tmax', 'consent', 'consentGiven', 'uspConsent'); - expect(data.v).to.exist.and.to.be.a('string'); - expect(data.requestId).to.exist.and.to.be.a('string'); - expect(data.referer).to.be.a('string'); - expect(data.tmax).to.exist.and.to.be.a('number'); - expect(data.gdpr).to.exist.and.to.be.within(0, 1); - expect(data.consent).to.equal(consentString); - expect(data.uspConsent).to.exist.and.to.equal(uspConsentData); - for (let j = 0; j < data['adSlots'].length; j++) { - const adSlot = data['adSlots'][i]; - expect(adSlot).to.have.all.keys('bidId', 'zoneId', 'floor', 'video', 'schain'); - expect(adSlot.bidId).to.be.a('string').and.to.equal(bidVideo.bidId); - expect(adSlot.zoneId).to.be.a('string').and.to.equal(bidVideo.params.zoneid); - expect(adSlot.floor).to.be.a('number'); - expect(adSlot.schain).to.be.an('object'); - expect(adSlot.video).to.be.an('object'); - } - } - }); - }); - describe('buildRequestBanner', function () { - beforeEach(function () { - config.resetConfig(); - }); - it('Creates Banner 2 ServerRequest object with method, URL and data with bidBanner', function () { - config.setConfig({'coppa': true}); - const serverRequests = spec.buildRequests([bidBanner], Object.assign({}, bidderRequest, {bids: [bidBanner]})); - expect(serverRequests).to.be.an('array'); - for (let i = 0; i < serverRequests.length; i++) { - const serverRequest = serverRequests[i]; - expect(serverRequest.method).to.be.a('string'); - expect(serverRequest.url).to.be.a('string'); - expect(serverRequest.data).to.be.a('string'); - expect(serverRequest.method).to.equal('POST'); - expect(serverRequest.url).to.equal('https://kssp.kbntx.ch/kubprebidjs'); - const data = JSON.parse(serverRequest.data); - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('v', 'requestId', 'adSlots', 'gdpr', 'coppa', 'referer', 'tmax', 'consent', 'consentGiven', 'uspConsent'); - expect(data.v).to.exist.and.to.be.a('string'); - expect(data.requestId).to.exist.and.to.be.a('string'); - expect(data.coppa).to.be.a('number').and.to.equal(1); - expect(data.referer).to.be.a('string'); - expect(data.tmax).to.exist.and.to.be.a('number'); - expect(data.gdpr).to.exist.and.to.be.within(0, 1); - expect(data.consent).to.equal(consentString); - expect(data.uspConsent).to.exist.and.to.equal(uspConsentData); - for (let j = 0; j < data['adSlots'].length; j++) { - const adSlot = data['adSlots'][i]; - expect(adSlot).to.have.all.keys('bidId', 'zoneId', 'banner', 'schain'); - expect(adSlot.bidId).to.be.a('string').and.to.equal(bidBanner.bidId); - expect(adSlot.zoneId).to.be.a('string').and.to.equal(bidBanner.params.zoneid); - expect(adSlot.schain).to.be.an('object'); - expect(adSlot.banner).to.be.an('object'); - } - } - }); - }); - describe('buildRequestVideo', function () { - beforeEach(function () { - config.resetConfig(); - }); - it('Creates Video 2 ServerRequest object with method, URL and data', function () { - config.setConfig({'coppa': true}); - const serverRequests = spec.buildRequests([bidVideo], Object.assign({}, bidderRequest, {bids: [bidVideo]})); - expect(serverRequests).to.be.an('array'); - for (let i = 0; i < serverRequests.length; i++) { - const serverRequest = serverRequests[i]; - expect(serverRequest.method).to.be.a('string'); - expect(serverRequest.url).to.be.a('string'); - expect(serverRequest.data).to.be.a('string'); - expect(serverRequest.method).to.equal('POST'); - expect(serverRequest.url).to.equal('https://kssp.kbntx.ch/kubprebidjs'); - const data = JSON.parse(serverRequest.data); - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('v', 'requestId', 'adSlots', 'gdpr', 'coppa', 'referer', 'tmax', 'consent', 'consentGiven', 'uspConsent'); - expect(data.v).to.exist.and.to.be.a('string'); - expect(data.requestId).to.exist.and.to.be.a('string'); - expect(data.coppa).to.be.a('number').and.to.equal(1); - expect(data.referer).to.be.a('string'); - expect(data.tmax).to.exist.and.to.be.a('number'); - expect(data.gdpr).to.exist.and.to.be.within(0, 1); - expect(data.consent).to.equal(consentString); - expect(data.uspConsent).to.exist.and.to.equal(uspConsentData); - for (let j = 0; j < data['adSlots'].length; j++) { - const adSlot = data['adSlots'][i]; - expect(adSlot).to.have.all.keys('bidId', 'zoneId', 'floor', 'video', 'schain'); - expect(adSlot.bidId).to.be.a('string').and.to.equal(bidVideo.bidId); - expect(adSlot.zoneId).to.be.a('string').and.to.equal(bidVideo.params.zoneid); - expect(adSlot.floor).to.be.a('number'); - expect(adSlot.schain).to.be.an('object'); - expect(adSlot.video).to.be.an('object'); - } - } - }); - }); - describe('isBidRequestValid', function () { - beforeEach(function () { - config.resetConfig(); - }); - it('Should return true when required params are found', function () { - expect(spec.isBidRequestValid(bidBanner)).to.be.true; - expect(spec.isBidRequestValid(bidVideo)).to.be.true; - }); - it('Should return false when required params are not found', function () { - expect(spec.isBidRequestValid(bidBanner)).to.be.true; - expect(spec.isBidRequestValid(bidVideo)).to.be.true; - }); - it('Should return false when params are not found', function () { - delete bidBanner.params; - expect(spec.isBidRequestValid(bidBanner)).to.be.false; - delete bidVideo.params; - expect(spec.isBidRequestValid(bidVideo)).to.be.false; - }); - }); - describe('interpretResponse', function () { - beforeEach(function () { - config.resetConfig(); - }); - it('Should interpret response', function () { - const serverResponse = { - body: - { - seatbid: [ - { - bid: [ - { - bidId: '000', - price: 1.5, - adm: '
test
', - creativeId: 'creativeId', - w: 300, - h: 250, - cur: 'USD', - netRevenue: false, - ttl: 360, - meta: {adomain: ['google.com', 'yahoo.com']} - } - ] - } - ] - } - }; - const bannerResponses = spec.interpretResponse(serverResponse); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'ad', 'creativeId', 'width', 'height', 'currency', 'netRevenue', 'ttl', 'meta'); - expect(dataItem.requestId).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.seatbid[0].bid[0].bidId); - expect(dataItem.cpm).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].price); - expect(dataItem.ad).to.exist.and.to.be.a('string').and.to.have.string(serverResponse.body.seatbid[0].bid[0].adm); - expect(dataItem.creativeId).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.seatbid[0].bid[0].creativeId); - expect(dataItem.width).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].w); - expect(dataItem.height).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].h); - expect(dataItem.currency).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.seatbid[0].bid[0].cur); - expect(dataItem.netRevenue).to.exist.and.to.be.a('boolean').and.to.equal(serverResponse.body.seatbid[0].bid[0].netRevenue); - expect(dataItem.ttl).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].ttl); - expect(dataItem.meta).to.exist.and.to.be.a('object'); - expect(dataItem.meta.advertiserDomains).to.exist.and.to.be.a('array').and.to.equal(serverResponse.body.seatbid[0].bid[0].meta.adomain); - }); - it('Should return no ad when not given a server response', function () { - const ads = spec.interpretResponse(null); - expect(ads).to.be.an('array').and.to.have.length(0); - }); - }); - - describe('interpretResponse Video', function () { - beforeEach(function () { - config.resetConfig(); - }); - it('Should interpret response', function () { - const serverResponse = { - body: - { - seatbid: [ - { - bid: [ - { - bidId: '000', - price: 1.5, - adm: '
test
', - creativeId: 'creativeId', - w: 300, - h: 250, - mediaType: VIDEO, - cur: 'USD', - netRevenue: false, - ttl: 360, - meta: {adomain: ['google.com', 'yahoo.com']} - } - ] - } - ] - } - }; - const bannerResponses = spec.interpretResponse(serverResponse); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'ad', 'creativeId', 'width', 'height', 'currency', 'netRevenue', 'ttl', 'meta', 'mediaType', 'vastXml'); - expect(dataItem.requestId).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.seatbid[0].bid[0].bidId); - expect(dataItem.cpm).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].price); - expect(dataItem.ad).to.exist.and.to.be.a('string').and.to.have.string(serverResponse.body.seatbid[0].bid[0].adm); - expect(dataItem.creativeId).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.seatbid[0].bid[0].creativeId); - expect(dataItem.width).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].w); - expect(dataItem.height).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].h); - expect(dataItem.currency).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.seatbid[0].bid[0].cur); - expect(dataItem.netRevenue).to.exist.and.to.be.a('boolean').and.to.equal(serverResponse.body.seatbid[0].bid[0].netRevenue); - expect(dataItem.ttl).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].ttl); - expect(dataItem.meta).to.exist.and.to.be.a('object'); - expect(dataItem.meta.advertiserDomains).to.exist.and.to.be.a('array').and.to.equal(serverResponse.body.seatbid[0].bid[0].meta.adomain); - expect(dataItem.mediaType).to.exist.and.to.equal(VIDEO); - expect(dataItem.vastXml).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.seatbid[0].bid[0].adm); - }); - it('Should return no ad when not given a server response', function () { - const ads = spec.interpretResponse(null); - expect(ads).to.be.an('array').and.to.have.length(0); - }); - }); - - describe('getUserSyncs', function () { - beforeEach(function () { - config.resetConfig(); - }); - it('should register the sync image without gdpr', function () { - const syncOptions = { - pixelEnabled: true - }; - const values = {}; - const serverResponses = null; - const gdprConsent = { - consentString: consentString - }; - const uspConsent = null; - config.setConfig({ - userSync: { - filterSettings: { - image: { - bidders: '*', - filter: 'include' - } - } - } - }); - const syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent); - values['consent'] = consentString; - expect(syncs).to.be.an('array').and.to.have.length(1); - expect(syncs[0].type).to.equal('image'); - expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?' + encodeQueryData(values)); - }); - it('should register the sync image with gdpr', function () { - const syncOptions = { - pixelEnabled: true - }; - const values = {}; - const serverResponses = null; - const gdprConsent = { - gdprApplies: true, - consentString: consentString - }; - const uspConsent = null; - config.setConfig({ - userSync: { - filterSettings: { - image: { - bidders: '*', - filter: 'include' - } - } - } - }); - const syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent); - values['gdpr'] = 1; - values['consent'] = consentString; - expect(syncs).to.be.an('array').and.to.have.length(1); - expect(syncs[0].type).to.equal('image'); - expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?' + encodeQueryData(values)); - }); - it('should register the sync image with gdpr vendor', function () { - const syncOptions = { - pixelEnabled: true - }; - const values = {}; - const serverResponses = null; - const gdprConsent = { - gdprApplies: true, - consentString: consentString, - apiVersion: 2, - vendorData: { - vendor: { - consents: { - 794: 1 - } - } - } - }; - const uspConsent = null; - config.setConfig({ - userSync: { - filterSettings: { - image: { - bidders: '*', - filter: 'include' - } - } - } - }); - const syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent); - values['gdpr'] = 1; - values['consent'] = consentString; - expect(syncs).to.be.an('array').and.to.have.length(1); - expect(syncs[0].type).to.equal('image'); - expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?' + encodeQueryData(values)); - }); - it('should register the sync image without gdpr and with uspConsent', function () { - const syncOptions = { - pixelEnabled: true - }; - const values = {}; - const serverResponses = null; - const gdprConsent = { - consentString: consentString - }; - const uspConsent = '1YNN'; - config.setConfig({ - userSync: { - filterSettings: { - image: { - bidders: '*', - filter: 'include' - } - } - } - }); - const syncs = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent, uspConsent); - values['consent'] = consentString; - values['usp'] = uspConsent; - expect(syncs).to.be.an('array').and.to.have.length(1); - expect(syncs[0].type).to.equal('image'); - expect(syncs[0].url).to.equal('https://matching.kubient.net/match/sp?' + encodeQueryData(values)); - }); - }) -}); diff --git a/test/spec/modules/kueezRtbBidAdapter_spec.js b/test/spec/modules/kueezRtbBidAdapter_spec.js deleted file mode 100644 index 08e4fefda..000000000 --- a/test/spec/modules/kueezRtbBidAdapter_spec.js +++ /dev/null @@ -1,815 +0,0 @@ -import {expect} from 'chai'; -import { - spec as adapter, - createDomain, - storage, - getAndSetFirstPartyData, - createFirstPartyData, -} from 'modules/kueezRtbBidAdapter.js'; -import * as utils from 'src/utils.js'; -import {version} from 'package.json'; -import {useFakeTimers} from 'sinon'; -import {BANNER, VIDEO} from '../../../src/mediaTypes.js'; -import {config} from '../../../src/config.js'; -import { - hashCode, - extractPID, - extractCID, - extractSubDomain, - getStorageItem, - setStorageItem, - tryParseJSON, - getUniqueDealId, -} from '../../../libraries/vidazooUtils/bidderUtils.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -export const TEST_ID_SYSTEMS = ['britepoolid', 'criteoId', 'id5id', 'idl_env', 'lipb', 'netId', 'parrableId', 'pubcid', 'tdid', 'pubProvidedId']; - -const SUB_DOMAIN = 'exchange'; - -const BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': 'div-gpt-ad-12345-0', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '59db6b3b4ffaa70004f45cdc', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1, - 'ext': { - 'param1': 'loremipsum', - 'param2': 'dolorsitamet' - } - }, - 'placementCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - 'sizes': [[300, 250], [300, 600]], - 'bidderRequestId': '1fdb5ff1b6eaa7', - 'auctionId': 'auction_id', - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'requestId': 'b0777d85-d061-450e-9bc7-260dd54bbb7a', - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'mediaTypes': [BANNER], - 'ortb2Imp': { - 'ext': { - 'gpid': '0123456789' - } - } -}; - -const VIDEO_BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': '63550ad1ff6642d368cba59dh5884270560', - 'bidderRequestId': '12a8ae9ada9c13', - 'transactionId': '56e184c6-bde9-497b-b9b9-cf47a61381ee', - 'auctionId': 'auction_id', - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '635509f7ff6642d368cb9837', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1 - }, - 'sizes': [[545, 307]], - 'mediaTypes': { - 'video': { - 'playerSize': [[545, 307]], - 'context': 'instream', - 'mimes': [ - 'video/mp4', - 'application/javascript' - ], - 'protocols': [2, 3, 5, 6], - 'maxduration': 60, - 'minduration': 0, - 'startdelay': 0, - 'linearity': 1, - 'api': [2], - 'placement': 1 - } - } -} - -const ORTB2_DEVICE = { - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - ext: {fiftyonedegrees_deviceId: '17595-133085-133468-18092'}, -}; - -const BIDDER_REQUEST = { - 'gdprConsent': { - 'consentString': 'consent_string', - 'gdprApplies': true - }, - 'gppString': 'gpp_string', - 'gppSid': [7], - 'uspConsent': 'consent_string', - 'refererInfo': { - 'page': 'https://www.greatsite.com', - 'ref': 'https://www.somereferrer.com' - }, - 'ortb2': { - 'site': { - 'content': { - 'language': 'en' - } - }, - 'regs': { - 'gpp': 'gpp_string', - 'gpp_sid': [7], - 'coppa': 0 - }, - 'device': ORTB2_DEVICE, - } -}; - -const SERVER_RESPONSE = { - body: { - cid: 'testcid123', - results: [{ - 'ad': '', - 'price': 0.8, - 'creativeId': '12610997325162499419', - 'exp': 30, - 'width': 300, - 'height': 250, - 'advertiserDomains': ['securepubads.g.doubleclick.net'], - 'cookies': [{ - 'src': 'https://sync.com', - 'type': 'iframe' - }, { - 'src': 'https://sync.com', - 'type': 'img' - }] - }] - } -}; - -const VIDEO_SERVER_RESPONSE = { - body: { - 'cid': '635509f7ff6642d368cb9837', - 'results': [{ - 'ad': '', - 'advertiserDomains': ['kueezrtb.com'], - 'exp': 60, - 'width': 545, - 'height': 307, - 'mediaType': 'video', - 'creativeId': '12610997325162499419', - 'price': 2, - 'cookies': [] - }] - } -}; - -const ORTB2_OBJ = { - "device": ORTB2_DEVICE, - "regs": {"coppa": 0, "gpp": "gpp_string", "gpp_sid": [7]}, - "site": {"content": {"language": "en"} - } -}; - -const REQUEST = { - data: { - width: 300, - height: 250, - bidId: '2d52001cabd527' - } -}; - -function getTopWindowQueryParams() { - try { - const parsedUrl = utils.parseUrl(window.top.document.URL, {decodeSearchAsString: true}); - return parsedUrl.search; - } catch (e) { - return ''; - } -} - -describe('KueezRtbBidAdapter', function () { - describe('validtae spec', function () { - it('exists and is a function', function () { - expect(adapter.isBidRequestValid).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.buildRequests).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.interpretResponse).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.getUserSyncs).to.exist.and.to.be.a('function'); - }); - - it('exists and is a string', function () { - expect(adapter.code).to.exist.and.to.be.a('string'); - }); - - it('exists and contains media types', function () { - expect(adapter.supportedMediaTypes).to.exist.and.to.be.an('array').with.length(2); - expect(adapter.supportedMediaTypes).to.contain.members([BANNER, VIDEO]); - }); - }); - - describe('validate bid requests', function () { - it('should require cId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - pId: 'pid' - } - }); - expect(isValid).to.be.false; - }); - - it('should require pId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid' - } - }); - expect(isValid).to.be.false; - }); - - it('should validate correctly', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid', - pId: 'pid' - } - }); - expect(isValid).to.be.true; - }); - }); - - describe('build requests', function () { - let sandbox; - let createFirstPartyDataStub; - before(function () { - getGlobal().bidderSettings = { - kueezrtb: { - storageAllowed: true - } - }; - sandbox = sinon.createSandbox(); - sandbox.stub(Date, 'now').returns(1000); - createFirstPartyDataStub = sandbox.stub(adapter, 'createFirstPartyData').returns({ - pcid: 'pcid', - pcidDate: 1000 - }); - }); - - it('should build video request', function () { - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - config.setConfig({ - bidderTimeout: 3000 - }); - const requests = adapter.buildRequests([VIDEO_BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/635509f7ff6642d368cb9837`, - data: { - adUnitCode: '63550ad1ff6642d368cba59dh5884270560', - bidFloor: 0.1, - bidId: '2d52001cabd527', - bidderVersion: adapter.version, - bidderRequestId: '12a8ae9ada9c13', - cb: 1000, - gdpr: 1, - gdprConsent: 'consent_string', - usPrivacy: 'consent_string', - gppString: 'gpp_string', - gppSid: [7], - prebidVersion: version, - transactionId: '56e184c6-bde9-497b-b9b9-cf47a61381ee', - auctionId: 'auction_id', - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - publisherId: '59ac17c192832d0011283fe3', - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - res: `${window.top.screen.width}x${window.top.screen.height}`, - schain: VIDEO_BID.schain, - iiqpcid: 'pcid', - iiqpcidDate: 1000, - sizes: ['545x307'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - uqs: getTopWindowQueryParams(), - mediaTypes: { - video: { - api: [2], - context: 'instream', - linearity: 1, - maxduration: 60, - mimes: [ - 'video/mp4', - 'application/javascript' - ], - minduration: 0, - placement: 1, - playerSize: [[545, 307]], - protocols: [2, 3, 5, 6], - startdelay: 0 - } - }, - gpid: '', - cat: [], - contentLang: 'en', - contentData: [], - isStorageAllowed: true, - ortb2: ORTB2_OBJ, - pagecat: [], - userData: [], - coppa: 0 - } - }); - }); - - it('should build banner request for each size', function () { - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - config.setConfig({ - bidderTimeout: 3000 - }); - const requests = adapter.buildRequests([BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/59db6b3b4ffaa70004f45cdc`, - data: { - gdprConsent: 'consent_string', - gdpr: 1, - gppString: 'gpp_string', - gppSid: [7], - usPrivacy: 'consent_string', - transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - auctionId: 'auction_id', - bidRequestsCount: 4, - bidderRequestsCount: 3, - iiqpcid: 'pcid', - iiqpcidDate: 1000, - bidderWinsCount: 1, - bidderTimeout: 3000, - bidderRequestId: '1fdb5ff1b6eaa7', - sizes: ['300x250', '300x600'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - cb: 1000, - bidFloor: 0.1, - bidId: '2d52001cabd527', - adUnitCode: 'div-gpt-ad-12345-0', - publisherId: '59ac17c192832d0011283fe3', - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - bidderVersion: adapter.version, - prebidVersion: version, - schain: BID.schain, - res: `${window.top.screen.width}x${window.top.screen.height}`, - mediaTypes: [BANNER], - ortb2Imp: BID.ortb2Imp, - ortb2: ORTB2_OBJ, - gpid: '0123456789', - uqs: getTopWindowQueryParams(), - 'ext.param1': 'loremipsum', - 'ext.param2': 'dolorsitamet', - cat: [], - contentLang: 'en', - contentData: [], - isStorageAllowed: true, - pagecat: [], - userData: [], - coppa: 0 - } - }); - }); - - after(function () { - getGlobal().bidderSettings = {}; - sandbox.restore(); - }); - }); - describe('getUserSyncs', function () { - it('should have valid user sync with iframeEnabled', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.kueezrtb.com/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - - it('should have valid user sync with cid on response', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.kueezrtb.com/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - - it('should have valid user sync with pixelEnabled', function () { - const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE]); - - expect(result).to.deep.equal([{ - 'url': 'https://sync.kueezrtb.com/api/sync/image/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0', - 'type': 'image' - }]); - }); - - it('should have valid user sync with coppa on response', function () { - config.setConfig({ - coppa: 1 - }); - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.kueezrtb.com/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=1' - }]); - }); - - it('should generate url with consent data', function () { - const gdprConsent = { - gdprApplies: true, - consentString: 'consent_string' - }; - const uspConsent = 'usp_string'; - const gppConsent = { - gppString: 'gpp_string', - applicableSections: [7] - } - - const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE], gdprConsent, uspConsent, gppConsent); - - expect(result).to.deep.equal([{ - 'url': 'https://sync.kueezrtb.com/api/sync/image/?cid=testcid123&gdpr=1&gdpr_consent=consent_string&us_privacy=usp_string&coppa=1&gpp=gpp_string&gpp_sid=7', - 'type': 'image' - }]); - }); - }); - - describe('interpret response', function () { - it('should return empty array when there is no response', function () { - const responses = adapter.interpretResponse(null); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no ad', function () { - const responses = adapter.interpretResponse({price: 1, ad: ''}); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no price', function () { - const responses = adapter.interpretResponse({price: null, ad: 'great ad'}); - expect(responses).to.be.empty; - }); - - it('should return an array of interpreted banner responses', function () { - const responses = adapter.interpretResponse(SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 0.8, - width: 300, - height: 250, - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 30, - ad: '', - meta: { - advertiserDomains: ['securepubads.g.doubleclick.net'] - } - }); - }); - - it('should get meta from response metaData', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - serverResponse.body.results[0].metaData = { - advertiserDomains: ['kueezrtb.com'], - agencyName: 'Agency Name', - }; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses[0].meta).to.deep.equal({ - advertiserDomains: ['kueezrtb.com'], - agencyName: 'Agency Name' - }); - }); - - it('should return an array of interpreted video responses', function () { - const responses = adapter.interpretResponse(VIDEO_SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 2, - width: 545, - height: 307, - mediaType: 'video', - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 60, - vastXml: '', - meta: { - advertiserDomains: ['kueezrtb.com'] - } - }); - }); - - it('should take default TTL', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - delete serverResponse.body.results[0].exp; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0].ttl).to.equal(300); - }); - }); - - describe('user id system', function () { - TEST_ID_SYSTEMS.forEach((idSystemProvider) => { - const id = Date.now().toString(); - const bid = utils.deepClone(BID); - - const userId = (function () { - switch (idSystemProvider) { - case 'lipb': - return {lipbid: id}; - case 'id5id': - return {uid: id}; - default: - return id; - } - })(); - - bid.userId = { - [idSystemProvider]: userId - }; - - it(`should include 'uid.${idSystemProvider}' in request params`, function () { - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data[`uid.${idSystemProvider}`]).to.equal(id); - }); - }); - // testing bid.userIdAsEids handling - it("should include user ids from bid.userIdAsEids (length=1)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - }) - it("should include user ids from bid.userIdAsEids (length=2)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - }, - { - "source": "rwdcntrl.net", - "uids": [{"id": "fakeid6f35197d5c", "atype": 1}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - expect(requests[0].data['uid.rwdcntrl.net']).to.equal("fakeid6f35197d5c"); - }) - // testing user.ext.eid handling - it("should include user ids from user.ext.eid (length=1)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - }) - it("should include user ids from user.ext.eid (length=2)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - }, - { - "source": "adserver.org", - "uids": [{"id": "fakeid495ff1"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - expect(requests[0].data['uid.adserver.org']).to.equal("fakeid495ff1"); - }) - }); - - describe('alternate param names extractors', function () { - it('should return undefined when param not supported', function () { - const cid = extractCID({'c_id': '1'}); - const pid = extractPID({'p_id': '1'}); - const subDomain = extractSubDomain({'sub_domain': 'prebid'}); - expect(cid).to.be.undefined; - expect(pid).to.be.undefined; - expect(subDomain).to.be.undefined; - }); - - it('should return value when param supported', function () { - const cid = extractCID({'cID': '1'}); - const pid = extractPID({'Pid': '2'}); - const subDomain = extractSubDomain({'subDOMAIN': 'prebid'}); - expect(cid).to.be.equal('1'); - expect(pid).to.be.equal('2'); - expect(subDomain).to.be.equal('prebid'); - }); - }); - - describe('unique deal id', function () { - before(function () { - getGlobal().bidderSettings = { - kueezrtb: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - const key = 'myKey'; - let uniqueDealId; - beforeEach(() => { - uniqueDealId = getUniqueDealId(storage, key, 0); - }) - - it('should get current unique deal id', function (done) { - // waiting some time so `now` will become past - setTimeout(() => { - const current = getUniqueDealId(storage, key); - expect(current).to.be.equal(uniqueDealId); - done(); - }, 200); - }); - - it('should get new unique deal id on expiration', function (done) { - setTimeout(() => { - const current = getUniqueDealId(storage, key, 100); - expect(current).to.not.be.equal(uniqueDealId); - done(); - }, 200) - }); - }); - - describe('storage utils', function () { - before(function () { - getGlobal().bidderSettings = { - kueezrtb: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - it('should get value from storage with create param', function () { - const now = Date.now(); - const clock = useFakeTimers({ - shouldAdvanceTime: true, - now - }); - setStorageItem(storage, 'myKey', 2020); - const {value, created} = getStorageItem(storage, 'myKey'); - expect(created).to.be.equal(now); - expect(value).to.be.equal(2020); - expect(typeof value).to.be.equal('number'); - expect(typeof created).to.be.equal('number'); - clock.restore(); - }); - - it('should get external stored value', function () { - const value = 'superman' - window.localStorage.setItem('myExternalKey', value); - const item = getStorageItem(storage, 'myExternalKey'); - expect(item).to.be.equal(value); - }); - - it('should parse JSON value', function () { - const data = JSON.stringify({event: 'send'}); - const {event} = tryParseJSON(data); - expect(event).to.be.equal('send'); - }); - - it('should get original value on parse fail', function () { - const value = 21; - const parsed = tryParseJSON(value); - expect(typeof parsed).to.be.equal('number'); - expect(parsed).to.be.equal(value); - }); - }); - - describe('First party data', () => { - before(function () { - getGlobal().bidderSettings = { - kueezrtb: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - storage.removeDataFromLocalStorage('_iiq_fdata'); - }) - - it('should create first party data', function () { - const data = createFirstPartyData(); - expect(data).to.have.property('pcid'); - expect(data).to.have.property('pcidDate'); - }); - - it('should get and set first party data', function () { - storage.removeDataFromLocalStorage('_iiq_fdata'); - - const data = getAndSetFirstPartyData(); - expect(data).to.have.property('pcid'); - expect(data).to.have.property('pcidDate'); - - const stored = storage.getDataFromLocalStorage('_iiq_fdata'); - const parsed = tryParseJSON(stored); - expect(parsed).to.deep.equal(data); - }); - }); -}); diff --git a/test/spec/modules/lane4BidAdapter_spec.js b/test/spec/modules/lane4BidAdapter_spec.js deleted file mode 100644 index 7e1a7bebb..000000000 --- a/test/spec/modules/lane4BidAdapter_spec.js +++ /dev/null @@ -1,322 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/lane4BidAdapter.js'; -import * as utils from '../../../src/utils.js'; - -describe('lane4 adapter', function () { - let bannerRequest, nativeRequest; - let bannerResponse, nativeResponse, invalidBannerResponse, invalidNativeResponse; - - beforeEach(function () { - bannerRequest = [ - { - bidder: 'lane4', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - placement_id: 110044, - bid_floor: 0.5 - } - } - ]; - nativeRequest = [ - { - bidder: 'lane4', - mediaTypes: { - native: { - title: { required: true, len: 100 }, - image: { required: true, sizes: [300, 250] }, - sponsored: { required: false }, - clickUrl: { required: true }, - desc: { required: true }, - icon: { required: false, sizes: [50, 50] }, - cta: { required: false } - } - }, - params: { - placement_id: 5551, - bid_floor: 1 - } - } - ]; - bannerResponse = { - 'body': { - 'id': '006ac3b3-67f0-43bf-a33a-388b2f869fef', - 'seatbid': [{ - 'bid': [{ - 'id': '049d07ed-c07e-4890-9f19-5cf41406a42d', - 'impid': '286e606ac84a09', - 'price': 0.11, - 'adid': '368853', - 'adm': "", - 'adomain': ['google.com'], - 'iurl': 'https://cdn.lane4.com/1_368853_1.png', - 'cid': '468133/368853', - 'crid': '368853', - 'w': 300, - 'h': 250, - 'cat': ['IAB7-19'] - }], - 'seat': 'lane4', - 'group': 0 - }], - 'cur': 'USD', - 'bidid': 'BIDDER_-1' - } - }; - nativeResponse = { - 'body': { - 'id': '453ade66-9113-4944-a674-5bbdcb9808ac', - 'seatbid': [{ - 'bid': [{ - 'id': '652c9a4c-66ea-4579-998b-cefe7b4cfecd', - 'impid': '2c3875bdbb1893', - 'price': 1.1, - 'adid': '368852', - 'adm': '{\"native\":{\"ver\":\"1.1\",\"assets\": [{\"id\":1,\"required\":1,\"title\":{\"text\":\"Integrative Approaches: Merging Traditional and Alternative \"}},{\"id\":2,\"required\":1,\"img\":{\"url\":\"https://cdn.lane4.com/1_368852_0.png\",\"w\":500,\"h\":300,\"type\":\"3\"}},{\"id\":3,\"required\":0,\"data\":{\"value\":\"Diabetes In Control. A free weekly diabetes newsletter for Medical Professionals.\"}},{\"id\":4,\"required\":1,\"data\":{\"value\":\"Integrative Approaches: Merging Traditional and Alternative \"}},{\"id\":6,\"required\":1,\"data\":{\"value\":\"URL\"}}],\"link\":{\"url\":\"https://r.lane4.com/adx-rtb-d/servlet/WebF_AdManager.AdLinkManager?qs=H4sIAAAAAAAAAx2U2QHDIAxDVwKDr3F84P1HqNLPtMSRpSeG9RiPXH+5a474KzO/47YX7UoP50m61fLujlNjb76/8ZiblkimHq5nL/ZRedp3031x1tnk55LjSNN6h9/Zq+qmaLLuWTl74m1ZJKnb+m2OtQm/3L4sb933pM92qMOgjJ41MYmPXKnndRVKs+9bfSEumoZIFpTXuXbCP+WXuzl725E3O+9odi5OJrnBzhwjx9+UnFN3nTNt1/HY5aeljKtvZYpoJHNXr8BWa8ysKQY7ZmNA3DHK2qRwY7+zLu+xm9z5eheJ4Pv2usSptvO3p7JHrnXn0T5yVWdccp9Yz7hhoz2iu2zqsXsGFZ9hh14J6yU4TkJ0BgnOY8tY3tS+n2qsw7xZfKuanSNbAo+9nkJ83i20+FwhfbJeDVOllXsdxmDWauYcSRgS9+yG5qHwUDjAxxA0iZnOjlsnI+y09+ATeTEwbAVGgp0Qu/ceP0kjUvpu1Ty7O9MoegfrmLPxdjUh3mJL+XhARby+Ax8iBckf6BQdn9W+DMlvmlzYLuLlIy7YociFOIvXvEiYYCMboVk8BLHbnw3Zmr5us3xbjtXL67L96F15acJXkM5BOmTaUbBkYGdCI+Et8XmlpbuE3xVQwmxryc2y4wP3ByuuP8GogPZz8OpPaBv8diWWUTrC2nnLhdNUrJRTKc9FepDvwHTDwfbbMCTSb4LhUIFkyFrw/i7GtkPi6NCCai6N47TgNsTnzZWRoVtOSLq7FsLiF29y0Gj0GHVPVYG3QOPS7Swc3UuiFAQZJx3YvpHA2geUgVBASMEL4vcDi2Dw3NPtBSC4EQEvH/uMILu6WyUwraywTeVpoqoHTqOoD84FzReKoWemJy6jyuiBieGlQIe6wY2elTaMOwEUFF5NagzPj6nauc0+aXzQN3Q72hxFAgtfORK60RRAHYZLYymIzSJcXLgRFsqrb1UoD+5Atq7TWojaLTfOyUvH9EeJvZEOilQAXrf/ALoI8ZhABQAA\"},\"imptrackers\":[\"https://i.lane4.com/adx-rtb-d/servlet/WebF_AdManager.ImpCounter?price=${AUCTION_PRICE}&ids=5551,16703,468132,368852,211356,233,13,16704,1&cb=1728409547&ap=5.00000&vd=223.233.85.189,14,8&nm=0.00&GUIDs=[adx_guid],652c9a4c-66ea-4579-998b-cefe7b4cfecd,652c9a4c-66ea-4579-998b-cefe7b4cfecd,999999,-1_&info=2,-1,IN&adx_custom=&adx_custom_ex=~~~-1~~~0&cat=-1&ref=https%3A%2F%2Fqa-jboss.audiencelogy.com%2Ftn_native_prod.html\",\"https://i.lane4.com/adx-rtb-d/servlet/WebF_AdManager.ImpTracker?price=${AUCTION_PRICE}&ids=5551,16703,468132,368852,211356,233,13,16704,1&cb=1728409547&ap=5.00000&vd=223.233.85.189,14,8&nm=0.00&GUIDs=[adx_guid],652c9a4c-66ea-4579-998b-cefe7b4cfecd,652c9a4c-66ea-4579-998b-cefe7b4cfecd,999999,-1_&info=2,-1,IN&adx_custom=&adx_custom_ex=~~~-1~~~0&cat=-1&ref=\",\"https://rtb-east.lane4.com:9001/beacon?uid=44636f6605b06ec6d4389d6efb7e5054&cc=468132&fccap=5&nid=1\"]}}', - 'adomain': ['www.diabetesincontrol.com'], - 'iurl': 'https://cdn.lane4.com/1_368852_0.png', - 'cid': '468132/368852', - 'crid': '368852', - 'cat': ['IAB7'] - }], - 'seat': 'lane4', - 'group': 0 - }], - 'cur': 'USD', - 'bidid': 'BIDDER_-1' - } - }; - invalidBannerResponse = { - 'body': { - 'id': '006ac3b3-67f0-43bf-a33a-388b2f869fef', - 'seatbid': [{ - 'bid': [{ - 'id': '049d07ed-c07e-4890-9f19-5cf41406a42d', - 'impid': '286e606ac84a09', - 'price': 0.11, - 'adid': '368853', - 'adm': 'invalid response', - 'adomain': ['google.com'], - 'iurl': 'https://cdn.lane4.com/1_368853_1.png', - 'cid': '468133/368853', - 'crid': '368853', - 'w': 300, - 'h': 250, - 'cat': ['IAB7-19'] - }], - 'seat': 'lane4', - 'group': 0 - }], - 'cur': 'USD', - 'bidid': 'BIDDER_-1' - } - }; - invalidNativeResponse = { - 'body': { - 'id': '453ade66-9113-4944-a674-5bbdcb9808ac', - 'seatbid': [{ - 'bid': [{ - 'id': '652c9a4c-66ea-4579-998b-cefe7b4cfecd', - 'impid': '2c3875bdbb1893', - 'price': 1.1, - 'adid': '368852', - 'adm': 'invalid response', - 'adomain': ['www.diabetesincontrol.com'], - 'iurl': 'https://cdn.lane4.com/1_368852_0.png', - 'cid': '468132/368852', - 'crid': '368852', - 'cat': ['IAB7'] - }], - 'seat': 'lane4', - 'group': 0 - }], - 'cur': 'USD', - 'bidid': 'BIDDER_-1' - } - }; - }); - - describe('validations', function () { - it('isBidValid : placement_id is passed', function () { - const bid = { - bidder: 'lane4', - params: { - placement_id: 110044 - } - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equals(true); - }); - it('isBidValid : placement_id is not passed', function () { - const bid = { - bidder: 'lane4', - params: { - width: 300, - height: 250, - domain: '', - bid_floor: 0.5 - } - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equals(false); - }); - }); - describe('Validate Banner Request', function () { - it('Immutable bid request validate', function () { - const _Request = utils.deepClone(bannerRequest); - const bidRequest = spec.buildRequests(bannerRequest); - expect(bannerRequest).to.deep.equal(_Request); - }); - it('Validate bidder connection', function () { - const _Request = spec.buildRequests(bannerRequest); - expect(_Request.url).to.equal('https://rtb.lane4.io/hb'); - expect(_Request.method).to.equal('POST'); - expect(_Request.options.contentType).to.equal('application/json'); - }); - it('Validate bid request : Impression', function () { - const _Request = spec.buildRequests(bannerRequest); - const data = JSON.parse(_Request.data); - // expect(data.at).to.equal(1); // auction type - expect(data[0].imp[0].id).to.equal(bannerRequest[0].bidId); - expect(data[0].placementId).to.equal(110044); - }); - it('Validate bid request : ad size', function () { - const _Request = spec.buildRequests(bannerRequest); - const data = JSON.parse(_Request.data); - expect(data[0].imp[0].banner).to.be.a('object'); - expect(data[0].imp[0].banner.w).to.equal(300); - expect(data[0].imp[0].banner.h).to.equal(250); - }); - it('Validate bid request : user object', function () { - const _Request = spec.buildRequests(bannerRequest); - const data = JSON.parse(_Request.data); - expect(data[0].user).to.be.a('object'); - expect(data[0].user.id).to.be.a('string'); - }); - it('Validate bid request : CCPA Check', function () { - const bidRequest = { - uspConsent: '1NYN' - }; - const _Request = spec.buildRequests(bannerRequest, bidRequest); - const data = JSON.parse(_Request.data); - expect(data[0].regs.ext.us_privacy).to.equal('1NYN'); - // let _bidRequest = {}; - // let _Request1 = spec.buildRequests(request, _bidRequest); - // let data1 = JSON.parse(_Request1.data); - // expect(data1.regs).to.equal(undefined); - }); - }); - describe('Validate banner response ', function () { - it('Validate bid response : valid bid response', function () { - const _Request = spec.buildRequests(bannerRequest); - const bResponse = spec.interpretResponse(bannerResponse, _Request); - expect(bResponse).to.be.an('array').with.length.above(0); - expect(bResponse[0].requestId).to.equal(bannerResponse.body.seatbid[0].bid[0].impid); - expect(bResponse[0].width).to.equal(bannerResponse.body.seatbid[0].bid[0].w); - expect(bResponse[0].height).to.equal(bannerResponse.body.seatbid[0].bid[0].h); - expect(bResponse[0].currency).to.equal('USD'); - expect(bResponse[0].netRevenue).to.equal(false); - expect(bResponse[0].mediaType).to.equal('banner'); - expect(bResponse[0].meta.advertiserDomains).to.deep.equal(['google.com']); - expect(bResponse[0].ttl).to.equal(300); - expect(bResponse[0].creativeId).to.equal(bannerResponse.body.seatbid[0].bid[0].crid); - expect(bResponse[0].dealId).to.equal(bannerResponse.body.seatbid[0].bid[0].dealId); - }); - it('Invalid bid response check ', function () { - const bRequest = spec.buildRequests(bannerRequest); - const response = spec.interpretResponse(invalidBannerResponse, bRequest); - expect(response[0].ad).to.equal('invalid response'); - }); - }); - describe('Validate Native Request', function () { - it('Immutable bid request validate', function () { - const _Request = utils.deepClone(nativeRequest); - const bidRequest = spec.buildRequests(nativeRequest); - expect(nativeRequest).to.deep.equal(_Request); - }); - it('Validate bidder connection', function () { - const _Request = spec.buildRequests(nativeRequest); - expect(_Request.url).to.equal('https://rtb.lane4.io/hb'); - expect(_Request.method).to.equal('POST'); - expect(_Request.options.contentType).to.equal('application/json'); - }); - it('Validate bid request : Impression', function () { - const _Request = spec.buildRequests(nativeRequest); - const data = JSON.parse(_Request.data); - // expect(data.at).to.equal(1); // auction type - expect(data[0].imp[0].id).to.equal(nativeRequest[0].bidId); - expect(data[0].placementId).to.equal(5551); - }); - it('Validate bid request : user object', function () { - const _Request = spec.buildRequests(nativeRequest); - const data = JSON.parse(_Request.data); - expect(data[0].user).to.be.a('object'); - expect(data[0].user.id).to.be.a('string'); - }); - it('Validate bid request : CCPA Check', function () { - const bidRequest = { - uspConsent: '1NYN' - }; - const _Request = spec.buildRequests(nativeRequest, bidRequest); - const data = JSON.parse(_Request.data); - expect(data[0].regs.ext.us_privacy).to.equal('1NYN'); - // let _bidRequest = {}; - // let _Request1 = spec.buildRequests(request, _bidRequest); - // let data1 = JSON.parse(_Request1.data); - // expect(data1.regs).to.equal(undefined); - }); - }); - describe('Validate native response ', function () { - it('Validate bid response : valid bid response', function () { - const _Request = spec.buildRequests(nativeRequest); - const bResponse = spec.interpretResponse(nativeResponse, _Request); - expect(bResponse).to.be.an('array').with.length.above(0); - expect(bResponse[0].requestId).to.equal(nativeResponse.body.seatbid[0].bid[0].impid); - // expect(bResponse[0].width).to.equal(bannerResponse.body.seatbid[0].bid[0].w); - // expect(bResponse[0].height).to.equal(bannerResponse.body.seatbid[0].bid[0].h); - expect(bResponse[0].currency).to.equal('USD'); - expect(bResponse[0].netRevenue).to.equal(false); - expect(bResponse[0].mediaType).to.equal('native'); - expect(bResponse[0].native.clickUrl).to.be.a('string').and.not.be.empty; - expect(bResponse[0].native.impressionTrackers).to.be.an('array').with.length.above(0); - expect(bResponse[0].native.title).to.be.a('string').and.not.be.empty; - expect(bResponse[0].native.image.url).to.be.a('string').and.not.be.empty; - expect(bResponse[0].meta.advertiserDomains).to.deep.equal(['www.diabetesincontrol.com']); - expect(bResponse[0].ttl).to.equal(300); - expect(bResponse[0].creativeId).to.equal(nativeResponse.body.seatbid[0].bid[0].crid); - expect(bResponse[0].dealId).to.equal(nativeResponse.body.seatbid[0].bid[0].dealId); - }); - }); - describe('GPP and coppa', function () { - it('Request params check with GPP Consent', function () { - const bidderReq = { gppConsent: { gppString: 'gpp-string-test', applicableSections: [5] } }; - const _Request = spec.buildRequests(bannerRequest, bidderReq); - const data = JSON.parse(_Request.data); - expect(data[0].regs.gpp).to.equal('gpp-string-test'); - expect(data[0].regs.gpp_sid[0]).to.equal(5); - }); - it('Request params check with GPP Consent read from ortb2', function () { - const bidderReq = { - ortb2: { - regs: { - gpp: 'gpp-test-string', - gpp_sid: [5] - } - } - }; - const _Request = spec.buildRequests(bannerRequest, bidderReq); - const data = JSON.parse(_Request.data); - expect(data[0].regs.gpp).to.equal('gpp-test-string'); - expect(data[0].regs.gpp_sid[0]).to.equal(5); - }); - it(' Bid request should have coppa flag if its true', () => { - const bidderReq = { ortb2: { regs: { coppa: 1 } } }; - const _Request = spec.buildRequests(bannerRequest, bidderReq); - const data = JSON.parse(_Request.data); - expect(data[0].regs.coppa).to.equal(1); - }); - }); -}); diff --git a/test/spec/modules/lassoBidAdapter_spec.js b/test/spec/modules/lassoBidAdapter_spec.js deleted file mode 100644 index 2198a837f..000000000 --- a/test/spec/modules/lassoBidAdapter_spec.js +++ /dev/null @@ -1,419 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/lassoBidAdapter.js'; -import { server } from '../../mocks/xhr.js'; - -const ENDPOINT_URL = 'https://trc.lhmos.com/prebid'; -const GET_IUD_URL = 'https://secure.adnxs.com/getuid?'; - -const bid = { - bidder: 'lasso', - params: { - adUnitId: 123456 - }, - auctionStart: Date.now(), - adUnitCode: 'adunit-code', - auctionId: 'cfa6f46d-4584-46e1-9c00-54769abb51e3', - bidderRequestId: 'a123b456c789d', - bidId: '123a456b789', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - sizes: [[300, 250]], - src: 'client', - transactionId: '26740296-0111-4b7a-80df-7196823026f4' -}; - -const bidderRequest = { - auctionId: 'cfa6f46d-4584-46e1-9c00-54769abb51e3', - auctionStart: Date.now(), - start: Date.now(), - biddeCode: 'lasso', - bidderRequestId: 'a123b456c789d', - bids: [bid], - timeout: 10000 -}; - -describe('lassoBidAdapter', function () { - describe('All needed functions are available', function() { - it(`isBidRequestValid is present and type function`, function () { - expect(spec.isBidRequestValid).to.exist.and.to.be.a('function') - }); - - it(`buildRequests is present and type function`, function () { - expect(spec.buildRequests).to.exist.and.to.be.a('function') - }); - - it(`interpretResponse is present and type function`, function () { - expect(spec.interpretResponse).to.exist.and.to.be.a('function') - }); - - it(`onTimeout is present and type function`, function () { - expect(spec.onTimeout).to.exist.and.to.be.a('function') - }); - - it(`onBidWon is present and type function`, function () { - expect(spec.onBidWon).to.exist.and.to.be.a('function') - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should return true when there are extra params', function () { - const invalidBid = Object.assign({}, bid, { - params: { - adUnitId: 123456, - zone: 1, - publisher: 'test' - } - }) - expect(spec.isBidRequestValid(invalidBid)).to.equal(true); - }); - it('should return false when there are no params', function () { - const invalidBid = { ...bid }; - delete invalidBid.params; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests with standard flow', function () { - let validBidRequests, bidRequest; - before(() => { - validBidRequests = spec.buildRequests([bid], bidderRequest); - expect(validBidRequests).to.be.an('array').that.is.not.empty; - bidRequest = validBidRequests[0]; - }) - - it('Returns valid bidRequest', function () { - expect(bidRequest).to.exist; - expect(bidRequest.method).to.exist; - expect(bidRequest.url).to.exist; - expect(bidRequest.data).to.exist; - }); - - it('Returns GET method', function() { - expect(bidRequest.method).to.exist; - expect(bidRequest.method).to.equal('GET'); - }); - - it('should send request to get uid and trc via get request', () => { - expect(bidRequest.data.test).to.equal(false) - expect(bidRequest.method).to.equal('GET'); - expect(bidRequest.url).to.equal(GET_IUD_URL + ENDPOINT_URL + '/request'); - }); - }); - - describe('buildRequests with dgid', function () { - let validBidRequests, bidRequest; - before(() => { - const updateBidParams = Object.assign({}, bid, { - params: { - adUnitId: 123456, - dgid: '123' - } - }); - validBidRequests = spec.buildRequests([updateBidParams], bidderRequest); - expect(validBidRequests).to.be.an('array').that.is.not.empty; - bidRequest = validBidRequests[0]; - }) - - it('Returns valid bidRequest', function () { - expect(bidRequest).to.exist; - expect(bidRequest.method).to.exist; - expect(bidRequest.url).to.exist; - expect(bidRequest.data).to.exist; - }); - - it('Returns GET method', function() { - expect(bidRequest.method).to.exist; - expect(bidRequest.method).to.equal('GET'); - }); - - it('should send request to trc via get request with dgid', () => { - expect(bidRequest.data.test).to.equal(false) - expect(bidRequest.method).to.equal('GET'); - expect(bidRequest.url).to.equal(ENDPOINT_URL + '/request'); - }); - }); - - describe('buildRequests with aimOnly', function () { - let validBidRequests, bidRequest; - before(() => { - const updateBidParams = Object.assign({}, bid, { - params: { - adUnitId: 123456, - aimOnly: true - } - }); - validBidRequests = spec.buildRequests([updateBidParams], bidderRequest); - expect(validBidRequests).to.be.an('array').that.is.not.empty; - bidRequest = validBidRequests[0]; - }) - - it('Returns valid bidRequest', function () { - expect(bidRequest).to.exist; - expect(bidRequest.method).to.exist; - expect(bidRequest.url).to.exist; - expect(bidRequest.data).to.exist; - }); - - it('Returns GET method', function() { - expect(bidRequest.method).to.exist; - expect(bidRequest.method).to.equal('GET'); - }); - - it('should send request to trc via get request with aimOnly true', () => { - expect(bidRequest.data.test).to.equal(false) - expect(bidRequest.method).to.equal('GET'); - expect(bidRequest.url).to.equal(ENDPOINT_URL + '/request'); - }); - }); - - describe('buildRequests with test dk', function () { - let validBidRequests, bidRequest; - before(() => { - const updateBidParams = Object.assign({}, bid, { - params: { - adUnitId: 123456, - testDk: '123' - } - }); - validBidRequests = spec.buildRequests([updateBidParams], bidderRequest); - expect(validBidRequests).to.be.an('array').that.is.not.empty; - bidRequest = validBidRequests[0]; - }) - - it('Returns valid bidRequest', function () { - expect(bidRequest).to.exist; - expect(bidRequest.method).to.exist; - expect(bidRequest.url).to.exist; - expect(bidRequest.data).to.exist; - }); - - it('Returns GET method', function() { - expect(bidRequest.method).to.exist; - expect(bidRequest.method).to.equal('GET'); - }); - - it('should send request to trc via get request with testDk and test param', () => { - expect(bidRequest.data.test).to.equal(true) - expect(bidRequest.data.testDk).to.equal('123') - expect(bidRequest.method).to.equal('GET'); - expect(bidRequest.url).to.equal(ENDPOINT_URL + '/request'); - }); - }); - - describe('buildRequests with npi', function () { - let validBidRequests, bidRequest; - before(() => { - const updateBidParams = Object.assign({}, bid, { - params: { - adUnitId: 123456, - npi: '123' - } - }); - validBidRequests = spec.buildRequests([updateBidParams], bidderRequest); - expect(validBidRequests).to.be.an('array').that.is.not.empty; - bidRequest = validBidRequests[0]; - }) - - it('Returns valid bidRequest', function () { - expect(bidRequest).to.exist; - expect(bidRequest.method).to.exist; - expect(bidRequest.url).to.exist; - expect(bidRequest.data).to.exist; - }); - - it('Returns GET method', function() { - expect(bidRequest.method).to.exist; - expect(bidRequest.method).to.equal('GET'); - }); - - it('should send request to trc via get request with npi', () => { - expect(bidRequest.data.test).to.equal(false) - expect(bidRequest.method).to.equal('GET'); - expect(bidRequest.url).to.equal(ENDPOINT_URL + '/request'); - }); - }); - - describe('buildRequests with test npi', function () { - let validBidRequests, bidRequest; - before(() => { - const updateBidParams = Object.assign({}, bid, { - params: { - adUnitId: 123456, - testNPI: '123' - } - }); - validBidRequests = spec.buildRequests([updateBidParams], bidderRequest); - expect(validBidRequests).to.be.an('array').that.is.not.empty; - bidRequest = validBidRequests[0]; - }) - - it('Returns valid bidRequest', function () { - expect(bidRequest).to.exist; - expect(bidRequest.method).to.exist; - expect(bidRequest.url).to.exist; - expect(bidRequest.data).to.exist; - }); - - it('Returns GET method', function() { - expect(bidRequest.method).to.exist; - expect(bidRequest.method).to.equal('GET'); - }); - - it('should send request to trc via get request with npi and test param', () => { - expect(bidRequest.data.test).to.equal(true) - expect(bidRequest.method).to.equal('GET'); - expect(bidRequest.url).to.equal(ENDPOINT_URL + '/request'); - }); - }); - - describe('buildRequests with test dgid', function () { - let validBidRequests, bidRequest; - before(() => { - const updateBidParams = Object.assign({}, bid, { - params: { - adUnitId: 123456, - testDGID: '123' - } - }); - validBidRequests = spec.buildRequests([updateBidParams], bidderRequest); - expect(validBidRequests).to.be.an('array').that.is.not.empty; - bidRequest = validBidRequests[0]; - }) - - it('Returns valid bidRequest', function () { - expect(bidRequest).to.exist; - expect(bidRequest.method).to.exist; - expect(bidRequest.url).to.exist; - expect(bidRequest.data).to.exist; - }); - - it('Returns GET method', function() { - expect(bidRequest.method).to.exist; - expect(bidRequest.method).to.equal('GET'); - }); - - it('should send request to trc via get request with dgid and test param', () => { - expect(bidRequest.data.test).to.equal(true) - expect(bidRequest.method).to.equal('GET'); - expect(bidRequest.url).to.equal(ENDPOINT_URL + '/request'); - }); - }); - - describe('buildRequests with npi hash', function () { - let validBidRequests, bidRequest; - before(() => { - const updateBidParams = Object.assign({}, bid, { - params: { - adUnitId: 123456, - npiHash: '123' - } - }); - validBidRequests = spec.buildRequests([updateBidParams], bidderRequest); - expect(validBidRequests).to.be.an('array').that.is.not.empty; - bidRequest = validBidRequests[0]; - }) - - it('Returns valid bidRequest', function () { - expect(bidRequest).to.exist; - expect(bidRequest.method).to.exist; - expect(bidRequest.url).to.exist; - expect(bidRequest.data).to.exist; - }); - - it('Returns GET method', function() { - expect(bidRequest.method).to.exist; - expect(bidRequest.method).to.equal('GET'); - }); - - it('should send request to trc via get request with npi', () => { - expect(bidRequest.data.test).to.equal(false) - expect(bidRequest.method).to.equal('GET'); - expect(bidRequest.url).to.equal(ENDPOINT_URL + '/request'); - }); - }); - - describe('interpretResponse', function () { - const serverResponse = { - body: { - bidid: '123456789', - id: '33302780340222111', - bid: { - price: 1, - w: 728, - h: 90, - crid: 123456, - ad: '', - mediaType: 'banner' - }, - meta: { - cat: ['1', '2', '3', '4'], - advertiserDomains: ['lassomarketing.io'], - advertiserName: 'Lasso' - }, - cur: 'USD', - netRevenue: false, - ttl: 300, - } - }; - - it('should get the correct bid response', function () { - const expectedResponse = { - requestId: '123456789', - bidId: '123456789', - cpm: 1, - currency: 'USD', - width: 728, - height: 90, - creativeId: 123456, - netRevenue: false, - ttl: 300, - ad: '', - mediaType: 'banner', - meta: { - secondaryCatIds: ['1', '2', '3', '4'], - advertiserDomains: ['lassomarketing.io'], - advertiserName: 'Lasso', - mediaType: 'banner' - } - }; - const result = spec.interpretResponse(serverResponse); - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse)); - }); - }); - - describe('onTimeout', () => { - it('should send timeout', () => { - const timeoutData = { - bidder: 'lasso', - auctionId: 'cfa6f46d-4584-46e1-9c00-54769abb51e3', - dUnitCode: 'adunit-code', - bidId: '123a456b789', - params: { - adUnitId: 123456, - }, - timeout: 3000 - }; - spec.onTimeout(timeoutData); - - expect(server.requests[0].method).to.equal('POST'); - expect(server.requests[0].url).to.equal(ENDPOINT_URL + '/timeout'); - expect(JSON.parse(server.requests[0].requestBody)).to.deep.equal(timeoutData); - }); - }); - - describe('onBidWon', () => { - it('should send bid won request', () => { - spec.onBidWon(bid); - - expect(server.requests[0].method).to.equal('POST'); - expect(server.requests[0].url).to.equal(ENDPOINT_URL + '/won'); - expect(JSON.parse(server.requests[0].requestBody)).to.deep.equal(bid); - }); - }); -}); diff --git a/test/spec/modules/lemmaDigitalBidAdapter_spec.js b/test/spec/modules/lemmaDigitalBidAdapter_spec.js deleted file mode 100644 index 2e6e4c43a..000000000 --- a/test/spec/modules/lemmaDigitalBidAdapter_spec.js +++ /dev/null @@ -1,623 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/lemmaDigitalBidAdapter.js'; -import * as utils from 'src/utils.js'; -import { config } from 'src/config.js'; -const constants = require('src/constants.js'); - -describe('lemmaDigitalBidAdapter', function () { - let bidRequests; - let videoBidRequests; - let bidResponses; - let videoBidResponse; - let schainConfig; - beforeEach(function () { - schainConfig = { - 'complete': 0, - 'nodes': [ - { - 'asi': 'mobupps.com', - 'sid': 'c74d97b01eae257e44aa9d5bade97baf5149', - 'rid': '79c25703ad5935b0b23b66d210dad1f3', - 'hp': 1 - }, - { - 'asi': 'lemmatechnologies.com', - 'sid': '975', - 'rid': 'a455157a-a1fb-11ed-a0e4-d08e79f7ace0', - 'hp': 1 - } - ] - }; - bidRequests = [{ - bidder: 'lemmadigital', - bidId: '22bddb28db77d', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ], - } - }, - params: { - pubId: 1001, - adunitId: 1, - currency: 'AUD', - bidFloor: 1.3, - geo: { - lat: '12.3', - lon: '23.7', - }, - banner: { - w: 300, - h: 250, - }, - tmax: 300, - bcat: ['IAB-26'] - }, - sizes: [ - [300, 250], - [300, 600] - ], - ortb2: { source: { ext: { schain: schainConfig } } } - }]; - videoBidRequests = [{ - code: 'video1', - mediaTypes: { - video: { - playerSize: [[640, 480]], - context: 'instream' - } - }, - bidder: 'lemmadigital', - bidId: '22bddb28db77d', - params: { - pubId: 1001, - adunitId: 1, - bidFloor: 1.3, - tmax: 300, - bcat: ['IAB-26'], - video: { - mimes: ['video/mp4', 'video/x-flv'], - skippable: true, - minduration: 5, - maxduration: 30 - } - }, - ortb2: { source: { ext: { schain: schainConfig } } } - }]; - bidResponses = { - 'body': { - 'id': '93D3BAD6-E2E2-49FB-9D89-920B1761C865', - 'seatbid': [{ - 'bid': [{ - 'id': '74858439-49D7-4169-BA5D-44A046315B2F', - 'impid': '22bddb28db77d', - 'price': 1.3, - 'adm': '

lemma"Connecting Advertisers and Publishers directly"

', - 'adomain': ['amazon.com'], - 'iurl': 'https://thetradedesk-t-general.s3.amazonaws.com/AdvertiserLogos/vgl908z.png', - 'cid': '22918', - 'crid': 'v55jutrh', - 'dealid': 'ASEA-MS-KLY-TTD-DESKTOP-ID-VID-6S-030420', - 'h': 250, - 'w': 300, - 'ext': {} - }] - }] - } - }; - videoBidResponse = { - 'body': { - 'id': '93D3BAD6-E2E2-49FB-9D89-920B1761C865', - 'seatbid': [{ - 'bid': [{ - 'id': '74858439-49D7-4169-BA5D-44A046315B2F', - 'impid': '22bddb28db77d', - 'price': 1.3, - 'adm': 'Acudeo CompatibleVAST 2.0 Instream Test 1VAST 2.0 Instream Test 1', - 'adomain': ['amazon.com'], - 'iurl': 'https://thetradedesk-t-general.s3.amazonaws.com/AdvertiserLogos/vgl908z.png', - 'cid': '22918', - 'crid': 'v55jutrh', - 'dealid': 'ASEA-MS-KLY-TTD-DESKTOP-ID-VID-6S-030420', - 'h': 250, - 'w': 300, - 'ext': {} - }] - }] - } - }; - }); - describe('implementation', function () { - describe('Bid validations', function () { - it('valid bid case', function () { - const validBid = { - bidder: 'lemmadigital', - params: { - pubId: 1001, - adunitId: 1 - } - }; - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(true); - }); - it('invalid bid case', function () { - const isValid = spec.isBidRequestValid(); - expect(isValid).to.equal(false); - }); - it('invalid bid case: pubId not passed', function () { - const validBid = { - bidder: 'lemmadigital', - params: { - adunitId: 1 - } - }; - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(false); - }); - it('invalid bid case: pubId is not number', function () { - const validBid = { - bidder: 'lemmadigital', - params: { - pubId: '301', - adunitId: 1 - } - }; - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(false); - }); - it('invalid bid case: adunitId is not passed', function () { - const validBid = { - bidder: 'lemmadigital', - params: { - pubId: 1001 - } - }; - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(false); - }); - it('invalid bid case: video bid request mimes is not passed', function () { - let validBid = { - bidder: 'lemmadigital', - params: { - pubId: 1001, - adunitId: 1, - video: { - skippable: true, - minduration: 5, - maxduration: 30 - } - } - }; - let isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(false); - validBid.params.video.mimes = []; - isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(false); - }); - }); - describe('Request formation', function () { - it('bidRequest check empty', function () { - const bidRequests = []; - const request = spec.buildRequests(bidRequests); - expect(request).to.equal(undefined); - }); - it('buildRequests function should not modify original bidRequests object', function () { - const originalBidRequests = utils.deepClone(bidRequests); - const request = spec.buildRequests(bidRequests); - expect(bidRequests).to.deep.equal(originalBidRequests); - }); - it('bidRequest imp array check empty', function () { - const request = spec.buildRequests(bidRequests); - const data = JSON.parse(request.data); - data.imp = []; - expect(data.imp.length).to.equal(0); - }); - it('Endpoint checking', function () { - const request = spec.buildRequests(bidRequests); - expect(request.url).to.equal('https://pbidj.lemmamedia.com/lemma/servad?pid=1001&aid=1'); - expect(request.method).to.equal('POST'); - }); - it('Request params check', function () { - const request = spec.buildRequests(bidRequests); - const data = JSON.parse(request.data); - expect(data.site.domain).to.be.a('string'); // domain should be set - expect(data.site.publisher.id).to.equal(bidRequests[0].params.pubId.toString()); // publisher Id - expect(data.imp[0].tagid).to.equal('1'); // tagid - expect(data.imp[0].bidfloorcur).to.equal(bidRequests[0].params.currency); - expect(data.imp[0].bidfloor).to.equal(bidRequests[0].params.bidFloor); - expect(data.source.ext.schain).to.deep.equal(bidRequests[0].ortb2.source.ext.schain); - }); - - it('Set sizes from mediaTypes object', function () { - const newBannerRequest = utils.deepClone(bidRequests); - delete newBannerRequest[0].sizes; - const request = spec.buildRequests(newBannerRequest); - const data = JSON.parse(request.data); - expect(data.sizes).to.equal(undefined); - }); - it('Check request banner object present', function () { - const newBannerRequest = utils.deepClone(bidRequests); - const request = spec.buildRequests(newBannerRequest); - const data = JSON.parse(request.data); - expect(data.banner).to.deep.equal(undefined); - }); - it('Check device, source object not present', function () { - const newBannerRequest = utils.deepClone(bidRequests); - delete newBannerRequest[0].ortb2; - const request = spec.buildRequests(newBannerRequest); - const data = JSON.parse(request.data); - delete data.device; - delete data.source; - expect(data.source).to.equal(undefined); - expect(data.device).to.equal(undefined); - }); - it('Set content from config, set site.content', function () { - const sandbox = sinon.createSandbox(); - const content = { - 'id': 'alpha-numeric-id' - }; - sandbox.stub(config, 'getConfig').callsFake((key) => { - var config = { - content: content - }; - return config[key]; - }); - const request = spec.buildRequests(bidRequests); - const data = JSON.parse(request.data); - expect(data.site.content).to.deep.equal(content); - sandbox.restore(); - }); - it('Set content from config, set app.content', function () { - const bidRequest = [{ - bidder: 'lemmadigital', - params: { - pubId: 1001, - adunitId: 1, - video: { - skippable: true, - minduration: 5, - maxduration: 30 - }, - app: { - id: 'e0977d04e6bafece57b4b6e93314f10a', - name: 'AMC', - bundle: 'com.roku.amc', - storeurl: 'https://channelstore.roku.com/details/12716/amc', - cat: [ - 'IAB-26' - ], - publisher: { - 'id': '975' - } - }, - } - }]; - const sandbox = sinon.createSandbox(); - const content = { - 'id': 'alpha-numeric-id' - }; - sandbox.stub(config, 'getConfig').callsFake((key) => { - var config = { - content: content - }; - return config[key]; - }); - const request = spec.buildRequests(bidRequest); - const data = JSON.parse(request.data); - expect(data.app.content).to.deep.equal(content); - sandbox.restore(); - }); - it('Set tmax from requestBids method', function () { - const request = spec.buildRequests(bidRequests); - const data = JSON.parse(request.data); - expect(data.tmax).to.deep.equal(300); - }); - it('Request params check without mediaTypes object', function () { - const bidRequests = [{ - bidder: 'lemmadigital', - params: { - pubId: 1001, - adunitId: 1, - currency: 'AUD' - }, - sizes: [ - [300, 250], - [300, 600] - ] - }]; - const request = spec.buildRequests(bidRequests); - const data = JSON.parse(request.data); - expect(data.imp[0].banner.w).to.equal(300); // width - expect(data.imp[0].banner.h).to.equal(250); // height - expect(data.imp[0].banner.format).exist.and.to.be.an('array'); - expect(data.imp[0].banner.format[0]).exist.and.to.be.an('object'); - expect(data.imp[0].banner.format[0].w).to.equal(300); // width - expect(data.imp[0].banner.format[0].h).to.equal(600); // height - }); - it('Request params check: without tagId', function () { - delete bidRequests[0].params.adunitId; - const request = spec.buildRequests(bidRequests); - const data = JSON.parse(request.data); - expect(data.site.domain).to.be.a('string'); // domain should be set - expect(data.site.publisher.id).to.equal(bidRequests[0].params.pubId.toString()); // publisher Id - expect(data.imp[0].tagid).to.equal(undefined); // tagid - expect(data.imp[0].bidfloorcur).to.equal(bidRequests[0].params.currency); - expect(data.imp[0].bidfloor).to.equal(bidRequests[0].params.bidFloor); - }); - it('Request params multi size format object check', function () { - const bidRequests = [{ - bidder: 'lemmadigital', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ], - } - }, - params: { - pubId: 1001, - adunitId: 1, - currency: 'AUD' - }, - sizes: [ - [300, 250], - [300, 600] - ] - }]; - /* case 1 - size passed in adslot */ - let request = spec.buildRequests(bidRequests); - let data = JSON.parse(request.data); - expect(data.imp[0].banner.w).to.equal(300); // width - expect(data.imp[0].banner.h).to.equal(250); // height - /* case 2 - size passed in adslot as well as in sizes array */ - bidRequests[0].sizes = [ - [300, 600], - [300, 250] - ]; - bidRequests[0].mediaTypes = { - banner: { - sizes: [ - [300, 600], - [300, 250] - ] - } - }; - request = spec.buildRequests(bidRequests); - data = JSON.parse(request.data); - expect(data.imp[0].banner.w).to.equal(300); // width - expect(data.imp[0].banner.h).to.equal(600); // height - /* case 3 - size passed in sizes but not in adslot */ - bidRequests[0].params.adunitId = 1; - bidRequests[0].sizes = [ - [300, 250], - [300, 600] - ]; - bidRequests[0].mediaTypes = { - banner: { - sizes: [ - [300, 250], - [300, 600] - ] - } - }; - request = spec.buildRequests(bidRequests); - data = JSON.parse(request.data); - expect(data.imp[0].banner.w).to.equal(300); // width - expect(data.imp[0].banner.h).to.equal(250); // height - expect(data.imp[0].banner.format).exist.and.to.be.an('array'); - expect(data.imp[0].banner.format[0]).exist.and.to.be.an('object'); - expect(data.imp[0].banner.format[0].w).to.equal(300); // width - expect(data.imp[0].banner.format[0].h).to.equal(250); // height - }); - it('Request params currency check', function () { - const bidRequest = [{ - bidder: 'lemmadigital', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ], - } - }, - params: { - pubId: 1001, - adunitId: 1, - currency: 'AUD' - }, - sizes: [ - [300, 250], - [300, 600] - ] - }]; - /* case 1 - - currency specified in adunits - output: imp[0] use currency specified in bidRequests[0].params.currency - */ - let request = spec.buildRequests(bidRequest); - let data = JSON.parse(request.data); - expect(data.imp[0].bidfloorcur).to.equal(bidRequests[0].params.currency); - /* case 2 - - currency specified in adunit - output: imp[0] use default currency - USD - */ - delete bidRequest[0].params.currency; - request = spec.buildRequests(bidRequest); - data = JSON.parse(request.data); - expect(data.imp[0].bidfloorcur).to.equal('USD'); - }); - it('Request params check for video ad', function () { - const request = spec.buildRequests(videoBidRequests); - const data = JSON.parse(request.data); - expect(data.imp[0].video).to.exist; - expect(data.imp[0].tagid).to.equal('1'); - expect(data.imp[0]['video']['mimes']).to.exist.and.to.be.an('array'); - expect(data.imp[0]['video']['mimes'][0]).to.equal(videoBidRequests[0].params.video['mimes'][0]); - expect(data.imp[0]['video']['mimes'][1]).to.equal(videoBidRequests[0].params.video['mimes'][1]); - expect(data.imp[0]['video']['minduration']).to.equal(videoBidRequests[0].params.video['minduration']); - expect(data.imp[0]['video']['maxduration']).to.equal(videoBidRequests[0].params.video['maxduration']); - expect(data.imp[0]['video']['w']).to.equal(videoBidRequests[0].mediaTypes.video.playerSize[0][0]); - expect(data.imp[0]['video']['h']).to.equal(videoBidRequests[0].mediaTypes.video.playerSize[0][1]); - expect(data.source.ext.schain).to.deep.equal(videoBidRequests[0].ortb2.source.ext.schain); - }); - describe('setting imp.floor using floorModule', function () { - /* - Use the minimum value among floor from floorModule per mediaType - If params.bidFloor is set then take max(floor, min(floors from floorModule)) - set imp.bidfloor only if it is more than 0 - */ - - let newRequest; - let floorModuleTestData; - const getFloor = function (req) { - return floorModuleTestData[req.mediaType]; - }; - - beforeEach(() => { - floorModuleTestData = { - 'banner': { - 'currency': 'AUD', - 'floor': 1.50 - }, - 'video': { - 'currency': 'AUD', - 'floor': 2.00 - } - }; - newRequest = utils.deepClone(bidRequests); - newRequest[0].getFloor = getFloor; - }); - - it('bidfloor should be undefined if calculation is <= 0', function () { - floorModuleTestData.banner.floor = 0; // lowest of them all - newRequest[0].params.bidFloor = undefined; - const request = spec.buildRequests(newRequest); - let data = JSON.parse(request.data); - data = data.imp[0]; - expect(data.bidfloor).to.equal(undefined); - }); - - it('ignore floormodule o/p if floor is not number', function () { - floorModuleTestData.banner.floor = 'INR'; - newRequest[0].params.bidFloor = undefined; - const request = spec.buildRequests(newRequest); - let data = JSON.parse(request.data); - data = data.imp[0]; - expect(data.bidfloor).to.equal(undefined); // video will be lowest now - }); - - it('ignore floormodule o/p if currency is not matched', function () { - floorModuleTestData.banner.currency = 'INR'; - newRequest[0].params.bidFloor = undefined; - const request = spec.buildRequests(newRequest); - let data = JSON.parse(request.data); - data = data.imp[0]; - expect(data.bidfloor).to.equal(undefined); // video will be lowest now - }); - - it('bidFloor is not passed, use minimum from floorModule', function () { - newRequest[0].params.bidFloor = undefined; - const request = spec.buildRequests(newRequest); - let data = JSON.parse(request.data); - data = data.imp[0]; - expect(data.bidfloor).to.equal(1.5); - }); - - it('bidFloor is passed as 1, use min of floorModule as it is highest', function () { - newRequest[0].params.bidFloor = '1.0';// yes, we want it as a string - const request = spec.buildRequests(newRequest); - let data = JSON.parse(request.data); - data = data.imp[0]; - expect(data.bidfloor).to.equal(1.5); - }); - }); - describe('Response checking', function () { - it('should check for valid response values', function () { - const request = spec.buildRequests(bidRequests); - const response = spec.interpretResponse(bidResponses, request); - expect(response).to.be.an('array').with.length.above(0); - expect(response[0].requestId).to.equal(bidResponses.body.seatbid[0].bid[0].impid); - expect(response[0].cpm).to.equal((bidResponses.body.seatbid[0].bid[0].price).toFixed(2)); - expect(response[0].width).to.equal(bidResponses.body.seatbid[0].bid[0].w); - expect(response[0].height).to.equal(bidResponses.body.seatbid[0].bid[0].h); - if (bidResponses.body.seatbid[0].bid[0].crid) { - expect(response[0].creativeId).to.equal(bidResponses.body.seatbid[0].bid[0].crid); - } else { - expect(response[0].creativeId).to.equal(bidResponses.body.seatbid[0].bid[0].id); - } - expect(response[0].dealId).to.equal(bidResponses.body.seatbid[0].bid[0].dealid); - expect(response[0].currency).to.equal('USD'); - expect(response[0].netRevenue).to.equal(false); - expect(response[0].ttl).to.equal(300); - }); - it('should check for valid banner mediaType in request', function () { - const request = spec.buildRequests(bidRequests); - const response = spec.interpretResponse(bidResponses, request); - - expect(response[0].mediaType).to.equal('banner'); - }); - it('should check for valid video mediaType in request', function () { - const request = spec.buildRequests(videoBidRequests); - const response = spec.interpretResponse(videoBidResponse, request); - - expect(response[0].mediaType).to.equal('video'); - }); - }); - }); - describe('Video request params', function () { - let sandbox, utilsMock, newVideoRequest; - beforeEach(() => { - utilsMock = sinon.mock(utils); - sandbox = sinon.createSandbox(); - sandbox.spy(utils, 'logWarn'); - newVideoRequest = utils.deepClone(videoBidRequests); - }); - - afterEach(() => { - utilsMock.restore(); - sandbox.restore(); - }); - - it('Video params from mediaTypes and params obj of bid are not present', function () { - delete newVideoRequest[0].mediaTypes.video; - delete newVideoRequest[0].params.video; - const request = spec.buildRequests(newVideoRequest); - expect(request).to.equal(undefined); - }); - - it('Should consider video params from mediaType object of bid', function () { - delete newVideoRequest[0].params.video; - - const request = spec.buildRequests(newVideoRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].video).to.exist; - expect(data.imp[0]['video']['w']).to.equal(videoBidRequests[0].mediaTypes.video.playerSize[0][0]); - expect(data.imp[0]['video']['h']).to.equal(videoBidRequests[0].mediaTypes.video.playerSize[0][1]); - expect(data.imp[0]['video']['battr']).to.equal(undefined); - }); - }); - describe('getUserSyncs', function () { - const syncurl_iframe = 'https://sync.lemmadigital.com/js/usersync.html?pid=1001'; - let sandbox; - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - afterEach(function () { - sandbox.restore(); - }); - - it('execute as per config', function () { - expect(spec.getUserSyncs({ iframeEnabled: true }, {}, undefined, undefined)).to.deep.equal([{ - type: 'iframe', url: syncurl_iframe - }]); - }); - - it('not execute as per config', function () { - expect(spec.getUserSyncs({ iframeEnabled: false }, {}, undefined, undefined)).to.deep.equal(undefined); - }); - }); - }); -}); diff --git a/test/spec/modules/lifestreetBidAdapter_spec.js b/test/spec/modules/lifestreetBidAdapter_spec.js deleted file mode 100644 index 2c121b304..000000000 --- a/test/spec/modules/lifestreetBidAdapter_spec.js +++ /dev/null @@ -1,232 +0,0 @@ -import { expect } from 'chai'; -import { BANNER, VIDEO } from 'src/mediaTypes.js'; -import { spec } from 'modules/lifestreetBidAdapter.js'; - -describe('lifestreetBidAdapter', function() { - let bidRequests; - let videoBidRequests; - let bidResponses; - let videoBidResponses; - beforeEach(function() { - bidRequests = [ - { - bidder: 'lifestreet', - params: { - slot: 'slot166704', - adkey: '78c', - ad_size: '160x600' - }, - mediaTypes: { - banner: { - sizes: [ - [160, 600], - [300, 600] - ] - } - }, - sizes: [ - [160, 600], - [300, 600] - ] - } - ]; - - bidResponses = { - body: { - cpm: 0.1, - netRevenue: true, - content_type: 'display_flash', - width: 160, - currency: 'USD', - ttl: 86400, - content: '', - adomain: ['domain.io'], - iurl: 'https://local.url', - cid: 'string-id', - crid: 'string-id', - cat: ['IAB2'], - attr: [], - w: 300, - h: 250, - ext: { - advertiser_name: 'Advertiser', - agency_name: 'mediakeys', - prebid: { - type: 'B' - } - }, - }, - ], - seat: '337', - }, - ], - cur: 'USD', - ext: { protocol: '5.3' }, - } - } - - it('Returns empty array if no bid', function () { - const bidRequests = [utils.deepClone(bid)]; - const request = spec.buildRequests(bidRequests, bidderRequest); - const response01 = spec.interpretResponse({ body: { seatbid: [{ bid: [] }] } }, request); - const response02 = spec.interpretResponse({ body: { seatbid: [] } }, request); - const response03 = spec.interpretResponse({ body: { seatbid: null } }, request); - const response04 = spec.interpretResponse({ body: { seatbid: null } }, request); - const response05 = spec.interpretResponse({ body: {} }, request); - const response06 = spec.interpretResponse({}, request); - - expect(response01.length).to.equal(0); - expect(response02.length).to.equal(0); - expect(response03.length).to.equal(0); - expect(response04.length).to.equal(0); - expect(response05.length).to.equal(0); - expect(response06.length).to.equal(0); - }); - - it('Meta Primary category handling', function() { - const rawServerResponseCopy = utils.deepClone(rawServerResponse); - const rawServerResponseCopy2 = utils.deepClone(rawServerResponse); - const rawServerResponseCopy3 = utils.deepClone(rawServerResponse); - const rawServerResponseCopy4 = utils.deepClone(rawServerResponse); - const rawServerResponseCopy5 = utils.deepClone(rawServerResponse); - const rawServerResponseCopy6 = utils.deepClone(rawServerResponse); - rawServerResponseCopy.body.seatbid[0].bid[0].cat = 'IAB12-1'; - rawServerResponseCopy2.body.seatbid[0].bid[0].cat = ['IAB12', 'IAB12-1']; - rawServerResponseCopy3.body.seatbid[0].bid[0].cat = ''; - rawServerResponseCopy4.body.seatbid[0].bid[0].cat = []; - rawServerResponseCopy5.body.seatbid[0].bid[0].cat = 123; - delete rawServerResponseCopy6.body.seatbid[0].bid[0].cat; - - const bidRequests = [utils.deepClone(bid)]; - const request = spec.buildRequests(bidRequests, bidderRequest); - const response = spec.interpretResponse(rawServerResponseCopy, request); - const response2 = spec.interpretResponse(rawServerResponseCopy2, request); - const response3 = spec.interpretResponse(rawServerResponseCopy3, request); - const response4 = spec.interpretResponse(rawServerResponseCopy4, request); - const response5 = spec.interpretResponse(rawServerResponseCopy5, request); - const response6 = spec.interpretResponse(rawServerResponseCopy6, request); - expect(response[0].meta.primaryCatId).to.equal('IAB12-1'); - expect(response2[0].meta.primaryCatId).to.equal('IAB12'); - expect(response3[0].meta.primaryCatId).to.not.exist; - expect(response4[0].meta.primaryCatId).to.not.exist; - expect(response5[0].meta.primaryCatId).to.not.exist; - expect(response6[0].meta.primaryCatId).to.not.exist; - }); - - it('Build banner response', function () { - const bidRequests = [utils.deepClone(bid)]; - const request = spec.buildRequests(bidRequests, bidderRequest); - const response = spec.interpretResponse(rawServerResponse, request); - - expect(response.length).to.equal(1); - expect(response[0].requestId).to.equal(rawServerResponse.body.seatbid[0].bid[0].impid); - expect(response[0].cpm).to.equal(rawServerResponse.body.seatbid[0].bid[0].price); - expect(response[0].width).to.equal(rawServerResponse.body.seatbid[0].bid[0].w); - expect(response[0].height).to.equal(rawServerResponse.body.seatbid[0].bid[0].h); - expect(response[0].creativeId).to.equal(rawServerResponse.body.seatbid[0].bid[0].crid); - expect(response[0].dealId).to.equal(null); - expect(response[0].currency).to.equal(rawServerResponse.body.cur); - expect(response[0].netRevenue).to.equal(true); - expect(response[0].ttl).to.equal(360); - expect(response[0].referrer).to.equal(''); - expect(response[0].ad).to.equal(rawServerResponse.body.seatbid[0].bid[0].adm); - expect(response[0].mediaType).to.equal('banner'); - expect(response[0].burl).to.equal(rawServerResponse.body.seatbid[0].bid[0].burl); - expect(response[0].meta).to.deep.equal({ - advertiserDomains: rawServerResponse.body.seatbid[0].bid[0].adomain, - advertiserName: 'Advertiser', - agencyName: 'mediakeys', - primaryCatId: 'IAB2', - mediaType: 'banner' - }); - }); - - it('interprets video bid response', function () { - const vastUrl = 'https://url.local?req=content'; - const bidRequests = [utils.deepClone(bidVideo)]; - const request = spec.buildRequests(bidRequests, bidderRequest); - - const rawServerResponseVideo = utils.deepClone(rawServerResponse); - rawServerResponseVideo.body.seatbid[0].bid[0].ext.prebid.type = 'V'; - rawServerResponseVideo.body.seatbid[0].bid[0].ext.vast_url = vastUrl; - - const response = spec.interpretResponse(rawServerResponseVideo, request); - - expect(response.length).to.equal(1); - expect(response[0].mediaType).to.equal('video'); - expect(response[0].meta.mediaType).to.equal('video'); - expect(response[0].vastXml).to.not.exist; - expect(response[0].vastUrl).to.equal(vastUrl + '&no_cache'); - expect(response[0].videoCacheKey).to.equal('no_cache'); - }); - - describe('Native response', function () { - let bidRequests; - let bidderRequestCopy; - let request; - let rawServerResponseNative; - let nativeObject; - - beforeEach(function() { - bidRequests = [utils.deepClone(bidNative)]; - bidderRequestCopy = utils.deepClone(bidderRequest); - bidderRequestCopy.bids = bidRequests; - - request = spec.buildRequests(bidRequests, bidderRequestCopy); - - nativeObject = { - ver: '1.2', - privacy: 'https://privacy.me', - assets: [ - { id: 5, data: { type: 1, value: 'Sponsor Brand' } }, - { id: 6, data: { type: 2, value: 'Brand Body' } }, - { id: 14, data: { type: 10, value: 'Brand Body 2' } }, - { id: 1, title: { text: 'Brand Title' } }, - { id: 2, img: { type: 3, url: 'https://url.com/img.jpg', w: 300, h: 250 } }, - { id: 3, img: { type: 1, url: 'https://url.com/ico.png', w: 50, h: 50 } }, - ], - link: { - url: 'https://brand.me', - clicktrackers: [ - 'https://click.me' - ] - }, - eventtrackers: [ - { event: 1, method: 1, url: 'https://eventrack.me/impression' }, - { event: 1, method: 2, url: 'https://eventrack-js.me/impression-1' } - ] - }; - - rawServerResponseNative = utils.deepClone(rawServerResponse); - rawServerResponseNative.body.seatbid[0].bid[0].ext.prebid.type = 'N'; - rawServerResponseNative.body.seatbid[0].bid[0].adm = JSON.stringify(nativeObject) - }); - - it('should ignore invalid native response', function() { - const nativeObjectCopy = utils.deepClone(nativeObject); - nativeObjectCopy.assets = []; - const rawServerResponseNativeCopy = utils.deepClone(rawServerResponseNative); - rawServerResponseNativeCopy.body.seatbid[0].bid[0].adm = JSON.stringify(nativeObjectCopy) - const response = spec.interpretResponse(rawServerResponseNativeCopy, request); - expect(response.length).to.equal(1); - expect(response[0].native).to.not.exist; - }); - - it('should build a classic Prebid.js native object for response', function() { - const rawServerResponseNativeCopy = utils.deepClone(rawServerResponseNative); - const response = spec.interpretResponse(rawServerResponseNativeCopy, request); - expect(response.length).to.equal(1); - expect(response[0].mediaType).to.equal('native'); - expect(response[0].meta.mediaType).to.equal('native'); - expect(response[0].native).to.exist; - expect(response[0].native.body).to.exist; - expect(response[0].native.privacyLink).to.exist; - expect(response[0].native.body2).to.exist; - expect(response[0].native.sponsoredBy).to.exist; - expect(response[0].native.image).to.exist; - expect(response[0].native.icon).to.exist; - expect(response[0].native.title).to.exist; - expect(response[0].native.clickUrl).to.exist; - expect(response[0].native.clickTrackers).to.exist; - expect(response[0].native.clickTrackers.length).to.equal(1); - expect(response[0].native.impressionTrackers).to.exist; - expect(response[0].native.impressionTrackers.length).to.equal(1); - expect(response[0].native.impressionTrackers[0]).to.equal('https://eventrack.me/impression'); - expect(response[0].native.javascriptTrackers).to.exist; - expect(response[0].native.javascriptTrackers).to.equal(''); - }); - - it('should ignore eventtrackers with a unsupported type', function() { - const rawServerResponseNativeCopy = utils.deepClone(rawServerResponseNative); - const nativeObjectCopy = utils.deepClone(nativeObject); - nativeObjectCopy.eventtrackers[0].event = 2; - rawServerResponseNativeCopy.body.seatbid[0].bid[0].adm = JSON.stringify(nativeObjectCopy); - const response = spec.interpretResponse(rawServerResponseNativeCopy, request); - expect(response[0].native.impressionTrackers).to.exist; - expect(response[0].native.impressionTrackers.length).to.equal(0); - }) - - it('Should handle multiple javascriptTrackers in one single string', () => { - const rawServerResponseNativeCopy = utils.deepClone(rawServerResponseNative); - const nativeObjectCopy = utils.deepClone(nativeObject); - nativeObjectCopy.eventtrackers.push( - { - event: 1, - method: 2, - url: 'https://eventrack-js.me/impression-2' - },) - rawServerResponseNativeCopy.body.seatbid[0].bid[0].adm = JSON.stringify(nativeObjectCopy); - const response = spec.interpretResponse(rawServerResponseNativeCopy, request); - const expected = '\n'; - expect(response[0].native.javascriptTrackers).to.equal(expected); - }); - }); - }); - - describe('onBidWon', function() { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - - afterEach(function() { - utils.triggerPixel.restore(); - }); - - it('Should not trigger pixel if bid does not contain burl', function() { - const result = spec.onBidWon({}); - expect(result).to.be.undefined; - expect(utils.triggerPixel.callCount).to.equal(0); - }) - - it('Should trigger pixel if bid.burl exists', function() { - const result = spec.onBidWon({ - cpm: 4.2, - burl: 'https://example.com/p=${AUCTION_PRICE}&foo=bar' - }); - - expect(utils.triggerPixel.callCount).to.equal(1) - expect(utils.triggerPixel.firstCall.args[0]).to.be.equal( - 'https://example.com/p=4.2&foo=bar' - ); - }) - }) -}); diff --git a/test/spec/modules/medianetAnalyticsAdapter_spec.js b/test/spec/modules/medianetAnalyticsAdapter_spec.js deleted file mode 100644 index 61248ffcf..000000000 --- a/test/spec/modules/medianetAnalyticsAdapter_spec.js +++ /dev/null @@ -1,863 +0,0 @@ -import {expect} from 'chai'; -import medianetAnalytics from 'modules/medianetAnalyticsAdapter.js'; -import * as utils from 'src/utils.js'; -import {EVENTS, REJECTION_REASON} from 'src/constants.js'; -import * as events from 'src/events.js'; -import {clearEvents} from 'src/events.js'; -import {deepAccess} from 'src/utils.js'; -import 'src/prebid.js'; -import {config} from 'src/config.js'; - -import {getGlobal} from 'src/prebidGlobal.js'; -import sinon from "sinon"; -import * as mnUtils from '../../../libraries/medianetUtils/utils.js'; - -const { - AUCTION_INIT, - BID_REQUESTED, - BID_RESPONSE, - NO_BID, - BID_TIMEOUT, - AUCTION_END, - SET_TARGETING, - BID_WON, - AD_RENDER_FAILED, - AD_RENDER_SUCCEEDED, - STALE_RENDER, - BID_REJECTED -} = EVENTS; - -function createBidResponse(bidderCode, requestId, cpm, adId = '3e6e4bce5c8fb3') { - return { - bidderCode, - width: 300, - height: 250, - adId, - requestId, - mediaType: 'banner', - source: 'client', - ext: {pvid: 123, crid: '321'}, - no_bid: false, - cpm, - ad: 'AD_CODE', - ttl: 180, - creativeId: 'Test1', - netRevenue: true, - currency: 'USD', - dfp_id: 'div-gpt-ad-1460505748561-0', - originalCpm: cpm, - originalCurrency: 'USD', - floorData: {floorValue: 1.10, floorRule: 'banner'}, - auctionId: '8e0d5245-deb3-406c-96ca-9b609e077ff7', - snm: 'SUCCESS', - responseTimestamp: 1584563606009, - requestTimestamp: 1584563605743, - bidder: 'medianet', - adUnitCode: 'div-gpt-ad-1460505748561-0', - timeToRespond: 266, - pbLg: '2.00', - pbMg: '2.20', - pbHg: '2.29', - pbAg: '2.25', - pbDg: '2.29', - pbCg: '2.00', - size: '300x250', - adserverTargeting: { - hb_bidder: 'medianet', - hb_adid: adId, - hb_pb: '1.8', - hb_size: '300x250', - hb_source: 'client', - hb_format: 'banner', - prebid_test: 1 - }, - params: [{cid: 'test123', crid: '451466393'}] - }; -} - -function createBidRequest(bidderCode, auctionId, bidId, adUnits) { - return { - bidderCode, - auctionId, - bids: adUnits.map(adUnit => ({ - bidder: bidderCode, - params: {cid: 'TEST_CID', crid: '451466393'}, - mediaTypes: adUnit.mediaTypes, - adUnitCode: adUnit.code, - sizes: [(adUnit.mediaTypes.banner?.sizes || []), (adUnit.mediaTypes.native?.image?.sizes || []), (adUnit.mediaTypes.video?.playerSize || [])], - bidId, - auctionId, - src: 'client' - })), - auctionStart: Date.now(), - timeout: 6000, - uspConsent: '1YY', - start: Date.now() - }; -} - -function createNoBid(bidder, params) { - return { - bidder, - params, - mediaTypes: {banner: {sizes: [[300, 250]], ext: ['asdads']}}, - adUnitCode: 'div-gpt-ad-1460505748561-0', - transactionId: '303fa0c6-682f-4aea-8e4a-dc68f0d5c7d5', - sizes: [[300, 250], [300, 600]], - bidId: '28248b0e6aece2', - bidderRequestId: '13fccf3809fe43', - auctionId: '8e0d5245-deb3-406c-96ca-9b609e077ff7', - src: 'client' - }; -} - -function createBidTimeout(bidId, bidder, auctionId, params) { - return [{ - bidId: '28248b0e6aece2', - bidder: 'medianet', - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId, - params, - timeout: 6 - }]; -} - -function createBidWon(bidderCode, adId, requestId, cpm) { - return { - bidderCode, - width: 300, - height: 250, - statusMessage: 'Bid available', - adId, - requestId, - mediaType: 'banner', - source: 'client', - no_bid: false, - cpm, - ad: 'AD_CODE', - ttl: 180, - creativeId: 'Test1', - netRevenue: true, - currency: 'USD', - dfp_id: 'div-gpt-ad-1460505748561-0', - originalCpm: 1.1495, - originalCurrency: 'USD', - auctionId: '8e0d5245-deb3-406c-96ca-9b609e077ff7', - responseTimestamp: 1584563606009, - requestTimestamp: 1584563605743, - bidder: 'medianet', - adUnitCode: 'div-gpt-ad-1460505748561-0', - snm: 'SUCCESS', - timeToRespond: 266, - pbLg: '2.00', - pbMg: '2.20', - pbHg: '2.29', - pbAg: '2.25', - pbDg: '2.29', - pbCg: '2.00', - size: '300x250', - adserverTargeting: { - hb_bidder: 'medianet', - hb_adid: adId, - hb_pb: '2.00', - hb_size: '300x250', - hb_source: 'client', - hb_format: 'banner', - prebid_test: 1 - }, - status: 'rendered', - params: [{cid: 'test123', crid: '451466393'}] - }; -} - -const BANNER_AD_UNIT = {code: 'div-gpt-ad-1460505748561-0', mediaTypes: {banner: {sizes: [[300, 250]]}}}; -const VIDEO_AD_UNIT = { - code: 'div-gpt-ad-1460505748561-0', - mediaTypes: {video: {playerSize: [640, 480], context: 'outstream'}} -}; -const INSTREAM_VIDEO_AD_UNIT = { - code: 'div-gpt-ad-1460505748561-0', - mediaTypes: {video: {playerSize: [640, 480], context: 'instream'}} -}; -const BANNER_NATIVE_AD_UNIT = { - code: 'div-gpt-ad-1460505748561-0', - mediaTypes: {banner: {sizes: [[300, 250]]}, native: {image: {required: true, sizes: [150, 50]}}} -}; -const BANNER_NATIVE_VIDEO_AD_UNIT = { - code: 'div-gpt-ad-1460505748561-0', - mediaTypes: { - banner: {sizes: [[300, 250]]}, - video: {playerSize: [640, 480], context: 'outstream'}, - native: {image: {required: true, sizes: [150, 50]}, title: {required: true, len: 80}} - } -}; - -function createS2SBidRequest(bidderCode, auctionId, bidId, adUnits) { - const bidRequest = createBidRequest(bidderCode, auctionId, bidId, adUnits); - // Update to mark as S2S - bidRequest.src = 's2s'; - bidRequest.bids.forEach(bid => { - bid.src = 's2s'; - }); - return bidRequest; -} - -function createS2SBidResponse(bidderCode, requestId, cpm, adId = '3e6e4bce5c8fb3') { - const bidResponse = createBidResponse(bidderCode, requestId, cpm, adId); - // Update to mark as S2S - bidResponse.source = 's2s'; - return bidResponse; -} - -const MOCK = { - AD_UNITS: [BANNER_NATIVE_AD_UNIT, VIDEO_AD_UNIT], - AUCTION_INIT: { - auctionId: '8e0d5245-deb3-406c-96ca-9b609e077ff7', - timestamp: 1584563605739, - timeout: 6000, - bidderRequests: [{bids: [{floorData: {enforcements: {enforceJS: true}}}]}] - }, - MNET_BID_REQUESTED: createBidRequest('medianet', '8e0d5245-deb3-406c-96ca-9b609e077ff7', '28248b0e6aece2', [BANNER_NATIVE_VIDEO_AD_UNIT]), - MNET_BID_RESPONSE: createBidResponse('medianet', '28248b0e6aece2', 2.299), - COMMON_REQ_ID_BID_REQUESTS: [ - createBidRequest('medianet', '8e0d5245-deb3-406c-96ca-9b609e077ff7', '28248b0e6aece2', [BANNER_AD_UNIT]), - createBidRequest('appnexus', '8e0d5245-deb3-406c-96ca-9b609e077ff7', '28248b0e6aecd5', [BANNER_AD_UNIT]) - ], - COMMON_REQ_ID_BID_RESPONSES: [ - createBidResponse('medianet', '28248b0e6aece2', 2.299, '3e6e4bce5c8fb3'), - createBidResponse('appnexus', '28248b0e6aecd5', 1.299, '3e6e4bce5c8fb4') - ], - COMMON_REQ_ID_BID_RESPONSES_EQUAL_CPM: [ - createBidResponse('medianet', '28248b0e6aece2', 2.299, '3e6e4bce5c8fb3'), - createBidResponse('medianet', '28248b0e6aece2', 2.299, '3e6e4bce5c8fb4') - ], - MULTI_BID_RESPONSES: [ - createBidResponse('medianet', '28248b0e6aece2', 2.299, '3e6e4bce5c8fb3'), - Object.assign(createBidResponse('medianet', '28248b0e6aebecc', 3.299, '3e6e4bce5c8fb4'), - {originalBidder: 'bidA2', originalRequestId: '28248b0e6aece2'}), - ], - MNET_NO_BID: createNoBid('medianet', {cid: 'test123', crid: '451466393', site: {}}), - MNET_BID_TIMEOUT: createBidTimeout('28248b0e6aece2', 'medianet', '8e0d5245-deb3-406c-96ca-9b609e077ff7', [{ - cid: 'test123', - crid: '451466393', - site: {} - }, {cid: '8CUX0H51P', crid: '451466393', site: {}}]), - AUCTION_END: { - auctionId: '8e0d5245-deb3-406c-96ca-9b609e077ff7', - auctionEnd: 1584563605739, - bidderRequests: [createBidRequest('medianet', '8e0d5245-deb3-406c-96ca-9b609e077ff7', '28248b0e6aece2', [BANNER_NATIVE_VIDEO_AD_UNIT])] - }, - MNET_BID_WON: createBidWon('medianet', '3e6e4bce5c8fb3', '28248b0e6aece2', 2.299), - BID_WON_UNKNOWN: createBidWon('appnexus', '3e6e4bce5c8fkk', '28248b0e6aecd5', 2.299), - MNET_SET_TARGETING: { - 'div-gpt-ad-1460505748561-0': { - prebid_test: '1', - hb_format: 'banner', - hb_source: 'client', - hb_size: '300x250', - hb_pb: '1.8', - hb_adid: '3e6e4bce5c8fb3', - hb_bidder: 'medianet', - hb_format_medianet: 'banner', - hb_source_medianet: 'client', - hb_size_medianet: '300x250', - hb_pb_medianet: '2.00', - hb_adid_medianet: '3e6e4bce5c8fb3', - hb_bidder_medianet: 'medianet' - } - }, - NO_BID_SET_TARGETING: {'div-gpt-ad-1460505748561-0': {}}, - // S2S mocks - MNET_S2S_BID_REQUESTED: createS2SBidRequest('medianet', '8e0d5245-deb3-406c-96ca-9b609e077ff7', '28248b0e6aece2', [BANNER_AD_UNIT]), - MNET_S2S_BID_RESPONSE: createS2SBidResponse('medianet', '28248b0e6aece2', 2.299), - MNET_S2S_BID_WON: Object.assign({}, createBidWon('medianet', '3e6e4bce5c8fb3', '28248b0e6aece2', 2.299), {source: 's2s'}), - MNET_S2S_SET_TARGETING: { - 'div-gpt-ad-1460505748561-0': { - prebid_test: '1', - hb_format: 'banner', - hb_source: 's2s', - hb_size: '300x250', - hb_pb: '1.8', - hb_adid: '3e6e4bce5c8fb3', - hb_bidder: 'medianet', - hb_format_medianet: 'banner', - hb_source_medianet: 's2s', - hb_size_medianet: '300x250', - hb_pb_medianet: '2.00', - hb_adid_medianet: '3e6e4bce5c8fb3', - hb_bidder_medianet: 'medianet' - } - }, - // Currency conversion mocks - MNET_JPY_BID_RESPONSE: Object.assign({}, createBidResponse('medianet', '28248b0e6aece2', 250, '3e6e4bce5c8fb5'), { - currency: 'JPY', - originalCurrency: 'JPY', - originalCpm: 250 - }) -}; - -function getQueryData(url, decode = false) { - const queryArgs = url.split('?')[1].split('&'); - return queryArgs.reduce((data, arg) => { - let [key, val] = arg.split('='); - if (decode) { - val = decodeURIComponent(val); - } - if (data[key] !== undefined) { - if (!Array.isArray(data[key])) { - data[key] = [data[key]]; - } - data[key].push(val); - } else { - data[key] = val; - } - return data; - }, {}); -} - -function waitForPromiseResolve(promise) { - return new Promise((resolve, reject) => { - promise.then(resolve).catch(reject); - }); -} - -function performNoBidAuction() { - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.AD_UNITS})); - events.emit(BID_REQUESTED, MOCK.MNET_BID_REQUESTED); - events.emit(NO_BID, MOCK.MNET_NO_BID); - events.emit(AUCTION_END, Object.assign({}, MOCK.AUCTION_END, {bidderRequests: [MOCK.MNET_BID_REQUESTED]})); - events.emit(SET_TARGETING, MOCK.MNET_SET_TARGETING); -} - -function performBidWonAuction() { - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.AD_UNITS})); - events.emit(BID_REQUESTED, MOCK.MNET_BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.MNET_BID_RESPONSE); - events.emit(SET_TARGETING, MOCK.MNET_SET_TARGETING); - events.emit(BID_WON, MOCK.MNET_BID_WON); -} - -function performBidTimeoutAuction() { - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.AD_UNITS})); - events.emit(BID_REQUESTED, MOCK.MNET_BID_REQUESTED); - events.emit(BID_TIMEOUT, MOCK.MNET_BID_TIMEOUT); - events.emit(AUCTION_END, Object.assign({}, MOCK.AUCTION_END, {bidderRequests: [MOCK.MNET_BID_REQUESTED]})); - events.emit(SET_TARGETING, MOCK.MNET_SET_TARGETING); -} - -function performAuctionWithSameRequestIdBids(bidRespArray) { - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.AD_UNITS})); - events.emit(BID_REQUESTED, MOCK.MNET_BID_REQUESTED); - bidRespArray.forEach(bidResp => events.emit(BID_RESPONSE, bidResp)); - events.emit(AUCTION_END, Object.assign({}, MOCK.AUCTION_END, {bidderRequests: [MOCK.MNET_BID_REQUESTED]})); - events.emit(SET_TARGETING, MOCK.MNET_SET_TARGETING); - events.emit(BID_WON, MOCK.MNET_BID_WON); -} - -function performAuctionNoWin() { - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.AD_UNITS})); - MOCK.COMMON_REQ_ID_BID_REQUESTS.forEach(bidReq => events.emit(BID_REQUESTED, bidReq)); - MOCK.COMMON_REQ_ID_BID_RESPONSES.forEach(bidResp => events.emit(BID_RESPONSE, bidResp)); - events.emit(AUCTION_END, Object.assign({}, MOCK.AUCTION_END, {bidderRequests: MOCK.COMMON_REQ_ID_BID_REQUESTS})); - events.emit(SET_TARGETING, MOCK.MNET_SET_TARGETING); -} - -function performMultiBidAuction() { - const bidRequest = createBidRequest('medianet', '8e0d5245-deb3-406c-96ca-9b609e077ff7', '28248b0e6aece2', [BANNER_AD_UNIT]); - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.AD_UNITS})); - events.emit(BID_REQUESTED, bidRequest); - MOCK.MULTI_BID_RESPONSES.forEach(bidResp => events.emit(BID_RESPONSE, bidResp)); - events.emit(AUCTION_END, Object.assign({}, MOCK.AUCTION_END, {bidderRequests: [bidRequest]})); - events.emit(SET_TARGETING, MOCK.MNET_SET_TARGETING); -} - -function performBidRejectedAuction() { - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.AD_UNITS})); - events.emit(BID_REQUESTED, MOCK.MNET_BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.MNET_BID_RESPONSE); - events.emit(BID_REJECTED, Object.assign({}, MOCK.MNET_BID_RESPONSE, { - rejectionReason: REJECTION_REASON.FLOOR_NOT_MET, - })); - events.emit(AUCTION_END, Object.assign({}, MOCK.AUCTION_END, {bidderRequests: [MOCK.MNET_BID_REQUESTED]})); -} - -function performS2SAuction() { - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.AD_UNITS})); - events.emit(BID_REQUESTED, MOCK.MNET_S2S_BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.MNET_S2S_BID_RESPONSE); - events.emit(AUCTION_END, Object.assign({}, MOCK.AUCTION_END, {bidderRequests: [MOCK.MNET_S2S_BID_REQUESTED]})); - events.emit(SET_TARGETING, MOCK.MNET_S2S_SET_TARGETING); - events.emit(BID_WON, MOCK.MNET_S2S_BID_WON); -} - -function performCurrencyConversionAuction() { - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.AD_UNITS})); - events.emit(BID_REQUESTED, MOCK.MNET_BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.MNET_JPY_BID_RESPONSE); - events.emit(AUCTION_END, Object.assign({}, MOCK.AUCTION_END, {bidderRequests: [MOCK.MNET_BID_REQUESTED]})); -} - -describe('Media.net Analytics Adapter', function () { - let sandbox; - let clock; - const CUSTOMER_ID = 'test123'; - const VALID_CONFIGURATION = { - options: { - cid: CUSTOMER_ID - } - } - - before(() => { - clearEvents(); - }); - - beforeEach(function () { - sandbox = sinon.createSandbox(); - clock = sinon.useFakeTimers(); - }); - - afterEach(function () { - sandbox.restore(); - clock.restore(); - }); - - describe('Configuration', function () { - it('should log error if publisher id is not passed', function () { - sandbox.stub(utils, 'logError'); - - medianetAnalytics.enableAnalytics(); - expect( - utils.logError.calledWith( - 'Media.net Analytics adapter: cid is required.' - ) - ).to.be.true; - }); - - it('should not log error if valid config is passed', function () { - sandbox.stub(utils, 'logError'); - - medianetAnalytics.enableAnalytics(VALID_CONFIGURATION); - expect(utils.logError.called).to.equal(false); - medianetAnalytics.disableAnalytics(); - }); - }); - - describe('VAST Tracking', function () { - beforeEach(function () { - medianetAnalytics.enableAnalytics({ - options: { - cid: 'test123' - } - }); - medianetAnalytics.clearlogsQueue(); - // Set config required for vastTrackerHandler - config.setConfig({ - cache: { - url: 'https://test.cache.url/endpoint' - } - }); - }); - - afterEach(function () { - medianetAnalytics.disableAnalytics(); - config.resetConfig(); - }); - - it('should generate valid tracking URL for video bids', function () { - const VIDEO_AUCTION = Object.assign({}, MOCK.AUCTION_INIT, {adUnits: [INSTREAM_VIDEO_AD_UNIT]}); - const VIDEO_BID_REQUESTED = createBidRequest('medianet', '8e0d5245-deb3-406c-96ca-9b609e077ff7', '28248b0e6aece2', [INSTREAM_VIDEO_AD_UNIT]); - const videoBidResponse = Object.assign({}, MOCK.MNET_BID_RESPONSE, { - mediaType: 'video', - playerSize: [640, 480] - }); - - events.emit(AUCTION_INIT, VIDEO_AUCTION); - events.emit(BID_REQUESTED, VIDEO_BID_REQUESTED); - events.emit(BID_RESPONSE, videoBidResponse); - - const trackers = medianetAnalytics.getVastTrackerHandler()(videoBidResponse, { - auction: VIDEO_AUCTION, - bidRequest: VIDEO_BID_REQUESTED.bids[0] - }); - - expect(trackers).to.be.an('array'); - expect(trackers.length).to.equal(1); - expect(trackers[0].event).to.equal('impressions'); - expect(trackers[0].url).to.include('https://'); - - const urlData = getQueryData(trackers[0].url); - expect(urlData.lgtp).to.equal('RA'); - expect(urlData.pvnm).to.include('medianet'); - expect(urlData.bdp).to.equal('2.299'); - expect(urlData.vplcmtt).to.equal('1'); - }); - - it('should return error tracker when auction is missing', function () { - const videoBidResponse = Object.assign({}, MOCK.MNET_BID_RESPONSE, { - mediaType: 'video', - vastUrl: 'https://vast.example.com/vast.xml', - videoCacheKey: 'video_cache_123', - auctionId: 'missing_auction_id' // This auction ID doesn't exist - }); - - const trackers = medianetAnalytics.getVastTrackerHandler()(videoBidResponse, { - bidRequest: MOCK.MNET_BID_REQUESTED.bids[0], - auction: MOCK.AUCTION_INIT - }); - - expect(trackers).to.be.an('array'); - expect(trackers.length).to.equal(1); - expect(trackers[0].url).to.include('vast_tracker_handler_missing_auction'); - }); - - it('should return error tracker when bidrequest is missing', function () { - const VIDEO_AUCTION = Object.assign({}, MOCK.AUCTION_INIT, {adUnits: [INSTREAM_VIDEO_AD_UNIT]}); - const VIDEO_BID_REQUESTED = createBidRequest('medianet', '8e0d5245-deb3-406c-96ca-9b609e077ff7', '28248b0e6aece2', [INSTREAM_VIDEO_AD_UNIT]); - const videoBidResponse = Object.assign({}, MOCK.MNET_BID_RESPONSE, { - mediaType: 'video', - playerSize: [640, 480], - }); - - events.emit(AUCTION_INIT, VIDEO_AUCTION); - - const trackers = medianetAnalytics.getVastTrackerHandler()(videoBidResponse, { - auction: VIDEO_AUCTION, - bidRequest: VIDEO_BID_REQUESTED.bids[0] - }); - expect(trackers).to.be.an('array'); - expect(trackers.length).to.equal(1); - expect(trackers[0].url).to.include('missing_bidrequest'); - }); - }); - - describe('Events', function () { - beforeEach(function () { - sandbox.stub(mnUtils, 'onHidden').callsFake(() => { - }) - medianetAnalytics.enableAnalytics({ - options: { - cid: 'test123' - } - }); - medianetAnalytics.clearlogsQueue(); - }); - afterEach(function () { - sandbox.restore(); - medianetAnalytics.disableAnalytics(); - }); - - it('can handle multi bid module', function (done) { - performMultiBidAuction(); - clock.tick(2000); - - waitForPromiseResolve(Promise.resolve()).then(() => { - const queue = medianetAnalytics.getlogsQueue(); - expect(queue.length).equals(1); - const multiBidLog = queue.map((log) => getQueryData(log, true))[0]; - expect(multiBidLog.pvnm).to.have.ordered.members(['-2', 'medianet', 'medianet']); - expect(multiBidLog.status).to.have.ordered.members(['1', '1', '1']); - done(); - }).catch(done); - }); - - it('should have all applicable sizes in request', function (done) { - performNoBidAuction(); - clock.tick(2000); - - waitForPromiseResolve(Promise.resolve()).then(() => { - const noBidLog = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log))[0]; - expect(noBidLog.mtype).to.have.ordered.members([encodeURIComponent('banner|native|video'), encodeURIComponent('banner|video|native')]); - expect(noBidLog.szs).to.have.ordered.members([encodeURIComponent('300x250|1x1|640x480'), encodeURIComponent('300x250|1x1|640x480')]); - expect(noBidLog.vplcmtt).to.equal('6'); - done(); - }).catch(done); - }); - - it('AP log should fire only once', function (done) { - performNoBidAuction(); - clock.tick(2000); - - waitForPromiseResolve(Promise.resolve()).then(() => { - const logs = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log, true)); - expect(logs[0]).to.exist; - expect(logs[0].lgtp).to.equal('APPR'); - done(); - }).catch(done); - }); - - it('should have no bid status', function (done) { - performNoBidAuction(); - clock.tick(2000); - - waitForPromiseResolve(Promise.resolve()).then(() => { - let noBidLog = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log)); - noBidLog = noBidLog[0]; - - expect(noBidLog.pvnm).to.have.ordered.members(['-2', 'medianet']); - expect(noBidLog.iwb).to.have.ordered.members(['0', '0']); - expect(noBidLog.status).to.have.ordered.members(['1', '2']); - expect(noBidLog.src).to.have.ordered.members(['client', 'client']); - expect(noBidLog.curr).to.have.ordered.members(['', '']); - expect(noBidLog.mtype).to.have.ordered.members([encodeURIComponent('banner|native|video'), encodeURIComponent('banner|video|native')]); - expect(noBidLog.ogbdp).to.have.ordered.members(['', '']); - expect(noBidLog.mpvid).to.have.ordered.members(['', '']); - expect(noBidLog.crid).to.have.ordered.members(['', '451466393']); - done(); - }).catch(done); - }); - - it('should have timeout status', function (done) { - performBidTimeoutAuction(); - clock.tick(2000); - - waitForPromiseResolve(Promise.resolve()).then(() => { - let timeoutLog = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log)); - timeoutLog = timeoutLog[0]; - - expect(timeoutLog.pvnm).to.have.ordered.members(['-2', 'medianet']); - expect(timeoutLog.iwb).to.have.ordered.members(['0', '0']); - expect(timeoutLog.status).to.have.ordered.members(['3', '3']); - expect(timeoutLog.src).to.have.ordered.members(['client', 'client']); - expect(timeoutLog.curr).to.have.ordered.members(['', '']); - expect(timeoutLog.mtype).to.have.ordered.members([encodeURIComponent('banner|native|video'), encodeURIComponent('banner|video|native')]); - expect(timeoutLog.ogbdp).to.have.ordered.members(['', '']); - expect(timeoutLog.mpvid).to.have.ordered.members(['', '']); - expect(timeoutLog.crid).to.have.ordered.members(['', '451466393']); - done(); - }).catch(done); - }); - - it('should have correct bid values after and before bidCmpAdjustment', function (done) { - const bidCopy = utils.deepClone(MOCK.MNET_BID_RESPONSE); - bidCopy.cpm = bidCopy.originalCpm * 0.8; // Simulate bidCpmAdjustment - - // Emit events to simulate an auction - events.emit(AUCTION_INIT, Object.assign({}, MOCK.AUCTION_INIT, {adUnits: MOCK.AD_UNITS})); - events.emit(BID_REQUESTED, MOCK.MNET_BID_REQUESTED); - events.emit(BID_RESPONSE, bidCopy); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.MNET_SET_TARGETING); - clock.tick(2000); - - waitForPromiseResolve(Promise.resolve()).then(() => { - const adjustedLog = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log))[0]; - - expect(adjustedLog.bdp[1]).to.equal(String(bidCopy.cpm)); - expect(adjustedLog.ogbdp[1]).to.equal(String(bidCopy.originalCpm)); - expect(adjustedLog.cbdp[1]).to.equal(String(bidCopy.cpm)); - expect(adjustedLog.dfpbd[1]).to.equal(String(deepAccess(bidCopy, 'adserverTargeting.hb_pb'))); - done(); - }).catch(done); - }); - - it('should pick winning bid if multibids with same request id', function (done) { - sandbox.stub(getGlobal(), 'getAdserverTargetingForAdUnitCode').returns({ - hb_pb: '2.299', - hb_adid: '3e6e4bce5c8fb3', - hb_pb_medianet: '2.299', - hb_adid_medianet: '3e6e4bce5c8fb3', - hb_pb_appnexus: '1.299', - hb_adid_appnexus: '3e6e4bce5c8fb4', - }); - performAuctionWithSameRequestIdBids(MOCK.COMMON_REQ_ID_BID_RESPONSES); - clock.tick(2000); - - waitForPromiseResolve(Promise.resolve()).then(() => { - const winningBid = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log)).filter(log => log.winner === '1')[0]; - expect(winningBid.adid).equals('3e6e4bce5c8fb3'); - medianetAnalytics.clearlogsQueue(); - - performAuctionWithSameRequestIdBids([...MOCK.COMMON_REQ_ID_BID_RESPONSES].reverse()); - clock.tick(2000); - - return waitForPromiseResolve(Promise.resolve()); - }).then(() => { - const winningBid = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log)).filter(log => log.winner === '1')[0]; - expect(winningBid.adid).equals('3e6e4bce5c8fb3'); - done(); - }).catch(done); - }); - - it('should pick winning bid if multibids with same request id and same time to respond', function (done) { - performAuctionWithSameRequestIdBids(MOCK.COMMON_REQ_ID_BID_RESPONSES_EQUAL_CPM); - clock.tick(2000); - - waitForPromiseResolve(Promise.resolve()).then(() => { - const winningBid = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log)).filter(log => log.winner === '1')[0]; - expect(winningBid.adid).equals('3e6e4bce5c8fb3'); - medianetAnalytics.clearlogsQueue(); - done(); - }).catch(done); - }); - - it('should ignore unknown winning bid and log error', function (done) { - performAuctionNoWin(); - events.emit(BID_WON, MOCK.BID_WON_UNKNOWN); - clock.tick(2000); - - waitForPromiseResolve(Promise.resolve()).then(() => { - const winningBids = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log)).filter(log => log.winner); - const errors = medianetAnalytics.getErrorQueue().map((log) => getQueryData(log)); - expect(winningBids.length).equals(0); - expect(errors.length).equals(1); - expect(errors[0].event).equals('winning_bid_absent'); - done(); - }).catch(done); - }); - - it('should have correct bid status for bid rejected', function (done) { - performBidRejectedAuction(); - clock.tick(2000); - - waitForPromiseResolve(Promise.resolve()).then(() => { - const bidRejectedLog = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log))[0]; - expect(bidRejectedLog.pvnm).to.have.ordered.members(['-2', 'medianet', 'medianet', 'medianet']); - expect(bidRejectedLog.status).to.have.ordered.members(['1', '1', '12', '12']); - done(); - }).catch(done); - }); - - it('should handle S2S auction correctly', function (done) { - performS2SAuction(); - clock.tick(2000); - - waitForPromiseResolve(Promise.resolve()).then(() => { - const queue = medianetAnalytics.getlogsQueue(); - const s2sLog = queue.map((log) => getQueryData(log, true))[0]; - - // Verify S2S source is recorded correctly - expect(s2sLog.src).to.equal('s2s'); - expect(s2sLog.pvnm).to.include('medianet'); - expect(s2sLog.status).to.include('1'); - expect(s2sLog.winner).to.equal('1'); - - done(); - }).catch(done); - }); - - it('should handle currency conversion from JPY to USD', function (done) { - const prebidGlobal = getGlobal(); - prebidGlobal.convertCurrency = prebidGlobal.convertCurrency || function () { - }; - const convertStub = sandbox.stub(prebidGlobal, 'convertCurrency'); - convertStub.withArgs(250, 'JPY', 'USD').returns(2.25); - - performCurrencyConversionAuction(); - clock.tick(2000); - - waitForPromiseResolve(Promise.resolve()).then(() => { - const queue = medianetAnalytics.getlogsQueue(); - expect(queue.length).equals(1); - const currencyLog = queue.map((log) => getQueryData(log, true))[0]; - - expect(currencyLog.curr).to.have.ordered.members(['', 'JPY', '']); - expect(currencyLog.ogbdp).to.have.ordered.members(['', '2.25', '']); - expect(currencyLog.bdp).to.have.ordered.members(['', '2.25', '']); - expect(currencyLog.bdp).to.have.ordered.members(['', '2.25', '']); - expect(convertStub.calledWith(250, 'JPY', 'USD')).to.be.true; - done(); - }).catch(done).finally(() => { - convertStub.restore(); - }); - }); - - it('should have winner log in standard auction', function () { - performBidWonAuction(); - - const winnerLog = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log)).filter((log) => log.winner); - expect(winnerLog.length).to.equal(1); - expect(winnerLog[0].lgtp).to.equal('RA'); - }); - - it('should have correct values in winner log', function () { - performBidWonAuction(); - - const winnerLog = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log)).filter((log) => log.winner); - expect(winnerLog[0]).to.include({ - winner: '1', - pvnm: 'medianet', - curr: 'USD', - src: 'client', - size: '300x250', - mtype: 'banner', - gdpr: '0', - cid: 'test123', - lper: '1', - ogbdp: '2.299', - flt: '1', - supcrid: 'div-gpt-ad-1460505748561-0', - mpvid: '123', - bidflr: '1.1' - }); - }); - - it('should have correct bid floor data in winner log', function (done) { - performBidWonAuction(); - const winnerLog = medianetAnalytics.getlogsQueue().map((log) => getQueryData(log)).filter((log) => log.winner); - expect(winnerLog[0]).to.include({ - winner: '1', - curr: 'USD', - ogbdp: '2.299', - bidflr: '1.1', - flrrule: 'banner', - flrdata: encodeURIComponent('ln=||skp=||sr=||fs=||enfj=true||enfd=') - }); - done(); - }); - - it('should log error on AD_RENDER_FAILED event', function () { - const errorData = { - reason: 'timeout', - message: 'Ad failed to render', - bid: { - auctionId: '8e0d5245-deb3-406c-96ca-9b609e077ff7', - adUnitCode: 'div-gpt-ad-1460505748561-0', - bidder: 'medianet', - creativeId: 'Test1' - } - }; - events.emit(AD_RENDER_FAILED, errorData); - - const errors = medianetAnalytics.getErrorQueue().map((log) => getQueryData(log)); - expect(errors.length).to.equal(1); - const relatedData = JSON.parse(decodeURIComponent(errors[0].rd)); - expect(errors[0].event).to.equal(AD_RENDER_FAILED); - expect(relatedData.reason).to.equal('timeout'); - expect(relatedData.message).to.equal('Ad failed to render'); - }); - - it('should log success on AD_RENDER_SUCCEEDED event', function () { - const successData = { - bid: { - auctionId: '8e0d5245-deb3-406c-96ca-9b609e077ff7', - adUnitCode: 'div-gpt-ad-1460505748561-0', - bidder: 'medianet', - creativeId: 'Test1' - } - }; - events.emit(AD_RENDER_SUCCEEDED, successData); - - const logs = medianetAnalytics.getErrorQueue().map((log) => getQueryData(log)); - expect(logs.length).to.equal(1); - expect(logs[0].event).to.equal(AD_RENDER_SUCCEEDED); - }); - - it('should log error on STALE_RENDER event', function () { - const staleData = { - auctionId: '8e0d5245-deb3-406c-96ca-9b609e077ff7', - adUnitCode: 'div-gpt-ad-1460505748561-0', - bidder: 'medianet', - creativeId: 'Test1', - adId: '3e6e4bce5c8fb3', - cpm: 2.299 - }; - events.emit(STALE_RENDER, staleData); - - const errors = medianetAnalytics.getErrorQueue().map((log) => getQueryData(log)); - expect(errors.length).to.equal(1); - const relatedData = JSON.parse(decodeURIComponent(errors[0].rd)); - expect(errors[0].event).to.equal(STALE_RENDER); - expect(relatedData.adId).to.equal('3e6e4bce5c8fb3'); - }); - }); -}); diff --git a/test/spec/modules/medianetBidAdapter_spec.js b/test/spec/modules/medianetBidAdapter_spec.js deleted file mode 100644 index c3c14f3d0..000000000 --- a/test/spec/modules/medianetBidAdapter_spec.js +++ /dev/null @@ -1,2490 +0,0 @@ -import {expect, assert} from 'chai'; -import {spec, EVENTS} from '../../../modules/medianetBidAdapter.js'; -import {POST_ENDPOINT} from '../../../libraries/medianetUtils/constants.js'; -import { makeSlot } from '../integration/faker/googletag.js'; -import { config } from '../../../src/config.js'; -import {server} from '../../mocks/xhr.js'; -import {resetWinDimensions} from '../../../src/utils.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -getGlobal().version = getGlobal().version || 'version'; -const VALID_BID_REQUEST = [{ - 'bidder': 'medianet', - 'params': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - ortb2Imp: { - ext: { - tid: '277b631f-92f5-4844-8b19-ea13c095d3f1' - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]], - } - }, - 'bidId': '28f8f8130a583e', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1, -}, { - 'bidder': 'medianet', - 'params': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-123', - ortb2Imp: { - ext: { - tid: 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 251]], - } - }, - 'sizes': [[300, 251]], - 'bidId': '3f97ca71b1e5c2', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1 -}]; - -const VALID_BID_REQUEST_WITH_CRID = [{ - 'bidder': 'medianet', - 'params': { - 'crid': 'crid', - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - ortb2Imp: { - ext: { - tid: '277b631f-92f5-4844-8b19-ea13c095d3f1', - } - }, - 'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]], - } - }, - 'bidId': '28f8f8130a583e', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1 -}, { - 'bidder': 'medianet', - 'params': { - 'crid': 'crid', - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-123', - ortb2Imp: { - ext: { - tid: 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 251]], - } - }, - 'sizes': [[300, 251]], - 'bidId': '3f97ca71b1e5c2', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1 -}]; -const VALID_BID_REQUEST_WITH_ORTB2 = [{ - 'bidder': 'medianet', - 'params': { - 'crid': 'crid', - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]], - } - }, - 'bidId': '28f8f8130a583e', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'ortb2Imp': { - 'ext': { - tid: '277b631f-92f5-4844-8b19-ea13c095d3f1', - 'data': {'pbadslot': '/12345/my-gpt-tag-0'} - } - }, - 'auctionsCount': 1 -}, { - 'bidder': 'medianet', - 'params': { - 'crid': 'crid', - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-123', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 251]], - } - }, - 'sizes': [[300, 251]], - 'bidId': '3f97ca71b1e5c2', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'ortb2Imp': { - 'ext': { - tid: 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - 'data': {'pbadslot': '/12345/my-gpt-tag-0'} - } - }, - 'auctionsCount': 1 -}]; - // Protected Audience API Request -const VALID_BID_REQUEST_WITH_AE_IN_ORTB2IMP = [{ - 'bidder': 'medianet', - 'params': { - 'crid': 'crid', - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]], - } - }, - 'bidId': '28f8f8130a583e', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'ortb2Imp': { - 'ext': { - 'tid': '277b631f-92f5-4844-8b19-ea13c095d3f1', - 'ae': 1 - } - }, - 'auctionsCount': 1 -}]; - -const VALID_BID_REQUEST_WITH_USERID = [{ - 'bidder': 'medianet', - 'params': { - 'crid': 'crid', - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - userId: { - britepoolid: '82efd5e1-816b-4f87-97f8-044f407e2911' - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - ortb2Imp: { - ext: { - tid: '277b631f-92f5-4844-8b19-ea13c095d3f1', - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]], - } - }, - 'bidId': '28f8f8130a583e', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1 -}, { - 'bidder': 'medianet', - 'params': { - 'crid': 'crid', - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-123', - ortb2Imp: { - ext: { - tid: 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 251]], - } - }, - 'sizes': [[300, 251]], - 'bidId': '3f97ca71b1e5c2', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1 -}]; -const VALID_BID_REQUEST_WITH_USERIDASEIDS = [{ - 'bidder': 'medianet', - 'params': { - 'crid': 'crid', - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - userIdAsEids: [{ - 'source': 'criteo.com', - 'uids': [ - { - 'id': 'VZME3l9ycFFORncwaGJRVUNtUzB1UVhpWVd5TElrR3A5SHVSWXAwSFVPJTJCWiUyRnV2UTBPWjZOZ1ZrWnN4SldxcWUlMkJhUnFmUVNzUVg4N1NsdW84SGpUU1BsUllQSnN5bERMdFdPM2pWVXAlMkZVSSUyQkZsJTJGcktlenpZaHp0YXlvU25INWRQQ2tXciUyRk9PQmdac3RHeG9adDNKVzlRWE51ZyUzRCUzRA', - 'atype': 1 - } - ] - } - ], - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - ortb2Imp: { - ext: { - tid: '277b631f-92f5-4844-8b19-ea13c095d3f1', - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]], - } - }, - 'bidId': '28f8f8130a583e', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1 -}, { - 'bidder': 'medianet', - 'params': { - 'crid': 'crid', - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-123', - ortb2Imp: { - ext: { - tid: 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 251]], - } - }, - 'sizes': [[300, 251]], - 'bidId': '3f97ca71b1e5c2', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1 -}]; - -const VALID_BID_REQUEST_INVALID_BIDFLOOR = [{ - 'bidder': 'medianet', - 'params': { - 'cid': 'customer_id', - 'bidfloor': 'abcdef', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - ortb2Imp: { - ext: { - tid: '277b631f-92f5-4844-8b19-ea13c095d3f1', - } - }, - 'sizes': [[300, 250]], - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]], - } - }, - 'bidId': '28f8f8130a583e', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1 -}, { - 'bidder': 'medianet', - 'params': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-123', - ortb2Imp: { - ext: { - tid: 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - } - }, - 'sizes': [[300, 251]], - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 251]], - } - }, - 'bidId': '3f97ca71b1e5c2', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1 -}]; -const VALID_NATIVE_BID_REQUEST = [{ - 'bidder': 'medianet', - 'params': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - ortb2Imp: { - ext: { - tid: '277b631f-92f5-4844-8b19-ea13c095d3f1', - } - }, - 'sizes': [[300, 250]], - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]], - } - }, - 'bidId': '28f8f8130a583e', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1, - 'nativeParams': { - 'image': { - 'required': true, - 'sizes': [ - 150, - 50 - ], - 'wmin': 50 - }, - 'title': { - 'required': true, - 'len': 80 - }, - 'sponsoredBy': { - 'required': true - }, - 'clickUrl': { - 'required': true - }, - 'body': { - 'required': true - }, - 'icon': { - 'required': true, - 'sizes': [ - 50, - 50 - ] - } - } -}, { - 'bidder': 'medianet', - 'params': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-123', - ortb2Imp: { - ext: { - tid: 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - } - }, - 'sizes': [[300, 251]], - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 251]], - } - }, - 'bidId': '3f97ca71b1e5c2', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1, - 'nativeParams': { - 'image': { - 'required': true, - 'sizes': [ - 150, - 50 - ], - 'wmin': 50 - }, - 'title': { - 'required': true, - 'len': 80 - }, - 'sponsoredBy': { - 'required': true - }, - 'clickUrl': { - 'required': true - }, - 'body': { - 'required': true - }, - 'icon': { - 'required': true, - 'sizes': [ - 50, - 50 - ] - } - } -}]; -const VALID_AUCTIONDATA = { - 'timeout': config.getConfig('bidderTimeout'), - 'refererInfo': { - referer: 'http://media.net/prebidtest', - stack: ['http://media.net/prebidtest'], - page: 'http://media.net/page', - domain: 'media.net', - topmostLocation: 'http://media.net/topmost', - reachedTop: true - } -}; -const VALID_PAYLOAD_INVALID_BIDFLOOR = { - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'topMostLocation': 'http://media.net/topmost', - 'isTop': true - }, - 'ext': { - 'customer_id': 'customer_id', - 'prebid_version': 'v' + '$prebid.version$', - 'gdpr_applies': false, - 'usp_applies': false, - 'coppa_applies': false, - 'screen': { - 'w': 1000, - 'h': 1000 - }, - 'vcoords': { - 'top_left': { - 'x': 50, - 'y': 100 - }, - 'bottom_right': { - 'x': 490, - 'y': 880 - } - } - }, - 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'imp': [{ - 'id': '28f8f8130a583e', - ortb2Imp: VALID_BID_REQUEST_INVALID_BIDFLOOR[0].ortb2Imp, - 'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1', - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-0', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-0' - }, - 'banner': [{ - 'w': 300, - 'h': 250 - }], - 'all': { - 'cid': 'customer_id', - 'bidfloor': 'abcdef', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }, { - 'id': '3f97ca71b1e5c2', - ortb2Imp: VALID_BID_REQUEST_INVALID_BIDFLOOR[1].ortb2Imp, - 'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-123', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-123' - }, - 'banner': [{ - 'w': 300, - 'h': 251 - }], - 'all': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }], - 'ortb2': {}, - 'tmax': config.getConfig('bidderTimeout') -}; -const VALID_PAYLOAD_NATIVE = { - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'topMostLocation': 'http://media.net/topmost', - 'isTop': true - }, - 'ext': { - 'customer_id': 'customer_id', - 'prebid_version': 'v' + '$prebid.version$', - 'gdpr_applies': false, - 'usp_applies': false, - 'coppa_applies': false, - 'screen': { - 'w': 1000, - 'h': 1000 - }, - 'vcoords': { - 'top_left': { - 'x': 50, - 'y': 100 - }, - 'bottom_right': { - 'x': 490, - 'y': 880 - } - } - }, - 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'imp': [{ - 'id': '28f8f8130a583e', - ortb2Imp: VALID_NATIVE_BID_REQUEST[0].ortb2Imp, - 'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1', - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-0', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-0' - }, - 'banner': [{ - 'w': 300, - 'h': 250 - }], - 'native': '{\"image\":{\"required\":true,\"sizes\":[150,50],\"wmin\":50},\"title\":{\"required\":true,\"len\":80},\"sponsoredBy\":{\"required\":true},\"clickUrl\":{\"required\":true},\"body\":{\"required\":true},\"icon\":{\"required\":true,\"sizes\":[50,50]}}', - 'all': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }, { - 'id': '3f97ca71b1e5c2', - ortb2Imp: VALID_NATIVE_BID_REQUEST[1].ortb2Imp, - 'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-123', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-123' - }, - 'banner': [{ - 'w': 300, - 'h': 251 - }], - 'native': '{\"image\":{\"required\":true,\"sizes\":[150,50],\"wmin\":50},\"title\":{\"required\":true,\"len\":80},\"sponsoredBy\":{\"required\":true},\"clickUrl\":{\"required\":true},\"body\":{\"required\":true},\"icon\":{\"required\":true,\"sizes\":[50,50]}}', - 'all': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }], - 'ortb2': {}, - 'tmax': config.getConfig('bidderTimeout') -}; -const VALID_PAYLOAD = { - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'topMostLocation': 'http://media.net/topmost', - 'isTop': true - }, - 'ext': { - 'customer_id': 'customer_id', - 'prebid_version': 'v' + '$prebid.version$', - 'gdpr_applies': false, - 'usp_applies': false, - 'coppa_applies': false, - 'screen': { - 'w': 1000, - 'h': 1000 - }, - 'vcoords': { - 'top_left': { - 'x': 50, - 'y': 100 - }, - 'bottom_right': { - 'x': 490, - 'y': 880 - } - } - }, - 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'imp': [{ - 'id': '28f8f8130a583e', - 'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1', - ortb2Imp: VALID_BID_REQUEST[0].ortb2Imp, - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-0', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-0' - }, - 'banner': [{ - 'w': 300, - 'h': 250 - }], - 'all': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }, { - 'id': '3f97ca71b1e5c2', - 'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - ortb2Imp: VALID_BID_REQUEST[1].ortb2Imp, - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-123', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-123' - }, - 'banner': [{ - 'w': 300, - 'h': 251 - }], - 'all': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }], - 'ortb2': {}, - 'tmax': config.getConfig('bidderTimeout') -}; -const VALID_PAYLOAD_WITH_USERID = { - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'topMostLocation': 'http://media.net/topmost', - 'isTop': true - }, - 'ext': { - 'customer_id': 'customer_id', - 'prebid_version': 'v' + '$prebid.version$', - 'gdpr_applies': false, - 'user_id': { - britepoolid: '82efd5e1-816b-4f87-97f8-044f407e2911' - }, - 'usp_applies': false, - 'coppa_applies': false, - 'screen': { - 'w': 1000, - 'h': 1000 - }, - 'vcoords': { - 'top_left': { - 'x': 50, - 'y': 100 - }, - 'bottom_right': { - 'x': 490, - 'y': 880 - } - } - }, - 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'imp': [{ - 'id': '28f8f8130a583e', - ortb2Imp: VALID_BID_REQUEST_WITH_USERID[0].ortb2Imp, - 'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1', - 'tagid': 'crid', - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-0', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-0' - }, - 'banner': [{ - 'w': 300, - 'h': 250 - }], - 'all': { - 'cid': 'customer_id', - 'crid': 'crid', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }, { - 'id': '3f97ca71b1e5c2', - ortb2Imp: VALID_BID_REQUEST_WITH_USERID[1].ortb2Imp, - 'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - 'tagid': 'crid', - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-123', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-123' - }, - 'banner': [{ - 'w': 300, - 'h': 251 - }], - 'all': { - 'cid': 'customer_id', - 'crid': 'crid', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }], - 'ortb2': {}, - 'tmax': config.getConfig('bidderTimeout') -}; -const VALID_PAYLOAD_WITH_USERIDASEIDS = { - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'topMostLocation': 'http://media.net/topmost', - 'isTop': true - }, - 'ext': { - 'customer_id': 'customer_id', - 'prebid_version': 'v' + '$prebid.version$', - 'gdpr_applies': false, - 'usp_applies': false, - 'coppa_applies': false, - 'screen': { - 'w': 1000, - 'h': 1000 - }, - 'vcoords': { - 'top_left': { - 'x': 50, - 'y': 100 - }, - 'bottom_right': { - 'x': 490, - 'y': 880 - } - } - }, - 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'imp': [{ - 'id': '28f8f8130a583e', - ortb2Imp: VALID_BID_REQUEST_WITH_USERID[0].ortb2Imp, - 'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1', - 'tagid': 'crid', - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-0', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-0' - }, - 'banner': [{ - 'w': 300, - 'h': 250 - }], - 'all': { - 'cid': 'customer_id', - 'crid': 'crid', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }, { - 'id': '3f97ca71b1e5c2', - ortb2Imp: VALID_BID_REQUEST_WITH_USERID[1].ortb2Imp, - 'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - 'tagid': 'crid', - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-123', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-123' - }, - 'banner': [{ - 'w': 300, - 'h': 251 - }], - 'all': { - 'cid': 'customer_id', - 'crid': 'crid', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }], - 'ortb2': { - 'user': { - 'ext': { - 'eids': [{ - 'source': 'criteo.com', - 'uids': [{ - 'id': 'VZME3l9ycFFORncwaGJRVUNtUzB1UVhpWVd5TElrR3A5SHVSWXAwSFVPJTJCWiUyRnV2UTBPWjZOZ1ZrWnN4SldxcWUlMkJhUnFmUVNzUVg4N1NsdW84SGpUU1BsUllQSnN5bERMdFdPM2pWVXAlMkZVSSUyQkZsJTJGcktlenpZaHp0YXlvU25INWRQQ2tXciUyRk9PQmdac3RHeG9adDNKVzlRWE51ZyUzRCUzRA', - 'atype': 1 - } - ] - }] - } - }, - }, - 'tmax': config.getConfig('bidderTimeout') -}; -const VALID_PAYLOAD_WITH_CRID = { - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'topMostLocation': 'http://media.net/topmost', - 'isTop': true - }, - 'ext': { - 'customer_id': 'customer_id', - 'prebid_version': 'v' + '$prebid.version$', - 'gdpr_applies': false, - 'usp_applies': false, - 'coppa_applies': true, - 'screen': { - 'w': 1000, - 'h': 1000 - }, - 'vcoords': { - 'top_left': { - 'x': 50, - 'y': 100 - }, - 'bottom_right': { - 'x': 490, - 'y': 880 - } - } - }, - 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'imp': [{ - 'id': '28f8f8130a583e', - ortb2Imp: VALID_BID_REQUEST_WITH_CRID[0].ortb2Imp, - 'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1', - 'tagid': 'crid', - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-0', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-0' - }, - 'banner': [{ - 'w': 300, - 'h': 250 - }], - 'all': { - 'cid': 'customer_id', - 'crid': 'crid', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }, { - 'id': '3f97ca71b1e5c2', - ortb2Imp: VALID_BID_REQUEST_WITH_CRID[1].ortb2Imp, - 'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - 'tagid': 'crid', - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-123', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-123' - }, - 'banner': [{ - 'w': 300, - 'h': 251 - }], - 'all': { - 'cid': 'customer_id', - 'crid': 'crid', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }], - 'ortb2': {}, - 'tmax': config.getConfig('bidderTimeout') -}; - // Protected Audience API Valid Payload -const VALID_PAYLOAD_PAAPI = { - 'site': { - 'domain': 'media.net', - 'page': 'http://media.net/prebidtest', - 'ref': 'http://media.net/prebidtest', - 'topMostLocation': 'http://media.net/topmost', - 'isTop': true - }, - 'ext': { - 'customer_id': 'customer_id', - 'prebid_version': 'v' + '$prebid.version$', - 'gdpr_applies': false, - 'usp_applies': false, - 'coppa_applies': false, - 'screen': { - 'w': 1000, - 'h': 1000 - }, - 'vcoords': { - 'top_left': { - 'x': 50, - 'y': 100 - }, - 'bottom_right': { - 'x': 490, - 'y': 880 - } - } - }, - 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'imp': [ - { - 'id': '28f8f8130a583e', - 'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1', - 'ext': { - 'ae': 1, - 'dfp_id': 'div-gpt-ad-1460505748561-0', - 'display_count': 1, - 'coordinates': { - 'top_left': { - 'x': 50, - 'y': 50 - }, - 'bottom_right': { - 'x': 100, - 'y': 100 - } - }, - 'viewability': 1, - 'visibility': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-0' - }, - 'all': { - 'cid': 'customer_id', - 'crid': 'crid', - 'site': { - 'domain': 'media.net', - 'isTop': true, - 'page': 'http://media.net/prebidtest', - 'ref': 'http://media.net/prebidtest' - } - }, - 'ortb2Imp': { - 'ext': { - 'tid': '277b631f-92f5-4844-8b19-ea13c095d3f1', - 'ae': 1 - } - }, - 'banner': [ - { - 'w': 300, - 'h': 250 - } - ], - 'tagid': 'crid' - } - ], - 'ortb2': {}, - 'tmax': 3000 -}; - -const VALID_VIDEO_BID_REQUEST = [{ - 'bidder': 'medianet', - 'params': { - 'cid': 'customer_id', - 'video': { - 'skipppable': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1', - 'mediaTypes': { - 'video': { - 'context': 'instream', - } - }, - 'bidId': '28f8f8130a583e', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1 -}]; - -const VALID_PAYLOAD_PAGE_META = (() => { - let PAGE_META; - try { - PAGE_META = JSON.parse(JSON.stringify(VALID_PAYLOAD)); - } catch (e) {} - PAGE_META.site = Object.assign(PAGE_META.site, { - 'canonical_url': 'http://localhost:9999/canonical-test', - }); - return PAGE_META; -})(); -const VALID_PARAMS = { - bidder: 'medianet', - params: { - cid: '8CUV090' - } -}; -const VALID_PARAMS_TS = { - bidder: 'trustedstack', - params: { - cid: 'TS012345' - } -}; -const PARAMS_MISSING = { - bidder: 'medianet', -}; -const PARAMS_MISSING_TS = { - bidder: 'trustedstack', -}; -const PARAMS_WITHOUT_CID = { - bidder: 'medianet', - params: {} -}; -const PARAMS_WITHOUT_CID_TS = { - bidder: 'trustedstack', - params: {} -}; -const PARAMS_WITH_INTEGER_CID = { - bidder: 'medianet', - params: { - cid: 8867587 - } -}; -const PARAMS_WITH_INTEGER_CID_TS = { - bidder: 'trustedstack', - params: { - cid: 8867587 - } -}; -const PARAMS_WITH_EMPTY_CID = { - bidder: 'medianet', - params: { - cid: '' - } -}; -const PARAMS_WITH_EMPTY_CID_TS = { - bidder: 'trustedstack', - params: { - cid: '' - } -}; -const SYNC_OPTIONS_BOTH_ENABLED = { - iframeEnabled: true, - pixelEnabled: true, -}; -const SYNC_OPTIONS_PIXEL_ENABLED = { - iframeEnabled: false, - pixelEnabled: true, -}; -const SYNC_OPTIONS_IFRAME_ENABLED = { - iframeEnabled: true, - pixelEnabled: false, -}; -const SERVER_CSYNC_RESPONSE = [{ - body: { - ext: { - csUrl: [{ - type: 'iframe', - url: 'iframe-url' - }, { - type: 'image', - url: 'pixel-url' - }] - } - } -}]; -const ENABLED_SYNC_IFRAME = [{ - type: 'iframe', - url: 'iframe-url' -}]; -const ENABLED_SYNC_PIXEL = [{ - type: 'image', - url: 'pixel-url' -}]; -const SERVER_RESPONSE_CPM_MISSING = { - body: { - 'id': 'd90ca32f-3877-424a-b2f2-6a68988df57a', - 'bidList': [{ - 'no_bid': false, - 'requestId': '27210feac00e96', - 'ad': 'ad', - 'width': 300, - 'height': 250, - 'creativeId': '375068987', - 'netRevenue': true - }], - 'ext': { - 'csUrl': [{ - 'type': 'image', - 'url': 'http://cs.media.net/cksync.php' - }, { - 'type': 'iframe', - 'url': 'http://contextual.media.net/checksync.php?&vsSync=1' - }] - } - } -}; -const SERVER_RESPONSE_CPM_ZERO = { - body: { - 'id': 'd90ca32f-3877-424a-b2f2-6a68988df57a', - 'bidList': [{ - 'no_bid': false, - 'requestId': '27210feac00e96', - 'ad': 'ad', - 'width': 300, - 'height': 250, - 'creativeId': '375068987', - 'netRevenue': true, - 'cpm': 0.0 - }], - 'ext': { - 'csUrl': [{ - 'type': 'image', - 'url': 'http://cs.media.net/cksync.php' - }, { - 'type': 'iframe', - 'url': 'http://contextual.media.net/checksync.php?&vsSync=1' - }] - } - } -}; -const SERVER_RESPONSE_NOBID = { - body: { - 'id': 'd90ca32f-3877-424a-b2f2-6a68988df57a', - 'bidList': [{ - 'no_bid': true, - 'requestId': '3a62cf7a853f84', - 'width': 0, - 'height': 0, - 'ttl': 0, - 'netRevenue': false - }], - 'ext': { - 'csUrl': [{ - 'type': 'image', - 'url': 'http://cs.media.net/cksync.php' - }, { - 'type': 'iframe', - 'url': 'http://contextual.media.net/checksync.php?&vsSync=1' - }] - } - } -}; -const SERVER_RESPONSE_NOBODY = { - -}; -const SERVER_RESPONSE_EMPTY_BIDLIST = { - body: { - 'id': 'd90ca32f-3877-424a-b2f2-6a68988df57a', - 'bidList': 'bid', - 'ext': { - 'csUrl': [{ - 'type': 'image', - 'url': 'http://cs.media.net/cksync.php' - }, { - 'type': 'iframe', - 'url': 'http://contextual.media.net/checksync.php?&vsSync=1' - }] - } - } - -}; -const SERVER_RESPONSE_VALID_BID = { - body: { - 'id': 'd90ca32f-3877-424a-b2f2-6a68988df57a', - 'bidList': [{ - 'no_bid': false, - 'requestId': '27210feac00e96', - 'ad': 'ad', - 'width': 300, - 'height': 250, - 'creativeId': '375068987', - 'netRevenue': true, - 'cpm': 0.1 - }], - 'ext': { - 'csUrl': [{ - 'type': 'image', - 'url': 'http://cs.media.net/cksync.php' - }, { - 'type': 'iframe', - 'url': 'http://contextual.media.net/checksync.php?&vsSync=1' - }] - } - } -}; - // Protected Audience API Response -const SERVER_RESPONSE_PAAPI = { - body: { - 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'bidList': [{ - 'no_bid': false, - 'requestId': '28f8f8130a583e', - 'ad': 'ad', - 'width': 300, - 'height': 250, - 'creativeId': 'crid', - 'netRevenue': true, - 'cpm': 0.1 - }], - 'ext': { - 'paApiAuctionConfigs': [ - { - 'bidId': '28f8f8130a583e', - 'config': { - 'seller': 'https://hbx.test.media.net', - 'decisionLogicUrl': 'https://hbx.test.media.net/decision-logic.js', - 'interestGroupBuyers': ['https://buyer.test.media.net'], - 'auctionSignals': { - 'logging_params': { - 'cid': 'customer_id', - 'crid': 'crid', - 'bid_uuid': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'browser_id': 2, - 'dfpid': 'div-gpt-ad-1460505748561-0' - }, - 'pvidLookup': { - 'https://buyer.test.media.net': { - 'pvid': '172', - 'seat': 'quantcast-qc1' - } - }, - 'bidFlr': 0.0 - }, - 'sellerTimout': 1000, - 'sellerSignals': { - 'callbackURL': 'https://test.com/paapi/v1/abcd' - }, - 'perBuyerSignals': { - 'https://buyer.test.media.net': [ 'test_buyer_signals' ] - }, - 'perBuyerTimeouts': { - '*': 200 - } - } - } - ], - 'csUrl': [{ - 'type': 'iframe', - 'url': 'http://contextual.media.net/checksync.php?&vsSync=1' - }] - } - } -}; - // Protected Audience API OpenRTB Response -const SERVER_RESPONSE_PAAPI_ORTB = { - body: { - 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'bidList': [{ - 'no_bid': false, - 'requestId': '28f8f8130a583e', - 'ad': 'ad', - 'width': 300, - 'height': 250, - 'creativeId': 'crid', - 'netRevenue': true, - 'cpm': 0.1 - }], - 'ext': { - 'igi': [{ - 'igs': [ - { - 'impid': '28f8f8130a583e', - 'bidId': '28f8f8130a583e', - 'config': { - 'seller': 'https://hbx.test.media.net', - 'decisionLogicUrl': 'https://hbx.test.media.net/decision-logic.js', - 'interestGroupBuyers': ['https://buyer.test.media.net'], - 'auctionSignals': { - 'logging_params': { - 'cid': 'customer_id', - 'crid': 'crid', - 'bid_uuid': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'browser_id': 2, - 'dfpid': 'div-gpt-ad-1460505748561-0' - }, - 'pvidLookup': { - 'https://buyer.test.media.net': { - 'pvid': '172', - 'seat': 'quantcast-qc1' - } - }, - 'bidFlr': 0.0 - }, - 'sellerTimout': 1000, - 'sellerSignals': { - 'callbackURL': 'https://test.com/paapi/v1/abcd' - }, - 'perBuyerSignals': { - 'https://buyer.test.media.net': [ 'test_buyer_signals' ] - }, - 'perBuyerTimeouts': { - '*': 200 - } - } - } - ], - }], - 'csUrl': [{ - 'type': 'iframe', - 'url': 'http://contextual.media.net/checksync.php?&vsSync=1' - }] - } - } -}; - -const SERVER_VIDEO_OUTSTREAM_RESPONSE_VALID_BID = { - body: { - 'id': 'd90ca32f-3877-424a-b2f2-6a68988df57a', - 'bidList': [{ - 'no_bid': false, - 'requestId': '27210feac00e96', - 'cpm': 12.00, - 'width': 640, - 'height': 480, - 'ttl': 180, - 'creativeId': '370637746', - 'netRevenue': true, - 'vastXml': '', - 'currency': 'USD', - 'dfp_id': 'video1', - 'mediaType': 'video', - 'vto': 5000, - 'mavtr': 10, - 'avp': true, - 'ap': true, - 'pl': true, - 'mt': true, - 'jslt': 3000, - 'context': 'outstream' - }], - 'ext': { - 'csUrl': [{ - 'type': 'image', - 'url': 'http://cs.media.net/cksync.php' - }, { - 'type': 'iframe', - 'url': 'http://contextual.media.net/checksync.php?&vsSync=1' - }] - } - } -}; -const SERVER_VALID_BIDS = [{ - 'no_bid': false, - 'requestId': '27210feac00e96', - 'ad': 'ad', - 'width': 300, - 'height': 250, - 'creativeId': '375068987', - 'netRevenue': true, - 'cpm': 0.1 -}]; -const BID_REQUEST_SIZE_AS_1DARRAY = [{ - 'bidder': 'medianet', - 'params': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - ortb2Imp: { - ext: { - tid: '277b631f-92f5-4844-8b19-ea13c095d3f1', - } - }, - 'sizes': [300, 250], - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]], - } - }, - 'bidId': '28f8f8130a583e', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1 -}, { - 'bidder': 'medianet', - 'params': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-123', - ortb2Imp: { - ext: { - tid: 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - } - }, - 'sizes': [300, 251], - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 251]], - } - }, - 'bidId': '3f97ca71b1e5c2', - 'bidderRequestId': '1e9b1f07797c1c', - 'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'auctionsCount': 1 -}]; -const VALID_BIDDER_REQUEST_WITH_GDPR = { - 'gdprConsent': { - 'consentString': 'consentString', - 'gdprApplies': true, - }, - 'uspConsent': '1NYN', - 'timeout': 3000, - refererInfo: { - referer: 'http://media.net/prebidtest', - stack: ['http://media.net/prebidtest'], - page: 'http://media.net/page', - domain: 'media.net', - topmostLocation: 'http://media.net/topmost', - reachedTop: true - } -}; -const VALID_PAYLOAD_FOR_GDPR = { - 'site': { - 'domain': 'media.net', - 'page': 'http://media.net/prebidtest', - 'ref': 'http://media.net/prebidtest', - 'topMostLocation': 'http://media.net/topmost', - 'isTop': true - }, - 'ext': { - 'customer_id': 'customer_id', - 'prebid_version': 'v' + '$prebid.version$', - 'gdpr_consent_string': 'consentString', - 'gdpr_applies': true, - 'usp_applies': true, - 'coppa_applies': false, - 'usp_consent_string': '1NYN', - 'screen': { - 'w': 1000, - 'h': 1000 - }, - 'vcoords': { - 'top_left': { - 'x': 50, - 'y': 100 - }, - 'bottom_right': { - 'x': 490, - 'y': 880 - } - } - }, - 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'imp': [{ - 'id': '28f8f8130a583e', - ortb2Imp: VALID_BID_REQUEST[0].ortb2Imp, - 'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1', - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-0', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-0' - }, - 'banner': [{ - 'w': 300, - 'h': 250 - }], - 'all': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }, { - 'id': '3f97ca71b1e5c2', - ortb2Imp: VALID_BID_REQUEST[1].ortb2Imp, - 'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-123', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-123' - }, - 'banner': [{ - 'w': 300, - 'h': 251 - }], - 'all': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }], - 'ortb2': {}, - 'tmax': 3000, -}; -const VALID_BIDDER_REQUEST_WITH_GPP_IN_ORTB2 = { - ortb2: { - regs: { - gpp: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', - gpp_sid: [5, 7] - } - }, - 'timeout': 3000, - refererInfo: { - referer: 'http://media.net/prebidtest', - stack: ['http://media.net/prebidtest'], - page: 'http://media.net/page', - domain: 'media.net', - topmostLocation: 'http://media.net/topmost', - reachedTop: true - } -}; -const VALID_PAYLOAD_FOR_GPP_ORTB2 = { - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'topMostLocation': 'http://media.net/topmost', - 'isTop': true - }, - 'ext': { - 'customer_id': 'customer_id', - 'prebid_version': 'v' + '$prebid.version$', - 'gdpr_applies': false, - 'usp_applies': false, - 'coppa_applies': false, - 'screen': { - 'w': 1000, - 'h': 1000 - }, - 'vcoords': { - 'top_left': { - 'x': 50, - 'y': 100 - }, - 'bottom_right': { - 'x': 490, - 'y': 880 - } - } - }, - 'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d', - 'imp': [{ - 'id': '28f8f8130a583e', - 'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1', - ortb2Imp: VALID_BID_REQUEST[0].ortb2Imp, - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-0', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-0' - }, - 'banner': [{ - 'w': 300, - 'h': 250 - }], - 'all': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }, { - 'id': '3f97ca71b1e5c2', - 'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822', - ortb2Imp: VALID_BID_REQUEST[1].ortb2Imp, - 'ext': { - 'dfp_id': 'div-gpt-ad-1460505748561-123', - 'visibility': 1, - 'viewability': 1, - 'coordinates': { - 'top_left': { - x: 50, - y: 50 - }, - 'bottom_right': { - x: 100, - y: 100 - } - }, - 'display_count': 1, - 'adUnitCode': 'div-gpt-ad-1460505748561-123' - }, - 'banner': [{ - 'w': 300, - 'h': 251 - }], - 'all': { - 'cid': 'customer_id', - 'site': { - 'page': 'http://media.net/prebidtest', - 'domain': 'media.net', - 'ref': 'http://media.net/prebidtest', - 'isTop': true - } - } - }], - 'ortb2': { - 'regs': { - 'gpp': 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', - 'gpp_sid': [5, 7], - } - }, - 'tmax': config.getConfig('bidderTimeout') -}; -describe('Media.net bid adapter', function () { - let sandbox; - beforeEach(function () { - sandbox = sinon.createSandbox(); - sandbox.stub(window.top, 'innerHeight').value(780) - sandbox.stub(window.top, 'innerWidth').value(440) - sandbox.stub(window.top, 'scrollY').value(100) - sandbox.stub(window.top, 'scrollX').value(50) - }); - - afterEach(function () { - resetWinDimensions(); - sandbox.restore(); - }); - - describe('isBidRequestValid', function () { - it('should accept valid bid params', function () { - const isValid = spec.isBidRequestValid(VALID_PARAMS); - expect(isValid).to.equal(true); - }); - - it('should reject bid if cid is not present', function () { - const isValid = spec.isBidRequestValid(PARAMS_WITHOUT_CID); - expect(isValid).to.equal(false); - }); - - it('should reject bid if cid is not a string', function () { - const isValid = spec.isBidRequestValid(PARAMS_WITH_INTEGER_CID); - expect(isValid).to.equal(false); - }); - - it('should reject bid if cid is a empty string', function () { - const isValid = spec.isBidRequestValid(PARAMS_WITH_EMPTY_CID); - expect(isValid).to.equal(false); - }); - - it('should have missing params', function () { - const isValid = spec.isBidRequestValid(PARAMS_MISSING); - expect(isValid).to.equal(false); - }); - }); - - describe('buildRequests', function () { - beforeEach(function () { - getGlobal().medianetGlobals = {}; - - const documentStub = sandbox.stub(document, 'getElementById'); - const boundingRect = { - top: 50, - left: 50, - bottom: 100, - right: 100 - }; - documentStub.withArgs('div-gpt-ad-1460505748561-123').returns({ - getBoundingClientRect: () => boundingRect - }); - documentStub.withArgs('div-gpt-ad-1460505748561-0').returns({ - getBoundingClientRect: () => boundingRect - }); - const windowSizeStub = sandbox.stub(spec, 'getWindowSize'); - windowSizeStub.returns({ - w: 1000, - h: 1000 - }); - }); - - it('should build valid payload on bid', function () { - const requestObj = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); - expect(JSON.parse(requestObj.data)).to.deep.include(VALID_PAYLOAD); - }); - - it('should accept size as a one dimensional array', function () { - const bidReq = spec.buildRequests(BID_REQUEST_SIZE_AS_1DARRAY, VALID_AUCTIONDATA); - expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD); - }); - - it('should ignore bidfloor if not a valid number', function () { - const bidReq = spec.buildRequests(VALID_BID_REQUEST_INVALID_BIDFLOOR, VALID_AUCTIONDATA); - expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_INVALID_BIDFLOOR); - }); - - it('should add gdpr to response ext', function () { - const bidReq = spec.buildRequests(VALID_BID_REQUEST, VALID_BIDDER_REQUEST_WITH_GDPR); - expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_FOR_GDPR); - }); - - it('should have gpp params in ortb2', function () { - const bidReq = spec.buildRequests(VALID_BID_REQUEST, VALID_BIDDER_REQUEST_WITH_GPP_IN_ORTB2); - expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_FOR_GPP_ORTB2); - }); - - it('should parse params for native request', function () { - const bidReq = spec.buildRequests(VALID_NATIVE_BID_REQUEST, VALID_AUCTIONDATA); - expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_NATIVE); - }); - - it('should parse params for video request', function () { - const bidReq = spec.buildRequests(VALID_VIDEO_BID_REQUEST, VALID_AUCTIONDATA); - expect(JSON.stringify(bidReq.data)).to.include('instream'); - }); - - it('should have valid crid present in bid request', function() { - sandbox.stub(config, 'getConfig').callsFake((key) => { - const config = { - 'coppa': true - }; - return config[key]; - }); - const bidreq = spec.buildRequests(VALID_BID_REQUEST_WITH_CRID, VALID_AUCTIONDATA); - expect(JSON.parse(bidreq.data)).to.deep.equal(VALID_PAYLOAD_WITH_CRID); - }); - - it('should have valid ortb2Imp param present in bid request', function() { - let bidreq = spec.buildRequests(VALID_BID_REQUEST_WITH_ORTB2, VALID_AUCTIONDATA); - let actual = JSON.parse(bidreq.data).imp[0].ortb2Imp; - const expected = VALID_BID_REQUEST_WITH_ORTB2[0].ortb2Imp - assert.equal(JSON.stringify(actual), JSON.stringify(expected)) - - bidreq = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); - actual = JSON.parse(bidreq.data).imp[0].ortb2Imp; - expect(actual).to.deep.equal(VALID_BID_REQUEST[0].ortb2Imp); - }); - - it('should have userid in bid request', function () { - const bidReq = spec.buildRequests(VALID_BID_REQUEST_WITH_USERID, VALID_AUCTIONDATA); - expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_WITH_USERID); - }); - - it('should have userIdAsEids in bid request', function () { - const bidReq = spec.buildRequests(VALID_BID_REQUEST_WITH_USERIDASEIDS, VALID_AUCTIONDATA); - expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_WITH_USERIDASEIDS); - }); - - it('should have valid payload when PAAPI is enabled', function () { - const bidReq = spec.buildRequests(VALID_BID_REQUEST_WITH_AE_IN_ORTB2IMP, {...VALID_AUCTIONDATA, paapi: {enabled: true}}); - expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_PAAPI); - }); - - it('should send whatever is set in ortb2imp.ext.ae in all bid requests when PAAPI is enabled', function () { - const bidReq = spec.buildRequests(VALID_BID_REQUEST_WITH_AE_IN_ORTB2IMP, {...VALID_AUCTIONDATA, paapi: {enabled: true}}); - const data = JSON.parse(bidReq.data); - expect(data).to.deep.equal(VALID_PAYLOAD_PAAPI); - expect(data.imp[0].ext).to.have.property('ae'); - expect(data.imp[0].ext.ae).to.equal(1); - }); - - describe('build requests: when page meta-data is available', () => { - beforeEach(() => { - spec.clearPageMeta(); - }); - - it('should pass canonical, twitter and fb parameters if available', () => { - const documentStub = sandbox.stub(window.top.document, 'querySelector'); - documentStub.withArgs('link[rel="canonical"]').returns({ - href: 'http://localhost:9999/canonical-test' - }); - documentStub.withArgs('meta[property="og:url"]').returns({ - content: 'http://localhost:9999/fb-test' - }); - documentStub.withArgs('meta[name="twitter:url"]').returns({ - content: 'http://localhost:9999/twitter-test' - }); - const bidReq = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); - expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_PAGE_META); - }); - }); - }); - - describe('slot visibility', function () { - let documentStub; - beforeEach(function () { - const windowSizeStub = sandbox.stub(spec, 'getWindowSize'); - windowSizeStub.returns({ - w: 1000, - h: 1000 - }); - documentStub = sandbox.stub(document, 'getElementById'); - }); - it('slot visibility should be 2 and ratio 0 when ad unit is BTF', function () { - const boundingRect = { - top: 1010, - left: 1010, - bottom: 1050, - right: 1050 - }; - documentStub.withArgs('div-gpt-ad-1460505748561-123').returns({ - getBoundingClientRect: () => boundingRect - }); - documentStub.withArgs('div-gpt-ad-1460505748561-0').returns({ - getBoundingClientRect: () => boundingRect - }); - - const bidReq = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); - const data = JSON.parse(bidReq.data); - expect(data.imp[0].ext.visibility).to.equal(2); - expect(data.imp[0].ext.viewability).to.equal(0); - }); - it('slot visibility should be 2 and ratio < 0.5 when ad unit is partially inside viewport', function () { - const boundingRect = { - top: 990, - left: 990, - bottom: 1050, - right: 1050 - }; - documentStub.withArgs('div-gpt-ad-1460505748561-123').returns({ - getBoundingClientRect: () => boundingRect - }); - documentStub.withArgs('div-gpt-ad-1460505748561-0').returns({ - getBoundingClientRect: () => boundingRect - }); - const bidReq = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); - const data = JSON.parse(bidReq.data); - expect(data.imp[0].ext.visibility).to.equal(2); - expect(data.imp[0].ext.viewability).to.equal(100 / 75000); - }); - it('slot visibility should be 1 and ratio > 0.5 when ad unit mostly in viewport', function () { - const boundingRect = { - top: 800, - left: 800, - bottom: 1050, - right: 1050 - }; - documentStub.withArgs('div-gpt-ad-1460505748561-123').returns({ - getBoundingClientRect: () => boundingRect - }); - documentStub.withArgs('div-gpt-ad-1460505748561-0').returns({ - getBoundingClientRect: () => boundingRect - }); - const bidReq = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); - const data = JSON.parse(bidReq.data); - expect(data.imp[0].ext.visibility).to.equal(1); - expect(data.imp[0].ext.viewability).to.equal(40000 / 75000); - }); - it('co-ordinates should not be sent and slot visibility should be 0 when ad unit is not present', function () { - const bidReq = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); - const data = JSON.parse(bidReq.data); - expect(data.imp[1].ext).to.not.have.ownPropertyDescriptor('viewability'); - expect(data.imp[1].ext.visibility).to.equal(0); - }); - it('slot visibility should be calculable even in case of adUnitPath', function () { - const code = '/19968336/header-bid-tag-0'; - const divId = 'div-gpt-ad-1460505748561-0'; - window.googletag.pubads().setSlots([makeSlot({ code, divId })]); - - const boundingRect = { - top: 1010, - left: 1010, - bottom: 1050, - right: 1050 - }; - documentStub.withArgs(divId).returns({ - getBoundingClientRect: () => boundingRect - }); - documentStub.withArgs('div-gpt-ad-1460505748561-123').returns({ - getBoundingClientRect: () => boundingRect - }); - - const bidRequest = [{...VALID_BID_REQUEST[0], adUnitCode: code}] - const bidReq = spec.buildRequests(bidRequest, VALID_AUCTIONDATA); - const data = JSON.parse(bidReq.data); - expect(data.imp[0].ext.visibility).to.equal(2); - expect(data.imp[0].ext.viewability).to.equal(0); - }); - }); - - describe('getUserSyncs', function () { - it('should exclude iframe syncs if iframe is disabled', function () { - const userSyncs = spec.getUserSyncs(SYNC_OPTIONS_PIXEL_ENABLED, SERVER_CSYNC_RESPONSE); - expect(userSyncs).to.deep.equal(ENABLED_SYNC_PIXEL); - }); - - it('should exclude pixel syncs if pixel is disabled', function () { - const userSyncs = spec.getUserSyncs(SYNC_OPTIONS_IFRAME_ENABLED, SERVER_CSYNC_RESPONSE); - expect(userSyncs).to.deep.equal(ENABLED_SYNC_IFRAME); - }); - - it('should choose iframe sync urls if both sync options are enabled', function () { - const userSyncs = spec.getUserSyncs(SYNC_OPTIONS_BOTH_ENABLED, SERVER_CSYNC_RESPONSE); - expect(userSyncs).to.deep.equal(ENABLED_SYNC_IFRAME); - }); - - it('should have empty user sync array', function() { - const userSyncs = spec.getUserSyncs(SYNC_OPTIONS_IFRAME_ENABLED, {}); - expect(userSyncs).to.deep.equal([]); - }); - }); - - describe('interpretResponse', function () { - it('should not push bid response if cpm missing', function () { - const validBids = []; - const bids = spec.interpretResponse(SERVER_RESPONSE_CPM_MISSING, []); - expect(bids).to.deep.equal(validBids); - }); - - it('should not push bid response if cpm 0', function () { - const validBids = []; - const bids = spec.interpretResponse(SERVER_RESPONSE_CPM_ZERO, []); - expect(bids).to.deep.equal(validBids); - }); - - it('should not push response if no-bid', function () { - const validBids = []; - const bids = spec.interpretResponse(SERVER_RESPONSE_NOBID, []); - expect(bids).to.deep.equal(validBids); - }); - - it('should have empty bid response', function() { - const bids = spec.interpretResponse(SERVER_RESPONSE_NOBODY, []); - expect(bids).to.deep.equal([]); - }); - - it('should have valid bids', function () { - const bids = spec.interpretResponse(SERVER_RESPONSE_VALID_BID, []); - expect(bids).to.deep.equal(SERVER_VALID_BIDS); - }); - - it('should have empty bid list', function() { - const validBids = []; - const bids = spec.interpretResponse(SERVER_RESPONSE_EMPTY_BIDLIST, []); - expect(bids).to.deep.equal(validBids); - }); - - it('should return paapi if PAAPI response is received', function() { - const response = spec.interpretResponse(SERVER_RESPONSE_PAAPI, []); - expect(response).to.have.property('bids'); - expect(response).to.have.property('paapi'); - expect(response.paapi[0]).to.deep.equal(SERVER_RESPONSE_PAAPI.body.ext.paApiAuctionConfigs[0]); - }); - - it('should return paapi if openRTB PAAPI response received', function () { - const response = spec.interpretResponse(SERVER_RESPONSE_PAAPI_ORTB, []); - expect(response).to.have.property('bids'); - expect(response).to.have.property('paapi'); - expect(response.paapi[0]).to.deep.equal(SERVER_RESPONSE_PAAPI_ORTB.body.ext.igi[0].igs[0]) - }); - - it('should have the correlation between paapi[0].bidId and bidreq.imp[0].id', function() { - const bidReq = spec.buildRequests(VALID_BID_REQUEST_WITH_AE_IN_ORTB2IMP, {...VALID_AUCTIONDATA, paapi: {enabled: true}}); - const bidRes = spec.interpretResponse(SERVER_RESPONSE_PAAPI, []); - expect(bidRes.paapi[0].bidId).to.equal(JSON.parse(bidReq.data).imp[0].id) - }); - - it('should have the correlation between paapi[0].bidId and bidreq.imp[0].id for openRTB response', function() { - const bidReq = spec.buildRequests(VALID_BID_REQUEST_WITH_AE_IN_ORTB2IMP, {...VALID_AUCTIONDATA, paapi: {enabled: true}}); - const bidRes = spec.interpretResponse(SERVER_RESPONSE_PAAPI_ORTB, []); - expect(bidRes.paapi[0].bidId).to.equal(JSON.parse(bidReq.data).imp[0].id) - }); - }); - - describe('onTimeout', function () { - it('onTimeout exist as a function', () => { - assert.typeOf(spec.onTimeout, 'function'); - }); - it('should send timeout data correctly', function () { - const timeoutData = [{ - bidder: 'medianet', - bidId: 'mnet-4644-442a-b5e0-93f268cf8d19', - adUnitCode: 'adUnit-code', - timeout: 3000, - auctionId: '12a34b56c' - }]; - sandbox.stub(window.navigator, 'sendBeacon').returns(false); - - spec.onTimeout(timeoutData); - const reqBody = new URLSearchParams(server.requests[0].requestBody); - - assert.equal(server.requests[0].method, 'POST'); - assert.equal(server.requests[0].url, POST_ENDPOINT); - assert.equal(reqBody.get('event'), EVENTS.TIMEOUT_EVENT_NAME); - assert.equal(reqBody.get('rd'), timeoutData[0].timeout.toString()); - assert.equal(reqBody.get('acid[]'), timeoutData[0].auctionId); - }); - }); - - describe('onBidWon', function () { - it('onBidWon exist as a function', () => { - assert.typeOf(spec.onBidWon, 'function'); - }); - it('should send winning bid data correctly', function () { - const bid = { - bidder: 'medianet', - bidId: 'mnet-4644-442a-b5e0-93f268cf8d19', - adUnitCode: 'adUnit-code', - timeout: 3000, - auctionId: '12a34b56c', - cpm: 12.24 - }; - sandbox.stub(window.navigator, 'sendBeacon').returns(false); - - spec.onBidWon(bid); - const reqBody = new URLSearchParams(server.requests[0].requestBody); - - assert.equal(server.requests[0].method, 'POST'); - assert.equal(server.requests[0].url, POST_ENDPOINT); - assert.equal(reqBody.get('event'), EVENTS.BID_WON_EVENT_NAME); - assert.equal(reqBody.get('value'), bid.cpm.toString()); - assert.equal(reqBody.get('acid[]'), bid.auctionId); - }); - }); - - describe('onSetTargeting', function () { - it('onSetTargeting exist as a function', () => { - assert.typeOf(spec.onSetTargeting, 'function'); - }); - it('should send targeting data correctly', function () { - const bid = { - bidder: 'medianet', - bidId: 'mnet-4644-442a-b5e0-93f268cf8d19', - adUnitCode: 'adUnit-code', - timeout: 3000, - auctionId: '12a34b56c', - cpm: 12.24 - }; - sandbox.stub(window.navigator, 'sendBeacon').returns(false); - sandbox.stub(config, 'getConfig').withArgs('enableSendAllBids').returns(false); - - spec.onSetTargeting(bid); - const reqBody = new URLSearchParams(server.requests[0].requestBody); - - assert.equal(server.requests[0].method, 'POST'); - assert.equal(server.requests[0].url, POST_ENDPOINT); - assert.equal(reqBody.get('event'), EVENTS.SET_TARGETING); - assert.equal(reqBody.get('value'), bid.cpm.toString()); - assert.equal(reqBody.get('acid[]'), bid.auctionId); - }); - }); - - describe('onBidderError', function () { - it('onBidderError exist as a function', () => { - assert.typeOf(spec.onBidderError, 'function'); - }); - it('should send bidderError data correctly', function () { - const error = { - reason: {message: 'Failed to fetch', status: 500}, - timedOut: true, - status: 0 - } - const bids = [{ - bidder: 'medianet', - bidId: 'mnet-4644-442a-b5e0-93f268cf8d19', - adUnitCode: 'adUnit-code', - timeout: 3000, - auctionId: '12a34b56c', - cpm: 12.24 - }]; - sandbox.stub(window.navigator, 'sendBeacon').returns(false); - - spec.onBidderError({error, bidderRequest: {bids}}); - const reqBody = new URLSearchParams(server.requests[0].requestBody); - - assert.equal(server.requests[0].method, 'POST'); - assert.equal(server.requests[0].url, POST_ENDPOINT); - assert.equal(reqBody.get('event'), EVENTS.BIDDER_ERROR); - assert.equal(reqBody.get('rd'), `timedOut:${error.timedOut}|status:${error.status}|message:${error.reason.message}`); - assert.equal(reqBody.get('acid[]'), bids[0].auctionId); - }); - }); - - it('context should be outstream', function () { - const bids = spec.interpretResponse(SERVER_VIDEO_OUTSTREAM_RESPONSE_VALID_BID, []); - expect(bids[0].context).to.equal('outstream'); - }); - describe('buildRequests floor tests', function () { - let floor; - const getFloor = function(req) { - return floor[req.mediaType]; - }; - beforeEach(function () { - floor = { - 'banner': { - 'currency': 'USD', - 'floor': 1 - } - }; - getGlobal().medianetGlobals = {}; - - const documentStub = sandbox.stub(document, 'getElementById'); - const boundingRect = { - top: 50, - left: 50, - bottom: 100, - right: 100 - }; - documentStub.withArgs('div-gpt-ad-1460505748561-123').returns({ - getBoundingClientRect: () => boundingRect - }); - documentStub.withArgs('div-gpt-ad-1460505748561-0').returns({ - getBoundingClientRect: () => boundingRect - }); - const windowSizeStub = sandbox.stub(spec, 'getWindowSize'); - windowSizeStub.returns({ - w: 1000, - h: 1000 - }); - VALID_BID_REQUEST[0].getFloor = getFloor; - }); - - it('should build valid payload with floor', function () { - let requestObj = spec.buildRequests(VALID_BID_REQUEST, VALID_AUCTIONDATA); - requestObj = JSON.parse(requestObj.data); - expect(requestObj.imp[0].hasOwnProperty('bidfloors')).to.equal(true); - }); - }); - - describe('isBidRequestValid trustedstack', function () { - it('should accept valid bid params', function () { - const isValid = spec.isBidRequestValid(VALID_PARAMS_TS); - expect(isValid).to.equal(true); - }); - - it('should reject bid if cid is not present', function () { - const isValid = spec.isBidRequestValid(PARAMS_WITHOUT_CID_TS); - expect(isValid).to.equal(false); - }); - - it('should reject bid if cid is not a string', function () { - const isValid = spec.isBidRequestValid(PARAMS_WITH_INTEGER_CID_TS); - expect(isValid).to.equal(false); - }); - - it('should reject bid if cid is a empty string', function () { - const isValid = spec.isBidRequestValid(PARAMS_WITH_EMPTY_CID_TS); - expect(isValid).to.equal(false); - }); - - it('should have missing params', function () { - const isValid = spec.isBidRequestValid(PARAMS_MISSING_TS); - expect(isValid).to.equal(false); - }); - }); - - describe('interpretResponse trustedstack', function () { - it('should not push response if no-bid', function () { - const validBids = []; - const bids = spec.interpretResponse(SERVER_RESPONSE_NOBID, []); - expect(bids).to.deep.equal(validBids); - }); - - it('should have empty bid response', function() { - const bids = spec.interpretResponse(SERVER_RESPONSE_NOBODY, []); - expect(bids).to.deep.equal([]); - }); - - it('should have valid bids', function () { - const bids = spec.interpretResponse(SERVER_RESPONSE_VALID_BID, []); - expect(bids).to.deep.equal(SERVER_VALID_BIDS); - }); - - it('should have empty bid list', function() { - const validBids = []; - const bids = spec.interpretResponse(SERVER_RESPONSE_EMPTY_BIDLIST, []); - expect(bids).to.deep.equal(validBids); - }); - }); -}); diff --git a/test/spec/modules/medianetRtdProvider_spec.js b/test/spec/modules/medianetRtdProvider_spec.js deleted file mode 100644 index ffd8109eb..000000000 --- a/test/spec/modules/medianetRtdProvider_spec.js +++ /dev/null @@ -1,146 +0,0 @@ -import * as medianetRTD from '../../../modules/medianetRtdProvider.js'; -import * as sinon from 'sinon'; -import { assert } from 'chai'; - -let sandbox; -let setDataSpy; -let getTargetingDataSpy; -let onPrebidRequestBidSpy; - -const conf = { - dataProviders: [{ - 'name': 'medianet', - 'params': { - 'cid': 'customer_id', - } - }] -}; - -describe('medianet realtime module', function () { - beforeEach(function () { - sandbox = sinon.createSandbox(); - window.mnjs = window.mnjs || {}; - window.mnjs.que = window.mnjs.que || []; - window.mnjs.setData = setDataSpy = sandbox.spy(); - window.mnjs.getTargetingData = getTargetingDataSpy = sandbox.spy(); - window.mnjs.onPrebidRequestBid = onPrebidRequestBidSpy = sandbox.spy(); - }); - - afterEach(function () { - sandbox.restore(); - window.mnjs = {}; - }); - - it('init should return false when customer id is passed', function () { - assert.equal(medianetRTD.medianetRtdModule.init({}), false); - }); - - it('init should return true when customer id is passed', function () { - assert.equal(medianetRTD.medianetRtdModule.init(conf.dataProviders[0]), true); - }); - - it('init should pass config to js when loaded', function () { - medianetRTD.medianetRtdModule.init(conf.dataProviders[0]); - - const command = window.mnjs.que.pop(); - assert.isFunction(command); - command(); - - assert.equal(setDataSpy.called, true); - assert.equal(setDataSpy.args[0][0].name, 'initIRefresh'); - }); - - it('auctionInit should pass information to js when loaded', function () { - const auctionObject = {adUnits: []}; - medianetRTD.medianetRtdModule.onAuctionInitEvent(auctionObject); - - const command = window.mnjs.que.pop(); - assert.isFunction(command); - command(); - - assert.equal(setDataSpy.called, true); - assert.equal(setDataSpy.args[0][0].name, 'auctionInit'); - assert.deepEqual(setDataSpy.args[0][0].data, {auction: auctionObject}); - }); - - describe('getTargeting should work correctly', function () { - it('should return empty if not loaded', function () { - window.mnjs.loaded = false; - assert.deepEqual(medianetRTD.medianetRtdModule.getTargetingData([], {}, {}, {}), {}); - }); - - it('should return ad unit codes when ad units are present', function () { - const adUnitCodes = ['code1', 'code2']; - assert.deepEqual(medianetRTD.medianetRtdModule.getTargetingData(adUnitCodes, {}, {}, {}), { - code1: {'mnadc': 'code1'}, - code2: {'mnadc': 'code2'}, - }); - }); - - it('should call mnjs.getTargetingData if loaded', function () { - window.mnjs.loaded = true; - medianetRTD.medianetRtdModule.getTargetingData([], {}, {}, {}); - assert.equal(getTargetingDataSpy.called, true); - }); - }); - - describe('getBidRequestData should work correctly', function () { - it('callback should be called when we are not interested in request', function () { - const requestBidsProps = { - adUnits: [{ - code: 'code1', bids: [], - }], - adUnitCodes: ['code1'], - }; - const callbackSpy = sandbox.spy(); - medianetRTD.medianetRtdModule.getBidRequestData(requestBidsProps, callbackSpy, conf.dataProviders[0], {}); - - const command = window.mnjs.que.pop(); - assert.isFunction(command); - command(); - - assert.equal(onPrebidRequestBidSpy.called, true, 'onPrebidRequest should always be called'); - assert.equal(callbackSpy.called, true, 'when onPrebidRequest returns nothing callback should be called immediately'); - }); - - it('we should wait for callback till onComplete', function () { - const requestBidsProps = { - adUnits: [{ - code: 'code1', bids: [], - }], - adUnitCodes: ['code1'], - }; - - const refreshInformation = { - mnrf: '1', - mnrfc: 2, - }; - - const callbackSpy = sandbox.spy(); - const onCompleteSpy = sandbox.spy(); - window.mnjs.onPrebidRequestBid = onPrebidRequestBidSpy = () => { - onPrebidRequestBidSpy.called = true; - return {onComplete: onCompleteSpy}; - }; - medianetRTD.medianetRtdModule.getBidRequestData(requestBidsProps, callbackSpy, conf.dataProviders[0], {}); - - const command = window.mnjs.que.pop(); - assert.isFunction(command); - command(); - - assert.equal(callbackSpy.called, false, 'callback should not be called, as we are returning a request from onPrebidRequestBid'); - assert.equal(onPrebidRequestBidSpy.called, true, 'onPrebidRequestBid should be called once'); - assert.equal(onCompleteSpy.called, true, 'onComplete should be passed callback'); - assert.isFunction(onCompleteSpy.args[0][0], 'onCompleteSpy first argument error callback should be a function'); - assert.isFunction(onCompleteSpy.args[0][1], 'onCompleteSpy second argument success callback should be a function'); - onCompleteSpy.args[0][0](); - assert.equal(callbackSpy.callCount, 1, 'callback should be called when error callback is triggered'); - onCompleteSpy.args[0][1]({}, { - 'code1': {ext: {refresh: refreshInformation}} - }); - assert.equal(callbackSpy.callCount, 2, 'callback should be called when success callback is triggered'); - assert.isObject(requestBidsProps.adUnits[0].ortb2Imp, 'ORTB object should be set'); - assert.deepEqual(requestBidsProps.adUnits[0].ortb2Imp.ext.refresh, refreshInformation, 'ORTB should have refresh information should be set'); - }); - }); -}); diff --git a/test/spec/modules/mediasniperBidAdapter_spec.js b/test/spec/modules/mediasniperBidAdapter_spec.js deleted file mode 100644 index 6a08bc4e3..000000000 --- a/test/spec/modules/mediasniperBidAdapter_spec.js +++ /dev/null @@ -1,498 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/mediasniperBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import * as utils from 'src/utils.js'; -import { BANNER } from '../../../src/mediaTypes.js'; - -const DEFAULT_CURRENCY = 'RUB'; -const DEFAULT_BID_TTL = 360; - -describe('mediasniperBidAdapter', function () { - const adapter = newBidder(spec); - let utilsMock; - let sandbox; - - const bid = { - bidder: 'mediasniper', - params: { siteid: 'testSiteID', placementId: '12345' }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - }, - }, - adUnitCode: 'div-gpt-ad-1460505748561-0', - transactionId: '47789656-9e5c-4250-b7e0-2ce4cbe71a55', - sizes: [ - [300, 250], - [300, 600], - ], - bidId: '299320f4de980d', - bidderRequestId: '1c1b642f803242', - auctionId: '84212956-c377-40e8-b000-9885a06dc692', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - }; - - const bidderRequest = { - bidderCode: 'mediasniper', - auctionId: '84212956-c377-40e8-b000-9885a06dc692', - bidderRequestId: '1c1b642f803242', - bids: [bid], - auctionStart: 1620973766319, - timeout: 1000, - refererInfo: { - referer: - 'https://local.url/integrationExamples/gpt/hello_world.html?pbjs_debug=true', - reachedTop: true, - isAmp: false, - numIframes: 0, - stack: [ - 'https://local.url/integrationExamples/gpt/hello_world.html?pbjs_debug=true', - ], - canonicalUrl: null, - }, - start: 1620973766325, - }; - - beforeEach(function () { - utilsMock = sinon.mock(utils); - sandbox = sinon.createSandbox(); - }); - - afterEach(function () { - utilsMock.restore(); - sandbox.restore(); - }); - - describe('isBidRequestValid', function () { - it('should returns true when bid is provided with params', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should returns false when bid is provided with empty params', function () { - const noParamsBid = { - bidder: 'mediasniper', - params: {}, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - }, - }, - adUnitCode: 'div-gpt-ad-1460505748561-0', - transactionId: '47789656-9e5c-4250-b7e0-2ce4cbe71a55', - sizes: [ - [300, 250], - [300, 600], - ], - bidId: '299320f4de980d', - }; - - expect(spec.isBidRequestValid(noParamsBid)).to.equal(false); - }); - - it('should returns false when bid is falsy or empty', function () { - const emptyBid = {}; - expect(spec.isBidRequestValid()).to.equal(false); - expect(spec.isBidRequestValid(false)).to.equal(false); - expect(spec.isBidRequestValid(emptyBid)).to.equal(false); - }); - - it('should return false when no sizes', function () { - const bannerNoSizeBid = { - bidder: 'mediasniper', - params: { placementId: '123' }, - mediaTypes: { - banner: {}, - }, - }; - - expect(spec.isBidRequestValid(bannerNoSizeBid)).to.equal(false); - }); - - it('should return false when empty sizes', function () { - const bannerEmptySizeBid = { - bidder: 'mediasniper', - params: { placementId: '123' }, - mediaTypes: { - banner: { sizes: [] }, - }, - }; - - expect(spec.isBidRequestValid(bannerEmptySizeBid)).to.equal(false); - }); - - it('should return false when mediaType is not supported', function () { - const bannerVideoBid = { - bidder: 'mediasniper', - params: { placementId: '123' }, - mediaTypes: { - video: {}, - }, - }; - - expect(spec.isBidRequestValid(bannerVideoBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('should create imp for supported mediaType only', function () { - const bidRequests = [utils.deepClone(bid)]; - const bidderRequestCopy = utils.deepClone(bidderRequest); - - bidderRequestCopy.bids = bidRequests[0]; - - const request = spec.buildRequests(bidRequests, bidderRequestCopy); - const data = JSON.parse(request.data); - - expect(data.imp.length).to.equal(1); - expect(data.imp[0].banner).to.exist; - }); - - it('should fill pmp only if dealid exists', function () { - const bidRequests = [utils.deepClone(bid)]; - const bidderRequestCopy = utils.deepClone(bidderRequest); - - bidRequests[0].params.dealid = '123'; - - const request = spec.buildRequests(bidRequests, bidderRequestCopy); - const data = JSON.parse(request.data); - - expect(data.imp.length).to.equal(1); - expect(data.imp[0].pmp).to.exist; - expect(data.imp[0].pmp.deals).to.exist; - expect(data.imp[0].pmp.deals.length).to.equal(1); - expect(data.imp[0].pmp.deals[0].id).to.equal( - bidRequests[0].params.dealid - ); - }); - - it('should fill site only if referer exists', function () { - const bidRequests = [utils.deepClone(bid)]; - const bidderRequestCopy = utils.deepClone(bidderRequest); - - bidderRequestCopy.refererInfo = {}; - - const request = spec.buildRequests(bidRequests, bidderRequestCopy); - const data = JSON.parse(request.data); - - expect(data.site.domain).to.not.exist; - expect(data.site.page).to.not.exist; - expect(data.site.ref).to.not.exist; - }); - - it('should fill site only if referer exists', function () { - const bidRequests = [utils.deepClone(bid)]; - const bidderRequestCopy = utils.deepClone(bidderRequest); - - bidderRequestCopy.refererInfo = null; - - const request = spec.buildRequests(bidRequests, bidderRequestCopy); - const data = JSON.parse(request.data); - - expect(data.site.domain).to.not.exist; - expect(data.site.page).to.not.exist; - expect(data.site.ref).to.not.exist; - }); - - it('should get expected properties with default values (no params set)', function () { - const bidRequests = [utils.deepClone(bid)]; - const request = spec.buildRequests(bidRequests, bidderRequest); - const data = JSON.parse(request.data); - - // openRTB 2.5 - expect(data.cur[0]).to.equal(DEFAULT_CURRENCY); - expect(data.id).to.exist; - - expect(data.imp.length).to.equal(1); - expect(data.imp[0].id).to.equal(bidRequests[0].bidId); - expect(data.imp[0].banner.w).to.equal(300); - expect(data.imp[0].banner.h).to.equal(250); - expect(data.imp[0].banner.format[0].w).to.equal(300); - expect(data.imp[0].banner.format[0].h).to.equal(250); - expect(data.imp[0].banner.format[1].w).to.equal(300); - expect(data.imp[0].banner.format[1].h).to.equal(600); - expect(data.imp[0].banner.topframe).to.equal(0); - expect(data.imp[0].banner.pos).to.equal(0); - }); - - it('should get expected properties with values from params', function () { - const bidRequests = [utils.deepClone(bid)]; - bidRequests[0].params = { - pos: 2, - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].banner.pos).to.equal(2); - }); - - describe('PriceFloors module support', function () { - it('should not set `imp[]bidfloor` property when priceFloors module is not available', function () { - const bidRequests = [bid]; - const request = spec.buildRequests(bidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].banner).to.exist; - expect(data.imp[0].bidfloor).to.not.exist; - }); - - it('should not set `imp[]bidfloor` property when priceFloors module returns false', function () { - const bidWithPriceFloors = utils.deepClone(bid); - - bidWithPriceFloors.getFloor = () => { - return false; - }; - - const bidRequests = [bidWithPriceFloors]; - const request = spec.buildRequests(bidRequests, bidderRequest); - const data = JSON.parse(request.data); - - expect(data.imp[0].banner).to.exist; - expect(data.imp[0].bidfloor).to.not.exist; - }); - - it('should get the highest floorPrice found when bid have several mediaTypes', function () { - const getFloorTest = (options) => { - switch (options.mediaType) { - case BANNER: - return { floor: 1, currency: DEFAULT_CURRENCY }; - default: - return false; - } - }; - - const bidWithPriceFloors = utils.deepClone(bid); - - bidWithPriceFloors.mediaTypes.video = { - playerSize: [600, 480], - }; - - bidWithPriceFloors.getFloor = getFloorTest; - - const bidRequests = [bidWithPriceFloors]; - const request = spec.buildRequests(bidRequests, bidderRequest); - const data = JSON.parse(request.data); - - expect(data.imp[0].banner).to.exist; - expect(data.imp[0].bidfloor).to.equal(1); - }); - }); - }); - - describe('intrepretResponse', function () { - const rawServerResponse = { - body: { - id: '60839f99-d5f2-3ab3-b6ac-736b4fe9d0ae', - seatbid: [ - { - bid: [ - { - id: '60839f99-d5f2-3ab3-b6ac-736b4fe9d0ae_0_0', - impid: '1', - price: 58.01, - adid: 'string-id', - cid: 'string-id', - crid: 'string-id', - nurl: 'https://local.url/notif?index=ab-cd-ef&price=${AUCTION_PRICE}', - w: 300, - h: 250, - adomain: ['domain.io'], - adm: '', - }, - ], - seat: '', - }, - ], - cur: DEFAULT_CURRENCY, - ext: { protocol: '5.3' }, - }, - }; - - it('Returns empty array if no bid', function () { - const request = ''; - const response01 = spec.interpretResponse( - { body: { seatbid: [{ bid: [] }] } }, - request - ); - const response02 = spec.interpretResponse( - { body: { seatbid: [] } }, - request - ); - const response03 = spec.interpretResponse( - { body: { seatbid: null } }, - request - ); - const response04 = spec.interpretResponse( - { body: { seatbid: null } }, - request - ); - const response05 = spec.interpretResponse({ body: {} }, request); - const response06 = spec.interpretResponse({}, request); - - expect(response01.length).to.equal(0); - expect(response02.length).to.equal(0); - expect(response03.length).to.equal(0); - expect(response04.length).to.equal(0); - expect(response05.length).to.equal(0); - expect(response06.length).to.equal(0); - }); - - describe('Build banner response', function () { - it('Retrurn successful response', function () { - const request = ''; - const response = spec.interpretResponse(rawServerResponse, request); - - expect(response.length).to.equal(1); - expect(response[0].requestId).to.equal( - rawServerResponse.body.seatbid[0].bid[0].impid - ); - expect(response[0].cpm).to.equal( - rawServerResponse.body.seatbid[0].bid[0].price - ); - expect(response[0].width).to.equal( - rawServerResponse.body.seatbid[0].bid[0].w - ); - expect(response[0].height).to.equal( - rawServerResponse.body.seatbid[0].bid[0].h - ); - expect(response[0].creativeId).to.equal( - rawServerResponse.body.seatbid[0].bid[0].crid - ); - expect(response[0].dealId).to.equal(null); - expect(response[0].currency).to.equal(rawServerResponse.body.cur); - expect(response[0].netRevenue).to.equal(true); - expect(response[0].ttl).to.equal(DEFAULT_BID_TTL); - expect(response[0].ad).to.equal( - rawServerResponse.body.seatbid[0].bid[0].adm - ); - expect(response[0].mediaType).to.equal(BANNER); - expect(response[0].burl).to.equal( - rawServerResponse.body.seatbid[0].bid[0].nurl - ); - expect(response[0].meta).to.deep.equal({ - advertiserDomains: rawServerResponse.body.seatbid[0].bid[0].adomain, - mediaType: BANNER, - }); - }); - - it('should use adid if no crid', function () { - const raw = { - body: { - seatbid: [ - { - bid: [ - { - adid: 'string-id', - }, - ], - }, - ], - }, - }; - const response = spec.interpretResponse(raw, ''); - - expect(response[0].creativeId).to.equal( - raw.body.seatbid[0].bid[0].adid - ); - }); - - it('should use id if no crid or adid', function () { - const raw = { - body: { - seatbid: [ - { - bid: [ - { - id: '60839f99-d5f2-3ab3-b6ac-736b4fe9d0ae_0_0', - }, - ], - }, - ], - }, - }; - const response = spec.interpretResponse(raw, ''); - - expect(response[0].creativeId).to.equal(raw.body.seatbid[0].bid[0].id); - }); - - it('should use 0 if no cpm', function () { - const raw = { - body: { - seatbid: [ - { - bid: [{}], - }, - ], - }, - }; - const response = spec.interpretResponse(raw, ''); - - expect(response[0].cpm).to.equal(0); - }); - - it('should use dealid if exists', function () { - const raw = { - body: { - seatbid: [ - { - bid: [{ dealid: '123' }], - }, - ], - }, - }; - const response = spec.interpretResponse(raw, ''); - - expect(response[0].dealId).to.equal(raw.body.seatbid[0].bid[0].dealid); - }); - - it('should use DEFAULT_CURRENCY if no cur', function () { - const raw = { - body: { - seatbid: [ - { - bid: [{}], - }, - ], - }, - }; - const response = spec.interpretResponse(raw, ''); - - expect(response[0].currency).to.equal(DEFAULT_CURRENCY); - }); - }); - }); - - describe('onBidWon', function () { - beforeEach(function () { - sinon.stub(utils, 'triggerPixel'); - }); - - afterEach(function () { - utils.triggerPixel.restore(); - }); - - it('Should not trigger pixel if bid does not contain burl', function () { - const result = spec.onBidWon({}); - expect(result).to.be.undefined; - expect(utils.triggerPixel.callCount).to.equal(0); - }); - - it('Should trigger pixel if bid.burl exists', function () { - const result = spec.onBidWon({ - cpm: 4.2, - burl: 'https://example.com/p=${AUCTION_PRICE}&foo=bar', - }); - - expect(utils.triggerPixel.callCount).to.equal(1); - expect(utils.triggerPixel.firstCall.args[0]).to.be.equal( - 'https://example.com/p=4.2&foo=bar' - ); - }); - }); -}); diff --git a/test/spec/modules/mediasquareBidAdapter_spec.js b/test/spec/modules/mediasquareBidAdapter_spec.js deleted file mode 100644 index caa22f4da..000000000 --- a/test/spec/modules/mediasquareBidAdapter_spec.js +++ /dev/null @@ -1,299 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/mediasquareBidAdapter.js'; -import { server } from 'test/mocks/xhr.js'; - -describe('MediaSquare bid adapter tests', function () { - var DEFAULT_PARAMS = [{ - adUnitCode: 'banner-div', - bidId: 'aaaa1234', - auctionId: 'bbbb1234', - ortb2Imp: { - ext: { - tid: 'cccc1234', - } - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - bidder: 'mediasquare', - params: { - owner: 'test', - code: 'publishername_atf_desktop_rg_pave' - }, - }]; - var VIDEO_PARAMS = [{ - adUnitCode: 'banner-div', - bidId: 'aaaa1234', - auctionId: 'bbbb1234', - transactionId: 'cccc1234', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480], - mimes: ['video/mp4'], - } - }, - bidder: 'mediasquare', - params: { - owner: 'test', - code: 'publishername_atf_desktop_rg_pave' - }, - }]; - var NATIVE_PARAMS = [{ - adUnitCode: 'banner-div', - bidId: 'aaaa1234', - auctionId: 'bbbb1234', - transactionId: 'cccc1234', - mediaTypes: { - native: { - title: { - required: true, - len: 80 - }, - } - }, - bidder: 'mediasquare', - params: { - owner: 'test', - code: 'publishername_atf_desktop_rg_pave' - }, - }]; - var FLOORS_PARAMS = [{ - adUnitCode: 'banner-div', - bidId: 'aaaa1234', - auctionId: 'bbbb1234', - transactionId: 'cccc1234', - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - bidder: 'mediasquare', - params: { - owner: 'test', - code: 'publishername_atf_desktop_rg_pave' - }, - sizes: [[300, 250]], - getFloor: function (a) { return { currency: 'USD', floor: 1.0 }; }, - }]; - var BID_RESPONSE = {'body': { - 'responses': [{ - 'transaction_id': 'cccc1234', - 'cpm': 22.256608, - 'width': 300, - 'height': 250, - 'creative_id': '158534630', - 'currency': 'USD', - 'originalCpm': 25.0123, - 'originalCurrency': 'USD', - 'net_revenue': true, - 'ttl': 300, - 'ad': '< --- creative code --- >', - 'bidder': 'msqClassic', - 'code': 'test/publishername_atf_desktop_rg_pave', - 'bid_id': 'aaaa1234', - 'adomain': ['test.com'], - 'context': 'instream', - 'increment': 1.0, - 'ova': 'cleared', - 'dsa': { - 'behalf': 'some-behalf', - 'paid': 'some-paid', - 'transparency': [{ - 'domain': 'test.com', - 'dsaparams': [1, 2, 3] - }], - 'adrender': 1 - } - }], - }}; - - const DEFAULT_OPTIONS = { - ortb2: { - regs: { - ext: { - dsa: { - dsarequired: '1', - pubrender: '2', - datatopub: '3', - transparency: [{ - domain: 'test.com', - dsaparams: [1, 2, 3] - }] - } - } - } - }, - userIdAsEids: [{ - "source": "superid.com", - "uids": [{ - "id": "12345678", - "atype": 1 - }] - }], - gdprConsent: { - gdprApplies: true, - consentString: 'BOzZdA0OzZdA0AGABBENDJ-AAAAvh7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__79__3z3_9pxP78k89r7337Mw_v-_v-b7JCPN_Y3v-8Kg', - vendorData: {} - }, - refererInfo: { - referer: 'https://www.prebid.org', - canonicalUrl: 'https://www.prebid.org/the/link/to/the/page' - }, - uspConsent: '111222333', - userId: { 'id5id': { uid: '1111' } }, - schain: { - 'ver': '1.0', - 'complete': 1, - 'nodes': [{ - 'asi': 'exchange1.com', - 'sid': '1234', - 'hp': 1, - 'rid': 'bid-request-1', - 'name': 'publisher', - 'domain': 'publisher.com' - }] - }, - }; - it('Verify build request', function () { - const request = spec.buildRequests(DEFAULT_PARAMS, DEFAULT_OPTIONS); - expect(request).to.have.property('url').and.to.equal('https://pbs-front.mediasquare.fr/msq_prebid'); - expect(request).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request.data); - expect(requestContent.codes[0]).to.have.property('owner').and.to.equal('test'); - expect(requestContent.codes[0]).to.have.property('code').and.to.equal('publishername_atf_desktop_rg_pave'); - expect(requestContent.codes[0]).to.have.property('adunit').and.to.equal('banner-div'); - expect(requestContent.codes[0]).to.have.property('bidId').and.to.equal('aaaa1234'); - expect(requestContent.codes[0]).not.to.have.property('auctionId'); - expect(requestContent.codes[0]).not.to.have.property('transactionId'); - expect(requestContent.codes[0]).to.have.property('mediatypes').exist; - expect(requestContent.codes[0]).to.have.property('floor').exist; - expect(requestContent.codes[0]).to.have.property('ortb2Imp').exist; - expect(requestContent).to.have.property('ortb2').exist; - expect(requestContent.eids).exist; - expect(requestContent.eids).to.have.lengthOf(1); - expect(requestContent.codes[0].floor).to.deep.equal({}); - expect(requestContent).to.have.property('dsa'); - const requestfloor = spec.buildRequests(FLOORS_PARAMS, DEFAULT_OPTIONS); - const responsefloor = JSON.parse(requestfloor.data); - expect(responsefloor.codes[0]).to.have.property('floor').exist; - expect(responsefloor.codes[0].floor).to.have.property('300x250').and.to.have.property('floor').and.to.equal(1); - expect(responsefloor.codes[0].floor).to.have.property('*'); - }); - - it('Verify parse response', function () { - const request = spec.buildRequests(DEFAULT_PARAMS, DEFAULT_OPTIONS); - const response = spec.interpretResponse(BID_RESPONSE, request); - expect(response).to.have.lengthOf(1); - const bid = response[0]; - expect(bid.cpm).to.equal(22.256608); - expect(bid.ad).to.equal('< --- creative code --- >'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creativeId).to.equal('158534630'); - expect(bid.currency).to.equal('USD'); - expect(bid.netRevenue).to.equal(true); - expect(bid.ttl).to.equal(300); - expect(bid.requestId).to.equal('aaaa1234'); - expect(bid.mediasquare).to.exist; - expect(bid.mediasquare.bidder).to.exist; - expect(bid.mediasquare.bidder).to.equal('msqClassic'); - expect(bid.mediasquare.context).to.exist; - expect(bid.mediasquare.context).to.equal('instream'); - expect(bid.mediasquare.increment).to.exist; - expect(bid.mediasquare.increment).to.equal(1.0); - expect(bid.mediasquare.code).to.equal([DEFAULT_PARAMS[0].params.owner, DEFAULT_PARAMS[0].params.code].join('/')); - expect(bid.mediasquare.ova).to.exist.and.to.equal('cleared'); - expect(bid.meta).to.exist; - expect(bid.meta.advertiserDomains).to.exist; - expect(bid.meta.advertiserDomains).to.have.lengthOf(1); - expect(bid.meta.dsa).to.exist; - }); - it('Verifies match', function () { - const request = spec.buildRequests(DEFAULT_PARAMS, DEFAULT_OPTIONS); - BID_RESPONSE.body.responses[0].match = true; - const response = spec.interpretResponse(BID_RESPONSE, request); - const bid = response[0]; - expect(bid.mediasquare.match).to.exist; - expect(bid.mediasquare.match).to.equal(true); - }); - it('Verifies hasConsent', function () { - const request = spec.buildRequests(DEFAULT_PARAMS, DEFAULT_OPTIONS); - BID_RESPONSE.body.responses[0].hasConsent = true; - const response = spec.interpretResponse(BID_RESPONSE, request); - const bid = response[0]; - expect(bid.mediasquare.hasConsent).to.exist; - expect(bid.mediasquare.hasConsent).to.equal(true); - }); - it('Verifies bidder code', function () { - expect(spec.code).to.equal('mediasquare'); - }); - - it('Verifies bidder aliases', function () { - expect(spec.aliases).to.have.lengthOf(1); - expect(spec.aliases[0]).to.equal('msq'); - }); - it('Verifies if bid request valid', function () { - expect(spec.isBidRequestValid(DEFAULT_PARAMS[0])).to.equal(true); - }); - it('Verifies bid won', function () { - const request = spec.buildRequests(DEFAULT_PARAMS, DEFAULT_OPTIONS); - BID_RESPONSE.body.responses[0].match = true - BID_RESPONSE.body.responses[0].hasConsent = true; - const response = spec.interpretResponse(BID_RESPONSE, request); - const won = spec.onBidWon(response[0]); - expect(won).to.equal(true); - expect(server.requests.length).to.equal(1); - const message = JSON.parse(server.requests[0].requestBody); - expect(message).to.have.property('increment').exist; - expect(message).to.have.property('increment').and.to.equal('1'); - expect(message).to.have.property('ova').and.to.equal('cleared'); - }); - it('Verifies user sync without cookie in bid response', function () { - var syncs = spec.getUserSyncs({}, [BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.have.lengthOf(0); - }); - it('Verifies user sync with cookies in bid response', function () { - BID_RESPONSE.body.cookies = [{'type': 'image', 'url': 'http://www.cookie.sync.org/'}]; - var syncs = spec.getUserSyncs({}, [BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0]).to.have.property('type').and.to.equal('image'); - expect(syncs[0]).to.have.property('url').and.to.equal('http://www.cookie.sync.org/'); - }); - it('Verifies user sync with no bid response', function() { - var syncs = spec.getUserSyncs({}, null, DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.have.lengthOf(0); - }); - it('Verifies user sync with no bid body response', function() { - let syncs = spec.getUserSyncs({}, [], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.have.lengthOf(0); - syncs = spec.getUserSyncs({}, [{}], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.have.lengthOf(0); - }); - it('Verifies native in bid response', function () { - const request = spec.buildRequests(NATIVE_PARAMS, DEFAULT_OPTIONS); - BID_RESPONSE.body.responses[0].native = {'title': 'native title'}; - const response = spec.interpretResponse(BID_RESPONSE, request); - expect(response).to.have.lengthOf(1); - const bid = response[0]; - expect(bid).to.have.property('native'); - delete BID_RESPONSE.body.responses[0].native; - }); - it('Verifies video in bid response', function () { - const request = spec.buildRequests(VIDEO_PARAMS, DEFAULT_OPTIONS); - BID_RESPONSE.body.responses[0].video = {'xml': 'my vast XML', 'url': 'my vast url'}; - const response = spec.interpretResponse(BID_RESPONSE, request); - expect(response).to.have.lengthOf(1); - const bid = response[0]; - expect(bid).to.have.property('vastXml'); - expect(bid).to.have.property('vastUrl'); - expect(bid).to.have.property('renderer'); - delete BID_RESPONSE.body.responses[0].video; - }); -}); diff --git a/test/spec/modules/mgidBidAdapter_spec.js b/test/spec/modules/mgidBidAdapter_spec.js deleted file mode 100644 index f6c2cc0ba..000000000 --- a/test/spec/modules/mgidBidAdapter_spec.js +++ /dev/null @@ -1,1036 +0,0 @@ -import {expect} from 'chai'; -import { spec, storage } from 'modules/mgidBidAdapter.js'; -import { version } from 'package.json'; -import * as utils from '../../../src/utils.js'; -import {USERSYNC_DEFAULT_CONFIG} from '../../../src/userSync.js'; -import {config} from '../../../src/config.js'; - -describe('Mgid bid adapter', function () { - let sandbox; - let logErrorSpy; - let logWarnSpy; - beforeEach(function () { - sandbox = sinon.createSandbox(); - logErrorSpy = sinon.spy(utils, 'logError'); - logWarnSpy = sinon.spy(utils, 'logWarn'); - }); - - afterEach(function () { - sandbox.restore(); - utils.logError.restore(); - utils.logWarn.restore(); - }); - const screenHeight = screen.height; - const screenWidth = screen.width; - const dnt = (navigator.doNotTrack === 'yes' || navigator.doNotTrack === '1' || navigator.msDoNotTrack === '1') ? 1 : 0; - const language = navigator.language ? 'language' : 'userLanguage'; - let lang = navigator[language].split('-')[0]; - if (lang.length !== 2 && lang.length !== 3) { - lang = ''; - } - const secure = window.location.protocol === 'https:' ? 1 : 0; - const mgid_ver = spec.VERSION; - const utcOffset = (new Date()).getTimezoneOffset().toString(); - - it('should expose gvlid', function() { - expect(spec.gvlid).to.equal(358) - }); - - describe('isBidRequestValid', function () { - const sbid = { - 'adUnitCode': 'div', - 'bidder': 'mgid', - 'params': { - 'property': '10433394', - 'zone': 'zone' - }, - }; - - it('should not accept bid without required params', function () { - const isValid = spec.isBidRequestValid(sbid); - expect(isValid).to.equal(false); - }); - - it('should return false when params are not passed', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.params = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when valid params are not passed', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.params = {accountId: '', placementId: ''}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when valid params are not passed', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.adUnitCode = ''; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - bid.params = {accountId: 2, placementId: 1}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when adUnitCode not passed', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.adUnitCode = ''; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - bid.params = {accountId: 2, placementId: 1}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when valid params are passed as nums', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.adUnitCode = 'div'; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - bid.params = {accountId: 2, placementId: 1}; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when valid params are not passed', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.mediaTypes = { - native: { - sizes: [[300, 250]] - } - }; - bid.params = {accountId: '0', placementId: '00'}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when valid mediaTypes are not passed', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.params = {accountId: '1', placementId: '1'}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when valid mediaTypes.banner are not passed', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.params = {accountId: '1', placementId: '1'}; - bid.mediaTypes = { - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when valid mediaTypes.banner.sizes are not passed', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.params = {accountId: '1', placementId: '1'}; - bid.mediaTypes = { - sizes: [] - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when valid mediaTypes.banner.sizes are not valid', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.params = {accountId: '1', placementId: '1'}; - bid.mediaTypes = { - sizes: [300, 250] - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when valid params are passed as strings', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.adUnitCode = 'div'; - bid.params = {accountId: '1', placementId: '1'}; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when valid mediaTypes.native is not object', function () { - const bid = Object.assign({}, sbid); - bid.params = {accountId: '1', placementId: '1'}; - bid.mediaTypes = { - native: [] - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when mediaTypes.native is empty object', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.params = {accountId: '1', placementId: '1'}; - bid.mediaTypes = { - native: {} - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when mediaTypes.native is invalid object', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.params = {accountId: '1', placementId: '1'}; - bid.mediaTypes = { - native: { - image: { - sizes: [80, 80] - }, - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when mediaTypes.native has unsupported required asset', function () { - const bid = Object.assign({}, sbid); - bid.params = {accountId: '2', placementId: '1'}; - bid.mediaTypes = { - native: { - title: {required: true}, - image: {required: false, sizes: [80, 80]}, - sponsored: {required: false}, - }, - }; - bid.nativeParams = { - title: {required: true}, - image: {required: false, sizes: [80, 80]}, - sponsored: {required: false}, - unsupported: {required: true}, - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when mediaTypes.native all assets needed', function () { - const bid = Object.assign({}, sbid); - bid.adUnitCode = 'div'; - bid.params = {accountId: '2', placementId: '1'}; - bid.mediaTypes = { - native: { - title: {required: true}, - image: {required: false, sizes: [80, 80]}, - sponsored: {required: false}, - }, - }; - bid.nativeParams = { - title: {required: true}, - image: {required: false, sizes: [80, 80]}, - sponsored: {required: false}, - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - - describe('override defaults', function () { - const sbid = { - bidder: 'mgid', - params: { - accountId: '1', - placementId: '2', - }, - }; - it('should return object', function () { - const bid = Object.assign({}, sbid); - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - const bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - expect(request).to.exist.and.to.be.a('object'); - }); - - it('should return overwrite default bidurl', function () { - const bid = Object.assign({}, sbid); - bid.params = { - bidUrl: 'https://newbidurl.com/', - accountId: '1', - placementId: '2', - }; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - const bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - expect(request.url).to.include('https://newbidurl.com/1'); - }); - it('should return overwrite default bidFloor', function () { - const bid = Object.assign({}, sbid); - bid.params = { - bidFloor: 1.1, - accountId: '1', - placementId: '2', - }; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - const bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - expect(request.data).to.be.a('string'); - const data = JSON.parse(request.data); - expect(data).to.be.a('object'); - expect(data.imp).to.be.a('array'); - expect(data.imp).to.have.lengthOf(1); - expect(data.imp[0].bidfloor).to.deep.equal(1.1); - }); - it('should return overwrite default currency', function () { - const bid = Object.assign({}, sbid); - bid.params = { - cur: 'GBP', - accountId: '1', - placementId: '2', - }; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - const bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - expect(request.data).to.be.a('string'); - const data = JSON.parse(request.data); - expect(data).to.be.a('object'); - expect(data.cur).to.deep.equal(['GBP']); - }); - }); - - describe('buildRequests', function () { - const abid = { - adUnitCode: 'div', - bidder: 'mgid', - ortb2Imp: { - ext: { - gpid: '/1111/gpid', - data: { - pbadslot: '/1111/gpid', - } - } - }, - params: { - accountId: '1', - placementId: '2', - }, - }; - afterEach(function () { - config.setConfig({coppa: undefined}) - }) - - it('should return undefined if no validBidRequests passed', function () { - expect(spec.buildRequests([])).to.be.undefined; - }); - it('should return request url with muid', function () { - const getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage'); - getDataFromLocalStorageStub.withArgs('mgMuidn').returns('xxx'); - - const bid = Object.assign({}, abid); - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - const bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1?muid=xxx'); - - getDataFromLocalStorageStub.restore(); - }); - it('should proper handle gdpr', function () { - config.setConfig({coppa: 1}) - const bid = Object.assign({}, abid); - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - const bidRequests = [bid]; - const request = spec.buildRequests(bidRequests, {gdprConsent: {consentString: 'gdpr', gdprApplies: true}, uspConsent: 'usp', gppConsent: {gppString: 'gpp'}}); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.user).deep.equal({ext: {consent: 'gdpr'}}); - expect(data.regs).deep.equal({ext: {gdpr: 1, us_privacy: 'usp'}, gpp: 'gpp', coppa: 1}); - }); - it('should handle refererInfo', function () { - const bid = Object.assign({}, abid); - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - const bidRequests = [bid]; - const domain = 'site.com' - const page = `http://${domain}/site.html` - const ref = 'http://ref.com/ref.html' - const request = spec.buildRequests(bidRequests, {refererInfo: {page, ref}}); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.site.domain).to.deep.equal(domain); - expect(data.site.page).to.deep.equal(page); - expect(data.site.ref).to.deep.equal(ref); - }); - it('should handle schain', function () { - const bid = Object.assign({}, abid); - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - bid.ortb2 = bid.ortb2 || {}; - bid.ortb2.source = bid.ortb2.source || {}; - bid.ortb2.source.ext = bid.ortb2.source.ext || {}; - bid.ortb2.source.ext.schain = ['schain1', 'schain2']; - const bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - const data = JSON.parse(request.data); - expect(data.source).to.deep.equal({ext: {schain: bid.ortb2.source.ext.schain}}); - }); - it('should handle userId', function () { - const bid = Object.assign({}, abid); - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - const bidRequests = [bid]; - const bidderRequest = {userId: 'userid'}; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.user.id).to.deep.equal(bidderRequest.userId); - }); - it('should handle eids', function () { - const bid = Object.assign({}, abid); - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - bid.userIdAsEids = ['eid1', 'eid2'] - const bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - const data = JSON.parse(request.data); - expect(data.user.ext.eids).to.deep.equal(bid.userIdAsEids); - }); - it('should return proper banner imp', function () { - const bid = Object.assign({}, abid); - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - const bidRequests = [bid]; - const page = top.location.href; - const domain = utils.parseUrl(page).hostname; - const request = spec.buildRequests(bidRequests); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.site.domain).to.deep.equal(domain); - expect(data.site.page).to.deep.equal(page); - expect(data.cur).to.deep.equal(['USD']); - expect(data.device.ua).to.deep.equal(navigator.userAgent); - expect(data.device.dnt).equal(dnt); - expect(data.device.h).equal(screenHeight); - expect(data.device.w).equal(screenWidth); - expect(data.device.language).to.deep.equal(lang); - expect(data.imp[0].tagid).to.deep.equal('2/div'); - expect(data.imp[0].ext.gpid).to.deep.equal('/1111/gpid'); - expect(data.imp[0].banner).to.deep.equal({w: 300, h: 250}); - expect(data.imp[0].secure).to.deep.equal(secure); - expect(request).to.deep.equal({ - 'method': 'POST', - 'url': 'https://prebid.mgid.com/prebid/1', - 'data': `{"site":{"domain":"${domain}","page":"${page}"},"cur":["USD"],"geo":{"utcoffset":${utcOffset}},"device":{"ua":"${navigator.userAgent}","js":1,"dnt":${dnt},"h":${screenHeight},"w":${screenWidth},"language":"${lang}"},"ext":{"mgid_ver":"${mgid_ver}","prebid_ver":"${version}"},"imp":[{"tagid":"2/div","secure":${secure},"ext":{"gpid":"/1111/gpid"},"banner":{"w":300,"h":250}}],"tmax":3000}`, - }); - }); - it('should not return native imp if minimum asset list not requested', function () { - const bid = Object.assign({}, abid); - bid.mediaTypes = { - native: '', - }; - bid.nativeParams = { - title: {required: true}, - image: {sizes: [80, 80]}, - }; - const bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - expect(request).to.be.undefined; - }); - it('should return proper native imp', function () { - const bid = Object.assign({}, abid); - bid.mediaTypes = { - native: '', - }; - bid.nativeParams = { - title: {required: true}, - image: {sizes: [80, 80]}, - sponsored: { }, - }; - - const bidRequests = [bid]; - const page = top.location.href; - const domain = utils.parseUrl(page).hostname; - const request = spec.buildRequests(bidRequests); - expect(request).to.be.a('object'); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.site.domain).to.deep.equal(domain); - expect(data.site.page).to.deep.equal(page); - expect(data.cur).to.deep.equal(['USD']); - expect(data.device.ua).to.deep.equal(navigator.userAgent); - expect(data.device.dnt).equal(dnt); - expect(data.device.h).equal(screenHeight); - expect(data.device.w).equal(screenWidth); - expect(data.device.language).to.deep.equal(lang); - expect(data.imp[0].tagid).to.deep.equal('2/div'); - expect(data.imp[0].ext.gpid).to.deep.equal('/1111/gpid'); - expect(data.imp[0].native).is.a('object').and.to.deep.equal({'request': {'assets': [{'id': 1, 'required': 1, 'title': {'len': 80}}, {'id': 2, 'img': {'h': 80, 'type': 3, 'w': 80}, 'required': 0}, {'data': {'type': 1}, 'id': 11, 'required': 0}], 'plcmtcnt': 1}}); - expect(data.imp[0].secure).to.deep.equal(secure); - expect(request).to.deep.equal({ - 'method': 'POST', - 'url': 'https://prebid.mgid.com/prebid/1', - 'data': `{"site":{"domain":"${domain}","page":"${page}"},"cur":["USD"],"geo":{"utcoffset":${utcOffset}},"device":{"ua":"${navigator.userAgent}","js":1,"dnt":${dnt},"h":${screenHeight},"w":${screenWidth},"language":"${lang}"},"ext":{"mgid_ver":"${mgid_ver}","prebid_ver":"${version}"},"imp":[{"tagid":"2/div","secure":${secure},"ext":{"gpid":"/1111/gpid"},"native":{"request":{"plcmtcnt":1,"assets":[{"id":1,"required":1,"title":{"len":80}},{"id":2,"required":0,"img":{"type":3,"w":80,"h":80}},{"id":11,"required":0,"data":{"type":1}}]}}}],"tmax":3000}`, - }); - }); - it('should return proper native imp with image altered', function () { - const bid = Object.assign({}, abid); - bid.mediaTypes = { - native: '', - }; - bid.nativeParams = { - title: {required: true}, - image: {wmin: 50, hmin: 50, required: true}, - icon: {}, - sponsored: { }, - }; - - const bidRequests = [bid]; - const page = top.location.href; - const domain = utils.parseUrl(page).hostname; - const request = spec.buildRequests(bidRequests); - expect(request).to.be.a('object'); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.site.domain).to.deep.equal(domain); - expect(data.site.page).to.deep.equal(page); - expect(data.cur).to.deep.equal(['USD']); - expect(data.device.ua).to.deep.equal(navigator.userAgent); - expect(data.device.dnt).equal(dnt); - expect(data.device.h).equal(screenHeight); - expect(data.device.w).equal(screenWidth); - expect(data.device.language).to.deep.equal(lang); - expect(data.imp[0].tagid).to.deep.equal('2/div'); - expect(data.imp[0].native).is.a('object').and.to.deep.equal({'request': {'assets': [{'id': 1, 'required': 1, 'title': {'len': 80}}, {'id': 2, 'img': {'h': 328, hmin: 50, 'type': 3, 'w': 492, wmin: 50}, 'required': 1}, {'id': 3, 'img': {'h': 50, 'type': 1, 'w': 50}, 'required': 0}, {'data': {'type': 1}, 'id': 11, 'required': 0}], 'plcmtcnt': 1}}); - expect(data.imp[0].secure).to.deep.equal(secure); - expect(request).to.deep.equal({ - 'method': 'POST', - 'url': 'https://prebid.mgid.com/prebid/1', - 'data': `{"site":{"domain":"${domain}","page":"${page}"},"cur":["USD"],"geo":{"utcoffset":${utcOffset}},"device":{"ua":"${navigator.userAgent}","js":1,"dnt":${dnt},"h":${screenHeight},"w":${screenWidth},"language":"${lang}"},"ext":{"mgid_ver":"${mgid_ver}","prebid_ver":"${version}"},"imp":[{"tagid":"2/div","secure":${secure},"ext":{"gpid":"/1111/gpid"},"native":{"request":{"plcmtcnt":1,"assets":[{"id":1,"required":1,"title":{"len":80}},{"id":2,"required":1,"img":{"type":3,"w":492,"h":328,"wmin":50,"hmin":50}},{"id":3,"required":0,"img":{"type":1,"w":50,"h":50}},{"id":11,"required":0,"data":{"type":1}}]}}}],"tmax":3000}`, - }); - }); - it('should return proper native imp with sponsoredBy', function () { - const bid = Object.assign({}, abid); - bid.mediaTypes = { - native: '', - }; - bid.nativeParams = { - title: {required: true}, - image: {sizes: [80, 80]}, - sponsoredBy: { }, - }; - - const bidRequests = [bid]; - const page = top.location.href; - const domain = utils.parseUrl(page).hostname; - const request = spec.buildRequests(bidRequests); - expect(request).to.be.a('object'); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.site.domain).to.deep.equal(domain); - expect(data.site.page).to.deep.equal(page); - expect(data.cur).to.deep.equal(['USD']); - expect(data.device.ua).to.deep.equal(navigator.userAgent); - expect(data.device.dnt).equal(dnt); - expect(data.device.h).equal(screenHeight); - expect(data.device.w).equal(screenWidth); - expect(data.device.language).to.deep.equal(lang); - expect(data.imp[0].tagid).to.deep.equal('2/div'); - expect(data.imp[0].native).is.a('object').and.to.deep.equal({'request': {'assets': [{'id': 1, 'required': 1, 'title': {'len': 80}}, {'id': 2, 'img': {'h': 80, 'type': 3, 'w': 80}, 'required': 0}, {'data': {'type': 1}, 'id': 4, 'required': 0}], 'plcmtcnt': 1}}); - expect(data.imp[0].secure).to.deep.equal(secure); - expect(request).to.deep.equal({ - 'method': 'POST', - 'url': 'https://prebid.mgid.com/prebid/1', - 'data': `{"site":{"domain":"${domain}","page":"${page}"},"cur":["USD"],"geo":{"utcoffset":${utcOffset}},"device":{"ua":"${navigator.userAgent}","js":1,"dnt":${dnt},"h":${screenHeight},"w":${screenWidth},"language":"${lang}"},"ext":{"mgid_ver":"${mgid_ver}","prebid_ver":"${version}"},"imp":[{"tagid":"2/div","secure":${secure},"ext":{"gpid":"/1111/gpid"},"native":{"request":{"plcmtcnt":1,"assets":[{"id":1,"required":1,"title":{"len":80}},{"id":2,"required":0,"img":{"type":3,"w":80,"h":80}},{"id":4,"required":0,"data":{"type":1}}]}}}],"tmax":3000}`, - }); - }); - it('should return proper banner request', function () { - const bid = Object.assign({}, abid); - bid.mediaTypes = { - banner: { - sizes: [[300, 600], [300, 250]], - pos: 1, - }, - }; - const bidRequests = [bid]; - const request = spec.buildRequests(bidRequests); - - const page = top.location.href; - const domain = utils.parseUrl(page).hostname; - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.site.domain).to.deep.equal(domain); - expect(data.site.page).to.deep.equal(page); - expect(data.cur).to.deep.equal(['USD']); - expect(data.device.ua).to.deep.equal(navigator.userAgent); - expect(data.device.dnt).equal(dnt); - expect(data.device.h).equal(screenHeight); - expect(data.device.w).equal(screenWidth); - expect(data.device.language).to.deep.equal(lang); - expect(data.imp[0].tagid).to.deep.equal('2/div'); - expect(data.imp[0].banner).to.deep.equal({w: 300, h: 600, format: [{w: 300, h: 600}, {w: 300, h: 250}], pos: 1}); - expect(data.imp[0].secure).to.deep.equal(secure); - - expect(request).to.deep.equal({ - 'method': 'POST', - 'url': 'https://prebid.mgid.com/prebid/1', - 'data': `{"site":{"domain":"${domain}","page":"${page}"},"cur":["USD"],"geo":{"utcoffset":${utcOffset}},"device":{"ua":"${navigator.userAgent}","js":1,"dnt":${dnt},"h":${screenHeight},"w":${screenWidth},"language":"${lang}"},"ext":{"mgid_ver":"${mgid_ver}","prebid_ver":"${version}"},"imp":[{"tagid":"2/div","secure":${secure},"ext":{"gpid":"/1111/gpid"},"banner":{"w":300,"h":600,"format":[{"w":300,"h":600},{"w":300,"h":250}],"pos":1}}],"tmax":3000}`, - }); - }); - it('should proper handle ortb2 data', function () { - const bid = Object.assign({}, abid); - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - const bidRequests = [bid]; - - const bidderRequest = { - gdprConsent: { - consentString: 'consent1', - gdprApplies: false, - }, - ortb2: { - bcat: ['bcat1', 'bcat2'], - badv: ['badv1.com', 'badv2.com'], - wlang: ['l1', 'l2'], - site: { - content: { - data: [{ - name: 'mgid.com', - ext: { - segtax: 1, - }, - segment: [ - {id: '123'}, - {id: '456'}, - ], - }] - } - }, - user: { - ext: { - consent: 'consent2 ', - }, - data: [{ - name: 'mgid.com', - ext: { - segtax: 2, - }, - segment: [ - {'id': '789'}, - {'id': '987'}, - ], - }] - }, - regs: { - ext: { - gdpr: 1, - } - } - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).deep.equal('https://prebid.mgid.com/prebid/1'); - expect(request.method).deep.equal('POST'); - const data = JSON.parse(request.data); - expect(data.bcat).deep.equal(bidderRequest.ortb2.bcat); - expect(data.badv).deep.equal(bidderRequest.ortb2.badv); - expect(data.wlang).deep.equal(bidderRequest.ortb2.wlang); - expect(data.site.content).deep.equal(bidderRequest.ortb2.site.content); - expect(data.regs).deep.equal(bidderRequest.ortb2.regs); - expect(data.user.data).deep.equal(bidderRequest.ortb2.user.data); - expect(data.user.ext).deep.equal(bidderRequest.ortb2.user.ext); - }); - }); - - describe('interpretResponse', function () { - it('should not push proper native bid response if adm is missing', function () { - const resp = { - body: {'id': '57c0c2b1b732ca', 'bidid': '57c0c2b1b732ca', 'cur': 'GBP', 'seatbid': [{'bid': [{'price': 1.5, 'h': 600, 'w': 300, 'id': '1', 'impid': '61e40632c53fc2', 'adid': '2898532/2419121/2592854/2499195', 'nurl': 'https nurl', 'burl': 'https burl', 'cid': '44082', 'crid': '2898532/2419121/2592854/2499195', 'cat': ['IAB7', 'IAB14', 'IAB18-3', 'IAB1-2'], 'ext': {'place': 0, 'crtype': 'native'}, 'adomain': ['test.com']}], 'seat': '44082'}]} - }; - const bids = spec.interpretResponse(resp); - expect(bids).to.deep.equal([]) - }); - it('should not push proper native bid response if assets is empty', function () { - const resp = { - body: {'id': '57c0c2b1b732ca', 'bidid': '57c0c2b1b732ca', 'cur': 'GBP', 'seatbid': [{'bid': [{'price': 1.5, 'h': 600, 'w': 300, 'id': '1', 'impid': '61e40632c53fc2', 'adid': '2898532/2419121/2592854/2499195', 'nurl': 'https nurl', 'burl': 'https burl', 'adm': '{"native":{"ver":"1.1","link":{"url":"link_url"},"assets":[],"imptrackers":["imptrackers1"]}}', 'cid': '44082', 'crid': '2898532/2419121/2592854/2499195', 'cat': ['IAB7', 'IAB14', 'IAB18-3', 'IAB1-2'], 'ext': {'place': 0, 'crtype': 'native'}, 'adomain': ['test.com']}], 'seat': '44082'}]} - }; - const bids = spec.interpretResponse(resp); - expect(bids).to.deep.equal([]) - }); - it('should push proper native bid response, assets1', function () { - const resp = { - body: {'id': '57c0c2b1b732ca', 'bidid': '57c0c2b1b732ca', 'cur': 'GBP', 'seatbid': [{'bid': [{'price': 1.5, 'h': 600, 'w': 300, 'id': '1', 'impid': '61e40632c53fc2', 'adid': '2898532/2419121/2592854/2499195', 'nurl': 'https nurl', 'burl': 'https burl', 'adm': '{"native":{"ver":"1.1","link":{"url":"link_url"},"assets":[{"id":1,"required":0,"title":{"text":"title1"}},{"id":2,"required":0,"img":{"w":80,"h":80,"type":3,"url":"image_src"}},{"id":3,"required":0,"img":{"w":50,"h":50,"type":1,"url":"icon_src"}},{"id":4,"required":0,"data":{"type":4,"value":"sponsored"}},{"id":5,"required":0,"data":{"type":6,"value":"price1"}},{"id":6,"required":0,"data":{"type":7,"value":"price2"}}],"imptrackers":["imptrackers1"]}}', 'cid': '44082', 'crid': '2898532/2419121/2592854/2499195', 'cat': ['IAB7', 'IAB14', 'IAB18-3', 'IAB1-2'], 'ext': {'place': 0, 'crtype': 'native'}, 'adomain': ['test.com']}], 'seat': '44082'}], ext: {'muidn': 'userid'}} - }; - const bids = spec.interpretResponse(resp); - expect(bids).to.deep.equal([{ - 'ad': '{"native":{"ver":"1.1","link":{"url":"link_url"},"assets":[{"id":1,"required":0,"title":{"text":"title1"}},{"id":2,"required":0,"img":{"w":80,"h":80,"type":3,"url":"image_src"}},{"id":3,"required":0,"img":{"w":50,"h":50,"type":1,"url":"icon_src"}},{"id":4,"required":0,"data":{"type":4,"value":"sponsored"}},{"id":5,"required":0,"data":{"type":6,"value":"price1"}},{"id":6,"required":0,"data":{"type":7,"value":"price2"}}],"imptrackers":["imptrackers1"]}}', - 'burl': 'https burl', - 'cpm': 1.5, - 'creativeId': '2898532/2419121/2592854/2499195', - 'currency': 'GBP', - 'dealId': '', - 'height': 0, - 'isBurl': true, - 'mediaType': 'native', - 'meta': {'advertiserDomains': ['test.com']}, - 'native': { - 'clickTrackers': [], - 'clickUrl': 'link_url', - 'data': 'price1', - 'icon': { - 'height': 50, - 'url': 'icon_src', - 'width': 50 - }, - 'image': { - 'height': 80, - 'url': 'image_src', - 'width': 80 - }, - 'impressionTrackers': [ - 'imptrackers1' - ], - 'jstracker': [], - 'sponsoredBy': 'sponsored', - 'title': 'title1' - }, - 'netRevenue': true, - 'nurl': 'https nurl', - 'requestId': '61e40632c53fc2', - 'ttl': 300, - 'width': 0 - }]) - }); - it('should push proper native bid response, assets2', function () { - const resp = { - body: {'id': '57c0c2b1b732ca', 'bidid': '57c0c2b1b732ca', 'cur': 'GBP', 'seatbid': [{'bid': [{'price': 1.5, 'h': 600, 'w': 300, 'id': '1', 'impid': '61e40632c53fc2', 'adid': '2898532/2419121/2592854/2499195', 'nurl': 'https nurl', 'burl': 'https burl', 'adm': '{"native":{"ver":"1.1","link":{"url":"link_url"},"assets":[{"id":1,"required":0,"title":{"text":"title1"}},{"id":2,"required":0,"img":{"w":80,"h":80,"type":3,"url":"image_src"}},{"id":3,"required":0,"img":{"w":50,"h":50,"type":1,"url":"icon_src"}}],"imptrackers":["imptrackers1"]}}', 'cid': '44082', 'crid': '2898532/2419121/2592854/2499195', 'cat': ['IAB7', 'IAB14', 'IAB18-3', 'IAB1-2'], 'ext': {'place': 0, 'crtype': 'native'}, 'adomain': ['test.com']}], 'seat': '44082'}]} - }; - const bids = spec.interpretResponse(resp); - expect(bids).to.deep.equal([ - { - 'ad': '{"native":{"ver":"1.1","link":{"url":"link_url"},"assets":[{"id":1,"required":0,"title":{"text":"title1"}},{"id":2,"required":0,"img":{"w":80,"h":80,"type":3,"url":"image_src"}},{"id":3,"required":0,"img":{"w":50,"h":50,"type":1,"url":"icon_src"}}],"imptrackers":["imptrackers1"]}}', - 'cpm': 1.5, - 'creativeId': '2898532/2419121/2592854/2499195', - 'currency': 'GBP', - 'dealId': '', - 'height': 0, - 'isBurl': true, - 'mediaType': 'native', - 'meta': {'advertiserDomains': ['test.com']}, - 'netRevenue': true, - 'nurl': 'https nurl', - 'burl': 'https burl', - 'requestId': '61e40632c53fc2', - 'ttl': 300, - 'width': 0, - 'native': { - clickTrackers: [], - title: 'title1', - image: { - url: 'image_src', - width: 80, - height: 80, - }, - icon: { - url: 'icon_src', - width: 50, - height: 50, - }, - impressionTrackers: ['imptrackers1'], - jstracker: [], - clickUrl: 'link_url', - } - } - ]); - }); - - it('should not push bid response', function () { - const bids = spec.interpretResponse(); - expect(bids).to.be.undefined; - }); - it('should push proper banner bid response', function () { - const resp = { - body: {'id': '57c0c2b1b732ca', 'bidid': '57c0c2b1b732ca', 'cur': '', 'seatbid': [{'bid': [{'price': 1.5, 'h': 600, 'w': 300, 'id': '1', 'impid': '61e40632c53fc2', 'adid': '2898532/2419121/2592854/2499195', 'nurl': 'https nurl', 'burl': 'https burl', 'adm': 'html: adm', 'cid': '44082', 'crid': '2898532/2419121/2592854/2499195', 'cat': ['IAB7', 'IAB14', 'IAB18-3', 'IAB1-2'], 'adomain': ['test.com']}], 'seat': '44082'}]} - }; - const bids = spec.interpretResponse(resp); - expect(bids).to.deep.equal([ - { - 'ad': 'html: adm', - 'cpm': 1.5, - 'creativeId': '2898532/2419121/2592854/2499195', - 'currency': 'USD', - 'dealId': '', - 'height': 600, - 'isBurl': true, - 'mediaType': 'banner', - 'meta': {'advertiserDomains': ['test.com']}, - 'netRevenue': true, - 'nurl': 'https nurl', - 'burl': 'https burl', - 'requestId': '61e40632c53fc2', - 'ttl': 300, - 'width': 300, - } - ]); - }); - }); - - describe('getUserSyncs', function () { - afterEach(function() { - config.setConfig({userSync: {syncsPerBidder: USERSYNC_DEFAULT_CONFIG.syncsPerBidder}}); - }); - it('should do nothing on getUserSyncs without inputs', function () { - expect(spec.getUserSyncs()).to.equal(undefined) - }); - it('should return frame object with empty consents', function () { - const sync = spec.getUserSyncs({iframeEnabled: true}) - expect(sync).to.have.length(1) - expect(sync[0]).to.have.property('type', 'iframe') - expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&gdpr_consent=&gdpr=0/) - }); - it('should return frame object with gdpr consent', function () { - const sync = spec.getUserSyncs({iframeEnabled: true}, undefined, {consentString: 'consent', gdprApplies: true}) - expect(sync).to.have.length(1) - expect(sync[0]).to.have.property('type', 'iframe') - expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&gdpr_consent=consent&gdpr=1/) - }); - it('should return frame object with gdpr + usp', function () { - const sync = spec.getUserSyncs({iframeEnabled: true}, undefined, {consentString: 'consent1', gdprApplies: true}, {'consentString': 'consent2'}) - expect(sync).to.have.length(1) - expect(sync[0]).to.have.property('type', 'iframe') - expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/) - }); - it('should return img object with gdpr + usp', function () { - config.setConfig({userSync: {syncsPerBidder: undefined}}); - const sync = spec.getUserSyncs({pixelEnabled: true}, undefined, {consentString: 'consent1', gdprApplies: true}, {'consentString': 'consent2'}) - expect(sync).to.have.length(USERSYNC_DEFAULT_CONFIG.syncsPerBidder) - for (let i = 0; i < USERSYNC_DEFAULT_CONFIG.syncsPerBidder; i++) { - expect(sync[i]).to.have.property('type', 'image') - expect(sync[i]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.gif\?cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/) - } - }); - it('should return frame object with gdpr + usp', function () { - const sync = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, undefined, {consentString: 'consent1', gdprApplies: true}, {'consentString': 'consent2'}) - expect(sync).to.have.length(1) - expect(sync[0]).to.have.property('type', 'iframe') - expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/) - }); - it('should return img (pixels) objects with gdpr + usp', function () { - const response = [{body: {ext: {cm: ['http://cm.mgid.com/i.gif?cdsp=1111', 'http://cm.mgid.com/i.gif']}}}] - const sync = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, response, {consentString: 'consent1', gdprApplies: true}, {'consentString': 'consent2'}) - expect(sync).to.have.length(2) - expect(sync[0]).to.have.property('type', 'image') - expect(sync[0]).to.have.property('url').match(/http:\/\/cm\.mgid\.com\/i\.gif\?cdsp=1111&cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/) - expect(sync[1]).to.have.property('type', 'image') - expect(sync[1]).to.have.property('url').match(/http:\/\/cm\.mgid\.com\/i\.gif\?cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/) - }); - }); - - describe('getUserSyncs with img from ext.cm and gdpr + usp + coppa + gpp', function () { - afterEach(function() { - config.setConfig({coppa: undefined}) - }); - it('should return img (pixels) objects with gdpr + usp + coppa + gpp', function () { - config.setConfig({coppa: 1}); - const response = [{body: {ext: {cm: ['http://cm.mgid.com/i.gif?cdsp=1111', 'http://cm.mgid.com/i.gif']}}}] - const sync = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, response, {consentString: 'consent1', gdprApplies: true}, {'consentString': 'consent2'}, {gppString: 'gpp'}) - expect(sync).to.have.length(2) - expect(sync[0]).to.have.property('type', 'image') - expect(sync[0]).to.have.property('url').match(/http:\/\/cm\.mgid\.com\/i\.gif\?cdsp=1111&cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2&gppString=gpp&coppa=1/) - expect(sync[1]).to.have.property('type', 'image') - expect(sync[1]).to.have.property('url').match(/http:\/\/cm\.mgid\.com\/i\.gif\?cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2&gppString=gpp&coppa=1/) - }); - }); - - describe('on bidWon', function () { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - it('should replace nurl and burl for native', function () { - const burl = 'burl&s=${' + 'AUCTION_PRICE}'; - const nurl = 'nurl&s=${' + 'AUCTION_PRICE}'; - const bid = {'bidderCode': 'mgid', 'width': 0, 'height': 0, 'statusMessage': 'Bid available', 'adId': '3d0b6ff1dda89', 'requestId': '2a423489e058a1', 'mediaType': 'native', 'source': 'client', 'ad': '{"native":{"ver":"1.1","link":{"url":"LinkURL"},"assets":[{"id":1,"required":0,"title":{"text":"TITLE"}},{"id":2,"required":0,"img":{"w":80,"h":80,"type":3,"url":"ImageURL"}},{"id":3,"required":0,"img":{"w":50,"h":50,"type":1,"url":"IconURL"}},{"id":11,"required":0,"data":{"type":1,"value":"sponsored"}}],"imptrackers":["ImpTrackerURL"]}}', 'cpm': 0.66, 'creativeId': '353538_591471', 'currency': 'USD', 'dealId': '', 'netRevenue': true, 'ttl': 300, 'nurl': nurl, 'burl': burl, 'isBurl': true, 'native': {'title': 'TITLE', 'image': {'url': 'ImageURL', 'height': 80, 'width': 80}, 'icon': {'url': 'IconURL', 'height': 50, 'width': 50}, 'sponsored': 'sponsored', 'clickUrl': 'LinkURL', 'clickTrackers': [], 'impressionTrackers': ['ImpTrackerURL'], 'jstracker': []}, 'auctionId': 'a92bffce-14d2-4f8f-a78a-7b9b5e4d28fa', 'responseTimestamp': 1556867386065, 'requestTimestamp': 1556867385916, 'bidder': 'mgid', 'adUnitCode': 'div-gpt-ad-1555415275793-0', 'timeToRespond': 149, 'pbLg': '0.50', 'pbMg': '0.60', 'pbHg': '0.66', 'pbAg': '0.65', 'pbDg': '0.66', 'pbCg': '', 'size': '0x0', 'adserverTargeting': {'hb_bidder': 'mgid', 'hb_adid': '3d0b6ff1dda89', 'hb_pb': '0.66', 'hb_size': '0x0', 'hb_source': 'client', 'hb_format': 'native', 'hb_native_title': 'TITLE', 'hb_native_image': 'hb_native_image:3d0b6ff1dda89', 'hb_native_icon': 'IconURL', 'hb_native_linkurl': 'hb_native_linkurl:3d0b6ff1dda89'}, 'status': 'targetingSet', 'params': [{'accountId': '184', 'placementId': '353538'}]}; - spec.onBidWon(bid); - expect(bid.nurl).to.deep.equal('nurl&s=0.66'); - expect(bid.burl).to.deep.equal('burl&s=0.66'); - }); - it('should replace nurl and burl for banner', function () { - const burl = 'burl&s=${' + 'AUCTION_PRICE}'; - const nurl = 'nurl&s=${' + 'AUCTION_PRICE}'; - const bid = {'bidderCode': 'mgid', 'width': 0, 'height': 0, 'statusMessage': 'Bid available', 'adId': '3d0b6ff1dda89', 'requestId': '2a423489e058a1', 'mediaType': 'banner', 'source': 'client', 'ad': burl, 'cpm': 0.66, 'creativeId': '353538_591471', 'currency': 'USD', 'dealId': '', 'netRevenue': true, 'ttl': 300, 'nurl': nurl, 'burl': burl, 'isBurl': true, 'auctionId': 'a92bffce-14d2-4f8f-a78a-7b9b5e4d28fa', 'responseTimestamp': 1556867386065, 'requestTimestamp': 1556867385916, 'bidder': 'mgid', 'adUnitCode': 'div-gpt-ad-1555415275793-0', 'timeToRespond': 149, 'pbLg': '0.50', 'pbMg': '0.60', 'pbHg': '0.66', 'pbAg': '0.65', 'pbDg': '0.66', 'pbCg': '', 'size': '0x0', 'adserverTargeting': {'hb_bidder': 'mgid', 'hb_adid': '3d0b6ff1dda89', 'hb_pb': '0.66', 'hb_size': '0x0', 'hb_source': 'client', 'hb_format': 'banner', 'hb_banner_title': 'TITLE', 'hb_banner_image': 'hb_banner_image:3d0b6ff1dda89', 'hb_banner_icon': 'IconURL', 'hb_banner_linkurl': 'hb_banner_linkurl:3d0b6ff1dda89'}, 'status': 'targetingSet', 'params': [{'accountId': '184', 'placementId': '353538'}]}; - spec.onBidWon(bid); - expect(bid.nurl).to.deep.equal('nurl&s=0.66'); - expect(bid.burl).to.deep.equal(burl); - expect(bid.ad).to.deep.equal('burl&s=0.66'); - }); - }); - - describe('price floor module', function() { - let bidRequest; - const bidRequests0 = { - adUnitCode: 'div', - bidder: 'mgid', - params: { - accountId: '1', - placementId: '2', - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - sizes: [[300, 250]], - } - beforeEach(function() { - bidRequest = [utils.deepClone(bidRequests0)]; - }); - - it('obtain floor from getFloor', function() { - bidRequest[0].getFloor = () => { - return { - currency: 'USD', - floor: 1.23 - }; - }; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.have.property('bidfloor', 1.23); - expect(payload.imp[0]).to.not.have.property('bidfloorcur'); - }); - it('obtain floor from params', function() { - bidRequest[0].getFloor = () => { - return { - currency: 'USD', - floor: 1.23 - }; - }; - bidRequest[0].params.bidfloor = 0.1; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.have.property('bidfloor', 0.1); - expect(payload.imp[0]).to.not.have.property('bidfloorcur'); - }); - - it('undefined currency -> USD', function() { - bidRequest[0].params.currency = 'EUR' - bidRequest[0].getFloor = () => { - return { - floor: 1.23 - }; - }; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.have.property('bidfloor', 1.23); - expect(payload.imp[0]).to.have.property('bidfloorcur', 'USD'); - }); - it('altered currency', function() { - bidRequest[0].getFloor = () => { - return { - currency: 'EUR', - floor: 1.23 - }; - }; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.have.property('bidfloor', 1.23); - expect(payload.imp[0]).to.have.property('bidfloorcur', 'EUR'); - }); - it('altered currency, same as in request', function() { - bidRequest[0].params.cur = 'EUR' - bidRequest[0].getFloor = () => { - return { - currency: 'EUR', - floor: 1.23 - }; - }; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.have.property('bidfloor', 1.23); - expect(payload.imp[0]).to.not.have.property('bidfloorcur'); - }); - - it('bad floor value', function() { - bidRequest[0].getFloor = () => { - return { - currency: 'USD', - floor: 'test' - }; - }; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.not.have.property('bidfloor'); - expect(payload.imp[0]).to.not.have.property('bidfloorcur'); - }); - - it('empty floor object', function() { - bidRequest[0].getFloor = () => { - return {}; - }; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.not.have.property('bidfloor'); - expect(payload.imp[0]).to.not.have.property('bidfloorcur'); - }); - - it('undefined floor result', function() { - bidRequest[0].getFloor = () => {}; - - const payload = JSON.parse(spec.buildRequests(bidRequest).data); - expect(payload.imp[0]).to.not.have.property('bidfloor'); - expect(payload.imp[0]).to.not.have.property('bidfloorcur'); - }); - }); -}); diff --git a/test/spec/modules/mgidRtdProvider_spec.js b/test/spec/modules/mgidRtdProvider_spec.js deleted file mode 100644 index 7fd41a3c4..000000000 --- a/test/spec/modules/mgidRtdProvider_spec.js +++ /dev/null @@ -1,362 +0,0 @@ -import { mgidSubmodule, storage } from '../../../modules/mgidRtdProvider.js'; -import {expect} from 'chai'; -import * as refererDetection from '../../../src/refererDetection.js'; -import {server} from '../../mocks/xhr.js'; - -describe('Mgid RTD submodule', () => { - let clock; - let getRefererInfoStub; - let getDataFromLocalStorageStub; - - beforeEach(() => { - clock = sinon.useFakeTimers(); - - getRefererInfoStub = sinon.stub(refererDetection, 'getRefererInfo'); - getRefererInfoStub.returns({ - canonicalUrl: 'https://www.test.com/abc' - }); - - getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage').returns('qwerty654321'); - }); - - afterEach(() => { - clock.restore(); - getRefererInfoStub.restore(); - getDataFromLocalStorageStub.restore(); - }); - - it('init is successfull, when clientSiteId is defined', () => { - expect(mgidSubmodule.init({params: {clientSiteId: 123}})).to.be.true; - }); - - it('init is unsuccessfull, when clientSiteId is not defined', () => { - expect(mgidSubmodule.init({})).to.be.false; - }); - - it('getBidRequestData send all params to our endpoint and succesfully modifies ortb2', () => { - const responseObj = { - userSegments: ['100', '200'], - userSegtax: 5, - siteSegments: ['300', '400'], - siteSegtax: 7, - muid: 'qwerty654321', - }; - - const reqBidsConfigObj = { - ortb2Fragments: { - global: { - site: { - content: { - language: 'en', - } - } - }, - } - }; - - const onDone = sinon.stub(); - - mgidSubmodule.getBidRequestData( - reqBidsConfigObj, - onDone, - {params: {clientSiteId: 123}}, - { - gdpr: { - gdprApplies: true, - consentString: 'testConsent', - }, - usp: '1YYY', - } - ); - - server.requests[0].respond( - 200, - {'Content-Type': 'application/json'}, - JSON.stringify(responseObj) - ); - - const requestUrl = new URL(server.requests[0].url); - expect(requestUrl.host).to.be.eq('servicer.mgid.com'); - expect(requestUrl.searchParams.get('gdprApplies')).to.be.eq('true'); - expect(requestUrl.searchParams.get('consentData')).to.be.eq('testConsent'); - expect(requestUrl.searchParams.get('uspString')).to.be.eq('1YYY'); - expect(requestUrl.searchParams.get('muid')).to.be.eq('qwerty654321'); - expect(requestUrl.searchParams.get('clientSiteId')).to.be.eq('123'); - expect(requestUrl.searchParams.get('cxurl')).to.be.eq('https://www.test.com/abc'); - expect(requestUrl.searchParams.get('cxlang')).to.be.eq('en'); - - assert.deepInclude( - reqBidsConfigObj.ortb2Fragments.global, - { - site: { - content: { - language: 'en', - data: [ - { - name: 'www.mgid.com', - ext: { - segtax: 7 - }, - segment: [ - { id: '300' }, - { id: '400' }, - ] - } - ], - } - }, - user: { - data: [ - { - name: 'www.mgid.com', - ext: { - segtax: 5 - }, - segment: [ - { id: '100' }, - { id: '200' }, - ] - } - ], - }, - }); - }); - - it('getBidRequestData doesn\'t send params (consent and cxlang), if we haven\'t received them', () => { - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - } - }; - - const onDone = sinon.stub(); - - mgidSubmodule.getBidRequestData( - reqBidsConfigObj, - onDone, - {params: {clientSiteId: 123}}, - {} - ); - - server.requests[0].respond( - 200, - {'Content-Type': 'application/json'}, - JSON.stringify({}) - ); - - const requestUrl = new URL(server.requests[0].url); - expect(requestUrl.host).to.be.eq('servicer.mgid.com'); - expect(requestUrl.searchParams.get('gdprApplies')).to.be.null; - expect(requestUrl.searchParams.get('consentData')).to.be.null; - expect(requestUrl.searchParams.get('uspString')).to.be.null; - expect(requestUrl.searchParams.get('muid')).to.be.eq('qwerty654321'); - expect(requestUrl.searchParams.get('clientSiteId')).to.be.eq('123'); - expect(requestUrl.searchParams.get('cxurl')).to.be.eq('https://www.test.com/abc'); - expect(requestUrl.searchParams.get('cxlang')).to.be.null; - expect(onDone.calledOnce).to.be.true; - }); - - it('getBidRequestData send gdprApplies event if it is false', () => { - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - } - }; - - const onDone = sinon.stub(); - - mgidSubmodule.getBidRequestData( - reqBidsConfigObj, - onDone, - {params: {clientSiteId: 123}}, - { - gdpr: { - gdprApplies: false, - consentString: 'testConsent', - }, - usp: '1YYY', - } - ); - - server.requests[0].respond( - 200, - {'Content-Type': 'application/json'}, - JSON.stringify({}) - ); - - const requestUrl = new URL(server.requests[0].url); - expect(requestUrl.host).to.be.eq('servicer.mgid.com'); - expect(requestUrl.searchParams.get('gdprApplies')).to.be.eq('false'); - expect(requestUrl.searchParams.get('consentData')).to.be.eq('testConsent'); - expect(requestUrl.searchParams.get('uspString')).to.be.eq('1YYY'); - expect(requestUrl.searchParams.get('muid')).to.be.eq('qwerty654321'); - expect(requestUrl.searchParams.get('clientSiteId')).to.be.eq('123'); - expect(requestUrl.searchParams.get('cxurl')).to.be.eq('https://www.test.com/abc'); - expect(requestUrl.searchParams.get('cxlang')).to.be.null; - expect(onDone.calledOnce).to.be.true; - }); - - it('getBidRequestData use og:url for cxurl, if it is available', () => { - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - } - }; - - const onDone = sinon.stub(); - - const metaStub = sinon.stub(document, 'getElementsByTagName').returns([ - { getAttribute: () => 'og:test', content: 'fake' }, - { getAttribute: () => 'og:url', content: 'https://realOgUrl.com/' } - ]); - - mgidSubmodule.getBidRequestData( - reqBidsConfigObj, - onDone, - {params: {clientSiteId: 123}}, - {} - ); - - server.requests[0].respond( - 200, - {'Content-Type': 'application/json'}, - JSON.stringify({}) - ); - - const requestUrl = new URL(server.requests[0].url); - expect(requestUrl.searchParams.get('cxurl')).to.be.eq('https://realOgUrl.com/'); - expect(onDone.calledOnce).to.be.true; - - metaStub.restore(); - }); - - it('getBidRequestData use topMostLocation for cxurl, if nothing else left', () => { - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - } - }; - - const onDone = sinon.stub(); - - getRefererInfoStub.returns({ - topmostLocation: 'https://www.test.com/topMost' - }); - - mgidSubmodule.getBidRequestData( - reqBidsConfigObj, - onDone, - {params: {clientSiteId: 123}}, - {} - ); - - server.requests[0].respond( - 200, - {'Content-Type': 'application/json'}, - JSON.stringify({}) - ); - - const requestUrl = new URL(server.requests[0].url); - expect(requestUrl.searchParams.get('cxurl')).to.be.eq('https://www.test.com/topMost'); - expect(onDone.calledOnce).to.be.true; - }); - - it('getBidRequestData won\'t modify ortb2 if response is broken', () => { - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - } - }; - - const onDone = sinon.stub(); - - mgidSubmodule.getBidRequestData( - reqBidsConfigObj, - onDone, - {params: {clientSiteId: 123}}, - {} - ); - - server.requests[0].respond( - 200, - {'Content-Type': 'application/json'}, - '{' - ); - - assert.deepEqual(reqBidsConfigObj.ortb2Fragments.global, {}); - expect(onDone.calledOnce).to.be.true; - }); - - it('getBidRequestData won\'t modify ortb2 if response status is not 200', () => { - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - } - }; - - const onDone = sinon.stub(); - - mgidSubmodule.getBidRequestData( - reqBidsConfigObj, - onDone, - {params: {clientSiteId: 123}}, - {} - ); - - server.requests[0].respond( - 204, - {'Content-Type': 'application/json'}, - ); - - assert.deepEqual(reqBidsConfigObj.ortb2Fragments.global, {}); - expect(onDone.calledOnce).to.be.true; - }); - - it('getBidRequestData won\'t modify ortb2 if response results in error', () => { - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - } - }; - - const onDone = sinon.stub(); - - mgidSubmodule.getBidRequestData( - reqBidsConfigObj, - onDone, - {params: {clientSiteId: 123}}, - {} - ); - - server.requests[0].respond( - 500, - {'Content-Type': 'application/json'}, - '{}' - ); - - assert.deepEqual(reqBidsConfigObj.ortb2Fragments.global, {}); - expect(onDone.calledOnce).to.be.true; - }); - - it('getBidRequestData won\'t modify ortb2 if response time hits timeout', () => { - const reqBidsConfigObj = { - ortb2Fragments: { - global: {}, - } - }; - - const onDone = sinon.stub(); - - mgidSubmodule.getBidRequestData( - reqBidsConfigObj, - onDone, - {params: {clientSiteId: 123, timeout: 500}}, - {} - ); - - clock.tick(510); - - assert.deepEqual(reqBidsConfigObj.ortb2Fragments.global, {}); - expect(onDone.calledOnce).to.be.true; - }); -}); diff --git a/test/spec/modules/mgidXBidAdapter_spec.js b/test/spec/modules/mgidXBidAdapter_spec.js deleted file mode 100644 index f6e1fd680..000000000 --- a/test/spec/modules/mgidXBidAdapter_spec.js +++ /dev/null @@ -1,543 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/mgidXBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; -import { config } from '../../../src/config.js'; -import { USERSYNC_DEFAULT_CONFIG } from '../../../src/userSync.js'; - -const bidder = 'mgidX'; - -describe('MGIDXBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - region: 'eu', - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - region: 'eu', - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid EU URL', function () { - bids[0].params.region = 'eu'; - serverRequest = spec.buildRequests(bids, bidderRequest); - expect(serverRequest.url).to.equal('https://eu-x.mgid.com/pbjs'); - }); - - it('Returns valid EAST URL', function () { - bids[0].params.region = 'other'; - serverRequest = spec.buildRequests(bids, bidderRequest); - expect(serverRequest.url).to.equal('https://us-east-x.mgid.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - expect(bidderRequest).to.have.property('ortb2'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function () { - afterEach(function() { - config.setConfig({userSync: {syncsPerBidder: USERSYNC_DEFAULT_CONFIG.syncsPerBidder}}); - }); - it('should do nothing on getUserSyncs without inputs', function () { - expect(spec.getUserSyncs()).to.equal(undefined) - }); - it('should return frame object with empty consents', function () { - const sync = spec.getUserSyncs({iframeEnabled: true}) - expect(sync).to.have.length(1) - expect(sync[0]).to.have.property('type', 'iframe') - expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&gdpr_consent=&gdpr=0/) - }); - it('should return frame object with gdpr consent', function () { - const sync = spec.getUserSyncs({iframeEnabled: true}, undefined, {consentString: 'consent', gdprApplies: true}) - expect(sync).to.have.length(1) - expect(sync[0]).to.have.property('type', 'iframe') - expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&gdpr_consent=consent&gdpr=1/) - }); - it('should return frame object with gdpr + usp', function () { - const sync = spec.getUserSyncs({iframeEnabled: true}, undefined, {consentString: 'consent1', gdprApplies: true}, {'consentString': 'consent2'}) - expect(sync).to.have.length(1) - expect(sync[0]).to.have.property('type', 'iframe') - expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/) - }); - it('should return img object with gdpr + usp', function () { - config.setConfig({userSync: {syncsPerBidder: undefined}}); - const sync = spec.getUserSyncs({pixelEnabled: true}, undefined, {consentString: 'consent1', gdprApplies: true}, {'consentString': 'consent2'}) - expect(sync).to.have.length(USERSYNC_DEFAULT_CONFIG.syncsPerBidder) - for (let i = 0; i < USERSYNC_DEFAULT_CONFIG.syncsPerBidder; i++) { - expect(sync[i]).to.have.property('type', 'image') - expect(sync[i]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.gif\?cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/) - } - }); - it('should return frame object with gdpr + usp', function () { - const sync = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, undefined, {consentString: 'consent1', gdprApplies: true}, {'consentString': 'consent2'}) - expect(sync).to.have.length(1) - expect(sync[0]).to.have.property('type', 'iframe') - expect(sync[0]).to.have.property('url').match(/https:\/\/cm\.mgid\.com\/i\.html\?cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/) - }); - it('should return img (pixels) objects with gdpr + usp', function () { - const response = [{body: {ext: {cm: ['http://cm.mgid.com/i.gif?cdsp=1111', 'http://cm.mgid.com/i.gif']}}}] - const sync = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, response, {consentString: 'consent1', gdprApplies: true}, {'consentString': 'consent2'}) - expect(sync).to.have.length(2) - expect(sync[0]).to.have.property('type', 'image') - expect(sync[0]).to.have.property('url').match(/http:\/\/cm\.mgid\.com\/i\.gif\?cdsp=1111&cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/) - expect(sync[1]).to.have.property('type', 'image') - expect(sync[1]).to.have.property('url').match(/http:\/\/cm\.mgid\.com\/i\.gif\?cbuster=\d+&gdpr_consent=consent1&gdpr=1&us_privacy=consent2/) - }); - }); -}); diff --git a/test/spec/modules/michaoBidAdapter_spec.js b/test/spec/modules/michaoBidAdapter_spec.js deleted file mode 100644 index 3bb67afde..000000000 --- a/test/spec/modules/michaoBidAdapter_spec.js +++ /dev/null @@ -1,651 +0,0 @@ -import { cloneDeep } from 'lodash'; -import { domainLogger, spec } from '../../../modules/michaoBidAdapter.js'; -import * as utils from '../../../src/utils.js'; - -describe('Michao Bid Adapter', () => { - let bannerBidRequest; - let videoBidRequest; - let nativeBidRequest; - let videoServerResponse; - let bannerServerResponse; - let domainLoggerMock; - let sandbox; - let triggerPixelSpy; - - beforeEach(() => { - bannerBidRequest = cloneDeep(_bannerBidRequest); - videoBidRequest = cloneDeep(_videoBidRequest); - nativeBidRequest = cloneDeep(_nativeBidRequest); - videoServerResponse = cloneDeep(_videoServerResponse); - bannerServerResponse = cloneDeep(_bannerServerResponse); - sandbox = sinon.createSandbox(); - domainLoggerMock = sandbox.stub(domainLogger); - triggerPixelSpy = sandbox.spy(utils, 'triggerPixel'); - }); - - afterEach(() => { - sandbox.restore(); - }); - - describe('`isBidRequestValid`', () => { - describe('Required parameter behavior', () => { - it('passes when siteId is a number', () => { - bannerBidRequest.params = { - ...bannerBidRequest.params, - site: 123, - }; - - const result = spec.isBidRequestValid(bannerBidRequest); - - expect(result).to.be.true; - expect(domainLoggerMock.invalidSiteError.calledOnce).to.be.false; - }); - - it('detects invalid input when siteId is not a number', () => { - bannerBidRequest.params = { - ...bannerBidRequest.params, - site: '123', - }; - - const result = spec.isBidRequestValid(bannerBidRequest); - - expect(result).to.be.false; - expect(domainLoggerMock.invalidSiteError.calledOnce).to.be.true; - }); - - it('passes when placementId is a string', () => { - bannerBidRequest.params = { - ...bannerBidRequest.params, - placement: '123', - }; - - const result = spec.isBidRequestValid(bannerBidRequest); - - expect(result).to.be.true; - expect(domainLoggerMock.invalidPlacementError.calledOnce).to.be.false; - }); - - it('detects invalid input when placementId is not a string', () => { - bannerBidRequest.params = { - ...bannerBidRequest.params, - placement: 123, - }; - - const result = spec.isBidRequestValid(bannerBidRequest); - - expect(result).to.be.false; - expect(domainLoggerMock.invalidPlacementError.calledOnce).to.be.true; - }); - }); - - describe('Optional parameter behavior', () => { - it('passes when partnerId is not specified', () => { - bannerBidRequest.params = { - ...bannerBidRequest.params, - partner: undefined, - }; - - const result = spec.isBidRequestValid(bannerBidRequest); - - expect(result).to.be.true; - expect(domainLoggerMock.invalidPartnerError.calledOnce).to.be.false; - }); - - it('passes when partnerId is a number', () => { - bannerBidRequest.params = { - ...bannerBidRequest.params, - partner: 6789, - }; - - const result = spec.isBidRequestValid(bannerBidRequest); - - expect(result).to.be.true; - expect(domainLoggerMock.invalidPartnerError.calledOnce).to.be.false; - }); - - it('detects invalid input when partnerId is not a number', () => { - bannerBidRequest.params = { - ...bannerBidRequest.params, - partner: '6789', - }; - - const result = spec.isBidRequestValid(bannerBidRequest); - - expect(result).to.be.false; - expect(domainLoggerMock.invalidPartnerError.calledOnce).to.be.true; - }); - - it('passes when test is not specified', () => { - bannerBidRequest.params = { - ...bannerBidRequest.params, - test: undefined, - }; - - const result = spec.isBidRequestValid(bannerBidRequest); - - expect(result).to.be.true; - expect(domainLoggerMock.invalidTestParamError.calledOnce).to.be.false; - }); - - it('passes when test is a boolean', () => { - bannerBidRequest.params = { - ...bannerBidRequest.params, - test: false, - }; - - const result = spec.isBidRequestValid(bannerBidRequest); - - expect(result).to.be.true; - expect(domainLoggerMock.invalidTestParamError.calledOnce).to.be.false; - }); - - it('detects invalid input when test is not a boolean', () => { - bannerBidRequest.params = { - ...bannerBidRequest.params, - test: 'trueee', - }; - - const result = spec.isBidRequestValid(bannerBidRequest); - - expect(result).to.be.false; - expect(domainLoggerMock.invalidTestParamError.calledOnce).to.be.true; - }); - }); - }); - - describe('`buildRequest`', () => { - describe('Bid request format behavior', () => { - it('creates banner-specific bid request from bid request containing one banner format', () => { - const bidderRequest = { - bids: [bannerBidRequest], - auctionId: bannerBidRequest.auctionId, - bidderRequestId: bannerBidRequest.bidderRequestId, - }; - - const result = spec.buildRequests([bannerBidRequest], bidderRequest); - - expect(result.length).to.equal(1); - expect(result[0].data.imp.length).to.equal(1); - expect(result[0].data.imp[0]).to.have.property( - 'banner' - ); - }); - - it('creates video-specific bid request from bid request containing one video format', () => { - const bidderRequest = { - bids: [videoBidRequest], - auctionId: videoBidRequest.auctionId, - bidderRequestId: videoBidRequest.bidderRequestId, - }; - - const result = spec.buildRequests([videoBidRequest], bidderRequest); - - expect(result.length).to.equal(1); - expect(result[0].data.imp.length).to.equal(1); - }); - - it('creates native-specific bid request from bid request containing one native format', () => { - const bidderRequest = { - bids: [nativeBidRequest], - auctionId: nativeBidRequest.auctionId, - bidderRequestId: nativeBidRequest.bidderRequestId, - }; - - const result = spec.buildRequests([nativeBidRequest], bidderRequest); - - expect(result.length).to.equal(1); - expect(result[0].data.imp.length).to.equal(1); - }); - }); - - describe('Multiple format combination behavior', () => { - it('creates banner and video bid request with two impressions from bid request containing both banner and video formats', () => { - const multiFormatRequest = { - ...bannerBidRequest, - mediaTypes: { - ...bannerBidRequest.mediaTypes, - video: videoBidRequest.mediaTypes.video, - }, - }; - - const bidderRequest = { - bids: [multiFormatRequest], - auctionId: multiFormatRequest.auctionId, - bidderRequestId: multiFormatRequest.bidderRequestId, - }; - - const result = spec.buildRequests([multiFormatRequest], bidderRequest); - - expect(result.length).to.equal(1); - expect(result[0].data.imp.length).to.equal(2); - expect(result[0].data.imp[0]).to.have.property( - 'banner' - ); - }); - - it('creates banner and native bid request with two impressions from bid request containing both banner and native formats', () => { - const multiFormatRequest = { - ...bannerBidRequest, - mediaTypes: { - ...bannerBidRequest.mediaTypes, - native: nativeBidRequest.mediaTypes.native, - }, - }; - - const bidderRequest = { - bids: [multiFormatRequest], - auctionId: multiFormatRequest.auctionId, - bidderRequestId: multiFormatRequest.bidderRequestId, - }; - - const result = spec.buildRequests([multiFormatRequest], bidderRequest); - - expect(result.length).to.equal(1); - expect(result[0].data.imp.length).to.equal(2); - expect(result[0].data.imp[0]).to.have.property( - 'banner' - ); - }); - - it('creates video and native bid request with two impressions from bid request containing both video and native formats', () => { - const multiFormatRequest = { - ...videoBidRequest, - mediaTypes: { - ...videoBidRequest.mediaTypes, - native: nativeBidRequest.mediaTypes.native, - }, - }; - - const bidderRequest = { - bids: [multiFormatRequest], - auctionId: multiFormatRequest.auctionId, - bidderRequestId: multiFormatRequest.bidderRequestId, - }; - - const result = spec.buildRequests([multiFormatRequest], bidderRequest); - - expect(result.length).to.equal(1); - expect(result[0].data.imp.length).to.equal(2); - }); - - it('creates banner, video and native bid request with three impressions from bid request containing all three formats', () => { - const multiFormatRequest = { - ...bannerBidRequest, - mediaTypes: { - ...bannerBidRequest.mediaTypes, - video: videoBidRequest.mediaTypes.video, - native: nativeBidRequest.mediaTypes.native, - }, - }; - - const bidderRequest = { - bids: [multiFormatRequest], - auctionId: multiFormatRequest.auctionId, - bidderRequestId: multiFormatRequest.bidderRequestId, - }; - - const result = spec.buildRequests([multiFormatRequest], bidderRequest); - - expect(result.length).to.equal(1); - expect(result[0].data.imp.length).to.equal(3); - expect(result[0].data.imp[0]).to.have.property( - 'banner' - ); - }); - }); - - describe('Required parameter behavior', () => { - it('sets siteId in site object', () => { - bannerBidRequest.params = { - site: 456, - placement: '123', - }; - const bidderRequest = { - bids: [bannerBidRequest], - auctionId: bannerBidRequest.auctionId, - bidderRequestId: bannerBidRequest.bidderRequestId, - }; - - const result = spec.buildRequests([bannerBidRequest], bidderRequest); - - expect(result[0].data.site.ext.michao.site).to.equal('456'); - }); - - it('sets placementId in impression object', () => { - bannerBidRequest.params = { - site: 456, - placement: '123', - }; - const bidderRequest = { - bids: [bannerBidRequest], - auctionId: bannerBidRequest.auctionId, - bidderRequestId: bannerBidRequest.bidderRequestId, - }; - - const result = spec.buildRequests([bannerBidRequest], bidderRequest); - - expect(result[0].data.imp[0].ext.michao.placement).to.equal('123'); - }); - }); - - describe('Optional parameter behavior', () => { - it('sets partnerId in publisher when specified', () => { - bannerBidRequest.params = { - site: 456, - placement: '123', - partner: 123, - }; - const bidderRequest = { - bids: [bannerBidRequest], - auctionId: bannerBidRequest.auctionId, - bidderRequestId: bannerBidRequest.bidderRequestId, - }; - - const result = spec.buildRequests([bannerBidRequest], bidderRequest); - - expect(result[0].data.site.publisher.ext.michao.partner).to.equal('123'); - }); - - it('sets test in publisher when specified', () => { - bannerBidRequest.params = { - site: 456, - placement: '123', - test: true, - }; - const bidderRequest = { - bids: [bannerBidRequest], - auctionId: bannerBidRequest.auctionId, - bidderRequestId: bannerBidRequest.bidderRequestId, - }; - - const result = spec.buildRequests([bannerBidRequest], bidderRequest); - - expect(result[0].data.test).to.equal(1); - }); - }); - }); - - describe('`interpretResponse`', () => { - it('sets renderer for video bid response when bid request was outstream', () => { - videoBidRequest.mediaTypes.video = { - ...videoBidRequest.mediaTypes.video, - context: 'outstream', - }; - const bidderRequest = { - bids: [videoBidRequest], - auctionId: videoBidRequest.auctionId, - bidderCode: 'michao', - bidderRequestId: videoBidRequest.bidderRequestId, - }; - const request = spec.buildRequests([videoBidRequest], bidderRequest); - - const result = spec.interpretResponse(videoServerResponse, request[0]).bids; - - expect(result[0].renderer.url).to.equal( - 'https://cdn.jsdelivr.net/npm/in-renderer-js@1/dist/in-video-renderer.umd.min.js' - ); - }); - - it('does not set renderer for video bid response when bid request was instream', () => { - videoBidRequest.mediaTypes.video = { - ...videoBidRequest.mediaTypes.video, - context: 'instream', - }; - const bidderRequest = { - bids: [videoBidRequest], - auctionId: videoBidRequest.auctionId, - bidderCode: 'michao', - bidderRequestId: videoBidRequest.bidderRequestId, - }; - const request = spec.buildRequests([videoBidRequest], bidderRequest); - - const result = spec.interpretResponse(videoServerResponse, request[0]).bids; - - expect(result[0].renderer).to.be.undefined; - }); - - it('does not set renderer for banner bid response', () => { - const bidderRequest = { - bids: [bannerBidRequest], - auctionId: bannerBidRequest.auctionId, - bidderCode: 'michao', - bidderRequestId: bannerBidRequest.bidderRequestId, - }; - const request = spec.buildRequests([bannerBidRequest], bidderRequest); - - const result = spec.interpretResponse(bannerServerResponse, request[0]).bids; - - expect(result[0].renderer).to.be.undefined; - }); - }); - - describe('`getUserSyncs`', () => { - it('performs iframe user sync when iframe is enabled', () => { - const syncOptions = { - iframeEnabled: true, - }; - - const result = spec.getUserSyncs(syncOptions, {}, {}, {}); - - expect(result[0].url).to.equal( - 'https://sync.michao-ssp.com/cookie-syncs?' - ); - expect(result[0].type).to.equal('iframe'); - }); - - it('does not perform iframe user sync when iframe is disabled', () => { - const syncOptions = { - iframeEnabled: false, - }; - - const result = spec.getUserSyncs(syncOptions, {}, {}, {}); - - expect(result.length).to.equal(0); - }); - - it('sets GDPR parameters in user sync URL when GDPR applies', () => { - const syncOptions = { - iframeEnabled: true, - }; - const gdprConsent = { - gdprApplies: true, - consentString: 'BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA', - }; - - const result = spec.getUserSyncs(syncOptions, {}, gdprConsent, {}); - - expect(result[0].url).to.equal( - 'https://sync.michao-ssp.com/cookie-syncs?gdpr=1&gdpr_consent=BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA' - ); - expect(result[0].type).to.equal('iframe'); - }); - - it('does not set GDPR parameters in user sync URL when GDPR does not apply', () => { - const syncOptions = { - iframeEnabled: true, - }; - const gdrpConsent = { - gdrpApplies: false, - }; - - const result = spec.getUserSyncs(syncOptions, {}, gdrpConsent, {}); - - expect(result[0].url).to.equal( - 'https://sync.michao-ssp.com/cookie-syncs?' - ); - expect(result[0].type).to.equal('iframe'); - }); - }); - - describe('`onBidBillable`', () => { - it('does not generate billing when billing URL is not included in bid', () => { - const bid = {}; - - spec.onBidBillable(bid); - - expect(triggerPixelSpy.calledOnce).to.be.false; - }); - - it('calls billing url when billing URL is a string', () => { - const bid = { - burl: 'https://example.com/burls', - cpm: 1, - }; - - spec.onBidBillable(bid); - - expect(triggerPixelSpy.calledOnce).to.be.true; - }); - - it('calls bidder billing url when billing URL includes bidder burl', () => { - const bid = { - burl: 'https://example.com/burl?burl=https://bidder.example.com/burl', - cpm: 1, - }; - - spec.onBidBillable(bid); - - expect(triggerPixelSpy.calledTwice).to.be.true; - }); - - it('does not calls billing url when billing URL is not a string', () => { - const bid = { - burl: 123, - }; - - spec.onBidBillable(bid); - - expect(triggerPixelSpy.calledOnce).to.be.false; - }); - }); -}); - -const _bannerBidRequest = { - adUnitCode: 'test-div', - auctionId: 'banner-auction-id', - bidId: 'banner-bid-id', - bidder: 'michao', - bidderRequestId: 'banner-bidder-request-id', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - mediaTypes: { banner: [[300, 250]] }, - params: { - site: 123, - placement: '456', - }, -}; - -const _videoBidRequest = { - adUnitCode: 'test-div', - auctionId: 'video-auction-request-id', - bidId: 'video-bid-id', - bidder: 'michao', - bidderRequestId: 'video-bidder-request-id', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 480], - mimes: ['video/mp4'], - minduration: 0, - maxduration: 120, - protocols: [2] - }, - }, - params: { - site: 123, - placement: '456', - }, -}; - -const _nativeBidRequest = { - adUnitCode: 'test-div', - auctionId: 'native-auction-id', - bidId: 'native-bid-id', - bidder: 'michao', - bidderRequestId: 'native-bidder-request-id', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - mediaTypes: { - native: { - ortb: { - assets: [ - { - id: 1, - title: { - len: 30, - }, - }, - ], - }, - }, - }, - params: { - site: 123, - placement: '456', - }, -}; - -const _videoServerResponse = { - headers: null, - body: { - id: 'video-server-response-id', - seatbid: [ - { - bid: [ - { - id: 'video-bid-id', - impid: 'video-bid-id', - price: 0.18, - adm: '', - adid: '144762342', - adomain: ['https://dummydomain.com'], - iurl: 'iurl', - cid: '109', - crid: 'creativeId', - cat: [], - w: 300, - h: 250, - mtype: 2, - }, - ], - seat: 'seat', - }, - ], - cur: 'USD', - }, -}; - -const _bannerServerResponse = { - headers: null, - body: { - id: 'banner-server-response-id', - seatbid: [ - { - bid: [ - { - id: 'banner-bid-id', - impid: 'banner-bid-id', - price: 0.18, - adm: '
ad
', - adid: '144762342', - adomain: ['https://dummydomain.com'], - iurl: 'iurl', - cid: '109', - crid: 'creativeId', - cat: [], - w: 300, - h: 250, - mtype: 1, - }, - ], - seat: 'seat', - }, - ], - cur: 'USD', - }, -}; diff --git a/test/spec/modules/microadBidAdapter_spec.js b/test/spec/modules/microadBidAdapter_spec.js deleted file mode 100644 index f1a4fbec9..000000000 --- a/test/spec/modules/microadBidAdapter_spec.js +++ /dev/null @@ -1,705 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/microadBidAdapter.js'; -import * as utils from 'src/utils.js'; - -describe('microadBidAdapter', () => { - const bidRequestTemplate = { - bidder: 'microad', - mediaTypes: { - banner: {} - }, - params: { - spot: 'spot-code' - }, - bidId: 'bid-id', - ortb2Imp: { - ext: { - tid: 'transaction-id' - } - } - }; - - describe('isBidRequestValid', () => { - it('should return true when required parameters are set', () => { - const validBids = [ - bidRequestTemplate, - Object.assign({}, bidRequestTemplate, { - mediaTypes: { - native: {} - } - }), - Object.assign({}, bidRequestTemplate, { - mediaTypes: { - video: {} - } - }) - ]; - validBids.forEach(validBid => { - expect(spec.isBidRequestValid(validBid)).to.equal(true); - }); - }); - - it('should return false when required parameters are not set', () => { - const bidWithoutParams = utils.deepClone(bidRequestTemplate); - delete bidWithoutParams.params; - const bidWithoutSpot = utils.deepClone(bidRequestTemplate); - delete bidWithoutSpot.params.spot; - const bidWithoutMediaTypes = utils.deepClone(bidRequestTemplate); - delete bidWithoutMediaTypes.mediaTypes; - - const invalidBids = [ - {}, - bidWithoutParams, - bidWithoutSpot, - bidWithoutMediaTypes, - Object.assign({}, bidRequestTemplate, { - mediaTypes: {} - }) - ]; - invalidBids.forEach(invalidBid => { - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - }); - - describe('buildRequests', () => { - const bidderRequest = { - refererInfo: { - page: 'https://example.com/to', - ref: 'https://example.com/from' - } - }; - const expectedResultTemplate = { - spot: 'spot-code', - url: 'https://example.com/to', - referrer: 'https://example.com/from', - bid_id: 'bid-id', - transaction_id: 'transaction-id', - media_types: 1 - }; - - it('should generate valid media_types', () => { - const bidRequests = [ - bidRequestTemplate, - Object.assign({}, bidRequestTemplate, { - mediaTypes: { - banner: {}, native: {} - } - }), - Object.assign({}, bidRequestTemplate, { - mediaTypes: { - banner: {}, native: {}, video: {} - } - }), - Object.assign({}, bidRequestTemplate, { - mediaTypes: { - native: {} - } - }), - Object.assign({}, bidRequestTemplate, { - mediaTypes: { - native: {}, video: {} - } - }), - Object.assign({}, bidRequestTemplate, { - mediaTypes: { - video: {} - } - }), - Object.assign({}, bidRequestTemplate, { - mediaTypes: { - banner: {}, video: {} - } - }) - ]; - - const results = bidRequests.map(bid => { - const requests = spec.buildRequests([bid], bidderRequest); - return requests[0].data.media_types; - }); - expect(results).to.deep.equal([ - 1, // BANNER - 3, // BANNER + NATIVE - 7, // BANNER + NATIVE + VIDEO - 2, // NATIVE - 6, // NATIVE + VIDEO - 4, // VIDEO - 5 // BANNER + VIDEO - ]); - }); - - it('should use window.location.href if there is no page', () => { - const bidderRequestWithoutCanonicalUrl = { - refererInfo: { - ref: 'https://example.com/from' - } - }; - const requests = spec.buildRequests([bidRequestTemplate], bidderRequestWithoutCanonicalUrl); - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt, - url: window.location.href - }) - ); - }); - }); - - it('should generate valid request with no optional parameters', () => { - const requests = spec.buildRequests([bidRequestTemplate], bidderRequest); - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt - }) - ); - }); - }); - - it('should add url_macro parameter to response if request parameters contain url', () => { - const bidRequestWithUrl = Object.assign({}, bidRequestTemplate, { - params: { - spot: 'spot-code', - url: '${COMPASS_EXT_URL}url-macro' - } - }); - const requests = spec.buildRequests([bidRequestWithUrl], bidderRequest); - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt, - url_macro: 'url-macro' - }) - ); - }); - }); - - it('should add referrer_macro parameter to response if request parameters contain referrer', () => { - const bidRequestWithReferrer = Object.assign({}, bidRequestTemplate, { - params: { - spot: 'spot-code', - referrer: '${COMPASS_EXT_REF}referrer-macro' - } - }); - const requests = spec.buildRequests([bidRequestWithReferrer], bidderRequest); - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt, - referrer_macro: 'referrer-macro' - }) - ); - }); - }); - - it('should add ifa parameter to response if request parameters contain ifa', () => { - const bidRequestWithIfa = Object.assign({}, bidRequestTemplate, { - params: { - spot: 'spot-code', - ifa: '${COMPASS_EXT_IFA}ifa' - } - }); - const requests = spec.buildRequests([bidRequestWithIfa], bidderRequest); - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt, - ifa: 'ifa' - }) - ); - }); - }); - - it('should add appid parameter to response if request parameters contain appid', () => { - const bidRequestWithAppid = Object.assign({}, bidRequestTemplate, { - params: { - spot: 'spot-code', - appid: '${COMPASS_EXT_APPID}appid' - } - }); - const requests = spec.buildRequests([bidRequestWithAppid], bidderRequest); - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt, - appid: 'appid' - }) - ); - }); - }); - - it('should not add geo parameter to response even if request parameters contain geo', () => { - const bidRequestWithGeo = Object.assign({}, bidRequestTemplate, { - params: { - spot: 'spot-code', - geo: '${COMPASS_EXT_GEO}35.655275,139.693771' - } - }); - const requests = spec.buildRequests([bidRequestWithGeo], bidderRequest); - requests.forEach(request => { - expect(request.data).to.not.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt, - geo: '35.655275,139.693771' - }) - ); - }); - }); - - it('should not add geo parameter to response if request parameters contain invalid geo', () => { - const bidRequestWithGeo = Object.assign({}, bidRequestTemplate, { - params: { - spot: 'spot-code', - geo: '${COMPASS_EXT_GEO}invalid format geo' - } - }); - const requests = spec.buildRequests([bidRequestWithGeo], bidderRequest); - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt - }) - ); - }); - }); - - it('should always use the HTTPS endpoint https://s-rtb-pb.send.microad.jp/prebid even if it is served via HTTP', () => { - const requests = spec.buildRequests([bidRequestTemplate], bidderRequest); - requests.forEach(request => { - expect(request.url.lastIndexOf('https', 0) === 0).to.be.true; - }); - }); - - it('should not add Liveramp identity link and Audience ID if it is not available in request parameters', () => { - const bidRequestWithOutLiveramp = Object.assign({}, bidRequestTemplate, { - userId: {} - }); - const requests = spec.buildRequests([bidRequestWithOutLiveramp], bidderRequest) - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt - }) - ); - }) - }); - - Object.entries({ - 'IM-UID': { - userId: {imuid: 'imuid-sample'}, - expected: {aids: JSON.stringify([{type: 6, id: 'imuid-sample'}])} - }, - 'ID5 ID': { - userId: {id5id: {uid: 'id5id-sample'}}, - expected: {aids: JSON.stringify([{type: 8, id: 'id5id-sample'}])} - }, - 'Unified ID': { - userId: {tdid: 'unified-sample'}, - expected: {aids: JSON.stringify([{type: 9, id: 'unified-sample'}])} - }, - 'Novatiq Snowflake ID': { - userId: {novatiq: {snowflake: 'novatiq-sample'}}, - expected: {aids: JSON.stringify([{type: 10, id: 'novatiq-sample'}])} - }, - 'AudienceOne User ID': { - userId: {dacId: {id: 'audience-one-sample'}}, - expected: {aids: JSON.stringify([{type: 12, id: 'audience-one-sample'}])} - }, - 'Ramp ID and Liveramp identity': { - userId: {idl_env: 'idl-env-sample'}, - expected: {idl_env: 'idl-env-sample', aids: JSON.stringify([{type: 13, id: 'idl-env-sample'}])} - }, - 'Criteo ID': { - userId: {criteoId: 'criteo-id-sample'}, - expected: {aids: JSON.stringify([{type: 14, id: 'criteo-id-sample'}])} - }, - 'Shared ID': { - userId: {pubcid: 'shared-id-sample'}, - expected: {aids: JSON.stringify([{type: 15, id: 'shared-id-sample'}])} - } - }).forEach(([test, arg]) => { - it(`should add ${test} if it is available in request parameters`, () => { - const bidRequestWithUserId = { ...bidRequestTemplate, userId: arg.userId } - const requests = spec.buildRequests([bidRequestWithUserId], bidderRequest) - requests.forEach((request) => { - expect(request.data).to.deep.equal({ - ...expectedResultTemplate, - cbt: request.data.cbt, - ...arg.expected - }) - }) - }) - }) - - Object.entries({ - 'ID5 ID': { - userId: {id5id: {uid: 'id5id-sample'}}, - userIdAsEids: [ - { - source: 'id5-sync.com', - uids: [{id: 'id5id-sample', aType: 1, ext: {linkType: 2, abTestingControlGroup: false}}] - } - ], - expected: { - aids: JSON.stringify([{type: 8, id: 'id5id-sample', ext: {linkType: 2, abTestingControlGroup: false}}]) - } - }, - 'Unified ID': { - userId: {tdid: 'unified-sample'}, - userIdAsEids: [ - { - source: 'adserver.org', - uids: [{id: 'unified-sample', aType: 1, ext: {rtiPartner: 'TDID'}}] - } - ], - expected: {aids: JSON.stringify([{type: 9, id: 'unified-sample', ext: {rtiPartner: 'TDID'}}])} - }, - 'not add': { - userId: {id5id: {uid: 'id5id-sample'}}, - userIdAsEids: [], - expected: { - aids: JSON.stringify([{type: 8, id: 'id5id-sample'}]) - } - } - }).forEach(([test, arg]) => { - it(`should ${test} ext if it is available in request parameters`, () => { - const bidRequestWithUserId = { - ...bidRequestTemplate, - userId: arg.userId, - userIdAsEids: arg.userIdAsEids - } - const requests = spec.buildRequests([bidRequestWithUserId], bidderRequest) - requests.forEach((request) => { - expect(request.data).to.deep.equal({ - ...expectedResultTemplate, - cbt: request.data.cbt, - ...arg.expected - }) - }) - }); - }) - - describe('should send gpid', () => { - it('from gpid', () => { - const bidRequest = Object.assign({}, bidRequestTemplate, { - ortb2Imp: { - ext: { - tid: 'transaction-id', - gpid: '1111/2222', - data: { - pbadslot: '3333/4444' - } - } - } - }); - const requests = spec.buildRequests([bidRequest], bidderRequest) - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt, - gpid: '1111/2222', - pbadslot: '3333/4444' - }) - ); - }) - }) - - it('from pbadslot', () => { - const bidRequest = Object.assign({}, bidRequestTemplate, { - ortb2Imp: { - ext: { - tid: 'transaction-id', - gpid: '3333/4444', - data: {} - } - } - }); - const requests = spec.buildRequests([bidRequest], bidderRequest) - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt, - gpid: '3333/4444', - }) - ); - }) - }) - }) - - const notGettingGpids = { - 'they are not existing': bidRequestTemplate, - 'they are blank': { - ortb2Imp: { - ext: { - tid: 'transaction-id', - gpid: '', - data: { - pbadslot: '' - } - } - } - } - } - - Object.entries(notGettingGpids).forEach(([testTitle, param]) => { - it(`should not send gpid because ${testTitle}`, () => { - const bidRequest = Object.assign({}, bidRequestTemplate, param); - const requests = spec.buildRequests([bidRequest], bidderRequest) - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt, - }) - ); - expect(request.data.gpid).to.be.undefined; - expect(request.data.pbadslot).to.be.undefined; - }) - }) - }) - - it('should send adservname', () => { - const bidRequest = Object.assign({}, bidRequestTemplate, { - ortb2Imp: { - ext: { - tid: 'transaction-id', - data: { - adserver: { - name: 'gam' - } - } - } - } - }); - const requests = spec.buildRequests([bidRequest], bidderRequest) - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt, - adservname: 'gam' - }) - ); - }) - }) - - const notGettingAdservnames = { - 'it is not existing': bidRequestTemplate, - 'it is blank': { - ortb2Imp: { - ext: { - tid: 'transaction-id', - data: { - adserver: { - name: '' - } - } - } - } - } - } - - Object.entries(notGettingAdservnames).forEach(([testTitle, param]) => { - it(`should not send adservname because ${testTitle}`, () => { - const bidRequest = Object.assign({}, bidRequestTemplate, param); - const requests = spec.buildRequests([bidRequest], bidderRequest) - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt, - }) - ); - expect(request.data.adservname).to.be.undefined; - }) - }) - }) - - it('should send adservadslot', () => { - const bidRequest = Object.assign({}, bidRequestTemplate, { - ortb2Imp: { - ext: { - tid: 'transaction-id', - data: { - adserver: { - adslot: '/1111/home' - } - } - } - } - }); - const requests = spec.buildRequests([bidRequest], bidderRequest) - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt, - adservadslot: '/1111/home' - }) - ); - }) - }) - - const notGettingAdservadslots = { - 'it is not existing': bidRequestTemplate, - 'it is blank': { - ortb2Imp: { - ext: { - tid: 'transaction-id', - data: { - adserver: { - adslot: '' - } - } - } - } - } - } - - Object.entries(notGettingAdservadslots).forEach(([testTitle, param]) => { - it(`should not send adservadslot because ${testTitle}`, () => { - const bidRequest = Object.assign({}, bidRequestTemplate, param); - const requests = spec.buildRequests([bidRequest], bidderRequest) - requests.forEach(request => { - expect(request.data).to.deep.equal( - Object.assign({}, expectedResultTemplate, { - cbt: request.data.cbt, - }) - ); - expect(request.data.adservadslot).to.be.undefined; - }) - }) - }) - }); - - describe('interpretResponse', () => { - const serverResponseTemplate = { - body: { - requestId: 'request-id', - cpm: 0.1, - width: 200, - height: 100, - ad: '
test
', - ttl: 10, - creativeId: 'creative-id', - netRevenue: true, - currency: 'JPY', - meta: { - advertiserDomains: ['foobar.com'] - } - } - }; - const expectedBidResponseTemplate = { - requestId: 'request-id', - cpm: 0.1, - width: 200, - height: 100, - ad: '
test
', - ttl: 10, - creativeId: 'creative-id', - netRevenue: true, - currency: 'JPY', - meta: { - advertiserDomains: ['foobar.com'] - } - }; - - it('should return nothing if server response body does not contain cpm', () => { - const emptyResponse = { - body: {} - }; - - expect(spec.interpretResponse(emptyResponse)).to.deep.equal([]); - }); - - it('should return nothing if returned cpm is zero', () => { - const serverResponse = { - body: { - cpm: 0 - } - }; - - expect(spec.interpretResponse(serverResponse)).to.deep.equal([]); - }); - - it('should return a valid bidResponse without deal id if serverResponse is valid, has a nonzero cpm and no deal id', () => { - expect(spec.interpretResponse(serverResponseTemplate)).to.deep.equal([expectedBidResponseTemplate]); - }); - - it('should return a valid bidResponse with deal id if serverResponse is valid, has a nonzero cpm and a deal id', () => { - const serverResponseWithDealId = Object.assign({}, utils.deepClone(serverResponseTemplate)); - serverResponseWithDealId.body['dealId'] = 10001; - const expectedBidResponse = Object.assign({}, expectedBidResponseTemplate, { - dealId: 10001 - }); - - expect(spec.interpretResponse(serverResponseWithDealId)).to.deep.equal([expectedBidResponse]); - }); - - it('should return a valid bidResponse without meta if serverResponse is valid, has a nonzero cpm and no deal id', () => { - const serverResponseWithoutMeta = Object.assign({}, utils.deepClone(serverResponseTemplate)); - delete serverResponseWithoutMeta.body.meta; - const expectedBidResponse = Object.assign({}, expectedBidResponseTemplate, { - meta: { advertiserDomains: [] } - }); - - expect(spec.interpretResponse(serverResponseWithoutMeta)).to.deep.equal([expectedBidResponse]); - }); - }); - - describe('getUserSyncs', () => { - const BOTH_ENABLED = { - iframeEnabled: true, pixelEnabled: true - }; - const IFRAME_ENABLED = { - iframeEnabled: true, pixelEnabled: false - }; - const PIXEL_ENABLED = { - iframeEnabled: false, pixelEnabled: true - }; - const BOTH_DISABLED = { - iframeEnabled: false, pixelEnabled: false - }; - const serverResponseTemplate = { - body: { - syncUrls: { - iframe: ['https://www.example.com/iframe1', 'https://www.example.com/iframe2'], - image: ['https://www.example.com/image1', 'https://www.example.com/image2'] - } - } - }; - const expectedIframeSyncs = [ - {type: 'iframe', url: 'https://www.example.com/iframe1'}, - {type: 'iframe', url: 'https://www.example.com/iframe2'} - ]; - const expectedImageSyncs = [ - {type: 'image', url: 'https://www.example.com/image1'}, - {type: 'image', url: 'https://www.example.com/image2'} - ]; - - it('should return nothing if no sync urls are set', () => { - const serverResponse = utils.deepClone(serverResponseTemplate); - serverResponse.body.syncUrls.iframe = []; - serverResponse.body.syncUrls.image = []; - - const syncs = spec.getUserSyncs(BOTH_ENABLED, [serverResponse]); - expect(syncs).to.deep.equal([]); - }); - - it('should return nothing if sync is disabled', () => { - const syncs = spec.getUserSyncs(BOTH_DISABLED, [serverResponseTemplate]); - expect(syncs).to.deep.equal([]); - }); - - it('should register iframe and image sync urls if sync is enabled', () => { - const syncs = spec.getUserSyncs(BOTH_ENABLED, [serverResponseTemplate]); - expect(syncs).to.deep.equal(expectedIframeSyncs.concat(expectedImageSyncs)); - }); - - it('should register iframe sync urls if iframe is enabled', () => { - const syncs = spec.getUserSyncs(IFRAME_ENABLED, [serverResponseTemplate]); - expect(syncs).to.deep.equal(expectedIframeSyncs); - }); - - it('should register image sync urls if image is enabled', () => { - const syncs = spec.getUserSyncs(PIXEL_ENABLED, [serverResponseTemplate]); - expect(syncs).to.deep.equal(expectedImageSyncs); - }); - }); -}); diff --git a/test/spec/modules/minutemediaBidAdapter_spec.js b/test/spec/modules/minutemediaBidAdapter_spec.js deleted file mode 100644 index c8f41a427..000000000 --- a/test/spec/modules/minutemediaBidAdapter_spec.js +++ /dev/null @@ -1,744 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/minutemediaBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import {BANNER, NATIVE, VIDEO} from '../../../src/mediaTypes.js'; -import * as utils from 'src/utils.js'; -import {decorateAdUnitsWithNativeParams} from '../../../src/native.js'; - -const ENDPOINT = 'https://hb.minutemedia-prebid.com/hb-mm-multi'; -const TEST_ENDPOINT = 'https://hb.minutemedia-prebid.com/hb-multi-mm-test'; -const TTL = 360; -/* eslint no-console: ["error", { allow: ["log", "warn", "error"] }] */ - -describe('minutemediaAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [['640', '480']], - 'params': { - 'org': 'jdye8weeyirk00000001' - } - }; - - it('should return true when required params are passed', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not found', function () { - const newBid = Object.assign({}, bid); - delete newBid.params; - newBid.params = { - 'org': null - }; - expect(spec.isBidRequestValid(newBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[640, 480]], - 'params': { - 'org': 'jdye8weeyirk00000001' - }, - 'bidId': '299ffc8cca0b87', - 'loop': 1, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'video': { - 'playerSize': [[640, 480]], - 'context': 'instream', - 'plcmt': 1 - } - }, - }, - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'params': { - 'org': 'jdye8weeyirk00000001' - }, - 'bidId': '299ffc8cca0b87', - 'loop': 1, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'banner': { - } - }, - }, - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'params': { - 'org': 'jdye8weeyirk00000001' - }, - 'bidId': '299ffc8cca0b87', - 'loop': 1, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ 300, 250 ] - ] - }, - 'video': { - 'playerSize': [[640, 480]], - 'context': 'instream', - 'plcmt': 1 - }, - 'native': { - 'ortb': { - 'assets': [ - { - 'id': 1, - 'required': 1, - 'img': { - 'type': 3, - 'w': 300, - 'h': 200, - } - }, - { - 'id': 2, - 'required': 1, - 'title': { - 'len': 80 - } - }, - { - 'id': 3, - 'required': 1, - 'data': { - 'type': 1 - } - } - ] - } - }, - }, - } - ]; - - const testModeBidRequests = [ - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[640, 480]], - 'params': { - 'org': 'jdye8weeyirk00000001', - 'testMode': true - }, - 'bidId': '299ffc8cca0b87', - 'loop': 2, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - } - ]; - - const bidderRequest = { - bidderCode: 'minutemedia', - } - const placementId = '12345678'; - const api = [1, 2]; - const mimes = ['application/javascript', 'video/mp4', 'video/quicktime']; - const protocols = [2, 3, 5, 6]; - - it('sends the placementId to ENDPOINT via POST', function () { - bidRequests[0].params.placementId = placementId; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].placementId).to.equal(placementId); - }); - - it('sends the plcmt to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].plcmt).to.equal(1); - }); - - it('sends the is_wrapper parameter to ENDPOINT via POST', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('is_wrapper'); - expect(request.data.params.is_wrapper).to.equal(false); - }); - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('sends bid request to TEST ENDPOINT via POST', function () { - const request = spec.buildRequests(testModeBidRequests, bidderRequest); - expect(request.url).to.equal(TEST_ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('should send the correct bid Id', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].bidId).to.equal('299ffc8cca0b87'); - }); - - it('should send the correct supported api array', function () { - bidRequests[0].mediaTypes.video.api = api; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].api).to.be.an('array'); - expect(request.data.bids[0].api).to.eql([1, 2]); - }); - - it('should send the correct mimes array', function () { - bidRequests[0].mediaTypes.video.mimes = mimes; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].mimes).to.be.an('array'); - expect(request.data.bids[0].mimes).to.eql(['application/javascript', 'video/mp4', 'video/quicktime']); - }); - - it('should send the correct protocols array', function () { - bidRequests[0].mediaTypes.video.protocols = protocols; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].protocols).to.be.an('array'); - expect(request.data.bids[0].protocols).to.eql([2, 3, 5, 6]); - }); - - it('should send the correct sizes array', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].sizes).to.be.an('array'); - expect(request.data.bids[0].sizes).to.equal(bidRequests[0].sizes) - expect(request.data.bids[1].sizes).to.be.an('array'); - expect(request.data.bids[1].sizes).to.equal(bidRequests[1].sizes) - expect(request.data.bids[2].sizes).to.be.an('array'); - expect(request.data.bids[2].sizes).to.eql(bidRequests[2].sizes) - }); - - it('should send nativeOrtbRequest in native bid request', function () { - decorateAdUnitsWithNativeParams(bidRequests) - const request = spec.buildRequests(bidRequests, bidderRequest); - assert.deepEqual(request.data.bids[2].nativeOrtbRequest, bidRequests[2].mediaTypes.native.ortb) - }); - - it('should send the correct media type', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].mediaType).to.equal(VIDEO) - expect(request.data.bids[1].mediaType).to.equal(BANNER) - expect(request.data.bids[2].mediaType.split(',')).to.include.members([VIDEO, NATIVE, BANNER]) - }); - - it('should respect syncEnabled option', function() { - config.setConfig({ - userSync: { - syncEnabled: false, - filterSettings: { - all: { - bidders: '*', - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('cs_method'); - }); - - it('should respect "iframe" filter settings', function () { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - iframe: { - bidders: [spec.code], - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'iframe'); - }); - - it('should respect "all" filter settings', function () { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - all: { - bidders: [spec.code], - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'iframe'); - }); - - it('should send the pixel user sync param if userSync is enabled and no "iframe" or "all" configs are present', function () { - config.resetConfig(); - config.setConfig({ - userSync: { - syncEnabled: true, - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'pixel'); - }); - - it('should respect total exclusion', function() { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - image: { - bidders: [spec.code], - filter: 'exclude' - }, - iframe: { - bidders: [spec.code], - filter: 'exclude' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('cs_method'); - }); - - it('should have us_privacy param if usPrivacy is available in the bidRequest', function () { - const bidderRequestWithUSP = Object.assign({uspConsent: '1YNN'}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithUSP); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('us_privacy', '1YNN'); - }); - - it('should have an empty us_privacy param if usPrivacy is missing in the bidRequest', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('us_privacy'); - }); - - it('should not send the gdpr param if gdprApplies is false in the bidRequest', function () { - const bidderRequestWithGDPR = Object.assign({gdprConsent: {gdprApplies: false}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('gdpr'); - expect(request.data.params).to.not.have.property('gdpr_consent'); - }); - - it('should send the gdpr param if gdprApplies is true in the bidRequest', function () { - const bidderRequestWithGDPR = Object.assign({gdprConsent: {gdprApplies: true, consentString: 'test-consent-string'}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('gdpr', true); - expect(request.data.params).to.have.property('gdpr_consent', 'test-consent-string'); - }); - - it('should not send the gpp param if gppConsent is false in the bidRequest', function () { - const bidderRequestWithGPP = Object.assign({gppConsent: false}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGPP); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('gpp'); - expect(request.data.params).to.not.have.property('gpp_sid'); - }); - - it('should send the gpp param if gppConsent is true in the bidRequest', function () { - const bidderRequestWithGPP = Object.assign({gppConsent: {gppString: 'test-consent-string', applicableSections: [7]}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGPP); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('gpp', 'test-consent-string'); - expect(request.data.params.gpp_sid[0]).to.be.equal(7); - }); - - it('should have schain param if it is available in the bidRequest', () => { - bidderRequest.ortb2 = { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [{ asi: 'indirectseller.com', sid: '00001', hp: 1 }], - } - } - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('schain', '1.0,1!indirectseller.com,00001,1,,,'); - }); - - it('should set flooPrice to getFloor.floor value if it is greater than params.floorPrice', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.getFloor = () => { - return { - currency: 'USD', - floor: 3.32 - } - } - bid.params.floorPrice = 0.64; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0]).to.be.an('object'); - expect(request.data.bids[0]).to.have.property('floorPrice', 3.32); - }); - - it('should set floorPrice to params.floorPrice value if it is greater than getFloor.floor', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.getFloor = () => { - return { - currency: 'USD', - floor: 0.8 - } - } - bid.params.floorPrice = 1.5; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0]).to.be.an('object'); - expect(request.data.bids[0]).to.have.property('floorPrice', 1.5); - }); - - it('should check sua param in bid request', function() { - const sua = { - 'platform': { - 'brand': 'macOS', - 'version': ['12', '4', '0'] - }, - 'browsers': [ - { - 'brand': 'Chromium', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Google Chrome', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Not;A=Brand', - 'version': [ '99', '0', '0', '0' ] - } - ], - 'mobile': 0, - 'model': '', - 'bitness': '64', - 'architecture': 'x86' - } - const bid = utils.deepClone(bidRequests[0]); - bid.ortb2 = { - 'device': { - 'sua': { - 'platform': { - 'brand': 'macOS', - 'version': [ '12', '4', '0' ] - }, - 'browsers': [ - { - 'brand': 'Chromium', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Google Chrome', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Not;A=Brand', - 'version': [ '99', '0', '0', '0' ] - } - ], - 'mobile': 0, - 'model': '', - 'bitness': '64', - 'architecture': 'x86' - } - } - } - const requestWithSua = spec.buildRequests([bid], bidderRequest); - const data = requestWithSua.data; - expect(data.bids[0].sua).to.exist; - expect(data.bids[0].sua).to.deep.equal(sua); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].sua).to.not.exist; - }); - - describe('COPPA Param', function() { - it('should set coppa equal 0 in bid request if coppa is set to false', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].coppa).to.be.equal(0); - }); - - it('should set coppa equal 1 in bid request if coppa is set to true', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.ortb2 = { - 'regs': { - 'coppa': true, - } - }; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0].coppa).to.be.equal(1); - }); - }); - }); - - describe('interpretResponse', function () { - const response = { - params: { - currency: 'USD', - netRevenue: true, - }, - bids: [{ - cpm: 12.5, - vastXml: '', - width: 640, - height: 480, - requestId: '21e12606d47ba7', - creativeId: 'creative-id', - nurl: 'http://example.com/win/1234', - adomain: ['abc.com'], - mediaType: VIDEO - }, - { - cpm: 12.5, - ad: '""', - width: 300, - height: 250, - requestId: '21e12606d47ba7', - creativeId: 'creative-id', - nurl: 'http://example.com/win/1234', - adomain: ['abc.com'], - mediaType: BANNER - }, - { - cpm: 12.5, - width: 300, - height: 200, - requestId: '21e12606d47ba7', - adomain: ['abc.com'], - creativeId: 'creative-id', - nurl: 'http://example.com/win/1234', - mediaType: NATIVE, - native: { - body: 'Advertise with Rise', - clickUrl: 'https://risecodes.com', - cta: 'Start now', - image: { - width: 300, - height: 200, - url: 'https://sdk.streamrail.com/media/rise-image.jpg' - }, - sponsoredBy: 'Rise', - title: 'Rise Ad Tech Solutions' - } - }] - }; - - const expectedVideoResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 640, - height: 480, - ttl: TTL, - creativeId: 'creative-id', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: VIDEO, - meta: { - mediaType: VIDEO, - advertiserDomains: ['abc.com'] - }, - vastXml: '', - }; - - const expectedBannerResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 300, - height: 250, - ttl: TTL, - creativeId: 'creative-id', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: BANNER, - meta: { - mediaType: BANNER, - advertiserDomains: ['abc.com'] - }, - ad: '""' - }; - - const expectedNativeResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 300, - height: 200, - ttl: TTL, - creativeId: 'creative-id', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: NATIVE, - meta: { - mediaType: NATIVE, - advertiserDomains: ['abc.com'] - }, - native: { - ortb: { - body: 'Advertise with Rise', - clickUrl: 'https://risecodes.com', - cta: 'Start now', - image: { - width: 300, - height: 200, - url: 'https://sdk.streamrail.com/media/rise-image.jpg', - }, - sponsoredBy: 'Rise', - title: 'Rise Ad Tech Solutions' - } - }, - }; - - it('should get correct bid response', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[0]).to.deep.equal(expectedVideoResponse); - expect(result[1]).to.deep.equal(expectedBannerResponse); - expect(result[2]).to.deep.equal(expectedNativeResponse); - }); - - it('video type should have vastXml key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[0].vastXml).to.equal(expectedVideoResponse.vastXml) - }); - - it('banner type should have ad key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[1].ad).to.equal(expectedBannerResponse.ad) - }); - - it('native type should have native key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[2].native).to.eql(expectedNativeResponse.native) - }); - }) - - describe('getUserSyncs', function() { - const imageSyncResponse = { - body: { - params: { - userSyncPixels: [ - 'https://image-sync-url.test/1', - 'https://image-sync-url.test/2', - 'https://image-sync-url.test/3' - ] - } - } - }; - - const iframeSyncResponse = { - body: { - params: { - userSyncURL: 'https://iframe-sync-url.test' - } - } - }; - - it('should register all img urls from the response', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true }, [imageSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'image', - url: 'https://image-sync-url.test/1' - }, - { - type: 'image', - url: 'https://image-sync-url.test/2' - }, - { - type: 'image', - url: 'https://image-sync-url.test/3' - } - ]); - }); - - it('should register the iframe url from the response', function() { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [iframeSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://iframe-sync-url.test' - } - ]); - }); - - it('should register both image and iframe urls from the responses', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, [iframeSyncResponse, imageSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://iframe-sync-url.test' - }, - { - type: 'image', - url: 'https://image-sync-url.test/1' - }, - { - type: 'image', - url: 'https://image-sync-url.test/2' - }, - { - type: 'image', - url: 'https://image-sync-url.test/3' - } - ]); - }); - - it('should handle an empty response', function() { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, []); - expect(syncs).to.deep.equal([]); - }); - - it('should handle when user syncs are disabled', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: false }, [imageSyncResponse]); - expect(syncs).to.deep.equal([]); - }); - }) - - describe('onBidWon', function() { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - - it('Should trigger pixel if bid nurl', function() { - const bid = { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [['640', '480']], - 'nurl': 'http://example.com/win/1234', - 'params': { - 'org': 'jdye8weeyirk00000001' - } - }; - - spec.onBidWon(bid); - expect(utils.triggerPixel.callCount).to.equal(1) - }) - }) -}); diff --git a/test/spec/modules/missenaBidAdapter_spec.js b/test/spec/modules/missenaBidAdapter_spec.js deleted file mode 100644 index f4e09a981..000000000 --- a/test/spec/modules/missenaBidAdapter_spec.js +++ /dev/null @@ -1,371 +0,0 @@ -import { expect } from 'chai'; -import { spec, storage } from 'modules/missenaBidAdapter.js'; -import { BANNER } from '../../../src/mediaTypes.js'; -import { config } from 'src/config.js'; -import * as autoplay from 'libraries/autoplayDetection/autoplay.js'; -import { getWinDimensions } from '../../../src/utils.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -const REFERRER = 'https://referer'; -const REFERRER2 = 'https://referer2'; -const COOKIE_DEPRECATION_LABEL = 'test'; -const CONSENT_STRING = 'AAAAAAAAA=='; -const API_KEY = 'PA-XXXXXX'; -const GPID = '/11223344/AdUnit#300x250'; - -describe('Missena Adapter', function () { - getGlobal().bidderSettings = { - missena: { - storageAllowed: true, - }, - }; - const sandbox = sinon.createSandbox(); - sandbox.stub(config, 'getConfig').withArgs('coppa').returns(true); - sandbox.stub(autoplay, 'isAutoplayEnabled').returns(false); - const viewport = { width: getWinDimensions().innerWidth, height: getWinDimensions().innerHeight }; - - const bidId = 'abc'; - const bid = { - bidder: 'missena', - bidId: bidId, - mediaTypes: { banner: { sizes: [[1, 1]] } }, - ortb2Imp: { - ext: { gpid: GPID }, - }, - ortb2: { - device: { - ext: { cdep: COOKIE_DEPRECATION_LABEL }, - }, - source: { - ext: { - schain: { - validation: 'strict', - config: { - ver: '1.0', - }, - }, - }, - }, - }, - params: { - apiKey: API_KEY, - placement: 'sticky', - formats: ['sticky-banner'], - }, - getFloor: (inputParams) => { - if (inputParams.mediaType === BANNER) { - return { - currency: 'EUR', - floor: 3.5, - }; - } else { - return {}; - } - }, - }; - const bidWithoutFloor = { - bidder: 'missena', - bidId: bidId, - mediaTypes: { banner: { sizes: [1, 1] } }, - params: { - apiKey: API_KEY, - placement: 'sticky', - formats: ['sticky-banner'], - }, - }; - - const bidderRequest = { - gdprConsent: { - consentString: CONSENT_STRING, - gdprApplies: true, - }, - uspConsent: 'IDO', - refererInfo: { - topmostLocation: REFERRER, - canonicalUrl: 'https://canonical', - }, - ortb2: { - regs: { coppa: 1, ext: { gdpr: 1 }, us_privacy: 'IDO' }, - user: { - ext: { consent: CONSENT_STRING }, - }, - device: { - w: screen.width, - h: screen.height, - ext: { cdep: COOKIE_DEPRECATION_LABEL }, - }, - }, - }; - - const bids = [bid, bidWithoutFloor]; - describe('codes', function () { - it('should return a bidder code of missena', function () { - expect(spec.code).to.equal('missena'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true if the apiKey param is present', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false if the apiKey is missing', function () { - expect( - spec.isBidRequestValid(Object.assign(bid, { params: {} })), - ).to.equal(false); - }); - - it('should return false if the apiKey is an empty string', function () { - expect( - spec.isBidRequestValid(Object.assign(bid, { params: { apiKey: '' } })), - ).to.equal(false); - }); - }); - - describe('buildRequests', function () { - let getDataFromLocalStorageStub = sinon.stub( - storage, - 'getDataFromLocalStorage', - ); - - const requests = spec.buildRequests(bids, bidderRequest); - const request = requests[0]; - const payload = JSON.parse(request.data); - const payloadNoFloor = JSON.parse(requests[1].data); - - it('should send disabled autoplay', function () { - expect(payload.autoplay).to.equal(0); - }); - - it('should contain coppa', function () { - expect(payload.ortb2.regs.coppa).to.equal(1); - }); - sandbox.restore(); - - it('should contain uspConsent', function () { - expect(payload.ortb2.regs.us_privacy).to.equal('IDO'); - }); - - it('should contain schain', function () { - expect(payload.schain.config.ver).to.equal('1.0'); - }); - - it('should return as many server requests as bidder requests', function () { - expect(requests.length).to.equal(2); - }); - - it('should have a post method', function () { - expect(request.method).to.equal('POST'); - }); - - it('should send the bidder id', function () { - expect(payload.request_id).to.equal(bidId); - }); - - it('should send placement', function () { - expect(payload.params.placement).to.equal('sticky'); - }); - - it('should send formats', function () { - expect(payload.params.formats).to.eql(['sticky-banner']); - }); - - it('should send viewport', function () { - expect(payload.viewport.width).to.equal(viewport.width); - expect(payload.viewport.height).to.equal(viewport.height); - }); - - it('should send gdpr consent information to the request', function () { - expect(payload.ortb2.user.ext.consent).to.equal(CONSENT_STRING); - expect(payload.ortb2.regs.ext.gdpr).to.equal(1); - }); - - it('should forward GPID from ortb2Imp into ortb2.ext', function () { - expect(payload.ortb2.ext.gpid).to.equal(GPID); - }); - - it('should send floor data', function () { - expect(payload.floor).to.equal(3.5); - expect(payload.floor_currency).to.equal('EUR'); - }); - it('should not send floor data if not available', function () { - expect(payloadNoFloor.floor).to.equal(undefined); - expect(payloadNoFloor.floor_currency).to.equal(undefined); - }); - it('should send the idempotency key', function () { - expect(window.msna_ik).to.not.equal(undefined); - expect(payload.ik).to.equal(window.msna_ik); - }); - - it('should send screen', function () { - expect(payload.ortb2.device.w).to.equal(screen.width); - expect(payload.ortb2.device.h).to.equal(screen.height); - }); - - it('should send size', function () { - expect(payload.sizes[0].width).to.equal(1); - expect(payload.sizes[0].height).to.equal(1); - }); - - it('should send single size', function () { - expect(payloadNoFloor.sizes[0].width).to.equal(1); - expect(payloadNoFloor.sizes[0].height).to.equal(1); - }); - - getDataFromLocalStorageStub.restore(); - getDataFromLocalStorageStub = sinon.stub( - storage, - 'getDataFromLocalStorage', - ); - const localStorageData = { - [`missena.missena.capper.remove-bubble.${bid.params.apiKey}`]: - JSON.stringify({ - expiry: new Date().getTime() + 600_000, // 10 min into the future - }), - }; - getDataFromLocalStorageStub.callsFake((key) => localStorageData[key]); - const cappedRequests = spec.buildRequests(bids, bidderRequest); - - it('should not participate if capped', function () { - expect(cappedRequests.length).to.equal(0); - }); - - const localStorageDataSamePage = { - [`missena.missena.capper.remove-bubble.${bid.params.apiKey}`]: - JSON.stringify({ - expiry: new Date().getTime() + 600_000, // 10 min into the future - referer: REFERRER, - }), - }; - - getDataFromLocalStorageStub.callsFake( - (key) => localStorageDataSamePage[key], - ); - const cappedRequestsSamePage = spec.buildRequests(bids, bidderRequest); - - it('should not participate if capped on same page', function () { - expect(cappedRequestsSamePage.length).to.equal(0); - }); - - const localStorageDataOtherPage = { - [`missena.missena.capper.remove-bubble.${bid.params.apiKey}`]: - JSON.stringify({ - expiry: new Date().getTime() + 600_000, // 10 min into the future - referer: REFERRER2, - }), - }; - - getDataFromLocalStorageStub.callsFake( - (key) => localStorageDataOtherPage[key], - ); - const cappedRequestsOtherPage = spec.buildRequests(bids, bidderRequest); - - it('should participate if capped on a different page', function () { - expect(cappedRequestsOtherPage.length).to.equal(2); - }); - - it('should send the prebid version', function () { - expect(payload.version).to.equal('prebid.js@$prebid.version$'); - }); - - it('should send cookie deprecation', function () { - expect(payload.ortb2.device.ext.cdep).to.equal(COOKIE_DEPRECATION_LABEL); - }); - }); - - describe('interpretResponse', function () { - const serverResponse = { - requestId: bidId, - cpm: 0.5, - currency: 'USD', - ad: '', - meta: { - advertiserDomains: ['missena.com'], - }, - }; - - const serverTimeoutResponse = { - requestId: bidId, - timeout: true, - ad: '', - }; - - const serverEmptyAdResponse = { - requestId: bidId, - cpm: 0.5, - currency: 'USD', - ad: '', - }; - - it('should return a proper bid response', function () { - const result = spec.interpretResponse({ body: serverResponse }, bid); - - expect(result.length).to.equal(1); - - expect(Object.keys(result[0])).to.have.members( - Object.keys(serverResponse), - ); - }); - - it('should return an empty response when the server answers with a timeout', function () { - const result = spec.interpretResponse( - { body: serverTimeoutResponse }, - bid, - ); - expect(result).to.deep.equal([]); - }); - - it('should return an empty response when the server answers with an empty ad', function () { - const result = spec.interpretResponse( - { body: serverEmptyAdResponse }, - bid, - ); - expect(result).to.deep.equal([]); - }); - }); - - describe('getUserSyncs', function () { - const syncFrameUrl = 'https://sync.missena.io/iframe'; - const consentString = 'sampleString'; - const iframeEnabledOptions = { - iframeEnabled: true, - }; - const iframeDisabledOptions = { - iframeEnabled: false, - }; - - it('should return userSync when iframeEnabled', function () { - const userSync = spec.getUserSyncs(iframeEnabledOptions, []); - - expect(userSync.length).to.be.equal(1); - expect(userSync[0].type).to.be.equal('iframe'); - expect(userSync[0].url).to.be.equal(`${syncFrameUrl}?t=${API_KEY}`); - }); - - it('should return empty array when iframeEnabled is false', function () { - const userSync = spec.getUserSyncs(iframeDisabledOptions, []); - expect(userSync.length).to.be.equal(0); - }); - - it('sync frame url should contain gdpr data when present', function () { - const userSync = spec.getUserSyncs(iframeEnabledOptions, [], { - gdprApplies: true, - consentString, - }); - const expectedUrl = `${syncFrameUrl}?t=${API_KEY}&gdpr=1&gdpr_consent=${consentString}`; - expect(userSync.length).to.be.equal(1); - expect(userSync[0].type).to.be.equal('iframe'); - expect(userSync[0].url).to.be.equal(expectedUrl); - }); - it('sync frame url should contain gdpr data when present (gdprApplies false)', function () { - const userSync = spec.getUserSyncs(iframeEnabledOptions, [], { - gdprApplies: false, - consentString, - }); - const expectedUrl = `${syncFrameUrl}?t=${API_KEY}&gdpr=0&gdpr_consent=${consentString}`; - expect(userSync.length).to.be.equal(1); - expect(userSync[0].type).to.be.equal('iframe'); - expect(userSync[0].url).to.be.equal(expectedUrl); - }); - }); -}); diff --git a/test/spec/modules/mobfoxpbBidAdapter_spec.js b/test/spec/modules/mobfoxpbBidAdapter_spec.js deleted file mode 100644 index a5bd3697d..000000000 --- a/test/spec/modules/mobfoxpbBidAdapter_spec.js +++ /dev/null @@ -1,479 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/mobfoxpbBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'mobfoxpb'; - -describe('MobfoxHBBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://bes.mobfox.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.traffic) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); -}); diff --git a/test/spec/modules/mobianRtdProvider_spec.js b/test/spec/modules/mobianRtdProvider_spec.js deleted file mode 100644 index 0794e9915..000000000 --- a/test/spec/modules/mobianRtdProvider_spec.js +++ /dev/null @@ -1,281 +0,0 @@ -import { expect } from 'chai'; -import sinon from 'sinon'; -import * as ajax from 'src/ajax.js'; -import * as gptUtils from 'libraries/gptUtils/gptUtils.js'; -import { - CONTEXT_KEYS, - AP_VALUES, - CATEGORIES, - EMOTIONS, - GENRES, - RISK, - SENTIMENT, - THEMES, - TONES, - extendBidRequestConfig, - fetchContextData, - getConfig, - getContextData, - makeContextDataToKeyValuesReducer, - makeDataFromResponse, - setTargeting, -} from 'modules/mobianRtdProvider.js'; - -describe('Mobian RTD Submodule', function () { - let ajaxStub; - let bidReqConfig; - let setKeyValueSpy; - - const mockResponse = JSON.stringify({ - meta: { - url: 'https://example.com', - has_results: true - }, - results: { - ap: { a0: [], a1: [2313, 12], p0: [1231231, 212], p1: [231, 419] }, - mobianContentCategories: [], - mobianEmotions: ['affection'], - mobianGenres: [], - mobianRisk: 'low', - mobianSentiment: 'positive', - mobianThemes: [], - mobianTones: [], - } - }); - - const mockContextData = { - [AP_VALUES]: { a0: [], a1: [2313, 12], p0: [1231231, 212], p1: [231, 419] }, - [CATEGORIES]: [], - [EMOTIONS]: ['affection'], - [GENRES]: [], - [RISK]: 'low', - [SENTIMENT]: 'positive', - [THEMES]: [], - [TONES]: [], - } - - const mockKeyValues = { - 'mobian_ap_a1': ['2313', '12'], - 'mobian_ap_p0': ['1231231', '212'], - 'mobian_ap_p1': ['231', '419'], - 'mobian_emotions': ['affection'], - 'mobian_risk': 'low', - 'mobian_sentiment': 'positive', - } - - const mockConfig = { - prefix: 'mobian', - publisherTargeting: [AP_VALUES, EMOTIONS, RISK, SENTIMENT, THEMES, TONES, GENRES], - advertiserTargeting: [AP_VALUES, EMOTIONS, RISK, SENTIMENT, THEMES, TONES, GENRES], - } - - beforeEach(function () { - bidReqConfig = { - ortb2Fragments: { - global: { - site: { - ext: { - data: {} - } - } - } - } - }; - - setKeyValueSpy = sinon.spy(gptUtils, 'setKeyValue'); - }); - - afterEach(function () { - ajaxStub.restore(); - setKeyValueSpy.restore(); - }); - - describe('fetchContextData', function () { - it('should return fetched context data', async function () { - ajaxStub = sinon.stub(ajax, 'ajaxBuilder').returns(function(url, callbacks) { - callbacks.success(mockResponse); - }); - - const contextData = await fetchContextData(); - expect(contextData).to.deep.equal(mockResponse); - }); - }); - - describe('makeDataFromResponse', function () { - it('should format context data response', async function () { - const data = makeDataFromResponse(mockResponse); - expect(data).to.deep.equal(mockContextData); - }); - }); - - describe('getContextData', function () { - it('should return formatted context data', async function () { - ajaxStub = sinon.stub(ajax, 'ajaxBuilder').returns(function(url, callbacks) { - callbacks.success(mockResponse); - }); - - const data = await getContextData(); - expect(data).to.deep.equal(mockContextData); - }); - }); - - describe('setTargeting', function () { - it('should set targeting key-value pairs as per config', function () { - const parsedConfig = { - prefix: 'mobian', - publisherTargeting: [AP_VALUES, EMOTIONS, RISK, SENTIMENT, THEMES, TONES, GENRES], - }; - setTargeting(parsedConfig, mockContextData); - - expect(setKeyValueSpy.callCount).to.equal(6); - expect(setKeyValueSpy.calledWith('mobian_ap_a1', ['2313', '12'])).to.equal(true); - expect(setKeyValueSpy.calledWith('mobian_ap_p0', ['1231231', '212'])).to.equal(true); - expect(setKeyValueSpy.calledWith('mobian_ap_p1', ['231', '419'])).to.equal(true); - expect(setKeyValueSpy.calledWith('mobian_emotions', ['affection'])).to.equal(true); - expect(setKeyValueSpy.calledWith('mobian_risk', 'low')).to.equal(true); - expect(setKeyValueSpy.calledWith('mobian_sentiment', 'positive')).to.equal(true); - - expect(setKeyValueSpy.calledWith('mobian_ap_a0')).to.equal(false); - expect(setKeyValueSpy.calledWith('mobian_themes')).to.equal(false); - expect(setKeyValueSpy.calledWith('mobian_tones')).to.equal(false); - expect(setKeyValueSpy.calledWith('mobian_genres')).to.equal(false); - }); - - it('should not set key-value pairs if context data is empty', function () { - const parsedConfig = { - prefix: 'mobian', - publisherTargeting: [AP_VALUES, EMOTIONS, RISK, SENTIMENT, THEMES, TONES, GENRES], - }; - setTargeting(parsedConfig, {}); - - expect(setKeyValueSpy.callCount).to.equal(0); - }); - - it('should only set key-value pairs for the keys specified in config', function () { - const parsedConfig = { - prefix: 'mobian', - publisherTargeting: [EMOTIONS, RISK], - }; - - setTargeting(parsedConfig, mockContextData); - - expect(setKeyValueSpy.callCount).to.equal(2); - expect(setKeyValueSpy.calledWith('mobian_emotions', ['affection'])).to.equal(true); - expect(setKeyValueSpy.calledWith('mobian_risk', 'low')).to.equal(true); - - expect(setKeyValueSpy.calledWith('mobian_ap_a0')).to.equal(false); - expect(setKeyValueSpy.calledWith('mobian_ap_a1')).to.equal(false); - expect(setKeyValueSpy.calledWith('mobian_ap_p0')).to.equal(false); - expect(setKeyValueSpy.calledWith('mobian_ap_p1')).to.equal(false); - expect(setKeyValueSpy.calledWith('mobian_themes')).to.equal(false); - expect(setKeyValueSpy.calledWith('mobian_tones')).to.equal(false); - expect(setKeyValueSpy.calledWith('mobian_genres')).to.equal(false); - }); - }); - - describe('extendBidRequestConfig', function () { - it('should extend bid request config with context data', function () { - const extendedConfig = extendBidRequestConfig(bidReqConfig, mockContextData, mockConfig); - expect(extendedConfig.ortb2Fragments.global.site.ext.data).to.deep.equal(mockKeyValues); - }); - - it('should not override existing data', function () { - bidReqConfig.ortb2Fragments.global.site.ext.data = { - existing: 'data' - }; - - const extendedConfig = extendBidRequestConfig(bidReqConfig, mockContextData, mockConfig); - expect(extendedConfig.ortb2Fragments.global.site.ext.data).to.deep.equal({ - existing: 'data', - ...mockKeyValues - }); - }); - - it('should create data object if missing', function () { - delete bidReqConfig.ortb2Fragments.global.site.ext.data; - const extendedConfig = extendBidRequestConfig(bidReqConfig, mockContextData, mockConfig); - expect(extendedConfig.ortb2Fragments.global.site.ext.data).to.deep.equal(mockKeyValues); - }); - }); - - describe('getConfig', function () { - it('should return config with correct keys', function () { - const config = getConfig({ - name: 'mobianBrandSafety', - params: { - prefix: 'mobiantest', - publisherTargeting: [AP_VALUES], - advertiserTargeting: [EMOTIONS], - } - }); - expect(config).to.deep.equal({ - prefix: 'mobiantest', - publisherTargeting: [AP_VALUES], - advertiserTargeting: [EMOTIONS], - }); - }); - - it('should set default values for configs not set', function () { - const config = getConfig({ - name: 'mobianBrandSafety', - params: { - publisherTargeting: [AP_VALUES], - } - }); - expect(config).to.deep.equal({ - prefix: 'mobian', - publisherTargeting: [AP_VALUES], - advertiserTargeting: [], - }); - }); - - it('should set default values if not provided', function () { - const config = getConfig({}); - expect(config).to.deep.equal({ - prefix: 'mobian', - publisherTargeting: [], - advertiserTargeting: [], - }); - }); - - it('should set default values if no config is provided', function () { - const config = getConfig(); - expect(config).to.deep.equal({ - prefix: 'mobian', - publisherTargeting: [], - advertiserTargeting: [], - }); - }); - - it('should set all tarteging values if value is true', function () { - const config = getConfig({ - name: 'mobianBrandSafety', - params: { - publisherTargeting: true, - advertiserTargeting: true, - } - }); - expect(config).to.deep.equal({ - prefix: 'mobian', - publisherTargeting: CONTEXT_KEYS, - advertiserTargeting: CONTEXT_KEYS, - }); - }); - }); - - describe('makeContextDataToKeyValuesReducer', function () { - it('should format context data to key-value pairs', function () { - const config = getConfig({ - name: 'mobianBrandSafety', - params: { - prefix: 'mobian', - publisherTargeting: true, - advertiserTargeting: true, - } - }); - const keyValues = Object.entries(mockContextData).reduce(makeContextDataToKeyValuesReducer(config), []); - const keyValuesObject = Object.fromEntries(keyValues); - expect(keyValuesObject).to.deep.equal(mockKeyValues); - }); - }); -}); diff --git a/test/spec/modules/mobilefuseBidAdapter_spec.js b/test/spec/modules/mobilefuseBidAdapter_spec.js deleted file mode 100644 index b234dbc40..000000000 --- a/test/spec/modules/mobilefuseBidAdapter_spec.js +++ /dev/null @@ -1,184 +0,0 @@ -import * as utils from '../../../src/utils.js'; -import { expect } from 'chai'; -import { spec } from 'modules/mobilefuseBidAdapter.js'; -import { config } from '../../../src/config.js'; -import { userSync } from '../../../src/userSync.js'; - -const bidRequest = { - bidder: 'mobilefuse', - params: { - placement_id: 'test-placement-id', - bidfloor: 1.25, - }, - adUnitCode: 'ad-slot-1', - mediaTypes: { - banner: { - sizes: [[300, 250]], - } - }, - bidId: 'bid-id-123', - transactionId: 'txn-id-123', - gpid: 'test-gpid', - userIdAsEids: [{ - source: 'sharedid.org', - uids: [{ id: '01ERJ8WABCXYZ6789', atype: 1 }], - }], - schain: { - ver: '1.0', - complete: 1, - nodes: [{ asi: 'exchange.com', sid: 'abc123', hp: 1 }], - }, -}; - -const bidderRequest = { - bidderCode: 'mobilefuse', - bids: [bidRequest], - uspConsent: '1YNN', - gppConsent: { - gppString: 'GPP_CONSENT_STRING', - applicableSections: [7], - }, -}; - -const serverResponse = { - body: { - seatbid: [{ - bid: [{ - impid: bidRequest.bidId, - price: 2.5, - adm: '
Ad Markup
', - crid: 'creative123', - w: 300, - h: 250, - mtype: 1, - adomain: ['example.com'], - }], - }], - } -}; - -describe('mobilefuseBidAdapter', function () { - it('should validate bids', function () { - expect(spec.isBidRequestValid(bidRequest)).to.be.true; - expect(spec.isBidRequestValid({params: {}})).to.be.false; - }); - - it('should build a valid request payload', function () { - const request = spec.buildRequests([bidRequest], bidderRequest); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://mfx.mobilefuse.com/prebidjs'); - expect(request.data).to.be.an('object'); - - const imp = request.data.imp[0]; - expect(imp.tagid).to.equal('test-placement-id'); - expect(imp.bidfloor).to.equal(1.25); - expect(imp.ext.gpid).to.equal('test-gpid'); - }); - - it('should include regs in the request', function () { - const request = spec.buildRequests([bidRequest], bidderRequest); - const regs = request.data.regs; - expect(regs.us_privacy).to.equal('1YNN'); - expect(regs.gpp).to.equal('GPP_CONSENT_STRING'); - expect(regs.gpp_sid).to.deep.equal([7]); - }); - - describe('should include ifsync in the request', function () { - let sandbox; - let utilsMock; - - beforeEach(() => { - utilsMock = sinon.mock(utils); - sandbox = sinon.createSandbox(); - utilsMock = sandbox.mock(utils); - }); - - afterEach(() => { - utilsMock.restore(); - sandbox.restore(); - }); - - it('the ifsync flag should be false for user-sync iframe disabled', function () { - sandbox.stub(config, 'getConfig') - .withArgs('userSync') - .returns({ syncEnabled: true }); - - sandbox.stub(userSync, 'canBidderRegisterSync') - .withArgs('iframe', 'mobilefuse') - .returns(false); - - const request = spec.buildRequests([bidRequest], bidderRequest); - const ext = request.data.ext.prebid.mobilefuse; - expect(ext.ifsync).to.equal(false); - }); - - it('the ifsync flag should be true for user-sync iframe enabled', function () { - sandbox.stub(config, 'getConfig') - .withArgs('userSync') - .returns({ syncEnabled: true }); - - sandbox.stub(userSync, 'canBidderRegisterSync') - .withArgs('iframe', 'mobilefuse') - .returns(true); - - const request = spec.buildRequests([bidRequest], bidderRequest); - const ext = request.data.ext.prebid.mobilefuse; - expect(ext.ifsync).to.equal(true); - }); - }); - - it('should interpret the response correctly', function () { - const request = spec.buildRequests([bidRequest], bidderRequest); - const bid = spec.interpretResponse(serverResponse, request)[0]; - expect(bid.cpm).to.equal(2.5); - expect(bid.ad).to.equal('
Ad Markup
'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.meta.advertiserDomains).to.deep.equal(['example.com']); - }); - - it('should return user syncs with proper query params when iframe sync is enabled', function () { - const syncs = spec.getUserSyncs( - {iframeEnabled: true}, - [], - null, - bidderRequest.uspConsent, - bidderRequest.gppConsent, - ); - - expect(syncs).to.be.an('array').that.has.lengthOf(1); - const sync = syncs[0]; - expect(sync.type).to.equal('iframe'); - expect(sync.url).to.include('https://mfx.mobilefuse.com/usync'); - expect(sync.url).to.include('gpp=GPP_CONSENT_STRING'); - expect(sync.url).to.include('gpp_sid=7'); - }); - - it('should return pixel user syncs when iframe sync is disabled', function () { - const response = { - body: { - ...serverResponse.body, - ext: { - syncs: [ - 'https://abc.com/pixel?id=123', - 'https://xyz.com/pixel?id=456', - ] - } - } - }; - - const syncs = spec.getUserSyncs( - {iframeEnabled: false}, - [response], - null, - bidderRequest.uspConsent, - bidderRequest.gppConsent, - ); - - expect(syncs).to.be.an('array').that.has.lengthOf(2); - expect(syncs[0].type).to.equal('image'); - expect(syncs[0].url).to.equal('https://abc.com/pixel?id=123'); - expect(syncs[1].type).to.equal('image'); - expect(syncs[1].url).to.equal('https://xyz.com/pixel?id=456'); - }); -}); diff --git a/test/spec/modules/mobkoiAnalyticsAdapter_spec.js b/test/spec/modules/mobkoiAnalyticsAdapter_spec.js deleted file mode 100644 index a3b785f44..000000000 --- a/test/spec/modules/mobkoiAnalyticsAdapter_spec.js +++ /dev/null @@ -1,516 +0,0 @@ -import mobkoiAnalyticsAdapter, { DEBUG_EVENT_LEVELS, utils, SUB_PAYLOAD_UNIQUE_FIELDS_LOOKUP, SUB_PAYLOAD_TYPES, PROD_PREBID_JS_INTEGRATION_ENDPOINT } from 'modules/mobkoiAnalyticsAdapter.js'; -import * as prebidUtils from 'src/utils'; -import adapterManager from '../../../src/adapterManager.js'; -import * as events from 'src/events.js'; -import { EVENTS } from 'src/constants.js'; -import sinon from 'sinon'; - -const defaultTimeout = 10000; -const requestId = 'test-request-id' -const publisherId = 'mobkoiPublisherId' -const bidId = 'test-bid-id' -const bidderCode = 'mobkoi' -const transactionId = 'test-transaction-id' -const impressionId = 'test-impression-id' -const adUnitId = 'test-ad-unit-id' -const auctionId = 'test-auction-id' -const integrationBaseUrl = 'http://integrationBaseUrl'; - -const adm = '
test ad
'; -const lurl = 'test.com/loss'; -const nurl = 'test.com/win'; - -const performStandardAuction = (auctionEvents) => { - auctionEvents.forEach(auctionEvent => { - events.emit(auctionEvent.event, auctionEvent.data); - }); -} - -const getOrtb2 = () => ({ - site: { - publisher: { - id: publisherId, - ext: { integrationEndpoint: integrationBaseUrl } - } - } -}) - -const getBidderResponse = () => ({ - body: { - id: bidId, - cur: 'USD', - seatbid: [ - { - seat: 'mobkoi_debug', - bid: [ - { - id: bidId, - impid: impressionId, - cid: 'campaign_1', - crid: 'creative_1', - price: 1, - cur: [ - 'USD' - ], - adomain: [ - 'advertiser.com' - ], - adm, - w: 300, - h: 250, - mtype: 1, - lurl, - nurl - } - ] - } - ], - } -}) - -const getMockEvents = () => { - const sizes = [800, 300]; - const timestamp = Date.now(); - const auctionOrBidError = {timestamp, error: 'error', bidderRequest: { bidderRequestId: requestId }} - - return { - AUCTION_TIMEOUT: auctionOrBidError, - AUCTION_INIT: { - timestamp, - auctionId, - auctionStatus: 'inProgress', - adUnits: [{ - adUnitId: adUnitId, - code: 'banner-ad', - mediaTypes: { banner: { sizes: [sizes] } }, - transactionId, - }], - bidderRequests: [{ - bidderRequestId: requestId, - bids: [getBidRequest()], - ortb2: getOrtb2() - }] - }, - BID_RESPONSE: { - auctionId, - timestamp, - requestId: bidId, - bidId, - ortbId: requestId, - cpm: 1.5, - currency: 'USD', - ortbBidResponse: { - id: requestId, - impid: bidId, - price: 1.5 - } - }, - NO_BID: auctionOrBidError, - BIDDER_DONE: { - timestamp, - auctionId, - bidderRequestId: requestId, - bids: [getBidRequest()], - ortb2: getOrtb2() - }, - BID_WON: { - timestamp, - auctionId, - requestId, - bidId, - ortbBidResponse: { - id: requestId, - impid: bidId - } - }, - AUCTION_END: { - timestamp, - auctionId, - auctionStatus: 'completed' - }, - AD_RENDER_SUCCEEDED: { - bid: { - timestamp, - requestId: bidId, - bidId, - ortbId: requestId, - ad: '
test ad
' - }, - doc: { visibilityState: 'visible' } - }, - AD_RENDER_FAILED: { - bid: { - timestamp, - requestId: bidId, - bidId, - ortbId: requestId, - ad: '
test ad
' - }, - reason: 'error', - message: 'error' - }, - BIDDER_ERROR: auctionOrBidError, - BID_REJECTED: { - timestamp, - error: 'error', - bidderRequestId: requestId - } - } -} - -const getBidRequest = () => ({ - bidder: bidderCode, - adUnitCode: 'banner-ad', - transactionId, - adUnitId, - bidId: bidId, - bidderRequestId: requestId, - auctionId, - ortb2: getOrtb2() -}) - -const getBidderRequest = () => ({ - bidderCode, - auctionId, - bidderRequestId: requestId, - bids: [getBidRequest()], - ortb2: getOrtb2() -}) - -describe('mobkoiAnalyticsAdapter', function () { - let sandbox; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - sandbox.stub(prebidUtils, 'logInfo'); - sandbox.stub(prebidUtils, 'logWarn'); - sandbox.stub(prebidUtils, 'logError'); - }); - - afterEach(function () { - sandbox.restore(); - }); - - it('should registers with the adapter manager', function () { - // should refer to the BIDDER_CODE in the mobkoiAnalyticsAdapter - const adapter = adapterManager.getAnalyticsAdapter('mobkoi'); - expect(adapter).to.exist; - // should refer to the GVL_ID in the mobkoiAnalyticsAdapter - expect(adapter.gvlid).to.equal(898); - expect(adapter.adapter).to.equal(mobkoiAnalyticsAdapter); - }); - - describe('Tracks events', function () { - let adapter; - let sandbox; - let pushEventSpy; - let flushEventsSpy; - let triggerBeaconSpy; - let postAjaxStub; - let sendGetRequestStub; - - beforeEach(function () { - adapter = mobkoiAnalyticsAdapter; - sandbox = sinon.createSandbox({ - useFakeTimers: { - now: new Date(2025, 0, 8, 0, 1, 33, 425), - }, - }); - - // Disable then reenable the adapter in order to have a fresh context - adapter.disableAnalytics(); - adapter.enableAnalytics({ - options: { - endpoint: integrationBaseUrl, - pid: 'test-pid', - timeout: defaultTimeout, - } - }); - - // Create spies after enabling analytics to ensure localContext exists - postAjaxStub = sandbox.stub(utils, 'postAjax'); - sendGetRequestStub = sandbox.stub(utils, 'sendGetRequest'); - pushEventSpy = sandbox.spy(adapter.localContext, 'pushEventToAllBidContexts'); - flushEventsSpy = sandbox.spy(adapter.localContext, 'flushAllDebugEvents'); - triggerBeaconSpy = sandbox.spy(adapter.localContext, 'triggerAllLossBidLossBeacon'); - }); - - afterEach(function () { - adapter.disableAnalytics(); - sandbox.restore(); - postAjaxStub.resetHistory(); - sendGetRequestStub.resetHistory(); - }); - - it('should call sendGetRequest while tracking BIDDER_DONE / BID_WON events', function () { - const { AUCTION_INIT, BID_RESPONSE, BID_WON } = getMockEvents(); - const bidResponse = { - ...BID_RESPONSE, - ortbBidResponse: { - ...BID_RESPONSE.ortbBidResponse, - lurl, - bidWin: false, - lurlTriggered: false - } - }; - const eventSequence = [ - { event: EVENTS.AUCTION_INIT, data: AUCTION_INIT }, - { event: EVENTS.BID_RESPONSE, data: bidResponse }, - { event: EVENTS.BID_WON, data: BID_WON }, - ] - - performStandardAuction(eventSequence); - - expect(sendGetRequestStub.callCount).to.equal(1); - expect(sendGetRequestStub.firstCall.args[0]).to.equal(lurl); - }) - - it('should call postAjax while tracking BIDDER_DONE event', function () { - const { AUCTION_INIT, BID_RESPONSE, BIDDER_DONE } = getMockEvents(); - - const eventSequence = [ - { event: EVENTS.AUCTION_INIT, data: AUCTION_INIT }, - { event: EVENTS.BID_RESPONSE, data: BID_RESPONSE }, - { event: EVENTS.BIDDER_DONE, data: BIDDER_DONE } - ]; - - performStandardAuction(eventSequence); - - expect(postAjaxStub.calledOnce).to.be.true; - expect(postAjaxStub.firstCall.args[0]).to.equal(`${integrationBaseUrl}/debug`); - }) - - it('should track complete auction workflow in correct sequence and trigger a loss beacon', function () { - const { AUCTION_INIT, BID_RESPONSE, AUCTION_END, AD_RENDER_SUCCEEDED, BIDDER_DONE } = getMockEvents(); - - const eventSequence = [ - { event: EVENTS.AUCTION_INIT, data: AUCTION_INIT }, - { event: EVENTS.BID_RESPONSE, data: BID_RESPONSE }, - { event: EVENTS.AD_RENDER_SUCCEEDED, data: AD_RENDER_SUCCEEDED }, - { event: EVENTS.AUCTION_END, data: AUCTION_END }, - { event: EVENTS.BIDDER_DONE, data: BIDDER_DONE } - ]; - - performStandardAuction(eventSequence); - expect(pushEventSpy.callCount).to.equal(3); // AUCTION_INIT, AUCTION_END, BIDDER_DONE - expect(flushEventsSpy.callCount).to.equal(1); - expect(triggerBeaconSpy.callCount).to.equal(1); // BIDDER_DONE - }); - - it('should track errors events', function () { - const { AUCTION_TIMEOUT, NO_BID, BID_REJECTED, BIDDER_ERROR, AD_RENDER_FAILED } = getMockEvents(); - - const eventSequence = [ - { event: EVENTS.AUCTION_TIMEOUT, data: AUCTION_TIMEOUT }, - { event: EVENTS.NO_BID, data: NO_BID }, - { event: EVENTS.BID_REJECTED, data: BID_REJECTED }, - { event: EVENTS.BIDDER_ERROR, data: BIDDER_ERROR }, - { event: EVENTS.AD_RENDER_FAILED, data: AD_RENDER_FAILED } - ]; - - performStandardAuction(eventSequence); - - expect(pushEventSpy.callCount).to.equal(3); // AUCTION_TIMEOUT, NO_BID, BIDDER_ERROR - }); - - it('should push unexpected error events to the localContext', async function () { - const { AUCTION_INIT } = getMockEvents(); - delete AUCTION_INIT.auctionStatus; - try { - await adapter.track({ - eventType: EVENTS.AUCTION_INIT, - args: AUCTION_INIT - }); - } catch { - expect(pushEventSpy.calledOnce).to.be.true; - const errorEventCall = pushEventSpy.getCall(0); - - expect(errorEventCall.args[0]).to.deep.include({ - eventType: EVENTS.AUCTION_INIT, - level: DEBUG_EVENT_LEVELS.error, - note: 'Error occurred when processing this event.' - }); - - const errorPayload = errorEventCall.args[0].subPayloads[`errorInEvent_${EVENTS.AUCTION_INIT}`]; - expect(errorPayload).to.exist; - expect(errorPayload.error).to.include('Unable to determine track args type'); - } - }); - }) - - describe('utils', function () { - let bidderRequest; - - beforeEach(function () { - bidderRequest = getBidderRequest(); - }); - - describe('isMobkoiBid', function () { - it('should return true when the bid is from mobkoi', function () { - expect(utils.isMobkoiBid(bidderRequest)).to.be.true; - }); - it('should return false when the bid is not from mobkoi', function () { - bidderRequest.bidderCode = 'anything'; - expect(utils.isMobkoiBid(bidderRequest)).to.be.false; - }); - }); - - describe('getOrtbId', function () { - it('should return the ortbId from the prebid request object (i.e bidderRequestId)', function () { - expect(utils.getOrtbId(bidderRequest)).to.equal(bidderRequest.bidderRequestId); - }); - - it('should return the ortbId from the prebid response object (i.e seatBidId)', function () { - const customBidRequest = { ...bidderRequest, seatBidId: bidderRequest.bidderRequestId }; - delete customBidRequest.bidderRequestId; - expect(utils.getOrtbId(customBidRequest)).to.equal(bidderRequest.bidderRequestId); - }); - - it('should return the ortbId from the interpreted prebid response object (i.e ortbId)', function () { - const customBidRequest = { ...bidderRequest, ortbId: bidderRequest.bidderRequestId }; - delete customBidRequest.bidderRequestId; - expect(utils.getOrtbId(customBidRequest)).to.equal(bidderRequest.bidderRequestId); - }); - - it('should return the ortbId from the ORTB request object (i.e has imp)', function () { - const customBidRequest = { ...bidderRequest, imp: {}, id: bidderRequest.bidderRequestId }; - delete customBidRequest.bidderRequestId; - expect(utils.getOrtbId(customBidRequest)).to.equal(bidderRequest.bidderRequestId); - }); - - it('should throw error when ortbId is missing', function () { - delete bidderRequest.bidderRequestId; - expect(() => { - utils.getOrtbId(bidderRequest); - }).to.throw(); - }); - }) - - describe('getImpId', function () { - let bidResponse; - beforeEach(function () { - const bidderResponse = getBidderResponse(); - bidResponse = bidderResponse.body.seatbid[0].bid[0]; - }); - - it('should return the impId from the impid field', function () { - expect(utils.getImpId(bidResponse)).to.equal(bidResponse.impid); - }); - - it('should return the impId from the requestId field', function () { - const customBidResponse = { ...bidResponse, requestId: bidResponse.impid }; - delete customBidResponse.impid; - expect(utils.getImpId(customBidResponse)).to.equal(bidResponse.impid); - }); - - it('should return the impId from the bidId field', function () { - const customBidResponse = { ...bidResponse, bidId: bidResponse.impid }; - delete customBidResponse.impid; - expect(utils.getImpId(customBidResponse)).to.equal(bidResponse.impid); - }); - - it('should return null if impId is missing', function () { - expect(utils.getImpId({})).to.be.null; - }); - }) - - describe('getPublisherId', function () { - it('should return the publisherId from the given object', function () { - expect(utils.getPublisherId(bidderRequest)).to.equal(bidderRequest.ortb2.site.publisher.id); - }); - - it('should throw error when publisherId is missing', function () { - delete bidderRequest.ortb2.site.publisher.id; - expect(() => { - utils.getPublisherId(bidderRequest); - }).to.throw(); - }); - }) - - describe('getIntegrationEndpoint', function () { - it('should return the integrationEndpoint from the given object', function () { - expect(utils.getIntegrationEndpoint(bidderRequest)) - .to.equal(integrationBaseUrl); - }); - - it('should use the default integrationEndpoint when integrationEndpoint is missing in ortb2.site.publisher.ext', function () { - delete bidderRequest.ortb2.site.publisher.ext.integrationEndpoint; - - expect(utils.getIntegrationEndpoint(bidderRequest)) - .to.equal(PROD_PREBID_JS_INTEGRATION_ENDPOINT); - }); - }) - - describe('determineObjType', function () { - [null, undefined, 123, 'string', true].forEach(value => { - it(`should throw an error when input is ${value}`, function() { - expect(() => { - utils.determineObjType(value); - }).to.throw(); - }); - }); - - it('should throw an error if the object type could not be determined', function () { - expect(() => { - utils.determineObjType({dumbAttribute: 'bid'}) - }).to.throw(); - }); - - Object.values(SUB_PAYLOAD_TYPES).forEach(type => { - it(`should return the ${type} type`, function () { - const eventArgs = {} - const uniqueFields = SUB_PAYLOAD_UNIQUE_FIELDS_LOOKUP[type] - uniqueFields.forEach(field => { - eventArgs[field] = 'random-value' - }) - expect(utils.determineObjType(eventArgs)).to.equal(type); - }) - }) - }) - - describe('mergePayloadAndCustomFields', function () { - it('should throw an error when the target is not an object', function () { - expect(() => { - utils.mergePayloadAndCustomFields(123, {}) - }).to.throw(); - }) - - it('should throw an error when the new values are not an object', function () { - expect(() => { - utils.mergePayloadAndCustomFields({}, 123) - }).to.throw(); - }) - - it('should throw an error if custom fields are provided and one of them is not a string', () => { - const customFields = {impid: 'bid-123', bidId: 123} - expect(() => { - utils.mergePayloadAndCustomFields({}, customFields) - }).to.throw(); - }) - }) - - describe('validateSubPayloads', function () { - it('should throw an error if the sub payloads required fields are not the correct type', function () { - expect(() => { - utils.validateSubPayloads({ - [SUB_PAYLOAD_TYPES.ORTB_BID]: { - impid: 123, - publisherId: 456 - } - }) - }).to.throw(); - }); - - it('should not throw when sub payloads have valid required fields', function () { - expect(() => { - utils.validateSubPayloads({ - [SUB_PAYLOAD_TYPES.ORTB_BID]: { - impid: '123', - publisherId: 'publisher-123' - } - }) - }).to.not.throw(); - }); - }); - }) -}); diff --git a/test/spec/modules/mobkoiBidAdapter_spec.js b/test/spec/modules/mobkoiBidAdapter_spec.js deleted file mode 100644 index 887614eb5..000000000 --- a/test/spec/modules/mobkoiBidAdapter_spec.js +++ /dev/null @@ -1,348 +0,0 @@ -import sinon from 'sinon'; - -import { - spec, - utils, - DEFAULT_PREBID_JS_INTEGRATION_ENDPOINT -} from 'modules/mobkoiBidAdapter.js'; -import * as prebidUtils from 'src/utils'; - -describe('Mobkoi bidding Adapter', function () { - const testIntegrationEndpoint = 'http://test.integration.endpoint.com/bid'; - const testRequestId = 'test-request-id'; - const testPlacementId = 'mobkoiPlacementId'; - const testBidId = 'test-bid-id'; - const bidderCode = 'mobkoi'; - const testTransactionId = 'test-transaction-id'; - const testAdUnitId = 'test-ad-unit-id'; - const testAuctionId = 'test-auction-id'; - - let sandbox; - - const getOrtb2 = () => ({ - site: { - publisher: { - ext: { integrationEndpoint: testIntegrationEndpoint } - } - } - }) - - const getBidRequest = () => ({ - bidder: bidderCode, - adUnitCode: 'banner-ad', - transactionId: testTransactionId, - adUnitId: testAdUnitId, - bidId: testBidId, - bidderRequestId: testRequestId, - auctionId: testAuctionId, - ortb2: getOrtb2(), - params: { - integrationEndpoint: testIntegrationEndpoint, - placementId: testPlacementId - } - }) - - const getBidderRequest = () => ({ - bidderCode, - auctionId: testAuctionId, - bidderRequestId: testRequestId, - bids: [getBidRequest()], - ortb2: getOrtb2() - }) - - const getConvertedBidRequest = () => ({ - id: testRequestId, - imp: [{ - id: testBidId, - tagid: testPlacementId, - }], - ...getOrtb2(), - test: 0 - }) - - const adm = '
test ad
'; - const lurl = 'test.com/loss'; - const nurl = 'test.com/win'; - - const getBidderResponse = () => ({ - body: { - id: testBidId, - cur: 'USD', - seatbid: [ - { - seat: 'mobkoi_debug', - bid: [ - { - id: testBidId, - impid: testBidId, - cid: 'campaign_1', - crid: 'creative_1', - price: 1, - cur: [ - 'USD' - ], - adomain: [ - 'advertiser.com' - ], - adm, - w: 300, - h: 250, - mtype: 1, - lurl, - nurl - } - ] - } - ], - } - }) - - beforeEach(function () { - sandbox = sinon.createSandbox(); - sandbox.stub(prebidUtils, 'logInfo'); - sandbox.stub(prebidUtils, 'logWarn'); - sandbox.stub(prebidUtils, 'logError'); - }); - - afterEach(function () { - sandbox.restore(); - }); - - describe('isBidRequestValid', function () { - let bid; - - beforeEach(function () { - bid = getBidderRequest().bids[0]; - }); - - it('should return true when placement id exist in ad unit params', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when placement id is missing in ad unit params', function () { - delete bid.params.placementId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - let bidderRequest, convertedBidRequest; - - beforeEach(function () { - bidderRequest = getBidderRequest(); - convertedBidRequest = getConvertedBidRequest(); - }); - - it('should include converted ORTB data in request', function () { - const request = spec.buildRequests(bidderRequest.bids, bidderRequest); - const ortbData = request.data; - - expect(ortbData.id).to.equal(bidderRequest.bidderRequestId); - }); - - it('should obtain integrationEndpoint from ad unit params if the value does not exist in ortb2', function () { - delete bidderRequest.ortb2.site.publisher.ext.integrationEndpoint; - const request = spec.buildRequests(bidderRequest.bids, bidderRequest); - const ortbData = request.data; - - expect(ortbData.site.publisher.ext.integrationBaseUrl).to.equal(bidderRequest.bids[0].params.integrationEndpoint); - }); - - it('should use the pro server url when the integration endpoint is not set', function () { - delete bidderRequest.ortb2.site.publisher.ext.integrationEndpoint; - delete bidderRequest.bids[0].params.integrationEndpoint; - - const request = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.url).to.equal(DEFAULT_PREBID_JS_INTEGRATION_ENDPOINT); - expect(request.url).to.include('/bid'); - }); - - it('should set ext.mobkoi.integration_type to "pbjs" in the ORTB request', function () { - const request = spec.buildRequests(bidderRequest.bids, bidderRequest); - const ortbData = request.data; - expect(ortbData).to.have.nested.property('ext.mobkoi.integration_type', 'pbjs'); - }); - }); - - describe('interpretResponse', function () { - let bidderRequest, bidRequest, bidderResponse; - - beforeEach(function () { - bidderRequest = getBidderRequest(); - bidRequest = spec.buildRequests(bidderRequest.bids, bidderRequest); - bidderResponse = getBidderResponse(); - }); - - it('should return empty array when response is empty', function () { - expect(spec.interpretResponse({}, {})).to.deep.equal([]); - }); - - it('should interpret valid bid response', function () { - const bidsResponse = spec.interpretResponse(bidderResponse, bidRequest); - expect(bidsResponse).to.not.be.empty; - const bid = bidsResponse[0]; - - expect(bid.ad).to.include(adm); - expect(bid.requestId).to.equal(bidderResponse.body.seatbid[0].bid[0].impid); - expect(bid.cpm).to.equal(bidderResponse.body.seatbid[0].bid[0].price); - expect(bid.width).to.equal(bidderResponse.body.seatbid[0].bid[0].w); - expect(bid.height).to.equal(bidderResponse.body.seatbid[0].bid[0].h); - expect(bid.creativeId).to.equal(bidderResponse.body.seatbid[0].bid[0].crid); - expect(bid.currency).to.equal(bidderResponse.body.cur); - expect(bid.netRevenue).to.be.true; - expect(bid.ttl).to.equal(30); - }); - }) - - describe('utils', function () { - let bidderRequest; - - beforeEach(function () { - bidderRequest = getBidderRequest(); - }); - - describe('getIntegrationEndpoint', function () { - it('should return the integrationEndpoint from the given object', function () { - expect(utils.getIntegrationEndpoint(bidderRequest)) - .to.equal(testIntegrationEndpoint); - }); - - it('should return default prod integration endpoint when integrationEndpoint is missing in params and ortb2', function () { - delete bidderRequest.ortb2.site.publisher.ext.integrationEndpoint; - delete bidderRequest.bids[0].params.integrationEndpoint; - - expect(utils.getIntegrationEndpoint(bidderRequest)).to.equal(DEFAULT_PREBID_JS_INTEGRATION_ENDPOINT); - }); - }) - - describe('getOrtbId', function () { - it('should return the ortbId from the prebid request object (i.e bidderRequestId)', function () { - expect(utils.getOrtbId(bidderRequest)).to.equal(bidderRequest.bidderRequestId); - }); - - it('should return the ortbId from the prebid response object (i.e seatBidId)', function () { - const customBidRequest = { ...bidderRequest, seatBidId: bidderRequest.bidderRequestId }; - delete customBidRequest.bidderRequestId; - expect(utils.getOrtbId(customBidRequest)).to.equal(bidderRequest.bidderRequestId); - }); - - it('should return the ortbId from the interpreted prebid response object (i.e ortbId)', function () { - const customBidRequest = { ...bidderRequest, ortbId: bidderRequest.bidderRequestId }; - delete customBidRequest.bidderRequestId; - expect(utils.getOrtbId(customBidRequest)).to.equal(bidderRequest.bidderRequestId); - }); - - it('should return the ortbId from the ORTB request object (i.e has imp)', function () { - const customBidRequest = { ...bidderRequest, imp: {}, id: bidderRequest.bidderRequestId }; - delete customBidRequest.bidderRequestId; - expect(utils.getOrtbId(customBidRequest)).to.equal(bidderRequest.bidderRequestId); - }); - - it('should throw error when ortbId is missing', function () { - delete bidderRequest.bidderRequestId; - expect(() => { - utils.getOrtbId(bidderRequest); - }).to.throw(); - }); - }) - }) - - describe('getUserSyncs', function () { - let syncOptions; - - beforeEach(function () { - syncOptions = { - pixelEnabled: true, - iframeEnabled: false - }; - }); - - it('should return empty array when pixelEnabled is false', function () { - syncOptions.pixelEnabled = false; - const gdprConsent = { gdprApplies: true, consentString: 'test-consent' }; - const serverResponses = [{ body: { ext: { pixels: [['image', 'test-url']] } } }]; - - const result = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent); - expect(result).to.be.an('array').that.is.empty; - }); - - it('should return empty array when no pixels in response', function () { - const gdprConsent = { gdprApplies: true, consentString: 'test-consent' }; - const serverResponses = [{ body: { ext: {} } }]; - - const result = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent); - expect(result).to.be.an('array').that.is.empty; - }); - - it('should return empty array when pixels is not an array', function () { - const gdprConsent = { gdprApplies: true, consentString: 'test-consent' }; - const serverResponses = [{ body: { ext: { pixels: 'not-an-array' } } }]; - - const result = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent); - expect(result).to.be.an('array').that.is.empty; - }); - - it('should process image pixels correctly', function () { - const gdprConsent = { gdprApplies: true, consentString: 'test-consent-string' }; - const testUrl = 'https://example.com/sync?gdpr=test-consent-string¶m=value'; - const serverResponses = [{ - body: { - ext: { - pixels: [ - ['image', testUrl], - ['image', 'https://another.com/pixel'] - ] - } - } - }]; - - const result = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent); - - expect(result).to.have.length(2); - expect(result[0]).to.deep.equal({ - type: 'image', - url: 'https://example.com/sync?gdpr=test-consent-string¶m=value' - }); - expect(result[1]).to.deep.equal({ - type: 'image', - url: 'https://another.com/pixel' - }); - }); - - it('should ignore non-image pixel types', function () { - const gdprConsent = { gdprApplies: true, consentString: 'test-consent' }; - const serverResponses = [{ - body: { - ext: { - pixels: [ - ['iframe', 'https://iframe.com/sync'], - ['image', 'https://image.com/pixel'], - ['unknown', 'https://unknown.com/pixel'] - ] - } - } - }]; - - const result = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent); - - expect(result).to.have.length(1); - expect(result[0]).to.deep.equal({ - type: 'image', - url: 'https://image.com/pixel' - }); - }); - - it('should handle responses without ext field gracefully', function () { - const gdprConsent = { gdprApplies: true, consentString: 'test-consent' }; - const serverResponses = [ - { body: {} }, - { body: { ext: { pixels: [['image', 'https://valid.com/pixel']] } } } - ]; - - const result = spec.getUserSyncs(syncOptions, serverResponses, gdprConsent); - - expect(result).to.have.length(1); - expect(result[0].url).to.equal('https://valid.com/pixel'); - }); - }) -}) diff --git a/test/spec/modules/my6senseBidAdapter_spec.js b/test/spec/modules/my6senseBidAdapter_spec.js deleted file mode 100644 index 9493b1046..000000000 --- a/test/spec/modules/my6senseBidAdapter_spec.js +++ /dev/null @@ -1,134 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/my6senseBidAdapter.js'; - -describe('My6sense Bid adapter test', function () { - let bidRequests, serverResponses; - beforeEach(function () { - bidRequests = [ - { - // valid 1 - bidder: 'my6sense', - params: { - key: 'DTAeOJN67pCjY36dbhrM3G', - dataVersion: 3, - pageUrl: 'liran.com', - zone: '[ZONE]', - dataParams: '', - dataView: '', - organicClicks: '', - paidClicks: '' - } - }, - { - // invalid 2- no params - bidder: 'my6sense' - }, - { - // invalid 3 - no key in params - bidder: 'my6sense', - params: { - dataVersion: 3, - pageUrl: 'liran.com', - zone: '[ZONE]', - dataParams: '', - dataView: '', - organicClicks: '', - paidClicks: '' - } - }, - ]; - serverResponses = [ - { - headers: {}, - body: { - cpm: 1.5, - width: 300, - height: 250, - placement_id: 1, - adm: '' - } - }, - { - headers: {}, - body: { - cpm: 0, - width: 0, - height: 0, - placement_id: 1, - adm: '' - } - }, - { - headers: {}, - body: { - cpm: 0, - width: 0, - height: 0, - placement_id: 0, - adm: '' - } - }, - { - headers: {}, - body: { - cpm: 5, - creativeId: '5b29f5d1e4b086e3ee8de36b', - currency: 'USD', - height: 250, - netRevenue: false, - requestId: '2954a0957643bb', - ttl: 360, - width: 300, - adm: '' - } - } - ] - }); - - describe('test if requestIsValid function', function () { - it('with valid data 1', function () { - expect(spec.isBidRequestValid(bidRequests[0])).to.equal(true); - }); - it('with invalid data 2', function () { - expect(spec.isBidRequestValid(bidRequests[1])).to.equal(false); - }); - it('with invalid data 3', function () { - expect(spec.isBidRequestValid(bidRequests[2])).to.equal(false); - }); - }); - - describe('test if buildRequests function', function () { - it('normal', function () { - var requests = spec.buildRequests([bidRequests[0]]); - expect(requests).to.be.lengthOf(1); - }); - }); - describe('test bid responses', function () { - it('success 1', function () { - var bids = spec.interpretResponse(serverResponses[0], {'bidRequest': bidRequests[0]}); - expect(bids).to.be.lengthOf(1); - expect(bids[0].cpm).to.equal(1.5); - expect(bids[0].width).to.equal(300); - expect(bids[0].height).to.equal(250); - expect(bids[0].adm).to.have.length.above(1); - }); - it('success 2', function () { - var bids = spec.interpretResponse(serverResponses[3]); - expect(bids).to.be.lengthOf(1); - expect(bids[0].cpm).to.equal(5); - expect(bids[0].width).to.equal(300); - expect(bids[0].height).to.equal(250); - expect(bids[0].netRevenue).to.equal(false); - expect(bids[0].ttl).to.equal(360); - expect(bids[0].currency).to.equal('USD'); - }); - it('fail 1 (cpm=0)', function () { - var bids = spec.interpretResponse(serverResponses[1]); - expect(bids).to.be.lengthOf(1); - }); - it('fail 2 (no response)', function () { - var bids = spec.interpretResponse([]); - expect(bids).to.be.lengthOf(0); - }); - }); -}); diff --git a/test/spec/modules/nativeryBidAdapter_spec.js b/test/spec/modules/nativeryBidAdapter_spec.js deleted file mode 100644 index e8706711b..000000000 --- a/test/spec/modules/nativeryBidAdapter_spec.js +++ /dev/null @@ -1,195 +0,0 @@ -import { expect } from 'chai'; -import { spec, converter } from 'modules/nativeryBidAdapter'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import * as utils from 'src/utils.js'; - -const ENDPOINT = 'https://hb.nativery.com/openrtb2/auction'; -const MAX_IMPS_PER_REQUEST = 10; - -const bid = { - bidder: 'nativery', - params: { - widgetId: 'abc123', - }, - adUnitCode: '/adunit-code/test-path', - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - transactionId: 'test-transactionId-1', -}; - -const bidRequests = [ - { - ...bid, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - }, - }, - ortb2: {}, - }, -]; - -describe('NativeryAdapter', function () { - const adapter = newBidder(spec); - let sandBox; - - beforeEach(() => { - sandBox = sinon.createSandbox(); - }); - - afterEach(() => sandBox.restore()); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params.widgetId; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('should build the request', function () { - const request = spec.buildRequests(bidRequests, {}); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal(ENDPOINT); - expect(request.options.withCredentials).to.equal(true); - expect(typeof request.data.id).to.equal('string'); - expect(request.data.imp).to.be.an('array'); - expect(request.data.imp.length).to.equal(1); - request.data.imp.forEach((data) => { - expect(data.id).to.exist.and.to.be.a('string'); - expect(data).to.have.nested.property('banner.format'); - expect(data.ext.nativery.widgetId).to.equal(bid.params.widgetId); - }); - }); - // build multi bid request - const multiBidRequest = Array(12).fill(bidRequests[0]); - - it('should build the request splitting in chuncks', function () { - const request = spec.buildRequests(multiBidRequest, {}); - - const expectedNumRequests = Math.ceil( - multiBidRequest.length / MAX_IMPS_PER_REQUEST - ); - expect(request).to.be.an('array').that.has.lengthOf(expectedNumRequests); - - // Check each object of the request - request.forEach((req) => { - expect(req).to.have.property('method', 'POST'); - expect(req).to.have.property('url', ENDPOINT); - expect(req).to.have.property('data').that.is.an('object'); - expect(req.data).to.have.property('imp').that.is.an('array'); - // Each chunk must contain at most MAX_IMPS_PER_REQUEST elements. - expect(req.data.imp.length).to.be.at.most(MAX_IMPS_PER_REQUEST); - }); - }); - }); - - describe('interpretResponse', function () { - const bidderRequest = spec.buildRequests(bidRequests, {}); - it('should return [] if serverResponse.body is falsy', function () { - // Case: serverResponse.body does not exist - let serverResponse = {}; - let result = spec.interpretResponse(serverResponse, bidderRequest); - expect(result).to.be.an('array').that.is.empty; - - // Case: serverResponse.body is null - serverResponse = { body: null }; - result = spec.interpretResponse(serverResponse, bidderRequest); - expect(result).to.be.an('array').that.is.empty; - }); - - it('should return [] if serverResponse.body is not an object', function () { - const serverResponse = { body: 'not an object' }; - const result = spec.interpretResponse(serverResponse, bidderRequest); - expect(result).to.be.an('array').that.is.empty; - }); - - it('should return [] if serverResponse.body.seatbid is not an array', function () { - const serverResponse = { - body: { - seatbid: {}, // Not an array - }, - }; - - const result = spec.interpretResponse(serverResponse, bidderRequest); - expect(result).to.be.an('array').that.is.empty; - }); - - it('should correctly process a response with a seatbid array and return bids', function () { - const bidsMock = [{ bid: 1 }, { bid: 2 }]; - const serverResponse = { - body: { - seatbid: [{}], - }, - }; - - sandBox.stub(converter, 'fromORTB').returns({ bids: bidsMock }); - - const result = spec.interpretResponse(serverResponse, bidderRequest); - expect(result).to.deep.equal(bidsMock); - sinon.assert.calledWith(converter.fromORTB, { - request: bidderRequest.data, - response: serverResponse.body, - }); - }); - - it('should log a warning if deepAccess returns errors, but still return bids', function () { - const logWarnSpy = sinon.spy(utils, 'logWarn'); - const bidsMock = [{ bid: 1 }]; - const bidderRequest = spec.buildRequests(bidRequests, {}); - - const errors = ['error1', 'error2']; - const serverResponse = { - body: { - seatbid: [{}], - ext: { - errors: { - nativery: errors, - }, - }, - }, - }; - - sandBox.stub(converter, 'fromORTB').returns({ bids: bidsMock }); - - const result = spec.interpretResponse(serverResponse, bidderRequest); - expect(result).to.deep.equal(bidsMock); - expect(logWarnSpy.calledOnceWithExactly(`Nativery: Error in bid response ${JSON.stringify(errors)}`)).to.be.true; - logWarnSpy.restore(); - }); - - it('should return [] and log an error if converter.fromORTB throws an error', function () { - const logErrorSpy = sinon.spy(utils, 'logError'); - const bidderRequest = spec.buildRequests(bidRequests, {}); - - const serverResponse = { - body: { - seatbid: [{}], - }, - }; - - const error = new Error('Test error'); - sandBox.stub(converter, 'fromORTB').throws(error); - - const result = spec.interpretResponse(serverResponse, bidderRequest); - expect(result).to.be.an('array').that.is.empty; - expect(logErrorSpy.calledOnceWithExactly(`Nativery: unhandled error in bid response ${error.message}`)).to.be.true; - logErrorSpy.restore(); - }); - }); -}); diff --git a/test/spec/modules/nativoBidAdapter_spec.js b/test/spec/modules/nativoBidAdapter_spec.js deleted file mode 100644 index c1e6642e7..000000000 --- a/test/spec/modules/nativoBidAdapter_spec.js +++ /dev/null @@ -1,919 +0,0 @@ -import { expect } from 'chai' -import { spec, BidDataMap } from 'modules/nativoBidAdapter.js' -import { - getSizeWildcardPrice, - getMediaWildcardPrices, - sizeToString, - parseFloorPriceData, - getPageUrlFromBidRequest, - hasProtocol, - addProtocol, - BidRequestDataSource, - RequestData, - UserEIDs, - buildRequestUrl, -} from '../../../modules/nativoBidAdapter.js' - -describe('bidDataMap', function () { - it('Should fail gracefully if no key value pairs have been added and no key is sent', function () { - const bdm = new BidDataMap() - const bidData = bdm.getBidData() - expect(bidData).to.be.undefined - }) - - it('Should fail gracefully if no key value pairs have been added', function () { - const bdm = new BidDataMap() - const bidData = bdm.getBidData('testKey') - expect(bidData).to.be.undefined - }) - - it('Should add bid data to corresponding keys', function () { - const keys = ['key1', 'anotherKey', 6] - const bidData = { prop: 'value' } - - const bdm = new BidDataMap() - bdm.addBidData(bidData, keys) - const bidDataKey0 = bdm.getBidData(keys[0]) - const bidDataKey1 = bdm.getBidData(keys[1]) - const bidDataKey2 = bdm.getBidData(keys[2]) - expect(bidDataKey0).to.be.equal(bidData) - expect(bidDataKey1).to.be.equal(bidData) - expect(bidDataKey2).to.be.equal(bidData) - }) -}) - -describe('nativoBidAdapterTests', function () { - describe('isBidRequestValid', function () { - const bid = { - bidder: 'nativo', - } - - it('should return true if no params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true) - }) - - it('should return true for valid placementId value', function () { - bid.params = { - placementId: '10433394', - } - expect(spec.isBidRequestValid(bid)).to.equal(true) - }) - - it('should return true for valid placementId value', function () { - bid.params = { - placementId: 10433394, - } - expect(spec.isBidRequestValid(bid)).to.equal(true) - }) - - it('should return false for invalid placementId value', function () { - bid.params = { - placementId: true, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - - it('should return true for valid placementId value', function () { - bid.params = { - url: 'www.test.com', - } - expect(spec.isBidRequestValid(bid)).to.equal(true) - }) - - it('should return false for invalid placementId value', function () { - bid.params = { - url: 4567890, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - }) - - describe('buildRequests', function () { - const bidRequest = { - bidder: 'nativo', - params: { - placementId: '10433394', - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250], - [300, 600], - ], - bidId: '27b02036ccfa6e', - bidderRequestId: '1372cd8bd8d6a8', - auctionId: 'cfc467e4-2707-48da-becb-bcaab0b2c114', - transactionId: '3b36e7e0-0c3e-4006-a279-a741239154ff', - } - const bidRequestString = JSON.stringify(bidRequest) - let bidRequests - - beforeEach(function () { - // Clone bidRequest each time - bidRequests = [JSON.parse(bidRequestString)] - }) - - it('Request should be POST, with JSON string payload and QS params should be added to the url', function () { - const request = spec.buildRequests(bidRequests, { - bidderRequestId: 123456, - refererInfo: { - referer: 'https://www.test.com', - }, - }) - - expect(request.method).to.equal('POST') - - expect(request.data).to.exist - expect(request.data).to.be.a('string') - - expect(request.url).to.exist - expect(request.url).to.be.a('string') - - expect(request.url).to.include('?') - expect(request.url).to.include('ntv_pbv') - expect(request.url).to.include('ntv_ptd') - expect(request.url).to.include('ntv_pb_rid') - expect(request.url).to.include('ntv_ppc') - expect(request.url).to.include('ntv_url') - expect(request.url).to.include('ntv_dbr') - expect(request.url).to.include('ntv_pas') - }) - - it('ntv_url should contain query params', function () { - const request = spec.buildRequests(bidRequests, { - bidderRequestId: 123456, - refererInfo: { - location: 'https://www.test.com?queryTest=true', - }, - }) - console.log(request.url) // eslint-disable-line no-console - expect(request.url).to.include(encodeURIComponent('?queryTest=true')) - }) - - it('ntv_url parameter should NOT be empty even if the utl parameter was set as an empty value', function () { - bidRequests[0].params.url = '' - const request = spec.buildRequests(bidRequests, { - bidderRequestId: 123456, - refererInfo: { - location: 'https://www.test.com', - }, - }) - - expect(request.url).to.exist - expect(request.url).to.be.a('string') - expect(request.url).to.not.be.empty - }) - - it('url should NOT contain placement specific query string parameters if placementId option is not provided', function () { - bidRequests[0].params = {} - const request = spec.buildRequests(bidRequests, { - bidderRequestId: 123456, - refererInfo: { - location: 'https://www.test.com', - }, - }) - - expect(request.url).to.exist - expect(request.url).to.be.a('string') - - expect(request.url).to.not.include('ntv_pas') - expect(request.url).to.not.include('ntv_ptd') - }) - }) -}) - -describe('interpretResponse', function () { - const response = { - id: '126456', - seatbid: [ - { - seat: 'seat_0', - bid: [ - { - id: 'f70362ac-f3cf-4225-82a5-948b690927a6', - impid: '1', - price: 3.569, - adm: '', - h: 300, - w: 250, - cat: [], - adomain: ['test.com'], - crid: '1060_72_6760217', - }, - ], - }, - ], - cur: 'USD', - } - - it('should get correct bid response', function () { - const expectedResponse = [ - { - requestId: '1F254428-AB11-4D5E-9887-567B3F952CA5', - cpm: 3.569, - currency: 'USD', - width: 300, - height: 250, - creativeId: '1060_72_6760217', - dealId: 'f70362ac-f3cf-4225-82a5-948b690927a6', - netRevenue: true, - ttl: 360, - ad: '', - meta: { - advertiserDomains: ['test.com'], - }, - mediaType: 'banner', - }, - ] - - const bidderRequest = { - id: 123456, - bids: [ - { - params: { - placementId: 1, - }, - }, - ], - } - - // mock - spec.getAdUnitData = () => { - return { - bidId: 123456, - sizes: [300, 250], - } - } - - const result = spec.interpretResponse({ body: response }, { bidderRequest }) - expect(Object.keys(result[0])).to.have.deep.members( - Object.keys(expectedResponse[0]) - ) - }) - - it('handles nobid responses', function () { - const response = {} - let bidderRequest - - const result = spec.interpretResponse({ body: response }, { bidderRequest }) - expect(result.length).to.equal(0) - }) -}) - -describe('getUserSyncs', function () { - const response = [ - { - body: { - cur: 'USD', - id: 'a136dbd8-4387-48bf-b8e4-ff9c1d6056ee', - seatbid: [ - { - bid: [{}], - seat: 'seat_0', - syncUrls: [ - { - type: 'image', - url: 'pixel-tracker-test-url/?{GDPR_params}', - }, - { - type: 'iframe', - url: 'iframe-tracker-test-url/?{GDPR_params}', - }, - ], - }, - ], - }, - }, - ] - - const gdprConsent = { - gdprApplies: true, - consentString: '111111', - } - - const uspConsent = { - uspConsent: '1YYY', - } - - it('Returns empty array if no supported user syncs', function () { - const userSync = spec.getUserSyncs( - { - iframeEnabled: false, - pixelEnabled: false, - }, - response, - gdprConsent, - uspConsent - ) - expect(userSync).to.be.an('array').with.lengthOf(0) - }) - - it('Returns valid iframe user sync', function () { - const userSync = spec.getUserSyncs( - { - iframeEnabled: true, - pixelEnabled: false, - }, - response, - gdprConsent, - uspConsent - ) - expect(userSync).to.be.an('array').with.lengthOf(1) - expect(userSync[0].type).to.exist - expect(userSync[0].url).to.exist - expect(userSync[0].type).to.be.equal('iframe') - expect(userSync[0].url).to.contain( - 'gdpr=1&gdpr_consent=111111&us_privacy=1YYY' - ) - }) - - it('Returns valid URL and type', function () { - const userSync = spec.getUserSyncs( - { - iframeEnabled: false, - pixelEnabled: true, - }, - response, - gdprConsent, - uspConsent - ) - expect(userSync).to.be.an('array').with.lengthOf(1) - expect(userSync[0].type).to.exist - expect(userSync[0].url).to.exist - expect(userSync[0].type).to.be.equal('image') - expect(userSync[0].url).to.contain( - 'gdpr=1&gdpr_consent=111111&us_privacy=1YYY' - ) - }) -}) - -describe('getAdUnitData', () => { - afterEach(() => { - if (window.bidRequestMap) delete window.bidRequestMap - }) - - it('Matches placementId value', () => { - const adUnitData = { - bidId: 123456, - sizes: [300, 250], - } - - window.bidRequestMap = { - 9876543: { - 12345: adUnitData, - }, - } - - const data = spec.getAdUnitData(9876543, { impid: 12345 }) - expect(Object.keys(data)).to.have.deep.members(Object.keys(adUnitData)) - }) - - it('Falls back to ad unit code value', () => { - const adUnitData = { - bidId: 123456, - sizes: [300, 250], - } - - window.bidRequestMap = { - 9876543: { - '#test-code': adUnitData, - }, - } - - const data = spec.getAdUnitData(9876543, { - impid: 12345, - ext: { ad_unit_code: '#test-code' }, - }) - expect(Object.keys(data)).to.have.deep.members(Object.keys(adUnitData)) - }) -}) - -describe('Response to Request Filter Flow', () => { - const bidRequests = [ - { - bidder: 'nativo', - params: { - placementId: '10433394', - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250], - [300, 600], - ], - bidId: '27b02036ccfa6e', - bidderRequestId: '1372cd8bd8d6a8', - auctionId: 'cfc467e4-2707-48da-becb-bcaab0b2c114', - transactionId: '3b36e7e0-0c3e-4006-a279-a741239154ff', - }, - ] - - let response - - beforeEach(() => { - response = { - id: '126456', - seatbid: [ - { - seat: 'seat_0', - bid: [ - { - id: 'f70362ac-f3cf-4225-82a5-948b690927a6', - impid: '1', - price: 3.569, - adm: '', - h: 300, - w: 250, - cat: [], - adomain: ['test.com'], - crid: '1060_72_6760217', - }, - ], - }, - ], - cur: 'USD', - } - }) - - const bidderRequest = { - id: 123456, - bids: [ - { - params: { - placementId: 1, - }, - }, - ], - } - - // mock - spec.getAdUnitData = () => { - return { - bidId: 123456, - size: [300, 250], - } - } - - it('Appends NO filter based on previous response', () => { - // Getting the mock response - const result = spec.interpretResponse({ body: response }, { bidderRequest }) - - // Winning the bid - spec.onBidWon(result[0]) - - // Making another request - const request = spec.buildRequests(bidRequests, { - bidderRequestId: 123456, - refererInfo: { - referer: 'https://www.test.com', - }, - }) - expect(request.url).to.not.include('ntv_aft') - expect(request.url).to.not.include('ntv_avtf') - expect(request.url).to.not.include('ntv_ctf') - }) - - it('Appends Ads filter based on previous response', () => { - response.seatbid[0].bid[0].ext = { adsToFilter: ['12345'] } - - // Getting the mock response - const result = spec.interpretResponse({ body: response }, { bidderRequest }) - - // Winning the bid - spec.onBidWon(result[0]) - - // Making another request - const request = spec.buildRequests(bidRequests, { - bidderRequestId: 123456, - refererInfo: { - referer: 'https://www.test.com', - }, - }) - expect(request.url).to.include(`ntv_atf=12345`) - expect(request.url).to.not.include('ntv_avtf') - expect(request.url).to.not.include('ntv_ctf') - }) - - it('Appends Advertiser filter based on previous response', () => { - response.seatbid[0].bid[0].ext = { advertisersToFilter: ['1'] } - - // Getting the mock response - const result = spec.interpretResponse({ body: response }, { bidderRequest }) - - // Winning the bid - spec.onBidWon(result[0]) - - // Making another request - const request = spec.buildRequests(bidRequests, { - bidderRequestId: 123456, - refererInfo: { - referer: 'https://www.test.com', - }, - }) - expect(request.url).to.include(`ntv_atf=12345`) - expect(request.url).to.include('ntv_avtf=1') - expect(request.url).to.not.include('ntv_ctf') - }) - - it('Appends Campaign filter based on previous response', () => { - response.seatbid[0].bid[0].ext = { campaignsToFilter: ['234'] } - - // Getting the mock response - const result = spec.interpretResponse({ body: response }, { bidderRequest }) - - // Winning the bid - spec.onBidWon(result[0]) - - // Making another request - const request = spec.buildRequests(bidRequests, { - bidderRequestId: 123456, - refererInfo: { - referer: 'https://www.test.com', - }, - }) - expect(request.url).to.include(`ntv_atf=12345`) - expect(request.url).to.include('ntv_avtf=1') - expect(request.url).to.include('ntv_ctf=234') - }) -}) - -describe('sizeToString', () => { - it('Formats size array correctly', () => { - const sizeString = sizeToString([300, 250]) - expect(sizeString).to.be.equal('300x250') - }) - - it('Returns an empty array for invalid data', () => { - // Not an array - let sizeString = sizeToString(300, 350) - expect(sizeString).to.be.equal('') - // Single entry - sizeString = sizeToString([300]) - expect(sizeString).to.be.equal('') - // Undefined - sizeString = sizeToString(undefined) - expect(sizeString).to.be.equal('') - }) -}) - -describe('getSizeWildcardPrice', () => { - it('Generates the correct floor price data', () => { - const floorPrice = { - currency: 'USD', - floor: 1.0, - } - const getFloorMock = () => { - return floorPrice - } - const floorMockSpy = sinon.spy(getFloorMock) - const bidRequest = { - getFloor: floorMockSpy, - mediaTypes: { - banner: { - sizes: [300, 250], - }, - }, - } - - const result = getSizeWildcardPrice(bidRequest, 'banner') - expect( - floorMockSpy.calledWith({ - currency: 'USD', - mediaType: 'banner', - size: '*', - }) - ).to.be.true - expect(result).to.equal(floorPrice) - }) -}) - -describe('getMediaWildcardPrices', () => { - it('Generates the correct floor price data', () => { - const defaultFloorPrice = { - currency: 'USD', - floor: 1.1, - } - const sizefloorPrice = { - currency: 'USD', - floor: 2.2, - } - const getFloorMock = ({ currency, mediaType, size }) => { - if (Array.isArray(size)) return sizefloorPrice - - return defaultFloorPrice - } - const floorMockSpy = sinon.spy(getFloorMock) - const bidRequest = { - getFloor: floorMockSpy, - mediaTypes: { - banner: { - sizes: [300, 250], - }, - }, - } - - const result = getMediaWildcardPrices(bidRequest, ['*', [300, 250]]) - expect( - floorMockSpy.calledWith({ - currency: 'USD', - mediaType: '*', - size: '*', - }) - ).to.be.true - expect( - floorMockSpy.calledWith({ - currency: 'USD', - mediaType: '*', - size: [300, 250], - }) - ).to.be.true - expect(result).to.deep.equal({ '*': 1.1, '300x250': 2.2 }) - }) -}) - -describe('parseFloorPriceData', () => { - it('Generates the correct floor price data', () => { - const defaultFloorPrice = { - currency: 'USD', - floor: 1.1, - } - const sizefloorPrice = { - currency: 'USD', - floor: 2.2, - } - const getFloorMock = ({ currency, mediaType, size }) => { - if (Array.isArray(size)) return sizefloorPrice - - return defaultFloorPrice - } - const floorMockSpy = sinon.spy(getFloorMock) - const bidRequest = { - getFloor: floorMockSpy, - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - } - - const result = parseFloorPriceData(bidRequest) - expect(result).to.deep.equal({ - '*': { '*': 1.1, '300x250': 2.2 }, - banner: { '*': 1.1, '300x250': 2.2 }, - }) - }) -}) - -describe('hasProtocol', () => { - it('https://www.testpage.com', () => { - expect(hasProtocol('https://www.testpage.com')).to.be.true - }) - it('http://www.testpage.com', () => { - expect(hasProtocol('http://www.testpage.com')).to.be.true - }) - it('//www.testpage.com', () => { - expect(hasProtocol('//www.testpage.com')).to.be.false - }) - it('www.testpage.com', () => { - expect(hasProtocol('www.testpage.com')).to.be.false - }) - it('httpsgsjhgflih', () => { - expect(hasProtocol('httpsgsjhgflih')).to.be.false - }) -}) - -describe('addProtocol', () => { - it('www.testpage.com', () => { - expect(addProtocol('www.testpage.com')).to.be.equal( - 'https://www.testpage.com' - ) - }) - it('//www.testpage.com', () => { - expect(addProtocol('//www.testpage.com')).to.be.equal( - 'https://www.testpage.com' - ) - }) - it('http://www.testpage.com', () => { - expect(addProtocol('http://www.testpage.com')).to.be.equal( - 'http://www.testpage.com' - ) - }) - it('https://www.testpage.com', () => { - expect(addProtocol('https://www.testpage.com')).to.be.equal( - 'https://www.testpage.com' - ) - }) -}) - -describe('getPageUrlFromBidRequest', () => { - const bidRequest = {} - - beforeEach(() => { - bidRequest.params = {} - }) - - it('Returns undefined for no url param', () => { - const url = getPageUrlFromBidRequest(bidRequest) - expect(url).to.be.undefined - }) - - it('@testUrl', () => { - const url = getPageUrlFromBidRequest(bidRequest) - expect(url).to.be.undefined - }) - - it('https://www.testpage.com', () => { - bidRequest.params.url = 'https://www.testpage.com' - const url = getPageUrlFromBidRequest(bidRequest) - expect(url).not.to.be.undefined - }) - - it('https://www.testpage.com/test/path', () => { - bidRequest.params.url = 'https://www.testpage.com/test/path' - const url = getPageUrlFromBidRequest(bidRequest) - expect(url).not.to.be.undefined - }) - - it('www.testpage.com', () => { - bidRequest.params.url = 'www.testpage.com' - const url = getPageUrlFromBidRequest(bidRequest) - expect(url).not.to.be.undefined - }) - - it('http://www.testpage.com', () => { - bidRequest.params.url = 'http://www.testpage.com' - const url = getPageUrlFromBidRequest(bidRequest) - expect(url).not.to.be.undefined - }) - - it('//www.testpage.com', () => { - bidRequest.params.url = '//www.testpage.com' - const url = getPageUrlFromBidRequest(bidRequest) - expect(url).not.to.be.undefined - }) -}) - -describe('RequestData', () => { - describe('addBidRequestDataSource', () => { - it('Adds a BidRequestDataSource', () => { - const requestData = new RequestData() - const testBidRequestDataSource = new BidRequestDataSource() - - requestData.addBidRequestDataSource(testBidRequestDataSource) - - expect(requestData.bidRequestDataSources.length === 1) - }) - - it("Doeasn't add a non BidRequestDataSource", () => { - const requestData = new RequestData() - - requestData.addBidRequestDataSource({}) - requestData.addBidRequestDataSource('test') - requestData.addBidRequestDataSource(1) - requestData.addBidRequestDataSource(true) - - expect(requestData.bidRequestDataSources.length === 0) - }) - }) - - describe('getRequestDataString', () => { - it("Doesn't append empty query strings", () => { - const requestData = new RequestData() - const testBidRequestDataSource = new BidRequestDataSource() - - requestData.addBidRequestDataSource(testBidRequestDataSource) - - let qs = requestData.getRequestDataQueryString() - expect(qs).to.be.empty - - testBidRequestDataSource.getRequestQueryString = () => { - return 'ntv_test=true' - } - qs = requestData.getRequestDataQueryString() - expect(qs).to.be.equal('ntv_test=true') - }) - }) -}) - -describe('UserEIDs', () => { - const userEids = new UserEIDs() - const eids = [{ testId: 1111 }] - - describe('processBidRequestData', () => { - it('Processes bid request without eids', () => { - userEids.processBidRequestData({}) - - expect(userEids.eids).to.be.empty - }) - - it('Processed bid request with eids', () => { - userEids.processBidRequestData({ userIdAsEids: eids }) - - expect(userEids.eids).to.not.be.empty - }) - }) - - describe('getRequestQueryString', () => { - it('Correctly prints out QS param string', () => { - const qs = userEids.getRequestQueryString() - const value = qs.slice(11) - - expect(qs).to.include('ntv_pb_eid=') - try { - expect(JSON.parse(value)).to.be.equal(eids) - } catch (err) {} - }) - }) -}) - -describe('buildRequestUrl', () => { - const baseUrl = 'https://www.testExchange.com' - it('Returns baseUrl if no QS strings passed', () => { - const url = buildRequestUrl(baseUrl) - expect(url).to.be.equal(baseUrl) - }) - - it('Returns baseUrl if empty QS strings passed', () => { - const url = buildRequestUrl(baseUrl, ['', '', '']) - expect(url).to.be.equal(baseUrl) - }) - - it('Returns baseUrl + QS params if QS strings passed', () => { - const url = buildRequestUrl(baseUrl, [ - 'ntv_ptd=123456&ntv_test=true', - 'ntv_foo=bar', - ]) - expect(url).to.be.equal( - `${baseUrl}?ntv_ptd=123456&ntv_test=true&ntv_foo=bar` - ) - }) - - it('Returns baseUrl + QS params if mixed QS strings passed', () => { - const url = buildRequestUrl(baseUrl, [ - 'ntv_ptd=123456&ntv_test=true', - '', - '', - 'ntv_foo=bar', - ]) - expect(url).to.be.equal( - `${baseUrl}?ntv_ptd=123456&ntv_test=true&ntv_foo=bar` - ) - }) -}) - -describe('Prebid Video', function () { - it('should handle video bid requests', function () { - const videoBidRequest = { - bidder: 'nativo', - params: { - video: { - mimes: ['video/mp4'], - protocols: [2, 3, 5, 6], - playbackmethod: [1, 2], - skip: 1, - skipafter: 5, - }, - }, - } - - const isValid = spec.isBidRequestValid(videoBidRequest) - expect(isValid).to.be.true - }) -}) - -describe('Prebid Native', function () { - it('should handle native bid requests', function () { - const nativeBidRequest = { - bidder: 'nativo', - params: { - native: { - title: { - required: true, - len: 80, - }, - image: { - required: true, - sizes: [150, 50], - }, - sponsoredBy: { - required: true, - }, - clickUrl: { - required: true, - }, - privacyLink: { - required: false, - }, - body: { - required: true, - }, - icon: { - required: true, - sizes: [50, 50], - }, - }, - }, - } - - const isValid = spec.isBidRequestValid(nativeBidRequest) - expect(isValid).to.be.true - }) -}) diff --git a/test/spec/modules/neuwoRtdProvider_spec.js b/test/spec/modules/neuwoRtdProvider_spec.js deleted file mode 100644 index c400eea04..000000000 --- a/test/spec/modules/neuwoRtdProvider_spec.js +++ /dev/null @@ -1,123 +0,0 @@ -import { server } from 'test/mocks/xhr.js'; -import * as neuwo from 'modules/neuwoRtdProvider'; - -const PUBLIC_TOKEN = 'public_key_0000'; -const config = () => ({ - params: { - publicToken: PUBLIC_TOKEN, - apiUrl: 'https://testing-requirement.neuwo.api' - } -}) - -const apiReturns = () => ({ - somethingExtra: { object: true }, - marketing_categories: { - iab_tier_1: [ - { ID: 'IAB21', label: 'Real Estate', relevance: '0.45699' } - ] - } -}) - -const TAX_ID = '441' - -/** - * Object generator, like above, written using alternative techniques - * @returns object with predefined (expected) bidsConfig fields - */ -function bidsConfiglike() { - return Object.assign({}, { - ortb2Fragments: { global: {} } - }) -} - -describe('neuwoRtdProvider', function () { - describe('neuwoRtdModule', function () { - it('initializes', function () { - expect(neuwo.neuwoRtdModule.init(config())).to.be.true; - }) - it('init needs that public token', function () { - expect(neuwo.neuwoRtdModule.init()).to.be.false; - }) - - describe('segment picking', function () { - it('handles bad inputs', function () { - expect(neuwo.pickSegments()).to.be.an('array').that.is.empty; - expect(neuwo.pickSegments('technically also an array')).to.be.an('array').that.is.empty; - expect(neuwo.pickSegments({ bad_object: 'bad' })).to.be.an('array').that.is.empty; - }) - it('handles malformations', function () { - const result = neuwo.pickSegments([{something_wrong: true}, null, { ID: 'IAB19-20' }, { id: 'IAB3-1', ID: 'IAB9-20' }]) - expect(result[0].id).to.equal('631') - expect(result[1].id).to.equal('58') - expect(result.length).to.equal(2) - }) - }) - - describe('topic injection', function () { - it('mutates bidsConfig', function () { - const topics = apiReturns() - const bidsConfig = bidsConfiglike() - neuwo.injectTopics(topics, bidsConfig, () => { }) - expect(bidsConfig.ortb2Fragments.global.site.content.data[0].name, 'name of first content data object').to.equal(neuwo.DATA_PROVIDER) - expect(bidsConfig.ortb2Fragments.global.site.content.data[0].segment[0].id, 'id of first segment in content.data').to.equal(TAX_ID) - expect(bidsConfig.ortb2Fragments.global.site.pagecat[0], 'category taxonomy code for pagecat').to.equal(TAX_ID) - }) - - it('handles malformed responses', function () { - let topics = { message: 'Forbidden' } - const bidsConfig = bidsConfiglike() - neuwo.injectTopics(topics, bidsConfig, () => { }) - expect(bidsConfig.ortb2Fragments.global.site.content.data[0].name, 'name of first content data object').to.equal(neuwo.DATA_PROVIDER) - expect(bidsConfig.ortb2Fragments.global.site.content.data[0].segment, 'length of segment(s) in content.data').to.be.an('array').that.is.empty; - - topics = '404 wouldn\'t really even show up for injection' - const bdsConfig = bidsConfiglike() - neuwo.injectTopics(topics, bdsConfig, () => { }) - expect(bdsConfig.ortb2Fragments.global.site.content.data[0].name, 'name of first content data object').to.equal(neuwo.DATA_PROVIDER) - expect(bdsConfig.ortb2Fragments.global.site.content.data[0].segment, 'length of segment(s) in content.data').to.be.an('array').that.is.empty; - - topics = undefined - const bdsConfigE = bidsConfiglike() - neuwo.injectTopics(topics, bdsConfigE, () => { }) - expect(bdsConfigE.ortb2Fragments.global.site.content.data[0].name, 'name of first content data object').to.equal(neuwo.DATA_PROVIDER) - expect(bdsConfigE.ortb2Fragments.global.site.content.data[0].segment, 'length of segment(s) in content.data').to.be.an('array').that.is.empty; - }) - }) - - describe('fragment addition', function () { - it('mutates input objects', function () { - const alphabet = { a: { b: { c: {} } } } - neuwo.addFragment(alphabet.a.b.c, 'd.e.f', { g: 'h' }) - expect(alphabet.a.b.c.d.e.f.g).to.equal('h') - }) - }) - - describe('getBidRequestData', function () { - it('forms requests properly and mutates input bidsConfig', function () { - const bids = bidsConfiglike() - const conf = config() - // control xhr api request target for testing - conf.params.argUrl = 'https://publisher.works/article.php?get=horrible_url_for_testing&id=5' - - neuwo.getBidRequestData(bids, () => { }, conf, 'any consent data works, clearly') - - const request = server.requests[0]; - expect(request.url).to.be.a('string').that.includes(conf.params.publicToken) - expect(request.url).to.include(encodeURIComponent(conf.params.argUrl)) - request.respond(200, { 'Content-Type': 'application/json; encoding=UTF-8' }, JSON.stringify(apiReturns())); - - expect(bids.ortb2Fragments.global.site.content.data[0].name, 'name of first content data object').to.equal(neuwo.DATA_PROVIDER) - expect(bids.ortb2Fragments.global.site.content.data[0].segment[0].id, 'id of first segment in content.data').to.equal(TAX_ID) - }) - - it('accepts detail not available result', function () { - const bidsConfig = bidsConfiglike() - const comparison = bidsConfiglike() - neuwo.getBidRequestData(bidsConfig, () => { }, config(), 'consensually') - const request = server.requests[0]; - request.respond(404, { 'Content-Type': 'application/json; encoding=UTF-8' }, JSON.stringify({ detail: 'Basically first time seeing this' })); - expect(bidsConfig).to.deep.equal(comparison) - }) - }) - }) -}) diff --git a/test/spec/modules/newspassidBidAdapter_spec.js b/test/spec/modules/newspassidBidAdapter_spec.js deleted file mode 100644 index b1668aafe..000000000 --- a/test/spec/modules/newspassidBidAdapter_spec.js +++ /dev/null @@ -1,346 +0,0 @@ -import { spec } from 'modules/newspassidBidAdapter.js'; -import { config } from 'src/config.js'; -import { deepClone } from 'src/utils.js'; -import { resolveNewpassidPublisherId } from '../../../modules/newspassidBidAdapter.js'; - -describe('newspassidBidAdapter', function () { - const TEST_PUBLISHER_ID = '123456'; - const TEST_PLACEMENT_ID = 'test-group1'; - - const validBidRequest = { - bidder: 'newspassid', - params: { - publisherId: TEST_PUBLISHER_ID, - placementId: TEST_PLACEMENT_ID - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - adUnitCode: 'test-div', - transactionId: '123456', - bidId: '789', - bidderRequestId: 'abc', - auctionId: 'xyz' - }; - - const validBidderRequest = { - bidderCode: 'newspassid', - auctionId: 'xyz', - bidderRequestId: 'abc', - bids: [validBidRequest], - gdprConsent: { - gdprApplies: true, - consentString: 'consent123' - }, - refererInfo: { - page: 'http://example.com' - } - }; - - const serverResponse = { - body: { - seatbid: [{ - bid: [{ - impid: '789', - price: 2.5, - w: 300, - h: 250, - crid: 'creative123', - adm: '
ad
', - adomain: ['advertiser.com'] - }] - }], - cur: 'USD' - } - }; - - describe('gvlid', function() { - it('should expose gvlid', function() { - expect(spec.gvlid).to.equal(1317); - }); - }); - - describe('resolveNewpassidPublisherId', function() { - afterEach(() => { - config.resetConfig(); - }); - - it('should return null if no bidrequest object or no global publisherId set', function() { - expect(resolveNewpassidPublisherId()).to.equal(null); - }); - - it('should return global publisherId if no bidrequest object and global publisherId set', function() { - config.setConfig({ - newspassid: { - publisherId: TEST_PUBLISHER_ID - } - }); - expect(resolveNewpassidPublisherId()).to.equal(TEST_PUBLISHER_ID); - }); - }); - - describe('isBidRequestValid', function() { - it('should return true when required params are present', function() { - expect(spec.isBidRequestValid(validBidRequest)).to.be.true; - }); - - it('should return false when publisherId is missing', function() { - const bid = deepClone(validBidRequest); - delete bid.params.publisherId; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false when placementId is missing', function() { - const bid = deepClone(validBidRequest); - delete bid.params.placementId; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - }); - - describe('buildRequests', function() { - it('should create request data', function() { - const requests = spec.buildRequests([validBidRequest], validBidderRequest); - expect(requests).to.have.lengthOf(1); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal('https://npid.amspbs.com/v0/bid/request'); - expect(requests[0].options.withCredentials).to.be.true; - }); - - it('should include bidder params in ortb2 request', function() { - const requests = spec.buildRequests([validBidRequest], validBidderRequest); - const data = requests[0].data; - expect(data.imp[0].ext.newspassid.publisher).to.equal(TEST_PUBLISHER_ID); - expect(data.imp[0].ext.newspassid.placementId).to.equal(TEST_PLACEMENT_ID); - }); - - it('should use global publisherId when not set in bid params', function() { - const validBidRequestWithoutPublisherId = { - ...validBidRequest, - params: { - placementId: TEST_PLACEMENT_ID - }, - }; - config.setConfig({ - newspassid: { - publisherId: TEST_PUBLISHER_ID - } - }); - const requests = spec.buildRequests([validBidRequestWithoutPublisherId], validBidderRequest); - const data = requests[0].data; - expect(data.imp[0].ext.newspassid.publisher).to.equal(TEST_PUBLISHER_ID); - expect(data.imp[0].ext.newspassid.placementId).to.equal(TEST_PLACEMENT_ID); - }); - - it('should use publisherId from bidRequest first over global publisherId', function() { - config.setConfig({ - newspassid: { - publisherId: TEST_PUBLISHER_ID - } - }); - const validBidRequestWithDifferentPublisherId = { - ...validBidRequest, - params: { - publisherId: 'publisherId123' - } - }; - const requests = spec.buildRequests([validBidRequestWithDifferentPublisherId], validBidderRequest); - const data = requests[0].data; - expect(data.imp[0].ext.newspassid.publisher).to.equal('publisherId123'); - }); - - it('should handle multiple bid requests', function() { - const secondBidRequest = deepClone(validBidRequest); - secondBidRequest.bidId = '790'; - const requests = spec.buildRequests([validBidRequest, secondBidRequest], validBidderRequest); - expect(requests).to.have.lengthOf(1); - expect(requests[0].data.imp).to.have.lengthOf(2); - }); - }); - - describe('interpretResponse', function() { - it('should return empty array if no valid bids', function() { - const invalidResponse = {body: {}}; - const bids = spec.interpretResponse(invalidResponse); - expect(bids).to.be.empty; - }); - - it('should return empty array if no seatbid', function() { - const noSeatbidResponse = {body: {cur: 'USD'}}; - const bids = spec.interpretResponse(noSeatbidResponse); - expect(bids).to.be.empty; - }); - - it('should interpret valid server response', function() { - const bids = spec.interpretResponse(serverResponse); - expect(bids).to.have.lengthOf(1); - expect(bids[0]).to.deep.equal({ - requestId: '789', - cpm: 2.5, - width: 300, - height: 250, - creativeId: 'creative123', - currency: 'USD', - netRevenue: true, - ttl: 300, - ad: '
ad
', - meta: { - advertiserDomains: ['advertiser.com'] - } - }); - }); - }); - - describe('getUserSyncs', function() { - afterEach(() => { - config.resetConfig(); - }); - - it('should expect correct host', function() { - const syncs = spec.getUserSyncs({iframeEnabled: true}, [], {}, '', {}); - const url = new URL(syncs[0].url); - expect(url.host).to.equal('npid.amspbs.com'); - }); - - it('should expect correct pathname', function() { - const syncs = spec.getUserSyncs({iframeEnabled: true}, [], {}, '', {}); - const url = new URL(syncs[0].url); - expect(url.pathname).to.equal('/v0/user/sync'); - }); - - it('should return empty array when iframe sync option is disabled', function() { - const syncs = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: false}); - expect(syncs).to.be.empty; - }); - - it('should use iframe sync when iframe enabled', function() { - const syncs = spec.getUserSyncs({iframeEnabled: true}); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.equal('https://npid.amspbs.com/v0/user/sync?gdpr=0&gdpr_consent=&gpp=&gpp_sid=&us_privacy='); - }); - - it('should include GDPR params if purpose 1 is true', function() { - const consentString = 'CQO03QAQO03QAPoABABGBiEIAIAAAIAAAACQKSwAQKSgpLABApKAAAAA.QKSwAQKSgAAA.IAAA'; // purpose 1 true - const gdprConsent = { - gdprApplies: true, - consentString: consentString, - vendorData: { - purpose: { - consents: { - 1: true - } - } - } - }; - const syncs = spec.getUserSyncs({iframeEnabled: true}, [], gdprConsent); - const url = new URL(syncs[0].url); - expect(url.searchParams.get('gdpr')).to.equal('1'); - expect(url.searchParams.get('gdpr_consent')).to.equal(encodeURIComponent(consentString)); - }); - - it('should disable user sync when purpose 1 is false', function() { - const consentString = 'CQO03QAQO03QAPoABABGBiEIAHAAAHAAAACQKSwAQKSgpLABApKAAAAA.QKSwAQKSgAAA.IAAA'; // purpose 1 false - const gdprConsent = { - gdprApplies: true, - consentString: consentString, - vendorData: { - purpose: { - consents: { - 1: false - } - } - } - }; - const syncs = spec.getUserSyncs({iframeEnabled: true}, [], gdprConsent); - expect(syncs).to.be.empty; - }); - - it('should include correct us_privacy param', function() { - const uspConsent = '1YNN'; - const syncs = spec.getUserSyncs({iframeEnabled: true}, [], {}, uspConsent, {}); - const url = new URL(syncs[0].url); - expect(url.searchParams.get('gdpr')).to.equal('0'); - expect(url.searchParams.get('gdpr_consent')).to.equal(''); - expect(url.searchParams.get('gpp')).to.equal(''); - expect(url.searchParams.get('gpp_sid')).to.equal(''); - expect(url.searchParams.get('us_privacy')).to.equal(uspConsent); - }); - - it('should include correct GPP params', function() { - const gppConsentString = 'DBABMA~1YNN'; - const gppSections = '2,6'; - const gppConsent = { - gppApplies: true, - gppString: gppConsentString, - applicableSections: gppSections - }; - const syncs = spec.getUserSyncs({iframeEnabled: true}, [], {}, '', gppConsent); - const url = new URL(syncs[0].url); - expect(url.searchParams.get('gdpr')).to.equal('0'); - expect(url.searchParams.get('gdpr_consent')).to.equal(''); - expect(url.searchParams.get('gpp')).to.equal(encodeURIComponent(gppConsentString)); - expect(url.searchParams.get('gpp_sid')).to.equal(encodeURIComponent(gppSections)); - expect(url.searchParams.get('us_privacy')).to.equal(''); - }); - - it('should include publisher param when publisherId is set in config', function() { - config.setConfig({ - newspassid: { - publisherId: TEST_PUBLISHER_ID - } - }); - const syncs = spec.getUserSyncs({iframeEnabled: true}); - const url = new URL(syncs[0].url); - expect(url.searchParams.get('gdpr')).to.equal('0'); - expect(url.searchParams.get('gdpr_consent')).to.equal(''); - expect(url.searchParams.get('gpp')).to.equal(''); - expect(url.searchParams.get('gpp_sid')).to.equal(''); - expect(url.searchParams.get('us_privacy')).to.equal(''); - expect(url.searchParams.get('publisher')).to.equal(encodeURIComponent(TEST_PUBLISHER_ID)); - }); - - it('should have zero user syncs if coppa is true', function() { - config.setConfig({coppa: true}); - const syncs = spec.getUserSyncs({iframeEnabled: true}); - expect(syncs).to.be.empty; - }); - - it('should include all params when all are present', function() { - const consentString = 'CQO03QAQO03QAPoABABGBiEIAIAAAIAAAACQKSwAQKSgpLABApKAAAAA.QKSwAQKSgAAA.IAAA'; // purpose 1 true - const gdprConsent = { - gdprApplies: true, - consentString: consentString, - vendorData: { - purpose: { - consents: { - 1: true - } - } - } - }; - const uspConsent = '1YNN'; - const gppConsentString = 'DBABMA~1YNN'; - const gppSections = '2,6'; - const gppConsent = { - gppApplies: true, - gppString: gppConsentString, - applicableSections: gppSections - }; - config.setConfig({ - newspassid: { - publisherId: TEST_PUBLISHER_ID - } - }); - const syncs = spec.getUserSyncs({iframeEnabled: true}, [], gdprConsent, uspConsent, gppConsent); - const url = new URL(syncs[0].url); - expect(url.searchParams.get('gdpr')).to.equal('1'); - expect(url.searchParams.get('gdpr_consent')).to.equal(encodeURIComponent(consentString)); - expect(url.searchParams.get('gpp')).to.equal(encodeURIComponent(gppConsentString)); - expect(url.searchParams.get('gpp_sid')).to.equal(encodeURIComponent(gppSections)); - expect(url.searchParams.get('us_privacy')).to.equal(encodeURIComponent(uspConsent)); - expect(url.searchParams.get('publisher')).to.equal(encodeURIComponent(TEST_PUBLISHER_ID)); - }); - }); -}); diff --git a/test/spec/modules/nextMillenniumBidAdapter_spec.js b/test/spec/modules/nextMillenniumBidAdapter_spec.js deleted file mode 100644 index 4cfa0e369..000000000 --- a/test/spec/modules/nextMillenniumBidAdapter_spec.js +++ /dev/null @@ -1,1341 +0,0 @@ -import { expect } from 'chai'; -import { - getImp, - setImpPos, - getSourceObj, - getExtNextMilImp, - replaceUsersyncMacros, - setConsentStrings, - setOrtb2Parameters, - setEids, - spec, -} from 'modules/nextMillenniumBidAdapter.js'; - -describe('nextMillenniumBidAdapterTests', () => { - describe('function getImp', () => { - const dataTests = [ - { - title: 'imp - banner', - data: { - id: '123', - postBody: {ext: {nextMillennium: {refresh_counts: {}, elemOffsets: {}}}}, - bid: { - mediaTypes: {banner: {sizes: [[300, 250], [320, 250]]}}, - adUnitCode: 'test-banner-1', - bidId: 'e36ea395f67f', - }, - - mediaTypes: { - banner: { - data: {sizes: [[300, 250], [320, 250]]}, - bidfloorcur: 'EUR', - bidfloor: 1.11, - pos: 3, - }, - }, - }, - - expected: { - id: 'e36ea395f67f', - bidfloorcur: 'EUR', - bidfloor: 1.11, - ext: {prebid: {storedrequest: {id: '123'}}}, - banner: { - pos: 3, - w: 300, - h: 250, - format: [{w: 300, h: 250}, {w: 320, h: 250}], - }, - }, - }, - - { - title: 'imp - video', - data: { - id: '234', - postBody: {ext: {nextMillennium: {refresh_counts: {}, elemOffsets: {}}}}, - bid: { - mediaTypes: {video: {playerSize: [400, 300], api: [2], placement: 1, plcmt: 1}}, - adUnitCode: 'test-video-1', - bidId: 'e36ea395f67f', - }, - - mediaTypes: { - video: { - data: {playerSize: [400, 300], api: [2], placement: 1, plcmt: 1}, - bidfloorcur: 'USD', - pos: 0, - }, - }, - }, - - expected: { - id: 'e36ea395f67f', - bidfloorcur: 'USD', - ext: {prebid: {storedrequest: {id: '234'}}}, - video: { - mimes: ['video/mp4', 'video/x-ms-wmv', 'application/javascript'], - api: [2], - placement: 1, - plcmt: 1, - w: 400, - h: 300, - pos: 0, - }, - }, - }, - - { - title: 'imp - mediaTypes.video is empty', - data: { - id: '234', - postBody: {ext: {nextMillennium: {refresh_counts: {}, elemOffsets: {}}}}, - bid: { - mediaTypes: {video: {w: 640, h: 480}}, - bidId: 'e36ea395f67f', - }, - - mediaTypes: { - video: { - data: {w: 640, h: 480}, - bidfloorcur: 'USD', - }, - }, - }, - - expected: { - id: 'e36ea395f67f', - bidfloorcur: 'USD', - ext: {prebid: {storedrequest: {id: '234'}}}, - video: {w: 640, h: 480, mimes: ['video/mp4', 'video/x-ms-wmv', 'application/javascript']}, - }, - }, - - { - title: 'imp with gpid', - data: { - id: '123', - postBody: {ext: {nextMillennium: {refresh_counts: {}, elemOffsets: {}}}}, - bid: { - mediaTypes: {banner: {sizes: [[300, 250], [320, 250]]}}, - adUnitCode: 'test-gpid-1', - bidId: 'e36ea395f67a', - ortb2Imp: {ext: {gpid: 'imp-gpid-123'}}, - }, - - mediaTypes: { - banner: { - data: {sizes: [[300, 250], [320, 250]]}, - }, - }, - }, - - expected: { - id: 'e36ea395f67a', - ext: { - prebid: {storedrequest: {id: '123'}}, - gpid: 'imp-gpid-123' - }, - banner: {w: 300, h: 250, format: [{w: 300, h: 250}, {w: 320, h: 250}]}, - }, - }, - - { - title: 'imp with pbadslot', - data: { - id: '123', - postBody: {ext: {nextMillennium: {refresh_counts: {}, elemOffsets: {}}}}, - bid: { - mediaTypes: {banner: {sizes: [[300, 250], [320, 250]]}}, - adUnitCode: 'test-gpid-1', - bidId: 'e36ea395f67a', - ortb2Imp: { - ext: { - data: { - pbadslot: 'slot-123' - } - } - }, - }, - - mediaTypes: { - banner: { - data: {sizes: [[300, 250], [320, 250]]}, - }, - }, - }, - - expected: { - id: 'e36ea395f67a', - ext: { - prebid: {storedrequest: {id: '123'}}, - }, - banner: {w: 300, h: 250, format: [{w: 300, h: 250}, {w: 320, h: 250}]}, - }, - }, - ]; - - for (const {title, data, expected} of dataTests) { - it(title, () => { - const {bid, id, mediaTypes, postBody} = data; - const imp = getImp(bid, id, mediaTypes, postBody); - expect(imp).to.deep.equal(expected); - }); - } - }); - - describe('function setImpPos', () => { - const tests = [ - { - title: 'position is - 1', - pos: 0, - expected: {pos: 0}, - }, - - { - title: 'position is - 2', - pos: 7, - expected: {pos: 7}, - }, - - { - title: 'position is empty', - expected: {}, - }, - ]; - - for (const {title, pos, expected} of tests) { - it(title, () => { - const obj = {}; - setImpPos(obj, pos); - expect(obj).to.deep.equal(expected); - }); - }; - }); - - describe('function getSourceObj', () => { - const dataTests = [ - { - title: 'schain is empty', - validBidRequests: [{}], - bidderRequest: {}, - expected: undefined, - }, - - { - title: 'schain is validBidReequest', - bidderRequest: {}, - validBidRequests: [{ - ortb2: { - source: { - ext: { - schain: { - validation: 'strict', - config: { - ver: '1.0', - complete: 1, - nodes: [{asi: 'test.test', sid: '00001', hp: 1}], - }, - }, - }, - }, - }, - }], - - expected: { - schain: { - validation: 'strict', - config: { - ver: '1.0', - complete: 1, - nodes: [{asi: 'test.test', sid: '00001', hp: 1}], - }, - }, - }, - }, - - { - title: 'schain is bidderReequest.ortb2.source.schain', - bidderRequest: { - ortb2: { - source: { - schain: { - validation: 'strict', - config: { - ver: '1.0', - complete: 1, - nodes: [{asi: 'test.test', sid: '00001', hp: 1}], - }, - }, - }, - }, - }, - - validBidRequests: [{}], - expected: { - schain: { - validation: 'strict', - config: { - ver: '1.0', - complete: 1, - nodes: [{asi: 'test.test', sid: '00001', hp: 1}], - }, - }, - }, - }, - - { - title: 'schain is bidderReequest.ortb2.source.ext.schain', - bidderRequest: { - ortb2: { - source: { - ext: { - schain: { - validation: 'strict', - config: { - ver: '1.0', - complete: 1, - nodes: [{asi: 'test.test', sid: '00001', hp: 1}], - }, - }, - }, - }, - }, - }, - - validBidRequests: [{}], - expected: { - schain: { - validation: 'strict', - config: { - ver: '1.0', - complete: 1, - nodes: [{asi: 'test.test', sid: '00001', hp: 1}], - }, - }, - }, - }, - ]; - - for (const {title, validBidRequests, bidderRequest, expected} of dataTests) { - it(title, () => { - const source = getSourceObj(validBidRequests, bidderRequest); - expect(source).to.deep.equal(expected); - }); - } - }); - - describe('function setConsentStrings', () => { - const dataTests = [ - { - title: 'full: uspConsent, gdprConsent and gppConsent', - data: { - postBody: {}, - bidderRequest: { - uspConsent: '1---', - gppConsent: {gppString: 'DBACNYA~CPXxRfAPXxR', applicableSections: [7]}, - gdprConsent: {consentString: 'kjfdniwjnifwenrif3', gdprApplies: true}, - ortb2: {regs: {gpp: 'DSFHFHWEUYVDC', gpp_sid: [8, 9, 10], coppa: 1}}, - }, - }, - - expected: { - user: {consent: 'kjfdniwjnifwenrif3'}, - regs: { - gpp: 'DBACNYA~CPXxRfAPXxR', - gpp_sid: [7], - gdpr: 1, - us_privacy: '1---', - coppa: 1 - }, - }, - }, - - { - title: 'gdprConsent(false) and ortb2(gpp)', - data: { - postBody: {}, - bidderRequest: { - gdprConsent: {consentString: 'ewtewbefbawyadexv', gdprApplies: false}, - ortb2: {regs: {gpp: 'DSFHFHWEUYVDC', gpp_sid: [8, 9, 10], coppa: 0}}, - }, - }, - - expected: { - user: {consent: 'ewtewbefbawyadexv'}, - regs: { - gpp: 'DSFHFHWEUYVDC', - gpp_sid: [8, 9, 10], - gdpr: 0, - coppa: 0, - }, - }, - }, - - { - title: 'gdprConsent(false)', - data: { - postBody: {}, - bidderRequest: {gdprConsent: {gdprApplies: false}}, - }, - - expected: { - regs: {gdpr: 0}, - }, - }, - - { - title: 'empty', - data: { - postBody: {}, - bidderRequest: {}, - }, - - expected: {}, - }, - ]; - - for (const {title, data, expected} of dataTests) { - it(title, () => { - const {postBody, bidderRequest} = data; - setConsentStrings(postBody, bidderRequest); - expect(postBody).to.deep.equal(expected); - }); - } - }); - - describe('function replaceUsersyncMacros', () => { - const dataTests = [ - { - title: 'url with all macroses - consents full: uspConsent, gdprConsent and gppConsent', - data: { - url: 'https://some.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}&type={{.TYPE_PIXEL}}', - uspConsent: '1---', - gppConsent: {gppString: 'DBACNYA~CPXxRfAPXxR', applicableSections: [7, 8]}, - gdprConsent: {consentString: 'kjfdniwjnifwenrif3', gdprApplies: true}, - type: 'image', - }, - - expected: 'https://some.url?gdpr=1&gdpr_consent=kjfdniwjnifwenrif3&us_privacy=1---&gpp=DBACNYA~CPXxRfAPXxR&gpp_sid=7,8&type=image', - }, - - { - title: 'url with some macroses - consents full: uspConsent, gdprConsent and gppConsent', - data: { - url: 'https://some.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&type={{.TYPE_PIXEL}}', - uspConsent: '1---', - gppConsent: {gppString: 'DBACNYA~CPXxRfAPXxR', applicableSections: [7, 8]}, - gdprConsent: {consentString: 'kjfdniwjnifwenrif3', gdprApplies: false}, - type: 'iframe', - }, - - expected: 'https://some.url?gdpr=0&gdpr_consent=kjfdniwjnifwenrif3&type=iframe', - }, - - { - title: 'url without macroses - consents full: uspConsent, gdprConsent and gppConsent', - data: { - url: 'https://some.url?param1=value1¶m2=value2', - uspConsent: '1---', - gppConsent: {gppString: 'DBACNYA~CPXxRfAPXxR', applicableSections: [7, 8]}, - gdprConsent: {consentString: 'kjfdniwjnifwenrif3', gdprApplies: false}, - type: 'iframe', - }, - - expected: 'https://some.url?param1=value1¶m2=value2', - }, - - { - title: 'url with all macroses - consents are empty', - data: { - url: 'https://some.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}&type={{.TYPE_PIXEL}}', - }, - - expected: 'https://some.url?gdpr=0&gdpr_consent=&us_privacy=&gpp=&gpp_sid=&type=', - }, - ]; - - for (const {title, data, expected} of dataTests) { - it(title, () => { - const {url, gdprConsent, uspConsent, gppConsent, type} = data; - const newUrl = replaceUsersyncMacros(url, gdprConsent, uspConsent, gppConsent, type); - expect(newUrl).to.equal(expected); - }); - } - }); - - describe('function spec.getUserSyncs', () => { - const dataTests = [ - { - title: 'pixels from responses ({iframeEnabled: true, pixelEnabled: true})', - data: { - syncOptions: {iframeEnabled: true, pixelEnabled: true}, - responses: [ - {body: {ext: {sync: { - image: [ - 'https://some.1.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}', - 'https://some.2.url?us_privacy={{.USPrivacy}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}', - 'https://some.3.url?param=1234', - ], - - iframe: [ - 'https://some.4.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}', - 'https://some.5.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}', - ], - }}}}, - - {body: {ext: {sync: { - iframe: [ - 'https://some.6.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}', - 'https://some.7.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}', - ], - }}}}, - - {body: {ext: {sync: { - image: [ - 'https://some.8.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}', - ], - }}}}, - ], - - uspConsent: '1---', - gppConsent: {gppString: 'DBACNYA~CPXxRfAPXxR', applicableSections: [7, 8]}, - gdprConsent: {consentString: 'kjfdniwjnifwenrif3', gdprApplies: true}, - }, - - expected: [ - {type: 'image', url: 'https://some.1.url?gdpr=1&gdpr_consent=kjfdniwjnifwenrif3&us_privacy=1---&gpp=DBACNYA~CPXxRfAPXxR&gpp_sid=7,8'}, - {type: 'image', url: 'https://some.2.url?us_privacy=1---&gpp=DBACNYA~CPXxRfAPXxR&gpp_sid=7,8'}, - {type: 'image', url: 'https://some.3.url?param=1234'}, - {type: 'iframe', url: 'https://some.4.url?gdpr=1&gdpr_consent=kjfdniwjnifwenrif3&gpp=DBACNYA~CPXxRfAPXxR&gpp_sid=7,8'}, - {type: 'iframe', url: 'https://some.5.url?gdpr=1&gdpr_consent=kjfdniwjnifwenrif3&us_privacy=1---'}, - {type: 'iframe', url: 'https://some.6.url?gdpr=1&gdpr_consent=kjfdniwjnifwenrif3&gpp=DBACNYA~CPXxRfAPXxR&gpp_sid=7,8'}, - {type: 'iframe', url: 'https://some.7.url?gdpr=1&gdpr_consent=kjfdniwjnifwenrif3&us_privacy=1---'}, - {type: 'image', url: 'https://some.8.url?gdpr=1&gdpr_consent=kjfdniwjnifwenrif3&us_privacy=1---&gpp=DBACNYA~CPXxRfAPXxR&gpp_sid=7,8'}, - ], - }, - - { - title: 'pixels from responses ({iframeEnabled: true, pixelEnabled: false})', - data: { - syncOptions: {iframeEnabled: true, pixelEnabled: false}, - responses: [ - {body: {ext: {sync: { - image: [ - 'https://some.1.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}', - 'https://some.2.url?us_privacy={{.USPrivacy}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}', - 'https://some.3.url?param=1234', - ], - - iframe: [ - 'https://some.4.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}', - 'https://some.5.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}', - ], - }}}}, - ], - - uspConsent: '1---', - gppConsent: {gppString: 'DBACNYA~CPXxRfAPXxR', applicableSections: [7, 8]}, - gdprConsent: {consentString: 'kjfdniwjnifwenrif3', gdprApplies: true}, - }, - - expected: [ - {type: 'iframe', url: 'https://some.4.url?gdpr=1&gdpr_consent=kjfdniwjnifwenrif3&gpp=DBACNYA~CPXxRfAPXxR&gpp_sid=7,8'}, - {type: 'iframe', url: 'https://some.5.url?gdpr=1&gdpr_consent=kjfdniwjnifwenrif3&us_privacy=1---'}, - ], - }, - - { - title: 'pixels from responses ({iframeEnabled: false, pixelEnabled: true})', - data: { - syncOptions: {iframeEnabled: false, pixelEnabled: true}, - responses: [ - {body: {ext: {sync: { - image: [ - 'https://some.1.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}', - 'https://some.2.url?us_privacy={{.USPrivacy}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}', - 'https://some.3.url?param=1234', - ], - - iframe: [ - 'https://some.4.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&gpp={{.GPP}}&gpp_sid={{.GPPSID}}', - 'https://some.5.url?gdpr={{.GDPR}}&gdpr_consent={{.GDPRConsent}}&us_privacy={{.USPrivacy}}', - ], - }}}}, - ], - - uspConsent: '1---', - gppConsent: {gppString: 'DBACNYA~CPXxRfAPXxR', applicableSections: [7, 8]}, - gdprConsent: {consentString: 'kjfdniwjnifwenrif3', gdprApplies: true}, - }, - - expected: [ - {type: 'image', url: 'https://some.1.url?gdpr=1&gdpr_consent=kjfdniwjnifwenrif3&us_privacy=1---&gpp=DBACNYA~CPXxRfAPXxR&gpp_sid=7,8'}, - {type: 'image', url: 'https://some.2.url?us_privacy=1---&gpp=DBACNYA~CPXxRfAPXxR&gpp_sid=7,8'}, - {type: 'image', url: 'https://some.3.url?param=1234'}, - ], - }, - - { - title: 'pixels - responses is empty ({iframeEnabled: true, pixelEnabled: true})', - data: { - syncOptions: {iframeEnabled: true, pixelEnabled: true}, - responses: [], - uspConsent: '1---', - gppConsent: {gppString: 'DBACNYA~CPXxRfAPXxR', applicableSections: [7, 8]}, - gdprConsent: {consentString: 'kjfdniwjnifwenrif3', gdprApplies: true}, - }, - - expected: [ - {type: 'image', url: 'https://cookies.nextmillmedia.com/sync?gdpr=1&gdpr_consent=kjfdniwjnifwenrif3&us_privacy=1---&gpp=DBACNYA~CPXxRfAPXxR&gpp_sid=7,8&type=image'}, - {type: 'iframe', url: 'https://cookies.nextmillmedia.com/sync?gdpr=1&gdpr_consent=kjfdniwjnifwenrif3&us_privacy=1---&gpp=DBACNYA~CPXxRfAPXxR&gpp_sid=7,8&type=iframe'}, - ], - }, - - { - title: 'pixels - responses is empty ({iframeEnabled: true, pixelEnabled: false})', - data: { - syncOptions: {iframeEnabled: true, pixelEnabled: false}, - uspConsent: '1---', - gppConsent: {gppString: 'DBACNYA~CPXxRfAPXxR', applicableSections: [7, 8]}, - gdprConsent: {consentString: 'kjfdniwjnifwenrif3', gdprApplies: true}, - }, - - expected: [ - {type: 'iframe', url: 'https://cookies.nextmillmedia.com/sync?gdpr=1&gdpr_consent=kjfdniwjnifwenrif3&us_privacy=1---&gpp=DBACNYA~CPXxRfAPXxR&gpp_sid=7,8&type=iframe'}, - ], - }, - - { - title: 'pixels - responses is empty ({iframeEnabled: false, pixelEnabled: false})', - data: { - syncOptions: {iframeEnabled: false, pixelEnabled: false}, - uspConsent: '1---', - gppConsent: {gppString: 'DBACNYA~CPXxRfAPXxR', applicableSections: [7, 8]}, - gdprConsent: {consentString: 'kjfdniwjnifwenrif3', gdprApplies: true}, - }, - - expected: [], - }, - ]; - - for (const {title, data, expected} of dataTests) { - it(title, () => { - const {syncOptions, responses, gdprConsent, uspConsent, gppConsent} = data; - const pixels = spec.getUserSyncs(syncOptions, responses, gdprConsent, uspConsent, gppConsent); - expect(pixels).to.deep.equal(expected); - }); - } - }); - - describe('function setOrtb2Parameters', () => { - const dataTests = [ - { - title: 'site.pagecat, site.content.cat and site.content.language', - data: { - postBody: {}, - ortb2: { - bcat: ['IAB1-3', 'IAB1-4'], - badv: ['domain1.com', 'domain2.com'], - wlang: ['en', 'fr', 'de'], - wlangb: ['en', 'fr', 'de'], - site: { - pagecat: ['IAB2-11', 'IAB2-12', 'IAB2-14'], - content: {cat: ['IAB2-11', 'IAB2-12', 'IAB2-14'], language: 'EN'}, - } - }, - }, - - expected: { - bcat: ['IAB1-3', 'IAB1-4'], - badv: ['domain1.com', 'domain2.com'], - wlang: ['en', 'fr', 'de'], - site: { - pagecat: ['IAB2-11', 'IAB2-12', 'IAB2-14'], - content: {cat: ['IAB2-11', 'IAB2-12', 'IAB2-14'], language: 'EN'}, - } - }, - }, - - { - title: 'site.keywords, site.content.keywords and user.keywords', - data: { - postBody: {}, - ortb2: { - wlangb: ['en', 'fr', 'de'], - user: {keywords: 'key7,key8,key9'}, - site: { - keywords: 'key1,key2,key3', - content: {keywords: 'key4,key5,key6'}, - }, - }, - }, - - expected: { - wlangb: ['en', 'fr', 'de'], - user: {keywords: 'key7,key8,key9'}, - site: { - keywords: 'key1,key2,key3', - content: {keywords: 'key4,key5,key6'}, - }, - }, - }, - - { - title: 'only site.content.language', - data: { - postBody: {site: {domain: 'some.domain'}}, - ortb2: {site: { - content: {language: 'EN'}, - }}, - }, - - expected: {site: { - domain: 'some.domain', - content: {language: 'EN'}, - }}, - }, - - { - title: 'object ortb2 is empty', - data: { - postBody: {imp: []}, - }, - - expected: {imp: []}, - }, - ]; - - for (const {title, data, expected} of dataTests) { - it(title, () => { - const {postBody, ortb2} = data; - setOrtb2Parameters(postBody, ortb2); - expect(postBody).to.deep.equal(expected); - }); - }; - }); - - describe('function setEids', () => { - const dataTests = [ - { - title: 'setEids - userIdAsEids is empty', - data: { - postBody: {}, - bids: [{ - userIdAsEids: undefined, - }], - }, - - expected: {}, - }, - - { - title: 'setEids - userIdAsEids - array is empty', - data: { - postBody: {}, - bids: [{ - userIdAsEids: [], - }], - }, - - expected: {}, - }, - - { - title: 'setEids - userIdAsEids is', - data: { - postBody: {}, - bids: [ - { - userIdAsEids: [], - }, - - { - userIdAsEids: [ - { - source: '33across.com', - uids: [{id: 'some-random-id-value', atype: 1}], - }, - - { - source: 'utiq.com', - uids: [{id: 'some-random-id-value', atype: 1}], - }, - ], - }, - - { - userIdAsEids: [ - { - source: 'test.test', - uids: [{id: 'some-random-id-value', atype: 1}], - }, - ], - }, - ], - }, - - expected: { - user: { - eids: [ - { - source: '33across.com', - uids: [{id: 'some-random-id-value', atype: 1}], - }, - - { - source: 'utiq.com', - uids: [{id: 'some-random-id-value', atype: 1}], - }, - ], - }, - }, - }, - ]; - - for (const { title, data, expected } of dataTests) { - it(title, () => { - const { postBody, bids } = data; - setEids(postBody, bids); - expect(postBody).to.deep.equal(expected); - }); - } - }); - - const bidRequestDataGI = getBidRequestDataGI(); - function getBidRequestDataGI(adUnitCodes = ['test-banner-gi', 'test-banner-gi', 'test-video-gi']) { - return [ - { - adUnitCode: adUnitCodes[0], - bidId: 'bid1234', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidder: 'nextMillennium', - params: { group_id: '1234' }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - - sizes: [[300, 250]], - uspConsent: '1---', - gdprConsent: { - consentString: 'kjfdniwjnifwenrif3', - gdprApplies: true - } - }, - - { - adUnitCode: adUnitCodes[1], - bidId: 'bid1235', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidder: 'nextMillennium', - params: { group_id: '1234' }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 300]] - } - }, - - sizes: [[300, 250], [300, 300]], - uspConsent: '1---', - gdprConsent: { - consentString: 'kjfdniwjnifwenrif3', - gdprApplies: true - } - }, - - { - adUnitCode: adUnitCodes[2], - bidId: 'bid1236', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidder: 'nextMillennium', - params: { group_id: '1234' }, - mediaTypes: { - video: { - playerSize: [640, 480], - } - }, - - uspConsent: '1---', - gdprConsent: { - consentString: 'kjfdniwjnifwenrif3', - gdprApplies: true - } - }, - ]; - } - - describe('check parameters group_id or placement_id', function() { - let numberTest = 0 - for (const test of bidRequestDataGI) { - it(`test - ${++numberTest}`, () => { - const request = spec.buildRequests([test]); - const requestData = JSON.parse(request[0].data); - const storeRequestId = (requestData.imp[0].ext.prebid.storedrequest.id || ''); - expect(storeRequestId.length).to.be.not.equal(0); - - const srId = storeRequestId.split(';'); - const isGroupId = (/^g[1-9]\d*/).test(srId[0]); - if (isGroupId) { - expect(srId.length).to.be.equal(3); - expect((/^g[1-9]\d*/).test(srId[0])).to.be.true; - const sizes = srId[1].split('|'); - for (const size of sizes) { - if (!(/^[1-9]\d*[xX,][1-9]\d*$/).test(size)) { - expect(storeRequestId).to.be.equal(''); - } - - expect((/^[1-9]\d*[xX,][1-9]\d*$/).test(size)).to.be.true; - } - } else { - expect(srId.length).to.be.equal(1); - expect((/^[1-9]\d*/).test(srId[0])).to.be.true; - }; - }); - }; - }); - - describe('Check ext.next_mil_imps', function() { - const expectedNextMilImps = [ - { - impId: 'bid1234', - nextMillennium: {refresh_count: 1}, - }, - - { - impId: 'bid1235', - nextMillennium: {refresh_count: 1}, - }, - - { - impId: 'bid1236', - nextMillennium: {refresh_count: 1}, - }, - ]; - - const dataForRequest = getBidRequestDataGI(expectedNextMilImps.map(el => el.impId)); - for (let j = 0; j < 2; j++) { - const request = spec.buildRequests(dataForRequest); - const bidRequest = JSON.parse(request[0].data); - for (let i = 0; i < bidRequest.ext.next_mil_imps.length; i++) { - it(`test - ${j * i + 1}`, () => { - const nextMilImp = bidRequest.ext.next_mil_imps[i]; - expect(nextMilImp.impId).to.deep.equal(expectedNextMilImps[i].impId); - expect(nextMilImp.nextMillennium.refresh_count).to.deep.equal(expectedNextMilImps[i].nextMillennium.refresh_count + j); - }) - }; - }; - }); - - describe('function spec._getUrlPixelMetric', function() { - const dataForTests = [ - { - title: 'Check function of getting URL for sending statistics data - 1', - eventName: 'bidRequested', - bids: { - bidderCode: 'appnexus', - bids: [{bidder: 'appnexus', params: {}}], - }, - - expected: undefined, - }, - - { - title: 'Check function of getting URL for sending statistics data - 2', - eventName: 'bidRequested', - bids: { - bidderCode: 'appnexus', - bids: [{bidder: 'appnexus', params: {placement_id: '807'}}], - }, - - expected: undefined, - }, - - { - title: 'Check function of getting URL for sending statistics data - 3', - eventName: 'bidRequested', - bids: { - bidderCode: 'nextMillennium', - bids: [{bidder: 'nextMillennium', params: {placement_id: '807'}}], - }, - - expected: 'https://hb-analytics.nextmillmedia.com/statistics/metric?event=bidRequested&bidder=nextMillennium&source=pbjs&placements=807', - }, - - { - title: 'Check function of getting URL for sending statistics data - 4', - eventName: 'bidRequested', - bids: { - bidderCode: 'nextMillennium', - bids: [ - {bidder: 'nextMillennium', params: {placement_id: '807'}}, - {bidder: 'nextMillennium', params: {placement_id: '111'}}, - ], - }, - - expected: 'https://hb-analytics.nextmillmedia.com/statistics/metric?event=bidRequested&bidder=nextMillennium&source=pbjs&placements=807;111', - }, - - { - title: 'Check function of getting URL for sending statistics data - 5', - eventName: 'bidRequested', - bids: { - bidderCode: 'nextMillennium', - bids: [{bidder: 'nextMillennium', params: {placement_id: '807', group_id: '123'}}], - }, - - expected: 'https://hb-analytics.nextmillmedia.com/statistics/metric?event=bidRequested&bidder=nextMillennium&source=pbjs&groups=123', - }, - - { - title: 'Check function of getting URL for sending statistics data - 6', - eventName: 'bidRequested', - bids: { - bidderCode: 'nextMillennium', - bids: [ - {bidder: 'nextMillennium', params: {placement_id: '807', group_id: '123'}}, - {bidder: 'nextMillennium', params: {group_id: '456'}}, - {bidder: 'nextMillennium', params: {placement_id: '222'}}, - ], - }, - - expected: 'https://hb-analytics.nextmillmedia.com/statistics/metric?event=bidRequested&bidder=nextMillennium&source=pbjs&groups=123;456&placements=222', - }, - - { - title: 'Check function of getting URL for sending statistics data - 7', - eventName: 'bidResponse', - bids: { - bidderCode: 'appnexus', - }, - - expected: undefined, - }, - - { - title: 'Check function of getting URL for sending statistics data - 8', - eventName: 'bidResponse', - bids: { - bidderCode: 'nextMillennium', - params: {placement_id: '807'}, - }, - - expected: 'https://hb-analytics.nextmillmedia.com/statistics/metric?event=bidResponse&bidder=nextMillennium&source=pbjs&placements=807', - }, - - { - title: 'Check function of getting URL for sending statistics data - 9', - eventName: 'noBid', - bids: { - bidder: 'appnexus', - }, - - expected: undefined, - }, - - { - title: 'Check function of getting URL for sending statistics data - 10', - eventName: 'noBid', - bids: { - bidder: 'nextMillennium', - params: {placement_id: '807'}, - }, - - expected: 'https://hb-analytics.nextmillmedia.com/statistics/metric?event=noBid&bidder=nextMillennium&source=pbjs&placements=807', - }, - - { - title: 'Check function of getting URL for sending statistics data - 11', - eventName: 'bidTimeout', - bids: { - bidder: 'appnexus', - }, - - expected: undefined, - }, - - { - title: 'Check function of getting URL for sending statistics data - 12', - eventName: 'bidTimeout', - bids: { - bidder: 'nextMillennium', - params: {placement_id: '807'}, - }, - - expected: 'https://hb-analytics.nextmillmedia.com/statistics/metric?event=bidTimeout&bidder=nextMillennium&source=pbjs&placements=807', - }, - - { - title: 'Check function of getting URL for sending statistics data - 13', - eventName: 'bidRequested', - bids: [ - { - bidderCode: 'nextMillennium', - bids: [ - {bidder: 'nextMillennium', params: {placement_id: '807', group_id: '123'}}, - {bidder: 'nextMillennium', params: {group_id: '456'}}, - {bidder: 'nextMillennium', params: {placement_id: '222'}}, - ], - }, - - { - bidderCode: 'nextMillennium', - params: {group_id: '7777'}, - }, - - { - bidderCode: 'nextMillennium', - params: {placement_id: '8888'}, - }, - ], - - expected: 'https://hb-analytics.nextmillmedia.com/statistics/metric?event=bidRequested&bidder=nextMillennium&source=pbjs&groups=123;456;7777&placements=222;8888', - }, - ]; - - for (const {title, eventName, bids, expected} of dataForTests) { - it(title, () => { - const url = spec._getUrlPixelMetric(eventName, bids); - expect(url).to.equal(expected); - }); - }; - }); - - describe('check function buildRequests', () => { - const tests = [ - { - title: 'test - 1', - bidderRequest: {bidderRequestId: 'mock-uuid', timeout: 1200}, - bidRequests: [ - { - adUnitCode: 'test-div', - bidId: 'bid1234', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidder: 'nextMillennium', - params: { placement_id: '-1' }, - sizes: [[300, 250]], - uspConsent: '1---', - gppConsent: {gppString: 'DBACNYA~CPXxRfAPXxR', applicableSections: [7]}, - gdprConsent: { - consentString: 'kjfdniwjnifwenrif3', - gdprApplies: true - }, - - ortb2: { - device: { - w: 1500, - h: 1000 - }, - - site: { - domain: 'example.com', - page: 'http://example.com' - } - } - }, - - { - adUnitCode: 'test-div-2', - bidId: 'bid1235', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidder: 'nextMillennium', - params: { placement_id: '333' }, - sizes: [[300, 250]], - uspConsent: '1---', - gppConsent: {gppString: 'DBACNYA~CPXxRfAPXxR', applicableSections: [7]}, - gdprConsent: { - consentString: 'kjfdniwjnifwenrif3', - gdprApplies: true - }, - - ortb2: { - device: { - w: 1500, - h: 1000 - }, - - site: { - domain: 'example.com', - page: 'http://example.com' - } - }, - }, - ], - - expected: { - id: 'mock-uuid', - impSize: 2, - requestSize: 1, - domain: 'example.com', - tmax: 1200, - }, - }, - ]; - - for (const {title, bidRequests, bidderRequest, expected} of tests) { - it(title, () => { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.length).to.equal(expected.requestSize); - - const requestData = JSON.parse(request[0].data); - expect(requestData.id).to.equal(expected.id); - expect(requestData.tmax).to.equal(expected.tmax); - expect(requestData?.imp?.length).to.equal(expected.impSize); - }); - }; - }); - - describe('check function interpretResponse', () => { - const tests = [ - { - title: 'test - 1', - serverResponse: { - body: { - id: 'f7b3d2da-e762-410c-b069-424f92c4c4b2', - seatbid: [ - { - bid: [ - { - id: '7457329903666272789-0', - impid: '700ce0a43f72', - price: 0.5, - adm: 'Hello! It\'s a test ad!', - adid: '96846035-0', - adomain: ['test.addomain.com'], - w: 300, - h: 250, - }, - - { - id: '7457329903666272789-1', - impid: '700ce0a43f73', - price: 0.7, - adm: 'https://some_vast_host.com/vast.xml', - adid: '96846035-1', - adomain: ['test.addomain.com'], - w: 400, - h: 300, - ext: {prebid: {type: 'video'}}, - }, - - { - id: '7457329903666272789-2', - impid: '700ce0a43f74', - price: 1.0, - adm: '', - adid: '96846035-3', - adomain: ['test.addomain.com'], - w: 640, - h: 480, - ext: {prebid: {type: 'video'}}, - }, - ], - }, - ], - cur: 'USD', - }, - }, - - expected: [ - { - title: 'banner', - requestId: '700ce0a43f72', - creativeId: '96846035-0', - ad: 'Hello! It\'s a test ad!', - vastUrl: undefined, - vastXml: undefined, - cpm: 0.5, - width: 300, - height: 250, - currency: 'USD', - }, - - { - title: 'video - vastUrl', - requestId: '700ce0a43f73', - creativeId: '96846035-1', - ad: undefined, - vastUrl: 'https://some_vast_host.com/vast.xml', - vastXml: undefined, - cpm: 0.7, - width: 400, - height: 300, - currency: 'USD', - }, - - { - title: 'video - vastXml', - requestId: '700ce0a43f74', - creativeId: '96846035-3', - ad: undefined, - vastUrl: undefined, - vastXml: '', - cpm: 1.0, - width: 640, - height: 480, - currency: 'USD', - }, - ], - }, - ]; - - for (const {title, serverResponse, bidRequest, expected} of tests) { - describe(title, () => { - const bids = spec.interpretResponse(serverResponse, bidRequest); - for (let i = 0; i < bids.length; i++) { - it(expected[i].title, () => { - expect(bids).to.have.lengthOf(expected.length); - - const bid = bids[i] - expect(bid.creativeId).to.equal(expected[i].creativeId); - expect(bid.requestId).to.equal(expected[i].requestId); - expect(bid.ad).to.equal(expected[i].ad); - expect(bid.vastUrl).to.equal(expected[i].vastUrl); - expect(bid.vastXml).to.equal(expected[i].vastXml); - expect(bid.cpm).to.equal(expected[i].cpm); - expect(bid.width).to.equal(expected[i].width); - expect(bid.height).to.equal(expected[i].height); - expect(bid.currency).to.equal(expected[i].currency); - }); - }; - }); - }; - }); - - describe('getExtNextMilImp parameters adSlots and allowedAds', () => { - const tests = [ - { - title: 'parameters adSlots and allowedAds are empty', - bid: { - params: {}, - }, - - expected: {}, - }, - - { - title: 'parameters adSlots and allowedAds', - bid: { - params: { - adSlots: ['test1'], - allowedAds: ['test2'], - }, - }, - - expected: { - adSlots: ['test1'], - allowedAds: ['test2'], - }, - }, - ]; - - for (const {title, bid, expected} of tests) { - it(title, () => { - const extNextMilImp = getExtNextMilImp(bid); - expect(extNextMilImp.nextMillennium.adSlots).to.deep.equal(expected.adSlots); - expect(extNextMilImp.nextMillennium.allowedAds).to.deep.equal(expected.allowedAds); - }); - }; - }); -}); diff --git a/test/spec/modules/nextrollBidAdapter_spec.js b/test/spec/modules/nextrollBidAdapter_spec.js deleted file mode 100644 index 5838e2929..000000000 --- a/test/spec/modules/nextrollBidAdapter_spec.js +++ /dev/null @@ -1,290 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/nextrollBidAdapter.js'; -import * as utils from 'src/utils.js'; -import { deepClone } from '../../../src/utils.js'; - -describe('nextrollBidAdapter', function() { - let utilsMock; - beforeEach(function () { - utilsMock = sinon.mock(utils); - }); - - afterEach(function() { - global.NextRoll = undefined; - utilsMock.restore(); - }); - - const validBid = { - bidder: 'nextroll', - adUnitCode: 'adunit-code', - bidId: 'bid_id', - sizes: [[300, 200]], - params: { - bidfloor: 1, - zoneId: 'zone1', - publisherId: 'publisher_id' - } - }; - const bidWithoutValidId = { id: '' }; - const bidWithoutId = { params: { zoneId: 'zone1' } }; - - describe('nativeBidRequest', () => { - it('validates native spec', () => { - const nativeAdUnit = [{ - bidder: 'nextroll', - adUnitCode: 'adunit-code', - bidId: 'bid_id', - mediaTypes: { - native: { - title: {required: true, len: 80}, - image: {required: true, sizes: [728, 90]}, - sponsoredBy: {required: false, len: 20}, - clickUrl: {required: true}, - body: {required: true, len: 25}, - icon: {required: true, sizes: [50, 50], aspect_ratios: [{ratio_height: 3, ratio_width: 4}]}, - someRandomAsset: {required: false, len: 100} // This should be ignored - } - }, - params: { - bidfloor: 1, - zoneId: 'zone1', - publisherId: 'publisher_id' - } - }]; - - const request = spec.buildRequests(nativeAdUnit) - const assets = request[0].data.imp.native.request.native.assets - - const excptedAssets = [ - {id: 1, required: 1, title: {len: 80}}, - {id: 2, required: 1, img: {w: 728, h: 90, wmin: 1, hmin: 1, type: 3}}, - {id: 3, required: 1, img: {w: 50, h: 50, wmin: 4, hmin: 3, type: 1}}, - {id: 5, required: 0, data: {len: 20, type: 1}}, - {id: 6, required: 1, data: {len: 25, type: 2}} - ] - expect(assets).to.be.deep.equal(excptedAssets) - }) - }) - - describe('isBidRequestValid', function() { - it('validates the bids correctly when the bid has an id', function() { - expect(spec.isBidRequestValid(validBid)).to.be.true; - }); - - it('validates the bids correcly when the bid does not have an id', function() { - expect(spec.isBidRequestValid(bidWithoutValidId)).to.be.false; - expect(spec.isBidRequestValid(bidWithoutId)).to.be.false; - }); - }); - - describe('buildRequests', function() { - it('builds the same amount of requests as valid requests it takes', function() { - expect(spec.buildRequests([validBid, validBid], {})).to.be.lengthOf(2); - }); - - it('doest not build a request when there is no valid requests', function () { - expect(spec.buildRequests([], {})).to.be.lengthOf(0); - }); - - it('builds a request with POST method', function () { - expect(spec.buildRequests([validBid], {})[0].method).to.equal('POST'); - }); - - it('builds a request with cookies method', function () { - expect(spec.buildRequests([validBid], {})[0].options.withCredentials).to.be.true; - }); - - it('builds a request with id, url and imp object', function () { - const request = spec.buildRequests([validBid], {})[0]; - expect(request.data.id).to.be.an('string').that.is.not.empty; - expect(request.url).to.equal('https://d.adroll.com/bid/prebid/'); - expect(request.data.imp).to.exist.and.to.be.a('object'); - }); - - it('builds a request with site and device information', function () { - const request = spec.buildRequests([validBid], {})[0]; - - expect(request.data.site).to.exist.and.to.be.a('object'); - expect(request.data.device).to.exist.and.to.be.a('object'); - }); - - it('builds a request with a complete imp object', function () { - const request = spec.buildRequests([validBid], {})[0]; - - expect(request.data.imp.id).to.equal('bid_id'); - expect(request.data.imp.bidfloor).to.be.equal(1); - expect(request.data.imp.banner).to.exist.and.to.be.a('object'); - expect(request.data.imp.ext.zone.id).to.be.equal('zone1'); - }); - - it('builds a request with the correct floor object', function () { - // bidfloor is defined, getFloor isn't - let bid = deepClone(validBid); - let request = spec.buildRequests([bid], {})[0]; - expect(request.data.imp.bidfloor).to.be.equal(1); - - // bidfloor not defined, getFloor not defined - bid = deepClone(validBid); - bid.params.bidfloor = null; - request = spec.buildRequests([bid], {})[0]; - expect(request.data.imp.bidfloor).to.not.exist; - - // bidfloor defined, getFloor defined, use getFloor - const getFloorResponse = { currency: 'USD', floor: 3 }; - bid = deepClone(validBid); - bid.getFloor = () => getFloorResponse; - request = spec.buildRequests([bid], {})[0]; - - expect(request.data.imp.bidfloor).to.exist.and.to.equal(3); - }); - - it('includes the sizes into the request correctly', function () { - const bannerObject = spec.buildRequests([validBid], {})[0].data.imp.banner; - - expect(bannerObject.format).to.exist; - expect(bannerObject.format).to.be.lengthOf(1); - expect(bannerObject.format[0].w).to.be.equal(300); - expect(bannerObject.format[0].h).to.be.equal(200); - }); - - it('sets the CCPA consent string', function () { - const us_privacy = '1YYY'; - const request = spec.buildRequests([validBid], {'uspConsent': us_privacy})[0]; - - expect(request.data.regs.ext.us_privacy).to.be.equal(us_privacy); - }); - }); - - describe('interpretResponse', function () { - const responseBody = { - id: 'bidresponse_id', - dealId: 'deal_id', - seatbid: [ - { - bid: [ - { - price: 1.2, - w: 300, - h: 200, - crid: 'crid1', - adm: 'adm1' - } - ] - }, - { - bid: [ - { - price: 2.1, - w: 250, - h: 300, - crid: 'crid2', - adm: 'adm2' - } - ] - } - ] - }; - - it('returns an empty list when there is no response body', function () { - expect(spec.interpretResponse({}, {})).to.be.eql([]); - }); - - it('builds the same amount of responses as server responses it receives', function () { - expect(spec.interpretResponse({body: responseBody}, {})).to.be.lengthOf(2); - }); - - it('builds a response with the expected fields', function () { - const response = spec.interpretResponse({body: responseBody}, {})[0]; - - expect(response.requestId).to.be.equal('bidresponse_id'); - expect(response.cpm).to.be.equal(1.2); - expect(response.width).to.be.equal(300); - expect(response.height).to.be.equal(200); - expect(response.creativeId).to.be.equal('crid1'); - expect(response.dealId).to.be.equal('deal_id'); - expect(response.currency).to.be.equal('USD'); - expect(response.netRevenue).to.be.equal(true); - expect(response.ttl).to.be.equal(300); - expect(response.ad).to.be.equal('adm1'); - }); - }); - - describe('interpret native response', () => { - const clickUrl = 'https://clickurl.com/with/some/path' - const titleText = 'Some title' - const imgW = 300 - const imgH = 250 - const imgUrl = 'https://clickurl.com/img.png' - const brandText = 'Some Brand' - const impUrl = 'https://clickurl.com/imptracker' - - const responseBody = { - body: { - id: 'bidresponse_id', - seatbid: [{ - bid: [{ - price: 1.2, - crid: 'crid1', - adm: { - link: {url: clickUrl}, - assets: [ - {id: 1, title: {text: titleText}}, - {id: 2, img: {w: imgW, h: imgH, url: imgUrl}}, - {id: 5, data: {value: brandText}} - ], - imptrackers: [impUrl] - } - }] - }] - } - }; - - it('Should interpret response', () => { - const response = spec.interpretResponse(utils.deepClone(responseBody)) - const expectedResponse = { - clickUrl: clickUrl, - impressionTrackers: [impUrl], - privacyLink: 'https://app.adroll.com/optout/personalized', - privacyIcon: 'https://s.adroll.com/j/ad-choices-small.png', - title: titleText, - image: {url: imgUrl, width: imgW, height: imgH}, - sponsoredBy: brandText, - clickTrackers: [], - jstracker: [] - } - - expect(response[0].native).to.be.deep.equal(expectedResponse) - }) - - it('Should interpret all assets', () => { - const allAssetsResponse = utils.deepClone(responseBody) - const iconUrl = imgUrl + '?icon=true'; const iconW = 10; const iconH = 15 - const logoUrl = imgUrl + '?logo=true'; const logoW = 20; const logoH = 25 - const bodyText = 'Some body text' - - allAssetsResponse.body.seatbid[0].bid[0].adm.assets.push(...[ - {id: 3, img: {w: iconW, h: iconH, url: iconUrl}}, - {id: 4, img: {w: logoW, h: logoH, url: logoUrl}}, - {id: 6, data: {value: bodyText}} - ]) - - const response = spec.interpretResponse(allAssetsResponse) - const expectedResponse = { - clickUrl: clickUrl, - impressionTrackers: [impUrl], - jstracker: [], - clickTrackers: [], - privacyLink: 'https://app.adroll.com/optout/personalized', - privacyIcon: 'https://s.adroll.com/j/ad-choices-small.png', - title: titleText, - image: {url: imgUrl, width: imgW, height: imgH}, - icon: {url: iconUrl, width: iconW, height: iconH}, - logo: {url: logoUrl, width: logoW, height: logoH}, - body: bodyText, - sponsoredBy: brandText - } - - expect(response[0].native).to.be.deep.equal(expectedResponse) - }) - }) -}); diff --git a/test/spec/modules/nexverseBidAdapter_spec.js b/test/spec/modules/nexverseBidAdapter_spec.js deleted file mode 100644 index 63d4046a2..000000000 --- a/test/spec/modules/nexverseBidAdapter_spec.js +++ /dev/null @@ -1,216 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/nexverseBidAdapter.js'; -import { getDeviceModel, buildEndpointUrl, parseNativeResponse } from '../../../libraries/nexverseUtils/index.js'; -import { getOsVersion } from '../../../libraries/advangUtils/index.js'; - -const BIDDER_ENDPOINT = 'https://rtb.nexverse.ai'; - -describe('nexverseBidAdapterTests', () => { - describe('isBidRequestValid', function () { - const sbid = { - 'adUnitCode': 'div', - 'bidder': 'nexverse', - 'params': { - 'uid': '77d4a2eb3d209ce6c7691dc79fcab358', - 'pubId': '24051' - }, - }; - - it('should not accept bid without required params', function () { - const isValid = spec.isBidRequestValid(sbid); - expect(isValid).to.equal(false); - }); - - it('should return false when params are not passed', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.params = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when valid params are not passed', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.params = {uid: '', pubId: '', pubEpid: ''}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when valid params are not passed', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.adUnitCode = ''; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - bid.params = {uid: '77d4a2eb3d209ce6c7691dc79fcab358', pubId: '24051'}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return true when valid params are passed as nums', function () { - const bid = Object.assign({}, sbid); - delete bid.params; - bid.mediaTypes = { - banner: { - sizes: [[300, 250]] - } - }; - bid.params = {uid: '77d4a2eb3d209ce6c7691dc79fcab358', pubId: '24051', pubEpid: '34561'}; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - - describe('getDeviceModel', () => { - it('should return "iPhone" for iPhone userAgent', function () { - Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_0 like Mac OS X)', configurable: true }); - expect(getDeviceModel()).to.equal('iPhone'); - }); - - it('should return "iPad" for iPad userAgent', function () { - Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (iPad; CPU OS 14_0 like Mac OS X)', configurable: true }); - expect(getDeviceModel()).to.equal('iPad'); - }); - - it('should return the Android device name for Android userAgent', function () { - Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (Linux; Android 10; Pixel 3 Build/QQ2A.200305.003) AppleWebKit/537.36', configurable: true }); - expect(getDeviceModel()).to.equal('Pixel 3'); - }); - - it('should return "Unknown Android Device" if device name is missing in Android userAgent', function () { - Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (Linux; Android 10;) AppleWebKit/537.36', configurable: true }); - expect(getDeviceModel()).to.equal('Unknown Android Device'); - }); - - it('should return "Mac" for Mac userAgent', function () { - Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7)', configurable: true }); - expect(getDeviceModel()).to.equal('Mac'); - }); - - it('should return "Linux" for Linux userAgent', function () { - Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (X11; Linux x86_64)', configurable: true }); - expect(getDeviceModel()).to.equal('Linux'); - }); - - it('should return "Windows PC" for Windows userAgent', function () { - Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64)', configurable: true }); - expect(getDeviceModel()).to.equal('Windows PC'); - }); - - it('should return "Unknown Device" for an unrecognized userAgent', function () { - Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (Unknown OS)', configurable: true }); - expect(getDeviceModel()).to.equal(''); - }); - }); - - describe('buildEndpointUrl', () => { - it('should construct the URL with uid, pubId, and pubEpid', function () { - const bid = { - params: { - uid: '12345', - pubId: '67890', - pubEpid: 'abcdef' - }, - isDebug: false - }; - const expectedUrl = `${BIDDER_ENDPOINT}?uid=12345&pub_id=67890&pub_epid=abcdef`; - expect(buildEndpointUrl(BIDDER_ENDPOINT, bid)).to.equal(expectedUrl); - }); - }); - - describe('buildEndpointUrl', () => { - it('should construct the test URL with uid, pubId, and pubEpid', function () { - const bid = { - params: { - uid: '12345', - pubId: '67890', - pubEpid: 'abcdef' - }, - isDebug: true - }; - const expectedUrl = `${BIDDER_ENDPOINT}?uid=12345&pub_id=67890&pub_epid=abcdef&test=1`; - expect(buildEndpointUrl(BIDDER_ENDPOINT, bid)).to.equal(expectedUrl); - }); - }); - - describe('parseNativeResponse', () => { - it('should parse and return the empty json object from a invalid JSON string', function () { - const adm = 'Nexverse test ad'; - const result = parseNativeResponse(adm); - expect(result).to.deep.equal({}); - }); - it('should parse and return the native object from a valid JSON string', function () { - const adm = '{"native":{"ver":"1.2","assets":[{"id":1,"required":1,"title":{"text":"Discover Amazing Products Today!"}},{"id":2,"required":1,"img":{"type":3,"url":"https://cdn.prod.website-files.com/64aabfa2adf7363205ea0135/67c168c650acb91b6ce4dfdf_%EC%8D%B8%EB%84%A4%EC%9D%BC_EN.webp","w":600,"h":315}},{"id":3,"data":{"label":"CTA","value":"Click Here To Visit Site","type":12}}],"link":{"url":"https://dailyhunt.in/news/india/english/for+you?launch=true&mode=pwa"},"imptrackers":["https://example.com/impression"]}}'; // JSON string - const result = parseNativeResponse(adm); - expect(result).to.deep.equal({ - clickTrackers: [], - clickUrl: - "https://dailyhunt.in/news/india/english/for+you?launch=true&mode=pwa", - cta: "Click Here To Visit Site", - image: { - height: 315, - url: "https://cdn.prod.website-files.com/64aabfa2adf7363205ea0135/67c168c650acb91b6ce4dfdf_%EC%8D%B8%EB%84%A4%EC%9D%BC_EN.webp", - width: 600, - }, - impressionTrackers: ["https://example.com/impression"], - javascriptTrackers: [], - title: "Discover Amazing Products Today!", - }); - }); - }); - - describe('getOsVersion', () => { - it('should detect Android OS', function () { - Object.defineProperty(navigator, 'userAgent', { value: 'Mozilla/5.0 (Linux; Android 10; Pixel 3 Build/QQ2A.200305.003) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.106 Mobile Safari/537.36', configurable: true }); - expect(getOsVersion()).to.equal('Android'); - }); - it('should detect iOS', function () { - Object.defineProperty(navigator, 'userAgent', { - value: 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Mobile/15E148 Safari/604.1', - configurable: true, - }); - expect(getOsVersion()).to.equal('iOS'); - }); - it('should detect Mac OS X', function () { - Object.defineProperty(navigator, 'userAgent', { - value: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', - configurable: true, - }); - expect(getOsVersion()).to.equal('Mac OS X'); - }); - it('should detect Windows 10', function () { - Object.defineProperty(navigator, 'userAgent', { - value: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', - configurable: true, - }); - expect(getOsVersion()).to.equal('Windows 10'); - }); - it('should detect Linux', function () { - Object.defineProperty(navigator, 'userAgent', { - value: 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', - configurable: true, - }); - expect(getOsVersion()).to.equal('Linux'); - }); - it('should detect Windows 7', function () { - Object.defineProperty(navigator, 'userAgent', { - value: 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', - configurable: true, - }); - expect(getOsVersion()).to.equal('Windows 7'); - }); - it('should detect Search Bot', function () { - Object.defineProperty(navigator, 'userAgent', { - value: 'Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)', - configurable: true, - }); - expect(getOsVersion()).to.equal('Search Bot'); - }); - it('should return unknown for an unrecognized user agent', function () { - Object.defineProperty(navigator, 'userAgent', { - value: 'Mozilla/5.0 (Unknown OS) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', - configurable: true, - }); - expect(getOsVersion()).to.equal('unknown'); - }); - }); -}); diff --git a/test/spec/modules/nexx360BidAdapter_spec.js b/test/spec/modules/nexx360BidAdapter_spec.js deleted file mode 100644 index 7756e96bd..000000000 --- a/test/spec/modules/nexx360BidAdapter_spec.js +++ /dev/null @@ -1,724 +0,0 @@ -import { expect } from 'chai'; -import { - spec, STORAGE, getNexx360LocalStorage, -} from 'modules/nexx360BidAdapter.js'; -import sinon from 'sinon'; -import { getAmxId } from '../../../libraries/nexx360Utils/index.js'; -const sandbox = sinon.createSandbox(); - -describe('Nexx360 bid adapter tests', () => { - const DEFAULT_OPTIONS = { - gdprConsent: { - gdprApplies: true, - consentString: 'BOzZdA0OzZdA0AGABBENDJ-AAAAvh7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__79__3z3_9pxP78k89r7337Mw_v-_v-b7JCPN_Y3v-8Kg', - vendorData: {}, - }, - refererInfo: { - referer: 'https://www.prebid.org', - canonicalUrl: 'https://www.prebid.org/the/link/to/the/page', - }, - uspConsent: '111222333', - userId: { id5id: { uid: '1111' } }, - schain: { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'exchange1.com', - sid: '1234', - hp: 1, - rid: 'bid-request-1', - name: 'publisher', - domain: 'publisher.com', - }], - }, - }; - - describe('isBidRequestValid()', () => { - let bannerBid; - beforeEach(() => { - bannerBid = { - bidder: 'nexx360', - mediaTypes: { banner: { sizes: [[300, 250], [300, 600]] } }, - adUnitCode: 'div-1', - transactionId: '70bdc37e-9475-4b27-8c74-4634bdc2ee66', - sizes: [[300, 250], [300, 600]], - bidId: '4906582fc87d0c', - bidderRequestId: '332fda16002dbe', - auctionId: '98932591-c822-42e3-850e-4b3cf748d063', - } - }); - - it('We verify isBidRequestValid with unvalid adUnitName', () => { - bannerBid.params = { adUnitName: 1 }; - expect(spec.isBidRequestValid(bannerBid)).to.be.equal(false); - }); - - it('We verify isBidRequestValid with empty adUnitName', () => { - bannerBid.params = { adUnitName: '' }; - expect(spec.isBidRequestValid(bannerBid)).to.be.equal(false); - }); - - it('We verify isBidRequestValid with unvalid adUnitPath', () => { - bannerBid.params = { adUnitPath: 1 }; - expect(spec.isBidRequestValid(bannerBid)).to.be.equal(false); - }); - - it('We verify isBidRequestValid with unvalid divId', () => { - bannerBid.params = { divId: 1 }; - expect(spec.isBidRequestValid(bannerBid)).to.be.equal(false); - }); - - it('We verify isBidRequestValid unvalid allBids', () => { - bannerBid.params = { allBids: 1 }; - expect(spec.isBidRequestValid(bannerBid)).to.be.equal(false); - }); - - it('We verify isBidRequestValid with uncorrect tagid', () => { - bannerBid.params = { 'tagid': 'luvxjvgn' }; - expect(spec.isBidRequestValid(bannerBid)).to.be.equal(false); - }); - - it('We verify isBidRequestValid with correct tagId', () => { - bannerBid.params = { 'tagId': 'luvxjvgn' }; - expect(spec.isBidRequestValid(bannerBid)).to.be.equal(true); - }); - - it('We verify isBidRequestValid with correct placement', () => { - bannerBid.params = { 'placement': 'testad' }; - expect(spec.isBidRequestValid(bannerBid)).to.be.equal(true); - }); - }); - - describe('getNexx360LocalStorage disabled', () => { - before(() => { - sandbox.stub(STORAGE, 'localStorageIsEnabled').callsFake(() => false); - }); - it('We test if we get the nexx360Id', () => { - const output = getNexx360LocalStorage(); - expect(output).to.be.eql(false); - }); - after(() => { - sandbox.restore() - }); - }) - - describe('getNexx360LocalStorage enabled but nothing', () => { - before(() => { - sandbox.stub(STORAGE, 'localStorageIsEnabled').callsFake(() => true); - sandbox.stub(STORAGE, 'setDataInLocalStorage'); - sandbox.stub(STORAGE, 'getDataFromLocalStorage').callsFake((key) => null); - }); - it('We test if we get the nexx360Id', () => { - const output = getNexx360LocalStorage(); - expect(typeof output.nexx360Id).to.be.eql('string'); - }); - after(() => { - sandbox.restore() - }); - }) - - describe('getNexx360LocalStorage enabled but wrong payload', () => { - before(() => { - sandbox.stub(STORAGE, 'localStorageIsEnabled').callsFake(() => true); - sandbox.stub(STORAGE, 'setDataInLocalStorage'); - sandbox.stub(STORAGE, 'getDataFromLocalStorage').callsFake((key) => '{"nexx360Id":"5ad89a6e-7801-48e7-97bb-fe6f251f6cb4",}'); - }); - it('We test if we get the nexx360Id', () => { - const output = getNexx360LocalStorage(); - expect(output).to.be.eql(false); - }); - after(() => { - sandbox.restore() - }); - }); - - describe('getNexx360LocalStorage enabled', () => { - before(() => { - sandbox.stub(STORAGE, 'localStorageIsEnabled').callsFake(() => true); - sandbox.stub(STORAGE, 'setDataInLocalStorage'); - sandbox.stub(STORAGE, 'getDataFromLocalStorage').callsFake((key) => '{"nexx360Id":"5ad89a6e-7801-48e7-97bb-fe6f251f6cb4"}'); - }); - it('We test if we get the nexx360Id', () => { - const output = getNexx360LocalStorage(); - expect(output.nexx360Id).to.be.eql('5ad89a6e-7801-48e7-97bb-fe6f251f6cb4'); - }); - after(() => { - sandbox.restore() - }); - }); - - describe('getAmxId() with localStorage enabled and data not set', () => { - before(() => { - sandbox.stub(STORAGE, 'localStorageIsEnabled').callsFake(() => true); - sandbox.stub(STORAGE, 'setDataInLocalStorage'); - sandbox.stub(STORAGE, 'getDataFromLocalStorage').callsFake((key) => null); - }); - it('We test if we get the amxId', () => { - const output = getAmxId(STORAGE, 'nexx360'); - expect(output).to.be.eql(false); - }); - after(() => { - sandbox.restore() - }); - }); - - describe('getAmxId() with localStorage enabled and data set', () => { - before(() => { - sandbox.stub(STORAGE, 'localStorageIsEnabled').callsFake(() => true); - sandbox.stub(STORAGE, 'setDataInLocalStorage'); - sandbox.stub(STORAGE, 'getDataFromLocalStorage').callsFake((key) => 'abcdef'); - }); - it('We test if we get the amxId', () => { - const output = getAmxId(STORAGE, 'nexx360'); - expect(output).to.be.eql('abcdef'); - }); - after(() => { - sandbox.restore() - }); - }); - - describe('buildRequests()', () => { - before(() => { - const documentStub = sandbox.stub(document, 'getElementById'); - documentStub.withArgs('div-1').returns({ - offsetWidth: 200, - offsetHeight: 250, - style: { - maxWidth: '400px', - maxHeight: '350px', - }, - getBoundingClientRect() { return { width: 200, height: 250 }; } - }); - sandbox.stub(STORAGE, 'localStorageIsEnabled').callsFake(() => true); - sandbox.stub(STORAGE, 'setDataInLocalStorage'); - sandbox.stub(STORAGE, 'getDataFromLocalStorage').callsFake((key) => 'abcdef'); - }); - describe('We test with a multiple display bids', () => { - const sampleBids = [ - { - bidder: 'nexx360', - params: { - tagId: 'luvxjvgn', - divId: 'div-1', - adUnitName: 'header-ad', - adUnitPath: '/12345/nexx360/Homepage/HP/Header-Ad', - }, - ortb2Imp: { - ext: { - gpid: '/12345/nexx360/Homepage/HP/Header-Ad', - } - }, - adUnitCode: 'header-ad-1234', - transactionId: '469a570d-f187-488d-b1cb-48c1a2009be9', - sizes: [[300, 250], [300, 600]], - bidId: '44a2706ac3574', - bidderRequestId: '359bf8a3c06b2e', - auctionId: '2e684815-b44e-4e04-b812-56da54adbe74', - }, - { - bidder: 'nexx360', - params: { - placement: 'testPlacement', - allBids: true, - }, - mediaTypes: { - banner: { - sizes: [[728, 90], [970, 250]] - } - }, - - adUnitCode: 'div-2-abcd', - transactionId: '6196885d-4e76-40dc-a09c-906ed232626b', - sizes: [[728, 90], [970, 250]], - bidId: '5ba94555219a03', - bidderRequestId: '359bf8a3c06b2e', - auctionId: '2e684815-b44e-4e04-b812-56da54adbe74', - } - ]; - const bidderRequest = { - bidderCode: 'nexx360', - auctionId: '2e684815-b44e-4e04-b812-56da54adbe74', - bidderRequestId: '359bf8a3c06b2e', - refererInfo: { - reachedTop: true, - isAmp: false, - numIframes: 0, - stack: [ - 'https://test.nexx360.io/adapter/index.html' - ], - topmostLocation: 'https://test.nexx360.io/adapter/index.html', - location: 'https://test.nexx360.io/adapter/index.html', - canonicalUrl: null, - page: 'https://test.nexx360.io/adapter/index.html', - domain: 'test.nexx360.io', - ref: null, - legacy: { - reachedTop: true, - isAmp: false, - numIframes: 0, - stack: [ - 'https://test.nexx360.io/adapter/index.html' - ], - referer: 'https://test.nexx360.io/adapter/index.html', - canonicalUrl: null - }, - }, - gdprConsent: { - gdprApplies: true, - consentString: 'CPhdLUAPhdLUAAKAsAENCmCsAP_AAE7AAAqIJFNd_H__bW9r-f5_aft0eY1P9_r37uQzDhfNk-8F3L_W_LwX52E7NF36tq4KmR4ku1LBIUNlHMHUDUmwaokVryHsak2cpzNKJ7BEknMZOydYGF9vmxtj-QKY7_5_d3bx2D-t_9v239z3z81Xn3d53-_03LCdV5_9Dfn9fR_bc9KPt_58v8v8_____3_e__3_7997BIiAaADgAJYBnwEeAJXAXmAwQBj4DtgHcgPBAeKBIgAA.YAAAAAAAAAAA', - } - }; - it('We perform a test with 2 display adunits', () => { - const displayBids = structuredClone(sampleBids); - displayBids[0].mediaTypes = { - banner: { - sizes: [[300, 250], [300, 600]] - } - }; - const request = spec.buildRequests(displayBids, bidderRequest); - const requestContent = request.data; - expect(request).to.have.property('method').and.to.equal('POST'); - const expectedRequest = { - imp: [ - { - id: '44a2706ac3574', - banner: { - topframe: 0, - format: [ - { w: 300, h: 250 }, - { w: 300, h: 600 }, - ], - }, - secure: 1, - tagid: 'header-ad-1234', - ext: { - adUnitCode: 'header-ad-1234', - gpid: '/12345/nexx360/Homepage/HP/Header-Ad', - divId: 'div-1', - dimensions: { - slotW: 200, - slotH: 250, - cssMaxW: '400px', - cssMaxH: '350px', - }, - nexx360: { - tagId: 'luvxjvgn', - }, - adUnitName: 'header-ad', - adUnitPath: '/12345/nexx360/Homepage/HP/Header-Ad', - }, - }, - { - id: '5ba94555219a03', - banner: { - topframe: 0, - format: [ - { w: 728, h: 90 }, - { w: 970, h: 250 }, - ], - }, - secure: 1, - tagid: 'div-2-abcd', - ext: { - adUnitCode: 'div-2-abcd', - divId: 'div-2-abcd', - nexx360: { - placement: 'testPlacement', - allBids: true, - }, - }, - }, - ], - id: requestContent.id, - test: 0, - ext: { - version: requestContent.ext.version, - source: 'prebid.js', - pageViewId: requestContent.ext.pageViewId, - bidderVersion: '6.3', - localStorage: { amxId: 'abcdef'} - }, - cur: [ - 'USD', - ], - user: { - ext: { - eids: [ - { - source: 'amxdt.net', - uids: [ - { - id: 'abcdef', - atype: 1, - } - ] - } - ] - } - }, - }; - expect(requestContent).to.be.eql(expectedRequest); - }); - - if (FEATURES.VIDEO) { - it('We perform a test with a multiformat adunit', () => { - const multiformatBids = structuredClone(sampleBids); - multiformatBids[0].mediaTypes = { - banner: { - sizes: [[300, 250], [300, 600]] - }, - video: { - context: 'outstream', - playerSize: [640, 480], - mimes: ['video/mp4'], - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - playbackmethod: [2], - skip: 1, - playback_method: ['auto_play_sound_off'] - } - }; - const request = spec.buildRequests(multiformatBids, bidderRequest); - const video = request.data.imp[0].video; - const expectedVideo = { - mimes: ['video/mp4'], - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - playbackmethod: [2], - skip: 1, - w: 640, - h: 480, - ext: { - playerSize: [640, 480], - context: 'outstream', - }, - }; - expect(video).to.eql(expectedVideo); - }); - - it('We perform a test with a instream adunit', () => { - const videoBids = structuredClone(sampleBids); - videoBids[0].mediaTypes = { - video: { - context: 'instream', - playerSize: [640, 480], - mimes: ['video/mp4'], - protocols: [1, 2, 3, 4, 5, 6], - playbackmethod: [2], - skip: 1 - } - }; - const request = spec.buildRequests(videoBids, bidderRequest); - const requestContent = request.data; - expect(request).to.have.property('method').and.to.equal('POST'); - expect(requestContent.imp[0].video.ext.context).to.be.eql('instream'); - expect(requestContent.imp[0].video.playbackmethod[0]).to.be.eql(2); - }); - } - }); - after(() => { - sandbox.restore() - }); - }); - - describe('We test intepretResponse', () => { - it('empty response', () => { - const response = { - body: '' - }; - const output = spec.interpretResponse(response); - expect(output.length).to.be.eql(0); - }); - it('banner responses with adm', () => { - const response = { - body: { - id: 'a8d3a675-a4ba-4d26-807f-c8f2fad821e0', - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: '4427551302944024629', - impid: '226175918ebeda', - price: 1.5, - adomain: [ - 'http://prebid.org', - ], - crid: '98493581', - ssp: 'appnexus', - h: 600, - w: 300, - adm: '
TestAd
', - cat: [ - 'IAB3-1', - ], - ext: { - adUnitCode: 'div-1', - mediaType: 'banner', - adUrl: 'https://fast.nexx360.io/cache?uuid=fdddcebc-1edf-489d-880d-1418d8bdc493', - ssp: 'appnexus', - }, - }, - ], - seat: 'appnexus', - }, - ], - ext: { - id: 'de3de7c7-e1cf-4712-80a9-94eb26bfc718', - cookies: [], - }, - }, - }; - const output = spec.interpretResponse(response); - const expectedOutput = [{ - requestId: '226175918ebeda', - cpm: 1.5, - width: 300, - height: 600, - creativeId: '98493581', - currency: 'USD', - netRevenue: true, - ttl: 120, - mediaType: 'banner', - meta: { - advertiserDomains: [ - 'http://prebid.org', - ], - demandSource: 'appnexus', - }, - ad: '
TestAd
', - }]; - expect(output).to.eql(expectedOutput); - }); - - it('instream responses', () => { - const response = { - body: { - id: '2be64380-ba0c-405a-ab53-51f51c7bde51', - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: '8275140264321181514', - impid: '263cba3b8bfb72', - price: 5, - adomain: [ - 'appnexus.com', - ], - crid: '97517771', - h: 1, - w: 1, - adm: 'vast', - ext: { - mediaType: 'instream', - ssp: 'appnexus', - adUnitCode: 'video1', - }, - }, - ], - seat: 'appnexus', - }, - ], - ext: { - cookies: [], - }, - }, - }; - - const output = spec.interpretResponse(response); - const expectedOutput = [{ - requestId: '263cba3b8bfb72', - cpm: 5, - width: 1, - height: 1, - creativeId: '97517771', - currency: 'USD', - netRevenue: true, - ttl: 120, - mediaType: 'video', - meta: { advertiserDomains: ['appnexus.com'], demandSource: 'appnexus' }, - vastXml: 'vast', - }]; - expect(output).to.eql(expectedOutput); - }); - - it('outstream responses', () => { - const response = { - body: { - id: '40c23932-135e-4602-9701-ca36f8d80c07', - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: '1186971142548769361', - impid: '4ce809b61a3928', - price: 5, - adomain: [ - 'appnexus.com', - ], - crid: '97517771', - h: 1, - w: 1, - adm: 'vast', - ext: { - mediaType: 'outstream', - ssp: 'appnexus', - adUnitCode: 'div-1', - }, - }, - ], - seat: 'appnexus', - }, - ], - ext: { - cookies: [], - }, - }, - }; - - const output = spec.interpretResponse(response); - const expectedOutut = [{ - requestId: '4ce809b61a3928', - cpm: 5, - width: 1, - height: 1, - creativeId: '97517771', - currency: 'USD', - netRevenue: true, - ttl: 120, - mediaType: 'video', - meta: { advertiserDomains: ['appnexus.com'], demandSource: 'appnexus' }, - vastXml: 'vast', - renderer: output[0].renderer, - }]; - expect(output).to.eql(expectedOutut); - }); - - it('native responses', () => { - const response = { - body: { - id: '3c0290c1-6e75-4ef7-9e37-17f5ebf3bfa3', - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: '6624930625245272225', - impid: '23e11d845514bb', - price: 10, - adomain: [ - 'prebid.org', - ], - crid: '97494204', - h: 1, - w: 1, - cat: [ - 'IAB3-1', - ], - ext: { - mediaType: 'native', - ssp: 'appnexus', - adUnitCode: '/19968336/prebid_native_example_1', - }, - adm: '{"ver":"1.2","assets":[{"id":1,"img":{"url":"https:\\/\\/vcdn.adnxs.com\\/p\\/creative-image\\/f8\\/7f\\/0f\\/13\\/f87f0f13-230c-4f05-8087-db9216e393de.jpg","w":989,"h":742,"ext":{"appnexus":{"prevent_crop":0}}}},{"id":0,"title":{"text":"This is a Prebid Native Creative"}},{"id":2,"data":{"value":"Prebid.org"}}],"link":{"url":"https:\\/\\/ams3-ib.adnxs.com\\/click?AAAAAAAAJEAAAAAAAAAkQAAAAAAAACRAAAAAAAAAJEAAAAAAAAAkQKZS4ZZl5vVbR6p-A-MwnyTZ7QVkAAAAAOLoyQBtJAAAbSQAAAIAAAC8pM8FnPgWAAAAAABVU0QAVVNEAAEAAQBNXQAAAAABAgMCAAAAALoAURe69gAAAAA.\\/bcr=AAAAAAAA8D8=\\/pp=${AUCTION_PRICE}\\/cnd=%21JBC72Aj8-LwKELzJvi4YnPFbIAQoADEAAAAAAAAkQDoJQU1TMzo2MTM1QNAwSQAAAAAAAPA_UQAAAAAAAAAAWQAAAAAAAAAAYQAAAAAAAAAAaQAAAAAAAAAAcQAAAAAAAAAAeACJAQAAAAAAAAAA\\/cca=OTMyNSNBTVMzOjYxMzU=\\/bn=97062\\/clickenc=http%3A%2F%2Fprebid.org%2Fdev-docs%2Fshow-native-ads.html"},"eventtrackers":[{"event":1,"method":1,"url":"https:\\/\\/ams3-ib.adnxs.com\\/it?an_audit=0&referrer=https%3A%2F%2Ftest.nexx360.io%2Fadapter%2Fnative%2Ftest.html&e=wqT_3QKJCqAJBQAAAwDWAAUBCNnbl6AGEKalhbfZzPn6WxjH1PqbsJzMzyQqNgkAAAECCCRAEQEHEAAAJEAZEQkAIREJACkRCQAxEQmoMOLRpwY47UhA7UhIAlC8yb4uWJzxW2AAaM26dXim9gWAAQGKAQNVU0SSAQEG9F4BmAEBoAEBqAEBsAEAuAECwAEDyAEC0AEJ2AEA4AEA8AEAigIpdWYoJ2EnLCAyNTI5ODg1LCAwKTt1ZigncicsIDk3NDk0MjA0LCAwKTuSAvEDIS0xRDNJQWo4LUx3S0VMekp2aTRZQUNDYzhWc3dBRGdBUUFSSTdVaFE0dEduQmxnQVlQX19fXzhQYUFCd0FYZ0JnQUVCaUFFQmtBRUJtQUVCb0FFQnFBRURzQUVBdVFIenJXcWtBQUFrUU1FQjg2MXFwQUFBSkVESkFYSUtWbWViSmZJXzJRRUFBQUFBQUFEd1AtQUJBUFVCQUFBQUFKZ0NBS0FDQUxVQ0FBQUFBTDBDQUFBQUFNQUNBY2dDQWRBQ0FkZ0NBZUFDQU9nQ0FQZ0NBSUFEQVpnREFib0RDVUZOVXpNNk5qRXpOZUFEMERDSUJBQ1FCQUNZQkFIQkJBQUFBQUFBQUFBQXlRUUFBCQscQUFOZ0VBUEURlSxBQUFDSUJmY3ZxUVUBDQRBQQGoCDdFRgEKCQEMREJCUQkKAQEAeRUoAUwyKAAAWi4oALg0QVhBaEQzd0JhTEQzd0w0QmQyMG1nR0NCZ05WVTBTSUJnQ1FCZ0dZQmdDaEJnQQFONEFBQ1JBcUFZQnNnWWtDHXQARR0MAEcdDABJHQw8dUFZS5oClQEhSkJDNzJBajL1ASRuUEZiSUFRb0FEFfhUa1FEb0pRVTFUTXpvMk1UTTFRTkF3UxFRDFBBX1URDAxBQUFXHQwAWR0MAGEdDABjHQwQZUFDSkEdEMjYAvfpA-ACrZhI6gIwaHR0cHM6Ly90ZXN0Lm5leHgzNjAuaW8vYWRhcHRlci9uYXRpdmUJH_CaaHRtbIADAIgDAZADAJgDFKADAaoDAMAD4KgByAMA2AMA4AMA6AMA-AMDgAQAkgQJL29wZW5ydGIymAQAqAQAsgQMCAAQABgAIAAwADgAuAQAwASA2rgiyAQA0gQOOTMyNSNBTVMzOjYxMzXaBAIIAeAEAPAEvMm-LvoEEgkAAABAPG1IQBEAAACgV8oCQIgFAZgFAKAF______8BBbABqgUkM2MwMjkwYzEtNmU3NS00ZWY3LTllMzctMTdmNWViZjNiZmEzwAUAyQWJFxTwP9IFCQkJDHgAANgFAeAFAfAFmfQh-gUECAAQAJAGAZgGALgGAMEGCSUo8D_QBvUv2gYWChAJERkBAdpg4AYM8gYCCACABwGIBwCgB0HIB6b2BdIHDRVkASYI2gcGAV1oGADgBwDqBwIIAPAHAIoIAhAAlQgAAIA_mAgB&s=ccf63f2e483a37091d2475d895e7cf7c911d1a78&pp=${AUCTION_PRICE}"}]}', - }, - ], - seat: 'appnexus', - }, - ], - ext: { - cookies: [], - }, - }, - }; - - const output = spec.interpretResponse(response); - const expectOutput = [{ - requestId: '23e11d845514bb', - cpm: 10, - width: 1, - height: 1, - creativeId: '97494204', - currency: 'USD', - netRevenue: true, - ttl: 120, - mediaType: 'native', - meta: { - advertiserDomains: [ - 'prebid.org', - ], - demandSource: 'appnexus', - }, - native: { - ortb: { - ver: '1.2', - assets: [ - { - id: 1, - img: { - url: 'https://vcdn.adnxs.com/p/creative-image/f8/7f/0f/13/f87f0f13-230c-4f05-8087-db9216e393de.jpg', - w: 989, - h: 742, - ext: { - appnexus: { - prevent_crop: 0, - }, - }, - }, - }, - { - id: 0, - title: { - text: 'This is a Prebid Native Creative', - }, - }, - { - id: 2, - data: { - value: 'Prebid.org', - }, - }, - ], - link: { - url: 'https://ams3-ib.adnxs.com/click?AAAAAAAAJEAAAAAAAAAkQAAAAAAAACRAAAAAAAAAJEAAAAAAAAAkQKZS4ZZl5vVbR6p-A-MwnyTZ7QVkAAAAAOLoyQBtJAAAbSQAAAIAAAC8pM8FnPgWAAAAAABVU0QAVVNEAAEAAQBNXQAAAAABAgMCAAAAALoAURe69gAAAAA./bcr=AAAAAAAA8D8=/pp=${AUCTION_PRICE}/cnd=%21JBC72Aj8-LwKELzJvi4YnPFbIAQoADEAAAAAAAAkQDoJQU1TMzo2MTM1QNAwSQAAAAAAAPA_UQAAAAAAAAAAWQAAAAAAAAAAYQAAAAAAAAAAaQAAAAAAAAAAcQAAAAAAAAAAeACJAQAAAAAAAAAA/cca=OTMyNSNBTVMzOjYxMzU=/bn=97062/clickenc=http%3A%2F%2Fprebid.org%2Fdev-docs%2Fshow-native-ads.html', - }, - eventtrackers: [ - { - event: 1, - method: 1, - url: 'https://ams3-ib.adnxs.com/it?an_audit=0&referrer=https%3A%2F%2Ftest.nexx360.io%2Fadapter%2Fnative%2Ftest.html&e=wqT_3QKJCqAJBQAAAwDWAAUBCNnbl6AGEKalhbfZzPn6WxjH1PqbsJzMzyQqNgkAAAECCCRAEQEHEAAAJEAZEQkAIREJACkRCQAxEQmoMOLRpwY47UhA7UhIAlC8yb4uWJzxW2AAaM26dXim9gWAAQGKAQNVU0SSAQEG9F4BmAEBoAEBqAEBsAEAuAECwAEDyAEC0AEJ2AEA4AEA8AEAigIpdWYoJ2EnLCAyNTI5ODg1LCAwKTt1ZigncicsIDk3NDk0MjA0LCAwKTuSAvEDIS0xRDNJQWo4LUx3S0VMekp2aTRZQUNDYzhWc3dBRGdBUUFSSTdVaFE0dEduQmxnQVlQX19fXzhQYUFCd0FYZ0JnQUVCaUFFQmtBRUJtQUVCb0FFQnFBRURzQUVBdVFIenJXcWtBQUFrUU1FQjg2MXFwQUFBSkVESkFYSUtWbWViSmZJXzJRRUFBQUFBQUFEd1AtQUJBUFVCQUFBQUFKZ0NBS0FDQUxVQ0FBQUFBTDBDQUFBQUFNQUNBY2dDQWRBQ0FkZ0NBZUFDQU9nQ0FQZ0NBSUFEQVpnREFib0RDVUZOVXpNNk5qRXpOZUFEMERDSUJBQ1FCQUNZQkFIQkJBQUFBQUFBQUFBQXlRUUFBCQscQUFOZ0VBUEURlSxBQUFDSUJmY3ZxUVUBDQRBQQGoCDdFRgEKCQEMREJCUQkKAQEAeRUoAUwyKAAAWi4oALg0QVhBaEQzd0JhTEQzd0w0QmQyMG1nR0NCZ05WVTBTSUJnQ1FCZ0dZQmdDaEJnQQFONEFBQ1JBcUFZQnNnWWtDHXQARR0MAEcdDABJHQw8dUFZS5oClQEhSkJDNzJBajL1ASRuUEZiSUFRb0FEFfhUa1FEb0pRVTFUTXpvMk1UTTFRTkF3UxFRDFBBX1URDAxBQUFXHQwAWR0MAGEdDABjHQwQZUFDSkEdEMjYAvfpA-ACrZhI6gIwaHR0cHM6Ly90ZXN0Lm5leHgzNjAuaW8vYWRhcHRlci9uYXRpdmUJH_CaaHRtbIADAIgDAZADAJgDFKADAaoDAMAD4KgByAMA2AMA4AMA6AMA-AMDgAQAkgQJL29wZW5ydGIymAQAqAQAsgQMCAAQABgAIAAwADgAuAQAwASA2rgiyAQA0gQOOTMyNSNBTVMzOjYxMzXaBAIIAeAEAPAEvMm-LvoEEgkAAABAPG1IQBEAAACgV8oCQIgFAZgFAKAF______8BBbABqgUkM2MwMjkwYzEtNmU3NS00ZWY3LTllMzctMTdmNWViZjNiZmEzwAUAyQWJFxTwP9IFCQkJDHgAANgFAeAFAfAFmfQh-gUECAAQAJAGAZgGALgGAMEGCSUo8D_QBvUv2gYWChAJERkBAdpg4AYM8gYCCACABwGIBwCgB0HIB6b2BdIHDRVkASYI2gcGAV1oGADgBwDqBwIIAPAHAIoIAhAAlQgAAIA_mAgB&s=ccf63f2e483a37091d2475d895e7cf7c911d1a78&pp=${AUCTION_PRICE}', - }, - ], - }, - }, - }]; - expect(output).to.eql(expectOutput); - }); - }); - - describe('getUserSyncs()', () => { - const response = { body: { cookies: [] } }; - it('Verifies user sync without cookie in bid response', () => { - const syncs = spec.getUserSyncs({}, [response], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.eql([]); - }); - it('Verifies user sync with cookies in bid response', () => { - response.body.ext = { - cookies: [{'type': 'image', 'url': 'http://www.cookie.sync.org/'}] - }; - const syncs = spec.getUserSyncs({}, [response], DEFAULT_OPTIONS.gdprConsent); - const expectedSyncs = [{ type: 'image', url: 'http://www.cookie.sync.org/' }]; - expect(syncs).to.eql(expectedSyncs); - }); - it('Verifies user sync with no bid response', () => { - var syncs = spec.getUserSyncs({}, null, DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.eql([]); - }); - it('Verifies user sync with no bid body response', () => { - let syncs = spec.getUserSyncs({}, [], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.eql([]); - syncs = spec.getUserSyncs({}, [{}], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.eql([]); - }); - }); -}); diff --git a/test/spec/modules/nobidAnalyticsAdapter_spec.js b/test/spec/modules/nobidAnalyticsAdapter_spec.js deleted file mode 100644 index e20348f51..000000000 --- a/test/spec/modules/nobidAnalyticsAdapter_spec.js +++ /dev/null @@ -1,617 +0,0 @@ -import nobidAnalytics from 'modules/nobidAnalyticsAdapter.js'; -import {expect} from 'chai'; -import {server} from 'test/mocks/xhr.js'; -import { EVENTS } from 'src/constants.js'; -const events = require('src/events'); -const adapterManager = require('src/adapterManager').default; - -const TOP_LOCATION = 'https://www.somesite.com'; -const SITE_ID = 1234; - -describe('NoBid Prebid Analytic', function () { - var clock; - describe('enableAnalytics', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - clock = sinon.useFakeTimers(Date.now()); - }); - - afterEach(function () { - events.getEvents.restore(); - clock.restore(); - }); - - after(function () { - nobidAnalytics.disableAnalytics(); - }); - - it('auctionInit test', function (done) { - const initOptions = { - options: { - /* siteId: SITE_ID */ - } - }; - - nobidAnalytics.enableAnalytics(initOptions); - expect(nobidAnalytics.initOptions).to.equal(undefined); - - initOptions.options.siteId = SITE_ID; - nobidAnalytics.enableAnalytics(initOptions); - expect(nobidAnalytics.initOptions.siteId).to.equal(SITE_ID); - - // Step 1: Initialize adapter - adapterManager.enableAnalytics({ - provider: 'nobid', - options: initOptions - }); - - // Step 2: Send init auction event - events.emit(EVENTS.AUCTION_INIT, {config: initOptions, - auctionId: '13', - timestamp: Date.now(), - bidderRequests: [{refererInfo: {topmostLocation: TOP_LOCATION}}]}); - expect(nobidAnalytics.initOptions).to.have.property('siteId', SITE_ID); - expect(nobidAnalytics).to.have.property('topLocation', TOP_LOCATION); - - const data = { ts: Date.now() }; - clock.tick(5000); - const expired = nobidAnalytics.isExpired(data); - expect(expired).to.equal(false); - - done(); - }); - - it('BID_REQUESTED/BID_RESPONSE/BID_TIMEOUT/AD_RENDER_SUCCEEDED test', function (done) { - const initOptions = { - options: { - siteId: SITE_ID - } - }; - - nobidAnalytics.enableAnalytics(initOptions); - - // Step 1: Initialize adapter - adapterManager.enableAnalytics({ - provider: 'nobid', - options: initOptions - }); - - // Step 2: Send init auction event - events.emit(EVENTS.AUCTION_INIT, {config: initOptions, - auctionId: '13', - timestamp: Date.now(), - bidderRequests: [{refererInfo: {topmostLocation: TOP_LOCATION}}]}); - events.emit(EVENTS.BID_WON, {}); - clock.tick(5000); - expect(server.requests).to.have.length(1); - - events.emit(EVENTS.BID_REQUESTED, {}); - clock.tick(5000); - expect(server.requests).to.have.length(1); - - events.emit(EVENTS.BID_RESPONSE, {}); - clock.tick(5000); - expect(server.requests).to.have.length(1); - - events.emit(EVENTS.BID_TIMEOUT, {}); - clock.tick(5000); - expect(server.requests).to.have.length(1); - - events.emit(EVENTS.AD_RENDER_SUCCEEDED, {}); - clock.tick(5000); - expect(server.requests).to.have.length(1); - - done(); - }); - - it('bidWon test', function (done) { - const initOptions = { - options: { - siteId: SITE_ID - } - }; - - nobidAnalytics.enableAnalytics(initOptions); - - const TOP_LOCATION = 'https://www.somesite.com'; - - const requestIncoming = { - bidderCode: 'nobid', - width: 728, - height: 9, - statusMessage: 'Bid available', - adId: '106d14b7d06b607', - requestId: '67a7f0e7ea55c4', - transactionId: 'd58cbeae-92c8-4262-ba8d-0e649cbf5470', - auctionId: 'd758cce5-d178-408c-b777-8cac605ef7ca', - mediaType: 'banner', - source: 'client', - cpm: 6.4, - currency: 'EUR', - creativeId: 'TEST', - dealId: '', - netRevenue: true, - ttl: 300, - ad: 'AD HERE', - meta: { - advertiserDomains: ['advertiser_domain.com'] - }, - metrics: { - 'requestBids.usp': 0 - }, - adapterCode: 'nobid', - originalCpm: 6.44, - originalCurrency: 'USD', - responseTimestamp: 1692156287517, - requestTimestamp: 1692156286972, - bidder: 'nobid', - adUnitCode: 'leaderboard', - timeToRespond: 545, - pbCg: '', - size: '728x90', - adserverTargeting: { - hb_bidder: 'nobid', - hb_adid: '106d14b7d06b607', - hb_pb: '6.40', - hb_size: '728x90', - hb_source: 'client', - hb_format: 'banner', - hb_adomain: 'advertiser_domain.com', - 'hb_crid': 'TEST' - }, - status: 'rendered', - params: [ - { - siteId: SITE_ID - } - ] - }; - - const expectedOutgoingRequest = { - version: nobidAnalyticsVersion, - bidderCode: 'nobid', - statusMessage: 'Bid available', - adId: '106d14b7d06b607', - requestId: '67a7f0e7ea55c4', - mediaType: 'banner', - cpm: 6.4, - currency: 'EUR', - originalCpm: 6.44, - originalCurrency: 'USD', - adUnitCode: 'leaderboard', - timeToRespond: 545, - size: '728x90', - topLocation: TOP_LOCATION - }; - - // Step 1: Initialize adapter - adapterManager.enableAnalytics({ - provider: 'nobid', - options: initOptions - }); - - // Step 2: Send init auction event - events.emit(EVENTS.AUCTION_INIT, {config: initOptions, - auctionId: '13', - timestamp: Date.now(), - bidderRequests: [{refererInfo: {topmostLocation: TOP_LOCATION}}]}); - - // Step 3: Send bid won event - events.emit(EVENTS.BID_WON, requestIncoming); - clock.tick(5000); - expect(server.requests).to.have.length(1); - const bidWonRequest = JSON.parse(server.requests[0].requestBody); - expect(bidWonRequest).to.have.property('version', nobidAnalyticsVersion); - expect(bidWonRequest).to.have.property('bidderCode', expectedOutgoingRequest.bidderCode); - expect(bidWonRequest).to.have.property('statusMessage', expectedOutgoingRequest.statusMessage); - expect(bidWonRequest).to.have.property('adId', expectedOutgoingRequest.adId); - expect(bidWonRequest).to.have.property('requestId', expectedOutgoingRequest.requestId); - expect(bidWonRequest).to.have.property('mediaType', expectedOutgoingRequest.mediaType); - expect(bidWonRequest).to.have.property('cpm', expectedOutgoingRequest.cpm); - expect(bidWonRequest).to.have.property('currency', expectedOutgoingRequest.currency); - expect(bidWonRequest).to.have.property('originalCpm', expectedOutgoingRequest.originalCpm); - expect(bidWonRequest).to.have.property('originalCurrency', expectedOutgoingRequest.originalCurrency); - expect(bidWonRequest).to.have.property('adUnitCode', expectedOutgoingRequest.adUnitCode); - expect(bidWonRequest).to.have.property('timeToRespond', expectedOutgoingRequest.timeToRespond); - expect(bidWonRequest).to.have.property('size', expectedOutgoingRequest.size); - expect(bidWonRequest).to.have.property('topLocation', expectedOutgoingRequest.topLocation); - expect(bidWonRequest).to.not.have.property('pbCg'); - - done(); - }); - - it('auctionEnd test', function (done) { - const initOptions = { - options: { - siteId: SITE_ID - } - }; - - nobidAnalytics.enableAnalytics(initOptions); - - const TOP_LOCATION = 'https://www.somesite.com'; - - const requestIncoming = { - auctionId: '4c056b3c-f1a6-46bd-8d82-58c15b22fcfa', - timestamp: 1692224437573, - auctionEnd: 1692224437986, - auctionStatus: 'completed', - adUnits: [ - { - code: 'leaderboard', - sizes: [[728, 90]], - sizeConfig: [ - { minViewPort: [0, 0], sizes: [[300, 250]] }, - { minViewPort: [750, 0], sizes: [[728, 90]] } - ], - adunit: '/111111/adunit', - bids: [{ bidder: 'nobid', params: { siteId: SITE_ID } }] - } - ], - adUnitCodes: ['leaderboard'], - bidderRequests: [ - { - bidderCode: 'nobid', - auctionId: '4c056b3c-f1a6-46bd-8d82-58c15b22fcfa', - bidderRequestId: '5beedb9f99ad98', - bids: [ - { - bidder: 'nobid', - params: { siteId: SITE_ID }, - mediaTypes: { banner: { sizes: [[728, 90]] } }, - adUnitCode: 'leaderboard', - transactionId: 'bcda424d-f4f4-419b-acf9-1808d2dd22b1', - sizes: [[728, 90]], - bidId: '6ef0277f36c8df', - bidderRequestId: '5beedb9f99ad98', - auctionId: '4c056b3c-f1a6-46bd-8d82-58c15b22fcfa', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - ortb2: { - site: { - domain: 'site.me', - publisher: { - domain: 'site.me' - }, - page: TOP_LOCATION - }, - device: { - w: 2605, - h: 895, - dnt: 0, - ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36', - language: 'en', - } - } - } - ], - auctionStart: 1692224437573, - timeout: 3000, - refererInfo: { - topmostLocation: TOP_LOCATION, - location: TOP_LOCATION, - page: TOP_LOCATION, - domain: 'site.me', - ref: null, - } - } - ], - noBids: [ - ], - bidsReceived: [ - { - bidderCode: 'nobid', - width: 728, - height: 90, - statusMessage: 'Bid available', - adId: '95781b6ae5ef2f', - requestId: '6ef0277f36c8df', - transactionId: 'bcda424d-f4f4-419b-acf9-1808d2dd22b1', - auctionId: '4c056b3c-f1a6-46bd-8d82-58c15b22fcfa', - mediaType: 'banner', - source: 'client', - cpm: 5.93, - currency: 'EUR', - creativeId: 'TEST', - dealId: '', - netRevenue: true, - ttl: 300, - ad: '', - meta: { - advertiserDomains: [ - 'advertiser_domain.com' - ] - }, - adapterCode: 'nobid', - originalCpm: 6.44, - originalCurrency: 'USD', - responseTimestamp: 1692224437982, - requestTimestamp: 1692224437576, - bidder: 'nobid', - adUnitCode: 'leaderboard', - timeToRespond: 0, - pbLg: 5.00, - pbCg: '', - size: '728x90', - adserverTargeting: { hb_bidder: 'nobid', hb_pb: '6.40' }, - status: 'targetingSet' - } - ], - bidsRejected: [], - winningBids: [], - timeout: 3000 - }; - - const expectedOutgoingRequest = { - auctionId: '4c056b3c-f1a6-46bd-8d82-58c15b22fcfa', - bidderRequests: [ - { - bidderCode: 'nobid', - bidderRequestId: '7c1940bb285731', - bids: [ - { - params: { siteId: SITE_ID }, - mediaTypes: { banner: { sizes: [[728, 90]] } }, - adUnitCode: 'leaderboard', - sizes: [[728, 90]], - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1 - } - ], - refererInfo: { - topmostLocation: TOP_LOCATION - } - } - ], - bidsReceived: [ - { - bidderCode: 'nobid', - width: 728, - height: 90, - mediaType: 'banner', - cpm: 5.93, - currency: 'EUR', - originalCpm: 6.44, - originalCurrency: 'USD', - adUnitCode: 'leaderboard' - } - ] - }; - - // Step 1: Initialize adapter - adapterManager.enableAnalytics({ - provider: 'nobid', - options: initOptions - }); - - // Step 2: Send init auction event - events.emit(EVENTS.AUCTION_INIT, {config: initOptions, - auctionId: '13', - timestamp: Date.now(), - bidderRequests: [{refererInfo: {topmostLocation: `${TOP_LOCATION}_something`}}]}); - - // Step 3: Send bid won event - events.emit(EVENTS.AUCTION_END, requestIncoming); - clock.tick(5000); - expect(server.requests).to.have.length(1); - const auctionEndRequest = JSON.parse(server.requests[0].requestBody); - expect(auctionEndRequest).to.have.property('version', nobidAnalyticsVersion); - expect(auctionEndRequest).to.have.property('pbver', '$prebid.version$'); - expect(auctionEndRequest).to.have.property('auctionId', expectedOutgoingRequest.auctionId); - expect(auctionEndRequest.bidderRequests).to.have.length(1); - expect(auctionEndRequest.bidderRequests[0].bidderCode).to.equal(expectedOutgoingRequest.bidderRequests[0].bidderCode); - expect(auctionEndRequest.bidderRequests[0].bids).to.have.length(1); - expect(typeof auctionEndRequest.bidderRequests[0].bids[0].bidder).to.equal('undefined'); - expect(auctionEndRequest.bidderRequests[0].bids[0].adUnitCode).to.equal(expectedOutgoingRequest.bidderRequests[0].bids[0].adUnitCode); - expect(typeof auctionEndRequest.bidderRequests[0].bids[0].params).to.equal('undefined'); - expect(typeof auctionEndRequest.bidderRequests[0].bids[0].src).to.equal('undefined'); - expect(auctionEndRequest.bidderRequests[0].refererInfo.topmostLocation).to.equal(expectedOutgoingRequest.bidderRequests[0].refererInfo.topmostLocation); - expect(auctionEndRequest.bidsReceived).to.have.length(1); - expect(auctionEndRequest.bidsReceived[0].bidderCode).to.equal(expectedOutgoingRequest.bidsReceived[0].bidderCode); - expect(auctionEndRequest.bidsReceived[0].width).to.equal(expectedOutgoingRequest.bidsReceived[0].width); - expect(auctionEndRequest.bidsReceived[0].height).to.equal(expectedOutgoingRequest.bidsReceived[0].height); - expect(auctionEndRequest.bidsReceived[0].mediaType).to.equal(expectedOutgoingRequest.bidsReceived[0].mediaType); - expect(auctionEndRequest.bidsReceived[0].cpm).to.equal(expectedOutgoingRequest.bidsReceived[0].cpm); - expect(auctionEndRequest.bidsReceived[0].currency).to.equal(expectedOutgoingRequest.bidsReceived[0].currency); - expect(auctionEndRequest.bidsReceived[0].originalCpm).to.equal(expectedOutgoingRequest.bidsReceived[0].originalCpm); - expect(auctionEndRequest.bidsReceived[0].originalCurrency).to.equal(expectedOutgoingRequest.bidsReceived[0].originalCurrency); - expect(auctionEndRequest.bidsReceived[0].adUnitCode).to.equal(expectedOutgoingRequest.bidsReceived[0].adUnitCode); - expect(typeof auctionEndRequest.bidsReceived[0].source).to.equal('undefined'); - - done(); - }); - - it('Analytics disabled test', function (done) { - let disabled; - nobidAnalytics.processServerResponse(JSON.stringify({disabled: 0})); - disabled = nobidAnalytics.isAnalyticsDisabled(); - expect(disabled).to.equal(false); - events.emit(EVENTS.AUCTION_END, {auctionId: '1234567890'}); - clock.tick(1000); - expect(server.requests).to.have.length(1); - events.emit(EVENTS.AUCTION_END, {auctionId: '12345678901'}); - clock.tick(1000); - expect(server.requests).to.have.length(2); - - nobidAnalytics.processServerResponse('disabled: true'); - events.emit(EVENTS.AUCTION_END, {auctionId: '12345678902'}); - clock.tick(1000); - expect(server.requests).to.have.length(3); - - nobidAnalytics.processServerResponse(JSON.stringify({disabled: 1})); - disabled = nobidAnalytics.isAnalyticsDisabled(); - expect(disabled).to.equal(true); - events.emit(EVENTS.AUCTION_END, {auctionId: '12345678902'}); - clock.tick(5000); - expect(server.requests).to.have.length(3); - - nobidAnalytics.retentionSeconds = 5; - nobidAnalytics.processServerResponse(JSON.stringify({disabled: 1})); - clock.tick(1000); - disabled = nobidAnalytics.isAnalyticsDisabled(); - expect(disabled).to.equal(true); - clock.tick(6000); - disabled = nobidAnalytics.isAnalyticsDisabled(); - expect(disabled).to.equal(false); - - done(); - }); - }); - - describe('Analytics disabled event type test', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - clock = sinon.useFakeTimers(Date.now()); - }); - - afterEach(function () { - events.getEvents.restore(); - clock.restore(); - }); - - after(function () { - nobidAnalytics.disableAnalytics(); - }); - - it('Analytics disabled event type test', function (done) { - // Initialize adapter - const initOptions = { options: { siteId: SITE_ID } }; - nobidAnalytics.enableAnalytics(initOptions); - adapterManager.enableAnalytics({ provider: 'nobid', options: initOptions }); - - let eventType = EVENTS.AUCTION_END; - let disabled; - nobidAnalytics.processServerResponse(JSON.stringify({disabled: 0})); - disabled = nobidAnalytics.isAnalyticsDisabled(); - expect(disabled).to.equal(false); - events.emit(eventType, {auctionId: '1234567890'}); - clock.tick(1000); - expect(server.requests).to.have.length(1); - events.emit(eventType, {auctionId: '12345678901'}); - clock.tick(1000); - expect(server.requests).to.have.length(2); - - server.requests.length = 0; - expect(server.requests).to.have.length(0); - - nobidAnalytics.processServerResponse(JSON.stringify({disabled_auctionEnd: 1})); - disabled = nobidAnalytics.isAnalyticsDisabled(eventType); - expect(disabled).to.equal(true); - events.emit(eventType, {auctionId: '1234567890'}); - clock.tick(1000); - expect(server.requests).to.have.length(0); - - server.requests.length = 0; - - nobidAnalytics.processServerResponse(JSON.stringify({disabled_auctionEnd: 0})); - disabled = nobidAnalytics.isAnalyticsDisabled(eventType); - expect(disabled).to.equal(false); - events.emit(EVENTS.AUCTION_END, {auctionId: '1234567890'}); - clock.tick(1000); - expect(server.requests).to.have.length(1); - - server.requests.length = 0; - expect(server.requests).to.have.length(0); - - eventType = EVENTS.BID_WON; - nobidAnalytics.processServerResponse(JSON.stringify({disabled_bidWon: 1})); - disabled = nobidAnalytics.isAnalyticsDisabled(eventType); - expect(disabled).to.equal(true); - events.emit(eventType, {bidderCode: 'nobid'}); - clock.tick(1000); - expect(server.requests).to.have.length(0); - - server.requests.length = 0; - expect(server.requests).to.have.length(0); - - eventType = EVENTS.AUCTION_END; - nobidAnalytics.processServerResponse(JSON.stringify({disabled: 1})); - disabled = nobidAnalytics.isAnalyticsDisabled(eventType); - expect(disabled).to.equal(true); - events.emit(eventType, {auctionId: '1234567890'}); - clock.tick(1000); - expect(server.requests).to.have.length(0); - - server.requests.length = 0; - expect(server.requests).to.have.length(0); - - eventType = EVENTS.AUCTION_END; - nobidAnalytics.processServerResponse(JSON.stringify({disabled_auctionEnd: 1, disabled_bidWon: 0})); - disabled = nobidAnalytics.isAnalyticsDisabled(eventType); - expect(disabled).to.equal(true); - events.emit(eventType, {auctionId: '1234567890'}); - clock.tick(1000); - expect(server.requests).to.have.length(0); - disabled = nobidAnalytics.isAnalyticsDisabled(EVENTS.BID_WON); - expect(disabled).to.equal(false); - events.emit(EVENTS.BID_WON, {bidderCode: 'nobid'}); - clock.tick(1000); - expect(server.requests).to.have.length(1); - - done(); - }); - }); - - describe('NoBid Carbonizer', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - clock = sinon.useFakeTimers(Date.now()); - }); - - afterEach(function () { - events.getEvents.restore(); - clock.restore(); - }); - - after(function () { - nobidAnalytics.disableAnalytics(); - }); - - it('Carbonizer test', function (done) { - let active = nobidCarbonizer.isActive(); - expect(active).to.equal(false); - - nobidAnalytics.processServerResponse(JSON.stringify({carbonizer_active: false})); - active = nobidCarbonizer.isActive(); - expect(active).to.equal(false); - - nobidAnalytics.processServerResponse(JSON.stringify({carbonizer_active: true})); - active = nobidCarbonizer.isActive(); - expect(active).to.equal(true); - - const previousRetention = nobidAnalytics.retentionSeconds; - nobidAnalytics.retentionSeconds = 3; - nobidAnalytics.processServerResponse(JSON.stringify({carbonizer_active: true})); - let stored = nobidCarbonizer.getStoredLocalData(); - expect(stored[nobidAnalytics.ANALYTICS_DATA_NAME]).to.contain(`{"carbonizer_active":true,"ts":`); - clock.tick(5000); - active = nobidCarbonizer.isActive(); - expect(active).to.equal(false); - - nobidAnalytics.retentionSeconds = previousRetention; - nobidAnalytics.processServerResponse(JSON.stringify({carbonizer_active: true})); - active = nobidCarbonizer.isActive(); - expect(active).to.equal(true); - - const adunits = [ - { - bids: [ - { bidder: 'bidder1' }, - { bidder: 'bidder2' } - ] - } - ] - nobidCarbonizer.carbonizeAdunits(adunits, true); - stored = nobidCarbonizer.getStoredLocalData(); - expect(stored[nobidAnalytics.ANALYTICS_DATA_NAME]).to.contain('{"carbonizer_active":true,"ts":'); - expect(stored[nobidAnalytics.ANALYTICS_OPT_NAME]).to.contain('{"bidder1":1,"bidder2":1}'); - clock.tick(5000); - expect(adunits[0].bids.length).to.equal(0); - - done(); - }); - }); -}); diff --git a/test/spec/modules/nobidBidAdapter_spec.js b/test/spec/modules/nobidBidAdapter_spec.js deleted file mode 100644 index 53a838121..000000000 --- a/test/spec/modules/nobidBidAdapter_spec.js +++ /dev/null @@ -1,1086 +0,0 @@ -import { expect } from 'chai'; -import * as utils from 'src/utils.js'; -import { spec } from 'modules/nobidBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import * as bidderFactory from 'src/adapters/bidderFactory.js'; - -describe('Nobid Adapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('buildRequestsWithFloor', function () { - const SITE_ID = 2; - const REFERER = 'https://www.examplereferer.com'; - const bidRequests = [ - { - 'bidder': 'nobid', - 'params': { - 'siteId': SITE_ID - }, - 'getFloor': () => { return { currency: 'USD', floor: 1.00 } }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - } - ]; - - const bidderRequest = { - refererInfo: {page: REFERER} - } - - it('should FLoor = 1', function () { - spec.buildRequests(bidRequests, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.a[0].floor).to.equal(1); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'nobid', - 'params': { - 'siteId': 2 - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when required params found', function () { - delete bid.params; - bid.params = { - 'siteId': 2 - }; - - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - delete bid.params; - bid.params = { - 'siteId': 0 - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('Request with ORTB2', function () { - const SITE_ID = 2; - const REFERER = 'https://www.examplereferer.com'; - const BIDDER_CODE = 'duration'; - const bidRequests = [ - { - 'bidder': BIDDER_CODE, - 'params': { - 'siteId': SITE_ID - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - } - ]; - - const bidderRequest = { - refererInfo: {page: REFERER}, bidderCode: BIDDER_CODE - } - - const siteName = 'example'; - const siteDomain = 'page.example.com'; - const sitePage = 'https://page.example.com/here.html'; - const siteRef = 'https://ref.example.com'; - const siteKeywords = 'power tools, drills'; - const siteSearch = 'drill'; - const siteCat = 'IAB2'; - const siteSectionCat = 'IAB2-2'; - const sitePageCat = 'IAB2-12'; - - it('ortb2 should exist', function () { - const ortb2 = { - site: { - name: siteName, - domain: siteDomain, - cat: [ siteCat ], - sectioncat: [ siteSectionCat ], - pagecat: [ sitePageCat ], - page: sitePage, - ref: siteRef, - keywords: siteKeywords, - search: siteSearch - } - }; - const request = spec.buildRequests(bidRequests, {...bidderRequest, ortb2}); - let payload = JSON.parse(request.data); - payload = JSON.parse(JSON.stringify(payload)); - expect(payload.sid).to.equal(SITE_ID); - expect(payload.ortb2.site.name).to.equal(siteName); - expect(payload.ortb2.site.domain).to.equal(siteDomain); - expect(payload.ortb2.site.page).to.equal(sitePage); - expect(payload.ortb2.site.ref).to.equal(siteRef); - expect(payload.ortb2.site.keywords).to.equal(siteKeywords); - expect(payload.ortb2.site.search).to.equal(siteSearch); - expect(payload.ortb2.site.cat[0]).to.equal(siteCat); - expect(payload.ortb2.site.sectioncat[0]).to.equal(siteSectionCat); - expect(payload.ortb2.site.pagecat[0]).to.equal(sitePageCat); - }); - }); - - describe('Request with GPP', function () { - const SITE_ID = 2; - const REFERER = 'https://www.examplereferer.com'; - const BIDDER_CODE = 'duration'; - const bidRequests = [ - { - 'bidder': BIDDER_CODE, - 'params': { - 'siteId': SITE_ID - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - } - ]; - - const GPP = 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN'; - const GPP_SID = [1, 3]; - - const bidderRequest = { - refererInfo: {page: REFERER}, - bidderCode: BIDDER_CODE, - gppConsent: {gppString: GPP, applicableSections: GPP_SID} - } - - it('gpp should match', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - let payload = JSON.parse(request.data); - payload = JSON.parse(JSON.stringify(payload)); - expect(payload.gpp).to.equal(GPP); - expect(payload.gpp_sid.join(',')).to.equal(GPP_SID.join(',')); - }); - - it('gpp should not be set', function () { - delete bidderRequest.gppConsent.applicableSections; - const request = spec.buildRequests(bidRequests, bidderRequest); - let payload = JSON.parse(request.data); - payload = JSON.parse(JSON.stringify(payload)); - expect(typeof payload.gpp).to.equal('undefined'); - expect(typeof payload.gpp_sid).to.equal('undefined'); - }); - - it('gpp ortb2 should match', function () { - delete bidderRequest.gppConsent; - bidderRequest.ortb2 = {regs: {gpp: GPP, gpp_sid: GPP_SID}}; - const request = spec.buildRequests(bidRequests, bidderRequest); - let payload = JSON.parse(request.data); - payload = JSON.parse(JSON.stringify(payload)); - expect(payload.gpp).to.equal(GPP); - expect(payload.gpp_sid.join(',')).to.equal(GPP_SID.join(',')); - }); - }); - - describe('isDurationBidRequestValid', function () { - const SITE_ID = 2; - const REFERER = 'https://www.examplereferer.com'; - const BIDDER_CODE = 'duration'; - const bidRequests = [ - { - 'bidder': BIDDER_CODE, - 'params': { - 'siteId': SITE_ID - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - } - ]; - - const bidderRequest = { - refererInfo: {page: REFERER}, bidderCode: BIDDER_CODE - } - - it('should add source and version to the tag', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.sid).to.equal(SITE_ID); - expect(payload.pjbdr).to.equal(BIDDER_CODE); - expect(payload.l).to.exist.and.to.equal(encodeURIComponent(REFERER)); - expect(payload.tt).to.exist; - expect(payload.a).to.exist; - expect(payload.t).to.exist; - expect(payload.tz).to.exist; - expect(payload.r).to.exist; - expect(payload.lang).to.exist; - expect(payload.ref).to.exist; - expect(payload.gdpr).to.exist; - }); - - it('sends bid request to ad size', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.a).to.exist; - expect(payload.a.length).to.exist.and.to.equal(1); - expect(payload.a[0].z[0][0]).to.equal(300); - expect(payload.a[0].z[0][1]).to.equal(250); - }); - - it('sends bid request to div id', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.a).to.exist; - expect(payload.a[0].d).to.equal('adunit-code'); - }); - - it('sends bid request to site id', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.a).to.exist; - expect(payload.a[0].sid).to.equal(2); - expect(payload.a[0].at).to.equal('banner'); - expect(payload.a[0].params.siteId).to.equal(2); - }); - - it('sends bid request to ad type', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.a).to.exist; - expect(payload.a[0].at).to.equal('banner'); - }); - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests); - expect(request.url).to.contain('ads.servenobid.com/adreq'); - expect(request.method).to.equal('POST'); - }); - - it('should add gdpr consent information to the request', function () { - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const bidderRequest = { - 'bidderCode': 'nobid', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - consentString: consentString, - gdprApplies: true - } - }; - bidderRequest.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdpr).to.exist; - expect(payload.gdpr.consentString).to.exist.and.to.equal(consentString); - expect(payload.gdpr.consentRequired).to.exist.and.to.be.true; - }); - - it('should add gdpr consent information to the request', function () { - const bidderRequest = { - 'bidderCode': 'nobid', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - gdprApplies: false - } - }; - bidderRequest.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdpr).to.exist; - expect(payload.gdpr.consentString).to.not.exist; - expect(payload.gdpr.consentRequired).to.exist.and.to.be.false; - }); - - it('should add usp consent information to the request', function () { - const bidderRequest = { - 'bidderCode': 'nobid', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'uspConsent': '1Y-N' - }; - bidderRequest.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.usp).to.exist; - expect(payload.usp).to.exist.and.to.equal('1Y-N'); - }); - }); - - describe('isVideoBidRequestValid', function () { - const bid = { - bidder: 'nobid', - params: { - siteId: 2, - video: { - skippable: true, - playback_methods: ['auto_play_sound_off'], - position: 'atf', - mimes: ['video/x-flv', 'video/mp4', 'video/x-ms-wmv', 'application/x-shockwave-flash', 'application/javascript'], - minduration: 1, - maxduration: 30, - frameworks: [1, 2, 3, 4, 5, 6] - } - }, - adUnitCode: 'adunit-code', - sizes: [[640, 480]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - mediaTypes: { - video: { - context: 'instream' - } - } - }; - const SITE_ID = 2; - const REFERER = 'https://www.examplereferer.com'; - const bidRequests = [ - { - bidder: 'nobid', - params: { - siteId: SITE_ID, - video: { - skippable: true, - playback_methods: ['auto_play_sound_off'], - position: 'atf', - mimes: ['video/x-flv', 'video/mp4', 'video/x-ms-wmv', 'application/x-shockwave-flash', 'application/javascript'], - minduration: 1, - maxduration: 30, - frameworks: [1, 2, 3, 4, 5, 6] - } - }, - adUnitCode: 'adunit-code', - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'instream' - } - } - } - ]; - - const bidderRequest = { - refererInfo: {page: REFERER} - } - - it('should add source and version to the tag', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.sid).to.equal(SITE_ID); - expect(payload.pjbdr).to.equal('nobid'); - expect(payload.pbver).to.equal('$prebid.version$'); - expect(payload.l).to.exist.and.to.equal(encodeURIComponent(REFERER)); - expect(payload.a).to.exist; - expect(payload.t).to.exist; - expect(payload.tz).to.exist; - expect(payload.lang).to.exist; - expect(payload.ref).to.exist; - expect(payload.a[0].d).to.exist.and.to.equal('adunit-code'); - expect(payload.a[0].at).to.exist.and.to.equal('video'); - expect(payload.a[0].params.video).to.exist; - expect(payload.a[0].params.video.skippable).to.exist.and.to.equal(true); - expect(payload.a[0].params.video.playback_methods).to.exist.and.to.contain('auto_play_sound_off'); - expect(payload.a[0].params.video.position).to.exist.and.to.equal('atf'); - expect(payload.a[0].params.video.mimes).to.exist.and.to.contain('video/x-flv'); - expect(payload.a[0].params.video.minduration).to.exist.and.to.equal(1); - expect(payload.a[0].params.video.maxduration).to.exist.and.to.equal(30); - expect(payload.a[0].params.video.frameworks[0]).to.exist.and.to.equal(1); - expect(payload.a[0].params.video.frameworks[1]).to.exist.and.to.equal(2); - expect(payload.a[0].params.video.frameworks[2]).to.exist.and.to.equal(3); - expect(payload.a[0].params.video.frameworks[3]).to.exist.and.to.equal(4); - expect(payload.a[0].params.video.frameworks[4]).to.exist.and.to.equal(5); - expect(payload.a[0].params.video.frameworks[5]).to.exist.and.to.equal(6); - }); - }); - - describe('isVideoBidRequestValid', function () { - const bid = { - bidder: 'nobid', - params: { - siteId: 2, - video: { - skippable: true, - playback_methods: ['auto_play_sound_off'], - position: 'atf', - mimes: ['video/x-flv', 'video/mp4', 'video/x-ms-wmv', 'application/x-shockwave-flash', 'application/javascript'], - minduration: 1, - maxduration: 30, - frameworks: [1, 2, 3, 4, 5, 6] - } - }, - adUnitCode: 'adunit-code', - sizes: [[640, 480]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - mediaTypes: { - video: { - context: 'outstream' - } - } - }; - const SITE_ID = 2; - const REFERER = 'https://www.examplereferer.com'; - const bidRequests = [ - { - bidder: 'nobid', - params: { - siteId: SITE_ID, - video: { - skippable: true, - playback_methods: ['auto_play_sound_off'], - position: 'atf', - mimes: ['video/x-flv', 'video/mp4', 'video/x-ms-wmv', 'application/x-shockwave-flash', 'application/javascript'], - minduration: 1, - maxduration: 30, - frameworks: [1, 2, 3, 4, 5, 6] - } - }, - adUnitCode: 'adunit-code', - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'outstream' - } - } - } - ]; - - const bidderRequest = { - refererInfo: {page: REFERER} - } - - it('should add source and version to the tag', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.pjbdr).to.equal('nobid'); - expect(payload.sid).to.equal(SITE_ID); - expect(payload.l).to.exist.and.to.equal(encodeURIComponent(REFERER)); - expect(payload.a).to.exist; - expect(payload.t).to.exist; - expect(payload.tz).to.exist; - expect(payload.r).to.exist; - expect(payload.lang).to.exist; - expect(payload.ref).to.exist; - expect(payload.a[0].d).to.exist.and.to.equal('adunit-code'); - expect(payload.a[0].at).to.exist.and.to.equal('video'); - expect(payload.a[0].params.video).to.exist; - expect(payload.a[0].params.video.skippable).to.exist.and.to.equal(true); - expect(payload.a[0].params.video.playback_methods).to.exist.and.to.contain('auto_play_sound_off'); - expect(payload.a[0].params.video.position).to.exist.and.to.equal('atf'); - expect(payload.a[0].params.video.mimes).to.exist.and.to.contain('video/x-flv'); - expect(payload.a[0].params.video.minduration).to.exist.and.to.equal(1); - expect(payload.a[0].params.video.maxduration).to.exist.and.to.equal(30); - expect(payload.a[0].params.video.frameworks[0]).to.exist.and.to.equal(1); - expect(payload.a[0].params.video.frameworks[1]).to.exist.and.to.equal(2); - expect(payload.a[0].params.video.frameworks[2]).to.exist.and.to.equal(3); - expect(payload.a[0].params.video.frameworks[3]).to.exist.and.to.equal(4); - expect(payload.a[0].params.video.frameworks[4]).to.exist.and.to.equal(5); - expect(payload.a[0].params.video.frameworks[5]).to.exist.and.to.equal(6); - }); - }); - - describe('buildRequestsEIDs', function () { - const SITE_ID = 2; - const REFERER = 'https://www.examplereferer.com'; - const bidRequests = [ - { - 'bidder': 'nobid', - 'params': { - 'siteId': SITE_ID - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'userIdAsEids': [ - { - 'source': 'criteo.com', - 'uids': [ - { - 'id': 'CRITEO_ID', - 'atype': 1 - } - ] - }, - { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': 'ID5_ID', - 'atype': 1 - } - ], - 'ext': { - 'linkType': 0 - } - }, - { - 'source': 'adserver.org', - 'uids': [ - { - 'id': 'TD_ID', - 'atype': 1, - 'ext': { - 'rtiPartner': 'TDID' - } - } - ] - } - ] - } - ]; - - const bidderRequest = { - refererInfo: {page: REFERER} - } - - it('should criteo eid', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.sid).to.exist.and.to.equal(2); - expect(payload.eids[0].source).to.exist.and.to.equal('criteo.com'); - expect(payload.eids[0].uids[0].id).to.exist.and.to.equal('CRITEO_ID'); - expect(payload.eids[1].source).to.exist.and.to.equal('id5-sync.com'); - expect(payload.eids[1].uids[0].id).to.exist.and.to.equal('ID5_ID'); - expect(payload.eids[2].source).to.exist.and.to.equal('adserver.org'); - expect(payload.eids[2].uids[0].id).to.exist.and.to.equal('TD_ID'); - }); - }); - - describe('buildRequests', function () { - const SITE_ID = 2; - const REFERER = 'https://www.examplereferer.com'; - const bidRequests = [ - { - 'bidder': 'nobid', - 'params': { - 'siteId': SITE_ID - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - } - ]; - - const bidderRequest = { - refererInfo: {page: REFERER} - } - - it('should add source and version to the tag', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.sid).to.equal(SITE_ID); - expect(payload.l).to.exist.and.to.equal(encodeURIComponent(REFERER)); - expect(payload.tt).to.exist; - expect(payload.a).to.exist; - expect(payload.t).to.exist; - expect(payload.tz).to.exist; - expect(payload.r).to.exist; - expect(payload.lang).to.exist; - expect(payload.ref).to.exist; - expect(payload.gdpr).to.exist; - }); - - it('sends bid request to ad size', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.a).to.exist; - expect(payload.a.length).to.exist.and.to.equal(1); - expect(payload.a[0].z[0][0]).to.equal(300); - expect(payload.a[0].z[0][1]).to.equal(250); - }); - - it('sends bid request to div id', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.a).to.exist; - expect(payload.a[0].d).to.equal('adunit-code'); - }); - - it('sends bid request to site id', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.a).to.exist; - expect(payload.a[0].sid).to.equal(2); - expect(payload.a[0].at).to.equal('banner'); - expect(payload.a[0].params.siteId).to.equal(2); - }); - - it('sends bid request to ad type', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.a).to.exist; - expect(payload.a[0].at).to.equal('banner'); - }); - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests); - expect(request.url).to.contain('ads.servenobid.com/adreq'); - expect(request.method).to.equal('POST'); - }); - - it('should add gdpr consent information to the request', function () { - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const bidderRequest = { - 'bidderCode': 'nobid', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - consentString: consentString, - gdprApplies: true - } - }; - bidderRequest.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdpr).to.exist; - expect(payload.gdpr.consentString).to.exist.and.to.equal(consentString); - expect(payload.gdpr.consentRequired).to.exist.and.to.be.true; - }); - - it('should add gdpr consent information to the request', function () { - const bidderRequest = { - 'bidderCode': 'nobid', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - gdprApplies: false - } - }; - bidderRequest.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdpr).to.exist; - expect(payload.gdpr.consentString).to.not.exist; - expect(payload.gdpr.consentRequired).to.exist.and.to.be.false; - }); - - it('should add usp consent information to the request', function () { - const bidderRequest = { - 'bidderCode': 'nobid', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'uspConsent': '1Y-N' - }; - bidderRequest.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.usp).to.exist; - expect(payload.usp).to.exist.and.to.equal('1Y-N'); - }); - }); - - describe('buildRequestsRefreshCount', function () { - const SITE_ID = 2; - const REFERER = 'https://www.examplereferer.com'; - const bidRequests = [ - { - 'bidder': 'nobid', - 'params': { - 'siteId': SITE_ID - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - } - ]; - - const bidderRequest = { - refererInfo: {page: REFERER} - } - - it('should refreshCount = 4', function () { - nobid.refreshLimit = 2; - nobid.refreshCount = 0; - spec.buildRequests(bidRequests, bidderRequest); - spec.buildRequests(bidRequests, bidderRequest); - spec.buildRequests(bidRequests, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(nobid.refreshCount).to.equal(3); - expect(typeof request).to.equal('undefined'); - }); - }); - - describe('interpretResponse', function () { - const CREATIVE_ID_300x250 = 'CREATIVE-100'; - const ADUNIT_300x250 = 'ADUNIT-1'; - const ADMARKUP_300x250 = 'ADMARKUP-300x250'; - const PRICE_300x250 = 0.51; - const REQUEST_ID = '3db3773286ee59'; - const DEAL_ID = 'deal123'; - const response = { - country: 'US', - ip: '68.83.15.75', - device: 'COMPUTER', - site: 2, - bids: [ - {id: 1, - bdrid: 101, - divid: ADUNIT_300x250, - dealid: DEAL_ID, - creativeid: CREATIVE_ID_300x250, - size: {'w': 300, 'h': 250}, - adm: ADMARKUP_300x250, - price: '' + PRICE_300x250 - } - ] - }; - - it('should get correct bid response', function () { - const expectedResponse = [ - { - requestId: REQUEST_ID, - cpm: PRICE_300x250, - width: 300, - height: 250, - creativeId: CREATIVE_ID_300x250, - dealId: DEAL_ID, - currency: 'USD', - netRevenue: true, - ttl: 300, - ad: ADMARKUP_300x250, - mediaType: 'banner' - } - ]; - - const bidderRequest = { - bids: [{ - bidId: REQUEST_ID, - adUnitCode: ADUNIT_300x250 - }] - } - const result = spec.interpretResponse({ body: response }, {bidderRequest: bidderRequest}); - expect(result.length).to.equal(expectedResponse.length); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - expect(result[0].requestId).to.equal(expectedResponse[0].requestId); - expect(result[0].cpm).to.equal(expectedResponse[0].cpm); - }); - - it('should get correct empty response', function () { - const bidderRequest = { - bids: [{ - bidId: REQUEST_ID, - adUnitCode: ADUNIT_300x250 + '1' - }] - } - const result = spec.interpretResponse({ body: response }, {bidderRequest: bidderRequest}); - expect(result.length).to.equal(0); - }); - - it('should get correct deal id', function () { - const expectedResponse = [ - { - requestId: REQUEST_ID, - cpm: PRICE_300x250, - width: 300, - height: 250, - creativeId: CREATIVE_ID_300x250, - dealId: DEAL_ID, - currency: 'USD', - netRevenue: true, - ttl: 300, - ad: ADMARKUP_300x250, - mediaType: 'banner' - } - ]; - - const bidderRequest = { - bids: [{ - bidId: REQUEST_ID, - adUnitCode: ADUNIT_300x250 - }] - } - const result = spec.interpretResponse({ body: response }, {bidderRequest: bidderRequest}); - expect(result.length).to.equal(expectedResponse.length); - expect(result[0].dealId).to.equal(expectedResponse[0].dealId); - }); - }); - - describe('interpretResponseWithRefreshLimit', function () { - const CREATIVE_ID_300x250 = 'CREATIVE-100'; - const ADUNIT_300x250 = 'ADUNIT-1'; - const ADMARKUP_300x250 = 'ADMARKUP-300x250'; - const PRICE_300x250 = 0.51; - const REQUEST_ID = '3db3773286ee59'; - const DEAL_ID = 'deal123'; - const REFRESH_LIMIT = 3; - const response = { - country: 'US', - ip: '68.83.15.75', - device: 'COMPUTER', - site: 2, - rlimit: REFRESH_LIMIT, - bids: [ - {id: 1, - bdrid: 101, - divid: ADUNIT_300x250, - dealid: DEAL_ID, - creativeid: CREATIVE_ID_300x250, - size: {'w': 300, 'h': 250}, - adm: ADMARKUP_300x250, - price: '' + PRICE_300x250 - } - ] - }; - - it('should refreshLimit be respected', function () { - const bidderRequest = { - bids: [{ - bidId: REQUEST_ID, - adUnitCode: ADUNIT_300x250 - }] - } - const result = spec.interpretResponse({ body: response }, {bidderRequest: bidderRequest}); - expect(nobid.refreshLimit).to.equal(REFRESH_LIMIT); - }); - }); - - describe('interpretResponseWithMeta', function () { - const CREATIVE_ID_300x250 = 'CREATIVE-100'; - const ADUNIT_300x250 = 'ADUNIT-1'; - const ADMARKUP_300x250 = 'ADMARKUP-300x250'; - const PRICE_300x250 = 0.51; - const REQUEST_ID = '3db3773286ee59'; - const DEAL_ID = 'deal123'; - const ADOMAINS = ['adomain1', 'adomain2']; - const response = { - country: 'US', - ip: '68.83.15.75', - device: 'COMPUTER', - site: 2, - bids: [ - {id: 1, - bdrid: 101, - divid: ADUNIT_300x250, - dealid: DEAL_ID, - creativeid: CREATIVE_ID_300x250, - size: {'w': 300, 'h': 250}, - adm: ADMARKUP_300x250, - price: '' + PRICE_300x250, - meta: { - advertiserDomains: ADOMAINS - } - } - ] - }; - - it('should meta.advertiserDomains be respected', function () { - const bidderRequest = { - bids: [{ - bidId: REQUEST_ID, - adUnitCode: ADUNIT_300x250 - }] - } - const result = spec.interpretResponse({ body: response }, {bidderRequest: bidderRequest}); - expect(result[0].meta.advertiserDomains).to.equal(ADOMAINS); - }); - }); - - describe('buildRequestsWithSupplyChain', function () { - const SITE_ID = 2; - const bidRequests = [ - { - bidder: 'nobid', - params: { - siteId: SITE_ID - }, - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - coppa: true, - ortb2: { - source: { - ext: { - schain: { - validation: 'strict', - config: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'indirectseller.com', - sid: '00001', - name: 'name.com', - hp: 1 - } - ] - } - } - } - } - } - } - ]; - - it('schain exist', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.schain).to.exist; - expect(payload.schain.validation).to.exist.and.to.equal('strict'); - expect(payload.schain.config.ver).to.exist.and.to.equal('1.0'); - expect(payload.schain.config.complete).to.exist.and.to.equal(1); - expect(payload.schain.config.nodes[0].asi).to.exist.and.to.equal('indirectseller.com'); - expect(payload.schain.config.nodes[0].sid).to.exist.and.to.equal('00001'); - expect(payload.schain.config.nodes[0].name).to.exist.and.to.equal('name.com'); - expect(payload.schain.config.nodes[0].hp).to.exist.and.to.equal(1); - expect(payload.coppa).to.exist; - expect(payload.coppa).to.exist.and.to.be.true; - expect(payload.a).to.be.lengthOf(1); - expect(request.method).to.equal('POST'); - }); - }); - - describe('interpretResponseWithUserLimit', function () { - const CREATIVE_ID_300x250 = 'CREATIVE-100'; - const ADUNIT_300x250 = 'ADUNIT-1'; - const ADMARKUP_300x250 = 'ADMARKUP-300x250'; - const PRICE_300x250 = 0.51; - const REQUEST_ID = '3db3773286ee59'; - const DEAL_ID = 'deal123'; - const ULIMIT = 1; - const response = { - country: 'US', - ip: '68.83.15.75', - device: 'COMPUTER', - site: 2, - ublock: ULIMIT, - bids: [ - {id: 1, - bdrid: 101, - divid: ADUNIT_300x250, - dealid: DEAL_ID, - creativeid: CREATIVE_ID_300x250, - size: {'w': 300, 'h': 250}, - adm: ADMARKUP_300x250, - price: '' + PRICE_300x250 - } - ] - }; - - it('should ULimit be respected', function () { - const bidderRequest = { - bids: [{ - bidId: REQUEST_ID, - adUnitCode: ADUNIT_300x250 - }] - } - const bidRequests = [ - { - 'bidder': 'nobid', - 'params': { - 'siteId': 2 - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - } - ]; - spec.interpretResponse({ body: response }, {bidderRequest: bidderRequest}); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request).to.equal(undefined); - }); - }); - - describe('getUserSyncs', function () { - const GDPR_CONSENT_STRING = 'GDPR_CONSENT_STRING'; - it('should get correct user sync when iframeEnabled', function () { - const pixel = spec.getUserSyncs({iframeEnabled: true}) - expect(pixel[0].type).to.equal('iframe'); - expect(pixel[0].url).to.equal('https://public.servenobid.com/sync.html'); - }); - - it('should get correct user sync when iframeEnabled and pixelEnabled', function () { - const pixel = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}) - expect(pixel[0].type).to.equal('iframe'); - expect(pixel[0].url).to.equal('https://public.servenobid.com/sync.html'); - }); - - it('should get correct user sync when iframeEnabled', function () { - const pixel = spec.getUserSyncs({iframeEnabled: true}, {}, {gdprApplies: true, consentString: GDPR_CONSENT_STRING}) - expect(pixel[0].type).to.equal('iframe'); - expect(pixel[0].url).to.equal('https://public.servenobid.com/sync.html?gdpr=1&gdpr_consent=' + GDPR_CONSENT_STRING); - }); - - it('should get correct user sync when !iframeEnabled', function () { - const pixel = spec.getUserSyncs({iframeEnabled: false}) - expect(pixel.length).to.equal(0); - }); - - it('should get correct user sync when !iframeEnabled and pixelEnabled', function () { - const pixel = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [{body: {syncs: ['sync_url']}}]) - expect(pixel.length).to.equal(1); - expect(pixel[0].type).to.equal('image'); - expect(pixel[0].url).to.equal('sync_url'); - }); - - it('should get correct user sync when !iframeEnabled', function () { - let pixel = spec.getUserSyncs({}) - expect(pixel.length).to.equal(0); - }); - }); - - describe('onTimeout', function (syncOptions) { - it('should increment timeoutTotal', function () { - const timeoutTotal = spec.onTimeout() - expect(timeoutTotal).to.equal(1); - }); - }); - - describe('onBidWon', function (syncOptions) { - it('should increment bidWonTotal', function () { - const bidWonTotal = spec.onBidWon() - expect(bidWonTotal).to.equal(1); - }); - }); -}); diff --git a/test/spec/modules/nodalsAiRtdProvider_spec.js b/test/spec/modules/nodalsAiRtdProvider_spec.js deleted file mode 100644 index f07d13fd1..000000000 --- a/test/spec/modules/nodalsAiRtdProvider_spec.js +++ /dev/null @@ -1,865 +0,0 @@ -import { expect } from 'chai'; -import { MODULE_TYPE_RTD } from 'src/activities/modules.js'; -import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; -import { server } from 'test/mocks/xhr.js'; - -import { nodalsAiRtdSubmodule } from 'modules/nodalsAiRtdProvider.js'; - -const jsonResponseHeaders = { - 'Content-Type': 'application/json', -}; - -const overrideLocalStorageKey = '_foobarbaz_'; - -const successPubEndpointResponse = { - deps: { - '1.0.0': 'https://static.nodals.io/sdk/rule/1.0.0/engine.js', - '1.1.0': 'https://static.nodals.io/sdk/rule/1.1.0/engine.js', - }, - facts: { - 'browser.name': 'safari', - 'geo.country': 'AR', - }, - campaigns: [ - { - id: '41ffa965', - ads: [ - { - delivery_id: '1234', - property_id: 'fd32da', - weighting: 1, - kvs: [ - { - key: 'nodals', - value: '1', - }, - ], - rules: { - engine: { - version: '1.0.0', - }, - conditions: { - ANY: [ - { - fact: 'id', - op: 'allin', - val: ['1', '2', '3'], - }, - ], - NONE: [ - { - fact: 'ua.browser', - op: 'eq', - val: 'opera', - }, - ], - }, - }, - }, - ], - }, - ], -}; - -const engineGetTargetingDataReturnValue = { - adUnit1: { - adv1: 'foobarbaz', - }, -}; - -const generateGdprConsent = (consent = {}) => { - const defaults = { - gdprApplies: true, - purpose1Consent: true, - purpose7Consent: true, - nodalsConsent: true, - }; - const mergedConsent = { ...defaults, ...consent }; - return JSON.parse(JSON.stringify({ - gdpr: { - gdprApplies: mergedConsent.gdprApplies, - consentString: mergedConsent.consentString, - vendorData: { - purpose: { - consents: { - 1: mergedConsent.purpose1Consent, - 2: true, - 3: true, - 4: true, - 5: true, - 6: true, - 7: mergedConsent.purpose7Consent, - 8: true, - 9: true, - 10: true, - }, - }, - specialFeatureOptins: { - 1: true, - }, - vendor: { - consents: { - 1360: mergedConsent.nodalsConsent, - }, - }, - }, - }, - })); -}; - -const setDataInLocalStorage = (data) => { - const storageData = { ...data }; - nodalsAiRtdSubmodule.storage.setDataInLocalStorage( - nodalsAiRtdSubmodule.STORAGE_KEY, - JSON.stringify(storageData), - ); -}; - -const createTargetingEngineStub = (getTargetingDataReturnValue = {}, raiseError = false) => { - const version = '1.x.x'; - const initStub = sinon.stub(); - const getTargetingDataStub = sinon.stub(); - const getBidRequestDataStub = sinon.stub(); - const onBidResponseEventStub = sinon.stub(); - const onAuctionEndEventStub = sinon.stub(); - if (raiseError) { - getTargetingDataStub.throws(new Error('Stubbed error')); - } else { - getTargetingDataStub.returns(getTargetingDataReturnValue); - } - window.$nodals = window.$nodals || {}; - window.$nodals.adTargetingEngine = window.$nodals.adTargetingEngine || {}; - window.$nodals.adTargetingEngine[version] = { - init: initStub, - getTargetingData: getTargetingDataStub, - getBidRequestData: getBidRequestDataStub, - onBidResponseEvent: onBidResponseEventStub, - onAuctionEndEvent: onAuctionEndEventStub, - }; - return window.$nodals.adTargetingEngine[version]; -}; - -describe('NodalsAI RTD Provider', () => { - let sandbox; - let validConfig; - const permissiveUserConsent = generateGdprConsent(); - const vendorRestrictiveUserConsent = generateGdprConsent({ nodalsConsent: false }); - const noPurpose1UserConsent = generateGdprConsent({ purpose1Consent: false }); - const noPurpose7UserConsent = generateGdprConsent({ purpose7Consent: false }); - const outsideGdprUserConsent = generateGdprConsent({ gdprApplies: false }); - - beforeEach(() => { - sandbox = sinon.createSandbox(); - - validConfig = { params: { propertyId: '10312dd2' } }; - - server.respondWith([ - 200, - jsonResponseHeaders, - JSON.stringify(successPubEndpointResponse) - ]); - }); - - afterEach(() => { - if (window.$nodals) { - delete window.$nodals; - } - - nodalsAiRtdSubmodule.storage.removeDataFromLocalStorage( - nodalsAiRtdSubmodule.STORAGE_KEY - ); - nodalsAiRtdSubmodule.storage.removeDataFromLocalStorage( - overrideLocalStorageKey - ); - - sandbox.restore(); - }); - - describe('Module properties', () => { - it('should have the name property set correctly', function () { - expect(nodalsAiRtdSubmodule.name).equals('nodalsAi'); - }); - - it('should expose the correct TCF Global Vendor ID', function () { - expect(nodalsAiRtdSubmodule.gvlid).equals(1360); - }); - }); - - describe('init()', () => { - describe('when initialised with empty consent data', () => { - it('should return true when initialised with valid config and empty user consent', function () { - const result = nodalsAiRtdSubmodule.init(validConfig, {}); - server.respond(); - - expect(result).to.be.true; - expect(server.requests.length).to.equal(1); - }); - - it('should return true when initialised with valid config and gdpr consent is null', function () { - const result = nodalsAiRtdSubmodule.init(validConfig, {gdpr: null}); - server.respond(); - - expect(result).to.be.true; - expect(server.requests.length).to.equal(1); - }); - - it('should return false when initialised with invalid config', () => { - const config = { params: { invalid: true } }; - const result = nodalsAiRtdSubmodule.init(config, {}); - server.respond(); - - expect(result).to.be.false; - expect(server.requests.length).to.equal(0); - }); - }); - - describe('when initialised with valid config data', () => { - it('should return false when user is under GDPR jurisdiction and purpose1 has not been granted', () => { - const result = nodalsAiRtdSubmodule.init(validConfig, noPurpose1UserConsent); - server.respond(); - - expect(result).to.be.false; - expect(server.requests.length).to.equal(0); - }); - - it('should return false when user is under GDPR jurisdiction and purpose7 has not been granted', () => { - const result = nodalsAiRtdSubmodule.init(validConfig, noPurpose7UserConsent); - server.respond(); - - expect(result).to.be.false; - expect(server.requests.length).to.equal(0); - }); - - it('should return false when user is under GDPR jurisdiction and Nodals AI as a vendor has no consent', () => { - const result = nodalsAiRtdSubmodule.init(validConfig, vendorRestrictiveUserConsent); - server.respond(); - - expect(result).to.be.false; - expect(server.requests.length).to.equal(0); - }); - - it('should return false when user is under GDPR jurisdiction and Nodals AI is not present in the decoded consent string', () => { - const userConsent = JSON.parse(JSON.stringify(permissiveUserConsent)); - userConsent.gdpr.vendorData.vendor.consents = {}; - const result = nodalsAiRtdSubmodule.init(validConfig, userConsent); - server.respond(); - - expect(result).to.be.false; - expect(server.requests.length).to.equal(0); - }); - - it('should return true when user is under GDPR jurisdiction and all consent provided', function () { - const result = nodalsAiRtdSubmodule.init(validConfig, permissiveUserConsent); - server.respond(); - - expect(result).to.be.true; - expect(server.requests.length).to.equal(1); - }); - - it('should return true when user is not under GDPR jurisdiction', () => { - const result = nodalsAiRtdSubmodule.init(validConfig, outsideGdprUserConsent); - server.respond(); - - expect(result).to.be.true; - expect(server.requests.length).to.equal(1); - }); - }); - - describe('when initialised with valid config and data already in storage', () => { - it('should return true and not make a remote request when stored data is valid', function () { - setDataInLocalStorage({ data: { foo: 'bar' }, createdAt: Date.now() }); - const result = nodalsAiRtdSubmodule.init(validConfig, permissiveUserConsent); - server.respond(); - - expect(result).to.be.true; - expect(server.requests.length).to.equal(0); - }); - - it('should return true and make a remote request when stored data has no TTL defined', function () { - setDataInLocalStorage({ data: { foo: 'bar' } }); - const result = nodalsAiRtdSubmodule.init(validConfig, permissiveUserConsent); - server.respond(); - - expect(result).to.be.true; - expect(server.requests.length).to.equal(1); - }); - - it('should return true and make a remote request when stored data has expired', function () { - setDataInLocalStorage({ data: { foo: 'bar' }, createdAt: 100 }); - const result = nodalsAiRtdSubmodule.init(validConfig, permissiveUserConsent); - server.respond(); - - expect(result).to.be.true; - expect(server.requests.length).to.equal(1); - }); - - it('should detect stale data if override TTL is exceeded', function () { - const fiveMinutesAgoMs = Date.now() - (5 * 60 * 1000); - setDataInLocalStorage({ - data: { foo: 'bar' }, - createdAt: fiveMinutesAgoMs, - }); - const config = Object.assign({}, validConfig); - config.params.storage = { ttl: 4 * 60 }; - const result = nodalsAiRtdSubmodule.init(config, permissiveUserConsent); - server.respond(); - - expect(result).to.be.true; - expect(server.requests.length).to.equal(1); - }); - - it('should detect stale data if remote defined TTL is exceeded', function () { - const fiveMinutesAgoMs = Date.now() - (5 * 60 * 1000); - setDataInLocalStorage({ - data: { foo: 'bar', meta: { ttl: 4 * 60 } }, - createdAt: fiveMinutesAgoMs, - }); - const result = nodalsAiRtdSubmodule.init(validConfig, permissiveUserConsent); - server.respond(); - - expect(result).to.be.true; - expect(server.requests.length).to.equal(1); - }); - - it('should respect pub defined TTL over remote defined TTL', function () { - const fiveMinutesAgoMs = Date.now() - (5 * 60 * 1000); - setDataInLocalStorage({ - data: { foo: 'bar', meta: { ttl: 4 * 60 } }, - createdAt: fiveMinutesAgoMs, - }); - const config = Object.assign({}, validConfig); - config.params.storage = { ttl: 6 * 60 }; - const result = nodalsAiRtdSubmodule.init(config, permissiveUserConsent); - server.respond(); - - expect(result).to.be.true; - expect(server.requests.length).to.equal(0); - }); - - it('should NOT detect stale data if override TTL is not exceeded', function () { - const fiveMinutesAgoMs = Date.now() - 5 * 60 * 1000; - setDataInLocalStorage({ - data: { foo: 'bar' }, - createdAt: fiveMinutesAgoMs, - }); - const config = Object.assign({}, validConfig); - config.params.storage = { ttl: 6 * 60 }; - const result = nodalsAiRtdSubmodule.init(config, permissiveUserConsent); - server.respond(); - - expect(result).to.be.true; - expect(server.requests.length).to.equal(0); - }); - - it('should return true and make a remote request when data stored under default key, but override key specified', () => { - setDataInLocalStorage({ data: { foo: 'bar' }, createdAt: Date.now() }); - const config = Object.assign({}, validConfig); - config.params.storage = { key: overrideLocalStorageKey }; - const result = nodalsAiRtdSubmodule.init(config, permissiveUserConsent); - server.respond(); - - expect(result).to.be.true; - expect(server.requests.length).to.equal(1); - }); - }); - - describe('when performing requests to the publisher endpoint', () => { - it('should construct the correct URL to the default origin', () => { - nodalsAiRtdSubmodule.init(validConfig, permissiveUserConsent); - const request = server.requests[0]; - server.respond(); - - expect(request.method).to.equal('GET'); - expect(request.withCredentials).to.be.false; - const requestUrl = new URL(request.url); - expect(requestUrl.origin).to.equal('https://nodals.io'); - }); - - it('should construct the URL to the overridden origin when specified in the config', () => { - const config = Object.assign({}, validConfig); - config.params.endpoint = { origin: 'http://localhost:8000' }; - nodalsAiRtdSubmodule.init(config, permissiveUserConsent); - const request = server.requests[0]; - server.respond(); - - expect(request.method).to.equal('GET'); - expect(request.withCredentials).to.be.false; - const requestUrl = new URL(request.url); - expect(requestUrl.origin).to.equal('http://localhost:8000'); - }); - - it('should construct the correct URL with the correct path', () => { - nodalsAiRtdSubmodule.init(validConfig, permissiveUserConsent); - const request = server.requests[0]; - server.respond(); - - const requestUrl = new URL(request.url); - expect(requestUrl.pathname).to.equal('/p/v1/10312dd2/config'); - }); - - it('should construct the correct URL with the correct GDPR query params', () => { - const consentData = { - consentString: 'foobarbaz', - }; - nodalsAiRtdSubmodule.init(validConfig, generateGdprConsent(consentData)); - const request = server.requests[0]; - server.respond(); - - const requestUrl = new URL(request.url); - expect(requestUrl.searchParams.get('gdpr')).to.equal('1'); - expect(requestUrl.searchParams.get('gdpr_consent')).to.equal( - 'foobarbaz' - ); - expect(requestUrl.searchParams.get('us_privacy')).to.equal(''); - expect(requestUrl.searchParams.get('gpp')).to.equal(''); - expect(requestUrl.searchParams.get('gpp_sid')).to.equal(''); - }); - }); - - describe('when handling responses from the publisher endpoint', () => { - it('should store successful response data in local storage', () => { - nodalsAiRtdSubmodule.init(validConfig, permissiveUserConsent); - const request = server.requests[0]; - server.respond(); - - const storedData = JSON.parse( - nodalsAiRtdSubmodule.storage.getDataFromLocalStorage( - nodalsAiRtdSubmodule.STORAGE_KEY - ) - ); - - expect(request.method).to.equal('GET'); - expect(storedData).to.have.property('createdAt'); - expect(storedData.data).to.deep.equal(successPubEndpointResponse); - }); - - it('should store successful response data in local storage under the override key', () => { - const config = Object.assign({}, validConfig); - config.params.storage = { key: overrideLocalStorageKey }; - nodalsAiRtdSubmodule.init(config, permissiveUserConsent); - server.respond(); - const request = server.requests[0]; - const storedData = JSON.parse( - nodalsAiRtdSubmodule.storage.getDataFromLocalStorage(overrideLocalStorageKey) - ); - - expect(request.method).to.equal('GET'); - expect(storedData).to.have.property('createdAt'); - expect(storedData.data).to.deep.equal(successPubEndpointResponse); - }); - - it('should attempt to load the referenced script libraries contained in the response payload', () => { - nodalsAiRtdSubmodule.init(validConfig, permissiveUserConsent); - server.respond(); - - expect(loadExternalScriptStub.calledTwice).to.be.true; - expect( - loadExternalScriptStub.calledWith( - successPubEndpointResponse.deps['1.0.0'], - MODULE_TYPE_RTD, - nodalsAiRtdSubmodule.name - ) - ).to.be.true; - expect( - loadExternalScriptStub.calledWith( - successPubEndpointResponse.deps['1.1.0'], - MODULE_TYPE_RTD, - nodalsAiRtdSubmodule.name - ) - ).to.be.true; - }); - }); - }); - - describe('getTargetingData()', () => { - it('should return an empty object when no data is available in local storage, but fetch data', () => { - const result = nodalsAiRtdSubmodule.getTargetingData( - ['adUnit1'], - validConfig, - permissiveUserConsent - ); - server.respond(); - expect(result).to.deep.equal({}); - expect(server.requests.length).to.equal(1); - }); - - it('should return an empty object when getTargetingData throws error', () => { - createTargetingEngineStub({adUnit1: {someKey: 'someValue'}}, true); - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - - const result = nodalsAiRtdSubmodule.getTargetingData( - ['adUnit1'], - validConfig, - permissiveUserConsent - ); - expect(result).to.deep.equal({}); - expect(server.requests.length).to.equal(0); - }); - - it('should initialise the versioned targeting engine if fresh data is in storage and not make a HTTP request', () => { - const returnData = {}; - const engine = createTargetingEngineStub(returnData); - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - - nodalsAiRtdSubmodule.getTargetingData( - ['adUnit1'], - validConfig, - permissiveUserConsent - ); - server.respond(); - - expect(engine.init.called).to.be.true; - const args = engine.init.getCall(0).args; - expect(args[0]).to.deep.equal(validConfig); - expect(server.requests.length).to.equal(0); - }); - - it('should initialise the versioned targeting engine with stale data if data expired and fetch fresh data', function () { - const returnData = {}; - const engine = createTargetingEngineStub(returnData); - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: 100, - }); - - nodalsAiRtdSubmodule.getTargetingData( - ['adUnit1'], - validConfig, - permissiveUserConsent - ); - server.respond(); - - expect(engine.init.called).to.be.true; - const args = engine.init.getCall(0).args; - expect(args[0]).to.deep.equal(validConfig); - expect(server.requests.length).to.equal(1); - }); - - it('should proxy the correct data to engine.getTargetingData() when storage data is available and we have consent under GDPR jurisdiction', () => { - const engine = createTargetingEngineStub( - engineGetTargetingDataReturnValue - ); - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - - nodalsAiRtdSubmodule.getTargetingData( - ['adUnit1', 'adUnit2'], - validConfig, - permissiveUserConsent - ); - server.respond(); - - expect(engine.getTargetingData.called).to.be.true; - const args = engine.getTargetingData.getCall(0).args; - expect(args[0]).to.deep.equal(['adUnit1', 'adUnit2']); - expect(args[1]).to.deep.equal(permissiveUserConsent); - - expect(args[2].deps).to.deep.equal(successPubEndpointResponse.deps); - expect(args[2].facts).to.deep.include(successPubEndpointResponse.facts); - expect(args[2].campaigns).to.deep.equal(successPubEndpointResponse.campaigns); - }); - - it('should return the data from engine.getTargetingData when storage data is available and we have consent under GDPR jurisdiction', () => { - createTargetingEngineStub(engineGetTargetingDataReturnValue); - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - - const result = nodalsAiRtdSubmodule.getTargetingData( - ['adUnit1'], - validConfig, - permissiveUserConsent - ); - server.respond(); - - expect(result).to.deep.equal(engineGetTargetingDataReturnValue); - }); - - it('should return the data from engine.getTargetingData when storage is available and we are NOT under GDPR jurisdiction', () => { - createTargetingEngineStub(engineGetTargetingDataReturnValue); - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - - const result = nodalsAiRtdSubmodule.getTargetingData( - ['adUnit1'], - validConfig, - outsideGdprUserConsent - ); - server.respond(); - - expect(result).to.deep.equal(engineGetTargetingDataReturnValue); - }); - - it('should return an empty object when data is available, but user has not provided consent to Nodals AI as a vendor', () => { - createTargetingEngineStub(engineGetTargetingDataReturnValue); - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - - const result = nodalsAiRtdSubmodule.getTargetingData( - ['adUnit1'], - validConfig, - vendorRestrictiveUserConsent - ); - server.respond(); - - expect(result).to.deep.equal({}); - }); - }); - - describe('getBidRequestData()', () => { - it('should invoke callback without attempting to initialise the engine if we do not have consent', () => { - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - const engine = createTargetingEngineStub(); - const customUserConsent = generateGdprConsent({ nodalsConsent: false }); - const callback = sinon.spy(); - nodalsAiRtdSubmodule.getBidRequestData( - {}, callback, validConfig, vendorRestrictiveUserConsent - ); - server.respond(); - - expect(callback.called).to.be.true; - expect(engine.init.called).to.be.false; - expect(window.$nodals.cmdQueue).to.be.undefined - expect(server.requests.length).to.equal(0); - }); - - it('should not store function arguments in a queue when no data is in localstorage and make a HTTP request for data', () => { - const callback = sinon.spy(); - const requestObj = {dummy: 'obj'} - nodalsAiRtdSubmodule.getBidRequestData( - requestObj, callback, validConfig, permissiveUserConsent - ); - server.respond(); - - expect(callback.called).to.be.true; - expect(window.$nodals).to.be.undefined; - expect(server.requests.length).to.equal(1); - }); - - it('should store function arguments in a queue when data is in localstorage and engine not loaded', () => { - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - const callback = sinon.spy(); - const reqBidsConfigObj = {dummy: 'obj'} - nodalsAiRtdSubmodule.getBidRequestData( - reqBidsConfigObj, callback, validConfig, permissiveUserConsent - ); - server.respond(); - - expect(callback.called).to.be.false; - expect(window.$nodals.cmdQueue).to.be.an('array').with.length(1); - expect(window.$nodals.cmdQueue[0].cmd).to.equal('getBidRequestData'); - expect(window.$nodals.cmdQueue[0].runtimeFacts).to.have.keys(['prebid.version', 'page.url']); - expect(window.$nodals.cmdQueue[0].data).to.deep.include({config: validConfig, reqBidsConfigObj, callback, userConsent: permissiveUserConsent}); - expect(window.$nodals.cmdQueue[0].data.storedData).to.have.property('deps').that.deep.equals( - successPubEndpointResponse.deps); - expect(window.$nodals.cmdQueue[0].data.storedData).to.have.property('facts').that.deep.includes( - successPubEndpointResponse.facts); - expect(window.$nodals.cmdQueue[0].data.storedData).to.have.property('campaigns').that.deep.equals( - successPubEndpointResponse.campaigns); - expect(server.requests.length).to.equal(0); - }); - - it('should proxy the correct data to engine.getBidRequestData when data is in localstorage and library has loaded', () => { - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - const engine = createTargetingEngineStub(); - const callback = sinon.spy(); - const reqBidsConfigObj = {dummy: 'obj'} - nodalsAiRtdSubmodule.getBidRequestData( - reqBidsConfigObj, callback, validConfig, permissiveUserConsent - ); - server.respond(); - - expect(callback.called).to.be.false; - expect(engine.init.called).to.be.true; - expect(engine.getBidRequestData.called).to.be.true; - const args = engine.getBidRequestData.getCall(0).args; - expect(args[0]).to.deep.equal(reqBidsConfigObj); - expect(args[1]).to.deep.equal(callback); - expect(args[2]).to.deep.equal(permissiveUserConsent); - expect(args[3].deps).to.deep.equal(successPubEndpointResponse.deps); - expect(args[3].facts).to.deep.include(successPubEndpointResponse.facts); - expect(args[3].campaigns).to.deep.equal(successPubEndpointResponse.campaigns); - expect(server.requests.length).to.equal(0); - }); - }); - - describe('onBidResponseEvent()', () => { - it('should not proxy the call if we do not have user consent', () => { - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - const engine = createTargetingEngineStub(); - const bidResponse = {dummy: 'obj', 'bid': 'foo'}; - nodalsAiRtdSubmodule.onBidResponseEvent( - bidResponse, validConfig, vendorRestrictiveUserConsent - ); - server.respond(); - - expect(engine.init.called).to.be.false; - expect(engine.onBidResponseEvent.called).to.be.false; - expect(window.$nodals.cmdQueue).to.be.undefined - expect(server.requests.length).to.equal(0); - }); - - it('should not store function arguments in a queue when no data is in localstorage and make a HTTP request for data', () => { - const bidResponse = {dummy: 'obj', 'bid': 'foo'}; - nodalsAiRtdSubmodule.onBidResponseEvent( - bidResponse, validConfig, permissiveUserConsent - ); - server.respond(); - - expect(window.$nodals).to.be.undefined; - expect(server.requests.length).to.equal(1); - }); - - it('should store function arguments in a queue when data is in localstorage and engine not loaded', () => { - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - const userConsent = generateGdprConsent(); - const bidResponse = {dummy: 'obj', 'bid': 'foo'}; - nodalsAiRtdSubmodule.onBidResponseEvent( - bidResponse, validConfig, permissiveUserConsent - ); - server.respond(); - - expect(window.$nodals.cmdQueue).to.be.an('array').with.length(1); - expect(window.$nodals.cmdQueue[0].cmd).to.equal('onBidResponseEvent'); - expect(window.$nodals.cmdQueue[0].runtimeFacts).to.have.keys(['prebid.version', 'page.url']); - expect(window.$nodals.cmdQueue[0].data).to.deep.include({config: validConfig, bidResponse, userConsent: permissiveUserConsent }); - expect(window.$nodals.cmdQueue[0].data.storedData).to.have.property('deps').that.deep.equals( - successPubEndpointResponse.deps); - expect(window.$nodals.cmdQueue[0].data.storedData).to.have.property('facts').that.deep.includes( - successPubEndpointResponse.facts); - expect(window.$nodals.cmdQueue[0].data.storedData).to.have.property('campaigns').that.deep.equals( - successPubEndpointResponse.campaigns); - expect(server.requests.length).to.equal(0); - }); - - it('should proxy the correct data to engine.onBidResponseEvent when data is in localstorage and library has loaded', () => { - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - const engine = createTargetingEngineStub(); - const bidResponse = {dummy: 'obj', 'bid': 'foo'}; - nodalsAiRtdSubmodule.onBidResponseEvent( - bidResponse, validConfig, permissiveUserConsent - ); - server.respond(); - - expect(engine.init.called).to.be.true; - expect(engine.onBidResponseEvent.called).to.be.true; - const args = engine.onBidResponseEvent.getCall(0).args; - expect(args[0]).to.deep.equal(bidResponse); - expect(args[1]).to.deep.equal(permissiveUserConsent); - expect(args[2].deps).to.deep.equal(successPubEndpointResponse.deps); - expect(args[2].facts).to.deep.include(successPubEndpointResponse.facts); - expect(args[2].campaigns).to.deep.equal(successPubEndpointResponse.campaigns); - expect(server.requests.length).to.equal(0); - }); - }); - - describe('onAuctionEndEvent()', () => { - it('should not proxy the call if we do not have user consent', () => { - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - const engine = createTargetingEngineStub(); - const auctionDetails = {dummy: 'obj', auction: 'foo'}; - nodalsAiRtdSubmodule.onAuctionEndEvent( - auctionDetails, validConfig, vendorRestrictiveUserConsent - ); - server.respond(); - - expect(engine.init.called).to.be.false; - expect(engine.onAuctionEndEvent.called).to.be.false; - expect(window.$nodals.cmdQueue).to.be.undefined - expect(server.requests.length).to.equal(0); - }); - - it('should not store function arguments in a queue when no data is in localstorage and make a HTTP request for data', () => { - const auctionDetails = {dummy: 'obj', auction: 'foo'}; - nodalsAiRtdSubmodule.onAuctionEndEvent( - auctionDetails, validConfig, permissiveUserConsent - ); - server.respond(); - - expect(window.$nodals).to.be.undefined; - expect(server.requests.length).to.equal(1); - }); - - it('should store function arguments in a queue when data is in localstorage and engine not loaded', () => { - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - const auctionDetails = {dummy: 'obj', auction: 'foo'}; - nodalsAiRtdSubmodule.onAuctionEndEvent( - auctionDetails, validConfig, permissiveUserConsent - ); - server.respond(); - - expect(window.$nodals.cmdQueue).to.be.an('array').with.length(1); - expect(window.$nodals.cmdQueue[0].cmd).to.equal('onAuctionEndEvent'); - expect(window.$nodals.cmdQueue[0].runtimeFacts).to.have.keys(['prebid.version', 'page.url']); - expect(window.$nodals.cmdQueue[0].data).to.deep.include({config: validConfig, auctionDetails, userConsent: permissiveUserConsent }); - expect(window.$nodals.cmdQueue[0].data.storedData).to.have.property('deps').that.deep.equals( - successPubEndpointResponse.deps); - expect(window.$nodals.cmdQueue[0].data.storedData).to.have.property('facts').that.deep.includes( - successPubEndpointResponse.facts); - expect(window.$nodals.cmdQueue[0].data.storedData).to.have.property('campaigns').that.deep.equals( - successPubEndpointResponse.campaigns); - expect(server.requests.length).to.equal(0); - }); - - it('should proxy the correct data to engine.onAuctionEndEvent when data is in localstorage and library has loaded', () => { - setDataInLocalStorage({ - data: successPubEndpointResponse, - createdAt: Date.now(), - }); - const engine = createTargetingEngineStub(); - const userConsent = generateGdprConsent(); - const auctionDetails = {dummy: 'obj', auction: 'foo'}; - nodalsAiRtdSubmodule.onAuctionEndEvent( - auctionDetails, validConfig, permissiveUserConsent - ); - server.respond(); - - expect(engine.init.called).to.be.true; - expect(engine.onAuctionEndEvent.called).to.be.true; - const args = engine.onAuctionEndEvent.getCall(0).args; - expect(args[0]).to.deep.equal(auctionDetails); - expect(args[1]).to.deep.equal(permissiveUserConsent); - expect(args[2].deps).to.deep.equal(successPubEndpointResponse.deps); - expect(args[2].facts).to.deep.include(successPubEndpointResponse.facts); - expect(args[2].campaigns).to.deep.equal(successPubEndpointResponse.campaigns); - expect(server.requests.length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/oftmediaRtdProvider_spec.js b/test/spec/modules/oftmediaRtdProvider_spec.js deleted file mode 100644 index c8b43b148..000000000 --- a/test/spec/modules/oftmediaRtdProvider_spec.js +++ /dev/null @@ -1,437 +0,0 @@ -import { - config -} from 'src/config.js'; -import * as oftmediaRtd from 'modules/oftmediaRtdProvider.js'; -import { - loadExternalScriptStub -} from 'test/mocks/adloaderStub.js'; -import * as userAgentUtils from '../../../libraries/userAgentUtils/index.js'; - -const RTD_CONFIG = { - dataProviders: [{ - name: 'oftmedia', - waitForIt: true, - params: { - publisherId: '0653b3fc-a645-4bcc-bfee-b8982974dd53', - keywords: ['red', 'blue', 'white'], - bidderCode: 'appnexus', - enrichRequest: true - }, - }, ], -}; - -const TIMEOUT = 10; - -describe('oftmedia RTD Submodule', function() { - let sandbox; - let loadExternalScriptTag; - let localStorageIsEnabledStub; - let clock; - - beforeEach(function() { - sandbox = sinon.createSandbox(); - clock = sandbox.useFakeTimers(); - config.resetConfig(); - - loadExternalScriptTag = document.createElement('script'); - - loadExternalScriptStub.callsFake((_url, _moduleName, _type, callback) => { - if (typeof callback === 'function') { - setTimeout(callback, 10); - } - - setTimeout(() => { - if (loadExternalScriptTag.onload) { - loadExternalScriptTag.onload(); - } - loadExternalScriptTag.dispatchEvent(new Event('load')); - }, 10); - - return loadExternalScriptTag; - }); - - localStorageIsEnabledStub = sandbox.stub(oftmediaRtd.storageManager, 'localStorageIsEnabled'); - localStorageIsEnabledStub.callsFake((cback) => cback(true)); - - sandbox.stub(userAgentUtils, 'getDeviceType').returns(1); - sandbox.stub(userAgentUtils, 'getOS').returns(1); - sandbox.stub(userAgentUtils, 'getBrowser').returns(2); - - if (oftmediaRtd.__testing__.moduleState && typeof oftmediaRtd.__testing__.moduleState.reset === 'function') { - oftmediaRtd.__testing__.moduleState.reset(); - } - }); - - afterEach(function() { - sandbox.restore(); - clock.restore(); - }); - - describe('Module initialization', function() { - it('should initialize and return true when publisherId is provided', function() { - const result = oftmediaRtd.oftmediaRtdSubmodule.init(RTD_CONFIG.dataProviders[0]); - expect(result).to.equal(true); - }); - - it('should return false when publisherId is not provided', function() { - const invalidConfig = { - params: { - bidderCode: 'appnexus', - enrichRequest: true - } - }; - const result = oftmediaRtd.oftmediaRtdSubmodule.init(invalidConfig); - expect(result).to.equal(false); - }); - - it('should return false when publisherId is not a string', function() { - const invalidConfig = { - params: { - publisherId: 12345, - bidderCode: 'appnexus', - enrichRequest: true - } - }; - const result = oftmediaRtd.oftmediaRtdSubmodule.init(invalidConfig); - expect(result).to.equal(false); - }); - - it('should set initTimestamp when initialized', function() { - const result = oftmediaRtd.oftmediaRtdSubmodule.init(RTD_CONFIG.dataProviders[0]); - expect(result).to.equal(true); - expect(oftmediaRtd.__testing__.moduleState.initTimestamp).to.be.a('number'); - }); - }); - - describe('ModuleState class functionality', function() { - it('should mark module as ready and execute callbacks', function() { - const moduleState = oftmediaRtd.__testing__.moduleState; - const callbackSpy = sinon.spy(); - - moduleState.onReady(callbackSpy); - expect(callbackSpy.called).to.be.false; - - moduleState.markReady(); - expect(callbackSpy.calledOnce).to.be.true; - - const secondCallbackSpy = sinon.spy(); - moduleState.onReady(secondCallbackSpy); - expect(secondCallbackSpy.calledOnce).to.be.true; - }); - - it('should reset module state properly', function() { - const moduleState = oftmediaRtd.__testing__.moduleState; - - moduleState.initTimestamp = 123; - moduleState.scriptLoadPromise = Promise.resolve(); - moduleState.isReady = true; - - moduleState.reset(); - - expect(moduleState.initTimestamp).to.be.null; - expect(moduleState.scriptLoadPromise).to.be.null; - expect(moduleState.isReady).to.be.false; - expect(moduleState.readyCallbacks).to.be.an('array').that.is.empty; - }); - }); - - describe('Helper functions', function() { - it('should create a timeout promise that resolves after specified time', function(done) { - let promiseResolved = false; - - oftmediaRtd.oftmediaRtdSubmodule.init(RTD_CONFIG.dataProviders[0]); - - const testPromise = new Promise(resolve => { - setTimeout(() => { - promiseResolved = true; - resolve('test-result'); - }, 100); - }); - - const racePromise = oftmediaRtd.__testing__.raceWithTimeout(testPromise, 50); - - racePromise.then(result => { - expect(promiseResolved).to.be.false; - expect(result).to.be.undefined; - done(); - }).catch(done); - - clock.tick(60); - }); - - it('should create a timeout promise that resolves with undefined after specified time', function(done) { - const neverResolvingPromise = new Promise(() => {}); - - const raceWithTimeout = oftmediaRtd.__testing__.raceWithTimeout; - const result = raceWithTimeout(neverResolvingPromise, 200); - - let resolved = false; - - result.then(value => { - resolved = true; - expect(value).to.be.undefined; - done(); - }).catch(done); - - expect(resolved).to.be.false; - clock.tick(100); - expect(resolved).to.be.false; - - clock.tick(150); - }); - - it('should return promise result when promise resolves before timeout', function(done) { - const raceWithTimeout = oftmediaRtd.__testing__.raceWithTimeout; - const fastPromise = Promise.resolve('success-result'); - - const result = raceWithTimeout(fastPromise, 100); - - result.then(value => { - expect(value).to.equal('success-result'); - done(); - }).catch(done); - - clock.tick(10); - }); - - it('should handle rejecting promises correctly', function(done) { - const raceWithTimeout = oftmediaRtd.__testing__.raceWithTimeout; - const rejectingPromise = Promise.reject(new Error('expected rejection')); - - const result = raceWithTimeout(rejectingPromise, 100); - - result.then(() => { - done(new Error('Promise should have been rejected')); - }).catch(error => { - expect(error.message).to.equal('expected rejection'); - done(); - }); - - clock.tick(10); - }); - - it('should calculate remaining time correctly', function() { - const calculateRemainingTime = oftmediaRtd.__testing__.calculateRemainingTime; - - const startTime = Date.now() - 300; - const maxDelay = 1000; - - const result = calculateRemainingTime(startTime, maxDelay); - - expect(result).to.be.closeTo(400, 10); - - const lateStartTime = Date.now() - 800; - const lateResult = calculateRemainingTime(lateStartTime, maxDelay); - expect(lateResult).to.equal(0); - }); - - it('should convert device types for specific bidders', function() { - const convertDeviceTypeForBidder = oftmediaRtd.__testing__.convertDeviceTypeForBidder; - - expect(convertDeviceTypeForBidder(0, 'oftmedia')).to.equal(2); - expect(convertDeviceTypeForBidder(1, 'oftmedia')).to.equal(4); - expect(convertDeviceTypeForBidder(2, 'oftmedia')).to.equal(5); - expect(convertDeviceTypeForBidder(1, 'appnexus')).to.equal(4); - expect(convertDeviceTypeForBidder(1, 'pubmatic')).to.equal(1); - expect(convertDeviceTypeForBidder(99, 'oftmedia')).to.equal(99); - expect(convertDeviceTypeForBidder("1", 'oftmedia')).to.equal(4); - }); - }); - - describe('Script loading functionality', function() { - it('should load script successfully with valid publisher ID', function(done) { - localStorageIsEnabledStub.callsFake(cback => cback(true)); - - const loadOftmediaScript = oftmediaRtd.__testing__.loadOftmediaScript; - - const scriptPromise = loadOftmediaScript(RTD_CONFIG.dataProviders[0]); - - scriptPromise.then(result => { - expect(result).to.be.true; - done(); - }).catch(done); - - clock.tick(20); - }); - - it('should reject when localStorage is not available', function(done) { - localStorageIsEnabledStub.callsFake(cback => cback(false)); - - const loadOftmediaScript = oftmediaRtd.__testing__.loadOftmediaScript; - - const scriptPromise = loadOftmediaScript(RTD_CONFIG.dataProviders[0]); - - scriptPromise.then(() => { - done(new Error('Promise should be rejected when localStorage is not available')); - }).catch(error => { - expect(error.message).to.include('localStorage is not available'); - done(); - }); - - clock.tick(20); - }); - - it('should reject when publisher ID is missing', function(done) { - const loadOftmediaScript = oftmediaRtd.__testing__.loadOftmediaScript; - - const scriptPromise = loadOftmediaScript({ - params: {} - }); - - scriptPromise.then(() => { - done(new Error('Promise should be rejected when publisher ID is missing')); - }).catch(error => { - expect(error.message).to.include('Publisher ID is required'); - done(); - }); - - clock.tick(20); - }); - }); - - describe('ORTB2 data building', function() { - it('should build valid ORTB2 data object with device and keywords', function() { - const buildOrtb2Data = oftmediaRtd.__testing__.buildOrtb2Data; - - const result = buildOrtb2Data(RTD_CONFIG.dataProviders[0]); - - expect(result).to.be.an('object'); - expect(result.bidderCode).to.equal('appnexus'); - expect(result.ortb2Data).to.be.an('object'); - expect(result.ortb2Data.device.devicetype).to.equal(4); - expect(result.ortb2Data.device.os).to.equal('1'); - expect(result.ortb2Data.site.keywords).to.include('red'); - expect(result.ortb2Data.site.keywords).to.include('blue'); - expect(result.ortb2Data.site.keywords).to.include('white'); - expect(result.ortb2Data.site.keywords).to.include('deviceBrowser=2'); - }); - - it('should return null when enrichRequest is false', function() { - const buildOrtb2Data = oftmediaRtd.__testing__.buildOrtb2Data; - - const result = buildOrtb2Data({ - params: { - publisherId: '0653b3fc-a645-4bcc-bfee-b8982974dd53', - bidderCode: 'appnexus', - enrichRequest: false - } - }); - - expect(result).to.be.null; - }); - - it('should return null when bidderCode is missing', function() { - const buildOrtb2Data = oftmediaRtd.__testing__.buildOrtb2Data; - - const result = buildOrtb2Data({ - params: { - publisherId: '0653b3fc-a645-4bcc-bfee-b8982974dd53', - enrichRequest: true - } - }); - - expect(result).to.be.null; - }); - }); - - describe('Bid request processing', function() { - it('should process bid request and enrich it with ORTB2 data', function(done) { - oftmediaRtd.oftmediaRtdSubmodule.init(RTD_CONFIG.dataProviders[0]); - - oftmediaRtd.__testing__.moduleState.markReady(); - - const bidConfig = { - ortb2Fragments: { - bidder: { - appnexus: {} - } - } - }; - - oftmediaRtd.oftmediaRtdSubmodule.getBidRequestData(bidConfig, () => { - expect(bidConfig.ortb2Fragments.bidder.appnexus.device).to.be.an('object'); - expect(bidConfig.ortb2Fragments.bidder.appnexus.device.devicetype).to.equal(4); - expect(bidConfig.ortb2Fragments.bidder.appnexus.device.os).to.equal('1'); - expect(bidConfig.ortb2Fragments.bidder.appnexus.site.keywords).to.include('deviceBrowser=2'); - done(); - }, RTD_CONFIG.dataProviders[0]); - }); - - it('should handle invalid bid request structure', function(done) { - oftmediaRtd.oftmediaRtdSubmodule.init(RTD_CONFIG.dataProviders[0]); - oftmediaRtd.__testing__.moduleState.markReady(); - const invalidBidConfig = {}; - - oftmediaRtd.oftmediaRtdSubmodule.getBidRequestData(invalidBidConfig, () => { - expect(invalidBidConfig.ortb2Fragments).to.be.undefined; - done(); - }, RTD_CONFIG.dataProviders[0]); - }); - }); - - describe('Bid request enrichment', function() { - it('should enrich bid request with keywords, OS and device when enrichRequest is true', function(done) { - const bidConfig = { - ortb2Fragments: { - bidder: { - appnexus: {} - } - } - }; - - const initResult = oftmediaRtd.oftmediaRtdSubmodule.init(RTD_CONFIG.dataProviders[0]); - expect(initResult).to.equal(true); - - oftmediaRtd.__testing__.moduleState.markReady(); - - oftmediaRtd.oftmediaRtdSubmodule.getBidRequestData(bidConfig, function(error) { - if (error) return done(error); - - try { - expect(bidConfig.ortb2Fragments.bidder.appnexus).to.have.nested.property('site.keywords'); - expect(bidConfig.ortb2Fragments.bidder.appnexus.device).to.be.an('object'); - expect(bidConfig.ortb2Fragments.bidder.appnexus.device.devicetype).to.equal(4); - expect(bidConfig.ortb2Fragments.bidder.appnexus.device.os).to.equal('1'); - done(); - } catch (e) { - done(e); - } - }, RTD_CONFIG.dataProviders[0]); - }); - - it('should not enrich bid request when enrichRequest is false', function(done) { - const configWithEnrichFalse = { - params: { - publisherId: '0653b3fc-a645-4bcc-bfee-b8982974dd53', - keywords: ['red', 'blue', 'white'], - bidderCode: 'appnexus', - enrichRequest: false - } - }; - - const bidConfig = { - ortb2Fragments: { - bidder: { - appnexus: {} - } - } - }; - - const initResult = oftmediaRtd.oftmediaRtdSubmodule.init(configWithEnrichFalse); - expect(initResult).to.equal(true); - - oftmediaRtd.__testing__.moduleState.markReady(); - - oftmediaRtd.oftmediaRtdSubmodule.getBidRequestData(bidConfig, function(error) { - if (error) return done(error); - - try { - expect(bidConfig.ortb2Fragments.bidder.appnexus).to.deep.equal({}); - done(); - } catch (e) { - done(e); - } - }, configWithEnrichFalse); - }); - }); -}); diff --git a/test/spec/modules/oguryBidAdapter_spec.js b/test/spec/modules/oguryBidAdapter_spec.js deleted file mode 100644 index f6922f709..000000000 --- a/test/spec/modules/oguryBidAdapter_spec.js +++ /dev/null @@ -1,1039 +0,0 @@ -import { expect } from 'chai'; -import sinon from 'sinon'; -import { spec, ortbConverterProps } from 'modules/oguryBidAdapter'; -import * as utils from 'src/utils.js'; -import { server } from '../../mocks/xhr.js'; - -const BID_URL = 'https://mweb-hb.presage.io/api/header-bidding-request'; -const TIMEOUT_URL = 'https://ms-ads-monitoring-events.presage.io/bid_timeout' - -describe('OguryBidAdapter', () => { - let bidRequests, bidderRequestBase, ortb2; - - const currentLocation = 'https://mwtt.ogury.tech/advanced'; - - bidRequests = [ - { - adUnitCode: 'adUnitCode', - ortb2Imp: { - ext: { - gpid: 'gpid' - } - }, - auctionId: 'auctionId', - bidId: 'bidId', - bidder: 'ogury', - params: { - assetKey: 'OGY-assetkey', - adUnitId: 'adunitId', - xMargin: 20, - yMarging: 20, - gravity: 'TOP_LEFT', - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - getFloor: ({ size, currency, mediaType }) => { - const floorResult = { - currency: 'USD', - floor: 0 - }; - - if (mediaType === 'banner') { - floorResult.floor = 4; - } else { - floorResult.floor = 1000; - } - - return floorResult; - }, - transactionId: 'transactionId', - userId: { pubcid: 'f5debac9-9a8e-4c08-9820-51e96b69f858' } - }, - { - adUnitCode: 'adUnitCode2', - auctionId: 'auctionId', - bidId: 'bidId2', - bidder: 'ogury', - params: { - assetKey: 'OGY-assetkey', - adUnitId: 'adunitId2' - }, - mediaTypes: { - banner: { - sizes: [[600, 500]] - } - }, - transactionId: 'transactionId2' - }, - ]; - - ortb2 = { - regs: { - gpp_sid: [7], - gpp: 'DBABLA~BAAAAAAAAQA.QA', - ext: { gdpr: 1 } - }, - site: { - domain: 'mwtt.ogury.tech', - publisher: { domain: 'ogury.tech', id: 'ca06d4199b92bf6808e5ce15b28c6d30' }, - page: currentLocation, - ref: 'https://google.com' - }, - user: { - ext: { - consent: 'CQJI3tqQJI3tqFzABBENBJFsAP_gAEPgAAqIg1NX_H__bW9r8Xr3aft0eY1P99j77sQxBhfJE-4FyLvW_JwXx2EwNA26tqIKmRIEu3ZBIQFlHJHURVigaogVryHsYkGcgTNKJ6BkgFMRI2dYCF5vmYtj-QKY5_p_d3fx2D-t_dv83dzzz8VHn3e5fmckcKCdQ58tDfn9bRKb-5IO9-78v4v09l_rk2_eTVn_pcvr7B-uft87_XU-9_fAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEQagCzDQqIA-yJCQi0DCKBACIKwgIoEAAAAJA0QEAJAwKdgYBLrCRACBFAAMEAIAAUZAAgAAEgAQiACQAoEAAEAgEAAAAAAgEADAwADgAtBAIAAQHQMUwoAFAsIEiMiIUwIQoEggJbKBBICgQVwgCLDAigERMFAAgCQAVgAAAsVgMASAlYkECWUG0AABAAgFFKFQik6MAQwJmy1U4om0AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAACAA.YAAAAAAAAAAA', - eids: [ - { - source: 'pubcid.org', - uids: [{ 'id': 'f5debac9-9a8e-4c08-9820-51e96b69f858', 'atype': 1 }] - } - ] - } - }, - device: { - w: 412, - h: 915, - dnt: 0, - ua: 'Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36', - language: 'en', - ext: { vpw: 412, vph: 915 }, - sua: { - source: 1, - platform: { brand: 'Android' }, - browsers: [{ brand: 'Google Chrome', version: ['131'] }], - mobile: 1 - } - } - }; - - bidderRequestBase = { - bids: bidRequests, - bidderRequestId: 'mock-uuid', - auctionId: bidRequests[0].auctionId, - gdprConsent: {consentString: 'myConsentString', vendorData: {}, gdprApplies: true}, - gppConsent: {gppString: 'myGppString', gppData: {}, applicableSections: [7], parsedSections: {}}, - timeout: 1000, - ortb2 - }; - - describe('isBidRequestValid', () => { - it('should validate correct bid', () => { - const validBid = utils.deepClone(bidRequests[0]); - - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.true; - }); - - it('should not validate when sizes is not defined', () => { - const invalidBid = utils.deepClone(bidRequests[0]); - delete invalidBid.sizes; - delete invalidBid.mediaTypes; - - const isValid = spec.isBidRequestValid(invalidBid); - expect(isValid).to.be.false; - }); - - it('should not validate bid when adunit is not defined', () => { - const invalidBid = utils.deepClone(bidRequests[0]); - delete invalidBid.params.adUnitId; - - const isValid = spec.isBidRequestValid(invalidBid); - expect(isValid).to.to.be.false; - }); - - it('should not validate bid when assetKey is not defined', () => { - const invalidBid = utils.deepClone(bidRequests[0]); - delete invalidBid.params.assetKey; - - const isValid = spec.isBidRequestValid(invalidBid); - expect(isValid).to.be.false; - }); - - it('should validate the request when only publisherId and adUnitCode is defined', () => { - const validBid = utils.deepClone(bidRequests[0]) - delete validBid.params.adUnitId - delete validBid.params.assetKey - - validBid.ortb2 = { site: { publisher: { id: 'publisherId' } } } - - expect(spec.isBidRequestValid(validBid)).to.be.true - }); - - it('should not validate the request when only publisherId is defined', () => { - const invalidBid = utils.deepClone(bidRequests[0]) - delete invalidBid.params.adUnitId - delete invalidBid.params.assetKey - delete invalidBid.adUnitCode - - invalidBid.ortb2 = { site: { publisher: { id: 'publisherId' } } } - - expect(spec.isBidRequestValid(invalidBid)).to.be.false - }); - - it('should not validate the request when only adUnitCode is defined', () => { - const invalidBid = utils.deepClone(bidRequests[0]) - delete invalidBid.params.adUnitId - delete invalidBid.params.assetKey - - expect(spec.isBidRequestValid(invalidBid)).to.be.false - }); - }); - - describe('getUserSyncs', () => { - let syncOptions, gdprConsent, gppConsent; - - beforeEach(() => { - gdprConsent = { - gdprApplies: true, - consentString: 'CPJl4C8PJl4C8OoAAAENAwCMAP_AAH_AAAAAAPgAAAAIAPgAAAAIAAA.IGLtV_T9fb2vj-_Z99_tkeYwf95y3p-wzhheMs-8NyZeH_B4Wv2MyvBX4JiQKGRgksjLBAQdtHGlcTQgBwIlViTLMYk2MjzNKJrJEilsbO2dYGD9Pn8HT3ZCY70-vv__7v3ff_3g' - }; - gppConsent = { - gppString: 'DBABLA~BAAAAAAAAQA.QA', - applicableSections: [7] - } - }); - - describe('pixel', () => { - beforeEach(() => { - syncOptions = { pixelEnabled: true }; - }); - - it('should return syncs array with three elements of type image', () => { - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - - expect(userSyncs).to.have.lengthOf(3); - expect(userSyncs[0].type).to.equal('image'); - expect(userSyncs[0].url).to.contain('https://ms-cookie-sync.presage.io/v1/init-sync/bid-switch'); - expect(userSyncs[1].type).to.equal('image'); - expect(userSyncs[1].url).to.contain('https://ms-cookie-sync.presage.io/ttd/init-sync'); - expect(userSyncs[2].type).to.equal('image'); - expect(userSyncs[2].url).to.contain('https://ms-cookie-sync.presage.io/xandr/init-sync'); - }); - - it('should set the source as query param', () => { - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(new URL(userSyncs[0].url).searchParams.get('source')).to.equal('prebid') - }); - - it('should set the tcString as query param', () => { - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(new URL(userSyncs[0].url).searchParams.get('iab_string')).to.equal(gdprConsent.consentString) - expect(new URL(userSyncs[1].url).searchParams.get('iab_string')).to.equal(gdprConsent.consentString) - expect(new URL(userSyncs[2].url).searchParams.get('iab_string')).to.equal(gdprConsent.consentString) - }); - - it('should set the gppString as query param', () => { - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(new URL(userSyncs[0].url).searchParams.get('gpp')).to.equal(gppConsent.gppString) - expect(new URL(userSyncs[1].url).searchParams.get('gpp')).to.equal(gppConsent.gppString) - expect(new URL(userSyncs[2].url).searchParams.get('gpp')).to.equal(gppConsent.gppString) - }); - - it('should set the gpp_sid as query param', () => { - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(new URL(userSyncs[0].url).searchParams.get('gpp_sid')).to.equal(gppConsent.applicableSections.toString()) - expect(new URL(userSyncs[1].url).searchParams.get('gpp_sid')).to.equal(gppConsent.applicableSections.toString()) - expect(new URL(userSyncs[2].url).searchParams.get('gpp_sid')).to.equal(gppConsent.applicableSections.toString()) - }); - - it('should return an empty array when pixel is disable', () => { - syncOptions.pixelEnabled = false; - expect(spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent)).to.have.lengthOf(0); - }); - - it('should return syncs array with three elements of type image when consentString is undefined', () => { - gdprConsent = { - gdprApplies: true, - consentString: undefined - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(3); - expect(userSyncs[0].type).to.equal('image'); - expect(new URL(userSyncs[0].url).searchParams.get('iab_string')).to.equal('') - expect(userSyncs[1].type).to.equal('image'); - expect(new URL(userSyncs[1].url).searchParams.get('iab_string')).to.equal('') - expect(userSyncs[2].type).to.equal('image'); - expect(new URL(userSyncs[2].url).searchParams.get('iab_string')).to.equal('') - }); - - it('should return syncs array with three elements of type image when consentString is null', () => { - gdprConsent = { - gdprApplies: true, - consentString: null - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(3); - expect(userSyncs[0].type).to.equal('image'); - expect(new URL(userSyncs[0].url).searchParams.get('iab_string')).to.equal('') - expect(userSyncs[1].type).to.equal('image'); - expect(new URL(userSyncs[1].url).searchParams.get('iab_string')).to.equal('') - expect(userSyncs[2].type).to.equal('image'); - expect(new URL(userSyncs[2].url).searchParams.get('iab_string')).to.equal('') - }); - - it('should return syncs array with three elements of type image when gdprConsent is undefined', () => { - gdprConsent = undefined; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(3); - expect(userSyncs[0].type).to.equal('image'); - expect(new URL(userSyncs[0].url).searchParams.get('iab_string')).to.equal('') - expect(userSyncs[1].type).to.equal('image'); - expect(new URL(userSyncs[1].url).searchParams.get('iab_string')).to.equal('') - expect(userSyncs[2].type).to.equal('image'); - expect(new URL(userSyncs[2].url).searchParams.get('iab_string')).to.equal('') - }); - - it('should return syncs array with three elements of type image when gdprConsent is null', () => { - gdprConsent = null; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(3); - expect(userSyncs[0].type).to.equal('image'); - expect(new URL(userSyncs[0].url).searchParams.get('iab_string')).to.equal('') - expect(userSyncs[1].type).to.equal('image'); - expect(new URL(userSyncs[1].url).searchParams.get('iab_string')).to.equal('') - expect(userSyncs[2].type).to.equal('image'); - expect(new URL(userSyncs[2].url).searchParams.get('iab_string')).to.equal('') - }); - - it('should return syncs array with three elements of type image when gdprConsent is null and gdprApplies is false', () => { - gdprConsent = { - gdprApplies: false, - consentString: null - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(3); - expect(userSyncs[0].type).to.equal('image'); - expect(new URL(userSyncs[0].url).searchParams.get('iab_string')).to.equal('') - expect(userSyncs[1].type).to.equal('image'); - expect(new URL(userSyncs[1].url).searchParams.get('iab_string')).to.equal('') - expect(userSyncs[2].type).to.equal('image'); - expect(new URL(userSyncs[2].url).searchParams.get('iab_string')).to.equal('') - }); - - it('should return syncs array with three elements of type image when gdprConsent is empty string and gdprApplies is false', () => { - gdprConsent = { - gdprApplies: false, - consentString: '' - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(3); - expect(userSyncs[0].type).to.equal('image'); - expect(new URL(userSyncs[0].url).searchParams.get('iab_string')).to.equal('') - expect(userSyncs[1].type).to.equal('image'); - expect(new URL(userSyncs[1].url).searchParams.get('iab_string')).to.equal('') - expect(userSyncs[2].type).to.equal('image'); - expect(new URL(userSyncs[2].url).searchParams.get('iab_string')).to.equal('') - }); - - it('should return syncs array with three elements of type image when gppString is undefined', () => { - gppConsent = { - applicableSections: [7], - gppString: undefined - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(3); - expect(userSyncs[0].type).to.equal('image'); - expect(userSyncs[1].type).to.equal('image'); - expect(userSyncs[2].type).to.equal('image'); - - const firstUrlSync = new URL(userSyncs[0].url).searchParams - expect(firstUrlSync.get('gpp')).to.equal('') - expect(firstUrlSync.get('gpp_sid')).to.equal(gppConsent.applicableSections.toString()) - - const secondtUrlSync = new URL(userSyncs[1].url).searchParams - expect(secondtUrlSync.get('gpp')).to.equal('') - expect(secondtUrlSync.get('gpp_sid')).to.equal(gppConsent.applicableSections.toString()) - - const thirdUrlSync = new URL(userSyncs[2].url).searchParams - expect(thirdUrlSync.get('gpp')).to.equal('') - expect(thirdUrlSync.get('gpp_sid')).to.equal(gppConsent.applicableSections.toString()) - }); - - it('should return syncs array with three elements of type image when gppString is null', () => { - gppConsent = { - applicableSections: [7, 8], - gppString: null - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(3); - expect(userSyncs[0].type).to.equal('image'); - expect(userSyncs[1].type).to.equal('image'); - expect(userSyncs[2].type).to.equal('image'); - - const firstUrlSync = new URL(userSyncs[0].url).searchParams - expect(firstUrlSync.get('gpp')).to.equal('') - expect(firstUrlSync.get('gpp_sid')).to.equal(gppConsent.applicableSections.toString()) - - const secondtUrlSync = new URL(userSyncs[1].url).searchParams - expect(secondtUrlSync.get('gpp')).to.equal('') - expect(secondtUrlSync.get('gpp_sid')).to.equal(gppConsent.applicableSections.toString()) - - const thirdUrlSync = new URL(userSyncs[2].url).searchParams - expect(thirdUrlSync.get('gpp')).to.equal('') - expect(thirdUrlSync.get('gpp_sid')).to.equal(gppConsent.applicableSections.toString()) - }); - - it('should return syncs array with three elements of type image when gppConsent is undefined', () => { - gppConsent = undefined; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(3); - expect(userSyncs[0].type).to.equal('image'); - expect(userSyncs[1].type).to.equal('image'); - expect(userSyncs[2].type).to.equal('image'); - - const firstUrlSync = new URL(userSyncs[0].url).searchParams - expect(firstUrlSync.get('gpp')).to.equal('') - expect(firstUrlSync.get('gpp_sid')).to.equal('') - - const secondtUrlSync = new URL(userSyncs[1].url).searchParams - expect(secondtUrlSync.get('gpp')).to.equal('') - expect(secondtUrlSync.get('gpp_sid')).to.equal('') - - const thirdUrlSync = new URL(userSyncs[2].url).searchParams - expect(thirdUrlSync.get('gpp')).to.equal('') - expect(thirdUrlSync.get('gpp_sid')).to.equal('') - }); - - it('should return syncs array with three elements of type image when gppConsent is null', () => { - gppConsent = null; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(3); - expect(userSyncs[0].type).to.equal('image'); - expect(userSyncs[1].type).to.equal('image'); - expect(userSyncs[2].type).to.equal('image'); - - const firstUrlSync = new URL(userSyncs[0].url).searchParams - expect(firstUrlSync.get('gpp')).to.equal('') - expect(firstUrlSync.get('gpp_sid')).to.equal('') - - const secondtUrlSync = new URL(userSyncs[1].url).searchParams - expect(secondtUrlSync.get('gpp')).to.equal('') - expect(secondtUrlSync.get('gpp_sid')).to.equal('') - - const thirdUrlSync = new URL(userSyncs[2].url).searchParams - expect(thirdUrlSync.get('gpp')).to.equal('') - expect(thirdUrlSync.get('gpp_sid')).to.equal('') - }); - - it('should return syncs array with three elements of type image when gppConsent is null and applicableSections is empty', () => { - gppConsent = { - applicableSections: [], - gppString: null - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(3); - expect(userSyncs[0].type).to.equal('image'); - expect(userSyncs[1].type).to.equal('image'); - expect(userSyncs[2].type).to.equal('image'); - - const firstUrlSync = new URL(userSyncs[0].url).searchParams - expect(firstUrlSync.get('gpp')).to.equal('') - expect(firstUrlSync.get('gpp_sid')).to.equal('') - - const secondtUrlSync = new URL(userSyncs[1].url).searchParams - expect(secondtUrlSync.get('gpp')).to.equal('') - expect(secondtUrlSync.get('gpp_sid')).to.equal('') - - const thirdUrlSync = new URL(userSyncs[2].url).searchParams - expect(thirdUrlSync.get('gpp')).to.equal('') - expect(thirdUrlSync.get('gpp_sid')).to.equal('') - }); - - it('should return syncs array with three elements of type image when gppString is empty string and applicableSections is empty', () => { - gppConsent = { - applicableSections: [], - gppString: '' - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent); - expect(userSyncs).to.have.lengthOf(3); - expect(userSyncs[0].type).to.equal('image'); - expect(userSyncs[1].type).to.equal('image'); - expect(userSyncs[2].type).to.equal('image'); - - const firstUrlSync = new URL(userSyncs[0].url).searchParams - expect(firstUrlSync.get('gpp')).to.equal('') - expect(firstUrlSync.get('gpp_sid')).to.equal('') - - const secondtUrlSync = new URL(userSyncs[1].url).searchParams - expect(secondtUrlSync.get('gpp')).to.equal('') - expect(secondtUrlSync.get('gpp_sid')).to.equal('') - - const thirdUrlSync = new URL(userSyncs[2].url).searchParams - expect(thirdUrlSync.get('gpp')).to.equal('') - expect(thirdUrlSync.get('gpp_sid')).to.equal('') - }); - }); - - describe('iframe', () => { - beforeEach(() => { - syncOptions = { iframeEnabled: true }; - }); - - it('should return syncs array with one element of type iframe', () => { - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - - expect(userSyncs).to.have.lengthOf(1); - expect(userSyncs[0].type).to.equal('iframe'); - expect(userSyncs[0].url).to.contain('https://ms-cookie-sync.presage.io/user-sync.html'); - }); - - it('should set the source as query param', () => { - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(new URL(userSyncs[0].url).searchParams.get('source')).to.equal('prebid'); - }); - - it('should set the tcString as query param', () => { - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(new URL(userSyncs[0].url).searchParams.get('gdpr_consent')).to.equal(gdprConsent.consentString); - }); - - it('should set the gppString as query param', () => { - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(new URL(userSyncs[0].url).searchParams.get('gpp')).to.equal(gppConsent.gppString); - }); - - it('should return an empty array when iframe is disable', () => { - syncOptions.iframeEnabled = false; - expect(spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent)).to.have.lengthOf(0); - }); - - it('should return syncs array with one element of type iframe when consentString is undefined', () => { - gdprConsent = { - gdprApplies: true, - consentString: undefined - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(1); - expect(userSyncs[0].type).to.equal('iframe'); - expect(new URL(userSyncs[0].url).searchParams.get('gdpr_consent')).to.equal(''); - }); - - it('should return syncs array with one element of type iframe when consentString is null', () => { - gdprConsent = { - gdprApplies: true, - consentString: null - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(1); - expect(userSyncs[0].type).to.equal('iframe'); - expect(new URL(userSyncs[0].url).searchParams.get('gdpr_consent')).to.equal(''); - }); - - it('should return syncs array with one element of type iframe when gdprConsent is undefined', () => { - gdprConsent = undefined; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(1); - expect(userSyncs[0].type).to.equal('iframe'); - expect(new URL(userSyncs[0].url).searchParams.get('gdpr_consent')).to.equal(''); - }); - - it('should return syncs array with one element of type iframe when gdprConsent is null', () => { - gdprConsent = null; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(1); - expect(userSyncs[0].type).to.equal('iframe'); - expect(new URL(userSyncs[0].url).searchParams.get('gdpr_consent')).to.equal(''); - }); - - it('should return syncs array with one element of type iframe when gdprConsent is null and gdprApplies is false', () => { - gdprConsent = { - gdprApplies: false, - consentString: null - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(1); - expect(userSyncs[0].type).to.equal('iframe'); - expect(new URL(userSyncs[0].url).searchParams.get('gdpr_consent')).to.equal(''); - }); - - it('should return syncs array with one element of type iframe when gdprConsent is empty string and gdprApplies is false', () => { - gdprConsent = { - gdprApplies: false, - consentString: '' - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(1); - expect(userSyncs[0].type).to.equal('iframe'); - expect(new URL(userSyncs[0].url).searchParams.get('gdpr_consent')).to.equal(''); - }); - - it('should return syncs array with one element of type iframe when gppConsent is empty string and applicableSections is empty', () => { - gppConsent = { - applicableSections: [], - gppString: '' - }; - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(1); - expect(userSyncs[0].type).to.equal('iframe'); - - const urlParams = new URL(userSyncs[0].url).searchParams - expect(urlParams.get('gpp')).to.equal('') - expect(urlParams.get('gpp_sid')).to.equal('') - }); - - it('should return syncs array with one element of type iframe when gppString is undefined', () => { - gppConsent = { - applicableSections: [7], - gppString: undefined - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(1); - expect(userSyncs[0].type).to.equal('iframe'); - - const urlParams = new URL(userSyncs[0].url).searchParams - expect(urlParams.get('gpp')).to.equal('') - expect(urlParams.get('gpp_sid')).to.equal(gppConsent.applicableSections.toString()) - }); - - it('should return syncs array with one element of type iframe when gppString is null', () => { - gppConsent = { - applicableSections: [7], - gppString: null - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(1); - expect(userSyncs[0].type).to.equal('iframe'); - - const urlParams = new URL(userSyncs[0].url).searchParams - expect(urlParams.get('gpp')).to.equal('') - expect(urlParams.get('gpp_sid')).to.equal(gppConsent.applicableSections.toString()) - }); - - it('should return syncs array with one element of type iframe when gppConsent is undefined', () => { - gppConsent = undefined; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(1); - expect(userSyncs[0].type).to.equal('iframe'); - - const urlParams = new URL(userSyncs[0].url).searchParams - expect(urlParams.get('gpp')).to.equal('') - expect(urlParams.get('gpp_sid')).to.equal('') - }); - - it('should return syncs array with one element of type iframe when gppConsent is null', () => { - gppConsent = null; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(1); - expect(userSyncs[0].type).to.equal('iframe'); - - const urlParams = new URL(userSyncs[0].url).searchParams - expect(urlParams.get('gpp')).to.equal('') - expect(urlParams.get('gpp_sid')).to.equal('') - }); - - it('should return syncs array with one element of type iframe when gppConsent is null and applicableSections is empty', () => { - gppConsent = { - applicableSections: [], - gppString: null - }; - - const userSyncs = spec.getUserSyncs(syncOptions, [], gdprConsent, [], gppConsent); - expect(userSyncs).to.have.lengthOf(1); - expect(userSyncs[0].type).to.equal('iframe'); - - const urlParams = new URL(userSyncs[0].url).searchParams - expect(urlParams.get('gpp')).to.equal('') - expect(urlParams.get('gpp_sid')).to.equal('') - }); - }); - }); - - describe('buildRequests', () => { - let windowTopStub; - const stubbedCurrentTime = 1234567890 - const stubbedDevicePixelRatio = 1 - const stubbedCurrentTimeMethod = sinon.stub(document.timeline, 'currentTime').get(function() { - return stubbedCurrentTime; - }); - - const stubbedDevicePixelMethod = sinon.stub(window, 'devicePixelRatio').get(function() { - return stubbedDevicePixelRatio; - }); - - const defaultTimeout = 1000; - - function assertImpObject(ortbBidRequest, bidRequest) { - expect(ortbBidRequest.secure).to.equal(1); - expect(ortbBidRequest.id).to.equal(bidRequest.bidId); - expect(ortbBidRequest.tagid).to.equal(bidRequest.adUnitCode); - expect(ortbBidRequest.banner).to.deep.equal({ - topframe: 0, - format: [{ - w: bidRequest.mediaTypes.banner.sizes[0][0], - h: bidRequest.mediaTypes.banner.sizes[0][1], - }] - }); - - expect(ortbBidRequest.ext).to.deep.equal({ - ...bidRequest.params, - gpid: bidRequest.ortb2Imp?.ext.gpid || bidRequest.adUnitCode, - timeSpentOnPage: stubbedCurrentTime - }); - } - - function assertRequestObject(dataRequest) { - expect(dataRequest.id).to.be.a('string'); - expect(dataRequest.tmax).to.equal(defaultTimeout); - - assertImpObject(dataRequest.imp[0], bidRequests[0]); - assertImpObject(dataRequest.imp[1], bidRequests[1]); - - expect(dataRequest.imp[0].bidfloor).to.equal(4); - expect(dataRequest.regs).to.deep.equal(ortb2.regs); - expect(dataRequest.site).to.deep.equal({ - ...ortb2.site, - page: currentLocation, - id: bidRequests[0].params.assetKey - }); - - expect(dataRequest.user).to.deep.equal({ - ext: { - ...ortb2.user.ext - } - }); - - expect(dataRequest.ext).to.deep.equal({ - prebidversion: '$prebid.version$', - adapterversion: '2.0.4' - }); - - expect(dataRequest.device).to.deep.equal({ - ...ortb2.device, - pxratio: stubbedDevicePixelRatio, - }); - - expect(dataRequest.regs.ext.gdpr).to.be.a('number'); - expect(dataRequest.device.pxratio).to.be.a('number'); - } - - beforeEach(() => { - windowTopStub = sinon.stub(utils, 'getWindowTop'); - windowTopStub.returns({ location: { href: currentLocation } }); - }); - - afterEach(() => { - windowTopStub.restore(); - }); - - after(() => { - stubbedCurrentTimeMethod.restore(); - stubbedDevicePixelMethod.restore(); - }); - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequestBase); - expect(request.url).to.equal(BID_URL); - expect(request.method).to.equal('POST'); - }); - - it('timeSpentOnpage should be 0 if timeline is undefined', function () { - const stubbedTimelineMethod = sinon.stub(document, 'timeline').get(function() { - return undefined; - }); - - const request = spec.buildRequests(bidRequests, bidderRequestBase); - expect(request.data.imp[0].ext.timeSpentOnPage).to.equal(0); - stubbedTimelineMethod.restore(); - }); - - it('bid request object should be conform', function () { - const request = spec.buildRequests(bidRequests, bidderRequestBase); - assertRequestObject(request.data); - }); - - it('should not set site.id when assetKey is not present', () => { - const bidderRequest = utils.deepClone(bidderRequestBase); - const validBidRequests = bidderRequest.bids; - delete validBidRequests[0].params.assetKey; - delete validBidRequests[1].params.assetKey; - - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data.site.id).to.be.an('undefined'); - }); - - it('should handle bidFloor undefined', () => { - const bidderRequest = utils.deepClone(bidderRequestBase); - const validBidRequests = bidderRequest.bids; - validBidRequests[0] = { - ...validBidRequests[0], - getFloor: undefined - }; - - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data.imp[0].bidfloor).to.be.an('undefined'); - }); - - it('should handle bidFloor when is not function', () => { - const bidderRequest = utils.deepClone(bidderRequestBase); - const validBidRequests = bidderRequest.bids; - validBidRequests[0] = { - ...validBidRequests[0], - getFloor: 'getFloor' - }; - - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data.imp[0].bidfloor).to.be.an('undefined'); - }); - - it('should handle bidFloor when currency is not USD', () => { - const bidderRequest = utils.deepClone(bidderRequestBase); - const validBidRequests = bidderRequest.bids; - - validBidRequests[0] = { - ...validBidRequests[0], - getFloor: ({ size, currency, mediaType }) => { - return { - currency: 'EUR', - floor: 4 - } - } - }; - - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data.imp[0].bidfloor).to.be.an('undefined'); - }); - - it('should use adUnitCode when gpid from ortb2 is undefined', () => { - const bidderRequest = utils.deepClone(bidderRequestBase); - const validBidRequests = bidderRequest.bids; - delete validBidRequests[0].ortb2Imp.ext.gpid; - - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data.imp[0].ext.gpid).to.equal(bidRequests[0].adUnitCode); - }); - - it('should use adUnitCode when gpid is not present in ortb2Imp object', () => { - const bidderRequest = utils.deepClone(bidderRequestBase); - const validBidRequests = bidderRequest.bids; - validBidRequests[0] = { - ...validBidRequests[0], - ortb2Imp: { - ext: {} - } - }; - - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data.imp[0].ext.gpid).to.equal(bidRequests[0].adUnitCode); - }); - - it('should set the actual site location in site.page when the ORTB object contains the referrer instead of the current location', () => { - const bidderRequest = utils.deepClone(bidderRequestBase); - bidderRequest.ortb2.site.page = 'https://google.com'; - - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.site.page).to.equal(currentLocation); - }); - }); - - describe('interpretResponse', function () { - const openRtbBidResponse = { - body: { - id: 'id_of_bid_response', - seatbid: [{ - bid: [{ - id: 'advertId', - impid: 'bidId', - price: 100, - nurl: 'url', - adm: `
cookies
`, - adomain: ['renault.fr'], - ext: { - adcontent: 'sample_creative', - advertid: '1a278c48-b79a-4bbf-b69f-3824803e7d87', - campaignid: '31724', - mediatype: 'image', - userid: 'ab4aabed-5230-49d9-9f1a-f06280d28366', - usersync: true, - advertiserid: '1', - isomidcompliant: false - }, - w: 180, - h: 101 - }, { - id: 'advertId2', - impid: 'bidId2', - price: 150, - nurl: 'url2', - adm: `
cookies
`, - adomain: ['peugeot.fr'], - ext: { - adcontent: 'sample_creative', - advertid: '2a278c48-b79a-4bbf-b69f-3824803e7d87', - campaignid: '41724', - userid: 'bb4aabed-5230-49d9-9f1a-f06280d28366', - usersync: false, - advertiserid: '2', - isomidcompliant: true, - mediatype: 'image', - landingpageurl: 'https://ogury.com' - }, - w: 600, - h: 500 - }], - }] - } - }; - - function assertPrebidBidResponse(prebidBidResponse, ortbResponse) { - expect(prebidBidResponse.ttl).to.equal(60); - expect(prebidBidResponse.currency).to.equal('USD'); - expect(prebidBidResponse.netRevenue).to.be.true; - expect(prebidBidResponse.mediaType).to.equal('banner'); - expect(prebidBidResponse.requestId).to.equal(ortbResponse.impid); - expect(prebidBidResponse.cpm).to.equal(ortbResponse.price); - expect(prebidBidResponse.width).to.equal(ortbResponse.w); - expect(prebidBidResponse.height).to.equal(ortbResponse.h); - expect(prebidBidResponse.ad).to.contain(ortbResponse.adm); - expect(prebidBidResponse.meta.advertiserDomains).to.deep.equal(ortbResponse.adomain); - expect(prebidBidResponse.seatBidId).to.equal(ortbResponse.id); - expect(prebidBidResponse.nurl).to.equal(ortbResponse.nurl); - } - - it('should correctly interpret bidResponse', () => { - const request = spec.buildRequests(bidRequests, bidderRequestBase); - const result = spec.interpretResponse(utils.deepClone(openRtbBidResponse), request); - - assertPrebidBidResponse(result[0], openRtbBidResponse.body.seatbid[0].bid[0]); - assertPrebidBidResponse(result[1], openRtbBidResponse.body.seatbid[0].bid[1]); - }); - }); - - describe('ortbConverterProps.bidResponse', () => { - it('should call buildBidResponse without nurl and return nurl into bidResponse to call it via ajax', () => { - const bidResponse = { adUnitCode: 'adUnitCode', cpm: 10, adapterCode: 'ogury', width: 1, height: 1 }; - const buildBidResponse = () => bidResponse; - const buildBidResponseSpy = sinon.spy(buildBidResponse); - - const bid = { nurl: 'http://url.co/win' }; - - expect(ortbConverterProps.bidResponse(buildBidResponseSpy, utils.deepClone(bid), {})).to.deep.equal({ - ...bidResponse, - currency: 'USD', - nurl: bid.nurl - }); - - sinon.assert.calledWith(buildBidResponseSpy, {}, {}); - }); - }); - - describe('onBidWon', function() { - const nurl = 'https://fakewinurl.test/'; - let requests; - - beforeEach(function() { - requests = server.requests; - }) - - it('Should not create nurl request if bid is undefined', function() { - spec.onBidWon() - expect(requests.length).to.equal(0); - }) - - it('Should not create nurl request if bid does not contains nurl', function() { - spec.onBidWon({}) - expect(requests.length).to.equal(0); - }) - - it('Should not create nurl request if bid contains undefined nurl', function() { - spec.onBidWon({ nurl: undefined }) - expect(requests.length).to.equal(0); - }) - - it('Should create nurl request if bid nurl', function() { - spec.onBidWon({ nurl }) - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal(nurl); - expect(requests[0].method).to.equal('GET') - }) - - it('Should trigger getWindowContext method', function() { - const bidSample = { - id: 'advertId', - impid: 'bidId', - price: 100, - nurl: 'url', - adm: `test creative
cookies
`, - adomain: ['renault.fr'], - ext: { - adcontent: 'sample_creative', - advertid: '1a278c48-b79a-4bbf-b69f-3824803e7d87', - campaignid: '31724', - mediatype: 'image', - userid: 'ab4aabed-5230-49d9-9f1a-f06280d28366', - usersync: true, - advertiserid: '1', - isomidcompliant: false - }, - w: 180, - h: 101 - } - spec.onBidWon(bidSample) - expect(window.top.OG_PREBID_BID_OBJECT).to.deep.equal(bidSample) - }) - }) - - describe('getWindowContext', function() { - it('Should return top window if exist', function() { - const res = spec.getWindowContext() - expect(res).to.equal(window.top) - expect(res).to.not.be.undefined; - }) - - it('Should return self window if getting top window throw an error', function() { - const stub = sinon.stub(utils, 'getWindowTop') - stub.throws() - const res = spec.getWindowContext() - expect(res).to.equal(window.self) - utils.getWindowTop.restore() - }) - }) - - describe('onTimeout', function () { - let requests; - - beforeEach(function() { - requests = server.requests; - server.onCreate = (xhr) => { - requests.push(xhr); - }; - }) - - it('should send on bid timeout notification', function() { - const bid = { - ad: 'cookies', - cpm: 3 - } - spec.onTimeout(bid); - expect(requests).to.not.be.undefined; - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal(TIMEOUT_URL); - expect(requests[0].method).to.equal('POST'); - expect(JSON.parse(requests[0].requestBody).location).to.equal(window.location.href); - }) - }); -}); diff --git a/test/spec/modules/omnidexBidAdapter_spec.js b/test/spec/modules/omnidexBidAdapter_spec.js deleted file mode 100644 index 66bc66f04..000000000 --- a/test/spec/modules/omnidexBidAdapter_spec.js +++ /dev/null @@ -1,775 +0,0 @@ -import {expect} from 'chai'; -import { - spec as adapter, - createDomain, - storage, -} from 'modules/omnidexBidAdapter'; -import * as utils from 'src/utils.js'; -import {version} from 'package.json'; -import {useFakeTimers} from 'sinon'; -import {BANNER, VIDEO} from '../../../src/mediaTypes.js'; -import {config} from '../../../src/config.js'; -import { - hashCode, - extractPID, - extractCID, - extractSubDomain, - getStorageItem, - setStorageItem, - tryParseJSON, - getUniqueDealId, -} from '../../../libraries/vidazooUtils/bidderUtils.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -export const TEST_ID_SYSTEMS = ['britepoolid', 'criteoId', 'id5id', 'idl_env', 'lipb', 'netId', 'parrableId', 'pubcid', 'tdid', 'pubProvidedId']; - -const SUB_DOMAIN = 'exchange'; - -const BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': 'div-gpt-ad-12345-0', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '59db6b3b4ffaa70004f45cdc', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1, - 'ext': { - 'param1': 'loremipsum', - 'param2': 'dolorsitamet' - } - }, - 'placementCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - 'sizes': [[300, 250], [300, 600]], - 'bidderRequestId': '1fdb5ff1b6eaa7', - 'auctionId': 'auction_id', - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'requestId': 'b0777d85-d061-450e-9bc7-260dd54bbb7a', - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'mediaTypes': [BANNER], - 'ortb2Imp': { - 'ext': { - 'gpid': '0123456789' - } - } -}; - -const VIDEO_BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': '63550ad1ff6642d368cba59dh5884270560', - 'bidderRequestId': '12a8ae9ada9c13', - 'transactionId': '56e184c6-bde9-497b-b9b9-cf47a61381ee', - 'auctionId': 'auction_id', - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '635509f7ff6642d368cb9837', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1 - }, - 'sizes': [[545, 307]], - 'mediaTypes': { - 'video': { - 'playerSize': [[545, 307]], - 'context': 'instream', - 'mimes': [ - 'video/mp4', - 'application/javascript' - ], - 'protocols': [2, 3, 5, 6], - 'maxduration': 60, - 'minduration': 0, - 'startdelay': 0, - 'linearity': 1, - 'api': [2], - 'placement': 1 - } - } -} - -const ORTB2_DEVICE = { - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - ext: {fiftyonedegrees_deviceId: '17595-133085-133468-18092'}, -}; - -const BIDDER_REQUEST = { - 'gdprConsent': { - 'consentString': 'consent_string', - 'gdprApplies': true - }, - 'gppString': 'gpp_string', - 'gppSid': [7], - 'uspConsent': 'consent_string', - 'refererInfo': { - 'page': 'https://www.greatsite.com', - 'ref': 'https://www.somereferrer.com' - }, - 'ortb2': { - 'site': { - 'content': { - 'language': 'en' - } - }, - 'regs': { - 'gpp': 'gpp_string', - 'gpp_sid': [7], - 'coppa': 0 - }, - 'device': ORTB2_DEVICE, - } -}; - -const SERVER_RESPONSE = { - body: { - cid: 'testcid123', - results: [{ - 'ad': '', - 'price': 0.8, - 'creativeId': '12610997325162499419', - 'exp': 30, - 'width': 300, - 'height': 250, - 'advertiserDomains': ['securepubads.g.doubleclick.net'], - 'cookies': [{ - 'src': 'https://sync.com', - 'type': 'iframe' - }, { - 'src': 'https://sync.com', - 'type': 'img' - }] - }] - } -}; - -const VIDEO_SERVER_RESPONSE = { - body: { - 'cid': '635509f7ff6642d368cb9837', - 'results': [{ - 'ad': '', - 'advertiserDomains': ['omnidex.com'], - 'exp': 60, - 'width': 545, - 'height': 307, - 'mediaType': 'video', - 'creativeId': '12610997325162499419', - 'price': 2, - 'cookies': [] - }] - } -}; - -const ORTB2_OBJ = { - "device": ORTB2_DEVICE, - "regs": {"coppa": 0, "gpp": "gpp_string", "gpp_sid": [7]}, - "site": {"content": {"language": "en"} - } -}; - -const REQUEST = { - data: { - width: 300, - height: 250, - bidId: '2d52001cabd527' - } -}; - -function getTopWindowQueryParams() { - try { - const parsedUrl = utils.parseUrl(window.top.document.URL, {decodeSearchAsString: true}); - return parsedUrl.search; - } catch (e) { - return ''; - } -} - -describe('OmnidexBidAdapter', function () { - before(() => config.resetConfig()); - after(() => config.resetConfig()); - - describe('validate spec', function () { - it('exists and is a function', function () { - expect(adapter.isBidRequestValid).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.buildRequests).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.interpretResponse).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.getUserSyncs).to.exist.and.to.be.a('function'); - }); - - it('exists and is a string', function () { - expect(adapter.code).to.exist.and.to.be.a('string'); - }); - - it('exists and contains media types', function () { - expect(adapter.supportedMediaTypes).to.exist.and.to.be.an('array').with.length(2); - expect(adapter.supportedMediaTypes).to.contain.members([BANNER, VIDEO]); - }); - }); - - describe('validate bid requests', function () { - it('should require cId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - pId: 'pid' - } - }); - expect(isValid).to.be.false; - }); - - it('should require pId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid' - } - }); - expect(isValid).to.be.false; - }); - - it('should validate correctly', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid', - pId: 'pid' - } - }); - expect(isValid).to.be.true; - }); - }); - - describe('build requests', function () { - let sandbox; - before(function () { - getGlobal().bidderSettings = { - omnidex: { - storageAllowed: true - } - }; - sandbox = sinon.createSandbox(); - sandbox.stub(Date, 'now').returns(1000); - }); - - it('should build video request', function () { - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - config.setConfig({ - bidderTimeout: 3000 - }); - const requests = adapter.buildRequests([VIDEO_BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/635509f7ff6642d368cb9837`, - data: { - adUnitCode: '63550ad1ff6642d368cba59dh5884270560', - bidFloor: 0.1, - bidId: '2d52001cabd527', - bidderVersion: adapter.version, - bidderRequestId: '12a8ae9ada9c13', - cb: 1000, - gdpr: 1, - gdprConsent: 'consent_string', - usPrivacy: 'consent_string', - gppString: 'gpp_string', - gppSid: [7], - prebidVersion: version, - transactionId: '56e184c6-bde9-497b-b9b9-cf47a61381ee', - auctionId: 'auction_id', - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - publisherId: '59ac17c192832d0011283fe3', - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - res: `${window.top.screen.width}x${window.top.screen.height}`, - schain: VIDEO_BID.schain, - sizes: ['545x307'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - uqs: getTopWindowQueryParams(), - mediaTypes: { - video: { - api: [2], - context: 'instream', - linearity: 1, - maxduration: 60, - mimes: [ - 'video/mp4', - 'application/javascript' - ], - minduration: 0, - placement: 1, - playerSize: [[545, 307]], - protocols: [2, 3, 5, 6], - startdelay: 0 - } - }, - gpid: '', - cat: [], - contentLang: 'en', - contentData: [], - isStorageAllowed: true, - pagecat: [], - ortb2: ORTB2_OBJ, - userData: [], - coppa: 0 - } - }); - }); - - it('should build banner request for each size', function () { - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - config.setConfig({ - bidderTimeout: 3000 - }); - const requests = adapter.buildRequests([BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/59db6b3b4ffaa70004f45cdc`, - data: { - gdprConsent: 'consent_string', - gdpr: 1, - gppString: 'gpp_string', - gppSid: [7], - usPrivacy: 'consent_string', - transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - auctionId: 'auction_id', - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - bidderRequestId: '1fdb5ff1b6eaa7', - sizes: ['300x250', '300x600'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - cb: 1000, - bidFloor: 0.1, - bidId: '2d52001cabd527', - adUnitCode: 'div-gpt-ad-12345-0', - publisherId: '59ac17c192832d0011283fe3', - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - bidderVersion: adapter.version, - prebidVersion: version, - schain: BID.schain, - res: `${window.top.screen.width}x${window.top.screen.height}`, - mediaTypes: [BANNER], - gpid: '0123456789', - uqs: getTopWindowQueryParams(), - 'ext.param1': 'loremipsum', - 'ext.param2': 'dolorsitamet', - cat: [], - contentLang: 'en', - contentData: [], - isStorageAllowed: true, - pagecat: [], - ortb2Imp: BID.ortb2Imp, - ortb2: ORTB2_OBJ, - userData: [], - coppa: 0 - } - }); - }); - - after(function () { - getGlobal().bidderSettings = {}; - sandbox.restore(); - }); - }); - describe('getUserSyncs', function () { - it('should have valid user sync with iframeEnabled', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.omni-dex.io/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - - it('should have valid user sync with cid on response', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.omni-dex.io/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - - it('should have valid user sync with pixelEnabled', function () { - const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE]); - - expect(result).to.deep.equal([{ - 'url': 'https://sync.omni-dex.io/api/sync/image/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0', - 'type': 'image' - }]); - }); - - it('should have valid user sync with coppa on response', function () { - config.setConfig({ - coppa: 1 - }); - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.omni-dex.io/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=1' - }]); - }); - - it('should generate url with consent data', function () { - const gdprConsent = { - gdprApplies: true, - consentString: 'consent_string' - }; - const uspConsent = 'usp_string'; - const gppConsent = { - gppString: 'gpp_string', - applicableSections: [7] - } - - const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE], gdprConsent, uspConsent, gppConsent); - - expect(result).to.deep.equal([{ - 'url': 'https://sync.omni-dex.io/api/sync/image/?cid=testcid123&gdpr=1&gdpr_consent=consent_string&us_privacy=usp_string&coppa=1&gpp=gpp_string&gpp_sid=7', - 'type': 'image' - }]); - }); - }); - - describe('interpret response', function () { - it('should return empty array when there is no response', function () { - const responses = adapter.interpretResponse(null); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no ad', function () { - const responses = adapter.interpretResponse({price: 1, ad: ''}); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no price', function () { - const responses = adapter.interpretResponse({price: null, ad: 'great ad'}); - expect(responses).to.be.empty; - }); - - it('should return an array of interpreted banner responses', function () { - const responses = adapter.interpretResponse(SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 0.8, - width: 300, - height: 250, - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 30, - ad: '', - meta: { - advertiserDomains: ['securepubads.g.doubleclick.net'] - } - }); - }); - - it('should get meta from response metaData', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - serverResponse.body.results[0].metaData = { - advertiserDomains: ['omnidex.com'], - agencyName: 'Agency Name', - }; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses[0].meta).to.deep.equal({ - advertiserDomains: ['omnidex.com'], - agencyName: 'Agency Name' - }); - }); - - it('should return an array of interpreted video responses', function () { - const responses = adapter.interpretResponse(VIDEO_SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 2, - width: 545, - height: 307, - mediaType: 'video', - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 60, - vastXml: '', - meta: { - advertiserDomains: ['omnidex.com'] - } - }); - }); - - it('should take default TTL', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - delete serverResponse.body.results[0].exp; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0].ttl).to.equal(300); - }); - }); - - describe('user id system', function () { - TEST_ID_SYSTEMS.forEach((idSystemProvider) => { - const id = Date.now().toString(); - const bid = utils.deepClone(BID); - - const userId = (function () { - switch (idSystemProvider) { - case 'lipb': - return {lipbid: id}; - case 'id5id': - return {uid: id}; - default: - return id; - } - })(); - - bid.userId = { - [idSystemProvider]: userId - }; - - it(`should include 'uid.${idSystemProvider}' in request params`, function () { - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data[`uid.${idSystemProvider}`]).to.equal(id); - }); - }); - // testing bid.userIdAsEids handling - it("should include user ids from bid.userIdAsEids (length=1)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - }) - it("should include user ids from bid.userIdAsEids (length=2)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - }, - { - "source": "rwdcntrl.net", - "uids": [{"id": "fakeid6f35197d5c", "atype": 1}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - expect(requests[0].data['uid.rwdcntrl.net']).to.equal("fakeid6f35197d5c"); - }) - // testing user.ext.eid handling - it("should include user ids from user.ext.eid (length=1)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - }) - it("should include user ids from user.ext.eid (length=2)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - }, - { - "source": "adserver.org", - "uids": [{"id": "fakeid495ff1"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - expect(requests[0].data['uid.adserver.org']).to.equal("fakeid495ff1"); - }) - }); - - describe('alternate param names extractors', function () { - it('should return undefined when param not supported', function () { - const cid = extractCID({'c_id': '1'}); - const pid = extractPID({'p_id': '1'}); - const subDomain = extractSubDomain({'sub_domain': 'prebid'}); - expect(cid).to.be.undefined; - expect(pid).to.be.undefined; - expect(subDomain).to.be.undefined; - }); - - it('should return value when param supported', function () { - const cid = extractCID({'cID': '1'}); - const pid = extractPID({'Pid': '2'}); - const subDomain = extractSubDomain({'subDOMAIN': 'prebid'}); - expect(cid).to.be.equal('1'); - expect(pid).to.be.equal('2'); - expect(subDomain).to.be.equal('prebid'); - }); - }); - - describe('unique deal id', function () { - before(function () { - getGlobal().bidderSettings = { - omnidex: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - const key = 'myKey'; - let uniqueDealId; - beforeEach(() => { - uniqueDealId = getUniqueDealId(storage, key, 0); - }) - - it('should get current unique deal id', function (done) { - // waiting some time so `now` will become past - setTimeout(() => { - const current = getUniqueDealId(storage, key); - expect(current).to.be.equal(uniqueDealId); - done(); - }, 200); - }); - - it('should get new unique deal id on expiration', function (done) { - setTimeout(() => { - const current = getUniqueDealId(storage, key, 100); - expect(current).to.not.be.equal(uniqueDealId); - done(); - }, 200) - }); - }); - - describe('storage utils', function () { - before(function () { - getGlobal().bidderSettings = { - omnidex: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - it('should get value from storage with create param', function () { - const now = Date.now(); - const clock = useFakeTimers({ - shouldAdvanceTime: true, - now - }); - setStorageItem(storage, 'myKey', 2020); - const {value, created} = getStorageItem(storage, 'myKey'); - expect(created).to.be.equal(now); - expect(value).to.be.equal(2020); - expect(typeof value).to.be.equal('number'); - expect(typeof created).to.be.equal('number'); - clock.restore(); - }); - - it('should get external stored value', function () { - const value = 'superman' - window.localStorage.setItem('myExternalKey', value); - const item = getStorageItem(storage, 'myExternalKey'); - expect(item).to.be.equal(value); - }); - - it('should parse JSON value', function () { - const data = JSON.stringify({event: 'send'}); - const {event} = tryParseJSON(data); - expect(event).to.be.equal('send'); - }); - - it('should get original value on parse fail', function () { - const value = 21; - const parsed = tryParseJSON(value); - expect(typeof parsed).to.be.equal('number'); - expect(parsed).to.be.equal(value); - }); - }); -}); diff --git a/test/spec/modules/omsBidAdapter_spec.js b/test/spec/modules/omsBidAdapter_spec.js deleted file mode 100644 index 2c36465c6..000000000 --- a/test/spec/modules/omsBidAdapter_spec.js +++ /dev/null @@ -1,577 +0,0 @@ -import {expect} from 'chai'; -import * as utils from 'src/utils.js'; -import {spec} from 'modules/omsBidAdapter'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import * as winDimensions from 'src/utils/winDimensions.js'; - -const URL = 'https://rt.marphezis.com/hb'; - -describe('omsBidAdapter', function () { - const adapter = newBidder(spec); - let element, win; - let bidRequests; - let sandbox; - - beforeEach(function () { - element = { - x: 0, - y: 0, - - width: 0, - height: 0, - - getBoundingClientRect: () => { - return { - width: element.width, - height: element.height, - - left: element.x, - top: element.y, - right: element.x + element.width, - bottom: element.y + element.height - }; - } - }; - win = { - document: { - visibilityState: 'visible' - }, - location: { - href: "http:/location" - }, - innerWidth: 800, - innerHeight: 600 - }; - bidRequests = [{ - 'bidder': 'oms', - 'params': { - 'publisherId': 1234567 - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 600]] - } - }, - 'bidId': '5fb26ac22bde4', - 'bidderRequestId': '4bf93aeb730cb9', - 'auctionId': 'ffe9a1f7-7b67-4bda-a8e0-9ee5dc9f442e', - 'ortb2': { - 'source': { - 'ext': { - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'exchange1.com', - 'sid': '1234', - 'hp': 1, - 'rid': 'bid-request-1', - 'name': 'publisher', - 'domain': 'publisher.com' - } - ] - } - } - } - }, - }]; - - sandbox = sinon.createSandbox(); - sandbox.stub(document, 'getElementById').withArgs('adunit-code').returns(element); - sandbox.stub(utils, 'getWindowTop').returns(win); - sandbox.stub(utils, 'getWindowSelf').returns(win); - }); - - afterEach(function () { - sandbox.restore(); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'oms', - 'params': { - 'publisherId': 1234567 - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 600]] - } - }, - 'bidId': '5fb26ac22bde4', - 'bidderRequestId': '4bf93aeb730cb9', - 'auctionId': 'ffe9a1f7-7b67-4bda-a8e0-9ee5dc9f442e', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when publisherId not passed correctly', function () { - bid.params.publisherId = undefined; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when require params are not passed', function () { - const invalidBid = Object.assign({}, bid); - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('sends bid request to our endpoint via POST', function () { - const request = spec.buildRequests(bidRequests); - expect(request.method).to.equal('POST'); - }); - - it('request url should match our endpoint url', function () { - const request = spec.buildRequests(bidRequests); - expect(request.url).to.equal(URL); - }); - - it('sets the proper banner object', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]); - }); - - it('sets the proper video object when ad unit media type is video', function () { - const bidRequests = [ - { - 'bidder': 'oms', - 'params': { - 'publisherId': 1234567 - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'video': { - 'context': 'instream', - 'playerSize': [640, 480] - } - }, - 'bidId': '5fb26ac22bde4', - 'bidderRequestId': '4bf93aeb730cb9', - 'auctionId': 'ffe9a1f7-7b67-4bda-a8e0-9ee5dc9f442e', - 'ortb2': { - 'source': { - 'ext': { - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'exchange1.com', - 'sid': '1234', - 'hp': 1, - 'rid': 'bid-request-1', - 'name': 'publisher', - 'domain': 'publisher.com' - } - ] - } - } - } - }, - } - ] - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].video.context).to.equal('instream'); - expect(payload.imp[0].video.playerSize).to.deep.equal([640, 480]); - }); - - it('accepts a single array as a size', function () { - bidRequests[0].mediaTypes.banner.sizes = [300, 250]; - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}]); - }); - - it('sends bidfloor param if present', function () { - bidRequests[0].params.bidFloor = 0.05; - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].bidfloor).to.equal(0.05); - }); - - it('sends tagid', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].tagid).to.equal('adunit-code'); - }); - - it('sends publisher id', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.site.publisher.id).to.equal(1234567); - }); - - it('sends gdpr info if exists', function () { - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const bidderRequest = { - 'bidderCode': 'oms', - 'auctionId': '1d1a030790a437', - 'bidderRequestId': '22edbae2744bf5', - 'timeout': 3000, - gdprConsent: { - consentString: consentString, - gdprApplies: true - }, - refererInfo: { - page: 'http://example.com/page.html', - domain: 'example.com', - } - }; - bidderRequest.bids = bidRequests; - - const data = JSON.parse(spec.buildRequests(bidRequests, bidderRequest).data); - - expect(data.regs.gdpr).to.exist.and.to.be.a('number'); - expect(data.regs.gdpr).to.equal(1); - expect(data.user.consent).to.exist.and.to.be.a('string'); - expect(data.user.consent).to.equal(consentString); - }); - - it('sends usp info if exists', function () { - const uspConsent = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const bidderRequest = { - 'bidderCode': 'oms', - 'auctionId': '1d1a030790a437', - 'bidderRequestId': '22edbae2744bf5', - 'timeout': 3000, - uspConsent, - refererInfo: { - page: 'http://example.com/page.html', - domain: 'example.com', - } - }; - bidderRequest.bids = bidRequests; - - const data = JSON.parse(spec.buildRequests(bidRequests, bidderRequest).data); - - expect(data.regs.us_privacy).to.exist.and.to.be.a('string'); - expect(data.regs.us_privacy).to.equal(uspConsent); - }); - - it('sends coppa', function () { - const data = JSON.parse(spec.buildRequests(bidRequests, {ortb2: {regs: {coppa: 1}}}).data) - expect(data.regs).to.not.be.undefined; - expect(data.regs.coppa).to.equal(1); - }); - - it('sends schain', function () { - const data = JSON.parse(spec.buildRequests(bidRequests).data); - expect(data).to.not.be.undefined; - expect(data.source).to.not.be.undefined; - expect(data.source.ext).to.not.be.undefined; - expect(data.source.ext.schain).to.not.be.undefined; - expect(data.source.ext.schain.complete).to.equal(1); - expect(data.source.ext.schain.ver).to.equal('1.0'); - expect(data.source.ext.schain.nodes).to.not.be.undefined; - expect(data.source.ext.schain.nodes).to.lengthOf(1); - expect(data.source.ext.schain.nodes[0].asi).to.equal('exchange1.com'); - expect(data.source.ext.schain.nodes[0].sid).to.equal('1234'); - expect(data.source.ext.schain.nodes[0].hp).to.equal(1); - expect(data.source.ext.schain.nodes[0].rid).to.equal('bid-request-1'); - expect(data.source.ext.schain.nodes[0].name).to.equal('publisher'); - expect(data.source.ext.schain.nodes[0].domain).to.equal('publisher.com'); - }); - - it('sends user eid parameters', function () { - bidRequests[0].userIdAsEids = [{ - source: 'pubcid.org', - uids: [{ - id: 'userid_pubcid' - }] - }, { - source: 'adserver.org', - uids: [{ - id: 'userid_ttd', - ext: { - rtiPartner: 'TDID' - } - }] - } - ]; - - const data = JSON.parse(spec.buildRequests(bidRequests).data); - - expect(data.user).to.not.be.undefined; - expect(data.user.ext).to.not.be.undefined; - expect(data.user.ext.eids).to.not.be.undefined; - expect(data.user.ext.eids).to.deep.equal(bidRequests[0].userIdAsEids); - }); - - it('sends gpid parameters', function () { - bidRequests[0].ortb2Imp = { - 'ext': { - 'gpid': '/1111/home-left', - 'data': { - 'adserver': { - 'name': 'gam', - 'adslot': '/1111/home' - }, - 'pbadslot': '/1111/home-left' - } - } - } - - const data = JSON.parse(spec.buildRequests(bidRequests).data); - expect(data.imp[0].ext).to.not.be.undefined; - expect(data.imp[0].ext.gpid).to.not.be.undefined; - expect(data.imp[0].ext.adserverName).to.not.be.undefined; - expect(data.imp[0].ext.adslot).to.not.be.undefined; - expect(data.imp[0].ext.pbadslot).to.not.be.undefined; - }); - - context('when element is fully in view', function () { - it('returns 100', function () { - Object.assign(element, {width: 600, height: 400}); - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.ext.viewability).to.equal(100); - }); - }); - - context('when element is out of view', function () { - it('returns 0', function () { - Object.assign(element, {x: -300, y: 0, width: 207, height: 320}); - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.ext.viewability).to.equal(0); - }); - }); - - context('when element is partially in view', function () { - it('returns percentage', function () { - const getWinDimensionsStub = sandbox.stub(winDimensions, 'getWinDimensions') - getWinDimensionsStub.returns({ innerHeight: win.innerHeight, innerWidth: win.innerWidth }); - Object.assign(element, {width: 800, height: 800}); - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.ext.viewability).to.equal(75); - }); - }); - - context('when width or height of the element is zero', function () { - it('try to use alternative values', function () { - const getWinDimensionsStub = sandbox.stub(winDimensions, 'getWinDimensions') - getWinDimensionsStub.returns({ innerHeight: win.innerHeight, innerWidth: win.innerWidth }); - Object.assign(element, {width: 0, height: 0}); - bidRequests[0].mediaTypes.banner.sizes = [[800, 2400]]; - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.ext.viewability).to.equal(25); - }); - }); - - context('when nested iframes', function () { - it('returns \'na\'', function () { - Object.assign(element, {width: 600, height: 400}); - - utils.getWindowTop.restore(); - utils.getWindowSelf.restore(); - sandbox.stub(utils, 'getWindowTop').returns(win); - sandbox.stub(utils, 'getWindowSelf').returns({}); - - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.ext.viewability).to.equal('na'); - }); - }); - - context('when tab is inactive', function () { - it('returns 0', function () { - Object.assign(element, {width: 600, height: 400}); - - utils.getWindowTop.restore(); - win.document.visibilityState = 'hidden'; - sandbox.stub(utils, 'getWindowTop').returns(win); - - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.ext.viewability).to.equal(0); - }); - }); - }); - - describe('interpretResponse', function () { - let response; - beforeEach(function () { - response = { - body: { - 'id': '37386aade21a71', - 'seatbid': [{ - 'bid': [{ - 'id': '376874781', - 'impid': '283a9f4cd2415d', - 'price': 0.35743275, - 'nurl': '', - 'adm': '', - 'w': 300, - 'h': 250, - 'adomain': ['example.com'] - }] - }] - } - }; - }); - - it('should get the correct bid response', function () { - const expectedResponse = [{ - 'requestId': '283a9f4cd2415d', - 'cpm': 0.35743275, - 'width': 300, - 'height': 250, - 'creativeId': '376874781', - 'currency': 'USD', - 'netRevenue': true, - 'mediaType': 'banner', - 'ad': `
`, - 'ttl': 300, - 'meta': { - 'advertiserDomains': ['example.com'] - } - }]; - - const result = spec.interpretResponse(response); - expect(result[0]).to.deep.equal(expectedResponse[0]); - }); - - it('should get the correct bid response for video bids', function () { - const expectedResponse = [{ - 'requestId': '283a9f4cd2415d', - 'cpm': 0.35743275, - 'width': 300, - 'height': 250, - 'creativeId': '376874781', - 'currency': 'USD', - 'netRevenue': true, - 'mediaType': 'video', - 'ad': `
`, - 'ttl': 300, - 'meta': { - 'advertiserDomains': ['example.com'] - } - }]; - const response = { - body: { - 'id': '37386aade21a71', - 'seatbid': [{ - 'bid': [{ - 'id': '376874781', - 'impid': '283a9f4cd2415d', - 'price': 0.35743275, - 'nurl': '', - 'adm': '', - 'w': 300, - 'h': 250, - 'adomain': ['example.com'], - 'mtype': 2 - }] - }] - } - }; - - const result = spec.interpretResponse(response); - expect(result[0]).to.deep.equal(expectedResponse[0]); - }); - - it('crid should default to the bid id if not on the response', function () { - const expectedResponse = [{ - 'requestId': '283a9f4cd2415d', - 'cpm': 0.35743275, - 'width': 300, - 'height': 250, - 'creativeId': response.body.seatbid[0].bid[0].id, - 'currency': 'USD', - 'netRevenue': true, - 'mediaType': 'banner', - 'ad': `
`, - 'ttl': 300, - 'meta': { - 'advertiserDomains': ['example.com'] - } - }]; - - const result = spec.interpretResponse(response); - expect(result[0]).to.deep.equal(expectedResponse[0]); - }); - - it('handles empty bid response', function () { - const response = { - body: '' - }; - const result = spec.interpretResponse(response); - expect(result.length).to.equal(0); - }); - }); - - describe('getUserSyncs ', () => { - const syncOptions = { iframeEnabled: true }; - const userSyncUrlIframe = 'https://rt.marphezis.com/sync?dpid=0'; - - it('returns empty syncs arr when syncOptions.iframeEnabled is false', () => { - expect(spec.getUserSyncs({ iframeEnabled: false }, {}, undefined, undefined)).to.be.empty; - }); - - it('returns syncs arr when syncOptions.iframeEnabled is true', () => { - expect(spec.getUserSyncs(syncOptions, {}, undefined, undefined)).to.deep.equal([{ - type: 'iframe', - url: userSyncUrlIframe - }]); - }); - - it('should pass gdpr param when gdprConsent.gdprApplies type is boolean', () => { - expect(spec.getUserSyncs(syncOptions, {}, { gdprApplies: true }, undefined)).to.deep.equal([{ - type: 'iframe', - url: `${userSyncUrlIframe}&gdpr=1` - }]); - expect(spec.getUserSyncs(syncOptions, {}, { gdprApplies: false }, undefined)).to.deep.equal([{ - type: 'iframe', - url: `${userSyncUrlIframe}&gdpr=0` - }]); - }); - - it('should pass gdpr_consent param when gdprConsent.consentString type is string', () => { - expect(spec.getUserSyncs(syncOptions, {}, { gdprApplies: false, consentString: 'test' }, undefined)).to.deep.equal([{ - type: 'iframe', - url: `${userSyncUrlIframe}&gdpr=0&gdpr_consent=test` - }]); - }); - - it('should pass no params when gdprConsent.consentString and gdprConsent.gdprApplies types dont match', () => { - expect(spec.getUserSyncs(syncOptions, {}, { gdprApplies: 'true', consentString: 1 }, undefined)).to.deep.equal([{ - type: 'iframe', - url: `${userSyncUrlIframe}` - }]); - }); - - it('should pass us_privacy param when uspConsent is defined', function () { - expect(spec.getUserSyncs(syncOptions, {}, undefined, 'test')).to.deep.equal([{ - type: 'iframe', url: `${userSyncUrlIframe}&us_privacy=test` - }]); - }); - - it('should pass gpp and gpp_sid params when gppConsent.gppString is defined', function () { - expect(spec.getUserSyncs(syncOptions, {}, {}, undefined, { - gppString: 'test', - applicableSections: [1, 2] - })).to.deep.equal([{ - type: 'iframe', url: `${userSyncUrlIframe}&gpp=test&gpp_sid=1,2` - }]); - }); - - it('should pass all params correctly', function () { - expect(spec.getUserSyncs(syncOptions, {}, { gdprApplies: false, consentString: 'test' }, 'test', { - gppString: 'test', - applicableSections: [] - })).to.deep.equal([{ - type: 'iframe', url: `${userSyncUrlIframe}&gdpr=0&gdpr_consent=test&us_privacy=test&gpp=test&gpp_sid=` - }]); - }); - }); -}); diff --git a/test/spec/modules/oneKeyRtdProvider_spec.js b/test/spec/modules/oneKeyRtdProvider_spec.js deleted file mode 100644 index 70023e351..000000000 --- a/test/spec/modules/oneKeyRtdProvider_spec.js +++ /dev/null @@ -1,152 +0,0 @@ -import {oneKeyDataSubmodule} from 'modules/oneKeyRtdProvider.js'; -import {getAdUnits} from '../../fixtures/fixtures.js'; - -const defaultSeed = { - version: '0.1', - transaction_ids: [ - 'd566b02a-a6e2-4c87-98dc-f5623cd9e828', - 'f7ffe3cc-0d58-4ec4-b687-1d3d410a48fe' - ], - publisher: 'cmp.pafdemopublisher.com', - source: { - domain: 'cmp.pafdemopublisher.com', - timestamp: 1657116880, - signature: '6OmdrSGwagPpugGFuQ4VGjzqYadHxWIXPaLItk0vA1lmi/EQyRvNF5seXStfwKWRnC7HZlOIGSjA6g7HAuofWw==' - - } -}; - -const defaultOrb2WithTransmission = { - user: { - ext: { - paf: { - transmission: { - seed: defaultSeed - } - } - } - } -}; - -const defaultRtdConfig = { - params: { - proxyHostName: 'host' - } -}; - -describe('oneKeyDataSubmodule', () => { - var bidsConfig; - beforeEach(() => { - // Fresh bidsConfig because it can be altered - // during the tests. - bidsConfig = getReqBidsConfig(); - setUpOneKey(); - }); - - it('successfully instantiates', () => { - expect(oneKeyDataSubmodule.init()).to.equal(true); - }); - - it('call OneKey API once it is loaded', () => { - const done = sinon.spy(); - - oneKeyDataSubmodule.getBidRequestData(bidsConfig, done, defaultRtdConfig); - - expect(bidsConfig).to.eql(getReqBidsConfig()); - expect(done.callCount).to.equal(0); - expect(window.OneKey.queue.length).to.equal(1); - }); - - it('don\'t change anything without a seed', () => { - window.OneKey.generateSeed = (_transactionIds) => { - return Promise.resolve(undefined); - }; - - // Act - return new Promise(resolve => { - oneKeyDataSubmodule.getBidRequestData(bidsConfig, resolve, defaultRtdConfig); - executeOneKeyQueue(); - }) - - // Assert - .then(() => { - expect(bidsConfig).to.eql(getReqBidsConfig()); - }); - }); - - [ // Test cases - { - description: 'global orb2', - rtdConfig: defaultRtdConfig, - expectedFragment: { - global: { - ...defaultOrb2WithTransmission - }, - bidder: {} - } - }, - - { - description: 'bidder-specific orb2', - rtdConfig: { - params: { - proxyHostName: 'host', - bidders: [ 'bidder42', 'bidder24' ] - } - }, - expectedFragment: { - global: { }, - bidder: { - bidder42: { - ...defaultOrb2WithTransmission - }, - bidder24: { - ...defaultOrb2WithTransmission - } - } - } - } - ].forEach(testCase => { - it(`update adUnits with transaction-ids and transmission in ${testCase.description}`, () => { - // Act - return new Promise(resolve => { - oneKeyDataSubmodule.getBidRequestData(bidsConfig, resolve, testCase.rtdConfig); - executeOneKeyQueue(); - }) - - // Assert - .then(() => { - // Verify transaction-ids without equality - // because they are generated UUID. - bidsConfig.adUnits.forEach((adUnit) => { - expect(adUnit.ortb2Imp.ext.data.paf.transaction_id).to.not.be.undefined; - }); - expect(bidsConfig.ortb2Fragments).to.eql(testCase.expectedFragment); - }); - }); - }); -}); - -const getReqBidsConfig = () => { - return { - adUnits: getAdUnits(), - ortb2Fragments: { - global: {}, - bidder: {} - } - } -} - -const setUpOneKey = () => { - window.OneKey.queue = []; - OneKey.generateSeed = (_transactionIds) => { - return Promise.resolve(defaultSeed); - }; -} - -const executeOneKeyQueue = () => { - while (window.OneKey.queue.length > 0) { - window.OneKey.queue[0](); - window.OneKey.queue.shift(); - } -} diff --git a/test/spec/modules/onetagBidAdapter_spec.js b/test/spec/modules/onetagBidAdapter_spec.js deleted file mode 100644 index 97ffdaf46..000000000 --- a/test/spec/modules/onetagBidAdapter_spec.js +++ /dev/null @@ -1,1158 +0,0 @@ -import { spec, isValid, hasTypeVideo, isSchainValid } from 'modules/onetagBidAdapter.js'; -import { expect } from 'chai'; -import { BANNER, VIDEO, NATIVE } from 'src/mediaTypes.js'; -import { INSTREAM, OUTSTREAM } from 'src/video.js'; -import { toOrtbNativeRequest } from 'src/native.js'; -import { hasTypeNative } from '../../../modules/onetagBidAdapter.js'; - -const NATIVE_SUFFIX = 'Ad'; - -const getFloor = function(params) { - let floorPrice = 0.0001; - switch (params.mediaType) { - case BANNER: - floorPrice = 1.0; - break; - case VIDEO: - floorPrice = 2.0; - break; - case INSTREAM: - floorPrice = 3.0; - break; - case OUTSTREAM: - floorPrice = 4.0; - break; - case NATIVE: - floorPrice = 5.0; - break; - } - return {currency: params.currency, floor: floorPrice}; -}; - -describe('onetag', function () { - function createBid() { - return { - 'bidder': 'onetag', - 'params': { - 'pubId': '386276e072', - }, - 'adUnitCode': 'adunit-code', - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'ortb2Imp': { - 'ext': { - 'tid': '0000' - } - }, - 'ortb2': { - 'source': { - 'tid': '1111' - } - }, - 'schain': { - 'validation': 'off', - 'config': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'indirectseller.com', - 'sid': '00001', - 'hp': 1 - } - ] - } - }, - }; - } - - function createNativeLegacyBid(bidRequest) { - let bid = bidRequest || createBid(); - bid.mediaTypes = bid.mediaTypes || {}; - bid.mediaTypes.native = { - adTemplate: "
\"##hb_native_brand##\"
##hb_native_brand##

##hb_native_title##

##hb_native_cta####hb_native_brand##
", - title: { - required: 1, - sendId: 1 - }, - body: { - required: 1, - sendId: 1 - }, - cta: { - required: 0, - sendId: 1 - }, - displayUrl: { - required: 0, - sendId: 1 - }, - icon: { - required: 0, - sendId: 1 - }, - image: { - required: 1, - sendId: 1 - }, - sponsoredBy: { - required: 1, - sendId: 1 - } - } - bid = addNativeParams(bid); - const ortbConversion = toOrtbNativeRequest(bid.nativeParams); - bid.mediaTypes.native = {}; - bid.mediaTypes.native.adTemplate = bid.nativeParams.adTemplate; - bid.mediaTypes.native.ortb = ortbConversion; - bid.floors = { - currency: 'EUR', - schema: { - delimiter: '|', - fields: [ 'mediaType', 'size' ] - }, - values: { - 'native|*': 1.10 - } - } - bid.getFloor = getFloor; - return bid; - } - - function addNativeParams(bidRequest) { - const bidParams = bidRequest.nativeParams || {}; - for (const property in bidRequest.mediaTypes.native) { - bidParams[property] = bidRequest.mediaTypes.native[property]; - } - bidRequest.nativeParams = bidParams; - return bidRequest; - } - - function createNativeBid(bidRequest) { - const bid = bidRequest || createBid(); - bid.mediaTypes = bid.mediaTypes || {}; - - bid.mediaTypes.native = { - ortb: { - ver: '1.2', - assets: [{ - id: 1, - required: 1, - title: { - len: 140 - } - }, - { - id: 2, - required: true, - img: { - type: 3, - wmin: 100, - hmin: 100, - } - }, - { - id: 3, - required: true, - data: { - type: 6 - } - }, - { - id: 4, - video: { - mimes: ['video/mp4', 'video/x-mswmv'], - minduration: 5, - maxduration: 30, - protocols: [2, 3] - } - }], - eventtrackers: [{ - event: 1, - methods: [1], - url: 'sample-url' - }] - } - }; - - bid.floors = { - currency: 'EUR', - schema: { - delimiter: '|', - fields: [ 'mediaType', 'size' ] - }, - values: { - 'native|*': 1.10 - } - } - bid.getFloor = getFloor; - - return bid; - } - - function createBannerBid(bidRequest) { - const bid = bidRequest || createBid(); - bid.mediaTypes = bid.mediaTypes || {}; - bid.mediaTypes.banner = { - sizes: [[300, 250]] - }; - bid.floors = { - currency: 'EUR', - schema: { - delimiter: '|', - fields: [ 'mediaType', 'size' ] - }, - values: { - 'banner|300x250': 0.10 - } - } - bid.getFloor = getFloor; - - return bid; - } - - function createInstreamVideoBid(bidRequest) { - const bid = bidRequest || createBid(); - bid.mediaTypes = bid.mediaTypes || {}; - bid.mediaTypes.video = { - context: 'instream', - mimes: ['video/mp4', 'video/webm', 'application/javascript', 'video/ogg'], - playerSize: [640, 480] - }; - bid.floors = { - currency: 'EUR', - schema: { - delimiter: '|', - fields: [ 'mediaType', 'size' ] - }, - values: { - 'video|640x480': 0.10 - } - } - bid.getFloor = getFloor; - return bid; - } - - function createOutstreamVideoBid(bidRequest) { - const bid = bidRequest || createBid(); - bid.mediaTypes = bid.mediaTypes || {}; - bid.mediaTypes.video = { - context: 'outstream', - mimes: ['video/mp4', 'video/webm', 'application/javascript', 'video/ogg'], - playerSize: [640, 480] - }; - bid.floors = { - currency: 'EUR', - schema: { - delimiter: '|', - fields: [ 'mediaType', 'size' ] - }, - values: { - 'video|640x480': 0.10 - } - } - bid.getFloor = getFloor; - return bid; - } - - function createMultiFormatBid() { - return createInstreamVideoBid(createBannerBid()); - } - - let bannerBid, instreamVideoBid, outstreamVideoBid, nativeBid, nativeLegacyBid; - beforeEach(() => { - bannerBid = createBannerBid(); - instreamVideoBid = createInstreamVideoBid(); - outstreamVideoBid = createOutstreamVideoBid(); - nativeBid = createNativeBid(); - nativeLegacyBid = createNativeLegacyBid(); - }) - - describe('isBidRequestValid', function () { - it('Should return true when required params are found', function () { - expect(spec.isBidRequestValid(bannerBid)).to.be.true; - }); - it('Should return false when pubId is not a string', function () { - bannerBid.params.pubId = 30; - expect(spec.isBidRequestValid(bannerBid)).to.be.false; - }); - it('Should return false when pubId is undefined', function () { - bannerBid.params.pubId = undefined; - expect(spec.isBidRequestValid(bannerBid)).to.be.false; - }); - describe('banner bidRequest', function () { - it('Should return false when the sizes array is empty', function () { - bannerBid.mediaTypes.banner.sizes = []; - expect(spec.isBidRequestValid(bannerBid)).to.be.false; - }); - }); - describe('native bidRequest', function () { - it('Should return true when correct native bid is passed', function () { - const nativeBid = createNativeBid(); - const nativeLegacyBid = createNativeLegacyBid(); - expect(spec.isBidRequestValid(nativeBid)).to.be.true; - expect(spec.isBidRequestValid(nativeLegacyBid)).to.be.true; - }); - it('Should return false when native is not an object', function () { - const nativeBid = createNativeBid(); - const nativeLegacyBid = createNativeLegacyBid(); - nativeBid.mediaTypes.native = nativeLegacyBid.mediaTypes.native = 30; - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - expect(spec.isBidRequestValid(nativeLegacyBid)).to.be.false; - }); - it('Should return false when native.ortb if defined but it isn\'t an object', function () { - const nativeBid = createNativeBid(); - nativeBid.mediaTypes.native.ortb = 30 || 'string'; - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - }); - it('Should return false when native.ortb.assets is not an array', function () { - const nativeBid = createNativeBid(); - const nativeLegacyBid = createNativeLegacyBid(); - nativeBid.mediaTypes.native.ortb.assets = nativeLegacyBid.mediaTypes.native.ortb.assets = 30; - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - expect(spec.isBidRequestValid(nativeLegacyBid)).to.be.false; - }); - it('Should return false when native.ortb.assets is an empty array', function () { - const nativeBid = createNativeBid(); - const nativeLegacyBid = createNativeLegacyBid(); - nativeBid.mediaTypes.native.ortb.assets = nativeLegacyBid.mediaTypes.native.ortb.assets = []; - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - expect(spec.isBidRequestValid(nativeLegacyBid)).to.be.false; - }); - it('Should return false when native.ortb.assets[i] doesnt have \'id\'', function () { - const nativeBid = createNativeBid(); - const nativeLegacyBid = createNativeLegacyBid(); - Reflect.deleteProperty(nativeBid.mediaTypes.native.ortb.assets[0], 'id'); - Reflect.deleteProperty(nativeLegacyBid.mediaTypes.native.ortb.assets[0], 'id'); - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - expect(spec.isBidRequestValid(nativeLegacyBid)).to.be.false; - }); - it('Should return false when native.ortb.assets[i] doesnt have any of \'title\', \'img\', \'data\' and \'video\' properties', function () { - const nativeBid = createNativeBid(); - const nativeLegacyBid = createNativeLegacyBid(); - const titleIndex = nativeBid.mediaTypes.native.ortb.assets.findIndex(asset => asset.title); - const legacyTitleIndex = nativeLegacyBid.mediaTypes.native.ortb.assets.findIndex(asset => asset.title); - Reflect.deleteProperty(nativeBid.mediaTypes.native.ortb.assets[titleIndex], 'title'); - Reflect.deleteProperty(nativeLegacyBid.mediaTypes.native.ortb.assets[legacyTitleIndex], 'title'); - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - expect(spec.isBidRequestValid(nativeLegacyBid)).to.be.false; - }); - it('Should return false when native.ortb.assets[i] have title, but doesnt have \'len\' property', function () { - const nativeBid = createNativeBid(); - const nativeLegacyBid = createNativeLegacyBid(); - const titleIndex = nativeBid.mediaTypes.native.ortb.assets.findIndex(asset => asset.title); - const legacyTitleIndex = nativeLegacyBid.mediaTypes.native.ortb.assets.findIndex(asset => asset.title); - Reflect.deleteProperty(nativeBid.mediaTypes.native.ortb.assets[titleIndex].title, 'len'); - Reflect.deleteProperty(nativeLegacyBid.mediaTypes.native.ortb.assets[legacyTitleIndex].title, 'len'); - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - expect(spec.isBidRequestValid(nativeLegacyBid)).to.be.false; - }); - it('Should return false when native.ortb.assets[i] is data but doesnt have \'type\' property', function () { - const nativeBid = createNativeBid(); - const nativeLegacyBid = createNativeLegacyBid(); - const dataIndex = nativeBid.mediaTypes.native.ortb.assets.findIndex(asset => asset.data); - Reflect.deleteProperty(nativeBid.mediaTypes.native.ortb.assets[dataIndex].data, 'type'); - Reflect.deleteProperty(nativeLegacyBid.mediaTypes.native.ortb.assets[dataIndex].data, 'type'); - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - expect(spec.isBidRequestValid(nativeLegacyBid)).to.be.false; - }); - it('Should return false when native.ortb.assets[i] is video but doesnt have \'mimes\' property', function () { - const nativeBid = createNativeBid(); - const videoIndex = nativeBid.mediaTypes.native.ortb.assets.findIndex(asset => asset.video); - Reflect.deleteProperty(nativeBid.mediaTypes.native.ortb.assets[videoIndex].video, 'mimes'); - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - }); - it('Should return false when native.ortb.assets[i] is video but doesnt have \'minduration\' property', function () { - const nativeBid = createNativeBid(); - const videoIndex = nativeBid.mediaTypes.native.ortb.assets.findIndex(asset => asset.video); - Reflect.deleteProperty(nativeBid.mediaTypes.native.ortb.assets[videoIndex].video, 'minduration'); - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - }); - it('Should return false when native.ortb.assets[i] is video but doesnt have \'maxduration\' property', function () { - const nativeBid = createNativeBid(); - const videoIndex = nativeBid.mediaTypes.native.ortb.assets.findIndex(asset => asset.video); - Reflect.deleteProperty(nativeBid.mediaTypes.native.ortb.assets[videoIndex].video, 'maxduration'); - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - }); - it('Should return false when native.ortb.assets[i] is video but doesnt have \'protocols\' property', function () { - const nativeBid = createNativeBid(); - const videoIndex = nativeBid.mediaTypes.native.ortb.assets.findIndex(asset => asset.video); - Reflect.deleteProperty(nativeBid.mediaTypes.native.ortb.assets[videoIndex].video, 'protocols'); - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - }); - it('Should return false when native.ortb.eventtrackers is not an array', function () { - const nativeBid = createNativeBid(); - nativeBid.mediaTypes.native.ortb.eventtrackers = 30; - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - }); - it('Should return false when native.ortb.eventtrackers[i].event is not a number', function () { - const nativeBid = createNativeBid(); - nativeBid.mediaTypes.native.ortb.eventtrackers[0].event = 'test-string'; - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - }); - it('Should return false when native.ortb.eventtrackers[i].event is not defined', function () { - const nativeBid = createNativeBid(); - nativeBid.mediaTypes.native.ortb.eventtrackers[0].event = undefined; - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - }); - it('Should return false when native.ortb.eventtrackers[i].methods is not an array', function () { - const nativeBid = createNativeBid(); - nativeBid.mediaTypes.native.ortb.eventtrackers[0].methods = 30; - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - }); - it('Should return false when native.ortb.eventtrackers[i].methods is empty array', function () { - const nativeBid = createNativeBid(); - nativeBid.mediaTypes.native.ortb.eventtrackers[0].methods = []; - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - }); - }); - describe('video bidRequest', function () { - it('Should return false when the context is undefined', function () { - instreamVideoBid.mediaTypes.video.context = undefined; - expect(spec.isBidRequestValid(instreamVideoBid)).to.be.false; - }); - it('Should return false when the context is not instream or outstream', function () { - instreamVideoBid.mediaTypes.video.context = 'wrong'; - expect(spec.isBidRequestValid(instreamVideoBid)).to.be.false; - }); - it('Should return false when playerSize is undefined', function () { - const videoBid = createInstreamVideoBid(); - videoBid.mediaTypes.video.playerSize = undefined; - expect(spec.isBidRequestValid(videoBid)).to.be.false; - }); - it('Should return false when playerSize is not an array', function () { - const videoBid = createInstreamVideoBid(); - videoBid.mediaTypes.video.playerSize = 30; - expect(spec.isBidRequestValid(videoBid)).to.be.false; - }); - it('Should return false when playerSize is an empty array', function () { - const videoBid = createInstreamVideoBid(); - videoBid.mediaTypes.video.playerSize = []; - expect(spec.isBidRequestValid(videoBid)).to.be.false; - }); - it('Should return true when context is outstream', function () { - expect(spec.isBidRequestValid(outstreamVideoBid)).to.be.true; - }); - }); - describe('multi format bidRequest', function () { - it('Should return true when correct multi format bid is passed', function () { - expect(spec.isBidRequestValid(createMultiFormatBid())).to.be.true; - }); - it('Should split multi format bid into two single format bid with same bidId', function () { - const bids = JSON.parse(spec.buildRequests([createMultiFormatBid()]).data).bids; - expect(bids.length).to.equal(2); - expect(bids[0].bidId).to.equal(bids[1].bidId); - }); - it('Should retrieve correct request bid when extracting video request data', function () { - const requestBid = createMultiFormatBid(); - const multiFormatRequest = spec.buildRequests([requestBid]); - const serverResponse = { - body: { - bids: [ - { - mediaType: BANNER, - requestId: requestBid.bidId, - ad: 'test-banner' - }, { - mediaType: VIDEO, - requestId: requestBid.bidId, - vastUrl: 'test-video' - } - ] - } - }; - const responseBids = spec.interpretResponse(serverResponse, multiFormatRequest); - expect(responseBids.length).to.equal(2); - expect(responseBids[0].ad).to.equal('test-banner'); - expect(responseBids[1].vastUrl).to.equal('test-video'); - }); - }); - }); - - describe('buildRequests', function () { - let serverRequest, data; - before(() => { - serverRequest = spec.buildRequests([bannerBid, instreamVideoBid, nativeBid, nativeLegacyBid]); - data = JSON.parse(serverRequest.data); - }); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://onetag-sys.com/prebid-request'); - }); - it('Should contain all keys', function () { - expect(data).to.be.an('object'); - expect(data).to.include.all.keys('location', 'referrer', 'stack', 'numIframes', 'sHeight', 'sWidth', 'docHeight', 'wHeight', 'wWidth', 'oHeight', 'oWidth', 'aWidth', 'aHeight', 'sLeft', 'sTop', 'hLength', 'bids', 'docHidden', 'xOffset', 'yOffset', 'networkConnectionType', 'networkEffectiveConnectionType', 'timing', 'version', 'fledgeEnabled'); - expect(data.location).to.satisfy(function (value) { - return value === null || typeof value === 'string'; - }); - expect(data.referrer).to.satisfy(referrer => referrer === null || typeof referrer === 'string'); - expect(data.stack).to.be.an('array'); - expect(data.numIframes).to.be.a('number'); - expect(data.sHeight).to.be.a('number'); - expect(data.sWidth).to.be.a('number'); - expect(data.wWidth).to.be.a('number'); - expect(data.wHeight).to.be.a('number'); - expect(data.oHeight).to.be.a('number'); - expect(data.oWidth).to.be.a('number'); - expect(data.aWidth).to.be.a('number'); - expect(data.aHeight).to.be.a('number'); - expect(data.sLeft).to.be.a('number'); - expect(data.sTop).to.be.a('number'); - expect(data.hLength).to.be.a('number'); - expect(data.networkConnectionType).to.satisfy(function (value) { - return value === null || typeof value === 'string' - }); - expect(data.networkEffectiveConnectionType).to.satisfy(function (value) { - return value === null || typeof value === 'string' - }); - expect(data.fledgeEnabled).to.be.a('boolean'); - expect(data.bids).to.be.an('array'); - expect(data.version).to.have.all.keys('prebid', 'adapter'); - const bids = data['bids']; - for (let i = 0; i < bids.length; i++) { - const bid = bids[i]; - if (hasTypeVideo(bid)) { - expect(bid).to.have.all.keys( - 'adUnitCode', - 'auctionId', - 'bidId', - 'bidderRequestId', - 'pubId', - 'ortb2Imp', - 'transactionId', - 'context', - 'playerSize', - 'mediaTypeInfo', - 'type', - 'priceFloors' - ); - } else if (hasTypeNative(bid)) { - expect(bid).to.have.all.keys( - 'adUnitCode', - 'auctionId', - 'bidId', - 'bidderRequestId', - 'pubId', - 'ortb2Imp', - 'transactionId', - 'mediaTypeInfo', - 'sizes', - 'type', - 'priceFloors' - ); - expect(bid.mediaTypeInfo).to.have.key('ortb'); - } else if (isValid(BANNER, bid)) { - expect(bid).to.have.all.keys( - 'adUnitCode', - 'auctionId', - 'bidId', - 'bidderRequestId', - 'pubId', - 'ortb2Imp', - 'transactionId', - 'mediaTypeInfo', - 'sizes', - 'type', - 'priceFloors' - ); - } - if (bid.schain && isSchainValid(bid.schain)) { - expect(data).to.have.all.keys('schain'); - } - expect(bid.bidId).to.be.a('string'); - expect(bid.pubId).to.be.a('string'); - expect(bid.priceFloors).to.be.an('array'); - expect(bid.priceFloors).to.satisfy(function (priceFloors) { - if (priceFloors.length === 0) { - return true; - } - return priceFloors.every(function (priceFloor) { - expect(priceFloor).to.have.all.keys('currency', 'floor', 'size'); - expect(priceFloor.currency).to.be.a('string'); - expect(priceFloor.floor).to.be.a('number'); - expect(priceFloor.size).to.satisfy(function (size) { - if (typeof size !== 'object' && size !== null && typeof size !== 'undefined') { - return false; - } - if (size !== null) { - const keys = Object.keys(size); - if (keys.length === 0) { - return true; - } - expect(size).to.have.keys('width', 'height'); - expect(size.width).to.be.a('number'); - expect(size.height).to.be.a('number'); - } - return true; - }); - return true; - }); - }); - } - }); - it('Returns empty data if no valid requests are passed', function () { - serverRequest = spec.buildRequests([]); - const dataString = serverRequest.data; - try { - const dataObj = JSON.parse(dataString); - expect(dataObj.bids).to.be.an('array').that.is.empty; - } catch (e) { } - }); - it('Should pick each bid\'s auctionId and transactionId from ortb2 related fields', function () { - const serverRequest = spec.buildRequests([bannerBid]); - const payload = JSON.parse(serverRequest.data); - - expect(payload).to.exist; - expect(payload.bids).to.exist.and.to.have.length(1); - expect(payload.bids[0].auctionId).to.equal(bannerBid.ortb2.source.tid); - expect(payload.bids[0].transactionId).to.equal(bannerBid.ortb2Imp.ext.tid); - expect(payload.bids[0].ortb2Imp).to.deep.equal(bannerBid.ortb2Imp); - }); - it('should send GDPR consent data', function () { - const consentString = 'consentString'; - const addtlConsent = '2~1.35.41.101~dv.9.21.81'; - const bidderRequest = { - 'bidderCode': 'onetag', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - consentString: consentString, - gdprApplies: true, - addtlConsent: addtlConsent - } - }; - const serverRequest = spec.buildRequests([bannerBid], bidderRequest); - const payload = JSON.parse(serverRequest.data); - - expect(payload).to.exist; - expect(payload.gdprConsent).to.exist; - expect(payload.gdprConsent.consentString).to.exist.and.to.equal(consentString); - expect(payload.gdprConsent.addtlConsent).to.exist.and.to.equal(addtlConsent); - expect(payload.gdprConsent.consentRequired).to.exist.and.to.be.true; - }); - it('Should send GPP consent data', function () { - const consentString = 'consentString'; - const applicableSections = [1, 2, 3]; - const bidderRequest = { - 'bidderCode': 'onetag', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gppConsent': { - gppString: consentString, - applicableSections: applicableSections - } - }; - const serverRequest = spec.buildRequests([bannerBid], bidderRequest); - const payload = JSON.parse(serverRequest.data); - - expect(payload).to.exist; - expect(payload.gppConsent).to.exist; - expect(payload.gppConsent.consentString).to.exist.and.to.equal(consentString); - expect(payload.gppConsent.applicableSections).to.have.same.members(applicableSections); - }); - it('Should send us privacy string', function () { - const consentString = 'us_foo'; - const bidderRequest = { - 'bidderCode': 'onetag', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'uspConsent': consentString - }; - const serverRequest = spec.buildRequests([bannerBid], bidderRequest); - const payload = JSON.parse(serverRequest.data); - - expect(payload.usPrivacy).to.exist; - expect(payload.usPrivacy).to.exist.and.to.equal(consentString); - }); - it('Should send FPD (ortb2 field)', function () { - const firtPartyData = { - // this is where the contextual data is placed - site: { - name: 'example', - domain: 'page.example.com', - // OpenRTB 2.5 spec / Content Taxonomy - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'], - page: 'https://page.example.com/here.html', - ref: 'https://ref.example.com', - keywords: 'power tools, drills', - search: 'drill', - content: { - userrating: '4', - data: [{ - name: 'www.dataprovider1.com', // who resolved the segments - ext: { - segtax: 7, // taxonomy used to encode the segments - cids: ['iris_c73g5jq96mwso4d8'] - }, - // the bare minimum are the IDs. These IDs are the ones from the new IAB Content Taxonomy v3 - segment: [ { id: '687' }, { id: '123' } ] - }] - }, - ext: { - data: { // fields that aren't part of openrtb 2.6 - pageType: 'article', - category: 'repair' - } - } - }, - // this is where the user data is placed - user: { - keywords: 'a,b', - data: [{ - name: 'dataprovider.com', - ext: { - segtax: 4 - }, - segment: [{ - id: '1' - }] - }], - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - }, - regs: { - gpp: 'abc1234', - gpp_sid: [7] - } - }; - const bidderRequest = { - 'bidderCode': 'onetag', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'ortb2': firtPartyData - } - const serverRequest = spec.buildRequests([bannerBid], bidderRequest); - const payload = JSON.parse(serverRequest.data); - expect(payload.ortb2).to.exist; - expect(payload.ortb2).to.exist.and.to.deep.equal(firtPartyData); - }); - it('Should send DSA (ortb2 field)', function () { - const dsa = { - 'regs': { - 'ext': { - 'dsa': { - 'required': 1, - 'pubrender': 0, - 'datatopub': 1, - 'transparency': [{ - 'domain': 'dsa-domain', - 'params': [1, 2] - }] - } - } - } - }; - const bidderRequest = { - 'bidderCode': 'onetag', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'ortb2': dsa - } - const serverRequest = spec.buildRequests([bannerBid], bidderRequest); - const payload = JSON.parse(serverRequest.data); - expect(payload.ortb2).to.exist; - expect(payload.ortb2).to.exist.and.to.deep.equal(dsa); - }); - it('Should send FLEDGE eligibility flag when FLEDGE is enabled', function () { - const bidderRequest = { - 'bidderCode': 'onetag', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'paapi': { - 'enabled': true - } - }; - const serverRequest = spec.buildRequests([bannerBid], bidderRequest); - const payload = JSON.parse(serverRequest.data); - - expect(payload.fledgeEnabled).to.exist; - expect(payload.fledgeEnabled).to.exist.and.to.equal(bidderRequest.paapi.enabled); - }); - it('Should send FLEDGE eligibility flag when FLEDGE is not enabled', function () { - const bidderRequest = { - 'bidderCode': 'onetag', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - paapi: { - enabled: false - } - }; - const serverRequest = spec.buildRequests([bannerBid], bidderRequest); - const payload = JSON.parse(serverRequest.data); - - expect(payload.fledgeEnabled).to.exist; - expect(payload.fledgeEnabled).to.exist.and.to.equal(bidderRequest.paapi.enabled); - }); - it('Should send FLEDGE eligibility flag set to false when fledgeEnabled is not defined', function () { - const bidderRequest = { - 'bidderCode': 'onetag', - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - }; - const serverRequest = spec.buildRequests([bannerBid], bidderRequest); - const payload = JSON.parse(serverRequest.data); - - expect(payload.fledgeEnabled).to.exist; - expect(payload.fledgeEnabled).to.exist.and.to.equal(false); - }); - }); - describe('interpretResponse', function () { - const request = getBannerVideoRequest(); - const response = getBannerVideoNativeResponse(); - const fledgeResponse = getFledgeBannerResponse(); - const requestData = JSON.parse(request.data); - it('Returns an array of valid server responses if response object is valid', function () { - const interpretedResponse = spec.interpretResponse(response, request); - const fledgeInterpretedResponse = spec.interpretResponse(fledgeResponse, request); - expect(interpretedResponse).to.be.an('array').that.is.not.empty; - expect(fledgeInterpretedResponse).to.be.an('object'); - expect(fledgeInterpretedResponse.bids).to.satisfy(function (value) { - return value === null || Array.isArray(value); - }); - expect(fledgeInterpretedResponse.paapi).to.be.an('array').that.is.not.empty; - for (let i = 0; i < interpretedResponse.length; i++) { - const dataItem = interpretedResponse[i]; - expect(dataItem).to.include.all.keys('requestId', 'cpm', 'width', 'height', 'ttl', 'creativeId', 'netRevenue', 'currency', 'meta', 'dealId'); - if (dataItem.meta.mediaType === VIDEO) { - const { context } = requestData.bids.find((item) => item.bidId === dataItem.requestId); - if (context === INSTREAM) { - expect(dataItem).to.include.all.keys('videoCacheKey', 'vastUrl'); - expect(dataItem.vastUrl).to.be.a('string'); - expect(dataItem.videoCacheKey).to.be.a('string'); - } else if (context === OUTSTREAM) { - expect(dataItem).to.include.all.keys('renderer', 'vastXml', 'vastUrl'); - expect(dataItem.renderer).to.be.an('object'); - expect(dataItem.vastUrl).to.be.a('string'); - expect(dataItem.vastXml).to.be.a('string'); - } - } else if (dataItem.meta.mediaType === BANNER) { - expect(dataItem).to.include.all.keys('ad'); - expect(dataItem.ad).to.be.a('string'); - } else if (dataItem.meta.mediaType === NATIVE || dataItem.meta.mediaType === NATIVE + NATIVE_SUFFIX) { - expect(dataItem).to.include.all.keys('native'); - expect(dataItem.native).to.be.an('object'); - } - expect(dataItem.requestId).to.be.a('string'); - expect(dataItem.cpm).to.be.a('number'); - expect(dataItem.width).to.be.a('number'); - expect(dataItem.height).to.be.a('number'); - expect(dataItem.ttl).to.be.a('number'); - expect(dataItem.creativeId).to.be.a('string'); - expect(dataItem.netRevenue).to.be.a('boolean'); - expect(dataItem.currency).to.be.a('string'); - expect(dataItem.meta.advertiserDomains).to.be.an('array'); - } - }); - it('Returns an empty array if response is not valid', function () { - const serverResponses = spec.interpretResponse('invalid_response', { data: '{}' }); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Returns meta dsa field if dsa field is present in response', function () { - const dsaResponseObj = { - 'behalf': 'Advertiser', - 'paid': 'Advertiser', - 'transparency': { - 'domain': 'dsp1domain.com', - 'params': [1, 2] - }, - 'adrender': 1 - }; - const responseWithDsa = {...response}; - responseWithDsa.body.bids.forEach(bid => bid.dsa = {...dsaResponseObj}); - const serverResponse = spec.interpretResponse(responseWithDsa, request); - serverResponse.forEach(bid => expect(bid.meta.dsa).to.deep.equals(dsaResponseObj)); - }); - }); - describe('getUserSyncs', function () { - const sync_endpoint = 'https://onetag-sys.com/usync/'; - it('Returns an iframe if iframeEnabled is true', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }); - expect(syncs).to.be.an('array'); - expect(syncs.length).to.equal(1); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.include(sync_endpoint); - }); - it('Returns an empty array if iframeEnabled is false', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: false }); - expect(syncs).to.be.an('array').that.is.empty; - }); - it('Must pass gdpr params when gdprApplies is true', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, { - gdprApplies: true, consentString: 'foo' - }); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.include(sync_endpoint); - expect(syncs[0].url).to.match(/(?:[?&](?:gdpr_consent=foo([^&]*)|gdpr=1([^&]*)|[^&]*))+$/); - }); - it('Must pass gdpr params when gdprApplies is false', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, { - gdprApplies: false, consentString: 'foo' - }); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.include(sync_endpoint); - expect(syncs[0].url).to.match(/(?:[?&](?:gdpr_consent=foo([^&]*)|gdpr=0([^&]*)))+$/); - }); - it('Must pass gdpr consent string param when gdprApplies is undefined', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, { - consentString: 'foo' - }); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.include(sync_endpoint); - expect(syncs[0].url).to.match(/(?:[?&](?:gdpr_consent=foo([^&]*)))+$/); - }); - it('Must pass no gdpr params when consentString is null', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, { - consentString: null - }); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.include(sync_endpoint); - expect(syncs[0].url).to.not.match(/(?:[?&](?:gdpr_consent=([^&]*)|gdpr=([^&]*)))+$/); - }); - it('Must pass no gdpr param when gdprConsent is empty', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, {}); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.include(sync_endpoint); - expect(syncs[0].url).to.not.match(/(?:[?&](?:gdpr_consent=([^&]*)|gdpr=([^&]*)))+$/); - }); - it('Must pass gpp consent string when gppConsent object is available', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, {}, {}, { - gppString: 'foo' - }); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.include(sync_endpoint); - expect(syncs[0].url).to.match(/(?:[?&](?:gpp_consent=foo([^&]*)))+$/); - }); - it('Must pass no gpp params when consentString is null', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, {}, {}, { - gppString: null - }); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.include(sync_endpoint); - expect(syncs[0].url).to.not.match(/(?:[?&](?:gpp_consent=([^&]*)))+$/); - }); - it('Must pass no gpp params when consentString is empty', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, {}, {}, {}); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.include(sync_endpoint); - expect(syncs[0].url).to.not.match(/(?:[?&](?:gpp_consent=([^&]*)))+$/); - }); - it('Should send us privacy string', function () { - const usConsentString = 'us_foo'; - const syncs = spec.getUserSyncs({ iframeEnabled: true }, {}, {}, usConsentString); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.include(sync_endpoint); - expect(syncs[0].url).to.match(/(?:[?&](?:us_privacy=us_foo(?:[&][^&]*)*))+$/); - }); - }); - describe('isSchainValid', function () { - it('Should return false when schain is null or undefined', function () { - expect(isSchainValid(null)).to.be.false; - expect(isSchainValid(undefined)).to.be.false; - }); - it('Should return false when schain is missing nodes key', function () { - const schain = { 'otherKey': 'otherValue' }; - expect(isSchainValid(schain)).to.be.false; - }); - it('Should return false when schain is missing one of the required SupplyChainNode attribute', function () { - const missingAsiNode = { 'sid': '00001', 'hp': 1 }; - const missingSidNode = { 'asi': 'indirectseller.com', 'hp': 1 }; - const missingHpNode = { 'asi': 'indirectseller.com', 'sid': '00001' }; - expect(isSchainValid({ 'config': { 'nodes': [missingAsiNode] } })).to.be.false; - expect(isSchainValid({ 'config': { 'nodes': [missingSidNode] } })).to.be.false; - expect(isSchainValid({ 'config': { 'nodes': [missingHpNode] } })).to.be.false; - }); - it('Should return true when schain contains all required attributes', function () { - const validSchain = { - 'nodes': [ - { - 'asi': 'indirectseller.com', - 'sid': '00001', - 'hp': 1 - } - ] - }; - expect(isSchainValid(validSchain)).to.be.true; - }) - }); -}); - -function getBannerVideoNativeResponse() { - return { - body: { - nobid: false, - bids: [ - { - ad: '
Advertising
', - cpm: 13, - width: 300, - height: 250, - creativeId: '1820', - dealId: 'dishfo', - currency: 'USD', - requestId: 'banner', - mediaType: BANNER, - adomain: [] - }, - { - cpm: 13, - width: 300, - height: 250, - creativeId: '1820', - dealId: 'dishfo', - currency: 'USD', - requestId: 'videoInstream', - vastUrl: 'https://videoinstream.org', - videoCacheKey: 'key', - mediaType: VIDEO, - adomain: ['test_domain'] - }, - { - cpm: 13, - width: 300, - height: 250, - creativeId: '1820', - dealId: 'dishfo', - currency: 'USD', - vastUrl: 'https://videooutstream.org', - requestId: 'videoOutstream', - ad: '', - rendererUrl: 'https://testRenderer', - mediaType: VIDEO, - adomain: [] - }, - { - requestId: 'nativeRequestId', - cpm: 10, - width: 300, - height: 600, - adomain: ['test-domain'], - creativeId: '1821', - mediaType: 'nativeAd', - native: { - ortb: { - ver: '1.2', - assets: [ - { - id: 1, - title: { - text: 'test-title', - len: 9 - } - }], - link: { - url: 'test-url', - clicktrackers: ['test-clicktracker'] - }, - eventtrackers: [ - { - event: 1, - method: 1, - url: 'test-url' - } - ] - } - }, - currency: 'EUR', - } - ] - } - }; -} - -function getFledgeBannerResponse() { - const bannerVideoResponse = getBannerVideoNativeResponse(); - bannerVideoResponse.body.fledgeAuctionConfigs = [ - { - bidId: 'fledge', - config: { - seller: 'https://onetag-sys.com', - decisionLogicUrl: - 'https://onetag-sys.com/paapi/decision_logic.js', - interestGroupBuyers: [ - 'https://onetag-sys.com' - ], - } - } - ] - return bannerVideoResponse; -} - -function getBannerVideoRequest() { - return { - data: JSON.stringify({ - bids: [ - { - adUnitCode: 'target-div', - bidId: 'videoOutstream', - bidderRequestId: '12bb1e0f9fb669', - auctionId: '80784b4d-79ad-49ef-a006-75d8888b7609', - transactionId: '5f132731-3091-49b2-8fab-0e9c917733bc', - pubId: '386276e072', - context: 'outstream', - mimes: [], - playerSize: [], - type: 'video' - }, - { - adUnitCode: 'target-div', - bidId: 'videoInstream', - bidderRequestId: '12bb1e0f9fb669', - auctionId: '80784b4d-79ad-49ef-a006-75d8888b7609', - transactionId: '5f132731-3091-49b2-8fab-0e9c917733bc', - pubId: '386276e072', - context: 'instream', - mimes: [], - playerSize: [], - type: 'video' - } - ], - location: 'https%3A%2F%2Flocal.onetag.net%3A9000%2Fv2%2Fprebid-video%2Fvideo.html%3Fpbjs_debug%3Dtrue', - referrer: '0', - masked: 0, - wWidth: 860, - wHeight: 949, - oWidth: 1853, - oHeight: 1053, - sWidth: 1920, - sHeight: 1080, - aWidth: 1920, - aHeight: 1053, - sLeft: 1987, - sTop: 27, - xOffset: 0, - yOffset: 0, - docHidden: false, - hLength: 2, - timing: { - pageLoadTime: -1593433770022, - connectTime: 42, - renderTime: -1593433770092 - }, - onetagSid: 'user_id' - }) - } -} diff --git a/test/spec/modules/onomagicBidAdapter_spec.js b/test/spec/modules/onomagicBidAdapter_spec.js deleted file mode 100644 index 6b4d44f49..000000000 --- a/test/spec/modules/onomagicBidAdapter_spec.js +++ /dev/null @@ -1,297 +0,0 @@ -import { expect } from 'chai'; -import * as utils from 'src/utils.js'; -import { spec } from 'modules/onomagicBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import * as winDimensions from 'src/utils/winDimensions.js'; - -const URL = 'https://bidder.onomagic.com/hb'; - -describe('onomagicBidAdapter', function() { - const adapter = newBidder(spec); - let element, win; - let bidRequests; - let sandbox; - - beforeEach(function() { - element = { - x: 0, - y: 0, - - width: 0, - height: 0, - - getBoundingClientRect: () => { - return { - width: element.width, - height: element.height, - - left: element.x, - top: element.y, - right: element.x + element.width, - bottom: element.y + element.height - }; - } - }; - win = { - document: { - visibilityState: 'visible' - }, - - innerWidth: 800, - innerHeight: 600 - }; - bidRequests = [{ - 'bidder': 'onomagic', - 'params': { - 'publisherId': 1234567 - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 600]] - } - }, - 'bidId': '5fb26ac22bde4', - 'bidderRequestId': '4bf93aeb730cb9', - 'auctionId': 'ffe9a1f7-7b67-4bda-a8e0-9ee5dc9f442e' - }]; - - sandbox = sinon.createSandbox(); - sandbox.stub(document, 'getElementById').withArgs('adunit-code').returns(element); - sandbox.stub(utils, 'getWindowTop').returns(win); - sandbox.stub(utils, 'getWindowSelf').returns(win); - }); - - afterEach(function() { - sandbox.restore(); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'onomagic', - 'params': { - 'publisherId': 1234567 - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 600]] - } - }, - 'bidId': '5fb26ac22bde4', - 'bidderRequestId': '4bf93aeb730cb9', - 'auctionId': 'ffe9a1f7-7b67-4bda-a8e0-9ee5dc9f442e', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when publisherId not passed correctly', function () { - bid.params.publisherId = undefined; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when require params are not passed', function () { - const invalidBid = Object.assign({}, bid); - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('sends bid request to our endpoint via POST', function () { - const request = spec.buildRequests(bidRequests); - expect(request.method).to.equal('POST'); - }); - - it('request url should match our endpoint url', function () { - const request = spec.buildRequests(bidRequests); - expect(request.url).to.equal(URL); - }); - - it('sets the proper banner object', function() { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]); - }); - - it('accepts a single array as a size', function() { - bidRequests[0].mediaTypes.banner.sizes = [300, 250]; - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}]); - }); - - it('sends bidfloor param if present', function () { - bidRequests[0].params.bidFloor = 0.05; - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].bidfloor).to.equal(0.05); - }); - - it('sends tagid', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].tagid).to.equal('adunit-code'); - }); - - it('sends publisher id', function () { - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.site.publisher.id).to.equal(1234567); - }); - - context('when element is fully in view', function() { - it('returns 100', function() { - Object.assign(element, { width: 600, height: 400 }); - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.ext.viewability).to.equal(100); - }); - }); - - context('when element is out of view', function() { - it('returns 0', function() { - Object.assign(element, { x: -300, y: 0, width: 207, height: 320 }); - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.ext.viewability).to.equal(0); - }); - }); - - context('when element is partially in view', function() { - it('returns percentage', function() { - const getWinDimensionsStub = sandbox.stub(winDimensions, 'getWinDimensions') - getWinDimensionsStub.returns({ innerHeight: win.innerHeight, innerWidth: win.innerWidth }); - Object.assign(element, { width: 800, height: 800 }); - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.ext.viewability).to.equal(75); - }); - }); - - context('when width or height of the element is zero', function() { - it('try to use alternative values', function() { - const getWinDimensionsStub = sandbox.stub(winDimensions, 'getWinDimensions') - getWinDimensionsStub.returns({ innerHeight: win.innerHeight, innerWidth: win.innerWidth }); - Object.assign(element, { width: 0, height: 0 }); - bidRequests[0].mediaTypes.banner.sizes = [[800, 2400]]; - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.ext.viewability).to.equal(25); - }); - }); - - context('when nested iframes', function() { - it('returns \'na\'', function() { - Object.assign(element, { width: 600, height: 400 }); - - utils.getWindowTop.restore(); - utils.getWindowSelf.restore(); - sandbox.stub(utils, 'getWindowTop').returns(win); - sandbox.stub(utils, 'getWindowSelf').returns({}); - - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.ext.viewability).to.equal('na'); - }); - }); - - context('when tab is inactive', function() { - it('returns 0', function() { - Object.assign(element, { width: 600, height: 400 }); - - utils.getWindowTop.restore(); - win.document.visibilityState = 'hidden'; - sandbox.stub(utils, 'getWindowTop').returns(win); - - const request = spec.buildRequests(bidRequests); - const payload = JSON.parse(request.data); - expect(payload.imp[0].banner.ext.viewability).to.equal(0); - }); - }); - }); - - describe('interpretResponse', function () { - let response; - beforeEach(function () { - response = { - body: { - 'id': '37386aade21a71', - 'seatbid': [{ - 'bid': [{ - 'id': '376874781', - 'impid': '283a9f4cd2415d', - 'price': 0.35743275, - 'nurl': '', - 'adm': '', - 'w': 300, - 'h': 250, - 'adomain': ['example.com'] - }] - }] - } - }; - }); - - it('should get the correct bid response', function () { - const expectedResponse = [{ - 'requestId': '283a9f4cd2415d', - 'cpm': 0.35743275, - 'width': 300, - 'height': 250, - 'creativeId': '376874781', - 'currency': 'USD', - 'netRevenue': true, - 'mediaType': 'banner', - 'ad': `
`, - 'ttl': 60, - 'meta': { - 'advertiserDomains': ['example.com'] - } - }]; - - const result = spec.interpretResponse(response); - expect(result[0]).to.deep.equal(expectedResponse[0]); - }); - - it('crid should default to the bid id if not on the response', function () { - const expectedResponse = [{ - 'requestId': '283a9f4cd2415d', - 'cpm': 0.35743275, - 'width': 300, - 'height': 250, - 'creativeId': response.body.seatbid[0].bid[0].id, - 'currency': 'USD', - 'netRevenue': true, - 'mediaType': 'banner', - 'ad': `
`, - 'ttl': 60, - 'meta': { - 'advertiserDomains': ['example.com'] - } - }]; - - const result = spec.interpretResponse(response); - expect(result[0]).to.deep.equal(expectedResponse[0]); - }); - - it('handles empty bid response', function () { - const response = { - body: '' - }; - const result = spec.interpretResponse(response); - expect(result.length).to.equal(0); - }); - }); - - describe('getUserSyncs ', () => { - const syncOptions = {iframeEnabled: true, pixelEnabled: true}; - - it('should not return', () => { - const returnStatement = spec.getUserSyncs(syncOptions, []); - expect(returnStatement).to.be.empty; - }); - }); -}); diff --git a/test/spec/modules/ooloAnalyticsAdapter_spec.js b/test/spec/modules/ooloAnalyticsAdapter_spec.js deleted file mode 100644 index 3a86f567f..000000000 --- a/test/spec/modules/ooloAnalyticsAdapter_spec.js +++ /dev/null @@ -1,793 +0,0 @@ -import ooloAnalytics, { PAGEVIEW_ID } from 'modules/ooloAnalyticsAdapter.js'; -import {expect} from 'chai'; -import {server} from 'test/mocks/xhr.js'; -import { EVENTS } from 'src/constants.js' -import * as events from 'src/events' -import { config } from 'src/config'; -import { buildAuctionData, generatePageViewId } from 'modules/ooloAnalyticsAdapter'; - -const auctionId = '0ea14159-2058-4b87-a966-9d7652176a56'; -const auctionStart = 1598513385415 -const timeout = 3000 -const adUnit1 = 'top_1'; -const adUnit2 = 'top_2'; -const bidId1 = '392b5a6b05d648' -const bidId2 = '392b5a6b05d649' -const bidId3 = '392b5a6b05d650' - -const auctionInit = { - timestamp: auctionStart, - auctionId: auctionId, - timeout: timeout, - auctionStart, - adUnits: [{ - code: adUnit1, - transactionId: 'abalksdkjfh-12sade' - }, { - code: adUnit2, - transactionId: 'abalksdkjfh-12sadf' - }] -}; - -const bidRequested = { - auctionId, - bidderCode: 'appnexus', - bidderRequestId: '2946b569352ef2', - start: 1598513405254, - bids: [ - { - auctionId, - bidId: bidId1, - bidderRequestId: '2946b569352ef2', - bidder: 'appnexus', - adUnitCode: adUnit1, - sizes: [[728, 90], [970, 90]], - mediaTypes: { - banner: { - sizes: [[728, 90], [970, 90]], - }, - }, - params: { - placementId: '4799418', - }, - schain: {} - }, - { - auctionId, - bidId: bidId2, - bidderRequestId: '2946b569352ef3', - bidder: 'rubicon', - adUnitCode: adUnit2, - sizes: [[728, 90], [970, 90]], - mediaTypes: { - banner: { - sizes: [[728, 90], [970, 90]], - }, - }, - params: { - placementId: '4799418', - }, - schain: {} - }, - { - auctionId, - bidId: bidId3, - bidderRequestId: '2946b569352ef4', - bidder: 'ix', - adUnitCode: adUnit2, - sizes: [[728, 90], [970, 90]], - mediaTypes: { - banner: { - sizes: [[728, 90], [970, 90]], - }, - }, - params: { - placementId: '4799418', - }, - schain: {} - }, - ], -} - -const noBid = { - auctionId, - adUnitCode: adUnit2, - bidId: bidId2, - requestId: bidId2 -} - -const bidResponse = { - auctionId, - bidderCode: 'appnexus', - mediaType: 'banner', - width: 0, - height: 0, - statusMessage: 'Bid available', - adId: '222bb26f9e8bd', - cpm: 0.112256, - responseTimestamp: 1598513485254, - requestTimestamp: 1462919238936, - bidder: 'appnexus', - adUnitCode: adUnit1, - timeToRespond: 401, - pbLg: '0.00', - pbMg: '0.10', - pbHg: '0.11', - pbAg: '0.10', - size: '0x0', - requestId: bidId1, - creativeId: '123456', - adserverTargeting: { - hb_bidder: 'appnexus', - hb_adid: '222bb26f9e8bd', - hb_pb: '10.00', - hb_size: '0x0', - foobar: '0x0', - }, - netRevenue: true, - currency: 'USD', - ttl: 300, -} - -const auctionEnd = { - auctionId: auctionId -}; - -const bidTimeout = [ - { - adUnitCode: adUnit2, - auctionId: auctionId, - bidId: bidId3, - bidder: 'ix', - timeout: timeout - } -]; - -const bidWon = { - auctionId, - adUnitCode: adUnit1, - bidId: bidId1, - cpm: 0.5 -} - -function simulateAuction () { - events.emit(EVENTS.AUCTION_INIT, auctionInit); - events.emit(EVENTS.BID_REQUESTED, bidRequested); - events.emit(EVENTS.BID_RESPONSE, bidResponse); - events.emit(EVENTS.NO_BID, noBid); - events.emit(EVENTS.BID_TIMEOUT, bidTimeout); - events.emit(EVENTS.AUCTION_END, auctionEnd); -} - -describe('oolo Prebid Analytic', () => { - let clock - - beforeEach(() => { - sinon.stub(events, 'getEvents').returns([]); - clock = sinon.useFakeTimers() - }); - - afterEach(() => { - ooloAnalytics.disableAnalytics(); - events.getEvents.restore() - clock.restore(); - }) - - describe('enableAnalytics init options', () => { - it('should not enable analytics if invalid config', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: undefined - } - }) - - expect(server.requests).to.have.length(0) - }) - - it('should send prebid config to the server', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - - const conf = {} - const pbjsConfig = JSON.parse(JSON.stringify(config.getConfig())) - - Object.keys(pbjsConfig).forEach(key => { - if (key[0] !== '_') { - conf[key] = pbjsConfig[key] - } - }) - - expect(server.requests[1].url).to.contain('/hbconf') - expect(JSON.parse(server.requests[1].requestBody)).to.deep.equal(conf) - }) - - it('should request server config and send page data', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - clock.next() - - expect(server.requests[0].url).to.contain('?pid=123') - - const pageData = JSON.parse(server.requests[2].requestBody) - - expect(pageData).to.have.property('timestamp') - expect(pageData).to.have.property('screenWidth') - expect(pageData).to.have.property('screenHeight') - expect(pageData).to.have.property('url') - expect(pageData).to.have.property('protocol') - expect(pageData).to.have.property('origin') - expect(pageData).to.have.property('referrer') - expect(pageData).to.have.property('pbVersion') - expect(pageData).to.have.property('pvid') - expect(pageData).to.have.property('pid') - expect(pageData).to.have.property('pbModuleVersion') - expect(pageData).to.have.property('domContentLoadTime') - expect(pageData).to.have.property('pageLoadTime') - }) - }) - - describe('data handling and sending events', () => { - it('should send an "auction" event to the server', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - clock.next() - - server.requests[0].respond(500) - - simulateAuction() - - expect(server.requests.length).to.equal(3) - clock.tick(2000) - expect(server.requests.length).to.equal(4) - - const request = JSON.parse(server.requests[3].requestBody); - - expect(request).to.include({ - eventType: 'auction', - pid: 123, - auctionId, - auctionStart, - auctionEnd: 0, - timeout, - }) - expect(request.pvid).to.be.a('number') - expect(request.adUnits).to.have.length(2) - - const auctionAdUnit1 = request.adUnits.filter(adUnit => adUnit.adunid === adUnit1)[0] - const auctionAdUnit2 = request.adUnits.filter(adUnit => adUnit.adunid === adUnit2)[0] - - expect(auctionAdUnit1.auctionId).to.equal(auctionId) - expect(auctionAdUnit1.bids).to.be.an('array') - expect(auctionAdUnit1.bids).to.have.length(1) - - // bid response - expect(auctionAdUnit1.bids[0].bidId).to.equal(bidId1) - expect(auctionAdUnit1.bids[0].bst).to.equal('bidReceived') - expect(auctionAdUnit1.bids[0].bidder).to.equal('appnexus') - expect(auctionAdUnit1.bids[0].cpm).to.equal(0.112256) - expect(auctionAdUnit1.bids[0].cur).to.equal('USD') - expect(auctionAdUnit1.bids[0].s).to.equal(bidRequested.start) - expect(auctionAdUnit1.bids[0].e).to.equal(bidResponse.responseTimestamp) - expect(auctionAdUnit1.bids[0].rs).to.equal(bidRequested.start - auctionStart) - expect(auctionAdUnit1.bids[0].re).to.equal(bidResponse.responseTimestamp - auctionStart) - expect(auctionAdUnit1.bids[0].h).to.equal(0) - expect(auctionAdUnit1.bids[0].w).to.equal(0) - expect(auctionAdUnit1.bids[0].mt).to.equal('banner') - expect(auctionAdUnit1.bids[0].nrv).to.equal(true) - expect(auctionAdUnit1.bids[0].params).to.have.keys('placementId') - expect(auctionAdUnit1.bids[0].size).to.equal('0x0') - expect(auctionAdUnit1.bids[0].crId).to.equal('123456') - expect(auctionAdUnit1.bids[0].ttl).to.equal(bidResponse.ttl) - expect(auctionAdUnit1.bids[0].ttr).to.equal(bidResponse.timeToRespond) - - expect(auctionAdUnit2.auctionId).to.equal(auctionId) - expect(auctionAdUnit2.bids).to.be.an('array') - expect(auctionAdUnit2.bids).to.have.length(2) - - // no bid - expect(auctionAdUnit2.bids[0].bidId).to.equal(bidId2) - expect(auctionAdUnit2.bids[0].bst).to.equal('noBid') - expect(auctionAdUnit2.bids[0].bidder).to.equal('rubicon') - expect(auctionAdUnit2.bids[0].s).to.be.a('number') - expect(auctionAdUnit2.bids[0].e).to.be.a('number') - expect(auctionAdUnit2.bids[0].params).to.have.keys('placementId') - - // timeout - expect(auctionAdUnit2.bids[1].bidId).to.equal(bidId3) - expect(auctionAdUnit2.bids[1].bst).to.equal('bidTimedOut') - expect(auctionAdUnit2.bids[1].bidder).to.equal('ix') - expect(auctionAdUnit2.bids[1].s).to.be.a('number') - expect(auctionAdUnit2.bids[1].e).to.be.a('undefined') - }) - - it('should push events to a queue and process them once server configuration returns', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - - events.emit(EVENTS.AUCTION_INIT, auctionInit); - events.emit(EVENTS.BID_REQUESTED, bidRequested); - events.emit(EVENTS.BID_RESPONSE, bidResponse); - - // configuration returned in an arbitrary moment - server.requests[0].respond(500) - - events.emit(EVENTS.NO_BID, noBid); - events.emit(EVENTS.BID_TIMEOUT, bidTimeout); - events.emit(EVENTS.AUCTION_END, auctionEnd); - - clock.tick(1500) - - const request = JSON.parse(server.requests[3].requestBody); - - expect(request).to.include({ - eventType: 'auction', - pid: 123, - auctionId, - auctionStart, - auctionEnd: 0, - timeout, - }) - expect(request.pvid).to.be.a('number') - expect(request.adUnits).to.have.length(2) - - const auctionAdUnit1 = request.adUnits.filter(adUnit => adUnit.adunid === adUnit1)[0] - const auctionAdUnit2 = request.adUnits.filter(adUnit => adUnit.adunid === adUnit2)[0] - - expect(auctionAdUnit1.auctionId).to.equal(auctionId) - expect(auctionAdUnit1.bids).to.be.an('array') - expect(auctionAdUnit1.bids).to.have.length(1) - - // bid response - expect(auctionAdUnit1.bids[0].bidId).to.equal(bidId1) - expect(auctionAdUnit1.bids[0].bst).to.equal('bidReceived') - expect(auctionAdUnit1.bids[0].bidder).to.equal('appnexus') - expect(auctionAdUnit1.bids[0].cpm).to.equal(0.112256) - expect(auctionAdUnit1.bids[0].cur).to.equal('USD') - expect(auctionAdUnit1.bids[0].s).to.equal(bidRequested.start) - expect(auctionAdUnit1.bids[0].e).to.equal(bidResponse.responseTimestamp) - expect(auctionAdUnit1.bids[0].rs).to.equal(bidRequested.start - auctionStart) - expect(auctionAdUnit1.bids[0].re).to.equal(bidResponse.responseTimestamp - auctionStart) - expect(auctionAdUnit1.bids[0].h).to.equal(0) - expect(auctionAdUnit1.bids[0].w).to.equal(0) - expect(auctionAdUnit1.bids[0].mt).to.equal('banner') - expect(auctionAdUnit1.bids[0].nrv).to.equal(true) - expect(auctionAdUnit1.bids[0].params).to.have.keys('placementId') - expect(auctionAdUnit1.bids[0].size).to.equal('0x0') - expect(auctionAdUnit1.bids[0].crId).to.equal('123456') - expect(auctionAdUnit1.bids[0].ttl).to.equal(bidResponse.ttl) - expect(auctionAdUnit1.bids[0].ttr).to.equal(bidResponse.timeToRespond) - - expect(auctionAdUnit2.auctionId).to.equal(auctionId) - expect(auctionAdUnit2.bids).to.be.an('array') - expect(auctionAdUnit2.bids).to.have.length(2) - - // no bid - expect(auctionAdUnit2.bids[0].bidId).to.equal(bidId2) - expect(auctionAdUnit2.bids[0].bst).to.equal('noBid') - expect(auctionAdUnit2.bids[0].bidder).to.equal('rubicon') - expect(auctionAdUnit2.bids[0].s).to.be.a('number') - expect(auctionAdUnit2.bids[0].e).to.be.a('number') - expect(auctionAdUnit2.bids[0].params).to.have.keys('placementId') - - // timeout - expect(auctionAdUnit2.bids[1].bidId).to.equal(bidId3) - expect(auctionAdUnit2.bids[1].bst).to.equal('bidTimedOut') - expect(auctionAdUnit2.bids[1].bidder).to.equal('ix') - expect(auctionAdUnit2.bids[1].s).to.be.a('number') - expect(auctionAdUnit2.bids[1].e).to.be.a('undefined') - }) - - it('should send "auction" event without all the fields that were set to undefined', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - - server.requests[0].respond(500) - - simulateAuction() - clock.tick(1500) - - const request = JSON.parse(server.requests[3].requestBody); - - const auctionAdUnit1 = request.adUnits.filter(adUnit => adUnit.adunid === adUnit1)[0] - const auctionAdUnit2 = request.adUnits.filter(adUnit => adUnit.adunid === adUnit2)[0] - - expect(auctionAdUnit1.code).to.equal(undefined) - expect(auctionAdUnit1.transactionId).to.equal(undefined) - expect(auctionAdUnit1.adUnitCode).to.equal(undefined) - expect(auctionAdUnit1.bids[0].auctionStart).to.equal(undefined) - expect(auctionAdUnit1.bids[0].bids).to.equal(undefined) - expect(auctionAdUnit1.bids[0].refererInfo).to.equal(undefined) - expect(auctionAdUnit1.bids[0].bidRequestsCount).to.equal(undefined) - expect(auctionAdUnit1.bids[0].bidderRequestId).to.equal(undefined) - expect(auctionAdUnit1.bids[0].bidderRequestsCount).to.equal(undefined) - expect(auctionAdUnit1.bids[0].bidderWinsCount).to.equal(undefined) - expect(auctionAdUnit1.bids[0].schain).to.equal(undefined) - expect(auctionAdUnit1.bids[0].src).to.equal(undefined) - expect(auctionAdUnit1.bids[0].transactionId).to.equal(undefined) - - // no bid - expect(auctionAdUnit2.bids[0].schain).to.equal(undefined) - expect(auctionAdUnit2.bids[0].src).to.equal(undefined) - expect(auctionAdUnit2.bids[0].transactionId).to.equal(undefined) - }) - - it('should mark bid winner and send to the server along with the auction data', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - - server.requests[0].respond(500) - simulateAuction() - events.emit(EVENTS.BID_WON, bidWon); - clock.tick(1500) - - // no bidWon - expect(server.requests).to.have.length(4) - - const request = JSON.parse(server.requests[3].requestBody); - expect(request.adUnits[0].bids[0].isW).to.equal(true) - }) - - it('should take BID_WON_TIMEOUT from server config if exists', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - - server.requests[0].respond(200, {}, JSON.stringify({ - 'events': {}, - 'BID_WON_TIMEOUT': 500 - })) - - simulateAuction() - events.emit(EVENTS.BID_WON, bidWon); - clock.tick(499) - - // no auction data - expect(server.requests).to.have.length(3) - - clock.tick(1) - - // auction data - expect(server.requests).to.have.length(4) - const request = JSON.parse(server.requests[3].requestBody); - expect(request.adUnits[0].bids[0].isW).to.equal(true) - }) - - it('should send a "bidWon" event to the server', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - - server.requests[0].respond(500) - simulateAuction() - clock.tick(1500) - events.emit(EVENTS.BID_WON, bidWon); - - expect(server.requests).to.have.length(5) - - const request = JSON.parse(server.requests[4].requestBody); - - expect(request.eventType).to.equal('bidWon') - expect(request.auctionId).to.equal(auctionId) - expect(request.adunid).to.equal(adUnit1) - expect(request.bid.bst).to.equal('bidWon') - expect(request.bid.cur).to.equal('USD') - expect(request.bid.cpm).to.equal(0.5) - }) - - it('should sent adRenderFailed to the server', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - - server.requests[0].respond(500) - simulateAuction() - clock.tick(1500) - events.emit(EVENTS.AD_RENDER_FAILED, { bidId: 'abcdef', reason: 'exception' }); - - expect(server.requests).to.have.length(5) - - const request = JSON.parse(server.requests[4].requestBody); - - expect(request.eventType).to.equal('adRenderFailed') - expect(request.pvid).to.equal(PAGEVIEW_ID) - expect(request.bidId).to.equal('abcdef') - expect(request.reason).to.equal('exception') - }) - - it('should pick fields according to server configuration', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - - server.requests[0].respond(200, {}, JSON.stringify({ - 'events': { - 'bidRequested': { - 'sendRaw': 0, - 'pickFields': ['transactionId'] - }, - 'noBid': { - 'sendRaw': 0, - 'pickFields': ['src'] - }, - 'bidResponse': { - 'sendRaw': 0, - 'pickFields': ['adUrl', 'statusMessage'] - }, - 'auctionEnd': { - 'sendRaw': 0, - 'pickFields': ['winningBids'] - }, - } - })) - - events.emit(EVENTS.AUCTION_INIT, { ...auctionInit }); - events.emit(EVENTS.BID_REQUESTED, { ...bidRequested, bids: bidRequested.bids.map(b => { b.transactionId = '123'; return b }) }); - events.emit(EVENTS.NO_BID, { ...noBid, src: 'client' }); - events.emit(EVENTS.BID_RESPONSE, { ...bidResponse, adUrl: '...' }); - events.emit(EVENTS.AUCTION_END, { ...auctionEnd, winningBids: [] }); - events.emit(EVENTS.BID_WON, { ...bidWon, statusMessage: 'msg2' }); - - clock.tick(1500) - - const request = JSON.parse(server.requests[3].requestBody) - - expect(request.adUnits[0].bids[0].transactionId).to.equal('123') - expect(request.adUnits[0].bids[0].adUrl).to.equal('...') - expect(request.adUnits[0].bids[0].statusMessage).to.equal('msg2') - expect(request.adUnits[1].bids[0].src).to.equal('client') - }) - - it('should omit fields according to server configuration', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - clock.next() - - server.requests[0].respond(200, {}, JSON.stringify({ - 'events': { - 'auctionInit': { - 'sendRaw': 0, - 'omitFields': ['custom_1'] - }, - 'bidResponse': { - 'sendRaw': 0, - 'omitFields': ['custom_2', 'custom_4', 'custom_5'] - } - } - })) - - events.emit(EVENTS.AUCTION_INIT, { ...auctionInit, custom_1: true }); - events.emit(EVENTS.BID_REQUESTED, { ...bidRequested, bids: bidRequested.bids.map(b => { b.custom_2 = true; return b }) }); - events.emit(EVENTS.NO_BID, { ...noBid, custom_3: true }); - events.emit(EVENTS.BID_RESPONSE, { ...bidResponse, custom_4: true }); - events.emit(EVENTS.AUCTION_END, { ...auctionEnd }); - events.emit(EVENTS.BID_WON, { ...bidWon, custom_5: true }); - - clock.tick(1500) - - const request = JSON.parse(server.requests[3].requestBody) - - expect(request.custom_1).to.equal(undefined) - expect(request.custom_6).to.equal(undefined) - expect(request.adUnits[0].bids[0].custom_2).to.equal(undefined) - expect(request.adUnits[0].bids[0].custom_4).to.equal(undefined) - expect(request.adUnits[0].bids[0].custom_5).to.equal(undefined) - expect(request.adUnits[0].bids[0].custom_7).to.equal(undefined) - }) - - it('should omit fields from raw data according to server configuration', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - clock.next() - - server.requests[0].respond(200, {}, JSON.stringify({ - 'events': { - 'auctionInit': { - 'sendRaw': 1, - 'omitRawFields': ['custom_1'] - }, - } - })) - - events.emit(EVENTS.AUCTION_INIT, { ...auctionInit, custom_1: true }); - - clock.tick(1500) - - const request = JSON.parse(server.requests[3].requestBody) - - expect(request.eventType).to.equal('auctionInit') - expect(request.custom_1).to.equal(undefined) - }) - - it('should send raw data to custom endpoint if exists in server configuration', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - clock.next() - - server.requests[0].respond(200, {}, JSON.stringify({ - 'events': { - 'auctionInit': { - 'sendRaw': 1, - 'endpoint': 'https://pbjs.com' - }, - } - })) - - events.emit(EVENTS.AUCTION_INIT, { ...auctionInit }); - - expect(server.requests[3].url).to.equal('https://pbjs.com/') - }) - - it('should send raw events based on server configuration', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - clock.next() - - server.requests[0].respond(200, {}, JSON.stringify({ - 'events': { - 'auctionInit': { - 'sendRaw': 0, - }, - 'bidRequested': { - 'sendRaw': 1, - } - } - })) - - events.emit(EVENTS.AUCTION_INIT, auctionInit) - events.emit(EVENTS.BID_REQUESTED, bidRequested); - - const request = JSON.parse(server.requests[3].requestBody) - - expect(request).to.deep.equal({ - eventType: 'bidRequested', - pid: 123, - pvid: PAGEVIEW_ID, - pbModuleVersion: '1.0.0', - ...bidRequested - }) - }) - - it('should queue events and raw events until server configuration resolves', () => { - ooloAnalytics.enableAnalytics({ - provider: 'oolo', - options: { - pid: 123 - } - }) - - simulateAuction() - clock.tick(1500) - - expect(server.requests).to.have.length(3) - - server.requests[0].respond(200, {}, JSON.stringify({ - 'events': { - 'auctionInit': { - 'sendRaw': 1, - }, - 'bidRequested': { - 'sendRaw': 1, - } - } - })) - - expect(server.requests).to.have.length(5) - expect(JSON.parse(server.requests[3].requestBody).eventType).to.equal('auctionInit') - expect(JSON.parse(server.requests[4].requestBody).eventType).to.equal('bidRequested') - }) - }); - - describe('buildAuctionData', () => { - const auction = { - auctionId, - auctionStart, - auctionEnd, - adUnitCodes: ['mid_1'], - auctionStatus: 'running', - bidderRequests: [], - bidsReceived: [], - noBids: [], - winningBids: [], - timestamp: 1234567, - config: {}, - adUnits: { - mid_1: { - adUnitCode: 'mid_1', - code: 'mid_1', - transactionId: '123dsafasdf', - bids: { - [bidId1]: { - adUnitCode: 'mid_1', - cpm: 0.5 - } - } - } - } - } - - it('should turn adUnits and bids objects into arrays', () => { - const auctionData = buildAuctionData(auction, []) - - expect(auctionData.adUnits).to.be.an('array') - expect(auctionData.adUnits[0].bids).to.be.an('array') - }) - - it('should remove fields from the auction', () => { - const auctionData = buildAuctionData(auction, []) - const auctionFields = Object.keys(auctionData) - const adUnitFields = Object.keys(auctionData.adUnits[0]) - - expect(auctionFields).not.to.contain('adUnitCodes') - expect(auctionFields).not.to.contain('auctionStatus') - expect(auctionFields).not.to.contain('bidderRequests') - expect(auctionFields).not.to.contain('bidsReceived') - expect(auctionFields).not.to.contain('noBids') - expect(auctionFields).not.to.contain('winningBids') - expect(auctionFields).not.to.contain('timestamp') - expect(auctionFields).not.to.contain('config') - - expect(adUnitFields).not.to.contain('adUnitCoe') - expect(adUnitFields).not.to.contain('code') - expect(adUnitFields).not.to.contain('transactionId') - }) - }) - - describe('generatePageViewId', () => { - it('should generate a 19 digits number', () => { - expect(generatePageViewId()).length(19) - }) - }) -}); diff --git a/test/spec/modules/opaMarketplaceBidAdapter_spec.js b/test/spec/modules/opaMarketplaceBidAdapter_spec.js deleted file mode 100644 index 4a7b4895a..000000000 --- a/test/spec/modules/opaMarketplaceBidAdapter_spec.js +++ /dev/null @@ -1,785 +0,0 @@ -import {expect} from 'chai'; -import { - spec as adapter, - createDomain, - storage, -} from 'modules/opaMarketplaceBidAdapter'; -import * as utils from 'src/utils.js'; -import {version} from 'package.json'; -import {useFakeTimers} from 'sinon'; -import {BANNER, VIDEO} from '../../../src/mediaTypes.js'; -import {config} from '../../../src/config.js'; -import { - hashCode, - extractPID, - extractCID, - extractSubDomain, - getStorageItem, - setStorageItem, - tryParseJSON, - getUniqueDealId, -} from '../../../libraries/vidazooUtils/bidderUtils.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -export const TEST_ID_SYSTEMS = ['britepoolid', 'criteoId', 'id5id', 'idl_env', 'lipb', 'netId', 'parrableId', 'pubcid', 'tdid', 'pubProvidedId']; - -const SUB_DOMAIN = 'exchange'; - -const BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': 'div-gpt-ad-12345-0', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '59db6b3b4ffaa70004f45cdc', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1, - 'ext': { - 'param1': 'loremipsum', - 'param2': 'dolorsitamet' - } - }, - 'placementCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - 'sizes': [[300, 250], [300, 600]], - 'bidderRequestId': '1fdb5ff1b6eaa7', - 'auctionId': 'auction_id', - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'requestId': 'b0777d85-d061-450e-9bc7-260dd54bbb7a', - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'mediaTypes': [BANNER], - 'ortb2Imp': { - 'ext': { - 'gpid': '0123456789' - } - } -}; - -const VIDEO_BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': '63550ad1ff6642d368cba59dh5884270560', - 'bidderRequestId': '12a8ae9ada9c13', - 'transactionId': '56e184c6-bde9-497b-b9b9-cf47a61381ee', - 'auctionId': 'auction_id', - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '635509f7ff6642d368cb9837', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1 - }, - 'sizes': [[545, 307]], - 'mediaTypes': { - 'video': { - 'playerSize': [[545, 307]], - 'context': 'instream', - 'mimes': [ - 'video/mp4', - 'application/javascript' - ], - 'protocols': [2, 3, 5, 6], - 'maxduration': 60, - 'minduration': 0, - 'startdelay': 0, - 'linearity': 1, - 'api': [2], - 'placement': 1 - } - } -} - -const ORTB2_DEVICE = { - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - ext: {fiftyonedegrees_deviceId: '17595-133085-133468-18092'}, -}; - -const BIDDER_REQUEST = { - 'gdprConsent': { - 'consentString': 'consent_string', - 'gdprApplies': true - }, - 'gppString': 'gpp_string', - 'gppSid': [7], - 'uspConsent': 'consent_string', - 'refererInfo': { - 'page': 'https://www.greatsite.com', - 'ref': 'https://www.somereferrer.com' - }, - 'ortb2': { - 'site': { - 'content': { - 'language': 'en' - } - }, - 'regs': { - 'gpp': 'gpp_string', - 'gpp_sid': [7], - 'coppa': 0 - }, - 'device': ORTB2_DEVICE, - } -}; - -const SERVER_RESPONSE = { - body: { - cid: 'testcid123', - results: [{ - 'ad': '', - 'price': 0.8, - 'creativeId': '12610997325162499419', - 'exp': 30, - 'width': 300, - 'height': 250, - 'advertiserDomains': ['securepubads.g.doubleclick.net'], - 'cookies': [{ - 'src': 'https://sync.com', - 'type': 'iframe' - }, { - 'src': 'https://sync.com', - 'type': 'img' - }] - }] - } -}; - -const VIDEO_SERVER_RESPONSE = { - body: { - 'cid': '635509f7ff6642d368cb9837', - 'results': [{ - 'ad': '', - 'advertiserDomains': ['opamarketplace.com'], - 'exp': 60, - 'width': 545, - 'height': 307, - 'mediaType': 'video', - 'creativeId': '12610997325162499419', - 'price': 2, - 'cookies': [] - }] - } -}; - -const ORTB2_OBJ = { - "device": ORTB2_DEVICE, - "regs": {"coppa": 0, "gpp": "gpp_string", "gpp_sid": [7]}, - "site": {"content": {"language": "en"} - } -}; - -const REQUEST = { - data: { - width: 300, - height: 250, - bidId: '2d52001cabd527' - } -}; - -function getTopWindowQueryParams() { - try { - const parsedUrl = utils.parseUrl(window.top.document.URL, {decodeSearchAsString: true}); - return parsedUrl.search; - } catch (e) { - return ''; - } -} - -describe('OpaMarketplaceBidAdapter', function () { - before(() => config.resetConfig()); - after(() => config.resetConfig()); - - describe('validate spec', function () { - it('exists and is a function', function () { - expect(adapter.isBidRequestValid).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.buildRequests).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.interpretResponse).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.getUserSyncs).to.exist.and.to.be.a('function'); - }); - - it('exists and is a string', function () { - expect(adapter.code).to.exist.and.to.be.a('string'); - }); - - it('exists and contains media types', function () { - expect(adapter.supportedMediaTypes).to.exist.and.to.be.an('array').with.length(2); - expect(adapter.supportedMediaTypes).to.contain.members([BANNER, VIDEO]); - }); - }); - - describe('validate bid requests', function () { - it('should require cId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - pId: 'pid' - } - }); - expect(isValid).to.be.false; - }); - - it('should require pId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid' - } - }); - expect(isValid).to.be.false; - }); - - it('should validate correctly', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid', - pId: 'pid' - } - }); - expect(isValid).to.be.true; - }); - }); - - describe('build requests', function () { - let sandbox; - before(function () { - getGlobal().bidderSettings = { - opamarketplace: { - storageAllowed: true - } - }; - sandbox = sinon.createSandbox(); - sandbox.stub(Date, 'now').returns(1000); - }); - - it('should build video request', function () { - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - config.setConfig({ - bidderTimeout: 3000 - }); - const requests = adapter.buildRequests([VIDEO_BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/635509f7ff6642d368cb9837`, - data: { - adUnitCode: '63550ad1ff6642d368cba59dh5884270560', - bidFloor: 0.1, - bidId: '2d52001cabd527', - bidderVersion: adapter.version, - bidderRequestId: '12a8ae9ada9c13', - cb: 1000, - gdpr: 1, - gdprConsent: 'consent_string', - usPrivacy: 'consent_string', - gppString: 'gpp_string', - gppSid: [7], - prebidVersion: version, - transactionId: '56e184c6-bde9-497b-b9b9-cf47a61381ee', - auctionId: 'auction_id', - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - publisherId: '59ac17c192832d0011283fe3', - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - res: `${window.top.screen.width}x${window.top.screen.height}`, - schain: VIDEO_BID.schain, - sizes: ['545x307'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - uqs: getTopWindowQueryParams(), - mediaTypes: { - video: { - api: [2], - context: 'instream', - linearity: 1, - maxduration: 60, - mimes: [ - 'video/mp4', - 'application/javascript' - ], - minduration: 0, - placement: 1, - playerSize: [[545, 307]], - protocols: [2, 3, 5, 6], - startdelay: 0 - } - }, - gpid: '', - cat: [], - contentLang: 'en', - contentData: [], - isStorageAllowed: true, - pagecat: [], - ortb2: ORTB2_OBJ, - userData: [], - coppa: 0 - } - }); - }); - - it('should build banner request for each size', function () { - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - config.setConfig({ - bidderTimeout: 3000 - }); - const requests = adapter.buildRequests([BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/59db6b3b4ffaa70004f45cdc`, - data: { - gdprConsent: 'consent_string', - gdpr: 1, - gppString: 'gpp_string', - gppSid: [7], - usPrivacy: 'consent_string', - transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - auctionId: 'auction_id', - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - bidderRequestId: '1fdb5ff1b6eaa7', - sizes: ['300x250', '300x600'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - cb: 1000, - bidFloor: 0.1, - bidId: '2d52001cabd527', - adUnitCode: 'div-gpt-ad-12345-0', - publisherId: '59ac17c192832d0011283fe3', - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - bidderVersion: adapter.version, - prebidVersion: version, - schain: BID.schain, - res: `${window.top.screen.width}x${window.top.screen.height}`, - mediaTypes: [BANNER], - gpid: '0123456789', - uqs: getTopWindowQueryParams(), - 'ext.param1': 'loremipsum', - 'ext.param2': 'dolorsitamet', - cat: [], - contentLang: 'en', - contentData: [], - isStorageAllowed: true, - pagecat: [], - ortb2Imp: BID.ortb2Imp, - ortb2: ORTB2_OBJ, - userData: [], - coppa: 0 - } - }); - }); - - after(function () { - getGlobal().bidderSettings = {}; - sandbox.restore(); - }); - }); - describe('getUserSyncs', function () { - it('should have valid user sync with iframeEnabled', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.have.length(1); - const url = new URL(result[0].url); - expect(result[0].type).to.equal('iframe') - expect(url.searchParams.get('cid')).to.equal('testcid123'); - expect(url.searchParams.get('coppa')).to.equal('0'); - expect(url.searchParams.get('gdpr')).to.equal('0'); - }); - - it('should have valid user sync with cid on response', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.have.length(1); - const url = new URL(result[0].url); - expect(result[0].type).to.equal('iframe') - expect(url.searchParams.get('cid')).to.equal('testcid123'); - expect(url.searchParams.get('coppa')).to.equal('0'); - expect(url.searchParams.get('gdpr')).to.equal('0'); - }); - - it('should have valid user sync with pixelEnabled', function () { - const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.have.length(1); - const url = new URL(result[0].url); - expect(result[0].type).to.equal('image') - expect(url.searchParams.get('cid')).to.equal('testcid123'); - expect(url.searchParams.get('coppa')).to.equal('0'); - expect(url.searchParams.get('gdpr')).to.equal('0'); - }); - - it('should have valid user sync with coppa on response', function () { - config.setConfig({ - coppa: 1 - }); - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.have.length(1); - const url = new URL(result[0].url); - expect(result[0].type).to.equal('iframe') - expect(url.searchParams.get('cid')).to.equal('testcid123'); - expect(url.searchParams.get('coppa')).to.equal('1'); - expect(url.searchParams.get('gdpr')).to.equal('0'); - }); - - it('should generate url with consent data', function () { - const gdprConsent = { - gdprApplies: true, - consentString: 'consent_string' - }; - const uspConsent = 'usp_string'; - const gppConsent = { - gppString: 'gpp_string', - applicableSections: [7] - } - - const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE], gdprConsent, uspConsent, gppConsent); - const url = new URL(result[0].url); - expect(result).to.deep.equal([{ - 'url': 'https://sync.opamarketplace.com/api/sync/image/?cid=testcid123&gdpr=1&gdpr_consent=consent_string&us_privacy=usp_string&coppa=1&gpp=gpp_string&gpp_sid=7', - 'type': 'image' - }]); - expect(url.searchParams.get('gdpr_consent')).to.equal('consent_string'); - expect(url.searchParams.get('us_privacy')).to.equal('usp_string'); - expect(url.searchParams.get('gpp')).to.equal('gpp_string'); - expect(url.searchParams.get('gpp_sid')).to.equal('7'); - }); - }); - - describe('interpret response', function () { - it('should return empty array when there is no response', function () { - const responses = adapter.interpretResponse(null); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no ad', function () { - const responses = adapter.interpretResponse({price: 1, ad: ''}); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no price', function () { - const responses = adapter.interpretResponse({price: null, ad: 'great ad'}); - expect(responses).to.be.empty; - }); - - it('should return an array of interpreted banner responses', function () { - const responses = adapter.interpretResponse(SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 0.8, - width: 300, - height: 250, - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 30, - ad: '', - meta: { - advertiserDomains: ['securepubads.g.doubleclick.net'] - } - }); - }); - - it('should get meta from response metaData', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - serverResponse.body.results[0].metaData = { - advertiserDomains: ['opamarketplace.com'], - agencyName: 'Agency Name', - }; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses[0].meta).to.deep.equal({ - advertiserDomains: ['opamarketplace.com'], - agencyName: 'Agency Name' - }); - }); - - it('should return an array of interpreted video responses', function () { - const responses = adapter.interpretResponse(VIDEO_SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 2, - width: 545, - height: 307, - mediaType: 'video', - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 60, - vastXml: '', - meta: { - advertiserDomains: ['opamarketplace.com'] - } - }); - }); - - it('should take default TTL', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - delete serverResponse.body.results[0].exp; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0].ttl).to.equal(300); - }); - }); - - describe('user id system', function () { - TEST_ID_SYSTEMS.forEach((idSystemProvider) => { - const id = Date.now().toString(); - const bid = utils.deepClone(BID); - - const userId = (function () { - switch (idSystemProvider) { - case 'lipb': - return {lipbid: id}; - case 'id5id': - return {uid: id}; - default: - return id; - } - })(); - - bid.userId = { - [idSystemProvider]: userId - }; - - it(`should include 'uid.${idSystemProvider}' in request params`, function () { - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data[`uid.${idSystemProvider}`]).to.equal(id); - }); - }); - // testing bid.userIdAsEids handling - it("should include user ids from bid.userIdAsEids (length=1)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - }) - it("should include user ids from bid.userIdAsEids (length=2)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - }, - { - "source": "rwdcntrl.net", - "uids": [{"id": "fakeid6f35197d5c", "atype": 1}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - expect(requests[0].data['uid.rwdcntrl.net']).to.equal("fakeid6f35197d5c"); - }) - // testing user.ext.eid handling - it("should include user ids from user.ext.eid (length=1)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - }) - it("should include user ids from user.ext.eid (length=2)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - }, - { - "source": "adserver.org", - "uids": [{"id": "fakeid495ff1"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - expect(requests[0].data['uid.adserver.org']).to.equal("fakeid495ff1"); - }) - }); - - describe('alternate param names extractors', function () { - it('should return undefined when param not supported', function () { - const cid = extractCID({'c_id': '1'}); - const pid = extractPID({'p_id': '1'}); - const subDomain = extractSubDomain({'sub_domain': 'prebid'}); - expect(cid).to.be.undefined; - expect(pid).to.be.undefined; - expect(subDomain).to.be.undefined; - }); - - it('should return value when param supported', function () { - const cid = extractCID({'cID': '1'}); - const pid = extractPID({'Pid': '2'}); - const subDomain = extractSubDomain({'subDOMAIN': 'prebid'}); - expect(cid).to.be.equal('1'); - expect(pid).to.be.equal('2'); - expect(subDomain).to.be.equal('prebid'); - }); - }); - - describe('unique deal id', function () { - before(function () { - getGlobal().bidderSettings = { - opamarketplace: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - const key = 'myKey'; - let uniqueDealId; - beforeEach(() => { - uniqueDealId = getUniqueDealId(storage, key, 0); - }) - - it('should get current unique deal id', function (done) { - // waiting some time so `now` will become past - setTimeout(() => { - const current = getUniqueDealId(storage, key); - expect(current).to.be.equal(uniqueDealId); - done(); - }, 200); - }); - - it('should get new unique deal id on expiration', function (done) { - setTimeout(() => { - const current = getUniqueDealId(storage, key, 100); - expect(current).to.not.be.equal(uniqueDealId); - done(); - }, 200) - }); - }); - - describe('storage utils', function () { - before(function () { - getGlobal().bidderSettings = { - opamarketplace: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - it('should get value from storage with create param', function () { - const now = Date.now(); - const clock = useFakeTimers({ - shouldAdvanceTime: true, - now - }); - setStorageItem(storage, 'myKey', 2020); - const {value, created} = getStorageItem(storage, 'myKey'); - expect(created).to.be.equal(now); - expect(value).to.be.equal(2020); - expect(typeof value).to.be.equal('number'); - expect(typeof created).to.be.equal('number'); - clock.restore(); - }); - - it('should get external stored value', function () { - const value = 'superman' - window.localStorage.setItem('myExternalKey', value); - const item = getStorageItem(storage, 'myExternalKey'); - expect(item).to.be.equal(value); - }); - - it('should parse JSON value', function () { - const data = JSON.stringify({event: 'send'}); - const {event} = tryParseJSON(data); - expect(event).to.be.equal('send'); - }); - - it('should get original value on parse fail', function () { - const value = 21; - const parsed = tryParseJSON(value); - expect(typeof parsed).to.be.equal('number'); - expect(parsed).to.be.equal(value); - }); - }); -}); diff --git a/test/spec/modules/open8BidAdapter_spec.js b/test/spec/modules/open8BidAdapter_spec.js deleted file mode 100644 index 049aead51..000000000 --- a/test/spec/modules/open8BidAdapter_spec.js +++ /dev/null @@ -1,258 +0,0 @@ -import { spec } from 'modules/open8BidAdapter'; -import { newBidder } from 'src/adapters/bidderFactory'; - -const ENDPOINT = 'https://as.vt.open8.com/v1/control/prebid'; - -describe('Open8Adapter', function() { - const adapter = newBidder(spec); - - describe('isBidRequestValid', function() { - const bid = { - 'bidder': 'open8', - 'params': { - 'slotKey': 'slotkey1234' - }, - 'adUnitCode': 'adunit', - 'sizes': [[300, 250]], - 'bidId': 'bidid1234', - 'bidderRequestId': 'requestid1234', - 'auctionId': 'auctionid1234', - }; - - it('should return true when required params found', function() { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function() { - bid.params = { - ' slotKey': 0 - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function() { - const bidRequests = [ - { - 'bidder': 'open8', - 'params': { - 'slotKey': 'slotkey1234' - }, - 'adUnitCode': 'adunit', - 'sizes': [[300, 250]], - 'bidId': 'bidid1234', - 'bidderRequestId': 'requestid1234', - 'auctionId': 'auctionid1234', - } - ]; - - it('sends bid request to ENDPOINT via GET', function() { - const requests = spec.buildRequests(bidRequests); - expect(requests[0].url).to.equal(ENDPOINT); - expect(requests[0].method).to.equal('GET'); - }); - }); - describe('interpretResponse', function() { - const adomin = ['example.com'] - const bannerResponse = { - slotKey: 'slotkey1234', - userId: 'userid1234', - impId: 'impid1234', - media: 'TEST_MEDIA', - nurl: '//example/win', - isAdReturn: true, - syncPixels: ['//example/sync/pixel.gif'], - syncIFs: [], - ad: { - bidId: 'TEST_BID_ID', - price: 1234.56, - creativeId: 'creativeid1234', - dealId: 'TEST_DEAL_ID', - currency: 'JPY', - ds: 876, - spd: 1234, - fa: 5678, - pr: 'pr1234', - mr: 'mr1234', - nurl: '//example/win', - adType: 2, - banner: { - w: 300, - h: 250, - adm: '
', - imps: ['//example.com/imp'] - }, - adomain: adomin - } - }; - const videoResponse = { - slotKey: 'slotkey1234', - userId: 'userid1234', - impId: 'impid1234', - media: 'TEST_MEDIA', - isAdReturn: true, - syncPixels: ['//example/sync/pixel.gif'], - syncIFs: [], - ad: { - bidId: 'TEST_BID_ID', - price: 1234.56, - creativeId: 'creativeid1234', - dealId: 'TEST_DEAL_ID', - currency: 'JPY', - ds: 876, - spd: 1234, - fa: 5678, - pr: 'pr1234', - mr: 'mr1234', - nurl: '//example/win', - adType: 1, - video: { - purl: '//playerexample.js', - vastXml: '', - w: 320, - h: 180 - }, - adomain: adomin - } - }; - - it('should get correct banner bid response', function() { - const expectedResponse = [{ - 'slotKey': 'slotkey1234', - 'userId': 'userid1234', - 'impId': 'impid1234', - 'media': 'TEST_MEDIA', - 'ds': 876, - 'spd': 1234, - 'fa': 5678, - 'pr': 'pr1234', - 'mr': 'mr1234', - 'nurl': '//example/win', - 'requestId': 'requestid1234', - 'cpm': 1234.56, - 'creativeId': 'creativeid1234', - 'dealId': 'TEST_DEAL_ID', - 'width': 300, - 'height': 250, - 'ad': "
", - 'mediaType': 'banner', - 'currency': 'JPY', - 'ttl': 360, - 'netRevenue': true, - 'meta': { } - }]; - - let bidderRequest; - const result = spec.interpretResponse({ body: bannerResponse }, { bidderRequest }); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - expect(result[0]).to.nested.contain.property('meta.advertiserDomains', adomin); - }); - - it('handles video responses', function() { - const expectedResponse = [{ - 'slotKey': 'slotkey1234', - 'userId': 'userid1234', - 'impId': 'impid1234', - 'media': 'TEST_MEDIA', - 'ds': 876, - 'spd': 1234, - 'fa': 5678, - 'pr': 'pr1234', - 'mr': 'mr1234', - 'nurl': '//example/win', - 'requestId': 'requestid1234', - 'cpm': 1234.56, - 'creativeId': 'creativeid1234', - 'dealId': 'TEST_DEAL_ID', - 'width': 320, - 'height': 180, - 'vastXml': '', - 'mediaType': 'video', - 'renderer': {}, - 'adResponse': {}, - 'currency': 'JPY', - 'ttl': 360, - 'netRevenue': true, - 'meta': { } - }]; - - let bidderRequest; - const result = spec.interpretResponse({ body: videoResponse }, { bidderRequest }); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - expect(result[0]).to.nested.contain.property('meta.advertiserDomains', adomin); - }); - - it('handles nobid responses', function() { - const response = { - isAdReturn: false, - 'ad': {} - }; - - let bidderRequest; - const result = spec.interpretResponse({ body: response }, { bidderRequest }); - expect(result.length).to.equal(0); - }); - }); - - describe('getUserSyncs', function() { - const imgResponse1 = { - body: { - 'isAdReturn': true, - 'ad': { /* ad body */ }, - 'syncPixels': [ - 'https://example.test/1' - ] - } - }; - - const imgResponse2 = { - body: { - 'isAdReturn': true, - 'ad': { /* ad body */ }, - 'syncPixels': [ - 'https://example.test/2' - ] - } - }; - - const ifResponse = { - body: { - 'isAdReturn': true, - 'ad': { /* ad body */ }, - 'syncIFs': [ - 'https://example.test/3' - ] - } - }; - - it('should use a sync img url from first response', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true }, [imgResponse1, imgResponse2, ifResponse]); - expect(syncs).to.deep.equal([ - { - type: 'image', - url: 'https://example.test/1' - } - ]); - }); - - it('handle ifs response', function() { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [ifResponse]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://example.test/3' - } - ]); - }); - - it('handle empty response (e.g. timeout)', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true }, []); - expect(syncs).to.deep.equal([]); - }); - - it('returns empty syncs when not enabled', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: false }, [imgResponse1]); - expect(syncs).to.deep.equal([]); - }); - }); -}); diff --git a/test/spec/modules/openadsServerBidAdapter_spec.js b/test/spec/modules/openadsServerBidAdapter_spec.js deleted file mode 100644 index 20690049a..000000000 --- a/test/spec/modules/openadsServerBidAdapter_spec.js +++ /dev/null @@ -1,4701 +0,0 @@ -import {expect} from 'chai'; -import { - OpenAdsServer as Adapter, - resetSyncedStatus, - validateConfig, - s2sDefaultConfig, - processPBSRequest -} from 'modules/openadsServerBidAdapter/index.js'; -import adapterManager, {PBS_ADAPTER_NAME} from 'src/adapterManager.js'; -import * as utils from 'src/utils.js'; -import {deepAccess, deepClone, mergeDeep} from 'src/utils.js'; -import {ajax} from 'src/ajax.js'; -import {config} from 'src/config.js'; -import * as events from 'src/events.js'; -import { EVENTS, DEBUG_MODE } from 'src/constants.js'; -import {server} from 'test/mocks/xhr.js'; -import 'modules/appnexusBidAdapter.js'; // appnexus alias test -import 'modules/rubiconBidAdapter.js'; // rubicon alias test -import {requestBids} from 'src/prebid.js'; -import 'modules/currency.js'; // adServerCurrency test -import 'modules/userId/index.js'; -import 'modules/multibid/index.js'; -import 'modules/priceFloors.js'; -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; -import 'modules/consentManagementGpp.js'; -import 'modules/paapi.js'; -import * as redactor from 'src/activities/redactor.js'; -import * as activityRules from 'src/activities/rules.js'; -import {hook} from '../../../src/hook.js'; -import {decorateAdUnitsWithNativeParams} from '../../../src/native.js'; -import {auctionManager} from '../../../src/auctionManager.js'; -import {stubAuctionIndex} from '../../helpers/indexStub.js'; -import {addPaapiConfig, registerBidder} from 'src/adapters/bidderFactory.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; -import {addFPDToBidderRequest} from '../../helpers/fpd.js'; -import {deepSetValue} from '../../../src/utils.js'; -import {ACTIVITY_TRANSMIT_UFPD} from '../../../src/activities/activities.js'; -import {MODULE_TYPE_PREBID} from '../../../src/activities/modules.js'; -import { - consolidateEids, - extractEids, - getPBSBidderConfig -} from '../../../modules/openadsServerBidAdapter/bidderConfig.js'; -import {markWinningBid} from '../../../src/adRendering.js'; - -let CONFIG = { - accountId: '1', - enabled: true, - bidders: ['appnexus'], - cacheMarkup: 2, - endpoint: { - p1Consent: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction', - noP1Consent: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' - } -}; - -const REQUEST = { - 'account_id': '1', - 'tid': '437fbbf5-33f5-487a-8e16-a7112903cfe5', - 'max_bids': 1, - 'timeout_millis': 1000, - 'secure': 0, - 'url': '', - 'prebid_version': '0.30.0-pre', - 's2sConfig': CONFIG, - 'ad_units': [ - { - 'code': 'div-gpt-ad-1460505748561-0', - 'sizes': [[300, 250], [300, 600]], - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 300]] - }, - 'native': { - 'title': { - 'required': true, - 'len': 800 - }, - 'image': { - 'required': true, - 'sizes': [989, 742], - }, - 'icon': { - 'required': true, - 'aspect_ratios': [{ - 'min_height': 10, - 'min_width': 10, - 'ratio_height': 1, - 'ratio_width': 1 - }] - }, - 'sponsoredBy': { - 'required': true - } - } - }, - 'transactionId': '4ef956ad-fd83-406d-bd35-e4bb786ab86c', - 'adUnitId': 'au-id-1', - 'bids': [ - { - 'bid_id': '123', - 'bidder': 'appnexus', - 'params': { - 'placementId': '10433394', - 'member': 123 - } - } - ] - } - ] -}; - -const NATIVE_ORTB_MTO = { - ortb: { - context: 3, - plcmttype: 2, - eventtrackers: [ - { - event: 1, - methods: [ - 1 - ] - }, - { - event: 2, - methods: [ - 2 - ] - } - ], - assets: [ - { - id: 1, - required: 1, - img: { - type: 3, - w: 300, - h: 250 - } - }, - { - id: 2, - required: 1, - img: { - type: 1, - w: 127, - h: 83 - } - }, - { - id: 3, - required: 1, - data: { - type: 1, - len: 25 - } - }, - { - id: 4, - required: 1, - title: { - len: 140 - } - }, - { - id: 5, - required: 1, - data: { - type: 2, - len: 40 - } - }, - { - id: 6, - required: 1, - data: { - type: 12, - len: 15 - } - }, - ], - ext: { - custom_param: { - key: 'custom_value' - } - }, - ver: '1.2' - } -} - -const VIDEO_REQUEST = { - 'account_id': '1', - 'tid': '437fbbf5-33f5-487a-8e16-a7112903cfe5', - 'max_bids': 1, - 'timeout_millis': 1000, - 'secure': 0, - 'url': '', - 'prebid_version': '1.4.0-pre', - 's2sConfig': CONFIG, - 'ad_units': [ - { - 'code': 'div-gpt-ad-1460505748561-0', - 'sizes': [640, 480], - 'mediaTypes': { - 'video': { - 'playerSize': [[640, 480]], - 'mimes': ['video/mp4'] - } - }, - 'transactionId': '4ef956ad-fd83-406d-bd35-e4bb786ab86c', - 'bids': [ - { - 'bid_id': '123', - 'bidder': 'appnexus', - 'params': { 'placementId': '12349520' } - } - ] - } - ] -}; - -const OUTSTREAM_VIDEO_REQUEST = { - 'account_id': '1', - 'tid': '437fbbf5-33f5-487a-8e16-a7112903cfe5', - 'max_bids': 1, - 'timeout_millis': 1000, - 'secure': 0, - 'url': '', - 'prebid_version': '1.4.0-pre', - 's2sConfig': CONFIG, - 'ad_units': [ - { - 'code': 'div-gpt-ad-1460505748561-0', - 'sizes': [640, 480], - 'mediaTypes': { - 'video': { - playerSize: [[640, 480]], - context: 'outstream', - mimes: ['video/mp4'], - renderer: { - url: 'https://acdn.adnxs.com/video/outstream/ANOutstreamVideo.js', - render: function (bid) { - ANOutstreamVideo.renderAd({ - targetId: bid.adUnitCode, - adResponse: bid.adResponse, - }); - } - } - }, - banner: { sizes: [[300, 250]] } - }, - 'transactionId': '4ef956ad-fd83-406d-bd35-e4bb786ab86c', - 'bids': [ - { - 'bid_id': '123', - 'bidder': 'appnexus', - 'params': { 'placementId': '12349520' } - } - ] - }, - { - code: 'video1', - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'outstream', - mimes: ['video/mp4'], - skip: 1 - } - }, - bids: [ - { - bidder: 'appnexus', - params: { - placementId: 13232385, - video: { - skippable: true, - playback_method: ['auto_play_sound_off'] - } - } - } - ] - } - ], -}; - -let BID_REQUESTS; - -const RESPONSE_NO_BID_NO_UNIT = { - 'tid': '437fbbf5-33f5-487a-8e16-a7112903cfe5', - 'status': 'OK', - 'bidder_status': [{ - 'bidder': 'appnexus', - 'response_time_ms': 132, - 'no_bid': true - }] -}; - -const RESPONSE_NO_BID_UNIT_SET = { - 'tid': '437fbbf5-33f5-487a-8e16-a7112903cfe5', - 'status': 'OK', - 'bidder_status': [{ - 'bidder': 'appnexus', - 'ad_unit': 'div-gpt-ad-1460505748561-0', - 'response_time_ms': 91, - 'no_bid': true - }] -}; - -const RESPONSE_NO_COOKIE = { - 'tid': 'd6eca075-4a59-4346-bdb3-86531830ef2c', - 'status': 'OK', - 'bidder_status': [{ - 'bidder': 'pubmatic', - 'no_cookie': true, - 'usersync': { - 'url': '//ads.pubmatic.com/AdServer/js/user_sync.html?predirect=http://localhost:8000/setuid?bidder=pubmatic&uid=', - 'type': 'iframe' - } - }] -}; - -const RESPONSE_NO_PBS_COOKIE = { - 'tid': '882fe33e-2981-4257-bd44-bd3b03945f48', - 'status': 'no_cookie', - 'bidder_status': [{ - 'bidder': 'rubicon', - 'no_cookie': true, - 'usersync': { - 'url': 'https://pixel.rubiconproject.com/exchange/sync.php?p=prebid', - 'type': 'redirect' - } - }, { - 'bidder': 'pubmatic', - 'no_cookie': true, - 'usersync': { - 'url': '//ads.pubmatic.com/AdServer/js/user_sync.html?predirect=https%3A%2F%2Fprebid.adnxs.com%2Fpbs%2Fv1%2Fsetuid%3Fbidder%3Dpubmatic%26uid%3D', - 'type': 'iframe' - } - }, { - 'bidder': 'appnexus', - 'response_time_ms': 162, - 'num_bids': 1, - 'debug': [{ - 'request_uri': 'http://ib.adnxs.com/openrtb2', - 'request_body': '{"id":"882fe33e-2981-4257-bd44-bd3b03945f48","imp":[{"id":"/19968336/header-bid-tag-0","banner":{"w":300,"h":250,"format":[{"w":300,"h":250}]},"secure":1,"ext":{"appnexus":{"placement_id":5914989}}}],"site":{"domain":"nytimes.com","page":"http://www.nytimes.com"},"device":{"ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36","ip":"75.97.0.47"},"user":{"id":"3519479852893340159","buyeruid":"3519479852893340159"},"at":1,"tmax":1000,"source":{"fd":1,"tid":"882fe33e-2981-4257-bd44-bd3b03945f48"}}', - 'response_body': '{"id":"882fe33e-2981-4257-bd44-bd3b03945f48"}', - 'status_code': 200 - }] - }], - 'bids': [{ - 'bid_id': '123', - 'code': 'div-gpt-ad-1460505748561-0', - 'creative_id': '70928274', - 'bidder': 'appnexus', - 'price': 0.07425, - 'adm': '', - 'width': 300, - 'height': 250, - 'response_time_ms': 162 - }] -}; - -const RESPONSE_OPENRTB = { - 'id': 'c7dcf14f', - 'seatbid': [ - { - 'bid': [ - { - 'id': '8750901685062148', - 'impid': 'div-gpt-ad-1460505748561-0', - 'price': 0.5, - 'adm': '', - 'adid': '29681110', - 'adomain': ['appnexus.com'], - 'iurl': 'http://lax1-ib.adnxs.com/cr?id=2968111', - 'cid': '958', - 'crid': '2968111', - 'dealid': 'test-dealid', - 'w': 300, - 'h': 250, - 'ext': { - 'prebid': { - 'type': 'banner', - 'event': { - 'win': 'http://wurl.org?id=333' - }, - 'meta': { - 'dchain': { 'ver': '1.0', 'complete': 0, 'nodes': [{ 'asi': 'magnite.com', 'bsid': '123456789', }] } - } - }, - 'bidder': { - 'appnexus': { - 'brand_id': 1, - 'auction_id': 3, - 'bidder_id': 2 - } - } - } - } - ], - 'seat': 'appnexus' - }, - ], - 'cur': 'EUR', - 'ext': { - 'responsetimemillis': { - 'appnexus': 8, - } - } -}; - -const RESPONSE_OPENRTB_VIDEO = { - id: 'c7dcf14f', - seatbid: [ - { - bid: [ - { - id: '1987250005171537465', - impid: 'div-gpt-ad-1460505748561-0', - price: 10, - adm: 'adnxs', - adid: '81877115', - adomain: ['appnexus.com'], - iurl: 'http://lax1-ib.adnxs.com/cr?id=81877115', - cid: '3535', - crid: '81877115', - dealid: 'test-dealid', - w: 1, - h: 1, - ext: { - prebid: { - type: 'video', - bidid: '654321' - }, - bidder: { - appnexus: { - brand_id: 1, - auction_id: '6673622101799484743', - bidder_id: 2, - bid_ad_type: 1, - }, - }, - }, - }, - ], - seat: 'appnexus', - }, - ], - ext: { - responsetimemillis: { - appnexus: 81, - }, - }, -}; - -const RESPONSE_OPENRTB_NATIVE = { - 'id': 'c7dcf14f', - 'seatbid': [ - { - 'bid': [ - { - 'id': '6451317310275562039', - 'impid': 'div-gpt-ad-1460505748561-0', - 'price': 10, - 'adm': { - 'ver': '1.2', - 'assets': [ - { - 'id': 1, - 'img': { - 'url': 'https://vcdn.adnxs.com/p/creative-image/f8/7f/0f/13/f87f0f13-230c-4f05-8087-db9216e393de.jpg', - 'w': 989, - 'h': 742, - 'ext': { - 'appnexus': { - 'prevent_crop': 0 - } - } - } - }, - { - 'id': 2, - 'img': { - 'url': 'https://vcdn.adnxs.com/p/creative-image/1a/3e/e9/5b/1a3ee95b-06cd-4260-98c7-0258627c9197.png', - 'w': 127, - 'h': 83, - 'ext': { - 'appnexus': { - 'prevent_crop': 0 - } - } - } - }, - { - 'id': 0, - 'title': { - 'text': 'This is a Prebid Native Creative' - } - }, - { - 'id': 3, - 'data': { - 'value': 'Prebid.org' - } - } - ], - 'link': { - 'url': 'https://lax1-ib.adnxs.com/click?AAAAAAAAJEAAAAAAAAAkQAAAAAAAACRAAAAAAAAAJEAAAAAAAAAkQGdce2vBWudAJZpFu1er1zA7ZzddAAAAAOLoyQBtJAAAbSQAAAIAAAC8pM8FnPgWAAAAAABVU0QAVVNEAAEAAQBNXQAAAAABAgMCAAAAALsAuhVqdgAAAAA./cpcpm=AAAAAAAAAAA=/bcr=AAAAAAAA8D8=/pp=${AUCTION_PRICE}/cnd=%213Q5HCQj8-LwKELzJvi4YnPFbIAQoADEAAAAAAAAkQDoJTEFYMTo0MDc3QKcPSQAAAAAAAPA_UQAAAAAAAAAAWQAAAAAAAAAAYQAAAAAAAAAAaQAAAAAAAAAAcQAAAAAAAAAA/cca=OTMyNSNMQVgxOjQwNzc=/bn=84305/test=1/clickenc=http%3A%2F%2Fprebid.org%2Fdev-docs%2Fshow-native-ads.html' - }, - 'eventtrackers': [ - { - 'event': 1, - 'method': 1, - 'url': 'https://lax1-ib.adnxs.com/it?an_audit=0&test=1&referrer=http%3A%2F%2Flocalhost%3A9999%2FintegrationExamples%2Fgpt%2Fdemo_native.html&e=wqT_3QKCCKACBAAAAwDWAAUBCLvO3ekFEOe47duW2NbzQBiltJba--rq6zAqNgkAAAECCCRAEQEHEAAAJEAZEQkAIREJACkRCQAxEQmoMOLRpwY47UhA7UhIAlC8yb4uWJzxW2AAaM26dXjRkgWAAQGKAQNVU0SSAQEG8FKYAQGgAQGoAQGwAQC4AQLAAQPIAQLQAQnYAQDgAQHwAQCKAjt1ZignYScsIDI1Mjk4ODUsIDE1NjM5MTE5OTUpO3VmKCdyJywgOTc0OTQyMDQsIC4eAPQ0AZICnQIhb2pkaWlnajgtTHdLRUx6SnZpNFlBQ0NjOFZzd0FEZ0FRQVJJN1VoUTR0R25CbGdBWVAwQmFBQndBSGdBZ0FFQWlBRUFrQUVCbUFFQm9BRUJxQUVEc0FFQXVRSHpyV3FrQUFBa1FNRUI4NjFxcEFBQUpFREpBVVZpYmxDaFpRQkEyUUVBQUFBQUFBRHdQLUFCQVBVQkFBQUFBUGdCQUpnQ0FLQUNBTFVDQUFBQUFMMENBQUFBQU1BQ0FNZ0NBT0FDQU9nQ0FQZ0NBSUFEQVpBREFKZ0RBYWdEX1BpOENyb0RDVXhCV0RFNk5EQTNOLUFEcHctUUJBQ1lCQUhCQkFBQUFBQUFBQUFBeVFRQUFBQUFBQUFBQU5nRUFBLi6aAoUBITNRNUhDUWo4LUx3S0VMeiUhJG5QRmJJQVFvQUQRvVhBa1FEb0pURUZZTVRvME1EYzNRS2NQUxFUDFBBX1URDAxBQUFXHQwAWR0MAGEdDABjHQz0FwHYAgDgAq2YSOoCPmh0dHA6Ly9sb2NhbGhvc3Q6OTk5OS9pbnRlZ3JhdGlvbkV4YW1wbGVzL2dwdC9kZW1vX25hdGl2ZS5odG1sgAMAiAMBkAMAmAMUoAMBqgMAwAPgqAHIAwDYAwDgAwDoAwD4AwOABACSBAkvb3BlbnJ0YjKYBACiBA0xNzMuMjQ0LjM2LjQwqATtoySyBAwIABAAGAAgADAAOAC4BADABADIBADSBA45MzI1I0xBWDE6NDA3N9oEAggB4AQA8AS8yb4uiAUBmAUAoAX___________8BqgUkZTU5YzNlYjYtNmRkNi00MmQ5LWExMWEtM2FhMTFjOTc5MGUwwAUAyQUAAAAAAADwP9IFCQkAaVh0ANgFAeAFAfAFmfQh-gUECAAQAJAGAZgGALgGAMEGCSQk8D_IBgDaBhYKEAkQGQEBwTTgBgzyBgIIAIAHAYgHAA..&s=11ababa390e9f7983de260493fc5b91ec5b1b3d4&pp=${AUCTION_PRICE}' - } - ] - }, - 'adid': '97494204', - 'adomain': [ - 'http://prebid.org' - ], - 'iurl': 'https://lax1-ib.adnxs.com/cr?id=97494204', - 'cid': '9325', - 'crid': '97494204', - 'cat': [ - 'IAB3-1' - ], - 'ext': { - 'prebid': { - 'targeting': { - 'oa_bidder': 'appnexus', - 'oa_pb': '10.00' - }, - 'type': 'native', - 'video': { - 'duration': 0, - 'primary_category': '' - } - }, - 'bidder': { - 'appnexus': { - 'brand_id': 555545, - 'auction_id': '4676806524825984103', - 'bidder_id': 2, - 'bid_ad_type': 3 - } - } - } - } - ], - 'seat': 'appnexus' - } - ] -}; - -async function addFpdEnrichmentsToS2SRequest(s2sReq, bidderRequests) { - return { - ...s2sReq, - ortb2Fragments: { - ...(s2sReq.ortb2Fragments || {}), - global: (await addFPDToBidderRequest({ - ...(bidderRequests?.[0] || {}), - ortb2: s2sReq.ortb2Fragments?.global || {} - })).ortb2 - } - } -} - -describe('s2s configuration', () => { - let cfg1, cfg2; - beforeEach(() => { - cfg1 = { - enabled: true, - bidders: ['bidderB'], - accountId: '123456', - endpoint: { - p1Consent: 'first.endpoint' - } - }; - cfg2 = { - enabled: true, - bidders: ['bidderA'], - accountId: '123456', - endpoint: { - p1Consent: 'second.endpoint', - } - }; - }) - it('sets openads server adapter by default', () => { - expect(validateConfig(cfg1)[0].adapter).to.eql('openadsServer'); - }); - it('filters out disabled configs', () => { - cfg1.enabled = false; - expect(validateConfig([cfg1, cfg2])).to.eql([cfg2]); - }) -}); - -describe('S2S Adapter', function () { - let adapter; - let addBidResponse = sinon.spy(); - let done = sinon.spy(); - - addBidResponse.reject = sinon.spy(); - - function prepRequest(req) { - req.ad_units.forEach((adUnit) => { - delete adUnit.nativeParams - }); - decorateAdUnitsWithNativeParams(req.ad_units); - } - - before(() => { - hook.ready(); - prepRequest(REQUEST); - }); - - beforeEach(function () { - config.resetConfig(); - config.setConfig({floors: {enabled: false}}); - adapter = new Adapter(); - BID_REQUESTS = [ - { - 'bidderCode': 'appnexus', - 'auctionId': '173afb6d132ba3', - 'bidderRequestId': '3d1063078dfcc8', - 'tid': '437fbbf5-33f5-487a-8e16-a7112903cfe5', - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': '10433394', - 'member': 123, - 'keywords': { - 'foo': ['bar', 'baz'], - 'fizz': ['buzz'] - } - }, - 'bid_id': '123', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]] - } - }, - 'transactionId': '4ef956ad-fd83-406d-bd35-e4bb786ab86c', - 'sizes': [300, 250], - 'bidId': '123', - 'bidderRequestId': '3d1063078dfcc8', - 'auctionId': '173afb6d132ba3' - } - ], - 'auctionStart': 1510852447530, - 'timeout': 5000, - 'src': 's2s', - 'doneCbCallCount': 0, - 'refererInfo': { - 'page': 'http://mytestpage.com' - } - } - ]; - }); - - afterEach(function () { - addBidResponse.resetHistory(); - addBidResponse.reject = sinon.spy(); - done.resetHistory(); - }); - - after(function () { - config.resetConfig(); - }); - - describe('request function', function () { - beforeEach(function () { - resetSyncedStatus(); - }); - - describe('FPD redaction', () => { - let sandbox, ortb2Fragments, redactorMocks, s2sReq; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - redactorMocks = {}; - sandbox.stub(redactor, 'redactor').callsFake((params) => { - if (!redactorMocks.hasOwnProperty(params.component)) { - redactorMocks[params.component] = { - ortb2: sinon.stub().callsFake(o => o), - bidRequest: sinon.stub().callsFake(o => o) - } - } - return redactorMocks[params.component]; - }) - ortb2Fragments = { - global: { - mock: 'value' - }, - bidder: { - appnexus: { - mock: 'A' - } - } - } - const s2sConfig = { - ...CONFIG, - }; - config.setConfig({s2sConfig}); - s2sReq = { - ...REQUEST, - s2sConfig - }; - }); - - afterEach(() => { - sandbox.restore(); - }) - - function callBids() { - adapter.callBids({ - ...s2sReq, - ortb2Fragments - }, BID_REQUESTS, addBidResponse, done, ajax); - } - - it('should be applied to ortb2Fragments', () => { - callBids(); - sinon.assert.calledWithMatch(redactorMocks['prebid.pbsBidAdapter'].ortb2, ortb2Fragments.global); - Object.entries(ortb2Fragments.bidder).forEach(([bidder, ortb2]) => { - sinon.assert.calledWith(redactorMocks[`bidder.${bidder}`].ortb2, ortb2); - }); - }); - - it('should be applied to ad units', () => { - callBids(); - s2sReq.ad_units.forEach(au => { - sinon.assert.calledWith(redactorMocks['prebid.pbsBidAdapter'].bidRequest, au); - au.bids.forEach((bid) => { - sinon.assert.calledWith(redactorMocks[`bidder.${bid.bidder}`].bidRequest, bid); - }) - }) - }) - }); - - describe('transaction IDs', () => { - let s2sReq; - beforeEach(() => { - s2sReq = { - ...REQUEST, - ortb2Fragments: {global: {}}, - ad_units: REQUEST.ad_units.map(au => ({...au, ortb2Imp: {ext: {tid: 'mock-tid'}}})), - }; - BID_REQUESTS[0].bids[0].ortb2Imp = {ext: {tid: 'mock-tid'}}; - }); - - function makeRequest() { - adapter.callBids(s2sReq, BID_REQUESTS, addBidResponse, done, ajax); - return JSON.parse(server.requests[0].requestBody); - } - - it('should always set transactionids', () => { - config.setConfig({ s2sConfig: CONFIG, enableTIDs: false }); - const req = makeRequest(); - expect(req.source.tid).to.eql(BID_REQUESTS[0].auctionId); - expect(req.imp[0].ext.tid).to.eql('mock-tid'); - }); - - it('should be set to auction ID otherwise', () => { - config.setConfig({s2sConfig: CONFIG, enableTIDs: true}); - const req = makeRequest(); - expect(req.source.tid).to.eql(BID_REQUESTS[0].auctionId); - expect(req.imp[0].ext.tid).to.eql('mock-tid'); - }) - }) - - describe('browsingTopics', () => { - const sandbox = sinon.createSandbox(); - afterEach(() => { - sandbox.restore() - }); - Object.entries({ - 'allowed': true, - 'not allowed': false, - }).forEach(([t, allow]) => { - it(`should be set to ${allow} when transmitUfpd is ${t}`, () => { - sandbox.stub(activityRules, 'isActivityAllowed').callsFake((activity, params) => { - if (activity === ACTIVITY_TRANSMIT_UFPD && params.component === `${MODULE_TYPE_PREBID}.${PBS_ADAPTER_NAME}`) { - return allow; - } - return false; - }); - config.setConfig({s2sConfig: CONFIG}); - const ajax = sinon.stub(); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - sinon.assert.calledWith(ajax, sinon.match.any, sinon.match.any, sinon.match.any, sinon.match({ - browsingTopics: allow - })); - }); - }); - }) - - it('should set tmaxmax correctly when publisher has specified it', () => { - const cfg = {...CONFIG}; - config.setConfig({s2sConfig: cfg}) - - // publisher has specified a tmaxmax in their setup - const ortb2Fragments = { - global: { - ext: { - tmaxmax: 4242 - } - } - }; - const s2sCfg = {...REQUEST, cfg} - const payloadWithFragments = { ...s2sCfg, ortb2Fragments }; - - adapter.callBids(payloadWithFragments, BID_REQUESTS, addBidResponse, done, ajax); - const req = JSON.parse(server.requests[0].requestBody); - - expect(req.ext.tmaxmax).to.eql(4242); - }); - - it('should set tmaxmax correctly when publisher has not specified it', () => { - const cfg = {...CONFIG}; - config.setConfig({s2sConfig: cfg}) - - // publisher has not specified a tmaxmax in their setup - so we should be - // falling back to requestBidsTimeout - const ortb2Fragments = {}; - const s2sCfg = {...REQUEST, cfg}; - const requestBidsTimeout = 808; - const payloadWithFragments = { ...s2sCfg, ortb2Fragments, requestBidsTimeout }; - - adapter.callBids(payloadWithFragments, BID_REQUESTS, addBidResponse, done, ajax); - const req = JSON.parse(server.requests[0].requestBody); - - expect(req.ext.tmaxmax).to.eql(808); - }); - - describe('default tmax', () => { - [null, 3000].forEach(maxTimeout => { - describe(`when maxTimeout is ${maxTimeout}`, () => { - let cfg; - - beforeEach(() => { - cfg = {accountId: '1', endpoint: 'mock-endpoint', maxTimeout}; - config.setConfig({s2sConfig: cfg}); - maxTimeout = maxTimeout ?? s2sDefaultConfig.maxTimeout - }); - - it('should cap tmax to maxTimeout', () => { - adapter.callBids({...REQUEST, requestBidsTimeout: maxTimeout * 2, s2sConfig: cfg}, BID_REQUESTS, addBidResponse, done, ajax); - const req = JSON.parse(server.requests[0].requestBody); - expect(req.tmax).to.eql(maxTimeout); - }); - - it('should be set to 0.75 * requestTimeout, if lower than maxTimeout', () => { - adapter.callBids({...REQUEST, requestBidsTimeout: maxTimeout / 2}, BID_REQUESTS, addBidResponse, done, ajax); - const req = JSON.parse(server.requests[0].requestBody); - expect(req.tmax).to.eql(Math.floor(maxTimeout / 2 * 0.75)); - }) - }) - }) - }) - - it('should set customHeaders correctly when publisher has provided it', () => { - const configWithCustomHeaders = utils.deepClone(CONFIG); - configWithCustomHeaders.customHeaders = { customHeader1: 'customHeader1Value' }; - config.setConfig({ s2sConfig: configWithCustomHeaders }); - - const reqWithNewConfig = utils.deepClone(REQUEST); - reqWithNewConfig.s2sConfig = configWithCustomHeaders; - - adapter.callBids(reqWithNewConfig, BID_REQUESTS, addBidResponse, done, ajax); - const reqHeaders = server.requests[0].requestHeaders - expect(reqHeaders.customHeader1).to.exist; - expect(reqHeaders.customHeader1).to.equal('customHeader1Value'); - }); - - it('should block request if config did not define p1Consent URL in endpoint object config', function () { - const badConfig = utils.deepClone(CONFIG); - badConfig.endpoint = { noP1Consent: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' }; - config.setConfig({ s2sConfig: badConfig }); - - const badCfgRequest = utils.deepClone(REQUEST); - badCfgRequest.s2sConfig = badConfig; - - adapter.callBids(badCfgRequest, BID_REQUESTS, addBidResponse, done, ajax); - - expect(server.requests.length).to.equal(0); - }); - - it('should block request if config did not define noP1Consent URL in endpoint object config', function () { - const badConfig = utils.deepClone(CONFIG); - badConfig.endpoint = { p1Consent: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' }; - config.setConfig({ s2sConfig: badConfig }); - - const badCfgRequest = utils.deepClone(REQUEST); - badCfgRequest.s2sConfig = badConfig; - - const badBidderRequest = utils.deepClone(BID_REQUESTS); - badBidderRequest[0].gdprConsent = { - consentString: 'abc123', - addtlConsent: 'superduperconsent', - gdprApplies: true, - apiVersion: 2, - vendorData: { - purpose: { - consents: { - 1: false - } - } - } - }; - - adapter.callBids(badCfgRequest, badBidderRequest, addBidResponse, done, ajax); - - expect(server.requests.length).to.equal(0); - }); - - it('should block request if config did not define any URLs in endpoint object config', function () { - const badConfig = utils.deepClone(CONFIG); - badConfig.endpoint = {}; - config.setConfig({ s2sConfig: badConfig }); - - const badCfgRequest = utils.deepClone(REQUEST); - badCfgRequest.s2sConfig = badConfig; - - adapter.callBids(badCfgRequest, BID_REQUESTS, addBidResponse, done, ajax); - - expect(server.requests.length).to.equal(0); - }); - - it('filters ad units without bidders when filterBidderlessCalls is true', function () { - const cfg = {...CONFIG, filterBidderlessCalls: true}; - config.setConfig({s2sConfig: cfg}); - - const badReq = utils.deepClone(REQUEST); - badReq.s2sConfig = cfg; - badReq.ad_units = [{...REQUEST.ad_units[0], bids: [{bidder: null}]}]; - - const badBidderRequest = utils.deepClone(BID_REQUESTS); - badBidderRequest[0].bidderCode = null; - badBidderRequest[0].bids = [{...badBidderRequest[0].bids[0], bidder: null}]; - - adapter.callBids(badReq, badBidderRequest, addBidResponse, done, ajax); - - expect(server.requests.length).to.equal(0); - }); - - if (FEATURES.VIDEO) { - it('should add outstream bc renderer exists on mediatype', function () { - config.setConfig({ s2sConfig: CONFIG }); - - adapter.callBids(OUTSTREAM_VIDEO_REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - - const requestBid = JSON.parse(server.requests[0].requestBody); - expect(requestBid.imp[0].banner).to.exist; - expect(requestBid.imp[0].video).to.exist; - }); - - it('converts video mediaType properties into openRTB format', function () { - const ortb2Config = utils.deepClone(CONFIG); - ortb2Config.endpoint.p1Consent = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction'; - - config.setConfig({ s2sConfig: ortb2Config }); - - const videoBid = utils.deepClone(VIDEO_REQUEST); - videoBid.ad_units[0].mediaTypes.video.context = 'instream'; - adapter.callBids(videoBid, BID_REQUESTS, addBidResponse, done, ajax); - - const requestBid = JSON.parse(server.requests[0].requestBody); - expect(requestBid.imp[0].banner).to.not.exist; - expect(requestBid.imp[0].video).to.exist; - expect(requestBid.imp[0].video.w).to.equal(640); - expect(requestBid.imp[0].video.h).to.equal(480); - expect(requestBid.imp[0].video.playerSize).to.be.undefined; - expect(requestBid.imp[0].video.context).to.be.undefined; - }); - } - describe('gzip compression', function () { - let gzipStub, gzipSupportStub, getParamStub, debugStub; - beforeEach(function() { - gzipStub = sinon.stub(utils, 'compressDataWithGZip').resolves('compressed'); - gzipSupportStub = sinon.stub(utils, 'isGzipCompressionSupported'); - getParamStub = sinon.stub(utils, 'getParameterByName'); - debugStub = sinon.stub(utils, 'debugTurnedOn'); - }); - - afterEach(function() { - gzipStub.restore(); - gzipSupportStub.restore(); - getParamStub.restore(); - debugStub.restore(); - }); - - it('should gzip payload when enabled and supported', function(done) { - const s2sCfg = Object.assign({}, CONFIG, {endpointCompression: true}); - config.setConfig({s2sConfig: s2sCfg}); - const req = utils.deepClone(REQUEST); - req.s2sConfig = s2sCfg; - gzipSupportStub.returns(true); - getParamStub.withArgs(DEBUG_MODE).returns('false'); - debugStub.returns(false); - - adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax); - - setTimeout(() => { - expect(gzipStub.calledOnce).to.be.true; - expect(server.requests[0].url).to.include('gzip=1'); - expect(server.requests[0].requestBody).to.equal('compressed'); - done(); - }); - }); - - it('should not gzip when debug mode is enabled', function(done) { - const s2sCfg = Object.assign({}, CONFIG, {endpointCompression: true}); - config.setConfig({s2sConfig: s2sCfg}); - const req = utils.deepClone(REQUEST); - req.s2sConfig = s2sCfg; - gzipSupportStub.returns(true); - getParamStub.withArgs(DEBUG_MODE).returns('true'); - debugStub.returns(true); - - adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax); - - setTimeout(() => { - expect(gzipStub.called).to.be.false; - expect(server.requests[0].url).to.not.include('gzip=1'); - done(); - }); - }); - }); - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - - function mockTCF({applies = true, hasP1Consent = true} = {}) { - return { - consentString: 'mockConsent', - gdprApplies: applies, - vendorData: {purpose: {consents: {1: hasP1Consent}}}, - } - } - - describe('gdpr tests', function () { - afterEach(function () { - requestBids.removeAll(); - }); - - it('adds gdpr consent information to ortb2 request depending on presence of module', async function () { - const consentConfig = {consentManagement: {cmpApi: 'iab'}, s2sConfig: CONFIG}; - config.setConfig(consentConfig); - - const gdprBidRequest = utils.deepClone(BID_REQUESTS); - gdprBidRequest[0].gdprConsent = mockTCF(); - - adapter.callBids(await addFpdEnrichmentsToS2SRequest(REQUEST, gdprBidRequest), gdprBidRequest, addBidResponse, done, ajax); - let requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid.regs.ext.gdpr).is.equal(1); - expect(requestBid.user.ext.consent).is.equal('mockConsent'); - - config.resetConfig(); - config.setConfig({s2sConfig: CONFIG}); - - adapter.callBids(await addFpdEnrichmentsToS2SRequest(REQUEST, BID_REQUESTS), BID_REQUESTS, addBidResponse, done, ajax); - requestBid = JSON.parse(server.requests[1].requestBody); - - expect(requestBid.regs?.ext?.gdpr).to.not.exist; - expect(requestBid.user?.ext?.consent).to.not.exist; - }); - - it('adds additional consent information to ortb2 request depending on presence of module', async function () { - const consentConfig = {consentManagement: {cmpApi: 'iab'}, s2sConfig: CONFIG}; - config.setConfig(consentConfig); - - const gdprBidRequest = utils.deepClone(BID_REQUESTS); - gdprBidRequest[0].gdprConsent = Object.assign(mockTCF(), { - addtlConsent: 'superduperconsent', - }); - - adapter.callBids(await addFpdEnrichmentsToS2SRequest(REQUEST, gdprBidRequest), gdprBidRequest, addBidResponse, done, ajax); - let requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid.regs.ext.gdpr).is.equal(1); - expect(requestBid.user.ext.consent).is.equal('mockConsent'); - expect(requestBid.user.ext.ConsentedProvidersSettings.consented_providers).is.equal('superduperconsent'); - - config.resetConfig(); - config.setConfig({s2sConfig: CONFIG}); - - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - requestBid = JSON.parse(server.requests[1].requestBody); - - expect(requestBid.regs).to.not.exist; - expect(requestBid.user).to.not.exist; - }); - }); - - describe('us_privacy (ccpa) consent data', function () { - afterEach(function () { - requestBids.removeAll(); - }); - - it('is added to ortb2 request when in FPD', async function () { - config.setConfig({s2sConfig: CONFIG}); - - const uspBidRequest = utils.deepClone(BID_REQUESTS); - uspBidRequest[0].uspConsent = '1NYN'; - - adapter.callBids(await addFpdEnrichmentsToS2SRequest(REQUEST, uspBidRequest), uspBidRequest, addBidResponse, done, ajax); - let requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid.regs.ext.us_privacy).is.equal('1NYN'); - - config.resetConfig(); - config.setConfig({s2sConfig: CONFIG}); - - adapter.callBids(await addFpdEnrichmentsToS2SRequest(REQUEST, BID_REQUESTS), BID_REQUESTS, addBidResponse, done, ajax); - requestBid = JSON.parse(server.requests[1].requestBody); - - expect(requestBid.regs?.ext?.us_privacy).to.not.exist; - }); - }); - - describe('gdpr and us_privacy (ccpa) consent data', function () { - afterEach(function () { - requestBids.removeAll(); - }); - - it('is added to ortb2 request when in bidRequest', async function () { - config.setConfig({s2sConfig: CONFIG}); - - const consentBidRequest = utils.deepClone(BID_REQUESTS); - consentBidRequest[0].uspConsent = '1NYN'; - consentBidRequest[0].gdprConsent = mockTCF(); - - adapter.callBids(await addFpdEnrichmentsToS2SRequest(REQUEST, consentBidRequest), consentBidRequest, addBidResponse, done, ajax); - let requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid.regs.ext.us_privacy).is.equal('1NYN'); - expect(requestBid.regs.ext.gdpr).is.equal(1); - expect(requestBid.user.ext.consent).is.equal('mockConsent'); - - config.resetConfig(); - config.setConfig({s2sConfig: CONFIG}); - - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - requestBid = JSON.parse(server.requests[1].requestBody); - - expect(requestBid.regs).to.not.exist; - expect(requestBid.user).to.not.exist; - }); - - it('is added to cookie_sync request when in bidRequest', function () { - const cookieSyncConfig = utils.deepClone(CONFIG); - cookieSyncConfig.syncEndpoint = { p1Consent: 'https://prebid.adnxs.com/pbs/v1/cookie_sync' }; - config.setConfig({ s2sConfig: cookieSyncConfig }); - - const consentBidRequest = utils.deepClone(BID_REQUESTS); - consentBidRequest[0].uspConsent = '1YNN'; - consentBidRequest[0].gdprConsent = mockTCF(); - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = cookieSyncConfig - - adapter.callBids(s2sBidRequest, consentBidRequest, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid.us_privacy).is.equal('1YNN'); - expect(requestBid.gdpr).is.equal(1); - expect(requestBid.gdpr_consent).is.equal('mockConsent'); - expect(requestBid.bidders).to.contain('appnexus').and.to.have.lengthOf(1); - expect(requestBid.account).is.equal('1'); - }); - }); - - it('adds device and app objects to request', async function () { - const _config = { - s2sConfig: CONFIG, - }; - config.setConfig(_config); - const s2sreq = await addFpdEnrichmentsToS2SRequest({ - ...REQUEST, - ortb2Fragments: { - global: { - device: {ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC'}, - app: {bundle: 'com.test.app'}, - } - } - }, BID_REQUESTS) - adapter.callBids(s2sreq, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - sinon.assert.match(requestBid.device, { - ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC', - w: window.screen.width, - h: window.screen.height, - }) - sinon.assert.match(requestBid.app, { - bundle: 'com.test.app', - publisher: {'id': '1'} - }); - }); - - it('adds device and app objects to request for OpenRTB', async function () { - const s2sConfig = Object.assign({}, CONFIG, { - endpoint: { - p1Consent: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' - } - }); - const _config = { - s2sConfig: s2sConfig, - }; - config.setConfig(_config); - const s2sReq = await addFpdEnrichmentsToS2SRequest({ - ...REQUEST, - ortb2Fragments: { - global: { - device: {ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC'}, - app: {bundle: 'com.test.app'}, - } - } - }, BID_REQUESTS) - adapter.callBids(s2sReq, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - sinon.assert.match(requestBid.device, { - ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC', - w: window.screen.width, - h: window.screen.height, - }) - sinon.assert.match(requestBid.app, { - bundle: 'com.test.app', - publisher: {'id': '1'} - }); - }); - - describe('price floors module', function () { - function runTest(expectedFloor, expectedCur) { - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[requestCount].requestBody); - expect(requestBid.imp[0].bidfloor).to.equal(expectedFloor); - expect(requestBid.imp[0].bidfloorcur).to.equal(expectedCur); - requestCount += 1; - } - - let getFloorResponse, requestCount; - beforeEach(function () { - getFloorResponse = {}; - requestCount = 0; - }); - - it('should NOT pass bidfloor and bidfloorcur when getFloor not present or returns invalid response', function () { - const _config = { - s2sConfig: CONFIG, - }; - - config.setConfig(_config); - - // if no get floor - runTest(undefined, undefined); - - // if getFloor returns empty object - BID_REQUESTS[0].bids[0].getFloor = () => getFloorResponse; - sinon.spy(BID_REQUESTS[0].bids[0], 'getFloor'); - - runTest(undefined, undefined); - // make sure getFloor was called - expect( - BID_REQUESTS[0].bids[0].getFloor.calledWith({ - currency: 'USD', - mediaType: '*', - size: '*' - }) - ).to.be.true; - - // if getFloor does not return number - getFloorResponse = { currency: 'EUR', floor: 'not a number' }; - runTest(undefined, undefined); - - // if getFloor does not return currency - getFloorResponse = { floor: 1.1 }; - runTest(undefined, undefined); - }); - - it('should correctly pass bidfloor and bidfloorcur', function () { - const _config = { - s2sConfig: CONFIG, - }; - - config.setConfig(_config); - - BID_REQUESTS[0].bids[0].getFloor = () => getFloorResponse; - sinon.spy(BID_REQUESTS[0].bids[0], 'getFloor'); - - // returns USD and string floor - getFloorResponse = { currency: 'USD', floor: '1.23' }; - runTest(1.23, 'USD'); - // make sure getFloor was called - expect( - BID_REQUESTS[0].bids[0].getFloor.calledWith({ - currency: 'USD', - mediaType: '*', - size: '*' - }) - ).to.be.true; - - // returns non USD and number floor - getFloorResponse = { currency: 'EUR', floor: 0.85 }; - runTest(0.85, 'EUR'); - }); - - it('should correctly pass adServerCurrency when set to getFloor not default', function () { - config.setConfig({ - s2sConfig: CONFIG, - currency: { adServerCurrency: 'JPY' }, - }); - - // we have to start requestCount at 1 because a conversion rates fetch occurs when adServerCur is not USD! - requestCount = 1; - - BID_REQUESTS[0].bids[0].getFloor = () => getFloorResponse; - sinon.spy(BID_REQUESTS[0].bids[0], 'getFloor'); - - // returns USD and string floor - getFloorResponse = { currency: 'JPY', floor: 97.2 }; - runTest(97.2, 'JPY'); - // make sure getFloor was called with JPY - expect( - BID_REQUESTS[0].bids[0].getFloor.calledWith({ - currency: 'JPY', - mediaType: '*', - size: '*' - }) - ).to.be.true; - }); - - it('should find the floor when not all bidderRequests contain it', () => { - config.setConfig({ - s2sConfig: { - ...CONFIG, - bidders: ['b1', 'b2'] - }, - }); - const bidderRequests = [ - { - ...BID_REQUESTS[0], - bidderCode: 'b1', - bids: [{ - bidder: 'b1', - bidId: 1, - }] - }, - { - ...BID_REQUESTS[0], - bidderCode: 'b2', - bids: [{ - bidder: 'b2', - bidId: 2, - getFloor: () => ({ - currency: 'CUR', - floor: 123 - }) - }], - } - ]; - const adUnits = [ - { - code: 'au1', - transactionId: 't1', - mediaTypes: { - banner: {sizes: [1, 1]} - }, - bids: [{bidder: 'b1', bid_id: 1}] - }, - { - code: 'au2', - transactionId: 't2', - bids: [{bidder: 'b2', bid_id: 2}], - mediaTypes: { - banner: {sizes: [1, 1]} - } - } - ]; - const s2sReq = { - ...REQUEST, - ad_units: adUnits - } - - adapter.callBids(s2sReq, bidderRequests, addBidResponse, done, ajax); - - const pbsReq = JSON.parse(server.requests[server.requests.length - 1].requestBody); - const [imp1, imp2] = pbsReq.imp; - - expect(imp1.bidfloor).to.be.undefined; - expect(imp1.bidfloorcur).to.be.undefined; - - expect(imp2.bidfloor).to.eql(123); - expect(imp2.bidfloorcur).to.eql('CUR'); - }); - - describe('when different bids have different floors', () => { - let s2sReq; - beforeEach(() => { - config.setConfig({ - s2sConfig: { - ...CONFIG, - bidders: ['b1', 'b2', 'b3'] - }, - }); - BID_REQUESTS = [ - { - ...BID_REQUESTS[0], - bidderCode: 'b2', - bids: [{ - bidder: 'b2', - bidId: 2, - getFloor: () => ({ - currency: '1', - floor: 2 - }) - }], - }, - { - ...BID_REQUESTS[0], - bidderCode: 'b1', - bids: [{ - bidder: 'b1', - bidId: 1, - getFloor: () => ({ - floor: 10, - currency: '0.1' - }) - }] - }, - { - ...BID_REQUESTS[0], - bidderCode: 'b3', - bids: [{ - bidder: 'b3', - bidId: 3, - getFloor: () => ({ - currency: '10', - floor: 1 - }) - }], - } - ]; - s2sReq = { - ...REQUEST, - ad_units: [ - { - code: 'au1', - transactionId: 't1', - mediaTypes: { - banner: {sizes: [1, 1]} - }, - bids: [ - {bidder: 'b2', bid_id: 2}, - {bidder: 'b3', bid_id: 3}, - {bidder: 'b1', bid_id: 1}, - ] - } - ] - }; - }); - - Object.entries({ - 'cannot compute a floor': (bid) => { bid.getFloor = () => { throw new Error() } }, - 'does not set a floor': (bid) => { delete bid.getFloor; }, - }).forEach(([t, updateBid]) => { - it(`should not set pricefloor if any one of them ${t}`, () => { - updateBid(BID_REQUESTS[1].bids[0]); - adapter.callBids(s2sReq, BID_REQUESTS, addBidResponse, done, ajax); - const pbsReq = JSON.parse(server.requests[server.requests.length - 1].requestBody); - [pbsReq.imp[0], pbsReq.imp[0].banner, pbsReq.imp[0].banner.format[0]].forEach(obj => { - expect(obj.bidfloor).to.be.undefined; - expect(obj.bidfloorcur).to.be.undefined; - }) - }); - }) - - Object.entries({ - 'imp level floors': { - target: 'imp.0' - }, - 'mediaType level floors': { - target: 'imp.0.banner.ext', - floorFilter: ({mediaType, size}) => size === '*' && mediaType !== '*' - }, - 'format level floors': { - target: 'imp.0.banner.format.0.ext', - floorFilter: ({size}) => size !== '*' - } - }).forEach(([t, {target, floorFilter}]) => { - describe(t, () => { - beforeEach(() => { - if (floorFilter != null) { - BID_REQUESTS - .flatMap(req => req.bids) - .forEach(req => { - req.getFloor = ((orig) => (params) => { - if (floorFilter(params)) { - return orig(params); - } - })(req.getFloor); - }) - } - }) - - Object.entries({ - 'is available': { - expectDesc: 'minimum after conversion', - expectedFloor: 10, - expectedCur: '0.1', - conversionFn: (amount, from, to) => { - from = parseFloat(from); - to = parseFloat(to); - return amount * from / to; - }, - }, - 'is not available': { - expectDesc: 'absolute minimum', - expectedFloor: 1, - expectedCur: '10', - conversionFn: null - }, - 'is not working': { - expectDesc: 'absolute minimum', - expectedFloor: 1, - expectedCur: '10', - conversionFn: () => { - throw new Error(); - } - } - }).forEach(([t, {expectDesc, expectedFloor, expectedCur, conversionFn}]) => { - describe(`and currency conversion ${t}`, () => { - let mockConvertCurrency; - const origConvertCurrency = getGlobal().convertCurrency; - beforeEach(() => { - if (conversionFn) { - getGlobal().convertCurrency = mockConvertCurrency = sinon.stub().callsFake(conversionFn) - } else { - mockConvertCurrency = null; - delete getGlobal().convertCurrency; - } - }); - - afterEach(() => { - if (origConvertCurrency != null) { - getGlobal().convertCurrency = origConvertCurrency; - } else { - delete getGlobal().convertCurrency; - } - }); - - it(`should pick the ${expectDesc}`, () => { - adapter.callBids(s2sReq, BID_REQUESTS, addBidResponse, done, ajax); - const pbsReq = JSON.parse(server.requests[server.requests.length - 1].requestBody); - expect(deepAccess(pbsReq, `${target}.bidfloor`)).to.eql(expectedFloor); - expect(deepAccess(pbsReq, `${target}.bidfloorcur`)).to.eql(expectedCur) - }); - }); - }); - }) - }) - }); - }); - - if (FEATURES.NATIVE) { - describe('native requests', function () { - const ORTB_NATIVE_REQ = { - 'ver': '1.2', - 'assets': [ - { - 'required': 1, - 'id': 0, - 'title': { - 'len': 800 - } - }, - { - 'required': 1, - 'id': 1, - 'img': { - 'type': 3, - 'w': 989, - 'h': 742 - } - }, - { - 'required': 1, - 'id': 2, - 'img': { - 'type': 1, - 'wmin': 10, - 'hmin': 10, - 'ext': { - 'aspectratios': ['1:1'] - } - } - }, - { - 'required': 1, - 'id': 3, - 'data': { - 'type': 1 - } - } - ] - }; - - it('adds device.w and device.h even if the config lacks a device object', async function () { - const _config = { - s2sConfig: CONFIG, - }; - config.setConfig(_config); - adapter.callBids(await addFpdEnrichmentsToS2SRequest(REQUEST, BID_REQUESTS), BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - sinon.assert.match(requestBid.device, { - w: window.screen.width, - h: window.screen.height, - }) - expect(requestBid.imp[0].native.ver).to.equal('1.2'); - }); - - it('adds native request for OpenRTB', function () { - const _config = { - s2sConfig: CONFIG - }; - - config.setConfig(_config); - adapter.callBids({...REQUEST, s2sConfig: Object.assign({}, CONFIG, s2sDefaultConfig)}, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - const ortbReq = JSON.parse(requestBid.imp[0].native.request); - expect(ortbReq).to.deep.equal({ - ...ORTB_NATIVE_REQ, - 'eventtrackers': [{ - event: 1, - methods: [1, 2] - }], - }); - expect(requestBid.imp[0].native.ver).to.equal('1.2'); - }); - - it('adds native ortb request for OpenRTB', function () { - const _config = { - s2sConfig: CONFIG - }; - - const openRtbNativeRequest = deepClone(REQUEST); - delete openRtbNativeRequest.ad_units[0].mediaTypes.native; - delete openRtbNativeRequest.ad_units[0].nativeParams; - - openRtbNativeRequest.ad_units[0].mediaTypes.native = NATIVE_ORTB_MTO; - prepRequest(openRtbNativeRequest); - - config.setConfig(_config); - adapter.callBids(openRtbNativeRequest, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - const nativeReq = JSON.parse(requestBid.imp[0].native.request); - expect(nativeReq).to.deep.equal(NATIVE_ORTB_MTO.ortb); - expect(requestBid.imp[0].native.ver).to.equal('1.2'); - }); - - it('can override default values for imp.native.request with s2sConfig.ortbNative', () => { - const cfg = { - ...CONFIG, - ortbNative: { - eventtrackers: [ - {event: 1, methods: [1, 2]} - ] - } - } - config.setConfig({ - s2sConfig: cfg - }); - adapter.callBids({...REQUEST, s2sConfig: cfg}, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - const ortbReq = JSON.parse(requestBid.imp[0].native.request); - expect(ortbReq).to.eql({ - ...ORTB_NATIVE_REQ, - eventtrackers: [ - {event: 1, methods: [1, 2]} - ] - }) - }) - - it('should not include ext.aspectratios if adunit\'s aspect_ratios do not define radio_width and ratio_height', () => { - const req = deepClone(REQUEST); - req.ad_units[0].mediaTypes.native.icon.aspect_ratios[0] = {'min_width': 1, 'min_height': 2}; - prepRequest(req); - adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax); - const nativeReq = JSON.parse(JSON.parse(server.requests[0].requestBody).imp[0].native.request); - const icons = nativeReq.assets.map((a) => a.img).filter((img) => img && img.type === 1); - expect(icons).to.have.length(1); - expect(icons[0].hmin).to.equal(2); - expect(icons[0].wmin).to.equal(1); - expect(deepAccess(icons[0], 'ext.aspectratios')).to.be.undefined; - }); - }); - } - - it('adds site if app is not present', async function () { - const _config = { - s2sConfig: CONFIG, - }; - - config.setConfig(_config); - const s2sReq = await addFpdEnrichmentsToS2SRequest({ - ...REQUEST, - ortb2Fragments: { - global: { - site: { - publisher: { - id: '1234', - domain: 'test.com' - }, - content: { - language: 'en' - } - } - } - } - }, BID_REQUESTS); - adapter.callBids(s2sReq, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - expect(requestBid.site).to.exist.and.to.be.a('object'); - expect(requestBid.site.publisher).to.exist.and.to.be.a('object'); - expect(requestBid.site.publisher.id).to.exist.and.to.be.a('string'); - expect(requestBid.site.publisher.domain).to.exist.and.to.be.a('string'); - expect(requestBid.site.page).to.exist.and.to.be.a('string'); - expect(requestBid.site.content).to.exist.and.to.be.a('object'); - expect(requestBid.site.content.language).to.exist.and.to.be.a('string'); - expect(requestBid.site).to.deep.equal({ - publisher: { - id: '1234', - domain: 'test.com' - }, - content: { - language: 'en' - }, - domain: 'mytestpage.com', - page: 'http://mytestpage.com' - }); - }); - - it('site should not be present when app is present', async function () { - const _config = { - s2sConfig: CONFIG, - }; - - config.setConfig(_config); - - const s2sReq = await addFpdEnrichmentsToS2SRequest({ - ...REQUEST, - ortb2Fragments: { - global: { - app: {bundle: 'com.test.app'}, - site: { - publisher: { - id: '1234', - domain: 'test.com' - }, - content: { - language: 'en' - } - } - } - } - }, BID_REQUESTS) - adapter.callBids(s2sReq, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - expect(requestBid.site).to.not.exist; - expect(requestBid.app.bundle).to.eql('com.test.app'); - }); - - it('adds appnexus aliases to request', function () { - config.setConfig({ s2sConfig: CONFIG }); - - const aliasBidder = { - bidder: 'beintoo', - bid_id: REQUEST.ad_units[0].bids[0].bid_id, - params: { placementId: '123456' } - }; - - const request = utils.deepClone(REQUEST); - request.ad_units[0].bids = [aliasBidder]; - - adapter.callBids(request, [{...BID_REQUESTS[0], bidderCode: 'beintoo'}], addBidResponse, done, ajax); - - const requestBid = JSON.parse(server.requests[0].requestBody); - expect(requestBid.ext).to.haveOwnProperty('prebid'); - expect(requestBid.ext.prebid).to.deep.include({ - aliases: { - beintoo: 'appnexus' - }, - auctiontimestamp: 1510852447530, - targeting: { - includebidderkeys: false, - includewinners: true - } - }); - }); - - it('unregistered bidder should alias', function () { - const adjustedConfig = utils.deepClone(CONFIG); - adjustedConfig.bidders = 'bidderD' - config.setConfig({ s2sConfig: adjustedConfig }); - - const aliasBidder = { - ...REQUEST.ad_units[0].bids[0], - bidder: 'bidderD', - params: { - unit: '10433394', - } - }; - - getGlobal().aliasBidder('mockBidder', aliasBidder.bidder); - - const request = utils.deepClone(REQUEST); - request.ad_units[0].bids = [aliasBidder]; - request.s2sConfig = adjustedConfig; - - adapter.callBids(request, [{...BID_REQUESTS[0], bidderCode: aliasBidder.bidder}], addBidResponse, done, ajax); - - const requestBid = JSON.parse(server.requests[0].requestBody); - expect(requestBid.ext.prebid.aliases).to.deep.equal({ bidderD: 'mockBidder' }); - }); - - it('adds dynamic aliases to request', function () { - config.setConfig({ s2sConfig: CONFIG }); - - const alias = 'foobar'; - const aliasBidder = { - bidder: alias, - bid_id: REQUEST.ad_units[0].bids[0].bid_id, - params: { placementId: '123456' } - }; - - const request = utils.deepClone(REQUEST); - request.ad_units[0].bids = [aliasBidder]; - - // TODO: stub this - getGlobal().aliasBidder('appnexus', alias); - adapter.callBids(request, [{...BID_REQUESTS[0], bidderCode: 'foobar'}], addBidResponse, done, ajax); - - const requestBid = JSON.parse(server.requests[0].requestBody); - expect(requestBid.ext).to.haveOwnProperty('prebid'); - expect(requestBid.ext.prebid).to.deep.include({ - aliases: { - [alias]: 'appnexus' - }, - auctiontimestamp: 1510852447530, - targeting: { - includebidderkeys: false, - includewinners: true - } - }); - }); - - it('skips pbs alias when skipPbsAliasing is enabled in adapter', function () { - const s2sConfig = Object.assign({}, CONFIG, { - endpoint: { - p1Consent: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' - } - }); - config.setConfig({ s2sConfig: s2sConfig }); - registerBidder({ - code: 'bidderCodeForTestSkipBPSAlias', - aliases: [{ - code: 'bidderCodeForTestSkipBPSAlias_Alias', - skipPbsAliasing: true - }] - }) - const aliasBidder = { - bidder: 'bidderCodeForTestSkipBPSAlias_Alias', - bid_id: REQUEST.ad_units[0].bids[0].bid_id, - params: { aid: 123 } - }; - - const request = utils.deepClone(REQUEST); - request.ad_units[0].bids = [aliasBidder]; - - adapter.callBids(request, [{...BID_REQUESTS[0], bidderCode: aliasBidder.bidder}], addBidResponse, done, ajax); - - const requestBid = JSON.parse(server.requests[0].requestBody); - - sinon.assert.match(requestBid.ext.prebid, { - auctiontimestamp: 1510852447530, - targeting: { - includebidderkeys: false, - includewinners: true - }, - channel: { - name: 'oajs', - version: 'v$prebid.oaVersion$' - } - }) - }); - - it('skips dynamic aliases to request when skipPbsAliasing enabled', function () { - const s2sConfig = Object.assign({}, CONFIG, { - endpoint: { - p1Consent: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' - } - }); - config.setConfig({ s2sConfig: s2sConfig }); - - const alias = 'foobar_1'; - const aliasBidder = { - bidder: alias, - bid_id: REQUEST.ad_units[0].bids[0].bid_id, - params: { aid: 1234567 } - }; - - const request = utils.deepClone(REQUEST); - request.ad_units[0].bids = [aliasBidder]; - - // TODO: stub this - getGlobal().aliasBidder('appnexus', alias, { skipPbsAliasing: true }); - adapter.callBids(request, [{...BID_REQUESTS[0], bidderCode: aliasBidder.bidder}], addBidResponse, done, ajax); - - const requestBid = JSON.parse(server.requests[0].requestBody); - - sinon.assert.match(requestBid.ext.prebid, { - auctiontimestamp: 1510852447530, - targeting: { - includebidderkeys: false, - includewinners: true - }, - channel: { - name: 'oajs', - version: 'v$prebid.oaVersion$' - } - }); - }); - - describe('cookie sync', () => { - let s2sConfig, bidderReqs; - - beforeEach(() => { - bidderReqs = utils.deepClone(BID_REQUESTS); - s2sConfig = utils.deepClone(CONFIG); - s2sConfig.syncEndpoint = { p1Consent: 'https://prebid.adnxs.com/pbs/v1/cookie_sync' }; - }) - - function callCookieSync() { - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - config.setConfig({ s2sConfig: s2sConfig }); - adapter.callBids(s2sBidRequest, bidderReqs, addBidResponse, done, ajax); - return JSON.parse(server.requests[0].requestBody); - } - - describe('filterSettings', function () { - it('correctly adds filterSettings to the cookie_sync request if userSync.filterSettings is present in the config and only the all key is present in userSync.filterSettings', function () { - config.setConfig({ - userSync: { - filterSettings: { - all: { - bidders: ['appnexus', 'rubicon', 'pubmatic'], - filter: 'exclude' - } - } - } - }); - expect(callCookieSync().filterSettings).to.deep.equal({ - 'image': { - 'bidders': ['appnexus', 'rubicon', 'pubmatic'], - 'filter': 'exclude' - }, - 'iframe': { - 'bidders': ['appnexus', 'rubicon', 'pubmatic'], - 'filter': 'exclude' - } - }); - }); - - it('correctly adds filterSettings to the cookie_sync request if userSync.filterSettings is present in the config and only the iframe key is present in userSync.filterSettings', function () { - config.setConfig({ - userSync: { - filterSettings: { - iframe: { - bidders: ['rubicon', 'pubmatic'], - filter: 'include' - } - } - } - }) - - expect(callCookieSync().filterSettings).to.deep.equal({ - 'image': { - 'bidders': '*', - 'filter': 'include' - }, - 'iframe': { - 'bidders': ['rubicon', 'pubmatic'], - 'filter': 'include' - } - }); - }); - - it('correctly adds filterSettings to the cookie_sync request if userSync.filterSettings is present in the config and the image and iframe keys are both present in userSync.filterSettings', function () { - config.setConfig({ - userSync: { - filterSettings: { - image: { - bidders: ['triplelift', 'appnexus'], - filter: 'include' - }, - iframe: { - bidders: ['pulsepoint', 'triplelift', 'appnexus', 'rubicon'], - filter: 'exclude' - } - } - } - }) - - expect(callCookieSync().filterSettings).to.deep.equal({ - 'image': { - 'bidders': ['triplelift', 'appnexus'], - 'filter': 'include' - }, - 'iframe': { - 'bidders': ['pulsepoint', 'triplelift', 'appnexus', 'rubicon'], - 'filter': 'exclude' - } - }); - }); - - it('correctly adds filterSettings to the cookie_sync request if userSync.filterSettings is present in the config and the all and iframe keys are both present in userSync.filterSettings', function () { - config.setConfig({ - userSync: { - filterSettings: { - all: { - bidders: ['triplelift', 'appnexus'], - filter: 'include' - }, - iframe: { - bidders: ['pulsepoint', 'triplelift', 'appnexus', 'rubicon'], - filter: 'exclude' - } - } - } - }) - - expect(callCookieSync().filterSettings).to.deep.equal({ - 'image': { - 'bidders': ['triplelift', 'appnexus'], - 'filter': 'include' - }, - 'iframe': { - 'bidders': ['pulsepoint', 'triplelift', 'appnexus', 'rubicon'], - 'filter': 'exclude' - } - }); - }); - }); - - describe('limit', () => { - it('is added to request if userSyncLimit is greater than 0', function () { - s2sConfig.userSyncLimit = 1; - const req = callCookieSync(); - expect(req.limit).is.equal(1); - }); - - Object.entries({ - 'missing': () => null, - '0': () => { s2sConfig.userSyncLimit = 0; } - }).forEach(([t, setup]) => { - it(`is not added to request if userSyncLimit is ${t}`, () => { - setup(); - const req = callCookieSync(); - expect(req.limit).to.not.exist; - }); - }); - }); - - describe('gdpr data is set', () => { - it('when we have consent data', function () { - bidderReqs[0].gdprConsent = mockTCF(); - const req = callCookieSync(); - expect(req.gdpr).is.equal(1); - expect(req.gdpr_consent).is.equal('mockConsent'); - }); - - it('when gdprApplies is false', () => { - bidderReqs[0].gdprConsent = mockTCF({applies: false}); - const req = callCookieSync(); - expect(req.gdpr).is.equal(0); - expect(req.gdpr_consent).is.undefined; - }); - }); - - it('adds USP data from bidder request', () => { - bidderReqs[0].uspConsent = '1YNN'; - expect(callCookieSync().us_privacy).to.equal('1YNN'); - }); - - it('adds GPP data from bidder requests', () => { - bidderReqs[0].gppConsent = { - applicableSections: [1, 2, 3], - gppString: 'mock-string' - }; - const req = callCookieSync(); - expect(req.gpp).to.eql('mock-string'); - expect(req.gpp_sid).to.eql('1,2,3'); - }); - }); - - it('adds s2sConfig adapterOptions to request for ORTB', function () { - const s2sConfig = Object.assign({}, CONFIG, { - adapterOptions: { - appnexus: { - key: 'value' - } - } - }); - const _config = { - s2sConfig: s2sConfig, - device: { ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC' }, - app: { bundle: 'com.test.app' }, - }; - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - - config.setConfig(_config); - adapter.callBids(s2sBidRequest, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - const requestParams = requestBid.imp[0].ext.prebid.bidder; - expect(requestParams.appnexus).to.haveOwnProperty('key'); - expect(requestParams.appnexus.key).to.be.equal('value') - }); - - describe('config site value is added to the oRTB request', function () { - const s2sConfig = Object.assign({}, CONFIG, { - adapterOptions: { - appnexus: { - key: 'value' - } - } - }); - const device = { - ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36', - ip: '75.97.0.47' - }; - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - - it('and overrides publisher and page', async function () { - config.setConfig({ - s2sConfig: s2sConfig, - }); - const s2sReq = await addFpdEnrichmentsToS2SRequest({ - ...s2sBidRequest, - ortb2Fragments: { - global: { - site: { - domain: 'nytimes.com', - page: 'http://www.nytimes.com', - publisher: {id: '2'} - }, - device, - } - } - }, BID_REQUESTS); - adapter.callBids(s2sReq, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid.site).to.exist.and.to.be.a('object'); - expect(requestBid.site.domain).to.equal('nytimes.com'); - expect(requestBid.site.page).to.equal('http://www.nytimes.com'); - expect(requestBid.site.publisher).to.exist.and.to.be.a('object'); - expect(requestBid.site.publisher.id).to.equal('2'); - }); - - it('and merges domain and page with the config site value', async function () { - config.setConfig({ - s2sConfig: s2sConfig, - }); - const s2sReq = await addFpdEnrichmentsToS2SRequest({ - ...s2sBidRequest, - ortb2Fragments: { - global: { - site: { - foo: 'bar' - }, - device: device - } - } - }, BID_REQUESTS); - adapter.callBids(s2sReq, BID_REQUESTS, addBidResponse, done, ajax); - - const requestBid = JSON.parse(server.requests[0].requestBody); - expect(requestBid.site).to.exist.and.to.be.a('object'); - expect(requestBid.site.foo).to.equal('bar'); - expect(requestBid.site.page).to.equal('http://mytestpage.com'); - expect(requestBid.site.publisher).to.exist.and.to.be.a('object'); - expect(requestBid.site.publisher.id).to.equal('1'); - }); - }); - - describe('user.ext.eids', () => { - let req; - beforeEach(() => { - const s2sConfig = { - ...CONFIG, - bidders: ['appnexus', 'rubicon'] - } - config.setConfig({s2sConfig}); - req = { - ...REQUEST, - s2sConfig, - ortb2Fragments: { - global: { - user: { - ext: { - eids: [{source: 'idA', id: 1}, {source: 'idB', id: 2}] - } - } - }, - bidder: { - appnexus: { - user: { - ext: { - eids: [{source: 'idC', id: 3}] - } - } - } - } - } - } - }) - it('should get picked up from from FPD', function () { - adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax); - const payload = JSON.parse(server.requests[0].requestBody); - expect(payload.user.ext.eids).to.eql([ - {source: 'idA', id: 1}, - {source: 'idB', id: 2}, - {source: 'idC', id: 3} - ]); - expect(payload.ext.prebid.data.eidpermissions).to.eql([{ - bidders: ['appnexus'], - source: 'idC' - }]); - }); - - it('should not set eidpermissions for unrequested bidders', () => { - req.ortb2Fragments.bidder.unknown = { - user: { - eids: [{source: 'idC', id: 3}, {source: 'idD', id: 4}] - } - } - adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax); - const payload = JSON.parse(server.requests[0].requestBody); - expect(payload.ext.prebid.data.eidpermissions).to.eql([{ - bidders: ['appnexus'], - source: 'idC' - }, { - bidders: [], - source: 'idD' - }]); - }); - - it('should repeat global EIDs when bidder-specific EIDs conflict', () => { - BID_REQUESTS.push({ - ...BID_REQUESTS[0], - bidderCode: 'rubicon', - bids: [{ - bidder: 'rubicon', - params: {} - }] - }) - req.ortb2Fragments.bidder.rubicon = { - user: { - ext: { - eids: [{source: 'idC', id: 4}] - } - } - } - adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax); - const payload = JSON.parse(server.requests[0].requestBody); - const globalEids = [ - {source: 'idA', id: 1}, - {source: 'idB', id: 2}, - ] - expect(payload.user.ext.eids).to.eql(globalEids); - expect(payload.ext.prebid?.data?.eidpermissions).to.not.exist; - expect(payload.ext.prebid.bidderconfig).to.have.deep.members([ - { - bidders: ['appnexus'], - config: { - ortb2: { - user: {ext: {eids: globalEids.concat([{source: 'idC', id: 3}])}} - } - } - }, - { - bidders: ['rubicon'], - config: { - ortb2: { - user: {ext: {eids: globalEids.concat([{source: 'idC', id: 4}])}} - } - } - } - ]) - }) - }) - - it('when config \'currency.adServerCurrency\' value is a string: ORTB has property \'cur\' value set to a single item array', function () { - config.setConfig({ - currency: { adServerCurrency: 'NZ' }, - }); - - const bidRequests = utils.deepClone(BID_REQUESTS); - adapter.callBids(REQUEST, bidRequests, addBidResponse, done, ajax); - - const parsedRequestBody = JSON.parse(server.requests.find(req => req.method === 'POST').requestBody); - expect(parsedRequestBody.cur).to.deep.equal(['NZ']); - }); - - it('when config \'currency.adServerCurrency\' is unset: ORTB should not define a \'cur\' property', function () { - config.setConfig({ s2sConfig: CONFIG }); - - const bidRequests = utils.deepClone(BID_REQUESTS); - adapter.callBids(REQUEST, bidRequests, addBidResponse, done, ajax); - - const parsedRequestBody = JSON.parse(server.requests[0].requestBody); - expect(typeof parsedRequestBody.cur).to.equal('undefined'); - }); - - it('always add ext.prebid.targeting.includebidderkeys: false for ORTB', function () { - const s2sConfig = Object.assign({}, CONFIG, { - adapterOptions: { - appnexus: { - key: 'value' - } - } - }); - const _config = { - s2sConfig: s2sConfig, - device: { ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC' }, - app: { bundle: 'com.test.app' }, - }; - - config.setConfig(_config); - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - - adapter.callBids(s2sBidRequest, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid.ext.prebid.targeting).to.haveOwnProperty('includebidderkeys'); - expect(requestBid.ext.prebid.targeting.includebidderkeys).to.equal(false); - }); - - it('always add ext.prebid.targeting.includewinners: true for ORTB', function () { - const s2sConfig = Object.assign({}, CONFIG, { - adapterOptions: { - appnexus: { - key: 'value' - } - } - }); - const _config = { - s2sConfig: s2sConfig, - device: { ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC' }, - app: { bundle: 'com.test.app' }, - }; - config.setConfig(_config); - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - - adapter.callBids(s2sBidRequest, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid.ext.prebid.targeting).to.haveOwnProperty('includewinners'); - expect(requestBid.ext.prebid.targeting.includewinners).to.equal(true); - }); - - it('adds s2sConfig video.ext.prebid to request for ORTB', function () { - const s2sConfig = Object.assign({}, CONFIG, { - extPrebid: { - foo: 'bar' - } - }); - const _config = { - s2sConfig: s2sConfig, - device: { ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC' }, - app: { bundle: 'com.test.app' }, - }; - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - - config.setConfig(_config); - adapter.callBids(s2sBidRequest, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid).to.haveOwnProperty('ext'); - expect(requestBid.ext).to.haveOwnProperty('prebid'); - expect(requestBid.ext.prebid).to.deep.include({ - auctiontimestamp: 1510852447530, - foo: 'bar', - targeting: { - includewinners: true, - includebidderkeys: false - } - }); - }); - - it('overrides request.ext.prebid properties using s2sConfig video.ext.prebid values for ORTB', function () { - const s2sConfig = Object.assign({}, CONFIG, { - extPrebid: { - targeting: { - includewinners: false, - includebidderkeys: true - } - } - }); - const _config = { - s2sConfig: s2sConfig, - device: { ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC' }, - app: { bundle: 'com.test.app' }, - }; - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - - config.setConfig(_config); - adapter.callBids(s2sBidRequest, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid).to.haveOwnProperty('ext'); - expect(requestBid.ext).to.haveOwnProperty('prebid'); - expect(requestBid.ext.prebid).to.deep.include({ - auctiontimestamp: 1510852447530, - targeting: { - includewinners: false, - includebidderkeys: true - } - }); - }); - - it('overrides request.ext.prebid properties using s2sConfig video.ext.prebid values for ORTB', function () { - const s2sConfig = Object.assign({}, CONFIG, { - extPrebid: { - cache: { - vastxml: 'vastxml-set-though-extPrebid.cache.vastXml' - }, - targeting: { - includewinners: false, - includebidderkeys: false - } - } - }); - const _config = { - s2sConfig: s2sConfig, - device: { ifa: '6D92078A-8246-4BA4-AE5B-76104861E7DC' }, - app: { bundle: 'com.test.app' }, - }; - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - - config.setConfig(_config); - adapter.callBids(s2sBidRequest, BID_REQUESTS, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid).to.haveOwnProperty('ext'); - expect(requestBid.ext).to.haveOwnProperty('prebid'); - expect(requestBid.ext.prebid).to.deep.include({ - auctiontimestamp: 1510852447530, - cache: { - vastxml: 'vastxml-set-though-extPrebid.cache.vastXml' - }, - targeting: { - includewinners: false, - includebidderkeys: false - } - }); - }); - - it('should have extPrebid.schains present on req object if bidder specific schains were configured with pbjs', function () { - const bidRequest = utils.deepClone(BID_REQUESTS); - bidRequest[0].bids[0].ortb2 = { - source: { - ext: { - schain: { - complete: 1, - nodes: [{ - asi: 'test.com', - hp: 1, - sid: '11111' - }], - ver: '1.0' - } - } - } - }; - - adapter.callBids(REQUEST, bidRequest, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid.ext.prebid.schains).to.deep.equal([ - { - bidders: ['appnexus'], - schain: { - complete: 1, - nodes: [ - { - asi: 'test.com', - hp: 1, - sid: '11111' - } - ], - ver: '1.0' - } - } - ]); - }); - - it('should skip over adding any bid specific schain entries that already exist on extPrebid.schains', function () { - const bidRequest = utils.deepClone(BID_REQUESTS); - bidRequest[0].bids[0].schain = { - complete: 1, - nodes: [{ - asi: 'pbjs.com', - hp: 1, - sid: '22222' - }], - ver: '1.0' - }; - - const s2sConfig = Object.assign({}, CONFIG, { - extPrebid: { - schains: [ - { - bidders: ['appnexus'], - schain: { - complete: 1, - nodes: [ - { - asi: 'pbs.com', - hp: 1, - sid: '11111' - } - ], - ver: '1.0' - } - } - ] - } - }); - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - - adapter.callBids(s2sBidRequest, bidRequest, addBidResponse, done, ajax); - - const requestBid = JSON.parse(server.requests[0].requestBody); - expect(requestBid.ext.prebid.schains).to.deep.equal([ - { - bidders: ['appnexus'], - schain: { - complete: 1, - nodes: [ - { - asi: 'pbs.com', - hp: 1, - sid: '11111' - } - ], - ver: '1.0' - } - } - ]); - }); - - it('should add a bidder name to pbs schain if the schain is equal to a pbjs one but the pbjs bidder name is not in the bidder array on the pbs side', function () { - const bidRequest = utils.deepClone(BID_REQUESTS); - bidRequest[0].bids[0].ortb2 = { - source: { - ext: { - schain: { - complete: 1, - nodes: [{ - asi: 'test.com', - hp: 1, - sid: '11111' - }], - ver: '1.0' - } - } - } - }; - - bidRequest[0].bids[1] = { - bidder: 'rubicon', - params: { - accountId: 14062, - siteId: 70608, - zoneId: 498816 - } - }; - - const s2sConfig = Object.assign({}, CONFIG, { - bidders: ['rubicon', 'appnexus'], - extPrebid: { - schains: [ - { - bidders: ['rubicon'], - schain: { - complete: 1, - nodes: [ - { - asi: 'test.com', - hp: 1, - sid: '11111' - } - ], - ver: '1.0' - } - } - ] - } - }); - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - - adapter.callBids(s2sBidRequest, bidRequest, addBidResponse, done, ajax); - - const requestBid = JSON.parse(server.requests[0].requestBody); - expect(requestBid.ext.prebid.schains).to.deep.equal([ - { - bidders: ['rubicon', 'appnexus'], - schain: { - complete: 1, - nodes: [ - { - asi: 'test.com', - hp: 1, - sid: '11111' - } - ], - ver: '1.0' - } - } - ]); - }); - - Object.entries({ - 'set': {}, - 'override': {source: {ext: {schain: 'pub-provided'}}} - }).forEach(([t, fpd]) => { - it(`should not ${t} source.ext.schain`, () => { - const bidderReqs = [ - {...deepClone(BID_REQUESTS[0]), bidderCode: 'A'}, - {...deepClone(BID_REQUESTS[0]), bidderCode: 'B'}, - {...deepClone(BID_REQUESTS[0]), bidderCode: 'C'} - ]; - const chain1 = {chain: 1}; - const chain2 = {chain: 2}; - - bidderReqs[0].bids[0].schain = chain1; - bidderReqs[1].bids[0].schain = chain2; - bidderReqs[2].bids[0].schain = chain2; - - adapter.callBids({...REQUEST, ortb2Fragments: {global: fpd}}, bidderReqs, addBidResponse, done, ajax); - const req = JSON.parse(server.requests[0].requestBody); - expect(req.source?.ext?.schain).to.eql(fpd?.source?.ext?.schain); - }) - }) - - it('passes multibid array in request', function () { - const bidRequests = utils.deepClone(BID_REQUESTS); - const multibid = [{ - bidder: 'bidderA', - maxBids: 2 - }, { - bidder: 'bidderB', - maxBids: 2 - }]; - const expected = [{ - bidder: 'bidderA', - maxbids: 2 - }, { - bidder: 'bidderB', - maxbids: 2 - }]; - - config.setConfig({ multibid: multibid }); - - adapter.callBids(REQUEST, bidRequests, addBidResponse, done, ajax); - const parsedRequestBody = JSON.parse(server.requests[0].requestBody); - expect(parsedRequestBody.ext.prebid.multibid).to.deep.equal(expected); - }); - - it('sets and passes pbjs version in request if channel does not exist in s2sConfig', () => { - const s2sBidRequest = utils.deepClone(REQUEST); - const bidRequests = utils.deepClone(BID_REQUESTS); - - adapter.callBids(s2sBidRequest, bidRequests, addBidResponse, done, ajax); - - const parsedRequestBody = JSON.parse(server.requests[0].requestBody); - expect(parsedRequestBody.ext.prebid.channel).to.deep.equal({ name: 'oajs', version: 'v$prebid.oaVersion$' }); - }); - - it('extPrebid is now mergedDeep -> should include default channel as well', () => { - const s2sBidRequest = utils.deepClone(REQUEST); - const bidRequests = utils.deepClone(BID_REQUESTS); - - utils.deepSetValue(s2sBidRequest, 's2sConfig.extPrebid.channel', { test: 1 }); - - adapter.callBids(s2sBidRequest, bidRequests, addBidResponse, done, ajax); - - const parsedRequestBody = JSON.parse(server.requests[0].requestBody); - - // extPrebid is now deep merged with - expect(parsedRequestBody.ext.prebid.channel).to.deep.equal({ - name: 'oajs', - test: 1, - version: 'v$prebid.oaVersion$' - }); - }); - - it('passes first party data in request', async () => { - const s2sBidRequest = utils.deepClone(REQUEST); - const bidRequests = utils.deepClone(BID_REQUESTS); - - const commonSite = { - keywords: ['power tools'], - search: 'drill' - }; - const commonUser = { - keywords: ['a', 'b'], - gender: 'M' - }; - - const site = { - content: {userrating: 4}, - ext: { - data: { - pageType: 'article', - category: 'tools' - } - } - }; - const user = { - yob: '1984', - geo: {country: 'ca'}, - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - }; - const bcat = ['IAB25', 'IAB7-39']; - const badv = ['blockedAdv-1.com', 'blockedAdv-2.com']; - const allowedBidders = ['appnexus']; - - const expected = allowedBidders.map(bidder => ({ - bidders: [bidder], - config: { - ortb2: { - site: { - content: {userrating: 4}, - ext: { - data: { - pageType: 'article', - category: 'tools' - } - } - }, - user: { - yob: '1984', - geo: {country: 'ca'}, - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - }, - bcat: ['IAB25', 'IAB7-39'], - badv: ['blockedAdv-1.com', 'blockedAdv-2.com'] - } - } - })); - const commonContextExpected = utils.mergeDeep({ - 'page': 'http://mytestpage.com', - 'domain': 'mytestpage.com', - 'publisher': { - 'id': '1', - 'domain': 'mytestpage.com' - } - }, commonSite); - - const ortb2Fragments = { - global: {site: commonSite, user: commonUser, badv, bcat}, - bidder: Object.fromEntries(allowedBidders.map(bidder => [bidder, {site, user, bcat, badv}])) - }; - - adapter.callBids(await addFpdEnrichmentsToS2SRequest({ - ...s2sBidRequest, - ortb2Fragments - }, bidRequests), bidRequests, addBidResponse, done, ajax); - const parsedRequestBody = JSON.parse(server.requests[0].requestBody); - expect(parsedRequestBody.ext.prebid.bidderconfig).to.deep.equal(expected); - expect(parsedRequestBody.site).to.deep.equal(commonContextExpected); - expect(parsedRequestBody.user).to.deep.equal(commonUser); - expect(parsedRequestBody.badv).to.deep.equal(badv); - expect(parsedRequestBody.bcat).to.deep.equal(bcat); - }); - - it('passes first party data in request for unknown when allowUnknownBidderCodes is true', async () => { - const cfg = {...CONFIG, allowUnknownBidderCodes: true}; - config.setConfig({s2sConfig: cfg}); - - const clonedReq = {...REQUEST, s2sConfig: cfg} - const s2sBidRequest = utils.deepClone(clonedReq); - const bidRequests = utils.deepClone(BID_REQUESTS); - - const commonSite = { - keywords: ['power tools'], - search: 'drill' - }; - const commonUser = { - keywords: ['a', 'b'], - gender: 'M' - }; - - const site = { - content: {userrating: 4}, - ext: { - data: { - pageType: 'article', - category: 'tools' - } - } - }; - const user = { - yob: '1984', - geo: {country: 'ca'}, - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - }; - const bcat = ['IAB25', 'IAB7-39']; - const badv = ['blockedAdv-1.com', 'blockedAdv-2.com']; - const allowedBidders = ['appnexus', 'unknown']; - - const expected = allowedBidders.map(bidder => ({ - bidders: [bidder], - config: { - ortb2: { - site: { - content: {userrating: 4}, - ext: { - data: { - pageType: 'article', - category: 'tools' - } - } - }, - user: { - yob: '1984', - geo: {country: 'ca'}, - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - }, - bcat: ['IAB25', 'IAB7-39'], - badv: ['blockedAdv-1.com', 'blockedAdv-2.com'] - } - } - })); - const commonContextExpected = utils.mergeDeep({ - 'page': 'http://mytestpage.com', - 'domain': 'mytestpage.com', - 'publisher': { - 'id': '1', - 'domain': 'mytestpage.com' - } - }, commonSite); - - const ortb2Fragments = { - global: {site: commonSite, user: commonUser, badv, bcat}, - bidder: Object.fromEntries(allowedBidders.map(bidder => [bidder, {site, user, bcat, badv}])) - }; - - // adapter.callBids({ ...REQUEST, s2sConfig: cfg }, BID_REQUESTS, addBidResponse, done, ajax); - - adapter.callBids(await addFpdEnrichmentsToS2SRequest({ - ...s2sBidRequest, - ortb2Fragments - }, bidRequests, cfg), bidRequests, addBidResponse, done, ajax); - const parsedRequestBody = JSON.parse(server.requests[0].requestBody); - // eslint-disable-next-line no-console - console.log(parsedRequestBody); - expect(parsedRequestBody.ext.prebid.bidderconfig).to.deep.equal(expected); - expect(parsedRequestBody.site).to.deep.equal(commonContextExpected); - expect(parsedRequestBody.user).to.deep.equal(commonUser); - expect(parsedRequestBody.badv).to.deep.equal(badv); - expect(parsedRequestBody.bcat).to.deep.equal(bcat); - }); - - describe('GAM ad unit config', function () { - it('should not send \"imp.ext.data.adserver.adslot\" if \"ortb2Imp.ext\" is undefined', function () { - const consentConfig = { s2sConfig: CONFIG }; - config.setConfig(consentConfig); - const bidRequest = utils.deepClone(REQUEST); - - adapter.callBids(bidRequest, BID_REQUESTS, addBidResponse, done, ajax); - const parsedRequestBody = JSON.parse(server.requests[0].requestBody); - - expect(parsedRequestBody.imp).to.be.a('array'); - expect(parsedRequestBody.imp[0]).to.be.a('object'); - expect(parsedRequestBody.imp[0]).to.not.have.deep.nested.property('ext.data.adslot'); - }); - - it('should not send \"imp.ext.data.adserver.adslot\" if \"ortb2Imp.ext.data.adserver.adslot\" is undefined', function () { - const consentConfig = { s2sConfig: CONFIG }; - config.setConfig(consentConfig); - const bidRequest = utils.deepClone(REQUEST); - bidRequest.ad_units[0].ortb2Imp = {}; - - adapter.callBids(bidRequest, BID_REQUESTS, addBidResponse, done, ajax); - const parsedRequestBody = JSON.parse(server.requests[0].requestBody); - - expect(parsedRequestBody.imp).to.be.a('array'); - expect(parsedRequestBody.imp[0]).to.be.a('object'); - expect(parsedRequestBody.imp[0]).to.not.have.deep.nested.property('ext.data.adslot'); - }); - - it('should not send \"imp.ext.data.adserver.adslot\" if \"ortb2Imp.ext.data.adserver.adslot\" is empty string', function () { - const consentConfig = { s2sConfig: CONFIG }; - config.setConfig(consentConfig); - const bidRequest = utils.deepClone(REQUEST); - bidRequest.ad_units[0].ortb2Imp = { - ext: { - data: { - adserver: { - adslot: '' - } - } - } - }; - - adapter.callBids(bidRequest, BID_REQUESTS, addBidResponse, done, ajax); - const parsedRequestBody = JSON.parse(server.requests[0].requestBody); - - expect(parsedRequestBody.imp).to.be.a('array'); - expect(parsedRequestBody.imp[0]).to.be.a('object'); - expect(parsedRequestBody.imp[0]).to.not.have.deep.nested.property('ext.data.adslot'); - }); - - it('should send both \"adslot\" and \"name\" from \"imp.ext.data.adserver\" if \"ortb2Imp.ext.data.adserver.adslot\" and \"ortb2Imp.ext.data.adserver.name\" values are non-empty strings', function () { - const consentConfig = { s2sConfig: CONFIG }; - config.setConfig(consentConfig); - const bidRequest = utils.deepClone(REQUEST); - bidRequest.ad_units[0].ortb2Imp = { - ext: { - data: { - adserver: { - adslot: '/a/b/c', - name: 'adserverName1' - } - } - } - }; - - adapter.callBids(bidRequest, BID_REQUESTS, addBidResponse, done, ajax); - const parsedRequestBody = JSON.parse(server.requests[0].requestBody); - - expect(parsedRequestBody.imp).to.be.a('array'); - expect(parsedRequestBody.imp[0]).to.be.a('object'); - expect(parsedRequestBody.imp[0]).to.have.deep.nested.property('ext.data.adserver.adslot'); - expect(parsedRequestBody.imp[0]).to.have.deep.nested.property('ext.data.adserver.name'); - expect(parsedRequestBody.imp[0].ext.data.adserver.adslot).to.equal('/a/b/c'); - expect(parsedRequestBody.imp[0].ext.data.adserver.name).to.equal('adserverName1'); - }); - }); - }); - - describe('Bidder-level ortb2Imp', () => { - beforeEach(() => { - config.setConfig({ - s2sConfig: { - ...CONFIG, - bidders: ['A', 'B'] - } - }) - }) - it('should be set on imp.ext.prebid.imp', () => { - const s2sReq = utils.deepClone(REQUEST); - s2sReq.ad_units[0].ortb2Imp = {l0: 'adUnit'}; - s2sReq.ad_units[0].bids = [ - { - bidder: 'A', - bid_id: 1, - ortb2Imp: { - l2: 'A' - } - }, - { - bidder: 'B', - bid_id: 2, - ortb2Imp: { - l2: 'B' - } - } - ]; - const bidderReqs = [ - { - ...BID_REQUESTS[0], - bidderCode: 'A', - bids: [{ - bidId: 1, - bidder: 'A' - }] - }, - { - ...BID_REQUESTS[0], - bidderCode: 'B', - bids: [{ - bidId: 2, - bidder: 'B' - }] - } - ] - adapter.callBids(s2sReq, bidderReqs, addBidResponse, done, ajax); - const req = JSON.parse(server.requests[0].requestBody); - expect(req.imp[0].l0).to.eql('adUnit'); - expect(req.imp[0].ext.prebid.imp).to.eql({ - A: {l2: 'A'}, - B: {l2: 'B'} - }); - }); - }); - - describe('ext.prebid config', function () { - it('should send \"imp.ext.prebid.storedrequest.id\" if \"ortb2Imp.ext.prebid.storedrequest.id\" is set', function () { - const consentConfig = { s2sConfig: CONFIG }; - config.setConfig(consentConfig); - const bidRequest = utils.deepClone(REQUEST); - const storedRequestId = 'my-id'; - bidRequest.ad_units[0].ortb2Imp = { - ext: { - prebid: { - storedrequest: { - id: storedRequestId - } - } - } - }; - - adapter.callBids(bidRequest, BID_REQUESTS, addBidResponse, done, ajax); - const parsedRequestBody = JSON.parse(server.requests[0].requestBody); - - expect(parsedRequestBody.imp).to.be.a('array'); - expect(parsedRequestBody.imp[0]).to.be.a('object'); - expect(parsedRequestBody.imp[0]).to.have.deep.nested.property('ext.prebid.storedrequest.id'); - expect(parsedRequestBody.imp[0].ext.prebid.storedrequest.id).to.equal(storedRequestId); - }); - }); - - describe('response handler', function () { - beforeEach(function () { - sinon.stub(utils, 'triggerPixel'); - sinon.stub(utils, 'insertUserSyncIframe'); - sinon.stub(utils, 'logError'); - sinon.stub(events, 'emit'); - }); - - afterEach(function () { - utils.triggerPixel.restore(); - utils.insertUserSyncIframe.restore(); - utils.logError.restore(); - events.emit.restore(); - }); - - it('triggers BIDDER_ERROR on server error', () => { - config.setConfig({ s2sConfig: CONFIG }); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(400, {}, {}); - BID_REQUESTS.forEach(bidderRequest => { - sinon.assert.calledWith(events.emit, EVENTS.BIDDER_ERROR, sinon.match({ bidderRequest })) - }) - }) - - describe('calls done', () => { - let success, error; - beforeEach(() => { - const mockAjax = function (_, callback) { - ({success, error} = callback); - } - config.setConfig({ s2sConfig: CONFIG }); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, mockAjax); - }) - - it('passing timedOut = false on succcess', () => { - success({}); - sinon.assert.calledWith(done, false); - }); - - Object.entries({ - 'timeouts': true, - 'other errors': false - }).forEach(([t, timedOut]) => { - it(`passing timedOut = ${timedOut} on ${t}`, () => { - error('', {timedOut}); - sinon.assert.calledWith(done, timedOut); - }) - }) - }) - - // TODO: test dependent on pbjs_api_spec. Needs to be isolated - it('does not call addBidResponse and calls done when ad unit not set', function () { - config.setConfig({ s2sConfig: CONFIG }); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_NO_BID_NO_UNIT)); - - sinon.assert.notCalled(addBidResponse); - sinon.assert.calledOnce(done); - }); - - it('does not call addBidResponse and calls done when server requests cookie sync', function () { - config.setConfig({ s2sConfig: CONFIG }); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_NO_COOKIE)); - - sinon.assert.notCalled(addBidResponse); - sinon.assert.calledOnce(done); - }); - - it('does not call addBidResponse and calls done when ad unit is set', function () { - config.setConfig({ s2sConfig: CONFIG }); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_NO_BID_UNIT_SET)); - - sinon.assert.notCalled(addBidResponse); - sinon.assert.calledOnce(done); - }); - - it('registers successful bids and calls done when there are less bids than requests', function () { - config.setConfig({ s2sConfig: CONFIG }); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_OPENRTB)); - - sinon.assert.calledOnce(addBidResponse); - sinon.assert.calledOnce(done); - - expect(addBidResponse.firstCall.args[0]).to.equal('div-gpt-ad-1460505748561-0'); - - expect(addBidResponse.firstCall.args[1]).to.have.property('requestId', '123'); - }); - - it('should have dealId in bidObject', function () { - config.setConfig({ s2sConfig: CONFIG }); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_OPENRTB)); - const response = addBidResponse.firstCall.args[1]; - expect(response).to.have.property('dealId', 'test-dealid'); - }); - - if (FEATURES.VIDEO) { - it('should pass through default adserverTargeting if present in bidObject for video request', function () { - config.setConfig({ s2sConfig: CONFIG }); - const cacheResponse = utils.deepClone(RESPONSE_OPENRTB); - const targetingTestData = { - oa_cache_path: '/cache', - oa_cache_host: 'prebid-cache.testurl.com' - }; - - cacheResponse.seatbid.forEach(item => { - item.bid[0].ext.prebid.targeting = targetingTestData - }); - adapter.callBids(VIDEO_REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(cacheResponse)); - - sinon.assert.calledOnce(addBidResponse); - const response = addBidResponse.firstCall.args[1]; - expect(response).to.have.property('adserverTargeting'); - expect(response.adserverTargeting).to.deep.equal({ - 'oa_cache_path': '/cache', - 'oa_cache_host': 'prebid-cache.testurl.com' - }); - }); - } - - it('should set the bidResponse currency to whats in the PBS response', function () { - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_OPENRTB)); - sinon.assert.calledOnce(addBidResponse); - const pbjsResponse = addBidResponse.firstCall.args[1]; - expect(pbjsResponse).to.have.property('currency', 'EUR'); - }); - - it('should set the default bidResponse currency when not specified in OpenRTB', function () { - const modifiedResponse = utils.deepClone(RESPONSE_OPENRTB); - modifiedResponse.cur = ''; - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(modifiedResponse)); - sinon.assert.calledOnce(addBidResponse); - const pbjsResponse = addBidResponse.firstCall.args[1]; - expect(pbjsResponse).to.have.property('currency', 'USD'); - }); - - it('should pass through default adserverTargeting if present in bidObject for banner request', function () { - const cacheResponse = utils.deepClone(RESPONSE_OPENRTB); - - const targetingTestData = { - 'foo': 'bar' - }; - - cacheResponse.seatbid.forEach(item => { - item.bid[0].ext.prebid.targeting = targetingTestData - }); - - config.setConfig({ s2sConfig: CONFIG }); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(cacheResponse)); - sinon.assert.calledOnce(addBidResponse); - const response = addBidResponse.firstCall.args[1]; - expect(response).to.have.property('adserverTargeting').that.deep.equals({ 'foo': 'bar' }); - }); - - it('registers client user syncs when client bid adapter is present', function () { - const rubiconAdapter = { - registerSyncs: sinon.spy() - }; - sinon.stub(adapterManager, 'getBidAdapter').callsFake(() => rubiconAdapter); - - config.setConfig({ s2sConfig: CONFIG }); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_NO_PBS_COOKIE)); - - sinon.assert.calledOnce(rubiconAdapter.registerSyncs); - - adapterManager.getBidAdapter.restore(); - }); - - it('registers client user syncs when using OpenRTB endpoint', function () { - const rubiconAdapter = { - registerSyncs: sinon.spy() - }; - sinon.stub(adapterManager, 'getBidAdapter').returns(rubiconAdapter); - - config.setConfig({ CONFIG }); - - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_OPENRTB)); - - sinon.assert.calledOnce(rubiconAdapter.registerSyncs); - - adapterManager.getBidAdapter.restore(); - }); - - it('handles OpenRTB responses and call BIDDER_DONE', function () { - config.setConfig({ CONFIG }); - - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_OPENRTB)); - - sinon.assert.calledTwice(events.emit); - const event = events.emit.secondCall.args; - expect(event[0]).to.equal(EVENTS.BIDDER_DONE); - expect(event[1].bids[0]).to.have.property('serverResponseTimeMs', 8); - - sinon.assert.calledOnce(addBidResponse); - const response = addBidResponse.firstCall.args[1]; - expect(response).to.have.property('bidderCode', 'appnexus'); - expect(response).to.have.property('requestId', '123'); - expect(response).to.have.property('cpm', 0.5); - expect(response).to.have.property('meta'); - expect(response.meta).to.have.property('advertiserDomains'); - expect(response.meta.advertiserDomains[0]).to.equal('appnexus.com'); - expect(response.meta).to.have.property('dchain'); - expect(response.meta.dchain.ver).to.equal('1.0'); - expect(response.meta.dchain.nodes[0].asi).to.equal('magnite.com'); - expect(response).to.not.have.property('vastUrl'); - expect(response).to.not.have.property('videoCacheKey'); - expect(response).to.have.property('ttl', 60); - }); - - it('handles seatnonbid responses and emits SEAT_NON_BID', function () { - const original = CONFIG; - CONFIG.extPrebid = { returnallbidstatus: true }; - const nonbidResponse = {...RESPONSE_OPENRTB, ext: {seatnonbid: [{}]}}; - config.setConfig({ CONFIG }); - CONFIG = original; - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - const responding = deepClone(nonbidResponse); - Object.assign(responding.ext.seatnonbid, [{auctionId: 2}]) - server.requests[0].respond(200, {}, JSON.stringify(responding)); - const event = events.emit.thirdCall.args; - expect(event[0]).to.equal(EVENTS.SEAT_NON_BID); - expect(event[1].seatnonbid[0]).to.have.property('auctionId', 2); - expect(event[1].requestedBidders).to.deep.equal(['appnexus']); - expect(event[1].response).to.deep.equal(responding); - }); - - it('emits the PBS_ANALYTICS event and captures seatnonbid responses', function () { - const original = CONFIG; - CONFIG.extPrebid = { returnallbidstatus: true }; - const nonbidResponse = {...RESPONSE_OPENRTB, ext: {seatnonbid: [{}]}}; - config.setConfig({ CONFIG }); - CONFIG = original; - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - const responding = deepClone(nonbidResponse); - Object.assign(responding.ext.seatnonbid, [{auctionId: 2}]) - server.requests[0].respond(200, {}, JSON.stringify(responding)); - const event = events.emit.getCall(3).args; - expect(event[0]).to.equal(EVENTS.PBS_ANALYTICS); - expect(event[1].seatnonbid[0]).to.have.property('auctionId', 2); - expect(event[1].requestedBidders).to.deep.equal(['appnexus']); - expect(event[1].response).to.deep.equal(responding); - }); - - it('emits the PBS_ANALYTICS event and captures atag responses', function () { - const original = CONFIG; - CONFIG.extPrebid = { returnallbidstatus: true }; - const atagResponse = {...RESPONSE_OPENRTB, ext: {prebid: {analytics: {tags: ['data']}}}}; - config.setConfig({ CONFIG }); - CONFIG = original; - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - const responding = deepClone(atagResponse); - Object.assign(responding.ext.prebid.analytics.tags, ['stuff']) - server.requests[0].respond(200, {}, JSON.stringify(responding)); - const event = events.emit.thirdCall.args; - expect(event[0]).to.equal(EVENTS.PBS_ANALYTICS); - expect(event[1].atag[0]).to.deep.equal('stuff'); - expect(event[1].response).to.deep.equal(responding); - }); - - it('emits the BEFORE_PBS_HTTP event and captures responses', function () { - config.setConfig({ CONFIG }); - - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_OPENRTB)); - - sinon.assert.calledTwice(events.emit); - const event = events.emit.firstCall.args; - expect(event[0]).to.equal(EVENTS.BEFORE_PBS_HTTP); - expect(event[1]).to.have.property('requestJson', server.requests[0].requestBody); - expect(event[1]).to.have.property('endpointUrl', CONFIG.endpoint.p1Consent); - expect(event[1].customHeaders).to.deep.equal({}); - }); - - it('respects defaultTtl', function () { - const s2sConfig = Object.assign({}, CONFIG, { - defaultTtl: 30 - }); - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - - adapter.callBids(s2sBidRequest, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_OPENRTB)); - - sinon.assert.calledTwice(events.emit); - const event = events.emit.firstCall.args; - sinon.assert.calledOnce(addBidResponse); - const response = addBidResponse.firstCall.args[1]; - expect(response).to.have.property('ttl', 30); - }); - - if (FEATURES.VIDEO) { - it('handles OpenRTB video responses', function () { - const s2sConfig = Object.assign({}, CONFIG, { - endpoint: { - p1Consent: 'https://prebidserverurl/openrtb2/auction?querystring=param' - } - }); - config.setConfig({ s2sConfig }); - - const s2sVidRequest = utils.deepClone(VIDEO_REQUEST); - s2sVidRequest.s2sConfig = s2sConfig; - - adapter.callBids(s2sVidRequest, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_OPENRTB_VIDEO)); - - sinon.assert.calledOnce(addBidResponse); - const response = addBidResponse.firstCall.args[1]; - expect(response).to.have.property('vastXml', RESPONSE_OPENRTB_VIDEO.seatbid[0].bid[0].adm); - expect(response).to.have.property('mediaType', 'video'); - expect(response).to.have.property('bidderCode', 'appnexus'); - expect(response).to.have.property('requestId', '123'); - expect(response).to.have.property('cpm', 10); - }); - - it('handles response cache from ext.prebid.cache.vastXml', function () { - const s2sConfig = Object.assign({}, CONFIG, { - endpoint: { - p1Consent: 'https://prebidserverurl/openrtb2/auction?querystring=param' - } - }); - config.setConfig({ s2sConfig }); - const cacheResponse = utils.deepClone(RESPONSE_OPENRTB_VIDEO); - cacheResponse.seatbid.forEach(item => { - item.bid[0].ext.prebid.cache = { - vastXml: { - cacheId: 'abcd1234', - url: 'https://prebid-cache.net/cache?uuid=abcd1234' - } - } - }); - - const s2sVidRequest = utils.deepClone(VIDEO_REQUEST); - s2sVidRequest.s2sConfig = s2sConfig; - - adapter.callBids(s2sVidRequest, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(cacheResponse)); - - sinon.assert.calledOnce(addBidResponse); - const response = addBidResponse.firstCall.args[1]; - - expect(response).to.have.property('videoCacheKey', 'abcd1234'); - expect(response).to.have.property('vastUrl', 'https://prebid-cache.net/cache?uuid=abcd1234'); - }); - } - - it('add adserverTargeting object to bids when ext.prebid.targeting is defined', function () { - const s2sConfig = Object.assign({}, CONFIG, { - endpoint: { - p1Consent: 'https://prebidserverurl/openrtb2/auction?querystring=param' - } - }); - config.setConfig({ s2sConfig }); - const cacheResponse = utils.deepClone(RESPONSE_OPENRTB_VIDEO); - const targetingTestData = { - oa_cache_path: '/cache', - oa_cache_host: 'prebid-cache.testurl.com' - }; - - cacheResponse.seatbid.forEach(item => { - item.bid[0].ext.prebid.targeting = targetingTestData - }); - - if (FEATURES.VIDEO) { - const s2sVidRequest = utils.deepClone(VIDEO_REQUEST); - s2sVidRequest.s2sConfig = s2sConfig; - - adapter.callBids(s2sVidRequest, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(cacheResponse)); - - sinon.assert.calledOnce(addBidResponse); - const response = addBidResponse.firstCall.args[1]; - - expect(response).to.have.property('adserverTargeting'); - expect(response.adserverTargeting).to.deep.equal({ - 'oa_cache_path': '/cache', - 'oa_cache_host': 'prebid-cache.testurl.com' - }); - } - }); - - it('handles response cache from ext.prebid.targeting', function () { - const s2sConfig = Object.assign({}, CONFIG, { - endpoint: { - p1Consent: 'https://prebidserverurl/openrtb2/auction?querystring=param' - } - }); - config.setConfig({ s2sConfig }); - const cacheResponse = utils.deepClone(RESPONSE_OPENRTB_VIDEO); - cacheResponse.seatbid.forEach(item => { - item.bid[0].ext.prebid.targeting = { - oa_uuid: 'a5ad3993', - oa_cache_host: 'prebid-cache.net', - oa_cache_path: '/cache' - } - }); - - if (FEATURES.VIDEO) { - const s2sVidRequest = utils.deepClone(VIDEO_REQUEST); - s2sVidRequest.s2sConfig = s2sConfig; - - adapter.callBids(s2sVidRequest, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(cacheResponse)); - - sinon.assert.calledOnce(addBidResponse); - const response = addBidResponse.firstCall.args[1]; - - expect(response).to.have.property('videoCacheKey', 'a5ad3993'); - expect(response).to.have.property('vastUrl', 'https://prebid-cache.net/cache?uuid=a5ad3993'); - } - }); - - it('handles response cache from ext.prebid.targeting with wurl', function () { - const s2sConfig = Object.assign({}, CONFIG, { - endpoint: { - p1Consent: 'https://prebidserverurl/openrtb2/auction?querystring=param' - } - }); - config.setConfig({ s2sConfig }); - const cacheResponse = utils.deepClone(RESPONSE_OPENRTB_VIDEO); - cacheResponse.seatbid.forEach(item => { - item.bid[0].ext.prebid.events = { - win: 'https://wurl.com?a=1&b=2' - }; - item.bid[0].ext.prebid.targeting = { - oa_uuid: 'a5ad3993', - oa_cache_host: 'prebid-cache.net', - oa_cache_path: '/cache' - } - }); - - if (FEATURES.VIDEO) { - const s2sVidRequest = utils.deepClone(VIDEO_REQUEST); - s2sVidRequest.s2sConfig = s2sConfig; - - adapter.callBids(s2sVidRequest, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(cacheResponse)); - - sinon.assert.calledOnce(addBidResponse); - const response = addBidResponse.firstCall.args[1]; - expect(response).to.have.property('pbsBidId', '654321'); - } - }); - - it('add request property pbsBidId with ext.prebid.bidid value', function () { - const s2sConfig = Object.assign({}, CONFIG, { - endpoint: { - p1Consent: 'https://prebidserverurl/openrtb2/auction?querystring=param' - } - }); - config.setConfig({ s2sConfig }); - const cacheResponse = utils.deepClone(RESPONSE_OPENRTB_VIDEO); - - if (FEATURES.VIDEO) { - const s2sVidRequest = utils.deepClone(VIDEO_REQUEST); - s2sVidRequest.s2sConfig = s2sConfig; - - adapter.callBids(s2sVidRequest, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(cacheResponse)); - - sinon.assert.calledOnce(addBidResponse); - const response = addBidResponse.firstCall.args[1]; - - expect(response).to.have.property('pbsBidId', '654321'); - } - }); - - if (FEATURES.NATIVE) { - it('handles OpenRTB native responses', function () { - const stub = sinon.stub(auctionManager, 'index'); - stub.get(() => stubAuctionIndex({adUnits: REQUEST.ad_units})); - const s2sConfig = Object.assign({}, CONFIG, { - endpoint: { - p1Consent: 'https://prebidserverurl/openrtb2/auction?querystring=param' - } - }); - config.setConfig({s2sConfig}); - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - - adapter.callBids(s2sBidRequest, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_OPENRTB_NATIVE)); - - sinon.assert.calledOnce(addBidResponse); - const response = addBidResponse.firstCall.args[1]; - expect(response).to.have.property('adm').deep.equal(RESPONSE_OPENRTB_NATIVE.seatbid[0].bid[0].adm); - expect(response).to.have.property('mediaType', 'native'); - expect(response).to.have.property('bidderCode', 'appnexus'); - expect(response).to.have.property('requestId', '123'); - expect(response).to.have.property('cpm', 10); - - stub.restore(); - }); - } - - it('should reject invalid bids', () => { - config.setConfig({ s2sConfig: CONFIG }); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - const response = deepClone(RESPONSE_OPENRTB); - Object.assign(response.seatbid[0].bid[0], {w: null, h: null}); - server.requests[0].respond(200, {}, JSON.stringify(response)); - expect(addBidResponse.reject.calledOnce).to.be.true; - expect(addBidResponse.called).to.be.false; - }); - - it('does not (by default) allow bids that were not requested', function () { - config.setConfig({ s2sConfig: CONFIG }); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - const response = deepClone(RESPONSE_OPENRTB); - response.seatbid[0].seat = 'unknown'; - server.requests[0].respond(200, {}, JSON.stringify(response)); - - expect(addBidResponse.called).to.be.false; - expect(addBidResponse.reject.calledOnce).to.be.true; - }); - - it('allows unrequested bids if config.allowUnknownBidderCodes', function () { - const cfg = { ...CONFIG, allowUnknownBidderCodes: true }; - config.setConfig({ s2sConfig: cfg }); - adapter.callBids({ ...REQUEST, s2sConfig: cfg }, BID_REQUESTS, addBidResponse, done, ajax); - const response = deepClone(RESPONSE_OPENRTB); - response.seatbid[0].seat = 'unknown'; - server.requests[0].respond(200, {}, JSON.stringify(response)); - - expect(addBidResponse.calledWith(sinon.match.any, sinon.match({ bidderCode: 'unknown' }))).to.be.true; - }); - - describe('stored impressions', () => { - let bidReq, response; - - function mks2sReq(s2sConfig = CONFIG) { - return {...REQUEST, s2sConfig, ad_units: [{...REQUEST.ad_units[0], bids: [{bidder: null, bid_id: 'testId'}]}]}; - } - - beforeEach(() => { - bidReq = {...BID_REQUESTS[0], bidderCode: null, bids: [{...BID_REQUESTS[0].bids[0], bidder: null, bidId: 'testId'}]} - response = deepClone(RESPONSE_OPENRTB); - response.seatbid[0].seat = 'storedImpression'; - }) - - it('uses "null" request\'s ID for all responses, when a null request is present', function () { - const cfg = {...CONFIG, allowUnknownBidderCodes: true}; - config.setConfig({s2sConfig: cfg}); - adapter.callBids(mks2sReq(cfg), [bidReq], addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(response)); - sinon.assert.calledWith(addBidResponse, sinon.match.any, sinon.match({bidderCode: 'storedImpression', requestId: 'testId'})) - }); - - it('does not allow null requests (= stored impressions) if allowUnknownBidderCodes is not set', () => { - config.setConfig({s2sConfig: CONFIG}); - adapter.callBids(mks2sReq(), [bidReq], addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(response)); - expect(addBidResponse.called).to.be.false; - expect(addBidResponse.reject.calledOnce).to.be.true; - }); - }) - - it('copies ortb2Imp to response when there is only a null bid', () => { - const cfg = {...CONFIG}; - config.setConfig({s2sConfig: cfg}); - const ortb2Imp = {ext: {prebid: {storedrequest: 'value'}}}; - const req = {...REQUEST, s2sConfig: cfg, ad_units: [{...REQUEST.ad_units[0], bids: [{bidder: null, bid_id: 'testId'}], ortb2Imp}]}; - const bidReq = {...BID_REQUESTS[0], bidderCode: null, bids: [{...BID_REQUESTS[0].bids[0], bidder: null, bidId: 'testId'}]} - adapter.callBids(req, [bidReq], addBidResponse, done, ajax); - const actual = JSON.parse(server.requests[0].requestBody); - sinon.assert.match(actual.imp[0], sinon.match(ortb2Imp)); - }); - - it('setting adapterCode for default bidder', function () { - config.setConfig({ CONFIG }); - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_OPENRTB)); - - const response = addBidResponse.firstCall.args[1]; - expect(response).to.have.property('adapterCode', 'appnexus'); - }); - - it('setting adapterCode for alternate bidder', function () { - config.setConfig({ CONFIG }); - const RESPONSE_OPENRTB2 = deepClone(RESPONSE_OPENRTB); - RESPONSE_OPENRTB2.seatbid[0].bid[0].ext.prebid.meta.adaptercode = 'appnexus2' - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_OPENRTB2)); - - const response = addBidResponse.firstCall.args[1]; - expect(response).to.have.property('adapterCode', 'appnexus2'); - }); - - it('should set deferBilling and deferRendering to true when request has deferBilling = true', () => { - config.setConfig({ CONFIG }); - const req = deepClone(REQUEST); - req.ad_units.forEach(au => au.deferBilling = true); - adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(RESPONSE_OPENRTB)); - sinon.assert.match(addBidResponse.firstCall.args[1], { - deferBilling: true, - deferRendering: true - }); - }); - - describe('on sync requested with no cookie', () => { - let cfg, req, csRes; - - beforeEach(() => { - cfg = utils.deepClone(CONFIG); - req = utils.deepClone(REQUEST); - cfg.syncEndpoint = { p1Consent: 'https://prebid.adnxs.com/pbs/v1/cookie_sync' }; - req.s2sConfig = cfg; - config.setConfig({ s2sConfig: cfg }); - csRes = utils.deepClone(RESPONSE_NO_COOKIE); - }); - - afterEach(() => { - resetSyncedStatus(); - }) - - Object.entries({ - iframe: () => utils.insertUserSyncIframe, - image: () => utils.triggerPixel, - }).forEach(([type, syncer]) => { - it(`passes timeout to ${type} syncs`, () => { - cfg.syncTimeout = 123; - csRes.bidder_status[0].usersync.type = type; - adapter.callBids(req, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(csRes)); - expect(syncer().args[0]).to.include.members([123]); - }); - }); - }); - describe('when the response contains ext.prebid.fledge', () => { - const AU = 'div-gpt-ad-1460505748561-0'; - const FLEDGE_RESP = { - ext: { - prebid: { - fledge: { - auctionconfigs: [ - { - impid: AU, - bidder: 'appnexus', - config: { - id: 1 - } - }, - { - impid: AU, - bidder: 'other', - config: { - id: 2 - } - } - ] - } - } - } - } - - let fledgeStub, request, bidderRequests; - - function fledgeHook(next, ...args) { - fledgeStub(...args); - } - - before(() => { - addPaapiConfig.before(fledgeHook); - }); - - after(() => { - addPaapiConfig.getHooks({hook: fledgeHook}).remove(); - }) - - beforeEach(function () { - fledgeStub = sinon.stub(); - config.setConfig({ - s2sConfig: CONFIG, - }); - bidderRequests = deepClone(BID_REQUESTS); - bidderRequests.forEach(req => { - Object.assign(req, { - paapi: { - enabled: true - }, - ortb2: { - fpd: 1 - } - }) - req.bids.forEach(bid => { - Object.assign(bid, { - ortb2Imp: { - fpd: 2, - } - }) - }) - }); - request = deepClone(REQUEST); - request.ad_units.forEach(au => deepSetValue(au, 'ortb2Imp.ext.ae', 1)); - }); - - function expectFledgeCalls() { - const auctionId = bidderRequests[0].auctionId; - sinon.assert.calledWith(fledgeStub, sinon.match({auctionId, adUnitCode: AU, ortb2: bidderRequests[0].ortb2, ortb2Imp: bidderRequests[0].bids[0].ortb2Imp}), sinon.match({config: {id: 1}})) - sinon.assert.calledWith(fledgeStub, sinon.match({auctionId, adUnitCode: AU, ortb2: undefined, ortb2Imp: undefined}), sinon.match({config: {id: 2}})) - } - - it('calls addPaapiConfig alongside addBidResponse', function () { - adapter.callBids(request, bidderRequests, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(mergeDeep({}, RESPONSE_OPENRTB, FLEDGE_RESP))); - expect(addBidResponse.called).to.be.true; - expectFledgeCalls(); - }); - - it('calls addPaapiConfig when there is no bid in the response', () => { - adapter.callBids(request, bidderRequests, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(FLEDGE_RESP)); - expect(addBidResponse.called).to.be.false; - expectFledgeCalls(); - }); - - it('wraps call in runWithBidder', () => { - let fail = false; - fledgeStub.callsFake(({bidder}) => { - try { - expect(bidder).to.exist.and.to.eql(config.getCurrentBidder()); - } catch (e) { - fail = true; - } - }); - adapter.callBids(request, bidderRequests, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(FLEDGE_RESP)); - expect(fail).to.be.false; - }) - }); - }); - - describe('bid won events', function () { - let uniqueIdCount = 0; - let triggerPixelStub; - const staticUniqueIds = ['1000', '1001', '1002', '1003']; - - before(function () { - triggerPixelStub = sinon.stub(utils, 'triggerPixel'); - }); - - beforeEach(function () { - sinon.stub(utils, 'insertUserSyncIframe'); - sinon.stub(utils, 'logError'); - sinon.stub(utils, 'getUniqueIdentifierStr').callsFake(() => { - uniqueIdCount++; - return staticUniqueIds[uniqueIdCount - 1]; - }); - triggerPixelStub.resetHistory(); - - config.setConfig({ - s2sConfig: Object.assign({}, CONFIG, { - endpoint: { - p1Consent: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' - } - }) - }); - }); - - afterEach(function () { - utils.triggerPixel.resetHistory(); - utils.insertUserSyncIframe.restore(); - utils.logError.restore(); - utils.getUniqueIdentifierStr.restore(); - uniqueIdCount = 0; - }); - - after(function () { - triggerPixelStub.restore(); - }); - - it('should translate wurl and burl into eventtrackers', () => { - const burlEvent = {event: 1, method: 1, url: 'burl'}; - const winEvent = {event: 500, method: 1, url: 'events.win'}; - const trackerEvent = {event: 500, method: 1, url: 'eventtracker'}; - - const resp = utils.deepClone(RESPONSE_OPENRTB); - resp.seatbid[0].bid[0].ext.eventtrackers = [ - trackerEvent, - burlEvent - ] - resp.seatbid[0].bid[0].ext.prebid.events = { - win: winEvent.url - }; - resp.seatbid[0].bid[0].burl = burlEvent.url; - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(resp)); - expect(addBidResponse.getCall(0).args[1].eventtrackers).to.have.deep.members([ - burlEvent, trackerEvent, winEvent - ]); - }) - - it('should call triggerPixel if wurl is defined', function () { - const clonedResponse = utils.deepClone(RESPONSE_OPENRTB); - clonedResponse.seatbid[0].bid[0].ext.prebid.events = { - win: 'https://wurl.org' - }; - - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(clonedResponse)); - - sinon.assert.calledOnce(addBidResponse); - markWinningBid(addBidResponse.getCall(0).args[1]); - - expect(utils.triggerPixel.called).to.be.true; - expect(utils.triggerPixel.getCall(0).args[0]).to.include('https://wurl.org'); - }); - - it('should not call triggerPixel if wurl is undefined', function () { - const clonedResponse = utils.deepClone(RESPONSE_OPENRTB); - clonedResponse.seatbid[0].bid[0].ext.prebid.events = {}; - - adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax); - server.requests[0].respond(200, {}, JSON.stringify(clonedResponse)); - - sinon.assert.calledOnce(addBidResponse); - markWinningBid(addBidResponse.getCall(0).args[1]); - expect(utils.triggerPixel.called).to.be.false; - }); - }) - - describe('s2sConfig', function () { - let logErrorSpy; - - beforeEach(function () { - logErrorSpy = sinon.spy(utils, 'logError'); - resetSyncedStatus(); - }); - - afterEach(function () { - utils.logError.restore(); - }); - - it('should log an error when accountId is missing', function () { - const options = { - enabled: true, - bidders: ['appnexus'], - timeout: 1000, - adapter: 'openadsServer', - endpoint: { - p1Consent: 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction' - } - }; - - config.setConfig({ s2sConfig: options }); - sinon.assert.calledOnce(logErrorSpy); - }); - - it('should log an error when endpoint is missing', function () { - const options = { - accountId: '1', - bidders: ['appnexus'], - timeout: 1000, - enabled: true, - adapter: 'openadsServer' - }; - - config.setConfig({ s2sConfig: options }); - sinon.assert.calledOnce(logErrorSpy); - }); - - it('should log an error when using an unknown vendor', function () { - const options = { - accountId: '1', - bidders: ['appnexus'], - defaultVendor: 'mytest' - }; - - config.setConfig({ s2sConfig: options }); - sinon.assert.calledOnce(logErrorSpy); - }); - - it('should set adapterOptions', function () { - config.setConfig({ - s2sConfig: { - adapterOptions: { - rubicon: { - singleRequest: true, - foo: 'bar' - } - } - } - }); - expect(config.getConfig('s2sConfig').adapterOptions).to.deep.equal({ - rubicon: { - singleRequest: true, - foo: 'bar' - } - }) - }); - - it('should set default s2s ttl', function () { - config.setConfig({ - s2sConfig: { - defaultTtl: 30 - } - }); - expect(config.getConfig('s2sConfig').defaultTtl).to.deep.equal(30); - }); - - it('should set syncUrlModifier', function () { - config.setConfig({ - s2sConfig: { - syncUrlModifier: { - appnexus: () => { - } - } - } - }); - expect(typeof config.getConfig('s2sConfig').syncUrlModifier.appnexus).to.equal('function') - }); - - Object.entries({ - 'an alias'() { - adapterManager.aliasBidAdapter('rubicon', 'rubicon-alias'); - }, - 'a server side alias'(s2sConfig) { - s2sConfig.extPrebid = { - aliases: { - 'rubicon-alias': 'rubicon' - } - } - } - }).forEach(([t, setupAlias]) => { - describe(`when using ${t}`, () => { - afterEach(() => { - delete adapterManager.aliasRegistry['rubicon-alias']; - }); - it(`should set correct bidder names to bidders property`, function () { - const s2sConfig = utils.deepClone(CONFIG); - - // Add syncEndpoint so that the request goes to the User Sync endpoint - // Modify the bidders property to include an alias for Rubicon adapter - s2sConfig.syncEndpoint = {p1Consent: 'https://prebid.adnxs.com/pbs/v1/cookie_sync'}; - s2sConfig.bidders = ['appnexus', 'rubicon-alias']; - - setupAlias(s2sConfig); - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - - // Add another bidder, `rubicon-alias` - s2sBidRequest.ad_units[0].bids.push({ - bidder: 'rubicon-alias', - params: { - accoundId: 14062, - siteId: 70608, - zoneId: 498816 - } - }); - - const bidRequest = utils.deepClone(BID_REQUESTS); - bidRequest.push({ - 'bidderCode': 'rubicon-alias', - 'auctionId': '4146ab2b-9422-4040-9b1c-966fffbfe2d4', - 'bidderRequestId': '4b1a4f9c3e4546', - 'tid': 'd7fa8342-ae22-4ca1-b237-331169350f84', - 'bids': [ - { - 'bidder': 'rubicon-alias', - 'params': { - 'accountId': 14062, - 'siteId': 70608, - 'zoneId': 498816 - }, - 'bid_id': '2a9523915411c3', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': '78ddc106-b7d8-45d1-bd29-86993098e53d', - 'sizes': [ - [ - 300, - 250 - ] - ], - 'bidId': '2a9523915411c3', - 'bidderRequestId': '4b1a4f9c3e4546', - 'auctionId': '4146ab2b-9422-4040-9b1c-966fffbfe2d4' - } - ], - 'auctionStart': 1569234122602, - 'timeout': 1000, - 'src': 's2s' - }); - - adapter.callBids(s2sBidRequest, bidRequest, addBidResponse, done, ajax); - - const requestBid = JSON.parse(server.requests[0].requestBody); - expect(requestBid.bidders).to.deep.equal(['appnexus', 'rubicon']); - }); - }); - }); - - it('should add cooperative sync flag to cookie_sync request if property is present', function () { - const s2sConfig = utils.deepClone(CONFIG); - s2sConfig.coopSync = false; - s2sConfig.syncEndpoint = { p1Consent: 'https://prebid.adnxs.com/pbs/v1/cookie_sync' }; - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - - const bidRequest = utils.deepClone(BID_REQUESTS); - - adapter.callBids(s2sBidRequest, bidRequest, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid.coopSync).to.equal(false); - }); - - it('should not add cooperative sync flag to cookie_sync request if property is not present', function () { - const s2sConfig = utils.deepClone(CONFIG); - s2sConfig.syncEndpoint = { p1Consent: 'https://prebid.adnxs.com/pbs/v1/cookie_sync' }; - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - - const bidRequest = utils.deepClone(BID_REQUESTS); - - adapter.callBids(s2sBidRequest, bidRequest, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid.coopSync).to.be.undefined; - }); - - it('should set imp banner if ortb2Imp.banner is present', function () { - const consentConfig = { s2sConfig: CONFIG }; - config.setConfig(consentConfig); - const bidRequest = utils.deepClone(REQUEST); - bidRequest.ad_units[0].ortb2Imp = { - banner: { - api: 7 - }, - instl: 1 - }; - - adapter.callBids(bidRequest, BID_REQUESTS, addBidResponse, done, ajax); - const parsedRequestBody = JSON.parse(server.requests[0].requestBody); - - expect(parsedRequestBody.imp[0].banner.api).to.equal(7); - expect(parsedRequestBody.imp[0].instl).to.equal(1); - }); - - it('adds debug flag', function () { - config.setConfig({ debug: true }); - - const bidRequest = utils.deepClone(BID_REQUESTS); - - adapter.callBids(REQUEST, bidRequest, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid.ext.prebid.debug).is.equal(true); - }); - - it('should correctly add floors flag', function () { - const bidRequest = utils.deepClone(BID_REQUESTS); - - // should not pass if floorData is undefined - adapter.callBids(REQUEST, bidRequest, addBidResponse, done, ajax); - let requestBid = JSON.parse(server.requests[0].requestBody); - - expect(requestBid.ext.prebid.floors).to.be.undefined; - - config.setConfig({floors: {}}); - - adapter.callBids(REQUEST, bidRequest, addBidResponse, done, ajax); - requestBid = JSON.parse(server.requests[1].requestBody); - - expect(requestBid.ext.prebid.floors).to.deep.equal({ enabled: false }); - }); - - it('should override openads server default DEFAULT_S2S_CURRENCY', function () { - config.setConfig({ - currency: { adServerCurrency: 'JPY' }, - }); - - const bidRequests = utils.deepClone(BID_REQUESTS); - adapter.callBids(REQUEST, bidRequests, addBidResponse, done, ajax); - - const parsedRequestBody = JSON.parse(server.requests[1].requestBody); - expect(parsedRequestBody.cur).to.deep.equal(['JPY']); - }); - - it('should correctly set the floorMin key when multiple bids with various bidfloors exist', function () { - const s2sConfig = Object.assign({}, CONFIG, { - extPrebid: { - floors: { - enabled: true - } - }, - bidders: ['b1', 'b2'] - }); - - const bidderRequests = [ - { - ...BID_REQUESTS[0], - bidderCode: 'b1', - bids: [{ - bidder: 'b1', - bidId: 1, - getFloor: () => ({ - currency: 'US', - floor: 1.23 - }) - }] - }, - { - ...BID_REQUESTS[0], - bidderCode: 'b2', - bids: [{ - bidder: 'b2', - bidId: 2, - getFloor: () => ({ - currency: 'EUR', - floor: 3.21 - }) - }], - } - ]; - - const adUnits = [ - { - code: 'au1', - transactionId: 't1', - mediaTypes: { - banner: {sizes: [1, 1]} - }, - bids: [{bidder: 'b1', bid_id: 1}] - }, - { - code: 'au2', - transactionId: 't2', - bids: [{bidder: 'b2', bid_id: 2}], - mediaTypes: { - banner: {sizes: [1, 1]} - } - } - ]; - - const _config = { - s2sConfig: s2sConfig, - }; - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - s2sBidRequest.ad_units = adUnits; - config.setConfig(_config); - - adapter.callBids(s2sBidRequest, bidderRequests, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - expect(requestBid.imp[0].bidfloor).to.equal(1.23); - expect(requestBid.imp[1].bidfloor).to.equal(3.21); - - // first imp floorCur should be set - expect(requestBid.ext.prebid.floors).to.deep.equal({ enabled: true, floorMin: 1.23, floorMinCur: 'US' }); - }); - - it('should correctly set the floorMin key when multiple bids with various bidfloors exist and ortb2Imp contains the lowest floorMin', function () { - const s2sConfig = Object.assign({}, CONFIG, { - extPrebid: { - floors: { - enabled: true - } - }, - bidders: ['b1', 'b2'] - }); - - const bidderRequests = [ - { - ...BID_REQUESTS[0], - bidderCode: 'b1', - bids: [{ - bidder: 'b1', - bidId: 1, - getFloor: () => ({ - currency: 'CUR', - floor: 1.23 - }) - }] - }, - { - ...BID_REQUESTS[0], - bidderCode: 'b2', - bids: [{ - bidder: 'b2', - bidId: 2, - getFloor: () => ({ - currency: 'CUR', - floor: 3.21 - }) - }], - } - ]; - - const adUnits = [ - { - code: 'au1', - transactionId: 't1', - mediaTypes: { - banner: {sizes: [1, 1]} - }, - bids: [{bidder: 'b1', bid_id: 1}] - }, - { - code: 'au2', - transactionId: 't2', - bids: [{bidder: 'b2', bid_id: 2}], - mediaTypes: { - banner: {sizes: [1, 1]} - }, - ortb2Imp: { - ext: { - prebid: { - floors: { - floorMin: 1 - } - } - } - } - } - ]; - - const _config = { - s2sConfig: s2sConfig, - }; - - const s2sBidRequest = utils.deepClone(REQUEST); - s2sBidRequest.s2sConfig = s2sConfig; - s2sBidRequest.ad_units = adUnits; - config.setConfig(_config); - - adapter.callBids(s2sBidRequest, bidderRequests, addBidResponse, done, ajax); - const requestBid = JSON.parse(server.requests[0].requestBody); - expect(requestBid.imp[0].bidfloor).to.equal(1.23); - expect(requestBid.imp[1].bidfloor).to.equal(3.21); - - expect(requestBid.ext.prebid.floors).to.deep.equal({ enabled: true, floorMin: 1, floorMinCur: 'CUR' }); - }); - }); - - describe('getPBSBidderConfig', () => { - [ - { - t: 'does not alter config when there are no conflicts', - global: { - k1: 'val' - }, - bidder: { - bidderA: { - k2: 'val' - } - }, - expected: { - bidderA: { - k2: 'val' - } - } - }, - { - t: 'uses bidder config on type mismatch (scalar/object)', - global: { - k1: 'val', - k2: 'val' - }, - bidder: { - bidderA: { - k1: {k3: 'val'} - } - }, - expected: { - bidderA: { - k1: {k3: 'val'} - } - } - }, - { - t: 'uses bidder config on type mismatch (array/object)', - global: { - k: [1, 2] - }, - bidder: { - bidderA: { - k: {inner: 'val'} - } - }, - expected: { - bidderA: { - k: {inner: 'val'} - } - } - }, - { - t: 'uses bidder config on type mismatch (object/array)', - global: { - k: {inner: 'val'} - }, - bidder: { - bidderA: { - k: [1, 2] - } - }, - expected: { - bidderA: { - k: [1, 2] - } - } - }, - { - t: 'uses bidder config on type mismatch (array/null)', - global: { - k: [1, 2] - }, - bidder: { - bidderA: { - k: null - } - }, - expected: { - bidderA: { - k: null - } - } - }, - { - t: 'uses bidder config on type mismatch (null/array)', - global: {}, - bidder: { - bidderA: { - k: [1, 2] - } - }, - expected: { - bidderA: { - k: [1, 2] - } - } - }, - { - t: 'concatenates arrays', - global: { - key: 'value', - array: [1] - }, - bidder: { - bidderA: { - array: [2] - } - }, - expected: { - bidderA: { - array: [1, 2] - } - } - }, - { - t: 'concatenates nested arrays', - global: { - nested: { - array: [1] - } - }, - bidder: { - bidderA: { - key: 'value', - nested: { - array: [2] - } - } - }, - expected: { - bidderA: { - key: 'value', - nested: { - array: [1, 2] - } - } - } - }, - { - t: 'does not repeat equal elements', - global: { - array: [{id: 1}] - }, - bidder: { - bidderA: { - array: [{id: 1}, {id: 2}] - } - }, - expected: { - bidderA: { - array: [{id: 1}, {id: 2}] - } - } - } - ].forEach(({t, global, bidder, expected}) => { - it(t, () => { - expect(getPBSBidderConfig({global, bidder})).to.eql(expected); - }) - }) - }); - describe('EID handling', () => { - function mkEid(source, value = source) { - return {source, value}; - } - - function eidEntry(source, value = source, bidders = false) { - return {eid: {source, value}, bidders}; - } - - describe('extractEids', () => { - [ - { - t: 'no bidder-specific eids', - global: { - user: { - ext: { - eids: [ - mkEid('idA', 'id1'), - mkEid('idA', 'id2') - ] - }, - eids: [mkEid('idB')] - } - }, - expected: { - eids: [ - eidEntry('idA', 'id1'), - eidEntry('idA', 'id2'), - eidEntry('idB') - ], - conflicts: ['idA'] - } - }, - { - t: 'bidder-specific eids', - global: { - user: { - eids: [ - mkEid('idA') - ] - }, - }, - bidder: { - bidderA: { - user: { - ext: { - eids: [ - mkEid('idB') - ] - } - } - } - }, - expected: { - eids: [ - eidEntry('idA'), - eidEntry('idB', 'idB', ['bidderA']) - ] - } - }, - { - t: 'conflicting bidder-specific eids', - global: { - user: { - eids: [mkEid('idA', 'idA1')] - }, - }, - bidder: { - bidderA: { - user: { - eids: [mkEid('idA', 'idA2'), mkEid('idB', 'idB1'), mkEid('idD')] - }, - }, - bidderB: { - user: { - ext: { - eids: [mkEid('idB', 'idB2'), mkEid('idC'), mkEid('idD')] - } - } - }, - }, - expected: { - eids: [ - eidEntry('idA', 'idA1'), - eidEntry('idA', 'idA2', ['bidderA']), - eidEntry('idB', 'idB1', ['bidderA']), - eidEntry('idB', 'idB2', ['bidderB']), - eidEntry('idC', 'idC', ['bidderB']), - eidEntry('idD', 'idD', ['bidderA', 'bidderB']) - ], - conflicts: ['idA', 'idB'] - } - }, - { - t: 'duplicated bidder-specific eids', - bidder: { - bidderA: { - user: { - eids: [mkEid('id'), mkEid('id')] - } - } - }, - expected: { - eids: [ - eidEntry('id', 'id', ['bidderA']) - ] - } - } - ].forEach(({t, global = {}, bidder = {}, expected}) => { - it(t, () => { - const {eids, conflicts} = extractEids({global, bidder}); - expect(eids).to.have.deep.members(expected.eids); - expect(Array.from(conflicts)).to.have.members(expected.conflicts || []); - }) - }); - }); - describe('consolidateEids', () => { - it('returns global EIDs without permissions', () => { - expect(consolidateEids({ - eids: [eidEntry('idA'), eidEntry('idB')] - })).to.eql({ - global: [mkEid('idA'), mkEid('idB')], - permissions: [], - bidder: {} - }) - }); - - it('returns conflicting, but global EIDs', () => { - expect(consolidateEids({ - eids: [eidEntry('idA', 'idA1'), eidEntry('idA', 'idA2')], - conflicts: new Set(['idA']) - })).to.eql({ - global: [mkEid('idA', 'idA1'), mkEid('idA', 'idA2')], - permissions: [], - bidder: {} - }) - }) - - it('sets permissions for bidder-speficic EIDS', () => { - expect(consolidateEids({ - eids: [ - eidEntry('idA'), - eidEntry('idB', 'idB', ['bidderB']) - ] - })).to.eql({ - global: [mkEid('idA'), mkEid('idB')], - permissions: [{source: 'idB', bidders: ['bidderB']}], - bidder: {} - }) - }) - - it('does not consolidate conflicting bidder-specific EIDs', () => { - expect(consolidateEids({ - eids: [ - eidEntry('global'), - eidEntry('idA', 'idA1', ['bidderA']), - eidEntry('idA', 'idA2', ['bidderB']) - ], - conflicts: new Set(['idA']) - })).to.eql({ - global: [mkEid('global')], - permissions: [], - bidder: { - bidderA: [mkEid('idA', 'idA1')], - bidderB: [mkEid('idA', 'idA2')] - } - }) - }) - - it('does not set permissions for conflicting bidder-specific eids', () => { - expect(consolidateEids({ - eids: [eidEntry('idA', 'idA1'), eidEntry('idA', 'idA2', ['bidderA'])], - conflicts: new Set(['idA']) - })).to.eql({ - global: [mkEid('idA', 'idA1')], - permissions: [], - bidder: { - bidderA: [mkEid('idA', 'idA2')] - } - }) - }); - - it('can do partial consolidation when only some IDs are conflicting', () => { - expect(consolidateEids({ - eids: [ - eidEntry('idA', 'idA1'), - eidEntry('idB', 'idB', ['bidderB']), - eidEntry('idA', 'idA2', ['bidderA']) - ], - conflicts: new Set(['idA']) - })).to.eql({ - global: [mkEid('idA', 'idA1'), mkEid('idB')], - permissions: [{source: 'idB', bidders: ['bidderB']}], - bidder: { - bidderA: [mkEid('idA', 'idA2')] - } - }); - }); - }) - }); -}); diff --git a/test/spec/modules/openwebBidAdapter_spec.js b/test/spec/modules/openwebBidAdapter_spec.js deleted file mode 100644 index 197cdb85d..000000000 --- a/test/spec/modules/openwebBidAdapter_spec.js +++ /dev/null @@ -1,753 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/openwebBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import {BANNER, NATIVE, VIDEO} from '../../../src/mediaTypes.js'; -import * as utils from 'src/utils.js'; -import {decorateAdUnitsWithNativeParams} from '../../../src/native.js'; - -const ENDPOINT = 'https://hb.openwebmp.com/hb-multi'; -const TEST_ENDPOINT = 'https://hb.openwebmp.com/hb-multi-test'; -const TTL = 360; -/* eslint no-console: ["error", { allow: ["log", "warn", "error"] }] */ - -describe('openwebAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [['640', '480']], - 'params': { - 'org': 'jdye8weeyirk00000001', - 'placementId': '123' - } - }; - - it('should return true when required params are passed', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when org param is not found', function () { - const newBid = Object.assign({}, bid); - delete newBid.params; - newBid.params = { - 'org': null - }; - expect(spec.isBidRequestValid(newBid)).to.equal(false); - }); - - it('should return false when placementId param is not found', function () { - const newBid = Object.assign({}, bid); - delete newBid.params; - newBid.params = { - 'placementId': null - }; - expect(spec.isBidRequestValid(newBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[640, 480]], - 'params': { - 'org': 'jdye8weeyirk00000001', - 'placementId': '123' - }, - 'bidId': '299ffc8cca0b87', - 'loop': 1, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'video': { - 'playerSize': [[640, 480]], - 'context': 'instream', - 'plcmt': 1 - } - }, - }, - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'params': { - 'org': 'jdye8weeyirk00000001' - }, - 'bidId': '299ffc8cca0b87', - 'loop': 1, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'banner': { - } - }, - }, - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'params': { - 'org': 'jdye8weeyirk00000001' - }, - 'bidId': '299ffc8cca0b87', - 'loop': 1, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ 300, 250 ] - ] - }, - 'video': { - 'playerSize': [[640, 480]], - 'context': 'instream', - 'plcmt': 1 - }, - 'native': { - 'ortb': { - 'assets': [ - { - 'id': 1, - 'required': 1, - 'img': { - 'type': 3, - 'w': 300, - 'h': 200, - } - }, - { - 'id': 2, - 'required': 1, - 'title': { - 'len': 80 - } - }, - { - 'id': 3, - 'required': 1, - 'data': { - 'type': 1 - } - } - ] - } - }, - }, - } - ]; - - const testModeBidRequests = [ - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[640, 480]], - 'params': { - 'org': 'jdye8weeyirk00000001', - 'testMode': true - }, - 'bidId': '299ffc8cca0b87', - 'loop': 2, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - } - ]; - - const bidderRequest = { - bidderCode: 'openweb', - } - const api = [1, 2]; - const mimes = ['application/javascript', 'video/mp4', 'video/quicktime']; - const protocols = [2, 3, 5, 6]; - - it('sends the placementId to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].placementId).to.equal('123'); - }); - - it('sends the plcmt to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].plcmt).to.equal(1); - }); - - it('sends the is_wrapper parameter to ENDPOINT via POST', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('is_wrapper'); - expect(request.data.params.is_wrapper).to.equal(false); - }); - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('sends bid request to TEST ENDPOINT via POST', function () { - const request = spec.buildRequests(testModeBidRequests, bidderRequest); - expect(request.url).to.equal(TEST_ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('should send the correct bid Id', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].bidId).to.equal('299ffc8cca0b87'); - }); - - it('should send the correct supported api array', function () { - bidRequests[0].mediaTypes.video.api = api; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].api).to.be.an('array'); - expect(request.data.bids[0].api).to.eql([1, 2]); - }); - - it('should send the correct mimes array', function () { - bidRequests[0].mediaTypes.video.mimes = mimes; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].mimes).to.be.an('array'); - expect(request.data.bids[0].mimes).to.eql(['application/javascript', 'video/mp4', 'video/quicktime']); - }); - - it('should send the correct protocols array', function () { - bidRequests[0].mediaTypes.video.protocols = protocols; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].protocols).to.be.an('array'); - expect(request.data.bids[0].protocols).to.eql([2, 3, 5, 6]); - }); - - it('should send the correct sizes array', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].sizes).to.be.an('array'); - expect(request.data.bids[0].sizes).to.equal(bidRequests[0].sizes) - expect(request.data.bids[1].sizes).to.be.an('array'); - expect(request.data.bids[1].sizes).to.equal(bidRequests[1].sizes) - expect(request.data.bids[2].sizes).to.be.an('array'); - expect(request.data.bids[2].sizes).to.eql(bidRequests[2].sizes) - }); - - it('should send nativeOrtbRequest in native bid request', function () { - decorateAdUnitsWithNativeParams(bidRequests) - const request = spec.buildRequests(bidRequests, bidderRequest); - assert.deepEqual(request.data.bids[2].nativeOrtbRequest, bidRequests[2].mediaTypes.native.ortb) - }); - - it('should send the correct media type', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].mediaType).to.equal(VIDEO) - expect(request.data.bids[1].mediaType).to.equal(BANNER) - expect(request.data.bids[2].mediaType.split(',')).to.include.members([VIDEO, NATIVE, BANNER]) - }); - - it('should respect syncEnabled option', function() { - config.setConfig({ - userSync: { - syncEnabled: false, - filterSettings: { - all: { - bidders: '*', - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('cs_method'); - }); - - it('should respect "iframe" filter settings', function () { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - iframe: { - bidders: [spec.code], - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'iframe'); - }); - - it('should respect "all" filter settings', function () { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - all: { - bidders: [spec.code], - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'iframe'); - }); - - it('should send the pixel user sync param if userSync is enabled and no "iframe" or "all" configs are present', function () { - config.resetConfig(); - config.setConfig({ - userSync: { - syncEnabled: true, - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'pixel'); - }); - - it('should respect total exclusion', function() { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - image: { - bidders: [spec.code], - filter: 'exclude' - }, - iframe: { - bidders: [spec.code], - filter: 'exclude' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('cs_method'); - }); - - it('should have us_privacy param if usPrivacy is available in the bidRequest', function () { - const bidderRequestWithUSP = Object.assign({uspConsent: '1YNN'}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithUSP); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('us_privacy', '1YNN'); - }); - - it('should have an empty us_privacy param if usPrivacy is missing in the bidRequest', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('us_privacy'); - }); - - it('should not send the gdpr param if gdprApplies is false in the bidRequest', function () { - const bidderRequestWithGDPR = Object.assign({gdprConsent: {gdprApplies: false}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('gdpr'); - expect(request.data.params).to.not.have.property('gdpr_consent'); - }); - - it('should send the gdpr param if gdprApplies is true in the bidRequest', function () { - const bidderRequestWithGDPR = Object.assign({gdprConsent: {gdprApplies: true, consentString: 'test-consent-string'}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('gdpr', true); - expect(request.data.params).to.have.property('gdpr_consent', 'test-consent-string'); - }); - - it('should not send the gpp param if gppConsent is false in the bidRequest', function () { - const bidderRequestWithGPP = Object.assign({gppConsent: false}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGPP); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('gpp'); - expect(request.data.params).to.not.have.property('gpp_sid'); - }); - - it('should send the gpp param if gppConsent is true in the bidRequest', function () { - const bidderRequestWithGPP = Object.assign({gppConsent: {gppString: 'test-consent-string', applicableSections: [7]}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGPP); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('gpp', 'test-consent-string'); - expect(request.data.params.gpp_sid[0]).to.be.equal(7); - }); - - it('should have schain param if it is available in the bidRequest', () => { - bidderRequest.ortb2 = { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [{ asi: 'indirectseller.com', sid: '00001', hp: 1 }], - } - } - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('schain', '1.0,1!indirectseller.com,00001,1,,,'); - }); - - it('should set flooPrice to getFloor.floor value if it is greater than params.floorPrice', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.getFloor = () => { - return { - currency: 'USD', - floor: 3.32 - } - } - bid.params.floorPrice = 0.64; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0]).to.be.an('object'); - expect(request.data.bids[0]).to.have.property('floorPrice', 3.32); - }); - - it('should set floorPrice to params.floorPrice value if it is greater than getFloor.floor', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.getFloor = () => { - return { - currency: 'USD', - floor: 0.8 - } - } - bid.params.floorPrice = 1.5; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0]).to.be.an('object'); - expect(request.data.bids[0]).to.have.property('floorPrice', 1.5); - }); - - it('should check sua param in bid request', function() { - const sua = { - 'platform': { - 'brand': 'macOS', - 'version': ['12', '4', '0'] - }, - 'browsers': [ - { - 'brand': 'Chromium', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Google Chrome', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Not;A=Brand', - 'version': [ '99', '0', '0', '0' ] - } - ], - 'mobile': 0, - 'model': '', - 'bitness': '64', - 'architecture': 'x86' - } - const bid = utils.deepClone(bidRequests[0]); - bid.ortb2 = { - 'device': { - 'sua': { - 'platform': { - 'brand': 'macOS', - 'version': [ '12', '4', '0' ] - }, - 'browsers': [ - { - 'brand': 'Chromium', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Google Chrome', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Not;A=Brand', - 'version': [ '99', '0', '0', '0' ] - } - ], - 'mobile': 0, - 'model': '', - 'bitness': '64', - 'architecture': 'x86' - } - } - } - const requestWithSua = spec.buildRequests([bid], bidderRequest); - const data = requestWithSua.data; - expect(data.bids[0].sua).to.exist; - expect(data.bids[0].sua).to.deep.equal(sua); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].sua).to.not.exist; - }); - - describe('COPPA Param', function() { - it('should set coppa equal 0 in bid request if coppa is set to false', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].coppa).to.be.equal(0); - }); - - it('should set coppa equal 1 in bid request if coppa is set to true', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.ortb2 = { - 'regs': { - 'coppa': true, - } - }; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0].coppa).to.be.equal(1); - }); - }); - }); - - describe('interpretResponse', function () { - const response = { - params: { - currency: 'USD', - netRevenue: true, - }, - bids: [{ - cpm: 12.5, - vastXml: '', - width: 640, - height: 480, - requestId: '21e12606d47ba7', - creativeId: 'creative-id-1', - nurl: 'http://example.com/win/1234', - adomain: ['abc.com'], - mediaType: VIDEO - }, - { - cpm: 12.5, - ad: '""', - width: 300, - height: 250, - requestId: '21e12606d47ba7', - creativeId: 'creative-id-2', - nurl: 'http://example.com/win/1234', - adomain: ['abc.com'], - mediaType: BANNER - }, - { - cpm: 12.5, - width: 300, - height: 200, - requestId: '21e12606d47ba7', - adomain: ['abc.com'], - creativeId: 'creative-id-3', - nurl: 'http://example.com/win/1234', - mediaType: NATIVE, - native: { - body: 'Advertise with Rise', - clickUrl: 'https://risecodes.com', - cta: 'Start now', - image: { - width: 300, - height: 200, - url: 'https://sdk.streamrail.com/media/rise-image.jpg' - }, - sponsoredBy: 'Rise', - title: 'Rise Ad Tech Solutions' - } - }] - }; - - const expectedVideoResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 640, - height: 480, - ttl: TTL, - creativeId: 'creative-id-1', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: VIDEO, - meta: { - mediaType: VIDEO, - advertiserDomains: ['abc.com'] - }, - vastXml: '', - }; - - const expectedBannerResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 300, - height: 250, - ttl: TTL, - creativeId: 'creative-id-2', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: BANNER, - meta: { - mediaType: BANNER, - advertiserDomains: ['abc.com'] - }, - ad: '""' - }; - - const expectedNativeResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 300, - height: 200, - ttl: TTL, - creativeId: 'creative-id-3', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: NATIVE, - meta: { - mediaType: NATIVE, - advertiserDomains: ['abc.com'] - }, - native: { - ortb: { - body: 'Advertise with Rise', - clickUrl: 'https://risecodes.com', - cta: 'Start now', - image: { - width: 300, - height: 200, - url: 'https://sdk.streamrail.com/media/rise-image.jpg', - }, - sponsoredBy: 'Rise', - title: 'Rise Ad Tech Solutions' - } - }, - }; - - it('should get correct bid response', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[0]).to.deep.equal(expectedVideoResponse); - expect(result[1]).to.deep.equal(expectedBannerResponse); - expect(result[2]).to.deep.equal(expectedNativeResponse); - }); - - it('video type should have vastXml key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[0].vastXml).to.equal(expectedVideoResponse.vastXml) - }); - - it('banner type should have ad key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[1].ad).to.equal(expectedBannerResponse.ad) - }); - - it('native type should have native key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[2].native).to.eql(expectedNativeResponse.native) - }); - }) - - describe('getUserSyncs', function() { - const imageSyncResponse = { - body: { - params: { - userSyncPixels: [ - 'https://image-sync-url.test/1', - 'https://image-sync-url.test/2', - 'https://image-sync-url.test/3' - ] - } - } - }; - - const iframeSyncResponse = { - body: { - params: { - userSyncURL: 'https://iframe-sync-url.test' - } - } - }; - - it('should register all img urls from the response', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true }, [imageSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'image', - url: 'https://image-sync-url.test/1' - }, - { - type: 'image', - url: 'https://image-sync-url.test/2' - }, - { - type: 'image', - url: 'https://image-sync-url.test/3' - } - ]); - }); - - it('should register the iframe url from the response', function() { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [iframeSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://iframe-sync-url.test' - } - ]); - }); - - it('should register both image and iframe urls from the responses', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, [iframeSyncResponse, imageSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://iframe-sync-url.test' - }, - { - type: 'image', - url: 'https://image-sync-url.test/1' - }, - { - type: 'image', - url: 'https://image-sync-url.test/2' - }, - { - type: 'image', - url: 'https://image-sync-url.test/3' - } - ]); - }); - - it('should handle an empty response', function() { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, []); - expect(syncs).to.deep.equal([]); - }); - - it('should handle when user syncs are disabled', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: false }, [imageSyncResponse]); - expect(syncs).to.deep.equal([]); - }); - }) - - describe('onBidWon', function() { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - - it('Should trigger pixel if bid nurl', function() { - const bid = { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [['640', '480']], - 'nurl': 'http://example.com/win/1234', - 'params': { - 'org': 'jdye8weeyirk00000001' - } - }; - - spec.onBidWon(bid); - expect(utils.triggerPixel.callCount).to.equal(1) - }) - }) -}); diff --git a/test/spec/modules/openxBidAdapter_spec.js b/test/spec/modules/openxBidAdapter_spec.js deleted file mode 100644 index 66151fa26..000000000 --- a/test/spec/modules/openxBidAdapter_spec.js +++ /dev/null @@ -1,2190 +0,0 @@ -import {expect} from 'chai'; -import {spec, REQUEST_URL, SYNC_URL, DEFAULT_PH} from 'modules/openxBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import {BANNER, NATIVE, VIDEO} from 'src/mediaTypes.js'; -import {config} from 'src/config.js'; -import * as utils from 'src/utils.js'; -// load modules that register ORTB processors -import 'src/prebid.js' -import 'modules/currency.js'; -import 'modules/userId/index.js'; -import 'modules/multibid/index.js'; -import 'modules/priceFloors.js'; -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; -import 'modules/paapi.js'; - -import {deepClone} from 'src/utils.js'; -import {version} from 'package.json'; -import {addFPDToBidderRequest} from '../../helpers/fpd.js'; -import {hook} from '../../../src/hook.js'; -const DEFAULT_SYNC = SYNC_URL + '?ph=' + DEFAULT_PH; - -const BidRequestBuilder = function BidRequestBuilder(options) { - const defaults = { - request: { - auctionId: '4fd1ca2d-846c-4211-b9e5-321dfe1709c9', - adUnitCode: 'adunit-code', - bidder: 'openx' - }, - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - sizes: [[300, 250], [300, 600]], - }; - - const request = { - ...defaults.request, - ...options - }; - - this.withParams = (options) => { - request.params = { - ...defaults.params, - ...options - }; - return this; - }; - - this.build = () => request; -}; - -const BidderRequestBuilder = function BidderRequestBuilder(options) { - const defaults = { - bidderCode: 'openx', - auctionId: '4fd1ca2d-846c-4211-b9e5-321dfe1709c9', - bidderRequestId: '7g36s867Tr4xF90X', - timeout: 3000, - refererInfo: { - numIframes: 0, - reachedTop: true, - referer: 'http://test.io/index.html?pbjs_debug=true' - } - }; - - const request = { - ...defaults, - ...options - }; - - this.build = () => request; -}; - -describe('OpenxRtbAdapter', function () { - before(() => { - hook.ready(); - }); - - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid()', function () { - describe('when request is for a banner ad', function () { - let bannerBid; - beforeEach(function () { - bannerBid = { - bidder: 'openx', - params: {}, - adUnitCode: 'adunit-code', - mediaTypes: {banner: {}}, - sizes: [[300, 250], [300, 600]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475' - }; - }); - - it('should return false when there is no delivery domain', function () { - bannerBid.params = {'unit': '12345678'}; - expect(spec.isBidRequestValid(bannerBid)).to.equal(false); - }); - - describe('when there is a delivery domain', function () { - beforeEach(function () { - bannerBid.params = {delDomain: 'test-delivery-domain'} - }); - - it('should return false when there is no ad unit id and size', function () { - expect(spec.isBidRequestValid(bannerBid)).to.equal(false); - }); - - it('should return true if there is an adunit id ', function () { - bannerBid.params.unit = '12345678'; - expect(spec.isBidRequestValid(bannerBid)).to.equal(true); - }); - - it('should return true if there is no adunit id and sizes are defined', function () { - bannerBid.mediaTypes.banner.sizes = [720, 90]; - expect(spec.isBidRequestValid(bannerBid)).to.equal(true); - }); - - it('should return false if no sizes are defined ', function () { - expect(spec.isBidRequestValid(bannerBid)).to.equal(false); - }); - - it('should return false if sizes empty ', function () { - bannerBid.mediaTypes.banner.sizes = []; - expect(spec.isBidRequestValid(bannerBid)).to.equal(false); - }); - }); - }); - - describe('when request is for a multiformat ad', function () { - describe('and request config uses mediaTypes video and banner', () => { - const multiformatBid = { - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250]] - }, - video: { - playerSize: [300, 250] - } - }, - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '4008d88a-8137-410b-aa35-fbfdabcb478e' - }; - it('should return true multisize when required params found', function () { - expect(spec.isBidRequestValid(multiformatBid)).to.equal(true); - }); - }); - }); - - describe('when request is for a video ad', function () { - describe('and request config uses mediaTypes', () => { - const videoBidWithMediaTypes = { - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - video: { - playerSize: [640, 480] - } - }, - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '4008d88a-8137-410b-aa35-fbfdabcb478e' - }; - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(videoBidWithMediaTypes)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidVideoBidWithMediaTypes = Object.assign({}, videoBidWithMediaTypes); - invalidVideoBidWithMediaTypes.params = {}; - expect(spec.isBidRequestValid(invalidVideoBidWithMediaTypes)).to.equal(false); - }); - }); - describe('and request config uses both delDomain and platform', () => { - const videoBidWithDelDomainAndPlatform = { - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain', - platform: '1cabba9e-cafe-3665-beef-f00f00f00f00' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - video: { - playerSize: [640, 480] - } - }, - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '4008d88a-8137-410b-aa35-fbfdabcb478e' - }; - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(videoBidWithDelDomainAndPlatform)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidVideoBidWithMediaTypes = Object.assign({}, videoBidWithDelDomainAndPlatform); - invalidVideoBidWithMediaTypes.params = {}; - expect(spec.isBidRequestValid(invalidVideoBidWithMediaTypes)).to.equal(false); - }); - }); - describe('and request config uses mediaType', () => { - const videoBidWithMediaType = { - 'bidder': 'openx', - 'params': { - 'unit': '12345678', - 'delDomain': 'test-del-domain' - }, - 'adUnitCode': 'adunit-code', - 'mediaType': 'video', - 'sizes': [640, 480], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'transactionId': '4008d88a-8137-410b-aa35-fbfdabcb478e' - }; - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(videoBidWithMediaType)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidVideoBidWithMediaType = Object.assign({}, videoBidWithMediaType); - delete invalidVideoBidWithMediaType.params; - invalidVideoBidWithMediaType.params = {}; - expect(spec.isBidRequestValid(invalidVideoBidWithMediaType)).to.equal(false); - }); - }); - }); - - describe('when request is for a native ad', function () { - const nativeOrtbRequest = { - assets: [{ - id: 1, - required: 1, - title: { - len: 80 - } - }] - } - describe('and request config uses mediaTypes', () => { - const nativeBidWithMediaTypes = { - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - native: { - ortb: { - ...nativeOrtbRequest - } - } - }, - nativeOrtbRequest, - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '4008d88a-8137-410b-aa35-fbfdabcb478e' - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(nativeBidWithMediaTypes)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidNativeBidWithMediaTypes = Object.assign({}, nativeBidWithMediaTypes); - invalidNativeBidWithMediaTypes.params = {}; - expect(spec.isBidRequestValid(invalidNativeBidWithMediaTypes)).to.equal(false); - }); - }); - - describe('and request config uses both delDomain and platform', () => { - const nativeBidWithDelDomainAndPlatform = { - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain', - platform: '1cabba9e-cafe-3665-beef-f00f00f00f00' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - native: { - ortb: { - ...nativeOrtbRequest - } - } - }, - nativeOrtbRequest, - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '4008d88a-8137-410b-aa35-fbfdabcb478e' - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(nativeBidWithDelDomainAndPlatform)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidNativeBidWithMediaTypes = Object.assign({}, nativeBidWithDelDomainAndPlatform); - invalidNativeBidWithMediaTypes.params = {}; - expect(spec.isBidRequestValid(invalidNativeBidWithMediaTypes)).to.equal(false); - }); - }); - }); - }); - - describe('buildRequests()', function () { - let bidRequestsWithMediaTypes; - let mockBidderRequest; - const nativeOrtbRequest = { - assets: [{ - id: 1, - required: 1, - title: { - len: 80 - } - }] - }; - const nativeBidRequest = { - bidder: 'openx', - params: { - unit: '33', - delDomain: 'test-del-domain', - platform: '1cabba9e-cafe-3665-beef-f00f00f00f00', - }, - adUnitCode: 'adunit-code', - mediaTypes: { - native: { - ortb: { - ...nativeOrtbRequest - } - } - }, - nativeOrtbRequest, - bidId: 'test-bid-id-3', - bidderRequestId: 'test-bid-request-3', - auctionId: 'test-auction-3', - transactionId: 'test-transactionId-3' - }; - - beforeEach(function () { - mockBidderRequest = {refererInfo: {}}; - - bidRequestsWithMediaTypes = [{ - bidder: 'openx', - params: { - unit: '11', - delDomain: 'test-del-domain', - platform: '1cabba9e-cafe-3665-beef-f00f00f00f00', - }, - adUnitCode: '/adunit-code/test-path', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - transactionId: 'test-transactionId-1', - ortb2Imp: { - ext: { - ae: 2 - } - } - }, { - bidder: 'openx', - params: { - unit: '22', - delDomain: 'test-del-domain', - platform: '1cabba9e-cafe-3665-beef-f00f00f00f00', - }, - adUnitCode: 'adunit-code', - mediaTypes: { - video: { - playerSize: [640, 480] - } - }, - bidId: 'test-bid-id-2', - bidderRequestId: 'test-bid-request-2', - auctionId: 'test-auction-2', - transactionId: 'test-transactionId-2' - }]; - }); - - context('common requests checks', function() { - it('should be able to handle multiformat request - banner + video', () => { - const multiformat = utils.deepClone(bidRequestsWithMediaTypes[0]); - multiformat.mediaTypes.video = { - context: 'outstream', - playerSize: [640, 480] - }; - const requests = spec.buildRequests([multiformat], mockBidderRequest); - expect(requests).to.have.length(2); - expect(requests[0].data.imp).to.have.length(1); - expect(requests[0].data.imp[0].banner).to.exist; - expect(requests[0].data.imp[0].video).to.not.exist; - expect(requests[0].data.imp[0].native).to.not.exist; - expect(requests[1].data.imp).to.have.length(1); - expect(requests[1].data.imp[0].banner).to.not.exist; - expect(requests[1].data.imp[0].native).to.not.exist; - if (FEATURES.VIDEO) { - expect(requests[1].data.imp[0].video).to.exist; - } - }) - - it('should be able to handle multiformat request - banner + native', () => { - const multiformat = utils.deepClone(nativeBidRequest); - multiformat.mediaTypes.banner = { - sizes: [[300, 250], [300, 600]] - } - const requests = spec.buildRequests([multiformat], mockBidderRequest); - expect(requests).to.have.length(1); - expect(requests[0].data.imp).to.have.length(1); - expect(requests[0].data.imp[0].banner).to.exist; - expect(requests[0].data.imp[0].video).to.not.exist; - if (FEATURES.NATIVE) { - expect(requests[0].data.imp[0].native).to.exist; - } - }) - - it('should be able to handle multiformat request - banner + video + native', () => { - const multiformat = utils.deepClone(nativeBidRequest); - multiformat.mediaTypes.video = { - context: 'outstream', - playerSize: [640, 480] - }; - multiformat.mediaTypes.banner = { - sizes: [[300, 250]] - } - const requests = spec.buildRequests([multiformat], mockBidderRequest); - expect(requests).to.have.length(2); - expect(requests[0].data.imp).to.have.length(1); - expect(requests[0].data.imp[0].banner).to.exist; - expect(requests[0].data.imp[0].video).to.not.exist; - if (FEATURES.NATIVE) { - expect(requests[0].data.imp[0].native).to.exist; - } - expect(requests[1].data.imp).to.have.length(1); - expect(requests[1].data.imp[0].banner).to.not.exist; - expect(requests[1].data.imp[0].native).to.not.exist; - if (FEATURES.VIDEO) { - expect(requests[1].data.imp[0].video).to.exist; - } - }) - - it('should send bid request to openx url via POST', function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest); - expect(request[0].url).to.equal(REQUEST_URL); - expect(request[0].method).to.equal('POST'); - expect(request[0].data.ext.pv).to.equal(version); - }); - - it('should send delivery domain, if available', function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest); - expect(request[0].data.ext.delDomain).to.equal(bidRequestsWithMediaTypes[0].params.delDomain); - expect(request[0].data.ext.platformId).to.be.undefined; - }); - - it('should send platform id, if available', function () { - bidRequestsWithMediaTypes[0].params.platform = '1cabba9e-cafe-3665-beef-f00f00f00f00'; - bidRequestsWithMediaTypes[1].params.platform = '51ca3159-abc2-4035-8e00-fe26eaa09397'; - - const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest); - expect(request[0].data.ext.platform).to.equal(bidRequestsWithMediaTypes[0].params.platform); - expect(request[1].data.ext.platform).to.equal(bidRequestsWithMediaTypes[1].params.platform); - }); - - it('should send openx adunit codes', function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest); - expect(request[0].data.imp[0].tagid).to.equal(bidRequestsWithMediaTypes[0].params.unit); - expect(request[1].data.imp[0].tagid).to.equal(bidRequestsWithMediaTypes[1].params.unit); - }); - - it('should send out custom params on bids that have customParams specified', function () { - const bidRequest = Object.assign({}, - bidRequestsWithMediaTypes[0], - { - params: { - unit: '12345678', - delDomain: 'test-del-domain', - customParams: {'Test1': 'testval1+', 'test2': ['testval2/', 'testval3']} - } - } - ); - - mockBidderRequest.bids = [bidRequest]; - const request = spec.buildRequests([bidRequest], mockBidderRequest); - expect(request[0].data.imp[0].ext.customParams).to.equal(bidRequest.params.customParams); - }) - - describe('floors', function () { - it('should send out custom floors on bids that have customFloors, no currency as account currency is used', function () { - const bidRequest = Object.assign({}, - bidRequestsWithMediaTypes[0], - { - params: { - unit: '12345678', - delDomain: 'test-del-domain', - customFloor: 1.500 - } - } - ); - - const request = spec.buildRequests([bidRequest], mockBidderRequest); - expect(request[0].data.imp[0].bidfloor).to.equal(bidRequest.params.customFloor); - expect(request[0].data.imp[0].bidfloorcur).to.equal(undefined); - }); - - context('with floors module', function () { - let adServerCurrencyStub; - - beforeEach(function () { - adServerCurrencyStub = sinon - .stub(config, 'getConfig') - .withArgs('currency.adServerCurrency') - }); - - afterEach(function () { - config.getConfig.restore(); - }); - - it('should send out floors on bids in USD', function () { - const bidRequest = Object.assign({}, - bidRequestsWithMediaTypes[0], - { - getFloor: () => { - return { - currency: 'USD', - floor: 9.99 - } - } - } - ); - - const request = spec.buildRequests([bidRequest], mockBidderRequest); - expect(request[0].data.imp[0].bidfloor).to.equal(9.99); - expect(request[0].data.imp[0].bidfloorcur).to.equal('USD'); - }); - - it('should send not send floors', function () { - adServerCurrencyStub.returns('EUR'); - const bidRequest = Object.assign({}, - bidRequestsWithMediaTypes[0], - { - getFloor: () => { - return { - currency: 'BTC', - floor: 9.99 - } - } - } - ); - - const request = spec.buildRequests([bidRequest], mockBidderRequest); - expect(request[0].data.imp[0].bidfloor).to.equal(undefined) - expect(request[0].data.imp[0].bidfloorcur).to.equal(undefined) - }); - }) - }) - - describe('FPD', function() { - let bidRequests; - const mockBidderRequest = {refererInfo: {}}; - - beforeEach(function () { - bidRequests = [{ - bidder: 'openx', - params: { - unit: '12345678-banner', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id', - transactionId: 'test-transaction-id-1' - }, { - bidder: 'openx', - mediaTypes: { - video: { - playerSize: [640, 480] - } - }, - params: { - unit: '12345678-video', - delDomain: 'test-del-domain' - }, - 'adUnitCode': 'adunit-code', - - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id', - transactionId: 'test-transaction-id-2' - }]; - }); - - it('ortb2.site should be merged in the request', function() { - const request = spec.buildRequests(bidRequests, { - ...mockBidderRequest, - 'ortb2': { - site: { - domain: 'page.example.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'] - } - } - }); - const data = request[0].data; - expect(data.site.domain).to.equal('page.example.com'); - expect(data.site.cat).to.deep.equal(['IAB2']); - expect(data.site.sectioncat).to.deep.equal(['IAB2-2']); - }); - - it('ortb2.user should be merged in the request', function() { - const request = spec.buildRequests(bidRequests, { - ...mockBidderRequest, - 'ortb2': { - user: { - yob: 1985 - } - } - }); - const data = request[0].data; - expect(data.user.yob).to.equal(1985); - }); - - describe('ortb2Imp', function() { - describe('ortb2Imp.ext.data.pbadslot', function() { - beforeEach(function () { - if (bidRequests[0].hasOwnProperty('ortb2Imp')) { - delete bidRequests[0].ortb2Imp; - } - }); - - it('should not send if imp[].ext.data object is invalid', function() { - bidRequests[0].ortb2Imp = { - ext: {} - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - expect(data.imp[0].ext).to.not.have.property('data'); - }); - - it('should not send if imp[].ext.data.pbadslot is undefined', function() { - bidRequests[0].ortb2Imp = { - ext: { - data: { - } - } - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - if (data.imp[0].ext.data) { - expect(data.imp[0].ext.data).to.not.have.property('pbadslot'); - } else { - expect(data.imp[0].ext).to.not.have.property('data'); - } - }); - - it('should send if imp[].ext.data.pbadslot is string', function() { - bidRequests[0].ortb2Imp = { - ext: { - data: { - pbadslot: 'abcd' - } - } - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - expect(data.imp[0].ext.data).to.have.property('pbadslot'); - expect(data.imp[0].ext.data.pbadslot).to.equal('abcd'); - }); - }); - - describe('ortb2Imp.ext.data.adserver', function() { - beforeEach(function () { - if (bidRequests[0].hasOwnProperty('ortb2Imp')) { - delete bidRequests[0].ortb2Imp; - } - }); - - it('should not send if imp[].ext.data object is invalid', function() { - bidRequests[0].ortb2Imp = { - ext: {} - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - expect(data.imp[0].ext).to.not.have.property('data'); - }); - - it('should not send if imp[].ext.data.adserver is undefined', function() { - bidRequests[0].ortb2Imp = { - ext: { - data: { - } - } - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - if (data.imp[0].ext.data) { - expect(data.imp[0].ext.data).to.not.have.property('adserver'); - } else { - expect(data.imp[0].ext).to.not.have.property('data'); - } - }); - - it('should send', function() { - const adSlotValue = 'abc'; - bidRequests[0].ortb2Imp = { - ext: { - data: { - adserver: { - name: 'GAM', - adslot: adSlotValue - } - } - } - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - expect(data.imp[0].ext.data.adserver.name).to.equal('GAM'); - expect(data.imp[0].ext.data.adserver.adslot).to.equal(adSlotValue); - }); - }); - - describe('ortb2Imp.ext.data.other', function() { - beforeEach(function () { - if (bidRequests[0].hasOwnProperty('ortb2Imp')) { - delete bidRequests[0].ortb2Imp; - } - }); - - it('should not send if imp[].ext.data object is invalid', function() { - bidRequests[0].ortb2Imp = { - ext: {} - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - expect(data.imp[0].ext).to.not.have.property('data'); - }); - - it('should not send if imp[].ext.data.other is undefined', function() { - bidRequests[0].ortb2Imp = { - ext: { - data: { - } - } - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - if (data.imp[0].ext.data) { - expect(data.imp[0].ext.data).to.not.have.property('other'); - } else { - expect(data.imp[0].ext).to.not.have.property('data'); - } - }); - - it('ortb2Imp.ext.data.other', function() { - bidRequests[0].ortb2Imp = { - ext: { - data: { - other: 1234 - } - } - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - expect(data.imp[0].ext.data.other).to.equal(1234); - }); - }); - }); - - describe('with user agent client hints', function () { - it('should add device.sua if available', function () { - const bidderRequestWithUserAgentClientHints = { refererInfo: {}, - ortb2: { - device: { - sua: { - source: 2, - platform: { - brand: 'macOS', - version: [ '12', '4', '0' ] - }, - browsers: [ - { - brand: 'Chromium', - version: [ '106', '0', '5249', '119' ] - }, - { - brand: 'Google Chrome', - version: [ '106', '0', '5249', '119' ] - }, - { - brand: 'Not;A=Brand', - version: [ '99', '0', '0', '0' ] - }], - mobile: 0, - model: 'Pro', - bitness: '64', - architecture: 'x86' - } - } - }}; - - let request = spec.buildRequests(bidRequests, bidderRequestWithUserAgentClientHints); - expect(request[0].data.device.sua).to.exist; - expect(request[0].data.device.sua).to.deep.equal(bidderRequestWithUserAgentClientHints.ortb2.device.sua); - const bidderRequestWithoutUserAgentClientHints = {refererInfo: {}, ortb2: {}}; - request = spec.buildRequests(bidRequests, bidderRequestWithoutUserAgentClientHints); - expect(request[0].data.device?.sua).to.not.exist; - }); - }); - }); - - context('when there is a consent management framework', function () { - let bidRequests; - let mockConfig; - let bidderRequest; - - beforeEach(function () { - bidRequests = [{ - bidder: 'openx', - params: { - unit: '12345678-banner', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id', - transactionId: 'test-transaction-id-1' - }, { - bidder: 'openx', - mediaTypes: { - video: { - playerSize: [640, 480] - } - }, - params: { - unit: '12345678-video', - delDomain: 'test-del-domain' - }, - 'adUnitCode': 'adunit-code', - - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id', - transactionId: 'test-transaction-id-2' - }]; - }); - - describe('us_privacy', function () { - beforeEach(function () { - bidderRequest = { - uspConsent: '1YYN', - refererInfo: {} - }; - - sinon.stub(config, 'getConfig').callsFake((key) => { - return utils.deepAccess(mockConfig, key); - }); - }); - - afterEach(function () { - config.getConfig.restore(); - }); - - it('should send a signal to specify that US Privacy applies to this request', async function () { - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.regs.ext.us_privacy).to.equal('1YYN'); - expect(request[1].data.regs.ext.us_privacy).to.equal('1YYN'); - }); - - it('should not send the regs object, when consent string is undefined', async function () { - delete bidderRequest.uspConsent; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.regs?.us_privacy).to.not.exist; - }); - }); - - describe('GDPR', function () { - beforeEach(function () { - bidderRequest = { - gdprConsent: { - consentString: 'test-gdpr-consent-string', - addtlConsent: 'test-addtl-consent-string', - gdprApplies: true - }, - refererInfo: {} - }; - - mockConfig = { - consentManagement: { - cmpApi: 'iab', - timeout: 1111, - allowAuctionWithoutConsent: 'cancel' - } - }; - - sinon.stub(config, 'getConfig').callsFake((key) => { - return utils.deepAccess(mockConfig, key); - }); - }); - - afterEach(function () { - config.getConfig.restore(); - }); - - it('should send a signal to specify that GDPR applies to this request', async function () { - bidderRequest.bids = bidRequests; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.regs.ext.gdpr).to.equal(1); - expect(request[1].data.regs.ext.gdpr).to.equal(1); - }); - - it('should send the consent string', async function () { - bidderRequest.bids = bidRequests; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString); - expect(request[1].data.user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString); - }); - - it('should send the addtlConsent string', async function () { - bidderRequest.bids = bidRequests; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.user.ext.ConsentedProvidersSettings.consented_providers).to.equal(bidderRequest.gdprConsent.addtlConsent); - expect(request[1].data.user.ext.ConsentedProvidersSettings.consented_providers).to.equal(bidderRequest.gdprConsent.addtlConsent); - }); - - it('should send a signal to specify that GDPR does not apply to this request', async function () { - bidderRequest.gdprConsent.gdprApplies = false; - bidderRequest.bids = bidRequests; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.regs.ext.gdpr).to.equal(0); - expect(request[1].data.regs.ext.gdpr).to.equal(0); - }); - - it('when GDPR application is undefined, should not send a signal to specify whether GDPR applies to this request, ' + - 'but can send consent data, ', async function () { - delete bidderRequest.gdprConsent.gdprApplies; - bidderRequest.bids = bidRequests; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.regs?.ext?.gdpr).to.not.be.ok; - expect(request[0].data.user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString); - expect(request[1].data.user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString); - }); - - it('when consent string is undefined, should not send the consent string, ', async function () { - delete bidderRequest.gdprConsent.consentString; - bidderRequest.bids = bidRequests; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.imp[0].ext.consent).to.equal(undefined); - expect(request[1].data.imp[0].ext.consent).to.equal(undefined); - }); - }); - - describe('GPP', function () { - it('should send GPP string and GPP section IDs in bid request when available', async function () { - bidderRequest.bids = bidRequests; - bidderRequest.ortb2 = { - regs: { - gpp: 'test-gpp-string', - gpp_sid: [6] - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].data.regs.gpp).to.equal('test-gpp-string'); - expect(request[0].data.regs.gpp_sid).to.deep.equal([6]); - expect(request[1].data.regs.gpp).to.equal('test-gpp-string'); - expect(request[1].data.regs.gpp_sid).to.deep.equal([6]); - }); - - it('should not send GPP string and GPP section IDs in bid request when not available', async function () { - bidderRequest.bids = bidRequests; - bidderRequest.ortb2 = { - regs: {} - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].data.regs.gpp).to.not.exist; - expect(request[0].data.regs.gpp_sid).to.not.exist; - expect(request[1].data.regs.gpp).to.not.exist; - expect(request[1].data.regs.gpp_sid).to.not.exist; - }); - }); - }); - - context('coppa', function() { - it('when there are no coppa param settings, should not send a coppa flag', async function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, await addFPDToBidderRequest(mockBidderRequest)); - expect(request[0].data.regs?.coppa).to.be.not.ok; - }); - - it('should send a coppa flag there is when there is coppa param settings in the bid requests', async function () { - const mockConfig = { - coppa: true - }; - - sinon.stub(config, 'getConfig').callsFake((key) => { - return utils.deepAccess(mockConfig, key); - }); - - const request = spec.buildRequests(bidRequestsWithMediaTypes, await addFPDToBidderRequest(mockBidderRequest)); - expect(request[0].data.regs.coppa).to.equal(1); - }); - - it('should send a coppa flag there is when there is coppa param settings in the bid params', async function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, await addFPDToBidderRequest(mockBidderRequest)); - request.params = {coppa: true}; - expect(request[0].data.regs.coppa).to.equal(1); - }); - - after(function () { - config.getConfig.restore() - }); - }); - - context('do not track (DNT)', function() { - let doNotTrackStub; - - beforeEach(function () { - doNotTrackStub = sinon.stub(utils, 'getDNT'); - }); - afterEach(function() { - doNotTrackStub.restore(); - }); - - it('when there is a do not track, should send a dnt', async function () { - doNotTrackStub.returns(1); - - const request = spec.buildRequests(bidRequestsWithMediaTypes, await addFPDToBidderRequest(mockBidderRequest)); - expect(request[0].data.device.dnt).to.equal(1); - }); - - it('when there is not do not track, don\'t send dnt', async function () { - doNotTrackStub.returns(0); - - const request = spec.buildRequests(bidRequestsWithMediaTypes, await addFPDToBidderRequest(mockBidderRequest)); - expect(request[0].data.device.dnt).to.equal(0); - }); - - it('when there is no defined do not track, don\'t send dnt', async function () { - doNotTrackStub.returns(null); - - const request = spec.buildRequests(bidRequestsWithMediaTypes, await addFPDToBidderRequest(mockBidderRequest)); - expect(request[0].data.device.dnt).to.equal(0); - }); - }); - - context('supply chain (schain)', function () { - let bidRequests; - let schainConfig; - const supplyChainNodePropertyOrder = ['asi', 'sid', 'hp', 'rid', 'name', 'domain']; - - beforeEach(function () { - schainConfig = { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'exchange1.com', - sid: '1234', - hp: 1, - rid: 'bid-request-1', - name: 'publisher', - domain: 'publisher.com' - // omitted ext - }, - { - asi: 'exchange2.com', - sid: 'abcd', - hp: 1, - rid: 'bid-request-2', - // name field missing - domain: 'intermediary.com' - }, - { - asi: 'exchange3.com', - sid: '4321', - hp: 1, - // request id - // name field missing - domain: 'intermediary-2.com' - } - ] - }; - - bidRequests = [{ - bidder: 'openx', - params: { - unit: '11', - delDomain: 'test-del-domain' - }, - adUnitCode: '/adunit-code/test-path', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - ortb2: {source: { - schain: schainConfig, - ext: {schain: schainConfig} - }} - }]; - - // Add schain to mockBidderRequest as well - mockBidderRequest.ortb2 = { - source: { - schain: schainConfig, - ext: {schain: schainConfig} - } - }; - }); - - it('should send a supply chain object', function () { - const request = spec.buildRequests(bidRequests, mockBidderRequest); - expect(request[0].data.source.ext.schain).to.deep.equal(schainConfig); - }); - - it('should send the supply chain object with the right version', function () { - const request = spec.buildRequests(bidRequests, mockBidderRequest); - expect(request[0].data.source.ext.schain.ver).to.equal(schainConfig.ver); - }); - - it('should send the supply chain object with the right complete value', function () { - const request = spec.buildRequests(bidRequests, mockBidderRequest); - expect(request[0].data.source.ext.schain.complete).to.equal(schainConfig.complete); - }); - }); - - context('when there are userid providers', function () { - const eids = [ - { - source: 'adserver.org', - uids: [{ - id: 'some-random-id-value', - atype: 1, - ext: { - rtiPartner: 'TDID' - } - }] - }, - { - source: 'id5-sync.com', - uids: [{ - id: 'some-random-id-value', - atype: 1 - }] - }, - { - source: 'sharedid.org', - uids: [{ - id: 'some-random-id-value', - atype: 1, - ext: { - third: 'some-random-id-value' - } - }] - } - ]; - - it(`should send the user id under the extended ids`, function () { - const bidRequests = [{ - bidder: 'openx', - params: { - unit: '11', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - }]; - // enrich bid request with userId key/value - - mockBidderRequest.ortb2 = {user: {ext: {eids}}} - const request = spec.buildRequests(bidRequests, mockBidderRequest); - expect(request[0].data.user.ext.eids).to.eql(eids); - }); - - it(`when no user ids are available, it should not send any extended ids`, function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest); - expect(request[0].data).to.not.have.any.keys('user'); - }); - }); - - context('FLEDGE', function() { - it('when FLEDGE is enabled, should send whatever is set in ortb2imp.ext.ae in all bid requests', function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, { - ...mockBidderRequest, - paapi: { - enabled: true - } - }); - expect(request[0].data.imp[0].ext.ae).to.equal(2); - }); - }); - }); - - context('banner', function () { - it('should send bid request with a mediaTypes specified with banner type', function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest); - expect(request[0].data.imp[0]).to.have.any.keys(BANNER); - }); - }); - - if (FEATURES.VIDEO) { - context('video', function () { - it('should send bid request with a mediaTypes specified with video type', function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest); - expect(request[1].data.imp[0]).to.have.any.keys(VIDEO); - }); - - it('Update imp.video with OpenRTB options from mimeTypes and params', function() { - const bid01 = new BidRequestBuilder({ - adUnitCode: 'adunit-code-01', - mediaTypes: { - banner: { sizes: [[300, 250]] }, - video: { - context: 'outstream', - playerSize: [[300, 250]], - mimes: ['video/mp4'], - protocols: [8] - } - }, - }).withParams({ - // options in video, will merge - video: { - skip: 1, - skipafter: 4, - minduration: 10, - maxduration: 30 - } - }).build(); - - const bidderRequest = new BidderRequestBuilder().build(); - const expected = { - mimes: ['video/mp4'], - skip: 1, - skipafter: 4, - minduration: 10, - maxduration: 30, - protocols: [8], - w: 300, - h: 250 - }; - const requests = spec.buildRequests([bid01], bidderRequest); - expect(requests).to.have.lengthOf(2); - expect(requests[1].data.imp[0].video).to.deep.equal(expected); - }); - }); - } - }); - - describe('interpretResponse()', function () { - let bidRequestConfigs; - let bidRequest; - let bidResponse; - let bid; - - context('when there is an nbr response', function () { - let response; - beforeEach(function () { - bidRequestConfigs = [{ - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = {nbr: 0}; // Unknown error - response = spec.interpretResponse({body: bidResponse}, bidRequest); - }); - - it('should not return any bids', function () { - expect(response.bids.length).to.equal(0); - }); - }); - - context('when no seatbid in response', function () { - let response; - beforeEach(function () { - bidRequestConfigs = [{ - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = {ext: {}, id: 'test-bid-id'}; - response = spec.interpretResponse({body: bidResponse}, bidRequest); - }); - - it('should not return any bids', function () { - expect(response.bids.length).to.equal(0); - }); - }); - - context('when there is no response', function () { - let response; - beforeEach(function () { - bidRequestConfigs = [{ - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = ''; // Unknown error - response = spec.interpretResponse({body: bidResponse}, bidRequest); - }); - - it('should not return any bids', function () { - expect(response.bids.length).to.equal(0); - }); - }); - - const SAMPLE_BID_REQUESTS = [{ - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - const SAMPLE_BID_RESPONSE = { - seatbid: [{ - bid: [{ - impid: 'test-bid-id', - price: 2, - w: 300, - h: 250, - crid: 'test-creative-id', - dealid: 'test-deal-id', - adm: 'test-ad-markup', - mtype: 1, - adomain: ['brand.com'], - ext: { - dsp_id: '123', - buyer_id: '456', - brand_id: '789' - } - }] - }], - cur: 'AUS' - }; - - context('when there is a response, the common response properties', function () { - beforeEach(function () { - bidRequestConfigs = deepClone(SAMPLE_BID_REQUESTS); - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - bidResponse = deepClone(SAMPLE_BID_RESPONSE); - - bid = spec.interpretResponse({body: bidResponse}, bidRequest).bids[0]; - }); - - it('should return a price', function () { - expect(bid.cpm).to.equal(bidResponse.seatbid[0].bid[0].price); - }); - - it('should return a request id', function () { - expect(bid.requestId).to.equal(bidResponse.seatbid[0].bid[0].impid); - }); - - it('should return width and height for the creative', function () { - expect(bid.width).to.equal(bidResponse.seatbid[0].bid[0].w); - expect(bid.height).to.equal(bidResponse.seatbid[0].bid[0].h); - }); - - it('should return a creativeId', function () { - expect(bid.creativeId).to.equal(bidResponse.seatbid[0].bid[0].crid); - }); - - it('should return an ad', function () { - expect(bid.ad).to.equal(bidResponse.seatbid[0].bid[0].adm); - }); - - it('should return a deal id if it exists', function () { - expect(bid.dealId).to.equal(bidResponse.seatbid[0].bid[0].dealid); - }); - - it('should have a time-to-live of 5 minutes', function () { - expect(bid.ttl).to.equal(300); - }); - - it('should always return net revenue', function () { - expect(bid.netRevenue).to.equal(true); - }); - - it('should return a currency', function () { - expect(bid.currency).to.equal(bidResponse.cur); - }); - - it('should return a brand ID', function () { - expect(bid.meta.brandId).to.equal(bidResponse.seatbid[0].bid[0].ext.brand_id); - }); - - it('should return a dsp ID', function () { - expect(bid.meta.networkId).to.equal(bidResponse.seatbid[0].bid[0].ext.dsp_id); - }); - - it('should return a buyer ID', function () { - expect(bid.meta.advertiserId).to.equal(bidResponse.seatbid[0].bid[0].ext.buyer_id); - }); - - it('should return adomain', function () { - expect(bid.meta.advertiserDomains).to.equal(bidResponse.seatbid[0].bid[0].adomain); - }); - }); - - context('when banner request and the response is a banner', function() { - beforeEach(function () { - bidRequestConfigs = [{ - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = { - seatbid: [{ - bid: [{ - impid: 'test-bid-id', - price: 2, - w: 300, - h: 250, - crid: 'test-creative-id', - dealid: 'test-deal-id', - adm: 'test-ad-markup', - mtype: 1, - }] - }], - cur: 'AUS' - }; - - bid = spec.interpretResponse({body: bidResponse}, bidRequest).bids[0]; - }); - - it('should return the proper mediaType', function () { - expect(bid.mediaType).to.equal(Object.keys(bidRequestConfigs[0].mediaTypes)[0]); - }); - }); - - if (FEATURES.VIDEO) { - context('when video request and the response is a video', function() { - beforeEach(function () { - bidRequestConfigs = [{ - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - video: { - playerSize: [[640, 360], [854, 480]], - }, - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = { - seatbid: [{ - bid: [{ - impid: 'test-bid-id', - price: 2, - w: 854, - h: 480, - crid: 'test-creative-id', - dealid: 'test-deal-id', - adm: '', - }] - }], - cur: 'AUS' - }; - }); - - it('should return the proper mediaType', function () { - bid = spec.interpretResponse({body: bidResponse}, bidRequest).bids[0]; - expect(bid.mediaType).to.equal(Object.keys(bidRequestConfigs[0].mediaTypes)[0]); - }); - - it('should return the proper vastUrl', function () { - const winUrl = 'https//my.win.url'; - bidResponse.seatbid[0].bid[0].nurl = winUrl - bid = spec.interpretResponse({body: bidResponse}, bidRequest).bids[0]; - - expect(bid.vastUrl).to.equal(winUrl); - }); - }); - - context('when multi-format request (banner + video) and the response is a video', function() { - beforeEach(function () { - bidRequestConfigs = [{ - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - size: [[300, 600]] - }, - video: { - playerSize: [[640, 360], [854, 480]], - }, - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = { - seatbid: [{ - bid: [{ - impid: 'test-bid-id', - price: 5, - adm: '', - mtype: 2 - }] - }], - cur: 'USD' - }; - }); - - it('should return video mediaType', function () { - bid = spec.interpretResponse({body: bidResponse}, bidRequest).bids[0]; - expect(bid.mediaType).to.equal(VIDEO); - }); - }); - - context('when multiple bid requests (banner + video) and the response is a banner', function() { - beforeEach(function () { - bidRequestConfigs = [{ - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - video: { - playerSize: [[640, 360], [854, 480]], - }, - }, - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bidder-request-id-1', - auctionId: 'test-auction-id-1' - }, - { - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'test-bid-id-2', - bidderRequestId: 'test-bidder-request-id-2', - auctionId: 'test-auction-id-2' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = { - seatbid: [{ - bid: [{ - impid: 'test-bid-id-2', - price: 2, - adm: '', - mtype: 1 - }] - }], - cur: 'USD' - }; - }); - - it('should return banner mediaType', function () { - bid = spec.interpretResponse({body: bidResponse}, bidRequest).bids[0]; - expect(bid.mediaType).to.equal(BANNER); - }); - }); - } - - if (FEATURES.NATIVE) { - context('when native request and the response is a native', function() { - beforeEach(function () { - const nativeOrtbRequest = { - ver: '1.2', - assets: [{ - id: 1, - required: 1, - title: { - len: 80 - } - }] - }; - bidRequestConfigs = [{ - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - native: { - ...nativeOrtbRequest - }, - }, - nativeOrtbRequest, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = { - seatbid: [{ - bid: [{ - impid: 'test-bid-id', - price: 2, - adm: '{"ver": "1.2", "assets": [{"id": 1, "required": 1,"title": {"text": "OpenX (Title)"}}], "link": {"url": "https://www.openx.com/"}, "eventtrackers":[{"event":1,"method":1,"url":"http://example.com/impression"}]}', - mtype: 4 - }] - }], - cur: 'AUS' - }; - }); - - it('should return the proper mediaType', function () { - bid = spec.interpretResponse({body: bidResponse}, bidRequest).bids[0]; - expect(bid.mediaType).to.equal(Object.keys(bidRequestConfigs[0].mediaTypes)[0]); - }); - - it('should return parsed adm JSON in native.ortb response field', function () { - bid = spec.interpretResponse({body: bidResponse}, bidRequest).bids[0]; - - expect(bid.native.ortb).to.deep.equal({ - ver: '1.2', - assets: [{ - id: 1, - required: 1, - title: {text: 'OpenX (Title)'} - }], - link: {url: 'https://www.openx.com/'}, - eventtrackers: [{ - event: 1, - method: 1, - url: 'http://example.com/impression' - }] - }); - }); - }); - - context('when multi-format request (banner + native) and the response is a banner', function() { - beforeEach(function () { - const nativeOrtbRequest = { - ver: '1.2', - assets: [{ - id: 1, - required: 1, - title: { - len: 80 - } - }] - }; - bidRequestConfigs = [{ - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - }, - native: { - ...nativeOrtbRequest - }, - }, - nativeOrtbRequest, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = { - seatbid: [{ - bid: [{ - impid: 'test-bid-id', - price: 2, - adm: '', - mtype: 1 - }] - }], - cur: 'AUS' - }; - }); - - it('should return banner mediaType', function () { - bid = spec.interpretResponse({body: bidResponse}, bidRequest).bids[0]; - expect(bid.mediaType).to.equal(BANNER); - }); - }); - - context('when multiple bid requests (banner + native) and the response is a native', function() { - beforeEach(function () { - const nativeOrtbRequest = { - ver: '1.2', - assets: [{ - id: 1, - required: 1, - title: { - len: 80 - } - }] - }; - bidRequestConfigs = [{ - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - native: { - ...nativeOrtbRequest - }, - }, - nativeOrtbRequest, - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bidder-request-id-1', - auctionId: 'test-auction-id-1' - }, - { - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'test-bid-id-2', - bidderRequestId: 'test-bidder-request-id-2', - auctionId: 'test-auction-id-2' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = { - seatbid: [{ - bid: [{ - impid: 'test-bid-id-1', - price: 2, - adm: '{"ver": "1.2", "assets": [{"id": 1, "required": 1,"title": {"text": "OpenX (Title)"}}], "link": {"url": "https://www.openx.com/"}, "eventtrackers":[{"event":1,"method":1,"url":"http://example.com/impression"}]}', - mtype: 4 - }] - }], - cur: 'USD' - }; - }); - - it('should return native mediaType', function () { - bid = spec.interpretResponse({body: bidResponse}, bidRequest).bids[0]; - expect(bid.mediaType).to.equal(NATIVE); - }); - }); - } - - context('when the response contains FLEDGE interest groups config', function() { - let response; - - beforeEach(function () { - sinon.stub(config, 'getConfig') - .withArgs('fledgeEnabled') - .returns(true); - - bidRequestConfigs = [{ - bidder: 'openx', - params: { - unit: '12345678', - delDomain: 'test-del-domain' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = { - seatbid: [{ - bid: [{ - impid: 'test-bid-id', - price: 2, - w: 300, - h: 250, - crid: 'test-creative-id', - dealid: 'test-deal-id', - adm: 'test-ad-markup' - }] - }], - cur: 'AUS', - ext: { - fledge_auction_configs: { - 'test-bid-id': { - seller: 'codinginadtech.com', - interestGroupBuyers: ['somedomain.com'], - sellerTimeout: 0, - perBuyerSignals: { - 'somedomain.com': { - base_bid_micros: 0.1, - disallowed_advertiser_ids: [ - '1234', - '2345' - ], - multiplier: 1.3, - use_bid_multiplier: true, - win_reporting_id: '1234567asdf' - } - } - } - } - } - }; - - response = spec.interpretResponse({body: bidResponse}, bidRequest); - }); - - afterEach(function () { - config.getConfig.restore(); - }); - - it('should return FLEDGE auction_configs alongside bids', function () { - expect(response).to.have.property('bids'); - expect(response).to.have.property('paapi'); - expect(response.paapi.length).to.equal(1); - expect(response.paapi[0].bidId).to.equal('test-bid-id'); - }); - - it('should inject ortb2Imp in auctionSignals', function () { - const auctionConfig = response.paapi[0].config; - expect(auctionConfig).to.deep.include({ - auctionSignals: { - ortb2Imp: { - id: 'test-bid-id', - tagid: '12345678', - banner: { - topframe: 0, - format: bidRequestConfigs[0].mediaTypes.banner.sizes.map(([w, h]) => ({w, h})) - }, - ext: { - divid: 'adunit-code', - }, - secure: 1 - } - } - }); - }) - }); - }); - - describe('user sync', function () { - it('should register the default image pixel if no pixels available', function () { - const syncs = spec.getUserSyncs( - {pixelEnabled: true}, - [] - ); - expect(syncs).to.deep.equal([{type: 'image', url: DEFAULT_SYNC}]); - }); - - it('should register custom syncUrl when exists', function () { - const syncs = spec.getUserSyncs( - {pixelEnabled: true}, - [{body: {ext: {delDomain: 'www.url.com'}}}] - ); - expect(syncs).to.deep.equal([{type: 'image', url: 'https://www.url.com/w/1.0/pd'}]); - }); - - it('should register custom syncUrl when exists', function () { - const syncs = spec.getUserSyncs( - {pixelEnabled: true}, - [{body: {ext: {platform: 'abc'}}}] - ); - expect(syncs).to.deep.equal([{type: 'image', url: SYNC_URL + '?ph=abc'}]); - }); - - it('when iframe sync is allowed, it should register an iframe sync', function () { - const syncs = spec.getUserSyncs( - {iframeEnabled: true}, - [] - ); - expect(syncs).to.deep.equal([{type: 'iframe', url: DEFAULT_SYNC}]); - }); - - it('should prioritize iframe over image for user sync', function () { - const syncs = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [] - ); - expect(syncs).to.deep.equal([{type: 'iframe', url: DEFAULT_SYNC}]); - }); - - describe('when gdpr applies', function () { - let gdprConsent; - let gdprPixelUrl; - const consentString = 'gdpr-pixel-consent'; - const gdprApplies = '1'; - beforeEach(() => { - gdprConsent = { - consentString, - gdprApplies: true - }; - - gdprPixelUrl = `${SYNC_URL}&gdpr=${gdprApplies}&gdpr_consent=${consentString}`; - }); - - it('when there is a response, it should have the gdpr query params', () => { - const [{url}] = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [], - gdprConsent - ); - - expect(url).to.have.string(`gdpr_consent=${consentString}`); - expect(url).to.have.string(`gdpr=${gdprApplies}`); - }); - - it('should not send signals if no consent object is available', function () { - const [{url}] = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [], - ); - expect(url).to.not.have.string('gdpr_consent='); - expect(url).to.not.have.string('gdpr='); - }); - }); - - describe('when gpp applies', function () { - it('should send GPP query params when GPP consent object available', () => { - const gppConsent = { - gppString: 'gpp-pixel-consent', - applicableSections: [6, 7] - } - const [{url}] = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [], - undefined, - undefined, - gppConsent - ); - - expect(url).to.have.string(`gpp=gpp-pixel-consent`); - expect(url).to.have.string(`gpp_sid=6,7`); - }); - - it('should send GDPR and GPP query params when both consent objects available', () => { - const gdprConsent = { - consentString: 'gdpr-pixel-consent', - gdprApplies: true - } - const gppConsent = { - gppString: 'gpp-pixel-consent', - applicableSections: [6, 7] - } - const [{url}] = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [], - gdprConsent, - undefined, - gppConsent - ); - - expect(url).to.have.string(`gdpr_consent=gdpr-pixel-consent`); - expect(url).to.have.string(`gdpr=1`); - expect(url).to.have.string(`gpp=gpp-pixel-consent`); - expect(url).to.have.string(`gpp_sid=6,7`); - }); - - it('should not send GPP query params when GPP string not available', function () { - const gppConsent = { - applicableSections: [6, 7] - } - const [{url}] = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [], - undefined, - undefined, - gppConsent - ); - - expect(url).to.not.have.string('gpp='); - expect(url).to.not.have.string('gpp_sid='); - }); - - it('should not send GPP query params when GPP section IDs not available', function () { - const gppConsent = { - gppString: 'gpp-pixel-consent', - } - const [{url}] = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [], - undefined, - undefined, - gppConsent - ); - - expect(url).to.not.have.string('gpp='); - expect(url).to.not.have.string('gpp_sid='); - }); - - it('should not send GPP query params when GPP section IDs empty', function () { - const gppConsent = { - gppString: 'gpp-pixel-consent', - applicableSections: [] - } - const [{url}] = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [], - undefined, - undefined, - gppConsent - ); - - expect(url).to.not.have.string('gpp='); - expect(url).to.not.have.string('gpp_sid='); - }); - - it('should not send GPP query params when GPP consent object not available', function () { - const [{url}] = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [], undefined, undefined, undefined - ); - expect(url).to.not.have.string('gpp='); - expect(url).to.not.have.string('gpp_sid='); - }); - }); - - describe('when ccpa applies', function () { - let usPrivacyConsent; - let uspPixelUrl; - const privacyString = 'TEST'; - beforeEach(() => { - usPrivacyConsent = 'TEST'; - uspPixelUrl = `${DEFAULT_SYNC}&us_privacy=${privacyString}` - }); - it('should send the us privacy string, ', () => { - const [{url}] = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [], - undefined, - usPrivacyConsent - ); - expect(url).to.have.string(`us_privacy=${privacyString}`); - }); - - it('should not send signals if no consent string is available', function () { - const [{url}] = spec.getUserSyncs( - {iframeEnabled: true, pixelEnabled: true}, - [], - ); - expect(url).to.not.have.string('us_privacy='); - }); - }); - }); -}); diff --git a/test/spec/modules/operaadsBidAdapter_spec.js b/test/spec/modules/operaadsBidAdapter_spec.js deleted file mode 100644 index 15708c1bb..000000000 --- a/test/spec/modules/operaadsBidAdapter_spec.js +++ /dev/null @@ -1,826 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/operaadsBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import {BANNER, NATIVE, VIDEO} from 'src/mediaTypes.js'; - -describe('Opera Ads Bid Adapter', function () { - describe('Test isBidRequestValid', function () { - it('undefined bid should return false', function () { - expect(spec.isBidRequestValid()).to.be.false; - }); - - it('null bid should return false', function () { - expect(spec.isBidRequestValid(null)).to.be.false; - }); - - it('bid.params should be set', function () { - expect(spec.isBidRequestValid({})).to.be.false; - }); - - it('bid.params.placementId should be set', function () { - expect(spec.isBidRequestValid({ - params: { endpointId: 'ep12345678', publisherId: 'pub12345678' } - })).to.be.false; - }); - - it('bid.params.publisherId should be set', function () { - expect(spec.isBidRequestValid({ - params: { placementId: 's12345678', endpointId: 'ep12345678' } - })).to.be.false; - }); - - it('bid.params.endpointId should be set', function () { - expect(spec.isBidRequestValid({ - params: { placementId: 's12345678', publisherId: 'pub12345678' } - })).to.be.false; - }); - - it('valid bid should return true', function () { - expect(spec.isBidRequestValid({ - params: { placementId: 's12345678', endpointId: 'ep12345678', publisherId: 'pub12345678' } - })).to.be.true; - }); - }); - - describe('Test buildRequests', function () { - const bidderRequest = { - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - auctionStart: Date.now(), - bidderCode: 'myBidderCode', - bidderRequestId: '15246a574e859f', - refererInfo: { - page: 'http://example.com', - stack: ['http://example.com'] - }, - gdprConsent: { - gdprApplies: true, - consentString: 'IwuyYwpjmnsauyYasIUWwe' - }, - uspConsent: 'Oush3@jmUw82has', - timeout: 3000 - }; - - it('build request object', function () { - const bidRequests = [ - { - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f461', - bidder: 'operaads', - bidderRequestId: '15246a574e859f', - mediaTypes: { - banner: { sizes: [[300, 250]] } - }, - params: { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678' - } - }, - { - adUnitCode: 'test-native', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f4622', - bidder: 'operaads', - bidderRequestId: '15246a574e859f', - mediaTypes: { - native: { - title: { - required: true, - len: 20, - }, - image: { - required: true, - sizes: [300, 250], - aspect_ratios: [{ - ratio_width: 1, - ratio_height: 1 - }] - }, - icon: { - required: true, - sizes: [60, 60], - aspect_ratios: [{ - ratio_width: 1, - ratio_height: 1 - }] - }, - sponsoredBy: { - required: true, - len: 20 - }, - body: { - required: true, - len: 140 - }, - cta: { - required: true, - len: 20, - } - } - }, - params: { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678' - } - }, - { - adUnitCode: 'test-native2', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f4632', - bidder: 'operaads', - bidderRequestId: '15246a574e859f', - mediaTypes: { - native: { - title: {}, - image: {}, - icon: {}, - sponsoredBy: {}, - body: {}, - cta: {} - } - }, - params: { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678' - } - }, - { - adUnitCode: 'test-native3', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f4633', - bidder: 'operaads', - bidderRequestId: '15246a574e859f', - mediaTypes: { - native: {}, - }, - params: { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678' - } - }, - { - adUnitCode: 'test-video', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f4623', - bidder: 'operaads', - bidderRequestId: '15246a574e859f', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[640, 480]], - mimes: ['video/mp4'], - protocols: [2, 3, 5, 6], - startdelay: 0, - skip: 1, - playbackmethod: [1, 2, 3, 4], - delivery: [1], - api: [1, 2, 5], - } - }, - params: { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678' - } - }, - { - adUnitCode: 'test-video', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f4643', - bidder: 'operaads', - bidderRequestId: '15246a574e859f', - mediaTypes: { - video: {} - }, - params: { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678' - } - } - ]; - - let reqs; - - expect(function () { - reqs = spec.buildRequests(bidRequests, bidderRequest); - }).to.not.throw(); - - expect(reqs).to.be.an('array').that.have.lengthOf(bidRequests.length); - - for (let i = 0, len = reqs.length; i < len; i++) { - const req = reqs[i]; - const bidRequest = bidRequests[i]; - - expect(req.method).to.equal('POST'); - expect(req.url).to.equal('https://s.adx.opera.com/ortb/v2/' + - bidRequest.params.publisherId + '?ep=' + bidRequest.params.endpointId); - - expect(req.options).to.be.an('object'); - expect(req.options.contentType).to.contain('application/json'); - expect(req.options.customHeaders).to.be.an('object'); - expect(req.options.customHeaders['x-openrtb-version']).to.equal(2.5); - - expect(req.originalBidRequest).to.equal(bidRequest); - - expect(req.data).to.be.a('string'); - - let requestData; - expect(function () { - requestData = JSON.parse(req.data); - }).to.not.throw(); - - expect(requestData.id).to.exist; - expect(requestData.tmax).to.equal(bidderRequest.timeout); - expect(requestData.test).to.equal(0); - expect(requestData.imp).to.be.an('array').that.have.lengthOf(1); - expect(requestData.device).to.be.an('object'); - expect(requestData.site).to.be.an('object'); - expect(requestData.site.id).to.equal(bidRequest.params.publisherId); - expect(requestData.site.domain).to.not.be.empty; - expect(requestData.site.page).to.equal(bidderRequest.refererInfo.page); - expect(requestData.at).to.equal(1); - expect(requestData.bcat).to.be.an('array').that.is.empty; - expect(requestData.cur).to.be.an('array').that.not.be.empty; - expect(requestData.user).to.be.an('object'); - - const impItem = requestData.imp[0]; - expect(impItem).to.be.an('object'); - expect(impItem.id).to.equal(bidRequest.bidId); - expect(impItem.tagid).to.equal(bidRequest.params.placementId); - expect(impItem.bidfloor).to.be.a('number'); - - if (bidRequest.mediaTypes.banner) { - expect(impItem.banner).to.be.an('object'); - } else if (bidRequest.mediaTypes.native) { - expect(impItem.native).to.be.an('object'); - } else if (bidRequest.mediaTypes.video) { - expect(impItem.video).to.be.an('object'); - } else { - expect.fail('should not happen'); - } - } - }); - - describe('test fulfilling inventory information', function () { - const bidRequest = { - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f461', - bidder: 'operaads', - bidderRequestId: '15246a574e859f', - mediaTypes: { - banner: {sizes: [[300, 250]]} - }, - params: { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678' - } - } - - const getRequest = function () { - let reqs; - expect(function () { - reqs = spec.buildRequests([bidRequest], bidderRequest); - }).to.not.throw(); - return JSON.parse(reqs[0].data); - } - - it('test default case', function () { - const requestData = getRequest(); - expect(requestData.site).to.be.an('object'); - expect(requestData.site.id).to.equal(bidRequest.params.publisherId); - expect(requestData.site.domain).to.not.be.empty; - expect(requestData.site.page).to.equal(bidderRequest.refererInfo.page); - }); - - it('test a case with site information specified', function () { - bidRequest.params = { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678', - site: { - name: 'test-site-1', - domain: 'www.test.com' - } - } - const requestData = getRequest(); - expect(requestData.site).to.be.an('object'); - expect(requestData.site.id).to.equal(bidRequest.params.publisherId); - expect(requestData.site.name).to.equal('test-site-1'); - expect(requestData.site.domain).to.equal('www.test.com'); - expect(requestData.site.page).to.equal(bidderRequest.refererInfo.page); - }); - - it('test a case with app information specified', function () { - bidRequest.params = { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678', - app: { - name: 'test-app-1' - } - } - const requestData = getRequest(); - expect(requestData.app).to.be.an('object'); - expect(requestData.app.id).to.equal(bidRequest.params.publisherId); - expect(requestData.app.name).to.equal('test-app-1'); - expect(requestData.app.domain).to.not.be.empty; - }); - - it('test a case with both site and app information specified', function () { - bidRequest.params = { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678', - site: { - name: 'test-site-2', - page: 'test-page' - }, - app: { - name: 'test-app-1' - } - } - const requestData = getRequest(); - expect(requestData.site).to.be.an('object'); - expect(requestData.site.id).to.equal(bidRequest.params.publisherId); - expect(requestData.site.name).to.equal('test-site-2'); - expect(requestData.site.page).to.equal('test-page'); - expect(requestData.site.domain).to.not.be.empty; - }); - }); - - it('test getBidFloor', function() { - const bidRequests = [ - { - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f461', - mediaTypes: { banner: { sizes: [[300, 250]] } }, - params: { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678' - }, - getFloor: function() { - return { - currency: 'USD', - floor: 0.1 - } - } - } - ]; - - const reqs = spec.buildRequests(bidRequests, bidderRequest); - - expect(reqs).to.be.an('array').that.have.lengthOf(1); - - for (const req of reqs) { - let requestData; - expect(function () { - requestData = JSON.parse(req.data); - }).to.not.throw(); - - expect(requestData.imp).to.be.an('array').that.have.lengthOf(1); - expect(requestData.imp[0].bidfloor).to.be.equal(0.1); - expect(requestData.imp[0].bidfloorcur).to.be.equal('USD'); - } - }); - - it('bcat in params should be used', function () { - const bidRequests = [ - { - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f461', - mediaTypes: { banner: { sizes: [[300, 250]] } }, - params: { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678', - bcat: ['IAB1-1'] - } - } - ]; - - const reqs = spec.buildRequests(bidRequests, bidderRequest); - - expect(reqs).to.be.an('array').that.have.lengthOf(1); - - for (const req of reqs) { - let requestData; - expect(function () { - requestData = JSON.parse(req.data); - }).to.not.throw(); - - expect(requestData.bcat).to.be.an('array').that.includes('IAB1-1'); - } - }); - - it('sharedid should be used', function () { - const bidRequests = [{ - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f461', - bidder: 'operaads', - bidderRequestId: '15246a574e859f', - mediaTypes: { - banner: { sizes: [[300, 250]] } - }, - params: { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678' - }, - userId: { - sharedid: { - id: '01F5DEQW731Q2VKT031KBKMW5W' - } - }, - userIdAsEids: [{ - source: 'pubcid.org', - uids: [{ - atype: 1, - id: '01F5DEQW731Q2VKT031KBKMW5W' - }] - }] - }]; - - const reqs = spec.buildRequests(bidRequests, bidderRequest); - - let requestData; - expect(function () { - requestData = JSON.parse(reqs[0].data); - }).to.not.throw(); - - expect(requestData.user.buyeruid).to.equal(bidRequests[0].userId.sharedid.id); - }); - - it('pubcid should be used when sharedid is empty', function () { - const bidRequests = [{ - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f461', - bidder: 'operaads', - bidderRequestId: '15246a574e859f', - mediaTypes: { - banner: { sizes: [[300, 250]] } - }, - params: { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678' - }, - userId: { - 'pubcid': '21F5DEQW731Q2VKT031KBKMW5W' - }, - userIdAsEids: [{ - source: 'pubcid.org', - uids: [{ - atype: 1, - id: '21F5DEQW731Q2VKT031KBKMW5W' - }] - }] - }]; - - const reqs = spec.buildRequests(bidRequests, bidderRequest); - - let requestData; - expect(function () { - requestData = JSON.parse(reqs[0].data); - }).to.not.throw(); - - expect(requestData.user.buyeruid).to.equal(bidRequests[0].userId.pubcid); - }); - - it('random uid will be generate when userId is empty', function () { - const bidRequests = [{ - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f461', - bidder: 'operaads', - bidderRequestId: '15246a574e859f', - mediaTypes: { - banner: { sizes: [[300, 250]] } - }, - params: { - placementId: 's12345678', - publisherId: 'pub12345678', - endpointId: 'ep12345678' - } - }]; - - const reqs = spec.buildRequests(bidRequests, bidderRequest); - - let requestData; - expect(function () { - requestData = JSON.parse(reqs[0].data); - }).to.not.throw(); - - expect(requestData.user.buyeruid).to.not.be.empty; - }) - }); - - describe('Test adapter request', function () { - const adapter = newBidder(spec); - - it('adapter.callBids exists and is a function', function () { - expect(adapter.callBids).to.be.a('function'); - }); - }); - - describe('Test response interpretResponse', function () { - it('Test banner interpretResponse', function () { - const serverResponse = { - body: { - 'id': 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - 'seatbid': [ - { - 'bid': [ - { - 'id': '003004d9c05c6bc7fec0', - 'impid': '22c4871113f461', - 'price': 1.04, - 'nurl': 'https://s.adx.opera.com/win', - 'lurl': 'https://s.adx.opera.com/loss', - 'adm': '', - 'adomain': [ - 'opera.com', - ], - 'cid': '0.49379027', - 'crid': '0.49379027', - 'cat': [ - 'IAB9-31', - 'IAB8' - ], - 'language': 'EN', - 'h': 300, - 'w': 250, - 'exp': 500, - 'ext': {} - } - ], - 'seat': 'adv4199760017536' - } - ], - 'bidid': '003004d9c05c6bc7fec0', - 'cur': 'USD' - } - }; - - const bidResponses = spec.interpretResponse(serverResponse, { - originalBidRequest: { - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f461', - bidder: 'operaads', - bidderRequestId: '15246a574e859f', - mediaTypes: { banner: { sizes: [[300, 250]] } }, - params: { - placementId: 's12345678', - publisherId: 'pub123456', - endpointId: 'ep1234566' - }, - src: 'client', - transactionId: '4781e6ac-93c4-42ba-86fe-ab5f278863cf' - } - }); - - expect(bidResponses).to.be.an('array').that.is.not.empty; - - const bid = serverResponse.body.seatbid[0].bid[0]; - const bidResponse = bidResponses[0]; - - expect(bidResponse.mediaType).to.equal(BANNER); - expect(bidResponse.requestId).to.equal(bid.impid); - expect(bidResponse.cpm).to.equal(parseFloat(bid.price).toFixed(2)) - expect(bidResponse.currency).to.equal(serverResponse.body.cur); - expect(bidResponse.creativeId).to.equal(bid.crid || bid.id); - expect(bidResponse.netRevenue).to.be.true; - expect(bidResponse.nurl).to.equal(bid.nurl); - expect(bidResponse.lurl).to.equal(bid.lurl); - - expect(bidResponse.meta).to.be.an('object'); - expect(bidResponse.meta.mediaType).to.equal(BANNER); - expect(bidResponse.meta.primaryCatId).to.equal('IAB9-31'); - expect(bidResponse.meta.secondaryCatIds).to.deep.equal(['IAB8']); - expect(bidResponse.meta.advertiserDomains).to.deep.equal(bid.adomain); - expect(bidResponse.meta.clickUrl).to.equal(bid.adomain[0]); - - expect(bidResponse.ad).to.equal(bid.adm); - expect(bidResponse.width).to.equal(bid.w); - expect(bidResponse.height).to.equal(bid.h); - }); - - it('Test video interpretResponse', function () { - const serverResponse = { - body: { - 'id': 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - 'seatbid': [ - { - 'bid': [ - { - 'id': '003004d9c05c6bc7fec0', - 'impid': '22c4871113f461', - 'price': 1.04, - 'nurl': 'https://s.adx.opera.com/win', - 'lurl': 'https://s.adx.opera.com/loss', - 'adm': 'Static VAST TemplateStatic VAST Taghttp://example.com/pixel.gif?asi=[ADSERVINGID]00:00:08http://example.com/pixel.gifhttp://example.com/pixel.gifhttp://example.com/pixel.gifhttp://example.com/pixel.gifhttp://example.com/pixel.gifhttp://example.com/pixel.gifhttp://example.com/pixel.gifhttp://example.com/pixel.gifhttp://www.jwplayer.com/http://example.com/pixel.gif?r=[REGULATIONS]&gdpr=[GDPRCONSENT]&pu=[PAGEURL]&da=[DEVICEUA] http://example.com/uploads/myPrerollVideo.mp4 https://example.com/adchoices-sm.pnghttps://sample-url.com', - 'adomain': [ - 'opera.com', - ], - 'cid': '0.49379027', - 'crid': '0.49379027', - 'cat': [ - 'IAB9-31', - 'IAB8' - ], - 'language': 'EN', - 'h': 300, - 'w': 250, - 'exp': 500, - 'ext': {} - } - ], - 'seat': 'adv4199760017536' - } - ], - 'bidid': '003004d9c05c6bc7fec0', - 'cur': 'USD' - } - }; - - const bidResponses = spec.interpretResponse(serverResponse, { - originalBidRequest: { - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f461', - bidder: 'operaads', - bidderRequestId: '15246a574e859f', - mediaTypes: { video: { context: 'outstream' } }, - params: { - placementId: 's12345678', - publisherId: 'pub123456', - endpointId: 'ep1234566' - }, - src: 'client', - transactionId: '4781e6ac-93c4-42ba-86fe-ab5f278863cf' - } - }); - - expect(bidResponses).to.be.an('array').that.is.not.empty; - - const bid = serverResponse.body.seatbid[0].bid[0]; - const bidResponse = bidResponses[0]; - - expect(bidResponse.mediaType).to.equal(VIDEO); - expect(bidResponse.vastXml).to.equal(bid.adm); - expect(bidResponse.width).to.equal(bid.w); - expect(bidResponse.height).to.equal(bid.h); - - expect(bidResponse.adResponse).to.be.an('object'); - expect(bidResponse.renderer).to.be.an('object'); - }); - - it('Test native interpretResponse', function () { - const serverResponse = { - body: { - 'id': 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - 'seatbid': [ - { - 'bid': [ - { - 'id': '003004d9c05c6bc7fec0', - 'impid': '22c4871113f461', - 'price': 1.04, - 'nurl': 'https://s.adx.opera.com/win', - 'lurl': 'https://s.adx.opera.com/loss', - 'adm': '{"native":{"ver":"1.1","assets":[{"id":1,"required":1,"title":{"text":"The first personal browser"}},{"id":2,"required":1,"img":{"url":"https://res.adx.opera.com/xxx.png","w":720,"h":1280}},{"id":3,"required":1,"img":{"url":"https://res.adx.opera.com/xxx.png","w":60,"h":60}},{"id":4,"required":1,"data":{"value":"Download Opera","len":14}},{"id":5,"required":1,"data":{"value":"Opera","len":5}},{"id":6,"required":1,"data":{"value":"Download","len":8}}],"link":{"url":"https://www.opera.com/mobile/opera","clicktrackers":["https://thirdpart-click.tracker.com","https://t-odx.op-mobile.opera.com/click"]},"imptrackers":["https://thirdpart-imp.tracker.com","https://t-odx.op-mobile.opera.com/impr"],"jstracker":""}}', - 'adomain': [ - 'opera.com', - ], - 'cid': '0.49379027', - 'crid': '0.49379027', - 'cat': [ - 'IAB9-31', - 'IAB8' - ], - 'language': 'EN', - 'h': 300, - 'w': 250, - 'exp': 500, - 'ext': {} - } - ], - 'seat': 'adv4199760017536' - } - ], - 'bidid': '003004d9c05c6bc7fec0', - 'cur': 'USD' - } - }; - - const bidResponses = spec.interpretResponse(serverResponse, { - originalBidRequest: { - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f461', - bidder: 'operaads', - bidderRequestId: '15246a574e859f', - mediaTypes: { native: { } }, - params: { - placementId: 's12345678', - publisherId: 'pub123456', - endpointId: 'ep1234566' - }, - src: 'client', - transactionId: '4781e6ac-93c4-42ba-86fe-ab5f278863cf' - } - }); - - expect(bidResponses).to.be.an('array').that.is.not.empty; - - const bidResponse = bidResponses[0]; - - expect(bidResponse.mediaType).to.equal(NATIVE) - expect(bidResponse.native).to.be.an('object'); - expect(bidResponse.native.clickUrl).is.not.empty; - expect(bidResponse.native.clickTrackers).to.have.lengthOf(2); - expect(bidResponse.native.impressionTrackers).to.have.lengthOf(2); - expect(bidResponse.native.javascriptTrackers).to.have.lengthOf(1); - }); - - it('Test empty server response', function () { - const bidResponses = spec.interpretResponse({}, {}); - - expect(bidResponses).to.be.an('array').that.is.empty; - }); - - it('Test empty bid response', function () { - const bidResponses = spec.interpretResponse({ body: { seatbid: null } }, {}); - - expect(bidResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('Test getUserSyncs with both iframe and pixel disabled', function () { - it('getUserSyncs should return an empty array', function () { - const syncOptions = {}; - expect(spec.getUserSyncs(syncOptions)).to.be.an('array').that.is.empty; - }); - }); - - describe('Test getUserSyncs with iframe enabled', function () { - it('getUserSyncs should return array', function () { - const syncOptions = { - iframeEnabled: true - } - const userSyncPixels = spec.getUserSyncs(syncOptions) - expect(userSyncPixels).to.have.lengthOf(1); - expect(userSyncPixels[0].url).to.equal('https://s.adx.opera.com/usersync/page') - }); - }); - - describe('Test getUserSyncs with pixel enabled', function () { - it('getUserSyncs should return array', function () { - const serverResponse = { - body: { - 'pixels': [ - 'https://b1.com/usersync', - 'https://b2.com/usersync' - ] - } - }; - const syncOptions = { - pixelEnabled: true - } - const userSyncPixels = spec.getUserSyncs(syncOptions, [serverResponse]) - expect(userSyncPixels).to.have.lengthOf(2); - expect(userSyncPixels[0].url).to.equal('https://b1.com/usersync') - expect(userSyncPixels[1].url).to.equal('https://b2.com/usersync') - }); - }); - - describe('Test onTimeout', function () { - it('onTimeout should not throw', function () { - expect(spec.onTimeout()).to.not.throw; - }); - }); - - describe('Test onBidWon', function () { - it('onBidWon should not throw', function () { - expect(spec.onBidWon({nurl: '#', originalCpm: '1.04', currency: 'USD'})).to.not.throw; - }); - }); - - describe('Test onSetTargeting', function () { - it('onSetTargeting should not throw', function () { - expect(spec.onSetTargeting()).to.not.throw; - }); - }); -}); diff --git a/test/spec/modules/oprxBidAdapter_spec.js b/test/spec/modules/oprxBidAdapter_spec.js deleted file mode 100644 index 33d54307b..000000000 --- a/test/spec/modules/oprxBidAdapter_spec.js +++ /dev/null @@ -1,99 +0,0 @@ -import { expect } from 'chai'; -import { spec, __setTestConverter } from 'modules/oprxBidAdapter.js'; - -describe('oprxBidAdapter', function () { - const bid = { - bidder: 'oprx', - bidId: 'bid123', - auctionId: 'auction123', - adUnitCode: 'div-id', - transactionId: 'txn123', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: { - key: 'abc', - placement_id: '123456', - npi: '9999999999', - bid_floor: 1.25 - } - }; - - const bidderRequest = { - auctionId: 'auction123', - bidderCode: 'oprx', - refererInfo: { referer: 'https://example.com' } - }; - - // SETUP: Replace real converter with mock - before(() => { - __setTestConverter({ - toORTB: ({ bidRequests }) => ({ - id: 'test-request', - imp: bidRequests.map(bid => ({ - id: bid.bidId, - banner: { format: [{ w: 300, h: 250 }] }, - bidfloor: bid.params.bid_floor || 0 - })), - cur: ['USD'], - site: { page: 'https://example.com' } - }), - fromORTB: ({ response }) => ({ - bids: response.seatbid?.[0]?.bid?.map(b => ({ - requestId: b.impid, - cpm: b.price, - ad: b.adm, - width: b.w, - height: b.h, - currency: 'USD', - creativeId: b.crid, - netRevenue: true, - ttl: 50 - })) || [] - }) - }); - }); - - describe('buildRequests', () => { - it('should build a valid request object', () => { - const request = spec.buildRequests([bid], bidderRequest)[0]; - expect(request.method).to.equal('POST'); - expect(request.data).to.be.an('object'); - }); - }); - - describe('interpretResponse', () => { - let request; - - beforeEach(() => { - request = spec.buildRequests([bid], bidderRequest)[0]; - }); - - it('should return a valid bid response', () => { - const serverResponse = { - body: { - id: 'resp123', - cur: 'USD', - seatbid: [{ - bid: [{ - impid: 'bid123', - price: 2.5, - adm: '
Ad
', - crid: 'creative-789', - w: 300, - h: 250 - }] - }] - } - }; - - const bids = spec.interpretResponse(serverResponse, request); - expect(bids).to.be.an('array').with.lengthOf(1); - const b = bids[0]; - expect(b.cpm).to.equal(2.5); - expect(b.ad).to.include('Ad'); - }); - }); -}); diff --git a/test/spec/modules/opscoBidAdapter_spec.js b/test/spec/modules/opscoBidAdapter_spec.js deleted file mode 100644 index 77051f56d..000000000 --- a/test/spec/modules/opscoBidAdapter_spec.js +++ /dev/null @@ -1,263 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/opscoBidAdapter'; -import {newBidder} from 'src/adapters/bidderFactory.js'; - -describe('opscoBidAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function') - }) - }) - - describe('isBidRequestValid', function () { - const validBid = { - bidder: 'opsco', - params: { - placementId: '123', - publisherId: '456' - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - }; - - it('should return true when required params are present', function () { - expect(spec.isBidRequestValid(validBid)).to.be.true; - }); - - it('should return false when placementId is missing', function () { - const invalidBid = {...validBid}; - delete invalidBid.params.placementId; - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - - it('should return false when publisherId is missing', function () { - const invalidBid = {...validBid}; - delete invalidBid.params.publisherId; - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - - it('should return false when mediaTypes.banner.sizes is missing', function () { - const invalidBid = {...validBid}; - delete invalidBid.mediaTypes.banner.sizes; - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - - it('should return false when mediaTypes.banner is missing', function () { - const invalidBid = {...validBid}; - delete invalidBid.mediaTypes.banner; - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - - it('should return false when bid params are missing', function () { - const invalidBid = {bidder: 'opsco'}; - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - - it('should return false when bid params are empty', function () { - const invalidBid = {bidder: 'opsco', params: {}}; - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let validBid, bidderRequest; - - beforeEach(function () { - validBid = { - bidder: 'opsco', - params: { - placementId: '123', - publisherId: '456' - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - }; - - bidderRequest = { - bidderRequestId: 'bid123', - refererInfo: { - domain: 'example.com', - page: 'https://example.com/page', - ref: 'https://referrer.com' - }, - gdprConsent: { - consentString: 'GDPR_CONSENT_STRING', - gdprApplies: true - }, - }; - }); - - it('should return true when banner sizes are defined', function () { - expect(spec.isBidRequestValid(validBid)).to.be.true; - }); - - it('should return false when banner sizes are invalid', function () { - const invalidSizes = [ - '2:1', - undefined, - 123, - 'undefined' - ]; - - invalidSizes.forEach((sizes) => { - validBid.mediaTypes.banner.sizes = sizes; - expect(spec.isBidRequestValid(validBid)).to.be.false; - }); - }); - - it('should send GDPR consent in the payload if present', function () { - const request = spec.buildRequests([validBid], bidderRequest); - expect(JSON.parse(request.data).user.ext.consent).to.deep.equal('GDPR_CONSENT_STRING'); - }); - - it('should send CCPA in the payload if present', function () { - const ccpa = '1YYY'; - bidderRequest.uspConsent = ccpa; - const request = spec.buildRequests([validBid], bidderRequest); - expect(JSON.parse(request.data).regs.ext.us_privacy).to.equal(ccpa); - }); - - it('should send eids in the payload if present', function () { - const eids = {data: [{source: 'test', uids: [{id: '123', ext: {}}]}]}; - validBid.userIdAsEids = eids; - const request = spec.buildRequests([validBid], bidderRequest); - expect(JSON.parse(request.data).user.ext.eids).to.deep.equal(eids); - }); - - it('should send schain in the payload if present', function () { - const schain = {'ver': '1.0', 'complete': 1, 'nodes': [{'asi': 'exchange1.com', 'sid': '1234', 'hp': 1}]}; - validBid.ortb2 = validBid.ortb2 || {}; - validBid.ortb2.source = validBid.ortb2.source || {}; - validBid.ortb2.source.ext = validBid.ortb2.source.ext || {}; - validBid.ortb2.source.ext.schain = schain; - const request = spec.buildRequests([validBid], bidderRequest); - expect(JSON.parse(request.data).source.ext.schain).to.deep.equal(schain); - }); - - it('should correctly identify test mode', function () { - validBid.params.test = true; - const request = spec.buildRequests([validBid], bidderRequest); - expect(JSON.parse(request.data).test).to.equal(1); - }); - }); - - describe('interpretResponse', function () { - const validResponse = { - body: { - seatbid: [ - { - bid: [ - { - impid: 'bid1', - price: 1.5, - w: 300, - h: 250, - crid: 'creative1', - currency: 'USD', - netRevenue: true, - ttl: 300, - adm: '
Ad content
', - mtype: 1 - }, - { - impid: 'bid2', - price: 2.0, - w: 728, - h: 90, - crid: 'creative2', - currency: 'USD', - netRevenue: true, - ttl: 300, - adm: '
Ad content
', - mtype: 1 - } - ] - } - ] - } - }; - - const emptyResponse = { - body: { - seatbid: [] - } - }; - - it('should return an array of bid objects with valid response', function () { - const interpretedBids = spec.interpretResponse(validResponse); - const expectedBids = validResponse.body.seatbid[0].bid; - expect(interpretedBids).to.have.lengthOf(expectedBids.length); - expectedBids.forEach((expectedBid, index) => { - expect(interpretedBids[index]).to.have.property('requestId', expectedBid.impid); - expect(interpretedBids[index]).to.have.property('cpm', expectedBid.price); - expect(interpretedBids[index]).to.have.property('width', expectedBid.w); - expect(interpretedBids[index]).to.have.property('height', expectedBid.h); - expect(interpretedBids[index]).to.have.property('creativeId', expectedBid.crid); - expect(interpretedBids[index]).to.have.property('currency', expectedBid.currency); - expect(interpretedBids[index]).to.have.property('netRevenue', expectedBid.netRevenue); - expect(interpretedBids[index]).to.have.property('ttl', expectedBid.ttl); - expect(interpretedBids[index]).to.have.property('ad', expectedBid.adm); - expect(interpretedBids[index]).to.have.property('mediaType', expectedBid.mtype); - }); - }); - - it('should return an empty array with empty response', function () { - const interpretedBids = spec.interpretResponse(emptyResponse); - expect(interpretedBids).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function () { - const RESPONSE = { - body: { - ext: { - usersync: { - sovrn: { - syncs: [{type: 'iframe', url: 'https://sovrn.com/iframe_sync'}] - }, - appnexus: { - syncs: [{type: 'image', url: 'https://appnexus.com/image_sync'}] - } - } - } - } - }; - - it('should return empty array if no options are provided', function () { - const opts = spec.getUserSyncs({}); - expect(opts).to.be.an('array').that.is.empty; - }); - - it('should return empty array if neither iframe nor pixel is enabled', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: false}); - expect(opts).to.be.an('array').that.is.empty; - }); - - it('should return syncs only for iframe sync type', function () { - const opts = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: false}, [RESPONSE]); - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('iframe'); - expect(opts[0].url).to.equal(RESPONSE.body.ext.usersync.sovrn.syncs[0].url); - }); - - it('should return syncs only for pixel sync types', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [RESPONSE]); - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('image'); - expect(opts[0].url).to.equal(RESPONSE.body.ext.usersync.appnexus.syncs[0].url); - }); - - it('should return syncs when both iframe and pixel are enabled', function () { - const opts = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, [RESPONSE]); - expect(opts.length).to.equal(2); - }); - }); -}); diff --git a/test/spec/modules/optableBidAdapter_spec.js b/test/spec/modules/optableBidAdapter_spec.js deleted file mode 100644 index b7cf2e3b4..000000000 --- a/test/spec/modules/optableBidAdapter_spec.js +++ /dev/null @@ -1,116 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/optableBidAdapter'; -import { newBidder } from 'src/adapters/bidderFactory.js'; - -describe('optableBidAdapter', function() { - const adapter = newBidder(spec); - - describe('isBidRequestValid', function() { - const validBid = { - bidder: 'optable', - params: { site: '123' }, - }; - - it('should return true when required params are present', function() { - expect(spec.isBidRequestValid(validBid)).to.be.true; - }); - - it('should return false when site is missing', function() { - const invalidBid = { ...validBid }; - delete invalidBid.params.site; - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function() { - const validBid = { - bidder: 'optable', - params: { - site: '123', - }, - }; - - const bidderRequest = { - bidderRequestId: 'bid123', - refererInfo: { - domain: 'example.com', - page: 'https://example.com/page', - ref: 'https://referrer.com' - }, - }; - - it('should include site as tagid in imp', function() { - const request = spec.buildRequests([validBid], bidderRequest); - expect(request.url).to.equal('https://ads.optable.co/ca/ortb2/v1/ssp/bid'); - expect(request.method).to.equal('POST'); - expect(request.data.imp[0].tagid).to.equal('123') - }); - }); - - describe('buildPAAPIConfigs', () => { - function makeRequest({bidId, site = 'mockSite', ae = 1}) { - return { - bidId, - params: { - site - }, - ortb2Imp: { - ext: {ae} - } - } - } - it('should generate auction configs for ae requests', () => { - const configs = spec.buildPAAPIConfigs([ - makeRequest({bidId: 'bid1', ae: 1}), - makeRequest({bidId: 'bid2', ae: 0}), - makeRequest({bidId: 'bid3', ae: 1}), - ]); - expect(configs.map(cfg => cfg.bidId)).to.eql(['bid1', 'bid3']); - configs.forEach(cfg => sinon.assert.match(cfg.config, { - seller: 'https://ads.optable.co', - decisionLogicURL: `https://ads.optable.co/ca/paapi/v1/ssp/decision-logic.js?origin=mockSite`, - interestGroupBuyers: ['https://ads.optable.co'] - })) - }) - }) - - describe('interpretResponse', function() { - const validBid = { - bidder: 'optable', - params: { - site: '123', - }, - }; - - const bidderRequest = { - bidderRequestId: 'bid123', - refererInfo: { - domain: 'example.com', - page: 'https://example.com/page', - ref: 'https://referrer.com' - }, - }; - - const response = { - body: { - ext: { - optable: { - fledge: { - auctionconfigs: [ - { impid: 'bid123', seller: 'https://ads.optable.co' }, - ] - } - } - } - } - }; - - it('maps paapi from ext.optable.fledge.auctionconfigs', function() { - const request = spec.buildRequests([validBid], bidderRequest); - const result = spec.interpretResponse(response, request); - expect(result.paapi).to.deep.equal([ - { bidId: 'bid123', config: { seller: 'https://ads.optable.co' } } - ]); - }); - }); -}); diff --git a/test/spec/modules/optableRtdProvider_spec.js b/test/spec/modules/optableRtdProvider_spec.js deleted file mode 100644 index 7aa4be3c8..000000000 --- a/test/spec/modules/optableRtdProvider_spec.js +++ /dev/null @@ -1,262 +0,0 @@ -import { - parseConfig, - defaultHandleRtd, - mergeOptableData, - getBidRequestData, - getTargetingData, - optableSubmodule, -} from 'modules/optableRtdProvider'; - -describe('Optable RTD Submodule', function () { - describe('parseConfig', function () { - it('parses valid config correctly', function () { - const config = { - params: { - bundleUrl: 'https://cdn.optable.co/bundle.js', - adserverTargeting: true, - handleRtd: () => {} - } - }; - expect(parseConfig(config)).to.deep.equal({ - bundleUrl: 'https://cdn.optable.co/bundle.js', - adserverTargeting: true, - handleRtd: config.params.handleRtd, - }); - }); - - it('trims bundleUrl if it contains extra spaces', function () { - const config = {params: {bundleUrl: ' https://cdn.optable.co/bundle.js '}}; - expect(parseConfig(config).bundleUrl).to.equal('https://cdn.optable.co/bundle.js'); - }); - - it('throws an error for invalid bundleUrl format', function () { - expect(() => parseConfig({params: {bundleUrl: 'invalidURL'}})).to.throw(); - expect(() => parseConfig({params: {bundleUrl: 'www.invalid.com'}})).to.throw(); - }); - - it('throws an error for non-HTTPS bundleUrl', function () { - expect(() => parseConfig({params: {bundleUrl: 'http://cdn.optable.co/bundle.js'}})).to.throw(); - expect(() => parseConfig({params: {bundleUrl: '//cdn.optable.co/bundle.js'}})).to.throw(); - expect(() => parseConfig({params: {bundleUrl: '/bundle.js'}})).to.throw(); - }); - - it('defaults adserverTargeting to true if missing', function () { - expect(parseConfig( - {params: {bundleUrl: 'https://cdn.optable.co/bundle.js'}} - ).adserverTargeting).to.be.true; - }); - - it('throws an error if handleRtd is not a function', function () { - expect(() => parseConfig({params: {handleRtd: 'notAFunction'}})).to.throw(); - }); - }); - - describe('defaultHandleRtd', function () { - let sandbox, reqBidsConfigObj, mergeFn; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - reqBidsConfigObj = {ortb2Fragments: {global: {}}}; - mergeFn = sinon.spy(); - window.optable = { - instance: { - targeting: sandbox.stub(), - targetingFromCache: sandbox.stub(), - }, - }; - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('merges valid targeting data into the global ORTB2 object', async function () { - const targetingData = {ortb2: {user: {ext: {optable: 'testData'}}}}; - window.optable.instance.targetingFromCache.returns(targetingData); - window.optable.instance.targeting.resolves(targetingData); - - await defaultHandleRtd(reqBidsConfigObj, {}, mergeFn); - expect(mergeFn.calledWith(reqBidsConfigObj.ortb2Fragments.global, targetingData.ortb2)).to.be.true; - }); - - it('does nothing if targeting data is missing the ortb2 property', async function () { - window.optable.instance.targetingFromCache.returns({}); - window.optable.instance.targeting.resolves({}); - - await defaultHandleRtd(reqBidsConfigObj, {}, mergeFn); - expect(mergeFn.called).to.be.false; - }); - - it('uses targeting data from cache if available', async function () { - const targetingData = {ortb2: {user: {ext: {optable: 'testData'}}}}; - window.optable.instance.targetingFromCache.returns(targetingData); - - await defaultHandleRtd(reqBidsConfigObj, {}, mergeFn); - expect(mergeFn.calledWith(reqBidsConfigObj.ortb2Fragments.global, targetingData.ortb2)).to.be.true; - }); - - it('calls targeting function if no data is found in cache', async function () { - const targetingData = {ortb2: {user: {ext: {optable: 'testData'}}}}; - window.optable.instance.targetingFromCache.returns(null); - window.optable.instance.targeting.resolves(targetingData); - - await defaultHandleRtd(reqBidsConfigObj, {}, mergeFn); - expect(mergeFn.calledWith(reqBidsConfigObj.ortb2Fragments.global, targetingData.ortb2)).to.be.true; - }); - }); - - describe('mergeOptableData', function () { - let sandbox, mergeFn, handleRtdFn, reqBidsConfigObj; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - mergeFn = sinon.spy(); - reqBidsConfigObj = {ortb2Fragments: {global: {}}}; - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('calls handleRtdFn synchronously if it is a regular function', async function () { - handleRtdFn = sinon.spy(); - await mergeOptableData(handleRtdFn, reqBidsConfigObj, {}, mergeFn); - expect(handleRtdFn.calledOnceWith(reqBidsConfigObj, {}, mergeFn)).to.be.true; - }); - - it('calls handleRtdFn asynchronously if it is an async function', async function () { - handleRtdFn = sinon.stub().resolves(); - await mergeOptableData(handleRtdFn, reqBidsConfigObj, {}, mergeFn); - expect(handleRtdFn.calledOnceWith(reqBidsConfigObj, {}, mergeFn)).to.be.true; - }); - }); - - describe('getBidRequestData', function () { - let sandbox, reqBidsConfigObj, callback, moduleConfig; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - reqBidsConfigObj = {ortb2Fragments: {global: {}}}; - callback = sinon.spy(); - moduleConfig = {params: {bundleUrl: 'https://cdn.optable.co/bundle.js'}}; - - sandbox.stub(window, 'optable').value({cmd: []}); - sandbox.stub(window.document, 'createElement'); - sandbox.stub(window.document, 'head'); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('loads Optable JS bundle if bundleUrl is provided', function () { - getBidRequestData(reqBidsConfigObj, callback, moduleConfig, {}); - expect(window.document.createElement.called).to.be.true; - }); - - it('uses existing Optable instance if no bundleUrl is provided', function () { - moduleConfig.params.bundleUrl = null; - getBidRequestData(reqBidsConfigObj, callback, moduleConfig, {}); - expect(window.optable.cmd.length).to.equal(1); - }); - - it('calls callback when assuming the bundle is present', function (done) { - moduleConfig.params.bundleUrl = null; - - getBidRequestData(reqBidsConfigObj, callback, moduleConfig, {}); - - // Check that the function is queued - expect(window.optable.cmd.length).to.equal(1); - // Manually trigger the queued function - window.optable.cmd[0](); - - setTimeout(() => { - expect(callback.calledOnce).to.be.true; - done(); - }, 50); - }); - - it('mergeOptableData catches error and executes callback when something goes wrong', function (done) { - moduleConfig.params.bundleUrl = null; - moduleConfig.params.handleRtd = () => { throw new Error('Test error'); }; - - getBidRequestData(reqBidsConfigObj, callback, moduleConfig, {}); - - expect(window.optable.cmd.length).to.equal(1); - window.optable.cmd[0](); - - setTimeout(() => { - expect(callback.calledOnce).to.be.true; - done(); - }, 50); - }); - - it('getBidRequestData catches error and executes callback when something goes wrong', function (done) { - moduleConfig.params.bundleUrl = null; - moduleConfig.params.handleRtd = 'not a function'; - - getBidRequestData(reqBidsConfigObj, callback, moduleConfig, {}); - - expect(window.optable.cmd.length).to.equal(0); - - setTimeout(() => { - expect(callback.calledOnce).to.be.true; - done(); - }, 50); - }); - - it("doesn't fail when optable is not available", function (done) { - delete window.optable; - getBidRequestData(reqBidsConfigObj, callback, moduleConfig, {}); - expect(window?.optable?.cmd?.length).to.be.undefined; - - setTimeout(() => { - expect(callback.calledOnce).to.be.true; - done(); - }, 50); - }); - }); - - describe('getTargetingData', function () { - let sandbox, moduleConfig; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - moduleConfig = {params: {adserverTargeting: true}}; - window.optable = {instance: {targetingKeyValuesFromCache: sandbox.stub().returns({key1: 'value1'})}}; - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('returns correct targeting data when Optable data is available', function () { - const result = getTargetingData(['adUnit1'], moduleConfig, {}, {}); - expect(result).to.deep.equal({adUnit1: {key1: 'value1'}}); - }); - - it('returns empty object when no Optable data is found', function () { - window.optable.instance.targetingKeyValuesFromCache.returns({}); - expect(getTargetingData(['adUnit1'], moduleConfig, {}, {})).to.deep.equal({}); - }); - - it('returns empty object when adserverTargeting is disabled', function () { - moduleConfig.params.adserverTargeting = false; - expect(getTargetingData(['adUnit1'], moduleConfig, {}, {})).to.deep.equal({}); - }); - - it('returns empty object when provided keys contain no data', function () { - window.optable.instance.targetingKeyValuesFromCache.returns({key1: []}); - expect(getTargetingData(['adUnit1'], moduleConfig, {}, {})).to.deep.equal({}); - - window.optable.instance.targetingKeyValuesFromCache.returns({key1: [], key2: [], key3: []}); - expect(getTargetingData(['adUnit1'], moduleConfig, {}, {})).to.deep.equal({}); - }); - }); - - describe('init', function () { - it('initializes Optable RTD module', function () { - expect(optableSubmodule.init()).to.be.true; - }); - }); -}); diff --git a/test/spec/modules/optidigitalBidAdapter_spec.js b/test/spec/modules/optidigitalBidAdapter_spec.js deleted file mode 100755 index 3b4ef61e9..000000000 --- a/test/spec/modules/optidigitalBidAdapter_spec.js +++ /dev/null @@ -1,667 +0,0 @@ -import { expect } from 'chai'; -import { spec, resetSync } from 'modules/optidigitalBidAdapter.js'; -import * as utils from 'src/utils.js'; - -const ENDPOINT = 'https://pbs.optidigital.com/bidder'; - -describe('optidigitalAdapterTests', function () { - describe('isBidRequestValid', function () { - it('bidRequest with publisherId and placementId', function () { - expect(spec.isBidRequestValid({ - bidder: 'optidigital', - params: { - publisherId: 's123', - placementId: 'Billboard_Top' - } - })).to.equal(true); - }); - it('bidRequest without publisherId', function () { - expect(spec.isBidRequestValid({ - bidder: 'optidigital', - params: { - placementId: 'Billboard_Top' - } - })).to.equal(false); - }); - it('bidRequest without placementId', function () { - expect(spec.isBidRequestValid({ - bidder: 'optidigital', - params: { - publisherId: 's123' - } - })).to.equal(false); - }); - it('bidRequest without required parameters', function () { - expect(spec.isBidRequestValid({ - bidder: 'optidigital', - params: {} - })).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidderRequest = { - bids: [ - { - 'bidder': 'optidigital', - 'params': { - 'publisherId': 's123', - 'placementId': 'Billboard_Top', - 'divId': 'Billboard_Top_3c5425', - 'badv': ['example.com'], - 'bcat': ['IAB1-1'], - 'bapp': ['com.blocked'], - 'battr': [1, 2] - }, - 'crumbs': { - 'pubcid': '7769fd03-574c-48fe-b512-8147f7c4023a' - }, - 'ortb2Imp': { - 'ext': { - 'tid': '0cb56262-9637-474d-a572-86fa860fd8b7', - 'data': { - 'adserver': { - 'name': 'gam', - 'adslot': '/19968336/header-bid-tag-0' - }, - 'pbadslot': '/19968336/header-bid-tag-0' - }, - 'gpid': '/19968336/header-bid-tag-0' - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ [ 300, 250 ], [ 300, 600 ] ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': '0cb56262-9637-474d-a572-86fa860fd8b7', - 'sizes': [ [ 300, 250 ], [ 300, 600 ] ], - 'bidId': '245d89f17f289f', - 'bidderRequestId': '199d7ffafa1e91', - 'auctionId': 'b66f01cd-3441-4403-99fa-d8062e795933', - 'src': 'client', - 'metrics': { - 'requestBids.usp': 0.5, - 'requestBids.pubCommonId': 0.29999999701976776, - 'requestBids.fpd': 3.1000000089406967, - 'requestBids.validate': 0.5, - 'requestBids.makeRequests': 2.2000000029802322, - 'requestBids.total': 570, - 'requestBids.callBids': 320.5, - 'adapter.client.net': [ - 317.30000001192093 - ], - 'adapters.client.optidigital.net': [ - 317.30000001192093 - ], - 'adapter.client.interpretResponse': [ - 0 - ], - 'adapters.client.optidigital.interpretResponse': [ - 0 - ], - 'adapter.client.validate': 0, - 'adapters.client.optidigital.validate': 0, - 'adapter.client.buildRequests': 1, - 'adapters.client.optidigital.buildRequests': 1, - 'adapter.client.total': 318.59999999403954, - 'adapters.client.optidigital.total': 318.59999999403954 - }, - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'site': { - 'page': 'https://example.com', - 'ref': 'https://example.com', - 'domain': 'example.com', - 'publisher': { - 'domain': 'example.com' - } - }, - 'device': { - 'w': 1605, - 'h': 1329, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36', - 'language': 'pl', - 'sua': { - 'source': 2, - 'platform': { - 'brand': 'Windows', - 'version': [ - '10', - '0', - '0' - ] - }, - 'browsers': [ - { - 'brand': 'Not_A Brand', - 'version': [ - '99', - '0', - '0', - '0' - ] - }, - { - 'brand': 'Google Chrome', - 'version': [ - '109', - '0', - '5414', - '75' - ] - }, - { - 'brand': 'Chromium', - 'version': [ - '109', - '0', - '5414', - '75' - ] - } - ], - 'mobile': 0, - 'model': '', - 'bitness': '64', - 'architecture': 'x86' - } - } - } - } - ], - 'refererInfo': { - 'canonicalUrl': 'https://www.prebid.org/the/link/to/the/page' - } - }; - - const validBidRequests = [ - { - 'bidder': 'optidigital', - 'bidId': '51ef8751f9aead', - 'params': { - 'publisherId': 's123', - 'placementId': 'Billboard_Top', - 'badv': ['example.com'], - 'bcat': ['IAB1-1'], - 'bapp': ['com.blocked'], - 'battr': [1, 2] - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'sizes': [[320, 50], [300, 250], [300, 600]], - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757' - } - ] - - it('should return an empty array if there are no bid requests', () => { - const emptyBidRequests = []; - const request = spec.buildRequests(emptyBidRequests, emptyBidRequests); - expect(request).to.be.an('array').that.is.empty; - }); - - it('should send bid request via POST', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.method).to.equal('POST'); - }); - - it('should send bid request to given endpoint', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.url).to.equal(ENDPOINT); - }); - - it('should be bidRequest data', function () { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.exist; - }); - - it('should add schain object to payload if exists', function () { - const bidRequest = Object.assign({}, validBidRequests[0], { - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'examplewebsite.com', - sid: '00001', - hp: 1 - }] - } - } - } - } - }); - const request = spec.buildRequests([bidRequest], bidderRequest); - const payload = JSON.parse(request.data) - expect(payload.schain).to.exist; - expect(payload.schain).to.deep.equal({ - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'examplewebsite.com', - sid: '00001', - hp: 1 - }] - }); - }); - - it('should add adContainerWidth and adContainerHeight to payload if divId exsists in parameter', function () { - const validBidRequestsWithDivId = [ - { - 'bidder': 'optidigital', - 'bidId': '51ef8751f9aead', - 'params': { - 'publisherId': 's123', - 'placementId': 'Billboard_Top', - 'divId': 'div-gpt-ad-1460505748561-0' - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 50], [300, 250], [300, 600]] - } - }, - 'sizes': [[320, 50], [300, 250], [300, 600]], - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757' - } - ] - const request = spec.buildRequests(validBidRequestsWithDivId, bidderRequest); - const payload = JSON.parse(request.data) - payload.imp[0].adContainerWidth = 1920 - payload.imp[0].adContainerHeight = 1080 - expect(payload.imp[0].adContainerWidth).to.exist; - expect(payload.imp[0].adContainerHeight).to.exist; - }); - - it('should add pageTemplate to payload if pageTemplate exsists in parameter', function () { - const validBidRequestsWithDivId = [ - { - 'bidder': 'optidigital', - 'bidId': '51ef8751f9aead', - 'params': { - 'publisherId': 's123', - 'placementId': 'Billboard_Top', - 'pageTemplate': 'home' - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 50], [300, 250], [300, 600]] - } - }, - 'sizes': [[320, 50], [300, 250], [300, 600]], - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757' - } - ] - const request = spec.buildRequests(validBidRequestsWithDivId, bidderRequest); - const payload = JSON.parse(request.data) - payload.imp[0].pageTemplate = 'home' - expect(payload.imp[0].pageTemplate).to.exist; - }); - - it('should add referrer to payload if it exsists in bidderRequest', function () { - bidderRequest.refererInfo.page = 'https://www.prebid.org'; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data) - expect(payload.referrer).to.equal('https://www.prebid.org'); - }); - - it('should use value for badv, bcat, bapp from params', function () { - bidderRequest.ortb2 = { - 'site': { - 'page': 'https://example.com', - 'ref': 'https://example.com', - 'domain': 'example.com', - 'publisher': { - 'domain': 'example.com' - } - }, - 'device': { - 'w': 1507, - 'h': 1329, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36', - 'language': 'pl', - 'sua': { - 'source': 2, - 'platform': { - 'brand': 'Windows', - 'version': [ - '10', - '0', - '0' - ] - }, - 'browsers': [ - { - 'brand': 'Not_A Brand', - 'version': [ - '99', - '0', - '0', - '0' - ] - }, - { - 'brand': 'Google Chrome', - 'version': [ - '109', - '0', - '5414', - '120' - ] - }, - { - 'brand': 'Chromium', - 'version': [ - '109', - '0', - '5414', - '120' - ] - } - ], - 'mobile': 0, - 'model': '', - 'bitness': '64', - 'architecture': 'x86' - } - } - }; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.badv).to.deep.equal(validBidRequests[0].params.badv); - expect(payload.bcat).to.deep.equal(validBidRequests[0].params.bcat); - expect(payload.bapp).to.deep.equal(validBidRequests[0].params.bapp); - }); - - it('should send empty GDPR consent and required set to false', function() { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.gdpr.consent).to.equal(''); - expect(payload.gdpr.required).to.equal(false); - }); - - it('should send GDPR to given endpoint', function() { - const consentString = 'DFR8KRePoQNsRREZCADBG+A=='; - bidderRequest.gdprConsent = { - 'consentString': consentString, - 'gdprApplies': true, - 'vendorData': { - 'hasGlobalConsent': false - }, - 'apiVersion': 1 - } - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.gdpr).to.exist; - expect(payload.gdpr.consent).to.equal(consentString); - expect(payload.gdpr.required).to.exist.and.to.be.true; - }); - - it('should send empty GDPR consent to endpoint', function() { - const consentString = false; - bidderRequest.gdprConsent = { - 'consentString': consentString, - 'gdprApplies': true, - 'vendorData': { - 'hasGlobalConsent': false - }, - 'apiVersion': 1 - } - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.gdpr.consent).to.equal(''); - }); - - it('should send uspConsent to given endpoint', function() { - bidderRequest.uspConsent = '1YYY'; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.us_privacy).to.exist; - }); - - it('should send gppConsent to given endpoint where there is gppConsent', function() { - const consentString = 'BOJ/P2HOJ/P2HABABMAAAAAZ+A=='; - bidderRequest.gppConsent = { - 'gppString': consentString, - 'applicableSections': [7] - }; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.gpp).to.exist; - }); - - it('should send gppConsent to given endpoint when there is gpp in ortb2', function() { - const consentString = 'BOJ/P2HOJ/P2HABABMAAAAAZ+A=='; - bidderRequest.gppConsent = undefined; - bidderRequest.ortb2 = { - regs: { - gpp: consentString, - gpp_sid: [7] - } - } - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.gpp).to.exist; - }); - - it('should use appropriate mediaTypes banner sizes', function() { - const mediaTypesBannerSize = { - 'mediaTypes': { - 'banner': { - 'sizes': [300, 600] - } - } - }; - returnBannerSizes(mediaTypesBannerSize, '300x600'); - }); - - it('should use appropriate mediaTypes banner sizes as array', function() { - const mediaTypesBannerSize = { - 'mediaTypes': { - 'banner': { - 'sizes': [300, 600] - } - } - }; - returnBannerSizes(mediaTypesBannerSize, ['300x600']); - }); - - it('should fetch floor from floor module if it is available', function() { - const validBidRequestsWithCurrency = [ - { - 'bidder': 'optidigital', - 'bidId': '51ef8751f9aead', - 'params': { - 'publisherId': 's123', - 'placementId': 'Billboard_Top', - 'pageTemplate': 'home', - 'currency': 'USD' - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 50], [300, 250], [300, 600]] - } - }, - 'sizes': [[320, 50], [300, 250], [300, 600]], - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757' - } - ] - let floorInfo; - validBidRequestsWithCurrency[0].getFloor = () => floorInfo; - floorInfo = { currency: 'USD', floor: 1.99 }; - const request = spec.buildRequests(validBidRequestsWithCurrency, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.imp[0].bidFloor).to.exist; - }); - - it('should add userEids to payload', function() { - const userIdAsEids = [{ - source: 'pubcid.org', - uids: [{ - id: '121213434342343', - atype: 1 - }] - }]; - validBidRequests[0].userIdAsEids = userIdAsEids; - bidderRequest.userIdAsEids = userIdAsEids; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.user.eids).to.deep.equal(userIdAsEids); - }); - - it('should not add userIdAsEids to payload when userIdAsEids is not present', function() { - validBidRequests[0].userIdAsEids = undefined; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.user).to.deep.equal(undefined); - }); - - function returnBannerSizes(mediaTypes, expectedSizes) { - const bidRequest = Object.assign(validBidRequests[0], mediaTypes); - const request = spec.buildRequests([bidRequest], bidderRequest); - const payload = JSON.parse(request.data); - return payload.imp.forEach(bid => { - if (Array.isArray(expectedSizes)) { - expect(JSON.stringify(bid.sizes)).to.equal(JSON.stringify(expectedSizes)); - } else { - expect(bid.sizes[0]).to.equal(expectedSizes); - } - }); - } - }); - describe('getUserSyncs', function() { - const syncurlIframe = 'https://scripts.opti-digital.com/js/presync.html?endpoint=optidigital'; - let test; - beforeEach(function () { - test = sinon.createSandbox(); - resetSync(); - }); - afterEach(function() { - test.restore(); - }); - - it('should be executed as in config', function() { - expect(spec.getUserSyncs({ iframeEnabled: true }, {}, undefined, undefined)).to.deep.equal([{ - type: 'iframe', url: syncurlIframe - }]); - }); - - it('should return appropriate URL with GDPR equals to 1 and GDPR consent', function() { - expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, undefined)).to.deep.equal([{ - type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=foo` - }]); - }); - it('should return appropriate URL with GDPR equals to 0 and GDPR consent', function() { - expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: false, consentString: 'foo'}, undefined)).to.deep.equal([{ - type: 'iframe', url: `${syncurlIframe}&gdpr=0&gdpr_consent=foo` - }]); - }); - it('should return appropriate URL with GDPR equals to 1 and no consent', function() { - expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: undefined}, undefined)).to.deep.equal([{ - type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=` - }]); - }); - it('should return appropriate URL with GDPR equals to 1, GDPR consent and US Privacy consent', function() { - expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, 'fooUsp')).to.deep.equal([{ - type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=foo&us_privacy=fooUsp` - }]); - }); - it('should return appropriate URL with GDPR equals to 1, GDPR consent, US Privacy consent and GPP consent', function() { - expect(spec.getUserSyncs({ iframeEnabled: true }, {}, {gdprApplies: true, consentString: 'foo'}, 'fooUsp', {gppString: 'fooGpp', applicableSections: [7]})).to.deep.equal([{ - type: 'iframe', url: `${syncurlIframe}&gdpr=1&gdpr_consent=foo&us_privacy=fooUsp&gpp=fooGpp&gpp_sid=7` - }]); - }); - }); - describe('interpretResponse', function () { - it('should get bids', function() { - const bids = { - 'body': { - 'bids': [{ - 'transactionId': 'cf5faec3-fcee-4f26-80ae-fc8b6cf23b7d', - 'placementId': 'Billboard_Top', - 'bidId': '83fb53a5e67f49', - 'ttl': 150, - 'creativeId': 'mobile_pos_2', - 'cur': 'USD', - 'cpm': 0.445455, - 'w': '300', - 'h': '600', - 'adm': '', - 'adomain': [] - }] - } - }; - const expectedResponse = [ - { - 'placementId': 'Billboard_Top', - 'requestId': '83fb53a5e67f49', - 'ttl': 150, - 'creativeId': 'mobile_pos_2', - 'currency': 'USD', - 'cpm': 0.445455, - 'width': '300', - 'height': '600', - 'ad': '', - 'netRevenue': true, - 'meta': { - 'advertiserDomains': [] - } - } - ]; - const result = spec.interpretResponse(bids); - expect(result).to.eql(expectedResponse); - }); - - it('should handle empty array bid response', function() { - const bids = { - 'body': { - 'bids': [] - } - }; - const result = spec.interpretResponse(bids); - expect(result.length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/optimeraRtdProvider_spec.js b/test/spec/modules/optimeraRtdProvider_spec.js deleted file mode 100644 index adcc84dcf..000000000 --- a/test/spec/modules/optimeraRtdProvider_spec.js +++ /dev/null @@ -1,231 +0,0 @@ -import * as optimeraRTD from '../../../modules/optimeraRtdProvider.js'; - -const utils = require('src/utils.js'); - -describe('Optimera RTD sub module', () => { - it('should init, return true, and set the params', () => { - const conf = { - dataProviders: [{ - name: 'optimeraRTD', - params: { - clientID: '9999', - optimeraKeyName: 'optimera', - device: 'de', - transmitWithBidRequests: 'allow', - } - }] - }; - expect(optimeraRTD.init(conf.dataProviders[0])).to.equal(true); - expect(optimeraRTD.clientID).to.equal('9999'); - expect(optimeraRTD.optimeraKeyName).to.equal('optimera'); - expect(optimeraRTD.device).to.equal('de'); - expect(optimeraRTD.transmitWithBidRequests).to.equal('allow'); - }); -}); - -describe('Optimera RTD score file URL is properly set for v0', () => { - it('should properly set the score file URL', () => { - const conf = { - dataProviders: [{ - name: 'optimeraRTD', - params: { - clientID: '9999', - optimeraKeyName: 'optimera', - device: 'de', - apiVersion: 'v0', - } - }] - }; - optimeraRTD.init(conf.dataProviders[0]); - optimeraRTD.setScores(); - expect(optimeraRTD.apiVersion).to.equal('v0'); - expect(optimeraRTD.scoresURL).to.equal('https://dyv1bugovvq1g.cloudfront.net/9999/localhost%3A9876/context.html.js'); - }); - - it('should properly set the score file URL without apiVersion set', () => { - const conf = { - dataProviders: [{ - name: 'optimeraRTD', - params: { - clientID: '9999', - optimeraKeyName: 'optimera', - device: 'de', - } - }] - }; - optimeraRTD.init(conf.dataProviders[0]); - optimeraRTD.setScores(); - expect(optimeraRTD.apiVersion).to.equal('v0'); - expect(optimeraRTD.scoresURL).to.equal('https://dyv1bugovvq1g.cloudfront.net/9999/localhost%3A9876/context.html.js'); - }); - - it('should properly set the score file URL with an api version other than v0 or v1', () => { - const conf = { - dataProviders: [{ - name: 'optimeraRTD', - params: { - clientID: '9999', - optimeraKeyName: 'optimera', - device: 'de', - apiVersion: 'v15', - } - }] - }; - optimeraRTD.init(conf.dataProviders[0]); - optimeraRTD.setScores(); - expect(optimeraRTD.scoresURL).to.equal('https://dyv1bugovvq1g.cloudfront.net/9999/localhost%3A9876/context.html.js'); - }); -}); - -describe('Optimera RTD score file URL is properly set for v1', () => { - it('should properly set the score file URL', () => { - const conf = { - dataProviders: [{ - name: 'optimeraRTD', - params: { - clientID: '9999', - optimeraKeyName: 'optimera', - device: 'de', - apiVersion: 'v1', - } - }] - }; - optimeraRTD.init(conf.dataProviders[0]); - optimeraRTD.setScores(); - expect(optimeraRTD.apiVersion).to.equal('v1'); - expect(optimeraRTD.scoresURL).to.equal('https://v1.oapi26b.com/api/products/scores?c=9999&h=localhost:9876&p=/context.html&s=de'); - }); -}); - -describe('Optimera RTD score file properly sets targeting values', () => { - const scores = { - 'div-0': ['A1', 'A2'], - 'div-1': ['A3', 'A4'], - device: { - de: { - 'div-0': ['A5', 'A6'], - 'div-1': ['A7', 'A8'], - insights: { - ilv: ['div-0'], - miv: ['div-4'], - } - }, - mo: { - 'div-0': ['A9', 'B0'], - 'div-1': ['B1', 'B2'], - insights: { - ilv: ['div-1'], - miv: ['div-2'], - } - } - }, - insights: { - ilv: ['div-5'], - miv: ['div-6'], - } - }; - it('Properly set the score file url and scores', () => { - optimeraRTD.setScores(JSON.stringify(scores)); - expect(optimeraRTD.optimeraTargeting['div-0']).to.include.ordered.members(['A5', 'A6']); - expect(optimeraRTD.optimeraTargeting['div-1']).to.include.ordered.members(['A7', 'A8']); - }); -}); - -describe('Optimera RTD propery sets the window.optimera object', () => { - const scores = { - 'div-0': ['A1', 'A2'], - 'div-1': ['A3', 'A4'], - device: { - de: { - 'div-0': ['A5', 'A6'], - 'div-1': ['A7', 'A8'], - insights: { - ilv: ['div-0'], - miv: ['div-4'], - } - }, - mo: { - 'div-0': ['A9', 'B0'], - 'div-1': ['B1', 'B2'], - insights: { - ilv: ['div-1'], - miv: ['div-2'], - } - } - }, - insights: { - ilv: ['div-5'], - miv: ['div-6'], - } - }; - it('Properly set the score file url and scores', () => { - optimeraRTD.setScores(JSON.stringify(scores)); - expect(window.optimera.data['div-1']).to.include.ordered.members(['A7', 'A8']); - expect(window.optimera.insights.ilv).to.include.ordered.members(['div-0']); - }); -}); - -describe('Optimera RTD targeting object is properly formed', () => { - const adDivs = ['div-0', 'div-1']; - it('applyTargeting properly created the targeting object', () => { - const targeting = optimeraRTD.returnTargetingData(adDivs); - expect(targeting).to.deep.include({ 'div-0': { optimera: [['A5', 'A6']] } }); - expect(targeting).to.deep.include({ 'div-1': { optimera: [['A7', 'A8']] } }); - }); -}); - -describe('Optimera RTD error logging', () => { - let utilsLogErrorStub; - - beforeEach(() => { - utilsLogErrorStub = sinon.stub(utils, 'logError'); - }); - afterEach(() => { - utilsLogErrorStub.restore(); - }); - - it('ommitting clientID should log an error', () => { - const conf = { - dataProviders: [{ - name: 'optimeraRTD', - params: { - optimeraKeyName: 'optimera', - device: 'de' - } - }] - }; - optimeraRTD.init(conf.dataProviders[0]); - expect(utils.logError.called).to.equal(true); - }); - - it('if adUnits is not an array should log an error', () => { - optimeraRTD.returnTargetingData('test'); - expect(utils.logError.called).to.equal(true); - }); -}); - -describe('Optimera RTD injectOrtbScores', () => { - it('injects optimera targeting into ortb2Imp.ext.data', () => { - const adUnits = [ - { code: 'div-0', ortb2Imp: {} }, - { code: 'div-1', ortb2Imp: {} } - ]; - - const reqBidsConfigObj = { adUnits }; - - optimeraRTD.injectOrtbScores(reqBidsConfigObj); - - expect(reqBidsConfigObj.adUnits[0].ortb2Imp.ext.data.optimera).to.deep.equal(['A5', 'A6']); - expect(reqBidsConfigObj.adUnits[1].ortb2Imp.ext.data.optimera).to.deep.equal(['A7', 'A8']); - }); - - it('does not inject when no targeting data is available', () => { - const adUnits = [{ code: 'div-unknown', ortb2Imp: {} }]; - - const reqBidsConfigObj = { adUnits }; - - optimeraRTD.injectOrtbScores(reqBidsConfigObj); - - expect(reqBidsConfigObj.adUnits[0].ortb2Imp.ext?.data?.optimera).to.be.undefined; - }); -}); diff --git a/test/spec/modules/optimonAnalyticsAdapter_spec.js b/test/spec/modules/optimonAnalyticsAdapter_spec.js deleted file mode 100644 index 270f3aec3..000000000 --- a/test/spec/modules/optimonAnalyticsAdapter_spec.js +++ /dev/null @@ -1,32 +0,0 @@ -import * as utils from 'src/utils.js'; -import { expect } from 'chai'; -import optimonAnalyticsAdapter from '../../../modules/optimonAnalyticsAdapter.js'; -import adapterManager from 'src/adapterManager'; -import * as events from 'src/events'; -import {expectEvents} from '../../helpers/analytics.js'; - -const AD_UNIT_CODE = 'demo-adunit-1'; -const PUBLISHER_CONFIG = { - pubId: 'optimon_test', - pubAdxAccount: 123456789, - pubTimezone: 'Asia/Jerusalem' -}; - -describe('Optimon Analytics Adapter', () => { - const optmn_currentWindow = utils.getWindowSelf(); - - beforeEach(() => { - optmn_currentWindow.OptimonAnalyticsAdapter = sinon.stub() - adapterManager.enableAnalytics({ - provider: 'optimon' - }); - }); - - afterEach(() => { - optimonAnalyticsAdapter.disableAnalytics(); - }); - - it('should forward all events to the queue', () => { - expectEvents().to.beBundledTo(optmn_currentWindow.OptimonAnalyticsAdapter); - }); -}); diff --git a/test/spec/modules/optoutBidAdapter_spec.js b/test/spec/modules/optoutBidAdapter_spec.js deleted file mode 100644 index 0b8e9574b..000000000 --- a/test/spec/modules/optoutBidAdapter_spec.js +++ /dev/null @@ -1,115 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/optoutBidAdapter.js'; -import {config} from 'src/config.js'; - -describe('optoutAdapterTest', function () { - describe('bidRequestValidity', function () { - it('bidRequest with adslot param', function () { - expect(spec.isBidRequestValid({ - bidder: 'optout', - params: { - 'adslot': 'prebid_demo', - 'publisher': '8' - } - })).to.equal(true); - }); - - it('bidRequest with no adslot param', function () { - expect(spec.isBidRequestValid({ - bidder: 'optout', - params: { - 'publisher': '8' - } - })).to.equal(false); - }); - - it('bidRequest with no publisher param', function () { - expect(spec.isBidRequestValid({ - bidder: 'optout', - params: { - 'adslot': 'prebid_demo' - } - })).to.equal(false); - }); - - it('bidRequest without params', function () { - expect(spec.isBidRequestValid({ - bidder: 'optout', - params: { } - })).to.equal(false); - }); - }); - - describe('bidRequest', function () { - const bidRequests = [{ - 'bidder': 'optout', - 'params': { - 'adslot': 'prebid_demo', - 'publisher': '8' - }, - 'adUnitCode': 'aaa', - 'transactionId': '1b8389fe-615c-482d-9f1a-177fb8f7d5b0', - 'bidId': '9304jr394ddfj', - 'bidderRequestId': '70deaff71c281d', - 'auctionId': '5c66da22-426a-4bac-b153-77360bef5337' - }, - { - 'bidder': 'optout', - 'params': { - 'adslot': 'testslot2', - 'publisher': '2' - }, - 'adUnitCode': 'bbb', - 'transactionId': '193995b4-7122-4739-959b-2463282a138b', - 'bidId': '893j4f94e8jei', - 'bidderRequestId': '70deaff71c281d', - 'gdprConsent': { - consentString: '', - gdprApplies: true, - apiVersion: 2 - }, - 'auctionId': 'e97cafd0-ebfc-4f5c-b7c9-baa0fd335a4a' - }]; - - it('bidRequest HTTP method', function () { - const requests = spec.buildRequests(bidRequests, {}); - requests.forEach(function(requestItem) { - expect(requestItem.method).to.equal('POST'); - }); - }); - - it('bidRequest url without consent', function () { - const requests = spec.buildRequests(bidRequests, {}); - requests.forEach(function(requestItem) { - expect(requestItem.url).to.match(new RegExp('adscience-nocookie\\.nl/prebid/display')); - }); - }); - - it('bidRequest id', function () { - const requests = spec.buildRequests(bidRequests, {}); - expect(requests[0].data.requestId).to.equal('9304jr394ddfj'); - expect(requests[1].data.requestId).to.equal('893j4f94e8jei'); - }); - - it('bidRequest with config for currency', function () { - config.setConfig({ - currency: { - adServerCurrency: 'USD', - granularityMultiplier: 1 - } - }) - - const requests = spec.buildRequests(bidRequests, {}); - expect(requests[0].data.cur.adServerCurrency).to.equal('USD'); - expect(requests[1].data.cur.adServerCurrency).to.equal('USD'); - }); - - it('bidRequest without config for currency', function () { - config.resetConfig(); - - const requests = spec.buildRequests(bidRequests, {}); - expect(requests[0].data.cur.adServerCurrency).to.equal('EUR'); - expect(requests[1].data.cur.adServerCurrency).to.equal('EUR'); - }); - }); -}); diff --git a/test/spec/modules/orakiBidAdapter_spec.js b/test/spec/modules/orakiBidAdapter_spec.js deleted file mode 100644 index 4a6b8fa7d..000000000 --- a/test/spec/modules/orakiBidAdapter_spec.js +++ /dev/null @@ -1,513 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/orakiBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'oraki'; - -describe('OrakiBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner', - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo', - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK', - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys( - 'deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync.oraki.io/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync.oraki.io/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync.oraki.io/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/orbidderBidAdapter_spec.js b/test/spec/modules/orbidderBidAdapter_spec.js deleted file mode 100644 index dc33222f8..000000000 --- a/test/spec/modules/orbidderBidAdapter_spec.js +++ /dev/null @@ -1,560 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/orbidderBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import * as _ from 'lodash'; -import { BANNER, NATIVE } from '../../../src/mediaTypes.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -describe('orbidderBidAdapter', () => { - const adapter = newBidder(spec); - const defaultBidRequestBanner = { - bidId: 'd66fa86787e0b0ca900a96eacfd5f0bb', - auctionId: 'ccc4c7cdfe11cfbd74065e6dd28413d8', - transactionId: 'd58851660c0c4461e4aa06344fc9c0c6', - bidRequestCount: 1, - adUnitCode: 'adunit-code', - sizes: [[300, 250], [300, 600]], - params: { - 'accountId': 'string1', - 'placementId': 'string2', - 'bidfloor': 1.23 - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - userId: { - 'id5id': { - 'uid': 'ID5*XXXXXXXXXXXXX', - 'ext': { - 'linkType': 2, - 'pba': 'XXXXXXXXXXXX==' - } - } - }, - userIdAsEids: [ - { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': 'ID5*XXXXXXXXXXXXX', - 'atype': 1, - 'ext': { - 'linkType': 2, - 'pba': 'XXXXXXXXXXXX==' - } - } - ] - } - ] - }; - - const defaultBidRequestNative = { - bidId: 'd66fa86787e0b0ca900a96eacfd5f0bc', - auctionId: 'ccc4c7cdfe11cfbd74065e6dd28413d9', - transactionId: 'd58851660c0c4461e4aa06344fc9c0c6', - bidRequestCount: 1, - adUnitCode: 'adunit-code-native', - sizes: [], - params: { - 'accountId': 'string3', - 'placementId': 'string4', - 'bidfloor': 2.34 - }, - mediaTypes: { - native: { - title: { - required: true - }, - image: { - required: true, - sizes: [300, 250] - }, - sponsoredBy: { - required: true - } - } - }, - userId: { - 'id5id': { - 'uid': 'ID5*YYYYYYYYYYYYYYY', - 'ext': { - 'linkType': 2, - 'pba': 'YYYYYYYYYYYYY==' - } - } - }, - userIdAsEids: [ - { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': 'ID5*YYYYYYYYYYYYYYY', - 'atype': 1, - 'ext': { - 'linkType': 2, - 'pba': 'YYYYYYYYYYYYY==' - } - } - ] - } - ] - }; - - const deepClone = function(val) { - return JSON.parse(JSON.stringify(val)); - }; - - const buildRequest = (buildRequest, bidderRequest) => { - if (!Array.isArray(buildRequest)) { - buildRequest = [buildRequest]; - } - - return spec.buildRequests(buildRequest, { - ...bidderRequest || {}, - refererInfo: { - page: 'https://localhost:9876/' - } - })[0]; - }; - - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', () => { - it('banner: should return true when required params found', () => { - expect(spec.isBidRequestValid(defaultBidRequestBanner)).to.equal(true); - }); - - it('native: should return true when required params found', () => { - expect(spec.isBidRequestValid(defaultBidRequestNative)).to.equal(true); - }); - - it('banner: accepts optional keyValues object', () => { - const bidRequest = deepClone(defaultBidRequestBanner); - bidRequest.params.keyValues = { 'key': 'value' }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('native: accepts optional keyValues object', () => { - const bidRequest = deepClone(defaultBidRequestNative); - bidRequest.params.keyValues = { 'key': 'value' }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('banner: performs type checking', () => { - const bidRequest = deepClone(defaultBidRequestBanner); - bidRequest.params.accountId = 1; // supposed to be a string - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('native: performs type checking', () => { - const bidRequest = deepClone(defaultBidRequestNative); - bidRequest.params.accountId = 1; // supposed to be a string - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('banner: doesn\'t accept malformed keyValues', () => { - const bidRequest = deepClone(defaultBidRequestBanner); - bidRequest.params.keyValues = 'another not usable string'; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('native: doesn\'t accept malformed keyValues', () => { - const bidRequest = deepClone(defaultBidRequestNative); - bidRequest.params.keyValues = 'another not usable string'; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('banner: should return false when required params are not passed', () => { - const bidRequest = deepClone(defaultBidRequestBanner); - delete bidRequest.params; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('native: should return false when required params are not passed', () => { - const bidRequest = deepClone(defaultBidRequestNative); - delete bidRequest.params; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('banner: accepts optional bidfloor', () => { - const bidRequest = deepClone(defaultBidRequestBanner); - bidRequest.params.bidfloor = 123; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - - bidRequest.params.bidfloor = 1.23; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('native: accepts optional bidfloor', () => { - const bidRequest = deepClone(defaultBidRequestNative); - bidRequest.params.bidfloor = 123; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - - bidRequest.params.bidfloor = 1.23; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - }); - - describe('buildRequests', () => { - let request, nativeRequest; - before(() => { - request = buildRequest(defaultBidRequestBanner); - nativeRequest = buildRequest(defaultBidRequestNative); - }) - - it('sends bid request to endpoint via https using post', () => { - expect(request.method).to.equal('POST'); - expect(request.url.indexOf('https://')).to.equal(0); - expect(request.url).to.equal(`${spec.hostname}/bid`); - }); - - it('contains prebid version parameter', () => { - expect(request.data.v).to.equal(getGlobal().version); - }); - - it('banner: sends correct bid parameters', () => { - // we add two, because we add pageUrl and version from bidderRequest object - expect(Object.keys(request.data).length).to.equal(Object.keys(defaultBidRequestBanner).length + 2); - - const expectedBidRequest = deepClone(defaultBidRequestBanner); - expectedBidRequest.pageUrl = 'https://localhost:9876/'; - expectedBidRequest.v = getGlobal().version; - expect(request.data).to.deep.equal(expectedBidRequest); - }); - - it('native: sends correct bid parameters', () => { - // we add two, because we add pageUrl and version from bidderRequest object - expect(Object.keys(nativeRequest.data).length).to.equal(Object.keys(defaultBidRequestNative).length + 2); - - const expectedBidRequest = deepClone(defaultBidRequestNative); - expectedBidRequest.pageUrl = 'https://localhost:9876/'; - expectedBidRequest.v = getGlobal().version; - expect(nativeRequest.data).to.deep.equal(expectedBidRequest); - }); - - it('banner: handles empty gdpr object', () => { - const request = buildRequest(defaultBidRequestBanner, { - gdprConsent: {} - }); - expect(request.data.gdprConsent.consentRequired).to.be.equal(false); - }); - - it('native: handles empty gdpr object', () => { - const request = buildRequest(defaultBidRequestNative, { - gdprConsent: {} - }); - expect(request.data.gdprConsent.consentRequired).to.be.equal(false); - }); - - it('banner: handles non-existent gdpr object', () => { - const request = buildRequest(defaultBidRequestBanner, { - gdprConsent: null - }); - expect(request.data.gdprConsent).to.be.undefined; - }); - - it('native: handles non-existent gdpr object', () => { - const request = buildRequest(defaultBidRequestNative, { - gdprConsent: null - }); - expect(request.data.gdprConsent).to.be.undefined; - }); - - it('banner: handles properly filled gdpr object where gdpr applies', () => { - const consentString = 'someWeirdString'; - const request = buildRequest(defaultBidRequestBanner, { - gdprConsent: { - gdprApplies: true, - consentString: consentString - } - }); - - const gdprConsent = request.data.gdprConsent; - expect(gdprConsent.consentRequired).to.be.equal(true); - expect(gdprConsent.consentString).to.be.equal(consentString); - }); - - it('native: handles properly filled gdpr object where gdpr applies', () => { - const consentString = 'someWeirdString'; - const request = buildRequest(defaultBidRequestNative, { - gdprConsent: { - gdprApplies: true, - consentString: consentString - } - }); - - const gdprConsent = request.data.gdprConsent; - expect(gdprConsent.consentRequired).to.be.equal(true); - expect(gdprConsent.consentString).to.be.equal(consentString); - }); - - it('banner: handles properly filled gdpr object where gdpr does not apply', () => { - const consentString = 'someWeirdString'; - const request = buildRequest(defaultBidRequestBanner, { - gdprConsent: { - gdprApplies: false, - consentString: consentString - } - }); - - const gdprConsent = request.data.gdprConsent; - expect(gdprConsent.consentRequired).to.be.equal(false); - expect(gdprConsent.consentString).to.be.equal(consentString); - }); - - it('native: handles properly filled gdpr object where gdpr does not apply', () => { - const consentString = 'someWeirdString'; - const request = buildRequest(defaultBidRequestNative, { - gdprConsent: { - gdprApplies: false, - consentString: consentString - } - }); - - const gdprConsent = request.data.gdprConsent; - expect(gdprConsent.consentRequired).to.be.equal(false); - expect(gdprConsent.consentString).to.be.equal(consentString); - }); - }); - - it('buildRequests with price floor module', () => { - const bidRequest = deepClone(defaultBidRequestBanner); - bidRequest.params.bidfloor = 1; - bidRequest.getFloor = (floorObj) => { - return { - floor: bidRequest.floors.values['banner|640x480'], - currency: floorObj.currency, - mediaType: floorObj.mediaType - } - }; - - bidRequest.floors = { - currency: 'EUR', - values: { - 'banner|640x480': 15.07 - } - }; - const request = buildRequest(bidRequest); - expect(request.data.params.bidfloor).to.equal(15.07); - }); - - describe('interpretResponse', () => { - it('banner: should get correct bid response', () => { - const serverResponse = [ - { - 'width': 300, - 'height': 250, - 'creativeId': '29681110', - 'ad': '', - 'cpm': 0.5, - 'requestId': '30b31c1838de1e', - 'ttl': 60, - 'netRevenue': true, - 'currency': 'EUR', - 'mediaType': BANNER, - } - ]; - - const expectedResponse = [ - { - 'requestId': '30b31c1838de1e', - 'cpm': 0.5, - 'creativeId': '29681110', - 'width': 300, - 'height': 250, - 'ttl': 60, - 'currency': 'EUR', - 'ad': '', - 'netRevenue': true, - 'mediaType': BANNER, - } - ]; - - const result = spec.interpretResponse({ body: serverResponse }); - expect(result.length).to.equal(expectedResponse.length); - expect(_.isEqual(expectedResponse, serverResponse)).to.be.true; - }); - - it('should get correct bid response with advertiserDomains', () => { - const serverResponse = [ - { - 'width': 300, - 'height': 250, - 'creativeId': '29681110', - 'ad': '', - 'cpm': 0.5, - 'requestId': '30b31c1838de1e', - 'ttl': 60, - 'netRevenue': true, - 'currency': 'EUR', - 'advertiserDomains': ['cm.tavira.pt'], - 'mediaType': BANNER - } - ]; - - const expectedResponse = [ - { - 'requestId': '30b31c1838de1e', - 'cpm': 0.5, - 'creativeId': '29681110', - 'width': 300, - 'height': 250, - 'ttl': 60, - 'currency': 'EUR', - 'ad': '', - 'netRevenue': true, - 'meta': { - 'advertiserDomains': ['cm.tavira.pt'] - }, - 'mediaType': BANNER - } - ]; - - const result = spec.interpretResponse({ body: serverResponse }); - - expect(result.length).to.equal(expectedResponse.length); - Object.keys(expectedResponse[0]).forEach((key) => { - expect(result[0][key]).to.deep.equal(expectedResponse[0][key]); - }); - }); - - it('native: should get correct bid response', () => { - const serverResponse = [ - { - 'creativeId': '29681110', - 'cpm': 0.5, - 'requestId': '30b31c1838de1e', - 'ttl': 60, - 'netRevenue': true, - 'currency': 'EUR', - 'mediaType': NATIVE, - 'native': { - 'image': { - 'url': 'image url', - 'width': 300, - 'height': 250, - }, - 'icon': { - 'url': 'icon url', - 'width': 50, - 'height': 50, - }, - 'impressionTrackers': 'imp tracker', - 'clickUrl': 'click', - 'sponsoredBy': 'brand', - 'cta': 'action', - 'body': 'text', - } - } - ]; - - const expectedResponse = [ - { - 'creativeId': '29681110', - 'cpm': 0.5, - 'requestId': '30b31c1838de1e', - 'ttl': 60, - 'netRevenue': true, - 'currency': 'EUR', - 'mediaType': NATIVE, - 'native': { - 'image': { - 'url': 'image url', - 'width': 300, - 'height': 250, - }, - 'icon': { - 'url': 'icon url', - 'width': 50, - 'height': 50, - }, - 'impressionTrackers': 'imp tracker', - 'clickUrl': 'click', - 'sponsoredBy': 'brand', - 'cta': 'action', - 'body': 'text', - } - } - ]; - - const result = spec.interpretResponse({ body: serverResponse }); - - expect(result.length).to.equal(expectedResponse.length); - expect(_.isEqual(expectedResponse, serverResponse)).to.be.true; - }); - - it('banner: handles broken bid response, missing creativeId', () => { - const serverResponse = [ - { - 'ad': '', - 'cpm': 0.5, - 'requestId': '30b31c1838de1e', - 'ttl': 60, - 'currency': 'EUR', - 'mediaType': BANNER, - 'width': 300, - 'height': 250, - 'netRevenue': true, - } - ]; - const result = spec.interpretResponse({ body: serverResponse }); - expect(result.length).to.equal(0); - }); - - it('banner: handles broken bid response, missing ad', () => { - const serverResponse = [ - { - 'cpm': 0.5, - 'requestId': '30b31c1838de1e', - 'ttl': 60, - 'currency': 'EUR', - 'mediaType': BANNER, - 'width': 300, - 'height': 250, - 'netRevenue': true, - 'creativeId': '29681110', - } - ]; - const result = spec.interpretResponse({ body: serverResponse }); - expect(result.length).to.equal(0); - }); - - it('native: handles broken bid response, missing impressionTrackers', () => { - const serverResponse = [ - { - 'creativeId': '29681110', - 'cpm': 0.5, - 'requestId': '30b31c1838de1e', - 'ttl': 60, - 'netRevenue': true, - 'currency': 'EUR', - 'mediaType': NATIVE, - 'native': { - 'title': 'native title', - 'sponsoredBy': 'test brand', - 'image': { - 'url': 'image url', - 'width': 300, - 'height': 250, - }, - 'clickUrl': 'click' - } - } - ]; - const result = spec.interpretResponse({ body: serverResponse }); - expect(result.length).to.equal(0); - }); - - it('handles nobid responses', () => { - const serverResponse = []; - const result = spec.interpretResponse({ body: serverResponse }); - expect(result.length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/orbitsoftBidAdapter_spec.js b/test/spec/modules/orbitsoftBidAdapter_spec.js deleted file mode 100644 index 9615daa98..000000000 --- a/test/spec/modules/orbitsoftBidAdapter_spec.js +++ /dev/null @@ -1,255 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/orbitsoftBidAdapter.js'; - -const ENDPOINT_URL = 'https://orbitsoft.com/php/ads/hb.phps'; -const REFERRER_URL = 'http://referrer.url/?_='; - -describe('Orbitsoft adapter', function () { - describe('implementation', function () { - describe('for requests', function () { - it('should accept valid bid', function () { - const validBid = { - bidder: 'orbitsoft', - params: { - placementId: '123', - requestUrl: ENDPOINT_URL - } - }; - const isValid = spec.isBidRequestValid(validBid); - - expect(isValid).to.equal(true); - }); - - it('should reject invalid bid', function () { - const invalidBid = { - bidder: 'orbitsoft' - }; - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.equal(false); - }); - }); - describe('for requests', function () { - it('should accept valid bid with styles', function () { - const validBid = { - bidder: 'orbitsoft', - params: { - placementId: '123', - requestUrl: ENDPOINT_URL, - style: { - title: { - family: 'Tahoma', - size: 'medium', - weight: 'normal', - style: 'normal', - color: '0053F9' - }, - description: { - family: 'Tahoma', - size: 'medium', - weight: 'normal', - style: 'normal', - color: '0053F9' - }, - url: { - family: 'Tahoma', - size: 'medium', - weight: 'normal', - style: 'normal', - color: '0053F9' - }, - colors: { - background: 'ffffff', - border: 'E0E0E0', - link: '5B99FE' - } - } - }, - refererInfo: {referer: REFERRER_URL}, - }; - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(true); - - const buildRequest = spec.buildRequests([validBid])[0]; - const requestUrl = buildRequest.url; - const requestUrlParams = buildRequest.data; - expect(requestUrl).to.equal(ENDPOINT_URL); - expect(requestUrlParams).have.property('f1', 'Tahoma'); - expect(requestUrlParams).have.property('fs1', 'medium'); - expect(requestUrlParams).have.property('w1', 'normal'); - expect(requestUrlParams).have.property('s1', 'normal'); - expect(requestUrlParams).have.property('c3', '0053F9'); - expect(requestUrlParams).have.property('f2', 'Tahoma'); - expect(requestUrlParams).have.property('fs2', 'medium'); - expect(requestUrlParams).have.property('w2', 'normal'); - expect(requestUrlParams).have.property('s2', 'normal'); - expect(requestUrlParams).have.property('c4', '0053F9'); - expect(requestUrlParams).have.property('f3', 'Tahoma'); - expect(requestUrlParams).have.property('fs3', 'medium'); - expect(requestUrlParams).have.property('w3', 'normal'); - expect(requestUrlParams).have.property('s3', 'normal'); - expect(requestUrlParams).have.property('c5', '0053F9'); - expect(requestUrlParams).have.property('c2', 'ffffff'); - expect(requestUrlParams).have.property('c1', 'E0E0E0'); - expect(requestUrlParams).have.property('c6', '5B99FE'); - }); - - it('should accept valid bid with custom params', function () { - const validBid = { - bidder: 'orbitsoft', - params: { - placementId: '123', - requestUrl: ENDPOINT_URL, - customParams: { - cacheBuster: 'bf4d7c1', - clickUrl: 'http://testclickurl.com' - } - }, - refererInfo: {referer: REFERRER_URL}, - }; - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(true); - - const buildRequest = spec.buildRequests([validBid])[0]; - const requestUrlCustomParams = buildRequest.data; - expect(requestUrlCustomParams).have.property('c.cacheBuster', 'bf4d7c1'); - expect(requestUrlCustomParams).have.property('c.clickUrl', 'http://testclickurl.com'); - }); - - it('should reject invalid bid without requestUrl', function () { - const invalidBid = { - bidder: 'orbitsoft', - params: { - placementId: '123' - } - }; - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.equal(false); - }); - - it('should reject invalid bid without placementId', function () { - const invalidBid = { - bidder: 'orbitsoft', - params: { - requestUrl: ENDPOINT_URL - } - }; - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.equal(false); - }); - }); - describe('bid responses', function () { - it('should return complete bid response', function () { - const serverResponse = { - body: { - callback_uid: '265b29b70cc106', - cpm: 0.5, - width: 240, - height: 240, - content_url: 'https://orbitsoft.com/php/ads/hb.html', - adomain: ['test.adomain.tld'] - } - }; - - const bidRequests = [ - { - bidder: 'orbitsoft', - params: { - placementId: '123', - requestUrl: ENDPOINT_URL - } - } - ]; - const bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); - expect(bids).to.be.lengthOf(1); - expect(bids[0].cpm).to.equal(serverResponse.body.cpm); - expect(bids[0].width).to.equal(serverResponse.body.width); - expect(bids[0].height).to.equal(serverResponse.body.height); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[0].adUrl).to.have.length.above(1); - expect(bids[0].adUrl).to.have.string('https://orbitsoft.com/php/ads/hb.html'); - expect(Object.keys(bids[0].meta)).to.include.members(['advertiserDomains']); - expect(bids[0].meta.advertiserDomains).to.deep.equal(serverResponse.body.adomain); - }); - - it('should return empty bid response', function () { - const bidRequests = [ - { - bidder: 'orbitsoft', - params: { - placementId: '123', - requestUrl: ENDPOINT_URL - } - } - ]; - const serverResponse = { - body: { - callback_uid: '265b29b70cc106', - cpm: 0 - } - }; - const bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); - - expect(bids).to.be.lengthOf(0); - }); - - it('should return empty bid response on incorrect size', function () { - const bidRequests = [ - { - bidder: 'orbitsoft', - params: { - placementId: '123', - requestUrl: ENDPOINT_URL - } - } - ]; - const serverResponse = { - body: { - callback_uid: '265b29b70cc106', - cpm: 1.5, - width: 0, - height: 0 - } - }; - const bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); - - expect(bids).to.be.lengthOf(0); - }); - - it('should return empty bid response with error', function () { - const bidRequests = [ - { - bidder: 'orbitsoft', - params: { - placementId: '123', - requestUrl: ENDPOINT_URL - } - } - ]; - const serverResponse = {error: 'error'}; - const bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); - - expect(bids).to.be.lengthOf(0); - }); - - it('should return empty bid response on empty body', function () { - const bidRequests = [ - { - bidder: 'orbitsoft', - params: { - placementId: '123', - requestUrl: ENDPOINT_URL - } - } - ]; - const serverResponse = {}; - const bids = spec.interpretResponse(serverResponse, {'bidRequest': bidRequests[0]}); - - expect(bids).to.be.lengthOf(0); - }); - }); - }); -}); diff --git a/test/spec/modules/otmBidAdapter_spec.js b/test/spec/modules/otmBidAdapter_spec.js deleted file mode 100644 index 27da17b84..000000000 --- a/test/spec/modules/otmBidAdapter_spec.js +++ /dev/null @@ -1,88 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/otmBidAdapter'; - -describe('otmBidAdapter', function () { - it('pub_params', function () { - expect(spec.isBidRequestValid({ - bidder: 'otm', - params: { - tid: '123', - bidfloor: 20 - } - })).to.equal(true); - }); - - it('generated_params common case', function () { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'otm', - params: { - tid: '123', - bidfloor: 20, - domain: 'github.com' - }, - sizes: [[240, 400]] - }]; - - const request = spec.buildRequests(bidRequestData); - const req_data = request[0].data; - - expect(req_data.bidid).to.equal('bid1234'); - expect(req_data.domain).to.equal('github.com'); - }); - - it('generated_params should return top level origin as domain if not defined', function () { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'otm', - params: { - tid: '123', - bidfloor: 20 - }, - sizes: [[240, 400]] - }]; - - const bidderRequest = {refererInfo: {page: `https://github.com:3000/`, domain: 'github.com:3000'}} - - const request = spec.buildRequests(bidRequestData, bidderRequest); - const req_data = request[0].data; - - expect(req_data.domain).to.equal(`github.com:3000`); - }); - - it('response_params common case', function () { - const bidRequestData = { - data: { - bidId: 'bid1234' - } - }; - - const serverResponse = { - body: [ - { - 'auctionid': '3c6f8e22-541b-485c-9214-e974d9fb1b6f', - 'cpm': 847.097, - 'ad': 'test html', - 'w': 240, - 'h': 400, - 'currency': 'RUB', - 'ttl': 300, - 'creativeid': '1_7869053', - 'bidid': '101f211def7c99', - 'transactionid': 'transaction_id_1' - } - ] - }; - - const bids = spec.interpretResponse(serverResponse, bidRequestData); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(847.097); - expect(bid.currency).to.equal('RUB'); - expect(bid.width).to.equal(240); - expect(bid.height).to.equal(400); - expect(bid.netRevenue).to.equal(true); - expect(bid.requestId).to.equal('101f211def7c99'); - expect(bid.ad).to.equal('test html'); - }); -}); diff --git a/test/spec/modules/outbrainBidAdapter_spec.js b/test/spec/modules/outbrainBidAdapter_spec.js deleted file mode 100644 index 06b94d985..000000000 --- a/test/spec/modules/outbrainBidAdapter_spec.js +++ /dev/null @@ -1,937 +0,0 @@ -import { expect } from 'chai'; -import { spec, storage } from 'modules/outbrainBidAdapter.js'; -import { config } from 'src/config.js'; -import { server } from 'test/mocks/xhr'; - -describe('Outbrain Adapter', function () { - describe('Bid request and response', function () { - const commonBidRequest = { - bidder: 'outbrain', - params: { - publisher: { - id: 'publisher-id' - }, - }, - bidId: '2d6815a92ba1ba', - auctionId: '12043683-3254-4f74-8934-f941b085579e', - } - const nativeBidRequestParams = { - nativeParams: { - image: { - required: true, - sizes: [ - 120, - 100 - ], - sendId: true - }, - title: { - required: true, - sendId: true - }, - sponsoredBy: { - required: false - } - }, - } - - const displayBidRequestParams = { - sizes: [ - [ - 300, - 250 - ] - ] - } - - const videoBidRequestParams = { - mediaTypes: { - video: { - playerSize: [[640, 480]], - mimes: ['video/mp4'], - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - playbackmethod: [1], - skip: 1, - api: [2], - minbitrate: 1000, - maxbitrate: 3000, - minduration: 3, - maxduration: 10, - startdelay: 2, - plcmt: 4, - placement: 5, - linearity: 1 - } - } - } - - const ortb2WithDeviceData = { - ortb2: { - device: { - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4' - } - } - }; - - describe('isBidRequestValid', function () { - before(() => { - config.setConfig({ - outbrain: { - bidderUrl: 'https://bidder-url.com', - } - } - ) - }) - after(() => { - config.resetConfig() - }) - - it('should fail when bid is invalid', function () { - const bid = { - bidder: 'outbrain', - params: { - publisher: { - id: 'publisher-id', - } - }, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - it('should succeed when bid contains native params', function () { - const bid = { - bidder: 'outbrain', - params: { - publisher: { - id: 'publisher-id', - } - }, - ...nativeBidRequestParams, - } - expect(spec.isBidRequestValid(bid)).to.equal(true) - }) - it('should succeed when bid contains sizes', function () { - const bid = { - bidder: 'outbrain', - params: { - publisher: { - id: 'publisher-id', - } - }, - ...displayBidRequestParams, - } - expect(spec.isBidRequestValid(bid)).to.equal(true) - }) - it('should succeed when bid contains video', function () { - const bid = { - bidder: 'outbrain', - params: { - publisher: { - id: 'publisher-id', - } - }, - ...videoBidRequestParams, - } - expect(spec.isBidRequestValid(bid)).to.equal(true) - }) - it('should fail when bid contains insufficient video information', function () { - const bid = { - bidder: 'outbrain', - params: { - publisher: { - id: 'publisher-id', - } - }, - mediaTypes: { - video: { - context: 'outstream' - } - }, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - it('should fail if publisher id is not set', function () { - const bid = { - bidder: 'outbrain', - ...nativeBidRequestParams, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - it('should fail if tag id is not string', function () { - const bid = { - bidder: 'outbrain', - params: { - tagid: 123 - }, - ...nativeBidRequestParams, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - it('should fail if badv does not include strings', function () { - const bid = { - bidder: 'outbrain', - params: { - tagid: 123, - badv: ['a', 2, 'c'] - }, - ...nativeBidRequestParams, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - it('should fail if bcat does not include strings', function () { - const bid = { - bidder: 'outbrain', - params: { - tagid: 123, - bcat: ['a', 2, 'c'] - }, - ...nativeBidRequestParams, - } - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - it('should succeed with outbrain config', function () { - const bid = { - bidder: 'outbrain', - params: { - publisher: { - id: 'publisher-id', - } - }, - ...nativeBidRequestParams, - } - config.resetConfig() - config.setConfig({ - outbrain: { - bidderUrl: 'https://bidder-url.com', - } - }) - expect(spec.isBidRequestValid(bid)).to.equal(true) - }) - it('should fail if bidder url is not set', function () { - const bid = { - bidder: 'outbrain', - params: { - publisher: { - id: 'publisher-id', - } - }, - ...nativeBidRequestParams, - } - config.resetConfig() - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - }) - - describe('buildRequests', function () { - let getDataFromLocalStorageStub; - - before(() => { - getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage') - config.setConfig({ - outbrain: { - bidderUrl: 'https://bidder-url.com', - } - }) - }) - after(() => { - getDataFromLocalStorageStub.restore() - config.resetConfig() - }) - - const commonBidderRequest = { - bidderRequestId: 'mock-uuid', - refererInfo: { - page: 'https://example.com/' - } - } - - it('should build native request', function () { - const bidRequest = { - ...commonBidRequest, - ...nativeBidRequestParams, - } - const expectedNativeAssets = { - assets: [ - { - required: 1, - id: 3, - img: { - type: 3, - w: 120, - h: 100 - } - }, - { - required: 1, - id: 0, - title: {} - }, - { - required: 0, - id: 5, - data: { - type: 1 - } - } - ] - } - const expectedData = { - id: 'mock-uuid', - site: { - page: 'https://example.com/', - publisher: { - id: 'publisher-id' - } - }, - device: { - ua: navigator.userAgent - }, - source: { - fd: 1 - }, - cur: [ - 'USD' - ], - imp: [ - { - id: '1', - native: { - request: JSON.stringify(expectedNativeAssets) - } - } - ], - ext: { - prebid: { - channel: { - name: 'pbjs', version: '$prebid.version$' - } - } - } - } - const res = spec.buildRequests([bidRequest], commonBidderRequest) - expect(res.url).to.equal('https://bidder-url.com') - expect(res.data).to.deep.equal(JSON.stringify(expectedData)) - }); - - it('should build display request', function () { - const bidRequest = { - ...commonBidRequest, - ...displayBidRequestParams, - } - const expectedData = { - id: 'mock-uuid', - site: { - page: 'https://example.com/', - publisher: { - id: 'publisher-id' - } - }, - device: { - ua: navigator.userAgent - }, - source: { - fd: 1 - }, - cur: [ - 'USD' - ], - imp: [ - { - id: '1', - banner: { - format: [ - { - w: 300, - h: 250 - } - ] - } - } - ], - ext: { - prebid: { - channel: { - name: 'pbjs', version: '$prebid.version$' - } - } - } - } - const res = spec.buildRequests([bidRequest], commonBidderRequest) - expect(res.url).to.equal('https://bidder-url.com') - expect(res.data).to.deep.equal(JSON.stringify(expectedData)) - }) - - it('should build video request', function () { - const bidRequest = { - ...commonBidRequest, - ...videoBidRequestParams, - } - const expectedData = { - id: 'mock-uuid', - site: { - page: 'https://example.com/', - publisher: { - id: 'publisher-id' - } - }, - device: { - ua: navigator.userAgent - }, - source: { - fd: 1 - }, - cur: [ - 'USD' - ], - imp: [ - { - id: '1', - video: { - w: 640, - h: 480, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - playbackmethod: [1], - mimes: ['video/mp4'], - skip: 1, - api: [2], - minbitrate: 1000, - maxbitrate: 3000, - minduration: 3, - maxduration: 10, - startdelay: 2, - placement: 5, - plcmt: 4, - linearity: 1 - } - } - ], - ext: { - prebid: { - channel: { - name: 'pbjs', version: '$prebid.version$' - } - } - } - } - const res = spec.buildRequests([bidRequest], commonBidderRequest) - expect(res.url).to.equal('https://bidder-url.com') - expect(res.data).to.deep.equal(JSON.stringify(expectedData)) - }) - - it('should pass optional parameters in request', function () { - const bidRequest = { - ...commonBidRequest, - ...nativeBidRequestParams, - } - bidRequest.params.tagid = 'test-tag' - bidRequest.params.publisher.name = 'test-publisher' - bidRequest.params.publisher.domain = 'test-publisher.com' - bidRequest.params.bcat = ['bad-category'] - bidRequest.params.badv = ['bad-advertiser'] - - const res = spec.buildRequests([bidRequest], commonBidderRequest) - const resData = JSON.parse(res.data) - expect(resData.imp[0].tagid).to.equal('test-tag') - expect(resData.site.publisher.name).to.equal('test-publisher') - expect(resData.site.publisher.domain).to.equal('test-publisher.com') - expect(resData.bcat).to.deep.equal(['bad-category']) - expect(resData.badv).to.deep.equal(['bad-advertiser']) - }); - - it('should pass first party data', function () { - const bidRequest = { - ...commonBidRequest, - ...nativeBidRequestParams, - } - const bidderRequest = { - ortb2: { - bcat: ['IAB1', 'IAB2-1'], - badv: ['domain1.com', 'domain2.com'], - wlang: ['en'], - }, - ...commonBidderRequest, - } - - const res = spec.buildRequests([bidRequest], bidderRequest) - const resData = JSON.parse(res.data) - expect(resData.bcat).to.deep.equal(bidderRequest.ortb2.bcat) - expect(resData.badv).to.deep.equal(bidderRequest.ortb2.badv) - expect(resData.wlang).to.deep.equal(bidderRequest.ortb2.wlang) - }); - - it('should pass bidder timeout', function () { - const bidRequest = { - ...commonBidRequest, - ...nativeBidRequestParams, - } - const bidderRequest = { - ...commonBidderRequest, - timeout: 500 - } - const res = spec.buildRequests([bidRequest], bidderRequest) - const resData = JSON.parse(res.data) - expect(resData.tmax).to.equal(500) - }); - - it('should pass GDPR consent', function () { - const bidRequest = { - ...commonBidRequest, - ...nativeBidRequestParams, - } - const bidderRequest = { - ...commonBidderRequest, - gdprConsent: { - gdprApplies: true, - consentString: 'consentString', - } - } - const res = spec.buildRequests([bidRequest], bidderRequest) - const resData = JSON.parse(res.data) - expect(resData.user.ext.consent).to.equal('consentString') - expect(resData.regs.ext.gdpr).to.equal(1) - }); - - it('should pass us privacy consent', function () { - const bidRequest = { - ...commonBidRequest, - ...nativeBidRequestParams, - } - const bidderRequest = { - ...commonBidderRequest, - uspConsent: 'consentString' - } - const res = spec.buildRequests([bidRequest], bidderRequest) - const resData = JSON.parse(res.data) - expect(resData.regs.ext.us_privacy).to.equal('consentString') - }); - - it('should pass coppa consent', function () { - const bidRequest = { - ...commonBidRequest, - ...nativeBidRequestParams, - } - config.setConfig({ coppa: true }) - - const res = spec.buildRequests([bidRequest], commonBidderRequest) - const resData = JSON.parse(res.data) - expect(resData.regs.coppa).to.equal(1) - - config.resetConfig() - }); - - it('should pass gpp information', function () { - const bidRequest = { - ...commonBidRequest, - ...nativeBidRequestParams, - }; - const bidderRequest = { - ...commonBidderRequest, - 'gppConsent': { - 'gppString': 'abc12345', - 'applicableSections': [8] - } - } - - const res = spec.buildRequests([bidRequest], bidderRequest); - const resData = JSON.parse(res.data); - - expect(resData.regs.ext.gpp).to.exist; - expect(resData.regs.ext.gpp_sid).to.exist; - expect(resData.regs.ext.gpp).to.equal('abc12345'); - expect(resData.regs.ext.gpp_sid).to.deep.equal([8]); - }); - - it('should pass extended ids', function () { - const bidRequest = { - bidId: 'bidId', - params: {}, - userIdAsEids: [ - { source: 'liveramp.com', uids: [{ id: 'id-value', atype: 3 }] } - ], - ...commonBidRequest, - }; - - const res = spec.buildRequests([bidRequest], commonBidderRequest); - const resData = JSON.parse(res.data) - expect(resData.user.ext.eids).to.deep.equal([ - { source: 'liveramp.com', uids: [{ id: 'id-value', atype: 3 }] } - ]); - }); - - it('should pass OB user token', function () { - getDataFromLocalStorageStub.returns('12345'); - - const bidRequest = { - bidId: 'bidId', - params: {}, - ...commonBidRequest, - }; - - const res = spec.buildRequests([bidRequest], commonBidderRequest); - const resData = JSON.parse(res.data) - expect(resData.user.ext.obusertoken).to.equal('12345') - expect(getDataFromLocalStorageStub.called).to.be.true; - sinon.assert.calledWith(getDataFromLocalStorageStub, 'OB-USER-TOKEN'); - }); - - it('should pass bidfloor', function () { - const bidRequest = { - ...commonBidRequest, - ...nativeBidRequestParams, - } - bidRequest.getFloor = function () { - return { - currency: 'USD', - floor: 1.23, - } - } - - const res = spec.buildRequests([bidRequest], commonBidderRequest) - const resData = JSON.parse(res.data) - expect(resData.imp[0].bidfloor).to.equal(1.23) - }); - - it('should transform string sizes to numbers', function () { - const bidRequest = { - bidId: 'bidId', - params: {}, - ...commonBidRequest, - ...nativeBidRequestParams, - }; - bidRequest.nativeParams.image.sizes = ['120', '100'] - - const expectedNativeAssets = { - assets: [ - { - required: 1, - id: 3, - img: { - type: 3, - w: 120, - h: 100 - } - }, - { - required: 1, - id: 0, - title: {} - }, - { - required: 0, - id: 5, - data: { - type: 1 - } - } - ] - } - - const res = spec.buildRequests([bidRequest], commonBidderRequest); - const resData = JSON.parse(res.data) - expect(resData.imp[0].native.request).to.equal(JSON.stringify(expectedNativeAssets)); - }); - - it('should pass ortb2 device data', function () { - const bidRequest = { - ...commonBidRequest, - ...nativeBidRequestParams, - }; - - const res = spec.buildRequests( - [bidRequest], - {...commonBidderRequest, ...ortb2WithDeviceData}, - ); - expect(JSON.parse(res.data).device).to.deep.equal(ortb2WithDeviceData.ortb2.device); - }); - }) - - describe('interpretResponse', function () { - it('should return empty array if no valid bids', function () { - const res = spec.interpretResponse({}, []) - expect(res).to.be.an('array').that.is.empty - }); - - it('should interpret native response', function () { - const serverResponse = { - body: { - id: '0a73e68c-9967-4391-b01b-dda2d9fc54e4', - seatbid: [ - { - bid: [ - { - id: '82822cf5-259c-11eb-8a52-f29e5275aa57', - impid: '1', - price: 1.1, - nurl: 'http://example.com/win/${AUCTION_PRICE}', - adm: '{"ver":"1.2","assets":[{"id":3,"required":1,"img":{"url":"http://example.com/img/url","w":120,"h":100}},{"id":0,"required":1,"title":{"text":"Test title"}},{"id":5,"data":{"value":"Test sponsor"}}],"privacy":"http://example.com/privacy","link":{"url":"http://example.com/click/url"},"eventtrackers":[{"event":1,"method":1,"url":"http://example.com/impression"}]}', - adomain: [ - 'example.com' - ], - cid: '3487171', - crid: '28023739', - cat: [ - 'IAB10-2' - ] - } - ], - seat: 'acc-5537' - } - ], - bidid: '82822cf5-259c-11eb-8a52-b48e7518c657', - cur: 'USD' - }, - } - const request = { - bids: [ - { - ...commonBidRequest, - ...nativeBidRequestParams, - } - ] - } - const expectedRes = [ - { - requestId: request.bids[0].bidId, - cpm: 1.1, - creativeId: '28023739', - ttl: 360, - netRevenue: true, - currency: 'USD', - mediaType: 'native', - nurl: 'http://example.com/win/${AUCTION_PRICE}', - meta: { - 'advertiserDomains': [ - 'example.com' - ] - }, - native: { - clickTrackers: undefined, - clickUrl: 'http://example.com/click/url', - image: { - url: 'http://example.com/img/url', - width: 120, - height: 100 - }, - title: 'Test title', - sponsoredBy: 'Test sponsor', - impressionTrackers: [ - 'http://example.com/impression', - ], - privacyLink: 'http://example.com/privacy' - } - } - ] - - const res = spec.interpretResponse(serverResponse, request) - expect(res).to.deep.equal(expectedRes) - }); - - it('should interpret display response', function () { - const serverResponse = { - body: { - id: '6b2eedc8-8ff5-46ef-adcf-e701b508943e', - seatbid: [ - { - bid: [ - { - id: 'd90fe7fa-28d7-11eb-8ce4-462a842a7cf9', - impid: '1', - price: 1.1, - nurl: 'http://example.com/win/${AUCTION_PRICE}', - adm: '
ad
', - adomain: [ - 'example.com' - ], - cid: '3865084', - crid: '29998660', - cat: [ - 'IAB10-2' - ], - w: 300, - h: 250 - } - ], - seat: 'acc-6536' - } - ], - bidid: 'd90fe7fa-28d7-11eb-8ce4-13d94bfa26f9', - cur: 'USD' - } - } - const request = { - bids: [ - { - ...commonBidRequest, - ...displayBidRequestParams - } - ] - } - const expectedRes = [ - { - requestId: request.bids[0].bidId, - cpm: 1.1, - creativeId: '29998660', - ttl: 360, - netRevenue: true, - currency: 'USD', - mediaType: 'banner', - nurl: 'http://example.com/win/${AUCTION_PRICE}', - ad: '
ad
', - width: 300, - height: 250, - meta: { - 'advertiserDomains': [ - 'example.com' - ] - }, - } - ] - - const res = spec.interpretResponse(serverResponse, request) - expect(res).to.deep.equal(expectedRes) - }); - - it('should interpret video response', function () { - const serverResponse = { - body: { - id: '123', - seatbid: [ - { - bid: [ - { - id: '111', - impid: '1', - price: 1.1, - adm: '\u003cVAST version="3.0"\u003e\u003cAd\u003e\u003cInLine\u003e\u003cAdSystem\u003ezemanta\u003c/AdSystem\u003e\u003cAdTitle\u003e1\u003c/AdTitle\u003e\u003cImpression\u003ehttp://win.com\u003c/Impression\u003e\u003cImpression\u003ehttp://example.com/imptracker\u003c/Impression\u003e\u003cCreatives\u003e\u003cCreative\u003e\u003cLinear\u003e\u003cDuration\u003e00:00:25\u003c/Duration\u003e\u003cTrackingEvents\u003e\u003cTracking event="start"\u003ehttp://example.com/start\u003c/Tracking\u003e\u003cTracking event="progress" offset="00:00:03"\u003ehttp://example.com/p3s\u003c/Tracking\u003e\u003c/TrackingEvents\u003e\u003cVideoClicks\u003e\u003cClickThrough\u003ehttp://link.com\u003c/ClickThrough\u003e\u003c/VideoClicks\u003e\u003cMediaFiles\u003e\u003cMediaFile delivery="progressive" type="video/mp4" bitrate="700" width="640" height="360"\u003ehttps://example.com/123_360p.mp4\u003c/MediaFile\u003e\u003c/MediaFiles\u003e\u003c/Linear\u003e\u003c/Creative\u003e\u003c/Creatives\u003e\u003c/InLine\u003e\u003c/Ad\u003e\u003c/VAST\u003e', - adid: '100', - cid: '5', - crid: '29998660', - cat: ['cat-1'], - adomain: [ - 'example.com' - ], - nurl: 'http://example.com/win/${AUCTION_PRICE}' - } - ], - seat: '100', - group: 1 - } - ], - bidid: '456', - cur: 'USD' - } - } - const request = { - bids: [ - { - ...commonBidRequest, - ...videoBidRequestParams - } - ] - } - const expectedRes = [ - { - requestId: request.bids[0].bidId, - cpm: 1.1, - creativeId: '29998660', - ttl: 360, - netRevenue: true, - currency: 'USD', - mediaType: 'video', - nurl: 'http://example.com/win/${AUCTION_PRICE}', - vastXml: 'zemanta1http://win.comhttp://example.com/imptracker00:00:25http://example.com/starthttp://example.com/p3shttp://link.comhttps://example.com/123_360p.mp4', - meta: { - 'advertiserDomains': [ - 'example.com' - ] - }, - } - ] - - const res = spec.interpretResponse(serverResponse, request) - expect(res).to.deep.equal(expectedRes) - }); - }) - }) - - describe('getUserSyncs', function () { - const usersyncUrl = 'https://usersync-url.com'; - beforeEach(() => { - config.setConfig({ - outbrain: { - usersyncUrl: usersyncUrl, - } - } - ) - }) - after(() => { - config.resetConfig() - }) - - it('should return user sync if pixel enabled with outbrain config', function () { - const ret = spec.getUserSyncs({ pixelEnabled: true }) - expect(ret).to.deep.equal([{ type: 'image', url: usersyncUrl }]) - }) - - it('should not return user sync if pixel disabled', function () { - const ret = spec.getUserSyncs({ pixelEnabled: false }) - expect(ret).to.be.an('array').that.is.empty - }) - - it('should not return user sync if url is not set', function () { - config.resetConfig() - const ret = spec.getUserSyncs({ pixelEnabled: true }) - expect(ret).to.be.an('array').that.is.empty - }) - - it('should pass GDPR consent', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, { gdprApplies: true, consentString: 'foo' }, undefined)).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?gdpr=1&gdpr_consent=foo` - }]); - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, { gdprApplies: false, consentString: 'foo' }, undefined)).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?gdpr=0&gdpr_consent=foo` - }]); - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, { gdprApplies: true, consentString: undefined }, undefined)).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?gdpr=1&gdpr_consent=` - }]); - }); - - it('should pass US consent', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, undefined, '1NYN')).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?us_privacy=1NYN` - }]); - }); - - it('should pass GDPR and US consent', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, { gdprApplies: true, consentString: 'foo' }, '1NYN')).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?gdpr=1&gdpr_consent=foo&us_privacy=1NYN` - }]); - }); - - it('should pass gpp consent', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, {}, undefined, '', { gppString: 'abc12345', applicableSections: [1, 2] })).to.deep.equal([{ - type: 'image', url: `${usersyncUrl}?gpp=abc12345&gpp_sid=1%2C2` - }]); - }); - }) - - describe('onBidWon', function () { - it('should make an ajax call with the original cpm', function () { - const bid = { - nurl: 'http://example.com/win/${AUCTION_PRICE}', - cpm: 2.1, - originalCpm: 1.1, - } - spec.onBidWon(bid) - expect(server.requests[0].url).to.equals('http://example.com/win/1.1') - }); - }) -}) diff --git a/test/spec/modules/overtoneRtdProvider_spec.mjs b/test/spec/modules/overtoneRtdProvider_spec.mjs deleted file mode 100644 index d1c37d3fb..000000000 --- a/test/spec/modules/overtoneRtdProvider_spec.mjs +++ /dev/null @@ -1,76 +0,0 @@ -import { expect } from 'chai'; -import sinon from 'sinon'; -import { overtoneModule, overtoneRtdProvider } from '../../../modules/overtoneRtdProvider.js'; -import { logMessage } from '../../../src/utils.js'; - -const TEST_URLS = { - success: 'https://www.theguardian.com/film/2024/nov/15/duncan-cowles-silent-men-interview', - fail: 'https://www.nytimes.com', - ignore: 'https://wsj.com', -}; - -describe('Overtone RTD Submodule with Test URLs', function () { - let fetchContextDataStub; - let getBidRequestDataStub; - - beforeEach(function () { - fetchContextDataStub = sinon.stub(overtoneModule, 'fetchContextData').callsFake(async (url) => { - if (url === TEST_URLS.success) { - return { categories: ['ovtn_004', 'ovtn_104', 'ovtn_309', 'ovtn_202'], status: 1 }; - } - if (url === TEST_URLS.fail) { - return { categories: [], status: 3 }; - } - if (url === TEST_URLS.ignore) { - return { categories: [], status: 4 }; - } - throw new Error('Unexpected URL in test'); - }); - - getBidRequestDataStub = sinon.stub(overtoneRtdProvider, 'getBidRequestData').callsFake((config, callback) => { - if (config.shouldFail) { - return; - } - callback(); - }); - }); - - afterEach(function () { - fetchContextDataStub.restore(); - getBidRequestDataStub.restore(); - }); - - it('should fetch and return categories for the success URL', async function () { - const data = await overtoneModule.fetchContextData(TEST_URLS.success); - logMessage(data); - expect(data).to.deep.equal({ - categories: ['ovtn_004', 'ovtn_104', 'ovtn_309', 'ovtn_202'], - status: 1, - }); - }); - - it('should return the expected structure for the fail URL', async function () { - const data = await overtoneModule.fetchContextData(TEST_URLS.fail); - expect(data).to.deep.equal({ - categories: [], - status: 3, - }); - }); - - it('should return the expected structure for the ignore URL', async function () { - const data = await overtoneModule.fetchContextData(TEST_URLS.ignore); - expect(data).to.deep.equal({ - categories: [], - status: 4, - }); - }); - - describe('getBidRequestData', function () { - it('should not call callback if config has shouldFail set to true', function () { - const bidReqConfig = { shouldFail: true, ortb2Fragments: { global: { site: { ext: {} } } } }; - const callbackSpy = sinon.spy(); - overtoneRtdProvider.getBidRequestData(bidReqConfig, callbackSpy); - sinon.assert.notCalled(callbackSpy); - }); - }); -}); diff --git a/test/spec/modules/ownadxBidAdapter_spec.js b/test/spec/modules/ownadxBidAdapter_spec.js deleted file mode 100644 index 0bb19af3a..000000000 --- a/test/spec/modules/ownadxBidAdapter_spec.js +++ /dev/null @@ -1,103 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/ownadxBidAdapter.js'; - -describe('ownadx', function () { - const METHOD = 'POST'; - const URL = 'https://pbs-js.prebid-ownadx.com/publisher/prebid/9/1231?token=3f2941af4f7e446f9a19ca6045f8cff4'; - - const bidRequest = { - bidder: 'ownadx', - params: { - tokenId: '3f2941af4f7e446f9a19ca6045f8cff4', - sspId: '1231', - seatId: '9' - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - sizes: [ - [300, 250], - [300, 600] - ], - bidId: 'bid-id-123456', - adUnitCode: 'ad-unit-code-1', - bidderRequestId: 'bidder-request-id-123456', - auctionId: 'auction-id-123456', - transactionId: 'transaction-id-123456' - }; - - describe('isBidRequestValid', function () { - it('should return true where required params found', function () { - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - }); - - describe('buildRequests', function () { - const bidderRequest = { - refererInfo: { - page: 'https://www.test.com', - reachedTop: true, - isAmp: false, - numIframes: 0, - stack: [ - 'https://www.test.com' - ], - canonicalUrl: null - } - }; - - it('should build correct POST request for banner bid', function () { - const request = spec.buildRequests([bidRequest], bidderRequest)[0]; - expect(request).to.be.an('object'); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://pbs-js.prebid-ownadx.com/publisher/prebid/9/1231?token=3f2941af4f7e446f9a19ca6045f8cff4'); - const payload = request.data; - expect(payload).to.be.an('object'); - expect(payload.sizes).to.be.an('array'); - expect(payload.slotBidId).to.be.a('string'); - expect(payload.PageUrl).to.be.a('string'); - expect(payload.mediaChannel).to.be.a('number'); - }); - }); - - describe('interpretResponse', function () { - const serverResponse = { - body: { - tokenId: '3f2941af4f7e446f9a19ca6045f8cff4', - bid: 'BID-XXXX-XXXX', - width: '300', - height: '250', - cpm: '0.7', - adm: '

Ad from OwnAdX

', - slotBidId: 'bid-id-123456', - adType: '1', - statusText: 'Success' - } - }; - - const expectedResponse = [{ - token: '3f2941af4f7e446f9a19ca6045f8cff4', - requestId: 'bid-id-123456', - cpm: '0.7', - currency: 'USD', - aType: '1', - netRevenue: false, - width: '300', - height: '250', - creativeId: 0, - ttl: 300, - ad: '

Ad from OwnAdX

', - meta: { - mediaType: 'banner', - advertiserDomains: [] - } - }]; - - it('should correctly interpret valid banner response', function () { - const result = spec.interpretResponse(serverResponse); - expect(result).to.deep.equal(expectedResponse); - }); - }); -}); diff --git a/test/spec/modules/oxxionAnalyticsAdapter_spec.js b/test/spec/modules/oxxionAnalyticsAdapter_spec.js deleted file mode 100644 index da8c3f698..000000000 --- a/test/spec/modules/oxxionAnalyticsAdapter_spec.js +++ /dev/null @@ -1,349 +0,0 @@ -import oxxionAnalytics, {dereferenceWithoutRenderer} from 'modules/oxxionAnalyticsAdapter.js'; - -import { expect } from 'chai'; -import { server } from 'test/mocks/xhr.js'; -import { EVENTS } from 'src/constants.js'; - -const adapterManager = require('src/adapterManager').default; -const events = require('src/events'); -describe('Oxxion Analytics', function () { - const timestamp = new Date() - 256; - const auctionId = '5018eb39-f900-4370-b71e-3bb5b48d324f'; - const timeout = 1500; - - const bidTimeout = [ - { - 'bidId': '5fe418f2d70364', - 'bidder': 'appnexusAst', - 'adUnitCode': 'tag_200124_banner', - 'auctionId': '1e8b993d-8f0a-4232-83eb-3639ddf3a44b' - } - ]; - - const auctionEnd = { - 'auctionId': '1e8b993d-8f0a-4232-83eb-3639ddf3a44b', - 'timestamp': 1647424261187, - 'auctionEnd': 1647424261714, - 'auctionStatus': 'completed', - 'adUnits': [ - { - 'code': 'tag_200124_banner', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 600 - ] - ] - } - }, - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 123456 - } - }, - { - 'bidder': 'appnexusAst', - 'params': { - 'placementId': 234567 - } - } - ], - 'sizes': [ - [ - 300, - 600 - ] - ], - 'transactionId': 'de664ccb-e18b-4436-aeb0-362382eb1b40' - } - ], - 'adUnitCodes': [ - 'tag_200124_banner' - ], - 'bidderRequests': [ - { - 'bidderCode': 'appnexus', - 'auctionId': '1e8b993d-8f0a-4232-83eb-3639ddf3a44b', - 'bidderRequestId': '11dc6ff6378de7', - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 123456 - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'tag_200124_banner', - 'transactionId': '8b2a8629-d1ea-4bb1-aff0-e335b96dd002', - 'sizes': [ - [ - 300, - 600 - ] - ], - 'bidId': '2bd3e8ff8a113f', - 'bidderRequestId': '11dc6ff6378de7', - 'auctionId': '1e8b993d-8f0a-4232-83eb-3639ddf3a44b', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ova': 'cleared' - } - ], - 'auctionStart': 1647424261187, - 'timeout': 1000, - 'gdprConsent': { - 'consentString': 'CONSENT', - 'gdprApplies': true, - 'apiVersion': 2, - 'vendorData': 'a lot of borring stuff', - }, - 'start': 1647424261189 - }, - ], - 'noBids': [ - { - 'bidder': 'appnexusAst', - 'params': { - 'placementId': 10471298 - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'tag_200124_banner', - 'transactionId': 'de664ccb-e18b-4436-aeb0-362382eb1b40', - 'sizes': [ - [ - 300, - 600 - ] - ], - 'bidId': '5fe418f2d70364', - 'bidderRequestId': '4229a45ab8ea87', - 'auctionId': '1e8b993d-8f0a-4232-83eb-3639ddf3a44b', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'bidsReceived': [ - { - 'bidderCode': 'appnexus', - 'width': 970, - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '65d16ef039a97a', - 'requestId': '2bd3e8ff8a113f', - 'transactionId': '8b2a8629-d1ea-4bb1-aff0-e335b96dd002', - 'auctionId': '1e8b993d-8f0a-4232-83eb-3639ddf3a44b', - 'mediaType': 'video', - 'source': 'client', - 'cpm': 27.4276, - 'creativeId': '158534630', - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 2000, - 'ad': 'some html', - 'meta': { - 'advertiserDomains': [ - 'example.com' - ], - 'demandSource': 'something' - }, - 'renderer': 'something', - 'originalCpm': 25.02521, - 'originalCurrency': 'EUR', - 'responseTimestamp': 1647424261559, - 'requestTimestamp': 1647424261189, - 'bidder': 'appnexus', - 'adUnitCode': 'tag_200124_banner', - 'timeToRespond': 370, - 'pbLg': '5.00', - 'pbMg': '20.00', - 'pbHg': '20.00', - 'pbAg': '20.00', - 'pbDg': '20.00', - 'pbCg': '20.000000', - 'size': '300x600', - 'adserverTargeting': { - 'hb_bidder': 'appnexus', - 'hb_adid': '65d16ef039a97a', - 'hb_pb': '20.000000', - 'hb_size': '300x600', - 'hb_source': 'client', - 'hb_format': 'banner', - 'hb_adomain': 'example.com' - } - } - ], - 'winningBids': [ - - ], - 'timeout': 1000 - }; - - const bidWon = { - 'bidderCode': 'appnexus', - 'width': 970, - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '65d16ef039a97a', - 'requestId': '2bd3e8ff8a113f', - 'transactionId': '8b2a8629-d1ea-4bb1-aff0-e335b96dd002', - 'auctionId': '1e8b993d-8f0a-4232-83eb-3639ddf3a44b', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 27.4276, - 'creativeId': '158533702', - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 2000, - 'ad': 'some html', - 'meta': { - 'advertiserDomains': [ - 'example.com' - ] - }, - 'renderer': 'something', - 'originalCpm': 25.02521, - 'originalCurrency': 'EUR', - 'responseTimestamp': 1647424261558, - 'requestTimestamp': 1647424261189, - 'bidder': 'appnexus', - 'adUnitCode': 'tag_200123_banner', - 'timeToRespond': 369, - 'originalBidder': 'appnexus', - 'pbLg': '5.00', - 'pbMg': '20.00', - 'pbHg': '20.00', - 'pbAg': '20.00', - 'pbDg': '20.00', - 'pbCg': '20.000000', - 'size': '970x250', - 'adserverTargeting': { - 'hb_bidder': 'appnexus', - 'hb_adid': '65d16ef039a97a', - 'hb_pb': '20.000000', - 'hb_size': '970x250', - 'hb_source': 'client', - 'hb_format': 'banner', - 'hb_adomain': 'example.com' - }, - 'status': 'rendered', - 'params': [ - { - 'placementId': 123456 - } - ] - }; - - after(function () { - oxxionAnalytics.disableAnalytics(); - }); - - describe('main test flow', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - sinon.spy(oxxionAnalytics, 'track'); - }); - afterEach(function () { - events.getEvents.restore(); - oxxionAnalytics.disableAnalytics(); - oxxionAnalytics.track.restore(); - }); - it('test dereferenceWithoutRenderer', function () { - adapterManager.registerAnalyticsAdapter({ - code: 'oxxion', - adapter: oxxionAnalytics - }); - - adapterManager.enableAnalytics({ - provider: 'oxxion', - options: { - domain: 'test' - } - }); - const resultBidWon = JSON.parse(dereferenceWithoutRenderer(bidWon)); - expect(resultBidWon).not.to.have.property('renderer'); - const resultBid = JSON.parse(dereferenceWithoutRenderer(auctionEnd)); - expect(resultBid).to.have.property('bidsReceived').and.to.have.lengthOf(1); - expect(resultBid.bidsReceived[0]).not.to.have.property('renderer'); - }); - it('test auctionEnd', function () { - adapterManager.registerAnalyticsAdapter({ - code: 'oxxion', - adapter: oxxionAnalytics - }); - - adapterManager.enableAnalytics({ - provider: 'oxxion', - options: { - domain: 'test' - } - }); - - events.emit(EVENTS.BID_REQUESTED, auctionEnd['bidderRequests'][0]); - events.emit(EVENTS.BID_RESPONSE, auctionEnd['bidsReceived'][0]); - events.emit(EVENTS.BID_TIMEOUT, bidTimeout); - events.emit(EVENTS.AUCTION_END, auctionEnd); - expect(server.requests.length).to.equal(1); - const message = JSON.parse(server.requests[0].requestBody); - expect(message).to.have.property('auctionEnd').exist; - expect(message.auctionEnd).to.have.lengthOf(1); - expect(message.auctionEnd[0]).to.have.property('bidsReceived').and.to.have.lengthOf(1); - expect(message.auctionEnd[0].bidsReceived[0]).not.to.have.property('ad'); - expect(message.auctionEnd[0].bidsReceived[0]).to.have.property('meta'); - expect(message.auctionEnd[0].bidsReceived[0].meta).to.have.property('advertiserDomains'); - expect(message.auctionEnd[0].bidsReceived[0].meta).to.have.property('demandSource'); - expect(message.auctionEnd[0].bidsReceived[0]).to.have.property('adId'); - expect(message.auctionEnd[0]).to.have.property('bidderRequests').and.to.have.lengthOf(1); - expect(message.auctionEnd[0].bidderRequests[0]).to.have.property('gdprConsent'); - expect(message.auctionEnd[0].bidderRequests[0].gdprConsent).not.to.have.property('vendorData'); - expect(message.auctionEnd[0].bidderRequests[0]).to.have.property('oxxionMode'); - }); - - it('test bidWon', function() { - window.OXXION_MODE = {'abtest': true}; - adapterManager.registerAnalyticsAdapter({ - code: 'oxxion', - adapter: oxxionAnalytics - }); - - adapterManager.enableAnalytics({ - provider: 'oxxion', - options: { - domain: 'test' - } - }); - events.emit(EVENTS.BID_WON, bidWon); - expect(server.requests.length).to.equal(1); - const message = JSON.parse(server.requests[0].requestBody); - expect(message).not.to.have.property('ad'); - expect(message).to.have.property('adId') - expect(message).to.have.property('cpmIncrement').and.to.equal(27.4276); - expect(message).to.have.property('oxxionMode').and.to.have.property('abtest').and.to.equal(true); - expect(message).to.have.property('ova').and.to.equal('cleared'); - }); - }); -}); diff --git a/test/spec/modules/oxxionRtdProvider_spec.js b/test/spec/modules/oxxionRtdProvider_spec.js deleted file mode 100644 index f5d2606e8..000000000 --- a/test/spec/modules/oxxionRtdProvider_spec.js +++ /dev/null @@ -1,160 +0,0 @@ -import {oxxionSubmodule} from 'modules/oxxionRtdProvider.js'; -import 'src/prebid.js'; - -const utils = require('src/utils.js'); - -const moduleConfig = { - params: { - domain: 'test.endpoint', - contexts: ['instream', 'outstream'], - samplingRate: 10, - threshold: false, - bidders: ['appnexus', 'mediasquare'], - } -}; - -const request = { - 'auctionId': '1e8b993d-8f0a-4232-83eb-3639ddf3a44b', - 'timestamp': 1647424261187, - 'auctionEnd': 1647424261714, - 'auctionStatus': 'completed', - 'adUnits': [ - { - 'code': 'msq_tag_200124_banner', - 'mediaTypes': { 'banner': { 'sizes': [[300, 600]] } }, - 'bids': [{'bidder': 'appnexus', 'params': {'placementId': 123456}}], - 'transactionId': 'de664ccb-e18b-4436-aeb0-362382eb1b40' - }, - { - 'code': 'msq_tag_200125_video', - 'mediaTypes': { 'video': { 'context': 'instream' }, playerSize: [640, 480], mimes: ['video/mp4'] }, - 'bids': [ - {'bidder': 'mediasquare', 'params': {'code': 'publishername_atf_desktop_rg_video', 'owner': 'test'}}, - {'bidder': 'appnexusAst', 'params': {'placementId': 345678}}, - ], - 'transactionId': 'de664ccb-e18b-4436-aeb0-362382eb1b41' - }, - { - 'code': 'msq_tag_200125_banner', - 'mediaTypes': { 'banner': { 'sizes': [[300, 250]] } }, - 'bids': [ - {'bidder': 'appnexusAst', 'params': {'placementId': 345678}}, - ], - 'transactionId': 'de664ccb-e18b-4436-aeb0-362382eb1b41' - } - ] -}; - -const bids = [{ - 'bidderCode': 'mediasquare', - 'width': 640, - 'height': 480, - 'statusMessage': 'Bid available', - 'adId': '3647626fdbe68a', - 'requestId': '2d891705d2125b', - 'transactionId': 'de664ccb-e18b-4436-aeb0-362382eb1b41', - 'auctionId': '1e8b993d-8f0a-4232-83eb-3639ddf3a44b', - 'mediaType': 'video', - 'source': 'client', - 'cpm': 0.9723, - 'creativeId': 'freewheel|AdswizzAd71819', - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 2000, - 'mediasquare': { - 'bidder': 'freewheel', - 'code': 'test/publishername_atf_desktop_rg_video', - 'hasConsent': true - }, - 'meta': { - 'advertiserDomains': [ - 'unknown' - ] - }, - 'vastUrl': 'https://some.vast-url.com', - 'vastXml': '', - 'adapterCode': 'mediasquare', - 'originalCpm': 0.9723, - 'originalCurrency': 'USD', - 'responseTimestamp': 1665505150740, - 'requestTimestamp': 1665505150594, - 'bidder': 'mediasquare', - 'adUnitCode': 'msq_tag_200125_video', - 'timeToRespond': 146, - 'size': '640x480', -}, { - 'bidderCode': 'appnexusAst', - 'width': 640, - 'height': 480, - 'statusMessage': 'Bid available', - 'adId': '4b2e1581c0ca1a', - 'requestId': '2d891705d2125b', - 'transactionId': 'de664ccb-e18b-4436-aeb0-362382eb1b41', - 'auctionId': '1e8b993d-8f0a-4232-83eb-3639ddf3a44b', - 'mediaType': 'video', - 'source': 'client', - 'cpm': 1.9723, - 'creativeId': '159080650', - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 2000, - 'vastUrl': 'https://some.vast-url.com', - 'vastXml': 'AdnxsTitle', - 'adapterCode': 'mediasquare', - 'originalCpm': 1.9723, - 'originalCurrency': 'USD', - 'responseTimestamp': 1665505150740, - 'requestTimestamp': 1665505150594, - 'bidder': 'appnexusAst', - 'adUnitCode': 'msq_tag_200125_video', - 'timeToRespond': 146, - 'size': '640x480', - 'vastImpUrl': 'https://some.tracking-url.com' -}, -]; - -const bidInterests = [ - {'id': 0, 'rate': 50.0, 'suggestion': true}, - {'id': 1, 'rate': 12.0, 'suggestion': false}, - {'id': 2, 'rate': 0.0, 'suggestion': true}, - {'id': 3, 'rate': 0.0, 'suggestion': false}, -]; - -const userConsent = { - 'gdpr': { - 'consentString': 'consent_hash' - }, - 'usp': null, - 'gpp': null, - 'coppa': false -}; - -describe('oxxionRtdProvider', () => { - describe('Oxxion RTD sub module', () => { - it('should init, return true, and set the params', () => { - expect(oxxionSubmodule.init(moduleConfig)).to.equal(true); - }); - }); - - describe('Oxxion RTD sub module', () => { - const auctionEnd = request; - auctionEnd.bidsReceived = bids; - it('call everything', function() { - oxxionSubmodule.getBidRequestData(request, null, moduleConfig); - }); - it('check bid filtering', function() { - const requestsList = oxxionSubmodule.getRequestsList(request); - expect(requestsList.length).to.equal(4); - expect(requestsList[0]).to.have.property('id'); - expect(request.adUnits[0].bids[0]).to.have.property('_id'); - expect(requestsList[0].id).to.equal(request.adUnits[0].bids[0]._id); - const [filteredBiddderRequests, filteredBids] = oxxionSubmodule.getFilteredAdUnitsOnBidRates(bidInterests, request.adUnits, moduleConfig.params, false); - expect(filteredBids.length).to.equal(1); - expect(filteredBiddderRequests.length).to.equal(3); - expect(filteredBiddderRequests[0]).to.have.property('bids'); - expect(filteredBiddderRequests[0].bids.length).to.equal(1); - expect(filteredBiddderRequests[1]).to.have.property('bids'); - expect(filteredBiddderRequests[1].bids.length).to.equal(1); - }); - }); -}); diff --git a/test/spec/modules/ozoneBidAdapter_spec.js b/test/spec/modules/ozoneBidAdapter_spec.js deleted file mode 100644 index e063e7702..000000000 --- a/test/spec/modules/ozoneBidAdapter_spec.js +++ /dev/null @@ -1,3717 +0,0 @@ -import { expect } from 'chai'; -import { spec, getWidthAndHeightFromVideoObject, defaultSize } from 'modules/ozoneBidAdapter.js'; -import { config } from 'src/config.js'; -import {Renderer} from '../../../src/Renderer.js'; -import * as utils from '../../../src/utils.js'; -import {deepSetValue} from '../../../src/utils.js'; -const OZONEURI = 'https://elb.the-ozone-project.com/openrtb2/auction'; -const BIDDER_CODE = 'ozone'; -spec.getGetParametersAsObject = function() { - return { - page: 'https://www.ozoneproject.com/sometestPage/?qsParam1=123', - location: 'https://www.ozoneproject.com/sometestPage/?qsParam1=123' - }; -} -var validBidRequests = [ - { - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - bidId: '2899ec066a91ff8', - bidRequestsCount: 1, - bidder: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - crumbs: {pubcid: '203a0692-f728-4856-87f6-9a25a6b63715'}, - params: { publisherId: '9876abcd12-3', customData: [{'settings': {}, 'targeting': {'gender': 'bart', 'age': 'low'}}], placementId: '1310000099', siteId: '1234567890', id: 'fea37168-78f1-4a23-a40e-88437a99377e', auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', imp: [ { id: '2899ec066a91ff8', tagid: 'undefined', secure: 1, banner: { format: [{ w: 300, h: 250 }, { w: 300, h: 600 }], h: 250, topframe: 1, w: 300 } } ] }, - sizes: [[300, 250], [300, 600]], - transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' - } -]; -var validBidRequestsNoCustomData = [ - { - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - bidId: '2899ec066a91ff8', - bidRequestsCount: 1, - bidder: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - crumbs: {pubcid: '203a0692-f728-4856-87f6-9a25a6b63715'}, - params: { publisherId: '9876abcd12-3', placementId: '1310000099', siteId: '1234567890', id: 'fea37168-78f1-4a23-a40e-88437a99377e', auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', imp: [ { id: '2899ec066a91ff8', tagid: 'undefined', secure: 1, banner: { format: [{ w: 300, h: 250 }, { w: 300, h: 600 }], h: 250, topframe: 1, w: 300 } } ] }, - sizes: [[300, 250], [300, 600]], - transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' - } -]; -var validBidRequestsMulti = [ - { - testId: 1, - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - bidId: '2899ec066a91ff8', - bidRequestsCount: 1, - bidder: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - crumbs: {pubcid: '203a0692-f728-4856-87f6-9a25a6b63715'}, - params: { publisherId: '9876abcd12-3', customData: [{'settings': {}, 'targeting': {'gender': 'bart', 'age': 'low'}}], placementId: '1310000099', siteId: '1234567890', id: 'fea37168-78f1-4a23-a40e-88437a99377e', auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', imp: [ { id: '2899ec066a91ff8', tagid: 'undefined', secure: 1, banner: { format: [{ w: 300, h: 250 }, { w: 300, h: 600 }], h: 250, topframe: 1, w: 300 } } ] }, - sizes: [[300, 250], [300, 600]], - transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' - }, - { - testId: 2, - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - bidId: '2899ec066a91ff0', - bidRequestsCount: 1, - bidder: 'ozone', - bidderRequestId: '1c1586b27a1b5c0', - crumbs: {pubcid: '203a0692-f728-4856-87f6-9a25a6b63715'}, - params: { publisherId: '9876abcd12-3', customData: [{'settings': {}, 'targeting': {'gender': 'bart', 'age': 'low'}}], placementId: '1310000099', siteId: '1234567890', id: 'fea37168-78f1-4a23-a40e-88437a99377e', auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', imp: [ { id: '2899ec066a91ff8', tagid: 'undefined', secure: 1, banner: { format: [{ w: 300, h: 250 }, { w: 300, h: 600 }], h: 250, topframe: 1, w: 300 } } ] }, - sizes: [[300, 250], [300, 600]], - transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' - } -]; -var validBidRequestsWithAuctionIdTransactionId = [{ - 'bidder': 'ozone', - 'params': { - 'publisherId': 'OZONENUK0001', - 'siteId': '4204204201', - 'placementId': '8000000330', - 'customData': [ - { - 'settings': {}, - 'targeting': { - 'sens': 'f', - 'pt1': '/uk', - 'pt5': [ - 'uk' - ], - 'pt7': 'desktop', - 'pt9': '|k0xw2vqzp33kklb3j5w4|||' - } - } - ] - }, - 'ortb2Imp': { - 'ext': { - 'gpid': 'mpu_pbadslot_from_adunit', - 'data': { - 'pbadslot': 'mpu_pbadslot_from_adunit', - 'adserver': { - 'name': 'gam', - 'adslot': '/22037345/projectozone' - } - }, - 'tid': 'f0dac8b5-09df-4da7-9d83-c99786d4517a' - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'mpu', - 'transactionId': 'f0dac8b5-09df-4da7-9d83-c99786d4517a', - 'adUnitId': '715b4bdc-515f-488b-8633-333654e72f3f', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '3da18cc31f1dda', - 'bidderRequestId': '263c3b0d970326', - 'auctionId': 'a9c479d0-d9cc-4505-a0a6-5982ce8fb8f0', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'source': { - 'tid': 'a9c479d0-d9cc-4505-a0a6-5982ce8fb8f0' - }, - 'regs': { - 'ext': { - 'gdpr': 1, - 'us_privacy': '1Y--' - } - }, - 'user': { - 'ext': { - 'consent': 'CQAaAwAQAaAwAAKA1AENA5EsAP_gAEPgACiQKRNV_G__bWlr8X73aftkeY1P9_h77sQxBhfJE-4FzLuW_JwXx2ExNA36tqIKmRIEu3bBIQNlHJDUTVCgaogVryDMakWcoTNKJ6BkiFMRO2dYCF5vmwtj-QKY5vr993dx2B-t_dv83dzyz4VHn3a5_2e0WJCdA58tDfv9bROb-9IPd_58v4v8_F_rE2_eT1l_tevp7D9-cts7_XW-9_fff79Ll_-mBwUcALMNCogDLIkJCDQMIIEAKgrCAigQAAAAkDRAQAmDAp2BgEusJEAIAUAAwQAgABRkACAAASABCIAIACgQAAQCBQAAgAACAQAMDAAGACwEAgABAdAhTAggUCwASMyIhTAgCgSCAlsqEEgCBBXCEIs8CCAREwUAAAJABWAAICwWAxJICViQQJcQbQAAEACAQQAVCKTswBBAGbLVXiibRlaQFo-ACjgAAAAA.YAAAAAAAAAAA' - } - }, - 'site': { - 'domain': 'ozoneproject.com', - 'publisher': { - 'domain': 'ozoneproject.com' - }, - 'page': 'https://www.ozoneproject.com/ozone/2.9.4/20240715-test-singlereq-optin.html?pbjs_debug=true' - }, - 'device': { - 'w': 1609, - 'h': 279, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', - 'language': 'en' - } - } -}]; -var valid6BidRequestsWithAuctionIdTransactionId = [{ - 'bidder': 'ozone', - 'params': { - 'publisherId': 'OZONENUK0001', - 'siteId': '4204204201', - 'placementId': '8000000330', - 'customData': [ - { - 'settings': {}, - 'targeting': { - 'sens': 'f', - 'pt1': '/uk', - 'pt5': [ - 'uk' - ], - 'pt7': 'desktop', - 'pt9': '|k0xw2vqzp33kklb3j5w4|||' - } - } - ] - }, - 'ortb2Imp': { - 'ext': { - 'gpid': 'mpu_pbadslot_from_adunit', - 'data': { - 'pbadslot': 'mpu_pbadslot_from_adunit', - 'adserver': { - 'name': 'gam', - 'adslot': '/22037345/projectozone' - } - }, - 'tid': 'f0dac8b5-09df-4da7-9d83-c99786d4517a' - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'mpu', - 'transactionId': 'f0dac8b5-09df-4da7-9d83-c99786d4517a', - 'adUnitId': '715b4bdc-515f-488b-8633-333654e72f3f', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '3da18cc31f1dda', - 'bidderRequestId': '263c3b0d970326', - 'auctionId': 'a9c479d0-d9cc-4505-a0a6-5982ce8fb8f0', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'source': { - 'tid': 'a9c479d0-d9cc-4505-a0a6-5982ce8fb8f0' - }, - 'regs': { - 'ext': { - 'gdpr': 1, - 'us_privacy': '1Y--' - } - }, - 'user': { - 'ext': { - 'consent': 'CQAaAwAQAaAwAAKA1AENA5EsAP_gAEPgACiQKRNV_G__bWlr8X73aftkeY1P9_h77sQxBhfJE-4FzLuW_JwXx2ExNA36tqIKmRIEu3bBIQNlHJDUTVCgaogVryDMakWcoTNKJ6BkiFMRO2dYCF5vmwtj-QKY5vr993dx2B-t_dv83dzyz4VHn3a5_2e0WJCdA58tDfv9bROb-9IPd_58v4v8_F_rE2_eT1l_tevp7D9-cts7_XW-9_fff79Ll_-mBwUcALMNCogDLIkJCDQMIIEAKgrCAigQAAAAkDRAQAmDAp2BgEusJEAIAUAAwQAgABRkACAAASABCIAIACgQAAQCBQAAgAACAQAMDAAGACwEAgABAdAhTAggUCwASMyIhTAgCgSCAlsqEEgCBBXCEIs8CCAREwUAAAJABWAAICwWAxJICViQQJcQbQAAEACAQQAVCKTswBBAGbLVXiibRlaQFo-ACjgAAAAA.YAAAAAAAAAAA' - } - }, - 'site': { - 'domain': 'ozoneproject.com', - 'publisher': { - 'domain': 'ozoneproject.com' - }, - 'page': 'https://www.ozoneproject.com/ozone/2.9.4/20240715-test-singlereq-optin.html?pbjs_debug=true' - }, - 'device': { - 'w': 1609, - 'h': 279, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', - 'language': 'en' - } - } -}, -{ - 'bidder': 'ozone', - 'params': { - 'publisherId': 'OZONENUK0001', - 'siteId': '4204204201', - 'placementId': '8000000330', - 'customData': [ - { - 'settings': {}, - 'targeting': { - 'sens': 'f', - 'pt1': '/uk', - 'pt5': [ - 'uk' - ], - 'pt7': 'desktop', - 'pt9': '|k0xw2vqzp33kklb3j5w4|||' - } - } - ] - }, - 'ortb2Imp': { - 'ext': { - 'gpid': 'mpu_pbadslot_from_adunit', - 'data': { - 'pbadslot': 'mpu_pbadslot_from_adunit', - 'adserver': { - 'name': 'gam', - 'adslot': '/22037345/projectozone' - } - }, - 'tid': 'f0dac8b5-09df-4da7-9d83-c99786d4517a' - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'mpu2', - 'transactionId': 'f0dac8b5-09df-4da7-9d83-c99786d4517a', - 'adUnitId': '715b4bdc-515f-488b-8633-333654e72f3f', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '3da18cc31f1ddb', - 'bidderRequestId': '263c3b0d970326', - 'auctionId': 'a9c479d0-d9cc-4505-a0a6-5982ce8fb8f0', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'source': { - 'tid': 'a9c479d0-d9cc-4505-a0a6-5982ce8fb8f0' - }, - 'regs': { - 'ext': { - 'gdpr': 1, - 'us_privacy': '1Y--' - } - }, - 'user': { - 'ext': { - 'consent': 'CQAaAwAQAaAwAAKA1AENA5EsAP_gAEPgACiQKRNV_G__bWlr8X73aftkeY1P9_h77sQxBhfJE-4FzLuW_JwXx2ExNA36tqIKmRIEu3bBIQNlHJDUTVCgaogVryDMakWcoTNKJ6BkiFMRO2dYCF5vmwtj-QKY5vr993dx2B-t_dv83dzyz4VHn3a5_2e0WJCdA58tDfv9bROb-9IPd_58v4v8_F_rE2_eT1l_tevp7D9-cts7_XW-9_fff79Ll_-mBwUcALMNCogDLIkJCDQMIIEAKgrCAigQAAAAkDRAQAmDAp2BgEusJEAIAUAAwQAgABRkACAAASABCIAIACgQAAQCBQAAgAACAQAMDAAGACwEAgABAdAhTAggUCwASMyIhTAgCgSCAlsqEEgCBBXCEIs8CCAREwUAAAJABWAAICwWAxJICViQQJcQbQAAEACAQQAVCKTswBBAGbLVXiibRlaQFo-ACjgAAAAA.YAAAAAAAAAAA' - } - }, - 'site': { - 'domain': 'ozoneproject.com', - 'publisher': { - 'domain': 'ozoneproject.com' - }, - 'page': 'https://www.ozoneproject.com/ozone/2.9.4/20240715-test-singlereq-optin.html?pbjs_debug=true' - }, - 'device': { - 'w': 1609, - 'h': 279, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', - 'language': 'en' - } - } -}, -{ - 'bidder': 'ozone', - 'params': { - 'publisherId': 'OZONENUK0001', - 'siteId': '4204204201', - 'placementId': '8000000330', - 'customData': [ - { - 'settings': {}, - 'targeting': { - 'sens': 'f', - 'pt1': '/uk', - 'pt5': [ - 'uk' - ], - 'pt7': 'desktop', - 'pt9': '|k0xw2vqzp33kklb3j5w4|||' - } - } - ] - }, - 'ortb2Imp': { - 'ext': { - 'gpid': 'mpu_pbadslot_from_adunit', - 'data': { - 'pbadslot': 'mpu_pbadslot_from_adunit', - 'adserver': { - 'name': 'gam', - 'adslot': '/22037345/projectozone' - } - }, - 'tid': 'f0dac8b5-09df-4da7-9d83-c99786d4517a' - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'mpu3', - 'transactionId': 'f0dac8b5-09df-4da7-9d83-c99786d4517a', - 'adUnitId': '715b4bdc-515f-488b-8633-333654e72f3f', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '3da18cc31f1ddc', - 'bidderRequestId': '263c3b0d970326', - 'auctionId': 'a9c479d0-d9cc-4505-a0a6-5982ce8fb8f0', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'source': { - 'tid': 'a9c479d0-d9cc-4505-a0a6-5982ce8fb8f0' - }, - 'regs': { - 'ext': { - 'gdpr': 1, - 'us_privacy': '1Y--' - } - }, - 'user': { - 'ext': { - 'consent': 'CQAaAwAQAaAwAAKA1AENA5EsAP_gAEPgACiQKRNV_G__bWlr8X73aftkeY1P9_h77sQxBhfJE-4FzLuW_JwXx2ExNA36tqIKmRIEu3bBIQNlHJDUTVCgaogVryDMakWcoTNKJ6BkiFMRO2dYCF5vmwtj-QKY5vr993dx2B-t_dv83dzyz4VHn3a5_2e0WJCdA58tDfv9bROb-9IPd_58v4v8_F_rE2_eT1l_tevp7D9-cts7_XW-9_fff79Ll_-mBwUcALMNCogDLIkJCDQMIIEAKgrCAigQAAAAkDRAQAmDAp2BgEusJEAIAUAAwQAgABRkACAAASABCIAIACgQAAQCBQAAgAACAQAMDAAGACwEAgABAdAhTAggUCwASMyIhTAgCgSCAlsqEEgCBBXCEIs8CCAREwUAAAJABWAAICwWAxJICViQQJcQbQAAEACAQQAVCKTswBBAGbLVXiibRlaQFo-ACjgAAAAA.YAAAAAAAAAAA' - } - }, - 'site': { - 'domain': 'ozoneproject.com', - 'publisher': { - 'domain': 'ozoneproject.com' - }, - 'page': 'https://www.ozoneproject.com/ozone/2.9.4/20240715-test-singlereq-optin.html?pbjs_debug=true' - }, - 'device': { - 'w': 1609, - 'h': 279, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', - 'language': 'en' - } - } -}, -{ - 'bidder': 'ozone', - 'params': { - 'publisherId': 'OZONENUK0001', - 'siteId': '4204204201', - 'placementId': '8000000330', - 'customData': [ - { - 'settings': {}, - 'targeting': { - 'sens': 'f', - 'pt1': '/uk', - 'pt5': [ - 'uk' - ], - 'pt7': 'desktop', - 'pt9': '|k0xw2vqzp33kklb3j5w4|||' - } - } - ] - }, - 'ortb2Imp': { - 'ext': { - 'gpid': 'mpu_pbadslot_from_adunit', - 'data': { - 'pbadslot': 'mpu_pbadslot_from_adunit', - 'adserver': { - 'name': 'gam', - 'adslot': '/22037345/projectozone' - } - }, - 'tid': 'f0dac8b5-09df-4da7-9d83-c99786d4517a' - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'mpu4', - 'transactionId': 'f0dac8b5-09df-4da7-9d83-c99786d4517a', - 'adUnitId': '715b4bdc-515f-488b-8633-333654e72f3f', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '3da18cc31f1ddd', - 'bidderRequestId': '263c3b0d970326', - 'auctionId': 'a9c479d0-d9cc-4505-a0a6-5982ce8fb8f0', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'source': { - 'tid': 'a9c479d0-d9cc-4505-a0a6-5982ce8fb8f0' - }, - 'regs': { - 'ext': { - 'gdpr': 1, - 'us_privacy': '1Y--' - } - }, - 'user': { - 'ext': { - 'consent': 'CQAaAwAQAaAwAAKA1AENA5EsAP_gAEPgACiQKRNV_G__bWlr8X73aftkeY1P9_h77sQxBhfJE-4FzLuW_JwXx2ExNA36tqIKmRIEu3bBIQNlHJDUTVCgaogVryDMakWcoTNKJ6BkiFMRO2dYCF5vmwtj-QKY5vr993dx2B-t_dv83dzyz4VHn3a5_2e0WJCdA58tDfv9bROb-9IPd_58v4v8_F_rE2_eT1l_tevp7D9-cts7_XW-9_fff79Ll_-mBwUcALMNCogDLIkJCDQMIIEAKgrCAigQAAAAkDRAQAmDAp2BgEusJEAIAUAAwQAgABRkACAAASABCIAIACgQAAQCBQAAgAACAQAMDAAGACwEAgABAdAhTAggUCwASMyIhTAgCgSCAlsqEEgCBBXCEIs8CCAREwUAAAJABWAAICwWAxJICViQQJcQbQAAEACAQQAVCKTswBBAGbLVXiibRlaQFo-ACjgAAAAA.YAAAAAAAAAAA' - } - }, - 'site': { - 'domain': 'ozoneproject.com', - 'publisher': { - 'domain': 'ozoneproject.com' - }, - 'page': 'https://www.ozoneproject.com/ozone/2.9.4/20240715-test-singlereq-optin.html?pbjs_debug=true' - }, - 'device': { - 'w': 1609, - 'h': 279, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', - 'language': 'en' - } - } -}, -{ - 'bidder': 'ozone', - 'params': { - 'publisherId': 'OZONENUK0001', - 'siteId': '4204204201', - 'placementId': '8000000330', - 'customData': [ - { - 'settings': {}, - 'targeting': { - 'sens': 'f', - 'pt1': '/uk', - 'pt5': [ - 'uk' - ], - 'pt7': 'desktop', - 'pt9': '|k0xw2vqzp33kklb3j5w4|||' - } - } - ] - }, - 'ortb2Imp': { - 'ext': { - 'gpid': 'mpu_pbadslot_from_adunit', - 'data': { - 'pbadslot': 'mpu_pbadslot_from_adunit', - 'adserver': { - 'name': 'gam', - 'adslot': '/22037345/projectozone' - } - }, - 'tid': 'f0dac8b5-09df-4da7-9d83-c99786d4517a' - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'mpu5', - 'transactionId': 'f0dac8b5-09df-4da7-9d83-c99786d4517a', - 'adUnitId': '715b4bdc-515f-488b-8633-333654e72f3f', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '3da18cc31f1dde', - 'bidderRequestId': '263c3b0d970326', - 'auctionId': 'a9c479d0-d9cc-4505-a0a6-5982ce8fb8f0', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'source': { - 'tid': 'a9c479d0-d9cc-4505-a0a6-5982ce8fb8f0' - }, - 'regs': { - 'ext': { - 'gdpr': 1, - 'us_privacy': '1Y--' - } - }, - 'user': { - 'ext': { - 'consent': 'CQAaAwAQAaAwAAKA1AENA5EsAP_gAEPgACiQKRNV_G__bWlr8X73aftkeY1P9_h77sQxBhfJE-4FzLuW_JwXx2ExNA36tqIKmRIEu3bBIQNlHJDUTVCgaogVryDMakWcoTNKJ6BkiFMRO2dYCF5vmwtj-QKY5vr993dx2B-t_dv83dzyz4VHn3a5_2e0WJCdA58tDfv9bROb-9IPd_58v4v8_F_rE2_eT1l_tevp7D9-cts7_XW-9_fff79Ll_-mBwUcALMNCogDLIkJCDQMIIEAKgrCAigQAAAAkDRAQAmDAp2BgEusJEAIAUAAwQAgABRkACAAASABCIAIACgQAAQCBQAAgAACAQAMDAAGACwEAgABAdAhTAggUCwASMyIhTAgCgSCAlsqEEgCBBXCEIs8CCAREwUAAAJABWAAICwWAxJICViQQJcQbQAAEACAQQAVCKTswBBAGbLVXiibRlaQFo-ACjgAAAAA.YAAAAAAAAAAA' - } - }, - 'site': { - 'domain': 'ozoneproject.com', - 'publisher': { - 'domain': 'ozoneproject.com' - }, - 'page': 'https://www.ozoneproject.com/ozone/2.9.4/20240715-test-singlereq-optin.html?pbjs_debug=true' - }, - 'device': { - 'w': 1609, - 'h': 279, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', - 'language': 'en' - } - } -}, -{ - 'bidder': 'ozone', - 'params': { - 'publisherId': 'OZONENUK0001', - 'siteId': '4204204201', - 'placementId': '8000000330', - 'customData': [ - { - 'settings': {}, - 'targeting': { - 'sens': 'f', - 'pt1': '/uk', - 'pt5': [ - 'uk' - ], - 'pt7': 'desktop', - 'pt9': '|k0xw2vqzp33kklb3j5w4|||' - } - } - ] - }, - 'ortb2Imp': { - 'ext': { - 'gpid': 'mpu_pbadslot_from_adunit', - 'data': { - 'pbadslot': 'mpu_pbadslot_from_adunit', - 'adserver': { - 'name': 'gam', - 'adslot': '/22037345/projectozone' - } - }, - 'tid': 'f0dac8b5-09df-4da7-9d83-c99786d4517a' - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'mpu6', - 'transactionId': 'f0dac8b5-09df-4da7-9d83-c99786d4517a', - 'adUnitId': '715b4bdc-515f-488b-8633-333654e72f3f', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '3da18cc31f1ddf', - 'bidderRequestId': '263c3b0d970326', - 'auctionId': 'a9c479d0-d9cc-4505-a0a6-5982ce8fb8f0', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'source': { - 'tid': 'a9c479d0-d9cc-4505-a0a6-5982ce8fb8f0' - }, - 'regs': { - 'ext': { - 'gdpr': 1, - 'us_privacy': '1Y--' - } - }, - 'user': { - 'ext': { - 'consent': 'CQAaAwAQAaAwAAKA1AENA5EsAP_gAEPgACiQKRNV_G__bWlr8X73aftkeY1P9_h77sQxBhfJE-4FzLuW_JwXx2ExNA36tqIKmRIEu3bBIQNlHJDUTVCgaogVryDMakWcoTNKJ6BkiFMRO2dYCF5vmwtj-QKY5vr993dx2B-t_dv83dzyz4VHn3a5_2e0WJCdA58tDfv9bROb-9IPd_58v4v8_F_rE2_eT1l_tevp7D9-cts7_XW-9_fff79Ll_-mBwUcALMNCogDLIkJCDQMIIEAKgrCAigQAAAAkDRAQAmDAp2BgEusJEAIAUAAwQAgABRkACAAASABCIAIACgQAAQCBQAAgAACAQAMDAAGACwEAgABAdAhTAggUCwASMyIhTAgCgSCAlsqEEgCBBXCEIs8CCAREwUAAAJABWAAICwWAxJICViQQJcQbQAAEACAQQAVCKTswBBAGbLVXiibRlaQFo-ACjgAAAAA.YAAAAAAAAAAA' - } - }, - 'site': { - 'domain': 'ozoneproject.com', - 'publisher': { - 'domain': 'ozoneproject.com' - }, - 'page': 'https://www.www.ozoneproject.com/ozone/2.9.4/20240715-test-singlereq-optin.html?pbjs_debug=true' - }, - 'device': { - 'w': 1609, - 'h': 279, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36', - 'language': 'en' - } - } -}]; -var validBidRequestsWithUserIdData = [ - { - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - bidId: '2899ec066a91ff8', - bidRequestsCount: 1, - bidder: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - crumbs: {pubcid: '203a0692-f728-4856-87f6-9a25a6b63715'}, - params: { publisherId: '9876abcd12-3', customData: [{'settings': {}, 'targeting': {'gender': 'bart', 'age': 'low'}}], placementId: '1310000099', siteId: '1234567890', id: 'fea37168-78f1-4a23-a40e-88437a99377e', auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', imp: [ { id: '2899ec066a91ff8', tagid: 'undefined', secure: 1, banner: { format: [{ w: 300, h: 250 }, { w: 300, h: 600 }], h: 250, topframe: 1, w: 300 } } ] }, - sizes: [[300, 250], [300, 600]], - transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87', - userId: { - 'pubcid': '12345678', - 'tdid': '1111tdid', - 'id5id': { uid: '1111', ext: { linkType: 2, abTestingControlGroup: false } }, - 'criteoId': '1111criteoId', - 'idl_env': 'liverampId', - 'lipb': {'lipbid': 'lipbidId123'}, - 'parrableId': {'eid': '01.5678.parrableid'}, - 'sharedid': {'id': '01EAJWWNEPN3CYMM5N8M5VXY22', 'third': '01EAJWWNEPN3CYMM5N8M5VXY22'} - }, - userIdAsEids: [ - { - 'source': 'pubcid.org', - 'uids': [ - { - 'id': '12345678', - 'atype': 1 - } - ] - }, - { - 'source': 'adserver.org', - 'uids': [{ - 'id': '1111tdid', - 'atype': 1, - 'ext': { - 'rtiPartner': 'TDID' - } - }] - }, - { - 'source': 'id5-sync.com', - 'uids': [{ - 'id': 'ID5-someId', - 'atype': 1, - }] - }, - { - 'source': 'criteoId', - 'uids': [{ - 'id': '1111criteoId', - 'atype': 1, - }] - }, - { - 'source': 'idl_env', - 'uids': [{ - 'id': 'liverampId', - 'atype': 1, - }] - }, - { - 'source': 'lipb', - 'uids': [{ - 'id': {'lipbid': 'lipbidId123'}, - 'atype': 1, - }] - }, - { - 'source': 'parrableId', - 'uids': [{ - 'id': {'eid': '01.5678.parrableid'}, - 'atype': 1, - }] - } - ] - } -]; -var validBidRequestsMinimal = [ - { - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - bidId: '2899ec066a91ff8', - bidRequestsCount: 1, - bidder: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - params: { publisherId: '9876abcd12-3', placementId: '1310000099', siteId: '1234567890', id: 'fea37168-78f1-4a23-a40e-88437a99377e', auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', imp: [ { id: '2899ec066a91ff8', tagid: 'undefined', secure: 1, banner: { format: [{ w: 300, h: 250 }, { w: 300, h: 600 }], h: 250, topframe: 1, w: 300 } } ] }, - sizes: [[300, 250], [300, 600]], - transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' - } -]; -var validBidRequestsNoSizes = [ - { - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - bidId: '2899ec066a91ff8', - bidRequestsCount: 1, - bidder: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - crumbs: {pubcid: '203a0692-f728-4856-87f6-9a25a6b63715'}, - params: { publisherId: '9876abcd12-3', customData: [{'settings': {}, 'targeting': {'gender': 'bart', 'age': 'low'}}], placementId: '1310000099', siteId: '1234567890', id: 'fea37168-78f1-4a23-a40e-88437a99377e', auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', imp: [ { id: '2899ec066a91ff8', tagid: 'undefined', secure: 1, banner: { format: [{ w: 300, h: 250 }, { w: 300, h: 600 }], h: 250, topframe: 1, w: 300 } } ] }, - transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' - } -]; -var validBidRequestsWithBannerMediaType = [ - { - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - bidId: '2899ec066a91ff8', - bidRequestsCount: 1, - bidder: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - crumbs: {pubcid: '203a0692-f728-4856-87f6-9a25a6b63715'}, - params: { publisherId: '9876abcd12-3', customData: [{'settings': {}, 'targeting': {'gender': 'bart', 'age': 'low'}}], placementId: '1310000099', siteId: '1234567890', id: 'fea37168-78f1-4a23-a40e-88437a99377e', auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', imp: [ { id: '2899ec066a91ff8', tagid: 'undefined', secure: 1, banner: { format: [{ w: 300, h: 250 }, { w: 300, h: 600 }], h: 250, topframe: 1, w: 300 } } ] }, - mediaTypes: {banner: {sizes: [[300, 250], [300, 600]]}}, - transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' - } -]; -var validBidRequestsWithNonBannerMediaTypesAndValidOutstreamVideo = [ - { - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - bidId: '2899ec066a91ff8', - bidRequestsCount: 1, - bidder: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - crumbs: {pubcid: '203a0692-f728-4856-87f6-9a25a6b63715'}, - params: { publisherId: '9876abcd12-3', customData: [{'settings': {}, 'targeting': {'gender': 'bart', 'age': 'low'}}], placementId: '1310000099', siteId: '1234567890', id: 'fea37168-78f1-4a23-a40e-88437a99377e', auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', imp: [ { id: '2899ec066a91ff8', tagid: 'undefined', secure: 1, video: {skippable: true, playback_method: ['auto_play_sound_off'], targetDiv: 'some-different-div-id-to-my-adunitcode'} } ] }, - mediaTypes: {video: {mimes: ['video/mp4'], 'context': 'outstream', 'sizes': [640, 480], playerSize: [640, 480]}, native: {info: 'dummy data'}}, - transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' - } -]; -var validBidRequests1OutstreamVideo2020 = [ - { - 'bidder': 'ozone', - 'testname': 'validBidRequests1OutstreamVideo2020', - 'params': { - 'publisherId': 'OZONERUP0001', - 'placementId': '8000000009', - 'siteId': '4204204201', - 'video': { - 'skippable': true, - 'playback_method': [ - 'auto_play_sound_off' - ] - }, - 'customData': [ - { - 'settings': {}, - 'targeting': { - 'sens': 'f', - 'pt1': '/uk', - 'pt2': 'uk', - 'pt3': 'network-front', - 'pt4': 'ng', - 'pt5': [ - 'uk' - ], - 'pt7': 'desktop', - 'pt8': [ - 'tfmqxwj7q', - 'penl4dfdk', - 'sek9ghqwi' - ], - 'pt9': '|k0xw2vqzp33kklb3j5w4|||' - } - } - ], - 'userId': { - 'pubcid': '2ada6ae6-aeca-4e07-8922-a99b3aaf8a56' - }, - 'userIdAsEids': [ - { - 'source': 'pubcid.org', - 'uids': [ - { - 'id': '2ada6ae6-aeca-4e07-8922-a99b3aaf8a56', - 'atype': 1 - } - ] - } - ] - }, - 'mediaTypes': { - 'video': { - 'playerSize': [ - [ - 640, - 480 - ] - ], - 'mimes': [ - 'video/mp4' - ], - 'context': 'outstream' - } - }, - 'adUnitCode': 'video-ad', - 'transactionId': '02c1ea7d-0bf2-451b-a122-1420040d1cf8', - 'sizes': [ - [ - 640, - 480 - ] - ], - 'bidId': '2899ec066a91ff8', - 'bidderRequestId': '1c1586b27a1b5c8', - 'auctionId': '0456c9b7-5ab2-4fec-9e10-f418d3d1f04c', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } -]; -var validBidderRequest1OutstreamVideo2020 = { - bidderRequest: { - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - auctionStart: 1536838908986, - bidderCode: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - bids: [ - { - 'bidder': 'ozone', - 'params': { - 'publisherId': 'OZONERUP0001', - 'placementId': '8000000009', - 'siteId': '4204204201', - 'video': { - 'skippable': true, - 'playback_method': [ - 'auto_play_sound_off' - ] - }, - 'customData': [ - { - 'settings': {}, - 'targeting': { - 'sens': 'f', - 'pt1': '/uk', - 'pt2': 'uk', - 'pt3': 'network-front', - 'pt4': 'ng', - 'pt5': [ - 'uk' - ], - 'pt7': 'desktop', - 'pt8': [ - 'tfmqxwj7q', - 'penl4dfdk', - 'uayf5jmv3', - 'sek9ghqwi' - ], - 'pt9': '|k0xw2vqzp33kklb3j5w4|||' - } - } - ] - }, - 'userId': { - 'id5id': { uid: '1111', ext: { linkType: 2, abTestingControlGroup: false } }, - 'pubcid': '2ada6ae6-aeca-4e07-8922-a99b3aaf8a56' - }, - 'userIdAsEids': [ - { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': 'ID5-ZHMOpSv9CkZNiNd1oR4zc62AzCgSS73fPjmQ6Od7OA', - 'atype': 1 - } - ] - }, - { - 'source': 'pubcid.org', - 'uids': [ - { - 'id': '2ada6ae6-aeca-4e07-8922-a99b3aaf8a56', - 'atype': 1 - } - ] - } - ], - 'mediaTypes': { - 'video': { - 'playerSize': [ - [ - 640, - 480 - ] - ], - 'mimes': [ - 'video/mp4' - ], - 'context': 'outstream' - } - }, - 'adUnitCode': 'video-ad', - 'transactionId': 'ec20cc65-de38-4410-b5b3-50de5b7df66a', - 'sizes': [ - [ - 640, - 480 - ] - ], - 'bidId': '2899ec066a91ff8', - 'bidderRequestId': '1c1586b27a1b5c8', - 'auctionId': '0456c9b7-5ab2-4fec-9e10-f418d3d1f04c', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - }], - doneCbCallCount: 1, - start: 1536838908987, - timeout: 3000 - } -}; -var validBidderRequest = { - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - auctionStart: 1536838908986, - bidderCode: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - bids: [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - bidId: '2899ec066a91ff8', - bidRequestsCount: 1, - bidder: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - crumbs: {pubcid: '203a0692-f728-4856-87f6-9a25a6b63715'}, - params: { publisherId: '9876abcd12-3', customData: [{'settings': {}, 'targeting': {'gender': 'bart', 'age': 'low'}}], placementId: '1310000099', siteId: '1234567890', id: 'fea37168-78f1-4a23-a40e-88437a99377e', auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', imp: [ { banner: { topframe: 1, w: 300, h: 250, format: [{ w: 300, h: 250 }, { w: 300, h: 600 }] }, id: '2899ec066a91ff8', secure: 1, tagid: 'undefined' } ] }, - sizes: [[300, 250], [300, 600]], - transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' - }], - doneCbCallCount: 1, - start: 1536838908987, - timeout: 3000 -}; -var validBidderRequestWithCookieDeprecation = { - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - auctionStart: 1536838908986, - bidderCode: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - bids: [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - bidId: '2899ec066a91ff8', - bidRequestsCount: 1, - bidder: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - crumbs: {pubcid: '203a0692-f728-4856-87f6-9a25a6b63715'}, - params: { publisherId: '9876abcd12-3', customData: [{'settings': {}, 'targeting': {'gender': 'bart', 'age': 'low'}}], placementId: '1310000099', siteId: '1234567890', id: 'fea37168-78f1-4a23-a40e-88437a99377e', auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', imp: [ { banner: { topframe: 1, w: 300, h: 250, format: [{ w: 300, h: 250 }, { w: 300, h: 600 }] }, id: '2899ec066a91ff8', secure: 1, tagid: 'undefined' } ] }, - sizes: [[300, 250], [300, 600]], - transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' - }], - doneCbCallCount: 1, - start: 1536838908987, - timeout: 3000, - ortb2: { - 'device': { - 'w': 1617, - 'h': 317, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36', - 'language': 'en', - 'sua': { - 'source': 1, - 'platform': { - 'brand': 'macOS' - }, - 'browsers': [ - { - 'brand': 'Google Chrome', - 'version': [ - '125' - ] - }, - { - 'brand': 'Chromium', - 'version': [ - '125' - ] - }, - { - 'brand': 'Not.A/Brand', - 'version': [ - '24' - ] - } - ], - 'mobile': 0 - }, - 'ext': { - 'cdep': 'fake_control_2' - } - } - } -}; -var bidderRequestWithFullGdpr = { - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - auctionStart: 1536838908986, - bidderCode: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - bids: [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - bidId: '2899ec066a91ff8', - bidRequestsCount: 1, - bidder: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - crumbs: {pubcid: '203a0692-f728-4856-87f6-9a25a6b63715'}, - params: { publisherId: '9876abcd12-3', customData: [{'settings': {}, 'targeting': {'gender': 'bart', 'age': 'low'}}], placementId: '1310000099', siteId: '1234567890', id: 'fea37168-78f1-4a23-a40e-88437a99377e', auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', imp: [ { banner: { topframe: 1, w: 300, h: 250, format: [{ w: 300, h: 250 }, { w: 300, h: 600 }] }, id: '2899ec066a91ff8', secure: 1, tagid: 'undefined' } ] }, - sizes: [[300, 250], [300, 600]], - transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' - }], - doneCbCallCount: 1, - start: 1536838908987, - timeout: 3000, - gdprConsent: { - 'consentString': 'BOh7mtYOh7mtYAcABBENCU-AAAAncgPIXJiiAoao0PxBFkgCAC8ACIAAQAQQAAIAAAIAAAhBGAAAQAQAEQgAAAAAAABAAAAAAAAAAAAAAACAAAAAAAACgAAAAABAAAAQAAAAAAA', - 'vendorData': { - 'metadata': 'BOh7mtYOh7mtYAcABBENCU-AAAAncgPIXJiiAoao0PxBFkgCAC8ACIAAQAQQAAIAAAIAAAhBGAAAQAQAEQgAAAAAAABAAAAAAAAAAAAAAACAAAAAAAACgAAAAABAAAAQAAAAAAA', - 'gdprApplies': true, - 'hasGlobalScope': false, - 'cookieVersion': '1', - 'created': '2019-05-31T12:46:48.825', - 'lastUpdated': '2019-05-31T12:46:48.825', - 'cmpId': '28', - 'cmpVersion': '1', - 'consentLanguage': 'en', - 'consentScreen': '1', - 'vendorListVersion': 148, - 'maxVendorId': 631, - 'purposeConsents': { - '1': true, - '2': true, - '3': true, - '4': true, - '5': true - }, - 'vendorConsents': { - '468': true, - '522': true, - '524': true, - '565': true, - '591': true - } - }, - 'gdprApplies': true - } -}; -var gdpr1 = { - 'consentString': 'BOh7mtYOh7mtYAcABBENCU-AAAAncgPIXJiiAoao0PxBFkgCAC8ACIAAQAQQAAIAAAIAAAhBGAAAQAQAEQgAAAAAAABAAAAAAAAAAAAAAACAAAAAAAACgAAAAABAAAAQAAAAAAA', - 'vendorData': { - 'metadata': 'BOh7mtYOh7mtYAcABBENCU-AAAAncgPIXJiiAoao0PxBFkgCAC8ACIAAQAQQAAIAAAIAAAhBGAAAQAQAEQgAAAAAAABAAAAAAAAAAAAAAACAAAAAAAACgAAAAABAAAAQAAAAAAA', - 'gdprApplies': true, - 'hasGlobalScope': false, - 'cookieVersion': '1', - 'created': '2019-05-31T12:46:48.825', - 'lastUpdated': '2019-05-31T12:46:48.825', - 'cmpId': '28', - 'cmpVersion': '1', - 'consentLanguage': 'en', - 'consentScreen': '1', - 'vendorListVersion': 148, - 'maxVendorId': 631, - 'purposeConsents': { - '1': true, - '2': true, - '3': true, - '4': true, - '5': true - }, - 'vendorConsents': { - '468': true, - '522': true, - '524': true, - '565': true, - '591': true - } - }, - 'gdprApplies': true -}; -var bidderRequestWithPartialGdpr = { - bidderRequest: { - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - auctionStart: 1536838908986, - bidderCode: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - bids: [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - bidId: '2899ec066a91ff8', - bidRequestsCount: 1, - bidder: 'ozone', - bidderRequestId: '1c1586b27a1b5c8', - crumbs: {pubcid: '203a0692-f728-4856-87f6-9a25a6b63715'}, - params: { - publisherId: '9876abcd12-3', - customData: [{'settings': {}, 'targeting': {'gender': 'bart', 'age': 'low'}}], - placementId: '1310000099', - siteId: '1234567890', - id: 'fea37168-78f1-4a23-a40e-88437a99377e', - auctionId: '27dcb421-95c6-4024-a624-3c03816c5f99', - imp: [{ - banner: {topframe: 1, w: 300, h: 250, format: [{w: 300, h: 250}, {w: 300, h: 600}]}, - id: '2899ec066a91ff8', - secure: 1, - tagid: 'undefined' - }] - }, - sizes: [[300, 250], [300, 600]], - transactionId: '2e63c0ed-b10c-4008-aed5-84582cecfe87' - }], - doneCbCallCount: 1, - start: 1536838908987, - timeout: 3000, - gdprConsent: { - 'consentString': 'BOh7mtYOh7mtYAcABBENCU-AAAAncgPIXJiiAoao0PxBFkgCAC8ACIAAQAQQAAIAAAIAAAhBGAAAQAQAEQgAAAAAAABAAAAAAAAAAAAAAACAAAAAAAACgAAAAABAAAAQAAAAAAA', - 'gdprApplies': true, - 'vendorData': { - 'metadata': 'BOh7mtYOh7mtYAcABBENCU-AAAAncgPIXJiiAoao0PxBFkgCAC8ACIAAQAQQAAIAAAIAAAhBGAAAQAQAEQgAAAAAAABAAAAAAAAAAAAAAACAAAAAAAACgAAAAABAAAAQAAAAAAA', - 'gdprApplies': true - } - } - } -}; -var validResponse = { - 'body': { - 'id': 'd6198807-7a53-4141-b2db-d2cb754d68ba', - 'seatbid': [ - { - 'bid': [ - { - 'id': '677903815252395017', - 'impid': '2899ec066a91ff8', - 'price': 0.5, - 'adm': '', - 'adid': '98493581', - 'adomain': [ - 'http://prebid.org' - ], - 'iurl': 'https://fra1-ib.adnxs.com/cr?id=98493581', - 'cid': '9325', - 'crid': '98493581', - 'cat': [ - 'IAB3-1' - ], - 'w': 300, - 'h': 600, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'appnexus': { - 'brand_id': 555545, - 'auction_id': 6500448734132353000, - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - } - } - ], - 'seat': 'appnexus' - } - ], - 'cur': 'GBP', - 'ext': { - 'responsetimemillis': { - 'appnexus': 47, - 'openx': 30 - } - }, - 'timing': { - 'start': 1536848078.089177, - 'end': 1536848078.142203, - 'TimeTaken': 0.05302619934082031 - } - }, - 'headers': {} -}; -var validResponse2Bids = { - 'body': { - 'id': 'd6198807-7a53-4141-b2db-d2cb754d68ba', - 'seatbid': [ - { - 'bid': [ - { - 'id': '677903815252395017', - 'impid': '2899ec066a91ff8', - 'price': 0.5, - 'adm': '', - 'adid': '98493581', - 'adomain': [ - 'http://prebid.org' - ], - 'iurl': 'https://fra1-ib.adnxs.com/cr?id=98493581', - 'cid': '9325', - 'crid': '98493581', - 'cat': [ - 'IAB3-1' - ], - 'w': 300, - 'h': 600, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'appnexus': { - 'brand_id': 555545, - 'auction_id': 6500448734132353000, - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - } - }, - { - 'id': '677903815252395010', - 'impid': '2899ec066a91ff0', - 'price': 0.9, - 'adm': '', - 'adid': '98493580', - 'adomain': [ - 'http://prebid.org' - ], - 'iurl': 'https://fra1-ib.adnxs.com/cr?id=98493581', - 'cid': '9320', - 'crid': '98493580', - 'cat': [ - 'IAB3-1' - ], - 'w': 300, - 'h': 600, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'appnexus': { - 'brand_id': 555540, - 'auction_id': 6500448734132353000, - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - } - } ], - 'seat': 'appnexus' - } - ], - 'cur': 'GBP', - 'ext': { - 'responsetimemillis': { - 'appnexus': 47, - 'openx': 30 - } - }, - 'timing': { - 'start': 1536848078.089177, - 'end': 1536848078.142203, - 'TimeTaken': 0.05302619934082031 - } - }, - 'headers': {} -}; -var validResponse2BidsSameAdunit = { - 'body': { - 'id': 'd6198807-7a53-4141-b2db-d2cb754d68ba', - 'seatbid': [ - { - 'bid': [ - { - 'id': '677903815252395017', - 'impid': '2899ec066a91ff8', - 'price': 0.5, - 'adm': '', - 'adid': '98493581', - 'adomain': [ - 'http://prebid.org' - ], - 'iurl': 'https://fra1-ib.adnxs.com/cr?id=98493581', - 'cid': '9325', - 'crid': '98493581', - 'cat': [ - 'IAB3-1' - ], - 'w': 300, - 'h': 600, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'appnexus': { - 'brand_id': 555545, - 'auction_id': 6500448734132353000, - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - } - }, - { - 'id': '677903815252395010', - 'impid': '2899ec066a91ff8', - 'price': 0.9, - 'adm': '', - 'adid': '98493580', - 'adomain': [ - 'http://prebid.org' - ], - 'iurl': 'https://fra1-ib.adnxs.com/cr?id=98493581', - 'cid': '9320', - 'crid': '98493580', - 'cat': [ - 'IAB3-1' - ], - 'w': 300, - 'h': 250, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'appnexus': { - 'brand_id': 555540, - 'auction_id': 6500448734132353000, - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - } - } ], - 'seat': 'ozappnexus' - } - ], - 'cur': 'GBP', - 'ext': { - 'responsetimemillis': { - 'appnexus': 47, - 'openx': 30 - } - }, - 'timing': { - 'start': 1536848078.089177, - 'end': 1536848078.142203, - 'TimeTaken': 0.05302619934082031 - } - }, - 'headers': {} -}; -function getCleanValidVideoResponse() { - return JSON.parse(JSON.stringify(_validVideoResponse)); -} -var _validVideoResponse = { - 'body': { - 'id': 'd6198807-7a53-4141-b2db-d2cb754d68ba', - 'seatbid': [ - { - 'bid': [ - { - 'id': '2899ec066a91ff8', - 'impid': '2899ec066a91ff8', - 'price': 31.7, - 'adm': '', - 'adomain': [ - 'sarr.properties' - ], - 'crid': 'ozone-655', - 'cat': [ - 'IAB21' - ], - 'w': 640, - 'h': 360, - 'ext': { - 'prebid': { - 'type': 'video' - } - }, - 'adId': '2899ec066a91ff8-2', - 'cpm': 31.7, - 'bidId': '2899ec066a91ff8', - 'requestId': '2899ec066a91ff8', - 'width': 640, - 'height': 360, - 'ad': '', - 'netRevenue': true, - 'creativeId': 'ozone-655', - 'currency': 'USD', - 'ttl': 300, - 'adserverTargeting': { - 'oz_ozbeeswax': 'ozbeeswax', - 'oz_ozbeeswax_pb': '31.7', - 'oz_ozbeeswax_crid': 'ozone-655', - 'oz_ozbeeswax_adv': 'sarr.properties', - 'oz_ozbeeswax_imp_id': '49d16ccc28663a8', - 'oz_ozbeeswax_adId': '49d16ccc28663a8-2', - 'oz_ozbeeswax_pb_r': '20.00', - 'oz_ozbeeswax_omp': '1', - 'oz_ozbeeswax_vid': 'outstream', - 'oz_auc_id': 'efa7fea0-7e87-4811-be86-fefb38c35fbb', - 'oz_winner': 'ozbeeswax', - 'oz_response_id': 'efa7fea0-7e87-4811-be86-fefb38c35fbb', - 'oz_winner_auc_id': '49d16ccc28663a8', - 'oz_winner_imp_id': '49d16ccc28663a8', - 'oz_pb_v': '2.4.0', - 'hb_bidder': 'ozone', - 'hb_adid': '49d16ccc28663a8-2', - 'hb_pb': '20.00', - 'hb_size': '640x360', - 'hb_source': 'client', - 'hb_format': 'banner' - }, - 'originalCpm': 31.7, - 'originalCurrency': 'USD' - } - ], - 'seat': 'ozbeeswax' - } - ], - 'ext': { - 'responsetimemillis': { - 'beeswax': 9, - 'openx': 43, - 'ozappnexus': 31, - 'ozbeeswax': 7 - } - }, - 'timing': { - 'start': 1536848078.089177, - 'end': 1536848078.142203, - 'TimeTaken': 0.05302619934082031 - } - }, - 'headers': {} -}; -var validBidResponse1adWith2Bidders = { - 'body': { - 'id': '91221f96-b931-4acc-8f05-c2a1186fa5ac', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'd6198807-7a53-4141-b2db-d2cb754d68ba', - 'impid': '2899ec066a91ff8', - 'price': 0.36754, - 'adm': '', - 'adid': '134928661', - 'adomain': [ - 'somecompany.com' - ], - 'iurl': 'https:\/\/ams1-ib.adnxs.com\/cr?id=134928661', - 'cid': '8825', - 'crid': '134928661', - 'cat': [ - 'IAB8-15', - 'IAB8-16', - 'IAB8-4', - 'IAB8-1', - 'IAB8-14', - 'IAB8-6', - 'IAB8-13', - 'IAB8-3', - 'IAB8-17', - 'IAB8-12', - 'IAB8-8', - 'IAB8-7', - 'IAB8-2', - 'IAB8-9', - 'IAB8', - 'IAB8-11' - ], - 'w': 300, - 'h': 250, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'appnexus': { - 'brand_id': 14640, - 'auction_id': 1.8369641905139e+18, - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - } - } - ], - 'seat': 'appnexus' - }, - { - 'bid': [ - { - 'id': '75665207-a1ca-49db-ba0e-a5e9c7d26f32', - 'impid': '37fff511779365a', - 'price': 1.046, - 'adm': '
removed
', - 'adomain': [ - 'kx.com' - ], - 'crid': '13005', - 'w': 300, - 'h': 250, - 'ext': { - 'prebid': { - 'type': 'banner' - } - } - } - ], - 'seat': 'openx' - } - ], - 'ext': { - 'responsetimemillis': { - 'appnexus': 91, - 'openx': 109, - 'ozappnexus': 46, - 'ozbeeswax': 2, - 'pangaea': 91 - } - } - }, - 'headers': {} -}; -var multiRequest1 = [ - { - 'bidder': 'ozone', - 'params': { - 'publisherId': 'OZONERUP0001', - 'siteId': '4204204201', - 'placementId': '0420420421', - 'customData': [ - { - 'settings': {}, - 'targeting': { - 'sens': 'f', - 'pt1': '/uk', - 'pt2': 'uk', - 'pt3': 'network-front', - 'pt4': 'ng', - 'pt5': [ - 'uk' - ], - 'pt7': 'desktop', - 'pt8': [ - 'tfmqxwj7q', - 'penl4dfdk', - 'uayf5jmv3', - 't8nyiude5', - 'sek9ghqwi' - ], - 'pt9': '|k0xw2vqzp33kklb3j5w4|||' - } - } - ] - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'mpu', - 'transactionId': '6480bac7-31b5-4723-9145-ad8966660651', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '2d30e86db743a8', - 'bidderRequestId': '1d03a1dfc563fc', - 'auctionId': '592ee33b-fb2e-4c00-b2d5-383e99cac57f', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - }, - { - 'bidder': 'ozone', - 'params': { - 'publisherId': 'OZONERUP0001', - 'siteId': '4204204201', - 'placementId': '0420420421', - 'customData': [ - { - 'settings': {}, - 'targeting': { - 'sens': 'f', - 'pt1': '/uk', - 'pt2': 'uk', - 'pt3': 'network-front', - 'pt4': 'ng', - 'pt5': [ - 'uk' - ], - 'pt7': 'desktop', - 'pt8': [ - 'tfmqxwj7q', - 'penl4dfdk', - 't8nxz6qzd', - 't8nyiude5', - 'sek9ghqwi' - ], - 'pt9': '|k0xw2vqzp33kklb3j5w4|||' - } - } - ] - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 728, - 90 - ], - [ - 970, - 250 - ] - ] - } - }, - 'adUnitCode': 'leaderboard', - 'transactionId': 'a49988e6-ae7c-46c4-9598-f18db49892a0', - 'sizes': [ - [ - 728, - 90 - ], - [ - 970, - 250 - ] - ], - 'bidId': '3025f169863b7f8', - 'bidderRequestId': '1d03a1dfc563fc', - 'auctionId': '592ee33b-fb2e-4c00-b2d5-383e99cac57f', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } -]; -var multiBidderRequest1 = { - 'bidderCode': 'ozone', - 'auctionId': '592ee33b-fb2e-4c00-b2d5-383e99cac57f', - 'bidderRequestId': '1d03a1dfc563fc', - 'bids': [ - { - 'bidder': 'ozone', - 'params': { - 'publisherId': 'OZONERUP0001', - 'siteId': '4204204201', - 'placementId': '0420420421', - 'customData': [ - { - 'settings': {}, - 'targeting': { - 'sens': 'f', - 'pt1': '/uk', - 'pt2': 'uk', - 'pt3': 'network-front', - 'pt4': 'ng', - 'pt5': [ - 'uk' - ], - 'pt7': 'desktop', - 'pt8': [ - 'tfmqxwj7q', - 'txeh7uyo0', - 't8nxz6qzd', - 't8nyiude5', - 'sek9ghqwi' - ], - 'pt9': '|k0xw2vqzp33kklb3j5w4|||' - } - } - ] - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'mpu', - 'transactionId': '6480bac7-31b5-4723-9145-ad8966660651', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '2d30e86db743a8', - 'bidderRequestId': '1d03a1dfc563fc', - 'auctionId': '592ee33b-fb2e-4c00-b2d5-383e99cac57f', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - }, - { - 'bidder': 'ozone', - 'params': { - 'publisherId': 'OZONERUP0001', - 'siteId': '4204204201', - 'placementId': '0420420421', - 'customData': [ - { - 'settings': {}, - 'targeting': { - 'sens': 'f', - 'pt1': '/uk', - 'pt2': 'uk', - 'pt3': 'network-front', - 'pt4': 'ng', - 'pt5': [ - 'uk' - ], - 'pt7': 'desktop', - 'pt8': [ - 'tfmqxwj7q', - 'penl4dfdk', - 't8nxz6qzd', - 't8nyiude5', - 'sek9ghqwi' - ], - 'pt9': '|k0xw2vqzp33kklb3j5w4|||' - } - } - ] - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 728, - 90 - ], - [ - 970, - 250 - ] - ] - } - }, - 'adUnitCode': 'leaderboard', - 'transactionId': 'a49988e6-ae7c-46c4-9598-f18db49892a0', - 'sizes': [ - [ - 728, - 90 - ], - [ - 970, - 250 - ] - ], - 'bidId': '3025f169863b7f8', - 'bidderRequestId': '1d03a1dfc563fc', - 'auctionId': '592ee33b-fb2e-4c00-b2d5-383e99cac57f', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'auctionStart': 1592918645574, - 'timeout': 3000, - 'refererInfo': { - 'referer': 'http://ozone.ozoneproject.com/adapter/2.4.0/620x350-switch.html?guardian=true&pbjs_debug=true', - 'reachedTop': true, - 'numIframes': 0, - 'stack': [ - 'http://ozone.ozoneproject.com/adapter/2.4.0/620x350-switch.html?guardian=true&pbjs_debug=true' - ] - }, - 'gdprConsent': { - 'consentString': 'BOvy5sFO1dBa2AKAiBENDP-AAAAwVrv7_77-_9f-_f__9uj3Gr_v_f__32ccL5tv3h_7v-_7fi_-0nV4u_1tft9ydk1-5ctDztp507iakiPHmqNeb9n_mz1eZpRP58E09j53z7Ew_v8_v-b7BCPN_Y3v-8K96kA', - 'vendorData': { - 'metadata': 'BOvy5sFO1dBa2AKAiBENDPA', - 'gdprApplies': true, - 'hasGlobalConsent': false, - 'hasGlobalScope': false, - 'purposeConsents': { - '1': true, - '2': true, - '3': true, - '4': true, - '5': true - }, - 'vendorConsents': { - '1': true, - '2': true, - '3': false, - '4': true, - '5': true - } - }, - 'gdprApplies': true - }, - 'start': 1592918645578 -}; -var multiResponse1 = { - 'body': { - 'id': '592ee33b-fb2e-4c00-b2d5-383e99cac57f', - 'seatbid': [ - { - 'bid': [ - { - 'id': '4419718600113204943', - 'impid': '2d30e86db743a8', - 'price': 0.2484, - 'adm': '', - 'adid': '119683582', - 'adomain': [ - 'https://ozoneproject.com' - ], - 'iurl': 'https://ams1-ib.adnxs.com/cr?id=119683582', - 'cid': '9979', - 'crid': '119683582', - 'cat': [ - 'IAB3' - ], - 'w': 300, - 'h': 250, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'ozone': {}, - 'appnexus': { - 'brand_id': 734921, - 'auction_id': 2995348111857539600, - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - }, - 'cpm': 0.2484, - 'bidId': '2d30e86db743a8', - 'requestId': '2d30e86db743a8', - 'width': 300, - 'height': 250, - 'ad': '', - 'netRevenue': true, - 'creativeId': '119683582', - 'currency': 'USD', - 'ttl': 300, - 'originalCpm': 0.2484, - 'originalCurrency': 'USD' - }, - { - 'id': '18552976939844681', - 'impid': '3025f169863b7f8', - 'price': 0.0621, - 'adm': '', - 'adid': '120179216', - 'adomain': [ - 'appnexus.com' - ], - 'iurl': 'https://ams1-ib.adnxs.com/cr?id=120179216', - 'cid': '9979', - 'crid': '120179216', - 'w': 970, - 'h': 250, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'ozone': {}, - 'appnexus': { - 'brand_id': 1, - 'auction_id': 3449036134472542700, - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - }, - 'cpm': 0.0621, - 'bidId': '3025f169863b7f8', - 'requestId': '3025f169863b7f8', - 'width': 970, - 'height': 250, - 'ad': '', - 'netRevenue': true, - 'creativeId': '120179216', - 'currency': 'USD', - 'ttl': 300, - 'originalCpm': 0.0621, - 'originalCurrency': 'USD' - }, - { - 'id': '18552976939844999', - 'impid': '3025f169863b7f8', - 'price': 0.521, - 'adm': '', - 'adid': '120179216', - 'adomain': [ - 'appnexus.com' - ], - 'iurl': 'https://ams1-ib.adnxs.com/cr?id=120179216', - 'cid': '9999', - 'crid': '120179299', - 'w': 728, - 'h': 90, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'ozone': {}, - 'appnexus': { - 'brand_id': 1, - 'auction_id': 3449036134472542700, - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - }, - 'cpm': 0.521, - 'bidId': '3025f169863b7f8', - 'requestId': '3025f169863b7f8', - 'width': 728, - 'height': 90, - 'ad': '', - 'netRevenue': true, - 'creativeId': '120179299', - 'currency': 'USD', - 'ttl': 300, - 'originalCpm': 0.0621, - 'originalCurrency': 'USD' - } - ], - 'seat': 'ozappnexus' - }, - { - 'bid': [ - { - 'id': '1c605e8a-4992-4ec6-8a5c-f82e2938c2db', - 'impid': '2d30e86db743a8', - 'price': 0.01, - 'adm': '
', - 'crid': '540463358', - 'w': 300, - 'h': 250, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'ozone': {} - } - }, - 'cpm': 0.01, - 'bidId': '2d30e86db743a8', - 'requestId': '2d30e86db743a8', - 'width': 300, - 'height': 250, - 'ad': '
', - 'netRevenue': true, - 'creativeId': '540463358', - 'currency': 'USD', - 'ttl': 300, - 'originalCpm': 0.01, - 'originalCurrency': 'USD' - }, - { - 'id': '3edeb4f7-d91d-44e2-8aeb-4a2f6d295ce5', - 'impid': '3025f169863b7f8', - 'price': 0.01, - 'adm': '
', - 'crid': '540221061', - 'w': 970, - 'h': 250, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'ozone': {} - } - }, - 'cpm': 0.01, - 'bidId': '3025f169863b7f8', - 'requestId': '3025f169863b7f8', - 'width': 970, - 'height': 250, - 'ad': '
', - 'netRevenue': true, - 'creativeId': '540221061', - 'currency': 'USD', - 'ttl': 300, - 'originalCpm': 0.01, - 'originalCurrency': 'USD' - } - ], - 'seat': 'openx' - } - ], - 'ext': { - 'debug': {}, - 'responsetimemillis': { - 'beeswax': 6, - 'openx': 91, - 'ozappnexus': 40, - 'ozbeeswax': 6 - } - } - }, - 'headers': {} -}; -describe('ozone Adapter', function () { - describe('isBidRequestValid', function () { - const validBidReq = { - bidder: BIDDER_CODE, - params: { - placementId: '1310000099', - publisherId: '9876abcd12-3', - siteId: '1234567890' - } - }; - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(validBidReq)).to.equal(true); - }); - var validBidReq2 = { - bidder: BIDDER_CODE, - params: { - placementId: '1310000099', - publisherId: '9876abcd12-3', - siteId: '1234567890', - customData: [{'settings': {}, 'targeting': {'gender': 'bart', 'age': 'low'}}] - }, - siteId: 1234567890 - } - it('should return true when required params found and all optional params are valid', function () { - expect(spec.isBidRequestValid(validBidReq2)).to.equal(true); - }); - var xEmptyPlacement = { - bidder: BIDDER_CODE, - params: { - placementId: '', - publisherId: '9876abcd12-3', - siteId: '1234567890' - } - }; - it('should not validate empty placementId', function () { - expect(spec.isBidRequestValid(xEmptyPlacement)).to.equal(false); - }); - var xMissingPlacement = { - bidder: BIDDER_CODE, - params: { - publisherId: '9876abcd12-3', - siteId: '1234567890' - } - }; - it('should not validate missing placementId', function () { - expect(spec.isBidRequestValid(xMissingPlacement)).to.equal(false); - }); - var xBadPlacement = { - bidder: BIDDER_CODE, - params: { - placementId: '123X45', - publisherId: '9876abcd12-3', - siteId: '1234567890' - } - }; - it('should not validate placementId with a non-numeric value', function () { - expect(spec.isBidRequestValid(xBadPlacement)).to.equal(false); - }); - var xBadPlacementTooShort = { - bidder: BIDDER_CODE, - params: { - placementId: 123456789, - publisherId: '9876abcd12-3', - siteId: '1234567890' - } - }; - it('should not validate placementId with a numeric value of wrong length', function () { - expect(spec.isBidRequestValid(xBadPlacementTooShort)).to.equal(false); - }); - var xBadPlacementTooLong = { - bidder: BIDDER_CODE, - params: { - placementId: 12345678901, - publisherId: '9876abcd12-3', - siteId: '1234567890' - } - }; - it('should not validate placementId with a numeric value of wrong length', function () { - expect(spec.isBidRequestValid(xBadPlacementTooLong)).to.equal(false); - }); - var xMissingPublisher = { - bidder: BIDDER_CODE, - params: { - placementId: '1234567890', - siteId: '1234567890' - } - }; - it('should not validate missing publisherId', function () { - expect(spec.isBidRequestValid(xMissingPublisher)).to.equal(false); - }); - var xMissingSiteId = { - bidder: BIDDER_CODE, - params: { - publisherId: '9876abcd12-3', - placementId: '1234567890', - } - }; - it('should not validate missing sitetId', function () { - expect(spec.isBidRequestValid(xMissingSiteId)).to.equal(false); - }); - var xBadPublisherTooShort = { - bidder: BIDDER_CODE, - params: { - placementId: '1234567890', - publisherId: '9876abcd12a', - siteId: '1234567890' - } - }; - it('should not validate publisherId being too short', function () { - expect(spec.isBidRequestValid(xBadPublisherTooShort)).to.equal(false); - }); - var xBadPublisherTooLong = { - bidder: BIDDER_CODE, - params: { - placementId: '1234567890', - publisherId: '9876abcd12abc', - siteId: '1234567890' - } - }; - it('should not validate publisherId being too long', function () { - expect(spec.isBidRequestValid(xBadPublisherTooLong)).to.equal(false); - }); - var publisherNumericOk = { - bidder: BIDDER_CODE, - params: { - placementId: '1234567890', - publisherId: 123456789012, - siteId: '1234567890' - } - }; - it('should validate publisherId being 12 digits', function () { - expect(spec.isBidRequestValid(publisherNumericOk)).to.equal(true); - }); - var xEmptyPublisher = { - bidder: BIDDER_CODE, - params: { - placementId: '1234567890', - publisherId: '', - siteId: '1234567890' - } - }; - it('should not validate empty publisherId', function () { - expect(spec.isBidRequestValid(xEmptyPublisher)).to.equal(false); - }); - var xBadSite = { - bidder: BIDDER_CODE, - params: { - placementId: '1234567890', - publisherId: '9876abcd12-3', - siteId: '12345Z' - } - }; - it('should not validate bad siteId', function () { - expect(spec.isBidRequestValid(xBadSite)).to.equal(false); - }); - it('should not validate siteId too long', function () { - expect(spec.isBidRequestValid(xBadSite)).to.equal(false); - }); - it('should not validate siteId too short', function () { - expect(spec.isBidRequestValid(xBadSite)).to.equal(false); - }); - var allNonStrings = { - bidder: BIDDER_CODE, - params: { - placementId: 1234567890, - publisherId: '9876abcd12-3', - siteId: 1234567890 - } - }; - it('should validate all numeric values being sent as non-string numbers', function () { - expect(spec.isBidRequestValid(allNonStrings)).to.equal(true); - }); - var emptySiteId = { - bidder: BIDDER_CODE, - params: { - placementId: 1234567890, - publisherId: '9876abcd12-3', - siteId: '' - } - }; - it('should not validate siteId being empty string (it is required now)', function () { - expect(spec.isBidRequestValid(emptySiteId)).to.equal(false); - }); - var xBadCustomData = { - bidder: BIDDER_CODE, - params: { - 'placementId': '1234567890', - 'publisherId': '9876abcd12-3', - 'siteId': '1234567890', - 'customData': 'this aint gonna work' - } - }; - it('should not validate customData not being an array', function () { - expect(spec.isBidRequestValid(xBadCustomData)).to.equal(false); - }); - var xBadCustomDataOldCustomdataValue = { - bidder: BIDDER_CODE, - params: { - 'placementId': '1234567890', - 'publisherId': '9876abcd12-3', - 'siteId': '1234567890', - 'customData': {'gender': 'bart', 'age': 'low'} - } - }; - it('should not validate customData being an object, not an array', function () { - expect(spec.isBidRequestValid(xBadCustomDataOldCustomdataValue)).to.equal(false); - }); - var xBadCustomDataZerocd = { - bidder: BIDDER_CODE, - params: { - 'placementId': '1111111110', - 'publisherId': '9876abcd12-3', - 'siteId': '1234567890', - 'customData': [] - } - }; - it('should not validate customData array having no elements', function () { - expect(spec.isBidRequestValid(xBadCustomDataZerocd)).to.equal(false); - }); - var xBadCustomDataNotargeting = { - bidder: BIDDER_CODE, - params: { - 'placementId': '1234567890', - 'publisherId': '9876abcd12-3', - 'customData': [{'settings': {}, 'xx': {'gender': 'bart', 'age': 'low'}}], - siteId: '1234567890' - } - }; - it('should not validate customData[] having no "targeting"', function () { - expect(spec.isBidRequestValid(xBadCustomDataNotargeting)).to.equal(false); - }); - var xBadCustomDataTgtNotObj = { - bidder: BIDDER_CODE, - params: { - 'placementId': '1234567890', - 'publisherId': '9876abcd12-3', - 'customData': [{'settings': {}, 'targeting': 'this should be an object'}], - siteId: '1234567890' - } - }; - it('should not validate customData[0].targeting not being an object', function () { - expect(spec.isBidRequestValid(xBadCustomDataTgtNotObj)).to.equal(false); - }); - var xBadCustomParams = { - bidder: BIDDER_CODE, - params: { - 'placementId': '1234567890', - 'publisherId': '9876abcd12-3', - 'siteId': '1234567890', - 'customParams': 'this key is no longer valid' - } - }; - it('should not validate customParams - this is a renamed key', function () { - expect(spec.isBidRequestValid(xBadCustomParams)).to.equal(false); - }); - var xBadVideoContext2 = { - bidder: BIDDER_CODE, - params: { - 'placementId': '1234567890', - 'publisherId': '9876abcd12-3', - siteId: '1234567890' - }, - mediaTypes: { - video: { - mimes: ['video/mp4']} - } - }; - it('should not validate video without context attribute', function () { - expect(spec.isBidRequestValid(xBadVideoContext2)).to.equal(false); - }); - const validVideoBidReq = { - bidder: BIDDER_CODE, - params: { - placementId: '1310000099', - publisherId: '9876abcd12-3', - siteId: '1234567890' - }, - mediaTypes: { - video: { - mimes: ['video/mp4'], - 'context': 'outstream'}, - } - }; - it('should validate video outstream being sent', function () { - expect(spec.isBidRequestValid(validVideoBidReq)).to.equal(true); - }); - it('should validate video instream being sent even though its not properly supported yet', function () { - const instreamVid = JSON.parse(JSON.stringify(validVideoBidReq)); - instreamVid.mediaTypes.video.context = 'instream'; - expect(spec.isBidRequestValid(instreamVid)).to.equal(true); - }); - }); - describe('buildRequests', function () { - beforeEach(function () { - config.resetConfig() - }); - it('sends bid request to OZONEURI via POST', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - expect(request.url).to.equal(OZONEURI); - expect(request.method).to.equal('POST'); - }); - it('sends data as a string', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - expect(request.data).to.be.a('string'); - }); - it('sends all bid parameters', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - expect(request).to.have.all.keys(['bidderRequest', 'data', 'method', 'url']); - }); - it('adds all parameters inside the ext object only', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - expect(request.data).to.be.a('string'); - var data = JSON.parse(request.data); - expect(data.imp[0].ext.ozone.customData).to.be.an('array'); - expect(request).not.to.have.key('lotameData'); - expect(request).not.to.have.key('customData'); - }); - it('adds all parameters inside the ext object only - lightning', function () { - const localBidReq = JSON.parse(JSON.stringify(validBidRequests)); - const request = spec.buildRequests(localBidReq, validBidderRequest); - expect(request.data).to.be.a('string'); - var data = JSON.parse(request.data); - expect(data.imp[0].ext.ozone.customData).to.be.an('array'); - expect(request).not.to.have.key('lotameData'); - expect(request).not.to.have.key('customData'); - }); - it('ignores ozoneData in & after version 2.1.1', function () { - const validBidRequestsWithOzoneData = JSON.parse(JSON.stringify(validBidRequests)); - validBidRequestsWithOzoneData[0].params.ozoneData = {'networkID': '3048', 'dfpSiteID': 'd.thesun', 'sectionID': 'homepage', 'path': '/', 'sec_id': 'null', 'sec': 'sec', 'topics': 'null', 'kw': 'null', 'aid': 'null', 'search': 'null', 'article_type': 'null', 'hide_ads': '', 'article_slug': 'null'}; - const request = spec.buildRequests(validBidRequestsWithOzoneData, validBidderRequest); - expect(request.data).to.be.a('string'); - var data = JSON.parse(request.data); - expect(data.imp[0].ext.ozone.customData).to.be.an('array'); - expect(data.imp[0].ext.ozone.ozoneData).to.be.undefined; - expect(request).not.to.have.key('lotameData'); - expect(request).not.to.have.key('customData'); - }); - it('has correct bidder', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - expect(request.bidderRequest.bids[0].bidder).to.equal(BIDDER_CODE); - }); - it('handles mediaTypes element correctly', function () { - const request = spec.buildRequests(validBidRequestsWithBannerMediaType, validBidderRequest); - expect(request).to.have.all.keys(['bidderRequest', 'data', 'method', 'url']); - }); - it('handles no ozone or custom data', function () { - const request = spec.buildRequests(validBidRequestsMinimal, validBidderRequest); - expect(request).to.have.all.keys(['bidderRequest', 'data', 'method', 'url']); - }); - it('handles video mediaType element correctly, with outstream video', function () { - const request = spec.buildRequests(validBidRequests1OutstreamVideo2020, validBidderRequest); - expect(request).to.have.all.keys(['bidderRequest', 'data', 'method', 'url']); - }); - it('should not crash when there is no sizes element at all', function () { - const request = spec.buildRequests(validBidRequestsNoSizes, validBidderRequest); - expect(request).to.have.all.keys(['bidderRequest', 'data', 'method', 'url']); - }); - it('should be able to handle non-single requests', function () { - config.setConfig({'ozone': {'singleRequest': false}}); - const request = spec.buildRequests(validBidRequestsNoSizes, validBidderRequest); - expect(request).to.be.a('array'); - expect(request[0]).to.have.all.keys(['bidderRequest', 'data', 'method', 'url']); - config.setConfig({'ozone': {'singleRequest': true}}); - }); - it('should add gdpr consent information to the request when ozone is true', function () { - const consentString = 'BOcocyaOcocyaAfEYDENCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NphLgA=='; - const bidderRequest = JSON.parse(JSON.stringify(validBidderRequest)); - bidderRequest.gdprConsent = { - consentString: consentString, - gdprApplies: true, - vendorData: { - metadata: consentString, - gdprApplies: true, - vendorConsents: {524: true}, - purposeConsents: {1: true, 2: true, 3: true, 4: true, 5: true} - } - } - const request = spec.buildRequests(validBidRequestsNoSizes, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.regs.ext.gdpr).to.equal(1); - expect(payload.user.ext.consent).to.equal(consentString); - }); - it('should add gdpr consent information to the request when vendorData is missing vendorConsents (Mirror)', function () { - const consentString = 'BOcocyaOcocyaAfEYDENCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NphLgA=='; - const bidderRequest = JSON.parse(JSON.stringify(validBidderRequest)); - bidderRequest.gdprConsent = { - consentString: consentString, - gdprApplies: true, - vendorData: { - metadata: consentString, - gdprApplies: true - } - } - const request = spec.buildRequests(validBidRequestsNoSizes, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.regs.ext.gdpr).to.equal(1); - expect(payload.user.ext.consent).to.equal(consentString); - }); - it('should set regs.ext.gdpr flag to 0 when gdprApplies is false', function () { - const consentString = 'BOcocyaOcocyaAfEYDENCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NphLgA=='; - const bidderRequest = JSON.parse(JSON.stringify(validBidderRequest)); - bidderRequest.gdprConsent = { - consentString: consentString, - gdprApplies: false, - vendorData: { - metadata: consentString, - gdprApplies: true, - vendorConsents: {}, - purposeConsents: {1: true, 2: true, 3: true, 4: true, 5: true} - } - }; - const request = spec.buildRequests(validBidRequestsNoSizes, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.regs.ext.gdpr).to.equal(0); - }); - it('should set gpp and gpp_sid when available', function() { - const gppString = 'gppConsentString'; - const gppSections = [7, 8, 9]; - const bidderRequest = JSON.parse(JSON.stringify(validBidderRequest)); - bidderRequest.ortb2 = {regs: {gpp: gppString, gpp_sid: gppSections}}; - const request = spec.buildRequests(validBidRequestsNoSizes, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.regs.ext.gpp).to.equal(gppString); - expect(payload.regs.ext.gpp_sid).to.have.same.members(gppSections); - }); - it('should not set gpp and gpp_sid keys when not available', function() { - const request = spec.buildRequests(validBidRequestsNoSizes, validBidderRequest); - const payload = JSON.parse(request.data); - expect(payload).to.not.contain.keys(['gpp', 'gpp_sid', 'ext', 'regs']); - }); - it('should not have imp[N].ext.ozone.userId', function () { - const consentString = 'BOcocyaOcocyaAfEYDENCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NphLgA=='; - const bidderRequest = JSON.parse(JSON.stringify(validBidderRequest)); - bidderRequest.gdprConsent = { - consentString: consentString, - gdprApplies: false, - vendorData: { - metadata: consentString, - gdprApplies: true, - vendorConsents: {524: true}, - purposeConsents: {1: true, 2: true, 3: true, 4: true, 5: true} - } - }; - const bidRequests = JSON.parse(JSON.stringify(validBidRequests)); - bidRequests[0]['userId'] = { - 'digitrustid': {data: {id: 'DTID', keyv: 4, privacy: {optout: false}, producer: 'ABC', version: 2}}, - 'id5id': { uid: '1111', ext: { linkType: 2, abTestingControlGroup: false } }, - 'idl_env': '3333', - 'parrableid': 'eidVersion.encryptionKeyReference.encryptedValue', - 'pubcid': '5555', - 'tdid': '6666', - 'sharedid': {'id': '01EAJWWNEPN3CYMM5N8M5VXY22', 'third': '01EAJWWNEPN3CYMM5N8M5VXY22'} - }; - bidRequests[0]['userIdAsEids'] = validBidRequestsWithUserIdData[0]['userIdAsEids']; - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - const firstBid = payload.imp[0].ext.ozone; - expect(firstBid).to.not.have.property('userId'); - }); - it('should pick up the value of pubcid when built using the pubCommonId module (not userId)', function () { - const bidRequests = validBidRequests; - const request = spec.buildRequests(bidRequests, validBidderRequest); - const payload = JSON.parse(request.data); - expect(payload.ext.ozone.pubcid).to.equal(bidRequests[0]['crumbs']['pubcid']); - }); - it('should add a user.ext.eids object to contain user ID data in the new location (Nov 2019) Updated Aug 2020', function() { - const request = spec.buildRequests(validBidRequestsWithUserIdData, validBidderRequest); - const payload = JSON.parse(request.data); - expect(payload.user).to.exist; - expect(payload.user.ext).to.exist; - expect(payload.user.ext.eids).to.exist; - expect(payload.user.ext.eids[0]['source']).to.equal('pubcid.org'); - expect(payload.user.ext.eids[0]['uids'][0]['id']).to.equal('12345678'); - expect(payload.user.ext.eids[1]['source']).to.equal('adserver.org'); - expect(payload.user.ext.eids[1]['uids'][0]['id']).to.equal('1111tdid'); - expect(payload.user.ext.eids[2]['source']).to.equal('id5-sync.com'); - expect(payload.user.ext.eids[2]['uids'][0]['id']).to.equal('ID5-someId'); - expect(payload.user.ext.eids[3]['source']).to.equal('criteoId'); - expect(payload.user.ext.eids[3]['uids'][0]['id']).to.equal('1111criteoId'); - expect(payload.user.ext.eids[4]['source']).to.equal('idl_env'); - expect(payload.user.ext.eids[4]['uids'][0]['id']).to.equal('liverampId'); - expect(payload.user.ext.eids[5]['source']).to.equal('lipb'); - expect(payload.user.ext.eids[5]['uids'][0]['id']['lipbid']).to.equal('lipbidId123'); - expect(payload.user.ext.eids[6]['source']).to.equal('parrableId'); - expect(payload.user.ext.eids[6]['uids'][0]['id']['eid']).to.equal('01.5678.parrableid'); - }); - it('replaces the auction url for a config override', function () { - const fakeOrigin = 'http://sometestendpoint'; - config.setConfig({'ozone': {'endpointOverride': {'origin': fakeOrigin}}}); - const request = spec.buildRequests(validBidRequests, validBidderRequest); - expect(request.url).to.equal(fakeOrigin + '/openrtb2/auction'); - expect(request.method).to.equal('POST'); - const data = JSON.parse(request.data); - expect(data.ext.ozone.origin).to.equal(fakeOrigin); - config.setConfig({'ozone': {'kvpPrefix': null, 'endpointOverride': null}}); - }); - it('replaces the FULL auction url for a config override', function () { - const fakeurl = 'http://sometestendpoint/myfullurl'; - config.setConfig({'ozone': {'endpointOverride': {'auctionUrl': fakeurl}}}); - const request = spec.buildRequests(validBidRequests, validBidderRequest); - expect(request.url).to.equal(fakeurl); - expect(request.method).to.equal('POST'); - const data = JSON.parse(request.data); - expect(data.ext.ozone.origin).to.equal(fakeurl); - config.setConfig({'ozone': {'kvpPrefix': null, 'endpointOverride': null}}); - }); - it('replaces the renderer url for a config override', function () { - const fakeUrl = 'http://renderer.com'; - config.setConfig({'ozone': {'endpointOverride': {'rendererUrl': fakeUrl}}}); - const result = spec.interpretResponse(getCleanValidVideoResponse(), validBidderRequest1OutstreamVideo2020); - const bid = result[0]; - expect(bid.renderer).to.be.an.instanceOf(Renderer); - expect(bid.renderer.url).to.equal(fakeUrl); - config.setConfig({'ozone': {'kvpPrefix': null, 'endpointOverride': null}}); - }); - it('should create a meta object on each bid returned', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.interpretResponse(validResponse, request); - expect(result[0]).to.have.own.property('meta'); - expect(result[0].meta.advertiserDomains[0]).to.equal('http://prebid.org'); - }); - it('should use oztestmode GET value if set', function() { - var specMock = utils.deepClone(spec); - specMock.getGetParametersAsObject = function() { - return {'oztestmode': 'mytestvalue_123'}; - }; - const request = specMock.buildRequests(validBidRequests, validBidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].ext.ozone.customData).to.be.an('array'); - expect(data.imp[0].ext.ozone.customData[0].targeting.oztestmode).to.equal('mytestvalue_123'); - }); - it('should ignore these GET params if present (removed 202410): ozf, ozpf, ozrp, ozip', function() { - var specMock = utils.deepClone(spec); - specMock.getGetParametersAsObject = function() { - return {ozf: '1', ozpf: '10', ozrp: '2', ozip: '123'}; - }; - const request = specMock.buildRequests(validBidRequests, validBidderRequest); - const data = JSON.parse(request.data); - expect(data.ext.ozone).to.not.have.any.keys('zf', 'ozpf', 'ozrp', 'ozip'); - }); - it('should use oztestmode GET value if set, even if there is no customdata in config', function() { - var specMock = utils.deepClone(spec); - specMock.getGetParametersAsObject = function() { - return {'oztestmode': 'mytestvalue_123'}; - }; - const request = specMock.buildRequests(validBidRequestsMinimal, validBidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].ext.ozone.customData).to.be.an('array'); - expect(data.imp[0].ext.ozone.customData[0].targeting.oztestmode).to.equal('mytestvalue_123'); - }); - it('should pass gpid to auction if it is present (gptPreAuction adapter sets this)', function () { - var specMock = utils.deepClone(spec); - const br = JSON.parse(JSON.stringify(validBidRequests)); - utils.deepSetValue(br[0], 'ortb2Imp.ext.gpid', '/22037345/projectozone'); - const request = specMock.buildRequests(br, validBidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].ext.gpid).to.equal('/22037345/projectozone'); - }); - it('should batch into 10s if config is set to true', function () { - config.setConfig({ozone: {'batchRequests': true}}); - var specMock = utils.deepClone(spec); - const arrReq = []; - for (let i = 0; i < 25; i++) { - const b = validBidRequests[0]; - b.adUnitCode += i; - arrReq.push(b); - } - const request = specMock.buildRequests(arrReq, validBidderRequest); - expect(request.length).to.equal(3); - config.resetConfig(); - }); - it('should batch into 7 if config is set to 7', function () { - config.setConfig({ozone: {'batchRequests': 7}}); - var specMock = utils.deepClone(spec); - const arrReq = []; - for (let i = 0; i < 25; i++) { - const b = validBidRequests[0]; - b.adUnitCode += i; - arrReq.push(b); - } - const request = specMock.buildRequests(arrReq, validBidderRequest); - expect(request.length).to.equal(4); - config.resetConfig(); - }); - it('should not batch if config is set to false and singleRequest is true', function () { - config.setConfig({ozone: {'batchRequests': false, 'singleRequest': true}}); - var specMock = utils.deepClone(spec); - const arrReq = []; - for (let i = 0; i < 15; i++) { - const b = validBidRequests[0]; - b.adUnitCode += i; - arrReq.push(b); - } - const request = specMock.buildRequests(arrReq, validBidderRequest); - expect(request.method).to.equal('POST'); - config.resetConfig(); - }); - it('should not batch if config is set to invalid value -10 and singleRequest is true', function () { - config.setConfig({ozone: {'batchRequests': -10, 'singleRequest': true}}); - var specMock = utils.deepClone(spec); - const arrReq = []; - for (let i = 0; i < 15; i++) { - const b = validBidRequests[0]; - b.adUnitCode += i; - arrReq.push(b); - } - const request = specMock.buildRequests(arrReq, validBidderRequest); - expect(request.method).to.equal('POST'); - config.resetConfig(); - }); - it('should use GET values for batchRequests if found', function() { - var specMock = utils.deepClone(spec); - specMock.getGetParametersAsObject = function() { - return {'batchRequests': '5'}; - }; - const arrReq = []; - for (let i = 0; i < 25; i++) { - const b = validBidRequests[0]; - b.adUnitCode += i; - arrReq.push(b); - } - let request = specMock.buildRequests(arrReq, validBidderRequest); - expect(request.length).to.equal(5); - specMock = utils.deepClone(spec); - specMock.getGetParametersAsObject = function() { - return {'batchRequests': '10'}; - }; - request = specMock.buildRequests(arrReq, validBidderRequest); - expect(request.length).to.equal(3); - specMock = utils.deepClone(spec); - specMock.getGetParametersAsObject = function() { - return {'batchRequests': true}; - }; - request = specMock.buildRequests(arrReq, validBidderRequest); - expect(request.method).to.equal('POST'); - specMock = utils.deepClone(spec); - specMock.getGetParametersAsObject = function() { - return {'batchRequests': 'true'}; - }; - request = specMock.buildRequests(arrReq, validBidderRequest); - expect(request.method).to.equal('POST'); - specMock = utils.deepClone(spec); - specMock.getGetParametersAsObject = function() { - return {'batchRequests': -5}; - }; - request = specMock.buildRequests(arrReq, validBidderRequest); - expect(request.method).to.equal('POST'); - }); - it('should use a valid ozstoredrequest GET value if set to override the placementId values, and set oz_rw if we find it', function() { - var specMock = utils.deepClone(spec); - specMock.getGetParametersAsObject = function() { - return {'ozstoredrequest': '1122334455'}; - }; - const request = specMock.buildRequests(validBidRequestsMinimal, validBidderRequest); - const data = JSON.parse(request.data); - expect(data.ext.ozone.oz_rw).to.equal(1); - expect(data.imp[0].ext.prebid.storedrequest.id).to.equal('1122334455'); - }); - it('should NOT use an invalid ozstoredrequest GET value if set to override the placementId values, and set oz_rw to 0', function() { - var specMock = utils.deepClone(spec); - specMock.getGetParametersAsObject = function() { - return {'ozstoredrequest': 'BADVAL'}; - }; - const request = specMock.buildRequests(validBidRequestsMinimal, validBidderRequest); - const data = JSON.parse(request.data); - expect(data.ext.ozone.oz_rw).to.equal(0); - expect(data.imp[0].ext.prebid.storedrequest.id).to.equal('1310000099'); - }); - it('should pick up the config value of coppa & set it in the request', function () { - config.setConfig({'coppa': true}); - const request = spec.buildRequests(validBidRequestsNoSizes, validBidderRequest); - const payload = JSON.parse(request.data); - expect(payload.regs).to.include.keys('coppa'); - expect(payload.regs.coppa).to.equal(1); - config.resetConfig(); - }); - it('should pick up the config value of coppa & only set it in the request if its true', function () { - config.setConfig({'coppa': false}); - const request = spec.buildRequests(validBidRequestsNoSizes, validBidderRequest); - const payload = JSON.parse(request.data); - expect(utils.deepAccess(payload, 'regs.coppa')).to.be.undefined; - config.resetConfig(); - }); - it('should handle oz_omp_floor correctly', function () { - config.setConfig({'ozone': {'oz_omp_floor': 1.56}}); - const request = spec.buildRequests(validBidRequestsNoSizes, validBidderRequest); - const payload = JSON.parse(request.data); - expect(utils.deepAccess(payload, 'ext.ozone.oz_omp_floor')).to.equal(1.56); - config.resetConfig(); - }); - it('should ignore invalid oz_omp_floor values', function () { - config.setConfig({'ozone': {'oz_omp_floor': '1.56'}}); - const request = spec.buildRequests(validBidRequestsNoSizes, validBidderRequest); - const payload = JSON.parse(request.data); - expect(utils.deepAccess(payload, 'ext.ozone.oz_omp_floor')).to.be.undefined; - config.resetConfig(); - }); - it('should handle a valid ozFloor string value in the adunit correctly', function () { - const cloneBidRequests = JSON.parse(JSON.stringify(validBidRequests)); - cloneBidRequests[0].params.ozFloor = '0.1234'; - const request = spec.buildRequests(cloneBidRequests, validBidderRequest); - const payload = JSON.parse(request.data); - expect(utils.deepAccess(payload, 'imp.0.ext.ozone.ozFloor')).to.equal(0.1234); - }); - it('should handle a valid ozFloor float value in the adunit correctly', function () { - const cloneBidRequests = JSON.parse(JSON.stringify(validBidRequests)); - cloneBidRequests[0].params.ozFloor = 0.1234; - const request = spec.buildRequests(cloneBidRequests, validBidderRequest); - const payload = JSON.parse(request.data); - expect(utils.deepAccess(payload, 'imp.0.ext.ozone.ozFloor')).to.equal(0.1234); - }); - it('should ignore an invalid ozFloor string value in the adunit correctly', function () { - const cloneBidRequests = JSON.parse(JSON.stringify(validBidRequests)); - cloneBidRequests[0].params.ozFloor = 'this is no good!'; - const request = spec.buildRequests(cloneBidRequests, validBidderRequest); - const payload = JSON.parse(request.data); - expect(utils.deepAccess(payload, 'imp.0.ext.ozone.ozFloor', null)).to.be.null; - }); - it('should should contain a unique page view id in the auction request which persists across calls', function () { - let request = spec.buildRequests(validBidRequests, validBidderRequest); - const payload = JSON.parse(request.data); - expect(utils.deepAccess(payload, 'ext.ozone.pv')).to.be.a('string'); - request = spec.buildRequests(validBidRequests1OutstreamVideo2020, validBidderRequest); - const payload2 = JSON.parse(request.data); - expect(utils.deepAccess(payload2, 'ext.ozone.pv')).to.be.a('string'); - expect(utils.deepAccess(payload2, 'ext.ozone.pv')).to.equal(utils.deepAccess(payload, 'ext.ozone.pv')); - }); - it('should indicate that the whitelist was used when it contains valid data', function () { - config.setConfig({'ozone': {'oz_whitelist_adserver_keys': ['oz_ozappnexus_pb', 'oz_ozappnexus_imp_id']}}); - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const payload = JSON.parse(request.data); - expect(payload.ext.ozone.oz_kvp_rw).to.equal(1); - }); - it('should indicate that the whitelist was not used when it contains no data', function () { - config.setConfig({'ozone': {'oz_whitelist_adserver_keys': []}}); - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const payload = JSON.parse(request.data); - expect(payload.ext.ozone.oz_kvp_rw).to.equal(0); - }); - it('should indicate that the whitelist was not used when it is not set in the config', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const payload = JSON.parse(request.data); - expect(payload.ext.ozone.oz_kvp_rw).to.equal(0); - }); - it('should handle ortb2 site data', function () { - const bidderRequest = JSON.parse(JSON.stringify(validBidderRequest)); - bidderRequest.ortb2 = { - 'site': { - 'name': 'example_ortb2_name', - 'domain': 'page.example.com', - 'cat': ['IAB2'], - 'sectioncat': ['IAB2-2'], - 'pagecat': ['IAB2-2'], - 'page': 'https://page.example.com/here.html', - 'ref': 'https://ref.example.com', - 'keywords': 'power tools, drills', - 'search': 'drill' - } - }; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.imp[0].ext.ozone.customData[0].targeting.name).to.equal('example_ortb2_name'); - expect(payload.user.ext).to.not.have.property('gender'); - }); - it('should add ortb2 site data when there is no customData already created', function () { - const bidderRequest = JSON.parse(JSON.stringify(validBidderRequest)); - bidderRequest.ortb2 = { - 'site': { - 'name': 'example_ortb2_name', - 'domain': 'page.example.com', - 'cat': ['IAB2'], - 'sectioncat': ['IAB2-2'], - 'pagecat': ['IAB2-2'], - 'page': 'https://page.example.com/here.html', - 'ref': 'https://ref.example.com', - 'keywords': 'power tools, drills', - 'search': 'drill' - } - }; - const request = spec.buildRequests(validBidRequestsNoCustomData, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.imp[0].ext.ozone.customData[0].targeting.name).to.equal('example_ortb2_name'); - expect(payload.imp[0].ext.ozone.customData[0].targeting).to.not.have.property('gender') - }); - it('should add ortb2 user data to the user object', function () { - const bidderRequest = JSON.parse(JSON.stringify(validBidderRequest)); - bidderRequest.ortb2 = { - 'user': { - 'gender': 'I identify as a box of rocks' - } - }; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.user.gender).to.equal('I identify as a box of rocks'); - }); - it('should not override the user.ext.consent string even if this is set in config ortb2', function () { - const bidderRequest = JSON.parse(JSON.stringify(bidderRequestWithFullGdpr)); - bidderRequest.ortb2 = { - 'user': { - 'ext': { - 'consent': 'this is the consent override that shouldnt work', - 'consent2': 'this should be set' - } - } - }; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.user.ext.consent2).to.equal('this should be set'); - expect(payload.user.ext.consent).to.equal('BOh7mtYOh7mtYAcABBENCU-AAAAncgPIXJiiAoao0PxBFkgCAC8ACIAAQAQQAAIAAAIAAAhBGAAAQAQAEQgAAAAAAABAAAAAAAAAAAAAAACAAAAAAAACgAAAAABAAAAQAAAAAAA'); - }); - it('should have openrtb video params', function() { - const allowed = ['mimes', 'minduration', 'maxduration', 'protocols', 'w', 'h', 'startdelay', 'placement', 'linearity', 'skip', 'skipmin', 'skipafter', 'sequence', 'battr', 'maxextended', 'minbitrate', 'maxbitrate', 'boxingallowed', 'playbackmethod', 'playbackend', 'delivery', 'pos', 'companionad', 'api', 'companiontype', 'ext']; - const request = spec.buildRequests(validBidRequests1OutstreamVideo2020, validBidderRequest); - const payload = JSON.parse(request.data); - const vid = (payload.imp[0].video); - const keys = Object.keys(vid); - for (let i = 0; i < keys.length; i++) { - expect(allowed).to.include(keys[i]); - } - expect(payload.imp[0].video.ext).to.include({'context': 'outstream'}); - }); - it('should handle standard floor config correctly', function () { - config.setConfig({ - floors: { - enforcement: { - floorDeals: false, - bidAdjustment: true - }, - data: { - currency: 'USD', - schema: { - fields: ['mediaType'] - }, - values: { - 'video': 1.20, - 'banner': 0.8 - } - } - } - }); - const localBidRequest = JSON.parse(JSON.stringify(validBidRequestsWithBannerMediaType)); - localBidRequest[0].getFloor = function(x) { return {'currency': 'USD', 'floor': 0.8} }; - const request = spec.buildRequests(localBidRequest, validBidderRequest); - const payload = JSON.parse(request.data); - expect(utils.deepAccess(payload, 'imp.0.floor.banner.currency')).to.equal('USD'); - expect(utils.deepAccess(payload, 'imp.0.floor.banner.floor')).to.equal(0.8); - }); - it(' (getFloorObjectForAuction) should handle advanced/custom floor config function correctly (note you cant fully test floor functionality because it relies on the floor module - only our code that interacts with it; we must extract the first w/h pair)', function () { - const testBidObject = { - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - }, - video: { - playerSize: [[640, 360]] - }, - native: { - image: { - sizes: [[300, 250], [640, 480]] - } - } - }, - getFloor: function(obj) { - return obj.size; - } - }; - const floorObject = spec.getFloorObjectForAuction(testBidObject); - expect(floorObject.banner).to.deep.equal([300, 250]); - expect(floorObject.video).to.deep.equal([640, 360]); - expect(floorObject.native).to.deep.equal([300, 250]); - }); - it('handles schain object in each bidrequest (will be the same in each br)', function () { - const br = JSON.parse(JSON.stringify(validBidRequests)); - const schainConfigObject = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'bidderA.com', - 'sid': '00001', - 'hp': 1 - } - ] - }; - br[0].ortb2 = br[0].ortb2 || {}; - br[0].ortb2.source = br[0].ortb2.source || {}; - br[0].ortb2.source.ext = br[0].ortb2.source.ext || {}; - br[0].ortb2.source.ext.schain = schainConfigObject; - const request = spec.buildRequests(br, validBidderRequest); - const data = JSON.parse(request.data); - expect(data.source.ext).to.haveOwnProperty('schain'); - expect(data.source.ext.schain).to.deep.equal(schainConfigObject); - }); - it('should find ortb2 cookieDeprecation values', function () { - const bidderRequest = JSON.parse(JSON.stringify(validBidderRequestWithCookieDeprecation)); - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.ext.ozone.cookieDeprecationLabel).to.equal('fake_control_2'); - }); - it('should set ortb2 cookieDeprecation to "none" if there is none', function () { - const bidderRequest = JSON.parse(JSON.stringify(validBidderRequest)); - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.ext.ozone.cookieDeprecationLabel).to.equal('none'); - }); - it('should handle fledge requests', function () { - const bidderRequest = JSON.parse(JSON.stringify(validBidderRequest)); - const bidRequests = JSON.parse(JSON.stringify(validBidRequests)); - deepSetValue(bidRequests[0], 'ortb2Imp.ext.ae', 1); - bidderRequest.fledgeEnabled = true; - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.imp[0].ext.ae).to.equal(1); - }); - it('Single request: should use ortb auction ID & transaction ID values if set (this will be the case when publisher opts in with config)', function() { - var specMock = utils.deepClone(spec); - config.setConfig({'ozone': {'singleRequest': true}}); - const request = specMock.buildRequests(validBidRequestsWithAuctionIdTransactionId, validBidderRequest); - expect(request).to.be.an('Object'); - const payload = JSON.parse(request.data); - expect(payload.source.tid).to.equal(validBidRequestsWithAuctionIdTransactionId[0].ortb2.source.tid); - expect(payload.imp[0].ext.auctionId).to.equal(validBidRequestsWithAuctionIdTransactionId[0].ortb2.source.tid); - expect(payload.imp[0].ext.tid).to.equal(validBidRequestsWithAuctionIdTransactionId[0].ortb2Imp.ext.tid); - config.resetConfig(); - }); - it('non-Single request: should use ortb auction ID & transaction ID values if set (this will be the case when publisher opts in with config)', function() { - var specMock = utils.deepClone(spec); - config.setConfig({'ozone': {'singleRequest': false}}); - const request = specMock.buildRequests(validBidRequestsWithAuctionIdTransactionId, validBidderRequest); - expect(request).to.be.an('Array'); - const payload = JSON.parse(request[0].data); - expect(payload.source.tid).to.equal(validBidRequestsWithAuctionIdTransactionId[0].ortb2.source.tid); - expect(payload.imp[0].ext.auctionId).to.equal(validBidRequestsWithAuctionIdTransactionId[0].ortb2.source.tid); - expect(payload.imp[0].ext.tid).to.equal(validBidRequestsWithAuctionIdTransactionId[0].ortb2Imp.ext.tid); - config.resetConfig(); - }); - it('Batch request (flat array of single requests): should use ortb auction ID & transaction ID values if set (this will be the case when publisher opts in with config)', function() { - var specMock = utils.deepClone(spec); - config.setConfig({'ozone': {'batchRequests': 3}}); - const request = specMock.buildRequests(valid6BidRequestsWithAuctionIdTransactionId, validBidderRequest); - expect(request).to.be.an('Array'); - expect(request).to.have.lengthOf(2); - const payload = JSON.parse(request[0].data); - expect(payload.source.tid).to.equal(valid6BidRequestsWithAuctionIdTransactionId[0].ortb2.source.tid); - expect(payload.imp[0].ext.auctionId).to.equal(valid6BidRequestsWithAuctionIdTransactionId[0].ortb2.source.tid); - expect(payload.imp[0].ext.tid).to.equal(valid6BidRequestsWithAuctionIdTransactionId[0].ortb2Imp.ext.tid); - config.resetConfig(); - }); - it('should handle ortb2 device data', function () { - const bidderRequest = JSON.parse(JSON.stringify(validBidderRequest)); - bidderRequest.ortb2 = { - device: { - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - ext: {fiftyonedegrees_deviceId: '17595-133085-133468-18092'}, - }, - }; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.device).to.deep.equal(bidderRequest.ortb2.device); - }); - }); - describe('interpretResponse', function () { - beforeEach(function () { - config.resetConfig() - }) - it('should build bid array', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.interpretResponse(validResponse, request); - expect(result.length).to.equal(1); - }); - it('should have all relevant fields', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.interpretResponse(validResponse, request); - const bid = result[0]; - expect(bid.cpm).to.equal(validResponse.body.seatbid[0].bid[0].cpm); - expect(bid.width).to.equal(validResponse.body.seatbid[0].bid[0].width); - expect(bid.height).to.equal(validResponse.body.seatbid[0].bid[0].height); - }); - it('should build bid array with gdpr', function () { - const validBR = JSON.parse(JSON.stringify(bidderRequestWithFullGdpr)); - validBR.gdprConsent = {'gdprApplies': 1, 'consentString': 'This is the gdpr consent string'}; - const request = spec.buildRequests(validBidRequests, validBR); - const result = spec.interpretResponse(validResponse, request); - expect(result.length).to.equal(1); - }); - it('should build bid array with usp/CCPA', function () { - const validBR = JSON.parse(JSON.stringify(bidderRequestWithFullGdpr)); - validBR.uspConsent = '1YNY'; - const request = spec.buildRequests(validBidRequests, validBR); - const payload = JSON.parse(request.data); - expect(payload.user.ext.uspConsent).not.to.exist; - expect(payload.regs.ext.us_privacy).to.equal('1YNY'); - }); - it('should build bid array with only partial gdpr', function () { - var validBidderRequestWithGdpr = bidderRequestWithPartialGdpr.bidderRequest; - validBidderRequestWithGdpr.gdprConsent = {'gdprApplies': 1, 'consentString': 'This is the gdpr consent string'}; - const request = spec.buildRequests(validBidRequests, validBidderRequestWithGdpr); - const payload = JSON.parse(request.data); - expect(payload.user.ext.consent).to.be.a('string'); - }); - it('should fail ok if no seatbid in server response', function () { - const result = spec.interpretResponse({}, {}); - expect(result).to.be.an('array'); - expect(result).to.be.empty; - }); - it('should fail ok if seatbid is not an array', function () { - const result = spec.interpretResponse({'body': {'seatbid': 'nothing_here'}}, {}); - expect(result).to.be.an('array'); - expect(result).to.be.empty; - }); - it('should have video renderer for outstream video', function () { - const result = spec.interpretResponse(getCleanValidVideoResponse(), validBidderRequest1OutstreamVideo2020); - const bid = result[0]; - expect(bid.renderer).to.be.an.instanceOf(Renderer); - }); - it('should have NO video renderer for instream video', function () { - const instreamRequestsObj = JSON.parse(JSON.stringify(validBidRequests1OutstreamVideo2020)); - instreamRequestsObj[0].mediaTypes.video.context = 'instream'; - const instreamBidderReq = JSON.parse(JSON.stringify(validBidderRequest1OutstreamVideo2020)); - instreamBidderReq.bidderRequest.bids[0].mediaTypes.video.context = 'instream'; - const result = spec.interpretResponse(getCleanValidVideoResponse(), instreamBidderReq); - const bid = result[0]; - expect(bid.hasOwnProperty('renderer')).to.be.false; - }); - it('should correctly parse response where there are more bidders than ad slots', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.interpretResponse(validBidResponse1adWith2Bidders, request); - expect(result.length).to.equal(2); - }); - it('should have a ttl of 600', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.interpretResponse(validResponse, request); - expect(result[0].ttl).to.equal(300); - }); - it('should handle oz_omp_floor_dollars correctly, inserting 1 as necessary', function () { - config.setConfig({'ozone': {'oz_omp_floor': 0.01}}); - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.interpretResponse(validResponse, request); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_omp')).to.equal('1'); - }); - it('should handle oz_omp_floor_dollars correctly, inserting 0 as necessary', function () { - config.setConfig({'ozone': {'oz_omp_floor': 2.50}}); - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.interpretResponse(validResponse, request); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_omp')).to.equal('0'); - }); - it('should handle missing oz_omp_floor_dollars correctly, inserting nothing', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.interpretResponse(validResponse, request); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_omp')).to.be.undefined; - }); - it('should handle ext.bidder.ozone.floor correctly, setting flr & rid as necessary', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const vres = JSON.parse(JSON.stringify(validResponse)); - vres.body.seatbid[0].bid[0].ext.bidder.ozone = {floor: 1, ruleId: 'ZjbsYE1q'}; - const result = spec.interpretResponse(vres, request); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_flr')).to.equal(1); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_rid')).to.equal('ZjbsYE1q'); - }); - it('should handle ext.bidder.ozone.floor correctly, inserting 0 as necessary', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const vres = JSON.parse(JSON.stringify(validResponse)); - vres.body.seatbid[0].bid[0].ext.bidder.ozone = {floor: 0, ruleId: 'ZjbXXE1q'}; - const result = spec.interpretResponse(vres, request); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_flr')).to.equal(0); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_rid')).to.equal('ZjbXXE1q'); - }); - it('should handle ext.bidder.ozone.floor correctly, inserting nothing as necessary', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const vres = JSON.parse(JSON.stringify(validResponse)); - vres.body.seatbid[0].bid[0].ext.bidder.ozone = {}; - const result = spec.interpretResponse(vres, request); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_flr', null)).to.equal(null); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_rid', null)).to.equal(null); - }); - it('should handle ext.bidder.ozone.floor correctly, when bidder.ozone is not there', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const vres = JSON.parse(JSON.stringify(validResponse)); - const result = spec.interpretResponse(vres, request); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_flr', null)).to.equal(null); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_rid', null)).to.equal(null); - }); - it('should handle a valid whitelist, removing items not on the list & leaving others', function () { - config.setConfig({'ozone': {'oz_whitelist_adserver_keys': ['oz_appnexus_crid', 'oz_appnexus_adId']}}); - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.interpretResponse(validResponse, request); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_adv')).to.be.undefined; - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_adId')).to.equal('2899ec066a91ff8-0-oz-0'); - }); - it('should ignore a whitelist if enhancedAdserverTargeting is false', function () { - config.setConfig({'ozone': {'oz_whitelist_adserver_keys': ['oz_appnexus_crid', 'oz_appnexus_imp_id'], 'enhancedAdserverTargeting': false}}); - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.interpretResponse(validResponse, request); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_adv')).to.be.undefined; - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_imp_id')).to.be.undefined; - }); - it('should correctly handle enhancedAdserverTargeting being false', function () { - config.setConfig({'ozone': {'enhancedAdserverTargeting': false}}); - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.interpretResponse(validResponse, request); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_adv')).to.be.undefined; - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_imp_id')).to.be.undefined; - }); - it('should add flr into ads request if floor exists in the auction response', function () { - const request = spec.buildRequests(validBidRequestsMulti, validBidderRequest); - const validres = JSON.parse(JSON.stringify(validResponse2Bids)); - validres.body.seatbid[0].bid[0].ext.bidder.ozone = {'floor': 1}; - const result = spec.interpretResponse(validres, request); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_flr')).to.equal(1); - expect(utils.deepAccess(result[1].adserverTargeting, 'oz_appnexus_flr', '')).to.equal(''); - }); - it('should add rid into ads request if ruleId exists in the auction response', function () { - const request = spec.buildRequests(validBidRequestsMulti, validBidderRequest); - const validres = JSON.parse(JSON.stringify(validResponse2Bids)); - validres.body.seatbid[0].bid[0].ext.bidder.ozone = {'ruleId': 123}; - const result = spec.interpretResponse(validres, request); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_rid')).to.equal(123); - expect(utils.deepAccess(result[1].adserverTargeting, 'oz_appnexus_rid', '')).to.equal(''); - }); - it('should add oz_auc_id (response id value)', function () { - const request = spec.buildRequests(validBidRequestsMulti, validBidderRequest); - const validres = JSON.parse(JSON.stringify(validBidResponse1adWith2Bidders)); - const result = spec.interpretResponse(validres, request); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_auc_id')).to.equal(validBidResponse1adWith2Bidders.body.id); - }); - it('should add unique adId values to each bid', function() { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const validres = JSON.parse(JSON.stringify(validResponse2BidsSameAdunit)); - const result = spec.interpretResponse(validres, request); - expect(result.length).to.equal(1); - expect(result[0]['price']).to.equal(0.9); - expect(result[0]['adserverTargeting']['oz_ozappnexus_adId']).to.equal('2899ec066a91ff8-0-oz-1'); - }); - it('should correctly process an auction with 2 adunits & multiple bidders one of which bids for both adslots', function() { - let validres = JSON.parse(JSON.stringify(multiResponse1)); - let request = spec.buildRequests(multiRequest1, multiBidderRequest1); - let result = spec.interpretResponse(validres, request); - expect(result.length).to.equal(4); - expect(result[1]['impid']).to.equal('3025f169863b7f8'); - expect(result[1]['id']).to.equal('18552976939844999'); - expect(result[1]['price']).to.equal(0.521); - expect(result[1]['adserverTargeting']['oz_ozappnexus_adId']).to.equal('3025f169863b7f8-0-oz-2'); - validres = JSON.parse(JSON.stringify(multiResponse1)); - validres.body.seatbid[0].bid[1].price = 1.1; - validres.body.seatbid[0].bid[1].cpm = 1.1; - request = spec.buildRequests(multiRequest1, multiBidderRequest1); - result = spec.interpretResponse(validres, request); - expect(result[1]['price']).to.equal(1.1); - expect(result[1]['impid']).to.equal('3025f169863b7f8'); - expect(result[1]['id']).to.equal('18552976939844681'); - expect(result[1]['adserverTargeting']['oz_ozappnexus_adId']).to.equal('3025f169863b7f8-0-oz-1'); - }); - it('should add mediaType: banner for a banner ad', function () { - const request = spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.interpretResponse(validResponse, request); - expect(result[0].mediaType).to.equal('banner'); - }); - it('should add mediaType: video for a video ad', function () { - const instreamRequestsObj = JSON.parse(JSON.stringify(validBidRequests1OutstreamVideo2020)); - instreamRequestsObj[0].mediaTypes.video.context = 'instream'; - const instreamBidderReq = JSON.parse(JSON.stringify(validBidderRequest1OutstreamVideo2020)); - instreamBidderReq.bidderRequest.bids[0].mediaTypes.video.context = 'instream'; - const result = spec.interpretResponse(getCleanValidVideoResponse(), instreamBidderReq); - const bid = result[0]; - expect(bid.mediaType).to.equal('video'); - }); - it('should handle fledge response', function () { - const req = spec.buildRequests(validBidRequests, validBidderRequest); - const objResp = JSON.parse(JSON.stringify(validResponse)); - objResp.body.ext = {igi: [{ - 'impid': '1', - 'igb': [{ - 'origin': 'https://paapi.dsp.com', - 'pbs': '{"key": "value"}' - }] - }]}; - const result = spec.interpretResponse(objResp, req); - expect(result).to.be.an('object'); - expect(result.fledgeAuctionConfigs[0]['impid']).to.equal('1'); - }); - it('should add labels in the adserver request if they are present in the auction response', function () { - const request = spec.buildRequests(validBidRequestsMulti, validBidderRequest); - const validres = JSON.parse(JSON.stringify(validResponse2Bids)); - validres.body.seatbid.push(JSON.parse(JSON.stringify(validres.body.seatbid[0]))); - validres.body.seatbid[1].seat = 'marktest'; - validres.body.seatbid[1].bid[0].ext.prebid.labels = ['b1', 'b2', 'b3']; - validres.body.seatbid[1].bid[0].price = 10; - validres.body.seatbid[1].bid[1].price = 0; - validres.body.seatbid[0].bid[0].ext.prebid.labels = ['bid1label1', 'bid1label2', 'bid1label3']; - validres.body.seatbid[0].bid[1].ext.prebid.labels = ['bid2label']; - const result = spec.interpretResponse(validres, request); - expect(result.length).to.equal(4); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_winner')).to.equal('marktest'); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_labels')).to.equal('b1,b2,b3'); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_labels')).to.equal('bid1label1,bid1label2,bid1label3'); - expect(utils.deepAccess(result[1].adserverTargeting, 'oz_winner')).to.equal('appnexus'); - expect(utils.deepAccess(result[1].adserverTargeting, 'oz_appnexus_labels')).to.equal('bid2label'); - expect(utils.deepAccess(result[1].adserverTargeting, 'oz_labels')).to.equal('bid2label'); - expect(utils.deepAccess(result[2].adserverTargeting, 'oz_labels')).to.equal('b1,b2,b3'); - expect(utils.deepAccess(result[3].adserverTargeting, 'oz_labels')).to.equal('bid2label'); - }); - it('should not add labels in the adserver request if they are present in the auction response when config contains ozone.enhancedAdserverTargeting', function () { - config.setConfig({'ozone': {'enhancedAdserverTargeting': false}}); - const request = spec.buildRequests(validBidRequestsMulti, validBidderRequest); - const validres = JSON.parse(JSON.stringify(validResponse2Bids)); - validres.body.seatbid.push(JSON.parse(JSON.stringify(validres.body.seatbid[0]))); - validres.body.seatbid[1].seat = 'marktest'; - validres.body.seatbid[1].bid[0].ext.prebid.labels = ['b1', 'b2', 'b3']; - validres.body.seatbid[1].bid[0].price = 10; - validres.body.seatbid[1].bid[1].price = 0; - validres.body.seatbid[0].bid[0].ext.prebid.labels = ['bid1label1', 'bid1label2', 'bid1label3']; - validres.body.seatbid[0].bid[1].ext.prebid.labels = ['bid2label']; - const result = spec.interpretResponse(validres, request); - expect(result.length).to.equal(4); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_winner')).to.equal('marktest'); - expect(result[0].adserverTargeting).to.not.have.property('oz_labels'); - expect(result[0].adserverTargeting).to.not.have.property('oz_appnexus_labels'); - expect(utils.deepAccess(result[1].adserverTargeting, 'oz_winner')).to.equal('appnexus'); - expect(result[1].adserverTargeting).to.not.have.property('oz_appnexus_labels'); - expect(result[1].adserverTargeting).to.not.have.property('oz_labels'); - expect(result[2].adserverTargeting).to.not.have.property('oz_labels'); - expect(result[3].adserverTargeting).to.not.have.property('oz_labels'); - config.resetConfig(); - }); - }); - describe('userSyncs', function () { - it('should fail gracefully if no server response', function () { - const result = spec.getUserSyncs('bad', false, gdpr1); - expect(result).to.be.empty; - }); - it('should fail gracefully if server response is empty', function () { - const result = spec.getUserSyncs('bad', [], gdpr1); - expect(result).to.be.empty; - }); - it('should append the various values if they exist', function() { - spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.getUserSyncs({iframeEnabled: true}, 'good server response', gdpr1); - expect(result).to.be.an('array'); - expect(result[0].url).to.include('publisherId=9876abcd12-3'); - expect(result[0].url).to.include('siteId=1234567890'); - expect(result[0].url).to.include('gdpr=1'); - expect(result[0].url).to.include('gdpr_consent=BOh7mtYOh7mtYAcABBENCU-AAAAncgPIXJiiAoao0PxBFkgCAC8ACIAAQAQQAAIAAAIAAAhBGAAAQAQAEQgAAAAAAABAAAAAAAAAAAAAAACAAAAAAAACgAAAAABAAAAQAAAAAAA'); - }); - it('should append ccpa (usp data)', function() { - spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.getUserSyncs({iframeEnabled: true}, 'good server response', gdpr1, '1YYN'); - expect(result).to.be.an('array'); - expect(result[0].url).to.include('usp_consent=1YYN'); - }); - it('should use "" if no usp is sent to cookieSync', function() { - spec.buildRequests(validBidRequests, validBidderRequest); - const result = spec.getUserSyncs({iframeEnabled: true}, 'good server response', gdpr1); - expect(result).to.be.an('array'); - expect(result[0].url).to.include('usp_consent=&'); - }); - it('should add gpp if its present', function () { - const result = spec.getUserSyncs({iframeEnabled: true}, 'good server response', gdpr1, '1---', { gppString: 'gppStringHere', applicableSections: [7, 8, 9] }); - expect(result[0].url).to.include('gpp=gppStringHere&gpp_sid=7,8,9'); - }); - }); - describe('video object utils', function () { - it('should find width & height from video object', function () { - const obj = {'playerSize': [640, 480], 'mimes': ['video/mp4'], 'context': 'outstream'}; - const result = getWidthAndHeightFromVideoObject(obj); - expect(result.w).to.equal(640); - expect(result.h).to.equal(480); - }); - it('should find null from bad video object', function () { - const obj = {'playerSize': [], 'mimes': ['video/mp4'], 'context': 'outstream'}; - const result = getWidthAndHeightFromVideoObject(obj); - expect(result).to.be.null; - }); - it('should find null from bad video object2', function () { - const obj = {'mimes': ['video/mp4'], 'context': 'outstream'}; - const result = getWidthAndHeightFromVideoObject(obj); - expect(result).to.be.null; - }); - it('should find null from bad video object3', function () { - const obj = {'playerSize': 'should be an array', 'mimes': ['video/mp4'], 'context': 'outstream'}; - const result = getWidthAndHeightFromVideoObject(obj); - expect(result).to.be.null; - }); - it('should find that player size is nested', function () { - const obj = {'playerSize': [[640, 480]], 'mimes': ['video/mp4'], 'context': 'outstream'}; - const result = getWidthAndHeightFromVideoObject(obj); - expect(result.w).to.equal(640); - expect(result.h).to.equal(480); - }); - it('should fail if player size is 2 x nested', function () { - const obj = {'playerSize': [[[640, 480]]], 'mimes': ['video/mp4'], 'context': 'outstream'}; - const result = getWidthAndHeightFromVideoObject(obj); - expect(result).to.be.null; - }); - it('should add oz_appnexus_dealid into ads request if dealid exists in the auction response', function () { - const request = spec.buildRequests(validBidRequestsMulti, validBidderRequest); - const validres = JSON.parse(JSON.stringify(validResponse2Bids)); - validres.body.seatbid[0].bid[0].dealid = '1234'; - const result = spec.interpretResponse(validres, request); - expect(utils.deepAccess(result[0].adserverTargeting, 'oz_appnexus_dealid')).to.equal('1234'); - expect(utils.deepAccess(result[1].adserverTargeting, 'oz_appnexus_dealid', '')).to.equal(''); - }); - }); - describe('default size', function () { - it('should should return default sizes if no obj is sent', function () { - const obj = ''; - const result = defaultSize(obj); - expect(result.defaultHeight).to.equal(250); - expect(result.defaultWidth).to.equal(300); - }); - }); - describe('blockTheRequest', function() { - beforeEach(function () { - config.resetConfig() - }) - it('should return true if oz_request is false', function() { - config.setConfig({'ozone': {'oz_request': false}}); - const result = spec.blockTheRequest(); - expect(result).to.be.true; - }); - it('should return false if oz_request is true', function() { - config.setConfig({'ozone': {'oz_request': true}}); - const result = spec.blockTheRequest(); - expect(result).to.be.false; - }); - }); - describe('getPageId', function() { - it('should return the same Page ID for multiple calls', function () { - const result = spec.getPageId(); - expect(result).to.be.a('string'); - const result2 = spec.getPageId(); - expect(result2).to.equal(result); - }); - }); - describe('getBidRequestForBidId', function() { - it('should locate a bid inside a bid array', function () { - let result = spec.getBidRequestForBidId('2899ec066a91ff8', validBidRequestsMulti); - expect(result.testId).to.equal(1); - result = spec.getBidRequestForBidId('2899ec066a91ff0', validBidRequestsMulti); - expect(result.testId).to.equal(2); - }); - }); - describe('getVideoContextForBidId', function() { - it('should locate the video context inside a bid', function () { - const result = spec.getVideoContextForBidId('2899ec066a91ff8', validBidRequestsWithNonBannerMediaTypesAndValidOutstreamVideo); - expect(result).to.equal('outstream'); - }); - }); - describe('unpackVideoConfigIntoIABformat', function() { - it('should correctly unpack a usual video config', function () { - const mediaTypes = { - playerSize: [640, 480], - mimes: ['video/mp4'], - context: 'outstream', - testKey: 'parent value' - }; - const bid_params_video = { - skippable: true, - playback_method: ['auto_play_sound_off'], - playbackmethod: 2, - minduration: 5, - maxduration: 60, - skipmin: 5, - skipafter: 5, - testKey: 'child value' - }; - const result = spec.unpackVideoConfigIntoIABformat(mediaTypes, bid_params_video); - expect(result.mimes).to.be.an('array').that.includes('video/mp4'); - expect(result.ext.context).to.equal('outstream'); - expect(result.ext.skippable).to.be.true; - expect(result.ext.testKey).to.equal('child value'); - }); - }); - describe('addVideoDefaults', function() { - it('should not add video defaults if there is no videoParams config', function () { - const mediaTypes = { - playerSize: [640, 480], - mimes: ['video/mp4'], - context: 'outstream', - }; - const bid_params_video = { - skippable: true, - playback_method: ['auto_play_sound_off'], - playbackmethod: 2, - minduration: 5, - maxduration: 60, - skipmin: 5, - skipafter: 5, - testKey: 'child value' - }; - let result = spec.addVideoDefaults({}, mediaTypes, mediaTypes); - expect(result.placement).to.be.undefined; - expect(result.skip).to.equal(0); - result = spec.addVideoDefaults({}, mediaTypes, bid_params_video); - expect(result.skip).to.equal(1); - }); - it('should correctly add video defaults if page config videoParams is defined, also check skip in the parent', function () { - var specMock = utils.deepClone(spec); - config.setConfig({'ozone': {videoParams: {outstream: 3, instream: 1}}}); - const mediaTypes = { - playerSize: [640, 480], - mimes: ['video/mp4'], - context: 'outstream', - skippable: true - }; - const bid_params_video = { - playback_method: ['auto_play_sound_off'], - playbackmethod: 2, - minduration: 5, - maxduration: 60, - skipmin: 5, - skipafter: 5, - testKey: 'child value' - }; - const result = specMock.addVideoDefaults({}, mediaTypes, bid_params_video); - expect(result.placement).to.equal(3); - expect(result.skip).to.equal(1); - config.resetConfig(); - }); - }); - describe('removeSingleBidderMultipleBids', function() { - it('should remove the multi bid by ozappnexus for adslot 2d30e86db743a8', function() { - const validres = JSON.parse(JSON.stringify(multiResponse1)); - expect(validres.body.seatbid[0].bid.length).to.equal(3); - expect(validres.body.seatbid[0].seat).to.equal('ozappnexus'); - const response = spec.removeSingleBidderMultipleBids(validres.body.seatbid); - expect(response.length).to.equal(2); - expect(response[0].bid.length).to.equal(2); - expect(response[0].seat).to.equal('ozappnexus'); - expect(response[1].bid.length).to.equal(2); - }); - }); - describe('setBidMediaTypeIfNotExist', function() { - it('should leave the bid object alone if it already contains mediaType', function() { - const thisBid = {mediaType: 'marktest'}; - spec.setBidMediaTypeIfNotExist(thisBid, 'replacement'); - expect(thisBid.mediaType).to.equal('marktest'); - }); - it('should change the bid object if it doesnt already contain mediaType', function() { - const thisBid = {someKey: 'someValue'}; - spec.setBidMediaTypeIfNotExist(thisBid, 'replacement'); - expect(thisBid.mediaType).to.equal('replacement'); - }); - }); - describe('getLoggableBidObject', function() { - it('should return an object without a "renderer" element', function () { - const obj = {'renderer': {}, 'somevalue': '', 'h': 100}; - const ret = spec.getLoggableBidObject(obj); - expect(ret).to.not.have.own.property('renderer'); - expect(ret.h).to.equal(100); - }); - }); - describe('getUserIdFromEids', function() { - it('should iterate over userIdAsEids when it is an object', function () { - let bid = { userIdAsEids: - [ - { - source: 'pubcid.org', - uids: [{ - id: 'some-random-id-value', - atype: 1 - }] - }, - { - source: 'adserver.org', - uids: [{ - id: 'some-random-id-value', - atype: 1, - ext: { - rtiPartner: 'TDID' - } - }] - } - ] - }; - let response = spec.findAllUserIdsFromEids(bid); - expect(Object.keys(response).length).to.equal(2); - }); - it('should have no problem with userIdAsEids when it is present but null', function () { - let bid = { userIdAsEids: null }; - let response = spec.findAllUserIdsFromEids(bid); - expect(Object.keys(response).length).to.equal(0); - }); - it('should have no problem with userIdAsEids when it is present but undefined', function () { - let bid = { userIdAsEids: undefined }; - let response = spec.findAllUserIdsFromEids(bid); - expect(Object.keys(response).length).to.equal(0); - }); - it('should have no problem with userIdAsEids when it is absent', function () { - let bid = {}; - let response = spec.findAllUserIdsFromEids(bid); - expect(Object.keys(response).length).to.equal(0); - }); - it('find pubcid in the old location when there are eids and when there arent', function () { - let bid = {crumbs: {pubcid: 'some-random-id-value' }}; - let response = spec.findAllUserIdsFromEids(bid); - expect(Object.keys(response).length).to.equal(1); - }); - }); -}); diff --git a/test/spec/modules/paapi_spec.js b/test/spec/modules/paapi_spec.js index 2d491cdfe..47091ddf4 100644 --- a/test/spec/modules/paapi_spec.js +++ b/test/spec/modules/paapi_spec.js @@ -1406,16 +1406,6 @@ describe('paapi module', () => { expect(getPAAPIConfig().au.componentAuctions.length).to.eql(1); }); - it('should hide TIDs from buildPAAPIConfigs', () => { - config.setConfig({enableTIDs: false}); - startParallel(); - sinon.assert.calledWith( - spec.buildPAAPIConfigs, - sinon.match(bidRequests => bidRequests.every(req => req.auctionId == null)), - sinon.match(bidderRequest => bidderRequest.auctionId == null) - ); - }); - it('should show TIDs when enabled', () => { config.setConfig({enableTIDs: true}); startParallel(); diff --git a/test/spec/modules/padsquadBidAdapter_spec.js b/test/spec/modules/padsquadBidAdapter_spec.js deleted file mode 100644 index 1229ce778..000000000 --- a/test/spec/modules/padsquadBidAdapter_spec.js +++ /dev/null @@ -1,262 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/padsquadBidAdapter.js'; - -const REQUEST = { - 'bidderCode': 'padsquad', - 'auctionId': 'auctionId-56a2-4f71-9098-720a68f2f708', - 'bidderRequestId': 'requestId', - 'bidRequest': [{ - 'bidder': 'padsquad', - 'params': { - 'unitId': 123456, - }, - 'placementCode': 'div-gpt-dummy-placement-code', - 'sizes': [ - [300, 250] - ], - 'bidId': 'bidId1', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId-56a2-4f71-9098-720a68f2f708' - }, - { - 'bidder': 'padsquad', - 'params': { - 'unitId': 123456, - }, - 'placementCode': 'div-gpt-dummy-placement-code', - 'sizes': [ - [300, 250] - ], - 'bidId': 'bidId2', - 'bidderRequestId': 'bidderRequestId', - 'auctionId': 'auctionId-56a2-4f71-9098-720a68f2f708' - }], - 'start': 1487883186070, - 'auctionStart': 1487883186069, - 'timeout': 3000 -}; - -const RESPONSE = { - 'headers': null, - 'body': { - 'id': 'responseId', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'bidId1', - 'impid': 'bidId1', - 'price': 0.18, - 'adm': '', - 'adid': '144762342', - 'adomain': [ - 'https://dummydomain.com' - ], - 'iurl': 'iurl', - 'cid': '109', - 'crid': 'creativeId', - 'cat': [], - 'w': 300, - 'h': 250, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'appnexus': { - 'brand_id': 334553, - 'auction_id': '514667951122925701', - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - } - }, - { - 'id': 'bidId2', - 'impid': 'bidId2', - 'price': 0.1, - 'adm': '', - 'adid': '144762342', - 'adomain': [ - 'https://dummydomain.com' - ], - 'iurl': 'iurl', - 'cid': '109', - 'crid': 'creativeId', - 'cat': [], - 'w': 300, - 'h': 250, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'appnexus': { - 'brand_id': 386046, - 'auction_id': '517067951122925501', - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - } - } - ], - 'seat': 'seat' - } - ], - 'ext': { - 'usersync': { - 'sovrn': { - 'status': 'none', - 'syncs': [ - { - 'url': 'urlsovrn', - 'type': 'iframe' - } - ] - }, - 'appnexus': { - 'status': 'none', - 'syncs': [ - { - 'url': 'urlappnexus', - 'type': 'pixel' - } - ] - } - }, - 'responsetimemillis': { - 'appnexus': 127 - } - } - } -}; - -describe('Padsquad bid adapter', function () { - describe('isBidRequestValid', function () { - it('should accept request if only unitId is passed', function () { - const bid = { - bidder: 'padsquad', - params: { - unitId: 'unitId', - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should accept request if only networkId is passed', function () { - const bid = { - bidder: 'padsquad', - params: { - networkId: 'networkId', - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should accept request if only publisherId is passed', function () { - const bid = { - bidder: 'padsquad', - params: { - publisherId: 'publisherId', - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('reject requests without params', function () { - const bid = { - bidder: 'padsquad', - params: {} - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('creates request data', function () { - const request = spec.buildRequests(REQUEST.bidRequest, REQUEST); - - expect(request).to.exist.and.to.be.a('object'); - const payload = JSON.parse(request.data); - expect(payload.imp[0]).to.have.property('id', REQUEST.bidRequest[0].bidId); - expect(payload.imp[1]).to.have.property('id', REQUEST.bidRequest[1].bidId); - }); - - it('has gdpr data if applicable', function () { - const req = Object.assign({}, REQUEST, { - gdprConsent: { - consentString: 'consentString', - gdprApplies: true, - } - }); - const request = spec.buildRequests(REQUEST.bidRequest, req); - - const payload = JSON.parse(request.data); - expect(payload.user.ext).to.have.property('consent', req.gdprConsent.consentString); - expect(payload.regs.ext).to.have.property('gdpr', 1); - }); - }); - - describe('interpretResponse', function () { - it('have bids', function () { - const bids = spec.interpretResponse(RESPONSE, REQUEST); - expect(bids).to.be.an('array').that.is.not.empty; - validateBidOnIndex(0); - validateBidOnIndex(1); - - function validateBidOnIndex(index) { - expect(bids[index]).to.have.property('currency', 'USD'); - expect(bids[index]).to.have.property('requestId', RESPONSE.body.seatbid[0].bid[index].impid); - expect(bids[index]).to.have.property('cpm', RESPONSE.body.seatbid[0].bid[index].price); - expect(bids[index]).to.have.property('width', RESPONSE.body.seatbid[0].bid[index].w); - expect(bids[index]).to.have.property('height', RESPONSE.body.seatbid[0].bid[index].h); - expect(bids[index]).to.have.property('ad', RESPONSE.body.seatbid[0].bid[index].adm); - expect(bids[index]).to.have.property('creativeId', RESPONSE.body.seatbid[0].bid[index].crid); - expect(bids[index].meta.advertiserDomains).to.deep.equal(RESPONSE.body.seatbid[0].bid[index].adomain); - expect(bids[index]).to.have.property('ttl', 30); - expect(bids[index]).to.have.property('netRevenue', true); - } - }); - - it('handles empty response', function () { - const EMPTY_RESP = Object.assign({}, RESPONSE, {'body': {}}); - const bids = spec.interpretResponse(EMPTY_RESP, REQUEST); - - expect(bids).to.be.empty; - }); - }); - - describe('getUserSyncs', function () { - it('handles no parameters', function () { - const opts = spec.getUserSyncs({}); - expect(opts).to.be.an('array').that.is.empty; - }); - it('returns non if sync is not allowed', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: false}); - - expect(opts).to.be.an('array').that.is.empty; - }); - - it('iframe sync enabled should return results', function () { - const opts = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: false}, [RESPONSE]); - - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('iframe'); - expect(opts[0].url).to.equal(RESPONSE.body.ext.usersync['sovrn'].syncs[0].url); - }); - - it('pixel sync enabled should return results', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [RESPONSE]); - - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('image'); - expect(opts[0].url).to.equal(RESPONSE.body.ext.usersync['appnexus'].syncs[0].url); - }); - - it('all sync enabled should return all results', function () { - const opts = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, [RESPONSE]); - - expect(opts.length).to.equal(2); - }); - }); -}); diff --git a/test/spec/modules/pangleBidAdapter_spec.js b/test/spec/modules/pangleBidAdapter_spec.js deleted file mode 100644 index 3fbdbaca4..000000000 --- a/test/spec/modules/pangleBidAdapter_spec.js +++ /dev/null @@ -1,391 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/pangleBidAdapter.js'; - -const REQUEST = [{ - adUnitCode: 'adUnitCode1', - bidId: 'bidId1', - auctionId: 'auctionId-56a2-4f71-9098-720a68f2f708', - ortb2Imp: { - ext: { - tid: 'cccc1234', - } - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - bidder: 'pangle', - params: { - placementid: 999, - appid: 111, - }, -}, -{ - adUnitCode: 'adUnitCode2', - bidId: 'bidId2', - auctionId: 'auctionId-56a2-4f71-9098-720a68f2f708', - ortb2Imp: { - ext: { - tid: 'cccc1234', - } - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - bidder: 'pangle', - params: { - placementid: 999, - appid: 111, - }, -}]; - -const DEFAULT_OPTIONS = { - userId: { - britepoolid: 'pangle-britepool', - criteoId: 'pangle-criteo', - digitrustid: { data: { id: 'pangle-digitrust' } }, - id5id: { uid: 'pangle-id5' }, - idl_env: 'pangle-idl-env', - lipb: { lipbid: 'pangle-liveintent' }, - netId: 'pangle-netid', - parrableId: { eid: 'pangle-parrable' }, - pubcid: 'pangle-pubcid', - tdid: 'pangle-ttd', - } -}; - -const RESPONSE = { - 'headers': null, - 'body': { - 'id': 'requestId', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'bidId1', - 'impid': 'bidId1', - 'price': 0.18, - 'adm': '', - 'adid': '144762342', - 'adomain': [ - 'https://dummydomain.com' - ], - 'iurl': 'iurl', - 'cid': '109', - 'crid': 'creativeId', - 'cat': [], - 'w': 300, - 'h': 250, - 'mtype': 1, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'pangle': { - 'brand_id': 334553, - 'auction_id': '514667951122925701', - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - } - } - ], - 'seat': 'seat' - } - ] - } -}; - -describe('pangle bid adapter', function () { - describe('isBidRequestValid', function () { - it('should accept request if placementid and appid is passed', function () { - const bid = { - bidder: 'pangle', - params: { - token: 'xxx', - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('reject requests without params', function () { - const bid = { - bidder: 'pangle', - params: {} - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('creates request data', function () { - const request1 = spec.buildRequests(REQUEST, DEFAULT_OPTIONS)[0]; - expect(request1).to.exist.and.to.be.a('object'); - const payload1 = request1.data; - expect(payload1.imp[0]).to.have.property('id', REQUEST[0].bidId); - - const request2 = spec.buildRequests(REQUEST, DEFAULT_OPTIONS)[1]; - expect(request2).to.exist.and.to.be.a('object'); - const payload2 = request2.data; - expect(payload2.imp[0]).to.have.property('id', REQUEST[1].bidId); - }); - }); - - describe('interpretResponse', function () { - it('has bids', function () { - const request = spec.buildRequests(REQUEST, DEFAULT_OPTIONS)[0]; - const bids = spec.interpretResponse(RESPONSE, request); - expect(bids).to.be.an('array').that.is.not.empty; - validateBidOnIndex(0); - - function validateBidOnIndex(index) { - expect(bids[index]).to.have.property('currency', 'USD'); - expect(bids[index]).to.have.property('requestId', RESPONSE.body.seatbid[0].bid[index].id); - expect(bids[index]).to.have.property('cpm', RESPONSE.body.seatbid[0].bid[index].price); - expect(bids[index]).to.have.property('width', RESPONSE.body.seatbid[0].bid[index].w); - expect(bids[index]).to.have.property('height', RESPONSE.body.seatbid[0].bid[index].h); - expect(bids[index]).to.have.property('ad', RESPONSE.body.seatbid[0].bid[index].adm); - expect(bids[index]).to.have.property('creativeId', RESPONSE.body.seatbid[0].bid[index].crid); - expect(bids[index]).to.have.property('ttl', 30); - expect(bids[index]).to.have.property('netRevenue', true); - } - }); - - it('handles empty response', function () { - const request = spec.buildRequests(REQUEST, DEFAULT_OPTIONS)[0]; - const EMPTY_RESP = Object.assign({}, RESPONSE, { 'body': {} }); - const bids = spec.interpretResponse(EMPTY_RESP, request); - expect(bids).to.be.empty; - }); - }); - - describe('parseUserAgent', function () { - let desktop, mobile, tablet; - beforeEach(function () { - desktop = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'; - mobile = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_2_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.3 Mobile/15E148 Safari/604.1'; - tablet = 'Apple iPad: Mozilla/5.0 (iPad; CPU OS 13_5_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1.1 Mobile/15E148 Safari/605.1.15'; - }); - - it('should return correct device type: tablet', function () { - const deviceType = spec.getDeviceType(tablet); - expect(deviceType).to.equal(5); - }); - - it('should return correct device type: mobile', function () { - const deviceType = spec.getDeviceType(mobile); - expect(deviceType).to.equal(4); - }); - - it('should return correct device type: desktop', function () { - const deviceType = spec.getDeviceType(desktop); - expect(deviceType).to.equal(2); - }); - }); -}); - -describe('Pangle Adapter with video', function() { - const videoBidRequest = [ - { - bidId: '2820132fe18114', - mediaTypes: { video: { context: 'outstream', playerSize: [[300, 250]] } }, - params: { token: 'test-token' } - } - ]; - const bidderRequest = { - refererInfo: { - referer: 'https://example.com' - } - }; - const serverResponse = { - 'headers': null, - 'body': { - 'id': '233f1693-68d1-470a-ad85-c156c3faaf6f', - 'seatbid': [ - { - 'bid': [ - { - 'id': '2820132fe18114', - 'impid': '2820132fe18114', - 'price': 0.03294, - 'nurl': 'https://api16-event-sg2.pangle.io/api/ad/union/openrtb/win/?req_id=233f1693-68d1-470a-ad85-c156c3faaf6fu1450&ttdsp_adx_index=256&rit=980589944&extra=oqveoB%2Bg4%2ByNz9L8wwu%2Fy%2FwKxQsGaKsJHuB4NMK77uqZ9%2FJKpnsVZculJX8%2FxrRBAtaktU1DRN%2Fy6TKAqibCbj%2FM3%2BZ6biAKQG%2BCyt4eIV0KVvri9jCCnaajbkN7YNJWJJw2lW6cJ6Va3SuJG9H7a%2FAJd2PMbhK7fXWhoW72TwgOcKHKBgjM6sNDISBKbWlZyY3L1PhKSX%2FM8LOvL6qahsb%2FDpEObIx24vhQLNWp28XY1L4UqeibuRjam3eCvN7nXoQq74KkJ45QQsTgvV4j6I6EbLOdjOi%2FURhWMDjUD1VCMpqUT%2B6L8ZROgrX9Tp53eJ3bFOczmSTOmDSazKMHa%2B3uZZ7JHcSx32eoY4hfYc99NOJmYBKXNKCmoXyJvS3PCM3PlAz97hKrDMGnVv1wAQ7QGDCbittF0vZwtsRAvvx2mWINNIB3%2FUB2PjhxFsoDA%2BWE2urVZwEdyu%2FJrCznJsMwenXjcbMD5jmUF5vDkkLS%2B7TMDIEawJPJKZ62pK35enrwGxCs6ePXi21rJJkA0bF8tgAdl4mU1illBIVO4kCL%2ByRASskHPjgg%2FcdFe9HP%2Fi8byjAprH%2BhRerN%2FRKFxC3xv8b75x2pb1g7dY%2FTj9IjT0evsBSPVwFNqtKmPId35IcY%2FSXiqPHh%2FrAHZzr5BPsTT19P49SlNMR9UZYTzViX1iJpcCL1UFjuDdrdff%2BhHCviXxo%2FkRmufEF3umHZwxbdDOPAghuZ0DtRCY6S1rnb%2FK9BbpsVKSndOtgfCwMHFwiPmdw1XjEXGc1eOWXY6qfSp90PIfL6WS7Neh3ba2qMv6WxG3HSOBYvrcCqVTsNxk4UdVm3qb1J0CMVByweTMo45usSkCTdvX3JuEB7tVA6%2BrEk57b3XJd5Phf2AN8hon%2F7lmcXE41kwMQuXq89ViwQmW0G247UFWOQx4t1cmBqFiP6qNA%2F%2BunkZDno1pmAsGnTv7Mz9xtpOaIqKl8BKrVQSTopZ9WcUVzdBUutF19mn1f43BvyA9gIEhcDJHOj&win_price=${AUCTION_PRICE}&auction_mwb=${AUCTION_BID_TO_WIN}&use_pb=1', - 'lurl': 'https://api16-event-sg2.pangle.io/api/ad/union/openrtb/loss/?req_id=233f1693-68d1-470a-ad85-c156c3faaf6fu1450&ttdsp_adx_index=256&rit=980589944&extra=oqveoB%2Bg4%2ByNz9L8wwu%2Fy%2FwKxQsGaKsJHuB4NMK77uqZ9%2FJKpnsVZculJX8%2FxrRBAtaktU1DRN%2Fy6TKAqibCbj%2FM3%2BZ6biAKQG%2BCyt4eIV0KVvri9jCCnaajbkN7YNJWJJw2lW6cJ6Va3SuJG9H7a%2FAJd2PMbhK7fXWhoW72TwgOcKHKBgjM6sNDISBKbWlZyY3L1PhKSX%2FM8LOvL6qahsb%2FDpEObIx24vhQLNWp28XY1L4UqeibuRjam3eCvN7nXoQq74KkJ45QQsTgvV4j6I6EbLOdjOi%2FURhWMDjUD1VCMpqUT%2B6L8ZROgrX9Tp53eJ3bFOczmSTOmDSazKMHa%2B3uZZ7JHcSx32eoY4hfYc99NOJmYBKXNKCmoXyJvS3PCM3PlAz97hKrDMGnVv1wAQ7QGDCbittF0vZwtsRAvvx2mWINNIB3%2FUB2PjhxFsoDA%2BWE2urVZwEdyu%2FJrCznJsMwenXjcbMD5jmUF5vDkkLS%2B7TMDIEawJPJKZ62pK35enrwGxCs6ePXi21rJJkA0bF8tgAdl4mU1illBIVO4kCL%2ByRASskHPjgg%2FcdFe9HP%2Fi8byjAprH%2BhRerN%2FRKFxC3xv8b75x2pb1g7dY%2FTj9IjT0evsBSPVwFNqtKmPId35IcY%2FSXiqPHh%2FrAHZzr5BPsTT19P49SlNMR9UZYTzViX1iJpcCL1UFjuDdrdff%2BhHCviXxo%2FkRmufEF3umHZwxbdDOPAghuZ0DtRCY6S1rnb%2FK9BbpsVKSndOtgfCwMHFwiPmdw1XjEXGc1eOWXY6qfSp90PIfL6WS7Neh3ba2qMv6WxG3HSOBYvrcCqVTsNxk4UdVm3qb1J0CMVByweTMo45usSkCTdvX3JuEB7tVA6%2BrEk57b3XJd5Phf2AN8hon%2F7lmcXE41kwMQuXq89ViwQmW0G247UFWOQx4t1cmBqFiP6qNA%2F%2BunkZDno1pmAsGnTv7Mz9xtpOaIqKl8BKrVQSTopZ9WcUVzdBUutF19mn1f43BvyA9gIEhcDJHOj&reason=${AUCTION_LOSS}&ad_slot_type=8&auction_mwb=${AUCTION_PRICE}&use_pb=1', - 'adm': '', - 'adid': '1780626232977441', - 'adomain': [ - 'swi.esxcmnb.com' - ], - 'iurl': 'https://p16-ttam-va.ibyteimg.com/origin/ad-site-i18n-sg/202310245d0d598b3ff5993c4f129a8b', - 'cid': '1780626232977441', - 'crid': '1780626232977441', - 'attr': [ - 4 - ], - 'w': 640, - 'h': 640, - 'mtype': 1, - 'ext': { - 'pangle': { - 'adtype': 8 - }, - 'event_notification_token': { - 'payload': '980589944:8:1450:7492' - } - } - } - ], - 'seat': 'pangle' - } - ] - } - }; - - describe('Video: buildRequests', function() { - it('should create a POST request for video bid', function() { - const requests = spec.buildRequests(videoBidRequest, bidderRequest); - expect(requests[0].method).to.equal('POST'); - }); - - it('should have a valid URL and payload for an out-stream video bid', function () { - const requests = spec.buildRequests(videoBidRequest, bidderRequest); - expect(requests[0].url).to.equal('https://pangle.pangleglobal.com/api/ad/union/web_js/common/get_ads'); - expect(requests[0].data).to.exist; - }); - }); - - describe('interpretResponse: Video', function () { - it('should get correct bid response', function () { - const request = spec.buildRequests(videoBidRequest, bidderRequest)[0]; - const interpretedResponse = spec.interpretResponse(serverResponse, request); - expect(interpretedResponse).to.be.an('array'); - const bid = interpretedResponse[0]; - expect(bid).to.exist; - expect(bid.requestId).to.exist; - expect(bid.cpm).to.be.above(0); - expect(bid.ttl).to.exist; - expect(bid.creativeId).to.exist; - if (bid.renderer) { - expect(bid.renderer.render).to.exist; - } - }); - }); -}); - -describe('pangle multi-format ads', function () { - const bidderRequest = { - refererInfo: { - referer: 'https://example.com' - } - }; - const multiRequest = [ - { - bidId: '2820132fe18114', - mediaTypes: { banner: { sizes: [[300, 250]] }, video: { context: 'outstream', playerSize: [[300, 250]] } }, - params: { token: 'test-token' } - } - ]; - const videoResponse = { - 'headers': null, - 'body': { - 'id': '233f1693-68d1-470a-ad85-c156c3faaf6f', - 'seatbid': [ - { - 'bid': [ - { - 'id': '2820132fe18114', - 'impid': '2820132fe18114', - 'price': 0.03294, - 'nurl': 'https://api16-event-sg2.pangle.io/api/ad/union/openrtb/win/?req_id=233f1693-68d1-470a-ad85-c156c3faaf6fu1450&ttdsp_adx_index=256&rit=980589944&extra=oqveoB%2Bg4%2ByNz9L8wwu%2Fy%2FwKxQsGaKsJHuB4NMK77uqZ9%2FJKpnsVZculJX8%2FxrRBAtaktU1DRN%2Fy6TKAqibCbj%2FM3%2BZ6biAKQG%2BCyt4eIV0KVvri9jCCnaajbkN7YNJWJJw2lW6cJ6Va3SuJG9H7a%2FAJd2PMbhK7fXWhoW72TwgOcKHKBgjM6sNDISBKbWlZyY3L1PhKSX%2FM8LOvL6qahsb%2FDpEObIx24vhQLNWp28XY1L4UqeibuRjam3eCvN7nXoQq74KkJ45QQsTgvV4j6I6EbLOdjOi%2FURhWMDjUD1VCMpqUT%2B6L8ZROgrX9Tp53eJ3bFOczmSTOmDSazKMHa%2B3uZZ7JHcSx32eoY4hfYc99NOJmYBKXNKCmoXyJvS3PCM3PlAz97hKrDMGnVv1wAQ7QGDCbittF0vZwtsRAvvx2mWINNIB3%2FUB2PjhxFsoDA%2BWE2urVZwEdyu%2FJrCznJsMwenXjcbMD5jmUF5vDkkLS%2B7TMDIEawJPJKZ62pK35enrwGxCs6ePXi21rJJkA0bF8tgAdl4mU1illBIVO4kCL%2ByRASskHPjgg%2FcdFe9HP%2Fi8byjAprH%2BhRerN%2FRKFxC3xv8b75x2pb1g7dY%2FTj9IjT0evsBSPVwFNqtKmPId35IcY%2FSXiqPHh%2FrAHZzr5BPsTT19P49SlNMR9UZYTzViX1iJpcCL1UFjuDdrdff%2BhHCviXxo%2FkRmufEF3umHZwxbdDOPAghuZ0DtRCY6S1rnb%2FK9BbpsVKSndOtgfCwMHFwiPmdw1XjEXGc1eOWXY6qfSp90PIfL6WS7Neh3ba2qMv6WxG3HSOBYvrcCqVTsNxk4UdVm3qb1J0CMVByweTMo45usSkCTdvX3JuEB7tVA6%2BrEk57b3XJd5Phf2AN8hon%2F7lmcXE41kwMQuXq89ViwQmW0G247UFWOQx4t1cmBqFiP6qNA%2F%2BunkZDno1pmAsGnTv7Mz9xtpOaIqKl8BKrVQSTopZ9WcUVzdBUutF19mn1f43BvyA9gIEhcDJHOj&win_price=${AUCTION_PRICE}&auction_mwb=${AUCTION_BID_TO_WIN}&use_pb=1', - 'lurl': 'https://api16-event-sg2.pangle.io/api/ad/union/openrtb/loss/?req_id=233f1693-68d1-470a-ad85-c156c3faaf6fu1450&ttdsp_adx_index=256&rit=980589944&extra=oqveoB%2Bg4%2ByNz9L8wwu%2Fy%2FwKxQsGaKsJHuB4NMK77uqZ9%2FJKpnsVZculJX8%2FxrRBAtaktU1DRN%2Fy6TKAqibCbj%2FM3%2BZ6biAKQG%2BCyt4eIV0KVvri9jCCnaajbkN7YNJWJJw2lW6cJ6Va3SuJG9H7a%2FAJd2PMbhK7fXWhoW72TwgOcKHKBgjM6sNDISBKbWlZyY3L1PhKSX%2FM8LOvL6qahsb%2FDpEObIx24vhQLNWp28XY1L4UqeibuRjam3eCvN7nXoQq74KkJ45QQsTgvV4j6I6EbLOdjOi%2FURhWMDjUD1VCMpqUT%2B6L8ZROgrX9Tp53eJ3bFOczmSTOmDSazKMHa%2B3uZZ7JHcSx32eoY4hfYc99NOJmYBKXNKCmoXyJvS3PCM3PlAz97hKrDMGnVv1wAQ7QGDCbittF0vZwtsRAvvx2mWINNIB3%2FUB2PjhxFsoDA%2BWE2urVZwEdyu%2FJrCznJsMwenXjcbMD5jmUF5vDkkLS%2B7TMDIEawJPJKZ62pK35enrwGxCs6ePXi21rJJkA0bF8tgAdl4mU1illBIVO4kCL%2ByRASskHPjgg%2FcdFe9HP%2Fi8byjAprH%2BhRerN%2FRKFxC3xv8b75x2pb1g7dY%2FTj9IjT0evsBSPVwFNqtKmPId35IcY%2FSXiqPHh%2FrAHZzr5BPsTT19P49SlNMR9UZYTzViX1iJpcCL1UFjuDdrdff%2BhHCviXxo%2FkRmufEF3umHZwxbdDOPAghuZ0DtRCY6S1rnb%2FK9BbpsVKSndOtgfCwMHFwiPmdw1XjEXGc1eOWXY6qfSp90PIfL6WS7Neh3ba2qMv6WxG3HSOBYvrcCqVTsNxk4UdVm3qb1J0CMVByweTMo45usSkCTdvX3JuEB7tVA6%2BrEk57b3XJd5Phf2AN8hon%2F7lmcXE41kwMQuXq89ViwQmW0G247UFWOQx4t1cmBqFiP6qNA%2F%2BunkZDno1pmAsGnTv7Mz9xtpOaIqKl8BKrVQSTopZ9WcUVzdBUutF19mn1f43BvyA9gIEhcDJHOj&reason=${AUCTION_LOSS}&ad_slot_type=8&auction_mwb=${AUCTION_PRICE}&use_pb=1', - 'adm': '', - 'adid': '1780626232977441', - 'adomain': [ - 'swi.esxcmnb.com' - ], - 'iurl': 'https://p16-ttam-va.ibyteimg.com/origin/ad-site-i18n-sg/202310245d0d598b3ff5993c4f129a8b', - 'cid': '1780626232977441', - 'crid': '1780626232977441', - 'attr': [ - 4 - ], - 'w': 640, - 'h': 640, - 'mtype': 2, - 'ext': { - 'pangle': { - 'adtype': 8 - }, - 'event_notification_token': { - 'payload': '980589944:8:1450:7492' - } - } - } - ], - 'seat': 'pangle' - } - ] - } - }; - const bannerResponse = { - 'headers': null, - 'body': { - 'id': '233f1693-68d1-470a-ad85-c156c3faaf6f', - 'seatbid': [ - { - 'bid': [ - { - 'id': '2820132fe18114', - 'impid': '2820132fe18114', - 'price': 0.03294, - 'nurl': 'https://api16-event-sg2.pangle.io/api/ad/union/openrtb/win/?req_id=233f1693-68d1-470a-ad85-c156c3faaf6fu1450&ttdsp_adx_index=256&rit=980589944&extra=oqveoB%2Bg4%2ByNz9L8wwu%2Fy%2FwKxQsGaKsJHuB4NMK77uqZ9%2FJKpnsVZculJX8%2FxrRBAtaktU1DRN%2Fy6TKAqibCbj%2FM3%2BZ6biAKQG%2BCyt4eIV0KVvri9jCCnaajbkN7YNJWJJw2lW6cJ6Va3SuJG9H7a%2FAJd2PMbhK7fXWhoW72TwgOcKHKBgjM6sNDISBKbWlZyY3L1PhKSX%2FM8LOvL6qahsb%2FDpEObIx24vhQLNWp28XY1L4UqeibuRjam3eCvN7nXoQq74KkJ45QQsTgvV4j6I6EbLOdjOi%2FURhWMDjUD1VCMpqUT%2B6L8ZROgrX9Tp53eJ3bFOczmSTOmDSazKMHa%2B3uZZ7JHcSx32eoY4hfYc99NOJmYBKXNKCmoXyJvS3PCM3PlAz97hKrDMGnVv1wAQ7QGDCbittF0vZwtsRAvvx2mWINNIB3%2FUB2PjhxFsoDA%2BWE2urVZwEdyu%2FJrCznJsMwenXjcbMD5jmUF5vDkkLS%2B7TMDIEawJPJKZ62pK35enrwGxCs6ePXi21rJJkA0bF8tgAdl4mU1illBIVO4kCL%2ByRASskHPjgg%2FcdFe9HP%2Fi8byjAprH%2BhRerN%2FRKFxC3xv8b75x2pb1g7dY%2FTj9IjT0evsBSPVwFNqtKmPId35IcY%2FSXiqPHh%2FrAHZzr5BPsTT19P49SlNMR9UZYTzViX1iJpcCL1UFjuDdrdff%2BhHCviXxo%2FkRmufEF3umHZwxbdDOPAghuZ0DtRCY6S1rnb%2FK9BbpsVKSndOtgfCwMHFwiPmdw1XjEXGc1eOWXY6qfSp90PIfL6WS7Neh3ba2qMv6WxG3HSOBYvrcCqVTsNxk4UdVm3qb1J0CMVByweTMo45usSkCTdvX3JuEB7tVA6%2BrEk57b3XJd5Phf2AN8hon%2F7lmcXE41kwMQuXq89ViwQmW0G247UFWOQx4t1cmBqFiP6qNA%2F%2BunkZDno1pmAsGnTv7Mz9xtpOaIqKl8BKrVQSTopZ9WcUVzdBUutF19mn1f43BvyA9gIEhcDJHOj&win_price=${AUCTION_PRICE}&auction_mwb=${AUCTION_BID_TO_WIN}&use_pb=1', - 'lurl': 'https://api16-event-sg2.pangle.io/api/ad/union/openrtb/loss/?req_id=233f1693-68d1-470a-ad85-c156c3faaf6fu1450&ttdsp_adx_index=256&rit=980589944&extra=oqveoB%2Bg4%2ByNz9L8wwu%2Fy%2FwKxQsGaKsJHuB4NMK77uqZ9%2FJKpnsVZculJX8%2FxrRBAtaktU1DRN%2Fy6TKAqibCbj%2FM3%2BZ6biAKQG%2BCyt4eIV0KVvri9jCCnaajbkN7YNJWJJw2lW6cJ6Va3SuJG9H7a%2FAJd2PMbhK7fXWhoW72TwgOcKHKBgjM6sNDISBKbWlZyY3L1PhKSX%2FM8LOvL6qahsb%2FDpEObIx24vhQLNWp28XY1L4UqeibuRjam3eCvN7nXoQq74KkJ45QQsTgvV4j6I6EbLOdjOi%2FURhWMDjUD1VCMpqUT%2B6L8ZROgrX9Tp53eJ3bFOczmSTOmDSazKMHa%2B3uZZ7JHcSx32eoY4hfYc99NOJmYBKXNKCmoXyJvS3PCM3PlAz97hKrDMGnVv1wAQ7QGDCbittF0vZwtsRAvvx2mWINNIB3%2FUB2PjhxFsoDA%2BWE2urVZwEdyu%2FJrCznJsMwenXjcbMD5jmUF5vDkkLS%2B7TMDIEawJPJKZ62pK35enrwGxCs6ePXi21rJJkA0bF8tgAdl4mU1illBIVO4kCL%2ByRASskHPjgg%2FcdFe9HP%2Fi8byjAprH%2BhRerN%2FRKFxC3xv8b75x2pb1g7dY%2FTj9IjT0evsBSPVwFNqtKmPId35IcY%2FSXiqPHh%2FrAHZzr5BPsTT19P49SlNMR9UZYTzViX1iJpcCL1UFjuDdrdff%2BhHCviXxo%2FkRmufEF3umHZwxbdDOPAghuZ0DtRCY6S1rnb%2FK9BbpsVKSndOtgfCwMHFwiPmdw1XjEXGc1eOWXY6qfSp90PIfL6WS7Neh3ba2qMv6WxG3HSOBYvrcCqVTsNxk4UdVm3qb1J0CMVByweTMo45usSkCTdvX3JuEB7tVA6%2BrEk57b3XJd5Phf2AN8hon%2F7lmcXE41kwMQuXq89ViwQmW0G247UFWOQx4t1cmBqFiP6qNA%2F%2BunkZDno1pmAsGnTv7Mz9xtpOaIqKl8BKrVQSTopZ9WcUVzdBUutF19mn1f43BvyA9gIEhcDJHOj&reason=${AUCTION_LOSS}&ad_slot_type=8&auction_mwb=${AUCTION_PRICE}&use_pb=1', - 'adm': '', - 'adid': '1780626232977441', - 'adomain': [ - 'swi.esxcmnb.com' - ], - 'iurl': 'https://p16-ttam-va.ibyteimg.com/origin/ad-site-i18n-sg/202310245d0d598b3ff5993c4f129a8b', - 'cid': '1780626232977441', - 'crid': '1780626232977441', - 'attr': [ - 4 - ], - 'w': 640, - 'h': 640, - 'mtype': 1, - 'ext': { - 'pangle': { - 'adtype': 8 - }, - 'event_notification_token': { - 'payload': '980589944:8:1450:7492' - } - } - } - ], - 'seat': 'pangle' - } - ] - } - }; - it('should set mediaType to banner', function() { - const request = spec.buildRequests(multiRequest, bidderRequest)[0]; - const interpretedResponse = spec.interpretResponse(bannerResponse, request); - const bid = interpretedResponse[0]; - expect(bid.mediaType).to.equal('banner'); - }) - it('should set mediaType to video', function() { - const request = spec.buildRequests(multiRequest, bidderRequest)[0]; - const interpretedResponse = spec.interpretResponse(videoResponse, request); - const bid = interpretedResponse[0]; - expect(bid.mediaType).to.equal('video'); - }) -}); diff --git a/test/spec/modules/performaxBidAdapter_spec.js b/test/spec/modules/performaxBidAdapter_spec.js deleted file mode 100644 index 218f9402e..000000000 --- a/test/spec/modules/performaxBidAdapter_spec.js +++ /dev/null @@ -1,175 +0,0 @@ -import { expect } from 'chai'; -import { spec, converter } from 'modules/performaxBidAdapter.js'; - -describe('Performax adapter', function () { - const bids = [{ - bidder: 'performax', - params: { - tagid: 'sample' - }, - ortb2Imp: { - ext: {} - }, - mediaTypes: { - banner: { - sizes: [ - [300, 300], - ]}}, - adUnitCode: 'postbid_iframe', - transactionId: '84deda92-e9ba-4b0d-a797-43be5e522430', - adUnitId: '4ee4643b-931f-4a17-a571-ccba57886dc8', - sizes: [ - [300, 300], - ], - bidId: '2bc545c347dbbe', - bidderRequestId: '1534dec005b9a', - auctionId: 'acd97e55-01e1-45ad-813c-67fa27fc5c1b', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - ortb2: { - source: {}, - site: {}, - device: {} - }, - }, - - { - bidder: 'performax', - params: { - tagid: '1545' - }, - ortb2Imp: { - ext: {} - }, - mediaTypes: { - banner: { - sizes: [ - [300, 600], - ]}}, - adUnitCode: 'postbid_halfpage_iframe', - transactionId: '84deda92-e9ba-4b0d-a797-43be5e522430', - adUnitId: '4ee4643b-931f-4a17-a571-ccba57886dc8', - sizes: [ - [300, 600], - ], - bidId: '3dd53d30c691fe', - bidderRequestId: '1534dec005b9a', - auctionId: 'acd97e55-01e1-45ad-813c-67fa27fc5c1b', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - ortb2: { - source: {}, - site: {}, - device: {} - }}]; - - const bidderRequest = { - bidderCode: 'performax2', - auctionId: 'acd97e55-01e1-45ad-813c-67fa27fc5c1b', - id: 'acd97e55-01e1-45ad-813c-67fa27fc5c1b', - bidderRequestId: '1534dec005b9a', - bids: bids, - ortb2: { - regs: { - ext: { - gdpr: 1 - }}, - user: { - ext: { - consent: 'consent-string' - } - }, - site: {}, - device: {} - }}; - - const serverResponse = { - body: { - cur: 'CZK', - seatbid: [ - { - seat: 'performax', - bid: [ - { - id: 'sample', - price: 20, - w: 300, - h: 300, - adm: 'My ad' - } - ]}]}, - } - - describe('isBidRequestValid', function () { - const bid = {}; - it('should return false when missing "tagid" param', function() { - bid.params = {slotId: 'param'}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - bid.params = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when tagid is correct', function() { - bid.params = {tagid: 'sample'}; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }) - - describe('buildRequests', function () { - it('should set correct request method and url', function () { - const requests = spec.buildRequests([bids[0]], bidderRequest); - expect(requests).to.be.an('array').that.has.lengthOf(1); - const request = requests[0]; - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://dale.performax.cz/ortb'); - expect(request.data).to.be.an('object'); - }); - - it('should pass correct imp', function () { - const requests = spec.buildRequests([bids[0]], bidderRequest); - const {data} = requests[0]; - const {imp} = data; - expect(imp).to.be.an('array').that.has.lengthOf(1); - expect(imp[0]).to.be.an('object'); - const bid = imp[0]; - expect(bid.id).to.equal('2bc545c347dbbe'); - expect(bid.banner).to.deep.equal({topframe: 0, format: [{w: 300, h: 300}]}); - }); - - it('should process multiple bids', function () { - const requests = spec.buildRequests(bids, bidderRequest); - expect(requests).to.be.an('array').that.has.lengthOf(1); - const {data} = requests[0]; - const {imp} = data; - expect(imp).to.be.an('array').that.has.lengthOf(bids.length); - const bid1 = imp[0]; - expect(bid1.banner).to.deep.equal({topframe: 0, format: [{w: 300, h: 300}]}); - const bid2 = imp[1]; - expect(bid2.banner).to.deep.equal({topframe: 0, format: [{w: 300, h: 600}]}); - }); - }); - - describe('interpretResponse', function () { - it('should map params correctly', function () { - const ortbRequest = {data: converter.toORTB({bidderRequest, bids})}; - serverResponse.body.id = ortbRequest.data.id; - serverResponse.body.seatbid[0].bid[0].imp_id = ortbRequest.data.imp[0].id; - - const result = spec.interpretResponse(serverResponse, ortbRequest); - expect(result).to.be.an('array').that.has.lengthOf(1); - const bid = result[0]; - - expect(bid.cpm).to.equal(20); - expect(bid.ad).to.equal('My ad'); - expect(bid.currency).to.equal('CZK'); - expect(bid.mediaType).to.equal('banner'); - expect(bid.netRevenue).to.equal(true); - expect(bid.ttl).to.equal(360); - expect(bid.creativeId).to.equal('sample'); - }); - }); -}); diff --git a/test/spec/modules/pgamsspBidAdapter_spec.js b/test/spec/modules/pgamsspBidAdapter_spec.js deleted file mode 100644 index 6eea9bec9..000000000 --- a/test/spec/modules/pgamsspBidAdapter_spec.js +++ /dev/null @@ -1,516 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/pgamsspBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'pgamssp'; - -describe('PGAMBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://us-east.pgammedia.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.pgammedia.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.pgammedia.com/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.pgammedia.com/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/pianoDmpAnalyticsAdapter_spec.js b/test/spec/modules/pianoDmpAnalyticsAdapter_spec.js deleted file mode 100644 index ea0dd4ab7..000000000 --- a/test/spec/modules/pianoDmpAnalyticsAdapter_spec.js +++ /dev/null @@ -1,63 +0,0 @@ -import pianoDmpAnalytics from 'modules/pianoDmpAnalyticsAdapter.js'; -import adapterManager from 'src/adapterManager'; -import * as events from 'src/events'; -import { EVENTS } from 'src/constants.js'; -import { expect } from 'chai'; - -describe('Piano DMP Analytics Adapter', () => { - let sandbox; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - - sandbox.stub(events, 'getEvents').returns([]); - }); - - afterEach(() => { - sandbox.restore(); - }); - - describe('track', () => { - beforeEach(() => { - adapterManager.enableAnalytics({ - provider: 'pianoDmp', - }); - }); - - afterEach(() => { - delete window.cX; - pianoDmpAnalytics.disableAnalytics(); - }); - - it('should pass events to call queue', () => { - const eventsList = [ - EVENTS.AUCTION_INIT, - EVENTS.AUCTION_END, - EVENTS.BID_ADJUSTMENT, - EVENTS.BID_TIMEOUT, - EVENTS.BID_REQUESTED, - EVENTS.BID_RESPONSE, - EVENTS.NO_BID, - EVENTS.BID_WON, - ]; - - // Given - const testEvents = eventsList.map((event) => ({ - event, - args: { test: event }, - })); - - // When - testEvents.forEach(({ event, args }) => events.emit(event, args)); - - // Then - const callQueue = (window.cX || {}).callQueue; - - testEvents.forEach(({event, args}) => { - const [method, params] = callQueue.filter(item => item[1].eventType === event)[0]; - expect(method).to.equal('prebid'); - expect(params.params).to.deep.equal(args); - }) - }); - }); -}); diff --git a/test/spec/modules/pilotxBidAdapter_spec.js b/test/spec/modules/pilotxBidAdapter_spec.js deleted file mode 100644 index 86b6e1ece..000000000 --- a/test/spec/modules/pilotxBidAdapter_spec.js +++ /dev/null @@ -1,370 +0,0 @@ -// import or require modules necessary for the test, e.g.: -import { expect } from 'chai'; // may prefer 'assert' in place of 'expect' -import { spec } from '../../../modules/pilotxBidAdapter.js'; - -describe('pilotxAdapter', function () { - describe('isBidRequestValid', function () { - let banner; - beforeEach(function () { - banner = { - bidder: 'pilotx', - adUnitCode: 'adunit-test', - mediaTypes: { banner: {} }, - sizes: [[300, 250], [468, 60]], - bidId: '2de8c82e30665a', - params: { - placementId: '1' - } - }; - }); - - it('should return false if sizes is empty', function () { - banner.sizes = [] - expect(spec.isBidRequestValid(banner)).to.equal(false); - }); - it('should return true if all is valid/ is not empty', function () { - expect(spec.isBidRequestValid(banner)).to.equal(true); - }); - it('should return false if there is no placement id found', function () { - banner.params = {} - expect(spec.isBidRequestValid(banner)).to.equal(false); - }); - it('should return false if sizes is empty', function () { - banner.sizes = [] - expect(spec.isBidRequestValid(banner)).to.equal(false); - }); - it('should return false for no size and empty params', function () { - const emptySizes = { - bidder: 'pilotx', - adUnitCode: 'adunit-test', - mediaTypes: { banner: {} }, - bidId: '2de8c82e30665a', - params: { - placementId: '1', - sizes: [] - } - }; - expect(spec.isBidRequestValid(emptySizes)).to.equal(false); - }) - it('should return true for no size and valid size params', function () { - const emptySizes = { - bidder: 'pilotx', - adUnitCode: 'adunit-test', - mediaTypes: { banner: {} }, - bidId: '2de8c82e30665a', - params: { - placementId: '1', - sizes: [[300, 250], [468, 60]] - } - }; - expect(spec.isBidRequestValid(emptySizes)).to.equal(true); - }) - it('should return false for no size items', function () { - const emptySizes = { - bidder: 'pilotx', - adUnitCode: 'adunit-test', - mediaTypes: { banner: {} }, - bidId: '2de8c82e30665a', - params: { - placementId: '1' - } - }; - expect(spec.isBidRequestValid(emptySizes)).to.equal(false); - }) - }); - - describe('buildRequests', function () { - const mockRequest = { refererInfo: {} }; - const mockRequestGDPR = { - refererInfo: {}, - gdprConsent: { - consentString: 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - gdprApplies: true - } - - } - const mockVideo1 = [{ - adUnitCode: 'video1', - auctionId: '01618029-7ae9-4e98-a73a-1ed0c817f414', - bidId: '2a59588c0114fa', - bidRequestsCount: 1, - bidder: 'pilotx', - bidderRequestId: '1f6b4ba2039726', - bidderRequestsCount: 1, - bidderWinsCount: 0, - crumbs: { pubcid: 'de5240ef-ff80-4b55-8837-26a11cfbf64c' }, - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mp4'], - playbackmethod: [2], - playerSize: [[640, 480]], - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1 - } - }, - ortb2Imp: { - ext: { - data: { - pbadslot: 'video1' - } - } - }, - params: { placementId: '379' }, - sizes: [[640, 480]], - src: 'client', - transactionId: 'fec9f2ff-da13-4921-8437-8d679c2be7fe', - }]; - const mockVideo2 = [{ - adUnitCode: 'video1', - auctionId: '01618029-7ae9-4e98-a73a-1ed0c817f414', - bidId: '2a59588c0114fa', - bidRequestsCount: 1, - bidder: 'pilotx', - bidderRequestId: '1f6b4ba2039726', - bidderRequestsCount: 1, - bidderWinsCount: 0, - crumbs: { pubcid: 'de5240ef-ff80-4b55-8837-26a11cfbf64c' }, - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mp4'], - playbackmethod: [2], - playerSize: [[640, 480]], - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - skip: 1 - } - }, - ortb2Imp: { - ext: { - data: { - pbadslot: 'video1' - } - } - }, - params: { placementId: '379' }, - sizes: [640, 480], - src: 'client', - transactionId: 'fec9f2ff-da13-4921-8437-8d679c2be7fe', - }]; - it('should return correct response', function () { - const builtRequest = spec.buildRequests(mockVideo1, mockRequest) - const builtRequestData = builtRequest.data - const data = JSON.parse(builtRequestData) - expect(data['379'].bidId).to.equal(mockVideo1[0].bidId) - }); - it('should return correct response for only array of size', function () { - const builtRequest = spec.buildRequests(mockVideo2, mockRequest) - const builtRequestData = builtRequest.data - const data = JSON.parse(builtRequestData) - expect(data['379'].sizes[0][0]).to.equal(mockVideo2[0].sizes[0]) - expect(data['379'].sizes[0][1]).to.equal(mockVideo2[0].sizes[1]) - }); - it('should be valid and pass gdpr items correctly', function () { - const builtRequest = spec.buildRequests(mockVideo2, mockRequestGDPR) - const builtRequestData = builtRequest.data - const data = JSON.parse(builtRequestData) - expect(data['379'].gdprConsentString).to.equal(mockRequestGDPR.gdprConsent.consentString) - expect(data['379'].gdprConsentRequired).to.equal(mockRequestGDPR.gdprConsent.gdprApplies) - }); - }); - describe('interpretResponse', function () { - const bidRequest = {} - const serverResponse = { - cpm: 2.5, - creativeId: 'V9060', - currency: 'US', - height: 480, - mediaType: 'video', - netRevenue: false, - requestId: '273b39c74069cb', - ttl: 3000, - vastUrl: 'http://testadserver.com/ads?&k=60cd901ad8ab70c9cedf373cb17b93b8&pid=379&tid=91342717', - width: 640, - advertiserDomains: ["test.com"] - } - const serverResponseVideo = { - body: serverResponse - } - const serverResponse2 = { - cpm: 2.5, - creativeId: 'V9060', - currency: 'US', - height: 480, - mediaType: 'banner', - netRevenue: false, - requestId: '273b39c74069cb', - ttl: 3000, - ad: 'http://testadserver.com/ads?&k=60cd901ad8ab70c9cedf373cb17b93b8&pid=379&tid=91342717', - width: 640, - advertiserDomains: ["test.com"] - } - const serverResponseBanner = { - body: serverResponse2 - } - const serverResponse3 = { - bids: [ - { - cpm: 2.5, - creativeId: 'V9060', - currency: 'US', - height: 480, - mediaType: 'banner', - netRevenue: false, - requestId: '273b39c74069cb', - ttl: 3000, - ad: 'http://testadserver.com/ads?&k=60cd901ad8ab70c9cedf373cb17b93b8&pid=379&tid=91342717', - width: 640, - advertiserDomains: ["testaddomainbanner"] - }, - { - cpm: 2.5, - creativeId: 'V9060', - currency: 'US', - height: 480, - mediaType: 'video', - netRevenue: false, - requestId: '273b39c74069cb', - ttl: 3000, - vastUrl: 'http://testadserver.com/ads?&k=60cd901ad8ab70c9cedf373cb17b93b8&pid=379&tid=91342717', - width: 640, - advertiserDomains: ["testaddomainvideo"] - } - ] - } - const serverResponseVideoAndBanner = { - body: serverResponse3 - } - const serverResponse4 = { - bids: [ - { - cpm: 2.5, - creativeId: 'V9060', - currency: 'US', - height: 480, - mediaType: 'video', - netRevenue: false, - requestId: '273b39c74069cb', - ttl: 3000, - vastUrl: 'http://testadserver.com/ads?&k=60cd901ad8ab70c9cedf373cb17b93b8&pid=379&tid=91342717', - width: 640, - advertiserDomains: ["testaddomainvideo"] - }, - { - cpm: 2.5, - creativeId: 'V9060', - currency: 'US', - height: 480, - mediaType: 'banner', - netRevenue: false, - requestId: '273b39c74069cb', - ttl: 3000, - ad: 'http://testadserver.com/ads?&k=60cd901ad8ab70c9cedf373cb17b93b8&pid=379&tid=91342717', - width: 640, - advertiserDomains: ["testaddomainbanner"] - } - ] - } - const serverResponseVideoAndBannerReversed = { - body: serverResponse4 - } - it('should be valid from bidRequest for video', function () { - const bidResponses = spec.interpretResponse(serverResponseVideo, bidRequest) - expect(bidResponses[0].requestId).to.equal(serverResponse.requestId) - expect(bidResponses[0].cpm).to.equal(serverResponse.cpm) - expect(bidResponses[0].width).to.equal(serverResponse.width) - expect(bidResponses[0].height).to.equal(serverResponse.height) - expect(bidResponses[0].creativeId).to.equal(serverResponse.creativeId) - expect(bidResponses[0].currency).to.equal(serverResponse.currency) - expect(bidResponses[0].netRevenue).to.equal(serverResponse.netRevenue) - expect(bidResponses[0].ttl).to.equal(serverResponse.ttl) - expect(bidResponses[0].vastUrl).to.equal(serverResponse.vastUrl) - expect(bidResponses[0].mediaType).to.equal(serverResponse.mediaType) - expect(bidResponses[0].meta.mediaType).to.equal(serverResponse.mediaType) - expect(bidResponses[0].meta.advertiserDomains).to.equal(serverResponse.advertiserDomains) - }); - it('should be valid from bidRequest for banner', function () { - const bidResponses = spec.interpretResponse(serverResponseBanner, bidRequest) - expect(bidResponses[0].requestId).to.equal(serverResponse2.requestId) - expect(bidResponses[0].cpm).to.equal(serverResponse2.cpm) - expect(bidResponses[0].width).to.equal(serverResponse2.width) - expect(bidResponses[0].height).to.equal(serverResponse2.height) - expect(bidResponses[0].creativeId).to.equal(serverResponse2.creativeId) - expect(bidResponses[0].currency).to.equal(serverResponse2.currency) - expect(bidResponses[0].netRevenue).to.equal(serverResponse2.netRevenue) - expect(bidResponses[0].ttl).to.equal(serverResponse2.ttl) - expect(bidResponses[0].ad).to.equal(serverResponse2.ad) - expect(bidResponses[0].mediaType).to.equal(serverResponse2.mediaType) - expect(bidResponses[0].meta.mediaType).to.equal(serverResponse2.mediaType) - expect(bidResponses[0].meta.advertiserDomains).to.equal(serverResponse2.advertiserDomains) - }); - it('should be valid from bidRequest for banner and video', function () { - const bidResponses = spec.interpretResponse(serverResponseVideoAndBanner, bidRequest) - expect(bidResponses[0].requestId).to.equal(serverResponse3.bids[0].requestId) - expect(bidResponses[0].cpm).to.equal(serverResponse3.bids[0].cpm) - expect(bidResponses[0].width).to.equal(serverResponse3.bids[0].width) - expect(bidResponses[0].height).to.equal(serverResponse3.bids[0].height) - expect(bidResponses[0].creativeId).to.equal(serverResponse3.bids[0].creativeId) - expect(bidResponses[0].currency).to.equal(serverResponse3.bids[0].currency) - expect(bidResponses[0].netRevenue).to.equal(serverResponse3.bids[0].netRevenue) - expect(bidResponses[0].ttl).to.equal(serverResponse3.bids[0].ttl) - expect(bidResponses[0].ad).to.equal(serverResponse3.bids[0].ad) - expect(bidResponses[0].mediaType).to.equal(serverResponse3.bids[0].mediaType) - expect(bidResponses[0].meta.mediaType).to.equal(serverResponse3.bids[0].mediaType) - expect(bidResponses[0].meta.advertiserDomains).to.equal(serverResponse3.bids[0].advertiserDomains) - - expect(bidResponses[1].requestId).to.equal(serverResponse3.bids[1].requestId) - expect(bidResponses[1].cpm).to.equal(serverResponse3.bids[1].cpm) - expect(bidResponses[1].width).to.equal(serverResponse3.bids[1].width) - expect(bidResponses[1].height).to.equal(serverResponse3.bids[1].height) - expect(bidResponses[1].creativeId).to.equal(serverResponse3.bids[1].creativeId) - expect(bidResponses[1].currency).to.equal(serverResponse3.bids[1].currency) - expect(bidResponses[1].netRevenue).to.equal(serverResponse3.bids[1].netRevenue) - expect(bidResponses[1].ttl).to.equal(serverResponse3.bids[1].ttl) - expect(bidResponses[1].vastUrl).to.equal(serverResponse3.bids[1].vastUrl) - expect(bidResponses[1].mediaType).to.equal(serverResponse3.bids[1].mediaType) - expect(bidResponses[1].meta.mediaType).to.equal(serverResponse3.bids[1].mediaType) - expect(bidResponses[1].meta.advertiserDomains).to.equal(serverResponse3.bids[1].advertiserDomains) - }) - it('should correctly handle response with video first and banner second', function () { - const bidResponses = spec.interpretResponse(serverResponseVideoAndBannerReversed, bidRequest) - expect(bidResponses[0].requestId).to.equal(serverResponse4.bids[0].requestId) - expect(bidResponses[0].cpm).to.equal(serverResponse4.bids[0].cpm) - expect(bidResponses[0].width).to.equal(serverResponse4.bids[0].width) - expect(bidResponses[0].height).to.equal(serverResponse4.bids[0].height) - expect(bidResponses[0].creativeId).to.equal(serverResponse4.bids[0].creativeId) - expect(bidResponses[0].currency).to.equal(serverResponse4.bids[0].currency) - expect(bidResponses[0].netRevenue).to.equal(serverResponse4.bids[0].netRevenue) - expect(bidResponses[0].ttl).to.equal(serverResponse4.bids[0].ttl) - expect(bidResponses[0].vastUrl).to.equal(serverResponse4.bids[0].vastUrl) - expect(bidResponses[0].mediaType).to.equal(serverResponse4.bids[0].mediaType) - expect(bidResponses[0].meta.mediaType).to.equal(serverResponse4.bids[0].mediaType) - expect(bidResponses[0].meta.advertiserDomains).to.equal(serverResponse4.bids[0].advertiserDomains) - - expect(bidResponses[1].requestId).to.equal(serverResponse4.bids[1].requestId) - expect(bidResponses[1].cpm).to.equal(serverResponse4.bids[1].cpm) - expect(bidResponses[1].width).to.equal(serverResponse4.bids[1].width) - expect(bidResponses[1].height).to.equal(serverResponse4.bids[1].height) - expect(bidResponses[1].creativeId).to.equal(serverResponse4.bids[1].creativeId) - expect(bidResponses[1].currency).to.equal(serverResponse4.bids[1].currency) - expect(bidResponses[1].netRevenue).to.equal(serverResponse4.bids[1].netRevenue) - expect(bidResponses[1].ttl).to.equal(serverResponse4.bids[1].ttl) - expect(bidResponses[1].ad).to.equal(serverResponse4.bids[1].ad) - expect(bidResponses[1].mediaType).to.equal(serverResponse4.bids[1].mediaType) - expect(bidResponses[1].meta.mediaType).to.equal(serverResponse4.bids[1].mediaType) - expect(bidResponses[1].meta.advertiserDomains).to.equal(serverResponse4.bids[1].advertiserDomains) - }); - }); - describe('setPlacementID', function () { - const multiplePlacementIds = ['380', '381'] - it('should be valid with an array of placement ids passed', function () { - const placementID = spec.setPlacementID(multiplePlacementIds) - expect(placementID).to.equal('380#381') - }); - it('should be valid with single placement ID passed', function () { - const placementID = spec.setPlacementID('381') - expect(placementID).to.equal('381') - }); - }); - // Add other `describe` or `it` blocks as necessary -}); diff --git a/test/spec/modules/pinkLionBidAdapter_spec.js b/test/spec/modules/pinkLionBidAdapter_spec.js deleted file mode 100644 index 1420eef14..000000000 --- a/test/spec/modules/pinkLionBidAdapter_spec.js +++ /dev/null @@ -1,478 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/pinkLionBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'pinkLion'; - -describe('PinkLionBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://us-east-ep.pinklion.io/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); -}); diff --git a/test/spec/modules/pixfutureBidAdapter_spec.js b/test/spec/modules/pixfutureBidAdapter_spec.js deleted file mode 100644 index 78069c624..000000000 --- a/test/spec/modules/pixfutureBidAdapter_spec.js +++ /dev/null @@ -1,255 +0,0 @@ -import { expect } from 'chai'; // may prefer 'assert' in place of 'expect' -import { spec } from 'modules/pixfutureBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import * as bidderFactory from 'src/adapters/bidderFactory.js'; -import { auctionManager } from 'src/auctionManager.js'; -import { deepClone } from 'src/utils.js'; -import { config } from 'src/config.js'; - -describe('PixFutureAdapter', function () { - it('', function () { - const adapter = newBidder(spec); - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - // Test of isBidRequestValid method - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'pixfuture', - 'pageUrl': 'https://adinify.com/prebidjs/?pbjs_debug=true', - 'bidId': '236e806f760f0c', - 'auctionId': 'aa7f5d76-806b-4e0d-b795-cd6bd84ddc63', - 'transactionId': '0fdf67c0-7b48-4fef-9716-cc64d948e95d', - 'adUnitCode': '26335x300x250x14x_ADSLOT88', - 'sizes': [[300, 250], [300, 600]], - 'params': { - 'pix_id': '777' - } - }; - it('should return true when required params found (bid)', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when required params found (bid.param=true)', function () { - delete bid.params; - bid.params = { - 'pix_id': '777' - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'pix_id': 0 - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - // Test of buildRequest method - - describe('Test of buildRequest method', function () { - const validBidRequests = [{ - 'labelAny': ['display'], - 'bidder': 'pixfuture', - 'params': { - 'pix_id': '777' - }, - 'userId': { - 'criteoId': 'P9iqSF9MSDVlZ2ZwdTVGanp5U2l0MWt1cnZya25TdEs4VlY4ZjNTeHQ4czlJUkZES0NFRXBZblJNcTNYYjU4MWxYS2VWalM5dnd5RUhRYm0lMkJuQUFNVm1iclRvSVJTYzBuNkcxZUtTa2duRyUyQnU4S3clM0Q', - 'id5id': { - 'uid': 'ID5-ZHMOcvSShIBZiIth_yYh9odjNFxVEmMQ_i5TArPfWw!ID5*dtrjfV5mPLasyya5TW2IE9oVzQZwx7xRPGyAYS4hcWkAAOoxoFef4bIoREpQys8x', - 'ext': { - 'linkType': 2 - } - }, - 'pubcid': 'e09ab6a3-ae74-4f01-b2e8-81b141d6dc61', - 'sharedid': { - 'id': '01EXPPGZ9C8NKG1MTXVHV98505', - 'third': '01EXPPGZ9C8NKG1MTXVHV98505' - } - }, - 'userIdAsEids': [{ - 'source': 'criteo.com', - 'uids': [{ - 'id': 'P9iqSF9MSDVlZ2ZwdTVGanp5U2l0MWt1cnZya25TdEs4VlY4ZjNTeHQ4czlJUkZES0NFRXBZblJNcTNYYjU4MWxYS2VWalM5dnd5RUhRYm0lMkJuQUFNVm1iclRvSVJTYzBuNkcxZUtTa2duRyUyQnU4S3clM0Q', - 'atype': 1 - }] - }, { - 'source': 'id5-sync.com', - 'uids': [{ - 'id': 'ID5-ZHMOcvSShIBZiIth_yYh9odjNFxVEmMQ_i5TArPfWw!ID5*dtrjfV5mPLasyya5TW2IE9oVzQZwx7xRPGyAYS4hcWkAAOoxoFef4bIoREpQys8x', - 'atype': 1, - 'ext': { - 'linkType': 2 - } - }] - }, { - 'source': 'pubcid.org', - 'uids': [{ - 'id': 'e09ab6a3-ae74-4f01-b2e8-81b141d6dc61', - 'atype': 1 - }] - }, { - 'source': 'sharedid.org', - 'uids': [{ - 'id': '01EXPPGZ9C8NKG1MTXVHV98505', - 'atype': 1, - 'ext': { - 'third': '01EXPPGZ9C8NKG1MTXVHV98505' - } - }] - }], - 'crumbs': { - 'pubcid': 'e09ab6a3-ae74-4f01-b2e8-81b141d6dc61' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 250] - ] - } - }, - 'adUnitCode': '26335x300x250x14x_ADSLOT88', - 'transactionId': '09310832-cd12-478c-86dd-fbd819dff9d3', - 'sizes': [ - [300, 250] - ], - 'bidId': '279272f27dfb3e', - 'bidderRequestId': '10a0de227377a3', - 'auctionId': '4cd5684b-ae2a-4d1f-84be-5f1ee66d9ff3', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [{ - 'asi': 'pixfuture.com', - 'sid': '14', - 'hp': 1 - }] - } - }]; - - const bidderRequests = - { - 'bidderCode': 'pixfuture', - 'auctionId': '4cd5684b-ae2a-4d1f-84be-5f1ee66d9ff3', - 'bidderRequestId': '10a0de227377a3', - 'bids': [{ - 'labelAny': ['display'], - 'bidder': 'pixfuture', - 'params': { - 'pix_id': '777' - }, - 'userId': { - 'criteoId': 'P9iqSF9MSDVlZ2ZwdTVGanp5U2l0MWt1cnZya25TdEs4VlY4ZjNTeHQ4czlJUkZES0NFRXBZblJNcTNYYjU4MWxYS2VWalM5dnd5RUhRYm0lMkJuQUFNVm1iclRvSVJTYzBuNkcxZUtTa2duRyUyQnU4S3clM0Q', - 'id5id': { - 'uid': 'ID5-ZHMOcvSShIBZiIth_yYh9odjNFxVEmMQ_i5TArPfWw!ID5*dtrjfV5mPLasyya5TW2IE9oVzQZwx7xRPGyAYS4hcWkAAOoxoFef4bIoREpQys8x', - 'ext': { - 'linkType': 2 - } - }, - 'pubcid': 'e09ab6a3-ae74-4f01-b2e8-81b141d6dc61', - 'sharedid': { - 'id': '01EXPPGZ9C8NKG1MTXVHV98505', - 'third': '01EXPPGZ9C8NKG1MTXVHV98505' - } - }, - 'userIdAsEids': [{ - 'source': 'criteo.com', - 'uids': [{ - 'id': 'P9iqSF9MSDVlZ2ZwdTVGanp5U2l0MWt1cnZya25TdEs4VlY4ZjNTeHQ4czlJUkZES0NFRXBZblJNcTNYYjU4MWxYS2VWalM5dnd5RUhRYm0lMkJuQUFNVm1iclRvSVJTYzBuNkcxZUtTa2duRyUyQnU4S3clM0Q', - 'atype': 1 - }] - }, { - 'source': 'id5-sync.com', - 'uids': [{ - 'id': 'ID5-ZHMOcvSShIBZiIth_yYh9odjNFxVEmMQ_i5TArPfWw!ID5*dtrjfV5mPLasyya5TW2IE9oVzQZwx7xRPGyAYS4hcWkAAOoxoFef4bIoREpQys8x', - 'atype': 1, - 'ext': { - 'linkType': 2 - } - }] - }, { - 'source': 'pubcid.org', - 'uids': [{ - 'id': 'e09ab6a3-ae74-4f01-b2e8-81b141d6dc61', - 'atype': 1 - }] - }, { - 'source': 'sharedid.org', - 'uids': [{ - 'id': '01EXPPGZ9C8NKG1MTXVHV98505', - 'atype': 1, - 'ext': { - 'third': '01EXPPGZ9C8NKG1MTXVHV98505' - } - }] - }], - 'crumbs': { - 'pubcid': 'e09ab6a3-ae74-4f01-b2e8-81b141d6dc61' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 250] - ] - } - }, - 'adUnitCode': '26335x300x250x14x_ADSLOT88', - 'transactionId': '09310832-cd12-478c-86dd-fbd819dff9d3', - 'sizes': [ - [300, 250] - ], - 'bidId': '279272f27dfb3e', - 'bidderRequestId': '10a0de227377a3', - 'auctionId': '4cd5684b-ae2a-4d1f-84be-5f1ee66d9ff3', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [{ - 'asi': 'pixfuture.com', - 'sid': '14', - 'hp': 1 - }] - } - }], - 'auctionStart': 1620934247115, - 'timeout': 3000, - 'refererInfo': { - 'referer': 'https://adinify.com/prebidjs/?pbjs_debug=true', - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': ['https://adinify.com/prebidjs/?pbjs_debug=true'], - 'canonicalUrl': null - }, - 'start': 1620934247117 - }; - - // let bidderRequest = Object.assign({}, bidderRequests); - const request = spec.buildRequests(validBidRequests, bidderRequests); - // console.log(JSON.stringify(request)); - const bidRequest = Object.assign({}, request[0]); - - expect(bidRequest.data).to.exist; - expect(bidRequest.data.sizes).to.deep.equal([[300, 250]]); - expect(bidRequest.data.params).to.deep.equal({'pix_id': '777'}); - expect(bidRequest.data.adUnitCode).to.deep.equal('26335x300x250x14x_ADSLOT88'); - }); - }); - // Add other `describe` or `it` blocks as necessary -}); diff --git a/test/spec/modules/playdigoBidAdapter_spec.js b/test/spec/modules/playdigoBidAdapter_spec.js deleted file mode 100644 index d3a2fc204..000000000 --- a/test/spec/modules/playdigoBidAdapter_spec.js +++ /dev/null @@ -1,478 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/playdigoBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'playdigo' - -describe('PlaydigoBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://server.playdigo.com/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); -}); diff --git a/test/spec/modules/precisoBidAdapter_spec.js b/test/spec/modules/precisoBidAdapter_spec.js deleted file mode 100644 index 2022fb137..000000000 --- a/test/spec/modules/precisoBidAdapter_spec.js +++ /dev/null @@ -1,342 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/precisoBidAdapter.js'; -import { NATIVE } from '../../../src/mediaTypes.js'; -import { OPENRTB } from '../../../libraries/precisoUtils/bidNativeUtils.js'; - -// simport { config } from '../../../src/config.js'; - -const DEFAULT_PRICE = 1 -const DEFAULT_CURRENCY = 'USD' -const DEFAULT_BANNER_WIDTH = 300 -const DEFAULT_BANNER_HEIGHT = 250 -const BIDDER_CODE = 'preciso'; - -describe('PrecisoAdapter', function () { - const bid = { - precisoBid: true, - bidId: '23fhj33i987f', - bidder: 'preciso', - buyerUid: 'testuid', - mediaTypes: { - banner: { - sizes: [[DEFAULT_BANNER_WIDTH, DEFAULT_BANNER_HEIGHT]] - } - }, - params: { - host: 'prebid', - sourceid: '0', - publisherId: '0', - mediaType: 'banner', - region: 'IND' - - }, - userId: { - pubcid: '12355454test' - - }, - user: { - geo: { - region: 'IND', - } - }, - ortb2: { - device: { - w: 1920, - h: 166, - dnt: 0, - }, - site: { - domain: 'localHost' - }, - source: { - tid: 'eaff09b-a1ab-4ec6-a81e-c5a75bc1dde3' - } - - } - - }; - - let nativeBid = { - precisoBid: true, - bidId: '23fhj33i987f', - bidder: 'precisonat', - buyerUid: 'testuid', - params: { - host: 'prebid', - sourceid: '0', - publisherId: '0', - mediaType: 'native', - region: 'IND' - - }, - userId: { - pubcid: '12355454test' - - }, - user: { - geo: { - region: 'IND', - } - }, - ortb2: { - device: { - w: 1920, - h: 166, - dnt: 0, - }, - site: { - domain: 'localHost' - }, - source: { - tid: 'eaff09b-a1ab-4ec6-a81e-c5a75bc1dde3' - } - - }, - mediaType: 'native', - nativeOrtbRequest: { - assets: [ - { - id: 2, - required: 1, - img: { - type: 3, - w: 300, - h: 250 - } - } - ] - }, - nativeParams: { - ortb: { - assets: [ - { - id: 2, - required: 1, - img: { - type: 3, - w: 300, - h: 250 - } - } - ] - } - } - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and sourceid parameters present', function () { - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - delete bid.params.publisherId; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - it('Should return true if there are bidId, params and sourceid parameters present native Bid', function () { - expect(spec.isBidRequestValid(nativeBid)).to.be.true; - }); - - it('Should return false if at least one of parameters is not present in native bid', function () { - delete nativeBid.params.publisherId; - expect(spec.isBidRequestValid(nativeBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests([bid]); - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://ssp-bidder.2trk.info/bid_request/openrtb'); - }); - it('Returns valid data if array of bids is valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data.device).to.be.a('object'); - expect(data.user).to.be.a('object'); - expect(data.source).to.be.a('object'); - expect(data.site).to.be.a('object'); - }); - it('Returns empty data if no valid requests are passed', function () { - delete bid.ortb2.device; - serverRequest = spec.buildRequests([bid]); - const data = serverRequest.data; - expect(data.device).to.be.undefined; - }); - - let ServeNativeRequest = spec.buildRequests([nativeBid]); - - it('Creates a valid nativeServerRequest object ', function () { - expect(ServeNativeRequest).to.exist; - expect(ServeNativeRequest.method).to.exist; - expect(ServeNativeRequest.url).to.exist; - expect(ServeNativeRequest.data).to.exist; - expect(ServeNativeRequest.method).to.equal('POST'); - expect(ServeNativeRequest.url).to.equal('https://ssp-bidder.2trk.info/bid_request/openrtb'); - }); - - it('should extract the native params', function () { - let nativeData = ServeNativeRequest.data; - const asset = JSON.parse(nativeData.imp[0].native.request).assets[0] - expect(asset).to.deep.equal({ - id: OPENRTB.NATIVE.ASSET_ID.IMAGE, - required: 1, - img: { - w: 300, - h: 250, - type: OPENRTB.NATIVE.IMAGE_TYPE.MAIN, - } - } - ) - }); - }); - - describe('interpretResponse', function () { - it('should get correct bid response', function () { - const response = { - - bidderRequestId: 'f6adb85f-4e19-45a0-b41e-2a5b9a48f23a', - - seatbid: [ - { - bid: [ - { - id: '123', - impid: 'b4f290d7-d4ab-4778-ab94-2baf06420b22', - price: DEFAULT_PRICE, - adm: 'hi', - cid: 'test_cid', - crid: 'test_banner_crid', - w: DEFAULT_BANNER_WIDTH, - h: DEFAULT_BANNER_HEIGHT, - adomain: [], - } - ], - seat: BIDDER_CODE - } - ], - } - - const expectedResponse = [ - { - requestId: 'b4f290d7-d4ab-4778-ab94-2baf06420b22', - cpm: DEFAULT_PRICE, - width: DEFAULT_BANNER_WIDTH, - height: DEFAULT_BANNER_HEIGHT, - creativeId: 'test_banner_crid', - ad: 'hi', - currency: DEFAULT_CURRENCY, - netRevenue: true, - ttl: 300, - meta: { advertiserDomains: [] }, - } - ] - const result = spec.interpretResponse({ body: response }) - - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])) - }) - - it('should get correct native bid response', function () { - const adm = { - native: { - ver: 1.2, - link: { - url: 'https://example.com', - clicktrackers: 'https://example.com/clktracker' - }, - eventtrackers: [ - { - url: 'https://example.com/imptracker' - } - ], - imptrackers: [ - 'https://example.com/imptracker' - ], - assets: [{ - id: OPENRTB.NATIVE.ASSET_ID.IMAGE, - required: 1, - img: { - url: 'https://example.com/image.jpg', - w: 150, - h: 50 - } - }], - } - } - let nativeResponse = { - bidderRequestId: 'f6adb85f-4e19-45a0-b41e-2a5b9a48f23a', - seatbid: [ - { - bid: [ - { - id: '123', - impid: 'b4f290d7-d4ab-4778-ab94-2baf06420b22', - price: DEFAULT_PRICE, - adm: JSON.stringify(adm), - cid: 'test_cid', - crid: 'test_banner_crid', - w: DEFAULT_BANNER_WIDTH, - h: DEFAULT_BANNER_HEIGHT, - adomain: [], - } - ], - seat: BIDDER_CODE - } - ], - } - - let expectedNativeResponse = [ - { - requestId: 'b4f290d7-d4ab-4778-ab94-2baf06420b22', - mediaType: NATIVE, - cpm: DEFAULT_PRICE, - creativeId: 'test_banner_crid', - width: 1, - height: 1, - ttl: 300, - meta: { - advertiserDomains: [] - }, - netRevenue: true, - currency: 'USD', - // meta: { advertiserDomains: [] }, - native: { - clickUrl: encodeURI('https://example.com'), - impressionTrackers: ['https://example.com/imptracker'], - image: { - url: encodeURI('https://example.com/image.jpg'), - width: 150, - height: 50 - }, - } - } - ] - - let result = spec.interpretResponse({ body: nativeResponse }); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedNativeResponse[0])); - }) - }) - - describe('getUserSyncs', function () { - const syncUrl = 'https://ck.2trk.info/rtb/user/usersync.aspx?id=NA&gdpr=0&gdpr_consent=&us_privacy=&t=4'; - const syncOptions = { - iframeEnabled: true, - spec: true - }; - const userSync = spec.getUserSyncs(syncOptions); - it('Returns valid URL and type', function () { - expect(userSync).to.be.an('array').with.lengthOf(1); - expect(userSync[0].type).to.exist; - expect(userSync[0].url).to.exist; - expect(userSync).to.deep.equal([ - { type: 'iframe', url: syncUrl } - ]); - }); - }); -}); diff --git a/test/spec/modules/prismaBidAdapter_spec.js b/test/spec/modules/prismaBidAdapter_spec.js deleted file mode 100644 index a368378a4..000000000 --- a/test/spec/modules/prismaBidAdapter_spec.js +++ /dev/null @@ -1,261 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/prismaBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import {config} from 'src/config.js'; -import * as utils from 'src/utils.js'; -import { requestBidsHook } from 'modules/consentManagementTcf.js'; - -describe('Prisma bid adapter tests', function () { - const DISPLAY_BID_REQUEST = [{ - 'bidder': 'prisma', - 'params': { - 'account': '1067', - 'tagId': 'luvxjvgn' - }, - 'userId': { - 'id5id': { - 'uid': 'ID5*hQ5WobYI9Od4u52qpaXVKHhxUa4DsOWRAlvaFajm8gINfI1oVAe3UK59416dT4TqDX1pj4MBJ5TYwir6x3JgBw1-avYHSnmvQDdRMbxmC2sNf3ggIRTbyQBdI1RjvHyeDYCsistnTXF_iKF1nutYeQ2BZ4P5d5muZTG7C2PXVFgNg-18io9dCiSjzJXx93KPDYRiuIwtsGGsp51rojlpFw2Fp_dUkjXl4CAblk58DvwNhobwQ27bnBP8F2-Pcs88DYcvKn4r6dm3Vi7ILttxDQ2IgZ2X44ClgjoWh-vRf6ANis8Z7uL16vO8q0P5C21eDYuc4v_KaZqN-p9YWEeEZQ2OpkbRL7n5NieVJExHM6ANkAlLZhVf2T-1906TAIHKDZFm_xMCa1jJfpBqZB2agw2TjfbK6wMtJeHiZaipSuUNlM_CSH0HVXtfMj9yfzjzDZZnltZQ9lvc4JhXye5AwA2X1f9Dhk8VURTvVdfEUlU', - 'ext': { - 'linkType': 2 - } - } - }, - 'userIdAsEids': [ - { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': 'ID5*hQ5WobYI9Od4u52qpaXVKHhxUa4DsOWRAlvaFajm8gINfI1oVAe3UK59416dT4TqDX1pj4MBJ5TYwir6x3JgBw1-avYHSnmvQDdRMbxmC2sNf3ggIRTbyQBdI1RjvHyeDYCsistnTXF_iKF1nutYeQ2BZ4P5d5muZTG7C2PXVFgNg-18io9dCiSjzJXx93KPDYRiuIwtsGGsp51rojlpFw2Fp_dUkjXl4CAblk58DvwNhobwQ27bnBP8F2-Pcs88DYcvKn4r6dm3Vi7ILttxDQ2IgZ2X44ClgjoWh-vRf6ANis8Z7uL16vO8q0P5C21eDYuc4v_KaZqN-p9YWEeEZQ2OpkbRL7n5NieVJExHM6ANkAlLZhVf2T-1906TAIHKDZFm_xMCa1jJfpBqZB2agw2TjfbK6wMtJeHiZaipSuUNlM_CSH0HVXtfMj9yfzjzDZZnltZQ9lvc4JhXye5AwA2X1f9Dhk8VURTvVdfEUlU', - 'atype': 1, - 'ext': { - 'linkType': 2 - } - } - ] - } - ], - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 600]] - } - }, - 'adUnitCode': 'banner-div', - 'transactionId': '9ad89d90-eb73-41b9-bf5f-7a8e2eecff27', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '4d9e29504f8af6', - 'bidderRequestId': '3423b6bd1a922c', - 'auctionId': '05e0a3a1-9f57-41f6-bbcb-2ba9c9e3d2d5', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - }]; - - const DISPLAY_BID_RESPONSE = {'body': { - 'responses': [ - { - 'bidId': '4d9e29504f8af6', - 'cpm': 0.437245, - 'width': 300, - 'height': 250, - 'creativeId': '98493581', - 'currency': 'EUR', - 'netRevenue': true, - 'type': 'banner', - 'ttl': 360, - 'uuid': 'ce6d1ee3-2a05-4d7c-b97a-9e62097798ec', - 'bidder': 'appnexus', - 'consent': 1, - 'tagId': 'luvxjvgn' - } - ], - }}; - - const VIDEO_BID_REQUEST = [ - { - 'bidder': 'prisma', - 'params': { - 'account': '1067', - 'tagId': 'yqsc1tfj' - }, - 'mediaTypes': { - 'video': { - 'context': 'instream', - 'playerSize': [[640, 480]], - 'mimes': ['video/mp4'], - 'protocols': [1, 2, 3, 4, 5, 6], - 'playbackmethod': [2], - 'skip': 1 - } - }, - 'adUnitCode': 'video1', - 'transactionId': '5434c81c-7210-44ae-9014-67c75dee48d0', - 'sizes': [[640, 480]], - 'bidId': '22f90541e576a3', - 'bidderRequestId': '1d4549243f3bfd', - 'auctionId': 'ed21b528-bcab-47e2-8605-ec9b71000c89', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ] - - const VIDEO_BID_RESPONSE = {'body': { - 'responses': [ - { - 'bidId': '2c129e8e01859a', - 'type': 'video', - 'uuid': 'b8e7b2f0-c378-479f-aa4f-4f55d5d7d1d5', - 'cpm': 4.5421, - 'width': 1, - 'height': 1, - 'creativeId': '97517771', - 'currency': 'EUR', - 'netRevenue': true, - 'ttl': 360, - 'bidder': 'appnexus', - 'consent': 1, - 'tagId': 'yqsc1tfj' - } - ] - }}; - - const DEFAULT_OPTIONS = { - gdprConsent: { - gdprApplies: true, - consentString: 'BOzZdA0OzZdA0AGABBENDJ-AAAAvh7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__79__3z3_9pxP78k89r7337Mw_v-_v-b7JCPN_Y3v-8Kg', - vendorData: {} - }, - refererInfo: { - referer: 'https://www.prebid.org', - canonicalUrl: 'https://www.prebid.org/the/link/to/the/page' - }, - uspConsent: '111222333', - userId: { 'id5id': { uid: '1111' } }, - schain: { - 'ver': '1.0', - 'complete': 1, - 'nodes': [{ - 'asi': 'exchange1.com', - 'sid': '1234', - 'hp': 1, - 'rid': 'bid-request-1', - 'name': 'publisher', - 'domain': 'publisher.com' - }] - }, - }; - - it('Verify banner build request', function () { - const request = spec.buildRequests(DISPLAY_BID_REQUEST, DEFAULT_OPTIONS); - expect(request).to.have.property('url').and.to.equal('https://prisma.nexx360.io/prebid'); - expect(request).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request.data); - expect(requestContent.userEids.length).to.be.eql(1); - expect(requestContent.userEids[0]).to.have.property('source').and.to.equal('id5-sync.com'); - expect(requestContent.userEids[0]).to.have.property('uids'); - expect(requestContent.userEids[0].uids[0]).to.have.property('id').and.to.equal('ID5*hQ5WobYI9Od4u52qpaXVKHhxUa4DsOWRAlvaFajm8gINfI1oVAe3UK59416dT4TqDX1pj4MBJ5TYwir6x3JgBw1-avYHSnmvQDdRMbxmC2sNf3ggIRTbyQBdI1RjvHyeDYCsistnTXF_iKF1nutYeQ2BZ4P5d5muZTG7C2PXVFgNg-18io9dCiSjzJXx93KPDYRiuIwtsGGsp51rojlpFw2Fp_dUkjXl4CAblk58DvwNhobwQ27bnBP8F2-Pcs88DYcvKn4r6dm3Vi7ILttxDQ2IgZ2X44ClgjoWh-vRf6ANis8Z7uL16vO8q0P5C21eDYuc4v_KaZqN-p9YWEeEZQ2OpkbRL7n5NieVJExHM6ANkAlLZhVf2T-1906TAIHKDZFm_xMCa1jJfpBqZB2agw2TjfbK6wMtJeHiZaipSuUNlM_CSH0HVXtfMj9yfzjzDZZnltZQ9lvc4JhXye5AwA2X1f9Dhk8VURTvVdfEUlU'); - expect(requestContent.adUnits[0]).to.have.property('account').and.to.equal('1067'); - expect(requestContent.adUnits[0]).to.have.property('tagId').and.to.equal('luvxjvgn'); - expect(requestContent.adUnits[0]).to.have.property('label').and.to.equal('banner-div'); - expect(requestContent.adUnits[0]).to.have.property('bidId').and.to.equal('4d9e29504f8af6'); - expect(requestContent.adUnits[0]).to.have.property('auctionId').and.to.equal('05e0a3a1-9f57-41f6-bbcb-2ba9c9e3d2d5'); - expect(requestContent.adUnits[0]).to.have.property('mediatypes').exist; - expect(requestContent.adUnits[0].mediatypes).to.have.property('banner').exist; - expect(requestContent.adUnits[0]).to.have.property('bidfloor').and.to.equal(0); - expect(requestContent.adUnits[0]).to.have.property('bidfloorCurrency').and.to.equal('USD'); - expect(requestContent.adUnits[0]).to.have.property('keywords'); - expect(requestContent.adUnits[0].keywords.length).to.be.eql(0); - }); - - it('Verify banner parse response', function () { - const request = spec.buildRequests(DISPLAY_BID_REQUEST, DEFAULT_OPTIONS); - const response = spec.interpretResponse(DISPLAY_BID_RESPONSE, request); - expect(response).to.have.lengthOf(1); - const bid = response[0]; - expect(bid.cpm).to.equal(0.437245); - expect(bid.adUrl).to.equal('https://prisma.nexx360.io/cache?uuid=ce6d1ee3-2a05-4d7c-b97a-9e62097798ec'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creativeId).to.equal('98493581'); - expect(bid.currency).to.equal('EUR'); - expect(bid.netRevenue).to.equal(true); - expect(bid.ttl).to.equal(360); - expect(bid.requestId).to.equal('4d9e29504f8af6'); - expect(bid.prisma).to.exist; - expect(bid.prisma.ssp).to.equal('appnexus'); - }); - - it('Verify video build request', function () { - const request = spec.buildRequests(VIDEO_BID_REQUEST, DEFAULT_OPTIONS); - expect(request).to.have.property('url').and.to.equal('https://prisma.nexx360.io/prebid'); - expect(request).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request.data); - expect(requestContent.adUnits[0]).to.have.property('account').and.to.equal('1067'); - expect(requestContent.adUnits[0]).to.have.property('tagId').and.to.equal('yqsc1tfj'); - expect(requestContent.adUnits[0]).to.have.property('label').and.to.equal('video1'); - expect(requestContent.adUnits[0]).to.have.property('bidId').and.to.equal('22f90541e576a3'); - expect(requestContent.adUnits[0]).to.have.property('auctionId').and.to.equal('ed21b528-bcab-47e2-8605-ec9b71000c89'); - expect(requestContent.adUnits[0]).to.have.property('mediatypes').exist; - expect(requestContent.adUnits[0].mediatypes).to.have.property('video').exist; - }); - - it('Verify video parse response', function () { - const request = spec.buildRequests(VIDEO_BID_REQUEST, DEFAULT_OPTIONS); - const response = spec.interpretResponse(VIDEO_BID_RESPONSE, request); - expect(response).to.have.lengthOf(1); - const bid = response[0]; - expect(bid.cpm).to.equal(4.5421); - expect(bid.vastUrl).to.equal('https://prisma.nexx360.io/cache?uuid=b8e7b2f0-c378-479f-aa4f-4f55d5d7d1d5'); - expect(bid.vastImpUrl).to.equal('https://prisma.nexx360.io/track-imp?type=prebid&mediatype=video&ssp=appnexus&tag_id=yqsc1tfj&consent=1&price=4.5421'); - expect(bid.width).to.equal(1); - expect(bid.height).to.equal(1); - expect(bid.creativeId).to.equal('97517771'); - expect(bid.currency).to.equal('EUR'); - expect(bid.netRevenue).to.equal(true); - expect(bid.ttl).to.equal(360); - expect(bid.requestId).to.equal('2c129e8e01859a'); - expect(bid.prisma).to.exist; - expect(bid.prisma.ssp).to.equal('appnexus'); - }); - - it('Verifies bidder code', function () { - expect(spec.code).to.equal('prisma'); - }); - - it('Verifies bidder aliases', function () { - expect(spec.aliases).to.have.lengthOf(1); - expect(spec.aliases[0]).to.eql('prismadirect'); - }); - it('Verifies if bid request valid', function () { - expect(spec.isBidRequestValid(DISPLAY_BID_REQUEST[0])).to.equal(true); - }); - it('Verifies bid won', function () { - const request = spec.buildRequests(DISPLAY_BID_REQUEST, DEFAULT_OPTIONS); - const response = spec.interpretResponse(DISPLAY_BID_RESPONSE, request); - const won = spec.onBidWon(response[0]); - expect(won).to.equal(true); - }); - it('Verifies user sync without cookie in bid response', function () { - var syncs = spec.getUserSyncs({}, [DISPLAY_BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.have.lengthOf(0); - }); - it('Verifies user sync with cookies in bid response', function () { - DISPLAY_BID_RESPONSE.body.cookies = [{'type': 'image', 'url': 'http://www.cookie.sync.org/'}]; - var syncs = spec.getUserSyncs({}, [DISPLAY_BID_RESPONSE], DEFAULT_OPTIONS.gdprConsent); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0]).to.have.property('type').and.to.equal('image'); - expect(syncs[0]).to.have.property('url').and.to.equal('http://www.cookie.sync.org/'); - }); - it('Verifies user sync with no bid response', function() { - var syncs = spec.getUserSyncs({}, null, DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.have.lengthOf(0); - }); - it('Verifies user sync with no bid body response', function() { - let syncs = spec.getUserSyncs({}, [], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.have.lengthOf(0); - syncs = spec.getUserSyncs({}, [{}], DEFAULT_OPTIONS.gdprConsent, DEFAULT_OPTIONS.uspConsent); - expect(syncs).to.have.lengthOf(0); - }); -}); diff --git a/test/spec/modules/programmaticXBidAdapter_spec.js b/test/spec/modules/programmaticXBidAdapter_spec.js deleted file mode 100644 index ef7f0caf7..000000000 --- a/test/spec/modules/programmaticXBidAdapter_spec.js +++ /dev/null @@ -1,788 +0,0 @@ -import {expect} from 'chai'; -import { - spec as adapter, - createDomain, - storage -} from 'modules/programmaticXBidAdapter'; -import * as utils from 'src/utils.js'; -import {version} from 'package.json'; -import {useFakeTimers} from 'sinon'; -import {BANNER, VIDEO} from '../../../src/mediaTypes.js' -import {config} from '../../../src/config.js'; -import { - hashCode, - extractPID, - extractCID, - extractSubDomain, - getStorageItem, - setStorageItem, - tryParseJSON, - getUniqueDealId, -} from '../../../libraries/vidazooUtils/bidderUtils.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -export const TEST_ID_SYSTEMS = ['criteoId', 'id5id', 'netId', 'tdid', 'pubProvidedId', 'intentIqId', 'liveIntentId']; - -const SUB_DOMAIN = 'exchange'; - -const BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': 'div-gpt-ad-12345-0', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '59db6b3b4ffaa70004f45cdc', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1, - 'ext': { - 'param1': 'loremipsum', - 'param2': 'dolorsitamet' - }, - 'placementId': 'testBanner' - }, - 'placementCode': 'div-gpt-ad-1460505748561-0', - 'sizes': [[300, 250], [300, 600]], - 'bidderRequestId': '1fdb5ff1b6eaa7', - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'requestId': 'b0777d85-d061-450e-9bc7-260dd54bbb7a', - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'mediaTypes': [BANNER], - 'ortb2Imp': { - 'ext': { - 'gpid': '0123456789', - 'tid': 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf' - } - } -}; - -const VIDEO_BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': '63550ad1ff6642d368cba59dh5884270560', - 'bidderRequestId': '12a8ae9ada9c13', - 'transactionId': '56e184c6-bde9-497b-b9b9-cf47a61381ee', - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '635509f7ff6642d368cb9837', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1, - 'placementId': 'testBanner' - }, - 'sizes': [[545, 307]], - 'mediaTypes': { - 'video': { - 'playerSize': [[545, 307]], - 'context': 'instream', - 'mimes': [ - 'video/mp4', - 'application/javascript' - ], - 'protocols': [2, 3, 5, 6], - 'maxduration': 60, - 'minduration': 0, - 'startdelay': 0, - 'linearity': 1, - 'api': [2], - 'placement': 1 - } - }, - 'ortb2Imp': { - 'ext': { - 'tid': '56e184c6-bde9-497b-b9b9-cf47a61381ee' - } - } -} - -const ORTB2_DEVICE = { - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - ext: {fiftyonedegrees_deviceId: '17595-133085-133468-18092'}, -}; - -const BIDDER_REQUEST = { - 'gdprConsent': { - 'consentString': 'consent_string', - 'gdprApplies': true - }, - 'gppString': 'gpp_string', - 'gppSid': [7], - 'uspConsent': 'consent_string', - 'refererInfo': { - 'page': 'https://www.greatsite.com', - 'ref': 'https://www.somereferrer.com' - }, - 'ortb2': { - 'site': { - 'content': { - 'language': 'en' - } - }, - 'regs': { - 'gpp': 'gpp_string', - 'gpp_sid': [7], - 'coppa': 0 - }, - 'device': ORTB2_DEVICE, - } -}; - -const SERVER_RESPONSE = { - body: { - cid: 'testcid123', - results: [{ - 'ad': '', - 'price': 0.8, - 'creativeId': '12610997325162499419', - 'exp': 30, - 'width': 300, - 'height': 250, - 'advertiserDomains': ['securepubads.g.doubleclick.net'], - 'cookies': [{ - 'src': 'https://sync.com', - 'type': 'iframe' - }, { - 'src': 'https://sync.com', - 'type': 'img' - }] - }] - } -}; - -const VIDEO_SERVER_RESPONSE = { - body: { - 'cid': '635509f7ff6642d368cb9837', - 'results': [{ - 'ad': '', - 'advertiserDomains': ['programmaticx.ai'], - 'exp': 60, - 'width': 545, - 'height': 307, - 'mediaType': 'video', - 'creativeId': '12610997325162499419', - 'price': 2, - 'cookies': [] - }] - } -}; - -const ORTB2_OBJ = { - "device": ORTB2_DEVICE, - "regs": {"coppa": 0, "gpp": "gpp_string", "gpp_sid": [7]}, - "site": {"content": {"language": "en"} - } -}; - -const REQUEST = { - data: { - width: 300, - height: 250, - bidId: '2d52001cabd527' - } -}; - -function getTopWindowQueryParams() { - try { - const parsedUrl = utils.parseUrl(window.top.document.URL, {decodeSearchAsString: true}); - return parsedUrl.search; - } catch (e) { - return ''; - } -} - -describe('programmaticXBidAdapter', function () { - before(() => config.resetConfig()); - after(() => config.resetConfig()); - - describe('validtae spec', function () { - it('exists and is a function', function () { - expect(adapter.isBidRequestValid).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.buildRequests).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.interpretResponse).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.getUserSyncs).to.exist.and.to.be.a('function'); - }); - - it('exists and is a string', function () { - expect(adapter.code).to.exist.and.to.be.a('string'); - }); - - it('exists and contains media types', function () { - expect(adapter.supportedMediaTypes).to.exist.and.to.be.an('array').with.length(2); - expect(adapter.supportedMediaTypes).to.contain.members([BANNER, VIDEO]); - }); - }); - - describe('validate bid requests', function () { - it('should require cId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - pId: 'pid' - } - }); - expect(isValid).to.be.false; - }); - - it('should require pId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid' - } - }); - expect(isValid).to.be.false; - }); - - it('should validate correctly', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid', - pId: 'pid' - } - }); - expect(isValid).to.be.true; - }); - }); - - describe('build requests', function () { - let sandbox; - before(function () { - getGlobal().bidderSettings = { - programmaticX: { - storageAllowed: true - } - }; - sandbox = sinon.createSandbox(); - sandbox.stub(Date, 'now').returns(1000); - }); - - it('should build video request', function () { - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - config.setConfig({ - bidderTimeout: 3000 - }); - const requests = adapter.buildRequests([VIDEO_BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/635509f7ff6642d368cb9837`, - data: { - adUnitCode: '63550ad1ff6642d368cba59dh5884270560', - bidFloor: 0.1, - bidId: '2d52001cabd527', - bidderVersion: adapter.version, - bidderRequestId: '12a8ae9ada9c13', - cb: 1000, - gdpr: 1, - gdprConsent: 'consent_string', - usPrivacy: 'consent_string', - gppString: 'gpp_string', - gppSid: [7], - prebidVersion: version, - transactionId: '56e184c6-bde9-497b-b9b9-cf47a61381ee', - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - publisherId: '59ac17c192832d0011283fe3', - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - res: `${window.top.screen.width}x${window.top.screen.height}`, - schain: VIDEO_BID.schain, - sizes: ['545x307'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - uqs: getTopWindowQueryParams(), - mediaTypes: { - video: { - api: [2], - context: 'instream', - linearity: 1, - maxduration: 60, - mimes: [ - 'video/mp4', - 'application/javascript' - ], - minduration: 0, - placement: 1, - playerSize: [[545, 307]], - protocols: [2, 3, 5, 6], - startdelay: 0 - } - }, - gpid: '', - cat: [], - contentLang: 'en', - contentData: [], - isStorageAllowed: true, - pagecat: [], - ortb2Imp: VIDEO_BID.ortb2Imp, - ortb2: ORTB2_OBJ, - placementId: "testBanner", - userData: [], - coppa: 0 - } - }); - }); - - it('should build banner request for each size', function () { - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - config.setConfig({ - bidderTimeout: 3000 - }); - const requests = adapter.buildRequests([BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/59db6b3b4ffaa70004f45cdc`, - data: { - gdprConsent: 'consent_string', - gdpr: 1, - gppString: 'gpp_string', - gppSid: [7], - usPrivacy: 'consent_string', - transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - bidderRequestId: '1fdb5ff1b6eaa7', - sizes: ['300x250', '300x600'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - cb: 1000, - bidFloor: 0.1, - bidId: '2d52001cabd527', - adUnitCode: 'div-gpt-ad-12345-0', - publisherId: '59ac17c192832d0011283fe3', - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - bidderVersion: adapter.version, - prebidVersion: version, - schain: BID.schain, - res: `${window.top.screen.width}x${window.top.screen.height}`, - mediaTypes: [BANNER], - gpid: '0123456789', - uqs: getTopWindowQueryParams(), - 'ext.param1': 'loremipsum', - 'ext.param2': 'dolorsitamet', - cat: [], - contentLang: 'en', - contentData: [], - isStorageAllowed: true, - pagecat: [], - ortb2Imp: BID.ortb2Imp, - ortb2: ORTB2_OBJ, - placementId: "testBanner", - userData: [], - coppa: 0 - } - }); - }); - - after(function () { - getGlobal().bidderSettings = {}; - sandbox.restore(); - }); - }); - describe('getUserSyncs', function () { - it('should have valid user sync with iframeEnabled', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.programmaticx.ai/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - - it('should have valid user sync with cid on response', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.programmaticx.ai/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - - it('should have valid user sync with pixelEnabled', function () { - const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE]); - - expect(result).to.deep.equal([{ - 'url': 'https://sync.programmaticx.ai/api/sync/image/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0', - 'type': 'image' - }]); - }); - - it('should have valid user sync with coppa 1 on response', function () { - config.setConfig({ - coppa: 1 - }); - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.programmaticx.ai/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=1' - }]); - }); - - it('should generate url with consent data', function () { - const gdprConsent = { - gdprApplies: true, - consentString: 'consent_string' - }; - const uspConsent = 'usp_string'; - const gppConsent = { - gppString: 'gpp_string', - applicableSections: [7] - } - - const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE], gdprConsent, uspConsent, gppConsent); - - expect(result).to.deep.equal([{ - 'url': 'https://sync.programmaticx.ai/api/sync/image/?cid=testcid123&gdpr=1&gdpr_consent=consent_string&us_privacy=usp_string&coppa=1&gpp=gpp_string&gpp_sid=7', - 'type': 'image' - }]); - }); - }); - - describe('interpret response', function () { - it('should return empty array when there is no response', function () { - const responses = adapter.interpretResponse(null); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no ad', function () { - const responses = adapter.interpretResponse({price: 1, ad: ''}); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no price', function () { - const responses = adapter.interpretResponse({price: null, ad: 'great ad'}); - expect(responses).to.be.empty; - }); - - it('should return an array of interpreted banner responses', function () { - const responses = adapter.interpretResponse(SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 0.8, - width: 300, - height: 250, - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 30, - ad: '', - meta: { - advertiserDomains: ['securepubads.g.doubleclick.net'] - } - }); - }); - - it('should get meta from response metaData', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - serverResponse.body.results[0].metaData = { - advertiserDomains: ['programmaticx.ai'], - agencyName: 'Agency Name', - }; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses[0].meta).to.deep.equal({ - advertiserDomains: ['programmaticx.ai'], - agencyName: 'Agency Name' - }); - }); - - it('should return an array of interpreted video responses', function () { - const responses = adapter.interpretResponse(VIDEO_SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 2, - width: 545, - height: 307, - mediaType: 'video', - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 60, - vastXml: '', - meta: { - advertiserDomains: ['programmaticx.ai'] - } - }); - }); - - it('should take default TTL', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - delete serverResponse.body.results[0].exp; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0].ttl).to.equal(300); - }); - }); - - describe('user id system', function () { - TEST_ID_SYSTEMS.forEach((idSystemProvider) => { - const id = Date.now().toString(); - const bid = utils.deepClone(BID); - - const userId = (function () { - switch (idSystemProvider) { - case 'lipb': - return {lipbid: id}; - case 'id5id': - return {uid: id}; - default: - return id; - } - })(); - - bid.userId = { - [idSystemProvider]: userId - }; - - it(`should include 'uid.${idSystemProvider}' in request params`, function () { - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data[`uid.${idSystemProvider}`]).to.equal(id); - }); - }); - // testing bid.userIdAsEids handling - it("should include user ids from bid.userIdAsEids (length=1)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - }) - it("should include user ids from bid.userIdAsEids (length=2)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - }, - { - "source": "rwdcntrl.net", - "uids": [{"id": "fakeid6f35197d5c", "atype": 1}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - expect(requests[0].data['uid.rwdcntrl.net']).to.equal("fakeid6f35197d5c"); - }) - // testing user.ext.eid handling - it("should include user ids from user.ext.eid (length=1)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - }) - it("should include user ids from user.ext.eid (length=2)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - }, - { - "source": "adserver.org", - "uids": [{"id": "fakeid495ff1"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - expect(requests[0].data['uid.adserver.org']).to.equal("fakeid495ff1"); - }) - }); - - describe('alternate param names extractors', function () { - it('should return undefined when param not supported', function () { - const cid = extractCID({'c_id': '1'}); - const pid = extractPID({'p_id': '1'}); - const subDomain = extractSubDomain({'sub_domain': 'prebid'}); - expect(cid).to.be.undefined; - expect(pid).to.be.undefined; - expect(subDomain).to.be.undefined; - }); - - it('should return value when param supported', function () { - const cid = extractCID({'cID': '1'}); - const pid = extractPID({'Pid': '2'}); - const subDomain = extractSubDomain({'subDOMAIN': 'prebid'}); - expect(cid).to.be.equal('1'); - expect(pid).to.be.equal('2'); - expect(subDomain).to.be.equal('prebid'); - }); - }); - - describe('unique deal id', function () { - before(function () { - getGlobal().bidderSettings = { - programmaticX: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - const key = 'myKey'; - let uniqueDealId; - beforeEach(() => { - uniqueDealId = getUniqueDealId(storage, key, 0); - }) - - it('should get current unique deal id', function (done) { - // waiting some time so `now` will become past - setTimeout(() => { - const current = getUniqueDealId(storage, key); - expect(current).to.be.equal(uniqueDealId); - done(); - }, 200); - }); - - it('should get new unique deal id on expiration', function (done) { - setTimeout(() => { - const current = getUniqueDealId(storage, key, 100); - expect(current).to.not.be.equal(uniqueDealId); - done(); - }, 200) - }); - }); - - describe('storage utils', function () { - before(function () { - getGlobal().bidderSettings = { - programmaticX: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - it('should get value from storage with create param', function () { - const now = Date.now(); - const clock = useFakeTimers({ - shouldAdvanceTime: true, - now - }); - setStorageItem(storage, 'myKey', 2020); - const {value, created} = getStorageItem(storage, 'myKey'); - expect(created).to.be.equal(now); - expect(value).to.be.equal(2020); - expect(typeof value).to.be.equal('number'); - expect(typeof created).to.be.equal('number'); - clock.restore(); - }); - - it('should get external stored value', function () { - const value = 'superman' - window.localStorage.setItem('myExternalKey', value); - const item = getStorageItem(storage, 'myExternalKey'); - expect(item).to.be.equal(value); - }); - - it('should parse JSON value', function () { - const data = JSON.stringify({event: 'send'}); - const {event} = tryParseJSON(data); - expect(event).to.be.equal('send'); - }); - - it('should get original value on parse fail', function () { - const value = 21; - const parsed = tryParseJSON(value); - expect(typeof parsed).to.be.equal('number'); - expect(parsed).to.be.equal(value); - }); - }); - - describe('createDomain test', function() { - it('should return correct domain', function () { - const responses = createDomain(); - expect(responses).to.be.equal('https://exchange.programmaticx.ai'); - }); - }) -}); diff --git a/test/spec/modules/programmaticaBidAdapter_spec.js b/test/spec/modules/programmaticaBidAdapter_spec.js deleted file mode 100644 index 819ad58cd..000000000 --- a/test/spec/modules/programmaticaBidAdapter_spec.js +++ /dev/null @@ -1,263 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/programmaticaBidAdapter.js'; -import { deepClone } from 'src/utils.js'; - -describe('programmaticaBidAdapterTests', function () { - const bidRequestData = { - bids: [ - { - bidId: 'testbid', - bidder: 'programmatica', - params: { - siteId: 'testsite', - placementId: 'testplacement', - }, - sizes: [[300, 250]] - } - ] - }; - const request = []; - - it('validate_pub_params', function () { - expect( - spec.isBidRequestValid({ - bidder: 'programmatica', - params: { - siteId: 'testsite', - placementId: 'testplacement', - } - }) - ).to.equal(true); - }); - - it('validate_generated_url', function () { - const request = spec.buildRequests(deepClone(bidRequestData.bids), { timeout: 1234 }); - const req_url = request[0].url; - - expect(req_url).to.equal('https://asr.programmatica.com/get'); - }); - - it('validate_response_params', function () { - const serverResponse = { - body: { - 'id': 'crid', - 'type': { - 'format': 'Image', - 'source': 'passback', - 'dspId': '', - 'dspCreativeId': '' - }, - 'content': { - 'data': 'test ad', - 'imps': null, - 'click': { - 'url': '', - 'track': null - } - }, - 'size': '300x250', - 'matching': '', - 'cpm': 10, - 'currency': 'USD' - } - }; - - const bidRequest = deepClone(bidRequestData.bids) - bidRequest[0].mediaTypes = { - banner: {} - } - - const request = spec.buildRequests(bidRequest); - const bids = spec.interpretResponse(serverResponse, request[0]); - expect(bids).to.have.lengthOf(1); - - const bid = bids[0]; - expect(bid.ad).to.equal('test ad'); - expect(bid.cpm).to.equal(10); - expect(bid.currency).to.equal('USD'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creativeId).to.equal('crid'); - expect(bid.meta.advertiserDomains).to.deep.equal(['programmatica.com']); - }); - - it('validate_response_params_imps', function () { - const serverResponse = { - body: { - 'id': 'crid', - 'type': { - 'format': 'Image', - 'source': 'passback', - 'dspId': '', - 'dspCreativeId': '' - }, - 'content': { - 'data': 'test ad', - 'imps': [ - 'testImp' - ], - 'click': { - 'url': '', - 'track': null - } - }, - 'size': '300x250', - 'matching': '', - 'cpm': 10, - 'currency': 'USD' - } - }; - - const bidRequest = deepClone(bidRequestData.bids) - bidRequest[0].mediaTypes = { - banner: {} - } - - const request = spec.buildRequests(bidRequest); - const bids = spec.interpretResponse(serverResponse, request[0]); - expect(bids).to.have.lengthOf(1); - - const bid = bids[0]; - expect(bid.ad).to.equal('test ad'); - expect(bid.cpm).to.equal(10); - expect(bid.currency).to.equal('USD'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creativeId).to.equal('crid'); - expect(bid.meta.advertiserDomains).to.deep.equal(['programmatica.com']); - }) - - it('validate_invalid_response', function () { - const serverResponse = { - body: {} - }; - - const bidRequest = deepClone(bidRequestData.bids) - bidRequest[0].mediaTypes = { - banner: {} - } - - const request = spec.buildRequests(bidRequest); - const bids = spec.interpretResponse(serverResponse, request[0]); - expect(bids).to.have.lengthOf(0); - }) - - it('video_bid', function () { - const bidRequest = deepClone(bidRequestData.bids); - bidRequest[0].mediaTypes = { - video: { - playerSize: [234, 765] - } - }; - - const request = spec.buildRequests(bidRequest, { timeout: 1234 }); - const vastXml = ''; - const serverResponse = { - body: { - 'id': 'cki2n3n6snkuulqutpf0', - 'type': { - 'format': '', - 'source': 'rtb', - 'dspId': '1' - }, - 'content': { - 'data': vastXml, - 'imps': [ - 'https://asr.dev.programmatica.com/track/imp' - ], - 'click': { - 'url': '', - 'track': null - } - }, - 'size': '', - 'matching': '', - 'cpm': 70, - 'currency': 'RUB' - } - }; - - const bids = spec.interpretResponse(serverResponse, request[0]); - expect(bids).to.have.lengthOf(1); - - const bid = bids[0]; - expect(bid.mediaType).to.equal('video'); - expect(bid.vastXml).to.equal(vastXml); - expect(bid.width).to.equal(234); - expect(bid.height).to.equal(765); - }); -}); - -describe('getUserSyncs', function() { - it('returns empty sync array', function() { - const syncOptions = {}; - - expect(spec.getUserSyncs(syncOptions)).to.deep.equal([]); - }); - - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({ - pixelEnabled: true, - }, {}, {}, '1---'); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('//sync.programmatica.com/match/sp?usp=1---&consent=') - }); - - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({ - iframeEnabled: true, - }, {}, { - gdprApplies: true, - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: { - purpose: { - consents: { - 1: true - }, - }, - } - }, ''); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('iframe') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('//sync.programmatica.com/match/sp.ifr?usp=&consent=COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw&gdpr=1') - }); - - it('Should return array of objects with proper sync config , include GDPR, no purpose', function() { - const syncData = spec.getUserSyncs({ - iframeEnabled: true, - }, {}, { - gdprApplies: true, - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: { - purpose: { - consents: { - 1: false - }, - }, - } - }, ''); - expect(syncData).is.empty; - }); - - it('Should return array of objects with proper sync config , GDPR not applies', function() { - const syncData = spec.getUserSyncs({ - iframeEnabled: true, - }, {}, { - gdprApplies: false, - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - }, ''); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('iframe') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('//sync.programmatica.com/match/sp.ifr?usp=&consent=COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw&gdpr=0') - }); -}) diff --git a/test/spec/modules/proxistoreBidAdapter_spec.js b/test/spec/modules/proxistoreBidAdapter_spec.js deleted file mode 100644 index 767ef93cf..000000000 --- a/test/spec/modules/proxistoreBidAdapter_spec.js +++ /dev/null @@ -1,167 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/proxistoreBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from '../../../src/config.js'; - -const BIDDER_CODE = 'proxistore'; -describe('ProxistoreBidAdapter', function () { - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const bidderRequest = { - bidderCode: BIDDER_CODE, - auctionId: '1025ba77-5463-4877-b0eb-14b205cb9304', - bidderRequestId: '10edf38ec1a719', - gdprConsent: { - apiVersion: 2, - gdprApplies: true, - consentString: consentString, - vendorData: { - vendor: { - consents: { - 418: true, - }, - }, - }, - }, - }; - const bid = { - sizes: [[300, 600]], - params: { - website: 'example.fr', - language: 'fr', - }, - ortb2: { - user: { ext: { data: { segments: [], contextual_categories: {} } } }, - }, - auctionId: 442133079, - bidId: 464646969, - transactionId: 511916005, - }; - describe('isBidRequestValid', function () { - it('it should be true if required params are presents and there is no info in the local storage', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('it should be false if the value in the localstorage is less than 5minutes of the actual time', function () { - const date = new Date(); - date.setMinutes(date.getMinutes() - 1); - localStorage.setItem(`PX_NoAds_${bid.params.website}`, date); - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('it should be true if the value in the localstorage is more than 5minutes of the actual time', function () { - const date = new Date(); - date.setMinutes(date.getMinutes() - 10); - localStorage.setItem(`PX_NoAds_${bid.params.website}`, date); - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - describe('buildRequests', function () { - const url = { - cookieBase: 'https://abs.proxistore.com/v3/rtb/prebid/multi', - cookieLess: - 'https://abs.cookieless-proxistore.com/v3/rtb/prebid/multi', - }; - - let request = spec.buildRequests([bid], bidderRequest); - it('should return a valid object', function () { - expect(request).to.be.an('object'); - expect(request.method).to.exist; - expect(request.url).to.exist; - expect(request.data).to.exist; - }); - it('request method should be POST', function () { - expect(request.method).to.equal('POST'); - }); - it('should have the value consentGiven to true bc we have 418 in the vendor list', function () { - const data = JSON.parse(request.data); - expect(data.gdpr.consentString).equal( - bidderRequest.gdprConsent.consentString - ); - expect(data.gdpr.applies).to.be.true; - expect(data.gdpr.consentGiven).to.be.true; - }); - it('should contain a valid url', function () { - // has gdpr consent - expect(request.url).equal(url.cookieBase); - // doens't have gdpr consent - bidderRequest.gdprConsent.vendorData = null; - - request = spec.buildRequests([bid], bidderRequest); - expect(request.url).equal(url.cookieLess); - - // api v2 - bidderRequest.gdprConsent = { - gdprApplies: true, - allowAuctionWithoutConsent: true, - consentString: consentString, - vendorData: { - vendor: { - consents: { - 418: true, - }, - }, - }, - apiVersion: 2, - }; - // has gdpr consent - request = spec.buildRequests([bid], bidderRequest); - expect(request.url).equal(url.cookieBase); - - bidderRequest.gdprConsent.vendorData.vendor = {}; - request = spec.buildRequests([bid], bidderRequest); - expect(request.url).equal(url.cookieLess); - }); - it('should have a property a length of bids equal to one if there is only one bid', function () { - const data = JSON.parse(request.data); - expect(data.hasOwnProperty('bids')).to.be.true; - expect(data.bids).to.be.an('array'); - expect(data.bids.length).equal(1); - expect(data.bids[0].hasOwnProperty('id')).to.be.true; - expect(data.bids[0].sizes).to.be.an('array'); - }); - it('should correctly set bidfloor on imp when getfloor in scope', function () { - let data = JSON.parse(request.data); - expect(data.bids[0].floor).to.be.null; - - bid.params['bidFloor'] = 1; - let req = spec.buildRequests([bid], bidderRequest); - data = JSON.parse(req.data); - expect(data.bids[0].floor).equal(1); - bid.getFloor = function () { - return { currency: 'USD', floor: 1.0 }; - }; - req = spec.buildRequests([bid], bidderRequest); - data = JSON.parse(req.data); - expect(data.bids[0].floor).to.be.null; - }); - }); - describe('interpretResponse', function () { - const emptyResponseParam = { body: [] }; - const fakeResponseParam = { - body: [ - { - ad: '', - cpm: 6.25, - creativeId: '22c3290b-8cd5-4cd6-8e8c-28a2de180ccd', - currency: 'EUR', - dealId: '2021-03_a63ec55e-b9bb-4ca4-b2c9-f456be67e656', - height: 600, - netRevenue: true, - requestId: '3543724f2a033c9', - segments: [], - ttl: 10, - vastUrl: null, - vastXml: null, - width: 300, - }, - ], - }; - - it('should always return an array', function () { - let response = spec.interpretResponse(emptyResponseParam, bid); - expect(response).to.be.an('array'); - expect(response.length).equal(0); - response = spec.interpretResponse(fakeResponseParam, bid); - expect(response).to.be.an('array'); - expect(response.length).equal(1); - }); - }); -}); diff --git a/test/spec/modules/pstudioBidAdapter_spec.js b/test/spec/modules/pstudioBidAdapter_spec.js deleted file mode 100644 index 2ec38e8dc..000000000 --- a/test/spec/modules/pstudioBidAdapter_spec.js +++ /dev/null @@ -1,514 +0,0 @@ -import { assert } from 'chai'; -import sinon from 'sinon'; -import { spec, storage } from 'modules/pstudioBidAdapter.js'; -import { deepClone } from '../../../src/utils.js'; - -describe('PStudioAdapter', function () { - let sandbox; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - - afterEach(function () { - sandbox.restore(); - }); - - const bannerBid = { - bidder: 'pstudio', - params: { - pubid: '258c2a8d-d2ad-4c31-a2a5-e63001186456', - adtagid: 'aae1aabb-6699-4b5a-9c3f-9ed034b1932c', - }, - adUnitCode: 'test-div-1', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - pos: 0, - name: 'some-name', - }, - }, - bidId: '30b31c1838de1e', - }; - - const videoBid = { - bidder: 'pstudio', - params: { - pubid: '258c2a8d-d2ad-4c31-a2a5-e63001186456', - adtagid: '34833639-f17c-40bc-9c4b-222b1b7459c7', - }, - adUnitCode: 'test-div-1', - mediaTypes: { - video: { - playerSize: [[300, 250]], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - protocols: [2, 3], - startdelay: 5, - placement: 2, - skip: 1, - skipafter: 1, - minbitrate: 10, - maxbitrate: 10, - delivery: 1, - playbackmethod: [1, 3], - api: [2], - linearity: 1, - }, - }, - bidId: '30b31c1838de1e', - }; - - const bidWithOptionalParams = deepClone(bannerBid); - bidWithOptionalParams.params['bcat'] = ['IAB17-18', 'IAB7-42']; - bidWithOptionalParams.params['badv'] = ['ford.com']; - bidWithOptionalParams.params['bapp'] = ['com.foo.mygame']; - bidWithOptionalParams.params['regs'] = { - coppa: 1, - }; - - bidWithOptionalParams.userId = { - uid2: { - id: '7505e78e-4a9b-4011-8901-0e00c3f55ea9', - }, - }; - - const emptyOrtb2BidderRequest = { ortb2: {} }; - - const baseBidderRequest = { - ortb2: { - device: { - w: 1680, - h: 342, - }, - }, - }; - - const extendedBidderRequest = deepClone(baseBidderRequest); - extendedBidderRequest.ortb2['device'] = { - dnt: 0, - ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36', - lmt: 0, - ip: '192.0.0.1', - ipv6: '2001:0000:130F:0000:0000:09C0:876A:130B', - devicetype: 2, - make: 'some_producer', - model: 'some_model', - os: 'some_os', - osv: 'some_version', - js: 1, - language: 'en', - carrier: 'WiFi', - connectiontype: 0, - ifa: 'some_ifa', - geo: { - lat: 50.4, - lon: 40.2, - country: 'some_country_code', - region: 'some_region_code', - regionfips104: 'some_fips_code', - metro: 'metro_code', - city: 'city_code', - zip: 'zip_code', - type: 2, - }, - ext: { - ifatype: 'dpid', - }, - }; - extendedBidderRequest.ortb2['site'] = { - id: 'some_id', - name: 'example', - domain: 'page.example.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'], - page: 'https://page.example.com/here.html', - ref: 'https://ref.example.com', - publisher: { - name: 'some_name', - cat: ['IAB2'], - domain: 'https://page.example.com/here.html', - }, - content: { - id: 'some_id', - episode: 22, - title: 'New episode.', - series: 'New series.', - artist: 'New artist', - genre: 'some genre', - album: 'New album', - isrc: 'AA-6Q7-20-00047', - season: 'New season', - }, - mobile: 0, - }; - extendedBidderRequest.ortb2['app'] = { - id: 'some_id', - name: 'example', - bundle: 'some_bundle', - domain: 'page.example.com', - storeurl: 'https://store.example.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'], - ver: 'some_version', - privacypolicy: 0, - paid: 0, - keywords: 'some, example, keywords', - publisher: { - name: 'some_name', - cat: ['IAB2'], - domain: 'https://page.example.com/here.html', - }, - content: { - id: 'some_id', - episode: 22, - title: 'New episode.', - series: 'New series.', - artist: 'New artist', - genre: 'some genre', - album: 'New album', - isrc: 'AA-6Q7-20-00047', - season: 'New season', - }, - }; - extendedBidderRequest.ortb2['user'] = { - yob: 1992, - gender: 'M', - }; - extendedBidderRequest.ortb2['regs'] = { - coppa: 0, - }; - - describe('isBidRequestValid', function () { - it('should return true when publisher id found', function () { - expect(spec.isBidRequestValid(bannerBid)).to.equal(true); - }); - - it('should return true for video bid', () => { - expect(spec.isBidRequestValid(videoBid)).to.equal(true); - }); - - it('should return false when publisher id not found', function () { - const localBid = deepClone(bannerBid); - delete localBid.params.pubid; - delete localBid.params.adtagid; - - expect(spec.isBidRequestValid(localBid)).to.equal(false); - }); - - it('should return false when playerSize in video not found', () => { - const localBid = deepClone(videoBid); - delete localBid.mediaTypes.video.playerSize; - - expect(spec.isBidRequestValid(localBid)).to.equal(false); - }); - - it('should return false when mimes in video not found', () => { - const localBid = deepClone(videoBid); - delete localBid.mediaTypes.video.mimes; - - expect(spec.isBidRequestValid(localBid)).to.equal(false); - }); - - it('should return false when protocols in video not found', () => { - const localBid = deepClone(videoBid); - delete localBid.mediaTypes.video.protocols; - - expect(spec.isBidRequestValid(localBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bannerRequest = spec.buildRequests([bannerBid], baseBidderRequest); - const bannerPayload = JSON.parse(bannerRequest[0].data); - const videoRequest = spec.buildRequests([videoBid], baseBidderRequest); - const videoPayload = JSON.parse(videoRequest[0].data); - - it('should properly map ids in request payload', function () { - expect(bannerPayload.id).to.equal(bannerBid.bidId); - expect(bannerPayload.adtagid).to.equal(bannerBid.params.adtagid); - }); - - it('should properly map banner mediaType in request payload', function () { - expect(bannerPayload.banner_properties).to.deep.equal({ - name: bannerBid.mediaTypes.banner.name, - sizes: bannerBid.mediaTypes.banner.sizes, - pos: bannerBid.mediaTypes.banner.pos, - }); - }); - - it('should properly map video mediaType in request payload', () => { - expect(videoPayload.video_properties).to.deep.equal({ - w: videoBid.mediaTypes.video.playerSize[0][0], - h: videoBid.mediaTypes.video.playerSize[0][1], - mimes: videoBid.mediaTypes.video.mimes, - minduration: videoBid.mediaTypes.video.minduration, - maxduration: videoBid.mediaTypes.video.maxduration, - protocols: videoBid.mediaTypes.video.protocols, - startdelay: videoBid.mediaTypes.video.startdelay, - placement: videoBid.mediaTypes.video.placement, - skip: videoBid.mediaTypes.video.skip, - skipafter: videoBid.mediaTypes.video.skipafter, - minbitrate: videoBid.mediaTypes.video.minbitrate, - maxbitrate: videoBid.mediaTypes.video.maxbitrate, - delivery: videoBid.mediaTypes.video.delivery, - playbackmethod: videoBid.mediaTypes.video.playbackmethod, - api: videoBid.mediaTypes.video.api, - linearity: videoBid.mediaTypes.video.linearity, - }); - }); - - it('should properly set required bidder params in request payload', function () { - expect(bannerPayload.pubid).to.equal(bannerBid.params.pubid); - expect(bannerPayload.adtagid).to.equal(bannerBid.params.adtagid); - }); - - it('should omit optional bidder params or first-party data from bid request if they are not provided', function () { - assert.isUndefined(bannerPayload.bcat); - assert.isUndefined(bannerPayload.badv); - assert.isUndefined(bannerPayload.bapp); - assert.isUndefined(bannerPayload.user); - assert.isUndefined(bannerPayload.device); - assert.isUndefined(bannerPayload.site); - assert.isUndefined(bannerPayload.app); - assert.isUndefined(bannerPayload.user_ids); - assert.isUndefined(bannerPayload.regs); - }); - - it('should properly set optional bidder parameters', function () { - const request = spec.buildRequests( - [bidWithOptionalParams], - baseBidderRequest - ); - const payload = JSON.parse(request[0].data); - - expect(payload.bcat).to.deep.equal(['IAB17-18', 'IAB7-42']); - expect(payload.badv).to.deep.equal(['ford.com']); - expect(payload.bapp).to.deep.equal(['com.foo.mygame']); - }); - - it('should properly set optional user_ids', function () { - const request = spec.buildRequests( - [bidWithOptionalParams], - baseBidderRequest - ); - const { - user: { uid2_token }, - } = JSON.parse(request[0].data); - const expectedUID = '7505e78e-4a9b-4011-8901-0e00c3f55ea9'; - - expect(uid2_token).to.equal(expectedUID); - }); - - it('should properly set optional user_ids when no first party data is provided', function () { - const request = spec.buildRequests( - [bidWithOptionalParams], - emptyOrtb2BidderRequest - ); - const { - user: { uid2_token }, - } = JSON.parse(request[0].data); - const expectedUID = '7505e78e-4a9b-4011-8901-0e00c3f55ea9'; - - expect(uid2_token).to.equal(expectedUID); - }); - - it('should properly handle first-party data', function () { - const request = spec.buildRequests([bannerBid], extendedBidderRequest); - const payload = JSON.parse(request[0].data); - - expect(payload.user).to.deep.equal(extendedBidderRequest.ortb2.user); - expect(payload.device).to.deep.equal(extendedBidderRequest.ortb2.device); - expect(payload.site).to.deep.equal(extendedBidderRequest.ortb2.site); - expect(payload.app).to.deep.equal(extendedBidderRequest.ortb2.app); - expect(payload.regs).to.deep.equal(extendedBidderRequest.ortb2.regs); - }); - - it('should not set first-party data if nothing is provided in ORTB2 param', function () { - const request = spec.buildRequests([bannerBid], emptyOrtb2BidderRequest); - const payload = JSON.parse(request[0].data); - - expect(payload).not.to.haveOwnProperty('user'); - expect(payload).not.to.haveOwnProperty('device'); - expect(payload).not.to.haveOwnProperty('site'); - expect(payload).not.to.haveOwnProperty('app'); - expect(payload).not.to.haveOwnProperty('regs'); - }); - - it('should set user id if proper cookie is present', function () { - const cookie = '157bc918-b961-4216-ac72-29fc6363edcb'; - sandbox.stub(storage, 'getCookie').returns(cookie); - - const request = spec.buildRequests([bannerBid], emptyOrtb2BidderRequest); - const payload = JSON.parse(request[0].data); - - expect(payload.user.id).to.equal(cookie); - }); - - it('should not set user id if proper cookie not present', function () { - const request = spec.buildRequests([bannerBid], emptyOrtb2BidderRequest); - const payload = JSON.parse(request[0].data); - - expect(payload).not.to.haveOwnProperty('user'); - }); - }); - - describe('interpretResponse', function () { - const serverResponse = { - body: { - id: '123141241231', - bids: [ - { - cpm: 1.02, - width: 300, - height: 600, - currency: 'USD', - ad: '

Hello ad

', - creative_id: 'crid12345', - net_revenue: true, - meta: { - advertiser_domains: ['https://advertiser.com'], - }, - }, - ], - }, - }; - - const serverVideoResponse = { - body: { - id: '123141241231', - bids: [ - { - vast_url: 'https://v.a/st.xml', - cpm: 5, - width: 640, - height: 480, - currency: 'USD', - creative_id: 'crid12345', - net_revenue: true, - meta: { - advertiser_domains: ['https://advertiser.com'], - }, - }, - ], - }, - }; - - const bidRequest = { - method: 'POST', - url: 'test-url', - data: JSON.stringify({ - id: '12345', - pubid: 'somepubid', - }), - }; - - it('should properly parse response from server', function () { - const expectedResponse = { - requestId: JSON.parse(bidRequest.data).id, - cpm: serverResponse.body.bids[0].cpm, - width: serverResponse.body.bids[0].width, - height: serverResponse.body.bids[0].height, - ad: serverResponse.body.bids[0].ad, - currency: serverResponse.body.bids[0].currency, - creativeId: serverResponse.body.bids[0].creative_id, - netRevenue: serverResponse.body.bids[0].net_revenue, - meta: { - advertiserDomains: - serverResponse.body.bids[0].meta.advertiser_domains, - }, - ttl: 300, - }; - const parsedResponse = spec.interpretResponse(serverResponse, bidRequest); - - expect(parsedResponse[0]).to.deep.equal(expectedResponse); - }); - - it('should properly parse video response from server', function () { - const expectedResponse = { - requestId: JSON.parse(bidRequest.data).id, - cpm: serverVideoResponse.body.bids[0].cpm, - width: serverVideoResponse.body.bids[0].width, - height: serverVideoResponse.body.bids[0].height, - currency: serverVideoResponse.body.bids[0].currency, - creativeId: serverVideoResponse.body.bids[0].creative_id, - netRevenue: serverVideoResponse.body.bids[0].net_revenue, - mediaType: 'video', - vastUrl: serverVideoResponse.body.bids[0].vast_url, - vastXml: undefined, - meta: { - advertiserDomains: - serverVideoResponse.body.bids[0].meta.advertiser_domains, - }, - ttl: 300, - }; - const parsedResponse = spec.interpretResponse( - serverVideoResponse, - bidRequest - ); - - expect(parsedResponse[0]).to.deep.equal(expectedResponse); - }); - - it('should return empty array if no bids are returned', function () { - const emptyResponse = deepClone(serverResponse); - emptyResponse.body.bids = undefined; - - const parsedResponse = spec.interpretResponse(emptyResponse, bidRequest); - - expect(parsedResponse).to.deep.equal([]); - }); - }); - - describe('getUserSyncs', function () { - it('should return sync object with correctly injected user id', function () { - sandbox.stub(storage, 'getCookie').returns('testid'); - - const result = spec.getUserSyncs({}, {}, {}, {}); - - expect(result).to.deep.equal([ - { - type: 'image', - url: 'https://match.adsrvr.org/track/cmf/generic?ttd_pid=k1on5ig&ttd_tpi=1&ttd_puid=testid&dsp=ttd', - }, - { - type: 'image', - url: 'https://dsp.myads.telkomsel.com/api/v1/pixel?uid=testid', - }, - ]); - }); - - it('should generate user id and put the same uuid it into sync object', function () { - sandbox.stub(storage, 'getCookie').returns(undefined); - - const result = spec.getUserSyncs({}, {}, {}, {}); - const url1 = result[0].url; - const url2 = result[1].url; - - const expectedUID1 = extractValueFromURL(url1, 'ttd_puid'); - const expectedUID2 = extractValueFromURL(url2, 'uid'); - - expect(expectedUID1).to.equal(expectedUID2); - - expect(result[0]).deep.equal({ - type: 'image', - url: `https://match.adsrvr.org/track/cmf/generic?ttd_pid=k1on5ig&ttd_tpi=1&ttd_puid=${expectedUID1}&dsp=ttd`, - }); - expect(result[1]).deep.equal({ - type: 'image', - url: `https://dsp.myads.telkomsel.com/api/v1/pixel?uid=${expectedUID2}`, - }); - // Helper function to extract UUID from URL - function extractValueFromURL(url, key) { - const match = url.match(new RegExp(`[?&]${key}=([^&]*)`)); - return match ? match[1] : null; - } - }); - }); -}); diff --git a/test/spec/modules/pubCircleBidAdapter_spec.js b/test/spec/modules/pubCircleBidAdapter_spec.js deleted file mode 100644 index 97953192a..000000000 --- a/test/spec/modules/pubCircleBidAdapter_spec.js +++ /dev/null @@ -1,467 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/pubCircleBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'pubcircle'; - -describe('PubCircleBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://ml.pubcircle.ai/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.pubcircle.ai/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.pubcircle.ai/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.pubcircle.ai/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/pubgeniusBidAdapter_spec.js b/test/spec/modules/pubgeniusBidAdapter_spec.js deleted file mode 100644 index 5475a58d3..000000000 --- a/test/spec/modules/pubgeniusBidAdapter_spec.js +++ /dev/null @@ -1,552 +0,0 @@ -import { expect } from 'chai'; - -import { spec } from 'modules/pubgeniusBidAdapter.js'; -import { config } from 'src/config.js'; -import { VIDEO } from 'src/mediaTypes.js'; -import { deepClone, parseQueryStringParameters } from 'src/utils.js'; -import { server } from 'test/mocks/xhr.js'; -import * as utils from 'src/utils.js'; - -const { - code, - supportedMediaTypes, - isBidRequestValid, - buildRequests, - interpretResponse, - getUserSyncs, - onTimeout, -} = spec; - -describe('pubGENIUS adapter', () => { - describe('code', () => { - it('should be pubgenius', () => { - expect(code).to.equal('pubgenius'); - }); - }); - - describe('supportedMediaTypes', () => { - it('should contain banner and video', () => { - expect(supportedMediaTypes).to.deep.equal(['banner', 'video']); - }); - }); - - describe('isBidRequestValid', () => { - let bid = null; - - beforeEach(() => { - bid = { - mediaTypes: { - banner: { - sizes: [[300, 600], [300, 250]], - }, - }, - params: { - adUnitId: 1112, - }, - }; - }); - - it('should return true with numeric adUnitId ', () => { - expect(isBidRequestValid(bid)).to.be.true; - }); - - it('should return true with string adUnitId ', () => { - bid.params.adUnitId = '1112'; - - expect(isBidRequestValid(bid)).to.be.true; - }); - - it('should return false without adUnitId', () => { - delete bid.params.adUnitId; - - expect(isBidRequestValid(bid)).to.be.false; - }); - - it('should return false with adUnitId of invalid type', () => { - bid.params.adUnitId = [1112]; - - expect(isBidRequestValid(bid)).to.be.false; - }); - - it('should return false with empty sizes', () => { - bid.mediaTypes.banner.sizes = []; - - expect(isBidRequestValid(bid)).to.be.false; - }); - - it('should return false with invalid size', () => { - bid.mediaTypes.banner.sizes = [[300, 600, 250]]; - - expect(isBidRequestValid(bid)).to.be.false; - }); - - it('should return false without banner or video', () => { - bid.mediaTypes = {}; - - expect(isBidRequestValid(bid)).to.be.false; - }); - - it('should return true with valid video media type', () => { - bid.mediaTypes = { - video: { - context: 'instream', - playerSize: [[100, 100]], - mimes: ['video/mp4'], - protocols: [1], - }, - }; - - expect(isBidRequestValid(bid)).to.be.true; - }); - - it('should return true with valid video params', () => { - bid.params.video = { - placement: 1, - w: 200, - h: 200, - mimes: ['video/mp4'], - protocols: [1], - }; - - expect(isBidRequestValid(bid)).to.be.true; - }); - - it('should return false without video protocols', () => { - bid.mediaTypes = { - video: { - context: 'instream', - playerSize: [[100, 100]], - }, - }; - bid.params.video = { - mimes: ['video/mp4'], - }; - - expect(isBidRequestValid(bid)).to.be.false; - }); - }); - - describe('buildRequests', () => { - const origBidderTimeout = config.getConfig('bidderTimeout'); - const origPageUrl = config.getConfig('pageUrl'); - const origCoppa = config.getConfig('coppa'); - - after(() => { - config.setConfig({ - bidderTimeout: origBidderTimeout, - pageUrl: origPageUrl, - coppa: origCoppa, - }); - }); - - let bidRequest = null; - let bidderRequest = null; - let expectedRequest = null; - - beforeEach(() => { - bidRequest = { - adUnitCode: 'test-div', - auctionId: 'fake-auction-id', - bidId: 'fakebidid', - bidder: 'pubgenius', - bidderRequestId: 'fakebidderrequestid', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - mediaTypes: { - banner: { - sizes: [[300, 600], [300, 250]], - }, - }, - params: { - adUnitId: 1112, - }, - transactionId: 'fake-transaction-id', - }; - - bidderRequest = { - auctionId: 'fake-auction-id', - bidderCode: 'pubgenius', - bidderRequestId: 'fakebidderrequestid', - refererInfo: {}, - timeout: 1200, - }; - - expectedRequest = { - method: 'POST', - url: 'https://auction.adpearl.io/prebid/auction', - data: { - id: 'fakebidderrequestid', - imp: [ - { - id: 'fakebidid', - banner: { - format: [{ w: 300, h: 600 }, { w: 300, h: 250 }], - topframe: 0, - }, - tagid: '1112', - }, - ], - tmax: 1200, - ext: { - pbadapter: { - version: '1.1.0', - }, - }, - }, - }; - - config.setConfig({ - bidderTimeout: 1000, - pageUrl: undefined, - coppa: undefined, - }); - }); - - it('should build basic requests correctly', () => { - expect(buildRequests([bidRequest], bidderRequest)).to.deep.equal(expectedRequest); - }); - - it('should build requests with multiple ad units', () => { - const bidRequest1 = deepClone(bidRequest); - bidRequest1.adUnitCode = 'test-div-1'; - bidRequest1.bidId = 'fakebidid1'; - bidRequest1.mediaTypes.banner.sizes = [[728, 90]]; - bidRequest1.params.adUnitId = '1111'; - - expectedRequest.data.imp.push({ - id: 'fakebidid1', - banner: { - format: [{ w: 728, h: 90 }], - topframe: 0, - }, - tagid: '1111', - }); - - expect(buildRequests([bidRequest, bidRequest1], bidderRequest)).to.deep.equal(expectedRequest); - }); - - it('should take bid floor from getFloor interface', () => { - bidRequest.getFloor = () => ({ floor: 0.5, currency: 'USD' }); - expectedRequest.data.imp[0].bidfloor = 0.5; - - expect(buildRequests([bidRequest], bidderRequest)).to.deep.equal(expectedRequest); - }); - - it('should take position in bidder params', () => { - bidRequest.params.position = 3; - expectedRequest.data.imp[0].banner.pos = 3; - - expect(buildRequests([bidRequest], bidderRequest)).to.deep.equal(expectedRequest); - }); - - it('should use page from refererInfo', () => { - bidderRequest.refererInfo.page = 'http://pageurl.org'; - expectedRequest.data.site = { page: 'http://pageurl.org' }; - - expect(buildRequests([bidRequest], bidderRequest)).to.deep.equal(expectedRequest); - }); - - it('should take gdprConsent when GDPR does not apply', () => { - bidderRequest.gdprConsent = { - gdprApplies: false, - consentString: 'fakeconsent', - }; - expectedRequest.data.regs = { - ext: { gdpr: 0 }, - }; - - expect(buildRequests([bidRequest], bidderRequest)).to.deep.equal(expectedRequest); - }); - - it('should take gdprConsent when GDPR applies', () => { - bidderRequest.gdprConsent = { - gdprApplies: true, - consentString: 'fakeconsent', - }; - expectedRequest.data.regs = { - ext: { gdpr: 1 }, - }; - expectedRequest.data.user = { - ext: { consent: 'fakeconsent' }, - }; - - expect(buildRequests([bidRequest], bidderRequest)).to.deep.equal(expectedRequest); - }); - - it('should take uspConsent', () => { - bidderRequest.uspConsent = '1---'; - expectedRequest.data.regs = { - ext: { us_privacy: '1---' }, - }; - - expect(buildRequests([bidRequest], bidderRequest)).to.deep.equal(expectedRequest); - }); - - it('should take schain', () => { - const schain = { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'indirectseller.com', - sid: '0001', - hp: 1 - } - ] - }; - bidRequest.ortb2 = bidRequest.ortb2 || {}; - bidRequest.ortb2.source = bidRequest.ortb2.source || {}; - bidRequest.ortb2.source.ext = bidRequest.ortb2.source.ext || {}; - bidRequest.ortb2.source.ext.schain = deepClone(schain); - expectedRequest.data.source = { - ext: { schain: deepClone(schain) }, - }; - - expect(buildRequests([bidRequest], bidderRequest)).to.deep.equal(expectedRequest); - }); - - it('should take coppa', () => { - config.setConfig({ coppa: true }); - expectedRequest.data.regs = { coppa: 1 }; - - expect(buildRequests([bidRequest], bidderRequest)).to.deep.equal(expectedRequest); - }); - - it('should take user IDs', () => { - const eid = { - source: 'adserver.org', - uids: [ - { - id: 'fake-user-id', - atype: 1, - ext: { rtiPartner: 'TDID' }, - }, - ], - }; - bidRequest.userIdAsEids = [deepClone(eid)]; - expectedRequest.data.user = { - ext: { - eids: [deepClone(eid)], - }, - }; - - expect(buildRequests([bidRequest], bidderRequest)).to.deep.equal(expectedRequest); - }); - - it('should not take unsupported user IDs', () => { - bidRequest.userIdAsEids = [ - { - source: 'pubcid.org', - uids: [ - { - id: 'fake-user-id', - atype: 1, - }, - ], - }, - ]; - - expect(buildRequests([bidRequest], bidderRequest)).to.deep.equal(expectedRequest); - }); - - it('should not take empty user IDs', () => { - bidRequest.userIdAsEids = []; - - expect(buildRequests([bidRequest], bidderRequest)).to.deep.equal(expectedRequest); - }); - - it('should build video imp', () => { - bidRequest.mediaTypes = { - video: { - context: 'instream', - playerSize: [[200, 100]], - mimes: ['video/mp4'], - protocols: [2, 3], - api: [1, 2], - playbackmethod: [3, 4], - maxduration: 10, - linearity: 1, - }, - }; - bidRequest.params.video = { - minduration: 5, - maxduration: 100, - skip: 1, - skipafter: 1, - startdelay: -1, - }; - - delete expectedRequest.data.imp[0].banner; - expectedRequest.data.imp[0].video = { - mimes: ['video/mp4'], - minduration: 5, - maxduration: 100, - protocols: [2, 3], - w: 200, - h: 100, - startdelay: -1, - skip: 1, - skipafter: 1, - playbackmethod: [3, 4], - api: [1, 2], - linearity: 1, - }; - - expect(buildRequests([bidRequest], bidderRequest)).to.deep.equal(expectedRequest); - }); - }); - - describe('interpretResponse', () => { - let serverResponse = null; - let expectedBidResponse = null; - - beforeEach(() => { - serverResponse = { - body: { - seatbid: [ - { - seat: 'pubgenius', - bid: [ - { - impid: 'fakebidid', - price: 0.3, - w: 300, - h: 250, - adm: 'fake_creative', - exp: 60, - crid: 'fakecreativeid', - }, - ], - }, - ], - }, - }; - expectedBidResponse = { - requestId: 'fakebidid', - cpm: 0.3, - currency: 'USD', - width: 300, - height: 250, - ad: 'fake_creative', - ttl: 60, - creativeId: 'fakecreativeid', - netRevenue: true, - }; - }); - - it('should interpret response correctly', () => { - expect(interpretResponse(serverResponse)).to.deep.equal([expectedBidResponse]); - }); - - it('should interpret response with adomain', () => { - serverResponse.body.seatbid[0].bid[0].adomain = ['fakeaddomain']; - expectedBidResponse.meta = { - advertiserDomains: ['fakeaddomain'], - }; - - expect(interpretResponse(serverResponse)).to.deep.equal([expectedBidResponse]); - }); - - it('should interpret no bids', () => { - expect(interpretResponse({ body: {} })).to.deep.equal([]); - }); - - it('should interpret video response', () => { - serverResponse.body.seatbid[0].bid[0] = { - ...serverResponse.body.seatbid[0].bid[0], - nurl: 'http://vasturl/cache?id=x', - ext: { - pbadapter: { - mediaType: 'video', - cacheKey: 'x', - }, - }, - }; - - delete expectedBidResponse.ad; - expectedBidResponse = { - ...expectedBidResponse, - vastUrl: 'http://vasturl/cache?id=x', - vastXml: 'fake_creative', - mediaType: VIDEO, - }; - - expect(interpretResponse(serverResponse)).to.deep.equal([expectedBidResponse]); - }); - }); - - describe('getUserSyncs', () => { - let syncOptions = null; - let expectedSync = null; - - beforeEach(() => { - syncOptions = { - iframeEnabled: true, - pixelEnabled: true, - }; - expectedSync = { - type: 'iframe', - url: 'https://auction.adpearl.io/usersync/pixels.html?', - }; - }); - - it('should return iframe pixels', () => { - expect(getUserSyncs(syncOptions)).to.deep.equal([expectedSync]); - }); - - it('should return empty when iframe is not enabled', () => { - syncOptions.iframeEnabled = false; - - expect(getUserSyncs(syncOptions)).to.deep.equal([]); - }); - - it('should return sync when GDPR applies', () => { - const gdprConsent = { - gdprApplies: true, - consentString: 'fake-gdpr-consent', - }; - expectedSync.url = expectedSync.url + parseQueryStringParameters({ - gdpr: 1, - consent: 'fake-gdpr-consent', - }); - - expect(getUserSyncs(syncOptions, [], gdprConsent)).to.deep.equal([expectedSync]); - }); - - it('should return sync when GDPR does not apply', () => { - const gdprConsent = { - gdprApplies: false, - }; - expectedSync.url = expectedSync.url + parseQueryStringParameters({ gdpr: 0 }); - - expect(getUserSyncs(syncOptions, [], gdprConsent)).to.deep.equal([expectedSync]); - }); - - it('should return sync with US privacy', () => { - expectedSync.url = expectedSync.url + parseQueryStringParameters({ us_privacy: '1---' }); - - expect(getUserSyncs(syncOptions, [], undefined, '1---')).to.deep.equal([expectedSync]); - }); - }); - - describe('onTimeout', () => { - it('should send timeout data', () => { - const timeoutData = { - bidder: 'pubgenius', - bidId: 'fakebidid', - params: { - adUnitId: 1234, - }, - adUnitCode: 'fake-ad-unit-code', - timeout: 3000, - auctionId: 'fake-auction-id', - }; - onTimeout(timeoutData); - - expect(server.requests[0].method).to.equal('POST'); - expect(server.requests[0].url).to.equal('https://auction.adpearl.io/prebid/events?type=timeout'); - expect(JSON.parse(server.requests[0].requestBody)).to.deep.equal(timeoutData); - }); - }); -}); diff --git a/test/spec/modules/publirBidAdapter_spec.js b/test/spec/modules/publirBidAdapter_spec.js deleted file mode 100644 index 0265fbb40..000000000 --- a/test/spec/modules/publirBidAdapter_spec.js +++ /dev/null @@ -1,493 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/publirBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import { BANNER } from '../../../src/mediaTypes.js'; -import * as utils from 'src/utils.js'; - -const ENDPOINT = 'https://prebid.publir.com/publirPrebidEndPoint'; -const RTB_DOMAIN_TEST = 'prebid.publir.com'; -const TTL = 360; - -describe('publirAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('bid adapter', function () { - it('should have aliases', function () { - expect(spec.aliases).to.be.an('array').that.is.not.empty; - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [['640', '480']], - 'params': { - 'pubId': 'jdye8weeyirk00000001' - } - }; - - it('should return true when required params are passed', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when pubId is missing', function () { - const bid = { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [['640', '480']], - 'params': {} - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when required params are not found', function () { - const newBid = Object.assign({}, bid); - delete newBid.params; - newBid.params = { - 'pubId': null - }; - expect(spec.isBidRequestValid(newBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'params': { - 'pubId': 'jdye8weeyirk00000001' - }, - 'bidId': '299ffc8cca0b87', - 'loop': 1, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'banner': { - } - }, - 'ad': '""' - } - ]; - - const bidderRequest = { - bidderCode: 'publir', - } - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('sends bid request to rtbDomain ENDPOINT via POST', function () { - bidRequests[0].params.rtbDomain = RTB_DOMAIN_TEST; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('should send the correct bid Id', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].bidId).to.equal('299ffc8cca0b87'); - }); - - it('should respect syncEnabled option', function() { - config.setConfig({ - userSync: { - syncEnabled: false, - filterSettings: { - all: { - bidders: '*', - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('cs_method'); - }); - - it('should respect "iframe" filter settings', function () { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - iframe: { - bidders: [spec.code], - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'iframe'); - }); - - it('should respect "all" filter settings', function () { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - all: { - bidders: [spec.code], - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'iframe'); - }); - - it('should send the pixel user sync param if userSync is enabled and no "iframe" or "all" configs are present', function () { - config.resetConfig(); - config.setConfig({ - userSync: { - syncEnabled: true, - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'pixel'); - }); - - it('should respect total exclusion', function() { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - image: { - bidders: [spec.code], - filter: 'exclude' - }, - iframe: { - bidders: [spec.code], - filter: 'exclude' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('cs_method'); - }); - - it('should have us_privacy param if usPrivacy is available in the bidRequest', function () { - const bidderRequestWithUSP = Object.assign({uspConsent: '1YNN'}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithUSP); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('us_privacy', '1YNN'); - }); - - it('should have an empty us_privacy param if usPrivacy is missing in the bidRequest', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('us_privacy'); - }); - - it('should not send the gdpr param if gdprApplies is false in the bidRequest', function () { - const bidderRequestWithGDPR = Object.assign({gdprConsent: {gdprApplies: false}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('gdpr'); - expect(request.data.params).to.not.have.property('gdpr_consent'); - }); - - it('should send the gdpr param if gdprApplies is true in the bidRequest', function () { - const bidderRequestWithGDPR = Object.assign({gdprConsent: {gdprApplies: true, consentString: 'test-consent-string'}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('gdpr', true); - expect(request.data.params).to.have.property('gdpr_consent', 'test-consent-string'); - }); - - it('should have schain param if it is available in the bidRequest', () => { - bidderRequest.ortb2 = { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [{ asi: 'indirectseller.com', sid: '00001', hp: 1 }], - } - } - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('schain', '1.0,1!indirectseller.com,00001,1,,,'); - }); - - it('should set flooPrice to getFloor.floor value if it is greater than params.floorPrice', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.getFloor = () => { - return { - currency: 'USD', - floor: 3.32 - } - } - bid.params.floorPrice = 0.64; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0]).to.be.an('object'); - expect(request.data.bids[0]).to.have.property('floorPrice', 3.32); - }); - - it('should set floorPrice to params.floorPrice value if it is greater than getFloor.floor', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.getFloor = () => { - return { - currency: 'USD', - floor: 0.8 - } - } - bid.params.floorPrice = 1.5; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0]).to.be.an('object'); - expect(request.data.bids[0]).to.have.property('floorPrice', 1.5); - }); - - it('should check sua param in bid request', function() { - const sua = { - 'platform': { - 'brand': 'macOS', - 'version': ['12', '4', '0'] - }, - 'browsers': [ - { - 'brand': 'Chromium', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Google Chrome', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Not;A=Brand', - 'version': [ '99', '0', '0', '0' ] - } - ], - 'mobile': 0, - 'model': '', - 'bitness': '64', - 'architecture': 'x86' - } - const bid = utils.deepClone(bidRequests[0]); - bid.ortb2 = { - 'device': { - 'sua': { - 'platform': { - 'brand': 'macOS', - 'version': [ '12', '4', '0' ] - }, - 'browsers': [ - { - 'brand': 'Chromium', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Google Chrome', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Not;A=Brand', - 'version': [ '99', '0', '0', '0' ] - } - ], - 'mobile': 0, - 'model': '', - 'bitness': '64', - 'architecture': 'x86' - } - } - } - const requestWithSua = spec.buildRequests([bid], bidderRequest); - const data = requestWithSua.data; - expect(data.bids[0].sua).to.exist; - expect(data.bids[0].sua).to.deep.equal(sua); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].sua).to.not.exist; - }); - - describe('COPPA Param', function() { - it('should set coppa equal 0 in bid request if coppa is set to false', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].coppa).to.be.equal(0); - }); - - it('should set coppa equal 1 in bid request if coppa is set to true', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.ortb2 = { - 'regs': { - 'coppa': true, - } - }; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0].coppa).to.be.equal(1); - }); - }); - }); - - describe('interpretResponse', function () { - const response = { - params: { - currency: 'USD', - netRevenue: true, - }, - bids: [ - { - cpm: 12.5, - ad: '""', - width: 300, - height: 250, - requestId: '21e12606d47ba7', - adomain: ['abc.com'], - mediaType: BANNER, - campId: '65902db45721d690ee0bc8c3' - }] - }; - - const expectedBannerResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 300, - height: 250, - ttl: TTL, - creativeId: '639153ddd0s443', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: BANNER, - meta: { - mediaType: BANNER, - ad_key: '9b5e00f2-8831-4efa-a933-c4f68710ffc0' - }, - ad: '""', - campId: '65902db45721d690ee0bc8c3', - bidder: 'publir' - }; - - it('should get correct bid response', function () { - const result = spec.interpretResponse({ body: response }); - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedBannerResponse)); - }); - }) - - describe('getUserSyncs', function() { - const imageSyncResponse = { - body: { - params: { - userSyncPixels: [ - 'https://image-sync-url.test/1', - 'https://image-sync-url.test/2', - 'https://image-sync-url.test/3' - ] - } - } - }; - - const iframeSyncResponse = { - body: { - params: { - userSyncURL: 'https://iframe-sync-url.test' - } - } - }; - - it('should register all img urls from the response', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true }, [imageSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'image', - url: 'https://image-sync-url.test/1' - }, - { - type: 'image', - url: 'https://image-sync-url.test/2' - }, - { - type: 'image', - url: 'https://image-sync-url.test/3' - } - ]); - }); - - it('should register the iframe url from the response', function() { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [iframeSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://iframe-sync-url.test' - } - ]); - }); - - it('should register both image and iframe urls from the responses', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, [iframeSyncResponse, imageSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://iframe-sync-url.test' - }, - { - type: 'image', - url: 'https://image-sync-url.test/1' - }, - { - type: 'image', - url: 'https://image-sync-url.test/2' - }, - { - type: 'image', - url: 'https://image-sync-url.test/3' - } - ]); - }); - - it('should handle an empty response', function() { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, []); - expect(syncs).to.deep.equal([]); - }); - - it('should handle when user syncs are disabled', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: false }, [imageSyncResponse]); - expect(syncs).to.deep.equal([]); - }); - }) - - describe('onBidWon', function() { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - - it('Should trigger pixel if bid nurl', function() { - const bid = { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [['640', '480']], - 'nurl': 'http://example.com/win/1234', - 'params': { - 'pubId': 'jdye8weeyirk00000001' - } - }; - - spec.onBidWon(bid); - expect(utils.triggerPixel.callCount).to.equal(1) - }) - }) -}); diff --git a/test/spec/modules/pubmaticAnalyticsAdapter_spec.js b/test/spec/modules/pubmaticAnalyticsAdapter_spec.js deleted file mode 100755 index b890a9d57..000000000 --- a/test/spec/modules/pubmaticAnalyticsAdapter_spec.js +++ /dev/null @@ -1,1569 +0,0 @@ -import pubmaticAnalyticsAdapter, { getMetadata } from 'modules/pubmaticAnalyticsAdapter.js'; -import adapterManager from 'src/adapterManager.js'; -import { EVENTS, REJECTION_REASON } from 'src/constants.js'; -import { config } from 'src/config.js'; -import { setConfig } from 'modules/currency.js'; -import { server } from '../../mocks/xhr.js'; -import { getGlobal } from 'src/prebidGlobal.js'; -import 'src/prebid.js'; - -const events = require('src/events'); -const utils = require('src/utils'); - -const DEFAULT_USER_AGENT = window.navigator.userAgent; -const MOBILE_USER_AGENT = 'Mozilla/5.0 (iPhone; CPU iPhone OS 13_3_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.0.5 Mobile/15E148 Safari/604.1'; -const setUADefault = () => { window.navigator.__defineGetter__('userAgent', function () { return DEFAULT_USER_AGENT }) }; -const setUAMobile = () => { window.navigator.__defineGetter__('userAgent', function () { return MOBILE_USER_AGENT }) }; -const setUANull = () => { window.navigator.__defineGetter__('userAgent', function () { return null }) }; - -const { - AUCTION_INIT, - AUCTION_END, - BID_REQUESTED, - BID_RESPONSE, - BID_REJECTED, - BIDDER_DONE, - BID_WON, - BID_TIMEOUT, - SET_TARGETING -} = EVENTS; - -const DISPLAY_MANAGER = 'Prebid.js'; - -const BID = { - 'bidder': 'pubmatic', - 'width': 640, - 'height': 480, - 'mediaType': 'video', - 'statusMessage': 'Bid available', - 'bidId': '2ecff0db240757', - 'partnerImpId': 'partnerImpressionID-1', - 'adId': 'fake_ad_id', - 'source': 's2s', - 'requestId': '2ecff0db240757', - 'currency': 'USD', - 'creativeId': '3571560', - 'cpm': 1.22752, - 'originalCpm': 1.22752, - 'originalCurrency': 'USD', - 'ttl': 300, - 'netRevenue': false, - 'ad': '', - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', - 'responseTimestamp': 1519149629415, - 'requestTimestamp': 1519149628471, - 'adUnitCode': '/19968336/header-bid-tag-0', - 'timeToRespond': 944, - 'pbLg': '1.00', - 'pbMg': '1.20', - 'pbHg': '1.22', - 'pbAg': '1.20', - 'pbDg': '1.22', - 'pbCg': '', - 'size': '640x480', - 'adserverTargeting': { - 'hb_bidder': 'pubmatic', - 'hb_adid': '2ecff0db240757', - 'hb_pb': 1.20, - 'hb_size': '640x480', - 'hb_source': 'server' - }, - 'floorData': { - 'cpmAfterAdjustments': 6.3, - 'enforcements': { 'enforceJS': true, 'enforcePBS': false, 'floorDeals': false, 'bidAdjustment': true }, - 'floorCurrency': 'USD', - 'floorRule': 'banner', - 'floorRuleValue': 1.1, - 'floorValue': 1.1 - }, - getStatusCode() { - return 1; - } -}; - -const BID2 = Object.assign({}, BID, { - adUnitCode: '/19968336/header-bid-tag-1', - bidId: '3bd4ebb1c900e2', - partnerImpId: 'partnerImpressionID-2', - adId: 'fake_ad_id_2', - requestId: '3bd4ebb1c900e2', - width: 728, - height: 90, - mediaType: 'banner', - cpm: 1.52, - originalCpm: 1.52, - dealId: 'the-deal-id', - dealChannel: 'PMP', - mi: 'matched-impression', - seatBidId: 'aaaa-bbbb-cccc-dddd', - adserverTargeting: { - 'hb_bidder': 'pubmatic', - 'hb_adid': '3bd4ebb1c900e2', - 'hb_pb': 1.50, - 'hb_size': '728x90', - 'hb_source': 'server' - }, - meta: { - advertiserDomains: ['example.com'] - } -}); -const BID3 = Object.assign({}, BID2, { - rejectionReason: REJECTION_REASON.FLOOR_NOT_MET -}) -const MOCK = { - SET_TARGETING: { - [BID.adUnitCode]: BID.adserverTargeting, - [BID2.adUnitCode]: BID2.adserverTargeting - }, - AUCTION_INIT: { - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', - 'timestamp': 1519767010567, - 'auctionStatus': 'inProgress', - 'adUnits': [{ - 'code': '/19968336/header-bid-tag-1', - 'sizes': [[640, 480]], - 'bids': [{ - 'bidder': 'pubmatic', - 'params': { - 'publisherId': '1001' - } - }], - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014' - } - ], - 'adUnitCodes': ['/19968336/header-bid-tag-1'], - 'bidderRequests': [{ - 'bidderCode': 'pubmatic', - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', - 'bidderRequestId': '1be65d7958826a', - 'bids': [{ - 'bidder': 'pubmatic', - 'params': { - 'publisherId': '1001', - 'kgpv': 'this-is-a-kgpv' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[640, 480]] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-1', - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'sizes': [[640, 480]], - 'bidId': '2ecff0db240757', - 'bidderRequestId': '1be65d7958826a', - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', - 'src': 'client', - 'bidRequestsCount': 1 - } - ], - 'timeout': 3000, - 'refererInfo': { - 'topmostLocation': 'http://www.test.com/page.html', 'reachedTop': true, 'numIframes': 0, 'stack': ['http://www.test.com/page.html'] - } - } - ], - 'bidsReceived': [], - 'winningBids': [], - 'timeout': 3000 - }, - BID_REQUESTED: { - 'bidder': 'pubmatic', - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', - 'bidderRequestId': '1be65d7958826a', - 'bids': [ - { - 'bidder': 'pubmatic', - 'adapterCode': 'pubmatic', - 'bidderCode': 'pubmatic', - 'params': { - 'publisherId': '1001', - 'video': { - 'minduration': 30, - 'skippable': true - } - }, - 'mediaType': 'video', - 'adUnitCode': '/19968336/header-bid-tag-0', - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'sizes': [[640, 480]], - 'bidId': '2ecff0db240757', - 'bidderRequestId': '1be65d7958826a', - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa' - }, - { - 'bidder': 'pubmatic', - 'adapterCode': 'pubmatic', - 'bidderCode': 'pubmatic', - 'params': { - 'publisherId': '1001', - 'kgpv': 'this-is-a-kgpv' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[1000, 300], [970, 250], [728, 90]] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-1', - 'transactionId': 'c116413c-9e3f-401a-bee1-d56aec29a1d4', - 'sizes': [[1000, 300], [970, 250], [728, 90]], - 'bidId': '3bd4ebb1c900e2', - 'seatBidId': 'aaaa-bbbb-cccc-dddd', - 'bidderRequestId': '1be65d7958826a', - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', - 'floorData': { - 'fetchStatus': 'success', - 'floorMin': undefined, - 'floorProvider': 'pubmatic', - 'location': 'fetch', - 'modelTimestamp': undefined, - 'modelVersion': 'floorModelTest', - 'modelWeight': undefined, - 'skipRate': 0, - 'skipped': false - } - } - ], - 'auctionStart': 1519149536560, - 'timeout': 5000, - 'start': 1519149562216, - 'refererInfo': { - 'topmostLocation': 'http://www.test.com/page.html', 'reachedTop': true, 'numIframes': 0, 'stack': ['http://www.test.com/page.html'] - }, - 'gdprConsent': { - 'consentString': 'here-goes-gdpr-consent-string', - 'gdprApplies': true - } - }, - BID_RESPONSE: [ - BID, - BID2 - ], - REJECTED_BID: [ - BID3 - ], - AUCTION_END: { - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa' - }, - BID_WON: [ - Object.assign({}, BID, { - 'status': 'rendered' - }), - Object.assign({}, BID2, { - 'status': 'rendered' - }) - ], - BIDDER_DONE: { - 'bidderCode': 'pubmatic', - 'bids': [ - BID, - Object.assign({}, BID2, { - 'serverResponseTimeMs': 42, - }) - ] - }, - BID_TIMEOUT: [ - { - 'bidId': '3bd4ebb1c900e2', - 'bidder': 'pubmatic', - 'adUnitCode': '/19968336/header-bid-tag-1', - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa' - } - ] -}; - -function getLoggerJsonFromRequest(requestBody) { - return JSON.parse(decodeURIComponent(requestBody)); -} - -describe('pubmatic analytics adapter', function () { - let sandbox; - let requests; - let oldScreen; - let clock; - - beforeEach(function () { - setUADefault(); - sandbox = sinon.createSandbox(); - - requests = server.requests; - - sandbox.stub(events, 'getEvents').returns([]); - - clock = sandbox.useFakeTimers(1519767013781); - - config.setConfig({ - s2sConfig: { - timeout: 1000, - accountId: 10000, - bidders: ['pubmatic'] - } - }) - }); - - afterEach(function () { - sandbox.restore(); - config.resetConfig(); - clock.runAll(); - clock.restore(); - }); - - it('should require publisherId', function () { - sandbox.stub(utils, 'logError'); - pubmaticAnalyticsAdapter.enableAnalytics({ - options: {} - }); - expect(utils.logError.called).to.equal(true); - }); - - describe('OW S2S', function () { - this.beforeEach(function () { - pubmaticAnalyticsAdapter.enableAnalytics({ - options: { - publisherId: 9999, - profileId: 1111, - profileVersionId: 20 - } - }); - config.setConfig({ - s2sConfig: { - accountId: '1234', - bidders: ['pubmatic'], - defaultVendor: 'openwrap', - timeout: 500 - } - }); - }); - - this.afterEach(function () { - pubmaticAnalyticsAdapter.disableAnalytics(); - }); - - it('Pubmatic Won: No tracker fired', function () { - this.timeout(5000) - - sandbox.stub(getGlobal(), 'getHighestCpmBids').callsFake(() => { - return [MOCK.BID_RESPONSE[0], MOCK.BID_RESPONSE[1]] - }); - - config.setConfig({ - testGroupId: 15 - }); - - if (getGlobal().getUserIds !== 'function') { - getGlobal().getUserIds = function () { return {}; }; - } - - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(1); // only logger is fired - const request = requests[0]; - expect(request.url).to.equal('https://t.pubmatic.com/wl?v=1&psrc=web'); - const data = getLoggerJsonFromRequest(request.requestBody); - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.rd.pubid).to.equal('9999'); - expect(data.rd.pid).to.equal('1111'); - expect(data.rd.pdvid).to.equal('20'); - }); - - it('Non-pubmatic won: logger, tracker fired', function () { - const APPNEXUS_BID = Object.assign({}, BID, { - 'bidder': 'appnexus', - 'adserverTargeting': { - 'hb_bidder': 'appnexus', - 'hb_adid': '2ecff0db240757', - 'hb_pb': 1.20, - 'hb_size': '640x480', - 'hb_source': 'server' - } - }); - - const MOCK_AUCTION_INIT_APPNEXUS = { - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', - 'timestamp': 1519767010567, - 'auctionStatus': 'inProgress', - 'adUnits': [{ - 'code': '/19968336/header-bid-tag-1', - 'sizes': [[640, 480]], - 'bids': [{ - 'bidder': 'appnexus', - 'params': { - 'publisherId': '1001' - } - }], - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014' - } - ], - 'adUnitCodes': ['/19968336/header-bid-tag-1'], - 'bidderRequests': [{ - 'bidderCode': 'appnexus', - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', - 'bidderRequestId': '1be65d7958826a', - 'bids': [{ - 'bidder': 'appnexus', - 'params': { - 'publisherId': '1001', - 'kgpv': 'this-is-a-kgpv' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[640, 480]] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-1', - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'sizes': [[640, 480]], - 'bidId': '2ecff0db240757', - 'bidderRequestId': '1be65d7958826a', - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', - 'src': 'client', - 'bidRequestsCount': 1 - } - ], - 'timeout': 3000, - 'refererInfo': { - 'topmostLocation': 'http://www.test.com/page.html', 'reachedTop': true, 'numIframes': 0, 'stack': ['http://www.test.com/page.html'] - } - } - ], - 'bidsReceived': [], - 'winningBids': [], - 'timeout': 3000 - }; - - const MOCK_BID_REQUESTED_APPNEXUS = { - 'bidder': 'appnexus', - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa', - 'bidderRequestId': '1be65d7958826a', - 'bids': [ - { - 'bidder': 'appnexus', - 'adapterCode': 'appnexus', - 'bidderCode': 'appnexus', - 'params': { - 'publisherId': '1001', - 'video': { - 'minduration': 30, - 'skippable': true - } - }, - 'mediaType': 'video', - 'adUnitCode': '/19968336/header-bid-tag-0', - 'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014', - 'sizes': [[640, 480]], - 'bidId': '2ecff0db240757', - 'bidderRequestId': '1be65d7958826a', - 'auctionId': '25c6d7f5-699a-4bfc-87c9-996f915341fa' - } - ], - 'auctionStart': 1519149536560, - 'timeout': 5000, - 'start': 1519149562216, - 'refererInfo': { - 'topmostLocation': 'http://www.test.com/page.html', 'reachedTop': true, 'numIframes': 0, 'stack': ['http://www.test.com/page.html'] - }, - 'gdprConsent': { - 'consentString': 'here-goes-gdpr-consent-string', - 'gdprApplies': true - } - }; - - this.timeout(5000) - - sandbox.stub(getGlobal(), 'getHighestCpmBids').callsFake((key) => { - return [APPNEXUS_BID] - }); - - events.emit(AUCTION_INIT, MOCK_AUCTION_INIT_APPNEXUS); - events.emit(BID_REQUESTED, MOCK_BID_REQUESTED_APPNEXUS); - events.emit(BID_RESPONSE, APPNEXUS_BID); - events.emit(BIDDER_DONE, { - 'bidderCode': 'appnexus', - 'bids': [ - APPNEXUS_BID, - Object.assign({}, APPNEXUS_BID, { - 'serverResponseTimeMs': 42, - }) - ] - }); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, { - [APPNEXUS_BID.adUnitCode]: APPNEXUS_BID.adserverTargeting, - }); - events.emit(BID_WON, Object.assign({}, APPNEXUS_BID, { - 'status': 'rendered' - })); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(2); // logger as well as tracker is fired - const request = requests[1]; // logger is executed late, trackers execute first - expect(request.url).to.equal('https://t.pubmatic.com/wl?v=1&psrc=web'); - const data = getLoggerJsonFromRequest(request.requestBody); - - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.rd.pubid).to.equal('9999'); - expect(data.rd.pid).to.equal('1111'); - expect(data.rd.pdvid).to.equal('20'); - - expect(data.sd).to.be.an('object'); - expect(Object.keys(data.sd).length).to.equal(1); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].adapterCode).to.equal('appnexus'); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidderCode).to.equal('appnexus'); - - const firstTracker = requests[0].url; - expect(firstTracker.split('?')[0]).to.equal('https://t.pubmatic.com/wt'); - firstTracker.split('?')[1].split('&').map(e => e.split('=')).forEach(e => data[e[0]] = e[1]); - expect(data.rd.pubid).to.equal('9999'); - expect(decodeURIComponent(data.rd.purl)).to.equal('http://www.test.com/page.html'); - }) - }); - - describe('when handling events', function () { - beforeEach(function () { - pubmaticAnalyticsAdapter.enableAnalytics({ - options: { - publisherId: 9999, - profileId: 1111, - profileVersionId: 20 - } - }); - }); - - afterEach(function () { - pubmaticAnalyticsAdapter.disableAnalytics(); - }); - - it('Logger: best case + win tracker', function () { - this.timeout(5000) - - const mockUserIds = { - 'pubmaticId': 'test-pubmaticId' - }; - - const mockUserSync = { - userIds: [ - { - name: 'pubmaticId', - storage: { name: 'pubmaticId', type: 'cookie&html5' } - } - ] - }; - - sandbox.stub(getGlobal(), 'getUserIds').callsFake(() => { - return mockUserIds; - }); - - sandbox.stub(getGlobal(), 'getConfig').callsFake((key) => { - if (key === 'userSync') return mockUserSync; - return null; - }); - - sandbox.stub(getGlobal(), 'getHighestCpmBids').callsFake((key) => { - return [MOCK.BID_RESPONSE[0], MOCK.BID_RESPONSE[1]] - }); - - config.setConfig({ - testGroupId: 15 - }); - - var mockAuctionEnd = { - "auctionId": MOCK.BID_REQUESTED.auctionId, - "bidderRequests": [ - { - "bidderCode": "pubmatic", - "auctionId": MOCK.BID_REQUESTED.auctionId, - "bidderRequestId": MOCK.BID_REQUESTED.bidderRequestId, - "bids": [ - { - "bidder": "pubmatic", - "auctionId": MOCK.BID_REQUESTED.auctionId, - "adUnitCode": "div2", - "transactionId": "bac39250-1006-42c2-b48a-876203505f95", - "adUnitId": "a36be277-84ce-42aa-b840-e95dbd104a3f", - "sizes": [ - [ - 728, - 90 - ] - ], - "bidId": "9cfd58f75514bc8", - "bidderRequestId": "857a9c3758c5cc8", - "timeout": 3000 - } - ], - "auctionStart": 1753342540904, - "timeout": 3000, - "ortb2": { - "source": {}, - "user": { - "ext": { - "ctr": "US" - } - } - }, - "start": 1753342540938 - } - ] - } - - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, mockAuctionEnd); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - events.emit(BID_WON, MOCK.BID_WON[1]); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(3); // 1 logger and 2 win-tracker - const request = requests[2]; // logger is executed late, trackers execute first - expect(request.url).to.equal('https://t.pubmatic.com/wl?v=1&psrc=web'); - const data = getLoggerJsonFromRequest(request.requestBody); - - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.rd.pubid).to.equal('9999'); - expect(data.rd.pid).to.equal('1111'); - expect(data.rd.pdvid).to.equal('20'); - expect(data.rd.iid).to.equal('25c6d7f5-699a-4bfc-87c9-996f915341fa'); - expect(data.rd.to).to.equal(3000); - expect(data.rd.purl).to.equal('http://www.test.com/page.html'); - expect(data.rd.tst).to.equal(1519767016); - expect(data.rd.tgid).to.equal(15); - expect(data.fd.bdv.lip).to.deep.equal(['pubmaticId']); - expect(data.rd.s2sls).to.deep.equal(['pubmatic']); - expect(data.rd.ctr).to.equal('US'); - - // floor data in featureList - expect(data.fd.flr.modelVersion).to.equal('floorModelTest'); - expect(data.fd.flr).to.have.property('enforcements'); - expect(data.fd.flr.enforcements).to.deep.equal({ - enforceJS: true, - enforcePBS: false, - floorDeals: false, - bidAdjustment: true - }); - expect(data.fd.flr.fetchStatus).to.equal('success'); - expect(data.fd.flr.floorProvider).to.equal('pubmatic'); - expect(data.fd.flr.location).to.equal('fetch'); - expect(data.fd.flr.skipRate).to.equal(0); - expect(data.fd.flr.skipped).to.equal(false); - - expect(data.sd).to.be.an('object'); - expect(Object.keys(data.sd).length).to.equal(2); - - // tracker slot1 - const firstTracker = requests[0]; - expect(firstTracker.url).to.equal('https://t.pubmatic.com/wt?v=1&psrc=web'); - const trackerData = getLoggerJsonFromRequest(firstTracker.requestBody); - expect(trackerData).to.have.property('sd'); - expect(trackerData).to.have.property('fd'); - expect(trackerData).to.have.property('rd'); - expect(trackerData.rd.pubid).to.equal('9999'); - expect(trackerData.rd.pid).to.equal('1111'); - expect(trackerData.rd.pdvid).to.equal('20'); - expect(trackerData.rd.purl).to.equal('http://www.test.com/page.html'); - expect(trackerData.rd.ctr).to.equal('US'); - }); - - it('Logger: log floor fields when prebids floor shows setConfig in location property', function () { - const BID_REQUESTED_COPY = utils.deepClone(MOCK.BID_REQUESTED); - BID_REQUESTED_COPY['bids'][1]['floorData']['location'] = 'fetch'; - - this.timeout(5000) - - sandbox.stub(getGlobal(), 'getHighestCpmBids').callsFake((key) => { - return [MOCK.BID_RESPONSE[0], MOCK.BID_RESPONSE[1]] - }); - - config.setConfig({ - testGroupId: 15 - }); - - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, BID_REQUESTED_COPY); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - events.emit(BID_WON, MOCK.BID_WON[1]); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(3); // 1 logger and 2 win-tracker - const request = requests[2]; // logger is executed late, trackers execute first - expect(request.url).to.equal('https://t.pubmatic.com/wl?v=1&psrc=web'); - - const data = getLoggerJsonFromRequest(request.requestBody); - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.rd.pubid).to.equal('9999'); - // floor data in featureList - expect(data.fd.flr.modelVersion).to.equal('floorModelTest'); - expect(data.fd.flr).to.have.property('enforcements'); - expect(data.fd.flr.enforcements).to.deep.equal({ - enforceJS: true, - enforcePBS: false, - floorDeals: false, - bidAdjustment: true - }); - expect(data.fd.flr.fetchStatus).to.equal('success'); - expect(data.fd.flr.floorProvider).to.equal('pubmatic'); - expect(data.fd.flr.location).to.equal('fetch'); - expect(data.fd.flr.skipRate).to.equal(0); - expect(data.fd.flr.skipped).to.equal(false); - }); - - // done - it('bidCpmAdjustment: USD: Logger: best case + win tracker', function () { - const bidCopy = utils.deepClone(BID); - bidCopy.cpm = bidCopy.originalCpm * 2; // bidCpmAdjustment => bidCpm * 2 - this.timeout(5000) - - sandbox.stub(getGlobal(), 'getHighestCpmBids').callsFake((key) => { - return [bidCopy, MOCK.BID_RESPONSE[1]] - }); - - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, bidCopy); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]); - events.emit(BID_RESPONSE, bidCopy); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - events.emit(BID_WON, MOCK.BID_WON[1]); - - clock.tick(3000 + 2000); - expect(requests.length).to.equal(3); // 1 logger and 2 win-tracker - const request = requests[2]; // logger is executed late, trackers execute first - expect(request.url).to.equal('https://t.pubmatic.com/wl?v=1&psrc=web'); - let data = getLoggerJsonFromRequest(request.requestBody); - - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.rd.pubid).to.equal('9999'); - expect(data.rd.pid).to.equal('1111'); - expect(data.rd.tgid).to.equal(0); - // floor data in featureList - expect(data.fd.flr.modelVersion).to.equal('floorModelTest'); - expect(data.fd.flr).to.have.property('enforcements'); - expect(data.fd.flr.enforcements).to.deep.equal({ - enforceJS: true, - enforcePBS: false, - floorDeals: false, - bidAdjustment: true - }); - expect(data.fd.flr.fetchStatus).to.equal('success'); - expect(data.fd.flr.floorProvider).to.equal('pubmatic'); - expect(data.fd.flr.location).to.equal('fetch'); - expect(data.fd.flr.skipRate).to.equal(0); - expect(data.fd.flr.skipped).to.equal(false); - - expect(data.sd).to.be.an('object'); - expect(Object.keys(data.sd).length).to.equal(2); - - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.bidGrossCpmUSD).to.equal(1.23); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.bidPriceUSD).to.equal(2.46); - // tracker slot1 - const firstTracker = requests[0].url; - expect(firstTracker.split('?')[0]).to.equal('https://t.pubmatic.com/wt'); - data = {}; - firstTracker.split('?')[1].split('&').map(e => e.split('=')).forEach(e => data[e[0]] = e[1]); - expect(data.v).to.equal('1'); - expect(data.psrc).to.equal('web'); - }); - - it('bidCpmAdjustment: JPY: Logger: best case + win tracker', function () { - config.setConfig({ - testGroupId: 25 - }); - - setConfig({ - adServerCurrency: 'JPY', - rates: { - USD: { - JPY: 100 - } - } - }); - const bidCopy = utils.deepClone(BID); - bidCopy.originalCpm = 100; - bidCopy.originalCurrency = 'JPY'; - bidCopy.currency = 'JPY'; - bidCopy.cpm = bidCopy.originalCpm * 2; // bidCpmAdjustment => bidCpm * 2 - - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, bidCopy); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]); - events.emit(BID_RESPONSE, bidCopy); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - events.emit(BID_WON, MOCK.BID_WON[1]); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(3); // 1 logger and 2 win-tracker - const request = requests[2]; // logger is executed late, trackers execute first - expect(request.url).to.equal('https://t.pubmatic.com/wl?v=1&psrc=web'); - let data = getLoggerJsonFromRequest(request.requestBody); - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.rd.pubid).to.equal('9999'); - expect(data.rd.pid).to.equal('1111'); - expect(data.rd.tgid).to.equal(0);// test group id should be between 0-15 else set to 0 - // floor data in featureList - expect(data.fd.flr.modelVersion).to.equal('floorModelTest'); - expect(data.fd.flr).to.have.property('enforcements'); - expect(data.fd.flr.enforcements).to.deep.equal({ - enforceJS: true, - enforcePBS: false, - floorDeals: false, - bidAdjustment: true - }); - expect(data.fd.flr.fetchStatus).to.equal('success'); - expect(data.fd.flr.floorProvider).to.equal('pubmatic'); - expect(data.fd.flr.location).to.equal('fetch'); - expect(data.fd.flr.skipRate).to.equal(0); - expect(data.fd.flr.skipped).to.equal(false); - expect(data.sd).to.be.an('object'); - expect(Object.keys(data.sd).length).to.equal(2); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.bidGrossCpmUSD).to.equal(1); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.bidPriceUSD).to.equal(200); // bidPriceUSD is not getting set as currency module is not added - - // tracker slot1 - let firstTracker = requests[0].url; - expect(firstTracker.split('?')[0]).to.equal('https://t.pubmatic.com/wt'); - data = {}; - firstTracker.split('?')[1].split('&').map(e => e.split('=')).forEach(e => data[e[0]] = e[1]); - expect(data.v).to.equal('1'); - expect(data.psrc).to.equal('web'); - }); - - it('Logger: when bid is not submitted, default bid status 1 check: pubmatic set as s2s', function () { - config.setConfig({ - testGroupId: '25' - }); - - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(2); // 1 logger and 1 win-tracker - const request = requests[1]; // logger is executed late, trackers execute first - const data = getLoggerJsonFromRequest(request.requestBody); - - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.rd.tgid).to.equal(0);// test group id should be an INT between 0-15 else set to 0 - - expect(data.sd).to.be.an('object'); - expect(Object.keys(data.sd).length).to.equal(2); - - expect(data.sd).to.have.property('/19968336/header-bid-tag-0'); - expect(data.sd['/19968336/header-bid-tag-0'].dimensions).to.deep.equal([[640, 480]]) - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].adapterCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidderCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.originalCpm).to.equal(1.23); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.originalCurrency).to.equal('USD'); - }); - - it('Logger: post-timeout check without bid response', function () { - // db = 1 and t = 1 means bidder did NOT respond with a bid but we got a timeout notification - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_TIMEOUT, MOCK.BID_TIMEOUT); - events.emit(AUCTION_END, MOCK.AUCTION_END); - clock.tick(2000 + 1000); - - expect(requests.length).to.equal(1); // 1 logger and 0 win-tracker - const request = requests[0]; - const data = getLoggerJsonFromRequest(request.requestBody); - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.sd).to.be.an('object'); - expect(Object.keys(data.sd).length).to.equal(2); - expect(data.sd).to.have.property('/19968336/header-bid-tag-1'); - expect(data.sd['/19968336/header-bid-tag-1'].dimensions).to.deep.equal([[1000, 300], [970, 250], [728, 90]]); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].adapterCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidderCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].params.kgpv).to.equal('this-is-a-kgpv'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0]).to.not.have.property('bidResponse') - }); - - it('Logger: post-timeout check with bid response', function () { - // db = 1 and t = 1 means bidder did NOT respond with a bid but we got a timeout notification - - sandbox.stub(getGlobal(), 'getHighestCpmBids').callsFake((key) => { - return [MOCK.BID_RESPONSE[1]] - }); - - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]); - events.emit(BID_TIMEOUT, MOCK.BID_TIMEOUT); - events.emit(AUCTION_END, MOCK.AUCTION_END); - clock.tick(2000 + 1000); - - expect(requests.length).to.equal(1); // 1 logger and 0 win-tracker - const request = requests[0]; - const data = getLoggerJsonFromRequest(request.requestBody); - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.sd).to.have.property('/19968336/header-bid-tag-1'); - expect(data.sd['/19968336/header-bid-tag-1'].dimensions).to.deep.equal([[1000, 300], [970, 250], [728, 90]]); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].adapterCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidderCode).to.equal('pubmatic'); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].params.kgpv).to.equal('this-is-a-kgpv'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0]).to.have.property('bidResponse'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCpm).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCurrency).to.equal('USD'); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.dealId).to.equal('the-deal-id'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].partnerTimeToRespond).to.equal(944); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].clientLatencyTimeMs).to.equal(3214); - expect(data.rd.s2sls).to.deep.equal(['pubmatic']); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].status).to.equal('error'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.mediaType).to.equal('banner'); - }); - - it('Logger: currency conversion check', function () { - setUANull(); - setConfig({ - adServerCurrency: 'JPY', - rates: { - USD: { - JPY: 100 - } - } - }); - const bidCopy = utils.deepClone(BID2); - bidCopy.currency = 'JPY'; - bidCopy.cpm = 100; - bidCopy.originalCpm = 100; - bidCopy.originalCurrency = 'JPY'; - - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_RESPONSE, bidCopy); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - events.emit(BID_WON, MOCK.BID_WON[1]); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(3); // 1 logger and 2 win-tracker - const request = requests[2]; // logger is executed late, trackers execute first - expect(request.url).to.equal('https://t.pubmatic.com/wl?v=1&psrc=web'); - const data = getLoggerJsonFromRequest(request.requestBody); - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.sd).to.have.property('/19968336/header-bid-tag-1'); - expect(data.sd['/19968336/header-bid-tag-1'].dimensions).to.deep.equal([[1000, 300], [970, 250], [728, 90]]); - expect(data.sd['/19968336/header-bid-tag-1'].bids).to.have.property('3bd4ebb1c900e2'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].adapterCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidderCode).to.equal('pubmatic'); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0]).to.have.property('bidResponse'); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCpm).to.equal(100); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCurrency).to.equal('JPY'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.mediaType).to.equal('banner'); - }); - - it('Logger: regexPattern in bid.params', function () { - setUAMobile(); - const BID_REQUESTED_COPY = utils.deepClone(MOCK.BID_REQUESTED); - BID_REQUESTED_COPY.bids[1].params.regexPattern = '*'; - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, BID_REQUESTED_COPY); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_RESPONSE, BID2); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - events.emit(BID_WON, MOCK.BID_WON[1]); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(3); // 1 logger and 2 win-tracker - const request = requests[2]; // logger is executed late, trackers execute first - expect(request.url).to.equal('https://t.pubmatic.com/wl?v=1&psrc=web'); - let data = getLoggerJsonFromRequest(request.requestBody); - - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.sd).to.have.property('/19968336/header-bid-tag-1'); - expect(data.sd['/19968336/header-bid-tag-1'].dimensions).to.deep.equal([[1000, 300], [970, 250], [728, 90]]); - expect(data.sd['/19968336/header-bid-tag-1'].bids).to.have.property('3bd4ebb1c900e2'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].adapterCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidderCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0]).to.have.property('bidResponse'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidId).to.equal('3bd4ebb1c900e2'); - expect(data.fd.flr.skipped).to.equal(false); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.bidGrossCpmUSD).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.bidPriceUSD).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].params.regexPattern).to.equal("*"); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.dealId).to.equal('the-deal-id'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].partnerTimeToRespond).to.equal(944); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].clientLatencyTimeMs).to.equal(3214); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCpm).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCurrency).to.equal('USD'); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.mi).to.equal('matched-impression'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.meta.advertiserDomains).to.deep.equal(['example.com']); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.mediaType).to.equal('banner'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.floorData.floorRuleValue).to.equal(1.1); - - expect(data.sd['/19968336/header-bid-tag-1'].bidWonAdId).to.equal('fake_ad_id_2'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.adserverTargeting.hb_pb).to.equal(1.5); - - const firstTracker = requests[1].url; - expect(firstTracker.split('?')[0]).to.equal('https://t.pubmatic.com/wt'); - data = {}; - firstTracker.split('?')[1].split('&').map(e => e.split('=')).forEach(e => data[e[0]] = e[1]); - expect(data.v).to.equal('1'); - expect(data.psrc).to.equal('web'); - }); - - it('Logger: regexPattern in bid.bidResponse and url in adomain', function () { - const BID2_COPY = utils.deepClone(BID2); - BID2_COPY.regexPattern = '*'; - BID2_COPY.meta.advertiserDomains = ['https://www.example.com/abc/223'] - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_RESPONSE, BID2_COPY); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - events.emit(BID_WON, Object.assign({}, BID2_COPY, { - 'status': 'rendered' - })); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(3); // 1 logger and 2 win-tracker - const request = requests[2]; // logger is executed late, trackers execute first - expect(request.url).to.equal('https://t.pubmatic.com/wl?v=1&psrc=web'); - let data = getLoggerJsonFromRequest(request.requestBody); - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.sd).to.have.property('/19968336/header-bid-tag-1'); - expect(data.sd['/19968336/header-bid-tag-1'].dimensions).to.deep.equal([[1000, 300], [970, 250], [728, 90]]); - expect(data.sd['/19968336/header-bid-tag-1'].bids).to.have.property('3bd4ebb1c900e2'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].adapterCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidderCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0]).to.have.property('bidResponse'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.floorData.floorValue).to.equal(1.1); - - // respective tracker slot - const firstTracker = requests[1].url; - expect(firstTracker.split('?')[0]).to.equal('https://t.pubmatic.com/wt'); - data = {}; - firstTracker.split('?')[1].split('&').map(e => e.split('=')).forEach(e => data[e[0]] = e[1]); - expect(data.v).to.equal('1'); - expect(data.psrc).to.equal('web'); - }); - - it('Logger: regexPattern in bid.params', function () { - const BID_REQUESTED_COPY = utils.deepClone(MOCK.BID_REQUESTED); - BID_REQUESTED_COPY.bids[1].params.regexPattern = '*'; - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, BID_REQUESTED_COPY); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_RESPONSE, BID2); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - events.emit(BID_WON, MOCK.BID_WON[1]); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(3); // 1 logger and 2 win-tracker - const request = requests[2]; // logger is executed late, trackers execute first - expect(request.url).to.equal('https://t.pubmatic.com/wl?v=1&psrc=web'); - let data = getLoggerJsonFromRequest(request.requestBody); - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.sd).to.have.property('/19968336/header-bid-tag-1'); - expect(data.sd['/19968336/header-bid-tag-1'].dimensions).to.deep.equal([[1000, 300], [970, 250], [728, 90]]); - expect(data.sd['/19968336/header-bid-tag-1'].bids).to.have.property('3bd4ebb1c900e2'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].adapterCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidderCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0]).to.have.property('bidResponse'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidId).to.equal('3bd4ebb1c900e2'); - expect(data.fd.flr.skipped).to.equal(false); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.bidGrossCpmUSD).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.bidPriceUSD).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].params.regexPattern).to.equal("*"); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.dealId).to.equal('the-deal-id'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].partnerTimeToRespond).to.equal(944); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].clientLatencyTimeMs).to.equal(3214); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCpm).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCurrency).to.equal('USD'); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.mi).to.equal('matched-impression'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.meta.advertiserDomains).to.deep.equal(['example.com']); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.mediaType).to.equal('banner'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.floorData.floorRuleValue).to.equal(1.1); - - expect(data.sd['/19968336/header-bid-tag-1'].bidWonAdId).to.equal('fake_ad_id_2'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.adserverTargeting.hb_pb).to.equal(1.5); - - let firstTracker = requests[1].url; - expect(firstTracker.split('?')[0]).to.equal('https://t.pubmatic.com/wt'); - data = {}; - firstTracker.split('?')[1].split('&').map(e => e.split('=')).forEach(e => data[e[0]] = e[1]); - expect(data.v).to.equal('1'); - expect(data.psrc).to.equal('web'); - }); - - it('Logger: regexPattern in bid.bidResponse', function () { - const BID2_COPY = utils.deepClone(BID2); - BID2_COPY.regexPattern = '*'; - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_RESPONSE, BID2_COPY); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - events.emit(BID_WON, Object.assign({}, BID2_COPY, { - 'status': 'rendered' - })); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(3); // 1 logger and 2 win-tracker - const request = requests[2]; // logger is executed late, trackers execute first - expect(request.url).to.equal('https://t.pubmatic.com/wl?v=1&psrc=web'); - const data = getLoggerJsonFromRequest(request.requestBody); - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.sd).to.have.property('/19968336/header-bid-tag-1'); - expect(data.sd['/19968336/header-bid-tag-1'].dimensions).to.deep.equal([[1000, 300], [970, 250], [728, 90]]); - expect(data.sd['/19968336/header-bid-tag-1'].bids).to.have.property('3bd4ebb1c900e2'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].adapterCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidderCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0]).to.have.property('bidResponse'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidId).to.equal('3bd4ebb1c900e2'); - expect(data.fd.flr.skipped).to.equal(false); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.bidGrossCpmUSD).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.bidPriceUSD).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.dealId).to.equal('the-deal-id'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].partnerTimeToRespond).to.equal(944); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].clientLatencyTimeMs).to.equal(3214); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCpm).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCurrency).to.equal('USD'); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.regexPattern).to.equal('*'); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.mi).to.equal('matched-impression'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.meta.advertiserDomains).to.deep.equal(['example.com']); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.mediaType).to.equal('banner'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.floorData.floorRuleValue).to.equal(1.1); - - expect(data.sd['/19968336/header-bid-tag-1'].bidWonAdId).to.equal('fake_ad_id_2'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.adserverTargeting.hb_pb).to.equal(1.5); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.dealChannel).to.equal('PMP'); - }); - - it('Logger: to handle floor rejected bids', function () { - this.timeout(5000) - - sandbox.stub(getGlobal(), 'getHighestCpmBids').callsFake((key) => { - return [MOCK.BID_RESPONSE[0], MOCK.BID_RESPONSE[1]] - }); - - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_REJECTED, MOCK.REJECTED_BID[0]); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(2); // 1 logger and 1 win-tracker - const request = requests[1]; // logger is executed late, trackers execute first - expect(request.url).to.equal('https://t.pubmatic.com/wl?v=1&psrc=web'); - const data = getLoggerJsonFromRequest(request.requestBody); - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.fd.flr.fetchStatus).to.equal('success'); - expect(data.fd.flr).to.have.property('enforcements'); - expect(data.fd.flr.floorProvider).to.equal('pubmatic'); - - expect(data.sd).to.have.property('/19968336/header-bid-tag-1'); - expect(data.sd['/19968336/header-bid-tag-1'].dimensions).to.deep.equal([[1000, 300], [970, 250], [728, 90]]); - expect(data.sd['/19968336/header-bid-tag-1'].bids).to.have.property('3bd4ebb1c900e2'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].adapterCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidderCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0]).to.have.property('bidResponse'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidId).to.equal('3bd4ebb1c900e2'); - expect(data.fd.flr.skipped).to.equal(false); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.bidGrossCpmUSD).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.bidPriceUSD).to.equal(0); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.dealId).to.equal('the-deal-id'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].partnerTimeToRespond).to.equal(944); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].clientLatencyTimeMs).to.equal(3214); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].partnerTimeToRespond).to.equal(944); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].clientLatencyTimeMs).to.equal(3214); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCpm).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCurrency).to.equal('USD'); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.mi).to.equal('matched-impression'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.meta.advertiserDomains).to.deep.equal(['example.com']); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.mediaType).to.equal('banner'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.floorData.floorRuleValue).to.equal(1.1); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.adserverTargeting.hb_pb).to.equal(1.5); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.dealChannel).to.equal('PMP'); - }); - - it('Logger: best case + win tracker in case of Bidder Aliases', function () { - MOCK.BID_REQUESTED['bids'][0]['bidder'] = 'pubmatic_alias'; - MOCK.BID_REQUESTED['bids'][0]['bidderCode'] = 'pubmatic_alias'; - adapterManager.aliasRegistry['pubmatic_alias'] = 'pubmatic'; - - sandbox.stub(getGlobal(), 'getHighestCpmBids').callsFake((key) => { - return [MOCK.BID_RESPONSE[0], MOCK.BID_RESPONSE[1]] - }); - - config.setConfig({ - testGroupId: 15 - }); - - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - events.emit(BID_WON, MOCK.BID_WON[1]); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(3); // 1 logger and 2 win-tracker - const request = requests[2]; // logger is executed late, trackers execute first - expect(request.url).to.equal('https://t.pubmatic.com/wl?v=1&psrc=web'); - let data = getLoggerJsonFromRequest(request.requestBody); - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.rd.pubid).to.equal('9999'); - expect(data.rd.pid).to.equal('1111'); - expect(data.rd.pdvid).to.equal('20'); - expect(data.rd.iid).to.equal('25c6d7f5-699a-4bfc-87c9-996f915341fa'); - expect(data.rd.to).to.equal(3000); - expect(data.rd.purl).to.equal('http://www.test.com/page.html'); - expect(data.rd.tst).to.equal(1519767016); - expect(data.rd.tgid).to.equal(15); - - // floor data in featureList - expect(data.fd.flr.modelVersion).to.equal('floorModelTest'); - expect(data.fd.flr).to.have.property('enforcements'); - expect(data.fd.flr.enforcements).to.deep.equal({ - enforceJS: true, - enforcePBS: false, - floorDeals: false, - bidAdjustment: true - }); - expect(data.fd.flr.fetchStatus).to.equal('success'); - expect(data.fd.flr.floorProvider).to.equal('pubmatic'); - expect(data.fd.flr.location).to.equal('fetch'); - expect(data.fd.flr.skipRate).to.equal(0); - expect(data.fd.flr.skipped).to.equal(false); - - expect(data.sd).to.be.an('object'); - expect(Object.keys(data.sd).length).to.equal(2); - - // slot 1 - - expect(data.sd).to.have.property('/19968336/header-bid-tag-0'); - - expect(data.sd['/19968336/header-bid-tag-0'].bids).to.have.property('2ecff0db240757'); - expect(data.sd['/19968336/header-bid-tag-0'].dimensions).to.deep.equal([[640, 480]]) - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].adapterCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidderCode).to.equal('pubmatic_alias'); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.originalCpm).to.equal(1.23); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.originalCurrency).to.equal('USD'); - - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0]).to.have.property('bidResponse'); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidId).to.equal('2ecff0db240757'); - expect(data.fd.flr.skipped).to.equal(false); - - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.bidGrossCpmUSD).to.equal(1.23); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.bidPriceUSD).to.equal(1.23); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].partnerTimeToRespond).to.equal(944); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].clientLatencyTimeMs).to.equal(3214); - - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.originalCpm).to.equal(1.23); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.originalCurrency).to.equal('USD'); - - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.mediaType).to.equal('video'); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.floorData.floorRuleValue).to.equal(1.1); - - expect(data.sd['/19968336/header-bid-tag-0'].bidWonAdId).to.equal('fake_ad_id'); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.adserverTargeting.hb_pb).to.equal(1.2); - - // slot 2 - expect(data.sd).to.have.property('/19968336/header-bid-tag-1'); - expect(data.sd['/19968336/header-bid-tag-1'].dimensions).to.deep.equal([[1000, 300], [970, 250], [728, 90]]); - expect(data.sd['/19968336/header-bid-tag-1'].bids).to.have.property('3bd4ebb1c900e2'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].adapterCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidderCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0]).to.have.property('bidResponse'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidId).to.equal('3bd4ebb1c900e2'); - expect(data.fd.flr.skipped).to.equal(false); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.bidGrossCpmUSD).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.bidPriceUSD).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].params.kgpv).to.equal("this-is-a-kgpv"); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.dealId).to.equal('the-deal-id'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].partnerTimeToRespond).to.equal(944); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].clientLatencyTimeMs).to.equal(3214); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCpm).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCurrency).to.equal('USD'); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.mi).to.equal('matched-impression'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.meta.advertiserDomains).to.deep.equal(['example.com']); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.mediaType).to.equal('banner'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.floorData.floorRuleValue).to.equal(1.1); - - expect(data.sd['/19968336/header-bid-tag-1'].bidWonAdId).to.equal('fake_ad_id_2'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.adserverTargeting.hb_pb).to.equal(1.5); - - // tracker slot1 - let firstTracker = requests[0].url; - expect(firstTracker.split('?')[0]).to.equal('https://t.pubmatic.com/wt'); - data = {}; - firstTracker.split('?')[1].split('&').map(e => e.split('=')).forEach(e => data[e[0]] = e[1]); - expect(data.v).to.equal('1'); - expect(data.psrc).to.equal('web'); - }); - - it('Logger: best case + win tracker in case of GroupM as alternate bidder', function () { - MOCK.BID_REQUESTED['bids'][0]['bidderCode'] = 'groupm'; - sandbox.stub(getGlobal(), 'getHighestCpmBids').callsFake((key) => { - return [MOCK.BID_RESPONSE[0], MOCK.BID_RESPONSE[1]] - }); - - config.setConfig({ - testGroupId: 15 - }); - - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[1]); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - events.emit(SET_TARGETING, MOCK.SET_TARGETING); - events.emit(BID_WON, MOCK.BID_WON[0]); - events.emit(BID_WON, MOCK.BID_WON[1]); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(3); // 1 logger and 2 win-tracker - const request = requests[2]; // logger is executed late, trackers execute first - expect(request.url).to.equal('https://t.pubmatic.com/wl?v=1&psrc=web'); - let data = getLoggerJsonFromRequest(request.requestBody); - // check mandatory fields - expect(data).to.have.property('sd'); - expect(data).to.have.property('fd'); - expect(data).to.have.property('rd'); - - expect(data.rd.pubid).to.equal('9999'); - expect(data.rd.pid).to.equal('1111'); - expect(data.rd.pdvid).to.equal('20'); - expect(data.rd.iid).to.equal('25c6d7f5-699a-4bfc-87c9-996f915341fa'); - expect(data.rd.to).to.equal(3000); - expect(data.rd.purl).to.equal('http://www.test.com/page.html'); - expect(data.rd.tst).to.equal(1519767016); - expect(data.rd.tgid).to.equal(15); - - // floor data in feature list data - expect(data.fd.flr.modelVersion).to.equal('floorModelTest'); - expect(data.fd.flr).to.have.property('enforcements'); - expect(data.fd.flr.enforcements).to.deep.equal({ - enforceJS: true, - enforcePBS: false, - floorDeals: false, - bidAdjustment: true - }); - expect(data.fd.flr.fetchStatus).to.equal('success'); - expect(data.fd.flr.floorProvider).to.equal('pubmatic'); - expect(data.fd.flr.location).to.equal('fetch'); - expect(data.fd.flr.skipRate).to.equal(0); - expect(data.fd.flr.skipped).to.equal(false); - - expect(data.sd).to.be.an('object'); - expect(Object.keys(data.sd).length).to.equal(2); - - expect(data.sd).to.have.property('/19968336/header-bid-tag-0'); - - expect(data.sd['/19968336/header-bid-tag-0'].bids).to.have.property('2ecff0db240757'); - expect(data.sd['/19968336/header-bid-tag-0'].dimensions).to.deep.equal([[640, 480]]) - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].adapterCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidderCode).to.equal('groupm'); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.originalCpm).to.equal(1.23); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.originalCurrency).to.equal('USD'); - - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0]).to.have.property('bidResponse'); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidId).to.equal('2ecff0db240757'); - expect(data.fd.flr.skipped).to.equal(false); - - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.bidGrossCpmUSD).to.equal(1.23); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.bidPriceUSD).to.equal(1.23); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].partnerTimeToRespond).to.equal(944); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].clientLatencyTimeMs).to.equal(3214); - - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.originalCpm).to.equal(1.23); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.originalCurrency).to.equal('USD'); - - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.mediaType).to.equal('video'); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.floorData.floorRuleValue).to.equal(1.1); - - expect(data.sd['/19968336/header-bid-tag-0'].bidWonAdId).to.equal('fake_ad_id'); - expect(data.sd['/19968336/header-bid-tag-0'].bids['2ecff0db240757'][0].bidResponse.adserverTargeting.hb_pb).to.equal(1.2); - - // slot 2 - expect(data.sd).to.have.property('/19968336/header-bid-tag-1'); - expect(data.sd['/19968336/header-bid-tag-1'].dimensions).to.deep.equal([[1000, 300], [970, 250], [728, 90]]); - expect(data.sd['/19968336/header-bid-tag-1'].bids).to.have.property('3bd4ebb1c900e2'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].adapterCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidderCode).to.equal('pubmatic'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0]).to.have.property('bidResponse'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidId).to.equal('3bd4ebb1c900e2'); - expect(data.fd.flr.skipped).to.equal(false); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.bidGrossCpmUSD).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.bidPriceUSD).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].params.kgpv).to.equal("this-is-a-kgpv"); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.dealId).to.equal('the-deal-id'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].partnerTimeToRespond).to.equal(944); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].clientLatencyTimeMs).to.equal(3214); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCpm).to.equal(1.52); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.originalCurrency).to.equal('USD'); - - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.mi).to.equal('matched-impression'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.meta.advertiserDomains).to.deep.equal(['example.com']); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.mediaType).to.equal('banner'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.floorData.floorRuleValue).to.equal(1.1); - - expect(data.sd['/19968336/header-bid-tag-1'].bidWonAdId).to.equal('fake_ad_id_2'); - expect(data.sd['/19968336/header-bid-tag-1'].bids['3bd4ebb1c900e2'][0].bidResponse.adserverTargeting.hb_pb).to.equal(1.5); - - // tracker slot1 - let firstTracker = requests[0].url; - expect(firstTracker.split('?')[0]).to.equal('https://t.pubmatic.com/wt'); - data = {}; - firstTracker.split('?')[1].split('&').map(e => e.split('=')).forEach(e => data[e[0]] = e[1]); - expect(data.v).to.equal('1'); - expect(data.psrc).to.equal('web'); - }); - - it('Logger: should verify display manager and version in analytics data', function () { - events.emit(AUCTION_INIT, MOCK.AUCTION_INIT); - events.emit(BID_REQUESTED, MOCK.BID_REQUESTED); - events.emit(BID_RESPONSE, MOCK.BID_RESPONSE[0]); - events.emit(BIDDER_DONE, MOCK.BIDDER_DONE); - events.emit(AUCTION_END, MOCK.AUCTION_END); - - clock.tick(2000 + 1000); - expect(requests.length).to.equal(1); - const request = requests[0]; - const data = getLoggerJsonFromRequest(request.requestBody); - // Verify display manager - expect(data.rd.dm).to.equal(DISPLAY_MANAGER); - // Verify display manager version using global Prebid version - expect(data.rd.dmv).to.equal('$prebid.version$' || '-1'); - }); - }); -}); diff --git a/test/spec/modules/pubmaticBidAdapter_spec.js b/test/spec/modules/pubmaticBidAdapter_spec.js deleted file mode 100644 index 3f2fb2123..000000000 --- a/test/spec/modules/pubmaticBidAdapter_spec.js +++ /dev/null @@ -1,1876 +0,0 @@ -import { expect } from 'chai'; -import { spec, cpmAdjustment, addViewabilityToImp, shouldAddDealTargeting } from 'modules/pubmaticBidAdapter.js'; -import * as utils from 'src/utils.js'; -import { bidderSettings } from 'src/bidderSettings.js'; -import { config } from 'src/config.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -describe('PubMatic adapter', () => { - let firstBid, videoBid, firstResponse, response, videoResponse, firstAliasBid; - const PUBMATIC_ALIAS_BIDDER = 'pubmaticAlias'; - const request = {}; - firstBid = { - adUnitCode: 'Div1', - bidder: 'pubmatic', - mediaTypes: { - banner: { - sizes: [[728, 90], [160, 600]], - pos: 1 - } - }, - params: { - publisherId: '5670', - adSlot: '/15671365/DMDemo@300x250:0', - kadfloor: '1.2', - pmzoneid: 'aabc, ddef', - // kadpageurl: 'www.publisher.com', - yob: '1986', - gender: 'M', - lat: '12.3', - lon: '23.7', - wiid: '1234567890', - profId: '100', - verId: '200', - currency: 'AUD', - dctr: 'key1:val1,val2|key2:val1', - deals: ['deal-1', 'deal-2'] - }, - placementCode: '/19968336/header-bid-tag-1', - sizes: [ - [300, 250], - [300, 600], - ['fluid'] - ], - bidId: '3736271c3c4b27', - requestId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - ortb2: { - device: { - w: 1200, - h: 1800, - sua: {}, - language: 'en', - js: 1, - connectiontype: 6 - }, - site: {domain: 'ebay.com', page: 'https://ebay.com', publisher: {id: '5670'}}, - source: {}, - user: { - ext: { - data: { - im_segments: ['segment1', 'segment2'] - } - } - } - }, - ortb2Imp: { - ext: { - tid: '92489f71-1bf2-49a0-adf9-000cea934729', - gpid: '/1111/homepage-leftnav', - data: { - pbadslot: '/1111/homepage-leftnav', - adserver: { - name: 'gam', - adslot: '/1111/homepage-leftnav' - }, - customData: { - id: 'id-1' - } - } - } - }, - rtd: { - jwplayer: { - targeting: { - content: { - id: 'jwplayer-content-id' - }, - segments: [ - 'jwplayer-segment-1', 'jwplayer-segment-2' - ] - } - } - } - } - firstAliasBid = { - adUnitCode: 'Div1', - bidder: PUBMATIC_ALIAS_BIDDER, - mediaTypes: { - banner: { - sizes: [[728, 90], [160, 600]], - pos: 1 - } - }, - params: { - publisherId: '5670', - adSlot: '/15671365/DMDemo@300x250:0', - kadfloor: '1.2', - pmzoneid: 'aabc, ddef', - // kadpageurl: 'www.publisher.com', - yob: '1986', - gender: 'M', - lat: '12.3', - lon: '23.7', - wiid: '1234567890', - profId: '100', - verId: '200', - currency: 'AUD', - dctr: 'key1:val1,val2|key2:val1', - deals: ['deal-1', 'deal-2'] - }, - placementCode: '/19968336/header-bid-tag-1', - sizes: [ - [300, 250], - [300, 600], - ['fluid'] - ], - bidId: '3736271c3c4b27', - requestId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - ortb2: { - device: { - w: 1200, - h: 1800, - sua: {}, - language: 'en', - js: 1, - connectiontype: 6 - }, - site: {domain: 'ebay.com', page: 'https://ebay.com', publisher: {id: '5670'}}, - source: {}, - user: { - ext: { - data: { - im_segments: ['segment1', 'segment2'] - } - } - } - }, - ortb2Imp: { - ext: { - tid: '92489f71-1bf2-49a0-adf9-000cea934729', - gpid: '/1111/homepage-leftnav', - data: { - pbadslot: '/1111/homepage-leftnav', - adserver: { - name: 'gam', - adslot: '/1111/homepage-leftnav' - }, - customData: { - id: 'id-1' - } - } - } - }, - rtd: { - jwplayer: { - targeting: { - content: { - id: 'jwplayer-content-id' - }, - segments: [ - 'jwplayer-segment-1', 'jwplayer-segment-2' - ] - } - } - } - } - videoBid = { - 'seat': 'seat-id', - 'ext': { - 'buyid': 'BUYER-ID-987' - }, - 'bid': [{ - 'id': '74858439-49D7-4169-BA5D-44A046315B2F', - 'impid': '3736271c3c4b27', - 'price': 1.3, - 'adm': 'Acudeo CompatibleVAST 2.0 Instream Test 1VAST 2.0 Instream Test 1https://dsptracker.com/{PSPM}00:00:04https://www.pubmatic.com', - 'adomain': ['blackrock.com'], - 'h': 250, - 'w': 300, - 'ext': { - 'deal_channel': 6, - 'advid': 976, - 'dspid': 123 - }, - 'dealid': 'PUBDEAL1', - 'mtype': 2, - 'params': {'outstreamAU': 'outstreamAU', 'renderer': 'renderer_test_pubmatic'} - }] - }; - firstResponse = { - 'seat': 'seat-id', - 'ext': { - 'buyid': 'BUYER-ID-987' - }, - 'bid': [{ - 'id': '74858439-49D7-4169-BA5D-44A046315B2F', - 'impid': '3736271c3c4b27', - 'price': 1.3, - 'adm': 'image3.pubmatic.com Layer based creative', - 'adomain': ['blackrock.com'], - 'h': 250, - 'w': 300, - 'ext': { - 'deal_channel': 6, - 'advid': 976, - 'dspid': 123 - }, - 'dealid': 'PUBDEAL1', - 'mtype': 1 - }] - }; - response = { - 'body': { - cur: 'USD', - id: '93D3BAD6-E2E2-49FB-9D89-920B1761C865', - seatbid: [firstResponse] - } - }; - videoResponse = { - 'body': { - cur: 'USD', - id: '93D3BAD6-E2E2-49FB-9D89-920B1761C865', - seatbid: [videoBid] - } - } - const validBidRequests = [firstBid]; - const validAliasBidRequests = [firstAliasBid]; - const bidderRequest = { - bids: [firstBid], - auctionId: 'ee3074fe-97ce-4681-9235-d7622aede74c', - auctionStart: 1725514077194, - bidderCode: 'pubmatic', - bidderRequestId: '1c56ad30b9b8ca8', - refererInfo: { - page: 'https://ebay.com', - ref: '' - }, - ortb2: { - device: { - w: 1200, - h: 1800, - sua: {}, - language: 'en', - js: 1, - connectiontype: 6 - }, - site: {domain: 'ebay.com', page: 'https://ebay.com'}, - source: {}, - user: { - ext: { - data: { - im_segments: ['segment1', 'segment2'] - } - } - } - }, - timeout: 2000, - - }; - const bidderAliasRequest = { - bids: [firstAliasBid], - auctionId: 'ee3074fe-97ce-4681-9235-d7622aede74c', - auctionStart: 1725514077194, - bidderCode: PUBMATIC_ALIAS_BIDDER, - bidderRequestId: '1c56ad30b9b8ca8', - refererInfo: { - page: 'https://ebay.com', - ref: '' - }, - ortb2: { - device: { - w: 1200, - h: 1800, - sua: {}, - language: 'en', - js: 1, - connectiontype: 6 - }, - site: {domain: 'ebay.com', page: 'https://ebay.com'}, - source: {}, - user: { - ext: { - data: { - im_segments: ['segment1', 'segment2'] - } - } - } - }, - timeout: 2000, - - }; - let videoBidRequest, videoBidderRequest, utilsLogWarnMock, nativeBidderRequest; - - describe('Bid validations', () => { - it('should return true if publisherId is present in params', () => { - const isValid = spec.isBidRequestValid(validBidRequests[0]); - expect(isValid).to.equal(true); - }); - - it('should return false if publisherId is missing', () => { - const bid = utils.deepClone(validBidRequests[0]); - delete bid.params.publisherId; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equal(false); - }); - - it('should return false if publisherId is not of type string', () => { - const bid = utils.deepClone(validBidRequests[0]); - bid.params.publisherId = 5890; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equal(false); - }); - - if (FEATURES.VIDEO) { - describe('VIDEO', () => { - beforeEach(() => { - videoBidRequest = utils.deepClone(validBidRequests[0]); - delete videoBidRequest.mediaTypes.banner; - delete videoBidRequest.mediaTypes.native; - videoBidRequest.mediaTypes.video = { - playerSize: [ - [640, 480] - ], - protocols: [1, 2, 5], - context: 'instream', - skippable: false, - skip: 1, - linearity: 2 - } - videoBidRequest.params.outstreamAU = 'outstreamAU'; - videoBidRequest.params.renderer = 'renderer_test_pubmatic' - }); - it('should return false if mimes are missing in a video impression request', () => { - const isValid = spec.isBidRequestValid(videoBidRequest); - expect(isValid).to.equal(false); - }); - - it('should return false if context is missing in a video impression request', () => { - delete videoBidRequest.mediaTypes.context; - const isValid = spec.isBidRequestValid(videoBidRequest); - expect(isValid).to.equal(false); - }) - - it('should return true if banner/native present, but outstreamAU or renderer is missing', () => { - videoBidRequest.mediaTypes.video.mimes = ['video/flv']; - videoBidRequest.mediaTypes.video.context = 'outstream'; - - videoBidRequest.mediaTypes.banner = { - sizes: [[728, 90], [160, 600]] - }; - - // Remove width and height from the video object to test coverage for missing values - delete videoBidRequest.mediaTypes.video.width; - delete videoBidRequest.mediaTypes.video.height; - - const isValid = spec.isBidRequestValid(videoBidRequest); - expect(isValid).to.equal(true); - }); - - it('should return false if outstreamAU or renderer is missing', () => { - const isValid = spec.isBidRequestValid(videoBidRequest); - expect(isValid).to.equal(false); - }); - - it('should return TRUE if outstreamAU or renderer is present', () => { - const isValid = spec.isBidRequestValid(videoBidRequest); - expect(isValid).to.equal(false); - }); - }); - } - }); - - describe('Request formation', () => { - describe('IMP', () => { - it('should include previousAuctionInfo in request when available', () => { - const bidRequestWithPrevAuction = utils.deepClone(validBidRequests[0]); - const bidderRequestWithPrevAuction = utils.deepClone(bidderRequest); - bidderRequestWithPrevAuction.ortb2 = bidderRequestWithPrevAuction.ortb2 || {}; - bidderRequestWithPrevAuction.ortb2.ext = bidderRequestWithPrevAuction.ortb2.ext || {}; - bidderRequestWithPrevAuction.ortb2.ext.prebid = bidderRequestWithPrevAuction.ortb2.ext.prebid || {}; - bidderRequestWithPrevAuction.ortb2.ext.prebid.previousauctioninfo = { - bidderRequestId: 'bidder-request-id' - }; - - const request = spec.buildRequests([bidRequestWithPrevAuction], bidderRequestWithPrevAuction); - expect(request.data.ext).to.have.property('previousAuctionInfo'); - expect(request.data.ext.previousAuctionInfo).to.deep.equal({ - bidderRequestId: 'bidder-request-id' - }); - }); - - it('should generate request with banner', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('banner'); - expect(imp[0]).to.have.property('id').equal('3736271c3c4b27'); - }); - - it('should have build request with alias bidder', () => { - getGlobal().aliasBidder('pubmatic', PUBMATIC_ALIAS_BIDDER); - const request = spec.buildRequests(validAliasBidRequests, bidderAliasRequest); - expect(request.data).to.have.property('ext').to.have.property('wrapper').to.have.property('biddercode'); - expect(request.data.ext.wrapper.biddercode).to.equal(PUBMATIC_ALIAS_BIDDER); - }); - - it('should add pmp if deals are present in parameters', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('pmp'); - expect(imp[0]).to.have.property('pmp').to.have.property('deals').with.lengthOf(2); - }); - - it('should not add pmp if deals are absent in parameters', () => { - delete validBidRequests[0].params.deals; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.not.have.property('pmp'); - }); - - it('should add key_val property if dctr is present in parameters', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('ext'); - expect(imp[0]).to.have.property('ext').to.have.property('key_val'); - }); - - it('adds key_val when dctr is missing but RTD provides custom targeting via ortb2', () => { - delete validBidRequests[0].params.dctr; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('ext').to.have.property('key_val'); - }); - - it('should set w and h to the primary size for banner', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('banner'); - expect(imp[0]).to.have.property('banner').to.have.property('w').equal(300); - expect(imp[0]).to.have.property('banner').to.have.property('h').equal(250); - }); - - it('should have 1 size in the banner.format array', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('banner').to.have.property('format'); - expect(imp[0]).to.have.property('banner').to.have.property('format').to.be.an('array'); - }); - - it('should not have format object in banner when there is only a single size', () => { - // Create a complete bid with only one size - const singleSizeBid = utils.deepClone(validBidRequests[0]); - singleSizeBid.mediaTypes.banner.sizes = [[300, 250]]; - singleSizeBid.params.adSlot = '/15671365/DMDemo@300x250:0'; - - // Create a complete bidder request - const singleSizeBidderRequest = utils.deepClone(bidderRequest); - singleSizeBidderRequest.bids = [singleSizeBid]; - - const request = spec.buildRequests([singleSizeBid], singleSizeBidderRequest); - const { imp } = request?.data; - - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('banner'); - expect(imp[0].banner).to.not.have.property('format'); - expect(imp[0].banner).to.have.property('w').equal(300); - expect(imp[0].banner).to.have.property('h').equal(250); - }); - - it('should add pmZoneId in ext if pmzoneid is present in parameters', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('ext'); - expect(imp[0]).to.have.property('ext').to.have.property('pmZoneId'); - }); - - it('should add pbcode in ext with adUnitCode value', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('ext'); - expect(imp[0].ext).to.have.property('pbcode'); - expect(imp[0].ext.pbcode).to.equal(validBidRequests[0].adUnitCode); - }); - - it('should add bidfloor if kadfloor is present in parameters', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('bidfloor'); - expect(imp[0]).to.have.property('bidfloor').equal(1.2); - }); - - it('should add bidfloorcur if currency is present in parameters', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('bidfloorcur'); - expect(imp[0]).to.have.property('bidfloorcur').equal('AUD'); - }); - - it('should add bidfloorcur with default value if currency is missing in parameters', () => { - delete validBidRequests[0].params.currency; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('bidfloorcur'); - expect(imp[0]).to.have.property('bidfloorcur').equal('USD'); - }); - - it('should add tagid', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('tagid'); - expect(imp[0]).to.have.property('tagid').equal('/15671365/DMDemo'); - }); - - it('should add secure, displaymanager & displaymanagerver', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('secure').equal(1); - expect(imp[0]).to.have.property('displaymanager').equal('Prebid.js'); - expect(imp[0]).to.have.property('displaymanagerver'); - }); - - it('should include the properties topframe and format as an array', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('banner').to.have.property('topframe'); - expect(imp[0]).to.have.property('banner').to.have.property('format').to.be.an('array'); - }); - - it('should respect the publisher-provided pos for the banner impression', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('banner').to.have.property('pos'); - expect(imp[0]).to.have.property('banner').to.have.property('pos').equal(1); - }); - - it('should default pos to 0 if not explicitly provided by the publisher', () => { - delete bidderRequest.bids[0].mediaTypes.banner.pos; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('banner').to.have.property('pos'); - expect(imp[0]).to.have.property('banner').to.have.property('pos').equal(0); - }); - - xit('should include custom targeting data in imp.ext when provided by RTD', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('ext'); - expect(imp[0].ext).to.have.property('key_val'); - expect(imp[0].ext.key_val).to.deep.equal('im_segments=segment1,segment2|jw-id=jwplayer-content-id|jw-jwplayer-segment-1=1|jw-jwplayer-segment-2=1'); - }) - - if (FEATURES.VIDEO) { - describe('VIDEO', () => { - beforeEach(() => { - utilsLogWarnMock = sinon.stub(utils, 'logWarn'); - videoBidderRequest = utils.deepClone(bidderRequest); - delete videoBidderRequest.bids[0].mediaTypes.banner; - videoBidderRequest.bids[0].mediaTypes.video = { - skip: 1, - mimes: ['video/mp4', 'video/x-flv'], - minduration: 5, - maxduration: 30, - startdelay: 5, - playbackmethod: [1, 3], - api: [1, 2], - protocols: [2, 3], - battr: [13, 14], - linearity: 1, - placement: 2, - plcmt: 1, - context: 'outstream', - minbitrate: 10, - maxbitrate: 10, - playerSize: [640, 480] - } - videoBidderRequest.bids[0].params.outstreamAU = 'outstreamAU'; - videoBidderRequest.bids[0].params.renderer = 'renderer_test_pubmatic' - videoBidderRequest.bids[0].adUnitCode = 'Div1'; - }); - - afterEach(() => { - utilsLogWarnMock.restore(); - }) - - it('should generate request with mediatype video', () => { - const request = spec.buildRequests(validBidRequests, videoBidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('video'); - }); - - it('should log a warning if playerSize is missing', () => { - delete videoBidderRequest.bids[0].mediaTypes.video.playerSize; - const request = spec.buildRequests(validBidRequests, videoBidderRequest); - sinon.assert.called(utils.logWarn); - }); - - it('should log a warning if plcmt is missing', () => { - delete videoBidderRequest.bids[0].mediaTypes.video.plcmt; - const request = spec.buildRequests(validBidRequests, videoBidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - sinon.assert.called(utils.logWarn); - expect(imp.video).to.be.undefined; - }); - - it('should have all supporting parameters', () => { - const request = spec.buildRequests(validBidRequests, videoBidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('video'); - expect(imp[0]).to.have.property('video').to.have.property('mimes'); - expect(imp[0]).to.have.property('video').to.have.property('minbitrate'); - expect(imp[0]).to.have.property('video').to.have.property('maxbitrate'); - expect(imp[0]).to.have.property('video').to.have.property('minduration'); - expect(imp[0]).to.have.property('video').to.have.property('maxduration'); - expect(imp[0]).to.have.property('video').to.have.property('plcmt'); - expect(imp[0]).to.have.property('video').to.have.property('battr'); - expect(imp[0]).to.have.property('video').to.have.property('startdelay'); - expect(imp[0]).to.have.property('video').to.have.property('playbackmethod'); - expect(imp[0]).to.have.property('video').to.have.property('api'); - expect(imp[0]).to.have.property('video').to.have.property('protocols'); - expect(imp[0]).to.have.property('video').to.have.property('linearity'); - expect(imp[0]).to.have.property('video').to.have.property('placement'); - expect(imp[0]).to.have.property('video').to.have.property('skip'); - expect(imp[0]).to.have.property('video').to.have.property('w'); - expect(imp[0]).to.have.property('video').to.have.property('h'); - }); - }); - } - if (FEATURES.NATIVE) { - describe('NATIVE', () => { - beforeEach(() => { - utilsLogWarnMock = sinon.stub(utils, 'logWarn'); - nativeBidderRequest = utils.deepClone(bidderRequest); - delete nativeBidderRequest.bids[0].mediaTypes.banner; - nativeBidderRequest.bids[0].nativeOrtbRequest = { - ver: '1.2', - assets: [{ - id: 0, - img: { - 'type': 3, - 'w': 300, - 'h': 250 - }, - required: 1, - }] - }; - nativeBidderRequest.bids[0].mediaTypes.native = { - title: { - required: true, - length: 80 - }, - image: { - required: true, - sizes: [300, 250] - }, - sponsoredBy: { - required: true - } - } - }); - - afterEach(() => { - utilsLogWarnMock.restore(); - }) - - it('should generate request with mediatype native', () => { - const request = spec.buildRequests(validBidRequests, nativeBidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('native'); - }); - }); - } - describe('ShouldAddDealTargeting', () => { - it('should return im_segment targeting', () => { - const ortb2 = { - user: { - ext: { - data: { - im_segments: ['segment1', 'segment2'] - } - } - } - }; - const result = shouldAddDealTargeting(ortb2); - expect(result).to.have.property('im_segments'); - expect(result.im_segments).to.deep.equal('im_segments=segment1,segment2'); - }); - it('should return ias-brand-safety targeting', () => { - const ortb2 = { - site: { - ext: { - data: { - 'ias-brand-safety': { - 'content': 'news', - 'sports': 'cricket', - 'cricket': 'player' - } - } - } - } - }; - const result = shouldAddDealTargeting(ortb2); - expect(result).to.have.property('ias-brand-safety'); - expect(result['ias-brand-safety']).to.deep.equal('content=news|sports=cricket|cricket=player'); - }); - it('should return undefined if no targeting is present', () => { - const ortb2 = {}; - const result = shouldAddDealTargeting(ortb2); - expect(result).to.be.undefined; - }); - it('should return both im_segment and ias-brand-safety targeting', () => { - const ortb2 = { - user: { - ext: { - data: { - im_segments: ['segment1', 'segment2'] - } - } - }, - site: { - ext: { - data: { - 'ias-brand-safety': { - 'content': 'news', - 'sports': 'cricket', - 'cricket': 'player' - } - } - } - } - }; - const result = shouldAddDealTargeting(ortb2); - expect(result).to.have.property('im_segments'); - expect(result.im_segments).to.deep.equal('im_segments=segment1,segment2'); - expect(result).to.have.property('ias-brand-safety'); - expect(result['ias-brand-safety']).to.deep.equal('content=news|sports=cricket|cricket=player'); - }); - }) - }); - - describe('rest of ORTB request', () => { - describe('BCAT', () => { - it('should contain only string values', () => { - validBidRequests[0].params.bcat = [1, 2, 3, 'IAB1', 'IAB2']; - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('bcat'); - expect(request.data).to.have.property('bcat').to.deep.equal(['IAB1', 'IAB2']); - }); - - it('should contain string values with length greater than 3', function() { - validBidRequests[0].params.bcat = ['AB', 'CD', 'IAB1', 'IAB2']; - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('bcat'); - expect(request.data).to.have.property('bcat').to.deep.equal(['IAB1', 'IAB2']); - }); - - it('should trim strings', function() { - validBidRequests[0].params.bcat = [' IAB1 ', ' IAB2 ']; - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('bcat'); - expect(request.data).to.have.property('bcat').to.deep.equal(['IAB1', 'IAB2']); - }); - - it('should pass unique strings', function() { - validBidRequests[0].params.bcat = ['IAB1', 'IAB2', 'IAB1', 'IAB2', 'IAB1', 'IAB2']; - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('bcat'); - expect(request.data).to.have.property('bcat').to.deep.equal(['IAB1', 'IAB2']); - }); - - it('should fail if validations are not met', function() { - validBidRequests[0].params.bcat = ['', 'IA', 'IB']; - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.not.have.property('bcat'); - }); - }); - - describe('ACAT', () => { - it('should contain only string values', () => { - validBidRequests[0].params.acat = [1, 2, 3, 'IAB1', 'IAB2']; - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('acat'); - expect(request.data).to.have.property('acat').to.deep.equal(['IAB1', 'IAB2']); - }); - - it('should trim strings', () => { - validBidRequests[0].params.acat = [' IAB1 ', ' IAB2 ']; - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('acat'); - expect(request.data).to.have.property('acat').to.deep.equal(['IAB1', 'IAB2']); - }); - - it('should pass unique strings', () => { - validBidRequests[0].params.acat = ['IAB1', 'IAB2', 'IAB1', 'IAB2', 'IAB1', 'IAB2']; - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('acat'); - expect(request.data).to.have.property('acat').to.deep.equal(['IAB1', 'IAB2']); - }); - - it('should fail if validations are not met', () => { - validBidRequests[0].params.acat = ['', 'IA', 'IB']; - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('acat'); - }); - }); - - describe('TMAX, ID, AT, CUR, EXT', () => { - it('should have tmax', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('tmax').to.equal(2000); - }); - - describe('Gzip Configuration', () => { - let configStub; - let bidderConfigStub; - - beforeEach(() => { - configStub = sinon.stub(config, 'getConfig'); - bidderConfigStub = sinon.stub(config, 'getBidderConfig'); - }); - - afterEach(() => { - configStub.restore(); - if (bidderConfigStub && bidderConfigStub.restore) { - bidderConfigStub.restore(); - } - }); - - it('should enable gzip compression by default', () => { - // No specific configuration set, should use default - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.options.endpointCompression).to.be.true; - }); - - it('should respect bidder-specific boolean configuration set via setBidderConfig', () => { - // Mock bidder-specific config to return false - bidderConfigStub.returns({ - pubmatic: { - gzipEnabled: false - } - }); - - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.options.endpointCompression).to.be.false; - }); - - it('should handle bidder-specific string configuration ("true")', () => { - bidderConfigStub.returns({ - pubmatic: { - gzipEnabled: 'true' - } - }); - - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.options.endpointCompression).to.be.true; - }); - - it('should handle bidder-specific string configuration ("false")', () => { - bidderConfigStub.returns({ - pubmatic: { - gzipEnabled: 'false' - } - }); - - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.options.endpointCompression).to.be.false; - }); - - it('should fall back to default when bidder-specific value is invalid', () => { - // Mock bidder-specific config to return invalid value - bidderConfigStub.returns({ - pubmatic: { - gzipEnabled: 'invalid' - } - }); - - const request = spec.buildRequests(validBidRequests, bidderRequest); - // Should fall back to default (true) - expect(request.options.endpointCompression).to.be.true; - }); - }); - - it('should remove test if pubmaticTest is not set', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('test').to.equal(undefined); - }); - - it('should have id', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('id'); - }); - - it('should set at to 1', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('at').to.equal(1); - }); - - it('should have cur', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('cur').to.be.an('array').to.have.lengthOf(1); - expect(request.data).to.have.property('cur').to.include.members(['USD']); - }); - - it('should have ext', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('ext').to.have.property('epoch'); - expect(request.data).to.have.property('ext').to.have.property('wrapper'); - expect(request.data).to.have.property('ext').to.have.property('wrapper').to.have.property('profile'); - expect(request.data).to.have.property('ext').to.have.property('wrapper').to.have.property('wiid'); - expect(request.data).to.have.property('ext').to.have.property('wrapper').to.have.property('wv'); - expect(request.data).to.have.property('ext').to.have.property('wrapper').to.have.property('wp'); - expect(request.data).to.have.property('ext').to.have.property('wrapper').to.have.property('biddercode'); - expect(request.data.ext.wrapper.biddercode).to.equal('pubmatic'); - }); - - it('should have url with post method', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request).to.have.property('method').to.equal('POST'); - expect(request).to.have.property('url').to.equal('https://hbopenbid.pubmatic.com/translator?source=prebid-client'); - }); - }); - - describe('Request Options', () => { - it('should set endpointCompression to true in request options', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request).to.have.property('options'); - expect(request.options).to.have.property('endpointCompression').to.equal(true); - }); - }); - - describe('GROUPM', () => { - let bidderSettingStub; - beforeEach(() => { - bidderSettingStub = sinon.stub(bidderSettings, 'get'); - }); - - afterEach(() => { - bidderSettingStub.restore(); - }); - - it('should skip setting the marketplace object in extension if allowAlternateBidderCodes is not defined', () => { - bidderSettingStub.returns(undefined); - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('ext').to.not.have.property('marketplace'); - }); - - it('should set the marketplace object in the extension when allowAlternateBidderCodes is set to "groupm"', () => { - bidderSettingStub.withArgs('pubmatic', 'allowAlternateBidderCodes').returns(true); - bidderSettingStub.withArgs('pubmatic', 'allowedAlternateBidderCodes').returns(['groupm']); - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('ext').to.have.property('marketplace'); - expect(request.data).to.have.property('ext').to.have.property('marketplace').to.have.property('allowedbidders').to.be.an('array'); - expect(request.data.ext.marketplace.allowedbidders.length).to.equal(2); - expect(request.data.ext.marketplace.allowedbidders[0]).to.equal('pubmatic'); - expect(request.data.ext.marketplace.allowedbidders[1]).to.equal('groupm'); - }); - - it('should be ALL when allowedAlternateBidderCodes is \'*\'', () => { - bidderSettingStub.withArgs('pubmatic', 'allowAlternateBidderCodes').returns(true); - bidderSettingStub.withArgs('pubmatic', 'allowedAlternateBidderCodes').returns(['*']); - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data.ext.marketplace.allowedbidders).to.be.an('array'); - expect(request.data.ext.marketplace.allowedbidders[0]).to.equal('all'); - }); - }); - - describe('SITE', () => { - it('should have site object', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('site'); - }); - - it('should have site object with page, domain', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('site').to.have.property('page').to.equal('https://ebay.com'); - expect(request.data).to.have.property('site').to.have.property('domain').to.equal('ebay.com'); - }); - }); - - describe('DEVICE', () => { - it('should have device object', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('device'); - expect(request.data.device).to.have.property('w').to.equal(1200); - expect(request.data.device).to.have.property('h').to.equal(1800); - expect(request.data.device).to.have.property('js').to.equal(1); - expect(request.data.device).to.have.property('connectiontype'); - expect(request.data.device).to.have.property('language').to.equal('en'); - }); - }); - - describe('CONFIG/BADV', () => { - let copiedBidderRequest; - beforeEach(() => { - copiedBidderRequest = utils.deepClone(bidderRequest); - copiedBidderRequest.ortb2.app = { - id: 'app-id', - name: 'app-name', - }; - copiedBidderRequest.ortb2.site.ext = { - id: 'site-id', - name: 'site-name', - } - copiedBidderRequest.ortb2.badv = ['example.com']; - }); - - it('should have app if it is set in ortb2', () => { - const request = spec.buildRequests(validBidRequests, copiedBidderRequest); - expect(request.data).to.have.property('app'); - }); - - it('should include app if it is defined in ortb2 but not site', () => { - const request = spec.buildRequests(validBidRequests, copiedBidderRequest); - expect(request.data).to.have.property('app'); - expect(request.data).to.not.have.property('site'); - }); - - it('should have badv if it is set in ortb2', () => { - const request = spec.buildRequests(validBidRequests, copiedBidderRequest); - expect(request.data).to.have.property('badv'); - expect(request.data.badv).to.deep.equal(['example.com']); - }); - }); - - describe('AUCTION ID', () => { - it('should use auctionId as wiid when it is not provided in params', () => { - const copiedValidBidRequests = utils.deepClone(validBidRequests); - delete copiedValidBidRequests[0].params.wiid; - const request = spec.buildRequests(copiedValidBidRequests, bidderRequest); - expect(request.data).to.have.property('ext'); - expect(request.data.ext).to.have.property('wrapper'); - expect(request.data.ext.wrapper).to.have.property('wiid'); - expect(request.data.ext.wrapper.wiid).to.equal('ee3074fe-97ce-4681-9235-d7622aede74c'); - }); - - it('should use auctionId as wiid from params', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('ext'); - expect(request.data.ext).to.have.property('wrapper'); - expect(request.data.ext.wrapper).to.have.property('wiid'); - expect(request.data.ext.wrapper.wiid).to.equal('1234567890'); - }); - }); - - describe('GDPR', () => { - let copiedBidderRequest; - beforeEach(() => { - copiedBidderRequest = utils.deepClone(bidderRequest); - copiedBidderRequest.ortb2.user = { - ext: { - consent: 'kjfdniwjnifwenrif3' - } - } - }); - - it('should have GDPR string', () => { - const request = spec.buildRequests(validBidRequests, copiedBidderRequest); - expect(request.data).to.have.property('user'); - expect(request.data.user).to.have.property('ext'); - expect(request.data.user.ext).to.have.property('consent').to.equal('kjfdniwjnifwenrif3'); - }); - }); - - describe('GPP', () => { - it('should have gpp & gpp_sid in request if set using ortb2 and not present in request', () => { - const copiedBidderRequest = utils.deepClone(bidderRequest); - copiedBidderRequest.ortb2.regs = { - gpp: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', - gpp_sid: [5] - } - const request = spec.buildRequests(validBidRequests, copiedBidderRequest); - expect(request.data).to.have.property('regs'); - expect(request.data.regs).to.have.property('gpp').to.equal('DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN'); - expect(request.data.regs).to.have.property('gpp_sid').that.eql([5]); - }); - }); - - describe('DSA', () => { - const dsa = { - dsarequired: 3, - pubrender: 0, - datatopub: 2, - transparency: [ - { - domain: 'platform1domain.com', - dsaparams: [1] - }, - { - domain: 'SSP2domain.com', - dsaparams: [1, 2] - } - ] - }; - beforeEach(() => { - bidderRequest.ortb2.regs = {ext: { dsa }}; - }); - - it('should have DSA in regs.ext', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('regs'); - expect(request.data.regs).to.have.property('ext'); - expect(request.data.regs.ext).to.have.property('dsa').to.deep.equal(dsa); - }); - }); - - describe('ORTB2IMP', () => { - it('should send gpid if specified', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('imp'); - expect(request.data.imp[0]).to.have.property('ext'); - expect(request.data.imp[0].ext).to.have.property('gpid'); - expect(request.data.imp[0].ext.gpid).to.equal('/1111/homepage-leftnav'); - }); - - it('should send pbadslot if specified', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('imp'); - expect(request.data.imp[0]).to.have.property('ext'); - expect(request.data.imp[0].ext).to.have.property('data'); - expect(request.data.imp[0].ext.data).to.have.property('pbadslot'); - expect(request.data.imp[0].ext.data.pbadslot).to.equal('/1111/homepage-leftnav'); - }); - - it('should send adserver if specified', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('imp'); - expect(request.data.imp[0]).to.have.property('ext'); - expect(request.data.imp[0].ext).to.have.property('data'); - expect(request.data.imp[0].ext.data).to.have.property('adserver'); - expect(request.data.imp[0].ext.data.adserver).to.have.property('name'); - expect(request.data.imp[0].ext.data.adserver.name).to.equal('gam'); - expect(request.data.imp[0].ext.data.adserver).to.have.property('adslot'); - expect(request.data.imp[0].ext.data.adserver.adslot).to.equal('/1111/homepage-leftnav'); - }); - - it('should send custom data if specified', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('imp'); - expect(request.data.imp[0]).to.have.property('ext'); - expect(request.data.imp[0].ext).to.have.property('data'); - expect(request.data.imp[0].ext.data).to.have.property('customData'); - expect(request.data.imp[0].ext.data.customData).to.have.property('id').to.equal('id-1'); - }); - }); - - describe('FLEDGE', () => { - it('should not send imp.ext.ae when FLEDGE is disabled, ', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.have.property('imp'); - expect(request.data.imp).to.be.an('array'); - expect(request.data.imp[0]).to.have.property('ext'); - expect(request.data.imp[0].ext).to.not.have.property('ae'); - }); - }) - - describe('cpm adjustment', () => { - beforeEach(() => { - global.cpmAdjustment = {}; - }); - - it('should not perform any action if the bid is undefined', () => { - spec.onBidWon(undefined); - expect(global.cpmAdjustment).to.deep.equal({}); - }); - - it('should not perform any action if the bid is null', () => { - spec.onBidWon(null); - expect(global.cpmAdjustment).to.deep.equal({}); - }); - it('should invoke _calculateBidCpmAdjustment and correctly update cpmAdjustment', () => { - const bid = { - cpm: 2.5, - originalCpm: 3, - originalCurrency: 'USD', - currency: 'USD', - mediaType: 'banner', - meta: { mediaType: 'banner' } - }; - - spec.onBidWon(bid); - expect(cpmAdjustment).to.deep.equal({ - currency: 'USD', - originalCurrency: 'USD', - adjustment: [ - { - cpmAdjustment: Number(((3 - 2.5) / 3).toFixed(2)), // Expected: 0.17 - mediaType: 'banner', - metaMediaType: 'banner', - cpm: 2.5, - originalCpm: 3 - } - ] - }); - }); - - it('should invoke _calculateBidCpmAdjustment and correctly update cpmAdjustment currency is different', () => { - const bid = { - cpm: 2.5, - originalCpm: 3, - originalCurrency: 'USD', - currency: 'EUR', - mediaType: 'banner', - meta: { mediaType: 'banner' }, - getCpmInNewCurrency: function(currency) { - return currency === 'EUR' ? 2.8 : this.cpm; - } - }; - spec.onBidWon(bid); - expect(cpmAdjustment).to.deep.equal({ - currency: 'USD', - originalCurrency: 'USD', - adjustment: [ - { - cpmAdjustment: Number(((3 - 2.5) / 3).toFixed(2)), // Expected: 0.17 - mediaType: 'banner', - metaMediaType: 'banner', - cpm: 2.5, - originalCpm: 3 - } - ] - }); - }); - - it('should replace existing adjustment entry if mediaType and metaMediaType match', () => { - const bid1 = { - cpm: 2.5, - originalCpm: 3, - originalCurrency: 'USD', - currency: 'USD', - mediaType: 'banner', - meta: { mediaType: 'banner' } - }; - const bid2 = { - cpm: 1.5, - originalCpm: 2, - originalCurrency: 'USD', - currency: 'USD', - mediaType: 'banner', - meta: { mediaType: 'banner' } - }; - - spec.onBidWon(bid1); - // Should add the first entry - expect(cpmAdjustment.adjustment.length).to.equal(1); - expect(cpmAdjustment.adjustment[0].cpm).to.equal(2.5); - spec.onBidWon(bid2); - // Should replace the entry, not add a new one - expect(cpmAdjustment.adjustment.length).to.equal(1); - expect(cpmAdjustment.adjustment[0].cpm).to.equal(1.5); - expect(cpmAdjustment.adjustment[0].originalCpm).to.equal(2); - }); - }); - }); - }); - - describe('Response', () => { - it('should parse native adm and set bidResponse.native, width, and height', () => { - // Prepare a valid native bidRequest - const bidRequest = utils.deepClone(validBidRequests[0]); - bidRequest.mediaTypes = { - native: { - title: { required: true, len: 140 } - } - }; - delete bidRequest.mediaTypes.banner; - delete bidRequest.mediaTypes.video; - bidRequest.sizes = undefined; - const request = spec.buildRequests([bidRequest], bidderRequest); - // Prepare a valid native bid response with matching impid - const nativeAdm = JSON.stringify({ native: { assets: [{ id: 1, title: { text: 'Test' } }] } }); - const nativeBid = { - id: 'bid-id', - impid: request.data.imp[0].id, // match the imp id - price: 1.2, - adm: nativeAdm, - w: 123, - h: 456, - adomain: ['example.com'], - mtype: 4 // NATIVE - }; - const seatbid = [{ bid: [nativeBid] }]; - const nativeResponse = { body: { seatbid } }; - const bidResponses = spec.interpretResponse(nativeResponse, request); - expect(bidResponses).to.be.an('array'); - expect(bidResponses[0]).to.exist; - expect(bidResponses[0].native).to.exist; - expect(bidResponses[0].width).to.equal(123); - expect(bidResponses[0].height).to.equal(456); - }); - - it('should handle invalid JSON in native adm gracefully', () => { - // Prepare a valid native bidRequest - const bidRequest = utils.deepClone(validBidRequests[0]); - bidRequest.mediaTypes = { - native: { - title: { required: true, len: 140 } - } - }; - delete bidRequest.mediaTypes.banner; - delete bidRequest.mediaTypes.video; - bidRequest.sizes = undefined; - const request = spec.buildRequests([bidRequest], bidderRequest); - - // Prepare a native bid response with invalid JSON and matching impid - const invalidAdm = '{ native: { assets: [ { id: 1, title: { text: "Test" } } ] }'; // missing closing } - const nativeBid = { - id: 'bid-id', - impid: request.data.imp[0].id, // match the imp id - price: 1.2, - adm: invalidAdm, - w: 123, - h: 456, - adomain: ['example.com'], - mtype: 4 // NATIVE - }; - const seatbid = [{ bid: [nativeBid] }]; - const nativeResponse = { body: { seatbid } }; - const bidResponses = spec.interpretResponse(nativeResponse, request); - expect(bidResponses).to.be.an('array'); - expect(bidResponses.length).to.equal(0); // No bid should be returned if adm is invalid - }); - - it('should set DEFAULT_WIDTH and DEFAULT_HEIGHT when bid.w and bid.h are missing for native', () => { - // Prepare a valid native bidRequest - const bidRequest = utils.deepClone(validBidRequests[0]); - bidRequest.mediaTypes = { - native: { - title: { required: true, len: 140 } - } - }; - delete bidRequest.mediaTypes.banner; - delete bidRequest.mediaTypes.video; - bidRequest.sizes = undefined; - const request = spec.buildRequests([bidRequest], bidderRequest); - // Prepare a native bid response with missing w and h - const nativeAdm = JSON.stringify({ native: { assets: [{ id: 1, title: { text: 'Test' } }] } }); - const nativeBid = { - id: 'bid-id', - impid: request.data.imp[0].id, // match the imp id - price: 1.2, - adm: nativeAdm, - // w and h are intentionally missing - adomain: ['example.com'], - mtype: 4 // NATIVE - }; - const seatbid = [{ bid: [nativeBid] }]; - const nativeResponse = { body: { seatbid } }; - const bidResponses = spec.interpretResponse(nativeResponse, request); - expect(bidResponses).to.be.an('array'); - expect(bidResponses[0]).to.exist; - expect(bidResponses[0].native).to.exist; - expect(bidResponses[0].width).to.equal(0); - expect(bidResponses[0].height).to.equal(0); - }); - - it('should return response in prebid format', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const bidResponse = spec.interpretResponse(response, request); - expect(bidResponse).to.be.an('array'); - expect(bidResponse[0]).to.be.an('object'); - expect(bidResponse[0]).to.have.property('ad'); - expect(bidResponse[0]).to.have.property('dealId'); - expect(bidResponse[0]).to.have.property('dealChannel'); - expect(bidResponse[0]).to.have.property('currency'); - expect(bidResponse[0]).to.have.property('meta'); - expect(bidResponse[0]).to.have.property('mediaType'); - expect(bidResponse[0]).to.have.property('referrer'); - expect(bidResponse[0]).to.have.property('cpm'); - expect(bidResponse[0]).to.have.property('pm_seat'); - expect(bidResponse[0]).to.have.property('pm_dspid'); - expect(bidResponse[0]).to.have.property('sspID'); - expect(bidResponse[0]).to.have.property('partnerImpId'); - expect(bidResponse[0]).to.have.property('requestId'); - expect(bidResponse[0]).to.have.property('width'); - expect(bidResponse[0]).to.have.property('height'); - expect(bidResponse[0]).to.have.property('ttl'); - expect(bidResponse[0]).to.have.property('netRevenue'); - expect(bidResponse[0]).to.have.property('creativeId'); - }); - - it('should return response and match with input values', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const bidResponse = spec.interpretResponse(response, request); - expect(bidResponse).to.be.an('array'); - expect(bidResponse[0]).to.be.an('object'); - expect(bidResponse[0]).to.have.property('currency').to.be.equal('USD'); - expect(bidResponse[0]).to.have.property('dealId').to.equal('PUBDEAL1'); - expect(bidResponse[0]).to.have.property('dealChannel').to.equal('PMPG'); - expect(bidResponse[0]).to.have.property('meta').to.be.an('object'); - expect(bidResponse[0]).to.have.property('mediaType').to.equal('banner'); - expect(bidResponse[0]).to.have.property('cpm').to.equal(1.3); - expect(bidResponse[0]).to.have.property('pm_seat').to.equal('seat-id'); - expect(bidResponse[0]).to.have.property('pm_dspid').to.equal(123); - expect(bidResponse[0]).to.have.property('sspID').to.equal('74858439-49D7-4169-BA5D-44A046315B2F'); - expect(bidResponse[0]).to.have.property('requestId').to.equal('3736271c3c4b27'); - expect(bidResponse[0]).to.have.property('width').to.equal(300); - expect(bidResponse[0]).to.have.property('height').to.equal(250); - expect(bidResponse[0]).to.have.property('ttl').to.equal(360); - }); - - describe('DEALID', () => { - it('should set deal_channel to PMP if ext.deal_channel is missing', () => { - const copiedResponse = utils.deepClone(response); - delete copiedResponse.body.seatbid[0].bid[0].ext.deal_channel; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const bidResponse = spec.interpretResponse(copiedResponse, request); - expect(bidResponse).to.be.an('array'); - expect(bidResponse[0]).to.be.an('object'); - expect(bidResponse[0]).to.have.property('dealChannel').to.equal('PMP'); - }); - - it('should exclude deal_id and deal_channel from the response if the deal id is missing', () => { - const copiedResponse = utils.deepClone(response); - delete copiedResponse.body.seatbid[0].bid[0].ext.deal_channel; - delete copiedResponse.body.seatbid[0].bid[0].dealid; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const bidResponse = spec.interpretResponse(copiedResponse, request); - expect(bidResponse).to.be.an('array'); - expect(bidResponse[0]).to.be.an('object'); - expect(bidResponse[0]).to.not.have.property('dealId'); - expect(bidResponse[0]).to.not.have.property('dealChannel'); - }); - }); - if (FEATURES.VIDEO) { - describe('VIDEO', () => { - beforeEach(() => { - const videoBidderRequest = utils.deepClone(bidderRequest); - delete videoBidderRequest.bids[0].mediaTypes.banner; - videoBidderRequest.bids[0].mediaTypes.video = { - skip: 1, - mimes: ['video/mp4', 'video/x-flv'], - minduration: 5, - maxduration: 30, - startdelay: 5, - playbackmethod: [1, 3], - api: [1, 2], - protocols: [2, 3], - battr: [13, 14], - linearity: 1, - placement: 2, - plcmt: 1, - context: 'outstream', - minbitrate: 10, - maxbitrate: 10, - playerSize: [640, 480] - } - videoBidderRequest.bids[0].params.outstreamAU = 'outstreamAU'; - videoBidderRequest.bids[0].params.renderer = 'renderer_test_pubmatic'; - videoBidderRequest.bids[0].adUnitCode = 'Div1'; - }); - - it('should generate video response', () => { - const request = spec.buildRequests(validBidRequests, videoBidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('video'); - const bidResponse = spec.interpretResponse(videoResponse, request); - expect(bidResponse).to.be.an('array'); - expect(bidResponse[0]).to.be.an('object'); - expect(bidResponse[0]).to.have.property('vastXml'); - expect(bidResponse[0]).to.have.property('mediaType'); - expect(bidResponse[0]).to.have.property('playerHeight'); - expect(bidResponse[0]).to.have.property('playerWidth'); - }); - - it('should generate video response with input values', () => { - const request = spec.buildRequests(validBidRequests, videoBidderRequest); - const { imp } = request?.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('video'); - const bidResponse = spec.interpretResponse(videoResponse, request); - expect(bidResponse).to.be.an('array'); - expect(bidResponse[0]).to.be.an('object'); - expect(bidResponse[0]).to.have.property('mediaType').to.equal('video'); - expect(bidResponse[0]).to.have.property('playerHeight').to.equal(480); - expect(bidResponse[0]).to.have.property('playerWidth').to.equal(640); - }); - - it('should set renderer and rendererCode for outstream video with outstreamAU', () => { - const request = spec.buildRequests(validBidRequests, videoBidderRequest); - const bidResponse = spec.interpretResponse(videoResponse, request); - expect(bidResponse).to.be.an('array'); - expect(bidResponse[0]).to.be.an('object'); - expect(bidResponse[0]).to.have.property('renderer'); - expect(bidResponse[0].renderer).to.be.an('object'); - expect(bidResponse[0]).to.have.property('rendererCode').to.equal('outstreamAU'); - }); - - it('should set width and height from playerWidth/playerHeight if not present in bid', () => { - // Clone and modify the video response to remove w and h - const modifiedVideoResponse = utils.deepClone(videoResponse); - delete modifiedVideoResponse.body.seatbid[0].bid[0].w; - delete modifiedVideoResponse.body.seatbid[0].bid[0].h; - // Set up the request as usual - const request = spec.buildRequests(validBidRequests, videoBidderRequest); - // Interpret the response - const bidResponses = spec.interpretResponse(modifiedVideoResponse, request); - // playerWidth = 640, playerHeight = 480 from playerSize in the test setup - expect(bidResponses[0].width).to.equal(640); - expect(bidResponses[0].height).to.equal(480); - }); - }); - } - - describe('CATEGORY IDS', () => { - it('should set primaryCatId and secondaryCatIds in meta when bid.cat is present', () => { - const copiedResponse = utils.deepClone(response); - copiedResponse.body.seatbid[0].bid[0].cat = ['IAB1', 'IAB2', 'IAB3']; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const bidResponse = spec.interpretResponse(copiedResponse, request); - expect(bidResponse).to.be.an('array'); - expect(bidResponse[0]).to.be.an('object'); - expect(bidResponse[0].meta).to.have.property('primaryCatId').to.equal('IAB1'); - expect(bidResponse[0].meta).to.have.property('secondaryCatIds').to.deep.equal(['IAB1', 'IAB2', 'IAB3']); - }); - - it('should not set primaryCatId and secondaryCatIds in meta when bid.cat is null', () => { - const copiedResponse = utils.deepClone(response); - copiedResponse.body.seatbid[0].bid[0].cat = null; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const bidResponse = spec.interpretResponse(copiedResponse, request); - expect(bidResponse).to.be.an('array'); - expect(bidResponse[0]).to.be.an('object'); - expect(bidResponse[0].meta).to.not.have.property('primaryCatId'); - expect(bidResponse[0].meta).to.not.have.property('secondaryCatIds'); - }); - - it('should not set primaryCatId and secondaryCatIds in meta when bid.cat is undefined', () => { - const copiedResponse = utils.deepClone(response); - delete copiedResponse.body.seatbid[0].bid[0].cat; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const bidResponse = spec.interpretResponse(copiedResponse, request); - expect(bidResponse).to.be.an('array'); - expect(bidResponse[0]).to.be.an('object'); - expect(bidResponse[0].meta).to.not.have.property('primaryCatId'); - expect(bidResponse[0].meta).to.not.have.property('secondaryCatIds'); - }); - }); - - describe('getUserSyncs', () => { - beforeEach(() => { - spec.buildRequests(validBidRequests, bidderRequest); - }); - - afterEach(() => { - config.resetConfig(); - }); - - it('returns iframe sync url with consent parameters and COPPA', () => { - config.setConfig({ coppa: true }); - const gdprConsent = { gdprApplies: true, consentString: 'CONSENT' }; - const uspConsent = '1YNN'; - const gppConsent = { gppString: 'GPP', applicableSections: [2, 4] }; - const [sync] = spec.getUserSyncs({ iframeEnabled: true }, [], gdprConsent, uspConsent, gppConsent); - expect(sync).to.deep.equal({ - type: 'iframe', - url: 'https://ads.pubmatic.com/AdServer/js/user_sync.html?kdntuid=1&p=5670&gdpr=1&gdpr_consent=CONSENT&us_privacy=1YNN&gpp=GPP&gpp_sid=2%2C4&coppa=1' - }); - }); - - it('returns image sync url when no consent data provided', () => { - const [sync] = spec.getUserSyncs({}, []); - expect(sync).to.deep.equal({ - type: 'image', - url: 'https://image8.pubmatic.com/AdServer/ImgSync?p=5670' - }); - }); - }); - }) - - it('should add userIdAsEids to user.ext.eids when present in bidRequest', () => { - const bidRequestWithEids = utils.deepClone(validBidRequests[0]); - bidRequestWithEids.userIdAsEids = [ - { - source: 'pubmatic', - uids: [{ id: 'test-id-123' }] - } - ]; - // Create a clean bidderRequest without existing eids - const cleanBidderRequest = utils.deepClone(bidderRequest); - // Ensure user object exists - cleanBidderRequest.user = cleanBidderRequest.user || {}; - cleanBidderRequest.user.ext = cleanBidderRequest.user.ext || {}; - delete cleanBidderRequest.user.ext.eids; - // Also set userIdAsEids on the bidderRequest.bids[0] like MediaKeys test - cleanBidderRequest.bids[0].userIdAsEids = bidRequestWithEids.userIdAsEids; - const request = spec.buildRequests([bidRequestWithEids], cleanBidderRequest); - expect(request.data.user).to.exist; - expect(request.data.user.ext).to.exist; - expect(request.data.user.ext.eids).to.deep.equal(bidRequestWithEids.userIdAsEids); - }); - it('should not add userIdAsEids when req.user.ext.eids already exists', () => { - const bidRequestWithEids = utils.deepClone(validBidRequests[0]); - bidRequestWithEids.userIdAsEids = [ - { - source: 'pubmatic', - uids: [{ id: 'test-id-123' }] - } - ]; - // Create a bidderRequest with existing eids - const bidderRequestWithExistingEids = utils.deepClone(bidderRequest); - // Ensure user object exists and set existing eids - bidderRequestWithExistingEids.user = bidderRequestWithExistingEids.user || {}; - bidderRequestWithExistingEids.user.ext = bidderRequestWithExistingEids.user.ext || {}; - bidderRequestWithExistingEids.user.ext.eids = [{ source: 'existing', uids: [{ id: 'existing-id' }] }]; - // Also set userIdAsEids on the bidderRequest.bids[0] like MediaKeys test - bidderRequestWithExistingEids.bids[0].userIdAsEids = bidRequestWithEids.userIdAsEids; - // Set existing eids in ortb2.user.ext.eids so the converter will merge them - // and the adapter will see them as already existing - bidderRequestWithExistingEids.ortb2 = bidderRequestWithExistingEids.ortb2 || {}; - bidderRequestWithExistingEids.ortb2.user = bidderRequestWithExistingEids.ortb2.user || {}; - bidderRequestWithExistingEids.ortb2.user.ext = bidderRequestWithExistingEids.ortb2.user.ext || {}; - bidderRequestWithExistingEids.ortb2.user.ext.eids = [{ source: 'existing', uids: [{ id: 'existing-id' }] }]; - const request = spec.buildRequests([bidRequestWithEids], bidderRequestWithExistingEids); - expect(request.data.user).to.exist; - expect(request.data.user.ext).to.exist; - expect(request.data.user.ext.eids).to.deep.equal(bidderRequestWithExistingEids.ortb2.user.ext.eids); - }); - - it('should copy geo from device to user when device has geo but user does not', () => { - const bidRequestWithDeviceGeo = utils.deepClone(validBidRequests[0]); - // Create a clean bidderRequest without existing geo data - const cleanBidderRequest = utils.deepClone(bidderRequest); - // Ensure user and device objects exist - cleanBidderRequest.user = cleanBidderRequest.user || {}; - cleanBidderRequest.ortb2 = cleanBidderRequest.ortb2 || {}; - cleanBidderRequest.ortb2.user = cleanBidderRequest.ortb2.user || {}; - cleanBidderRequest.ortb2.device = cleanBidderRequest.ortb2.device || {}; - delete cleanBidderRequest.user.geo; - delete cleanBidderRequest.ortb2.user.geo; - // Set geo data in bidderRequest.ortb2.device.geo so the converter will merge it - cleanBidderRequest.ortb2.device.geo = { lat: 40.7128, lon: -74.0060 }; - const request = spec.buildRequests([bidRequestWithDeviceGeo], cleanBidderRequest); - expect(request.data.user).to.exist; - expect(request.data.user.geo).to.deep.equal({ lat: 40.7128, lon: -74.0060 }); - }); - - it('should copy geo from user to device when user has geo but device does not', () => { - const bidRequestWithUserGeo = utils.deepClone(validBidRequests[0]); - // Create a clean bidderRequest without existing geo data - const cleanBidderRequest = utils.deepClone(bidderRequest); - // Ensure device object exists - cleanBidderRequest.device = cleanBidderRequest.device || {}; - cleanBidderRequest.ortb2 = cleanBidderRequest.ortb2 || {}; - cleanBidderRequest.ortb2.device = cleanBidderRequest.ortb2.device || {}; - cleanBidderRequest.ortb2.user = cleanBidderRequest.ortb2.user || {}; - delete cleanBidderRequest.device.geo; - delete cleanBidderRequest.ortb2.device.geo; - // Set geo data in bidderRequest.ortb2.user.geo so the converter will merge it - cleanBidderRequest.ortb2.user.geo = { lat: 40.7128, lon: -74.0060 }; - const request = spec.buildRequests([bidRequestWithUserGeo], cleanBidderRequest); - expect(request.data.device).to.exist; - expect(request.data.device.geo).to.deep.equal({ lat: 40.7128, lon: -74.0060 }); - }); - - it('should update site.page with kadpageurl when present', () => { - const bidRequestWithKadPageUrl = utils.deepClone(validBidRequests[0]); - bidRequestWithKadPageUrl.params.kadpageurl = 'https://example.com/page'; - const request = spec.buildRequests([bidRequestWithKadPageUrl], bidderRequest); - expect(request.data.site).to.exist; - expect(request.data.site.page).to.equal('https://example.com/page'); - }); - - describe('Impression optimization', () => { - it('should add pbcode to impression ext with adUnitCode value', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const { imp } = request?.data; - - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('ext'); - expect(imp[0].ext).to.have.property('pbcode'); - expect(imp[0].ext.pbcode).to.equal(validBidRequests[0].adUnitCode); - }); - - it('should consolidate impressions with same adUnitCode and media type', () => { - // Create two banner bids with the same adUnitCode - const bid1 = utils.deepClone(validBidRequests[0]); - const bid2 = utils.deepClone(validBidRequests[0]); - - bid1.bidId = 'bid-id-1'; - bid2.bidId = 'bid-id-2'; - - // Set the same adUnitCode and adSlot to ensure they're treated as the same unit - const sharedAdUnitCode = 'shared-ad-unit'; - bid1.adUnitCode = sharedAdUnitCode; - bid2.adUnitCode = sharedAdUnitCode; - bid1.params.adSlot = 'same_ad_slot'; - bid2.params.adSlot = 'same_ad_slot'; - - bid1.mediaTypes = { banner: { sizes: [[300, 250]] } }; - bid2.mediaTypes = { banner: { sizes: [[300, 250]] } }; - - bid1.params.pmzoneid = 'zone1'; - bid2.params.pmzoneid = 'zone2'; - - const bidRequests = [bid1, bid2]; - const combinedBidderRequest = utils.deepClone(bidderRequest); - combinedBidderRequest.bids = bidRequests; - - const request = spec.buildRequests(bidRequests, combinedBidderRequest); - const { imp } = request?.data; - - // Should be consolidated to a single impression - expect(imp).to.be.an('array'); - expect(imp).to.have.lengthOf(1); - - expect(imp[0].ext).to.have.property('pbcode'); - expect(imp[0].ext.pbcode).to.equal(sharedAdUnitCode); - - if (imp[0].ext.pmZoneId) { - expect(typeof imp[0].ext.pmZoneId).to.equal('string'); - expect(imp[0].ext.pmZoneId).to.equal('zone2'); - } - }); - }); - - it('should set site.publisher.id from pubId', () => { - // Ensure site.publisher structure exists in bidderRequest.ortb2 - const bidderRequestWithPublisher = utils.deepClone(bidderRequest); - bidderRequestWithPublisher.ortb2 = bidderRequestWithPublisher.ortb2 || {}; - bidderRequestWithPublisher.ortb2.site = bidderRequestWithPublisher.ortb2.site || {}; - bidderRequestWithPublisher.ortb2.site.publisher = bidderRequestWithPublisher.ortb2.site.publisher || {}; - const request = spec.buildRequests(validBidRequests, bidderRequestWithPublisher); - expect(request.data.site).to.exist; - expect(request.data.site.publisher).to.exist; - expect(request.data.site.publisher.id).to.equal('5670'); // pubId from params - }); - - it('should set site.ref from refURL when not already present', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data.site).to.exist; - // Check if site.ref exists (it might be set to empty string or undefined) - if (request.data.site.ref !== undefined) { - expect(request.data.site.ref).to.exist; - } - }); - - it('should build a basic request successfully', () => { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.data).to.exist; - expect(request.data.imp).to.be.an('array'); - expect(request.data.imp.length).to.be.greaterThan(0); - }); - - it('should set floor values correctly for multi-format requests using getFloor', () => { - // Start with a valid bid - const testBid = utils.deepClone(validBidRequests[0]); - testBid.mediaTypes = { - banner: { - sizes: [[300, 250], [728, 90]], - format: [{ w: 300, h: 250 }, { w: 728, h: 90 }] - }, - video: {}, - native: {} - }; - testBid.getFloor = ({ currency, mediaType, size }) => { - if (mediaType === 'banner') return { currency: 'AUD', floor: 2.5 }; - if (mediaType === 'video') return { currency: 'AUD', floor: 1.5 }; - if (mediaType === 'native') return { currency: 'AUD', floor: 1.0 }; - return { currency: 'AUD', floor: 0 }; - }; - const testBidderRequest = { - bids: [testBid], - auctionId: 'test-auction', - bidderCode: 'pubmatic', - refererInfo: { page: 'https://example.com', ref: '' }, - ortb2: { device: { w: 1200, h: 1800 }, site: { domain: 'example.com', page: 'https://example.com' } }, - timeout: 2000 - }; - const request = spec.buildRequests([testBid], testBidderRequest); - expect(request).to.exist; - const builtImp = request.data.imp[0]; - if (builtImp.banner && builtImp.banner.ext) { - expect(builtImp.banner.ext).to.deep.equal({ bidfloor: 1, bidfloorcur: 'AUD' }); - } - if (builtImp.video && builtImp.video.ext) { - expect(builtImp.video.ext).to.deep.equal({ bidfloor: 1, bidfloorcur: 'AUD' }); - } - if (builtImp.native && builtImp.native.ext) { - expect(builtImp.native.ext).to.deep.equal({ bidfloor: 1, bidfloorcur: 'AUD' }); - } - // The impression-level bidfloor should match the banner floor (2.5) - expect(builtImp.bidfloor).to.equal(2.5); - }); -}) - -describe('addViewabilityToImp', () => { - let imp; - let element; - let originalGetElementById; - let originalVisibilityState; - let sandbox; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - imp = { ext: {} }; - element = document.createElement('div'); - element.id = 'Div1'; - document.body.appendChild(element); - originalGetElementById = document.getElementById; - sandbox.stub(document, 'getElementById').callsFake(id => id === 'Div1' ? element : null); - originalVisibilityState = document.visibilityState; - Object.defineProperty(document, 'visibilityState', { - value: 'visible', - configurable: true - }); - sandbox.stub(utils, 'getWindowTop').returns(window); - }); - - afterEach(() => { - sandbox.restore(); - document.body.removeChild(element); - Object.defineProperty(document, 'visibilityState', { - value: originalVisibilityState, - configurable: true - }); - document.getElementById = originalGetElementById; - }); - - it('should add viewability to imp.ext when measurable', () => { - addViewabilityToImp(imp, 'Div1', { w: 300, h: 250 }); - expect(imp.ext).to.have.property('viewability'); - }); - - it('should set viewability amount to "na" if not measurable (e.g., in iframe)', () => { - const isIframeStub = sandbox.stub(utils, 'inIframe').returns(true); - addViewabilityToImp(imp, 'Div1', { w: 300, h: 250 }); - expect(imp.ext).to.have.property('viewability'); - expect(imp.ext.viewability.amount).to.equal('na'); - }); - - it('should not add viewability if element is not found', () => { - document.getElementById.restore(); - sandbox.stub(document, 'getElementById').returns(null); - addViewabilityToImp(imp, 'Div1', { w: 300, h: 250 }); - expect(imp.ext).to.not.have.property('viewability'); - }); - - it('should create imp.ext if not present', () => { - imp = {}; - addViewabilityToImp(imp, 'Div1', { w: 300, h: 250 }); - expect(imp.ext).to.exist; - expect(imp.ext).to.have.property('viewability'); - }); -}); diff --git a/test/spec/modules/pubmaticRtdProvider_spec.js b/test/spec/modules/pubmaticRtdProvider_spec.js deleted file mode 100644 index 830fd585d..000000000 --- a/test/spec/modules/pubmaticRtdProvider_spec.js +++ /dev/null @@ -1,1243 +0,0 @@ -import { expect } from 'chai'; -import * as priceFloors from '../../../modules/priceFloors.js'; -import * as utils from '../../../src/utils.js'; -import * as suaModule from '../../../src/fpd/sua.js'; -import { config as conf } from '../../../src/config.js'; -import * as hook from '../../../src/hook.js'; -import * as prebidGlobal from '../../../src/prebidGlobal.js'; -import { - registerSubModule, pubmaticSubmodule, getFloorsConfig, fetchData, - getCurrentTimeOfDay, getBrowserType, getOs, getDeviceType, getCountry, getUtm, getBidder, _country, - _profileConfigs, _floorsData, defaultValueTemplate, withTimeout, configMerged, - getProfileConfigs, setProfileConfigs, getTargetingData -} from '../../../modules/pubmaticRtdProvider.js'; -import sinon from 'sinon'; - -describe('Pubmatic RTD Provider', () => { - let sandbox; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - sandbox.stub(conf, 'getConfig').callsFake(() => { - return { - floors: { - 'enforcement': { - 'floorDeals': true, - 'enforceJS': true - } - }, - realTimeData: { - auctionDelay: 100 - } - }; - }); - }); - - afterEach(() => { - sandbox.restore(); - }); - - describe('registerSubModule', () => { - it('should register RTD submodule provider', () => { - const submoduleStub = sinon.stub(hook, 'submodule'); - registerSubModule(); - assert(submoduleStub.calledOnceWith('realTimeData', pubmaticSubmodule)); - submoduleStub.restore(); - }); - }); - - describe('submodule', () => { - describe('name', () => { - it('should be pubmatic', () => { - expect(pubmaticSubmodule.name).to.equal('pubmatic'); - }); - }); - }); - - describe('init', () => { - let logErrorStub; - let continueAuctionStub; - - const getConfig = () => ({ - params: { - publisherId: 'test-publisher-id', - profileId: 'test-profile-id' - }, - }); - - beforeEach(() => { - logErrorStub = sandbox.stub(utils, 'logError'); - continueAuctionStub = sandbox.stub(priceFloors, 'continueAuction'); - }); - - it('should return false if publisherId is missing', () => { - const config = { - params: { - profileId: 'test-profile-id' - } - }; - expect(pubmaticSubmodule.init(config)).to.be.false; - }); - - it('should return false if profileId is missing', () => { - const config = { - params: { - publisherId: 'test-publisher-id' - } - }; - expect(pubmaticSubmodule.init(config)).to.be.false; - }); - - it('should accept numeric publisherId by converting to string', () => { - const config = { - params: { - publisherId: 123, - profileId: 'test-profile-id' - } - }; - expect(pubmaticSubmodule.init(config)).to.be.true; - }); - - it('should accept numeric profileId by converting to string', () => { - const config = { - params: { - publisherId: 'test-publisher-id', - profileId: 345 - } - }; - expect(pubmaticSubmodule.init(config)).to.be.true; - }); - - it('should initialize successfully with valid config', () => { - expect(pubmaticSubmodule.init(getConfig())).to.be.true; - }); - - it('should handle empty config object', () => { - expect(pubmaticSubmodule.init({})).to.be.false; - expect(logErrorStub.calledWith(sinon.match(/Missing publisher Id/))).to.be.true; - }); - - it('should return false if continueAuction is not a function', () => { - continueAuctionStub.value(undefined); - expect(pubmaticSubmodule.init(getConfig())).to.be.false; - expect(logErrorStub.calledWith(sinon.match(/continueAuction is not a function/))).to.be.true; - }); - }); - - describe('getCurrentTimeOfDay', () => { - let clock; - - beforeEach(() => { - clock = sandbox.useFakeTimers(new Date('2024-01-01T12:00:00')); // Set fixed time for testing - }); - - afterEach(() => { - clock.restore(); - }); - - const testTimes = [ - { hour: 6, expected: 'morning' }, - { hour: 13, expected: 'afternoon' }, - { hour: 18, expected: 'evening' }, - { hour: 22, expected: 'night' }, - { hour: 4, expected: 'night' } - ]; - - testTimes.forEach(({ hour, expected }) => { - it(`should return ${expected} at ${hour}:00`, () => { - clock.setSystemTime(new Date().setHours(hour)); - const result = getCurrentTimeOfDay(); - expect(result).to.equal(expected); - }); - }); - }); - - describe('getBrowserType', () => { - let userAgentStub, getLowEntropySUAStub; - - const USER_AGENTS = { - chrome: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', - firefox: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:89.0) Gecko/20100101 Firefox/89.0', - edge: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Edg/91.0.864.67 Safari/537.36', - safari: 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0.6 Mobile/15E148 Safari/604.1', - ie: 'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; Trident/6.0)', - opera: 'Opera/9.80 (Windows NT 6.1; WOW64) Presto/2.12.388 Version/12.16', - unknown: 'UnknownBrowser/1.0' - }; - - beforeEach(() => { - userAgentStub = sandbox.stub(navigator, 'userAgent'); - getLowEntropySUAStub = sandbox.stub(suaModule, 'getLowEntropySUA').returns(undefined); - }); - - afterEach(() => { - userAgentStub.restore(); - getLowEntropySUAStub.restore(); - }); - - it('should detect Chrome', () => { - userAgentStub.value(USER_AGENTS.chrome); - expect(getBrowserType()).to.equal('9'); - }); - - it('should detect Firefox', () => { - userAgentStub.value(USER_AGENTS.firefox); - expect(getBrowserType()).to.equal('12'); - }); - - it('should detect Edge', () => { - userAgentStub.value(USER_AGENTS.edge); - expect(getBrowserType()).to.equal('2'); - }); - - it('should detect Internet Explorer', () => { - userAgentStub.value(USER_AGENTS.ie); - expect(getBrowserType()).to.equal('4'); - }); - - it('should detect Opera', () => { - userAgentStub.value(USER_AGENTS.opera); - expect(getBrowserType()).to.equal('3'); - }); - - it('should return 0 for unknown browser', () => { - userAgentStub.value(USER_AGENTS.unknown); - expect(getBrowserType()).to.equal('0'); - }); - - it('should return -1 when userAgent is null', () => { - userAgentStub.value(null); - expect(getBrowserType()).to.equal('-1'); - }); - }); - - describe('Utility functions', () => { - it('should set browser correctly', () => { - expect(getBrowserType()).to.be.a('string'); - }); - - it('should set OS correctly', () => { - expect(getOs()).to.be.a('string'); - }); - - it('should set device type correctly', () => { - expect(getDeviceType()).to.be.a('string'); - }); - - it('should set time of day correctly', () => { - expect(getCurrentTimeOfDay()).to.be.a('string'); - }); - - it('should set country correctly', () => { - expect(getCountry()).to.satisfy(value => typeof value === 'string' || value === undefined); - }); - - it('should set UTM correctly', () => { - expect(getUtm()).to.be.a('string'); - expect(getUtm()).to.be.oneOf(['0', '1']); - }); - - it('should extract bidder correctly', () => { - expect(getBidder({ bidder: 'pubmatic' })).to.equal('pubmatic'); - expect(getBidder({})).to.be.undefined; - expect(getBidder(null)).to.be.undefined; - expect(getBidder(undefined)).to.be.undefined; - }); - }); - - describe('getFloorsConfig', () => { - let floorsData, profileConfigs; - let sandbox; - let logErrorStub; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - logErrorStub = sandbox.stub(utils, 'logError'); - floorsData = { - "currency": "USD", - "floorProvider": "PM", - "floorsSchemaVersion": 2, - "modelGroups": [ - { - "modelVersion": "M_1", - "modelWeight": 100, - "schema": { - "fields": [ - "domain" - ] - }, - "values": { - "*": 2.00 - } - } - ], - "skipRate": 0 - }; - profileConfigs = { - 'plugins': { - 'dynamicFloors': { - 'enabled': true, - 'config': { - 'enforcement': { - 'floorDeals': false, - 'enforceJS': false - }, - 'floorMin': 0.1111, - 'skipRate': 11, - 'defaultValues': { - "*|*": 0.2 - } - } - } - } - } - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should return correct config structure', () => { - const result = getFloorsConfig(floorsData, profileConfigs); - - expect(result.floors).to.be.an('object'); - expect(result.floors).to.be.an('object'); - expect(result.floors).to.have.property('enforcement'); - expect(result.floors.enforcement).to.have.property('floorDeals', false); - expect(result.floors.enforcement).to.have.property('enforceJS', false); - expect(result.floors).to.have.property('floorMin', 0.1111); - - // Verify the additionalSchemaFields structure - expect(result.floors.additionalSchemaFields).to.have.all.keys([ - 'deviceType', - 'timeOfDay', - 'browser', - 'os', - 'country', - 'utm', - 'bidder' - ]); - - Object.values(result.floors.additionalSchemaFields).forEach(field => { - expect(field).to.be.a('function'); - }); - }); - - it('should return undefined when plugin is disabled', () => { - profileConfigs.plugins.dynamicFloors.enabled = false; - const result = getFloorsConfig(floorsData, profileConfigs); - - expect(result).to.equal(undefined); - }); - - it('should initialise default values to empty object when not available', () => { - profileConfigs.plugins.dynamicFloors.config.defaultValues = undefined; - floorsData = undefined; - const result = getFloorsConfig(floorsData, profileConfigs); - - expect(result.floors.data).to.have.property('currency', 'USD'); - expect(result.floors.data).to.have.property('skipRate', 11); - expect(result.floors.data.schema).to.deep.equal(defaultValueTemplate.schema); - expect(result.floors.data.value).to.deep.equal(defaultValueTemplate.value); - }); - - it('should replace skipRate from config to data when avaialble', () => { - const result = getFloorsConfig(floorsData, profileConfigs); - - expect(result.floors.data).to.have.property('skipRate', 11); - }); - - it('should not replace skipRate from config to data when not avaialble', () => { - delete profileConfigs.plugins.dynamicFloors.config.skipRate; - const result = getFloorsConfig(floorsData, profileConfigs); - - expect(result.floors.data).to.have.property('skipRate', 0); - }); - - it('should maintain correct function references', () => { - const result = getFloorsConfig(floorsData, profileConfigs); - - expect(result.floors.additionalSchemaFields.deviceType).to.equal(getDeviceType); - expect(result.floors.additionalSchemaFields.timeOfDay).to.equal(getCurrentTimeOfDay); - expect(result.floors.additionalSchemaFields.browser).to.equal(getBrowserType); - expect(result.floors.additionalSchemaFields.os).to.equal(getOs); - expect(result.floors.additionalSchemaFields.country).to.equal(getCountry); - expect(result.floors.additionalSchemaFields.utm).to.equal(getUtm); - expect(result.floors.additionalSchemaFields.bidder).to.equal(getBidder); - }); - - it('should log error when profileConfigs is not an object', () => { - profileConfigs = 'invalid'; - const result = getFloorsConfig(floorsData, profileConfigs); - expect(result).to.be.undefined; - expect(logErrorStub.calledWith(sinon.match(/profileConfigs is not an object or is empty/))).to.be.true; - }); - }); - - describe('fetchData for configs', () => { - let logErrorStub; - let fetchStub; - let confStub; - - beforeEach(() => { - logErrorStub = sandbox.stub(utils, 'logError'); - fetchStub = sandbox.stub(window, 'fetch'); - confStub = sandbox.stub(conf, 'setConfig'); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should successfully fetch profile configs', async () => { - const mockApiResponse = { - "profileName": "profie name", - "desc": "description", - "plugins": { - "dynamicFloors": { - "enabled": false - } - } - }; - - fetchStub.resolves(new Response(JSON.stringify(mockApiResponse), { status: 200 })); - - const result = await fetchData('1234', '123', 'CONFIGS'); - expect(result).to.deep.equal(mockApiResponse); - }); - - it('should log error when JSON parsing fails', async () => { - fetchStub.resolves(new Response('Invalid JSON', { status: 200 })); - - await fetchData('1234', '123', 'CONFIGS'); - expect(logErrorStub.calledWith(sinon.match(/Error while fetching\s*CONFIGS/))).to.be.true; - }); - - it('should log error when response is not ok', async () => { - fetchStub.resolves(new Response(null, { status: 500 })); - - await fetchData('1234', '123', 'CONFIGS'); - expect(logErrorStub.calledWith(sinon.match(/Error while fetching\s*CONFIGS/))).to.be.true; - }); - - it('should log error on network failure', async () => { - fetchStub.rejects(new Error('Network Error')); - - await fetchData('1234', '123', 'CONFIGS'); - expect(logErrorStub.called).to.be.true; - expect(logErrorStub.calledWith(sinon.match(/Error while fetching\s*CONFIGS/))).to.be.true; - }); - }); - - describe('fetchData for floors', () => { - let logErrorStub; - let fetchStub; - let confStub; - - beforeEach(() => { - logErrorStub = sandbox.stub(utils, 'logError'); - fetchStub = sandbox.stub(window, 'fetch'); - confStub = sandbox.stub(conf, 'setConfig'); - global._country = undefined; - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should successfully fetch and parse floor rules', async () => { - const mockApiResponse = { - data: { - currency: 'USD', - modelGroups: [], - values: {} - } - }; - - fetchStub.resolves(new Response(JSON.stringify(mockApiResponse), { status: 200, headers: { 'country_code': 'US' } })); - - const result = await fetchData('1234', '123', 'FLOORS'); - expect(result).to.deep.equal(mockApiResponse); - expect(_country).to.equal('US'); - }); - - it('should correctly extract the first unique country code from response headers', async () => { - fetchStub.resolves(new Response(JSON.stringify({}), { - status: 200, - headers: { 'country_code': 'US,IN,US' } - })); - - await fetchData('1234', '123', 'FLOORS'); - expect(_country).to.equal('US'); - }); - - it('should set _country to undefined if country_code header is missing', async () => { - fetchStub.resolves(new Response(JSON.stringify({}), { - status: 200 - })); - - await fetchData('1234', '123', 'FLOORS'); - expect(_country).to.be.undefined; - }); - - it('should log error when JSON parsing fails', async () => { - fetchStub.resolves(new Response('Invalid JSON', { status: 200 })); - - await fetchData('1234', '123', 'FLOORS'); - expect(logErrorStub.calledWith(sinon.match(/Error while fetching\s*FLOORS/))).to.be.true; - }); - - it('should log error when response is not ok', async () => { - fetchStub.resolves(new Response(null, { status: 500 })); - - await fetchData('1234', '123', 'FLOORS'); - expect(logErrorStub.calledWith(sinon.match(/Error while fetching\s*FLOORS/))).to.be.true; - }); - - it('should log error on network failure', async () => { - fetchStub.rejects(new Error('Network Error')); - - await fetchData('1234', '123', 'FLOORS'); - expect(logErrorStub.called).to.be.true; - expect(logErrorStub.calledWith(sinon.match(/Error while fetching\s*FLOORS/))).to.be.true; - }); - }); - - describe('getBidRequestData', function () { - let callback, continueAuctionStub, mergeDeepStub, logErrorStub; - - const reqBidsConfigObj = { - adUnits: [{ code: 'ad-slot-code-0' }], - auctionId: 'auction-id-0', - ortb2Fragments: { - bidder: { - user: { - ext: { - ctr: 'US', - } - } - } - } - }; - - const ortb2 = { - user: { - ext: { - ctr: 'US', - } - } - } - - const hookConfig = { - reqBidsConfigObj, - context: this, - nextFn: () => true, - haveExited: false, - timer: null - }; - - beforeEach(() => { - callback = sinon.spy(); - continueAuctionStub = sandbox.stub(priceFloors, 'continueAuction'); - logErrorStub = sandbox.stub(utils, 'logError'); - - global.configMergedPromise = Promise.resolve(); - }); - - afterEach(() => { - sandbox.restore(); // Restore all stubs/spies - }); - - it('should call continueAuction with correct hookConfig', async function () { - configMerged(); - await pubmaticSubmodule.getBidRequestData(reqBidsConfigObj, callback); - - expect(continueAuctionStub.called).to.be.true; - expect(continueAuctionStub.firstCall.args[0]).to.have.property('reqBidsConfigObj', reqBidsConfigObj); - expect(continueAuctionStub.firstCall.args[0]).to.have.property('haveExited', false); - }); - - // it('should merge country data into ortb2Fragments.bidder', async function () { - // configMerged(); - // global._country = 'US'; - // pubmaticSubmodule.getBidRequestData(reqBidsConfigObj, callback); - - // expect(reqBidsConfigObj.ortb2Fragments.bidder).to.have.property('pubmatic'); - // // expect(reqBidsConfigObj.ortb2Fragments.bidder.pubmatic.user.ext.ctr).to.equal('US'); - // }); - - it('should call callback once after execution', async function () { - configMerged(); - await pubmaticSubmodule.getBidRequestData(reqBidsConfigObj, callback); - - expect(callback.called).to.be.true; - }); - }); - - describe('withTimeout', function () { - it('should resolve with the original promise value if it resolves before the timeout', async function () { - const promise = new Promise((resolve) => setTimeout(() => resolve('success'), 50)); - const result = await withTimeout(promise, 100); - expect(result).to.equal('success'); - }); - - it('should resolve with undefined if the promise takes longer than the timeout', async function () { - const promise = new Promise((resolve) => setTimeout(() => resolve('success'), 200)); - const result = await withTimeout(promise, 100); - expect(result).to.be.undefined; - }); - - it('should properly handle rejected promises', async function () { - const promise = new Promise((resolve, reject) => setTimeout(() => reject(new Error('Failure')), 50)); - try { - await withTimeout(promise, 100); - } catch (error) { - expect(error.message).to.equal('Failure'); - } - }); - - it('should resolve with undefined if the original promise is rejected but times out first', async function () { - const promise = new Promise((resolve, reject) => setTimeout(() => reject(new Error('Failure')), 200)); - const result = await withTimeout(promise, 100); - expect(result).to.be.undefined; - }); - - it('should clear the timeout when the promise resolves before the timeout', async function () { - const clock = sinon.useFakeTimers(); - const clearTimeoutSpy = sinon.spy(global, 'clearTimeout'); - - const promise = new Promise((resolve) => setTimeout(() => resolve('success'), 50)); - const resultPromise = withTimeout(promise, 100); - - clock.tick(50); - await resultPromise; - - expect(clearTimeoutSpy.called).to.be.true; - - clearTimeoutSpy.restore(); - clock.restore(); - }); - }); - - describe('getTargetingData', function () { - let sandbox; - let logInfoStub; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - logInfoStub = sandbox.stub(utils, 'logInfo'); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should return empty object when profileConfigs is undefined', function () { - // Store the original value to restore it later - const originalProfileConfigs = getProfileConfigs(); - // Set profileConfigs to undefined - setProfileConfigs(undefined); - - const adUnitCodes = ['test-ad-unit']; - const config = {}; - const userConsent = {}; - const auction = {}; - - const result = getTargetingData(adUnitCodes, config, userConsent, auction); - - // Restore the original value - setProfileConfigs(originalProfileConfigs); - - expect(result).to.deep.equal({}); - expect(logInfoStub.calledWith(sinon.match(/pmTargetingKeys is disabled or profileConfigs is undefined/))).to.be.true; - }); - - it('should return empty object when pmTargetingKeys.enabled is false', function () { - // Create profileConfigs with pmTargetingKeys.enabled set to false - const profileConfigsMock = { - plugins: { - dynamicFloors: { - pmTargetingKeys: { - enabled: false - } - } - } - }; - - // Store the original value to restore it later - const originalProfileConfigs = getProfileConfigs(); - // Set profileConfigs to our mock - setProfileConfigs(profileConfigsMock); - - const adUnitCodes = ['test-ad-unit']; - const config = {}; - const userConsent = {}; - const auction = {}; - - const result = getTargetingData(adUnitCodes, config, userConsent, auction); - - // Restore the original value - setProfileConfigs(originalProfileConfigs); - - expect(result).to.deep.equal({}); - expect(logInfoStub.calledWith(sinon.match(/pmTargetingKeys is disabled or profileConfigs is undefined/))).to.be.true; - }); - - it('should set pm_ym_flrs to 0 when no RTD floor is applied to any bid', function () { - // Create profileConfigs with pmTargetingKeys.enabled set to true - const profileConfigsMock = { - plugins: { - dynamicFloors: { - pmTargetingKeys: { - enabled: true - } - } - } - }; - - // Store the original value to restore it later - const originalProfileConfigs = getProfileConfigs(); - // Set profileConfigs to our mock - setProfileConfigs(profileConfigsMock); - - // Create multiple ad unit codes to test - const adUnitCodes = ['ad-unit-1', 'ad-unit-2']; - const config = {}; - const userConsent = {}; - - // Create a mock auction object with bids that don't have RTD floors applied - // This tests several scenarios where RTD floor is not applied: - // 1. No floorData - // 2. floorData but floorProvider is not 'PM' - // 3. floorData with floorProvider 'PM' but skipped is true - const auction = { - adUnits: [ - { - code: 'ad-unit-1', - bids: [ - { bidder: 'bidderA' }, // No floorData - { bidder: 'bidderB', floorData: { floorProvider: 'OTHER' } } // Not PM provider - ] - }, - { - code: 'ad-unit-2', - bids: [ - { bidder: 'bidderC', floorData: { floorProvider: 'PM', skipped: true } } // PM but skipped - ] - } - ], - bidsReceived: [ - { adUnitCode: 'ad-unit-1', bidder: 'bidderA' }, - { adUnitCode: 'ad-unit-1', bidder: 'bidderB', floorData: { floorProvider: 'OTHER' } }, - { adUnitCode: 'ad-unit-2', bidder: 'bidderC', floorData: { floorProvider: 'PM', skipped: true } } - ] - }; - - const result = getTargetingData(adUnitCodes, config, userConsent, auction); - - // Restore the original value - setProfileConfigs(originalProfileConfigs); - - // Verify that for each ad unit code, only pm_ym_flrs is set to 0 - expect(result['ad-unit-1']).to.have.property('pm_ym_flrs', 0); - expect(result['ad-unit-2']).to.have.property('pm_ym_flrs', 0); - }); - - it('should set pm_ym_flrs to 1 when RTD floor is applied to a bid', function () { - // Create profileConfigs with pmTargetingKeys.enabled set to true - const profileConfigsMock = { - plugins: { - dynamicFloors: { - pmTargetingKeys: { - enabled: true - } - } - } - }; - - // Store the original value to restore it later - const originalProfileConfigs = getProfileConfigs(); - // Set profileConfigs to our mock - setProfileConfigs(profileConfigsMock); - - // Create multiple ad unit codes to test - const adUnitCodes = ['ad-unit-1', 'ad-unit-2']; - const config = {}; - const userConsent = {}; - - // Create a mock auction object with bids that have RTD floors applied - const auction = { - adUnits: [ - { - code: 'ad-unit-1', - bids: [ - { bidder: 'bidderA', floorData: { floorProvider: 'PM', skipped: false } }, - { bidder: 'bidderB', floorData: { floorProvider: 'PM', skipped: false } } - ] - }, - { - code: 'ad-unit-2', - bids: [ - { bidder: 'bidderC', floorData: { floorProvider: 'PM', skipped: false } }, - { bidder: 'bidderD', floorData: { floorProvider: 'PM', skipped: false } } - ] - } - ], - bidsReceived: [ - { adUnitCode: 'ad-unit-1', bidder: 'bidderA', floorData: { floorProvider: 'PM', skipped: false } }, - { adUnitCode: 'ad-unit-1', bidder: 'bidderB', floorData: { floorProvider: 'PM', skipped: false } }, - { adUnitCode: 'ad-unit-2', bidder: 'bidderC', floorData: { floorProvider: 'PM', skipped: false } }, - { adUnitCode: 'ad-unit-2', bidder: 'bidderD', floorData: { floorProvider: 'PM', skipped: false } } - ] - }; - - const result = getTargetingData(adUnitCodes, config, userConsent, auction); - - // Restore the original value - setProfileConfigs(originalProfileConfigs); - - // Verify that for each ad unit code, pm_ym_flrs is set to 1 - expect(result['ad-unit-1']).to.have.property('pm_ym_flrs', 1); - expect(result['ad-unit-2']).to.have.property('pm_ym_flrs', 1); - }); - - it('should set different targeting keys for winning bids (status 1) and floored bids (status 2)', function () { - // Create profileConfigs with pmTargetingKeys.enabled set to true - const profileConfigsMock = { - plugins: { - dynamicFloors: { - pmTargetingKeys: { - enabled: true - } - } - } - }; - - const mockPbjs = { - getHighestCpmBids: (adUnitCode) => { - // For div2, return a winning bid - if (adUnitCode === 'div2') { - return [{ - adUnitCode: 'div2', - cpm: 5.5, - floorData: { - floorValue: 5.0, - floorProvider: 'PM' - } - }]; - } - // For all other ad units, return empty array (no winning bids) - return []; - } - }; - - // Stub getGlobal to return our mock object - const getGlobalStub = sandbox.stub(prebidGlobal, 'getGlobal').returns(mockPbjs); - - // Store the original value to restore it later - const originalProfileConfigs = getProfileConfigs(); - // Set profileConfigs to our mock - setProfileConfigs(profileConfigsMock); - - // Create ad unit codes to test - const adUnitCodes = ['div2', 'div3']; - const config = {}; - const userConsent = {}; - - // Create a mock auction object with bids that have RTD floors applied - const auction = { - adUnits: [ - { code: "div2", bids: [{ floorData: { floorProvider: "PM", skipped: false } }] }, - { code: "div3", bids: [{ floorData: { floorProvider: "PM", skipped: false } }] } - ], - adUnitCodes: ["div2", "div3"], - bidsReceived: [[ - { - "bidderCode": "appnexus", - "auctionId": "a262767c-5499-4e98-b694-af36dbcb50f6", - "mediaType": "banner", - "source": "client", - "cpm": 5.5, - "adUnitCode": "div2", - "adapterCode": "appnexus", - "originalCpm": 5.5, - "floorData": { - "floorValue": 5, - "floorRule": "banner|*|*|div2|*|*|*|*|*", - "floorRuleValue": 5, - "floorCurrency": "USD", - - }, - "bidder": "appnexus", - } - ]], - bidsRejected: [ - { adUnitCode: "div3", bidder: "pubmatic", cpm: 20, floorData: { floorValue: 40 }, rejectionReason: "Bid does not meet price floor" }] - }; - - const result = getTargetingData(adUnitCodes, config, userConsent, auction); - - // Restore the original value - setProfileConfigs(originalProfileConfigs); - - // Check the test results - - expect(result['div2']).to.have.property('pm_ym_flrs', 1); - expect(result['div2']).to.have.property('pm_ym_flrv', '5.50'); - expect(result['div2']).to.have.property('pm_ym_bid_s', 1); - - expect(result['div3']).to.have.property('pm_ym_flrs', 1); - expect(result['div3']).to.have.property('pm_ym_flrv', '32.00'); - expect(result['div3']).to.have.property('pm_ym_bid_s', 2); - getGlobalStub.restore(); - }); - - describe('should handle the no bid scenario correctly', function () { - it('should handle no bid scenario correctly', function () { - // Create profileConfigs with pmTargetingKeys enabled - const profileConfigsMock = { - plugins: { - dynamicFloors: { - pmTargetingKeys: { - enabled: true, - multiplier: { - nobid: 1.2 // Explicit nobid multiplier - } - } - } - } - }; - - // Store the original value to restore it later - const originalProfileConfigs = getProfileConfigs(); - // Set profileConfigs to our mock - setProfileConfigs(profileConfigsMock); - - // Create ad unit codes to test - const adUnitCodes = ['Div2']; - const config = {}; - const userConsent = {}; - - // Create a mock auction with no bids but with RTD floor applied - // For this test, we'll observe what the function actually does rather than - // try to match specific multiplier values - const auction = { - "auctionId": "faf0b7d0-3a12-4774-826a-3d56033d9a74", - "auctionStatus": "completed", - "adUnits": [ - { - "code": "Div2", - "sizes": [[300, 250]], - "mediaTypes": { - "banner": { "sizes": [[300, 250]] } - }, - "bids": [ - { - "bidder": "pubmatic", - "params": { - "publisherId": "164392", - "adSlot": "/4374asd3431/DMDemo1@160x600" - }, - "floorData": { - "floorProvider": "PM" - } - } - ] - } - ], - "adUnitCodes": ["Div2"], - "bidderRequests": [ - { - "bidderCode": "pubmatic", - "auctionId": "faf0b7d0-3a12-4774-826a-3d56033d9a74", - "bids": [ - { - "bidder": "pubmatic", - "adUnitCode": "Div2", - "floorData": { - "floorProvider": "PM" - }, - "mediaTypes": { - "banner": { "sizes": [[300, 250]] } - }, - "getFloor": () => { return { floor: 0.05, currency: 'USD' }; } - } - ] - } - ], - "noBids": [ - { - "bidder": "pubmatic", - "adUnitCode": "Div2", - "floorData": { - "floorProvider": "PM", - "floorMin": 0.05 - } - } - ], - "bidsReceived": [], - "bidsRejected": [], - "winningBids": [] - }; - - const result = getTargetingData(adUnitCodes, config, userConsent, auction); - - // Restore the original value - setProfileConfigs(originalProfileConfigs); - - // Verify correct values for no bid scenario - expect(result['Div2']['pm_ym_flrs']).to.equal(1); // RTD floor was applied - expect(result['Div2']['pm_ym_bid_s']).to.equal(0); // NOBID status - - // Since finding floor values from bidder requests depends on implementation details - // we'll just verify the type rather than specific value - expect(result['Div2']['pm_ym_flrv']).to.be.a('string'); - }); - - it('should handle no bid scenario correctly for single ad unit multiple size scenarios', function () { - // Create profileConfigs with pmTargetingKeys enabled - const profileConfigsMock = { - plugins: { - dynamicFloors: { - pmTargetingKeys: { - enabled: true, - multiplier: { - nobid: 1.2 // Explicit nobid multiplier - } - } - } - } - }; - - // Store the original value to restore it later - const originalProfileConfigs = getProfileConfigs(); - // Set profileConfigs to our mock - setProfileConfigs(profileConfigsMock); - - // Create ad unit codes to test - const adUnitCodes = ['Div2']; - const config = {}; - const userConsent = {}; - - // Create a mock auction with no bids but with RTD floor applied - // For this test, we'll observe what the function actually does rather than - // try to match specific multiplier values - const auction = { - "auctionId": "faf0b7d0-3a12-4774-826a-3d56033d9a74", - "auctionStatus": "completed", - "adUnits": [ - { - "code": "Div2", - "sizes": [[300, 250]], - "mediaTypes": { "banner": { "sizes": [[300, 250]] } }, - "bids": [ - { - "bidder": "pubmatic", - "params": { - "publisherId": "164392", - "adSlot": "/4374asd3431/DMDemo1@160x600" - }, - "floorData": { - "floorProvider": "PM" - } - } - ] - } - ], - "adUnitCodes": ["Div2"], - "bidderRequests": [ - { - "bidderCode": "pubmatic", - "auctionId": "faf0b7d0-3a12-4774-826a-3d56033d9a74", - "bids": [ - { - "bidder": "pubmatic", - "adUnitCode": "Div2", - "floorData": { - "floorProvider": "PM" - }, - "mediaTypes": { - "banner": { "sizes": [[300, 250]] } - }, - "getFloor": () => { return { floor: 5, currency: 'USD' }; } - } - ] - } - ], - "noBids": [ - { - "bidder": "pubmatic", - "adUnitCode": "Div2", - "floorData": { - "floorProvider": "PM", - "floorMin": 0.05 - } - } - ], - "bidsReceived": [], - "bidsRejected": [], - "winningBids": [] - }; - - const result = getTargetingData(adUnitCodes, config, userConsent, auction); - - // Restore the original value - setProfileConfigs(originalProfileConfigs); - - // Verify correct values for no bid scenario - expect(result['Div2']['pm_ym_flrs']).to.equal(1); // RTD floor was applied - expect(result['Div2']['pm_ym_bid_s']).to.equal(0); // NOBID status - - // Since finding floor values from bidder requests depends on implementation details - // we'll just verify the type rather than specific value - expect(result['Div2']['pm_ym_flrv']).to.be.a('string'); - expect(result['Div2']['pm_ym_flrv']).to.equal("6.00"); - }); - - it('should handle no bid scenario correctly for multi-format ad unit with different floors', function () { - // Create profileConfigs with pmTargetingKeys enabled - const profileConfigsMock = { - plugins: { - dynamicFloors: { - pmTargetingKeys: { - enabled: true, - multiplier: { - nobid: 1.2 // Explicit nobid multiplier - } - } - } - } - }; - - // Store the original value to restore it later - const originalProfileConfigs = getProfileConfigs(); - // Set profileConfigs to our mock - setProfileConfigs(profileConfigsMock); - - // Create ad unit codes to test - const adUnitCodes = ['multiFormatDiv']; - const config = {}; - const userConsent = {}; - - // Mock getFloor implementation that returns different floors for different media types - const mockGetFloor = (params) => { - const floors = { - 'banner': 0.50, // Higher floor for banner - 'video': 0.25 // Lower floor for video - }; - - return { - floor: floors[params.mediaType] || 0.10, - currency: 'USD' - }; - }; - - // Create a mock auction with a multi-format ad unit (banner + video) - const auction = { - "auctionId": "multi-format-test-auction", - "auctionStatus": "completed", - "adUnits": [ - { - "code": "multiFormatDiv", - "mediaTypes": { - "banner": { - "sizes": [[300, 250], [300, 600]] - }, - "video": { - "playerSize": [[640, 480]], - "context": "instream" - } - }, - "bids": [ - { - "bidder": "pubmatic", - "params": { - "publisherId": "test-publisher", - "adSlot": "/test/slot" - }, - "floorData": { - "floorProvider": "PM" - } - } - ] - } - ], - "adUnitCodes": ["multiFormatDiv"], - "bidderRequests": [ - { - "bidderCode": "pubmatic", - "auctionId": "multi-format-test-auction", - "bids": [ - { - "bidder": "pubmatic", - "adUnitCode": "multiFormatDiv", - "mediaTypes": { - "banner": { - "sizes": [[300, 250], [300, 600]] - }, - "video": { - "playerSize": [[640, 480]], - "context": "instream" - } - }, - "floorData": { - "floorProvider": "PM" - }, - "getFloor": mockGetFloor - } - ] - } - ], - "noBids": [ - { - "bidder": "pubmatic", - "adUnitCode": "multiFormatDiv", - "floorData": { - "floorProvider": "PM" - } - } - ], - "bidsReceived": [], - "bidsRejected": [], - "winningBids": [] - }; - - // Create a spy to monitor the getFloor calls - const getFloorSpy = sinon.spy(auction.bidderRequests[0].bids[0], "getFloor"); - - // Run the targeting function - const result = getTargetingData(adUnitCodes, config, userConsent, auction); - - // Restore the original value - setProfileConfigs(originalProfileConfigs); - - // Verify correct values for no bid scenario - expect(result['multiFormatDiv']['pm_ym_flrs']).to.equal(1); // RTD floor was applied - expect(result['multiFormatDiv']['pm_ym_bid_s']).to.equal(0); // NOBID status - - // Verify that getFloor was called with both media types - expect(getFloorSpy.called).to.be.true; - let bannerCallFound = false; - let videoCallFound = false; - - getFloorSpy.getCalls().forEach(call => { - const args = call.args[0]; - if (args.mediaType === 'banner') bannerCallFound = true; - if (args.mediaType === 'video') videoCallFound = true; - }); - - expect(bannerCallFound).to.be.true; // Verify banner format was checked - expect(videoCallFound).to.be.true; // Verify video format was checked - - // Since we created the mockGetFloor to return 0.25 for video (lower than 0.50 for banner), - // we expect the RTD provider to use the minimum floor value (0.25) - // We can't test the exact value due to multiplier application, but we can make sure - // it's derived from the lower value - expect(parseFloat(result['multiFormatDiv']['pm_ym_flrv'])).to.be.closeTo(0.25 * 1.2, 0.001); // 0.25 * nobid multiplier (1.2) - - // Clean up - getFloorSpy.restore(); - }); - }); - }); -}); diff --git a/test/spec/modules/pubperfAnalyticsAdapter_spec.js b/test/spec/modules/pubperfAnalyticsAdapter_spec.js deleted file mode 100644 index 0d75c64f9..000000000 --- a/test/spec/modules/pubperfAnalyticsAdapter_spec.js +++ /dev/null @@ -1,43 +0,0 @@ -import pubperfAnalytics from 'modules/pubperfAnalyticsAdapter.js'; -import {expect} from 'chai'; -import {server} from 'test/mocks/xhr.js'; -import {expectEvents, fireEvents} from '../../helpers/analytics.js'; - -const events = require('src/events'); -const utils = require('src/utils.js'); - -describe('Pubperf Analytics Adapter', function() { - describe('Prebid Manager Analytic tests', function() { - beforeEach(function() { - sinon.stub(events, 'getEvents').returns([]); - sinon.stub(utils, 'logError'); - }); - - afterEach(function() { - events.getEvents.restore(); - utils.logError.restore(); - }); - - it('should throw error, when pubperf_pbjs is not defined', function() { - pubperfAnalytics.enableAnalytics({ - provider: 'pubperf' - }); - - fireEvents(); - expect(server.requests.length).to.equal(0); - expect(utils.logError.called).to.equal(true); - }); - - it('track event without errors', function() { - sinon.spy(pubperfAnalytics, 'track'); - - window['pubperf_pbjs'] = function() {}; - - pubperfAnalytics.enableAnalytics({ - provider: 'pubperf' - }); - - expectEvents().to.beTrackedBy(pubperfAnalytics.track); - }); - }); -}); diff --git a/test/spec/modules/pubriseBidAdapter_spec.js b/test/spec/modules/pubriseBidAdapter_spec.js deleted file mode 100644 index 786f6a98b..000000000 --- a/test/spec/modules/pubriseBidAdapter_spec.js +++ /dev/null @@ -1,517 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/pubriseBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'pubrise'; - -describe('PubriseBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://backend.pubrise.ai/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys( - 'device', - 'deviceWidth', - 'deviceHeight', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync.pubrise.ai/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync.pubrise.ai/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://sync.pubrise.ai/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/pubstackAnalyticsAdapter_spec.js b/test/spec/modules/pubstackAnalyticsAdapter_spec.js deleted file mode 100644 index 6e532698d..000000000 --- a/test/spec/modules/pubstackAnalyticsAdapter_spec.js +++ /dev/null @@ -1,24 +0,0 @@ -import * as utils from 'src/utils.js'; -import pubstackAnalytics from '../../../modules/pubstackAnalyticsAdapter.js'; -import adapterManager from 'src/adapterManager'; -import * as events from 'src/events'; -import {expectEvents} from '../../helpers/analytics.js'; - -describe('Pubstack Analytics Adapter', () => { - const scope = utils.getWindowSelf(); - - beforeEach(() => { - scope.PubstackAnalytics = sinon.stub(); - adapterManager.enableAnalytics({ - provider: 'pubstack' - }); - }); - - afterEach(() => { - pubstackAnalytics.disableAnalytics(); - }); - - it('should forward all events to the queue', () => { - expectEvents().to.beBundledTo(scope.PubstackAnalytics); - }); -}); diff --git a/test/spec/modules/pubwiseAnalyticsAdapter_spec.js b/test/spec/modules/pubwiseAnalyticsAdapter_spec.js deleted file mode 100644 index 35284fbdd..000000000 --- a/test/spec/modules/pubwiseAnalyticsAdapter_spec.js +++ /dev/null @@ -1,151 +0,0 @@ -import {expect} from 'chai'; -import pubwiseAnalytics from 'modules/pubwiseAnalyticsAdapter.js'; -import {expectEvents} from '../../helpers/analytics.js'; -import {server} from '../../mocks/xhr.js'; -import { EVENTS } from 'src/constants.js'; - -const events = require('src/events'); -const adapterManager = require('src/adapterManager').default; - -describe('PubWise Prebid Analytics', function () { - let requests; - let sandbox; - let clock; - const mock = {}; - - mock.DEFAULT_PW_CONFIG = { - provider: 'pubwiseanalytics', - options: { - site: ['b1ccf317-a6fc-428d-ba69-0c9c208aa61c'], - custom: {'c_script_type': 'test-script-type', 'c_host': 'test-host', 'c_slot1': 'test-slot1', 'c_slot2': 'test-slot2', 'c_slot3': 'test-slot3', 'c_slot4': 'test-slot4'} - } - }; - mock.AUCTION_INIT = {auctionId: '53c35d77-bd62-41e7-b920-244140e30c77'}; - mock.AUCTION_INIT_EXTRAS = { - auctionId: '53c35d77-bd62-41e7-b920-244140e30c77', - adUnitCodes: 'not empty', - adUnits: '', - bidderRequests: ['0'], - bidsReceived: '0', - config: {test: 'config'}, - noBids: 'no bids today', - winningBids: 'winning bids', - extraProp: 'extraProp retained' - }; - - beforeEach(function() { - sandbox = sinon.createSandbox(); - clock = sandbox.useFakeTimers({shouldClearNativeTimers: true}); - sandbox.stub(events, 'getEvents').returns([]); - - requests = server.requests; - }); - - afterEach(function () { - sandbox.restore(); - clock.restore(); - pubwiseAnalytics.disableAnalytics(); - }); - - describe('enableAnalytics', function () { - it('should catch all events', function () { - pubwiseAnalytics.enableAnalytics(mock.DEFAULT_PW_CONFIG); - - sandbox.spy(pubwiseAnalytics, 'track'); - - expectEvents([ - EVENTS.AUCTION_INIT, - EVENTS.BID_REQUESTED, - EVENTS.BID_RESPONSE, - EVENTS.BID_WON, - EVENTS.AD_RENDER_FAILED, - EVENTS.TCF2_ENFORCEMENT, - EVENTS.BID_TIMEOUT, - EVENTS.AUCTION_END, - ]).to.beTrackedBy(pubwiseAnalytics.track); - }); - - it('should initialize the auction properly', function () { - pubwiseAnalytics.enableAnalytics(mock.DEFAULT_PW_CONFIG); - - // sent - events.emit(EVENTS.AUCTION_INIT, mock.AUCTION_INIT); - events.emit(EVENTS.BID_REQUESTED, {}); - events.emit(EVENTS.BID_RESPONSE, {}); - events.emit(EVENTS.BID_WON, {}); - // force flush - clock.tick(500); - - /* check for critical values */ - const request = requests[0]; - const data = JSON.parse(request.requestBody); - - // console.log(data.metaData); - expect(data.metaData, 'metaData property').to.exist; - expect(data.metaData.pbjs_version, 'pbjs version').to.equal('$prebid.version$') - expect(data.metaData.session_id, 'session id').not.to.be.empty - expect(data.metaData.activation_id, 'activation id').not.to.be.empty - - // check custom metadata slots - expect(data.metaData.c_script_type, 'c_script_type property').to.exist; - expect(data.metaData.c_script_type, 'c_script_type').not.to.be.empty - expect(data.metaData.c_script_type).to.equal('test-script-type'); - - expect(data.metaData.c_host, 'c_host property').to.exist; - expect(data.metaData.c_host, 'c_host').not.to.be.empty - expect(data.metaData.c_host).to.equal('test-host'); - - expect(data.metaData.c_slot1, 'c_slot1 property').to.exist; - expect(data.metaData.c_slot1, 'c_slot1').not.to.be.empty - expect(data.metaData.c_slot1).to.equal('test-slot1'); - - expect(data.metaData.c_slot2, 'c_slot1 property').to.exist; - expect(data.metaData.c_slot2, 'c_slot1').not.to.be.empty - expect(data.metaData.c_slot2).to.equal('test-slot2'); - - expect(data.metaData.c_slot3, 'c_slot1 property').to.exist; - expect(data.metaData.c_slot3, 'c_slot1').not.to.be.empty - expect(data.metaData.c_slot3).to.equal('test-slot3'); - - expect(data.metaData.c_slot4, 'c_slot1 property').to.exist; - expect(data.metaData.c_slot4, 'c_slot1').not.to.be.empty - expect(data.metaData.c_slot4).to.equal('test-slot4'); - - // check for version info too - expect(data.metaData.pw_version, 'pw_version property').to.exist; - expect(data.metaData.pbjs_version, 'pbjs_version property').to.exist; - }); - - it('should remove extra data on init', function () { - pubwiseAnalytics.enableAnalytics(mock.DEFAULT_PW_CONFIG); - - // sent - events.emit(EVENTS.AUCTION_INIT, mock.AUCTION_INIT_EXTRAS); - // force flush - clock.tick(500); - - /* check for critical values */ - const request = requests[0]; - const data = JSON.parse(request.requestBody); - - // check the basics - expect(data.eventList, 'eventList property').to.exist; - expect(data.eventList[0], 'eventList property').to.exist; - expect(data.eventList[0].args, 'eventList property').to.exist; - - // console.log(data.eventList[0].args); - - const eventArgs = data.eventList[0].args; - // the props we want removed should go away - expect(eventArgs.adUnitCodes, 'adUnitCodes property').not.to.exist; - expect(eventArgs.bidderRequests, 'adUnitCodes property').not.to.exist; - expect(eventArgs.bidsReceived, 'adUnitCodes property').not.to.exist; - expect(eventArgs.config, 'adUnitCodes property').not.to.exist; - expect(eventArgs.noBids, 'adUnitCodes property').not.to.exist; - expect(eventArgs.winningBids, 'adUnitCodes property').not.to.exist; - - // the extra prop should still exist - expect(eventArgs.extraProp, 'adUnitCodes property').to.exist; - }); - }); -}); diff --git a/test/spec/modules/pubxBidAdapter_spec.js b/test/spec/modules/pubxBidAdapter_spec.js deleted file mode 100644 index f0148bb1d..000000000 --- a/test/spec/modules/pubxBidAdapter_spec.js +++ /dev/null @@ -1,207 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/pubxBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import * as utils from 'src/utils.js'; - -describe('pubxAdapter', function () { - const adapter = newBidder(spec); - const ENDPOINT = 'https://api.primecaster.net/adlogue/api/slot/bid'; - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - bidder: 'pubx', - params: { - sid: '12345abc' - } - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - id: '26c1ee0038ac11', - params: { - sid: '12345abc' - }, - ortb2: { - site: { - page: `${location.href}?test=1` - } - } - } - ]; - - const data = { - banner: { - sid: '12345abc', - pu: encodeURIComponent( - utils.deepAccess(bidRequests[0], 'ortb2.site.page').replace(/\?.*$/, '') - ), - }, - }; - - it('sends bid request to ENDPOINT via GET', function () { - const request = spec.buildRequests(bidRequests)[0]; - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('GET'); - }); - - it('should attach params to the banner request', function () { - const request = spec.buildRequests(bidRequests)[0]; - expect(request.data).to.deep.equal(data.banner); - }); - }); - - describe('getUserSyncs', function () { - const sandbox = sinon.createSandbox(); - - const keywordsText = 'meta1,meta2,meta3,meta4,meta5'; - const descriptionText = 'description1description2description3description4description5description'; - - let documentStubMeta; - - beforeEach(function () { - documentStubMeta = sandbox.stub(document, 'getElementsByName'); - const metaElKeywords = document.createElement('meta'); - metaElKeywords.setAttribute('name', 'keywords'); - metaElKeywords.setAttribute('content', keywordsText); - documentStubMeta.withArgs('keywords').returns([metaElKeywords]); - - const metaElDescription = document.createElement('meta'); - metaElDescription.setAttribute('name', 'description'); - metaElDescription.setAttribute('content', descriptionText); - documentStubMeta.withArgs('description').returns([metaElDescription]); - }); - - afterEach(function () { - documentStubMeta.restore(); - }); - - let kwString = ''; - let kwEnc = ''; - let descContent = ''; - let descEnc = ''; - - it('returns empty sync array when iframe is not enabled', function () { - const syncOptions = {}; - expect(spec.getUserSyncs(syncOptions)).to.deep.equal([]); - }); - - it('returns kwEnc when there is kwTag with more than 20 length', function () { - const kwArray = keywordsText.substr(0, 20).split(','); - kwArray.pop(); - kwString = kwArray.join(); - kwEnc = encodeURIComponent(kwString); - const syncs = spec.getUserSyncs({ iframeEnabled: true }); - expect(syncs[0].url).to.include(`pkw=${kwEnc}`); - }); - - it('returns kwEnc when there is kwTag with more than 60 length', function () { - descContent = descContent.substr(0, 60); - descEnc = encodeURIComponent(descContent); - const syncs = spec.getUserSyncs({ iframeEnabled: true }); - expect(syncs[0].url).to.include(`pkw=${descEnc}`); - }); - - it('returns titleEnc when there is titleContent with more than 30 length', function () { - let titleText = 'title1title2title3title4title5title'; - const documentStubTitle = sandbox.stub(document, 'title').value(titleText); - - if (titleText.length > 30) { - titleText = titleText.substr(0, 30); - } - - const syncs = spec.getUserSyncs({ iframeEnabled: true }); - expect(syncs[0].url).to.include(`pt=${encodeURIComponent(titleText)}`); - }); - }); - - describe('interpretResponse', function () { - const serverResponse = { - body: { - TTL: 300, - adm: '
some creative
', - cid: 'TKmB', - cpm: 500, - currency: 'JPY', - height: 250, - width: 300, - adomains: [ - 'test.com' - ], - } - } - - const bidRequests = [ - { - id: '26c1ee0038ac11', - params: { - sid: '12345abc' - } - } - ]; - - const bidResponses = [ - { - requestId: '26c1ee0038ac11', - cpm: 500, - currency: 'JPY', - width: 300, - height: 250, - creativeId: 'TKmB', - netRevenue: true, - ttl: 300, - ad: '
some creative
', - meta: { - advertiserDomains: [ - 'test.com' - ] - }, - } - ]; - it('should return empty array when required param is empty', function () { - const serverResponseWithCidEmpty = { - body: { - TTL: 300, - adm: '
some creative
', - cid: '', - cpm: '', - currency: 'JPY', - height: 250, - width: 300, - } - } - const result = spec.interpretResponse(serverResponseWithCidEmpty, bidRequests[0]); - expect(result).to.be.empty; - }); - it('handles banner responses', function () { - const result = spec.interpretResponse(serverResponse, bidRequests[0])[0]; - expect(result.requestId).to.equal(bidResponses[0].requestId); - expect(result.width).to.equal(bidResponses[0].width); - expect(result.height).to.equal(bidResponses[0].height); - expect(result.creativeId).to.equal(bidResponses[0].creativeId); - expect(result.currency).to.equal(bidResponses[0].currency); - expect(result.netRevenue).to.equal(bidResponses[0].netRevenue); - expect(result.ttl).to.equal(bidResponses[0].ttl); - expect(result.ad).to.equal(bidResponses[0].ad); - expect(result.meta.advertiserDomains).deep.to.equal(bidResponses[0].meta.advertiserDomains); - }); - }); -}); diff --git a/test/spec/modules/pubxaiAnalyticsAdapter_spec.js b/test/spec/modules/pubxaiAnalyticsAdapter_spec.js deleted file mode 100644 index e9bde2d77..000000000 --- a/test/spec/modules/pubxaiAnalyticsAdapter_spec.js +++ /dev/null @@ -1,1178 +0,0 @@ -/* globals describe, beforeEach, afterEach, sinon */ -import { expect } from 'chai'; -import { getGptSlotInfoForAdUnitCode } from 'libraries/gptUtils/gptUtils.js'; -import { getDeviceType, getBrowser, getOS } from 'libraries/userAgentUtils'; -import pubxaiAnalyticsAdapter, { - auctionCache, -} from 'modules/pubxaiAnalyticsAdapter.js'; -import { EVENTS } from 'src/constants.js'; -import adapterManager from 'src/adapterManager.js'; -import { getWindowLocation } from 'src/utils.js'; -import { getGlobal } from 'src/prebidGlobal.js'; -import * as events from 'src/events.js' -import 'modules/userId/index.js' - -const readBlobSafariCompat = (blob) => { - return new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.onload = () => resolve(reader.result) - reader.onerror = reject - reader.readAsText(blob) - }) -} - -describe('pubxai analytics adapter', () => { - beforeEach(() => { - sinon.stub(events, 'getEvents').returns([]); - getGlobal().refreshUserIds?.() - }); - - afterEach(() => { - events.getEvents.restore(); - }); - - describe('track', () => { - const pubxId = '6c415fc0-8b0e-4cf5-be73-01526a4db625'; - const initOptions = { - samplingRate: '1', - pubxId: pubxId, - }; - - let originalVS; - - const location = getWindowLocation(); - - const replaceProperty = (obj, params) => { - let strObj = JSON.stringify(obj); - params.forEach(({ field, updated, replaced }) => { - strObj = strObj.replace( - new RegExp('"' + field + '":' + replaced, 'g'), - '"' + field + '":' + updated - ); - }); - return JSON.parse(strObj); - }; - - const prebidEvent = { - auctionInit: { - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - timestamp: 1603865707180, - auctionStatus: 'inProgress', - adUnits: [ - { - code: '/19968336/header-bid-tag-1', - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - bids: [ - { - bidder: 'appnexus', - params: { - placementId: 13144370, - }, - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - floorData: { - skipped: false, - skipRate: 0, - modelVersion: 'test model 1.0', - location: 'fetch', - floorProvider: 'PubXFloorProvider', - fetchStatus: 'success', - }, - }, - ], - sizes: [[300, 250]], - transactionId: '41ec8eaf-3e7c-4a8b-8344-ab796ff6e294', - }, - ], - adUnitCodes: ['/19968336/header-bid-tag-1'], - bidderRequests: [ - { - bidderCode: 'appnexus', - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - bidderRequestId: '184cbc05bb90ba', - bids: [ - { - bidder: 'appnexus', - params: { - placementId: 13144370, - }, - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - floorData: { - skipped: false, - skipRate: 0, - modelVersion: 'test model 1.0', - location: 'fetch', - floorProvider: 'PubXFloorProvider', - fetchStatus: 'success', - }, - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - adUnitCode: '/19968336/header-bid-tag-1', - transactionId: '41ec8eaf-3e7c-4a8b-8344-ab796ff6e294', - sizes: [[300, 250]], - bidId: '248f9a4489835e', - bidderRequestId: '184cbc05bb90ba', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - }, - ], - ortb2: { - device: { - ext: { - cdep: true, - }, - }, - }, - auctionStart: 1603865707180, - timeout: 1000, - refererInfo: { - referer: 'http://local-pnh.net:8080/stream/', - reachedTop: true, - isAmp: false, - numIframes: 0, - stack: ['http://local-pnh.net:8080/stream/'], - canonicalUrl: null, - }, - start: 1603865707182, - }, - ], - noBids: [], - bidsReceived: [], - winningBids: [], - timeout: 1000, - config: { - samplingRate: '1', - pubxId: pubxId, - }, - }, - bidRequested: { - bidderCode: 'appnexus', - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - bidderRequestId: '184cbc05bb90ba', - bids: [ - { - bidder: 'appnexus', - params: { - placementId: 13144370, - }, - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - floorData: { - skipped: false, - skipRate: 0, - modelVersion: 'test model 1.0', - location: 'fetch', - floorProvider: 'PubXFloorProvider', - fetchStatus: 'success', - }, - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - adUnitCode: '/19968336/header-bid-tag-1', - transactionId: '41ec8eaf-3e7c-4a8b-8344-ab796ff6e294', - sizes: [[300, 250]], - bidId: '248f9a4489835e', - bidderRequestId: '184cbc05bb90ba', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - }, - ], - ortb2: { - device: { - ext: { - cdep: true, - }, - }, - }, - auctionStart: 1603865707180, - timeout: 1000, - refererInfo: { - referer: 'http://local-pnh.net:8080/stream/', - reachedTop: true, - isAmp: false, - numIframes: 0, - stack: ['http://local-pnh.net:8080/stream/'], - canonicalUrl: null, - }, - start: 1603865707182, - }, - bidTimeout: [], - bidResponse: { - bidderCode: 'appnexus', - width: 300, - height: 250, - statusMessage: 'Bid available', - adId: '32780c4bc382cb', - requestId: '248f9a4489835e', - mediaType: 'banner', - source: 'client', - cpm: 0.5, - creativeId: 96846035, - currency: 'USD', - netRevenue: true, - ttl: 300, - adUnitCode: '/19968336/header-bid-tag-1', - appnexus: { - buyerMemberId: 9325, - }, - meta: { - advertiserId: 2529885, - }, - ad: '', - originalCpm: 0.5, - originalCurrency: 'USD', - floorData: { - fetchStatus: 'success', - floorProvider: 'PubXFloorProvider', - location: 'fetch', - modelVersion: 'test model 1.0', - skipRate: 0, - skipped: false, - floorValue: 0.4, - floorRule: '/19968336/header-bid-tag-1|banner', - floorCurrency: 'USD', - cpmAfterAdjustments: 0.5, - enforcements: { - enforceJS: true, - enforcePBS: false, - floorDeals: true, - bidAdjustment: true, - }, - matchedFields: { - gptSlot: '/19968336/header-bid-tag-1', - mediaType: 'banner', - }, - }, - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - responseTimestamp: 1616654313071, - requestTimestamp: 1616654312804, - bidder: 'appnexus', - timeToRespond: 267, - pbLg: '0.50', - pbMg: '0.50', - pbHg: '0.50', - pbAg: '0.50', - pbDg: '0.50', - pbCg: '0.50', - size: '300x250', - adserverTargeting: { - hb_bidder: 'appnexus', - hb_adid: '32780c4bc382cb', - hb_pb: '0.50', - hb_size: '300x250', - hb_source: 'client', - hb_format: 'banner', - }, - }, - auctionEnd: { - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - timestamp: 1616654312804, - auctionEnd: 1616654313090, - auctionStatus: 'completed', - adUnits: [ - { - code: '/19968336/header-bid-tag-1', - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - bids: [ - { - bidder: 'appnexus', - params: { - placementId: 13144370, - }, - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - floorData: { - skipped: false, - skipRate: 0, - modelVersion: 'test model 1.0', - location: 'fetch', - floorProvider: 'PubXFloorProvider', - fetchStatus: 'success', - }, - }, - ], - sizes: [[300, 250]], - transactionId: '41ec8eaf-3e7c-4a8b-8344-ab796ff6e294', - }, - ], - adUnitCodes: ['/19968336/header-bid-tag-1'], - bidderRequests: [ - { - bidderCode: 'appnexus', - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - bidderRequestId: '184cbc05bb90ba', - bids: [ - { - bidder: 'appnexus', - params: { - placementId: 13144370, - }, - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - floorData: { - skipped: false, - skipRate: 0, - modelVersion: 'test model 1.0', - location: 'fetch', - floorProvider: 'PubXFloorProvider', - fetchStatus: 'success', - }, - mediaTypes: { - banner: { - sizes: [[300, 250]], - }, - }, - adUnitCode: '/19968336/header-bid-tag-1', - transactionId: '41ec8eaf-3e7c-4a8b-8344-ab796ff6e294', - sizes: [[300, 250]], - bidId: '248f9a4489835e', - bidderRequestId: '184cbc05bb90ba', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - }, - ], - ortb2: { - device: { - ext: { - cdep: true, - }, - }, - }, - auctionStart: 1603865707180, - timeout: 1000, - refererInfo: { - referer: 'http://local-pnh.net:8080/stream/', - reachedTop: true, - isAmp: false, - numIframes: 0, - stack: ['http://local-pnh.net:8080/stream/'], - canonicalUrl: null, - }, - start: 1603865707182, - }, - ], - noBids: [], - bidsReceived: [ - { - bidderCode: 'appnexus', - width: 300, - height: 250, - statusMessage: 'Bid available', - adId: '32780c4bc382cb', - requestId: '248f9a4489835e', - mediaType: 'banner', - source: 'client', - cpm: 0.5, - creativeId: 96846035, - currency: 'USD', - netRevenue: true, - ttl: 300, - adUnitCode: '/19968336/header-bid-tag-1', - appnexus: { - buyerMemberId: 9325, - }, - meta: { - advertiserId: 2529885, - }, - ad: '', - originalCpm: 0.5, - originalCurrency: 'USD', - floorData: { - fetchStatus: 'success', - floorProvider: 'PubXFloorProvider', - location: 'fetch', - modelVersion: 'test model 1.0', - skipRate: 0, - skipped: false, - floorValue: 0.4, - floorRule: '/19968336/header-bid-tag-1|banner', - floorCurrency: 'USD', - cpmAfterAdjustments: 0.5, - enforcements: { - enforceJS: true, - enforcePBS: false, - floorDeals: true, - bidAdjustment: true, - }, - matchedFields: { - gptSlot: '/19968336/header-bid-tag-1', - mediaType: 'banner', - }, - }, - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - responseTimestamp: 1616654313071, - requestTimestamp: 1616654312804, - bidder: 'appnexus', - timeToRespond: 267, - pbLg: '0.50', - pbMg: '0.50', - pbHg: '0.50', - pbAg: '0.50', - pbDg: '0.50', - pbCg: '0.50', - size: '300x250', - adserverTargeting: { - hb_bidder: 'appnexus', - hb_adid: '32780c4bc382cb', - hb_pb: '0.50', - hb_size: '300x250', - hb_source: 'client', - hb_format: 'banner', - }, - status: 'rendered', - params: [ - { - placementId: 13144370, - }, - ], - }, - ], - winningBids: [], - timeout: 1000, - }, - bidWon: { - bidderCode: 'appnexus', - width: 300, - height: 250, - statusMessage: 'Bid available', - adId: '32780c4bc382cb', - requestId: '248f9a4489835e', - mediaType: 'banner', - source: 'client', - cpm: 0.5, - creativeId: 96846035, - currency: 'USD', - netRevenue: true, - ttl: 300, - adUnitCode: '/19968336/header-bid-tag-1', - appnexus: { - buyerMemberId: 9325, - }, - meta: { - advertiserId: 2529885, - }, - ad: '', - originalCpm: 0.5, - originalCurrency: 'USD', - floorData: { - fetchStatus: 'success', - floorProvider: 'PubXFloorProvider', - location: 'fetch', - modelVersion: 'test model 1.0', - skipRate: 0, - skipped: false, - floorValue: 0.4, - floorRule: '/19968336/header-bid-tag-1|banner', - floorCurrency: 'USD', - cpmAfterAdjustments: 0.5, - enforcements: { - enforceJS: true, - enforcePBS: false, - floorDeals: true, - bidAdjustment: true, - }, - matchedFields: { - gptSlot: '/19968336/header-bid-tag-1', - mediaType: 'banner', - }, - }, - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - responseTimestamp: 1616654313071, - requestTimestamp: 1616654312804, - bidder: 'appnexus', - timeToRespond: 267, - pbLg: '0.50', - pbMg: '0.50', - pbHg: '0.50', - pbAg: '0.50', - pbDg: '0.50', - pbCg: '0.50', - size: '300x250', - adserverTargeting: { - hb_bidder: 'appnexus', - hb_adid: '32780c4bc382cb', - hb_pb: '0.50', - hb_size: '300x250', - hb_source: 'client', - hb_format: 'banner', - }, - status: 'rendered', - params: [ - { - placementId: 13144370, - }, - ], - }, - }; - - const expectedAfterBid = { - bids: [ - { - bidderCode: 'appnexus', - bidId: '248f9a4489835e', - adUnitCode: '/19968336/header-bid-tag-1', - gptSlotCode: - getGptSlotInfoForAdUnitCode('/19968336/header-bid-tag-1').gptSlot || - null, - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - sizes: '300x250', - bidType: 2, - requestTimestamp: 1616654312804, - creativeId: 96846035, - currency: 'USD', - cpm: 0.5, - netRevenue: true, - mediaType: 'banner', - statusMessage: 'Bid available', - floorData: { - fetchStatus: 'success', - floorProvider: 'PubXFloorProvider', - location: 'fetch', - modelVersion: 'test model 1.0', - skipRate: 0, - skipped: false, - floorValue: 0.4, - floorRule: '/19968336/header-bid-tag-1|banner', - floorCurrency: 'USD', - cpmAfterAdjustments: 0.5, - enforcements: { - enforceJS: true, - enforcePBS: false, - floorDeals: true, - bidAdjustment: true, - }, - matchedFields: { - gptSlot: '/19968336/header-bid-tag-1', - mediaType: 'banner', - }, - }, - placementId: null, - timeToRespond: 267, - source: 'client', - responseTimestamp: 1616654313071, - }, - ], - auctionDetail: { - adUnitCodes: ['/19968336/header-bid-tag-1'], - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - refreshRank: 0, - timestamp: 1616654312804, - }, - pageDetail: { - host: location.host, - path: location.pathname, - search: location.search, - }, - floorDetail: { - fetchStatus: 'success', - floorProvider: 'PubXFloorProvider', - location: 'fetch', - modelVersion: 'test model 1.0', - skipRate: 0, - skipped: false, - }, - deviceDetail: { - platform: navigator.platform, - deviceType: getDeviceType(), - deviceOS: getOS(), - browser: getBrowser(), - cdep: true, - }, - userDetail: { - userIdTypes: Object.keys(getGlobal().getUserIds?.() || {}), - }, - consentDetail: { - consentTypes: Object.keys(getGlobal().getConsentMetadata?.() || {}), - }, - pmacDetail: {}, - extraData: {}, - initOptions: { - ...initOptions, - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - }, - }; - - const expectedAfterBidWon = { - winningBid: { - adUnitCode: '/19968336/header-bid-tag-1', - gptSlotCode: - getGptSlotInfoForAdUnitCode('/19968336/header-bid-tag-1').gptSlot || - null, - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - bidderCode: 'appnexus', - bidId: '248f9a4489835e', - cpm: 0.5, - creativeId: 96846035, - currency: 'USD', - floorData: { - fetchStatus: 'success', - floorProvider: 'PubXFloorProvider', - location: 'fetch', - modelVersion: 'test model 1.0', - skipRate: 0, - skipped: false, - floorValue: 0.4, - floorRule: '/19968336/header-bid-tag-1|banner', - floorCurrency: 'USD', - cpmAfterAdjustments: 0.5, - enforcements: { - enforceJS: true, - enforcePBS: false, - floorDeals: true, - bidAdjustment: true, - }, - matchedFields: { - gptSlot: '/19968336/header-bid-tag-1', - mediaType: 'banner', - }, - }, - adServerData: {}, - floorProvider: 'PubXFloorProvider', - floorFetchStatus: 'success', - floorLocation: 'fetch', - floorModelVersion: 'test model 1.0', - floorSkipRate: 0, - isFloorSkipped: false, - isWinningBid: true, - mediaType: 'banner', - netRevenue: true, - placementId: 13144370, - renderedSize: '300x250', - sizes: '300x250', - bidType: 4, - responseTimestamp: 1616654313071, - requestTimestamp: 1616654312804, - status: 'rendered', - statusMessage: 'Bid available', - timeToRespond: 267, - source: 'client', - }, - auctionDetail: { - adUnitCodes: ['/19968336/header-bid-tag-1'], - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - refreshRank: 0, - timestamp: 1616654312804, - }, - pageDetail: { - host: location.host, - path: location.pathname, - search: location.search, - }, - floorDetail: { - fetchStatus: 'success', - floorProvider: 'PubXFloorProvider', - location: 'fetch', - modelVersion: 'test model 1.0', - skipRate: 0, - skipped: false, - }, - deviceDetail: { - platform: navigator.platform, - deviceType: getDeviceType(), - deviceOS: getOS(), - browser: getBrowser(), - cdep: true, - }, - userDetail: { - userIdTypes: Object.keys(getGlobal().getUserIds?.() || {}), - }, - consentDetail: { - consentTypes: Object.keys(getGlobal().getConsentMetadata?.() || {}), - }, - pmacDetail: {}, - extraData: {}, - initOptions: { - ...initOptions, - auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', - }, - }; - - adapterManager.registerAnalyticsAdapter({ - code: 'pubxai', - adapter: pubxaiAnalyticsAdapter, - }); - - beforeEach(() => { - adapterManager.enableAnalytics({ - provider: 'pubxai', - options: initOptions, - }); - sinon.stub(navigator, 'sendBeacon').returns(true); - originalVS = document.visibilityState; - document['__defineGetter__']('visibilityState', function () { - return 'hidden'; - }); - }); - - afterEach(() => { - pubxaiAnalyticsAdapter.disableAnalytics(); - navigator.sendBeacon.restore(); - delete auctionCache['bc3806e4-873e-453c-8ae5-204f35e923b4']; - delete auctionCache['auction2']; - document['__defineGetter__']('visibilityState', function () { - return originalVS; - }); - }); - - it('builds and sends auction data', async () => { - // Step 1: Send auction init event - events.emit(EVENTS.AUCTION_INIT, prebidEvent['auctionInit']); - - // Step 2: Send bid requested event - events.emit(EVENTS.BID_REQUESTED, prebidEvent['bidRequested']); - - // Step 3: Send bid response event - events.emit(EVENTS.BID_RESPONSE, prebidEvent['bidResponse']); - - // Step 4: Send bid time out event - events.emit(EVENTS.BID_TIMEOUT, prebidEvent['bidTimeout']); - - // Step 5: Send auction end event - events.emit(EVENTS.AUCTION_END, prebidEvent['auctionEnd']); - - // Simulate "navigate away" behaviour - document.dispatchEvent(new Event('visibilitychange')); - - expect(navigator.sendBeacon.callCount).to.equal(0); - - // Step 6: Send auction bid won event - events.emit(EVENTS.BID_WON, prebidEvent['bidWon']); - - // Simulate end of session - document.dispatchEvent(new Event('visibilitychange')); - - expect(navigator.sendBeacon.callCount).to.equal(2); - - for (const [index, arg] of navigator.sendBeacon.args.entries()) { - const [expectedUrl, expectedData] = arg; - const parsedUrl = new URL(expectedUrl); - expect(parsedUrl.pathname).to.equal( - ['/analytics/bidwon', '/analytics/auction'][index] - ); - expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ - auctionTimestamp: '1616654312804', - pubxaiAnalyticsVersion: 'v2.1.0', - prebidVersion: '$prebid.version$', - pubxId: pubxId, - }); - expect(expectedData.type).to.equal('text/json'); - expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([ - [expectedAfterBidWon, expectedAfterBid][index], - ]); - } - }); - - it('auction data with only rejected bids', async () => { - // Step 1: Send auction init event - events.emit(EVENTS.AUCTION_INIT, prebidEvent['auctionInit']); - - // Step 2: Send bid requested event - events.emit(EVENTS.BID_REQUESTED, prebidEvent['bidRequested']); - - // Step 3: Send bid rejected (afaict the only expected reason would be a bid being too low) - events.emit(EVENTS.BID_REJECTED, prebidEvent['bidResponse']); - - // Simulate "navigate away" behaviour - document.dispatchEvent(new Event('visibilitychange')); - - // Step 4: check the number of calls made to pubx.ai - expect(navigator.sendBeacon.callCount).to.equal(0); - - // Step 5: Send auction end event - events.emit(EVENTS.AUCTION_END, prebidEvent['auctionEnd']); - - // Simulate end of session - document.dispatchEvent(new Event('visibilitychange')); - - // Step 6: check the number of calls made to pubx.ai - expect(navigator.sendBeacon.callCount).to.equal(1); - - // Step 7: check the pathname of the calls is correct (sent only to the auction endpoint) - const [expectedUrl, expectedData] = navigator.sendBeacon.args[0]; - const parsedUrl = new URL(expectedUrl); - expect(parsedUrl.pathname).to.equal('/analytics/auction'); - - // Step 8: check that the meta information in the call is correct - expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ - auctionTimestamp: '1616654312804', - pubxaiAnalyticsVersion: 'v2.1.0', - prebidVersion: '$prebid.version$', - pubxId: pubxId, - }); - - // Step 9: check that the data sent in the request is correct - expect(expectedData.type).to.equal('text/json'); - expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([ - { - ...expectedAfterBid, - bids: [{ - ...expectedAfterBid.bids[0], - bidType: 1 - }] - } - ]); - }); - - it('auction data with only timed out bids', async () => { - // Step 1: Send auction init event - events.emit(EVENTS.AUCTION_INIT, prebidEvent['auctionInit']); - - // Step 2: Send bid requested event - events.emit(EVENTS.BID_REQUESTED, prebidEvent['bidRequested']); - - // Step 3: Send bid rejected (afaict the only expected reason would be a bid being too low) - events.emit(EVENTS.BID_TIMEOUT, [prebidEvent['bidResponse']]); - - // Simulate "navigate away" behaviour - document.dispatchEvent(new Event('visibilitychange')); - - // Step 4: check the number of calls made to pubx.ai - expect(navigator.sendBeacon.callCount).to.equal(0); - - // Step 5: Send auction end event - events.emit(EVENTS.AUCTION_END, prebidEvent['auctionEnd']); - - // Simulate end of session - document.dispatchEvent(new Event('visibilitychange')); - - // Step 6: check the number of calls made to pubx.ai - expect(navigator.sendBeacon.callCount).to.equal(1); - - // Step 7: check the pathname of the calls is correct (sent only to the auction endpoint) - const [expectedUrl, expectedData] = navigator.sendBeacon.args[0]; - const parsedUrl = new URL(expectedUrl); - expect(parsedUrl.pathname).to.equal('/analytics/auction'); - - // Step 8: check that the meta information in the call is correct - expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ - auctionTimestamp: '1616654312804', - pubxaiAnalyticsVersion: 'v2.1.0', - prebidVersion: '$prebid.version$', - pubxId: pubxId, - }); - - // Step 9: check that the data sent in the request is correct - expect(expectedData.type).to.equal('text/json'); - expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([ - { - ...expectedAfterBid, - bids: [{ - ...expectedAfterBid.bids[0], - bidType: 3 - }] - } - ]); - }); - - it('auction with no bids', async () => { - // Step 1: Send auction init event - events.emit(EVENTS.AUCTION_INIT, prebidEvent['auctionInit']); - - // Step 2: Send bid requested event - events.emit(EVENTS.BID_REQUESTED, prebidEvent['bidRequested']); - - // Simulate "navigate away" behaviour - document.dispatchEvent(new Event('visibilitychange')); - - // Step 3: check the number of calls made to pubx.ai - expect(navigator.sendBeacon.callCount).to.equal(0); - - // Step 4: Send auction end event - events.emit(EVENTS.AUCTION_END, prebidEvent['auctionEnd']); - - // Simulate end of session - document.dispatchEvent(new Event('visibilitychange')); - - // Step 5: check the number of calls made to pubx.ai - expect(navigator.sendBeacon.callCount).to.equal(1); - - // Step 6: check the pathname of the calls is correct (sent only to the auction endpoint) - const [expectedUrl, expectedData] = navigator.sendBeacon.args[0]; - const parsedUrl = new URL(expectedUrl); - expect(parsedUrl.pathname).to.equal('/analytics/auction'); - - // Step 7: check that the meta information in the call is correct - expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ - auctionTimestamp: '1616654312804', - pubxaiAnalyticsVersion: 'v2.1.0', - prebidVersion: '$prebid.version$', - pubxId: pubxId, - }); - - // Step 8: check that the data sent in the request is correct - expect(expectedData.type).to.equal('text/json'); - expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([ - { - ...expectedAfterBid, - bids: [], - }, - ]); - }); - - it('2 concurrent auctions', async () => { - // Step 1: Send auction init event for auction 1 - events.emit(EVENTS.AUCTION_INIT, prebidEvent['auctionInit']); - - // Step 2: Send bid requested event for auction 1 - events.emit(EVENTS.BID_REQUESTED, prebidEvent['bidRequested']); - - // Step 3: Send auction init event for auction 2 - events.emit( - EVENTS.AUCTION_INIT, - replaceProperty(prebidEvent['auctionInit'], [ - { - field: 'auctionId', - updated: '"auction2"', - replaced: '"bc3806e4-873e-453c-8ae5-204f35e923b4"', - }, - ]) - ); - - // Step 4: Send bid requested event for auction 2 - events.emit( - EVENTS.BID_REQUESTED, - replaceProperty(prebidEvent['bidRequested'], [ - { - field: 'auctionId', - updated: '"auction2"', - replaced: '"bc3806e4-873e-453c-8ae5-204f35e923b4"', - }, - ]) - ); - - // Step 5: Send bid response event for auction 1 - events.emit(EVENTS.BID_RESPONSE, prebidEvent['bidResponse']); - - // Step 6: Send bid time out event for auction 1 - events.emit(EVENTS.BID_TIMEOUT, prebidEvent['bidTimeout']); - - // Step 7: Send bid response event for auction 2 - events.emit( - EVENTS.BID_RESPONSE, - replaceProperty(prebidEvent['bidResponse'], [ - { - field: 'auctionId', - updated: '"auction2"', - replaced: '"bc3806e4-873e-453c-8ae5-204f35e923b4"', - }, - ]) - ); - - // Step 8: Send auction end event for auction 1 - events.emit(EVENTS.AUCTION_END, prebidEvent['auctionEnd']); - - // Simulate "navigate away" behaviour - document.dispatchEvent(new Event('visibilitychange')); - - // Step 9: check the number of calls made to pubx.ai - expect(navigator.sendBeacon.callCount).to.equal(0); - - // Step 10: Send auction bid won event for auction 1 - events.emit(EVENTS.BID_WON, prebidEvent['bidWon']); - - // Simulate "navigate away" behaviour - document.dispatchEvent(new Event('visibilitychange')); - - // Step 11: check the number of calls made to pubx.ai - expect(navigator.sendBeacon.callCount).to.equal(2); - - // Step 12: Send auction end event for auction 2 - events.emit( - EVENTS.AUCTION_END, - replaceProperty(prebidEvent['auctionEnd'], [ - { - field: 'auctionId', - updated: '"auction2"', - replaced: '"bc3806e4-873e-453c-8ae5-204f35e923b4"', - }, - ]) - ); - - // Simulate "navigate away" behaviour - document.dispatchEvent(new Event('visibilitychange')); - - // Step 13: check the number of calls made to pubx.ai - expect(navigator.sendBeacon.callCount).to.equal(2); - - // Step 14: Send auction bid won event for auction 2 - events.emit( - EVENTS.BID_WON, - replaceProperty(prebidEvent['bidWon'], [ - { - field: 'auctionId', - updated: '"auction2"', - replaced: '"bc3806e4-873e-453c-8ae5-204f35e923b4"', - }, - ]) - ); - - // Simulate end of session - document.dispatchEvent(new Event('visibilitychange')); - - // Step 15: check the calls made to pubx.ai - expect(navigator.sendBeacon.callCount).to.equal(4); - for (const [index, arg] of navigator.sendBeacon.args.entries()) { - const [expectedUrl, expectedData] = arg; - const parsedUrl = new URL(expectedUrl); - const auctionIdMapFn = index < 2 ? (i, _) => i : replaceProperty; - expect(parsedUrl.pathname).to.equal( - ['/analytics/bidwon', '/analytics/auction'][index % 2] - ); - expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ - auctionTimestamp: '1616654312804', - pubxaiAnalyticsVersion: 'v2.1.0', - prebidVersion: '$prebid.version$', - pubxId: pubxId, - }); - expect(expectedData.type).to.equal('text/json'); - expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([ - auctionIdMapFn([expectedAfterBidWon, expectedAfterBid][index % 2], [ - { - field: 'auctionId', - updated: '"auction2"', - replaced: '"bc3806e4-873e-453c-8ae5-204f35e923b4"', - }, - { - field: 'refreshRank', - updated: '1', - replaced: '0', - }, - ]), - ]); - } - }); - - it('2 concurrent auctions with batch sending', async () => { - // Step 1: Send auction init event for auction 1 - events.emit(EVENTS.AUCTION_INIT, prebidEvent['auctionInit']); - - // Step 2: Send bid requested event for auction 1 - events.emit(EVENTS.BID_REQUESTED, prebidEvent['bidRequested']); - - // Step 3: Send auction init event for auction 2 - events.emit( - EVENTS.AUCTION_INIT, - replaceProperty(prebidEvent['auctionInit'], [ - { - field: 'auctionId', - updated: '"auction2"', - replaced: '"bc3806e4-873e-453c-8ae5-204f35e923b4"', - }, - ]) - ); - - // Step 4: Send bid requested event for auction 2 - events.emit( - EVENTS.BID_REQUESTED, - replaceProperty(prebidEvent['bidRequested'], [ - { - field: 'auctionId', - updated: '"auction2"', - replaced: '"bc3806e4-873e-453c-8ae5-204f35e923b4"', - }, - ]) - ); - - // Step 5: Send bid response event for auction 1 - events.emit(EVENTS.BID_RESPONSE, prebidEvent['bidResponse']); - - // Step 6: Send bid time out event for auction 1 - events.emit(EVENTS.BID_TIMEOUT, prebidEvent['bidTimeout']); - - // Step 7: Send bid response event for auction 2 - events.emit( - EVENTS.BID_RESPONSE, - replaceProperty(prebidEvent['bidResponse'], [ - { - field: 'auctionId', - updated: '"auction2"', - replaced: '"bc3806e4-873e-453c-8ae5-204f35e923b4"', - }, - ]) - ); - - // Step 8: Send auction end event for auction 1 - events.emit(EVENTS.AUCTION_END, prebidEvent['auctionEnd']); - - // Step 9: Send auction bid won event for auction 1 - events.emit(EVENTS.BID_WON, prebidEvent['bidWon']); - - // Step 10: Send auction end event for auction 2 - events.emit( - EVENTS.AUCTION_END, - replaceProperty(prebidEvent['auctionEnd'], [ - { - field: 'auctionId', - updated: '"auction2"', - replaced: '"bc3806e4-873e-453c-8ae5-204f35e923b4"', - }, - ]) - ); - - // Step 11: Send auction bid won event for auction 2 - events.emit( - EVENTS.BID_WON, - replaceProperty(prebidEvent['bidWon'], [ - { - field: 'auctionId', - updated: '"auction2"', - replaced: '"bc3806e4-873e-453c-8ae5-204f35e923b4"', - }, - ]) - ); - - // Step 12: check the number of calls made to pubx.ai - expect(navigator.sendBeacon.callCount).to.equal(0); - - // Simulate end of session - document.dispatchEvent(new Event('visibilitychange')); - - // Step 13: check the calls made to pubx.ai - expect(navigator.sendBeacon.callCount).to.equal(2); - for (const [index, arg] of navigator.sendBeacon.args.entries()) { - const [expectedUrl, expectedData] = arg; - const parsedUrl = new URL(expectedUrl); - expect(parsedUrl.pathname).to.equal( - ['/analytics/bidwon', '/analytics/auction'][index] - ); - expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ - auctionTimestamp: '1616654312804', - pubxaiAnalyticsVersion: 'v2.1.0', - prebidVersion: '$prebid.version$', - pubxId: pubxId, - }); - expect(expectedData.type).to.equal('text/json'); - expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([ - [expectedAfterBidWon, expectedAfterBid][index], - replaceProperty([expectedAfterBidWon, expectedAfterBid][index], [ - { - field: 'auctionId', - updated: '"auction2"', - replaced: '"bc3806e4-873e-453c-8ae5-204f35e923b4"', - }, - { - field: 'refreshRank', - updated: '1', - replaced: '0', - }, - ]), - ]); - } - }); - }); -}); diff --git a/test/spec/modules/pubxaiRtdProvider_spec.js b/test/spec/modules/pubxaiRtdProvider_spec.js deleted file mode 100644 index 76d878263..000000000 --- a/test/spec/modules/pubxaiRtdProvider_spec.js +++ /dev/null @@ -1,429 +0,0 @@ -import * as priceFloors from '../../../modules/priceFloors.js'; -import { - FLOORS_END_POINT, - storage, - FLOORS_EVENT_HANDLE, - FloorsApiStatus, - beforeInit, - fetchFloorRules, - getFloorsConfig, - getUrl, - pubxaiSubmodule, - setDefaultPriceFloors, - setFloorsApiStatus, - setFloorsConfig, - setPriceFloors, -} from '../../../modules/pubxaiRtdProvider.js'; -import { config } from '../../../src/config.js'; -import * as hook from '../../../src/hook.js'; -import { server } from '../../mocks/xhr.js'; - -const getConfig = () => ({ - params: { - useRtd: true, - endpoint: 'http://pubxai.com:3001/floors', - data: { - currency: 'EUR', - floorProvider: 'PubxFloorProvider', - modelVersion: 'gpt-mvm_AB_0.50_dt_0.75_dwt_0.95_dnt_0.25_fm_0.50', - schema: { fields: ['gptSlot', 'mediaType'] }, - values: { '*|banner': 0.02 }, - }, - }, -}); - -const getFloorsResponse = () => ({ - currency: 'USD', - floorProvider: 'PubxFloorProvider', - modelVersion: 'gpt-mvm_AB_0.50_dt_0.75_dwt_0.95_dnt_0.25_fm_0.50', - schema: { fields: ['gptSlot', 'mediaType'] }, - values: { '*|banner': 0.02 }, -}); - -const resetGlobals = () => { - window.__pubxLoaded__ = undefined; - window.__pubxPrevFloorsConfig__ = undefined; - window.__pubxFloorsConfig__ = undefined; - window.__pubxFloorsApiStatus__ = undefined; - window.__pubxFloorRulesPromise__ = null; - localStorage.removeItem('pubx:dynamicFloors'); -}; - -const fakeServer = ( - fakeResponse = '', - providerConfig = undefined, - statusCode = 200 -) => { - const fakeResponseHeaders = { - 'Content-Type': 'application/json', - 'Access-Control-Allow-Origin': '*', - }; - const request = server.requests[0]; - request.respond( - statusCode, - fakeResponseHeaders, - fakeResponse ? JSON.stringify(fakeResponse) : '' - ); - return request; -}; - -const stubConfig = () => { - const stub = sinon.stub(config, 'setConfig'); - return stub; -}; - -describe('pubxaiRtdProvider', () => { - describe('beforeInit', () => { - it('should register RTD submodule provider', function () { - const submoduleStub = sinon.stub(hook, 'submodule'); - beforeInit(); - assert(submoduleStub.calledOnceWith('realTimeData', pubxaiSubmodule)); - submoduleStub.restore(); - }); - }); - describe('submodule', () => { - describe('name', function () { - it('should be pubxai', function () { - expect(pubxaiSubmodule.name).to.equal('pubxai'); - }); - }); - }); - describe('init', () => { - let stub; - beforeEach(() => { - resetGlobals(); - stub = stubConfig(); - }); - afterEach(() => { - stub.restore(); - }); - it('standard case - returns true', () => { - const initResult = pubxaiSubmodule.init({ params: { useRtd: true } }); - expect(initResult).to.be.true; - }); - it('setPriceFloors called when `useRtd` is true in the provider config', () => { - pubxaiSubmodule.init(getConfig()); - expect(window.__pubxLoaded__).to.equal(true); - }); - }); - describe('getBidRequestData', () => { - const reqBidsConfigObj = { - adUnits: [{ code: 'ad-slot-code-0' }], - auctionId: 'auction-id-0', - }; - let stub; - beforeEach(() => { - window.__pubxFloorRulesPromise__ = Promise.resolve(); - stub = sinon.stub(priceFloors, 'createFloorsDataForAuction'); - }); - afterEach(() => { - resetGlobals(); - stub.restore(); - }); - it('createFloorsDataForAuction called once before and once after __pubxFloorRulesPromise__. Also getBidRequestData executed only once', async () => { - pubxaiSubmodule.getBidRequestData(reqBidsConfigObj, () => { }); - assert(priceFloors.createFloorsDataForAuction.calledOnce); - await window.__pubxFloorRulesPromise__; - assert(priceFloors.createFloorsDataForAuction.calledTwice); - assert( - priceFloors.createFloorsDataForAuction.alwaysCalledWith( - reqBidsConfigObj.adUnits, - reqBidsConfigObj.auctionId - ) - ); - pubxaiSubmodule.getBidRequestData(reqBidsConfigObj, () => { }); - await window.__pubxFloorRulesPromise__; - assert(priceFloors.createFloorsDataForAuction.calledTwice); - }); - }); - describe('fetchFloorRules', () => { - const providerConfig = getConfig(); - const floorsResponse = getFloorsResponse(); - let storageStub; - - beforeEach(() => { - storageStub = sinon.stub(storage, 'getDataFromSessionStorage'); - }); - - afterEach(() => { - storageStub.restore(); - }); - - it('success with floors response', (done) => { - const promise = fetchFloorRules(providerConfig); - fakeServer(floorsResponse); - promise.then((res) => { - expect(res).to.deep.equal(floorsResponse); - done(); - }); - }); - - it('success with no floors response', (done) => { - const promise = fetchFloorRules(providerConfig); - fakeServer(undefined); - promise.then((res) => { - expect(res).to.deep.equal(null); - done(); - }); - }); - - it('API call error', (done) => { - const promise = fetchFloorRules(providerConfig); - fakeServer(undefined, undefined, 404); - promise - .then((res) => { - expect(true).to.be.false; - }) - .catch((e) => { - expect(e).to.not.be.undefined; - }) - .finally(() => { - done(); - }); - }); - - it('Wrong API response', (done) => { - const promise = fetchFloorRules(providerConfig); - fakeServer('floorsResponse'); - promise - .then((res) => { - expect(true).to.be.false; - }) - .catch((e) => { - expect(e).to.not.be.undefined; - }) - .finally(() => { - done(); - }); - }); - - it('success with local data response', (done) => { - const localFloorsResponse = getFloorsResponse(); - storageStub.withArgs('pubx:dynamicFloors').returns(JSON.stringify(localFloorsResponse)); - const promise = fetchFloorRules({ params: {} }); - promise.then((res) => { - expect(res).to.deep.equal(localFloorsResponse); - done(); - }); - }); - - it('no local data response', (done) => { - storageStub.withArgs('pubx:dynamicFloors').returns(null); - const promise = fetchFloorRules({ params: {} }); - promise.then((res) => { - expect(res).to.deep.equal(null); - done(); - }); - }); - }); - describe('setPriceFloors', () => { - const providerConfig = getConfig(); - const floorsResponse = getFloorsResponse(); - let stub; - beforeEach(() => { - resetGlobals(); - stub = stubConfig(); - }); - afterEach(() => { - stub.restore(); - }); - it('with floors response', (done) => { - const floorsPromise = setPriceFloors(providerConfig); - fakeServer(floorsResponse); - expect(window.__pubxLoaded__).to.be.true; - expect(window.__pubxFloorsConfig__).to.deep.equal( - getFloorsConfig(providerConfig, providerConfig.params.data) - ); - floorsPromise.then(() => { - expect(window.__pubxLoaded__).to.be.true; - expect(window.__pubxFloorsConfig__).to.deep.equal( - getFloorsConfig(providerConfig, floorsResponse) - ); - done(); - }); - }); - it('without floors response', (done) => { - const floorsPromise = setPriceFloors(providerConfig); - fakeServer(undefined); - expect(window.__pubxLoaded__).to.be.true; - expect(window.__pubxFloorsConfig__).to.deep.equal( - getFloorsConfig(providerConfig, providerConfig.params.data) - ); - floorsPromise.then(() => { - expect(window.__pubxLoaded__).to.be.false; - expect(window.__pubxFloorsConfig__).to.deep.equal(null); - done(); - }); - }); - it('default floors', (done) => { - const floorsPromise = setPriceFloors(providerConfig); - fakeServer(undefined, undefined, 404); - expect(window.__pubxLoaded__).to.be.true; - expect(window.__pubxFloorsConfig__).to.deep.equal( - getFloorsConfig(providerConfig, providerConfig.params.data) - ); - floorsPromise - .then(() => { - expect(true).to.be.false; - }) - .catch((e) => { - expect(window.__pubxLoaded__).to.be.true; - expect(window.__pubxFloorsConfig__).to.deep.equal( - getFloorsConfig(providerConfig, providerConfig.params.data) - ); - }) - .finally(() => { - done(); - }); - }); - }); - describe('setFloorsConfig', () => { - const providerConfig = getConfig(); - let stub; - beforeEach(() => { - resetGlobals(); - stub = stubConfig(); - }); - afterEach(function () { - stub.restore(); - }); - it('non-empty floorResponse', () => { - const floorsResponse = getFloorsResponse(); - setFloorsConfig(providerConfig, floorsResponse); - const floorsConfig = getFloorsConfig(providerConfig, floorsResponse); - assert(config.setConfig.calledOnceWith(floorsConfig)); - expect(window.__pubxLoaded__).to.be.true; - expect(window.__pubxFloorsConfig__).to.deep.equal(floorsConfig); - }); - it('empty floorResponse', () => { - const floorsResponse = null; - setFloorsConfig(providerConfig, floorsResponse); - assert(config.setConfig.calledOnceWith({ floors: undefined })); - expect(window.__pubxLoaded__).to.be.false; - expect(window.__pubxFloorsConfig__).to.be.null; - }); - }); - describe('getFloorsConfig', () => { - let providerConfig; - const floorsResponse = getFloorsResponse(); - beforeEach(() => { - providerConfig = getConfig(); - }); - it('no customizations in the provider config', () => { - const result = getFloorsConfig(providerConfig, floorsResponse); - expect(result).to.deep.equal({ - floors: { - enforcement: { floorDeals: true }, - data: floorsResponse, - }, - }); - }); - it('only floormin in the provider config', () => { - providerConfig.params.floorMin = 2; - expect(getFloorsConfig(providerConfig, floorsResponse)).to.deep.equal({ - floors: { - enforcement: { floorDeals: true }, - floorMin: 2, - data: floorsResponse, - }, - }); - }); - it('only enforcement in the provider config', () => { - providerConfig.params.enforcement = { - bidAdjustment: true, - enforceJS: false, - }; - expect(getFloorsConfig(providerConfig, floorsResponse)).to.deep.equal({ - floors: { - enforcement: { - bidAdjustment: true, - enforceJS: false, - }, - data: floorsResponse, - }, - }); - }); - it('both floorMin and enforcement in the provider config', () => { - providerConfig.params.floorMin = 2; - providerConfig.params.enforcement = { - bidAdjustment: true, - enforceJS: false, - }; - expect(getFloorsConfig(providerConfig, floorsResponse)).to.deep.equal({ - floors: { - enforcement: { - bidAdjustment: true, - enforceJS: false, - }, - floorMin: 2, - data: floorsResponse, - }, - }); - }); - }); - describe('setDefaultPriceFloors', () => { - let stub; - beforeEach(() => { - resetGlobals(); - stub = stubConfig(); - }); - afterEach(function () { - stub.restore(); - }); - it('should set default floors config', () => { - const providerConfig = getConfig(); - setDefaultPriceFloors(providerConfig); - assert( - config.setConfig.calledOnceWith( - getFloorsConfig(providerConfig, providerConfig.params.data) - ) - ); - expect(window.__pubxLoaded__).to.be.true; - }); - }); - describe('setFloorsApiStatus', () => { - let stub; - beforeEach(() => { - resetGlobals(); - stub = sinon.stub(window, 'dispatchEvent'); - }); - afterEach(function () { - stub.restore(); - }); - it('set status', () => { - setFloorsApiStatus(FloorsApiStatus.SUCCESS); - expect(window.__pubxFloorsApiStatus__).to.equal(FloorsApiStatus.SUCCESS); - }); - it('dispatch event', () => { - setFloorsApiStatus(FloorsApiStatus.SUCCESS); - assert( - window.dispatchEvent.calledOnceWith( - new CustomEvent(FLOORS_EVENT_HANDLE, { - detail: { status: FloorsApiStatus.SUCCESS }, - }) - ) - ); - }); - }); - describe('getUrl', () => { - const provider = { - name: 'pubxai', - waitForIt: true, - params: { - pubxId: '12345', - }, - }; - it('floors end point', () => { - expect(FLOORS_END_POINT).to.equal('https://floor.pbxai.com/'); - }); - it('standard case', () => { - expect(getUrl(provider)).to.equal(null); - }); - it('custom url provided', () => { - provider.params.endpoint = 'https://custom.floor.com/'; - expect(getUrl(provider)).to.equal( - `https://custom.floor.com/?pubxId=12345&page=${window.location.href}` - ); - }); - }); -}); diff --git a/test/spec/modules/pulsepointBidAdapter_spec.js b/test/spec/modules/pulsepointBidAdapter_spec.js deleted file mode 100644 index a13b285b6..000000000 --- a/test/spec/modules/pulsepointBidAdapter_spec.js +++ /dev/null @@ -1,706 +0,0 @@ -/* eslint dot-notation:0, quote-props:0 */ -import {expect} from 'chai'; -import {spec} from 'modules/pulsepointBidAdapter.js'; -import {addFPDToBidderRequest} from '../../helpers/fpd.js'; -import {deepClone} from '../../../src/utils.js'; -import 'modules/consentManagementTcf'; -import 'modules/consentManagementUsp'; -import 'modules/userId/index'; - -describe('PulsePoint Adapter Tests', function () { - const slotConfigs = [{ - placementCode: '/DfpAccount1/slot1', - mediaTypes: { - banner: { - sizes: [[728, 90], [160, 600]] - } - }, - bidId: 'bid12345', - params: { - cp: 'p10000', - ct: 't10000', - cf: '300x250' - } - }, { - placementCode: '/DfpAccount2/slot2', - mediaTypes: { - banner: { - sizes: [[728, 90]] - } - }, - bidId: 'bid23456', - params: { - cp: 'p10000', - ct: 't20000', - cf: '728x90' - } - }]; - const nativeOrtbRequest = { - assets: [{ - id: 1, - required: 1, - img: { - type: 3, - w: 150, - h: 50, - } - }, - { - id: 2, - required: 1, - title: { - len: 80 - } - }, - { - id: 3, - required: 0, - data: { - type: 1 - } - }] - }; - const nativeSlotConfig = [{ - placementCode: '/DfpAccount1/slot3', - bidId: 'bid12345', - mediaTypes: { - native: { - ortb: nativeOrtbRequest - } - }, - nativeOrtbRequest, - params: { - cp: 'p10000', - ct: 't10000' - } - }]; - const videoSlotConfig = [{ - placementCode: '/DfpAccount1/slotVideo', - bidId: 'bid12345', - mediaTypes: { - video: { - playerSize: [400, 300], - w: 400, - h: 300, - minduration: 5, - maxduration: 10, - startdelay: 0, - skip: 1, - minbitrate: 200, - protocols: [1, 2, 4] - } - }, - params: { - cp: 'p10000', - ct: 't10000' - } - }]; - const additionalParamsConfig = [{ - placementCode: '/DfpAccount1/slot1', - mediaTypes: { - banner: { - sizes: [[1, 1]] - } - }, - bidId: 'bid12345', - params: { - cp: 'p10000', - ct: 't10000', - cf: '1x1', - extra_key1: 'extra_val1', - extra_key2: 12345, - extra_key3: { - key1: 'val1', - key2: 23456, - }, - extra_key4: [1, 2, 3] - } - }]; - - const schainParamsSlotConfig = [{ - placementCode: '/DfpAccount1/slot1', - mediaTypes: { - banner: { - sizes: [[1, 1]] - } - }, - bidId: 'bid12345', - params: { - cp: 'p10000', - ct: 't10000', - cf: '1x1', - bcat: ['IAB-1', 'IAB-20'], - battr: [1, 2, 3], - bidfloor: 1.5, - badv: ['cocacola.com', 'lays.com'] - }, - ortb2: {source: {ext: {schain: { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'exchange1.com', - 'sid': '1234', - 'hp': 1, - 'rid': 'bid-request-1', - 'name': 'publisher', - 'domain': 'publisher.com' - } - ] - }}}} - }]; - - const bidderRequest = { - refererInfo: { - page: 'https://publisher.com/home', - ref: 'https://referrer' - } - }; - - it('Verify build request', async function () { - const request = spec.buildRequests(slotConfigs, await addFPDToBidderRequest(bidderRequest)); - expect(request.url).to.equal('https://bid.contextweb.com/header/ortb?src=prebid'); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - // site object - expect(ortbRequest.site).to.not.equal(null); - expect(ortbRequest.site.publisher).to.not.equal(null); - expect(ortbRequest.site.publisher.id).to.equal('p10000'); - expect(ortbRequest.site.page).to.equal('https://publisher.com/home'); - expect(ortbRequest.imp).to.have.lengthOf(2); - // device object - expect(ortbRequest.device).to.not.equal(null); - expect(ortbRequest.device.ua).to.equal(navigator.userAgent); - // slot 1 - expect(ortbRequest.imp[0].tagid).to.equal('t10000'); - expect(ortbRequest.imp[0].banner).to.not.equal(null); - expect(ortbRequest.imp[0].banner.format).to.deep.eq([{'w': 728, 'h': 90}, {'w': 160, 'h': 600}]); - // slot 2 - expect(ortbRequest.imp[1].tagid).to.equal('t20000'); - expect(ortbRequest.imp[1].banner).to.not.equal(null); - expect(ortbRequest.imp[1].banner.format).to.deep.eq([{'w': 728, 'h': 90}]); - }); - - it('Verify parse response', async function () { - const request = spec.buildRequests(slotConfigs, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - const ortbResponse = { - seatbid: [{ - bid: [{ - impid: ortbRequest.imp[0].id, - price: 1.25, - adm: 'This is an Ad', - crid: 'Creative#123', - mtype: 1, - w: 300, - h: 250, - exp: 20, - adomain: ['advertiser.com'] - }] - }] - }; - const bids = spec.interpretResponse({body: ortbResponse}, request); - expect(bids).to.have.lengthOf(1); - // verify first bid - const bid = bids[0]; - expect(bid.cpm).to.equal(1.25); - expect(bid.ad).to.equal('This is an Ad'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creative_id).to.equal('Creative#123'); - expect(bid.creativeId).to.equal('Creative#123'); - expect(bid.netRevenue).to.equal(true); - expect(bid.currency).to.equal('USD'); - expect(bid.ttl).to.equal(20); - expect(bid.meta).to.not.be.null; - expect(bid.meta.advertiserDomains).to.eql(['advertiser.com']); - }); - - it('Verify full passback', function () { - const request = spec.buildRequests(slotConfigs, bidderRequest); - const bids = spec.interpretResponse({body: null}, request) - expect(bids).to.have.lengthOf(0); - }); - - if (FEATURES.NATIVE) { - it('Verify Native request', async function () { - const request = spec.buildRequests(nativeSlotConfig, await addFPDToBidderRequest(bidderRequest)); - expect(request.url).to.equal('https://bid.contextweb.com/header/ortb?src=prebid'); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - // native impression - expect(ortbRequest.imp[0].tagid).to.equal('t10000'); - expect(ortbRequest.imp[0].banner).to.be.undefined; - const nativePart = ortbRequest.imp[0]['native']; - expect(nativePart).to.not.equal(null); - expect(nativePart.request).to.not.equal(null); - // native request assets - const nativeRequest = JSON.parse(ortbRequest.imp[0]['native'].request); - expect(nativeRequest).to.not.equal(null); - expect(nativeRequest.assets).to.have.lengthOf(3); - // image asset - expect(nativeRequest.assets[0].id).to.equal(1); - expect(nativeRequest.assets[0].required).to.equal(1); - expect(nativeRequest.assets[0].title).to.be.undefined; - expect(nativeRequest.assets[0].img).to.not.equal(null); - expect(nativeRequest.assets[0].img.w).to.equal(150); - expect(nativeRequest.assets[0].img.h).to.equal(50); - expect(nativeRequest.assets[0].img.type).to.equal(3); - // title asset - expect(nativeRequest.assets[1].id).to.equal(2); - expect(nativeRequest.assets[1].required).to.equal(1); - expect(nativeRequest.assets[1].title).to.not.equal(null); - expect(nativeRequest.assets[1].title.len).to.equal(80); - // data asset - expect(nativeRequest.assets[2].id).to.equal(3); - expect(nativeRequest.assets[2].required).to.equal(0); - expect(nativeRequest.assets[2].title).to.be.undefined; - expect(nativeRequest.assets[2].data).to.not.equal(null); - expect(nativeRequest.assets[2].data.type).to.equal(1); - }); - - it('Verify Native response', async function () { - const request = spec.buildRequests(nativeSlotConfig, await addFPDToBidderRequest(bidderRequest)); - expect(request.url).to.equal('https://bid.contextweb.com/header/ortb?src=prebid'); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - const nativeResponse = { - assets: [ - {id: 1, img: {type: 3, url: 'https://images.cdn.brand.com/123'}}, - {id: 2, title: {text: 'Ad Title'}}, - {id: 3, data: {type: 1, value: 'Sponsored By: Brand'}} - ], - link: {url: 'https://brand.clickme.com/'}, - imptrackers: ['https://imp1.trackme.com/', 'https://imp1.contextweb.com/'] - - }; - const ortbResponse = { - seatbid: [{ - bid: [{ - impid: ortbRequest.imp[0].id, - price: 1.25, - adm: JSON.stringify(nativeResponse), - mtype: 4 - }] - }] - }; - const bids = spec.interpretResponse({body: ortbResponse}, request); - // verify bid - const bid = bids[0]; - expect(bid.cpm).to.equal(1.25); - expect(bid.requestId).to.equal('bid12345'); - expect(bid.ad).to.be.undefined; - expect(bid.mediaType).to.equal('native'); - expect(bid['native']).to.not.be.null; - expect(bid['native'].ortb).to.not.be.null; - const nativeBid = bid['native'].ortb; - expect(nativeBid.assets).to.have.lengthOf(3); - expect(nativeBid.assets[0].id).to.equal(1); - expect(nativeBid.assets[0].img).to.not.be.null; - expect(nativeBid.assets[0].img.type).to.equal(3); - expect(nativeBid.assets[0].img.url).to.equal('https://images.cdn.brand.com/123'); - expect(nativeBid.assets[1].id).to.equal(2); - expect(nativeBid.assets[1].title).to.not.be.null; - expect(nativeBid.assets[1].title.text).to.equal('Ad Title'); - expect(nativeBid.assets[2].id).to.equal(3); - expect(nativeBid.assets[2].data).to.not.be.null; - expect(nativeBid.assets[2].data.type).to.equal(1); - expect(nativeBid.assets[2].data.value).to.equal('Sponsored By: Brand'); - expect(nativeBid.link).to.not.be.null; - expect(nativeBid.link.url).to.equal('https://brand.clickme.com/'); - expect(nativeBid.imptrackers).to.have.lengthOf(2); - expect(nativeBid.imptrackers[0]).to.equal('https://imp1.trackme.com/'); - expect(nativeBid.imptrackers[1]).to.equal('https://imp1.contextweb.com/'); - }); - } - - it('Verifies bidder code', function () { - expect(spec.code).to.equal('pulsepoint'); - }); - - it('Verifies bidder aliases', function () { - expect(spec.aliases).to.have.lengthOf(2); - expect(spec.aliases[0]).to.equal('pulseLite'); - expect(spec.aliases[1]).to.equal('pulsepointLite'); - }); - - it('Verifies supported media types', function () { - expect(spec.supportedMediaTypes).to.have.lengthOf(3); - expect(spec.supportedMediaTypes[0]).to.equal('banner'); - expect(spec.supportedMediaTypes[1]).to.equal('native'); - expect(spec.supportedMediaTypes[2]).to.equal('video'); - }); - - it('Verifies if bid request valid', function () { - expect(spec.isBidRequestValid(slotConfigs[0])).to.equal(true); - expect(spec.isBidRequestValid(slotConfigs[1])).to.equal(true); - expect(spec.isBidRequestValid(nativeSlotConfig[0])).to.equal(true); - expect(spec.isBidRequestValid({})).to.equal(false); - expect(spec.isBidRequestValid({ params: {} })).to.equal(false); - expect(spec.isBidRequestValid({ params: { ct: 123 } })).to.equal(false); - expect(spec.isBidRequestValid({ params: { cp: 123 } })).to.equal(false); - expect(spec.isBidRequestValid({ params: { ct: 123, cp: 234 } })).to.equal(true); - }); - - it('Verifies sync options', function () { - expect(spec.getUserSyncs({})).to.be.undefined; - expect(spec.getUserSyncs({ iframeEnabled: false })).to.be.undefined; - const options = spec.getUserSyncs({ iframeEnabled: true }); - expect(options).to.not.be.undefined; - expect(options).to.have.lengthOf(1); - expect(options[0].type).to.equal('iframe'); - expect(options[0].url).to.equal('https://bh.contextweb.com/visitormatch'); - }); - - it('Verifies image pixel sync', function () { - const options = spec.getUserSyncs({ pixelEnabled: true }); - expect(options).to.not.be.undefined; - expect(options).to.have.lengthOf(1); - expect(options[0].type).to.equal('image'); - expect(options[0].url).to.equal('https://bh.contextweb.com/visitormatch/prebid'); - }); - - it('Verify GDPR', async function () { - const bidderRequestGdpr = { - gdprConsent: { - gdprApplies: true, - consentString: 'serialized_gdpr_data' - } - }; - const request = spec.buildRequests(slotConfigs, await addFPDToBidderRequest(Object.assign({}, bidderRequest, bidderRequestGdpr))); - expect(request.url).to.equal('https://bid.contextweb.com/header/ortb?src=prebid'); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - // user object - expect(ortbRequest.user).to.not.equal(null); - expect(ortbRequest.user.ext).to.not.equal(null); - expect(ortbRequest.user.ext.consent).to.equal('serialized_gdpr_data'); - // regs object - expect(ortbRequest.regs).to.not.equal(null); - expect(ortbRequest.regs.ext).to.not.equal(null); - expect(ortbRequest.regs.ext.gdpr).to.equal(1); - }); - - it('Verify CCPA', async function () { - const bidderRequestUSPrivacy = { - uspConsent: '1YYY' - }; - const request = spec.buildRequests(slotConfigs, - await addFPDToBidderRequest(Object.assign({}, bidderRequest, bidderRequestUSPrivacy))); - expect(request.url).to.equal('https://bid.contextweb.com/header/ortb?src=prebid'); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - // regs object - expect(ortbRequest.regs).to.not.equal(null); - expect(ortbRequest.regs.ext).to.not.equal(null); - expect(ortbRequest.regs.ext.us_privacy).to.equal('1YYY'); - }); - - if (FEATURES.VIDEO) { - it('Verify Video request', async function () { - const request = spec.buildRequests(videoSlotConfig, await addFPDToBidderRequest(bidderRequest)); - expect(request.url).to.equal('https://bid.contextweb.com/header/ortb?src=prebid'); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - expect(ortbRequest).to.not.equal(null); - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].video).to.not.be.null; - expect(ortbRequest.imp[0].native).to.be.undefined; - expect(ortbRequest.imp[0].banner).to.be.undefined; - expect(ortbRequest.imp[0].video.w).to.equal(400); - expect(ortbRequest.imp[0].video.h).to.equal(300); - expect(ortbRequest.imp[0].video.minduration).to.equal(5); - expect(ortbRequest.imp[0].video.maxduration).to.equal(10); - expect(ortbRequest.imp[0].video.startdelay).to.equal(0); - expect(ortbRequest.imp[0].video.skip).to.equal(1); - expect(ortbRequest.imp[0].video.minbitrate).to.equal(200); - expect(ortbRequest.imp[0].video.protocols).to.eql([1, 2, 4]); - }); - - it('Verify Video response', function () { - const request = spec.buildRequests(videoSlotConfig, bidderRequest); - expect(request.url).to.equal('https://bid.contextweb.com/header/ortb?src=prebid'); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - const ortbResponse = { - seatbid: [{ - bid: [{ - impid: ortbRequest.imp[0].id, - price: 1.25, - adm: 'https//pulsepoint.video.mp4', - mtype: 2 - }] - }] - }; - const bids = spec.interpretResponse({ body: ortbResponse }, request); - const bid = bids[0]; - expect(bid.cpm).to.equal(1.25); - expect(bid.ad).to.be.undefined; - expect(bid['native']).to.be.undefined; - expect(bid.mediaType).to.equal('video'); - expect(bid.vastXml).to.equal(ortbResponse.seatbid[0].bid[0].adm); - }); - } - - it('Verify extra parameters', async function () { - let request = spec.buildRequests(additionalParamsConfig, await addFPDToBidderRequest(bidderRequest)); - let ortbRequest = request.data; - expect(ortbRequest).to.not.equal(null); - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].ext).to.not.equal(null); - expect(ortbRequest.imp[0].ext.prebid).to.not.equal(null); - expect(ortbRequest.imp[0].ext.prebid).to.not.be.null; - expect(ortbRequest.imp[0].ext.prebid.extra_key1).to.equal('extra_val1'); - expect(ortbRequest.imp[0].ext.prebid.extra_key2).to.equal(12345); - expect(ortbRequest.imp[0].ext.prebid.extra_key3).to.not.be.null; - expect(ortbRequest.imp[0].ext.prebid.extra_key3.key1).to.equal('val1'); - expect(ortbRequest.imp[0].ext.prebid.extra_key3.key2).to.equal(23456); - expect(ortbRequest.imp[0].ext.prebid.extra_key4).to.eql([1, 2, 3]); - expect(Object.keys(ortbRequest.imp[0].ext.prebid)).to.eql(['extra_key1', 'extra_key2', 'extra_key3', 'extra_key4']); - // attempting with a configuration with no unknown params. - request = spec.buildRequests(videoSlotConfig, bidderRequest); - ortbRequest = request.data; - expect(ortbRequest).to.not.equal(null); - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].ext).to.be.undefined; - }); - - it('Verify schain parameters', function () { - const modifiedBidderRequest = { - ...bidderRequest, - ortb2: { - source: { - ext: { - schain: { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'exchange1.com', - 'sid': '1234', - 'hp': 1, - 'rid': 'bid-request-1', - 'name': 'publisher', - 'domain': 'publisher.com' - } - ] - } - } - } - } - }; - const request = spec.buildRequests(schainParamsSlotConfig, modifiedBidderRequest); - const ortbRequest = request.data; - expect(ortbRequest).to.not.equal(null); - expect(ortbRequest.source).to.not.equal(null); - expect(ortbRequest.source.ext).to.not.equal(null); - expect(ortbRequest.source.ext.schain).to.not.equal(null); - expect(ortbRequest.source.ext.schain.complete).to.equal(1); - expect(ortbRequest.source.ext.schain.ver).to.equal('1.0'); - expect(ortbRequest.source.ext.schain.nodes).to.not.equal(null); - expect(ortbRequest.source.ext.schain.nodes).to.lengthOf(1); - expect(ortbRequest.source.ext.schain.nodes[0].asi).to.equal('exchange1.com'); - expect(ortbRequest.source.ext.schain.nodes[0].sid).to.equal('1234'); - expect(ortbRequest.source.ext.schain.nodes[0].hp).to.equal(1); - expect(ortbRequest.source.ext.schain.nodes[0].rid).to.equal('bid-request-1'); - expect(ortbRequest.source.ext.schain.nodes[0].name).to.equal('publisher'); - expect(ortbRequest.source.ext.schain.nodes[0].domain).to.equal('publisher.com'); - }); - - it('Verify common id parameters', async function () { - const bidRequests = deepClone(slotConfigs); - const eids = [ - { - source: 'pubcid.org', - uids: [{ - id: 'userid_pubcid' - }] - }, { - source: 'adserver.org', - uids: [{ - id: 'userid_ttd', - ext: { - rtiPartner: 'TDID' - } - }] - } - ]; - const br = { - ...bidderRequest, - ortb2: { - user: { - ext: { - eids - } - } - } - } - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(br)); - expect(request).to.be.not.null; - expect(request.data).to.be.not.null; - const ortbRequest = request.data; - // user object - expect(ortbRequest.user).to.not.be.undefined; - expect(ortbRequest.user.ext).to.not.be.undefined; - expect(ortbRequest.user.ext.eids).to.not.be.undefined; - expect(ortbRequest.user.ext.eids).to.deep.equal(eids); - }); - - it('Verify user level first party data', async function () { - const bidderRequest = { - refererInfo: { - page: 'https://publisher.com/home', - ref: 'https://referrer' - }, - gdprConsent: { - gdprApplies: true, - consentString: 'serialized_gdpr_data' - }, - ortb2: { - user: { - yob: 1985, - gender: 'm', - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - } - } - }; - const request = spec.buildRequests(slotConfigs, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest).to.not.equal(null); - expect(ortbRequest.user).to.not.equal(null); - expect(ortbRequest.user).to.deep.equal({ - yob: 1985, - gender: 'm', - ext: { - data: { - registered: true, - interests: ['cars'] - }, - consent: 'serialized_gdpr_data' - } - }); - }); - - it('Verify site level first party data', async function () { - const bidderRequest = { - ortb2: { - site: { - content: { - data: [{ - name: 'www.iris.com', - ext: { - segtax: 500, - cids: ['iris_c73g5jq96mwso4d8'] - } - }] - }, - page: 'http://pub.com/news', - ref: 'http://google.com', - publisher: { - domain: 'pub.com' - } - } - } - }; - const request = spec.buildRequests(slotConfigs, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest).to.not.equal(null); - expect(ortbRequest.site).to.not.equal(null); - expect(ortbRequest.site).to.deep.equal({ - content: { - data: [{ - name: 'www.iris.com', - ext: { - segtax: 500, - cids: ['iris_c73g5jq96mwso4d8'] - } - }] - }, - page: 'http://pub.com/news', - ref: 'http://google.com', - publisher: { - id: 'p10000', - domain: 'pub.com' - } - }); - }); - - it('Verify impression/slot level first party data', function () { - const bidderRequests = [{ - placementCode: '/DfpAccount1/slot1', - mediaTypes: { - banner: { - sizes: [[1, 1]] - } - }, - bidId: 'bid12345', - params: { - cp: 'p10000', - ct: 't10000', - extra_key1: 'extra_val1', - extra_key2: 12345 - }, - ortb2Imp: { - ext: { - data: { - pbadslot: 'homepage-top-rect', - adUnitSpecificAttribute: '123' - } - } - } - }]; - const request = spec.buildRequests(bidderRequests, bidderRequest); - const ortbRequest = request.data; - expect(ortbRequest).to.not.equal(null); - expect(ortbRequest.imp).to.not.equal(null); - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].ext).to.not.equal(null); - expect(ortbRequest.imp[0].ext).to.deep.equal({ - prebid: { - extra_key1: 'extra_val1', - extra_key2: 12345 - }, - data: { - pbadslot: 'homepage-top-rect', - adUnitSpecificAttribute: '123' - } - }); - }); - - it('Verify bid request timeouts', function () { - const mkRequest = (bidderRequest) => spec.buildRequests(slotConfigs, bidderRequest).data; - // assert default is used when no bidderRequest.timeout value is available - expect(mkRequest(bidderRequest).tmax).to.equal(500) - - // assert bidderRequest value is used when available - expect(mkRequest(Object.assign({}, { timeout: 6000 }, bidderRequest)).tmax).to.equal(6000) - }); - - it('Verify deals', async function () { - const bidRequests = deepClone(slotConfigs); - const deals = [{ - id: 'DEAL_ONE', - bidfloor: 1.1 - }, { - id: 'DEAL_TWO', - bidfloor: 2.2 - }]; - bidRequests[0].params.deals = deals; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request.url).to.equal('https://bid.contextweb.com/header/ortb?src=prebid'); - expect(request.method).to.equal('POST'); - const ortbRequest = request.data; - // slot 1 - expect(ortbRequest.imp[0].tagid).to.equal('t10000'); - expect(ortbRequest.imp[0].pmp).to.not.be.undefined; - expect(ortbRequest.imp[0].pmp).to.deep.equal({ - private_auction: 0, - deals - }); - }) -}); diff --git a/test/spec/modules/pwbidBidAdapter_spec.js b/test/spec/modules/pwbidBidAdapter_spec.js deleted file mode 100644 index 25dd79a22..000000000 --- a/test/spec/modules/pwbidBidAdapter_spec.js +++ /dev/null @@ -1,897 +0,0 @@ -// import or require modules necessary for the test, e.g.: - -import {expect} from 'chai'; -import {spec, _checkVideoPlacement, _checkMediaType, _parseAdSlot} from 'modules/pwbidBidAdapter.js'; // _ functions exported only for testing so maintaining the JS convention of _ to indicate the intent -import * as utils from 'src/utils.js'; - -const sampleRequestBanner = { - 'id': '6c148795eb836a', - 'tagid': 'div-gpt-ad-1460505748561-0', - 'bidfloor': 1, - 'secure': 1, - 'bidfloorcur': 'USD', - 'banner': { - 'w': 300, - 'h': 250, - 'format': [ - { - 'w': 300, - 'h': 600 - } - ], - 'pos': 0, - 'topframe': 1 - } -}; - -const sampleRequest = { - 'at': 1, - 'cur': [ - 'USD' - ], - 'imp': [ - sampleRequestBanner, - { - 'id': '7329ddc1d84eb3', - 'tagid': 'div-gpt-ad-1460505748561-1', - 'secure': 1, - 'bidfloorcur': 'USD', - 'native': { - 'request': '{"assets":[{"id":1,"required":1,"title":{"len":80}},{"id":5,"required":1,"data":{"type":2}},{"id":2,"required":1,"img":{"type":{"ID":2,"KEY":"image","TYPE":0},"w":150,"h":50}},{"id":4,"required":1,"data":{"type":1}}]}' - } - } - ], - 'site': { - 'page': 'http://localhost:9999/integrationExamples/gpt/hello_world.html?pbjs_debug=true', - 'ref': 'http://localhost:9999/integrationExamples/gpt/hello_world.html?pbjs_debug=true', - 'publisher': { - 'id': 'xxxxxx' - } - }, - 'device': { - 'ua': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/86.0.4240.198 Safari/537.36', - 'js': 1, - 'dnt': 0, - 'h': 600, - 'w': 800, - 'language': 'en-US', - 'geo': { - 'lat': 33.91989876432274, - 'lon': -84.38897708175764 - } - }, - 'user': { - 'gender': 'M', - 'geo': { - 'lat': 33.91989876432274, - 'lon': -84.38897708175764 - }, - 'yob': 2000 - }, - 'test': 0, - 'ext': { - 'version': '0.0.1' - }, - 'source': { - 'tid': '2c8cd034-f068-4419-8c30-f07292c0d17b' - } -}; - -const sampleValidBannerBidRequest = { - 'bidder': 'pubwise', - 'params': { - 'siteId': 'xxxxxx', - 'bidFloor': '1.00', - 'currency': 'USD', - 'gender': 'M', - 'lat': '33.91989876432274', - 'lon': '-84.38897708175764', - 'yob': '2000', - 'bcat': ['IAB25-3', 'IAB26-1', 'IAB26-2', 'IAB26-3', 'IAB26-4'], - }, - 'gdprConsent': { - 'consentString': 'BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA', - 'gdprApplies': 1, - }, - 'uspConsent': 1, - 'crumbs': { - 'pubcid': '9a62f261-3c0b-4cc8-8db3-a72ae86ec6ba' - }, - ortb2Imp: { - ext: { - tid: '2001a8b2-3bcf-417d-b64f-92641dae21e0', - data: { - adserver: { - name: 'gam', - adslot: '/19968336/header-bid-tag-0' - }, - pbadslot: '/19968336/header-bid-tag-0', - } - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '6c148795eb836a', - 'bidderRequestId': '18a45bff5ff705', - 'auctionId': '9f20663c-4629-4b5c-bff6-ff3aa8319358', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 -}; - -const sampleValidBidRequests = [ - sampleValidBannerBidRequest, - { - 'bidder': 'pubwise', - 'params': { - 'siteId': 'xxxxxx' - }, - 'crumbs': { - 'pubcid': '9a62f261-3c0b-4cc8-8db3-a72ae86ec6ba' - }, - 'nativeParams': { - 'title': { - 'required': true, - 'len': 80 - }, - 'body': { - 'required': true - }, - 'image': { - 'required': true, - 'sizes': [ - 150, - 50 - ] - }, - 'sponsoredBy': { - 'required': true - }, - 'icon': { - 'required': false - } - }, - ortb2Imp: { - ext: { - tid: '2c8cd034-f068-4419-8c30-f07292c0d17b', - data: { - adserver: { - name: 'gam', - adslot: '/19968336/header-bid-tag-0' - }, - pbadslot: '/19968336/header-bid-tag-0', - } - } - }, - 'mediaTypes': { - 'native': { - 'title': { - 'required': true, - 'len': 80 - }, - 'body': { - 'required': true - }, - 'image': { - 'required': true, - 'sizes': [ - 150, - 50 - ] - }, - 'sponsoredBy': { - 'required': true - }, - 'icon': { - 'required': false - } - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-1', - 'sizes': [], - 'bidId': '30ab7516a51a7c', - 'bidderRequestId': '18a45bff5ff705', - 'auctionId': '9f20663c-4629-4b5c-bff6-ff3aa8319358', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } -] - -const sampleBidderBannerRequest = { - 'bidder': 'pubwise', - 'params': { - 'siteId': 'xxxxxx', - 'height': 250, - 'width': 300, - 'gender': 'M', - 'yob': '2000', - 'lat': '33.91989876432274', - 'lon': '-84.38897708175764', - 'bidFloor': '1.00', - 'currency': 'USD', - 'adSlot': '', - 'adUnit': 'div-gpt-ad-1460505748561-0', - 'bcat': [ - 'IAB25-3', - 'IAB26-1', - 'IAB26-2', - 'IAB26-3', - 'IAB26-4', - ], - }, - 'crumbs': { - 'pubcid': '9a62f261-3c0b-4cc8-8db3-a72ae86ec6ba' - }, - ortb2Imp: { - ext: { - tid: '2001a8b2-3bcf-417d-b64f-92641dae21e0', - data: { - adserver: { - name: 'gam', - adslot: '/19968336/header-bid-tag-0' - }, - pbadslot: '/19968336/header-bid-tag-0', - } - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '6c148795eb836a', - 'bidderRequestId': '18a45bff5ff705', - 'auctionId': '9f20663c-4629-4b5c-bff6-ff3aa8319358', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'gdprConsent': { - 'consentString': 'BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA', - 'gdprApplies': 1, - }, - 'uspConsent': 1, -}; - -const sampleBidderRequest = { - 'bidderCode': 'pubwise', - ortb2: { - source: { - tid: '9f20663c-4629-4b5c-bff6-ff3aa8319358', - } - }, - 'bidderRequestId': '18a45bff5ff705', - 'bids': [ - sampleBidderBannerRequest, - { - 'bidder': 'pubwise', - 'params': { - 'siteId': 'xxxxxx' - }, - 'crumbs': { - 'pubcid': '9a62f261-3c0b-4cc8-8db3-a72ae86ec6ba' - }, - 'nativeParams': { - 'title': { - 'required': true, - 'len': 80 - }, - 'body': { - 'required': true - }, - 'image': { - 'required': true, - 'sizes': [ - 150, - 50 - ] - }, - 'sponsoredBy': { - 'required': true - }, - 'icon': { - 'required': false - } - }, - ortb2Imp: { - ext: { - data: { - adserver: { - name: 'gam', - adslot: '/19968336/header-bid-tag-0' - }, - pbadslot: '/19968336/header-bid-tag-0', - } - } - }, - 'mediaTypes': { - 'native': { - 'title': { - 'required': true, - 'len': 80 - }, - 'body': { - 'required': true - }, - 'image': { - 'required': true, - 'sizes': [ - 150, - 50 - ] - }, - 'sponsoredBy': { - 'required': true - }, - 'icon': { - 'required': false - } - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-1', - 'transactionId': '2c8cd034-f068-4419-8c30-f07292c0d17b', - 'sizes': [], - 'bidId': '30ab7516a51a7c', - 'bidderRequestId': '18a45bff5ff705', - 'auctionId': '9f20663c-4629-4b5c-bff6-ff3aa8319358', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'auctionStart': 1606269202001, - 'timeout': 1000, - 'gdprConsent': { - 'consentString': 'BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA', - 'gdprApplies': 1, - }, - 'uspConsent': 1, - 'refererInfo': { - 'referer': 'http://localhost:9999/integrationExamples/gpt/hello_world.html?pbjs_debug=true', - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': [ - 'http://localhost:9999/integrationExamples/gpt/hello_world.html?pbjs_debug=true' - ], - 'canonicalUrl': null - }, - 'start': 1606269202004 -}; - -const sampleRTBResponse = { - 'body': { - 'id': '1606251348404', - 'seatbid': [ - { - 'bid': [ - { - 'id': '1606579704052', - 'impid': '6c148795eb836a', - 'price': 1.23, - 'adm': '\u003cdiv style="box-sizing: border-box;width:298px;height:248px;border: 1px solid rgba(0,0,0,.25);border-radius:10px;"\u003e\n\t\u003ch3 style="margin-top:80px;text-align: center;"\u003ePubWise Test Bid\u003c/h3\u003e\n\u003c/div\u003e', - 'crid': 'test', - 'w': 300, - 'h': 250 - }, - { - 'id': '1606579704052', - 'impid': '7329ddc1d84eb3', - 'price': 1.23, - 'adm': '{"ver":"1.2","assets":[{"id":1,"title":{"text":"PubWise Test"}},{"id":2,"img":{"type":3,"url":"http://www.pubwise.io","w":300,"h":250}},{"id":3,"img":{"type":1,"url":"http://www.pubwise.io","w":150,"h":125}},{"id":5,"data":{"type":2,"value":"PubWise Test Desc"}},{"id":4,"data":{"type":1,"value":"PubWise.io"}}],"link":{"url":"http://www.pubwise.io"}}', - 'crid': 'test', - 'w': 300, - 'h': 250 - } - ] - } - ], - 'bidid': 'testtesttest' - } -}; - -const samplePBBidObjects = [ - { - 'requestId': '6c148795eb836a', - 'cpm': '1.23', - 'width': 300, - 'height': 250, - 'creativeId': 'test', - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'ad': '
\n\t

PubWise Test Bid

\n
', - 'pw_seat': null, - 'pw_dspid': null, - 'partnerImpId': '1606579704052', - 'meta': {}, - 'mediaType': 'banner', - }, - { - 'requestId': '7329ddc1d84eb3', - 'cpm': '1.23', - 'width': 300, - 'height': 250, - 'creativeId': 'test', - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'ad': '{\"ver\":\"1.2\",\"assets\":[{\"id\":1,\"title\":{\"text\":\"PubWise Test\"}},{\"id\":2,\"img\":{\"type\":3,\"url\":\"http://www.pubwise.io\",\"w\":300,\"h\":250}},{\"id\":3,\"img\":{\"type\":1,\"url\":\"http://www.pubwise.io\",\"w\":150,\"h\":125}},{\"id\":5,\"data\":{\"type\":2,\"value\":\"PubWise Test Desc\"}},{\"id\":4,\"data\":{\"type\":1,\"value\":\"PubWise.io\"}}],\"link\":{\"url\":\"http://www.pubwise.io\"}}', - 'pw_seat': null, - 'pw_dspid': null, - 'partnerImpId': '1606579704052', - 'mediaType': 'native', - 'native': { - 'body': 'PubWise Test Desc', - 'icon': { - 'height': 125, - 'url': 'http://www.pubwise.io', - 'width': 150, - }, - 'image': { - 'height': 250, - 'url': 'http://www.pubwise.io', - 'width': 300, - }, - 'sponsoredBy': 'PubWise.io', - 'title': 'PubWise Test' - }, - 'meta': {}, - 'impressionTrackers': [], - 'jstracker': [], - 'clickTrackers': [], - 'clickUrl': 'http://www.pubwise.io' - } -]; - -describe('PubWiseAdapter', function () { - describe('Handles Params Properly', function () { - it('properly sets the default endpoint', function () { - const referenceEndpoint = 'https://bid.pubwise.io/prebid'; - const endpointBidRequest = utils.deepClone(sampleValidBidRequests); - // endpointBidRequest.forEach((bidRequest) => { - // bidRequest.params.endpoint_url = newEndpoint; - // }); - const result = spec.buildRequests(endpointBidRequest, {auctionId: 'placeholder'}); - expect(result.url).to.equal(referenceEndpoint); - }); - - it('allows endpoint to be reset', function () { - const newEndpoint = 'http://www.pubwise.io/endpointtest'; - const endpointBidRequest = utils.deepClone(sampleValidBidRequests); - endpointBidRequest.forEach((bidRequest) => { - bidRequest.params.endpoint_url = newEndpoint; - }); - const result = spec.buildRequests(endpointBidRequest, {auctionId: 'placeholder'}); - expect(result.url).to.equal(newEndpoint); - }); - }); - - describe('Properly Validates Bids', function () { - it('valid bid', function () { - const validBid = { - bidder: 'pubwise', - params: { - siteId: 'xxxxxx' - } - }; - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(true); - }); - - it('valid bid: extra fields are ok', function () { - const validBid = { - bidder: 'pubwise', - params: { - siteId: 'xxxxxx', - gender: 'M', - } - }; - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(true); - }); - - it('invalid bid: no siteId', function () { - const inValidBid = { - bidder: 'pubwise', - params: { - gender: 'M', - } - }; - const isValid = spec.isBidRequestValid(inValidBid); - expect(isValid).to.equal(false); - }); - - it('invalid bid: siteId should be a string', function () { - const validBid = { - bidder: 'pubwise', - params: { - siteId: 123456 - } - }; - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(false); - }); - }); - - describe('Handling Request Construction', function () { - it('bid requests are not mutable', function() { - const sourceBidRequest = utils.deepClone(sampleValidBidRequests); - spec.buildRequests(sampleValidBidRequests, {auctionId: 'placeholder'}); - expect(sampleValidBidRequests).to.deep.equal(sourceBidRequest, 'Should be unedited as they are used elsewhere'); - }); - it('should handle complex bidRequest', function() { - const request = spec.buildRequests(sampleValidBidRequests, sampleBidderRequest); - expect(request.bidderRequest).to.equal(sampleBidderRequest, "Bid Request Doesn't Match Sample"); - expect(request.data.source.tid).to.equal(sampleBidderRequest.ortb2.source.tid, 'source.tid -> source.tid Mismatch'); - expect(request.data.imp[0].ext.tid).to.equal(sampleBidderRequest.bids[0].ortb2Imp.ext.tid, 'ext.tid -> ext.tid Mismatch'); - }); - it('must conform to API for buildRequests', function() { - const request = spec.buildRequests(sampleValidBidRequests); - expect(request.bidderRequest).to.be.undefined; - }); - }); - - describe('Identifies Media Types', function () { - it('identifies native adm type', function() { - const adm = '{"ver":"1.2","assets":[{"title":{"text":"PubWise Test"}},{"img":{"type":3,"url":"http://www.pubwise.io"}},{"img":{"type":1,"url":"http://www.pubwise.io"}},{"data":{"type":2,"value":"PubWise Test Desc"}},{"data":{"type":1,"value":"PubWise.io"}}],"link":{"url":""}}'; - const newBid = {mediaType: 'unknown'}; - _checkMediaType({adm}, newBid); - expect(newBid.mediaType).to.equal('native', adm + ' Is a Native adm'); - }); - - it('identifies banner adm type', function() { - let adm = '
↵

PubWise Test Bid

↵
'; - let newBid = {mediaType: 'unknown'}; - _checkMediaType({adm}, newBid); - expect(newBid.mediaType).to.equal('banner', adm + ' Is a Banner adm'); - }); - }); - - describe('Properly Parses AdSlot Data', function () { - it('parses banner', function() { - const testBid = utils.deepClone(sampleValidBannerBidRequest) - _parseAdSlot(testBid) - expect(testBid).to.deep.equal(sampleBidderBannerRequest); - }); - }); - - describe('Properly Handles Response', function () { - it('handles response with muiltiple responses', function() { - // the request when it comes back is on the data object - const pbResponse = spec.interpretResponse(sampleRTBResponse, {'data': sampleRequest}) - expect(pbResponse).to.deep.equal(samplePBBidObjects); - }); - }); - - describe('Video Testing', function () { - /** - * Video Testing - */ - - const videoBidRequests = - [ - { - code: 'video1', - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'instream' - } - }, - bidder: 'pwbid', - bidId: '22bddb28db77d', - adUnitCode: 'Div1', - params: { - siteId: 'xxxxxx', - video: { - mimes: ['video/mp4', 'video/x-flv'], - skippable: true, - minduration: 5, - maxduration: 30, - startdelay: 5, - playbackmethod: [1, 3], - api: [1, 2], - protocols: [2, 3], - battr: [13, 14], - linearity: 1, - placement: 2, - minbitrate: 10, - maxbitrate: 10 - } - } - } - ]; - - const newvideoRequests = [{ - 'bidder': 'pwbid', - 'params': { - 'siteId': 'xxxxx', - 'video': { - 'mimes': ['video/mp4'], - 'skippable': true, - 'protocols': [1, 2, 5], - 'linearity': 1 - } - }, - 'mediaTypes': { - 'video': { - 'playerSize': [ - [640, 480] - ], - 'protocols': [1, 2, 5], - 'context': 'instream', - 'mimes': ['video/flv'], - 'skippable': false, - 'skip': 1, - 'linearity': 2 - } - }, - 'adUnitCode': 'video1', - 'transactionId': '803e3750-0bbe-4ffe-a548-b6eca15087bf', - 'sizes': [ - [640, 480] - ], - 'bidId': '2c95df014cfe97', - 'bidderRequestId': '1fe59391566442', - 'auctionId': '3a4118ef-fb96-4416-b0b0-3cfc1cebc142', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - }]; - - const newvideoBidResponses = { - 'body': { - 'id': '1621441141473', - 'cur': 'USD', - 'customdata': 'openrtb1', - 'ext': { - 'buyid': 'myBuyId' - }, - 'seatbid': [{ - 'bid': [{ - 'id': '2c95df014cfe97', - 'impid': '2c95df014cfe97', - 'price': 4.2, - 'cid': 'test1', - 'crid': 'test2', - 'adm': "Acudeo CompatibleVAST 2.0 Instream Test 1VAST 2.0 Instream Test 1", - 'w': 0, - 'h': 0 - }], - 'ext': { - 'buyid': 'myBuyId' - } - }] - }, - 'headers': {} - }; - - const videoBidResponse = { - 'body': { - 'id': '93D3BAD6-E2E2-49FB-9D89-920B1761C865', - 'seatbid': [{ - 'bid': [{ - 'id': '74858439-49D7-4169-BA5D-44A046315B2F', - 'impid': '22bddb28db77d', - 'price': 1.3, - 'adm': '', - 'h': 250, - 'w': 300, - 'ext': { - 'deal_channel': 6 - } - }] - }] - } - }; - - it('Request params check for video ad', function () { - const request = spec.buildRequests(videoBidRequests, { - auctionId: 'new-auction-id' - }); - const data = request.data; - expect(data.imp[0].video).to.exist; - expect(data.imp[0].tagid).to.equal('Div1'); - expect(data.imp[0]['video']['mimes']).to.exist.and.to.be.an('array'); - expect(data.imp[0]['video']['mimes'][0]).to.equal(videoBidRequests[0].params.video['mimes'][0]); - expect(data.imp[0]['video']['mimes'][1]).to.equal(videoBidRequests[0].params.video['mimes'][1]); - expect(data.imp[0]['video']['minduration']).to.equal(videoBidRequests[0].params.video['minduration']); - expect(data.imp[0]['video']['maxduration']).to.equal(videoBidRequests[0].params.video['maxduration']); - expect(data.imp[0]['video']['startdelay']).to.equal(videoBidRequests[0].params.video['startdelay']); - - expect(data.imp[0]['video']['playbackmethod']).to.exist.and.to.be.an('array'); - expect(data.imp[0]['video']['playbackmethod'][0]).to.equal(videoBidRequests[0].params.video['playbackmethod'][0]); - expect(data.imp[0]['video']['playbackmethod'][1]).to.equal(videoBidRequests[0].params.video['playbackmethod'][1]); - - expect(data.imp[0]['video']['api']).to.exist.and.to.be.an('array'); - expect(data.imp[0]['video']['api'][0]).to.equal(videoBidRequests[0].params.video['api'][0]); - expect(data.imp[0]['video']['api'][1]).to.equal(videoBidRequests[0].params.video['api'][1]); - - expect(data.imp[0]['video']['protocols']).to.exist.and.to.be.an('array'); - expect(data.imp[0]['video']['protocols'][0]).to.equal(videoBidRequests[0].params.video['protocols'][0]); - expect(data.imp[0]['video']['protocols'][1]).to.equal(videoBidRequests[0].params.video['protocols'][1]); - - expect(data.imp[0]['video']['battr']).to.exist.and.to.be.an('array'); - expect(data.imp[0]['video']['battr'][0]).to.equal(videoBidRequests[0].params.video['battr'][0]); - expect(data.imp[0]['video']['battr'][1]).to.equal(videoBidRequests[0].params.video['battr'][1]); - - expect(data.imp[0]['video']['linearity']).to.equal(videoBidRequests[0].params.video['linearity']); - expect(data.imp[0]['video']['placement']).to.equal(videoBidRequests[0].params.video['placement']); - expect(data.imp[0]['video']['minbitrate']).to.equal(videoBidRequests[0].params.video['minbitrate']); - expect(data.imp[0]['video']['maxbitrate']).to.equal(videoBidRequests[0].params.video['maxbitrate']); - - expect(data.imp[0]['video']['w']).to.equal(videoBidRequests[0].mediaTypes.video.playerSize[0]); - expect(data.imp[0]['video']['h']).to.equal(videoBidRequests[0].mediaTypes.video.playerSize[1]); - }); - - it('should assign mediaType even if bid.ext.mediaType does not exists', function() { - const newrequest = spec.buildRequests(newvideoRequests, { - auctionId: 'new-auction-id' - }); - const newresponse = spec.interpretResponse(newvideoBidResponses, newrequest); - expect(newresponse[0].mediaType).to.equal('video'); - }); - - it('should not assign renderer if bid is video and request is for instream', function() { - const request = spec.buildRequests(videoBidRequests, { - auctionId: 'new-auction-id' - }); - const response = spec.interpretResponse(videoBidResponse, request); - expect(response[0].renderer).to.not.exist; - }); - - it('should process instream and outstream', function() { - const validOutstreamRequest = - { - code: 'video1', - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'outstream' - } - }, - bidder: 'pwbid', - bidId: '47acc48ad47af5', - requestId: '0fb4905b-1234-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: '92489f71-1bf2-49a0-adf9-000cea934729', - params: { - siteId: 'xxxxx', - adSlot: 'Div1', // ad_id or tagid - video: { - mimes: ['video/mp4', 'video/x-flv'], - skippable: true, - minduration: 5, - maxduration: 30 - } - } - }; - - const outstreamBidRequest = - [ - validOutstreamRequest - ]; - - const validInstreamRequest = { - code: 'video1', - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'instream' - } - }, - bidder: 'pwbid', - bidId: '47acc48ad47af5', - requestId: '0fb4905b-1234-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: '92489f71-1bf2-49a0-adf9-000cea934729', - params: { - siteId: 'xxxxx', - adSlot: 'Div1', // ad_id or tagid - video: { - mimes: ['video/mp4', 'video/x-flv'], - skippable: true, - minduration: 5, - maxduration: 30 - } - } - }; - - const instreamBidRequest = - [ - validInstreamRequest - ]; - - const outstreamRequest = spec.isBidRequestValid(validOutstreamRequest); - expect(outstreamRequest).to.equal(false); - - const instreamRequest = spec.isBidRequestValid(validInstreamRequest); - expect(instreamRequest).to.equal(true); - }); - - describe('Checking for Video.Placement property', function() { - let sandbox, utilsMock; - const adUnit = 'DivCheckPlacement'; - const msg_placement_missing = 'PubWise: Video.Placement param missing for DivCheckPlacement'; - const videoData = { - battr: [6, 7], - skipafter: 15, - maxduration: 50, - context: 'instream', - playerSize: [640, 480], - skip: 0, - connectiontype: [1, 2, 6], - skipmin: 10, - minduration: 10, - mimes: ['video/mp4', 'video/x-flv'], - } - beforeEach(() => { - utilsMock = sinon.mock(utils); - sandbox = sinon.createSandbox(); - sandbox.spy(utils, 'logWarn'); - }); - - afterEach(() => { - utilsMock.restore(); - sandbox.restore(); - }) - - it('should log Video.Placement param missing', function() { - _checkVideoPlacement(videoData, adUnit); - // when failing this gives an odd message about "AssertError: expected logWarn to be called with arguments" it means the specific message expected - sinon.assert.calledWith(utils.logWarn, msg_placement_missing); - }) - it('should not log Video.Placement param missing', function() { - videoData['placement'] = 1; - _checkVideoPlacement(videoData, adUnit); - sinon.assert.neverCalledWith(utils.logWarn, msg_placement_missing); - }) - }); - // end video testing - }); -}); diff --git a/test/spec/modules/pxyzBidAdapter_spec.js b/test/spec/modules/pxyzBidAdapter_spec.js deleted file mode 100644 index 2ce6ed014..000000000 --- a/test/spec/modules/pxyzBidAdapter_spec.js +++ /dev/null @@ -1,224 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/pxyzBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { deepClone } from 'src/utils.js'; - -const URL = 'https://ads.playground.xyz/host-config/prebid?v=2'; -const GDPR_CONSENT = 'XYZ-CONSENT'; - -const BIDDER_REQUEST = { - refererInfo: { - page: 'https://example.com', - } -}; - -describe('pxyzBidAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'pxyz', - 'params': { - 'placementId': '10433394' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [320, 50]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'placementId': 0 - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - 'bidder': 'pxyz', - 'params': { - 'placementId': '10433394' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - } - ]; - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, BIDDER_REQUEST); - const data = JSON.parse(request.data); - const banner = data.imp[0].banner; - - expect(Object.keys(data.imp[0].ext)).to.have.members(['appnexus', 'pxyz']); - expect([banner.w, banner.h]).to.deep.equal([300, 250]); - expect(banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]); - expect(request.url).to.equal(URL); - expect(request.method).to.equal('POST'); - }); - - describe('CCPA', function () { - describe('when USP consent object is NOT present in bidder request', function () { - const request = spec.buildRequests(bidRequests, BIDDER_REQUEST); - const data = JSON.parse(request.data); - it('should not populate ext.gdpr or ext.consent', function () { - expect(data).to.not.have.property('Regs.ext.us_privacy'); - }); - }); - - describe('when USP consent object is present in bidder request', function () { - describe('when GDPR is applicable', function () { - const request = spec.buildRequests( - bidRequests, - Object.assign({}, BIDDER_REQUEST, { uspConsent: '1YYY' }) - ); - const data = JSON.parse(request.data); - it('should set Regs.ext.us_privacy with the correct value', function () { - expect(data.Regs.ext['us_privacy']).to.equal('1YYY'); - }); - }); - }); - }); - - describe('GDPR', function () { - describe('when no GDPR consent object is present in bidder request', function () { - const request = spec.buildRequests(bidRequests, BIDDER_REQUEST); - const data = JSON.parse(request.data); - it('should not populate ext.gdpr or ext.consent', function () { - expect(data).to.not.have.property('Regs.ext.consent'); - }); - }); - - describe('when GDPR consent object is present in bidder request', function () { - describe('when GDPR is applicable', function () { - const request = spec.buildRequests( - bidRequests, - Object.assign({}, BIDDER_REQUEST, { - gdprConsent: { gdprApplies: true, consentString: GDPR_CONSENT } - }) - ); - const data = JSON.parse(request.data); - it('should set ext.gdpr with 1', function () { - expect(data.Regs.ext.gdpr).to.equal(1); - }); - it('should set ext.consent', function () { - expect(data.User.ext.consent).to.equal('XYZ-CONSENT'); - }); - }); - describe('when GDPR is NOT applicable', function () { - const request = spec.buildRequests( - bidRequests, - Object.assign({}, BIDDER_REQUEST, { - gdprConsent: { gdprApplies: false, consentString: GDPR_CONSENT } - }) - ); - const data = JSON.parse(request.data); - it('should set ext.gdpr to 0', function () { - expect(data.Regs.ext.gdpr).to.equal(0); - }); - it('should populate ext.consent', function () { - expect(data.User.ext.consent).to.equal('XYZ-CONSENT'); - }); - }); - }); - }); - }) - - describe('interpretResponse', function () { - const response = { - 'id': 'bidd_id', - 'seatbid': [ { - 'bid': [ - { - 'id': '4434762738980910431', - 'impid': '221f2bdc1fbc31', - 'price': 1, - 'adid': '91673066', - 'adm': '', - 'adomain': [ 'pg.xyz' ], - 'iurl': 'http://pgxyz.com/cr?id=91673066', - 'cid': 'c_id', - 'crid': 'c_rid', - 'h': 50, - 'w': 320, - 'ext': { - 'appnexus': { - 'brand_id': 1, - 'auction_id': 1087655594852566000, - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - } - ], - 'seat': '4321' - }], - 'bidid': '6894227111893743356', - 'cur': 'AUD' - }; - - const bidderRequest = { - 'bidderCode': 'pxyz' - }; - - it('should get correct bid response', function () { - const expectedResponse = [ - { - 'requestId': '221f2bdc1fbc31', - 'cpm': 1, - 'creativeId': 91673066, - 'width': 300, - 'height': 50, - 'ad': '', - 'mediaType': 'banner', - 'currency': 'AUD', - 'ttl': 300, - 'netRevenue': true, - 'meta': { - advertiserDomains: ['pg.xyz'] - } - } - ]; - const result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - expect(result[0].meta.advertiserDomains).to.deep.equal(expectedResponse[0].meta.advertiserDomains); - }); - - it('handles nobid response', function () { - const response = undefined; - const result = spec.interpretResponse({ body: response }, {bidderRequest}); - expect(result.length).to.equal(0); - }); - }); - - describe('getUserSyncs', function () { - const syncImageUrl = '//ib.adnxs.com/getuidnb?https://ads.playground.xyz/usersync?partner=appnexus&uid=$UID'; - const syncIframeUrl = '//rtb.gumgum.com/getuid/15801?r=https%3A%2F%2Fads.playground.xyz%2Fusersync%3Fpartner%3Dgumgum%26uid%3D'; - it('should return one image type user sync pixel', function () { - const result = spec.getUserSyncs(); - expect(result.length).to.equal(2); - expect(result[0].type).to.equal('image') - expect(result[0].url).to.equal(syncImageUrl); - expect(result[1].type).to.equal('iframe') - expect(result[1].url).to.equal(syncIframeUrl); - }); - }) -}); diff --git a/test/spec/modules/qortexRtdProvider_spec.js b/test/spec/modules/qortexRtdProvider_spec.js deleted file mode 100644 index 3f6379af8..000000000 --- a/test/spec/modules/qortexRtdProvider_spec.js +++ /dev/null @@ -1,410 +0,0 @@ -import * as utils from 'src/utils.js'; -import * as events from 'src/events.js'; -import { EVENTS } from '../../../src/constants.js'; -import { loadExternalScriptStub } from 'test/mocks/adloaderStub.js'; -import { - qortexSubmodule as module, - addContextToRequests, - setContextData, - loadScriptTag, - initializeModuleData, - setGroupConfigData, - requestContextData, - windowPostMessageReceived -} from '../../../modules/qortexRtdProvider.js'; -import {server} from '../../mocks/xhr.js'; -import { cloneDeep } from 'lodash'; - -describe('qortexRtdProvider', () => { - let logWarnSpy; - let logMessageSpy; - let ortb2Stub; - - const defaultApiHost = 'https://demand.qortex.ai'; - const defaultGroupId = 'test'; - const validBidderArray = ['qortex', 'test']; - const validTagConfig = { - videoContainer: 'my-video-container' - } - const validModuleConfig = { - params: { - groupId: defaultGroupId, - apiUrl: defaultApiHost, - bidders: validBidderArray, - enableBidEnrichment: true - } - } - const bidEnrichmentDisabledModuleConfig = { - params: { - groupId: defaultGroupId, - apiUrl: defaultApiHost, - bidders: validBidderArray - } - } - const invalidApiUrlModuleConfig = { - params: { - groupId: defaultGroupId, - apiUrl: 'test123', - bidders: validBidderArray - } - } - const emptyModuleConfig = { - params: {} - } - const validImpressionEvent = { - detail: { - uid: 'uid123', - type: 'qx-impression' - } - } - const validImpressionEvent2 = { - detail: { - uid: 'uid1234', - type: 'qx-impression' - } - } - const missingIdImpressionEvent = { - detail: { - type: 'qx-impression' - } - } - const QortexPostMessageInitialized = { - target: 'QORTEX-PREBIDJS-RTD-MODULE', - message: 'CX-BID-ENRICH-INITIALIZED', - params: {groupConfig: {data: true}} - } - const QortexPostMessageContext = { - target: 'QORTEX-PREBIDJS-RTD-MODULE', - message: 'DISPATCH-CONTEXT', - params: {context: {data: true}} - } - const invalidTypeQortexEvent = { - detail: { - type: 'invalid-type' - } - } - const responseHeaders = { - 'content-type': 'application/json', - 'access-control-allow-origin': '*' - }; - const contextResponseObj = { - site: { - content: { - id: '123456', - episode: 15, - title: 'test episode', - series: 'test show', - season: '1', - url: 'https://example.com/file.mp4' - } - } - } - const contextResponse = JSON.stringify(contextResponseObj); - const validGroupConfigResponseObj = { - groupId: defaultGroupId, - active: true, - prebidBidEnrichment: true, - prebidBidEnrichmentPercentage: 100, - prebidReportingPercentage: 100 - } - const validGroupConfigResponse = JSON.stringify(validGroupConfigResponseObj); - const inactiveGroupConfigResponseObj = { - groupId: defaultGroupId, - active: false, - PrebidBidEnrichment: true, - PrebidReportingPercentage: 100 - } - const inactiveGroupConfigResponse = JSON.stringify(inactiveGroupConfigResponseObj); - const noEnrichmentGroupConfigResponseObj = { - groupId: defaultGroupId, - active: true, - prebidBidEnrichment: true, - prebidBidEnrichmentPercentage: 0, - prebidReportingPercentage: 100 - } - const reqBidsConfig = { - auctionId: '1234', - adUnits: [{ - bids: [ - { bidder: 'qortex' } - ] - }], - ortb2Fragments: { - bidder: {}, - global: {} - } - } - - beforeEach(() => { - ortb2Stub = sinon.stub(reqBidsConfig, 'ortb2Fragments').value({bidder: {}, global: {}}) - logWarnSpy = sinon.spy(utils, 'logWarn'); - logMessageSpy = sinon.spy(utils, 'logMessage'); - }) - - afterEach(() => { - logWarnSpy.restore(); - logMessageSpy.restore(); - ortb2Stub.restore(); - setContextData(null); - }) - - describe('init', () => { - it('will not initialize bid enrichment if it is disabled', () => { - module.init(bidEnrichmentDisabledModuleConfig); - expect(logWarnSpy.calledWith('Bid Enrichment Function has been disabled in module configuration')).to.be.true; - }) - - it('returns false and logs error for missing groupId', () => { - expect(module.init(emptyModuleConfig)).to.be.false; - expect(logWarnSpy.calledOnce).to.be.true; - expect(logWarnSpy.calledWith('Qortex RTD module config does not contain valid groupId parameter. Config params: {}')).to.be.ok; - }) - - it('loads Qortex script if tagConfig is present in module config params', () => { - const config = cloneDeep(validModuleConfig); - config.params.tagConfig = validTagConfig; - expect(module.init(config)).to.be.true; - expect(loadExternalScriptStub.calledOnce).to.be.true; - }) - }) - - describe('loadScriptTag', () => { - let addEventListenerSpy; - let billableEvents = []; - - const config = cloneDeep(validModuleConfig); - config.params.tagConfig = validTagConfig; - - events.on(EVENTS.BILLABLE_EVENT, (e) => { - billableEvents.push(e); - }) - - beforeEach(() => { - initializeModuleData(config); - addEventListenerSpy = sinon.spy(window, 'addEventListener'); - }) - - afterEach(() => { - addEventListenerSpy.restore(); - billableEvents = []; - }) - - it('adds event listener', () => { - loadScriptTag(config); - expect(addEventListenerSpy.calledOnce).to.be.true; - }) - - it('parses incoming qortex-impression events', () => { - loadScriptTag(config); - dispatchEvent(new CustomEvent('qortex-rtd', validImpressionEvent)); - expect(billableEvents.length).to.be.equal(1); - expect(billableEvents[0].type).to.be.equal(validImpressionEvent.detail.type); - expect(billableEvents[0].transactionId).to.be.equal(validImpressionEvent.detail.uid); - }) - - it('will emit two events for impressions with two different ids', () => { - loadScriptTag(config); - dispatchEvent(new CustomEvent('qortex-rtd', validImpressionEvent)); - dispatchEvent(new CustomEvent('qortex-rtd', validImpressionEvent2)); - expect(billableEvents.length).to.be.equal(2); - expect(billableEvents[0].transactionId).to.be.equal(validImpressionEvent.detail.uid); - expect(billableEvents[1].transactionId).to.be.equal(validImpressionEvent2.detail.uid); - }) - - it('will not allow multiple events with the same id', () => { - loadScriptTag(config); - dispatchEvent(new CustomEvent('qortex-rtd', validImpressionEvent)); - dispatchEvent(new CustomEvent('qortex-rtd', validImpressionEvent)); - expect(billableEvents.length).to.be.equal(1); - expect(logWarnSpy.calledWith('Received invalid billable event due to duplicate uid: qx-impression')).to.be.ok; - }) - - it('will not allow events with missing uid', () => { - loadScriptTag(config); - dispatchEvent(new CustomEvent('qortex-rtd', missingIdImpressionEvent)); - expect(billableEvents.length).to.be.equal(0); - expect(logWarnSpy.calledWith('Received invalid billable event due to missing uid: qx-impression')).to.be.ok; - }) - - it('will not allow events with unavailable type', () => { - loadScriptTag(config); - dispatchEvent(new CustomEvent('qortex-rtd', invalidTypeQortexEvent)); - expect(billableEvents.length).to.be.equal(0); - expect(logWarnSpy.calledWith('Received invalid billable event: invalid-type')).to.be.ok; - }) - }) - - describe('getBidRequestData', () => { - let callbackSpy; - - beforeEach(() => { - initializeModuleData(validModuleConfig); - setGroupConfigData(validGroupConfigResponseObj); - callbackSpy = sinon.spy(); - server.reset(); - }) - - afterEach(() => { - initializeModuleData(emptyModuleConfig); - callbackSpy.resetHistory(); - }) - - it('will call callback immediately if no adunits', () => { - const reqBidsConfigNoBids = { adUnits: [] }; - module.getBidRequestData(reqBidsConfigNoBids, callbackSpy); - expect(callbackSpy.calledOnce).to.be.true; - expect(logWarnSpy.calledOnce).to.be.true; - }) - - it('will not request context if prebid disable toggle is true', (done) => { - initializeModuleData(bidEnrichmentDisabledModuleConfig); - const cb = function () { - expect(server.requests.length).to.be.eql(0); - expect(logWarnSpy.called).to.be.true; - expect(logWarnSpy.calledWith('Bid enrichment disabled at prebid config')).to.be.true; - done(); - } - module.getBidRequestData(reqBidsConfig, cb); - }) - - it('will request to add context when ad units present and enabled', (done) => { - const cb = function () { - setContextData(null); - expect(server.requests.length).to.be.eql(0); - expect(logWarnSpy.called).to.be.true; - expect(logWarnSpy.calledWith('No context data received at this time')).to.be.true; - done(); - } - module.getBidRequestData(reqBidsConfig, cb); - }) - }) - - describe('onAuctionEndEvent', () => { - beforeEach(() => { - initializeModuleData(validModuleConfig); - setGroupConfigData(validGroupConfigResponseObj); - }) - - afterEach(() => { - initializeModuleData(emptyModuleConfig); - setGroupConfigData(null); - }) - - it('Properly sends analytics event with valid config', () => { - const testData = {auctionId: reqBidsConfig.auctionId, data: 'data'}; - module.onAuctionEndEvent(testData); - }) - }) - - describe('requestContextData', () => { - before(() => { - setContextData({data: true}); - }) - - after(() => { - setContextData(null); - }) - - it('Will log properly when context data already available', () => { - requestContextData(); - expect(logMessageSpy.calledWith('Context data already retrieved.')).to.be.true; - }) - }) - - describe('addContextToRequests', () => { - let testReqBids; - beforeEach(() => { - setGroupConfigData(validGroupConfigResponseObj); - testReqBids = { - auctionId: '1234', - adUnits: [{ - bids: [ - { bidder: 'qortex' } - ] - }], - ortb2Fragments: { - bidder: {}, - global: {} - } - } - }) - - afterEach(() => { - setGroupConfigData(null); - }) - - it('logs error if no data was retrieved from get context call', () => { - initializeModuleData(validModuleConfig); - addContextToRequests(reqBidsConfig); - expect(logWarnSpy.calledOnce).to.be.true; - expect(logWarnSpy.calledWith('No context data received at this time')).to.be.ok; - expect(reqBidsConfig.ortb2Fragments.global).to.be.eql({}); - expect(reqBidsConfig.ortb2Fragments.bidder).to.be.eql({}); - }) - - it('adds context only to global ortb2 when bidders array is omitted', () => { - const omittedBidderArrayConfig = cloneDeep(validModuleConfig); - delete omittedBidderArrayConfig.params.bidders; - initializeModuleData(omittedBidderArrayConfig); - setContextData(contextResponseObj); - addContextToRequests(reqBidsConfig); - expect(reqBidsConfig.ortb2Fragments.global).to.have.property('site'); - expect(reqBidsConfig.ortb2Fragments.global.site).to.have.property('content'); - expect(reqBidsConfig.ortb2Fragments.global.site.content).to.be.eql(contextResponseObj.site.content); - expect(reqBidsConfig.ortb2Fragments.bidder).to.be.eql({}); - }) - - it('adds only to bidder ortb2 when bidders array is included', () => { - initializeModuleData(validModuleConfig); - setContextData(contextResponseObj); - addContextToRequests(reqBidsConfig); - - const qortexOrtb2Fragment = reqBidsConfig.ortb2Fragments.bidder['qortex'] - expect(qortexOrtb2Fragment).to.not.be.null; - expect(qortexOrtb2Fragment).to.have.property('site'); - expect(qortexOrtb2Fragment.site).to.have.property('content'); - expect(qortexOrtb2Fragment.site.content).to.be.eql(contextResponseObj.site.content); - - const testOrtb2Fragment = reqBidsConfig.ortb2Fragments.bidder['test'] - expect(testOrtb2Fragment).to.not.be.null; - expect(testOrtb2Fragment).to.have.property('site'); - expect(testOrtb2Fragment.site).to.have.property('content'); - expect(testOrtb2Fragment.site.content).to.be.eql(contextResponseObj.site.content); - - expect(reqBidsConfig.ortb2Fragments.global).to.be.eql({}); - }) - - it('logs error if there is an empty bidder array', () => { - const invalidBidderArrayConfig = cloneDeep(validModuleConfig); - invalidBidderArrayConfig.params.bidders = []; - initializeModuleData(invalidBidderArrayConfig); - setContextData(contextResponseObj) - addContextToRequests(reqBidsConfig); - - expect(logWarnSpy.calledWith('Config contains an empty bidders array, unable to determine which bids to enrich')).to.be.ok; - expect(reqBidsConfig.ortb2Fragments.global).to.be.eql({}); - expect(reqBidsConfig.ortb2Fragments.bidder).to.be.eql({}); - }) - }) - - describe('initializeBidEnrichment', () => { - beforeEach(() => { - initializeModuleData(validModuleConfig); - setGroupConfigData(validGroupConfigResponseObj); - setContextData(null); - }) - - afterEach(() => { - setGroupConfigData(null); - setContextData(null); - }) - - it('processes incoming qortex component "initialize" message', () => { - windowPostMessageReceived({data: QortexPostMessageInitialized}) - }) - - it('processes incoming qortex component "context" message', () => { - windowPostMessageReceived({data: QortexPostMessageContext}) - }) - }) -}) diff --git a/test/spec/modules/qtBidAdapter_spec.js b/test/spec/modules/qtBidAdapter_spec.js deleted file mode 100644 index 279962d0d..000000000 --- a/test/spec/modules/qtBidAdapter_spec.js +++ /dev/null @@ -1,516 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/qtBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'qt'; - -describe('QTBidAdapter', function () { - const userIdAsEids = [{ - source: 'test.org', - uids: [{ - id: '01**********', - atype: 1, - ext: { - third: '01***********' - } - }] - }]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 'testBanner' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60 - } - }, - params: { - placementId: 'testVideo' - }, - userIdAsEids - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - placementId: 'testNative' - }, - userIdAsEids - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {} - }, - refererInfo: { - referer: 'https://test.com', - page: 'https://test.com' - }, - ortb2: { - device: { - w: 1512, - h: 982, - language: 'en-UK' - } - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://endpoint1.qt.io/pbjs'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'device', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids - } - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf(['testBanner', 'testVideo', 'testNative']); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8] - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }) - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }) - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with proper sync config , include GDPR', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.qt.io/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - it('Should return array of objects with proper sync config , include CCPA', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.qt.io/image?pbjs=1&ccpa_consent=1---&coppa=0') - }); - it('Should return array of objects with proper sync config , include GPP', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'abc123', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://cs.qt.io/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0') - }); - }); -}); diff --git a/test/spec/modules/quantcastBidAdapter_spec.js b/test/spec/modules/quantcastBidAdapter_spec.js deleted file mode 100644 index dbf6b2c9e..000000000 --- a/test/spec/modules/quantcastBidAdapter_spec.js +++ /dev/null @@ -1,859 +0,0 @@ -import { expect } from 'chai'; -import { - QUANTCAST_DOMAIN, - QUANTCAST_TEST_DOMAIN, - QUANTCAST_NET_REVENUE, - QUANTCAST_TTL, - QUANTCAST_TEST_PUBLISHER, - QUANTCAST_PROTOCOL, - QUANTCAST_PORT, - spec as qcSpec, - storage -} from '../../../modules/quantcastBidAdapter.js'; -import { newBidder } from '../../../src/adapters/bidderFactory.js'; -import { parseUrl } from 'src/utils.js'; -import { config } from 'src/config.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -describe('Quantcast adapter', function () { - const quantcastAdapter = newBidder(qcSpec); - let bidRequest; - let bidderRequest; - - afterEach(function () { - getGlobal().bidderSettings = {}; - }); - beforeEach(function () { - getGlobal().bidderSettings = { - quantcast: { - storageAllowed: true - } - }; - bidRequest = { - bidder: 'quantcast', - bidId: '2f7b179d443f14', - auctionId: '595ffa73-d78a-46c9-b18e-f99548a5be6b', - bidderRequestId: '1cc026909c24c8', - placementCode: 'div-gpt-ad-1438287399331-0', - params: { - publisherId: QUANTCAST_TEST_PUBLISHER, // REQUIRED - Publisher ID provided by Quantcast - battr: [1, 2] // OPTIONAL - Array of blocked creative attributes as per OpenRTB Spec List 5.3 - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - }; - - bidderRequest = { - refererInfo: { - page: 'http://example.com/hello.html', - ref: 'http://example.com/hello.html', - domain: 'example.com' - } - }; - - storage.setCookie('__qca', '', 'Thu, 01 Jan 1970 00:00:00 GMT'); - }); - - function setupVideoBidRequest(videoParams, mediaTypesParams) { - bidRequest.params = { - publisherId: 'test-publisher', // REQUIRED - Publisher ID provided by Quantcast - // Video object as specified in OpenRTB 2.5 - video: videoParams - }; - if (mediaTypesParams) { - bidRequest['mediaTypes'] = { - video: mediaTypesParams - } - } - }; - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(quantcastAdapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('`isBidRequestValid`', function () { - it('should return `true` when bid has publisherId', function () { - const bidRequest = { - bidder: 'quantcast', - params: { - publisherId: 'my_publisher_id' - } - }; - - expect(qcSpec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return `false` when bid has no publisherId', function () { - const bidRequest = { - bidder: 'quantcast', - params: { - } - }; - - expect(qcSpec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); - - describe('`buildRequests`', function () { - it('sends secure bid requests', function () { - const requests = qcSpec.buildRequests([bidRequest]); - const url = parseUrl(requests[0]['url']); - expect(url.protocol).to.equal('https'); - }); - - it('sends bid requests to Quantcast Canary Endpoint if `publisherId` is `test-publisher`', function () { - const requests = qcSpec.buildRequests([bidRequest]); - const url = parseUrl(requests[0]['url']); - expect(url.hostname).to.equal(QUANTCAST_TEST_DOMAIN); - }); - - it('sends bid requests to default endpoint for non standard publisher IDs', function () { - const modifiedBidRequest = Object.assign({}, bidRequest, { - params: Object.assign({}, bidRequest.params, { - publisherId: 'foo-bar', - }), - }); - const requests = qcSpec.buildRequests([modifiedBidRequest]); - expect(requests[0]['url']).to.equal( - `${QUANTCAST_PROTOCOL}://${QUANTCAST_DOMAIN}:${QUANTCAST_PORT}/qchb` - ); - }); - - it('sends bid requests to Quantcast Header Bidding Endpoints via POST', function () { - const requests = qcSpec.buildRequests([bidRequest]); - - expect(requests[0].method).to.equal('POST'); - }); - - const expectedBannerBidRequest = { - publisherId: QUANTCAST_TEST_PUBLISHER, - requestId: '2f7b179d443f14', - imp: [ - { - banner: { - battr: [1, 2], - sizes: [{ width: 300, height: 250 }] - }, - placementCode: 'div-gpt-ad-1438287399331-0', - bidFloor: 1e-10 - } - ], - site: { - page: 'http://example.com/hello.html', - referrer: 'http://example.com/hello.html', - domain: 'example.com' - }, - bidId: '2f7b179d443f14', - gdprSignal: 0, - uspSignal: 0, - coppa: 0, - prebidJsVersion: '$prebid.version$', - fpa: '' - }; - - it('sends banner bid requests contains all the required parameters', function () { - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - - expect(requests[0].data).to.equal(JSON.stringify(expectedBannerBidRequest)); - }); - - it('supports deprecated banner format', function () { - bidRequest.sizes = bidRequest.mediaTypes.banner.sizes; - delete bidRequest.mediaTypes; - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - - expect(requests[0].data).to.equal(JSON.stringify(expectedBannerBidRequest)); - }); - - it('sends video bid requests containing all the required parameters', function () { - setupVideoBidRequest({ - mimes: ['video/mp4'], // required - minduration: 3, // optional - maxduration: 5, // optional - protocols: [3], // optional - startdelay: 1, // optional - linearity: 1, // optinal - battr: [1, 2], // optional - maxbitrate: 10, // optional - playbackmethod: [1], // optional - delivery: [1], // optional - api: [2, 3] // optional - }, { - context: 'instream', - playerSize: [600, 300] - }); - - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - const expectedVideoBidRequest = { - publisherId: QUANTCAST_TEST_PUBLISHER, - requestId: '2f7b179d443f14', - imp: [ - { - video: { - mimes: ['video/mp4'], - minduration: 3, - maxduration: 5, - protocols: [3], - startdelay: 1, - linearity: 1, - battr: [1, 2], - maxbitrate: 10, - playbackmethod: [1], - delivery: [1], - api: [2, 3], - w: 600, - h: 300 - }, - placementCode: 'div-gpt-ad-1438287399331-0', - bidFloor: 1e-10 - } - ], - site: { - page: 'http://example.com/hello.html', - referrer: 'http://example.com/hello.html', - domain: 'example.com' - }, - bidId: '2f7b179d443f14', - gdprSignal: 0, - uspSignal: 0, - coppa: 0, - prebidJsVersion: '$prebid.version$', - fpa: '' - }; - - expect(requests[0].data).to.equal(JSON.stringify(expectedVideoBidRequest)); - }); - - it('sends video bid requests containing all the required parameters from mediaTypes', function() { - setupVideoBidRequest(null, { - mimes: ['video/mp4'], // required - minduration: 3, // optional - maxduration: 5, // optional - protocols: [3], // optional - startdelay: 1, // optional - linearity: 1, // optinal - battr: [1, 2], // optional - maxbitrate: 10, // optional - playbackmethod: [1], // optional - delivery: [1], // optional - api: [2, 3], // optional - context: 'instream', - playerSize: [600, 300] - }); - - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - const expectedVideoBidRequest = { - publisherId: QUANTCAST_TEST_PUBLISHER, - requestId: '2f7b179d443f14', - imp: [ - { - video: { - mimes: ['video/mp4'], - minduration: 3, - maxduration: 5, - protocols: [3], - startdelay: 1, - linearity: 1, - battr: [1, 2], - maxbitrate: 10, - playbackmethod: [1], - delivery: [1], - api: [2, 3], - w: 600, - h: 300 - }, - placementCode: 'div-gpt-ad-1438287399331-0', - bidFloor: 1e-10 - } - ], - site: { - page: 'http://example.com/hello.html', - referrer: 'http://example.com/hello.html', - domain: 'example.com' - }, - bidId: '2f7b179d443f14', - gdprSignal: 0, - uspSignal: 0, - coppa: 0, - prebidJsVersion: '$prebid.version$', - fpa: '' - }; - - expect(requests[0].data).to.equal(JSON.stringify(expectedVideoBidRequest)); - }); - - it('overrides video parameters with parameters from adunit', function() { - setupVideoBidRequest({ - mimes: ['video/mp4'] - }, { - context: 'instream', - playerSize: [600, 300] - }); - bidRequest.mediaTypes.video.mimes = ['video/webm']; - - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - const expectedVideoBidRequest = { - publisherId: QUANTCAST_TEST_PUBLISHER, - requestId: '2f7b179d443f14', - imp: [ - { - video: { - mimes: ['video/webm'], - w: 600, - h: 300 - }, - placementCode: 'div-gpt-ad-1438287399331-0', - bidFloor: 1e-10 - } - ], - site: { - page: 'http://example.com/hello.html', - referrer: 'http://example.com/hello.html', - domain: 'example.com' - }, - bidId: '2f7b179d443f14', - gdprSignal: 0, - uspSignal: 0, - coppa: 0, - prebidJsVersion: '$prebid.version$', - fpa: '' - }; - - expect(requests[0].data).to.equal(JSON.stringify(expectedVideoBidRequest)); - }); - - it('sends video bid request when no video parameters are given', function () { - setupVideoBidRequest(null, { - context: 'instream', - playerSize: [600, 300] - }); - - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - const expectedVideoBidRequest = { - publisherId: QUANTCAST_TEST_PUBLISHER, - requestId: '2f7b179d443f14', - imp: [ - { - video: { - w: 600, - h: 300 - }, - placementCode: 'div-gpt-ad-1438287399331-0', - bidFloor: 1e-10 - } - ], - site: { - page: 'http://example.com/hello.html', - referrer: 'http://example.com/hello.html', - domain: 'example.com' - }, - bidId: '2f7b179d443f14', - gdprSignal: 0, - uspSignal: 0, - coppa: 0, - prebidJsVersion: '$prebid.version$', - fpa: '' - }; - - expect(requests[0].data).to.equal(JSON.stringify(expectedVideoBidRequest)); - }); - - it('ignores unsupported video bid requests', function () { - bidRequest.mediaTypes = { - video: { - context: 'outstream', - playerSize: [[550, 310]] - } - }; - - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - - expect(requests).to.be.empty; - }); - - it('parses multi-format bid request', function () { - bidRequest.mediaTypes = { - banner: {sizes: [[300, 250], [728, 90], [250, 250], [468, 60], [320, 50]]}, - native: { - image: {required: true, sizes: [150, 50]}, - title: {required: true, len: 80}, - sponsoredBy: {required: true}, - clickUrl: {required: true}, - privacyLink: {required: false}, - body: {required: true}, - icon: {required: true, sizes: [50, 50]} - }, - video: { - context: 'outstream', - playerSize: [[550, 310]] - } - }; - - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - const expectedBidRequest = { - publisherId: QUANTCAST_TEST_PUBLISHER, - requestId: '2f7b179d443f14', - imp: [{ - banner: { - battr: [1, 2], - sizes: [ - {width: 300, height: 250}, - {width: 728, height: 90}, - {width: 250, height: 250}, - {width: 468, height: 60}, - {width: 320, height: 50} - ] - }, - placementCode: 'div-gpt-ad-1438287399331-0', - bidFloor: 1e-10 - }], - site: { - page: 'http://example.com/hello.html', - referrer: 'http://example.com/hello.html', - domain: 'example.com' - }, - bidId: '2f7b179d443f14', - gdprSignal: 0, - uspSignal: 0, - coppa: 0, - prebidJsVersion: '$prebid.version$', - fpa: '' - }; - - expect(requests[0].data).to.equal(JSON.stringify(expectedBidRequest)); - }); - }); - - it('propagates GDPR consent string and signal', function () { - const bidderRequest = { - gdprConsent: { - gdprApplies: true, - consentString: 'consentString' - } - }; - - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - const parsed = JSON.parse(requests[0].data); - - expect(parsed.gdprSignal).to.equal(1); - expect(parsed.gdprConsent).to.equal('consentString'); - }); - - it('allows TCF v2 request when Quantcast has consent for purpose 1', function() { - const bidderRequest = { - gdprConsent: { - gdprApplies: true, - consentString: 'consentString', - vendorData: { - vendor: { - consents: { - '11': true - } - }, - purpose: { - consents: { - '1': true - } - } - }, - apiVersion: 2 - } - }; - - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - const parsed = JSON.parse(requests[0].data); - - expect(parsed.gdprSignal).to.equal(1); - expect(parsed.gdprConsent).to.equal('consentString'); - }); - - it('blocks TCF v2 request when no consent for Quantcast', function() { - const bidderRequest = { - gdprConsent: { - gdprApplies: true, - consentString: 'consentString', - vendorData: { - vendor: { - consents: { - '11': false - } - }, - purpose: { - consents: { - '1': true - } - } - }, - apiVersion: 2 - } - }; - - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - - expect(requests).to.equal(undefined); - }); - - it('blocks TCF v2 request when no consent for purpose 1', function() { - const bidderRequest = { - gdprConsent: { - gdprApplies: true, - consentString: 'consentString', - vendorData: { - vendor: { - consents: { - '11': true - } - }, - purpose: { - consents: { - '1': false - } - } - }, - apiVersion: 2 - } - }; - - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - - expect(requests).to.equal(undefined); - }); - - it('blocks TCF v2 request when Quantcast not allowed by publisher', function () { - const bidderRequest = { - gdprConsent: { - gdprApplies: true, - consentString: 'consentString', - vendorData: { - vendor: { - consents: { - '11': true - } - }, - purpose: { - consents: { - '1': true - } - }, - publisher: { - restrictions: { - '1': { - '11': 0 - } - } - } - }, - apiVersion: 2 - } - }; - - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - - expect(requests).to.equal(undefined); - }); - - it('blocks TCF v2 request when legitimate interest required', function () { - const bidderRequest = { - gdprConsent: { - gdprApplies: true, - consentString: 'consentString', - vendorData: { - vendor: { - consents: { - '11': true - } - }, - purpose: { - consents: { - '1': true - } - }, - publisher: { - restrictions: { - '1': { - '11': 2 - } - } - } - }, - apiVersion: 2 - } - }; - - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - - expect(requests).to.equal(undefined); - }); - - it('propagates US Privacy/CCPA consent information', function () { - const bidderRequest = { uspConsent: 'consentString' } - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - const parsed = JSON.parse(requests[0].data); - expect(parsed.uspSignal).to.equal(1); - expect(parsed.uspConsent).to.equal('consentString'); - }); - - it('propagates Quantcast first-party cookie (fpa)', function() { - storage.setCookie('__qca', 'P0-TestFPA'); - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - const parsed = JSON.parse(requests[0].data); - expect(parsed.fpa).to.equal('P0-TestFPA'); - }); - - describe('propagates coppa', function() { - let sandbox; - beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('propagates coppa as 1 if coppa param is set to true in the bid request', function () { - bidRequest.params = { - publisherId: 'test_publisher_id', - coppa: true - }; - sandbox.stub(config, 'getConfig').callsFake((key) => { - const config = { - 'coppa': true - }; - return config[key]; - }); - const requests = qcSpec.buildRequests([bidRequest], bidderRequest); - expect(JSON.parse(requests[0].data).coppa).to.equal(1); - }); - - it('propagates coppa as 0 if there is no coppa param or coppa is set to false in the bid request', function () { - const requestsWithoutCoppa = qcSpec.buildRequests([bidRequest], bidderRequest); - expect(JSON.parse(requestsWithoutCoppa[0].data).coppa).to.equal(0); - - bidRequest.params = { - publisherId: 'test_publisher_id', - coppa: false - }; - sandbox.stub(config, 'getConfig').callsFake((key) => { - const config = { - 'coppa': false - }; - return config[key]; - }); - const requestsWithFalseCoppa = qcSpec.buildRequests([bidRequest], bidderRequest); - expect(JSON.parse(requestsWithFalseCoppa[0].data).coppa).to.equal(0); - }); - }); - - describe('`interpretResponse`', function () { - // The sample response is from https://wiki.corp.qc/display/adinf/QCX - const body = { - bidderCode: 'qcx', // Renaming it to use CamelCase since that is what is used in the Prebid.js variable name - requestId: 'erlangcluster@qa-rtb002.us-ec.adtech.com-11417780270886458', // Added this field. This is not used now but could be useful in troubleshooting later on. Specially for sites using iFrames - bids: [ - { - statusCode: 1, - placementCode: 'imp1', // Changing this to placementCode to be reflective - cpm: 4.5, - currency: 'USD', - ad: - '
Quantcast
', - creativeId: 1001, - width: 300, - height: 250, - meta: { - advertiserDomains: ['dailymail.com'] - } - } - ] - }; - - const response = { - body, - headers: {} - }; - - const videoBody = { - bidderCode: 'qcx', - requestId: 'erlangcluster@qa-rtb002.us-ec.adtech.com-11417780270886458', - bids: [ - { - statusCode: 1, - placementCode: 'video1', - cpm: 4.5, - currency: 'USD', - videoUrl: 'https://vast.quantserve.com/vast?p=&r=&gdpr=&gdpr_consent=&rand=1337&d=H4sIAAAAAAAAAONi4mIQcrzFqGLi5OzibOzmpGtm4eyia-LoaqDraGRupOtobGJhYuni6GRiYLmLiYWrp5f_BBPDDybGScxcPs7-aRYmpmVVoVJgCSXBkozMYl0gKslI1S1Izk9JBQALkFy_YAAAAA&h=uRnsTjyXbOrXJtBQiaMn239i9GI', - width: 600, - height: 300 - } - ] - }; - - const videoResponse = { - body: videoBody, - headers: {} - }; - - it('should return an empty array if `serverResponse` is `undefined`', function () { - const interpretedResponse = qcSpec.interpretResponse(); - - expect(interpretedResponse.length).to.equal(0); - }); - - it('should return an empty array if the parsed response does NOT include `bids`', function () { - const interpretedResponse = qcSpec.interpretResponse({}); - - expect(interpretedResponse.length).to.equal(0); - }); - - it('should return an empty array if the parsed response has an empty `bids`', function () { - const interpretedResponse = qcSpec.interpretResponse({ bids: [] }); - - expect(interpretedResponse.length).to.equal(0); - }); - - it('should get correct bid response', function () { - const expectedResponse = { - requestId: 'erlangcluster@qa-rtb002.us-ec.adtech.com-11417780270886458', - cpm: 4.5, - width: 300, - height: 250, - ad: - '
Quantcast
', - ttl: QUANTCAST_TTL, - creativeId: 1001, - netRevenue: QUANTCAST_NET_REVENUE, - currency: 'USD', - meta: { - advertiserDomains: ['dailymail.com'] - } - }; - const interpretedResponse = qcSpec.interpretResponse(response); - - expect(interpretedResponse[0]).to.deep.equal(expectedResponse); - }); - - it('should include dealId in bid response', function () { - response.body.bids[0].dealId = 'test-dealid'; - const expectedResponse = { - requestId: 'erlangcluster@qa-rtb002.us-ec.adtech.com-11417780270886458', - cpm: 4.5, - width: 300, - height: 250, - ad: - '
Quantcast
', - ttl: QUANTCAST_TTL, - creativeId: 1001, - netRevenue: QUANTCAST_NET_REVENUE, - currency: 'USD', - dealId: 'test-dealid', - meta: { - advertiserDomains: ['dailymail.com'] - } - }; - const interpretedResponse = qcSpec.interpretResponse(response); - - expect(interpretedResponse[0]).to.deep.equal(expectedResponse); - }); - - it('should get correct bid response for instream video', function() { - const expectedResponse = { - requestId: 'erlangcluster@qa-rtb002.us-ec.adtech.com-11417780270886458', - cpm: 4.5, - width: 600, - height: 300, - vastUrl: 'https://vast.quantserve.com/vast?p=&r=&gdpr=&gdpr_consent=&rand=1337&d=H4sIAAAAAAAAAONi4mIQcrzFqGLi5OzibOzmpGtm4eyia-LoaqDraGRupOtobGJhYuni6GRiYLmLiYWrp5f_BBPDDybGScxcPs7-aRYmpmVVoVJgCSXBkozMYl0gKslI1S1Izk9JBQALkFy_YAAAAA&h=uRnsTjyXbOrXJtBQiaMn239i9GI', - mediaType: 'video', - ttl: QUANTCAST_TTL, - creativeId: undefined, - ad: undefined, - netRevenue: QUANTCAST_NET_REVENUE, - currency: 'USD' - }; - const interpretedResponse = qcSpec.interpretResponse(videoResponse); - - expect(interpretedResponse[0]).to.deep.equal(expectedResponse); - }); - - it('handles no bid response', function () { - const body = { - bidderCode: 'qcx', // Renaming it to use CamelCase since that is what is used in the Prebid.js variable name - requestId: 'erlangcluster@qa-rtb002.us-ec.adtech.com-11417780270886458', // Added this field. This is not used now but could be useful in troubleshooting later on. Specially for sites using iFrames - bids: [] - }; - const response = { - body, - headers: {} - }; - const interpretedResponse = qcSpec.interpretResponse(response); - - expect(interpretedResponse.length).to.equal(0); - }); - - it('should return pixel url when available userSync available', function () { - const syncOptions = { - pixelEnabled: true - }; - const serverResponses = [ - { - body: { - userSync: { - url: 'http://quantcast.com/pixelUrl' - } - } - }, - { - body: { - - } - } - ]; - - const actualSyncs = qcSpec.getUserSyncs(syncOptions, serverResponses); - const expectedSync = { - type: 'image', - url: 'http://quantcast.com/pixelUrl' - }; - expect(actualSyncs.length).to.equal(1); - expect(actualSyncs[0]).to.deep.equal(expectedSync); - qcSpec.resetUserSync(); - }); - - it('should not return user syncs if done already', function () { - const syncOptions = { - pixelEnabled: true - }; - const serverResponses = [ - { - body: { - userSync: { - url: 'http://quantcast.com/pixelUrl' - } - } - }, - { - body: { - - } - } - ]; - - let actualSyncs = qcSpec.getUserSyncs(syncOptions, serverResponses); - const expectedSync = { - type: 'image', - url: 'http://quantcast.com/pixelUrl' - }; - expect(actualSyncs.length).to.equal(1); - expect(actualSyncs[0]).to.deep.equal(expectedSync); - - actualSyncs = qcSpec.getUserSyncs(syncOptions, serverResponses); - expect(actualSyncs.length).to.equal(0); - - qcSpec.resetUserSync(); - }); - }); -}); diff --git a/test/spec/modules/qwarryBidAdapter_spec.js b/test/spec/modules/qwarryBidAdapter_spec.js deleted file mode 100644 index ae9302774..000000000 --- a/test/spec/modules/qwarryBidAdapter_spec.js +++ /dev/null @@ -1,170 +0,0 @@ -import { expect } from 'chai' -import { ENDPOINT, spec } from 'modules/qwarryBidAdapter.js' -import { newBidder } from 'src/adapters/bidderFactory.js' - -const REQUEST = { - 'bidId': '456', - 'bidder': 'qwarry', - 'sizes': [[100, 200], [300, 400]], - 'params': { - zoneToken: 'e64782a4-8e68-4c38-965b-80ccf115d46f', - pos: 7 - }, - 'ortb2': { - 'source': { - 'ext': { - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [{ - 'asi': 'qwarry.com', - 'sid': '00001', - 'hp': 1 - }] - } - } - } - } -} - -const BIDDER_BANNER_RESPONSE = { - 'prebidResponse': [{ - 'ad': '
test
', - 'requestId': 'e64782a4-8e68-4c38-965b-80ccf115d46d', - 'cpm': 900.5, - 'currency': 'USD', - 'width': 640, - 'height': 480, - 'ttl': 300, - 'creativeId': 1, - 'netRevenue': true, - 'winUrl': 'http://test.com', - 'format': 'banner', - 'adomain': ['test.com'] - }] -} - -const BIDDER_VIDEO_RESPONSE = { - 'prebidResponse': [{ - 'ad': 'vast', - 'requestId': 'e64782a4-8e68-4c38-965b-80ccf115d46z', - 'cpm': 800.4, - 'currency': 'USD', - 'width': 1024, - 'height': 768, - 'ttl': 200, - 'creativeId': 2, - 'netRevenue': true, - 'winUrl': 'http://test.com', - 'format': 'video', - 'adomain': ['test.com'] - }] -} - -const BIDDER_NO_BID_RESPONSE = '' - -describe('qwarryBidAdapter', function () { - const adapter = newBidder(spec) - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function') - }) - }) - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(REQUEST)).to.equal(true) - }) - - it('should return false when required params are not passed', function () { - const bid = Object.assign({}, REQUEST) - delete bid.params.zoneToken - expect(spec.isBidRequestValid(bid)).to.equal(false) - delete bid.params - expect(spec.isBidRequestValid(bid)).to.equal(false) - }) - }) - - describe('buildRequests', function () { - const bidRequests = [REQUEST] - const bidderRequest = spec.buildRequests(bidRequests, { - bidderRequestId: '123', - gdprConsent: { - gdprApplies: true, - consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==' - }, - refererInfo: { - page: 'http://test.com/path.html', - } - }) - - it('sends bid request to ENDPOINT via POST', function () { - expect(bidderRequest.method).to.equal('POST') - expect(bidderRequest.data.requestId).to.equal('123') - expect(bidderRequest.data.referer).to.equal('http://test.com/path.html') - expect(bidderRequest.data.schain).to.deep.contains({ver: '1.0', complete: 1, nodes: [{asi: 'qwarry.com', sid: '00001', hp: 1}]}) - expect(bidderRequest.data.bids).to.deep.contains({ bidId: '456', zoneToken: 'e64782a4-8e68-4c38-965b-80ccf115d46f', pos: 7, sizes: [{ width: 100, height: 200 }, { width: 300, height: 400 }] }) - expect(bidderRequest.data.gdprConsent).to.deep.contains({ consentRequired: true, consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==' }) - expect(bidderRequest.options.customHeaders).to.deep.equal({ 'Rtb-Direct': true }) - expect(bidderRequest.options.contentType).to.equal('application/json') - expect(bidderRequest.url).to.equal(ENDPOINT) - }) - }) - - describe('interpretResponse', function () { - it('handles banner request : should get correct bid response', function () { - const result = spec.interpretResponse({ body: BIDDER_BANNER_RESPONSE }, {}) - - expect(result[0]).to.have.property('ad').equal('
test
') - expect(result[0]).to.have.property('requestId').equal('e64782a4-8e68-4c38-965b-80ccf115d46d') - expect(result[0]).to.have.property('cpm').equal(900.5) - expect(result[0]).to.have.property('currency').equal('USD') - expect(result[0]).to.have.property('width').equal(640) - expect(result[0]).to.have.property('height').equal(480) - expect(result[0]).to.have.property('ttl').equal(300) - expect(result[0]).to.have.property('creativeId').equal(1) - expect(result[0]).to.have.property('netRevenue').equal(true) - expect(result[0]).to.have.property('winUrl').equal('http://test.com') - expect(result[0]).to.have.property('format').equal('banner') - expect(result[0].meta).to.exist.property('advertiserDomains') - expect(result[0].meta).to.have.property('advertiserDomains').lengthOf(1) - }) - - it('handles video request : should get correct bid response', function () { - const result = spec.interpretResponse({ body: BIDDER_VIDEO_RESPONSE }, {}) - - expect(result[0]).to.have.property('ad').equal('vast') - expect(result[0]).to.have.property('requestId').equal('e64782a4-8e68-4c38-965b-80ccf115d46z') - expect(result[0]).to.have.property('cpm').equal(800.4) - expect(result[0]).to.have.property('currency').equal('USD') - expect(result[0]).to.have.property('width').equal(1024) - expect(result[0]).to.have.property('height').equal(768) - expect(result[0]).to.have.property('ttl').equal(200) - expect(result[0]).to.have.property('creativeId').equal(2) - expect(result[0]).to.have.property('netRevenue').equal(true) - expect(result[0]).to.have.property('winUrl').equal('http://test.com') - expect(result[0]).to.have.property('format').equal('video') - expect(result[0]).to.have.property('vastXml').equal('vast') - expect(result[0].meta).to.exist.property('advertiserDomains') - expect(result[0].meta).to.have.property('advertiserDomains').lengthOf(1) - }) - - it('handles no bid response : should get empty array', function () { - let result = spec.interpretResponse({ body: undefined }, {}) - expect(result).to.deep.equal([]) - - result = spec.interpretResponse({ body: BIDDER_NO_BID_RESPONSE }, {}) - expect(result).to.deep.equal([]) - }) - }) - - describe('onBidWon', function () { - it('handles banner win: should get true', function () { - const win = BIDDER_BANNER_RESPONSE.prebidResponse[0] - const bidWonResult = spec.onBidWon(win) - - expect(bidWonResult).to.equal(true) - }) - }) -}) diff --git a/test/spec/modules/r2b2BidAdapter_spec.js b/test/spec/modules/r2b2BidAdapter_spec.js deleted file mode 100644 index 2d506ab8d..000000000 --- a/test/spec/modules/r2b2BidAdapter_spec.js +++ /dev/null @@ -1,689 +0,0 @@ -import {expect} from 'chai'; -import {spec, internal as r2b2, internal} from 'modules/r2b2BidAdapter.js'; -import * as utils from '../../../src/utils.js'; -import 'modules/userId/index.js'; - -function encodePlacementIds (ids) { - return btoa(JSON.stringify(ids)); -} - -describe('R2B2 adapter', function () { - let serverResponse, requestForInterpretResponse; - let bidderRequest; - let bids = []; - const gdprConsent = { - gdprApplies: true, - consentString: 'consent-string', - }; - const schain = { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'example.com', - sid: '00001', - hp: 1 - }] - }; - const usPrivacyString = '1YNN'; - const impId = 'impID'; - const price = 10.6; - const ad = 'adm'; - const creativeId = 'creativeID'; - const cid = 41849; - const cdid = 595121; - const unitCode = 'unitCode'; - const bidId1 = '1'; - const bidId2 = '2'; - const bidId3 = '3'; - const bidId4 = '4'; - const bidId5 = '5'; - const bidWonUrl = 'url1'; - const setTargetingUrl = 'url2'; - const bidder = 'r2b2'; - const foreignBidder = 'differentBidder'; - const id1 = { pid: 'd/g/p' }; - const id1Object = { d: 'd', g: 'g', p: 'p', m: 0 }; - const id2 = { pid: 'd/g/p/1' }; - const id2Object = { d: 'd', g: 'g', p: 'p', m: 1 }; - const badId = { pid: 'd/g/' }; - const bid1 = { bidId: bidId1, bidder, params: [ id1 ] }; - const bid2 = { bidId: bidId2, bidder, params: [ id2 ] }; - const bidWithBadSetup = { bidId: bidId3, bidder, params: [ badId ] }; - const bidForeign1 = { bidId: bidId4, bidder: foreignBidder, params: [ { id: 'abc' } ] }; - const bidForeign2 = { bidId: bidId5, bidder: foreignBidder, params: [ { id: 'xyz' } ] }; - const fakeTime = 1234567890; - const cacheBusterRegex = /[\?&]cb=([^&]+)/; - let bidStub, time; - - beforeEach(function () { - bids = [{ - bidder: 'r2b2', - params: { - pid: 'example.com/generic/300x250/1' - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - adUnitCode: unitCode, - transactionId: '29c408b9-65ce-48b1-9167-18a57791f908', - sizes: [ - [300, 250] - ], - bidId: '20917a54ee9858', - bidderRequestId: '15270d403778d', - auctionId: '36acef1b-f635-4f57-b693-5cc55ee16346', - src: 'client', - ortb2: { - regs: { - ext: { - gdpr: 1, - us_privacy: '1YYY' - } - }, - user: { - ext: { - consent: 'consent-string' - } - }, - site: {}, - device: {}, - source: {ext: {schain: schain}} - }, - }, { - bidder: 'r2b2', - params: { - pid: 'example.com/generic/300x600/0' - }, - mediaTypes: { - banner: { - sizes: [ - [300, 600] - ] - } - }, - adUnitCode: unitCode, - transactionId: '29c408b9-65ce-48b1-9167-18a57791f908', - sizes: [ - [300, 600] - ], - bidId: '3dd53d30c691fe', - bidderRequestId: '15270d403778d', - auctionId: '36acef1b-f635-4f57-b693-5cc55ee16346', - src: 'client', - ortb2: { - regs: { - ext: { - gdpr: 1, - us_privacy: '1YYY' - } - }, - user: { - ext: { - consent: 'consent-string' - } - }, - site: {}, - device: {}, - source: {ext: {schain: schain}} - }, - }]; - bidderRequest = { - bidderCode: 'r2b2', - auctionId: '36acef1b-f635-4f57-b693-5cc55ee16346', - bidderRequestId: '15270d403778d', - bids: bids, - ortb2: { - regs: { - ext: { - gdpr: 1, - us_privacy: '1YYY' - } - }, - user: { - ext: { - consent: 'consent-string' - } - }, - site: {}, - device: {}, - source: {ext: {schain: schain}} - }, - gdprConsent: { - consentString: 'consent-string', - vendorData: {}, - gdprApplies: true, - apiVersion: 2 - }, - uspConsent: '1YYY', - }; - serverResponse = { - id: 'a66a6e32-2a7d-4ed3-bb13-6f3c9bdcf6a1', - seatbid: [{ - bid: [{ - id: '4756cc9e9b504fd0bd39fdd594506545', - impid: impId, - price: price, - adm: ad, - crid: creativeId, - w: 300, - h: 250, - ext: { - prebid: { - meta: { - adaptercode: 'r2b2' - }, - type: 'banner' - }, - r2b2: { - cdid: cdid, - cid: cid, - useRenderer: true - } - } - }], - seat: 'seat' - }] - }; - requestForInterpretResponse = { - data: { - imp: [ - {id: impId} - ] - }, - bids - }; - }); - - describe('isBidRequestValid', function () { - const bid = {}; - - it('should return false when missing required "pid" param', function () { - bid.params = {random: 'param'}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - bid.params = {d: 'd', g: 'g', p: 'p', m: 1}; - expect(spec.isBidRequestValid(bid)).to.equal(false) - }); - - it('should return false when "pid" is malformed', function () { - bid.params = {pid: 'pid'}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - bid.params = {pid: '///'}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - bid.params = {pid: '/g/p/m'}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - bid.params = {pid: 'd//p/m'}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - bid.params = {pid: 'd/g//m'}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - bid.params = {pid: 'd/p/'}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - bid.params = {pid: 'd/g/p/m/t'}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when "pid" is a correct dgpm', function () { - bid.params = {pid: 'd/g/p/m'}; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should return true when type is blank', function () { - bid.params = {pid: 'd/g/p/'}; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should return true when type is missing', function () { - bid.params = {pid: 'd/g/p'}; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should return true when "pid" is a number', function () { - bid.params = {pid: 12356}; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should return true when "pid" is a numeric string', function () { - bid.params = {pid: '12356'}; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should return true for selfpromo unit', function () { - bid.params = {pid: 'selfpromo'}; - expect(spec.isBidRequestValid(bid)).to.equal(true) - }); - }); - - describe('buildRequests', function () { - beforeEach(function () { - r2b2.placementsToSync = []; - r2b2.mappedParams = {}; - }); - - it('should set correct request method and url and pass bids', function () { - const requests = spec.buildRequests([bids[0]], bidderRequest); - expect(requests).to.be.an('array').that.has.lengthOf(1); - const request = requests[0] - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://hb.r2b2.cz/openrtb2/bid'); - expect(request.data).to.be.an('object'); - expect(request.bids).to.deep.equal(bids); - }); - - it('should pass correct parameters', function () { - const requests = spec.buildRequests([bids[0]], bidderRequest); - const {data} = requests[0]; - const {imp, device, site, source, ext, cur, test} = data; - expect(imp).to.be.an('array').that.has.lengthOf(1); - expect(device).to.be.an('object'); - expect(site).to.be.an('object'); - expect(source).to.be.an('object'); - expect(cur).to.deep.equal(['USD']); - expect(ext.version).to.equal('1.0.0'); - expect(test).to.equal(0); - }); - - it('should pass correct imp', function () { - const requests = spec.buildRequests([bids[0]], bidderRequest); - const {data} = requests[0]; - const {imp} = data; - expect(imp).to.be.an('array').that.has.lengthOf(1); - expect(imp[0]).to.be.an('object'); - const bid = imp[0]; - expect(bid.id).to.equal('20917a54ee9858'); - expect(bid.banner).to.deep.equal({topframe: 0, format: [{w: 300, h: 250}]}); - expect(bid.ext).to.be.an('object'); - expect(bid.ext.r2b2).to.deep.equal({d: 'example.com', g: 'generic', p: '300x250', m: 1}); - }); - - it('should map type correctly', function () { - let result, bid; - const requestWithId = function(id) { - const b = bids[0]; - b.params.pid = id; - const passedBids = [b]; - bidderRequest.bids = passedBids; - return spec.buildRequests(passedBids, bidderRequest); - }; - - result = requestWithId('example.com/generic/300x250/mobile'); - bid = result[0].data.imp[0]; - expect(bid.ext.r2b2.m).to.be.a('number').that.is.equal(1); - - result = requestWithId('example.com/generic/300x250/desktop'); - bid = result[0].data.imp[0]; - expect(bid.ext.r2b2.m).to.be.a('number').that.is.equal(0); - - result = requestWithId('example.com/generic/300x250/1'); - bid = result[0].data.imp[0]; - expect(bid.ext.r2b2.m).to.be.a('number').that.is.equal(1); - - result = requestWithId('example.com/generic/300x250/0'); - bid = result[0].data.imp[0]; - expect(bid.ext.r2b2.m).to.be.a('number').that.is.equal(0); - - result = requestWithId('example.com/generic/300x250/m'); - bid = result[0].data.imp[0]; - expect(bid.ext.r2b2.m).to.be.a('number').that.is.equal(1); - - result = requestWithId('example.com/generic/300x250'); - bid = result[0].data.imp[0]; - expect(bid.ext.r2b2.m).to.be.a('number').that.is.equal(0); - }); - - it('should pass correct parameters for test ad', function () { - const testAdBid = bids[0]; - testAdBid.params = {pid: 'selfpromo'}; - const requests = spec.buildRequests([testAdBid], bidderRequest); - const {data} = requests[0]; - const {imp} = data; - expect(imp).to.be.an('array').that.has.lengthOf(1); - expect(imp[0]).to.be.an('object'); - const bid = imp[0]; - expect(bid.ext).to.be.an('object'); - expect(bid.ext.r2b2).to.deep.equal({d: 'test', g: 'test', p: 'selfpromo', m: 0, 'selfpromo': 1}); - }); - - it('should pass multiple bids', function () { - const requests = spec.buildRequests(bids, bidderRequest); - expect(requests).to.be.an('array').that.has.lengthOf(1); - const {data} = requests[0]; - const {imp} = data; - expect(imp).to.be.an('array').that.has.lengthOf(bids.length); - const bid1 = imp[0]; - expect(bid1.ext.r2b2).to.deep.equal({d: 'example.com', g: 'generic', p: '300x250', m: 1}); - const bid2 = imp[1]; - expect(bid2.ext.r2b2).to.deep.equal({d: 'example.com', g: 'generic', p: '300x600', m: 0}); - }); - - it('should set up internal variables', function () { - const requests = spec.buildRequests(bids, bidderRequest); - const bid1Id = bids[0].bidId; - const bid2Id = bids[1].bidId; - expect(r2b2.placementsToSync).to.be.an('array').that.has.lengthOf(2); - expect(r2b2.mappedParams).to.have.property(bid1Id); - expect(r2b2.mappedParams[bid1Id]).to.deep.equal({d: 'example.com', g: 'generic', p: '300x250', m: 1, pid: 'example.com/generic/300x250/1'}); - expect(r2b2.mappedParams).to.have.property(bid2Id); - expect(r2b2.mappedParams[bid2Id]).to.deep.equal({d: 'example.com', g: 'generic', p: '300x600', m: 0, pid: 'example.com/generic/300x600/0'}); - }); - - it('should pass gdpr properties', function () { - const requests = spec.buildRequests(bids, bidderRequest); - const {data} = requests[0]; - const {user, regs} = data; - expect(user).to.be.an('object').that.has.property('ext'); - expect(regs).to.be.an('object').that.has.property('ext'); - expect(user.ext.consent).to.equal('consent-string'); - expect(regs.ext.gdpr).to.equal(1); - }); - - it('should pass us privacy properties', function () { - const requests = spec.buildRequests(bids, bidderRequest); - const {data} = requests[0]; - const {regs} = data; - expect(regs).to.be.an('object').that.has.property('ext'); - expect(regs.ext.us_privacy).to.equal('1YYY'); - }); - - it('should pass supply chain', function () { - const requests = spec.buildRequests(bids, bidderRequest); - const {data} = requests[0]; - const {source} = data; - expect(source).to.be.an('object').that.has.property('ext'); - expect(source.ext.schain).to.deep.equal({ - complete: 1, - nodes: [ - {asi: 'example.com', hp: 1, sid: '00001'} - ], - ver: '1.0' - }) - }); - - it('should pass extended ids', function () { - const eidsArray = [ - { - source: 'adserver.org', - uids: [ - { - atype: 1, - ext: { - rtiPartner: 'TDID', - }, - id: 'TTD_ID_FROM_USER_ID_MODULE', - }, - ], - }, - { - source: 'pubcid.org', - uids: [ - { - atype: 1, - id: 'pubCommonId_FROM_USER_ID_MODULE', - }, - ], - }, - ]; - bidderRequest.ortb2 = {user: {ext: {eids: eidsArray}}} - const requests = spec.buildRequests(bids, bidderRequest); - const request = requests[0]; - const eids = request.data.user.ext.eids; - - expect(eids).to.deep.equal(eidsArray); - }); - }); - - describe('interpretResponse', function () { - it('should respond with empty response when there are no bids', function () { - let result = spec.interpretResponse({ body: {} }, {}); - expect(result).to.be.an('array').that.has.lengthOf(0); - result = spec.interpretResponse({ body: { seatbid: [] } }, {}); - expect(result).to.be.an('array').that.has.lengthOf(0); - result = spec.interpretResponse({ body: { seatbid: [ {} ] } }, {}); - expect(result).to.be.an('array').that.has.lengthOf(0); - result = spec.interpretResponse({ body: { seatbid: [ { bids: [] } ] } }, {}); - expect(result).to.be.an('array').that.has.lengthOf(0); - }); - - it('should map params correctly', function () { - const result = spec.interpretResponse({ body: serverResponse }, requestForInterpretResponse); - expect(result).to.be.an('array').that.has.lengthOf(1); - const bid = result[0]; - expect(bid.requestId).to.equal(impId); - expect(bid.cpm).to.equal(price); - expect(bid.ad).to.equal(ad); - expect(bid.currency).to.equal('USD'); - expect(bid.mediaType).to.equal('banner'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.netRevenue).to.equal(true); - expect(bid.ttl).to.equal(360); - expect(bid.creativeId).to.equal(creativeId); - }); - - it('should set up renderer on bid', function () { - const result = spec.interpretResponse({ body: serverResponse }, requestForInterpretResponse); - expect(result).to.be.an('array').that.has.lengthOf(1); - const bid = result[0]; - expect(bid.renderer).to.be.an('object'); - expect(bid.renderer).to.have.property('render').that.is.a('function'); - expect(bid.renderer).to.have.property('url').that.is.a('string'); - }); - - it('should map ext params correctly', function() { - const dgpm = {something: 'something'}; - r2b2.mappedParams = {}; - r2b2.mappedParams[impId] = dgpm; - const result = spec.interpretResponse({ body: serverResponse }, requestForInterpretResponse); - expect(result).to.be.an('array').that.has.lengthOf(1); - const bid = result[0]; - expect(bid.ext).to.be.an('object'); - const { ext } = bid; - expect(ext.dgpm).to.deep.equal(dgpm); - expect(ext.cid).to.equal(cid); - expect(ext.cdid).to.equal(cdid); - expect(ext.adUnit).to.equal(unitCode); - expect(ext.mediaType).to.deep.equal({ - type: 'banner', - settings: { - chd: null, - width: 300, - height: 250, - ad: { - type: 'content', - data: ad - } - } - }); - }); - - it('should handle multiple bids', function() { - const impId2 = '123456'; - const price2 = 12; - const ad2 = 'gaeouho'; - const w2 = 300; - const h2 = 600; - const b = serverResponse.seatbid[0].bid[0]; - const b2 = Object.assign({}, b); - b2.impid = impId2; - b2.price = price2; - b2.adm = ad2; - b2.w = w2; - b2.h = h2; - serverResponse.seatbid[0].bid.push(b2); - requestForInterpretResponse.data.imp.push({id: impId2}); - const result = spec.interpretResponse({ body: serverResponse }, requestForInterpretResponse); - expect(result).to.be.an('array').that.has.lengthOf(2); - const firstBid = result[0]; - const secondBid = result[1]; - expect(firstBid.requestId).to.equal(impId); - expect(firstBid.ad).to.equal(ad); - expect(firstBid.cpm).to.equal(price); - expect(firstBid.width).to.equal(300); - expect(firstBid.height).to.equal(250); - expect(secondBid.requestId).to.equal(impId2); - expect(secondBid.ad).to.equal(ad2); - expect(secondBid.cpm).to.equal(price2); - expect(secondBid.width).to.equal(w2); - expect(secondBid.height).to.equal(h2); - }); - }); - - describe('getUserSyncs', function() { - const syncOptions = { - iframeEnabled: true, - pixelEnabled: true - }; - - it('should return an array with a sync for all bids', function() { - r2b2.placementsToSync = [id1Object, id2Object]; - const expectedEncodedIds = encodePlacementIds(r2b2.placementsToSync); - const syncs = spec.getUserSyncs(syncOptions); - expect(syncs).to.be.an('array').that.has.lengthOf(1); - const sync = syncs[0]; - expect(sync).to.be.an('object'); - expect(sync.type).to.equal('iframe'); - expect(sync.url).to.include(`?p=${expectedEncodedIds}`); - }); - - it('should return the sync and include gdpr and usp parameters in the url', function() { - r2b2.placementsToSync = [id1Object, id2Object]; - const syncs = spec.getUserSyncs(syncOptions, {}, gdprConsent, usPrivacyString); - const sync = syncs[0]; - expect(sync).to.be.an('object'); - expect(sync.url).to.include(`&gdpr=1`); - expect(sync.url).to.include(`&gdpr_consent=${gdprConsent.consentString}`); - expect(sync.url).to.include(`&us_privacy=${usPrivacyString}`); - }); - }); - - describe('events', function() { - beforeEach(function() { - time = sinon.useFakeTimers(fakeTime); - sinon.stub(utils, 'triggerPixel'); - r2b2.mappedParams = {}; - r2b2.mappedParams[bidId1] = id1Object; - r2b2.mappedParams[bidId2] = id2Object; - bidStub = { - adserverTargeting: { hb_bidder: bidder, hb_pb: '10.00', hb_size: '300x300' }, - cpm: 10, - currency: 'USD', - ext: { - dgpm: { d: 'r2b2.cz', g: 'generic', m: 1, p: '300x300', pid: 'r2b2.cz/generic/300x300/1' } - }, - params: [ { pid: 'r2b2.cz/generic/300x300/1' } ], - }; - }); - afterEach(function() { - utils.triggerPixel.restore(); - time.restore(); - }); - - describe('onBidWon', function () { - it('exists and is a function', () => { - expect(spec.onBidWon).to.exist.and.to.be.a('function'); - }); - it('should return nothing and trigger a pixel with passed url', function () { - bidStub.ext.events = { - onBidWon: bidWonUrl, - onSetTargeting: setTargetingUrl - }; - const response = spec.onBidWon(bidStub); - expect(response).to.be.an('undefined'); - expect(utils.triggerPixel.called).to.equal(true); - expect(utils.triggerPixel.callCount).to.equal(1); - expect(utils.triggerPixel.calledWithMatch(bidWonUrl)).to.equal(true); - }); - it('should not trigger a pixel if url is not available', function () { - bidStub.ext.events = null; - spec.onBidWon(bidStub); - expect(utils.triggerPixel.callCount).to.equal(0); - bidStub.ext.events = { - onBidWon: '', - onSetTargeting: '', - }; - spec.onBidWon(bidStub); - expect(utils.triggerPixel.callCount).to.equal(0); - }); - }); - - describe('onSetTargeting', function () { - it('exists and is a function', () => { - expect(spec.onSetTargeting).to.exist.and.to.be.a('function'); - }); - it('should return nothing and trigger a pixel with passed url', function () { - bidStub.ext.events = { - onBidWon: bidWonUrl, - onSetTargeting: setTargetingUrl - }; - const response = spec.onSetTargeting(bidStub); - expect(response).to.be.an('undefined'); - expect(utils.triggerPixel.called).to.equal(true); - expect(utils.triggerPixel.callCount).to.equal(1); - expect(utils.triggerPixel.calledWithMatch(setTargetingUrl)).to.equal(true); - }); - it('should not trigger a pixel if url is not available', function () { - bidStub.ext.events = null; - spec.onSetTargeting(bidStub); - expect(utils.triggerPixel.callCount).to.equal(0); - bidStub.ext.events = { - onBidWon: '', - onSetTargeting: '', - }; - spec.onSetTargeting(bidStub); - expect(utils.triggerPixel.callCount).to.equal(0); - }); - }); - - describe('onTimeout', function () { - it('exists and is a function', () => { - expect(spec.onTimeout).to.exist.and.to.be.a('function'); - }); - it('should return nothing and trigger a pixel', function () { - const bids = [bid1, bid2]; - const response = spec.onTimeout(bids); - expect(response).to.be.an('undefined'); - expect(utils.triggerPixel.callCount).to.equal(1); - }); - it('should not trigger a pixel if no bids available', function () { - const bids = []; - spec.onTimeout(bids); - expect(utils.triggerPixel.callCount).to.equal(0); - }); - it('should trigger a pixel with correct ids and a cache buster', function () { - const bids = [bid1, bidForeign1, bidForeign2, bid2, bidWithBadSetup]; - const expectedIds = [id1Object, id2Object]; - const expectedEncodedIds = encodePlacementIds(expectedIds); - spec.onTimeout(bids); - expect(utils.triggerPixel.callCount).to.equal(1); - const triggeredUrl = utils.triggerPixel.args[0][0]; - expect(triggeredUrl).to.include(`p=${expectedEncodedIds}`); - expect(triggeredUrl.match(cacheBusterRegex)).to.exist; - }); - }); - - describe('onBidderError', function () { - it('exists and is a function', () => { - expect(spec.onBidderError).to.exist.and.to.be.a('function'); - }); - it('should return nothing and trigger a pixel', function () { - const bidderRequest = { bids: [bid1, bid2] }; - const response = spec.onBidderError({ bidderRequest }); - expect(response).to.be.an('undefined') - expect(utils.triggerPixel.callCount).to.equal(1); - }); - it('should not trigger a pixel if no bids available', function () { - const bidderRequest = { bids: [] }; - spec.onBidderError({ bidderRequest }); - expect(utils.triggerPixel.callCount).to.equal(0); - }); - it('should call triggerEvent with correct ids and a cache buster', function () { - const bids = [bid1, bid2, bidWithBadSetup] - const bidderRequest = { bids }; - const expectedIds = [id1Object, id2Object]; - const expectedEncodedIds = encodePlacementIds(expectedIds); - spec.onBidderError({ bidderRequest }); - expect(utils.triggerPixel.callCount).to.equal(1); - const triggeredUrl = utils.triggerPixel.args[0][0]; - expect(triggeredUrl).to.include(`p=${expectedEncodedIds}`); - expect(triggeredUrl.match(cacheBusterRegex)).to.exist; - }); - }); - }); -}); diff --git a/test/spec/modules/rakutenBidAdapter_spec.js b/test/spec/modules/rakutenBidAdapter_spec.js deleted file mode 100644 index e6cdb12e3..000000000 --- a/test/spec/modules/rakutenBidAdapter_spec.js +++ /dev/null @@ -1,171 +0,0 @@ -import { expect } from 'chai' -import { spec } from 'modules/rakutenBidAdapter/index.js' -import { newBidder } from 'src/adapters/bidderFactory.js' -import {config} from '../../../src/config.js'; - -describe('rakutenBidAdapter', function() { - const adapter = newBidder(spec); - const ENDPOINT = 'https://s-bid.rmp.rakuten.com/h'; - let sandbox; - - beforeEach(function() { - config.resetConfig(); - }); - - afterEach(function () { - config.resetConfig(); - }); - - describe('inherited functions', () => { - it('exists and is a function', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function') - }) - }); - - describe('isBidRequestValid', () => { - const bid = { - bidder: 'rakuten', - params: { - adSpotId: '56789' - } - }; - - it('should return true when required params found', () => { - expect(spec.isBidRequestValid(bid)).to.equal(true) - }); - - it('should return false when required params are not passed', () => { - bid.params.adSpotId = ''; - expect(spec.isBidRequestValid(bid)).to.equal(false) - }); - - it('should return false when required params are not passed', () => { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false) - }) - }); - - describe('buildRequests', () => { - const bidRequests = [ - { - // banner - params: { - adSpotId: '58278' - } - } - ]; - - const bidderRequest = { - bids: bidRequests, - refererInfo: { - referer: 'http://test.com', - stack: ['http://test.com'] - }, - gdprConsent: { - consentString: 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - vendorData: {}, - gdprApplies: true - }, - uspConsent: '1YN-' - }; - - it('sends bid request to ENDPOINT via GET', () => { - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('GET') - expect(request.data.gdpr).to.equal(1); - expect(request.data.cd).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A=='); - expect(request.data.ccpa).to.equal('1YN-'); - }); - - it('allows url override', () => { - config.setConfig({ - rakuten: { - endpoint: '//test.rakuten.com' - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.url).to.equal('//test.rakuten.com'); - }) - }); - - describe('interpretResponse', () => { - const bidRequests = { - banner: { - method: 'GET', - url: '', - data: { - t: '56789', - s: 'https', - ua: - 'Mozilla/5.0 (Linux; Android 5.0; SM-G900P Build/LRX21T) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Mobile Safari/537.36', - l: 'ja', - d: 'examples.com', - tp: 'https://examples.com/foo/fuga', - pp: 'https://examples.com/hoge/muga' - } - } - }; - - const serverResponse = { - noAd: [], - noAd2: { - requestId: 'biequa9oaph4we' - }, - banner: { - requestId: 'biequa9oaph4we', - cpm: 37.66, - width: 300, - height: 250, - creativeId: 140281, - dealId: 'phoh3pad-ai4ah-xoh7x-ahk7cheasae3oh', - currency: 'USD', - netRevenue: 300, - ttl: 3000, - ad: '' - } - }; - - it('handles nobid responses', () => { - const result = spec.interpretResponse( - { body: serverResponse.noAd }, - bidRequests.banner - ); - expect(result.length).to.equal(0); - - const result2 = spec.interpretResponse( - { body: serverResponse.noAd2 }, - bidRequests.banner - ); - expect(result2.length).to.equal(0); - }) - }); - describe('spec.getUserSyncs', function () { - const syncResponse = [{ - body: { - request_id: 'biequa9oaph4we', - sync_urls: ['https://rdn1.test/sync?uid=9876543210', 'https://rdn2.test/sync?uid=9876543210'] - } - }]; - const nosyncResponse = [{ - body: { - request_id: 'biequa9oaph4we', - sync_urls: [] - } - }]; - let syncOptions - beforeEach(function () { - syncOptions = { - pixelEnabled: true - } - }); - it('sucess usersync url', function () { - const result = []; - result.push({type: 'image', url: 'https://rdn1.test/sync?uid=9876543210'}); - result.push({type: 'image', url: 'https://rdn2.test/sync?uid=9876543210'}); - expect(spec.getUserSyncs(syncOptions, syncResponse)).to.deep.equal(result); - }); - }); -}); diff --git a/test/spec/modules/raveltechRtdProvider_spec.js b/test/spec/modules/raveltechRtdProvider_spec.js deleted file mode 100644 index 051221a92..000000000 --- a/test/spec/modules/raveltechRtdProvider_spec.js +++ /dev/null @@ -1,108 +0,0 @@ -import {hook} from '../../../src/hook.js'; -import {BANNER} from '../../../src/mediaTypes.js'; -import {raveltechSubmodule} from 'modules/raveltechRtdProvider'; -import adapterManager from '../../../src/adapterManager.js'; -import {registerBidder} from 'src/adapters/bidderFactory.js'; - -describe('raveltechRtdProvider', () => { - const fakeBuildRequests = sinon.spy((valibBidRequests) => { - return { method: 'POST', data: { count: valibBidRequests.length, uids: valibBidRequests[0]?.userIdAsEids }, url: 'https://www.fakebidder.com' } - }); - - const fakeZkad = sinon.spy((id) => id.substr(0, 3)); - const fakeAjax = sinon.spy(); - - const fakeBidReq = { - adUnitCode: 'adunit', - adUnitId: '123', - auctionId: 'abc', - bidId: 'abc123', - userIdAsEids: [ - { source: 'usersource.com', uids: [ { id: 'testid123', atype: 1 } ] } - ] - }; - - before(() => { - hook.ready(); - // Setup fake bidder - const stubBidder = { - code: 'test', - supportedMediaTypes: [BANNER], - buildRequests: fakeBuildRequests, - interpretResponse: () => [], - isBidRequestValid: () => true - }; - registerBidder(stubBidder); - adapterManager.aliasBidAdapter('test', 'alias1'); - adapterManager.aliasBidAdapter('test', 'alias2'); - - // Init module - raveltechSubmodule.init({ params: { bidders: [ 'alias1', 'test' ], preserveOriginalBid: true } }); - }) - - afterEach(() => { - fakeBuildRequests.resetHistory(); - fakeZkad.resetHistory(); - fakeAjax.resetHistory(); - }) - - it('do not wrap bidder not in bidders params', () => { - adapterManager.getBidAdapter('alias2').callBids({ - auctionId: '123', - bidderCode: 'alias2', - bidderRequestId: 'abc', - bids: [ { ...fakeBidReq, bidder: 'alias2' } ] - }, sinon.stub(), sinon.stub(), fakeAjax, sinon.stub(), sinon.stub()); - expect(fakeAjax.calledOnce).to.be.true; - expect(fakeZkad.called).to.be.false; - expect(fakeBuildRequests.calledOnce).to.be.true; - expect(fakeAjax.getCall(0).args[2]).to.contain('"id":"testid123"'); - expect(fakeAjax.getCall(0).args[2]).not.to.contain('"pbjsAdapter":"test"'); - }) - - it('wrap bidder only by alias', () => { - adapterManager.getBidAdapter('alias2').callBids({ - auctionId: '123', - bidderCode: 'test', - bidderRequestId: 'abc', - bids: [ { ...fakeBidReq, bidder: 'test' } ] - }, sinon.stub(), sinon.stub(), fakeAjax, sinon.stub(), sinon.stub()); - expect(fakeAjax.calledOnce).to.be.true; - expect(fakeZkad.called).to.be.false; - expect(fakeBuildRequests.calledOnce).to.be.true; - expect(fakeAjax.getCall(0).args[2]).to.contain('"id":"testid123"'); - expect(fakeAjax.getCall(0).args[2]).not.to.contain('"pbjsAdapter":"test"'); - }) - - it('do not call ravel when ZKAD unavailable', () => { - adapterManager.getBidAdapter('alias1').callBids({ - auctionId: '123', - bidderCode: 'test', - bidderRequestId: 'abc', - bids: [ { ...fakeBidReq, bidder: 'test' } ] - }, sinon.stub(), sinon.stub(), fakeAjax, sinon.stub(), sinon.stub()); - expect(fakeAjax.calledOnce).to.be.true; - expect(fakeZkad.called).to.be.false; - expect(fakeBuildRequests.calledOnce).to.be.true; - expect(fakeAjax.getCall(0).args[2]).to.contain('"id":"testid123"'); - expect(fakeAjax.getCall(0).args[2]).not.to.contain('"pbjsAdapter":"test"'); - }) - - it('successfully replace uids with ZKAD', () => { - window.ZKAD = { anonymizeID: fakeZkad, ready: true }; - adapterManager.getBidAdapter('alias1').callBids({ - auctionId: '123', - bidderCode: 'test', - bidderRequestId: 'abc', - bids: [ { ...fakeBidReq, bidder: 'test' } ] - }, sinon.stub(), sinon.stub(), fakeAjax, sinon.stub(), sinon.stub()); - expect(fakeAjax.calledTwice).to.be.true; - expect(fakeZkad.calledOnce).to.be.true; - expect(fakeBuildRequests.calledTwice).to.be.true; - expect(fakeAjax.getCall(0).args[2]).to.contain('"id":"testid123"'); - expect(fakeAjax.getCall(1).args[2]).not.to.contain('"id":"testid123"'); - expect(fakeAjax.getCall(1).args[2]).to.contain('"id":"tes"'); - expect(fakeAjax.getCall(0).args[2]).not.to.contain('"pbjsAdapter":"test"'); - expect(fakeAjax.getCall(1).args[2]).to.contain('"pbjsAdapter":"test"'); - }) -}) diff --git a/test/spec/modules/raynRtdProvider_spec.js b/test/spec/modules/raynRtdProvider_spec.js deleted file mode 100644 index 65584c84c..000000000 --- a/test/spec/modules/raynRtdProvider_spec.js +++ /dev/null @@ -1,368 +0,0 @@ -import * as raynRTD from 'modules/raynRtdProvider.js'; -import { config } from 'src/config.js'; -import * as utils from 'src/utils.js'; - -const TEST_CHECKSUM = '-1135402174'; -const TEST_URL = 'http://localhost:9876/context.html'; -const TEST_SEGMENTS = { - [TEST_CHECKSUM]: { - 7: { - 2: ['51', '246', '652', '48', '324'] - } - } -}; - -const RTD_CONFIG = { - auctionDelay: 250, - dataProviders: [ - { - name: 'rayn', - waitForIt: true, - params: { - bidders: [], - integration: { - iabAudienceCategories: { - v1_1: { - tier: 6, - enabled: true, - }, - }, - iabContentCategories: { - v3_0: { - tier: 4, - enabled: true, - }, - v2_2: { - tier: 4, - enabled: true, - }, - }, - } - }, - }, - ], -}; - -describe('rayn RTD Submodule', function () { - let sandbox; - let getDataFromLocalStorageStub; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - config.resetConfig(); - - // reset RTD_CONFIG mutations - RTD_CONFIG.dataProviders[0].params.bidders = []; - RTD_CONFIG.dataProviders[0].params.integration = { - iabAudienceCategories: { - v1_1: { - tier: 6, - enabled: true, - }, - }, - iabContentCategories: { - v3_0: { - tier: 4, - enabled: true, - }, - v2_2: { - tier: 4, - enabled: true, - }, - }, - }; - - // reset TEST_SEGMENTS mutations - TEST_SEGMENTS[TEST_CHECKSUM] = { - 7: { - 2: ['51', '246', '652', '48', '324'] - } - }; - delete TEST_SEGMENTS['4']; - delete TEST_SEGMENTS['103015']; - delete TEST_SEGMENTS[TEST_CHECKSUM]['6']; - - getDataFromLocalStorageStub = sandbox.stub( - raynRTD.storage, - 'getDataFromLocalStorage', - ); - - sandbox.stub(raynRTD, 'generateChecksum').returns(TEST_CHECKSUM); - - delete global.window.raynJS; - }); - - afterEach(function () { - sandbox.restore(); - delete global.window.raynJS; - }); - - function expectLog(spy, message) { - // TODO: instead of testing the business logic, this suite tests - // what it logs (and the module is then forced to log its request payloads, which is just noise). - expect(spy.args.map(args => args[args.length - 1])).to.contain(message); - } - - describe('Initialize module', function () { - it('should initialize and return true', function () { - expect(raynRTD.raynSubmodule.init(RTD_CONFIG.dataProviders[0])).to.equal( - true, - ); - }); - }); - - describe('Generate ortb data object', function () { - it('should set empty segment array', function () { - expect(raynRTD.generateOrtbDataObject(7, 'invalid', 2).segment).to.be.instanceOf(Array).and.lengthOf(0); - }); - - it('should set segment array', function () { - const expectedSegmentIdsMap = TEST_SEGMENTS[TEST_CHECKSUM][7][2].map((id) => { - return { id }; - }); - expect(raynRTD.generateOrtbDataObject(7, TEST_SEGMENTS[TEST_CHECKSUM][7], 4)).to.deep.equal({ - name: raynRTD.SEGMENTS_RESOLVER, - ext: { - segtax: 7, - }, - segment: expectedSegmentIdsMap, - }); - }); - }); - - describe('Generate checksum', function () { - it('should generate checksum', function () { - expect(raynRTD.generateChecksum(TEST_URL)).to.equal(TEST_CHECKSUM); - }); - }); - - describe('Get segments', function () { - it('should get segments from local storage', function () { - getDataFromLocalStorageStub - .withArgs(raynRTD.RAYN_LOCAL_STORAGE_KEY) - .returns(JSON.stringify(TEST_SEGMENTS)); - - const segments = raynRTD.readSegments(raynRTD.RAYN_LOCAL_STORAGE_KEY); - - expect(segments).to.deep.equal(TEST_SEGMENTS); - }); - - it('should return null if unable to read and parse data from local storage', function () { - const testString = 'test'; - getDataFromLocalStorageStub - .withArgs(raynRTD.RAYN_LOCAL_STORAGE_KEY) - .returns(testString); - - const segments = raynRTD.readSegments(raynRTD.RAYN_LOCAL_STORAGE_KEY); - - expect(segments).to.equal(null); - }); - }); - - describe('Set segments as bidder ortb2', function () { - it('should set global ortb2 config', function () { - const globalOrtb2 = {}; - const bidders = RTD_CONFIG.dataProviders[0].params.bidders; - const integrationConfig = RTD_CONFIG.dataProviders[0].params.integration; - - raynRTD.setSegmentsAsBidderOrtb2({ ortb2Fragments: { global: globalOrtb2 } }, bidders, integrationConfig, TEST_SEGMENTS, TEST_CHECKSUM); - - TEST_SEGMENTS[TEST_CHECKSUM]['7']['2'].forEach((id) => { - expect(globalOrtb2.site.content.data[0].segment.find(segment => segment.id === id)).to.exist; - }) - }); - - it('should set bidder specific ortb2 config', function () { - RTD_CONFIG.dataProviders[0].params.bidders = ['appnexus']; - - const bidderOrtb2 = {}; - const bidders = RTD_CONFIG.dataProviders[0].params.bidders; - const integrationConfig = RTD_CONFIG.dataProviders[0].params.integration; - - raynRTD.setSegmentsAsBidderOrtb2({ ortb2Fragments: { bidder: bidderOrtb2 } }, bidders, integrationConfig, TEST_SEGMENTS, TEST_CHECKSUM); - - bidders.forEach((bidder) => { - const ortb2 = bidderOrtb2[bidder]; - TEST_SEGMENTS[TEST_CHECKSUM]['7']['2'].forEach((id) => { - expect(ortb2.site.content.data[0].segment.find(segment => segment.id === id)).to.exist; - }) - }); - }); - - it('should set bidder specific ortb2 config with all segments', function () { - TEST_SEGMENTS['4'] = { - 3: ['4', '17', '72', '612'] - }; - TEST_SEGMENTS[TEST_CHECKSUM]['6'] = { - 2: ['71', '313'], - 4: ['33', '145', '712'] - }; - TEST_SEGMENTS['103015'] = ['agdv23', 'avscg3']; - - const bidderOrtb2 = {}; - const bidders = RTD_CONFIG.dataProviders[0].params.bidders; - const integrationConfig = RTD_CONFIG.dataProviders[0].params.integration; - - raynRTD.setSegmentsAsBidderOrtb2({ ortb2Fragments: { bidder: bidderOrtb2 } }, bidders, integrationConfig, TEST_SEGMENTS, TEST_CHECKSUM); - - bidders.forEach((bidder) => { - const ortb2 = bidderOrtb2[bidder]; - - TEST_SEGMENTS[TEST_CHECKSUM]['6']['2'].forEach((id) => { - expect(ortb2.site.content.data[0].segment.find(segment => segment.id === id)).to.exist; - }); - TEST_SEGMENTS[TEST_CHECKSUM]['6']['4'].forEach((id) => { - expect(ortb2.site.content.data[0].segment.find(segment => segment.id === id)).to.exist; - }); - TEST_SEGMENTS[TEST_CHECKSUM]['7']['2'].forEach((id) => { - expect(ortb2.site.content.data[1].segment.find(segment => segment.id === id)).to.exist; - }); - TEST_SEGMENTS['4']['3'].forEach((id) => { - expect(ortb2.user.data[0].segment.find(segment => segment.id === id)).to.exist; - }); - TEST_SEGMENTS['103015'].forEach((id) => { - expect(ortb2.user.data[1].segment.find(segment => segment.id === id)).to.exist; - }); - }); - }); - }); - - describe('Alter Bid Requests', function () { - it('should update reqBidsConfigObj and execute callback', function () { - const callbackSpy = sinon.spy(); - const logMessageSpy = sandbox.spy(utils, 'logMessage'); - - getDataFromLocalStorageStub - .withArgs(raynRTD.RAYN_LOCAL_STORAGE_KEY) - .returns(JSON.stringify(TEST_SEGMENTS)); - - const reqBidsConfigObj = { ortb2Fragments: { bidder: {} } }; - - raynRTD.raynSubmodule.getBidRequestData(reqBidsConfigObj, callbackSpy, RTD_CONFIG); - - expect(callbackSpy.calledOnce).to.be.true; - expectLog(logMessageSpy, `Segtax data from localStorage: ${JSON.stringify(TEST_SEGMENTS)}`); - }); - - it('should update reqBidsConfigObj and execute callback using user segments from localStorage', function () { - const callbackSpy = sinon.spy(); - const logMessageSpy = sandbox.spy(utils, 'logMessage'); - const testSegments = { - 4: { - 3: ['4', '17', '72', '612'] - } - }; - - getDataFromLocalStorageStub - .withArgs(raynRTD.RAYN_LOCAL_STORAGE_KEY) - .returns(JSON.stringify(testSegments)); - - RTD_CONFIG.dataProviders[0].params.integration.iabContentCategories = { - v3_0: { - enabled: false, - }, - v2_2: { - enabled: false, - }, - }; - - const reqBidsConfigObj = { ortb2Fragments: { bidder: {} } }; - - raynRTD.raynSubmodule.getBidRequestData(reqBidsConfigObj, callbackSpy, RTD_CONFIG.dataProviders[0]); - - expect(callbackSpy.calledOnce).to.be.true; - expectLog(logMessageSpy, `Segtax data from localStorage: ${JSON.stringify(testSegments)}`) - }); - - it('should update reqBidsConfigObj and execute callback using persona segment from localStorage', function () { - const callbackSpy = sinon.spy(); - const logMessageSpy = sandbox.spy(utils, 'logMessage'); - const testSegments = { - 103015: ['agdv23', 'avscg3'] - }; - - getDataFromLocalStorageStub - .withArgs(raynRTD.RAYN_LOCAL_STORAGE_KEY) - .returns(JSON.stringify(testSegments)); - - const reqBidsConfigObj = { ortb2Fragments: { bidder: {} } }; - - raynRTD.raynSubmodule.getBidRequestData(reqBidsConfigObj, callbackSpy, RTD_CONFIG.dataProviders[0]); - - expect(callbackSpy.calledOnce).to.be.true; - expectLog(logMessageSpy, `Segtax data from localStorage: ${JSON.stringify(testSegments)}`) - }); - - it('should update reqBidsConfigObj and execute callback using segments from raynJS', function () { - const callbackSpy = sinon.spy(); - const logMessageSpy = sandbox.spy(utils, 'logMessage'); - - getDataFromLocalStorageStub - .withArgs(raynRTD.RAYN_LOCAL_STORAGE_KEY) - .returns(null); - - const reqBidsConfigObj = { ortb2Fragments: { bidder: {} } }; - - raynRTD.raynSubmodule.getBidRequestData(reqBidsConfigObj, callbackSpy, RTD_CONFIG.dataProviders[0]); - - expect(callbackSpy.calledOnce).to.be.true; - expectLog(logMessageSpy, `No segtax data`) - }); - - it('should update reqBidsConfigObj and execute callback using audience from localStorage', function (done) { - const callbackSpy = sinon.spy(); - const logMessageSpy = sandbox.spy(utils, 'logMessage'); - const testSegments = { - 6: { - 4: ['3', '27', '177'] - } - }; - - global.window.raynJS = { - getSegtax: function () { - return Promise.resolve(testSegments); - } - }; - - getDataFromLocalStorageStub - .withArgs(raynRTD.RAYN_LOCAL_STORAGE_KEY) - .returns(null); - - const reqBidsConfigObj = { ortb2Fragments: { bidder: {} } }; - - raynRTD.raynSubmodule.getBidRequestData(reqBidsConfigObj, callbackSpy, RTD_CONFIG.dataProviders[0]); - - setTimeout(() => { - expect(callbackSpy.calledOnce).to.be.true; - expectLog(logMessageSpy, `Segtax data from RaynJS: ${JSON.stringify(testSegments)}`) - done(); - }, 0) - }); - - it('should execute callback if log error', function (done) { - const callbackSpy = sinon.spy(); - const logErrorSpy = sandbox.spy(utils, 'logError'); - const rejectError = 'Error'; - - global.window.raynJS = { - getSegtax: function () { - return Promise.reject(rejectError); - } - }; - - getDataFromLocalStorageStub - .withArgs(raynRTD.RAYN_LOCAL_STORAGE_KEY) - .returns(null); - - const reqBidsConfigObj = { ortb2Fragments: { bidder: {} } }; - - raynRTD.raynSubmodule.getBidRequestData(reqBidsConfigObj, callbackSpy, RTD_CONFIG.dataProviders[0]); - - setTimeout(() => { - expect(callbackSpy.calledOnce).to.be.true; - expectLog(logErrorSpy, rejectError); - done(); - }, 0) - }); - }); -}); diff --git a/test/spec/modules/readpeakBidAdapter_spec.js b/test/spec/modules/readpeakBidAdapter_spec.js deleted file mode 100644 index 32a4d9910..000000000 --- a/test/spec/modules/readpeakBidAdapter_spec.js +++ /dev/null @@ -1,539 +0,0 @@ -import { expect } from 'chai'; -import { spec, ENDPOINT } from 'modules/readpeakBidAdapter.js'; -import { config } from 'src/config.js'; -import { parseUrl } from 'src/utils.js'; - -describe('ReadPeakAdapter', function() { - let baseBidRequest; - let bannerBidRequest; - let nativeBidRequest; - let nativeServerResponse; - let nativeServerRequest; - let bannerServerResponse; - let bannerServerRequest; - let bidderRequest; - - beforeEach(function() { - bidderRequest = { - refererInfo: { - page: 'https://publisher.com/home', - domain: 'publisher.com' - } - }; - - baseBidRequest = { - bidder: 'readpeak', - params: { - bidfloor: 5.0, - publisherId: '11bc5dd5-7421-4dd8-c926-40fa653bec76', - siteId: '11bc5dd5-7421-4dd8-c926-40fa653bec77', - tagId: 'test-tag-1' - }, - bidId: '2ffb201a808da7', - bidderRequestId: '178e34bad3658f', - auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', - transactionId: 'd45dd707-a418-42ec-b8a7-b70a6c6fab0b', - }; - - nativeBidRequest = { - ...baseBidRequest, - nativeParams: { - title: { required: true, len: 200 }, - image: { wmin: 100 }, - sponsoredBy: {}, - body: { required: false }, - cta: { required: false } - }, - mediaTypes: { - native: { - title: { required: true, len: 200 }, - image: { wmin: 100 }, - sponsoredBy: {}, - body: { required: false }, - cta: { required: false } - }, - } - }; - bannerBidRequest = { - ...baseBidRequest, - mediaTypes: { - banner: { - sizes: [[640, 320], [300, 600]], - } - }, - sizes: [[640, 320], [300, 600]], - } - nativeServerResponse = { - id: baseBidRequest.bidderRequestId, - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: 'baseBidRequest.bidId', - impid: baseBidRequest.bidId, - price: 0.12, - cid: '12', - crid: '123', - adomain: ['readpeak.com'], - adm: { - assets: [ - { - id: 1, - title: { - text: 'Title' - } - }, - { - id: 3, - data: { - type: 1, - value: 'Brand Name' - } - }, - { - id: 4, - data: { - type: 2, - value: 'Description' - } - }, - { - id: 2, - img: { - type: 3, - url: 'http://url.to/image', - w: 750, - h: 500 - } - } - ], - link: { - url: 'http://url.to/target' - }, - imptrackers: ['http://url.to/pixeltracker'] - } - } - ] - } - ] - }; - bannerServerResponse = { - id: baseBidRequest.bidderRequestId, - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: 'baseBidRequest.bidId', - impid: baseBidRequest.bidId, - price: 0.12, - cid: '12', - crid: '123', - adomain: ['readpeak.com'], - adm: '', - burl: 'https://localhost:8081/url/b?d=0O95O4326I528Ie4d39f94-533d-4577-a579-585fd4c02b0aI0I352e303232363639333139393939393939&c=USD&p=${AUCTION_PRICE}&bad=0-0-95O0O0OdO640360&gc=0', - nurl: 'https://localhost:8081/url/n?d=0O95O4326I528Ie4d39f94-533d-4577-a579-585fd4c02b0aI0I352e303232363639333139393939393939&gc=0', - w: 640, - h: 360, - } - ] - } - ] - }; - nativeServerRequest = { - method: 'POST', - url: 'http://localhost:60080/header/prebid', - data: JSON.stringify({ - id: '178e34bad3658f', - imp: [ - { - id: '2ffb201a808da7', - native: { - request: - '{\"assets\":[{\"id\":1,\"required\":1,\"title\":{\"len\":70}},{\"id\":2,\"required\":1,\"img\":{\"type\":3,\"wmin\":150,\"hmin\":150}},{\"id\":4,\"required\":1,\"data\":{\"type\":2,\"len\":120}}]}', - ver: '1.1' - }, - bidfloor: 5, - bidfloorcur: 'USD', - tagId: 'test-tag-1' - } - ], - site: { - publisher: { - id: '11bc5dd5-7421-4dd8-c926-40fa653bec76' - }, - id: '11bc5dd5-7421-4dd8-c926-40fa653bec77', - ref: '', - page: 'http://localhost', - domain: 'localhost' - }, - app: null, - device: { - ua: - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/61.0.3163.100 Safari/537.36', - language: 'en-US' - }, - isPrebid: true - }) - }; - bannerServerRequest = { - method: 'POST', - url: 'http://localhost:60080/header/prebid', - data: JSON.stringify({ - id: '178e34bad3658f', - imp: [ - { - id: '2ffb201a808da7', - bidfloor: 5, - bidfloorcur: 'USD', - tagId: 'test-tag-1', - banner: { - w: 640, - h: 360, - format: [ - { w: 640, h: 360 }, - { w: 320, h: 320 }, - ] - } - } - ], - site: { - publisher: { - id: '11bc5dd5-7421-4dd8-c926-40fa653bec76' - }, - id: '11bc5dd5-7421-4dd8-c926-40fa653bec77', - ref: '', - page: 'http://localhost', - domain: 'localhost' - }, - app: null, - device: { - ua: - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) HeadlessChrome/61.0.3163.100 Safari/537.36', - language: 'en-US' - }, - isPrebid: true - }) - }; - }); - - describe('Native', function() { - describe('spec.isBidRequestValid', function() { - it('should return true when the required params are passed', function() { - expect(spec.isBidRequestValid(nativeBidRequest)).to.equal(true); - }); - - it('should return false when the "publisherId" param is missing', function() { - nativeBidRequest.params = { - bidfloor: 5.0 - }; - expect(spec.isBidRequestValid(nativeBidRequest)).to.equal(false); - }); - - it('should return false when no bid params are passed', function() { - nativeBidRequest.params = {}; - expect(spec.isBidRequestValid(nativeBidRequest)).to.equal(false); - }); - - it('should return false when a bid request is not passed', function() { - expect(spec.isBidRequestValid()).to.equal(false); - expect(spec.isBidRequestValid({})).to.equal(false); - }); - }); - - describe('spec.buildRequests', function() { - it('should create a POST request for every bid', function() { - const request = spec.buildRequests([nativeBidRequest], bidderRequest); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal(ENDPOINT); - }); - - it('should attach request data', function() { - config.setConfig({ - currency: { - adServerCurrency: 'EUR' - } - }); - - const request = spec.buildRequests([nativeBidRequest], bidderRequest); - - const data = JSON.parse(request.data); - - expect(data.source.ext.prebid).to.equal('$prebid.version$'); - expect(data.id).to.equal(nativeBidRequest.bidderRequestId); - expect(data.imp[0].bidfloor).to.equal(nativeBidRequest.params.bidfloor); - expect(data.imp[0].bidfloorcur).to.equal('USD'); - expect(data.imp[0].tagId).to.equal('test-tag-1'); - expect(data.site.publisher.id).to.equal(nativeBidRequest.params.publisherId); - expect(data.site.id).to.equal(nativeBidRequest.params.siteId); - expect(data.site.page).to.equal(bidderRequest.refererInfo.page); - expect(data.site.domain).to.equal(bidderRequest.refererInfo.domain); - expect(data.device).to.deep.contain({ - ua: navigator.userAgent, - language: navigator.language - }); - expect(data.cur).to.deep.equal(['EUR']); - expect(data.user).to.be.undefined; - expect(data.regs).to.be.undefined; - }); - - it('should get bid floor from module', function() { - const floorModuleData = { - currency: 'USD', - floor: 3.2, - } - nativeBidRequest.getFloor = function () { - return floorModuleData - } - const request = spec.buildRequests([nativeBidRequest], bidderRequest); - - const data = JSON.parse(request.data); - - expect(data.source.ext.prebid).to.equal('$prebid.version$'); - expect(data.id).to.equal(nativeBidRequest.bidderRequestId); - expect(data.imp[0].bidfloor).to.equal(floorModuleData.floor); - expect(data.imp[0].bidfloorcur).to.equal(floorModuleData.currency); - }); - - it('should send gdpr data when gdpr does not apply', function() { - const gdprData = { - gdprConsent: { - gdprApplies: false, - consentString: undefined, - } - } - const request = spec.buildRequests([nativeBidRequest], {...bidderRequest, ...gdprData}); - - const data = JSON.parse(request.data); - - expect(data.user).to.deep.equal({ - ext: { - consent: '' - } - }); - expect(data.regs).to.deep.equal({ - ext: { - gdpr: false - } - }); - }); - - it('should send gdpr data when gdpr applies', function() { - const tcString = 'sometcstring'; - const gdprData = { - gdprConsent: { - gdprApplies: true, - consentString: tcString - } - } - const request = spec.buildRequests([nativeBidRequest], {...bidderRequest, ...gdprData}); - - const data = JSON.parse(request.data); - - expect(data.user).to.deep.equal({ - ext: { - consent: tcString - } - }); - expect(data.regs).to.deep.equal({ - ext: { - gdpr: true - } - }); - }); - }); - - describe('spec.interpretResponse', function() { - it('should return no bids if the response is not valid', function() { - const bidResponse = spec.interpretResponse({ body: null }, nativeServerRequest); - expect(bidResponse.length).to.equal(0); - }); - - it('should return a valid bid response', function() { - const bidResponse = spec.interpretResponse( - { body: nativeServerResponse }, - nativeServerRequest - )[0]; - expect(bidResponse).to.contain({ - requestId: nativeBidRequest.bidId, - cpm: nativeServerResponse.seatbid[0].bid[0].price, - creativeId: nativeServerResponse.seatbid[0].bid[0].crid, - ttl: 300, - netRevenue: true, - mediaType: 'native', - currency: nativeServerResponse.cur - }); - - expect(bidResponse.meta).to.deep.equal({ - advertiserDomains: ['readpeak.com'], - }) - expect(bidResponse.native.title).to.equal('Title'); - expect(bidResponse.native.body).to.equal('Description'); - expect(bidResponse.native.image).to.deep.equal({ - url: 'http://url.to/image', - width: 750, - height: 500 - }); - expect(bidResponse.native.clickUrl).to.equal( - 'http://url.to/target' - ); - expect(bidResponse.native.impressionTrackers).to.contain( - 'http://url.to/pixeltracker' - ); - }); - }); - }); - - describe('Banner', function() { - describe('spec.isBidRequestValid', function() { - it('should return true when the required params are passed', function() { - expect(spec.isBidRequestValid(bannerBidRequest)).to.equal(true); - }); - - it('should return false when the "publisherId" param is missing', function() { - bannerBidRequest.params = { - bidfloor: 5.0 - }; - expect(spec.isBidRequestValid(bannerBidRequest)).to.equal(false); - }); - - it('should return false when no bid params are passed', function() { - bannerBidRequest.params = {}; - expect(spec.isBidRequestValid(bannerBidRequest)).to.equal(false); - }); - }); - - describe('spec.buildRequests', function() { - it('should create a POST request for every bid', function() { - const request = spec.buildRequests([bannerBidRequest], bidderRequest); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal(ENDPOINT); - }); - - it('should attach request data', function() { - config.setConfig({ - currency: { - adServerCurrency: 'EUR' - } - }); - - const request = spec.buildRequests([bannerBidRequest], bidderRequest); - - const data = JSON.parse(request.data); - - expect(data.source.ext.prebid).to.equal('$prebid.version$'); - expect(data.id).to.equal(bannerBidRequest.bidderRequestId); - expect(data.imp[0].bidfloor).to.equal(bannerBidRequest.params.bidfloor); - expect(data.imp[0].bidfloorcur).to.equal('USD'); - expect(data.imp[0].tagId).to.equal('test-tag-1'); - expect(data.site.publisher.id).to.equal(bannerBidRequest.params.publisherId); - expect(data.site.id).to.equal(bannerBidRequest.params.siteId); - expect(data.site.page).to.equal(bidderRequest.refererInfo.page); - expect(data.site.domain).to.equal(bidderRequest.refererInfo.domain); - expect(data.device).to.deep.contain({ - ua: navigator.userAgent, - language: navigator.language - }); - expect(data.cur).to.deep.equal(['EUR']); - expect(data.user).to.be.undefined; - expect(data.regs).to.be.undefined; - }); - - it('should get bid floor from module', function() { - const floorModuleData = { - currency: 'USD', - floor: 3.2, - } - bannerBidRequest.getFloor = function () { - return floorModuleData - } - const request = spec.buildRequests([bannerBidRequest], bidderRequest); - - const data = JSON.parse(request.data); - - expect(data.source.ext.prebid).to.equal('$prebid.version$'); - expect(data.id).to.equal(bannerBidRequest.bidderRequestId); - expect(data.imp[0].bidfloor).to.equal(floorModuleData.floor); - expect(data.imp[0].bidfloorcur).to.equal(floorModuleData.currency); - }); - - it('should send gdpr data when gdpr does not apply', function() { - const gdprData = { - gdprConsent: { - gdprApplies: false, - consentString: undefined, - } - } - const request = spec.buildRequests([bannerBidRequest], {...bidderRequest, ...gdprData}); - - const data = JSON.parse(request.data); - - expect(data.user).to.deep.equal({ - ext: { - consent: '' - } - }); - expect(data.regs).to.deep.equal({ - ext: { - gdpr: false - } - }); - }); - - it('should send gdpr data when gdpr applies', function() { - const tcString = 'sometcstring'; - const gdprData = { - gdprConsent: { - gdprApplies: true, - consentString: tcString - } - } - const request = spec.buildRequests([bannerBidRequest], {...bidderRequest, ...gdprData}); - - const data = JSON.parse(request.data); - - expect(data.user).to.deep.equal({ - ext: { - consent: tcString - } - }); - expect(data.regs).to.deep.equal({ - ext: { - gdpr: true - } - }); - }); - }); - - describe('spec.interpretResponse', function() { - it('should return no bids if the response is not valid', function() { - const bidResponse = spec.interpretResponse({ body: null }, bannerServerRequest); - expect(bidResponse.length).to.equal(0); - }); - - it('should return a valid bid response', function() { - const bidResponse = spec.interpretResponse( - { body: bannerServerResponse }, - bannerServerRequest - )[0]; - expect(bidResponse).to.contain({ - requestId: bannerBidRequest.bidId, - cpm: bannerServerResponse.seatbid[0].bid[0].price, - creativeId: bannerServerResponse.seatbid[0].bid[0].crid, - ttl: 300, - netRevenue: true, - mediaType: 'banner', - currency: bannerServerResponse.cur, - ad: bannerServerResponse.seatbid[0].bid[0].adm, - width: bannerServerResponse.seatbid[0].bid[0].w, - height: bannerServerResponse.seatbid[0].bid[0].h, - burl: bannerServerResponse.seatbid[0].bid[0].burl, - }); - expect(bidResponse.meta).to.deep.equal({ - advertiserDomains: ['readpeak.com'], - }); - }); - }); - }); -}); diff --git a/test/spec/modules/reconciliationRtdProvider_spec.js b/test/spec/modules/reconciliationRtdProvider_spec.js deleted file mode 100644 index 6efe55ddf..000000000 --- a/test/spec/modules/reconciliationRtdProvider_spec.js +++ /dev/null @@ -1,221 +0,0 @@ -import { - reconciliationSubmodule, - track, - getTopIFrameWin, - getSlotByWin -} from 'modules/reconciliationRtdProvider.js'; -import { makeSlot } from '../integration/faker/googletag.js'; -import * as utils from 'src/utils.js'; - -describe('Reconciliation Real time data submodule', function () { - const conf = { - dataProviders: [{ - 'name': 'reconciliation', - 'params': { - 'publisherMemberId': 'test_prebid_publisher' - }, - }] - }; - - let trackPostStub; - - beforeEach(function () { - trackPostStub = sinon.stub(track, 'trackPost'); - }); - - afterEach(function () { - trackPostStub.restore(); - }); - - describe('reconciliationSubmodule', function () { - describe('initialization', function () { - let utilsLogErrorSpy; - - before(function () { - utilsLogErrorSpy = sinon.spy(utils, 'logError'); - }); - - after(function () { - utils.logError.restore(); - }); - - it('successfully instantiates', function () { - expect(reconciliationSubmodule.init(conf.dataProviders[0])).to.equal(true); - }); - - it('should log error if initializied without parameters', function () { - expect(reconciliationSubmodule.init({'name': 'reconciliation', 'params': {}})).to.equal(true); - expect(utilsLogErrorSpy.calledOnce).to.be.true; - }); - }); - - describe('getData', function () { - it('should return data in proper format', function () { - makeSlot({code: '/reconciliationAdunit1', divId: 'reconciliationAd1'}); - - const targetingData = reconciliationSubmodule.getTargetingData(['/reconciliationAdunit1']); - expect(targetingData['/reconciliationAdunit1'].RSDK_AUID).to.eql('/reconciliationAdunit1'); - expect(targetingData['/reconciliationAdunit1'].RSDK_ADID).to.be.a('string'); - }); - - it('should return unit path if called with divId', function () { - makeSlot({code: '/reconciliationAdunit2', divId: 'reconciliationAd2'}); - - const targetingData = reconciliationSubmodule.getTargetingData(['reconciliationAd2']); - expect(targetingData['reconciliationAd2'].RSDK_AUID).to.eql('/reconciliationAdunit2'); - expect(targetingData['reconciliationAd2'].RSDK_ADID).to.be.a('string'); - }); - - it('should skip empty adUnit id', function () { - makeSlot({code: '/reconciliationAdunit3', divId: 'reconciliationAd3'}); - - const targetingData = reconciliationSubmodule.getTargetingData(['reconciliationAd3', '']); - expect(targetingData).to.have.all.keys('reconciliationAd3'); - }); - }); - - describe('track events', function () { - it('should track init event with data', function () { - const adUnit = { - code: '/adunit' - }; - - reconciliationSubmodule.getTargetingData([adUnit.code]); - - expect(trackPostStub.calledOnce).to.be.true; - expect(trackPostStub.getCalls()[0].args[0]).to.eql('https://confirm.fiduciadlt.com/init'); - expect(trackPostStub.getCalls()[0].args[1].adUnits[0].adUnitId).to.eql(adUnit.code); - expect(trackPostStub.getCalls()[0].args[1].adUnits[0].adDeliveryId).be.a('string'); - expect(trackPostStub.getCalls()[0].args[1].publisherMemberId).to.eql('test_prebid_publisher'); - }); - }); - - describe('get topmost iframe', function () { - /** - * - top - * -- iframe.window <-- top iframe window - * --- iframe.window - * ---- iframe.window <-- win - */ - const mockFrameWin = (topWin, parentWin) => { - return { - top: topWin, - parent: parentWin - } - } - - it('should return null if called with null', function() { - expect(getTopIFrameWin(null)).to.be.null; - }); - - it('should return null if there is an error in frames chain', function() { - const topWin = {}; - const iframe1Win = mockFrameWin(topWin, null); // break chain - const iframe2Win = mockFrameWin(topWin, iframe1Win); - - expect(getTopIFrameWin(iframe1Win, topWin)).to.be.null; - }); - - it('should get the topmost iframe', function () { - const topWin = {}; - const iframe1Win = mockFrameWin(topWin, topWin); - const iframe2Win = mockFrameWin(topWin, iframe1Win); - - expect(getTopIFrameWin(iframe2Win, topWin)).to.eql(iframe1Win); - }); - }); - - describe('get slot by nested iframe window', function () { - it('should return the slot', function () { - const adSlotElement = document.createElement('div'); - const adSlotIframe = document.createElement('iframe'); - - adSlotElement.id = 'reconciliationAd'; - adSlotElement.appendChild(adSlotIframe); - document.body.appendChild(adSlotElement); - - const adSlot = makeSlot({code: '/reconciliationAdunit', divId: adSlotElement.id}); - - expect(getSlotByWin(adSlotIframe.contentWindow)).to.eql(adSlot); - }); - - it('should return null if the slot is not found', function () { - const adSlotElement = document.createElement('div'); - const adSlotIframe = document.createElement('iframe'); - - adSlotElement.id = 'reconciliationAd'; - document.body.appendChild(adSlotElement); - document.body.appendChild(adSlotIframe); // iframe is not in ad slot - - const adSlot = makeSlot({code: '/reconciliationAdunit', divId: adSlotElement.id}); - - expect(getSlotByWin(adSlotIframe.contentWindow)).to.be.null; - }); - }); - - describe('handle postMessage from Reconciliation Tag in ad iframe', function () { - it('should track impression pixel with parameters', function (done) { - const adSlotElement = document.createElement('div'); - const adSlotIframe = document.createElement('iframe'); - - adSlotElement.id = 'reconciliationAdMessage'; - adSlotElement.appendChild(adSlotIframe); - document.body.appendChild(adSlotElement); - - const adSlot = makeSlot({code: '/reconciliationAdunit', divId: adSlotElement.id}); - // Fix targeting methods - adSlot.targeting = {}; - adSlot.setTargeting = function(key, value) { - this.targeting[key] = [value]; - }; - adSlot.getTargeting = function(key) { - return this.targeting[key]; - }; - - adSlot.setTargeting('RSDK_AUID', '/reconciliationAdunit'); - adSlot.setTargeting('RSDK_ADID', '12345'); - adSlotIframe.contentDocument.open(); - adSlotIframe.contentDocument.write(``); - adSlotIframe.contentDocument.close(); - - setTimeout(() => { - expect(trackPostStub.calledOnce).to.be.true; - expect(trackPostStub.getCalls()[0].args[0]).to.eql('https://confirm.fiduciadlt.com/pimp'); - expect(trackPostStub.getCalls()[0].args[1].adUnitId).to.eql('/reconciliationAdunit'); - expect(trackPostStub.getCalls()[0].args[1].adDeliveryId).to.eql('12345'); - expect(trackPostStub.getCalls()[0].args[1].tagOwnerMemberId).to.eql('test_member_id'); ; - expect(trackPostStub.getCalls()[0].args[1].dataSources.length).to.eql(1); - expect(trackPostStub.getCalls()[0].args[1].dataRecipients.length).to.eql(2); - expect(trackPostStub.getCalls()[0].args[1].publisherMemberId).to.eql('test_prebid_publisher'); - done(); - }, 100); - }); - }); - }); -}); diff --git a/test/spec/modules/rediadsBidAdapter_spec.js b/test/spec/modules/rediadsBidAdapter_spec.js deleted file mode 100644 index a47817d73..000000000 --- a/test/spec/modules/rediadsBidAdapter_spec.js +++ /dev/null @@ -1,144 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/rediadsBidAdapter.js'; - -describe('rediads Bid Adapter', function () { - const BIDDER_CODE = 'rediads'; - const STAGING_ENDPOINT_URL = - 'https://stagingbidding.rediads.com/openrtb2/auction'; - - const bidRequest = { - bidder: BIDDER_CODE, - params: { - account_id: '12345', - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [728, 90], - ], - }, - }, - adUnitCode: 'adunit-code', - bidId: '2ab03f1234', - auctionId: '123456789', - }; - - const bidderRequest = { - bidderCode: BIDDER_CODE, - refererInfo: { - referer: 'http://example.com', - }, - }; - - const resetHash = (originalHash) => { - // Reset the hash, ensuring no trailing # - if (originalHash) { - location.hash = originalHash; - } else { - history.replaceState(null, '', location.pathname + location.search); - } - }; - - describe('isBidRequestValid', function () { - it('should return true for valid bid requests', function () { - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false if account_id is missing', function () { - const invalidBid = { ...bidRequest, params: {} }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('should build a valid request with correct data', function () { - const requests = spec.buildRequests([bidRequest], bidderRequest); - expect(requests).to.be.an('array').that.is.not.empty; - - const request = requests[0]; - expect(request.method).to.equal('POST'); - expect(request.url).that.is.not.empty; - - const sitePublisherId = request?.data?.site?.publisher?.id; - const appPublisherId = request?.data?.app?.publisher?.id; - const accountId = request?.data?.ext?.rediads?.params?.account_id; - expect(sitePublisherId || appPublisherId || accountId).to.be.ok; - }); - - it('should include test flag if testBidsRequested is true', function () { - const originalHash = location.hash; - location.hash = '#rediads-test-bids'; - - const requests = spec.buildRequests([bidRequest], bidderRequest); - expect(requests[0].data.test).to.equal(1); - - resetHash(originalHash); - }); - - it('should set staging environtment if stagingEnvRequested is true', function () { - const originalHash = location.hash; - location.hash = '#rediads-staging'; - - const requests = spec.buildRequests([bidRequest], bidderRequest); - expect(requests[0].url).to.equal(STAGING_ENDPOINT_URL); - - resetHash(originalHash); - }); - }); - - describe('interpretResponse', function () { - it('should interpret and return valid bid responses for banner bid', function () { - const serverResponse = { - body: { - seatbid: [ - { - bid: [ - { - price: 1.23, - impid: '2ab03f1234', - adm: '
Ad
', - crid: 'creative123', - w: 123, - h: 321, - }, - ], - }, - ], - }, - }; - const requestObj = spec.buildRequests([bidRequest], bidderRequest); - const bids = spec.interpretResponse(serverResponse, requestObj[0]); - expect(bids).to.be.an('array').that.is.not.empty; - - const bid = bids[0]; - expect(bid).to.include({ - requestId: '2ab03f1234', - cpm: 1.23, - creativeId: 'creative123', - width: 123, - height: 321, - ad: '
Ad
', - }); - expect(bid.mediaType).to.equal('banner'); - }); - - it('should return an empty array for invalid responses', function () { - const invalidResponse = { body: {} }; - const updatedBidRequest = { ...bidRequest, params: undefined }; - const requestObj = spec.buildRequests([updatedBidRequest], bidderRequest); - const bids = spec.interpretResponse(invalidResponse, requestObj[0]); - expect(bids).to.be.an('array').that.is.empty; - }); - }); - - describe('Miscellaneous', function () { - it('should support multiple media types', function () { - expect(spec.supportedMediaTypes).to.include.members([ - 'banner', - 'native', - 'video', - ]); - }); - }); -}); diff --git a/test/spec/modules/redtramBidAdapter_spec.js b/test/spec/modules/redtramBidAdapter_spec.js deleted file mode 100644 index 45d2b08a5..000000000 --- a/test/spec/modules/redtramBidAdapter_spec.js +++ /dev/null @@ -1,256 +0,0 @@ -import {expect} from 'chai'; -import {spec} from '../../../modules/redtramBidAdapter.js'; -import { BANNER } from '../../../src/mediaTypes.js'; -import * as utils from '../../../src/utils.js'; - -describe('RedtramBidAdapter', function () { - const bid = { - bidId: '23dc19818e5293', - bidder: 'redtram', - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - placementId: 23611, - } - }; - - const bidderRequest = { - refererInfo: { - referer: 'test.com' - } - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - delete bid.params.placementId; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests([bid], bidderRequest); - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal('https://prebid.redtram.com/pbjs'); - }); - it('Returns valid data if array of bids is valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'language', 'host', 'page', 'placements'); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.gdpr).to.not.exist; - expect(data.ccpa).to.not.exist; - const placement = data['placements'][0]; - expect(placement).to.have.keys('placementId', 'bidId', 'adFormat', 'sizes', 'schain', 'bidfloor'); - expect(placement.placementId).to.equal(23611); - expect(placement.bidId).to.equal('23dc19818e5293'); - expect(placement.adFormat).to.equal(BANNER); - expect(placement.schain).to.be.an('object'); - expect(placement.sizes).to.be.an('array'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - bidderRequest.gdprConsent = 'test'; - serverRequest = spec.buildRequests([bid], bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('string'); - expect(data.gdpr).to.equal(bidderRequest.gdprConsent); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = 'test'; - serverRequest = spec.buildRequests([bid], bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - - it('Returns empty data if no valid requests are passed', function () { - serverRequest = spec.buildRequests([]); - const data = serverRequest.data; - expect(data.placements).to.be.an('array').that.is.empty; - }); - }); - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23dc19818e5293', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: {} - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23dc19818e5293'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.width).to.equal(300); - expect(dataItem.height).to.equal(250); - expect(dataItem.ad).to.equal('Test'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23dc19818e5293', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function () { - it('should do nothing on getUserSyncs', function () { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://prebid.redtram.com/sync/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0') - }); - }); - - describe('on bidWon', function () { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - it('should replace nurl for banner', function () { - const nurl = 'nurl/?ap=${' + 'AUCTION_PRICE}'; - const bid = { - 'bidderCode': 'redtram', - 'width': 300, - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '5691dd18ba6ab6', - 'requestId': '23dc19818e5293', - 'transactionId': '948c716b-bf64-4303-bcf4-395c2f6a9770', - 'auctionId': 'a6b7c61f-15a9-481b-8f64-e859787e9c07', - 'mediaType': 'banner', - 'source': 'client', - 'ad': "
\n", - 'cpm': 0.68, - 'nurl': nurl, - 'creativeId': 'test', - 'currency': 'USD', - 'dealId': '', - 'meta': { - 'advertiserDomains': [], - 'dchain': { - 'ver': '1.0', - 'complete': 0, - 'nodes': [ - { - 'name': 'redtram' - } - ] - } - }, - 'netRevenue': true, - 'ttl': 120, - 'metrics': {}, - 'adapterCode': 'redtram', - 'originalCpm': 0.68, - 'originalCurrency': 'USD', - 'responseTimestamp': 1668162732297, - 'requestTimestamp': 1668162732292, - 'bidder': 'redtram', - 'adUnitCode': 'div-prebid', - 'timeToRespond': 5, - 'pbLg': '0.50', - 'pbMg': '0.60', - 'pbHg': '0.68', - 'pbAg': '0.65', - 'pbDg': '0.68', - 'pbCg': '', - 'size': '300x250', - 'adserverTargeting': { - 'hb_bidder': 'redtram', - 'hb_adid': '5691dd18ba6ab6', - 'hb_pb': '0.68', - 'hb_size': '300x250', - 'hb_source': 'client', - 'hb_format': 'banner', - 'hb_adomain': '' - }, - 'status': 'rendered', - 'params': [ - { - 'placementId': 23611 - } - ] - }; - spec.onBidWon(bid); - expect(bid.nurl).to.deep.equal('nurl/?ap=0.68'); - }); - }); -}); diff --git a/test/spec/modules/relaidoBidAdapter_spec.js b/test/spec/modules/relaidoBidAdapter_spec.js deleted file mode 100644 index da3584a2d..000000000 --- a/test/spec/modules/relaidoBidAdapter_spec.js +++ /dev/null @@ -1,584 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/relaidoBidAdapter.js'; -import * as utils from 'src/utils.js'; -import {VIDEO} from 'src/mediaTypes.js'; -import {getCoreStorageManager} from '../../../src/storageManager.js'; -import * as mockGpt from '../integration/faker/googletag.js'; - -const UUID_KEY = 'relaido_uuid'; -const relaido_uuid = 'hogehoge'; - -describe('RelaidoAdapter', function () { - let bidRequest; - let bidderRequest; - let serverResponse; - let serverResponseBanner; - let serverRequest; - let generateUUIDStub; - let triggerPixelStub; - let sandbox; - - before(() => { - const storage = getCoreStorageManager(); - storage.setCookie(UUID_KEY, relaido_uuid); - }); - - beforeEach(function () { - mockGpt.disable(); - generateUUIDStub = sinon.stub(utils, 'generateUUID').returns(relaido_uuid); - triggerPixelStub = sinon.stub(utils, 'triggerPixel'); - sandbox = sinon.createSandbox(); - bidRequest = { - bidder: 'relaido', - params: { - placementId: '100000', - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [ - [640, 360] - ] - } - }, - adUnitCode: 'test', - bidId: '2ed93003f7bb99', - bidderRequestId: '1c50443387a1f2', - auctionId: '413ed000-8c7a-4ba1-a1fa-9732e006f8c3', - ortb2Imp: { - ext: { - tid: '5c2d064c-7b76-42e8-a383-983603afdc45', - } - }, - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }; - bidderRequest = { - timeout: 1000, - refererInfo: { - page: 'https://publisher.com/home?aaa=test1&bbb=test2', - canonicalUrl: 'https://publisher.com/home' - } - }; - serverResponse = { - body: { - status: 'ok', - ads: [{ - placementId: 100000, - width: 640, - height: 360, - bidId: '2ed93003f7bb99', - price: 500, - model: 'vcpm', - currency: 'JPY', - creativeId: 1000, - vast: '', - syncUrl: 'https://relaido/sync.html', - adomain: ['relaido.co.jp', 'www.cmertv.co.jp'], - mediaType: 'video' - }], - playerUrl: 'https://relaido/player.js', - syncUrl: 'https://api-dev.ulizaex.com/tr/v1/prebid/sync.html', - uuid: relaido_uuid, - } - }; - serverResponseBanner = { - body: { - status: 'ok', - ads: [{ - placementId: 100000, - width: 640, - height: 360, - bidId: '2ed93003f7bb99', - price: 500, - model: 'vcpm', - currency: 'JPY', - creativeId: 1000, - adTag: '%3Cdiv%3E%3Cimg%20src%3D%22https%3A%2F%2Frelaido%2Ftest.jpg%22%20%2F%3E%3C%2Fdiv%3E', - syncUrl: 'https://relaido/sync.html', - adomain: ['relaido.co.jp', 'www.cmertv.co.jp'], - mediaType: 'banner' - }], - syncUrl: 'https://api-dev.ulizaex.com/tr/v1/prebid/sync.html', - uuid: relaido_uuid, - } - }; - serverRequest = { - method: 'POST', - data: { - bids: [{ - bidId: bidRequest.bidId, - width: bidRequest.mediaTypes.video.playerSize[0][0] || bidRequest.mediaTypes.video.playerSize[0], - height: bidRequest.mediaTypes.video.playerSize[0][1] || bidRequest.mediaTypes.video.playerSize[1], - mediaType: 'video' - }] - } - }; - window.RelaidoPlayer = { - renderAd: function() { - return null; - } - }; - }); - - afterEach(() => { - generateUUIDStub.restore(); - triggerPixelStub.restore(); - sandbox.restore(); - }); - - describe('spec.isBidRequestValid', function () { - it('should return true when the required params are passed by video', function () { - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true when not existed mediaTypes.video.playerSize and existed valid params.video.playerSize by video', function () { - bidRequest.mediaTypes = { - video: { - context: 'outstream' - } - }; - bidRequest.params = { - placementId: '100000', - video: { - playerSize: [ - [640, 360] - ] - } - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return even true when the playerSize is Array[Number, Number] by video', function () { - bidRequest.mediaTypes = { - video: { - context: 'outstream', - playerSize: [640, 360] - } - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true when the required params are passed by banner', function () { - bidRequest.mediaTypes = { - banner: { - sizes: [ - [300, 250] - ] - } - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false when missing 300x250 over and 1x1 by banner', function () { - bidRequest.mediaTypes = { - banner: { - sizes: [ - [100, 100], - [300, 100] - ] - } - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return true when 300x250 by banner', function () { - bidRequest.mediaTypes = { - banner: { - sizes: [ - [300, 250] - ] - } - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true when 1x1 by banner', function () { - bidRequest.mediaTypes = { - banner: { - sizes: [ - [1, 1] - ] - } - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true when 300x250 over by banner', function () { - bidRequest.mediaTypes = { - banner: { - sizes: [ - [100, 100], - [300, 250] - ] - } - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false when the placementId params are missing', function () { - bidRequest.params.placementId = undefined; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false when the mediaType video params are missing', function () { - bidRequest.mediaTypes = { - video: {} - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false when the mediaType banner params are missing', function () { - bidRequest.mediaTypes = { - banner: {} - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false when the mediaTypes params are missing', function () { - bidRequest.mediaTypes = {}; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); - - describe('spec.buildRequests', function () { - it('should build bid requests by video', function () { - const bidRequests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(bidRequests.data); - expect(data.bids).to.have.lengthOf(1); - const request = data.bids[0]; - expect(bidRequests.method).to.equal('POST'); - expect(bidRequests.url).to.equal('https://api.relaido.jp/bid/v1/sprebid'); - expect(data.canonical_url).to.equal('https://publisher.com/home'); - expect(data.canonical_url_hash).to.equal('e6092f44a0044903ae3764126eedd6187c1d9f04'); - expect(data.ref).to.equal(bidderRequest.refererInfo.page); - expect(data.timeout_ms).to.equal(bidderRequest.timeout); - expect(request.ad_unit_code).to.equal(bidRequest.adUnitCode); - expect(request.auction_id).to.equal(bidRequest.auctionId); - expect(data.bidder).to.equal(bidRequest.bidder); - expect(request.bidder_request_id).to.equal(bidRequest.bidderRequestId); - expect(data.bid_requests_count).to.equal(bidRequest.bidRequestsCount); - expect(request.bid_id).to.equal(bidRequest.bidId); - expect(request.transaction_id).to.equal(bidRequest.ortb2Imp.ext.tid); - expect(request.media_type).to.equal('video'); - expect(request.pagekvt).to.deep.equal({}); - expect(data.uuid).to.equal(relaido_uuid); - expect(data.pv).to.equal('$prebid.version$'); - expect(request.userIdAsEids).to.be.an('array'); - }); - - it('should build bid requests by banner', function () { - bidRequest.mediaTypes = { - video: { - context: 'outstream', - playerSize: [ - [320, 180] - ] - }, - banner: { - sizes: [ - [640, 360], - [1, 1] - ] - } - }; - const bidRequests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(bidRequests.data); - expect(data.bids).to.have.lengthOf(1); - const request = data.bids[0]; - expect(request.media_type).to.equal('banner'); - expect(request.banner_sizes).to.equal('640x360,1x1'); - }); - - it('should take 1x1 size', function () { - bidRequest.mediaTypes = { - video: { - context: 'outstream', - playerSize: [ - [320, 180] - ] - }, - banner: { - sizes: [ - [640, 360], - [1, 1] - ] - } - }; - const bidRequests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(bidRequests.data); - expect(data.bids).to.have.lengthOf(1); - const request = data.bids[0]; - - expect(request.width).to.equal(1); - }); - - it('The referrer should be the last', function () { - const bidRequests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(bidRequests.data); - expect(data.bids).to.have.lengthOf(1); - const keys = Object.keys(data); - expect(keys[0]).to.equal('version'); - expect(keys[keys.length - 1]).to.equal('ref'); - }); - - it('should get userIdAsEids', function () { - const userIdAsEids = [ - { - source: 'hogehoge.com', - uids: { - atype: 1, - id: 'hugahuga' - } - } - ] - bidRequest.userIdAsEids = userIdAsEids - const bidRequests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(bidRequests.data); - expect(data.bids[0].userIdAsEids).to.have.lengthOf(1); - expect(data.bids[0].userIdAsEids[0].source).to.equal('hogehoge.com'); - }); - - it('should get pagekvt', function () { - mockGpt.enable(); - window.googletag.pubads().clearTargeting(); - window.googletag.pubads().setTargeting('testkey', ['testvalue']); - bidRequest.adUnitCode = 'test-adunit-code-1'; - window.googletag.pubads().setSlots([mockGpt.makeSlot({ code: bidRequest.adUnitCode })]); - const bidRequests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(bidRequests.data); - expect(data.bids).to.have.lengthOf(1); - const request = data.bids[0]; - expect(request.pagekvt).to.deep.equal({testkey: ['testvalue']}); - }); - - it('should get canonicalUrl (ogUrl:true)', function () { - bidRequest.params.ogUrl = true; - bidderRequest.refererInfo.canonicalUrl = null; - const documentStub = sandbox.stub(window.top.document, 'querySelector'); - documentStub.withArgs('meta[property="og:url"]').returns({ - content: 'http://localhost:9999/fb-test' - }); - const bidRequests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(bidRequests.data); - expect(data.bids).to.have.lengthOf(1); - expect(data.canonical_url).to.equal('http://localhost:9999/fb-test'); - expect(data.canonical_url_hash).to.equal('cd106829f866d60ee4ed43c6e2a5d0a5212ffc97'); - }); - - it('should not get canonicalUrl (ogUrl:false)', function () { - bidRequest.params.ogUrl = false; - bidderRequest.refererInfo.canonicalUrl = null; - const documentStub = sandbox.stub(window.top.document, 'querySelector'); - documentStub.withArgs('meta[property="og:url"]').returns({ - content: 'http://localhost:9999/fb-test' - }); - const bidRequests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(bidRequests.data); - expect(data.bids).to.have.lengthOf(1); - expect(data.canonical_url).to.be.null; - expect(data.canonical_url_hash).to.be.null; - }); - - it('should not get canonicalUrl (ogUrl:nothing)', function () { - bidderRequest.refererInfo.canonicalUrl = null; - const documentStub = sandbox.stub(window.top.document, 'querySelector'); - documentStub.withArgs('meta[property="og:url"]').returns({ - content: 'http://localhost:9999/fb-test' - }); - const bidRequests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(bidRequests.data); - expect(data.bids).to.have.lengthOf(1); - expect(data.canonical_url).to.be.null; - expect(data.canonical_url_hash).to.be.null; - }); - }); - - describe('spec.interpretResponse', function () { - it('should build bid response by video and serverResponse contains vast', function () { - const bidResponses = spec.interpretResponse(serverResponse, serverRequest); - expect(bidResponses).to.have.lengthOf(1); - const response = bidResponses[0]; - expect(response.requestId).to.equal(serverRequest.data.bids[0].bidId); - expect(response.placementId).to.equal(serverResponse.body.ads[0].placementId); - expect(response.width).to.equal(serverRequest.data.bids[0].width); - expect(response.height).to.equal(serverRequest.data.bids[0].height); - expect(response.cpm).to.equal(serverResponse.body.ads[0].price); - expect(response.currency).to.equal(serverResponse.body.ads[0].currency); - expect(response.creativeId).to.equal(serverResponse.body.ads[0].creativeId); - expect(response.vastXml).to.equal(serverResponse.body.ads[0].vast); - expect(response.playerUrl).to.equal(serverResponse.body.playerUrl); - expect(response.meta.advertiserDomains).to.equal(serverResponse.body.ads[0].adomain); - expect(response.meta.mediaType).to.equal(VIDEO); - expect(response.ad).to.be.undefined; - }); - - it('should build bid response by banner and serverResponse contains vast', function () { - serverResponse.body.ads[0].mediaType = 'banner'; - const bidResponses = spec.interpretResponse(serverResponse, serverRequest); - expect(bidResponses).to.have.lengthOf(1); - const response = bidResponses[0]; - expect(response.requestId).to.equal(serverRequest.data.bids[0].bidId); - expect(response.placementId).to.equal(serverResponse.body.ads[0].placementId); - expect(response.width).to.equal(serverRequest.data.bids[0].width); - expect(response.height).to.equal(serverRequest.data.bids[0].height); - expect(response.cpm).to.equal(serverResponse.body.ads[0].price); - expect(response.currency).to.equal(serverResponse.body.ads[0].currency); - expect(response.creativeId).to.equal(serverResponse.body.ads[0].creativeId); - expect(response.vastXml).to.be.undefined; - expect(response.playerUrl).to.equal(serverResponse.body.playerUrl); - expect(response.ad).to.include(`
`); - expect(response.ad).to.include(``); - expect(response.ad).to.include(`window.RelaidoPlayer.renderAd`); - }); - - it('should build bid response by banner and serverResponse contains adTag', function () { - const bidResponses = spec.interpretResponse(serverResponseBanner, serverRequest); - expect(bidResponses).to.have.lengthOf(1); - const response = bidResponses[0]; - expect(response.requestId).to.equal(serverRequest.data.bids[0].bidId); - expect(response.placementId).to.equal(serverResponseBanner.body.ads[0].placementId); - expect(response.cpm).to.equal(serverResponseBanner.body.ads[0].price); - expect(response.currency).to.equal(serverResponseBanner.body.ads[0].currency); - expect(response.creativeId).to.equal(serverResponseBanner.body.ads[0].creativeId); - expect(response.vastXml).to.be.undefined; - expect(response.playerUrl).to.be.undefined; - expect(response.ad).to.include(`
`); - }); - - it('should build bid response by video and playerUrl in ads', function () { - serverResponse.body.ads[0].playerUrl = 'https://relaido/player-customized.js'; - const bidResponses = spec.interpretResponse(serverResponse, serverRequest); - expect(bidResponses).to.have.lengthOf(1); - const response = bidResponses[0]; - expect(response.playerUrl).to.equal(serverResponse.body.ads[0].playerUrl); - }); - - it('should build bid response by banner and playerUrl in ads', function () { - serverResponse.body.ads[0].playerUrl = 'https://relaido/player-customized.js'; - serverResponse.body.ads[0].mediaType = 'banner'; - const bidResponses = spec.interpretResponse(serverResponse, serverRequest); - expect(bidResponses).to.have.lengthOf(1); - const response = bidResponses[0]; - expect(response.playerUrl).to.equal(serverResponse.body.ads[0].playerUrl); - }); - - it('should not build bid response', function () { - serverResponse = {}; - const bidResponses = spec.interpretResponse(serverResponse, serverRequest); - expect(bidResponses).to.have.lengthOf(0); - }); - - it('should not build bid response', function () { - serverResponse = { - body: { - status: 'no_ad', - } - }; - const bidResponses = spec.interpretResponse(serverResponse, serverRequest); - expect(bidResponses).to.have.lengthOf(0); - }); - }); - - describe('spec.getUserSyncs', function () { - it('should choose iframe sync urls', function () { - const userSyncs = spec.getUserSyncs({iframeEnabled: true}, [serverResponse]); - expect(userSyncs).to.deep.equal([{ - type: 'iframe', - url: serverResponse.body.syncUrl + '?uu=hogehoge' - }]); - }); - - it('should choose iframe sync urls if serverResponse are empty', function () { - const userSyncs = spec.getUserSyncs({iframeEnabled: true}, []); - expect(userSyncs).to.deep.equal([{ - type: 'iframe', - url: 'https://api.relaido.jp/tr/v1/prebid/sync.html?uu=hogehoge' - }]); - }); - - it('should choose iframe sync urls if syncUrl are undefined', function () { - serverResponse.body.syncUrl = undefined; - const userSyncs = spec.getUserSyncs({iframeEnabled: true}, [serverResponse]); - expect(userSyncs).to.deep.equal([{ - type: 'iframe', - url: 'https://api.relaido.jp/tr/v1/prebid/sync.html?uu=hogehoge' - }]); - }); - - it('should return empty if iframeEnabled are false', function () { - const userSyncs = spec.getUserSyncs({iframeEnabled: false}, [serverResponse]); - expect(userSyncs).to.have.lengthOf(0); - }); - }); - - describe('spec.onBidWon', function () { - it('Should create nurl pixel if bid nurl', function () { - const bid = { - bidder: bidRequest.bidder, - creativeId: serverResponse.body.ads[0].creativeId, - cpm: serverResponse.body.ads[0].price, - params: [bidRequest.params], - auctionId: bidRequest.auctionId, - requestId: bidRequest.bidId, - adId: '3b286a4db7031f', - adUnitCode: bidRequest.adUnitCode, - ref: window.location.href, - } - spec.onBidWon(bid); - const parser = utils.parseUrl(triggerPixelStub.getCall(0).args[0]); - const query = parser.search; - expect(parser.hostname).to.equal('api.relaido.jp'); - expect(parser.pathname).to.equal('/tr/v1/prebid/win.gif'); - expect(query.placement_id).to.equal('100000'); - expect(query.creative_id).to.equal('1000'); - expect(query.price).to.equal('500'); - expect(query.auction_id).to.equal('413ed000-8c7a-4ba1-a1fa-9732e006f8c3'); - expect(query.bid_id).to.equal('2ed93003f7bb99'); - expect(query.ad_id).to.equal('3b286a4db7031f'); - expect(query.ad_unit_code).to.equal('test'); - expect(query.ref).to.include(window.location.href); - }); - }); - - describe('spec.onTimeout', function () { - it('Should create nurl pixel if bid nurl', function () { - const data = [{ - bidder: bidRequest.bidder, - bidId: bidRequest.bidId, - adUnitCode: bidRequest.adUnitCode, - auctionId: bidRequest.auctionId, - params: [bidRequest.params], - timeout: bidderRequest.timeout, - }]; - spec.onTimeout(data); - const parser = utils.parseUrl(triggerPixelStub.getCall(0).args[0]); - const query = parser.search; - expect(parser.hostname).to.equal('api.relaido.jp'); - expect(parser.pathname).to.equal('/tr/v1/prebid/timeout.gif'); - expect(query.placement_id).to.equal('100000'); - expect(query.timeout).to.equal('1000'); - expect(query.auction_id).to.equal('413ed000-8c7a-4ba1-a1fa-9732e006f8c3'); - expect(query.bid_id).to.equal('2ed93003f7bb99'); - expect(query.ad_unit_code).to.equal('test'); - expect(query.ref).to.include(window.location.href); - }); - }); - - describe('spec.outstreamRender', function () { - it('Should to pass a Bid to renderAd', function () { - const bidResponses = spec.interpretResponse(serverResponse, serverRequest); - const response = bidResponses[0]; - sinon.spy(window.RelaidoPlayer, 'renderAd'); - response.renderer.render(response); - const renderCall = window.RelaidoPlayer.renderAd.getCall(0); - const arg = renderCall.args[0]; - expect(arg.width).to.equal(640); - expect(arg.height).to.equal(360); - expect(arg.vastXml).to.equal(''); - expect(arg.mediaType).to.equal(VIDEO); - expect(arg.placementId).to.equal(100000); - }); - }); -}); diff --git a/test/spec/modules/relayBidAdapter_spec.js b/test/spec/modules/relayBidAdapter_spec.js deleted file mode 100644 index 38a3cfc9b..000000000 --- a/test/spec/modules/relayBidAdapter_spec.js +++ /dev/null @@ -1,131 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/relayBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'relay' -const endpoint = 'https://e.relay.bid/p/openrtb2'; - -describe('RelayBidAdapter', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder, - mediaTypes: { [BANNER]: { sizes: [[300, 250]] } }, - params: { - accountId: 15000, - }, - ortb2Imp: { - ext: { - relay: { - bidders: { - bidderA: { - theId: 'abc123' - }, - bidderB: { - theId: 'xyz789' - } - } - } - } - } - }, - { - bidId: getUniqueIdentifierStr(), - bidder, - mediaTypes: { [BANNER]: { sizes: [[300, 250]] } }, - params: { - accountId: 30000, - }, - ortb2Imp: { - ext: { - relay: { - bidders: { - bidderA: { - theId: 'def456' - }, - bidderB: { - theId: 'uvw101112' - } - } - } - } - } - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: {} - } - - const bidderRequest = {}; - - describe('isBidRequestValid', function () { - it('Valid bids have a params.accountId.', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Invalid bids do not have a params.accountId.', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - const requests = spec.buildRequests(bids, bidderRequest); - const firstRequest = requests[0]; - const secondRequest = requests[1]; - - it('Creates two requests', function () { - expect(firstRequest).to.exist; - expect(firstRequest.data).to.exist; - expect(firstRequest.method).to.exist; - expect(firstRequest.method).to.equal('POST'); - expect(firstRequest.url).to.exist; - expect(firstRequest.url).to.equal(`${endpoint}?a=15000&pb=1&pbv=v8.1.0`); - - expect(secondRequest).to.exist; - expect(secondRequest.data).to.exist; - expect(secondRequest.method).to.exist; - expect(secondRequest.method).to.equal('POST'); - expect(secondRequest.url).to.exist; - expect(secondRequest.url).to.equal(`${endpoint}?a=30000&pb=1&pbv=v8.1.0`); - }); - - it('Does not generate requests when there are no bids', function () { - const request = spec.buildRequests([], bidderRequest); - expect(request).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function () { - it('Uses Prebid consent values if incoming sync URLs lack consent.', function () { - const syncOpts = { - iframeEnabled: true, - pixelEnabled: true - }; - const test_gdpr_applies = true; - const test_gdpr_consent_str = 'TEST_GDPR_CONSENT_STRING'; - const responses = [{ - body: { - ext: { - user_syncs: [ - { type: 'image', url: 'https://image-example.com' }, - { type: 'iframe', url: 'https://iframe-example.com' } - ] - } - } - }]; - - const sync_urls = spec.getUserSyncs(syncOpts, responses, { gdprApplies: test_gdpr_applies, consentString: test_gdpr_consent_str }); - expect(sync_urls).to.be.an('array'); - expect(sync_urls[0].url).to.equal('https://image-example.com/?gdpr=1&gdpr_consent=TEST_GDPR_CONSENT_STRING'); - expect(sync_urls[1].url).to.equal('https://iframe-example.com/?gdpr=1&gdpr_consent=TEST_GDPR_CONSENT_STRING'); - }); - }); -}); diff --git a/test/spec/modules/relevadRtdProvider_spec.js b/test/spec/modules/relevadRtdProvider_spec.js deleted file mode 100644 index 6902d910f..000000000 --- a/test/spec/modules/relevadRtdProvider_spec.js +++ /dev/null @@ -1,412 +0,0 @@ -import { addRtdData, getBidRequestData, relevadSubmodule, serverData } from 'modules/relevadRtdProvider.js'; -import { server } from 'test/mocks/xhr.js'; -import {config} from 'src/config.js'; -import { deepClone, deepAccess, deepSetValue } from '../../../src/utils.js'; - -const responseHeader = {'Content-Type': 'application/json'}; - -const moduleConfigCommon = { - 'dryrun': true, - params: { - setgpt: true, - minscore: 50, - partnerid: 12345, - bidders: [{ bidder: 'appnexus' }, - { bidder: 'rubicon', }, - { bidder: 'smart', }, - { bidder: 'ix', }, - { bidder: 'proxistore', }, - { bidder: 'other' }] - } -}; - -const reqBidsCommon = { - 'timeout': 10000, - 'adUnitCodes': ['/19968336/header-bid-tag-0'], - 'ortb2Fragments': { - 'global': { - 'site': { - 'page': 'http://www.localhost.localdomain:8888/integrationExamples/gpt/relevadRtdProvider_example.html?pbjs_debug=true', - 'domain': 'localhost.localdomain:8888', - 'publisher': { - 'domain': 'localhost.localdomain:8888' - } - }, - 'device': { - 'w': 355, - 'h': 682, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36', - 'language': 'en' - } - }, - 'bidder': {} - } -}; - -const adUnitsCommon = [ - { - 'code': '/19968336/header-bid-tag-0', - 'mediaTypes': { - 'banner': { 'sizes': [[728, 90]] } - }, - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { 'placementId': '13144370' } - }, - { bidder: 'other' }, - { bidder: 'rubicon', 'params': { id: 1 } }, - { bidder: 'smart', }, - { bidder: 'ix', }, - { bidder: 'proxistore', } - ] - } -]; - -describe('relevadRtdProvider', function() { - describe('relevadSubmodule', function() { - it('successfully instantiates', function () { - expect(relevadSubmodule.init()).to.equal(true); - }); - }); - - describe('Add segments and categories test 1', function() { - it('adds contextual categories and segments', function() { - const moduleConfig = { ...deepClone(moduleConfigCommon) }; - const reqBids = { - ...deepClone(reqBidsCommon), - 'adUnits': deepClone(adUnitsCommon), - }; - - const data = { - segments: ['segment1', 'segment2'], - cats: { 'category3': 100 }, - }; - - (config.getConfig('ix') || {}).firstPartyData = null; - addRtdData(reqBids, data, moduleConfig, () => {}); - expect(reqBids.adUnits[0].bids[0].params.keywords).to.have.deep.property('relevad_rtd', ['segment1', 'segment2', 'category3']); - expect(reqBids.adUnits[0].bids[1].ortb2.site.ext.data).to.have.deep.property('relevad_rtd', ['category3']); - expect(reqBids.adUnits[0].bids[1].ortb2.user.ext.data).to.have.deep.property('relevad_rtd', ['segment1', 'segment2']); - expect(reqBids.adUnits[0].bids[3].params).to.have.deep.property('target', 'relevad_rtd=segment1;relevad_rtd=segment2;relevad_rtd=category3'); - expect(reqBids.adUnits[0].bids[5].ortb2.user.ext.data).to.have.deep.property('segments', ['segment1', 'segment2']); - expect(reqBids.adUnits[0].bids[5].ortb2.user.ext.data).to.have.deep.property('contextual_categories', ['category3']); - expect(reqBids.ortb2Fragments.bidder.rubicon.user.ext.data).to.have.deep.property('relevad_rtd', ['segment1', 'segment2']); - expect(config.getConfig('ix.firstPartyData')).to.have.deep.property('relevad_rtd', ['segment1', 'segment2', 'category3']); - }); - }); - - describe('Add segments and categories test 2 to one bidder out of many', function() { - it('adds contextual categories and segments', function() { - const moduleConfig = { ...deepClone(moduleConfigCommon) }; - const reqBids = { - ...deepClone(reqBidsCommon), - 'adUnits': deepClone(adUnitsCommon), - }; - - const data = { - segments: ['segment1', 'segment2'], - cats: { 'category3': 100 }, - wl: { 'appnexus': { 'placementId': '13144370' } }, - }; - - (config.getConfig('ix') || {}).firstPartyData = null; - addRtdData(reqBids, data, moduleConfig, () => { }); - expect(reqBids.adUnits[0].bids[0].params.keywords).to.have.deep.property('relevad_rtd', ['segment1', 'segment2', 'category3']); - expect(reqBids.adUnits[0].bids[1].ortb2?.site?.ext?.data || {}).to.not.have.property('relevad_rtd'); - expect(reqBids.adUnits[0].bids[1].ortb2?.user?.ext?.data || {}).to.not.have.property('relevad_rtd'); - expect(reqBids.adUnits[0].bids[3].params || {}).to.not.have.deep.property('target', 'relevad_rtd=segment1;relevad_rtd=segment2;relevad_rtd=category3'); - expect(reqBids.adUnits[0].bids[5].ortb2?.user?.ext?.data || {}).to.not.have.deep.property('segments', ['segment1', 'segment2']); - expect(reqBids.adUnits[0].bids[5].ortb2?.user?.ext?.data || {}).to.not.have.deep.property('contextual_categories', ['category3']); - expect(reqBids.adUnits[0].bids[5].ortb2?.user?.ext?.data || {}).to.not.have.deep.property('contextual_categories', {'0': 'category3'}); - expect(reqBids.ortb2Fragments?.bidder?.rubicon?.user?.ext?.data || {}).to.not.have.deep.property('relevad_rtd', ['segment1', 'segment2']); - expect(config.getConfig('ix.firstPartyData') || {}).to.not.have.deep.property('relevad_rtd', ['segment1', 'segment2', 'category3']); - }); - }); - - describe('Add segments and categories test 4', function() { - it('adds contextual categories and segments', function() { - const moduleConfig = { - 'dryrun': true, - params: { - setgpt: true, - minscore: 50, - partnerid: 12345, - } - }; - - const reqBids = { - 'timeout': 10000, - 'adUnits': deepClone(adUnitsCommon), - 'adUnitCodes': [ '/19968336/header-bid-tag-0' ], - 'ortb2Fragments': { - 'global': { - 'site': { - 'page': 'http://www.localhost.localdomain:8888/integrationExamples/gpt/relevadRtdProvider_example.html?pbjs_debug=true', - 'domain': 'localhost.localdomain:8888', - 'publisher': { - 'domain': 'localhost.localdomain:8888' - } - }, - 'device': { - 'w': 355, - 'h': 682, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36', - 'language': 'en' - } - }, - 'bidder': {} - }, - 'metrics': {}, - 'defer': { 'promise': {} } - } - - const data = { - segments: ['segment1', 'segment2'], - cats: {'category3': 100} - }; - (config.getConfig('ix') || {}).firstPartyData = null; - addRtdData(reqBids, data, moduleConfig, () => {}); - expect(reqBids.adUnits[0].bids[0].params.keywords).to.have.deep.property('relevad_rtd', ['segment1', 'segment2', 'category3']); - }); - }); - - describe('Get Segments And Categories', function() { - it('gets data from async request and adds contextual categories and segments', function() { - const moduleConfig = { - params: { - 'dryrun': true, - sdtgpt: false, - minscore: 50, - bidders: [{ bidder: 'appnexus' }, - { bidder: 'other' }] - } - }; - - const reqBidsConfigObj = { - adUnits: [{ - bids: [{ - bidder: 'appnexus', - params: { - placementId: 13144370 - } - }, { - bidder: 'other' - }] - }] - }; - - const data = { - segments: ['segment1', 'segment2'], - cats: {'category3': 100} - }; - - getBidRequestData(reqBidsConfigObj, () => {}, moduleConfig, {}); - - const request = server.requests[0]; - request.respond(200, responseHeader, JSON.stringify(data)); - - expect(reqBidsConfigObj.adUnits[0].bids[0].params.keywords).to.have.deep.property('relevad_rtd', ['segment1', 'segment2', 'category3']); - expect(reqBidsConfigObj.adUnits[0].bids[1].ortb2.site.ext.data).to.have.deep.property('relevad_rtd', ['category3']); - expect(reqBidsConfigObj.adUnits[0].bids[1].ortb2.user.ext.data).to.have.deep.property('relevad_rtd', ['segment1', 'segment2']); - }); - }); -}); - -describe('Process auction end data', function() { - it('Collects bid data on auction end event', function() { - const auctionEndData = { - 'auctionDetails': { - 'auctionId': 'f7ec9895-5809-475e-8fef-49cbc221921a', - 'auctionStatus': 'completed', - 'adUnits': [ - { - 'code': '/19968336/header-bid-tag-0', - 'mediaTypes': { - 'banner': { 'sizes': [ [ 728, 90 ] ] } - }, - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': '13144370', - 'keywords': { - 'relevad_rtd': [ 'IAB410-391', 'IAB63-53' ] - } - } - } - ], - 'ortb2Imp': { 'ext': { 'data': { 'relevad_rtd': [ 'IAB410-391', 'IAB63-53' ] }, } }, - 'sizes': [ [ 728, 90 ] ], - } - ], - 'adUnitCodes': [ '/19968336/header-bid-tag-0' ], - 'bidderRequests': [ - { - 'bidderCode': 'appnexus', - 'auctionId': 'f7ec9895-5809-475e-8fef-49cbc221921a', - 'bidderRequestId': '1d917281b2bf6c', - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': '13144370', - 'keywords': { - 'relevad_rtd': [ - 'IAB410-391', - 'IAB63-53' - ] - } - }, - 'ortb2Imp': { - 'ext': { 'data': { 'relevad_rtd': [ 'IAB410-391', 'IAB63-53' ] }, } - }, - 'mediaTypes': { 'banner': { 'sizes': [ [ 728, 90 ] ] } }, - 'adUnitCode': '/19968336/header-bid-tag-0', - 'sizes': [ [ 728, 90 ] ], - 'bidId': '20f0b347b07f94', - 'bidderRequestId': '1d917281b2bf6c', - 'auctionId': 'f7ec9895-5809-475e-8fef-49cbc221921a', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'site': { - 'page': 'http://www.localhost.localdomain:8888/integrationExamples/gpt/relevadRtdProvider_example.html', - 'domain': 'localhost.localdomain:8888', - 'publisher': { 'domain': 'localhost.localdomain:8888' }, - 'cat': [ 'IAB410-391', 'IAB63-53' ], - 'pagecat': [ 'IAB410-391', 'IAB63-53' ], - 'sectioncat': [ 'IAB410-391', 'IAB63-53' ] - }, - 'device': { - 'w': 326, - 'h': 649, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36', - 'language': 'en' - } - } - } - ], - 'timeout': 10000, - 'refererInfo': { - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': [ - 'http://www.localhost.localdomain:8888/integrationExamples/gpt/relevadRtdProvider_example.html' - ], - 'topmostLocation': 'http://www.localhost.localdomain:8888/integrationExamples/gpt/relevadRtdProvider_example.html', - 'location': 'http://www.localhost.localdomain:8888/integrationExamples/gpt/relevadRtdProvider_example.html', - 'canonicalUrl': null, - 'page': 'http://www.localhost.localdomain:8888/integrationExamples/gpt/relevadRtdProvider_example.html', - 'domain': 'www.localhost.localdomain:8888', - 'ref': null, - 'legacy': { - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': [ 'http://www.localhost.localdomain:8888/integrationExamples/gpt/relevadRtdProvider_example.html' ], - 'referer': 'http://www.localhost.localdomain:8888/integrationExamples/gpt/relevadRtdProvider_example.html', - 'canonicalUrl': null - } - }, - 'ortb2': { - 'site': { - 'page': 'http://www.localhost.localdomain:8888/integrationExamples/gpt/relevadRtdProvider_example.html', - 'domain': 'localhost.localdomain:8888', - 'publisher': { 'domain': 'localhost.localdomain:8888' }, - 'cat': [ 'IAB410-391', 'IAB63-53' ], - 'pagecat': [ 'IAB410-391', 'IAB63-53' ], - 'sectioncat': [ 'IAB410-391', 'IAB63-53' ] - }, - 'device': { - 'w': 326, - 'h': 649, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36', - 'language': 'en' - } - }, - 'start': 1674132848498 - } - ], - 'noBids': [], - 'bidsReceived': [ - { - 'bidderCode': 'appnexus', - 'width': 728, - 'height': 90, - 'statusMessage': 'Bid available', - 'adId': '3222e6ead116f3', - 'requestId': '20f0b347b07f94', - 'transactionId': 'df8586ac-6476-4fbf-a727-eda99996dc39', - 'auctionId': 'f7ec9895-5809-475e-8fef-49cbc221921a', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 1.5, - 'creativeId': 98493734, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'adUnitCode': '/19968336/header-bid-tag-0', - 'adapterCode': 'appnexus', - 'originalCpm': 1.5, - 'originalCurrency': 'USD', - 'responseTimestamp': 1674132848649, - 'requestTimestamp': 1674132848498, - 'bidder': 'appnexus', - 'size': '728x90', - } - ], - }, - 'config': { - 'name': 'RelevadRTDModule', - 'waitForIt': true, - 'dryrun': true, - 'params': { - 'partnerid': 12345, - 'setgpt': true - } - }, - 'userConsent': { 'gdpr': null, 'usp': null, 'gpp': null, 'coppa': false } - }; - - const auctionDetails = auctionEndData['auctionDetails']; - const userConsent = auctionEndData['userConsent']; - const moduleConfig = auctionEndData['config']; - - relevadSubmodule.onAuctionEndEvent(auctionDetails, moduleConfig, userConsent); - expect(serverData.clientdata).to.deep.equal( - { - 'event': 'bids', - 'adunits': [ - { - 'code': '/19968336/header-bid-tag-0', - 'bids': [ - { - 'bidder': 'appnexus', - 'cpm': 1.5, - 'currency': 'USD', - 'type': 'banner', - 'ttr': undefined, - 'dealId': undefined, - 'size': '728x90' - } - ] - } - ], - 'reledata': { segments: ['segment1', 'segment2'], cats: { 'category3': 100 }, }, - 'gdpra': '', - 'gdprc': '', - 'aid': '', - 'cid': '12345', - 'pid': '', - } - ); - }); -}); diff --git a/test/spec/modules/relevantAnalyticsAdapter_spec.js b/test/spec/modules/relevantAnalyticsAdapter_spec.js deleted file mode 100644 index e3d0eca1b..000000000 --- a/test/spec/modules/relevantAnalyticsAdapter_spec.js +++ /dev/null @@ -1,43 +0,0 @@ -import relevantAnalytics from '../../../modules/relevantAnalyticsAdapter.js'; -import adapterManager from 'src/adapterManager'; -import * as events from 'src/events'; -import { EVENTS } from 'src/constants.js' -import { expect } from 'chai'; - -describe('Relevant Analytics Adapter', () => { - beforeEach(() => { - adapterManager.enableAnalytics({ - provider: 'relevant' - }); - }); - - afterEach(() => { - relevantAnalytics.disableAnalytics(); - }); - - it('should pass all events to the global array', () => { - // Given - const testEvents = [ - { ev: EVENTS.AUCTION_INIT, args: { test: 1 } }, - { ev: EVENTS.BID_REQUESTED, args: { test: 2 } }, - ]; - - // When - testEvents.forEach(({ ev, args }) => ( - events.emit(ev, args) - )); - - // Then - const eventQueue = (window.relevantDigital || {}).pbEventLog; - expect(eventQueue).to.be.an('array'); - expect(eventQueue.length).to.be.at.least(testEvents.length); - - // The last events should be our test events - const myEvents = eventQueue.slice(-testEvents.length); - testEvents.forEach(({ ev, args }, idx) => { - const actualEvent = myEvents[idx]; - expect(actualEvent.ev).to.eql(ev); - expect(actualEvent.args).to.eql(args); - }); - }); -}); diff --git a/test/spec/modules/relevantdigitalBidAdapter_spec.js b/test/spec/modules/relevantdigitalBidAdapter_spec.js deleted file mode 100644 index 45a84d599..000000000 --- a/test/spec/modules/relevantdigitalBidAdapter_spec.js +++ /dev/null @@ -1,299 +0,0 @@ -import {spec, resetBidderConfigs} from 'modules/relevantdigitalBidAdapter.js'; -import { parseUrl } from 'src/utils.js'; - -const expect = require('chai').expect; - -const PBS_HOST = 'dev-api.relevant-digital.com'; -const PLACEMENT_ID = 'example_placement_id'; -const ACCOUNT_ID = 'example_account_id'; -const TEST_DOMAIN = 'example.com'; -const TEST_PAGE = `https://${TEST_DOMAIN}/page.html`; -const ADUNIT_CODE = '/19968336/header-bid-tag-0'; - -const BID_PARAMS = { - 'params': { - 'placementId': PLACEMENT_ID, - 'accountId': ACCOUNT_ID, - 'pbsHost': PBS_HOST - } -}; - -const BID_REQUEST = { - 'bidder': 'relevantdigital', - ...BID_PARAMS, - 'ortb2Imp': { - 'ext': { - 'tid': 'e13391ea-00f3-495d-99a6-d937990d73a9' - } - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - ] - } - }, - 'adUnitCode': ADUNIT_CODE, - 'transactionId': 'e13391ea-00f3-495d-99a6-d937990d73a9', - 'sizes': [ - [ - 300, - 250 - ], - ], - 'bidId': '2d69406037a662', - 'bidderRequestId': '1decd098c76ed2', - 'auctionId': '251a6a36-a5c5-4b82-b2b3-538c148a29dd', - 'src': 'client', - 'metrics': { - 'requestBids.validate': 0.7, - 'requestBids.makeRequests': 2.9, - 'adapter.client.validate': 0.4, - 'adapters.client.relevantdigital.validate': 0.4 - }, - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'site': { - 'page': TEST_PAGE, - 'domain': TEST_DOMAIN, - 'publisher': { - 'domain': 'relevant-digital.com' - } - }, - 'device': { - 'w': 1848, - 'h': 1007, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36', - 'language': 'en', - 'sua': { - 'source': 2, - 'platform': { - 'brand': 'Linux', - 'version': [ - '5', - '4', - '0' - ] - }, - 'browsers': [ - { - 'brand': 'Google Chrome', - 'version': [ - '111', - '0', - '5563', - '146' - ] - }, - ], - 'mobile': 0, - 'model': '', - 'bitness': '64', - 'architecture': 'x86' - } - } - } -}; - -const BIDDER_REQUEST = { - 'bidderCode': BID_REQUEST.bidder, - 'auctionId': BID_REQUEST.auctionId, - 'bidderRequestId': BID_REQUEST.bidderRequestId, - 'bids': [BID_REQUEST], - 'metrics': BID_REQUEST.metrics, - 'ortb2': BID_REQUEST.ortb2, - 'auctionStart': 1681224591370, - 'timeout': 1000, - 'refererInfo': { - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': [ - TEST_PAGE - ], - 'topmostLocation': TEST_PAGE, - 'location': TEST_PAGE, - 'canonicalUrl': null, - 'page': TEST_PAGE, - 'domain': TEST_DOMAIN, - 'ref': null, - 'legacy': { - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': [ - TEST_PAGE - ], - 'referer': TEST_PAGE, - 'canonicalUrl': null - } - }, - 'start': 1681224591375 -}; - -const BID_RESPONSE = { - 'seatbid': [ - { - 'bid': [ - { - 'id': '613673EF-A07C-4486-8EE9-3FC71A7DC73D', - 'impid': BID_REQUEST.bidId, - 'price': 10.76091063668997, - 'adm': '', - 'adomain': [ - 'www.addomain.com' - ], - 'iurl': 'http://localhost11', - 'crid': 'creative111', - 'w': 300, - 'h': 250, - 'ext': { - 'bidtype': 0, - 'dspid': 6, - 'origbidcpm': 1, - 'origbidcur': 'USD', - 'prebid': { - 'meta': { - 'adaptercode': 'pubmatic' - }, - 'targeting': { - 'hb_bidder': 'pubmatic', - 'hb_cache_host': PBS_HOST, - 'hb_cache_path': '/analytics_cache/read', - 'hb_format': 'banner', - 'hb_pb': '10.70', - 'hb_size': '300x250' - }, - 'type': 'banner', - 'video': { - 'duration': 0, - 'primary_category': '' - }, - 'events': { - 'win': `https://${PBS_HOST}/event?t=win&b=fed970f7-4295-456d-a251-38013faab795&a=620523ae7f4bbe1691bbb815&bidder=pubmatic&ts=1678646619765`, - 'imp': `https://${PBS_HOST}/event?t=imp&b=fed970f7-4295-456d-a251-38013faab795&a=620523ae7f4bbe1691bbb815&bidder=pubmatic&ts=1678646619765` - }, - 'bidid': 'fed970f7-4295-456d-a251-38013faab795' - } - } - } - ], - 'seat': 'pubmatic' - } - ], - 'cur': 'SEK', - 'ext': { - 'responsetimemillis': { - 'appnexus': 305, - 'pubmatic': 156 - }, - 'tmaxrequest': 750, - 'relevant': { - 'sync': [ - { 'type': 'redirect', 'url': 'https://example1.com/sync' }, - { 'type': 'redirect', 'url': 'https://example2.com/sync' }, - ], - }, - 'prebid': { - 'auctiontimestamp': 1678646619765, - 'passthrough': { - 'relevant': { - 'bidder': spec.code - } - } - } - } -}; - -const S2S_RESPONSE_BIDDER = BID_RESPONSE.seatbid[0].seat; - -const resetAndBuildRequest = (params) => { - resetBidderConfigs(); - const bidRequest = { - ...BID_REQUEST, - params: { - ...BID_REQUEST.params, - ...params, - }, - }; - return spec.buildRequests([bidRequest], BIDDER_REQUEST); -}; - -describe('Relevant Digital Bid Adaper', function () { - describe('buildRequests', () => { - const [request] = resetAndBuildRequest(); - const {data, url} = request - it('should give the correct URL', () => { - expect(url).equal(`https://${PBS_HOST}/openrtb2/auction`); - }); - it('should set the correct stored request ids', () => { - expect(data.ext.prebid.storedrequest.id).equal(ACCOUNT_ID); - expect(data.imp[0].ext.prebid.storedrequest.id).equal(PLACEMENT_ID); - }); - it('should include bidder code in passthrough object', () => { - expect(data.ext.prebid.passthrough.relevant.bidder).equal(spec.code); - }); - it('should set tmax to something below the timeout', () => { - expect(data.tmax).be.greaterThan(0); - expect(data.tmax).be.lessThan(BIDDER_REQUEST.timeout) - }); - }); - describe('interpreteResponse', () => { - const [request] = resetAndBuildRequest(); - const [bid] = spec.interpretResponse({ body: BID_RESPONSE }, request); - it('should not have S2S bidder\'s bidder code', () => { - expect(bid.bidderCode).not.equal(S2S_RESPONSE_BIDDER); - }); - it('should return the right creative content', () => { - const respBid = BID_RESPONSE.seatbid[0].bid[0]; - expect(bid.cpm).equal(respBid.price); - expect(bid.ad).equal(respBid.adm); - expect(bid.width).equal(respBid.w); - expect(bid.height).equal(respBid.h); - }); - }); - describe('interpreteResponse with useSourceBidderCode', () => { - const [request] = resetAndBuildRequest({ useSourceBidderCode: true }); - const [bid] = spec.interpretResponse({ body: BID_RESPONSE }, request); - it('should have S2S bidder\'s code', () => { - expect(bid.bidderCode).equal(S2S_RESPONSE_BIDDER); - }); - }); - describe('getUserSyncs with iframeEnabled', () => { - resetAndBuildRequest() - const allSyncs = spec.getUserSyncs({ iframeEnabled: true }, [{ body: BID_RESPONSE }], null, null); - const [{ url, type }] = allSyncs; - const { bidders, endpoint } = parseUrl(url).search; - it('should return a single sync object', () => { - expect(allSyncs.length).equal(1); - }); - it('should use iframe sync when available', () => { - expect(type).equal('iframe'); - }); - it('should sync to all s2s bidders', () => { - expect(bidders.split(',').sort()).to.deep.equal(['appnexus', 'pubmatic']); - }); - it('should sync to the right endpoint', () => { - expect(endpoint).equal(`https://${PBS_HOST}/cookie_sync`); - }); - it('should not sync to the same s2s bidders when called again', () => { - const newSyncs = spec.getUserSyncs({ iframeEnabled: true }, [{ body: BID_RESPONSE }], null, null); - expect(newSyncs).to.deep.equal([]); - }); - }); - describe('getUserSyncs with pixelEnabled', () => { - resetAndBuildRequest() - const responseSyncs = BID_RESPONSE.ext.relevant.sync; - const allSyncs = spec.getUserSyncs({ pixelEnabled: true }, [{ body: BID_RESPONSE }], null, null); - it('should return one sync object per pixel', () => { - const expectedResult = responseSyncs.map(({ url }) => ({url, type: 'image'})); - expect(allSyncs).to.deep.equal(expectedResult) - }); - }); -}); diff --git a/test/spec/modules/relevatehealthBidAdapter_spec.js b/test/spec/modules/relevatehealthBidAdapter_spec.js deleted file mode 100644 index b9cb37416..000000000 --- a/test/spec/modules/relevatehealthBidAdapter_spec.js +++ /dev/null @@ -1,209 +0,0 @@ -import { - expect -} from 'chai'; -import { - spec -} from '../../../modules/relevatehealthBidAdapter.js'; -import * as utils from '../../../src/utils.js'; - -describe('relevatehealth adapter', function() { - let request; - let bannerResponse, invalidResponse; - - beforeEach(function() { - request = [{ - bidder: 'relevatehealth', - mediaTypes: { - banner: { - sizes: [ - [160, 600] - ] - } - }, - params: { - placement_id: 110011, - width: 160, - height: 600, - domain: '', - bid_floor: 0.5 - } - }]; - bannerResponse = { - 'body': { - 'id': 'a48b79e7-7104-4213-99f3-55f3234f2e54', - 'seatbid': [{ - 'bid': [{ - 'id': '3d7dd6dc-7665-4cdc-96a4-5ea192df32b8', - 'impid': '285b9c53b2c662', - 'price': 20.68, - 'adid': '3389', - 'adm': "", - 'adomain': ['google.com'], - 'iurl': 'https://rtb.relevate.health/prebid/relevate', - 'cid': '1431/3389', - 'crid': '3389', - 'w': 160, - 'h': 600, - 'cat': ['IAB1-15'] - }], - 'seat': '00001', - 'group': 0 - }], - 'cur': 'USD', - 'bidid': 'BIDDER_1276' - } - }; - invalidResponse = { - 'body': { - 'id': 'a48b79e7-7104-4213-99f3-55f3234f2e54', - 'seatbid': [{ - 'bid': [{ - 'id': '3d7dd6dc-7665-4cdc-96a4-5ea192df32b8', - 'impid': '285b9c53b2c662', - 'price': 20.68, - 'adid': '3389', - 'adm': 'invalid response', - 'adomain': ['google.com'], - 'iurl': 'https://rtb.relevate.health/prebid/relevate', - 'cid': '1431/3389', - 'crid': '3389', - 'w': 160, - 'h': 600, - 'cat': ['IAB1-15'] - }], - 'seat': '00001', - 'group': 0 - }], - 'cur': 'USD', - 'bidid': 'BIDDER_1276' - } - }; - }); - - describe('validations', function() { - it('isBidValid : placement_id is passed', function() { - const bid = { - bidder: 'relevatehealth', - params: { - placement_id: 110011 - } - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equals(true); - }); - it('isBidValid : placement_id is not passed', function() { - const bid = { - bidder: 'relevatehealth', - params: { - width: 160, - height: 600, - domain: '', - bid_floor: 0.5 - } - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equals(false); - }); - }); - describe('Validate Request', function() { - it('Immutable bid request validate', function() { - const _Request = utils.deepClone(request); - const bidRequest = spec.buildRequests(request); - expect(request).to.deep.equal(_Request); - }); - it('Validate bidder connection', function() { - const _Request = spec.buildRequests(request); - expect(_Request.url).to.equal('https://rtb.relevate.health/prebid/relevate'); - expect(_Request.method).to.equal('POST'); - expect(_Request.options.contentType).to.equal('application/json'); - }); - it('Validate bid request : Impression', function() { - const _Request = spec.buildRequests(request); - const data = JSON.parse(_Request.data); - expect(data[0].imp[0].id).to.equal(request[0].bidId); - expect(data[0].placementId).to.equal(110011); - }); - it('Validate bid request : ad size', function() { - const _Request = spec.buildRequests(request); - const data = JSON.parse(_Request.data); - expect(data[0].imp[0].banner).to.be.a('object'); - expect(data[0].imp[0].banner.w).to.equal(160); - expect(data[0].imp[0].banner.h).to.equal(600); - }); - it('Validate bid request : user object', function() { - const _Request = spec.buildRequests(request); - const data = JSON.parse(_Request.data); - expect(data[0].user).to.be.a('object'); - expect(data[0].user.id).to.be.a('string'); - }); - it('Validate bid request : CCPA Check', function() { - const bidRequest = { - uspConsent: '1NYN' - }; - const _Request = spec.buildRequests(request, bidRequest); - const data = JSON.parse(_Request.data); - expect(data[0].regs.ext.us_privacy).to.equal('1NYN'); - }); - }); - describe('Validate response ', function() { - it('Validate bid response : valid bid response', function() { - const bResponse = spec.interpretResponse(bannerResponse, request); - expect(bResponse).to.be.an('array').with.length.above(0); - expect(bResponse[0].requestId).to.equal(bannerResponse.body.seatbid[0].bid[0].impid); - expect(bResponse[0].width).to.equal(bannerResponse.body.seatbid[0].bid[0].w); - expect(bResponse[0].height).to.equal(bannerResponse.body.seatbid[0].bid[0].h); - expect(bResponse[0].currency).to.equal('USD'); - expect(bResponse[0].netRevenue).to.equal(false); - expect(bResponse[0].mediaType).to.equal('banner'); - expect(bResponse[0].meta.advertiserDomains).to.deep.equal(['google.com']); - expect(bResponse[0].ttl).to.equal(300); - expect(bResponse[0].creativeId).to.equal(bannerResponse.body.seatbid[0].bid[0].crid); - expect(bResponse[0].dealId).to.equal(bannerResponse.body.seatbid[0].bid[0].dealId); - }); - it('Invalid bid response check ', function() { - const bRequest = spec.buildRequests(request); - const response = spec.interpretResponse(invalidResponse, bRequest); - expect(response[0].ad).to.equal('invalid response'); - }); - }); - describe('GPP and coppa', function() { - it('Request params check with GPP Consent', function() { - const bidderReq = { - gppConsent: { - gppString: 'gpp-string-test', - applicableSections: [5] - } - }; - const _Request = spec.buildRequests(request, bidderReq); - const data = JSON.parse(_Request.data); - expect(data[0].regs.gpp).to.equal('gpp-string-test'); - expect(data[0].regs.gpp_sid[0]).to.equal(5); - }); - it('Request params check with GPP Consent read from ortb2', function() { - const bidderReq = { - ortb2: { - regs: { - gpp: 'gpp-test-string', - gpp_sid: [5] - } - } - }; - const _Request = spec.buildRequests(request, bidderReq); - const data = JSON.parse(_Request.data); - expect(data[0].regs.gpp).to.equal('gpp-test-string'); - expect(data[0].regs.gpp_sid[0]).to.equal(5); - }); - it(' Bid request should have coppa flag if its true', () => { - const bidderReq = { - ortb2: { - regs: { - coppa: 1 - } - } - }; - const _Request = spec.buildRequests(request, bidderReq); - const data = JSON.parse(_Request.data); - expect(data[0].regs.coppa).to.equal(1); - }); - }); -}); diff --git a/test/spec/modules/resetdigitalBidAdapter_spec.js b/test/spec/modules/resetdigitalBidAdapter_spec.js deleted file mode 100644 index d010ee865..000000000 --- a/test/spec/modules/resetdigitalBidAdapter_spec.js +++ /dev/null @@ -1,221 +0,0 @@ -import { expect } from 'chai' -import { spec, _getPlatform } from 'modules/resetdigitalBidAdapter.js' -import { newBidder } from 'src/adapters/bidderFactory.js' - -const br = { - body: { - bids: [{ - bid_id: '123', - cpm: 1.23, - w: 300, - h: 250, - html: 'deadbeef', - crid: 'crid' - }], - pixels: [ - { type: 'image', url: 'https://reset.com/image' }, - { type: 'iframe', url: 'https://reset.com/iframe' } - ] - } -} - -const vr = { - body: { - bids: [{ - bid_id: 'abc', - cpm: 2.34, - w: 640, - h: 480, - vast_url: 'https://demo.tremorvideo.com/proddev/vast/vast_inline_nonlinear.xml', - crid: 'video_crid' - }], - pixels: [ - { type: 'image', url: 'https://reset.com/image' }, - { type: 'iframe', url: 'https://reset.com/iframe' } - ] - } -} - -describe('resetdigitalBidAdapter', function () { - const adapter = newBidder(spec) - - const bannerRequest = { - bidId: '123', - transactionId: '456', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - params: { - pubId: '12345' - } - } - - const videoRequest = { - bidId: 'abc', - transactionId: 'def', - mediaTypes: { - video: { - playerDimension: [640, 480] - } - }, - params: { - pubId: 'CK6gUYp58EGopLJnUvM2' - } - } - - describe('codes', function () { - it('should return a bidder code of resetdigital', function () { - expect(spec.code).to.equal('resetdigital') - }) - }) - - describe('isBidRequestValid', function () { - it('should return true if all params present', function () { - expect(spec.isBidRequestValid(bannerRequest)).to.be.true - }) - - it('should return false if zone id and pub id missing', function () { - expect(spec.isBidRequestValid(Object.assign(bannerRequest, { params: { pubId: null, zoneId: null } }))).to.be.false - }) - }) - - describe('buildRequests', function () { - const req = spec.buildRequests([ bannerRequest ], { refererInfo: { } }) - let rdata - - it('should return request object', function () { - expect(req).to.not.be.null - }) - - it('should build request data', function () { - expect(req.data).to.not.be.null - }) - - it('should include one request', function () { - rdata = JSON.parse(req.data) - expect(rdata.imps.length).to.equal(1) - }) - - it('should include all publisher params', function () { - expect(rdata.imps[0].zone_id !== null).to.be.true - }) - - it('should include media types', function () { - expect(rdata.imps[0].media_types !== null).to.be.true - }) - }) - - describe('interpretResponse', function () { - it('should form compliant banner bid object response', function () { - const ir = spec.interpretResponse(br, bannerRequest) - - expect(ir.length).to.equal(1) - - const en = ir[0] - - expect(en.requestId != null && - en.cpm != null && typeof en.cpm === 'number' && - en.width != null && typeof en.width === 'number' && - en.height != null && typeof en.height === 'number' && - en.ad != null && - en.creativeId != null - ).to.be.true - }) - it('should form compliant video object response', function () { - const ir = spec.interpretResponse(vr, videoRequest) - - expect(ir.length).to.equal(1) - - const en = ir[0] - - expect(en.requestId != null && - en.cpm != null && typeof en.cpm === 'number' && - en.width != null && typeof en.width === 'number' && - en.height != null && typeof en.height === 'number' && - (en.vastUrl != null || en.vastXml != null) && - en.creativeId != null - ).to.be.true - }) - }) - - describe('getUserSyncs', function () { - it('should return iframe sync', function () { - const sync = spec.getUserSyncs({ iframeEnabled: true }, [br]) - expect(sync.length).to.equal(1) - expect(sync[0].type === 'iframe') - expect(typeof sync[0].url === 'string') - }) - - it('should return pixel sync', function () { - const sync = spec.getUserSyncs({ pixelEnabled: true }, [br]) - expect(sync.length).to.equal(1) - expect(sync[0].type === 'image') - expect(typeof sync[0].url === 'string') - }) - }) - - describe('schain support', function () { - it('should include schain in the payload if present in bidderRequest', function () { - const schain = { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'example.com', - sid: '00001', - hp: 1, - rid: 'req-1', - name: 'seller', - domain: 'example.com' - }] - }; - - const bidRequest = { - bidId: 'schain-test-id', - params: { - pubId: 'schain-pub' - } - }; - - const bidderRequest = { - ortb2: { - source: { - ext: { - schain - } - } - }, - refererInfo: {} - }; - - const request = spec.buildRequests([bidRequest], bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.schain).to.deep.equal(schain); - }); - - it('should not include schain if not present in bidderRequest', function () { - const bidRequest = { - bidId: 'no-schain-id', - params: { - pubId: 'no-schain-pub' - } - }; - - const bidderRequest = { - ortb2: { - source: { - ext: {} - } - }, - refererInfo: {} - }; - - const request = spec.buildRequests([bidRequest], bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload).to.not.have.property('schain'); - }); - }); -}) diff --git a/test/spec/modules/responsiveAdsBidAdapter_spec.js b/test/spec/modules/responsiveAdsBidAdapter_spec.js deleted file mode 100644 index 375568162..000000000 --- a/test/spec/modules/responsiveAdsBidAdapter_spec.js +++ /dev/null @@ -1,145 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/responsiveAdsBidAdapter.js'; -import * as utils from 'src/utils.js'; - -describe('responsiveAdsBidAdapter', function() { - let bidRequests; - let bidderRequest; - let sandbox; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - sandbox.stub(utils, 'isSafeFrameWindow').returns(false); - sandbox.stub(utils, 'canAccessWindowTop').returns(true); - bidRequests = [{ - bidder: 'responsiveads', - params: { - placementId: '1', - }, - adUnitCode: '/3434399/header-bid-tag-1', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - } - }, - bidId: '123', - auctionId: '456', - bidderRequestId: '789', - transactionId: '123' - }]; - - bidderRequest = { - timeout: 3000, - } - }); - - afterEach(function () { - sandbox.restore(); - }); - - describe('Check if bid is valid', function() { - it('Should accept valid bid', function() { - const validBid = { - bidder: 'responsiveads', - params: {}, - }; - - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(true); - }); - - it('Should not reject bid if missing placementId', function() { - const validBid = { - bidder: 'responsiveads', - params: {} - }; - - const isValid = spec.isBidRequestValid(validBid); - expect(isValid).to.equal(true); - }); - }); - - describe('Build requests', function () { - it('Should not bit on safeframe', function() { - utils.isSafeFrameWindow.restore(); - sandbox.stub(utils, 'isSafeFrameWindow').returns(true); - - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(requests).to.be.null; - }); - - it('Should not bit if cant access window top', function () { - utils.canAccessWindowTop.restore(); - sandbox.stub(utils, 'canAccessWindowTop').returns(false); - - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(requests).to.be.null; - }); - - it('Should use POST and have URL', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.method).to.exist; - expect(request.method).to.equal('POST'); - expect(request.url).to.exist; - }); - - it('Should add adapter version', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.ext.prebid.adapterVersion).to.exist; - }); - }); - - describe('Handling responses', function() { - it('Should return complete bid response', function() { - const serverResponse = { - body: { - id: 'response-id', - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: '123', - impid: '123', - price: 0.5, - adm: ``, - nurl: 'https://example.com/win', - crid: '662d13e12e0c567af92d0918', - w: 300, - h: 250, - mediaType: 'banner', - adomain: ['responsiveads.com'], - attr: [1], - cat: ['IAB1'] - } - ] - } - ] - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - - expect(bids).to.be.lengthOf(1); - expect(bids[0].requestId).to.equal('123'); - expect(bids[0].cpm).to.equal(0.5); - expect(bids[0].width).to.equal(300); - expect(bids[0].height).to.equal(250); - expect(bids[0].ad).to.have.length.above(1); - expect(bids[0].meta.advertiserDomains).to.deep.equal(['responsiveads.com']); - }); - - it('should return empty bid response', function () { - const emptyServerResponse = { - body: [] - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(emptyServerResponse, request); - - expect(bids).to.be.lengthOf(0); - }); - }); -}); diff --git a/test/spec/modules/retailspotBidAdapter_spec.js b/test/spec/modules/retailspotBidAdapter_spec.js deleted file mode 100644 index 7e693c797..000000000 --- a/test/spec/modules/retailspotBidAdapter_spec.js +++ /dev/null @@ -1,426 +0,0 @@ -import { expect } from 'chai'; - -import { spec } from 'modules/retailspotBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; - -describe('RetailSpot Adapter', function () { - const canonicalUrl = 'https://canonical.url/?t=%26'; - const referrerUrl = 'http://referrer.url/?param=value'; - const pageUrl = 'http://page.url/?param=value'; - const domain = 'domain:123'; - const env = 'preprod'; - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - consentString: consentString, - gdprApplies: true - }, - refererInfo: {location: referrerUrl, canonicalUrl, domain, topmostLocation: 'fakePageURL'}, - ortb2: {site: {page: pageUrl, ref: referrerUrl}} - }; - - const bidRequestWithSinglePlacement = [ - { - 'bidId': 'bid_id_0', - 'bidder': 'retailspot', - 'placementCode': 'adunit/hb-0', - 'params': { - 'placement': 'placement_0' - }, - 'sizes': '300x250', - 'mediaTypes': { - 'banner': { - 'sizes': ['300x250'] - }, - }, - 'transactionId': 'bid_id_0_transaction_id' - } - ]; - - const bidRequestWithMultipleMediatype = [ - { - 'bidId': 'bid_id_0', - 'bidder': 'retailspot', - 'placementCode': 'adunit/hb-0', - 'params': { - 'placement': 'placement_0' - }, - 'sizes': '300x250', - 'mediaTypes': { - 'banner': { - 'sizes': ['640x480'] - }, - 'video': { - 'playerSize': [640, 480], - 'context': 'outstream' - } - }, - 'transactionId': 'bid_id_0_transaction_id' - } - ]; - - const sentBidVideo = [ - { - 'bidId': 'bid_id_0', - 'placement': 'test-1234', - 'video': { - 'playerSize': [640, 480] - } - } - ]; - - const bidRequestWithDevPlacement = [ - { - 'bidId': 'bid_id_0', - 'bidder': 'retailspot', - 'placementCode': 'adunit/hb-0', - 'params': { - 'placement': 'placement_0', - 'env': 'dev' - }, - 'sizes': '300x250', - 'mediaTypes': - { 'banner': - {'sizes': ['300x250'] - } - }, - 'transactionId': 'bid_id_0_transaction_id' - } - ]; - - const bidRequestMultiPlacements = [ - { - 'bidId': 'bid_id_0', - 'bidder': 'retailspot', - 'placementCode': 'adunit/hb-0', - 'params': { - 'placement': 'placement_0' - }, - 'sizes': '300x250', - 'mediaTypes': - { 'banner': - {'sizes': ['300x250'] - } - }, - 'transactionId': 'bid_id_0_transaction_id' - }, - { - 'bidId': 'bid_id_1', - 'bidder': 'retailspot', - 'placementCode': 'adunit/hb-1', - 'params': { - 'placement': 'placement_1' - }, - 'sizes': [[300, 600]], - 'mediaTypes': - { 'banner': - {'sizes': ['300x600'] - } - }, - 'transactionId': 'bid_id_1_transaction_id' - }, - { - 'bidId': 'bid_id_2', - 'bidder': 'retailspot', - 'placementCode': 'adunit/hb-2', - 'params': {}, - 'sizes': '300x400', - 'transactionId': 'bid_id_2_transaction_id' - }, - { - 'bidId': 'bid_id_3', - 'bidder': 'retailspot', - 'placementCode': 'adunit/hb-3', - 'params': { - 'placement': 'placement_3' - }, - 'transactionId': 'bid_id_3_transaction_id' - } - ]; - - const requestDataOnePlacement = [ - { - 'bidId': 'bid_id_0', - 'placement': 'e622af275681965d3095808561a1e510', - 'width': 300, - 'height': 600 - } - ] - - const requestDataMultiPlacement = [ - { - 'bidId': 'bid_id_0', - 'placement': 'e622af275681965d3095808561a1e510', - 'width': 300, - 'height': 600 - }, - { - 'bidId': 'bid_id_1', - 'placement': 'e622af275681965d3095808561a1e510', - 'width': 400, - 'height': 250 - } - ] - - const testMetaObject = { - 'networkId': 123, - 'advertiserId': '3', - 'advertiserName': 'foobar', - 'advertiserDomains': ['foobar.com'], - 'brandId': '345', - 'brandName': 'Foo', - 'primaryCatId': '34', - 'secondaryCatIds': ['IAB-222', 'IAB-333'], - 'mediaType': 'banner' - }; - const admSample = "\u003cscript id=\"ayl-prebid-a11a121205932e75e622af275681965d\"\u003e\n(function(){\n\twindow.isPrebid = true\n\tvar prebidResults = /*PREBID*/{\"OnEvents\": {\"CLICK\": [{\"Kind\": \"PIXEL_URL\",\"Url\": \"https://testPixelCLICK.com/fake\"}],\"IMPRESSION\": [{\"Kind\": \"PIXEL_URL\",\"Url\": \"https://testPixelIMP.com/fake\"}, {\"Kind\": \"JAVASCRIPT_URL\",\"Url\": \"https://testJsIMP.com/fake.js\"}]},\"Disabled\": false,\"Attempt\": \"a11a121205932e75e622af275681965d\",\"ApiPrefix\": \"https://fo-api.omnitagjs.com/fo-api\",\"TrackingPrefix\": \"https://tracking.omnitagjs.com/tracking\",\"DynamicPrefix\": \"https://tag-dyn.omnitagjs.com/fo-dyn\",\"StaticPrefix\": \"https://fo-static.omnitagjs.com/fo-static\",\"BlobPrefix\": \"https://fo-api.omnitagjs.com/fo-api/blobs\",\"SspPrefix\": \"https://fo-ssp.omnitagjs.com/fo-ssp\",\"VisitorPrefix\": \"https://visitor.omnitagjs.com/visitor\",\"Trusted\": true,\"Placement\": \"e622af275681965d3095808561a1e510\",\"PlacementAccess\": \"ALL\",\"Site\": \"6e2df7a92203c3c7a25561ed63f25a27\",\"Lang\": \"EN\",\"SiteLogo\": null,\"HasSponsorImage\": true,\"ResizeIframe\": true,\"IntegrationConfig\": {\"Kind\": \"WIDGET\",\"Widget\": {\"ExtraStyleSheet\": \"\",\"Placeholders\": {\"Body\": {\"Color\": {\"R\": 77,\"G\": 21,\"B\": 82,\"A\": 100},\"BackgroundColor\": {\"R\": 255,\"G\": 255,\"B\": 255,\"A\": 100},\"FontFamily\": \"Lato\",\"Width\": \"100%\",\"Align\": \"\",\"BoxShadow\": true},\"CallToAction\": {\"Color\": {\"R\": 26,\"G\": 157,\"B\": 212,\"A\": 100}},\"Description\": {\"Length\": 130},\"Image\": {\"Width\": 600,\"Height\": 600,\"Lowres\": false,\"Raw\": false},\"Size\": {\"Height\": \"250px\",\"Width\": \"300px\"},\"Title\": {\"Color\": {\"R\": 219,\"G\": 181,\"B\": 255,\"A\": 100}}},\"Selector\": {\"Kind\": \"CSS\",\"Css\": \"#ayl-prebid-a11a121205932e75e622af275681965d\"},\"Insertion\": \"AFTER\",\"ClickFormat\": true,\"Creative20\": true,\"WidgetKind\": \"CREATIVE_TEMPLATE_4\"}},\"Legal\": \"Sponsored\",\"ForcedCampaign\": \"f1c80d4bb5643c222ae8de75e9b2f991\",\"ForcedTrack\": \"\",\"ForcedCreative\": \"\",\"ForcedSource\": \"\",\"DisplayMode\": \"DEFAULT\",\"Campaign\": \"f1c80d4bb5643c222ae8de75e9b2f991\",\"CampaignAccess\": \"ALL\",\"CampaignKind\": \"AD_TRAFFIC\",\"DataSource\": \"LOCAL\",\"DataSourceUrl\": \"\",\"DataSourceOnEventsIsolated\": false,\"DataSourceWithoutCookie\": false,\"Content\": {\"Preview\": {\"Thumbnail\": {\"Image\": {\"Kind\": \"EXTERNAL\",\"Data\": {\"External\": {\"Url\": \"https://tag-dyn.omnitagjs.com/fo-dyn/native/preview/image?key=fd4362d35bb174d6f1c80d4bb5643c22\\u0026kind=INTERNAL\\u0026ztop=0.000000\\u0026zleft=0.000000\\u0026zwidth=0.333333\\u0026zheight=1.000000\\u0026width=[width]\\u0026height=[height]\"}},\"ZoneTop\": 0,\"ZoneLeft\": 0,\"ZoneWidth\": 1,\"ZoneHeight\": 1,\"Smart\": false,\"NoTransform\": false,\"Quality\": \"NORMAL\"}},\"Text\": {\"CALLTOACTION\": \"Click here to learn more\",\"DESCRIPTION\": \"Considérant l'extrémité conjoncturelle, il serait bon d'anticiper toutes les voies de bon sens.\",\"SPONSOR\": \"Tested by\",\"TITLE\": \"Adserver Traffic Redirect Internal\"},\"Sponsor\": {\"Name\": \"QA Team\",\"Logo\": {\"Resource\": {\"Kind\": \"EXTERNAL\",\"Data\": {\"External\": {\"Url\": \"https://fo-static.omnitagjs.com/fo-static/native/images/info-ayl.svg\"}},\"ZoneTop\": 0,\"ZoneLeft\": 0,\"ZoneWidth\": 1,\"ZoneHeight\": 1,\"Smart\": false,\"NoTransform\": false,\"Quality\": \"NORMAL\"}}},\"Credit\": {\"Logo\": {\"Resource\": {\"Kind\": \"EXTERNAL\",\"Data\": {\"External\": {\"Url\": \"https://fo-static.omnitagjs.com/fo-static/native/images/info-ayl.png\"}},\"ZoneTop\": 0,\"ZoneLeft\": 0,\"ZoneWidth\": 1,\"ZoneHeight\": 1,\"Smart\": false,\"NoTransform\": false,\"Quality\": \"NORMAL\"}},\"Url\": \"https://blobs.omnitagjs.com/adchoice/\"}},\"Landing\": {\"Url\": \"https://www.w3.org/People/mimasa/test/xhtml/entities/entities-11.xhtml#lat1\",\"LegacyTracking\": false},\"ViewButtons\": {\"Close\": {\"Skip\": 6000}},\"InternalContentFields\": {\"AnimatedImage\": false}},\"AdDomain\": \"retailspot.com\",\"Opener\": \"REDIRECT\",\"PerformUITriggers\": [\"CLICK\"],\"RedirectionTarget\": \"TAB\"}/*PREBID*/;\n\tvar insertAds = function insertAds() {\insertAds();\n\t}\n})();\n\u003c/script\u003e"; - const responseWithSinglePlacement = [ - { - 'requestId': 'bid_id_0', - 'placement': 'placement_0', - 'ad': admSample, - 'cpm': 0.5, - 'height': 250, - 'width': 300, - 'meta': testMetaObject, - 'mediaType': 'banner' - } - ]; - - const responseWithSingleVideo = [{ - 'requestId': 'bid_id_0', - 'placement': 'placement_0', - 'vastXml': 'PFZBU1Q+RW1wdHkgc2FtcGxlPC92YXN0Pg==', - 'cpm': 0.5, - 'height': 300, - 'width': 530, - 'mediaType': 'video', - 'creativeId': 'testvideo123', - 'netRevenue': true, - 'currency': 'USD', - 'adId': 'fakeAdID', - 'dealId': 'fakeDealId' - }]; - - const videoResult = [{ - bidderCode: 'retailspot', - cpm: 0.5, - creativeId: 'testvideo123', - currency: 'USD', - height: 300, - netRevenue: true, - requestId: 'bid_id_0', - ttl: 3600, - mediaType: 'video', - meta: { - advertiserDomains: ['retail-spot.io'] - }, - vastXml: 'Empty sample', - width: 530, - adId: 'fakeAdID', - dealId: 'fakeDealId' - }]; - - const responseWithMultiplePlacements = [ - { - 'requestId': 'bid_id_0', - 'mediaType': 'banner', - 'placement': 'placement_0', - 'ad': 'placement_0', - 'cpm': 0.5, - 'height': 0, // test with wrong value - 'width': 300, - }, - { - 'requestId': 'bid_id_1', - 'mediaType': 'banner', - 'placement': 'placement_1', - 'ad': 'placement_1', - 'cpm': 0.6, - 'height': 250 - // 'width' test with missing value - } - ]; - const adapter = newBidder(spec); - - const DEV_URL = 'http://localhost:3030/'; - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidId': 'bid_id_1', - 'bidder': 'retailspot', - 'placementCode': 'adunit/hb-1', - 'params': { - 'placement': 'placement_1' - }, - 'sizes': [[300, 600]], - 'transactionId': 'bid_id_1_transaction_id' - }; - - const bidWSize = { - 'bidId': 'bid_id_1', - 'bidder': 'retailspot', - 'placementCode': 'adunit/hb-1', - 'params': { - 'placement': 'placement_1', - 'size': [250, 300], - }, - 'transactionId': 'bid_id_1_transaction_id' - }; - - it('should return true when required params found', function () { - expect(!!spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when required params found with size in bid params', function () { - expect(!!spec.isBidRequestValid(bidWSize)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.sizes; - - expect(!!spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'placement': 0 - }; - expect(!!spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('should add gdpr/usp consent information to the request', function () { - const consentString = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - const uspConsentData = '1YCC'; - const bidderRequest = { - 'auctionId': '1d1a030790a475', - 'bidderRequestId': '22edbae2733bf6', - 'timeout': 3000, - 'gdprConsent': { - consentString: consentString, - gdprApplies: true - }, - 'uspConsent': uspConsentData - }; - - bidderRequest.Bids = bidRequestWithSinglePlacement; - - const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdprConsent).to.exist; - expect(payload.gdprConsent.consentString).to.exist.and.to.equal(consentString); - expect(payload.uspConsent).to.exist.and.to.equal(uspConsentData); - }); - - it('sends bid request to endpoint with single placement', function () { - bidderRequest.Bids = bidRequestWithSinglePlacement; - - const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest); - const payload = JSON.parse(request.data); - - expect(request.url).to.contain('https://hbapi.retailspotads.com/'); - expect(request.method).to.equal('POST'); - - expect(payload).to.deep.equal(bidderRequest); - }); - - it('sends bid request to endpoint with single placement multiple mediatype', function () { - bidderRequest.Bids = bidRequestWithMultipleMediatype; - const request = spec.buildRequests(bidRequestWithSinglePlacement, bidderRequest); - const payload = JSON.parse(request.data); - - expect(request.url).to.contain('https://hbapi.retailspotads.com/'); - expect(request.method).to.equal('POST'); - - expect(payload).to.deep.equal(bidderRequest); - }); - - it('sends bid request to endpoint with multiple placements', function () { - bidderRequest.Bids = bidRequestMultiPlacements; - const request = spec.buildRequests(bidRequestMultiPlacements, bidderRequest); - const payload = JSON.parse(request.data); - - expect(request.url).to.contain('https://hbapi.retailspotads.com/'); - expect(request.method).to.equal('POST'); - - expect(payload).to.deep.equal(bidderRequest); - }); - - it('sends bid request to endpoint setted by parameters', function () { - const request = spec.buildRequests(bidRequestWithDevPlacement, bidderRequest); - expect(request.url).to.contain(DEV_URL); - }); - }); - // - describe('interpretResponse', function () { - let serverResponse; - - beforeEach(function () { - serverResponse = { - body: {} - } - }); - - it('handles nobid responses', function () { - const response = [{ - requestId: '123dfsdf', - placement: '12df1' - }]; - serverResponse.body = response; - const result = spec.interpretResponse(serverResponse, []); - expect(result).deep.equal([]); - }); - - it('receive reponse with single placement', function () { - serverResponse.body = responseWithSinglePlacement; - const result = spec.interpretResponse(serverResponse, {data: '{"bids":' + JSON.stringify(requestDataOnePlacement) + '}'}); - - expect(result.length).to.equal(1); - expect(result[0].cpm).to.equal(0.5); - expect(result[0].ad).to.equal(admSample); - expect(result[0].width).to.equal(300); - expect(result[0].height).to.equal(250); - expect(result[0].meta).to.deep.equal(testMetaObject); - }); - - it('receive reponse with multiple placement', function () { - serverResponse.body = responseWithMultiplePlacements; - const result = spec.interpretResponse(serverResponse, {data: '{"bids":' + JSON.stringify(requestDataMultiPlacement) + '}'}); - - expect(result.length).to.equal(2); - - expect(result[0].cpm).to.equal(0.5); - expect(result[0].ad).to.equal('placement_0'); - expect(result[0].width).to.equal(300); - expect(result[0].height).to.equal(600); - - expect(result[1].cpm).to.equal(0.6); - expect(result[1].ad).to.equal('placement_1'); - expect(result[1].width).to.equal(400); - expect(result[1].height).to.equal(250); - }); - - it('receive Vast reponse with Video ad', function () { - serverResponse.body = responseWithSingleVideo; - const result = spec.interpretResponse(serverResponse, {data: '{"bids":' + JSON.stringify(sentBidVideo) + '}'}); - - expect(result.length).to.equal(1); - expect(result).to.deep.equal(videoResult); - }); - }); -}); diff --git a/test/spec/modules/revcontentBidAdapter_spec.js b/test/spec/modules/revcontentBidAdapter_spec.js deleted file mode 100644 index 6d660d1b3..000000000 --- a/test/spec/modules/revcontentBidAdapter_spec.js +++ /dev/null @@ -1,366 +0,0 @@ -// jshint esversion: 6, es3: false, node: true -import {assert, expect} from 'chai'; -import {spec} from 'modules/revcontentBidAdapter.js'; -import { NATIVE } from 'src/mediaTypes.js'; -import { config } from 'src/config.js'; -import * as utils from 'src/utils.js'; - -describe('revcontent adapter', function () { - let serverResponse, bidRequest, bidResponses; - const bids = []; - - describe('isBidRequestValid', function () { - const bid = { - bidder: 'revcontent', - nativeParams: {}, - params: { - size: {width: 300, height: 250}, - apiKey: '8a33fa9cf220ae685dcc3544f847cdda858d3b1c', - userId: 673, - domain: 'test.com', - endpoint: 'trends-s0.revcontent.com' - } - }; - - it('should return true when required params found', function () { - assert(spec.isBidRequestValid(bid)); - }); - - it('should return false when required params are missing', function () { - bid.params.apiKey = undefined; - assert.isFalse(spec.isBidRequestValid(bid)); - }); - }); - - describe('buildRequests', function () { - it('should send request with correct structure', function () { - const validBidRequests = [{ - bidder: 'revcontent', - nativeParams: {}, - params: { - size: {width: 300, height: 250}, - apiKey: '8a33fa9cf220ae685dcc3544f847cdda858d3b1c', - userId: 673, - widgetId: 33861, - endpoint: 'trends-s0.revcontent.com' - } - }]; - let request = spec.buildRequests(validBidRequests, {refererInfo: {page: 'page'}}); - request = request[0]; - assert.equal(request.method, 'POST'); - assert.equal(request.url, 'https://trends-s0.revcontent.com/rtb?apiKey=8a33fa9cf220ae685dcc3544f847cdda858d3b1c&userId=673&widgetId=33861'); - assert.deepEqual(request.options, {contentType: 'application/json'}); - assert.ok(request.data); - }); - - it('should have default request structure', function () { - const keys = 'method,options,url,data,bid'.split(','); - const validBidRequests = [{ - bidder: 'revcontent', - nativeParams: {}, - params: { - size: {width: 300, height: 250}, - apiKey: '8a33fa9cf220ae685dcc3544f847cdda858d3b1c', - userId: 673, - domain: 'test.com', - endpoint: 'trends-s0.revcontent.com' - } - }]; - let request = spec.buildRequests(validBidRequests, {refererInfo: {page: 'page'}}); - - request = request[0]; - const data = Object.keys(request); - - assert.deepEqual(keys, data); - }); - - it('should send info about device and unique bidfloor', function () { - const validBidRequests = [{ - bidder: 'revcontent', - nativeParams: {}, - params: { - size: {width: 300, height: 250}, - apiKey: '8a33fa9cf220ae685dcc3544f847cdda858d3b1c', - userId: 673, - domain: 'test.com', - endpoint: 'trends-s0.revcontent.com', - bidfloor: 0.05 - } - }]; - let request = spec.buildRequests(validBidRequests, {refererInfo: {page: 'page'}}); - request = JSON.parse(request[0].data); - assert.equal(request.imp[0].bidfloor, 0.05); - assert.equal(request.device.ua, navigator.userAgent); - }); - - it('should send info about device and use getFloor', function () { - const validBidRequests = [{ - bidder: 'revcontent', - nativeParams: {}, - params: { - size: {width: 300, height: 250}, - apiKey: '8a33fa9cf220ae685dcc3544f847cdda858d3b1c', - userId: 673, - domain: 'test.com', - endpoint: 'trends-s0.revcontent.com', - bidfloor: 0.05 - } - }]; - validBidRequests[0].getFloor = () => { - return { - floor: 0.07, - currency: 'USD' - }; - }; - let request = spec.buildRequests(validBidRequests, {refererInfo: {page: 'page'}}); - request = JSON.parse(request[0].data); - assert.equal(request.imp[0].bidfloor, 0.07); - assert.equal(request.device.ua, navigator.userAgent); - }); - - it('should send info about the site and default bidfloor', function () { - const validBidRequests = [{ - bidder: 'revcontent', - nativeParams: { - image: { - required: false - }, - 'title': { - required: false, - len: 140 - }, - clickUrl: { - required: false - }, - sponsoredBy: { - id: 5, - name: 'data', - type: 1 - } - }, - params: { - size: {width: 300, height: 250}, - apiKey: '8a33fa9cf220ae685dcc3544f847cdda858d3b1c', - userId: 673, - domain: 'test.com', - endpoint: 'trends-s0.revcontent.com' - } - }]; - const refererInfo = {page: 'page'}; - let request = spec.buildRequests(validBidRequests, {refererInfo}); - - request = JSON.parse(request[0].data); - assert.equal(request.imp[0].bidfloor, 0.1); - assert.deepEqual(request.site, { - domain: 'test.com', - page: 'page', - publisher: {id: 673, domain: 'test.com'} - }); - }); - }); - - describe('interpretResponse', function () { - it('should return if no body in response', function () { - const serverResponse = {}; - const bidRequest = {}; - - const result = spec.interpretResponse(serverResponse, bidRequest); - assert.equal(result.length, 0); - }); - - const serverResponse = { - body: { - id: '5d61ca27-1b7a-4d5a-90ad-bbfc93e53f58', - seatbid: [ - { - bid: [ - { - id: '6bbe3eed-f443-4e2b-a8da-57fd6327b37d', - impid: '1', - price: 0.1, - crid: '4162547', - nurl: 'https://trends-s0.revcontent.com/push/track/?p=${AUCTION_PRICE}&d=nTCdHIfsgKOLFuV7DS1LF%2FnTk5HiFduGU65BgKgB%2BvKyG9YV7ceQWN76HMbBE0C6gwQeXUjravv3Hq5x9TT8CM6r2oUNgkGC9mhgv2yroTH9i3cSoH%2BilxyY19fMXFirtBz%2BF%2FEXKi4bsNh%2BDMPfj0L4elo%2FJEZmx4nslvOneJJjsFjJJtUJc%2F3UPivOisSCa%2B36mAgFQqt%2FSWBriYB%2BVAufz70LaGspF6T6jDzuIyVFJUpLhZVDtLRSJEzh7Lyzzw1FmYarp%2FPg0gZDY48aDdjw5A3Tlj%2Bap0cPHLDprNOyF0dmHDn%2FOVJEDRTWvrQ2JNK1t%2Fg1bGHIih0ec6XBVIBNurqRpLFBuUY6LgXCt0wRZWTByTEZ8AEv8IoYVILJAL%2BXL%2F9IyS4eTcdOUfn5X7gT8QBghCrAFrsCg8ZXKgWddTEXbpN1lU%2FzHdI5eSHkxkJ6WcYxSkY9PyripaIbmKiyb98LQMgTD%2B20RJO5dAmXTQTAcauw6IUPTjgSPEU%2Bd6L5Txd3CM00Hbd%2Bw1bREIQcpKEmlMwrRSwe4bu1BCjlh5A9gvU9Xc2sf7ekS3qPPmtp059r5IfzdNFQJB5aH9HqeDEU%2FxbMHx4ggMgojLBBL1fKrCKLAteEDQxd7PVmFJv7GHU2733vt5TnjKiEhqxHVFyi%2B0MIYMGIziM5HfUqfq3KUf%2F%2FeiCtJKXjg7FS6hOambdimSt7BdGDIZq9QECWdXsXcQqqVLwli27HYDMFVU3TWWRyjkjbhnQID9gQJlcpwIi87jVAODb6qP%2FKGQ%3D%3D', - adm: '{"ver":"1.1","assets":[{"id":3,"required":1,"img":{"url":"//img.revcontent.com/?url=https://revcontent-p0.s3.amazonaws.com/content/images/15761052960288727821.jpg&static=true"}},{"id":0,"required":1,"title":{"text":"Do You Eat Any of These Craving-trigger Foods?"}},{"id":5,"required":1,"data":{"value":""}}],"link":{"url":"https://trends-s0.revcontent.com/click.php?d=A7EVbNYBVyonty19Ak08zCr9J54qg%2Bmduq6p0Zyn5%2F%2Bapm4deUo9VAXmOGEIbUBf6i7m3%2F%2FWJm%2FzTha8SJ%2Br9MZL9jhhUxDeiKb6aRY1biLrvr6tFUd1phvtKqVmPd76l9VBLFMxS1brSzKjRCJlIGmyGJg7ueFvxpE9X%2BpHmdbE2uqUdRC49ENO3XZyHCCKMAZ8XD29fasX9Kli9mKpZTqw8vayFlXbVYSUwB8wfSwCt1sIUrt0aICYc0jcyWU3785GTS1xXzQj%2FIVszFYYrdTWd%2BDijjNZtFny0OomPHp8lRy5VcQVCuLpw0Fks4myvsE38XcNvs4wO3tWTNrI%2BMqcW1%2BD2OnMSq5nN5FCbmi2ly%2F1LbN9fibaFvW%2FQbzQhN9ZsAwmhm409UTtdmSA6hd96vDxDWLeUJhVO3UQyI0yq2TtVnB9tEICD8mZNWwYehOab%2BQ1EWmTerF6ZCDx8RyZus1UrsDfRwvTCyUjCmkZhmeo4QVJkpPy6QobCsngSaxkkKhH%2Fb7coZyBXXEt3ORoYBLUbfRO6nR8GdIt8413vrYr4gTAroh46VcWK0ls0gFNe2u3%2FqP%2By1yLKbzDVaR%2Fa02G%2Biiqbw86sCYfsy7qK9atyjNTm8RkH6JLESUzxc6IEazu4iwHKGnu5phTacmseXCi8y9Y5AdBZn8VnLP%2F2a%2FyAqq93xEH%2BIrkAdhGRY1tY39rBYAtvH%2FVyNFZcong%2FutUMYbp0WhDNyfl6iWxmpE28Cx9KDcqXss0NIwQm0AWeu8ogJCIG3faAkm5PdFsUdf2X9h3HuFDbnbvnXW27ml6z9GykEzv%2F8aSZlMZ"}}' - } - ] - } - ], - bidid: '7f729368-edb2-427a-bde7-a55b3bf8837c' - }, - headers: {} - }; - - const bidRequest = { - method: 'POST', - options: { - contentType: 'application/json' - }, - url: 'https://trends-s0.revcontent.com/rtb?apiKey=8a33fa9cf220ae685dcc3544f847cdda858d3b1c&userId=673', - data: '{"id":"5d61ca27-1b7a-4d5a-90ad-bbfc93e53f58","imp":[{"id":1,"bidderRequestId":"14e4dab7b5396e8","auctionId":"5d61ca27-1b7a-4d5a-90ad-bbfc93e53f58","transactionId":"69e69abf-a3ea-484d-a81c-d48dd0d5eaa3","native":{"request":{"ver":"1.1","context":2,"contextsubtype":21,"plcmttype":4,"plcmtcnt":4,"assets":[{"required":0,"id":3,"img":{"type":3}},{"required":0,"id":0,"title":{"len":140}},{"required":0,"id":5,"data":{"type":1}}]},"ver":"1.1","battr":[1,3,8,11,17]},"instl":0,"bidfloor":0.1,"secure":"1"}],"site":{"domain":"test.com","page":"https://feudfun.com/test22/revcontent_example.php","cat":["IAB17"],"publisher":{"id":673,"domain":"test.com"}},"device":{"ua":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:71.0) Gecko/20100101 Firefox/71.0","language":"en"},"user":{"id":1},"at":2,"bcat":["IAB24","IAB25","IAB25-1","IAB25-2","IAB25-3","IAB25-4","IAB25-5","IAB25-6","IAB25-7","IAB26","IAB26-1","IAB26-2","IAB26-3","IAB26-4"]}', - bid: [ - { - bidder: 'revcontent', - params: { - size: { - width: 300, - height: 250 - }, - apiKey: '8a33fa9cf220ae685dcc3544f847cdda858d3b1c', - userId: 673, - domain: 'test.com', - endpoint: 'trends-s0.revcontent.com' - }, - crumbs: { - pubcid: '7a0b4adc-c109-49f0-aadc-4a4b62ebe269' - }, - nativeParams: { - image: { - required: false - }, - 'title': { - required: false, - len: 140 - }, - clickUrl: { - required: false - }, - sponsoredBy: { - id: 5, - name: 'data', - type: 1 - } - }, - mediaTypes: { - native: { - image: { - required: false - }, - title: { - required: false, - len: 140 - }, - clickUrl: { - required: false - }, - sponsoredBy: { - id: 5, - name: 'data', - type: 1 - } - } - }, - adUnitCode: '/19968336/header-bid-tag-1', - transactionId: '69e69abf-a3ea-484d-a81c-d48dd0d5eaa3', - sizes: [], - bidId: '294a7f446202848', - bidderRequestId: '14e4dab7b5396e8', - auctionId: '5d61ca27-1b7a-4d5a-90ad-bbfc93e53f58', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - } - ] - }; - - it('should set correct native params', function () { - const result = spec.interpretResponse(serverResponse, bidRequest)[0]; - - assert.equal(result.mediaType, 'native'); - assert.equal(result.requestId, '294a7f446202848'); - assert.equal(result.cpm, '0.1'); - assert.equal(result.creativeId, '4162547'); - }); - - it('validate template 728x90', function () { - bidRequest.bid[0].params.size.width = 728; - bidRequest.bid[0].params.size.height = 90; - - const result = spec.interpretResponse(serverResponse, bidRequest)[0]; - assert.equal(result.mediaType, 'native'); - assert.equal(result.requestId, '294a7f446202848'); - assert.equal(result.cpm, '0.1'); - assert.equal(result.creativeId, '4162547'); - }); - - it('validate template 300x600', function () { - bidRequest.bid[0].params.size.width = 300; - bidRequest.bid[0].params.size.height = 600; - - const result = spec.interpretResponse(serverResponse, bidRequest)[0]; - assert.equal(result.mediaType, 'native'); - assert.equal(result.requestId, '294a7f446202848'); - assert.equal(result.cpm, '0.1'); - assert.equal(result.creativeId, '4162547'); - }); - - it('validate template custom template', function () { - bidRequest.bid[0].params.template = '

{title}

SEE MORE
'; - - const result = spec.interpretResponse(serverResponse, bidRequest)[0]; - assert.equal(result.mediaType, 'native'); - assert.equal(result.requestId, '294a7f446202848'); - assert.equal(result.cpm, '0.1'); - assert.equal(result.creativeId, '4162547'); - }); - - it('validate template custom invalid template', function () { - bidRequest.bid[0].params.size.width = 100; - bidRequest.bid[0].params.size.height = 200; - - const result = spec.interpretResponse(serverResponse, bidRequest)[0]; - assert.equal(result.mediaType, 'native'); - assert.equal(result.requestId, '294a7f446202848'); - assert.equal(result.cpm, '0.1'); - assert.equal(result.creativeId, '4162547'); - }); - - it('should return empty when there is no bids in response', function () { - const serverResponse = { - body: { - id: null, - bidid: null, - seatbid: [{bid: []}], - cur: 'USD' - } - }; - const bidRequest = { - data: '{}', - bids: [{bidId: 'bidId1'}] - }; - const result = spec.interpretResponse(serverResponse, bidRequest)[0]; - assert.ok(!result); - }); - }); - - describe('onBidWon', function () { - it('default bid won', function () { - const bid = { - nurl: 'https://trends-s0.revcontent.com/push/track/?p=${AUCTION_PRICE}&d=nTCdHIfsgKOLFuV7DS1LF%2FnTk5HiFduGU65BgKgB%2BvKyG9YV7ceQWN76HMbBE0C6gwQeXUjravv3Hq5x9TT8CM6r2oUNgkGC9mhgv2yroTH9i3cSoH%2BilxyY19fMXFirtBz%2BF%2FEXKi4bsNh%2BDMPfj0L4elo%2FJEZmx4nslvOneJJjsFjJJtUJc%2F3UPivOisSCa%2B36mAgFQqt%2FSWBriYB%2BVAufz70LaGspF6T6jDzuIyVFJUpLhZVDtLRSJEzh7Lyzzw1FmYarp%2FPg0gZDY48aDdjw5A3Tlj%2Bap0cPHLDprNOyF0dmHDn%2FOVJEDRTWvrQ2JNK1t%2Fg1bGHIih0ec6XBVIBNurqRpLFBuUY6LgXCt0wRZWTByTEZ8AEv8IoYVILJAL%2BXL%2F9IyS4eTcdOUfn5X7gT8QBghCrAFrsCg8ZXKgWddTEXbpN1lU%2FzHdI5eSHkxkJ6WcYxSkY9PyripaIbmKiyb98LQMgTD%2B20RJO5dAmXTQTAcauw6IUPTjgSPEU%2Bd6L5Txd3CM00Hbd%2Bw1bREIQcpKEmlMwrRSwe4bu1BCjlh5A9gvU9Xc2sf7ekS3qPPmtp059r5IfzdNFQJB5aH9HqeDEU%2FxbMHx4ggMgojLBBL1fKrCKLAteEDQxd7PVmFJv7GHU2733vt5TnjKiEhqxHVFyi%2B0MIYMGIziM5HfUqfq3KUf%2F%2FeiCtJKXjg7FS6hOambdimSt7BdGDIZq9QECWdXsXcQqqVLwli27HYDMFVU3TWWRyjkjbhnQID9gQJlcpwIi87jVAODb6qP%2FKGQ%3D%3D', - cpm: '0.1' - }; - const result = spec.onBidWon(bid); - assert.ok(result); - }); - }); - - describe('onBidWon', function() { - const bid = { - nurl: 'https://trends-s0.revcontent.com/push/track/?p=${AUCTION_PRICE}&d=nTCdHIfsgKOLFuV7DS1LF%2FnTk5HiFduGU65BgKgB%2BvKyG9YV7ceQWN76HMbBE0C6gwQeXUjravv3Hq5x9TT8CM6r2oUNgkGC9mhgv2yroTH9i3cSoH%2BilxyY19fMXFirtBz%2BF%2FEXKi4bsNh%2BDMPfj0L4elo%2FJEZmx4nslvOneJJjsFjJJtUJc%2F3UPivOisSCa%2B36mAgFQqt%2FSWBriYB%2BVAufz70LaGspF6T6jDzuIyVFJUpLhZVDtLRSJEzh7Lyzzw1FmYarp%2FPg0gZDY48aDdjw5A3Tlj%2Bap0cPHLDprNOyF0dmHDn%2FOVJEDRTWvrQ2JNK1t%2Fg1bGHIih0ec6XBVIBNurqRpLFBuUY6LgXCt0wRZWTByTEZ8AEv8IoYVILJAL%2BXL%2F9IyS4eTcdOUfn5X7gT8QBghCrAFrsCg8ZXKgWddTEXbpN1lU%2FzHdI5eSHkxkJ6WcYxSkY9PyripaIbmKiyb98LQMgTD%2B20RJO5dAmXTQTAcauw6IUPTjgSPEU%2Bd6L5Txd3CM00Hbd%2Bw1bREIQcpKEmlMwrRSwe4bu1BCjlh5A9gvU9Xc2sf7ekS3qPPmtp059r5IfzdNFQJB5aH9HqeDEU%2FxbMHx4ggMgojLBBL1fKrCKLAteEDQxd7PVmFJv7GHU2733vt5TnjKiEhqxHVFyi%2B0MIYMGIziM5HfUqfq3KUf%2F%2FeiCtJKXjg7FS6hOambdimSt7BdGDIZq9QECWdXsXcQqqVLwli27HYDMFVU3TWWRyjkjbhnQID9gQJlcpwIi87jVAODb6qP%2FKGQ%3D%3D', - cpm: '0.1' - }; - - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - - afterEach(function() { - utils.triggerPixel.restore(); - }); - - it('make sure only 1 ajax call is happening', function() { - spec.onBidWon(bid); - expect(utils.triggerPixel.calledOnce).to.equal(true); - }); - }); -}); diff --git a/test/spec/modules/rhythmoneBidAdapter_spec.js b/test/spec/modules/rhythmoneBidAdapter_spec.js deleted file mode 100644 index 77ae6266e..000000000 --- a/test/spec/modules/rhythmoneBidAdapter_spec.js +++ /dev/null @@ -1,763 +0,0 @@ -import {spec} from '../../../modules/rhythmoneBidAdapter.js'; -import * as utils from '../../../src/utils.js'; -import * as sinon from 'sinon'; - -var r1adapter = spec; - -describe('rhythmone adapter tests', function () { - beforeEach(function() { - this.defaultBidderRequest = { - 'refererInfo': { - 'ref': 'Reference Page', - 'stack': [ - 'aodomain.dvl', - 'page.dvl' - ] - } - }; - }); - - describe('Verify 1.0 POST Banner Bid Request', function () { - it('buildRequests works', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - 'zone': 'myzone', - 'path': 'mypath' - }, - 'mediaType': 'banner', - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'sizes': [[300, 250]], - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - - expect(bidRequest.url).to.have.string('https://tag.1rx.io/rmp/myplacement/0/mypath?z=myzone&hbv='); - expect(bidRequest.method).to.equal('POST'); - const openrtbRequest = JSON.parse(bidRequest.data); - expect(openrtbRequest.site).to.not.equal(null); - expect(openrtbRequest.site.ref).to.equal('Reference Page'); - expect(openrtbRequest.device).to.not.equal(null); - expect(openrtbRequest.device.ua).to.equal(navigator.userAgent); - expect(openrtbRequest.device.dnt).to.equal(0); - expect(openrtbRequest.imp[0].banner).to.not.equal(null); - expect(openrtbRequest.imp[0].banner.format[0].w).to.equal(300); - expect(openrtbRequest.imp[0].banner.format[0].h).to.equal(250); - expect(openrtbRequest.imp[0].ext.bidder.zone).to.equal('myzone'); - expect(openrtbRequest.imp[0].ext.bidder.path).to.equal('mypath'); - }); - - it('interpretResponse works', function() { - var bidList = { - 'body': [ - { - 'impid': 'div-gpt-ad-1438287399331-0', - 'w': 300, - 'h': 250, - 'adm': '
My Compelling Ad
', - 'price': 1, - 'crid': 'cr-cfy24' - } - ] - }; - - var bannerBids = r1adapter.interpretResponse(bidList); - - expect(bannerBids.length).to.equal(1); - const bid = bannerBids[0]; - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creativeId).to.equal('cr-cfy24'); - expect(bid.currency).to.equal('USD'); - expect(bid.netRevenue).to.equal(true); - expect(bid.cpm).to.equal(1.0); - expect(bid.ttl).to.equal(350); - }); - }); - - describe('Verify POST Video Bid Request', function() { - it('buildRequests works', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - 'zone': 'myzone', - 'path': 'mypath' - }, - 'mediaTypes': { - 'video': { - 'playerSize': [640, 480], - 'context': 'instream' - } - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-1', - 'sizes': [ - [300, 250] - ], - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - - expect(bidRequest.url).to.have.string('https://tag.1rx.io/rmp/myplacement/0/mypath?z=myzone&hbv='); - expect(bidRequest.method).to.equal('POST'); - const openrtbRequest = JSON.parse(bidRequest.data); - expect(openrtbRequest.site).to.not.equal(null); - expect(openrtbRequest.device).to.not.equal(null); - expect(openrtbRequest.device.ua).to.equal(navigator.userAgent); - expect(openrtbRequest.device).to.have.property('dnt'); - expect(openrtbRequest.imp[0].video).to.not.equal(null); - expect(openrtbRequest.imp[0].video.w).to.equal(640); - expect(openrtbRequest.imp[0].video.h).to.equal(480); - expect(openrtbRequest.imp[0].video.mimes[0]).to.equal('video/mp4'); - expect(openrtbRequest.imp[0].video.protocols).to.eql([2, 3, 5, 6]); - expect(openrtbRequest.imp[0].video.startdelay).to.equal(0); - expect(openrtbRequest.imp[0].video.skip).to.equal(0); - expect(openrtbRequest.imp[0].video.playbackmethod).to.eql([1, 2, 3, 4]); - expect(openrtbRequest.imp[0].video.delivery[0]).to.equal(1); - expect(openrtbRequest.imp[0].video.api).to.eql([1, 2, 5]); - }); - - it('interpretResponse works', function() { - var bidList = { - 'body': [ - { - 'impid': 'div-gpt-ad-1438287399331-1', - 'price': 1, - 'nurl': 'https://testdomain/rmp/placementid/0/path?reqId=1636037', - 'adomain': [ - 'test.com' - ], - 'cid': '467415', - 'crid': 'cr-vid', - 'w': 800, - 'h': 600 - } - ] - }; - - var videoBids = r1adapter.interpretResponse(bidList); - - expect(videoBids.length).to.equal(1); - const bid = videoBids[0]; - expect(bid.width).to.equal(800); - expect(bid.height).to.equal(600); - expect(bid.vastUrl).to.equal('https://testdomain/rmp/placementid/0/path?reqId=1636037'); - expect(bid.meta.advertiserDomains).to.deep.equal(['test.com']); - expect(bid.mediaType).to.equal('video'); - expect(bid.creativeId).to.equal('cr-vid'); - expect(bid.currency).to.equal('USD'); - expect(bid.netRevenue).to.equal(true); - expect(bid.cpm).to.equal(1.0); - expect(bid.ttl).to.equal(600); - }); - }); - - describe('Verify Multi-Format ads and Multiple Size Bid Request', function() { - it('buildRequests works', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - 'zone': 'myzone', - 'path': 'mypath', - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 250], - [300, 600] - ] - }, - 'video': { - 'playerSize': [[640, 480]], - 'context': 'instream' - } - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-5', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - - const openrtbRequest = JSON.parse(bidRequest.data); - expect(openrtbRequest.site).to.not.equal(null); - expect(openrtbRequest.site.ref).to.equal('Reference Page'); - expect(openrtbRequest.device).to.not.equal(null); - expect(openrtbRequest.device.ua).to.equal(navigator.userAgent); - expect(openrtbRequest.device).to.have.property('dnt'); - expect(openrtbRequest.imp[0].video).to.not.equal(null); - expect(openrtbRequest.imp[0].video.w).to.equal(640); - expect(openrtbRequest.imp[0].video.h).to.equal(480); - expect(openrtbRequest.imp[0].video.mimes[0]).to.equal('video/mp4'); - expect(openrtbRequest.imp[0].video.protocols).to.eql([2, 3, 5, 6]); - expect(openrtbRequest.imp[0].video.startdelay).to.equal(0); - expect(openrtbRequest.imp[0].video.skip).to.equal(0); - expect(openrtbRequest.imp[0].video.playbackmethod).to.eql([1, 2, 3, 4]); - expect(openrtbRequest.imp[0].video.delivery[0]).to.equal(1); - expect(openrtbRequest.imp[0].video.api).to.eql([1, 2, 5]); - expect(openrtbRequest.imp[0].banner).to.not.equal(null); - expect(openrtbRequest.imp[0].banner.format[0].w).to.equal(300); - expect(openrtbRequest.imp[0].banner.format[0].h).to.equal(250); - expect(openrtbRequest.imp[0].banner.format[1].w).to.equal(300); - expect(openrtbRequest.imp[0].banner.format[1].h).to.equal(600); - expect(openrtbRequest.imp[0].ext.bidder.zone).to.equal('myzone'); - expect(openrtbRequest.imp[0].ext.bidder.path).to.equal('mypath'); - }); - - it('interpretResponse works', function() { - var bidList = { - 'body': { - 'id': '1e810245dd1779', - 'seatbid': [ - { - 'bid': [ - { - 'impid': 'div-gpt-ad-1438287399331-5', - 'price': 1, - 'nurl': 'https://testdomain/rmp/placementid/0/path?reqId=1636037', - 'adomain': [ - 'test.com' - ], - 'cid': '467415', - 'crid': 'cr-vid', - 'w': 800, - 'h': 600 - } - ] - } - ] - } - }; - - var forRMPMultiFormatResponse = r1adapter.interpretResponse(bidList); - - expect(forRMPMultiFormatResponse.length).to.equal(1); - const bid = forRMPMultiFormatResponse[0]; - expect(bid.width).to.equal(800); - expect(bid.height).to.equal(600); - expect(bid.vastUrl).to.equal('https://testdomain/rmp/placementid/0/path?reqId=1636037'); - expect(bid.mediaType).to.equal('video'); - expect(bid.creativeId).to.equal('cr-vid'); - expect(bid.currency).to.equal('USD'); - expect(bid.netRevenue).to.equal(true); - expect(bid.cpm).to.equal(1.0); - expect(bid.ttl).to.equal(600); - }); - }); - - describe('misc buildRequests', function() { - it('should send GDPR Consent data to RhythmOne tag', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - 'zone': 'myzone', - 'path': 'mypath' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]] - } - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-3', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var consentString = 'testConsentString'; - var gdprBidderRequest = this.defaultBidderRequest; - gdprBidderRequest.gdprConsent = { - 'gdprApplies': true, - 'consentString': consentString - }; - - var bidRequest = r1adapter.buildRequests(bidRequestList, gdprBidderRequest); - - const openrtbRequest = JSON.parse(bidRequest.data); - expect(openrtbRequest.user.ext.consent).to.equal(consentString); - expect(openrtbRequest.regs.ext.gdpr).to.equal(true); - }); - - it('prefer 2.0 sizes', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - 'zone': 'myzone', - 'path': 'mypath' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 600]] - } - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'sizes': [[300, 250]], - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - - const openrtbRequest = JSON.parse(bidRequest.data); - expect(openrtbRequest.imp[0].banner.format[0].w).to.equal(300); - expect(openrtbRequest.imp[0].banner.format[0].h).to.equal(600); - }); - - it('does not return request for invalid banner size configuration', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - 'zone': 'myzone', - 'path': 'mypath' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300]] - } - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - expect(bidRequest.method).to.be.undefined; - }); - - it('does not return request for missing banner size configuration', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - 'zone': 'myzone', - 'path': 'mypath' - }, - 'mediaTypes': { - 'banner': {} - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - expect(bidRequest.method).to.be.undefined; - }); - - it('reject bad sizes', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - 'zone': 'myzone', - 'path': 'mypath' - }, - 'mediaTypes': { - 'banner': {'sizes': [['400', '500'], ['4n0', '5g0']]} - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - const openrtbRequest = JSON.parse(bidRequest.data); - expect(openrtbRequest.imp[0].banner.format.length).to.equal(1); - }); - - it('dnt is correctly set to 1', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 600]] - } - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var dntStub = sinon.stub(utils, 'getDNT').returns(1); - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - - dntStub.restore(); - - const openrtbRequest = JSON.parse(bidRequest.data); - expect(openrtbRequest.device.dnt).to.equal(1); - }); - - it('sets floor to zero', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - 'floor': 100.0 - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 600]] - } - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - - const openrtbRequest = JSON.parse(bidRequest.data); - expect(openrtbRequest.imp[0].bidfloor).to.equal(0); - }); - - it('supports string video sizes', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - }, - 'mediaTypes': { - 'video': { - 'context': 'instream', - 'playerSize': ['600', '300'] - } - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-1', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - - const openrtbRequest = JSON.parse(bidRequest.data); - expect(openrtbRequest.imp[0].video.w).to.equal(600); - expect(openrtbRequest.imp[0].video.h).to.equal(300); - }); - - it('rejects bad video sizes', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - }, - 'mediaTypes': { - 'video': { - 'context': 'instream', - 'playerSize': ['badWidth', 'badHeight'] - } - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-1', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - - const openrtbRequest = JSON.parse(bidRequest.data); - expect(openrtbRequest.imp[0].video.w).to.be.undefined; - expect(openrtbRequest.imp[0].video.h).to.be.undefined; - }); - - it('supports missing video size', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - }, - 'mediaTypes': { - 'video': { - 'context': 'instream' - } - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-1', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - - const openrtbRequest = JSON.parse(bidRequest.data); - expect(openrtbRequest.imp[0].video.w).to.be.undefined; - expect(openrtbRequest.imp[0].video.h).to.be.undefined; - }); - - it('uses default zone and path', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 600] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - - const openrtbRequest = JSON.parse(bidRequest.data); - expect(openrtbRequest.imp[0].ext.bidder.zone).to.equal('1r'); - expect(openrtbRequest.imp[0].ext.bidder.path).to.equal('mvo'); - }); - - it('should return empty when required params not found', function () { - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'zone': 'myzone', - 'path': 'mypath' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 250] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1438287399331-3', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - - expect(bidRequest).to.be.empty; - }); - - it('should return empty site data when refererInfo is missing', function() { - delete this.defaultBidderRequest.refererInfo; - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - 'zone': 'myzone', - 'path': 'mypath' - }, - 'mediaType': 'banner', - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'sizes': [[300, 250]], - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - const openrtbRequest = JSON.parse(bidRequest.data); - - expect(openrtbRequest.site.domain).to.equal(''); - expect(openrtbRequest.site.page).to.equal(''); - expect(openrtbRequest.site.ref).to.equal(''); - }); - }); - - it('should secure correctly', function() { - this.defaultBidderRequest.refererInfo.stack[0] = ['https://securesite.dvl']; - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - 'zone': 'myzone', - 'path': 'mypath' - }, - 'mediaType': 'banner', - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'sizes': [[300, 250]], - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead' - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - const openrtbRequest = JSON.parse(bidRequest.data); - - expect(openrtbRequest.imp[0].secure).to.equal(1); - }); - - it('should pass schain', function() { - var schain = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [{ - 'asi': 'indirectseller.com', - 'sid': '00001', - 'hp': 1 - }, { - 'asi': 'indirectseller-2.com', - 'sid': '00002', - 'hp': 1 - }] - }; - var bidRequestList = [ - { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - 'zone': 'myzone', - 'path': 'mypath' - }, - 'mediaType': 'banner', - 'adUnitCode': 'div-gpt-ad-1438287399331-0', - 'sizes': [[300, 250]], - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'bidRequestsCount': 1, - 'bidId': '51ef8751f9aead', - 'ortb2': { - 'source': { - 'ext': { - 'schain': schain - } - } - } - } - ]; - - var bidRequest = r1adapter.buildRequests(bidRequestList, this.defaultBidderRequest); - const openrtbRequest = JSON.parse(bidRequest.data); - - expect(openrtbRequest.source.ext.schain).to.deep.equal(schain); - }); - - describe('misc interpretResponse', function () { - it('No bid response', function() { - var noBidResponse = r1adapter.interpretResponse({ - 'body': '' - }); - expect(noBidResponse.length).to.equal(0); - }); - }); - - describe('isBidRequestValid', function () { - var bid = { - 'bidder': 'rhythmone', - 'params': { - 'placementId': 'myplacement', - 'path': 'mypath', - 'zone': 'myzone' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]] - } - }, - 'adUnitCode': 'bannerDiv' - }; - - it('should return true when required params found', function () { - expect(r1adapter.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when placementId missing', function () { - delete bid.params.placementId; - expect(r1adapter.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('getUserSyncs', function () { - it('returns an empty string', function () { - expect(r1adapter.getUserSyncs()).to.deep.equal([]); - }); - }); -}); diff --git a/test/spec/modules/richaudienceBidAdapter_spec.js b/test/spec/modules/richaudienceBidAdapter_spec.js deleted file mode 100644 index fd75c6d0c..000000000 --- a/test/spec/modules/richaudienceBidAdapter_spec.js +++ /dev/null @@ -1,1306 +0,0 @@ -// import or require modules necessary for the test, e.g.: -import {expect} from 'chai'; // may prefer 'assert' in place of 'expect' -import { - spec -} from 'modules/richaudienceBidAdapter.js'; -import {config} from 'src/config.js'; -import * as utils from 'src/utils.js'; -import sinon from 'sinon'; - -describe('Richaudience adapter tests', function () { - var DEFAULT_PARAMS_NEW_SIZES = [{ - adUnitCode: 'test-div', - bidId: '2c7c8e9c900244', - mediaTypes: { - banner: { - sizes: [ - [300, 250], [300, 600], [728, 90], [970, 250]] - } - }, - bidder: 'richaudience', - params: { - bidfloor: 0.5, - pid: 'ADb1f40rmi', - supplyType: 'site', - keywords: 'key1=value1;key2=value2' - }, - auctionId: '0cb3144c-d084-4686-b0d6-f5dbe917c563', - bidRequestsCount: 1, - bidderRequestId: '1858b7382993ca', - ortb2Imp: { - ext: { - tid: '29df2112-348b-4961-8863-1b33684d95e6', - } - }, - user: {} - }]; - - var DEFAULT_PARAMS_NEW_DSA = [{ - adUnitCode: 'test-div', - bidId: '2c7c8e9c900244', - mediaTypes: { - banner: { - sizes: [ - [300, 250], [300, 600], [728, 90], [970, 250]] - } - }, - bidder: 'richaudience', - params: { - bidfloor: 0.5, - pid: 'ADb1f40rmi', - supplyType: 'site', - keywords: 'key1=value1;key2=value2' - }, - auctionId: '0cb3144c-d084-4686-b0d6-f5dbe917c563', - bidRequestsCount: 1, - bidderRequestId: '1858b7382993ca', - ortb2: { - regs: { - ext: { - dsa: { - dsarequired: 2, - pubrender: 1, - datatopub: 1, - transparency: [ - { - domain: 'richaudience.com', - dsaparams: [1, 3, 6] - }, - { - domain: 'adpone.com', - dsaparams: [8, 10, 12] - }, - { - domain: 'sunmedia.com', - dsaparams: [14, 16, 18] - } - ] - } - } - } - }, - user: {} - }]; - - var DEFAULT_PARAMS_NEW_SIZES_GPID = [{ - adUnitCode: 'test-div', - bidId: '2c7c8e9c900244', - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-1#example-2', - data: { - pbadslot: '/19968336/header-bid-tag-1#example-2' - } - } - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], [300, 600], [728, 90], [970, 250]] - } - }, - bidder: 'richaudience', - params: { - bidfloor: 0.5, - pid: 'ADb1f40rmi', - supplyType: 'site', - keywords: 'key1=value1;key2=value2' - }, - auctionId: '0cb3144c-d084-4686-b0d6-f5dbe917c563', - bidRequestsCount: 1, - bidderRequestId: '1858b7382993ca', - transactionId: '29df2112-348b-4961-8863-1b33684d95e6', - user: {} - }]; - - var DEFAULT_PARAMS_VIDEO_TIMEOUT = [{ - adUnitCode: 'test-div', - bidId: '2c7c8e9c900244', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480], - mimes: ['video/mp4'] - } - }, - bidder: 'richaudience', - params: [{ - bidfloor: 0.5, - pid: 'ADb1f40rmi', - supplyType: 'site' - }], - timeout: 3000, - auctionId: '0cb3144c-d084-4686-b0d6-f5dbe917c563', - bidRequestsCount: 1, - bidderRequestId: '1858b7382993ca', - transactionId: '29df2112-348b-4961-8863-1b33684d95e6', - user: {} - }] - - var DEFAULT_PARAMS_VIDEO_IN = [{ - adUnitCode: 'test-div', - bidId: '2c7c8e9c900244', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480], - mimes: ['video/mp4'] - } - }, - bidder: 'richaudience', - params: { - bidfloor: 0.5, - pid: 'ADb1f40rmi', - supplyType: 'site' - }, - auctionId: '0cb3144c-d084-4686-b0d6-f5dbe917c563', - bidRequestsCount: 1, - bidderRequestId: '1858b7382993ca', - transactionId: '29df2112-348b-4961-8863-1b33684d95e6', - user: {} - }]; - - var DEFAULT_PARAMS_VIDEO_OUT = [{ - adUnitCode: 'test-div', - bidId: '2c7c8e9c900244', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 480], - mimes: ['video/mp4'] - } - }, - bidder: 'richaudience', - params: { - bidfloor: 0.5, - pid: 'ADb1f40rmi', - supplyType: 'site' - }, - auctionId: '0cb3144c-d084-4686-b0d6-f5dbe917c563', - bidRequestsCount: 1, - bidderRequestId: '1858b7382993ca', - transactionId: '29df2112-348b-4961-8863-1b33684d95e6', - user: {} - }]; - - var DEFAULT_PARAMS_BANNER_OUTSTREAM = [{ - adUnitCode: 'test-div', - bidId: '2c7c8e9c900244', - mediaTypes: { - banner: { - sizes: [[300, 250], [600, 300]] - } - }, - bidder: 'richaudience', - params: { - bidfloor: 0.5, - pid: 'ADb1f40rmi', - supplyType: 'site' - }, - auctionId: '0cb3144c-d084-4686-b0d6-f5dbe917c563', - bidRequestsCount: 1, - bidderRequestId: '1858b7382993ca', - transactionId: '29df2112-348b-4961-8863-1b33684d95e6', - user: {} - }]; - - var DEFAULT_PARAMS_APP = [{ - adUnitCode: 'test-div', - bidId: '2c7c8e9c900244', - sizes: [ - [300, 250], - [300, 600], - [728, 90], - [970, 250] - ], - bidder: 'richaudience', - params: { - bidfloor: 0.5, - ifa: 'AAAAAAAAA-BBBB-CCCC-1111-222222220000', - pid: 'ADb1f40rmi', - supplyType: 'app', - }, - auctionId: '0cb3144c-d084-4686-b0d6-f5dbe917c563', - bidRequestsCount: 1, - bidderRequestId: '1858b7382993ca', - transactionId: '29df2112-348b-4961-8863-1b33684d95e6' - }]; - - var DEFAULT_PARAMS_WO_OPTIONAL = [{ - adUnitCode: 'test-div', - bidId: '2c7c8e9c900244', - sizes: [ - [300, 250], - [300, 600], - [728, 90], - [970, 250] - ], - bidder: 'richaudience', - params: { - pid: 'ADb1f40rmi', - supplyType: 'site', - }, - auctionId: '851adee7-d843-48f9-a7e9-9ff00573fcbf', - bidRequestsCount: 1, - bidderRequestId: '1858b7382993ca', - transactionId: '29df2112-348b-4961-8863-1b33684d95e6' - }]; - - var BID_PARAMS_EIDS = [{ - 'bidder': 'richaudience', - 'params': { - 'pid': 'IHOhChZNuI', - 'supplyType': 'site' - }, - 'userIdAsEids': [], - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - }] - - var id5 = { - 'source': 'id5-sync.com', - 'uids': [ - { - 'id': 'id5-string-cookie', - 'atype': 1, - 'ext': { - 'linkType': 2, - 'pba': 'id5-pba', - 'abTestingControlGroup': false - } - } - ] - } - - var first_id = { - 'source': 'first-id.fr', - 'uids': [ - { - 'id': 'value read from cookie or local storage', - 'atype': 1, - 'ext': { - 'stype': 'ppuid' - } - } - ] - } - - var three_party_provided = { - 'source': '3rdpartyprovided.com', - 'uids': [ - { - 'id': 'value read from cookie or local storage', - 'atype': 3, - 'ext': { - 'stype': 'dmp' - } - } - ] - } - - var BID_RESPONSE = { - body: { - cpm: 1.50, - adm: '', - media_type: 'js', - width: 300, - height: 250, - creative_id: '189198063', - netRevenue: true, - currency: 'USD', - ttl: 300, - dealId: 'dealId', - adomain: ['richaudience.com'] - } - }; - - var BID_RESPONSE_VIDEO = { - body: { - cpm: 1.50, - media_type: 'video', - width: 1, - height: 1, - creative_id: '189198063', - netRevenue: true, - currency: 'USD', - ttl: 300, - vastXML: '', - dealId: 'dealId', - adomain: ['richaudience.com'] - } - }; - - var DEFAULT_PARAMS_GDPR = { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: { - page: 'http://domain.com', - numIframes: 0 - } - } - - it('Referer undefined', function () { - config.setConfig({ - 'currency': {'adServerCurrency': 'USD'} - }) - - const request = spec.buildRequests(DEFAULT_PARAMS_NEW_SIZES, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: {} - }) - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('referer').and.to.equal(null); - expect(requestContent).to.have.property('referer').and.to.equal(null); - }) - - it('Verify build request to prebid 3.0 display test', function () { - const request = spec.buildRequests(DEFAULT_PARAMS_NEW_SIZES, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: { - page: 'https://domain.com', - numIframes: 0 - } - }); - - expect(request[0]).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('bidfloor').and.to.equal(0.5); - expect(requestContent).to.have.property('pid').and.to.equal('ADb1f40rmi'); - expect(requestContent).to.have.property('supplyType').and.to.equal('site'); - expect(requestContent).to.have.property('auctionId').and.to.equal('0cb3144c-d084-4686-b0d6-f5dbe917c563'); - expect(requestContent).to.have.property('bidId').and.to.equal('2c7c8e9c900244'); - expect(requestContent).to.have.property('BidRequestsCount').and.to.equal(1); - expect(requestContent).to.have.property('bidder').and.to.equal('richaudience'); - expect(requestContent).to.have.property('bidderRequestId').and.to.equal('1858b7382993ca'); - expect(requestContent).to.have.property('tagId').and.to.equal('test-div'); - expect(requestContent).to.have.property('referer').and.to.equal('https%3A%2F%2Fdomain.com'); - expect(requestContent).to.have.property('sizes'); - expect(requestContent.sizes[0]).to.have.property('w').and.to.equal(300); - expect(requestContent.sizes[0]).to.have.property('h').and.to.equal(250); - expect(requestContent.sizes[1]).to.have.property('w').and.to.equal(300); - expect(requestContent.sizes[1]).to.have.property('h').and.to.equal(600); - expect(requestContent.sizes[2]).to.have.property('w').and.to.equal(728); - expect(requestContent.sizes[2]).to.have.property('h').and.to.equal(90); - expect(requestContent.sizes[3]).to.have.property('w').and.to.equal(970); - expect(requestContent.sizes[3]).to.have.property('h').and.to.equal(250); - expect(requestContent).to.have.property('transactionId').and.to.equal('29df2112-348b-4961-8863-1b33684d95e6'); - expect(requestContent).to.have.property('timeout').and.to.equal(600); - expect(requestContent).to.have.property('numIframes').and.to.equal(0); - expect(typeof requestContent.scr_rsl === 'string') - expect(typeof requestContent.cpuc === 'number') - expect(typeof requestContent.gpid === 'string') - expect(requestContent).to.have.property('kws').and.to.equal('key1=value1;key2=value2'); - }) - - it('Verify build request to prebid video inestream', function () { - const request = spec.buildRequests(DEFAULT_PARAMS_VIDEO_IN, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: { - page: 'https://domain.com', - numIframes: 0 - } - }); - - expect(request[0]).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request[0].data); - - expect(requestContent).to.have.property('demand').and.to.equal('video'); - expect(requestContent.videoData).to.have.property('format').and.to.equal('instream'); - }) - - it('Verify build request to prebid video outstream', function () { - const request = spec.buildRequests(DEFAULT_PARAMS_VIDEO_OUT, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: { - page: 'https://domain.com', - numIframes: 0 - } - }); - - expect(request[0]).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request[0].data); - - expect(requestContent).to.have.property('demand').and.to.equal('video'); - expect(requestContent.videoData).to.have.property('format').and.to.equal('outstream'); - }) - - describe('gdpr test', function () { - it('Verify build request with GDPR', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'USD' - }, - consentManagement: { - cmpApi: 'iab', - timeout: 8000, - allowAuctionWithoutConsent: true - } - }); - - const request = spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: { - page: 'https://domain.com', - numIframes: 0 - } - }); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('gdpr_consent').and.to.equal('BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA'); - }); - - it('Verify adding ifa when supplyType equal to app', function () { - const request = spec.buildRequests(DEFAULT_PARAMS_APP, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: { - page: 'https://domain.com', - numIframes: 0 - } - }); - }); - - it('Verify build request with GDPR without gdprApplies', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - }, - consentManagement: { - cmp: 'iab', - consentRequired: true, - timeout: 8000, - allowAuctionWithoutConsent: true - } - }); - const request = spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA' - }, - refererInfo: { - page: 'https://domain.com', - numIframes: 0 - } - }); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('gdpr_consent').and.to.equal('BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA'); - }); - }); - - describe('UID test', function () { - config.setConfig({ - consentManagement: { - cmpApi: 'iab', - timeout: 5000, - allowAuctionWithoutConsent: true - }, - userSync: { - userIds: [{ - name: 'id5Id', - params: { - partner: 173, // change to the Partner Number you received from ID5 - pd: 'MT1iNTBjY...' // optional, see table below for a link to how to generate this - }, - storage: { - type: 'html5', // 'html5' is the required storage type - name: 'id5id', // 'id5id' is the required storage name - expires: 90, // storage lasts for 90 days - refreshInSeconds: 8 * 3600 // refresh ID every 8 hours to ensure it's fresh - } - }], - auctionDelay: 50 // 50ms maximum auction delay, applies to all userId modules - } - }); - - it('Verify build return empty users', function () { - var request = spec.buildRequests(BID_PARAMS_EIDS, DEFAULT_PARAMS_GDPR); - var requestContent = JSON.parse(request[0].data); - - expect(requestContent.eids).to.deep.equal([]); - }) - - it('Verify build return all users', function () { - BID_PARAMS_EIDS[0].userIdAsEids = [id5, three_party_provided, first_id] - var request = spec.buildRequests(BID_PARAMS_EIDS, DEFAULT_PARAMS_GDPR); - var requestContent = JSON.parse(request[0].data); - expect(requestContent.eids).to.deep.equal([id5, three_party_provided, first_id]); - }) - - it('Verify build return first-id.fr users', function () { - BID_PARAMS_EIDS[0].userIdAsEids = [first_id] - var request = spec.buildRequests(BID_PARAMS_EIDS, DEFAULT_PARAMS_GDPR); - var requestContent = JSON.parse(request[0].data); - expect(requestContent.eids).to.deep.equal([first_id]); - }) - - it('Verify build return first-id.fr users', function () { - BID_PARAMS_EIDS[0].userIdAsEids = [first_id] - var request = spec.buildRequests(BID_PARAMS_EIDS, DEFAULT_PARAMS_GDPR); - var requestContent = JSON.parse(request[0].data); - expect(requestContent.eids).to.deep.equal([first_id]); - }) - - it('Verify build return users []', function () { - BID_PARAMS_EIDS[0].userIdAsEids = [] - var request = spec.buildRequests(BID_PARAMS_EIDS, DEFAULT_PARAMS_GDPR); - var requestContent = JSON.parse(request[0].data); - expect(requestContent.eids).to.deep.equal([]); - }) - - it('Verify build return users null', function () { - BID_PARAMS_EIDS[0].userIdAsEids = null - var request = spec.buildRequests(BID_PARAMS_EIDS, DEFAULT_PARAMS_GDPR); - var requestContent = JSON.parse(request[0].data); - expect(requestContent.eids).to.deep.equal([]); - }) - - it('Verify build return users {}', function () { - BID_PARAMS_EIDS[0].userIdAsEids = null - var request = spec.buildRequests(BID_PARAMS_EIDS, DEFAULT_PARAMS_GDPR); - var requestContent = JSON.parse(request[0].data); - expect(requestContent.eids).to.deep.equal([]); - }) - }); - - it('Verify interprete response', function () { - const request = spec.buildRequests(DEFAULT_PARAMS_NEW_SIZES, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: { - page: 'https://domain.com', - numIframes: 0 - } - }); - - const bids = spec.interpretResponse(BID_RESPONSE, request[0]); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(1.50); - expect(bid.ad).to.equal(''); - expect(bid.mediaType).to.equal('js'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creativeId).to.equal('189198063'); - expect(bid.netRevenue).to.equal(true); - expect(bid.currency).to.equal('USD'); - expect(bid.ttl).to.equal(300); - expect(bid.dealId).to.equal('dealId'); - expect(bid.meta.advertiserDomains[0]).to.equal('richaudience.com'); - }); - - it('no banner media response inestream', function () { - const request = spec.buildRequests(DEFAULT_PARAMS_VIDEO_IN, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: { - page: 'https://domain.com', - numIframes: 0 - } - }); - - const bids = spec.interpretResponse(BID_RESPONSE_VIDEO, request[0]); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(1.50); - expect(bid.mediaType).to.equal('video'); - expect(bid.vastXml).to.equal(''); - expect(bid.cpm).to.equal(1.50); - expect(bid.width).to.equal(1); - expect(bid.height).to.equal(1); - expect(bid.creativeId).to.equal('189198063'); - expect(bid.netRevenue).to.equal(true); - expect(bid.currency).to.equal('USD'); - expect(bid.ttl).to.equal(300); - expect(bid.dealId).to.equal('dealId'); - expect(bid.meta.advertiserDomains[0]).to.equal('richaudience.com'); - }); - - it('no banner media response outstream', function () { - const request = spec.buildRequests(DEFAULT_PARAMS_VIDEO_OUT, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: { - page: 'https://domain.com', - numIframes: 0 - } - }); - - const bids = spec.interpretResponse(BID_RESPONSE_VIDEO, request[0]); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(1.50); - expect(bid.mediaType).to.equal('video'); - expect(bid.vastXml).to.equal(''); - expect(bid.renderer.url).to.equal('https://cdn3.richaudience.com/prebidVideo/player.js'); - expect(bid.cpm).to.equal(1.50); - expect(bid.width).to.equal(1); - expect(bid.height).to.equal(1); - expect(bid.creativeId).to.equal('189198063'); - expect(bid.netRevenue).to.equal(true); - expect(bid.currency).to.equal('USD'); - expect(bid.ttl).to.equal(300); - expect(bid.dealId).to.equal('dealId'); - }); - - it('banner media and response VAST', function () { - const request = spec.buildRequests(DEFAULT_PARAMS_BANNER_OUTSTREAM, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: { - page: 'https://domain.com', - numIframes: 0 - } - }); - - const bids = spec.interpretResponse(BID_RESPONSE_VIDEO, request[0]); - const bid = bids[0]; - expect(bid.mediaType).to.equal('video'); - expect(bid.vastXml).to.equal(''); - expect(bid.renderer.url).to.equal('https://cdn3.richaudience.com/prebidVideo/player.js'); - }); - - it('Verifies bidder_code', function () { - expect(spec.code).to.equal('richaudience'); - }); - - it('Verifies bidder aliases', function () { - expect(spec.aliases).to.have.lengthOf(1); - expect(spec.aliases[0]).to.deep.equal({code: 'ra', gvlid: 108}); - }); - - it('Verifies bidder gvlid', function () { - expect(spec.gvlid).to.equal(108); - }); - - it('Verifies bidder supportedMediaTypes', function () { - expect(spec.supportedMediaTypes).to.have.lengthOf(2); - expect(spec.supportedMediaTypes[0]).to.equal('banner'); - expect(spec.supportedMediaTypes[1]).to.equal('video'); - }); - - it('Verifies if bid request is valid', function () { - expect(spec.isBidRequestValid(DEFAULT_PARAMS_NEW_SIZES[0])).to.equal(true); - expect(spec.isBidRequestValid(DEFAULT_PARAMS_WO_OPTIONAL[0])).to.equal(true); - expect(spec.isBidRequestValid({})).to.equal(false); - expect(spec.isBidRequestValid({ - params: {} - })).to.equal(false); - expect(spec.isBidRequestValid({ - params: { - pid: 'ADb1f40rmi' - } - })).to.equal(false); - expect(spec.isBidRequestValid({ - params: { - supplyType: 'site' - } - })).to.equal(false); - expect(spec.isBidRequestValid({ - params: { - supplyType: 'app' - } - })).to.equal(false); - expect(spec.isBidRequestValid({ - params: { - pid: 'ADb1f40rmi', - supplyType: 'site' - } - })).to.equal(true); - expect(spec.isBidRequestValid({ - params: { - pid: ['1gCB5ZC4XL', '1a40xk8qSV'], - supplyType: 'site' - } - })).to.equal(true); - expect(spec.isBidRequestValid({ - params: { - pid: 'ADb1f40rmi', - supplyType: 'site' - } - })).to.equal(true); - expect(spec.isBidRequestValid({ - params: { - pid: 'ADb1f40rmi', - supplyType: 'app', - ifa: 'AAAAAAAAA-BBBB-CCCC-1111-222222220000', - } - })).to.equal(true); - expect(spec.isBidRequestValid({ - params: { - pid: 'ADb1f40rmi', - supplyType: 'site', - bidfloor: 0.50, - } - })).to.equal(true); - expect(spec.isBidRequestValid({ - params: { - pid: 'ADb1f40rmi', - supplyType: 'site', - bidfloor: 0.50, - } - })).to.equal(true); - expect(spec.isBidRequestValid({ - params: { - pid: ['1gCB5ZC4XL', '1a40xk8qSV'], - bidfloor: 0.50, - } - })).to.equal(false); - expect(spec.isBidRequestValid({ - params: { - pid: ['1gCB5ZC4XL', '1a40xk8qSV'], - supplyType: 'site', - bidfloor: 0.50, - } - })).to.equal(true); - expect(spec.isBidRequestValid({ - params: { - supplyType: 'site', - bidfloor: 0.50, - ifa: 'AAAAAAAAA-BBBB-CCCC-1111-222222220000', - } - })).to.equal(false); - expect(spec.isBidRequestValid({ - params: { - pid: ['1gCB5ZC4XL', '1a40xk8qSV'], - supplyType: 'site', - bidfloor: 0.50, - ifa: 'AAAAAAAAA-BBBB-CCCC-1111-222222220000', - } - })).to.equal(true); - }); - - it('should pass schain', function () { - const schain = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [{ - 'asi': 'richaudience.com', - 'sid': '00001', - 'hp': 1 - }, { - 'asi': 'richaudience-2.com', - 'sid': '00002', - 'hp': 1 - }] - } - - DEFAULT_PARAMS_NEW_SIZES[0].ortb2 = { - source: { - ext: { - schain: { - 'ver': '1.0', - 'complete': 1, - 'nodes': [{ - 'asi': 'richaudience.com', - 'sid': '00001', - 'hp': 1 - }, { - 'asi': 'richaudience-2.com', - 'sid': '00002', - 'hp': 1 - }] - } - } - } - } - - const request = spec.buildRequests(DEFAULT_PARAMS_NEW_SIZES, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: {} - }) - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('schain').to.deep.equal(schain); - }) - - it('should pass DSA', function () { - const request = spec.buildRequests(DEFAULT_PARAMS_NEW_DSA, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: {} - }) - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('dsa').property('dsarequired').and.to.equal(2) - expect(requestContent).to.have.property('dsa').property('pubrender').and.to.equal(1); - expect(requestContent).to.have.property('dsa').property('datatopub').and.to.equal(1); - expect(requestContent.dsa.transparency[0]).to.have.property('domain').and.to.equal('richaudience.com'); - }) - - it('should pass gpid', function () { - const request = spec.buildRequests(DEFAULT_PARAMS_NEW_SIZES_GPID, { - gdprConsent: { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - refererInfo: {} - }) - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('gpid').and.to.equal('/19968336/header-bid-tag-1#example-2'); - }) - - describe('onTimeout', function () { - beforeEach(function () { - sinon.stub(utils, 'triggerPixel'); - }); - - afterEach(function () { - utils.triggerPixel.restore(); - }); - it('onTimeout exist as a function', () => { - expect(spec.onTimeout).to.exist.and.to.be.a('function'); - }); - it('should send timeouts', function () { - spec.onTimeout(DEFAULT_PARAMS_VIDEO_TIMEOUT); - expect(utils.triggerPixel.called).to.equal(true); - expect(utils.triggerPixel.firstCall.args[0]).to.equal('https://s.richaudience.com/err/?ec=6&ev=3000&pla=ADb1f40rmi&int=PREBID&pltfm=&node=&dm=localhost:9876'); - }); - }); - - describe('userSync', function () { - let sandbox; - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - afterEach(function () { - sandbox.restore(); - }); - it('Verifies user syncs iframe include', function () { - config.setConfig({ - 'userSync': {filterSettings: {iframe: {bidders: '*', filter: 'include'}}} - }) - - var syncs = spec.getUserSyncs({ - iframeEnabled: true - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - ); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true, - }); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: true, - }, [], {consentString: '', gdprApplies: false}); - expect(syncs).to.have.lengthOf(1); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - }, [], {consentString: '', gdprApplies: true}); - expect(syncs).to.have.lengthOf(0); - }); - it('Verifies user syncs iframe exclude', function () { - config.setConfig({ - 'userSync': {filterSettings: {iframe: {bidders: '*', filter: 'exclude'}}} - }) - - var syncs = spec.getUserSyncs({ - iframeEnabled: true - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - ); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true, - }); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: true, - }, [], {consentString: '', gdprApplies: false}); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - }, [], {consentString: '', gdprApplies: true}); - expect(syncs).to.have.lengthOf(0); - }); - - it('Verifies user syncs image include', function () { - config.setConfig({ - 'userSync': {filterSettings: {image: {bidders: '*', filter: 'include'}}} - }) - - var syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: true - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - referer: 'http://domain.com', - gdprApplies: true - }) - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('image'); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: true - }, [BID_RESPONSE], { - consentString: '', - referer: 'http://domain.com', - gdprApplies: true - }) - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('image'); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: true - }, [], { - consentString: null, - referer: 'http://domain.com', - gdprApplies: false - }) - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('image'); - }); - - it('Verifies user syncs image exclude', function () { - config.setConfig({ - 'userSync': {filterSettings: {image: {bidders: '*', filter: 'exclude'}}} - }) - - var syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: true - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - referer: 'http://domain.com', - gdprApplies: true - }) - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: true - }, [BID_RESPONSE], { - consentString: '', - referer: 'http://domain.com', - gdprApplies: true - }) - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: true - }, [], { - consentString: null, - referer: 'http://domain.com', - gdprApplies: false - }) - expect(syncs).to.have.lengthOf(0); - }); - - it('Verifies user syncs iframe/image include', function () { - config.setConfig({ - 'userSync': { - filterSettings: { - iframe: {bidders: '*', filter: 'include'}, - image: {bidders: '*', filter: 'include'} - } - } - }) - - var syncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - ); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true, - }); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, [], {consentString: '', gdprApplies: false}); - expect(syncs).to.have.lengthOf(1); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, [], {consentString: '', gdprApplies: true}); - expect(syncs).to.have.lengthOf(0); - }); - - it('Verifies user syncs iframe/image exclude', function () { - config.setConfig({ - 'userSync': { - filterSettings: { - iframe: {bidders: '*', filter: 'exclude'}, - image: {bidders: '*', filter: 'exclude'} - } - } - }) - - var syncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - ); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true, - }); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, [], {consentString: '', gdprApplies: false}); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, [], {consentString: '', gdprApplies: true}); - expect(syncs).to.have.lengthOf(0); - }); - - it('Verifies user syncs iframe exclude / image include', function () { - config.setConfig({ - 'userSync': { - filterSettings: { - iframe: {bidders: '*', filter: 'exclude'}, - image: {bidders: '*', filter: 'include'} - } - } - }) - - var syncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - ); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('image'); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true, - }); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, [], {consentString: '', gdprApplies: false}); - expect(syncs).to.have.lengthOf(1); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, [], {consentString: '', gdprApplies: true}); - expect(syncs).to.have.lengthOf(0); - }); - - it('Verifies user syncs iframe include / image exclude', function () { - config.setConfig({ - 'userSync': { - filterSettings: { - iframe: {bidders: '*', filter: 'include'}, - image: {bidders: '*', filter: 'exclude'} - } - } - }) - - var syncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }, - ); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true, - }); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, [BID_RESPONSE], { - consentString: 'BOZcQl_ObPFjWAeABAESCD-AAAAjx7_______9______9uz_Ov_v_f__33e8__9v_l_7_-___u_-33d4-_1vf99yfm1-7ftr3tp_87ues2_Xur__59__3z3_NohBgA', - gdprApplies: true - }); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true - }, [], {consentString: '', gdprApplies: false}); - expect(syncs).to.have.lengthOf(1); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, [], {consentString: '', gdprApplies: true}); - expect(syncs).to.have.lengthOf(0); - }); - - it('Verifies user syncs iframe/image include with GPP', function () { - config.setConfig({ - 'userSync': {filterSettings: {iframe: {bidders: '*', filter: 'include'}}} - }) - - let syncs = spec.getUserSyncs({iframeEnabled: true}, [BID_RESPONSE], { - gppString: 'DBABL~BVVqAAEABgA.QA', - applicableSections: [7] - }, - ); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - - config.setConfig({ - 'userSync': {filterSettings: {image: {bidders: '*', filter: 'include'}}} - }) - - syncs = spec.getUserSyncs({pixelEnabled: true}, [BID_RESPONSE], { - gppString: 'DBABL~BVVqAAEABgA.QA', - applicableSections: [7, 5] - }, - ); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('image'); - }); - - it('Verifies user syncs URL image include with GPP', function () { - const gppConsent = { - gppString: 'DBACMYA~CP5P4cAP5P4cAPoABAESAlEAAAAAAAAAAAAAA2QAQA2ADZABADYAAAAA.QA2QAQA2AAAA.IA2QAQA2AAAA~BP5P4cAP5P4cAPoABABGBACAAAAAAAAAAAAAAAAAAA.YAAAAAAAAAA', - applicableSections: [0] - }; - const result = spec.getUserSyncs({pixelEnabled: true}, undefined, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'image', - url: `https://sync.richaudience.com/bf7c142f4339da0278e83698a02b0854/?referrer=http%3A%2F%2Fdomain.com&gpp=DBACMYA~CP5P4cAP5P4cAPoABAESAlEAAAAAAAAAAAAAA2QAQA2ADZABADYAAAAA.QA2QAQA2AAAA.IA2QAQA2AAAA~BP5P4cAP5P4cAPoABABGBACAAAAAAAAAAAAAAAAAAA.YAAAAAAAAAA&gpp_sid=0` - }]); - }); - }) -}); diff --git a/test/spec/modules/ringieraxelspringerBidAdapter_spec.js b/test/spec/modules/ringieraxelspringerBidAdapter_spec.js deleted file mode 100644 index 08587e517..000000000 --- a/test/spec/modules/ringieraxelspringerBidAdapter_spec.js +++ /dev/null @@ -1,676 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/ringieraxelspringerBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; - -const CSR_ENDPOINT = 'https://csr.onet.pl/4178463/csr-006/csr.json?nid=4178463&'; - -describe('ringieraxelspringerBidAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - const bid = { - sizes: [[300, 250], [300, 600]], - bidder: 'ringieraxelspringer', - params: { - slot: 'slot', - area: 'areatest', - site: 'test', - network: '4178463' - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params not found', function () { - const failBid = { - sizes: [[300, 250], [300, 300]], - bidder: 'ringieraxelspringer', - params: { - site: 'test', - network: '4178463' - } - }; - expect(spec.isBidRequestValid(failBid)).to.equal(false); - }); - - it('should return nothing when bid request is malformed', function () { - const failBid = { - sizes: [[300, 250], [300, 300]], - bidder: 'ringieraxelspringer', - }; - expect(spec.isBidRequestValid(failBid)).to.equal(undefined); - }); - }); - - describe('buildRequests', function () { - const bid = { - sizes: [[300, 250], [300, 600]], - bidder: 'ringieraxelspringer', - bidId: 1, - params: { - slot: 'test', - area: 'areatest', - site: 'test', - slotSequence: '0', - network: '4178463', - customParams: { - test: 'name=value' - } - }, - mediaTypes: { - banner: { - sizes: [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - } - }; - const bid2 = { - sizes: [[750, 300]], - bidder: 'ringieraxelspringer', - bidId: 2, - params: { - slot: 'test2', - area: 'areatest', - site: 'test', - network: '4178463' - }, - mediaTypes: { - banner: { - sizes: [ - [ - 750, - 300 - ] - ] - } - } - }; - - it('should parse bids to request', function () { - const requests = spec.buildRequests([bid], { - 'gdprConsent': { - 'gdprApplies': true, - 'consentString': 'some-consent-string' - }, - 'refererInfo': { - 'ref': 'https://example.org/', - 'page': 'https://example.com/' - } - }); - expect(requests[0].url).to.have.string(CSR_ENDPOINT); - expect(requests[0].url).to.have.string('slot0=test'); - expect(requests[0].url).to.have.string('id0=1'); - expect(requests[0].url).to.have.string('site=test'); - expect(requests[0].url).to.have.string('area=areatest'); - expect(requests[0].url).to.have.string('cre_format=html'); - expect(requests[0].url).to.have.string('systems=das'); - expect(requests[0].url).to.have.string('ems_url=1'); - expect(requests[0].url).to.have.string('bid_rate=1'); - expect(requests[0].url).to.have.string('gdpr_applies=true'); - expect(requests[0].url).to.have.string('euconsent=some-consent-string'); - expect(requests[0].url).to.have.string('du=https%3A%2F%2Fexample.com%2F'); - expect(requests[0].url).to.have.string('dr=https%3A%2F%2Fexample.org%2F'); - expect(requests[0].url).to.have.string('test=name%3Dvalue'); - }); - - it('should return empty consent string when undefined', function () { - const requests = spec.buildRequests([bid]); - const gdpr = requests[0].url.search('gdpr_applies'); - const euconsent = requests[0].url.search('euconsent='); - expect(gdpr).to.equal(-1); - expect(euconsent).to.equal(-1); - }); - - it('should parse bids to request from pageContext', function () { - const bidCopy = { ...bid }; - bidCopy.params = { - ...bid.params, - pageContext: { - dv: 'test/areatest', - du: 'https://example.com/', - dr: 'https://example.org/', - keyWords: ['val1', 'val2'], - keyValues: { - adunit: 'test/areatest' - } - } - }; - const requests = spec.buildRequests([bidCopy, bid2]); - - expect(requests[0].url).to.have.string(CSR_ENDPOINT); - expect(requests[0].url).to.have.string('slot0=test'); - expect(requests[0].url).to.have.string('id0=1'); - expect(requests[0].url).to.have.string('iusizes0=300x250%2C300x600'); - expect(requests[0].url).to.have.string('slot1=test2'); - expect(requests[0].url).to.have.string('kvhb_format0=banner'); - expect(requests[0].url).to.have.string('id1=2'); - expect(requests[0].url).to.have.string('iusizes1=750x300'); - expect(requests[0].url).to.have.string('kvhb_format1=banner'); - expect(requests[0].url).to.have.string('site=test'); - expect(requests[0].url).to.have.string('area=areatest'); - expect(requests[0].url).to.have.string('cre_format=html'); - expect(requests[0].url).to.have.string('systems=das'); - expect(requests[0].url).to.have.string('ems_url=1'); - expect(requests[0].url).to.have.string('bid_rate=1'); - expect(requests[0].url).to.have.string('du=https%3A%2F%2Fexample.com%2F'); - expect(requests[0].url).to.have.string('dr=https%3A%2F%2Fexample.org%2F'); - expect(requests[0].url).to.have.string('DV=test%2Fareatest'); - expect(requests[0].url).to.have.string('kwrd=val1%2Bval2'); - expect(requests[0].url).to.have.string('kvadunit=test%2Fareatest'); - expect(requests[0].url).to.have.string('pos0=0'); - }); - - it('should parse dsainfo when available', function () { - const bidCopy = { ...bid }; - bidCopy.params = { - ...bid.params, - pageContext: { - dv: 'test/areatest', - du: 'https://example.com/', - dr: 'https://example.org/', - keyWords: ['val1', 'val2'], - keyValues: { - adunit: 'test/areatest' - } - } - }; - const bidderRequest = { - ortb2: { - regs: { - ext: { - dsa: { - required: 1 - } - } - } - } - }; - let requests = spec.buildRequests([bidCopy], bidderRequest); - expect(requests[0].url).to.have.string('dsainfo=1'); - - bidderRequest.ortb2.regs.ext.dsa.required = 0; - requests = spec.buildRequests([bidCopy], bidderRequest); - expect(requests[0].url).to.have.string('dsainfo=0'); - }); - }); - - describe('interpretResponse', function () { - const response = { - 'adsCheck': 'ok', - 'geoloc': {}, - 'ir': '92effd60-0c84-4dac-817e-763ea7b8ac65', - 'ads': [ - { - 'id': 'flat-belkagorna', - 'slot': 'flat-belkagorna', - 'prio': 10, - 'type': 'html', - 'bid_rate': 0.321123, - 'adid': 'das,50463,152276', - 'id_3': '12734', - 'html': '' - } - ], - 'iv': '202003191334467636346500' - }; - - it('should get correct bid response', function () { - const resp = spec.interpretResponse({ body: response }, { bidIds: [{ slot: 'flat-belkagorna', bidId: 1 }] }); - expect(resp[0]).to.have.all.keys('cpm', 'currency', 'netRevenue', 'requestId', 'ttl', 'width', 'height', 'creativeId', 'dealId', 'ad', 'meta', 'actgMatch', 'mediaType'); - expect(resp.length).to.equal(1); - }); - - it('should handle empty ad', function () { - const res = { - 'ads': [{ - type: 'empty' - }] - }; - const resp = spec.interpretResponse({ body: res }, {}); - expect(resp).to.deep.equal([]); - }); - - it('should handle empty server response', function () { - const res = { - 'ads': [] - }; - const resp = spec.interpretResponse({ body: res }, {}); - expect(resp).to.deep.equal([]); - }); - - it('should generate auctionConfig when fledge is enabled', function () { - const bidRequest = { - method: 'GET', - url: 'https://example.com', - bidIds: [{ - slot: 'top', - bidId: '123', - network: 'testnetwork', - sizes: ['300x250'], - params: { - site: 'testsite', - area: 'testarea', - network: 'testnetwork' - }, - fledgeEnabled: true - }, - { - slot: 'top', - bidId: '456', - network: 'testnetwork', - sizes: ['300x250'], - params: { - site: 'testsite', - area: 'testarea', - network: 'testnetwork' - }, - fledgeEnabled: false - }] - }; - - const auctionConfigs = [{ - 'bidId': '123', - 'config': { - 'seller': 'https://csr.onet.pl', - 'decisionLogicUrl': 'https://csr.onet.pl/testnetwork/v1/protected-audience-api/decision-logic.js', - 'interestGroupBuyers': ['https://csr.onet.pl'], - 'auctionSignals': { - 'params': { - site: 'testsite', - area: 'testarea', - network: 'testnetwork' - }, - 'sizes': ['300x250'], - 'gctx': '1234567890' - } - } - }]; - const resp = spec.interpretResponse({body: {gctx: '1234567890'}}, bidRequest); - expect(resp).to.deep.equal({bids: [], paapi: auctionConfigs}); - }); - }); - - describe('buildNativeRequests', function () { - const bid = { - sizes: 'fluid', - bidder: 'ringieraxelspringer', - bidId: 1, - params: { - slot: 'nativestd', - area: 'areatest', - site: 'test', - slotSequence: '0', - network: '4178463', - customParams: { - test: 'name=value' - } - }, - mediaTypes: { - native: { - clickUrl: { - required: true - }, - image: { - required: true - }, - sponsoredBy: { - len: 25, - required: true - }, - title: { - len: 50, - required: true - } - } - } - }; - - it('should parse bids to native request', function () { - const requests = spec.buildRequests([bid], { - 'gdprConsent': { - 'gdprApplies': true, - 'consentString': 'some-consent-string' - }, - 'refererInfo': { - 'ref': 'https://example.org/', - 'page': 'https://example.com/' - } - }); - - expect(requests[0].url).to.have.string(CSR_ENDPOINT); - expect(requests[0].url).to.have.string('slot0=nativestd'); - expect(requests[0].url).to.have.string('id0=1'); - expect(requests[0].url).to.have.string('site=test'); - expect(requests[0].url).to.have.string('area=areatest'); - expect(requests[0].url).to.have.string('cre_format=html'); - expect(requests[0].url).to.have.string('systems=das'); - expect(requests[0].url).to.have.string('ems_url=1'); - expect(requests[0].url).to.have.string('bid_rate=1'); - expect(requests[0].url).to.have.string('gdpr_applies=true'); - expect(requests[0].url).to.have.string('euconsent=some-consent-string'); - expect(requests[0].url).to.have.string('du=https%3A%2F%2Fexample.com%2F'); - expect(requests[0].url).to.have.string('dr=https%3A%2F%2Fexample.org%2F'); - expect(requests[0].url).to.have.string('test=name%3Dvalue'); - expect(requests[0].url).to.have.string('cre_format0=native'); - expect(requests[0].url).to.have.string('kvhb_format0=native'); - expect(requests[0].url).to.have.string('iusizes0=fluid'); - }); - }); - - describe('interpretNativeResponse', function () { - const response = { - 'adsCheck': 'ok', - 'geoloc': {}, - 'ir': '92effd60-0c84-4dac-817e-763ea7b8ac65', - 'iv': '202003191334467636346500', - 'ads': [ - { - 'id': 'nativestd', - 'slot': 'nativestd', - 'prio': 10, - 'type': 'native', - 'bid_rate': 0.321123, - 'adid': 'das,50463,152276', - 'id_3': '12734' - } - ] - }; - const responseTeaserStandard = { - adsCheck: 'ok', - geoloc: {}, - ir: '92effd60-0c84-4dac-817e-763ea7b8ac65', - iv: '202003191334467636346500', - ads: [ - { - id: 'nativestd', - slot: 'nativestd', - prio: 10, - type: 'native', - bid_rate: 0.321123, - adid: 'das,50463,152276', - id_3: '12734', - data: { - fields: { - leadtext: 'BODY', - title: 'Headline', - image: '//img.url', - url: '//link.url', - partner_logo: '//logo.url', - adInfo: 'REKLAMA', - impression: '//impression.url', - impression1: '//impression1.url', - impressionJs1: '//impressionJs1.url' - }, - meta: { - slot: 'nativestd', - height: 1, - width: 1, - advertiser_name: 'Test Onet', - dsaurl: '//dsa.url', - adclick: '//adclick.url' - } - }, - ems_link: '//ems.url' - } - ] - }; - const responseNativeInFeed = { - adsCheck: 'ok', - geoloc: {}, - ir: '92effd60-0c84-4dac-817e-763ea7b8ac65', - iv: '202003191334467636346500', - ads: [ - { - id: 'nativestd', - slot: 'nativestd', - prio: 10, - type: 'native', - bid_rate: 0.321123, - adid: 'das,50463,152276', - id_3: '12734', - data: { - fields: { - Body: 'BODY', - Calltoaction: 'Calltoaction', - Headline: 'Headline', - Image: '//img.url', - adInfo: 'REKLAMA', - Thirdpartyclicktracker: '//link.url', - imp: '//imp.url', - thirdPartyClickTracker2: '//thirdPartyClickTracker.url' - }, - meta: { - slot: 'nativestd', - height: 1, - width: 1, - advertiser_name: 'Test Onet', - dsaurl: '//dsa.url', - adclick: '//adclick.url' - } - }, - ems_link: '//ems.url' - } - ] - }; - const expectedTeaserStandardOrtbResponse = { - ver: '1.2', - assets: [ - { - id: 0, - data: { - value: '', - type: 2 - }, - }, - { - id: 1, - data: { - value: 'REKLAMA', - type: 10 - }, - }, - { - id: 3, - img: { - type: 1, - url: '//logo.url', - w: 1, - h: 1 - } - }, - { - id: 4, - img: { - type: 3, - url: '//img.url', - w: 1, - h: 1 - } - }, - { - id: 5, - data: { - value: 'Test Onet', - type: 1 - }, - }, - { - id: 6, - title: { - text: 'Headline' - } - }, - ], - link: { - url: '//adclick.url//link.url', - clicktrackers: [] - }, - eventtrackers: [ - { - event: 1, - method: 1, - url: '//ems.url' - }, - { - event: 1, - method: 1, - url: '//impression.url' - }, - { - event: 1, - method: 1, - url: '//impression1.url' - }, - { - event: 1, - method: 2, - url: '//impressionJs1.url' - } - ], - privacy: '//dsa.url' - }; - const expectedTeaserStandardResponse = { - title: 'Headline', - image: { - url: '//img.url', - width: 1, - height: 1 - }, - icon: { - url: '//logo.url', - width: 1, - height: 1 - }, - clickUrl: '//adclick.url//link.url', - cta: '', - body: 'BODY', - body2: 'REKLAMA', - sponsoredBy: 'Test Onet', - ortb: expectedTeaserStandardOrtbResponse, - privacyLink: '//dsa.url' - }; - const expectedNativeInFeedOrtbResponse = { - ver: '1.2', - assets: [ - { - id: 0, - data: { - value: '', - type: 2 - }, - }, - { - id: 1, - data: { - value: 'REKLAMA', - type: 10 - }, - }, - { - id: 3, - img: { - type: 1, - url: '', - w: 1, - h: 1 - } - }, - { - id: 4, - img: { - type: 3, - url: '//img.url', - w: 1, - h: 1 - } - }, - { - id: 5, - data: { - value: 'Test Onet', - type: 1 - }, - }, - { - id: 6, - title: { - text: 'Headline' - } - }, - ], - link: { - url: '//adclick.url//link.url', - clicktrackers: ['//thirdPartyClickTracker.url'] - }, - eventtrackers: [ - { - event: 1, - method: 1, - url: '//ems.url' - }, - { - event: 1, - method: 1, - url: '//imp.url' - } - ], - privacy: '//dsa.url', - }; - const expectedNativeInFeedResponse = { - title: 'Headline', - image: { - url: '//img.url', - width: 1, - height: 1 - }, - icon: { - url: '', - width: 1, - height: 1 - }, - clickUrl: '//adclick.url//link.url', - cta: 'Calltoaction', - body: 'BODY', - body2: 'REKLAMA', - sponsoredBy: 'Test Onet', - ortb: expectedNativeInFeedOrtbResponse, - privacyLink: '//dsa.url' - }; - - it('should get correct bid native response', function () { - const resp = spec.interpretResponse({ body: response }, { bidIds: [{ slot: 'nativestd', bidId: 1, mediaType: 'native' }] }); - - expect(resp[0]).to.have.all.keys('cpm', 'currency', 'netRevenue', 'requestId', 'ttl', 'width', 'height', 'creativeId', 'dealId', 'meta', 'actgMatch', 'mediaType', 'native'); - expect(resp.length).to.equal(1); - }); - - it('should get correct native response for TeaserStandard', function () { - const resp = spec.interpretResponse({ body: responseTeaserStandard }, { bidIds: [{ slot: 'nativestd', bidId: 1, mediaType: 'native' }] }); - const teaserStandardResponse = resp[0].native; - - expect(JSON.stringify(teaserStandardResponse)).to.equal(JSON.stringify(expectedTeaserStandardResponse)); - }); - - it('should get correct native response for NativeInFeed', function () { - const resp = spec.interpretResponse({ body: responseNativeInFeed }, { bidIds: [{ slot: 'nativestd', bidId: 1, mediaType: 'native' }] }); - const nativeInFeedResponse = resp[0].native; - - expect(JSON.stringify(nativeInFeedResponse)).to.equal(JSON.stringify(expectedNativeInFeedResponse)); - }); - }); -}); diff --git a/test/spec/modules/riseBidAdapter_spec.js b/test/spec/modules/riseBidAdapter_spec.js deleted file mode 100644 index 4f5de5a65..000000000 --- a/test/spec/modules/riseBidAdapter_spec.js +++ /dev/null @@ -1,795 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/riseBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import {BANNER, NATIVE, VIDEO} from '../../../src/mediaTypes.js'; -import * as utils from 'src/utils.js'; -import {decorateAdUnitsWithNativeParams} from '../../../src/native.js'; - -const ENDPOINT = 'https://hb.yellowblue.io/hb-multi'; -const TEST_ENDPOINT = 'https://hb.yellowblue.io/hb-multi-test'; -const RTB_DOMAIN_TEST = 'testseller.com'; -const RTB_DOMAIN_ENDPOINT = `https://${RTB_DOMAIN_TEST}/hb-multi`; -const RTB_DOMAIN_TEST_ENDPOINT = `https://${RTB_DOMAIN_TEST}/hb-multi-test`; -const TTL = 360; -/* eslint no-console: ["error", { allow: ["log", "warn", "error"] }] */ - -describe('riseAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('bid adapter', function () { - it('should have aliases', function () { - expect(spec.aliases).to.be.an('array').that.is.not.empty; - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [['640', '480']], - 'params': { - 'org': 'jdye8weeyirk00000001' - } - }; - - it('should return true when required params are passed', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not found', function () { - const newBid = Object.assign({}, bid); - delete newBid.params; - newBid.params = { - 'org': null - }; - expect(spec.isBidRequestValid(newBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[640, 480]], - 'params': { - 'org': 'jdye8weeyirk00000001', - }, - 'bidId': '299ffc8cca0b87', - 'loop': 1, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'video': { - 'playerSize': [[640, 480]], - 'context': 'instream', - 'plcmt': 1 - } - }, - }, - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'params': { - 'org': 'jdye8weeyirk00000001' - }, - 'bidId': '299ffc8cca0b87', - 'loop': 1, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'banner': { - } - }, - }, - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'params': { - 'org': 'jdye8weeyirk00000001' - }, - 'bidId': '299ffc8cca0b87', - 'loop': 1, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ 300, 250 ] - ] - }, - 'video': { - 'playerSize': [[640, 480]], - 'context': 'instream', - 'plcmt': 1 - }, - 'native': { - 'ortb': { - 'assets': [ - { - 'id': 1, - 'required': 1, - 'img': { - 'type': 3, - 'w': 300, - 'h': 200, - } - }, - { - 'id': 2, - 'required': 1, - 'title': { - 'len': 80 - } - }, - { - 'id': 3, - 'required': 1, - 'data': { - 'type': 1 - } - } - ] - } - }, - }, - } - ]; - - const testModeBidRequests = [ - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[640, 480]], - 'params': { - 'org': 'jdye8weeyirk00000001', - 'testMode': true - }, - 'bidId': '299ffc8cca0b87', - 'loop': 2, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - } - ]; - - const bidderRequest = { - bidderCode: 'rise', - ortb2: {device: {}}, - } - const placementId = '12345678'; - const api = [1, 2]; - const mimes = ['application/javascript', 'video/mp4', 'video/quicktime']; - const protocols = [2, 3, 5, 6]; - - it('sends the placementId to ENDPOINT via POST', function () { - bidRequests[0].params.placementId = placementId; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].placementId).to.equal(placementId); - }); - - it('sends the plcmt to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].plcmt).to.equal(1); - }); - - it('sends the is_wrapper parameter to ENDPOINT via POST', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('is_wrapper'); - expect(request.data.params.is_wrapper).to.equal(false); - }); - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('sends bid request to TEST ENDPOINT via POST', function () { - const request = spec.buildRequests(testModeBidRequests, bidderRequest); - expect(request.url).to.equal(TEST_ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('sends bid request to rtbDomain ENDPOINT via POST', function () { - bidRequests[0].params.rtbDomain = RTB_DOMAIN_TEST; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).to.equal(RTB_DOMAIN_ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('sends bid request to rtbDomain TEST ENDPOINT via POST', function () { - testModeBidRequests[0].params.rtbDomain = RTB_DOMAIN_TEST; - const request = spec.buildRequests(testModeBidRequests, bidderRequest); - expect(request.url).to.equal(RTB_DOMAIN_TEST_ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('should send the correct bid Id', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].bidId).to.equal('299ffc8cca0b87'); - }); - - it('should send the correct supported api array', function () { - bidRequests[0].mediaTypes.video.api = api; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].api).to.be.an('array'); - expect(request.data.bids[0].api).to.eql([1, 2]); - }); - - it('should send the correct mimes array', function () { - bidRequests[0].mediaTypes.video.mimes = mimes; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].mimes).to.be.an('array'); - expect(request.data.bids[0].mimes).to.eql(['application/javascript', 'video/mp4', 'video/quicktime']); - }); - - it('should send the correct protocols array', function () { - bidRequests[0].mediaTypes.video.protocols = protocols; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].protocols).to.be.an('array'); - expect(request.data.bids[0].protocols).to.eql([2, 3, 5, 6]); - }); - - it('should send the correct sizes array', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].sizes).to.be.an('array'); - expect(request.data.bids[0].sizes).to.equal(bidRequests[0].sizes) - expect(request.data.bids[1].sizes).to.be.an('array'); - expect(request.data.bids[1].sizes).to.equal(bidRequests[1].sizes) - expect(request.data.bids[2].sizes).to.be.an('array'); - expect(request.data.bids[2].sizes).to.eql(bidRequests[2].sizes) - }); - - it('should send nativeOrtbRequest in native bid request', function () { - decorateAdUnitsWithNativeParams(bidRequests) - const request = spec.buildRequests(bidRequests, bidderRequest); - assert.deepEqual(request.data.bids[2].nativeOrtbRequest, bidRequests[2].mediaTypes.native.ortb) - }); - - it('should send the correct media type', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].mediaType).to.equal(VIDEO) - expect(request.data.bids[1].mediaType).to.equal(BANNER) - expect(request.data.bids[2].mediaType.split(',')).to.include.members([VIDEO, NATIVE, BANNER]) - }); - - it('should respect syncEnabled option', function() { - config.setConfig({ - userSync: { - syncEnabled: false, - filterSettings: { - all: { - bidders: '*', - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('cs_method'); - }); - - it('should respect "iframe" filter settings', function () { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - iframe: { - bidders: [spec.code], - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'iframe'); - }); - - it('should respect "all" filter settings', function () { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - all: { - bidders: [spec.code], - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'iframe'); - }); - - it('should send the pixel user sync param if userSync is enabled and no "iframe" or "all" configs are present', function () { - config.resetConfig(); - config.setConfig({ - userSync: { - syncEnabled: true, - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'pixel'); - }); - - it('should respect total exclusion', function() { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - image: { - bidders: [spec.code], - filter: 'exclude' - }, - iframe: { - bidders: [spec.code], - filter: 'exclude' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('cs_method'); - }); - - it('should have us_privacy param if usPrivacy is available in the bidRequest', function () { - const bidderRequestWithUSP = Object.assign({uspConsent: '1YNN'}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithUSP); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('us_privacy', '1YNN'); - }); - - it('should have an empty us_privacy param if usPrivacy is missing in the bidRequest', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('us_privacy'); - }); - - it('should not send the gdpr param if gdprApplies is false in the bidRequest', function () { - const bidderRequestWithGDPR = Object.assign({gdprConsent: {gdprApplies: false}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('gdpr'); - expect(request.data.params).to.not.have.property('gdpr_consent'); - }); - - it('should send the gdpr param if gdprApplies is true in the bidRequest', function () { - const bidderRequestWithGDPR = Object.assign({gdprConsent: {gdprApplies: true, consentString: 'test-consent-string'}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('gdpr', true); - expect(request.data.params).to.have.property('gdpr_consent', 'test-consent-string'); - }); - - it('should not send the gpp param if gppConsent is false in the bidRequest', function () { - const bidderRequestWithoutGPP = Object.assign({gppConsent: false}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithoutGPP); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('gpp'); - expect(request.data.params).to.not.have.property('gpp_sid'); - }); - - it('should send the gpp param if gppConsent is true in the bidRequest', function () { - const bidderRequestWithGPP = Object.assign({gppConsent: {gppString: 'gpp-consent', applicableSections: [7]}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGPP); - console.log('request.data.params'); - console.log(request.data.params); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('gpp', 'gpp-consent'); - expect(request.data.params.gpp_sid[0]).to.be.equal(7); - }); - - it('should have schain param if it is available in the bidRequest', () => { - bidderRequest.ortb2 = { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [{ asi: 'indirectseller.com', sid: '00001', hp: 1 }], - } - } - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('schain', '1.0,1!indirectseller.com,00001,1,,,'); - }); - - it('should set flooPrice to getFloor.floor value if it is greater than params.floorPrice', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.getFloor = () => { - return { - currency: 'USD', - floor: 3.32 - } - } - bid.params.floorPrice = 0.64; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0]).to.be.an('object'); - expect(request.data.bids[0]).to.have.property('floorPrice', 3.32); - }); - - it('should set floorPrice to params.floorPrice value if it is greater than getFloor.floor', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.getFloor = () => { - return { - currency: 'USD', - floor: 0.8 - } - } - bid.params.floorPrice = 1.5; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0]).to.be.an('object'); - expect(request.data.bids[0]).to.have.property('floorPrice', 1.5); - }); - - it('should check sua param in bid request', function() { - const sua = { - 'platform': { - 'brand': 'macOS', - 'version': ['12', '4', '0'] - }, - 'browsers': [ - { - 'brand': 'Chromium', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Google Chrome', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Not;A=Brand', - 'version': [ '99', '0', '0', '0' ] - } - ], - 'mobile': 0, - 'model': '', - 'bitness': '64', - 'architecture': 'x86' - } - const bid = utils.deepClone(bidRequests[0]); - bid.ortb2 = { - 'device': { - 'sua': { - 'platform': { - 'brand': 'macOS', - 'version': [ '12', '4', '0' ] - }, - 'browsers': [ - { - 'brand': 'Chromium', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Google Chrome', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Not;A=Brand', - 'version': [ '99', '0', '0', '0' ] - } - ], - 'mobile': 0, - 'model': '', - 'bitness': '64', - 'architecture': 'x86' - } - } - } - const requestWithSua = spec.buildRequests([bid], bidderRequest); - const data = requestWithSua.data; - expect(data.bids[0].sua).to.exist; - expect(data.bids[0].sua).to.deep.equal(sua); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].sua).to.not.exist; - }); - - it('should send ORTB2 device data in bid request', function() { - const ortb2 = { - device: { - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - ext: {fiftyonedegrees_deviceId: '17595-133085-133468-18092'}, - }, - }; - - const request = spec.buildRequests(bidRequests, { - ...bidderRequest, - ortb2, - }); - - expect(request.data.params.device).to.deep.equal(ortb2.device); - }); - - describe('COPPA Param', function() { - it('should set coppa equal 0 in bid request if coppa is set to false', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].coppa).to.be.equal(0); - }); - - it('should set coppa equal 1 in bid request if coppa is set to true', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.ortb2 = { - 'regs': { - 'coppa': true, - } - }; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0].coppa).to.be.equal(1); - }); - }); - }); - - describe('interpretResponse', function () { - const response = { - params: { - currency: 'USD', - netRevenue: true, - }, - bids: [{ - cpm: 12.5, - vastXml: '', - width: 640, - height: 480, - requestId: '21e12606d47ba7', - adomain: ['abc.com'], - creativeId: 'creative-id', - nurl: 'http://example.com/win/1234', - mediaType: VIDEO - }, - { - cpm: 12.5, - ad: '""', - width: 300, - height: 250, - requestId: '21e12606d47ba7', - adomain: ['abc.com'], - creativeId: 'creative-id', - nurl: 'http://example.com/win/1234', - mediaType: BANNER - }, - { - cpm: 12.5, - width: 300, - height: 200, - requestId: '21e12606d47ba7', - adomain: ['abc.com'], - creativeId: 'creative-id', - nurl: 'http://example.com/win/1234', - mediaType: NATIVE, - native: { - body: 'Advertise with Rise', - clickUrl: 'https://risecodes.com', - cta: 'Start now', - image: { - width: 300, - height: 200, - url: 'https://sdk.streamrail.com/media/rise-image.jpg' - }, - sponsoredBy: 'Rise', - title: 'Rise Ad Tech Solutions' - } - }] - }; - - const expectedVideoResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 640, - height: 480, - ttl: TTL, - creativeId: 'creative-id', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: VIDEO, - meta: { - mediaType: VIDEO, - advertiserDomains: ['abc.com'] - }, - vastXml: '', - }; - - const expectedBannerResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 300, - height: 250, - ttl: TTL, - creativeId: 'creative-id', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: BANNER, - meta: { - mediaType: BANNER, - advertiserDomains: ['abc.com'] - }, - ad: '""' - }; - - const expectedNativeResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 300, - height: 200, - ttl: TTL, - creativeId: 'creative-id', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: NATIVE, - meta: { - mediaType: NATIVE, - advertiserDomains: ['abc.com'] - }, - native: { - ortb: { - body: 'Advertise with Rise', - clickUrl: 'https://risecodes.com', - cta: 'Start now', - image: { - width: 300, - height: 200, - url: 'https://sdk.streamrail.com/media/rise-image.jpg', - }, - sponsoredBy: 'Rise', - title: 'Rise Ad Tech Solutions' - } - }, - }; - - it('should get correct bid response', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[0]).to.deep.equal(expectedVideoResponse); - expect(result[1]).to.deep.equal(expectedBannerResponse); - expect(result[2]).to.deep.equal(expectedNativeResponse); - }); - - it('video type should have vastXml key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[0].vastXml).to.equal(expectedVideoResponse.vastXml) - }); - - it('banner type should have ad key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[1].ad).to.equal(expectedBannerResponse.ad) - }); - - it('native type should have native key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[2].native).to.eql(expectedNativeResponse.native) - }); - }) - - describe('getUserSyncs', function() { - const imageSyncResponse = { - body: { - params: { - userSyncPixels: [ - 'https://image-sync-url.test/1', - 'https://image-sync-url.test/2', - 'https://image-sync-url.test/3' - ] - } - } - }; - - const iframeSyncResponse = { - body: { - params: { - userSyncURL: 'https://iframe-sync-url.test' - } - } - }; - - it('should register all img urls from the response', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true }, [imageSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'image', - url: 'https://image-sync-url.test/1' - }, - { - type: 'image', - url: 'https://image-sync-url.test/2' - }, - { - type: 'image', - url: 'https://image-sync-url.test/3' - } - ]); - }); - - it('should register the iframe url from the response', function() { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [iframeSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://iframe-sync-url.test' - } - ]); - }); - - it('should register both image and iframe urls from the responses', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, [iframeSyncResponse, imageSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://iframe-sync-url.test' - }, - { - type: 'image', - url: 'https://image-sync-url.test/1' - }, - { - type: 'image', - url: 'https://image-sync-url.test/2' - }, - { - type: 'image', - url: 'https://image-sync-url.test/3' - } - ]); - }); - - it('should handle an empty response', function() { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, []); - expect(syncs).to.deep.equal([]); - }); - - it('should handle when user syncs are disabled', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: false }, [imageSyncResponse]); - expect(syncs).to.deep.equal([]); - }); - }) - - describe('onBidWon', function() { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - - it('Should trigger pixel if bid nurl', function() { - const bid = { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [['640', '480']], - 'nurl': 'http://example.com/win/1234', - 'params': { - 'org': 'jdye8weeyirk00000001' - } - }; - - spec.onBidWon(bid); - expect(utils.triggerPixel.callCount).to.equal(1) - }) - }) -}); diff --git a/test/spec/modules/risemediatechBidAdapter_spec.js b/test/spec/modules/risemediatechBidAdapter_spec.js deleted file mode 100644 index d4d70017c..000000000 --- a/test/spec/modules/risemediatechBidAdapter_spec.js +++ /dev/null @@ -1,497 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/risemediatechBidAdapter.js'; - -describe('RiseMediaTech adapter', () => { - const validBidRequest = { - bidder: 'risemediatech', - params: { - publisherId: '12345', - adSlot: '/1234567/adunit', - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [728, 90]], - }, - }, - bidId: '1abc', - auctionId: '2def', - }; - - const bidderRequest = { - refererInfo: { - page: 'https://example.com', - }, - timeout: 3000, - gdprConsent: { - gdprApplies: true, - consentString: 'consent123', - }, - uspConsent: '1YNN', - }; - - const serverResponse = { - body: { - id: '2def', - seatbid: [ - { - bid: [ - { - id: '1abc', - impid: '1abc', - price: 1.5, - adm: '
Ad
', - w: 300, - h: 250, - crid: 'creative123', - adomain: ['example.com'], - }, - ], - }, - ], - }, - }; - - describe('isBidRequestValid', () => { - it('should return true for valid bid request', () => { - expect(spec.isBidRequestValid(validBidRequest)).to.equal(true); - }); - - it('should return false for invalid video bid request', () => { - const invalidVideoRequest = { - ...validBidRequest, - mediaTypes: { - video: { - mimes: [], - }, - }, - }; - expect(spec.isBidRequestValid(invalidVideoRequest)).to.equal(false); - }); - - it('should return false for video bid request with missing mimes', () => { - const invalidVideoRequest = { - ...validBidRequest, - mediaTypes: { - video: { - w: 640, - h: 480 - // mimes missing - } - } - }; - expect(spec.isBidRequestValid(invalidVideoRequest)).to.equal(false); - }); - - it('should return false for video request with invalid mimes (not an array)', () => { - const invalidBid = { - ...validBidRequest, - mediaTypes: { - video: { - mimes: 'video/mp4', // Not an array - w: 640, - h: 480 - } - } - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false for video request with empty mimes array', () => { - const invalidBid = { - ...validBidRequest, - mediaTypes: { - video: { - mimes: [], - w: 640, - h: 480 - } - } - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false for video request with width <= 0', () => { - const invalidBid = { - ...validBidRequest, - mediaTypes: { - video: { - mimes: ['video/mp4'], - w: 0, - h: 480 - } - } - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false for video request with height <= 0', () => { - const invalidBid = { - ...validBidRequest, - mediaTypes: { - video: { - mimes: ['video/mp4'], - w: 640, - h: -10 - } - } - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false for video bid request with invalid width', () => { - const invalidVideoRequest = { - ...validBidRequest, - mediaTypes: { - video: { - mimes: ['video/mp4'], - w: 0, - h: 480 - } - } - }; - expect(spec.isBidRequestValid(invalidVideoRequest)).to.equal(false); - }); - - it('should return false for video bid request with invalid height', () => { - const invalidVideoRequest = { - ...validBidRequest, - mediaTypes: { - video: { - mimes: ['video/mp4'], - w: 640, - h: 0 - } - } - }; - expect(spec.isBidRequestValid(invalidVideoRequest)).to.equal(false); - }); - }); - - describe('buildRequests', () => { - it('should build a valid server request', () => { - const request = spec.buildRequests([validBidRequest], bidderRequest); - expect(request).to.be.an('object'); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://dev-ads.risemediatech.com/ads/rtb/prebid/js'); - expect(request.data).to.be.an('object'); - }); - - it('should include GDPR and USP consent in the request', () => { - const request = spec.buildRequests([validBidRequest], bidderRequest); - const { regs, user } = request.data; - expect(regs.ext).to.have.property('gdpr', 1); - expect(user.ext).to.have.property('consent', 'consent123'); - expect(regs.ext).to.have.property('us_privacy', '1YNN'); - }); - - it('should include banner impressions in the request', () => { - const request = spec.buildRequests([validBidRequest], bidderRequest); - const { imp } = request.data; - expect(imp).to.be.an('array'); - expect(imp[0]).to.have.property('banner'); - expect(imp[0].banner).to.have.property('format').with.lengthOf(2); - }); - - it('should set request.test to 0 if bidderRequest.test is not provided', () => { - const request = spec.buildRequests([validBidRequest], { ...bidderRequest }); - expect(request.data.test).to.equal(0); - }); - - it('should set request.test to bidderRequest.test if provided', () => { - const testBidderRequest = { ...bidderRequest, test: 1 }; - const request = spec.buildRequests([validBidRequest], testBidderRequest); - expect(request.data.test).to.equal(1); - }); - - it('should build a video impression if only video mediaType is present', () => { - const videoBidRequest = { - ...validBidRequest, - mediaTypes: { - video: { - mimes: ['video/mp4'], - w: 640, - h: 480 - } - }, - params: { - ...validBidRequest.params, - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - startdelay: 0, - maxseq: 1, - poddur: 60, - protocols: [2, 3] - } - }; - const request = spec.buildRequests([videoBidRequest], bidderRequest); - const { imp } = request.data; - expect(imp[0]).to.have.property('video'); - expect(imp[0]).to.not.have.property('banner'); - expect(imp[0].video).to.include({ w: 640, h: 480 }); - expect(imp[0].video.mimes).to.include('video/mp4'); - }); - - it('should set gdpr to 0 if gdprApplies is false', () => { - const noGdprBidderRequest = { - ...bidderRequest, - gdprConsent: { - gdprApplies: false, - consentString: 'consent123' - } - }; - const request = spec.buildRequests([validBidRequest], noGdprBidderRequest); - expect(request.data.regs.ext).to.have.property('gdpr', 0); - expect(request.data.user.ext).to.have.property('consent', 'consent123'); - }); - - it('should set regs and regs.ext to {} if not already set when only USP consent is present', () => { - const onlyUspBidderRequest = { - ...bidderRequest, - gdprConsent: undefined, - uspConsent: '1YNN' - }; - const request = spec.buildRequests([validBidRequest], onlyUspBidderRequest); - expect(request.data.regs).to.be.an('object'); - expect(request.data.regs.ext).to.be.an('object'); - expect(request.data.regs.ext).to.have.property('us_privacy', '1YNN'); - }); - }); - - describe('interpretResponse', () => { - it('should interpret the server response correctly', () => { - const request = spec.buildRequests([validBidRequest], bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - expect(bids).to.be.an('array').with.lengthOf(1); - const bid = bids[0]; - expect(bid).to.have.property('requestId', '1abc'); - expect(bid).to.have.property('cpm', 1.5); - expect(bid).to.have.property('width', 300); - expect(bid).to.have.property('height', 250); - expect(bid).to.have.property('creativeId', 'creative123'); - expect(bid).to.have.property('currency', 'USD'); - expect(bid).to.have.property('netRevenue', true); - expect(bid).to.have.property('ttl', 60); - }); - - it('should return an empty array if no bids are present', () => { - const emptyResponse = { body: { seatbid: [] } }; - const request = spec.buildRequests([validBidRequest], bidderRequest); - const bids = spec.interpretResponse(emptyResponse, request); - expect(bids).to.be.an('array').with.lengthOf(0); - }); - - it('should interpret multiple seatbids as multiple bids', () => { - const multiSeatbidResponse = { - body: { - id: '2def', - seatbid: [ - { - bid: [ - { - id: '1abc', - impid: '1abc', - price: 1.5, - adm: '
Ad1
', - w: 300, - h: 250, - crid: 'creative123', - adomain: ['example.com'], - mtype: 1 - }, - ], - }, - { - bid: [ - { - id: '2bcd', - impid: '2bcd', - price: 2.0, - adm: '
Ad2
', - w: 728, - h: 90, - crid: 'creative456', - adomain: ['another.com'], - mtype: 2 - }, - ], - }, - ], - }, - }; - const request = spec.buildRequests([validBidRequest], bidderRequest); - const bids = spec.interpretResponse(multiSeatbidResponse, request); - expect(bids).to.be.an('array').with.lengthOf(2); - expect(bids[0]).to.have.property('requestId', '1abc'); - expect(bids[1]).to.have.property('requestId', '2bcd'); - expect(bids[0].mediaType).to.equal('banner'); - expect(bids[1].mediaType).to.equal('video'); - expect(bids[0]).to.have.property('cpm', 1.5); - expect(bids[1]).to.have.property('cpm', 2.0); - }); - - it('should set mediaType to banner if mtype is missing', () => { - const responseNoMtype = { - body: { - id: '2def', - seatbid: [ - { - bid: [ - { - id: '1abc', - impid: '1abc', - price: 1.5, - adm: '
Ad
', - w: 300, - h: 250, - crid: 'creative123', - adomain: ['example.com'] - // mtype missing - } - ] - } - ] - } - }; - const request = spec.buildRequests([validBidRequest], bidderRequest); - const bids = spec.interpretResponse(responseNoMtype, request); - expect(bids[0].mediaType).to.equal('banner'); - }); - - it('should set meta.advertiserDomains to an empty array if adomain is missing', () => { - const responseWithoutAdomain = { - body: { - id: '2def', - seatbid: [ - { - bid: [ - { - id: '1abc', - impid: '1abc', - price: 1.5, - adm: '
Ad
', - w: 300, - h: 250, - crid: 'creative123' - // adomain is missing - } - ] - } - ] - } - }; - const request = spec.buildRequests([validBidRequest], bidderRequest); - const bids = spec.interpretResponse(responseWithoutAdomain, request); - expect(bids[0].meta.advertiserDomains).to.be.an('array').that.is.empty; - }); - - it('should return an empty array and warn if server response is undefined', () => { - const request = spec.buildRequests([validBidRequest], bidderRequest); - const bids = spec.interpretResponse(undefined, request); - expect(bids).to.be.an('array').that.is.empty; - }); - - it('should return an empty array and warn if server response body is missing', () => { - const request = spec.buildRequests([validBidRequest], bidderRequest); - const bids = spec.interpretResponse({}, request); - expect(bids).to.be.an('array').that.is.empty; - }); - - it('should return bids from converter if present', () => { - const request = spec.buildRequests([validBidRequest], bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - expect(bids).to.be.an('array').with.lengthOf(1); - }); - - it('should log a warning and not set mediaType for unknown mtype', () => { - const responseWithUnknownMtype = { - body: { - id: '2def', - seatbid: [ - { - bid: [ - { - id: '1abc', - impid: '1abc', - price: 1.5, - adm: '
Ad
', - w: 300, - h: 250, - crid: 'creative123', - adomain: ['example.com'], - mtype: 999, // Unknown mtype - }, - ], - }, - ], - }, - }; - const request = spec.buildRequests([validBidRequest], bidderRequest); - const bids = spec.interpretResponse(responseWithUnknownMtype, request); - expect(bids).to.be.an('array').with.lengthOf(1); - expect(bids[0].meta).to.not.have.property('mediaType'); - }); - - it('should include dealId if present in the bid response', () => { - const responseWithDealId = { - body: { - id: '2def', - seatbid: [ - { - bid: [ - { - id: '1abc', - impid: '1abc', - price: 1.5, - adm: '
Ad
', - w: 300, - h: 250, - crid: 'creative123', - adomain: ['example.com'], - dealid: 'deal123', - }, - ], - }, - ], - }, - }; - const request = spec.buildRequests([validBidRequest], bidderRequest); - const bids = spec.interpretResponse(responseWithDealId, request); - expect(bids).to.be.an('array').with.lengthOf(1); - expect(bids[0]).to.have.property('dealId', 'deal123'); - }); - - it('should handle bids with missing price gracefully', () => { - const responseWithoutPrice = { - body: { - id: '2def', - seatbid: [ - { - bid: [ - { - id: '1abc', - impid: '1abc', - adm: '
Ad
', - w: 300, - h: 250, - crid: 'creative123', - adomain: ['example.com'], - }, - ], - }, - ], - }, - }; - const request = spec.buildRequests([validBidRequest], bidderRequest); - const bids = spec.interpretResponse(responseWithoutPrice, request); - expect(bids).to.be.an('array').that.is.not.empty; - }); - }); - - describe('getUserSyncs', () => { - it('should return null as user syncs are not implemented', () => { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [], bidderRequest.gdprConsent, bidderRequest.uspConsent); - expect(syncs).to.be.null; - }); - }); -}); diff --git a/test/spec/modules/rivrAnalyticsAdapter_spec.js b/test/spec/modules/rivrAnalyticsAdapter_spec.js deleted file mode 100644 index 1192d1ba6..000000000 --- a/test/spec/modules/rivrAnalyticsAdapter_spec.js +++ /dev/null @@ -1,149 +0,0 @@ -import * as utils from 'src/utils.js'; -import analyticsAdapter, { - sendImpressions, - handleClickEventWithClosureScope, - createUnOptimisedParamsField, - dataLoaderForHandler, - pinHandlerToHTMLElement, - setAuctionAbjectPosition, - createNewAuctionObject, - concatAllUnits, - trackAuctionEnd, - handleImpression, - getCookie, - storeAndReturnRivrUsrIdCookie, - arrayDifference, - activelyWaitForBannersToRender} from 'modules/rivrAnalyticsAdapter.js'; - -import {expect} from 'chai'; -import adapterManager from 'src/adapterManager.js'; -import * as ajax from 'src/ajax.js'; -import { EVENTS } from 'src/constants.js'; - -const events = require('../../../src/events.js'); - -describe('RIVR Analytics adapter', () => { - const EXPIRING_QUEUE_TIMEOUT = 4000; - const EXPIRING_QUEUE_TIMEOUT_MOCK = 100; - const RVR_CLIENT_ID_MOCK = 'aCliendId'; - const SITE_CATEGORIES_MOCK = ['cat1', 'cat2']; - const EMITTED_AUCTION_ID = 1; - const TRACKER_BASE_URL_MOCK = 'tracker.rivr.simplaex.com'; - const UUID_REG_EXP = new RegExp('[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}', 'i'); - const MOCK_RIVRADDON_CONTEXT = {}; - let sandbox; - let ajaxStub; - let rivraddonsEnableAnalyticsStub; - let rivraddonsTrackPbjsEventStub; - let timer; - - before(() => { - sandbox = sinon.createSandbox(); - window.rivraddon = { - analytics: { - enableAnalytics: () => {}, - getContext: () => { return MOCK_RIVRADDON_CONTEXT; }, - trackPbjsEvent: () => {}, - } - }; - rivraddonsEnableAnalyticsStub = sandbox.stub(window.rivraddon.analytics, 'enableAnalytics'); - }); - - beforeEach(() => { - timer = sandbox.useFakeTimers(0); - ajaxStub = sandbox.stub(ajax, 'ajax'); - sinon.stub(events, 'getEvents').returns([]); - - adapterManager.registerAnalyticsAdapter({ - code: 'rivr', - adapter: analyticsAdapter - }); - adapterManager.enableAnalytics({ - provider: 'rivr', - options: { - clientID: RVR_CLIENT_ID_MOCK, - adUnits: [utils.deepClone(BANNER_AD_UNITS_MOCK)], - siteCategories: SITE_CATEGORIES_MOCK, - } - }); - }); - - afterEach(() => { - analyticsAdapter.disableAnalytics(); - events.getEvents.restore(); - ajaxStub.restore(); - timer.restore(); - }); - - after(() => { - sandbox.restore(); - delete window.rivraddon; - }); - - it('enableAnalytics - should call rivraddon enableAnalytics with the correct arguments', () => { - // adapterManager.enableAnalytics() is called in beforeEach. If just called here it doesn't seem to work. - const firstArgument = rivraddonsEnableAnalyticsStub.getCall(0).args[0]; - const secondArgument = rivraddonsEnableAnalyticsStub.getCall(0).args[1]; - - expect(firstArgument.provider).to.be.equal('rivr'); - - expect(secondArgument).to.have.property('utils'); - expect(secondArgument).to.have.property('ajax'); - }); - - it('Firing an event when rivraddon context is not defined it should do nothing', () => { - const rivraddonsGetContextStub = sandbox.stub(window.rivraddon.analytics, 'getContext'); - rivraddonsTrackPbjsEventStub = sandbox.stub(window.rivraddon.analytics, 'trackPbjsEvent'); - - expect(rivraddonsTrackPbjsEventStub.callCount).to.be.equal(0); - - events.emit(EVENTS.AUCTION_INIT, { auctionId: EMITTED_AUCTION_ID, config: {}, timeout: 3000 }); - - expect(rivraddonsTrackPbjsEventStub.callCount).to.be.equal(0); - - window.rivraddon.analytics.getContext.restore(); - window.rivraddon.analytics.trackPbjsEvent.restore(); - }); - - it('Firing AUCTION_INIT should call rivraddon trackPbjsEvent passing the parameters', () => { - rivraddonsTrackPbjsEventStub = sandbox.stub(window.rivraddon.analytics, 'trackPbjsEvent'); - - expect(rivraddonsTrackPbjsEventStub.callCount).to.be.equal(0); - - events.emit(EVENTS.AUCTION_INIT, { auctionId: EMITTED_AUCTION_ID, config: {}, timeout: 3000 }); - - expect(rivraddonsTrackPbjsEventStub.callCount).to.be.equal(1); - - const firstArgument = rivraddonsTrackPbjsEventStub.getCall(0).args[0]; - expect(firstArgument.eventType).to.be.equal(EVENTS.AUCTION_INIT); - expect(firstArgument.args.auctionId).to.be.equal(EMITTED_AUCTION_ID); - - window.rivraddon.analytics.trackPbjsEvent.restore(); - }); - - const BANNER_AD_UNITS_MOCK = [ - { - code: 'banner-container1', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 200], [300, 600]] - } - }, - bids: [ - { - bidder: 'appnexus', - params: { - placementId: '10433394', - reserve: 0.5 - } - }, - { - bidder: 'huddledmasses', - params: { - placement_id: 0 - } - }, - ] - } - ]; -}); diff --git a/test/spec/modules/rixengineBidAdapter_spec.js b/test/spec/modules/rixengineBidAdapter_spec.js deleted file mode 100644 index c20423879..000000000 --- a/test/spec/modules/rixengineBidAdapter_spec.js +++ /dev/null @@ -1,141 +0,0 @@ -import { spec } from 'modules/rixengineBidAdapter.js'; -const ENDPOINT = 'http://demo.svr.rixengine.com/rtb?sid=36540&token=1e05a767930d7d96ef6ce16318b4ab99'; - -const REQUEST = [ - { - adUnitCode: 'adUnitCode1', - bidId: 'bidId1', - auctionId: 'auctionId-56a2-4f71-9098-720a68f2f708', - mediaTypes: { - banner: {}, - }, - bidder: 'rixengine', - params: { - endpoint: 'http://demo.svr.rixengine.com/rtb', - token: '1e05a767930d7d96ef6ce16318b4ab99', - sid: '36540', - }, - }, -]; - -const RESPONSE = { - headers: null, - body: { - id: 'requestId', - bidid: 'bidId1', - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: 'bidId1', - impid: 'bidId1', - adm: '', - cid: '24:17:18', - crid: '40_37_66:30_32_132:31_27_70', - adomain: ['www.rixengine.com'], - price: 10.00, - bundle: - 'com.xinggame.cast.video.screenmirroring.casttotv:https://www.greysa.com.tw/Product/detail/pid/119/?utm_source=popIn&utm_medium=cpc&utm_campaign=neck_202307_300*250:https://www.avaige.top/', - iurl: 'https://crs.rixbeedesk.com/test/kkd2ms/04c6d62912cff9037106fb50ed21b558.png:https://crs.rixbeedesk.com/test/kkd2ms/69a72b23c6c52e703c0c8e3f634e44eb.png:https://crs.rixbeedesk.com/test/kkd2ms/d229c5cd66bcc5856cb26bb2817718c9.png', - w: 300, - h: 250, - exp: 30, - }, - ], - seat: 'Zh2Kiyk=', - }, - ], - }, -}; - -describe('rixengine bid adapter', function () { - describe('isBidRequestValid', function () { - const bid = { - bidder: 'rixengine', - params: { - endpoint: 'http://demo.svr.rixengine.com/rtb', - token: '1e05a767930d7d96ef6ce16318b4ab99', - sid: '36540', - }, - }; - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should return false when missing endpoint', function () { - delete bid.params.endpoint; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false when missing sid', function () { - delete bid.params.sid; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - it('should return false when missing token', function () { - delete bid.params.token; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - describe('buildRequests', function () { - it('creates request data', function () { - const request = spec.buildRequests(REQUEST, { - refererInfo: { - page: 'page', - }, - })[0]; - expect(request).to.exist.and.to.be.a('object'); - }); - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(REQUEST, {})[0]; - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - }); - - describe('interpretResponse', function () { - it('has bids', function () { - const request = spec.buildRequests(REQUEST, {})[0]; - const bids = spec.interpretResponse(RESPONSE, request); - expect(bids).to.be.an('array').that.is.not.empty; - validateBidOnIndex(0); - - function validateBidOnIndex(index) { - expect(bids[index]).to.have.property('currency', 'USD'); - expect(bids[index]).to.have.property( - 'requestId', - RESPONSE.body.seatbid[0].bid[index].id - ); - expect(bids[index]).to.have.property( - 'cpm', - RESPONSE.body.seatbid[0].bid[index].price - ); - expect(bids[index]).to.have.property( - 'width', - RESPONSE.body.seatbid[0].bid[index].w - ); - expect(bids[index]).to.have.property( - 'height', - RESPONSE.body.seatbid[0].bid[index].h - ); - expect(bids[index]).to.have.property( - 'ad', - RESPONSE.body.seatbid[0].bid[index].adm - ); - expect(bids[index]).to.have.property( - 'creativeId', - RESPONSE.body.seatbid[0].bid[index].crid - ); - expect(bids[index]).to.have.property('ttl', 30); - expect(bids[index]).to.have.property('netRevenue', true); - } - }); - - it('handles empty response', function () { - it('No bid response', function() { - var noBidResponse = spec.interpretResponse({ - body: '', - }); - expect(noBidResponse.length).to.equal(0); - }); - }); - }); -}); diff --git a/test/spec/modules/robustAppsBidAdapter_spec.js b/test/spec/modules/robustAppsBidAdapter_spec.js deleted file mode 100644 index 931d50023..000000000 --- a/test/spec/modules/robustAppsBidAdapter_spec.js +++ /dev/null @@ -1,441 +0,0 @@ -import {expect} from 'chai'; -import {config} from 'src/config.js'; -import {spec} from 'modules/robustAppsBidAdapter.js'; -import {deepClone} from 'src/utils'; -import {getBidFloor} from '../../../libraries/xeUtils/bidderUtils.js'; - -const ENDPOINT = 'https://pbjs.rbstsystems.live'; - -const defaultRequest = { - tmax: 0, - adUnitCode: 'test', - bidId: '1', - requestId: 'qwerty', - ortb2: { - source: { - tid: 'auctionId' - } - }, - ortb2Imp: { - ext: { - tid: 'tr1', - } - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 200] - ] - } - }, - bidder: 'robustApps', - params: { - pid: 'aa8217e20131c095fe9dba67981040b0', - ext: {} - }, - bidRequestsCount: 1 -}; - -const defaultRequestVideo = deepClone(defaultRequest); -defaultRequestVideo.mediaTypes = { - video: { - playerSize: [640, 480], - context: 'instream', - skipppable: true - } -}; - -const videoBidderRequest = { - bidderCode: 'robustApps', - bids: [{mediaTypes: {video: {}}, bidId: 'qwerty'}] -}; - -const displayBidderRequest = { - bidderCode: 'robustApps', - bids: [{bidId: 'qwerty'}] -}; - -describe('robustAppsBidAdapter', () => { - describe('isBidRequestValid', function () { - it('should return false when request params is missing', function () { - const invalidRequest = deepClone(defaultRequest); - delete invalidRequest.params; - expect(spec.isBidRequestValid(invalidRequest)).to.equal(false); - }); - - it('should return false when required pid param is missing', function () { - const invalidRequest = deepClone(defaultRequest); - delete invalidRequest.params.pid; - expect(spec.isBidRequestValid(invalidRequest)).to.equal(false); - }); - - it('should return false when video.playerSize is missing', function () { - const invalidRequest = deepClone(defaultRequestVideo); - delete invalidRequest.mediaTypes.video.playerSize; - expect(spec.isBidRequestValid(invalidRequest)).to.equal(false); - }); - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(defaultRequest)).to.equal(true); - }); - }); - - describe('buildRequests', function () { - beforeEach(function () { - config.resetConfig(); - }); - - it('should send request with correct structure', function () { - const request = spec.buildRequests([defaultRequest], {}); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal(ENDPOINT + '/bid'); - expect(request.options).to.have.property('contentType').and.to.equal('application/json'); - expect(request).to.have.property('data'); - }); - - it('should build basic request structure', function () { - const request = JSON.parse(spec.buildRequests([defaultRequest], {}).data)[0]; - expect(request).to.have.property('tmax').and.to.equal(defaultRequest.tmax); - expect(request).to.have.property('bidId').and.to.equal(defaultRequest.bidId); - expect(request).to.have.property('auctionId').and.to.equal(defaultRequest.ortb2.source.tid); - expect(request).to.have.property('transactionId').and.to.equal(defaultRequest.ortb2Imp.ext.tid); - expect(request).to.have.property('tz').and.to.equal(new Date().getTimezoneOffset()); - expect(request).to.have.property('bc').and.to.equal(1); - expect(request).to.have.property('floor').and.to.equal(null); - expect(request).to.have.property('banner').and.to.deep.equal({sizes: [[300, 250], [300, 200]]}); - expect(request).to.have.property('gdprConsent').and.to.deep.equal({}); - expect(request).to.have.property('userEids').and.to.deep.equal([]); - expect(request).to.have.property('usPrivacy').and.to.equal(''); - expect(request).to.have.property('sizes').and.to.deep.equal(['300x250', '300x200']); - expect(request).to.have.property('ext').and.to.deep.equal({}); - expect(request).to.have.property('env').and.to.deep.equal({ - pid: 'aa8217e20131c095fe9dba67981040b0' - }); - expect(request).to.have.property('device').and.to.deep.equal({ - ua: navigator.userAgent, - lang: navigator.language - }); - }); - - it('should build request with schain', function () { - const schainRequest = deepClone(defaultRequest); - const bidderRequest = { - ortb2: { - source: { - ext: { - schain: { - ver: '1.0' - } - } - } - } - }; - const request = JSON.parse(spec.buildRequests([schainRequest], bidderRequest).data)[0]; - expect(request).to.have.property('schain').and.to.deep.equal({ - ver: '1.0' - }); - }); - - it('should build request with location', function () { - const bidderRequest = { - refererInfo: { - page: 'page', - location: 'location', - domain: 'domain', - ref: 'ref', - isAmp: false - } - }; - const request = JSON.parse(spec.buildRequests([defaultRequest], bidderRequest).data)[0]; - expect(request).to.have.property('location'); - const location = request.location; - expect(location).to.have.property('page').and.to.equal('page'); - expect(location).to.have.property('location').and.to.equal('location'); - expect(location).to.have.property('domain').and.to.equal('domain'); - expect(location).to.have.property('ref').and.to.equal('ref'); - expect(location).to.have.property('isAmp').and.to.equal(false); - }); - - it('should build request with ortb2 info', function () { - const ortb2Request = deepClone(defaultRequest); - ortb2Request.ortb2 = { - site: { - name: 'name' - } - }; - const request = JSON.parse(spec.buildRequests([ortb2Request], {}).data)[0]; - expect(request).to.have.property('ortb2').and.to.deep.equal({ - site: { - name: 'name' - } - }); - }); - - it('should build request with ortb2Imp info', function () { - const ortb2ImpRequest = deepClone(defaultRequest); - ortb2ImpRequest.ortb2Imp = { - ext: { - data: { - pbadslot: 'home1', - adUnitSpecificAttribute: '1' - } - } - }; - const request = JSON.parse(spec.buildRequests([ortb2ImpRequest], {}).data)[0]; - expect(request).to.have.property('ortb2Imp').and.to.deep.equal({ - ext: { - data: { - pbadslot: 'home1', - adUnitSpecificAttribute: '1' - } - } - }); - }); - - it('should build request with valid bidfloor', function () { - const bfRequest = deepClone(defaultRequest); - bfRequest.getFloor = () => ({floor: 5, currency: 'USD'}); - const request = JSON.parse(spec.buildRequests([bfRequest], {}).data)[0]; - expect(request).to.have.property('floor').and.to.equal(5); - }); - - it('should build request with usp consent data if applies', function () { - const bidderRequest = { - uspConsent: '1YA-' - }; - const request = JSON.parse(spec.buildRequests([defaultRequest], bidderRequest).data)[0]; - expect(request).to.have.property('usPrivacy').and.equals('1YA-'); - }); - - it('should build request with extended ids', function () { - const idRequest = deepClone(defaultRequest); - idRequest.userIdAsEids = [ - {source: 'adserver.org', uids: [{id: 'TTD_ID_FROM_USER_ID_MODULE', atype: 1, ext: {rtiPartner: 'TDID'}}]}, - {source: 'pubcid.org', uids: [{id: 'pubCommonId_FROM_USER_ID_MODULE', atype: 1}]} - ]; - const request = JSON.parse(spec.buildRequests([idRequest], {}).data)[0]; - expect(request).to.have.property('userEids').and.deep.equal(idRequest.userIdAsEids); - }); - - it('should build request with video', function () { - const request = JSON.parse(spec.buildRequests([defaultRequestVideo], {}).data)[0]; - expect(request).to.have.property('video').and.to.deep.equal({ - playerSize: [640, 480], - context: 'instream', - skipppable: true - }); - expect(request).to.have.property('sizes').and.to.deep.equal(['640x480']); - }); - }); - - describe('interpretResponse', function () { - it('should return empty bids', function () { - const serverResponse = { - body: { - data: null - } - }; - - const invalidResponse = spec.interpretResponse(serverResponse, {}); - expect(invalidResponse).to.be.an('array').that.is.empty; - }); - - it('should interpret valid response', function () { - const serverResponse = { - body: { - data: [{ - requestId: 'qwerty', - cpm: 1, - currency: 'USD', - width: 300, - height: 250, - ttl: 600, - meta: { - advertiserDomains: ['robustApps'] - }, - ext: { - pixels: [ - ['iframe', 'surl1'], - ['image', 'surl2'], - ] - } - }] - } - }; - - const validResponse = spec.interpretResponse(serverResponse, {bidderRequest: displayBidderRequest}); - const bid = validResponse[0]; - expect(validResponse).to.be.an('array').that.is.not.empty; - expect(bid.requestId).to.equal('qwerty'); - expect(bid.cpm).to.equal(1); - expect(bid.currency).to.equal('USD'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.ttl).to.equal(600); - expect(bid.meta).to.deep.equal({advertiserDomains: ['robustApps']}); - }); - - it('should interpret valid banner response', function () { - const serverResponse = { - body: { - data: [{ - requestId: 'qwerty', - cpm: 1, - currency: 'USD', - width: 300, - height: 250, - ttl: 600, - mediaType: 'banner', - creativeId: 'demo-banner', - ad: 'ad', - meta: {} - }] - } - }; - - const validResponseBanner = spec.interpretResponse(serverResponse, {bidderRequest: displayBidderRequest}); - const bid = validResponseBanner[0]; - expect(validResponseBanner).to.be.an('array').that.is.not.empty; - expect(bid.mediaType).to.equal('banner'); - expect(bid.creativeId).to.equal('demo-banner'); - expect(bid.ad).to.equal('ad'); - }); - - it('should interpret valid video response', function () { - const serverResponse = { - body: { - data: [{ - requestId: 'qwerty', - cpm: 1, - currency: 'USD', - width: 600, - height: 480, - ttl: 600, - mediaType: 'video', - creativeId: 'demo-video', - ad: 'vast-xml', - meta: {} - }] - } - }; - - const validResponseBanner = spec.interpretResponse(serverResponse, {bidderRequest: videoBidderRequest}); - const bid = validResponseBanner[0]; - expect(validResponseBanner).to.be.an('array').that.is.not.empty; - expect(bid.mediaType).to.equal('video'); - expect(bid.creativeId).to.equal('demo-video'); - expect(bid.ad).to.equal('vast-xml'); - }); - }); - - describe('getUserSyncs', function () { - it('shoukd handle no params', function () { - const opts = spec.getUserSyncs({}, []); - expect(opts).to.be.an('array').that.is.empty; - }); - - it('should return empty if sync is not allowed', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: false}); - expect(opts).to.be.an('array').that.is.empty; - }); - - it('should allow iframe sync', function () { - const opts = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: false}, [{ - body: { - data: [{ - requestId: 'qwerty', - ext: { - pixels: [ - ['iframe', 'surl1?a=b'], - ['image', 'surl2?a=b'], - ] - } - }] - } - }]); - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('iframe'); - expect(opts[0].url).to.equal('surl1?a=b&us_privacy=&gdpr=0&gdpr_consent='); - }); - - it('should allow pixel sync', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [{ - body: { - data: [{ - requestId: 'qwerty', - ext: { - pixels: [ - ['iframe', 'surl1?a=b'], - ['image', 'surl2?a=b'], - ] - } - }] - } - }]); - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('image'); - expect(opts[0].url).to.equal('surl2?a=b&us_privacy=&gdpr=0&gdpr_consent='); - }); - - it('should allow pixel sync and parse consent params', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [{ - body: { - data: [{ - requestId: 'qwerty', - ext: { - pixels: [ - ['iframe', 'surl1?a=b'], - ['image', 'surl2?a=b'], - ] - } - }] - } - }], { - gdprApplies: 1, - consentString: '1YA-' - }); - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('image'); - expect(opts[0].url).to.equal('surl2?a=b&us_privacy=&gdpr=1&gdpr_consent=1YA-'); - }); - }); - - describe('getBidFloor', function () { - it('should return null when getFloor is not a function', () => { - const bid = {getFloor: 2}; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when getFloor doesnt return an object', () => { - const bid = {getFloor: () => 2}; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when floor is not a number', () => { - const bid = { - getFloor: () => ({floor: 'string', currency: 'USD'}) - }; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return null when currency is not USD', () => { - const bid = { - getFloor: () => ({floor: 5, currency: 'EUR'}) - }; - const result = getBidFloor(bid); - expect(result).to.be.null; - }); - - it('should return floor value when everything is correct', () => { - const bid = { - getFloor: () => ({floor: 5, currency: 'USD'}) - }; - const result = getBidFloor(bid); - expect(result).to.equal(5); - }); - }); -}); diff --git a/test/spec/modules/robustaBidAdapter_spec.js b/test/spec/modules/robustaBidAdapter_spec.js deleted file mode 100644 index 811a0d1b3..000000000 --- a/test/spec/modules/robustaBidAdapter_spec.js +++ /dev/null @@ -1,150 +0,0 @@ -import { spec } from 'modules/robustaBidAdapter.js'; -import { config } from 'src/config.js'; -import { deepClone } from 'src/utils.js'; - -describe('robustaBidAdapter', function () { - const validBidRequest = { - bidId: 'bid123', - params: { - lineItemId: '12345' - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - }; - - const validBidderRequest = { - bidderCode: 'robusta', - auctionId: 'auction123', - bidderRequestId: 'req123', - timeout: 3000, - gdprConsent: { - consentString: 'BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA', - gdprApplies: true - } - }; - - const validServerResponse = { - body: { - id: 'auction123', - seatbid: [{ - bid: [{ - mtype: 1, - id: 'bid123', - impid: 'bid123', - price: 0.5, - adm: '
ad
', - w: 300, - h: 250, - crid: 'creative123' - }] - }], - cur: 'USD' - } - }; - - describe('isBidRequestValid', function () { - it('should return true when lineItemId is present', function () { - expect(spec.isBidRequestValid(validBidRequest)).to.be.true; - }); - - it('should return false when lineItemId is missing', function () { - const bid = deepClone(validBidRequest); - delete bid.params.lineItemId; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - it('should create request with correct structure', function () { - const requests = spec.buildRequests([validBidRequest], validBidderRequest); - - expect(requests).to.have.lengthOf(1); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal('//pbjs.baristartb.com/api/prebid'); - expect(requests[0].options.withCredentials).to.be.false; - }); - - it('should use custom rtbDomain if configured', function () { - config.setBidderConfig({ bidders: ['robusta'], config: { rtbDomain: 'custom.domain.com' } }); - const requests = config.runWithBidder(spec.code, () => spec.buildRequests([validBidRequest], validBidderRequest)); - - expect(requests[0].url).to.equal('//custom.domain.com/api/prebid'); - config.resetConfig(); - }); - - it('should include bid params in imp.ext.params', function () { - const requests = spec.buildRequests([validBidRequest], validBidderRequest); - const imp = requests[0].data.imp[0]; - - expect(imp.ext.params).to.deep.equal(validBidRequest.params); - }); - }); - - describe('interpretResponse', function () { - it('should return valid bid response', function () { - const request = spec.buildRequests([validBidRequest], validBidderRequest)[0]; - const result = spec.interpretResponse(validServerResponse, request); - - expect(result.bids).to.be.an('array'); - expect(result.bids).to.have.lengthOf(1); - expect(result.bids[0]).to.include({ - requestId: 'bid123', - cpm: 0.5, - width: 300, - height: 250, - ad: '
ad
', - creativeId: 'creative123', - netRevenue: true, - ttl: 30, - currency: 'USD' - }); - }); - - it('should return empty bids array if no valid bids', function () { - const emptyResponse = { body: { id: 'auction123', seatbid: [] } }; - const request = spec.buildRequests([validBidRequest], validBidderRequest)[0]; - const result = spec.interpretResponse(emptyResponse, request); - - expect(result.bids).to.be.an('array'); - expect(result.bids).to.have.lengthOf(0); - }); - }); - - describe('getUserSyncs', function () { - const gdprConsent = { - gdprApplies: true, - consentString: 'BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA' - }; - - it('should return iframe sync when iframeEnabled', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [], gdprConsent); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.include('//sync.baristartb.com/api/sync?'); - expect(syncs[0].url).to.include('gdpr=1'); - expect(syncs[0].url).to.include('gdpr_consent=BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA'); - }); - - it('should return pixel sync when pixelEnabled', function () { - const syncs = spec.getUserSyncs({ pixelEnabled: true }, [], gdprConsent); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('image'); - }); - - it('should use custom syncDomain if configured', function () { - config.setBidderConfig({ bidders: ['robusta'], config: { syncDomain: 'custom.sync.com' } }); - const syncs = config.runWithBidder(spec.code, () => spec.getUserSyncs({ iframeEnabled: true }, [], gdprConsent)); - expect(syncs[0].url).to.include('//custom.sync.com/api/sync?'); - config.resetConfig(); - }); - - it('should handle missing gdprConsent', function () { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, []); - expect(syncs[0].url).to.not.include('gdpr'); - expect(syncs[0].url).to.not.include('gdpr_consent'); - }); - }); -}); diff --git a/test/spec/modules/rocketlabBidAdapter_spec.js b/test/spec/modules/rocketlabBidAdapter_spec.js deleted file mode 100644 index fc162c679..000000000 --- a/test/spec/modules/rocketlabBidAdapter_spec.js +++ /dev/null @@ -1,597 +0,0 @@ -import { expect } from "chai"; -import { spec } from "../../../modules/rocketlabBidAdapter.js"; -import { BANNER, VIDEO, NATIVE } from "../../../src/mediaTypes.js"; -import { getUniqueIdentifierStr } from "../../../src/utils.js"; - -const bidder = "rocketlab"; - -describe("RocketLabBidAdapter", function () { - const userIdAsEids = [ - { - source: "test.org", - uids: [ - { - id: "01**********", - atype: 1, - ext: { - third: "01***********", - }, - }, - ], - }, - ]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]], - }, - }, - params: { - placementId: "testBanner", - }, - userIdAsEids, - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60, - }, - }, - params: { - placementId: "testVideo", - }, - userIdAsEids, - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true, - }, - body: { - required: true, - }, - icon: { - required: true, - size: [64, 64], - }, - }, - }, - }, - params: { - placementId: "testNative", - }, - userIdAsEids, - }, - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]], - }, - }, - params: {}, - }; - - const bidderRequest = { - uspConsent: "1---", - gdprConsent: { - consentString: - "COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw", - vendorData: {}, - }, - refererInfo: { - referer: "https://test.com", - }, - timeout: 500, - }; - - describe("isBidRequestValid", function () { - it("Should return true if there are bidId, params and key parameters present", function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it("Should return false if at least one of parameters is not present", function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe("buildRequests", function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it("Creates a ServerRequest object with method, URL and data", function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it("Returns POST method", function () { - expect(serverRequest.method).to.equal("POST"); - }); - - it("Returns general data valid", function () { - const data = serverRequest.data; - expect(data).to.be.an("object"); - expect(data).to.have.all.keys( - "deviceWidth", - "deviceHeight", - "language", - "secure", - "host", - "page", - "placements", - "coppa", - "ccpa", - "gdpr", - "tmax", - "bcat", - "badv", - "bapp", - "battr" - ); - expect(data.deviceWidth).to.be.a("number"); - expect(data.deviceHeight).to.be.a("number"); - expect(data.language).to.be.a("string"); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a("string"); - expect(data.page).to.be.a("string"); - expect(data.coppa).to.be.a("number"); - expect(data.gdpr).to.be.a("object"); - expect(data.ccpa).to.be.a("string"); - expect(data.tmax).to.be.a("number"); - expect(data.placements).to.have.lengthOf(3); - }); - - it("Returns valid placements", function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf([ - "testBanner", - "testVideo", - "testNative", - ]); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a("string"); - expect(placement.schain).to.be.an("object"); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal("publisher"); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an("array"); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an("array"); - break; - case VIDEO: - expect(placement.playerSize).to.be.an("array"); - expect(placement.minduration).to.be.an("number"); - expect(placement.maxduration).to.be.an("number"); - break; - case NATIVE: - expect(placement.native).to.be.an("object"); - break; - } - } - }); - - it("Returns valid endpoints", function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]], - }, - }, - params: { - endpointId: "testBanner", - }, - userIdAsEids, - }, - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf([ - "testBanner", - "testVideo", - "testNative", - ]); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a("string"); - expect(placement.schain).to.be.an("object"); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal("network"); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an("array"); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an("array"); - break; - case VIDEO: - expect(placement.playerSize).to.be.an("array"); - expect(placement.minduration).to.be.an("number"); - expect(placement.maxduration).to.be.an("number"); - break; - case NATIVE: - expect(placement.native).to.be.an("object"); - break; - } - } - }); - - it("Returns data with gdprConsent and without uspConsent", function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a("object"); - expect(data.gdpr).to.have.property("consentString"); - expect(data.gdpr).to.not.have.property("vendorData"); - expect(data.gdpr.consentString).to.equal( - bidderRequest.gdprConsent.consentString - ); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it("Returns data with uspConsent and without gdprConsent", function () { - bidderRequest.uspConsent = "1---"; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a("string"); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe("gpp consent", function () { - it("bidderRequest.gppConsent", () => { - bidderRequest.gppConsent = { - gppString: "abc123", - applicableSections: [8], - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an("object"); - expect(data).to.have.property("gpp"); - expect(data).to.have.property("gpp_sid"); - - delete bidderRequest.gppConsent; - }); - - it("bidderRequest.ortb2.regs.gpp", () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = "abc123"; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an("object"); - expect(data).to.have.property("gpp"); - expect(data).to.have.property("gpp_sid"); - }); - }); - - describe("interpretResponse", function () { - it("Should interpret banner response", function () { - const banner = { - body: [ - { - mediaType: "banner", - width: 300, - height: 250, - cpm: 0.4, - ad: "Test", - requestId: "23fhj33i987f", - ttl: 120, - creativeId: "2", - netRevenue: true, - currency: "USD", - dealId: "1", - meta: { - advertiserDomains: ["google.com"], - advertiserId: 1234, - }, - }, - ], - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an("array").that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys( - "requestId", - "cpm", - "width", - "height", - "ad", - "ttl", - "creativeId", - "netRevenue", - "currency", - "dealId", - "mediaType", - "meta" - ); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta) - .to.be.an("object") - .that.has.any.key("advertiserDomains"); - }); - it("Should interpret video response", function () { - const video = { - body: [ - { - vastUrl: "test.com", - mediaType: "video", - cpm: 0.5, - requestId: "23fhj33i987f", - ttl: 120, - creativeId: "2", - netRevenue: true, - currency: "USD", - dealId: "1", - meta: { - advertiserDomains: ["google.com"], - advertiserId: 1234, - }, - }, - ], - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an("array").that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys( - "requestId", - "cpm", - "vastUrl", - "ttl", - "creativeId", - "netRevenue", - "currency", - "dealId", - "mediaType", - "meta" - ); - expect(dataItem.requestId).to.equal("23fhj33i987f"); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal("test.com"); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal("2"); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal("USD"); - expect(dataItem.meta) - .to.be.an("object") - .that.has.any.key("advertiserDomains"); - }); - it("Should interpret native response", function () { - const native = { - body: [ - { - mediaType: "native", - native: { - clickUrl: "test.com", - title: "Test", - image: "test.com", - impressionTrackers: ["test.com"], - }, - ttl: 120, - cpm: 0.4, - requestId: "23fhj33i987f", - creativeId: "2", - netRevenue: true, - currency: "USD", - meta: { - advertiserDomains: ["google.com"], - advertiserId: 1234, - }, - }, - ], - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an("array").that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys( - "requestId", - "cpm", - "ttl", - "creativeId", - "netRevenue", - "currency", - "mediaType", - "native", - "meta" - ); - expect(dataItem.native).to.have.keys( - "clickUrl", - "impressionTrackers", - "title", - "image" - ); - expect(dataItem.requestId).to.equal("23fhj33i987f"); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal("test.com"); - expect(dataItem.native.title).to.equal("Test"); - expect(dataItem.native.image).to.equal("test.com"); - expect(dataItem.native.impressionTrackers).to.be.an("array").that.is.not - .empty; - expect(dataItem.native.impressionTrackers[0]).to.equal("test.com"); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal("2"); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal("USD"); - expect(dataItem.meta) - .to.be.an("object") - .that.has.any.key("advertiserDomains"); - }); - it("Should return an empty array if invalid banner response is passed", function () { - const invBanner = { - body: [ - { - width: 300, - cpm: 0.4, - ad: "Test", - requestId: "23fhj33i987f", - ttl: 120, - creativeId: "2", - netRevenue: true, - currency: "USD", - dealId: "1", - }, - ], - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an("array").that.is.empty; - }); - it("Should return an empty array if invalid video response is passed", function () { - const invVideo = { - body: [ - { - mediaType: "video", - cpm: 0.5, - requestId: "23fhj33i987f", - ttl: 120, - creativeId: "2", - netRevenue: true, - currency: "USD", - dealId: "1", - }, - ], - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an("array").that.is.empty; - }); - it("Should return an empty array if invalid native response is passed", function () { - const invNative = { - body: [ - { - mediaType: "native", - clickUrl: "test.com", - title: "Test", - impressionTrackers: ["test.com"], - ttl: 120, - requestId: "23fhj33i987f", - creativeId: "2", - netRevenue: true, - currency: "USD", - }, - ], - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an("array").that.is.empty; - }); - it("Should return an empty array if invalid response is passed", function () { - const invalid = { - body: [ - { - ttl: 120, - creativeId: "2", - netRevenue: true, - currency: "USD", - dealId: "1", - }, - ], - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an("array").that.is.empty; - }); - }); - - describe("getUserSyncs", function () { - it("Should return array of objects with proper sync config , include GDPR", function () { - const syncData = spec.getUserSyncs( - {}, - {}, - { - consentString: "ALL", - gdprApplies: true, - }, - {} - ); - expect(syncData).to.be.an("array").which.is.not.empty; - expect(syncData[0]).to.be.an("object"); - expect(syncData[0].type).to.be.a("string"); - expect(syncData[0].type).to.equal("image"); - expect(syncData[0].url).to.be.a("string"); - expect(syncData[0].url).to.equal( - "https://usync.rocketlab.ai/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0" - ); - }); - it("Should return array of objects with proper sync config , include CCPA", function () { - const syncData = spec.getUserSyncs( - {}, - {}, - {}, - { - consentString: "1---", - } - ); - expect(syncData).to.be.an("array").which.is.not.empty; - expect(syncData[0]).to.be.an("object"); - expect(syncData[0].type).to.be.a("string"); - expect(syncData[0].type).to.equal("image"); - expect(syncData[0].url).to.be.a("string"); - expect(syncData[0].url).to.equal( - "https://usync.rocketlab.ai/image?pbjs=1&ccpa_consent=1---&coppa=0" - ); - }); - it("Should return array of objects with proper sync config , include GPP", function () { - const syncData = spec.getUserSyncs( - {}, - {}, - {}, - {}, - { - gppString: "abc123", - applicableSections: [8], - } - ); - expect(syncData).to.be.an("array").which.is.not.empty; - expect(syncData[0]).to.be.an("object"); - expect(syncData[0].type).to.be.a("string"); - expect(syncData[0].type).to.equal("image"); - expect(syncData[0].url).to.be.a("string"); - expect(syncData[0].url).to.equal( - "https://usync.rocketlab.ai/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0" - ); - }); - }); -}); diff --git a/test/spec/modules/roxotAnalyticsAdapter_spec.js b/test/spec/modules/roxotAnalyticsAdapter_spec.js deleted file mode 100644 index 4882d6e7c..000000000 --- a/test/spec/modules/roxotAnalyticsAdapter_spec.js +++ /dev/null @@ -1,443 +0,0 @@ -import roxotAnalytic from 'modules/roxotAnalyticsAdapter.js'; -import {expect} from 'chai'; -import {server} from 'test/mocks/xhr.js'; -import { EVENTS } from 'src/constants.js'; - -const events = require('src/events'); - -describe('Roxot Prebid Analytic', function () { - const roxotConfigServerUrl = 'config-server'; - const roxotEventServerUrl = 'event-server'; - const publisherId = 'test_roxot_prebid_analytics_publisher_id'; - - const auctionId = '0ea14159-2058-4b87-a966-9d7652176a56'; - const timeout = 3000; - const auctionStartTimestamp = Date.now(); - const bidder = 'rubicon'; - - const bidAdUnit = 'div_with_bid'; - const noBidAdUnit = 'div_no_bid'; - const bidAfterTimeoutAdUnit = 'div_after_timeout'; - - const auctionInit = { - timestamp: auctionStartTimestamp, - auctionId: auctionId, - timeout: timeout - }; - - const bidRequested = { - auctionId: auctionId, - auctionStart: auctionStartTimestamp, - bidderCode: bidder, - bidderRequestId: '10340af0c7dc72', - bids: [ - { - adUnitCode: bidAdUnit, - auctionId: auctionId, - bidId: '298bf14ecbafb', - bidder: bidder, - bidderRequestId: '10340af0c7dc72', - sizes: [[300, 250]], - startTime: auctionStartTimestamp + 50, - transactionId: '7aafa3ee-a80a-46d7-a4a0-cbcba463d97a' - }, - { - adUnitCode: bidAfterTimeoutAdUnit, - auctionId: auctionId, - bidId: '36c6375e2dceba', - bidder: bidder, - bidderRequestId: '10340af0c7dc72', - sizes: [[300, 250]], - startTime: auctionStartTimestamp + 70, - transactionId: 'cf627df3-5828-4d3e-9dd0-c1733d328142' - }, - { - adUnitCode: noBidAdUnit, - auctionId: auctionId, - bidId: '36c6375e2dce21', - bidder: bidder, - bidderRequestId: '10340af0c7dc72', - sizes: [[300, 250]], - startTime: auctionStartTimestamp + 90, - transactionId: 'cf627df3-5828-4d3e-9dd0-c1737aafa3ee' - } - ], - doneCbCallCount: 1, - start: auctionStartTimestamp, - timeout: timeout - }; - - const bidAdjustmentWithBid = { - ad: 'html', - adId: '298bf14ecbafb', - adUnitCode: bidAdUnit, - auctionId: auctionId, - bidder: bidder, - bidderCode: bidder, - cpm: 1.01, - creativeId: '2249:92806132', - currency: 'USD', - height: 250, - mediaType: 'banner', - requestId: '298bf14ecbafb', - requestTimestamp: auctionStartTimestamp + 50, - responseTimestamp: auctionStartTimestamp + 50 + 421, - size: '300x250', - source: 'client', - status: 'rendered', - statusMessage: 'Bid available', - timeToRespond: 421, - ttl: 300, - width: 300 - }; - - const bidAdjustmentAfterTimeout = { - ad: 'html', - adId: '36c6375e2dceba', - adUnitCode: bidAfterTimeoutAdUnit, - auctionId: auctionId, - bidder: bidder, - bidderCode: bidder, - cpm: 2.02, - creativeId: '2249:92806132', - currency: 'USD', - height: 250, - mediaType: 'banner', - requestId: '36c6375e2dceba', - requestTimestamp: auctionStartTimestamp + 70, - responseTimestamp: auctionStartTimestamp + 70 + 6141, - size: '300x250', - source: 'client', - status: 'rendered', - statusMessage: 'Bid available', - timeToRespond: 6141, - ttl: 300, - width: 300 - }; - - const bidAdjustmentNoBid = { - ad: 'html', - adId: '36c6375e2dce21', - adUnitCode: noBidAdUnit, - auctionId: auctionId, - bidder: bidder, - bidderCode: bidder, - cpm: 0, - creativeId: '2249:92806132', - currency: 'USD', - height: 0, - mediaType: 'banner', - requestId: '36c6375e2dce21', - requestTimestamp: auctionStartTimestamp + 90, - responseTimestamp: auctionStartTimestamp + 90 + 215, - size: '300x250', - source: 'client', - status: 'rendered', - statusMessage: 'Bid available', - timeToRespond: 215, - ttl: 300, - width: 0 - }; - - const auctionEnd = { - auctionId: auctionId - }; - - const bidTimeout = [ - { - adUnitCode: bidAfterTimeoutAdUnit, - auctionId: auctionId, - bidId: '389444beed7361', - bidder: bidder, - timeout: timeout - } - ]; - - const bidResponseWithBid = bidAdjustmentWithBid; - const bidResponseAfterTimeout = bidAdjustmentAfterTimeout; - const bidResponseNoBid = bidAdjustmentNoBid; - const bidderDone = bidRequested; - const bidWon = bidAdjustmentWithBid; - - describe('correct build and send events', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - }); - afterEach(function () { - roxotAnalytic.disableAnalytics(); - events.getEvents.restore(); - }); - it('should send prepared events to backend', function () { - roxotAnalytic.enableAnalytics({ - provider: 'roxot', - options: { - publisherId: publisherId, - configServer: roxotConfigServerUrl, - server: roxotEventServerUrl - } - }); - - expect(server.requests.length).to.equal(1); - expect(server.requests[0].url).to.equal('https://' + roxotConfigServerUrl + '/c?publisherId=' + publisherId + '&host=localhost'); - server.requests[0].respond(200, {'Content-Type': 'application/json'}, '{"a": 1, "i": 1, "bat": 1}'); - - events.emit(EVENTS.AUCTION_INIT, auctionInit); - events.emit(EVENTS.BID_REQUESTED, bidRequested); - events.emit(EVENTS.BID_ADJUSTMENT, bidAdjustmentWithBid); - events.emit(EVENTS.BID_RESPONSE, bidResponseWithBid); - events.emit(EVENTS.BID_ADJUSTMENT, bidAdjustmentNoBid); - events.emit(EVENTS.BID_RESPONSE, bidResponseNoBid); - events.emit(EVENTS.BID_TIMEOUT, bidTimeout); - events.emit(EVENTS.AUCTION_END, auctionEnd); - events.emit(EVENTS.BID_ADJUSTMENT, bidAdjustmentAfterTimeout); - events.emit(EVENTS.BID_RESPONSE, bidResponseAfterTimeout); - events.emit(EVENTS.BIDDER_DONE, bidderDone); - events.emit(EVENTS.BID_WON, bidWon); - - expect(server.requests.length).to.equal(4); - - expect(server.requests[1].url).to.equal('https://' + roxotEventServerUrl + '/a?publisherId=' + publisherId + '&host=localhost'); - expect(server.requests[2].url).to.equal('https://' + roxotEventServerUrl + '/bat?publisherId=' + publisherId + '&host=localhost'); - expect(server.requests[3].url).to.equal('https://' + roxotEventServerUrl + '/i?publisherId=' + publisherId + '&host=localhost'); - - const auction = JSON.parse(server.requests[1].requestBody); - expect(auction).to.include.all.keys('event', 'eventName', 'options', 'data'); - expect(auction.event).to.equal('a'); - - expect(auction.data).to.include.all.keys('id', 'start', 'finish', 'timeout', 'adUnits'); - expect(auction.data.id).to.equal(auctionId); - expect(auction.data.timeout).to.equal(timeout); - - expect(auction.data.adUnits).to.include.all.keys(bidAdUnit, bidAfterTimeoutAdUnit, noBidAdUnit); - expect(auction.data.adUnits[bidAdUnit].bidders).to.have.property(bidder); - expect(auction.data.adUnits[bidAfterTimeoutAdUnit].bidders).to.have.property(bidder); - expect(auction.data.adUnits[noBidAdUnit].bidders).to.have.property(bidder); - - expect(auction.data.adUnits[bidAdUnit].bidders[bidder].status).to.equal('bid'); - expect(auction.data.adUnits[bidAfterTimeoutAdUnit].bidders[bidder].status).to.equal('timeout'); - expect(auction.data.adUnits[noBidAdUnit].bidders[bidder].status).to.equal('noBid'); - - const bidAfterTimeout = JSON.parse(server.requests[2].requestBody); - expect(bidAfterTimeout).to.include.all.keys('event', 'eventName', 'options', 'data'); - expect(bidAfterTimeout.event).to.equal('bat'); - - expect(bidAfterTimeout.data).to.include.all.keys('start', 'finish', 'mediaType', 'adUnit', 'bidder', 'cpm', 'size', 'auction'); - expect(bidAfterTimeout.data.adUnit).to.equal(bidAfterTimeoutAdUnit); - expect(bidAfterTimeout.data.bidder).to.equal(bidder); - expect(bidAfterTimeout.data.cpm).to.equal(bidAdjustmentAfterTimeout.cpm); - - const impression = JSON.parse(server.requests[3].requestBody); - expect(impression).to.include.all.keys('event', 'eventName', 'options', 'data'); - expect(impression.event).to.equal('i'); - - expect(impression.data).to.include.all.keys('mediaType', 'adUnit', 'bidder', 'cpm', 'size', 'auction', 'isNew'); - expect(impression.data.adUnit).to.equal(bidAdUnit); - expect(impression.data.bidder).to.equal(bidder); - expect(impression.data.cpm).to.equal(bidAdjustmentWithBid.cpm); - }); - }); - - describe('support ad unit filter', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - }); - afterEach(function () { - roxotAnalytic.disableAnalytics(); - events.getEvents.restore(); - }); - it('should not send event for blocked ad unit', function () { - roxotAnalytic.enableAnalytics({ - provider: 'roxot', - options: { - publisherId: publisherId, - configServer: roxotConfigServerUrl, - server: roxotEventServerUrl, - adUnits: [noBidAdUnit, bidAfterTimeoutAdUnit] - } - }); - - expect(server.requests.length).to.equal(1); - expect(server.requests[0].url).to.equal('https://' + roxotConfigServerUrl + '/c?publisherId=' + publisherId + '&host=localhost'); - server.requests[0].respond(200, {'Content-Type': 'application/json'}, '{"a": 1, "i": 1, "bat": 1}'); - - events.emit(EVENTS.AUCTION_INIT, auctionInit); - events.emit(EVENTS.BID_REQUESTED, bidRequested); - events.emit(EVENTS.BID_ADJUSTMENT, bidAdjustmentWithBid); - events.emit(EVENTS.BID_RESPONSE, bidResponseWithBid); - events.emit(EVENTS.BID_ADJUSTMENT, bidAdjustmentNoBid); - events.emit(EVENTS.BID_RESPONSE, bidResponseNoBid); - events.emit(EVENTS.BID_TIMEOUT, bidTimeout); - events.emit(EVENTS.AUCTION_END, auctionEnd); - events.emit(EVENTS.BID_ADJUSTMENT, bidAdjustmentAfterTimeout); - events.emit(EVENTS.BID_RESPONSE, bidResponseAfterTimeout); - events.emit(EVENTS.BIDDER_DONE, bidderDone); - events.emit(EVENTS.BID_WON, bidWon); - - expect(server.requests.length).to.equal(3); - - expect(server.requests[1].url).to.equal('https://' + roxotEventServerUrl + '/a?publisherId=' + publisherId + '&host=localhost'); - expect(server.requests[2].url).to.equal('https://' + roxotEventServerUrl + '/bat?publisherId=' + publisherId + '&host=localhost'); - - const auction = JSON.parse(server.requests[1].requestBody); - expect(auction.data.adUnits).to.include.all.keys(noBidAdUnit, bidAfterTimeoutAdUnit); - expect(auction.data.adUnits).to.not.include.all.keys(bidAdUnit); - }); - }); - - describe('should correct parse config', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - }); - - afterEach(function () { - roxotAnalytic.disableAnalytics(); - events.getEvents.restore(); - }); - - it('correct parse publisher config', function () { - const publisherOptions = { - publisherId: publisherId, - configServer: roxotConfigServerUrl, - server: roxotEventServerUrl, - anything: 'else', - }; - - roxotAnalytic.enableAnalytics({ - provider: 'roxot', - options: publisherOptions - }); - - expect(roxotAnalytic.getOptions().options).to.deep.equal(publisherOptions); - }); - - it('support deprecated options', function () { - const publisherOptions = { - publisherIds: [publisherId], - }; - - roxotAnalytic.enableAnalytics({ - provider: 'roxot', - options: publisherOptions - }); - - expect(roxotAnalytic.getOptions().options).to.deep.equal(publisherOptions); - expect(roxotAnalytic.getOptions().publisherId).to.equal(publisherId); - }); - - it('support default end-points', function () { - const publisherOptions = { - publisherId: publisherId, - }; - - roxotAnalytic.enableAnalytics({ - provider: 'roxot', - options: publisherOptions - }); - - expect(roxotAnalytic.getOptions().configServer).to.equal('pa.rxthdr.com/v3'); - expect(roxotAnalytic.getOptions().server).to.equal('pa.rxthdr.com/v3'); - }); - - it('support custom config end-point', function () { - const publisherOptions = { - publisherId: publisherId, - configServer: roxotConfigServerUrl - }; - - roxotAnalytic.enableAnalytics({ - provider: 'roxot', - options: publisherOptions - }); - - expect(roxotAnalytic.getOptions().configServer).to.equal(roxotConfigServerUrl); - expect(roxotAnalytic.getOptions().server).to.equal('pa.rxthdr.com/v3'); - }); - - it('support custom config and event end-point', function () { - const publisherOptions = { - publisherId: publisherId, - server: roxotEventServerUrl - }; - - roxotAnalytic.enableAnalytics({ - provider: 'roxot', - options: publisherOptions - }); - - expect(roxotAnalytic.getOptions().configServer).to.equal(roxotEventServerUrl); - expect(roxotAnalytic.getOptions().server).to.equal(roxotEventServerUrl); - }); - - it('support different config and event end-points', function () { - const publisherOptions = { - publisherId: publisherId, - configServer: roxotConfigServerUrl, - server: roxotEventServerUrl - }; - - roxotAnalytic.enableAnalytics({ - provider: 'roxot', - options: publisherOptions - }); - - expect(roxotAnalytic.getOptions().configServer).to.equal(roxotConfigServerUrl); - expect(roxotAnalytic.getOptions().server).to.equal(roxotEventServerUrl); - }); - - it('support adUnit filter', function () { - const publisherOptions = { - publisherId: publisherId, - adUnits: ['div1', 'div2'] - }; - - roxotAnalytic.enableAnalytics({ - provider: 'roxot', - options: publisherOptions - }); - - expect(roxotAnalytic.getOptions().adUnits).to.deep.equal(['div1', 'div2']); - }); - - it('support fail loading server config', function () { - const publisherOptions = { - publisherId: publisherId - }; - - roxotAnalytic.enableAnalytics({ - provider: 'roxot', - options: publisherOptions - }); - - server.requests[0].respond(500); - - expect(roxotAnalytic.getOptions().serverConfig).to.deep.equal({a: 1, i: 1, bat: 1, isError: 1}); - }); - }); - - describe('build utm tag data', function () { - beforeEach(function () { - localStorage.setItem('roxot_analytics_utm_source', 'utm_source'); - localStorage.setItem('roxot_analytics_utm_medium', 'utm_medium'); - localStorage.setItem('roxot_analytics_utm_campaign', ''); - localStorage.setItem('roxot_analytics_utm_term', ''); - localStorage.setItem('roxot_analytics_utm_content', ''); - localStorage.setItem('roxot_analytics_utm_ttl', Date.now()); - }); - afterEach(function () { - localStorage.removeItem('roxot_analytics_utm_source'); - localStorage.removeItem('roxot_analytics_utm_medium'); - localStorage.removeItem('roxot_analytics_utm_campaign'); - localStorage.removeItem('roxot_analytics_utm_term'); - localStorage.removeItem('roxot_analytics_utm_content'); - localStorage.removeItem('roxot_analytics_utm_ttl'); - }); - it('should build utm data from local storage', function () { - const utmTagData = roxotAnalytic.buildUtmTagData(); - expect(utmTagData.utm_source).to.equal('utm_source'); - expect(utmTagData.utm_medium).to.equal('utm_medium'); - expect(utmTagData.utm_campaign).to.equal(''); - expect(utmTagData.utm_term).to.equal(''); - expect(utmTagData.utm_content).to.equal(''); - }); - }); -}); diff --git a/test/spec/modules/rtbhouseBidAdapter_spec.js b/test/spec/modules/rtbhouseBidAdapter_spec.js deleted file mode 100644 index 2f1fa127b..000000000 --- a/test/spec/modules/rtbhouseBidAdapter_spec.js +++ /dev/null @@ -1,815 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/rtbhouseBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import { mergeDeep } from '../../../src/utils.js'; -import { OPENRTB } from '../../../libraries/precisoUtils/bidNativeUtils.js'; - -describe('RTBHouseAdapter', () => { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'rtbhouse', - 'params': { - 'publisherId': 'PREBID_TEST', - 'region': 'prebid-eu' - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 600]], - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('Checking backward compatibility. should return true', function () { - const bid2 = Object.assign({}, bid); - delete bid2.mediaTypes; - bid2.sizes = [[300, 250], [300, 600]]; - expect(spec.isBidRequestValid(bid2)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'someIncorrectParam': 0 - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - let bidRequests; - let bidderRequest; - - beforeEach(() => { - bidderRequest = { - 'auctionId': 'bidderrequest-auction-id', - 'refererInfo': { - 'numIframes': 0, - 'reachedTop': true, - 'referer': 'https://example.com', - 'stack': ['https://example.com'] - } - }; - bidRequests = [ - { - 'bidder': 'rtbhouse', - 'params': { - 'publisherId': 'PREBID_TEST', - 'region': 'prebid-eu', - 'channel': 'Partner_Site - news', - 'test': 1 - }, - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 600]], - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'transactionId': 'example-transaction-id', - 'ortb2Imp': { - 'ext': { - 'tid': 'ortb2Imp-transaction-id-1', - 'gpid': 'example-gpid' - } - }, - 'ortb2': { - 'source': { - 'ext': { - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'directseller.com', - 'sid': '00001', - 'rid': 'BidRequest1', - 'hp': 1 - } - ] - } - } - } - } - } - ]; - }); - - afterEach(function () { - config.resetConfig(); - }); - - it('should build test param into the request', () => { - const builtTestRequest = spec.buildRequests(bidRequests, bidderRequest).data; - expect(JSON.parse(builtTestRequest).test).to.equal(1); - }); - - it('should build channel param into request.site', () => { - const builtTestRequest = spec.buildRequests(bidRequests, bidderRequest).data; - expect(JSON.parse(builtTestRequest).site.channel).to.equal('Partner_Site - news'); - }) - - it('should not build channel param into request.site if no value is passed', () => { - const bidRequest = Object.assign([], bidRequests); - bidRequest[0].params.channel = undefined; - const builtTestRequest = spec.buildRequests(bidRequest, bidderRequest).data; - expect(JSON.parse(builtTestRequest).site.channel).to.be.undefined - }) - - it('should cap the request.site.channel length to 50', () => { - const bidRequest = Object.assign([], bidRequests); - bidRequest[0].params.channel = 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent scelerisque ipsum eu purus lobortis iaculis.'; - const builtTestRequest = spec.buildRequests(bidRequest, bidderRequest).data; - expect(JSON.parse(builtTestRequest).site.channel.length).to.equal(50) - }) - - it('should build valid OpenRTB banner object', () => { - const request = JSON.parse(spec.buildRequests(bidRequests, bidderRequest).data); - const imp = request.imp[0]; - expect(imp.banner).to.deep.equal({ - w: 300, - h: 250, - format: [{ - w: 300, - h: 250 - }, { - w: 300, - h: 600 - }] - }) - }); - - it('sends bid request to ENDPOINT via POST', function () { - const bidRequest = Object.assign([], bidRequests); - delete bidRequest[0].params.test; - const request = spec.buildRequests(bidRequest, bidderRequest); - expect(request.url).to.equal('https://prebid-eu.creativecdn.com/bidder/prebid/bids'); - expect(request.method).to.equal('POST'); - }); - - it('should not populate GDPR if for non-EEA users', function () { - const bidRequest = Object.assign([], bidRequests); - delete bidRequest[0].params.test; - const request = spec.buildRequests(bidRequest, bidderRequest); - const data = JSON.parse(request.data); - expect(data).to.not.have.property('regs'); - expect(data).to.not.have.property('user'); - }); - - it('should populate GDPR and consent string if available for EEA users', function () { - const bidRequest = Object.assign([], bidRequests); - delete bidRequest[0].params.test; - const request = spec.buildRequests( - bidRequest, - Object.assign({}, bidderRequest, { - gdprConsent: { - gdprApplies: true, - consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==' - } - }) - ); - const data = JSON.parse(request.data); - expect(data.regs.ext.gdpr).to.equal(1); - expect(data.user.ext.consent).to.equal('BOJ8RZsOJ8RZsABAB8AAAAAZ-A'); - }); - - it('should populate GDPR and empty consent string if available for EEA users without consent string but with consent', function () { - const bidRequest = Object.assign([], bidRequests); - delete bidRequest[0].params.test; - const request = spec.buildRequests( - bidRequest, - Object.assign({}, bidderRequest, { - gdprConsent: { - gdprApplies: true - } - }) - ); - const data = JSON.parse(request.data); - expect(data.regs.ext.gdpr).to.equal(1); - expect(data.user.ext.consent).to.equal(''); - }); - - it('should include banner imp in request', () => { - const bidRequest = Object.assign([], bidRequests); - const request = spec.buildRequests(bidRequest, bidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].banner).to.not.be.empty; - }); - - it('should include source.tid in request', () => { - const bidRequest = Object.assign([], bidRequests); - const request = spec.buildRequests(bidRequest, bidderRequest); - const data = JSON.parse(request.data); - expect(data.source.tid).to.equal('bidderrequest-auction-id'); - }); - - it('should include bidfloor from floor module if avaiable', () => { - const bidRequest = Object.assign([], bidRequests); - bidRequest[0].getFloor = () => ({floor: 1.22}); - const request = spec.buildRequests(bidRequest, bidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].bidfloor).to.equal(1.22) - }); - - it('should use bidfloor from floor module if both floor module and bid floor avaiable', () => { - const bidRequest = Object.assign([], bidRequests); - bidRequest[0].getFloor = () => ({floor: 1.22}); - bidRequest[0].params.bidfloor = 0.01; - const request = spec.buildRequests(bidRequest, bidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].bidfloor).to.equal(1.22) - }); - - it('should include bidfloor in request if available', () => { - const bidRequest = Object.assign([], bidRequests); - bidRequest[0].params.bidfloor = 0.01; - const request = spec.buildRequests(bidRequest, bidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].bidfloor).to.equal(0.01) - }); - - it('should include schain in request', () => { - const bidRequest = Object.assign([], bidRequests); - const request = spec.buildRequests(bidRequest, bidderRequest); - const data = JSON.parse(request.data); - expect(data.ext.schain).to.deep.equal({ - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'directseller.com', - 'sid': '00001', - 'rid': 'BidRequest1', - 'hp': 1 - } - ] - }); - }); - - it('should include source.tid in request', () => { - const bidRequest = Object.assign([], bidRequests); - const request = spec.buildRequests(bidRequest, bidderRequest); - const data = JSON.parse(request.data); - expect(data.source).to.have.deep.property('tid'); - }); - - it('should include impression level transaction id when provided', () => { - const bidRequest = Object.assign([], bidRequests); - const request = spec.buildRequests(bidRequest, bidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].ext.tid).to.equal('ortb2Imp-transaction-id-1'); - }); - - it('should include impression level GPID when provided', () => { - const bidRequest = Object.assign([], bidRequests); - const request = spec.buildRequests(bidRequest, bidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].ext.gpid).to.equal('example-gpid'); - }); - - it('should not include imp[].ext.ae set at impression level when provided', () => { - const bidRequest = Object.assign([], bidRequests); - bidRequest[0].ortb2Imp.ext.ae = 1; - const request = spec.buildRequests(bidRequest, bidderRequest); - const data = JSON.parse(request.data); - expect(data.imp[0].ext.ae).to.be.undefined; - }); - - it('should not include invalid schain', () => { - const bidRequest = Object.assign([], bidRequests); - bidRequest[0].ortb2 = bidRequest[0].ortb2 || {}; - bidRequest[0].ortb2.source = bidRequest[0].ortb2.source || {}; - bidRequest[0].ortb2.source.ext = bidRequest[0].ortb2.source.ext || {}; - bidRequest[0].ortb2.source.ext.schain = { - 'nodes': [{ - 'unknown_key': 1 - }] - }; - const request = spec.buildRequests(bidRequest, bidderRequest); - const data = JSON.parse(request.data); - expect(data.source).to.not.have.property('ext'); - }); - - it('should include first party data', function () { - const bidRequest = Object.assign([], bidRequests); - const localBidderRequest = { - ...bidderRequest, - ortb2: { - bcat: ['IAB1', 'IAB2-1'], - badv: ['domain1.com', 'domain2.com'], - site: { ext: { data: 'some site data' } }, - device: { ext: { data: 'some device data' } }, - user: { ext: { data: 'some user data' } } - } - }; - - const request = spec.buildRequests(bidRequest, localBidderRequest); - const data = JSON.parse(request.data); - expect(data.bcat).to.deep.equal(localBidderRequest.ortb2.bcat); - expect(data.badv).to.deep.equal(localBidderRequest.ortb2.badv); - expect(data.site).to.nested.include({'ext.data': 'some site data'}); - expect(data.device).to.nested.include({'ext.data': 'some device data'}); - expect(data.user).to.nested.include({'ext.data': 'some user data'}); - }); - - context('DSA', () => { - const validDSAObject = { - 'dsarequired': 3, - 'pubrender': 0, - 'datatopub': 2, - 'transparency': [ - { - 'domain': 'platform1domain.com', - 'dsaparams': [1] - }, - { - 'domain': 'SSP2domain.com', - 'dsaparams': [1, 2] - } - ] - }; - const invalidDSAObjects = [ - -1, - 0, - '', - 'x', - true, - [], - [1], - {}, - { - 'dsarequired': -1 - }, - { - 'pubrender': -1 - }, - { - 'datatopub': -1 - }, - { - 'dsarequired': 4 - }, - { - 'pubrender': 3 - }, - { - 'datatopub': 3 - }, - { - 'dsarequired': '1' - }, - { - 'pubrender': '1' - }, - { - 'datatopub': '1' - }, - { - 'transparency': '1' - }, - { - 'transparency': 2 - }, - { - 'transparency': [ - 1, 2 - ] - }, - { - 'transparency': [ - { - domain: '', - dsaparams: [] - } - ] - }, - { - 'transparency': [ - { - domain: 'x', - dsaparams: null - } - ] - }, - { - 'transparency': [ - { - domain: 'x', - dsaparams: [1, '2'] - } - ] - }, - ]; - let bidRequest; - - beforeEach(() => { - bidRequest = Object.assign([], bidRequests); - }); - - it('should add dsa information to the request via bidderRequest.ortb2.regs.ext.dsa', function () { - const localBidderRequest = { - ...bidderRequest, - ortb2: { - regs: { - ext: { - dsa: validDSAObject - } - } - } - }; - - const request = spec.buildRequests(bidRequest, localBidderRequest); - const data = JSON.parse(request.data); - - expect(data).to.have.nested.property('regs.ext.dsa'); - expect(data.regs.ext.dsa.dsarequired).to.equal(3); - expect(data.regs.ext.dsa.pubrender).to.equal(0); - expect(data.regs.ext.dsa.datatopub).to.equal(2); - expect(data.regs.ext.dsa.transparency).to.deep.equal([ - { - 'domain': 'platform1domain.com', - 'dsaparams': [1] - }, - { - 'domain': 'SSP2domain.com', - 'dsaparams': [1, 2] - } - ]); - }); - - invalidDSAObjects.forEach((invalidDSA, index) => { - it(`should not add dsa information to the request via bidderRequest.ortb2.regs.ext.dsa; test# ${index}`, function () { - const localBidderRequest = { - ...bidderRequest, - ortb2: { - regs: { - ext: { - dsa: invalidDSA - } - } - } - }; - - const request = spec.buildRequests(bidRequest, localBidderRequest); - const data = JSON.parse(request.data); - - expect(data).to.not.have.nested.property('regs.ext.dsa'); - }); - }); - }); - - describe('native imp', () => { - function basicRequest(extension) { - return Object.assign({ - bidder: 'bidder', - adUnitCode: 'adunit-code', - bidId: '1', - params: { - publisherId: 'PREBID_TEST', - region: 'prebid-eu', - test: 1 - } - }, extension); - } - - function buildImp(request) { - const resultRequest = spec.buildRequests([request], bidderRequest); - return JSON.parse(resultRequest.data).imp[0]; - } - - it('should extract native params when single mediaType', () => { - const imp = buildImp(basicRequest({ - mediaType: 'native', - nativeParams: { - title: { - required: true, - len: 100 - } - } - })); - expect(imp.native.request.assets[0]).to.deep.equal({ - id: OPENRTB.NATIVE.ASSET_ID.TITLE, - required: 1, - title: { - len: 100 - } - }) - }); - - it('should extract native params when many mediaTypes', () => { - const imp = buildImp(basicRequest({ - mediaTypes: { - native: { - title: { - len: 100 - } - } - } - })); - expect(imp.native.request.assets[0]).to.deep.equal({ - id: OPENRTB.NATIVE.ASSET_ID.TITLE, - required: 0, - title: { - len: 100 - } - }) - }); - - it('should not contain banner in imp', () => { - const imp = buildImp(basicRequest({ - mediaTypes: { - native: { - title: { - required: true - } - } - } - })); - expect(imp.banner).to.be.undefined; - }); - - describe('image sizes', () => { - it('should parse single image size', () => { - const imp = buildImp(basicRequest({ - mediaTypes: { - native: { - image: { - sizes: [300, 250] - } - } - } - })); - expect(imp.native.request.assets[0]).to.deep.equal({ - id: OPENRTB.NATIVE.ASSET_ID.IMAGE, - required: 0, - img: { - w: 300, - h: 250, - type: OPENRTB.NATIVE.IMAGE_TYPE.MAIN, - } - }) - }); - - it('should parse multiple image sizes', () => { - const imp = buildImp(basicRequest({ - mediaTypes: { - native: { - image: { - sizes: [[300, 250], [100, 100]] - } - } - } - })); - expect(imp.native.request.assets[0]).to.deep.equal({ - id: OPENRTB.NATIVE.ASSET_ID.IMAGE, - required: 0, - img: { - w: 300, - h: 250, - type: OPENRTB.NATIVE.IMAGE_TYPE.MAIN, - } - }) - }) - }); - - it('should parse aspect ratios with min_width', () => { - const imp = buildImp(basicRequest({ - mediaTypes: { - native: { - icon: { - aspect_ratios: [{ - min_width: 300, - ratio_width: 2, - ratio_height: 3, - }] - } - } - } - })); - expect(imp.native.request.assets[0]).to.deep.equal({ - id: OPENRTB.NATIVE.ASSET_ID.ICON, - required: 0, - img: { - type: OPENRTB.NATIVE.IMAGE_TYPE.ICON, - wmin: 300, - hmin: 450, - } - }) - }); - - it('should parse aspect ratios without min_width', () => { - const imp = buildImp(basicRequest({ - mediaTypes: { - native: { - icon: { - aspect_ratios: [{ - ratio_width: 2, - ratio_height: 3, - }] - } - } - } - })); - expect(imp.native.request.assets[0]).to.deep.equal({ - id: OPENRTB.NATIVE.ASSET_ID.ICON, - required: 0, - img: { - type: OPENRTB.NATIVE.IMAGE_TYPE.ICON, - wmin: 100, - hmin: 150, - } - }) - }); - - it('should handle all native assets', () => { - const imp = buildImp(basicRequest({ - mediaTypes: { - native: { - title: {}, - image: {}, - icon: {}, - sponsoredBy: {}, - body: {}, - cta: {}, - } - } - })); - expect(imp.native.request.assets.length).to.equal(6); - imp.native.request.assets.forEach(asset => { - expect(asset.id).to.be.at.least(1) - }) - }); - }); - }); - - describe('interpretResponse', function () { - let response; - beforeEach(() => { - response = [{ - 'id': 'bidder_imp_identifier', - 'impid': '552b8922e28f27', - 'price': 0.5, - 'adid': 'Ad_Identifier', - 'adm': '', - 'adomain': ['rtbhouse.com'], - 'cid': 'Ad_Identifier', - 'w': 300, - 'h': 250 - }]; - }); - - it('should get correct bid response', function () { - const expectedResponse = [ - { - 'requestId': '552b8922e28f27', - 'cpm': 0.5, - 'creativeId': 29681110, - 'width': 300, - 'height': 250, - 'ad': '', - 'mediaType': 'banner', - 'currency': 'USD', - 'ttl': 300, - 'meta': { advertiserDomains: ['rtbhouse.com'] }, - 'netRevenue': true - } - ]; - let bidderRequest; - const result = spec.interpretResponse({body: response}, {bidderRequest}); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - - it('handles nobid responses', function () { - const response = ''; - let bidderRequest; - const result = spec.interpretResponse({body: response}, {bidderRequest}); - expect(result.length).to.equal(0); - }); - - context('when the response contains DSA object', function () { - it('should get correct bid response', function () { - const dsa = { - 'dsa': { - 'behalf': 'Advertiser', - 'paid': 'Advertiser', - 'transparency': [{ - 'domain': 'dsp1domain.com', - 'dsaparams': [1, 2] - }], - 'adrender': 1 - } - }; - mergeDeep(response[0], { ext: dsa }); - - const expectedResponse = [ - { - 'requestId': '552b8922e28f27', - 'cpm': 0.5, - 'creativeId': 29681110, - 'width': 300, - 'height': 250, - 'ad': '', - 'mediaType': 'banner', - 'currency': 'USD', - 'ttl': 300, - 'meta': { - 'advertiserDomains': ['rtbhouse.com'], - ...dsa - }, - 'netRevenue': true, - ext: { ...dsa } - } - ]; - let bidderRequest; - const result = spec.interpretResponse({body: response}, {bidderRequest}); - - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - expect(result[0]).to.have.nested.property('meta.dsa'); - expect(result[0]).to.have.nested.property('ext.dsa'); - expect(result[0].meta.dsa).to.deep.equal(expectedResponse[0].meta.dsa); - expect(result[0].ext.dsa).to.deep.equal(expectedResponse[0].meta.dsa); - }); - }); - - describe('native', () => { - const adm = { - native: { - ver: 1.1, - link: { - url: 'https://example.com' - }, - imptrackers: [ - 'https://example.com/imptracker' - ], - assets: [{ - id: OPENRTB.NATIVE.ASSET_ID.TITLE, - required: 1, - title: { - text: 'Title text' - } - }, { - id: OPENRTB.NATIVE.ASSET_ID.IMAGE, - required: 1, - img: { - url: 'https://example.com/image.jpg', - w: 150, - h: 50 - } - }, { - id: OPENRTB.NATIVE.ASSET_ID.BODY, - required: 0, - data: { - value: 'Body text' - } - }], - } - }; - const response = [{ - 'id': 'id', - 'impid': 'impid', - 'price': 1, - 'adid': 'adid', - 'adm': JSON.stringify(adm), - 'adomain': ['rtbhouse.com'], - 'cid': 'cid', - 'w': 1, - 'h': 1 - }]; - - it('should contain native assets in valid format', () => { - const bids = spec.interpretResponse({body: response}, {}); - expect(bids[0].meta.advertiserDomains).to.deep.equal(['rtbhouse.com']); - expect(bids[0].native).to.deep.equal({ - title: 'Title text', - clickUrl: encodeURI('https://example.com'), - impressionTrackers: ['https://example.com/imptracker'], - image: { - url: encodeURI('https://example.com/image.jpg'), - width: 150, - height: 50 - }, - body: 'Body text' - }); - }); - }); - }); -}); diff --git a/test/spec/modules/rtbsapeBidAdapter_spec.js b/test/spec/modules/rtbsapeBidAdapter_spec.js deleted file mode 100644 index 538a728d0..000000000 --- a/test/spec/modules/rtbsapeBidAdapter_spec.js +++ /dev/null @@ -1,209 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/rtbsapeBidAdapter.js'; -import 'src/prebid.js'; -import * as utils from 'src/utils.js'; -import {executeRenderer, Renderer} from 'src/Renderer.js'; - -describe('rtbsapeBidAdapterTests', function () { - describe('isBidRequestValid', function () { - it('valid', function () { - expect(spec.isBidRequestValid({bidder: 'rtbsape', mediaTypes: {banner: true}, params: {placeId: 4321}})).to.equal(true); - expect(spec.isBidRequestValid({bidder: 'rtbsape', mediaTypes: {video: true}, params: {placeId: 4321}})).to.equal(true); - }); - - it('invalid', function () { - expect(spec.isBidRequestValid({bidder: 'rtbsape', mediaTypes: {banner: true}, params: {}})).to.equal(false); - expect(spec.isBidRequestValid({bidder: 'rtbsape', params: {placeId: 4321}})).to.equal(false); - }); - }); - - it('buildRequests', function () { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'rtbsape', - params: {placeId: 4321}, - sizes: [[240, 400]] - }]; - const bidderRequest = { - auctionId: '2e208334-cafe-4c2c-b06b-f055ff876852', - bidderRequestId: '1392d0aa613366', - refererInfo: {} - }; - const request = spec.buildRequests(bidRequestData, bidderRequest); - expect(request.data.auctionId).to.equal('2e208334-cafe-4c2c-b06b-f055ff876852'); - expect(request.data.requestId).to.equal('1392d0aa613366'); - expect(request.data.bids[0].bidId).to.equal('bid1234'); - expect(request.data.timezone).to.not.equal(undefined); - }); - - describe('interpretResponse', function () { - it('banner', function () { - const serverResponse = { - body: { - bids: [{ - requestId: 'bid1234', - cpm: 2.21, - currency: 'RUB', - width: 240, - height: 400, - netRevenue: true, - ad: 'Ad html', - meta: { - advertiserDomains: ['rtb.sape.ru'] - } - }] - } - }; - const bids = spec.interpretResponse(serverResponse, {data: {bids: [{mediaTypes: {banner: true}}]}}); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(2.21); - expect(bid.currency).to.equal('RUB'); - expect(bid.width).to.equal(240); - expect(bid.height).to.equal(400); - expect(bid.netRevenue).to.equal(true); - expect(bid.requestId).to.equal('bid1234'); - expect(bid.ad).to.equal('Ad html'); - }); - - describe('video (outstream)', function () { - let bid; - - before(() => { - const serverResponse = { - body: { - bids: [{ - requestId: 'bid1234', - adUnitCode: 'ad-bid1234', - cpm: 3.32, - currency: 'RUB', - width: 600, - height: 340, - netRevenue: true, - vastUrl: 'https://cdn-rtb.sape.ru/vast/4321.xml', - meta: { - advertiserDomains: ['rtb.sape.ru'], - mediaType: 'video' - } - }] - } - }; - const serverRequest = { - data: { - bids: [{ - bidId: 'bid1234', - adUnitCode: 'ad-bid1234', - mediaTypes: { - video: { - context: 'outstream' - } - }, - params: { - placeId: 4321, - video: { - playerMuted: false - } - } - }] - } - }; - const bids = spec.interpretResponse(serverResponse, serverRequest); - expect(bids).to.have.lengthOf(1); - bid = bids[0]; - }); - - it('should add renderer', () => { - expect(bid).to.have.own.property('renderer'); - expect(bid.renderer).to.be.instanceof(Renderer); - expect(bid.renderer.url).to.equal('https://cdn-rtb.sape.ru/js/player.js'); - expect(bid.playerMuted).to.equal(false); - }); - - it('should create player instance', () => { - let spy = false; - - window.sapeRtbPlayerHandler = function (id, w, h, m) { - const player = {addSlot: () => [id, w, h, m]} - expect(spy).to.equal(false); - spy = sinon.spy(player, 'addSlot'); - return player; - }; - - executeRenderer(bid.renderer, bid); - bid.renderer.callback(); - expect(spy).to.not.equal(false); - expect(spy.called).to.be.true; - - const spyCall = spy.getCall(0); - expect(spyCall.args[0].url).to.be.equal('https://cdn-rtb.sape.ru/vast/4321.xml'); - expect(spyCall.returnValue[0]).to.be.equal('ad-bid1234'); - expect(spyCall.returnValue[1]).to.be.equal(600); - expect(spyCall.returnValue[2]).to.be.equal(340); - expect(spyCall.returnValue[3]).to.be.equal(false); - }); - }); - - it('skip adomain', function () { - const serverResponse = { - body: { - bids: [{ - requestId: 'bid1234', - cpm: 2.21, - currency: 'RUB', - width: 240, - height: 400, - netRevenue: true, - ad: 'Ad html 1' - }, { - requestId: 'bid1235', - cpm: 2.23, - currency: 'RUB', - width: 300, - height: 250, - netRevenue: true, - ad: 'Ad html 2', - meta: { - advertiserDomains: ['rtb.sape.ru'] - } - }] - } - }; - const bids = spec.interpretResponse(serverResponse, {data: {bids: [{mediaTypes: {banner: true}}]}}); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(2.23); - expect(bid.currency).to.equal('RUB'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.netRevenue).to.equal(true); - expect(bid.requestId).to.equal('bid1235'); - expect(bid.ad).to.equal('Ad html 2'); - }); - }); - - it('getUserSyncs', function () { - const syncs = spec.getUserSyncs({iframeEnabled: true}); - expect(syncs).to.be.an('array').that.to.have.lengthOf(1); - expect(syncs[0]).to.deep.equal({type: 'iframe', url: 'https://www.acint.net/mc/?dp=141'}); - }); - - describe('onBidWon', function () { - beforeEach(function () { - sinon.stub(utils, 'triggerPixel'); - }); - - afterEach(function () { - utils.triggerPixel.restore(); - }); - - it('called once', function () { - spec.onBidWon({cpm: '2.21', nurl: 'https://ssp-rtb.sape.ru/track?event=win'}); - expect(utils.triggerPixel.calledOnce).to.equal(true); - }); - - it('called false', function () { - spec.onBidWon({cpm: '2.21'}); - expect(utils.triggerPixel.called).to.equal(false); - }); - }); -}); diff --git a/test/spec/modules/rubiconBidAdapter_spec.js b/test/spec/modules/rubiconBidAdapter_spec.js deleted file mode 100644 index b96a5e4fd..000000000 --- a/test/spec/modules/rubiconBidAdapter_spec.js +++ /dev/null @@ -1,4919 +0,0 @@ -import {expect} from 'chai'; -import { - spec, - getPriceGranularity, - masSizeOrdering, - classifiedAsVideo, - resetRubiConf, - resetImpIdMap, - converter -} from 'modules/rubiconBidAdapter.js'; -import {config} from 'src/config.js'; -import * as utils from 'src/utils.js'; -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; -import 'modules/userId/index.js'; -import 'modules/priceFloors.js'; -import 'modules/multibid/index.js'; -import adapterManager from 'src/adapterManager.js'; -import {addFPDToBidderRequest} from '../../helpers/fpd.js'; -import { deepClone } from '../../../src/utils.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -const INTEGRATION = `pbjs_lite_v$prebid.version$`; // $prebid.version$ will be substituted in by gulp in built prebid -const PBS_INTEGRATION = 'pbjs'; - -describe('the rubicon adapter', function () { - let sandbox, - bidderRequest, - sizeMap, - getFloorResponse, - logErrorSpy; - - /** - * @typedef {import('../../../src/adapters/bidderFactory.js').BidRequest} BidRequest - * @typedef {Object} sizeMapConverted - * @property {string} sizeId - * @property {string} size - * @property {Array.} sizeAsArray - * @property {number} width - * @property {number} height - */ - - /** - * @param {Array.} sizesMapConverted - * @param {Object} bid - * @return {sizeMapConverted} - */ - function getSizeIdForBid(sizesMapConverted, bid) { - return sizesMapConverted.find(item => (item.width === bid.width && item.height === bid.height)); - } - - /** - * @param {Array.} ads - * @param {sizeMapConverted} size - * @return {Object} - */ - function getResponseAdBySize(ads, size) { - return ads.find(item => item.size_id === size.sizeId); - } - - /** - * @param {Array.} bidRequests - * @param {sizeMapConverted} size - * @return {BidRequest} - */ - function getBidRequestBySize(bidRequests, size) { - return bidRequests.find(item => item.sizes[0][0] === size.width && item.sizes[0][1] === size.height); - } - - /** - * @typedef {Object} overrideProps - * @property {string} status - * @property {number} cpm - * @property {number} zone_id - * @property {number} ad_id - * @property {string} creative_id - * @property {string} targeting_key - rpfl_{id} - */ - /** - * @param {number} i - index - * @param {string} sizeId - id that maps to size - * @param {Array.} [indexOverMap] - * @return {{status: string, cpm: number, zone_id: *, size_id: *, impression_id: *, ad_id: *, creative_id: string, type: string, targeting: *[]}} - */ - - function getBidderRequest() { - return { - bidderCode: 'rubicon', - ortb2: { - source: { - tid: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', - } - }, - auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', - bidderRequestId: '178e34bad3658f', - bids: [ - { - bidder: 'rubicon', - params: { - accountId: '14062', - siteId: '70608', - zoneId: '335918', - userId: '12346', - keywords: ['a', 'b', 'c'], - inventory: { - rating: '5-star', // This actually should not be sent to frank!! causes 400 - prodtype: ['tech', 'mobile'] - }, - visitor: { - ucat: 'new', - lastsearch: 'iphone', - likes: ['sports', 'video games'] - }, - position: 'atf', - referrer: 'localhost', - latLong: [40.7607823, '111.8910325'] - }, - mediaTypes: { - banner: [[300, 250]] - }, - adUnitCode: '/19968336/header-bid-tag-0', - code: 'div-1', - sizes: [[300, 250], [320, 50]], - bidId: '2ffb201a808da7', - bidderRequestId: '178e34bad3658f', - auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', - ortb2Imp: { - ext: { - tid: 'd45dd707-a418-42ec-b8a7-b70a6c6fab0b', - } - }, - ortb2: { - source: {} - } - } - ], - start: 1472239426002, - auctionStart: 1472239426000, - timeout: 5000 - }; - }; - - function createResponseAdByIndex(i, sizeId, indexOverMap) { - const overridePropMap = (indexOverMap && indexOverMap[i] && typeof indexOverMap[i] === 'object') ? indexOverMap[i] : {}; - const overrideProps = Object.keys(overridePropMap).reduce((aggregate, key) => { - aggregate[key] = overridePropMap[key]; - return aggregate; - }, {}); - - const getProp = (propName, defaultValue) => { - return (overrideProps[propName]) ? overridePropMap[propName] : defaultValue; - }; - - return { - 'status': getProp('status', 'ok'), - 'cpm': getProp('cpm', i / 100), - 'zone_id': getProp('zone_id', i + 1), - 'size_id': sizeId, - 'impression_id': getProp('impression_id', `1-${i}`), - 'ad_id': getProp('ad_id', i + 1), - 'advertiser': i + 1, - 'network': i + 1, - 'creative_id': getProp('creative_id', `crid-${i}`), - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': i + 1, - 'targeting': [ - { - 'key': getProp('targeting_key', `rpfl_${i}`), - 'values': ['43_tier_all_test'] - } - ] - }; - } - - /** - * @param {number} i - * @param {Array.} size - * @return {{ params: {accountId: string, siteId: string, zoneId: string }, adUnitCode: string, code: string, sizes: *[], bidId: string, bidderRequestId: string }} - */ - function createBidRequestByIndex(i, size) { - return { - bidder: 'rubicon', - params: { - accountId: '14062', - siteId: '70608', - zoneId: (i + 1).toString(), - userId: '12346', - position: 'atf', - referrer: 'localhost' - }, - adUnitCode: `/19968336/header-bid-tag-${i}`, - code: `div-${i}`, - sizes: [size], - bidId: i.toString(), - bidderRequestId: i.toString(), - auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', - transactionId: 'd45dd707-a418-42ec-b8a7-b70a6c6fab0b' - }; - } - - /** - * @param {boolean} [gdprApplies] - */ - function createGdprBidderRequest(gdprApplies) { - const bidderRequest = getBidderRequest(); - if (typeof gdprApplies === 'boolean') { - bidderRequest.gdprConsent = { - 'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - 'gdprApplies': gdprApplies - }; - } else { - bidderRequest.gdprConsent = { - 'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==' - }; - } - return bidderRequest; - } - - function addUspToBidderRequest(bidderRequest) { - bidderRequest.uspConsent = '1NYN'; - } - - function createVideoBidderRequest() { - const bidderRequest = createGdprBidderRequest(true); - addUspToBidderRequest(bidderRequest); - - const bid = bidderRequest.bids[0]; - bid.mediaTypes = { - video: { - context: 'instream', - mimes: ['video/mp4', 'video/x-flv'], - api: [2], - minduration: 15, - playerSize: [640, 480], - maxduration: 30, - startdelay: 0, - playbackmethod: [2], - linearity: 1, - skip: 1, - skipafter: 15, - pos: 1, - protocols: [1, 2, 3, 4, 5, 6] - } - }; - bid.params.video = { - 'language': 'en', - 'skip': 1, - 'skipafter': 15, - 'playerHeight': 480, - 'playerWidth': 640, - 'size_id': 201, - }; - bid.userId = { - lipb: {lipbid: '0000-1111-2222-3333', segments: ['segA', 'segB']}, - idl_env: '1111-2222-3333-4444', - tdid: '3000', - pubcid: '4000', - pubProvidedId: [{ - source: 'example.com', - uids: [{ - id: '333333', - ext: { - stype: 'ppuid' - } - }] - }, { - source: 'id-partner.com', - uids: [{ - id: '4444444' - }] - }], - criteoId: '1111', - }; - const eids = [ - { - 'source': 'liveintent.com', - 'uids': [ - { - 'id': '0000-1111-2222-3333', - 'atype': 3 - } - ], - 'ext': { - 'segments': [ - 'segA', - 'segB' - ] - } - }, - { - 'source': 'liveramp.com', - 'uids': [ - { - 'id': '1111-2222-3333-4444', - 'atype': 3 - } - ] - }, - { - 'source': 'adserver.org', - 'uids': [ - { - 'id': '3000', - 'atype': 1, - 'ext': { - 'rtiPartner': 'TDID' - } - } - ] - }, - { - 'source': 'pubcid.org', - 'uids': [ - { - 'id': '4000', - 'atype': 1 - } - ] - }, - { - 'source': 'example.com', - 'uids': [ - { - 'id': '333333', - 'ext': { - 'stype': 'ppuid' - } - } - ] - }, - { - 'source': 'id-partner.com', - 'uids': [ - { - 'id': '4444444' - } - ] - }, - { - 'source': 'criteo.com', - 'uids': [ - { - 'id': '1111', - 'atype': 1 - } - ] - } - ]; - bidderRequest.ortb2 = {user: {ext: {eids}}}; - return bidderRequest; - } - - function removeVideoParamFromBidderRequest(bidderRequest) { - const bid = bidderRequest.bids[0]; - bid.mediaTypes = { - video: { - context: 'instream' - }, - }; - bid.params.video = false; - } - - function createVideoBidderRequestOutstream() { - const bidderRequest = createGdprBidderRequest(false); - const bid = bidderRequest.bids[0]; - delete bid.sizes; - bid.mediaTypes = { - video: { - context: 'outstream', - mimes: ['video/mp4', 'video/x-flv'], - api: [2], - minduration: 15, - playerSize: [640, 480], - maxduration: 30, - startdelay: 0, - playbackmethod: [2], - linearity: 1, - skip: 1, - skipafter: 15, - pos: 1, - protocols: [1, 2, 3, 4, 5, 6] - }, - }; - bid.params = { - accountId: 14062, - siteId: 70608, - zoneId: 335918, - video: { - 'language': 'en', - 'skip': 1, - 'skipafter': 15, - 'playerHeight': 320, - 'playerWidth': 640, - 'size_id': 203 - } - } - return bidderRequest; - } - - beforeEach(function () { - sandbox = sinon.createSandbox(); - logErrorSpy = sinon.spy(utils, 'logError'); - getFloorResponse = {}; - bidderRequest = { - bidderCode: 'rubicon', - auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', - ortb2: { - source: { - tid: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', - } - }, - bidderRequestId: '178e34bad3658f', - bids: [ - { - bidder: 'rubicon', - params: { - accountId: '14062', - siteId: '70608', - zoneId: '335918', - userId: '12346', - keywords: ['a', 'b', 'c'], - inventory: { - rating: '5-star', // This actually should not be sent to frank!! causes 400 - prodtype: ['tech', 'mobile'] - }, - visitor: { - ucat: 'new', - lastsearch: 'iphone', - likes: ['sports', 'video games'] - }, - position: 'atf', - referrer: 'localhost', - latLong: [40.7607823, '111.8910325'] - }, - mediaTypes: { - banner: [[300, 250]] - }, - adUnitCode: '/19968336/header-bid-tag-0', - code: 'div-1', - sizes: [[300, 250], [320, 50]], - bidId: '2ffb201a808da7', - bidderRequestId: '178e34bad3658f', - auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', - ortb2Imp: { - ext: { - tid: 'd45dd707-a418-42ec-b8a7-b70a6c6fab0b', - } - }, - } - ], - start: 1472239426002, - auctionStart: 1472239426000, - timeout: 5000 - }; - - sizeMap = [ - {sizeId: 1, size: '468x60'}, - {sizeId: 2, size: '728x90'}, - {sizeId: 5, size: '120x90'}, - {sizeId: 8, size: '120x600'}, - {sizeId: 9, size: '160x600'}, - {sizeId: 10, size: '300x600'}, - {sizeId: 13, size: '200x200'}, - {sizeId: 14, size: '250x250'}, - {sizeId: 15, size: '300x250'}, - {sizeId: 16, size: '336x280'}, - {sizeId: 19, size: '300x100'}, - {sizeId: 31, size: '980x120'}, - {sizeId: 32, size: '250x360'} - // Create convenience properties for [sizeAsArray, width, height] by parsing the size string - ].map(item => { - const sizeAsArray = item.size.split('x').map(s => parseInt(s)); - return { - sizeId: item.sizeId, - size: item.size, - sizeAsArray: sizeAsArray.slice(), - width: sizeAsArray[0], - height: sizeAsArray[1] - }; - }); - }); - - afterEach(function () { - sandbox.restore(); - utils.logError.restore(); - config.resetConfig(); - resetRubiConf(); - resetImpIdMap(); - delete getGlobal().installedModules; - }); - - describe('MAS mapping / ordering', function () { - it('should sort values without any MAS priority sizes in regular ascending order', function () { - const ordering = masSizeOrdering([126, 43, 65, 16]); - expect(ordering).to.deep.equal([16, 43, 65, 126]); - }); - - it('should sort MAS priority sizes in the proper order w/ rest ascending', function () { - let ordering = masSizeOrdering([43, 9, 65, 15, 16, 126]); - expect(ordering).to.deep.equal([15, 9, 16, 43, 65, 126]); - - ordering = masSizeOrdering([43, 15, 9, 65, 16, 126, 2]); - expect(ordering).to.deep.equal([15, 2, 9, 16, 43, 65, 126]); - - ordering = masSizeOrdering([8, 43, 9, 65, 16, 126, 2]); - expect(ordering).to.deep.equal([2, 9, 8, 16, 43, 65, 126]); - }); - }); - - describe('buildRequests implementation', function () { - describe('for requests', function () { - describe('to fastlane', function () { - it('should make a well-formed request object', function () { - sandbox.stub(Math, 'random').callsFake(() => 0.1); - const duplicate = Object.assign(bidderRequest); - duplicate.bids[0].params.floor = 0.01; - - const [request] = spec.buildRequests(duplicate.bids, duplicate); - const data = new URLSearchParams(request.data); - - expect(request.url).to.equal('https://fastlane.rubiconproject.com/a/api/fastlane.json'); - - const expectedQuery = { - 'account_id': '14062', - 'site_id': '70608', - 'zone_id': '335918', - 'size_id': '15', - 'alt_size_ids': '43', - 'p_pos': 'atf', - 'rp_floor': '0.01', - 'rp_secure': /[01]/, - 'rand': '0.1', - 'tk_flint': INTEGRATION, - 'x_source.tid': 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', - 'p_screen_res': /\d+x\d+/, - 'tk_user_key': '12346', - 'kw': 'a,b,c', - 'tg_v.ucat': 'new', - 'tg_v.lastsearch': 'iphone', - 'tg_v.likes': 'sports,video games', - 'tg_i.rating': '5-star', - 'tg_i.prodtype': 'tech,mobile', - 'tg_fl.eid': 'div-1', - 'rf': 'localhost' - }; - - // test that all values above are both present and correct - Object.keys(expectedQuery).forEach(key => { - const value = expectedQuery[key]; - if (value instanceof RegExp) { - expect(data.get(key)).to.match(value); - } else { - expect(data.get(key)).to.equal(value); - } - }); - }); - - it('should correctly send hard floors when getFloor function is present and returns valid floor', function () { - // default getFloor response is empty object so should not break and not send hard_floor - bidderRequest.bids[0].getFloor = () => getFloorResponse; - sinon.spy(bidderRequest.bids[0], 'getFloor'); - let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - - // make sure banner bid called with right stuff - expect( - bidderRequest.bids[0].getFloor.calledWith({ - currency: 'USD', - mediaType: 'banner', - size: '*' - }) - ).to.be.true; - - let data = new URLSearchParams(request.data); - expect(data.get('rp_hard_floor')).to.be.null; - - // not an object should work and not send - getFloorResponse = undefined; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - data = new URLSearchParams(request.data); - expect(data.get('rp_hard_floor')).to.be.null; - - // make it respond with a non USD floor should not send it - getFloorResponse = {currency: 'EUR', floor: 1.0}; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - data = new URLSearchParams(request.data); - expect(data.get('rp_hard_floor')).to.be.null; - - // make it respond with a non USD floor should not send it - getFloorResponse = {currency: 'EUR'}; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - data = new URLSearchParams(request.data); - expect(data.get('rp_hard_floor')).to.be.null; - - // make it respond with USD floor and string floor - getFloorResponse = {currency: 'USD', floor: '1.23'}; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - data = new URLSearchParams(request.data); - expect(data.get('rp_hard_floor')).to.equal('1.23'); - - // make it respond with USD floor and num floor - getFloorResponse = {currency: 'USD', floor: 1.23}; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - data = new URLSearchParams(request.data); - expect(data.get('rp_hard_floor')).to.equal('1.23'); - }); - - it('should send rp_maxbids to AE if rubicon multibid config exists', function () { - var multibidRequest = utils.deepClone(bidderRequest); - multibidRequest.bidLimit = 5; - - const [request] = spec.buildRequests(multibidRequest.bids, multibidRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('rp_maxbids')).to.equal('5'); - }); - - it('should not send p_pos to AE if not params.position specified', function () { - var noposRequest = utils.deepClone(bidderRequest); - delete noposRequest.bids[0].params.position; - - const [request] = spec.buildRequests(noposRequest.bids, noposRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('site_id')).to.equal('70608'); - expect(data.get('p_pos')).to.equal(null); - }); - - it('should not send p_pos to AE if not mediaTypes.banner.pos is invalid', function () { - var bidRequest = utils.deepClone(bidderRequest); - bidRequest.bids[0].mediaTypes = { - banner: { - pos: 5 - } - }; - delete bidRequest.bids[0].params.position; - - const [request] = spec.buildRequests(bidRequest.bids, bidRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('site_id')).to.equal('70608'); - expect(data.get('p_pos')).to.equal(null); - }); - - it('should send p_pos to AE if mediaTypes.banner.pos is valid', function () { - var bidRequest = utils.deepClone(bidderRequest); - bidRequest.bids[0].mediaTypes = { - banner: { - pos: 1 - } - }; - delete bidRequest.bids[0].params.position; - - const [request] = spec.buildRequests(bidRequest.bids, bidRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('site_id')).to.equal('70608'); - expect(data.get('p_pos')).to.equal('atf'); - }); - - it('should not send p_pos to AE if not params.position is invalid', function () { - var badposRequest = utils.deepClone(bidderRequest); - badposRequest.bids[0].params.position = 'bad'; - - const [request] = spec.buildRequests(badposRequest.bids, badposRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('site_id')).to.equal('70608'); - expect(data.get('p_pos')).to.equal(null); - }); - - it('should correctly send p_pos in sra fashion', function() { - config.setConfig({rubicon: {singleRequest: true}}); - // first one is atf - var sraPosRequest = utils.deepClone(bidderRequest); - - // second is not present - const bidCopy = utils.deepClone(sraPosRequest.bids[0]); - delete bidCopy.params.position; - sraPosRequest.bids.push(bidCopy); - - // third is btf - const bidCopy1 = utils.deepClone(sraPosRequest.bids[0]); - bidCopy1.params.position = 'btf'; - sraPosRequest.bids.push(bidCopy1); - - // fourth is invalid (aka not atf or btf) - const bidCopy2 = utils.deepClone(sraPosRequest.bids[0]); - bidCopy2.params.position = 'unknown'; - sraPosRequest.bids.push(bidCopy2); - - // fifth is not present - const bidCopy3 = utils.deepClone(sraPosRequest.bids[0]); - delete bidCopy3.params.position; - sraPosRequest.bids.push(bidCopy3); - - const [request] = spec.buildRequests(sraPosRequest.bids, sraPosRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('p_pos')).to.equal('atf;;btf;;'); - }); - - it('should correctly send cdep signal when requested', () => { - var badposRequest = utils.deepClone(bidderRequest); - badposRequest.bids[0].ortb2 = {device: {ext: {cdep: 3}}}; - - const [request] = spec.buildRequests(badposRequest.bids, badposRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('o_cdep')).to.equal('3'); - }); - - it('should correctly send ip signal when ortb2.device.ip is provided', () => { - const ipRequest = utils.deepClone(bidderRequest); - ipRequest.bids[0].ortb2 = { device: { ip: '123.45.67.89' } }; - - const [request] = spec.buildRequests(ipRequest.bids, ipRequest); - const data = new URLSearchParams(request.data); - - // Verify if 'ip' is correctly added to the request data - expect(data.get('ip')).to.equal('123.45.67.89'); - }); - - it('should correctly send ipv6 signal when ortb2.device.ipv6 is provided', () => { - const ipv6Request = utils.deepClone(bidderRequest); - ipv6Request.bids[0].ortb2 = { device: { ipv6: '2001:db8::ff00:42:8329' } }; - - const [request] = spec.buildRequests(ipv6Request.bids, ipv6Request); - const data = new URLSearchParams(request.data); - - // Verify if 'ipv6' is correctly added to the request data - expect(data.get('ipv6')).to.equal('2001:db8::ff00:42:8329'); - }); - - it('ad engine query params should be ordered correctly', function () { - sandbox.stub(Math, 'random').callsFake(() => 0.1); - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - - const referenceOrdering = ['account_id', 'site_id', 'zone_id', 'size_id', 'alt_size_ids', 'p_pos', 'rf', 'p_geo.latitude', 'p_geo.longitude', 'kw', 'tg_v.ucat', 'tg_v.lastsearch', 'tg_v.likes', 'tg_i.rating', 'tg_i.prodtype', 'tk_flint', 'x_source.tid', 'l_pb_bid_id', 'p_screen_res', 'rp_secure', 'tk_user_key', 'x_imp.ext.tid', 'tg_fl.eid', 'slots', 'rand']; - - request.data.split('&').forEach((item, i) => { - expect(item.split('=')[0]).to.equal(referenceOrdering[i]); - }); - }); - - it('should make a well-formed request object without latLong', function () { - const expectedQuery = { - 'account_id': '14062', - 'site_id': '70608', - 'zone_id': '335918', - 'size_id': '15', - 'alt_size_ids': '43', - 'p_pos': 'atf', - 'rp_secure': /[01]/, - 'rand': '0.1', - 'tk_flint': INTEGRATION, - 'x_source.tid': 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', - 'x_imp.ext.tid': 'd45dd707-a418-42ec-b8a7-b70a6c6fab0b', - 'p_screen_res': /\d+x\d+/, - 'tk_user_key': '12346', - 'kw': 'a,b,c', - 'tg_v.ucat': 'new', - 'tg_v.lastsearch': 'iphone', - 'tg_v.likes': 'sports,video games', - 'tg_i.rating': '5-star', - 'tg_i.prodtype': 'tech,mobile', - 'rf': 'localhost', - 'p_geo.latitude': null, - 'p_geo.longitude': null - }; - - sandbox.stub(Math, 'random').callsFake(() => 0.1); - - delete bidderRequest.bids[0].params.latLong; - let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - let data = new URLSearchParams(request.data); - - expect(request.url).to.equal('https://fastlane.rubiconproject.com/a/api/fastlane.json'); - - // test that all values above are both present and correct - Object.keys(expectedQuery).forEach(key => { - const value = expectedQuery[key]; - if (value instanceof RegExp) { - expect(data.get(key)).to.match(value); - } else { - expect(data.get(key)).to.equal(value); - } - }); - - bidderRequest.bids[0].params.latLong = []; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - data = new URLSearchParams(request.data); - - expect(request.url).to.equal('https://fastlane.rubiconproject.com/a/api/fastlane.json'); - - // test that all values above are both present and correct - Object.keys(expectedQuery).forEach(key => { - const value = expectedQuery[key]; - if (value instanceof RegExp) { - expect(data.get(key)).to.match(value); - } else { - expect(data.get(key)).to.equal(value); - } - }); - }); - - it('should add referer info to request data', function () { - const refererInfo = { - page: 'https://www.prebid.org', - reachedTop: true, - numIframes: 1, - stack: [ - 'https://www.prebid.org/page.html', - 'https://www.prebid.org/iframe1.html', - ] - }; - - bidderRequest = Object.assign({refererInfo}, bidderRequest); - delete bidderRequest.bids[0].params.referrer; - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - - expect(new URLSearchParams(request.data).get('rf')).to.exist; - expect(new URLSearchParams(request.data).get('rf')).to.equal('https://www.prebid.org'); - }); - - it('page_url should use params.referrer, bidderRequest.refererInfo in that order', function () { - let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(new URLSearchParams(request.data).get('rf')).to.equal('localhost'); - - delete bidderRequest.bids[0].params.referrer; - const refererInfo = {page: 'https://www.prebid.org'}; - bidderRequest = Object.assign({refererInfo}, bidderRequest); - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(new URLSearchParams(request.data).get('rf')).to.equal('https://www.prebid.org'); - - bidderRequest.refererInfo.page = 'http://www.prebid.org'; - bidderRequest.bids[0].params.secure = true; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(new URLSearchParams(request.data).get('rf')).to.equal('https://www.prebid.org'); - }); - - it('should use rubicon sizes if present (including non-mappable sizes)', function () { - var sizesBidderRequest = utils.deepClone(bidderRequest); - sizesBidderRequest.bids[0].params.sizes = [55, 57, 59, 801]; - - const [request] = spec.buildRequests(sizesBidderRequest.bids, sizesBidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('size_id')).to.equal('55'); - expect(data.get('alt_size_ids')).to.equal('57,59,801'); - }); - - it('should not validate bid request if no valid sizes', function () { - var sizesBidderRequest = utils.deepClone(bidderRequest); - sizesBidderRequest.bids[0].sizes = [[621, 250], [300, 251]]; - - const result = spec.isBidRequestValid(sizesBidderRequest.bids[0]); - - expect(result).to.equal(false); - }); - - it('should not validate bid request if no account id is present', function () { - var noAccountBidderRequest = utils.deepClone(bidderRequest); - delete noAccountBidderRequest.bids[0].params.accountId; - - const result = spec.isBidRequestValid(noAccountBidderRequest.bids[0]); - - expect(result).to.equal(false); - }); - - it('should allow a floor override', function () { - var floorBidderRequest = utils.deepClone(bidderRequest); - floorBidderRequest.bids[0].params.floor = 2; - - const [request] = spec.buildRequests(floorBidderRequest.bids, floorBidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('rp_floor')).to.equal('2'); - }); - - describe('GDPR consent config', function () { - it('should send "gdpr" and "gdpr_consent", when gdprConsent defines consentString and gdprApplies', function () { - const bidderRequest = createGdprBidderRequest(true); - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('gdpr')).to.equal('1'); - expect(data.get('gdpr_consent')).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A=='); - }); - - it('should send only "gdpr_consent", when gdprConsent defines only consentString', function () { - const bidderRequest = createGdprBidderRequest(); - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('gdpr_consent')).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A=='); - expect(data.get('gdpr')).to.equal(null); - }); - - it('should not send GDPR params if gdprConsent is not defined', function () { - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('gdpr')).to.equal(null); - expect(data.get('gdpr_consent')).to.equal(null); - }); - - it('should set "gdpr" value as 1 or 0, using "gdprApplies" value of either true/false', function () { - let bidderRequest = createGdprBidderRequest(true); - let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - let data = new URLSearchParams(request.data); - expect(data.get('gdpr')).to.equal('1'); - - bidderRequest = createGdprBidderRequest(false); - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - data = new URLSearchParams(request.data); - expect(data.get('gdpr')).to.equal('0'); - }); - }); - - describe('USP Consent', function () { - it('should send us_privacy if bidderRequest has a value for uspConsent', function () { - addUspToBidderRequest(bidderRequest); - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('us_privacy')).to.equal('1NYN'); - }); - - it('should not send us_privacy if bidderRequest has no uspConsent value', function () { - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('us_privacy')).to.equal(null); - }); - }); - - describe('GPP Consent', function () { - it('should send gpp information if bidderRequest has a value for gppConsent', function () { - bidderRequest.gppConsent = { - gppString: 'consent', - applicableSections: 2 - }; - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - delete bidderRequest.gppConsent; - - expect(data.get('gpp')).to.equal('consent'); - expect(data.get('gpp_sid')).to.equal('2'); - }); - - it('should not send gpp information if bidderRequest does not have a value for gppConsent', function () { - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('gpp')).to.equal(null); - expect(data.get('gpp_sid')).to.equal(null); - }); - }); - - describe('first party data', function () { - it('should not have any tg_v or tg_i params if all are undefined', function () { - const params = { - inventory: { - rating: null, - prodtype: undefined - }, - visitor: { - ucat: undefined, - lastsearch: null, - likes: undefined - }, - }; - - // Overwrite the bidder request params with the above ones - Object.assign(bidderRequest.bids[0].params, params); - - // get the built request - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - // make sure that no tg_v or tg_i keys are present in the request - const matchingExp = RegExp('^tg_(i|v)\..*$'); - // Display the keys - for (const key of data.keys()) { - expect(key).to.not.match(matchingExp); - } - }); - - it('should contain valid params when some are undefined', function () { - const params = { - inventory: { - rating: undefined, - prodtype: ['tech', 'mobile'] - }, - visitor: { - ucat: null, - lastsearch: 'iphone', - likes: undefined - }, - }; - const undefinedKeys = ['tg_i.rating', 'tg_v.ucat', 'tg_v.likes'] - const expectedQuery = { - 'tg_v.lastsearch': 'iphone', - 'tg_i.prodtype': 'tech,mobile', - } - - // Overwrite the bidder request params with the above ones - Object.assign(bidderRequest.bids[0].params, params); - - // get the built request - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - // make sure none of the undefined keys are in query - undefinedKeys.forEach(key => { - expect(data.get(key)).to.equal(null); - }); - - // make sure the expected and defined ones do show up still - Object.keys(expectedQuery).forEach(key => { - const value = expectedQuery[key]; - expect(data.get(key)).to.equal(value); - }); - }); - - it('should merge first party data from getConfig with the bid params, if present', () => { - const site = { - keywords: 'e,f', - rating: '4-star', - ext: { - data: { - page: 'home' - } - }, - content: { - data: [{ - 'name': 'www.dataprovider1.com', - 'ext': { 'segtax': 1 }, - 'segment': [ - { 'id': '987' } - ] - }, { - 'name': 'www.dataprovider1.com', - 'ext': { 'segtax': 2 }, - 'segment': [ - { 'id': '432' } - ] - }, { - 'name': 'www.dataprovider1.com', - 'ext': { 'segtax': 5 }, - 'segment': [ - { 'id': '55' } - ] - }, { - 'name': 'www.dataprovider1.com', - 'ext': { 'segtax': 6 }, - 'segment': [ - { 'id': '66' } - ] - } - ] - } - }; - const user = { - data: [{ - 'name': 'www.dataprovider1.com', - 'ext': { 'segtax': 4 }, - 'segment': [ - { 'id': '687' }, - { 'id': '123' } - ] - }], - gender: 'M', - yob: '1984', - geo: {country: 'ca'}, - keywords: 'd', - ext: { - data: { - age: 40 - } - } - }; - - const ortb2 = { - site, - user - } - - const expectedQuery = { - 'kw': 'a,b,c,d', - 'tg_v.ucat': 'new', - 'tg_v.lastsearch': 'iphone', - 'tg_v.likes': 'sports,video games', - 'tg_v.gender': 'M', - 'tg_v.age': '40', - 'tg_v.iab': '687,123', - 'tg_i.iab': '987,432,55,66', - 'tg_v.yob': '1984', - 'tg_i.rating': '4-star,5-star', - 'tg_i.page': 'home', - 'tg_i.prodtype': 'tech,mobile', - }; - - // get the built request - const [request] = spec.buildRequests(bidderRequest.bids.map((b) => ({...b, ortb2})), bidderRequest); - const data = new URLSearchParams(request.data); - - // make sure that tg_v, tg_i, and kw values are correct - Object.keys(expectedQuery).forEach(key => { - const value = expectedQuery[key]; - expect(data.get(key)).to.deep.equal(value); - }); - }); - }); - - describe('singleRequest config', function () { - it('should group all bid requests with the same site id', function () { - sandbox.stub(Math, 'random').callsFake(() => 0.1); - - config.setConfig({rubicon: {singleRequest: true}}); - - const expectedQuery = { - 'account_id': '14062', - 'site_id': '70608', - 'zone_id': '335918', - 'size_id': '15', - 'alt_size_ids': '43', - 'p_pos': 'atf', - 'rp_secure': /[01]/, - 'rand': '0.1', - 'tk_flint': INTEGRATION, - 'x_source.tid': 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', - 'p_screen_res': /\d+x\d+/, - 'tk_user_key': '12346', - 'kw': 'a,b,c', - 'tg_v.ucat': 'new', - 'tg_v.lastsearch': 'iphone', - 'tg_v.likes': 'sports,video games', - 'tg_i.rating': '5-star', - 'tg_i.prodtype': 'tech,mobile', - 'tg_fl.eid': 'div-1', - 'rf': 'localhost' - }; - - const bidCopy = utils.deepClone(bidderRequest.bids[0]); - bidCopy.params.siteId = '70608'; - bidCopy.params.zoneId = '1111'; - bidderRequest.bids.push(bidCopy); - - const bidCopy2 = utils.deepClone(bidderRequest.bids[0]); - bidCopy2.params.siteId = '99999'; - bidCopy2.params.zoneId = '2222'; - bidderRequest.bids.push(bidCopy2); - - const bidCopy3 = utils.deepClone(bidderRequest.bids[0]); - bidCopy3.params.siteId = '99999'; - bidCopy3.params.zoneId = '3333'; - bidderRequest.bids.push(bidCopy3); - - const serverRequests = spec.buildRequests(bidderRequest.bids, bidderRequest); - - // array length should match the num of unique 'siteIds' - expect(serverRequests).to.be.a('array'); - expect(serverRequests).to.have.lengthOf(2); - - // collect all bidRequests so order can be checked against the url param slot order - const bidRequests = serverRequests.reduce((aggregator, item) => aggregator.concat(item.bidRequest), []); - let bidRequestIndex = 0; - - serverRequests.forEach(item => { - expect(item).to.be.a('object'); - expect(item).to.have.property('method'); - expect(item).to.have.property('url'); - expect(item).to.have.property('data'); - expect(item).to.have.property('bidRequest'); - - expect(item.method).to.equal('GET'); - expect(item.url).to.equal('https://fastlane.rubiconproject.com/a/api/fastlane.json'); - expect(item.data).to.be.a('string'); - - // 'bidRequest' type must be 'array' if SRA enabled - expect(item.bidRequest).to.be.a('array').to.have.lengthOf(2); - - item.bidRequest.forEach((bidRequestItem, i, array) => { - expect(bidRequestItem).to.be.a('object'); - // every 'siteId' values need to match - expect(bidRequestItem.params.siteId).to.equal(array[0].params.siteId); - }); - - const data = new URLSearchParams(item.data); - - Object.keys(expectedQuery).forEach(key => { - expect(data.get(key)).to.be.exist; - - // extract semicolon delineated values - const params = data.get(key).split(';'); - - // skip value test for site and zone ids - if (key !== 'site_id' && key !== 'zone_id') { - if (expectedQuery[key] instanceof RegExp) { - params.forEach(paramItem => { - expect(paramItem).to.match(expectedQuery[key]); - }); - } else { - expect(params).to.contain(expectedQuery[key]); - } - } - - // check parsed url data list order with requestBid list, items must have same index in both lists - if (key === 'zone_id') { - params.forEach((p) => { - expect(bidRequests[bidRequestIndex]).to.be.a('object'); - expect(bidRequests[bidRequestIndex].params).to.be.a('object'); - - // 'zone_id' is used to verify so each bid must have a unique 'zone_id' - expect(p).to.equal(bidRequests[bidRequestIndex].params.zoneId); - - // increment to next bidRequest index having verified that item positions match in url params and bidRequest lists - bidRequestIndex++; - }); - } - }); - }); - }); - - it('should not send more than 10 bids in a request (split into separate requests with <= 10 bids each)', function () { - config.setConfig({rubicon: {singleRequest: true}}); - let serverRequests; - let data; - - // TEST '10' BIDS, add 9 to 1 existing bid - for (let i = 0; i < 9; i++) { - const bidCopy = utils.deepClone(bidderRequest.bids[0]); - bidCopy.params.zoneId = `${i}0000`; - bidderRequest.bids.push(bidCopy); - } - serverRequests = spec.buildRequests(bidderRequest.bids, bidderRequest); - // '10' bids per SRA request: so there should be 1 request - expect(serverRequests.length).to.equal(1); - // and that one request should have data from 10 bids - expect(serverRequests[0].bidRequest).to.have.lengthOf(10); - // check that slots param value matches - expect(serverRequests[0].data.indexOf('&slots=10&') !== -1).to.equal(true); - // check that zone_id has 10 values (since all zone_ids are unique all should exist in get param) - data = new URLSearchParams(serverRequests[0].data); - expect(typeof data).to.equal('object'); - expect(data.get('zone_id')).to.be.exist; - expect(data.get('zone_id').split(';')).to.have.lengthOf(10); - - // TEST '100' BIDS, add 90 to the previously added 10 - for (let i = 0; i < 90; i++) { - const bidCopy = utils.deepClone(bidderRequest.bids[0]); - bidCopy.params.zoneId = `${(i + 10)}0000`; - bidderRequest.bids.push(bidCopy); - } - serverRequests = spec.buildRequests(bidderRequest.bids, bidderRequest); - // '100' bids: should be '10' SRA requests - expect(serverRequests.length).to.equal(10); - // check that each request has 10 items - serverRequests.forEach((serverRequest) => { - // and that one request should have data from 10 bids - expect(serverRequest.bidRequest).to.have.lengthOf(10); - // check that slots param value matches - expect(serverRequest.data.indexOf('&slots=10&') !== -1).to.equal(true); - }); - }); - - it('should still use single request if other rubicon configs are set after', function () { - // set single request to true - config.setConfig({ rubicon: { singleRequest: true } }); - - // execute some other rubicon setConfig - config.setConfig({ rubicon: { netRevenue: true } }); - - const bidCopy = utils.deepClone(bidderRequest.bids[0]); - bidderRequest.bids.push(bidCopy); - bidderRequest.bids.push(bidCopy); - bidderRequest.bids.push(bidCopy); - - const serverRequests = spec.buildRequests(bidderRequest.bids, bidderRequest); - - // should have 1 request only - expect(serverRequests).that.is.an('array').of.length(1); - - // get the built query - const data = new URLSearchParams(serverRequests[0].data); - - // num slots should be 4 - expect(data.get('slots')).to.equal('4'); - }); - - it('should not group bid requests if singleRequest does not equal true', function () { - config.setConfig({rubicon: {singleRequest: false}}); - - const bidCopy = utils.deepClone(bidderRequest.bids[0]); - bidderRequest.bids.push(bidCopy); - - const bidCopy2 = utils.deepClone(bidderRequest.bids[0]); - bidCopy2.params.siteId = '32001'; - bidderRequest.bids.push(bidCopy2); - - const bidCopy3 = utils.deepClone(bidderRequest.bids[0]); - bidCopy3.params.siteId = '32001'; - bidderRequest.bids.push(bidCopy3); - - const serverRequests = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(serverRequests).that.is.an('array').of.length(4); - }); - - it('should not group video bid requests', function () { - config.setConfig({rubicon: {singleRequest: true}}); - - const bidCopy = utils.deepClone(bidderRequest.bids[0]); - bidderRequest.bids.push(bidCopy); - - const bidCopy2 = utils.deepClone(bidderRequest.bids[0]); - bidCopy2.params.siteId = '32001'; - bidderRequest.bids.push(bidCopy2); - - const bidCopy3 = utils.deepClone(bidderRequest.bids[0]); - bidCopy3.params.siteId = '32001'; - bidderRequest.bids.push(bidCopy3); - - const bidCopy4 = utils.deepClone(bidderRequest.bids[0]); - bidCopy4.mediaTypes = { - video: { - context: 'instream', - playerSize: [640, 480], - mimes: ['video/mp4', 'video/x-ms-wmv'], - protocols: [2, 5], - maxduration: 30, - linearity: 1, - api: [2] - } - }; - bidCopy4.params.video = { - 'language': 'en', - 'p_aso.video.ext.skip': true, - 'p_aso.video.ext.skipdelay': 15, - 'playerHeight': 320, - 'playerWidth': 640, - 'size_id': 201, - 'aeParams': { - 'p_aso.video.ext.skip': '1', - 'p_aso.video.ext.skipdelay': '15' - } - }; - bidderRequest.bids.push(bidCopy4); - - const serverRequests = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(serverRequests).that.is.an('array').of.length(3); - }); - }); - - describe('user id config', function () { - describe('pubcid support', function () { - it('should send eid_pubcid.org when ortb2.user.ext.eids contains pubcid', function () { - const clonedBid = utils.deepClone(bidderRequest.bids[0]); - clonedBid.userId = { - pubcid: '1111' - }; - clonedBid.ortb2 = { - user: { - ext: { - eids: [{ - 'source': 'pubcid.org', - 'uids': [{ - 'id': '1111', - 'atype': 1 - }] - }] - } - } - }; - const [request] = spec.buildRequests([clonedBid], bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('eid_pubcid.org')).to.equal('1111^1^^^^^'); - }); - }); - - describe('Criteo support', function () { - it('should send eid_criteo.com when ortb2.user.ext.eids contains criteo', function () { - const clonedBid = utils.deepClone(bidderRequest.bids[0]); - clonedBid.userId = { - criteoId: '1111' - }; - clonedBid.ortb2 = { - user: { - ext: { - eids: [{ - 'source': 'criteo.com', - 'uids': [{ - 'id': '1111', - 'atype': 1 - }] - }] - } - } - }; - const [request] = spec.buildRequests([clonedBid], bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('eid_criteo.com')).to.equal('1111^1^^^^^'); - }); - }); - - describe('pubProvidedId support', function () { - it('should send pubProvidedId when ortb2.user.ext.eids contains pubProvidedId ids', function () { - const clonedBid = utils.deepClone(bidderRequest.bids[0]); - clonedBid.userId = { - pubProvidedId: [{ - source: 'example.com', - uids: [{ - id: '11111', - ext: { - stype: 'ppuid' - } - }] - }, { - source: 'id-partner.com', - uids: [{ - id: '222222' - }] - }] - }; - clonedBid.ortb2 = { - user: { - ext: { - eids: [{ - 'source': 'example.com', - 'uids': [{ - 'id': '11111', - 'ext': { - 'stype': 'ppuid' - } - }] - }, - { - 'source': 'id-partner.com', - 'uids': [{ - 'id': '222222' - }] - }] - } - } - }; - const [request] = spec.buildRequests([clonedBid], bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('ppuid')).to.equal('11111'); - }); - }); - - describe('ID5 support', function () { - it('should send ID5 id when ortb2.user.ext.eids contains ID5', function () { - const clonedBid = utils.deepClone(bidderRequest.bids[0]); - clonedBid.userId = { - id5id: { - uid: '11111', - ext: { - linkType: '22222' - } - } - }; - clonedBid.ortb2 = { - user: { - ext: { - eids: [{ - 'source': 'id5-sync.com', - 'uids': [{ - 'id': '11111', - 'atype': 1, - 'ext': { - 'linkType': '22222' - } - }] - }] - } - } - }; - const [request] = spec.buildRequests([clonedBid], bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('eid_id5-sync.com')).to.equal('11111^1^^^^^'); - }); - }); - - describe('UserID catchall support', function () { - it('should send user id with generic format', function () { - const clonedBid = utils.deepClone(bidderRequest.bids[0]); - // Hardcoding userIdAsEids since createEidsArray returns empty array if source not found in eids.js - clonedBid.ortb2 = { - user: { - ext: { - eids: [{ - 'source': 'catchall', - 'uids': [{ - 'id': '11111', - 'atype': 2 - }] - }] - } - } - }; - const [request] = spec.buildRequests([clonedBid], bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('eid_catchall')).to.equal('11111^2^^^^^'); - }); - - it('should send rubiconproject special case', function () { - const clonedBid = utils.deepClone(bidderRequest.bids[0]); - // Hardcoding userIdAsEids since createEidsArray returns empty array if source not found in eids.js - clonedBid.ortb2 = { - user: { - ext: { - eids: [{ - source: 'rubiconproject.com', - uids: [{ - id: 'some-cool-id', - atype: 3 - }] - }] - } - } - }; - const [request] = spec.buildRequests([clonedBid], bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('eid_rubiconproject.com')).to.equal('some-cool-id^3^^^^^'); - }); - describe('Full eidValue format validation', function () { - it('should send complete eidValue in the format uid^atype^third^inserter^matcher^mm^rtipartner', function () { - const clonedBid = utils.deepClone(bidderRequest.bids[0]); - // Simulating a full EID object with multiple fields - clonedBid.ortb2 = { - user: { - ext: { - eids: [{ - source: 'example.com', - uids: [{ - id: '11111', // UID - atype: 2, // atype - ext: { - rtipartner: 'rtipartner123', // rtipartner - stype: 'ppuid' // stype - } - }], - inserter: 'inserter123', // inserter - matcher: 'matcher123', // matcher - mm: 'mm123' // mm - }] - } - } - }; - - const [request] = spec.buildRequests([clonedBid], bidderRequest); - const data = new URLSearchParams(request.data); - - // Expected format: uid^atype^third^inserter^matcher^mm^rtipartner - const expectedEidValue = '11111^2^^inserter123^matcher123^mm123^rtipartner123'; - - // Check if the generated EID value matches the expected format - expect(data.get('eid_example.com')).to.equal(expectedEidValue); - }); - it('should generate eidValue with all attributes including rtiPartner', function () { - const clonedBid = utils.deepClone(bidderRequest.bids[0]); - // Simulating a full EID object with multiple fields - clonedBid.ortb2 = { - user: { - ext: { - eids: [{ - source: 'example.com', - uids: [{ - id: '11111', // UID - atype: 2, // atype - ext: { - rtiPartner: 'rtipartner123', // rtiPartner (note the different capitalization) - stype: 'ppuid' // stype - } - }], - inserter: 'inserter123', // inserter - matcher: 'matcher123', // matcher - mm: 'mm123' // mm - }] - } - } - }; - - const [request] = spec.buildRequests([clonedBid], bidderRequest); - const data = new URLSearchParams(request.data); - - // Expected format: uid^atype^third^inserter^matcher^mm^rtipartner - const expectedEidValue = '11111^2^^inserter123^matcher123^mm123^rtipartner123'; - - // Check if the generated EID value matches the expected format - expect(data.get('eid_example.com')).to.equal(expectedEidValue); - }); - }); - }); - describe('Config user.id support', function () { - it('should send ppuid when config defines user.id', function () { - config.setConfig({user: {id: '123'}}); - const clonedBid = utils.deepClone(bidderRequest.bids[0]); - clonedBid.userId = { - pubcid: '1111' - }; - const [request] = spec.buildRequests([clonedBid], bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('ppuid')).to.equal('123'); - }); - }); - }); - - describe('Prebid AdSlot', function () { - beforeEach(function () { - // enforce that the bid at 0 does not have a 'context' property - if (bidderRequest.bids[0].hasOwnProperty('ortb2Imp')) { - delete bidderRequest.bids[0].ortb2Imp; - } - }); - - it('should not send \"tg_i.pbadslot’\" if \"ortb2Imp.ext.data\" object is not valid', function () { - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(typeof data).to.equal('object'); - expect(data.get('tg_i.pbadslot’')).to.be.null; - }); - - it('should not send \"tg_i.pbadslot’\" if \"ortb2Imp.ext.data.pbadslot\" is undefined', function () { - bidderRequest.bids[0].ortb2Imp = {}; - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(typeof data).to.equal('object'); - expect(data.get('tg_i.pbadslot’')).to.be.null; - }); - - it('should not send \"tg_i.pbadslot’\" if \"ortb2Imp.ext.data.pbadslot\" value is an empty string', function () { - bidderRequest.bids[0].ortb2Imp = { - ext: { - data: { - pbadslot: '' - } - } - }; - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(typeof data).to.equal('object'); - expect(data.get('tg_i.pbadslot')).to.be.null; - }); - - it('should send \"tg_i.pbadslot\" if \"ortb2Imp.ext.data.pbadslot\" value is a valid string', function () { - bidderRequest.bids[0].ortb2Imp = { - ext: { - data: { - pbadslot: 'abc' - } - } - } - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(typeof data).to.equal('object'); - expect(data.get('tg_i.pbadslot')).to.be.exist; - expect(data.get('tg_i.pbadslot')).to.equal('abc'); - }); - - it('should send \"tg_i.pbadslot\" if \"ortb2Imp.ext.data.pbadslot\" value is a valid string', function () { - bidderRequest.bids[0].ortb2Imp = { - ext: { - data: { - pbadslot: '/a/b/c' - } - } - } - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(typeof data).to.equal('object'); - expect(data.get('tg_i.pbadslot')).to.be.exist; - expect(data.get('tg_i.pbadslot')).to.equal('/a/b/c'); - }); - - it('should send gpid as p_gpid if valid', function () { - bidderRequest.bids[0].ortb2Imp = { - ext: { - gpid: '/1233/sports&div1' - } - } - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(typeof data).to.equal('object'); - expect(data.get('p_gpid')).to.be.exist; - expect(data.get('p_gpid')).to.equal('/1233/sports&div1'); - }); - - describe('Pass DSA signals', function() { - const ortb2 = { - regs: { - ext: { - dsa: { - dsarequired: 3, - pubrender: 0, - datatopub: 2, - transparency: [ - { - domain: 'testdomain.com', - dsaparams: [1], - }, - { - domain: 'testdomain2.com', - dsaparams: [1, 2] - } - ] - } - } - } - } - it('should send valid dsaparams but filter out invalid ones', function () { - const ortb2Clone = JSON.parse(JSON.stringify(ortb2)); - ortb2Clone.regs.ext.dsa.transparency = [ - { - domain: 'testdomain.com', - dsaparams: [1], - }, - { - domain: '', - dsaparams: [2], - } - ]; - - const expectedTransparency = 'testdomain.com~1'; - const [request] = spec.buildRequests(bidderRequest.bids.map((b) => ({ ...b, ortb2: ortb2Clone })), bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('dsatransparency')).to.equal(expectedTransparency); - }) - it('should send dsaparams if \"ortb2.regs.ext.dsa.transparancy[0].params\"', function() { - const ortb2Clone = JSON.parse(JSON.stringify(ortb2)); - - ortb2Clone.regs.ext.dsa.transparency = [{ - domain: 'testdomain.com', - dsaparams: [1], - }]; - - const expectedTransparency = 'testdomain.com~1'; - const [request] = spec.buildRequests(bidderRequest.bids.map((b) => ({...b, ortb2: ortb2Clone})), bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('dsatransparency')).to.equal(expectedTransparency); - }) - it('should pass an empty transparency param if \"ortb2.regs.ext.dsa.transparency[0].params\" is empty', function() { - const ortb2Clone = JSON.parse(JSON.stringify(ortb2)); - - ortb2Clone.regs.ext.dsa.transparency = [{ - domain: 'testdomain.com', - params: [], - }]; - - const [request] = spec.buildRequests(bidderRequest.bids.map((b) => ({...b, ortb2: ortb2Clone})), bidderRequest); - const data = new URLSearchParams(request.data); - expect(data.get('dsatransparency')).to.be.null - }) - it('should send an empty transparency if \"ortb2.regs.ext.dsa.transparency[0].domain\" is empty', function() { - const ortb2Clone = JSON.parse(JSON.stringify(ortb2)); - - ortb2Clone.regs.ext.dsa.transparency = [{ - domain: '', - dsaparams: [1], - }]; - - const [request] = spec.buildRequests(bidderRequest.bids.map((b) => ({...b, ortb2: ortb2Clone})), bidderRequest); - const data = new URLSearchParams(request.data); - - expect(data.get('dsatransparency')).to.be.null - }) - it('should send dsa signals if \"ortb2.regs.ext.dsa\"', function() { - const expectedTransparency = 'testdomain.com~1~~testdomain2.com~1_2' - const [request] = spec.buildRequests(bidderRequest.bids.map((b) => ({...b, ortb2})), bidderRequest) - const data = new URLSearchParams(request.data); - - expect(typeof data).to.equal('object'); - expect(data.get('dsarequired')).to.be.exist; - expect(data.get('dsapubrender')).to.be.exist; - expect(data.get('dsadatatopubs')).to.be.exist; - expect(data.get('dsatransparency')).to.be.exist; - - expect(data.get('dsarequired')).to.equal(ortb2.regs.ext.dsa.dsarequired.toString()); - expect(data.get('dsapubrender')).to.equal(ortb2.regs.ext.dsa.pubrender.toString()); - expect(data.get('dsadatatopubs')).to.equal(ortb2.regs.ext.dsa.datatopub.toString()); - expect(data.get('dsatransparency')).to.equal(expectedTransparency); - }) - it('should return one transparency param', function() { - const expectedTransparency = 'testdomain.com~1'; - const ortb2Clone = deepClone(ortb2); - ortb2Clone.regs.ext.dsa.transparency.pop() - const [request] = spec.buildRequests(bidderRequest.bids.map((b) => ({...b, ortb2: ortb2Clone})), bidderRequest) - const data = new URLSearchParams(request.data); - - expect(typeof data).to.equal('object'); - expect(data.get('dsatransparency')).to.be.exist; - expect(data.get('dsatransparency')).to.equal(expectedTransparency); - }) - }) - - it('should send gpid and pbadslot since it is prefered over dfp code', function () { - bidderRequest.bids[0].ortb2Imp = { - ext: { - gpid: '/1233/sports&div1', - data: { - pbadslot: 'pb_slot', - adserver: { - adslot: '/1234/sports', - name: 'gam' - } - } - } - } - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(typeof data).to.equal('object'); - expect(data.get('p_gpid')).to.equal('/1233/sports&div1'); - expect(data.get('tg_i.dfp_ad_unit_code')).to.be.null; - expect(data.get('tg_i.pbadslot')).to.equal('pb_slot'); - }); - }); - - describe('GAM ad unit', function () { - beforeEach(function () { - // enforce that the bid at 0 does not have a 'context' property - if (bidderRequest.bids[0].hasOwnProperty('ortb2Imp')) { - delete bidderRequest.bids[0].ortb2Imp; - } - }); - - it('should not send \"tg_i.dfp_ad_unit_code’\" if \"ortb2Imp.ext.data\" object is not valid', function () { - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(typeof data).to.equal('object'); - expect(data.get('tg_i.dfp_ad_unit_code’')).to.be.null; - }); - - it('should not send \"tg_i.dfp_ad_unit_code’\" if \"ortb2Imp.ext.data.adServer.adslot\" is undefined', function () { - bidderRequest.bids[0].ortb2Imp = {}; - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(typeof data).to.equal('object'); - expect(data.get('tg_i.dfp_ad_unit_code’')).to.be.null; - }); - - it('should not send \"tg_i.dfp_ad_unit_code’\" if \"ortb2Imp.ext.data.adServer.adslot\" value is an empty string', function () { - bidderRequest.bids[0].ortb2Imp = { - ext: { - data: { - adserver: { - adslot: '' - } - } - } - }; - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(typeof data).to.equal('object'); - expect(data.get('tg_i.dfp_ad_unit_code')).to.be.null; - }); - - it('should send NOT \"tg_i.dfp_ad_unit_code\" if \"ortb2Imp.ext.data.adServer.adslot\" value is a valid string but not gam', function () { - bidderRequest.bids[0].ortb2Imp = { - ext: { - data: { - adserver: { - adslot: '/a/b/c', - name: 'not gam' - } - } - } - } - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(typeof data).to.equal('object'); - expect(data.get('tg_i.dfp_ad_unit_code')).to.but.null; - }); - - it('should send \"tg_i.dfp_ad_unit_code\" if \"ortb2Imp.ext.data.adServer.adslot\" value is a valid string and name is gam', function () { - bidderRequest.bids[0].ortb2Imp = { - ext: { - data: { - adserver: { - name: 'gam', - adslot: '/a/b/c' - } - } - } - }; - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const data = new URLSearchParams(request.data); - - expect(typeof data).to.equal('object'); - expect(data.get('tg_i.dfp_ad_unit_code')).to.be.exist; - expect(data.get('tg_i.dfp_ad_unit_code')).to.equal('/a/b/c'); - }); - }); - - describe('client hints', function () { - let standardSuaObject; - beforeEach(function () { - standardSuaObject = { - source: 2, - platform: { - brand: 'macOS', - version: [ - '12', - '6', - '0' - ] - }, - browsers: [ - { - brand: 'Not.A/Brand', - version: [ - '8', - '0', - '0', - '0' - ] - }, - { - brand: 'Chromium', - version: [ - '114', - '0', - '5735', - '198' - ] - }, - { - brand: 'Google Chrome', - version: [ - '114', - '0', - '5735', - '198' - ] - } - ], - mobile: 0, - model: '', - bitness: '64', - architecture: 'x86' - } - }); - it('should send m_ch_* params if ortb2.device.sua object is there with igh entropy', function () { - const bidRequestSua = utils.deepClone(bidderRequest); - bidRequestSua.bids[0].ortb2 = { device: { sua: standardSuaObject } }; - - // How should fastlane query be constructed with default SUA - const expectedValues = { - m_ch_arch: 'x86', - m_ch_bitness: '64', - m_ch_ua: `"Not.A/Brand"|v="8","Chromium"|v="114","Google Chrome"|v="114"`, - m_ch_full_ver: `"Not.A/Brand"|v="8.0.0.0","Chromium"|v="114.0.5735.198","Google Chrome"|v="114.0.5735.198"`, - m_ch_mobile: '?0', - m_ch_platform: 'macOS', - m_ch_platform_ver: '12.6.0' - } - - // Build Fastlane call - const [request] = spec.buildRequests(bidRequestSua.bids, bidRequestSua); - const data = new URLSearchParams(request.data); - - // Loop through expected values and if they do not match push an error - const errors = Object.entries(expectedValues).reduce((accum, [key, val]) => { - if (data.get(key) !== val) accum.push(`${key} - expect: ${val} - got: ${data[key]}`) - return accum; - }, []); - - // should be no errors - expect(errors).to.deep.equal([]); - }); - it('should not send invalid values for m_ch_*', function () { - const bidRequestSua = utils.deepClone(bidderRequest); - - // Alter input SUA object - // send model - standardSuaObject.model = 'Suface Duo'; - // send mobile = 1 - standardSuaObject.mobile = 1; - - // make browsers not an array - standardSuaObject.browsers = 'My Browser'; - - // make platform not have version - delete standardSuaObject.platform.version; - - // delete architecture - delete standardSuaObject.architecture; - - // add SUA to bid - bidRequestSua.bids[0].ortb2 = { device: { sua: standardSuaObject } }; - - // Build Fastlane request - const [request] = spec.buildRequests(bidRequestSua.bids, bidRequestSua); - const data = new URLSearchParams(request.data); - - // should show new names - expect(data.get('m_ch_model')).to.equal('Suface Duo'); - expect(data.get('m_ch_mobile')).to.equal('?1'); - - // should still send platform - expect(data.get('m_ch_platform')).to.equal('macOS'); - - // platform version not sent - expect(data.get('m_ch_platform_ver')).to.be.null; - - // both ua and full_ver not sent because browsers not array - expect(data.get('m_ch_ua')).to.be.null; - expect(data.get('m_ch_full_ver')).to.be.null; - - // arch not sent - expect(data.get('m_ch_arch')).to.be.null; - }); - it('should not send high entropy if not present when it is low entropy client hints', function () { - const bidRequestSua = utils.deepClone(bidderRequest); - bidRequestSua.bids[0].ortb2 = { device: { sua: { - 'source': 1, - 'platform': { - 'brand': 'macOS' - }, - 'browsers': [ - { - 'brand': 'Not A(Brand', - 'version': [ - '8' - ] - }, - { - 'brand': 'Chromium', - 'version': [ - '132' - ] - }, - { - 'brand': 'Google Chrome', - 'version': [ - '132' - ] - } - ], - 'mobile': 0 - } } }; - - // How should fastlane query be constructed with default SUA - const expectedValues = { - m_ch_ua: `"Not A(Brand"|v="8","Chromium"|v="132","Google Chrome"|v="132"`, - m_ch_mobile: '?0', - m_ch_platform: 'macOS', - } - - // Build Fastlane call - const [request] = spec.buildRequests(bidRequestSua.bids, bidRequestSua); - const data = new URLSearchParams(request.data); - - // Loop through expected values and if they do not match push an error - const errors = Object.entries(expectedValues).reduce((accum, [key, val]) => { - if (data.get(key) !== val) accum.push(`${key} - expect: ${val} - got: ${data[key]}`) - return accum; - }, []); - - // should be no errors - expect(errors).to.deep.equal([]); - - // make sure high entropy keys are not present - const highEntropyHints = ['m_ch_full_ver', 'm_ch_arch', 'm_ch_bitness', 'm_ch_platform_ver']; - highEntropyHints.forEach((hint) => { expect(data.get(hint)).to.be.null; }); - }); - it('should ignore invalid browser hints (missing version)', function () { - const bidRequestSua = utils.deepClone(bidderRequest); - bidRequestSua.bids[0].ortb2 = { device: { sua: { - 'browsers': [ - { - 'brand': 'Not A(Brand', - // 'version': ['8'], // missing version - }, - ], - } } }; - - // How should fastlane query be constructed with default SUA - const expectedValues = { - m_ch_ua: `"Not A(Brand"|v="undefined"`, - } - - // Build Fastlane call - const [request] = spec.buildRequests(bidRequestSua.bids, bidRequestSua); - const data = new URLSearchParams(request.data); - - // Loop through expected values and if they do not match push an error - const errors = Object.entries(expectedValues).reduce((accum, [key, val]) => { - if (data.get(key) !== val) accum.push(`${key} - expect: ${val} - got: ${data[key]}`) - return accum; - }, []); - - // should be no errors - expect(errors).to.deep.equal([]); - - // make sure high entropy keys are not present - const highEntropyHints = ['m_ch_full_ver']; - highEntropyHints.forEach((hint) => { expect(data.get(hint)).to.be.null; }); - }); - }); - }); - - if (FEATURES.VIDEO) { - describe('for video requests', function () { - it('should make a well-formed video request', async function () { - const bidderRequest = createVideoBidderRequest(); - - sandbox.stub(Date, 'now').callsFake(() => - bidderRequest.auctionStart + 100 - ); - - const [request] = spec.buildRequests(bidderRequest.bids, await addFPDToBidderRequest(bidderRequest)); - const post = request.data; - - expect(post).to.have.property('imp'); - // .with.length.of(1); - const imp = post.imp[0]; - expect(imp.id).to.equal(bidderRequest.bids[0].adUnitCode); - expect(imp.exp).to.equal(undefined); // now undefined - expect(imp.video.w).to.equal(640); - expect(imp.video.h).to.equal(480); - expect(imp.video.pos).to.equal(1); - expect(imp.video.minduration).to.equal(15); - expect(imp.video.maxduration).to.equal(30); - expect(imp.video.startdelay).to.equal(0); - expect(imp.video.skip).to.equal(1); - expect(imp.video.skipafter).to.equal(15); - expect(imp.ext.prebid.bidder.rubicon.video.playerWidth).to.equal(640); - expect(imp.ext.prebid.bidder.rubicon.video.playerHeight).to.equal(480); - expect(imp.ext.prebid.bidder.rubicon.video.size_id).to.equal(201); - expect(imp.ext.prebid.bidder.rubicon.video.language).to.equal('en'); - // Also want it to be in post.site.content.language - expect(imp.ext.prebid.bidder.rubicon.video.skip).to.equal(1); - expect(imp.ext.prebid.bidder.rubicon.video.skipafter).to.equal(15); - expect(post.ext.prebid.auctiontimestamp).to.equal(1472239426000); - // should contain version - expect(post.ext.prebid.channel).to.deep.equal({name: 'pbjs', version: getGlobal().version}); - expect(post.user.ext.consent).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A=='); - // EIDs should exist - expect(post.user.ext).to.have.property('eids').that.is.an('array'); - // LiveIntent should exist - expect(post.user.ext.eids[0].source).to.equal('liveintent.com'); - expect(post.user.ext.eids[0].uids[0].id).to.equal('0000-1111-2222-3333'); - expect(post.user.ext.eids[0].uids[0].atype).to.equal(3); - expect(post.user.ext.eids[0]).to.have.property('ext').that.is.an('object'); - expect(post.user.ext.eids[0].ext).to.have.property('segments').that.is.an('array'); - expect(post.user.ext.eids[0].ext.segments[0]).to.equal('segA'); - expect(post.user.ext.eids[0].ext.segments[1]).to.equal('segB'); - // LiveRamp should exist - expect(post.user.ext.eids[1].source).to.equal('liveramp.com'); - expect(post.user.ext.eids[1].uids[0].id).to.equal('1111-2222-3333-4444'); - expect(post.user.ext.eids[1].uids[0].atype).to.equal(3); - // UnifiedId should exist - expect(post.user.ext.eids[2].source).to.equal('adserver.org'); - expect(post.user.ext.eids[2].uids[0].atype).to.equal(1); - expect(post.user.ext.eids[2].uids[0].id).to.equal('3000'); - // PubCommonId should exist - expect(post.user.ext.eids[3].source).to.equal('pubcid.org'); - expect(post.user.ext.eids[3].uids[0].atype).to.equal(1); - expect(post.user.ext.eids[3].uids[0].id).to.equal('4000'); - // example should exist - expect(post.user.ext.eids[4].source).to.equal('example.com'); - expect(post.user.ext.eids[4].uids[0].id).to.equal('333333'); - // id-partner.com - expect(post.user.ext.eids[5].source).to.equal('id-partner.com'); - expect(post.user.ext.eids[5].uids[0].id).to.equal('4444444'); - // CriteoId should exist - expect(post.user.ext.eids[6].source).to.equal('criteo.com'); - expect(post.user.ext.eids[6].uids[0].id).to.equal('1111'); - expect(post.user.ext.eids[6].uids[0].atype).to.equal(1); - - expect(post.regs.ext.gdpr).to.equal(1); - expect(post.regs.ext.us_privacy).to.equal('1NYN'); - expect(post).to.have.property('ext').that.is.an('object'); - expect(post.ext.prebid.targeting.includewinners).to.equal(true); - expect(post.ext.prebid).to.have.property('cache').that.is.an('object'); - expect(post.ext.prebid.cache).to.have.property('vastxml').that.is.an('object'); - expect(post.ext.prebid.cache.vastxml).to.have.property('returnCreative').that.is.an('boolean'); - expect(post.ext.prebid.cache.vastxml.returnCreative).to.equal(false); - expect(post.ext.prebid.bidders.rubicon.integration).to.equal(PBS_INTEGRATION); - }); - - describe('ortb2imp sent to video bids', function () { - beforeEach(function () { - // initialize - if (bidderRequest.bids[0].hasOwnProperty('ortb2Imp')) { - delete bidderRequest.bids[0].ortb2Imp; - } - }); - - it('should add ortb values to video requests', function () { - const bidderRequest = createVideoBidderRequest(); - - sandbox.stub(Date, 'now').callsFake(() => - bidderRequest.auctionStart + 100 - ); - - bidderRequest.bids[0].ortb2Imp = { - ext: { - gpid: '/test/gpid', - data: { - pbadslot: '/test/pbadslot' - }, - prebid: { - storedauctionresponse: { - id: 'sample_video_response' - } - } - } - } - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const post = request.data; - - expect(post).to.have.property('imp'); - // .with.length.of(1); - const imp = post.imp[0]; - expect(imp.ext.gpid).to.equal('/test/gpid'); - expect(imp.ext.data.pbadslot).to.equal('/test/pbadslot'); - expect(imp.ext.prebid.storedauctionresponse.id).to.equal('sample_video_response'); - }); - }); - - it('should correctly set bidfloor on imp when getfloor in scope', function () { - const bidderRequest = createVideoBidderRequest(); - // default getFloor response is empty object so should not break and not send hard_floor - bidderRequest.bids[0].getFloor = () => getFloorResponse; - sinon.spy(bidderRequest.bids[0], 'getFloor'); - - sandbox.stub(Date, 'now').callsFake(() => - bidderRequest.auctionStart + 100 - ); - - let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - - // make sure banner bid called with right stuff - expect( - bidderRequest.bids[0].getFloor.calledWith({ - currency: 'USD', - mediaType: '*', - size: '*' - }) - ).to.be.true; - - // not an object should work and not send - expect(request.data.imp[0].bidfloor).to.be.undefined; - - // make it respond with a non USD floor should not send it - getFloorResponse = {currency: 'EUR', floor: 1.0}; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.data.imp[0].bidfloor).to.be.undefined; - - // make it respond with a non USD floor should not send it - getFloorResponse = {currency: 'EUR'}; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.data.imp[0].bidfloor).to.be.undefined; - - // make it respond with USD floor and string floor - getFloorResponse = {currency: 'USD', floor: '1.23'}; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.data.imp[0].bidfloor).to.equal(1.23); - - // make it respond with USD floor and num floor - getFloorResponse = {currency: 'USD', floor: 1.23}; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.data.imp[0].bidfloor).to.equal(1.23); - }); - - it('should continue with auction if getFloor throws error', function () { - const bidderRequest = createVideoBidderRequest(); - // default getFloor response is empty object so should not break and not send hard_floor - bidderRequest.bids[0].getFloor = () => { - throw new Error('An exception!'); - }; - sandbox.stub(Date, 'now').callsFake(() => - bidderRequest.auctionStart + 100 - ); - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - - // should have an imp - expect(request.data.imp).to.exist.and.to.be.a('array'); - expect(request.data.imp).to.have.lengthOf(1); - - // should be NO bidFloor - expect(request.data.imp[0].bidfloor).to.be.undefined; - expect(request.data.imp[0].bidfloorcur).to.be.undefined; - }); - - it('should add alias name to PBS Request', function () { - const bidderRequest = createVideoBidderRequest(); - adapterManager.aliasRegistry['superRubicon'] = 'rubicon'; - bidderRequest.bidderCode = 'superRubicon'; - bidderRequest.bids[0].bidder = 'superRubicon'; - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - - // should have the aliases object sent to PBS - expect(request.data.ext.prebid).to.haveOwnProperty('aliases'); - expect(request.data.ext.prebid.aliases).to.deep.equal({superRubicon: 'rubicon'}); - - // should have the imp ext bidder params be under the alias name not rubicon superRubicon - expect(request.data.imp[0].ext.prebid.bidder).to.have.property('superRubicon').that.is.an('object'); - expect(request.data.imp[0].ext.prebid.bidder).to.not.haveOwnProperty('rubicon'); - }); - - it('should add floors flag correctly to PBS Request', function () { - const bidderRequest = createVideoBidderRequest(); - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - - // should not pass if undefined - expect(request.data.ext.prebid.floors).to.be.undefined; - - // should pass it as false - bidderRequest.bids[0].floorData = { - skipped: false, - location: 'fetch', - } - const [newRequest] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(newRequest.data.ext.prebid.floors).to.deep.equal({ enabled: false }); - }); - - it('should add multibid configuration to PBS Request', function () { - const bidderRequest = createVideoBidderRequest(); - - const multibid = [{ - bidder: 'bidderA', - maxBids: 2 - }, { - bidder: 'bidderB', - maxBids: 2 - }]; - const expected = [{ - bidder: 'bidderA', - maxbids: 2 - }, { - bidder: 'bidderB', - maxbids: 2 - }]; - - config.setConfig({multibid: multibid}); - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - - // should have the aliases object sent to PBS - expect(request.data.ext.prebid).to.haveOwnProperty('multibid'); - expect(request.data.ext.prebid.multibid).to.deep.equal(expected); - }); - - it('should pass client analytics to PBS endpoint if all modules included', function () { - const bidderRequest = createVideoBidderRequest(); - getGlobal().installedModules = []; - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const payload = request.data; - - expect(payload.ext.prebid.analytics).to.not.be.undefined; - expect(payload.ext.prebid.analytics).to.deep.equal({'rubicon': {'client-analytics': true}}); - }); - - it('should pass client analytics to PBS endpoint if rubicon analytics adapter is included', function () { - const bidderRequest = createVideoBidderRequest(); - getGlobal().installedModules = ['rubiconBidAdapter', 'rubiconAnalyticsAdapter']; - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const payload = request.data; - - expect(payload.ext.prebid.analytics).to.not.be.undefined; - expect(payload.ext.prebid.analytics).to.deep.equal({'rubicon': {'client-analytics': true}}); - }); - - it('should not pass client analytics to PBS endpoint if rubicon analytics adapter is not included', function () { - const bidderRequest = createVideoBidderRequest(); - getGlobal().installedModules = ['rubiconBidAdapter']; - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const payload = request.data; - - expect(payload.ext.prebid.analytics).to.be.undefined; - }); - - it('should not send video exp at all if not set in s2sConfig config', function () { - const bidderRequest = createVideoBidderRequest(); - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const post = request.data; - - // should exp set to the right value according to config - const imp = post.imp[0]; - // bidderFactory stringifies request body before sending so removes undefined attributes: - expect(imp.exp).to.equal(undefined); - }); - - it('should send tmax as the bidderRequest timeout value', function () { - const bidderRequest = createVideoBidderRequest(); - bidderRequest.timeout = 3333; - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - const post = request.data; - expect(post.tmax).to.equal(3333); - }); - - it('should send correct bidfloor to PBS', function () { - const bidderRequest = createVideoBidderRequest(); - - bidderRequest.bids[0].params.floor = 0.1; - let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.data.imp[0].bidfloor).to.equal(0.1); - - bidderRequest.bids[0].params.floor = 5.5; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.data.imp[0].bidfloor).to.equal(5.5); - - bidderRequest.bids[0].params.floor = '1.7'; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.data.imp[0].bidfloor).to.equal(1.7); - - bidderRequest.bids[0].params.floor = 0; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.data.imp[0].bidfloor).to.equal(0); - - bidderRequest.bids[0].params.floor = undefined; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.data.imp[0]).to.not.haveOwnProperty('bidfloor'); - - bidderRequest.bids[0].params.floor = null; - [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.data.imp[0]).to.not.haveOwnProperty('bidfloor'); - }); - - it('should send request with proper ad position', function () { - const bidderRequest = createVideoBidderRequest(); - let positionBidderRequest = utils.deepClone(bidderRequest); - positionBidderRequest.bids[0].mediaTypes.video.pos = 1; - let [request] = spec.buildRequests(positionBidderRequest.bids, positionBidderRequest); - expect(request.data.imp[0].video.pos).to.equal(1); - - positionBidderRequest = utils.deepClone(bidderRequest); - positionBidderRequest.bids[0].params.position = undefined; - positionBidderRequest.bids[0].mediaTypes.video.pos = undefined; - [request] = spec.buildRequests(positionBidderRequest.bids, positionBidderRequest); - expect(request.data.imp[0].video.pos).to.equal(undefined); - - positionBidderRequest = utils.deepClone(bidderRequest); - positionBidderRequest.bids[0].params.position = 'atf' - positionBidderRequest.bids[0].mediaTypes.video.pos = undefined; - [request] = spec.buildRequests(positionBidderRequest.bids, positionBidderRequest); - expect(request.data.imp[0].video.pos).to.equal(1); - - positionBidderRequest = utils.deepClone(bidderRequest); - positionBidderRequest.bids[0].params.position = 'btf'; - positionBidderRequest.bids[0].mediaTypes.video.pos = undefined; - [request] = spec.buildRequests(positionBidderRequest.bids, positionBidderRequest); - expect(request.data.imp[0].video.pos).to.equal(3); - - positionBidderRequest = utils.deepClone(bidderRequest); - positionBidderRequest.bids[0].params.position = 'foobar'; - positionBidderRequest.bids[0].mediaTypes.video.pos = undefined; - [request] = spec.buildRequests(positionBidderRequest.bids, positionBidderRequest); - expect(request.data.imp[0].video.pos).to.equal(undefined); - }); - - it('should properly enforce video.context to be either instream or outstream', function () { - const bid = bidderRequest.bids[0]; - bid.mediaTypes = { - video: { - context: 'instream', - mimes: ['video/mp4', 'video/x-ms-wmv'], - protocols: [2, 5], - maxduration: 30, - linearity: 1, - api: [2] - } - } - bid.params.video = {}; - - sandbox.stub(Date, 'now').callsFake(() => - bidderRequest.auctionStart + 100 - ); - - const bidRequestCopy = utils.deepClone(bidderRequest.bids[0]); - expect(spec.isBidRequestValid(bidRequestCopy)).to.equal(true); - - // change context to outstream, still true - bidRequestCopy.mediaTypes.video.context = 'outstream'; - expect(spec.isBidRequestValid(bidRequestCopy)).to.equal(true); - - // change context to random, false now - bidRequestCopy.mediaTypes.video.context = 'random'; - expect(spec.isBidRequestValid(bidRequestCopy)).to.equal(false); - - // change context to undefined, still false - bidRequestCopy.mediaTypes.video.context = undefined; - expect(spec.isBidRequestValid(bidRequestCopy)).to.equal(false); - - // remove context, still false - delete bidRequestCopy.mediaTypes.video.context; - expect(spec.isBidRequestValid(bidRequestCopy)).to.equal(false); - }); - - it('should enforce the new required mediaTypes.video params', function () { - let bidderRequest = createVideoBidderRequest(); - - sandbox.stub(Date, 'now').callsFake(() => - bidderRequest.auctionStart + 100 - ); - - expect(spec.isBidRequestValid(bidderRequest.bids[0])).to.equal(true); - - // change mimes to a non array, no good - bidderRequest = createVideoBidderRequest(); - bidderRequest.bids[0].mediaTypes.video.mimes = 'video/mp4'; - expect(spec.isBidRequestValid(bidderRequest.bids[0])).to.equal(false); - - // delete mimes, no good - bidderRequest = createVideoBidderRequest(); - delete bidderRequest.bids[0].mediaTypes.video.mimes; - expect(spec.isBidRequestValid(bidderRequest.bids[0])).to.equal(false); - - // change protocols to an int not array of ints, no good - bidderRequest = createVideoBidderRequest(); - bidderRequest.bids[0].mediaTypes.video.protocols = 1; - expect(spec.isBidRequestValid(bidderRequest.bids[0])).to.equal(false); - - // delete protocols, no good - bidderRequest = createVideoBidderRequest(); - delete bidderRequest.bids[0].mediaTypes.video.protocols; - expect(spec.isBidRequestValid(bidderRequest.bids[0])).to.equal(false); - - // change linearity to an string, no good - bidderRequest = createVideoBidderRequest(); - bidderRequest.bids[0].mediaTypes.video.linearity = 'string'; - expect(spec.isBidRequestValid(bidderRequest.bids[0])).to.equal(false); - - // delete linearity, no good - bidderRequest = createVideoBidderRequest(); - delete bidderRequest.bids[0].mediaTypes.video.linearity; - expect(spec.isBidRequestValid(bidderRequest.bids[0])).to.equal(false); - }); - - it('bid request is valid when video context is outstream', function () { - const bidderRequest = createVideoBidderRequestOutstream(); - sandbox.stub(Date, 'now').callsFake(() => - bidderRequest.auctionStart + 100 - ); - - const bidRequestCopy = utils.deepClone(bidderRequest); - - const [request] = spec.buildRequests(bidRequestCopy.bids, bidRequestCopy); - expect(spec.isBidRequestValid(bidderRequest.bids[0])).to.equal(true); - expect(request.data.imp[0].ext.prebid.bidder.rubicon.video.size_id).to.equal(203); - }); - - it('should send banner request when outstream or instream video included but no rubicon video obect is present', function () { - // add banner and video mediaTypes - bidderRequest.mediaTypes = { - banner: { - sizes: [[300, 250]] - }, - video: { - context: 'outstream' - } - }; - // no video object in rubicon params, so we should see one call made for banner - - sandbox.stub(Date, 'now').callsFake(() => - bidderRequest.auctionStart + 100 - ); - - let requests = spec.buildRequests(bidderRequest.bids, bidderRequest); - - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal('https://fastlane.rubiconproject.com/a/api/fastlane.json'); - - bidderRequest.mediaTypes.video.context = 'instream'; - - requests = spec.buildRequests(bidderRequest.bids, bidderRequest); - - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal('https://fastlane.rubiconproject.com/a/api/fastlane.json'); - }); - - it('should send request as banner when invalid video bid in multiple mediaType bidRequest', function () { - removeVideoParamFromBidderRequest(bidderRequest); - - const bid = bidderRequest.bids[0]; - bid.mediaTypes.banner = { - sizes: [[300, 250]] - }; - - sandbox.stub(Date, 'now').callsFake(() => - bidderRequest.auctionStart + 100 - ); - - const bidRequestCopy = utils.deepClone(bidderRequest); - - const requests = spec.buildRequests(bidRequestCopy.bids, bidRequestCopy); - expect(requests.length).to.equal(1); - expect(requests[0].url).to.equal('https://fastlane.rubiconproject.com/a/api/fastlane.json'); - }); - - it('should include coppa flag in video bid request', async () => { - const bidderRequest = createVideoBidderRequest(); - - sandbox.stub(Date, 'now').callsFake(() => - bidderRequest.auctionStart + 100 - ); - - sandbox.stub(config, 'getConfig').callsFake(key => { - const config = { - 'coppa': true - }; - return config[key]; - }); - const [request] = spec.buildRequests(bidderRequest.bids, await addFPDToBidderRequest(bidderRequest)); - expect(request.data.regs.coppa).to.equal(1); - }); - - it('should include first party data', () => { - const bidderRequest = createVideoBidderRequest(); - - const site = { - ext: { - data: { - page: 'home' - } - }, - content: { - data: [{foo: 'bar'}] - }, - keywords: 'e,f', - rating: '4-star', - data: [{foo: 'bar'}] - }; - const user = { - ext: { - data: { - age: 31 - } - }, - keywords: 'd', - gender: 'M', - yob: '1984', - geo: {country: 'ca'}, - data: [{foo: 'bar'}] - }; - - const ortb2 = { - site, - user - }; - - const [request] = spec.buildRequests(bidderRequest.bids.map((b) => ({...b, ortb2})), bidderRequest); - - const expected = { - site: Object.assign({}, site, {keywords: bidderRequest.bids[0].params.keywords.join(',')}), - user: Object.assign({}, user), - siteData: Object.assign({}, site.ext.data, bidderRequest.bids[0].params.inventory), - userData: Object.assign({}, user.ext.data, bidderRequest.bids[0].params.visitor), - }; - - delete request.data.site.page; - delete request.data.site.content.language; - - expect(request.data.site.keywords).to.deep.equal('a,b,c'); - expect(request.data.user.keywords).to.deep.equal('d'); - expect(request.data.site.ext.data).to.deep.equal(expected.siteData); - expect(request.data.user.ext.data).to.deep.equal(expected.userData); - }); - - it('should include pbadslot in bid request', function () { - const bidderRequest = createVideoBidderRequest(); - bidderRequest.bids[0].ortb2Imp = { - ext: { - data: { - pbadslot: '1234567890' - } - } - } - - sandbox.stub(Date, 'now').callsFake(() => - bidderRequest.auctionStart + 100 - ); - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.data.imp[0].ext.data.pbadslot).to.equal('1234567890'); - }); - - it('should NOT include storedrequests in pbs payload', function () { - const bidderRequest = createVideoBidderRequest(); - bidderRequest.bids[0].ortb2 = { - ext: { - prebid: { - storedrequest: 'no-send-top-level-sr' - } - } - } - - bidderRequest.bids[0].ortb2Imp = { - ext: { - prebid: { - storedrequest: 'no-send-imp-sr' - } - } - } - - sandbox.stub(Date, 'now').callsFake(() => - bidderRequest.auctionStart + 100 - ); - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.data.ext.prebid.storedrequest).to.be.undefined; - expect(request.data.imp[0].ext.prebid.storedrequest).to.be.undefined; - }); - - it('should include GAM ad unit in bid request', function () { - const bidderRequest = createVideoBidderRequest(); - bidderRequest.bids[0].ortb2Imp = { - ext: { - data: { - adserver: { - adslot: '1234567890', - name: 'adServerName1' - } - } - } - }; - - sandbox.stub(Date, 'now').callsFake(() => - bidderRequest.auctionStart + 100 - ); - - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.data.imp[0].ext.data.adserver.adslot).to.equal('1234567890'); - expect(request.data.imp[0].ext.data.adserver.name).to.equal('adServerName1'); - }); - - it('should use the integration type provided in the config instead of the default', () => { - const bidderRequest = createVideoBidderRequest(); - config.setConfig({rubicon: {int_type: 'testType'}}); - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request.data.ext.prebid.bidders.rubicon.integration).to.equal('testType'); - }); - - it('should pass the user.id provided in the config', async function () { - config.setConfig({user: {id: '123'}}); - const bidderRequest = createVideoBidderRequest(); - - sandbox.stub(Date, 'now').callsFake(() => - bidderRequest.auctionStart + 100 - ); - - const [request] = spec.buildRequests(bidderRequest.bids, await addFPDToBidderRequest(bidderRequest)); - const post = request.data; - - expect(post).to.have.property('imp') - // .with.length.of(1); - const imp = post.imp[0]; - expect(imp.id).to.equal(bidderRequest.bids[0].adUnitCode); - expect(imp.exp).to.equal(undefined); - expect(imp.video.w).to.equal(640); - expect(imp.video.h).to.equal(480); - expect(imp.video.pos).to.equal(1); - expect(imp.video.minduration).to.equal(15); - expect(imp.video.maxduration).to.equal(30); - expect(imp.video.startdelay).to.equal(0); - expect(imp.video.skip).to.equal(1); - expect(imp.video.skipafter).to.equal(15); - expect(imp.ext.prebid.bidder.rubicon.video.playerWidth).to.equal(640); - expect(imp.ext.prebid.bidder.rubicon.video.playerHeight).to.equal(480); - expect(imp.ext.prebid.bidder.rubicon.video.language).to.equal('en'); - - // Also want it to be in post.site.content.language - expect(post.site.content.language).to.equal('en'); - expect(post.ext.prebid.auctiontimestamp).to.equal(1472239426000); - expect(post.user.ext.consent).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A=='); - - // Config user.id - expect(post.user.id).to.equal('123'); - - expect(post.regs.ext.gdpr).to.equal(1); - expect(post.regs.ext.us_privacy).to.equal('1NYN'); - expect(post).to.have.property('ext').that.is.an('object'); - expect(post.ext.prebid.targeting.includewinners).to.equal(true); - expect(post.ext.prebid).to.have.property('cache').that.is.an('object'); - expect(post.ext.prebid.cache).to.have.property('vastxml').that.is.an('object'); - expect(post.ext.prebid.cache.vastxml).to.have.property('returnCreative').that.is.an('boolean'); - expect(post.ext.prebid.cache.vastxml.returnCreative).to.equal(false); - expect(post.ext.prebid.bidders.rubicon.integration).to.equal(PBS_INTEGRATION); - }) - }); - } - - describe('combineSlotUrlParams', function () { - it('should combine an array of slot url params', function () { - expect(spec.combineSlotUrlParams([])).to.deep.equal({}); - - expect(spec.combineSlotUrlParams([{p1: 'foo', p2: 'test', p3: ''}])).to.deep.equal({ - p1: 'foo', - p2: 'test', - p3: '' - }); - - expect(spec.combineSlotUrlParams([{}, {p1: 'foo', p2: 'test'}])).to.deep.equal({p1: ';foo', p2: ';test'}); - - expect(spec.combineSlotUrlParams([{}, {}, {p1: 'foo', p2: ''}, {}])).to.deep.equal({p1: ';;foo;', p2: ''}); - - expect(spec.combineSlotUrlParams([{}, {p1: 'foo'}, {p1: ''}])).to.deep.equal({p1: ';foo;'}); - - expect(spec.combineSlotUrlParams([ - {p1: 'foo', p2: 'test'}, - {p2: 'test', p3: 'bar'}, - {p1: 'bar', p2: 'test', p4: 'bar'} - ])).to.deep.equal({p1: 'foo;;bar', p2: 'test', p3: ';bar;', p4: ';;bar'}); - - expect(spec.combineSlotUrlParams([ - {p1: 'foo', p2: 'test', p3: 'baz'}, - {p1: 'foo', p2: 'bar'}, - {p2: 'test'} - ])).to.deep.equal({p1: 'foo;foo;', p2: 'test;bar;test', p3: 'baz;;'}); - }); - }); - - describe('createSlotParams', function () { - it('should return a valid slot params object', function () { - const localBidderRequest = Object.assign({}, bidderRequest); - const expectedQuery = { - 'account_id': '14062', - 'site_id': '70608', - 'zone_id': '335918', - 'size_id': 15, - 'alt_size_ids': '43', - 'p_pos': 'atf', - 'rp_secure': /[01]/, - 'tk_flint': INTEGRATION, - 'x_source.tid': 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', - 'p_screen_res': /\d+x\d+/, - 'tk_user_key': '12346', - 'kw': 'a,b,c', - 'tg_v.ucat': 'new', - 'tg_v.lastsearch': 'iphone', - 'tg_v.likes': 'sports,video games', - 'tg_i.rating': '5-star', - 'tg_i.prodtype': 'tech,mobile', - 'tg_fl.eid': 'div-1', - 'rf': 'localhost' - }; - - const slotParams = spec.createSlotParams(bidderRequest.bids[0], localBidderRequest); - - // test that all values above are both present and correct - Object.keys(expectedQuery).forEach(key => { - const value = expectedQuery[key]; - if (value instanceof RegExp) { - expect(slotParams[key]).to.match(value); - } else { - expect(slotParams[key]).to.equal(value); - } - }); - }); - - it('should not fail if keywords param is not an array', function () { - bidderRequest.bids[0].params.keywords = 'a,b,c'; - const slotParams = spec.createSlotParams(bidderRequest.bids[0], bidderRequest); - expect(slotParams.kw).to.equal('a,b,c'); - }); - - it('should pass along o_ae param when fledge is enabled', () => { - const localBidRequest = Object.assign({}, bidderRequest.bids[0]); - localBidRequest.ortb2Imp.ext.ae = true; - - const slotParams = spec.createSlotParams(localBidRequest, bidderRequest); - - expect(slotParams['o_ae']).to.equal(1) - }); - - it('should pass along desired segtaxes, but not non-desired ones', () => { - const localBidderRequest = Object.assign({}, bidderRequest); - localBidderRequest.refererInfo = {domain: 'bob'}; - config.setConfig({ - rubicon: { - sendUserSegtax: [9], - sendSiteSegtax: [10] - } - }); - localBidderRequest.ortb2.user = { - data: [{ - ext: { - segtax: '404' - }, - segment: [{id: 5}, {id: 6}] - }, { - ext: { - segtax: '508' - }, - segment: [{id: 5}, {id: 2}] - }, { - ext: { - segtax: '9' - }, - segment: [{id: 1}, {id: 2}] - }] - } - localBidderRequest.ortb2.site = { - content: { - data: [{ - ext: { - segtax: '10' - }, - segment: [{id: 2}, {id: 3}] - }, { - ext: { - segtax: '507' - }, - segment: [{id: 3}, {id: 4}] - }] - } - } - const slotParams = spec.createSlotParams(bidderRequest.bids[0], localBidderRequest); - expect(slotParams['tg_i.tax507']).is.equal('3,4'); - expect(slotParams['tg_v.tax508']).is.equal('5,2'); - expect(slotParams['tg_v.tax9']).is.equal('1,2'); - expect(slotParams['tg_i.tax10']).is.equal('2,3'); - expect(slotParams['tg_v.tax404']).is.equal(undefined); - }); - - it('should support IAB segtax 7 in site segments', () => { - const localBidderRequest = Object.assign({}, bidderRequest); - localBidderRequest.refererInfo = {domain: 'bob'}; - config.setConfig({ - rubicon: { - sendUserSegtax: [4], - sendSiteSegtax: [1, 2, 5, 6, 7] - } - }); - localBidderRequest.ortb2.site = { - content: { - data: [{ - ext: { - segtax: '7' - }, - segment: [{id: 8}, {id: 9}] - }] - } - }; - const slotParams = spec.createSlotParams(bidderRequest.bids[0], localBidderRequest); - expect(slotParams['tg_i.tax7']).to.equal('8,9'); - }); - - it('should add p_site.mobile if mobile is a number in ortb2.site', function () { - // Set up a bidRequest with mobile property as a number - const localBidderRequest = Object.assign({}, bidderRequest); - localBidderRequest.bids[0].ortb2 = { - site: { - mobile: 1 // Valid mobile value (number) - } - }; - - // Call the function - const slotParams = spec.createSlotParams(localBidderRequest.bids[0], localBidderRequest); - // Check that p_site.mobile was added to the slotParams with the correct value - expect(slotParams['p_site.mobile']).to.equal(1); - }); - it('should not add p_site.mobile if mobile is not a number in ortb2.site', function () { - // Set up a bidRequest with mobile property as a string (invalid value) - const localBidderRequest = Object.assign({}, bidderRequest); - localBidderRequest.bids[0].ortb2 = { - site: { - mobile: 'not-a-number' // Invalid mobile value (string) - } - }; - - // Call the function - const slotParams = spec.createSlotParams(localBidderRequest.bids[0], localBidderRequest); - - // Check that p_site.mobile is not added to the slotParams - expect(slotParams['p_site.mobile']).to.be.undefined; - }); - }); - - describe('classifiedAsVideo', function () { - it('should return true if mediaTypes is video', function () { - const bidderRequest = createVideoBidderRequest(); - const bidClassifiedAsVideo = classifiedAsVideo(bidderRequest.bids[0]); - expect(bidClassifiedAsVideo).is.equal(true); - }); - - it('should return false if trying to use legacy mediaType with video', function () { - const bidderRequest = createVideoBidderRequest(); - delete bidderRequest.bids[0].mediaTypes; - bidderRequest.bids[0].mediaType = 'video'; - const legacyVideoTypeBidRequest = classifiedAsVideo(bidderRequest.bids[0]); - expect(legacyVideoTypeBidRequest).is.equal(false); - }); - - it('should return false if bid.mediaTypes is not equal to video', function () { - expect(classifiedAsVideo({ - mediaType: 'banner' - })).is.equal(false); - }); - - it('should return false if bid.mediaTypes is not defined', function () { - expect(classifiedAsVideo({})).is.equal(false); - }); - - it('Should return false if both banner and video mediaTypes are set and params.video is not an object', function () { - removeVideoParamFromBidderRequest(bidderRequest); - const bid = bidderRequest.bids[0]; - bid.mediaTypes.banner = {flag: true}; - expect(classifiedAsVideo(bid)).to.equal(false); - }); - it('Should return true if both banner and video mediaTypes are set and params.video is an object', function () { - removeVideoParamFromBidderRequest(bidderRequest); - const bid = bidderRequest.bids[0]; - bid.mediaTypes.banner = {flag: true}; - bid.params.video = {}; - expect(classifiedAsVideo(bid)).to.equal(true); - }); - - it('Should return true and create a params.video object if one is not already present', function () { - removeVideoParamFromBidderRequest(bidderRequest); - const bid = bidderRequest.bids[0] - expect(classifiedAsVideo(bid)).to.equal(true); - expect(bid.params.video).to.not.be.undefined; - }); - }); - - if (FEATURES.NATIVE) { - describe('when there is a native request', function () { - describe('and bidonmultiformat = undefined (false)', () => { - it('should send only one native bid to PBS endpoint', function () { - const bidReq = addNativeToBidRequest(bidderRequest); - bidReq.bids[0].params = { - video: {} - } - const [request] = spec.buildRequests(bidReq.bids, bidReq); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://prebid-server.rubiconproject.com/openrtb2/auction'); - expect(request.data.imp).to.have.nested.property('[0].native'); - }); - - it('should not break if position is set and no video MT', function () { - const bidReq = addNativeToBidRequest(bidderRequest); - delete bidReq.bids[0].mediaTypes.banner; - bidReq.bids[0].params = { - position: 'atf' - } - const [request] = spec.buildRequests(bidReq.bids, bidReq); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://prebid-server.rubiconproject.com/openrtb2/auction'); - expect(request.data.imp).to.have.nested.property('[0].native'); - }); - - describe('that contains also a banner mediaType', function () { - it('should send the banner to fastlane BUT NOT the native bid because missing params.video', function() { - const bidReq = addNativeToBidRequest(bidderRequest); - bidReq.bids[0].mediaTypes.banner = { - sizes: [[300, 250]] - } - const [request] = spec.buildRequests(bidReq.bids, bidReq); - expect(request.method).to.equal('GET'); - expect(request.url).to.include('https://fastlane.rubiconproject.com/a/api/fastlane.json'); - }); - }); - describe('with another banner request', () => { - it('should send the native bid to PBS and the banner to fastlane', function() { - const bidReq = addNativeToBidRequest(bidderRequest); - bidReq.bids[0].params = { video: {} }; - // add second bidRqeuest - bidReq.bids.push({ - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - params: bidReq.bids[0].params - }) - const [request1, request2] = spec.buildRequests(bidReq.bids, bidReq); - expect(request1.method).to.equal('POST'); - expect(request1.url).to.equal('https://prebid-server.rubiconproject.com/openrtb2/auction'); - expect(request1.data.imp).to.have.nested.property('[0].native'); - expect(request2.method).to.equal('GET'); - expect(request2.url).to.include('https://fastlane.rubiconproject.com/a/api/fastlane.json'); - }); - }); - }); - - describe('with bidonmultiformat === true', () => { - it('should send two requests, to PBS with 2 imps', () => { - const bidReq = addNativeToBidRequest(bidderRequest); - // add second mediaType - bidReq.bids[0].mediaTypes = { - ...bidReq.bids[0].mediaTypes, - banner: { - sizes: [[300, 250]] - } - }; - bidReq.bids[0].params.bidonmultiformat = true; - const [pbsRequest, fastlanteRequest] = spec.buildRequests(bidReq.bids, bidReq); - expect(pbsRequest.method).to.equal('POST'); - expect(pbsRequest.url).to.equal('https://prebid-server.rubiconproject.com/openrtb2/auction'); - expect(pbsRequest.data.imp).to.have.nested.property('[0].native'); - expect(fastlanteRequest.url).to.equal('https://fastlane.rubiconproject.com/a/api/fastlane.json'); - }); - - it('should include multiformat data in the pbs request', () => { - const bidReq = addNativeToBidRequest(bidderRequest); - // add second mediaType - bidReq.bids[0].mediaTypes = { - ...bidReq.bids[0].mediaTypes, - banner: { - sizes: [[300, 250]] - } - }; - bidReq.bids[0].params.bidonmultiformat = true; - const [pbsRequest, fastlanteRequest] = spec.buildRequests(bidReq.bids, bidReq); - expect(pbsRequest.data.imp[0].ext.prebid.bidder.rubicon.formats).to.deep.equal(['native', 'banner']); - }); - - it('should include multiformat data in the fastlane request', () => { - const bidReq = addNativeToBidRequest(bidderRequest); - // add second mediaType - bidReq.bids[0].mediaTypes = { - ...bidReq.bids[0].mediaTypes, - banner: { - sizes: [[300, 250]] - } - }; - bidReq.bids[0].params.bidonmultiformat = true; - const [pbsRequest, fastlanteRequest] = spec.buildRequests(bidReq.bids, bidReq); - const formatsIncluded = fastlanteRequest.data.indexOf('formats=native%2Cbanner') !== -1; - expect(formatsIncluded).to.equal(true); - }); - }); - describe('with bidonmultiformat === false', () => { - it('should send only banner request because there\'s no params.video', () => { - const bidReq = addNativeToBidRequest(bidderRequest); - // add second mediaType - bidReq.bids[0].mediaTypes = { - ...bidReq.bids[0].mediaTypes, - banner: { - sizes: [[300, 250]] - } - }; - - const [fastlanteRequest, ...others] = spec.buildRequests(bidReq.bids, bidReq); - expect(fastlanteRequest.url).to.equal('https://fastlane.rubiconproject.com/a/api/fastlane.json'); - expect(others).to.be.empty; - }); - - it('should not send native to PBS even if there\'s param.video', () => { - const bidReq = addNativeToBidRequest(bidderRequest); - // add second mediaType - bidReq.bids[0].mediaTypes = { - ...bidReq.bids[0].mediaTypes, - banner: { - sizes: [[300, 250]] - } - }; - // by adding this, when bidonmultiformat is false, the native request will be sent to pbs - bidReq.bids[0].params = { - video: {} - } - const [fastlaneRequest, ...other] = spec.buildRequests(bidReq.bids, bidReq); - expect(fastlaneRequest.method).to.equal('GET'); - expect(fastlaneRequest.url).to.equal('https://fastlane.rubiconproject.com/a/api/fastlane.json'); - expect(other).to.be.empty; - }); - }); - - describe('with duplicate adUnitCodes', () => { - it('should increment PBS request imp[].id starting at 2', () => { - const nativeBidderRequest = addNativeToBidRequest(bidderRequest, {twin: true}); - const request = converter.toORTB({bidderRequest: nativeBidderRequest, bidRequests: nativeBidderRequest.bids}); - for (let i = 0; i < nativeBidderRequest.bids.length; i++) { - var adUnitCode = nativeBidderRequest.bids[i].adUnitCode; - if (i === 0) { - expect(request.imp[i].id).to.equal(adUnitCode); - } else { - expect(request.imp[i].id).to.equal(adUnitCode + (i + 1)); - } - } - }); - }); - }); - } - }); - - describe('interpretResponse', function () { - describe('for fastlane', function () { - it('should handle a success response and sort by cpm', function () { - const response = { - 'status': 'ok', - 'account_id': 14062, - 'site_id': 70608, - 'zone_id': 530022, - 'size_id': 15, - 'alt_size_ids': [ - 43 - ], - 'tracking': '', - 'inventory': {}, - 'ads': [ - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374c', - 'size_id': '15', - 'ad_id': '6', - 'adomain': ['test.com'], - 'advertiser': 7, - 'network': 8, - 'creative_id': 'crid-9', - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 0.811, - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '15_tier_all_test' - ] - } - ] - }, - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374d', - 'size_id': '43', - 'ad_id': '7', - 'adomain': ['test.com'], - 'advertiser': 7, - 'network': 8, - 'creative_id': 'crid-9', - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 0.911, - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '43_tier_all_test' - ] - } - ] - } - ] - }; - - const bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - - expect(bids).to.be.lengthOf(2); - - expect(bids[0].width).to.equal(320); - expect(bids[0].height).to.equal(50); - expect(bids[0].cpm).to.equal(0.911); - expect(bids[0].ttl).to.equal(360); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[0].rubicon.advertiserId).to.equal(7); - expect(bids[0].rubicon.networkId).to.equal(8); - expect(bids[0].creativeId).to.equal('crid-9'); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].meta.mediaType).to.equal('banner'); - expect(String(bids[0].meta.advertiserDomains)).to.equal('test.com'); - expect(bids[0].ad).to.contain(`alert('foo')`) - .and.to.contain(``) - .and.to.contain(`
`); - expect(bids[0].rubiconTargeting.rpfl_elemid).to.equal('/19968336/header-bid-tag-0'); - expect(bids[0].rubiconTargeting.rpfl_14062).to.equal('43_tier_all_test'); - - expect(bids[1].width).to.equal(300); - expect(bids[1].height).to.equal(250); - expect(bids[1].cpm).to.equal(0.811); - expect(bids[1].ttl).to.equal(360); - expect(bids[1].netRevenue).to.equal(true); - expect(bids[1].rubicon.advertiserId).to.equal(7); - expect(bids[1].rubicon.networkId).to.equal(8); - expect(bids[1].creativeId).to.equal('crid-9'); - expect(bids[1].currency).to.equal('USD'); - expect(bids[1].ad).to.contain(`alert('foo')`) - .and.to.contain(``) - .and.to.contain(`
`); - expect(bids[1].rubiconTargeting.rpfl_elemid).to.equal('/19968336/header-bid-tag-0'); - expect(bids[1].rubiconTargeting.rpfl_14062).to.equal('15_tier_all_test'); - }); - - it('should pass netRevenue correctly if set in setConfig', function () { - const response = { - 'status': 'ok', - 'account_id': 14062, - 'site_id': 70608, - 'zone_id': 530022, - 'size_id': 15, - 'alt_size_ids': [ - 43 - ], - 'tracking': '', - 'inventory': {}, - 'ads': [ - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374c', - 'size_id': '15', - 'ad_id': '6', - 'advertiser': 7, - 'network': 8, - 'creative_id': 'crid-9', - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 0.811, - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '15_tier_all_test' - ] - } - ] - }, - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374d', - 'size_id': '43', - 'ad_id': '7', - 'advertiser': 7, - 'network': 8, - 'creative_id': 'crid-9', - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 0.911, - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '43_tier_all_test' - ] - } - ] - } - ] - }; - - // Set to false => false - config.setConfig({ - rubicon: { - netRevenue: false - } - }); - let bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - expect(bids).to.be.lengthOf(2); - expect(bids[0].netRevenue).to.equal(false); - expect(bids[1].netRevenue).to.equal(false); - - // Set to true => true - config.setConfig({ - rubicon: { - netRevenue: true - } - }); - bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - expect(bids).to.be.lengthOf(2); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[1].netRevenue).to.equal(true); - - // Set to undefined => true - config.setConfig({ - rubicon: { - netRevenue: undefined - } - }); - bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - expect(bids).to.be.lengthOf(2); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[1].netRevenue).to.equal(true); - - // Set to string => true - config.setConfig({ - rubicon: { - netRevenue: 'someString' - } - }); - bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - expect(bids).to.be.lengthOf(2); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[1].netRevenue).to.equal(true); - - config.resetConfig(); - }); - it('should use "network-advertiser" if no creative_id', function () { - const response = { - 'status': 'ok', - 'account_id': 14062, - 'site_id': 70608, - 'zone_id': 530022, - 'size_id': 15, - 'alt_size_ids': [ - 43, 10, 2 - ], - 'tracking': '', - 'inventory': {} - }; - - response.ads = [ - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374c', - 'size_id': '15', - 'ad_id': '6', - 'advertiser': 7, - 'network': 8, - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 0.811, - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '15_tier_all_test' - ] - } - ] - } - ]; - - let bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - expect(bids[0].creativeId).to.equal('8-7'); - - response.ads = [ - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374d', - 'size_id': '43', - 'ad_id': '7', - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 0.911, - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '43_tier_all_test' - ] - } - ] - } - ]; - - bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - expect(bids[0].creativeId).to.equal('-'); - - response.ads = [ - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374d', - 'size_id': '10', - 'ad_id': '7', - 'network': 8, - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 0.911, - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '10_tier_all_test' - ] - } - ] - } - ]; - - bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - expect(bids[0].creativeId).to.equal('8-'); - - response.ads = [ - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374d', - 'size_id': '2', - 'ad_id': '7', - 'advertiser': 7, - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 0.911, - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '2_tier_all_test' - ] - } - ] - } - ]; - - bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - expect(bids[0].creativeId).to.equal('-7'); - }); - - it('should be fine with a CPM of 0', function () { - const response = { - 'status': 'ok', - 'account_id': 14062, - 'site_id': 70608, - 'zone_id': 530022, - 'size_id': 15, - 'alt_size_ids': [ - 43 - ], - 'tracking': '', - 'inventory': {}, - 'ads': [{ - 'status': 'ok', - 'cpm': 0, - 'size_id': 15 - }] - }; - - const bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - - expect(bids).to.be.lengthOf(1); - expect(bids[0].cpm).to.be.equal(0); - }); - - it('should handle DSA object from response', function() { - const response = { - 'status': 'ok', - 'account_id': 14062, - 'site_id': 70608, - 'zone_id': 530022, - 'size_id': 15, - 'alt_size_ids': [ - 43 - ], - 'tracking': '', - 'inventory': {}, - 'ads': [ - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374c', - 'size_id': '15', - 'ad_id': '6', - 'adomain': ['test.com'], - 'advertiser': 7, - 'network': 8, - 'creative_id': 'crid-9', - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 0.811, - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '15_tier_all_test' - ] - } - ], - 'dsa': { - 'behalf': 'Advertiser', - 'paid': 'Advertiser', - 'transparency': [{ - 'domain': 'dsp1domain.com', - 'dsaparams': [1, 2] - }], - 'adrender': 1 - } - }, - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374d', - 'size_id': '43', - 'ad_id': '7', - 'adomain': ['test.com'], - 'advertiser': 7, - 'network': 8, - 'creative_id': 'crid-9', - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 0.911, - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '43_tier_all_test' - ] - } - ], - 'dsa': {} - } - ] - }; - const bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - expect(bids).to.be.lengthOf(2); - expect(bids[1].meta.dsa).to.have.property('behalf'); - expect(bids[1].meta.dsa).to.have.property('paid'); - - // if we dont have dsa field in response or the dsa object is empty - expect(bids[0].meta).to.not.have.property('dsa'); - }) - - it('should create bids with matching requestIds if imp id matches', function () { - const bidRequests = [{ - 'bidder': 'rubicon', - 'params': { - 'accountId': 1001, - 'siteId': 12345, - 'zoneId': 67890, - 'floor': null - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': '404a7b28-f276-41cc-a5cf-c1d3dc5671f9', - 'sizes': [[300, 250]], - 'bidId': '557ba307cef098', - 'bidderRequestId': '46a00704ffeb7', - 'auctionId': '3fdc6494-da94-44a0-a292-b55a90b08b2c', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'startTime': 1615412098213 - }, { - 'bidder': 'rubicon', - 'params': { - 'accountId': 1001, - 'siteId': 12345, - 'zoneId': 67890, - 'floor': null - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-1', - 'transactionId': '404a7b28-f276-41cc-a5cf-c1d3dc5671f9', - 'sizes': [[300, 250]], - 'bidId': '456gt123jkl098', - 'bidderRequestId': '46a00704ffeb7', - 'auctionId': '3fdc6494-da94-44a0-a292-b55a90b08b2c', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'startTime': 1615412098213 - }]; - - const response = { - 'status': 'ok', - 'account_id': 14062, - 'site_id': 70608, - 'zone_id': 530022, - 'size_id': 15, - 'alt_size_ids': [ - 43 - ], - 'tracking': '', - 'inventory': {}, - 'ads': [ - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374c', - 'size_id': '15', - 'ad_id': '6', - 'advertiser': 7, - 'network': 8, - 'creative_id': 'crid-9', - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 0.811, - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '15_tier_all_test' - ] - } - ] - }, - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374c', - 'size_id': '15', - 'ad_id': '7', - 'advertiser': 7, - 'network': 8, - 'creative_id': 'crid-9', - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 0.911, - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '43_tier_all_test' - ] - } - ] - }, - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374d', - 'size_id': '43', - 'ad_id': '7', - 'advertiser': 7, - 'network': 8, - 'creative_id': 'crid-9', - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 1.911, - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '43_tier_all_test' - ] - } - ] - } - ] - }; - - config.setConfig({ multibid: [{bidder: 'rubicon', maxbids: 2, targetbiddercodeprefix: 'rubi'}] }); - - const bids = spec.interpretResponse({body: response}, { - bidRequest: bidRequests - }); - - expect(bids).to.be.lengthOf(3); - expect(bids[0].requestId).to.not.equal(bids[1].requestId); - expect(bids[1].requestId).to.equal(bids[2].requestId); - }); - - it('should handle an error with no ads returned', function () { - const response = { - 'status': 'ok', - 'account_id': 14062, - 'site_id': 70608, - 'zone_id': 530022, - 'size_id': 15, - 'alt_size_ids': [ - 43 - ], - 'tracking': '', - 'inventory': {}, - 'ads': [] - }; - - const bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - - expect(bids).to.be.lengthOf(0); - }); - - it('Should support recieving an auctionConfig and pass it along to Prebid', function () { - const response = { - 'status': 'ok', - 'account_id': 14062, - 'site_id': 70608, - 'zone_id': 530022, - 'size_id': 15, - 'alt_size_ids': [ - 43 - ], - 'tracking': '', - 'inventory': {}, - 'ads': [{ - 'status': 'ok', - 'cpm': 0, - 'size_id': 15 - }], - 'component_auction_config': [{ - 'random': 'value', - 'bidId': '5432' - }, - { - 'random': 'string', - 'bidId': '6789' - }] - }; - - const {bids, paapi} = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - - expect(bids).to.be.lengthOf(1); - expect(paapi[0].bidId).to.equal('5432'); - expect(paapi[0].config.random).to.equal('value'); - expect(paapi[1].bidId).to.equal('6789'); - }); - - it('should handle an error', function () { - const response = { - 'status': 'ok', - 'account_id': 14062, - 'site_id': 70608, - 'zone_id': 530022, - 'size_id': 15, - 'alt_size_ids': [ - 43 - ], - 'tracking': '', - 'inventory': {}, - 'ads': [{ - 'status': 'not_ok', - }] - }; - - const bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - - expect(bids).to.be.lengthOf(0); - }); - - it('should handle an error because of malformed json response', function () { - const response = '{test{'; - - const bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - - expect(bids).to.be.lengthOf(0); - }); - - it('should handle a bidRequest argument of type Array', function () { - const response = { - 'status': 'ok', - 'account_id': 14062, - 'site_id': 70608, - 'zone_id': 530022, - 'size_id': 15, - 'alt_size_ids': [ - 43 - ], - 'tracking': '', - 'inventory': {}, - 'ads': [{ - 'status': 'ok', - 'cpm': 0, - 'size_id': 15 - }] - }; - - const bids = spec.interpretResponse({body: response}, { - bidRequest: [utils.deepClone(bidderRequest.bids[0])] - }); - - expect(bids).to.be.lengthOf(1); - expect(bids[0].cpm).to.be.equal(0); - }); - - it('should use ads.emulated_format if defined for bid.meta.mediaType', function () { - const response = { - 'status': 'ok', - 'account_id': 14062, - 'site_id': 70608, - 'zone_id': 530022, - 'size_id': 15, - 'alt_size_ids': [ - 43 - ], - 'tracking': '', - 'inventory': {}, - 'ads': [ - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374c', - 'size_id': '15', - 'ad_id': '6', - 'advertiser': 7, - 'network': 8, - 'creative_id': 'crid-9', - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 0.811, - 'emulated_format': 'video', - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '15_tier_all_test' - ] - } - ] - }, - { - 'status': 'ok', - 'impression_id': '153dc240-8229-4604-b8f5-256933b9374d', - 'size_id': '43', - 'ad_id': '7', - 'advertiser': 7, - 'network': 8, - 'creative_id': 'crid-9', - 'type': 'script', - 'script': 'alert(\'foo\')', - 'campaign_id': 10, - 'cpm': 0.911, - 'targeting': [ - { - 'key': 'rpfl_14062', - 'values': [ - '43_tier_all_test' - ] - } - ] - } - ] - }; - const bids = spec.interpretResponse({body: response}, { - bidRequest: bidderRequest.bids[0] - }); - expect(bids[0].meta.mediaType).to.equal('banner'); - expect(bids[1].meta.mediaType).to.equal('video'); - }); - - describe('singleRequest enabled', function () { - it('handles bidRequest of type Array and returns associated adUnits', function () { - const overrideMap = []; - overrideMap[0] = {impression_id: '1'}; - - const stubAds = []; - for (let i = 0; i < 10; i++) { - stubAds.push(createResponseAdByIndex(i, sizeMap[i].sizeId, overrideMap)); - } - - const stubBids = []; - for (let i = 0; i < 10; i++) { - stubBids.push(createBidRequestByIndex(i, sizeMap[i].sizeAsArray.slice())); - } - - const bids = spec.interpretResponse({ - body: { - 'status': 'ok', - 'site_id': '1100', - 'account_id': 14062, - 'zone_id': 2100, - 'size_id': '1', - 'tracking': '', - 'inventory': {}, - 'ads': stubAds - } - }, {bidRequest: stubBids}); - expect(bids).to.be.a('array').with.lengthOf(10); - - bids.forEach((bid) => { - expect(bid).to.be.a('object'); - expect(bid).to.have.property('cpm').that.is.a('number'); - expect(bid).to.have.property('width').that.is.a('number'); - expect(bid).to.have.property('height').that.is.a('number'); - - // verify that result bid 'sizeId' links to a size from the sizeMap - const size = getSizeIdForBid(sizeMap, bid); - expect(size).to.be.a('object'); - - // use 'size' to verify that result bid links to the 'response.ad' passed to function - const associateAd = getResponseAdBySize(stubAds, size); - expect(associateAd).to.be.a('object'); - expect(associateAd).to.have.property('creative_id').that.is.a('string'); - - // use 'size' to verify that result bid links to the 'bidRequest' passed to function - const associateBidRequest = getBidRequestBySize(stubBids, size); - expect(associateBidRequest).to.be.a('object'); - expect(associateBidRequest).to.have.property('bidId').that.is.a('string'); - - // verify all bid properties set using 'ad' and 'bidRequest' match - // 'ad.creative_id === bid.creativeId' - expect(bid.requestId).to.equal(associateBidRequest.bidId); - // 'bid.requestId === bidRequest.bidId' - expect(bid.creativeId).to.equal(associateAd.creative_id); - }); - }); - - it('handles incorrect adUnits length by returning all bids with matching ads', function () { - const overrideMap = []; - overrideMap[0] = {impression_id: '1'}; - - const stubAds = []; - for (let i = 0; i < 6; i++) { - stubAds.push(createResponseAdByIndex(i, sizeMap[i].sizeId, overrideMap)); - } - - const stubBids = []; - for (let i = 0; i < 10; i++) { - stubBids.push(createBidRequestByIndex(i, sizeMap[i].sizeAsArray.slice())); - } - - const bids = spec.interpretResponse({ - body: { - 'status': 'ok', - 'site_id': '1100', - 'account_id': 14062, - 'zone_id': 2100, - 'size_id': '1', - 'tracking': '', - 'inventory': {}, - 'ads': stubAds - } - }, {bidRequest: stubBids}); - - // no bids expected because response didn't match requested bid number - expect(bids).to.be.a('array').with.lengthOf(6); - }); - - it('skips adUnits with error status and returns all bids with ok status', function () { - const stubAds = []; - // Create overrides to break associations between bids and ads - // Each override should cause one less bid to be returned by interpretResponse - const overrideMap = []; - overrideMap[0] = {impression_id: '1'}; - overrideMap[2] = {status: 'error'}; - overrideMap[4] = {status: 'error'}; - overrideMap[7] = {status: 'error'}; - overrideMap[8] = {status: 'error'}; - - for (let i = 0; i < 10; i++) { - stubAds.push(createResponseAdByIndex(i, sizeMap[i].sizeId, overrideMap)); - } - - const stubBids = []; - for (let i = 0; i < 10; i++) { - stubBids.push(createBidRequestByIndex(i, sizeMap[i].sizeAsArray.slice())); - } - - const bids = spec.interpretResponse({ - body: { - 'status': 'error', - 'site_id': '1100', - 'account_id': 14062, - 'zone_id': 2100, - 'size_id': '1', - 'tracking': '', - 'inventory': {}, - 'ads': stubAds - } - }, {bidRequest: stubBids}); - expect(bids).to.be.a('array').with.lengthOf(6); - - bids.forEach((bid) => { - expect(bid).to.be.a('object'); - expect(bid).to.have.property('cpm').that.is.a('number'); - expect(bid).to.have.property('width').that.is.a('number'); - expect(bid).to.have.property('height').that.is.a('number'); - - // verify that result bid 'sizeId' links to a size from the sizeMap - const size = getSizeIdForBid(sizeMap, bid); - expect(size).to.be.a('object'); - - // use 'size' to verify that result bid links to the 'response.ad' passed to function - const associateAd = getResponseAdBySize(stubAds, size); - expect(associateAd).to.be.a('object'); - expect(associateAd).to.have.property('creative_id').that.is.a('string'); - expect(associateAd).to.have.property('status').that.is.a('string'); - expect(associateAd.status).to.equal('ok'); - - // use 'size' to verify that result bid links to the 'bidRequest' passed to function - const associateBidRequest = getBidRequestBySize(stubBids, size); - expect(associateBidRequest).to.be.a('object'); - expect(associateBidRequest).to.have.property('bidId').that.is.a('string'); - - // verify all bid properties set using 'ad' and 'bidRequest' match - // 'ad.creative_id === bid.creativeId' - expect(bid.requestId).to.equal(associateBidRequest.bidId); - // 'bid.requestId === bidRequest.bidId' - expect(bid.creativeId).to.equal(associateAd.creative_id); - }); - }); - }); - }); - - if (FEATURES.VIDEO) { - describe('for video', function () { - it('should register a successful bid', function () { - const bidderRequest = createVideoBidderRequest(); - const response = { - cur: 'USD', - seatbid: [{ - bid: [{ - id: '0', - impid: '/19968336/header-bid-tag-0', - adomain: ['test.com'], - price: 2, - crid: '4259970', - ext: { - bidder: { - rp: { - mime: 'application/javascript', - size_id: 201, - advid: 12345 - } - }, - prebid: { - targeting: { - hb_uuid: '0c498f63-5111-4bed-98e2-9be7cb932a64' - }, - type: 'video' - } - } - }], - group: 0, - seat: 'rubicon' - }], - }; - - const request = converter.toORTB({bidderRequest, bidRequests: bidderRequest.bids}); - - const bids = spec.interpretResponse({body: response}, {data: request}); - - expect(bids).to.be.lengthOf(1); - - expect(bids[0].seatBidId).to.equal('0'); - expect(bids[0].creativeId).to.equal('4259970'); - expect(bids[0].cpm).to.equal(2); - expect(bids[0].ttl).to.equal(360); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[0].adserverTargeting).to.deep.equal({hb_uuid: '0c498f63-5111-4bed-98e2-9be7cb932a64'}); - expect(bids[0].mediaType).to.equal('video'); - expect(bids[0].meta.mediaType).to.equal('video'); - expect(String(bids[0].meta.advertiserDomains)).to.equal('test.com'); - expect(bids[0].meta.advertiserId).to.equal(12345); - expect(bids[0].bidderCode).to.equal('rubicon'); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].width).to.equal(640); - expect(bids[0].height).to.equal(480); - }); - }); - } - - if (FEATURES.NATIVE) { - describe('for native', () => { - it('should get a native bid', () => { - const nativeBidderRequest = addNativeToBidRequest(bidderRequest); - const request = converter.toORTB({bidderRequest: nativeBidderRequest, bidRequests: nativeBidderRequest.bids}); - const response = getNativeResponse({impid: request.imp[0].id}); - const bids = spec.interpretResponse({body: response}, {data: request}); - expect(bids).to.have.nested.property('[0].native'); - }); - it('should set 0 to bids width and height if `w` and `h` in response object not defined', () => { - const nativeBidderRequest = addNativeToBidRequest(bidderRequest); - const request = converter.toORTB({bidderRequest: nativeBidderRequest, bidRequests: nativeBidderRequest.bids}); - const response = getNativeResponse({impid: request.imp[0].id}); - delete response.seatbid[0].bid[0].w; - delete response.seatbid[0].bid[0].h - const bids = spec.interpretResponse({body: response}, {data: request}); - expect(bids[0].width).to.equal(0); - expect(bids[0].height).to.equal(0); - }); - }); - } - - if (FEATURES.VIDEO) { - describe('for outstream video', function () { - const sandbox = sinon.createSandbox(); - beforeEach(function () { - config.setConfig({rubicon: { - rendererConfig: { - align: 'left', - closeButton: true, - collapse: false - }, - rendererUrl: 'https://example.test/renderer.js' - }}); - window.MagniteApex = { - renderAd: function() { - return null; - } - } - }); - - afterEach(function () { - sandbox.restore(); - delete window.MagniteApex; - }); - - it('should register a successful bid', function () { - const bidderRequest = createVideoBidderRequestOutstream(); - const response = { - cur: 'USD', - seatbid: [{ - bid: [{ - id: '0', - impid: '/19968336/header-bid-tag-0', - adomain: ['test.com'], - price: 2, - crid: '4259970', - ext: { - bidder: { - rp: { - mime: 'application/javascript', - size_id: 201, - advid: 12345 - } - }, - prebid: { - targeting: { - hb_uuid: '0c498f63-5111-4bed-98e2-9be7cb932a64' - }, - type: 'video' - } - } - }], - group: 0, - seat: 'rubicon' - }], - }; - - const request = converter.toORTB({bidderRequest, bidRequests: bidderRequest.bids}); - - const bids = spec.interpretResponse({body: response}, { data: request }); - - expect(bids).to.be.lengthOf(1); - - expect(bids[0].seatBidId).to.equal('0'); - expect(bids[0].creativeId).to.equal('4259970'); - expect(bids[0].cpm).to.equal(2); - expect(bids[0].ttl).to.equal(360); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[0].adserverTargeting).to.deep.equal({hb_uuid: '0c498f63-5111-4bed-98e2-9be7cb932a64'}); - expect(bids[0].mediaType).to.equal('video'); - expect(bids[0].meta.mediaType).to.equal('video'); - expect(String(bids[0].meta.advertiserDomains)).to.equal('test.com'); - expect(bids[0].meta.advertiserId).to.equal(12345); - expect(bids[0].bidderCode).to.equal('rubicon'); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].width).to.equal(640); - expect(bids[0].height).to.equal(320); - // check custom renderer - expect(typeof bids[0].renderer).to.equal('object'); - expect(bids[0].renderer.getConfig()).to.deep.equal({ - align: 'left', - closeButton: true, - collapse: false - }); - expect(bids[0].renderer.url).to.equal('https://example.test/renderer.js'); - }); - - it('should render ad with Magnite renderer', function () { - const bidderRequest = createVideoBidderRequestOutstream(); - const response = { - cur: 'USD', - seatbid: [{ - bid: [{ - id: '0', - impid: '/19968336/header-bid-tag-0', - adomain: ['test.com'], - price: 2, - crid: '4259970', - ext: { - bidder: { - rp: { - mime: 'application/javascript', - size_id: 201, - advid: 12345 - } - }, - prebid: { - targeting: { - hb_uuid: '0c498f63-5111-4bed-98e2-9be7cb932a64' - }, - type: 'video' - } - }, - nurl: 'https://test.com/vast.xml' - }], - group: 0, - seat: 'rubicon' - }], - }; - - const request = converter.toORTB({bidderRequest, bidRequests: bidderRequest.bids}); - - sinon.spy(window.MagniteApex, 'renderAd'); - - const bids = spec.interpretResponse({body: response}, {data: request}); - const bid = bids[0]; - bid.adUnitCode = 'outstream_video1_placement'; - const adUnit = document.createElement('div'); - const adUnitSelector = `#${bid.adUnitCode}` - adUnit.id = bid.adUnitCode; - document.body.appendChild(adUnit); - - bid.renderer.render(bid); - - const renderCall = window.MagniteApex.renderAd.getCall(0); - expect(renderCall.args[0]).to.deep.equal({ - closeButton: true, - collapse: false, - height: 320, - label: undefined, - placement: { - align: 'left', - attachTo: adUnitSelector, - position: 'append', - }, - vastUrl: 'https://test.com/vast.xml', - width: 640 - }); - // cleanup - adUnit.parentNode.removeChild(adUnit); - }); - - it('should render ad with Magnite renderer without video object', function () { - const bidderRequest = createVideoBidderRequestOutstream(); - delete bidderRequest.bids[0].params.video; - bidderRequest.bids[0].params.bidonmultiformat = true; - bidderRequest.bids[0].mediaTypes.video.placement = 3; - bidderRequest.bids[0].mediaTypes.video.playerSize = [640, 480]; - - const response = { - cur: 'USD', - seatbid: [{ - bid: [{ - id: '0', - impid: '/19968336/header-bid-tag-0', - adomain: ['test.com'], - price: 2, - crid: '4259970', - ext: { - bidder: { - rp: { - mime: 'application/javascript', - size_id: 201, - advid: 12345 - } - }, - prebid: { - targeting: { - hb_uuid: '0c498f63-5111-4bed-98e2-9be7cb932a64' - }, - type: 'video' - } - }, - nurl: 'https://test.com/vast.xml' - }], - group: 0, - seat: 'rubicon' - }], - }; - - const request = converter.toORTB({bidderRequest, bidRequests: bidderRequest.bids}); - - sinon.spy(window.MagniteApex, 'renderAd'); - - const bids = spec.interpretResponse({body: response}, {data: request}); - const bid = bids[0]; - bid.adUnitCode = 'outstream_video1_placement'; - const adUnit = document.createElement('div'); - const adUnitSelector = `#${bid.adUnitCode}` - adUnit.id = bid.adUnitCode; - document.body.appendChild(adUnit); - - bid.renderer.render(bid); - - const renderCall = window.MagniteApex.renderAd.getCall(0); - expect(renderCall.args[0]).to.deep.equal({ - closeButton: true, - collapse: false, - height: 480, - label: undefined, - placement: { - align: 'left', - attachTo: adUnitSelector, - position: 'append', - }, - vastUrl: 'https://test.com/vast.xml', - width: 640 - }); - // cleanup - adUnit.parentNode.removeChild(adUnit); - }); - }); - } - - describe('config with integration type', () => { - it('should use the integration type provided in the config instead of the default', () => { - config.setConfig({rubicon: {int_type: 'testType'}}); - const [request] = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(new URLSearchParams(request.data).get('tk_flint')).to.equal('testType_v$prebid.version$'); - }); - }); - }); - }); - - describe('user sync', function () { - const emilyUrl = 'https://eus.rubiconproject.com/usync.html'; - - it('should register the Emily iframe', function () { - const syncs = spec.getUserSyncs({ - iframeEnabled: true - }); - - expect(syncs).to.deep.equal({type: 'iframe', url: emilyUrl}); - }); - - it('should register the Emily iframe more than once', function () { - let syncs = spec.getUserSyncs({ - iframeEnabled: true - }); - expect(syncs).to.deep.equal({type: 'iframe', url: emilyUrl}); - - // when called again, should still have only been called once - syncs = spec.getUserSyncs({ - iframeEnabled: true - }); - expect(syncs).to.deep.equal({type: 'iframe', url: emilyUrl}); - }); - - it('should pass gdpr params if consent is true', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, { - gdprApplies: true, consentString: 'foo' - })).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}?gdpr=1&gdpr_consent=foo` - }); - }); - - it('should pass gdpr params if consent is false', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, { - gdprApplies: false, consentString: 'foo' - })).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}?gdpr=0&gdpr_consent=foo` - }); - }); - - it('should pass gdpr param gdpr_consent only when gdprApplies is undefined', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, { - consentString: 'foo' - })).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}?gdpr_consent=foo` - }); - }); - - it('should pass no params if gdpr consentString is not defined', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, {})).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}` - }); - }); - - it('should pass no params if gdpr consentString is a number', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, { - consentString: 0 - })).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}` - }); - }); - - it('should pass no params if gdpr consentString is null', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, { - consentString: null - })).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}` - }); - }); - - it('should pass no params if gdpr consentString is a object', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, { - consentString: {} - })).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}` - }); - }); - - it('should pass no params if gdpr is not defined', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, undefined)).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}` - }); - }); - - it('should pass us_privacy if uspConsent is defined', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, undefined, '1NYN')).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}?us_privacy=1NYN` - }); - }); - - it('should pass us_privacy after gdpr if both are present', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, { - consentString: 'foo' - }, '1NYN')).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}?gdpr_consent=foo&us_privacy=1NYN` - }); - }); - - it('should pass gdprApplies', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, { - gdprApplies: true - }, '1NYN')).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}?gdpr=1&us_privacy=1NYN` - }); - }); - - it('should pass all correctly', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, { - gdprApplies: true, - consentString: 'foo' - }, '1NYN')).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}?gdpr=1&gdpr_consent=foo&us_privacy=1NYN` - }); - }); - - it('should pass gpp params when gppConsent is present', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, {}, undefined, { - gppString: 'foo', - applicableSections: [2] - })).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}?gpp=foo&gpp_sid=2` - }); - }); - - it('should pass multiple sid\'s when multiple are present', function () { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, {}, undefined, { - gppString: 'foo', - applicableSections: [2, 5] - })).to.deep.equal({ - type: 'iframe', url: `${emilyUrl}?gpp=foo&gpp_sid=2,5` - }); - }); - }); - - describe('get price granularity', function () { - it('should return correct buckets for all price granularity values', function () { - const CUSTOM_PRICE_BUCKET_ITEM = {max: 5, increment: 0.5}; - - const mockConfig = { - priceGranularity: undefined, - customPriceBucket: { - buckets: [CUSTOM_PRICE_BUCKET_ITEM] - } - }; - sandbox.stub(config, 'getConfig').callsFake(key => { - return mockConfig[key]; - }); - - [ - {key: 'low', val: {max: 5.00, increment: 0.50}}, - {key: 'medium', val: {max: 20.00, increment: 0.10}}, - {key: 'high', val: {max: 20.00, increment: 0.01}}, - {key: 'auto', val: {max: 5.00, increment: 0.05}}, - {key: 'dense', val: {max: 3.00, increment: 0.01}}, - {key: 'custom', val: CUSTOM_PRICE_BUCKET_ITEM}, - - ].forEach(kvPair => { - mockConfig.priceGranularity = kvPair.key; - const result = getPriceGranularity(config); - expect(typeof result).to.equal('object'); - expect(result).to.haveOwnProperty('ranges'); - expect(Array.isArray(result.ranges)).to.equal(true); - expect(result.ranges.length).to.be.greaterThan(0) - expect(result.ranges[0]).to.deep.equal(kvPair.val); - }); - }); - }); - - describe('Supply Chain Support', function () { - const nodePropsOrder = ['asi', 'sid', 'hp', 'rid', 'name', 'domain']; - let bidRequests; - let schainConfig; - - const getSupplyChainConfig = () => { - return { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'rubicon.com', - sid: '1234', - hp: 1, - rid: 'bid-request-1', - name: 'pub one', - domain: 'pub1.com' - }, - { - asi: 'theexchange.com', - sid: '5678', - hp: 1, - rid: 'bid-request-2', - name: 'pub two', - domain: 'pub2.com' - }, - { - asi: 'wesellads.com', - sid: '9876', - hp: 1, - rid: 'bid-request-3', - // name: 'alladsallthetime', - domain: 'alladsallthetime.com' - } - ] - }; - }; - - beforeEach(() => { - bidRequests = getBidderRequest(); - schainConfig = getSupplyChainConfig(); - bidRequests.bids[0].ortb2.source.ext = bidRequests.bids[0].ortb2.source.ext || {}; - bidRequests.bids[0].ortb2.source.ext.schain = schainConfig; - }); - - it('should properly serialize schain object with correct delimiters', () => { - const results = spec.buildRequests(bidRequests.bids, bidRequests); - const numNodes = schainConfig.nodes.length; - const schain = new URLSearchParams(results[0].data).get('rp_schain'); - - // each node serialization should start with an ! - expect(schain.match(/!/g).length).to.equal(numNodes); - - // 5 commas per node plus 1 for version - expect(schain.match(/,/g).length).to.equal(numNodes * 5 + 1); - }); - - it('should send the proper version for the schain', () => { - const results = spec.buildRequests(bidRequests.bids, bidRequests); - const schain = new URLSearchParams(results[0].data).get('rp_schain').split('!'); - const version = schain.shift().split(',')[0]; - expect(version).to.equal(bidRequests.bids[0].ortb2.source.ext.schain.ver); - }); - - it('should send the correct value for complete in schain', () => { - const results = spec.buildRequests(bidRequests.bids, bidRequests); - const schain = new URLSearchParams(results[0].data).get('rp_schain').split('!'); - const complete = schain.shift().split(',')[1]; - expect(complete).to.equal(String(bidRequests.bids[0].ortb2.source.ext.schain.complete)); - }); - - it('should send available params in the right order', () => { - const results = spec.buildRequests(bidRequests.bids, bidRequests); - const schain = new URLSearchParams(results[0].data).get('rp_schain').split('!'); - schain.shift(); - - schain.forEach((serializeNode, nodeIndex) => { - const nodeProps = serializeNode.split(','); - nodeProps.forEach((nodeProp, propIndex) => { - const node = schainConfig.nodes[nodeIndex]; - const key = nodePropsOrder[propIndex]; - expect(nodeProp).to.equal(node[key] ? String(node[key]) : ''); - }); - }); - }); - - it('should copy the schain JSON to to bid.source.ext.schain', () => { - const bidderRequest = createVideoBidderRequest(); - const schain = getSupplyChainConfig(); - bidderRequest.bids[0].ortb2.source.ext = { schain: schain }; - const request = spec.buildRequests(bidderRequest.bids, bidderRequest); - expect(request[0].data.source.ext.schain).to.deep.equal(schain); - }); - }); - - describe('configurable settings', function() { - afterEach(() => { - config.setConfig({ - rubicon: { - bannerHost: 'rubicon', - videoHost: 'prebid-server', - syncHost: 'eus', - returnVast: false - } - }); - config.resetConfig(); - }); - - it('should update fastlane endpoint if', function () { - config.setConfig({ - rubicon: { - bannerHost: 'fastlane-qa', - videoHost: 'prebid-server-qa', - syncHost: 'eus-qa', - returnVast: true - } - }); - - // banner - const bannerBidderRequest = createGdprBidderRequest(false); - const [bannerRequest] = spec.buildRequests(bannerBidderRequest.bids, bannerBidderRequest); - expect(bannerRequest.url).to.equal('https://fastlane-qa.rubiconproject.com/a/api/fastlane.json'); - - // video and returnVast - const videoBidderRequest = createVideoBidderRequest(); - const [videoRequest] = spec.buildRequests(videoBidderRequest.bids, videoBidderRequest); - const post = videoRequest.data; - expect(videoRequest.url).to.equal('https://prebid-server-qa.rubiconproject.com/openrtb2/auction'); - expect(post.ext.prebid.cache.vastxml).to.have.property('returnCreative').that.is.an('boolean'); - expect(post.ext.prebid.cache.vastxml.returnCreative).to.equal(true); - - // user sync - const syncs = spec.getUserSyncs({ - iframeEnabled: true - }); - expect(syncs).to.deep.equal({type: 'iframe', url: 'https://eus-qa.rubiconproject.com/usync.html'}); - }); - }); -}); - -function addNativeToBidRequest(bidderRequest, options = {twin: false}) { - const nativeOrtbRequest = { - assets: [{ - id: 0, - required: 1, - title: { - len: 140 - } - }, - { - id: 1, - required: 1, - img: { - type: 3, - w: 300, - h: 600 - } - }, - { - id: 2, - required: 1, - data: { - type: 1 - } - }] - }; - bidderRequest.refererInfo = { - page: 'localhost' - } - const numBids = !options.twin ? 1 : 2; - for (let i = 0; i < numBids; i++) { - bidderRequest.bids[i] = { - bidder: 'rubicon', - params: { - accountId: '14062', - siteId: '70608', - zoneId: '335918', - }, - adUnitCode: '/19968336/header-bid-tag-0', - code: 'div-1', - bidId: '2ffb201a808da7', - bidderRequestId: '178e34bad3658f', - auctionId: 'c45dd708-a418-42ec-b8a7-b70a6c6fab0a', - transactionId: 'd45dd707-a418-42ec-b8a7-b70a6c6fab0b', - mediaTypes: { - native: { - ortb: { - ...nativeOrtbRequest - } - } - }, - nativeOrtbRequest - } - } - return bidderRequest; -} - -function getNativeResponse(options = {impid: 1234}) { - return { - 'id': 'd7786a80-bfb4-4541-859f-225a934e81d4', - 'seatbid': [ - { - 'bid': [ - { - 'id': '971650', - 'impid': options.impid, - 'price': 20, - 'adm': { - 'ver': '1.2', - 'assets': [ - { - 'id': 0, - 'title': { - 'text': 'This is a title' - }, - 'link': { - 'clicktrackers': [ - 'http://localhost:5500/event?type=click1&component=card&asset=0' - ] - } - }, - { - 'id': 1, - 'img': { - 'url': 'https:\\\\/\\\\/vcdn.adnxs.com\\\\/p\\\\/creative-image\\\\/94\\\\/22\\\\/cd\\\\/0f\\\\/9422cd0f-f400-45d3-80f5-2b92629d9257.jpg', - 'h': 2250, - 'w': 3000 - }, - 'link': { - 'clicktrackers': [ - 'http://localhost:5500/event?type=click1&component=card&asset=1' - ] - } - }, - { - 'id': 2, - 'data': { - 'value': 'this is asset data 1 that corresponds to sponsoredBy' - } - } - ], - 'link': { - 'url': 'https://magnite.com', - 'clicktrackers': [ - 'http://localhost:5500/event?type=click1&component=card', - 'http://localhost:5500/event?type=click2&component=card' - ] - }, - 'jstracker': '', - 'eventtrackers': [ - { - 'event': 1, - 'method': 2, - 'url': 'http://localhost:5500/event?type=1&method=2' - }, - { - 'event': 2, - 'method': 1, - 'url': 'http://localhost:5500/event?type=v50&component=card' - } - ] - }, - 'adid': '392180', - 'adomain': [ - 'http://prebid.org' - ], - 'iurl': 'https://lax1-ib.adnxs.com/cr?id=97494403', - 'cid': '9325', - 'crid': '97494403', - 'cat': [ - 'IAB3-1' - ], - 'w': 300, - 'h': 600, - 'ext': { - 'prebid': { - 'targeting': { - 'hb_bidder': 'rubicon', - 'hb_cache_host': 'prebid.lax1.adnxs-simple.com', - 'hb_cache_path': '/pbc/v1/cache', - 'hb_pb': '20.00' - }, - 'type': 'native', - 'video': { - 'duration': 0, - 'primary_category': '' - } - }, - 'rubicon': { - 'auction_id': 642778043863823100, - 'bid_ad_type': 3, - 'bidder_id': 2, - 'brand_id': 555545 - } - } - } - ], - 'seat': 'rubicon' - } - ], - 'cur': 'USD' - }; -} diff --git a/test/spec/modules/rumbleBidAdapter_spec.js b/test/spec/modules/rumbleBidAdapter_spec.js deleted file mode 100644 index a3e34e34d..000000000 --- a/test/spec/modules/rumbleBidAdapter_spec.js +++ /dev/null @@ -1,125 +0,0 @@ -import {spec, converter} from 'modules/rumbleBidAdapter.js'; -import { config } from '../../../src/config.js'; -import {BANNER} from "../../../src/mediaTypes.js"; -import {deepClone, getUniqueIdentifierStr} from "../../../src/utils.js"; -import {expect} from "chai"; - -const bidder = 'rumble'; - -describe('RumbleBidAdapter', function() { - describe('isBidRequestValid', function() { - const bidId = getUniqueIdentifierStr(); - const bidderRequestId = getUniqueIdentifierStr(); - - function newBid() { - return { - bidder, - bidId, - bidderRequestId, - params: { - publisherId: '123', - siteId: '321', - }, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - } - } - - it('should return true when all required parameters exist', function() { - expect(spec.isBidRequestValid(newBid())).to.equal(true); - }); - - it('should return false when publisherId is not present', function() { - let bid = newBid(); - delete bid.params.publisherId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when siteId is not present', function() { - let bid = newBid(); - delete bid.params.siteId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if mediaTypes.banner or video is not present', function () { - let bid = newBid(); - delete bid.mediaTypes - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when global configuration is present', function() { - let bid = newBid(); - delete bid.params.publisherId; - delete bid.params.siteId; - - config.mergeConfig({ - rumble: { - publisherId: 1, - siteId: 1, - test: true, - } - }); - - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - - describe('buildRequests', function() { - let bidRequests = [{ - bidder: 'rumble', - params: { - publisherId: 1, - siteId: 2, - zoneId: 3, - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - sizes: [[300, 250]], - bidId: getUniqueIdentifierStr(), - bidderRequestId: getUniqueIdentifierStr(), - auctionId: getUniqueIdentifierStr(), - src: 'client', - bidRequestsCount: 1 - }]; - - let bidderRequest = { - bidderCode: 'rumble', - auctionId: getUniqueIdentifierStr(), - refererInfo: { - domain: 'localhost', - page: 'http://localhost/integrationExamples/gpt/hello_world.html?pbjs_debug=true', - }, - ortb2: { - site: { - publisher: { - name: 'rumble' - } - } - } - }; - - function createRequests(bidRequests, bidderRequest) { - let cbr = deepClone(bidderRequest); - cbr.bids = bidRequests; - return spec.buildRequests(bidRequests, cbr); - } - - it('should validate request', function() { - let requests = createRequests(bidRequests, bidderRequest); - - expect(requests).to.have.lengthOf(bidRequests.length); - - requests.forEach(function(request, idx) { - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://a.ads.rmbl.ws/v1/sites/2/ortb?pid=1&a=3'); - expect(request.bidRequest).to.equal(bidRequests[idx]); - }); - }); - }); -}); diff --git a/test/spec/modules/scaleableAnalyticsAdapter_spec.js b/test/spec/modules/scaleableAnalyticsAdapter_spec.js deleted file mode 100644 index 5f8607389..000000000 --- a/test/spec/modules/scaleableAnalyticsAdapter_spec.js +++ /dev/null @@ -1,165 +0,0 @@ -import scaleableAnalytics from 'modules/scaleableAnalyticsAdapter.js'; -import { expect } from 'chai'; -import * as events from 'src/events.js'; -import { EVENTS } from 'src/constants.js'; -import { server } from 'test/mocks/xhr.js'; - -const BID_TIMEOUT = EVENTS.BID_TIMEOUT; -const AUCTION_INIT = EVENTS.AUCTION_INIT; -const BID_WON = EVENTS.BID_WON; -const AUCTION_END = EVENTS.AUCTION_END; - -describe('Scaleable Analytics Adapter', function() { - const bidsReceivedObj = { - adUnitCode: '12345', - bidderCode: 'test-code', - cpm: 3.14, - currency: 'USD', - dealId: null, - mediaType: 'banner', - timeToRespond: 285, - size: '300x250' - }; - - const MOCK_DATA = { - adUnitCode: '12345', - auctionEnd: { - bidsReceived: [bidsReceivedObj] - }, - bidderRequests: [{ - bids: [{ - adUnitCode: '12345', - bidder: 'test-code', - params: { - test: 'value' - } - }] - }], - site: '5c4fab7a829e955d6c265e72', - bidResponse: { - adUnitCode: '12345', - bidderCode: 'test-code', - cpm: 3.14, - timeToRespond: 285, - params: [{ - test: 'value' - }] - }, - bidTimeout: [ - { - adUnitCode: '67890', - bidder: 'test-code' - } - ] - }; - - const bidObj = MOCK_DATA.bidderRequests[0].bids[0]; - - const expectedBidRequests = [{bidder: 'scaleable_adunit_request'}].concat([ - { - bidder: bidObj.bidder, - params: bidObj.params - } - ]); - - MOCK_DATA.expectedRequestResponse = { - event: 'request', - site: MOCK_DATA.site, - adunits: [{ - code: bidObj.adUnitCode, - bidRequests: expectedBidRequests - }] - } - - MOCK_DATA.expectedBidTimeout = { - [MOCK_DATA.bidTimeout[0].adUnitCode]: [{ - timeouts: 1, - bidder: MOCK_DATA.bidTimeout[0].bidder - }] - }; - - MOCK_DATA.expectedAuctionEndResponse = { - event: 'bids', - site: MOCK_DATA.site, - adunits: [{ - code: MOCK_DATA.auctionEnd.bidsReceived[0].adUnitCode, - bidData: [{ - bidder: bidsReceivedObj.bidderCode, - cpm: bidsReceivedObj.cpm, - currency: bidsReceivedObj.currency, - dealId: bidsReceivedObj.dealId, - type: bidsReceivedObj.mediaType, - ttr: bidsReceivedObj.timeToRespond, - size: bidsReceivedObj.size - }] - }, - { - bidData: MOCK_DATA.expectedBidTimeout[MOCK_DATA.bidTimeout[0].adUnitCode], - code: MOCK_DATA.bidTimeout[0].adUnitCode - }] - } - - describe('Event Handling', function() { - beforeEach(function() { - sinon.stub(events, 'getEvents').returns([]); - - scaleableAnalytics.enableAnalytics({ - provider: 'scaleable', - options: { - site: MOCK_DATA.site - } - }); - }); - - afterEach(function() { - events.getEvents.restore(); - scaleableAnalytics.disableAnalytics(); - }); - - it('should handle the auction init event', function(done) { - events.emit(AUCTION_INIT, { - adUnitCodes: [MOCK_DATA.adUnitCode], - bidderRequests: MOCK_DATA.bidderRequests - }); - - const result = JSON.parse(server.requests[0].requestBody); - expect(result).to.deep.equal(MOCK_DATA.expectedRequestResponse); - - done(); - }); - - it('should handle the bid timeout event', function() { - events.emit(BID_TIMEOUT, MOCK_DATA.bidTimeout); - - const actual = scaleableAnalytics.getAuctionData(); - - expect(actual).to.deep.equal(MOCK_DATA.expectedBidTimeout); - }); - - it('should handle the bid won event', function(done) { - events.emit(BID_WON, MOCK_DATA.bidResponse); - - const result = JSON.parse(server.requests[0].requestBody); - expect(result).to.deep.equal({ - adunit: MOCK_DATA.adUnitCode, - code: MOCK_DATA.bidResponse.bidderCode, - cpm: MOCK_DATA.bidResponse.cpm, - ttr: MOCK_DATA.bidResponse.timeToRespond, - params: MOCK_DATA.bidResponse.params, - event: 'win', - site: MOCK_DATA.site - }); - - done(); - }); - - it('should handle the auction end event', function(done) { - events.emit(AUCTION_END, MOCK_DATA.auctionEnd); - - const result = JSON.parse(server.requests[0].requestBody); - expect(result).to.deep.equal(MOCK_DATA.expectedAuctionEndResponse); - - done(); - }); - }); -}); diff --git a/test/spec/modules/scatteredBidAdapter_spec.js b/test/spec/modules/scatteredBidAdapter_spec.js deleted file mode 100644 index 29ac828fc..000000000 --- a/test/spec/modules/scatteredBidAdapter_spec.js +++ /dev/null @@ -1,208 +0,0 @@ -import { spec, converter } from 'modules/scatteredBidAdapter.js'; -import { assert } from 'chai'; -import { config } from 'src/config.js'; -import { deepClone, mergeDeep } from '../../../src/utils.js'; -describe('Scattered adapter', function () { - describe('isBidRequestValid', function () { - // A valid bid - const validBid = { - bidder: 'scattered', - mediaTypes: { - banner: { - sizes: [[300, 250], [760, 400]] - } - }, - params: { - bidderDomain: 'https://prebid.scattered.eu', - test: 0 - } - }; - - // Because this valid bid is modified to create invalid bids in following tests we first check it. - // We must be sure it is a valid one, not to get false negatives. - it('should accept a valid bid', function () { - assert.isTrue(spec.isBidRequestValid(validBid)); - }); - - it('should skip if bidderDomain info is missing', function () { - const bid = deepClone(validBid); - - delete bid.params.bidderDomain; - assert.isFalse(spec.isBidRequestValid(bid)); - }); - - it('should expect at least one banner size', function () { - const bid = deepClone(validBid); - - delete bid.mediaTypes.banner; - assert.isFalse(spec.isBidRequestValid(bid)); - - // empty sizes array - bid.mediaTypes = { - banner: { - sizes: [] - } - }; - assert.isFalse(spec.isBidRequestValid(bid)); - }); - }); - - describe('buildRequests', function () { - let arrayOfValidBidRequests, validBidderRequest; - - beforeEach(function () { - arrayOfValidBidRequests = [{ - bidder: 'scattered', - params: { - bidderDomain: 'https://prebid.scattered.eu', - test: 0 - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [760, 400]] - }, - adUnitCode: 'test-div', - transactionId: '32d09c47-c6b8-40b0-9605-2e251a472ea4', - bidId: '21adc5d8765aa1', - bidderRequestId: '130728f7662afc', - auctionId: 'b4a45a23-8371-4d87-9308-39146b29ca32', - }, - }]; - - validBidderRequest = { - bidderCode: 'scattered', - auctionId: 'b4a45a23-8371-4d87-9308-39146b29ca32', - gdprConsent: { consentString: 'BOtmiBKOtmiBKABABAENAFAAAAACeAAA', gdprApplies: true }, - refererInfo: { - domain: 'localhost', - page: 'http://localhost:9999/integrationExamples/gpt/hello_world.html?pbjs_debug=true', - }, - ortb2: { - site: { - publisher: { - name: 'publisher1 INC.' - } - } - } - }; - }); - - it('should validate request format', function () { - const request = spec.buildRequests(arrayOfValidBidRequests, validBidderRequest); - assert.equal(request.method, 'POST'); - assert.deepEqual(request.options, { contentType: 'application/json' }); - assert.ok(request.data); - }); - - it('has the right fields filled', function () { - const request = spec.buildRequests(arrayOfValidBidRequests, validBidderRequest); - const bidderRequest = request.data; - assert.ok(bidderRequest.site); - assert.lengthOf(bidderRequest.imp, 1); - }); - - it('should configure the site object', function () { - const request = spec.buildRequests(arrayOfValidBidRequests, validBidderRequest); - const site = request.data.site; - assert.equal(site.publisher.name, validBidderRequest.ortb2.site.publisher.name) - }); - - it('should configure site with ortb2', function () { - const req = mergeDeep({}, validBidderRequest, { - ortb2: { - site: { - id: '876', - publisher: { - domain: 'publisher1.eu' - } - } - } - }); - - const request = spec.buildRequests(arrayOfValidBidRequests, req); - const site = request.data.site; - assert.deepEqual(site, { - id: '876', - publisher: { - domain: 'publisher1.eu', - name: 'publisher1 INC.' - } - }); - }); - - it('should send device info', function () { - it('should send info about device', function () { - config.setConfig({ - device: { w: 375, h: 273 } - }); - - const request = spec.buildRequests(arrayOfValidBidRequests, validBidderRequest); - - assert.equal(request.device.ua, navigator.userAgent); - assert.equal(request.device.w, 375); - assert.equal(request.device.h, 273); - }); - }) - }) -}) - -describe('interpretResponse', function () { - const serverResponse = { - body: { - id: 'b4a45a23-8371-4d87-9308-39146b29ca32', - bidid: '11111111-2222-2222-2222-333333333333', - cur: 'PLN', - seatbid: [{ - bid: [ - { - id: '234234-234234-234234', // bidder generated - impid: '123', - price: '34.2', - nurl: 'https://scattered.eu/nurl', - adm: '
{ - return getSlotConfigs(mediatypes || { banner: {} }, { - publisherId: PUBLISHER_ID, - adUnitId: ADUNIT_ID, - }); -}; - -describe('Seedtag Adapter', function () { - beforeEach(function () { - mockGpt.reset(); - }); - - afterEach(function () { - mockGpt.enable(); - }); - describe('isBidRequestValid method', function () { - describe('returns true', function () { - describe('when banner slot config has all mandatory params', () => { - it('should be valid', function () { - const isBidRequestValid = spec.isBidRequestValid( - createBannerSlotConfig() - ); - expect(isBidRequestValid).to.equal(true); - }); - - it('should be valid when has display and video mediatypes, and video context is outstream', - function () { - const isBidRequestValid = spec.isBidRequestValid( - createBannerSlotConfig({ - banner: {}, - video: { - context: 'outstream', - playerSize: [[600, 200]], - }, - }) - ); - expect(isBidRequestValid).to.equal(true); - } - ); - - it('should be valid when has only video mediatypes, and video context is outstream', - function () { - const isBidRequestValid = spec.isBidRequestValid( - createBannerSlotConfig({ - video: { - context: 'outstream', - playerSize: [[600, 200]], - }, - }) - ); - expect(isBidRequestValid).to.equal(true); - } - ); - it('should be valid when has display and video mediatypes, and video context is instream', - function () { - const isBidRequestValid = spec.isBidRequestValid( - createBannerSlotConfig({ - banner: {}, - video: { - context: 'instream', - playerSize: [[600, 200]], - }, - }) - ); - expect(isBidRequestValid).to.equal(false); - } - ); - it("shouldn't be valid when has display and video mediatypes, and video context is instream", - function () { - const isBidRequestValid = spec.isBidRequestValid( - createBannerSlotConfig({ - banner: {}, - video: { - context: 'instream', - playerSize: [[600, 200]], - }, - }) - ); - expect(isBidRequestValid).to.equal(false); - } - ); - }); - describe('when video slot has all mandatory params', function () { - it('should return true, when video context is instream', function () { - const slotConfig = createInStreamSlotConfig({ - video: { - context: 'instream', - playerSize: [[600, 200]], - }, - }); - const isBidRequestValid = spec.isBidRequestValid(slotConfig); - expect(isBidRequestValid).to.equal(true); - }); - it('should return false, when video context is instream and mediatype is video and banner', function () { - const slotConfig = createInStreamSlotConfig({ - video: { - context: 'instream', - playerSize: [[600, 200]], - }, - banner: {}, - }); - const isBidRequestValid = spec.isBidRequestValid(slotConfig); - expect(isBidRequestValid).to.equal(false); - }); - }); - }); - describe('returns false', function () { - describe('when params are not correct', function () { - function createSlotConfig(params) { - return getSlotConfigs({ banner: {} }, params); - } - it('does not have the PublisherToken.', function () { - const isBidRequestValid = spec.isBidRequestValid( - createSlotConfig({ - adUnitId: ADUNIT_ID, - }) - ); - expect(isBidRequestValid).to.equal(false); - }); - it('does not have the AdUnitId.', function () { - const isBidRequestValid = spec.isBidRequestValid( - createSlotConfig({ - publisherId: PUBLISHER_ID, - }) - ); - expect(isBidRequestValid).to.equal(false); - }); - }); - - describe('when video mediaType object is not correct', function () { - it('is a void object', function () { - const isBidRequestValid = spec.isBidRequestValid( - createInStreamSlotConfig({ video: {} }) - ); - expect(isBidRequestValid).to.equal(false); - }); - it('does not have playerSize.', function () { - const isBidRequestValid = spec.isBidRequestValid( - createInStreamSlotConfig({ video: { context: 'instream' } }) - ); - expect(isBidRequestValid).to.equal(false); - }); - - describe('order does not matter', function () { - it('when video is not the first slot', function () { - const isBidRequestValid = spec.isBidRequestValid( - createInStreamSlotConfig({ banner: {}, video: {} }) - ); - expect(isBidRequestValid).to.equal(false); - }); - it('when video is the first slot', function () { - const isBidRequestValid = spec.isBidRequestValid( - createInStreamSlotConfig({ video: {}, banner: {} }) - ); - expect(isBidRequestValid).to.equal(false); - }); - }); - }); - }); - }); - - describe('buildRequests method', function () { - const bidFloor = 0.60 - const bidderRequest = { - refererInfo: { page: 'referer' }, - timeout: 1000, - }; - const mandatoryDisplayParams = { - publisherId: PUBLISHER_ID, - adUnitId: ADUNIT_ID, - }; - const mandatoryVideoParams = { - publisherId: PUBLISHER_ID, - adUnitId: ADUNIT_ID, - }; - const validBidRequests = [ - getSlotConfigs({ banner: {} }, mandatoryDisplayParams), - getSlotConfigs( - { - video: { - context: 'instream', - playerSize: [[300, 200]], - mimes: ['video/mp4'], - }, - }, - mandatoryVideoParams - ), - ]; - validBidRequests[0].getFloor = () => ({ - currency: BIDFLOOR_CURRENCY, - floor: bidFloor - }) - - it('Url params should be correct ', function () { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://s.seedtag.com/c/hb/bid'); - }); - - it('Common data request should be correct', function () { - const now = Date.now(); - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.url).to.equal('referer'); - expect(data.publisherToken).to.equal('0000-0000-01'); - expect(typeof data.version).to.equal('string'); - expect( - ['fixed', 'mobile', 'unknown'].indexOf(data.connectionType) - ).to.be.above(-1); - expect(data.auctionStart).to.be.greaterThanOrEqual(now); - expect(data.ttfb).to.be.greaterThanOrEqual(0); - - expect(data.bidRequests[0].adUnitCode).to.equal(adUnitCode); - expect(data.bidRequests[0].gpid).to.equal('some-gpid'); - }); - - describe('GDPR params', function () { - describe('when there arent consent management platform', function () { - it('cmp should be false', function () { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.cmp).to.equal(false); - }); - }); - describe('when there are consent management platform', function () { - it('cmps should be true and ga should not sended, when gdprApplies is undefined', function () { - bidderRequest['gdprConsent'] = { - gdprApplies: undefined, - consentString: 'consentString', - }; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.cmp).to.equal(true); - expect(Object.keys(data).indexOf('data')).to.equal(-1); - expect(data.cd).to.equal('consentString'); - }); - it('cmps should be true and all gdpr parameters should be sended, when there are gdprApplies', function () { - bidderRequest['gdprConsent'] = { - gdprApplies: true, - consentString: 'consentString', - }; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.cmp).to.equal(true); - expect(data.ga).to.equal(true); - expect(data.cd).to.equal('consentString'); - }); - it('should expose gvlid', function () { - expect(spec.gvlid).to.equal(157); - }); - it('should handle uspConsent', function () { - const uspConsent = '1---'; - - bidderRequest['uspConsent'] = uspConsent; - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.uspConsent).to.exist; - expect(payload.uspConsent).to.equal(uspConsent); - }); - - it("shouldn't send uspConsent when not available", function () { - const uspConsent = undefined; - - bidderRequest['uspConsent'] = uspConsent; - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.uspConsent).to.not.exist; - }); - }); - }); - - describe('BidRequests params', function () { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - const bidRequests = data.bidRequests; - it('should request a Banner', function () { - const bannerBid = bidRequests[0]; - expect(bannerBid.id).to.equal('30b31c1838de1e'); - expect(bannerBid.transactionId).to.equal( - 'd704d006-0d6e-4a09-ad6c-179e7e758096' - ); - expect(bannerBid.supplyTypes[0]).to.equal('display'); - expect(bannerBid.adUnitId).to.equal('000000'); - expect(bannerBid.sizes[0][0]).to.equal(300); - expect(bannerBid.sizes[0][1]).to.equal(250); - expect(bannerBid.sizes[1][0]).to.equal(300); - expect(bannerBid.sizes[1][1]).to.equal(600); - expect(bannerBid.requestCount).to.equal(1); - }); - it('should request an InStream Video', function () { - const videoBid = bidRequests[1]; - expect(videoBid.id).to.equal('30b31c1838de1e'); - expect(videoBid.transactionId).to.equal( - 'd704d006-0d6e-4a09-ad6c-179e7e758096' - ); - expect(videoBid.supplyTypes[0]).to.equal('video'); - expect(videoBid.adUnitId).to.equal('000000'); - expect(videoBid.videoParams.mimes).to.eql(['video/mp4']); - expect(videoBid.videoParams.w).to.equal(300); - expect(videoBid.videoParams.h).to.equal(200); - expect(videoBid.sizes[0][0]).to.equal(300); - expect(videoBid.sizes[0][1]).to.equal(250); - expect(videoBid.sizes[1][0]).to.equal(300); - expect(videoBid.sizes[1][1]).to.equal(600); - expect(videoBid.requestCount).to.equal(1); - }); - - it('should have geom parameters if slot is available', function () { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - const bidRequests = data.bidRequests; - const bannerBid = bidRequests[0]; - - // on some CI, the DOM is not initialized, so we need to check if the slot is available - const slot = document.getElementById(adUnitCode) - if (slot) { - expect(bannerBid).to.have.property('geom') - - const params = [['width', 300], ['height', 250], ['top', 10], ['left', 20], ['scrollY', 0]] - params.forEach(([param, value]) => { - expect(bannerBid.geom).to.have.property(param) - expect(bannerBid.geom[param]).to.be.a('number') - expect(bannerBid.geom[param]).to.be.equal(value) - }) - - expect(bannerBid.geom).to.have.property('viewport') - const viewportParams = ['width', 'height'] - viewportParams.forEach(param => { - expect(bannerBid.geom.viewport).to.have.property(param) - expect(bannerBid.geom.viewport[param]).to.be.a('number') - }) - } else { - expect(bannerBid).to.not.have.property('geom') - } - }) - - it('should have bidfloor parameter if available', function () { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - const bidRequests = data.bidRequests; - - expect(bidRequests[0].bidFloor).to.be.equal(bidFloor) - expect(bidRequests[1]).not.to.have.property('bidFloor') - }) - - it('should not launch an exception when request a video with no playerSize', function () { - const validBidRequests = [ - getSlotConfigs( - { - video: { - context: 'instream', - playerSize: [], - }, - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - mandatoryVideoParams - ), - ]; - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - const bidRequests = data.bidRequests; - const firstBidRequest = bidRequests[0]; - - expect(firstBidRequest).to.not.have.property('videoParams') - }); - }); - - describe('COPPA param', function () { - it('should add COPPA param to payload when prebid config has parameter COPPA equal to true', function () { - config.setConfig({ coppa: true }); - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.coppa).to.equal(true); - }); - - it('should not add COPPA param to payload when prebid config has parameter COPPA equal to false', function () { - config.setConfig({ coppa: false }); - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.coppa).to.be.undefined; - }); - - it('should not add COPPA param to payload when prebid config has not parameter COPPA', function () { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.coppa).to.be.undefined; - }); - }); - describe('schain param', function () { - it('should add schain to payload when exposed on validBidRequest', function () { - // https://github.com/prebid/Prebid.js/blob/master/modules/schain.md#sample-code-for-passing-the-schain-object - const schain = { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'indirectseller.com', - sid: '00001', - hp: 1, - }, - - { - asi: 'indirectseller-2.com', - sid: '00002', - hp: 1, - }, - ], - }; - - // duplicate - const bidRequests = JSON.parse(JSON.stringify(validBidRequests)); - bidRequests[0].ortb2 = bidRequests[0].ortb2 || {}; - bidRequests[0].ortb2.source = bidRequests[0].ortb2.source || {}; - bidRequests[0].ortb2.source.ext = bidRequests[0].ortb2.source.ext || {}; - bidRequests[0].ortb2.source.ext.schain = schain; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - const payload = JSON.parse(request.data); - - expect(payload.schain).to.exist; - expect(payload.schain).to.deep.equal(schain); - }); - - it("shouldn't add schain to payload when not exposed", function () { - const request = spec.buildRequests(validBidRequests, bidderRequest); - - const payload = JSON.parse(request.data); - - expect(payload.schain).to.not.exist; - }); - }); - - describe('GPP param', function () { - it('should be added to payload when bidderRequest has gppConsent param', function () { - const gppConsent = { - gppString: 'someGppString', - applicableSections: [7] - } - bidderRequest['gppConsent'] = gppConsent - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.gppConsent).to.exist; - expect(data.gppConsent.gppString).to.equal(gppConsent.gppString); - expect(data.gppConsent.applicableSections[0]).to.equal(gppConsent.applicableSections[0]); - }); - - it('should be undefined on payload when bidderRequest has not gppConsent param', function () { - bidderRequest.gppConsent = undefined - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.gppConsent).to.be.undefined; - }); - - it('should be added to payload when bidderRequest has ortb2 param', function () { - const ortb2 = { - regs: { - gpp: 'someGppString', - gpp_sid: [7] - } - } - bidderRequest['gppConsent'] = undefined - bidderRequest['ortb2'] = ortb2; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.gppConsent).to.exist; - expect(data.gppConsent.gppString).to.equal(ortb2.regs.gpp); - expect(data.gppConsent.applicableSections[0]).to.equal(ortb2.regs.gpp_sid[0]); - }); - - it('should be added to payload when bidderRequest has neither gppConsent nor ortb2', function () { - bidderRequest['ortb2'] = undefined; - bidderRequest['gppConsent'] = undefined; - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.gppConsent).to.be.undefined; - }); - }); - - describe('User param', function () { - it('should be added to payload user data param when bidderRequest has ortb2 user info', function () { - var ortb2 = { - - user: { - - data: [ - { - ext: { - segtax: 601, - segclass: '4' - }, - segment: [ - { - id: '149' - } - ], - name: 'randomname' - } - - ] - } - } - bidderRequest['ortb2'] = ortb2 - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - - expect(data.user).to.exist; - expect(data.user.topics).to.exist; - expect(data.user.topics).to.be.an('array').that.is.not.empty; - expect(data.user.topics[0].ext).to.eql(ortb2.user.data[0].ext); - expect(data.user.topics[0].segment).to.eql(ortb2.user.data[0].segment); - expect(data.user.topics[0].name).to.eql(ortb2.user.data[0].name); - }) - - it('should be added to payload user eids param when validRequest has userId info', function () { - var userIdAsEids = [{ - source: 'sourceid', - uids: [{ - atype: 1, - id: 'randomId' - }] - }] - validBidRequests[0]['userIdAsEids'] = userIdAsEids - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - - expect(data.user).to.exist; - expect(data.user.eids).to.exist; - expect(data.user.eids).to.be.an('array').that.is.not.empty; - expect(data.user.eids).to.deep.equal(userIdAsEids); - }) - }); - - describe('Blocking params', function () { - it('should add bcat param to payload when bidderRequest has ortb2 bcat info', function () { - const blockedCategories = ['IAB1', 'IAB2'] - var ortb2 = { - bcat: blockedCategories - } - bidderRequest['ortb2'] = ortb2 - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.bcat).to.deep.equal(blockedCategories); - }); - - it('should add badv param to payload when bidderRequest has ortb2 badv info', function () { - const blockedAdvertisers = ['blocked.com'] - var ortb2 = { - badv: blockedAdvertisers - } - bidderRequest['ortb2'] = ortb2 - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.badv).to.deep.equal(blockedAdvertisers); - }); - - it('should not add bcat and badv params to payload when bidderRequest does not have ortb2 badv and bcat info', function () { - var ortb2 = {} - bidderRequest['ortb2'] = ortb2 - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.bcat).to.be.undefined; - expect(data.badv).to.be.undefined; - }); - }); - - describe('Site params', function () { - it('should add cat param to payload when bidderRequest has ortb2 site cat info', function () { - const siteCategories = ['1217', 'bsr004', '692'] - var ortb2 = { - site: { - cat: siteCategories - } - } - bidderRequest['ortb2'] = ortb2 - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.site.cat).to.deep.equal(siteCategories); - }); - - it('should add pagecat param to payload when bidderRequest has ortb2 site pagecat info', function () { - const pageCategories = ['1217', 'bsr004', '692'] - var ortb2 = { - site: { - pagecat: pageCategories - } - } - bidderRequest['ortb2'] = ortb2 - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.site.pagecat).to.deep.equal(pageCategories); - }); - - it('should add cattac param to payload when bidderRequest has ortb2 site cattax info', function () { - const taxonomy = 6 - var ortb2 = { - site: { - cattax: taxonomy - } - } - bidderRequest['ortb2'] = ortb2 - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.site.cattax).to.equal(taxonomy); - }); - - it('should not add site params to payload when bidderRequest does not have ortb2 site info', function () { - var ortb2 = {} - bidderRequest['ortb2'] = ortb2 - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.site.cattax).to.be.undefined; - expect(data.site.cat).to.be.undefined; - expect(data.site.pagecat).to.be.undefined; - }); - }); - - describe('device.sua param', function () { - it('should add device.sua param to payload when bidderRequest has ortb2 device.sua info', function () { - const sua = 1 - var ortb2 = { - device: { - sua: sua - } - } - bidderRequest['ortb2'] = ortb2 - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.sua).to.equal(sua); - }); - - it('should not add device.sua param to payload when bidderRequest does not have ortb2 device.sua info', function () { - var ortb2 = { - device: {} - } - bidderRequest['ortb2'] = ortb2 - - const request = spec.buildRequests(validBidRequests, bidderRequest); - const data = JSON.parse(request.data); - expect(data.sua).to.be.undefined; - }); - }); - }) - describe('interpret response method', function () { - it('should return a void array, when the server response are not correct.', function () { - const request = { data: JSON.stringify({}) }; - const serverResponse = { - body: {}, - }; - const bids = spec.interpretResponse(serverResponse, request); - expect(typeof bids).to.equal('object'); - expect(bids.length).to.equal(0); - }); - it('should return a void array, when the server response have no bids.', function () { - const request = { data: JSON.stringify({}) }; - const serverResponse = { body: { bids: [] } }; - const bids = spec.interpretResponse(serverResponse, request); - expect(typeof bids).to.equal('object'); - expect(bids.length).to.equal(0); - }); - describe('when the server response return a bid', function () { - describe('the bid is a banner', function () { - it('should return a banner bid', function () { - const request = { data: JSON.stringify({}) }; - const serverResponse = { - body: { - bids: [ - { - bidId: '2159a54dc2566f', - price: 0.5, - currency: 'USD', - content: 'content', - width: 728, - height: 90, - mediaType: 'display', - ttl: 360, - nurl: 'testurl.com/nurl', - adomain: ['advertiserdomain.com'], - }, - ], - cookieSync: { url: '' }, - }, - }; - const bids = spec.interpretResponse(serverResponse, request); - expect(bids.length).to.equal(1); - expect(bids[0].requestId).to.equal('2159a54dc2566f'); - expect(bids[0].cpm).to.equal(0.5); - expect(bids[0].width).to.equal(728); - expect(bids[0].height).to.equal(90); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[0].ad).to.equal('content'); - expect(bids[0].nurl).to.equal('testurl.com/nurl'); - expect(bids[0].meta.advertiserDomains).to.deep.equal([ - 'advertiserdomain.com', - ]); - }); - }); - describe('the bid is a video', function () { - it('should return a instream bid', function () { - const request = { data: JSON.stringify({}) }; - const serverResponse = { - body: { - bids: [ - { - bidId: '2159a54dc2566f', - price: 0.5, - currency: 'USD', - content: 'content', - width: 728, - height: 90, - mediaType: 'video', - ttl: 360, - nurl: undefined, - }, - ], - cookieSync: { url: '' }, - }, - }; - const bids = spec.interpretResponse(serverResponse, request); - expect(bids.length).to.equal(1); - expect(bids[0].requestId).to.equal('2159a54dc2566f'); - expect(bids[0].cpm).to.equal(0.5); - expect(bids[0].width).to.equal(728); - expect(bids[0].height).to.equal(90); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[0].vastXml).to.equal('content'); - expect(bids[0].meta.advertiserDomains).to.deep.equal([]); - }); - }); - describe('the bid is a banner but the content is a video or display (video)', function () { - it('should return a banner bid with right meta.mediaType', function () { - const request = { data: JSON.stringify({}) }; - const serverResponse = { - body: { - bids: [ - { - bidId: '2159a54dc2566f', - price: 0.5, - currency: 'USD', - content: 'content', - width: 728, - height: 90, - mediaType: 'display', - ttl: 360, - nurl: 'testurl.com/nurl', - adomain: ['advertiserdomain.com'], - realMediaType: 'video' - }, - ], - cookieSync: { url: '' }, - }, - }; - const bids = spec.interpretResponse(serverResponse, request); - expect(bids.length).to.equal(1); - expect(bids[0].meta.mediaType).to.deep.equal('video'); - }); - it('should return a banner bid with right meta.mediaType (display)', function () { - const request = { data: JSON.stringify({}) }; - const serverResponse = { - body: { - bids: [ - { - bidId: '2159a54dc2566f', - price: 0.5, - currency: 'USD', - content: 'content', - width: 728, - height: 90, - mediaType: 'display', - ttl: 360, - nurl: 'testurl.com/nurl', - adomain: ['advertiserdomain.com'], - realMediaType: 'banner' - }, - ], - cookieSync: { url: '' }, - }, - }; - const bids = spec.interpretResponse(serverResponse, request); - expect(bids.length).to.equal(1); - expect(bids[0].meta.mediaType).to.deep.equal('banner'); - }); - }); - }); - }); - - describe('user syncs method', function () { - it('should return empty array, when iframe sync option are disabled.', function () { - const syncOption = { iframeEnabled: false }; - const serverResponses = [{ body: { cookieSync: 'someUrl' } }]; - const cookieSyncArray = spec.getUserSyncs(syncOption, serverResponses); - expect(cookieSyncArray.length).to.equal(0); - }); - it('should return empty array, when the server response are wrong.', function () { - const syncOption = { iframeEnabled: true }; - const serverResponses = [{ body: {} }]; - const cookieSyncArray = spec.getUserSyncs(syncOption, serverResponses); - expect(cookieSyncArray.length).to.equal(0); - }); - it('should return empty array, when the server response are void.', function () { - const syncOption = { iframeEnabled: true }; - const serverResponses = [{ body: { cookieSync: '' } }]; - const cookieSyncArray = spec.getUserSyncs(syncOption, serverResponses); - expect(cookieSyncArray.length).to.equal(0); - }); - it('should return a array with the cookie sync, when the server response with a cookie sync.', function () { - const syncOption = { iframeEnabled: true }; - const serverResponses = [{ body: { cookieSync: 'someUrl' } }]; - const cookieSyncArray = spec.getUserSyncs(syncOption, serverResponses); - expect(cookieSyncArray.length).to.equal(1); - expect(cookieSyncArray[0].type).to.equal('iframe'); - expect(cookieSyncArray[0].url).to.equal('someUrl'); - }); - }); - - describe('onTimeout', function () { - beforeEach(function () { - sinon.stub(utils, 'triggerPixel'); - }); - - afterEach(function () { - utils.triggerPixel.restore(); - }); - - it('should return the correct endpoint', function () { - const params = { publisherId: '0000', adUnitId: '11111' }; - const timeout = 3000; - const timeoutData = [{ params: [params], timeout }]; - const timeoutUrl = getTimeoutUrl(timeoutData); - expect(timeoutUrl).to.equal( - 'https://s.seedtag.com/se/hb/timeout?publisherToken=' + - params.publisherId + - '&adUnitId=' + - params.adUnitId + - '&timeout=' + - timeout - ); - }); - - it('should set the timeout pixel', function () { - const params = { publisherId: '0000', adUnitId: '11111' }; - const timeout = 3000; - const timeoutData = [{ params: [params], timeout }]; - spec.onTimeout(timeoutData); - expect( - utils.triggerPixel.calledWith( - 'https://s.seedtag.com/se/hb/timeout?publisherToken=' + - params.publisherId + - '&adUnitId=' + - params.adUnitId + - '&timeout=' + - timeout - ) - ).to.equal(true); - }); - }); - - describe('onBidWon', function () { - beforeEach(function () { - sinon.stub(utils, 'triggerPixel'); - }); - - afterEach(function () { - utils.triggerPixel.restore(); - }); - - describe('without nurl', function () { - const bid = {}; - - it('does not create pixel ', function () { - spec.onBidWon(bid); - expect(utils.triggerPixel.called).to.equal(false); - }); - }); - - describe('with nurl', function () { - const nurl = 'http://seedtag_domain/won'; - const bid = { nurl }; - - it('creates nurl pixel if bid nurl', function () { - spec.onBidWon({ nurl }); - expect(utils.triggerPixel.calledWith(nurl)).to.equal(true); - }); - }); - }); -}); diff --git a/test/spec/modules/semantiqRtdProvider_spec.js b/test/spec/modules/semantiqRtdProvider_spec.js deleted file mode 100644 index 49abc6c23..000000000 --- a/test/spec/modules/semantiqRtdProvider_spec.js +++ /dev/null @@ -1,441 +0,0 @@ -import { convertSemantiqKeywordToOrtb, getOrtbKeywords, semantiqRtdSubmodule, storage } from '../../../modules/semantiqRtdProvider.js'; -import { expect } from 'chai'; -import { server } from '../../mocks/xhr.js'; -import * as utils from '../../../src/utils.js'; - -describe('semantiqRtdProvider', () => { - let clock; - let getDataFromLocalStorageStub; - let getWindowLocationStub; - - beforeEach(() => { - clock = sinon.useFakeTimers(); - getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage').returns(null); - getWindowLocationStub = sinon.stub(utils, 'getWindowLocation').returns(new URL('https://example.com/article')); - }); - - afterEach(() => { - clock.restore(); - getDataFromLocalStorageStub.restore(); - getWindowLocationStub.restore(); - }); - - describe('init', () => { - it('returns true on initialization', () => { - const initResult = semantiqRtdSubmodule.init({}); - expect(initResult).to.be.true; - }); - }); - - describe('pageImpression event', () => { - it('dispatches an event on initialization', () => { - getWindowLocationStub.returns(new URL('https://example.com/article')); - - semantiqRtdSubmodule.init({ params: { companyId: 5 } }); - - const body = JSON.parse(server.requests[0].requestBody); - - expect(server.requests[0].url).to.be.equal('https://api.adnz.co/api/ws-clickstream-collector/submit'); - expect(server.requests[0].method).to.be.equal('POST'); - - expect(body.company_id).to.be.equal(5); - expect(body.event_id).not.to.be.empty; - expect(body.event_timestamp).not.to.be.empty; - expect(body.event_type).to.be.equal('pageImpression'); - expect(body.page_impression_id).not.to.be.empty; - expect(body.source).to.be.equal('semantiqPrebidModule'); - expect(body.url).to.be.equal('https://example.com/article'); - }); - - it('uses the correct company ID', () => { - semantiqRtdSubmodule.init({ params: { companyId: 555 } }); - semantiqRtdSubmodule.init({ params: { companyId: [111, 222, 333] } }); - - const body1 = JSON.parse(server.requests[0].requestBody); - const body2 = JSON.parse(server.requests[1].requestBody); - - expect(body1.company_id).to.be.equal(555); - expect(body2.company_id).to.be.equal(111); - }); - - it('uses cached page impression ID if present', () => { - window.audienzz = { collectorPageImpressionId: 'cached-guid' }; - semantiqRtdSubmodule.init({ params: { companyId: 5 } }); - - const body = JSON.parse(server.requests[0].requestBody); - - expect(body.page_impression_id).to.be.equal('cached-guid'); - }); - }); - - describe('convertSemantiqKeywordToOrtb', () => { - it('converts SemantIQ keywords properly', () => { - expect(convertSemantiqKeywordToOrtb('foo', 'bar')).to.be.equal('foo=bar'); - expect(convertSemantiqKeywordToOrtb('foo', ['bar', 'baz'])).to.be.equal('foo=bar,foo=baz'); - }); - - it('returns an empty string if keyword value is empty', () => { - expect(convertSemantiqKeywordToOrtb('foo', '')).to.be.equal(''); - expect(convertSemantiqKeywordToOrtb('foo', [])).to.be.equal(''); - }); - }); - - describe('getOrtbKeywords', () => { - it('returns an empty string if no keywords are provided', () => { - expect(getOrtbKeywords({})).to.be.equal(''); - }); - - it('converts keywords to ORTB format', () => { - expect(getOrtbKeywords({ foo: 'bar', fizz: ['buzz', 'quz'] })).to.be.equal('foo=bar,fizz=buzz,fizz=quz'); - }); - - it('ignores keywords with no value', () => { - expect(getOrtbKeywords({ foo: 'bar', fizz: ['buzz', 'quz'], baz: '', xyz: [], quz: undefined, buzz: null })).to.be.equal('foo=bar,fizz=buzz,fizz=quz'); - }); - }); - - describe('getBidRequestData', () => { - it('requests data with correct parameters', async () => { - const reqBidsConfigObj = { - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - }; - - semantiqRtdSubmodule.getBidRequestData( - reqBidsConfigObj, - () => undefined, - { params: {} }, - {} - ); - - server.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({}) - ); - - const requestUrl = new URL(server.requests[0].url); - - expect(requestUrl.host).to.be.equal('api.adnz.co'); - expect(requestUrl.searchParams.get('url')).to.be.equal('https://example.com/article'); - expect(requestUrl.searchParams.get('tenantIds')).to.be.equal('1'); - }); - - it('allows to specify company ID as a parameter', async () => { - const reqBidsConfigObj = { - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - }; - - const onDoneSpy = sinon.spy(); - - const promise = new Promise((resolve) => semantiqRtdSubmodule.getBidRequestData( - reqBidsConfigObj, - () => { - onDoneSpy(); - resolve(); - }, - { params: { companyId: 13 } }, - {} - )); - - server.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({}) - ); - - await promise; - - const requestUrl = new URL(server.requests[0].url); - - expect(requestUrl.searchParams.get('tenantIds')).to.be.equal('13'); - }); - - it('allows to specify multiple company IDs as a parameter', async () => { - const reqBidsConfigObj = { - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - }; - - const onDoneSpy = sinon.spy(); - - const promise = new Promise((resolve) => semantiqRtdSubmodule.getBidRequestData( - reqBidsConfigObj, - () => { - onDoneSpy(); - resolve(); - }, - { params: { companyId: [13, 23] } }, - {} - )); - - server.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({}) - ); - - await promise; - - const requestUrl = new URL(server.requests[0].url); - - expect(requestUrl.searchParams.get('tenantIds')).to.be.equal('13,23'); - }); - - it('gets keywords from the cache if the data is present in the storage', async () => { - getDataFromLocalStorageStub.returns(JSON.stringify({ url: 'https://example.com/article', keywords: { sentiment: 'negative', ctx_segment: ['C001', 'C002'] } })); - - const reqBidsConfigObj = { - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - ortb2Fragments: { - global: {}, - } - }; - - const onDoneSpy = sinon.spy(); - - const promise = new Promise((resolve) => semantiqRtdSubmodule.getBidRequestData( - reqBidsConfigObj, - () => { - onDoneSpy(); - resolve(); - }, - { params: {} }, - {} - )); - - await promise; - - expect(onDoneSpy.calledOnce).to.be.true; - expect(server.requests).to.have.lengthOf(0); - expect(reqBidsConfigObj.ortb2Fragments.global).to.deep.equal({ site: { keywords: 'sentiment=negative,ctx_segment=C001,ctx_segment=C002' } }); - }); - - it('requests keywords from the server if the URL of the page is different from the cached one', async () => { - getDataFromLocalStorageStub.returns(JSON.stringify({ url: 'https://example.com/article', keywords: { cached: 'true' } })); - getWindowLocationStub.returns(new URL('https://example.com/another-article')); - - const reqBidsConfigObj = { - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - ortb2Fragments: { - global: {}, - } - }; - - const onDoneSpy = sinon.spy(); - - const promise = new Promise((resolve) => semantiqRtdSubmodule.getBidRequestData( - reqBidsConfigObj, - () => { - onDoneSpy(); - resolve(); - }, - { params: {} }, - {} - )); - - server.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ server: 'true' }) - ); - - await promise; - - expect(onDoneSpy.calledOnce).to.be.true; - expect(reqBidsConfigObj.ortb2Fragments.global).to.deep.equal({ site: { keywords: 'server=true' } }); - }); - - it('requests keywords from the server if the cached data is missing in the storage', async () => { - const reqBidsConfigObj = { - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - ortb2Fragments: { - global: {}, - }, - }; - - const onDoneSpy = sinon.spy(); - - const promise = new Promise((resolve) => semantiqRtdSubmodule.getBidRequestData( - reqBidsConfigObj, - () => { - onDoneSpy(); - resolve(); - }, - { params: {} }, - {} - )); - - server.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ sentiment: 'negative', ctx_segment: ['C001', 'C002'] }) - ); - - await promise; - - expect(onDoneSpy.calledOnce).to.be.true; - expect(reqBidsConfigObj.ortb2Fragments.global).to.deep.equal({ site: { keywords: 'sentiment=negative,ctx_segment=C001,ctx_segment=C002' } }); - }); - - it('merges ORTB site keywords if they are present', async () => { - const reqBidsConfigObj = { - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - ortb2Fragments: { - global: { - site: { - keywords: 'iab_category=politics', - } - }, - }, - }; - - const onDoneSpy = sinon.spy(); - - const promise = new Promise((resolve) => semantiqRtdSubmodule.getBidRequestData( - reqBidsConfigObj, - () => { - onDoneSpy(); - resolve(); - }, - { params: {} }, - {} - )); - - server.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - JSON.stringify({ sentiment: 'negative', ctx_segment: ['C001', 'C002'] }) - ); - - await promise; - - expect(onDoneSpy.calledOnce).to.be.true; - expect(reqBidsConfigObj.ortb2Fragments.global).to.deep.equal({ site: { keywords: 'iab_category=politics,sentiment=negative,ctx_segment=C001,ctx_segment=C002' } }); - }); - - it("won't modify ortb2 if if no ad units are provided", async () => { - const reqBidsConfigObj = { - adUnits: [], - ortb2Fragments: {} - }; - - const onDoneSpy = sinon.spy(); - - semantiqRtdSubmodule.getBidRequestData(reqBidsConfigObj, onDoneSpy, { params: {} }, {}); - - expect(onDoneSpy.calledOnce).to.be.true; - expect(reqBidsConfigObj).to.deep.equal({ - adUnits: [], - ortb2Fragments: {} - }); - }); - - it("won't modify ortb2 if response is broken", async () => { - const reqBidsConfigObj = { - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - ortb2Fragments: {} - }; - const onDoneSpy = sinon.spy(); - - const promise = new Promise((resolve) => { - semantiqRtdSubmodule.getBidRequestData(reqBidsConfigObj, () => { - onDoneSpy(); - resolve(); - }, { params: {} }, {}); - }); - - server.requests[0].respond( - 200, - { 'Content-Type': 'application/json' }, - '{' - ); - - await promise; - - expect(onDoneSpy.calledOnce).to.be.true; - expect(reqBidsConfigObj).to.deep.equal({ - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - ortb2Fragments: {} - }); - }); - - it("won't modify ortb2 if response status is not 200", async () => { - const reqBidsConfigObj = { - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - ortb2Fragments: {} - }; - const onDoneSpy = sinon.spy(); - - const promise = new Promise((resolve) => { - semantiqRtdSubmodule.getBidRequestData(reqBidsConfigObj, () => { - onDoneSpy(); - resolve(); - }, { params: {} }, {}); - }); - - server.requests[0].respond( - 204, - { 'Content-Type': 'application/json' }, - ); - - await promise; - - expect(onDoneSpy.calledOnce).to.be.true; - expect(reqBidsConfigObj).to.deep.equal({ - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - ortb2Fragments: {} - }); - }); - - it("won't modify ortb2 if an error occurs during the request", async () => { - const reqBidsConfigObj = { - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - ortb2Fragments: {} - }; - const onDoneSpy = sinon.spy(); - - const promise = new Promise((resolve) => { - semantiqRtdSubmodule.getBidRequestData(reqBidsConfigObj, () => { - onDoneSpy(); - resolve(); - }, { params: {} }, {}); - }); - - server.requests[0].respond( - 500, - { 'Content-Type': 'application/json' }, - '{}' - ); - - await promise; - - expect(onDoneSpy.calledOnce).to.be.true; - expect(reqBidsConfigObj).to.deep.equal({ - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - ortb2Fragments: {}, - }); - }); - - it("won't modify ortb2 if response time hits timeout", async () => { - const reqBidsConfigObj = { - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - ortb2Fragments: {}, - }; - const onDoneSpy = sinon.spy(); - - const promise = new Promise((resolve) => semantiqRtdSubmodule.getBidRequestData(reqBidsConfigObj, () => { - onDoneSpy(); - resolve(); - }, { params: { timeout: 500 } }, {})); - - clock.tick(510); - - await promise; - - expect(onDoneSpy.calledOnce).to.be.true; - expect(reqBidsConfigObj).to.deep.equal({ - adUnits: [{ bids: [{ bidder: 'appnexus' }] }], - ortb2Fragments: {}, - }); - }); - }); -}); diff --git a/test/spec/modules/setupadBidAdapter_spec.js b/test/spec/modules/setupadBidAdapter_spec.js deleted file mode 100644 index 0448ee8d2..000000000 --- a/test/spec/modules/setupadBidAdapter_spec.js +++ /dev/null @@ -1,390 +0,0 @@ -import { spec, biddersCreativeIds } from 'modules/setupadBidAdapter.js'; - -describe('SetupadAdapter', function () { - const userIdAsEids = [ - { - source: 'pubcid.org', - uids: [ - { - atype: 1, - id: '01EAJWWNEPN3CYMM5N8M5VXY22', - }, - ], - }, - ]; - - const bidRequests = [ - { - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f461', - bidder: 'rubicon', - bidderRequestId: '15246a574e859f', - uspConsent: 'usp-context-string', - gdprConsent: { - consentString: 'BOtmiBKOtmiBKABABAENAFAAAAACeAAA', - gdprApplies: true, - }, - params: { - placement_id: '123', - account_id: 'test-account-id', - }, - sizes: [[300, 250]], - ortb2: { - device: { - w: 1500, - h: 1000, - }, - site: { - domain: 'test.com', - page: 'http://test.com', - }, - }, - userIdAsEids, - }, - { - adUnitCode: 'test-div-2', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f461', - bidder: 'rubicon', - bidderRequestId: '15246a574e859f', - uspConsent: 'usp-context-string', - gdprConsent: { - consentString: 'BOtmiBKOtmiBKABABAENAFAAAAACeAAA', - gdprApplies: true, - }, - params: { - placement_id: '123', - account_id: 'test-account-id', - }, - sizes: [[300, 250]], - ortb2: { - device: { - w: 1500, - h: 1000, - }, - site: { - domain: 'test.com', - page: 'http://test.com', - }, - }, - userIdAsEids, - }, - ]; - - const bidderRequest = { - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - auctionStart: 1579746300522, - bidderCode: 'setupad', - bidderRequestId: '15246a574e859f', - bids: [ - { - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f461', - bidder: 'rubicon', - bidderRequestId: '15246a574e859f', - uspConsent: 'usp-context-string', - gdprConsent: { - consentString: 'BOtmiBKOtmiBKABABAENAFAAAAACeAAA', - gdprApplies: true, - }, - params: { - placement_id: '123', - account_id: 'test-account-id', - }, - sizes: [[300, 250]], - ortb2: { - device: { - w: 1500, - h: 1000, - }, - site: { - domain: 'test.com', - page: 'http://test.com', - }, - }, - userIdAsEids, - }, - { - adUnitCode: 'test-div-2', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '22c4871113f461', - bidder: 'rubicon', - bidderRequestId: '15246a574e859f', - uspConsent: 'usp-context-string', - gdprConsent: { - consentString: 'BOtmiBKOtmiBKABABAENAFAAAAACeAAA', - gdprApplies: true, - }, - params: { - placement_id: '123', - account_id: 'test-account-id', - }, - sizes: [[300, 250]], - ortb2: { - device: { - w: 1500, - h: 1000, - }, - site: { - domain: 'test.com', - page: 'http://test.com', - }, - }, - userIdAsEids, - }, - ], - gdprConsent: { - consentString: 'BOtmiBKOtmiBKABABAENAFAAAAACeAAA', - vendorData: {}, - gdprApplies: true, - }, - ortb2: { - device: { - w: 1500, - h: 1000, - }, - }, - refererInfo: { - canonicalUrl: null, - domain: 'test.com', - page: 'http://test.com', - referer: null, - }, - }; - - const serverResponse = { - body: { - seatbid: [ - { - bid: [{ crid: 123 }, { crid: 1234 }], - seat: 'pubmatic', - }, - { - bid: [{ crid: 12345 }], - seat: 'setupad', - }, - ], - }, - testCase: 1, - }; - - describe('isBidRequestValid', function () { - const bid = { - bidder: 'setupad', - params: { - placement_id: '123', - account_id: '123', - }, - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when placement_id is missing', function () { - const bidWithoutPlacementId = { ...bid }; - delete bidWithoutPlacementId.params.placement_id; - expect(spec.isBidRequestValid(bidWithoutPlacementId)).to.equal(false); - }); - - it('should return false when account_id is missing', function () { - const bidWithoutAccountId = { ...bid }; - delete bidWithoutAccountId.params.account_id; - expect(spec.isBidRequestValid(bidWithoutAccountId)).to.equal(false); - }); - - it('should return false when required params are not passed', function () { - delete bid.params.placement_id; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('should return correct storedrequest id for bids if placement_id is provided', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.imp[0].ext.prebid.storedrequest.id).to.equal('123'); - }); - - it('should return correct storedrequest id if account_id is provided', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.ext.prebid.storedrequest.id).to.equal('test-account-id'); - }); - - it('should return setupad custom adapter param', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.setupad).to.equal('adapter'); - }); - - // Change this to 1 whenever TEST_REQUEST = 1. This is allowed only for testing requests locally - it('should return correct test attribute value from global value', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.test).to.equal(0); - }); - }); - - describe('getUserSyncs', () => { - it('should return user sync', () => { - const syncOptions = { - iframeEnabled: true, - pixelEnabled: true, - }; - const responses = [ - { - body: { - ext: { - responsetimemillis: { - 'test seat 1': 2, - 'test seat 2': 1, - }, - }, - }, - }, - ]; - const gdprConsent = { - gdprApplies: 1, - consentString: 'dkj49Sjmfjuj34as:12jaf90123hufabidfy9u23brfpoig', - }; - const uspConsent = 'mkjvbiniwot4827obfoy8sdg8203gb'; - const expectedUserSyncs = [ - { - type: 'iframe', - url: 'https://cookie.stpd.cloud/sync?bidders=%5B%22test%20seat%201%22%2C%22test%20seat%202%22%5D&gdpr=1&gdpr_consent=dkj49Sjmfjuj34as:12jaf90123hufabidfy9u23brfpoig&usp_consent=mkjvbiniwot4827obfoy8sdg8203gb&type=iframe', - }, - ]; - - const userSyncs = spec.getUserSyncs(syncOptions, responses, gdprConsent, uspConsent); - - expect(userSyncs).to.deep.equal(expectedUserSyncs); - }); - - it('should return empty user syncs when responsetimemillis is not defined', () => { - const syncOptions = { - iframeEnabled: true, - pixelEnabled: true, - }; - const responses = [ - { - body: { - ext: {}, - }, - }, - ]; - const gdprConsent = { - gdprApplies: 1, - consentString: 'dkj49Sjmfjuj34as:12jaf90123hufabidfy9u23brfpoig', - }; - const uspConsent = 'mkjvbiniwot4827obfoy8sdg8203gb'; - const expectedUserSyncs = []; - - const userSyncs = spec.getUserSyncs(syncOptions, responses, gdprConsent, uspConsent); - - expect(userSyncs).to.deep.equal(expectedUserSyncs); - }); - }); - - describe('interpretResponse', function () { - it('should return empty array if error during parsing', () => { - const wrongServerResponse = 'wrong data'; - const request = spec.buildRequests(bidRequests, bidderRequest); - const result = spec.interpretResponse(wrongServerResponse, request); - - expect(result).to.be.instanceof(Array); - expect(result.length).to.equal(0); - }); - - it('should update biddersCreativeIds correctly', function () { - spec.interpretResponse(serverResponse, bidderRequest); - - expect(biddersCreativeIds).to.deep.equal({ - 123: 'pubmatic', - 1234: 'pubmatic', - 12345: 'setupad', - }); - }); - }); - - describe('onBidWon', function () { - it('should stop if bidder is not equal to BIDDER_CODE', function () { - const bid = { - bidder: 'rubicon', - }; - const result = spec.onBidWon(bid); - expect(result).to.be.undefined; - }); - - it('should stop if bid.params is not provided', function () { - const bid = { - bidder: 'setupad', - }; - const result = spec.onBidWon(bid); - expect(result).to.be.undefined; - }); - - it('should stop if bid.params is empty array', function () { - const bid = { - bidder: 'setupad', - params: [], - }; - const result = spec.onBidWon(bid); - expect(result).to.be.undefined; - }); - - it('should stop if bid.params is not array', function () { - expect( - spec.onBidWon({ - bidder: 'setupad', - params: {}, - }) - ).to.be.undefined; - - expect( - spec.onBidWon({ - bidder: 'setupad', - params: 'test', - }) - ).to.be.undefined; - - expect( - spec.onBidWon({ - bidder: 'setupad', - params: 1, - }) - ).to.be.undefined; - - expect( - spec.onBidWon({ - bidder: 'setupad', - params: null, - }) - ).to.be.undefined; - - expect( - spec.onBidWon({ - bidder: 'setupad', - params: undefined, - }) - ).to.be.undefined; - }); - - it('should stop if bid.params.placement_id is not provided', function () { - const bid = { - bidder: 'setupad', - params: [{ account_id: 'test' }], - }; - const result = spec.onBidWon(bid); - expect(result).to.be.undefined; - }); - - it('should stop if bid.params is not provided and bid.bids is not an array', function () { - const bid = { - bidder: 'setupad', - params: undefined, - bids: {}, - }; - const result = spec.onBidWon(bid); - expect(result).to.be.undefined; - }); - }); -}); diff --git a/test/spec/modules/sevioBidAdapter_spec.js b/test/spec/modules/sevioBidAdapter_spec.js deleted file mode 100644 index 60c66870e..000000000 --- a/test/spec/modules/sevioBidAdapter_spec.js +++ /dev/null @@ -1,209 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/sevioBidAdapter.js'; - -const ENDPOINT_URL = 'https://req.adx.ws/prebid'; - -describe('sevioBidAdapter', function () { - describe('isBidRequestValid', function () { - let bid = { - 'bidder': 'sevio', - 'params': { - zone: 'zoneId' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[728, 90]] - } - }, - 'adUnitCode': 'adunit-code', - 'bidId': '1234asdf1234', - 'bidderRequestId': '1234asdf1234asdf', - 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf120' - }; - it('should return true where required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - - describe('buildRequests', function () { - let bidRequests = [ - { - 'bidder': 'sevio', - 'params': { - zone: 'zoneId' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[728, 90]] - } - }, - 'bidId': '3e16f4cbbca2b', - 'bidderRequestId': '2d0e47e3ddc744', - 'auctionId': 'fb56cc83-bc64-4c44-a9b8-34fec672b592', - }, - { - 'bidder': 'sevio', - 'params': { - zone: 'zoneId' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[728, 90]] - } - }, - 'adUnitCode': 'adunit-sevio-2nd', - 'bidId': '3a7e104573c543"', - 'bidderRequestId': '250799bbf223c6', - 'auctionId': '0b29430c-b25f-487a-b90c-68697a01f4e6', - } - ]; - - let bidderRequests = { - 'refererInfo': { - 'numIframes': 0, - 'reachedTop': true, - 'referer': 'https://example.com', - 'stack': ['https://example.com'] - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequests); - it('sends bid request to our endpoint via POST', function () { - expect(request[0].method).to.equal('POST'); - expect(request[1].method).to.equal('POST'); - }); - it('attaches source and version to endpoint URL as query params', function () { - expect(request[0].url).to.equal(ENDPOINT_URL); - expect(request[1].url).to.equal(ENDPOINT_URL); - }); - }); - - describe('interpretResponse', function () { - let bidRequest = [ - { - 'method': 'POST', - 'url': ENDPOINT_URL, - 'data': { - 'zone': 'zoneId', - 'width': '728', - 'height': '90', - 'bidId': 'bidId123', - 'referer': 'www.example.com' - } - } - ]; - let serverResponse = { - body: { - "bids": [ - { - "requestId": "3e16f4cbbca2b", - "cpm": 5.0, - "currency": "EUR", - "width": 728, - "height": 90, - "creativeId": "b38d1ea7-36ea-410a-801a-0673b8ed8201", - "ad": "

I am an ad

", - "ttl": 300, - "netRevenue": false, - "mediaType": "BANNER", - "meta": { - "advertiserDomains": [ - "none.com" - ] - } - } - ], - "userSyncs": [ - { - "url": "https://example.com/dmp/profile/?pid=12718&sg=SEVIO_CGE", - "type": "image" - } - ] - } - }; - it('should get the correct bid response', function () { - let expectedResponse = [{ - 'requestId': '3e16f4cbbca2b', - 'cpm': 5.0, - 'width': 728, - 'height': 90, - 'creativeId': 'b38d1ea7-36ea-410a-801a-0673b8ed8201', - 'currency': 'EUR', - 'netRevenue': true, - 'ttl': 3000, - 'ad': '

I am an ad

', - 'mediaType': 'banner', - 'meta': {'advertiserDomains': ['none.com']} - }]; - let result = spec.interpretResponse(serverResponse, bidRequest[0]); - - expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponse)); - }); - - it('should get the correct bid response for the native case', function () { - let expectedResponseNative = [{ - requestId: '36e835f6cbfca38', - cpm: 5, - currency: 'EUR', - width: 1, - height: 1, - creativeId: '28cf46ce-fe57-4417-acd6-285db604aa30', - ad: '{"ver":"1.2","assets":[{"id":1,"img":{"type":3,"url":"https://delivery.targetblankdev.com/bc42a192-9413-458b-ad88-f93ce023eacb/native/assets/4336011f-2076-4122-acb9-60f0478311eb/28cf46ce-fe57-4417-acd6-285db604aa30/552e9483-5ba6-46ed-b014-c61e80d8f9d1.png"}},{"id":2,"title":{"text":"TestAdNative","len":12}},{"id":4,"data":{"type":2,"value":"Test Ad Native"}}],"link":{"url":"https://work.targetblankdev.com/ad-server-e?data=o4rIvHAEkHlT9_ItFWCiBfQDNUkLHzkjLF9uPkIArQZiqBg_bWdNjmhGDU96MmBAI3UURTDIZ4CuqYA90CazeB7gVUwZboKeJXp8MIMiLQEzxaUQh6qsFjBoVFbn6H0qq7neZUEX82NuPcgwNzsThJnING6uFzUUCrlgAGncJQc68DMldAFqxTrgsSHpAhyF00-LCUF1eblyoT03R6RWIEpBl1O85VE9MeRPV5BHDaIjYVT7wWUSLXa40_mr_tUpFST6oDwVEFldoYQruwm07gjxLLLjnymoj9QXUuSTgGYwPFwW6wqG0p67xaGuGNB8J08AUweUujghsXHf_iSbkqfhO1LilHa_YrZ0UXzZSjRRWOX_sPVLs6Wta4RsEl3KMKVsVlgSLV6j0Okbw2cP6GztzMbURlz2C3jX2veaOsKxvajdqU5U1VLPYaRBAp-RDhuGKTbBHTe83bqgvgwebcEzcqQk-gAAAAA&integrity=3Yj4qCKUgBQPCshcNy2FPHD3Upsj8M5GOQ8E4ORetqI"},"eventtrackers":[{"event":1,"method":1,"url":"https://work.targetblankdev.com/ad-server-e?data=gS4Wtf5CrSPsZHjTBW1mDkQ1TP6aDOWpxpBQrUEfS4u8zrPxIBN1RFHJR5HdEKIKSdLjXZojo-lwz87xbP-ABPgD90lpjBeL-KOVOgvvwBy92VYCLZPvbsgYxJd_BFSiiz2UvwathNDkSsWChylm6t8sbIF62Qe540dhb3T1cI_Ben_qkgqrobPSHbAyBRKsje_twgWYf2TJFKsKmQYq5zSwgCnZKpMgZ0nFqUitx7DPjiZrGTFZxZ66J3ArskkREs6N0nPy4H5y2zFNepzAorp-pLONDHWSFkbQNzqNZqZgUJ_8XracHjL5_VDDwmz392xnx6_Kf1a6ezDRJyfp3k7ZJoGA5U4Wx5z4S7SelueaXZYgnHv--skg7P3pIXc7veM6nfXQD-GDmC0sDdrRgFbJCwCHBdkvurEcFASxIiBOaH8FOu2quxAth0dEoEHFpwKd_bJdAcXZFfUt4URDy43hQAQAAAAA&integrity=fP4SzYcSbOv8RbHcTT5xsC0fmeftmjv51PV_8G7-Wy0"},{"event":2,"method":1,"url":"https://work.targetblankdev.com/ad-server-e?data=PMO9Lc4-g0OGvzRglK8_72bWOZumt1Hgvy-ifNC3VT5iJ3PEBt1FD96vxr8w_Oy4E0BMXXHlDABkXelqcS6a1HJTdR8u-BncqZ8lycFkrVg9wMFNiorbpVxzpM5lgaj-uUEH7oYreDCXD_qK_5OzQaJp3rHgXjtyUZEaXimv6Bgu-hBeUYimezBT5Ba9IJJ1YDMdgdY-pFIU4ND1-kQN11KYTwikW37IWX-q8zZMwM3m78KsgKnY_OkJzy-0JJUeKkmRv7awNoBBOmhjmY7qHbDcVcwG5GQp4b0zJTm9bg6zHxIIYKsYqdQzXUjqL94rQ1M113QrGW9p9U11W0fSpX3VbHL0EtSrnoAo8d9xTjQ2nc5OsJOlDbYXakVO_GEiGtqK1kMUtBkQzjctCB_TyatPj_f7GZ-Vjuema9bTQUwKybco4Gmfu32GpsDKlPL4j3sMahH1W55zTrjOl2f4SkVyrXpTTpWS8Ifxl6Gq-xvYm7vixStI6gAAAAA&integrity=hDyA0PinLzMdhwKbV6BOJVTUn3xP9UQSDqf6JebKFhQ"}]}', - ttl: 300, - netRevenue: false, - mediaType: 'NATIVE', - meta: { - advertiserDomains: "example.com" - }, - bidder: 'sevio', - native: { - "image": "https://example.com/image.png", - "image_width": 0, - "image_height": 0, - "title": "TestAdNative", - "body": "Test Ad Native", - "clickUrl": "https://example.com/ad-server-e?data=rYe8nbAM5c5zq5NcGi0xXHqGPRSwg9NdOtXo8HW7MBdZO6niYSCmNsZqZDU6PDs9jVqmCux1S-phDpqQodyDvLfMMFomYzBMfo6O9A9Zbjy_tDB-cEUwMbeiifLkXixiYbfWReUMm4VCErRUggbh-aZvd9HEpiSKQVxdzmL7_zJh0ZxCBPz6p6ukHQr_OqNcSeJvXK0UnFgvOT460CvfsZRwiXJ7PlOyJIrKJcllKMbQCnXRvnuXgZ7md-JLuorEF1zr2mU_a-1KvEkuPjdRZXGhgx68IZ1X7nBah-bbh_a3RD5_-nfOs5Sgm-osdxAxqAP90YFhHJSFubBlOvVaGJCEvpwz2hQAkkFoumfx1DkXLTbwFQBgi_mnXZssXz9RPQ-uzes7Hrpv2vWvtXcQtZcXkDLVc8vno1KQnaGTdING9ASNDMb0FwRHQqLH18lRxiAvtWZuAAqL3y2K2OClxKESDwRfCQAAAAA&integrity=1q8zuOP0wR6HFL22B0EcXl8a1FhqB4dYakIdamrH4TM", - "impressionTrackers": [ - "https://example.com/ad-server-e?data=Q0uIkM00KhPFH-kwwFyX0xng6t1ZzDT-7TFojIwp1kSUAZRMxWAwpkifMKIv5xVteKcn_TStODvcIk2DFNBsLH68EBXiXtzlSuqrkRNhRXCshvuIuEpi7p18OFtztv0p42_D-LqnD0qaeVQP_UJ7Vxbi2cchLD6WxswYGafQ6hbuIw9bDXbx_FFzlTd3v99mq5YzZSyr6A26sKRr4FQz7F-1nXlXqln7MVUEDtbkbumxw8FfzIZsP04u4bWFnMd0pWCAwmp4z0ZwAfsMWquUlOf2eZVls-9dwdssB6PxjmkLIp3TRwMwiT2aNALf0sIMCH1gkyTl12ircYgjX9urxSGx3e1GoTlPQvdQZM9_WQyct8MJYh_HCRF_ZDGsPUtGT8f9MkttjWZUG1aXboPbL1EntUzzjM8XMb5vHnu4fOuVkAFY6jF7y4JLnq07dKnxB3e2mxQCuVFqw0i6u9IFo5i4PmQAAAAA&integrity=2iKlABjSJ08PWsZwavEV4fvFabbRW3MN5EcXyBdg4VE" - ], - "viewableTrackers": [ - "https://example.com/ad-server-e?data=yMc4kfll-AQy3mUXZIl1xA2JjMlgm73j3HoGmqofgXVcVe1Q3wS6GD9ic0upRjeat_rLEP_aNrBevQsEUulH9F9JzFYDrkQavrGlhmHbddFnAx4mDrFK1N50uWR4oFmhl-V1RZ6PMrNeCLSH5KV8nDRsl5bCYG3YNBu6A65w-VJZpxfavNSHZfhDkDRvxSM6cYlstqlgg-dXp6jYdFS8w2SXIb8KgrxPN18Zw4T6wCqd0OGTDcO2ylQzjsvFeRrdBkkIyLlvovkfnYOYaLsyoAOclOMNaoDwmOhTLqCZr6IPrieLP4VyrsussbkIhBBSNvVr7KwNpLptTj3JqX6dSazTTm3FSojqCp8o6PoE072QmX6xmMK_Mm1XIJq9jtCxRER2s9VLkaWyzksgDmFeHzrnHurmDQ52BxA6m4DYQ9_txrMfxy5kK5lb73Qls2bcLzF2oosqRRCg2SWXomwKSkOkovxM7kxh_eIhYcZyxRO0wq5fILlMXgAAAAA&integrity=9QYkbMgRLGjGxBY2sO3VeZqyR5CF2sJHkGvPp6V6AeM" - ], - "adTemplate": "
\n \n
\n

\n ##title##\n

\n

##body##

\n
##title##
\n
\n
" - } - }]; - let serverResponseNative = { - body: { - "bids": [ - { - "requestId": "36e835f6cbfca38", - "cpm": 5.0, - "currency": "EUR", - "width": 1, - "height": 1, - "creativeId": "28cf46ce-fe57-4417-acd6-285db604aa30", - "ad": "{\"ver\":\"1.2\",\"assets\":[{\"id\":1,\"img\":{\"type\":3,\"url\":\"https://example.com/image.png\"}},{\"id\":2,\"title\":{\"text\":\"TestAdNative\",\"len\":12}},{\"id\":4,\"data\":{\"type\":2,\"value\":\"Test Ad Native\"}}],\"link\":{\"url\":\"https://example.com/ad-server-e?data=o4rIvHAEkHlT9_ItFWCiBfQDNUkLHzkjLF9uPkIArQZiqBg_bWdNjmhGDU96MmBAI3UURTDIZ4CuqYA90CazeB7gVUwZboKeJXp8MIMiLQEzxaUQh6qsFjBoVFbn6H0qq7neZUEX82NuPcgwNzsThJnING6uFzUUCrlgAGncJQc68DMldAFqxTrgsSHpAhyF00-LCUF1eblyoT03R6RWIEpBl1O85VE9MeRPV5BHDaIjYVT7wWUSLXa40_mr_tUpFST6oDwVEFldoYQruwm07gjxLLLjnymoj9QXUuSTgGYwPFwW6wqG0p67xaGuGNB8J08AUweUujghsXHf_iSbkqfhO1LilHa_YrZ0UXzZSjRRWOX_sPVLs6Wta4RsEl3KMKVsVlgSLV6j0Okbw2cP6GztzMbURlz2C3jX2veaOsKxvajdqU5U1VLPYaRBAp-RDhuGKTbBHTe83bqgvgwebcEzcqQk-gAAAAA&integrity=3Yj4qCKUgBQPCshcNy2FPHD3Upsj8M5GOQ8E4ORetqI\"},\"eventtrackers\":[{\"event\":1,\"method\":1,\"url\":\"https://example.com/ad-server-e?data=gS4Wtf5CrSPsZHjTBW1mDkQ1TP6aDOWpxpBQrUEfS4u8zrPxIBN1RFHJR5HdEKIKSdLjXZojo-lwz87xbP-ABPgD90lpjBeL-KOVOgvvwBy92VYCLZPvbsgYxJd_BFSiiz2UvwathNDkSsWChylm6t8sbIF62Qe540dhb3T1cI_Ben_qkgqrobPSHbAyBRKsje_twgWYf2TJFKsKmQYq5zSwgCnZKpMgZ0nFqUitx7DPjiZrGTFZxZ66J3ArskkREs6N0nPy4H5y2zFNepzAorp-pLONDHWSFkbQNzqNZqZgUJ_8XracHjL5_VDDwmz392xnx6_Kf1a6ezDRJyfp3k7ZJoGA5U4Wx5z4S7SelueaXZYgnHv--skg7P3pIXc7veM6nfXQD-GDmC0sDdrRgFbJCwCHBdkvurEcFASxIiBOaH8FOu2quxAth0dEoEHFpwKd_bJdAcXZFfUt4URDy43hQAQAAAAA&integrity=fP4SzYcSbOv8RbHcTT5xsC0fmeftmjv51PV_8G7-Wy0\"},{\"event\":2,\"method\":1,\"url\":\"https://example.com/ad-server-e?data=PMO9Lc4-g0OGvzRglK8_72bWOZumt1Hgvy-ifNC3VT5iJ3PEBt1FD96vxr8w_Oy4E0BMXXHlDABkXelqcS6a1HJTdR8u-BncqZ8lycFkrVg9wMFNiorbpVxzpM5lgaj-uUEH7oYreDCXD_qK_5OzQaJp3rHgXjtyUZEaXimv6Bgu-hBeUYimezBT5Ba9IJJ1YDMdgdY-pFIU4ND1-kQN11KYTwikW37IWX-q8zZMwM3m78KsgKnY_OkJzy-0JJUeKkmRv7awNoBBOmhjmY7qHbDcVcwG5GQp4b0zJTm9bg6zHxIIYKsYqdQzXUjqL94rQ1M113QrGW9p9U11W0fSpX3VbHL0EtSrnoAo8d9xTjQ2nc5OsJOlDbYXakVO_GEiGtqK1kMUtBkQzjctCB_TyatPj_f7GZ-Vjuema9bTQUwKybco4Gmfu32GpsDKlPL4j3sMahH1W55zTrjOl2f4SkVyrXpTTpWS8Ifxl6Gq-xvYm7vixStI6gAAAAA&integrity=hDyA0PinLzMdhwKbV6BOJVTUn3xP9UQSDqf6JebKFhQ\"}]}", - "ttl": 300, - "netRevenue": false, - "mediaType": "NATIVE", - "meta": { - "advertiserDomains": [ - "example.com" - ] - } - } - ], - "userSyncs": [ - { - "url": "https://dmp.adform.net/dmp/profile/?pid=12718&sg=SEVIO_CGE", - "type": "image" - } - ] - } - }; - - let result = spec.interpretResponse(serverResponseNative); - expect(Object.keys(result)).to.deep.equal(Object.keys(expectedResponseNative)); - }) - }); -}); diff --git a/test/spec/modules/sharethroughBidAdapter_spec.js b/test/spec/modules/sharethroughBidAdapter_spec.js deleted file mode 100644 index c988f9c63..000000000 --- a/test/spec/modules/sharethroughBidAdapter_spec.js +++ /dev/null @@ -1,1545 +0,0 @@ -import { expect } from 'chai'; -import { sharethroughAdapterSpec, sharethroughInternal } from 'modules/sharethroughBidAdapter.js'; -import * as sinon from 'sinon'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config'; -import * as utils from 'src/utils'; -import { deepSetValue } from '../../../src/utils.js'; -import { getImpIdMap, setIsEqtvTest } from '../../../modules/sharethroughBidAdapter.js'; -import * as equativUtils from '../../../libraries/equativUtils/equativUtils.js' - -const spec = newBidder(sharethroughAdapterSpec).getSpec(); - -describe('sharethrough adapter spec', function () { - let protocolStub; - let inIframeStub; - - beforeEach(() => { - protocolStub = sinon.stub(sharethroughInternal, 'getProtocol').returns('https'); - inIframeStub = sinon.stub(utils, 'inIframe').returns(false); - }); - - afterEach(() => { - protocolStub.restore(); - inIframeStub.restore(); - }); - - describe('code', function () { - it('should return a bidder code of sharethrough', function () { - expect(spec.code).to.eql('sharethrough'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return false if req has no pkey', function () { - const invalidBidRequest = { - bidder: 'sharethrough', - params: { - notPKey: 'abc123', - }, - }; - expect(spec.isBidRequestValid(invalidBidRequest)).to.eql(false); - }); - - it('should return true if req is correct', function () { - const validBidRequest = { - params: { - pkey: 'abc123', - }, - }; - expect(spec.isBidRequestValid(validBidRequest)).to.eq(true); - }); - }); - - describe('open rtb', () => { - let bidRequests, bidderRequest, multiImpBidRequests; - - const bannerBidRequests = [ - { - adUnitCode: 'eqtv_42', - bidId: 'abcd1234', - sizes: [ - [300, 250], - [300, 600], - ], - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - }, - }, - bidder: 'sharethrough', - params: { - pkey: 111, - equativNetworkId: 73 - }, - requestId: 'efgh5678', - ortb2Imp: { - ext: { - tid: 'zsfgzzg', - }, - }, - } - ]; - - const videoBidRequests = [ - { - adUnitCode: 'eqtv_43', - bidId: 'efgh5678', - sizes: [], - mediaTypes: { - video: { - context: 'instream', - playerSize: [[640, 480]], - pos: 3, - skip: 1, - linearity: 1, - minduration: 10, - maxduration: 30, - minbitrate: 300, - maxbitrate: 600, - w: 640, - h: 480, - playbackmethod: [1], - api: [3], - mimes: ['video/x-flv', 'video/mp4'], - startdelay: 42, - battr: [13, 14], - placement: 1, - }, - }, - bidder: 'sharethrough', - params: { - pkey: 111, - equativNetworkIdId: 73 - }, - requestId: 'abcd1234', - ortb2Imp: { - ext: { - tid: 'zsgzgzz', - }, - }, - } - ]; - - const nativeOrtbRequest = { - assets: [{ - id: 0, - required: 1, - title: { - len: 140 - } - }, - { - id: 1, - required: 1, - img: { - type: 3, - w: 300, - h: 600 - } - }, - { - id: 2, - required: 1, - data: { - type: 1 - } - }], - context: 1, - eventtrackers: [{ - event: 1, - methods: [1, 2] - }], - plcmttype: 1, - privacy: 1, - ver: '1.2', - }; - - const nativeBidRequests = [{ - bidder: 'sharethrough', - adUnitCode: 'sharethrough_native_42', - bidId: 'bidId3', - sizes: [], - mediaTypes: { - native: { - ...nativeOrtbRequest - }, - }, - nativeOrtbRequest, - params: { - pkey: 777, - equativNetworkId: 73 - }, - requestId: 'sharethrough_native_reqid_42', - ortb2Imp: { - ext: { - tid: 'sharethrough_native_tid_42', - }, - }, - }] - - beforeEach(() => { - config.setConfig({ - bidderTimeout: 242, - coppa: true, - }); - - bidRequests = [ - { - bidder: 'sharethrough', - bidId: 'bidId1', - transactionId: 'transactionId1', - sizes: [ - [300, 250], - [300, 600], - ], - params: { - pkey: 'aaaa1111', - bcat: ['cat1', 'cat2'], - badv: ['adv1', 'adv2'], - }, - mediaTypes: { - banner: { - pos: 1, - battr: [6, 7], - }, - }, - ortb2Imp: { - ext: { - tid: 'transaction-id-1', - gpid: 'universal-id', - data: { - pbadslot: 'pbadslot-id', - }, - }, - }, - userIdAsEids: [ - { - source: 'pubcid.org', - uids: [ - { - atype: 1, - id: 'fake-pubcid', - }, - ], - }, - { - source: 'liveramp.com', - uids: [ - { - atype: 1, - id: 'fake-identity-link', - }, - ], - }, - { - source: 'id5-sync.com', - uids: [ - { - atype: 1, - id: 'fake-id5id', - }, - ], - }, - { - source: 'adserver.org', - uids: [ - { - atype: 1, - id: 'fake-tdid', - }, - ], - }, - { - source: 'criteo.com', - uids: [ - { - atype: 1, - id: 'fake-criteo', - }, - ], - }, - { - source: 'britepool.com', - uids: [ - { - atype: 1, - id: 'fake-britepool', - }, - ], - }, - { - source: 'liveintent.com', - uids: [ - { - atype: 1, - id: 'fake-lipbid', - }, - ], - }, - { - source: 'intentiq.com', - uids: [ - { - atype: 1, - id: 'fake-intentiq', - }, - ], - }, - { - source: 'crwdcntrl.net', - uids: [ - { - atype: 1, - id: 'fake-lotame', - }, - ], - }, - { - source: 'parrable.com', - uids: [ - { - atype: 1, - id: 'fake-parrable', - }, - ], - }, - { - source: 'netid.de', - uids: [ - { - atype: 1, - id: 'fake-netid', - }, - ], - }, - ], - crumbs: { - pubcid: 'fake-pubcid-in-crumbs-obj', - }, - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'directseller.com', - sid: '00001', - rid: 'BidRequest1', - hp: 1, - }, - ], - } - } - } - }, - getFloor: () => ({ currency: 'USD', floor: 42 }), - }, - { - bidder: 'sharethrough', - bidId: 'bidId2', - sizes: [[600, 300]], - transactionId: 'transactionId2', - params: { - pkey: 'bbbb2222', - }, - mediaTypes: { - video: { - pos: 3, - skip: 1, - linearity: 1, - minduration: 10, - maxduration: 30, - playbackmethod: [1], - api: [3], - mimes: ['video/3gpp'], - protocols: [2, 3], - playerSize: [[640, 480]], - startdelay: 42, - skipmin: 10, - skipafter: 20, - delivery: 1, - battr: [13, 14], - companiontype: 'companion type', - companionad: 'companion ad', - context: 'instream', - placement: 1, - plcmt: 1, - }, - }, - getFloor: () => ({ currency: 'USD', floor: 42 }), - }, - ]; - - multiImpBidRequests = [ - { - adUnitCode: 'equativ_42', - bidId: 'abcd1234', - mediaTypes: { - banner: bannerBidRequests[0].mediaTypes.banner, - video: videoBidRequests[0].mediaTypes.video, - native: nativeBidRequests[0].mediaTypes.native - }, - sizes: [], - nativeOrtbRequest, - bidder: 'sharethrough', - params: { - pkey: 111, - equativNetworkId: 73 - }, - requestId: 'efgh5678', - ortb2Imp: { - ext: { - tid: 'zsfgzzg', - }, - }, - getFloor: ({ mediaType, size }) => { - if ((mediaType === 'banner' && size[0] === 300 && size[1] === 250) || mediaType === 'native') { - return { floor: 1.1 }; - } - return { floor: 0.9 }; - } - } - ]; - - bidderRequest = { - refererInfo: { - ref: 'https://referer.com', - }, - ortb2: { - source: { - tid: 'auction-id', - }, - }, - timeout: 242, - }; - }); - - afterEach(() => { - setIsEqtvTest(null); - }) - - describe('buildRequests', function () { - describe('top level object', () => { - it('should build openRTB request', () => { - const builtRequests = spec.buildRequests(bidRequests, bidderRequest); - - const expectedImpValues = [ - { - id: 'bidId1', - tagid: 'aaaa1111', - secure: 1, - bidfloor: 42, - }, - { - id: 'bidId2', - tagid: 'bbbb2222', - secure: 1, - bidfloor: 42, - }, - ]; - - builtRequests.map((builtRequest, rIndex) => { - expect(builtRequest.method).to.equal('POST'); - expect(builtRequest.url).not.to.be.undefined; - expect(builtRequest.options).to.be.undefined; - - const openRtbReq = builtRequest.data; - expect(openRtbReq.id).not.to.be.undefined; - expect(openRtbReq.cur).to.deep.equal(['USD']); - expect(openRtbReq.tmax).to.equal(242); - - expect(Object.keys(openRtbReq.site)).to.have.length(3); - expect(openRtbReq.site.domain).not.to.be.undefined; - expect(openRtbReq.site.page).not.to.be.undefined; - expect(openRtbReq.site.ref).to.equal('https://referer.com'); - - const expectedEids = { - 'liveramp.com': { id: 'fake-identity-link' }, - 'id5-sync.com': { id: 'fake-id5id' }, - 'pubcid.org': { id: 'fake-pubcid' }, - 'adserver.org': { id: 'fake-tdid' }, - 'criteo.com': { id: 'fake-criteo' }, - 'britepool.com': { id: 'fake-britepool' }, - 'liveintent.com': { id: 'fake-lipbid' }, - 'intentiq.com': { id: 'fake-intentiq' }, - 'crwdcntrl.net': { id: 'fake-lotame' }, - 'parrable.com': { id: 'fake-parrable' }, - 'netid.de': { id: 'fake-netid' }, - }; - expect(openRtbReq.user.ext.eids).to.be.an('array').that.have.length(Object.keys(expectedEids).length); - for (const eid of openRtbReq.user.ext.eids) { - expect(Object.keys(expectedEids)).to.include(eid.source); - expect(eid.uids[0].id).to.equal(expectedEids[eid.source].id); - expect(eid.uids[0].atype).to.be.ok; - } - - // expect(openRtbReq.regs.gpp).to.equal(bidderRequest.gppConsent.gppString); - // expect(openRtbReq.regs.gpp_sid).to.equal(bidderRequest.gppConsent.applicableSections); - - // expect(openRtbReq.regs.ext.gpp).to.equal(bidderRequest.ortb2.regs.gpp); - // expect(openRtbReq.regs.ext.gpp_sid).to.equal(bidderRequest.ortb2.regs.gpp_sid); - - expect(openRtbReq.device.ua).to.equal(navigator.userAgent); - expect(openRtbReq.regs.coppa).to.equal(1); - - expect(openRtbReq.source.tid).to.equal(bidderRequest.ortb2.source.tid); - expect(openRtbReq.source.ext.version).not.to.be.undefined; - expect(openRtbReq.source.ext.str).not.to.be.undefined; - expect(openRtbReq.source.ext.schain).to.deep.equal(bidRequests[0].ortb2.source.ext.schain); - - expect(openRtbReq.bcat).to.deep.equal(bidRequests[0].params.bcat); - expect(openRtbReq.badv).to.deep.equal(bidRequests[0].params.badv); - - expect(openRtbReq.imp).to.have.length(1); - - expect(openRtbReq.imp[0].id).to.equal(expectedImpValues[rIndex].id); - expect(openRtbReq.imp[0].tagid).to.equal(expectedImpValues[rIndex].tagid); - expect(openRtbReq.imp[0].secure).to.equal(expectedImpValues[rIndex].secure); - expect(openRtbReq.imp[0].bidfloor).to.equal(expectedImpValues[rIndex].bidfloor); - }); - }); - - it('should have empty eid array if no id is provided', () => { - const openRtbReq = spec.buildRequests([bidRequests[1]], bidderRequest)[0].data; - - expect(openRtbReq.user.ext.eids).to.deep.equal([]); - }); - - it('should add ORTB2 device data to the request', () => { - const bidderRequestWithOrtb2Device = { - ...bidderRequest, - ...{ - ortb2: { - device: { - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - }, - }, - }, - }; - - const [request] = spec.buildRequests(bidRequests, bidderRequestWithOrtb2Device); - - expect(request.data.device.w).to.equal(bidderRequestWithOrtb2Device.ortb2.device.w); - expect(request.data.device.h).to.equal(bidderRequestWithOrtb2Device.ortb2.device.h); - expect(request.data.device.dnt).to.equal(bidderRequestWithOrtb2Device.ortb2.device.dnt); - expect(request.data.device.ua).to.equal(bidderRequestWithOrtb2Device.ortb2.device.ua); - expect(request.data.device.language).to.equal(bidderRequestWithOrtb2Device.ortb2.device.language); - expect(request.data.device.devicetype).to.equal(bidderRequestWithOrtb2Device.ortb2.device.devicetype); - expect(request.data.device.make).to.equal(bidderRequestWithOrtb2Device.ortb2.device.make); - expect(request.data.device.model).to.equal(bidderRequestWithOrtb2Device.ortb2.device.model); - expect(request.data.device.os).to.equal(bidderRequestWithOrtb2Device.ortb2.device.os); - expect(request.data.device.osv).to.equal(bidderRequestWithOrtb2Device.ortb2.device.osv); - }); - }); - - describe('no referer provided', () => { - beforeEach(() => { - bidderRequest = {}; - }); - - it('should set referer to undefined', () => { - const openRtbReq = spec.buildRequests(bidRequests, bidderRequest)[0].data; - expect(openRtbReq.site.ref).to.be.undefined; - }); - }); - - describe('regulation', () => { - describe('gdpr', () => { - it('should populate request accordingly when gdpr applies', () => { - bidderRequest.gdprConsent = { - gdprApplies: true, - consentString: 'consent', - }; - - const openRtbReq = spec.buildRequests(bidRequests, bidderRequest)[0].data; - - expect(openRtbReq.regs.ext.gdpr).to.equal(1); - expect(openRtbReq.user.ext.consent).to.equal('consent'); - }); - - it('should populate request accordingly when gdpr explicitly does not apply', () => { - bidderRequest.gdprConsent = { - gdprApplies: false, - }; - - const openRtbReq = spec.buildRequests(bidRequests, bidderRequest)[0].data; - - expect(openRtbReq.regs.ext.gdpr).to.equal(0); - expect(openRtbReq.user.ext.consent).to.be.undefined; - }); - }); - - describe('US privacy', () => { - it('should populate request accordingly when us privacy applies', () => { - bidderRequest.uspConsent = 'consent'; - - const openRtbReq = spec.buildRequests(bidRequests, bidderRequest)[0].data; - - expect(openRtbReq.regs.ext.us_privacy).to.equal('consent'); - expect(openRtbReq.regs.us_privacy).to.equal('consent'); - }); - }); - - describe('coppa', () => { - it('should populate request accordingly when coppa does not apply', () => { - config.setConfig({ coppa: false }); - - const openRtbReq = spec.buildRequests(bidRequests, bidderRequest)[0].data; - - expect(openRtbReq.regs.coppa).to.equal(0); - }); - }); - - describe('gpp', () => { - it('should properly attach GPP information to the request when applicable', () => { - bidderRequest.gppConsent = { - gppString: 'some-gpp-string', - applicableSections: [3, 5], - }; - - const openRtbReq = spec.buildRequests(bidRequests, bidderRequest)[0].data; - expect(openRtbReq.regs.gpp).to.equal(bidderRequest.gppConsent.gppString); - expect(openRtbReq.regs.gpp_sid).to.equal(bidderRequest.gppConsent.applicableSections); - }); - - it('should populate request accordingly when gpp explicitly does not apply', function () { - const openRtbReq = spec.buildRequests(bidRequests, {})[0].data; - - expect(openRtbReq.regs.gpp).to.be.undefined; - }); - }); - }); - - describe('dsa', () => { - it('should properly attach dsa information to the request when applicable', () => { - bidderRequest.ortb2 = { - regs: { - ext: { - dsa: { - 'dsarequired': 1, - 'pubrender': 0, - 'datatopub': 1, - 'transparency': [{ - 'domain': 'good-domain', - 'dsaparams': [1, 2] - }, { - 'domain': 'bad-setup', - 'dsaparams': ['1', 3] - }] - } - } - } - } - - const openRtbReq = spec.buildRequests(bidRequests, bidderRequest)[0].data; - expect(openRtbReq.regs.ext.dsa.dsarequired).to.equal(1); - expect(openRtbReq.regs.ext.dsa.pubrender).to.equal(0); - expect(openRtbReq.regs.ext.dsa.datatopub).to.equal(1); - expect(openRtbReq.regs.ext.dsa.transparency).to.deep.equal([{ - 'domain': 'good-domain', - 'dsaparams': [1, 2] - }, { - 'domain': 'bad-setup', - 'dsaparams': ['1', 3] - }]); - }); - }); - - describe('transaction id at the impression level', () => { - it('should include transaction id when provided', () => { - const requests = spec.buildRequests(bidRequests, bidderRequest); - - expect(requests[0].data.imp[0].ext.tid).to.equal('transaction-id-1'); - expect(requests[1].data.imp[0].ext).to.be.empty; - }); - }); - - describe('universal id', () => { - it('should include gpid when universal id is provided', () => { - const requests = spec.buildRequests(bidRequests, bidderRequest); - - expect(requests[0].data.imp[0].ext.gpid).to.equal('universal-id'); - expect(requests[1].data.imp[0].ext).to.be.empty; - }); - }); - - describe('secure flag', () => { - it('should be positive when protocol is https', () => { - protocolStub.returns('https'); - const requests = spec.buildRequests(bidRequests, bidderRequest); - - expect(requests[0].data.imp[0].secure).to.equal(1); - expect(requests[1].data.imp[0].secure).to.equal(1); - }); - - it('should be negative when protocol is http', () => { - protocolStub.returns('http'); - const requests = spec.buildRequests(bidRequests, bidderRequest); - - expect(requests[0].data.imp[0].secure).to.equal(0); - expect(requests[1].data.imp[0].secure).to.equal(0); - }); - - it('should be positive when protocol is neither http nor https', () => { - protocolStub.returns('about'); - const requests = spec.buildRequests(bidRequests, bidderRequest); - - expect(requests[0].data.imp[0].secure).to.equal(1); - expect(requests[1].data.imp[0].secure).to.equal(1); - }); - }); - - describe('banner imp', () => { - it('should generate open rtb banner imp', () => { - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[0]; - - const bannerImp = builtRequest.data.imp[0].banner; - expect(bannerImp.pos).to.equal(1); - expect(bannerImp.topframe).to.equal(1); - expect(bannerImp.format).to.deep.equal([ - { w: 300, h: 250 }, - { w: 300, h: 600 }, - ]); - }); - - it('should correctly harvest battr values for banner if present in mediaTypes.banner of impression and battr is not defined in ortb2Imp.banner', () => { - // assemble - const EXPECTED_BATTR_VALUES = [6, 7]; - - // act - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[0]; - const ACTUAL_BATTR_VALUES = builtRequest.data.imp[0].banner.battr - - // assert - expect(ACTUAL_BATTR_VALUES).to.deep.equal(EXPECTED_BATTR_VALUES); - }); - - it('should not include battr values for banner if NOT present in mediaTypes.banner of impression and battr is not defined in ortb2Imp.banner', () => { - // assemble - delete bidRequests[0].mediaTypes.banner.battr; - - // act - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[0]; - - // assert - expect(builtRequest.data.imp[0].banner.battr).to.be.undefined; - }); - - it('should prefer battr values from mediaTypes.banner over ortb2Imp.banner', () => { - // assemble - deepSetValue(bidRequests[0], 'ortb2Imp.banner.battr', [1, 2, 3]); - const EXPECTED_BATTR_VALUES = [6, 7]; // values from mediaTypes.banner - - // act - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[0]; - const ACTUAL_BATTR_VALUES = builtRequest.data.imp[0].banner.battr - - // assert - expect(ACTUAL_BATTR_VALUES).to.deep.equal(EXPECTED_BATTR_VALUES); - }); - - it('should use battr values from ortb2Imp.banner if mediaTypes.banner.battr is not present', () => { - // assemble - delete bidRequests[0].mediaTypes.banner.battr; - const EXPECTED_BATTR_VALUES = [1, 2, 3]; - deepSetValue(bidRequests[0], 'ortb2Imp.banner.battr', EXPECTED_BATTR_VALUES); - - // act - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[0]; - const ACTUAL_BATTR_VALUES = builtRequest.data.imp[0].banner.battr - - // assert - expect(ACTUAL_BATTR_VALUES).to.deep.equal(EXPECTED_BATTR_VALUES); - }); - - it('should default to pos 0 if not provided', () => { - delete bidRequests[0].mediaTypes.banner.pos; - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[0]; - - const bannerImp = builtRequest.data.imp[0].banner; - expect(bannerImp.pos).to.equal(0); - }); - }); - - describe('video imp', () => { - it('should generate open rtb video imp', () => { - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[1]; - - const videoImp = builtRequest.data.imp[0].video; - expect(videoImp.pos).to.equal(3); - expect(videoImp.topframe).to.equal(1); - expect(videoImp.skip).to.equal(1); - expect(videoImp.linearity).to.equal(1); - expect(videoImp.minduration).to.equal(10); - expect(videoImp.maxduration).to.equal(30); - expect(videoImp.playbackmethod).to.deep.equal([1]); - expect(videoImp.api).to.deep.equal([3]); - expect(videoImp.mimes).to.deep.equal(['video/3gpp']); - expect(videoImp.protocols).to.deep.equal([2, 3]); - expect(videoImp.w).to.equal(640); - expect(videoImp.h).to.equal(480); - expect(videoImp.startdelay).to.equal(42); - expect(videoImp.skipmin).to.equal(10); - expect(videoImp.skipafter).to.equal(20); - expect(videoImp.placement).to.equal(1); - expect(videoImp.delivery).to.equal(1); - expect(videoImp.battr).to.deep.equal([13, 14]); - expect(videoImp.companiontype).to.equal('companion type'); - expect(videoImp.companionad).to.equal('companion ad'); - }); - - it('should set defaults in some circumstances if no value provided', () => { - delete bidRequests[1].mediaTypes.video.pos; - delete bidRequests[1].mediaTypes.video.playerSize; - - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[1]; - - const videoImp = builtRequest.data.imp[0].video; - expect(videoImp.pos).to.equal(0); - expect(videoImp.w).to.equal(640); - expect(videoImp.h).to.equal(360); - }); - - it('should not set values in some circumstances when non-valid values are supplied', () => { - // arrange - bidRequests[1].mediaTypes.video.api = 1; // non-array value, will not be used - bidRequests[1].mediaTypes.video.battr = undefined; // non-array value, will not be used - bidRequests[1].mediaTypes.video.mimes = 'video/3gpp'; // non-array value, will not be used - bidRequests[1].mediaTypes.video.playbackmethod = null; // non-array value, will not be used - bidRequests[1].mediaTypes.video.protocols = []; // empty array, will not be used - - // act - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[1]; - const videoImp = builtRequest.data.imp[0].video; - - // assert - expect(videoImp.api).to.be.undefined; - expect(videoImp.battr).to.be.undefined; - expect(videoImp.mimes).to.be.undefined; - expect(videoImp.playbackmethod).to.be.undefined; - expect(videoImp.protocols).to.be.undefined; - }); - - it('should not set a property if no corresponding property is detected on mediaTypes.video', () => { - // arrange - const propertiesToConsider = [ - 'api', 'battr', 'companionad', 'companiontype', 'delivery', 'linearity', 'maxduration', 'mimes', 'minduration', 'placement', 'playbackmethod', 'plcmt', 'protocols', 'skip', 'skipafter', 'skipmin', 'startdelay' - ] - - // act - propertiesToConsider.forEach(propertyToConsider => { - delete bidRequests[1].mediaTypes.video[propertyToConsider]; - }); - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[1]; - const videoImp = builtRequest.data.imp[0].video; - - // assert - propertiesToConsider.forEach(propertyToConsider => { - expect(videoImp[propertyToConsider]).to.be.undefined; - }); - }); - - describe('outstream', () => { - it('should use placement value if provided', () => { - bidRequests[1].mediaTypes.video.context = 'outstream'; - bidRequests[1].mediaTypes.video.placement = 3; - - const builtRequest = spec.buildRequests(bidRequests, bidderRequest)[1]; - const videoImp = builtRequest.data.imp[0].video; - - expect(videoImp.placement).to.equal(3); - }); - }); - }); - - describe('cookie deprecation', () => { - it('should not add cdep if we do not get it in an impression request', () => { - const builtRequests = spec.buildRequests(bidRequests, { - auctionId: 'new-auction-id', - ortb2: { - device: { - ext: { - propThatIsNotCdep: 'value-we-dont-care-about', - }, - }, - }, - }); - const noCdep = builtRequests.every((builtRequest) => { - const ourCdepValue = builtRequest.data.device?.ext?.cdep; - return ourCdepValue === undefined; - }); - expect(noCdep).to.be.true; - }); - - it('should add cdep if we DO get it in an impression request', () => { - const builtRequests = spec.buildRequests(bidRequests, { - auctionId: 'new-auction-id', - ortb2: { - device: { - ext: { - cdep: 'cdep-value', - }, - }, - }, - }); - const cdepPresent = builtRequests.every((builtRequest) => { - return builtRequest.data.device.ext.cdep === 'cdep-value'; - }); - expect(cdepPresent).to.be.true; - }); - }); - - describe('first party data', () => { - const firstPartyData = { - site: { - name: 'example', - keywords: 'power tools, drills', - search: 'drill', - content: { - userrating: '4', - }, - ext: { - data: { - pageType: 'article', - category: 'repair', - }, - }, - }, - user: { - yob: 1985, - gender: 'm', - ext: { - data: { - registered: true, - interests: ['cars'], - }, - }, - }, - bcat: ['IAB1', 'IAB2-1'], - badv: ['domain1.com', 'domain2.com'], - regs: { - gpp: 'gpp_string', - gpp_sid: [7], - }, - }; - - it('should include first party data in open rtb request, site section', () => { - const openRtbReq = spec.buildRequests(bidRequests, { ...bidderRequest, ortb2: firstPartyData })[0].data; - - expect(openRtbReq.site.name).to.equal(firstPartyData.site.name); - expect(openRtbReq.site.keywords).to.equal(firstPartyData.site.keywords); - expect(openRtbReq.site.search).to.equal(firstPartyData.site.search); - expect(openRtbReq.site.content).to.deep.equal(firstPartyData.site.content); - expect(openRtbReq.site.ext).to.deep.equal(firstPartyData.site.ext); - }); - - it('should include first party data in open rtb request, user section', () => { - const openRtbReq = spec.buildRequests(bidRequests, { ...bidderRequest, ortb2: firstPartyData })[0].data; - - expect(openRtbReq.user.yob).to.equal(firstPartyData.user.yob); - expect(openRtbReq.user.gender).to.equal(firstPartyData.user.gender); - expect(openRtbReq.user.ext.data).to.deep.equal(firstPartyData.user.ext.data); - expect(openRtbReq.user.ext.eids).not.to.be.undefined; - }); - - it('should include first party data in open rtb request, ORTB blocked section', () => { - const openRtbReq = spec.buildRequests(bidRequests, { ...bidderRequest, ortb2: firstPartyData })[0].data; - - expect(openRtbReq.bcat).to.deep.equal(firstPartyData.bcat); - expect(openRtbReq.badv).to.deep.equal(firstPartyData.badv); - }); - - it('should include first party data in open rtb request, regulation section', () => { - const openRtbReq = spec.buildRequests(bidRequests, { ...bidderRequest, ortb2: firstPartyData })[0].data; - - expect(openRtbReq.regs.ext.gpp).to.equal(firstPartyData.regs.gpp); - expect(openRtbReq.regs.ext.gpp_sid).to.equal(firstPartyData.regs.gpp_sid); - }); - }); - - describe('fledge', () => { - it('should attach "ae" as a property to the request if 1) fledge auctions are enabled, and 2) request is display (only supporting display for now)', () => { - // ASSEMBLE - const EXPECTED_AE_VALUE = 1; - - // ACT - bidderRequest.paapi = { enabled: true }; - const builtRequests = spec.buildRequests(bidRequests, bidderRequest); - const ACTUAL_AE_VALUE = builtRequests[0].data.imp[0].ext.ae; - - // ASSERT - expect(ACTUAL_AE_VALUE).to.equal(EXPECTED_AE_VALUE); - expect(builtRequests[1].data.imp[0].ext.ae).to.be.undefined; - }); - }); - - describe('isEqtvTest', () => { - it('should set publisher id if equativNetworkId param is present', () => { - const builtRequest = spec.buildRequests(multiImpBidRequests, bidderRequest)[0] - expect(builtRequest.data.site.publisher.id).to.equal(73) - }) - - it('should not set publisher id if equativNetworkId param is not present', () => { - const bidRequest = { - ...bidRequests[0], - params: { - ...bidRequests[0].params, - equativNetworkId: undefined - } - } - - const builtRequest = spec.buildRequests([bidRequest], bidderRequest)[0] - expect(builtRequest.data.site.publisher).to.equal(undefined) - }) - - it('should generate a 14-char id for each imp object', () => { - const request = spec.buildRequests( - bannerBidRequests, - bidderRequest - ); - - request[0].data.imp.forEach(imp => { - expect(imp.id).to.have.lengthOf(14); - }); - }); - - it('should split banner sizes per floor', () => { - const bids = [ - { - ...bannerBidRequests[0], - getFloor: ({ size }) => ({ floor: size[0] * size[1] / 100_000 }) - } - ]; - - const request = spec.buildRequests( - bids, - bidderRequest - ); - - expect(request[0].data.imp).to.have.lengthOf(2); - - const firstImp = request[0].data.imp[0]; - expect(firstImp.bidfloor).to.equal(300 * 250 / 100_000); - expect(firstImp.banner.format).to.have.lengthOf(1); - expect(firstImp.banner.format[0]).to.deep.equal({ w: 300, h: 250 }); - - const secondImp = request[0].data.imp[1]; - expect(secondImp.bidfloor).to.equal(300 * 600 / 100_000); - expect(secondImp.banner.format).to.have.lengthOf(1); - expect(secondImp.banner.format[0]).to.deep.equal({ w: 300, h: 600 }); - }); - - // it('should group media types per floor', () => { - // const request = spec.buildRequests( - // multiImpBidRequests, - // bidderRequest - // ); - - // const firstImp = request[0].data.imp[0]; - - // expect(firstImp.banner.format).to.have.lengthOf(1); - // expect(firstImp.banner.format[0]).to.deep.equal({ w: 300, h: 250 }); - // expect(firstImp).to.have.property('native'); - // expect(firstImp).to.not.have.property('video'); - - // const secondImp = request[0].data.imp[1]; - - // expect(secondImp.banner.format).to.have.lengthOf(1); - // expect(secondImp.banner.format[0]).to.deep.equal({ w: 300, h: 600 }); - // expect(secondImp).to.not.have.property('native'); - // expect(secondImp).to.have.property('video'); - // }); - }) - - it('should return correct native properties from ORTB converter', () => { - if (FEATURES.NATIVE) { - const request = spec.buildRequests(nativeBidRequests, {})[0]; - const assets = JSON.parse(request.data.imp[0].native.request).assets; - - const asset1 = assets[0]; - expect(asset1.id).to.equal(0); - expect(asset1.required).to.equal(1); - expect(asset1.title).to.deep.equal({ 'len': 140 }); - - const asset2 = assets[1]; - expect(asset2.id).to.equal(1); - expect(asset2.required).to.equal(1); - expect(asset2.img).to.deep.equal({ 'type': 3, 'w': 300, 'h': 600 }); - - const asset3 = assets[2]; - expect(asset3.id).to.equal(2); - expect(asset3.required).to.equal(1); - expect(asset3.data).to.deep.equal({ 'type': 1 }) - } - }) - }); - - describe('interpretResponse', function () { - let request; - let response; - - describe('banner', () => { - beforeEach(() => { - request = spec.buildRequests(bidRequests, bidderRequest)[0]; - response = { - body: { - seatbid: [ - { - bid: [ - { - id: '123', - impid: 'bidId1', - w: 300, - h: 250, - price: 42, - crid: 'creative', - dealid: 'deal', - adomain: ['domain.com'], - adm: 'markup', - }, - { - id: '456', - impid: 'bidId2', - w: 640, - h: 480, - price: 42, - adm: 'vastTag', - }, - ], - }, - ], - }, - }; - }); - - it('should return a banner bid', () => { - const resp = spec.interpretResponse(response, request); - - const bannerBid = resp[0]; - expect(bannerBid.requestId).to.equal('bidId1'); - expect(bannerBid.width).to.equal(300); - expect(bannerBid.height).to.equal(250); - expect(bannerBid.cpm).to.equal(42); - expect(bannerBid.creativeId).to.equal('creative'); - expect(bannerBid.dealId).to.equal('deal'); - expect(bannerBid.mediaType).to.equal('banner'); - expect(bannerBid.currency).to.equal('USD'); - expect(bannerBid.netRevenue).to.equal(true); - expect(bannerBid.ttl).to.equal(360); - expect(bannerBid.ad).to.equal('markup'); - expect(bannerBid.meta.advertiserDomains).to.deep.equal(['domain.com']); - expect(bannerBid.vastXml).to.be.undefined; - }); - - it('should set requestId from impIdMap when isEqtvTest is true', () => { - setIsEqtvTest(true); - request = spec.buildRequests(bannerBidRequests, bidderRequest)[0] - response = { - body: { - seatbid: [ - { - bid: [ - { - id: 'abcd1234', - impid: 'aaaabbbbccccdd', - w: 300, - h: 250, - price: 42, - crid: 'creative', - dealid: 'deal', - adomain: ['domain.com'], - adm: 'markup', - }, - ], - }, - ], - }, - }; - - const impIdMap = getImpIdMap(); - impIdMap['aaaabbbbccccdd'] = 'abcd1234' - - const resp = spec.interpretResponse(response, request)[0]; - - expect(resp.requestId).to.equal('abcd1234') - }) - - it('should set ttl when bid.exp is a number > 0', () => { - request = spec.buildRequests(bannerBidRequests, bidderRequest)[0] - response = { - body: { - seatbid: [ - { - bid: [ - { - id: 'abcd1234', - impid: 'aaaabbbbccccdd', - w: 300, - h: 250, - price: 42, - crid: 'creative', - dealid: 'deal', - adomain: ['domain.com'], - adm: 'markup', - exp: 100 - }, - ], - }, - ], - }, - }; - - const resp = spec.interpretResponse(response, request)[0]; - expect(resp.ttl).to.equal(100); - }) - - it('should set ttl to 360 when bid.exp is a number <= 0', () => { - request = spec.buildRequests(bannerBidRequests, bidderRequest)[0] - response = { - body: { - seatbid: [ - { - bid: [ - { - id: 'abcd1234', - impid: 'aaaabbbbccccdd', - w: 300, - h: 250, - price: 42, - crid: 'creative', - dealid: 'deal', - adomain: ['domain.com'], - adm: 'markup', - exp: -1 - }, - ], - }, - ], - }, - }; - - const resp = spec.interpretResponse(response, request)[0]; - expect(resp.ttl).to.equal(360); - }) - - it('should return correct properties when fledgeAuctionEnabled is true and isEqtvTest is false', () => { - request = spec.buildRequests(bidRequests, bidderRequest)[0] - response = { - body: { - ext: { - auctionConfigs: { - key: 'value' - } - }, - seatbid: [ - { - bid: [ - { - id: 'abcd1234', - impid: 'aaaabbbbccccdd', - w: 300, - h: 250, - price: 42, - crid: 'creative', - dealid: 'deal', - adomain: ['domain.com'], - adm: 'markup', - exp: -1 - }, - { - id: 'efgh5678', - impid: 'ddeeeeffffgggg', - w: 300, - h: 250, - price: 42, - crid: 'creative', - dealid: 'deal', - adomain: ['domain.com'], - adm: 'markup', - exp: -1 - }, - ], - }, - ], - }, - }; - - const resp = spec.interpretResponse(response, request); - expect(resp.bids.length).to.equal(2); - expect(resp.paapi).to.deep.equal({ 'key': 'value' }) - }) - }); - - describe('video', () => { - beforeEach(() => { - request = spec.buildRequests(bidRequests, bidderRequest)[1]; - response = { - body: { - seatbid: [ - { - bid: [ - { - id: '456', - impid: 'bidId2', - w: 640, - h: 480, - price: 42, - adm: 'vastTag', - }, - ], - }, - ], - }, - }; - }); - - it('should return a video bid', () => { - const resp = spec.interpretResponse(response, request); - - const bannerBid = resp[0]; - expect(bannerBid.requestId).to.equal('bidId2'); - expect(bannerBid.width).to.equal(640); - expect(bannerBid.height).to.equal(480); - expect(bannerBid.cpm).to.equal(42); - expect(bannerBid.creativeId).to.be.undefined; - expect(bannerBid.dealId).to.be.null; - expect(bannerBid.mediaType).to.equal('video'); - expect(bannerBid.currency).to.equal('USD'); - expect(bannerBid.netRevenue).to.equal(true); - expect(bannerBid.ttl).to.equal(3600); - expect(bannerBid.ad).to.equal('vastTag'); - expect(bannerBid.meta.advertiserDomains).to.deep.equal([]); - expect(bannerBid.vastXml).to.equal('vastTag'); - }); - }); - - describe('native', () => { - beforeEach(() => { - request = spec.buildRequests(nativeBidRequests, bidderRequest)[0]; - response = { - body: { - seatbid: [ - { - bid: [ - { - id: '456', - impid: 'bidId2', - w: 640, - h: 480, - price: 42, - adm: '{"ad": "ad"}', - }, - ], - }, - ], - }, - }; - }); - - it('should set correct ortb property', () => { - const resp = spec.interpretResponse(response, request)[0]; - - expect(resp.native.ortb).to.deep.equal({ 'ad': 'ad' }) - }) - }) - - describe('meta object', () => { - beforeEach(() => { - request = spec.buildRequests(bidRequests, bidderRequest)[0]; - response = { - body: { - seatbid: [ - { - bid: [ - { - id: '123', - impid: 'bidId1', - w: 300, - h: 250, - price: 42, - crid: 'creative', - dealid: 'deal', - adomain: ['domain.com'], - adm: 'markup', - }, - ], - }, - ], - }, - }; - }); - - it("should have null optional fields when the response's optional seatbid[].bid[].ext field is empty", () => { - const bid = spec.interpretResponse(response, request)[0]; - - expect(bid.meta.networkId).to.be.null; - expect(bid.meta.networkName).to.be.null; - expect(bid.meta.agencyId).to.be.null; - expect(bid.meta.agencyName).to.be.null; - expect(bid.meta.advertiserId).to.be.null; - expect(bid.meta.advertiserName).to.be.null; - expect(bid.meta.brandId).to.be.null; - expect(bid.meta.brandName).to.be.null; - expect(bid.meta.demandSource).to.be.null; - expect(bid.meta.dchain).to.be.null; - expect(bid.meta.primaryCatId).to.be.null; - expect(bid.meta.secondaryCatIds).to.be.null; - expect(bid.meta.mediaType).to.be.null; - }); - - it("should have populated fields when the response's optional seatbid[].bid[].ext fields are filled", () => { - response.body.seatbid[0].bid[0].ext = { - networkId: 'my network id', - networkName: 'my network name', - agencyId: 'my agency id', - agencyName: 'my agency name', - advertiserId: 'my advertiser id', - advertiserName: 'my advertiser name', - brandId: 'my brand id', - brandName: 'my brand name', - demandSource: 'my demand source', - dchain: { 'my key': 'my value' }, - primaryCatId: 'my primary cat id', - secondaryCatIds: ['my', 'secondary', 'cat', 'ids'], - mediaType: 'my media type', - }; - - const bid = spec.interpretResponse(response, request)[0]; - - expect(bid.meta.networkId).to.equal('my network id'); - expect(bid.meta.networkName).to.equal('my network name'); - expect(bid.meta.agencyId).to.equal('my agency id'); - expect(bid.meta.agencyName).to.equal('my agency name'); - expect(bid.meta.advertiserId).to.equal('my advertiser id'); - expect(bid.meta.advertiserName).to.equal('my advertiser name'); - expect(bid.meta.brandId).to.equal('my brand id'); - expect(bid.meta.brandName).to.equal('my brand name'); - expect(bid.meta.demandSource).to.equal('my demand source'); - expect(bid.meta.dchain).to.deep.equal({ 'my key': 'my value' }); - expect(bid.meta.primaryCatId).to.equal('my primary cat id'); - expect(bid.meta.secondaryCatIds).to.deep.equal(['my', 'secondary', 'cat', 'ids']); - expect(bid.meta.mediaType).to.equal('my media type'); - }); - }); - }); - - describe('getUserSyncs', function () { - const cookieSyncs = ['cookieUrl1', 'cookieUrl2', 'cookieUrl3']; - const serverResponses = [{ body: { cookieSyncUrls: cookieSyncs } }]; - let handleCookieSyncStub; - - const SAMPLE_RESPONSE = { - body: { - id: '12h712u7-k22g-8124-ab7a-h268s22dy271', - seatbid: [ - { - bid: [ - { - id: '1bh7jku7-ko2g-8654-ab72-h268shvwy271', - impid: 'r12gwgf231', - price: 0.6565, - adm: '

AD

', - adomain: ['abc.com'], - cid: '1242512', - crid: '535231', - w: 300, - h: 600, - mtype: 1, - cat: ['IAB19', 'IAB19-1'], - cattax: 1, - }, - ], - seat: '4212', - }, - ], - cur: 'USD', - statuscode: 0, - }, - }; - - beforeEach(() => { - handleCookieSyncStub = sinon.stub(equativUtils, 'handleCookieSync'); - }); - afterEach(() => { - handleCookieSyncStub.restore(); - }); - - it('should call handleCookieSync with correct parameters and return its result', () => { - setIsEqtvTest(true); - - const expectedResult = [ - { type: 'iframe', url: 'https://sync.example.com' }, - ]; - - handleCookieSyncStub.returns(expectedResult) - - const result = spec.getUserSyncs({ iframeEnabled: true }, - SAMPLE_RESPONSE, - { gdprApplies: true, vendorData: { vendor: { consents: {} } } }); - - sinon.assert.calledWithMatch( - handleCookieSyncStub, - { iframeEnabled: true }, - SAMPLE_RESPONSE, - { gdprApplies: true, vendorData: { vendor: { consents: {} } } }, - sinon.match.number, - sinon.match.object - ); - - expect(result).to.deep.equal(expectedResult); - }); - - it('should not call handleCookieSync and return undefined when isEqtvTest is false', () => { - setIsEqtvTest(false); - - spec.getUserSyncs({}, {}, {}); - - sinon.assert.notCalled(handleCookieSyncStub); - }); - - it('returns an array of correctly formatted user syncs', function () { - const syncArray = spec.getUserSyncs({ pixelEnabled: true }, serverResponses); - expect(syncArray).to.deep.equal([ - { type: 'image', url: 'cookieUrl1' }, - { type: 'image', url: 'cookieUrl2' }, - { type: 'image', url: 'cookieUrl3' }, - ]); - }); - - it('returns an empty array if serverResponses is empty', function () { - const syncArray = spec.getUserSyncs({ pixelEnabled: true }, []); - expect(syncArray).to.be.an('array').that.is.empty; - }); - - it('returns an empty array if the body is null', function () { - const syncArray = spec.getUserSyncs({ pixelEnabled: true }, [{ body: null }]); - expect(syncArray).to.be.an('array').that.is.empty; - }); - - it('returns an empty array if the body.cookieSyncUrls is missing', function () { - const syncArray = spec.getUserSyncs({ pixelEnabled: true }, [{ body: { creatives: ['creative'] } }]); - expect(syncArray).to.be.an('array').that.is.empty; - }); - - it('returns an empty array if pixels are not enabled', function () { - const syncArray = spec.getUserSyncs({ pixelEnabled: false }, serverResponses); - expect(syncArray).to.be.an('array').that.is.empty; - }); - }); - }); -}); diff --git a/test/spec/modules/shinezBidAdapter_spec.js b/test/spec/modules/shinezBidAdapter_spec.js deleted file mode 100644 index b5976fbc7..000000000 --- a/test/spec/modules/shinezBidAdapter_spec.js +++ /dev/null @@ -1,608 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/shinezBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import {BANNER, NATIVE, VIDEO} from '../../../src/mediaTypes.js'; -import * as utils from 'src/utils.js'; -import {decorateAdUnitsWithNativeParams} from '../../../src/native.js'; - -const ENDPOINT = 'https://hb.sweetgum.io/hb-sz-multi'; -const TEST_ENDPOINT = 'https://hb.sweetgum.io/hb-multi-sz-test'; -const TTL = 360; -/* eslint no-console: ["error", { allow: ["log", "warn", "error"] }] */ - -describe('shinezAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [['640', '480']], - 'params': { - 'org': 'jdye8weeyirk00000001' - } - }; - - it('should return true when required params are passed', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not found', function () { - const newBid = Object.assign({}, bid); - delete newBid.params; - newBid.params = { - 'org': null - }; - expect(spec.isBidRequestValid(newBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[640, 480]], - 'params': { - 'org': 'jdye8weeyirk00000001' - }, - 'bidId': '299ffc8cca0b87', - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'video': { - 'playerSize': [[640, 480]], - 'context': 'instream' - } - }, - }, - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'params': { - 'org': 'jdye8weeyirk00000001' - }, - 'bidId': '299ffc8cca0b87', - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'banner': { - } - }, - }, - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'params': { - 'org': 'jdye8weeyirk00000001' - }, - 'bidId': '299ffc8cca0b87', - 'loop': 1, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ 300, 250 ] - ] - }, - 'video': { - 'playerSize': [[640, 480]], - 'context': 'instream', - 'plcmt': 1 - }, - 'native': { - 'ortb': { - 'assets': [ - { - 'id': 1, - 'required': 1, - 'img': { - 'type': 3, - 'w': 300, - 'h': 200, - } - }, - { - 'id': 2, - 'required': 1, - 'title': { - 'len': 80 - } - }, - { - 'id': 3, - 'required': 1, - 'data': { - 'type': 1 - } - } - ] - } - }, - }, - } - ]; - - const testModeBidRequests = [ - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[640, 480]], - 'params': { - 'org': 'jdye8weeyirk00000001', - 'testMode': true - }, - 'bidId': '299ffc8cca0b87', - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - } - ]; - - const bidderRequest = { - bidderCode: 'shinez', - } - const placementId = '12345678'; - - it('sends the placementId to ENDPOINT via POST', function () { - bidRequests[0].params.placementId = placementId; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].placementId).to.equal(placementId); - }); - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('sends bid request to TEST ENDPOINT via POST', function () { - const request = spec.buildRequests(testModeBidRequests, bidderRequest); - expect(request.url).to.equal(TEST_ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('should send the correct bid Id', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].bidId).to.equal('299ffc8cca0b87'); - }); - - it('should send the correct sizes array', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].sizes).to.be.an('array'); - expect(request.data.bids[0].sizes).to.equal(bidRequests[0].sizes) - expect(request.data.bids[1].sizes).to.be.an('array'); - expect(request.data.bids[1].sizes).to.equal(bidRequests[1].sizes) - expect(request.data.bids[2].sizes).to.be.an('array'); - expect(request.data.bids[2].sizes).to.eql(bidRequests[2].sizes) - }); - - it('should send nativeOrtbRequest in native bid request', function () { - decorateAdUnitsWithNativeParams(bidRequests) - const request = spec.buildRequests(bidRequests, bidderRequest); - assert.deepEqual(request.data.bids[2].nativeOrtbRequest, bidRequests[2].mediaTypes.native.ortb) - }); - - it('should send the correct media type', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].mediaType).to.equal(VIDEO) - expect(request.data.bids[1].mediaType).to.equal(BANNER) - expect(request.data.bids[2].mediaType.split(',')).to.include.members([VIDEO, NATIVE, BANNER]) - }); - - it('should respect syncEnabled option', function() { - config.setConfig({ - userSync: { - syncEnabled: false, - filterSettings: { - all: { - bidders: '*', - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('cs_method'); - }); - - it('should respect "iframe" filter settings', function () { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - iframe: { - bidders: [spec.code], - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'iframe'); - }); - - it('should respect "all" filter settings', function () { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - all: { - bidders: [spec.code], - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'iframe'); - }); - - it('should send the pixel user sync param if userSync is enabled and no "iframe" or "all" configs are present', function () { - config.resetConfig(); - config.setConfig({ - userSync: { - syncEnabled: true, - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'pixel'); - }); - - it('should respect total exclusion', function() { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - image: { - bidders: [spec.code], - filter: 'exclude' - }, - iframe: { - bidders: [spec.code], - filter: 'exclude' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('cs_method'); - }); - - it('should have us_privacy param if usPrivacy is available in the bidRequest', function () { - const bidderRequestWithUSP = Object.assign({uspConsent: '1YNN'}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithUSP); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('us_privacy', '1YNN'); - }); - - it('should have an empty us_privacy param if usPrivacy is missing in the bidRequest', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('us_privacy'); - }); - - it('should not send the gdpr param if gdprApplies is false in the bidRequest', function () { - const bidderRequestWithGDPR = Object.assign({gdprConsent: {gdprApplies: false}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('gdpr'); - expect(request.data.params).to.not.have.property('gdpr_consent'); - }); - - it('should send the gdpr param if gdprApplies is true in the bidRequest', function () { - const bidderRequestWithGDPR = Object.assign({gdprConsent: {gdprApplies: true, consentString: 'test-consent-string'}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('gdpr', true); - expect(request.data.params).to.have.property('gdpr_consent', 'test-consent-string'); - }); - - it('should have schain param if it is available in the bidRequest', () => { - bidderRequest.ortb2 = { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [{ asi: 'indirectseller.com', sid: '00001', hp: 1 }], - } - } - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('schain', '1.0,1!indirectseller.com,00001,1,,,'); - }); - - it('should set flooPrice to getFloor.floor value if it is greater than params.floorPrice', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.getFloor = () => { - return { - currency: 'USD', - floor: 3.32 - } - } - bid.params.floorPrice = 0.64; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0]).to.be.an('object'); - expect(request.data.bids[0]).to.have.property('floorPrice', 3.32); - }); - - it('should set floorPrice to params.floorPrice value if it is greater than getFloor.floor', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.getFloor = () => { - return { - currency: 'USD', - floor: 0.8 - } - } - bid.params.floorPrice = 1.5; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0]).to.be.an('object'); - expect(request.data.bids[0]).to.have.property('floorPrice', 1.5); - }); - }); - - describe('interpretResponse', function () { - const response = { - params: { - currency: 'USD', - netRevenue: true, - }, - bids: [{ - cpm: 12.5, - vastXml: '', - width: 640, - height: 480, - requestId: '21e12606d47ba7', - adomain: ['abc.com'], - creativeId: 'creative-id', - nurl: 'http://example.com/win/1234', - mediaType: VIDEO - }, - { - cpm: 12.5, - ad: '""', - width: 300, - height: 250, - requestId: '21e12606d47ba7', - adomain: ['abc.com'], - creativeId: 'creative-id', - nurl: 'http://example.com/win/1234', - mediaType: BANNER - }, - { - cpm: 12.5, - width: 300, - height: 200, - requestId: '21e12606d47ba7', - adomain: ['abc.com'], - creativeId: 'creative-id', - nurl: 'http://example.com/win/1234', - mediaType: NATIVE, - native: { - body: 'Advertise with Rise', - clickUrl: 'https://risecodes.com', - cta: 'Start now', - image: { - width: 300, - height: 200, - url: 'https://sdk.streamrail.com/media/rise-image.jpg' - }, - sponsoredBy: 'Rise', - title: 'Rise Ad Tech Solutions' - } - }] - }; - - const expectedVideoResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 640, - height: 480, - ttl: TTL, - creativeId: 'creative-id', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: VIDEO, - meta: { - mediaType: VIDEO, - advertiserDomains: ['abc.com'] - }, - vastXml: '', - }; - - const expectedBannerResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 300, - height: 250, - ttl: TTL, - creativeId: 'creative-id', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: BANNER, - meta: { - mediaType: BANNER, - advertiserDomains: ['abc.com'] - }, - ad: '""' - }; - - const expectedNativeResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 300, - height: 200, - ttl: TTL, - creativeId: 'creative-id', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: NATIVE, - meta: { - mediaType: NATIVE, - advertiserDomains: ['abc.com'] - }, - native: { - ortb: { - body: 'Advertise with Rise', - clickUrl: 'https://risecodes.com', - cta: 'Start now', - image: { - width: 300, - height: 200, - url: 'https://sdk.streamrail.com/media/rise-image.jpg', - }, - sponsoredBy: 'Rise', - title: 'Rise Ad Tech Solutions' - } - }, - }; - - it('should get correct bid response', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[0]).to.deep.equal(expectedVideoResponse); - expect(result[1]).to.deep.equal(expectedBannerResponse); - expect(result[2]).to.deep.equal(expectedNativeResponse); - }); - - it('video type should have vastXml key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[0].vastXml).to.equal(expectedVideoResponse.vastXml) - }); - - it('banner type should have ad key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[1].ad).to.equal(expectedBannerResponse.ad) - }); - - it('native type should have native key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[2].native).to.eql(expectedNativeResponse.native) - }); - }) - - describe('getUserSyncs', function() { - const imageSyncResponse = { - body: { - params: { - userSyncPixels: [ - 'https://image-sync-url.test/1', - 'https://image-sync-url.test/2', - 'https://image-sync-url.test/3' - ] - } - } - }; - - const iframeSyncResponse = { - body: { - params: { - userSyncURL: 'https://iframe-sync-url.test' - } - } - }; - - it('should register all img urls from the response', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true }, [imageSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'image', - url: 'https://image-sync-url.test/1' - }, - { - type: 'image', - url: 'https://image-sync-url.test/2' - }, - { - type: 'image', - url: 'https://image-sync-url.test/3' - } - ]); - }); - - it('should register the iframe url from the response', function() { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [iframeSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://iframe-sync-url.test' - } - ]); - }); - - it('should register both image and iframe urls from the responses', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, [iframeSyncResponse, imageSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://iframe-sync-url.test' - }, - { - type: 'image', - url: 'https://image-sync-url.test/1' - }, - { - type: 'image', - url: 'https://image-sync-url.test/2' - }, - { - type: 'image', - url: 'https://image-sync-url.test/3' - } - ]); - }); - - it('should handle an empty response', function() { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, []); - expect(syncs).to.deep.equal([]); - }); - - it('should handle when user syncs are disabled', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: false }, [imageSyncResponse]); - expect(syncs).to.deep.equal([]); - }); - }) - - describe('onBidWon', function() { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - - it('Should trigger pixel if bid nurl', function() { - const bid = { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [['640', '480']], - 'nurl': 'http://example.com/win/1234', - 'params': { - 'org': 'jdye8weeyirk00000001' - } - }; - - spec.onBidWon(bid); - expect(utils.triggerPixel.callCount).to.equal(1) - }) - }) -}); diff --git a/test/spec/modules/shinezRtbBidAdapter_spec.js b/test/spec/modules/shinezRtbBidAdapter_spec.js deleted file mode 100644 index 443999989..000000000 --- a/test/spec/modules/shinezRtbBidAdapter_spec.js +++ /dev/null @@ -1,763 +0,0 @@ -import {expect} from 'chai'; -import { - spec as adapter, - createDomain, - storage -} from 'modules/shinezRtbBidAdapter'; -import { - hashCode, - extractPID, - extractCID, - extractSubDomain, - getStorageItem, - setStorageItem, - tryParseJSON, - getUniqueDealId, -} from '../../../libraries/vidazooUtils/bidderUtils.js'; -import {parseUrl, deepClone} from 'src/utils.js'; -import {version} from 'package.json'; -import {useFakeTimers} from 'sinon'; -import {BANNER, VIDEO} from '../../../src/mediaTypes.js'; -import {config} from '../../../src/config.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; -import * as utils from 'src/utils.js'; - -export const TEST_ID_SYSTEMS = ['criteoId', 'id5id', 'idl_env', 'lipb', 'netId', 'pubcid', 'tdid', 'pubProvidedId']; - -const SUB_DOMAIN = 'exchange'; - -const BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': 'div-gpt-ad-12345-0', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '59db6b3b4ffaa70004f45cdc', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1, - 'ext': { - 'param1': 'loremipsum', - 'param2': 'dolorsitamet' - } - }, - 'placementCode': 'div-gpt-ad-1460505748561-0', - 'sizes': [[300, 250], [300, 600]], - 'bidderRequestId': '1fdb5ff1b6eaa7', - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'requestId': 'b0777d85-d061-450e-9bc7-260dd54bbb7a', - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'mediaTypes': [BANNER], - 'ortb2Imp': { - 'ext': { - 'gpid': '0123456789', - 'tid': 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf' - } - } -}; - -const VIDEO_BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': '63550ad1ff6642d368cba59dh5884270560', - 'bidderRequestId': '12a8ae9ada9c13', - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '635509f7ff6642d368cb9837', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1 - }, - 'sizes': [[545, 307]], - 'mediaTypes': { - 'video': { - 'playerSize': [[545, 307]], - 'context': 'instream', - 'mimes': [ - 'video/mp4', - 'application/javascript' - ], - 'protocols': [2, 3, 5, 6], - 'maxduration': 60, - 'minduration': 0, - 'startdelay': 0, - 'linearity': 1, - 'api': [2], - 'placement': 1 - } - }, - 'ortb2Imp': { - 'ext': { - 'gpid': '0123456789', - 'tid': '56e184c6-bde9-497b-b9b9-cf47a61381ee' - } - } -} - -const ORTB2_DEVICE = { - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - ext: {fiftyonedegrees_deviceId: '17595-133085-133468-18092'}, -}; - -const BIDDER_REQUEST = { - 'gdprConsent': { - 'consentString': 'consent_string', - 'gdprApplies': true - }, - 'gppConsent': { - 'gppString': 'gpp_string', - 'applicableSections': [7] - }, - 'uspConsent': 'consent_string', - 'refererInfo': { - 'page': 'https://www.greatsite.com', - 'ref': 'https://www.somereferrer.com' - }, - 'ortb2': { - 'site': { - 'content': { - 'language': 'en' - } - }, - 'regs': { - 'gpp': 'gpp_string', - 'gpp_sid': [7], - 'coppa': 0 - }, - 'device': ORTB2_DEVICE, - } -}; - -const SERVER_RESPONSE = { - body: { - cid: 'testcid123', - results: [{ - 'ad': '', - 'price': 0.8, - 'creativeId': '12610997325162499419', - 'exp': 30, - 'width': 300, - 'height': 250, - 'advertiserDomains': ['securepubads.g.doubleclick.net'], - 'cookies': [{ - 'src': 'https://sync.com', - 'type': 'iframe' - }, { - 'src': 'https://sync.com', - 'type': 'img' - }] - }] - } -}; - -const VIDEO_SERVER_RESPONSE = { - body: { - 'cid': '635509f7ff6642d368cb9837', - 'results': [{ - 'ad': '', - 'advertiserDomains': ['sweetgum.io'], - 'exp': 60, - 'width': 545, - 'height': 307, - 'mediaType': 'video', - 'creativeId': '12610997325162499419', - 'price': 2, - 'cookies': [] - }] - } -}; - -const ORTB2_OBJ = { - "device": ORTB2_DEVICE, - "regs": {"coppa": 0, "gpp": "gpp_string", "gpp_sid": [7]}, - "site": {"content": {"language": "en"} - } -}; - -const REQUEST = { - data: { - width: 300, - height: 250, - bidId: '2d52001cabd527' - } -}; - -function getTopWindowQueryParams() { - try { - const parsedUrl = parseUrl(window.top.document.URL, {decodeSearchAsString: true}); - return parsedUrl.search; - } catch (e) { - return ''; - } -} - -describe('ShinezRtbBidAdapter', function () { - before(() => config.resetConfig()); - after(() => config.resetConfig()); - - describe('validtae spec', function () { - it('exists and is a function', function () { - expect(adapter.isBidRequestValid).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.buildRequests).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.interpretResponse).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.getUserSyncs).to.exist.and.to.be.a('function'); - }); - - it('exists and is a string', function () { - expect(adapter.code).to.exist.and.to.be.a('string'); - }); - - it('exists and contains media types', function () { - expect(adapter.supportedMediaTypes).to.exist.and.to.be.an('array').with.length(2); - expect(adapter.supportedMediaTypes).to.contain.members([BANNER, VIDEO]); - }); - }); - - describe('validate bid requests', function () { - it('should require cId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - pId: 'pid' - } - }); - expect(isValid).to.be.false; - }); - - it('should require pId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid' - } - }); - expect(isValid).to.be.false; - }); - - it('should validate correctly', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid', - pId: 'pid' - } - }); - expect(isValid).to.be.true; - }); - }); - - describe('build requests', function () { - let sandbox; - before(function () { - getGlobal().bidderSettings = { - shinezRtb: { - storageAllowed: true - } - }; - sandbox = sinon.createSandbox(); - sandbox.stub(Date, 'now').returns(1000); - }); - - it('should build video request', function () { - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - config.setConfig({ - bidderTimeout: 3000, - enableTIDs: true - }); - const requests = adapter.buildRequests([VIDEO_BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/635509f7ff6642d368cb9837`, - data: { - adUnitCode: '63550ad1ff6642d368cba59dh5884270560', - bidFloor: 0.1, - bidId: '2d52001cabd527', - bidderVersion: adapter.version, - bidderRequestId: '12a8ae9ada9c13', - cb: 1000, - gdpr: 1, - gdprConsent: 'consent_string', - usPrivacy: 'consent_string', - gppString: 'gpp_string', - gppSid: [7], - transactionId: '56e184c6-bde9-497b-b9b9-cf47a61381ee', - prebidVersion: version, - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - publisherId: '59ac17c192832d0011283fe3', - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - res: `${window.top.screen.width}x${window.top.screen.height}`, - schain: VIDEO_BID.schain, - sizes: ['545x307'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - uqs: getTopWindowQueryParams(), - mediaTypes: { - video: { - api: [2], - context: 'instream', - linearity: 1, - maxduration: 60, - mimes: [ - 'video/mp4', - 'application/javascript' - ], - minduration: 0, - placement: 1, - playerSize: [[545, 307]], - protocols: [2, 3, 5, 6], - startdelay: 0 - } - }, - gpid: '0123456789', - cat: [], - contentLang: 'en', - contentData: [], - isStorageAllowed: true, - pagecat: [], - ortb2Imp: VIDEO_BID.ortb2Imp, - ortb2: ORTB2_OBJ, - userData: [], - coppa: 0 - } - }); - }); - - it('should build banner request for each size', function () { - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - config.setConfig({ - bidderTimeout: 3000, - enableTIDs: true - }); - const requests = adapter.buildRequests([BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/59db6b3b4ffaa70004f45cdc`, - data: { - gdprConsent: 'consent_string', - gdpr: 1, - gppString: 'gpp_string', - gppSid: [7], - usPrivacy: 'consent_string', - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - bidderRequestId: '1fdb5ff1b6eaa7', - transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - sizes: ['300x250', '300x600'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - cb: 1000, - bidFloor: 0.1, - bidId: '2d52001cabd527', - adUnitCode: 'div-gpt-ad-12345-0', - publisherId: '59ac17c192832d0011283fe3', - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - bidderVersion: adapter.version, - prebidVersion: version, - schain: BID.schain, - res: `${window.top.screen.width}x${window.top.screen.height}`, - mediaTypes: [BANNER], - gpid: '0123456789', - uqs: getTopWindowQueryParams(), - 'ext.param1': 'loremipsum', - 'ext.param2': 'dolorsitamet', - cat: [], - contentLang: 'en', - contentData: [], - isStorageAllowed: true, - pagecat: [], - ortb2Imp: BID.ortb2Imp, - ortb2: ORTB2_OBJ, - userData: [], - coppa: 0 - } - }); - }); - - after(function () { - getGlobal().bidderSettings = {}; - sandbox.restore(); - }); - }); - describe('getUserSyncs', function () { - it('should have valid user sync with iframeEnabled', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.sweetgum.io/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - - it('should have valid user sync with cid on response', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.sweetgum.io/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - - it('should have valid user sync with pixelEnabled', function () { - const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE]); - - expect(result).to.deep.equal([{ - 'url': 'https://sync.sweetgum.io/api/sync/image/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0', - 'type': 'image' - }]); - }); - - it('should have valid user sync with coppa on response', function () { - config.setConfig({ - coppa: 1 - }); - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.sweetgum.io/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=1' - }]); - }); - }); - - describe('interpret response', function () { - it('should return empty array when there is no response', function () { - const responses = adapter.interpretResponse(null); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no ad', function () { - const responses = adapter.interpretResponse({price: 1, ad: ''}); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no price', function () { - const responses = adapter.interpretResponse({price: null, ad: 'great ad'}); - expect(responses).to.be.empty; - }); - - it('should return an array of interpreted banner responses', function () { - const responses = adapter.interpretResponse(SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 0.8, - width: 300, - height: 250, - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 30, - ad: '', - meta: { - advertiserDomains: ['securepubads.g.doubleclick.net'] - } - }); - }); - - it('should get meta from response metaData', function () { - const serverResponse = deepClone(SERVER_RESPONSE); - serverResponse.body.results[0].metaData = { - advertiserDomains: ['sweetgum.io'], - agencyName: 'Agency Name', - }; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses[0].meta).to.deep.equal({ - advertiserDomains: ['sweetgum.io'], - agencyName: 'Agency Name' - }); - }); - - it('should return an array of interpreted video responses', function () { - const responses = adapter.interpretResponse(VIDEO_SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 2, - width: 545, - height: 307, - mediaType: 'video', - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 60, - vastXml: '', - meta: { - advertiserDomains: ['sweetgum.io'] - } - }); - }); - - it('should take default TTL', function () { - const serverResponse = deepClone(SERVER_RESPONSE); - delete serverResponse.body.results[0].exp; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0].ttl).to.equal(300); - }); - }); - - describe('user id system', function () { - TEST_ID_SYSTEMS.forEach((idSystemProvider) => { - const id = Date.now().toString(); - const bid = deepClone(BID); - - const userId = (function () { - switch (idSystemProvider) { - case 'lipb': - return {lipbid: id}; - case 'id5id': - return {uid: id}; - default: - return id; - } - })(); - - bid.userId = { - [idSystemProvider]: userId - }; - - it(`should include 'uid.${idSystemProvider}' in request params`, function () { - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data[`uid.${idSystemProvider}`]).to.equal(id); - }); - }); - // testing bid.userIdAsEids handling - it("should include user ids from bid.userIdAsEids (length=1)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - }) - it("should include user ids from bid.userIdAsEids (length=2)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - }, - { - "source": "rwdcntrl.net", - "uids": [{"id": "fakeid6f35197d5c", "atype": 1}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - expect(requests[0].data['uid.rwdcntrl.net']).to.equal("fakeid6f35197d5c"); - }) - // testing user.ext.eid handling - it("should include user ids from user.ext.eid (length=1)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - }) - it("should include user ids from user.ext.eid (length=2)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - }, - { - "source": "adserver.org", - "uids": [{"id": "fakeid495ff1"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - expect(requests[0].data['uid.adserver.org']).to.equal("fakeid495ff1"); - }) - }); - - describe('alternate param names extractors', function () { - it('should return undefined when param not supported', function () { - const cid = extractCID({'c_id': '1'}); - const pid = extractPID({'p_id': '1'}); - const subDomain = extractSubDomain({'sub_domain': 'prebid'}); - expect(cid).to.be.undefined; - expect(pid).to.be.undefined; - expect(subDomain).to.be.undefined; - }); - - it('should return value when param supported', function () { - const cid = extractCID({'cID': '1'}); - const pid = extractPID({'Pid': '2'}); - const subDomain = extractSubDomain({'subDOMAIN': 'prebid'}); - expect(cid).to.be.equal('1'); - expect(pid).to.be.equal('2'); - expect(subDomain).to.be.equal('prebid'); - }); - }); - - describe('unique deal id', function () { - before(function () { - getGlobal().bidderSettings = { - shinezRtb: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - const key = 'myKey'; - let uniqueDealId; - beforeEach(() => { - uniqueDealId = getUniqueDealId(storage, key, 0); - }) - - it('should get current unique deal id', function (done) { - // waiting some time so `now` will become past - setTimeout(() => { - const current = getUniqueDealId(storage, key); - expect(current).to.be.equal(uniqueDealId); - done(); - }, 200); - }); - - it('should get new unique deal id on expiration', function (done) { - setTimeout(() => { - const current = getUniqueDealId(storage, key, 100); - expect(current).to.not.be.equal(uniqueDealId); - done(); - }, 200) - }); - }); - - describe('storage utils', function () { - before(function () { - getGlobal().bidderSettings = { - shinezRtb: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - it('should get value from storage with create param', function () { - const now = Date.now(); - const clock = useFakeTimers({ - shouldAdvanceTime: true, - now - }); - setStorageItem(storage, 'myKey', 2020); - const {value, created} = getStorageItem(storage, 'myKey'); - expect(created).to.be.equal(now); - expect(value).to.be.equal(2020); - expect(typeof value).to.be.equal('number'); - expect(typeof created).to.be.equal('number'); - clock.restore(); - }); - - it('should get external stored value', function () { - const value = 'superman' - window.localStorage.setItem('myExternalKey', value); - const item = getStorageItem(storage, 'myExternalKey'); - expect(item).to.be.equal(value); - }); - - it('should parse JSON value', function () { - const data = JSON.stringify({event: 'send'}); - const {event} = tryParseJSON(data); - expect(event).to.be.equal('send'); - }); - - it('should get original value on parse fail', function () { - const value = 21; - const parsed = tryParseJSON(value); - expect(typeof parsed).to.be.equal('number'); - expect(parsed).to.be.equal(value); - }); - }); -}); diff --git a/test/spec/modules/showheroes-bsBidAdapter_spec.js b/test/spec/modules/showheroes-bsBidAdapter_spec.js deleted file mode 100644 index 290447c37..000000000 --- a/test/spec/modules/showheroes-bsBidAdapter_spec.js +++ /dev/null @@ -1,362 +0,0 @@ -import { expect } from 'chai' -import { spec } from 'modules/showheroes-bsBidAdapter.js' -import { addFPDToBidderRequest } from '../../helpers/fpd.js'; -import { getGlobal } from '../../../src/prebidGlobal.js'; -import 'modules/priceFloors.js'; -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; -import { VIDEO } from 'src/mediaTypes.js' - -const bidderRequest = { - refererInfo: { - page: 'https://example.com/home', - ref: 'https://referrer' - } -} - -const adomain = ['showheroes.com']; - -const gdpr = { - gdprConsent: { - apiVersion: 2, - consentString: 'CONSENT', - vendorData: { purpose: { consents: { 1: true } } }, - gdprApplies: true, - } -} - -const uspConsent = '1---'; - -const schain = { - schain: { - validation: 'strict', - config: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'some.com', - sid: '00001', - hp: 1 - } - ] - } - } -} - -const bidRequestCommonParamsV2 = { - bidder: 'showheroes-bs', - params: { - unitId: 'AACBWAcof-611K4U', - }, - adUnitCode: 'adunit-code-1', - bidId: '38b373e1e31c18', - bidderRequestId: '12e3ade2543ba6', - auctionId: '43aa080090a47f', -} - -const bidRequestVideoV2 = { - ...bidRequestCommonParamsV2, - ...{ - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'instream', - } - } - } -} - -const bidRequestOutstreamV2 = { - ...bidRequestCommonParamsV2, - ...{ - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'outstream' - }, - } - } -} - -const bidRequestBannerV2 = { - ...bidRequestCommonParamsV2, - ...{ - mediaTypes: { - banner: { - sizes: [[300, 250]], - } - } - } -} - -describe('shBidAdapter', () => { - before(() => { - // without this change in the Renderer.js file exception is thrown - // because 'adUnits' is undefined, and there is a call that does - // 'pbjs.adUnits.find' in the Renderer.js file - getGlobal().adUnits = []; - }); - - it('validates request', () => { - const bid = { - params: { - testKey: 'testValue', - }, - }; - expect(spec.isBidRequestValid(bid)).to.eql(false); - bid.params = { - unitId: 'test_unit', - }; - expect(spec.isBidRequestValid(bid)).to.eql(true); - }); - - it('passes gdpr, usp, schain, floor in ortb request', async () => { - const bidRequest = Object.assign({}, bidRequestVideoV2) - const fullRequest = { - bids: [bidRequestVideoV2], - ...bidderRequest, - ...gdpr, - ...{uspConsent: uspConsent}, - ortb2: { - source: { - ext: {schain: schain.schain.config} - } - } - }; - bidRequest.ortb2 = { - source: { - ext: {schain: schain.schain.config} - } - }; - const getFloorResponse = {currency: 'EUR', floor: 3}; - bidRequest.getFloor = () => getFloorResponse; - const request = spec.buildRequests([bidRequest], await addFPDToBidderRequest(fullRequest)); - const payload = request.data; - expect(payload.regs.ext.gdpr).to.eql(Number(gdpr.gdprConsent.gdprApplies)); - expect(payload.regs.ext.us_privacy).to.eql(uspConsent); - expect(payload.user.ext.consent).to.eql(gdpr.gdprConsent.consentString); - expect(payload.source.ext.schain).to.deep.equal(bidRequest.ortb2.source.ext.schain); - expect(payload.test).to.eql(0); - expect(payload.imp[0].bidfloor).eql(3); - expect(payload.imp[0].bidfloorcur).eql('EUR'); - expect(payload.imp[0].displaymanager).eql('Prebid.js'); - expect(payload.site.page).to.eql('https://example.com/home'); - }); - - describe('interpretResponse', function () { - const vastXml = '' - - const callback_won = 'https://test.com/track/?ver=15&session_id=01ecd03ce381505ccdeb88e555b05001&category=request_session&type=event&request_session_id=01ecd03ce381505ccdeb88e555b05001&label=prebid_won&reason=ok' - const basicResponse = { - cur: 'EUR', - seatbid: [{ - bid: [{ - price: 1, - w: 640, - h: 480, - adm: vastXml, - impid: '38b373e1e31c18', - crid: 'c_38b373e1e31c18', - mtype: 2, // 2 = video - adomain: adomain, - ext: { - callbacks: { - won: [callback_won], - }, - extra: 'test', - }, - }], - seat: 'showheroes', - }] - } - const vastUrl = 'https://test.com/vast/?zid=AACBWAcof-611K4U&u=https://example.org/?foo=bar&gdpr=0&cs=XXXXXXXXXXXXXXXXXXXX&sid=01ecd03ce381505ccdeb88e555b05001&width=300&height=200&prebidmode=1' - - if (FEATURES.VIDEO) { - it('should get correct bid response when type is video (V2)', function () { - const request = spec.buildRequests([bidRequestVideoV2], bidderRequest) - const expectedResponse = [ - { - cpm: 1, - creativeId: 'c_38b373e1e31c18', - creative_id: 'c_38b373e1e31c18', - currency: 'EUR', - width: 640, - height: 480, - playerHeight: 480, - playerWidth: 640, - mediaType: 'video', - netRevenue: true, - requestId: '38b373e1e31c18', - ttl: 300, - meta: { - advertiserDomains: adomain - }, - vastXml: vastXml, - callbacks: { - won: [callback_won], - }, - extra: 'test', - } - ] - - const result = spec.interpretResponse({ 'body': basicResponse }, request) - expect(result).to.deep.equal(expectedResponse) - }) - - it('should get correct bid response when type is outstream (slot V2)', function () { - window.myRenderer = { - renderAd: function() { - return null; - } - } - const bidRequestV2 = JSON.parse(JSON.stringify(bidRequestOutstreamV2)); - const bidResponse = JSON.parse(JSON.stringify(basicResponse)); - bidResponse.seatbid[0].bid[0].ext.rendererConfig = { - rendererUrl: 'https://test.com/render.js', - renderFunc: 'myRenderer.renderAd', - renderOptions: { - key: 'my renderer custom value', - } - }; - const slotId = 'testSlot2' - - const container = document.createElement('div') - container.setAttribute('id', slotId) - document.body.appendChild(container) - - const request = spec.buildRequests([bidRequestV2], bidderRequest) - - const result = spec.interpretResponse({ 'body': bidResponse }, request) - const bid = result[0] - expect(bid).to.have.property('mediaType', VIDEO); - expect(typeof bid.renderer).to.be.eql('object'); - expect(bid.renderer.url).to.eql('https://test.com/render.js'); - - sinon.spy(window.myRenderer, 'renderAd'); - bid.renderer.render(bid); - - const renderCall = window.myRenderer.renderAd.getCall(0); - const renderPayload = renderCall.args[0]; - expect(renderPayload.adResponse.content).to.eql(vastXml); - expect(renderPayload.key).to.eql('my renderer custom value'); - }) - - it('should get correct bid response when type is outstream (customRender)', function () { - const bidRequest = JSON.parse(JSON.stringify(bidRequestOutstreamV2)); - - const request = spec.buildRequests([bidRequest], bidderRequest) - - const result = spec.interpretResponse({ 'body': basicResponse }, request) - const bid = result[0]; - expect(bid).to.have.property('mediaType', VIDEO); - - expect(bid.vastXml).to.eql(vastXml); - }) - - it('should get vast url', function () { - const bidRequest = JSON.parse(JSON.stringify(bidRequestOutstreamV2)); - const bidResponse = JSON.parse(JSON.stringify(basicResponse)); - bidResponse.seatbid[0].bid[0].nurl = vastUrl - - const request = spec.buildRequests([bidRequest], bidderRequest) - - const result = spec.interpretResponse({ 'body': bidResponse }, request) - const bid = result[0]; - expect(bid).to.have.property('mediaType', VIDEO); - - expect(bid.vastXml).to.eql(vastXml); - expect(bid.vastUrl).to.eql(vastUrl); - }) - } - - it('should get correct bid response when type is banner', function () { - const request = spec.buildRequests([bidRequestBannerV2], bidderRequest); - const bannerResponse = { - cur: 'EUR', - seatbid: [{ - bid: [{ - price: 1, - w: 300, - h: 250, - adm: '
test banner
', - impid: '38b373e1e31c18', - crid: 'c_38b373e1e31c18', - mtype: 1, // 1 = banner - adomain: adomain, - ext: { - callbacks: { - won: [callback_won], - }, - extra: 'test', - }, - }], - seat: 'showheroes', - }] - }; - - const expectedResponse = [ - { - cpm: 1, - creativeId: 'c_38b373e1e31c18', - creative_id: 'c_38b373e1e31c18', - currency: 'EUR', - width: 300, - height: 250, - mediaType: 'banner', - netRevenue: true, - requestId: '38b373e1e31c18', - ttl: 300, - meta: { - advertiserDomains: adomain, - }, - ad: '
test banner
', - callbacks: { - won: [callback_won], - }, - extra: 'test', - } - ]; - - const result = spec.interpretResponse({ 'body': bannerResponse }, request); - expect(result).to.deep.equal(expectedResponse); - }) - }); - - describe('getUserSyncs', function () { - const response = [{ - body: { - ext: { - userSync: { - iframes: ['https://sync.showheroes.com/iframe'], - pixels: ['https://sync.showheroes.com/pixel'] - } - } - } - }] - - it('empty', function () { - const result = spec.getUserSyncs({}, []); - - expect(result).to.deep.equal([]); - }); - - it('iframe', function () { - const result = spec.getUserSyncs({ - iframeEnabled: true - }, response); - - expect(result[0].type).to.equal('iframe'); - expect(result[0].url).to.equal('https://sync.showheroes.com/iframe'); - }); - - it('pixel', function () { - const result = spec.getUserSyncs({ - pixelEnabled: true - }, response); - - expect(result[0].type).to.equal('image'); - expect(result[0].url).to.equal('https://sync.showheroes.com/pixel'); - }); - }); -}); diff --git a/test/spec/modules/silvermobBidAdapter_spec.js b/test/spec/modules/silvermobBidAdapter_spec.js deleted file mode 100644 index 21cdea24d..000000000 --- a/test/spec/modules/silvermobBidAdapter_spec.js +++ /dev/null @@ -1,303 +0,0 @@ -import { expect } from 'chai'; -import {spec} from '../../../modules/silvermobBidAdapter.js'; -import 'modules/priceFloors.js'; -import { newBidder } from 'src/adapters/bidderFactory'; -import { config } from '../../../src/config.js'; -import { addFPDToBidderRequest } from '../../helpers/fpd.js'; - -// load modules that register ORTB processors -import 'src/prebid.js'; -import 'modules/currency.js'; -import 'modules/userId/index.js'; -import 'modules/multibid/index.js'; - -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; - -const SIMPLE_BID_REQUEST = { - bidder: 'silvermob', - params: { - zoneid: '0', - host: 'us', - }, - mediaTypes: { - banner: { - sizes: [ - [320, 250], - [300, 600], - ], - }, - }, - adUnitCode: 'div-gpt-ad-1499748733608-0', - transactionId: 'f183e871-fbed-45f0-a427-c8a63c4c01eb', - bidId: '33e9500b21129f', - bidderRequestId: '2772c1e566670b', - auctionId: '192721e36a0239', - sizes: [[300, 250], [160, 600]], - gdprConsent: { - apiVersion: 2, - consentString: 'CONSENT', - vendorData: { purpose: { consents: { 1: true } } }, - gdprApplies: true, - addtlConsent: '1~1.35.41.101', - }, -} - -const BANNER_BID_REQUEST = { - bidder: 'silvermob', - params: { - zoneid: '0', - host: 'us', - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - }, - }, - adUnitCode: '/adunit-code/test-path', - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - transactionId: 'test-transactionId-1', - code: 'banner_example', - timeout: 1000, -} - -const VIDEO_BID_REQUEST = { - placementCode: '/DfpAccount1/slotVideo', - bidId: 'test-bid-id-2', - mediaTypes: { - video: { - playerSize: [400, 300], - w: 400, - h: 300, - minduration: 5, - maxduration: 10, - startdelay: 0, - skip: 1, - minbitrate: 200, - protocols: [1, 2, 4] - } - }, - bidder: 'silvermob', - params: { - zoneid: '0', - host: 'us', - }, - adUnitCode: '/adunit-code/test-path', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - transactionId: 'test-transactionId-1', - timeout: 1000, -} - -const NATIVE_BID_REQUEST = { - code: 'native_example', - mediaTypes: { - native: { - title: { - required: true, - len: 800 - }, - image: { - required: true, - len: 80 - }, - sponsoredBy: { - required: true - }, - clickUrl: { - required: true - }, - privacyLink: { - required: false - }, - body: { - required: true - }, - icon: { - required: true, - sizes: [50, 50] - } - } - }, - bidder: 'silvermob', - params: { - zoneid: '0', - host: 'us', - }, - adUnitCode: '/adunit-code/test-path', - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - transactionId: 'test-transactionId-1', - timeout: 1000, - uspConsent: 'uspConsent' -}; - -const bidderRequest = { - refererInfo: { - page: 'https://publisher.com/home', - ref: 'https://referrer' - } -}; - -const gdprConsent = { - apiVersion: 2, - consentString: 'CONSENT', - vendorData: { purpose: { consents: { 1: true } } }, - gdprApplies: true, - addtlConsent: '1~1.35.41.101', -} - -describe('silvermobAdapter', function () { - const adapter = newBidder(spec); - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('with user privacy regulations', function () { - it('should send the Coppa "required" flag set to "1" in the request', async function () { - sinon.stub(config, 'getConfig') - .withArgs('coppa') - .returns(true); - const serverRequest = spec.buildRequests([SIMPLE_BID_REQUEST], await addFPDToBidderRequest(bidderRequest)); - expect(serverRequest.data.regs.coppa).to.equal(1); - config.getConfig.restore(); - }); - - it('should send the GDPR Consent data in the request', async function () { - const serverRequest = spec.buildRequests([SIMPLE_BID_REQUEST], await addFPDToBidderRequest({ - ...bidderRequest, - gdprConsent - })); - expect(serverRequest.data.regs.ext.gdpr).to.exist.and.to.equal(1); - expect(serverRequest.data.user.ext.consent).to.equal('CONSENT'); - }); - - it('should send the CCPA data in the request', async function () { - const serverRequest = spec.buildRequests([SIMPLE_BID_REQUEST], await addFPDToBidderRequest({...bidderRequest, ...{uspConsent: '1YYY'}})); - expect(serverRequest.data.regs.ext.us_privacy).to.equal('1YYY'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(BANNER_BID_REQUEST)).to.equal(true); - }); - - it('should return false when zoneid is missing', function () { - const localbid = Object.assign({}, BANNER_BID_REQUEST); - delete localbid.params.zoneid; - expect(spec.isBidRequestValid(BANNER_BID_REQUEST)).to.equal(false); - }); - }); - - describe('build request', function () { - it('should return an empty array when no bid requests', async function () { - const bidRequest = spec.buildRequests([], await addFPDToBidderRequest(bidderRequest)); - expect(bidRequest).to.be.an('array'); - expect(bidRequest.length).to.equal(0); - }); - - it('should return a valid bid request object', async function () { - const request = spec.buildRequests([SIMPLE_BID_REQUEST], await addFPDToBidderRequest(bidderRequest)); - expect(request).to.not.equal('array'); - expect(request.data).to.be.an('object'); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal('https://us.silvermob.com/marketplace/api/dsp/prebidjs/0'); - - expect(request.data.site).to.have.property('page'); - expect(request.data.site).to.have.property('domain'); - expect(request.data).to.have.property('id'); - expect(request.data).to.have.property('imp'); - expect(request.data).to.have.property('device'); - }); - - it('should return a valid bid BANNER request object', async function () { - const request = spec.buildRequests([BANNER_BID_REQUEST], await addFPDToBidderRequest(bidderRequest)); - expect(request.data.imp[0].banner).to.exist; - expect(request.data.imp[0].banner.format[0].w).to.be.an('number'); - expect(request.data.imp[0].banner.format[0].h).to.be.an('number'); - }); - - if (FEATURES.VIDEO) { - it('should return a valid bid VIDEO request object', async function () { - const request = spec.buildRequests([VIDEO_BID_REQUEST], await addFPDToBidderRequest(bidderRequest)); - expect(request.data.imp[0].video).to.exist; - expect(request.data.imp[0].video.w).to.be.an('number'); - expect(request.data.imp[0].video.h).to.be.an('number'); - }); - } - - it('should return a valid bid NATIVE request object', async function () { - const request = spec.buildRequests([NATIVE_BID_REQUEST], await addFPDToBidderRequest(bidderRequest)); - expect(request.data.imp[0]).to.be.an('object'); - }); - }) - - describe('interpretResponse', function () { - let bidRequests, bidderRequest; - beforeEach(function () { - bidRequests = [{ - 'bidId': '28ffdk2B952532', - 'bidder': 'silvermob', - 'userId': { - 'freepassId': { - 'userIp': '172.21.0.1', - 'userId': '123', - 'commonId': 'commonIdValue' - } - }, - 'adUnitCode': 'adunit-code', - 'params': { - 'publisherId': 'publisherIdValue' - } - }]; - bidderRequest = {}; - }); - - it('Empty response must return empty array', function () { - const emptyResponse = null; - const response = spec.interpretResponse(emptyResponse, BANNER_BID_REQUEST); - - expect(response).to.be.an('array').that.is.empty; - }) - - it('Should interpret banner response', function () { - const serverResponse = { - body: { - 'cur': 'USD', - 'seatbid': [{ - 'bid': [{ - 'impid': '28ffdk2B952532', - 'price': 97, - 'adm': '', - 'w': 300, - 'h': 250, - 'crid': 'creative0' - }] - }] - } - }; - it('should interpret server response', async function () { - const bidRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const bids = spec.interpretResponse(serverResponse, bidRequest); - expect(bids).to.be.an('array'); - const bid = bids[0]; - expect(bid).to.be.an('object'); - expect(bid.currency).to.equal('USD'); - expect(bid.cpm).to.equal(97); - expect(bid.ad).to.equal(ad) - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creativeId).to.equal('creative0'); - }); - }) - }); -}); diff --git a/test/spec/modules/silverpushBidAdapter_spec.js b/test/spec/modules/silverpushBidAdapter_spec.js deleted file mode 100644 index 204c59e3f..000000000 --- a/test/spec/modules/silverpushBidAdapter_spec.js +++ /dev/null @@ -1,394 +0,0 @@ -import { expect } from 'chai'; -import * as utils from 'src/utils'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { REQUEST_URL, SP_OUTSTREAM_PLAYER_URL, CONVERTER, spec } from '../../../modules/silverpushBidAdapter.js'; - -const bannerBid = { - bidder: 'silverpush', - params: { - publisherId: '012345', - bidFloor: 1.5 - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 50], - ], - }, - }, - adUnitCode: 'div-gpt-ad-928572628472-0', - bidId: 'dl38fjf9d', - bidderRequestId: 'brid00000000', - auctionId: 'aucid0000000', -}; - -const videoBid = { - bidder: 'silverpush', - params: { - publisherId: '012345', - bidFloor: 0.1 - }, - mediaTypes: { - video: { - api: [1, 2, 4, 6], - mimes: ['video/mp4'], - playbackmethod: [2, 4, 6], - playerSize: [[1024, 768]], - protocols: [3, 4, 7, 8, 10], - placement: 1, - minduration: 0, - maxduration: 60, - startdelay: 0 - }, - }, - adUnitCode: 'div-gpt-ad-928572628472-1', - bidId: '281141d3541362', - bidderRequestId: 'brid00000000', - auctionId: 'aucid0000000', -}; - -const bidderRequest = { - auctionId: 'aucid0000000', - bidderRequestId: 'brid00000000', - timeout: 200, - refererInfo: { - page: 'https://hello-world-page.com/', - domain: 'hello-world-page.com', - ref: 'http://example-domain.com/foo', - } -}; - -const bannerReponse = { - 'id': 'brid00000000', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'ARUYoUZx', - 'impid': 'dl38fjf9d', - 'price': 1.64, - 'adid': 'aaaaadddddddd', - 'burl': 'http://0.0.0.0:8181/burl', - 'adm': '
', - 'adomain': [ - 'https://www.exampleabc.com' - ], - 'iurl': 'https://example.example.com/2.png', - 'cid': 'aaaaadddddddd', - 'crid': 'aaaaadddddddd', - 'h': 250, - 'w': 300 - } - ] - } - ], - 'bidid': 'ARUYoUZx', - 'cur': 'USD' -} - -const videoResponse = { - 'id': 'brid00000000', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'soCWeklh', - 'impid': '281141d3541362', - 'price': 1.09, - 'adid': 'outstream_video', - 'burl': 'http://0.0.0.0:8181/burl', - 'adm': '\n', - 'adomain': [ - 'https://www.exampleabc.com' - ], - 'cid': '229369649', - 'crid': 'aaaaadddddddd', - 'h': 768, - 'w': 1024 - } - ] - } - ], - 'bidid': 'soCWeklh', - 'cur': 'USD' -} - -describe('Silverpush Adapter', function () { - describe('isBidRequestValid()', () => { - it('should return false when publisherId is not defined', () => { - const bid = utils.deepClone(bannerBid); - delete bid.params.publisherId; - - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false when publisherId is empty string', () => { - const bid = utils.deepClone(bannerBid); - bid.params.publisherId = ''; - - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false when publisherId is a number', () => { - const bid = utils.deepClone(bannerBid); - bid.params.publisherId = 12345; - - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false when there is no banner in mediaTypes', () => { - const bid = utils.deepClone(bannerBid); - delete bid.mediaTypes.banner; - - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when sizes for banner are not specified', () => { - const bid = utils.deepClone(bannerBid); - delete bid.mediaTypes.banner.sizes; - - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when there is no video in mediaTypes', () => { - const bid = utils.deepClone(videoBid); - delete bid.mediaTypes.video; - - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should reutrn false if player size is not set', () => { - const bid = utils.deepClone(videoBid); - delete bid.mediaTypes.video.playerSize; - - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when required params found', () => { - expect(spec.isBidRequestValid(bannerBid)).to.equal(true); - expect(spec.isBidRequestValid(videoBid)).to.equal(true); - }); - }); - - describe('buildRequests()', () => { - it('should build correct request for banner bid with both w, h', () => { - const bid = utils.deepClone(bannerBid); - - const [request] = spec.buildRequests([bid], bidderRequest); - const requestData = request.data; - - expect(requestData.imp[0].banner.w).to.equal(300); - expect(requestData.imp[0].banner.h).to.equal(250); - }); - - it('should return default bidfloor when bidFloor is not defined', () => { - const bid = utils.deepClone(bannerBid); - delete bid.params.bidFloor; - - const [request] = spec.buildRequests([bid], bidderRequest); - const requestData = request.data; - - expect(requestData.imp[0].bidfloor).to.equal(0.05); - }); - - it('should contain deals in request if deal is specified in params', () => { - const bid = utils.deepClone(bannerBid); - bid.params.deals = [{ id: 'test' }]; - - const [request] = spec.buildRequests([bid], bidderRequest); - const requestData = request.data; - - expect(requestData.imp[0].pmp.deals).to.equal(bid.params.deals); - }); - - it('should return bidfloor when bidFloor is defined', () => { - const bid = utils.deepClone(bannerBid); - - const [request] = spec.buildRequests([bid], bidderRequest); - const requestData = request.data; - - expect(requestData.imp[0].bidfloor).to.equal(bannerBid.params.bidFloor); - }); - - it('should build correct request for video bid with playerSize', () => { - const bid = utils.deepClone(videoBid); - - const [request] = spec.buildRequests([bid], bidderRequest); - const requestData = request.data; - - expect(requestData.imp[0].video.w).to.equal(1024); - expect(requestData.imp[0].video.h).to.equal(768); - }); - - it('should use bidder video params if they are set', () => { - const videoBidWithParams = utils.deepClone(videoBid); - const bidderVideoParams = { - api: [1, 2], - mimes: ['video/mp4', 'video/x-flv'], - playbackmethod: [3, 4], - protocols: [5, 6], - placement: 1, - minduration: 0, - maxduration: 60, - w: 1024, - h: 768, - startdelay: 0 - }; - - videoBidWithParams.params.video = bidderVideoParams; - - const requests = spec.buildRequests([videoBidWithParams], bidderRequest); - const request = requests[0].data; - - expect(request.imp[0]).to.deep.include({ - video: { - ...bidderVideoParams, - w: videoBidWithParams.mediaTypes.video.playerSize[0][0], - h: videoBidWithParams.mediaTypes.video.playerSize[0][1], - }, - }); - }); - }); - - describe('getOS()', () => { - it('shold return correct os name for Windows', () => { - const userAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'; - const osName = spec.getOS(userAgent); - - expect(osName).to.equal('Windows'); - }); - - it('shold return correct os name for Mac OS', () => { - const userAgent = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9'; - const osName = spec.getOS(userAgent); - - expect(osName).to.equal('macOS'); - }); - - it('shold return correct os name for Android', () => { - const userAgent = 'Mozilla/5.0 (Linux; Android 10; SM-G996U Build/QP1A.190711.020; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Mobile Safari/537.36'; - const osName = spec.getOS(userAgent); - - expect(osName).to.equal('Android'); - }); - - it('shold return correct os name for ios', () => { - const userAgent = 'Mozilla/5.0 (iPhone14,3; U; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/19A346 Safari/602.1'; - const osName = spec.getOS(userAgent); - - expect(osName).to.equal('iOS'); - }); - - it('shold return correct os name for Linux', () => { - const userAgent = 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1'; - const osName = spec.getOS(userAgent); - - expect(osName).to.equal('Linux'); - }); - }); - - describe('interpretResponse()', () => { - it('should return nbr to 0 when response not received', () => { - const requests = spec.buildRequests([bannerBid], bidderRequest); - const bids = spec.interpretResponse({ body: null }, requests[0]); - - expect(bids[0]).to.equal(undefined); - }); - - it('should correctly interpret valid banner response', () => { - const response = utils.deepClone(bannerReponse); - const requests = spec.buildRequests([bannerBid], bidderRequest); - const bids = spec.interpretResponse({ body: response }, requests[0]); - - expect(bids[0].ad).to.equal('
'); - expect(bids[0].burl).to.equal('http://0.0.0.0:8181/burl'); - expect(bids[0].cpm).to.equal(1.64); - expect(bids[0].creativeId).to.equal('aaaaadddddddd'); - expect(bids[0].creative_id).to.equal('aaaaadddddddd'); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].height).to.equal(250); - expect(bids[0].mediaType).to.equal('banner'); - expect(bids[0].meta.advertiserDomains[0]).to.equal('https://www.exampleabc.com'); - expect(bids[0].netRevenue).to.equal(true); - expect(bids[0].requestId).to.equal('dl38fjf9d'); - expect(bids[0].seatBidId).to.equal('ARUYoUZx'); - expect(bids[0].ttl).to.equal(300); - expect(bids[0].width).to.equal(300); - }); - - if (FEATURES.VIDEO) { - it('should correctly interpret valid instream video response', () => { - const response = utils.deepClone(videoResponse); - videoBid.mediaTypes.video.context = 'outstream'; - const requests = spec.buildRequests([videoBid], bidderRequest); - const bids = spec.interpretResponse({ body: response }, requests[0]); - - expect(bids[0].vastXml).to.equal('\n'); - expect(bids[0].burl).to.equal('http://0.0.0.0:8181/burl'); - expect(bids[0].cpm).to.equal(1.09); - expect(bids[0].creativeId).to.equal('aaaaadddddddd'); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].mediaType).to.equal('video'); - expect(bids[0].meta.advertiserDomains[0]).to.equal('https://www.exampleabc.com'); - expect(bids[0].requestId).to.equal('281141d3541362'); - expect(bids[0].seatBidId).to.equal('soCWeklh'); - expect(bids[0].width).to.equal(1024); - expect(bids[0].height).to.equal(768); - }); - - it('should correctly interpret valid outstream video response', () => { - const response = utils.deepClone(videoResponse); - videoBid.mediaTypes.video.context = 'outstream'; - - const requests = spec.buildRequests([videoBid], bidderRequest); - const bids = spec.interpretResponse({ body: response }, requests[0]); - - expect(bids[0].vastXml).to.equal('\n'); - expect(bids[0].rendererUrl).to.equal(SP_OUTSTREAM_PLAYER_URL); - expect(bids[0].renderer.url).to.equal(SP_OUTSTREAM_PLAYER_URL); - expect(bids[0].burl).to.equal('http://0.0.0.0:8181/burl'); - expect(bids[0].cpm).to.equal(1.09); - expect(bids[0].creativeId).to.equal('aaaaadddddddd'); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].mediaType).to.equal('video'); - expect(bids[0].meta.advertiserDomains[0]).to.equal('https://www.exampleabc.com'); - expect(bids[0].requestId).to.equal('281141d3541362'); - expect(bids[0].seatBidId).to.equal('soCWeklh'); - expect(bids[0].width).to.equal(1024); - expect(bids[0].height).to.equal(768); - }); - } - }); - - describe('onBidWon', function() { - let ajaxStub; - - beforeEach(() => { - ajaxStub = sinon.stub(spec, 'getRequest') - }) - - afterEach(() => { - ajaxStub.restore() - }) - - it('Should not trigger pixel if bid does not contain burl', function() { - const result = spec.onBidWon({}); - - expect(ajaxStub.calledOnce).to.equal(false); - }) - - it('Should trigger pixel with correct macros if bid burl is present', function() { - const result = spec.onBidWon({ - cpm: 1.5, - auctionId: 'auc123', - requestId: 'req123', - adId: 'ad1234', - seatBidId: 'sea123', - burl: 'http://won.foo.bar/trk?ap=${AUCTION_PRICE}&aid=${AUCTION_ID}&imp=${AUCTION_IMP_ID}&adid=${AUCTION_AD_ID}&sid=${AUCTION_SEAT_ID}' - }); - - expect(ajaxStub.calledOnceWith('http://won.foo.bar/trk?ap=1.5&aid=auc123&imp=req123&adid=ad1234&sid=sea123')).to.equal(true); - }) - }) -}); diff --git a/test/spec/modules/sirdataRtdProvider_spec.js b/test/spec/modules/sirdataRtdProvider_spec.js deleted file mode 100644 index da7c8756c..000000000 --- a/test/spec/modules/sirdataRtdProvider_spec.js +++ /dev/null @@ -1,362 +0,0 @@ -import { - addSegmentData, - getSegmentsAndCategories, - getUidFromStorage, - loadCustomFunction, - mergeEuidsArrays, - onDataDeletionRequest, - onDocumentReady, - postContentForSemanticAnalysis, - removePII, - sanitizeContent, - setOrtb2, - setUidInStorage, - sirdataSubmodule -} from 'modules/sirdataRtdProvider.js'; -import {expect} from 'chai'; -import {deepSetValue} from 'src/utils.js'; -import {server} from 'test/mocks/xhr.js'; - -const responseHeader = {'Content-Type': 'application/json'}; - -describe('sirdataRtdProvider', function () { - describe('sirdata Submodule init', function () { - it('exists', function () { - expect(sirdataSubmodule.init).to.be.a('function'); - }); - it('successfully instantiates', function () { - const moduleConfig = { - params: { - partnerId: 1, - key: 1, - } - }; - expect(sirdataSubmodule.init(moduleConfig)).to.equal(true); - }); - it('has the correct module name', function () { - expect(sirdataSubmodule.name).to.equal('SirdataRTDModule'); - }); - }); - - describe('Sanitize content', function () { - it('removes PII from content', function () { - const doc = document.implementation.createHTMLDocument(''); - const div = doc.createElement('div'); - div.className = 'test'; - div.setAttribute('test', 'test'); - div.textContent = 'My email is test@test.com, My bank account number is 123456789012, my SSN is 123-45-6789, and my credit card number is 1234 5678 9101 1121.Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.'; - const div2 = doc.createElement('div'); - const div3 = doc.createElement('div'); - div3.innerText = 'hello'; - div2.appendChild(div3); - div.appendChild(div2); - doc.body.appendChild(div); - const cleanedDom = removePII(doc.documentElement.innerHTML); - const sanitizedDom = sanitizeContent(doc); - expect(cleanedDom).to.equal('
My email is , My bank account number is , my SSN is , and my credit card number is .Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
hello
'); - expect(sanitizedDom.documentElement.innerHTML).to.equal('
My email is , My bank account number is , my SSN is , and my credit card number is .Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
hello
'); - }); - }); - - describe('setUidInStorage', function () { - it('sets Id in Storage', function () { - setUidInStorage('123456789'); - const val = getUidFromStorage(); - expect(val).to.deep.equal([{source: 'sddan.com', uids: [{id: '123456789', atype: 1}]}]); - }); - }); - - describe('mergeEuidsArrays', function () { - it('merges Euids Arrays', function () { - const object1 = [{source: 'sddan.com', uids: [{id: '123456789', atype: 1}]}]; - const object2 = [{source: 'sddan.com', uids: [{id: '987654321', atype: 1}]}]; - const object3 = mergeEuidsArrays(object1, object2); - expect(object3).to.deep.equal([{source: 'sddan.com', uids: [{id: '123456789', atype: 1}, {id: '987654321', atype: 1}]}]); - }); - }); - - describe('onDocumentReady', function () { - it('on Document Ready function execution', function () { - const testString = ''; - const testFunction = function() { return true; }; - let resString; - try { - resString = onDocumentReady(testString); - } catch (e) {} - expect(resString).to.be.false; - const resFunction = onDocumentReady(testFunction); - expect(resFunction).to.be.true; - }); - }); - - describe('postContentForSemanticAnalysis', function () { - it('gets content for analysis', function () { - const res = postContentForSemanticAnalysis('1223456', 'https://www.sirdata.com/'); - const resEmpty = postContentForSemanticAnalysis('1223456', ''); - expect(res).to.be.true; - expect(resEmpty).to.be.false; - }); - }); - - describe('loadCustomFunction', function () { - it('load function', function () { - const res = loadCustomFunction(function(...args) { return true; }, {}, {}, {}, {}); - expect(res).to.be.true; - }); - }); - - describe('onDataDeletionRequest', function () { - it('destroy id', function () { - const moduleConfig = { - params: { - partnerId: 1, - key: 1, - } - }; - const res = onDataDeletionRequest(moduleConfig); - expect(res).to.be.true; - }); - }); - - describe('Add Segment Data', function () { - it('adds segment data', function () { - const firstConfig = { - params: { - partnerId: 1, - key: 1, - setGptKeyValues: true, - gptCurationId: 27449, - contextualMinRelevancyScore: 50, - actualUrl: 'https://www.sirdata.com/', - cookieAccessGranted: true, - bidders: [] - } - }; - sirdataSubmodule.init(firstConfig); - - const adUnits = [ - { - bids: [{ - bidder: 'appnexus', - params: { - placementId: 13144370 - } - }, { - bidder: 'other' - }] - } - ]; - - const firstReqBidsConfigObj = { - adUnits: adUnits, - ortb2Fragments: { - global: {} - } - }; - - const firstData = { - segments: [111111, 222222], - contextual_categories: {'333333': 100}, - 'segtaxid': null, - 'cattaxid': null, - 'shared_taxonomy': { - '27449': { - 'segments': [444444, 555555], - 'segtaxid': null, - 'cattaxid': null, - 'contextual_categories': {'666666': 100} - } - }, - 'global_taxonomy': { - '9998': { - 'segments': [123, 234], - 'segtaxid': 4, - 'cattaxid': 7, - 'contextual_categories': {'345': 100, '456': 100} - }, - 'sddan_id': '123456789', - 'post_content_token': '987654321' - } - } - addSegmentData(firstReqBidsConfigObj, firstData, adUnits, function() { return true; }); - expect(firstReqBidsConfigObj.ortb2Fragments.global.user.data[0].ext.segtax).to.equal(4); - }); - }); - - describe('Get Segments And Categories', function () { - it('gets data from async request and adds segment data', function () { - const overrideAppnexus = function (adUnit, list, data, bid) { - deepSetValue(bid, 'params.keywords.custom', list.segments.concat(list.categories)); - } - - const config = { - params: { - setGptKeyValues: false, - contextualMinRelevancyScore: 50, - bidders: [{ - bidder: 'appnexus', - customFunction: overrideAppnexus, - curationId: 27446 - }, { - bidder: 'smartadserver', - curationId: 27440 - }, { - bidder: 'ix', - sizeLimit: 1200, - curationId: 27248 - }, { - bidder: 'rubicon', - curationId: 27452 - }, { - bidder: 'proxistore', - curationId: 27484 - }] - } - }; - sirdataSubmodule.init(config); - - const reqBidsConfigObj = { - adUnits: [{ - bids: [{ - bidder: 'appnexus', - params: { - placementId: 13144370 - } - }, { - bidder: 'smartadserver', - params: { - siteId: 207435, - pageId: 896536, - formatId: 62913 - } - }, { - bidder: 'proxistore', - params: {website: 'demo.sirdata.com', language: 'fr'}, - adUnitCode: 'HALFPAGE_CENTER_LOADER', - transactionId: '92ac333a-a569-4827-abf1-01fc9d19278a', - sizes: [[300, 600]], - mediaTypes: { - banner: { - filteredSizeConfig: [ - {minViewPort: [1600, 0], sizes: [[300, 600]]}, - ], - sizeConfig: [ - {minViewPort: [0, 0], sizes: [[300, 600]]}, - {minViewPort: [768, 0], sizes: [[300, 600]]}, - {minViewPort: [1200, 0], sizes: [[300, 600]]}, - {minViewPort: [1600, 0], sizes: [[300, 600]]}, - ], - sizes: [[300, 600]], - }, - }, - bidId: '190bab495bc5f6e', - bidderRequestId: '18c0b0f0c91cd88', - auctionId: '9bdd917b-908d-4d9f-8f2f-d443277a62fc', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - }, { - bidder: 'ix', - params: { - siteId: '12345', - size: [300, 600] - } - }, { - bidder: 'rubicon', - params: { - accountId: 14062, - siteId: 70608, - zoneId: 498816 - } - }] - }], - ortb2Fragments: { - global: {} - } - }; - - const data = { - 'segments': [111111, 222222], - 'segtaxid': null, - 'cattaxid': null, - 'contextual_categories': {'333333': 100}, - 'shared_taxonomy': { - '27440': { - 'segments': [444444, 555555], - 'segtaxid': 552, - 'cattaxid': 553, - 'contextual_categories': {'666666': 100} - }, - '27446': { - 'segments': [777777, 888888], - 'segtaxid': 552, - 'cattaxid': 553, - 'contextual_categories': {'999999': 100} - } - }, - 'global_taxonomy': { - '9998': { - 'segments': [123, 234], - 'segtaxid': 4, - 'cattaxid': 7, - 'contextual_categories': {'345': 100, '456': 100} - } - }, - 'sddan_id': '123456789', - 'post_content_token': '987654321' - }; - - getSegmentsAndCategories(reqBidsConfigObj, () => { - }, {}, {}); - - const request = server.requests[0]; - request.respond(200, responseHeader, JSON.stringify(data)); - - expect(reqBidsConfigObj.ortb2Fragments.global.site.content.data[0].name).to.equal( - 'sirdata.com' - ); - expect(reqBidsConfigObj.ortb2Fragments.global.site.content.data[0].segment).to.eql([ - {id: '345'}, - {id: '456'} - ]); - expect(reqBidsConfigObj.ortb2Fragments.global.site.content.data[0].ext.segtax).to.equal(7); - - expect(reqBidsConfigObj.ortb2Fragments.global.user.data[0].name).to.equal( - 'sirdata.com' - ); - expect(reqBidsConfigObj.ortb2Fragments.global.user.data[0].segment).to.eql([ - {id: '123'}, - {id: '234'} - ]); - expect(reqBidsConfigObj.ortb2Fragments.global.user.data[0].ext.segtax).to.equal(4); - }); - }); - - describe('Set ortb2 for bidder', function () { - it('set ortb2 for a givent bidder', function () { - const reqBidsConfigObj = { - adUnits: [{ - bids: [{ - bidder: 'appnexus', - params: { - placementId: 13144370 - } - }] - }], - ortb2Fragments: { - global: {} - } - }; - - window.googletag = window.googletag || {}; - window.googletag.cmd = window.googletag.cmd || []; - - let test = setOrtb2(reqBidsConfigObj.ortb2Fragments, 'appnexus', 'user', []); - expect(test).to.be.false; - - test = setOrtb2(reqBidsConfigObj.ortb2Fragments, 'appnexus', 'user', ['1']); - expect(test).to.be.true; - }); - }); -}); diff --git a/test/spec/modules/slimcutBidAdapter_spec.js b/test/spec/modules/slimcutBidAdapter_spec.js deleted file mode 100644 index 40c66b9b3..000000000 --- a/test/spec/modules/slimcutBidAdapter_spec.js +++ /dev/null @@ -1,199 +0,0 @@ -import { - expect -} from 'chai'; -import { - spec -} from 'modules/slimcutBidAdapter.js'; -import { - newBidder -} from 'src/adapters/bidderFactory.js'; -const ENDPOINT = 'https://sb.freeskreen.com/pbr'; -const AD_SCRIPT = '"'; -describe('slimcutBidAdapter', function() { - const adapter = newBidder(spec); - describe('inherited functions', function() { - it('exists and is a function', function() { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - describe('isBidRequestValid', function() { - const bid = { - 'bidder': 'slimcut', - 'params': { - 'placementId': 83 - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '3c871ffa8ef14c', - 'bidderRequestId': 'b41642f1aee381', - 'auctionId': '4e156668c977d7' - }; - it('should return true when required params found', function() { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should return false when placementId is not valid (letters)', function() { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'placementId': 'ABCD' - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - it('should return false when placementId < 0', function() { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'placementId': -1 - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - it('should return false when required params are not passed', function() { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - describe('buildRequests', function() { - const bidRequests = [{ - 'bidder': 'teads', - 'params': { - 'placementId': 10433394 - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250], - [300, 600] - ], - 'bidId': '3c871ffa8ef14c', - 'bidderRequestId': 'b41642f1aee381', - 'auctionId': '4e156668c977d7', - 'deviceWidth': 1680 - }]; - const bidderResquestDefault = { - 'auctionId': '4e156668c977d7', - 'bidderRequestId': 'b41642f1aee381', - 'timeout': 3000 - }; - it('sends bid request to ENDPOINT via POST', function() { - const request = spec.buildRequests(bidRequests, bidderResquestDefault); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - it('should send GDPR to endpoint', function() { - const consentString = 'JRJ8RKfDeBNsERRDCSAAZ+A=='; - const bidderRequest = { - 'auctionId': '4e156668c977d7', - 'bidderRequestId': 'b41642f1aee381', - 'timeout': 3000, - 'gdprConsent': { - 'consentString': consentString, - 'gdprApplies': true, - 'vendorData': { - 'hasGlobalConsent': false - } - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.gdpr_iab).to.exist; - expect(payload.gdpr_iab.consent).to.equal(consentString); - }); - it('should add referer info to payload', function() { - const bidRequest = Object.assign({}, bidRequests[0]) - const bidderRequest = { - refererInfo: { - page: 'https://example.com/page.html', - reachedTop: true, - numIframes: 2 - } - } - const request = spec.buildRequests([bidRequest], bidderRequest); - const payload = JSON.parse(request.data); - expect(payload.referrer).to.exist; - expect(payload.referrer).to.deep.equal('https://example.com/page.html') - }); - }); - describe('getUserSyncs', () => { - const bids = { - 'body': { - 'responses': [{ - 'ad': AD_SCRIPT, - 'cpm': 0.5, - 'currency': 'USD', - 'height': 250, - 'netRevenue': true, - 'requestId': '3ede2a3fa0db94', - 'ttl': 360, - 'width': 300, - 'creativeId': 'er2ee', - 'transactionId': 'deadb33f', - 'winUrl': 'https://sb.freeskreen.com/win' - }] - } - }; - it('should get the correct number of sync urls', () => { - const urls = spec.getUserSyncs({ - iframeEnabled: true - }, bids); - expect(urls.length).to.equal(1); - expect(urls[0].url).to.equal('https://sb.freeskreen.com/async_usersync.html'); - }); - it('should return no url if not iframe enabled', () => { - const urls = spec.getUserSyncs({ - iframeEnabled: false - }, bids); - expect(urls.length).to.equal(0); - }); - }); - describe('interpretResponse', function() { - const bids = { - 'body': { - 'responses': [{ - 'ad': AD_SCRIPT, - 'cpm': 0.5, - 'currency': 'USD', - 'height': 250, - 'netRevenue': true, - 'requestId': '3ede2a3fa0db94', - 'ttl': 360, - 'width': 300, - 'creativeId': 'er2ee', - 'transactionId': 'deadb33f', - 'winUrl': 'https://sb.freeskreen.com/win' - }] - } - }; - it('should get correct bid response', function() { - const expectedResponse = [{ - 'cpm': 0.5, - 'width': 300, - 'height': 250, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 360, - 'ad': AD_SCRIPT, - 'requestId': '3ede2a3fa0db94', - 'creativeId': 'er2ee', - 'winUrl': 'https://sb.freeskreen.com/win', - 'meta': { - 'advertiserDomains': [] - } - }]; - const result = spec.interpretResponse(bids); - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); - }); - it('handles nobid responses', function() { - const bids = { - 'body': { - 'responses': [] - } - }; - const result = spec.interpretResponse(bids); - expect(result.length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/smaatoBidAdapter_spec.js b/test/spec/modules/smaatoBidAdapter_spec.js deleted file mode 100644 index f1bd464fb..000000000 --- a/test/spec/modules/smaatoBidAdapter_spec.js +++ /dev/null @@ -1,1778 +0,0 @@ -import {spec} from 'modules/smaatoBidAdapter.js'; -import * as utils from 'src/utils.js'; -import {config} from 'src/config.js'; - -// load modules that register ORTB processors -import 'src/prebid.js' -import 'modules/currency.js'; -import 'modules/userId/index.js'; -import 'modules/multibid/index.js'; -import 'modules/priceFloors.js'; -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; - -const IMAGE_SYNC_URL = 'https://s.ad.smaato.net/c/?adExInit=p' -const IFRAME_SYNC_URL = 'https://s.ad.smaato.net/i/?adExInit=p' - -const ADTYPE_IMG = 'Img'; -const ADTYPE_VIDEO = 'Video'; -const ADTYPE_NATIVE = 'Native'; - -const REFERRER = 'http://example.com/page.html' -const CONSENT_STRING = 'HFIDUYFIUYIUYWIPOI87392DSU' -const AUCTION_ID = '6653'; - -const defaultBidderRequest = { - bidderRequestId: 'mock-uuid', - gdprConsent: { - consentString: CONSENT_STRING, - gdprApplies: true - }, - uspConsent: 'uspConsentString', - refererInfo: { - ref: REFERRER, - }, - timeout: 1200, - auctionId: AUCTION_ID -}; - -const BANNER_PREBID_MEDIATYPE = { - sizes: [[300, 50]] -} - -const singleBannerBidRequest = { - bidder: 'smaato', - params: { - publisherId: 'publisherId', - adspaceId: 'adspaceId' - }, - mediaTypes: { - banner: BANNER_PREBID_MEDIATYPE - }, - adUnitCode: '/19968336/header-bid-tag-0', - transactionId: 'transactionId', - sizes: [[300, 50]], - bidId: 'bidId', - bidderRequestId: 'bidderRequestId', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 -}; - -const extractPayloadOfFirstAndOnlyRequest = (reqs) => { - expect(reqs).to.have.length(1); - return JSON.parse(reqs[0].data); -} - -describe('smaatoBidAdapterTest', () => { - describe('isBidRequestValid', () => { - it('is invalid, when params object is not present', () => { - expect(spec.isBidRequestValid({})).to.be.false; - }); - - it('is invalid, when params object is empty', () => { - expect(spec.isBidRequestValid({params: {}})).to.be.false; - }); - - it('is invalid, when publisherId is present but of wrong type', () => { - expect(spec.isBidRequestValid({params: {publisherId: 123}})).to.be.false; - }); - - describe('for ad pod / long form video requests', () => { - const ADPOD = {video: {context: 'adpod'}} - it('is invalid, when adbreakId is missing', () => { - expect(spec.isBidRequestValid({mediaTypes: ADPOD, params: {publisherId: '123'}})).to.be.false; - }); - - it('is invalid, when adbreakId is present but of wrong type', () => { - expect(spec.isBidRequestValid({mediaTypes: ADPOD, params: {publisherId: '123', adbreakId: 456}})).to.be.false; - }); - - it('is valid, when required params are present', () => { - expect(spec.isBidRequestValid({mediaTypes: ADPOD, params: {publisherId: '123', adbreakId: '456'}})).to.be.true; - }); - - it('is invalid, when forbidden adspaceId param is present', () => { - expect(spec.isBidRequestValid({ - mediaTypes: ADPOD, - params: {publisherId: '123', adbreakId: '456', adspaceId: '42'} - })).to.be.false; - }); - }); - - describe('for non adpod requests', () => { - it('is invalid, when adspaceId is missing', () => { - expect(spec.isBidRequestValid({params: {publisherId: '123'}})).to.be.false; - }); - - it('is invalid, when adspaceId is present but of wrong type', () => { - expect(spec.isBidRequestValid({params: {publisherId: '123', adspaceId: 456}})).to.be.false; - }); - - it('is valid, when required params are present for minimal request', () => { - expect(spec.isBidRequestValid({params: {publisherId: '123', adspaceId: '456'}})).to.be.true; - }); - - it('is invalid, when forbidden adbreakId param is present', () => { - expect(spec.isBidRequestValid({params: {publisherId: '123', adspaceId: '456', adbreakId: '42'}})).to.be.false; - }); - }); - }); - - describe('buildRequests', () => { - const BANNER_OPENRTB_IMP = { - format: [ - { - h: 50, - w: 300 - } - ], - topframe: 0, - } - - describe('common', () => { - const MINIMAL_BIDDER_REQUEST = { - refererInfo: { - ref: REFERRER, - } - }; - - let sandbox; - beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - - afterEach(() => { - sandbox.restore(); - }) - - it('auction type is 1 (first price auction)', () => { - const reqs = spec.buildRequests([singleBannerBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.at).to.be.equal(1); - }) - - it('can override endpoint', () => { - const overridenEndpoint = 'https://prebid/bidder'; - const updatedBidRequest = utils.deepClone(singleBannerBidRequest); - utils.deepSetValue(updatedBidRequest, 'params.endpoint', overridenEndpoint); - - const reqs = spec.buildRequests([updatedBidRequest], defaultBidderRequest); - - expect(reqs).to.have.length(1); - expect(reqs[0].url).to.equal(overridenEndpoint); - }); - - it('sends correct imp', () => { - const reqs = spec.buildRequests([singleBannerBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp).to.deep.equal([ - { - id: 'bidId', - banner: BANNER_OPENRTB_IMP, - tagid: 'adspaceId', - secure: 1 - } - ]); - }); - - it('sends bidfloor when configured', () => { - const singleBannerBidRequestWithFloor = Object.assign({}, singleBannerBidRequest); - singleBannerBidRequestWithFloor.getFloor = function (arg) { - if (arg.currency === 'USD' && - arg.mediaType === 'banner' && - JSON.stringify(arg.size) === JSON.stringify([300, 50])) { - return { - currency: 'USD', - floor: 0.123 - } - } - } - const reqs = spec.buildRequests([singleBannerBidRequestWithFloor], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].bidfloor).to.be.equal(0.123); - }); - - it('bidfloor uses catch-all when multiple sizes', () => { - const singleBannerMultipleSizesBidRequestWithFloor = Object.assign({}, singleBannerBidRequest, { - mediaTypes: { - banner: { - sizes: [[320, 50], [320, 250]] - } - } - }); - singleBannerMultipleSizesBidRequestWithFloor.getFloor = function (arg) { - if (arg.size === '*') { - return { - currency: 'USD', - floor: 0.101 - } - } - } - const reqs = spec.buildRequests([singleBannerMultipleSizesBidRequestWithFloor], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].bidfloor).to.be.equal(0.101); - }); - - it('sends undefined bidfloor when not a function', () => { - const singleBannerBidRequestWithFloor = Object.assign({}, singleBannerBidRequest); - singleBannerBidRequestWithFloor.getFloor = 0 - - const reqs = spec.buildRequests([singleBannerBidRequestWithFloor], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].bidfloor).to.be.undefined - }); - - it('sends undefined bidfloor when invalid', () => { - const singleBannerBidRequestWithFloor = Object.assign({}, singleBannerBidRequest); - singleBannerBidRequestWithFloor.getFloor = function () { - return undefined; - } - const reqs = spec.buildRequests([singleBannerBidRequestWithFloor], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].bidfloor).to.be.undefined - }); - - it('sends undefined bidfloor when not a number', () => { - const singleBannerBidRequestWithFloor = Object.assign({}, singleBannerBidRequest); - singleBannerBidRequestWithFloor.getFloor = function () { - return { - currency: 'USD', - } - } - const reqs = spec.buildRequests([singleBannerBidRequestWithFloor], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].bidfloor).to.be.undefined; - }); - - it('sends undefined bidfloor when wrong currency', () => { - const singleBannerBidRequestWithFloor = Object.assign({}, singleBannerBidRequest); - singleBannerBidRequestWithFloor.getFloor = function () { - return { - currency: 'EUR', - floor: 0.123 - } - } - const reqs = spec.buildRequests([singleBannerBidRequestWithFloor], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].bidfloor).to.be.undefined; - }); - - it('sends correct site', () => { - const reqs = spec.buildRequests([singleBannerBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.site.id).to.exist.and.to.be.a('string'); - expect(req.site.domain).to.exist.and.to.be.a('string'); - expect(req.site.page).to.exist.and.to.be.a('string'); - expect(req.site.ref).to.equal(REFERRER); - expect(req.site.publisher.id).to.equal('publisherId'); - }) - - it('sends correct site from ortb2', () => { - const domain = 'domain'; - const page = 'page'; - const ref = 'ref'; - const ortb2 = { - site: { - name: 'example', - domain: domain, - page: page, - ref: ref - }, - }; - - const reqs = spec.buildRequests([singleBannerBidRequest], {...defaultBidderRequest, ortb2}); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.site.id).to.exist.and.to.be.a('string'); - expect(req.site.domain).to.equal(domain); - expect(req.site.page).to.equal(page); - expect(req.site.ref).to.equal(ref); - expect(req.site.publisher.id).to.equal('publisherId'); - expect(req.dooh).to.be.undefined; - }) - - it('sends correct dooh from ortb2', () => { - const name = 'name'; - const domain = 'domain'; - const keywords = 'keyword1,keyword2'; - const venuetypetax = 1; - const ortb2 = { - dooh: { - name: name, - domain: domain, - keywords: keywords, - venuetypetax: venuetypetax - }, - }; - - const reqs = spec.buildRequests([singleBannerBidRequest], {...defaultBidderRequest, ortb2}); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.dooh.id).to.exist.and.to.be.a('string'); - expect(req.dooh.name).to.equal(name); - expect(req.dooh.domain).to.equal(domain); - expect(req.dooh.keywords).to.equal(keywords); - expect(req.dooh.venuetypetax).to.equal(venuetypetax); - expect(req.dooh.publisher.id).to.equal('publisherId'); - expect(req.site).to.be.undefined; - }) - - it('sends correct device from ortb2', () => { - const language = 'language' - const ua = 'ua' - const sua = 'sua' - const dnt = 1 - const w = 2 - const h = 3 - const ortb2 = { - device: { - language: language, - ua: ua, - sua: sua, - dnt: dnt, - w: w, - h: h - }, - }; - - const reqs = spec.buildRequests([singleBannerBidRequest], {...defaultBidderRequest, ortb2}); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.device.language).to.equal(language); - expect(req.device.ua).to.equal(ua); - expect(req.device.sua).to.equal(sua); - expect(req.device.dnt).to.equal(dnt); - expect(req.device.w).to.equal(w); - expect(req.device.h).to.equal(h); - }) - - it('sends gdpr applies if exists', () => { - const reqs = spec.buildRequests([singleBannerBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.regs.ext.gdpr).to.equal(1); - expect(req.user.ext.consent).to.equal(CONSENT_STRING); - }); - - it('sends correct coppa from ortb2', () => { - const ortb2 = { - regs: { - coppa: 1 - }, - }; - - const reqs = spec.buildRequests([singleBannerBidRequest], {...defaultBidderRequest, ortb2}); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.regs.coppa).to.equal(1); - }) - - it('sends no gdpr applies if no gdpr exists', () => { - const reqs = spec.buildRequests([singleBannerBidRequest], MINIMAL_BIDDER_REQUEST); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.regs.ext.gdpr).to.not.exist; - expect(req.user.ext.consent).to.not.exist; - }); - - it('sends us_privacy if exists', () => { - const reqs = spec.buildRequests([singleBannerBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.regs.ext.us_privacy).to.equal('uspConsentString'); - }); - - it('sends gpp', () => { - const ortb2 = { - regs: { - gpp: 'gppString', - gpp_sid: [7] - } - }; - - const reqs = spec.buildRequests([singleBannerBidRequest], {...defaultBidderRequest, ortb2}); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.regs.ext.gpp).to.eql('gppString'); - expect(req.regs.ext.gpp_sid).to.eql([7]); - }); - - it('sends no schain if no schain exists', () => { - const reqs = spec.buildRequests([singleBannerBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.source.ext.schain).to.not.exist; - }); - - it('sends instl if instl exists', () => { - const instl = {instl: 1}; - const bidRequestWithInstl = Object.assign({}, singleBannerBidRequest, {ortb2Imp: instl}); - - const reqs = spec.buildRequests([bidRequestWithInstl], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].instl).to.equal(1); - }); - - it('sends tmax', () => { - const reqs = spec.buildRequests([singleBannerBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.tmax).to.equal(1200); - }); - - it('sends no us_privacy if no us_privacy exists', () => { - const reqs = spec.buildRequests([singleBannerBidRequest], MINIMAL_BIDDER_REQUEST); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.regs.ext.us_privacy).to.not.exist; - }); - - it('sends first party data', () => { - const ortb2 = { - site: { - keywords: 'power tools,drills', - publisher: { - id: 'otherpublisherid', - name: 'publishername' - } - }, - user: { - keywords: 'a,b', - gender: 'M', - yob: 1984 - }, - device: { - ifa: 'ifa', - geo: { - lat: 53.5488, - lon: 9.9872 - } - } - }; - - const reqs = spec.buildRequests([singleBannerBidRequest], {...defaultBidderRequest, ortb2}); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.user.gender).to.equal('M'); - expect(req.user.yob).to.equal(1984); - expect(req.user.keywords).to.eql('a,b'); - expect(req.user.ext.consent).to.equal(CONSENT_STRING); - expect(req.site.keywords).to.eql('power tools,drills'); - expect(req.site.publisher.id).to.equal('publisherId'); - expect(req.device.ifa).to.equal('ifa'); - expect(req.device.geo.lat).to.equal(53.5488); - expect(req.device.geo.lon).to.equal(9.9872); - }); - - it('sends user first party data when user is not defined', () => { - const reqs = spec.buildRequests([singleBannerBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.user.gender).be.undefined; - expect(req.user.yob).to.be.undefined; - expect(req.user.keywords).to.be.undefined; - expect(req.user.ext.consent).to.equal(CONSENT_STRING); - }); - - it('has no user ids', () => { - const reqs = spec.buildRequests([singleBannerBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.user.ext.eids).to.not.exist; - }); - - it('sends dsa', () => { - const ortb2 = { - regs: { - ext: { - dsa: { - dsarequired: 2, - pubrender: 0, - datatopub: 1, - transparency: [ - { - domain: 'testdomain.com', - dsaparams: [1, 2, 3] - } - ] - } - } - } - }; - - const reqs = spec.buildRequests([singleBannerBidRequest], {...defaultBidderRequest, ortb2}); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.regs.ext.dsa.dsarequired).to.eql(2); - expect(req.regs.ext.dsa.pubrender).to.eql(0); - expect(req.regs.ext.dsa.datatopub).to.eql(1); - expect(req.regs.ext.dsa.transparency[0].domain).to.eql('testdomain.com'); - expect(req.regs.ext.dsa.transparency[0].dsaparams).to.eql([1, 2, 3]); - }); - - it('sends no dsa', () => { - const ortb2 = { - regs: { - ext: {} - } - }; - - const reqs = spec.buildRequests([singleBannerBidRequest], {...defaultBidderRequest, ortb2}); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.regs.ext.dsa).to.be.undefined; - }); - }); - - describe('multiple requests', () => { - it('build individual server request for each bid request', () => { - const bidRequest1 = utils.deepClone(singleBannerBidRequest); - const bidRequest1BidId = '1111'; - utils.deepSetValue(bidRequest1, 'bidId', bidRequest1BidId); - const bidRequest2 = utils.deepClone(singleBannerBidRequest); - const bidRequest2BidId = '2222'; - utils.deepSetValue(bidRequest2, 'bidId', bidRequest2BidId); - - const reqs = spec.buildRequests([bidRequest1, bidRequest2], defaultBidderRequest); - - expect(reqs).to.have.length(2); - expect(JSON.parse(reqs[0].data).imp[0].id).to.be.equal(bidRequest1BidId); - expect(JSON.parse(reqs[1].data).imp[0].id).to.be.equal(bidRequest2BidId); - }); - }); - - describe('buildRequests for video imps', () => { - const VIDEO_OUTSTREAM_PREBID_MEDIATYPE = { - context: 'outstream', - playerSize: [[768, 1024]], - mimes: ['video/mp4', 'video/quicktime', 'video/3gpp', 'video/x-m4v'], - minduration: 5, - maxduration: 30, - startdelay: 0, - linearity: 1, - protocols: [7], - skip: 1, - skipmin: 5, - api: [7], - ext: {rewarded: 0} - }; - const VIDEO_OUTSTREAM_OPENRTB_IMP = { - mimes: ['video/mp4', 'video/quicktime', 'video/3gpp', 'video/x-m4v'], - minduration: 5, - startdelay: 0, - linearity: 1, - h: 1024, - maxduration: 30, - skip: 1, - protocols: [7], - ext: { - rewarded: 0 - }, - skipmin: 5, - api: [7], - w: 768 - }; - const singleVideoBidRequest = { - bidder: 'smaato', - params: { - publisherId: 'publisherId', - adspaceId: 'adspaceId' - }, - mediaTypes: { - video: VIDEO_OUTSTREAM_PREBID_MEDIATYPE - }, - adUnitCode: '/19968336/header-bid-tag-0', - transactionId: 'transactionId', - bidId: 'bidId', - bidderRequestId: 'bidderRequestId', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }; - - if (FEATURES.VIDEO) { - it('sends correct video imps', () => { - const reqs = spec.buildRequests([singleVideoBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].id).to.be.equal('bidId'); - expect(req.imp[0].tagid).to.be.equal('adspaceId'); - expect(req.imp[0].bidfloor).to.be.undefined; - expect(req.imp[0].video).to.deep.equal(VIDEO_OUTSTREAM_OPENRTB_IMP); - }); - - it('sends bidfloor when configured', () => { - const singleVideoBidRequestWithFloor = Object.assign({}, singleVideoBidRequest); - singleVideoBidRequestWithFloor.getFloor = function (arg) { - if (arg.currency === 'USD' && - arg.mediaType === 'video' && - JSON.stringify(arg.size) === JSON.stringify([768, 1024])) { - return { - currency: 'USD', - floor: 0.456 - } - } - } - const reqs = spec.buildRequests([singleVideoBidRequestWithFloor], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].bidfloor).to.be.equal(0.456); - }); - - it('sends instl if instl exists', () => { - const instl = {instl: 1}; - const bidRequestWithInstl = Object.assign({}, singleVideoBidRequest, {ortb2Imp: instl}); - - const reqs = spec.buildRequests([bidRequestWithInstl], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].instl).to.equal(1); - }); - - it('splits multi format bid requests', () => { - const combinedBannerAndVideoBidRequest = { - bidder: 'smaato', - params: { - publisherId: 'publisherId', - adspaceId: 'adspaceId' - }, - mediaTypes: { - banner: BANNER_PREBID_MEDIATYPE, - video: VIDEO_OUTSTREAM_PREBID_MEDIATYPE - }, - adUnitCode: '/19968336/header-bid-tag-0', - transactionId: 'transactionId', - sizes: [[300, 50]], - bidId: 'bidId', - bidderRequestId: 'bidderRequestId', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }; - - const reqs = spec.buildRequests([combinedBannerAndVideoBidRequest], defaultBidderRequest); - - expect(reqs).to.have.length(2); - expect(JSON.parse(reqs[0].data).imp[0].banner).to.deep.equal(BANNER_OPENRTB_IMP); - expect(JSON.parse(reqs[0].data).imp[0].video).to.not.exist; - expect(JSON.parse(reqs[1].data).imp[0].banner).to.not.exist; - expect(JSON.parse(reqs[1].data).imp[0].video).to.deep.equal(VIDEO_OUTSTREAM_OPENRTB_IMP); - }); - - describe('ad pod / long form video', () => { - describe('required parameters with requireExactDuration false', () => { - const ADBREAK_ID = 'adbreakId'; - const ADPOD = 'adpod'; - const BID_ID = '4331'; - const W = 640; - const H = 480; - const ADPOD_DURATION = 300; - const DURATION_RANGE = [15, 30]; - const longFormVideoBidRequest = { - params: { - publisherId: 'publisherId', - adbreakId: ADBREAK_ID, - }, - mediaTypes: { - video: { - context: ADPOD, - playerSize: [[W, H]], - adPodDurationSec: ADPOD_DURATION, - durationRangeSec: DURATION_RANGE, - requireExactDuration: false - } - }, - bidId: BID_ID - }; - - it('sends required fields', () => { - const reqs = spec.buildRequests([longFormVideoBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.id).to.exist; - expect(req.imp.length).to.be.equal(ADPOD_DURATION / DURATION_RANGE[0]); - expect(req.imp[0].id).to.be.equal(BID_ID); - expect(req.imp[0].tagid).to.be.equal(ADBREAK_ID); - expect(req.imp[0].bidfloor).to.be.undefined; - expect(req.imp[0].video.ext.context).to.be.equal(ADPOD); - expect(req.imp[0].video.w).to.be.equal(W); - expect(req.imp[0].video.h).to.be.equal(H); - expect(req.imp[0].video.maxduration).to.be.equal(DURATION_RANGE[1]); - expect(req.imp[0].video.sequence).to.be.equal(1); - expect(req.imp[1].id).to.be.equal(BID_ID); - expect(req.imp[1].tagid).to.be.equal(ADBREAK_ID); - expect(req.imp[1].bidfloor).to.be.undefined; - expect(req.imp[1].video.ext.context).to.be.equal(ADPOD); - expect(req.imp[1].video.w).to.be.equal(W); - expect(req.imp[1].video.h).to.be.equal(H); - expect(req.imp[1].video.maxduration).to.be.equal(DURATION_RANGE[1]); - expect(req.imp[1].video.sequence).to.be.equal(2); - }); - - it('sends instl if instl exists', () => { - const instl = {instl: 1}; - const bidRequestWithInstl = Object.assign({}, longFormVideoBidRequest, {ortb2Imp: instl}); - - const reqs = spec.buildRequests([bidRequestWithInstl], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].instl).to.equal(1); - expect(req.imp[1].instl).to.equal(1); - }); - - it('sends bidfloor when configured', () => { - const longFormVideoBidRequestWithFloor = Object.assign({}, longFormVideoBidRequest); - longFormVideoBidRequestWithFloor.getFloor = function (arg) { - if (arg.currency === 'USD' && - arg.mediaType === 'video' && - JSON.stringify(arg.size) === JSON.stringify([640, 480])) { - return { - currency: 'USD', - floor: 0.789 - } - } - } - const reqs = spec.buildRequests([longFormVideoBidRequestWithFloor], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].bidfloor).to.be.equal(0.789); - expect(req.imp[1].bidfloor).to.be.equal(0.789); - }); - - it('sends brand category exclusion as true when config is set to true', () => { - config.setConfig({adpod: {brandCategoryExclusion: true}}); - - const reqs = spec.buildRequests([longFormVideoBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].video.ext.brandcategoryexclusion).to.be.equal(true); - }); - - it('sends brand category exclusion as false when config is set to false', () => { - config.setConfig({adpod: {brandCategoryExclusion: false}}); - - const reqs = spec.buildRequests([longFormVideoBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].video.ext.brandcategoryexclusion).to.be.equal(false); - }); - - it('sends brand category exclusion as false when config is not set', () => { - const reqs = spec.buildRequests([longFormVideoBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].video.ext.brandcategoryexclusion).to.be.equal(false); - }); - }); - describe('required parameters with requireExactDuration true', () => { - const ADBREAK_ID = 'adbreakId'; - const ADPOD = 'adpod'; - const BID_ID = '4331'; - const W = 640; - const H = 480; - const ADPOD_DURATION = 5; - const DURATION_RANGE = [5, 15, 25]; - const longFormVideoBidRequest = { - params: { - publisherId: 'publisherId', - adbreakId: ADBREAK_ID, - }, - mediaTypes: { - video: { - context: ADPOD, - playerSize: [[W, H]], - adPodDurationSec: ADPOD_DURATION, - durationRangeSec: DURATION_RANGE, - requireExactDuration: true - } - }, - bidId: BID_ID - }; - - it('sends required fields', () => { - const reqs = spec.buildRequests([longFormVideoBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.id).to.exist; - expect(req.imp.length).to.be.equal(DURATION_RANGE.length); - expect(req.imp[0].id).to.be.equal(BID_ID); - expect(req.imp[0].tagid).to.be.equal(ADBREAK_ID); - expect(req.imp[0].video.ext.context).to.be.equal(ADPOD); - expect(req.imp[0].video.w).to.be.equal(W); - expect(req.imp[0].video.h).to.be.equal(H); - expect(req.imp[0].video.minduration).to.be.equal(DURATION_RANGE[0]); - expect(req.imp[0].video.maxduration).to.be.equal(DURATION_RANGE[0]); - expect(req.imp[0].video.sequence).to.be.equal(1); - expect(req.imp[1].id).to.be.equal(BID_ID); - expect(req.imp[1].tagid).to.be.equal(ADBREAK_ID); - expect(req.imp[1].video.ext.context).to.be.equal(ADPOD); - expect(req.imp[1].video.w).to.be.equal(W); - expect(req.imp[1].video.h).to.be.equal(H); - expect(req.imp[1].video.minduration).to.be.equal(DURATION_RANGE[1]); - expect(req.imp[1].video.maxduration).to.be.equal(DURATION_RANGE[1]); - expect(req.imp[1].video.sequence).to.be.equal(2); - expect(req.imp[2].id).to.be.equal(BID_ID); - expect(req.imp[2].tagid).to.be.equal(ADBREAK_ID); - expect(req.imp[2].video.ext.context).to.be.equal(ADPOD); - expect(req.imp[2].video.w).to.be.equal(W); - expect(req.imp[2].video.h).to.be.equal(H); - expect(req.imp[2].video.minduration).to.be.equal(DURATION_RANGE[2]); - expect(req.imp[2].video.maxduration).to.be.equal(DURATION_RANGE[2]); - expect(req.imp[2].video.sequence).to.be.equal(3); - }); - }); - - describe('forwarding of optional parameters', () => { - const MIMES = ['video/mp4', 'video/quicktime', 'video/3gpp', 'video/x-m4v']; - const STARTDELAY = 0; - const LINEARITY = 1; - const SKIP = 1; - const PROTOCOLS = [7]; - const SKIPMIN = 5; - const API = [7]; - const validBasicAdpodBidRequest = { - params: { - publisherId: 'publisherId', - adbreakId: 'adbreakId', - }, - mediaTypes: { - video: { - context: 'adpod', - playerSize: [640, 480], - adPodDurationSec: 300, - durationRangeSec: [15, 30], - mimes: MIMES, - startdelay: STARTDELAY, - linearity: LINEARITY, - skip: SKIP, - protocols: PROTOCOLS, - skipmin: SKIPMIN, - api: API - } - }, - bidId: 'bidId' - }; - - it('sends general video fields when they are present', () => { - const reqs = spec.buildRequests([validBasicAdpodBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].video.mimes).to.eql(MIMES); - expect(req.imp[0].video.startdelay).to.be.equal(STARTDELAY); - expect(req.imp[0].video.linearity).to.be.equal(LINEARITY); - expect(req.imp[0].video.skip).to.be.equal(SKIP); - expect(req.imp[0].video.protocols).to.eql(PROTOCOLS); - expect(req.imp[0].video.skipmin).to.be.equal(SKIPMIN); - expect(req.imp[0].video.api).to.eql(API); - }); - - it('sends series name when parameter is present', () => { - const SERIES_NAME = 'foo' - const adpodRequestWithParameter = utils.deepClone(validBasicAdpodBidRequest); - adpodRequestWithParameter.mediaTypes.video.tvSeriesName = SERIES_NAME; - - const reqs = spec.buildRequests([adpodRequestWithParameter], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.site.content.series).to.be.equal(SERIES_NAME); - }); - - it('sends episode name when parameter is present', () => { - const EPISODE_NAME = 'foo' - const adpodRequestWithParameter = utils.deepClone(validBasicAdpodBidRequest); - adpodRequestWithParameter.mediaTypes.video.tvEpisodeName = EPISODE_NAME; - - const reqs = spec.buildRequests([adpodRequestWithParameter], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.site.content.title).to.be.equal(EPISODE_NAME); - }); - - it('sends season number as string when parameter is present', () => { - const SEASON_NUMBER_AS_NUMBER_IN_PREBID_REQUEST = 42 - const SEASON_NUMBER_AS_STRING_IN_OUTGOING_REQUEST = '42' - const adpodRequestWithParameter = utils.deepClone(validBasicAdpodBidRequest); - adpodRequestWithParameter.mediaTypes.video.tvSeasonNumber = SEASON_NUMBER_AS_NUMBER_IN_PREBID_REQUEST; - - const reqs = spec.buildRequests([adpodRequestWithParameter], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.site.content.season).to.be.equal(SEASON_NUMBER_AS_STRING_IN_OUTGOING_REQUEST); - }); - - it('sends episode number when parameter is present', () => { - const EPISODE_NUMBER = 42 - const adpodRequestWithParameter = utils.deepClone(validBasicAdpodBidRequest); - adpodRequestWithParameter.mediaTypes.video.tvEpisodeNumber = EPISODE_NUMBER; - - const reqs = spec.buildRequests([adpodRequestWithParameter], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.site.content.episode).to.be.equal(EPISODE_NUMBER); - }); - - it('sends content length when parameter is present', () => { - const LENGTH = 42 - const adpodRequestWithParameter = utils.deepClone(validBasicAdpodBidRequest); - adpodRequestWithParameter.mediaTypes.video.contentLengthSec = LENGTH; - - const reqs = spec.buildRequests([adpodRequestWithParameter], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.site.content.len).to.be.equal(LENGTH); - }); - - it('sends livestream as 1 when content mode parameter is live', () => { - const adpodRequestWithParameter = utils.deepClone(validBasicAdpodBidRequest); - adpodRequestWithParameter.mediaTypes.video.contentMode = 'live'; - - const reqs = spec.buildRequests([adpodRequestWithParameter], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.site.content.livestream).to.be.equal(1); - }); - - it('sends livestream as 0 when content mode parameter is on-demand', () => { - const adpodRequestWithParameter = utils.deepClone(validBasicAdpodBidRequest); - adpodRequestWithParameter.mediaTypes.video.contentMode = 'on-demand'; - - const reqs = spec.buildRequests([adpodRequestWithParameter], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.site.content.livestream).to.be.equal(0); - }); - - it('doesn\'t send any optional parameters when none are present', () => { - const reqs = spec.buildRequests([validBasicAdpodBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].video.ext.requireExactDuration).to.not.exist; - expect(req.site.content).to.not.exist; - }); - }); - }); - } - }); - - if (FEATURES.NATIVE) { - describe('buildRequests for native imps', () => { - const NATIVE_OPENRTB_REQUEST = { - ver: '1.2', - assets: [ - { - id: 4, - required: 1, - img: { - type: 3, - w: 150, - h: 50, - } - }, - { - id: 2, - required: 1, - img: { - type: 2, - w: 50, - h: 50 - } - }, - { - id: 0, - required: 1, - title: { - len: 80 - } - }, - { - id: 1, - required: 1, - data: { - type: 1 - } - }, - { - id: 3, - required: 1, - data: { - type: 2 - } - }, - { - id: 5, - required: 1, - data: { - type: 3 - } - }, - { - id: 6, - required: 1, - data: { - type: 4 - } - }, - { - id: 7, - required: 1, - data: { - type: 5 - } - }, - { - id: 8, - required: 1, - data: { - type: 6 - } - }, - { - id: 9, - required: 1, - data: { - type: 7 - } - }, - { - id: 10, - required: 0, - data: { - type: 8 - } - }, - { - id: 11, - required: 1, - data: { - type: 9 - } - }, - { - id: 12, - require: 0, - data: { - type: 10 - } - }, - { - id: 13, - required: 0, - data: { - type: 11 - } - }, - { - id: 14, - required: 1, - data: { - type: 12 - } - } - ] - }; - - const singleNativeBidRequest = { - bidder: 'smaato', - params: { - publisherId: 'publisherId', - adspaceId: 'adspaceId' - }, - nativeOrtbRequest: NATIVE_OPENRTB_REQUEST, - adUnitCode: '/19968336/header-bid-tag-0', - transactionId: 'transactionId', - bidId: 'bidId', - bidderRequestId: 'bidderRequestId', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }; - - it('sends correct native imps', () => { - const reqs = spec.buildRequests([singleNativeBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].id).to.be.equal('bidId'); - expect(req.imp[0].tagid).to.be.equal('adspaceId'); - expect(req.imp[0].bidfloor).to.be.undefined; - expect(req.imp[0].native.request).to.deep.equal(JSON.stringify(NATIVE_OPENRTB_REQUEST)); - }); - - it('sends bidfloor when configured', () => { - const singleNativeBidRequestWithFloor = Object.assign({}, singleNativeBidRequest); - singleNativeBidRequestWithFloor.getFloor = function (arg) { - if (arg.currency === 'USD' && - arg.mediaType === 'native' && - JSON.stringify(arg.size) === JSON.stringify([150, 50])) { - return { - currency: 'USD', - floor: 0.123 - } - } - } - const reqs = spec.buildRequests([singleNativeBidRequestWithFloor], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.imp[0].bidfloor).to.be.equal(0.123); - }); - }); - } - describe('in-app requests', () => { - const LOCATION = { - lat: 33.3, - lon: -88.8 - } - const DEVICE_ID = 'aDeviceId' - const inAppBidRequestWithoutAppParams = { - bidder: 'smaato', - params: { - publisherId: 'publisherId', - adspaceId: 'adspaceId' - }, - mediaTypes: { - banner: BANNER_PREBID_MEDIATYPE - }, - adUnitCode: '/19968336/header-bid-tag-0', - transactionId: 'transactionId', - sizes: [[300, 50]], - bidId: 'bidId', - bidderRequestId: 'bidderRequestId', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }; - - it('when geo and ifa info present, then add both to device object', () => { - const inAppBidRequest = utils.deepClone(inAppBidRequestWithoutAppParams); - inAppBidRequest.params.app = {ifa: DEVICE_ID, geo: LOCATION}; - - const reqs = spec.buildRequests([inAppBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.device.geo).to.deep.equal(LOCATION); - expect(req.device.ifa).to.equal(DEVICE_ID); - }); - - it('when geo and ifa info present and fpd present, then prefer fpd', () => { - const ortb2 = { - device: { - ifa: 'ifa', - geo: { - lat: 53.5488, - lon: 9.9872 - } - } - }; - - const inAppBidRequest = utils.deepClone(inAppBidRequestWithoutAppParams); - inAppBidRequest.params.app = {ifa: DEVICE_ID, geo: LOCATION}; - - const reqs = spec.buildRequests([inAppBidRequest], {...defaultBidderRequest, ortb2}); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.device.geo.lat).to.equal(53.5488); - expect(req.device.geo.lon).to.equal(9.9872); - expect(req.device.ifa).to.equal('ifa'); - }); - - it('when ifa is present but geo is missing, then add only ifa to device object', () => { - const inAppBidRequest = utils.deepClone(inAppBidRequestWithoutAppParams); - inAppBidRequest.params.app = {ifa: DEVICE_ID}; - - const reqs = spec.buildRequests([inAppBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.device.geo).to.not.exist; - expect(req.device.ifa).to.equal(DEVICE_ID); - }); - - it('when geo is present but ifa is missing, then add only geo to device object', () => { - const inAppBidRequest = utils.deepClone(inAppBidRequestWithoutAppParams); - inAppBidRequest.params.app = {geo: LOCATION}; - - const reqs = spec.buildRequests([inAppBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.device.geo).to.deep.equal(LOCATION); - expect(req.device.ifa).to.not.exist; - }); - - it('when app param does not exist, then add no specific device info', () => { - const reqs = spec.buildRequests([inAppBidRequestWithoutAppParams], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.device.geo).to.not.exist; - expect(req.device.ifa).to.not.exist; - }); - }); - - describe('user ids in requests', () => { - it('user ids are added to user.ext.eids', () => { - const userIdBidRequest = { - bidder: 'smaato', - params: { - publisherId: 'publisherId', - adspaceId: 'adspaceId' - }, - mediaTypes: { - banner: BANNER_PREBID_MEDIATYPE - }, - adUnitCode: '/19968336/header-bid-tag-0', - transactionId: 'transactionId', - sizes: [[300, 50]], - bidId: 'bidId', - bidderRequestId: 'bidderRequestId', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - userId: { - criteoId: '123456', - tdid: '89145' - }, - userIdAsEids: [ - {id: 1}, {id: 2} - ] - }; - - const reqs = spec.buildRequests([userIdBidRequest], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.user.ext.eids).to.eql(userIdBidRequest.userIdAsEids); - }); - }); - - describe('schain in request', () => { - it('schain is added to source.ext.schain', () => { - const schain = { - ver: '1.0', - complete: 1, - nodes: [ - { - 'asi': 'asi', - 'sid': 'sid', - 'rid': 'rid', - 'hp': 1 - } - ] - }; - const bidRequestWithSchain = Object.assign({}, singleBannerBidRequest, { - ortb2: { - source: { - ext: { - schain: schain - } - } - } - }); - - const reqs = spec.buildRequests([bidRequestWithSchain], defaultBidderRequest); - - const req = extractPayloadOfFirstAndOnlyRequest(reqs); - expect(req.source.ext.schain).to.deep.equal(schain); - }); - }); - }); - - describe('interpretResponse', () => { - function buildBidRequest(payloadAsJsObj = {imp: [{}]}) { - return { - method: 'POST', - url: 'https://prebid.ad.smaato.net/oapi/prebid', - data: JSON.stringify(payloadAsJsObj) - } - } - - const NATIVE_RESPONSE = { - ver: '1.2', - link: { - url: 'https://link.url', - clicktrackers: [ - 'http://click.url/v1/click?e=prebid' - ] - }, - assets: [ - { - id: 0, - required: 1, - title: { - text: 'Title' - } - }, - { - id: 2, - required: 1, - img: { - type: 1, - url: 'https://logo.png', - w: 40, - h: 40 - } - }, - { - id: 4, - required: 1, - img: { - type: 3, - url: 'https://main.png', - w: 480, - h: 320 - } - }, - { - id: 3, - required: 1, - data: { - type: 2, - value: 'Desc' - } - }, - { - id: 14, - required: 1, - data: { - type: 12, - value: 'CTAText' - } - }, - { - id: 5, - required: 0, - data: { - type: 3, - value: '2 stars' - } - } - ], - eventtrackers: [ - { - event: 2, - method: 1, - url: 'https://js.url' - }, - { - event: 1, - method: 1, - url: 'http://view.url/v1/view?e=prebid' - } - ], - privacy: 'https://privacy.com/' - } - - const buildOpenRtbBidResponse = (adType) => { - let adm = ''; - - switch (adType) { - case ADTYPE_IMG: - adm = '' - break; - case ADTYPE_VIDEO: - adm = ''; - break; - case ADTYPE_NATIVE: - adm = JSON.stringify({native: NATIVE_RESPONSE}) - break; - default: - throw Error('Invalid AdType'); - } - - return { - body: { - bidid: '04db8629-179d-4bcd-acce-e54722969006', - cur: 'USD', - ext: {}, - id: '5ebea288-f13a-4754-be6d-4ade66c68877', - seatbid: [ - { - bid: [ - { - 'adm': adm, - 'adomain': [ - 'smaato.com' - ], - 'bidderName': 'smaato', - 'cid': 'CM6523', - 'crid': 'CR69381', - 'dealid': '12345', - 'id': '6906aae8-7f74-4edd-9a4f-f49379a3cadd', - 'impid': '226416e6e6bf41', - 'iurl': 'https://prebid/iurl', - 'nurl': 'https://prebid/nurl', - 'price': 0.01, - 'w': 350, - 'h': 50, - 'ext': { - curls: ['https://prebid/track/click/1'] - } - } - ], - seat: 'CM6523' - } - ], - }, - headers: { - get: function (header) { - if (header === 'X-SMT-ADTYPE') { - return adType; - } - } - } - }; - }; - - it('returns empty array on no bid responses', () => { - const response_with_empty_body = {body: {}}; - - const bids = spec.interpretResponse(response_with_empty_body, buildBidRequest()); - - expect(bids).to.be.empty; - }); - - describe('non ad pod', () => { - it('single banner response', () => { - const bids = spec.interpretResponse(buildOpenRtbBidResponse(ADTYPE_IMG), buildBidRequest()); - - expect(bids).to.deep.equal([ - { - requestId: '226416e6e6bf41', - cpm: 0.01, - width: 350, - height: 50, - ad: '
', - ttl: 300, - creativeId: 'CR69381', - dealId: '12345', - netRevenue: true, - currency: 'USD', - mediaType: 'banner', - meta: { - advertiserDomains: ['smaato.com'], - agencyId: 'CM6523', - networkName: 'smaato', - mediaType: 'banner' - } - } - ]); - }); - - it('single video response', () => { - const bids = spec.interpretResponse(buildOpenRtbBidResponse(ADTYPE_VIDEO), buildBidRequest()); - - expect(bids).to.deep.equal([ - { - requestId: '226416e6e6bf41', - cpm: 0.01, - width: 350, - height: 50, - vastXml: '', - ttl: 300, - creativeId: 'CR69381', - dealId: '12345', - netRevenue: true, - currency: 'USD', - mediaType: 'video', - meta: { - advertiserDomains: ['smaato.com'], - agencyId: 'CM6523', - networkName: 'smaato', - mediaType: 'video' - } - } - ]); - }); - - it('single native response', () => { - const bids = spec.interpretResponse(buildOpenRtbBidResponse(ADTYPE_NATIVE), buildBidRequest()); - - expect(bids).to.deep.equal([ - { - requestId: '226416e6e6bf41', - cpm: 0.01, - width: 350, - height: 50, - native: { - ortb: NATIVE_RESPONSE - }, - ttl: 300, - creativeId: 'CR69381', - dealId: '12345', - netRevenue: true, - currency: 'USD', - mediaType: 'native', - meta: { - advertiserDomains: ['smaato.com'], - agencyId: 'CM6523', - networkName: 'smaato', - mediaType: 'native' - } - } - ]); - }); - - it('ignores bid response with invalid ad type', () => { - const serverResponse = buildOpenRtbBidResponse(ADTYPE_IMG); - serverResponse.headers.get = (header) => { - if (header === 'X-SMT-ADTYPE') { - return undefined; - } - }; - - const bids = spec.interpretResponse(serverResponse, buildBidRequest()); - - expect(bids).to.be.empty; - }); - }); - - describe('ad pod', () => { - const bidRequestWithAdpodContext = buildBidRequest({imp: [{video: {ext: {context: 'adpod'}}}]}); - const PRIMARY_CAT_ID = 1337 - const serverResponse = { - body: { - bidid: '04db8629-179d-4bcd-acce-e54722969006', - cur: 'USD', - ext: {}, - id: '5ebea288-f13a-4754-be6d-4ade66c68877', - seatbid: [ - { - bid: [ - { - adm: '', - adomain: [ - 'smaato.com' - ], - bidderName: 'smaato', - cid: 'CM6523', - crid: 'CR69381', - dealid: '12345', - id: '6906aae8-7f74-4edd-9a4f-f49379a3cadd', - impid: '226416e6e6bf41', - iurl: 'https://prebid/iurl', - nurl: 'https://prebid/nurl', - price: 0.01, - w: 350, - h: 50, - cat: [PRIMARY_CAT_ID], - ext: { - duration: 42 - } - } - ], - seat: 'CM6523' - } - ] - }, - headers: {get: () => undefined} - }; - - it('sets required values for adpod bid from server response', () => { - const bids = spec.interpretResponse(serverResponse, bidRequestWithAdpodContext); - - expect(bids).to.deep.equal([ - { - requestId: '226416e6e6bf41', - cpm: 0.01, - width: 350, - height: 50, - vastXml: '', - ttl: 300, - creativeId: 'CR69381', - dealId: '12345', - netRevenue: true, - currency: 'USD', - mediaType: 'video', - video: { - context: 'adpod', - durationSeconds: 42 - }, - meta: { - advertiserDomains: ['smaato.com'], - agencyId: 'CM6523', - networkName: 'smaato', - mediaType: 'video' - } - } - ]); - }); - - it('sets primary category id in case of enabled brand category exclusion', () => { - config.setConfig({adpod: {brandCategoryExclusion: true}}); - - const bids = spec.interpretResponse(serverResponse, bidRequestWithAdpodContext) - - expect(bids[0].meta.primaryCatId).to.be.equal(PRIMARY_CAT_ID) - }) - }); - - it('uses correct TTL when expire header exists', () => { - const clock = sinon.useFakeTimers(); - clock.tick(2000); - const resp = buildOpenRtbBidResponse(ADTYPE_IMG); - resp.headers.get = (header) => { - if (header === 'X-SMT-ADTYPE') { - return ADTYPE_IMG; - } - if (header === 'X-SMT-Expires') { - return 2000 + (400 * 1000); - } - }; - - const bids = spec.interpretResponse(resp, buildBidRequest()); - - expect(bids[0].ttl).to.equal(400); - - clock.restore(); - }); - - it('uses net revenue flag send from server', () => { - const resp = buildOpenRtbBidResponse(ADTYPE_IMG); - resp.body.seatbid[0].bid[0].ext = {net: false}; - - const bids = spec.interpretResponse(resp, buildBidRequest()); - - expect(bids[0].netRevenue).to.equal(false); - }); - - it('uses dsa object sent from server', () => { - const resp = buildOpenRtbBidResponse(ADTYPE_IMG); - const dsa = { - behalf: 'advertiser', - paid: 'advertiser', - adrender: 1, - transparency: [ - { - domain: 'dsp1domain.com', - dsaparams: [1, 2] - } - ] - }; - resp.body.seatbid[0].bid[0].ext.dsa = dsa; - - const bids = spec.interpretResponse(resp, buildBidRequest()); - - expect(bids[0].meta.dsa).to.deep.equal(dsa); - }); - - it('does not use dsa object if not sent from server', () => { - const resp = buildOpenRtbBidResponse(ADTYPE_IMG); - resp.body.seatbid[0].bid[0].ext = {} - - const bids = spec.interpretResponse(resp, buildBidRequest()); - - expect(bids[0].meta.dsa).to.be.undefined; - }); - }); - - describe('getUserSyncs', () => { - afterEach(() => { - config.resetConfig(); - }) - - it('when pixelEnabled and iframeEnabled false then returns no syncs', () => { - expect(spec.getUserSyncs()).to.be.empty - }) - - it('when pixelEnabled true then returns image sync', () => { - expect(spec.getUserSyncs({pixelEnabled: true}, null, null, null)).to.deep.equal( - [ - { - type: 'image', - url: IMAGE_SYNC_URL - } - ] - ) - }) - - it('when iframeEnabled true then returns iframe sync', () => { - expect(spec.getUserSyncs({iframeEnabled: true}, null, null, null)).to.deep.equal( - [ - { - type: 'iframe', - url: IFRAME_SYNC_URL - } - ] - ) - }) - - it('when iframeEnabled true and syncsPerBidder then returns iframe sync', () => { - config.setConfig({userSync: {syncsPerBidder: 5}}); - expect(spec.getUserSyncs({iframeEnabled: true}, null, null, null)).to.deep.equal( - [ - { - type: 'iframe', - url: `${IFRAME_SYNC_URL}&maxUrls=5` - } - ] - ) - }) - - it('when iframeEnabled and pixelEnabled true then returns iframe sync', () => { - expect(spec.getUserSyncs({pixelEnabled: true, iframeEnabled: true}, null, null, null)).to.deep.equal( - [ - { - type: 'iframe', - url: IFRAME_SYNC_URL - } - ] - ) - }) - - it('when pixelEnabled true and gdprConsent then returns image sync with gdpr params', () => { - expect(spec.getUserSyncs({pixelEnabled: true}, null, {gdprApplies: true, consentString: CONSENT_STRING}, null)).to.deep.equal( - [ - { - type: 'image', - url: `${IMAGE_SYNC_URL}&gdpr=1&gdpr_consent=${CONSENT_STRING}` - } - ] - ) - }) - - it('when iframeEnabled true and gdprConsent then returns iframe with gdpr params', () => { - expect(spec.getUserSyncs({iframeEnabled: true}, null, {gdprApplies: true, consentString: CONSENT_STRING}, null)).to.deep.equal( - [ - { - type: 'iframe', - url: `${IFRAME_SYNC_URL}&gdpr=1&gdpr_consent=${CONSENT_STRING}` - } - ] - ) - }) - - it('when pixelEnabled true and gdprConsent without gdpr then returns pixel sync with gdpr_consent', () => { - expect(spec.getUserSyncs({pixelEnabled: true}, null, {consentString: CONSENT_STRING}, null), null).to.deep.equal( - [ - { - type: 'image', - url: `${IMAGE_SYNC_URL}&gdpr_consent=${CONSENT_STRING}` - } - ] - ) - }) - - it('when iframeEnabled true and gdprConsent without gdpr then returns iframe sync with gdpr_consent', () => { - expect(spec.getUserSyncs({iframeEnabled: true}, null, {consentString: CONSENT_STRING}, null), null).to.deep.equal( - [ - { - type: 'iframe', - url: `${IFRAME_SYNC_URL}&gdpr_consent=${CONSENT_STRING}` - } - ] - ) - }) - }) -}); diff --git a/test/spec/modules/smartadserverBidAdapter_spec.js b/test/spec/modules/smartadserverBidAdapter_spec.js deleted file mode 100644 index 4b6d623e3..000000000 --- a/test/spec/modules/smartadserverBidAdapter_spec.js +++ /dev/null @@ -1,1693 +0,0 @@ -import { expect } from 'chai'; -import { BANNER, VIDEO } from 'src/mediaTypes.js'; -import { config } from 'src/config.js'; -import { deepClone } from 'src/utils.js'; -import { getBidFloor } from 'libraries/equativUtils/equativUtils.js' -import { spec } from 'modules/smartadserverBidAdapter.js'; -import { setConfig as setCurrencyConfig } from '../../../modules/currency.js'; -import { addFPDToBidderRequest } from '../../helpers/fpd.js'; - -// Default params with optional ones -describe('Smart bid adapter tests', function () { - var DEFAULT_PARAMS = [{ - adUnitCode: 'sas_42', - bidId: 'abcd1234', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 200] - ] - } - }, - bidder: 'smartadserver', - params: { - domain: 'https://prg.smartadserver.com', - siteId: '1234', - pageId: '5678', - formatId: '90', - target: 'test=prebid', - bidfloor: 0.420, - buId: '7569', - appName: 'Mozilla', - ckId: 42 - }, - requestId: 'efgh5678', - ortb2Imp: { - ext: { - tid: 'zsfgzzg' - } - }, - }]; - - var DEFAULT_PARAMS_WITH_EIDS = [{ - adUnitCode: 'sas_42', - bidId: 'abcd1234', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 200] - ] - } - }, - bidder: 'smartadserver', - params: { - domain: 'https://prg.smartadserver.com', - siteId: '1234', - pageId: '5678', - formatId: '90', - target: 'test=prebid', - bidfloor: 0.420, - buId: '7569', - appName: 'Mozilla', - ckId: 42 - }, - requestId: 'efgh5678', - transactionId: 'zsfgzzg', - userIdAsEids: [ - { - 'source': 'pubcid.org', - 'uids': [ - { - 'atype': 1, - 'id': '1111' - } - ] - }, - { - 'source': 'britepoolid', - 'uids': [ - { - 'atype': 1, - 'id': '1111' - } - ] - }, - { - 'source': 'id5id', - 'uids': [ - { - 'atype': 1, - 'id': '1111' - } - ] - }, - { - 'source': 'idl_env', - 'uids': [ - { - 'atype': 1, - 'id': '1111' - } - ] - }, - { - 'source': 'lipbid', - 'uids': [ - { - 'atype': 1, - 'id': '1111' - } - ] - }, - { - 'source': 'parrableid', - 'uids': [ - { - 'atype': 1, - 'id': 'eidVersion.encryptionKeyReference.encryptedValue' - } - ] - }, - { - 'source': 'tdid', - 'uids': [ - { - 'atype': 1, - 'id': '1111' - } - ] - }, - { - 'source': 'netId', - 'uids': [ - { - 'atype': 1, - 'id': 'fH5A3n2O8_CZZyPoJVD-eabc6ECb7jhxCicsds7qSg' - } - ] - } - ] - }]; - - // Default params without optional ones - var DEFAULT_PARAMS_WO_OPTIONAL = [{ - adUnitCode: 'sas_42', - bidId: 'abcd1234', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 200] - ], - } - }, - - bidder: 'smartadserver', - params: { - domain: 'https://prg.smartadserver.com', - siteId: '1234', - pageId: '5678', - formatId: '90' - }, - requestId: 'efgh5678' - }]; - - var BID_RESPONSE = { - body: { - cpm: 12, - width: 300, - height: 250, - creativeId: 'zioeufg', - currency: 'GBP', - isNetCpm: true, - ttl: 300, - adUrl: 'http://awesome.fake.url', - ad: '< --- awesome script --- >', - cSyncUrl: 'http://awesome.fake.csync.url', - isNoAd: false - } - }; - - var BID_RESPONSE_IS_NO_AD = { - body: { - cpm: 12, - width: 300, - height: 250, - creativeId: 'zioeufg', - currency: 'GBP', - isNetCpm: true, - ttl: 300, - adUrl: 'http://awesome.fake.url', - ad: '< --- awesome script --- >', - cSyncUrl: 'http://awesome.fake.csync.url', - isNoAd: true - } - }; - - var BID_RESPONSE_IMAGE_SYNC = { - body: { - cpm: 12, - width: 300, - height: 250, - creativeId: 'zioeufg', - currency: 'GBP', - isNetCpm: true, - ttl: 300, - adUrl: 'http://awesome.fake.url', - ad: '< --- awesome script --- >', - cSyncUrl: 'http://awesome.fake.csync.url', - isNoAd: false, - dspPixels: ['pixelOne', 'pixelTwo', 'pixelThree'] - } - }; - - var BID_RESPONSE_IFRAME_SYNC_MISSING_CSYNC = { - body: { - cpm: 12, - width: 300, - height: 250, - creativeId: 'zioeufg', - currency: 'GBP', - isNetCpm: true, - ttl: 300, - adUrl: 'http://awesome.fake.url', - ad: '< --- awesome script --- >', - cSyncUrl: null, - isNoAd: false - } - }; - - var sellerDefinedAudience = [ - { - 'name': 'hearst.com', - 'ext': { 'segtax': 1 }, - 'segment': [ - { 'id': '1001' }, - { 'id': '1002' } - ] - } - ]; - - var sellerDefinedContext = [ - { - 'name': 'cnn.com', - 'ext': { 'segtax': 2 }, - 'segment': [ - { 'id': '2002' } - ] - } - ]; - - it('Verify build request', function () { - setCurrencyConfig({ adServerCurrency: 'EUR' }); - config.setConfig({ - ortb2: { - 'user': { - 'data': sellerDefinedAudience - }, - 'site': { - 'content': { - 'data': sellerDefinedContext - } - } - } - }); - - return addFPDToBidderRequest(DEFAULT_PARAMS[0]).then(res => { - const request = spec.buildRequests(DEFAULT_PARAMS, res); - expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); - expect(request[0]).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('siteid').and.to.equal('1234'); - expect(requestContent).to.have.property('pageid').and.to.equal('5678'); - expect(requestContent).to.have.property('formatid').and.to.equal('90'); - expect(requestContent).to.have.property('currencyCode').and.to.equal('EUR'); - expect(requestContent).to.have.property('bidfloor').and.to.equal(0.42); - expect(requestContent).to.have.property('targeting').and.to.equal('test=prebid'); - expect(requestContent).to.have.property('tagId').and.to.equal('sas_42'); - expect(requestContent).to.have.property('sizes'); - expect(requestContent.sizes[0]).to.have.property('w').and.to.equal(300); - expect(requestContent.sizes[0]).to.have.property('h').and.to.equal(250); - expect(requestContent.sizes[1]).to.have.property('w').and.to.equal(300); - expect(requestContent.sizes[1]).to.have.property('h').and.to.equal(200); - expect(requestContent).to.not.have.property('pageDomain'); - expect(requestContent).to.have.property('transactionId').and.to.not.equal(null).and.to.not.be.undefined; - expect(requestContent).to.have.property('buid').and.to.equal('7569'); - expect(requestContent).to.have.property('appname').and.to.equal('Mozilla'); - expect(requestContent).to.have.property('ckid').and.to.equal(42); - expect(requestContent).to.have.property('sda').and.to.deep.equal(sellerDefinedAudience); - expect(requestContent).to.have.property('sdc').and.to.deep.equal(sellerDefinedContext); - setCurrencyConfig({}); - }); - }); - - it('Verify parse response with no ad', function () { - const request = spec.buildRequests(DEFAULT_PARAMS); - const bids = spec.interpretResponse(BID_RESPONSE_IS_NO_AD, request[0]); - expect(bids).to.have.lengthOf(0); - - expect(function () { - spec.interpretResponse(BID_RESPONSE_IS_NO_AD, { - data: 'invalid Json' - }) - }).to.not.throw(); - }); - - it('Should not nest response if ad and adUrl empty', () => { - const BID_RESPONSE_EMPTY = { - body: { - ad: null, - adUrl: null, - cpm: 0.92, - isNoAd: false - } - }; - - const request = spec.buildRequests(DEFAULT_PARAMS); - const bids = spec.interpretResponse(BID_RESPONSE_EMPTY, request[0]); - - expect(bids).to.have.lengthOf(0); - expect(() => { - spec.interpretResponse(BID_RESPONSE_EMPTY, { - data: 'invalid Json' - }); - }).to.not.throw(); - }); - - it('Verify parse response', function () { - const request = spec.buildRequests(DEFAULT_PARAMS); - const bids = spec.interpretResponse(BID_RESPONSE, request[0]); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(12); - expect(bid.adUrl).to.equal('http://awesome.fake.url'); - expect(bid.ad).to.equal('< --- awesome script --- >'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creativeId).to.equal('zioeufg'); - expect(bid.currency).to.equal('GBP'); - expect(bid.netRevenue).to.equal(true); - expect(bid.ttl).to.equal(300); - expect(bid.requestId).to.equal(DEFAULT_PARAMS[0].bidId); - - expect(function () { - spec.interpretResponse(BID_RESPONSE, { - data: 'invalid Json' - }) - }).to.not.throw(); - }); - - it('Verifies bidder code', function () { - expect(spec.code).to.equal('smartadserver'); - }); - - it('Verifies bidder aliases', function () { - expect(spec.aliases).to.have.lengthOf(1); - expect(spec.aliases[0]).to.equal('smart'); - }); - - it('Verifies if bid request valid', function () { - expect(spec.isBidRequestValid(DEFAULT_PARAMS[0])).to.equal(true); - expect(spec.isBidRequestValid(DEFAULT_PARAMS_WO_OPTIONAL[0])).to.equal(true); - expect(spec.isBidRequestValid({})).to.equal(false); - expect(spec.isBidRequestValid({ - params: {} - })).to.equal(false); - expect(spec.isBidRequestValid({ - params: { - pageId: 123 - } - })).to.equal(false); - expect(spec.isBidRequestValid({ - params: { - siteId: 123 - } - })).to.equal(false); - expect(spec.isBidRequestValid({ - params: { - formatId: 123, - pageId: 234 - } - })).to.equal(false); - expect(spec.isBidRequestValid({ - params: { - domain: 'www.test.com', - pageId: 234 - } - })).to.equal(false); - expect(spec.isBidRequestValid({ - params: { - domain: 'www.test.com', - formatId: 123, - siteId: 456, - pageId: 234 - } - })).to.equal(true); - expect(spec.isBidRequestValid({ - params: { - domain: 'www.test.com', - formatId: 123, - siteId: 456, - pageId: 234, - buId: 789, - appName: 'Mozilla' - } - })).to.equal(true); - expect(spec.isBidRequestValid({ - params: { - domain: 'www.test.com', - formatId: 123, - pageId: 234, - buId: 789, - appName: 'Mozilla' - } - })).to.equal(false); - }); - - it('Verifies user sync', function () { - var syncs = spec.getUserSyncs({ - iframeEnabled: true - }, [BID_RESPONSE]); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.equal('http://awesome.fake.csync.url'); - - syncs = spec.getUserSyncs({ - iframeEnabled: false - }, [BID_RESPONSE]); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: true - }, []); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: true - }, [BID_RESPONSE_IFRAME_SYNC_MISSING_CSYNC]); - expect(syncs).to.have.lengthOf(0); - }); - - it('Verifies user sync using dspPixels', function () { - var syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: true - }, [BID_RESPONSE_IMAGE_SYNC]); - expect(syncs).to.have.lengthOf(3); - expect(syncs[0].type).to.equal('image'); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: false - }, [BID_RESPONSE_IMAGE_SYNC]); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: false, - pixelEnabled: true - }, []); - expect(syncs).to.have.lengthOf(0); - }); - - it('should set browsingTopics=false in request.options', () => { - const requests = spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL); - expect(requests[0]).to.have.property('options').and.to.deep.equal({ - browsingTopics: false - }); - }); - - it('Verify metadata', function () { - const adomain = ['advertiser-domain.com']; - const dsa = { - dsarequired: 1, - pubrender: 0, - datatopub: 1, - transparency: [{ - domain: 'smartadserver.com', - dsaparams: [1, 2] - }] - }; - const request = spec.buildRequests(DEFAULT_PARAMS); - const bids = spec.interpretResponse({ - body: { - ...BID_RESPONSE.body, - adomain, - dsa, - } - }, request[0]); - - expect(bids[0].cpm).to.equal(12); - expect(bids[0]).to.have.property('meta'); - expect(bids[0].meta).to.have.property('advertiserDomains').and.to.deep.equal(adomain); - expect(bids[0].meta).to.have.property('dsa').and.to.deep.equal(dsa); - }); - - describe('gdpr tests', function () { - afterEach(function () { - config.setConfig({ ortb2: undefined }); - config.resetConfig(); - }); - - it('Verify build request with GDPR', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - }, - consentManagement: { - cmp: 'iab', - consentRequired: true, - timeout: 1000, - allowAuctionWithoutConsent: true - } - }); - const request = spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL, { - gdprConsent: { - consentString: 'BOKAVy4OKAVy4ABAB8AAAAAZ+A==', - gdprApplies: true - } - }); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('gdpr').and.to.equal(true); - expect(requestContent).to.have.property('gdpr_consent').and.to.equal('BOKAVy4OKAVy4ABAB8AAAAAZ+A=='); - }); - - it('Verify build request with GDPR without gdprApplies', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - }, - consentManagement: { - cmp: 'iab', - consentRequired: true, - timeout: 1000, - allowAuctionWithoutConsent: true - } - }); - const request = spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL, { - gdprConsent: { - consentString: 'BOKAVy4OKAVy4ABAB8AAAAAZ+A==' - } - }); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.not.have.property('gdpr'); - expect(requestContent).to.have.property('gdpr_consent').and.to.equal('BOKAVy4OKAVy4ABAB8AAAAAZ+A=='); - }); - }); - - describe('GPP', function () { - it('should be added to payload when gppConsent available in bidder request', function () { - const options = { - gppConsent: { - gppString: 'some-gpp-string', - applicableSections: [3, 5] - } - }; - const request = spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL, options); - const payload = JSON.parse(request[0].data); - - expect(payload).to.have.property('gpp').and.to.equal(options.gppConsent.gppString); - expect(payload).to.have.property('gpp_sid').and.to.be.an('array'); - expect(payload.gpp_sid).to.have.lengthOf(2).and.to.deep.equal(options.gppConsent.applicableSections); - }); - - it('should be undefined on payload when gppConsent unavailable in bidder request', function () { - const request = spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL, {}); - const payload = JSON.parse(request[0].data); - - expect(payload.gpp).to.be.undefined; - }); - }); - - describe('ccpa/us privacy tests', function () { - afterEach(function () { - config.resetConfig(); - }); - - it('Verify build request with us privacy', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - }, - consentManagement: { - cmp: 'iab', - consentRequired: true, - timeout: 1000, - allowAuctionWithoutConsent: true - } - }); - - const uspConsentValue = '1YNN' - const request = spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL, { - uspConsent: uspConsentValue - }); - const requestContent = JSON.parse(request[0].data); - - expect(requestContent).to.have.property('us_privacy').and.to.equal(uspConsentValue); - }); - }); - - describe('Instream video tests', function () { - afterEach(function () { - config.resetConfig(); - }); - - const INSTREAM_DEFAULT_PARAMS = [{ - adUnitCode: 'sas_42', - bidId: 'abcd1234', - bidder: 'smartadserver', - mediaTypes: { - video: { - context: 'instream', - playerSize: [[640, 480]] // It seems prebid.js transforms the player size array into an array of array... - } - }, - params: { - siteId: '1234', - pageId: '5678', - formatId: '90', - target: 'test=prebid', - bidfloor: 0.420, - buId: '7569', - appName: 'Mozilla', - ckId: 42, - video: { - protocol: 6 - } - }, - requestId: 'efgh5678', - ortb2Imp: { - ext: { - tid: 'zsfgzzg', - } - }, - }]; - - var INSTREAM_BID_RESPONSE = { - body: { - cpm: 12, - width: 640, - height: 480, - creativeId: 'zioeufg', - currency: 'GBP', - isNetCpm: true, - ttl: 300, - adUrl: 'http://awesome.fake-vast.url', - ad: '', - cSyncUrl: 'http://awesome.fake.csync.url' - } - }; - - it('Verify instream video build request', function () { - setCurrencyConfig({ adServerCurrency: 'EUR' }); - config.setConfig({ - ortb2: { - 'user': { - 'data': sellerDefinedAudience - }, - 'site': { - 'content': { - 'data': sellerDefinedContext - } - } - } - }); - - return addFPDToBidderRequest(INSTREAM_DEFAULT_PARAMS[0]).then(res => { - const request = spec.buildRequests(INSTREAM_DEFAULT_PARAMS, res); - expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); - expect(request[0]).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('siteid').and.to.equal('1234'); - expect(requestContent).to.have.property('pageid').and.to.equal('5678'); - expect(requestContent).to.have.property('formatid').and.to.equal('90'); - expect(requestContent).to.have.property('currencyCode').and.to.equal('EUR'); - expect(requestContent).to.have.property('bidfloor').and.to.equal(0.42); - expect(requestContent).to.have.property('targeting').and.to.equal('test=prebid'); - expect(requestContent).to.have.property('tagId').and.to.equal('sas_42'); - expect(requestContent).to.not.have.property('pageDomain'); - expect(requestContent).to.have.property('transactionId').and.to.not.equal(null).and.to.not.be.undefined; - expect(requestContent).to.have.property('buid').and.to.equal('7569'); - expect(requestContent).to.have.property('appname').and.to.equal('Mozilla'); - expect(requestContent).to.have.property('ckid').and.to.equal(42); - expect(requestContent).to.have.property('sda').and.to.deep.equal(sellerDefinedAudience); - expect(requestContent).to.have.property('sdc').and.to.deep.equal(sellerDefinedContext); - expect(requestContent).to.have.property('isVideo').and.to.equal(true); - expect(requestContent).to.have.property('videoData'); - expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(6); - expect(requestContent.videoData).to.have.property('playerWidth').and.to.equal(640); - expect(requestContent.videoData).to.have.property('playerHeight').and.to.equal(480); - setCurrencyConfig({}); - }); - }); - - it('Verify instream parse response', function () { - const request = spec.buildRequests(INSTREAM_DEFAULT_PARAMS); - const bids = spec.interpretResponse(INSTREAM_BID_RESPONSE, request[0]); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(12); - expect(bid.mediaType).to.equal('video'); - expect(bid.vastUrl).to.equal('http://awesome.fake-vast.url'); - expect(bid.vastXml).to.equal(''); - expect(bid.content).to.equal(''); - expect(bid.width).to.equal(640); - expect(bid.height).to.equal(480); - expect(bid.creativeId).to.equal('zioeufg'); - expect(bid.currency).to.equal('GBP'); - expect(bid.netRevenue).to.equal(true); - expect(bid.ttl).to.equal(300); - expect(bid.requestId).to.equal(INSTREAM_DEFAULT_PARAMS[0].bidId); - - expect(function () { - spec.interpretResponse(INSTREAM_BID_RESPONSE, { - data: 'invalid Json' - }) - }).to.not.throw(); - }); - - it('Verify not handled media type return empty request', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - } - }); - const request = spec.buildRequests([{ - adUnitCode: 'sas_42', - bidder: 'smartadserver', - mediaTypes: { - video: { - context: 'badcontext' - } - }, - params: { - domain: 'https://prg.smartadserver.com', - siteId: '1234', - pageId: '5678', - formatId: '90', - target: 'test=prebid', - bidfloor: 0.420, - buId: '7569', - appName: 'Mozilla', - ckId: 42 - }, - requestId: 'efgh5678', - transactionId: 'zsfgzzg' - }, INSTREAM_DEFAULT_PARAMS[0]]); - expect(request[0]).to.be.empty; - expect(request[1]).to.not.be.empty; - }); - - describe('Instream videoData meta & params tests', function () { - it('Verify videoData assigns values from meta', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - } - }); - const request = spec.buildRequests([{ - adUnitCode: 'sas_42', - bidId: 'abcd1234', - bidder: 'smartadserver', - mediaTypes: { - video: { - context: 'instream', - playerSize: [[640, 480]], // It seems prebid.js transforms the player size array into an array of array... - protocols: [8, 2], - startdelay: 0 - } - }, - params: { - siteId: '1234', - pageId: '5678', - formatId: '90', - target: 'test=prebid', - bidfloor: 0.420, - buId: '7569', - appName: 'Mozilla', - ckId: 42, - }, - requestId: 'efgh5678', - transactionId: 'zsfgzzg' - }]); - - expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); - expect(request[0]).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('videoData'); - expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(8); - expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(1); - }); - - it('Verify videoData default values assigned', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - } - }); - const request = spec.buildRequests([{ - adUnitCode: 'sas_42', - bidId: 'abcd1234', - bidder: 'smartadserver', - mediaTypes: { - video: { - context: 'instream', - playerSize: [[640, 480]] // It seems prebid.js transforms the player size array into an array of array... - } - }, - params: { - siteId: '1234', - pageId: '5678', - formatId: '90', - target: 'test=prebid', - bidfloor: 0.420, - buId: '7569', - appName: 'Mozilla', - ckId: 42, - }, - requestId: 'efgh5678', - transactionId: 'zsfgzzg' - }]); - - expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); - expect(request[0]).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('videoData'); - expect(requestContent.videoData).not.to.have.property('videoProtocol').eq(true); - expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(1); - }); - - it('Verify videoData params override meta values', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - } - }); - const request = spec.buildRequests([{ - adUnitCode: 'sas_42', - bidId: 'abcd1234', - bidder: 'smartadserver', - mediaTypes: { - video: { - context: 'instream', - playerSize: [[640, 480]], // It seems prebid.js transforms the player size array into an array of array... - protocols: [8, 2], - startdelay: 0 - } - }, - params: { - siteId: '1234', - pageId: '5678', - formatId: '90', - target: 'test=prebid', - bidfloor: 0.420, - buId: '7569', - appName: 'Mozilla', - ckId: 42, - video: { - protocol: 6, - startDelay: 3 - } - }, - requestId: 'efgh5678', - transactionId: 'zsfgzzg' - }]); - - expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); - expect(request[0]).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('videoData'); - expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(6); - expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(3); - }); - - it('should pass additional parameters', function () { - const request = spec.buildRequests([{ - bidder: 'smartadserver', - mediaTypes: { - video: { - context: 'instream', - api: [1, 2, 3], - maxbitrate: 50, - minbitrate: 20, - maxduration: 30, - minduration: 5, - placement: 3, - playbackmethod: [2, 4], - playerSize: [[640, 480]], - plcmt: 1, - skip: 0 - } - }, - params: { - siteId: '123' - } - }]); - const requestContent = JSON.parse(request[0].data); - - expect(requestContent.videoData).to.have.property('iabframeworks').and.to.equal('1,2,3'); - expect(requestContent.videoData).not.to.have.property('skip'); - expect(requestContent.videoData).to.have.property('vbrmax').and.to.equal(50); - expect(requestContent.videoData).to.have.property('vbrmin').and.to.equal(20); - expect(requestContent.videoData).to.have.property('vdmax').and.to.equal(30); - expect(requestContent.videoData).to.have.property('vdmin').and.to.equal(5); - expect(requestContent.videoData).to.have.property('vplcmt').and.to.equal(1); - expect(requestContent.videoData).to.have.property('vpmt').and.to.have.lengthOf(2); - expect(requestContent.videoData.vpmt[0]).to.equal(2); - expect(requestContent.videoData.vpmt[1]).to.equal(4); - expect(requestContent.videoData).to.have.property('vpt').and.to.equal(3); - }); - - it('should not pass not valuable parameters', function () { - const request = spec.buildRequests([{ - bidder: 'smartadserver', - mediaTypes: { - video: { - context: 'instream', - maxbitrate: 20, - minbitrate: null, - maxduration: 0, - playbackmethod: [], - playerSize: [[640, 480]], - plcmt: 1 - } - }, - params: { - siteId: '123' - } - }]); - const requestContent = JSON.parse(request[0].data); - - expect(requestContent.videoData).not.to.have.property('iabframeworks'); - expect(requestContent.videoData).to.have.property('vbrmax').and.to.equal(20); - expect(requestContent.videoData).not.to.have.property('vbrmin'); - expect(requestContent.videoData).not.to.have.property('vdmax'); - expect(requestContent.videoData).not.to.have.property('vdmin'); - expect(requestContent.videoData).to.have.property('vplcmt').and.to.equal(1); - expect(requestContent.videoData).not.to.have.property('vpmt'); - expect(requestContent.videoData).not.to.have.property('vpt'); - }); - }); - }); - - describe('Outstream video tests', function () { - afterEach(function () { - config.resetConfig(); - }); - - const OUTSTREAM_DEFAULT_PARAMS = [{ - adUnitCode: 'sas_43', - bidId: 'abcd1234', - bidder: 'smartadserver', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[800, 600]] // It seems prebid.js transforms the player size array into an array of array... - } - }, - params: { - siteId: '1234', - pageId: '5678', - formatId: '91', - target: 'test=prebid-outstream', - bidfloor: 0.430, - buId: '7579', - appName: 'Mozilla', - ckId: 43, - video: { - protocol: 7 - } - }, - ortb2Imp: { - ext: { - tid: 'efgh5679', - } - }, - transactionId: 'zsfgzzga' - }]; - - var OUTSTREAM_BID_RESPONSE = { - body: { - cpm: 14, - width: 800, - height: 600, - creativeId: 'zioeufga', - currency: 'USD', - isNetCpm: true, - ttl: 300, - adUrl: 'http://awesome.fake-vast2.url', - ad: '', - cSyncUrl: 'http://awesome.fake2.csync.url' - } - }; - - it('Verify outstream video build request', function () { - setCurrencyConfig({ adServerCurrency: 'EUR' }); - config.setConfig({ - ortb2: { - 'user': { - 'data': sellerDefinedAudience - }, - 'site': { - 'content': { - 'data': sellerDefinedContext - } - } - } - }); - - return addFPDToBidderRequest(OUTSTREAM_DEFAULT_PARAMS[0]).then(res => { - const request = spec.buildRequests(OUTSTREAM_DEFAULT_PARAMS, res); - expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); - expect(request[0]).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('siteid').and.to.equal('1234'); - expect(requestContent).to.have.property('pageid').and.to.equal('5678'); - expect(requestContent).to.have.property('formatid').and.to.equal('91'); - expect(requestContent).to.have.property('currencyCode').and.to.equal('EUR'); - expect(requestContent).to.have.property('bidfloor').and.to.equal(0.43); - expect(requestContent).to.have.property('targeting').and.to.equal('test=prebid-outstream'); - expect(requestContent).to.have.property('tagId').and.to.equal('sas_43'); - expect(requestContent).to.not.have.property('pageDomain'); - expect(requestContent).to.have.property('transactionId').and.to.not.equal(null).and.to.not.be.undefined; - expect(requestContent).to.have.property('buid').and.to.equal('7579'); - expect(requestContent).to.have.property('appname').and.to.equal('Mozilla'); - expect(requestContent).to.have.property('ckid').and.to.equal(43); - expect(requestContent).to.have.property('sda').and.to.deep.equal(sellerDefinedAudience); - expect(requestContent).to.have.property('sdc').and.to.deep.equal(sellerDefinedContext); - expect(requestContent).to.have.property('isVideo').and.to.equal(false); - expect(requestContent).to.have.property('videoData'); - expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(7); - expect(requestContent.videoData).to.have.property('playerWidth').and.to.equal(800); - expect(requestContent.videoData).to.have.property('playerHeight').and.to.equal(600); - setCurrencyConfig({}); - }); - }); - - it('Verify outstream parse response', function () { - const request = spec.buildRequests(OUTSTREAM_DEFAULT_PARAMS); - const bids = spec.interpretResponse(OUTSTREAM_BID_RESPONSE, request[0]); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(14); - expect(bid.mediaType).to.equal('video'); - expect(bid.vastUrl).to.equal('http://awesome.fake-vast2.url'); - expect(bid.vastXml).to.equal(''); - expect(bid.content).to.equal(''); - expect(bid.width).to.equal(800); - expect(bid.height).to.equal(600); - expect(bid.creativeId).to.equal('zioeufga'); - expect(bid.currency).to.equal('USD'); - expect(bid.netRevenue).to.equal(true); - expect(bid.ttl).to.equal(300); - expect(bid.requestId).to.equal(OUTSTREAM_DEFAULT_PARAMS[0].bidId); - - expect(function () { - spec.interpretResponse(OUTSTREAM_BID_RESPONSE, { - data: 'invalid Json' - }) - }).to.not.throw(); - }); - }); - - describe('Outstream videoData meta & params tests', function () { - it('Verify videoData assigns values from meta', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - } - }); - const request = spec.buildRequests([{ - adUnitCode: 'sas_42', - bidId: 'abcd1234', - bidder: 'smartadserver', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[640, 480]], // It seems prebid.js transforms the player size array into an array of array... - protocols: [8, 2], - startdelay: 0 - } - }, - params: { - siteId: '1234', - pageId: '5678', - formatId: '90', - target: 'test=prebid-outstream', - bidfloor: 0.420, - buId: '7569', - appName: 'Mozilla', - ckId: 42, - }, - requestId: 'efgh5678', - transactionId: 'zsfgzzg' - }]); - - expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); - expect(request[0]).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('videoData'); - expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(8); - expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(1); - }); - - it('Verify videoData default values assigned', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - } - }); - const request = spec.buildRequests([{ - adUnitCode: 'sas_42', - bidId: 'abcd1234', - bidder: 'smartadserver', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[640, 480]] // It seems prebid.js transforms the player size array into an array of array... - } - }, - params: { - siteId: '1234', - pageId: '5678', - formatId: '90', - target: 'test=prebid-outstream', - bidfloor: 0.420, - buId: '7569', - appName: 'Mozilla', - ckId: 42, - }, - requestId: 'efgh5678', - transactionId: 'zsfgzzg' - }]); - - expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); - expect(request[0]).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('videoData'); - expect(requestContent.videoData).not.to.have.property('videoProtocol').eq(true); - expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(1); - }); - - it('Verify videoData params override meta values', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - } - }); - const request = spec.buildRequests([{ - adUnitCode: 'sas_42', - bidId: 'abcd1234', - bidder: 'smartadserver', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[640, 480]], // It seems prebid.js transforms the player size array into an array of array... - protocols: [8, 2], - startdelay: 0 - } - }, - params: { - siteId: '1234', - pageId: '5678', - formatId: '90', - target: 'test=prebid-outstream', - bidfloor: 0.420, - buId: '7569', - appName: 'Mozilla', - ckId: 42, - video: { - protocol: 6, - startDelay: 3 - } - }, - requestId: 'efgh5678', - transactionId: 'zsfgzzg' - }]); - - expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); - expect(request[0]).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('videoData'); - expect(requestContent.videoData).to.have.property('videoProtocol').and.to.equal(6); - expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(3); - }); - - it('should handle value of videoMediaType.startdelay', function () { - const request = spec.buildRequests([{ - bidder: 'smartadserver', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[640, 480]], - startdelay: -2 - } - }, - params: { - siteId: 123, - pageId: 456, - formatId: 78 - } - }]); - - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('videoData'); - expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(3); - }); - - it('should return specified value of videoMediaType.startdelay', function () { - const request = spec.buildRequests([{ - bidder: 'smartadserver', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[640, 480]], - startdelay: 60 - } - }, - params: { - siteId: 123, - pageId: 456, - formatId: 78 - } - }]); - - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('videoData'); - expect(requestContent.videoData).to.have.property('adBreak').and.to.equal(2); - }); - }); - - describe('External ids tests', function () { - it('Verify external ids in request and ids found', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - } - }); - const request = spec.buildRequests(DEFAULT_PARAMS_WITH_EIDS); - expect(request[0]).to.have.property('url').and.to.equal('https://prg.smartadserver.com/prebid/v1'); - expect(request[0]).to.have.property('method').and.to.equal('POST'); - const requestContent = JSON.parse(request[0].data); - - expect(requestContent).to.have.property('eids'); - expect(requestContent.eids).to.not.equal(null).and.to.not.be.undefined; - expect(requestContent.eids.length).to.greaterThan(0); - for (const index in requestContent.eids) { - const eid = requestContent.eids[index]; - expect(eid.source).to.not.equal(null).and.to.not.be.undefined; - expect(eid.uids).to.not.equal(null).and.to.not.be.undefined; - for (const uidsIndex in eid.uids) { - const uid = eid.uids[uidsIndex]; - expect(uid.id).to.not.equal(null).and.to.not.be.undefined; - } - } - }); - }); - - describe('Supply Chain Serializer tests', function () { - it('Verify a multi node supply chain serialization matches iab example', function() { - const schain = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'exchange1.com', - 'sid': '1234', - 'hp': 1, - 'rid': 'bid-request-1', - 'name': 'publisher', - 'domain': 'publisher.com' - }, - { - 'asi': 'exchange2.com', - 'sid': 'abcd', - 'hp': 1, - 'rid': 'bid-request-2', - 'name': 'intermediary', - 'domain': 'intermediary.com' - } - ] - }; - - const serializedSchain = spec.serializeSupplyChain(schain); - expect(serializedSchain).to.equal('1.0,1!exchange1.com,1234,1,bid-request-1,publisher,publisher.com!exchange2.com,abcd,1,bid-request-2,intermediary,intermediary.com'); - }); - - it('Verifiy that null schain produce null result', function () { - const actual = spec.serializeSupplyChain(null); - expect(null, actual); - }); - - it('Verifiy that schain with null nodes produce null result', function () { - const schain = { - 'ver': '1.0', - 'complete': 1 - - }; - const actual = spec.serializeSupplyChain(null); - expect(null, actual); - }); - }); - - describe('Floors module', function () { - const getFloor = (bid) => { - switch (bid.mediaType) { - case BANNER: - return { currency: 'USD', floor: 1.93 }; - case VIDEO: - return { currency: 'USD', floor: 2.72 }; - default: - return {}; - } - }; - - it('should include floor from bid params', function() { - const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS))[0].data); - expect(bidRequest.bidfloor).to.deep.equal(DEFAULT_PARAMS[0].params.bidfloor); - }); - - it('should return default floor when module not activated', function() { - const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL))[0].data); - - const floor = getBidFloor(bidRequest, 'EUR'); - expect(floor).to.deep.equal(0); - }); - - it('should return default floor when getFloor returns not proper object', function() { - const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL))[0].data); - bidRequest.getFloor = function () { - return { floor: 'one' }; - }; - - const floor = getBidFloor(bidRequest, 'EUR'); - expect(floor).to.deep.equal(0.0); - }); - - it('should return default floor when currency unknown', function() { - const bidRequest = JSON.parse((spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL))[0].data); - - const floor = getBidFloor(bidRequest, null); - expect(floor).to.deep.equal(0); - }); - - it('should take floor from bidder params over ad unit', function() { - const bidRequest = [{ - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - getFloor, - params: { siteId: 1234, pageId: 678, formatId: 73, bidfloor: 1.25 } - }]; - - const request = spec.buildRequests(bidRequest); - const requestContent = JSON.parse(request[0].data); - - expect(requestContent).to.have.property('bidfloor').and.to.equal(1.25); - }); - - it('should take floor from banner ad unit', function() { - const bidRequest = [{ - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - getFloor, - params: { siteId: 1234, pageId: 678, formatId: 73 } - }]; - - const request = spec.buildRequests(bidRequest); - const requestContent = JSON.parse(request[0].data); - - expect(requestContent).to.have.property('bidfloor').and.to.equal(1.93); - }); - - it('should take floor from video ad unit', function() { - const bidRequest = [{ - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[640, 480]] - } - }, - getFloor, - params: { siteId: 1234, pageId: 678, formatId: 73 } - }]; - - const request = spec.buildRequests(bidRequest); - const requestContent = JSON.parse(request[0].data); - - expect(requestContent).to.have.property('bidfloor').and.to.equal(2.72); - }); - - it('should take floor from multiple media type ad unit', function() { - const bidRequest = [{ - mediaTypes: { - banner: { - sizes: [[300, 600]] - }, - video: { - context: 'outstream', - playerSize: [[640, 480]] - } - }, - getFloor, - params: { siteId: 1234, pageId: 678, formatId: 73 } - }]; - - const requests = spec.buildRequests(bidRequest); - expect(requests).to.have.lengthOf(2); - - const requestContents = requests.map(r => JSON.parse(r.data)); - const videoRequest = requestContents.filter(r => r.videoData)[0]; - expect(videoRequest).to.not.equal(null).and.to.not.be.undefined; - expect(videoRequest).to.have.property('bidfloor').and.to.equal(2.72); - - const bannerRequest = requestContents.filter(r => !r.videoData)[0]; - expect(bannerRequest).to.not.equal(null).and.to.not.be.undefined; - expect(bannerRequest).to.have.property('bidfloor').and.to.equal(1.93); - }); - - describe('#getBidFloor', () => { - let bid; - beforeEach(() => { - bid = { - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ] - } - }, - getFloor: (data) => { - if (data.currency === 'USD') { - if (data.mediaType === BANNER) { - if (data.size[0] === 300 && data.size[1] === 250) { - return { floor: 1.2 }; - } else if (data.size[0] === 300 && data.size[1] === 600) { - return { floor: 1.4 }; - } else if (data.size[0] === 30 && data.size[1] === 60) { - return 'string'; - } else { - return { floor: 1.0 }; - } - } else if (data.mediaType === VIDEO) { - if (data.size[0] === 640 && data.size[1] === 480) { - return { floor: 2.3 }; - } else { - return { floor: 2.1 }; - } - } else { - return {}; - } - } else { - return undefined; - } - } - }; - }); - - it('should return lowest floor from specified ones', () => { - expect(getBidFloor(bid, 'USD', BANNER)).to.deep.eq(1.2); - }); - - it('should return default floor for media type whatever size', () => { - bid.mediaTypes.banner.sizes.push([300, 400]); - expect(getBidFloor(bid, 'USD', BANNER)).to.deep.eq(1.0); - }); - - it('should return default floor', () => { - expect(getBidFloor(bid, 'USD', VIDEO)).to.deep.eq(0); - }); - - it('should return floor when currency not passed', () => { - expect(getBidFloor(bid, undefined, BANNER)).to.deep.eq(1.2); - }); - - it('should return DEFAULT_FLOOR in case of not a number value from floor module', () => { - bid.mediaTypes.banner.sizes.push([30, 60]); - expect(getBidFloor(bid, 'USD', BANNER)).to.deep.eq(0); - }); - - it('should return proper video floor', () => { - bid.mediaTypes = { - video: { - playerSize: [ - [640, 480] - ] - } - }; - expect(getBidFloor(bid, 'USD', VIDEO)).to.deep.eq(2.3); - }); - - it('should return default video floor', () => { - bid.mediaTypes = { - video: { - playerSize: [ - [640, 490] - ] - } - }; - expect(getBidFloor(bid, 'USD', VIDEO)).to.deep.eq(2.1); - }); - - it('should return DEFAULT_FLOOR for not supported media type', () => { - expect(getBidFloor(bid, 'USD', 'test')).to.deep.eq(0); - }); - }); - }); - - describe('Verify bid requests with multiple mediaTypes', function () { - afterEach(function () { - config.resetConfig(); - }); - - var DEFAULT_PARAMS_MULTIPLE_MEDIA_TYPES = [{ - adUnitCode: 'sas_42', - bidId: 'abcd1234', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 200] - ] - }, - video: { - context: 'outstream', - playerSize: [[640, 480]] // It seems prebid.js transforms the player size array into an array of array... - } - }, - bidder: 'smartadserver', - params: { - domain: 'https://prg.smartadserver.com', - siteId: '1234', - pageId: '5678', - formatId: '90', - target: 'test=prebid', - bidfloor: 0.420, - buId: '7569', - appName: 'Mozilla', - ckId: 42, - video: { - protocol: 6, - startDelay: 1 - } - }, - requestId: 'efgh5678', - transactionId: 'zsfgzzg' - }]; - - it('Verify build request with banner and outstream', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - } - }); - const requests = spec.buildRequests(DEFAULT_PARAMS_MULTIPLE_MEDIA_TYPES); - expect(requests).to.have.lengthOf(2); - - const requestContents = requests.map(r => JSON.parse(r.data)); - const videoRequest = requestContents.filter(r => r.videoData)[0]; - expect(videoRequest).to.not.equal(null).and.to.not.be.undefined; - - const bannerRequest = requestContents.filter(r => !r.videoData)[0]; - expect(bannerRequest).to.not.equal(null).and.to.not.be.undefined; - - expect(videoRequest).to.not.equal(bannerRequest); - expect(videoRequest.videoData).to.have.property('videoProtocol').and.to.equal(6); - expect(videoRequest.videoData).to.have.property('playerWidth').and.to.equal(640); - expect(videoRequest.videoData).to.have.property('playerHeight').and.to.equal(480); - expect(videoRequest).to.have.property('siteid').and.to.equal('1234'); - expect(videoRequest).to.have.property('pageid').and.to.equal('5678'); - expect(videoRequest).to.have.property('formatid').and.to.equal('90'); - - expect(bannerRequest).to.have.property('siteid').and.to.equal('1234'); - expect(bannerRequest).to.have.property('pageid').and.to.equal('5678'); - expect(bannerRequest).to.have.property('formatid').and.to.equal('90'); - }); - }); - - describe('Global Placement ID (GPID)', function () { - it('should not include gpid by default', () => { - const request = spec.buildRequests(DEFAULT_PARAMS_WO_OPTIONAL); - const requestContent = JSON.parse(request[0].data); - - expect(requestContent).to.not.have.property('gdid'); - }); - - it('should include gpid if pbadslot in ortb2Imp', () => { - const gpid = '/19968336/header-bid-tag-1'; - const bidRequests = deepClone(DEFAULT_PARAMS_WO_OPTIONAL); - - bidRequests[0].ortb2Imp = { - ext: { - data: {}, - gpid - } - }; - - const request = spec.buildRequests(bidRequests); - const requestContent = JSON.parse(request[0].data); - - expect(requestContent).to.have.property('gpid').and.to.equal(gpid); - }); - - it('should include gpid if imp[].ext.gpid exists', () => { - const gpid = '/1111/homepage#div-leftnav'; - const bidRequests = deepClone(DEFAULT_PARAMS_WO_OPTIONAL); - - bidRequests[0].ortb2Imp = { - ext: { gpid } - }; - - const request = spec.buildRequests(bidRequests); - const requestContent = JSON.parse(request[0].data); - - expect(requestContent).to.have.property('gpid').and.to.equal(gpid); - }); - }); - - describe('Digital Services Act (DSA)', function () { - it('should include dsa if ortb2.regs.ext.dsa available', function () { - const dsa = { - dsarequired: 1, - pubrender: 0, - datatopub: 1, - transparency: [ - { - domain: 'ok.domain.com', - dsaparams: [1, 2] - }, - { - domain: 'ko.domain.com', - dsaparams: [1, '3'] - } - ] - }; - - const bidRequests = deepClone(DEFAULT_PARAMS_WO_OPTIONAL); - bidRequests[0].ortb2 = { - regs: { - ext: { dsa } - } - }; - - const request = spec.buildRequests(bidRequests); - const requestContent = JSON.parse(request[0].data); - - expect(requestContent).to.have.property('dsa').and.to.deep.equal(dsa); - }); - }); - - describe('#getValuableProperty method', function () { - it('should return an object when calling with a number value', () => { - const obj = spec.getValuableProperty('prop', 3); - expect(obj).to.deep.equal({ prop: 3 }); - }); - - it('should return an empty object when calling with a string value', () => { - const obj = spec.getValuableProperty('prop', 'str'); - expect(obj).to.deep.equal({}); - }); - - it('should return an empty object when calling with a number property', () => { - const obj = spec.getValuableProperty(7, 'str'); - expect(obj).to.deep.equal({}); - }); - - it('should return an empty object when calling with a null value', () => { - const obj = spec.getValuableProperty('prop', null); - expect(obj).to.deep.equal({}); - }); - - it('should return an empty object when calling with an object value', () => { - const obj = spec.getValuableProperty('prop', {}); - expect(obj).to.deep.equal({}); - }); - - it('should return an empty object when calling with a 0 value', () => { - const obj = spec.getValuableProperty('prop', 0); - expect(obj).to.deep.equal({}); - }); - - it('should return an empty object when calling without the value argument', () => { - const obj = spec.getValuableProperty('prop'); - expect(obj).to.deep.equal({}); - }); - }); -}); diff --git a/test/spec/modules/smarthubBidAdapter_spec.js b/test/spec/modules/smarthubBidAdapter_spec.js deleted file mode 100644 index 29607365c..000000000 --- a/test/spec/modules/smarthubBidAdapter_spec.js +++ /dev/null @@ -1,490 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/smarthubBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'smarthub'; -const bidderAlias = 'markapp'; - -describe('SmartHubBidAdapter', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - partnerName: 'testname', - seat: 'testSeat', - token: 'testBanner', - iabCat: ['IAB1-1', 'IAB3-1', 'IAB4-3'], - minBidfloor: 10, - pos: 1, - } - }, - { - bidId: getUniqueIdentifierStr(), - bidder: 'Jambojar', - mediaTypes: { - [BANNER]: { - sizes: [[400, 350]] - } - }, - params: { - seat: 'testSeat', - token: 'testBanner', - region: 'Apac', - iabCat: ['IAB1-1', 'IAB3-1', 'IAB4-3'], - minBidfloor: 9, - pos: 1, - } - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidderAlias, - mediaTypes: { - [BANNER]: { - sizes: [[400, 350]] - } - }, - params: { - seat: 'testSeat', - token: 'testBanner', - iabCat: ['IAB1-1', 'IAB3-1', 'IAB4-3'], - minBidfloor: 9, - pos: 1, - } - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60, - plcmt: 1, - } - }, - params: { - partnerName: 'testname', - seat: 'testSeat', - token: 'testVideo', - iabCat: ['IAB1-1', 'IAB3-1', 'IAB4-3'], - minBidfloor: 10, - pos: 1, - } - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true - }, - body: { - required: true - }, - icon: { - required: true, - size: [64, 64] - } - } - } - }, - params: { - partnerName: 'testname', - seat: 'testSeat', - token: 'testToken', - iabCat: ['IAB1-1', 'IAB3-1', 'IAB4-3'], - minBidfloor: 10, - pos: 1, - } - } - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]] - } - }, - params: { - - } - } - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw' - }, - refererInfo: { - page: 'https://test.com' - }, - timeout: 500 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let [serverRequest, regionRequest, requestAlias] = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(serverRequest.url).to.equal(`https://prebid.attekmi.co/pbjs?partnerName=testname`); - }); - - it('Returns valid URL if region added', function () { - expect(regionRequest.url).to.equal(`https://jambojar-apac-prebid.attekmi.co/pbjs`); - }); - - it('Returns valid URL if alias', function () { - expect(requestAlias.url).to.equal(`https://${bidderAlias}-prebid.attekmi.co/pbjs`); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', - 'deviceHeight', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr.consentString).to.be.a('string'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.partnerName).to.be.a('string'); - expect(placement.seat).to.be.a('string'); - expect(placement.token).to.be.a('string'); - expect(placement.iabCat).to.be.an('array'); - expect(placement.minBidfloor).to.be.a('number'); - expect(placement.pos).to.be.within(0, 7); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - expect(placement.plcmt).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest[0].data; - expect(data.gdpr).to.exist; - expect(data.gdpr.consentString).to.be.a('string'); - expect(data.gdpr.consentString).to.equal(bidderRequest.gdprConsent.consentString); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest[0].data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - - it('Returns empty data if no valid requests are passed', function () { - serverRequest = spec.buildRequests([], bidderRequest); - expect(serverRequest).to.be.an('array').that.is.empty; - }); - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta).to.be.an('object').that.has.property('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - width: 300, - height: 250, - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta', 'width', 'height'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.property('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234 - } - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta).to.be.an('object').that.has.property('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function() { - it('Should return array of objects with GDPR values', function() { - const syncData = spec.getUserSyncs({}, {}, { - consentString: 'ALL', - gdprApplies: true, - }, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://us4.shb-sync.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0&pid=360') - }); - it('Should return array of objects with CCPA values', function() { - const syncData = spec.getUserSyncs({}, {}, {}, { - consentString: '1---' - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://us4.shb-sync.com/image?pbjs=1&ccpa_consent=1---&coppa=0&pid=360') - }); - it('Should return array of objects with GPP values', function() { - const syncData = spec.getUserSyncs({}, {}, {}, {}, { - gppString: 'ab12345', - applicableSections: [8] - }); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('image') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://us4.shb-sync.com/image?pbjs=1&gpp=ab12345&gpp_sid=8&coppa=0&pid=360') - }); - it('Should return iframe type if iframeEnabled is true', function() { - const syncData = spec.getUserSyncs({iframeEnabled: true}, {}, {}, {}, {}); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object') - expect(syncData[0].type).to.be.a('string') - expect(syncData[0].type).to.equal('iframe') - expect(syncData[0].url).to.be.a('string') - expect(syncData[0].url).to.equal('https://us4.shb-sync.com/iframe?pbjs=1&coppa=0&pid=360') - }); - }); -}); diff --git a/test/spec/modules/smarticoBidAdapter_spec.js b/test/spec/modules/smarticoBidAdapter_spec.js deleted file mode 100644 index 50fba36e2..000000000 --- a/test/spec/modules/smarticoBidAdapter_spec.js +++ /dev/null @@ -1,135 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/smarticoBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; - -describe('smarticoBidAdapter', function () { - const adapter = newBidder(spec); - const bid = { - adUnitCode: 'adunit-code', - auctionId: '5kaj89l8-3456-2s56-c455-4g6h78jsdfgf', - bidRequestsCount: 1, - bidder: 'smartico', - bidderRequestId: '24081afs940568', - bidderRequestsCount: 1, - bidderWinsCount: 0, - bidId: '22499d052045', - mediaTypes: {banner: {sizes: [[300, 250]]}}, - params: { - token: 'FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya', - placementId: 'testPlacementId' - }, - sizes: [ - [300, 250] - ], - transactionId: '34562345-4dg7-46g7-4sg6-45gdsdj8fd56' - } - const bidderRequests = { - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - auctionStart: 1579746300522, - bidderCode: 'myBidderCode', - bidderRequestId: '15246a574e859f', - bids: [bid], - refererInfo: { - canonicalUrl: '', - numIframes: 0, - reachedTop: true - } - } - describe('isBidRequestValid', function () { - it('should return true where required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - describe('buildRequests', function () { - const bidRequests = [ bid ]; - const request = spec.buildRequests(bidRequests, bidderRequests); - it('sends bid request via POST', function () { - expect(request.method).to.equal('POST'); - }); - it('must contain token', function() { - expect(request.data.bidParams[0].token).to.equal('FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya'); - }); - it('must contain auctionId', function() { - expect(request.data.auctionId).to.exist.and.to.be.a('string') - }); - it('must contain valid width and height', function() { - expect(request.data.bidParams[0]['banner-format-width']).to.exist.and.to.be.a('number') - expect(request.data.bidParams[0]['banner-format-height']).to.exist.and.to.be.a('number') - }); - }); - - describe('interpretResponse', function () { - const bidRequest = { - method: 'POST', - url: 'https://trmads.eu/preBidRequest', - bids: [bid], - data: [{ - token: 'FNVzUGZn9ebpIOoheh3kEJ2GQ6H6IyMH39sHXaya', - bidId: '22499d052045', - 'banner-format-width': 300, - 'banner-format-height': 250, - placementId: 'testPlacementId', - }] - }; - const serverResponse = { - body: [{ - bidId: '22499d052045', - id: 987654, - cpm: 10, - netRevenue: 0, - currency: 'EUR', - ttl: 30, - bannerFormatWidth: 300, - bannerFormatHeight: 250, - bannerFormatAlias: 'medium_rectangle', - domains: ['www.advertiser.com'], - title: 'Advertiser' - }] - }; - const expectedResponse = [{ - requestId: bid.bidId, - cpm: 10, - width: 300, - height: 250, - creativeId: 987654, - currency: 'EUR', - netRevenue: false, // gross - ttl: 30, - ad: '
", - 'cpm': 0.1, - 'ttl': 120, - 'creativeId': '123', - 'netRevenue': true, - 'currency': 'USD', - 'dealId': 'HASH', - 'sid': 1234, - 'meta': { - 'advertiserDomains': [ - 'smartyads.com' - ], - 'dchain': { - 'ver': '1.0', - 'complete': 0, - 'nodes': [ - { - 'name': 'smartyads' - } - ] - } - }, - 'metrics': { - 'requestBids.usp': 0.20000000298023224, - 'requestBids.gdpr': 67.19999999925494, - 'requestBids.fpd': 4.299999997019768, - 'requestBids.validate': 0.29999999701976776, - 'requestBids.makeRequests': 1.800000000745058, - 'requestBids.total': 740.9000000022352, - 'requestBids.callBids': 663, - 'adapter.client.validate': 0, - 'adapters.client.smartyads.validate': 0, - 'adapter.client.buildRequests': 1, - 'adapters.client.smartyads.buildRequests': 1, - 'adapter.client.total': 661.6999999992549, - 'adapters.client.smartyads.total': 661.6999999992549, - 'adapter.client.net': 657.8999999985099, - 'adapters.client.smartyads.net': 657.8999999985099, - 'adapter.client.interpretResponse': 0, - 'adapters.client.smartyads.interpretResponse': 0, - 'addBidResponse.validate': 0.19999999925494194, - 'addBidResponse.categoryTranslation': 0, - 'addBidResponse.dchain': 0.10000000149011612, - 'addBidResponse.dsa': 0, - 'addBidResponse.multibid': 0, - 'addBidResponse.total': 1.5999999977648258, - 'render.pending': 368.80000000074506, - 'render.e2e': 1109.7000000029802 - }, - 'adapterCode': 'smartyads', - 'originalCpm': 0.1, - 'originalCurrency': 'USD', - 'responseTimestamp': 1715350155081, - 'requestTimestamp': 1715350154420, - 'bidder': 'smartyads', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'timeToRespond': 661, - 'pbLg': '0.00', - 'pbMg': '0.10', - 'pbHg': '0.10', - 'pbAg': '0.10', - 'pbDg': '0.10', - 'pbCg': '', - 'size': '300x250', - 'adserverTargeting': { - 'hb_bidder': 'smartyads', - 'hb_adid': '3c81d46b03abb', - 'hb_pb': '0.10', - 'hb_size': '300x250', - 'hb_deal': 'HASH', - 'hb_source': 'client', - 'hb_format': 'banner', - 'hb_adomain': 'smartyads.com', - 'hb_crid': '123' - }, - 'latestTargetedAuctionId': '5c0d10bf-96cb-4afa-92ac-2ef75470da22', - 'status': 'rendered', - 'params': [ - { - 'sourceid': '983', - 'host': 'prebid', - 'accountid': '18349', - 'traffic': 'banner' - } - ] - } - }; - - after(function () { - smartyadsAnalytics.disableAnalytics(); - }); - - describe('main test', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - sinon.spy(smartyadsAnalytics, 'track'); - }); - - afterEach(function () { - events.getEvents.restore(); - smartyadsAnalytics.disableAnalytics(); - smartyadsAnalytics.track.restore(); - }); - - it('test auctionEnd', function () { - adapterManager.registerAnalyticsAdapter({ - code: 'smartyads', - adapter: smartyadsAnalytics - }); - - adapterManager.enableAnalytics({ - provider: 'smartyads', - }); - - events.emit(EVENTS.AUCTION_END, auctionEnd); - expect(server.requests.length).to.equal(1); - const message = JSON.parse(server.requests[0].requestBody); - expect(message).to.have.property('auctionData'); - expect(message).to.have.property('eventType').and.to.equal(EVENTS.AUCTION_END); - expect(message.auctionData).to.have.property('auctionId'); - expect(message.auctionData.bidderRequests).to.have.length(1); - }); - - it('test bidWon', function() { - adapterManager.registerAnalyticsAdapter({ - code: 'smartyads', - adapter: smartyadsAnalytics - }); - - adapterManager.enableAnalytics({ - provider: 'smartyads', - }); - - events.emit(EVENTS.BID_WON, bidWon); - expect(server.requests.length).to.equal(1); - const message = JSON.parse(server.requests[0].requestBody); - expect(message).to.have.property('eventType').and.to.equal(EVENTS.BID_WON); - expect(message).to.have.property('bid'); - expect(message.bid).to.have.property('bidder').and.to.equal('smartyads'); - expect(message.bid).to.have.property('cpm').and.to.equal(bidWon.cpm); - }); - - it('test adRender', function() { - adapterManager.registerAnalyticsAdapter({ - code: 'smartyads', - adapter: smartyadsAnalytics - }); - - adapterManager.enableAnalytics({ - provider: 'smartyads', - }); - - events.emit(EVENTS.AD_RENDER_SUCCEEDED, renderData); - expect(server.requests.length).to.equal(1); - const message = JSON.parse(server.requests[0].requestBody); - expect(message).to.have.property('eventType').and.to.equal(EVENTS.AD_RENDER_SUCCEEDED); - expect(message).to.have.property('renderData'); - expect(message.renderData).to.have.property('doc'); - expect(message.renderData).to.have.property('doc'); - expect(message.renderData).to.have.property('bid'); - expect(message.renderData.bid).to.have.property('adId').and.to.equal(renderData.bid.adId); - }); - }); -}); diff --git a/test/spec/modules/smartyadsBidAdapter_spec.js b/test/spec/modules/smartyadsBidAdapter_spec.js deleted file mode 100644 index 2a3f1e844..000000000 --- a/test/spec/modules/smartyadsBidAdapter_spec.js +++ /dev/null @@ -1,278 +0,0 @@ -import {expect} from 'chai'; -import {spec} from '../../../modules/smartyadsBidAdapter.js'; -import { config } from '../../../src/config.js'; -import {server} from '../../mocks/xhr.js'; - -describe('SmartyadsAdapter', function () { - const bid = { - bidId: '23fhj33i987f', - bidder: 'smartyads', - params: { - host: 'prebid', - sourceid: '0', - accountid: '0', - traffic: 'banner' - } - }; - - const bidResponse = { - width: 300, - height: 250, - mediaType: 'banner', - ad: `test mode`, - requestId: '23fhj33i987f', - cpm: 0.1, - ttl: 120, - creativeId: '123', - netRevenue: true, - currency: 'USD', - dealId: 'HASH', - sid: 1234 - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and sourceid parameters present', function () { - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - delete bid.params.sourceid; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests([bid]); - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - it('Returns valid URL', function () { - expect(serverRequest.url).to.be.oneOf([ - 'https://n1.smartyads.com/?c=o&m=prebid&secret_key=prebid_js', - 'https://n2.smartyads.com/?c=o&m=prebid&secret_key=prebid_js', - 'https://n6.smartyads.com/?c=o&m=prebid&secret_key=prebid_js' - ]); - }); - it('Returns valid data if array of bids is valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys('deviceWidth', 'deviceHeight', 'host', 'page', 'placements', 'coppa', 'eeid', 'ifa'); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.coppa).to.be.a('number'); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - const placement = data['placements'][0]; - expect(placement).to.have.keys('placementId', 'bidId', 'traffic', 'sizes', 'publisherId'); - expect(placement.placementId).to.equal('0'); - expect(placement.bidId).to.equal('23fhj33i987f'); - expect(placement.traffic).to.equal('banner'); - }); - it('Returns empty data if no valid requests are passed', function () { - serverRequest = spec.buildRequests([]); - const data = serverRequest.data; - expect(data.placements).to.be.an('array').that.is.empty; - }); - }); - - describe('with COPPA', function() { - beforeEach(function() { - sinon.stub(config, 'getConfig') - .withArgs('coppa') - .returns(true); - }); - afterEach(function() { - config.getConfig.restore(); - }); - - it('should send the Coppa "required" flag set to "1" in the request', function () { - const serverRequest = spec.buildRequests([bid]); - expect(serverRequest.data.coppa).to.equal(1); - }); - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [{ - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: {advertiserDomains: ['example.com']} - }] - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.width).to.equal(300); - expect(dataItem.height).to.equal(250); - expect(dataItem.ad).to.equal('Test'); - expect(dataItem.meta).to.have.property('advertiserDomains'); - expect(dataItem.meta.advertiserDomains).to.be.an('array'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - }); - it('Should interpret video response', function () { - const video = { - body: [{ - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'vastUrl', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType', 'meta'); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - }); - it('Should interpret native response', function () { - const native = { - body: [{ - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys('requestId', 'cpm', 'ttl', 'creativeId', 'netRevenue', 'currency', 'mediaType', 'native', 'meta'); - expect(dataItem.native).to.have.keys('clickUrl', 'impressionTrackers', 'title', 'image') - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not.empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [{ - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [{ - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [{ - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }] - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [{ - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1' - }] - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - describe('getUserSyncs', function () { - const syncUrl = 'https://as.ck-ie.com/prebidjs?p=7c47322e527cf8bdeb7facc1bb03387a/iframe?pbjs=1&coppa=0'; - const syncOptions = { - iframeEnabled: true - }; - const userSync = spec.getUserSyncs(syncOptions); - it('Returns valid URL and type', function () { - expect(userSync).to.be.an('array').with.lengthOf(1); - expect(userSync[0].type).to.exist; - expect(userSync[0].url).to.exist; - expect(userSync).to.deep.equal([ - { type: 'iframe', url: syncUrl } - ]); - }); - }); -}); diff --git a/test/spec/modules/smartytechBidAdapter_spec.js b/test/spec/modules/smartytechBidAdapter_spec.js deleted file mode 100644 index fe6af7ff1..000000000 --- a/test/spec/modules/smartytechBidAdapter_spec.js +++ /dev/null @@ -1,361 +0,0 @@ -import {expect} from 'chai'; -import {spec, ENDPOINT_PROTOCOL, ENDPOINT_DOMAIN, ENDPOINT_PATH} from 'modules/smartytechBidAdapter'; -import {newBidder} from 'src/adapters/bidderFactory.js'; - -const BIDDER_CODE = 'smartytech'; - -describe('SmartyTechDSPAdapter: inherited functions', function () { - let adapter; - beforeEach(() => { - adapter = newBidder(spec); - }); - it('exists and is a function', function () { - expect(adapter.callBids).to.be.exist.and.to.be.a('function'); - }); - it(`bidder code is ${BIDDER_CODE}`, function () { - expect(spec.code).to.be.equal(BIDDER_CODE); - }) -}); - -describe('SmartyTechDSPAdapter: isBidRequestValid', function () { - it('Invalid bid request. Should return false', function () { - const bidFixture = { - params: { - use_id: 13144375 - } - } - - expect(spec.isBidRequestValid(bidFixture)).to.be.false - }); - it('Valid bid request. Should return true', function () { - const bidFixture = { - params: { - endpointId: 13144375 - } - } - expect(spec.isBidRequestValid(bidFixture)).to.be.true - }); - - it('Invalid bid request. Check video block', function () { - const bidFixture = { - params: { - endpointId: 1 - }, - mediaTypes: { - video: {} - } - } - expect(spec.isBidRequestValid(bidFixture)).to.be.false - }); - - it('Invalid bid request. Check playerSize', function () { - const bidFixture = { - params: { - endpointId: 1 - }, - mediaTypes: { - video: { - playerSize: '300x250' - } - } - } - expect(spec.isBidRequestValid(bidFixture)).to.be.false - }); - - it('Invalid bid request. Check context', function () { - const bidFixture = { - params: { - endpointId: 1 - }, - mediaTypes: { - video: { - playerSize: [300, 250] - } - } - } - expect(spec.isBidRequestValid(bidFixture)).to.be.false - }); - - it('Valid bid request. valid video bid', function () { - const bidFixture = { - params: { - endpointId: 1 - }, - mediaTypes: { - video: { - playerSize: [300, 250], - context: 'instream' - } - } - } - expect(spec.isBidRequestValid(bidFixture)).to.be.true - }); - - it('Invalid bid request. Check banner block', function () { - const bidFixture = { - params: { - endpointId: 1 - }, - mediaTypes: { - banner: {} - } - } - expect(spec.isBidRequestValid(bidFixture)).to.be.false - }); - - it('Invalid bid request. Check banner sizes', function () { - const bidFixture = { - params: { - endpointId: 1 - }, - mediaTypes: { - banner: { - sizes: '300x250' - } - } - } - expect(spec.isBidRequestValid(bidFixture)).to.be.false - }); - - it('Valid bid request. valid banner bid', function () { - const bidFixture = { - params: { - endpointId: 1 - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - } - expect(spec.isBidRequestValid(bidFixture)).to.be.true - }); -}); - -function mockRandomSizeArray(len) { - return Array.apply(null, {length: len}).map(i => { - return [Math.floor(Math.random() * 800), Math.floor(Math.random() * 800)] - }); -} - -function mockBidRequestListData(mediaType, size, customSizes) { - return Array.apply(null, {length: size}).map((i, index) => { - const id = Math.floor(Math.random() * 800) * (index + 1); - let mediaTypes; - const params = { - endpointId: id - } - - if (mediaType === 'video') { - mediaTypes = { - video: { - playerSize: mockRandomSizeArray(1), - context: 'instream' - }, - } - } else { - mediaTypes = { - banner: { - sizes: mockRandomSizeArray(index + 1) - } - } - } - - if (customSizes === undefined || customSizes.length > 0) { - params.sizes = customSizes - } - - return { - adUnitCode: `adUnitCode-${id}`, - mediaTypes: mediaTypes, - bidId: `bidId-${id}`, - params: params - } - }); -} - -function mockRefererData() { - return { - refererInfo: { - page: 'https://some-test.page' - } - } -} - -function mockResponseData(requestData) { - const data = {} - requestData.data.forEach((request, index) => { - const rndIndex = Math.floor(Math.random() * 800); - let width, height, mediaType; - if (request.video !== undefined) { - width = request.video.playerSize[0][0]; - height = request.video.playerSize[0][1]; - mediaType = 'video'; - } else { - width = request.banner.sizes[0][0]; - height = request.banner.sizes[0][1]; - mediaType = 'banner'; - } - - data[request.adUnitCode] = { - ad: `ad-${rndIndex}`, - width: width, - height: height, - creativeId: `creative-id-${index}`, - cpm: Math.floor(Math.random() * 100), - currency: `UAH-${rndIndex}`, - mediaType: mediaType, - meta: { - primaryCatId: 'IAB2-2', - secondaryCatIds: ['IAB2-14', 'IAB2-6'] - } - }; - }); - return { - body: data - } -}; - -describe('SmartyTechDSPAdapter: buildRequests', () => { - let mockBidRequest; - let mockReferer; - beforeEach(() => { - mockBidRequest = mockBidRequestListData('banner', 8, []); - mockReferer = mockRefererData(); - }); - it('has return data', () => { - const request = spec.buildRequests(mockBidRequest, mockReferer); - expect(request).not.null; - }); - it('correct request URL', () => { - const request = spec.buildRequests(mockBidRequest, mockReferer); - expect(request.url).to.be.equal(`${ENDPOINT_PROTOCOL}://${ENDPOINT_DOMAIN}${ENDPOINT_PATH}`) - }); - it('correct request method', () => { - const request = spec.buildRequests(mockBidRequest, mockReferer); - expect(request.method).to.be.equal(`POST`) - }); - it('correct request data', () => { - const data = spec.buildRequests(mockBidRequest, mockReferer).data; - data.forEach((request, index) => { - expect(request.adUnitCode).to.be.equal(mockBidRequest[index].adUnitCode); - expect(request.banner).to.be.equal(mockBidRequest[index].mediaTypes.banner); - expect(request.bidId).to.be.equal(mockBidRequest[index].bidId); - expect(request.endpointId).to.be.equal(mockBidRequest[index].params.endpointId); - expect(request.referer).to.be.equal(mockReferer.refererInfo.page); - }) - }); -}); - -describe('SmartyTechDSPAdapter: buildRequests banner custom size', () => { - let mockBidRequest; - let mockReferer; - beforeEach(() => { - mockBidRequest = mockBidRequestListData('banner', 8, [[300, 600]]); - mockReferer = mockRefererData(); - }); - - it('correct request data', () => { - const data = spec.buildRequests(mockBidRequest, mockReferer).data; - data.forEach((request, index) => { - expect(request.banner.sizes).to.be.equal(mockBidRequest[index].params.sizes); - }) - }); -}); - -describe('SmartyTechDSPAdapter: buildRequests video custom size', () => { - let mockBidRequest; - let mockReferer; - beforeEach(() => { - mockBidRequest = mockBidRequestListData('video', 8, [[300, 300], [250, 250]]); - mockReferer = mockRefererData(); - }); - - it('correct request data', () => { - const data = spec.buildRequests(mockBidRequest, mockReferer).data; - data.forEach((request, index) => { - expect(request.video.sizes).to.be.equal(mockBidRequest[index].params.sizes); - }) - }); -}); - -describe('SmartyTechDSPAdapter: interpretResponse', () => { - let mockBidRequest; - let mockReferer; - let request; - let mockResponse; - beforeEach(() => { - const brData = mockBidRequestListData('banner', 2, []); - mockReferer = mockRefererData(); - request = spec.buildRequests(brData, mockReferer); - mockBidRequest = { - data: brData - } - mockResponse = mockResponseData(request); - }); - - it('interpretResponse: empty data request', () => { - delete mockResponse['body'] - const data = spec.interpretResponse(mockResponse, mockBidRequest); - expect(data.length).to.be.equal(0); - }); - - it('interpretResponse: response data and convert data arrays has same length', () => { - const keys = Object.keys(mockResponse.body); - const data = spec.interpretResponse(mockResponse, mockBidRequest); - expect(data.length).to.be.equal(keys.length); - }); - - it('interpretResponse: convert to correct data', () => { - const keys = Object.keys(mockResponse.body); - const data = spec.interpretResponse(mockResponse, mockBidRequest); - - data.forEach((responseItem, index) => { - expect(responseItem.ad).to.be.equal(mockResponse.body[keys[index]].ad); - expect(responseItem.cpm).to.be.equal(mockResponse.body[keys[index]].cpm); - expect(responseItem.creativeId).to.be.equal(mockResponse.body[keys[index]].creativeId); - expect(responseItem.currency).to.be.equal(mockResponse.body[keys[index]].currency); - expect(responseItem.netRevenue).to.be.true; - expect(responseItem.ttl).to.be.equal(60); - expect(responseItem.requestId).to.be.equal(mockBidRequest.data[index].bidId); - expect(responseItem.width).to.be.equal(mockResponse.body[keys[index]].width); - expect(responseItem.height).to.be.equal(mockResponse.body[keys[index]].height); - expect(responseItem.mediaType).to.be.equal(mockResponse.body[keys[index]].mediaType); - }); - }); -}); - -describe('SmartyTechDSPAdapter: interpretResponse video', () => { - let mockBidRequest; - let mockReferer; - let request; - let mockResponse; - beforeEach(() => { - const brData = mockBidRequestListData('video', 2, []); - mockReferer = mockRefererData(); - request = spec.buildRequests(brData, mockReferer); - mockBidRequest = { - data: brData - } - mockResponse = mockResponseData(request); - }); - - it('interpretResponse: convert to correct data', () => { - const keys = Object.keys(mockResponse.body); - const data = spec.interpretResponse(mockResponse, mockBidRequest); - - data.forEach((responseItem, index) => { - expect(responseItem.ad).to.be.equal(mockResponse.body[keys[index]].ad); - expect(responseItem.cpm).to.be.equal(mockResponse.body[keys[index]].cpm); - expect(responseItem.creativeId).to.be.equal(mockResponse.body[keys[index]].creativeId); - expect(responseItem.currency).to.be.equal(mockResponse.body[keys[index]].currency); - expect(responseItem.netRevenue).to.be.true; - expect(responseItem.ttl).to.be.equal(60); - expect(responseItem.requestId).to.be.equal(mockBidRequest.data[index].bidId); - expect(responseItem.width).to.be.equal(mockResponse.body[keys[index]].width); - expect(responseItem.height).to.be.equal(mockResponse.body[keys[index]].height); - expect(responseItem.mediaType).to.be.equal(mockResponse.body[keys[index]].mediaType); - expect(responseItem.vastXml).to.be.equal(mockResponse.body[keys[index]].ad); - }); - }); -}); diff --git a/test/spec/modules/smilewantedBidAdapter_spec.js b/test/spec/modules/smilewantedBidAdapter_spec.js deleted file mode 100644 index e1d740ea1..000000000 --- a/test/spec/modules/smilewantedBidAdapter_spec.js +++ /dev/null @@ -1,662 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/smilewantedBidAdapter.js'; -import { config } from 'src/config.js'; - -const DISPLAY_REQUEST = [{ - adUnitCode: 'sw_300x250', - bidId: '12345', - sizes: [ - [300, 250], - [300, 200] - ], - bidder: 'smilewanted', - params: { - zoneId: 1 - }, - requestId: 'request_abcd1234', - ortb2Imp: { - ext: { - tid: 'trans_abcd1234', - } - }, -}]; - -const DISPLAY_REQUEST_WITH_EIDS = [{ - adUnitCode: 'sw_300x250', - bidId: '12345', - sizes: [ - [300, 250], - [300, 200] - ], - bidder: 'smilewanted', - params: { - zoneId: 1 - }, - requestId: 'request_abcd1234', - ortb2Imp: { - ext: { - tid: 'trans_abcd1234', - } - }, - userIdAsEids: [{ - source: 'pubcid.org', - uids: [{ - id: 'some-random-id-value', - atype: 1 - }] - }, { - source: 'adserver.org', - uids: [{ - id: 'some-random-id-value', - atype: 1, - ext: { - rtiPartner: 'TDID' - } - }] - }] -}]; - -const DISPLAY_REQUEST_WITH_POSITION_TYPE = [{ - adUnitCode: 'sw_300x250', - bidId: '12345', - sizes: [ - [300, 250], - [300, 200] - ], - bidder: 'smilewanted', - params: { - zoneId: 1, - positionType: 'infeed' - }, - requestId: 'request_abcd1234', - ortb2Imp: { - ext: { - tid: 'trans_abcd1234', - } - }, -}]; - -const SCHAIN = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'exchange1.com', - 'sid': '1234', - 'hp': 1, - 'rid': 'bid-request-1', - 'name': 'publisher', - 'domain': 'publisher.com' - }, - { - 'asi': 'exchange2.com', - 'sid': 'abcd', - 'hp': 1, - 'rid': 'bid-request-2', - 'name': 'intermediary', - 'domain': 'intermediary.com' - } - ] -}; - -const DISPLAY_REQUEST_WITH_SCHAIN = [{ - adUnitCode: 'sw_300x250', - bidId: '12345', - sizes: [ - [300, 250], - [300, 200] - ], - bidder: 'smilewanted', - params: { - zoneId: 1, - }, - requestId: 'request_abcd1234', - ortb2Imp: { - ext: { - tid: 'trans_abcd1234', - } - }, - ortb2: { - source: { - ext: { - schain: SCHAIN - } - } - }, -}]; - -const BID_RESPONSE_DISPLAY = { - body: { - cpm: 3, - width: 300, - height: 250, - creativeId: 'crea_sw_1', - currency: 'EUR', - isNetCpm: true, - ttl: 300, - ad: '< --- sw script --- >', - cSyncUrl: 'https://csync.smilewanted.com' - } -}; - -const VIDEO_INSTREAM_REQUEST = [{ - code: 'video1', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mp4'], - minduration: 0, - maxduration: 120, - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - startdelay: 0, - placement: 1, - skip: 1, - skipafter: 10, - minbitrate: 10, - maxbitrate: 10, - delivery: [1], - playbackmethod: [2], - api: [1, 2], - linearity: 1, - playerSize: [640, 480] - } - }, - sizes: [ - [640, 480] - ], - bidder: 'smilewanted', - params: { - zoneId: 2, - bidfloor: 2.50 - }, - requestId: 'request_abcd1234', - ortb2Imp: { - ext: { - tid: 'trans_abcd1234', - } - } -}]; - -const BID_RESPONSE_VIDEO_INSTREAM = { - body: { - cpm: 3, - width: 640, - height: 480, - creativeId: 'crea_sw_2', - currency: 'EUR', - isNetCpm: true, - ttl: 300, - ad: 'https://vast.smilewanted.com', - cSyncUrl: 'https://csync.smilewanted.com', - formatTypeSw: 'video_instream' - } -}; - -const VIDEO_OUTSTREAM_REQUEST = [{ - code: 'video1', - mediaTypes: { - video: {} - }, - sizes: [ - [640, 480] - ], - bidder: 'smilewanted', - params: { - zoneId: 3, - bidfloor: 2.50 - }, - requestId: 'request_abcd1234', - ortb2Imp: { - ext: { - tid: 'trans_abcd1234', - } - } -}]; - -const BID_RESPONSE_VIDEO_OUTSTREAM = { - body: { - cpm: 3, - width: 640, - height: 480, - creativeId: 'crea_sw_3', - currency: 'EUR', - isNetCpm: true, - ttl: 300, - ad: 'https://vast.smilewanted.com', - cSyncUrl: 'https://csync.smilewanted.com', - OustreamTemplateUrl: 'https://prebid.smilewanted.com/scripts_outstream/infeed.js', - formatTypeSw: 'video_outstream' - } -}; - -const NATIVE_REQUEST = [{ - adUnitCode: 'native_300x250', - code: '/19968336/prebid_native_example_1', - bidId: '12345', - sizes: [ - [300, 250] - ], - mediaTypes: { - native: { - title: { - required: true, - len: 140 - }, - image: { - required: true, - sizes: [300, 250] - }, - icon: { - required: false, - sizes: [50, 50] - }, - sponsoredBy: { - required: true - }, - body: { - required: true - }, - clickUrl: { - required: false - }, - privacyLink: { - required: false - }, - cta: { - required: false - }, - rating: { - required: false - }, - likes: { - required: false - }, - downloads: { - required: false - }, - price: { - required: false - }, - salePrice: { - required: false - }, - phone: { - required: false - }, - address: { - required: false - }, - desc2: { - required: false - }, - displayUrl: { - required: false - } - } - }, - bidder: 'smilewanted', - params: { - zoneId: 4, - }, - requestId: 'request_abcd1234', - ortb2Imp: { - ext: { - tid: 'trans_abcd1234', - } - }, -}]; - -const BID_RESPONSE_NATIVE = { - body: { - cpm: 3, - width: 300, - height: 250, - creativeId: 'crea_sw_1', - currency: 'EUR', - isNetCpm: true, - ttl: 300, - ad: '{"link":{"url":"https://www.smilewanted.com"},"assets":[{"id":0,"required":1,"title":{"len":50}},{"id":1,"required":1,"img":{"type":3,"w":150,"h":50,"ext":{"aspectratios":["2:1"]}}},{"id":2,"required":0,"img":{"type":1,"w":50,"h":50,"ext":{"aspectratios":["2:1"]}}},{"id":3,"required":1,"data":{"type":1,"value":"Smilewanted sponsor"}},{"id":4,"required":1,"data":{"type":2,"value":"Smilewanted Description"}}]}', - cSyncUrl: 'https://csync.smilewanted.com', - formatTypeSw: 'native' - } -}; - -// Default params with optional ones -describe('smilewantedBidAdapterTests', function () { - it('SmileWanted - Verify build request', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - } - }); - - const requestDisplay = spec.buildRequests(DISPLAY_REQUEST); - expect(requestDisplay[0]).to.have.property('url').and.to.equal('https://prebid.smilewanted.com'); - expect(requestDisplay[0]).to.have.property('method').and.to.equal('POST'); - const requestDisplayContent = JSON.parse(requestDisplay[0].data); - expect(requestDisplayContent).to.have.property('zoneId').and.to.equal(1); - expect(requestDisplayContent).to.have.property('currencyCode').and.to.equal('EUR'); - expect(requestDisplayContent).to.have.property('sizes'); - expect(requestDisplayContent.sizes[0]).to.have.property('w').and.to.equal(300); - expect(requestDisplayContent.sizes[0]).to.have.property('h').and.to.equal(250); - expect(requestDisplayContent.sizes[1]).to.have.property('w').and.to.equal(300); - expect(requestDisplayContent.sizes[1]).to.have.property('h').and.to.equal(200); - expect(requestDisplayContent).to.have.property('transactionId').and.to.not.equal(null).and.to.not.be.undefined; - - const requestVideoInstream = spec.buildRequests(VIDEO_INSTREAM_REQUEST); - expect(requestVideoInstream[0]).to.have.property('url').and.to.equal('https://prebid.smilewanted.com'); - expect(requestVideoInstream[0]).to.have.property('method').and.to.equal('POST'); - const requestVideoInstreamContent = JSON.parse(requestVideoInstream[0].data); - expect(requestVideoInstreamContent).to.have.property('zoneId').and.to.equal(2); - expect(requestVideoInstreamContent).to.have.property('currencyCode').and.to.equal('EUR'); - expect(requestVideoInstreamContent).to.have.property('sizes'); - expect(requestVideoInstreamContent.sizes[0]).to.have.property('w').and.to.equal(640); - expect(requestVideoInstreamContent.sizes[0]).to.have.property('h').and.to.equal(480); - expect(requestVideoInstreamContent).to.have.property('transactionId').and.to.not.equal(null).and.to.not.be.undefined; - expect(requestVideoInstreamContent).to.have.property('videoParams'); - expect(requestVideoInstreamContent.videoParams).to.have.property('context').and.to.equal('instream').and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('mimes').to.be.an('array').that.include('video/mp4').and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('minduration').and.to.equal(0).and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('maxduration').and.to.equal(120).and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('protocols').to.be.an('array').that.include.members([1, 2, 3, 4, 5, 6, 7, 8]).and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('startdelay').and.to.equal(0).and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('placement').and.to.equal(1).and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('skip').and.to.equal(1).and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('skipafter').and.to.equal(10).and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('minbitrate').and.to.equal(10).and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('maxbitrate').and.to.equal(10).and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('delivery').to.be.an('array').that.include(1).and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('playbackmethod').to.be.an('array').that.include(2).and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('api').to.be.an('array').that.include.members([1, 2]).and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('linearity').and.to.equal(1).and.to.not.be.undefined; - expect(requestVideoInstreamContent.videoParams).to.have.property('playerSize').to.be.an('array').that.include.members([640, 480]).and.to.not.be.undefined; - - const requestVideoOutstream = spec.buildRequests(VIDEO_OUTSTREAM_REQUEST); - expect(requestVideoOutstream[0]).to.have.property('url').and.to.equal('https://prebid.smilewanted.com'); - expect(requestVideoOutstream[0]).to.have.property('method').and.to.equal('POST'); - const requestVideoOutstreamContent = JSON.parse(requestVideoOutstream[0].data); - expect(requestVideoOutstreamContent).to.have.property('zoneId').and.to.equal(3); - expect(requestVideoOutstreamContent).to.have.property('currencyCode').and.to.equal('EUR'); - expect(requestVideoOutstreamContent).to.have.property('sizes'); - expect(requestVideoOutstreamContent.sizes[0]).to.have.property('w').and.to.equal(640); - expect(requestVideoOutstreamContent.sizes[0]).to.have.property('h').and.to.equal(480); - expect(requestVideoOutstreamContent).to.have.property('transactionId').and.to.not.equal(null).and.to.not.be.undefined; - - const requestNative = spec.buildRequests(NATIVE_REQUEST); - expect(requestNative[0]).to.have.property('url').and.to.equal('https://prebid.smilewanted.com'); - expect(requestNative[0]).to.have.property('method').and.to.equal('POST'); - const requestNativeContent = JSON.parse(requestNative[0].data); - expect(requestNativeContent).to.have.property('zoneId').and.to.equal(4); - expect(requestNativeContent).to.have.property('currencyCode').and.to.equal('EUR'); - expect(requestNativeContent).to.have.property('sizes'); - expect(requestNativeContent.sizes[0]).to.have.property('w').and.to.equal(300); - expect(requestNativeContent.sizes[0]).to.have.property('h').and.to.equal(250); - expect(requestNativeContent).to.have.property('transactionId').and.to.not.equal(null).and.to.not.be.undefined; - expect(requestNativeContent).to.have.property('context').and.to.equal('native').and.to.not.be.undefined; - expect(requestNativeContent).to.have.property('nativeParams'); - expect(requestNativeContent.nativeParams.title).to.have.property('required').and.to.equal(true); - expect(requestNativeContent.nativeParams.title).to.have.property('len').and.to.equal(140); - expect(requestNativeContent.nativeParams.image).to.have.property('required').and.to.equal(true); - expect(requestNativeContent.nativeParams.image).to.have.property('sizes').to.be.an('array').that.include.members([300, 250]).and.to.not.be.undefined; - expect(requestNativeContent.nativeParams.icon).to.have.property('required').and.to.equal(false); - expect(requestNativeContent.nativeParams.icon).to.have.property('sizes').to.be.an('array').that.include.members([50, 50]).and.to.not.be.undefined; - expect(requestNativeContent.nativeParams.sponsoredBy).to.have.property('required').and.to.equal(true); - expect(requestNativeContent.nativeParams.body).to.have.property('required').and.to.equal(true); - expect(requestNativeContent.nativeParams.clickUrl).to.have.property('required').and.to.equal(false); - expect(requestNativeContent.nativeParams.privacyLink).to.have.property('required').and.to.equal(false); - expect(requestNativeContent.nativeParams.cta).to.have.property('required').and.to.equal(false); - expect(requestNativeContent.nativeParams.rating).to.have.property('required').and.to.equal(false); - expect(requestNativeContent.nativeParams.likes).to.have.property('required').and.to.equal(false); - expect(requestNativeContent.nativeParams.downloads).to.have.property('required').and.to.equal(false); - expect(requestNativeContent.nativeParams.price).to.have.property('required').and.to.equal(false); - expect(requestNativeContent.nativeParams.salePrice).to.have.property('required').and.to.equal(false); - expect(requestNativeContent.nativeParams.phone).to.have.property('required').and.to.equal(false); - expect(requestNativeContent.nativeParams.address).to.have.property('required').and.to.equal(false); - expect(requestNativeContent.nativeParams.desc2).to.have.property('required').and.to.equal(false); - expect(requestNativeContent.nativeParams.displayUrl).to.have.property('required').and.to.equal(false); - }); - - it('SmileWanted - Verify build request with referrer', function () { - const request = spec.buildRequests(DISPLAY_REQUEST, { - refererInfo: { - page: 'https://localhost/Prebid.js/integrationExamples/gpt/hello_world.html' - } - }); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('pageDomain').and.to.equal('https://localhost/Prebid.js/integrationExamples/gpt/hello_world.html'); - }); - - it('Verify external ids in request and ids found', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - } - }); - const request = spec.buildRequests(DISPLAY_REQUEST_WITH_EIDS, {}); - const requestContent = JSON.parse(request[0].data); - - expect(requestContent).to.have.property('eids'); - expect(requestContent.eids).to.not.equal(null).and.to.not.be.undefined; - expect(requestContent.eids.length).to.greaterThan(0); - for (const index in requestContent.eids) { - const eid = requestContent.eids[index]; - expect(eid.source).to.not.equal(null).and.to.not.be.undefined; - expect(eid.uids).to.not.equal(null).and.to.not.be.undefined; - for (const uidsIndex in eid.uids) { - const uid = eid.uids[uidsIndex]; - expect(uid.id).to.not.equal(null).and.to.not.be.undefined; - } - } - }); - - describe('gdpr tests', function () { - afterEach(function () { - config.resetConfig(); - }); - - it('SmileWanted - Verify build request with GDPR', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - }, - consentManagement: { - cmp: 'iab', - consentRequired: true, - timeout: 1000, - allowAuctionWithoutConsent: true - } - }); - const request = spec.buildRequests(DISPLAY_REQUEST, { - gdprConsent: { - consentString: 'BOO_ch7OO_ch7AKABBENA2-AAAAZ97_______9______9uz_Gv_r_f__33e8_39v_h_7_u___m_-zzV4-_lvQV1yPA1OrfArgFA', - gdprApplies: true - } - }); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('gdpr').and.to.equal(true); - expect(requestContent).to.have.property('gdpr_consent').and.to.equal('BOO_ch7OO_ch7AKABBENA2-AAAAZ97_______9______9uz_Gv_r_f__33e8_39v_h_7_u___m_-zzV4-_lvQV1yPA1OrfArgFA'); - }); - - it('SmileWanted - Verify build request with GDPR without gdprApplies', function () { - config.setConfig({ - 'currency': { - 'adServerCurrency': 'EUR' - }, - consentManagement: { - cmp: 'iab', - consentRequired: true, - timeout: 1000, - allowAuctionWithoutConsent: true - } - }); - const request = spec.buildRequests(DISPLAY_REQUEST, { - gdprConsent: { - consentString: 'BOO_ch7OO_ch7AKABBENA2-AAAAZ97_______9______9uz_Gv_r_f__33e8_39v_h_7_u___m_-zzV4-_lvQV1yPA1OrfArgFA' - } - }); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.not.have.property('gdpr'); - expect(requestContent).to.have.property('gdpr_consent').and.to.equal('BOO_ch7OO_ch7AKABBENA2-AAAAZ97_______9______9uz_Gv_r_f__33e8_39v_h_7_u___m_-zzV4-_lvQV1yPA1OrfArgFA'); - }); - }); - - it('SmileWanted - Verify parse response - Display', function () { - const request = spec.buildRequests(DISPLAY_REQUEST); - const bids = spec.interpretResponse(BID_RESPONSE_DISPLAY, request[0]); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(3); - expect(bid.ad).to.equal('< --- sw script --- >'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creativeId).to.equal('crea_sw_1'); - expect(bid.currency).to.equal('EUR'); - expect(bid.netRevenue).to.equal(true); - expect(bid.ttl).to.equal(300); - expect(bid.requestId).to.equal(DISPLAY_REQUEST[0].bidId); - - expect(function () { - spec.interpretResponse(BID_RESPONSE_DISPLAY, { - data: 'invalid Json' - }) - }).to.not.throw(); - }); - - it('SmileWanted - Verify parse response - Video Instream', function () { - const request = spec.buildRequests(VIDEO_INSTREAM_REQUEST); - const bids = spec.interpretResponse(BID_RESPONSE_VIDEO_INSTREAM, request[0]); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(3); - expect(bid.ad).to.equal(null); - expect(bid.vastUrl).to.equal('https://vast.smilewanted.com'); - expect(bid.width).to.equal(640); - expect(bid.height).to.equal(480); - expect(bid.creativeId).to.equal('crea_sw_2'); - expect(bid.currency).to.equal('EUR'); - expect(bid.netRevenue).to.equal(true); - expect(bid.ttl).to.equal(300); - expect(bid.requestId).to.equal(VIDEO_INSTREAM_REQUEST[0].bidId); - - expect(function () { - spec.interpretResponse(BID_RESPONSE_VIDEO_INSTREAM, { - data: 'invalid Json' - }) - }).to.not.throw(); - }); - - it('SmileWanted - Verify parse response - Video Outstream', function () { - const request = spec.buildRequests(VIDEO_OUTSTREAM_REQUEST); - const bids = spec.interpretResponse(BID_RESPONSE_VIDEO_OUTSTREAM, request[0]); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(3); - expect(bid.vastUrl).to.equal('https://vast.smilewanted.com'); - expect(bid.renderer.url).to.equal('https://prebid.smilewanted.com/scripts_outstream/infeed.js'); - expect(bid.width).to.equal(640); - expect(bid.height).to.equal(480); - expect(bid.creativeId).to.equal('crea_sw_3'); - expect(bid.currency).to.equal('EUR'); - expect(bid.netRevenue).to.equal(true); - expect(bid.ttl).to.equal(300); - expect(bid.requestId).to.equal(VIDEO_OUTSTREAM_REQUEST[0].bidId); - - expect(function () { - spec.interpretResponse(BID_RESPONSE_VIDEO_OUTSTREAM, { - data: 'invalid Json' - }) - }).to.not.throw(); - }); - - it('SmileWanted - Verify parse response - Native', function () { - const request = spec.buildRequests(NATIVE_REQUEST); - const bids = spec.interpretResponse(BID_RESPONSE_NATIVE, request[0]); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.cpm).to.equal(3); - expect(bid.ad).to.equal('{"link":{"url":"https://www.smilewanted.com"},"assets":[{"id":0,"required":1,"title":{"len":50}},{"id":1,"required":1,"img":{"type":3,"w":150,"h":50,"ext":{"aspectratios":["2:1"]}}},{"id":2,"required":0,"img":{"type":1,"w":50,"h":50,"ext":{"aspectratios":["2:1"]}}},{"id":3,"required":1,"data":{"type":1,"value":"Smilewanted sponsor"}},{"id":4,"required":1,"data":{"type":2,"value":"Smilewanted Description"}}]}'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.creativeId).to.equal('crea_sw_1'); - expect(bid.currency).to.equal('EUR'); - expect(bid.netRevenue).to.equal(true); - expect(bid.ttl).to.equal(300); - expect(bid.requestId).to.equal(NATIVE_REQUEST[0].bidId); - - expect(function () { - spec.interpretResponse(BID_RESPONSE_NATIVE, { - data: 'invalid Json' - }) - }).to.not.throw(); - }); - - it('SmileWanted - Verify bidder code', function () { - expect(spec.code).to.equal('smilewanted'); - }); - - it('SmileWanted - Verify bidder aliases', function () { - expect(spec.aliases).to.have.lengthOf(2); - expect(spec.aliases[0]).to.equal('smile'); - expect(spec.aliases[1]).to.equal('sw'); - }); - - it('SmileWanted - Verify if bid request valid', function () { - expect(spec.isBidRequestValid(DISPLAY_REQUEST[0])).to.equal(true); - expect(spec.isBidRequestValid({ - params: { - zoneId: 1234 - } - })).to.equal(true); - }); - - it('SmileWanted - Verify if params(zoneId) is not passed', function () { - expect(spec.isBidRequestValid({})).to.equal(false); - expect(spec.isBidRequestValid({ - params: {} - })).to.equal(false); - }); - - it('SmileWanted - Verify if payload(positionType) is default value when nothing is passed on the param', function () { - const request = spec.buildRequests(DISPLAY_REQUEST, {}); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('positionType').and.to.equal(''); - }); - - it('SmileWanted - Verify if payload(positionType) is well passed', function () { - const request = spec.buildRequests(DISPLAY_REQUEST_WITH_POSITION_TYPE, {}); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('positionType').and.to.equal('infeed'); - }); - - it('SmileWanted - Verify if schain is well passed', function () { - const request = spec.buildRequests(DISPLAY_REQUEST_WITH_SCHAIN, {}); - const requestContent = JSON.parse(request[0].data); - expect(requestContent).to.have.property('schain').and.to.equal('1.0,1!exchange1.com,1234,1,bid-request-1,publisher,publisher.com,!exchange2.com,abcd,1,bid-request-2,intermediary,intermediary.com,'); - }); - - it('SmileWanted - Verify user sync - empty data', function () { - const syncs = spec.getUserSyncs({iframeEnabled: true}, {}, {}, null); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.equal('https://csync.smilewanted.com'); - }); - - it('SmileWanted - Verify user sync', function () { - let syncs = spec.getUserSyncs({iframeEnabled: true}, {}, { - consentString: 'foo' - }, '1NYN'); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.equal('https://csync.smilewanted.com?gdpr_consent=foo&us_privacy=1NYN'); - - syncs = spec.getUserSyncs({ - iframeEnabled: false - }, [BID_RESPONSE_DISPLAY]); - expect(syncs).to.have.lengthOf(0); - - syncs = spec.getUserSyncs({ - iframeEnabled: true - }, []); - expect(syncs).to.have.lengthOf(1); - }); -}); diff --git a/test/spec/modules/smootBidAdapter_spec.js b/test/spec/modules/smootBidAdapter_spec.js deleted file mode 100644 index d9c5580e6..000000000 --- a/test/spec/modules/smootBidAdapter_spec.js +++ /dev/null @@ -1,597 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/smootBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from '../../../src/mediaTypes.js'; -import { getUniqueIdentifierStr } from '../../../src/utils.js'; - -const bidder = 'smoot'; - -describe('SmootBidAdapter', function () { - const userIdAsEids = [ - { - source: 'test.org', - uids: [ - { - id: '01**********', - atype: 1, - ext: { - third: '01***********', - }, - }, - ], - }, - ]; - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]], - }, - }, - params: { - placementId: 'testBanner', - }, - userIdAsEids, - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [VIDEO]: { - playerSize: [[300, 300]], - minduration: 5, - maxduration: 60, - }, - }, - params: { - placementId: 'testVideo', - }, - userIdAsEids, - }, - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [NATIVE]: { - native: { - title: { - required: true, - }, - body: { - required: true, - }, - icon: { - required: true, - size: [64, 64], - }, - }, - }, - }, - params: { - placementId: 'testNative', - }, - userIdAsEids, - }, - ]; - - const invalidBid = { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]], - }, - }, - params: {}, - }; - - const bidderRequest = { - uspConsent: '1---', - gdprConsent: { - consentString: - 'COvFyGBOvFyGBAbAAAENAPCAAOAAAAAAAAAAAEEUACCKAAA.IFoEUQQgAIQwgIwQABAEAAAAOIAACAIAAAAQAIAgEAACEAAAAAgAQBAAAAAAAGBAAgAAAAAAAFAAECAAAgAAQARAEQAAAAAJAAIAAgAAAYQEAAAQmAgBC3ZAYzUw', - vendorData: {}, - }, - refererInfo: { - referer: 'https://test.com', - }, - timeout: 500, - }; - - describe('isBidRequestValid', function () { - it('Should return true if there are bidId, params and key parameters present', function () { - expect(spec.isBidRequestValid(bids[0])).to.be.true; - }); - it('Should return false if at least one of parameters is not present', function () { - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let serverRequest = spec.buildRequests(bids, bidderRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist; - expect(serverRequest.method).to.exist; - expect(serverRequest.url).to.exist; - expect(serverRequest.data).to.exist; - }); - - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST'); - }); - - it('Returns general data valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys( - 'deviceWidth', - 'deviceHeight', - 'language', - 'secure', - 'host', - 'page', - 'placements', - 'coppa', - 'ccpa', - 'gdpr', - 'tmax', - 'bcat', - 'badv', - 'bapp', - 'battr' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.language).to.be.a('string'); - expect(data.secure).to.be.within(0, 1); - expect(data.host).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.coppa).to.be.a('number'); - expect(data.gdpr).to.be.a('object'); - expect(data.ccpa).to.be.a('string'); - expect(data.tmax).to.be.a('number'); - expect(data.placements).to.have.lengthOf(3); - }); - - it('Returns valid placements', function () { - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.placementId).to.be.oneOf([ - 'testBanner', - 'testVideo', - 'testNative', - ]); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('publisher'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns valid endpoints', function () { - const bids = [ - { - bidId: getUniqueIdentifierStr(), - bidder: bidder, - mediaTypes: { - [BANNER]: { - sizes: [[300, 250]], - }, - }, - params: { - endpointId: 'testBanner', - }, - userIdAsEids, - }, - ]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - - const { placements } = serverRequest.data; - for (let i = 0, len = placements.length; i < len; i++) { - const placement = placements[i]; - expect(placement.endpointId).to.be.oneOf([ - 'testBanner', - 'testVideo', - 'testNative', - ]); - expect(placement.adFormat).to.be.oneOf([BANNER, VIDEO, NATIVE]); - expect(placement.bidId).to.be.a('string'); - expect(placement.schain).to.be.an('object'); - expect(placement.bidfloor).to.exist.and.to.equal(0); - expect(placement.type).to.exist.and.to.equal('network'); - expect(placement.eids).to.exist.and.to.be.deep.equal(userIdAsEids); - - if (placement.adFormat === BANNER) { - expect(placement.sizes).to.be.an('array'); - } - switch (placement.adFormat) { - case BANNER: - expect(placement.sizes).to.be.an('array'); - break; - case VIDEO: - expect(placement.playerSize).to.be.an('array'); - expect(placement.minduration).to.be.an('number'); - expect(placement.maxduration).to.be.an('number'); - break; - case NATIVE: - expect(placement.native).to.be.an('object'); - break; - } - } - }); - - it('Returns data with gdprConsent and without uspConsent', function () { - delete bidderRequest.uspConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.gdpr).to.exist; - expect(data.gdpr).to.be.a('object'); - expect(data.gdpr).to.have.property('consentString'); - expect(data.gdpr).to.not.have.property('vendorData'); - expect(data.gdpr.consentString).to.equal( - bidderRequest.gdprConsent.consentString - ); - expect(data.ccpa).to.not.exist; - delete bidderRequest.gdprConsent; - }); - - it('Returns data with uspConsent and without gdprConsent', function () { - bidderRequest.uspConsent = '1---'; - delete bidderRequest.gdprConsent; - serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data.ccpa).to.exist; - expect(data.ccpa).to.be.a('string'); - expect(data.ccpa).to.equal(bidderRequest.uspConsent); - expect(data.gdpr).to.not.exist; - }); - }); - - describe('gpp consent', function () { - it('bidderRequest.gppConsent', () => { - bidderRequest.gppConsent = { - gppString: 'abc123', - applicableSections: [8], - }; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - - delete bidderRequest.gppConsent; - }); - - it('bidderRequest.ortb2.regs.gpp', () => { - bidderRequest.ortb2 = bidderRequest.ortb2 || {}; - bidderRequest.ortb2.regs = bidderRequest.ortb2.regs || {}; - bidderRequest.ortb2.regs.gpp = 'abc123'; - bidderRequest.ortb2.regs.gpp_sid = [8]; - - const serverRequest = spec.buildRequests(bids, bidderRequest); - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.property('gpp'); - expect(data).to.have.property('gpp_sid'); - }); - }); - - describe('interpretResponse', function () { - it('Should interpret banner response', function () { - const banner = { - body: [ - { - mediaType: 'banner', - width: 300, - height: 250, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234, - }, - }, - ], - }; - const bannerResponses = spec.interpretResponse(banner); - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys( - 'requestId', - 'cpm', - 'width', - 'height', - 'ad', - 'ttl', - 'creativeId', - 'netRevenue', - 'currency', - 'dealId', - 'mediaType', - 'meta' - ); - expect(dataItem.requestId).to.equal(banner.body[0].requestId); - expect(dataItem.cpm).to.equal(banner.body[0].cpm); - expect(dataItem.width).to.equal(banner.body[0].width); - expect(dataItem.height).to.equal(banner.body[0].height); - expect(dataItem.ad).to.equal(banner.body[0].ad); - expect(dataItem.ttl).to.equal(banner.body[0].ttl); - expect(dataItem.creativeId).to.equal(banner.body[0].creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(banner.body[0].currency); - expect(dataItem.meta) - .to.be.an('object') - .that.has.any.key('advertiserDomains'); - }); - it('Should interpret video response', function () { - const video = { - body: [ - { - vastUrl: 'test.com', - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234, - }, - }, - ], - }; - const videoResponses = spec.interpretResponse(video); - expect(videoResponses).to.be.an('array').that.is.not.empty; - - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys( - 'requestId', - 'cpm', - 'vastUrl', - 'ttl', - 'creativeId', - 'netRevenue', - 'currency', - 'dealId', - 'mediaType', - 'meta' - ); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.5); - expect(dataItem.vastUrl).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta) - .to.be.an('object') - .that.has.any.key('advertiserDomains'); - }); - it('Should interpret native response', function () { - const native = { - body: [ - { - mediaType: 'native', - native: { - clickUrl: 'test.com', - title: 'Test', - image: 'test.com', - impressionTrackers: ['test.com'], - }, - ttl: 120, - cpm: 0.4, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['google.com'], - advertiserId: 1234, - }, - }, - ], - }; - const nativeResponses = spec.interpretResponse(native); - expect(nativeResponses).to.be.an('array').that.is.not.empty; - - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.keys( - 'requestId', - 'cpm', - 'ttl', - 'creativeId', - 'netRevenue', - 'currency', - 'mediaType', - 'native', - 'meta' - ); - expect(dataItem.native).to.have.keys( - 'clickUrl', - 'impressionTrackers', - 'title', - 'image' - ); - expect(dataItem.requestId).to.equal('23fhj33i987f'); - expect(dataItem.cpm).to.equal(0.4); - expect(dataItem.native.clickUrl).to.equal('test.com'); - expect(dataItem.native.title).to.equal('Test'); - expect(dataItem.native.image).to.equal('test.com'); - expect(dataItem.native.impressionTrackers).to.be.an('array').that.is.not - .empty; - expect(dataItem.native.impressionTrackers[0]).to.equal('test.com'); - expect(dataItem.ttl).to.equal(120); - expect(dataItem.creativeId).to.equal('2'); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal('USD'); - expect(dataItem.meta) - .to.be.an('object') - .that.has.any.key('advertiserDomains'); - }); - it('Should return an empty array if invalid banner response is passed', function () { - const invBanner = { - body: [ - { - width: 300, - cpm: 0.4, - ad: 'Test', - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - }, - ], - }; - - const serverResponses = spec.interpretResponse(invBanner); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid video response is passed', function () { - const invVideo = { - body: [ - { - mediaType: 'video', - cpm: 0.5, - requestId: '23fhj33i987f', - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - }, - ], - }; - const serverResponses = spec.interpretResponse(invVideo); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid native response is passed', function () { - const invNative = { - body: [ - { - mediaType: 'native', - clickUrl: 'test.com', - title: 'Test', - impressionTrackers: ['test.com'], - ttl: 120, - requestId: '23fhj33i987f', - creativeId: '2', - netRevenue: true, - currency: 'USD', - }, - ], - }; - const serverResponses = spec.interpretResponse(invNative); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - it('Should return an empty array if invalid response is passed', function () { - const invalid = { - body: [ - { - ttl: 120, - creativeId: '2', - netRevenue: true, - currency: 'USD', - dealId: '1', - }, - ], - }; - const serverResponses = spec.interpretResponse(invalid); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - - describe('getUserSyncs', function () { - it('Should return array of objects with proper sync config , include GDPR', function () { - const syncData = spec.getUserSyncs( - {}, - {}, - { - consentString: 'ALL', - gdprApplies: true, - }, - {} - ); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object'); - expect(syncData[0].type).to.be.a('string'); - expect(syncData[0].type).to.equal('image'); - expect(syncData[0].url).to.be.a('string'); - expect(syncData[0].url).to.equal( - 'https://usync.smxconv.com/image?pbjs=1&gdpr=1&gdpr_consent=ALL&coppa=0' - ); - }); - it('Should return array of objects with proper sync config , include CCPA', function () { - const syncData = spec.getUserSyncs( - {}, - {}, - {}, - { - consentString: '1---', - } - ); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object'); - expect(syncData[0].type).to.be.a('string'); - expect(syncData[0].type).to.equal('image'); - expect(syncData[0].url).to.be.a('string'); - expect(syncData[0].url).to.equal( - 'https://usync.smxconv.com/image?pbjs=1&ccpa_consent=1---&coppa=0' - ); - }); - it('Should return array of objects with proper sync config , include GPP', function () { - const syncData = spec.getUserSyncs( - {}, - {}, - {}, - {}, - { - gppString: 'abc123', - applicableSections: [8], - } - ); - expect(syncData).to.be.an('array').which.is.not.empty; - expect(syncData[0]).to.be.an('object'); - expect(syncData[0].type).to.be.a('string'); - expect(syncData[0].type).to.equal('image'); - expect(syncData[0].url).to.be.a('string'); - expect(syncData[0].url).to.equal( - 'https://usync.smxconv.com/image?pbjs=1&gpp=abc123&gpp_sid=8&coppa=0' - ); - }); - }); -}); diff --git a/test/spec/modules/snigelBidAdapter_spec.js b/test/spec/modules/snigelBidAdapter_spec.js deleted file mode 100644 index faeba529a..000000000 --- a/test/spec/modules/snigelBidAdapter_spec.js +++ /dev/null @@ -1,451 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/snigelBidAdapter.js'; -import {config} from 'src/config.js'; -import {isValid} from 'src/adapters/bidderFactory.js'; -import {registerActivityControl} from 'src/activities/rules.js'; -import {ACTIVITY_ACCESS_DEVICE} from 'src/activities/activities.js'; - -const BASE_BID_REQUEST = { - adUnitCode: 'top_leaderboard', - bidId: 'bid_test', - sizes: [ - [970, 90], - [728, 90], - ], - bidder: 'snigel', - params: {}, - requestId: 'req_test', - transactionId: 'trans_test', -}; -const makeBidRequest = function (overrides) { - return {...BASE_BID_REQUEST, ...overrides}; -}; - -const BASE_BIDDER_REQUEST = { - auctionId: 'test', - bidderRequestId: 'test', - refererInfo: { - page: 'https://localhost', - canonicalUrl: 'https://localhost', - }, -}; -const makeBidderRequest = function (overrides) { - return {...BASE_BIDDER_REQUEST, ...overrides}; -}; - -const DUMMY_USP_CONSENT = '1YYN'; -const DUMMY_GDPR_CONSENT_STRING = - 'BOSSotLOSSotLAPABAENBc-AAAAgR7_______9______9uz_Gv_v_f__33e8__9v_l_7_-___u_-33d4-_1vX99yfm1-7ftr3tp_86ues2_XqK_9oIiA'; -const DUMMY_GPP_CONSENT_STRING = 'DBABrw~BAAAAAAAAABA.QA~BAAAAABA.QA'; - -describe('snigelBidAdapter', function () { - describe('isBidRequestValid', function () { - it('should return false if no placement provided', function () { - expect(spec.isBidRequestValid(BASE_BID_REQUEST)).to.equal(false); - }); - - it('should return true if placement provided', function () { - const bidRequest = makeBidRequest({params: {placement: 'top_leaderboard'}}); - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - }); - - describe('buildRequests', function () { - afterEach(function () { - config.resetConfig(); - }); - - it('should build a single request for every impression and its placement', function () { - const bidderRequest = Object.assign({}, BASE_BIDDER_REQUEST); - const bidRequests = [ - makeBidRequest({bidId: 'a', adUnitCode: 'au_a', params: {placement: 'top_leaderboard'}}), - makeBidRequest({bidId: 'b', adUnitCode: 'au_b', params: {placement: 'bottom_leaderboard'}}), - ]; - - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request).to.be.an('object'); - expect(request).to.have.property('url').and.to.equal('https://adserv.snigelweb.com/bp/v1/prebid'); - expect(request).to.have.property('method').and.to.equal('POST'); - - expect(request).to.have.property('data'); - const data = JSON.parse(request.data); - expect(data).to.have.property('id').and.to.equal('test'); - expect(data).to.have.property('cur').and.to.deep.equal(['USD']); - expect(data).to.have.property('test').and.to.equal(false); - expect(data).to.have.property('page').and.to.equal('https://localhost'); - expect(data).to.have.property('placements'); - expect(data.placements.length).to.equal(2); - expect(data.placements[0].id).to.equal('au_a'); - expect(data.placements[0].name).to.equal('top_leaderboard'); - expect(data.placements[1].id).to.equal('au_b'); - expect(data.placements[1].name).to.equal('bottom_leaderboard'); - }); - - it('should forward GDPR flag and GDPR consent string if enabled', function () { - const bidderRequest = makeBidderRequest({ - gdprConsent: { - gdprApplies: true, - consentString: DUMMY_GDPR_CONSENT_STRING, - }, - }); - - const request = spec.buildRequests([], bidderRequest); - expect(request).to.have.property('data'); - const data = JSON.parse(request.data); - expect(data).to.have.property('gdprApplies').and.to.equal(true); - expect(data).to.have.property('gdprConsentString').and.to.equal(DUMMY_GDPR_CONSENT_STRING); - }); - - it('should forward GDPR flag and no GDPR consent string if disabled', function () { - const bidderRequest = makeBidderRequest({ - gdprConsent: { - gdprApplies: false, - consentString: DUMMY_GDPR_CONSENT_STRING, - }, - }); - - const request = spec.buildRequests([], bidderRequest); - expect(request).to.have.property('data'); - const data = JSON.parse(request.data); - expect(data).to.have.property('gdprApplies').and.to.equal(false); - expect(data).to.not.have.property('gdprConsentString'); - }); - - it('should forward USP consent if set', function () { - const bidderRequest = makeBidderRequest({ - uspConsent: DUMMY_USP_CONSENT, - }); - - const request = spec.buildRequests([], bidderRequest); - expect(request).to.have.property('data'); - const data = JSON.parse(request.data); - expect(data).to.have.property('uspConsent').and.to.equal(DUMMY_USP_CONSENT); - }); - - it('should forward whether or not COPPA applies', function () { - config.setConfig({ - 'coppa': true, - }); - - const request = spec.buildRequests([], BASE_BIDDER_REQUEST); - expect(request).to.have.property('data'); - const data = JSON.parse(request.data); - expect(data).to.have.property('coppa').and.to.equal(true); - }); - - it('should forward refresh information', function () { - const bidderRequest = Object.assign({}, BASE_BIDDER_REQUEST); - const topLeaderboard = makeBidRequest({adUnitCode: 'top_leaderboard'}); - const bottomLeaderboard = makeBidRequest({adUnitCode: 'bottom_leaderboard'}); - const sidebar = makeBidRequest({adUnitCode: 'sidebar'}); - - // first auction, no refresh - let request = spec.buildRequests([topLeaderboard, bottomLeaderboard], bidderRequest); - expect(request).to.have.property('data'); - let data = JSON.parse(request.data); - expect(data).to.have.property('placements'); - expect(data.placements.length).to.equal(2); - expect(data.placements[0].id).to.equal('top_leaderboard'); - expect(data.placements[0].refresh).to.be.undefined; - expect(data.placements[1].id).to.equal('bottom_leaderboard'); - expect(data.placements[1].refresh).to.be.undefined; - - // second auction for top leaderboard, was refreshed - request = spec.buildRequests([topLeaderboard, sidebar], bidderRequest); - expect(request).to.have.property('data'); - data = JSON.parse(request.data); - expect(data).to.have.property('placements'); - expect(data.placements.length).to.equal(2); - expect(data.placements[0].id).to.equal('top_leaderboard'); - expect(data.placements[0].refresh).to.not.be.undefined; - expect(data.placements[0].refresh.count).to.equal(1); - expect(data.placements[0].refresh.time).to.be.greaterThanOrEqual(0); - expect(data.placements[1].id).to.equal('sidebar'); - expect(data.placements[1].refresh).to.be.undefined; - - // third auction, all units refreshed at some point - request = spec.buildRequests([topLeaderboard, bottomLeaderboard, sidebar], bidderRequest); - expect(request).to.have.property('data'); - data = JSON.parse(request.data); - expect(data).to.have.property('placements'); - expect(data.placements.length).to.equal(3); - expect(data.placements[0].id).to.equal('top_leaderboard'); - expect(data.placements[0].refresh).to.not.be.undefined; - expect(data.placements[0].refresh.count).to.equal(2); - expect(data.placements[0].refresh.time).to.be.greaterThanOrEqual(0); - expect(data.placements[1].id).to.equal('bottom_leaderboard'); - expect(data.placements[1].refresh).to.not.be.undefined; - expect(data.placements[1].refresh.count).to.equal(1); - expect(data.placements[1].refresh.time).to.be.greaterThanOrEqual(0); - expect(data.placements[2].id).to.equal('sidebar'); - expect(data.placements[2].refresh).to.not.be.undefined; - expect(data.placements[2].refresh.count).to.equal(1); - expect(data.placements[2].refresh.time).to.be.greaterThanOrEqual(0); - }); - - it('should increment auction counter upon every request', function () { - const bidderRequest = makeBidderRequest({}); - - let request = spec.buildRequests([], bidderRequest); - expect(request).to.have.property('data'); - let data = JSON.parse(request.data); - const previousCounter = data.counter; - - request = spec.buildRequests([], bidderRequest); - expect(request).to.have.property('data'); - data = JSON.parse(request.data); - expect(data.counter).to.equal(previousCounter + 1); - }); - - it('should increment placement counter for each placement', function () { - const bidderRequest = Object.assign({}, BASE_BIDDER_REQUEST); - const topLeaderboard = makeBidRequest({adUnitCode: 'top_leaderboard', params: {placement: 'ros'}}); - const bottomLeaderboard = makeBidRequest({adUnitCode: 'bottom_leaderboard', params: {placement: 'ros'}}); - const sidebar = makeBidRequest({adUnitCode: 'sidebar', params: {placement: 'other'}}); - - let request = spec.buildRequests([topLeaderboard, bottomLeaderboard, sidebar], bidderRequest); - expect(request).to.have.property('data'); - let data = JSON.parse(request.data); - const previousCounters = {}; - data.placements.forEach((placement) => { - previousCounters[placement.name] = Math.max(previousCounters[placement.name] || 0, placement.counter); - }); - - request = spec.buildRequests([topLeaderboard, bottomLeaderboard, sidebar], bidderRequest); - expect(request).to.have.property('data'); - data = JSON.parse(request.data); - expect(data).to.have.property('placements'); - expect(data.placements.length).to.equal(3); - expect(data.placements[0].id).to.equal('top_leaderboard'); - expect(previousCounters).to.have.property(data.placements[0].name); - expect(data.placements[0].counter).to.equal(previousCounters[data.placements[0].name] + 1); - expect(data.placements[1].id).to.equal('bottom_leaderboard'); - expect(previousCounters).to.have.property(data.placements[1].name); - expect(data.placements[1].counter).to.equal(previousCounters[data.placements[1].name] + 2); - expect(data.placements[2].id).to.equal('sidebar'); - expect(previousCounters).to.have.property(data.placements[2].name); - expect(data.placements[2].counter).to.equal(previousCounters[data.placements[2].name] + 1); - }); - }); - - describe('interpretResponse', function () { - it('should not return any bids if the request failed', function () { - expect(spec.interpretResponse({}, {})).to.be.empty; - expect(spec.interpretResponse({body: 'Some error message'}, {})).to.be.empty; - }); - - it('should not return any bids if the request did not return any bids either', function () { - expect(spec.interpretResponse({body: {bids: []}})).to.be.empty; - }); - - it('should return valid bids with additional meta information', function () { - const serverResponse = { - body: { - id: BASE_BIDDER_REQUEST.bidderRequestId, - cur: 'USD', - bids: [ - { - id: BASE_BID_REQUEST.adUnitCode, - price: 0.0575, - ad: '

Test Ad

', - width: 728, - height: 90, - crid: 'test', - meta: { - advertiserDomains: ['addomain.com'], - }, - }, - ], - }, - }; - - const bids = spec.interpretResponse(serverResponse, {bidderRequest: {bids: [BASE_BID_REQUEST]}}); - expect(bids.length).to.equal(1); - const bid = bids[0]; - expect(isValid(BASE_BID_REQUEST.adUnitCode, bid)).to.be.true; - expect(bid).to.have.property('meta'); - expect(bid.meta).to.have.property('advertiserDomains'); - expect(bid.meta.advertiserDomains).to.be.an('array'); - expect(bid.meta.advertiserDomains.length).to.equal(1); - expect(bid.meta.advertiserDomains[0]).to.equal('addomain.com'); - }); - }); - - describe('getUserSyncs', function () { - it('should not return any user syncs if sync url does not exist in response', function () { - const response = { - body: { - id: BASE_BIDDER_REQUEST.bidderRequestId, - cur: 'USD', - bids: [], - }, - }; - const syncOptions = { - iframeEnabled: true, - }; - const gdprConsent = { - gdprApplies: false, - }; - - const syncs = spec.getUserSyncs(syncOptions, [response], gdprConsent); - expect(syncs).to.be.undefined; - }); - - it('should not return any user syncs if publisher disabled iframe-based sync', function () { - const response = { - body: { - id: BASE_BIDDER_REQUEST.bidderRequestId, - cur: 'USD', - syncUrl: 'https://somesyncurl', - bids: [], - }, - }; - const syncOptions = { - iframeEnabled: false, - }; - const gdprConsent = { - gdprApplies: false, - }; - - const syncs = spec.getUserSyncs(syncOptions, [response], gdprConsent); - expect(syncs).to.be.undefined; - }); - - it("should return an iframe specific to the publisher's property if all conditions are met", function () { - const response = { - body: { - id: BASE_BIDDER_REQUEST.bidderRequestId, - cur: 'USD', - syncUrl: 'https://somesyncurl', - bids: [], - }, - }; - const syncOptions = { - iframeEnabled: true, - }; - const gdprConsent = { - gdprApplies: false, - }; - - const syncs = spec.getUserSyncs(syncOptions, [response], gdprConsent); - expect(syncs).to.be.an('array').and.of.length(1); - const sync = syncs[0]; - expect(sync).to.have.property('type'); - expect(sync.type).to.equal('iframe'); - expect(sync).to.have.property('url'); - expect(sync.url).to.equal('https://somesyncurl?gdpr=0&gdpr_consent=&gpp_sid=&gpp=&us_privacy='); - }); - - it('should pass GDPR applicability and consent string as query parameters', function () { - const response = { - body: { - id: BASE_BIDDER_REQUEST.bidderRequestId, - cur: 'USD', - syncUrl: 'https://somesyncurl', - bids: [], - }, - }; - const syncOptions = { - iframeEnabled: true, - }; - const gdprConsent = { - gdprApplies: true, - consentString: DUMMY_GDPR_CONSENT_STRING, - vendorData: { - purpose: { - consents: {1: true}, - }, - }, - }; - - const syncs = spec.getUserSyncs(syncOptions, [response], gdprConsent); - expect(syncs).to.be.an('array').and.of.length(1); - const sync = syncs[0]; - expect(sync).to.have.property('type'); - expect(sync.type).to.equal('iframe'); - expect(sync).to.have.property('url'); - expect(sync.url).to.equal( - `https://somesyncurl?gdpr=1&gdpr_consent=${DUMMY_GDPR_CONSENT_STRING}&gpp_sid=&gpp=&us_privacy=` - ); - }); - - it('should pass GPP section IDs and consent string as query parameters', function () { - const response = { - body: { - id: BASE_BIDDER_REQUEST.bidderRequestId, - cur: 'USD', - syncUrl: 'https://somesyncurl', - bids: [], - }, - }; - const syncOptions = { - iframeEnabled: true, - }; - const gppConsent = { - applicableSections: [7, 8], - gppString: DUMMY_GPP_CONSENT_STRING, - }; - - const syncs = spec.getUserSyncs(syncOptions, [response], undefined, undefined, gppConsent); - expect(syncs).to.be.an('array').and.of.length(1); - const sync = syncs[0]; - expect(sync).to.have.property('type'); - expect(sync.type).to.equal('iframe'); - expect(sync).to.have.property('url'); - expect(sync.url).to.equal( - `https://somesyncurl?gdpr=0&gdpr_consent=&gpp_sid=7,8&gpp=${DUMMY_GPP_CONSENT_STRING}&us_privacy=` - ); - }); - - it('should omit session ID if no device access', function () { - const bidderRequest = makeBidderRequest(); - const unregisterRule = registerActivityControl(ACTIVITY_ACCESS_DEVICE, 'denyAccess', () => { - return {allow: false, reason: 'no consent'}; - }); - - try { - const request = spec.buildRequests([], bidderRequest); - expect(request).to.have.property('data'); - const data = JSON.parse(request.data); - expect(data.sessionId).to.be.undefined; - } finally { - unregisterRule(); - } - }); - - it('should determine full GDPR consent correctly', function () { - const baseBidderRequest = makeBidderRequest({ - gdprConsent: { - gdprApplies: true, - vendorData: { - purpose: { - consents: {1: true, 2: true, 3: true, 4: true, 5: true}, - }, - vendor: { - consents: {[spec.gvlid]: true}, - }, - }, - }, - }); - let request = spec.buildRequests([], baseBidderRequest); - expect(request).to.have.property('data'); - let data = JSON.parse(request.data); - expect(data.gdprConsent).to.be.true; - - let bidderRequest = {...baseBidderRequest, ...{gdprConsent: {vendorData: {purpose: {consents: {1: false}}}}}}; - request = spec.buildRequests([], bidderRequest); - expect(request).to.have.property('data'); - data = JSON.parse(request.data); - expect(data.gdprConsent).to.be.false; - - bidderRequest = { - ...baseBidderRequest, - ...{gdprConsent: {vendorData: {vendor: {consents: {[spec.gvlid]: false}}}}}, - }; - request = spec.buildRequests([], bidderRequest); - expect(request).to.have.property('data'); - data = JSON.parse(request.data); - expect(data.gdprConsent).to.be.false; - }); - }); -}); diff --git a/test/spec/modules/sonaradsBidAdapter_spec.js b/test/spec/modules/sonaradsBidAdapter_spec.js deleted file mode 100644 index e0afd0c7d..000000000 --- a/test/spec/modules/sonaradsBidAdapter_spec.js +++ /dev/null @@ -1,1156 +0,0 @@ -import { expect } from 'chai'; -import { - spec, BIDDER_CODE, SERVER_PATH_US1_SYNC, SERVER_PATH_US1_EVENTS -} from '../../../modules/sonaradsBidAdapter.js'; -import * as utils from 'src/utils.js'; -import * as ajax from 'src/ajax.js'; -import { hook } from '../../../src/hook.js'; -import { config } from '../../../src/config.js'; -import { addFPDToBidderRequest } from '../../helpers/fpd.js'; -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; -import 'modules/consentManagementGpp.js'; -import 'modules/priceFloors.js'; -import sinon from 'sinon'; - -// constants -const SITE_DOMAIN_NAME = 'sonargames.com'; -const SITE_PAGE = 'https://sonargames.com'; -describe('bridgeuppBidAdapter_spec', function () { - let utilsMock, sandbox, ajaxStub, fetchStub; - - afterEach(function () { - sandbox.restore(); - utilsMock.restore(); - ajaxStub.restore(); - fetchStub.restore(); - }); - - beforeEach(function () { - sandbox = sinon.createSandbox(); - utilsMock = sinon.mock(utils); - ajaxStub = sandbox.stub(ajax, 'ajax'); - fetchStub = sinon.stub(global, 'fetch').resolves(new Response('OK')); - }); - - describe('isBidRequestValid', function () { - let bid; - beforeEach(function () { - bid = { - 'bidder': BIDDER_CODE, - 'params': { - 'siteId': 'site-id-12', - } - }; - }); - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should return false when missing siteId', function () { - delete bid.params.siteId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - before(() => { - hook.ready(); - }) - afterEach(function () { - config.resetConfig(); - }); - const bidderRequest = { - refererInfo: { - page: 'https://sonarads.com/home', - ref: 'https://referrer' - }, - timeout: 1000, - gdprConsent: { - gdprApplies: true, - consentString: 'consentDataString', - vendorData: { - vendorConsents: { - '1300': 1 - }, - }, - apiVersion: 1, - }, - }; - - it('request should build with correct siteId', async function () { - const bidRequests = [ - { - bidId: 'bidId', - bidder: 'sonarads', - adUnitCode: 'bid-12', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - 'siteId': 'site-id-12' - } - }, - ]; - - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.imp[0].ext.bidder.siteId).to.deep.equal('site-id-12'); - }); - - it('request should build with correct imp', async function () { - const expectedMetric = { - url: 'https://sonarads.com' - } - const bidRequests = [{ - bidId: 'bidId', - bidder: 'sonarads', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - ortb2Imp: { - instl: 1, - metric: expectedMetric, - ext: { - gpid: 'gpid_sonarads' - }, - rwdd: 1 - }, - params: { - siteId: 'site-id-12', - bidfloor: 2.12, - bidfloorcur: 'USD' - } - }]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.imp).to.have.lengthOf(1); - expect(ortbRequest.imp[0].id).to.deep.equal('bidId'); - expect(ortbRequest.imp[0].tagid).to.deep.equal('impId'); - expect(ortbRequest.imp[0].instl).to.equal(1); - expect(ortbRequest.imp[0].bidfloor).to.equal(2.12); - expect(ortbRequest.imp[0].bidfloorcur).to.equal('USD'); - expect(ortbRequest.imp[0].metric).to.deep.equal(expectedMetric); - expect(ortbRequest.imp[0].ext.gpid).to.equal('gpid_sonarads'); - expect(ortbRequest.imp[0].secure).to.equal(1); - expect(ortbRequest.imp[0].rwdd).to.equal(1); - }); - - it('request should build with proper site data', async function () { - const bidRequests = [ - { - bidder: 'sonarads', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - siteId: 'site-id-12' - }, - }, - ]; - const ortb2 = { - site: { - name: SITE_DOMAIN_NAME, - domain: SITE_DOMAIN_NAME, - keywords: 'keyword1, keyword2', - cat: ['IAB2'], - pagecat: ['IAB3'], - sectioncat: ['IAB4'], - page: SITE_PAGE, - ref: 'google.com', - privacypolicy: 1, - content: { - url: SITE_PAGE + '/games1' - } - } - }; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest({...bidderRequest, ortb2})).data; - expect(ortbRequest.site.domain).to.equal(SITE_DOMAIN_NAME); - expect(ortbRequest.site.publisher.domain).to.equal('sonarads.com'); - expect(ortbRequest.site.page).to.equal(SITE_PAGE); - expect(ortbRequest.site.name).to.equal(SITE_DOMAIN_NAME); - expect(ortbRequest.site.keywords).to.equal('keyword1, keyword2'); - expect(ortbRequest.site.cat).to.deep.equal(['IAB2']); - expect(ortbRequest.site.pagecat).to.deep.equal(['IAB3']); - expect(ortbRequest.site.sectioncat).to.deep.equal(['IAB4']); - expect(ortbRequest.site.ref).to.equal('google.com'); - expect(ortbRequest.site.privacypolicy).to.equal(1); - expect(ortbRequest.site.content.url).to.equal(SITE_PAGE + '/games1') - }); - - it('request should build with proper device data', async function () { - const bidRequests = [ - { - bidder: 'sonarads', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - siteId: 'site-id-12' - }, - }, - ]; - const ortb2 = { - device: { - dnt: 1, - ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36', - ip: '203.0.113.42', - h: 800, - w: 1280, - language: 'fr', - lmt: 0, - js: 0, - connectiontype: 2, - hwv: 'iPad', - model: 'Pro', - mccmnc: '234-030', - geo: { - lat: 48.8566, - lon: 2.3522 - } - } - }; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest({...bidderRequest, ortb2})).data; - expect(ortbRequest.device.dnt).to.equal(1); - expect(ortbRequest.device.lmt).to.equal(0); - expect(ortbRequest.device.js).to.equal(0); - expect(ortbRequest.device.connectiontype).to.equal(2); - expect(ortbRequest.device.ua).to.equal('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36'); - expect(ortbRequest.device.ip).to.equal('203.0.113.42'); - expect(ortbRequest.device.h).to.equal(800); - expect(ortbRequest.device.w).to.equal(1280); - expect(ortbRequest.device.language).to.deep.equal('fr'); - expect(ortbRequest.device.hwv).to.deep.equal('iPad'); - expect(ortbRequest.device.model).to.deep.equal('Pro'); - expect(ortbRequest.device.mccmnc).to.deep.equal('234-030'); - expect(ortbRequest.device.geo.lat).to.deep.equal(48.8566); - expect(ortbRequest.device.geo.lon).to.deep.equal(2.3522); - }); - - it('should properly build a request with source object', async function () { - const expectedSchain = {id: 'prebid'}; - const ortb2 = { - source: { - pchain: 'sonarads', - ext: { - schain: expectedSchain - } - } - }; - const bidRequests = [ - { - bidder: 'sonarads', - bidId: 'bidId', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - siteId: 'site-id-12', - }, - }, - ]; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest({...bidderRequest, ortb2})).data; - expect(ortbRequest.source.ext.schain).to.deep.equal(expectedSchain); - expect(ortbRequest.source.pchain).to.equal('sonarads'); - }); - - it('should properly user object', async function () { - const bidRequests = [ - { - bidder: 'sonarads', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - siteId: 'site-id-12' - } - }, - ]; - const br = { - ...bidderRequest, - ortb2: { - user: { - yob: 2012, - keyowrds: 'test test', - gender: 'M', - customdata: 'test no', - geo: { - lat: 48.8566, - lon: 2.3522 - }, - ext: { - eids: [ - { - source: 'sonarads.com', - uids: [{ - id: 'iid', - atype: 1 - }] - } - ] - } - } - } - } - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(br)); - const ortbRequest = request.data; - expect(ortbRequest.user.yob).to.deep.equal(2012); - expect(ortbRequest.user.keyowrds).to.deep.equal('test test'); - expect(ortbRequest.user.gender).to.deep.equal('M'); - expect(ortbRequest.user.customdata).to.deep.equal('test no'); - expect(ortbRequest.user.geo.lat).to.deep.equal(48.8566); - expect(ortbRequest.user.geo.lon).to.deep.equal(2.3522); - expect(ortbRequest.user.ext.eids).to.deep.equal([ - { - source: 'sonarads.com', - uids: [{ - id: 'iid', - atype: 1 - }] - } - ]); - }); - - it('should properly build a request regs object', async function () { - const bidRequests = [ - { - bidder: 'sonarads', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - siteId: 'site-id-12' - }, - }, - ]; - const ortb2 = { - regs: { - coppa: 1, - gpp: 'consent_string', - gpp_sid: [0, 1, 2], - us_privacy: 'yes us privacy applied' - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest({...bidderRequest, ortb2})).data; - expect(ortbRequest.regs.coppa).to.equal(1); - expect(ortbRequest.regs.gpp).to.equal('consent_string'); - expect(ortbRequest.regs.gpp_sid).to.deep.equal([0, 1, 2]); - expect(ortbRequest.regs.us_privacy).to.deep.equal('yes us privacy applied'); - }); - - it('gdpr test', async function () { - // using privacy params from global bidder Request - const bidRequests = [ - { - bidder: 'sonarads', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - siteId: 'site-id-12' - }, - }, - ]; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.regs.ext.gdpr).to.deep.equal(1); - expect(ortbRequest.user.ext.consent).to.equal('consentDataString'); - }); - - it('should properly set tmax if available', async function () { - // using tmax from global bidder Request - const bidRequests = [ - { - bidder: 'sonarads', - adUnitCode: 'bid-1', - transactionId: 'trans-1', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - siteId: 'site-id-12' - } - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.tmax).to.equal(bidderRequest.timeout); - }); - - it('should properly set auction data', async function () { - const bidRequests = [ - { - bidder: 'sonarads', - adUnitCode: 'bid-1', - transactionId: 'trans-1', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - siteId: 'site-id-12' - } - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.auctionStart).to.equal(bidderRequest.auctionStart); - }); - - it('should properly build a request with bcat field', async function () { - const bcat = ['IAB1', 'IAB2']; - const bidRequests = [ - { - bidder: 'sonarads', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - siteId: 'site-id-12', - }, - }, - ]; - const bidderRequest = { - ortb2: { - bcat - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.bcat).to.deep.equal(bcat); - }); - - it('should properly build a request with badv field', async function () { - const badv = ['nike.com']; - const bidRequests = [ - { - bidder: 'sonarads', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - siteId: 'site-id-12', - }, - }, - ]; - const bidderRequest = { - ortb2: { - badv - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.badv).to.deep.equal(badv); - }); - - it('should properly build a request with bapp field', async function () { - const bapp = ['nike.com']; - const bidRequests = [ - { - bidder: 'sonarads', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - siteId: 'site-id-12', - }, - }, - ]; - const bidderRequest = { - ortb2: { - bapp - } - }; - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.bapp).to.deep.equal(bapp); - }); - - it('banner request test', async function () { - const bidderRequest = {}; - const bidRequests = [ - { - bidId: 'bidId', - bidder: 'sonarads', - adUnitCode: 'bid-12', - mediaTypes: { - banner: { - sizes: [[320, 250]], - pos: 1, - topframe: 0, - } - }, - params: { - siteId: 'site-id-12' - }, - ortb2Imp: { - banner: { - api: [1, 2, 3], - mimes: ['image/jpg', 'image/gif'] - } - } - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.imp[0].banner).not.to.be.null; - expect(ortbRequest.imp[0].banner.format[0].w).to.equal(320); - expect(ortbRequest.imp[0].banner.format[0].h).to.equal(250); - expect(ortbRequest.imp[0].banner.pos).to.equal(1); - expect(ortbRequest.imp[0].banner.topframe).to.equal(0); - expect(ortbRequest.imp[0].banner.api).to.deep.equal([1, 2, 3]); - expect(ortbRequest.imp[0].banner.mimes).to.deep.equal(['image/jpg', 'image/gif']); - }); - - it('banner request test with sizes > 1', async function () { - const bidderRequest = {}; - const bidRequests = [ - { - bidId: 'bidId', - bidder: 'sonarads', - adUnitCode: 'bid-12', - mediaTypes: { - banner: { - sizes: [[336, 336], [720, 50]] - } - }, - params: { - siteId: 'site-id-12' - } - }, - ]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = request.data; - expect(ortbRequest.imp[0].banner).not.to.be.null; - expect(ortbRequest.imp[0].banner.format[0].w).to.equal(336); - expect(ortbRequest.imp[0].banner.format[0].h).to.equal(336); - expect(ortbRequest.imp[0].banner.format[1].w).to.equal(720); - expect(ortbRequest.imp[0].banner.format[1].h).to.equal(50); - }); - - it('should properly build a request when coppa is true', async function () { - const bidRequests = []; - const bidderRequest = {}; - config.setConfig({coppa: true}); - - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.regs.coppa).to.equal(1); - }); - - it('should properly build a request when coppa is false', async function () { - const bidRequests = []; - const bidderRequest = {}; - config.setConfig({coppa: false}); - const buildRequests = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const ortbRequest = buildRequests.data; - expect(ortbRequest.regs.coppa).to.equal(0); - }); - - it('should properly build a request when coppa is not defined', async function () { - const bidRequests = []; - const bidderRequest = {}; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.regs?.coppa).to.be.undefined; - }); - - it('build a banner request with bidFloor', async function () { - const bidRequests = [ - { - bidder: 'sonarads', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50], [720, 90]] - } - }, - params: { - siteId: 'site-id-12', - bidfloor: 1, - bidfloorcur: 'USD' - } - } - ]; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].bidfloor).to.deep.equal(1); - expect(ortbRequest.imp[0].bidfloorcur).to.deep.equal('USD'); - }); - - it('build a banner request with getFloor', async function () { - const bidRequests = [ - { - bidder: 'sonarads', - adUnitCode: 'impId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - siteId: 'site-id-12' - }, - getFloor: () => { - return {currency: 'USD', floor: 1.23, size: '*', mediaType: '*'}; - } - } - ]; - const ortbRequest = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)).data; - expect(ortbRequest.imp[0].bidfloor).equal(1.23); - expect(ortbRequest.imp[0].bidfloorcur).equal('USD'); - }); - }); - - describe('interpretResponse', function () { - const bidderRequest = { - refererInfo: { - page: 'https://sonarads.com/home', - ref: 'https://referrer' - }, - timeout: 1000, - gdprConsent: { - gdprApplies: true, - consentString: 'consentDataString', - vendorData: { - vendorConsents: { - '1300': 1 - }, - }, - apiVersion: 1, - }, - } - - function mockResponse(bidId, mediaType) { - return { - id: 'sonarads-response-id-hash-123123', - cur: 'USD', - seatbid: [ - { - bid: [ - { - id: 'sonarads-seatbid-bid-id-hash-123qaasd34', - impid: bidId, - price: 1.12, - adomain: ['advertiserDomain.sandbox.sonarads.com'], - crid: 'd3868d0b2f43c11e4bd60333e5e5ee8be471c4061b3b0cd454539c7edb68a1ca', - w: 320, - h: 250, - adm: 'test-ad', - mtype: mediaType, - nurl: 'https://et-l.w.sonarads.com/c.asm/', - api: 3, - cat: [], - ext: { - prebid: { - meta: { - advertiserDomains: ['advertiserDomain.sandbox.sonarads.com'], - networkName: 'sonarads' - } - } - } - } - ] - } - ], - ext: { - prebidjs: { - urls: [ - { url: 'https://sync.sonarads.com/prebidjs' }, - { url: 'https://eus.rubiconproject.com/usync.html?p=test' } - ] - } - } - } - } - - it('should returns an empty array when bid response is empty', async function () { - const bidRequests = []; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const serverResponse = { - headers: { - get: function () { - return undefined - } - }, - body: {} - }; - - const interpretedBids = spec.interpretResponse(serverResponse, request); - expect(interpretedBids).to.have.lengthOf(0); - expect(spec.reportEventsEnabled).to.equal(false); - }); - - it('should return an empty array when there is no bid response', async function () { - const bidRequests = []; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const serverResponse = { - headers: { - get: function () { - return undefined - } - }, - body: {seatbid: []} - }; - - const interpretedBids = spec.interpretResponse(serverResponse, request); - expect(interpretedBids).to.have.lengthOf(0); - expect(spec.reportEventsEnabled).to.equal(false); - }); - - it('return banner response', async function () { - const bidRequests = [{ - adUnitCode: 'impId', - bidId: 'bidId', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - siteId: 'site-id-12', - } - }]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const serverResponse = { - headers: { - get: function () { - return undefined - } - }, - body: mockResponse('bidId', 1) - }; - const interpretedBids = spec.interpretResponse(serverResponse, request); - expect(spec.reportEventsEnabled).to.equal(false); - expect(interpretedBids).to.have.length(1); - expect(interpretedBids[0].currency).to.deep.equal('USD'); - expect(interpretedBids[0].mediaType).to.deep.equal('banner'); - expect(interpretedBids[0].requestId).to.deep.equal('bidId'); - expect(interpretedBids[0].seatBidId).to.deep.equal('sonarads-seatbid-bid-id-hash-123qaasd34'); - expect(interpretedBids[0].cpm).to.equal(1.12); - expect(interpretedBids[0].width).to.equal(320); - expect(interpretedBids[0].height).to.equal(250); - expect(interpretedBids[0].creativeId).to.deep.equal('d3868d0b2f43c11e4bd60333e5e5ee8be471c4061b3b0cd454539c7edb68a1ca'); - expect(interpretedBids[0].meta.advertiserDomains[0]).to.deep.equal('advertiserDomain.sandbox.sonarads.com'); - }); - - it('should set the reportEventsEnabled to true as part of the response', async function () { - const bidRequests = [{ - adUnitCode: 'impId', - bidId: 'bidId', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 320], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - siteId: 'site-id-12', - }, - }, { - adUnitCode: 'impId', - bidId: 'bidId2', - mediaTypes: { - banner: { - sizes: [[320, 50]] - } - }, - params: { - siteId: 'site-id-12', - } - }]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const serverResponse = { - headers: { - get: function (header) { - if (header === 'reportEventsEnabled') { - return 1; - } - } - }, - body: mockResponse('bidId2', 1) - }; - - const interpretedBids = spec.interpretResponse(serverResponse, request); - expect(spec.reportEventsEnabled).to.equal(true); - expect(interpretedBids).to.have.length(1); - }); - - it('bid response when banner wins among two ad units', async function () { - const bidRequests = [{ - adUnitCode: 'impId', - bidId: 'bidId', - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mpeg'], - playerSize: [640, 320], - protocols: [5, 6], - maxduration: 30, - api: [1, 2] - } - }, - params: { - siteId: 'site-id-12', - }, - }, { - adUnitCode: 'impId', - bidId: 'bidId2', - mediaTypes: { - banner: { - sizes: [[320, 250]] - } - }, - params: { - siteId: 'site-id-12', - } - }]; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - const serverResponse = { - headers: { - get: function (header) { - if (header === 'reportEventsEnabled') { - return 1; - } - } - }, - body: mockResponse('bidId2', 1) - }; - - const interpretedBids = spec.interpretResponse(serverResponse, request); - expect(spec.reportEventsEnabled).to.equal(true); - expect(interpretedBids[0].currency).to.deep.equal('USD'); - expect(interpretedBids[0].mediaType).to.deep.equal('banner'); - expect(interpretedBids[0].requestId).to.deep.equal('bidId2'); - expect(interpretedBids[0].cpm).to.equal(1.12); - expect(interpretedBids[0].seatBidId).to.deep.equal('sonarads-seatbid-bid-id-hash-123qaasd34'); - expect(interpretedBids[0].creativeId).to.deep.equal('d3868d0b2f43c11e4bd60333e5e5ee8be471c4061b3b0cd454539c7edb68a1ca'); - expect(interpretedBids[0].width).to.equal(320); - expect(interpretedBids[0].height).to.equal(250); - expect(interpretedBids[0].meta.advertiserDomains[0]).to.deep.equal('advertiserDomain.sandbox.sonarads.com'); - }); - }); - - describe('getUserSyncs', function () { - it('should return empty if iframe disabled and pixelEnabled is false', function () { - const res = spec.getUserSyncs({}); - expect(res).to.deep.equal([]); - }); - - it('should return user sync if iframe enabled is true', function () { - const res = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }); - expect(res).to.deep.equal([{ type: 'iframe', url: `${SERVER_PATH_US1_SYNC}` }]); - }); - - it('should return user sync if iframe enabled is true and gdpr not present', function () { - const res = spec.getUserSyncs({ iframeEnabled: true }, {}, { gdprApplies: false }); - expect(res).to.deep.equal([{ type: 'iframe', url: `${SERVER_PATH_US1_SYNC}` }]); - }); - - it('should return user sync if iframe enabled is true and gdpr = 1 and gdpr consent present', function () { - const res = spec.getUserSyncs({ iframeEnabled: true }, {}, { gdprApplies: true, consentString: 'GDPR_CONSENT' }); - expect(res).to.deep.equal([{ type: 'iframe', url: `${SERVER_PATH_US1_SYNC}?gdpr=1&gdpr_consent=GDPR_CONSENT` }]); - }); - - it('should return user sync if iframe enabled is true and gdpr = 1 , gdpr consent present and usp_consent present', function () { - const res = spec.getUserSyncs({ iframeEnabled: true }, {}, { gdprApplies: true, consentString: 'GDPR_CONSENT' }, 'USP_CONSENT'); - expect(res).to.deep.equal([{ type: 'iframe', url: `${SERVER_PATH_US1_SYNC}?gdpr=1&gdpr_consent=GDPR_CONSENT&us_privacy=USP_CONSENT` }]); - }); - - it('should return user sync if iframe enabled is true usp_consent present and gppConsent present', function () { - const res = spec.getUserSyncs({ iframeEnabled: true }, {}, { gdprApplies: false, consentString: undefined }, 'USP_CONSENT', { gppString: 'GPP_STRING', applicableSections: [32, 51] }); - expect(res).to.deep.equal([{ type: 'iframe', url: `${SERVER_PATH_US1_SYNC}?us_privacy=USP_CONSENT&gpp=GPP_STRING&gpp_sid=32%2C51` }]); - }); - }); - - describe('onTimeout', function () { - it('onTimeout function should be defined', function () { - expect(spec.onTimeout).to.exist.and.to.be.a('function'); - }); - - it('should invoke onTimeout, resolving the eventType and domain', function () { - const bid = [ - { - bidder: 'sonarads', - bidId: 'sonar-bid-id-1231232', - adUnitCode: 'sonar-ad-1231232', - timeout: 1000, - auctionId: 'sonar-auction-1231232' - } - ]; - spec.reportEventsEnabled = true; - spec.onTimeout(bid); - - // expected url and payload - const expectedUrl = `${SERVER_PATH_US1_EVENTS}`; - const expectedPayload = JSON.stringify({ - domain: location.hostname, - prebidVersion: '$prebid.version$', - eventType: 'onTimeout', - eventPayload: bid - }); - - // assert statements - expect(fetchStub.callCount).to.be.equal(1); - - const fetchArgs = fetchStub.getCall(0).args; - expect(fetchArgs[0]).to.equal(expectedUrl); - const actualPayload = fetchArgs[1]?.body; - expect(actualPayload).to.equal(expectedPayload); - expect(fetchArgs[1]).to.deep.include({ - method: 'POST', - keepalive: true, - }); - expect(fetchArgs[1]?.headers).to.deep.equal({ - 'Content-Type': 'application/json', - }); - }); - - it('onTimeout should not be called if the bid data is null', function () { - // Call onTimeout with null data - spec.onTimeout(null); - // Assert that ajax was not called since bid data is null - expect(fetchStub.callCount).to.be.equal(0); - }); - }); - - describe('onSetTargeting', function () { - it('onSetTargeting function should be defined', function () { - expect(spec.onSetTargeting).to.exist.and.to.be.a('function'); - }); - - it('should invoke onSetTargeting, resolving the eventType and domain', function () { - const bid = [ - { - bidder: 'sonarads', - bidId: 'sonar-bid-id-1231232', - adUnitCode: 'sonar-ad-1231232', - timeout: 1000, - auctionId: 'sonar-auction-1231232' - } - ]; - spec.reportEventsEnabled = true; - spec.onSetTargeting(bid); - - // expected url and payload - const expectedUrl = `${SERVER_PATH_US1_EVENTS}`; - const expectedPayload = JSON.stringify({ - domain: location.hostname, - prebidVersion: '$prebid.version$', - eventType: 'onSetTargeting', - eventPayload: bid - }); - - // assert statements - expect(fetchStub.callCount).to.be.equal(1); - - const fetchArgs = fetchStub.getCall(0).args; - expect(fetchArgs[0]).to.equal(expectedUrl); - const actualPayload = fetchArgs[1]?.body; - expect(actualPayload).to.equal(expectedPayload); - expect(fetchArgs[1]).to.deep.include({ - method: 'POST', - keepalive: true, - }); - expect(fetchArgs[1]?.headers).to.deep.equal({ - 'Content-Type': 'application/json', - }); - }); - - it('onSetTargeting should not be called if the bid data is null', function () { - // Call onSetTargeting with null data - spec.onSetTargeting(null); - // Assert that ajax was not called since bid data is null - expect(fetchStub.callCount).to.be.equal(0); - }); - }); - - describe('onAdRenderSucceeded', function () { - it('onAdRenderSucceeded function should be defined', function () { - expect(spec.onAdRenderSucceeded).to.exist.and.to.be.a('function'); - }); - - it('should invoke onAdRenderSucceeded, resolving the eventType and domain', function () { - const bid = [ - { - bidder: 'sonarads', - bidId: 'sonar-bid-id-1231232', - adUnitCode: 'sonar-ad-1231232', - timeout: 1000, - auctionId: 'sonar-auction-1231232' - } - ]; - - spec.reportEventsEnabled = true; - spec.onAdRenderSucceeded(bid); - - // expected url and payload - const expectedUrl = `${SERVER_PATH_US1_EVENTS}`; - const expectedPayload = JSON.stringify({ - domain: location.hostname, - prebidVersion: '$prebid.version$', - eventType: 'onAdRenderSucceeded', - eventPayload: bid - }); - - // assert statements - expect(fetchStub.callCount).to.be.equal(1); - - const fetchArgs = fetchStub.getCall(0).args; - expect(fetchArgs[0]).to.equal(expectedUrl); - const actualPayload = fetchArgs[1]?.body; - expect(actualPayload).to.equal(expectedPayload); - expect(fetchArgs[1]).to.deep.include({ - method: 'POST', - keepalive: true, - }); - expect(fetchArgs[1]?.headers).to.deep.equal({ - 'Content-Type': 'application/json', - }); - }); - - it('onAdRenderSucceeded should not be called if the bid data is null', function () { - // Call onAdRenderSucceeded with null data - spec.onAdRenderSucceeded(null); - // Assert that ajax was not called since bid data is null - expect(fetchStub.callCount).to.be.equal(0); - }); - }); - - describe('onBidderError', function () { - it('onBidderError function should be defined', function () { - expect(spec.onBidderError).to.exist.and.to.be.a('function'); - }); - - it('should invoke onBidderError, resolving the eventType and domain', function () { - const bid = [ - { - bidder: 'sonarads', - bidId: 'sonar-bid-id-1231232', - adUnitCode: 'sonar-ad-1231232', - timeout: 1000, - auctionId: 'sonar-auction-1231232' - } - ]; - spec.reportEventsEnabled = true; - spec.onBidderError(bid); - - // expected url and payload - const expectedUrl = `${SERVER_PATH_US1_EVENTS}`; - const expectedPayload = JSON.stringify({ - domain: location.hostname, - prebidVersion: '$prebid.version$', - eventType: 'onBidderError', - eventPayload: bid - }); - - // assert statements - expect(fetchStub.callCount).to.be.equal(1); - - const fetchArgs = fetchStub.getCall(0).args; - expect(fetchArgs[0]).to.equal(expectedUrl); - const actualPayload = fetchArgs[1]?.body; - expect(actualPayload).to.equal(expectedPayload); - expect(fetchArgs[1]).to.deep.include({ - method: 'POST', - keepalive: true, - }); - expect(fetchArgs[1]?.headers).to.deep.equal({ - 'Content-Type': 'application/json', - }); - }); - - it('onBidderError should not be called if the bid data is null', function () { - // Call onBidderError with null data - spec.onBidderError(null); - // Assert that ajax was not called since bid data is null - expect(fetchStub.callCount).to.be.equal(0); - }); - }); - - describe('onBidWon', function () { - it('onBidWon function should be defined', function () { - expect(spec.onBidWon).to.exist.and.to.be.a('function'); - }); - - it('should invoke onBidWon, resolving the eventType and domain', function () { - const bid = [ - { - bidder: 'sonarads', - bidId: 'sonar-bid-id-1231232', - adUnitCode: 'sonar-ad-1231232', - timeout: 1000, - auctionId: 'sonar-auction-1231232' - } - ]; - spec.reportEventsEnabled = true; - spec.onBidWon(bid); - - // expected url and payload - const expectedUrl = `${SERVER_PATH_US1_EVENTS}`; - const expectedPayload = JSON.stringify({ - domain: location.hostname, - prebidVersion: '$prebid.version$', - eventType: 'onBidWon', - eventPayload: bid - }); - - // assert statements - expect(fetchStub.callCount).to.be.equal(1); - - const fetchArgs = fetchStub.getCall(0).args; - expect(fetchArgs[0]).to.equal(expectedUrl); - const actualPayload = fetchArgs[1]?.body; - expect(actualPayload).to.equal(expectedPayload); - expect(fetchArgs[1]).to.deep.include({ - method: 'POST', - keepalive: true, - }); - expect(fetchArgs[1]?.headers).to.deep.equal({ - 'Content-Type': 'application/json', - }); - }); - - it('onBidWon should not be called if the bid data is null', function () { - // Call onBidWon with null data - spec.onBidWon(null); - // Assert that ajax was not called since bid data is null - expect(fetchStub.callCount).to.be.equal(0); - }); - }); -}); diff --git a/test/spec/modules/sonobiBidAdapter_spec.js b/test/spec/modules/sonobiBidAdapter_spec.js deleted file mode 100644 index f7b1d858d..000000000 --- a/test/spec/modules/sonobiBidAdapter_spec.js +++ /dev/null @@ -1,909 +0,0 @@ -import { expect } from 'chai'; -import { _getPlatform, spec } from 'modules/sonobiBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { userSync } from '../../../src/userSync.js'; -import { config } from 'src/config.js'; -import * as gptUtils from '../../../libraries/gptUtils/gptUtils.js'; -import { parseQS } from '../../../src/utils.js' -import {getGlobal} from '../../../src/prebidGlobal.js'; -describe('SonobiBidAdapter', function () { - const adapter = newBidder(spec) - const originalBuildRequests = spec.buildRequests; - spec.buildRequests = (...args) => { - const result = originalBuildRequests(...args); - if (result && result.data) { - result.data = parseQS(result.data); // Translate back into a js object so we can validate it - } - - return result; - } - describe('.code', function () { - it('should return a bidder code of sonobi', function () { - expect(spec.code).to.equal('sonobi') - }) - }) - - describe('inherited functions', function () { - it('should exist and be a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function') - }) - }) - - describe('.isBidRequestValid', function () { - it('should return false if there are no params', () => { - const bid = { - 'bidder': 'sonobi', - 'adUnitCode': 'adunit-code', - 'mediaTypes': { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if there is no placement_id param and no ad_unit param', () => { - const bid = { - 'bidder': 'sonobi', - 'adUnitCode': 'adunit-code', - params: { - placementId: '1a2b3c4d5e6f1a2b3c4d', - }, - 'mediaTypes': { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if there is no mediaTypes', () => { - const bid = { - 'bidder': 'sonobi', - 'adUnitCode': 'adunit-code', - params: { - placement_id: '1a2b3c4d5e6f1a2b3c4d' - }, - 'mediaTypes': { - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true if the bid is valid', () => { - const bid = { - 'bidder': 'sonobi', - 'adUnitCode': 'adunit-code', - params: { - placement_id: '1a2b3c4d5e6f1a2b3c4d' - }, - 'mediaTypes': { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - describe('banner', () => { - it('should return false if there are no banner sizes and no param sizes', () => { - const bid = { - 'bidder': 'sonobi', - 'adUnitCode': 'adunit-code', - params: { - placement_id: '1a2b3c4d5e6f1a2b3c4d' - }, - 'mediaTypes': { - banner: { - - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true if there is banner sizes and no param sizes', () => { - const bid = { - 'bidder': 'sonobi', - 'adUnitCode': 'adunit-code', - params: { - placement_id: '1a2b3c4d5e6f1a2b3c4d' - }, - 'mediaTypes': { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true if there is param sizes and no banner sizes', () => { - const bid = { - 'bidder': 'sonobi', - 'adUnitCode': 'adunit-code', - params: { - placement_id: '1a2b3c4d5e6f1a2b3c4d', - sizes: [[300, 250], [300, 600]] - }, - 'mediaTypes': { - banner: { - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - - describe('video', () => { - describe('instream', () => { - it('should return false if there is no playerSize defined in the video mediaType', () => { - const bid = { - 'bidder': 'sonobi', - 'adUnitCode': 'adunit-code', - params: { - placement_id: '1a2b3c4d5e6f1a2b3c4d', - sizes: [[300, 250], [300, 600]] - }, - 'mediaTypes': { - video: { - context: 'instream' - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true if there is playerSize defined on the video mediaType', () => { - const bid = { - 'bidder': 'sonobi', - 'adUnitCode': 'adunit-code', - params: { - placement_id: '1a2b3c4d5e6f1a2b3c4d', - }, - 'mediaTypes': { - video: { - context: 'instream', - playerSize: [300, 250] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - - describe('outstream', () => { - it('should return false if there is no playerSize', () => { - const bid = { - 'bidder': 'sonobi', - 'adUnitCode': 'adunit-code', - params: { - placement_id: '1a2b3c4d5e6f1a2b3c4d', - }, - 'mediaTypes': { - video: { - context: 'outstream', - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true if there is playerSize', () => { - const bid = { - 'bidder': 'sonobi', - 'adUnitCode': 'adunit-code', - params: { - placement_id: '1a2b3c4d5e6f1a2b3c4d', - sizes: [300, 250] - - }, - 'mediaTypes': { - video: { - context: 'outstream', - playerSize: [640, 480] - } - }, - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - }); - }); - - describe('.buildRequests', function () { - before(function () { - getGlobal().bidderSettings = { - sonobi: { - storageAllowed: true - } - }; - }); - let sandbox; - beforeEach(function () { - sinon.stub(userSync, 'canBidderRegisterSync'); - sinon.stub(gptUtils, 'getGptSlotInfoForAdUnitCode') - .onFirstCall().returns({ gptSlot: '/123123/gpt_publisher/adunit-code-3', divId: 'adunit-code-3-div-id' }); - sandbox = sinon.createSandbox(); - }); - afterEach(function () { - userSync.canBidderRegisterSync.restore(); - gptUtils.getGptSlotInfoForAdUnitCode.restore(); - sandbox.restore(); - }); - const bidRequest = [{ - 'ortb2': { - 'source': { - 'ext': { - 'schain': { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'indirectseller.com', - 'sid': '00001', - 'hp': 1 - }, - { - 'asi': 'indirectseller-2.com', - 'sid': '00002', - 'hp': 0 - }, - ] - } - } - } - }, - 'bidder': 'sonobi', - 'params': { - 'keywords': 'sports,news,some_other_keyword', - 'placement_id': '1a2b3c4d5e6f1a2b3c4d', - 'sizes': [[300, 250], [300, 600]], - 'floor': '1.25', - 'referrer': 'overrides_top_window_location' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1f', - ortb2Imp: { - ext: { - data: {}, - gpid: '/123123/gpt_publisher/adunit-code-1' - } - }, - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'outstream', - playbackmethod: [1, 2, 3], - plcmt: 3, - placement: 2, - protocols: [1, 2, 3, 4, 5], - mimes: ['video/mp4', 'video/mpeg', 'video/x-flv'], - battr: [16, 17], - api: [1, 2, 3], - minduration: 5, - maxduration: 60, - skip: 1, - skipafter: 10, - startdelay: 5, - linearity: 1, - minbitrate: 1, - maxbitrate: 2 - } - } - }, - { - - 'bidder': 'sonobi', - 'params': { - 'keywords': 'sports,news,some_other_keyword', - 'placement_id': '1a2b3c4d5e6f1a2b3c4d', - 'sizes': [[300, 250], [300, 600]], - 'floor': '1.25', - }, - 'adUnitCode': 'adunit-code-42', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1g', - ortb2Imp: { - ext: { - gpid: '/123123/gpt_publisher/adunit-code-42' - } - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - } - }, - { - 'bidder': 'sonobi', - 'params': { - 'placement_id': '1a2b3c4d5e6f1a2b3c4e', - 'sizes': [[300, 250], [300, 600]], - 'referrer': 'overrides_top_window_location' - }, - 'adUnitCode': 'adunit-code-3', - 'sizes': [[120, 600], [300, 600], [160, 600]], - 'bidId': '30b31c1838de1d', - 'getFloor': ({ currency, mediaType, size }) => { - return { - currency: 'USD', - floor: 0.42 - } - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - } - }, - { - 'bidder': 'sonobi', - 'params': { - 'ad_unit': '/7780971/sparks_prebid_LB', - 'sizes': [[300, 250], [300, 600]], - 'referrer': 'overrides_top_window_location' - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[120, 600], [300, 600], [160, 600]], - 'bidId': '30b31c1838de1e', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - } - }]; - - const keyMakerData = { - '30b31c1838de1f': '1a2b3c4d5e6f1a2b3c4d|640x480|f=1.25,gpid=/123123/gpt_publisher/adunit-code-1,c=v,pm=1:2:3,p=2,pl=3,protocols=1:2:3:4:5,mimes=video/mp4:video/mpeg:video/x-flv,battr=16:17,api=1:2:3,minduration=5,maxduration=60,skip=1,skipafter=10,startdelay=5,linearity=1,minbitrate=1,maxbitrate=2,', - '30b31c1838de1g': '1a2b3c4d5e6f1a2b3c4d|300x250,300x600|f=1.25,gpid=/123123/gpt_publisher/adunit-code-42,c=d,', - '30b31c1838de1d': '1a2b3c4d5e6f1a2b3c4e|300x250,300x600|f=0.42,gpid=/123123/gpt_publisher/adunit-code-3,c=d,', - '/7780971/sparks_prebid_LB|30b31c1838de1e': '300x250,300x600|gpid=/7780971/sparks_prebid_LB,c=d,', - }; - - const bidderRequests = { - 'gdprConsent': { - 'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - 'vendorData': {}, - 'gdprApplies': true - }, - 'refererInfo': { - 'numIframes': 0, - 'reachedTop': true, - 'page': 'https://example.com', - 'stack': ['https://example.com'] - }, - uspConsent: 'someCCPAString', - ortb2: {} - - }; - - it('should set fpd if there is any data in ortb2', function () { - const ortb2 = { - site: { - ext: { - data: { - pageType: 'article', - category: 'tools' - } - } - }, - user: { - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - } - }; - const bidRequests = spec.buildRequests(bidRequest, { ...bidderRequests, ortb2 }); - expect(bidRequests.data.fpd).to.equal(encodeURIComponent(JSON.stringify(ortb2))); - }); - - it('should populate coppa as 1 if set in config', function () { - config.setConfig({ coppa: true }); - const bidRequests = spec.buildRequests(bidRequest, bidderRequests); - - expect(bidRequests.data.coppa).to.equal(encodeURIComponent(1)); - }); - - it('should populate coppa as 0 if set in config', function () { - config.setConfig({ coppa: false }); - const bidRequests = spec.buildRequests(bidRequest, bidderRequests); - - expect(bidRequests.data.coppa).to.equal(encodeURIComponent(0)); - }); - - it('should have storageAllowed set to true', function () { - expect(getGlobal().bidderSettings.sonobi.storageAllowed).to.be.true; - }); - - it('should return a properly formatted request', function () { - const bidRequests = spec.buildRequests(bidRequest, bidderRequests) - const bidRequestsPageViewID = spec.buildRequests(bidRequest, bidderRequests) - expect(bidRequests.url).to.equal('https://apex.go.sonobi.com/trinity.json') - expect(bidRequests.method).to.equal('POST') - expect(decodeURIComponent(bidRequests.data.key_maker)).to.deep.equal(JSON.stringify((keyMakerData))) - expect(bidRequests.data.ref).not.to.be.empty - expect(bidRequests.data.s).not.to.be.empty - expect(bidRequests.data.pv).to.equal(bidRequestsPageViewID.data.pv) - expect(JSON.parse(decodeURIComponent(bidRequests.data.iqid)).pcid).to.match(/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/) - expect(JSON.parse(decodeURIComponent(bidRequests.data.iqid)).pcidDate).to.match(/^[0-9]{13}$/) - expect(bidRequests.data.hfa).to.not.exist - expect(bidRequests.bidderRequests).to.eql(bidRequest); - expect(bidRequests.data.ref).to.equal('overrides_top_window_location'); - expect(['mobile', 'tablet', 'desktop']).to.contain(bidRequests.data.vp); - }) - - it('should return a properly formatted request with GDPR applies set to true', function () { - const bidRequests = spec.buildRequests(bidRequest, bidderRequests) - expect(bidRequests.url).to.equal('https://apex.go.sonobi.com/trinity.json') - expect(bidRequests.method).to.equal('POST') - expect(bidRequests.data.gdpr).to.equal('true') - expect(bidRequests.data.consent_string).to.equal(encodeURIComponent('BOJ/P2HOJ/P2HABABMAAAAAZ+A==')) - }) - - it('should return a properly formatted request with referer', function () { - bidRequest[0].params.referrer = '' - const bidRequests = spec.buildRequests(bidRequest, bidderRequests) - expect(bidRequests.data.ref).to.equal(encodeURIComponent('https://example.com')) - }) - - it('should return a properly formatted request with GDPR applies set to false', function () { - bidderRequests.gdprConsent.gdprApplies = false; - const bidRequests = spec.buildRequests(bidRequest, bidderRequests) - expect(bidRequests.url).to.equal('https://apex.go.sonobi.com/trinity.json') - expect(bidRequests.method).to.equal('POST') - expect(bidRequests.data.gdpr).to.equal('false') - expect(bidRequests.data.consent_string).to.equal(encodeURIComponent('BOJ/P2HOJ/P2HABABMAAAAAZ+A==')) - }) - it('should return a properly formatted request with GDPR applies set to false with no consent_string param', function () { - const bidderRequests = { - 'gdprConsent': { - 'consentString': undefined, - 'vendorData': {}, - 'gdprApplies': false - }, - 'refererInfo': { - 'numIframes': 0, - 'reachedTop': true, - 'page': 'https://example.com', - 'stack': ['https://example.com'] - } - }; - const bidRequests = spec.buildRequests(bidRequest, bidderRequests) - expect(bidRequests.url).to.equal('https://apex.go.sonobi.com/trinity.json') - expect(bidRequests.method).to.equal('POST') - expect(bidRequests.data.gdpr).to.equal('false') - expect(bidRequests.data).to.not.include.keys('consent_string') - }) - it('should return a properly formatted request with GDPR applies set to true with no consent_string param', function () { - const bidderRequests = { - 'gdprConsent': { - 'consentString': undefined, - 'vendorData': {}, - 'gdprApplies': true - }, - 'refererInfo': { - 'numIframes': 0, - 'reachedTop': true, - 'page': 'https://example.com', - 'stack': ['https://example.com'] - } - }; - const bidRequests = spec.buildRequests(bidRequest, bidderRequests) - expect(bidRequests.url).to.equal('https://apex.go.sonobi.com/trinity.json') - expect(bidRequests.method).to.equal('POST') - expect(bidRequests.data.gdpr).to.equal('true') - expect(bidRequests.data).to.not.include.keys('consent_string') - }) - it('should return a properly formatted request with hfa', function () { - bidRequest[0].params.hfa = 'hfakey' - bidRequest[1].params.hfa = 'hfakey' - const bidRequests = spec.buildRequests(bidRequest, bidderRequests) - expect(bidRequests.url).to.equal('https://apex.go.sonobi.com/trinity.json') - expect(bidRequests.method).to.equal('POST') - expect(bidRequests.data.ref).not.to.be.empty - expect(bidRequests.data.s).not.to.be.empty - expect(bidRequests.data.hfa).to.equal('hfakey') - }) - - it('should return a properly formatted request with experianRtidData and exexperianRtidKeypKey omitted from fpd', function () { - const bidRequests = spec.buildRequests(bidRequest, bidderRequests) - expect(bidRequests.data.fpd.indexOf('experianRtidData')).to.equal(-1); - expect(bidRequests.data.fpd.indexOf('exexperianRtidKeypKey')).to.equal(-1); - }); - - it('should return null if there is nothing to bid on', function () { - const bidRequests = spec.buildRequests([{ params: {} }], bidderRequests) - expect(bidRequests).to.equal(null); - }); - - it('should set ius as 0 if Sonobi cannot drop iframe pixels', function () { - userSync.canBidderRegisterSync.returns(false); - const bidRequests = spec.buildRequests(bidRequest, bidderRequests); - expect(bidRequests.data.ius).to.equal(encodeURIComponent(0)); - }); - - it('should set ius as 1 if Sonobi can drop iframe pixels', function () { - userSync.canBidderRegisterSync.returns(true); - const bidRequests = spec.buildRequests(bidRequest, bidderRequests); - expect(bidRequests.data.ius).to.equal(encodeURIComponent(1)); - }); - - it('should return a properly formatted request with schain defined', function () { - const bidRequests = spec.buildRequests(bidRequest, bidderRequests); - expect(JSON.parse(decodeURIComponent(bidRequests.data.schain))).to.deep.equal(bidRequest[0].ortb2.source.ext.schain) - }); - - it('should return a properly formatted request with eids as a JSON-encoded set of eids', function () { - bidRequest[0].userIdAsEids = [ - { - 'source': 'pubcid.org', - 'uids': [ - { - 'id': '97b1ff9b-6bf1-41fc-95de-acfd33dbb95a', - 'atype': 1 - } - ] - } - ]; - bidRequest[1].userIdAsEids = [ - { - 'source': 'pubcid.org', - 'uids': [ - { - 'id': '97b1ff9b-6bf1-41fc-95de-acfd33dbb95a', - 'atype': 1 - } - ] - } - ]; - const bidRequests = spec.buildRequests(bidRequest, bidderRequests); - expect(bidRequests.url).to.equal('https://apex.go.sonobi.com/trinity.json'); - expect(bidRequests.method).to.equal('POST'); - expect(bidRequests.data.ref).not.to.be.empty; - expect(bidRequests.data.s).not.to.be.empty; - expect(JSON.parse(decodeURIComponent(bidRequests.data.eids))).to.eql([ - { - 'source': 'pubcid.org', - 'uids': [ - { - 'id': '97b1ff9b-6bf1-41fc-95de-acfd33dbb95a', - 'atype': 1 - } - ] - } - ]); - }); - - it('should return a properly formatted request with the userid value omitted when the userId object is present on the bidRequest. ', function () { - bidRequest[0].userId = { 'pubcid': 'abcd-efg-0101', 'tdid': 'td-abcd-efg-0101', 'id5id': { 'uid': 'ID5-ZHMOrVeUVTUKgrZ-a2YGxeh5eS_pLzHCQGYOEAiTBQ', 'ext': { 'linkType': 2 } } }; - bidRequest[1].userId = { 'pubcid': 'abcd-efg-0101', 'tdid': 'td-abcd-efg-0101', 'id5id': { 'uid': 'ID5-ZHMOrVeUVTUKgrZ-a2YGxeh5eS_pLzHCQGYOEAiTBQ', 'ext': { 'linkType': 2 } } }; - const bidRequests = spec.buildRequests(bidRequest, bidderRequests); - expect(bidRequests.url).to.equal('https://apex.go.sonobi.com/trinity.json'); - expect(bidRequests.method).to.equal('POST'); - expect(bidRequests.data.ref).not.to.be.empty; - expect(bidRequests.data.s).not.to.be.empty; - expect(bidRequests.data.userid).to.be.undefined; - }); - - it('should return a properly formatted request with keywrods included as a csv of strings', function () { - const bidRequests = spec.buildRequests(bidRequest, bidderRequests); - expect(bidRequests.data.kw).to.equal(encodeURIComponent('sports,news,some_other_keyword')); - }); - - it('should return a properly formatted request with us_privacy included', function () { - const bidRequests = spec.buildRequests(bidRequest, bidderRequests); - expect(bidRequests.data.us_privacy).to.equal('someCCPAString'); - }); - - it('should make a request to the url defined in the bidder param', function () { - const bRequest = [ - { - ...bidRequest[0], - params: { - ...bidRequest[0].params, - bid_request_url: 'https://iad-2-apex.go.sonobi.com/trinity.json' - } - } - ]; - const bidRequests = spec.buildRequests(bRequest, bidderRequests); - expect(bidRequests.url).to.equal('https://iad-2-apex.go.sonobi.com/trinity.json'); - }); - }); - - describe('.interpretResponse', function () { - const bidRequests = { - 'method': 'POST', - 'url': 'https://apex.go.sonobi.com/trinity.json', - 'withCredentials': true, - 'data': { - 'key_maker': '{"30b31c1838de1f":"1a2b3c4d5e6f1a2b3c4d|300x250,300x600|f=1.25","/7780971/sparks_prebid_LB|30b31c1838de1e":"300x250,300x600"}', 'ref': 'https://localhost/', 's': '2474372d-c0ff-4f46-aef4-a173058403d9', 'pv': 'c9cfc207-cd83-4a01-b591-8bb29389d4b0' - }, - 'bidderRequests': [ - { - 'bidder': 'sonobi', - 'params': { - 'ad_unit': '/7780971/sparks_prebid_LB', - 'sizes': [[300, 250], [300, 600]], - 'floor': '1.25' - }, - 'adUnitCode': 'adunit-code-1', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1f' - }, - { - 'bidder': 'sonobi', - 'params': { - 'placement_id': '1a2b3c4d5e6f1a2b3c4d', - 'sizes': [[300, 250], [300, 600]] - }, - 'adUnitCode': 'adunit-code-2', - 'sizes': [[120, 600], [300, 600], [160, 600]], - 'bidId': '30b31c1838de1e' - }, - { - 'bidder': 'sonobi', - 'params': { - 'ad_unit': '/7780971/sparks_prebid_LB', - 'sizes': [[300, 250], [300, 600]] - }, - 'adUnitCode': 'adunit-code-3', - 'sizes': [[120, 600], [300, 600], [160, 600]], - 'bidId': '30b31c1838de1g' - }, - { - 'bidId': '30b31c1838de1zzzz', - 'adUnitCode': 'outstream-dom-id', - bidder: 'sonobi', - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 480] - } - }, - params: { - placement_id: '92e95368e86639dbd86d' - } - } - ] - }; - - const bidResponse = { - 'body': { - 'slots': { - '/7780971/sparks_prebid_LB|30b31c1838de1f': { - 'sbi_size': '300x600', - 'sbi_apoc': 'remnant', - 'sbi_crid': '1234abcd', - 'sbi_aid': '30292e432662bd5f86d90774b944b039', - 'sbi_mouse': 1.07, - 'sbi_adomain': 'sonobi.com' - }, - '30b31c1838de1e': { - 'sbi_size': '640x480', - 'sbi_apoc': 'remnant', - 'sbi_aid': '30292e432662bd5f86d90774b944b038', - 'sbi_mouse': 1.25, - 'sbi_dozer': 'dozerkey', - 'sbi_ct': 'video', - 'sbi_adomain': 'sonobi.com' - - }, - '/7780971/sparks_prebid_LB_OUTSTREAM|30b31c1838de1g': { - 'sbi_size': '640x480', - 'sbi_apoc': 'remnant', - 'sbi_crid': '1234abcd', - 'sbi_aid': '30292e432662bd5f86d90774b944b038', - 'sbi_mouse': 1.07, - 'sbi_adomain': 'sonobi.com' - - }, - '/7780971/sparks_prebid_LB|30b31c1838de1g': {}, - '30b31c1838de1zzzz': { - sbi_aid: 'force_1550072228_da1c5d030cb49150c5db8a2136175755', - sbi_apoc: 'premium', - sbi_ct: 'video', - sbi_curr: 'USD', - sbi_mouse: 1.25, - sbi_size: 'preroll', - 'sbi_crid': 'somecrid', - 'sbi_adomain': 'sonobi.com' - - } - - }, - 'sbi_dc': 'mco-1-', - 'sbi_px': [{ - 'code': 'so', - 'delay': 0, - 'url': 'https://example.com/pixel.png', - 'type': 'image' - }], - 'sbi_suid': 'af99f47a-e7b1-4791-ab32-34952d87c5a0', - } - }; - - const prebidResponse = [ - { - 'requestId': '30b31c1838de1f', - 'cpm': 1.07, - 'width': 300, - 'height': 600, - 'ad': ``, - 'ttl': 500, - 'creativeId': '1234abcd', - 'netRevenue': true, - 'currency': 'USD', - 'aid': '30292e432662bd5f86d90774b944b039', - meta: { - advertiserDomains: ['sonobi.com'] - } - }, - { - 'requestId': '30b31c1838de1e', - 'cpm': 1.25, - 'width': 640, - 'height': 480, - 'vastUrl': 'https://mco-1-apex.go.sonobi.com/vast.xml?vid=30292e432662bd5f86d90774b944b038&ref=https%3A%2F%2Flocalhost%2F', - 'ttl': 500, - 'creativeId': '30292e432662bd5f86d90774b944b038', - 'netRevenue': true, - 'currency': 'USD', - 'dealId': 'dozerkey', - 'aid': '30292e432662bd5f86d90774b944b038', - 'mediaType': 'video', - meta: { - advertiserDomains: ['sonobi.com'] - } - }, - { - 'requestId': '30b31c1838de1g', - 'cpm': 1.07, - 'width': 640, - 'height': 480, - 'ad': ``, - 'ttl': 500, - 'creativeId': '1234abcd', - 'netRevenue': true, - 'currency': 'USD', - 'aid': '30292e432662bd5f86d90774b944b038', - meta: { - advertiserDomains: ['sonobi.com'] - } - }, - { - 'requestId': '30b31c1838de1zzzz', - 'cpm': 1.25, - 'width': 640, - 'height': 480, - 'vastUrl': 'https://mco-1-apex.go.sonobi.com/vast.xml?vid=30292e432662bd5f86d90774b944b038&ref=https%3A%2F%2Flocalhost%2F', - 'ttl': 500, - 'creativeId': 'somecrid', - 'netRevenue': true, - 'currency': 'USD', - 'dealId': 'dozerkey', - 'aid': 'force_1550072228_da1c5d030cb49150c5db8a2136175755', - 'mediaType': 'video', - renderer: () => { }, - meta: { - advertiserDomains: ['sonobi.com'] - } - }, - ]; - - it('should map bidResponse to prebidResponse', function () { - const response = spec.interpretResponse(bidResponse, bidRequests); - response.forEach((resp, i) => { - expect(resp.requestId).to.equal(prebidResponse[i].requestId); - expect(resp.cpm).to.equal(prebidResponse[i].cpm); - - expect(resp.ttl).to.equal(prebidResponse[i].ttl); - expect(resp.creativeId).to.equal(prebidResponse[i].creativeId); - expect(resp.netRevenue).to.equal(prebidResponse[i].netRevenue); - expect(resp.currency).to.equal(prebidResponse[i].currency); - expect(resp.aid).to.equal(prebidResponse[i].aid); - if (resp.mediaType === 'video' && resp.renderer) { - expect(resp.vastUrl.indexOf('vast.xml')).to.be.greaterThan(0); - expect(resp.width).to.equal(prebidResponse[i].width); - expect(resp.height).to.equal(prebidResponse[i].height); - expect(resp.renderer).to.be.ok; - expect(resp.ad).to.equal(undefined); - } else if (resp.mediaType === 'video') { - expect(resp.vastUrl.indexOf('vast.xml')).to.be.greaterThan(0); - expect(resp.ad).to.be.undefined; - expect(resp.width).to.be.undefined; - expect(resp.height).to.be.undefined; - } else { - expect(resp.ad.indexOf('localhost')).to.be.greaterThan(0); - expect(resp.width).to.equal(prebidResponse[i].width); - expect(resp.height).to.equal(prebidResponse[i].height); - } - }); - }); - }); - - describe('.getUserSyncs', function () { - const bidResponse = [{ - 'body': { - 'sbi_px': [{ - 'code': 'so', - 'delay': 0, - 'url': 'https://pixel-test', - 'type': 'image' - }] - } - }]; - - it('should return one sync pixel', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, bidResponse)).to.deep.equal([{ - type: 'image', - url: 'https://pixel-test' - }]); - }) - it('should return an empty array when sync is enabled but there are no bidResponses', function () { - expect(spec.getUserSyncs({ pixelEnabled: true }, [])).to.have.length(0); - }) - - it('should return an empty array when sync is enabled but no sync pixel returned', function () { - const pixel = Object.assign({}, bidResponse); - delete pixel[0].body.sbi_px; - expect(spec.getUserSyncs({ pixelEnabled: true }, bidResponse)).to.have.length(0); - }) - - it('should return an empty array', function () { - expect(spec.getUserSyncs({ pixelEnabled: false }, bidResponse)).to.have.length(0); - expect(spec.getUserSyncs({ pixelEnabled: true }, [])).to.have.length(0); - }); - }) - describe('_getPlatform', function () { - it('should return mobile', function () { - expect(_getPlatform({ innerWidth: 767 })).to.equal('mobile') - }) - it('should return tablet', function () { - expect(_getPlatform({ innerWidth: 800 })).to.equal('tablet') - }) - it('should return desktop', function () { - expect(_getPlatform({ innerWidth: 1000 })).to.equal('desktop') - }) - }) -}) diff --git a/test/spec/modules/sovrnBidAdapter_spec.js b/test/spec/modules/sovrnBidAdapter_spec.js deleted file mode 100644 index 586087050..000000000 --- a/test/spec/modules/sovrnBidAdapter_spec.js +++ /dev/null @@ -1,1413 +0,0 @@ -import {expect} from 'chai' -import {spec} from 'modules/sovrnBidAdapter.js' -import {config} from 'src/config.js' -import * as utils from 'src/utils.js' - -const ENDPOINT = `https://ap.lijit.com/rtb/bid?src=$$REPO_AND_VERSION$$` - -const baseBidRequest = { - bidder: 'sovrn', - params: { - tagid: 403370 - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 250], - [300, 600] - ], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', -} -const baseBidderRequest = { - refererInfo: { - page: 'http://example.com/page.html', - domain: 'example.com', - } -} - -describe('sovrnBidAdapter', function() { - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(baseBidRequest)).to.equal(true) - }) - - it('should return false when tagid not passed correctly', function () { - const bidRequest = { - ...baseBidRequest, - params: { - ...baseBidRequest.params, - tagid: 'ABCD' - }, - } - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false) - }) - - it('should return false when require params are not passed', function () { - const bidRequest = { - ...baseBidRequest, - params: {} - } - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false) - }) - - it('should return false when require video params are not passed', function () { - const bidRequest = { - ...baseBidRequest, - mediaTypes: { - 'video': { - } - } - } - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false) - }) - - it('should return true when minduration is not passed', function() { - const width = 300 - const height = 250 - const mimes = ['video/mp4', 'application/javascript'] - const protocols = [2, 5] - const maxduration = 60 - const startdelay = 0 - const videoBidRequest = { - ...baseBidRequest, - mediaTypes: { - video: { - mimes, - protocols, - playerSize: [[width, height], [360, 240]], - maxduration, - startdelay - } - } - } - - expect(spec.isBidRequestValid(videoBidRequest)).to.equal(true) - }) - }) - - describe('buildRequests', function () { - describe('basic bid parameters', function() { - const request = spec.buildRequests([baseBidRequest], baseBidderRequest) - const payload = JSON.parse(request.data) - - it('sends bid request to our endpoint via POST', function () { - expect(request.method).to.equal('POST') - }) - - it('attaches source and version to endpoint URL as query params', function () { - expect(request.url).to.equal(ENDPOINT) - }) - - it('sets the proper banner object', function() { - const bannerBidRequest = { - ...baseBidRequest, - mediaTypes: { - banner: {} - } - } - const request = spec.buildRequests([bannerBidRequest], baseBidderRequest) - const payload = JSON.parse(request.data) - const impression = payload.imp[0] - - expect(impression.banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]) - expect(impression.banner.w).to.equal(1) - expect(impression.banner.h).to.equal(1) - }) - - it('sets the proper video object with sizes defined', function() { - const width = 300 - const height = 250 - const mimes = ['video/mp4', 'application/javascript'] - const protocols = [2, 5] - const minduration = 5 - const maxduration = 60 - const startdelay = 0 - const videoBidRequest = { - ...baseBidRequest, - mediaTypes: { - video: { - mimes, - protocols, - playerSize: [[width, height], [360, 240]], - minduration, - maxduration, - startdelay - } - } - } - const request = spec.buildRequests([videoBidRequest], baseBidderRequest) - const payload = JSON.parse(request.data) - const impression = payload.imp[0] - - expect(impression.video.w).to.equal(width) - expect(impression.video.h).to.equal(height) - expect(impression.video.mimes).to.have.same.members(mimes) - expect(impression.video.protocols).to.have.same.members(protocols) - expect(impression.video.minduration).to.equal(minduration) - expect(impression.video.maxduration).to.equal(maxduration) - expect(impression.video.startdelay).to.equal(startdelay) - }) - - it('sets the proper video object wihtout sizes defined but video sizes defined', function() { - const width = 360 - const height = 240 - const mimes = ['video/mp4', 'application/javascript'] - const protocols = [2, 5] - const minduration = 5 - const maxduration = 60 - const startdelay = 0 - const modifiedBidRequest = baseBidRequest; - delete modifiedBidRequest.sizes; - const videoBidRequest = { - ...modifiedBidRequest, - mediaTypes: { - video: { - mimes, - protocols, - playerSize: [[width, height], [360, 240]], - minduration, - maxduration, - startdelay - } - } - } - const request = spec.buildRequests([videoBidRequest], baseBidderRequest) - const payload = JSON.parse(request.data) - const impression = payload.imp[0] - - expect(impression.video.w).to.equal(width) - expect(impression.video.h).to.equal(height) - expect(impression.video.mimes).to.have.same.members(mimes) - expect(impression.video.protocols).to.have.same.members(protocols) - expect(impression.video.minduration).to.equal(minduration) - expect(impression.video.maxduration).to.equal(maxduration) - expect(impression.video.startdelay).to.equal(startdelay) - }) - - it('gets correct site info', function() { - expect(payload.site.page).to.equal('http://example.com/page.html') - expect(payload.site.domain).to.equal('example.com') - }) - - it('sets correct timeout', function() { - const bidderRequest = { - ...baseBidderRequest, - bidderCode: 'sovrn', - auctionId: '1d1a030790a475', - bidderRequestId: '22edbae2733bf6', - timeout: 3000, - bids: [baseBidRequest] - } - const payload = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - expect(payload.tmax).to.equal(3000) - }) - - it('forwards auction level tid', function() { - const bidderRequest = { - ...baseBidderRequest, - ortb2: { - source: { - tid: '1d1a030790a475' - } - }, - bids: [baseBidRequest] - } - - const payload = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - expect(payload.source?.tid).to.equal('1d1a030790a475') - }) - - it('forwards impression level tid', function() { - const bidRequest = { - ...baseBidRequest, - ortb2Imp: { - ext: { - tid: '1a2c032473f4983' - } - }, - } - - const bidderRequest = { - ...baseBidderRequest, - bids: [bidRequest] - } - - const payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest).data) - expect(payload.imp[0]?.ext?.tid).to.equal('1a2c032473f4983') - }) - - it('when FLEDGE is enabled, should send ortb2imp.ext.ae', function () { - const bidderRequest = { - ...baseBidderRequest, - paapi: {enabled: true} - } - const bidRequest = { - ...baseBidRequest, - ortb2Imp: { - ext: { - ae: 1 - } - }, - } - const payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest).data) - expect(payload.imp[0].ext.ae).to.equal(1) - }) - - it('when FLEDGE is not enabled, should not send ortb2imp.ext.ae', function () { - const bidRequest = { - ...baseBidRequest, - ortb2Imp: { - ext: { - ae: 1 - } - }, - } - const payload = JSON.parse(spec.buildRequests([bidRequest], baseBidderRequest).data) - expect(payload.imp[0].ext.ae).to.be.undefined - }) - - it('when FLEDGE is enabled, but env is malformed, should not send ortb2imp.ext.ae', function () { - const bidderRequest = { - ...baseBidderRequest, - paapi: { - enabled: true - } - } - const bidRequest = { - ...baseBidRequest, - ortb2Imp: { - ext: { - ae: 'malformed' - } - }, - } - const payload = JSON.parse(spec.buildRequests([bidRequest], bidderRequest).data) - expect(payload.imp[0].ext.ae).to.be.undefined - }) - - it('includes the ad unit code in the request', function() { - const impression = payload.imp[0] - expect(impression.adunitcode).to.equal('adunit-code') - }) - - it('converts tagid to string', function () { - expect(request.data).to.contain('"tagid":"403370"') - }) - }) - - it('accepts a single array as a size', function() { - const singleSizeBidRequest = { - ...baseBidRequest, - params: { - iv: 'vet' - }, - sizes: [300, 250], - mediaTypes: { - banner: {} - }, - } - const request = spec.buildRequests([singleSizeBidRequest], baseBidderRequest) - const payload = JSON.parse(request.data) - const impression = payload.imp[0] - - expect(impression.banner.format).to.deep.equal([{w: 300, h: 250}]) - expect(impression.banner.w).to.equal(1) - expect(impression.banner.h).to.equal(1) - }) - - it('sends \'iv\' as query param if present', function () { - const ivBidRequest = { - ...baseBidRequest, - params: { - iv: 'vet' - } - } - const request = spec.buildRequests([ivBidRequest], baseBidderRequest) - - expect(request.url).to.contain('iv=vet') - }) - - it('sends gdpr info if exists', function () { - const bidderRequest = { - ...baseBidderRequest, - bidderCode: 'sovrn', - auctionId: '1d1a030790a475', - bidderRequestId: '22edbae2733bf6', - timeout: 3000, - gdprConsent: { - consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==', - gdprApplies: true - }, - bids: [baseBidRequest] - } - const { regs, user } = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - - expect(regs.ext.gdpr).to.exist.and.to.be.a('number') - expect(regs.ext.gdpr).to.equal(1) - expect(user.ext.consent).to.exist.and.to.be.a('string') - expect(user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString) - }) - - it('should send us_privacy if bidderRequest has a value for uspConsent', function () { - const bidderRequest = { - ...baseBidderRequest, - bidderCode: 'sovrn', - auctionId: '1d1a030790a475', - bidderRequestId: '22edbae2733bf6', - timeout: 3000, - uspConsent: '1NYN', - bids: [baseBidRequest] - } - const data = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - - expect(data.regs.ext['us_privacy']).to.equal(bidderRequest.uspConsent) - }) - - it('should not set coppa when coppa is undefined', function () { - const bidderRequest = { - ...baseBidderRequest, - bidderCode: 'sovrn', - auctionId: '1d1a030790a475', - bidderRequestId: '22edbae2733bf6', - timeout: 3000, - bids: [baseBidRequest], - gdprConsent: { - consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==', - gdprApplies: true - }, - } - const {regs} = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - expect(regs.coppa).to.be.undefined - }) - - it('should set coppa to 1 when coppa is provided with value true', function () { - const bidderRequest = { - ...baseBidderRequest, - ortb2: { - regs: { - coppa: true - } - }, - bidderCode: 'sovrn', - auctionId: '1d1a030790a475', - bidderRequestId: '22edbae2733bf6', - timeout: 3000, - bids: [baseBidRequest] - } - const {regs} = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - expect(regs.coppa).to.equal(1) - }) - - it('should not set bcat array when ortb2 bcat is undefined', function () { - const bidderRequest = { - ...baseBidderRequest, - bidderCode: 'sovrn', - auctionId: '1d1a030790a475', - bidderRequestId: '22edbae2733bf6', - timeout: 3000, - bids: [baseBidRequest], - gdprConsent: { - consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==', - gdprApplies: true - }, - } - const {bcat} = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - expect(bcat).to.be.undefined - }) - - it('should set bcat array when valid ortb2 bcat is provided', function () { - const bidderRequest = { - ...baseBidderRequest, - ortb2: { - bcat: ['IAB1-1', 'IAB1-2'] - }, - bidderCode: 'sovrn', - auctionId: '1d1a030790a475', - bidderRequestId: '22edbae2733bf6', - timeout: 3000, - bids: [baseBidRequest] - } - const {bcat} = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - expect(bcat).to.exist.and.to.be.a('array') - expect(bcat).to.deep.equal(['IAB1-1', 'IAB1-2']) - }) - - it('should send gpp info in OpenRTB 2.6 location when gppConsent defined', function () { - const bidderRequest = { - ...baseBidderRequest, - bidderCode: 'sovrn', - auctionId: '1d1a030790a475', - bidderRequestId: '22edbae2733bf6', - timeout: 3000, - gppConsent: { - gppString: 'gppstring', - applicableSections: [8] - }, - bids: [baseBidRequest] - } - const { regs } = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - expect(regs.gpp).to.equal('gppstring') - expect(regs.gpp_sid).to.be.an('array') - expect(regs.gpp_sid).to.include(8) - }) - - it('should add ORTB2 device data to the request', function () { - const bidderRequest = { - ...baseBidderRequest, - ortb2: { - device: { - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - }, - }, - }; - - const request = spec.buildRequests([baseBidRequest], bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.device).to.deep.equal(bidderRequest.ortb2.device); - }); - - it('should not send gpp info when gppConsent is not defined', function () { - const bidderRequest = { - ...baseBidderRequest, - bidderCode: 'sovrn', - auctionId: '1d1a030790a475', - bidderRequestId: '22edbae2733bf6', - timeout: 3000, - bids: [baseBidRequest], - gdprConsent: { - consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==', - gdprApplies: true - }, - } - const { regs } = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - expect(regs.gpp).to.be.undefined - }) - - it('should send gdpr info even when gppConsent defined', function () { - const bidderRequest = { - ...baseBidderRequest, - bidderCode: 'sovrn', - auctionId: '1d1a030790a475', - bidderRequestId: '22edbae2733bf6', - timeout: 3000, - gdprConsent: { - consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==', - gdprApplies: true - }, - gppConsent: { - gppString: 'gppstring', - applicableSections: [8] - }, - bids: [baseBidRequest] - } - - const { regs, user } = JSON.parse(spec.buildRequests([baseBidRequest], bidderRequest).data) - - expect(regs.ext.gdpr).to.exist.and.to.be.a('number') - expect(regs.ext.gdpr).to.equal(1) - expect(user.ext.consent).to.exist.and.to.be.a('string') - expect(user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString) - expect(regs.gpp).to.equal('gppstring') - expect(regs.gpp_sid).to.be.an('array') - expect(regs.gpp_sid).to.include(8) - }) - - it('should add schain if present', function() { - const schainRequest = { - ...baseBidRequest, - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'directseller.com', - sid: '00001', - rid: 'BidRequest1', - hp: 1 - } - ] - } - } - } - } - } - const schainRequests = [schainRequest, baseBidRequest] - const data = JSON.parse(spec.buildRequests(schainRequests, baseBidderRequest).data) - - expect(data.source.ext.schain.nodes.length).to.equal(1) - }) - - it('should add eids to the bid request', function() { - const criteoIdRequest = { - ...baseBidRequest, - userIdAsEids: [ - { - source: 'criteo.com', - uids: [ - { - atype: 1, - id: 'A_CRITEO_ID' - } - ] - }, - { - source: 'adserver.org', - uids: [ - { - atype: 1, - ext: { - rtiPartner: 'TDID' - }, - id: 'SOMESORTOFID' - } - ] - } - ] - }; - const criteoIdRequests = [criteoIdRequest, baseBidRequest] - const ext = JSON.parse(spec.buildRequests(criteoIdRequests, baseBidderRequest).data).user.ext - const firstEID = ext.eids[0] - const secondEID = ext.eids[1] - - expect(firstEID.source).to.equal('criteo.com') - expect(firstEID.uids[0].id).to.equal('A_CRITEO_ID') - expect(firstEID.uids[0].atype).to.equal(1) - expect(secondEID.source).to.equal('adserver.org') - expect(secondEID.uids[0].id).to.equal('SOMESORTOFID') - expect(secondEID.uids[0].ext.rtiPartner).to.equal('TDID') - expect(secondEID.uids[0].atype).to.equal(1) - expect(ext.prebid_criteoid).to.equal('A_CRITEO_ID') - }) - - it('should ignore empty segments', function() { - const request = spec.buildRequests([baseBidRequest], baseBidderRequest) - const payload = JSON.parse(request.data) - - expect(payload.imp[0].ext).to.be.undefined - }) - - it('should pass the segments param value as trimmed deal ids array', function() { - const segmentsRequest = { - ...baseBidRequest, - params: { - segments: ' test1,test2 ' - } - } - const request = spec.buildRequests([segmentsRequest], baseBidderRequest) - const deals = JSON.parse(request.data).imp[0].ext.deals - - expect(deals[0]).to.equal('test1') - expect(deals[1]).to.equal('test2') - }) - it('should use the floor provided from the floor module if present', function() { - const floorBid = { - ...baseBidRequest, - getFloor: () => ({currency: 'USD', floor: 1.10}), - params: { - tagid: 1234, - bidfloor: 2.00 - } - } - const request = spec.buildRequests([floorBid], baseBidderRequest) - const payload = JSON.parse(request.data) - - expect(payload.imp[0].bidfloor).to.equal(1.10) - }) - it('should use the floor from the param if there is no floor from the floor module', function() { - const floorBid = { - ...baseBidRequest, - getFloor: () => ({}) - } - floorBid.params = { - tagid: 1234, - bidfloor: 2.00 - } - const request = spec.buildRequests([floorBid], baseBidderRequest) - const impression = JSON.parse(request.data).imp[0] - - expect(impression.bidfloor).to.equal(2.00) - }) - it('floor should be undefined if there is no floor from the floor module and params', function() { - const floorBid = { - ...baseBidRequest - } - floorBid.params = { - tagid: 1234 - } - const request = spec.buildRequests([floorBid], baseBidderRequest) - const impression = JSON.parse(request.data).imp[0] - - expect(impression.bidfloor).to.be.undefined - }) - it('floor should be undefined if there is incorrect floor value from the floor module', function() { - const floorBid = { - ...baseBidRequest, - getFloor: () => ({currency: 'USD', floor: 'incorrect_value'}), - params: { - tagid: 1234 - } - } - const request = spec.buildRequests([floorBid], baseBidderRequest) - const impression = JSON.parse(request.data).imp[0] - - expect(impression.bidfloor).to.be.undefined - }) - it('floor should be undefined if there is incorrect floor value from the params', function() { - const floorBid = { - ...baseBidRequest, - getFloor: () => ({}) - } - floorBid.params = { - tagid: 1234, - bidfloor: 'incorrect_value' - } - const request = spec.buildRequests([floorBid], baseBidderRequest) - const impression = JSON.parse(request.data).imp[0] - - expect(impression.bidfloor).to.be.undefined - }) - describe('First Party Data', function () { - it('should provide first party data if provided', function() { - const ortb2 = { - site: { - keywords: 'test keyword' - }, - user: { - data: 'some user data' - } - }; - - const request = spec.buildRequests([baseBidRequest], {...baseBidderRequest, ortb2}) - const { user, site } = JSON.parse(request.data) - - expect(user.data).to.equal('some user data') - expect(site.keywords).to.equal('test keyword') - expect(site.page).to.equal('http://example.com/page.html') - expect(site.domain).to.equal('example.com') - }) - it('should append impression first party data', function () { - const fpdBidRequest = { - ...baseBidRequest, - ortb2Imp: { - ext: { - data: { - pbadslot: 'homepage-top-rect', - adUnitSpecificAttribute: '123' - } - } - } - } - const request = spec.buildRequests([fpdBidRequest], baseBidderRequest) - const payload = JSON.parse(request.data) - - expect(payload.imp[0].ext.data.pbadslot).to.equal('homepage-top-rect') - expect(payload.imp[0].ext.data.adUnitSpecificAttribute).to.equal('123') - }) - it('should not overwrite deals when impression fpd is present', function() { - const fpdBid = { - ...baseBidRequest, - params: { - segments: 'seg1, seg2' - }, - ortb2Imp: { - ext: { - data: { - pbadslot: 'homepage-top-rect', - adUnitSpecificAttribute: '123' - } - } - } - } - const request = spec.buildRequests([fpdBid], baseBidderRequest) - const impression = JSON.parse(request.data).imp[0] - - expect(impression.ext.data.pbadslot).to.equal('homepage-top-rect') - expect(impression.ext.data.adUnitSpecificAttribute).to.equal('123') - expect(impression.ext.deals).to.deep.equal(['seg1', 'seg2']) - }) - }) - }) - - describe('interpretResponse', function () { - let response - const baseResponse = { - requestId: '263c448586f5a1', - cpm: 0.45882675, - width: 728, - height: 90, - creativeId: 'creativelycreatedcreativecreative', - dealId: null, - currency: 'USD', - netRevenue: true, - mediaType: 'banner', - ttl: 90, - meta: { advertiserDomains: [] }, - ad: decodeURIComponent(``), - } - const videoBid = { - id: 'a_403370_332fdb9b064040ddbec05891bd13ab28', - crid: 'creativelycreatedcreativecreative', - impid: '263c448586f5a1', - price: 0.45882675, - nurl: '', - adm: 'key%3Dvalue', - h: 480, - w: 640, - mtype: 2 - } - const bannerBid = { - id: 'a_403370_332fdb9b064040ddbec05891bd13ab28', - crid: 'creativelycreatedcreativecreative', - impid: '263c448586f5a1', - price: 0.45882675, - nurl: '', - adm: '', - h: 90, - w: 728, - mtype: 1 - } - - beforeEach(function () { - response = { - body: { - id: '37386aade21a71', - seatbid: [{ - bid: [{ - ...bannerBid - }] - }] - } - } - }) - - it('Should return the bid response of correct type when nurl is missing', function () { - const expectedResponse = { - requestId: '263c448586f5a1', - cpm: 0.45882675, - width: 728, - height: 90, - creativeId: 'creativelycreatedcreativecreative', - dealId: null, - currency: 'USD', - netRevenue: true, - mediaType: 'banner', - ttl: 60000, - meta: { advertiserDomains: [] }, - ad: decodeURIComponent(``) - } - - response = { - body: { - id: '37386aade21a71', - seatbid: [{ - bid: [{ - ...bannerBid, - nurl: '' - }] - }] - } - } - - const result = spec.interpretResponse(response) - - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse)) - }) - - it('Should return the bid response of correct type when nurl is present', function () { - const expectedResponse = { - requestId: '263c448586f5a1', - cpm: 0.45882675, - width: 728, - height: 90, - creativeId: 'creativelycreatedcreativecreative', - dealId: null, - currency: 'USD', - netRevenue: true, - mediaType: 'banner', - ttl: 60000, - meta: { advertiserDomains: [] }, - ad: decodeURIComponent(`>`) - } - - response = { - body: { - id: '37386aade21a71', - seatbid: [{ - bid: [{ - ...bannerBid - }] - }] - } - } - - const result = spec.interpretResponse(response) - - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse)) - }) - - it('should get the correct bid response', function () { - const expectedResponse = { - requestId: '263c448586f5a1', - cpm: 0.45882675, - width: 728, - height: 90, - creativeId: 'creativelycreatedcreativecreative', - dealId: null, - currency: 'USD', - netRevenue: true, - mediaType: 'banner', - ttl: 60000, - meta: { advertiserDomains: [] }, - ad: decodeURIComponent(`>`) - } - const result = spec.interpretResponse(response) - - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse)) - }) - - it('crid should default to the bid id if not on the response', function () { - delete response.body.seatbid[0].bid[0].crid - - const expectedResponse = { - ...baseResponse, - creativeId: response.body.seatbid[0].bid[0].id, - ad: decodeURIComponent(``), - } - const result = spec.interpretResponse(response) - - expect(result[0]).to.deep.equal(expectedResponse) - }) - - it('should get correct bid response when dealId is passed', function () { - response.body.seatbid[0].bid[0].dealid = 'baking' - const expectedResponse = { - ...baseResponse, - dealId: 'baking', - } - const result = spec.interpretResponse(response) - - expect(result[0]).to.deep.equal(expectedResponse) - }) - - it('should get correct bid response when ttl is set', function () { - response.body.seatbid[0].bid[0].ext = { ttl: 480 } - - const expectedResponse = { - ...baseResponse, - ttl: 480, - } - const result = spec.interpretResponse(response) - - expect(result[0]).to.deep.equal(expectedResponse) - }) - - it('handles empty bid response', function () { - const response = { - body: { - id: '37386aade21a71', - seatbid: [] - } - } - const result = spec.interpretResponse(response) - - expect(result.length).to.equal(0) - }) - - it('should get the correct bid response with 2 different bids', function () { - const expectedVideoResponse = { - ...baseResponse, - vastXml: decodeURIComponent(videoBid.adm) - } - delete expectedVideoResponse.ad - - const expectedBannerResponse = { - ...baseResponse - } - - response.body.seatbid = [{ bid: [bannerBid] }, { bid: [videoBid] }] - const result = spec.interpretResponse(response) - - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedBannerResponse)) - expect(Object.keys(result[1])).to.deep.equal(Object.keys(expectedVideoResponse)) - }) - - it('should get the correct bid response with 2 seatbid items', function () { - const expectedResponse = { - ...baseResponse - } - response.body.seatbid = [response.body.seatbid[0], response.body.seatbid[0]] - - const result = spec.interpretResponse(response) - - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse)) - expect(Object.keys(result[1])).to.deep.equal(Object.keys(expectedResponse)) - }) - }) - - describe('fledge response', function () { - const fledgeResponse = { - body: { - id: '37386aade21a71', - seatbid: [{ - bid: [{ - id: 'a_403370_332fdb9b064040ddbec05891bd13ab28', - crid: 'creativelycreatedcreativecreative', - impid: '263c448586f5a1', - price: 0.45882675, - nurl: '', - adm: '', - h: 90, - w: 728 - }] - }], - ext: { - seller: 'seller.lijit.com', - decisionLogicUrl: 'https://decision.lijit.com', - igbid: [{ - impid: 'test_imp_id', - igbuyer: [{ - igdomain: 'ap.lijit.com', - buyerdata: { - base_bid_micros: 0.1, - use_bid_multiplier: true, - multiplier: '1.3' - } - }, { - igdomain: 'buyer2.com', - buyerdata: {} - }, { - igdomain: 'buyer3.com', - buyerdata: {} - }] - }, { - impid: 'test_imp_id_2', - igbuyer: [{ - igdomain: 'ap2.lijit.com', - buyerdata: { - base_bid_micros: '0.2', - } - }] - }, { - impid: '', - igbuyer: [{ - igdomain: 'ap3.lijit.com', - buyerdata: { - base_bid_micros: '0.3', - } - }] - }, { - impid: 'test_imp_id_3', - igbuyer: [{ - igdomain: '', - buyerdata: { - base_bid_micros: '0.3', - } - }] - }, { - impid: 'test_imp_id_4', - igbuyer: [] - }] - } - } - } - const emptyFledgeResponse = { - body: { - id: '37386aade21a71', - seatbid: [{ - bid: [{ - id: 'a_403370_332fdb9b064040ddbec05891bd13ab28', - crid: 'creativelycreatedcreativecreative', - impid: '263c448586f5a1', - price: 0.45882675, - nurl: '', - adm: '', - h: 90, - w: 728 - }] - }], - ext: { - igbid: { - } - } - } - } - const expectedResponse = { - requestId: '263c448586f5a1', - cpm: 0.45882675, - width: 728, - height: 90, - creativeId: 'creativelycreatedcreativecreative', - dealId: null, - currency: 'USD', - netRevenue: true, - mediaType: 'banner', - ttl: 60000, - meta: { advertiserDomains: [] }, - ad: decodeURIComponent(`>`) - } - const expectedFledgeResponse = [ - { - bidId: 'test_imp_id', - config: { - seller: 'seller.lijit.com', - decisionLogicUrl: 'https://decision.lijit.com', - sellerTimeout: undefined, - auctionSignals: {}, - interestGroupBuyers: ['ap.lijit.com', 'buyer2.com', 'buyer3.com'], - perBuyerSignals: { - 'ap.lijit.com': { - base_bid_micros: 0.1, - use_bid_multiplier: true, - multiplier: '1.3' - }, - 'buyer2.com': {}, - 'buyer3.com': {} - } - } - }, - { - bidId: 'test_imp_id_2', - config: { - seller: 'seller.lijit.com', - decisionLogicUrl: 'https://decision.lijit.com', - sellerTimeout: undefined, - auctionSignals: {}, - interestGroupBuyers: ['ap2.lijit.com'], - perBuyerSignals: { - 'ap2.lijit.com': { - base_bid_micros: '0.2', - } - } - } - } - ] - - it('should return valid fledge auction configs alongside bids', function () { - const result = spec.interpretResponse(fledgeResponse) - expect(result).to.have.property('bids') - expect(result).to.have.property('paapi') - expect(result.paapi.length).to.equal(2) - expect(result.paapi).to.deep.equal(expectedFledgeResponse) - }) - it('should ignore empty fledge auction configs array', function () { - const result = spec.interpretResponse(emptyFledgeResponse) - expect(result.length).to.equal(1) - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse)) - }) - }) - - describe('interpretResponse video', function () { - let videoResponse - const bidAdm = 'key%3Dvalue' - const decodedBidAdm = decodeURIComponent(bidAdm) - const baseVideoResponse = { - requestId: '263c448586f5a1', - cpm: 0.45882675, - width: 640, - height: 480, - creativeId: 'creativelycreatedcreativecreative', - dealId: null, - currency: 'USD', - netRevenue: true, - mediaType: 'video', - ttl: 90, - meta: { advertiserDomains: [] }, - vastXml: decodedBidAdm - } - - beforeEach(function () { - videoResponse = { - body: { - id: '37386aade21a71', - seatbid: [{ - bid: [{ - id: 'a_403370_332fdb9b064040ddbec05891bd13ab28', - crid: 'creativelycreatedcreativecreative', - impid: '263c448586f5a1', - price: 0.45882675, - nurl: '', - adm: bidAdm, - h: 480, - w: 640, - mtype: 2 - }] - }] - } - } - }) - - it('should get the correct bid response', function () { - const expectedResponse = { - ...baseVideoResponse, - ttl: 60000, - } - const result = spec.interpretResponse(videoResponse) - - expect(result[0]).to.have.deep.keys(expectedResponse) - }) - - it('crid should default to the bid id if not on the response', function () { - delete videoResponse.body.seatbid[0].bid[0].crid - - const expectedResponse = { - ...baseVideoResponse, - creativeId: videoResponse.body.seatbid[0].bid[0].id, - } - const result = spec.interpretResponse(videoResponse) - - expect(result[0]).to.deep.equal(expectedResponse) - }) - - it('should get correct bid response when dealId is passed', function () { - videoResponse.body.seatbid[0].bid[0].dealid = 'baking' - const expectedResponse = { - ...baseVideoResponse, - dealId: 'baking', - } - const result = spec.interpretResponse(videoResponse) - - expect(result[0]).to.deep.equal(expectedResponse) - }) - - it('should get correct bid response when ttl is set', function () { - videoResponse.body.seatbid[0].bid[0].ext = { 'ttl': 480 } - - const expectedResponse = { - ...baseVideoResponse, - ttl: 480, - } - const result = spec.interpretResponse(videoResponse) - - expect(result[0]).to.deep.equal(expectedResponse) - }) - - it('handles empty bid response', function () { - const response = { - body: { - id: '37386aade21a71', - seatbid: [] - } - } - const result = spec.interpretResponse(response) - - expect(result.length).to.equal(0) - }) - }) - - describe('getUserSyncs ', function() { - const syncOptions = { iframeEnabled: true, pixelEnabled: false } - const iframeDisabledSyncOptions = { iframeEnabled: false, pixelEnabled: false } - const serverResponse = [ - { - body: { - id: '546956d68c757f', - seatbid: [ - { - bid: [ - { - id: 'a_448326_16c2ada014224bee815a90d2248322f5', - impid: '2a3826aae345f4', - price: 1.0099999904632568, - nurl: 'http://localhost/rtb/impression?bannerid=220958&campaignid=3890&rtb_tid=15588614-75d2-40ab-b27e-13d2127b3c2e&rpid=1295&seatid=seat1&zoneid=448326&cb=26900712&tid=a_448326_16c2ada014224bee815a90d2248322f5', - adm: 'yo a creative', - crid: 'cridprebidrtb', - w: 160, - h: 600 - }, - { - id: 'a_430392_beac4c1515da4576acf6cb9c5340b40c', - impid: '3cf96fd26ed4c5', - price: 1.0099999904632568, - nurl: 'http://localhost/rtb/impression?bannerid=220957&campaignid=3890&rtb_tid=5bc0e68b-3492-448d-a6f9-26fa3fd0b646&rpid=1295&seatid=seat1&zoneid=430392&cb=62735099&tid=a_430392_beac4c1515da4576acf6cb9c5340b40c', - adm: 'yo a creative', - crid: 'cridprebidrtb', - w: 300, - h: 250 - }, - ] - } - ], - ext: { - iid: 13487408, - sync: { - pixels: [ - { - url: 'http://idprovider1.com' - }, - { - url: 'http://idprovider2.com' - } - ] - } - } - }, - headers: {} - } - ] - - it('should return if iid present on server response & iframe syncs enabled', function() { - const expectedReturnStatement = { - type: 'iframe', - url: 'https://ce.lijit.com/beacon?informer=13487408', - } - const returnStatement = spec.getUserSyncs(syncOptions, serverResponse) - - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement) - }) - - it('should include gdpr consent string if present', function() { - const gdprConsent = { - gdprApplies: 1, - consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==' - } - const expectedReturnStatement = { - type: 'iframe', - url: `https://ce.lijit.com/beacon?gdpr_consent=${gdprConsent.consentString}&informer=13487408`, - } - - const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent, '', null) - - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement) - }) - - it('should include us privacy string if present', function() { - const uspString = '1NYN' - const expectedReturnStatement = { - type: 'iframe', - url: `https://ce.lijit.com/beacon?us_privacy=${uspString}&informer=13487408`, - } - - const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, null, uspString, null) - - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement) - }) - - it('should include gpp consent string if present', function() { - const gppConsent = { - applicableSections: [1, 2], - gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN' - } - const expectedReturnStatement = { - type: 'iframe', - url: `https://ce.lijit.com/beacon?gpp=${gppConsent.gppString}&gpp_sid=${gppConsent.applicableSections}&informer=13487408`, - } - - const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, null, '', gppConsent) - - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement) - }) - - it('should include all privacy strings if present', function() { - const gdprConsent = { - gdprApplies: 1, - consentString: 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A==' - } - const uspString = '1NYN' - const gppConsent = { - applicableSections: [1, 2], - gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN' - } - - const expectedReturnStatement = { - type: 'iframe', - url: `https://ce.lijit.com/beacon?gdpr_consent=${gdprConsent.consentString}&us_privacy=${uspString}&gpp=${gppConsent.gppString}&gpp_sid=${gppConsent.applicableSections}&informer=13487408`, - } - - const returnStatement = spec.getUserSyncs(syncOptions, serverResponse, gdprConsent, uspString, gppConsent) - - expect(returnStatement[0]).to.deep.equal(expectedReturnStatement) - }) - - it('should not return if iid missing on server response', function() { - const returnStatement = spec.getUserSyncs(syncOptions, []) - - expect(returnStatement).to.be.empty - }) - - it('should not return if iframe syncs disabled', function() { - const returnStatement = spec.getUserSyncs(iframeDisabledSyncOptions, serverResponse) - - expect(returnStatement).to.be.empty - }) - - it('should include pixel syncs', function() { - const pixelEnabledOptions = { iframeEnabled: false, pixelEnabled: true } - const otherResponce = { - ...serverResponse, - body: { - ...serverResponse.body, - ext: { - iid: 13487408, - sync: { - pixels: [ - { - url: 'http://idprovider3.com' - }, - { - url: 'http://idprovider4.com' - } - ] - } - } - } - } - - const returnStatement = spec.getUserSyncs(pixelEnabledOptions, [...serverResponse, otherResponce]) - - expect(returnStatement.length).to.equal(4) - expect(returnStatement).to.deep.include.members([ - { type: 'image', url: 'http://idprovider1.com' }, - { type: 'image', url: 'http://idprovider2.com' }, - { type: 'image', url: 'http://idprovider3.com' }, - { type: 'image', url: 'http://idprovider4.com' } - ]) - }) - }) - - describe('prebid 3 upgrade', function() { - const bidRequest = { - ...baseBidRequest, - params: { - tagid: '403370' - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ] - } - }, - } - const request = spec.buildRequests([bidRequest], baseBidderRequest) - const payload = JSON.parse(request.data) - - it('gets sizes from mediaTypes.banner', function() { - expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]) - expect(payload.imp[0].banner.w).to.equal(1) - expect(payload.imp[0].banner.h).to.equal(1) - }) - - it('gets correct site info', function() { - expect(payload.site.page).to.equal('http://example.com/page.html') - expect(payload.site.domain).to.equal('example.com') - }) - }) -}) diff --git a/test/spec/modules/sparteoBidAdapter_spec.js b/test/spec/modules/sparteoBidAdapter_spec.js deleted file mode 100644 index e65fbbd88..000000000 --- a/test/spec/modules/sparteoBidAdapter_spec.js +++ /dev/null @@ -1,534 +0,0 @@ -import {expect} from 'chai'; -import { deepClone, mergeDeep } from 'src/utils'; -import {spec as adapter} from 'modules/sparteoBidAdapter'; - -const CURRENCY = 'EUR'; -const TTL = 60; -const HTTP_METHOD = 'POST'; -const REQUEST_URL = 'https://bid.sparteo.com/auction'; -const USER_SYNC_URL_IFRAME = 'https://sync.sparteo.com/sync/iframe.html?from=prebidjs'; - -const VALID_BID_BANNER = { - bidder: 'sparteo', - bidId: '1a2b3c4d', - adUnitCode: 'id-1234', - params: { - networkId: '1234567a-eb1b-1fae-1d23-e1fbaef234cf', - formats: ['corner'] - }, - mediaTypes: { - banner: { - sizes: [ - [1, 1] - ] - } - } -}; - -const VALID_BID_VIDEO = { - bidder: 'sparteo', - bidId: '5e6f7g8h', - adUnitCode: 'id-5678', - params: { - networkId: '1234567a-eb1b-1fae-1d23-e1fbaef234cf' - }, - mediaTypes: { - video: { - playerSize: [640, 360], - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - api: [1, 2], - mimes: ['video/mp4'], - skip: 1, - startdelay: 0, - placement: 1, - linearity: 1, - minduration: 5, - maxduration: 30, - context: 'instream' - } - }, - ortb2Imp: { - ext: { - pbadslot: 'video' - } - } -}; - -const VALID_REQUEST_BANNER = { - method: HTTP_METHOD, - url: REQUEST_URL, - data: { - 'imp': [{ - 'secure': 1, - 'id': '1a2b3c4d', - 'banner': { - 'format': [{ - 'h': 1, - 'w': 1 - }], - 'topframe': 0 - }, - 'ext': { - 'sparteo': { - 'params': { - 'networkId': '1234567a-eb1b-1fae-1d23-e1fbaef234cf', - 'adUnitCode': 'id-1234', - 'formats': ['corner'] - } - } - } - }], - 'site': { - 'publisher': { - 'ext': { - 'params': { - 'networkId': '1234567a-eb1b-1fae-1d23-e1fbaef234cf', - 'pbjsVersion': '$prebid.version$' - } - } - } - }, - 'test': 0 - } -}; - -const VALID_REQUEST_VIDEO = { - method: HTTP_METHOD, - url: REQUEST_URL, - data: { - 'imp': [{ - 'secure': 1, - 'id': '5e6f7g8h', - 'video': { - 'w': 640, - 'h': 360, - 'protocols': [1, 2, 3, 4, 5, 6, 7, 8], - 'api': [1, 2], - 'mimes': ['video/mp4'], - 'skip': 1, - 'startdelay': 0, - 'placement': 1, - 'linearity': 1, - 'minduration': 5, - 'maxduration': 30, - }, - 'ext': { - 'pbadslot': 'video', - 'sparteo': { - 'params': { - 'networkId': '1234567a-eb1b-1fae-1d23-e1fbaef234cf', - 'adUnitCode': 'id-5678' - } - } - } - }], - 'site': { - 'publisher': { - 'ext': { - 'params': { - 'networkId': '1234567a-eb1b-1fae-1d23-e1fbaef234cf', - 'pbjsVersion': '$prebid.version$' - } - } - } - }, - 'test': 0 - } -}; - -const VALID_REQUEST = { - method: HTTP_METHOD, - url: REQUEST_URL, - data: { - 'imp': [{ - 'secure': 1, - 'id': '1a2b3c4d', - 'banner': { - 'format': [{ - 'h': 1, - 'w': 1 - }], - 'topframe': 0 - }, - 'ext': { - 'sparteo': { - 'params': { - 'networkId': '1234567a-eb1b-1fae-1d23-e1fbaef234cf', - 'adUnitCode': 'id-1234', - 'formats': ['corner'] - } - } - } - }, { - 'secure': 1, - 'id': '5e6f7g8h', - 'video': { - 'w': 640, - 'h': 360, - 'protocols': [1, 2, 3, 4, 5, 6, 7, 8], - 'api': [1, 2], - 'mimes': ['video/mp4'], - 'skip': 1, - 'startdelay': 0, - 'placement': 1, - 'linearity': 1, - 'minduration': 5, - 'maxduration': 30, - }, - 'ext': { - 'pbadslot': 'video', - 'sparteo': { - 'params': { - 'networkId': '1234567a-eb1b-1fae-1d23-e1fbaef234cf', - 'adUnitCode': 'id-5678' - } - } - } - }], - 'site': { - 'publisher': { - 'ext': { - 'params': { - 'networkId': '1234567a-eb1b-1fae-1d23-e1fbaef234cf', - 'pbjsVersion': '$prebid.version$' - } - } - } - }, - 'test': 0 - } -}; - -const BIDDER_REQUEST = { - bids: [VALID_BID_BANNER, VALID_BID_VIDEO] -} - -const BIDDER_REQUEST_BANNER = { - bids: [VALID_BID_BANNER] -} - -const BIDDER_REQUEST_VIDEO = { - bids: [VALID_BID_VIDEO] -} - -describe('SparteoAdapter', function () { - describe('isBidRequestValid', function () { - describe('Check method return', function () { - it('should return true', function () { - expect(adapter.isBidRequestValid(VALID_BID_BANNER)).to.equal(true); - expect(adapter.isBidRequestValid(VALID_BID_VIDEO)).to.equal(true); - }); - - it('should return false because the networkId is missing', function () { - const wrongBid = deepClone(VALID_BID_BANNER); - delete wrongBid.params.networkId; - - expect(adapter.isBidRequestValid(wrongBid)).to.equal(false); - }); - - it('should return false because the banner size is missing', function () { - const wrongBid = deepClone(VALID_BID_BANNER); - - wrongBid.mediaTypes.banner.sizes = '123456'; - expect(adapter.isBidRequestValid(wrongBid)).to.equal(false); - - delete wrongBid.mediaTypes.banner.sizes; - expect(adapter.isBidRequestValid(wrongBid)).to.equal(false); - }); - - it('should return false because the video player size paramater is missing', function () { - const wrongBid = deepClone(VALID_BID_VIDEO); - - wrongBid.mediaTypes.video.playerSize = '123456'; - expect(adapter.isBidRequestValid(wrongBid)).to.equal(false); - - delete wrongBid.mediaTypes.video.playerSize; - expect(adapter.isBidRequestValid(wrongBid)).to.equal(false); - }); - }); - }); - - describe('buildRequests', function () { - describe('Check method return', function () { - if (FEATURES.VIDEO) { - it('should return the right formatted requests', function() { - const request = adapter.buildRequests([VALID_BID_BANNER, VALID_BID_VIDEO], BIDDER_REQUEST); - delete request.data.id; - - expect(request).to.deep.equal(VALID_REQUEST); - }); - } - - it('should return the right formatted banner requests', function() { - const request = adapter.buildRequests([VALID_BID_BANNER], BIDDER_REQUEST_BANNER); - delete request.data.id; - - expect(request).to.deep.equal(VALID_REQUEST_BANNER); - }); - - if (FEATURES.VIDEO) { - it('should return the right formatted video requests', function() { - const request = adapter.buildRequests([VALID_BID_VIDEO], BIDDER_REQUEST_VIDEO); - delete request.data.id; - - expect(request).to.deep.equal(VALID_REQUEST_VIDEO); - }); - } - - it('should return the right formatted request with endpoint test', function() { - const endpoint = 'https://bid-test.sparteo.com/auction'; - - const bids = mergeDeep(deepClone([VALID_BID_BANNER, VALID_BID_VIDEO]), { - params: { - endpoint: endpoint - } - }); - - const requests = mergeDeep(deepClone(VALID_REQUEST)); - - const request = adapter.buildRequests(bids, BIDDER_REQUEST); - requests.url = endpoint; - delete request.data.id; - - expect(requests).to.deep.equal(requests); - }); - }); - }); - - describe('interpretResponse', function() { - describe('Check method return', function () { - it('should return the right formatted response', function() { - const response = { - body: { - 'id': '63f4d300-6896-4bdc-8561-0932f73148b1', - 'cur': 'EUR', - 'seatbid': [ - { - 'seat': 'sparteo', - 'group': 0, - 'bid': [ - { - 'id': 'cdbb6982-a269-40c7-84e5-04797f11d87a', - 'impid': '1a2b3c4d', - 'price': 4.5, - 'ext': { - 'prebid': { - 'type': 'banner' - } - }, - 'adm': 'script', - 'crid': 'crid', - 'w': 1, - 'h': 1, - 'nurl': 'https://t.bidder.sparteo.com/img' - } - ] - } - ] - } - }; - - if (FEATURES.VIDEO) { - response.body.seatbid[0].bid.push({ - 'id': 'cdbb6982-a269-40c7-84e5-04797f11d87b', - 'impid': '5e6f7g8h', - 'price': 5, - 'ext': { - 'prebid': { - 'type': 'video', - 'cache': { - 'vastXml': { - 'url': 'https://pbs.tet.com/cache?uuid=1234' - } - } - } - }, - 'adm': 'tag', - 'crid': 'crid', - 'w': 640, - 'h': 480, - 'nurl': 'https://t.bidder.sparteo.com/img' - }); - } - - const formattedReponse = [ - { - requestId: '1a2b3c4d', - seatBidId: 'cdbb6982-a269-40c7-84e5-04797f11d87a', - cpm: 4.5, - width: 1, - height: 1, - creativeId: 'crid', - creative_id: 'crid', - currency: CURRENCY, - netRevenue: true, - ttl: TTL, - mediaType: 'banner', - meta: {}, - ad: '
script' - } - ]; - - if (FEATURES.VIDEO) { - formattedReponse.push({ - requestId: '5e6f7g8h', - seatBidId: 'cdbb6982-a269-40c7-84e5-04797f11d87b', - cpm: 5, - width: 640, - height: 480, - playerWidth: 640, - playerHeight: 360, - creativeId: 'crid', - creative_id: 'crid', - currency: CURRENCY, - netRevenue: true, - ttl: TTL, - mediaType: 'video', - meta: {}, - nurl: 'https://t.bidder.sparteo.com/img', - vastUrl: 'https://pbs.tet.com/cache?uuid=1234', - vastXml: 'tag' - }); - } - - if (FEATURES.VIDEO) { - const request = adapter.buildRequests([VALID_BID_BANNER, VALID_BID_VIDEO], BIDDER_REQUEST); - expect(adapter.interpretResponse(response, request)).to.deep.equal(formattedReponse); - } else { - const request = adapter.buildRequests([VALID_BID_BANNER], BIDDER_REQUEST_BANNER); - expect(adapter.interpretResponse(response, request)).to.deep.equal(formattedReponse); - } - }); - - if (FEATURES.VIDEO) { - it('should interprete renderer config', function () { - let response = { - body: { - 'id': '63f4d300-6896-4bdc-8561-0932f73148b1', - 'cur': 'EUR', - 'seatbid': [ - { - 'seat': 'sparteo', - 'group': 0, - 'bid': [ - { - 'id': 'cdbb6982-a269-40c7-84e5-04797f11d87b', - 'impid': '5e6f7g8h', - 'price': 5, - 'ext': { - 'prebid': { - 'type': 'video', - 'cache': { - 'vastXml': { - 'url': 'https://pbs.tet.com/cache?uuid=1234' - } - }, - 'renderer': { - 'url': 'testVideoPlayer.js', - 'options': { - 'disableTopBar': true, - 'showBigPlayButton': false, - 'showProgressBar': 'bar', - 'showVolume': false, - 'showMute': true, - 'allowFullscreen': true - } - } - } - }, - 'adm': 'tag', - 'crid': 'crid', - 'w': 640, - 'h': 480, - 'nurl': 'https://t.bidder.sparteo.com/img' - } - ] - } - ] - } - }; - - const request = adapter.buildRequests([VALID_BID_BANNER, VALID_BID_VIDEO], BIDDER_REQUEST); - let formattedReponse = adapter.interpretResponse(response, request); - - expect(formattedReponse[0].renderer.url).to.equal(response.body.seatbid[0].bid[0].ext.prebid.renderer.url); - expect(formattedReponse[0].renderer.config).to.deep.equal(response.body.seatbid[0].bid[0].ext.prebid.renderer); - }); - } - }); - }); - - describe('onBidWon', function() { - describe('Check methods succeed', function () { - it('should not throw error', function() { - const bids = [ - { - requestId: '1a2b3c4d', - seatBidId: 'cdbb6982-a269-40c7-84e5-04797f11d87a', - cpm: 4.5, - width: 1, - height: 1, - creativeId: 'crid', - creative_id: 'crid', - currency: CURRENCY, - netRevenue: true, - ttl: TTL, - mediaType: 'banner', - meta: {}, - ad: 'script
', - nurl: [ - 'win.domain.com' - ] - }, - { - requestId: '2570', - seatBidId: 'cdbb6982-a269-40c7-84e5-04797f11d87b', - id: 'id-5678', - cpm: 5, - width: 640, - height: 480, - creativeId: 'crid', - currency: CURRENCY, - netRevenue: true, - ttl: TTL, - mediaType: 'video', - meta: {}, - vastXml: 'vast xml', - nurl: [ - 'win.domain2.com' - ] - } - ]; - - bids.forEach(function(bid) { - expect(adapter.onBidWon.bind(adapter, bid)).to.not.throw(); - }); - }); - }); - }); - - describe('getUserSyncs', function() { - describe('Check methods succeed', function () { - it('should return the sync url', function() { - const syncOptions = { - 'iframeEnabled': true, - 'pixelEnabled': false - }; - const gdprConsent = { - gdprApplies: 1, - consentString: 'tcfv2' - }; - const uspConsent = { - consentString: '1Y---' - }; - - const syncUrls = [{ - type: 'iframe', - url: USER_SYNC_URL_IFRAME + '&gdpr=1&gdpr_consent=tcfv2&usp_consent=1Y---' - }]; - - expect(adapter.getUserSyncs(syncOptions, null, gdprConsent, uspConsent)).to.deep.equal(syncUrls); - }); - }); - }); -}); diff --git a/test/spec/modules/ssmasBidAdapter_spec.js b/test/spec/modules/ssmasBidAdapter_spec.js deleted file mode 100644 index a97a40cae..000000000 --- a/test/spec/modules/ssmasBidAdapter_spec.js +++ /dev/null @@ -1,244 +0,0 @@ -import { expect } from 'chai'; -import { spec, SSMAS_CODE, SSMAS_ENDPOINT, SSMAS_REQUEST_METHOD } from 'modules/ssmasBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import * as utils from 'src/utils.js'; - -describe('ssmasBidAdapter', function () { - const bid = { - bidder: SSMAS_CODE, - adUnitCode: 'adunit-code', - sizes: [[300, 250]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - params: { - placementId: '1' - } - }; - - const bidderRequest = { - 'bidderCode': SSMAS_CODE, - 'auctionId': 'd912faa2-174f-4636-b755-7396a0a964d8', - 'bidderRequestId': '109db5a5f5c6788', - 'bids': [ - bid - ], - 'auctionStart': 1684799653734, - 'timeout': 20000, - 'metrics': {}, - 'ortb2': { - 'site': { - 'domain': 'localhost:9999', - 'publisher': { - 'domain': 'localhost:9999' - }, - 'page': 'http://localhost:9999/integrationExamples/noadserver/basic_noadserver.html', - 'ref': 'http://localhost:9999/integrationExamples/noadserver/' - }, - 'device': { - 'w': 1536, - 'h': 711, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0', - 'language': 'es' - } - }, - 'start': 1684799653737 - }; - - describe('Build Requests', () => { - it('Check bid request', function () { - const request = spec.buildRequests([bid], bidderRequest); - expect(request[0].method).to.equal(SSMAS_REQUEST_METHOD); - expect(request[0].url).to.equal(SSMAS_ENDPOINT); - }); - }); - - describe('register adapter functions', () => { - const adapter = newBidder(spec); - it('is registered', () => { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('validate bid request building', function () { - expect(spec.isBidRequestValid(bid)).to.be.true; - }); - - it('test bad bid request', function () { - // empty bid - expect(spec.isBidRequestValid({bidId: '', params: {}})).to.be.false; - - // empty bidId - bid.bidId = ''; - expect(spec.isBidRequestValid(bid)).to.be.false; - - // empty placementId - bid.bidId = '1231'; - bid.params.placementId = ''; - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('check bid request bidder is Sem Seo & Mas', function() { - const invalidBid = { - ...bid, bidder: 'invalidBidder' - }; - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('interpretResponse', function () { - const bidOrtbResponse = { - 'id': 'aa02e2fe-56d9-4713-88f9-d8672ceae8ab', - 'seatbid': [ - { - 'bid': [ - { - 'id': '0001', - 'impid': '3919400af0b73e8', - 'price': 7.01, - 'adid': null, - 'nurl': null, - 'adm': '', - 'adomain': [ - 'ssmas.com' - ], - 'iurl': null, - 'cid': null, - 'crid': '3547894', - 'attr': [], - 'api': 0, - 'protocol': 0, - 'dealid': null, - 'h': 600, - 'w': 300, - 'cat': null, - 'ext': null, - 'builder': { - 'id': '0001', - 'adid': null, - 'impid': '3919400af0b73e8', - 'adomainList': [ - 'ssmas.com' - ], - 'attrList': [] - }, - 'adomainList': [ - 'ssmas.com' - ], - 'attrList': [] - } - ], - 'seat': null, - 'group': 0 - } - ], - 'bidid': '408731cc-c018-4976-bfc6-89f9c61e97a0', - 'cur': 'EUR', - 'nbr': -1 - }; - const bidResponse = { - 'mediaType': 'banner', - 'ad': '', - 'requestId': '37c658fe8ba57b', - 'seatBidId': '0001', - 'cpm': 10, - 'currency': 'EUR', - 'width': 300, - 'height': 250, - 'dealId': null, - 'creative_id': '3547894', - 'creativeId': '3547894', - 'ttl': 30, - 'netRevenue': true, - 'meta': { - 'advertiserDomains': [ - 'ssmas.com' - ] - } - }; - const bidRequest = { - 'imp': [ - { - 'ext': { - 'tid': '937db9c3-c22d-4454-b786-fcad76a349e5', - 'data': { - 'pbadslot': 'test-div' - } - }, - 'id': '3919400af0b73e8', - 'banner': { - 'topframe': 1, - 'format': [ - { - 'w': 300, - 'h': 600 - } - ] - } - }, - { - 'ext': { - 'tid': '0c0d3d1b-0ad0-4786-896d-24c15fc6531d', - 'data': { - 'pbadslot': 'test-div2' - } - }, - 'id': '3919400af0b73e8', - 'banner': { - 'topframe': 1, - 'format': [ - { - 'w': 300, - 'h': 600 - } - ] - } - } - ], - 'site': { - 'domain': 'localhost:9999', - 'publisher': { - 'domain': 'localhost:9999' - }, - 'page': 'http://localhost:9999/integrationExamples/noadserver/basic_noadserver.html', - 'ref': 'http://localhost:9999/integrationExamples/noadserver/', - 'id': 1, - 'ext': { - 'placementId': 13144370 - } - }, - 'device': { - 'w': 1536, - 'h': 711, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/113.0', - 'language': 'es' - }, - 'id': '8cc2f4b0-084d-4f40-acfa-5bec2023b1ab', - 'test': 0, - 'tmax': 20000, - 'source': { - 'tid': '8cc2f4b0-084d-4f40-acfa-5bec2023b1ab' - } - } - }); - - describe('test onBidWon function', function () { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - it('exists and is a function', () => { - expect(spec.onBidWon).to.exist.and.to.be.a('function'); - }); - it('should return nothing', function () { - var response = spec.onBidWon({}); - expect(response).to.be.an('undefined') - expect(utils.triggerPixel.called).to.equal(false); - }); - }); -}); diff --git a/test/spec/modules/sspBCBidAdapter_spec.js b/test/spec/modules/sspBCBidAdapter_spec.js deleted file mode 100644 index 53261a3a7..000000000 --- a/test/spec/modules/sspBCBidAdapter_spec.js +++ /dev/null @@ -1,835 +0,0 @@ -import { assert, expect } from 'chai'; -import { spec } from 'modules/sspBCBidAdapter.js'; -import * as utils from 'src/utils.js'; - -const BIDDER_CODE = 'sspBC'; -const BIDDER_URL = 'https://ssp.wp.pl/bidder/'; -const SYNC_URL_IFRAME = 'https://ssp.wp.pl/bidder/usersync'; -const SYNC_URL_IMAGE = 'https://ssp.wp.pl/v1/sync/pixel'; - -describe('SSPBC adapter', function () { - function prepareTestData() { - const bidderRequestId = '1041bb47b0fafa'; - const auctionId = '8eda6d06-3d7c-4a94-9b35-74e42fbb3089'; - const transactionId = '50259989-b5c0-4edf-8f47-b1ef5fbedf39'; - const gdprConsent = { - consentString: 'BOtq-3dOtq-30BIABCPLC4-AAAAthr_7__7-_9_-_f__9uj3Or_v_f__30ccL59v_h_7v-_7fi_20nV4u_1vft9yfk1-5ctDztp505iakivHmqNeb9v_mz1_5pRP78k89r7337Ew_v8_v-b7JCON_Ig', - gdprApplies: true, - } - const bids = [{ - adUnitCode: 'test_wideboard', - bidder: BIDDER_CODE, - mediaTypes: { - banner: { - sizes: [ - [728, 90], - [750, 100], - [750, 200] - ] - } - }, - sizes: [ - [728, 90], - [750, 100], - [750, 200] - ], - params: { - id: '003', - siteId: '8816', - }, - auctionId, - bidderRequestId, - bidId: bidderRequestId + '1', - transactionId, - }, - { - adUnitCode: 'test_rectangle', - bidder: BIDDER_CODE, - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - sizes: [ - [300, 250] - ], - params: { - id: '005', - siteId: '8816', - }, - auctionId, - bidderRequestId, - bidId: bidderRequestId + '2', - transactionId, - } - ]; - const bid_OneCode = { - adUnitCode: 'test_wideboard', - bidder: BIDDER_CODE, - mediaTypes: { - banner: { - sizes: [ - [728, 90], - [750, 100], - [750, 200] - ] - } - }, - sizes: [ - [728, 90], - [750, 100], - [750, 200] - ], - auctionId, - bidderRequestId, - bidId: bidderRequestId + '1', - transactionId, - }; - const bid_native = { - adUnitCode: 'test_native', - bidder: BIDDER_CODE, - mediaTypes: { - native: { - image: { - required: true, - sizes: [150, 50], - }, - title: { - required: true, - len: 80 - }, - sponsoredBy: { - required: true, - }, - clickUrl: { - required: true, - }, - privacyLink: { - required: false, - }, - body: { - required: true, - }, - icon: { - required: true, - sizes: [50, 50] - } - } - }, - sizes: [ - [1, 1], - ], - auctionId, - bidderRequestId, - bidId: bidderRequestId + '1', - transactionId, - }; - const bid_video = { - adUnitCode: 'test_video', - bidder: BIDDER_CODE, - mediaTypes: { - video: { - context: 'instream', - playerSize: [[640, 480]], - mimes: ['video/mp4', 'video/x-ms-wmv', 'video/webm', 'video/3gpp', 'application/javascript'], - protocols: [2, 3, 5, 6], - api: [2], - maxduration: 30, - linearity: 1 - } - }, - sizes: [ - [640, 480], - ], - auctionId, - bidderRequestId, - bidId: bidderRequestId + '1', - transactionId, - }; - const bids_timeouted = [{ - adUnitCode: 'test_wideboard', - bidder: BIDDER_CODE, - params: [{ - id: '003', - siteId: '8816', - }], - auctionId, - bidId: bidderRequestId + '1', - timeout: 100, - }, - { - adUnitCode: 'test_rectangle', - bidder: BIDDER_CODE, - params: [{ - id: '005', - siteId: '8816', - }], - auctionId, - bidId: bidderRequestId + '2', - timeout: 100, - } - ]; - const bids_test = [{ - adUnitCode: 'test_wideboard', - bidder: BIDDER_CODE, - mediaTypes: { - banner: { - sizes: [ - [970, 300], - [750, 300], - [750, 200], - [750, 100], - [300, 250] - ] - } - }, - sizes: [ - [970, 300], - [750, 300], - [750, 200], - [750, 100], - [300, 250] - ], - params: { - id: '005', - siteId: '235911', - test: 1 - }, - auctionId, - bidderRequestId, - bidId: bidderRequestId + '1', - transactionId, - }]; - const bidRequest = { - auctionId, - bidderCode: BIDDER_CODE, - bidderRequestId, - bids, - gdprConsent, - refererInfo: { - reachedTop: true, - page: 'https://test.site.pl/', - domain: 'test.site.pl', - stack: ['https://test.site.pl/'], - } - }; - const bidRequestSingle = { - auctionId, - bidderCode: BIDDER_CODE, - bidderRequestId, - bids: [bids[0]], - gdprConsent, - refererInfo: { - reachedTop: true, - page: 'https://test.site.pl/', - domain: 'test.site.pl', - stack: ['https://test.site.pl/'], - } - }; - const bidRequestNative = { - auctionId, - bidderCode: BIDDER_CODE, - bidderRequestId, - bids: [bid_native], - gdprConsent, - refererInfo: { - reachedTop: true, - page: 'https://test.site.pl/', - domain: 'test.site.pl', - stack: ['https://test.site.pl/'], - } - }; - const bidRequestVideo = { - auctionId, - bidderCode: BIDDER_CODE, - bidderRequestId, - bids: [bid_video], - gdprConsent, - refererInfo: { - reachedTop: true, - page: 'https://test.site.pl/', - domain: 'test.site.pl', - stack: ['https://test.site.pl/'], - } - }; - const bidRequestOneCode = { - auctionId, - bidderCode: BIDDER_CODE, - bidderRequestId, - bids: [bid_OneCode], - gdprConsent, - refererInfo: { - reachedTop: true, - page: 'https://test.site.pl/', - domain: 'test.site.pl', - stack: ['https://test.site.pl/'], - } - }; - const bidRequestTest = { - auctionId, - bidderCode: BIDDER_CODE, - bidderRequestId, - bids: bids_test, - gdprConsent, - refererInfo: { - reachedTop: true, - page: 'https://test.site.pl/', - domain: 'test.site.pl', - stack: ['https://test.site.pl/'], - } - }; - const bidRequestTestNoGDPR = { - auctionId, - bidderCode: BIDDER_CODE, - bidderRequestId, - bids: bids_test, - refererInfo: { - reachedTop: true, - page: 'https://test.site.pl/', - domain: 'test.site.pl', - stack: ['https://test.site.pl/'], - } - }; - const serverResponse = { - 'body': { - 'id': bidderRequestId, - 'seatbid': [{ - 'bid': [{ - 'id': '3347324c-6889-46d2-a800-ae78a5214c06', - 'impid': '003', - 'siteid': '8816', - 'slotid': '003', - 'price': 1, - 'adid': 'lxHWkB7OnZeso3QiN1N4', - 'nurl': '', - 'adm': 'AD_CODE1', - 'adomain': ['adomain.pl'], - 'cid': 'BZ4gAg21T5nNtxlUCDSW', - 'crid': 'lxHWkB7OnZeso3QiN1N4', - 'w': 728, - 'h': 90 - }], - 'seat': 'dsp1', - 'group': 0 - }, { - 'bid': [{ - 'id': '2d766853-ea07-4529-8299-5f0ebadc546a', - 'impid': '005', - 'siteid': '8816', - 'slotid': '005', - 'price': 2, - 'adm': 'AD_CODE2', - 'cid': '57744', - 'crid': '858252', - 'w': 300, - 'h': 250 - }], - 'seat': 'dsp2', - 'group': 0 - }], - 'cur': 'PLN' - } - }; - const serverResponseSingle = { - 'body': { - 'id': bidderRequestId, - 'seatbid': [{ - 'bid': [{ - 'id': '3347324c-6889-46d2-a800-ae78a5214c06', - 'impid': '003', - 'siteid': '8816', - 'slotid': '003', - 'price': 1, - 'adid': 'lxHWkB7OnZeso3QiN1N4', - 'nurl': '', - 'adm': 'AD_CODE', - 'adomain': ['adomain.pl'], - 'cid': 'BZ4gAg21T5nNtxlUCDSW', - 'crid': 'lxHWkB7OnZeso3QiN1N4', - 'w': 728, - 'h': 90, - }], - 'seat': 'dsp1', - 'group': 0 - }], - 'cur': 'PLN' - } - }; - - const serverResponsePaapi = { - 'body': { - 'id': bidderRequestId, - 'seatbid': [{ - 'bid': [{ - 'id': '3347324c-6889-46d2-a800-ae78a5214c06', - 'impid': '003', - 'siteid': '8816', - 'slotid': '003', - 'price': 1, - 'adid': 'lxHWkB7OnZeso3QiN1N4', - 'nurl': '', - 'adm': 'AD_CODE', - 'adomain': ['adomain.pl'], - 'cid': 'BZ4gAg21T5nNtxlUCDSW', - 'crid': 'lxHWkB7OnZeso3QiN1N4', - 'w': 728, - 'h': 90, - }], - 'seat': 'dsp1', - 'group': 0 - }], - 'cur': 'PLN', - 'ext': { - 'paapi': [ - { 'config_data': 'config value' }, - ] - }, - } - }; - - const serverResponseIncorrect = { - 'body': { - 'id': bidderRequestId, - 'seatbid': [{ - 'bid': [{ - 'id': '3347324c-6889-46d2-a800-ae78a5214c06', - 'impid': '003', - 'siteid': '8816', - 'slotid': '003', - 'price': 1, - 'adid': 'lxHWkB7OnZeso3QiN1N4', - 'nurl': '', - 'adm': 'THIS_IS_NOT_AN_AD', - 'adomain': ['adomain.pl'], - 'cid': 'BZ4gAg21T5nNtxlUCDSW', - 'crid': 'lxHWkB7OnZeso3QiN1N4', - 'w': 728, - 'h': 90 - }], - 'seat': 'dsp1', - 'group': 0 - }], - 'cur': 'PLN' - } - }; - const serverResponseOneCode = { - 'body': { - 'id': bidderRequestId, - 'seatbid': [{ - 'bid': [{ - 'id': '3347324c-6889-46d2-a800-ae78a5214c06', - 'impid': 'bidid-' + bidderRequestId + '1', - 'price': 1, - 'adid': 'lxHWkB7OnZeso3QiN1N4', - 'nurl': '', - 'adm': 'AD_CODE', - 'adomain': ['adomain.pl'], - 'cid': 'BZ4gAg21T5nNtxlUCDSW', - 'crid': 'lxHWkB7OnZeso3QiN1N4', - 'w': 728, - 'h': 90, - 'ext': { - 'siteid': '8816', - 'slotid': '003', - }, - }], - 'seat': 'dsp1', - 'group': 0 - }], - 'cur': 'PLN' - } - }; - const serverResponseVideo = { - 'body': { - 'id': bidderRequestId, - 'seatbid': [{ - 'bid': [{ - 'id': '3347324c-6889-46d2-a800-ae78a5214c06', - 'impid': 'bidid-' + bidderRequestId + '1', - 'price': 1, - 'adid': 'lxHWkB7OnZeso3QiN1N4', - 'nurl': '', - 'adm': 'adnxs', - 'adomain': ['adomain.pl'], - 'cid': 'BZ4gAg21T5nNtxlUCDSW', - 'crid': 'lxHWkB7OnZeso3QiN1N4', - 'w': 640, - 'h': 480, - 'ext': { - 'siteid': '8816', - 'slotid': '150', - 'cache': 'https://video.tag.cache' - }, - }], - 'seat': 'dsp1', - 'group': 0 - }], - 'cur': 'PLN' - } - }; - const serverResponseNative = { - 'body': { - 'id': bidderRequestId, - 'seatbid': [{ - 'bid': [{ - 'id': '3347324c-6889-46d2-a800-ae78a5214c06', - 'impid': 'bidid-' + bidderRequestId + '1', - 'price': 1, - 'adid': 'lxHWkB7OnZeso3QiN1N4', - 'nurl': '', - 'adm': '{\"native\":{\"assets\":[{\"id\":3,\"img\":{\"url\":\"native_image\",\"w\":300,\"h\":150}},{\"id\":2,\"img\":{\"url\":\"native_icon\",\"w\":50,\"h\":50}},{\"id\":0,\"title\":{\"text\":\"native_title\"}},{\"id\":5,\"data\":{\"value\":\"native adomain\"}},{\"id\":4,\"data\":{\"value\":\"native_text\"}}],\"link\":{\"url\":\"native_url\"},\"imptrackers\":[\"native_tracker\"]}}', - 'adomain': ['adomain.pl'], - 'cid': 'BZ4gAg21T5nNtxlUCDSW', - 'crid': 'lxHWkB7OnZeso3QiN1N4', - 'ext': { - 'siteid': '8816', - 'slotid': '80', - }, - }], - 'seat': 'dsp1', - 'group': 0 - }], - 'cur': 'PLN' - } - }; - const emptyResponse = { - 'body': { - 'id': bidderRequestId, - } - } - return { - bid_OneCode, - bids, - bids_test, - bids_timeouted, - bid_native, - bid_video, - bidRequest, - bidRequestOneCode, - bidRequestSingle, - bidRequestNative, - bidRequestVideo, - bidRequestTest, - bidRequestTestNoGDPR, - serverResponse, - serverResponseOneCode, - serverResponseSingle, - serverResponseIncorrect, - serverResponsePaapi, - serverResponseVideo, - serverResponseNative, - emptyResponse - }; - }; - - describe('dependencies', function () { - it('utils should contain required functions', function () { - expect(utils.parseUrl).to.be.a('function'); - expect(utils.deepAccess).to.be.a('function'); - expect(utils.logWarn).to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const { bids } = prepareTestData(); - const bid = bids[0]; - - it('should always return true whether bid has params (standard) or not (OneCode)', function () { - assert(spec.isBidRequestValid(bid)); - bid.params.id = undefined; - assert(spec.isBidRequestValid(bid)); - }); - }); - - describe('buildRequests', function () { - const { bids, bid_native, bid_video, bidRequest, bidRequestSingle, bidRequestNative, bidRequestVideo } = prepareTestData(); - const request = spec.buildRequests(bids, bidRequest); - const requestSingle = spec.buildRequests([bids[0]], bidRequestSingle); - const requestNative = spec.buildRequests([bid_native], bidRequestNative); - const requestVideo = spec.buildRequests([bid_video], bidRequestVideo); - const payload = request ? JSON.parse(request.data) : { site: false, imp: false }; - const payloadSingle = requestSingle ? JSON.parse(requestSingle.data) : { site: false, imp: false }; - const payloadNative = requestNative ? JSON.parse(requestNative.data) : { site: false, imp: false }; - const payloadVideo = requestVideo ? JSON.parse(requestVideo.data) : { site: false, imp: false }; - - it('should send bid request to endpoint via POST', function () { - expect(request.url).to.contain(BIDDER_URL); - expect(request.method).to.equal('POST'); - }); - - it('should contain prebid and bidder versions', function () { - expect(request.url).to.contain('bdver'); - expect(request.url).to.contain('pbver=$prebid.version$'); - }); - - it('should create one imp object per bid', function () { - expect(payload.imp.length).to.equal(bids.length); - expect(payloadSingle.imp.length).to.equal(1); - }); - - it('should save bidder request data', function () { - expect(request.bidderRequest).to.deep.equal(bidRequest); - }); - - it('should send site Id from bidder params', function () { - expect(payload.site.id).to.equal(bids[0].params.siteId); - }); - - it('should send page url from refererInfo', function () { - expect(payload.site.page).to.equal(bidRequest.refererInfo.page); - }); - - it('should send gdpr data', function () { - expect(payload.regs).to.be.an('object').and.to.have.property('gdpr', 1); - expect(payload.user).to.be.an('object').and.to.have.property('consent', bidRequest.gdprConsent.consentString); - }); - - it('should send net info and pvid', function () { - expect(payload.user).to.be.an('object').and.to.have.property('data').that.is.an('array'); - - const userData = payload.user.data; - expect(userData.length).to.equal(2); - - const netInfo = userData[0]; - expect(netInfo.id).to.equal('12'); - expect(netInfo.name).to.equal('NetInfo'); - expect(netInfo).to.have.property('segment').that.is.an('array'); - - const pvid = userData[1]; - expect(pvid.id).to.equal('7'); - expect(pvid.name).to.equal('pvid'); - expect(pvid).to.have.property('segment').that.is.an('array'); - expect(pvid.segment[0]).to.have.property('value'); - }); - - it('pvid should be constant on a single page view', function () { - const userData1 = payload.user.data; - const userData2 = payloadNative.user.data; - const pvid1 = userData1[1]; - const pvid2 = userData2[1]; - - expect(pvid1.segment[0].value).to.equal(pvid2.segment[0].value); - }); - - it('should build correct native payload', function () { - const nativeAssets = payloadNative.imp && payloadNative.imp[0].native.request; - - expect(payloadNative.imp.length).to.equal(1); - - expect(nativeAssets).to.contain('{"id":0,"required":true,"title":{"len":80}}'); - expect(nativeAssets).to.contain('{"id":2,"required":true,"img":{"type":1,"w":50,"h":50}}'); - expect(nativeAssets).to.contain('{"id":3,"required":true,"img":{"type":3,"w":150,"h":50}}'); - expect(nativeAssets).to.contain('{"id":4,"required":true,"data":{"type":2}'); - expect(nativeAssets).to.contain('{"id":5,"required":true,"data":{"type":1}'); - }); - - it('should build correct video payload', function () { - const videoAssets = payloadVideo.imp && payloadVideo.imp[0].video; - - expect(payloadVideo.imp.length).to.equal(1); - expect(videoAssets).to.have.property('w').that.equals(640); - expect(videoAssets).to.have.property('h').that.equals(480); - expect(videoAssets).to.have.property('context').that.equals('instream'); - expect(videoAssets).to.have.property('maxduration').that.equals(30); - expect(videoAssets).to.have.property('linearity').that.equals(1); - expect(videoAssets).to.have.property('mimes').that.is.an('array'); - expect(videoAssets).to.have.property('protocols').that.is.an('array'); - expect(videoAssets).to.have.property('api').that.is.an('array'); - }); - - it('should create auxilary placement identifier (size_numUsed), that is constant for a given adUnit', function () { - const extAssets1 = payload.imp && payload.imp[0].ext.data; - const extAssets2 = payloadSingle.imp && payloadSingle.imp[0].ext.data; - - /* - note that payload comes from first, and payloadSingle from second auction in the test run - also, since both have same adUnitName, value of pbsize property should be the same - */ - expect(extAssets1).to.have.property('pbsize').that.equals('750x200_1') - expect(extAssets2).to.have.property('pbsize').that.equals('750x200_1') - }); - - it('should send supply chain data', function () { - const supplyChain = { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'first-seller.com', - sid: '00001', - hp: 1 - }, - ] - } - const bidWithSupplyChain = Object.assign(bids[0], { ortb2: { source: { ext: { schain: supplyChain } } } }); - const requestWithSupplyChain = spec.buildRequests([bidWithSupplyChain], bidRequest); - const payloadWithSupplyChain = requestWithSupplyChain ? JSON.parse(requestWithSupplyChain.data) : { site: false, imp: false }; - - expect(payloadWithSupplyChain.source).to.have.property('schain').that.has.keys('ver', 'complete', 'nodes'); - }); - }); - - describe('interpretResponse', function () { - const { bid_OneCode, bid_video, bid_native, bids, emptyResponse, serverResponse, serverResponseOneCode, serverResponseSingle, serverResponseIncorrect, serverResponsePaapi, serverResponseVideo, serverResponseNative, bidRequest, bidRequestOneCode, bidRequestSingle, bidRequestVideo, bidRequestNative } = prepareTestData(); - const request = spec.buildRequests(bids, bidRequest); - const requestSingle = spec.buildRequests([bids[0]], bidRequestSingle); - const requestOneCode = spec.buildRequests([bid_OneCode], bidRequestOneCode); - const requestVideo = spec.buildRequests([bid_video], bidRequestVideo); - const requestNative = spec.buildRequests([bid_native], bidRequestNative); - - it('should handle nobid responses', function () { - const result = spec.interpretResponse(emptyResponse, request); - expect(result.length).to.equal(0); - }); - - it('should create bids from non-empty responses', function () { - const result = spec.interpretResponse(serverResponse, request); - const resultSingle = spec.interpretResponse(serverResponseSingle, requestSingle); - - expect(result.length).to.equal(bids.length); - expect(resultSingle.length).to.equal(1); - expect(resultSingle[0]).to.have.keys('ad', 'cpm', 'width', 'height', 'mediaType', 'meta', 'requestId', 'creativeId', 'currency', 'netRevenue', 'ttl', 'vurls'); - }); - - it('should create bid from OneCode (parameter-less) request, if response contains siteId', function () { - const resultOneCode = spec.interpretResponse(serverResponseOneCode, requestOneCode); - - expect(resultOneCode.length).to.equal(1); - expect(resultOneCode[0]).to.have.keys('ad', 'cpm', 'width', 'height', 'mediaType', 'meta', 'requestId', 'creativeId', 'currency', 'netRevenue', 'ttl', 'vurls'); - }); - - it('should not create bid from OneCode (parameter-less) request, if response does not contain siteId', function () { - const resultOneCodeNoMatch = spec.interpretResponse(serverResponse, requestOneCode); - - expect(resultOneCodeNoMatch.length).to.equal(0); - }); - - it('should handle a partial response', function () { - const resultPartial = spec.interpretResponse(serverResponseSingle, request); - expect(resultPartial.length).to.equal(1); - }); - - it('should not alter HTML from response', function () { - const resultSingle = spec.interpretResponse(serverResponseSingle, requestSingle); - const adcode = resultSingle[0].ad; - - expect(adcode).to.be.equal(serverResponseSingle.body.seatbid[0].bid[0].adm); - }); - - it('should create a correct video bid', function () { - const resultVideo = spec.interpretResponse(serverResponseVideo, requestVideo); - - expect(resultVideo.length).to.equal(1); - - const videoBid = resultVideo[0]; - expect(videoBid).to.have.keys('adType', 'cpm', 'creativeId', 'currency', 'width', 'height', 'meta', 'mediaType', 'netRevenue', 'requestId', 'ttl', 'vastContent', 'vastXml', 'vastUrl', 'vurls'); - expect(videoBid.adType).to.equal('instream'); - expect(videoBid.mediaType).to.equal('video'); - expect(videoBid.vastXml).to.match(/^<\?xml.*<\/VAST>$/); - expect(videoBid.vastContent).to.match(/^<\?xml.*<\/VAST>$/); - expect(videoBid.vastUrl).to.equal('https://video.tag.cache'); - }); - - it('should create a correct native bid', function () { - const resultNative = spec.interpretResponse(serverResponseNative, requestNative); - - expect(resultNative.length).to.equal(1); - - const nativeBid = resultNative[0]; - expect(nativeBid).to.have.keys('cpm', 'creativeId', 'currency', 'width', 'height', 'meta', 'mediaType', 'netRevenue', 'requestId', 'ttl', 'native', 'vurls'); - expect(nativeBid.native).to.have.keys('image', 'icon', 'title', 'sponsoredBy', 'body', 'clickUrl', 'impressionTrackers', 'javascriptTrackers', 'clickTrackers'); - }); - - it('should reject responses that are not HTML, VATS/VPAID or native', function () { - const resultIncorrect = spec.interpretResponse(serverResponseIncorrect, requestSingle); - - expect(resultIncorrect.length).to.equal(0); - }); - - it('should response with fledge auction configs', function () { - const { bids, fledgeAuctionConfigs } = spec.interpretResponse(serverResponsePaapi, requestSingle); - - expect(bids.length).to.equal(1); - expect(fledgeAuctionConfigs.length).to.equal(1); - }); - }); - - describe('getUserSyncs', function () { - const syncResultAll = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }); - const syncResultImage = spec.getUserSyncs({ iframeEnabled: false, pixelEnabled: true }); - const syncResultNone = spec.getUserSyncs({ iframeEnabled: false, pixelEnabled: false }); - - it('should provide correct iframe url, if frame sync is allowed', function () { - expect(syncResultAll).to.have.length(1); - expect(syncResultAll[0].url).to.have.string(SYNC_URL_IFRAME); - }); - - it('should provide correct image url, if image sync is allowed', function () { - expect(syncResultImage).to.have.length(1); - expect(syncResultImage[0].url).to.have.string(SYNC_URL_IMAGE); - }); - - it('should send no syncs, if no sync is allowed', function () { - expect(syncResultNone).to.have.length(0); - expect(syncResultNone).to.have.length(0); - }); - }); - - describe('onBidWon', function () { - it('should generate no notification if bid is undefined', function () { - const notificationPayload = spec.onBidWon(); - expect(notificationPayload).to.be.undefined; - }); - - it('should generate notification with event name and request/adUnit data, if correct bid is provided. Should also contain site/slot data as arrays.', function () { - const { bids } = prepareTestData(); - const bid = bids[0]; - - const notificationPayload = spec.onBidWon(bid); - expect(notificationPayload).to.have.property('event').that.equals('bidWon'); - expect(notificationPayload).to.have.property('requestId').that.equals(bid.bidderRequestId); - expect(notificationPayload).to.have.property('tagid').that.deep.equals([bid.adUnitCode]); - expect(notificationPayload).to.have.property('siteId').that.is.an('array'); - expect(notificationPayload).to.have.property('slotId').that.is.an('array'); - }); - }); - - describe('onBidBillable', function () { - it('should generate no notification if bid is undefined', function () { - const notificationPayload = spec.onBidBillable(); - expect(notificationPayload).to.be.undefined; - }); - - it('should generate notification with event name and request/adUnit data, if correct bid is provided. Should also contain site/slot data as arrays.', function () { - const { bids } = prepareTestData(); - const bid = bids[0]; - - const notificationPayload = spec.onBidBillable(bid); - expect(notificationPayload).to.have.property('event').that.equals('bidBillable'); - expect(notificationPayload).to.have.property('requestId').that.equals(bid.bidderRequestId); - expect(notificationPayload).to.have.property('tagid').that.deep.equals([bid.adUnitCode]); - expect(notificationPayload).to.have.property('siteId').that.is.an('array'); - expect(notificationPayload).to.have.property('slotId').that.is.an('array'); - }); - }); - - describe('onTimeout', function () { - it('should generate no notification if timeout data is undefined / has no bids', function () { - const notificationPayloadUndefined = spec.onTimeout(); - const notificationPayloadNoBids = spec.onTimeout([]); - - expect(notificationPayloadUndefined).to.be.undefined; - expect(notificationPayloadNoBids).to.be.undefined; - }); - - it('should generate single notification for any number of timeouted bids', function () { - const { bids_timeouted } = prepareTestData(); - const notificationPayload = spec.onTimeout(bids_timeouted); - - expect(notificationPayload).to.have.property('event').that.equals('timeout'); - expect(notificationPayload).to.have.property('tagid').that.deep.equals([bids_timeouted[0].adUnitCode, bids_timeouted[1].adUnitCode]); - }); - }); -}); diff --git a/test/spec/modules/ssp_genieeBidAdapter_spec.js b/test/spec/modules/ssp_genieeBidAdapter_spec.js deleted file mode 100644 index 980d97c4c..000000000 --- a/test/spec/modules/ssp_genieeBidAdapter_spec.js +++ /dev/null @@ -1,681 +0,0 @@ -import { expect } from 'chai'; -import { - spec, - BANNER_ENDPOINT, - buildExtuidQuery, -} from 'modules/ssp_genieeBidAdapter.js'; -import { config } from 'src/config.js'; - -describe('ssp_genieeBidAdapter', function () { - const ZONE_ID = 1234567; - const AD_UNIT_CODE = 'adunit-code'; - const BANNER_BID = { - bidder: spec.code, - params: { - zoneId: ZONE_ID, - invalidImpBeacon: false, - }, - adUnitCode: AD_UNIT_CODE, - sizes: [[300, 250]], - bidId: 'bidId12345', - bidderRequestId: 'bidderRequestId12345', - auctionId: 'auctionId12345', - }; - let sandbox; - - function getGeparamsDefinedBid(bid, params) { - const newBid = { ...bid }; - newBid.params.geparams = params; - return newBid; - } - - function hasParamsNotBlankStringTestGeparams(param, query) { - it(`should set the ${query} query to geparams.${param} when geparams.${param} is neither undefined nor null nor a blank string`, function () { - window.geparams[param] = undefined; - let request = spec.buildRequests([BANNER_BID]); - expect(request[0].data).to.not.have.property(`"${query}:`); - - window.geparams[param] = null; - request = spec.buildRequests([BANNER_BID]); - expect(request[0].data).to.not.have.property(`"${query}:`); - - window.geparams[param] = ''; - request = spec.buildRequests([BANNER_BID]); - expect(request[0].data).to.not.have.property(`"${query}:`); - - const value = 'hoge'; - window.geparams[param] = value; - request = spec.buildRequests([BANNER_BID]); - expect(JSON.stringify(request[0].data)).to.have.string(`"${query}":"${value}"`); - }); - } - - function hasParamsNotBlankStringTestGecuparams(param, query) { - it(`should set the ${query} query to gecuparams.${param} when gecuparams.${param} is neither undefined nor null nor a blank string`, function () { - window.gecuparams = {}; - window.gecuparams[param] = undefined; - let request = spec.buildRequests([BANNER_BID]); - expect(request[0].data).to.not.have.property(`"${query}:`); - - window.gecuparams[param] = null; - request = spec.buildRequests([BANNER_BID]); - expect(request[0].data).to.not.have.property(`"${query}:`); - - window.gecuparams[param] = ''; - request = spec.buildRequests([BANNER_BID]); - expect(request[0].data).to.not.have.property(`"${query}:`); - - const value = 'hoge'; - window.gecuparams[param] = value; - request = spec.buildRequests([BANNER_BID]); - expect(JSON.stringify(request[0].data)).to.have.string(`"${query}":"${value}"`); - }); - } - - beforeEach(function () { - sandbox = sinon.createSandbox(); - document.documentElement.innerHTML = ''; - const adTagParent = document.createElement('div'); - adTagParent.id = AD_UNIT_CODE; - document.body.appendChild(adTagParent); - }); - - afterEach(function () { - sandbox.restore(); - }); - - describe('isBidRequestValid', function () { - it('should return true when params.zoneId exists and params.currency does not exist', function () { - expect(spec.isBidRequestValid(BANNER_BID)).to.be.true; - }); - - it('should return true when params.zoneId and params.currency exist and params.currency is JPY or USD', function () { - config.setConfig({ currency: { adServerCurrency: 'JPY' } }); - expect( - spec.isBidRequestValid({ - ...BANNER_BID, - params: { ...BANNER_BID.params }, - }) - ).to.be.true; - config.setConfig({ currency: { adServerCurrency: 'USD' } }); - expect( - spec.isBidRequestValid({ - ...BANNER_BID, - params: { ...BANNER_BID.params }, - }) - ).to.be.true; - }); - - it('should return false when params.zoneId does not exist', function () { - expect(spec.isBidRequestValid({ ...BANNER_BID, params: {} })).to.be.false; - }); - - it('should return false when params.zoneId and params.currency exist and params.currency is neither JPY nor USD', function () { - config.setConfig({ currency: { adServerCurrency: 'EUR' } }); - expect( - spec.isBidRequestValid({ - ...BANNER_BID, - params: { ...BANNER_BID.params }, - }) - ).to.be.false; - }); - }); - - describe('buildRequests', function () { - it('should changes the endpoint with banner ads or naive ads', function () { - const request = spec.buildRequests([BANNER_BID]); - expect(request[0].url).to.equal(BANNER_ENDPOINT); - }); - - it('should return a ServerRequest where the bid is a bid for validBidRequests', function () { - const request = spec.buildRequests([BANNER_BID]); - expect(request[0].bid).to.equal(BANNER_BID); - }); - - describe('QueryStringParameters', function () { - it('should sets the value of the zoneid query to bid.params.zoneId', function () { - const request = spec.buildRequests([BANNER_BID]); - expect(request[0].data.zoneid).to.deep.equal(BANNER_BID.params.zoneId); - }); - - it('should set the title query to the encoded page title', function () { - const testTitle = "Test Page Title with 'special' & \"chars\""; - sandbox.stub(document, 'title').value(testTitle); - const request = spec.buildRequests([BANNER_BID]); - const expectedEncodedTitle = encodeURIComponent(testTitle).replace(/'/g, '%27'); - expect(request[0].data.title).to.deep.equal(expectedEncodedTitle); - }); - - it('should not set the title query when the page title is empty', function () { - sandbox.stub(document, 'title').value(''); - const request = spec.buildRequests([BANNER_BID]); - expect(request[0].data).to.not.have.property('title'); - }); - - it('should sets the values for loc and referer queries when bidderRequest.refererInfo.referer has a value', function () { - const referer = 'https://example.com/'; - const request = spec.buildRequests([BANNER_BID], { - refererInfo: { legacy: { referer: referer }, ref: referer }, - }); - expect(request[0].data.loc).to.deep.equal(referer); - expect(request[0].data.referer).to.deep.equal(referer); - }); - - it('should makes the values of loc query and referer query geparams value when bidderRequest.refererInfo.referer is a falsy value', function () { - const loc = 'https://www.google.com/'; - const referer = 'https://example.com/'; - window.geparams = { - loc: 'https://www.google.com/', - ref: 'https://example.com/', - }; - const request = spec.buildRequests([ - getGeparamsDefinedBid(BANNER_BID, { loc: loc, ref: referer }), - ]); - expect(request[0].data.loc).to.deep.equal(encodeURIComponent(loc)); - expect(request[0].data.referer).to.deep.equal(encodeURIComponent(referer)); - }); - - it('should sets the value of the ct0 query to geparams.ct0', function () { - const ct0 = 'hoge'; - window.geparams = { - ct0: 'hoge', - }; - const request = spec.buildRequests([ - getGeparamsDefinedBid(BANNER_BID, { ct0: ct0 }), - ]); - expect(request[0].data.ct0).to.deep.equal(ct0); - }); - - it('should replaces currency with JPY if there is no currency provided', function () { - const request = spec.buildRequests([BANNER_BID]); - expect(request[0].data.cur).to.deep.equal('JPY'); - }); - - it('should makes currency the value of params.currency when params.currency exists', function () { - const request = spec.buildRequests([ - { - ...BANNER_BID, - params: { ...BANNER_BID.params, currency: 'JPY' }, - }, - { - ...BANNER_BID, - params: { ...BANNER_BID.params, currency: 'USD' }, - }, - ]); - expect(request[0].data.cur).to.deep.equal('JPY'); - expect(request[1].data.cur).to.deep.equal('USD'); - }); - - it('should not sets the value of the adtk query when geparams.lat does not exist', function () { - const request = spec.buildRequests([BANNER_BID]); - expect(request[0].data).to.not.have.property('adtk'); - }); - - it('should sets the value of the adtk query to 0 when geparams.lat is truthy value', function () { - window.geparams = { - lat: 1, - }; - const request = spec.buildRequests([ - getGeparamsDefinedBid(BANNER_BID, { lat: 1 }), - ]); - expect(request[0].data.adtk).to.deep.equal('0'); - }); - - it('should sets the value of the adtk query to 1 when geparams.lat is falsy value', function () { - window.geparams = { - lat: 0, - }; - const request = spec.buildRequests([ - getGeparamsDefinedBid(BANNER_BID, { lat: 0 }), - ]); - expect(request[0].data.adtk).to.deep.equal('1'); - }); - - it('should sets the value of the idfa query to geparams.idfa', function () { - const idfa = 'hoge'; - window.geparams = { - idfa: 'hoge', - }; - const request = spec.buildRequests([ - getGeparamsDefinedBid(BANNER_BID, { idfa: idfa }), - ]); - expect(request[0].data.idfa).to.deep.equal(idfa); - }); - - it('should set the sw query to screen.height and the sh query to screen.width when screen.width is greater than screen.height', function () { - const width = 1440; - const height = 900; - const stub = sinon.stub(window, 'screen').get(function () { - return { width: width, height: height }; - }); - const request = spec.buildRequests([BANNER_BID]); - expect(request[0].data.sw).to.deep.equal(height); - expect(request[0].data.sh).to.deep.equal(width); - stub.restore(); - }); - - it('should set the sw query to screen.width and the sh query to screen.height when screen.width is not greater than screen.height', function () { - const width = 411; - const height = 731; - const stub = sinon.stub(window, 'screen').get(function () { - return { width: width, height: height }; - }); - const request = spec.buildRequests([BANNER_BID]); - expect(request[0].data.sw).to.deep.equal(width); - expect(request[0].data.sh).to.deep.equal(height); - stub.restore(); - }); - - hasParamsNotBlankStringTestGeparams('zip', 'zip'); - hasParamsNotBlankStringTestGeparams('country', 'country'); - hasParamsNotBlankStringTestGeparams('city', 'city'); - hasParamsNotBlankStringTestGeparams('long', 'long'); - hasParamsNotBlankStringTestGeparams('lati', 'lati'); - - it('should set the custom query to geparams.custom', function () { - const params = { - custom: { - c1: undefined, - c2: null, - c3: '', - c4: 'hoge', - }, - }; - window.geparams = { - custom: { - c1: undefined, - c2: null, - c3: '', - c4: 'hoge', - }, - }; - const request = spec.buildRequests([ - getGeparamsDefinedBid(BANNER_BID, params), - ]); - expect(request[0].data).to.not.have.property('custom_c1'); - expect(request[0].data).to.not.have.property('custom_c2'); - expect(request[0].data).to.not.have.property('custom_c3'); - expect(request[0].data.custom_c4).to.have.string( - `${params.custom.c4}` - ); - }); - - hasParamsNotBlankStringTestGecuparams('ver', 'gc_ver'); - hasParamsNotBlankStringTestGecuparams('minor', 'gc_minor'); - hasParamsNotBlankStringTestGecuparams('value', 'gc_value'); - - it('should sets the value of the gfuid query to geparams.gfuid', function () { - const gfuid = 'hoge'; - window.geparams = { - gfuid: 'hoge', - }; - const request = spec.buildRequests([ - getGeparamsDefinedBid(BANNER_BID, { gfuid: gfuid }), - ]); - expect(request[0].data).to.not.have.property('gfuid'); - }); - - it('should sets the value of the adt query to geparams.adt', function () { - const adt = 'hoge'; - window.geparams = { - adt: 'hoge', - }; - const request = spec.buildRequests([ - getGeparamsDefinedBid(BANNER_BID, { adt: adt }), - ]); - expect(request[0].data).to.not.have.property('adt'); - }); - - it('should adds a query for naive ads and no query for banner ads', function () { - // const query = '&tkf=1&ad_track=1&apiv=1.1.0'; - const query_apiv = '1.1.0'; - const query_tkf = '1'; - const query_ad_track = '1'; - const request = spec.buildRequests([BANNER_BID]); - expect(String(request[0].data.apiv)).to.not.have.string(query_apiv); - expect(String(request[0].data.tkf)).to.not.have.string(query_tkf); - expect(String(request[0].data.ad_track)).to.not.have.string(query_ad_track); - }); - - it('should sets the value of the apid query to geparams.bundle when media type is banner', function () { - const bundle = 'hoge'; - window.geparams = { - bundle: 'hoge', - }; - const request = spec.buildRequests([ - getGeparamsDefinedBid(BANNER_BID, { bundle: bundle }), - ]); - expect(request[0].data.apid).to.deep.equal(bundle); - }); - - it('should include only imuid in extuid query when only imuid exists', function () { - const imuid = 'b.a4ad1d3eeb51e600'; - const request = spec.buildRequests([{...BANNER_BID, userId: {imuid}}]); - expect(request[0].data.extuid).to.deep.equal(`im:${imuid}`); - }); - - it('should include only id5id in extuid query when only id5id exists', function () { - const id5id = 'id5id'; - const request = spec.buildRequests([{...BANNER_BID, userId: {id5id: {uid: id5id}}}]); - expect(request[0].data.extuid).to.deep.equal(`id5:${id5id}`); - }); - - it('should include id5id and imuid in extuid query when id5id and imuid exists', function () { - const imuid = 'b.a4ad1d3eeb51e600'; - const id5id = 'id5id'; - const request = spec.buildRequests([{...BANNER_BID, userId: {id5id: {uid: id5id}, imuid: imuid}}]); - expect(request[0].data.extuid).to.deep.equal(`id5:${id5id}\tim:${imuid}`); - }); - - it('should not include the extuid query when both id5 and imuid are missing', function () { - const request = spec.buildRequests([BANNER_BID]); - expect(request[0].data).to.not.have.property('extuid'); - }); - - describe('buildExtuidQuery', function() { - it('should return tab-separated string when both id5 and imuId exist', function() { - const result = buildExtuidQuery({ id5: 'test_id5', imuId: 'test_imu' }); - expect(result).to.equal('id5:test_id5\tim:test_imu'); - }); - - it('should return only id5 when imuId is missing', function() { - const result = buildExtuidQuery({ id5: 'test_id5', imuId: null }); - expect(result).to.equal('id5:test_id5'); - }); - - it('should return only imuId when id5 is missing', function() { - const result = buildExtuidQuery({ id5: null, imuId: 'test_imu' }); - expect(result).to.equal('im:test_imu'); - }); - - it('should return null when both id5 and imuId are missing', function() { - const result = buildExtuidQuery({ id5: null, imuId: null }); - expect(result).to.be.null; - }); - }); - - it('should include gpid when ortb2Imp.ext.gpid exists', function () { - const gpid = '/123/abc'; - const bidWithGpid = { - ...BANNER_BID, - ortb2Imp: { - ext: { - gpid: gpid - } - } - }; - const request = spec.buildRequests([bidWithGpid]); - expect(String(request[0].data.gpid)).to.have.string(gpid); - }); - - it('should include gpid when ortb2Imp.ext.gpid exists', function () { - const gpid = '/123/abc'; - const bidWithPbadslot = { - ...BANNER_BID, - ortb2Imp: { - ext: { - gpid - } - } - }; - const request = spec.buildRequests([bidWithPbadslot]); - expect(String(request[0].data.gpid)).to.have.string(gpid); - }); - - it('should not include gpid when neither ortb2Imp.ext.gpid nor ortb2Imp.ext.data.pbadslot exists', function () { - const request = spec.buildRequests([BANNER_BID]); - expect(request[0].data).to.not.have.property('gpid'); - }); - }); - }); - - describe('interpretResponse', function () { - const response = {}; - response[ZONE_ID] = { - creativeId: '', - cur: 'JPY', - price: 0.092, - width: 300, - height: 250, - requestid: '2e42361a6172bf', - adm: '', - }; - const expected = { - requestId: response[ZONE_ID].requestid, - cpm: response[ZONE_ID].price, - creativeId: response[ZONE_ID].creativeId, - netRevenue: true, - currency: 'JPY', - ttl: 700, - width: response[ZONE_ID].width, - height: response[ZONE_ID].height, - }; - - it('should sets the response correctly when it comes to banner ads', function () { - const expectedBanner = { - ...expected, - ad: - '
' + - response[ZONE_ID].adm + - '
', - mediaType: 'banner', - }; - const request = spec.buildRequests([BANNER_BID])[0]; - const result = spec.interpretResponse({ body: response }, request); - expect(result[0]).to.deep.equal(expectedBanner); - }); - }); - - describe('getUserSyncs', function () { - const syncOptions = { - pixelEnabled: true, - iframeEnabled: true, - }; - const responseBase = { - creativeId: '', - cur: 'JPY', - price: 0.092, - width: 300, - height: 250, - requestid: '2e42361a6172bf', - adm: '', - }; - - it('should return an array of length 1 when adm contains one mcs endpoint', function () { - const response = [{ - body: { - [ZONE_ID]: { - ...responseBase, - adm: '%5c%22https%3a%5c%2f%5c%2fcs.gssprt.jp%5c%2fyie%5c%2fld%5c%2fmcs%3fver%3d1%26dspid%3dlamp%26format%3dgif%26vid%3d1%5c%22%20style%3d' - } - } - }] - const result = spec.getUserSyncs(syncOptions, response); - expect(result).to.have.deep.equal([{ - type: 'image', - url: 'https://cs.gssprt.jp/yie/ld/mcs?ver=1&dspid=lamp&format=gif&vid=1', - }]); - }); - - it('should return an array of length 2 when adm contains two mcs endpoints', function () { - const response = [{ - body: { - [ZONE_ID]: { - ...responseBase, - adm: '%5c%22https%3a%5c%2f%5c%2fcs.gssprt.jp%5c%2fyie%5c%2fld%5c%2fmcs%3fver%3d1%26dspid%3dlamp%26format%3dgif%26vid%3d1%5c%22%20style%3d%5c%22display%3a%20none%3b%20visibility%3a%20hidden%3b%5c%22%20%5c%2f%3e%3cimg%20src%3d%5c%22https%3a%5c%2f%5c%2fcs.gssprt.jp%5c%2fyie%5c%2fld%5c%2fmcs%3fver%3d1%26dspid%3drtbhouse%26format%3dgif%26vid%3d1%5c%22%20style%3d%5c%22display%3a' - } - } - }] - const result = spec.getUserSyncs(syncOptions, response); - expect(result).to.have.deep.equal([{ - type: 'image', - url: 'https://cs.gssprt.jp/yie/ld/mcs?ver=1&dspid=lamp&format=gif&vid=1', - }, { - type: 'image', - url: 'https://cs.gssprt.jp/yie/ld/mcs?ver=1&dspid=rtbhouse&format=gif&vid=1', - }]); - }); - - it('should return an empty array When adm does not include the mcs endpoint', function () { - const response = [{ - body: { - [ZONE_ID]: responseBase - } - }] - const result = spec.getUserSyncs(syncOptions, response); - expect(result).to.have.deep.equal([]); - }); - - it('should return an iframe sync when cs_url exists and iframeEnabled is true', function () { - const csUrlParam = '/cshtml?ver=1&dspid=lamp&format=html'; - const response = [{ - body: { - [ZONE_ID]: { - ...responseBase, - cs_url: csUrlParam - } - } - }]; - const result = spec.getUserSyncs(syncOptions, response); - expect(result).to.have.deep.equal([{ - type: 'iframe', - url: `https://aladdin.genieesspv.jp/yie/ld${csUrlParam}`, - }]); - }); - - it('should prioritize iframe sync over image sync when cs_url exists', function () { - const csUrlParam = '/cshtml?ver=1&dspid=lamp&format=html'; - const response = [{ - body: { - [ZONE_ID]: { - ...responseBase, - cs_url: csUrlParam, - adm: '%5c%22https%3a%5c%2f%5c%2fcs.gssprt.jp%5c%2fyie%5c%2fld%5c%2fmcs%3fver%3d1%26dspid%3dlamp%26format%3dgif%26vid%3d1%5c%22%20style%3d' // admも含む - } - } - }]; - const result = spec.getUserSyncs(syncOptions, response); - expect(result).to.have.deep.equal([{ - type: 'iframe', - url: `https://aladdin.genieesspv.jp/yie/ld${csUrlParam}`, - }]); - }); - - it('should return an image sync when cs_url does not exist but adm contains mcs endpoint and pixelEnabled is true, even if iframeEnabled is false', function () { - const response = [{ - body: { - [ZONE_ID]: { - ...responseBase, - adm: '%5c%22https%3a%5c%2f%5c%2fcs.gssprt.jp%5c%2fyie%5c%2fld%5c%2fmcs%3fver%3d1%26dspid%3dlamp%26format%3dgif%26vid%3d1%5c%22%20style%3d' - } - } - }]; - const result = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: false }, response); - expect(result).to.have.deep.equal([{ - type: 'image', - url: 'https://cs.gssprt.jp/yie/ld/mcs?ver=1&dspid=lamp&format=gif&vid=1', - }]); - }); - - it('should return an empty array when cs_url exists but iframeEnabled is false and adm does not contain mcs endpoint', function () { - const csUrlParam = '/cshtml?ver=1&dspid=lamp&format=html'; - const response = [{ - body: { - [ZONE_ID]: { - ...responseBase, - cs_url: csUrlParam, - adm: '' - } - } - }]; - const result = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: false }, response); - expect(result).to.have.deep.equal([]); - }); - - it('should return correct sync objects when responses contain cs_url, adm or empty body with syncOptions (both true)', function () { - const csUrlParam = '/cshtml?ver=1&dspid=lamp&format=html'; - const response = [{ - body: { - [ZONE_ID]: { - ...responseBase, - cs_url: csUrlParam - } - } - }, { - body: { - 1345678: { - ...responseBase, - adm: '%5c%22https%3a%5c%2f%5c%2fcs.gssprt.jp%5c%2fyie%5c%2fld%5c%2fmcs%3fver%3d1%26dspid%3dappier%26format%3dgif%26vid%3d1%5c%22%20style%3d' - } - } - }, { - body: '' - }]; - const result = spec.getUserSyncs(syncOptions, response); - expect(result).to.have.deep.equal([{ - type: 'iframe', - url: `https://aladdin.genieesspv.jp/yie/ld${csUrlParam}`, - }, { - type: 'image', - url: 'https://cs.gssprt.jp/yie/ld/mcs?ver=1&dspid=appier&format=gif&vid=1', - }]); - }); - - it('should return an iframe sync when iframeEnabled is true and cs_url exists', function () { - const csUrlParam = '/cshtml?ver=1&dspid=lamp&format=html'; - const response = [{ - body: { - [ZONE_ID]: { - ...responseBase, - cs_url: csUrlParam - } - } - }]; - const result = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: false }, response); - expect(result).to.have.deep.equal([{ - type: 'iframe', - url: `https://aladdin.genieesspv.jp/yie/ld${csUrlParam}`, - }]); - }); - - it('should not return an iframe sync when iframeEnabled is true but cs_url does not exist', function () { - const response = [{ - body: { - [ZONE_ID]: { - ...responseBase, - } - } - }]; - const result = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: false }, response); - expect(result).to.have.deep.equal([]); - }); - - it('should create an object for each response and return an array when there are multiple responses', function () { - const response = [{ - body: { - [ZONE_ID]: { - ...responseBase, - adm: '%5c%22https%3a%5c%2f%5c%2fcs.gssprt.jp%5c%2fyie%5c%2fld%5c%2fmcs%3fver%3d1%26dspid%3dlamp%26format%3dgif%26vid%3d1%5c%22%20style%3d' - } - } - }, { - body: { - [ZONE_ID]: { - ...responseBase, - adm: '%5c%22https%3a%5c%2f%5c%2fcs.gssprt.jp%5c%2fyie%5c%2fld%5c%2fmcs%3fver%3d1%26dspid%3drtbhouse%26format%3dgif%26vid%3d1%5c%22%20style%3d' - } - } - }]; - const result = spec.getUserSyncs(syncOptions, response); - expect(result).to.have.deep.equal([{ - type: 'image', - url: 'https://cs.gssprt.jp/yie/ld/mcs?ver=1&dspid=lamp&format=gif&vid=1', - }, { - type: 'image', - url: 'https://cs.gssprt.jp/yie/ld/mcs?ver=1&dspid=rtbhouse&format=gif&vid=1', - }]); - }); - }); -}); diff --git a/test/spec/modules/stackadaptBidAdapter_spec.js b/test/spec/modules/stackadaptBidAdapter_spec.js deleted file mode 100644 index 00c799b52..000000000 --- a/test/spec/modules/stackadaptBidAdapter_spec.js +++ /dev/null @@ -1,1391 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/stackadaptBidAdapter'; -import { deepClone, mergeDeep, deepSetValue } from 'src/utils.js'; -import { config } from 'src/config'; - -describe('stackadaptBidAdapter', function () { - describe('intepretResponse() mediatypes - complete', () => { - const defaultBidRequest = { - 'bidderRequestId': '2856b3d7c2c8e93e', - 'bidder': 'stackadapt', - 'params': { - 'publisherId': 473298, - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [336, 280], - [320, 100] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'aa837ec1-ba90-3821-jduq-1cc083921a9a', - 'sizes': [ - [336, 280], - [320, 100] - ], - 'bidId': '001', - 'auctionId': '8d6e5b89-9c9f-4f25-9d4f-e4c08b0b9d7f', - 'ortb2': {} - }; - - const ortbResponse = { - 'body': { - 'id': '2856b3d7c2c8e93e', - 'seatbid': [ - { - 'bid': [ - { - 'id': '1', - 'impid': '001', - 'price': 6.97, - 'adid': '5739901', - 'adm': '', - 'adomain': ['mobility.com'], - 'crid': '5739901', - 'w': 336, - 'h': 280, - } - ], - 'seat': 'StackAdapt' - } - ], - 'cur': 'USD' - }, - 'headers': {} - } - - it('should return empty', () => { - const req = spec.buildRequests([defaultBidRequest], { - bids: [defaultBidRequest] - }) - const result = spec.interpretResponse(null, { - data: req.data - }) - - expect(result.length).to.eq(0); - }); - - it('should set mediaType from bid request mediaTypes', () => { - const req = spec.buildRequests([defaultBidRequest], { - id: '832j6c82-893j-21j9-8392-4wd9d82pl739', - bidderRequestId: '2856b3d7c2c8e93e', - bids: [defaultBidRequest] - }) - const result = spec.interpretResponse(ortbResponse, { - data: req.data - }) - - expect(result.length).to.eq(1); - expect(result[0].mediaType).to.eq('banner') - }); - - it('should set mediaType from present video adm', () => { - const bidRequest = mergeDeep(defaultBidRequest, { - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - }, - video: { - playerSize: [640, 480] - } - } - }) - const bannerResponse = deepClone(ortbResponse); - const ortbReq = spec.buildRequests([bidRequest], { - bids: [bidRequest] - }) - deepSetValue(bannerResponse, 'body.seatbid.0.bid.0.adm', ''); - const result = spec.interpretResponse(bannerResponse, { - data: ortbReq.data - }) - - expect(result.length).to.eq(1); - expect(result[0].mediaType).to.eq('video') - }); - - it('should set mediaType from missing adm', () => { - const bidRequest = mergeDeep(defaultBidRequest, { - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - }, - video: { - playerSize: [640, 480] - } - } - }) - const ortbReq = spec.buildRequests([bidRequest], { - bids: [bidRequest] - }) - const result = spec.interpretResponse(ortbResponse, { - data: ortbReq.data - }) - - expect(result.length).to.eq(1); - expect(result[0].mediaType).to.eq('banner') - }); - }) - - describe('interpretResponse() empty', function () { - it('should handle empty response', function () { - const result = spec.interpretResponse({}); - expect(result.length).to.equal(0); - }); - - it('should handle empty seatbid response', function () { - const response = { - body: { - 'id': '9p1a65c0oc85a62', - 'seatbid': [] - } - }; - const result = spec.interpretResponse(response); - expect(result.length).to.equal(0); - }); - }); - - describe('interpretResponse() single-display - complete', function () { - const ortbResponse = { - body: { - 'id': '5ce18294-9682-4ad0-1c92-0ab12bg8dc5e', - 'bidid': '173283728930905039521896', - 'seatbid': [ - { - 'bid': [ - { - 'id': '1', - 'impid': '5', - 'crid': '1609382', - 'price': 6.97, - 'adm': '', - 'cat': [ - 'IAB1', - 'IAB2' - ], - 'h': 50, - 'w': 320, - 'dealid': '189321890321', - 'adomain': ['mobility.com'], - 'ext': { - 'creative_id': '8493266', - 'bid_type': 'cpm', - 'crtype': 'display' - } - } - ], - 'seat': 'StackAdapt' - } - ], - 'cur': 'USD', - } - }; - - const bidderRequest = { - 'id': '832j6c82-893j-21j9-8392-4wd9d82pl739', - 'bidder': 'stackadapt', - 'params': { - 'publisherId': 473298, - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 320, - 50 - ] - ] - } - }, - 'sizes': [ - [ - 320, - 50 - ] - ], - 'bidId': '5', - 'bidderRequestId': '5ce18294-9682-4ad0-1c92-0ab12bg8dc5e', - 'auctionId': '8d6e5b89-9c9f-4f25-9d4f-e4c08b0b9d7f', - 'ortb2': {} - }; - - const expectedBid = { - 'requestId': '5', - 'seatBidId': '1', - 'cpm': 6.97, - 'width': 320, - 'height': 50, - 'creativeId': '1609382', - 'creative_id': '1609382', - 'dealId': '189321890321', - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'ad': '', - 'mediaType': 'banner', - 'meta': { - 'advertiserDomains': ['mobility.com'], - 'primaryCatId': 'IAB1', - 'secondaryCatIds': [ - 'IAB2' - ] - } - }; - - it('should match bid response', function () { - const ortbRequest = spec.buildRequests([bidderRequest], { - bids: [bidderRequest] - }) - - const result = spec.interpretResponse(ortbResponse, {data: ortbRequest.data}); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal(expectedBid); - }); - }); - - describe('interpretResponse() multi-display - complete', function () { - const ortbResponse = { - 'body': { - 'id': 'r4r90kj7-2816-392j-1d41-31y998t21d2d', - 'seatbid': [ - { - 'bid': [ - { - 'id': '1', - 'impid': '001', - 'price': 3.50, - 'adm': '', - 'cid': '4521903', - 'crid': '6254972', - 'adomain': [ - 'test.com' - ], - 'dealid': '122781928112', - 'w': 320, - 'h': 50, - 'cat': [], - }, - { - 'id': '2', - 'impid': '002', - 'price': 4.75, - 'adm': '', - 'cid': '8472189', - 'crid': '8593271', - 'adomain': [ - 'test.com' - ], - 'dealid': '849328172299', - 'w': 300, - 'h': 250, - 'cat': [], - } - ], - 'seat': 'StackAdapt' - } - ], - 'cur': 'USD' - } - }; - - const bidderRequest1 = { - 'id': '11dd91ds-197k-23e1-9950-q79s37aq0a42', - 'bidder': 'stackadapt', - 'params': { - 'publisherId': 473298, - 'placementId': 'placement1' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 320, - 50 - ] - ] - } - }, - 'sizes': [ - [ - 320, - 50 - ] - ], - 'bidId': '001', - 'bidderRequestId': 'r4r90kj7-2816-392j-1d41-31y998t21d2d', - 'auctionId': '7483329d-22il-2hyu-1d78-1098qw89457l', - 'ortb2': {} - }; - - const bidderRequest2 = { - 'id': '11dd91ds-197k-23e1-9950-q79s37aq0a43', - 'bidder': 'stackadapt', - 'params': { - 'publisherId': 473298, - 'placementId': 'placement2' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 728, - 90 - ] - ] - } - }, - 'sizes': [ - [ - 728, - 90 - ] - ], - 'bidId': '002', - 'bidderRequestId': 'r4r90kj7-2816-392j-1d41-31y998t21d2d', - 'auctionId': '7483329d-22il-2hyu-1d78-1098qw89457l', - 'ortb2': {} - }; - - const expectedBids = [ - { - 'requestId': '001', - 'seatBidId': '1', - 'cpm': 3.5, - 'width': 320, - 'height': 50, - 'creativeId': '6254972', - 'creative_id': '6254972', - 'currency': 'USD', - 'dealId': '122781928112', - 'netRevenue': true, - 'ttl': 300, - 'ad': '', - 'mediaType': 'banner', - 'meta': { - 'advertiserDomains': ['test.com'], - 'primaryCatId': undefined, - 'secondaryCatIds': [] - } - }, - { - 'requestId': '002', - 'seatBidId': '2', - 'cpm': 4.75, - 'width': 300, - 'height': 250, - 'creativeId': '8593271', - 'creative_id': '8593271', - 'currency': 'USD', - 'dealId': '849328172299', - 'netRevenue': true, - 'ttl': 300, - 'ad': '', - 'mediaType': 'banner', - 'meta': { - 'advertiserDomains': ['test.com'], - 'primaryCatId': undefined, - 'secondaryCatIds': [] - } - } - ]; - - it('should match bid response', function () { - const ortbRequest = spec.buildRequests([bidderRequest1, bidderRequest2], { - bids: [bidderRequest1, bidderRequest2] - }) - const result = spec.interpretResponse(ortbResponse, {data: ortbRequest.data}); - expect(result.length).to.equal(2); - expect(result).to.deep.equal(expectedBids); - }); - }); - - if (FEATURES.VIDEO) { - describe('interpretResponse() single-video - complete', function () { - const ortbResponse = { - 'body': { - 'id': '5ce18294-9682-4ad0-1c92-0ab12bg8dc5e', - 'bidid': '173283728930905039521879', - 'cur': 'USD', - 'seatbid': [ - { - 'bid': [ - { - 'crid': '6254972', - 'ext': { - 'creative_id': '1762289', - 'bid_type': 'cpm', - 'duration': 30, - }, - 'adm': '', - 'h': 480, - 'impid': '001', - 'id': '1', - 'price': 11.5, - 'w': 600 - } - ], - 'seat': 'StackAdapt' - } - ] - }, - 'headers': {} - }; - - const bidderRequest = { - 'id': '748a3c21-908a-25j9-4301-2ca9d11al199', - 'bidder': 'stackadapt', - 'params': { - 'publisherId': 473298, - }, - 'mediaTypes': { - 'video': {} - }, - 'bidId': '001', - 'bidderRequestId': '5ce18294-9682-4ad0-1c92-0ab12bg8dc5e', - 'auctionId': '8d6e5b89-9c9f-4f25-9d4f-e4c08b0b9d7f', - 'ortb2': {} - }; - - const expectedBid = { - 'requestId': '001', - 'seatBidId': '1', - 'cpm': 11.5, - 'creativeId': '6254972', - 'creative_id': '6254972', - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'width': 600, - 'height': 480, - 'mediaType': 'video', - 'vastXml': '', - 'meta': {} - }; - - it('should match bid response with adm', function () { - const ortbRequest = spec.buildRequests([bidderRequest], { - bids: [bidderRequest] - }) - - const result = spec.interpretResponse(ortbResponse, {data: ortbRequest.data}); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal(expectedBid); - }); - }); - } - - describe('isBidRequestValid()', function() { - const bannerBidderRequest = { - 'bidder': 'stackadapt', - 'params': { - 'publisherId': '11111', - 'placementId': '1' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [200, 50] - ] - } - }, - 'bidId': '001', - 'bidderRequestId': '5ce18294-9682-4ad0-1c92-0ab12bg8dc5e', - 'auctionId': '8d6e5b89-9c9f-4f25-9d4f-e4c08b0b9d7f', - }; - - describe('basic tests', function () { - it('should be valid with required bid.params', function () { - expect(spec.isBidRequestValid(bannerBidderRequest)).to.equal(true); - }); - - it('should be invalid when missing publisherId param', function () { - const bidderRequest = deepClone(bannerBidderRequest); - delete bidderRequest.params.publisherId; - expect(spec.isBidRequestValid(bidderRequest)).to.equal(false); - }); - - it('should be invalid if bid request is not mediaTypes.banner or mediaTypes.video', function () { - const bidderRequest = deepClone(bannerBidderRequest); - delete bidderRequest.mediaTypes - expect(spec.isBidRequestValid(bidderRequest)).to.equal(false); - }); - - it('should be invalid if bidfloor is incorrect type', function () { - const bidderRequest = deepClone(bannerBidderRequest); - bidderRequest.params.bidfloor = 'invalid bidfloor'; - expect(spec.isBidRequestValid(bidderRequest)).to.equal(false); - }); - - it('should be valid if bidfloor param is a float', function () { - const bidderRequest = deepClone(bannerBidderRequest); - bidderRequest.params.bidfloor = 3.01; - expect(spec.isBidRequestValid(bidderRequest)).to.equal(true); - }); - }); - - describe('banner tests', function () { - it('should be invalid if banner sizes is wrong format', function () { - const bidderRequest = deepClone(bannerBidderRequest); - bidderRequest.mediaTypes.banner.sizes = 'invalid'; - expect(spec.isBidRequestValid(bidderRequest)).to.equal(false); - }); - - it('should be invalid if missing banner sizes', function () { - const bidderRequest = deepClone(bannerBidderRequest); - delete bidderRequest.mediaTypes.banner.sizes; - expect(spec.isBidRequestValid(bidderRequest)).to.equal(false); - }); - - it('should be invalid when passed valid banner.pos', function () { - const bidderRequest = deepClone(bannerBidderRequest); - bidderRequest.mediaTypes.banner.pos = 1; - expect(spec.isBidRequestValid(bidderRequest)).to.equal(true); - }); - }); - - if (FEATURES.VIDEO) { - describe('video tests', function () { - const videoBidderRequest = { - 'bidder': 'stackadapt', - 'params': { - 'publisherId': '11111', - 'placementId': '1' - }, - 'mediaTypes': { - 'video': { - 'maxduration': 120, - 'api': [2, 7], - 'mimes': [ - 'video/mp4', - 'application/javascript', - 'video/webm' - ], - 'protocols': [2, 3, 5, 6, 7, 8], - 'plcmt': 1, - } - }, - 'sizes': [ - [200, 50] - ], - 'bidId': '001', - 'bidderRequestId': '5ce18294-9682-4ad0-1c92-0ab12bg8dc5e', - 'auctionId': '8d6e5b89-9c9f-4f25-9d4f-e4c08b0b9d7f', - }; - - it('should be valid with required bid.params', function () { - const bidderRequest = deepClone(videoBidderRequest); - expect(spec.isBidRequestValid(bidderRequest)).to.equal(true); - }); - - it('should be invalid if missing bid.mediaTypes.video.maxduration', function () { - const bidderRequest = deepClone(videoBidderRequest); - delete bidderRequest.mediaTypes.video.maxduration; - expect(spec.isBidRequestValid(bidderRequest)).to.equal(false); - }); - - it('should be invalid if missing bid.mediaTypes.video.api', function () { - const bidderRequest = deepClone(videoBidderRequest); - delete bidderRequest.mediaTypes.video.api; - expect(spec.isBidRequestValid(bidderRequest)).to.equal(false); - }); - - it('should be invalid if missing bid.mediaTypes.video.mimes', function () { - const bidderRequest = deepClone(videoBidderRequest); - delete bidderRequest.mediaTypes.video.mimes; - expect(spec.isBidRequestValid(bidderRequest)).to.equal(false); - }); - - it('should be invalid if missing bid.mediaTypes.video.protocols', function () { - const bidderRequest = deepClone(videoBidderRequest); - delete bidderRequest.mediaTypes.video.protocols; - expect(spec.isBidRequestValid(bidderRequest)).to.equal(false); - }); - }); - } - }); - - describe('buildRequests() banner', function () { - const bidRequests = [{ - 'bidder': 'stackadapt', - 'params': { - 'publisherId': '11111', - 'placementId': '1', - 'bidfloor': 1.01 - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[336, 280], [320, 100]] - } - }, - 'ortb2Imp': { - 'ext': { - 'tid': '2121283921', - } - }, - 'sizes': [[336, 280], [320, 100]], - 'bidId': '001', - 'bidderRequestId': '5ce18294-9682-4ad0-1c92-0ab12bg8dc5e', - 'auctionId': '8d6e5b89-9c9f-4f25-9d4f-e4c08b0b9d7f', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'aa837ec1-ba90-3821-jduq-1cc083921a9a', - 'src': 'client', - 'bidRequestsCount': 10 - }]; - - const bidderRequest = { - 'bidderCode': 'stackadapt', - 'auctionId': '8d6e5b89-9c9f-4f25-9d4f-e4c08b0b9d7f', - ortb2: { - source: { - tid: '8d6e5b89-9c9f-4f25-9d4f-e4c08b0b9d7f', - }, - site: { - domain: 'tech.stacktest.com', - publisher: { - domain: 'stacktest.com' - }, - page: 'https://tech.stacktest.com/', - ref: 'https://www.google.com/' - } - }, - 'bidderRequestId': '5ce18294-9682-4ad0-1c92-0ab12bg8dc5e', - 'auctionStart': 1731042158610, - 'timeout': 1750, - 'refererInfo': { - 'reachedTop': true, - 'numIframes': 0, - 'isAmp': false, - 'page': 'https://www.mobile.com/test', - 'domain': 'www.mobile.com', - 'ref': 'https://testsite.com/', - }, - 'start': 1731042158587 - }; - - bidderRequest.bids = bidRequests; - - it('should have correct request components', function () { - const ortbRequest = spec.buildRequests(bidRequests, bidderRequest); - expect(ortbRequest.method).to.equal('POST'); - expect(ortbRequest.url).to.be.not.empty; - expect(ortbRequest.data).to.be.not.null; - }); - - it('should set ortb request.id to bidderRequestId', function () { - const ortbRequest = spec.buildRequests(bidRequests, bidderRequest).data; - expect(ortbRequest.id).to.equal('5ce18294-9682-4ad0-1c92-0ab12bg8dc5e'); - }); - - it('should set impression id from bidId', function () { - const ortbRequest = spec.buildRequests(bidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].id).to.equal('001'); - }); - - it('should set correct endpoint', function () { - const ortbRequest = spec.buildRequests(bidRequests, bidderRequest); - expect(ortbRequest.url).to.equal('https://pjs.srv.stackadapt.com/br'); - }); - - it('should set correct publisherId', function () { - const ortbRequest = spec.buildRequests(bidRequests, bidderRequest).data; - expect(ortbRequest.site?.publisher?.id).to.equal(bidRequests[0].params.publisherId); - }); - - it('should set placementId in tagid', function () { - const ortbRequest = spec.buildRequests(bidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].tagid).to.equal(bidRequests[0].params.placementId); - }); - - it('should set bidfloor if param set', function () { - const ortbRequest = spec.buildRequests(bidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].bidfloor).to.equal(bidRequests[0].params.bidfloor); - }); - - it('should set gpid in ortb ext.gpid if present', function () { - const clonedBidderRequest = deepClone(bidderRequest); - const clonedBidRequests = deepClone(bidRequests); - const gpid = 'site-desktop-homepage-banner-top'; - clonedBidRequests[0].ortb2Imp = { - ext: { - gpid: gpid - } - }; - clonedBidderRequest.bids = clonedBidRequests; - const ortbRequest = spec.buildRequests(clonedBidRequests, clonedBidderRequest).data; - - expect(ortbRequest.imp[0].ext).to.be.not.null; - expect(ortbRequest.imp[0].ext.gpid).to.equal(gpid); - }); - - it('should set rwdd in imp.rwdd if present', function () { - const clonedBidderRequest = deepClone(bidderRequest); - const clonedBidRequests = deepClone(bidRequests); - const rwdd = 1; - clonedBidRequests[0].ortb2Imp = { - rwdd: rwdd, - }; - clonedBidderRequest.bids = clonedBidRequests; - const ortbRequest = spec.buildRequests(clonedBidRequests, clonedBidderRequest).data; - - expect(ortbRequest.imp[0].rwdd).to.be.not.null; - expect(ortbRequest.imp[0].rwdd).to.equal(1); - }); - - it('should set source.tid', function () { - const ortbRequest = spec.buildRequests(bidRequests, bidderRequest).data; - expect(ortbRequest.source?.tid).to.equal(bidderRequest.ortb2.source.tid); - }); - - it('should set ad sizes in the ortb request', function () { - const ortbRequest = spec.buildRequests(bidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].banner.format[0].w).to.equal(336); - expect(ortbRequest.imp[0].banner.format[0].h).to.equal(280); - expect(ortbRequest.imp[0].banner.format[1].w).to.equal(320); - expect(ortbRequest.imp[0].banner.format[1].h).to.equal(100); - }); - - it('should set referer in the bid request. ortb object takes precedence', function () { - const ortbRequest = spec.buildRequests(bidRequests, bidderRequest).data; - expect(ortbRequest.site.page).to.equal('https://tech.stacktest.com/'); - }); - - it('should set the banner pos if sent', function () { - const clonedBidderRequest = deepClone(bidderRequest); - const clonedBidRequests = deepClone(bidRequests); - clonedBidRequests[0].mediaTypes.banner.pos = 1; - clonedBidderRequest.bids = clonedBidRequests; - const ortbRequest = spec.buildRequests(clonedBidRequests, clonedBidderRequest).data; - - expect(ortbRequest.imp[0].banner.pos).to.equal(1); - }); - - it('should set the banner expansion direction if param set', function () { - const clonedBidderRequest = deepClone(bidderRequest); - const clonedBidRequests = deepClone(bidRequests); - const expdir = [1, 3] - clonedBidRequests[0].params.banner = { - expdir: expdir - }; - - clonedBidderRequest.bids = clonedBidRequests; - const ortbRequest = spec.buildRequests(clonedBidRequests, clonedBidderRequest).data; - - expect(ortbRequest.imp[0].banner.expdir).to.equal(expdir); - }); - - it('should set first party site data after merge', function () { - const ortb2 = { - site: { - publisher: { - domain: 'https://publisher.com', - } - } - }; - const bidderRequestWithoutRefererDomain = { - ...bidderRequest, - refererInfo: { - ...bidRequests.referer, - domain: null - } - } - - const ortbRequest = spec.buildRequests(bidRequests, {...bidderRequestWithoutRefererDomain, ortb2}).data; - expect(ortbRequest.site.publisher).to.deep.equal({domain: 'https://publisher.com', id: '11111'}); - }); - - it('should set first party side data publisher domain taking precedence over referer domain', function () { - const ortb2 = { - site: { - domain: 'https://publisher.com', - } - }; - const ortbRequest = spec.buildRequests(bidRequests, {...bidderRequest, ortb2}).data; - expect(ortbRequest.site.domain).to.equal('https://publisher.com'); - }); - - it('should set bcat if present', function () { - const ortb2 = { - bcat: ['IAB1', 'IAB2'] - }; - const ortbRequest = spec.buildRequests(bidRequests, {...bidderRequest, ortb2}).data; - expect(ortbRequest.bcat).to.deep.equal(['IAB1', 'IAB2']); - }); - - it('should set badv if present', function () { - const ortb2 = { - badv: ['chargers.com', 'house.com'] - }; - const ortbRequest = spec.buildRequests(bidRequests, {...bidderRequest, ortb2}).data; - expect(ortbRequest.badv).to.deep.equal(['chargers.com', 'house.com']); - }); - - it('should set battr if present', function () { - const clonedBidderRequest = deepClone(bidderRequest); - const clonedBidRequests = deepClone(bidRequests); - const battr = [1, 2, 3]; - clonedBidRequests[0].ortb2Imp = { - banner: { - battr: battr - } - }; - clonedBidderRequest.bids = clonedBidRequests; - const ortbRequest = spec.buildRequests(clonedBidRequests, clonedBidderRequest).data; - - expect(ortbRequest.imp[0].banner.battr).to.deep.equal(battr); - }); - - it('should set ortb2 gdpr consent info', function () { - const consentString = 'CQGRvoAQGRvoAAHABAENBKFsAP_gAEPgAAAAKhNV'; - const ortb2 = { - user: { - ext: { - consent: consentString - } - }, - regs: { - ext: { - gdpr: 1 - } - } - }; - const clonedBidderRequest = {...deepClone(bidderRequest), ortb2}; - const ortbRequest = spec.buildRequests(bidRequests, clonedBidderRequest).data; - expect(ortbRequest.user.ext.consent).to.equal(consentString); - expect(ortbRequest.regs.ext.gdpr).to.equal(1); - }); - - it('should set ortb2 usp consent info', function () { - const consentString = 'CQGRvoAQGRvoAAHABAENBKFsAP_gAEPgAAAAKhNV'; - const ortb2 = { - regs: { - ext: { - us_privacy: consentString - } - } - }; - const clonedBidderRequest = {...deepClone(bidderRequest), ortb2}; - const ortbRequest = spec.buildRequests(bidRequests, clonedBidderRequest).data; - expect(ortbRequest.regs.ext.us_privacy).to.equal(consentString); - }); - - it('should set ortb2 coppa consent info', function () { - const ortb2 = { - regs: { - coppa: 1 - } - }; - const clonedBidderRequest = {...deepClone(bidderRequest), ortb2}; - const ortbRequest = spec.buildRequests(bidRequests, clonedBidderRequest).data; - expect(ortbRequest.regs.coppa).to.equal(1); - }); - - it('should set ortb2 gpp consent info', function () { - const ortb2 = { - regs: { - gpp: 'DCACTA~1YAA', - gpp_sid: [9] - } - }; - const clonedBidderRequest = {...deepClone(bidderRequest), ortb2}; - const ortbRequest = spec.buildRequests(bidRequests, clonedBidderRequest).data; - expect(ortbRequest.regs.gpp).to.equal('DCACTA~1YAA'); - expect(ortbRequest.regs.gpp_sid).to.eql([9]); - }); - - it('should set schain info', function () { - const clonedBidderRequest = deepClone(bidderRequest); - const clonedBidRequests = deepClone(bidRequests); - const schain = { - 'nodes': [{ - 'asi': 'adtech.com', - 'sid': '1078492', - 'hp': 1 - }, { - 'asi': 'google.com', - 'sid': 'pub-315292981', - 'hp': 1 - }], - 'complete': 1, - 'ver': '1.0' - }; - - clonedBidRequests[0].ortb2 = { - source: { - ext: {schain: schain} - } - }; - clonedBidderRequest.bids = clonedBidRequests; - - // Add schain to bidderRequest as well - clonedBidderRequest.ortb2 = { - source: { - ext: {schain: schain} - } - }; - - const ortbRequest = spec.buildRequests(clonedBidRequests, clonedBidderRequest).data; - expect(ortbRequest.source.ext.schain).to.deep.equal(schain); - }); - - it('should set first party site data', function () { - const ortb2 = { - site: { - id: '144da00b-8309-4b2e-9482-4b3829c0b54a', - name: 'game', - domain: 'game.wiki.com', - cat: ['IAB1'], - sectioncat: ['IAB1-1'], - pagecat: ['IAB1-1'], - page: 'https://game.wiki.com/craft', - ref: 'https://www.google.com/', - keywords: 'device={}' - } - }; - const mergedBidderRequest = {...bidderRequest, ortb2}; - const ortbRequest = spec.buildRequests(bidRequests, mergedBidderRequest).data; - expect(ortbRequest.site.id).to.equal('144da00b-8309-4b2e-9482-4b3829c0b54a'); - expect(ortbRequest.site.name).to.equal('game'); - expect(ortbRequest.site.domain).to.equal('game.wiki.com'); - expect(ortbRequest.site.cat[0]).to.equal('IAB1'); - expect(ortbRequest.site.sectioncat[0]).to.equal('IAB1-1'); - expect(ortbRequest.site.pagecat[0]).to.equal('IAB1-1'); - expect(ortbRequest.site.page).to.equal('https://game.wiki.com/craft'); - expect(ortbRequest.site.ref).to.equal('https://www.google.com/'); - expect(ortbRequest.site.keywords).to.equal('device={}'); - }); - - it('should set from floor module if no bidfloor is sent', function () { - const clonedBidderRequests = deepClone(bidderRequest); - const clonedBidRequests = deepClone(bidRequests); - delete clonedBidRequests[0].params.bidfloor; - const bidfloor = 1.00 - clonedBidRequests[0].getFloor = () => { - return { currency: 'USD', floor: 1.00 }; - }; - clonedBidderRequests.bids = clonedBidRequests; - const ortbRequest = spec.buildRequests(clonedBidRequests, clonedBidderRequests).data; - expect(ortbRequest.imp[0].bidfloor).to.equal(bidfloor); - }); - - it('should set default secure value if not present', function () { - const ortbRequest = spec.buildRequests(bidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].secure).to.equal(1); - }); - - it('should set secure to request when present', function () { - const clonedBidderReqest = deepClone(bidderRequest); - const clonedBidRequests = deepClone(bidRequests); - clonedBidRequests[0].ortb2Imp.secure = 0; - clonedBidderReqest.bids = clonedBidRequests; - - let ortbRequest = spec.buildRequests(clonedBidRequests, clonedBidderReqest).data; - expect(0).to.equal(ortbRequest.imp[0].secure); - - clonedBidRequests[0].ortb2Imp.secure = 1; - ortbRequest = spec.buildRequests(clonedBidRequests, clonedBidderReqest).data; - expect(1).to.equal(ortbRequest.imp[0].secure); - }); - - const extFirstPartyData = { - data: { - firstPartyKey: 'firstPartyValue', - firstPartyKey2: ['value', 'value2'] - }, - custom: 'custom_data', - custom_kvp: { - customKey: 'customValue' - } - } - - function validateExtFirstPartyData(ext) { - expect(ext.data.firstPartyKey).to.equal('firstPartyValue'); - expect(ext.data.firstPartyKey2).to.eql(['value', 'value2']); - expect(ext.custom).to.equal('custom_data'); - expect(ext.custom_kvp.customKey).to.equal('customValue'); - } - - it('should set site first party data', function() { - const ortb2 = { - site: { - ext: extFirstPartyData, - search: 'test search' - } - }; - - const bidderRequestMerged = {...bidderRequest, ortb2}; - const ortbRequest = spec.buildRequests(bidRequests, bidderRequestMerged).data; - - validateExtFirstPartyData(ortbRequest.site.ext) - expect(ortbRequest.site.search).to.equal('test search') - }); - - it('should set user first party data', function() { - const ortb2 = { - user: { - ext: extFirstPartyData, - yob: 1998 - } - }; - - const bidderRequestMerged = {...bidderRequest, ortb2}; - const ortbRequest = spec.buildRequests(bidRequests, bidderRequestMerged).data; - - validateExtFirstPartyData(ortbRequest.user.ext) - expect(ortbRequest.user.yob).to.equal(1998) - }); - - it('should set imp first party data', function() { - const clonedBidderRequest = deepClone(bidderRequest); - const clonedBidRequests = deepClone(bidRequests); - const metric = { type: 'viewability', value: 0.8 }; - clonedBidRequests[0].ortb2Imp = { - ext: extFirstPartyData, - metric: [metric], - clickbrowser: 1 - }; - clonedBidderRequest.bids = clonedBidRequests; - - const ortbRequest = spec.buildRequests(clonedBidRequests, clonedBidderRequest).data; - - validateExtFirstPartyData(ortbRequest.imp[0].ext) - expect(ortbRequest.imp[0].tagid).to.equal('1'); - expect(ortbRequest.imp[0].metric[0]).to.deep.equal(metric); - expect(ortbRequest.imp[0].clickbrowser).to.equal(1) - }); - - it('should set app first party data', function() { - const ortb2 = { - app: { - ext: extFirstPartyData, - ver: 'v1.0' - } - }; - - const bidderRequestMerged = {...bidderRequest, ortb2}; - const ortbRequest = spec.buildRequests(bidRequests, bidderRequestMerged).data; - - validateExtFirstPartyData(ortbRequest.app.ext) - expect(ortbRequest.app.ver).to.equal('v1.0') - }); - - it('should set device first party data', function() { - const ortb2 = { - device: { - ext: extFirstPartyData, - os: 'ios' - } - }; - - const bidderRequestMerged = {...bidderRequest, ortb2}; - const ortbRequest = spec.buildRequests(bidRequests, bidderRequestMerged).data; - - validateExtFirstPartyData(ortbRequest.device.ext) - expect(ortbRequest.device.os).to.equal('ios') - }); - - it('should set pmp first party data', function() { - const ortb2 = { - pmp: { - ext: extFirstPartyData, - private_auction: 1 - } - }; - - const bidderRequestMerged = {...bidderRequest, ortb2}; - const ortbRequest = spec.buildRequests(bidRequests, bidderRequestMerged).data; - - validateExtFirstPartyData(ortbRequest.pmp.ext) - expect(ortbRequest.pmp.private_auction).to.equal(1) - }); - }); - - describe('buildRequests() banner-multiple', function () { - const multiBidRequests = [{ - 'bidder': 'stackadapt', - 'params': { - 'publisherId': '11111', - 'placementId': '1' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250]] - } - }, - 'ortb2Imp': { - 'ext': { - 'tid': '2121283921', - } - }, - 'sizes': [[300, 250]], - 'bidId': '001', - 'bidderRequestId': '5ce18294-9682-4ad0-1c92-0ab12bg8dc5e', - 'auctionId': '8d6e5b89-9c9f-4f25-9d4f-e4c08b0b9d7f', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'aa837ec1-ba90-3821-jduq-1cc083921a9a', - 'src': 'client', - 'bidRequestsCount': 5 - }, { - 'bidder': 'stackadapt', - 'params': { - 'publisherId': '11111', - 'placementId': '2' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[336, 280], [320, 100]] - } - }, - 'ortb2Imp': { - 'ext': { - 'tid': '3728192832', - } - }, - 'sizes': [[336, 280], [320, 100]], - 'bidId': '002', - 'bidderRequestId': '5ce18294-9682-4ad0-1c92-0ab12bg8dc5e', - 'auctionId': '8d6e5b89-9c9f-4f25-9d4f-e4c08b0b9d7f', - 'adUnitCode': 'div-gpt-ad-1460505748561-123', - 'transactionId': 'au289bg3-bc89-3894-dfak-3dp281927l1b', - 'src': 'client', - 'bidRequestsCount': 10 - }]; - - const bidderRequest = { - 'bidderCode': 'stackadapt', - 'auctionId': '8d6e5b89-9c9f-4f25-9d4f-e4c08b0b9d7f', - ortb2: { - source: { - tid: '8d6e5b89-9c9f-4f25-9d4f-e4c08b0b9d7f', - } - }, - 'bidderRequestId': '5ce18294-9682-4ad0-1c92-0ab12bg8dc5e', - 'auctionStart': 1731042158610, - 'timeout': 1750, - 'refererInfo': { - 'reachedTop': true, - 'numIframes': 0, - 'isAmp': false, - 'page': 'https://www.mobile.com/test', - 'domain': 'www.mobile.com', - 'ref': 'https://testsite.com/', - }, - 'start': 1731042158587 - }; - - it('should correctly set multiple impressions', function () { - const ortbRequest = spec.buildRequests(multiBidRequests, bidderRequest).data; - expect(ortbRequest.imp.length).to.equal(2); - expect(ortbRequest.source?.tid).to.equal(bidderRequest.ortb2.source.tid); - expect(ortbRequest.imp[0].ext?.tid).to.equal('2121283921'); - expect(ortbRequest.imp[1].ext?.tid).to.equal('3728192832'); - }); - - it('should correctly set the tagids for each impression', function () { - const ortbRequest = spec.buildRequests(multiBidRequests, bidderRequest).data; - - expect(ortbRequest.imp[0].id).to.equal('001'); - expect(ortbRequest.imp[0].tagid).to.equal('1'); - - expect(ortbRequest.imp[1].id).to.equal('002'); - expect(ortbRequest.imp[1].tagid).to.equal('2'); - }); - - it('should set the sizes for each impression', function () { - const ortbRequest = spec.buildRequests(multiBidRequests, bidderRequest).data; - - expect(ortbRequest.imp[0].banner.format[0].w).to.equal(300); - expect(ortbRequest.imp[0].banner.format[0].h).to.equal(250); - - expect(ortbRequest.imp[1].banner.format[0].w).to.equal(336); - expect(ortbRequest.imp[1].banner.format[0].h).to.equal(280); - expect(ortbRequest.imp[1].banner.format[1].w).to.equal(320); - expect(ortbRequest.imp[1].banner.format[1].h).to.equal(100); - }); - }); - - if (FEATURES.VIDEO) { - describe('buildRequests() video', function () { - const videoBidRequests = [{ - 'bidder': 'stackadapt', - 'params': { - 'publisherId': '11111', - 'placementId': '1' - }, - 'mediaTypes': { - 'video': { - 'playerSize': [187, 105], - 'api': [1, 2], - 'mimes': [ - 'video/mp4', - 'video/x-ms-wmv', - 'application/javascript' - ], - 'protocols': [2, 3, 4, 5, 6], - 'minduration': 1, - 'maxduration': 60 - } - }, - 'ortb2Imp': { - 'ext': { - 'tid': '2121283921', - } - }, - 'transactionId': 'aa837ec1-ba90-3821-jduq-1cc083921a9a', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'bidId': '001', - 'bidderRequestId': '5ce18294-9682-4ad0-1c92-0ab12bg8dc5e', - 'auctionId': '8d6e5b89-9c9f-4f25-9d4f-e4c08b0b9d7f', - 'src': 'client', - 'bidRequestsCount': 10 - }]; - - const bidderRequest = { - 'bidderCode': 'stackadapt', - 'auctionId': '8d6e5b89-9c9f-4f25-9d4f-e4c08b0b9d7f', - 'bidderRequestId': '5ce18294-9682-4ad0-1c92-0ab12bg8dc5e', - 'auctionStart': 1731042158610, - 'timeout': 1750, - 'refererInfo': { - 'reachedTop': true, - 'numIframes': 0, - 'isAmp': false, - 'page': 'https://www.mobile.com/test', - 'domain': 'www.mobile.com', - 'ref': 'https://testsite.com/', - }, - 'start': 1731042158587, - }; - - it('should set the ad size', function () { - const ortbRequest = spec.buildRequests(videoBidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].video.w).to.equal(187); - expect(ortbRequest.imp[0].video.h).to.equal(105); - }); - - it('should set mimes', function () { - const ortbRequest = spec.buildRequests(videoBidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].video.mimes[0]).to.equal('video/mp4'); - expect(ortbRequest.imp[0].video.mimes[1]).to.equal('video/x-ms-wmv'); - expect(ortbRequest.imp[0].video.mimes[2]).to.equal('application/javascript'); - }); - - it('should set min and max duration', function () { - const ortbRequest = spec.buildRequests(videoBidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].video.minduration).to.equal(1); - expect(ortbRequest.imp[0].video.maxduration).to.equal(60); - }); - - it('should set api frameworks array', function () { - const ortbRequest = spec.buildRequests(videoBidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].video.api[0]).to.equal(1); - expect(ortbRequest.imp[0].video.api[1]).to.equal(2); - }); - - it('should set the protocols array', function () { - const ortbRequest = spec.buildRequests(videoBidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].video.protocols[0]).to.equal(2); - expect(ortbRequest.imp[0].video.protocols[1]).to.equal(3); - expect(ortbRequest.imp[0].video.protocols[2]).to.equal(4); - expect(ortbRequest.imp[0].video.protocols[3]).to.equal(5); - expect(ortbRequest.imp[0].video.protocols[4]).to.equal(6); - }); - - it('should set skip if present', function () { - const clonnedVideoBidRequests = deepClone(videoBidRequests); - clonnedVideoBidRequests[0].mediaTypes.video.skip = 1; - clonnedVideoBidRequests[0].mediaTypes.video.skipmin = 5; - clonnedVideoBidRequests[0].mediaTypes.video.skipafter = 10; - - const ortbRequest = spec.buildRequests(clonnedVideoBidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].video.skip).to.equal(1); - expect(ortbRequest.imp[0].video.skipmin).to.equal(5); - expect(ortbRequest.imp[0].video.skipafter).to.equal(10); - }); - - it('should set bitrate if present', function () { - const clonnedVideoBidRequests = deepClone(videoBidRequests); - clonnedVideoBidRequests[0].mediaTypes.video.minbitrate = 100; - clonnedVideoBidRequests[0].mediaTypes.video.maxbitrate = 500; - - const ortbRequest = spec.buildRequests(clonnedVideoBidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].video.minbitrate).to.equal(100); - expect(ortbRequest.imp[0].video.maxbitrate).to.equal(500); - }); - - it('should set pos if present', function () { - const clonnedVideoBidRequests = deepClone(videoBidRequests); - clonnedVideoBidRequests[0].mediaTypes.video.pos = 1; - - const ortbRequest = spec.buildRequests(clonnedVideoBidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].video.pos).to.equal(1); - }); - - it('should set playbackmethod if present', function () { - const clonnedVideoBidRequests = deepClone(videoBidRequests); - clonnedVideoBidRequests[0].mediaTypes.video.playbackmethod = [1]; - - const ortbRequest = spec.buildRequests(clonnedVideoBidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].video.playbackmethod[0]).to.equal(1); - }); - - it('should set startdelay if present', function () { - const clonnedVideoBidRequests = deepClone(videoBidRequests); - clonnedVideoBidRequests[0].mediaTypes.video.startdelay = -1; - - const ortbRequest = spec.buildRequests(clonnedVideoBidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].video.startdelay).to.equal(-1); - }); - - it('should set placement if present', function () { - const clonnedVideoBidRequests = deepClone(videoBidRequests); - clonnedVideoBidRequests[0].mediaTypes.video.plcmt = 3; - - const ortbRequest = spec.buildRequests(clonnedVideoBidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].video.plcmt).to.equal(3); - }); - - it('should set plcmt if present', function () { - const clonnedVideoBidRequests = deepClone(videoBidRequests); - clonnedVideoBidRequests[0].mediaTypes.video.plcmt = 3; - - const ortbRequest = spec.buildRequests(clonnedVideoBidRequests, bidderRequest).data; - expect(ortbRequest.imp[0].video.plcmt).to.equal(3); - }); - }); - } - - describe('getUserSyncs', function () { - it('should get usersync', function () { - const syncOptions = { - pixelEnabled: true - }; - const gdprConsentString = 'CQGRvoAQGRvoAAHABAENBKFsAP_gAEPgAAAAKhNV'; - const gdprConsent = { - consentString: gdprConsentString, - gdprApplies: true - }; - const uspConsent = '1YNY'; - const gppConsent = { - gppString: 'DCACTA~1YAB', - applicableSections: [7, 8] - }; - - const syncs = spec.getUserSyncs(syncOptions, [], gdprConsent, uspConsent, gppConsent); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('image'); - expect(syncs[0].url).to.equal('https://sync.srv.stackadapt.com/sync?nid=pjs&gdpr=1&gdpr_consent=CQGRvoAQGRvoAAHABAENBKFsAP_gAEPgAAAAKhNV&us_privacy=1YNY&gpp=DCACTA~1YAB&gpp_sid=7,8'); - - const params = new URLSearchParams(new URL(syncs[0].url).search); - expect(params.get('us_privacy')).to.equal(uspConsent); - expect(params.get('gdpr')).to.equal('1'); - expect(params.get('gdpr_consent')).to.equal(gdprConsentString); - expect(params.get('gpp')).to.equal(gppConsent.gppString); - expect(params.get('gpp_sid')).to.equal(gppConsent.applicableSections.toString()); - }); - }); -}); diff --git a/test/spec/modules/startioBidAdapter_spec.js b/test/spec/modules/startioBidAdapter_spec.js deleted file mode 100644 index 021c11e80..000000000 --- a/test/spec/modules/startioBidAdapter_spec.js +++ /dev/null @@ -1,373 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/startioBidAdapter.js'; -import { BANNER, VIDEO, NATIVE } from 'src/mediaTypes.js'; -import {deepClone} from '../../../src/utils.js'; - -const DEFAULT_REQUEST_DATA = { - adUnitCode: 'test-div', - auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917', - bidId: '32d4d86b4f22ed', - bidder: 'startio', - bidderRequestId: '1bbb7854dfa0d8', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ] - } - }, - params: {}, - src: 'client', - transactionId: 'db739693-9b4a-4669-9945-8eab938783cc' -} - -const VALID_MEDIA_TYPES_REQUESTS = { - [BANNER]: [{ - ...DEFAULT_REQUEST_DATA, - mediaTypes: { - [BANNER]: { - sizes: [ - [300, 250], - [300, 600] - ] - } - }, - }], - [VIDEO]: [{ - ...DEFAULT_REQUEST_DATA, - mediaTypes: { - video: { - minduration: 3, - maxduration: 43, - playerSize: [640, 480], - mimes: ['video/mp4'], - protocols: [2] - } - }, - }], - [NATIVE]: [{ - ...DEFAULT_REQUEST_DATA, - mediaTypes: { - [NATIVE]: { - title: { required: true, len: 200 }, - image: { required: true, sizes: [150, 50] }, - } - }, - nativeOrtbRequest: { - assets: [ - { required: 1, title: { len: 200 } }, - { required: 1, img: { type: 3, w: 150, h: 50 } }, - ] - }, - }] -} - -const DEFAULT_BIDDER_REQUEST = { - refererInfo: { referer: 'https://example.com' }, -}; - -const VALID_BIDDER_REQUEST = { - auctionId: '19c97f22-5bd1-4b16-a128-80f75fb0a8a0', - bidderCode: 'startio', - bidderRequestId: '1bbb7854dfa0d8', - bids: [ - { - params: {}, - } - ], - refererInfo: { - page: 'test-page', - domain: 'test-domain', - ref: 'test-referer' - }, -} - -const DEFAULT_BID_RESPONSE_DATA = { - 'id': '29596384-e502-4d3c-a47d-4f16b16bd554', - 'impid': '32d4d86b4f22ed', - 'price': 0.18417903447819028, - 'adid': '2:64:162:1001', - 'adomain': [ - 'start.io' - ], - 'nurl': 'https://start.io/v1', - 'lurl': 'https://start.io/v1', - 'iurl': 'https://start.io/v1', - 'cid': '1982494692188097775', - 'crid': '5889732975267688811', - 'cat': ['IAB1-1', 'IAB1-6'], - 'w': 300, - 'h': 250, - 'mtype': 1, -}; - -const SERVER_RESPONSE_BANNER = { - 'id': '5d997535-e900-4a6b-9cb7-737e402d5cfa', - 'seatbid': [ - { - 'bid': [ - { - ...DEFAULT_BID_RESPONSE_DATA, - 'adm': 'banner.img', - 'ext': { - 'duration': 0, - 'prebid': { - 'type': BANNER - } - } - } - ], - 'seat': 'start.io', - 'group': 0 - } - ], - 'cur': 'USD' -} - -const SERVER_RESPONSE_VIDEO = { - 'id': '8cd85aed-25a6-4db0-ad98-4a3af1f7601c', - 'seatbid': [ - { - 'bid': [ - { - ...DEFAULT_BID_RESPONSE_DATA, - 'adm': '', - 'ext': { - 'duration': 0, - 'prebid': { - 'type': VIDEO - } - } - } - ], - 'seat': 'start.io', - 'group': 0 - } - ], - 'cur': 'USD' -} - -const SERVER_RESPONSE_NATIVE = { - 'id': '29667448-5659-42bb-abcf-dc973f98eae1', - 'seatbid': [ - { - 'bid': [ - { - ...DEFAULT_BID_RESPONSE_DATA, - 'adm': '{"native":{"assets":[{"id":0,"title":{"len":90,"text":"Title"}}, {"id":1,"img":{"w":320,"h":250,"url":"https://img.image.com/product/image.jpg"}}]}}', - 'ext': { - 'duration': 0, - 'prebid': { - 'type': NATIVE - } - } - } - ], - 'seat': 'start.io', - 'group': 0 - } - ], - 'cur': 'USD' -} - -describe('Prebid Adapter: Startio', function () { - describe('code', function () { - it('should return a bidder code of startio', function () { - expect(spec.code).to.eql('startio'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true for bid request', function () { - const bidRequest = { - bidder: 'startio', - }; - expect(spec.isBidRequestValid(bidRequest)).to.eql(true); - }); - it('should verify bidFloorCur for bid request', function () { - const bidRequestUSD = { - bidder: 'startio', - ortb2Imp: { - bidfloorcur: 'USD' - } - }; - expect(spec.isBidRequestValid(bidRequestUSD)).to.eql(true); - - const bidRequestEUR = { - bidder: 'startio', - ortb2Imp: { - bidfloorcur: 'EUR' - } - }; - expect(spec.isBidRequestValid(bidRequestEUR)).to.eql(false); - }); - }); - - describe('buildRequests', function () { - it('should build request for banner media type', function () { - const bidRequest = VALID_MEDIA_TYPES_REQUESTS[BANNER][0]; - - const requests = spec.buildRequests([bidRequest], DEFAULT_BIDDER_REQUEST); - - expect(requests).to.have.lengthOf(1); - const request = requests[0]; - expect(request.method).to.equal('POST'); - expect(request.data).to.have.property('imp'); - expect(request.data.imp[0].banner.w).to.equal(300); - expect(request.data.imp[0].banner.h).to.equal(250); - }); - - it('should provide bidfloor when either bid param or getFloor function exists', function () { - let bidRequest = deepClone(DEFAULT_REQUEST_DATA); - - // with no param or getFloor bidfloor is not specified - let request = spec.buildRequests([bidRequest], DEFAULT_BIDDER_REQUEST)[0].data; - expect(request.imp[0].bidfloor).to.not.exist; - expect(request.imp[0].bidfloorcur).to.not.exist; - - // with param and no getFloor bidfloor uses value from param - bidRequest.params.floor = 1.3; - request = spec.buildRequests([bidRequest], DEFAULT_BIDDER_REQUEST)[0].data; - expect(request.imp[0].bidfloor).to.equal(1.3); - expect(request.imp[0].bidfloorcur).to.equal('USD'); - - // with param and getFloor bidfloor uses value form getFloor - bidRequest.getFloor = () => { return { currency: 'USD', floor: 2.4 }; }; - request = spec.buildRequests([bidRequest], DEFAULT_BIDDER_REQUEST)[0].data; - expect(request.imp[0].bidfloor).to.equal(2.4); - expect(request.imp[0].bidfloorcur).to.equal('USD'); - }); - - it('should provide us_privacy', function () { - let bidderRequest = deepClone(DEFAULT_BIDDER_REQUEST); - - bidderRequest.uspConsent = '1YYN'; - const request = spec.buildRequests([DEFAULT_REQUEST_DATA], bidderRequest)[0].data; - - expect(request.regs.ext.us_privacy).to.equal('1YYN'); - }); - - it('should provide coppa', () => { - let bidderRequest = deepClone(DEFAULT_BIDDER_REQUEST); - bidderRequest.ortb2 = {regs: {coppa: 0}}; - let request = spec.buildRequests([DEFAULT_REQUEST_DATA], bidderRequest)[0].data; - expect(request.regs.coppa).to.equal(0); - - bidderRequest.ortb2 = {regs: {coppa: 1}}; - request = spec.buildRequests([DEFAULT_REQUEST_DATA], bidderRequest)[0].data; - expect(request.regs.coppa).to.equal(1); - }); - - it('should provide blocked parameters', function () { - let bidRequest = deepClone(DEFAULT_REQUEST_DATA); - let bidderRequest = deepClone(DEFAULT_BIDDER_REQUEST); - - bidRequest.params.bcat = ['IAB25', 'IAB7-39']; - bidRequest.params.bapp = ['com.bad.app1']; - bidRequest.params.badv = ['competitor1.com', 'badsite1.net']; - bidRequest.params.battr = [1, 2]; - - let request = spec.buildRequests([bidRequest], bidderRequest)[0].data; - expect(request.bcat).to.deep.equal(['IAB25', 'IAB7-39']); - expect(request.bapp).to.deep.equal(['com.bad.app1']); - expect(request.badv).to.deep.equal(['competitor1.com', 'badsite1.net']); - expect(request.imp[0].banner.battr).to.deep.equal([1, 2]); - - bidderRequest.ortb2 = { - bcat: ['IAB1', 'IAB2'], - bapp: ['com.bad.app2'], - badv: ['competitor2.com', 'badsite2.net'], - banner: { battr: [3, 4] } - }; - request = spec.buildRequests([bidRequest], bidderRequest)[0].data; - expect(request.bcat).to.deep.equal(['IAB1', 'IAB2']); - expect(request.bapp).to.deep.equal(['com.bad.app2']); - expect(request.badv).to.deep.equal(['competitor2.com', 'badsite2.net']); - expect(request.imp[0].banner.battr).to.deep.equal([3, 4]); - }); - - if (FEATURES.VIDEO) { - it('should build request for video media type', function () { - const bidRequest = VALID_MEDIA_TYPES_REQUESTS[VIDEO][0]; - - const requests = spec.buildRequests([bidRequest], DEFAULT_BIDDER_REQUEST); - - expect(requests).to.have.lengthOf(1); - const request = requests[0]; - - expect(request.data.imp[0].video).to.exist; - expect(request.data.imp[0].video.minduration).to.equal(3); - expect(request.data.imp[0].video.maxduration).to.equal(43); - }); - } - - if (FEATURES.NATIVE) { - it('should build request for native media type', function () { - const bidRequest = VALID_MEDIA_TYPES_REQUESTS[NATIVE][0]; - - const requests = spec.buildRequests([bidRequest], DEFAULT_BIDDER_REQUEST); - - expect(requests).to.have.lengthOf(1); - const request = requests[0]; - - expect(request.data.imp[0].native).to.exist; - }); - } - }); - - describe('interpretResponse', function () { - it('should return a valid bid array with a banner bid', () => { - const requests = spec.buildRequests(VALID_MEDIA_TYPES_REQUESTS[BANNER], VALID_BIDDER_REQUEST) - const { data } = requests[0]; - const bids = spec.interpretResponse({ body: SERVER_RESPONSE_BANNER }, { data }).bids; - - expect(bids).to.be.a('array').that.has.lengthOf(1) - bids.forEach(value => { - expect(value).to.be.a('object').that.has.all.keys( - 'ad', 'cpm', 'creativeId', 'currency', 'height', 'mediaType', 'meta', 'netRevenue', 'requestId', 'ttl', 'width', 'seatBidId', 'creative_id' - ) - }) - }); - - it('should set meta.adomain from the bid response adomain field', () => { - const requests = spec.buildRequests(VALID_MEDIA_TYPES_REQUESTS[BANNER], VALID_BIDDER_REQUEST); - const { data } = requests[0]; - const bids = spec.interpretResponse({ body: SERVER_RESPONSE_BANNER }, { data }).bids; - - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - - expect(bid.meta).to.be.an('object'); - expect(bid.meta.advertiserDomains).to.be.an('array').that.includes('start.io'); - }); - - if (FEATURES.VIDEO) { - it('should return a valid bid array with a video bid', () => { - const requests = spec.buildRequests(VALID_MEDIA_TYPES_REQUESTS[VIDEO], VALID_BIDDER_REQUEST); - const { data } = requests[0]; - const bids = spec.interpretResponse({ body: SERVER_RESPONSE_VIDEO }, { data }).bids - expect(bids).to.be.a('array').that.has.lengthOf(1) - bids.forEach(value => { - expect(value).to.be.a('object').that.has.all.keys( - 'vastUrl', 'vastXml', 'playerHeight', 'playerWidth', 'cpm', 'creativeId', 'currency', 'height', 'mediaType', 'meta', 'netRevenue', 'requestId', 'ttl', 'width', 'seatBidId', 'creative_id' - ) - }) - }); - } - - if (FEATURES.NATIVE) { - it('should return a valid bid array with a native bid', () => { - const requests = spec.buildRequests(VALID_MEDIA_TYPES_REQUESTS[NATIVE], VALID_BIDDER_REQUEST); - const { data } = requests[0]; - const bids = spec.interpretResponse({ body: SERVER_RESPONSE_NATIVE }, { data }).bids - expect(bids).to.be.a('array').that.has.lengthOf(1) - bids.forEach(value => { - expect(value).to.be.a('object').that.has.all.keys( - 'native', 'cpm', 'creativeId', 'currency', 'height', 'mediaType', 'meta', 'netRevenue', 'requestId', 'ttl', 'width', 'seatBidId', 'creative_id' - ) - }) - }); - } - }); -}); diff --git a/test/spec/modules/stnBidAdapter_spec.js b/test/spec/modules/stnBidAdapter_spec.js deleted file mode 100644 index 021005a90..000000000 --- a/test/spec/modules/stnBidAdapter_spec.js +++ /dev/null @@ -1,745 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/stnBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { config } from 'src/config.js'; -import {BANNER, NATIVE, VIDEO} from '../../../src/mediaTypes.js'; -import * as utils from 'src/utils.js'; -import {decorateAdUnitsWithNativeParams} from '../../../src/native.js'; - -const ENDPOINT = 'https://hb.stngo.com/hb-multi'; -const TEST_ENDPOINT = 'https://hb.stngo.com/hb-multi-test'; -const TTL = 360; -/* eslint no-console: ["error", { allow: ["log", "warn", "error"] }] */ - -describe('stnAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [['640', '480']], - 'params': { - 'org': 'jdye8weeyirk00000001' - } - }; - - it('should return true when required params are passed', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not found', function () { - const newBid = Object.assign({}, bid); - delete newBid.params; - newBid.params = { - 'org': null - }; - expect(spec.isBidRequestValid(newBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[640, 480]], - 'params': { - 'org': 'jdye8weeyirk00000001' - }, - 'bidId': '299ffc8cca0b87', - 'loop': 1, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'video': { - 'playerSize': [[640, 480]], - 'context': 'instream', - 'plcmt': 1 - } - }, - }, - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'params': { - 'org': 'jdye8weeyirk00000001' - }, - 'bidId': '299ffc8cca0b87', - 'loop': 1, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'banner': { - } - }, - }, - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250]], - 'params': { - 'org': 'jdye8weeyirk00000001' - }, - 'bidId': '299ffc8cca0b87', - 'loop': 1, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ 300, 250 ] - ] - }, - 'video': { - 'playerSize': [[640, 480]], - 'context': 'instream', - 'plcmt': 1 - }, - 'native': { - 'ortb': { - 'assets': [ - { - 'id': 1, - 'required': 1, - 'img': { - 'type': 3, - 'w': 300, - 'h': 200, - } - }, - { - 'id': 2, - 'required': 1, - 'title': { - 'len': 80 - } - }, - { - 'id': 3, - 'required': 1, - 'data': { - 'type': 1 - } - } - ] - } - }, - }, - 'ad': '""' - } - ]; - - const testModeBidRequests = [ - { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [[640, 480]], - 'params': { - 'org': 'jdye8weeyirk00000001', - 'testMode': true - }, - 'bidId': '299ffc8cca0b87', - 'loop': 2, - 'bidderRequestId': '1144f487e563f9', - 'auctionId': 'bfc420c3-8577-4568-9766-a8a935fb620d', - } - ]; - - const bidderRequest = { - bidderCode: 'stn', - } - const placementId = '12345678'; - const api = [1, 2]; - const mimes = ['application/javascript', 'video/mp4', 'video/quicktime']; - const protocols = [2, 3, 5, 6]; - - it('sends the placementId to ENDPOINT via POST', function () { - bidRequests[0].params.placementId = placementId; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].placementId).to.equal(placementId); - }); - - it('sends the plcmt to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].plcmt).to.equal(1); - }); - - it('sends the is_wrapper parameter to ENDPOINT via POST', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('is_wrapper'); - expect(request.data.params.is_wrapper).to.equal(false); - }); - - it('sends bid request to ENDPOINT via POST', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.url).to.equal(ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('sends bid request to TEST ENDPOINT via POST', function () { - const request = spec.buildRequests(testModeBidRequests, bidderRequest); - expect(request.url).to.equal(TEST_ENDPOINT); - expect(request.method).to.equal('POST'); - }); - - it('should send the correct bid Id', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].bidId).to.equal('299ffc8cca0b87'); - }); - - it('should send the correct supported api array', function () { - bidRequests[0].mediaTypes.video.api = api; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].api).to.be.an('array'); - expect(request.data.bids[0].api).to.eql([1, 2]); - }); - - it('should send the correct mimes array', function () { - bidRequests[0].mediaTypes.video.mimes = mimes; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].mimes).to.be.an('array'); - expect(request.data.bids[0].mimes).to.eql(['application/javascript', 'video/mp4', 'video/quicktime']); - }); - - it('should send the correct protocols array', function () { - bidRequests[0].mediaTypes.video.protocols = protocols; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].protocols).to.be.an('array'); - expect(request.data.bids[0].protocols).to.eql([2, 3, 5, 6]); - }); - - it('should send the correct sizes array', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].sizes).to.be.an('array'); - expect(request.data.bids[0].sizes).to.equal(bidRequests[0].sizes) - expect(request.data.bids[1].sizes).to.be.an('array'); - expect(request.data.bids[1].sizes).to.equal(bidRequests[1].sizes) - expect(request.data.bids[2].sizes).to.be.an('array'); - expect(request.data.bids[2].sizes).to.eql(bidRequests[2].sizes) - }); - - it('should send nativeOrtbRequest in native bid request', function () { - decorateAdUnitsWithNativeParams(bidRequests) - const request = spec.buildRequests(bidRequests, bidderRequest); - assert.deepEqual(request.data.bids[2].nativeOrtbRequest, bidRequests[2].mediaTypes.native.ortb) - }); - - it('should send the correct media type', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].mediaType).to.equal(VIDEO) - expect(request.data.bids[1].mediaType).to.equal(BANNER) - expect(request.data.bids[2].mediaType.split(',')).to.include.members([VIDEO, NATIVE, BANNER]) - }); - - it('should respect syncEnabled option', function() { - config.setConfig({ - userSync: { - syncEnabled: false, - filterSettings: { - all: { - bidders: '*', - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('cs_method'); - }); - - it('should respect "iframe" filter settings', function () { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - iframe: { - bidders: [spec.code], - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'iframe'); - }); - - it('should respect "all" filter settings', function () { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - all: { - bidders: [spec.code], - filter: 'include' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'iframe'); - }); - - it('should send the pixel user sync param if userSync is enabled and no "iframe" or "all" configs are present', function () { - config.resetConfig(); - config.setConfig({ - userSync: { - syncEnabled: true, - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('cs_method', 'pixel'); - }); - - it('should respect total exclusion', function() { - config.setConfig({ - userSync: { - syncEnabled: true, - filterSettings: { - image: { - bidders: [spec.code], - filter: 'exclude' - }, - iframe: { - bidders: [spec.code], - filter: 'exclude' - } - } - } - }); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('cs_method'); - }); - - it('should have us_privacy param if usPrivacy is available in the bidRequest', function () { - const bidderRequestWithUSP = Object.assign({uspConsent: '1YNN'}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithUSP); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('us_privacy', '1YNN'); - }); - - it('should have an empty us_privacy param if usPrivacy is missing in the bidRequest', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('us_privacy'); - }); - - it('should not send the gdpr param if gdprApplies is false in the bidRequest', function () { - const bidderRequestWithGDPR = Object.assign({gdprConsent: {gdprApplies: false}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('gdpr'); - expect(request.data.params).to.not.have.property('gdpr_consent'); - }); - - it('should send the gdpr param if gdprApplies is true in the bidRequest', function () { - const bidderRequestWithGDPR = Object.assign({gdprConsent: {gdprApplies: true, consentString: 'test-consent-string'}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGDPR); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('gdpr', true); - expect(request.data.params).to.have.property('gdpr_consent', 'test-consent-string'); - }); - - it('should not send the gpp param if gppConsent is false in the bidRequest', function () { - const bidderRequestWithGPP = Object.assign({gppConsent: false}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGPP); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.not.have.property('gpp'); - expect(request.data.params).to.not.have.property('gpp_sid'); - }); - - it('should send the gpp param if gppConsent is true in the bidRequest', function () { - const bidderRequestWithGPP = Object.assign({gppConsent: {gppString: 'test-consent-string', applicableSections: [7]}}, bidderRequest); - const request = spec.buildRequests(bidRequests, bidderRequestWithGPP); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('gpp', 'test-consent-string'); - expect(request.data.params.gpp_sid[0]).to.be.equal(7); - }); - - it('should have schain param if it is available in the bidRequest', () => { - bidderRequest.ortb2 = { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [{ asi: 'indirectseller.com', sid: '00001', hp: 1 }], - } - } - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.params).to.be.an('object'); - expect(request.data.params).to.have.property('schain', '1.0,1!indirectseller.com,00001,1,,,'); - }); - - it('should set flooPrice to getFloor.floor value if it is greater than params.floorPrice', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.getFloor = () => { - return { - currency: 'USD', - floor: 3.32 - } - } - bid.params.floorPrice = 0.64; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0]).to.be.an('object'); - expect(request.data.bids[0]).to.have.property('floorPrice', 3.32); - }); - - it('should set floorPrice to params.floorPrice value if it is greater than getFloor.floor', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.getFloor = () => { - return { - currency: 'USD', - floor: 0.8 - } - } - bid.params.floorPrice = 1.5; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0]).to.be.an('object'); - expect(request.data.bids[0]).to.have.property('floorPrice', 1.5); - }); - - it('should check sua param in bid request', function() { - const sua = { - 'platform': { - 'brand': 'macOS', - 'version': ['12', '4', '0'] - }, - 'browsers': [ - { - 'brand': 'Chromium', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Google Chrome', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Not;A=Brand', - 'version': [ '99', '0', '0', '0' ] - } - ], - 'mobile': 0, - 'model': '', - 'bitness': '64', - 'architecture': 'x86' - } - const bid = utils.deepClone(bidRequests[0]); - bid.ortb2 = { - 'device': { - 'sua': { - 'platform': { - 'brand': 'macOS', - 'version': [ '12', '4', '0' ] - }, - 'browsers': [ - { - 'brand': 'Chromium', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Google Chrome', - 'version': [ '106', '0', '5249', '119' ] - }, - { - 'brand': 'Not;A=Brand', - 'version': [ '99', '0', '0', '0' ] - } - ], - 'mobile': 0, - 'model': '', - 'bitness': '64', - 'architecture': 'x86' - } - } - } - const requestWithSua = spec.buildRequests([bid], bidderRequest); - const data = requestWithSua.data; - expect(data.bids[0].sua).to.exist; - expect(data.bids[0].sua).to.deep.equal(sua); - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].sua).to.not.exist; - }); - - describe('COPPA Param', function() { - it('should set coppa equal 0 in bid request if coppa is set to false', function() { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.bids[0].coppa).to.be.equal(0); - }); - - it('should set coppa equal 1 in bid request if coppa is set to true', function() { - const bid = utils.deepClone(bidRequests[0]); - bid.ortb2 = { - 'regs': { - 'coppa': true, - } - }; - const request = spec.buildRequests([bid], bidderRequest); - expect(request.data.bids[0].coppa).to.be.equal(1); - }); - }); - }); - - describe('interpretResponse', function () { - const response = { - params: { - currency: 'USD', - netRevenue: true, - }, - bids: [{ - cpm: 12.5, - vastXml: '', - width: 640, - height: 480, - requestId: '21e12606d47ba7', - creativeId: 'creative-id-1', - adomain: ['abc.com'], - mediaType: VIDEO, - nurl: 'http://example.com/win/1234', - }, - { - cpm: 12.5, - ad: '""', - width: 300, - height: 250, - requestId: '21e12606d47ba7', - creativeId: 'creative-id-2', - adomain: ['abc.com'], - mediaType: BANNER, - nurl: 'http://example.com/win/1234', - }, - { - cpm: 12.5, - width: 300, - height: 200, - requestId: '21e12606d47ba7', - adomain: ['abc.com'], - creativeId: 'creative-id-3', - nurl: 'http://example.com/win/1234', - mediaType: NATIVE, - native: { - body: 'Advertise with Rise', - clickUrl: 'https://risecodes.com', - cta: 'Start now', - image: { - width: 300, - height: 200, - url: 'https://sdk.streamrail.com/media/rise-image.jpg' - }, - sponsoredBy: 'Rise', - title: 'Rise Ad Tech Solutions' - } - }] - }; - - const expectedVideoResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 640, - height: 480, - ttl: TTL, - creativeId: 'creative-id-1', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: VIDEO, - meta: { - mediaType: VIDEO, - advertiserDomains: ['abc.com'] - }, - vastXml: '', - }; - - const expectedBannerResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 300, - height: 250, - ttl: TTL, - creativeId: 'creative-id-2', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: BANNER, - meta: { - mediaType: BANNER, - advertiserDomains: ['abc.com'] - }, - ad: '""' - }; - - const expectedNativeResponse = { - requestId: '21e12606d47ba7', - cpm: 12.5, - currency: 'USD', - width: 300, - height: 200, - ttl: TTL, - creativeId: 'creative-id-3', - netRevenue: true, - nurl: 'http://example.com/win/1234', - mediaType: NATIVE, - meta: { - mediaType: NATIVE, - advertiserDomains: ['abc.com'] - }, - native: { - ortb: { - body: 'Advertise with Rise', - clickUrl: 'https://risecodes.com', - cta: 'Start now', - image: { - width: 300, - height: 200, - url: 'https://sdk.streamrail.com/media/rise-image.jpg', - }, - sponsoredBy: 'Rise', - title: 'Rise Ad Tech Solutions' - } - }, - }; - - it('should get correct bid response', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[0]).to.deep.equal(expectedVideoResponse); - expect(result[1]).to.deep.equal(expectedBannerResponse); - expect(result[2]).to.deep.equal(expectedNativeResponse); - }); - - it('video type should have vastXml key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[0].vastXml).to.equal(expectedVideoResponse.vastXml) - }); - - it('banner type should have ad key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[1].ad).to.equal(expectedBannerResponse.ad) - }); - - it('native type should have native key', function () { - const result = spec.interpretResponse({ body: response }); - expect(result[2].native).to.eql(expectedNativeResponse.native) - }); - }) - - describe('getUserSyncs', function() { - const imageSyncResponse = { - body: { - params: { - userSyncPixels: [ - 'https://image-sync-url.test/1', - 'https://image-sync-url.test/2', - 'https://image-sync-url.test/3' - ] - } - } - }; - - const iframeSyncResponse = { - body: { - params: { - userSyncURL: 'https://iframe-sync-url.test' - } - } - }; - - it('should register all img urls from the response', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true }, [imageSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'image', - url: 'https://image-sync-url.test/1' - }, - { - type: 'image', - url: 'https://image-sync-url.test/2' - }, - { - type: 'image', - url: 'https://image-sync-url.test/3' - } - ]); - }); - - it('should register the iframe url from the response', function() { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, [iframeSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://iframe-sync-url.test' - } - ]); - }); - - it('should register both image and iframe urls from the responses', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: true, iframeEnabled: true }, [iframeSyncResponse, imageSyncResponse]); - expect(syncs).to.deep.equal([ - { - type: 'iframe', - url: 'https://iframe-sync-url.test' - }, - { - type: 'image', - url: 'https://image-sync-url.test/1' - }, - { - type: 'image', - url: 'https://image-sync-url.test/2' - }, - { - type: 'image', - url: 'https://image-sync-url.test/3' - } - ]); - }); - - it('should handle an empty response', function() { - const syncs = spec.getUserSyncs({ iframeEnabled: true }, []); - expect(syncs).to.deep.equal([]); - }); - - it('should handle when user syncs are disabled', function() { - const syncs = spec.getUserSyncs({ pixelEnabled: false }, [imageSyncResponse]); - expect(syncs).to.deep.equal([]); - }); - }) - - describe('onBidWon', function() { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - - it('Should trigger pixel if bid nurl', function() { - const bid = { - 'bidder': spec.code, - 'adUnitCode': 'adunit-code', - 'sizes': [['640', '480']], - 'nurl': 'http://example.com/win/1234', - 'params': { - 'org': 'jdye8weeyirk00000001' - } - }; - - spec.onBidWon(bid); - expect(utils.triggerPixel.callCount).to.equal(1) - }) - }) -}); diff --git a/test/spec/modules/stroeerCoreBidAdapter_spec.js b/test/spec/modules/stroeerCoreBidAdapter_spec.js deleted file mode 100644 index 5458a33ec..000000000 --- a/test/spec/modules/stroeerCoreBidAdapter_spec.js +++ /dev/null @@ -1,1150 +0,0 @@ -import {assert} from 'chai'; -import {spec} from 'modules/stroeerCoreBidAdapter.js'; -import * as utils from 'src/utils.js'; -import {BANNER, VIDEO} from '../../../src/mediaTypes.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; -import sinon from 'sinon'; - -describe('stroeerCore bid adapter', function () { - let sandbox; - let bidderRequest; - let clock; - - beforeEach(() => { - bidderRequest = buildBidderRequest(); - sandbox = sinon.createSandbox(); - clock = sandbox.useFakeTimers(); - }); - - afterEach(() => { - clock.restore(); - sandbox.restore(); - }); - - function assertStandardFieldsBid(bidObject, bidId, width, height, cpm) { - assert.propertyVal(bidObject, 'requestId', bidId); - assert.propertyVal(bidObject, 'width', width); - assert.propertyVal(bidObject, 'height', height); - assert.propertyVal(bidObject, 'cpm', cpm); - assert.propertyVal(bidObject, 'currency', 'EUR'); - assert.propertyVal(bidObject, 'netRevenue', true); - assert.propertyVal(bidObject, 'creativeId', ''); - } - - function assertStandardFieldsOnBannerBid(bidObject, bidId, ad, width, height, cpm) { - assertStandardFieldsBid(bidObject, bidId, width, height, cpm); - assertBannerAdMarkup(bidObject, ad); - } - - function assertStandardFieldsOnVideoBid(bidObject, bidId, vastXml, width, height, cpm) { - assertStandardFieldsBid(bidObject, bidId, width, height, cpm); - assertVideoVastXml(bidObject, vastXml); - } - - function assertBannerAdMarkup(bidObject, ad) { - assert.propertyVal(bidObject, 'ad', ad); - assert.notProperty(bidObject, 'vastXml'); - } - - function assertVideoVastXml(bidObject, vastXml) { - assert.propertyVal(bidObject, 'vastXml', vastXml); - assert.notProperty(bidObject, 'ad'); - } - - // Vendor user ids and associated data - const eids = Object.freeze([ - { - source: 'pubcid.org', - uids: [ - { - atype: 1, - id: '0dc6b760-0000-4716-9999-f92afdf2afb9', - }, - { - atype: 3, - id: '8263836331', - } - ], - }, - { - source: 'criteo.com', - uids: [ - { - atype: 2, - id: 'WpgEVV9zekZDVmglMkJQQ09vN05JbWg', - ext: { - other: 'stuff' - } - } - ], - } - ]); - - const buildBidderRequest = () => ({ - bidderRequestId: 'bidder-request-id-123', - bidderCode: 'stroeerCore', - timeout: 5000, - auctionStart: 10000, - refererInfo: { - page: 'https://www.example.com/monkey/index.html', - ref: 'https://www.example.com/?search=monkey' - }, - bids: [{ - bidId: 'bid1', - bidder: 'stroeerCore', - adUnitCode: 'div-1', - mediaTypes: { - banner: { - sizes: [[300, 600], [160, 60]] - } - }, - params: { - sid: 'NDA=' - }, - userIdAsEids: eids - }, { - bidId: 'bid2', - bidder: 'stroeerCore', - adUnitCode: 'div-2', - mediaTypes: { - banner: { - sizes: [[728, 90]], - } - }, - params: { - sid: 'ODA=' - }, - userIdAsEids: eids - }], - }); - - const buildBidderResponse = () => ({ - 'bids': [{ - 'bidId': 'bid1', 'cpm': 4.0, 'width': 300, 'height': 600, 'ad': '
tag1
', 'tracking': {'brandId': 123} - }, { - 'bidId': 'bid2', 'cpm': 7.3, 'width': 728, 'height': 90, 'ad': '
tag2
' - }] - }); - - const buildBidderResponseWithVideo = () => ({ - 'bids': [{ - 'bidId': 'bid1', 'cpm': 4.0, 'width': 800, 'height': 250, 'vastXml': 'video' - }] - }); - - const createWindow = (href, params = {}) => { - const {parent, top, frameElement, placementElements = []} = params; - - const protocol = href.startsWith('https') ? 'https:' : 'http:'; - const win = { - frameElement, - parent, - top, - location: { - protocol, href - }, - document: { - createElement: function () { - return { - setAttribute: function () { - } - } - }, - getElementById: id => placementElements.find(el => el.id === id) - } - }; - - win.self = win; - - if (!parent) { - win.parent = win; - } - - if (!top) { - win.top = win; - } - - return win; - }; - - function createElement(id, offsetTop = 0) { - return { - id, - getBoundingClientRect: function () { - return { - top: offsetTop, height: 1 - } - } - } - } - - function setupSingleWindow(sandBox, placementElements = [createElement('div-1', 17), createElement('div-2', 54)]) { - let singleWin = null - singleWin = createWindow('http://www.xyz.com/', { - parent: singleWin, top: singleWin, frameElement: createElement(undefined, 304), placementElements: placementElements - }); - - singleWin.innerHeight = 200; - - sandBox.stub(utils, 'getWindowSelf').returns(singleWin); - sandBox.stub(utils, 'getWindowTop').returns(singleWin); - - return singleWin; - } - - function setupNestedWindows(sandBox, placementElements = [createElement('div-1', 17), createElement('div-2', 54)]) { - const topWin = createWindow('http://www.abc.org/'); - topWin.innerHeight = 800; - - const midWin = createWindow('http://www.abc.org/', {parent: topWin, top: topWin, frameElement: createElement()}); - midWin.innerHeight = 400; - - const win = createWindow('http://www.xyz.com/', { - parent: midWin, top: topWin, frameElement: createElement(undefined, 304), placementElements - }); - - win.innerHeight = 200; - - sandBox.stub(utils, 'getWindowSelf').returns(win); - sandBox.stub(utils, 'getWindowTop').returns(topWin); - - return {topWin, midWin, win}; - } - - it('should support BANNER and VIDEO mediaType', function () { - assert.deepEqual(spec.supportedMediaTypes, [BANNER, VIDEO]); - }); - - it('should have GDPR vendor list id (gvlid) set on the spec', function () { - assert.equal(spec.gvlid, 136); - }); - - describe('bid validation entry point', () => { - let bidRequest; - - beforeEach(() => { - bidRequest = buildBidderRequest().bids[0]; - }); - - it('should have \"isBidRequestValid\" function', () => { - assert.isFunction(spec.isBidRequestValid); - }); - - it('should pass a valid bid', () => { - assert.isTrue(spec.isBidRequestValid(bidRequest)); - }); - - it('should exclude bids without slot id param', () => { - bidRequest.params.sid = undefined; - assert.isFalse(spec.isBidRequestValid(bidRequest)); - }); - - it('should allow instream video bids', () => { - delete bidRequest.mediaTypes.banner; - bidRequest.mediaTypes.video = { - playerSize: [640, 480], - context: 'instream' - }; - - assert.isTrue(spec.isBidRequestValid(bidRequest)); - }); - - it('should allow outstream video bids', () => { - delete bidRequest.mediaTypes.banner; - bidRequest.mediaTypes.video = { - playerSize: [640, 480], - context: 'outstream' - }; - - assert.isTrue(spec.isBidRequestValid(bidRequest)); - }); - - it('should allow multi-format bid that has banner and instream video', () => { - assert.isTrue('banner' in bidRequest.mediaTypes); - - // Allowed because instream video component of the bid will be ignored in buildRequest() - bidRequest.mediaTypes.video = { - playerSize: [640, 480], - context: 'instream' - }; - - assert.isTrue(spec.isBidRequestValid(bidRequest)) - }); - - it('should exclude multi-format bid that has no format of interest', () => { - bidRequest.mediaTypes = { - video: { - playerSize: [640, 480], - context: 'adpod' - }, - native: { - image: { - required: true, - sizes: [150, 50] - }, - title: { - required: true, - len: 80 - }, - sponsoredBy: { - required: true - }, - clickUrl: { - required: true - }, - privacyLink: { - required: false - }, - body: { - required: true - }, - icon: { - required: true, - sizes: [50, 50] - } - } - }; - - assert.isFalse(spec.isBidRequestValid(bidRequest)); - }); - - it('should exclude video bids without context', () => { - delete bidRequest.mediaTypes.banner; - bidRequest.mediaTypes.video = { - playerSize: [640, 480], - context: undefined - }; - - assert.isFalse(spec.isBidRequestValid(bidRequest)); - }); - - it('should exclude video, pre-version 3 bids', () => { - delete bidRequest.mediaTypes; - bidRequest.mediaType = VIDEO; - assert.isFalse(spec.isBidRequestValid(bidRequest)); - }); - }); - - describe('build request entry point', () => { - it('should have \"buildRequests\" function', () => { - assert.isFunction(spec.buildRequests); - }); - - describe('url on server request info object', () => { - let win; - beforeEach(() => { - win = setupSingleWindow(sandbox); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should use hardcoded url as default endpoint', () => { - const bidReq = buildBidderRequest(); - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - - assert.equal(serverRequestInfo.method, 'POST'); - assert.isObject(serverRequestInfo.data); - assert.equal(serverRequestInfo.url, 'https://hb.adscale.de/dsh'); - }); - - describe('should use custom url if provided', () => { - const samples = [{ - protocol: 'http:', - params: {sid: 'ODA=', host: 'other.com', port: '234', path: '/xyz'}, - expected: 'https://other.com:234/xyz' - }, { - protocol: 'https:', - params: {sid: 'ODA=', host: 'other.com', port: '234', path: '/xyz'}, - expected: 'https://other.com:234/xyz' - }, { - protocol: 'https:', - params: {sid: 'ODA=', host: 'other.com', port: '234', securePort: '871', path: '/xyz'}, - expected: 'https://other.com:871/xyz' - }, { - protocol: 'http:', params: {sid: 'ODA=', port: '234', path: '/xyz'}, expected: 'https://hb.adscale.de:234/xyz' - }, ]; - - samples.forEach(sample => { - it(`should use ${sample.expected} as endpoint when given params ${JSON.stringify(sample.params)} and protocol ${sample.protocol}`, - function () { - win.location.protocol = sample.protocol; - - const bidReq = buildBidderRequest(); - bidReq.bids[0].params = sample.params; - bidReq.bids.length = 1; - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - - assert.equal(serverRequestInfo.method, 'POST'); - assert.isObject(serverRequestInfo.data); - assert.equal(serverRequestInfo.url, sample.expected); - }); - }); - }); - }); - - describe('payload on server request info object', () => { - let topWin; - let win; - - let placementElements; - beforeEach(() => { - placementElements = [createElement('div-1', 17), createElement('div-2', 54)]; - ({ topWin, win } = setupNestedWindows(sandbox, placementElements)); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should have expected JSON structure', () => { - clock.tick(13500); - const bidReq = buildBidderRequest(); - - const UUID = 'fb6a39e3-083f-424c-9046-f1095e15f3d5'; - - const generateUUIDStub = sinon.stub(utils, 'generateUUID').returns(UUID); - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - - const expectedTimeout = bidderRequest.timeout - (13500 - bidderRequest.auctionStart); - - assert.equal(expectedTimeout, 1500); - - const expectedJsonPayload = { - 'id': UUID, - 'timeout': expectedTimeout, - 'ref': 'https://www.example.com/?search=monkey', - 'mpa': true, - 'url': 'https://www.example.com/monkey/index.html', - 'bids': [{ - 'sid': 'NDA=', - 'bid': 'bid1', - 'viz': true, - 'ban': { - 'siz': [[300, 600], [160, 60]] - } - }, { - 'sid': 'ODA=', - 'bid': 'bid2', - 'viz': true, - 'ban': { - 'siz': [[728, 90]] - } - }], - 'user': { - 'eids': eids - }, - 'ver': { - 'pb': getGlobal().version, - } - }; - - // trim away fields with undefined - const actualJsonPayload = JSON.parse(JSON.stringify(serverRequestInfo.data)); - assert.deepEqual(actualJsonPayload, expectedJsonPayload); - - generateUUIDStub.restore(); - }); - - describe('video bids', () => { - it('should be able to build instream video bid', () => { - bidderRequest.bids = [{ - bidId: 'bid1', - bidder: 'stroeerCore', - adUnitCode: 'div-1', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480], - mimes: ['video/mp4', 'video/quicktime'] - } - }, - params: { - sid: 'NDA=' - }, - userIdAsEids: eids - }]; - - const expectedBids = [{ - 'sid': 'NDA=', - 'bid': 'bid1', - 'viz': true, - 'vid': { - 'ctx': 'instream', - 'siz': [640, 480], - 'mim': ['video/mp4', 'video/quicktime'] - } - }]; - - const serverRequestInfo = spec.buildRequests(bidderRequest.bids, bidderRequest); - - const bids = JSON.parse(JSON.stringify(serverRequestInfo.data.bids)); - assert.deepEqual(bids, expectedBids); - }); - }); - - describe('multi-formats', () => { - it(`should create a request for video and banner`, () => { - const videoBid = { - bidId: 'bid3', - bidder: 'stroeerCore', - adUnitCode: 'div-1', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480], - mimes: ['video/mp4', 'video/quicktime'], - } - }, - params: { - sid: 'ODA=', - }, - userIdAsEids: eids - } - - const bannerBid1 = { - bidId: 'bid8', - bidder: 'stroeerCore', - adUnitCode: 'div-2', - mediaTypes: { - banner: { - sizes: [[300, 600], [160, 60]], - } - }, - params: { - sid: 'NDA=', - }, - userIdAsEids: eids - } - - const bannerBid2 = { - bidId: 'bid12', - bidder: 'stroeerCore', - adUnitCode: 'div-3', - mediaTypes: { - banner: { - sizes: [[100, 200], [300, 500]], - } - }, - params: { - sid: 'ABC=', - }, - userIdAsEids: eids - } - - bidderRequest.bids = [bannerBid1, videoBid, bannerBid2]; - - const expectedBannerBids = [ - { - 'sid': 'NDA=', - 'bid': 'bid8', - 'viz': true, - 'ban': { - 'siz': [[300, 600], [160, 60]], - 'fp': undefined - }, - 'sfp': undefined, - }, - { - 'sid': 'ABC=', - 'bid': 'bid12', - 'ban': { - 'siz': [[100, 200], [300, 500]], - 'fp': undefined - }, - 'viz': undefined, - 'sfp': undefined, - } - ]; - - const expectedVideoBids = [ - { - 'sid': 'ODA=', - 'bid': 'bid3', - 'viz': true, - 'vid': { - 'ctx': 'instream', - 'siz': [640, 480], - 'mim': ['video/mp4', 'video/quicktime'], - 'fp': undefined - }, - 'sfp': undefined, - } - ]; - - const serverRequestInfo = spec.buildRequests(bidderRequest.bids, bidderRequest); - - assert.deepEqual(serverRequestInfo.data.bids, [...expectedBannerBids, ...expectedVideoBids]); - }); - - it('should split multi-format bid', function() { - const multiFormatBid = { - bidId: 'bid3', - bidder: 'stroeerCore', - adUnitCode: 'div-1', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480], - mimes: ['video/mp4', 'video/quicktime'], - }, - banner: { - sizes: [[100, 200], [300, 500]], - } - }, - params: { - sid: 'ODA=', - }, - userIdAsEids: eids - } - - bidderRequest.bids = [multiFormatBid]; - - const serverRequestInfo = spec.buildRequests(bidderRequest.bids, bidderRequest); - - const expectedBannerBids = [ - { - 'sid': 'ODA=', - 'bid': 'bid3', - 'viz': true, - 'ban': { - 'siz': [[100, 200], [300, 500]], - 'fp': undefined - }, - 'sfp': undefined, - } - ]; - - const expectedVideoBids = [ - { - 'sid': 'ODA=', - 'bid': 'bid3', - 'viz': true, - 'vid': { - 'ctx': 'instream', - 'siz': [640, 480], - 'mim': ['video/mp4', 'video/quicktime'], - 'fp': undefined - }, - 'sfp': undefined, - } - ]; - - assert.deepEqual(serverRequestInfo.data.bids, [...expectedBannerBids, ...expectedVideoBids]); - }); - }); - - describe('optional fields', () => { - it('should skip viz field when unable to determine visibility of placement', () => { - placementElements.length = 0; - const bidReq = buildBidderRequest(); - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - assert.lengthOf(serverRequestInfo.data.bids, 2); - - for (const bid of serverRequestInfo.data.bids) { - assert.isUndefined(bid.viz); - } - }); - - it('should skip ref field when unable to determine document referrer', () => { - // i.e., empty if user came from bookmark, or web page using 'rel="noreferrer" on link, etc - buildBidderRequest(); - - const serverRequestInfo = spec.buildRequests(bidderRequest.bids, bidderRequest); - assert.lengthOf(serverRequestInfo.data.bids, 2); - - for (const bid of serverRequestInfo.data.bids) { - assert.isUndefined(bid.ref); - } - }); - - const gdprSamples = [ - {consentString: 'RG9ua2V5IEtvbmc=', gdprApplies: true}, - {consentString: 'UGluZyBQb25n', gdprApplies: false}, - {consentString: undefined, gdprApplies: true}, - {consentString: undefined, gdprApplies: false}, - {consentString: undefined, gdprApplies: undefined}, - ]; - gdprSamples.forEach((sample) => { - it(`should add GDPR info ${JSON.stringify(sample)} when provided`, () => { - const bidReq = buildBidderRequest(); - bidReq.gdprConsent = sample; - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - - const actualGdpr = serverRequestInfo.data.gdpr; - assert.propertyVal(actualGdpr, 'applies', sample.gdprApplies); - assert.propertyVal(actualGdpr, 'consent', sample.consentString); - }); - }); - - it(`should not add GDPR info when not provided`, () => { - const bidReq = buildBidderRequest(); - - delete bidReq.gdprConsent; - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - - assert.notProperty(serverRequestInfo.data, 'gdpr'); - }); - - it('should be able to build without third party user id data', () => { - const bidReq = buildBidderRequest(); - bidReq.bids.forEach(bid => delete bid.userIdAsEids); - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - assert.lengthOf(serverRequestInfo.data.bids, 2); - assert.notProperty(serverRequestInfo.data, 'user'); - }); - - it('should add schain if available', () => { - const schain = Object.freeze({ - ver: '1.0', - complete: 1, - 'nodes': [ - { - asi: 'exchange1.com', - sid: 'ABC', - hp: 1, - rid: 'bid-request-1', - name: 'publisher', - domain: 'publisher.com' - } - ] - }); - - const bidReq = buildBidderRequest(); - bidReq.bids.forEach(bid => { - bid.ortb2 = bid.ortb2 || {}; - bid.ortb2.source = bid.ortb2.source || {}; - bid.ortb2.source.ext = bid.ortb2.source.ext || {}; - bid.ortb2.source.ext.schain = schain; - }); - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - assert.deepEqual(serverRequestInfo.data.schain, schain); - }); - - it('should add floor info to banner bid request if floor is available', () => { - const bidReq = buildBidderRequest(); - - const getFloorStub1 = sinon.stub(); - const getFloorStub2 = sinon.stub(); - - getFloorStub1 - .returns({}) - .withArgs({currency: 'EUR', mediaType: BANNER, size: '*'}) - .returns({currency: 'TRY', floor: 0.7}) - .withArgs({currency: 'EUR', mediaType: 'banner', size: [300, 600]}) - .returns({currency: 'TRY', floor: 1.3}) - .withArgs({currency: 'EUR', mediaType: 'banner', size: [160, 60]}) - .returns({currency: 'TRY', floor: 2.5}) - - getFloorStub2 - .returns({}) - .withArgs({currency: 'EUR', mediaType: 'banner', size: '*'}) - .returns({currency: 'USD', floor: 1.2}) - .withArgs({currency: 'EUR', mediaType: 'banner', size: [728, 90]}) - .returns({currency: 'USD', floor: 1.85}) - - bidReq.bids[0].getFloor = getFloorStub1; - bidReq.bids[1].getFloor = getFloorStub2; - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - - const serverRequestBids = serverRequestInfo.data.bids; - const firstBid = serverRequestBids[0]; - const secondBid = serverRequestBids[1]; - - assert.nestedPropertyVal(firstBid, 'ban.fp.def', 0.7); - assert.nestedPropertyVal(firstBid, 'ban.fp.cur', 'TRY'); - assert.deepNestedPropertyVal(firstBid, 'ban.fp.siz', [{w: 300, h: 600, p: 1.3}, {w: 160, h: 60, p: 2.5}]); - - assert.isTrue(getFloorStub1.calledThrice); - - assert.nestedPropertyVal(secondBid, 'ban.fp.def', 1.2); - assert.nestedPropertyVal(secondBid, 'ban.fp.cur', 'USD'); - assert.deepNestedPropertyVal(secondBid, 'ban.fp.siz', [{w: 728, h: 90, p: 1.85}]); - - assert.isTrue(getFloorStub2.calledTwice); - }); - - it('should add floor info to video bid request if floor is available', () => { - const bidReq = buildBidderRequest(); - - const getFloorStub1 = sinon.stub(); - const getFloorStub2 = sinon.stub(); - - getFloorStub1 - .returns({}) - .withArgs({currency: 'EUR', mediaType: 'video', size: '*'}) - .returns({currency: 'NZD', floor: 3.25}) - .withArgs({currency: 'EUR', mediaType: 'video', size: [640, 480]}) - .returns({currency: 'NZD', floor: 4.10}); - - getFloorStub2 - .returns({}) - .withArgs({currency: 'EUR', mediaType: 'video', size: '*'}) - .returns({currency: 'GBP', floor: 4.75}) - .withArgs({currency: 'EUR', mediaType: 'video', size: [1280, 720]}) - .returns({currency: 'GBP', floor: 6.50}) - - delete bidReq.bids[0].mediaTypes.banner; - bidReq.bids[0].mediaTypes.video = { - playerSize: [640, 480], - context: 'instream' - }; - - delete bidReq.bids[1].mediaTypes.banner; - bidReq.bids[1].mediaTypes.video = { - playerSize: [1280, 720], - context: 'outstream' - }; - - bidReq.bids[0].getFloor = getFloorStub1; - bidReq.bids[1].getFloor = getFloorStub2; - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - - const serverRequestBids = serverRequestInfo.data.bids; - const firstBid = serverRequestBids[0]; - const secondBid = serverRequestBids[1]; - - assert.nestedPropertyVal(firstBid, 'vid.fp.def', 3.25); - assert.nestedPropertyVal(firstBid, 'vid.fp.cur', 'NZD'); - assert.deepNestedPropertyVal(firstBid, 'vid.fp.siz', [{w: 640, h: 480, p: 4.10}]); - - assert.isTrue(getFloorStub1.calledTwice); - - assert.nestedPropertyVal(secondBid, 'vid.fp.def', 4.75); - assert.nestedPropertyVal(secondBid, 'vid.fp.cur', 'GBP'); - assert.deepNestedPropertyVal(secondBid, 'vid.fp.siz', [{w: 1280, h: 720, p: 6.50}]); - - assert.isTrue(getFloorStub2.calledTwice); - }); - - it('should not add floor info to bid request if floor is unavailable', () => { - const bidReq = buildBidderRequest(); - const getFloorSpy = sinon.spy(() => ({})); - - delete bidReq.bids[0].getFloor; - bidReq.bids[1].getFloor = getFloorSpy; - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - - const serverRequestBids = serverRequestInfo.data.bids; - const firstBid = serverRequestBids[0]; - const secondBid = serverRequestBids[1]; - - assert.nestedPropertyVal(firstBid, 'ban.fp', undefined); - assert.nestedPropertyVal(secondBid, 'ban.fp', undefined); - - assert.isTrue(getFloorSpy.calledWith({currency: 'EUR', mediaType: 'banner', size: '*'})); - assert.isTrue(getFloorSpy.calledWith({currency: 'EUR', mediaType: 'banner', size: [728, 90]})); - assert.isTrue(getFloorSpy.calledTwice); - }); - - it('should not add floor info for a size when it is the same as the default', () => { - const bidReq = buildBidderRequest(); - const getFloorStub = sinon.stub(); - - getFloorStub - .returns({currency: 'EUR', floor: 1.9}) - .withArgs({currency: 'EUR', mediaType: BANNER, size: [160, 60]}) - .returns({currency: 'EUR', floor: 2.7}); - - bidReq.bids[0].getFloor = getFloorStub; - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - - const serverRequestBids = serverRequestInfo.data.bids; - const bid = serverRequestBids[0]; - - assert.nestedPropertyVal(bid, 'ban.fp.def', 1.9); - assert.nestedPropertyVal(bid, 'ban.fp.cur', 'EUR'); - assert.deepNestedPropertyVal(bid, 'ban.fp.siz', [{w: 160, h: 60, p: 2.7}]); - }); - - it('should add the DSA signals', () => { - const bidReq = buildBidderRequest(); - const dsa = { - dsarequired: 3, - pubrender: 0, - datatopub: 2, - transparency: [ - { - domain: 'testplatform.com', - dsaparams: [1], - }, - { - domain: 'testdomain.com', - dsaparams: [1, 2] - } - ] - } - const ortb2 = { - regs: { - ext: { - dsa - } - } - } - - bidReq.ortb2 = utils.deepClone(ortb2); - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - const sentOrtb2 = serverRequestInfo.data.ortb2; - - assert.deepEqual(sentOrtb2, ortb2); - }); - - it('should add the Cookie Deprecation Label', () => { - const bidReq = buildBidderRequest(); - - const cDepObj = { - cdep: 'example_label_1' - }; - - const ortb2 = { - device: { - ext: cDepObj - } - }; - - bidReq.ortb2 = utils.deepClone(ortb2); - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - const sentOrtb2 = serverRequestInfo.data.ortb2; - - assert.deepEqual(sentOrtb2, ortb2); - }); - - it('should add the special format parameters', () => { - const bidReq = buildBidderRequest(); - - const sfp0 = { - 'field1': { - 'abc': '123', - } - }; - - const sfp1 = { - 'field3': 'xyz' - }; - - bidReq.bids[0].params.sfp = utils.deepClone(sfp0); - bidReq.bids[1].params.sfp = utils.deepClone(sfp1); - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - - assert.deepEqual(serverRequestInfo.data.bids[0].sfp, sfp0); - assert.deepEqual(serverRequestInfo.data.bids[1].sfp, sfp1); - }); - - it('should add the special format parameters even when it is an empty object', () => { - const bidReq = buildBidderRequest(); - - bidReq.bids[0].params.sfp = {}; - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - - assert.deepEqual(serverRequestInfo.data.bids[0].sfp, {}); - assert.isUndefined(serverRequestInfo.data.bids[1].sfp); - }); - - it('should add the ortb2 site extension', () => { - const bidReq = buildBidderRequest(); - - const ortb2 = { - site: { - domain: 'example.com', - ext: { - data: { - abc: '123' - } - } - } - }; - - bidReq.ortb2 = utils.deepClone(ortb2); - - const serverRequestInfo = spec.buildRequests(bidReq.bids, bidReq); - - const sentOrtb2 = serverRequestInfo.data.ortb2; - assert.deepEqual(sentOrtb2, {site: {ext: ortb2.site.ext}}) - }); - }); - }); - }); - - describe('interpret response entry point', () => { - it('should have \"interpretResponse\" function', () => { - assert.isFunction(spec.interpretResponse); - }); - - const invalidResponses = ['', ' ', ' ', undefined, null]; - invalidResponses.forEach(sample => { - it('should ignore invalid responses (\"' + sample + '\") response', () => { - const result = spec.interpretResponse({body: sample}); - assert.isArray(result); - assert.lengthOf(result, 0); - }); - }); - - it('should interpret a standard response', () => { - const bidderResponse = buildBidderResponse(); - - const result = spec.interpretResponse({body: bidderResponse}); - assertStandardFieldsOnBannerBid(result[0], 'bid1', '
tag1
', 300, 600, 4); - assertStandardFieldsOnBannerBid(result[1], 'bid2', '
tag2
', 728, 90, 7.3); - }); - - it('should return empty array, when response contains no bids', () => { - const result = spec.interpretResponse({body: {bids: []}}); - assert.deepStrictEqual(result, []); - }); - - it('should interpret a video response', () => { - const bidderResponse = buildBidderResponseWithVideo(); - const bidResponses = spec.interpretResponse({body: bidderResponse}); - const videoBidResponse = bidResponses[0]; - assertStandardFieldsOnVideoBid(videoBidResponse, 'bid1', 'video', 800, 250, 4); - }) - - it('should set meta object', () => { - const dsaResponse = { - behalf: 'AdvertiserA', - paid: 'AdvertiserB', - transparency: [{ - domain: 'dspexample.com', - dsaparams: [1, 2], - }], - adrender: 1, - }; - - const response = buildBidderResponse(); - response.bids[0] = Object.assign(response.bids[0], { - meta: { - advertiserDomains: ['website.org', 'domain.com'], - dsa: utils.deepClone(dsaResponse), - campaignType: 'RTB', - another: 'thing', - }, - }); - - const result = spec.interpretResponse({body: response}); - - const firstBidMeta = result[0].meta; - assert.deepPropertyVal(firstBidMeta, 'advertiserDomains', ['website.org', 'domain.com']); - assert.deepPropertyVal(firstBidMeta, 'dsa', dsaResponse); - assert.propertyVal(firstBidMeta, 'campaignType', 'RTB'); - assert.propertyVal(firstBidMeta, 'another', 'thing'); - - assert.isEmpty(result[1].meta) - }); - }); - - describe('get user syncs entry point', () => { - let win; - - beforeEach(() => { - win = setupSingleWindow(sandbox); - - // fake - win.document.createElement = function () { - const attrs = {}; - return { - setAttribute: (name, value) => { - attrs[name] = value - }, - getAttribute: (name) => attrs[name], - hasAttribute: (name) => attrs[name] !== undefined, - tagName: 'SCRIPT', - } - } - }); - - it('should have \"getUserSyncs\" function', () => { - assert.isFunction(spec.getUserSyncs); - }); - - describe('when iframe option is enabled', () => { - it('should perform user connect when there was a response', () => { - const expectedUrl = 'https://js.adscale.de/pbsync.html'; - const userSyncResponse = spec.getUserSyncs({iframeEnabled: true}, ['']); - - assert.deepStrictEqual(userSyncResponse, [{type: 'iframe', url: expectedUrl}]); - }); - - it('should not perform user connect when there was no response', () => { - const userSyncResponse = spec.getUserSyncs({iframeEnabled: true}, []); - - assert.deepStrictEqual(userSyncResponse, []); - }); - - describe('and gdpr consent is defined', () => { - describe('and gdpr applies', () => { - it('should place gdpr query param to the user sync url with value of 1', () => { - const expectedUrl = 'https://js.adscale.de/pbsync.html?gdpr=1&gdpr_consent='; - const userSyncResponse = spec.getUserSyncs({iframeEnabled: true}, [''], {gdprApplies: true}); - - assert.deepStrictEqual(userSyncResponse, [{type: 'iframe', url: expectedUrl}]); - }); - }); - - describe('and gdpr does not apply', () => { - it('should place gdpr query param to the user sync url with zero value', () => { - const expectedUrl = 'https://js.adscale.de/pbsync.html?gdpr=0&gdpr_consent='; - const userSyncResponse = spec.getUserSyncs({iframeEnabled: true}, [''], {gdprApplies: false}); - - assert.deepStrictEqual(userSyncResponse, [{type: 'iframe', url: expectedUrl}]); - }); - - describe('because consent does not specify it', () => { - it('should place gdpr query param to the user sync url with zero value', () => { - const expectedUrl = 'https://js.adscale.de/pbsync.html?gdpr=0&gdpr_consent='; - const userSyncResponse = spec.getUserSyncs({iframeEnabled: true}, [''], {}); - - assert.deepStrictEqual(userSyncResponse, [{type: 'iframe', url: expectedUrl}]); - }); - }); - }); - - describe('and consent string is defined', () => { - it('should pass consent string to gdpr consent query param', () => { - const consentString = 'consent_string'; - const expectedUrl = `https://js.adscale.de/pbsync.html?gdpr=1&gdpr_consent=${consentString}`; - const userSyncResponse = spec.getUserSyncs({iframeEnabled: true}, [''], {gdprApplies: true, consentString}); - - assert.deepStrictEqual(userSyncResponse, [{type: 'iframe', url: expectedUrl}]); - }); - - it('should correctly escape invalid characters', () => { - const consentString = 'consent ?stri&ng'; - const expectedUrl = `https://js.adscale.de/pbsync.html?gdpr=1&gdpr_consent=consent%20%3Fstri%26ng`; - const userSyncResponse = spec.getUserSyncs({iframeEnabled: true}, [''], {gdprApplies: true, consentString}); - - assert.deepStrictEqual(userSyncResponse, [{type: 'iframe', url: expectedUrl}]); - }); - }); - }); - }); - - describe('when iframe option is disabled', () => { - it('should not perform user connect even when there was a response', () => { - const userSyncResponse = spec.getUserSyncs({iframeEnabled: false}, ['']); - - assert.deepStrictEqual(userSyncResponse, []); - }); - - it('should not perform user connect when there was no response', () => { - const userSyncResponse = spec.getUserSyncs({iframeEnabled: false}, []); - - assert.deepStrictEqual(userSyncResponse, []); - }); - }); - }); -}); diff --git a/test/spec/modules/stvBidAdapter_spec.js b/test/spec/modules/stvBidAdapter_spec.js deleted file mode 100644 index 9da594d8b..000000000 --- a/test/spec/modules/stvBidAdapter_spec.js +++ /dev/null @@ -1,526 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/stvBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; - -const ENDPOINT_URL = 'https://ads.smartstream.tv/r/'; -const ENDPOINT_URL_DEV = 'https://ads.smartstream.tv/r/'; - -describe('stvAdapter', function() { - const adapter = newBidder(spec); - - describe('isBidRequestValid', function() { - const bid = { - 'bidder': 'stv', - 'params': { - 'placement': '6682', - 'floorprice': 1000000, - 'bcat': 'IAB2,IAB4', - 'dvt': 'desktop' - }, - 'sizes': [ - [300, 250] - ], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475' - }; - - it('should return true when required params found', function() { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function() { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'someIncorrectParam': 0 - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function() { - const bidRequests = [ - // banner - { - 'bidder': 'stv', - 'params': { - 'placement': '6682', - 'floorprice': 1000000, - 'geo': { - 'country': 'DE' - }, - 'bcat': 'IAB2,IAB4', - 'dvt': 'desktop' - }, - 'sizes': [ - [300, 250] - ], - 'bidId': '30b31c1838de1e1', - 'bidderRequestId': '22edbae2733bf61', - 'auctionId': '1d1a030790a475', - 'adUnitCode': 'testDiv1', - 'ortb2': { - 'source': { - 'ext': { - 'schain': { - 'ver': '1.0', - 'complete': 0, - 'nodes': [ - { - 'asi': 'reseller.com', - 'sid': 'aaaaa', - 'rid': 'BidRequest4', - 'hp': 1 - } - ] - } - } - } - }, - 'userIdAsEids': [ - { - 'source': 'id5-sync.com', - 'uids': [{ - 'id': '1234', - 'ext': { - 'linkType': 'abc' - } - }] - }, - { - 'source': 'netid.de', - 'uids': [{ - 'id': '2345' - }] - }, - { - 'source': 'uidapi.com', - 'uids': [{ - 'id': '3456' - }] - }, - { - 'source': 'pubcid.org', - 'uids': [{ - 'id': '4567' - }] - }, - { - 'source': 'liveramp.com', - 'uids': [{ - 'id': '5678' - }] - }, - { - 'source': 'criteo.com', - 'uids': [{ - 'id': '6789' - }] - }, - { - 'source': 'utiq.com', - 'uids': [{ - 'id': '7890' - }] - }, - { - 'source': 'euid.eu', - 'uids': [{ - 'id': '8901' - }] - } - ] - }, - { - 'bidder': 'stv', - 'params': { - 'placement': '101', - 'devMode': true - }, - 'sizes': [ - [300, 250] - ], - 'bidId': '30b31c1838de1e2', - 'bidderRequestId': '22edbae2733bf62', - 'auctionId': '1d1a030790a476', - 'userIdAsEids': [ - { - 'source': 'id5-sync.com', - 'uids': [{ - 'id': '1234', - 'ext': { - 'linkType': 'abc' - } - }] - }, - { - 'source': 'netid.de', - 'uids': [{ - 'id': '2345' - }] - }, - { - 'source': 'uidapi.com', - 'uids': [{ - 'id': '3456' - }] - }, - { - 'source': 'pubcid.org', - 'uids': [{ - 'id': '4567' - }] - }, - { - 'source': 'liveramp.com', - 'uids': [{ - 'id': '5678' - }] - }, - { - 'source': 'criteo.com', - 'uids': [{ - 'id': '6789' - }] - }, - { - 'source': 'utiq.com', - 'uids': [{ - 'id': '7890' - }] - }, - { - 'source': 'euid.eu', - 'uids': [{ - 'id': '8901' - }] - } - ] - }, { - 'bidder': 'stv', - 'params': { - 'placement': '6682', - 'floorprice': 1000000, - 'geo': { - 'country': 'DE' - }, - 'bcat': 'IAB2,IAB4', - 'dvt': 'desktop' - }, - 'sizes': [ - [300, 250] - ], - 'bidId': '30b31c1838de1e3', - 'bidderRequestId': '22edbae2733bf69', - 'auctionId': '1d1a030790a477', - 'adUnitCode': 'testDiv2' - }, - // video - { - 'bidder': 'stv', - 'params': { - 'placement': '101', - 'devMode': true, - 'max_duration': 20, - }, - 'mediaTypes': { - 'video': { - 'playerSize': [640, 480], - 'context': 'instream' - }, - }, - - 'bidId': '30b31c1838de1e4', - 'bidderRequestId': '22edbae2733bf67', - 'auctionId': '1d1a030790a478', - 'adUnitCode': 'testDiv3' - }, - { - 'bidder': 'stv', - 'params': { - 'placement': '101', - 'devMode': true, - }, - 'mediaTypes': { - 'video': { - 'playerSize': [640, 480], - 'context': 'instream', - 'maxduration': 40, - } - }, - 'bidId': '30b31c1838de1e41', - 'bidderRequestId': '22edbae2733bf67', - 'auctionId': '1d1a030790a478', - 'adUnitCode': 'testDiv4' - }, - { - 'bidder': 'stv', - 'params': { - 'placement': '101', - 'devMode': true, - 'max_duration': 20, - }, - 'mediaTypes': { - 'video': { - 'playerSize': [640, 480], - 'context': 'instream', - 'maxduration': 40, - } - }, - 'bidId': '30b31c1838de1e41', - 'bidderRequestId': '22edbae2733bf67', - 'auctionId': '1d1a030790a478', - 'adUnitCode': 'testDiv4' - } - - ]; - - // With gdprConsent - var bidderRequest = { - refererInfo: { - referer: 'some_referrer.net' - }, - gdprConsent: { - consentString: 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - vendorData: { someData: 'value' }, - gdprApplies: true - } - }; - - var request1 = spec.buildRequests([bidRequests[0]], bidderRequest)[0]; - it('sends bid request 1 to our endpoint via GET', function() { - expect(request1.method).to.equal('GET'); - expect(request1.url).to.equal(ENDPOINT_URL); - const data = request1.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid').replace(/pbver=.*?&/g, 'pbver=test&'); - expect(data).to.equal('_f=html&alternative=prebid_js&_ps=6682&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e1&pbver=test&schain=1.0,0!reseller.com,aaaaa,1,BidRequest4,,&uids=id5%3A1234,id5_linktype%3Aabc,netid%3A2345,uid2%3A3456,sharedid%3A4567,liverampid%3A5678,criteoid%3A6789,utiq%3A7890,euid%3A8901&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bgeo%5D%5Bcountry%5D=DE&gdpr_consent=BOJ%2FP2HOJ%2FP2HABABMAAAAAZ%2BA%3D%3D&gdpr=true&bcat=IAB2%2CIAB4&dvt=desktop&pbcode=testDiv1&media_types%5Bbanner%5D=300x250'); - }); - - var request2 = spec.buildRequests([bidRequests[1]], bidderRequest)[0]; - it('sends bid request 2 endpoint via GET', function() { - expect(request2.method).to.equal('GET'); - expect(request2.url).to.equal(ENDPOINT_URL); - const data = request2.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid').replace(/pbver=.*?&/g, 'pbver=test&'); - expect(data).to.equal('_f=html&alternative=prebid_js&_ps=101&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e2&pbver=test&uids=id5%3A1234,id5_linktype%3Aabc,netid%3A2345,uid2%3A3456,sharedid%3A4567,liverampid%3A5678,criteoid%3A6789,utiq%3A7890,euid%3A8901&gdpr_consent=BOJ%2FP2HOJ%2FP2HABABMAAAAAZ%2BA%3D%3D&gdpr=true&prebidDevMode=1&media_types%5Bbanner%5D=300x250'); - }); - - // Without gdprConsent - var bidderRequestWithoutGdpr = { - refererInfo: { - referer: 'some_referrer.net' - } - }; - var request3 = spec.buildRequests([bidRequests[2]], bidderRequestWithoutGdpr)[0]; - it('sends bid request 3 without gdprConsent to our endpoint via GET', function() { - expect(request3.method).to.equal('GET'); - expect(request3.url).to.equal(ENDPOINT_URL); - const data = request3.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid').replace(/pbver=.*?&/g, 'pbver=test&'); - expect(data).to.equal('_f=html&alternative=prebid_js&_ps=6682&srw=300&srh=250&idt=100&bid_id=30b31c1838de1e3&pbver=test&pfilter%5Bfloorprice%5D=1000000&pfilter%5Bgeo%5D%5Bcountry%5D=DE&bcat=IAB2%2CIAB4&dvt=desktop&pbcode=testDiv2&media_types%5Bbanner%5D=300x250'); - }); - - var request4 = spec.buildRequests([bidRequests[3]], bidderRequestWithoutGdpr)[0]; - it('sends bid request 4 (video) without gdprConsent endpoint via GET', function() { - expect(request4.method).to.equal('GET'); - expect(request4.url).to.equal(ENDPOINT_URL); - const data = request4.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid').replace(/pbver=.*?&/g, 'pbver=test&'); - expect(data).to.equal('_f=vast2&alternative=prebid_js&_ps=101&srw=640&srh=480&idt=100&bid_id=30b31c1838de1e4&pbver=test&pfilter%5Bmax_duration%5D=20&prebidDevMode=1&pbcode=testDiv3&media_types%5Bvideo%5D=640x480'); - }); - - var request5 = spec.buildRequests([bidRequests[4]], bidderRequestWithoutGdpr)[0]; - it('sends bid request 5 (video) to our endpoint via GET', function() { - expect(request5.method).to.equal('GET'); - expect(request5.url).to.equal(ENDPOINT_URL); - const data = request5.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid').replace(/pbver=.*?&/g, 'pbver=test&'); - expect(data).to.equal('_f=vast2&alternative=prebid_js&_ps=101&srw=640&srh=480&idt=100&bid_id=30b31c1838de1e41&pbver=test&pfilter%5Bmax_duration%5D=40&prebidDevMode=1&pbcode=testDiv4&media_types%5Bvideo%5D=640x480'); - }); - - var request6 = spec.buildRequests([bidRequests[5]], bidderRequestWithoutGdpr)[0]; - it('sends bid request 6 (video) to our endpoint via GET', function() { - expect(request6.method).to.equal('GET'); - expect(request6.url).to.equal(ENDPOINT_URL); - const data = request6.data.replace(/rnd=\d+\&/g, '').replace(/ref=.*\&bid/g, 'bid').replace(/pbver=.*?&/g, 'pbver=test&'); - expect(data).to.equal('_f=vast2&alternative=prebid_js&_ps=101&srw=640&srh=480&idt=100&bid_id=30b31c1838de1e41&pbver=test&pfilter%5Bmax_duration%5D=20&prebidDevMode=1&pbcode=testDiv4&media_types%5Bvideo%5D=640x480'); - }); - }); - - describe('interpretResponse', function() { - const serverResponse = { - 'body': { - 'cpm': 5000000, - 'crid': 100500, - 'width': '300', - 'height': '250', - 'type': 'sspHTML', - 'adTag': '', - 'requestId': '220ed41385952a', - 'currency': 'EUR', - 'ttl': 60, - 'netRevenue': true, - 'zone': '6682', - 'adomain': ['bdomain'] - } - }; - const serverVideoResponse = { - 'body': { - 'cpm': 5000000, - 'crid': 100500, - 'width': '300', - 'height': '250', - 'vastXml': '{"reason":7001,"status":"accepted"}', - 'requestId': '220ed41385952a', - 'type': 'vast2', - 'currency': 'EUR', - 'ttl': 60, - 'netRevenue': true, - 'zone': '6682' - } - }; - - const expectedResponse = [{ - requestId: '23beaa6af6cdde', - cpm: 0.5, - width: 0, - height: 0, - creativeId: 100500, - dealId: '', - currency: 'EUR', - netRevenue: true, - ttl: 300, - meta: { advertiserDomains: ['bdomain'] }, - ad: '', - }, { - requestId: '23beaa6af6cdde', - cpm: 0.5, - width: 0, - height: 0, - creativeId: 100500, - dealId: '', - currency: 'EUR', - netRevenue: true, - ttl: 300, - meta: { advertiserDomains: [] }, - vastXml: '{"reason":7001,"status":"accepted"}', - mediaType: 'video', - }]; - - it('should get the correct bid response by display ad', function() { - const bidRequest = [{ - 'method': 'GET', - 'url': ENDPOINT_URL, - 'data': { - 'bid_id': '30b31c1838de1e' - } - }]; - const result = spec.interpretResponse(serverResponse, bidRequest[0]); - expect(Object.keys(result[0])).to.include.members(Object.keys(expectedResponse[0])); - expect(result[0].meta.advertiserDomains.length).to.equal(1); - expect(result[0].meta.advertiserDomains[0]).to.equal(expectedResponse[0].meta.advertiserDomains[0]); - }); - - it('should get the correct smartstream video bid response by display ad', function() { - const bidRequest = [{ - 'method': 'GET', - 'url': ENDPOINT_URL, - 'mediaTypes': { - 'video': { - 'playerSize': [640, 480], - 'context': 'instream' - } - }, - 'data': { - 'bid_id': '30b31c1838de1e' - } - }]; - const result = spec.interpretResponse(serverVideoResponse, bidRequest[0]); - expect(Object.keys(result[0])).to.include.members(Object.keys(expectedResponse[1])); - expect(result[0].meta.advertiserDomains.length).to.equal(0); - }); - - it('handles empty bid response', function() { - const response = { - body: {} - }; - const result = spec.interpretResponse(response); - expect(result.length).to.equal(0); - }); - }); - - describe(`getUserSyncs test usage`, function() { - let serverResponses; - - beforeEach(function() { - serverResponses = [{ - body: { - requestId: '23beaa6af6cdde', - cpm: 0.5, - width: 0, - height: 0, - creativeId: 100500, - dealId: '', - currency: 'EUR', - netRevenue: true, - ttl: 300, - type: 'sspHTML', - ad: '', - userSync: { - iframeUrl: ['anyIframeUrl?a=1'], - imageUrl: ['anyImageUrl', 'anyImageUrl2'] - } - } - }]; - }); - - it(`return value should be an array`, function() { - expect(spec.getUserSyncs({ iframeEnabled: true })).to.be.an('array'); - }); - it(`array should have only one object and it should have a property type = 'iframe'`, function() { - expect(spec.getUserSyncs({ iframeEnabled: true }, serverResponses).length).to.be.equal(1); - const [userSync] = spec.getUserSyncs({ iframeEnabled: true }, serverResponses); - expect(userSync).to.have.property('type'); - expect(userSync.type).to.be.equal('iframe'); - }); - it(`we have valid sync url for iframe`, function() { - const [userSync] = spec.getUserSyncs({ iframeEnabled: true }, serverResponses, { consentString: 'anyString' }); - expect(userSync.url).to.be.equal('anyIframeUrl?a=1&gdpr_consent=anyString') - expect(userSync.type).to.be.equal('iframe'); - }); - it(`we have valid sync url for image`, function() { - const [userSync] = spec.getUserSyncs({ pixelEnabled: true }, serverResponses, { gdprApplies: true, consentString: 'anyString' }); - expect(userSync.url).to.be.equal('anyImageUrl?gdpr=1&gdpr_consent=anyString') - expect(userSync.type).to.be.equal('image'); - }); - it(`we have valid sync url for image and iframe`, function() { - const userSync = spec.getUserSyncs({ iframeEnabled: true, pixelEnabled: true }, serverResponses, { gdprApplies: true, consentString: 'anyString' }); - expect(userSync.length).to.be.equal(3); - expect(userSync[0].url).to.be.equal('anyIframeUrl?a=1&gdpr=1&gdpr_consent=anyString') - expect(userSync[0].type).to.be.equal('iframe'); - expect(userSync[1].url).to.be.equal('anyImageUrl?gdpr=1&gdpr_consent=anyString') - expect(userSync[1].type).to.be.equal('image'); - expect(userSync[2].url).to.be.equal('anyImageUrl2?gdpr=1&gdpr_consent=anyString') - expect(userSync[2].type).to.be.equal('image'); - }); - }); - - describe(`getUserSyncs test usage in passback response`, function() { - let serverResponses; - - beforeEach(function() { - serverResponses = [{ - body: { - reason: 8002, - status: 'error', - msg: 'passback', - } - }]; - }); - - it(`check for zero array when iframeEnabled`, function() { - expect(spec.getUserSyncs({ iframeEnabled: true })).to.be.an('array'); - expect(spec.getUserSyncs({ iframeEnabled: true }, serverResponses).length).to.be.equal(0); - }); - it(`check for zero array when iframeEnabled`, function() { - expect(spec.getUserSyncs({ pixelEnabled: true })).to.be.an('array'); - expect(spec.getUserSyncs({ pixelEnabled: true }, serverResponses).length).to.be.equal(0); - }); - }); -}); diff --git a/test/spec/modules/sublimeBidAdapter_spec.js b/test/spec/modules/sublimeBidAdapter_spec.js deleted file mode 100644 index a5657896f..000000000 --- a/test/spec/modules/sublimeBidAdapter_spec.js +++ /dev/null @@ -1,614 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/sublimeBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -const sinon = require('sinon'); - -const utils = require('src/utils'); - -const USER_AGENT = { - // UNKOWN - 'Opera/9.80 (S60; SymbOS; Opera Mobi/1209; U; sk) Presto/2.5.28 Version/10.1': { - type: 'desktop', os: { name: '', version: 0 }, browser: { name: '', version: 0 }, - }, - 'Opera/12.02 (Android 4.1; Linux; Opera Mobi/ADR-1111101157; U; en-US) Presto/2.9.201 Version/12.02': { - type: 'tablet', os: { name: 'android', version: 4.1 }, browser: { name: '', version: 0 }, - }, - - // MOBILES - // Android Mobile User Agents - 'Mozilla/5.0 (compatible; MSIE 9.0; Windows Phone OS 7.5; Trident/5.0; IEMobile/9.0)': { - type: 'mobile', os: { name: 'windowsPhone', version: 7.5 }, browser: { name: 'Internet Explorer', version: 9 }, - }, - 'Mozilla/5.0 (Linux; U; Android 2.3.5; en-us; HTC Vision Build/GRI40) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1': { - type: 'mobile', os: { name: 'android', version: 2.3 }, browser: { name: 'Safari', version: 4 }, - }, - 'Mozilla/5.0 (Linux; U; Android 4.0.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30': { - type: 'mobile', os: { name: 'android', version: 4 }, browser: { name: 'Safari', version: 4 }, - }, - 'Mozilla/5.0 (Linux; U; Android 4.4.3; ko-kr; LG-L160L Build/IML74K) AppleWebkit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30': { - type: 'mobile', os: { name: 'android', version: 4.4 }, browser: { name: 'Safari', version: 4 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 55 }, - }, - 'Mozilla/5.0 (Linux; Android 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 7 }, browser: { name: 'Chrome', version: 60 }, - }, - 'Mozilla/5.0 (Linux; Android 7.0; SM-G930VC Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/58.0.3029.83 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 7 }, browser: { name: 'Chrome', version: 58 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0.1; SM-G935S Build/MMB29K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 55 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0.1; SM-G920V Build/MMB29K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 52 }, - }, - 'Mozilla/5.0 (Linux; Android 5.1.1; SM-G928X Build/LMY47X) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.83 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 5.1 }, browser: { name: 'Chrome', version: 47 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0.1; Nexus 6P Build/MMB29P) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.83 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 47 }, - }, - 'Mozilla/5.0 (Linux; Android 7.1.1; G8231 Build/41.2.A.0.219; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/59.0.3071.125 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 7.1 }, browser: { name: 'Chrome', version: 59 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0.1; E6653 Build/32.2.A.0.253) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 52 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0; HTC One X10 Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/61.0.3163.98 Mobile Safari/537.36': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 61 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0; HTC One M9 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Mobile Safari/537.3': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 52 }, - }, - 'Mozilla/5.0 (Linux; U; 4.0.2; en-us; Galaxy Nexus Build/ICL53F) AppleWebKit/534.30 (KHTML like Gecko) Version/4.0 Mobile Safari/534.30': { - type: 'mobile', os: { name: '', version: 0 }, browser: { name: 'Safari', version: 4 }, - }, - // iPhone User Agents - 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1': { - type: 'mobile', os: { name: 'iOS', version: 11 }, browser: { name: 'Safari', version: 11 }, - }, - 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1': { - type: 'mobile', os: { name: 'iOS', version: 11 }, browser: { name: 'Safari', version: 11 }, - }, - 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A5370a Safari/604.1': { - type: 'mobile', os: { name: 'iOS', version: 11 }, browser: { name: 'Safari', version: 11 }, - }, - 'Mozilla/5.0 (iPhone9,3; U; CPU iPhone OS 10_0_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14A403 Safari/602.1': { - type: 'mobile', os: { name: 'iOS', version: 10 }, browser: { name: 'Safari', version: 10 }, - }, - 'Mozilla/5.0 (iPhone9,4; U; CPU iPhone OS 10_0_1 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/14A403 Safari/602.1': { - type: 'mobile', os: { name: 'iOS', version: 10 }, browser: { name: 'Safari', version: 10 }, - }, - 'Mozilla/5.0 (Apple-iPhone7C2/1202.466; U; CPU like Mac OS X; en) AppleWebKit/420+ (KHTML, like Gecko) Version/3.0 Mobile/1A543 Safari/419.3': { - type: 'mobile', os: { name: '', version: 0 }, browser: { name: 'Safari', version: 3 }, - }, - 'Mozilla/5.0 (Windows Phone 10.0; Android 6.0.1; Microsoft; RM-1152) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Mobile Safari/537.36 Edge/15.15254': { - type: 'mobile', os: { name: 'windowsPhone', version: 10 }, browser: { name: 'Edge', version: 15.15254 }, - }, - 'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; RM-1127_16056) AppleWebKit/537.36(KHTML, like Gecko) Chrome/42.0.2311.135 Mobile Safari/537.36 Edge/12.10536': { - type: 'mobile', os: { name: 'windowsPhone', version: 10 }, browser: { name: 'Edge', version: 12.10536 }, - }, - 'Mozilla/5.0 (Windows Phone 10.0; Android 4.2.1; Microsoft; Lumia 950) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Mobile Safari/537.36 Edge/13.1058': { - type: 'mobile', os: { name: 'windowsPhone', version: 10 }, browser: { name: 'Edge', version: 13.1058 }, - }, - 'Mozilla/5.0 (Linux; 7.0; SM-G892A Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/60.0.3112.107 Mobile Safari/537.36': { - type: 'mobile', os: { name: '', version: 0 }, browser: { name: 'Chrome', version: 60 }, - }, - 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.0 Mobile/15E148 Safari/604.1': { - type: 'mobile', os: { name: 'iOS', version: 11.3 }, browser: { name: 'Safari', version: 11 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0.1; SM-G903F Build/MMB29K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/44.0.2403.119 Mobile Safari/537.36 ACHEETAHI/1': { - type: 'mobile', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 44 }, - }, - - // TABLETS - 'Mozilla/5.0 (Linux; Android 5.0.2; SAMSUNG SM-T550 Build/LRX22G) AppleWebKit/537.36 (KHTML, like Gecko) SamsungBrowser/3.3 Chrome/38.0.2125.102 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 5 }, browser: { name: 'Chrome', version: 38 }, - }, - 'Mozilla/5.0 (Linux; Android 5.1.1; SHIELD Tablet Build/LMY48C) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.98 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 5.1 }, browser: { name: 'Chrome', version: 52 }, - }, - 'Mozilla/5.0 (Linux; Android 7.0; Pixel C Build/NRD90M; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/52.0.2743.98 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 7 }, browser: { name: 'Chrome', version: 52 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0.1; SGP771 Build/32.2.A.0.253; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/52.0.2743.98 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 52 }, - }, - 'Mozilla/5.0 (Linux; Android 6.0.1; SHIELD Tablet K1 Build/MRA58K; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/55.0.2883.91 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 6 }, browser: { name: 'Chrome', version: 55 }, - }, - 'Mozilla/5.0 (Linux; Android 7.0; SM-T827R4 Build/NRD90M) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.116 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 7 }, browser: { name: 'Chrome', version: 60 }, - }, - 'Mozilla/5.0 (Linux; Android 4.4.3; KFTHWI Build/KTU84M) AppleWebKit/537.36 (KHTML, like Gecko) Silk/47.1.79 like Chrome/47.0.2526.80 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 4.4 }, browser: { name: 'Chrome', version: 47 }, - }, - 'Mozilla/5.0 (Linux; Android 5.0.2; LG-V410/V41020c Build/LRX22G) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/34.0.1847.118 Safari/537.36': { - type: 'tablet', os: { name: 'android', version: 5 }, browser: { name: 'Chrome', version: 34 }, - }, - 'Mozilla/5.0 (iPad; CPU OS 9_3_2 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Version/9.0 Mobile/13F69 Safari/601.1': { - type: 'tablet', os: { name: 'iOS', version: 9.3 }, browser: { name: 'Safari', version: 9 }, - }, - 'Mozilla/5.0 (iPad; CPU OS 11_0_2 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A421 Safari/604.1': { - type: 'tablet', os: { name: 'iOS', version: 11 }, browser: { name: 'Safari', version: 11 }, - }, - 'Mozilla/5.0 (Android 7.0; Tablet; rv:62.0) Gecko/62.0 Firefox/62.0': { - type: 'tablet', os: { name: 'android', version: 7 }, browser: { name: 'Firefox', version: 62 }, - }, - - // DESKTOP - 'Mozilla/ 5.0(Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari / 537.36': { - type: 'desktop', os: { name: 'Windows', version: 6.1 }, browser: { name: 'Chrome', version: 41 }, - }, - 'Mozilla/5.0 (hone; CPU one OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1': { - type: 'desktop', os: { name: '', version: 0 }, browser: { name: 'Safari', version: 11 }, - }, - 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246': { - type: 'desktop', os: { name: 'Windows', version: 10 }, browser: { name: 'Edge', version: 12.246 }, - }, - 'Mozilla/5.0 (X11; CrOS x86_64 8172.45.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.64 Safari/537.36': { - type: 'desktop', os: { name: '', version: 0 }, browser: { name: 'Chrome', version: 51 }, - }, - 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/601.3.9 (KHTML, like Gecko) Version/9.0.2 Safari/601.3.9': { - type: 'desktop', os: { name: 'Mac', version: 10.11 }, browser: { name: 'Safari', version: 9 }, - }, - 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36': { - type: 'desktop', os: { name: 'Windows', version: 6.1 }, browser: { name: 'Chrome', version: 47 }, - }, -}; - -describe('Sublime Adapter', function () { - describe('detectDevice', function () { - it('should correctly detect device', function () { - const uaStub = sinon.stub(window.navigator, 'userAgent'); - - Object.keys(USER_AGENT).forEach(userAgent => { - const value = USER_AGENT[userAgent]; - uaStub.value(userAgent); - expect(spec.detectDevice()).to.equal(value.type.charAt(0)); - }); - - uaStub.restore(); - }) - }); - - describe('sendEvent', function () { - let sandbox; - const triggeredPixelProperties = [ - 't', - 'tse', - 'z', - 'e', - 'src', - 'puid', - 'notid', - 'pbav', - 'pubpbv', - 'device', - 'pubtimeout', - ]; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - - it('should trigger pixel', function () { - sandbox.spy(utils, 'triggerPixel'); - spec.sendEvent('test'); - expect(utils.triggerPixel.called).to.equal(true); - const params = utils.parseUrl(utils.triggerPixel.args[0][0]).search; - expect(Object.keys(params)).to.have.members(triggeredPixelProperties); - }); - - afterEach(function () { - sandbox.restore(); - }); - }) - - describe('inherited functions', function () { - it('exists and is a function', function () { - const adapter = newBidder(spec); - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - let bid; - beforeEach(function () { - bid = { - bidder: 'sublime', - params: { - zoneId: 24549, - endpoint: '', - }, - }; - }) - - afterEach(function () { - delete window.sublime; - }) - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when a valid notifyId is provided', function () { - bid.params.notifyId = 'f1514724-0922-4b45-a297-27531aeb829a'; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when an invalid notifyId is provided', function () { - bid.params.notifyId = 'some_invalid_notify_id'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when required params are not passed', function () { - bid.params = {}; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when the notifyId does not match sublime one', function () { - bid.params.notifyId = 'f1514724-0922-4b45-a297-27531aeb829a'; - window.sublime = { notifyId: '5c444a48-7713-4333-a895-44b1ae793417' }; - expect(spec.isBidRequestValid(bid)).to.equal(false); // FIX THIS - delete window.sublime; - }); - }); - - describe('getNotifyId', function () { - afterEach(function () { - delete window.sublime; - }); - - it('generates a notifyId (not in params, not in sublime)', function () { - const params = Object.freeze({}); - window.sublime = {}; - const notifyId = spec.getNotifyId(params); - expect(spec.isValidNotifyId(notifyId)).to.be.true; - expect(window.sublime.notifyId).to.equal(notifyId); - }); - - it('uses sublime notifyId (not in params, present in sublime)', function () { - const params = Object.freeze({}); - window.sublime = { notifyId: '5c444a48-7713-4333-a895-44b1ae793417' }; - const notifyId = spec.getNotifyId(params); - expect(notifyId).to.equal('5c444a48-7713-4333-a895-44b1ae793417'); - expect(window.sublime.notifyId).to.equal('5c444a48-7713-4333-a895-44b1ae793417'); - }); - - it('assigns notifyId from params to sublime (present in params, not in sublime)', function () { - const params = Object.freeze({ notifyId: 'f1514724-0922-4b45-a297-27531aeb829a' }); - window.sublime = {}; - const notifyId = spec.getNotifyId(params); - expect(notifyId).to.equal('f1514724-0922-4b45-a297-27531aeb829a'); - expect(window.sublime.notifyId).to.equal('f1514724-0922-4b45-a297-27531aeb829a'); - }); - - it('returns notifyId from params (same in params & in sublime)', function () { - const params = Object.freeze({ notifyId: 'f1514724-0922-4b45-a297-27531aeb829a' }); - window.sublime = { notifyId: 'f1514724-0922-4b45-a297-27531aeb829a' }; - const notifyId = spec.getNotifyId(params); - expect(notifyId).to.equal('f1514724-0922-4b45-a297-27531aeb829a'); - expect(window.sublime.notifyId).to.equal('f1514724-0922-4b45-a297-27531aeb829a'); - }); - - it('returns notifyId from params (present in params & in sublime, with mismatch)', function () { - const params = Object.freeze({ notifyId: 'f1514724-0922-4b45-a297-27531aeb829a' }); - window.sublime = { notifyId: '5c444a48-7713-4333-a895-44b1ae793417' }; - const notifyId = spec.getNotifyId(params); - expect(notifyId).to.equal('f1514724-0922-4b45-a297-27531aeb829a'); - expect(window.sublime.notifyId).to.equal('5c444a48-7713-4333-a895-44b1ae793417'); // did not change - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - bidder: 'sublime', - adUnitCode: 'sublime_code', - bidId: 'abc1234', - sizes: [[1800, 1000], [640, 300]], - requestId: 'xyz654', - params: { - zoneId: 123, - callbackName: 'false', - notifyId: 'ea252d4f-93d9-4c2f-8cca-88cec3a0a347' - } - }, { - bidder: 'sublime', - adUnitCode: 'sublime_code_2', - bidId: 'abc1234_2', - sizes: [[1, 1]], - requestId: 'xyz654_2', - params: { - zoneId: 456, - } - } - ]; - - const bidderRequest = { - gdprConsent: { - consentString: 'EOHEIRCOUCOUIEHZIOEIU-TEST', - gdprApplies: true - }, - refererInfo: { - referer: 'https://example.com', - numIframes: 2, - } - }; - - it('should have a post method', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].method).to.equal('POST'); - expect(request[1].method).to.equal('POST'); - }); - - it('should contains a request id equals to the bid id', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - for (let i = 0; i < request.length; i = i + 1) { - expect(JSON.parse(request[i].data).requestId).to.equal(bidRequests[i].bidId); - } - }); - - it('should have an url that contains bid keyword', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].url).to.match(/bid/); - expect(request[1].url).to.match(/bid/); - }); - - it('should contains a request notifyId', function () { - const request = spec.buildRequests(bidRequests, bidderRequest); - for (let i = 0; i < request.length; i = i + 1) { - const { notifyId } = JSON.parse(request[i].data); - expect(spec.isValidNotifyId(notifyId)).to.be.true; - } - }); - }); - - describe('buildRequests: default arguments', function () { - const bidRequests = [{ - bidder: 'sublime', - adUnitCode: 'sublime_code', - bidId: 'abc1234', - sizes: [[1800, 1000], [640, 300]], - requestId: 'xyz654', - params: { - zoneId: 123 - } - }]; - - it('should have an url that match the default endpoint', function () { - const request = spec.buildRequests(bidRequests); - expect(request[0].url).to.equal('https://pbjs.sskzlabs.com/bid'); - }); - }); - - describe('interpretResponse', function () { - const serverResponse = { - 'request_id': '3db3773286ee59', - 'sspname': 'foo', - 'cpm': 0.5, - 'ad': '', - }; - - it('should get correct bid response', function () { - // Mock the fire method - top.window.sublime = { - analytics: { - fire: function () { } - } - }; - - const expectedResponse = [ - { - requestId: '', - cpm: 0.5, - width: 1800, - height: 1000, - creativeId: 1, - dealId: 1, - currency: 'USD', - sspname: 'foo', - netRevenue: true, - ttl: 600, - pbav: '0.8.0', - ad: '', - }, - ]; - const result = spec.interpretResponse({ body: serverResponse }); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - }); - - it('should get correct default size for 1x1', function () { - const serverResponse = { - 'requestId': 'xyz654_2', - 'sspname': 'sublime', - 'cpm': 0.5, - 'ad': '', - }; - - const bidRequest = { - bidder: 'sublime', - adUnitCode: 'sublime_code_2', - bidId: 'abc1234_2', - data: { - w: 1, - h: 1, - }, - requestId: 'xyz654_2', - params: { - zoneId: 456, - } - }; - - const result = spec.interpretResponse({ body: serverResponse }, bidRequest); - - const expectedResponse = { - requestId: 'xyz654_2', - cpm: 0.5, - width: 1, - height: 1, - creativeId: 1, - dealId: 1, - currency: 'EUR', - netRevenue: true, - ttl: 600, - ad: '', - pbav: '0.8.0', - sspname: 'sublime' - }; - - expect(result[0]).to.deep.equal(expectedResponse); - }); - - it('should return bid empty response', function () { - const serverResponse = ''; - const bidRequest = {}; - - const result = spec.interpretResponse({ body: serverResponse }, bidRequest); - - const expectedResponse = []; - - expect(result).to.deep.equal(expectedResponse); - }); - - it('should return bid with default value in response', function () { - const serverResponse = { - 'requestId': 'xyz654_2', - 'sspname': 'sublime', - 'ad': '', - }; - - const bidRequest = { - bidder: 'sublime', - adUnitCode: 'sublime_code_2', - bidId: 'abc1234_2', - data: { - w: 1, - h: 1, - }, - requestId: 'xyz654_2', - params: { - zoneId: 456, - } - }; - - const result = spec.interpretResponse({ body: serverResponse }, bidRequest); - - const expectedResponse = { - requestId: 'xyz654_2', - cpm: 0, - width: 1, - height: 1, - creativeId: 1, - dealId: 1, - currency: 'EUR', - sspname: 'sublime', - netRevenue: true, - ttl: 600, - ad: '', - pbav: '0.8.0', - }; - - expect(result[0]).to.deep.equal(expectedResponse); - }); - - it('should return empty bid response because of timeout', function () { - const serverResponse = { - 'requestId': 'xyz654_2', - 'timeout': true, - 'ad': '', - }; - - const bidRequest = { - bidder: 'sublime', - adUnitCode: 'sublime_code_2', - bidId: 'abc1234_2', - data: { - w: 1, - h: 1, - }, - requestId: 'xyz654_2', - params: { - zoneId: 456, - } - }; - - const result = spec.interpretResponse({ body: serverResponse }, bidRequest); - - const expectedResponse = []; - - expect(result).to.deep.equal(expectedResponse); - - describe('On bid Time out', function () { - spec.onTimeout(result); - }); - }); - - it('should add advertiserDomains', function () { - const responseWithAdvertiserDomains = utils.deepClone(serverResponse); - responseWithAdvertiserDomains.advertiserDomains = ['a_sublime_adomain']; - - const bidRequest = { - bidder: 'sublime', - params: { - zoneId: 456, - } - }; - - const result = spec.interpretResponse({ body: responseWithAdvertiserDomains }, bidRequest); - - expect(Object.keys(result[0].meta)).to.include.members(['advertiserDomains']); - expect(Object.keys(result[0].meta.advertiserDomains)).to.deep.equal([]); - }); - }); - - describe('onBidWon', function () { - let sandbox; - const bid = { foo: 'bar' }; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - - it('should trigger "bidwon" pixel', function () { - sandbox.spy(utils, 'triggerPixel'); - spec.onBidWon(bid); - const params = utils.parseUrl(utils.triggerPixel.args[0][0]).search; - expect(params.e).to.equal('bidwon'); - }); - - afterEach(function () { - sandbox.restore(); - }); - }); - - describe('onTimeout', function () { - let sandbox; - // Array of bids that timed out - const timeoutData = [{ - timeout: 1234 - }]; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - }); - - it('should trigger "bidtimeout" pixel', function () { - sandbox.spy(utils, 'triggerPixel'); - spec.onTimeout(timeoutData); - const params = utils.parseUrl(utils.triggerPixel.args[0][0]).search; - expect(params.e).to.equal('bidtimeout'); - }); - - it('should set timeout value in state', function () { - spec.onTimeout(timeoutData); - expect(spec.state).to.deep.include({ timeout: 1234 }); - }); - - afterEach(function () { - sandbox.restore(); - }); - }) -}); diff --git a/test/spec/modules/suimBidAdapter_spec.js b/test/spec/modules/suimBidAdapter_spec.js deleted file mode 100644 index e06e5875d..000000000 --- a/test/spec/modules/suimBidAdapter_spec.js +++ /dev/null @@ -1,154 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/suimBidAdapter.js'; - -const ENDPOINT = 'https://bid.suimad.com/api/v1/prebids'; -const SYNC_URL = 'https://bid.suimad.com/api/v1/logs/usersync'; - -describe('SuimAdapter', function () { - describe('isBidRequestValid', function () { - it('should return true when bid contains all required params', function () { - const bid = { - bidder: 'suim', - params: { - ad_space_id: '123456', - }, - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = { - bidder: 'suim', - params: {}, - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - bidder: 'suim', - params: { - ad_space_id: '123456', - }, - adUnitCode: 'adunit-code', - sizes: [ - [1, 1], - [320, 50], - [970, 250], - [300, 250], - [728, 90], - [300, 600], - [320, 100], - ], - bidId: '22a91eced2e93a', - bidderRequestId: '20098c23bb863c', - auctionId: '1c0ceb30-c9c9-4988-b9ff-2724cf91e7db', - }, - ]; - - const bidderRequest = { - refererInfo: { - topmostLocation: 'https://example.com', - }, - }; - - it('sends bid request to ENDPOINT via POST', function () { - const requests = spec.buildRequests(bidRequests, bidderRequest); - expect(requests[0].url).to.equal(ENDPOINT); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].data).to.deep.equal({ - bids: [ - { - bidId: '22a91eced2e93a', - ad_space_id: '123456', - sizes: [ - [1, 1], - [320, 50], - [970, 250], - [300, 250], - [728, 90], - [300, 600], - [320, 100], - ], - src_url: 'https://example.com', - } - ] - }); - }); - }); - - describe('interpretResponse', function () { - const bidResponse = { - bidId: '22a91eced2e93a', - cpm: 300, - currency: 'JPY', - width: 300, - height: 250, - ad: '

I am an ad

', - ttl: 300, - creativeId: '123456', - netRevenue: true, - meta: { - advertiserDomains: [], - }, - }; - const bidderRequests = { - bids: [{ - bidId: '22a91eced2e93a', - ad_space_id: '123456', - sizes: [ - [1, 1], - [320, 50], - [970, 250], - [300, 250], - [728, 90], - [300, 600], - [320, 100], - ], - src_url: 'https://example.com', - }] - } - - it('should interpret response', function () { - const result = spec.interpretResponse({ body: bidResponse }, bidderRequests); - expect(result).to.have.lengthOf(1); - expect(result[0]).to.deep.equal({ - requestId: bidResponse.bid, - cpm: 300, - currency: 'JPY', - width: 300, - height: 250, - ad: '

I am an ad

', - ttl: 300, - creativeId: '123456', - netRevenue: true, - meta: { - advertiserDomains: [], - }, - }); - }); - - it('should return empty array when response is empty', function () { - const response = []; - const result = spec.interpretResponse({ body: response }, bidderRequests); - expect(result.length).to.equal(0); - }); - }); - - describe('getUserSyncs', function () { - it('should return user syncs', function () { - const syncs = spec.getUserSyncs( - { pixelEnabled: true, iframeEnabled: true }, - {} - ); - expect(syncs).to.deep.equal([ - { - type: 'image', - url: SYNC_URL, - }, - ]); - }); - }); -}); diff --git a/test/spec/modules/symitriAnalyticsAdapter_spec.js b/test/spec/modules/symitriAnalyticsAdapter_spec.js deleted file mode 100644 index d52ae2e88..000000000 --- a/test/spec/modules/symitriAnalyticsAdapter_spec.js +++ /dev/null @@ -1,90 +0,0 @@ -import symitriAnalyticsAdapter from 'modules/symitriAnalyticsAdapter.js'; -import { expect } from 'chai'; -import adapterManager from 'src/adapterManager.js'; -import { server } from 'test/mocks/xhr.js'; -import { EVENTS } from 'src/constants.js'; - -const events = require('src/events'); - -describe('symitri analytics adapter', function () { - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - }); - - afterEach(function () { - events.getEvents.restore(); - }); - - describe('track', function () { - const initOptionsValid = { - apiAuthToken: 'TOKEN1234' - }; - const initOptionsInValid = { - }; - - const bidWon = { - 'bidderCode': 'appnexus', - 'width': 300, - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '393976d8770041', - 'requestId': '263efc09896d0c', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 0.5, - 'creativeId': 96846035, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'originalCpm': 0.5, - 'originalCurrency': 'USD', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'responseTimestamp': 1576823894050, - 'requestTimestamp': 1576823893838, - 'bidder': 'appnexus', - 'timeToRespond': 212, - 'status': 'rendered' - }; - - adapterManager.registerAnalyticsAdapter({ - code: 'symitri', - adapter: symitriAnalyticsAdapter - }); - - afterEach(function () { - symitriAnalyticsAdapter.disableAnalytics(); - }); - - it('Test with valid apiAuthToken', function () { - adapterManager.enableAnalytics({ - provider: 'symitri', - options: initOptionsValid - }); - events.emit(EVENTS.BID_WON, bidWon); - expect(server.requests.length).to.equal(1); - }); - - it('Test with missing apiAuthToken', function () { - adapterManager.enableAnalytics({ - provider: 'symitri', - options: initOptionsInValid - }); - events.emit(EVENTS.BID_WON, bidWon); - expect(server.requests.length).to.equal(0); - }); - - it('Test correct winning bid is sent to server', function () { - adapterManager.enableAnalytics({ - provider: 'symitri', - options: initOptionsValid - }); - events.emit(EVENTS.BID_WON, bidWon); - expect(server.requests.length).to.equal(1); - const winEventData = JSON.parse(server.requests[0].requestBody); - expect(winEventData).to.deep.equal(bidWon); - const authToken = server.requests[0].requestHeaders['Authorization']; - expect(authToken).to.equal(initOptionsValid.apiAuthToken); - }); - }); -}); diff --git a/test/spec/modules/symitriDapRtdProvider_spec.js b/test/spec/modules/symitriDapRtdProvider_spec.js deleted file mode 100644 index f3deb8406..000000000 --- a/test/spec/modules/symitriDapRtdProvider_spec.js +++ /dev/null @@ -1,708 +0,0 @@ -import {config} from 'src/config.js'; -import { - dapUtils, - generateRealTimeData, - symitriDapRtdSubmodule, - onBidWonListener, - storage, DAP_MAX_RETRY_TOKENIZE, DAP_SS_ID, DAP_TOKEN, DAP_MEMBERSHIP, DAP_ENCRYPTED_MEMBERSHIP -} from 'modules/symitriDapRtdProvider.js'; -import {server} from 'test/mocks/xhr.js'; -import {hook} from '../../../src/hook.js'; -import { EVENTS } from 'src/constants.js'; -const responseHeader = {'Content-Type': 'application/json'}; - -const events = require('src/events'); - -describe('symitriDapRtdProvider', function() { - const testReqBidsConfigObj = { - adUnits: [ - { - bids: ['bid1', 'bid2'] - } - ] - }; - - const onDone = function() { return true }; - - const sampleGdprConsentConfig = { - 'gdpr': { - 'consentString': null, - 'vendorData': {}, - 'gdprApplies': true - } - }; - - const sampleUspConsentConfig = { - 'usp': '1YYY' - }; - - const sampleIdentity = { - type: 'dap-signature:1.0.0' - }; - - const cmoduleConfig = { - 'name': 'symitriDap', - 'waitForIt': true, - 'params': { - 'apiHostname': 'prebid.dap.akadns.net', - 'apiVersion': 'x1', - 'apiAuthToken': 'Token 1234', - 'domain': 'prebid.org', - 'identityType': 'dap-signature:1.0.0', - 'segtax': 708 - } - } - - const emoduleConfig = { - 'name': 'symitriDap', - 'waitForIt': true, - 'params': { - 'apiHostname': 'prebid.dap.akadns.net', - 'apiVersion': 'x1', - 'domain': 'prebid.org', - 'identityType': 'dap-signature:1.0.0', - 'segtax': 710, - 'pixelUrl': 'https://www.test.com/pixel' - } - } - - const sampleConfig = { - 'api_hostname': 'prebid.dap.akadns.net', - 'api_version': 'x1', - 'domain': 'prebid.org', - 'segtax': 708, - 'identity': sampleIdentity - } - - const sampleX2Config = { - 'api_hostname': 'prebid.dap.akadns.net', - 'api_version': 'x2', - 'domain': 'prebid.org', - 'segtax': 708, - 'identity': sampleIdentity - } - - const esampleConfig = { - 'api_hostname': 'prebid.dap.akadns.net', - 'api_version': 'x1', - 'domain': 'prebid.org', - 'segtax': 710, - 'identity': sampleIdentity - } - const cacheExpiry = Math.round(Date.now() / 1000.0) + 300; // in seconds - const sampleCachedToken = {'expires_at': cacheExpiry, 'token': 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoicGFzc3dvcmQxIn0..6buzBd2BjtgoyaNbHN8YnQ.l38avCfm3sYNy798-ETYOugz0cOx1cCkjACkAhYszxzrZ0sUJ0AiF-NdDXVTiTyp2Ih3vCWKzS0rKJ8lbS1zhyEVWVu91QwtwseM2fBbwA5ggAgBEo5wV-IXqDLPxVnxsPF0D3hP6cNCiH9Q2c-vULfsLhMhG5zvvZDPBbn4hUY5fKB8LoCBTF9rbuuWGYK1nramnb4AlS5UK82wBsHQea1Ou_Kp5wWCMNZ6TZk5qKIuRBfPIAhQblWvHECaHXkg1wyoM9VASs_yNhne7RR-qkwzbFiPFiMJibNOt9hF3_vPDJO5-06ZBjRTP1BllYGWxI-uQX6InzN18Wtun2WHqg.63sH0SNlIRcsK57v0pMujfB_nhU8Y5CuQbsHqH5MGoM'}; - const cachedEncryptedMembership = {'expires_at': cacheExpiry, 'encryptedSegments': 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoic29tZXNlY3JldGludmF1bHQifQ..IvnIUQDqWBVYIS0gbcE9bw.Z4NZGvtogWaWlGH4e-GdYKe_PUc15M2x3Bj85rMWsN1A17mIxQIMOfg2hsQ2tgieLu5LggWPmsFu1Wbph6P0k3kOu1dVReoIhOHzxw50rP0DLHKaEZ5mLMJ7Lcosvwh4miIfFuCHlsX7J0sFgOTAp0zGo1S_UsHLtev1JflhjoSB0AoX95ALbAnyctirPuLJM8gZ1vXTiZ01jpvucGyR1lM4cWjPOeD8jPtgwaPGgSRZXE-3X2Cqy7z4Giam5Uqu74LPWTBuKtUQTGyAXA5QJoP7xwTbsU4O1f69lu3fWNqC92GijeTH1A4Zd_C-WXxWuQlDEURjlkWQoaqTHka2OqlnwukEQIf_v0r5KQQX64CTLhEUH91jeD0-E9ClcIP7pwOLxxqiKoaBmx8Mrnm_6Agj5DtTA1rusy3AL63sI_rsUxrmLrVt0Wft4aCfRkW8QpQxu8clFdOmce0NNCGeBCyCPVw9d9izrILlXJ6rItU2cpFrcbz8uw2otamF5eOFCOY3IzHedWVNNuKHFIUVC_xYSlsYvQ8f2QIP1eiMbmukcuPzmTzjw1h1_7IKaj-jJkXrnrY-TdDgX_4-_Z3rmbpXK2yTR7dBrsg-ubqFbgbKic1b4zlQEO_LbBlgPl3DYdWEuJ8CY2NUt1GfpATQGsufS2FTY1YGw_gkPe3q04l_cgLafDoxHvHh_t_0ZgPjciW82gThB_kN4RP7Mc3krVcXl_P6N1VbV07xyx0hCyVsrrxbLslI8q9wYDiLGci7mNmByM5j7SXV9jPwwPkHtn0HfMJlw2PFbIDPjgG3h7sOyLcBIJTTvuUIgpHPIkRWLIl_4FlIucXbJ7orW2nt5BWleBVHgumzGcnl9ZNcZb3W-dsdYPSOmuj0CY28MRTP2oJ1rzLInbDDpIRffJBtR7SS4nYyy7Vi09PtBigod5YNz1Q0WDSJxr8zeH_aKFaXInw7Bfo_U0IAcLiRgcT0ogsMLeQRjRFy27mr4XNJv3NtHhbdjDAwF2aClCktXyXbQaVdsPH2W71v6m2Q9rB5GQWOktw2s5f-4N1-_EBPGq6TgjF-aJZP22MJVwp1pimT50DfOzoeEqDwi862NNwNNoHmcObH0ZfwAXlhRxsgupNBe20-MNNABj2Phlfv4DUrtQbMdfCnNiypzNCmoTb7G7c_o5_JUwoV_GVkwUtvmi_IUm05P4GeMASSUw8zDKVRAj9h31C2cabM8RjMHGhkbCWpUP2pcz9zlJ7Y76Dh3RLnctfTw7DG9U4w4UlaxNZOgLUiSrGwfyapuSiuGUpuOJkBBLiHmEqAGI5C8oJpcVRccNlHxJAYowgXyFopD5Fr-FkXmv8KMkS0h5C9F6KihmDt5sqDD0qnjM0hHJgq01l7wjVnhEmPpyD-6auFQ-xDnbh1uBOJ_0gCVbRad--FSa5p-dXenggegRxOvZXJ0iAtM6Fal5Og-RCjexIHa9WhVbXhQBJpkSTWwAajZJ64eQ.yih49XB51wE-Xob7COT9OYqBrzBmIMVCQbLFx2UdzkI'}; - const cachedMembership = {'expires_at': cacheExpiry, 'said': 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoicGFzc3dvcmQxIn0..QwvU5h0NVJYaJbs5EqWCKA.XNaJHSlnsH8P-yBIr3gIEqavLONWDIFyj7QCHFwJVkwXH_EYkxrk0_26b0uMPzfJp5URnqxKZusMH9DzEJsmj8EMrKQv1y3IYYMsW5_0BdP5bcAWfG6fzOqtMOwLiYRkYiQOqn1ZVGzhovheHWEmNr2_oCY0LvAr3iN1eG_K-l-bBKvBWnwvuuGKquUfCqO8NMMq6wtkecEXM9blqFRZ7oNYmW2aIG7qcHUsrUW7HMr9Ev2Ik0sIeEUsOYrgf_X_VA64RgKSTRugS9FupMv1p54JkHokwduF9pOFmW8QLQi8itFogKGbbgvOTNnmahxQUX5FcrjjYLqHwKqC8htLdlHnO5LWU9l4A7vLXrRurvoSnh0cAJy0GsdoyEwTqR9bwVFHoPquxlJjQ4buEd7PIxpBj9Qg9oOPH3b2upbMTu5CQ9oj526eXPhP5G54nwGklm2AZ3Vggd7jCQJn45Jjiq0iIfsXAtpqS2BssCLBN8WhmUTnStK8m5sux6WUBdrpDESQjPj-EEHVS-DB5rA7icRUh6EzRxzen2rndvHvnwVhSG_l6cwPYuJ0HE0KBmYHOoqNpKwzoGiKFHrf4ReA06iWB3V2TEGJucGujhtQ9_18WwHCeJ1XtQiiO1eqa3tp5MwAbFXawVFl3FFOBgadrPyvGmkmUJ6FCLU2MSwHiYZmANMnJsokFX_6DwoAgO3U_QnvEHIVSvefc7ReeJ8fBDdmrH3LtuLrUpXsvLvEIMQdWQ_SXhjKIi7tOODR8CfrhUcdIjsp3PZs1DpuOcDB6YJKbGnKZTluLUJi3TyHgyi-DHXdTm-jSE5i_DYJGW-t2Gf23FoQhexv4q7gdrfsKfcRJNrZLp6Gd6jl4zHhUtY.nprKBsy9taQBk6dCPbA7BFF0CiGhQOEF_MazZ2bedqk', 'cohorts': ['9', '11', '13']}; - const cachedMembershipWithDeals = {'expires_at': cacheExpiry, 'said': 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoicGFzc3dvcmQxIn0..QwvU5h0NVJYaJbs5EqWCKA.XNaJHSlnsH8P-yBIr3gIEqavLONWDIFyj7QCHFwJVkwXH_EYkxrk0_26b0uMPzfJp5URnqxKZusMH9DzEJsmj8EMrKQv1y3IYYMsW5_0BdP5bcAWfG6fzOqtMOwLiYRkYiQOqn1ZVGzhovheHWEmNr2_oCY0LvAr3iN1eG_K-l-bBKvBWnwvuuGKquUfCqO8NMMq6wtkecEXM9blqFRZ7oNYmW2aIG7qcHUsrUW7HMr9Ev2Ik0sIeEUsOYrgf_X_VA64RgKSTRugS9FupMv1p54JkHokwduF9pOFmW8QLQi8itFogKGbbgvOTNnmahxQUX5FcrjjYLqHwKqC8htLdlHnO5LWU9l4A7vLXrRurvoSnh0cAJy0GsdoyEwTqR9bwVFHoPquxlJjQ4buEd7PIxpBj9Qg9oOPH3b2upbMTu5CQ9oj526eXPhP5G54nwGklm2AZ3Vggd7jCQJn45Jjiq0iIfsXAtpqS2BssCLBN8WhmUTnStK8m5sux6WUBdrpDESQjPj-EEHVS-DB5rA7icRUh6EzRxzen2rndvHvnwVhSG_l6cwPYuJ0HE0KBmYHOoqNpKwzoGiKFHrf4ReA06iWB3V2TEGJucGujhtQ9_18WwHCeJ1XtQiiO1eqa3tp5MwAbFXawVFl3FFOBgadrPyvGmkmUJ6FCLU2MSwHiYZmANMnJsokFX_6DwoAgO3U_QnvEHIVSvefc7ReeJ8fBDdmrH3LtuLrUpXsvLvEIMQdWQ_SXhjKIi7tOODR8CfrhUcdIjsp3PZs1DpuOcDB6YJKbGnKZTluLUJi3TyHgyi-DHXdTm-jSE5i_DYJGW-t2Gf23FoQhexv4q7gdrfsKfcRJNrZLp6Gd6jl4zHhUtY.nprKBsy9taQBk6dCPbA7BFF0CiGhQOEF_MazZ2bedqk', 'cohorts': ['9', '11', '13'], 'deals': ['{"id":"DEMODEAL555","bidfloor":5.0,"at":1,"guar":0}', '{"id":"DEMODEAL111","bidfloor":5.0,"at":1,"guar":0}', '{"id":"DEMODEAL123","bidfloor":5.0,"at":1,"guar":0}']}; - const rtdUserObj = { - name: 'www.dataprovider3.com', - ext: { - taxonomyname: 'iab_audience_taxonomy' - }, - segment: [ - { - id: '1918' - }, - { - id: '1939' - } - ] - }; - - const encRtdUserObj = { - name: 'www.dataprovider3.com', - ext: { - segtax: 710, - taxonomyname: 'iab_audience_taxonomy' - }, - segment: [] - }; - - const cachedRtd = { - rtd: { - ortb2: { - user: { - data: [rtdUserObj] - } - } - } - }; - - const membership = { - said: cachedMembership.said, - cohorts: cachedMembership.cohorts, - attributes: null - }; - const encMembership = { - encryptedSegments: cachedEncryptedMembership.encryptedSegments - }; - encRtdUserObj.segment.push({ id: encMembership.encryptedSegments }); - const cachedEncRtd = { - rtd: { - ortb2: { - user: { - data: [encRtdUserObj] - } - } - } - }; - - before(() => { - hook.ready(); - }); - - let ortb2, bidConfig; - - beforeEach(function() { - bidConfig = {ortb2Fragments: {}}; - ortb2 = bidConfig.ortb2Fragments.global = {}; - config.resetConfig(); - storage.removeDataFromLocalStorage(DAP_TOKEN); - storage.removeDataFromLocalStorage(DAP_MEMBERSHIP); - storage.removeDataFromLocalStorage(DAP_ENCRYPTED_MEMBERSHIP); - storage.removeDataFromLocalStorage(DAP_SS_ID); - }); - - afterEach(function () { - }); - - describe('symitriDapRtdSubmodule', function() { - it('successfully instantiates', function () { - expect(symitriDapRtdSubmodule.init()).to.equal(true); - }); - }); - - describe('Get Real-Time Data', function() { - it('gets rtd from local storage cache', function() { - const dapGetMembershipFromLocalStorageStub = sinon.stub(dapUtils, 'dapGetMembershipFromLocalStorage').returns(membership) - const dapGetRtdObjStub = sinon.stub(dapUtils, 'dapGetRtdObj').returns(cachedRtd) - const dapGetEncryptedMembershipFromLocalStorageStub = sinon.stub(dapUtils, 'dapGetEncryptedMembershipFromLocalStorage').returns(encMembership) - const dapGetEncryptedRtdObjStub = sinon.stub(dapUtils, 'dapGetEncryptedRtdObj').returns(cachedEncRtd) - const callDapApisStub = sinon.stub(dapUtils, 'callDapAPIs') - try { - storage.setDataInLocalStorage(DAP_TOKEN, JSON.stringify(sampleCachedToken)); - expect(ortb2).to.eql({}); - generateRealTimeData(bidConfig, () => {}, emoduleConfig, {}); - - expect(ortb2.user.data).to.deep.include.members([encRtdUserObj]); - generateRealTimeData(bidConfig, () => {}, cmoduleConfig, {}); - expect(ortb2.user.data).to.deep.include.members([rtdUserObj]); - } finally { - dapGetRtdObjStub.restore() - dapGetMembershipFromLocalStorageStub.restore() - dapGetEncryptedRtdObjStub.restore() - dapGetEncryptedMembershipFromLocalStorageStub.restore() - callDapApisStub.restore() - } - }); - }); - - describe('calling DAP APIs', function() { - it('Calls callDapAPIs for unencrypted segments flow', function() { - storage.setDataInLocalStorage(DAP_TOKEN, JSON.stringify(sampleCachedToken)); - const dapExtractExpiryFromTokenStub = sinon.stub(dapUtils, 'dapExtractExpiryFromToken').returns(cacheExpiry) - try { - expect(ortb2).to.eql({}); - dapUtils.callDapAPIs(bidConfig, () => {}, cmoduleConfig, {}); - const membership = {'cohorts': ['9', '11', '13'], 'said': 'sample-said'} - const membershipRequest = server.requests[0]; - membershipRequest.respond(200, responseHeader, JSON.stringify(membership)); - const tokenWithExpiry = 'Sample-token-with-exp' - const tokenizeRequest = server.requests[1]; - tokenizeRequest.requestHeaders['Content-Type'].should.equal('application/json'); - responseHeader['Symitri-DAP-Token'] = tokenWithExpiry; - tokenizeRequest.respond(200, responseHeader, JSON.stringify(tokenWithExpiry)); - const data = dapUtils.dapGetRtdObj(membership, cmoduleConfig.params.segtax); - expect(ortb2.user.data).to.deep.include.members(data.rtd.ortb2.user.data); - } finally { - dapExtractExpiryFromTokenStub.restore(); - } - }); - - it('Calls callDapAPIs for encrypted segments flow', function() { - storage.setDataInLocalStorage(DAP_TOKEN, JSON.stringify(sampleCachedToken)); - const dapExtractExpiryFromTokenStub = sinon.stub(dapUtils, 'dapExtractExpiryFromToken').returns(cacheExpiry) - try { - expect(ortb2).to.eql({}); - dapUtils.callDapAPIs(bidConfig, () => {}, emoduleConfig, {}); - const encMembership = 'Sample-enc-token'; - const membershipRequest = server.requests[0]; - responseHeader['Symitri-DAP-Token'] = encMembership; - membershipRequest.respond(200, responseHeader, JSON.stringify(encMembership)); - const tokenWithExpiry = 'Sample-token-with-exp' - const tokenizeRequest = server.requests[1]; - tokenizeRequest.requestHeaders['Content-Type'].should.equal('application/json'); - responseHeader['Symitri-DAP-Token'] = tokenWithExpiry; - tokenizeRequest.respond(200, responseHeader, JSON.stringify(tokenWithExpiry)); - const data = dapUtils.dapGetEncryptedRtdObj({'encryptedSegments': encMembership}, emoduleConfig.params.segtax); - expect(ortb2.user.data).to.deep.include.members(data.rtd.ortb2.user.data); - } finally { - dapExtractExpiryFromTokenStub.restore(); - } - }); - }); - - describe('dapTokenize', function () { - it('dapTokenize error callback', function () { - const configAsync = JSON.parse(JSON.stringify(sampleConfig)); - const submoduleCallback = dapUtils.dapTokenize(configAsync, sampleIdentity, onDone, - function(token, status, xhr, onDone) { - }, - function(xhr, status, error, onDone) { - } - ); - const request = server.requests[0]; - request.respond(400, responseHeader, JSON.stringify('error')); - expect(submoduleCallback).to.equal(undefined); - }); - - it('dapTokenize success callback', function () { - const configAsync = JSON.parse(JSON.stringify(sampleConfig)); - const submoduleCallback = dapUtils.dapTokenize(configAsync, sampleIdentity, onDone, - function(token, status, xhr, onDone) { - }, - function(xhr, status, error, onDone) { - } - ); - const request = server.requests[0]; - request.requestHeaders['Content-Type'].should.equal('application/json'); - request.respond(200, responseHeader, JSON.stringify('success')); - expect(submoduleCallback).to.equal(undefined); - }); - }); - - describe('dapX2Tokenize', function () { - it('dapX2Tokenize error callback', function () { - const configAsync = JSON.parse(JSON.stringify(sampleX2Config)); - const submoduleCallback = dapUtils.dapTokenize(configAsync, sampleIdentity, onDone, - function(token, status, xhr, onDone) { - }, - function(xhr, status, error, onDone) { - } - ); - const request = server.requests[0]; - request.requestHeaders['Content-Type'].should.equal('application/json'); - request.respond(400, responseHeader, JSON.stringify('error')); - expect(submoduleCallback).to.equal(undefined); - }); - - it('dapX2Tokenize success callback', function () { - const configAsync = JSON.parse(JSON.stringify(sampleX2Config)); - const submoduleCallback = dapUtils.dapTokenize(configAsync, sampleIdentity, onDone, - function(token, status, xhr, onDone) { - }, - function(xhr, status, error, onDone) { - } - ); - const request = server.requests[0]; - request.requestHeaders['Content-Type'].should.equal('application/json'); - request.respond(200, responseHeader, JSON.stringify('success')); - expect(submoduleCallback).to.equal(undefined); - }); - }); - - describe('dapTokenize and dapMembership incorrect params', function () { - it('Onerror and config are null', function () { - expect(dapUtils.dapTokenize(null, 'identity', onDone, null, null)).to.be.equal(undefined); - expect(dapUtils.dapMembership(null, 'identity', onDone, null, null)).to.be.equal(undefined); - expect(dapUtils.dapEncryptedMembership(null, 'identity', onDone, null, null)).to.be.equal(undefined); - const config = { - 'api_hostname': 'prebid.dap.akadns.net', - 'api_version': 1, - 'domain': '', - 'segtax': 708 - }; - const encConfig = { - 'api_hostname': 'prebid.dap.akadns.net', - 'api_version': 1, - 'domain': '', - 'segtax': 710 - }; - const identity = { - type: 'dap-signature:1.0.0' - }; - expect(dapUtils.dapTokenize(config, identity, onDone, null, null)).to.be.equal(undefined); - expect(dapUtils.dapMembership(config, 'token', onDone, null, null)).to.be.equal(undefined); - expect(dapUtils.dapEncryptedMembership(encConfig, 'token', onDone, null, null)).to.be.equal(undefined); - }); - }); - - describe('Getting dapTokenize, dapMembership and dapEncryptedMembership from localstorage', function () { - it('dapGetTokenFromLocalStorage success', function () { - storage.setDataInLocalStorage(DAP_TOKEN, JSON.stringify(sampleCachedToken)); - expect(dapUtils.dapGetTokenFromLocalStorage(60)).to.be.equal(sampleCachedToken.token); - }); - - it('dapGetMembershipFromLocalStorage success', function () { - storage.setDataInLocalStorage(DAP_MEMBERSHIP, JSON.stringify(cachedMembership)); - expect(JSON.stringify(dapUtils.dapGetMembershipFromLocalStorage())).to.be.equal(JSON.stringify(membership)); - }); - - it('dapGetEncryptedMembershipFromLocalStorage success', function () { - storage.setDataInLocalStorage(DAP_ENCRYPTED_MEMBERSHIP, JSON.stringify(cachedEncryptedMembership)); - expect(JSON.stringify(dapUtils.dapGetEncryptedMembershipFromLocalStorage())).to.be.equal(JSON.stringify(encMembership)); - }); - }); - - describe('dapMembership', function () { - it('dapMembership success callback', function () { - const configAsync = JSON.parse(JSON.stringify(sampleConfig)); - const submoduleCallback = dapUtils.dapMembership(configAsync, 'token', onDone, - function(token, status, xhr, onDone) { - }, - function(xhr, status, error, onDone) { - } - ); - const request = server.requests[0]; - request.respond(200, responseHeader, JSON.stringify('success')); - expect(submoduleCallback).to.equal(undefined); - }); - - it('dapMembership error callback', function () { - const configAsync = JSON.parse(JSON.stringify(sampleConfig)); - const submoduleCallback = dapUtils.dapMembership(configAsync, 'token', onDone, - function(token, status, xhr, onDone) { - }, - function(xhr, status, error, onDone) { - } - ); - const request = server.requests[0]; - request.respond(400, responseHeader, JSON.stringify('error')); - expect(submoduleCallback).to.equal(undefined); - }); - }); - - describe('dapEncMembership', function () { - it('dapEncMembership success callback', function () { - const configAsync = JSON.parse(JSON.stringify(esampleConfig)); - const submoduleCallback = dapUtils.dapEncryptedMembership(configAsync, 'token', onDone, - function(token, status, xhr, onDone) { - }, - function(xhr, status, error, onDone) { - } - ); - const request = server.requests[0]; - request.respond(200, responseHeader, JSON.stringify('success')); - expect(submoduleCallback).to.equal(undefined); - }); - - it('dapEncMembership error callback', function () { - const configAsync = JSON.parse(JSON.stringify(esampleConfig)); - const submoduleCallback = dapUtils.dapEncryptedMembership(configAsync, 'token', onDone, - function(token, status, xhr, onDone) { - }, - function(xhr, status, error, onDone) { - } - ); - const request = server.requests[0]; - request.respond(400, responseHeader, JSON.stringify('error')); - expect(submoduleCallback).to.equal(undefined); - }); - }); - - describe('dapMembership', function () { - it('should invoke the getDapToken and getDapMembership', function () { - const membership = { - said: 'item.said1', - cohorts: 'item.cohorts', - attributes: null - }; - - const getDapMembershipStub = sinon.stub(dapUtils, 'dapGetMembershipFromLocalStorage').returns(membership); - const callDapApisStub = sinon.stub(dapUtils, 'callDapAPIs'); - try { - generateRealTimeData(testReqBidsConfigObj, onDone, cmoduleConfig); - expect(getDapMembershipStub.calledOnce).to.be.equal(true); - } finally { - getDapMembershipStub.restore(); - callDapApisStub.restore(); - } - }); - }); - - describe('dapEncMembership test', function () { - it('should invoke the getDapToken and getEncDapMembership', function () { - const encMembership = { - encryptedSegments: 'enc.seg', - }; - - const getDapEncMembershipStub = sinon.stub(dapUtils, 'dapGetEncryptedMembershipFromLocalStorage').returns(encMembership); - const callDapApisStub = sinon.stub(dapUtils, 'callDapAPIs'); - try { - generateRealTimeData(testReqBidsConfigObj, onDone, emoduleConfig); - expect(getDapEncMembershipStub.calledOnce).to.be.equal(true); - } finally { - getDapEncMembershipStub.restore(); - callDapApisStub.restore(); - } - }); - }); - - describe('dapGetRtdObj test', function () { - it('dapGetRtdObj', function () { - const config = { - apiHostname: 'prebid.dap.akadns.net', - apiVersion: 'x1', - domain: 'prebid.org', - segtax: 708 - }; - expect(dapUtils.dapRefreshMembership(ortb2, config, 'token', onDone)).to.equal(undefined) - const membership = {cohorts: ['1', '5', '7']} - expect(dapUtils.dapGetRtdObj(membership, config.segtax)).to.not.equal(undefined); - }); - }); - - describe('checkAndAddRealtimeData test', function () { - it('add realtime data for segtax 708 and 710', function () { - dapUtils.checkAndAddRealtimeData(ortb2, cachedEncRtd, 710); - dapUtils.checkAndAddRealtimeData(ortb2, cachedEncRtd, 710); - expect(ortb2.user.data).to.deep.include.members([encRtdUserObj]); - dapUtils.checkAndAddRealtimeData(ortb2, cachedRtd, 708); - expect(ortb2.user.data).to.deep.include.members([rtdUserObj]); - }); - }); - - describe('dapExtractExpiryFromToken test', function () { - it('test dapExtractExpiryFromToken function', function () { - const tokenWithoutExpiry = 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoicGFzc3dvcmQxIn0..6buzBd2BjtgoyaNbHN8YnQ.l38avCfm3sYNy798-ETYOugz0cOx1cCkjACkAhYszxzrZ0sUJ0AiF-NdDXVTiTyp2Ih3vCWKzS0rKJ8lbS1zhyEVWVu91QwtwseM2fBbwA5ggAgBEo5wV-IXqDLPxVnxsPF0D3hP6cNCiH9Q2c-vULfsLhMhG5zvvZDPBbn4hUY5fKB8LoCBTF9rbuuWGYK1nramnb4AlS5UK82wBsHQea1Ou_Kp5wWCMNZ6TZk5qKIuRBfPIAhQblWvHECaHXkg1wyoM9VASs_yNhne7RR-qkwzbFiPFiMJibNOt9hF3_vPDJO5-06ZBjRTP1BllYGWxI-uQX6InzN18Wtun2WHqg.63sH0SNlIRcsK57v0pMujfB_nhU8Y5CuQbsHqH5MGoM' - expect(dapUtils.dapExtractExpiryFromToken(tokenWithoutExpiry)).to.equal(undefined); - const tokenWithExpiry = 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoicGFzc3dvcmQxIiwiZXhwIjoxNjQzODMwMzY5fQ..hTbcSQgmmO0HUJJrQ5fRHw.7zjrQXNNVkb-GD0ZhIVhEPcWbyaDBilHTWv-bp1lFZ9mdkSC0QbcAvUbYteiTD7ya23GUwcL2WOW8WgRSHaWHOJe0B5NDqfdUGTzElWfu7fFodRxRgGmwG8Rq5xxteFKLLGHLf1mFYRJKDtjtgajGNUKIDfn9AEt-c5Qz4KU8VolG_KzrLROx-f6Z7MnoPTcwRCj0WjXD6j2D6RAZ80-mKTNIsMIELdj6xiabHcjDJ1WzwtwCZSE2y2nMs451pSYp8W-bFPfZmDDwrkjN4s9ASLlIXcXgxK-H0GsiEbckQOZ49zsIKyFtasBvZW8339rrXi1js-aBh99M7aS5w9DmXPpUDmppSPpwkeTfKiqF0cQiAUq8tpeEQrGDJuw3Qt2.XI8h9Xw-VZj_NOmKtV19wLM63S4snos7rzkoHf9FXCw' - expect(dapUtils.dapExtractExpiryFromToken(tokenWithExpiry)).to.equal(1643830369); - }); - }); - - describe('dapRefreshToken test', function () { - it('test dapRefreshToken success response', function () { - dapUtils.dapRefreshToken(ortb2, sampleConfig, true, onDone) - const request = server.requests[0]; - request.requestHeaders['Content-Type'].should.equal('application/json'); - responseHeader['Symitri-DAP-Token'] = sampleCachedToken.token; - request.respond(200, responseHeader, JSON.stringify(sampleCachedToken.token)); - expect(JSON.parse(storage.getDataFromLocalStorage(DAP_TOKEN)).token).to.be.equal(sampleCachedToken.token); - }); - - it('test dapRefreshToken success response with deviceid 100', function () { - dapUtils.dapRefreshToken(ortb2, esampleConfig, true, onDone) - const request = server.requests[0]; - request.requestHeaders['Content-Type'].should.equal('application/json'); - responseHeader['Symitri-DAP-100'] = sampleCachedToken.token; - request.respond(200, responseHeader, ''); - expect(storage.getDataFromLocalStorage('dap_deviceId100')).to.be.equal(sampleCachedToken.token); - }); - - it('test dapRefreshToken success response with exp claim', function () { - dapUtils.dapRefreshToken(ortb2, sampleConfig, true, onDone) - const request = server.requests[0]; - const tokenWithExpiry = 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoicGFzc3dvcmQxIiwiZXhwIjoxNjQzODMwMzY5fQ..hTbcSQgmmO0HUJJrQ5fRHw.7zjrQXNNVkb-GD0ZhIVhEPcWbyaDBilHTWv-bp1lFZ9mdkSC0QbcAvUbYteiTD7ya23GUwcL2WOW8WgRSHaWHOJe0B5NDqfdUGTzElWfu7fFodRxRgGmwG8Rq5xxteFKLLGHLf1mFYRJKDtjtgajGNUKIDfn9AEt-c5Qz4KU8VolG_KzrLROx-f6Z7MnoPTcwRCj0WjXD6j2D6RAZ80-mKTNIsMIELdj6xiabHcjDJ1WzwtwCZSE2y2nMs451pSYp8W-bFPfZmDDwrkjN4s9ASLlIXcXgxK-H0GsiEbckQOZ49zsIKyFtasBvZW8339rrXi1js-aBh99M7aS5w9DmXPpUDmppSPpwkeTfKiqF0cQiAUq8tpeEQrGDJuw3Qt2.XI8h9Xw-VZj_NOmKtV19wLM63S4snos7rzkoHf9FXCw' - responseHeader['Symitri-DAP-Token'] = tokenWithExpiry; - request.requestHeaders['Content-Type'].should.equal('application/json'); - request.respond(200, responseHeader, JSON.stringify(tokenWithExpiry)); - expect(JSON.parse(storage.getDataFromLocalStorage(DAP_TOKEN)).expires_at).to.be.equal(1643830359); - }); - - it('test dapRefreshToken error response', function () { - storage.setDataInLocalStorage(DAP_TOKEN, JSON.stringify(sampleCachedToken)); - dapUtils.dapRefreshToken(ortb2, sampleConfig, false, onDone) - const request = server.requests[0]; - request.requestHeaders['Content-Type'].should.equal('application/json'); - request.respond(400, responseHeader, 'error'); - expect(JSON.parse(storage.getDataFromLocalStorage(DAP_TOKEN)).expires_at).to.be.equal(cacheExpiry);// Since the expiry is same, the token is not updated in the cache - }); - }); - - describe('dapRefreshEncryptedMembership test', function () { - it('test dapRefreshEncryptedMembership success response', function () { - const expiry = Math.round(Date.now() / 1000.0) + 3600; // in seconds - const encMembership = 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoic29tZXNlY3JldGludmF1bHQifQ..f8_At4OqeQXyQcSwThOJ_w.69ImVQ3bEZ6QP7ROCRpAJjNcKY49SEPYR6qTp_8l7L8kQdPbpi4wmuOzt78j7iBrX64k2wltzmQFjDmVKSxDhrEguxpgx6t-L1tT8ZA0UosMWpVsgmKEZxOn2e9ES3jw8RNCS4WSWocSPQX33xSb51evXjm9E1s0tGoLnwXl0GsUvzRsSU86wQG6RZnAQTi7s-r-M2TKibdDjUqgIt62vJ-aBZ7RWw91MINgOdmDNs1bFfbBX5Cy1kd4-kjvRDz_aJ6zHX4sK_7EmQhGEY3tW-A3_l2I88mw-RSJaPkb_IWg0QpVwXDaE2F2g8NpY1PzCRvG_NIE8r28eK5q44OMVitykHmKmBXGDj7z2JVgoXkfo5u0I-dypZARn4GP_7niK932avB-9JD7Mz3TrlU4GZ7IpYfJ91PMsRhrs5xNPQwLZbpuhF76A7Dp7iss71UjkGCiPTU6udfRb4foyf_7xEF66m1eQVcVaMdxEbMuu9GBfdr-d04TbtJhPfUV8JfxTenvRYoi13n0j5kH0M5OgaSQD9kQ3Mrd9u-Cms-BGtT0vf-N8AaFZY_wn0Y4rkpv5HEaH7z3iT4RCHINWrXb_D0WtjLTKQi2YmF8zMlzUOewNJGwZRwbRwxc7JoDIKEc5RZkJYevfJXOEEOPGXZ7AGZxOEsJawPqFqd_nOUosCZS4akHhcDPcVowoecVAV0hhhoS6JEY66PhPp1snbt6yqA-fQhch7z8Y-DZT3Scibvffww3Scg_KFANWp0KeEvHG0vyv9R2F4o66viSS8y21MDnM7Yjk8C-j7aNMldUQbjN_7Yq1nkfe0jiBX_hsINBRPgJHUY4zCaXuyXs-JZZfU92nwG0RT3A_3RP2rpY8-fXp9d3C2QJjEpnmHvTMsuAZCQSBe5DVrJwN_UKedxcJEoOt0wLz6MaCMyYZPd8tnQeqYK1cd3RgQDXtzKC0HDw1En489DqJXEst4eSSkaaW1lImLeaF8XCOaIqPqoyGk4_6KVLw5Q7OnpczuXqYKMd9UTMovGeuTuo1k0ddfEqTq9QwxkwZL51AiDRnwTCAeYBU1krV8FCJQx-mH_WPB5ftZj-o_3pbvANeRk27QBVmjcS-tgDllJkWBxX-4axRXzLw8pUUUZUT_NOL0OiqUCWVm0qMBEpgRQ57Se42-hkLMTzLhhGJOnVcaXU1j4ep-N7faNvbgREBjf_LgzvaWS90a2NJ9bB_J9FyXelhCN_AMLfdOS3fHkeWlZ0u0PMbn5DxXRMe0l9jB-2VJZhcPQRlWoYyoCO3l4F5ZmuQP5Xh9CU4tvSWih6jlwMDgdVWuTpdfPD5bx8ccog3JDq87enx-QtPzLU3gMgouNARJGgNwKS_GJSE1uPrt2oiqgZ3Z0u_I5MKvPdQPV3o-4rsaE730eB4OwAOF-mkGWpzy8Pbl-Qe5PR9mHBhuyJgZ-WDSCHl5yvet2kfO9mPXZlqBQ26fzTcUYH94MULAZn36og6w.3iKGv-Le-AvRmi26W1v6ibRLGbwKbCR92vs-a9t55hw'; - dapUtils.dapRefreshEncryptedMembership(ortb2, esampleConfig, sampleCachedToken.token, onDone) - const request = server.requests[0]; - responseHeader['Symitri-DAP-Token'] = encMembership; - request.respond(200, responseHeader, encMembership); - const rtdObj = dapUtils.dapGetEncryptedRtdObj({'encryptedSegments': encMembership}, 710) - expect(ortb2.user.data).to.deep.include.members(rtdObj.rtd.ortb2.user.data); - expect(JSON.parse(storage.getDataFromLocalStorage(DAP_ENCRYPTED_MEMBERSHIP)).expires_at).to.equal(expiry); - }); - - it('test dapRefreshEncryptedMembership success response with exp claim', function () { - const encMembership = 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoic29tZXNlY3JldGludmF1bHQiLCJleHAiOjE2NDM4MzA2NDB9..inYoxwht_aqTIWqGhEm_Gw.wDcCUOCwtqgnNUouaD723gKfm7X7bgkHgtiX4mr07P3tWk25PUQunmwTLhWBB5CYzzGIfIvveG_u4glNRLi_eRSQV4ihKKk1AN-BSSJ3d0CLAdY9I1WG5vX1VmopXyKnV90bl9SLNqnhg4Vxe6YU4ogTYxsKHuIN1EeIH4hpl-HbCQWQ1DQt4mB-MQF8V9AWTfU0D7sFMSK8f9qj6NGmf1__oHdHUlws0t5V2UAn_dhJexsuREK_gh65pczCuly5eEcziZ82LeP-nOhKWSRHB_tS_mKXrRU6_At_EVDgtfA3PSBJ6eQylCii6bTL42vZzz4jZhJv_3eLfRdKqpVT5CWNBzcDoQ2VcQgKgIBtPJ45KFfAYTQ6kdl21QMSjqtu8GTsv1lEZtrqHY6zRiG8_Mu28-PmjEw4LDdZmBDOeroue_MJD6wuE_jlE7J2iVdo8CkVnoRgzFwNbKBo7CK4z0WahV9rhuOm0LKAN5H0jF_gj696U-3fVTDTIb8ndNKNI2_xAhvWs00BFGtUtWgr8QGDGRTDCNGsDgnb_Vva9xCqVOyAE9O3Fq1QYl-tMA-KkBt3zzvmFFpOxpOyH-lUubKLKlsrxKc3GSyVEQ9DDLhrXXJgR5H5BSE4tjlK7p3ODF5qz0FHtIj7oDcgLazFO7z2MuFy2LjJmd3hKl6ujcfYEDiQ4D3pMIo7oiU33aFBD1YpzI4-WzNfJlUt1FoK0-DAXpbbV95s8p08GOD4q81rPw5hRADKJEr0QzrbDwplTWCzT2fKXMg_dIIc5AGqGKnVRUS6UyF1DnHpudNIJWxyWZjWIEw_QNjU0cDFmyPSyKxNrnfq9w8WE2bfbS5KTicxei5QHnC-cnL7Nh7IXp7WOW6R1YHbNPT7Ad4OhnlV-jjrXwkSv4wMAbfwAWoSCchGh7uvENNAeJymuponlJbOgw_GcYM73hMs8Z8W9qxRfbyF4WX5fDKXg61mMlaieHkc0EnoC5q7uKyXuZUehHZ76JLDFmewslLkQq5SkVCttzJePBnY1ouPEHw5ZTzUnG5f01QQOVcjIN-AqXNDbG5IOwq0heyS6vVfq7lZKJdLDVQ21qRjazGPaqYwLzugkWkzCOzPTgyFdbXzgjfmJwylHSOM5Jpnul84GzxEQF-1mHP2A8wtIT-M7_iX24It2wwWvc8qLA6GEqruWCtNyoug8CXo44mKdSSCGeEZHtfMbzXdLIBHCy2jSHz5i8S7DU_R7rE_5Ssrb81CqIYbgsAQBHtOYoyvzduTOruWcci4De0QcULloqImIEHUuIe2lnYO889_LIx5p7nE3UlSvLBo0sPexavFUtHqI6jdG6ye9tdseUEoNBDXW0aWD4D-KXX1JLtAgToPVUtEaXCJI7QavwO9ZG6UZM6jbfuJ5co0fvUXp6qYrFxPQo2dYHkar0nT6s1Zg5l2g8yWlLUJrHdHAzAw_NScUp71OpM4TmNsLnYaPVPcOxMvtJXTanbNWr0VKc8gy9q3k_1XxAnQwiduNs7f5bA-6qCVpayHv5dE7mUhFEwyh1_w95jEaURsQF_hnnd2OqRkADfiok4ZiPU2b38kFW1LXjpI39XXES3JU0e08Rq2uuelyLbCLWuJWq_axuKSZbZvpYeqWtIAde8FjCiO7RPlEc0nyzWBst8RBxQ-Bekg9UXPhxBRcm0HwA.Q2cBSFOQAC-QKDwmjrQXnVQd3jNOppMl9oZfd2yuKeY'; - dapUtils.dapRefreshEncryptedMembership(ortb2, esampleConfig, sampleCachedToken.token, onDone) - const request = server.requests[0]; - responseHeader['Symitri-DAP-Token'] = encMembership; - request.respond(200, responseHeader, encMembership); - const rtdObj = dapUtils.dapGetEncryptedRtdObj({'encryptedSegments': encMembership}, 710) - expect(ortb2.user.data).to.deep.include.members(rtdObj.rtd.ortb2.user.data); - expect(JSON.parse(storage.getDataFromLocalStorage(DAP_ENCRYPTED_MEMBERSHIP)).expires_at).to.equal(1643830630); - }); - - it('test dapRefreshEncryptedMembership error response', function () { - dapUtils.dapRefreshEncryptedMembership(ortb2, esampleConfig, sampleCachedToken.token, onDone) - const request = server.requests[0]; - request.respond(400, responseHeader, 'error'); - expect(ortb2).to.eql({}); - }); - - it('test dapRefreshEncryptedMembership 403 error response', function () { - dapUtils.dapRefreshEncryptedMembership(ortb2, esampleConfig, sampleCachedToken.token, onDone) - const request = server.requests[0]; - request.respond(403, responseHeader, 'error'); - const requestTokenize = server.requests[1]; - responseHeader['Symitri-DAP-Token'] = sampleCachedToken.token; - requestTokenize.respond(200, responseHeader, ''); - const requestMembership = server.requests[2]; - requestMembership.respond(403, responseHeader, 'error'); - expect(server.requests.length).to.be.equal(DAP_MAX_RETRY_TOKENIZE + 2); - }); - }); - - describe('dapRefreshMembership test', function () { - it('test dapRefreshMembership success response', function () { - const membership = {'cohorts': ['9', '11', '13'], 'said': 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoicGFzc3dvcmQxIn0..17wnrhz6FbWx0Cf6LXpm1A.m9PKVCradk3CZokNKzVHzE06TOqiXYeijgxTQUiQy5Syx-yicnO8DyYX6zQ6rgPcNgUNRt4R4XE5MXuK0laUVQJr9yc9g3vUfQfw69OMYGW_vRlLMPzoNOhF2c4gSyfkRrLr7C0qgALmZO1D11sPflaCTNmO7pmZtRaCOB5buHoWcQhp1bUSJ09DNDb31dX3llimPwjNGSrUhyq_EZl4HopnnjxbM4qVNMY2G_43C_idlVOvbFoTxcDRATd-6MplJoIOIHQLDZEetpIOVcbEYN9gQ_ndBISITwuu5YEgs5C_WPHA25nm6e4BT5R-tawSA8yPyQAupqE8gk4ZWq_2-T0cqyTstIHrMQnZ_vysYN7h6bkzE-KeZRk7GMtySN87_fiu904hLD9QentGegamX6UAbVqQh7Htj7SnMHXkEenjxXAM5mRqQvNCTlw8k-9-VPXs-vTcKLYP8VFf8gMOmuYykgWac1gX-svyAg-24mo8cUbqcsj9relx4Qj5HiXUVyDMBZxK-mHZi-Xz6uv9GlggcsjE13DSszar-j2OetigpdibnJIxRZ-4ew3-vlvZ0Dul3j0LjeWURVBWYWfMjuZ193G7lwR3ohh_NzlNfwOPBK_SYurdAnLh7jJgTW-lVLjH2Dipmi9JwX9s03IQq9opexAn7hlM9oBI6x5asByH8JF8WwZ5GhzDjpDwpSmHPQNGFRSyrx_Sh2CPWNK6C1NJmLkyqAtJ5iw0_al7vPDQyZrKXaLTjBCUnbpJhUZ8dUKtWLzGPjzFXp10muoDIutd1NfyKxk1aWGhx5aerYuLdywv6cT_M8RZTi8924NGj5VA30V5OvEwLLyX93eDhntXZSCbkPHpAfiRZNGXrPY.GhCbWGQz11mIRD4uPKmoAuFXDH7hGnils54zg7N7-TU'} - dapUtils.dapRefreshMembership(ortb2, sampleConfig, sampleCachedToken.token, onDone); - const request = server.requests[0]; - request.respond(200, responseHeader, JSON.stringify(membership)); - const rtdObj = dapUtils.dapGetRtdObj(membership, 708); - expect(ortb2.user.data).to.deep.include.members(rtdObj.rtd.ortb2.user.data); - }); - - it('test dapRefreshMembership success response with exp claim', function () { - const membership = {'cohorts': ['9', '11', '13'], 'said': 'eyJhbGciOiJkaXIiLCJlbmMiOiJBMTI4Q0JDLUhTMjU2Iiwia2lkIjoicGFzc3dvcmQxIiwiZXhwIjoxNjQ3OTcxNTU4fQ..ptdM5WO-62ypXlKxFXD4FQ.waEo9MHS2NYQCi-zh_p6HgT9BdqGyQbBq4GfGLfsay4nRBgICsTS-VkV6e7xx5U1T8BgpKkRJIZBwTOY5Pkxk9FpK5nnffDSEljRrp1LXLCkNP4qwrlqHInFbZsonNWW4_mW-7aUPlTwIsTbfjTuyHdXHeQa1ALrwFFFWE7QUmPNd2RsHjDwUsxlJPEb5TnHn5W0Mgo_PQZaxvhJInMbxPgtJLoqnJvOqCBEoQY7au7ALZL_nWK8XIwPMF19J7Z3cBg9vQInhr_E3rMdQcAFHEzYfgoNcIYCCR0t1UOqUE3HNtX-E64kZAYKWdlsBb9eW5Gj9hHYyPNL_4Hntjg5eLXGpsocMg0An-qQKGC6hkrxKzeM-GrjpvSaQLNs4iqDpHUtzA02LW_vkLkMNRUiyXVJ3FUZwfyq6uHSRKWZ6UFdAfL0rfJ8q8x8Ll-qJO2Jfyvidlsi9FIs7x1WJrvDCKepfAQM1UXRTonrQljFBAk83PcL2bmWuJDgJZ0lWS4VnZbIf6A7fDourmkDxdVRptvQq5nSjtzCA6whRw0-wGz8ehNJsaJw9H_nG9k4lRKs7A5Lqsyy7TVFrAPjnA_Q1a2H6xF2ULxrtIqoNqdX7k9RjowEZSQlZgZUOAmI4wzjckdcSyC_pUlYBMcBwmlld34mmOJe9EBHAxjdci7Q_9lvj1HTcwGDcQITXnkW9Ux5Jkt9Naw-IGGrnEIADaT2guUAto8W_Gb05TmwHSd6DCmh4zepQCbqeVe6AvPILtVkTgsTTo27Q-NvS7h-XtthJy8425j5kqwxxpZFJ0l0ytc6DUyNCLJXuxi0JFU6-LoSXcROEMVrHa_Achufr9vHIELwacSAIHuwseEvg_OOu1c1WYEwZH8ynBLSjqzy8AnDj24hYgA0YanPAvDqacrYrTUFqURbHmvcQqLBTcYa_gs7uDx4a1EjtP_NvHRlvCgGAaASrjGMhTX8oJxlTqahhQ.pXm-7KqnNK8sbyyczwkVYhcjgiwkpO8LjBBVw4lcyZE'}; - dapUtils.dapRefreshMembership(ortb2, sampleConfig, sampleCachedToken.token, onDone); - const request = server.requests[0]; - request.respond(200, responseHeader, JSON.stringify(membership)); - const rtdObj = dapUtils.dapGetRtdObj(membership, 708) - expect(ortb2.user.data).to.deep.include.members(rtdObj.rtd.ortb2.user.data); - expect(JSON.parse(storage.getDataFromLocalStorage(DAP_MEMBERSHIP)).expires_at).to.be.equal(1647971548); - }); - - it('test dapRefreshMembership 400 error response', function () { - dapUtils.dapRefreshMembership(ortb2, sampleConfig, sampleCachedToken.token, onDone) - const request = server.requests[0]; - request.respond(400, responseHeader, 'error'); - expect(ortb2).to.eql({}); - }); - - it('test dapRefreshMembership 403 error response', function () { - dapUtils.dapRefreshMembership(ortb2, sampleConfig, sampleCachedToken.token, onDone) - const request = server.requests[0]; - request.respond(403, responseHeader, 'error'); - expect(server.requests.length).to.be.equal(DAP_MAX_RETRY_TOKENIZE); - }); - }); - - describe('dapGetEncryptedMembershipFromLocalStorage test', function () { - it('test dapGetEncryptedMembershipFromLocalStorage function with valid cache', function () { - storage.setDataInLocalStorage(DAP_ENCRYPTED_MEMBERSHIP, JSON.stringify(cachedEncryptedMembership)) - expect(JSON.stringify(dapUtils.dapGetEncryptedMembershipFromLocalStorage())).to.equal(JSON.stringify(encMembership)); - }); - - it('test dapGetEncryptedMembershipFromLocalStorage function with invalid cache', function () { - const expiry = Math.round(Date.now() / 1000.0) - 100; // in seconds - const encMembership = {'expiry': expiry, 'encryptedSegments': cachedEncryptedMembership.encryptedSegments} - storage.setDataInLocalStorage(DAP_ENCRYPTED_MEMBERSHIP, JSON.stringify(encMembership)) - expect(dapUtils.dapGetEncryptedMembershipFromLocalStorage()).to.equal(null); - }); - }); - - describe('Symitri-DAP-SS-ID test', function () { - it('Symitri-DAP-SS-ID present in response header', function () { - const expiry = Math.round(Date.now() / 1000.0) + 300; // in seconds - dapUtils.dapRefreshToken(ortb2, sampleConfig, false, onDone) - const request = server.requests[0]; - request.requestHeaders['Content-Type'].should.equal('application/json'); - const sampleSSID = 'Test_SSID_Spec'; - responseHeader['Symitri-DAP-Token'] = sampleCachedToken.token; - responseHeader['Symitri-DAP-SS-ID'] = sampleSSID; - request.respond(200, responseHeader, ''); - expect(storage.getDataFromLocalStorage(DAP_SS_ID)).to.be.equal(JSON.stringify(sampleSSID)); - }); - - it('Test if Symitri-DAP-SS-ID is present in request header', function () { - const expiry = Math.round(Date.now() / 1000.0) + 100; // in seconds - storage.setDataInLocalStorage(DAP_SS_ID, JSON.stringify('Test_SSID_Spec')) - dapUtils.dapRefreshToken(ortb2, sampleConfig, false, onDone) - const request = server.requests[0]; - request.requestHeaders['Content-Type'].should.equal('application/json'); - const ssidHeader = request.requestHeaders['Symitri-DAP-SS-ID']; - responseHeader['Symitri-DAP-Token'] = sampleCachedToken.token; - request.respond(200, responseHeader, ''); - expect(ssidHeader).to.be.equal('Test_SSID_Spec'); - }); - }); - - describe('Test gdpr and usp consent handling', function () { - it('Gdpr applies and gdpr consent string not present', function () { - expect(symitriDapRtdSubmodule.init(null, sampleGdprConsentConfig)).to.equal(false); - }); - - it('Gdpr applies and gdpr consent string is present', function () { - sampleGdprConsentConfig.gdpr.consentString = 'BOJ/P2HOJ/P2HABABMAAAAAZ+A=='; - expect(symitriDapRtdSubmodule.init(null, sampleGdprConsentConfig)).to.equal(true); - }); - - it('USP consent present and user have opted out', function () { - expect(symitriDapRtdSubmodule.init(null, sampleUspConsentConfig)).to.equal(false); - }); - - it('USP consent present and user have not been provided with option to opt out', function () { - expect(symitriDapRtdSubmodule.init(null, {'usp': '1NYY'})).to.equal(false); - }); - - it('USP consent present and user have not opted out', function () { - expect(symitriDapRtdSubmodule.init(null, {'usp': '1YNY'})).to.equal(true); - }); - }); - - describe('Test identifier is added properly to apiParams', function() { - let sandbox; - - beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('passed identifier is handled', async function () { - const test_identity = 'test_identity_1234'; - const identity = { - value: test_identity - }; - const apiParams = { - 'type': identity.type, - }; - - if (window.crypto && window.crypto.subtle) { - const hid = await dapUtils.addIdentifier(identity, apiParams).then(); - expect(hid['identity']).is.equal('843BE0FB20AAE699F27E5BC88C554B716F3DD366F58C1BDE0ACFB7EA0DD90CE7'); - } else { - expect(window.crypto.subtle).is.undefined - } - }); - - it('passed undefined identifier is handled', async function () { - const test_identity = undefined; - const identity = { - identity: test_identity - } - const apiParams = { - 'type': identity.type, - }; - - const hid = await dapUtils.addIdentifier(identity, apiParams); - expect(hid.identity).is.undefined; - }); - }); - - describe('onBidResponseEvent', function () { - const bidResponse = {adId: 'ad_123', bidder: 'test_bidder', bidderCode: 'test_bidder_code', cpm: '1.5', creativeId: 'creative_123', dealId: 'DEMODEAL555', mediaType: 'banner', responseTimestamp: '1725892736147', ad: ''}; - const url = emoduleConfig.params.pixelUrl + '?token=' + sampleCachedToken.token + '&ad_id=' + bidResponse.adId + '&bidder=' + bidResponse.bidder + '&bidder_code=' + bidResponse.bidderCode + '&cpm=' + bidResponse.cpm + '&creative_id=' + bidResponse.creativeId + '&deal_id=' + bidResponse.dealId + '&media_type=' + bidResponse.mediaType + '&response_timestamp=' + bidResponse.responseTimestamp; - const adPixel = `${bidResponse.ad}", - 'adomain': ['google.com'], - 'iurl': 'https://cdn.tapnative.com/1_368853_1.png', - 'cid': '468133/368853', - 'crid': '368853', - 'w': 300, - 'h': 250, - 'cat': ['IAB7-19'] - }], - 'seat': 'tapnative', - 'group': 0 - }], - 'cur': 'USD', - 'bidid': 'BIDDER_-1' - } - }; - nativeResponse = { - 'body': { - 'id': '453ade66-9113-4944-a674-5bbdcb9808ac', - 'seatbid': [{ - 'bid': [{ - 'id': '652c9a4c-66ea-4579-998b-cefe7b4cfecd', - 'impid': '2c3875bdbb1893', - 'price': 1.1, - 'adid': '368852', - 'adm': '{\"native\":{\"ver\":\"1.1\",\"assets\": [{\"id\":1,\"required\":1,\"title\":{\"text\":\"Integrative Approaches: Merging Traditional and Alternative \"}},{\"id\":2,\"required\":1,\"img\":{\"url\":\"https://cdn.tapnative.com/1_368852_0.png\",\"w\":500,\"h\":300,\"type\":\"3\"}},{\"id\":3,\"required\":0,\"data\":{\"value\":\"Diabetes In Control. A free weekly diabetes newsletter for Medical Professionals.\"}},{\"id\":4,\"required\":1,\"data\":{\"value\":\"Integrative Approaches: Merging Traditional and Alternative \"}},{\"id\":6,\"required\":1,\"data\":{\"value\":\"URL\"}}],\"link\":{\"url\":\"https://r.tapnative.com/adx-rtb-d/servlet/WebF_AdManager.AdLinkManager?qs=H4sIAAAAAAAAAx2U2QHDIAxDVwKDr3F84P1HqNLPtMSRpSeG9RiPXH+5a474KzO/47YX7UoP50m61fLujlNjb76/8ZiblkimHq5nL/ZRedp3031x1tnk55LjSNN6h9/Zq+qmaLLuWTl74m1ZJKnb+m2OtQm/3L4sb933pM92qMOgjJ41MYmPXKnndRVKs+9bfSEumoZIFpTXuXbCP+WXuzl725E3O+9odi5OJrnBzhwjx9+UnFN3nTNt1/HY5aeljKtvZYpoJHNXr8BWa8ysKQY7ZmNA3DHK2qRwY7+zLu+xm9z5eheJ4Pv2usSptvO3p7JHrnXn0T5yVWdccp9Yz7hhoz2iu2zqsXsGFZ9hh14J6yU4TkJ0BgnOY8tY3tS+n2qsw7xZfKuanSNbAo+9nkJ83i20+FwhfbJeDVOllXsdxmDWauYcSRgS9+yG5qHwUDjAxxA0iZnOjlsnI+y09+ATeTEwbAVGgp0Qu/ceP0kjUvpu1Ty7O9MoegfrmLPxdjUh3mJL+XhARby+Ax8iBckf6BQdn9W+DMlvmlzYLuLlIy7YociFOIvXvEiYYCMboVk8BLHbnw3Zmr5us3xbjtXL67L96F15acJXkM5BOmTaUbBkYGdCI+Et8XmlpbuE3xVQwmxryc2y4wP3ByuuP8GogPZz8OpPaBv8diWWUTrC2nnLhdNUrJRTKc9FepDvwHTDwfbbMCTSb4LhUIFkyFrw/i7GtkPi6NCCai6N47TgNsTnzZWRoVtOSLq7FsLiF29y0Gj0GHVPVYG3QOPS7Swc3UuiFAQZJx3YvpHA2geUgVBASMEL4vcDi2Dw3NPtBSC4EQEvH/uMILu6WyUwraywTeVpoqoHTqOoD84FzReKoWemJy6jyuiBieGlQIe6wY2elTaMOwEUFF5NagzPj6nauc0+aXzQN3Q72hxFAgtfORK60RRAHYZLYymIzSJcXLgRFsqrb1UoD+5Atq7TWojaLTfOyUvH9EeJvZEOilQAXrf/ALoI8ZhABQAA\"},\"imptrackers\":[\"https://i.tapnative.com/adx-rtb-d/servlet/WebF_AdManager.ImpCounter?price=${AUCTION_PRICE}&ids=111519,16703,468132,368852,211356,233,13,16704,1&cb=1728409547&ap=5.00000&vd=223.233.85.189,14,8&nm=0.00&GUIDs=[adx_guid],652c9a4c-66ea-4579-998b-cefe7b4cfecd,652c9a4c-66ea-4579-998b-cefe7b4cfecd,999999,-1_&info=2,-1,IN&adx_custom=&adx_custom_ex=~~~-1~~~0&cat=-1&ref=https%3A%2F%2Fqa-jboss.audiencelogy.com%2Ftn_native_prod.html\",\"https://i.tapnative.com/adx-rtb-d/servlet/WebF_AdManager.ImpTracker?price=${AUCTION_PRICE}&ids=111519,16703,468132,368852,211356,233,13,16704,1&cb=1728409547&ap=5.00000&vd=223.233.85.189,14,8&nm=0.00&GUIDs=[adx_guid],652c9a4c-66ea-4579-998b-cefe7b4cfecd,652c9a4c-66ea-4579-998b-cefe7b4cfecd,999999,-1_&info=2,-1,IN&adx_custom=&adx_custom_ex=~~~-1~~~0&cat=-1&ref=\",\"https://rtb-east.tapnative.com:9001/beacon?uid=44636f6605b06ec6d4389d6efb7e5054&cc=468132&fccap=5&nid=1\"]}}', - 'adomain': ['www.diabetesincontrol.com'], - 'iurl': 'https://cdn.tapnative.com/1_368852_0.png', - 'cid': '468132/368852', - 'crid': '368852', - 'cat': ['IAB7'] - }], - 'seat': 'tapnative', - 'group': 0 - }], - 'cur': 'USD', - 'bidid': 'BIDDER_-1' - } - }; - invalidBannerResponse = { - 'body': { - 'id': '006ac3b3-67f0-43bf-a33a-388b2f869fef', - 'seatbid': [{ - 'bid': [{ - 'id': '049d07ed-c07e-4890-9f19-5cf41406a42d', - 'impid': '286e606ac84a09', - 'price': 0.11, - 'adid': '368853', - 'adm': 'invalid response', - 'adomain': ['google.com'], - 'iurl': 'https://cdn.tapnative.com/1_368853_1.png', - 'cid': '468133/368853', - 'crid': '368853', - 'w': 300, - 'h': 250, - 'cat': ['IAB7-19'] - }], - 'seat': 'tapnative', - 'group': 0 - }], - 'cur': 'USD', - 'bidid': 'BIDDER_-1' - } - }; - invalidNativeResponse = { - 'body': { - 'id': '453ade66-9113-4944-a674-5bbdcb9808ac', - 'seatbid': [{ - 'bid': [{ - 'id': '652c9a4c-66ea-4579-998b-cefe7b4cfecd', - 'impid': '2c3875bdbb1893', - 'price': 1.1, - 'adid': '368852', - 'adm': 'invalid response', - 'adomain': ['www.diabetesincontrol.com'], - 'iurl': 'https://cdn.tapnative.com/1_368852_0.png', - 'cid': '468132/368852', - 'crid': '368852', - 'cat': ['IAB7'] - }], - 'seat': 'tapnative', - 'group': 0 - }], - 'cur': 'USD', - 'bidid': 'BIDDER_-1' - } - }; - }); - - describe('validations', function () { - it('isBidValid : placement_id is passed', function () { - const bid = { - bidder: 'tapnative', - params: { - placement_id: 111520 - } - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equals(true); - }); - it('isBidValid : placement_id is not passed', function () { - const bid = { - bidder: 'tapnative', - params: { - width: 300, - height: 250, - domain: '', - bid_floor: 0.5 - } - }; - const isValid = spec.isBidRequestValid(bid); - expect(isValid).to.equals(false); - }); - }); - describe('Validate Banner Request', function () { - it('Immutable bid request validate', function () { - const _Request = utils.deepClone(bannerRequest); - const bidRequest = spec.buildRequests(bannerRequest); - expect(bannerRequest).to.deep.equal(_Request); - }); - it('Validate bidder connection', function () { - const _Request = spec.buildRequests(bannerRequest); - expect(_Request.url).to.equal('https://rtb-east.tapnative.com/hb'); - expect(_Request.method).to.equal('POST'); - expect(_Request.options.contentType).to.equal('application/json'); - }); - it('Validate bid request : Impression', function () { - const _Request = spec.buildRequests(bannerRequest); - const data = JSON.parse(_Request.data); - // expect(data.at).to.equal(1); // auction type - expect(data[0].imp[0].id).to.equal(bannerRequest[0].bidId); - expect(data[0].placementId).to.equal(111520); - }); - it('Validate bid request : ad size', function () { - const _Request = spec.buildRequests(bannerRequest); - const data = JSON.parse(_Request.data); - expect(data[0].imp[0].banner).to.be.a('object'); - expect(data[0].imp[0].banner.w).to.equal(300); - expect(data[0].imp[0].banner.h).to.equal(250); - }); - it('Validate bid request : user object', function () { - const _Request = spec.buildRequests(bannerRequest); - const data = JSON.parse(_Request.data); - expect(data[0].user).to.be.a('object'); - expect(data[0].user.id).to.be.a('string'); - }); - it('Validate bid request : CCPA Check', function () { - const bidRequest = { - uspConsent: '1NYN' - }; - const _Request = spec.buildRequests(bannerRequest, bidRequest); - const data = JSON.parse(_Request.data); - expect(data[0].regs.ext.us_privacy).to.equal('1NYN'); - // let _bidRequest = {}; - // let _Request1 = spec.buildRequests(request, _bidRequest); - // let data1 = JSON.parse(_Request1.data); - // expect(data1.regs).to.equal(undefined); - }); - }); - describe('Validate banner response ', function () { - it('Validate bid response : valid bid response', function () { - const _Request = spec.buildRequests(bannerRequest); - const bResponse = spec.interpretResponse(bannerResponse, _Request); - expect(bResponse).to.be.an('array').with.length.above(0); - expect(bResponse[0].requestId).to.equal(bannerResponse.body.seatbid[0].bid[0].impid); - expect(bResponse[0].width).to.equal(bannerResponse.body.seatbid[0].bid[0].w); - expect(bResponse[0].height).to.equal(bannerResponse.body.seatbid[0].bid[0].h); - expect(bResponse[0].currency).to.equal('USD'); - expect(bResponse[0].netRevenue).to.equal(false); - expect(bResponse[0].mediaType).to.equal('banner'); - expect(bResponse[0].meta.advertiserDomains).to.deep.equal(['google.com']); - expect(bResponse[0].ttl).to.equal(300); - expect(bResponse[0].creativeId).to.equal(bannerResponse.body.seatbid[0].bid[0].crid); - expect(bResponse[0].dealId).to.equal(bannerResponse.body.seatbid[0].bid[0].dealId); - }); - it('Invalid bid response check ', function () { - const bRequest = spec.buildRequests(bannerRequest); - const response = spec.interpretResponse(invalidBannerResponse, bRequest); - expect(response[0].ad).to.equal('invalid response'); - }); - }); - describe('Validate Native Request', function () { - it('Immutable bid request validate', function () { - const _Request = utils.deepClone(nativeRequest); - const bidRequest = spec.buildRequests(nativeRequest); - expect(nativeRequest).to.deep.equal(_Request); - }); - it('Validate bidder connection', function () { - const _Request = spec.buildRequests(nativeRequest); - expect(_Request.url).to.equal('https://rtb-east.tapnative.com/hb'); - expect(_Request.method).to.equal('POST'); - expect(_Request.options.contentType).to.equal('application/json'); - }); - it('Validate bid request : Impression', function () { - const _Request = spec.buildRequests(nativeRequest); - const data = JSON.parse(_Request.data); - // expect(data.at).to.equal(1); // auction type - expect(data[0].imp[0].id).to.equal(nativeRequest[0].bidId); - expect(data[0].placementId).to.equal(111519); - }); - it('Validate bid request : user object', function () { - const _Request = spec.buildRequests(nativeRequest); - const data = JSON.parse(_Request.data); - expect(data[0].user).to.be.a('object'); - expect(data[0].user.id).to.be.a('string'); - }); - it('Validate bid request : CCPA Check', function () { - const bidRequest = { - uspConsent: '1NYN' - }; - const _Request = spec.buildRequests(nativeRequest, bidRequest); - const data = JSON.parse(_Request.data); - expect(data[0].regs.ext.us_privacy).to.equal('1NYN'); - // let _bidRequest = {}; - // let _Request1 = spec.buildRequests(request, _bidRequest); - // let data1 = JSON.parse(_Request1.data); - // expect(data1.regs).to.equal(undefined); - }); - }); - describe('Validate native response ', function () { - it('Validate bid response : valid bid response', function () { - const _Request = spec.buildRequests(nativeRequest); - const bResponse = spec.interpretResponse(nativeResponse, _Request); - expect(bResponse).to.be.an('array').with.length.above(0); - expect(bResponse[0].requestId).to.equal(nativeResponse.body.seatbid[0].bid[0].impid); - // expect(bResponse[0].width).to.equal(bannerResponse.body.seatbid[0].bid[0].w); - // expect(bResponse[0].height).to.equal(bannerResponse.body.seatbid[0].bid[0].h); - expect(bResponse[0].currency).to.equal('USD'); - expect(bResponse[0].netRevenue).to.equal(false); - expect(bResponse[0].mediaType).to.equal('native'); - expect(bResponse[0].native.clickUrl).to.be.a('string').and.not.be.empty; - expect(bResponse[0].native.impressionTrackers).to.be.an('array').with.length.above(0); - expect(bResponse[0].native.title).to.be.a('string').and.not.be.empty; - expect(bResponse[0].native.image.url).to.be.a('string').and.not.be.empty; - expect(bResponse[0].meta.advertiserDomains).to.deep.equal(['www.diabetesincontrol.com']); - expect(bResponse[0].ttl).to.equal(300); - expect(bResponse[0].creativeId).to.equal(nativeResponse.body.seatbid[0].bid[0].crid); - expect(bResponse[0].dealId).to.equal(nativeResponse.body.seatbid[0].bid[0].dealId); - }); - }); - describe('GPP and coppa', function () { - it('Request params check with GPP Consent', function () { - const bidderReq = { gppConsent: { gppString: 'gpp-string-test', applicableSections: [5] } }; - const _Request = spec.buildRequests(bannerRequest, bidderReq); - const data = JSON.parse(_Request.data); - expect(data[0].regs.gpp).to.equal('gpp-string-test'); - expect(data[0].regs.gpp_sid[0]).to.equal(5); - }); - it('Request params check with GPP Consent read from ortb2', function () { - const bidderReq = { - ortb2: { - regs: { - gpp: 'gpp-test-string', - gpp_sid: [5] - } - } - }; - const _Request = spec.buildRequests(bannerRequest, bidderReq); - const data = JSON.parse(_Request.data); - expect(data[0].regs.gpp).to.equal('gpp-test-string'); - expect(data[0].regs.gpp_sid[0]).to.equal(5); - }); - it(' Bid request should have coppa flag if its true', () => { - const bidderReq = { ortb2: { regs: { coppa: 1 } } }; - const _Request = spec.buildRequests(bannerRequest, bidderReq); - const data = JSON.parse(_Request.data); - expect(data[0].regs.coppa).to.equal(1); - }); - }); -}); diff --git a/test/spec/modules/tappxBidAdapter_spec.js b/test/spec/modules/tappxBidAdapter_spec.js deleted file mode 100644 index d9d0004e1..000000000 --- a/test/spec/modules/tappxBidAdapter_spec.js +++ /dev/null @@ -1,531 +0,0 @@ -import { assert } from 'chai'; -import { spec } from 'modules/tappxBidAdapter.js'; -import { _checkParamDataType, _getHostInfo, _extractPageUrl } from '../../../modules/tappxBidAdapter.js'; - -const c_BIDREQUEST = { - data: { - }, - bids: [ - { - bidder: 'tappx', - params: { - host: 'testing.ssp.tappx.com\/rtb\/v2\/', - tappxkey: 'pub-1234-android-1234', - endpoint: 'ZZ1234PBJS', - bidfloor: 0.05 - }, - crumbs: { - pubcid: 'df2144f7-673f-4440-83f5-cd4a73642d99' - }, - ortb2Imp: { - ext: { - divid: 'div-ad-12345', - gpid: '/19968336/header-bid-tag-0', - data: { - adserver: { - name: 'gam', - adslot: '/19968336/header-bid-tag-0' - }, - pbadslot: '/19968336/header-bid-tag-0', - } - } - }, - mediaTypes: { - banner: { - sizes: [ - [ - 320, - 480 - ] - ] - } - }, - adUnitCode: 'div-1', - transactionId: '47dd44e8-e7db-417c-a8f1-621a2e1a117d', - sizes: [ - [ - 320, - 480 - ] - ], - bidId: '2170932097e505', - bidderRequestId: '140ba7a1ab7aeb', - auctionId: '1c54b4f1-645f-44e6-b8ae-5d43c923ef1c', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0, - } - ] -}; -const c_SERVERRESPONSE_B = { - body: { - id: '1c54b4f1-645f-44e6-b8ae-5d43c923ef1c', - bidid: 'bid3811165568213389257', - seatbid: [ - { - seat: '1', - group: 0, - bid: [ - { - id: '3811165568213389257', - impid: 1, - price: 0.05, - adm: "\t", - w: 320, - h: 480, - lurl: 'https:\/\/ssp.api.tappx.com\/burlURL', - burl: 'https:\/\/ssp.api.tappx.com\/burlURL', - nurl: 'https:\/\/ssp.api.tappx.com\/nurllURL', - dealId: 'b21d0704-9688-4e46-81d9-41de1050fef7', - cid: '01744fbb521e9fb10ffea926190effea', - crid: 'a13cf884e66e7c660afec059c89d98b6', - adomain: [ - ], - }, - ], - }, - ], - cur: 'USD', - }, - headers: {} -}; - -const c_SERVERRESPONSE_V = { - body: { - id: '1c54b4f1-645f-44e6-b8ae-5d43c923ef1c', - bidid: 'bid3811165568213389257', - seatbid: [ - { - seat: '1', - group: 0, - bid: [ - { - id: '3811165568213389257', - impid: 1, - price: 0.05, - adm: "Tappx<\/AdSystem>Tappx<\/AdTitle><\/Impression><\/Error>00:00:22<\/Duration><\/Tracking><\/Tracking><\/Tracking><\/Tracking><\/Tracking><\/Tracking><\/Tracking><\/TrackingEvents><\/ClickThrough><\/ClickTracking><\/VideoClicks><\/MediaFile><\/MediaFiles><\/Linear><\/Creative><\/Creatives><\/InLine><\/Ad><\/VAST>", - lurl: 'https:\/\/ssp.api.tappx.com\/lurlURL', - burl: 'https:\/\/ssp.api.tappx.com\/burlURL', - nurl: 'https:\/\/ssp.api.tappx.com\/nurllURL', - dealId: 'b21d0704-9688-4e46-81d9-41de1050fef7', - cid: '01744fbb521e9fb10ffea926190effea', - crid: 'a13cf884e66e7c660afec059c89d98b6', - adomain: [ - ], - }, - ], - }, - ], - cur: 'USD', - }, - headers: {} -}; - -const c_CONSENTSTRING = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; -const c_VALIDBIDREQUESTS = [{'bidder': 'tappx', 'params': {'host': 'testing.ssp.tappx.com\/rtb\/v2\/', 'tappxkey': 'pub-1234-android-1234', 'endpoint': 'ZZ1234PBJS', 'bidfloor': 0.005, 'test': 1}, 'userId': {'haloId': '0000x179MZAzMqUWsFonu7Drm3eDDBMYtj5SPoWQnl89Upk3WTlCvEnKI9SshX0p6eFJ7otPYix179MZAzMqUWsFonu7Drm3eDDBMYtj5SPoWQnl89Upk3WTlCvEnKI9SshX0p6e', 'id5id': {'uid': 'ID5@iu-PJX_OQ0d6FJjKS8kYfUpHriD_rEXbz6UYtYEJelYrDaZOLkh8WcF9J0ZHmEHFKZEBlLXsgP6xqXU3BCj4Ay0Z6fw_jSOaHxMHwd-voRHqFA4Q9NwAxFcVLyPWnNGZ9VbcSAPos1wupq7Xu3MIm-Bw_0vxjhZdWNy4chM9x3i', 'ext': {'linkType': 0}}, 'intentIqId': 'GIF89a\u0000\u0000\u0000\u0000�\u0000\u0000���\u0000\u0000\u0000?�\u0000\u0000\u0000\u0000\u0000\u0000,\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000A\u0000\u0000;', 'lotamePanoramaId': 'xTtLUY7GwqX2MMqSHo9RQ2YUOIBFhlASOR43I9KjvgtcrxIys3RxME96M02LTjWR', 'parrableId': {'eid': '02.YoqC9lWZh8.C8QTSiJTNgI6Pp0KCM5zZgEgwVMSsVP5W51X8cmiUHQESq9WRKB4nreqZJwsWIcNKlORhG4u25Wm6lmDOBmQ0B8hv0KP6uVQ97aouuH52zaz2ctVQTORUKkErPRPcaCJ7dKFcrNoF2i6WOR0S5Nk'}, 'pubcid': 'b1254-152f-12F5-5698-dI1eljK6C7WA', 'pubProvidedId': [{'source': 'domain.com', 'uids': [{'id': 'value read from cookie or local storage', 'atype': 1, 'ext': {'stype': 'ppuid'}}]}, {'source': '3rdpartyprovided.com', 'uids': [{'id': 'value read from cookie or local storage', 'atype': 3, 'ext': {'stype': 'sha256email'}}]}]}, 'userIdAsEids': [{'source': 'audigent.com', 'uids': [{'id': '0000fgclxw05ycn0608xiyi90bwpa0c0evvlif0hv1x0i0ku88il0ntek0o0qskvir0trr70u0wqxiix0zq3u1012pa5j315ogh1618nmsj91bmt41c1elzfjf1hl5r1i1kkc2jl', 'atype': 1}]}, {'source': 'id5-sync.com', 'uids': [{'id': 'ID5@iu-PJX_OQ0d6FJjKS8kYfUpHriD_qpoXJUngedfpNva812If1fHEqHHkamLC89txVxk1i9WGqeQrTX97HFCgv9QDa1M_bkHUBsAWFm-D5r1rYrsfMFFiyqwCAEzqNbvsUZXOYCAQSjPcLxR4of22w-U9_JDRThCGRDV3Fmvc38E', 'atype': 1, 'ext': {'linkType': 0}}]}], 'ortb2Imp': {'ext': {'divid': 'div-ad-12345', 'gpid': '/19968336/header-bid-tag-0', 'data': {'adserver': {'name': 'gam', 'adslot': '/19968336/header-bid-tag-0'}, 'pbadslot': '/19968336/header-bid-tag-0'}}}, 'mediaTypes': {'banner': {'sizes': [[320, 480], [320, 50]]}}, 'adUnitCode': 'div-gpt-ad-1460505748561-0', 'transactionId': '71c0d86b-4b47-4aff-a6da-1af0b1712439', 'sizes': [[320, 480], [320, 50]], 'bidId': '264d7969b125a5', 'bidderRequestId': '1c674c14a3889c', 'auctionId': '13a8a3a9-ed3a-4101-9435-4699ee77bb62', 'src': 'client', 'bidRequestsCount': 1, 'bidderRequestsCount': 1, 'bidderWinsCount': 0}]; -const c_VALIDBIDAPPREQUESTS = [{'bidder': 'tappx', 'params': {'host': 'testing.ssp.tappx.com\/rtb\/v2\/', 'tappxkey': 'pub-1234-android-1234', 'endpoint': 'ZZ1234PBJS', 'bidfloor': 0.005, 'test': 1, 'app': {'name': 'Tappx Test', 'bundle': 'com.test.tappx', 'domain': 'tappx.com', 'publisher': { 'name': 'Tappx', 'domain': 'tappx.com' }}}, 'userId': {'haloId': '0000fgclxw05ycn0608xiyi90bwpa0c0evvlif0hv1x0i0ku88il0ntek0o0qskvir0trr70u0wqxiix0zq3u1012pa5j315ogh1618nmsj91bmt41c1elzfjf1hl5r1i1kkc2jl', 'id5id': {'uid': 'ID5@iu-PJX_OQ0d6FJjKS8kYfUpHriD_qpoXJUngedfpNva812If1fHEqHHkamLC89txVxk1i9WGqeQrTX97HFCgv9QDa1M_bkHUBsAWFm-D5r1rYrsfMFFiyqwCAEzqNbvsUZXOYCAQSjPcLxR4of22w-U9_JDRThCGRDV3Fmvc38E', 'ext': {'linkType': 0}}, 'intentIqId': 'GIF89a\u0001\u0000\u0001\u0000�\u0000\u0000���\u0000\u0000\u0000!�\u0004\u0001\u0000\u0000\u0000\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0002D\u0001\u0000;', 'lotamePanoramaId': '8003916b61a95b185690ec103bdf4945a70213e01818a5e5d8690b542730755a', 'parrableId': {'eid': '01.1617088921.7faa68d9570a50ea8e4f359e9b99ca4b7509e948a6175b3e5b0b8cbaf5b62424104ccfb0191ca79366de8368ed267b89a68e236df5f41f96f238e4301659e9023fec05e46399fb1ad0a0'}, 'pubcid': 'b7143795-852f-42f0-8864-5ecbea1ade4e', 'pubProvidedId': [{'source': 'domain.com', 'uids': [{'id': 'value read from cookie or local storage', 'atype': 1, 'ext': {'stype': 'ppuid'}}]}, {'source': '3rdpartyprovided.com', 'uids': [{'id': 'value read from cookie or local storage', 'atype': 3, 'ext': {'stype': 'sha256email'}}]}]}, 'userIdAsEids': [{'source': 'audigent.com', 'uids': [{'id': '0000fgclxw05ycn0608xiyi90bwpa0c0evvlif0hv1x0i0ku88il0ntek0o0qskvir0trr70u0wqxiix0zq3u1012pa5j315ogh1618nmsj91bmt41c1elzfjf1hl5r1i1kkc2jl', 'atype': 1}]}, {'source': 'id5-sync.com', 'uids': [{'id': 'ID5@iu-PJX_OQ0d6FJjKS8kYfUpHriD_qpoXJUngedfpNva812If1fHEqHHkamLC89txVxk1i9WGqeQrTX97HFCgv9QDa1M_bkHUBsAWFm-D5r1rYrsfMFFiyqwCAEzqNbvsUZXOYCAQSjPcLxR4of22w-U9_JDRThCGRDV3Fmvc38E', 'atype': 1, 'ext': {'linkType': 0}}]}, {'source': 'intentiq.com', 'uids': [{'id': 'GIF89a\u0001\u0000\u0001\u0000�\u0000\u0000���\u0000\u0000\u0000!�\u0004\u0001\u0000\u0000\u0000\u0000,\u0000\u0000\u0000\u0000\u0001\u0000\u0001\u0000\u0000\u0002\u0002D\u0001\u0000;', 'atype': 1}]}, {'source': 'crwdcntrl.net', 'uids': [{'id': '8003916b61a95b185690ec103bdf4945a70213e01818a5e5d8690b542730755a', 'atype': 1}]}, {'source': 'parrable.com', 'uids': [{'id': '01.1617088921.7faa68d9570a50ea8e4f359e9b99ca4b7509e948a6175b3e5b0b8cbaf5b62424104ccfb0191ca79366de8368ed267b89a68e236df5f41f96f238e4301659e9023fec05e46399fb1ad0a0', 'atype': 1}]}, {'source': 'pubcid.org', 'uids': [{'id': 'b7143795-852f-42f0-8864-5ecbea1ade4e', 'atype': 1}]}, {'source': 'domain.com', 'uids': [{'id': 'value read from cookie or local storage', 'atype': 1, 'ext': {'stype': 'ppuid'}}]}, {'source': '3rdpartyprovided.com', 'uids': [{'id': 'value read from cookie or local storage', 'atype': 3, 'ext': {'stype': 'sha256email'}}]}], 'ortb2Imp': {'ext': {'divid': 'div-ad-12345', 'gpid': '/19968336/header-bid-tag-0', 'data': {'adserver': {'name': 'gam', 'adslot': '/19968336/header-bid-tag-0'}, 'pbadslot': '/19968336/header-bid-tag-0'}}}, 'mediaTypes': {'banner': {'sizes': [[320, 480], [320, 50]]}}, 'adUnitCode': 'div-gpt-ad-1460505748561-0', 'transactionId': '71c0d86b-4b47-4aff-a6da-1af0b1712439', 'sizes': [[320, 480], [320, 50]], 'bidId': '264d7969b125a5', 'bidderRequestId': '1c674c14a3889c', 'auctionId': '13a8a3a9-ed3a-4101-9435-4699ee77bb62', 'src': 'client', 'bidRequestsCount': 1, 'bidderRequestsCount': 1, 'bidderWinsCount': 0}]; -const c_BIDDERREQUEST_B = {'bidderCode': 'tappx', 'auctionId': '13a8a3a9-ed3a-4101-9435-4699ee77bb62', 'bidderRequestId': '1c674c14a3889c', 'bids': [{'bidder': 'tappx', 'params': {'host': 'testing.ssp.tappx.com\/rtb\/v2\/', 'tappxkey': 'pub-1234-android-1234', 'endpoint': 'ZZ1234PBJS', 'bidfloor': 0.005, 'test': 1}, 'userId': {'haloId': '0000fgclxw05ycn0608xiyi90bwpa0c0evvlif0hv1x0i0ku88il0ntek0o0qskvir0trr70u0wqxiix0zq3u1012pa5j315ogh1618nmsj91bmt41c1elzfjf1hl5r1i1kkc2jl', 'id5id': {'uid': 'ID5@iu-PJX_OQ0d6FJjKS8kYfUpHriD_qpoXJUngedfpNva812If1fHEqHHkamLC89txVxk1i9WGqeQrTX97HFCgv9QDa1M_bkHUBsAWFm-D5r1rYrsfMFFiyqwCAEzqNbvsUZXOYCAQSjPcLxR4of22w-U9_JDRThCGRDV3Fmvc38E', 'ext': {'linkType': 0}}, 'intentIqId': 'GIF89a\u0000\u0000\u0000\u0000�\u0000\u0000���\u0000\u0000\u0000?�\u0000\u0000\u0000\u0000\u0000\u0000,\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000A\u0000\u0000;', 'lotamePanoramaId': '8003916b61a95b185690ec103bdf4945a70213e01818a5e5d8690b542730755a', 'parrableId': {'eid': '01.1617088921.7faa68d9570a50ea8e4f359e9b99ca4b7509e948a6175b3e5b0b8cbaf5b62424104ccfb0191ca79366de8368ed267b89a68e236df5f41f96f238e4301659e9023fec05e46399fb1ad0a0'}, 'pubcid': 'b7143795-852f-42f0-8864-5ecbea1ade4e', 'pubProvidedId': [{'source': 'domain.com', 'uids': [{'id': 'value read from cookie or local storage', 'atype': 1, 'ext': {'stype': 'ppuid'}}]}, {'source': '3rdpartyprovided.com', 'uids': [{'id': 'value read from cookie or local storage', 'atype': 3, 'ext': {'stype': 'sha256email'}}]}]}, 'userIdAsEids': [{'source': 'audigent.com', 'uids': [{'id': '0000fgclxw05ycn0608xiyi90bwpa0c0evvlif0hv1x0i0ku88il0ntek0o0qskvir0trr70u0wqxiix0zq3u1012pa5j315ogh1618nmsj91bmt41c1elzfjf1hl5r1i1kkc2jl', 'atype': 1}]}, {'source': 'id5-sync.com', 'uids': [{'id': 'ID5@iu-PJX_OQ0d6FJjKS8kYfUpHriD_qpoXJUngedfpNva812If1fHEqHHkamLC89txVxk1i9WGqeQrTX97HFCgv9QDa1M_bkHUBsAWFm-D5r1rYrsfMFFiyqwCAEzqNbvsUZXOYCAQSjPcLxR4of22w-U9_JDRThCGRDV3Fmvc38E', 'atype': 1, 'ext': {'linkType': 0}}]}], 'ortb2Imp': {'ext': {'divid': 'div-ad-12345', 'gpid': '/19968336/header-bid-tag-0', 'data': {'adserver': {'name': 'gam', 'adslot': '/19968336/header-bid-tag-0'}, 'pbadslot': '/19968336/header-bid-tag-0'}}}, 'mediaTypes': {'banner': {'sizes': [[320, 480], [320, 50]]}}, 'adUnitCode': 'div-gpt-ad-1460505748561-0', 'transactionId': '71c0d86b-4b47-4aff-a6da-1af0b1712439', 'sizes': [[320, 480], [320, 50]], 'bidId': '264d7969b125a5', 'bidderRequestId': '1c674c14a3889c', 'auctionId': '13a8a3a9-ed3a-4101-9435-4699ee77bb62', 'src': 'client', 'bidRequestsCount': 1, 'bidderRequestsCount': 1, 'bidderWinsCount': 0}], 'auctionStart': 1617088922120, 'timeout': 700, 'refererInfo': {'page': 'http://localhost:9999/integrationExamples/gpt/gdpr_hello_world.html?pbjs_debug=true', 'reachedTop': true, 'isAmp': false, 'numIframes': 0, 'stack': ['http://localhost:9999/integrationExamples/gpt/gdpr_hello_world.html?pbjs_debug=true'], 'canonicalUrl': null}, 'gdprConsent': {'consentString': c_CONSENTSTRING, 'vendorData': {'metadata': 'BO-JeiTPABAOkAAABAENABA', 'gdprApplies': true, 'hasGlobalScope': false, 'cookieVersion': 1, 'created': '2020-12-09T09:22:09.900Z', 'lastUpdated': '2021-01-14T15:44:03.600Z', 'cmpId': 0, 'cmpVersion': 1, 'consentScreen': 0, 'consentLanguage': 'EN', 'vendorListVersion': 1, 'maxVendorId': 0, 'purposeConsents': {}, 'vendorConsents': {}}, 'gdprApplies': true, 'apiVersion': 1}, 'uspConsent': '1YCC', 'start': 1611308859099}; -const c_BIDDERREQUEST_V = {'method': 'POST', 'url': 'https://testing.ssp.tappx.com/rtb/v2//VZ12TESTCTV?type_cnn=prebidjs&v=0.1.10329', 'data': '{"site":{"name":"localhost","bundle":"localhost","domain":"localhost"},"user":{"ext":{}},"id":"0fecfa84-c541-49f8-8c45-76b90fddc30e","test":1,"at":1,"tmax":1000,"bidder":"tappx","imp":[{"video":{"mimes":["video/mp4","application/javascript"],"minduration":3,"maxduration":30,"startdelay":5,"playbackmethod":[1,3],"api":[1,2],"protocols":[2,3],"battr":[13,14],"linearity":1,"plcmt":2,"minbitrate":10,"maxbitrate":10,"w":320,"h":250},"id":"2398241a5a860b","tagid":"localhost_typeAdBanVid_windows","secure":1,"bidfloor":0.005,"ext":{"bidder":{"tappxkey":"pub-1234-desktop-1234","endpoint":"vz34906po","host":"https://vz34906po.pub.tappx.com/rtb/","bidfloor":0.005}}}],"device":{"os":"windows","ip":"peer","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36","h":864,"w":1536,"dnt":0,"language":"en","make":"Google Inc."},"params":{"host":"tappx.com","bidfloor":0.005},"regs":{"gdpr":0,"ext":{}}}', 'bids': {'bidder': 'tappx', 'params': {'host': 'testing.ssp.tappx.com/rtb/v2/', 'tappxkey': 'pub-1234-desktop-1234', 'endpoint': 'VZ12TESTCTV', 'bidfloor': 0.005, 'test': true}, 'crumbs': {'pubcid': 'dccfe922-3823-4676-b7b2-e5ed8743154e'}, 'ortb2Imp': {'ext': {'data': {'pbadslot': 'video-ad-div'}}}, 'renderer': {'options': {'text': 'Tappx Outstream Video'}}, 'mediaTypes': {'video': {'mimes': ['video/mp4', 'application/javascript'], 'minduration': 3, 'maxduration': 30, 'startdelay': 5, 'playbackmethod': [1, 3], 'api': [1, 2], 'protocols': [2, 3], 'battr': [13, 14], 'linearity': 1, 'plcmt': 2, 'minbitrate': 10, 'maxbitrate': 10, 'w': 320, 'h': 250}}, 'adUnitCode': 'video-ad-div', 'transactionId': 'ed41c805-d14c-49c3-954d-26b98b2aa2c2', 'sizes': [[320, 250]], 'bidId': '28f49c71b13f2f', 'bidderRequestId': '1401710496dc7', 'auctionId': 'e807363f-3095-43a8-a4a6-f44196cb7318', 'src': 'client', 'bidRequestsCount': 1, 'bidderRequestsCount': 1, 'bidderWinsCount': 0}} -const c_BIDDERREQUEST_VOutstream = {'method': 'POST', 'url': 'https://testing.ssp.tappx.com/rtb/v2//VZ12TESTCTV?type_cnn=prebidjs&v=0.1.10329', 'data': '{"site":{"name":"localhost","bundle":"localhost","domain":"localhost"},"user":{"ext":{}},"id":"0fecfa84-c541-49f8-8c45-76b90fddc30e","test":1,"at":1,"tmax":1000,"bidder":"tappx","imp":[{"video":{"context": "outstream","playerSize":[640, 480],"mimes":["video/mp4","application/javascript"],"minduration":3,"maxduration":30,"startdelay":5,"playbackmethod":[1,3],"api":[1,2],"protocols":[2,3],"battr":[13,14],"linearity":1,"plcmt":2,"minbitrate":10,"maxbitrate":10,"w":320,"h":250},"id":"2398241a5a860b","tagid":"localhost_typeAdBanVid_windows","secure":1,"bidfloor":0.005,"ext":{"bidder":{"tappxkey":"pub-1234-desktop-1234","endpoint":"vz34906po","host":"https://vz34906po.pub.tappx.com/rtb/","bidfloor":0.005}}}],"device":{"os":"windows","ip":"peer","ua":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36","h":864,"w":1536,"dnt":0,"language":"en","make":"Google Inc."},"params":{"host":"tappx.com","bidfloor":0.005},"regs":{"gdpr":0,"ext":{}}}', 'bids': {'bidder': 'tappx', 'params': {'host': 'testing.ssp.tappx.com/rtb/v2/', 'tappxkey': 'pub-1234-desktop-1234', 'endpoint': 'VZ12TESTCTV', 'bidfloor': 0.005, 'test': true}, 'crumbs': {'pubcid': 'dccfe922-3823-4676-b7b2-e5ed8743154e'}, 'ortb2Imp': {'ext': {'data': {'pbadslot': 'video-ad-div'}}}, 'renderer': {'options': {'text': 'Tappx Outstream Video'}}, 'mediaTypes': {'video': {'mimes': ['video/mp4', 'application/javascript'], 'minduration': 3, 'maxduration': 30, 'startdelay': 5, 'playbackmethod': [1, 3], 'api': [1, 2], 'protocols': [2, 3], 'battr': [13, 14], 'linearity': 1, 'plcmt': 2, 'minbitrate': 10, 'maxbitrate': 10, 'w': 320, 'h': 250}}, 'adUnitCode': 'video-ad-div', 'transactionId': 'ed41c805-d14c-49c3-954d-26b98b2aa2c2', 'sizes': [[320, 250]], 'bidId': '28f49c71b13f2f', 'bidderRequestId': '1401710496dc7', 'auctionId': 'e807363f-3095-43a8-a4a6-f44196cb7318', 'src': 'client', 'bidRequestsCount': 1, 'bidderRequestsCount': 1, 'bidderWinsCount': 0}} - -describe('Tappx bid adapter', function () { - /** - * IS REQUEST VALID - */ - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - assert.isTrue(spec.isBidRequestValid(c_BIDREQUEST.bids[0]), JSON.stringify(c_BIDREQUEST)); - }); - - it('should return false when tappxkey is missing', function () { - const badBidRequestTpxkey = JSON.parse(JSON.stringify(c_BIDREQUEST)); ; - delete badBidRequestTpxkey.bids[0].params.tappxkey; - assert.isFalse(spec.isBidRequestValid(badBidRequestTpxkey.bids[0])); - }); - - it('should return false when host is missing', function () { - const badBidRequestHost = JSON.parse(JSON.stringify(c_BIDREQUEST)); ; - delete badBidRequestHost.bids[0].params.host; - assert.isFalse(spec.isBidRequestValid(badBidRequestHost.bids[0])); - }); - - it('should return false when classic endpoint is missing', function () { - const badBidRequestClEp = JSON.parse(JSON.stringify(c_BIDREQUEST)); ; - delete badBidRequestClEp.bids[0].params.endpoint; - assert.isFalse(spec.isBidRequestValid(badBidRequestClEp.bids[0])); - }); - - it('should return true when endpoint is not set for new endpoints', function () { - const badBidRequestNwEp = JSON.parse(JSON.stringify(c_BIDREQUEST)); ; - delete badBidRequestNwEp.bids[0].params.endpoint; - badBidRequestNwEp.bids[0].params.host = 'zztesting.ssp.tappx.com/rtb/v2/'; - assert.isTrue(spec.isBidRequestValid(badBidRequestNwEp.bids[0])); - }); - - it('should return false for not instream/outstream requests', function () { - const badBidRequest_v = c_BIDDERREQUEST_V; - delete badBidRequest_v.bids.mediaTypes.banner; - badBidRequest_v.bids.mediaTypes.video = {}; - badBidRequest_v.bids.mediaTypes.video.context = ''; - badBidRequest_v.bids.mediaTypes.video.playerSize = [320, 250]; - assert.isFalse(spec.isBidRequestValid(badBidRequest_v.bids)); - }); - - it('should export the TCF vendor ID', function () { - expect(spec.gvlid).to.equal(628); - }) - }); - - /** - * BUILD REQUEST TEST - */ - describe('buildRequest', function () { - // Web Test - const validBidRequests = c_VALIDBIDREQUESTS; - const validBidRequests_V = c_VALIDBIDREQUESTS; - const validBidRequests_Voutstream = c_VALIDBIDREQUESTS; - // App Test - const validAppBidRequests = c_VALIDBIDAPPREQUESTS; - - const bidderRequest = c_BIDDERREQUEST_B; - const bidderRequest_V = c_BIDDERREQUEST_V; - const bidderRequest_VOutstream = c_BIDDERREQUEST_VOutstream; - - it('should add gdpr/usp consent information to the request', function () { - const request = spec.buildRequests(validBidRequests, bidderRequest); - const payload = JSON.parse(request[0].data); - - expect(payload.regs.gdpr).to.exist.and.to.be.true; - expect(payload.user.ext.consent).to.exist.and.to.equal(c_CONSENTSTRING); - expect(payload.regs.ext.us_privacy).to.exist; - }); - - it('should properly build a banner request', function () { - const request = spec.buildRequests(validBidRequests, bidderRequest); - expect(request[0].url).to.match(/^(http|https):\/\/(.*)\.tappx\.com\/.+/); - expect(request[0].method).to.equal('POST'); - - const data = JSON.parse(request[0].data); - expect(data.site).to.not.equal(null); - expect(data.imp).to.have.lengthOf(1); - expect(data.imp[0].bidfloor, data).to.not.be.null; - expect(data.imp[0].banner).to.not.equal(null); - expect(data.imp[0].banner.w).to.be.oneOf([320, 50, 250, 480]); - expect(data.imp[0].banner.h).to.be.oneOf([320, 50, 250, 480]); - }); - - it('should properly build a video request', function () { - delete validBidRequests_V[0].mediaTypes.banner - validBidRequests_V[0].mediaTypes.video = {}; - validBidRequests_V[0].mediaTypes.video.playerSize = [640, 480]; - validBidRequests_V[0].mediaTypes.video.context = 'instream'; - - bidderRequest_V.bids.mediaTypes.context = 'instream'; - - const request = spec.buildRequests(validBidRequests_V, bidderRequest_V); - expect(request[0].url).to.match(/^(http|https):\/\/(.*)\.tappx\.com\/.+/); - expect(request[0].method).to.equal('POST'); - - const data = JSON.parse(request[0].data); - expect(data.site).to.not.equal(null); - expect(data.imp).to.have.lengthOf(1); - expect(data.imp[0].bidfloor, data).to.not.be.null; - expect(data.imp[0].video).to.not.equal(null); - }); - - it('should properly build a video outstream request', function () { - delete validBidRequests_Voutstream[0].mediaTypes.banner - validBidRequests_Voutstream[0].mediaTypes.video = {}; - validBidRequests_Voutstream[0].mediaTypes.video.playerSize = [640, 480]; - validBidRequests_Voutstream[0].mediaTypes.video.context = 'outstream'; - - bidderRequest_VOutstream.bids.mediaTypes.context = 'outstream'; - - const request = spec.buildRequests(validBidRequests_Voutstream, bidderRequest_VOutstream); - expect(request[0].url).to.match(/^(http|https):\/\/(.*)\.tappx\.com\/.+/); - expect(request[0].method).to.equal('POST'); - - const data = JSON.parse(request[0].data); - expect(data.site).to.not.equal(null); - expect(data.imp).to.have.lengthOf(1); - expect(data.imp[0].bidfloor, data).to.not.be.null; - expect(data.imp[0].video).to.not.equal(null); - }); - - it('should properly create video rewarded request', function () { - delete validBidRequests_Voutstream[0].mediaTypes.banner - validBidRequests_Voutstream[0].mediaTypes.video = {}; - validBidRequests_Voutstream[0].mediaTypes.video.rewarded = 1; - validBidRequests_Voutstream[0].mediaTypes.video.playerSize = [640, 480]; - validBidRequests_Voutstream[0].mediaTypes.video.context = 'outstream'; - - bidderRequest_VOutstream.bids.mediaTypes.context = 'outstream'; - - const request = spec.buildRequests(validBidRequests_Voutstream, bidderRequest_VOutstream); - expect(request[0].url).to.match(/^(http|https):\/\/(.*)\.tappx\.com\/.+/); - expect(request[0].method).to.equal('POST'); - - const data = JSON.parse(request[0].data); - expect(data.site).to.not.equal(null); - expect(data.imp).to.have.lengthOf(1); - expect(data.imp[0].bidfloor, data).to.not.be.null; - expect(data.imp[0].video).to.not.equal(null); - }); - - it('should set user eids array', function () { - const request = spec.buildRequests(validBidRequests, bidderRequest); - - const data = JSON.parse(request[0].data); - expect(data.user.ext.eids, data).to.not.be.null; - expect(data.user.ext.eids[0]).to.have.keys(['source', 'uids']); - }); - - it('should properly build a banner request with app params', function () { - const request = spec.buildRequests(validAppBidRequests, bidderRequest); - expect(request[0].url).to.match(/^(http|https):\/\/(.*)\.tappx\.com\/.+/); - expect(request[0].method).to.equal('POST'); - - const data = JSON.parse(request[0].data); - expect(data.site).to.not.equal(null); - expect(data.imp).to.have.lengthOf(1); - expect(data.imp[0].bidfloor, data).to.not.be.null; - expect(data.imp[0].banner).to.not.equal(null); - expect(data.imp[0].banner.w).to.be.oneOf([320, 50, 250, 480]); - expect(data.imp[0].banner.h).to.be.oneOf([320, 50, 250, 480]); - }); - - it('should properly build a ext optional object', function() { - const extBidRequest = c_VALIDBIDREQUESTS; - extBidRequest[0].params.ext = {'optionalData': '1234'}; - const extBidderRequest = c_BIDDERREQUEST_B; - extBidderRequest.bids[0].ext = {'optionalData': '1234'}; - - const request = spec.buildRequests(extBidRequest, extBidderRequest); - const data = JSON.parse(request[0].data); - expect(data.imp[0].ext.bidder.ext).to.be.an('object'); - expect(data.imp[0].ext.bidder.ext.optionalData).to.be.equal('1234'); - }); - - it('should ignore ext optional if is not a object', function() { - const badExtBidRequest = c_VALIDBIDREQUESTS; - badExtBidRequest[0].params.ext = 'stringValue'; - const badExtBidderRequest = c_BIDDERREQUEST_B; - badExtBidderRequest.bids[0].ext = 'stringValue'; - - const request = spec.buildRequests(badExtBidRequest, badExtBidderRequest); - const data = JSON.parse(request[0].data); - expect(data.imp[0].ext.bidder.ext).not.to.be.an('string'); - expect(data.imp[0].ext.bidder.ext).to.be.an('undefined'); - expect(data.imp[0].ext.bidder).to.not.have.property('ext') - }); - - it('should correctly build ortb2Imp.ext params when present', function () { - const bidRequestsWithAdData = c_VALIDBIDREQUESTS; - const request = spec.buildRequests(bidRequestsWithAdData, bidderRequest); - const payload = JSON.parse(request[0].data); - const impExt = payload.imp[0].ext; - - expect(impExt.data).to.exist.and.to.be.an('object'); - expect(impExt.data.pbadslot).to.be.equal('/19968336/header-bid-tag-0'); - - expect(impExt.data.adserver).to.exist.and.to.be.an('object'); - expect(impExt.data.adserver.name).to.be.equal('gam'); - expect(impExt.data.adserver.adslot).to.be.equal('/19968336/header-bid-tag-0'); - - expect(impExt.divid).to.be.equal('div-ad-12345'); - expect(impExt.gpid).to.be.equal('/19968336/header-bid-tag-0'); - }); - - it('should not add ortb2Imp.ext params when not received', function () { - const bidRequestsWithoutGpidData = c_VALIDBIDREQUESTS; - - bidRequestsWithoutGpidData[0].ortb2Imp.ext = { - gpid: undefined, - data: { - pbadslot: undefined, - adserver: { - name: undefined, - adslot: undefined - } - }, - divid: undefined - }; - - const request = spec.buildRequests(bidRequestsWithoutGpidData, bidderRequest); - const payload = JSON.parse(request[0].data); - const impExt = payload.imp[0].ext; - - expect(impExt.data).to.not.exist; - expect(impExt.divid).to.be.an('undefined'); - expect(impExt.gpid).to.be.an('undefined'); - }); - }); - - /** - * INTERPRET RESPONSE TESTS - */ - describe('interpretResponse', function () { - it('receive banner reponse with single plcmt', function () { - const bids = spec.interpretResponse(c_SERVERRESPONSE_B, c_BIDDERREQUEST_B); - const bid = bids[0]; - expect(bid.cpm).to.exist; - expect(bid.ad).to.match(/^', - 'ttl': 700, - 'ad': '' - } - ]; - const request = spec.buildRequests(bidRequests)[0]; - const result = spec.interpretResponse({body: response}, request); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - expect(result[0].cpm).to.not.equal(null); - expect(result[0].creativeId).to.not.equal(null); - expect(result[0].ad).to.not.equal(null); - expect(result[0].currency).to.equal('TRY'); - expect(result[0].netRevenue).to.equal(false); - }); - }) -}) diff --git a/test/spec/modules/terceptAnalyticsAdapter_spec.js b/test/spec/modules/terceptAnalyticsAdapter_spec.js deleted file mode 100644 index bcbfaf63a..000000000 --- a/test/spec/modules/terceptAnalyticsAdapter_spec.js +++ /dev/null @@ -1,1020 +0,0 @@ -import terceptAnalyticsAdapter from 'modules/terceptAnalyticsAdapter.js'; -import { expect } from 'chai'; -import adapterManager from 'src/adapterManager.js'; -import * as utils from 'src/utils.js'; -import { server } from 'test/mocks/xhr.js'; -import { EVENTS } from 'src/constants.js'; - -const events = require('src/events'); - -describe('tercept analytics adapter', function () { - let clock; - - beforeEach(function () { - // Freeze time at a fixed date/time - clock = sinon.useFakeTimers(new Date('2025-07-25T12:00:00Z').getTime()); - sinon.stub(events, 'getEvents').returns([]); - }); - - afterEach(function () { - clock.restore(); - events.getEvents.restore(); - }); - - describe('track', function () { - const initOptions = { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - hostName: 'us-central1-quikr-ebay.cloudfunctions.net', - pathName: '/prebid-analytics' - }; - - const prebidEvent = { - 'addAdUnits': {}, - 'requestBids': {}, - 'auctionInit': { - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'timestamp': 1576823893836, - 'auctionStatus': 'inProgress', - 'adUnits': [ - { - 'code': 'div-gpt-ad-1460505748561-0', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 13144370 - }, - 'crumbs': { - 'pubcid': 'ff4002c4-ce05-4a61-b4ef-45a3cd93991a' - } - } - ], - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'transactionId': '6d275806-1943-4f3e-9cd5-624cbd05ad98' - } - ], - 'adUnitCodes': [ - 'div-gpt-ad-1460505748561-0' - ], - 'bidderRequests': [ - { - 'bidderCode': 'appnexus', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'bidderRequestId': '155975c76e13b1', - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 13144370 - }, - 'crumbs': { - 'pubcid': 'ff4002c4-ce05-4a61-b4ef-45a3cd93991a' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': '6d275806-1943-4f3e-9cd5-624cbd05ad98', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '263efc09896d0c', - 'bidderRequestId': '155975c76e13b1', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'auctionStart': 1576823893836, - 'timeout': 1000, - 'refererInfo': { - 'referer': 'http://observer.com/integrationExamples/gpt/hello_world.html', - 'reachedTop': true, - 'numIframes': 0, - 'stack': [ - 'http://observer.com/integrationExamples/gpt/hello_world.html' - ] - }, - 'start': 1576823893838 - }, - { - 'bidderCode': 'ix', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'bidderRequestId': '181df4d465699c', - 'bids': [ - { - 'bidder': 'ix', - 'params': { - 'placementId': 13144370 - }, - 'crumbs': { - 'pubcid': 'ff4002c4-ce05-4a61-b4ef-45a3cd93991a' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': '6d275806-1943-4f3e-9cd5-624cbd05ad98', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '9424dea605368f', - 'bidderRequestId': '181df4d465699c', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'auctionStart': 1576823893836, - 'timeout': 1000, - 'refererInfo': { - 'referer': 'http://observer.com/integrationExamples/gpt/hello_world.html', - 'reachedTop': true, - 'numIframes': 0, - 'stack': [ - 'http://observer.com/integrationExamples/gpt/hello_world.html' - ] - }, - 'start': 1576823893838 - } - ], - 'noBids': [], - 'bidsReceived': [], - 'winningBids': [], - 'timeout': 1000 - }, - 'bidRequested': { - 'bidderCode': 'appnexus', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'bidderRequestId': '155975c76e13b1', - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 13144370 - }, - 'crumbs': { - 'pubcid': 'ff4002c4-ce05-4a61-b4ef-45a3cd93991a' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': '6d275806-1943-4f3e-9cd5-624cbd05ad98', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '263efc09896d0c', - 'bidderRequestId': '155975c76e13b1', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'auctionStart': 1576823893836, - 'timeout': 1000, - 'refererInfo': { - 'referer': 'http://observer.com/integrationExamples/gpt/hello_world.html', - 'reachedTop': true, - 'numIframes': 0, - 'stack': [ - 'http://observer.com/integrationExamples/gpt/hello_world.html' - ] - }, - 'start': 1576823893838 - }, - 'bidRequested2': { - 'bidderCode': 'ix', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'bidderRequestId': '181df4d465699c', - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 13144370 - }, - 'crumbs': { - 'pubcid': 'ff4002c4-ce05-4a61-b4ef-45a3cd93991a' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'd99d90e0-663a-459d-8c87-4c92ce6a527c', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '9424dea605368f', - 'bidderRequestId': '181df4d465699c', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'auctionStart': 1576823893836, - 'timeout': 1000, - 'refererInfo': { - 'referer': 'http://observer.com/integrationExamples/gpt/hello_world.html', - 'reachedTop': true, - 'numIframes': 0, - 'stack': [ - 'http://observer.com/integrationExamples/gpt/hello_world.html' - ] - }, - 'start': 1576823893838 - }, - 'bidAdjustment': { - 'bidderCode': 'appnexus', - 'width': 300, - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '393976d8770041', - 'requestId': '263efc09896d0c', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 0.5, - 'creativeId': 96846035, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'appnexus': { - 'buyerMemberId': 9325 - }, - 'meta': { - 'advertiserId': 2529885 - }, - 'ad': '', - 'originalCpm': 0.5, - 'originalCurrency': 'USD', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'responseTimestamp': 1576823894050, - 'requestTimestamp': 1576823893838, - 'bidder': 'appnexus', - 'timeToRespond': 212 - }, - 'noBid': { - 'bidder': 'ix', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': 'd99d90e0-663a-459d-8c87-4c92ce6a527c', - 'sizes': [[300, 250]], - 'bidId': '9424dea605368f', - 'bidderRequestId': '181df4d465699c', - 'auctionId': '86e005fa-1900-4782-b6df-528500f09128', - 'src': 's2s', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - }, - 'bidTimeout': [ - ], - 'bidResponse': { - 'bidderCode': 'appnexus', - 'width': 300, - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '393976d8770041', - 'requestId': '263efc09896d0c', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 0.5, - 'creativeId': 96846035, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'appnexus': { - 'buyerMemberId': 9325 - }, - 'meta': { - 'advertiserId': 2529885 - }, - 'ad': '', - 'originalCpm': 0.5, - 'originalCurrency': 'USD', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'responseTimestamp': 1576823894050, - 'requestTimestamp': 1576823893838, - 'bidder': 'appnexus', - 'timeToRespond': 212, - 'pbLg': '0.50', - 'pbMg': '0.50', - 'pbHg': '0.50', - 'pbAg': '0.50', - 'pbDg': '0.50', - 'pbCg': '', - 'size': '300x250', - 'adserverTargeting': { - 'hb_bidder': 'appnexus', - 'hb_adid': '393976d8770041', - 'hb_pb': '0.50', - 'hb_size': '300x250', - 'hb_source': 'client', - 'hb_format': 'banner' - } - }, - 'auctionEnd': { - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'timestamp': 1576823893836, - 'auctionEnd': 1576823894054, - 'auctionStatus': 'completed', - 'adUnits': [ - { - 'code': 'div-gpt-ad-1460505748561-0', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 13144370 - }, - 'crumbs': { - 'pubcid': 'ff4002c4-ce05-4a61-b4ef-45a3cd93991a' - } - } - ], - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'transactionId': '6d275806-1943-4f3e-9cd5-624cbd05ad98' - } - ], - 'adUnitCodes': [ - 'div-gpt-ad-1460505748561-0' - ], - 'bidderRequests': [ - { - 'bidderCode': 'appnexus', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'bidderRequestId': '155975c76e13b1', - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 13144370 - }, - 'crumbs': { - 'pubcid': 'ff4002c4-ce05-4a61-b4ef-45a3cd93991a' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': '6d275806-1943-4f3e-9cd5-624cbd05ad98', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '263efc09896d0c', - 'bidderRequestId': '155975c76e13b1', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'auctionStart': 1576823893836, - 'timeout': 1000, - 'refererInfo': { - 'referer': 'http://observer.com/integrationExamples/gpt/hello_world.html', - 'reachedTop': true, - 'numIframes': 0, - 'stack': [ - 'http://observer.com/integrationExamples/gpt/hello_world.html' - ] - }, - 'start': 1576823893838 - } - ], - 'noBids': [], - 'bidsReceived': [ - { - 'bidderCode': 'appnexus', - 'width': 300, - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '393976d8770041', - 'requestId': '263efc09896d0c', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 0.5, - 'creativeId': 96846035, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'appnexus': { - 'buyerMemberId': 9325 - }, - 'meta': { - 'advertiserId': 2529885 - }, - 'ad': '', - 'originalCpm': 0.5, - 'originalCurrency': 'USD', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'responseTimestamp': 1576823894050, - 'requestTimestamp': 1576823893838, - 'bidder': 'appnexus', - 'timeToRespond': 212, - 'pbLg': '0.50', - 'pbMg': '0.50', - 'pbHg': '0.50', - 'pbAg': '0.50', - 'pbDg': '0.50', - 'pbCg': '', - 'size': '300x250', - 'adserverTargeting': { - 'hb_bidder': 'appnexus', - 'hb_adid': '393976d8770041', - 'hb_pb': '0.50', - 'hb_size': '300x250', - 'hb_source': 'client', - 'hb_format': 'banner' - } - } - ], - 'winningBids': [], - 'timeout': 1000 - }, - 'setTargeting': { - 'div-gpt-ad-1460505748561-0': { - 'hb_format': 'banner', - 'hb_source': 'client', - 'hb_size': '300x250', - 'hb_pb': '0.50', - 'hb_adid': '393976d8770041', - 'hb_bidder': 'appnexus', - 'hb_format_appnexus': 'banner', - 'hb_source_appnexus': 'client', - 'hb_size_appnexus': '300x250', - 'hb_pb_appnexus': '0.50', - 'hb_adid_appnexus': '393976d8770041', - 'hb_bidder_appnexus': 'appnexus' - } - }, - 'bidderDone': { - 'bidderCode': 'appnexus', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'bidderRequestId': '155975c76e13b1', - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 13144370 - }, - 'crumbs': { - 'pubcid': 'ff4002c4-ce05-4a61-b4ef-45a3cd93991a' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'transactionId': '6d275806-1943-4f3e-9cd5-624cbd05ad98', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '263efc09896d0c', - 'bidderRequestId': '155975c76e13b1', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'auctionStart': 1576823893836, - 'timeout': 1000, - 'refererInfo': { - 'referer': 'http://observer.com/integrationExamples/gpt/hello_world.html', - 'reachedTop': true, - 'numIframes': 0, - 'stack': [ - 'http://observer.com/integrationExamples/gpt/hello_world.html' - ] - }, - 'start': 1576823893838 - }, - 'bidWon': { - 'bidderCode': 'appnexus', - 'width': 300, - 'height': 250, - 'statusMessage': 'Bid available', - 'adId': '393976d8770041', - 'requestId': '263efc09896d0c', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 0.5, - 'creativeId': 96846035, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'appnexus': { - 'buyerMemberId': 9325 - }, - 'meta': { - 'advertiserId': 2529885 - }, - 'ad': '', - 'originalCpm': 0.5, - 'originalCurrency': 'USD', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'responseTimestamp': 1576823894050, - 'requestTimestamp': 1576823893838, - 'bidder': 'appnexus', - 'timeToRespond': 212, - 'pbLg': '0.50', - 'pbMg': '0.50', - 'pbHg': '0.50', - 'pbAg': '0.50', - 'pbDg': '0.50', - 'pbCg': '', - 'size': '300x250', - 'adserverTargeting': { - 'hb_bidder': 'appnexus', - 'hb_adid': '393976d8770041', - 'hb_pb': '0.50', - 'hb_size': '300x250', - 'hb_source': 'client', - 'hb_format': 'banner' - }, - 'status': 'rendered', - 'params': [ - { - 'placementId': 13144370 - } - ] - } - }; - const location = utils.getWindowLocation(); - - const expectedAfterBid = { - "bids": [ - { - "bidderCode": "appnexus", - "bidId": "263efc09896d0c", - "adUnitCode": "div-gpt-ad-1460505748561-0", - "requestId": "155975c76e13b1", - "auctionId": "db377024-d866-4a24-98ac-5e430f881313", - "sizes": "300x250,300x600", - "renderStatus": 2, - "requestTimestamp": 1576823893838, - "creativeId": 96846035, - "currency": "USD", - "cpm": 0.5, - "netRevenue": true, - "mediaType": "banner", - "statusMessage": "Bid available", - "timeToRespond": 212, - "responseTimestamp": 1576823894050 - }, - { - "bidderCode": "ix", - "adUnitCode": "div-gpt-ad-1460505748561-0", - "requestId": "181df4d465699c", - "auctionId": "86e005fa-1900-4782-b6df-528500f09128", - "transactionId": "d99d90e0-663a-459d-8c87-4c92ce6a527c", - "sizes": "300x250,300x600", - "renderStatus": 5, - "responseTimestamp": 1753444800000 - } - ], - "auctionInit": { - "auctionId": "db377024-d866-4a24-98ac-5e430f881313", - "timestamp": 1576823893836, - "auctionStatus": "inProgress", - "adUnits": [ - { - "code": "div-gpt-ad-1460505748561-0", - "mediaTypes": { - "banner": { - "sizes": [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - "bids": [ - { - "bidder": "appnexus", - "params": { - "placementId": 13144370 - }, - "crumbs": { - "pubcid": "ff4002c4-ce05-4a61-b4ef-45a3cd93991a" - } - } - ], - "sizes": [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - "transactionId": "6d275806-1943-4f3e-9cd5-624cbd05ad98" - } - ], - "adUnitCodes": [ - "div-gpt-ad-1460505748561-0" - ], - "bidderRequests": [ - { - "bidderCode": "appnexus", - "auctionId": "db377024-d866-4a24-98ac-5e430f881313", - "bidderRequestId": "155975c76e13b1", - "bids": [ - { - "bidder": "appnexus", - "params": { - "placementId": 13144370 - }, - "crumbs": { - "pubcid": "ff4002c4-ce05-4a61-b4ef-45a3cd93991a" - }, - "mediaTypes": { - "banner": { - "sizes": [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - "adUnitCode": "div-gpt-ad-1460505748561-0", - "transactionId": "6d275806-1943-4f3e-9cd5-624cbd05ad98", - "sizes": [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - "bidId": "263efc09896d0c", - "bidderRequestId": "155975c76e13b1", - "auctionId": "db377024-d866-4a24-98ac-5e430f881313", - "src": "client", - "bidRequestsCount": 1, - "bidderRequestsCount": 1, - "bidderWinsCount": 0 - } - ], - "auctionStart": 1576823893836, - "timeout": 1000, - "refererInfo": { - "referer": "http://observer.com/integrationExamples/gpt/hello_world.html", - "reachedTop": true, - "numIframes": 0, - "stack": [ - "http://observer.com/integrationExamples/gpt/hello_world.html" - ] - }, - "start": 1576823893838 - }, - { - "bidderCode": "ix", - "auctionId": "db377024-d866-4a24-98ac-5e430f881313", - "bidderRequestId": "181df4d465699c", - "bids": [ - { - "bidder": "ix", - "params": { - "placementId": 13144370 - }, - "crumbs": { - "pubcid": "ff4002c4-ce05-4a61-b4ef-45a3cd93991a" - }, - "mediaTypes": { - "banner": { - "sizes": [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - "adUnitCode": "div-gpt-ad-1460505748561-0", - "transactionId": "6d275806-1943-4f3e-9cd5-624cbd05ad98", - "sizes": [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - "bidId": "9424dea605368f", - "bidderRequestId": "181df4d465699c", - "auctionId": "db377024-d866-4a24-98ac-5e430f881313", - "src": "client", - "bidRequestsCount": 1, - "bidderRequestsCount": 1, - "bidderWinsCount": 0 - } - ], - "auctionStart": 1576823893836, - "timeout": 1000, - "refererInfo": { - "referer": "http://observer.com/integrationExamples/gpt/hello_world.html", - "reachedTop": true, - "numIframes": 0, - "stack": [ - "http://observer.com/integrationExamples/gpt/hello_world.html" - ] - }, - "start": 1576823893838 - } - ], - "noBids": [], - "bidsReceived": [], - "winningBids": [], - "timeout": 1000, - "host": "localhost:9876", - "path": "/context.html", - "search": "" - }, - "initOptions": { - "pubId": "1", - "pubKey": "ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==", - "hostName": "us-central1-quikr-ebay.cloudfunctions.net", - "pathName": "/prebid-analytics" - } - }; - - const expectedAfterBidWon = { - 'bidWon': { - 'bidderCode': 'appnexus', - 'bidId': '263efc09896d0c', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'auctionId': 'db377024-d866-4a24-98ac-5e430f881313', - 'creativeId': 96846035, - 'currency': 'USD', - 'cpm': 0.5, - 'netRevenue': true, - 'renderedSize': '300x250', - 'mediaType': 'banner', - 'statusMessage': 'Bid available', - 'status': 'rendered', - 'renderStatus': 4, - 'timeToRespond': 212, - 'requestTimestamp': 1576823893838, - 'responseTimestamp': 1576823894050, - "host": "localhost", - "path": "/context.html", - "search": "", - }, - 'initOptions': initOptions - } - - adapterManager.registerAnalyticsAdapter({ - code: 'tercept', - adapter: terceptAnalyticsAdapter - }); - - beforeEach(function () { - adapterManager.enableAnalytics({ - provider: 'tercept', - options: initOptions - }); - }); - - afterEach(function () { - terceptAnalyticsAdapter.disableAnalytics(); - }); - - it('builds and sends auction data', function () { - // Step 1: Send auction init event - events.emit(EVENTS.AUCTION_INIT, prebidEvent['auctionInit']); - - // Step 2: Send bid requested events - events.emit(EVENTS.BID_REQUESTED, prebidEvent['bidRequested']); - events.emit(EVENTS.BID_REQUESTED, prebidEvent['bidRequested2']); - - // Step 3: Send bid response event - events.emit(EVENTS.BID_RESPONSE, prebidEvent['bidResponse']); - - // Step 4: Send no bid response event - events.emit(EVENTS.NO_BID, prebidEvent['noBid']); - - // Step 5: Send bid time out event - events.emit(EVENTS.BID_TIMEOUT, prebidEvent['bidTimeout']); - - // Step 6: Send auction end event - events.emit(EVENTS.AUCTION_END, prebidEvent['auctionEnd']); - - expect(server.requests.length).to.equal(1); - - const realAfterBid = JSON.parse(server.requests[0].requestBody); - - expect(realAfterBid).to.deep.equal(expectedAfterBid); - - // Step 7: Send auction bid won event - events.emit(EVENTS.BID_WON, prebidEvent['bidWon']); - - expect(server.requests.length).to.equal(2); - - const winEventData = JSON.parse(server.requests[1].requestBody); - - expect(winEventData).to.deep.equal(expectedAfterBidWon); - }); - }); -}); diff --git a/test/spec/modules/theAdxBidAdapter_spec.js b/test/spec/modules/theAdxBidAdapter_spec.js deleted file mode 100644 index fd2a306ca..000000000 --- a/test/spec/modules/theAdxBidAdapter_spec.js +++ /dev/null @@ -1,752 +0,0 @@ -import { - expect -} from 'chai'; -import { - spec, - internals -} from 'modules/theAdxBidAdapter.js'; -import { - newBidder -} from 'src/adapters/bidderFactory.js'; - -describe('TheAdxAdapter', function () { - const adapter = newBidder(spec); - - describe('getUserSyncs', () => { - const USER_SYNC_IFRAME_URL = 'https://ssp.theadx.com/async_usersync_iframe.html' - const USER_SYNC_IMAGE_URL = 'https://ssp.theadx.com/async_usersync_image.gif' - - expect(spec.getUserSyncs({ - iframeEnabled: true, - pixelEnabled: true, - }, [{ - body: { - ext: { - sync: { - iframe: [USER_SYNC_IFRAME_URL], - image: [USER_SYNC_IMAGE_URL], - } - } - } - }])).to.deep.equal([{ - type: 'iframe', - url: USER_SYNC_IFRAME_URL - }, - { - type: 'image', - url: USER_SYNC_IMAGE_URL - }, - ]); - }); - - describe('bid validator', function () { - it('rejects a bid that is missing the placementId', function () { - const testBid = {}; - expect(spec.isBidRequestValid(testBid)).to.be.false; - }); - - it('accepts a bid with all the expected parameters', function () { - const testBid = { - params: { - pid: '1', - tagId: '1', - } - }; - - expect(spec.isBidRequestValid(testBid)).to.be.true; - }); - }); - - describe('request builder', function () { - // Taken from the docs, so used as much as is valid - const sampleBidRequest = { - 'bidder': 'tests', - 'bidId': '51ef8751f9aead', - 'params': { - 'pid': '1', - 'tagId': '1', - }, - 'adUnitCode': 'div-gpt-ad-sample', - 'transactionId': 'd7b773de-ceaa-484d-89ca-d9f51b8d61ec', - 'sizes': [ - [300, 250] - ], - 'bidderRequestId': '418b37f85e772c', - 'auctionId': '18fd8b8b0bd757', - 'mediaTypes': { - banner: { - 'sizes': [ - [320, 50], - [300, 250], - [300, 600] - ] - } - }, - userId: { - uid2: { id: 'sample-uid2' }, - id5id: { - 'uid': 'sample-id5id', - 'ext': { - 'linkType': 'abc' - } - }, - netId: 'sample-netid', - sharedid: { - 'id': 'sample-sharedid', - }, - - }, - }; - - const sampleBidderRequest = { - bidderRequestId: 'sample', - refererInfo: { - canonicalUrl: 'https://domain.com/to', - referer: 'https://domain.com/from' - } - } - - it('successfully generates a URL', function () { - const placementId = '1'; - - const bidRequests = [sampleBidRequest]; - - const results = spec.buildRequests(bidRequests, sampleBidderRequest); - const result = results.pop(); - - expect(result.url).to.not.be.undefined; - expect(result.url).to.not.be.null; - - expect(result.url).to.include('tagid=' + placementId); - }); - - it('uses the bidId id as the openRtb request ID', function () { - const bidId = '51ef8751f9aead'; - - const bidRequests = [ - sampleBidRequest - ]; - - const results = spec.buildRequests(bidRequests, sampleBidderRequest); - const result = results.pop(); - - // Double encoded JSON - const payload = JSON.parse(result.data); - - expect(payload).to.not.be.null; - expect(payload.id).to.equal(bidId); - }); - - it('generates the device payload as expected', function () { - const bidRequests = [ - sampleBidRequest - ]; - - const results = spec.buildRequests(bidRequests, sampleBidderRequest); - const result = results.pop(); - - // Double encoded JSON - const payload = JSON.parse(result.data); - - expect(payload).to.not.be.null; - const userData = payload.user; - - expect(userData).to.not.be.null; - }); - - it('generates multiple requests with single imp bodies', function () { - const SECOND_PLACEMENT_ID = '2'; - const firstBidRequest = JSON.parse(JSON.stringify(sampleBidRequest)); - const secondBidRequest = JSON.parse(JSON.stringify(sampleBidRequest)); - secondBidRequest.params.tagId = SECOND_PLACEMENT_ID; - - const bidRequests = [ - firstBidRequest, - secondBidRequest - ]; - - const results = spec.buildRequests(bidRequests, sampleBidderRequest); - - expect(results instanceof Array).to.be.true; - expect(results.length).to.equal(2); - - const firstRequest = results[0]; - - // Double encoded JSON - const firstPayload = JSON.parse(firstRequest.data); - - expect(firstPayload).to.not.be.null; - expect(firstPayload.imp).to.not.be.null; - expect(firstPayload.imp.length).to.equal(1); - - expect(firstRequest.url).to.not.be.null; - expect(firstRequest.url.indexOf('tagid=1')).to.be.gt(0); - - const secondRequest = results[1]; - - // Double encoded JSON - const secondPayload = JSON.parse(secondRequest.data); - - expect(secondPayload).to.not.be.null; - expect(secondPayload.imp).to.not.be.null; - expect(secondPayload.imp.length).to.equal(1); - - expect(secondRequest.url).to.not.be.null; - expect(secondRequest.url.indexOf(`tagid=${SECOND_PLACEMENT_ID}`)).to.be.gte(0); - }); - - it('generates a banner request as expected', function () { - // clone the sample for stability - const localBidRequest = JSON.parse(JSON.stringify(sampleBidRequest)); - - const results = spec.buildRequests([localBidRequest], sampleBidderRequest); - const result = results.pop(); - - // Double encoded JSON - const payload = JSON.parse(result.data); - - expect(payload).to.not.be.null; - - const imps = payload.imp; - - const firstImp = imps[0]; - - expect(firstImp.banner).to.not.be.null; - - const bannerData = firstImp.banner; - - expect(bannerData.w).to.equal(320); - expect(bannerData.h).to.equal(50); - }); - - it('generates a banner request using a singular adSize instead of an array', function () { - // clone the sample for stability - const localBidRequest = JSON.parse(JSON.stringify(sampleBidRequest)); - localBidRequest.sizes = [320, 50]; - localBidRequest.mediaTypes = { - banner: {} - }; - - const results = spec.buildRequests([localBidRequest], sampleBidderRequest); - const result = results.pop(); - - // Double encoded JSON - const payload = JSON.parse(result.data); - - expect(payload).to.not.be.null; - - const imps = payload.imp; - - const firstImp = imps[0]; - - expect(firstImp.banner).to.not.be.null; - - const bannerData = firstImp.banner; - - expect(bannerData.w).to.equal(320); - expect(bannerData.h).to.equal(50); - }); - - it('fails gracefully on an invalid size', function () { - // clone the sample for stability - const localBidRequest = JSON.parse(JSON.stringify(sampleBidRequest)); - localBidRequest.sizes = ['x', 'w']; - - localBidRequest.mediaTypes = { - banner: { - sizes: ['y', 'z'] - } - }; - - const results = spec.buildRequests([localBidRequest], sampleBidderRequest); - const result = results.pop(); - - // Double encoded JSON - const payload = JSON.parse(result.data); - - expect(payload).to.not.be.null; - - const imps = payload.imp; - - const firstImp = imps[0]; - - expect(firstImp.banner).to.not.be.null; - - const bannerData = firstImp.banner; - - expect(bannerData.w).to.equal(null); - expect(bannerData.h).to.equal(null); - }); - - it('generates a video request as expected', function () { - // clone the sample for stability - const localBidRequest = JSON.parse(JSON.stringify(sampleBidRequest)); - - localBidRequest.mediaTypes = { - video: { - sizes: [ - [326, 256] - ] - } - }; - - const results = spec.buildRequests([localBidRequest], sampleBidderRequest); - const result = results.pop(); - - // Double encoded JSON - const payload = JSON.parse(result.data); - - expect(payload).to.not.be.null; - - const imps = payload.imp; - - const firstImp = imps[0]; - - expect(firstImp.video).to.not.be.null; - - const videoData = firstImp.video; - expect(videoData.w).to.equal(326); - expect(videoData.h).to.equal(256); - }); - - it('generates a native request as expected', function () { - // clone the sample for stability - const localBidRequest = JSON.parse(JSON.stringify(sampleBidRequest)); - - localBidRequest.mediaTypes = { - native: { - image: { - required: false, - sizes: [100, 50] - }, - title: { - required: false, - len: 140 - }, - sponsoredBy: { - required: false - }, - clickUrl: { - required: false - }, - body: { - required: false - }, - icon: { - required: false, - sizes: [50, 50] - }, - } - }; - - const results = spec.buildRequests([localBidRequest], sampleBidderRequest); - const result = results.pop(); - - // Double encoded JSON - const payload = JSON.parse(result.data); - - expect(payload).to.not.be.null; - - const imps = payload.imp; - - const firstImp = imps[0]; - - expect(firstImp.native).to.not.be.null; - }); - - it('propagates the mediaTypes object in the built request', function () { - const localBidRequest = JSON.parse(JSON.stringify(sampleBidRequest)); - - localBidRequest.mediaTypes = { - video: {} - }; - - const results = spec.buildRequests([localBidRequest], sampleBidderRequest); - const result = results.pop(); - - const mediaTypes = result.mediaTypes; - - expect(mediaTypes).to.not.be.null; - expect(mediaTypes).to.not.be.undefined; - expect(mediaTypes.video).to.not.be.null; - expect(mediaTypes.video).to.not.be.undefined; - }); - - it('add eids to request', function () { - const localBidRequest = JSON.parse(JSON.stringify(sampleBidRequest)); - - const results = spec.buildRequests([localBidRequest], sampleBidderRequest); - const result = results.pop(); - const payload = JSON.parse(result.data); - expect(payload).to.not.be.null; - expect(payload.ext).to.not.be.null; - - expect(payload.ext.uid2).to.not.be.null; - expect(payload.ext.uid2.length).to.greaterThan(0); - - expect(payload.ext.id5id).to.not.be.null; - expect(payload.ext.id5id.length).to.greaterThan(0); - expect(payload.ext.id5_linktype).to.not.be.null; - expect(payload.ext.id5_linktype.length).to.greaterThan(0); - - expect(payload.ext.netid).to.not.be.null; - expect(payload.ext.netid.length).to.greaterThan(0); - - expect(payload.ext.sharedid).to.not.be.null; - expect(payload.ext.sharedid.length).to.greaterThan(0); - }); - }); - - describe('response interpreter', function () { - it('returns an empty array when no bids present', function () { - // an empty JSON body indicates no ad was found - - const result = spec.interpretResponse({ - body: '' - }, {}) - - expect(result).to.eql([]); - }); - - it('gracefully fails when a non-JSON body is present', function () { - const result = spec.interpretResponse({ - body: 'THIS IS NOT ' - }, {}) - - expect(result).to.eql([]); - }); - - it('returns a valid bid response on sucessful banner request', function () { - const incomingRequestId = 'XXtestingXX'; - const responsePrice = 3.14 - - const responseCreative = 'sample_creative&{FOR_COVARAGE}'; - - const responseCreativeId = '274'; - const responseCurrency = 'TRY'; - - const responseWidth = 300; - const responseHeight = 250; - const responseTtl = 213; - - const sampleResponse = { - id: '66043f5ca44ecd8f8769093b1615b2d9', - seatbid: [{ - bid: [{ - id: 'c21bab0e-7668-4d8f-908a-63e094c09197', - impid: '1', - price: responsePrice, - adid: responseCreativeId, - crid: responseCreativeId, - adm: responseCreative, - adomain: [ - 'www.domain.com' - ], - cid: '274', - attr: [], - w: responseWidth, - h: responseHeight, - ext: { - ttl: responseTtl - } - }], - seat: '201', - group: 0 - }], - bidid: 'c21bab0e-7668-4d8f-908a-63e094c09197', - cur: responseCurrency - }; - - const sampleRequest = { - bidId: incomingRequestId, - mediaTypes: { - banner: {} - }, - requestId: incomingRequestId - }; - const serverResponse = { - body: sampleResponse - } - const result = spec.interpretResponse(serverResponse, sampleRequest); - - expect(result.length).to.equal(1); - - const processedBid = result[0]; - - // expect(processedBid.requestId).to.equal(incomingRequestId); - expect(processedBid.cpm).to.equal(responsePrice); - expect(processedBid.width).to.equal(responseWidth); - expect(processedBid.height).to.equal(responseHeight); - expect(processedBid.ad).to.equal(responseCreative); - expect(processedBid.ttl).to.equal(responseTtl); - expect(processedBid.creativeId).to.equal(responseCreativeId); - expect(processedBid.netRevenue).to.equal(true); - expect(processedBid.currency).to.equal(responseCurrency); - }); - - it('returns a valid deal bid response on sucessful banner request with deal', function () { - const incomingRequestId = 'XXtestingXX'; - const responsePrice = 3.14 - - const responseCreative = 'sample_creative&{FOR_COVARAGE}'; - - const responseCreativeId = '274'; - const responseCurrency = 'TRY'; - - const responseWidth = 300; - const responseHeight = 250; - const responseTtl = 213; - const dealId = 'theadx_deal_id'; - - const sampleResponse = { - id: '66043f5ca44ecd8f8769093b1615b2d9', - seatbid: [{ - bid: [{ - id: 'c21bab0e-7668-4d8f-908a-63e094c09197', - dealid: 'theadx_deal_id', - impid: '1', - price: responsePrice, - adid: responseCreativeId, - crid: responseCreativeId, - adm: responseCreative, - adomain: [ - 'www.domain.com' - ], - cid: '274', - attr: [], - w: responseWidth, - h: responseHeight, - ext: { - ttl: responseTtl - } - }], - seat: '201', - group: 0 - }], - bidid: 'c21bab0e-7668-4d8f-908a-63e094c09197', - cur: responseCurrency - }; - - const sampleRequest = { - bidId: incomingRequestId, - mediaTypes: { - banner: {} - }, - requestId: incomingRequestId, - deals: [{ id: dealId }] - }; - const serverResponse = { - body: sampleResponse - } - const result = spec.interpretResponse(serverResponse, sampleRequest); - - expect(result.length).to.equal(1); - - const processedBid = result[0]; - - // expect(processedBid.requestId).to.equal(incomingRequestId); - expect(processedBid.cpm).to.equal(responsePrice); - expect(processedBid.width).to.equal(responseWidth); - expect(processedBid.height).to.equal(responseHeight); - expect(processedBid.ad).to.equal(responseCreative); - expect(processedBid.ttl).to.equal(responseTtl); - expect(processedBid.creativeId).to.equal(responseCreativeId); - expect(processedBid.netRevenue).to.equal(true); - expect(processedBid.currency).to.equal(responseCurrency); - expect(processedBid.dealId).to.equal(dealId); - }); - - it('returns an valid bid response on sucessful video request', function () { - const incomingRequestId = 'XXtesting-275XX'; - const responsePrice = 6 - const vast_url = 'https://theadx.com/vast?rid=a8ae0b48-a8db-4220-ba0c-7458f452b1f5&{FOR_COVARAGE}' - - const responseCreativeId = '1556'; - const responseCurrency = 'TRY'; - - const responseWidth = 284; - const responseHeight = 285; - const responseTtl = 286; - - const sampleResponse = { - id: '1234567890', - seatbid: [{ - bid: [{ - id: 'a8ae0b48-a8db-4220-ba0c-7458f452b1f5', - impid: '1', - price: responsePrice, - adid: responseCreativeId, - crid: responseCreativeId, - cid: '270', - attr: [], - w: responseWidth, - h: responseHeight, - ext: { - vast_url: vast_url, - ttl: responseTtl - } - }], - seat: '201', - group: 0 - }], - bidid: 'a8ae0b48-a8db-4220-ba0c-7458f452b1f5', - cur: 'TRY' - }; - - const sampleRequest = { - bidId: incomingRequestId, - mediaTypes: { - video: {} - }, - requestId: incomingRequestId - }; - - const result = spec.interpretResponse({ - body: sampleResponse - }, - sampleRequest - ); - - expect(result.length).to.equal(1); - - const processedBid = result[0]; - // expect(processedBid.requestId).to.equal(incomingRequestId); - expect(processedBid.cpm).to.equal(responsePrice); - expect(processedBid.width).to.equal(responseWidth); - expect(processedBid.height).to.equal(responseHeight); - expect(processedBid.ad).to.equal(null); - expect(processedBid.ttl).to.equal(responseTtl); - expect(processedBid.creativeId).to.equal(responseCreativeId); - expect(processedBid.netRevenue).to.equal(true); - expect(processedBid.currency).to.equal(responseCurrency); - expect(processedBid.vastUrl).to.equal(vast_url); - }); - - it('returns an valid bid response on sucessful native request', function () { - const incomingRequestId = 'XXtesting-275XX'; - const responsePrice = 6 - const nurl = 'https://app.theadx.com/ixc?rid=02aefd80-2df9-11e9-896d-d33384d77f5c&time=v-1549888312715&sp=1WzMjcRpeyk%3D'; - const linkUrl = 'https%3A%2F%2Fapp.theadx.com%2Fgclick%3Frid%3D02aefd80-2df9-11e9-896d-d33384d77f5c%26url%3Dhttps%253A%252F%252Fwww.theadx.com%252Ftr%252Fhedeflemeler' - const responseCreativeId = '1556'; - const responseCurrency = 'TRY'; - - const responseTtl = 286; - - const sampleResponse = { - id: '1234567890', - seatbid: [{ - bid: [{ - id: 'a8ae0b48-a8db-4220-ba0c-7458f452b1f5', - impid: '1', - nurl: nurl, - price: responsePrice, - adid: responseCreativeId, - crid: responseCreativeId, - cid: '270', - attr: [], - ext: { - ttl: responseTtl, - native: { - ver: 1, - link: { - url: linkUrl - }, - assets: [{ - id: 3, - img: { - url: 'https://ads.theadx.com/winwords/120/17508/154712307258.73.jpg', - h: 627, - w: 1200 - } - }, { - id: 0, - title: { - ext: 'SELF-MANAGED DSP' - } - }, { - id: 5, - data: { - value: 'Sponsored by Theadx' - } - }, { - id: 4, - data: { - value: 'Gerçek Zamanlı Self-Managed DSP ile kampanya oluşturmak ve yönetmek çok kolay ' - } - }, { - id: 2, - img: { - url: 'https://ads.theadx.com/winwords/120/17508/154712307258.74.png', - h: 128, - w: 128 - } - }] - }, - - rid: '02ac3e60-2df9-11e9-9d09-bba751e172da', - impu: 'https://ssp.theadx.com/ixc?rid=02ac3e60-2df9-11e9-9d09-bba751e172da&time=1549888312719&tid=1', - cliu: 'https://ssp.theadx.com/click?trid=02ac3e60-2df9-11e9-9d09-bba751e172da' - - } - }], - seat: '201', - group: 0 - }], - bidid: 'a8ae0b48-a8db-4220-ba0c-7458f452b1f5', - cur: 'TRY' - }; - - const sampleRequest = { - bidId: incomingRequestId, - mediaTypes: { - native: { - image: { - required: false, - sizes: [100, 50] - }, - title: { - required: false, - len: 140 - }, - sponsoredBy: { - required: false - }, - clickUrl: { - required: false - }, - body: { - required: false - }, - icon: { - required: false, - sizes: [50, 50] - } - - }, - }, - requestId: incomingRequestId - }; - - const result = spec.interpretResponse({ - body: sampleResponse - }, - sampleRequest - ); - - expect(result.length).to.equal(1); - - const processedBid = result[0]; - // expect(processedBid.requestId).to.equal(incomingRequestId); - expect(processedBid.cpm).to.equal(responsePrice); - expect(processedBid.width).to.equal(0); - expect(processedBid.height).to.equal(0); - expect(processedBid.ad).to.equal(null); - expect(processedBid.ttl).to.equal(responseTtl); - expect(processedBid.creativeId).to.equal(responseCreativeId); - expect(processedBid.netRevenue).to.equal(true); - expect(processedBid.currency).to.equal(responseCurrency); - expect(processedBid.native.impressionTrackers[0]).to.equal(nurl); - expect(processedBid.native.clickUrl).to.equal(linkUrl); - }); - }); -}); diff --git a/test/spec/modules/themoneytizerBidAdapter_spec.js b/test/spec/modules/themoneytizerBidAdapter_spec.js deleted file mode 100644 index d07a2eeaf..000000000 --- a/test/spec/modules/themoneytizerBidAdapter_spec.js +++ /dev/null @@ -1,283 +0,0 @@ -import { spec } from '../../../modules/themoneytizerBidAdapter.js' - -const ENDPOINT_URL = 'https://ads.biddertmz.com/m/'; - -const VALID_BID_BANNER = { - bidder: 'themoneytizer', - ortb2Imp: { - ext: {} - }, - params: { - pid: 123456, - }, - mediaTypes: { - banner: { - sizes: [[970, 250]] - } - }, - adUnitCode: 'ad-unit-code', - bidId: '82376dbe72be72', - timeout: 3000, - ortb2: {}, - userIdAsEids: [], - auctionId: '123456-abcdef-7890', - schain: {}, -} - -const VALID_TEST_BID_BANNER = { - bidder: 'themoneytizer', - ortb2Imp: { - ext: {} - }, - params: { - pid: 123456, - test: 1, - baseUrl: 'https://custom-endpoint.biddertmz.com/m/' - }, - mediaTypes: { - banner: { - sizes: [[970, 250]] - } - }, - adUnitCode: 'ad-unit-code', - bidId: '82376dbe72be72', - timeout: 3000, - ortb2: {}, - userIdAsEids: [], - auctionId: '123456-abcdef-7890', - schain: {} -} - -const BIDDER_REQUEST_BANNER = { - bids: [VALID_BID_BANNER, VALID_TEST_BID_BANNER], - refererInfo: { - topmostLocation: 'http://prebid.org/', - canonicalUrl: 'http://prebid.org/' - }, - gdprConsent: { - gdprApplies: true, - consentString: 'abcdefghxyz' - } -} - -const SERVER_RESPONSE = { - c_sync: { - status: 'ok', - bidder_status: [ - { - bidder: 'bidder-A', - usersync: { - url: 'https://syncurl.com', - type: 'redirect' - } - }, - { - bidder: 'bidder-B', - usersync: { - url: 'https://syncurl2.com', - type: 'image' - } - } - ] - }, - bid: { - requestId: '17750222eb16825', - cpm: 0.098, - currency: 'USD', - width: 300, - height: 600, - creativeId: '44368852571075698202250', - dealId: '', - netRevenue: true, - ttl: 5, - ad: '

This is an ad

', - mediaType: 'banner', - } -}; - -describe('The Moneytizer Bidder Adapter', function () { - describe('codes', function () { - it('should return a bidder code of themoneytizer', function () { - expect(spec.code).to.equal('themoneytizer'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true for a bid with all required fields', function () { - const validBid = spec.isBidRequestValid(VALID_BID_BANNER); - expect(validBid).to.be.true; - }); - - it('should return false for an invalid bid', function () { - const invalidBid = spec.isBidRequestValid(null); - expect(invalidBid).to.be.false; - }); - - it('should return false when params are incomplete', function () { - const bidWithIncompleteParams = { - ...VALID_BID_BANNER, - params: {} - }; - expect(spec.isBidRequestValid(bidWithIncompleteParams)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let requests, request, requests_test, request_test; - - before(function () { - requests = spec.buildRequests([VALID_BID_BANNER], BIDDER_REQUEST_BANNER); - request = requests[0]; - - requests_test = spec.buildRequests([VALID_TEST_BID_BANNER], BIDDER_REQUEST_BANNER); - request_test = requests_test[0]; - }); - - it('should build a request array for valid bids', function () { - expect(requests).to.be.an('array').that.is.not.empty; - }); - - it('should build a request array for valid test bids', function () { - expect(requests_test).to.be.an('array').that.is.not.empty; - }); - - it('should build a request with the correct method, URL, and data type', function () { - expect(request).to.include.keys(['method', 'url', 'data']); - expect(request.method).to.equal('POST'); - expect(request.url).to.equal(ENDPOINT_URL); - expect(request.data).to.be.a('string'); - }); - - it('should build a test request with the correct method, URL, and data type', function () { - expect(request_test).to.include.keys(['method', 'url', 'data']); - expect(request_test.method).to.equal('POST'); - expect(request_test.url).to.equal(VALID_TEST_BID_BANNER.params.baseUrl); - expect(request_test.data).to.be.a('string'); - }); - - describe('Payload structure', function () { - let payload; - - before(function () { - payload = JSON.parse(request.data); - }); - - it('should have correct payload structure', function () { - expect(payload).to.be.an('object'); - expect(payload.size).to.be.an('object'); - expect(payload.params).to.be.an('object'); - }); - }); - - describe('Payload structure optional params', function () { - let payload; - - before(function () { - payload = JSON.parse(request_test.data); - }); - - it('should have correct params', function () { - expect(payload.params.pid).to.equal(123456); - }); - - it('should have correct referer info', function () { - expect(payload.referer).to.equal(BIDDER_REQUEST_BANNER.refererInfo.topmostLocation); - expect(payload.referer_canonical).to.equal(BIDDER_REQUEST_BANNER.refererInfo.canonicalUrl); - }); - - it('should have correct GDPR consent', function () { - expect(payload.consent_string).to.equal(BIDDER_REQUEST_BANNER.gdprConsent.consentString); - expect(payload.consent_required).to.equal(BIDDER_REQUEST_BANNER.gdprConsent.gdprApplies); - }); - }); - }); - - describe('interpretResponse', function () { - let bidResponse, receivedBid; - const responseBody = SERVER_RESPONSE; - - before(function () { - receivedBid = responseBody.bid; - const response = { body: responseBody }; - bidResponse = spec.interpretResponse(response, null); - }); - - it('should not return an empty response', function () { - expect(bidResponse).to.not.be.empty; - }); - - describe('Parsed Bid Object', function () { - let bid; - - before(function () { - bid = bidResponse[0]; - }); - - it('should not be empty', function () { - expect(bid).to.not.be.empty; - }); - - it('should correctly interpret ad markup', function () { - expect(bid.ad).to.equal(receivedBid.ad); - }); - - it('should correctly interpret CPM', function () { - expect(bid.cpm).to.equal(receivedBid.cpm); - }); - - it('should correctly interpret dimensions', function () { - expect(bid.height).to.equal(receivedBid.height); - expect(bid.width).to.equal(receivedBid.width); - }); - - it('should correctly interpret request ID', function () { - expect(bid.requestId).to.equal(receivedBid.requestId); - }); - }); - }); - - describe('onTimeout', function () { - const timeoutData = [{ - timeout: null - }]; - - it('should exists and be a function', () => { - expect(spec.onTimeout).to.exist.and.to.be.a('function'); - }); - it('should include timeoutData', function () { - expect(spec.onTimeout(timeoutData)).to.be.undefined; - }) - }); - - describe('getUserSyncs', function () { - const response = { body: SERVER_RESPONSE }; - - it('should have empty user sync with iframeEnabled to false and pixelEnabled to false', function () { - const result = spec.getUserSyncs({ iframeEnabled: false, pixelEnabled: false }, [response]); - - expect(result).to.be.empty; - }); - - it('should have user sync with iframeEnabled to true', function () { - const result = spec.getUserSyncs({ iframeEnabled: true }, [response]); - - expect(result).to.not.be.empty; - expect(result[0].type).to.equal('image'); - expect(result[0].url).to.equal(SERVER_RESPONSE.c_sync.bidder_status[0].usersync.url); - }); - - it('should have user sync with pixelEnabled to true', function () { - const result = spec.getUserSyncs({ pixelEnabled: true }, [response]); - - expect(result).to.not.be.empty; - expect(result[0].type).to.equal('image'); - expect(result[0].url).to.equal(SERVER_RESPONSE.c_sync.bidder_status[0].usersync.url); - }); - - it('should transform type redirect into image', function () { - const result = spec.getUserSyncs({ iframeEnabled: true }, [response]); - - expect(result[1].type).to.equal('image'); - }); - }); -}); diff --git a/test/spec/modules/timeoutRtdProvider_spec.js b/test/spec/modules/timeoutRtdProvider_spec.js deleted file mode 100644 index b4231c3db..000000000 --- a/test/spec/modules/timeoutRtdProvider_spec.js +++ /dev/null @@ -1,338 +0,0 @@ -import { timeoutRtdFunctions, timeoutSubmodule } from '../../../modules/timeoutRtdProvider.js' -import { expect } from 'chai'; -import * as ajax from 'src/ajax.js'; -import * as prebidGlobal from 'src/prebidGlobal.js'; - -const DEFAULT_USER_AGENT = window.navigator.userAgent; -const DEFAULT_CONNECTION = window.navigator.connection; - -const PC_USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246'; -const MOBILE_USER_AGENT = 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Version/10.0 Mobile/14E304 Safari/602.1'; -const TABLET_USER_AGENT = 'Mozilla/5.0 (iPad; CPU OS 12_2 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148'; - -function resetUserAgent() { - window.navigator.__defineGetter__('userAgent', () => DEFAULT_USER_AGENT); -}; - -function setUserAgent(userAgent) { - window.navigator.__defineGetter__('userAgent', () => userAgent); -} - -function resetConnection() { - window.navigator.__defineGetter__('connection', () => DEFAULT_CONNECTION); -} -function setConnectionType(connectionType) { - window.navigator.__defineGetter__('connection', () => { return {'type': connectionType} }); -} - -describe('getDeviceType', () => { - afterEach(() => { - resetUserAgent(); - }); - - [ - // deviceType, userAgent, deviceTypeNum - ['pc', PC_USER_AGENT, 2], - ['mobile', MOBILE_USER_AGENT, 4], - ['tablet', TABLET_USER_AGENT, 5], - ].forEach(function(args) { - const [deviceType, userAgent, deviceTypeNum] = args; - it(`should be able to recognize ${deviceType} devices`, () => { - setUserAgent(userAgent); - const res = timeoutRtdFunctions.getDeviceType(); - expect(res).to.equal(deviceTypeNum) - }) - }) -}); - -describe('getConnectionSpeed', () => { - afterEach(() => { - resetConnection(); - }); - [ - // connectionType, connectionSpeed - ['slow-2g', 'slow'], - ['2g', 'slow'], - ['3g', 'medium'], - ['bluetooth', 'fast'], - ['cellular', 'fast'], - ['ethernet', 'fast'], - ['wifi', 'fast'], - ['wimax', 'fast'], - ['4g', 'fast'], - ['not known', 'unknown'], - [undefined, 'unknown'], - ].forEach(function(args) { - const [connectionType, connectionSpeed] = args; - it(`should be able to categorize connection speed when the connection type is ${connectionType}`, () => { - setConnectionType(connectionType); - const res = timeoutRtdFunctions.getConnectionSpeed(); - expect(res).to.equal(connectionSpeed) - }) - }) -}); - -describe('Timeout modifier calculations', () => { - let sandbox; - beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should be able to detect video ad units', () => { - let adUnits = [] - let res = timeoutRtdFunctions.checkVideo(adUnits); - expect(res).to.be.false; - - adUnits = [{ - mediaTypes: { - video: [] - } - }]; - res = timeoutRtdFunctions.checkVideo(adUnits); - expect(res).to.be.true; - - adUnits = [{ - mediaTypes: { - banner: [] - } - }]; - res = timeoutRtdFunctions.checkVideo(adUnits); - expect(res).to.be.false; - }); - - it('should calculate the timeout modifier for video', () => { - sandbox.stub(timeoutRtdFunctions, 'checkVideo').returns(true); - const rules = { - includesVideo: { - 'true': 200, - 'false': 50 - } - } - const res = timeoutRtdFunctions.calculateTimeoutModifier([], rules); - expect(res).to.equal(200) - }); - - it('should calculate the timeout modifier for connectionSpeed', () => { - sandbox.stub(timeoutRtdFunctions, 'getConnectionSpeed').returns('slow'); - const rules = { - connectionSpeed: { - 'slow': 200, - 'medium': 100, - 'fast': 50 - } - } - const res = timeoutRtdFunctions.calculateTimeoutModifier([], rules); - expect(res).to.equal(200); - }); - - it('should calculate the timeout modifier for deviceType', () => { - sandbox.stub(timeoutRtdFunctions, 'getDeviceType').returns(4); - const rules = { - deviceType: { - '2': 50, - '4': 100, - '5': 200 - }, - } - const res = timeoutRtdFunctions.calculateTimeoutModifier([], rules); - expect(res).to.equal(100) - }); - - it('should calculate the timeout modifier for ranged numAdunits', () => { - const rules = { - numAdUnits: { - '1-5': 100, - '6-10': 200, - '11-15': 300, - } - } - const adUnits = [1, 2, 3, 4, 5, 6]; - const res = timeoutRtdFunctions.calculateTimeoutModifier(adUnits, rules); - expect(res).to.equal(200) - }); - - it('should calculate the timeout modifier for exact numAdunits', () => { - const rules = { - numAdUnits: { - '1': 100, - '2': 200, - '3': 300, - '4-5': 400, - } - } - const adUnits = [1, 2]; - const res = timeoutRtdFunctions.calculateTimeoutModifier(adUnits, rules); - expect(res).to.equal(200); - }); - - it('should add up all the modifiers when all the rules are present', () => { - sandbox.stub(timeoutRtdFunctions, 'getConnectionSpeed').returns('slow'); - sandbox.stub(timeoutRtdFunctions, 'getDeviceType').returns(4); - const rules = { - connectionSpeed: { - 'slow': 200, - 'medium': 100, - 'fast': 50 - }, - deviceType: { - '2': 50, - '4': 100, - '5': 200 - }, - includesVideo: { - 'true': 200, - 'false': 50 - }, - numAdUnits: { - '1': 100, - '2': 200, - '3': 300, - '4-5': 400, - } - } - const res = timeoutRtdFunctions.calculateTimeoutModifier([{ - mediaTypes: { - video: [] - } - }], rules); - expect(res).to.equal(600); - }); -}); - -describe('Timeout RTD submodule', () => { - let sandbox; - beforeEach(() => { - sandbox = sinon.createSandbox(); - }); - - afterEach(() => { - sandbox.restore(); - }); - - it('should init successfully', () => { - expect(timeoutSubmodule.init()).to.equal(true); - }); - - it('should make a request to the endpoint url if it is provided, and handle the response', () => { - const response = '{"deviceType":{ "2": 50, "4": 100, "5": 200 }}' - const ajaxStub = sandbox.stub().callsFake(function (url, callbackObj) { - callbackObj.success(response); - }); - sandbox.stub(ajax, 'ajaxBuilder').callsFake(function () { return ajaxStub }); - - const reqBidsConfigObj = {} - const expectedLink = 'https://somelink.json' - const config = { - 'name': 'timeout', - 'params': { - 'endpoint': { - url: expectedLink - } - } - } - const handleTimeoutIncrementStub = sandbox.stub(timeoutRtdFunctions, 'handleTimeoutIncrement'); - timeoutSubmodule.getBidRequestData(reqBidsConfigObj, function() {}, config) - - expect(ajaxStub.calledWith(expectedLink)).to.be.true; - expect(handleTimeoutIncrementStub.calledWith(reqBidsConfigObj, JSON.parse(response))).to.be.true; - }); - - it('should make a request to the endpoint url and ignore the rules object if the endpoint is provided', () => { - const ajaxStub = sandbox.stub().callsFake((url, callbackObj) => {}); - sandbox.stub(ajax, 'ajaxBuilder').callsFake(() => ajaxStub); - const expectedLink = 'https://somelink.json' - const config = { - 'name': 'timeout', - 'params': { - 'endpoint': { - url: expectedLink - }, - 'rules': { - 'includesVideo': { - 'true': 200, - }, - } - } - } - timeoutSubmodule.getBidRequestData({}, function() {}, config); - expect(ajaxStub.calledWith(expectedLink)).to.be.true; - }); - - it('should use the rules object if there is no endpoint url', () => { - const config = { - 'name': 'timeout', - 'params': { - 'rules': { - 'includesVideo': { - 'true': 200, - }, - } - } - } - const handleTimeoutIncrementStub = sandbox.stub(timeoutRtdFunctions, 'handleTimeoutIncrement'); - const reqBidsConfigObj = {}; - timeoutSubmodule.getBidRequestData(reqBidsConfigObj, function() {}, config); - expect(handleTimeoutIncrementStub.calledWith(reqBidsConfigObj, config.params.rules)).to.be.true; - }); - - it('should exit quietly if no relevant timeout config is found', () => { - const callback = sandbox.stub() - const ajaxStub = sandbox.stub().callsFake((url, callbackObj) => {}); - sandbox.stub(ajax, 'ajaxBuilder').callsFake(function() { return ajaxStub }); - const handleTimeoutIncrementStub = sandbox.stub(timeoutRtdFunctions, 'handleTimeoutIncrement'); - - timeoutSubmodule.getBidRequestData({}, callback, {}); - - expect(handleTimeoutIncrementStub.called).to.be.false; - expect(callback.called).to.be.true; - expect(ajaxStub.called).to.be.false; - }); - - it('should be able to increment the timeout with the calculated timeout modifier', () => { - const baseTimeout = 100; - const getConfigStub = sandbox.stub().returns(baseTimeout); - sandbox.stub(prebidGlobal, 'getGlobal').callsFake(() => { - return { - getConfig: getConfigStub - } - }); - - const reqBidsConfigObj = {adUnits: [1, 2, 3]} - const addedTimeout = 400; - const rules = { - numAdUnits: { - '3-5': addedTimeout, - } - } - - timeoutRtdFunctions.handleTimeoutIncrement(reqBidsConfigObj, rules) - expect(reqBidsConfigObj.timeout).to.be.equal(baseTimeout + addedTimeout); - }); - - it('should be able to increment the timeout with the calculated timeout modifier when there are multiple matching rules', () => { - const baseTimeout = 100; - const getConfigStub = sandbox.stub().returns(baseTimeout); - sandbox.stub(prebidGlobal, 'getGlobal').callsFake(() => { - return { - getConfig: getConfigStub - } - }); - - const reqBidsConfigObj = {adUnits: [1, 2, 3]} - const addedTimeout = 400; - const rules = { - numAdUnits: { - '3-5': addedTimeout / 2, - }, - includesVideo: { - 'false': addedTimeout / 2, - } - } - timeoutRtdFunctions.handleTimeoutIncrement(reqBidsConfigObj, rules) - expect(reqBidsConfigObj.timeout).to.be.equal(baseTimeout + addedTimeout); - }); -}); diff --git a/test/spec/modules/tpmnBidAdapter_spec.js b/test/spec/modules/tpmnBidAdapter_spec.js deleted file mode 100644 index e099d9d59..000000000 --- a/test/spec/modules/tpmnBidAdapter_spec.js +++ /dev/null @@ -1,447 +0,0 @@ -import {spec, storage, VIDEO_RENDERER_URL} from 'modules/tpmnBidAdapter.js'; -import {generateUUID} from '../../../src/utils.js'; -import {expect} from 'chai'; -import * as utils from 'src/utils'; -import * as sinon from 'sinon'; -import 'modules/consentManagementTcf.js'; -import {addFPDToBidderRequest} from '../../helpers/fpd.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -const BIDDER_CODE = 'tpmn'; -const BANNER_BID = { - bidder: BIDDER_CODE, - params: { - inventoryId: 1 - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ], - }, - }, - adUnitCode: 'adUnitCode1', - bidId: 'bidId', - bidderRequestId: 'bidderRequestId', - auctionId: 'auctionId-56a2-4f71-9098-720a68f2f708', -}; - -const VIDEO_BID = { - bidder: BIDDER_CODE, - params: { - inventoryId: 1 - }, - mediaTypes: { - video: { - context: 'outstream', - api: [1, 2, 4, 6], - mimes: ['video/mp4'], - playbackmethod: [2, 4, 6], - playerSize: [[1024, 768]], - protocols: [3, 4, 7, 8, 10], - placement: 1, - plcmt: 1, - minduration: 0, - maxduration: 60, - startdelay: 0 - }, - }, - adUnitCode: 'adUnitCode1', - bidId: 'bidId', - bidderRequestId: 'bidderRequestId', - auctionId: 'auctionId-56a2-4f71-9098-720a68f2f708', -}; - -const BIDDER_REQUEST = { - auctionId: 'auctionId-56a2-4f71-9098-720a68f2f708', - bidderRequestId: 'bidderRequestId', - timeout: 500, - refererInfo: { - page: 'https://hello-world-page.com/', - domain: 'hello-world-page.com', - ref: 'http://example-domain.com/foo', - } -}; - -const BANNER_BID_RESPONSE = { - 'id': 'bidderRequestId', - 'bidId': 'bidid', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'id', - 'impid': 'bidId', - 'price': 0.18, - 'adm': '', - 'adid': '144762342', - 'burl': 'http://0.0.0.0:8181/burl', - 'adomain': [ - 'https://dummydomain.com' - ], - 'cid': 'cid', - 'crid': 'crid', - 'iurl': 'iurl', - 'cat': [], - 'w': 300, - 'h': 250 - } - ] - } - ], - 'cur': 'USD' -}; - -const VIDEO_BID_RESPONSE = { - 'id': 'bidderRequestId', - 'bidid': 'bidid', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'id', - 'impid': 'bidId', - 'price': 1.09, - 'adid': '144762342', - 'burl': 'http://0.0.0.0:8181/burl', - 'adm': '', - 'adomain': [ - 'https://dummydomain.com' - ], - 'cid': 'cid', - 'crid': 'crid', - 'iurl': 'iurl', - 'cat': [], - 'h': 768, - 'w': 1024 - } - ] - } - ], - 'cur': 'USD' -}; - -describe('tpmnAdapterTests', function () { - let sandbox = sinon.createSandbox(); - let getCookieStub; - beforeEach(function () { - getGlobal().bidderSettings = { - tpmn: { - storageAllowed: true - } - }; - sandbox = sinon.createSandbox(); - getCookieStub = sinon.stub(storage, 'getCookie'); - }); - - afterEach(function () { - sandbox.restore(); - getCookieStub.restore(); - getGlobal().bidderSettings = {}; - }); - - describe('isBidRequestValid()', function () { - it('should accept request if placementId is passed', function () { - const bid = { - bidder: BIDDER_CODE, - params: { - inventoryId: 123 - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should reject requests without params', function () { - const bid = { - bidder: BIDDER_CODE, - params: {} - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when required params found', () => { - expect(spec.isBidRequestValid(BANNER_BID)).to.equal(true); - expect(spec.isBidRequestValid(VIDEO_BID)).to.equal(true); - }); - }); - - describe('buildRequests()', function () { - it('should have gdpr data if applicable', async function () { - const bid = utils.deepClone(BANNER_BID); - - const req = await addFPDToBidderRequest(Object.assign({}, BIDDER_REQUEST, { - gdprConsent: { - consentString: 'consentString', - gdprApplies: true, - } - })); - const request = spec.buildRequests([bid], req)[0]; - - const payload = request.data; - expect(payload.user.ext).to.have.property('consent', req.gdprConsent.consentString); - expect(payload.regs.ext).to.have.property('gdpr', 1); - }); - - it('should properly forward ORTB blocking params', function () { - let bid = utils.deepClone(BANNER_BID); - bid = utils.mergeDeep(bid, { - params: { bcat: ['IAB1-1'], badv: ['example.com'], bapp: ['com.example'], battr: [1] }, - mediaTypes: { banner: { battr: [1] } } - }); - - const [request] = spec.buildRequests([bid], BIDDER_REQUEST); - - expect(request).to.exist.and.to.be.an('object'); - const payload = request.data; - expect(payload).to.have.deep.property('bcat', ['IAB1-1']); - expect(payload).to.have.deep.property('badv', ['example.com']); - expect(payload).to.have.deep.property('bapp', ['com.example']); - expect(payload.imp[0].banner).to.have.deep.property('battr', [1]); - }); - - context('when mediaType is banner', function () { - it('should build correct request for banner bid with both w, h', () => { - const bid = utils.deepClone(BANNER_BID); - - const [request] = spec.buildRequests([bid], BIDDER_REQUEST); - const requestData = request.data; - // expect(requestData.imp[0].banner).to.equal(null); - expect(requestData.imp[0].banner.format[0].w).to.equal(300); - expect(requestData.imp[0].banner.format[0].h).to.equal(250); - }); - - it('should create request data', function () { - const bid = utils.deepClone(BANNER_BID); - - const [request] = spec.buildRequests([bid], BIDDER_REQUEST); - expect(request).to.exist.and.to.be.a('object'); - const payload = request.data; - expect(payload.imp[0]).to.have.property('id', bid.bidId); - }); - }); - - context('when mediaType is video', function () { - if (FEATURES.VIDEO) { - it('should return false when there is no video in mediaTypes', () => { - const bid = utils.deepClone(VIDEO_BID); - delete bid.mediaTypes.video; - - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - } - - if (FEATURES.VIDEO) { - it('should reutrn false if player size is not set', () => { - const bid = utils.deepClone(VIDEO_BID); - delete bid.mediaTypes.video.playerSize; - - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - } - if (FEATURES.VIDEO) { - it('when mediaType is Video - check', () => { - const bid = utils.deepClone(VIDEO_BID); - const check = { - w: 1024, - h: 768, - mimes: ['video/mp4'], - playbackmethod: [2, 4, 6], - api: [1, 2, 4, 6], - protocols: [3, 4, 7, 8, 10], - placement: 1, - minduration: 0, - maxduration: 60, - startdelay: 0, - plcmt: 1 - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - const requests = spec.buildRequests([bid], BIDDER_REQUEST); - const request = requests[0].data; - expect(request.imp[0].video).to.deep.include({...check}); - }); - } - - if (FEATURES.VIDEO) { - it('when mediaType New Video', () => { - const NEW_VIDEO_BID = { - 'bidder': 'tpmn', - 'params': {'inventoryId': 2, 'bidFloor': 2}, - 'userId': {'pubcid': '88a49ee6-beeb-4dd6-92ac-3b6060e127e1'}, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'mimes': ['video/mp4'], - 'playerSize': [[1024, 768]], - 'playbackmethod': [2, 4, 6], - 'protocols': [3, 4], - 'api': [1, 2, 3, 6], - 'placement': 1, - 'minduration': 0, - 'maxduration': 30, - 'startdelay': 0, - 'skip': 1, - 'plcmt': 4 - } - }, - }; - - const check = { - w: 1024, - h: 768, - mimes: [ 'video/mp4' ], - playbackmethod: [2, 4, 6], - api: [1, 2, 3, 6], - protocols: [3, 4], - placement: 1, - minduration: 0, - maxduration: 30, - startdelay: 0, - skip: 1, - plcmt: 4 - } - - expect(spec.isBidRequestValid(NEW_VIDEO_BID)).to.equal(true); - const requests = spec.buildRequests([NEW_VIDEO_BID], BIDDER_REQUEST); - const request = requests[0].data; - expect(request.imp[0].video.w).to.equal(check.w); - expect(request.imp[0].video.h).to.equal(check.h); - expect(request.imp[0].video.placement).to.equal(check.placement); - expect(request.imp[0].video.minduration).to.equal(check.minduration); - expect(request.imp[0].video.maxduration).to.equal(check.maxduration); - expect(request.imp[0].video.startdelay).to.equal(check.startdelay); - expect(request.imp[0].video.skip).to.equal(check.skip); - expect(request.imp[0].video.plcmt).to.equal(check.plcmt); - expect(request.imp[0].video.mimes).to.deep.have.same.members(check.mimes); - expect(request.imp[0].video.playbackmethod).to.deep.have.same.members(check.playbackmethod); - expect(request.imp[0].video.api).to.deep.have.same.members(check.api); - expect(request.imp[0].video.protocols).to.deep.have.same.members(check.protocols); - }); - } - - if (FEATURES.VIDEO) { - it('should use bidder video params if they are set', () => { - const bid = utils.deepClone(VIDEO_BID); - const check = { - api: [1, 2], - mimes: ['video/mp4', 'video/x-flv'], - playbackmethod: [3, 4], - protocols: [5, 6], - placement: 1, - plcmt: 1, - minduration: 0, - maxduration: 30, - startdelay: 0, - w: 640, - h: 480 - - }; - bid.mediaTypes.video = {...check}; - bid.mediaTypes.video.context = 'instream'; - bid.mediaTypes.video.playerSize = [[640, 480]]; - - expect(spec.isBidRequestValid(bid)).to.equal(true); - const requests = spec.buildRequests([bid], BIDDER_REQUEST); - const request = requests[0].data; - expect(request.imp[0].video).to.deep.include({...check}); - }); - } - }); - }); - - describe('interpretResponse()', function () { - context('when mediaType is banner', function () { - it('should correctly interpret valid banner response', function () { - const bid = utils.deepClone(BANNER_BID); - const [request] = spec.buildRequests([bid], BIDDER_REQUEST); - const response = utils.deepClone(BANNER_BID_RESPONSE); - - const bids = spec.interpretResponse({ body: response }, request); - expect(bids).to.be.an('array').that.is.not.empty; - - expect(bids[0].mediaType).to.equal('banner'); - expect(bids[0].burl).to.equal(BANNER_BID_RESPONSE.seatbid[0].bid[0].burl); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].requestId).to.equal(BANNER_BID_RESPONSE.seatbid[0].bid[0].impid); - expect(bids[0].cpm).to.equal(BANNER_BID_RESPONSE.seatbid[0].bid[0].price); - expect(bids[0].width).to.equal(BANNER_BID_RESPONSE.seatbid[0].bid[0].w); - expect(bids[0].height).to.equal(BANNER_BID_RESPONSE.seatbid[0].bid[0].h); - expect(bids[0].ad).to.equal(BANNER_BID_RESPONSE.seatbid[0].bid[0].adm); - expect(bids[0].creativeId).to.equal(BANNER_BID_RESPONSE.seatbid[0].bid[0].crid); - expect(bids[0].meta.advertiserDomains[0]).to.equal('https://dummydomain.com'); - expect(bids[0].ttl).to.equal(500); - expect(bids[0].netRevenue).to.equal(true); - }); - - it('should handle empty bid response', function () { - const bid = utils.deepClone(BANNER_BID); - - const request = spec.buildRequests([bid], BIDDER_REQUEST)[0]; - const EMPTY_RESP = Object.assign({}, BANNER_BID_RESPONSE, { 'body': {} }); - const bids = spec.interpretResponse(EMPTY_RESP, request); - expect(bids).to.be.empty; - }); - }); - if (FEATURES.VIDEO) { - context('when mediaType is video', function () { - it('should correctly interpret valid instream video response', () => { - const bid = utils.deepClone(VIDEO_BID); - - const [request] = spec.buildRequests([bid], BIDDER_REQUEST); - const bids = spec.interpretResponse({ body: VIDEO_BID_RESPONSE }, request); - expect(bids).to.be.an('array').that.is.not.empty; - - expect(bids[0].mediaType).to.equal('video'); - expect(bids[0].burl).to.equal(VIDEO_BID_RESPONSE.seatbid[0].bid[0].burl); - expect(bids[0].currency).to.equal('USD'); - expect(bids[0].requestId).to.equal(VIDEO_BID_RESPONSE.seatbid[0].bid[0].impid); - expect(bids[0].cpm).to.equal(VIDEO_BID_RESPONSE.seatbid[0].bid[0].price); - expect(bids[0].width).to.equal(VIDEO_BID_RESPONSE.seatbid[0].bid[0].w); - expect(bids[0].height).to.equal(VIDEO_BID_RESPONSE.seatbid[0].bid[0].h); - expect(bids[0].vastXml).to.equal(VIDEO_BID_RESPONSE.seatbid[0].bid[0].adm); - expect(bids[0].rendererUrl).to.equal(VIDEO_RENDERER_URL); - expect(bids[0].creativeId).to.equal(VIDEO_BID_RESPONSE.seatbid[0].bid[0].crid); - expect(bids[0].meta.advertiserDomains[0]).to.equal('https://dummydomain.com'); - expect(bids[0].ttl).to.equal(500); - expect(bids[0].netRevenue).to.equal(true); - }); - }); - } - }); - - describe('getUserSync', function () { - const KEY_ID = 'uuid'; - const TMP_UUID = generateUUID().replace(/-/g, ''); - - it('getCookie mock Test', () => { - const uuid = storage.getCookie(KEY_ID); - expect(uuid).to.equal(undefined); - }); - - it('getCookie mock Test', () => { - expect(TMP_UUID.length).to.equal(32); - getCookieStub.withArgs(KEY_ID).returns(TMP_UUID); - const uuid = storage.getCookie(KEY_ID); - expect(uuid).to.equal(TMP_UUID); - }); - - it('case 1 -> allow iframe', () => { - const syncs = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}); - expect(syncs.length).to.equal(1); - expect(syncs[0].type).to.equal('iframe'); - }); - - it('case 2 -> allow pixel with static sync', () => { - const syncs = spec.getUserSyncs({ iframeEnabled: false, pixelEnabled: true }); - expect(syncs.length).to.be.equal(4); - expect(syncs[0].type).to.be.equal('image'); - expect(syncs[1].type).to.be.equal('image'); - expect(syncs[2].type).to.be.equal('image'); - expect(syncs[3].type).to.be.equal('image'); - }); - }); -}); diff --git a/test/spec/modules/trafficgateBidAdapter_spec.js b/test/spec/modules/trafficgateBidAdapter_spec.js deleted file mode 100644 index 85a8aac56..000000000 --- a/test/spec/modules/trafficgateBidAdapter_spec.js +++ /dev/null @@ -1,1384 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/trafficgateBidAdapter'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import {BANNER, VIDEO} from 'src/mediaTypes.js'; -import {config} from 'src/config.js'; -import * as utils from 'src/utils.js'; -import 'src/prebid.js' -import 'modules/currency.js'; -import 'modules/userId/index.js'; -import 'modules/multibid/index.js'; -import 'modules/priceFloors.js'; -import 'modules/consentManagementTcf.js'; -import 'modules/consentManagementUsp.js'; -import 'modules/paapi.js'; - -import {deepClone} from 'src/utils.js'; -import {addFPDToBidderRequest} from '../../helpers/fpd.js'; -import {hook} from '../../../src/hook.js'; - -const BidRequestBuilder = function BidRequestBuilder(options) { - const defaults = { - request: { - auctionId: '4fd1ca2d-846c-4211-b9e5-321dfe1709c9', - adUnitCode: 'adunit-code', - bidder: 'trafficgate' - }, - params: { - placementId: '98765', - host: 'example' - }, - sizes: [[300, 250], [300, 600]], - }; - - const request = { - ...defaults.request, - ...options - }; - - this.withParams = (options) => { - request.params = { - ...defaults.params, - ...options - }; - return this; - }; - - this.build = () => request; -}; - -const BidderRequestBuilder = function BidderRequestBuilder(options) { - const defaults = { - bidderCode: 'trafficgate', - auctionId: '4fd1ca2d-846c-4211-b9e5-321dfe1709c9', - bidderRequestId: '7g36s867Tr4xF90X', - timeout: 3000, - refererInfo: { - numIframes: 0, - reachedTop: true, - referer: 'http://test.io/index.html?pbjs_debug=true' - } - }; - - const request = { - ...defaults, - ...options - }; - - this.build = () => request; -}; - -describe('TrafficgateOpenxRtbAdapter', function () { - before(() => { - hook.ready(); - }); - - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid()', function () { - describe('when request is for a banner ad', function () { - let bannerBid; - beforeEach(function () { - bannerBid = { - bidder: 'trafficgate', - params: {}, - adUnitCode: 'adunit-code', - mediaTypes: {banner: {}}, - sizes: [[300, 250], [300, 600]], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475' - }; - }); - - it('should return false when there is placementId only', function () { - bannerBid.params = {'placementId': '98765'}; - expect(spec.isBidRequestValid(bannerBid)).to.equal(false); - }); - - describe('should return false when there is a host only', function () { - beforeEach(function () { - bannerBid.params = {host: 'test-delivery-domain'} - }); - - it('should return false when there is no placementId and size', function () { - expect(spec.isBidRequestValid(bannerBid)).to.equal(false); - }); - - it('should return false if there is an placementId without sizes', function () { - bannerBid.params.placementId = '98765'; - expect(spec.isBidRequestValid(bannerBid)).to.equal(false); - }); - - it('should return false if there is no placementId and sizes are defined', function () { - bannerBid.mediaTypes.banner.sizes = [720, 90]; - expect(spec.isBidRequestValid(bannerBid)).to.equal(false); - }); - - it('should return false if no sizes are defined ', function () { - expect(spec.isBidRequestValid(bannerBid)).to.equal(false); - }); - - it('should return false if sizes empty ', function () { - bannerBid.mediaTypes.banner.sizes = []; - expect(spec.isBidRequestValid(bannerBid)).to.equal(false); - }); - - it('should return true if there is placementId and sizes are defined', function () { - bannerBid.params.placementId = '98765'; - bannerBid.mediaTypes.banner.sizes = [720, 90]; - expect(spec.isBidRequestValid(bannerBid)).to.equal(true); - }); - }); - }); - - describe('when request is for a multiformat ad', function () { - describe('and request config uses mediaTypes video and banner', () => { - const multiformatBid = { - bidder: 'trafficgate', - params: { - placementId: '98765', - host: 'example' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250]] - }, - video: { - playerSize: [300, 250] - } - }, - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '4008d88a-8137-410b-aa35-fbfdabcb478e' - }; - it('should return true multisize when required params found', function () { - expect(spec.isBidRequestValid(multiformatBid)).to.equal(true); - }); - }); - }); - - describe('when request is for a video ad', function () { - describe('and request config uses mediaTypes', () => { - const videoBidWithMediaTypes = { - bidder: 'trafficgate', - params: { - placementId: '98765', - host: 'example' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - video: { - playerSize: [640, 480] - } - }, - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '4008d88a-8137-410b-aa35-fbfdabcb478e' - }; - it('should return false when isBannerBid', function () { - expect(spec.isBannerBid(videoBidWithMediaTypes)).to.equal(false); - }); - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(videoBidWithMediaTypes)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidVideoBidWithMediaTypes = Object.assign({}, videoBidWithMediaTypes); - invalidVideoBidWithMediaTypes.params = {}; - expect(spec.isBidRequestValid(invalidVideoBidWithMediaTypes)).to.equal(false); - }); - }); - describe('and request config uses both host and platform', () => { - const videoBidWithHostAndPlacement = { - bidder: 'trafficgate', - params: { - placementId: '98765', - host: 'example' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - video: { - playerSize: [640, 480] - } - }, - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - transactionId: '4008d88a-8137-410b-aa35-fbfdabcb478e' - }; - it('should return false when isBannerBid', function () { - expect(spec.isBannerBid(videoBidWithHostAndPlacement)).to.equal(false); - }); - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(videoBidWithHostAndPlacement)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const videoBidWithMediaTypes = Object.assign({}, videoBidWithHostAndPlacement); - videoBidWithMediaTypes.params = {}; - expect(spec.isBidRequestValid(videoBidWithMediaTypes)).to.equal(false); - }); - }); - describe('and request config uses mediaType', () => { - const videoBidWithMediaType = { - 'bidder': 'trafficgate', - 'params': { - 'placementId': '98765', - 'host': 'example' - }, - 'adUnitCode': 'adunit-code', - 'mediaType': 'video', - 'sizes': [640, 480], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'transactionId': '4008d88a-8137-410b-aa35-fbfdabcb478e' - }; - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(videoBidWithMediaType)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidVideoBidWithMediaTypes = Object.assign({}, videoBidWithMediaType); - delete invalidVideoBidWithMediaTypes.params; - invalidVideoBidWithMediaTypes.params = {}; - expect(spec.isBidRequestValid(invalidVideoBidWithMediaTypes)).to.equal(false); - }); - }); - }); - }); - - describe('buildRequests()', function () { - let bidRequestsWithMediaTypes; - let bidRequestsWithPlatform; - let mockBidderRequest; - - beforeEach(function () { - mockBidderRequest = {refererInfo: {}}; - - bidRequestsWithMediaTypes = [{ - bidder: 'trafficgate', - params: { - placementId: '11', - host: 'example', - }, - adUnitCode: '/adunit-code/test-path', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - transactionId: 'test-transactionId-1', - ortb2Imp: { - ext: { - ae: 2 - } - } - }, { - bidder: 'trafficgate', - params: { - placementId: '22', - host: 'example', - }, - adUnitCode: 'adunit-code', - mediaTypes: { - video: { - playerSize: [640, 480] - } - }, - bidId: 'test-bid-id-2', - bidderRequestId: 'test-bid-request-2', - auctionId: 'test-auction-2', - transactionId: 'test-transactionId-2' - }]; - }); - - context('common requests checks', function() { - it('should be able to handle multiformat requests', () => { - const multiformat = utils.deepClone(bidRequestsWithMediaTypes[0]); - multiformat.mediaTypes.video = { - context: 'outstream', - playerSize: [640, 480] - } - const requests = spec.buildRequests([multiformat], mockBidderRequest); - const outgoingFormats = requests.flatMap(rq => rq.data.imp.flatMap(imp => ['banner', 'video'].filter(k => imp[k] != null))); - const expected = FEATURES.VIDEO ? ['banner', 'video'] : ['banner'] - expect(outgoingFormats).to.have.members(expected); - }) - - it('should send bid request to trafficgate url via POST', function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest); - expect(request[0].url).to.equal('https://example.bc-plugin.com/prebidjs'); - expect(request[0].method).to.equal('POST'); - }); - - it('should send delivery domain, if available', function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest); - expect(request[0].data.imp[0].ext.bidder.host).to.equal(bidRequestsWithMediaTypes[0].params.host); - expect(request[1].data.imp[0].ext.bidder.host).to.equal(bidRequestsWithMediaTypes[1].params.host); - }); - - it('should send placementId', function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest); - expect(request[0].data.imp[0].ext.bidder.placementId).to.equal(bidRequestsWithMediaTypes[0].params.placementId); - expect(request[1].data.imp[0].ext.bidder.placementId).to.equal(bidRequestsWithMediaTypes[1].params.placementId); - }); - - describe('floors', function () { - it('should send out custom floors on bids that have customFloors, no currency as account currency is used', function () { - const bidRequest = Object.assign({}, - bidRequestsWithMediaTypes[0], - { - params: { - placementId: '98765', - host: 'example', - customFloor: 1.500 - } - } - ); - - const request = spec.buildRequests([bidRequest], mockBidderRequest); - expect(request[0].data.imp[0].bidfloor).to.equal(bidRequest.params.customFloor); - expect(request[0].data.imp[0].bidfloorcur).to.equal(undefined); - }); - - context('with floors module', function () { - let adServerCurrencyStub; - - beforeEach(function () { - adServerCurrencyStub = sinon - .stub(config, 'getConfig') - .withArgs('currency.adServerCurrency') - }); - - afterEach(function () { - config.getConfig.restore(); - }); - - it('should send out floors on bids in USD', function () { - const bidRequest = Object.assign({}, - bidRequestsWithMediaTypes[0], - { - getFloor: () => { - return { - currency: 'USD', - floor: 9.99 - } - } - } - ); - - const request = spec.buildRequests([bidRequest], mockBidderRequest); - expect(request[0].data.imp[0].bidfloor).to.equal(9.99); - expect(request[0].data.imp[0].bidfloorcur).to.equal('USD'); - }); - - it('should send not send floors', function () { - adServerCurrencyStub.returns('EUR'); - const bidRequest = Object.assign({}, - bidRequestsWithMediaTypes[0], - { - getFloor: () => { - return { - currency: 'BTC', - floor: 9.99 - } - } - } - ); - - const request = spec.buildRequests([bidRequest], mockBidderRequest); - expect(request[0].data.imp[0].bidfloor).to.equal(undefined) - expect(request[0].data.imp[0].bidfloorcur).to.equal(undefined) - }); - }) - }) - - describe('FPD', function() { - let bidRequests; - const mockBidderRequest = {refererInfo: {}}; - - beforeEach(function () { - bidRequests = [{ - bidder: 'trafficgate', - params: { - placementId: '98765-banner', - host: 'example' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id', - transactionId: 'test-transaction-id-1' - }, { - bidder: 'trafficgate', - mediaTypes: { - video: { - playerSize: [640, 480] - } - }, - params: { - placementId: '98765-video', - host: 'example' - }, - 'adUnitCode': 'adunit-code', - - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id', - transactionId: 'test-transaction-id-2' - }]; - }); - - it('ortb2.site should be merged in the request', function() { - const request = spec.buildRequests(bidRequests, { - ...mockBidderRequest, - 'ortb2': { - site: { - domain: 'page.example.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'] - } - } - }); - const data = request[0].data; - expect(data.site.domain).to.equal('page.example.com'); - expect(data.site.cat).to.deep.equal(['IAB2']); - expect(data.site.sectioncat).to.deep.equal(['IAB2-2']); - }); - - it('ortb2.user should be merged in the request', function() { - const request = spec.buildRequests(bidRequests, { - ...mockBidderRequest, - 'ortb2': { - user: { - yob: 1985 - } - } - }); - const data = request[0].data; - expect(data.user.yob).to.equal(1985); - }); - - describe('ortb2Imp', function() { - describe('ortb2Imp.ext.data.pbadslot', function() { - beforeEach(function () { - if (bidRequests[0].hasOwnProperty('ortb2Imp')) { - delete bidRequests[0].ortb2Imp; - } - }); - - it('should not send if imp[].ext.data object is invalid', function() { - bidRequests[0].ortb2Imp = { - ext: {} - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - expect(data.imp[0].ext).to.not.have.property('data'); - }); - - it('should not send if imp[].ext.data.pbadslot is undefined', function() { - bidRequests[0].ortb2Imp = { - ext: { - data: { - } - } - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - if (data.imp[0].ext.data) { - expect(data.imp[0].ext.data).to.not.have.property('pbadslot'); - } else { - expect(data.imp[0].ext).to.not.have.property('data'); - } - }); - - it('should send if imp[].ext.data.pbadslot is string', function() { - bidRequests[0].ortb2Imp = { - ext: { - data: { - pbadslot: 'abcd' - } - } - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - expect(data.imp[0].ext.data).to.have.property('pbadslot'); - expect(data.imp[0].ext.data.pbadslot).to.equal('abcd'); - }); - }); - - describe('ortb2Imp.ext.data.adserver', function() { - beforeEach(function () { - if (bidRequests[0].hasOwnProperty('ortb2Imp')) { - delete bidRequests[0].ortb2Imp; - } - }); - - it('should not send if imp[].ext.data object is invalid', function() { - bidRequests[0].ortb2Imp = { - ext: {} - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - expect(data.imp[0].ext).to.not.have.property('data'); - }); - - it('should not send if imp[].ext.data.adserver is undefined', function() { - bidRequests[0].ortb2Imp = { - ext: { - data: { - } - } - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - if (data.imp[0].ext.data) { - expect(data.imp[0].ext.data).to.not.have.property('adserver'); - } else { - expect(data.imp[0].ext).to.not.have.property('data'); - } - }); - - it('should send', function() { - const adSlotValue = 'abc'; - bidRequests[0].ortb2Imp = { - ext: { - data: { - adserver: { - name: 'GAM', - adslot: adSlotValue - } - } - } - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - expect(data.imp[0].ext.data.adserver.name).to.equal('GAM'); - expect(data.imp[0].ext.data.adserver.adslot).to.equal(adSlotValue); - }); - }); - - describe('ortb2Imp.ext.data.other', function() { - beforeEach(function () { - if (bidRequests[0].hasOwnProperty('ortb2Imp')) { - delete bidRequests[0].ortb2Imp; - } - }); - - it('should not send if imp[].ext.data object is invalid', function() { - bidRequests[0].ortb2Imp = { - ext: {} - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - expect(data.imp[0].ext).to.not.have.property('data'); - }); - - it('should not send if imp[].ext.data.other is undefined', function() { - bidRequests[0].ortb2Imp = { - ext: { - data: { - } - } - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - if (data.imp[0].ext.data) { - expect(data.imp[0].ext.data).to.not.have.property('other'); - } else { - expect(data.imp[0].ext).to.not.have.property('data'); - } - }); - - it('ortb2Imp.ext.data.other', function() { - bidRequests[0].ortb2Imp = { - ext: { - data: { - other: 1234 - } - } - }; - const request = spec.buildRequests(bidRequests, mockBidderRequest); - const data = request[0].data; - expect(data.imp[0].ext.data.other).to.equal(1234); - }); - }); - }); - - describe('with user agent client hints', function () { - it('should add device.sua if available', function () { - const bidderRequestWithUserAgentClientHints = { refererInfo: {}, - ortb2: { - device: { - sua: { - source: 2, - platform: { - brand: 'macOS', - version: [ '12', '4', '0' ] - }, - browsers: [ - { - brand: 'Chromium', - version: [ '106', '0', '5249', '119' ] - }, - { - brand: 'Google Chrome', - version: [ '106', '0', '5249', '119' ] - }, - { - brand: 'Not;A=Brand', - version: [ '99', '0', '0', '0' ] - }], - mobile: 0, - model: 'Pro', - bitness: '64', - architecture: 'x86' - } - } - }}; - - let request = spec.buildRequests(bidRequests, bidderRequestWithUserAgentClientHints); - expect(request[0].data.device.sua).to.exist; - expect(request[0].data.device.sua).to.deep.equal(bidderRequestWithUserAgentClientHints.ortb2.device.sua); - const bidderRequestWithoutUserAgentClientHints = {refererInfo: {}, ortb2: {}}; - request = spec.buildRequests(bidRequests, bidderRequestWithoutUserAgentClientHints); - expect(request[0].data.device?.sua).to.not.exist; - }); - }); - }); - - context('when there is a consent management framework', function () { - let bidRequests; - let mockConfig; - let bidderRequest; - - beforeEach(function () { - bidRequests = [{ - bidder: 'trafficgate', - params: { - placementId: '98765-banner', - host: 'example' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id', - transactionId: 'test-transaction-id-1' - }, { - bidder: 'trafficgate', - mediaTypes: { - video: { - playerSize: [640, 480] - } - }, - params: { - placementId: '98765-video', - host: 'example' - }, - 'adUnitCode': 'adunit-code', - - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id', - transactionId: 'test-transaction-id-2' - }]; - }); - - describe('us_privacy', function () { - beforeEach(function () { - bidderRequest = { - uspConsent: '1YYN', - refererInfo: {} - }; - - sinon.stub(config, 'getConfig').callsFake((key) => { - return utils.deepAccess(mockConfig, key); - }); - }); - - afterEach(function () { - config.getConfig.restore(); - }); - - it('should send a signal to specify that US Privacy applies to this request', async function () { - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.regs.ext.us_privacy).to.equal('1YYN'); - expect(request[1].data.regs.ext.us_privacy).to.equal('1YYN'); - }); - - it('should not send the regs object, when consent string is undefined', async function () { - delete bidderRequest.uspConsent; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.regs?.us_privacy).to.not.exist; - }); - }); - - describe('GDPR', function () { - beforeEach(function () { - bidderRequest = { - gdprConsent: { - consentString: 'test-gdpr-consent-string', - addtlConsent: 'test-addtl-consent-string', - gdprApplies: true - }, - refererInfo: {} - }; - - mockConfig = { - consentManagement: { - cmpApi: 'iab', - timeout: 1111, - allowAuctionWithoutConsent: 'cancel' - } - }; - - sinon.stub(config, 'getConfig').callsFake((key) => { - return utils.deepAccess(mockConfig, key); - }); - }); - - afterEach(function () { - config.getConfig.restore(); - }); - - it('should send a signal to specify that GDPR applies to this request', async function () { - bidderRequest.bids = bidRequests; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.regs.ext.gdpr).to.equal(1); - expect(request[1].data.regs.ext.gdpr).to.equal(1); - }); - - it('should send the consent string', async function () { - bidderRequest.bids = bidRequests; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString); - expect(request[1].data.user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString); - }); - - it('should send the addtlConsent string', async function () { - bidderRequest.bids = bidRequests; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.user.ext.ConsentedProvidersSettings.consented_providers).to.equal(bidderRequest.gdprConsent.addtlConsent); - expect(request[1].data.user.ext.ConsentedProvidersSettings.consented_providers).to.equal(bidderRequest.gdprConsent.addtlConsent); - }); - - it('should send a signal to specify that GDPR does not apply to this request', async function () { - bidderRequest.gdprConsent.gdprApplies = false; - bidderRequest.bids = bidRequests; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.regs.ext.gdpr).to.equal(0); - expect(request[1].data.regs.ext.gdpr).to.equal(0); - }); - - it('when GDPR application is undefined, should not send a signal to specify whether GDPR applies to this request, ' + - 'but can send consent data, ', async function () { - delete bidderRequest.gdprConsent.gdprApplies; - bidderRequest.bids = bidRequests; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.regs?.ext?.gdpr).to.not.be.ok; - expect(request[0].data.user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString); - expect(request[1].data.user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString); - }); - - it('when consent string is undefined, should not send the consent string, ', async function () { - delete bidderRequest.gdprConsent.consentString; - bidderRequest.bids = bidRequests; - const request = spec.buildRequests(bidRequests, await addFPDToBidderRequest(bidderRequest)); - expect(request[0].data.imp[0].ext.consent).to.equal(undefined); - expect(request[1].data.imp[0].ext.consent).to.equal(undefined); - }); - }); - }); - - context('coppa', function() { - it('when there are no coppa param settings, should not send a coppa flag', async function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, await addFPDToBidderRequest(mockBidderRequest)); - expect(request[0].data.regs?.coppa).to.be.not.ok; - }); - - it('should send a coppa flag there is when there is coppa param settings in the bid requests', async function () { - const mockConfig = { - coppa: true - }; - - sinon.stub(config, 'getConfig').callsFake((key) => { - return utils.deepAccess(mockConfig, key); - }); - - const request = spec.buildRequests(bidRequestsWithMediaTypes, await addFPDToBidderRequest(mockBidderRequest)); - expect(request[0].data.regs.coppa).to.equal(1); - }); - - it('should send a coppa flag there is when there is coppa param settings in the bid params', async function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, await addFPDToBidderRequest(mockBidderRequest)); - request.params = {coppa: true}; - expect(request[0].data.regs.coppa).to.equal(1); - }); - - after(function () { - config.getConfig.restore() - }); - }); - - context('do not track (DNT)', function() { - let doNotTrackStub; - - beforeEach(function () { - doNotTrackStub = sinon.stub(utils, 'getDNT'); - }); - afterEach(function() { - doNotTrackStub.restore(); - }); - - it('when there is a do not track, should send a dnt', async function () { - doNotTrackStub.returns(1); - - const request = spec.buildRequests(bidRequestsWithMediaTypes, await addFPDToBidderRequest(mockBidderRequest)); - expect(request[0].data.device.dnt).to.equal(1); - }); - - it('when there is not do not track, don\'t send dnt', async function () { - doNotTrackStub.returns(0); - - const request = spec.buildRequests(bidRequestsWithMediaTypes, await addFPDToBidderRequest(mockBidderRequest)); - expect(request[0].data.device.dnt).to.equal(0); - }); - - it('when there is no defined do not track, don\'t send dnt', async function () { - doNotTrackStub.returns(null); - - const request = spec.buildRequests(bidRequestsWithMediaTypes, await addFPDToBidderRequest(mockBidderRequest)); - expect(request[0].data.device.dnt).to.equal(0); - }); - }); - - context('supply chain (schain)', function () { - let bidRequests; - let schainConfig; - const supplyChainNodePropertyOrder = ['asi', 'sid', 'hp', 'rid', 'name', 'domain']; - - beforeEach(function () { - schainConfig = { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'exchange1.com', - sid: '1234', - hp: 1, - rid: 'bid-request-1', - name: 'publisher', - domain: 'publisher.com' - // omitted ext - }, - { - asi: 'exchange2.com', - sid: 'abcd', - hp: 1, - rid: 'bid-request-2', - // name field missing - domain: 'intermediary.com' - }, - { - asi: 'exchange3.com', - sid: '4321', - hp: 1, - // request id - // name field missing - domain: 'intermediary-2.com' - } - ] - }; - - bidRequests = [{ - bidder: 'trafficgate', - params: { - placementId: '11', - host: 'example' - }, - adUnitCode: '/adunit-code/test-path', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - ortb2: {source: { - ext: {schain: schainConfig} - }} - }]; - - // Add schain to mockBidderRequest as well - mockBidderRequest.ortb2 = { - source: { - ext: {schain: schainConfig} - } - }; - }); - - it('should send a supply chain object', function () { - const request = spec.buildRequests(bidRequests, mockBidderRequest); - expect(request[0].data.source.ext.schain).to.deep.equal(schainConfig); - }); - - it('should send the supply chain object with the right version', function () { - const request = spec.buildRequests(bidRequests, mockBidderRequest); - expect(request[0].data.source.ext.schain.ver).to.equal(schainConfig.ver); - }); - - it('should send the supply chain object with the right complete value', function () { - const request = spec.buildRequests(bidRequests, mockBidderRequest); - expect(request[0].data.source.ext.schain.complete).to.equal(schainConfig.complete); - }); - }); - - context('when there are userid providers', function () { - const userIdAsEids = [ - { - source: 'adserver.org', - uids: [{ - id: 'some-random-id-value', - atype: 1, - ext: { - rtiPartner: 'TDID' - } - }] - }, - { - source: 'id5-sync.com', - uids: [{ - id: 'some-random-id-value', - atype: 1 - }] - }, - { - source: 'sharedid.org', - uids: [{ - id: 'some-random-id-value', - atype: 1, - ext: { - third: 'some-random-id-value' - } - }] - } - ]; - - it(`should send the user id under the extended ids`, function () { - const bidRequestsWithUserId = [{ - bidder: 'trafficgate', - params: { - placementId: '11', - host: 'example' - }, - userId: { - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'test-bid-id-1', - bidderRequestId: 'test-bid-request-1', - auctionId: 'test-auction-1', - }]; - // enrich bid request with userId key/value - mockBidderRequest.ortb2 = {user: {ext: {eids: userIdAsEids}}} - const request = spec.buildRequests(bidRequestsWithUserId, mockBidderRequest); - expect(request[0].data.user.ext.eids).to.eql(userIdAsEids); - }); - - it(`when no user ids are available, it should not send any extended ids`, function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest); - expect(request[0].data).to.not.have.any.keys('user'); - }); - }); - - context('FLEDGE', function() { - it('when FLEDGE is enabled, should send whatever is set in ortb2imp.ext.ae in all bid requests', function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, { - ...mockBidderRequest, - paapi: { - enabled: true - } - }); - expect(request[0].data.imp[0].ext.ae).to.equal(2); - }); - }); - }); - - context('banner', function () { - it('should send bid request with a mediaTypes specified with banner type', function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest); - expect(request[0].data.imp[0]).to.have.any.keys(BANNER); - }); - }); - - if (FEATURES.VIDEO) { - context('video', function () { - it('should send bid request with a mediaTypes specified with video type', function () { - const request = spec.buildRequests(bidRequestsWithMediaTypes, mockBidderRequest); - expect(request[1].data.imp[0]).to.have.any.keys(VIDEO); - }); - - it('Update imp.video with OpenRTB options from mimeTypes and params', function() { - const bid01 = new BidRequestBuilder({ - adUnitCode: 'adunit-code-01', - mediaTypes: { - banner: { sizes: [[300, 250]] }, - video: { - context: 'outstream', - playerSize: [[300, 250]], - mimes: ['video/mp4'], - protocols: [8] - } - }, - }).withParams({ - // options in video, will merge - video: { - skip: 1, - skipafter: 4, - minduration: 10, - maxduration: 30 - } - }).build(); - - const bidderRequest = new BidderRequestBuilder().build(); - const expected = { - mimes: ['video/mp4'], - skip: 1, - skipafter: 4, - minduration: 10, - maxduration: 30, - placement: 4, - protocols: [8], - w: 300, - h: 250 - }; - const requests = spec.buildRequests([bid01], bidderRequest); - expect(requests).to.have.lengthOf(2); - expect(requests[1].data.imp[0].video).to.deep.equal(expected); - }); - }); - } - }); - - describe('interpretResponse()', function () { - let bidRequestConfigs; - let bidRequest; - let bidResponse; - let bid; - - context('when there is an nbr response', function () { - let bids; - beforeEach(function () { - bidRequestConfigs = [{ - bidder: 'trafficgate', - params: { - placementId: '98765', - host: 'example' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = {nbr: 0}; // Unknown error - bids = spec.interpretResponse({body: bidResponse}, bidRequest); - }); - - it('should not return any bids', function () { - expect(bids.length).to.equal(0); - }); - }); - - context('when no seatbid in response', function () { - let bids; - beforeEach(function () { - bidRequestConfigs = [{ - bidder: 'trafficgate', - params: { - placementId: '98765', - host: 'example' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = {ext: {}, id: 'test-bid-id'}; - bids = spec.interpretResponse({body: bidResponse}, bidRequest); - }); - - it('should not return any bids', function () { - expect(bids.length).to.equal(0); - }); - }); - - context('when there is no response', function () { - let bids; - beforeEach(function () { - bidRequestConfigs = [{ - bidder: 'trafficgate', - params: { - placementId: '98765', - host: 'example' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = ''; // Unknown error - bids = spec.interpretResponse({body: bidResponse}, bidRequest); - }); - - it('should not return any bids', function () { - expect(bids.length).to.equal(0); - }); - }); - - const SAMPLE_BID_REQUESTS = [{ - bidder: 'trafficgate', - params: { - placementId: '98765', - host: 'example' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - const SAMPLE_BID_RESPONSE = { - seatbid: [{ - bid: [{ - impid: 'test-bid-id', - price: 3.5, - w: 300, - h: 250, - crid: 'test-creative-id', - dealid: 'test-deal-id', - adm: 'test-ad-markup', - adomain: ['brand.com'], - ext: { - networkId: 123, - advertiserDomains: ['domain.com'], - } - }] - }], - cur: 'USD' - }; - - context('when there is a response, the common response properties', function () { - beforeEach(function () { - bidRequestConfigs = deepClone(SAMPLE_BID_REQUESTS); - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - bidResponse = deepClone(SAMPLE_BID_RESPONSE); - - bid = spec.interpretResponse({body: bidResponse}, bidRequest)[0]; - }); - - it('should return a price', function () { - expect(bid.cpm).to.equal(bidResponse.seatbid[0].bid[0].price); - }); - - it('should return a request id', function () { - expect(bid.requestId).to.equal(bidResponse.seatbid[0].bid[0].impid); - }); - - it('should return width and height for the creative', function () { - expect(bid.width).to.equal(bidResponse.seatbid[0].bid[0].w); - expect(bid.height).to.equal(bidResponse.seatbid[0].bid[0].h); - }); - - it('should return a creativeId', function () { - expect(bid.creativeId).to.equal(bidResponse.seatbid[0].bid[0].crid); - }); - - it('should return an ad', function () { - expect(bid.ad).to.equal(bidResponse.seatbid[0].bid[0].adm); - }); - - it('should return a deal id if it exists', function () { - expect(bid.dealId).to.equal(bidResponse.seatbid[0].bid[0].dealid); - }); - - it('should have a time-to-live of 5 minutes', function () { - expect(bid.ttl).to.equal(300); - }); - - it('should always return net revenue', function () { - expect(bid.netRevenue).to.equal(true); - }); - - it('should return a currency', function () { - expect(bid.currency).to.equal(bidResponse.cur); - }); - - it('should return a networkId', function () { - expect(bid.meta.networkId).to.equal(bidResponse.seatbid[0].bid[0].ext.networkId); - }); - - it('should return adomain', function () { - expect(bid.meta.advertiserDomains).to.equal(bidResponse.seatbid[0].bid[0].ext.advertiserDomains); - }); - }); - - context('when the response is a banner', function() { - beforeEach(function () { - bidRequestConfigs = [{ - bidder: 'trafficgate', - params: { - placementId: '98765', - host: 'example' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]], - }, - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = { - seatbid: [{ - bid: [{ - impid: 'test-bid-id', - price: 2, - w: 300, - h: 250, - crid: 'test-creative-id', - dealid: 'test-deal-id', - adm: 'test-ad-markup' - }] - }], - cur: 'AUS' - }; - - bid = spec.interpretResponse({body: bidResponse}, bidRequest)[0]; - }); - - it('should return the proper mediaType', function () { - it('should return a creativeId', function () { - expect(bid.mediaType).to.equal(Object.keys(bidRequestConfigs[0].mediaTypes)[0]); - }); - }); - }); - - if (FEATURES.VIDEO) { - context('when the response is a video', function() { - beforeEach(function () { - bidRequestConfigs = [{ - bidder: 'trafficgate', - params: { - placementId: '98765', - host: 'example' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - video: { - playerSize: [[640, 360], [854, 480]], - }, - }, - bidId: 'test-bid-id', - bidderRequestId: 'test-bidder-request-id', - auctionId: 'test-auction-id' - }]; - - bidRequest = spec.buildRequests(bidRequestConfigs, {refererInfo: {}})[0]; - - bidResponse = { - seatbid: [{ - bid: [{ - impid: 'test-bid-id', - price: 2, - w: 854, - h: 480, - crid: 'test-creative-id', - dealid: 'test-deal-id', - adm: 'test-ad-markup', - }] - }], - cur: 'AUS' - }; - }); - - it('should return the proper mediaType', function () { - bid = spec.interpretResponse({body: bidResponse}, bidRequest)[0]; - expect(bid.mediaType).to.equal(Object.keys(bidRequestConfigs[0].mediaTypes)[0]); - }); - - it('should return the proper mediaType', function () { - const winUrl = 'https//my.win.url'; - bidResponse.seatbid[0].bid[0].nurl = winUrl - bid = spec.interpretResponse({body: bidResponse}, bidRequest)[0]; - - expect(bid.vastUrl).to.equal(winUrl); - }); - }); - } - }); -}); diff --git a/test/spec/modules/trionBidAdapter_spec.js b/test/spec/modules/trionBidAdapter_spec.js deleted file mode 100644 index 306cacc24..000000000 --- a/test/spec/modules/trionBidAdapter_spec.js +++ /dev/null @@ -1,407 +0,0 @@ -import {expect} from 'chai'; -import * as utils from 'src/utils.js'; -import {spec, acceptPostMessage, getStorageData, setStorageData} from 'modules/trionBidAdapter.js'; -import {deepClone} from 'src/utils.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -const CONSTANTS = require('src/constants.js'); -const adloader = require('src/adloader'); - -const PLACEMENT_CODE = 'ad-tag'; -const BID_REQUEST_BASE_URL = 'https://in-appadvertising.com/api/bidRequest'; - -const TRION_BID = { - bidder: 'trion', - params: { - pubId: '1', - sectionId: '2' - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [300, 600]] - } - }, - adUnitCode: 'adunit-code', - sizes: [[300, 250], [300, 600]], - bidId: 'test-bid-id', - bidRequest: 'test-bid-request' -}; - -const TRION_BID_REQUEST = [TRION_BID]; - -const TRION_BIDDER_REQUEST = { - 'bidderCode': 'trion', - 'auctionId': '12345', - 'bidderRequestId': 'abc1234', - 'bids': TRION_BID_REQUEST -}; - -const TRION_BID_RESPONSE = { - bidId: 'test-bid-id', - sizes: [[300, 250], [300, 600]], - result: { - cpm: 100, - placeBid: true, - height: '250', - width: '300', - ad: 'test', - msg: 'response messaging' - } - -}; - -const getPublisherUrl = function () { - var url = null; - try { - if (window.top === window) { - url = window.location.href; - } else { - try { - url = window.top.location.href; - } catch (e) { - url = document.referrer; - } - } - } catch (e) { - } - return url -}; - -describe('Trion adapter tests', function () { - let adapter; - - beforeEach(function () { - // adapter = trionAdapter.createNew(); - getGlobal().bidderSettings = { - trion: { - storageAllowed: true - } - }; - sinon.stub(document.body, 'appendChild'); - }); - - afterEach(function () { - getGlobal().bidderSettings = {}; - document.body.appendChild.restore(); - }); - - describe('isBidRequestValid', function () { - it('should return true with correct params', function () { - expect(spec.isBidRequestValid(TRION_BID)).to.equal(true); - }); - - it('should return false when params are missing', function () { - TRION_BID.params = {}; - - expect(spec.isBidRequestValid(TRION_BID)).to.equal(false); - TRION_BID.params = { - pubId: '1', - sectionId: '2' - }; - }); - - it('should return false when pubId is missing', function () { - TRION_BID.params = { - sectionId: '2' - }; - - expect(spec.isBidRequestValid(TRION_BID)).to.equal(false); - TRION_BID.params = { - pubId: '1', - sectionId: '2' - }; - }); - - it('should return false when sectionId is missing', function () { - TRION_BID.params = { - pubId: '1' - }; - - expect(spec.isBidRequestValid(TRION_BID)).to.equal(false); - TRION_BID.params = { - pubId: '1', - sectionId: '2' - }; - }); - }); - - describe('buildRequests', function () { - it('should return bids requests with empty params', function () { - const bidRequests = spec.buildRequests([]); - expect(bidRequests.length).to.equal(0); - }); - - it('should include the base bidrequest url', function () { - const bidRequests = spec.buildRequests(TRION_BID_REQUEST); - - const bidUrl = bidRequests[0].url; - expect(bidUrl).to.include(BID_REQUEST_BASE_URL); - }); - - it('should call buildRequests with the correct required params', function () { - const bidRequests = spec.buildRequests(TRION_BID_REQUEST); - - const bidUrlParams = bidRequests[0].data; - expect(bidUrlParams).to.include('pubId=1'); - expect(bidUrlParams).to.include('sectionId=2'); - expect(bidUrlParams).to.include('sizes=300x250,300x600'); - expect(bidUrlParams).to.include('vers=$prebid.version$'); - }); - - it('should call buildRequests with the correct optional params', function () { - const bidRequests = spec.buildRequests(TRION_BID_REQUEST); - const bidUrlParams = bidRequests[0].data; - expect(bidUrlParams).to.include(getPublisherUrl()); - }); - - // describe('webdriver', function () { - // let originalWD; - - // beforeEach(function () { - // originalWD = window.navigator.webdriver; - // }); - - // afterEach(function () { - // window.navigator['__defineGetter__']('webdriver', function () { - // return originalWD; - // }); - // }); - - // describe('is present', function () { - // beforeEach(function () { - // window.navigator['__defineGetter__']('webdriver', function () { - // return 1; - // }); - // }); - - // it('when there is non human traffic', function () { - // let bidRequests = spec.buildRequests(TRION_BID_REQUEST); - // let bidUrlParams = bidRequests[0].data; - // expect(bidUrlParams).to.include('tr_wd=1'); - // }); - // }); - - // describe('is not present', function () { - // beforeEach(function () { - // window.navigator['__defineGetter__']('webdriver', function () { - // return 0; - // }); - // }); - - // it('when there is not non human traffic', function () { - // let bidRequests = spec.buildRequests(TRION_BID_REQUEST); - // let bidUrlParams = bidRequests[0].data; - // expect(bidUrlParams).to.include('tr_wd=0'); - // }); - // }); - // }); - - describe('document', function () { - let originalHD; - let originalVS; - - beforeEach(function () { - originalHD = document.hidden; - originalVS = document.visibilityState; - }); - - afterEach(function () { - document['__defineGetter__']('hidden', function () { - return originalHD; - }); - document['__defineGetter__']('visibilityState', function () { - return originalVS; - }); - }); - - describe('is visible', function () { - beforeEach(function () { - document['__defineGetter__']('hidden', function () { - return 1; - }); - document['__defineGetter__']('visibilityState', function () { - return 'visible'; - }); - }); - - it('should detect and send the document is visible', function () { - const bidRequests = spec.buildRequests(TRION_BID_REQUEST); - const bidUrlParams = bidRequests[0].data; - expect(bidUrlParams).to.include('tr_hd=1'); - expect(bidUrlParams).to.include('tr_vs=visible'); - }); - }); - - describe('is hidden', function () { - beforeEach(function () { - document['__defineGetter__']('hidden', function () { - return 1; - }); - document['__defineGetter__']('visibilityState', function () { - return 'hidden'; - }); - }); - - it('should detect and send the document is hidden', function () { - const bidRequests = spec.buildRequests(TRION_BID_REQUEST); - const bidUrlParams = bidRequests[0].data; - expect(bidUrlParams).to.include('tr_hd=1'); - expect(bidUrlParams).to.include('tr_vs=hidden'); - }); - }); - }); - - describe('should call buildRequests with correct consent params', function () { - it('when gdpr is present', function () { - TRION_BIDDER_REQUEST.gdprConsent = { - consentString: 'test_gdpr_str', - gdprApplies: true - }; - const bidRequests = spec.buildRequests(TRION_BID_REQUEST, TRION_BIDDER_REQUEST); - const bidUrlParams = bidRequests[0].data; - const gcEncoded = encodeURIComponent(TRION_BIDDER_REQUEST.gdprConsent.consentString); - expect(bidUrlParams).to.include('gdprc=' + gcEncoded); - expect(bidUrlParams).to.include('gdpr=1'); - delete TRION_BIDDER_REQUEST.gdprConsent; - }); - - it('when us privacy is present', function () { - TRION_BIDDER_REQUEST.uspConsent = '1YYY'; - const bidRequests = spec.buildRequests(TRION_BID_REQUEST, TRION_BIDDER_REQUEST); - const bidUrlParams = bidRequests[0].data; - const uspEncoded = encodeURIComponent(TRION_BIDDER_REQUEST.uspConsent); - expect(bidUrlParams).to.include('usp=' + uspEncoded); - delete TRION_BIDDER_REQUEST.uspConsent; - }); - }); - }); - - describe('interpretResponse', function () { - it('when there is no response do not bid', function () { - const response = spec.interpretResponse(null, {bidRequest: TRION_BID}); - expect(response).to.deep.equal([]); - }); - - it('when place bid is returned as false', function () { - TRION_BID_RESPONSE.result.placeBid = false; - const response = spec.interpretResponse({body: TRION_BID_RESPONSE}, {bidRequest: TRION_BID}); - - expect(response).to.deep.equal([]); - - TRION_BID_RESPONSE.result.placeBid = true; - }); - - it('when no cpm is in the response', function () { - TRION_BID_RESPONSE.result.cpm = 0; - const response = spec.interpretResponse({body: TRION_BID_RESPONSE}, {bidRequest: TRION_BID}); - expect(response).to.deep.equal([]); - TRION_BID_RESPONSE.result.cpm = 1; - }); - - it('when no ad is in the response', function () { - TRION_BID_RESPONSE.result.ad = null; - const response = spec.interpretResponse({body: TRION_BID_RESPONSE}, {bidRequest: TRION_BID}); - expect(response).to.deep.equal([]); - TRION_BID_RESPONSE.result.ad = 'test'; - }); - - it('height and width are appropriately set', function () { - const bidWidth = '1'; - const bidHeight = '2'; - TRION_BID_RESPONSE.result.width = bidWidth; - TRION_BID_RESPONSE.result.height = bidHeight; - const response = spec.interpretResponse({body: TRION_BID_RESPONSE}, {bidRequest: TRION_BID}); - expect(response[0].width).to.equal(bidWidth); - expect(response[0].height).to.equal(bidHeight); - TRION_BID_RESPONSE.result.width = '300'; - TRION_BID_RESPONSE.result.height = '250'; - }); - - it('cpm is properly set and transformed to cents', function () { - const bidCpm = 2; - TRION_BID_RESPONSE.result.cpm = bidCpm * 100; - const response = spec.interpretResponse({body: TRION_BID_RESPONSE}, {bidRequest: TRION_BID}); - expect(response[0].cpm).to.equal(bidCpm); - TRION_BID_RESPONSE.result.cpm = 100; - }); - - it('advertiserDomains is included when sent by server', function () { - TRION_BID_RESPONSE.result.adomain = ['test_adomain']; - const response = spec.interpretResponse({body: TRION_BID_RESPONSE}, {bidRequest: TRION_BID}); - expect(Object.keys(response[0].meta)).to.include.members(['advertiserDomains']); - expect(response[0].meta.advertiserDomains).to.deep.equal(['test_adomain']); - delete TRION_BID_RESPONSE.result.adomain; - }); - }); - - describe('getUserSyncs', function () { - const USER_SYNC_URL = 'https://in-appadvertising.com/api/userSync.html'; - const BASE_KEY = '_trion_'; - - beforeEach(function () { - delete window.TR_INT_T; - }); - - it('trion int is included in bid url', function () { - window.TR_INT_T = 'test_user_sync'; - const userTag = encodeURIComponent(window.TR_INT_T); - const bidRequests = spec.buildRequests(TRION_BID_REQUEST); - const bidUrlParams = bidRequests[0].data; - - expect(bidUrlParams).to.include(userTag); - }); - - it('should register trion user script', function () { - const syncs = spec.getUserSyncs({iframeEnabled: true}); - const pageUrl = getPublisherUrl(); - const pubId = 1; - const sectionId = 2; - const syncString = `?p=${pubId}&s=${sectionId}&u=${pageUrl}`; - expect(syncs[0]).to.deep.equal({type: 'iframe', url: USER_SYNC_URL + syncString}); - }); - - it('should register trion user script with gdpr params', function () { - const gdprConsent = { - consentString: 'test_gdpr_str', - gdprApplies: true - }; - const syncs = spec.getUserSyncs({iframeEnabled: true}, null, gdprConsent); - const pageUrl = getPublisherUrl(); - const pubId = 1; - const sectionId = 2; - const gcEncoded = encodeURIComponent(gdprConsent.consentString); - const syncString = `?p=${pubId}&s=${sectionId}&gc=${gcEncoded}&g=1&u=${pageUrl}`; - expect(syncs[0]).to.deep.equal({type: 'iframe', url: USER_SYNC_URL + syncString}); - }); - - it('should register trion user script with us privacy params', function () { - const uspConsent = '1YYY'; - const syncs = spec.getUserSyncs({iframeEnabled: true}, null, null, uspConsent); - const pageUrl = getPublisherUrl(); - const pubId = 1; - const sectionId = 2; - const uspEncoded = encodeURIComponent(uspConsent); - const syncString = `?p=${pubId}&s=${sectionId}&up=${uspEncoded}&u=${pageUrl}`; - expect(syncs[0]).to.deep.equal({type: 'iframe', url: USER_SYNC_URL + syncString}); - }); - - it('should except posted messages from user sync script', function () { - const testId = 'testId'; - const message = BASE_KEY + 'userId=' + testId; - setStorageData(BASE_KEY + 'int_t', null); - acceptPostMessage({data: message}); - const newKey = getStorageData(BASE_KEY + 'int_t'); - expect(newKey).to.equal(testId); - }); - - it('should not try to post messages not from trion', function () { - const testId = 'testId'; - const badId = 'badId'; - const message = 'Not Trion: userId=' + testId; - setStorageData(BASE_KEY + 'int_t', badId); - acceptPostMessage({data: message}); - const newKey = getStorageData(BASE_KEY + 'int_t'); - expect(newKey).to.equal(badId); - }); - }); -}); diff --git a/test/spec/modules/tripleliftBidAdapter_spec.js b/test/spec/modules/tripleliftBidAdapter_spec.js deleted file mode 100644 index 19c537e4d..000000000 --- a/test/spec/modules/tripleliftBidAdapter_spec.js +++ /dev/null @@ -1,1512 +0,0 @@ -import { expect } from 'chai'; -import { tripleliftAdapterSpec, storage } from 'modules/tripleliftBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { deepClone } from 'src/utils.js'; -import { config } from 'src/config.js'; -import prebid from 'package.json'; -import * as utils from 'src/utils.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -const ENDPOINT = 'https://tlx.3lift.com/header/auction?'; -const GDPR_CONSENT_STR = 'BOONm0NOONm0NABABAENAa-AAAARh7______b9_3__7_9uz_Kv_K7Vf7nnG072lPVA9LTOQ6gEaY'; -const GPP_CONSENT_STR = 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN' - -describe('triplelift adapter', function () { - const adapter = newBidder(tripleliftAdapterSpec); - let bid, instreamBid, sandbox, logErrorSpy; - - this.beforeEach(() => { - bid = { - bidder: 'triplelift', - params: { - inventoryCode: '12345', - floor: 1.0, - }, - mediaTypes: { - banner: { - sizes: [ - [970, 250], - [1, 1] - ] - } - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - - instreamBid = { - bidder: 'triplelift', - params: { - inventoryCode: 'insteam_test', - floor: 1.0, - video: { - mimes: ['video/mp4'], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480] - } - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [300, 600]], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - }) - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true for valid bid request', function () { - expect(tripleliftAdapterSpec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when required params found', function () { - bid.params.inventoryCode = 'another_inv_code'; - expect(tripleliftAdapterSpec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true when required params found - instream', function () { - expect(tripleliftAdapterSpec.isBidRequestValid(instreamBid)).to.equal(true); - }); - - it('should return true when required params found - instream - 2', function () { - delete instreamBid.mediaTypes.playerSize; - delete instreamBid.params.video.w; - delete instreamBid.params.video.h; - // the only required param is inventoryCode - expect(tripleliftAdapterSpec.isBidRequestValid(instreamBid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - delete bid.params.inventoryCode; - expect(tripleliftAdapterSpec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when required params are not passed - instream', function () { - delete instreamBid.params.inventoryCode; - expect(tripleliftAdapterSpec.isBidRequestValid(instreamBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - let bidRequests; - let bidderRequest; - const schain = { - validation: 'strict', - config: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'indirectseller.com', - sid: '00001', - hp: 1, - } - ] - } - }; - - this.beforeEach(() => { - bidRequests = [ - { - bidder: 'triplelift', - params: { - inventoryCode: '12345', - floor: 1.0, - }, - mediaTypes: { - banner: { - sizes: [ - [970, 250], - [1, 1] - ] - } - }, - adUnitCode: 'adunit-code', - sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - transactionId: '173f49a8-7549-4218-a23c-e7ba59b47229', - auctionId: '1d1a030790a475', - userId: {}, - ortb2: { - source: { - ext: { - schain - } - } - }, - ortb2Imp: { - ext: { - tid: '173f49a8-7549-4218-a23c-e7ba59b47229' - } - } - }, - { - bidder: 'triplelift', - params: { - inventoryCode: 'insteam_test', - floor: 1.0, - video: { - mimes: ['video/mp4'], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480], - playbackmethod: 5, - plcmt: 1 - } - }, - adUnitCode: 'adunit-code-instream', - sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userId: {}, - ortb2: { - source: { - ext: { - schain - } - } - }, - ortb2Imp: { - ext: { - data: { - pbAdSlot: 'homepage-top-rect', - adUnitSpecificAttribute: 123 - }, - tid: '173f49a8-7549-4218-a23c-e7ba59b47229' - } - } - }, - // banner and outstream video - { - bidder: 'triplelift', - params: { - inventoryCode: 'outstream_test', - floor: 1.0, - video: { - mimes: ['video/mp4'], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 480] - }, - banner: { - sizes: [ - [970, 250], - [1, 1] - ] - } - }, - adUnitCode: 'adunit-code-instream', - sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userId: {}, - schain, - }, - // banner and incomplete video - { - bidder: 'triplelift', - params: { - inventoryCode: 'outstream_test', - floor: 1.0, - video: { - mimes: ['video/mp4'], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - - }, - banner: { - sizes: [ - [970, 250], - [1, 1] - ] - } - }, - adUnitCode: 'adunit-code-instream', - sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userId: {}, - ortb2: { - source: { - ext: { - schain - } - } - }, - ortb2Imp: { - misc: { - test: 1 - } - } - }, - // incomplete banner and incomplete video - { - bidder: 'triplelift', - params: { - inventoryCode: 'outstream_test', - floor: 1.0, - video: { - mimes: ['video/mp4'], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - - }, - banner: { - - } - }, - adUnitCode: 'adunit-code-instream', - sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userId: {}, - schain, - }, - // banner and instream video - { - bidder: 'triplelift', - params: { - inventoryCode: 'outstream_test', - floor: 1.0, - video: { - mimes: ['video/mp4'], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480], - playbackmethod: [1, 2, 3], - plcmt: 1 - }, - banner: { - sizes: [ - [970, 250], - [1, 1] - ] - } - }, - adUnitCode: 'adunit-code-instream', - sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userId: {}, - schain, - }, - // banner and outream video and native - { - bidder: 'triplelift', - params: { - inventoryCode: 'outstream_test', - floor: 1.0, - video: { - mimes: ['video/mp4'], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 480] - }, - banner: { - sizes: [ - [970, 250], - [1, 1] - ] - }, - native: { - - } - }, - adUnitCode: 'adunit-code-instream', - sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userId: {}, - schain, - }, - // outstream video only - { - bidder: 'triplelift', - params: { - inventoryCode: 'outstream_test', - floor: 1.0, - video: { - mimes: ['video/mp4'], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 480] - } - }, - adUnitCode: 'adunit-code-outstream', - sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userId: {}, - schain, - }, - // banner and incomplete outstream (missing size) - { - bidder: 'triplelift', - params: { - inventoryCode: 'outstream_test', - floor: 1.0, - video: { - mimes: ['video/mp4'], - maxduration: 30, - minduration: 6 - } - }, - mediaTypes: { - video: { - context: 'outstream' - }, - banner: { - sizes: [ - [970, 250], - [1, 1] - ] - } - }, - adUnitCode: 'adunit-code-instream', - sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userId: {}, - schain, - }, - // outstream video; valid placement - { - bidder: 'triplelift', - params: { - inventoryCode: 'outstream_test', - floor: 1.0, - video: { - mimes: ['video/mp4'], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 480], - placement: 3 - } - }, - adUnitCode: 'adunit-code-instream', - sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userId: {}, - schain, - }, - // outstream video; valid placement - { - bidder: 'triplelift', - params: { - inventoryCode: 'outstream_test', - floor: 1.0, - video: { - mimes: ['video/mp4'], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 480], - placement: 4 - } - }, - adUnitCode: 'adunit-code-instream', - sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userId: {}, - schain, - }, - // outstream video; valid placement - { - bidder: 'triplelift', - params: { - inventoryCode: 'outstream_test', - floor: 1.0, - video: { - mimes: ['video/mp4'], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 480], - placement: 5 - } - }, - adUnitCode: 'adunit-code-instream', - sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userId: {}, - schain, - }, - // outstream video; undefined placement - { - bidder: 'triplelift', - params: { - inventoryCode: 'outstream_test', - floor: 1.0, - video: { - mimes: ['video/mp4'], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 480], - plcmt: 4 - } - }, - adUnitCode: 'adunit-code-instream', - sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userId: {}, - schain, - }, - // outstream video; invalid placement - { - bidder: 'triplelift', - params: { - inventoryCode: 'outstream_test', - floor: 1.0, - video: { - mimes: ['video/mp4'], - maxduration: 30, - minduration: 6, - w: 640, - h: 480 - } - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 480], - plcmt: 3 - } - }, - adUnitCode: 'adunit-code-instream', - sizes: [[300, 250], [300, 600], [1, 1, 1], ['flex']], - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - userId: {}, - schain, - } - ]; - - bidderRequest = { - bidderCode: 'triplelift', - auctionId: 'a7ebcd1d-66ff-4b5c-a82c-6a21a6ee5a18', - bidderRequestId: '5c55612f99bc11', - bids: [ - { - imp_id: 0, - cpm: 1.062, - width: 300, - height: 250, - ad: 'ad-markup', - iurl: 'https://s.adroll.com/a/IYR/N36/IYRN366MFVDITBAGNNT5U6.jpg' - }, - { - imp_id: 1, - crid: '10092_76480_i2j6qm8u', - cpm: 0.01, - ad: 'The Trade Desk', - tlx_source: 'hdx' - } - ], - refererInfo: { - page: 'https://examplereferer.com' - }, - gdprConsent: { - consentString: GDPR_CONSENT_STR, - gdprApplies: true - }, - }; - sandbox = sinon.createSandbox(); - logErrorSpy = sinon.spy(utils, 'logError'); - - getGlobal().bidderSettings = { - triplelift: { - storageAllowed: true - } - }; - }); - afterEach(() => { - sandbox.restore(); - utils.logError.restore(); - getGlobal().bidderSettings = {}; - }); - - it('exists and is an object', function () { - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request).to.exist.and.to.be.a('object'); - }); - - it('should be able find video object from the instream request', function () { - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.imp[1].video).to.exist.and.to.be.a('object'); - }); - - it('should only parse sizes that are of the proper length and format', function () { - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.imp[0].banner.format).to.have.length(2); - expect(request.data.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]); - }); - - it('should be a post request and populate the payload', function () { - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - expect(payload).to.exist; - expect(payload.imp[0].tagid).to.equal('12345'); - expect(payload.imp[0].floor).to.equal(1.0); - expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]); - // instream - expect(payload.imp[1].tagid).to.equal('insteam_test'); - expect(payload.imp[1].floor).to.equal(1.0); - expect(payload.imp[1].video).to.exist.and.to.be.a('object'); - expect(payload.imp[1].video.plcmt).to.equal(1); - // banner and outstream video - expect(payload.imp[2]).to.have.property('video'); - expect(payload.imp[2]).to.have.property('banner'); - expect(payload.imp[2].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]); - expect(payload.imp[2].video).to.deep.equal({'mimes': ['video/mp4'], 'maxduration': 30, 'minduration': 6, 'w': 640, 'h': 480, 'context': 'outstream'}); - // banner and incomplete video - expect(payload.imp[3]).to.not.have.property('video'); - expect(payload.imp[3]).to.have.property('banner'); - expect(payload.imp[3].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]); - // incomplete mediatypes.banner and incomplete video - expect(payload.imp[4]).to.not.have.property('video'); - expect(payload.imp[4]).to.have.property('banner'); - expect(payload.imp[4].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]); - // banner and instream video - expect(payload.imp[5]).to.not.have.property('banner'); - expect(payload.imp[5]).to.have.property('video'); - expect(payload.imp[5].video).to.exist.and.to.be.a('object'); - expect(payload.imp[5].video.plcmt).to.equal(1); - // banner and outream video and native - expect(payload.imp[6]).to.have.property('video'); - expect(payload.imp[6]).to.have.property('banner'); - expect(payload.imp[6].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]); - expect(payload.imp[6].video).to.deep.equal({'mimes': ['video/mp4'], 'maxduration': 30, 'minduration': 6, 'w': 640, 'h': 480, 'context': 'outstream'}); - // outstream video only - expect(payload.imp[7]).to.have.property('video'); - expect(payload.imp[7]).to.not.have.property('banner'); - expect(payload.imp[7].video).to.deep.equal({'mimes': ['video/mp4'], 'maxduration': 30, 'minduration': 6, 'w': 640, 'h': 480, 'context': 'outstream'}); - // banner and incomplete outstream (missing size); video request is permitted so banner can still monetize - expect(payload.imp[8]).to.have.property('video'); - expect(payload.imp[8]).to.have.property('banner'); - expect(payload.imp[8].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}]); - expect(payload.imp[8].video).to.deep.equal({'mimes': ['video/mp4'], 'maxduration': 30, 'minduration': 6, 'context': 'outstream'}); - // outstream new plcmt value - expect(payload.imp[13]).to.have.property('video'); - expect(payload.imp[13].video).to.deep.equal({'mimes': ['video/mp4'], 'maxduration': 30, 'minduration': 6, 'w': 640, 'h': 480, 'context': 'outstream', 'plcmt': 3}); - }); - - it('should check for valid outstream placement values', function () { - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - // outstream video; valid placement - expect(payload.imp[9]).to.not.have.property('banner'); - expect(payload.imp[9]).to.have.property('video'); - expect(payload.imp[9].video).to.exist.and.to.be.a('object'); - expect(payload.imp[9].video.placement).to.equal(3); - // outstream video; valid placement - expect(payload.imp[10]).to.not.have.property('banner'); - expect(payload.imp[10]).to.have.property('video'); - expect(payload.imp[10].video).to.exist.and.to.be.a('object'); - expect(payload.imp[10].video.placement).to.equal(4); - // outstream video; valid placement - expect(payload.imp[11]).to.not.have.property('banner'); - expect(payload.imp[11]).to.have.property('video'); - expect(payload.imp[11].video).to.exist.and.to.be.a('object'); - expect(payload.imp[11].video.placement).to.equal(5); - // outstream video; undefined placement - expect(payload.imp[12]).to.not.have.property('banner'); - expect(payload.imp[12]).to.have.property('video'); - expect(payload.imp[12].video).to.exist.and.to.be.a('object'); - expect(payload.imp[12].video.plcmt).to.equal(4); - // outstream video; invalid placement - expect(payload.imp[13]).to.not.have.property('banner'); - expect(payload.imp[13]).to.have.property('video'); - expect(payload.imp[13].video).to.exist.and.to.be.a('object'); - expect(payload.imp[13].video.plcmt).to.equal(3); - }); - - it('should add tid to imp.ext if transactionId exists', function() { - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.imp[0].ext.tid).to.exist.and.be.a('string'); - expect(request.data.imp[0].ext.tid).to.equal('173f49a8-7549-4218-a23c-e7ba59b47229'); - }); - - it('should not add impression ext object if ortb2Imp does not exist', function() { - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.imp[2].ext).to.not.exist; - }); - - it('should not add impression ext object if ortb2Imp.ext does not exist', function() { - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.imp[3].ext).to.not.exist; - }); - - it('should copy entire impression ext object', function() { - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.imp[1].ext).to.haveOwnProperty('tid'); - expect(request.data.imp[1].ext).to.haveOwnProperty('data'); - expect(request.data.imp[1].ext.data).to.haveOwnProperty('adUnitSpecificAttribute'); - expect(request.data.imp[1].ext.data).to.haveOwnProperty('pbAdSlot'); - expect(request.data.imp[1].ext).to.deep.equal( - { - data: { - pbAdSlot: 'homepage-top-rect', - adUnitSpecificAttribute: 123 - }, - tid: '173f49a8-7549-4218-a23c-e7ba59b47229' - } - ); - }); - - it('should add tdid to the payload if included', function () { - const tdid = '6bca7f6b-a98a-46c0-be05-6020f7604598'; - bidRequests[0].userIdAsEids = [ - { - source: 'adserver.org', - uids: [ - { - atype: 1, - ext: { - rtiPartner: 'TDID' - }, - id: tdid - } - ] - }, - ]; - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - expect(payload).to.exist; - expect(payload.user).to.deep.equal({ext: {eids: [{source: 'adserver.org', uids: [{id: tdid, atype: 1, ext: {rtiPartner: 'TDID'}}]}]}}); - }); - - it('should add criteoId to the payload if included', function () { - const id = '53e30ea700424f7bbdd793b02abc5d7'; - bidRequests[0].userIdAsEids = [ - { - source: 'criteo.com', - uids: [ - { - atype: 1, - ext: { - rtiPartner: 'criteoId' - }, - id: id - } - ] - }, - ]; - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - expect(payload).to.exist; - expect(payload.user).to.deep.equal({ext: {eids: [{source: 'criteo.com', uids: [{id: id, atype: 1, ext: {rtiPartner: 'criteoId'}}]}]}}); - }); - - it('should add tdid and criteoId to the payload if both are included', function () { - const tdid = '6bca7f6b-a98a-46c0-be05-6020f7604598'; - const criteoId = '53e30ea700424f7bbdd793b02abc5d7'; - bidRequests[0].userIdAsEids = [ - { - source: 'adserver.org', - uids: [ - { - atype: 1, - ext: { - rtiPartner: 'TDID' - }, - id: tdid - } - ] - }, - { - source: 'criteo.com', - uids: [ - { - atype: 1, - ext: { - rtiPartner: 'criteoId' - }, - id: criteoId - } - ] - }, - ]; - - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const payload = request.data; - - expect(payload).to.exist; - expect(payload.user).to.deep.equal({ - ext: { - eids: [ - { - source: 'adserver.org', - uids: [ - { - id: tdid, - atype: 1, - ext: { rtiPartner: 'TDID' } - } - ], - }, - { - source: 'criteo.com', - uids: [ - { - id: criteoId, - atype: 1, - ext: { rtiPartner: 'criteoId' } - } - ] - } - ] - } - }); - - expect(payload.user.ext.eids).to.be.an('array'); - expect(payload.user.ext.eids).to.have.lengthOf(2); - }); - - it('should return a query string for TL call', function () { - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const url = request.url; - expect(url).to.exist; - expect(url).to.be.a('string'); - expect(url).to.match(/(?:tlx.3lift.com\/header\/auction)/) - expect(url).to.match(/(?:lib=prebid)/) - expect(url).to.match(new RegExp('(?:' + prebid.version + ')')) - expect(url).to.match(/(?:referrer)/); - }); - it('should use refererInfo.page for referrer', function () { - bidderRequest.refererInfo.page = 'https://topmostlocation.com?foo=bar' - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const url = request.url; - expect(url).to.match(/(\?|&)referrer=https%3A%2F%2Ftopmostlocation.com%3Ffoo%3Dbar/); - delete bidderRequest.refererInfo.page - }); - it('should return us_privacy param when CCPA info is available', function() { - bidderRequest.uspConsent = '1YYY'; - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const url = request.url; - expect(url).to.match(/(\?|&)us_privacy=1YYY/); - }); - it('should pass fledge signal when Triplelift is eligible for fledge', function() { - bidderRequest.paapi = {enabled: true}; - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const url = request.url; - expect(url).to.match(/(\?|&)fledge=true/); - }); - it('should return coppa param when COPPA config is set to true', function() { - sinon.stub(config, 'getConfig').withArgs('coppa').returns(true); - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - config.getConfig.restore(); - const url = request.url; - expect(url).to.match(/(\?|&)coppa=true/); - }); - it('should not return coppa param when COPPA config is set to false', function() { - sinon.stub(config, 'getConfig').withArgs('coppa').returns(false); - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - config.getConfig.restore(); - const url = request.url; - expect(url).not.to.match(/(\?|&)coppa=/); - }); - it('should return schain when present', function() { - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const { data: payload } = request; - expect(payload.ext.schain).to.deep.equal(schain); - }); - it('should not create root level ext when schain is not present', function() { - delete bidRequests[0].ortb2.source.ext.schain; - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - const { data: payload } = request; - expect(payload.ext).to.deep.equal(undefined); - }); - it('should get floor from floors module if available', function() { - let floorInfo; - bidRequests[0].getFloor = () => floorInfo; - - // standard float response; expected functionality of floors module - floorInfo = { currency: 'USD', floor: 1.99 }; - let request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.imp[0].floor).to.equal(1.99); - - // if string response, convert to float - floorInfo = { currency: 'USD', floor: '1.99' }; - request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.imp[0].floor).to.equal(1.99); - }); - it('should call getFloor with the correct parameters based on mediaType', function() { - bidRequests.forEach(request => { - request.getFloor = () => {}; - sinon.spy(request, 'getFloor') - }); - - tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - - // banner - expect(bidRequests[0].getFloor.calledWith({ - currency: 'USD', - mediaType: 'banner', - size: '*' - })).to.be.true; - - // instream - expect(bidRequests[1].getFloor.calledWith({ - currency: 'USD', - mediaType: 'video', - size: '*' - })).to.be.true; - - // banner and incomplete video (POST will only include banner) - expect(bidRequests[3].getFloor.calledWith({ - currency: 'USD', - mediaType: 'banner', - size: '*' - })).to.be.true; - - // banner and instream (POST will only include video) - expect(bidRequests[5].getFloor.calledWith({ - currency: 'USD', - mediaType: 'video', - size: '*' - })).to.be.true; - }); - it('should catch error if getFloor throws error', function() { - bidRequests[0].getFloor = () => { - throw new Error('An exception!'); - }; - - tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - - expect(logErrorSpy.calledOnce).to.equal(true); - }); - it('should add ortb2 ext object if global fpd is available', function() { - const ortb2 = { - site: { - domain: 'page.example.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'], - page: 'https://page.example.com/here.html', - }, - user: { - yob: 1985, - gender: 'm', - keywords: 'a,b', - data: [ - { - name: 'dataprovider.com', - ext: { segtax: 4 }, - segment: [{ id: '1' }] - } - ], - ext: { - data: { - registered: true, - interests: ['cars'] - } - } - } - }; - - const request = tripleliftAdapterSpec.buildRequests(bidRequests, {...bidderRequest, ortb2}); - const { data: payload } = request; - expect(payload.ext.ortb2).to.exist; - expect(payload.ext.ortb2.site).to.deep.equal({ - domain: 'page.example.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'], - page: 'https://page.example.com/here.html', - }); - }); - it('should send global config fpd if kvps are available', function() { - const sens = null; - const category = ['news', 'weather', 'hurricane']; - const pmp_elig = 'true'; - const ortb2 = { - site: { - pmp_elig: pmp_elig, - ext: { - data: { - category: category - } - } - }, - user: { - sens: sens, - } - } - const request = tripleliftAdapterSpec.buildRequests(bidRequests, {...bidderRequest, ortb2}); - const { data: payload } = request; - expect(payload.ext.fpd.user).to.not.exist; - expect(payload.ext.fpd.context.ext.data).to.haveOwnProperty('category'); - expect(payload.ext.fpd.context).to.haveOwnProperty('pmp_elig'); - }); - it('should send ad unit fpd if kvps are available', function() { - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.imp[1].fpd.context).to.haveOwnProperty('data'); - expect(request.data.imp[1].fpd.context.data).to.haveOwnProperty('pbAdSlot'); - expect(request.data.imp[1].fpd.context.data).to.haveOwnProperty('adUnitSpecificAttribute'); - expect(request.data.imp[2].fpd).to.not.exist; - }); - it('should send 1PlusX data as fpd if localStorage is available and no other fpd is defined', function() { - sandbox.stub(storage, 'getDataFromLocalStorage').callsFake(() => '{"kid":1,"s":"ySRdArquXuBolr/cVv0UNqrJhTO4QZsbNH/t+2kR3gXjbA==","t":"/yVtBrquXuBolr/cVv0UNtx1mssdLYeKFhWFI3Dq1dJnug=="}'); - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.ext.fpd).to.deep.equal({ - 'user': { - 'data': [ - { - 'name': 'www.1plusx.com', - 'ext': { - 'kid': 1, - 's': 'ySRdArquXuBolr/cVv0UNqrJhTO4QZsbNH/t+2kR3gXjbA==', - 't': '/yVtBrquXuBolr/cVv0UNtx1mssdLYeKFhWFI3Dq1dJnug==' - } - } - ] - } - }) - }); - it('should append 1PlusX data to existing user.data entries if localStorage is available', function() { - bidderRequest.ortb2 = { - user: { - data: [ - { name: 'dataprovider.com', ext: { segtax: 4 }, segment: [{ id: '1' }] } - ] - } - } - sandbox.stub(storage, 'getDataFromLocalStorage').callsFake(() => '{"kid":1,"s":"ySRdArquXuBolr/cVv0UNqrJhTO4QZsbNH/t+2kR3gXjbA==","t":"/yVtBrquXuBolr/cVv0UNtx1mssdLYeKFhWFI3Dq1dJnug=="}'); - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.ext.fpd).to.deep.equal({ - 'user': { - 'data': [ - { 'name': 'dataprovider.com', 'ext': { 'segtax': 4 }, 'segment': [{ 'id': '1' }] }, - { - 'name': 'www.1plusx.com', - 'ext': { - 'kid': 1, - 's': 'ySRdArquXuBolr/cVv0UNqrJhTO4QZsbNH/t+2kR3gXjbA==', - 't': '/yVtBrquXuBolr/cVv0UNtx1mssdLYeKFhWFI3Dq1dJnug==' - } - } - ] - } - }) - }); - it('should not append anything if getDataFromLocalStorage returns null', function() { - bidderRequest.ortb2 = { - user: { - data: [ - { name: 'dataprovider.com', ext: { segtax: 4 }, segment: [{ id: '1' }] } - ] - } - } - sandbox.stub(storage, 'getDataFromLocalStorage').callsFake(() => null); - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.ext.fpd).to.deep.equal({ - 'user': { - 'data': [ - { 'name': 'dataprovider.com', 'ext': { 'segtax': 4 }, 'segment': [{ 'id': '1' }] }, - ] - } - }) - }); - it('should add gpp consent data to bid request object if gpp data exists', function() { - bidderRequest.ortb2 = { - regs: { - 'gpp': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - 'gpp_sid': [7] - } - } - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.regs).to.deep.equal({ - 'gpp': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - 'gpp_sid': [7] - }) - }); - it('should cast playbackmethod as an array if it is an integer and it exists', function() { - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.imp[1].video.playbackmethod).to.be.a('array'); - expect(request.data.imp[1].video.playbackmethod).to.deep.equal([5]); - }); - it('should set playbackmethod as an array if it exists as an array', function() { - const request = tripleliftAdapterSpec.buildRequests(bidRequests, bidderRequest); - expect(request.data.imp[5].video.playbackmethod).to.be.a('array'); - expect(request.data.imp[5].video.playbackmethod).to.deep.equal([1, 2, 3]); - }); - }); - - describe('interpretResponse', function () { - let response, bidderRequest; - this.beforeEach(() => { - response = { - body: { - bids: [ - { - imp_id: 0, - cpm: 1.062, - width: 300, - height: 250, - ad: 'ad-markup', - iurl: 'https://s.adroll.com/a/IYR/N36/IYRN366MFVDITBAGNNT5U6.jpg', - tl_source: 'tlx', - advertiser_name: 'fake advertiser name', - adomain: ['basspro.com', 'internetalerts.org'], - media_type: 'banner' - }, - { - imp_id: 1, - crid: '10092_76480_i2j6qm8u', - cpm: 9.99, - ad: 'The Trade Desk', - tl_source: 'hdx', - media_type: 'video' - }, - // video bid on banner+outstream request - { - imp_id: 2, - crid: '5989_33264_352817187', - cpm: 20, - ad: '\n \n \t', - tl_source: 'hdx', - advertiser_name: 'zennioptical.com', - adomain: ['zennioptical.com'], - media_type: 'video' - }, - // banner bid on banner+outstream request - { - imp_id: 3, - crid: '5989_33264_352817187', - cpm: 20, - width: 970, - height: 250, - ad: 'ad-markup', - tl_source: 'hdx', - advertiser_name: 'zennioptical.com', - adomain: ['zennioptical.com'], - media_type: 'banner' - } - ] - } - }; - bidderRequest = { - bidderCode: 'triplelift', - auctionId: 'a7ebcd1d-66ff-4b5c-a82c-6a21a6ee5a18', - bidderRequestId: '5c55612f99bc11', - bids: [ - { - imp_id: 0, - cpm: 1.062, - width: 300, - height: 250, - ad: 'ad-markup', - iurl: 'https://s.adroll.com/a/IYR/N36/IYRN366MFVDITBAGNNT5U6.jpg', - tl_source: 'tlx', - mediaTypes: { - banner: { - sizes: [ - [970, 250], - [1, 1] - ] - } - }, - bidId: '30b31c1838de1e' - }, - { - imp_id: 1, - crid: '10092_76480_i2j6qm8u', - cpm: 9.99, - ad: 'The Trade Desk', - tlx_source: 'hdx', - mediaTypes: { - video: { - context: 'instream', - playerSize: [640, 480] - } - }, - bidId: '30b31c1838de1e' - }, - // banner and outstream - { - bidder: 'triplelift', - params: { - inventoryCode: 'testing_desktop_outstream', - floor: 1 - }, - nativeParams: {}, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[640, 480]], - mimes: ['video/mp4'], - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - playbackmethod: [2], - skip: 1 - }, - banner: { - sizes: [ - [728, 90], - [970, 250], - [970, 90] - ] - }, - native: {} - }, - adUnitCode: 'video-outstream', - transactionId: '135061c3-f546-4e28-8a07-44c2fb58a958', - sizes: [ - [728, 90], - [970, 250], - [970, 90] - ], - bidId: '73edc0ba8de203', - bidderRequestId: '3d81143328560b', - auctionId: 'f6427dc0-b954-4010-a76c-d498380796a2', - src: 'client', - bidRequestsCount: 2, - bidderRequestsCount: 2, - bidderWinsCount: 0 - }, - // banner and outstream - { - bidder: 'triplelift', - params: { - inventoryCode: 'testing_desktop_outstream', - floor: 1 - }, - nativeParams: {}, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[640, 480]], - mimes: ['video/mp4'], - protocols: [1, 2, 3, 4, 5, 6, 7, 8], - playbackmethod: [2], - skip: 1 - }, - banner: { - sizes: [ - [728, 90], - [970, 250], - [970, 90] - ] - }, - native: {} - }, - adUnitCode: 'video-outstream', - transactionId: '135061c3-f546-4e28-8a07-44c2fb58a958', - sizes: [ - [728, 90], - [970, 250], - [970, 90] - ], - bidId: '73edc0ba8de203', - bidderRequestId: '3d81143328560b', - auctionId: 'f6427dc0-b954-4010-a76c-d498380796a2', - src: 'client', - bidRequestsCount: 2, - bidderRequestsCount: 2, - bidderWinsCount: 0 - } - ], - refererInfo: { - referer: 'https://examplereferer.com' - }, - gdprConsent: { - consentString: GDPR_CONSENT_STR, - gdprApplies: true - } - }; - }) - - it('should get correct bid response', function () { - const expectedResponse = [ - { - requestId: '30b31c1838de1e', - cpm: 1.062, - width: 300, - height: 250, - netRevenue: true, - ad: 'ad-markup', - creativeId: 29681110, - dealId: '', - currency: 'USD', - ttl: 33, - tl_source: 'tlx', - meta: {} - }, - { - requestId: '30b31c1838de1e', - cpm: 1.062, - width: 300, - height: 250, - netRevenue: true, - ad: 'The Trade Desk', - creativeId: 29681110, - dealId: '', - currency: 'USD', - ttl: 33, - tl_source: 'hdx', - mediaType: 'video', - vastXml: 'The Trade Desk', - meta: {} - } - ]; - const result = tripleliftAdapterSpec.interpretResponse(response, {bidderRequest}); - expect(result).to.have.length(4); - expect(Object.keys(result[0])).to.have.members(Object.keys(expectedResponse[0])); - expect(Object.keys(result[1])).to.have.members(Object.keys(expectedResponse[1])); - expect(result[0].ttl).to.equal(300); - expect(result[1].ttl).to.equal(3600); - }); - - it('should identify format of bid and respond accordingly', function() { - const result = tripleliftAdapterSpec.interpretResponse(response, {bidderRequest}); - expect(result[0].meta.mediaType).to.equal('native'); - expect(result[1].mediaType).to.equal('video'); - expect(result[1].meta.mediaType).to.equal('video'); - // video bid on banner+outstream request - expect(result[2].mediaType).to.equal('video'); - expect(result[2].meta.mediaType).to.equal('video'); - expect(result[2].vastXml).to.include('aid=148508128401385324170&inv_code=testing_mobile_outstream'); - // banner bid on banner+outstream request - expect(result[3].meta.mediaType).to.equal('banner'); - }) - - it('should return multiple responses to support SRA', function () { - const result = tripleliftAdapterSpec.interpretResponse(response, {bidderRequest}); - expect(result).to.have.length(4); - }); - - it('should include the advertiser name in the meta field if available', function () { - const result = tripleliftAdapterSpec.interpretResponse(response, {bidderRequest}); - expect(result[0].meta.advertiserName).to.equal('fake advertiser name'); - expect(result[1].meta).to.not.have.key('advertiserName'); - }); - - it('should include the advertiser domain array in the meta field if available', function () { - const result = tripleliftAdapterSpec.interpretResponse(response, {bidderRequest}); - expect(result[0].meta.advertiserDomains[0]).to.equal('basspro.com'); - expect(result[0].meta.advertiserDomains[1]).to.equal('internetalerts.org'); - expect(result[1].meta).to.not.have.key('advertiserDomains'); - }); - - it('should include networkId in the meta field if available', function () { - const result = tripleliftAdapterSpec.interpretResponse(response, {bidderRequest}); - expect(result[1].meta.networkId).to.equal('10092'); - expect(result[2].meta.networkId).to.equal('5989'); - expect(result[3].meta.networkId).to.equal('5989'); - }); - - it('should return fledgeAuctionConfigs if PAAPI response is received', function() { - response.body.paapi = [ - { - imp_id: '0', - auctionConfig: { - seller: 'https://3lift.com', - decisionLogicUrl: 'https://3lift.com/decision_logic.js', - interestGroupBuyers: ['https://some_buyer.com'], - perBuyerSignals: { - 'https://some_buyer.com': { a: 1 } - } - } - }, - { - imp_id: '2', - auctionConfig: { - seller: 'https://3lift.com', - decisionLogicUrl: 'https://3lift.com/decision_logic.js', - interestGroupBuyers: ['https://some_other_buyer.com'], - perBuyerSignals: { - 'https://some_other_buyer.com': { b: 2 } - } - } - } - ]; - - const result = tripleliftAdapterSpec.interpretResponse(response, {bidderRequest}); - - expect(result).to.have.property('bids'); - expect(result).to.have.property('paapi'); - expect(result.paapi.length).to.equal(2); - expect(result.paapi[0].bidId).to.equal('30b31c1838de1e'); - expect(result.paapi[1].bidId).to.equal('73edc0ba8de203'); - expect(result.paapi[0].config).to.deep.equal( - { - 'seller': 'https://3lift.com', - 'decisionLogicUrl': 'https://3lift.com/decision_logic.js', - 'interestGroupBuyers': ['https://some_buyer.com'], - 'perBuyerSignals': { 'https://some_buyer.com': { 'a': 1 } } - } - ); - expect(result.paapi[1].config).to.deep.equal( - { - 'seller': 'https://3lift.com', - 'decisionLogicUrl': 'https://3lift.com/decision_logic.js', - 'interestGroupBuyers': ['https://some_other_buyer.com'], - 'perBuyerSignals': { 'https://some_other_buyer.com': { 'b': 2 } } - } - ); - }); - }); - - describe('getUserSyncs', function() { - const expectedIframeSyncUrl = 'https://eb2.3lift.com/sync?gdpr=true&cmp_cs=' + GDPR_CONSENT_STR + '&'; - const expectedImageSyncUrl = 'https://eb2.3lift.com/sync?px=1&src=prebid&gdpr=true&cmp_cs=' + GDPR_CONSENT_STR + '&'; - const expectedGppSyncUrl = 'https://eb2.3lift.com/sync?gdpr=true&cmp_cs=' + GDPR_CONSENT_STR + '&gpp=' + GPP_CONSENT_STR + '&gpp_sid=2%2C8' + '&'; - - it('returns undefined when syncing is not enabled', function() { - expect(tripleliftAdapterSpec.getUserSyncs({})).to.equal(undefined); - expect(tripleliftAdapterSpec.getUserSyncs()).to.equal(undefined); - }); - - it('returns iframe user sync pixel when iframe syncing is enabled', function() { - const syncOptions = { - iframeEnabled: true - }; - const result = tripleliftAdapterSpec.getUserSyncs(syncOptions); - expect(result[0].type).to.equal('iframe'); - expect(result[0].url).to.equal(expectedIframeSyncUrl); - }); - - it('returns image user sync pixel when iframe syncing is disabled', function() { - const syncOptions = { - pixelEnabled: true - }; - const result = tripleliftAdapterSpec.getUserSyncs(syncOptions); - expect(result[0].type).to.equal('image') - expect(result[0].url).to.equal(expectedImageSyncUrl); - }); - - it('returns iframe user sync pixel when both options are enabled', function() { - const syncOptions = { - pixelEnabled: true, - iframeEnabled: true - }; - const result = tripleliftAdapterSpec.getUserSyncs(syncOptions); - expect(result[0].type).to.equal('iframe'); - expect(result[0].url).to.equal(expectedIframeSyncUrl); - }); - it('sends us_privacy param when info is available', function() { - const syncOptions = { - iframeEnabled: true - }; - const result = tripleliftAdapterSpec.getUserSyncs(syncOptions, null, null, '1YYY', null); - expect(result[0].url).to.match(/(\?|&)us_privacy=1YYY/); - }); - it('returns a user sync pixel with GPP signals when available', function() { - const syncOptions = { - iframeEnabled: true - }; - const gppConsent = { - 'applicableSections': [2, 8], - 'gppString': 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN' - } - const result = tripleliftAdapterSpec.getUserSyncs(syncOptions, null, null, null, gppConsent); - expect(result[0].url).to.equal(expectedGppSyncUrl); - }); - }); -}); diff --git a/test/spec/modules/truereachBidAdapter_spec.js b/test/spec/modules/truereachBidAdapter_spec.js deleted file mode 100644 index 6b39d46ea..000000000 --- a/test/spec/modules/truereachBidAdapter_spec.js +++ /dev/null @@ -1,102 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/truereachBidAdapter.js'; - -describe('truereachBidAdapterTests', function () { - it('validate_pub_params', function () { - expect(spec.isBidRequestValid({ - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - bidder: 'truereach', - params: { - site_id: '0142010a-8400-1b01-72cb-a553b9000009', - } - })).to.equal(true); - }); - - it('validate_generated_params', function () { - const bidRequestData = [{ - bidId: '34ce3f3b15190a', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - bidder: 'truereach', - params: { - site_id: '0142010a-8400-1b01-72cb-a553b9000009' - }, - sizes: [[300, 250]] - }]; - - const request = spec.buildRequests(bidRequestData, {}); - const req_data = request.data; - - expect(request.method).to.equal('POST'); - expect(req_data.imp[0].id).to.equal('34ce3f3b15190a'); - expect(req_data.imp[0].banner.w).to.equal(300); - expect(req_data.imp[0].banner.h).to.equal(250); - }); - - it('validate_response_params', function () { - const serverResponse = { - body: { - 'id': '34ce3f3b15190a', - 'seatbid': [{ - 'bid': [{ - 'id': '0142010a-8400-0801-72dc-04a99e6f7fc0:1ed', - 'impid': '34ce3f3b15190a', - 'price': 2.55, - 'adm': '', - 'adid': '493', - 'adomain': ['https://www.momagic.com/'], - 'iurl': '', - 'cid': '260', - 'crid': '0142010a-8400-1b01-72cb-afb296000012', - 'w': 300, - 'h': 250 - }] - }], - 'bidid': '0142010a-8400-0801-72dc-04a99e6f7fc1', - 'cur': 'USD' - } - }; - - const bids = spec.interpretResponse(serverResponse, {}); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.requestId).to.equal('34ce3f3b15190a'); - expect(bid.cpm).to.equal(2.55); - expect(bid.currency).to.equal('USD'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.ad).to.equal(''); - expect(bid.ttl).to.equal(180); - expect(bid.creativeId).to.equal('0142010a-8400-1b01-72cb-afb296000012'); - expect(bid.netRevenue).to.equal(false); - expect(bid.meta.advertiserDomains[0]).to.equal('https://www.momagic.com/'); - }); - - describe('user_sync', function() { - const user_sync_url = 'https://ads-sg.momagic.com/jsp/usersync.jsp'; - it('register_iframe_pixel_if_iframeEnabled_is_true', function() { - const syncs = spec.getUserSyncs( - {iframeEnabled: true} - ); - expect(syncs).to.be.an('array'); - expect(syncs.length).to.equal(1); - expect(syncs[0].type).to.equal('iframe'); - expect(syncs[0].url).to.equal(user_sync_url); - }); - - it('if_pixelEnabled_is_true', function() { - const syncs = spec.getUserSyncs( - {pixelEnabled: true} - ); - expect(syncs).to.be.an('array'); - expect(syncs.length).to.equal(0); - }); - }); -}); diff --git a/test/spec/modules/ttdBidAdapter_spec.js b/test/spec/modules/ttdBidAdapter_spec.js deleted file mode 100644 index c11378e72..000000000 --- a/test/spec/modules/ttdBidAdapter_spec.js +++ /dev/null @@ -1,1697 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/ttdBidAdapter'; -import { deepClone } from 'src/utils.js'; -import { config } from 'src/config'; -import { detectReferer } from 'src/refererDetection.js'; - -import { buildWindowTree } from '../../helpers/refererDetectionHelper.js'; - -describe('ttdBidAdapter', function () { - function testBuildRequests(bidRequests, bidderRequestBase) { - const clonedBidderRequest = deepClone(bidderRequestBase); - clonedBidderRequest.bids = bidRequests; - return spec.buildRequests(bidRequests, clonedBidderRequest); - } - - describe('isBidRequestValid', function() { - function makeBid() { - return { - 'bidder': 'ttd', - 'params': { - 'supplySourceId': 'supplier', - 'publisherId': '22222222', - 'placementId': 'some-PlacementId_1' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [300, 250] - ] - } - }, - 'adUnitCode': 'adunit-code', - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - } - - describe('core', function () { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(makeBid())).to.equal(true); - }); - - it('should return false when publisherId not passed', function () { - const bid = makeBid(); - delete bid.params.publisherId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when supplySourceId not passed', function () { - const bid = makeBid(); - delete bid.params.supplySourceId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when publisherId is longer than 64 characters', function () { - const bid = makeBid(); - bid.params.publisherId = '1'.repeat(65); - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true when publisherId is equal to 64 characters', function () { - const bid = makeBid(); - bid.params.publisherId = '1'.repeat(64); - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return true if placementId is not passed and gpid is passed', function () { - const bid = makeBid(); - delete bid.params.placementId; - bid.ortb2Imp = { - ext: { - gpid: '/1111/home#header' - } - } - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false if neither placementId nor gpid is passed', function () { - const bid = makeBid(); - delete bid.params.placementId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if neither mediaTypes.banner nor mediaTypes.video is passed', function () { - const bid = makeBid(); - delete bid.mediaTypes - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if bidfloor is passed incorrectly', function () { - const bid = makeBid(); - bid.params.bidfloor = 'invalid bidfloor'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true if bidfloor is passed correctly as a float', function () { - const bid = makeBid(); - bid.params.bidfloor = 3.01; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false if customBidderEndpoint is provided and does not start with https://', function () { - const bid = makeBid(); - bid.params.customBidderEndpoint = 'customBidderEndpoint/bid/bidder/'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if customBidderEndpoint is provided and does not end with /bid/bidder/', function () { - const bid = makeBid(); - bid.params.customBidderEndpoint = 'https://customBidderEndpoint/bid/bidder'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true if customBidderEndpoint is provided that starts with https:// and ends with /bid/bidder/', function () { - const bid = makeBid(); - bid.params.customBidderEndpoint = 'https://customBidderEndpoint/bid/bidder/'; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - - describe('banner', function () { - it('should return true if banner.pos is passed correctly', function () { - const bid = makeBid(); - bid.mediaTypes.banner.pos = 1; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - - describe('video', function () { - if (!FEATURES.VIDEO) { - return; - } - - function makeBid() { - return { - 'bidder': 'ttd', - 'params': { - 'supplySourceId': 'supplier', - 'publisherId': '22222222', - 'placementId': 'somePlacementId' - }, - 'mediaTypes': { - 'video': { - 'minduration': 5, - 'maxduration': 30, - 'playerSize': [640, 480], - 'api': [1, 3], - 'mimes': ['video/mp4'], - 'protocols': [2, 3, 5, 6] - } - }, - 'adUnitCode': 'adunit-code', - 'sizes': [ - [300, 250] - ], - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - } - - it('should return true if required parameters are passed', function () { - const bid = makeBid(); - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false if maxduration is missing', function () { - const bid = makeBid(); - delete bid.mediaTypes.video.maxduration; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if api is missing', function () { - const bid = makeBid(); - delete bid.mediaTypes.video.api; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if mimes is missing', function () { - const bid = makeBid(); - delete bid.mediaTypes.video.mimes; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false if protocols is missing', function () { - const bid = makeBid(); - delete bid.mediaTypes.video.protocols; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - }); - - describe('getUserSyncs', function () { - it('to check the user sync iframe', function () { - const syncOptions = { - pixelEnabled: true - }; - const gdprConsentString = 'BON3G4EON3G4EAAABAENAA____ABl____A'; - const gdprConsent = { - consentString: gdprConsentString, - gdprApplies: true - }; - const uspConsent = '1YYY'; - - const syncs = spec.getUserSyncs(syncOptions, [], gdprConsent, uspConsent); - expect(syncs).to.have.lengthOf(1); - expect(syncs[0].type).to.equal('image'); - - const params = new URLSearchParams(new URL(syncs[0].url).search); - expect(params.get('us_privacy')).to.equal(uspConsent); - expect(params.get('ust')).to.equal('image'); - expect(params.get('gdpr')).to.equal('1'); - expect(params.get('gdpr_consent')).to.equal(gdprConsentString); - }); - }); - - describe('buildRequests-banner', function () { - const baseBannerBidRequests = [{ - 'bidder': 'ttd', - 'params': { - 'supplySourceId': 'supplier', - 'publisherId': '13144370', - 'placementId': '1gaa015' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 600]] - } - }, - 'ortb2Imp': { - 'ext': { - 'tid': '8651474f-58b1-4368-b812-84f8c937a099', - } - }, - 'sizes': [[300, 250], [300, 600]], - 'transactionId': '1111474f-58b1-4368-b812-84f8c937a099', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'bidId': '243310435309b5', - 'bidderRequestId': '18084284054531', - 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'src': 'client', - 'bidRequestsCount': 1 - }]; - - const testWindow = buildWindowTree(['https://www.example.com/test', 'https://www.example.com/other/page', 'https://www.example.com/third/page'], 'https://othersite.com/', 'https://example.com/canonical/page'); - const baseBidderRequestReferer = detectReferer(testWindow)(); - const baseBidderRequest = { - 'bidderCode': 'ttd', - ortb2: { - source: { - tid: 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - } - }, - 'bidderRequestId': '18084284054531', - 'auctionStart': 1540945362095, - 'timeout': 3000, - 'refererInfo': baseBidderRequestReferer, - 'start': 1540945362099, - 'doneCbCallCount': 0 - }; - - const extFirstPartyDataValues = ['value', 'value2']; - const extFirstPartyData = { - data: { - firstPartyKey: 'firstPartyValue', - firstPartyKey2: extFirstPartyDataValues - }, - custom: 'custom_data', - custom_kvp: { - customKey: 'customValue' - } - } - - function validateExtFirstPartyData(ext) { - expect(ext.data.firstPartyKey).to.equal('firstPartyValue'); - expect(ext.data.firstPartyKey2).to.eql(extFirstPartyDataValues); - expect(ext.custom).to.equal('custom_data'); - expect(ext.custom_kvp.customKey).to.equal('customValue'); - } - - it('sends bid request to our endpoint that makes sense', function () { - const request = testBuildRequests(baseBannerBidRequests, baseBidderRequest); - expect(request.method).to.equal('POST'); - expect(request.url).to.be.not.empty; - expect(request.data).to.be.not.null; - }); - - it('bid request should parse tmax or have a default and minimum', function () { - const requestWithoutTimeout = { - ...baseBidderRequest, - timeout: null - }; - var requestBody = testBuildRequests(baseBannerBidRequests, requestWithoutTimeout).data; - expect(requestBody.tmax).to.be.equal(400); - - const requestWithTimeout = { - ...baseBidderRequest, - timeout: 600 - }; - requestBody = testBuildRequests(baseBannerBidRequests, requestWithTimeout).data; - expect(requestBody.tmax).to.be.equal(600); - - const requestWithLowerTimeout = { - ...baseBidderRequest, - timeout: 300 - }; - requestBody = testBuildRequests(baseBannerBidRequests, requestWithLowerTimeout).data; - expect(requestBody.tmax).to.be.equal(400); - }); - - it('sets bidrequest.id to bidderRequestId', function () { - const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest).data; - expect(requestBody.id).to.equal('18084284054531'); - }); - - it('sets impression id to ad unit\'s bid id', function () { - const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest).data; - expect(requestBody.imp[0].id).to.equal('243310435309b5'); - }); - - it('sends bid requests to the correct endpoint', function () { - const url = testBuildRequests(baseBannerBidRequests, baseBidderRequest).url; - expect(url).to.equal('https://direct.adsrvr.org/bid/bidder/supplier'); - }); - - it('sends bid requests to the correct http2 endpoint', function () { - const bannerBidRequestsWithHttp2Endpoint = deepClone(baseBannerBidRequests); - bannerBidRequestsWithHttp2Endpoint[0].params.useHttp2 = true; - const url = testBuildRequests(bannerBidRequestsWithHttp2Endpoint, baseBidderRequest).url; - expect(url).to.equal('https://d2.adsrvr.org/bid/bidder/supplier'); - }); - - it('sends bid requests to the correct custom endpoint', function () { - const bannerBidRequestsWithCustomEndpoint = deepClone(baseBannerBidRequests); - bannerBidRequestsWithCustomEndpoint[0].params.customBidderEndpoint = 'https://customBidderEndpoint/bid/bidder/'; - const url = testBuildRequests(bannerBidRequestsWithCustomEndpoint, baseBidderRequest).url; - expect(url).to.equal('https://customBidderEndpoint/bid/bidder/supplier'); - }); - - it('sends publisher id', function () { - const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest).data; - expect(requestBody.site).to.be.not.null; - expect(requestBody.site.publisher).to.be.not.null; - expect(requestBody.site.publisher.id).to.equal(baseBannerBidRequests[0].params.publisherId); - }); - - it('sends placement id in tagid', function () { - const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest).data; - expect(requestBody.imp[0].tagid).to.equal(baseBannerBidRequests[0].params.placementId); - }); - - it('sends gpid in tagid if present', function () { - const clonedBannerRequests = deepClone(baseBannerBidRequests); - const gpid = '/1111/home#header'; - clonedBannerRequests[0].ortb2Imp = { - ext: { - gpid: gpid - } - }; - const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data; - expect(requestBody.imp[0].tagid).to.equal(gpid); - }); - - it('sends gpid in ext.gpid if present', function () { - const clonedBannerRequests = deepClone(baseBannerBidRequests); - const gpid = '/1111/home#header'; - clonedBannerRequests[0].ortb2Imp = { - ext: { - gpid: gpid - } - }; - const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data; - expect(requestBody.imp[0].ext).to.be.not.null; - expect(requestBody.imp[0].ext.gpid).to.equal(gpid); - }); - - it('sends rwdd in imp.rwdd if present', function () { - const clonedBannerRequests = deepClone(baseBannerBidRequests); - const gpid = '/1111/home#header'; - const rwdd = 1; - clonedBannerRequests[0].ortb2Imp = { - rwdd: rwdd, - ext: { - gpid: gpid - } - }; - const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data; - expect(requestBody.imp[0].rwdd).to.be.not.null; - expect(requestBody.imp[0].rwdd).to.equal(1); - }); - - it('sends source.tid', function () { - const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest).data; - expect(requestBody.source).to.be.not.null; - expect(requestBody.source.tid).to.equal(baseBidderRequest.ortb2.source.tid); - }); - - it('includes the ad size in the bid request', function () { - const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest).data; - expect(requestBody.imp[0].banner.format[0].w).to.equal(300); - expect(requestBody.imp[0].banner.format[0].h).to.equal(250); - expect(requestBody.imp[0].banner.format[1].w).to.equal(300); - expect(requestBody.imp[0].banner.format[1].h).to.equal(600); - }); - - it('includes the detected referer in the bid request', function () { - const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest).data; - expect(requestBody.site.page).to.equal('https://www.example.com/test'); - }); - - it('ensure top most location is used', function () { - const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest).data; - expect(requestBody.site.page).to.equal('https://www.example.com/test'); - }); - - it('sets the banner pos correctly if sent', function () { - const clonedBannerRequests = deepClone(baseBannerBidRequests); - clonedBannerRequests[0].mediaTypes.banner.pos = 1; - - const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data; - expect(requestBody.imp[0].banner.pos).to.equal(1); - }); - - it('sets the banner expansion direction correctly if sent', function () { - const clonedBannerRequests = deepClone(baseBannerBidRequests); - const expdir = [1, 3] - clonedBannerRequests[0].params.banner = { - expdir: expdir - }; - - const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data; - expect(requestBody.imp[0].banner.expdir).to.equal(expdir); - }); - - it('merges first party site data', function () { - const ortb2 = { - site: { - publisher: { - domain: 'https://foo.bar', - } - } - }; - const baseBidderRequestWithoutRefererDomain = { - ...baseBidderRequest, - refererInfo: { - ...baseBannerBidRequests.referer, - domain: null - } - } - const requestBody = testBuildRequests( - baseBannerBidRequests, {...baseBidderRequestWithoutRefererDomain, ortb2} - ).data; - config.resetConfig(); - expect(requestBody.site.publisher).to.deep.equal({domain: 'https://foo.bar', id: '13144370'}); - }); - - it('referer domain overrides first party site data publisher domain', function () { - const ortb2 = { - site: { - publisher: { - domain: 'https://foo.bar', - } - } - }; - const requestBody = testBuildRequests( - baseBannerBidRequests, {...baseBidderRequest, ortb2} - ).data; - config.resetConfig(); - expect(requestBody.site.publisher.domain).to.equal(baseBidderRequest.refererInfo.domain); - }); - - it('sets keywords properly if sent', function () { - const ortb2 = { - site: { - keywords: 'highViewability, clothing, holiday shopping' - } - }; - const requestBody = testBuildRequests(baseBannerBidRequests, {...baseBidderRequest, ortb2}).data; - config.resetConfig(); - expect(requestBody.ext.ttdprebid.keywords).to.deep.equal(['highViewability', 'clothing', 'holiday shopping']); - }); - - it('sets bcat properly if sent', function () { - const ortb2 = { - bcat: ['IAB1-1', 'IAB2-9'] - }; - const requestBody = testBuildRequests(baseBannerBidRequests, {...baseBidderRequest, ortb2}).data; - config.resetConfig(); - expect(requestBody.bcat).to.deep.equal(['IAB1-1', 'IAB2-9']); - }); - - it('sets badv properly if sent', function () { - const ortb2 = { - badv: ['adv1.com', 'adv2.com'] - }; - const requestBody = testBuildRequests(baseBannerBidRequests, {...baseBidderRequest, ortb2}).data; - config.resetConfig(); - expect(requestBody.badv).to.deep.equal(['adv1.com', 'adv2.com']); - }); - - it('sets battr properly if present', function () { - const clonedBannerRequests = deepClone(baseBannerBidRequests); - const battr = [1, 2, 3]; - clonedBannerRequests[0].ortb2Imp = { - banner: { - battr: battr - } - }; - const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data; - expect(requestBody.imp[0].banner.battr).to.equal(battr); - }); - - it('sets ext properly', function () { - const clonedBannerRequests = deepClone(baseBannerBidRequests); - - const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data; - expect(requestBody.ext.ttdprebid.pbjs).to.equal('$prebid.version$'); - }); - - it('adds gdpr consent info to the request', function () { - const consentString = 'BON3G4EON3G4EAAABAENAA____ABl____A'; - const clonedBidderRequest = deepClone(baseBidderRequest); - clonedBidderRequest.gdprConsent = { - consentString: consentString, - gdprApplies: true - }; - - const requestBody = testBuildRequests(baseBannerBidRequests, clonedBidderRequest).data; - expect(requestBody.user.ext.consent).to.equal(consentString); - expect(requestBody.regs.ext.gdpr).to.equal(1); - }); - - it('adds usp consent info to the request', function () { - const consentString = 'BON3G4EON3G4EAAABAENAA____ABl____A'; - const clonedBidderRequest = deepClone(baseBidderRequest); - clonedBidderRequest.uspConsent = consentString; - - const requestBody = testBuildRequests(baseBannerBidRequests, clonedBidderRequest).data; - expect(requestBody.regs.ext.us_privacy).to.equal(consentString); - }); - - it('adds coppa consent info to the request', function () { - const clonedBidderRequest = deepClone(baseBidderRequest); - - config.setConfig({coppa: true}); - const requestBody = testBuildRequests(baseBannerBidRequests, clonedBidderRequest).data; - config.resetConfig(); - expect(requestBody.regs.coppa).to.equal(1); - }); - - it('adds gpp consent info to the request', function () { - const ortb2 = { - regs: { - gpp: 'somegppstring', - gpp_sid: [6, 7] - } - }; - const clonedBidderRequest = {...deepClone(baseBidderRequest), ortb2}; - const requestBody = testBuildRequests(baseBannerBidRequests, clonedBidderRequest).data; - config.resetConfig(); - expect(requestBody.regs.gpp).to.equal('somegppstring'); - expect(requestBody.regs.gpp_sid).to.eql([6, 7]); - }); - - it('adds schain info to the request', function () { - const schain = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [{ - 'asi': 'indirectseller.com', - 'sid': '00001', - 'hp': 1 - }, { - 'asi': 'indirectseller-2.com', - 'sid': '00002', - 'hp': 1 - }] - }; - const clonedBannerBidRequests = deepClone(baseBannerBidRequests); - clonedBannerBidRequests[0].ortb2 = { source: { ext: { schain: schain } } }; - - const requestBody = testBuildRequests(clonedBannerBidRequests, baseBidderRequest).data; - expect(requestBody.source.ext.schain).to.deep.equal(schain); - }); - - it('adds unified ID and UID2 info to user.ext.eids in the request', function () { - const TDID = '00000000-0000-0000-0000-000000000000'; - const UID2 = '99999999-9999-9999-9999-999999999999'; - const clonedBannerRequests = deepClone(baseBannerBidRequests); - clonedBannerRequests[0].userIdAsEids = [ - { - source: 'adserver.org', - uids: [ - { - atype: 1, - ext: { - rtiPartner: 'TDID' - }, - id: TDID - } - ] - }, - { - source: 'uidapi.com', - uids: [ - { - atype: 3, - id: UID2 - } - ] - } - ]; - const expectedEids = clonedBannerRequests[0].userIdAsEids; - - const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data; - expect(requestBody.user.ext.eids).to.deep.equal(expectedEids); - }); - - it('adds first party site data to the request', function () { - const ortb2 = { - site: { - name: 'example', - domain: 'page.example.com', - cat: ['IAB2'], - sectioncat: ['IAB2-2'], - pagecat: ['IAB2-2'], - page: 'https://page.example.com/here.html', - ref: 'https://ref.example.com', - keywords: 'power tools, drills' - } - }; - const clonedBidderRequest = {...deepClone(baseBidderRequest), ortb2}; - const requestBody = testBuildRequests(baseBannerBidRequests, clonedBidderRequest).data; - expect(requestBody.site.name).to.equal('example'); - expect(requestBody.site.domain).to.equal('page.example.com'); - expect(requestBody.site.cat[0]).to.equal('IAB2'); - expect(requestBody.site.sectioncat[0]).to.equal('IAB2-2'); - expect(requestBody.site.pagecat[0]).to.equal('IAB2-2'); - expect(requestBody.site.page).to.equal('https://page.example.com/here.html'); - expect(requestBody.site.ref).to.equal('https://ref.example.com'); - expect(requestBody.site.keywords).to.equal('power tools, drills'); - }); - - it('should fallback to floor module if no bidfloor is sent ', function () { - const clonedBannerRequests = deepClone(baseBannerBidRequests); - const bidfloor = 5.00; - clonedBannerRequests[0].getFloor = () => { - return { currency: 'USD', floor: bidfloor }; - }; - const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data; - config.resetConfig(); - expect(requestBody.imp[0].bidfloor).to.equal(bidfloor); - }); - - it('adds default value for secure if not set to request', function () { - const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest).data; - expect(requestBody.imp[0].secure).to.equal(1); - }); - - it('adds secure to request', function () { - const clonedBannerRequests = deepClone(baseBannerBidRequests); - clonedBannerRequests[0].ortb2Imp.secure = 0; - - let requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data; - expect(0).to.equal(requestBody.imp[0].secure); - - clonedBannerRequests[0].ortb2Imp.secure = 1; - requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data; - expect(1).to.equal(requestBody.imp[0].secure); - }); - - it('adds all of site first party data to request', function() { - const ortb2 = { - site: { - ext: extFirstPartyData, - search: 'test search' - } - }; - - const clonedBidderRequest = {...deepClone(baseBidderRequest), ortb2}; - const requestBody = testBuildRequests(baseBannerBidRequests, clonedBidderRequest).data; - - validateExtFirstPartyData(requestBody.site.ext) - expect(requestBody.site.search).to.equal('test search') - }); - - it('adds all of user first party data to request', function() { - const ortb2 = { - user: { - ext: extFirstPartyData, - yob: 1998 - } - }; - - const clonedBidderRequest = {...deepClone(baseBidderRequest), ortb2}; - const requestBody = testBuildRequests(baseBannerBidRequests, clonedBidderRequest).data; - - validateExtFirstPartyData(requestBody.user.ext) - expect(requestBody.user.yob).to.equal(1998) - }); - - it('adds all of imp first party data to request', function() { - const metric = { type: 'viewability', value: 0.8 }; - const clonedBannerRequests = deepClone(baseBannerBidRequests); - clonedBannerRequests[0].ortb2Imp = { - ext: extFirstPartyData, - metric: [metric], - clickbrowser: 1 - }; - - const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest).data; - - validateExtFirstPartyData(requestBody.imp[0].ext) - expect(requestBody.imp[0].tagid).to.equal('1gaa015'); - expect(requestBody.imp[0].metric[0]).to.deep.equal(metric); - expect(requestBody.imp[0].clickbrowser).to.equal(1) - }); - - it('adds all of app first party data to request', function() { - const ortb2 = { - app: { - ext: extFirstPartyData, - ver: 'v1.0' - } - }; - - const clonedBidderRequest = {...deepClone(baseBidderRequest), ortb2}; - const requestBody = testBuildRequests(baseBannerBidRequests, clonedBidderRequest).data; - - validateExtFirstPartyData(requestBody.app.ext) - expect(requestBody.app.ver).to.equal('v1.0') - }); - - it('adds all of device first party data to request', function() { - const ortb2 = { - device: { - ext: extFirstPartyData, - os: 'iPhone' - } - }; - - const clonedBidderRequest = {...deepClone(baseBidderRequest), ortb2}; - const requestBody = testBuildRequests(baseBannerBidRequests, clonedBidderRequest).data; - - validateExtFirstPartyData(requestBody.device.ext) - expect(requestBody.device.os).to.equal('iPhone') - }); - - it('adds all of pmp first party data to request', function() { - const ortb2 = { - pmp: { - ext: extFirstPartyData, - private_auction: 1 - } - }; - - const clonedBidderRequest = {...deepClone(baseBidderRequest), ortb2}; - const requestBody = testBuildRequests(baseBannerBidRequests, clonedBidderRequest).data; - - validateExtFirstPartyData(requestBody.imp[0].pmp.ext) - expect(requestBody.imp[0].pmp.private_auction).to.equal(1) - }); - }); - - describe('buildRequests-banner-multiple', function () { - const baseBannerMultipleBidRequests = [{ - 'bidder': 'ttd', - 'params': { - 'supplySourceId': 'supplier', - 'publisherId': '13144370', - 'placementId': 'bottom' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[300, 250], [300, 600]] - } - }, - 'ortb2Imp': { - 'ext': { - 'tid': '8651474f-58b1-4368-b812-84f8c937a099', - } - }, - 'sizes': [[300, 250], [300, 600]], - 'transactionId': '1111474f-58b1-4368-b812-84f8c937a099', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'bidId': 'small', - 'bidderRequestId': '18084284054531', - 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'src': 'client', - 'bidRequestsCount': 1 - }, { - 'bidder': 'ttd', - 'params': { - 'publisherId': '13144370', - 'placementId': 'top' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[728, 90]] - } - }, - 'ortb2Imp': { - 'ext': { - 'tid': '12345678-58b1-4368-b812-84f8c937a099', - } - }, - 'sizes': [[728, 90]], - 'transactionId': '825c1228-ca8c-4657-b40f-2df500621527', - 'adUnitCode': 'div-gpt-ad-91515710-0', - 'bidId': 'large', - 'bidderRequestId': '18084284054531', - 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'src': 'client', - 'bidRequestsCount': 1 - }]; - - const baseBidderRequest = { - 'bidderCode': 'ttd', - ortb2: { - source: { - tid: 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - } - }, - 'bidderRequestId': '18084284054531', - 'auctionStart': 1540945362095, - 'timeout': 3000, - 'refererInfo': { - 'referer': 'https://www.test.com', - 'reachedTop': true, - 'numIframes': 0, - 'stack': [ - 'https://www.test.com' - ] - }, - 'start': 1540945362099, - 'doneCbCallCount': 0 - }; - - it('sends multiple impressions', function () { - const requestBody = testBuildRequests(baseBannerMultipleBidRequests, baseBidderRequest).data; - expect(requestBody.imp.length).to.equal(2); - expect(requestBody.source).to.be.not.null; - expect(requestBody.source.tid).to.equal(baseBidderRequest.ortb2.source.tid); - expect(requestBody.imp[0].ext).to.be.not.null; - expect(requestBody.imp[0].ext.tid).to.equal('8651474f-58b1-4368-b812-84f8c937a099'); - expect(requestBody.imp[1].ext).to.be.not.null; - expect(requestBody.imp[1].ext.tid).to.equal('12345678-58b1-4368-b812-84f8c937a099'); - }); - - it('sends the right tag ids for each ad unit', function () { - const requestBody = testBuildRequests(baseBannerMultipleBidRequests, baseBidderRequest).data; - requestBody.imp.forEach(imp => { - if (imp.id === 'small') { - expect(imp.tagid).to.equal('bottom'); - } else if (imp.id === 'large') { - expect(imp.tagid).to.equal('top'); - } else { - assert.fail('no matching impression id found'); - } - }); - }); - - it('sends the sizes for each ad unit', function () { - const requestBody = testBuildRequests(baseBannerMultipleBidRequests, baseBidderRequest).data; - requestBody.imp.forEach(imp => { - if (imp.id === 'small') { - expect(imp.banner.format[0].w).to.equal(300); - expect(imp.banner.format[0].h).to.equal(250); - expect(imp.banner.format[1].w).to.equal(300); - expect(imp.banner.format[1].h).to.equal(600); - } else if (imp.id === 'large') { - expect(imp.banner.format[0].w).to.equal(728); - expect(imp.banner.format[0].h).to.equal(90); - } else { - assert.fail('no matching impression id found'); - } - }); - }); - }); - - describe('buildRequests-display-video-multiformat', function () { - if (!FEATURES.VIDEO) { - return; - } - - const baseMultiformatBidRequests = [{ - 'bidder': 'ttd', - 'params': { - 'supplySourceId': 'supplier', - 'publisherId': '13144370', - 'placementId': '1gaa015' - }, - 'mediaTypes': { - 'video': { - 'playerSize': [640, 480], - 'api': [1, 3], - 'mimes': ['video/mp4'], - 'protocols': [2, 3, 5, 6], - 'minduration': 5, - 'maxduration': 30 - }, - 'banner': { - 'sizes': [[300, 250], [300, 600]] - } - }, - 'ortb2Imp': { - 'ext': { - 'tid': '8651474f-58b1-4368-b812-84f8c937a099', - } - }, - 'transactionId': '1111474f-58b1-4368-b812-84f8c937a099', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'bidId': '243310435309b5', - 'bidderRequestId': '18084284054531', - 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'src': 'client', - 'bidRequestsCount': 1 - }]; - - const baseBidderRequest = { - 'bidderCode': 'ttd', - 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'bidderRequestId': '18084284054531', - 'auctionStart': 1540945362095, - 'timeout': 3000, - 'refererInfo': { - 'referer': 'https://www.example.com/test', - 'reachedTop': true, - 'numIframes': 0, - 'stack': [ - 'https://www.example.com/test' - ] - }, - 'start': 1540945362099, - 'doneCbCallCount': 0 - }; - - it('includes the video ad size in the bid request', function () { - const requestBody = testBuildRequests(baseMultiformatBidRequests, baseBidderRequest).data; - expect(requestBody.imp[0].video.w).to.equal(640); - expect(requestBody.imp[0].video.h).to.equal(480); - }); - - it('includes the banner ad size in the bid request', function () { - const requestBody = testBuildRequests(baseMultiformatBidRequests, baseBidderRequest).data; - expect(requestBody.imp[0].banner.format[0].w).to.equal(300); - expect(requestBody.imp[0].banner.format[0].h).to.equal(250); - expect(requestBody.imp[0].banner.format[1].w).to.equal(300); - expect(requestBody.imp[0].banner.format[1].h).to.equal(600); - }); - }); - - describe('buildRequests-video', function () { - if (!FEATURES.VIDEO) { - return; - } - - const baseVideoBidRequests = [{ - 'bidder': 'ttd', - 'params': { - 'supplySourceId': 'supplier', - 'publisherId': '13144370', - 'placementId': '1gaa015' - }, - 'mediaTypes': { - 'video': { - 'playerSize': [640, 480], - 'api': [1, 3], - 'mimes': ['video/mp4'], - 'protocols': [2, 3, 5, 6], - 'minduration': 5, - 'maxduration': 30 - } - }, - 'ortb2Imp': { - 'ext': { - 'tid': '8651474f-58b1-4368-b812-84f8c937a099', - } - }, - 'transactionId': '1111474f-58b1-4368-b812-84f8c937a099', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'bidId': '243310435309b5', - 'bidderRequestId': '18084284054531', - 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'src': 'client', - 'bidRequestsCount': 1 - }]; - - const baseBidderRequest = { - 'bidderCode': 'ttd', - 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'bidderRequestId': '18084284054531', - 'auctionStart': 1540945362095, - 'timeout': 3000, - 'refererInfo': { - 'referer': 'https://www.example.com/test', - 'reachedTop': true, - 'numIframes': 0, - 'stack': [ - 'https://www.example.com/test' - ] - }, - 'start': 1540945362099, - 'doneCbCallCount': 0 - }; - - it('includes the ad size in the bid request', function () { - const requestBody = testBuildRequests(baseVideoBidRequests, baseBidderRequest).data; - expect(requestBody.imp[0].video.w).to.equal(640); - expect(requestBody.imp[0].video.h).to.equal(480); - }); - - it('includes the mimes in the bid request', function () { - const requestBody = testBuildRequests(baseVideoBidRequests, baseBidderRequest).data; - expect(requestBody.imp[0].video.mimes[0]).to.equal('video/mp4'); - }); - - it('includes the min and max duration in the bid request', function () { - const requestBody = testBuildRequests(baseVideoBidRequests, baseBidderRequest).data; - expect(requestBody.imp[0].video.minduration).to.equal(5); - expect(requestBody.imp[0].video.maxduration).to.equal(30); - }); - - it('sets the minduration to 0 if missing', function () { - const clonedVideoRequests = deepClone(baseVideoBidRequests); - delete clonedVideoRequests[0].mediaTypes.video.minduration - - const requestBody = testBuildRequests(clonedVideoRequests, baseBidderRequest).data; - expect(requestBody.imp[0].video.minduration).to.equal(0); - }); - - it('includes the api frameworks in the bid request', function () { - const requestBody = testBuildRequests(baseVideoBidRequests, baseBidderRequest).data; - expect(requestBody.imp[0].video.api[0]).to.equal(1); - expect(requestBody.imp[0].video.api[1]).to.equal(3); - }); - - it('includes the protocols in the bid request', function () { - const requestBody = testBuildRequests(baseVideoBidRequests, baseBidderRequest).data; - expect(requestBody.imp[0].video.protocols[0]).to.equal(2); - expect(requestBody.imp[0].video.protocols[1]).to.equal(3); - expect(requestBody.imp[0].video.protocols[2]).to.equal(5); - expect(requestBody.imp[0].video.protocols[3]).to.equal(6); - }); - - it('sets skip correctly if sent', function () { - const clonedVideoRequests = deepClone(baseVideoBidRequests); - clonedVideoRequests[0].mediaTypes.video.skip = 1; - clonedVideoRequests[0].mediaTypes.video.skipmin = 5; - clonedVideoRequests[0].mediaTypes.video.skipafter = 10; - - const requestBody = testBuildRequests(clonedVideoRequests, baseBidderRequest).data; - expect(requestBody.imp[0].video.skip).to.equal(1); - expect(requestBody.imp[0].video.skipmin).to.equal(5); - expect(requestBody.imp[0].video.skipafter).to.equal(10); - }); - - it('sets bitrate correctly if sent', function () { - const clonedVideoRequests = deepClone(baseVideoBidRequests); - clonedVideoRequests[0].mediaTypes.video.minbitrate = 100; - clonedVideoRequests[0].mediaTypes.video.maxbitrate = 500; - - const requestBody = testBuildRequests(clonedVideoRequests, baseBidderRequest).data; - expect(requestBody.imp[0].video.minbitrate).to.equal(100); - expect(requestBody.imp[0].video.maxbitrate).to.equal(500); - }); - - it('sets pos correctly if sent', function () { - const clonedVideoRequests = deepClone(baseVideoBidRequests); - clonedVideoRequests[0].mediaTypes.video.pos = 1; - - const requestBody = testBuildRequests(clonedVideoRequests, baseBidderRequest).data; - expect(requestBody.imp[0].video.pos).to.equal(1); - }); - - it('sets playbackmethod correctly if sent', function () { - const clonedVideoRequests = deepClone(baseVideoBidRequests); - clonedVideoRequests[0].mediaTypes.video.playbackmethod = [1]; - - const requestBody = testBuildRequests(clonedVideoRequests, baseBidderRequest).data; - expect(requestBody.imp[0].video.playbackmethod[0]).to.equal(1); - }); - - it('sets startdelay correctly if sent', function () { - const clonedVideoRequests = deepClone(baseVideoBidRequests); - clonedVideoRequests[0].mediaTypes.video.startdelay = -1; - - const requestBody = testBuildRequests(clonedVideoRequests, baseBidderRequest).data; - expect(requestBody.imp[0].video.startdelay).to.equal(-1); - }); - - it('sets placement correctly if sent', function () { - const clonedVideoRequests = deepClone(baseVideoBidRequests); - clonedVideoRequests[0].mediaTypes.video.placement = 3; - - const requestBody = testBuildRequests(clonedVideoRequests, baseBidderRequest).data; - expect(requestBody.imp[0].video.placement).to.equal(3); - }); - - it('sets plcmt correctly if sent', function () { - const clonedVideoRequests = deepClone(baseVideoBidRequests); - clonedVideoRequests[0].mediaTypes.video.plcmt = 3; - - const requestBody = testBuildRequests(clonedVideoRequests, baseBidderRequest).data; - expect(requestBody.imp[0].video.plcmt).to.equal(3); - }); - }); - - describe('interpretResponse-empty', function () { - it('should handle empty response', function () { - const result = spec.interpretResponse({}); - expect(result.length).to.equal(0); - }); - - it('should handle empty seatbid response', function () { - const response = { - body: { - 'id': '5e5c23a5ba71e78', - 'seatbid': [] - } - }; - const result = spec.interpretResponse(response); - expect(result.length).to.equal(0); - }); - }); - - describe('interpretResponse-simple-display', function () { - const incoming = { - body: { - 'id': '5e5c23a5ba71e78', - 'seatbid': [ - { - 'bid': [ - { - 'id': '6vmb3isptf', - 'crid': 'ttdscreative', - 'impid': '322add653672f68', - 'price': 1.22, - 'adm': '', - 'cat': [], - 'h': 90, - 'w': 728, - 'ttl': 60, - 'dealid': 'ttd-dealid-1', - 'adomain': ['advertiser.com'], - 'ext': { - 'mediatype': 1 - } - } - ], - 'seat': 'MOCK' - } - ], - 'cur': 'EUR', - 'bidid': '5e5c23a5ba71e78' - } - }; - - const serverRequest = { - 'method': 'POST', - 'url': 'https://direct.adsrvr.org/bid/bidder/supplier', - 'data': { - 'id': 'c47237df-c108-419f-9c2b-da513dc3c133', - 'imp': [ - { - 'id': '322add653672f68', - 'tagid': 'simple', - 'banner': { - 'w': 728, - 'h': 90, - 'format': [ - { - 'w': 728, - 'h': 90 - } - ] - } - } - ], - 'site': { - 'page': 'http://www.test.com', - 'publisher': { - 'id': '111' - } - }, - 'device': { - 'ua': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36', - 'dnt': 0, - 'language': 'en-US', - 'connectiontype': 0 - }, - 'user': {}, - 'at': 1, - 'cur': [ - 'USD' - ], - 'regs': {}, - 'ext': { - 'ttdprebid': { - 'ver': 'TTD-PREBID-2019.11.12', - 'pbjs': '2.31.0' - } - } - }, - 'options': { - 'withCredentials': true - } - }; - - const expectedBid = { - 'requestId': '322add653672f68', - 'cpm': 1.22, - 'width': 728, - 'height': 90, - 'creativeId': 'ttdscreative', - 'dealId': 'ttd-dealid-1', - 'currency': 'EUR', - 'netRevenue': true, - 'ttl': 60, - 'ad': '', - 'mediaType': 'banner', - 'meta': { - 'advertiserDomains': ['advertiser.com'] - } - }; - - it('should get the correct bid response', function () { - const result = spec.interpretResponse(incoming, serverRequest); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal(expectedBid); - }); - }); - - describe('interpretResponse-multiple-display', function () { - const incoming = { - 'body': { - 'id': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'small', - 'impid': 'small', - 'price': 4.25, - 'adm': 'Default Test Ad Tag', - 'cid': 'campaignId132', - 'crid': 'creativeId999', - 'adomain': [ - 'http://foo' - ], - 'dealid': null, - 'w': 300, - 'h': 600, - 'cat': [], - 'ext': { - 'mediatype': 1 - } - }, - { - 'id': 'large', - 'impid': 'large', - 'price': 5.25, - 'adm': 'Default Test Ad Tag', - 'cid': 'campaignId132', - 'crid': 'creativeId222', - 'adomain': [ - 'http://foo2' - ], - 'dealid': null, - 'w': 728, - 'h': 90, - 'cat': [], - 'ext': { - 'mediatype': 1 - } - } - ], - 'seat': 'supplyVendorBuyerId132' - } - ], - 'cur': 'USD' - } - }; - - const expectedBids = [ - { - 'requestId': 'small', - 'cpm': 4.25, - 'width': 300, - 'height': 600, - 'creativeId': 'creativeId999', - 'currency': 'USD', - 'dealId': null, - 'netRevenue': true, - 'ttl': 360, - 'ad': 'Default Test Ad Tag', - 'mediaType': 'banner', - 'meta': { - 'advertiserDomains': ['http://foo'] - } - }, - { - 'requestId': 'large', - 'cpm': 5.25, - 'width': 728, - 'height': 90, - 'creativeId': 'creativeId222', - 'currency': 'USD', - 'dealId': null, - 'netRevenue': true, - 'ttl': 360, - 'ad': 'Default Test Ad Tag', - 'mediaType': 'banner', - 'meta': { - 'advertiserDomains': ['http://foo2'] - } - } - ]; - - const serverRequest = { - 'method': 'POST', - 'url': 'https://direct.adsrvr.org/bid/bidder/supplier', - 'data': { - 'id': 'c47237df-c108-419f-9c2b-da513dc3c133', - 'imp': [ - { - 'id': 'small', - 'tagid': 'test1', - 'banner': { - 'w': 300, - 'h': 600, - 'format': [ - { - 'w': 300, - 'h': 600 - } - ] - } - }, - { - 'id': 'large', - 'tagid': 'test2', - 'banner': { - 'w': 728, - 'h': 90, - 'format': [ - { - 'w': 728, - 'h': 90 - } - ] - } - } - ], - 'site': { - 'page': 'http://www.test.com', - 'publisher': { - 'id': '111' - } - }, - 'device': { - 'ua': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36', - 'dnt': 0, - 'language': 'en-US', - 'connectiontype': 0 - }, - 'user': {}, - 'at': 1, - 'cur': [ - 'USD' - ], - 'regs': {}, - 'ext': { - 'ttdprebid': { - 'ver': 'TTD-PREBID-2019.11.12', - 'pbjs': '2.31.0' - } - } - }, - 'options': { - 'withCredentials': true - } - }; - - it('should get the correct bid response', function () { - const result = spec.interpretResponse(incoming, serverRequest); - expect(result.length).to.equal(2); - expect(result).to.deep.equal(expectedBids); - }); - }); - - describe('interpretResponse-simple-video', function () { - if (!FEATURES.VIDEO) { - return; - } - - const incoming = { - 'body': { - 'cur': 'USD', - 'seatbid': [ - { - 'bid': [ - { - 'crid': 'mokivv6m', - 'ext': { - 'advid': '7ieo6xk', - 'agid': '7q9n3s2', - 'deal': { - 'dealid': '7013542' - }, - 'imptrackers': [], - 'viewabilityvendors': [], - 'mediatype': 2 - }, - 'h': 480, - 'impid': '2eabb87dfbcae4', - 'nurl': 'https://insight.adsrvr.org/enduser/vast?iid=00000000-0000-0000-0000-000000000000&crid=v3pek2eh&wp=${AUCTION_PRICE}&aid=&wpc=&sfe=0&puid=&tdid=00000000-0000-0000-0000-000000000000&pid=&ag=&adv=&sig=AAAAAAAAAAAAAA.&cf=&fq=0&td_s=&rcats=&mcat=&mste=&mfld=4&mssi=&mfsi=&uhow=&agsa=&rgco=&rgre=&rgme=&rgci=&rgz=&svbttd=0&dt=&osf=&os=&br=&rlangs=en&mlang=en&svpid=&did=&rcxt=&lat=&lon=&tmpc=&daid=&vp=0&osi=&osv=&dc=0&vcc=QAFIAVABiAECwAEDyAED0AED6AEG8AEBgAIDigIMCAIIBQgDCAYICwgMmgIECAEIAqACA6gCAsACAA..&sv=noop&pidi=&advi=&cmpi=&agi=&cridi=&svi=&cmp=&skip=1&c=&dur=&crrelr=', - 'price': 13.6, - 'ttl': 500, - 'w': 600 - } - ], - 'seat': 'supplyVendorBuyerId132' - } - ] - }, - 'headers': {} - }; - - const serverRequest = { - 'method': 'POST', - 'url': 'https://direct.bid.adsrvr.org/bid/bidder/supplier', - 'data': { - 'id': 'e94ec12d-ae1d-4ed7-abd1-eb3198ce3b63', - 'imp': [ - { - 'id': '2eabb87dfbcae4', - 'tagid': 'video', - 'video': { - 'api': [ - 1, - 3 - ], - 'mimes': [ - 'video/mp4' - ], - 'minduration': 5, - 'maxduration': 30, - 'w': 640, - 'h': 480, - 'protocols': [ - 2, - 3, - 5, - 6 - ] - } - } - ], - 'site': { - 'page': 'http://www.test.com', - 'publisher': { - 'id': '111' - } - }, - 'device': { - 'ua': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36', - 'dnt': 0, - 'language': 'en-US', - 'connectiontype': 0 - }, - 'user': {}, - 'at': 1, - 'cur': [ - 'USD' - ], - 'regs': {}, - 'ext': { - 'ttdprebid': { - 'ver': 'TTD-PREBID-2019.11.12', - 'pbjs': '3.10.0' - } - } - }, - 'options': { - 'withCredentials': true - } - }; - - const expectedBid = { - 'requestId': '2eabb87dfbcae4', - 'cpm': 13.6, - 'creativeId': 'mokivv6m', - 'dealId': null, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 500, - 'width': 640, - 'height': 480, - 'mediaType': 'video', - 'vastUrl': 'https://insight.adsrvr.org/enduser/vast?iid=00000000-0000-0000-0000-000000000000&crid=v3pek2eh&wp=13.6&aid=&wpc=&sfe=0&puid=&tdid=00000000-0000-0000-0000-000000000000&pid=&ag=&adv=&sig=AAAAAAAAAAAAAA.&cf=&fq=0&td_s=&rcats=&mcat=&mste=&mfld=4&mssi=&mfsi=&uhow=&agsa=&rgco=&rgre=&rgme=&rgci=&rgz=&svbttd=0&dt=&osf=&os=&br=&rlangs=en&mlang=en&svpid=&did=&rcxt=&lat=&lon=&tmpc=&daid=&vp=0&osi=&osv=&dc=0&vcc=QAFIAVABiAECwAEDyAED0AED6AEG8AEBgAIDigIMCAIIBQgDCAYICwgMmgIECAEIAqACA6gCAsACAA..&sv=noop&pidi=&advi=&cmpi=&agi=&cridi=&svi=&cmp=&skip=1&c=&dur=&crrelr=', - 'meta': {} - }; - - it('should get the correct bid response if nurl is returned', function () { - const result = spec.interpretResponse(incoming, serverRequest); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal(expectedBid); - }); - - it('should get the correct bid response if adm is returned', function () { - const vastXml = "2.0574840600:00:30 \"Click ]]>"; - const admIncoming = deepClone(incoming); - delete admIncoming.body.seatbid[0].bid[0].nurl; - admIncoming.body.seatbid[0].bid[0].adm = vastXml; - - const vastXmlExpectedBid = deepClone(expectedBid); - delete vastXmlExpectedBid.vastUrl; - vastXmlExpectedBid.vastXml = vastXml; - - const result = spec.interpretResponse(admIncoming, serverRequest); - expect(result.length).to.equal(1); - expect(result[0]).to.deep.equal(vastXmlExpectedBid); - }); - }); - - describe('interpretResponse-display-and-video', function () { - if (!FEATURES.VIDEO) { - return; - } - - const incoming = { - 'body': { - 'id': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'seatbid': [ - { - 'bid': [ - { - 'id': 'small', - 'impid': 'small', - 'price': 4.25, - 'adm': 'Default Test Ad Tag', - 'cid': 'campaignId132', - 'crid': 'creativeId999', - 'adomain': [ - 'http://foo' - ], - 'dealid': null, - 'w': 300, - 'h': 600, - 'cat': [], - 'ext': { - 'mediatype': 1 - } - }, - { - 'crid': 'mokivv6m', - 'ext': { - 'advid': '7ieo6xk', - 'agid': '7q9n3s2', - 'deal': { - 'dealid': '7013542' - }, - 'imptrackers': [], - 'viewabilityvendors': [], - 'mediatype': 2 - }, - 'h': 480, - 'impid': '2eabb87dfbcae4', - 'nurl': 'https://insight.adsrvr.org/enduser/vast?iid=00000000-0000-0000-0000-000000000000&crid=v3pek2eh&wp=${AUCTION_PRICE}&aid=&wpc=&sfe=0&puid=&tdid=00000000-0000-0000-0000-000000000000&pid=&ag=&adv=&sig=AAAAAAAAAAAAAA.&cf=&fq=0&td_s=&rcats=&mcat=&mste=&mfld=4&mssi=&mfsi=&uhow=&agsa=&rgco=&rgre=&rgme=&rgci=&rgz=&svbttd=0&dt=&osf=&os=&br=&rlangs=en&mlang=en&svpid=&did=&rcxt=&lat=&lon=&tmpc=&daid=&vp=0&osi=&osv=&dc=0&vcc=QAFIAVABiAECwAEDyAED0AED6AEG8AEBgAIDigIMCAIIBQgDCAYICwgMmgIECAEIAqACA6gCAsACAA..&sv=noop&pidi=&advi=&cmpi=&agi=&cridi=&svi=&cmp=&skip=1&c=&dur=&crrelr=', - 'price': 13.6, - 'ttl': 500, - 'w': 600 - } - ], - 'seat': 'supplyVendorBuyerId132' - } - ], - 'cur': 'USD' - } - }; - - const expectedBids = [ - { - 'requestId': 'small', - 'cpm': 4.25, - 'width': 300, - 'height': 600, - 'creativeId': 'creativeId999', - 'currency': 'USD', - 'dealId': null, - 'netRevenue': true, - 'ttl': 360, - 'ad': 'Default Test Ad Tag', - 'mediaType': 'banner', - 'meta': { - 'advertiserDomains': ['http://foo'] - } - }, - { - 'requestId': '2eabb87dfbcae4', - 'cpm': 13.6, - 'creativeId': 'mokivv6m', - 'dealId': null, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 500, - 'width': 640, - 'height': 480, - 'mediaType': 'video', - 'vastUrl': 'https://insight.adsrvr.org/enduser/vast?iid=00000000-0000-0000-0000-000000000000&crid=v3pek2eh&wp=13.6&aid=&wpc=&sfe=0&puid=&tdid=00000000-0000-0000-0000-000000000000&pid=&ag=&adv=&sig=AAAAAAAAAAAAAA.&cf=&fq=0&td_s=&rcats=&mcat=&mste=&mfld=4&mssi=&mfsi=&uhow=&agsa=&rgco=&rgre=&rgme=&rgci=&rgz=&svbttd=0&dt=&osf=&os=&br=&rlangs=en&mlang=en&svpid=&did=&rcxt=&lat=&lon=&tmpc=&daid=&vp=0&osi=&osv=&dc=0&vcc=QAFIAVABiAECwAEDyAED0AED6AEG8AEBgAIDigIMCAIIBQgDCAYICwgMmgIECAEIAqACA6gCAsACAA..&sv=noop&pidi=&advi=&cmpi=&agi=&cridi=&svi=&cmp=&skip=1&c=&dur=&crrelr=', - 'meta': {} - } - ]; - - const serverRequest = { - 'method': 'POST', - 'url': 'https://direct.adsrvr.org/bid/bidder/supplier', - 'data': { - 'id': 'c47237df-c108-419f-9c2b-da513dc3c133', - 'imp': [ - { - 'id': 'small', - 'tagid': 'test1', - 'banner': { - 'w': 300, - 'h': 600, - 'format': [ - { - 'w': 300, - 'h': 600 - } - ] - }, - }, - { - 'id': '2eabb87dfbcae4', - 'tagid': 'video', - 'video': { - 'api': [ - 1, - 3 - ], - 'mimes': [ - 'video/mp4' - ], - 'minduration': 5, - 'maxduration': 30, - 'w': 640, - 'h': 480, - 'protocols': [ - 2, - 3, - 5, - 6 - ] - } - } - ], - 'site': { - 'page': 'http://www.test.com', - 'publisher': { - 'id': '111' - } - }, - 'device': { - 'ua': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.122 Safari/537.36', - 'dnt': 0, - 'language': 'en-US', - 'connectiontype': 0 - }, - 'user': {}, - 'at': 1, - 'cur': [ - 'USD' - ], - 'regs': {}, - 'ext': { - 'ttdprebid': { - 'ver': 'TTD-PREBID-2019.11.12', - 'pbjs': '2.31.0' - } - } - }, - 'options': { - 'withCredentials': true - } - }; - - it('should get the correct bid response', function () { - const result = spec.interpretResponse(incoming, serverRequest); - expect(result.length).to.equal(2); - expect(result).to.deep.equal(expectedBids); - }); - }); -}); diff --git a/test/spec/modules/twistDigitalBidAdapter_spec.js b/test/spec/modules/twistDigitalBidAdapter_spec.js deleted file mode 100644 index ea3779c8b..000000000 --- a/test/spec/modules/twistDigitalBidAdapter_spec.js +++ /dev/null @@ -1,1064 +0,0 @@ -import {expect} from 'chai'; -import { - spec as adapter, - createDomain, - storage -} from 'modules/twistDigitalBidAdapter.js'; -import * as utils from 'src/utils.js'; -import {version} from 'package.json'; -import {useFakeTimers} from 'sinon'; -import {BANNER, VIDEO} from '../../../src/mediaTypes.js'; -import {config} from '../../../src/config.js'; -import {deepSetValue} from 'src/utils.js'; -import { - extractPID, - extractCID, - extractSubDomain, - hashCode, - getStorageItem, - setStorageItem, - tryParseJSON, - getUniqueDealId -} from '../../../libraries/vidazooUtils/bidderUtils.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -export const TEST_ID_SYSTEMS = ['britepoolid', 'criteoId', 'id5id', 'idl_env', 'lipb', 'netId', 'parrableId', 'pubcid', 'tdid', 'pubProvidedId']; - -const SUB_DOMAIN = 'openrtb'; - -const BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': 'div-gpt-ad-12345-0', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '59db6b3b4ffaa70004f45cdc', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1, - 'ext': { - 'param1': 'loremipsum', - 'param2': 'dolorsitamet' - } - }, - 'placementCode': 'div-gpt-ad-1460505748561-0', - 'sizes': [[300, 250], [300, 600]], - 'bidderRequestId': '1fdb5ff1b6eaa7', - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'requestId': 'b0777d85-d061-450e-9bc7-260dd54bbb7a', - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'mediaTypes': [BANNER], - 'ortb2Imp': { - 'ext': { - tid: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - 'gpid': '1234567890' - } - } -}; - -const VIDEO_BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': '63550ad1ff6642d368cba59dh5884270560', - 'bidderRequestId': '12a8ae9ada9c13', - ortb2Imp: { - ext: { - tid: '56e184c6-bde9-497b-b9b9-cf47a61381ee', - } - }, - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '635509f7ff6642d368cb9837', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1 - }, - 'sizes': [[545, 307]], - 'mediaTypes': { - 'video': { - 'playerSize': [[545, 307]], - 'context': 'instream', - 'mimes': [ - 'video/mp4', - 'application/javascript' - ], - 'protocols': [2, 3, 5, 6], - 'maxduration': 60, - 'minduration': 0, - 'startdelay': 0, - 'linearity': 1, - 'api': [2], - 'placement': 1 - } - } -} - -const ORTB2_DEVICE = { - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - ext: {fiftyonedegrees_deviceId: '17595-133085-133468-18092'}, -}; - -const BIDDER_REQUEST = { - 'gdprConsent': { - 'consentString': 'consent_string', - 'gdprApplies': true - }, - 'gppString': 'gpp_string', - 'gppSid': [7], - 'uspConsent': 'consent_string', - 'refererInfo': { - 'page': 'https://www.greatsite.com', - 'ref': 'https://www.somereferrer.com' - }, - 'ortb2': { - 'site': { - 'cat': ['IAB2'], - 'pagecat': ['IAB2-2'], - 'content': { - 'language': 'en', - 'data': [{ - 'name': 'example.com', - 'ext': { - 'segtax': 7 - }, - 'segments': [ - {'id': 'segId1'}, - {'id': 'segId2'} - ] - }] - } - }, - 'regs': { - 'gpp': 'gpp_string', - 'gpp_sid': [7], - 'coppa': 0 - }, - device: ORTB2_DEVICE, - user: { - data: [ - { - ext: {segtax: 600, segclass: '1'}, - name: 'example.com', - segment: [{id: '243'}], - }, - ], - } - }, -}; - -const SERVER_RESPONSE = { - body: { - cid: 'testcid123', - results: [{ - 'ad': '', - 'bidId': '2d52001cabd527-response', - 'price': 0.8, - 'creativeId': '12610997325162499419', - 'exp': 30, - 'width': 300, - 'height': 250, - 'advertiserDomains': ['securepubads.g.doubleclick.net'], - 'cookies': [{ - 'src': 'https://sync.com', - 'type': 'iframe' - }, { - 'src': 'https://sync.com', - 'type': 'img' - }] - }] - } -}; - -const VIDEO_SERVER_RESPONSE = { - body: { - 'cid': '635509f7ff6642d368cb9837', - 'results': [{ - 'ad': '', - 'advertiserDomains': ['twistdigital.com'], - 'exp': 60, - 'width': 545, - 'height': 307, - 'mediaType': 'video', - 'creativeId': '12610997325162499419', - 'price': 2, - 'cookies': [] - }] - } -}; - -const ORTB2_OBJ = { - "device": ORTB2_DEVICE, - "regs": {"coppa": 0, "gpp": "gpp_string", "gpp_sid": [7]}, - "site": { - "cat": ["IAB2"], - "content": { - "data": [{ - "ext": {"segtax": 7}, - "name": "example.com", - "segments": [{"id": "segId1"}, {"id": "segId2"}] - }], - "language": "en" - }, - "pagecat": ["IAB2-2"] - }, - "user": { - "data": [{"ext": {"segclass": "1", "segtax": 600}, "name": "example.com", "segment": [{"id": "243"}]}] - } -}; - -const REQUEST = { - data: { - width: 300, - height: 250, - bidId: '2d52001cabd527' - } -}; - -function getTopWindowQueryParams() { - try { - const parsedUrl = utils.parseUrl(window.top.document.URL, {decodeSearchAsString: true}); - return parsedUrl.search; - } catch (e) { - return ''; - } -} - -describe('TwistDigitalBidAdapter', function () { - before(() => config.resetConfig()); - after(() => config.resetConfig()); - - describe('validtae spec', function () { - it('exists and is a function', function () { - expect(adapter.isBidRequestValid).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.buildRequests).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.interpretResponse).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.getUserSyncs).to.exist.and.to.be.a('function'); - }); - - it('exists and is a string', function () { - expect(adapter.code).to.exist.and.to.be.a('string'); - }); - - it('exists and contains media types', function () { - expect(adapter.supportedMediaTypes).to.exist.and.to.be.an('array').with.length(2); - expect(adapter.supportedMediaTypes).to.contain.members([BANNER, VIDEO]); - }); - }); - - describe('validate bid requests', function () { - it('should require cId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - pId: 'pid' - } - }); - expect(isValid).to.be.false; - }); - - it('should require pId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid' - } - }); - expect(isValid).to.be.false; - }); - - it('should validate correctly', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid', - pId: 'pid' - } - }); - expect(isValid).to.be.true; - }); - }); - - describe('build requests', function () { - let sandbox; - before(function () { - getGlobal().bidderSettings = { - twistdigital: { - storageAllowed: true, - } - }; - sandbox = sinon.createSandbox(); - sandbox.stub(Date, 'now').returns(1000); - }); - - it('should build video request', function () { - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - config.setConfig({ - bidderTimeout: 3000 - }); - const requests = adapter.buildRequests([VIDEO_BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/635509f7ff6642d368cb9837`, - data: { - adUnitCode: '63550ad1ff6642d368cba59dh5884270560', - bidFloor: 0.1, - bidId: '2d52001cabd527', - bidderVersion: adapter.version, - cat: ['IAB2'], - pagecat: ['IAB2-2'], - ortb2Imp: VIDEO_BID.ortb2Imp, - ortb2: ORTB2_OBJ, - cb: 1000, - gdpr: 1, - gdprConsent: 'consent_string', - usPrivacy: 'consent_string', - gppString: 'gpp_string', - gppSid: [7], - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - transactionId: '56e184c6-bde9-497b-b9b9-cf47a61381ee', - bidderRequestId: '12a8ae9ada9c13', - gpid: '', - prebidVersion: version, - publisherId: '59ac17c192832d0011283fe3', - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - res: `${window.top.screen.width}x${window.top.screen.height}`, - schain: VIDEO_BID.schain, - sizes: ['545x307'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - contentLang: 'en', - coppa: 0, - device: ORTB2_DEVICE, - contentData: [{ - 'name': 'example.com', - 'ext': { - 'segtax': 7 - }, - 'segments': [ - {'id': 'segId1'}, - {'id': 'segId2'} - ] - }], - userData: [ - { - ext: {segtax: 600, segclass: '1'}, - name: 'example.com', - segment: [{id: '243'}], - }, - ], - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - uqs: getTopWindowQueryParams(), - isStorageAllowed: true, - mediaTypes: { - video: { - api: [2], - context: 'instream', - linearity: 1, - maxduration: 60, - mimes: [ - 'video/mp4', - 'application/javascript' - ], - minduration: 0, - placement: 1, - playerSize: [[545, 307]], - protocols: [2, 3, 5, 6], - startdelay: 0 - } - } - } - }) - ; - }); - - it('should build banner request for each size', function () { - config.setConfig({ - bidderTimeout: 3000 - }); - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - const requests = adapter.buildRequests([BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/59db6b3b4ffaa70004f45cdc`, - data: { - gdprConsent: 'consent_string', - gdpr: 1, - usPrivacy: 'consent_string', - gppString: 'gpp_string', - gppSid: [7], - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - bidderRequestId: '1fdb5ff1b6eaa7', - sizes: ['300x250', '300x600'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - cb: 1000, - bidFloor: 0.1, - bidId: '2d52001cabd527', - adUnitCode: 'div-gpt-ad-12345-0', - publisherId: '59ac17c192832d0011283fe3', - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - bidderVersion: adapter.version, - prebidVersion: version, - schain: BID.schain, - res: `${window.top.screen.width}x${window.top.screen.height}`, - mediaTypes: [BANNER], - uqs: getTopWindowQueryParams(), - 'ext.param1': 'loremipsum', - 'ext.param2': 'dolorsitamet', - isStorageAllowed: true, - gpid: '1234567890', - cat: ['IAB2'], - pagecat: ['IAB2-2'], - ortb2Imp: BID.ortb2Imp, - ortb2: ORTB2_OBJ, - contentLang: 'en', - coppa: 0, - contentData: [{ - 'name': 'example.com', - 'ext': { - 'segtax': 7 - }, - 'segments': [ - {'id': 'segId1'}, - {'id': 'segId2'} - ] - }], - userData: [ - { - ext: {segtax: 600, segclass: '1'}, - name: 'example.com', - segment: [{id: '243'}], - }, - ] - } - }); - }); - - it('should build single banner request for multiple bids', function () { - config.setConfig({ - bidderTimeout: 3000, - twistdigital: { - singleRequest: true, - chunkSize: 2 - } - }); - - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - - const BID2 = utils.deepClone(BID); - BID2.bidId = '2d52001cabd528'; - BID2.adUnitCode = 'div-gpt-ad-12345-1'; - BID2.sizes = [[300, 250]]; - - const REQUEST_DATA = { - gdprConsent: 'consent_string', - gdpr: 1, - usPrivacy: 'consent_string', - gppString: 'gpp_string', - gppSid: [7], - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - bidderRequestId: '1fdb5ff1b6eaa7', - sizes: ['300x250', '300x600'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - cb: 1000, - bidFloor: 0.1, - bidId: '2d52001cabd527', - adUnitCode: 'div-gpt-ad-12345-0', - publisherId: '59ac17c192832d0011283fe3', - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - bidderVersion: adapter.version, - prebidVersion: version, - schain: BID.schain, - res: `${window.top.screen.width}x${window.top.screen.height}`, - mediaTypes: [BANNER], - uqs: getTopWindowQueryParams(), - 'ext.param1': 'loremipsum', - 'ext.param2': 'dolorsitamet', - isStorageAllowed: true, - gpid: '1234567890', - cat: ['IAB2'], - pagecat: ['IAB2-2'], - contentLang: 'en', - coppa: 0, - contentData: [{ - 'name': 'example.com', - 'ext': { - 'segtax': 7 - }, - 'segments': [ - {'id': 'segId1'}, - {'id': 'segId2'} - ] - }], - userData: [ - { - ext: {segtax: 600, segclass: '1'}, - name: 'example.com', - segment: [{id: '243'}], - }, - ] - }; - - const REQUEST_DATA2 = utils.deepClone(REQUEST_DATA); - REQUEST_DATA2.bidId = '2d52001cabd528'; - REQUEST_DATA2.adUnitCode = 'div-gpt-ad-12345-1'; - REQUEST_DATA2.sizes = ['300x250']; - - const requests = adapter.buildRequests([BID, BID2], BIDDER_REQUEST); - expect(requests).to.have.length(1); - - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/59db6b3b4ffaa70004f45cdc`, - data: {bids: [ - {...REQUEST_DATA, ortb2: ORTB2_OBJ, ortb2Imp: BID.ortb2Imp}, - {...REQUEST_DATA2, ortb2: ORTB2_OBJ, ortb2Imp: BID.ortb2Imp} - ]} - }); - }); - - it('should return separated requests for video and banner if singleRequest is true', function () { - config.setConfig({ - bidderTimeout: 3000, - twistdigital: { - singleRequest: true, - chunkSize: 2 - } - }); - - const requests = adapter.buildRequests([BID, VIDEO_BID], BIDDER_REQUEST); - expect(requests).to.have.length(2); - }); - - it('should chunk requests if requests exceed chunkSize and singleRequest is true', function () { - config.setConfig({ - bidderTimeout: 3000, - twistdigital: { - singleRequest: true, - chunkSize: 2 - } - }); - - const requests = adapter.buildRequests([BID, BID, BID, BID], BIDDER_REQUEST); - expect(requests).to.have.length(2); - }); - - it('should set fledge correctly if enabled', function () { - config.resetConfig(); - const bidderRequest = utils.deepClone(BIDDER_REQUEST); - bidderRequest.paapi = {enabled: true}; - deepSetValue(bidderRequest, 'ortb2Imp.ext.ae', 1); - const requests = adapter.buildRequests([BID], bidderRequest); - expect(requests[0].data.fledge).to.equal(1); - }); - - after(function () { - getGlobal().bidderSettings = {}; - config.resetConfig(); - sandbox.restore(); - }); - }); - - describe('getUserSyncs', function () { - it('should have valid user sync with iframeEnabled', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.twist.win/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - - it('should have valid user sync with cid on response', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.twist.win/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - - it('should have valid user sync with pixelEnabled', function () { - const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE]); - - expect(result).to.deep.equal([{ - 'url': 'https://sync.twist.win/api/sync/image/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0', - 'type': 'image' - }]); - }); - - it('should have valid user sync with coppa 1 on response', function () { - config.setConfig({ - coppa: 1 - }); - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.twist.win/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=1' - }]); - }); - }); - - describe('interpret response', function () { - it('should return empty array when there is no response', function () { - const responses = adapter.interpretResponse(null); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no ad', function () { - const responses = adapter.interpretResponse({price: 1, ad: ''}); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no price', function () { - const responses = adapter.interpretResponse({price: null, ad: 'great ad'}); - expect(responses).to.be.empty; - }); - - it('should return an array of interpreted banner responses', function () { - const responses = adapter.interpretResponse(SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 0.8, - width: 300, - height: 250, - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 30, - ad: '', - meta: { - advertiserDomains: ['securepubads.g.doubleclick.net'] - } - }); - }); - - it('should get meta from response metaData', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - serverResponse.body.results[0].metaData = { - advertiserDomains: ['twistdigital.com'], - agencyName: 'Agency Name', - }; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses[0].meta).to.deep.equal({ - advertiserDomains: ['twistdigital.com'], - agencyName: 'Agency Name' - }); - }); - - it('should return an array of interpreted video responses', function () { - const responses = adapter.interpretResponse(VIDEO_SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 2, - width: 545, - height: 307, - mediaType: 'video', - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 60, - vastXml: '', - meta: { - advertiserDomains: ['twistdigital.com'] - } - }); - }); - - it('should populate requestId from response in case of singleRequest true', function () { - config.setConfig({ - twistdigital: { - singleRequest: true, - chunkSize: 2 - } - }); - - const responses = adapter.interpretResponse(SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0].requestId).to.equal('2d52001cabd527-response'); - - config.resetConfig(); - }); - - it('should take default TTL', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - delete serverResponse.body.results[0].exp; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0].ttl).to.equal(300); - }); - - it('should add nurl if exists on response', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - serverResponse.body.results[0].nurl = 'https://test.com/win-notice?test=123'; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0].nurl).to.equal('https://test.com/win-notice?test=123'); - }); - }); - - describe('user id system', function () { - TEST_ID_SYSTEMS.forEach((idSystemProvider) => { - const id = Date.now().toString(); - const bid = utils.deepClone(BID); - - const userId = (function () { - switch (idSystemProvider) { - case 'lipb': - return {lipbid: id}; - case 'id5id': - return {uid: id}; - default: - return id; - } - })(); - - bid.userId = { - [idSystemProvider]: userId - }; - - it(`should include 'uid.${idSystemProvider}' in request params`, function () { - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data[`uid.${idSystemProvider}`]).to.equal(id); - }); - }); - // testing bid.userIdAsEids handling - it("should include user ids from bid.userIdAsEids (length=1)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - }) - it("should include user ids from bid.userIdAsEids (length=2)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - }, - { - "source": "rwdcntrl.net", - "uids": [{"id": "fakeid6f35197d5c", "atype": 1}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - expect(requests[0].data['uid.rwdcntrl.net']).to.equal("fakeid6f35197d5c"); - }) - // testing user.ext.eid handling - it("should include user ids from user.ext.eid (length=1)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - }) - it("should include user ids from user.ext.eid (length=2)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - }, - { - "source": "adserver.org", - "uids": [{"id": "fakeid495ff1"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - expect(requests[0].data['uid.adserver.org']).to.equal("fakeid495ff1"); - }) - }); - - describe('alternate param names extractors', function () { - it('should return undefined when param not supported', function () { - const cid = extractCID({'c_id': '1'}); - const pid = extractPID({'p_id': '1'}); - const subDomain = extractSubDomain({'sub_domain': 'prebid'}); - expect(cid).to.be.undefined; - expect(pid).to.be.undefined; - expect(subDomain).to.be.undefined; - }); - - it('should return value when param supported', function () { - const cid = extractCID({'cID': '1'}); - const pid = extractPID({'Pid': '2'}); - const subDomain = extractSubDomain({'subDOMAIN': 'prebid'}); - expect(cid).to.be.equal('1'); - expect(pid).to.be.equal('2'); - expect(subDomain).to.be.equal('prebid'); - }); - }); - - describe('deal id', function () { - before(function () { - getGlobal().bidderSettings = { - twistdigital: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - }); - - describe('unique deal id', function () { - before(function () { - getGlobal().bidderSettings = { - twistdigital: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - const key = 'myKey'; - let uniqueDealId; - beforeEach(() => { - uniqueDealId = getUniqueDealId(storage, key, 0); - }) - - it('should get current unique deal id', function (done) { - // waiting some time so `now` will become past - setTimeout(() => { - const current = getUniqueDealId(storage, key); - expect(current).to.be.equal(uniqueDealId); - done(); - }, 200); - }); - - it('should get new unique deal id on expiration', function (done) { - setTimeout(() => { - const current = getUniqueDealId(storage, key, 100); - expect(current).to.not.be.equal(uniqueDealId); - done(); - }, 200) - }); - }); - - describe('storage utils', function () { - before(function () { - getGlobal().bidderSettings = { - twistdigital: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - it('should get value from storage with create param', function () { - const now = Date.now(); - const clock = useFakeTimers({ - shouldAdvanceTime: true, - now - }); - setStorageItem(storage, 'myKey', 2020); - const {value, created} = getStorageItem(storage, 'myKey'); - expect(created).to.be.equal(now); - expect(value).to.be.equal(2020); - expect(typeof value).to.be.equal('number'); - expect(typeof created).to.be.equal('number'); - clock.restore(); - }); - - it('should get external stored value', function () { - const value = 'superman' - window.localStorage.setItem('myExternalKey', value); - const item = getStorageItem(storage, 'myExternalKey'); - expect(item).to.be.equal(value); - }); - - it('should parse JSON value', function () { - const data = JSON.stringify({event: 'send'}); - const {event} = tryParseJSON(data); - expect(event).to.be.equal('send'); - }); - - it('should get original value on parse fail', function () { - const value = 21; - const parsed = tryParseJSON(value); - expect(typeof parsed).to.be.equal('number'); - expect(parsed).to.be.equal(value); - }); - }); - - describe('validate onBidWon', function () { - beforeEach(function () { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function () { - utils.triggerPixel.restore(); - }); - - it('should call triggerPixel if nurl exists', function () { - const bid = { - adUnitCode: 'div-gpt-ad-12345-0', - adId: '2d52001cabd527', - auctionId: '1fdb5ff1b6eaa7', - transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - status: 'rendered', - timeToRespond: 100, - cpm: 0.8, - originalCpm: 0.8, - creativeId: '12610997325162499419', - currency: 'USD', - originalCurrency: 'USD', - height: 250, - mediaType: 'banner', - nurl: 'https://test.com/win-notice?test=123', - netRevenue: true, - requestId: '2d52001cabd527', - ttl: 30, - width: 300 - }; - adapter.onBidWon(bid); - expect(utils.triggerPixel.called).to.be.true; - - const url = utils.triggerPixel.args[0]; - - expect(url[0]).to.be.equal('https://test.com/win-notice?test=123&adId=2d52001cabd527&creativeId=12610997325162499419&auctionId=1fdb5ff1b6eaa7&transactionId=c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf&adUnitCode=div-gpt-ad-12345-0&cpm=0.8¤cy=USD&originalCpm=0.8&originalCurrency=USD&netRevenue=true&mediaType=banner&timeToRespond=100&status=rendered'); - }); - - it('should not call triggerPixel if nurl does not exist', function () { - const bid = { - adUnitCode: 'div-gpt-ad-12345-0', - adId: '2d52001cabd527', - auctionId: '1fdb5ff1b6eaa7', - transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - status: 'rendered', - timeToRespond: 100, - cpm: 0.8, - originalCpm: 0.8, - creativeId: '12610997325162499419', - currency: 'USD', - originalCurrency: 'USD', - height: 250, - mediaType: 'banner', - netRevenue: true, - requestId: '2d52001cabd527', - ttl: 30, - width: 300 - }; - adapter.onBidWon(bid); - expect(utils.triggerPixel.called).to.be.false; - }); - }); -}); diff --git a/test/spec/modules/ucfunnelAnalyticsAdapter_spec.js b/test/spec/modules/ucfunnelAnalyticsAdapter_spec.js deleted file mode 100644 index 997586c19..000000000 --- a/test/spec/modules/ucfunnelAnalyticsAdapter_spec.js +++ /dev/null @@ -1,487 +0,0 @@ -import { - ucfunnelAnalyticsAdapter, parseBidderCode, parseAdUnitCode, - ANALYTICS_VERSION, BIDDER_STATUS -} from 'modules/ucfunnelAnalyticsAdapter.js'; - -import {expect} from 'chai'; - -const events = require('src/events'); -const constants = require('src/constants.js'); - -const pbuid = 'pbuid-AA778D8A796AEA7A0843E2BBEB677766'; -const adid = 'test-ad-83444226E44368D1E32E49EEBE6D29'; -const auctionId = 'b0b39610-b941-4659-a87c-de9f62d3e13e'; - -describe('ucfunnel Prebid AnalyticsAdapter Testing', function () { - describe('event tracking and message cache manager', function () { - beforeEach(function () { - const configOptions = { - pbuid: pbuid, - adid: adid, - sampling: 0, - }; - - ucfunnelAnalyticsAdapter.enableAnalytics({ - provider: 'ucfunnelAnalytics', - options: configOptions - }); - }); - - afterEach(function () { - ucfunnelAnalyticsAdapter.disableAnalytics(); - }); - - describe('#parseBidderCode()', function() { - it('should get lower case bidder code from bidderCode field value', function() { - const receivedBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_1', - bidder: 'ucfunnel', - bidderCode: 'UCFUNNEL', - requestId: 'a1b2c3d4', - timeToRespond: 72, - cpm: 0.1, - currency: 'USD', - ad: 'fake ad1' - }, - ]; - const result = parseBidderCode(receivedBids[0]); - expect(result).to.equal('ucfunnel'); - }); - it('should get lower case bidder code from bidder field value as bidderCode field is missing', function() { - const receivedBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_1', - bidder: 'UCFUNNEL', - bidderCode: '', - requestId: 'a1b2c3d4', - timeToRespond: 72, - cpm: 0.1, - currency: 'USD', - ad: 'fake ad1' - }, - ]; - const result = parseBidderCode(receivedBids[0]); - expect(result).to.equal('ucfunnel'); - }); - }); - - describe('#parseAdUnitCode()', function() { - it('should get lower case adUnit code from adUnitCode field value', function() { - const receivedBids = [ - { - auctionId: auctionId, - adUnitCode: 'ADUNIT', - bidder: 'ucfunnel', - bidderCode: 'UCFUNNEL', - requestId: 'a1b2c3d4', - timeToRespond: 72, - cpm: 0.1, - currency: 'USD', - ad: 'fake ad1' - }, - ]; - const result = parseAdUnitCode(receivedBids[0]); - expect(result).to.equal('adunit'); - }); - }); - - describe('#getCachedAuction()', function() { - const existing = {timeoutBids: [{}]}; - ucfunnelAnalyticsAdapter.cachedAuctions['test_auction_id'] = existing; - - it('should get the existing cached object if it exists', function() { - const result = ucfunnelAnalyticsAdapter.getCachedAuction('test_auction_id'); - - expect(result).to.equal(existing); - }); - - it('should create a new object and store it in the cache on cache miss', function() { - const result = ucfunnelAnalyticsAdapter.getCachedAuction('no_such_id'); - - expect(result).to.deep.include({ - timeoutBids: [], - }); - }); - }); - - describe('when formatting JSON payload sent to backend', function() { - const receivedBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_1', - bidder: 'ucfunnel', - bidderCode: 'ucfunnel', - requestId: 'a1b2c3d4', - timeToRespond: 72, - cpm: 0.1, - currency: 'USD', - ad: 'fake ad1' - }, - { - auctionId: auctionId, - adUnitCode: 'adunit_1', - bidder: 'ucfunnelx', - bidderCode: 'ucfunnelx', - requestId: 'b2c3d4e5', - timeToRespond: 100, - cpm: 0.08, - currency: 'USD', - ad: 'fake ad2' - }, - { - auctionId: auctionId, - adUnitCode: 'adunit_2', - bidder: 'ucfunnel', - bidderCode: 'ucfunnel', - requestId: 'c3d4e5f6', - timeToRespond: 120, - cpm: 0.09, - currency: 'USD', - ad: 'fake ad3' - }, - ]; - const highestCpmBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_1', - bidder: 'ucfunnel', - bidderCode: 'ucfunnel', - // No requestId - timeToRespond: 72, - cpm: 0.1, - currency: 'USD', - ad: 'fake ad1' - } - ]; - const noBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_2', - bidder: 'ucfunnel', - bidderCode: 'ucfunnel', - bidId: 'a1b2c3d4', - } - ]; - const timeoutBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_2', - bidder: 'ucfunnel', - bidderCode: 'ucfunnel', - bidId: '00123d4c', - } - ]; - function assertHavingRequiredMessageFields(message) { - expect(message).to.include({ - version: ANALYTICS_VERSION, - auctionId: auctionId, - pbuid: pbuid, - adid: adid, - // referrer: window.location.href, - sampling: 0, - prebid: '$prebid.version$', - }); - } - - describe('#createCommonMessage', function() { - it('should correctly serialize some common fields', function() { - const message = ucfunnelAnalyticsAdapter.createCommonMessage(auctionId); - - assertHavingRequiredMessageFields(message); - }); - }); - - describe('#serializeBidResponse', function() { - it('should handle BID properly and serialize bid price related fields', function() { - const result = ucfunnelAnalyticsAdapter.serializeBidResponse(receivedBids[0], BIDDER_STATUS.BID); - - expect(result).to.include({ - prebidWon: false, - isTimeout: false, - status: BIDDER_STATUS.BID, - time: 72, - cpm: 0.1, - currency: 'USD', - }); - }); - - it('should handle NO_BID properly and set status to noBid', function() { - const result = ucfunnelAnalyticsAdapter.serializeBidResponse(noBids[0], BIDDER_STATUS.NO_BID); - - expect(result).to.include({ - prebidWon: false, - isTimeout: false, - status: BIDDER_STATUS.NO_BID, - }); - }); - - it('should handle BID_WON properly and serialize bid price related fields', function() { - const result = ucfunnelAnalyticsAdapter.serializeBidResponse(receivedBids[0], BIDDER_STATUS.BID_WON); - - expect(result).to.include({ - prebidWon: true, - isTimeout: false, - status: BIDDER_STATUS.BID_WON, - time: 72, - cpm: 0.1, - currency: 'USD', - }); - }); - - it('should handle TIMEOUT properly and set status to timeout and isTimeout to true', function() { - const result = ucfunnelAnalyticsAdapter.serializeBidResponse(noBids[0], BIDDER_STATUS.TIMEOUT); - - expect(result).to.include({ - prebidWon: false, - isTimeout: true, - status: BIDDER_STATUS.TIMEOUT, - }); - }); - }); - - describe('#addBidResponseToMessage()', function() { - it('should add a bid response in the output message, grouped by adunit_id and bidder', function() { - const message = { - adUnits: {} - }; - ucfunnelAnalyticsAdapter.addBidResponseToMessage(message, noBids[0], BIDDER_STATUS.NO_BID); - - expect(message.adUnits).to.deep.include({ - 'adunit_2': { - 'ucfunnel': { - prebidWon: false, - isTimeout: false, - status: BIDDER_STATUS.NO_BID, - } - } - }); - }); - }); - - describe('#createBidMessage()', function() { - it('should format auction message sent to the backend', function() { - const args = { - auctionId: auctionId, - timestamp: 1234567890, - timeout: 3000, - auctionEnd: 1234567990, - adUnitCodes: ['adunit_1', 'adunit_2'], - bidsReceived: receivedBids, - noBids: noBids - }; - - const result = ucfunnelAnalyticsAdapter.createBidMessage(args, highestCpmBids, timeoutBids); - - assertHavingRequiredMessageFields(result); - expect(result).to.deep.include({ - auctionElapsed: 100, - adUnits: { - 'adunit_1': { - 'ucfunnel': { - prebidWon: true, - isTimeout: false, - status: BIDDER_STATUS.BID, - time: 72, - cpm: 0.1, - currency: 'USD', - }, - 'ucfunnelx': { - prebidWon: false, - isTimeout: false, - status: BIDDER_STATUS.BID, - time: 100, - cpm: 0.08, - currency: 'USD', - } - }, - 'adunit_2': { - // this bid result exists in both bid and noBid arrays and should be treated as bid - 'ucfunnel': { - prebidWon: false, - isTimeout: true, - status: BIDDER_STATUS.TIMEOUT, - } - } - } - }); - }); - }); - - describe('#createImpressionMessage()', function() { - it('should format message sent to the backend with the bid result', function() { - const bid = receivedBids[0]; - const result = ucfunnelAnalyticsAdapter.createImpressionMessage(bid); - - assertHavingRequiredMessageFields(result); - expect(result.adUnits).to.deep.include({ - 'adunit_1': { - 'ucfunnel': { - prebidWon: true, - isTimeout: false, - status: BIDDER_STATUS.BID_WON, - time: 72, - cpm: 0.1, - currency: 'USD', - } - } - }); - }); - }); - - describe('#handleBidTimeout()', function() { - it('should cached the timeout bid as BID_TIMEOUT event was triggered', function() { - ucfunnelAnalyticsAdapter.cachedAuctions['test_timeout_auction_id'] = { 'timeoutBids': [] }; - const args = [{ - auctionId: 'test_timeout_auction_id', - timestamp: 1234567890, - timeout: 3000, - auctionEnd: 1234567990, - bidsReceived: receivedBids, - noBids: noBids - }]; - - ucfunnelAnalyticsAdapter.handleBidTimeout(args); - const result = ucfunnelAnalyticsAdapter.getCachedAuction('test_timeout_auction_id'); - expect(result).to.deep.include({ - timeoutBids: [{ - auctionId: 'test_timeout_auction_id', - timestamp: 1234567890, - timeout: 3000, - auctionEnd: 1234567990, - bidsReceived: receivedBids, - noBids: noBids - }] - }); - }); - }); - describe('#handleBidWon()', function() { - it('should call createImpressionMessage once as BID_WON event was triggered', function() { - sinon.spy(ucfunnelAnalyticsAdapter, 'createImpressionMessage'); - const receivedBids = [ - { - auctionId: auctionId, - adUnitCode: 'adunit_1', - bidder: 'ucfunnel', - bidderCode: 'ucfunnel', - requestId: 'a1b2c3d4', - timeToRespond: 72, - cpm: 0.1, - currency: 'USD', - ad: 'fake ad1' - }, - ] - - ucfunnelAnalyticsAdapter.handleBidWon(receivedBids[0]); - sinon.assert.callCount(ucfunnelAnalyticsAdapter.createImpressionMessage, 1); - ucfunnelAnalyticsAdapter.createImpressionMessage.restore(); - }); - }); - }); - }); - - describe('ucfunnel Analytics Adapter track handler ', function () { - const configOptions = { - pbuid: pbuid, - adid: adid, - sampling: 1, - }; - - beforeEach(function () { - sinon.stub(events, 'getEvents').returns([]); - ucfunnelAnalyticsAdapter.enableAnalytics({ - provider: 'ucfunnelAnalytics', - options: configOptions - }); - }); - - afterEach(function () { - ucfunnelAnalyticsAdapter.disableAnalytics(); - events.getEvents.restore(); - }); - - it('should call handleBidWon as BID_WON trigger event', function() { - sinon.spy(ucfunnelAnalyticsAdapter, 'handleBidWon'); - events.emit(constants.EVENTS.BID_WON, {}); - sinon.assert.callCount(ucfunnelAnalyticsAdapter.handleBidWon, 1); - ucfunnelAnalyticsAdapter.handleBidWon.restore(); - }); - - it('should call handleBidTimeout as BID_TIMEOUT trigger event', function() { - sinon.spy(ucfunnelAnalyticsAdapter, 'handleBidTimeout'); - events.emit(constants.EVENTS.BID_TIMEOUT, {}); - sinon.assert.callCount(ucfunnelAnalyticsAdapter.handleBidTimeout, 1); - ucfunnelAnalyticsAdapter.handleBidTimeout.restore(); - }); - - it('should call handleAuctionEnd as AUCTION_END trigger event', function() { - sinon.spy(ucfunnelAnalyticsAdapter, 'handleAuctionEnd'); - events.emit(constants.EVENTS.AUCTION_END, {}); - sinon.assert.callCount(ucfunnelAnalyticsAdapter.handleAuctionEnd, 1); - ucfunnelAnalyticsAdapter.handleAuctionEnd.restore(); - }); - }); - - describe('enableAnalytics and config parser', function () { - const configOptions = { - pbuid: pbuid, - adid: adid, - sampling: 0, - }; - - beforeEach(function () { - ucfunnelAnalyticsAdapter.enableAnalytics({ - provider: 'ucfunnelAnalytics', - options: configOptions - }); - }); - - afterEach(function () { - ucfunnelAnalyticsAdapter.disableAnalytics(); - }); - - it('should parse config correctly with optional values', function () { - expect(ucfunnelAnalyticsAdapter.getAnalyticsOptions().options).to.deep.equal(configOptions); - expect(ucfunnelAnalyticsAdapter.getAnalyticsOptions().pbuid).to.equal(configOptions.pbuid); - expect(ucfunnelAnalyticsAdapter.getAnalyticsOptions().adid).to.equal(configOptions.adid); - expect(ucfunnelAnalyticsAdapter.getAnalyticsOptions().sampled).to.equal(false); - }); - - it('should not enable Analytics when adid is missing', function () { - const configOptions = { - options: { - pbuid: pbuid - } - }; - const validConfig = ucfunnelAnalyticsAdapter.initConfig(configOptions); - expect(validConfig).to.equal(false); - }); - - it('should not enable Analytics when pbuid is missing', function () { - const configOptions = { - options: { - adid: adid - } - }; - const validConfig = ucfunnelAnalyticsAdapter.initConfig(configOptions); - expect(validConfig).to.equal(false); - }); - it('should fall back to default value when sampling factor is not number', function () { - const configOptions = { - options: { - pbuid: pbuid, - adid: adid, - sampling: 'string', - } - }; - ucfunnelAnalyticsAdapter.enableAnalytics({ - provider: 'ucfunnelAnalytics', - options: configOptions - }); - - expect(ucfunnelAnalyticsAdapter.getAnalyticsOptions().sampled).to.equal(false); - }); - }); -}); diff --git a/test/spec/modules/ucfunnelBidAdapter_spec.js b/test/spec/modules/ucfunnelBidAdapter_spec.js deleted file mode 100644 index 3e78ee4d0..000000000 --- a/test/spec/modules/ucfunnelBidAdapter_spec.js +++ /dev/null @@ -1,367 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/ucfunnelBidAdapter.js'; -import {BANNER, VIDEO, NATIVE} from 'src/mediaTypes.js'; -import {deepClone} from '../../../src/utils.js'; -const URL = 'https://hb.aralego.com/header'; -const BIDDER_CODE = 'ucfunnel'; - -const bidderRequest = { - uspConsent: '1YNN', - refererInfo: { - domain: 'example.com', - page: 'http://example.com/index.html' - } -}; - -const userId = { - 'criteoId': 'vYlICF9oREZlTHBGRVdrJTJCUUJnc3U2ckNVaXhrV1JWVUZVSUxzZmJlcnJZR0ZxbVhFRnU5bDAlMkJaUWwxWTlNcmdEeHFrJTJGajBWVlV4T3lFQ0FyRVcxNyUyQlIxa0lLSlFhcWJpTm9PSkdPVkx0JTJCbzlQRTQlM0Q', - 'id5id': {'uid': 'ID5-8ekgswyBTQqnkEKy0ErmeQ1GN5wV4pSmA-RE4eRedA'}, - 'netId': 'fH5A3n2O8_CZZyPoJVD-eabc6ECb7jhxCicsds7qSg', - 'parrableId': {'eid': '01.1608624401.fe44bca9b96873084a0d4e9d0ac5729f13790ba8f8e58fa4707b6b3c096df91c6b5f254992bdad4ab1dd4a89919081e9b877d7a039ac3183709277665bac124f28e277d109f0ff965058'}, - 'pubcid': 'd8aa10fa-d86c-451d-aad8-5f16162a9e64', - 'tdid': 'D6885E90-2A7A-4E0F-87CB-7734ED1B99A3', - 'haloId': {}, - 'uid2': {'id': 'eb33b0cb-8d35-4722-b9c0-1a31d4064888'}, - 'connectid': '4567' -} - -const validBannerBidReq = { - bidder: BIDDER_CODE, - params: { - adid: 'ad-34BBD2AA24B678BBFD4E7B9EE3B872D' - }, - sizes: [[300, 250], [336, 280]], - bidId: '263be71e91dd9d', - auctionId: '9ad1fa8d-2297-4660-a018-b39945054746', - ortb2Imp: { - ext: { - gpid: '/1111/homepage#div-leftnav' - } - }, - userId: userId, - ortb2: { - source: { - ext: { - schain: { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'exchange1.com', - 'sid': '1234', - 'hp': 1, - 'rid': 'bid-request-1', - 'name': 'publisher', - 'domain': 'publisher.com' - } - ] - } - } - } - } -}; - -const invalidBannerBidReq = { - bidder: BIDDER_CODE, - params: { - adid: 123456789 - }, - sizes: [[300, 250]], - bidId: '263be71e91dd9d', - auctionId: '9ad1fa8d-2297-4660-a018-b39945054746' -}; - -const validBannerBidRes = { - creative_type: BANNER, - ad_id: 'ad-34BBD2AA24B678BBFD4E7B9EE3B872D', - adm: '
', - cpm: 1.01, - height: 250, - width: 300, - crid: 'test-crid' -}; - -const invalidBannerBidRes = ''; - -const validVideoBidReq = { - bidder: BIDDER_CODE, - params: { - adid: 'ad-9A22D466494297EAC443D967B2622DA9' - }, - sizes: [[640, 360]], - bidId: '263be71e91dd9f', - auctionId: '9ad1fa8d-2297-4660-a018-b39945054746', -}; - -const validVideoBidRes = { - creative_type: VIDEO, - ad_id: 'ad-9A22D466494297EAC443D967B2622DA9', - vastUrl: 'https://ads.aralego.com/ads/58f9749f-0553-4993-8d9a-013a38b29e55', - vastXml: 'ucX I-Primo 00:00:30', - cpm: 1.01, - width: 640, - height: 360 -}; - -const validNativeBidReq = { - bidder: BIDDER_CODE, - params: { - adid: 'ad-627736446B2BD3A60E8AEABDB7BD833E' - }, - sizes: [[1, 1]], - bidId: '263be71e91dda0', - auctionId: '9ad1fa8d-2297-4660-a018-b39945054746', -}; - -const validNativeBidRes = { - creative_type: NATIVE, - ad_id: 'ad-9A22D466494297EAC443D967B2622DA9', - native: { - title: 'ucfunnel adExchange', - body: 'We monetize your traffic via historic data driven protocol', - cta: 'Learn more', - sponsoredBy: 'ucfunnel Co., Ltd.', - image: { - url: 'https://cdn.aralego.net/img/main/AdGent-1200x627.jpg', - width: 1200, - height: 627 - }, - icon: { - url: 'https://cdn.aralego.net/img/logo/logo-84x84.jpg', - widt: 84, - heigh: 84 - }, - clickUrl: 'https://www.ucfunnel.com', - clicktrackers: ['https://dev-ad-track.aralego.com/v1/nat/click?iid=72165d02-408a-470c-bb52-ae7d7b0a4549'], - impressionTrackers: ['https://www.aralego.net/imp?mf=native&adid=ad-9A22D466494297EAC443D967B2622DA9&auc=9ad1fa8d-2297-4660-a018-b39945054746'], - }, - cpm: 1.01, - height: 1, - width: 1 -}; - -const gdprConsent = { - consentString: 'CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA', - vendorData: {}, - gdprApplies: true, - apiVersion: 2 -}; - -describe('ucfunnel Adapter', function () { - describe('request', function () { - it('should validate bid request', function () { - expect(spec.isBidRequestValid(validBannerBidReq)).to.equal(true); - }); - it('should not validate incorrect bid request', function () { - expect(spec.isBidRequestValid(invalidBannerBidReq)).to.equal(false); - }); - }); - describe('build request', function () { - let request; - before(() => { - request = spec.buildRequests([validBannerBidReq], bidderRequest); - }) - it('should create a POST request for every bid', function () { - expect(request[0].method).to.equal('GET'); - expect(request[0].url).to.equal(spec.ENDPOINT); - }); - - it('should attach the bid request object', function () { - expect(request[0].bidRequest).to.equal(validBannerBidReq); - }); - - it('should set gpid if configured', function () { - const data = request[0].data; - expect(data.gpid).to.equal('/1111/homepage#div-leftnav'); - }); - - it('should attach request data', function () { - const data = request[0].data; - const [ width, height ] = validBannerBidReq.sizes[0]; - expect(data.usprivacy).to.equal('1YNN'); - expect(data.adid).to.equal('ad-34BBD2AA24B678BBFD4E7B9EE3B872D'); - expect(data.w).to.equal(width); - expect(data.h).to.equal(height); - expect(data.eids).to.equal('uid2,eb33b0cb-8d35-4722-b9c0-1a31d4064888!verizonMediaId,4567'); - expect(data.schain).to.equal('1.0,1!exchange1.com,1234,1,bid-request-1,publisher,publisher.com'); - }); - - it('should support multiple size', function () { - const sizes = [[300, 250], [336, 280]]; - const format = '300,250;336,280'; - validBannerBidReq.sizes = sizes; - const requests = spec.buildRequests([ validBannerBidReq ], bidderRequest); - const data = requests[0].data; - expect(data.w).to.equal(sizes[0][0]); - expect(data.h).to.equal(sizes[0][1]); - expect(data.format).to.equal(format); - }); - - it('should set bidfloor if configured', function() { - const bid = deepClone(validBannerBidReq); - bid.getFloor = function() { - return { - currency: 'USD', - floor: 2.02 - } - }; - const requests = spec.buildRequests([ bid ], bidderRequest); - const data = requests[0].data; - expect(data.fp).to.equal(2.02); - }); - - it('should set bidfloor if configured', function() { - const bid = deepClone(validBannerBidReq); - bid.params.bidfloor = 2.01; - const requests = spec.buildRequests([ bid ], bidderRequest); - const data = requests[0].data; - expect(data.fp).to.equal(2.01); - }); - - it('should set bidfloor if configured', function() { - const bid = deepClone(validBannerBidReq); - bid.getFloor = function() { - return { - currency: 'USD', - floor: 2.02 - } - }; - bid.params.bidfloor = 2.01; - const requests = spec.buildRequests([ bid ], bidderRequest); - const data = requests[0].data; - expect(data.fp).to.equal(2.01); - }); - }); - - describe('interpretResponse', function () { - describe('should support banner', function () { - let request, result; - before(() => { - request = spec.buildRequests([ validBannerBidReq ], bidderRequest); - result = spec.interpretResponse({body: validBannerBidRes}, request[0]); - }); - - it('should build bid array for banner', function () { - expect(result.length).to.equal(1); - }); - - it('should have all relevant fields', function () { - const bid = result[0]; - - expect(bid.mediaType).to.equal(BANNER); - expect(bid.ad).to.exist; - expect(bid.requestId).to.equal('263be71e91dd9d'); - expect(bid.cpm).to.equal(1.01); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - }); - }); - - describe('handle banner no ad', function () { - let request, result; - before(() => { - request = spec.buildRequests([ validBannerBidReq ], bidderRequest); - result = spec.interpretResponse({body: invalidBannerBidRes}, request[0]); - }) - it('should build bid array for banner', function () { - expect(result.length).to.equal(1); - }); - - it('should have all relevant fields', function () { - const bid = result[0]; - - expect(bid.ad).to.exist; - expect(bid.requestId).to.equal('263be71e91dd9d'); - expect(bid.cpm).to.equal(0); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - }); - }); - - describe('handle banner cpm under bidfloor', function () { - let request, result; - before(() => { - request = spec.buildRequests([ validBannerBidReq ], bidderRequest); - result = spec.interpretResponse({body: invalidBannerBidRes}, request[0]); - }) - it('should build bid array for banner', function () { - expect(result.length).to.equal(1); - }); - - it('should have all relevant fields', function () { - const bid = result[0]; - - expect(bid.ad).to.exist; - expect(bid.requestId).to.equal('263be71e91dd9d'); - expect(bid.cpm).to.equal(0); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - }); - }); - - describe('should support video', function () { - let request, result; - before(() => { - request = spec.buildRequests([ validVideoBidReq ], bidderRequest); - result = spec.interpretResponse({body: validVideoBidRes}, request[0]); - }) - it('should build bid array', function () { - expect(result.length).to.equal(1); - }); - - it('should have all relevant fields', function () { - const bid = result[0]; - - expect(bid.mediaType).to.equal(VIDEO); - expect(bid.vastUrl).to.exist; - expect(bid.vastXml).to.exist; - expect(bid.requestId).to.equal('263be71e91dd9f'); - expect(bid.cpm).to.equal(1.01); - expect(bid.width).to.equal(640); - expect(bid.height).to.equal(360); - }); - }); - - describe('should support native', function () { - let request, result; - before(() => { - request = spec.buildRequests([ validNativeBidReq ], bidderRequest); - result = spec.interpretResponse({body: validNativeBidRes}, request[0]); - }) - it('should build bid array', function () { - expect(result.length).to.equal(1); - }); - - it('should have all relevant fields', function () { - const bid = result[0]; - - expect(bid.mediaType).to.equal(NATIVE); - expect(bid.native).to.exist; - expect(bid.requestId).to.equal('263be71e91dda0'); - expect(bid.cpm).to.equal(1.01); - expect(bid.width).to.equal(1); - expect(bid.height).to.equal(1); - expect(bid.native.clickUrl).to.equal('https://www.ucfunnel.com'); - expect(bid.native.clickTrackers[0]).to.equal('https://dev-ad-track.aralego.com/v1/nat/click?iid=72165d02-408a-470c-bb52-ae7d7b0a4549'); - }); - }); - }); - - describe('cookie sync', function () { - describe('cookie sync iframe', function () { - const result = spec.getUserSyncs({'iframeEnabled': true}, null, gdprConsent); - - it('should return cookie sync iframe info', function () { - expect(result[0].type).to.equal('iframe'); - expect(result[0].url).to.equal('https://cdn.aralego.net/ucfad/cookie/sync.html?gdpr=1&euconsent-v2=CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA&'); - }); - }); - describe('cookie sync image', function () { - const result = spec.getUserSyncs({'pixelEnabled': true}, null, gdprConsent); - it('should return cookie sync image info', function () { - expect(result[0].type).to.equal('image'); - expect(result[0].url).to.equal('https://sync.aralego.com/idSync?gdpr=1&euconsent-v2=CO9rhBTO9rhBTAcABBENBCCsAP_AAH_AACiQHItf_X_fb3_j-_59_9t0eY1f9_7_v20zjgeds-8Nyd_X_L8X42M7vB36pq4KuR4Eu3LBIQdlHOHcTUmw6IkVqTPsbk2Mr7NKJ7PEinMbe2dYGH9_n9XTuZKY79_s___z__-__v__7_f_r-3_3_vp9V---3YHIgEmGpfARZiWOBJNGlUKIEIVxIdACACihGFomsICVwU7K4CP0EDABAagIwIgQYgoxZBAAAAAElEQEgB4IBEARAIAAQAqQEIACNAEFgBIGAQACgGhYARQBCBIQZHBUcpgQESLRQTyVgCUXexhhCGUUANAg4AA.YAAAAAAAAAAA&'); - }); - }); - }); -}); diff --git a/test/spec/modules/underdogmediaBidAdapter_spec.js b/test/spec/modules/underdogmediaBidAdapter_spec.js deleted file mode 100644 index 466d856ab..000000000 --- a/test/spec/modules/underdogmediaBidAdapter_spec.js +++ /dev/null @@ -1,1058 +0,0 @@ -import { - expect -} from 'chai'; -import { - spec, - resetUserSync -} from 'modules/underdogmediaBidAdapter.js'; -import { config } from '../../../src/config.js'; - -describe('UnderdogMedia adapter', function () { - let bidRequests; - let bidderRequest; - - beforeEach(function () { - bidRequests = [{ - bidder: 'underdogmedia', - params: { - siteId: 12143 - }, - adUnitCode: '/19968336/header-bid-tag-1', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - [728, 90], - [160, 600], - [320, 50] - ], - } - }, - bidId: '23acc48ad47af5', - auctionId: '0fb4905b-9456-4152-86be-c6f6d259ba99', - bidderRequestId: '1c56ad30b9b8ca8', - transactionId: '92489f71-1bf2-49a0-adf9-000cea934729' - }]; - - bidderRequest = { - timeout: 3000, - gdprConsent: { - gdprApplies: 1, - consentString: 'consentDataString', - vendorData: { - vendorConsents: { - '159': 1 - }, - }, - }, - } - }); - - describe('implementation', function () { - describe('for requests', function () { - it('should accept valid bid', function () { - const validBid = { - bidder: 'underdogmedia', - params: { - siteId: '12143' - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ] - } - } - }; - const isValid = spec.isBidRequestValid(validBid); - - expect(isValid).to.equal(true); - }); - - it('should reject invalid bid missing sizes', function () { - const invalidBid = { - bidder: 'underdogmedia', - params: { - siteId: '12143', - } - }; - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.equal(false); - }); - - it('should reject invalid bid missing siteId', function () { - const invalidBid = { - bidder: 'underdogmedia', - params: {}, - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ] - } - } - }; - const isValid = spec.isBidRequestValid(invalidBid); - - expect(isValid).to.equal(false); - }); - - it('request data should contain sid', function () { - const bidRequests = [{ - bidId: '3c9408cdbf2f68', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - params: { - siteId: '12143' - }, - auctionId: '10b327aa396609', - adUnitCode: '/123456/header-bid-tag-1' - }]; - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.sid).to.equal(12143); - }); - - it('request data should contain sizes', function () { - const bidRequests = [{ - bidId: '3c9408cdbf2f68', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [728, 90] - ] - } - }, - bidder: 'underdogmedia', - params: { - siteId: '12143' - }, - auctionId: '10b327aa396609', - adUnitCode: '/123456/header-bid-tag-1' - }]; - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.placements[0].sizes[0]).to.equal('300x250'); - expect(request.data.placements[0].sizes[1]).to.equal('728x90'); - }); - - it('request data should contain gdpr info', function () { - const bidRequests = [{ - bidId: '3c9408cdbf2f68', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [728, 90] - ] - } - }, - bidder: 'underdogmedia', - params: { - siteId: '12143' - }, - auctionId: '10b327aa396609', - adUnitCode: '/123456/header-bid-tag-1' - }]; - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.gdpr.gdprApplies).to.equal(true); - expect(request.data.gdpr.consentGiven).to.equal(true); - expect(request.data.gdpr.consentData).to.equal('consentDataString'); - }); - - it('should not build a request if no vendorConsent', function () { - const bidRequests = [{ - bidId: '3c9408cdbf2f68', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [728, 90] - ] - } - }, - bidder: 'underdogmedia', - params: { - siteId: '12143' - }, - auctionId: '10b327aa396609', - adUnitCode: '/123456/header-bid-tag-1' - }]; - - const bidderRequest = { - timeout: 3000, - gdprConsent: { - gdprApplies: 1, - consentString: 'consentDataString', - vendorData: { - vendorConsents: { - '159': 0 - }, - }, - }, - } - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request).to.equal(undefined); - }); - - it('should properly build a request if no vendorConsent but no gdprApplies', function () { - const bidRequests = [{ - bidId: '3c9408cdbf2f68', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [728, 90] - ] - } - }, - bidder: 'underdogmedia', - params: { - siteId: '12143' - }, - auctionId: '10b327aa396609', - adUnitCode: '/123456/header-bid-tag-1' - }]; - - const bidderRequest = { - timeout: 3000, - gdprConsent: { - gdprApplies: 0, - consentString: 'consentDataString', - vendorData: { - vendorConsents: { - '159': 0 - }, - }, - }, - } - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.placements[0].sizes[0]).to.equal('300x250'); - expect(request.data.placements[0].sizes[1]).to.equal('728x90'); - expect(request.data.sid).to.equal(12143); - expect(request.data.gdpr.gdprApplies).to.equal(false); - expect(request.data.gdpr.consentGiven).to.equal(false); - expect(request.data.gdpr.consentData).to.equal('consentDataString'); - }); - - it('should properly build a request if gdprConsent empty', function () { - const bidRequests = [{ - bidId: '3c9408cdbf2f68', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [728, 90] - ] - } - }, - bidder: 'underdogmedia', - params: { - siteId: '12143' - }, - auctionId: '10b327aa396609', - adUnitCode: '/123456/header-bid-tag-1' - }]; - - const bidderRequest = { - timeout: 3000, - gdprConsent: {} - } - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.placements[0].sizes[0]).to.equal('300x250'); - expect(request.data.placements[0].sizes[1]).to.equal('728x90'); - expect(request.data.sid).to.equal(12143); - }); - - it('should have uspConsent if defined', function () { - const uspConsent = '1YYN' - bidderRequest.uspConsent = uspConsent - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request.data.usp.uspConsent).to.equal(uspConsent); - }); - - it('should have correct number of placements', function () { - const bidRequests = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '2dbc995ad299c', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [160, 600] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-0' - } - }, - params: { - siteId: '12143' - }, - }, - { - adUnitCode: 'div-gpt-ad-2460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '3a378b833cdef4', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-1' - } - }, - params: { - siteId: '12143' - }, - }, - { - adUnitCode: 'div-gpt-ad-3460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '4088f04e07c2a1', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [160, 600] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-2' - } - }, - params: { - siteId: '12143' - }, - } - ]; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.usp.uspConsent).to.be.undefined; - expect(request.data.placements.length).to.equal(3); - }); - - it('should have correct adUnitCode for each placement', function () { - const bidRequests = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '2dbc995ad299c', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [160, 600] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-0' - } - }, - params: { - siteId: '12143' - }, - }, - { - adUnitCode: 'div-gpt-ad-2460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '3a378b833cdef4', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-1' - } - }, - params: { - siteId: '12143' - }, - }, - { - adUnitCode: 'div-gpt-ad-3460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '4088f04e07c2a1', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [160, 600] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-2' - } - }, - params: { - siteId: '12143' - }, - } - ]; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.usp.uspConsent).to.be.undefined; - expect(request.data.placements[0].adUnitCode).to.equal('div-gpt-ad-1460505748561-0'); - expect(request.data.placements[1].adUnitCode).to.equal('div-gpt-ad-2460505748561-0'); - expect(request.data.placements[2].adUnitCode).to.equal('div-gpt-ad-3460505748561-0'); - }); - - it('should have gpid if it exists', function () { - const bidRequests = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '2dbc995ad299c', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [160, 600] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-0' - } - }, - params: { - siteId: '12143' - }, - }]; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.placements[0].gpid).to.equal('/19968336/header-bid-tag-0'); - }); - - it('gpid should be undefined if it does not exists', function () { - const bidRequests = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '2dbc995ad299c', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [160, 600] - ] - } - }, - params: { - siteId: '12143' - }, - }]; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.placements[0].gpid).to.equal(undefined); - }); - - it('should have productId equal to 1 if the productId is standard', function () { - const bidRequests = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '2dbc995ad299c', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [160, 600] - ] - } - }, - params: { - siteId: '12143', - productId: 'standard' - }, - }]; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.placements[0].productId).to.equal(1); - }); - - it('should have productId equal to 2 if the productId is adhesion', function () { - const bidRequests = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '2dbc995ad299c', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [160, 600] - ] - } - }, - params: { - siteId: '12143', - productId: 'adhesion' - }, - }]; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.placements[0].productId).to.equal(2); - }); - - it('productId should default to 1 if it is not defined', function () { - const bidRequests = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '2dbc995ad299c', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [160, 600] - ] - } - }, - params: { - siteId: '12143' - }, - }]; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.placements[0].productId).to.equal(1); - }); - - it('should have correct sizes for multiple placements', function () { - const bidRequests = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '2dbc995ad299c', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [160, 600] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-0' - } - }, - params: { - siteId: '12143' - }, - }, - { - adUnitCode: 'div-gpt-ad-2460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '3a378b833cdef4', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-1' - } - }, - params: { - siteId: '12143' - }, - }, - { - adUnitCode: 'div-gpt-ad-3460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '4088f04e07c2a1', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [160, 600] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-2' - } - }, - params: { - siteId: '12143' - }, - } - ]; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.placements[0].sizes.length).to.equal(2); - expect(request.data.placements[0].sizes[0]).to.equal('300x250'); - expect(request.data.placements[0].sizes[1]).to.equal('160x600'); - expect(request.data.placements[1].sizes.length).to.equal(1); - expect(request.data.placements[1].sizes[0]).to.equal('300x250'); - expect(request.data.placements[2].sizes.length).to.equal(1); - expect(request.data.placements[2].sizes[0]).to.equal('160x600'); - }); - - it('should have ref if it exists', function () { - const bidderRequest = { - timeout: 3000, - gdprConsent: { - gdprApplies: 1, - consentString: 'consentDataString', - vendorData: { - vendorConsents: { - '159': 1 - }, - }, - }, - refererInfo: { - page: 'www.example.com' - } - } - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.ref).to.equal('www.example.com'); - }); - - it('ref should be undefined if it does not exist', function () { - const bidderRequest = { - timeout: 3000, - gdprConsent: { - gdprApplies: 1, - consentString: 'consentDataString', - vendorData: { - vendorConsents: { - '159': 1 - }, - }, - } - } - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.ref).to.equal(undefined); - }); - - it('should have pbTimeout to be 3001 if bidder timeout does not exists', function () { - config.setConfig({ bidderTimeout: '' }) - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.pbTimeout).to.equal(3001) - }) - - it('should have pbTimeout to be a numerical value if bidder timeout is in a string', function () { - config.setConfig({ bidderTimeout: '1000' }) - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.pbTimeout).to.equal(1000) - }) - - it('should have pubcid if it exists', function () { - const bidRequests = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '2dbc995ad299c', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [160, 600] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-0' - } - }, - params: { - siteId: '12143' - }, - userIdAsEids: [{ - source: 'pubcid.org', - uids: [{ id: 'sample-user-id' }] - }] - }]; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.userIds.pubcid).to.equal('sample-user-id'); - }); - - it('pubcid should be undefined if it does not exist', function () { - const bidRequests = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '2dbc995ad299c', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [160, 600] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-0' - } - }, - params: { - siteId: '12143' - }, - }]; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.userIds.pubcid).to.equal(undefined); - }); - - it('should have unifiedId if tdid if it exists', function () { - const bidRequests = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '2dbc995ad299c', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [160, 600] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-0' - } - }, - params: { - siteId: '12143' - }, - userIdAsEids: [{ - source: 'adserver.org', - uids: [{ id: 'sample-user-id' }] - }] - }]; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.userIds.unifiedId).to.equal('sample-user-id'); - }); - - it('unifiedId should be undefined if tdid does not exist', function () { - const bidRequests = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '2dbc995ad299c', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [160, 600] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-0' - } - }, - params: { - siteId: '12143' - } - }]; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.userIds.unifiedId).to.equal(undefined); - }); - - it('should have correct viewability information', function () { - const bidRequests = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - auctionId: 'dfa93f1f-6ecc-4d75-8725-f5cb92307658', - bidId: '2dbc995ad299c', - bidder: 'underdogmedia', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [160, 600] - ] - } - }, - ortb2Imp: { - ext: { - gpid: '/19968336/header-bid-tag-0' - } - }, - params: { - siteId: '12143' - }, - }]; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - expect(request.data.placements[0].viewability).to.equal(-1) - }); - }); - - describe('bid responses', function () { - it('should return complete bid response', function () { - const serverResponse = { - body: { - mids: [{ - ad_code_html: 'ad_code_html', - ad_unit_code: '/19968336/header-bid-tag-1', - advertiser_domains: ['domain1'], - cpm: 2.5, - height: '600', - mid: '32634', - notification_url: 'notification_url', - tid: '4', - width: '160', - }, - { - ad_code_html: 'ad_code_html', - ad_unit_code: '/19968336/header-bid-tag-1', - cpm: 3.0, - height: '250', - mid: '32633', - notification_url: 'notification_url', - tid: '2', - width: '300' - }, - ] - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - - expect(bids).to.be.lengthOf(2); - - expect(bids[0].meta.advertiserDomains).to.deep.equal(['domain1']) - expect(bids[0].cpm).to.equal(2.5); - expect(bids[0].width).to.equal('160'); - expect(bids[0].height).to.equal('600'); - expect(bids[0].ad).to.have.length.above(1); - expect(bids[0].creativeId).to.equal('32634'); - expect(bids[0].currency).to.equal('USD'); - }); - - it('should return empty bid response if mids empty', function () { - const serverResponse = { - body: { - mids: [] - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - - expect(bids).to.be.lengthOf(0); - }); - - it('should return empty bid response on incorrect size', function () { - const serverResponse = { - body: { - mids: [{ - ad_code_html: 'ad_code_html', - cpm: 2.5, - height: '123', - mid: '32634', - notification_url: 'notification_url', - tid: '4', - width: '160' - }] - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - - expect(bids).to.be.lengthOf(0); - }); - - it('should return empty bid response on 0 cpm', function () { - const serverResponse = { - body: { - mids: [{ - ad_code_html: 'ad_code_html', - cpm: 0, - height: '600', - mid: '32634', - notification_url: 'notification_url', - tid: '4', - width: '160' - }] - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - - expect(bids).to.be.lengthOf(0); - }); - - it('should return empty bid response if no ad in response', function () { - const serverResponse = { - body: { - mids: [{ - ad_code_html: '', - cpm: 2.5, - height: '600', - mid: '32634', - notification_url: 'notification_url', - tid: '4', - width: '160' - }] - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - - expect(bids).to.be.lengthOf(0); - }); - - it('ad html string should contain the notification urls', function () { - const serverResponse = { - body: { - mids: [{ - ad_code_html: 'ad_cod_html', - ad_unit_code: '/19968336/header-bid-tag-1', - cpm: 2.5, - height: '600', - mid: '32634', - notification_url: 'notification_url', - tid: '4', - width: '160' - }] - } - }; - const request = spec.buildRequests(bidRequests, bidderRequest); - const bids = spec.interpretResponse(serverResponse, request); - - expect(bids[0].ad).to.have.string('notification_url'); - expect(bids[0].ad).to.have.string(';style=adapter'); - }); - }); - }); - - describe('getUserSyncs', function () { - const syncOptionsPixelOnly = { - 'pixelEnabled': true - }; - - const syncOptionsIframeOnly = { - 'iframeEnabled': true - }; - - const syncOptionsPixelAndIframe = { - 'pixelEnabled': true, - 'iframeEnabled': true - }; - - const responseWithUserSyncs = [{ - body: { - userSyncs: [{ - type: 'image', - url: 'https://test.url.com' - }, - { - type: 'iframe', - url: 'https://test.url.com' - } - ] - } - }]; - - const responseWithEmptyUserSyncs = [{ - body: { - userSyncs: [] - } - }]; - - it('user syncs should only return what is allowed', function () { - const result = spec.getUserSyncs(syncOptionsPixelOnly, responseWithUserSyncs); - expect(result[0].type).to.equal('image'); - expect(result.length).to.equal(1); - }); - - it('user syncs should only load once per user', function () { - const result = spec.getUserSyncs(syncOptionsPixelAndIframe, responseWithUserSyncs); - expect(result).to.equal(undefined); - }); - - it('user syncs should return undefined when empty', function () { - resetUserSync(); - - const result = spec.getUserSyncs(syncOptionsPixelAndIframe, responseWithEmptyUserSyncs); - expect(result).to.equal(undefined); - }); - - it('should reset USER_SYNCED flag, allowing another sync', function () { - resetUserSync(); - - const result = spec.getUserSyncs(syncOptionsIframeOnly, responseWithUserSyncs); - expect(result[0].type).to.equal('iframe'); - expect(result.length).to.equal(1); - }); - - it('should return all enabled syncs', function () { - resetUserSync(); - - const result = spec.getUserSyncs(syncOptionsPixelAndIframe, responseWithUserSyncs); - expect(result[0].type).to.equal('image'); - expect(result[1].type).to.equal('iframe'); - expect(result.length).to.equal(2); - }); - }); -}); diff --git a/test/spec/modules/undertoneBidAdapter_spec.js b/test/spec/modules/undertoneBidAdapter_spec.js deleted file mode 100644 index ed531371a..000000000 --- a/test/spec/modules/undertoneBidAdapter_spec.js +++ /dev/null @@ -1,665 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/undertoneBidAdapter.js'; -import {BANNER, VIDEO} from '../../../src/mediaTypes.js'; -import {deepClone, getWinDimensions} from '../../../src/utils.js'; - -const URL = 'https://hb.undertone.com/hb'; -const BIDDER_CODE = 'undertone'; -const validBidReq = { - bidder: BIDDER_CODE, - params: { - placementId: '10433394', - publisherId: 12345 - }, - sizes: [[300, 250], [300, 600]], - bidId: '263be71e91dd9d', - auctionId: '9ad1fa8d-2297-4660-a018-b39945054747', -}; - -const invalidBidReq = { - bidder: BIDDER_CODE, - params: { - placementId: '123456789' - }, - sizes: [[300, 250], [300, 600]], - bidId: '263be71e91dd9d', - auctionId: '9ad1fa8d-2297-4660-a018-b39945054746' -}; - -const videoBidReq = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - bidder: BIDDER_CODE, - params: { - placementId: '10433394', - publisherId: 12345, - video: { - id: 123, - skippable: true, - playbackMethod: 2, - maxDuration: 30 - } - }, - ortb2Imp: { - ext: { - gpid: '/1111/gpid#728x90', - } - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 480], - placement: 1, - plcmt: 1 - } - }, - sizes: [[300, 250], [300, 600]], - bidId: '263be71e91dd9d', - auctionId: '9ad1fa8d-2297-4660-a018-b39945054746' -}, -{ - adUnitCode: 'div-gpt-ad-1460505748561-1', - bidder: BIDDER_CODE, - params: { - placementId: '10433395', - publisherId: 12345 - }, - ortb2Imp: { - ext: { - data: {}, - gpid: '/1111/pbadslot#728x90' - } - }, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [640, 480] - } - }, - sizes: [[300, 250], [300, 600]], - bidId: '263be71e91dd9d', - auctionId: '9ad1fa8d-2297-4660-a018-b39945054746' -}]; -const schainObj = { - 'ver': '1.0', - 'complete': 1, - 'nodes': [ - { - 'asi': 'indirectseller.com', - 'sid': '00001', - 'hp': 1 - }, - - { - 'asi': 'indirectseller-2.com', - 'sid': '00002', - 'hp': 2 - } - ] -}; -const bidReq = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - bidder: BIDDER_CODE, - params: { - placementId: '10433394', - publisherId: 12345, - }, - sizes: [[300, 250], [300, 600]], - bidId: '263be71e91dd9d', - auctionId: '9ad1fa8d-2297-4660-a018-b39945054746' -}, -{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - bidder: BIDDER_CODE, - params: { - publisherId: 12345 - }, - sizes: [[1, 1]], - bidId: '453cf42d72bb3c', - auctionId: '6c22f5a5-59df-4dc6-b92c-f433bcf0a874', - ortb2: { source: { ext: { schain: schainObj } } } -}]; - -const supplyChainedBidReqs = [{ - adUnitCode: 'div-gpt-ad-1460505748561-0', - bidder: BIDDER_CODE, - params: { - placementId: '10433394', - publisherId: 12345, - }, - sizes: [[300, 250], [300, 600]], - bidId: '263be71e91dd9d', - auctionId: '9ad1fa8d-2297-4660-a018-b39945054746', - ortb2: { source: { ext: { schain: schainObj } } } -}, { - adUnitCode: 'div-gpt-ad-1460505748561-0', - bidder: BIDDER_CODE, - params: { - publisherId: 12345 - }, - sizes: [[1, 1]], - bidId: '453cf42d72bb3c', - auctionId: '6c22f5a5-59df-4dc6-b92c-f433bcf0a874' -}]; - -const bidReqUserIds = [{ - bidder: BIDDER_CODE, - params: { - placementId: '10433394', - publisherId: 12345 - }, - sizes: [[300, 250], [300, 600]], - bidId: '263be71e91dd9d', - auctionId: '9ad1fa8d-2297-4660-a018-b39945054746', - userId: { - idl_env: '1111', - tdid: '123456', - digitrustid: {data: {id: 'DTID', keyv: 4, privacy: {optout: false}, producer: 'ABC', version: 2}}, - id5id: { uid: '1111' } - } -}, -{ - bidder: BIDDER_CODE, - params: { - publisherId: 12345 - }, - sizes: [[1, 1]], - bidId: '453cf42d72bb3c', - auctionId: '6c22f5a5-59df-4dc6-b92c-f433bcf0a874' -}]; - -const bidderReq = { - refererInfo: { - topmostLocation: 'http://prebid.org/dev-docs/bidder-adaptor.html' - } -}; - -const bidderReqGdpr = { - refererInfo: { - topmostLocation: 'http://prebid.org/dev-docs/bidder-adaptor.html' - }, - gdprConsent: { - gdprApplies: true, - consentString: 'acdefgh' - } -}; - -const bidderReqCcpa = { - refererInfo: { - topmostLocation: 'http://prebid.org/dev-docs/bidder-adaptor.html' - }, - uspConsent: 'NY12' -}; - -const bidderReqCcpaAndGdpr = { - refererInfo: { - topmostLocation: 'http://prebid.org/dev-docs/bidder-adaptor.html' - }, - gdprConsent: { - gdprApplies: true, - consentString: 'acdefgh' - }, - uspConsent: 'NY12' -}; - -const bidderReqGpp = { - refererInfo: { - topmostLocation: 'http://prebid.org/dev-docs/bidder-adaptor.html' - }, - gppConsent: { - gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', - applicableSections: [7] - } -}; - -const bidderReqFullGppCcpaGdpr = { - refererInfo: { - topmostLocation: 'http://prebid.org/dev-docs/bidder-adaptor.html' - }, - gppConsent: { - gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', - applicableSections: [7] - }, - gdprConsent: { - gdprApplies: true, - consentString: 'gdprConsent' - }, - uspConsent: '1YNN' -}; - -const validBidRes = { - ad: '
Hello
', - publisherId: 12345, - bidRequestId: '263be71e91dd9d', - adId: 15, - cpm: 100, - nCampaignId: 2, - creativeId: '123abc', - currency: 'USD', - netRevenue: true, - width: 300, - height: 250, - ttl: 360 -}; - -const bidResponse = [validBidRes]; - -const bidResArray = [ - validBidRes, - { - ad: '', - bidRequestId: '263be71e91dd9d', - cpm: 100, - adId: '123abc', - currency: 'USD', - netRevenue: true, - width: 300, - height: 250, - ttl: 360 - }, - { - ad: '
Hello
', - bidRequestId: '', - cpm: 0, - adId: '123abc', - currency: 'USD', - netRevenue: true, - width: 300, - height: 250, - ttl: 360 - } -]; -const bidVideoResponse = [ - { - ad: '', - bidRequestId: '263be71e91dd9d', - cpm: 100, - adId: '123abc', - currency: 'USD', - mediaType: 'video', - netRevenue: true, - width: 300, - height: 250, - ttl: 360 - } -]; - -let element; -let sandbox; - -const elementParent = { - offsetLeft: 100, - offsetTop: 100, - offsetHeight: 100, - getAttribute: function() {} -}; - -describe('Undertone Adapter', () => { - describe('request', () => { - it('should validate bid request', () => { - expect(spec.isBidRequestValid(validBidReq)).to.equal(true); - }); - it('should not validate incorrect bid request', () => { - expect(spec.isBidRequestValid(invalidBidReq)).to.equal(undefined); - }); - }); - describe('build request', function () { - beforeEach(function() { - element = { - id: 'div-gpt-ad-1460505748561-0', - offsetLeft: 100, - offsetTop: 100, - offsetWidth: 300, - offsetHeight: 250, - getBoundingClientRect() { return { left: 100, top: 100, width: 300, height: 250 }; } - }; - - sandbox = sinon.createSandbox(); - sandbox.stub(document, 'getElementById').withArgs('div-gpt-ad-1460505748561-0').returns(element); - }); - - afterEach(function() { - sandbox.restore(); - }); - - describe('getFloor', function () { - it('should send 0 floor when getFloor is undefined', function() { - const request = spec.buildRequests(videoBidReq, bidderReq); - const bidReq = JSON.parse(request.data)['x-ut-hb-params'][0]; - expect(bidReq.mediaType).to.deep.equal(VIDEO); - expect(bidReq.bidfloor).to.deep.equal(0); - }); - it('should send mocked floor when defined on video media-type', function() { - const clonedVideoBidReqArr = deepClone(videoBidReq); - const mockedFloorResponse = { - currency: 'USD', - floor: 2.3 - }; - clonedVideoBidReqArr[1].getFloor = () => mockedFloorResponse; - - const request = spec.buildRequests(clonedVideoBidReqArr, bidderReq); - const bidReq1 = JSON.parse(request.data)['x-ut-hb-params'][0]; - const bidReq2 = JSON.parse(request.data)['x-ut-hb-params'][1]; - expect(bidReq1.mediaType).to.deep.equal(VIDEO); - expect(bidReq1.bidfloor).to.deep.equal(0); - - expect(bidReq2.mediaType).to.deep.equal(VIDEO); - expect(bidReq2.bidfloor).to.deep.equal(mockedFloorResponse.floor); - }); - it('should send mocked floor on banner media-type', function() { - const clonedValidBidReqArr = [deepClone(validBidReq)]; - const mockedFloorResponse = { - currency: 'USD', - floor: 2.3 - }; - clonedValidBidReqArr[0].getFloor = () => mockedFloorResponse; - - const request = spec.buildRequests(clonedValidBidReqArr, bidderReq); - const bidReq = JSON.parse(request.data)['x-ut-hb-params'][0]; - expect(bidReq.mediaType).to.deep.equal(BANNER); - expect(bidReq.bidfloor).to.deep.equal(mockedFloorResponse.floor); - }); - it('should send 0 floor on invalid currency', function() { - const clonedValidBidReqArr = [deepClone(validBidReq)]; - const mockedFloorResponse = { - currency: 'EUR', - floor: 2.3 - }; - clonedValidBidReqArr[0].getFloor = () => mockedFloorResponse; - - const request = spec.buildRequests(clonedValidBidReqArr, bidderReq); - const bidReq = JSON.parse(request.data)['x-ut-hb-params'][0]; - expect(bidReq.mediaType).to.deep.equal(BANNER); - expect(bidReq.bidfloor).to.deep.equal(0); - }); - }); - describe('supply chain', function () { - it('should send supply chain if found on first bid', function () { - const request = spec.buildRequests(supplyChainedBidReqs, bidderReq); - const commons = JSON.parse(request.data)['commons']; - expect(commons.schain).to.deep.equal(schainObj); - }); - it('should not send supply chain if not found on first bid', function () { - const request = spec.buildRequests(bidReq, bidderReq); - const commons = JSON.parse(request.data)['commons']; - expect(commons.schain).to.not.exist; - }); - }); - it('should send request to correct url via POST not in GDPR or CCPA', function () { - const request = spec.buildRequests(bidReq, bidderReq); - const domainStart = bidderReq.refererInfo.topmostLocation.indexOf('//'); - const domainEnd = bidderReq.refererInfo.topmostLocation.indexOf('/', domainStart + 2); - const domain = bidderReq.refererInfo.topmostLocation.substring(domainStart + 2, domainEnd); - const REQ_URL = `${URL}?pid=${bidReq[0].params.publisherId}&domain=${domain}`; - expect(request.url).to.equal(REQ_URL); - expect(request.method).to.equal('POST'); - }); - it('should send request to correct url via POST when in GDPR', function () { - const request = spec.buildRequests(bidReq, bidderReqGdpr); - const domainStart = bidderReq.refererInfo.topmostLocation.indexOf('//'); - const domainEnd = bidderReq.refererInfo.topmostLocation.indexOf('/', domainStart + 2); - const domain = bidderReq.refererInfo.topmostLocation.substring(domainStart + 2, domainEnd); - const gdpr = bidderReqGdpr.gdprConsent.gdprApplies ? 1 : 0; - const REQ_URL = `${URL}?pid=${bidReq[0].params.publisherId}&domain=${domain}&gdpr=${gdpr}&gdprstr=${bidderReqGdpr.gdprConsent.consentString}`; - expect(request.url).to.equal(REQ_URL); - expect(request.method).to.equal('POST'); - }); - it('should send request to correct url via POST when in CCPA', function () { - const request = spec.buildRequests(bidReq, bidderReqCcpa); - const domainStart = bidderReq.refererInfo.topmostLocation.indexOf('//'); - const domainEnd = bidderReq.refererInfo.topmostLocation.indexOf('/', domainStart + 2); - const domain = bidderReq.refererInfo.topmostLocation.substring(domainStart + 2, domainEnd); - const ccpa = bidderReqCcpa.uspConsent; - const REQ_URL = `${URL}?pid=${bidReq[0].params.publisherId}&domain=${domain}&ccpa=${ccpa}`; - expect(request.url).to.equal(REQ_URL); - expect(request.method).to.equal('POST'); - }); - it('should send request to correct url via POST when in GDPR and CCPA', function () { - const request = spec.buildRequests(bidReq, bidderReqCcpaAndGdpr); - const domainStart = bidderReq.refererInfo.topmostLocation.indexOf('//'); - const domainEnd = bidderReq.refererInfo.topmostLocation.indexOf('/', domainStart + 2); - const domain = bidderReq.refererInfo.topmostLocation.substring(domainStart + 2, domainEnd); - const ccpa = bidderReqCcpaAndGdpr.uspConsent; - const gdpr = bidderReqCcpaAndGdpr.gdprConsent.gdprApplies ? 1 : 0; - const REQ_URL = `${URL}?pid=${bidReq[0].params.publisherId}&domain=${domain}&gdpr=${gdpr}&gdprstr=${bidderReqGdpr.gdprConsent.consentString}&ccpa=${ccpa}`; - expect(request.url).to.equal(REQ_URL); - expect(request.method).to.equal('POST'); - }); - it(`should have gppConsent fields`, function () { - const request = spec.buildRequests(bidReq, bidderReqGpp); - const domainStart = bidderReq.refererInfo.topmostLocation.indexOf('//'); - const domainEnd = bidderReq.refererInfo.topmostLocation.indexOf('/', domainStart + 2); - const domain = bidderReq.refererInfo.topmostLocation.substring(domainStart + 2, domainEnd); - const gppStr = bidderReqGpp.gppConsent.gppString; - const gppSid = bidderReqGpp.gppConsent.applicableSections; - const REQ_URL = `${URL}?pid=${bidReq[0].params.publisherId}&domain=${domain}&gpp=${gppStr}&gpp_sid=${gppSid}`; - expect(request.url).to.equal(REQ_URL); - expect(request.method).to.equal('POST'); - }); - it(`should have gpp, ccpa and gdpr fields`, function () { - const request = spec.buildRequests(bidReq, bidderReqFullGppCcpaGdpr); - const domainStart = bidderReq.refererInfo.topmostLocation.indexOf('//'); - const domainEnd = bidderReq.refererInfo.topmostLocation.indexOf('/', domainStart + 2); - const domain = bidderReq.refererInfo.topmostLocation.substring(domainStart + 2, domainEnd); - const gppStr = bidderReqFullGppCcpaGdpr.gppConsent.gppString; - const gppSid = bidderReqFullGppCcpaGdpr.gppConsent.applicableSections; - const ccpa = bidderReqFullGppCcpaGdpr.uspConsent; - const gdpr = bidderReqFullGppCcpaGdpr.gdprConsent.gdprApplies ? 1 : 0; - const gdprStr = bidderReqFullGppCcpaGdpr.gdprConsent.consentString; - const REQ_URL = `${URL}?pid=${bidReq[0].params.publisherId}&domain=${domain}&gdpr=${gdpr}&gdprstr=${gdprStr}&ccpa=${ccpa}&gpp=${gppStr}&gpp_sid=${gppSid}`; - expect(request.url).to.equal(REQ_URL); - expect(request.method).to.equal('POST'); - }); - it('should have all relevant fields', function () { - const request = spec.buildRequests(bidReq, bidderReq); - const bid1 = JSON.parse(request.data)['x-ut-hb-params'][0]; - expect(bid1.bidRequestId).to.equal('263be71e91dd9d'); - expect(bid1.sizes.length).to.equal(2); - expect(bid1.placementId).to.equal('10433394'); - expect(bid1.publisherId).to.equal(12345); - expect(bid1.coordinates).to.be.an('array'); - expect(bid1.params).to.be.an('object'); - const bid2 = JSON.parse(request.data)['x-ut-hb-params'][1]; - expect(bid2.bidRequestId).to.equal('453cf42d72bb3c'); - expect(bid2.sizes.length).to.equal(1); - expect(bid2.placementId === null).to.equal(true); - expect(bid2.publisherId).to.equal(12345); - expect(bid2.params).to.be.an('object'); - }); - it('should send video fields correctly', function () { - const request = spec.buildRequests(videoBidReq, bidderReq); - const bidVideo = JSON.parse(request.data)['x-ut-hb-params'][0]; - const bidVideo2 = JSON.parse(request.data)['x-ut-hb-params'][1]; - - expect(bidVideo.mediaType).to.equal('video'); - expect(bidVideo.video).to.be.an('object'); - expect(bidVideo.video.playerSize).to.be.an('array'); - expect(bidVideo.video.streamType).to.equal('outstream'); - expect(bidVideo.video.playbackMethod).to.equal(2); - expect(bidVideo.video.maxDuration).to.equal(30); - expect(bidVideo.video.skippable).to.equal(true); - expect(bidVideo.video.placement).to.equal(1); - expect(bidVideo.video.plcmt).to.equal(1); - expect(bidVideo.gpid).to.equal('/1111/gpid#728x90'); - - expect(bidVideo2.video.skippable).to.equal(null); - expect(bidVideo2.video.maxDuration).to.equal(null); - expect(bidVideo2.video.playbackMethod).to.equal(null); - expect(bidVideo2.video.placement).to.equal(null); - expect(bidVideo2.video.plcmt).to.equal(null); - expect(bidVideo2.gpid).to.equal('/1111/pbadslot#728x90'); - }); - it('should send all userIds data to server', function () { - const request = spec.buildRequests(bidReqUserIds, bidderReq); - const bidCommons = JSON.parse(request.data)['commons']; - expect(bidCommons).to.be.an('object'); - expect(bidCommons.uids).to.be.an('object'); - expect(bidCommons.uids.tdid).to.equal('123456'); - expect(bidCommons.uids.idl_env).to.equal('1111'); - expect(bidCommons.uids.digitrustid.data.id).to.equal('DTID'); - expect(bidCommons.uids.id5id.uid).to.equal('1111'); - }); - it('should send page sizes sizes correctly', function () { - const request = spec.buildRequests(bidReqUserIds, bidderReq); - const bidCommons = JSON.parse(request.data)['commons']; - expect(bidCommons).to.be.an('object'); - expect(bidCommons.pageSize).to.be.an('array'); - expect(bidCommons.pageSize[0]).to.equal(getWinDimensions().innerWidth); - expect(bidCommons.pageSize[1]).to.equal(getWinDimensions().innerHeight); - }); - it('should send banner coordinates', function() { - const request = spec.buildRequests(bidReq, bidderReq); - const bid1 = JSON.parse(request.data)['x-ut-hb-params'][0]; - expect(bid1.coordinates).to.be.an('array'); - expect(bid1.coordinates[0]).to.equal(100); - expect(bid1.coordinates[1]).to.equal(100); - }); - it('should send banner coordinates plus parent', function() { - element.offsetParent = elementParent; - const request = spec.buildRequests(bidReq, bidderReq); - const bid1 = JSON.parse(request.data)['x-ut-hb-params'][0]; - expect(bid1.coordinates).to.be.an('array'); - expect(bid1.coordinates[0]).to.equal(100); - expect(bid1.coordinates[1]).to.equal(100); - }); - }); - - describe('interpretResponse', () => { - it('should build bid array', () => { - const result = spec.interpretResponse({body: bidResponse}); - expect(result.length).to.equal(1); - }); - - it('should have all relevant fields', () => { - const result = spec.interpretResponse({body: bidResponse}); - const bid = result[0]; - - expect(bid.requestId).to.equal('263be71e91dd9d'); - expect(bid.cpm).to.equal(100); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.meta.advertiserDomains).to.deep.equal([]); - expect(bid.creativeId).to.equal(15); - expect(bid.currency).to.equal('USD'); - expect(bid.netRevenue).to.equal(true); - expect(bid.ttl).to.equal(360); - }); - - it('should return empty array when response is incorrect', () => { - expect(spec.interpretResponse({body: {}}).length).to.equal(0); - expect(spec.interpretResponse({body: []}).length).to.equal(0); - }); - - it('should only use valid bid responses', () => { - expect(spec.interpretResponse({ body: bidResArray }).length).to.equal(1); - }); - - it('should detect video response', () => { - const videoResult = spec.interpretResponse({body: bidVideoResponse}); - const vbid = videoResult[0]; - - expect(vbid.mediaType).to.equal('video'); - }); - }); - - describe('getUserSyncs', () => { - const testParams = [ - { - name: 'with iframe and no gdpr or ccpa data', - arguments: [{ iframeEnabled: true, pixelEnabled: true }, {}, null], - expect: { - type: 'iframe', - pixels: ['https://cdn.undertone.com/js/usersync.html'] - } - }, - { - name: 'with iframe and gdpr on', - arguments: [{ iframeEnabled: true, pixelEnabled: true }, {}, {gdprApplies: true, consentString: '234234'}], - expect: { - type: 'iframe', - pixels: ['https://cdn.undertone.com/js/usersync.html?gdpr=1&gdprstr=234234'] - } - }, - { - name: 'with iframe and ccpa on', - arguments: [{ iframeEnabled: true, pixelEnabled: true }, {}, null, 'YN12'], - expect: { - type: 'iframe', - pixels: ['https://cdn.undertone.com/js/usersync.html?ccpa=YN12'] - } - }, - { - name: 'with iframe and no gdpr off or ccpa', - arguments: [{ iframeEnabled: true, pixelEnabled: true }, {}, {gdprApplies: false}], - expect: { - type: 'iframe', - pixels: ['https://cdn.undertone.com/js/usersync.html?gdpr=0&gdprstr='] - } - }, - { - name: 'with iframe and gdpr and ccpa', - arguments: [{ iframeEnabled: true, pixelEnabled: true }, {}, {gdprApplies: true, consentString: '234234'}, 'YN12'], - expect: { - type: 'iframe', - pixels: ['https://cdn.undertone.com/js/usersync.html?gdpr=1&gdprstr=234234&ccpa=YN12'] - } - }, - { - name: 'with pixels and no gdpr or ccpa data', - arguments: [{ pixelEnabled: true }, {}, null], - expect: { - type: 'image', - pixels: ['https://usr.undertone.com/userPixel/syncOne?id=1&of=2', - 'https://usr.undertone.com/userPixel/syncOne?id=2&of=2'] - } - }, - { - name: 'with pixels and gdpr on', - arguments: [{ pixelEnabled: true }, {}, {gdprApplies: true, consentString: '234234'}], - expect: { - type: 'image', - pixels: ['https://usr.undertone.com/userPixel/syncOne?id=1&of=2&gdpr=1&gdprstr=234234', - 'https://usr.undertone.com/userPixel/syncOne?id=2&of=2&gdpr=1&gdprstr=234234'] - } - }, - { - name: 'with pixels and ccpa on', - arguments: [{ pixelEnabled: true }, {}, null, 'YN12'], - expect: { - type: 'image', - pixels: ['https://usr.undertone.com/userPixel/syncOne?id=1&of=2&ccpa=YN12', - 'https://usr.undertone.com/userPixel/syncOne?id=2&of=2&ccpa=YN12'] - } - }, - { - name: 'with pixels and gdpr off', - arguments: [{ pixelEnabled: true }, {}, {gdprApplies: false}], - expect: { - type: 'image', - pixels: ['https://usr.undertone.com/userPixel/syncOne?id=1&of=2&gdpr=0&gdprstr=', - 'https://usr.undertone.com/userPixel/syncOne?id=2&of=2&gdpr=0&gdprstr='] - } - }, - { - name: 'with pixels and gdpr and ccpa on', - arguments: [{ pixelEnabled: true }, {}, {gdprApplies: true, consentString: '234234'}, 'YN12'], - expect: { - type: 'image', - pixels: ['https://usr.undertone.com/userPixel/syncOne?id=1&of=2&gdpr=1&gdprstr=234234&ccpa=YN12', - 'https://usr.undertone.com/userPixel/syncOne?id=2&of=2&gdpr=1&gdprstr=234234&ccpa=YN12'] - } - } - ]; - - for (let i = 0; i < testParams.length; i++) { - const currParams = testParams[i]; - it(currParams.name, function () { - const result = spec.getUserSyncs.apply(this, currParams.arguments); - expect(result).to.have.lengthOf(currParams.expect.pixels.length); - for (let ix = 0; ix < currParams.expect.pixels.length; ix++) { - expect(result[ix].url).to.equal(currParams.expect.pixels[ix]); - expect(result[ix].type).to.equal(currParams.expect.type); - } - }); - } - }); -}); diff --git a/test/spec/modules/unicornBidAdapter_spec.js b/test/spec/modules/unicornBidAdapter_spec.js deleted file mode 100644 index 7e6d41fc8..000000000 --- a/test/spec/modules/unicornBidAdapter_spec.js +++ /dev/null @@ -1,570 +0,0 @@ -import {assert, expect} from 'chai'; -import * as utils from 'src/utils.js'; -import {spec} from 'modules/unicornBidAdapter.js'; -import * as _ from 'lodash'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -const bidRequests = [ - { - bidder: 'unicorn', - params: { - accountId: 12345 - }, - mediaTypes: { - banner: { - sizes: [ - [ - 300, 250 - ], - [ - 336, 280 - ] - ] - } - }, - adUnitCode: '/19968336/header-bid-tag-0', - transactionId: 'ea0aa332-a6e1-4474-8180-83720e6b87bc', - sizes: [ - [ - 300, 250 - ], - [ - 336, 280 - ] - ], - bidId: '226416e6e6bf41', - bidderRequestId: '1f41cbdcbe58d5', - auctionId: '77987c3a-9be9-4e43-985a-26fc91d84724', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }, { - bidder: 'unicorn', - params: { - accountId: 12345 - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - transactionId: 'cf801303-cf98-4b4a-9e0a-c27b93bce6d8', - sizes: [ - [300, 250] - ], - bidId: '37cdc0b5d0363b', - bidderRequestId: '1f41cbdcbe58d5', - auctionId: '77987c3a-9be9-4e43-985a-26fc91d84724', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }, { - bidder: 'unicorn', - params: { - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - adUnitCode: '/19968336/header-bid-tag-2', - transactionId: 'ba7f114c-3676-4a08-a26d-1ee293d521ed', - sizes: [ - [300, 250] - ], - bidId: '468569a6597a4', - bidderRequestId: '1f41cbdcbe58d5', - auctionId: '77987c3a-9be9-4e43-985a-26fc91d84724', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - } -]; - -const validBidRequests = [ - { - bidder: 'unicorn', - params: { - placementId: 'rectangle-ad-1', - accountId: 12345, - publisherId: 99999, - mediaId: 'example' - }, - mediaTypes: { - banner: { - sizes: [ - [ - 300, 250 - ], - [ - 336, 280 - ] - ] - } - }, - adUnitCode: '/19968336/header-bid-tag-0', - transactionId: 'fbf94ccf-f377-4201-a662-32c2feb8ab6d', - sizes: [ - [ - 300, 250 - ], - [ - 336, 280 - ] - ], - bidId: '2fb90842443e24', - bidderRequestId: '123ae4cc3eeb7e', - auctionId: 'c594a888-6744-46c6-8b0e-d188e40e83ef', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }, { - bidder: 'unicorn', - params: { - accountId: 12345 - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - adUnitCode: '/19968336/header-bid-tag-1', - transactionId: '2d65e313-f8a6-4888-b9ab-50fb3ca744ea', - sizes: [ - [300, 250] - ], - bidId: '352f86f158d97a', - bidderRequestId: '123ae4cc3eeb7e', - auctionId: 'c594a888-6744-46c6-8b0e-d188e40e83ef', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }, { - bidder: 'unicorn', - params: { - placementId: 'rectangle-ad-2', - accountId: 12345 - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - adUnitCode: '/19968336/header-bid-tag-2', - transactionId: '82f445a8-44bc-40bc-9913-739b40375566', - sizes: [ - [300, 250] - ], - bidId: '4cde82cc90126b', - bidderRequestId: '123ae4cc3eeb7e', - auctionId: 'c594a888-6744-46c6-8b0e-d188e40e83ef', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - } -]; - -const bidderRequest = { - bidderCode: 'unicorn', - auctionId: 'c594a888-6744-46c6-8b0e-d188e40e83ef', - bidderRequestId: '123ae4cc3eeb7e', - bids: [ - { - bidder: 'unicorn', - params: { - placementId: 'rectangle-ad-1', - accountId: 12345 - }, - mediaTypes: { - banner: { - sizes: [ - [ - 300, 250 - ], - [ - 336, 280 - ] - ] - } - }, - adUnitCode: '/19968336/header-bid-tag-0', - transactionId: 'fbf94ccf-f377-4201-a662-32c2feb8ab6d', - sizes: [ - [ - 300, 250 - ], - [ - 336, 280 - ] - ], - bidId: '2fb90842443e24', - bidderRequestId: '123ae4cc3eeb7e', - auctionId: 'c594a888-6744-46c6-8b0e-d188e40e83ef', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }, { - bidder: 'unicorn', - params: { - accountId: 12345 - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - adUnitCode: '/19968336/header-bid-tag-1', - transactionId: '2d65e313-f8a6-4888-b9ab-50fb3ca744ea', - sizes: [ - [300, 250] - ], - bidId: '352f86f158d97a', - bidderRequestId: '123ae4cc3eeb7e', - auctionId: 'c594a888-6744-46c6-8b0e-d188e40e83ef', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - }, { - bidder: 'unicorn', - params: { - placementId: 'rectangle-ad-2', - accountId: 12345 - }, - mediaTypes: { - banner: { - sizes: [ - [300, 250] - ] - } - }, - adUnitCode: '/19968336/header-bid-tag-2', - transactionId: '82f445a8-44bc-40bc-9913-739b40375566', - sizes: [ - [300, 250] - ], - bidId: '4cde82cc90126b', - bidderRequestId: '123ae4cc3eeb7e', - auctionId: 'c594a888-6744-46c6-8b0e-d188e40e83ef', - src: 'client', - bidRequestsCount: 1, - bidderRequestsCount: 1, - bidderWinsCount: 0 - } - ], - auctionStart: 1581064124172, - timeout: 1000, - refererInfo: { - ref: 'https://uni-corn.net/', - reachedTop: true, - numIframes: 0, - stack: ['https://uni-corn.net/'] - }, - start: 1581064124177 -}; - -const openRTBRequest = { - id: '5ebea288-f13a-4754-be6d-4ade66c68877', - at: 1, - imp: [ - { - id: '216255f234b602', - banner: { - w: 300, - h: 250, - format: [ - { - w: 300, - h: 250 - }, { - w: 336, - h: 280 - } - ] - }, - secure: 1, - bidfloor: 0, - tagid: 'rectangle-ad-1' - }, { - id: '31e2b28ced2475', - banner: { - w: 300, - h: 250, - format: [ - { - w: 300, - h: 250 - } - ] - }, - secure: 1, - bidfloor: 0, - tagid: '/19968336/header-bid-tag-1' - }, { - id: '40a333e047a9bd', - banner: { - w: 300, - h: 250, - format: [ - { - w: 300, - h: 250 - } - ] - }, - secure: 1, - bidfloor: 0, - tagid: 'rectangle-ad-2' - } - ], - cur: ['JPY'], - ext: { - accountId: 12345 - }, - site: { - id: 'example', - publisher: { - id: '99999' - }, - domain: 'uni-corn.net', - page: 'https://uni-corn.net/', - ref: 'https://uni-corn.net/' - }, - device: { - language: 'ja', - ua: 'Mozilla/5.0 (Linux; Android 8.0.0; ONEPLUS A5000) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.93 Mobile Safari/537.36' - }, - user: { - id: '69d9e1c2-801e-4901-a665-fad467550fec' - }, - bcat: [], - source: { - ext: { - stype: 'prebid_uncn', - bidder: 'unicorn', - prebid_version: '1.1' - } - } -}; - -const serverResponse = { - body: { - bidid: '04db8629-179d-4bcd-acce-e54722969006', - cur: 'JPY', - ext: {}, - id: '5ebea288-f13a-4754-be6d-4ade66c68877', - seatbid: [ - { - bid: [ - { - adid: 'uqgbp4y0_OoqM1QOt', - adm: '
test
', - adomain: ['test1.co.jp'], - attr: [], - bundle: 'com.test1.android', - cat: ['IAB9'], - cid: '2196', - crid: 'ABCDE', - ext: { - imptrackers: ['https://uncn.jp/pb/2/view/test1'] - }, - h: 250, - id: '1', - impid: '216255f234b602', - iurl: 'https://assets.ucontent.net/test1.jpg', - price: 1.0017, - w: 300 - }, { - adid: 'uqgbp4y0_uqjrNT7h_25512', - adm: '
test
', - adomain: null, - attr: ['6'], - bundle: 'com.test1.android', - cat: ['IAB9'], - cid: '2196', - crid: 'abcde', - ext: { - imptrackers: ['https://uncn.jp/pb/2/view/test1'] - }, - h: 250, - id: '2', - impid: '31e2b28ced2475', - iurl: 'https://assets.ucontent.net/test1.jpg', - price: 0.9513, - w: 300 - } - ], - group: 0, - seat: '65' - }, { - bid: [ - { - adid: 'uoNYC6II_eoySuXNi', - adm: '
test
', - attr: [], - bundle: 'jp.co.test2', - cat: ['IAB9'], - cid: '7315', - crid: 'XYZXYZ', - ext: { - imptrackers: ['https://uncn.jp/pb/2/view/test2'] - }, - h: 250, - id: '3', - impid: '40a333e047a9bd', - iurl: 'https://assets.ucontent.net/test2.jpg', - price: 0.674, - w: 300 - } - ], - group: 0, - seat: '274' - } - ], - units: 0 - }, - headers: {} -}; - -const request = { - method: 'POST', - url: 'https://ds.uncn.jp/pb/0/bid.json', - data: '{"id":"5ebea288-f13a-4754-be6d-4ade66c68877","at":1,"imp":[{"id":"216255f234b602","banner":{"w":300,"h":250},"format":[{"w":300,"h":250},{"w":336,"h":280}],"secure":1,"bidfloor":0,"tagid":"/19968336/header-bid-tag-0"},{"id":"31e2b28ced2475","banner":{"w":"300","h":"250"},"format":[{"w":"300","h":"250"}],"secure":1,"bidfloor":0"tagid":"/19968336/header-bid-tag-1"},{"id":"40a333e047a9bd","banner":{"w":300,"h":250},"format":[{"w":300,"h":250}],"secure":1,"bidfloor":0,"tagid":"/19968336/header-bid-tag-2"}],"cur":"JPY","site":{"id":"uni-corn.net","publisher":{"id":12345},"domain":"uni-corn.net","page":"https://uni-corn.net/","ref":"https://uni-corn.net/"},"device":{"language":"ja","ua":"Mozilla/5.0 (Linux; Android 8.0.0; ONEPLUS A5000) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.93 Mobile Safari/537.36"},"user":{"id":"69d9e1c2-801e-4901-a665-fad467550fec"},"bcat":[],"source":{"ext":{"stype":"prebid_uncn","bidder":"unicorn","prebid_version":"1.1"}}}' -}; - -const interpretedBids = [ - { - requestId: '216255f234b602', - cpm: 1.0017, - width: 300, - height: 250, - meta: { - advertiserDomains: [ - 'test1.co.jp' - ] - }, - ad: '
test
', - ttl: 1000, - creativeId: 'ABCDE', - netRevenue: true, - currency: 'JPY' - }, { - requestId: '31e2b28ced2475', - cpm: 0.9513, - width: 300, - height: 250, - ad: '
test
', - ttl: 1000, - creativeId: 'abcde', - netRevenue: true, - currency: 'JPY' - }, { - requestId: '40a333e047a9bd', - cpm: 0.674, - width: 300, - height: 250, - ad: '
test
', - ttl: 1000, - creativeId: 'XYZXYZ', - netRevenue: true, - currency: 'JPY' - } -]; - -describe('unicornBidAdapterTest', () => { - describe('isBidRequestValid', () => { - it('isBidRequestValid', () => { - expect(spec.isBidRequestValid(bidRequests[0])).to.equal(true); - expect(spec.isBidRequestValid(bidRequests[1])).to.equal(false); - expect(spec.isBidRequestValid(bidRequests[2])).to.equal(false); - }); - }); - - describe('buildBidRequest', () => { - const removeUntestableAttrs = data => { - delete data['device']; - delete data['site']['domain']; - delete data['site']['page']; - delete data['id']; - data['imp'].forEach(imp => { - delete imp['id']; - }) - delete data['user']['id']; - return data; - }; - before(function () { - getGlobal().bidderSettings = { - unicorn: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - it('buildBidRequest', () => { - const req = spec.buildRequests(validBidRequests, bidderRequest); - const uid = JSON.parse(req.data)['user']['id']; - const reqData = removeUntestableAttrs(JSON.parse(req.data)); - const openRTBRequestData = removeUntestableAttrs(openRTBRequest); - assert.deepStrictEqual(reqData, openRTBRequestData); - const req2 = spec.buildRequests(validBidRequests, bidderRequest); - const uid2 = JSON.parse(req2.data)['user']['id']; - assert.deepStrictEqual(uid, uid2); - }); - it('test if contains ID5', () => { - const _validBidRequests = utils.deepClone(validBidRequests); - _validBidRequests[0].userId = { - id5id: { - uid: 'id5_XXXXX' - } - } - const req = spec.buildRequests(_validBidRequests, bidderRequest); - const reqData = removeUntestableAttrs(JSON.parse(req.data)); - const openRTBRequestData = removeUntestableAttrs(utils.deepClone(openRTBRequest)); - openRTBRequestData.user.eids = [ - { - source: 'id5-sync.com', - uids: [ - { - id: 'id5_XXXXX' - } - ] - } - ] - assert.deepStrictEqual(reqData, openRTBRequestData); - }) - }); - - describe('interpretResponse', () => { - it('interpretResponse', () => { - const bids = spec.interpretResponse(serverResponse, request); - assert.deepStrictEqual(bids, interpretedBids); - }); - it('interpretResponseEmptyString', () => { - const bids = spec.interpretResponse('', request); - assert.deepStrictEqual(bids, []); - }); - it('interpretResponseEmptyArray', () => { - const bids = spec.interpretResponse([], request); - assert.deepStrictEqual(bids, []); - }); - }); -}); diff --git a/test/spec/modules/uniquestAnalyticsAdapter_spec.js b/test/spec/modules/uniquestAnalyticsAdapter_spec.js deleted file mode 100644 index 80a573d2b..000000000 --- a/test/spec/modules/uniquestAnalyticsAdapter_spec.js +++ /dev/null @@ -1,461 +0,0 @@ -import uniquestAnalyticsAdapter from 'modules/uniquestAnalyticsAdapter.js'; -import {config} from 'src/config'; -import {EVENTS} from 'src/constants.js'; -import {server} from '../../mocks/xhr.js'; - -const events = require('src/events'); - -const SAMPLE_EVENTS = { - AUCTION_END: { - 'auctionId': 'uniq1234', - 'timestamp': 1733709113000, - 'auctionEnd': 1733709113500, - 'auctionStatus': 'completed', - 'metrics': { - 'someMetric': 1 - }, - 'adUnits': [ - { - 'code': '/12345678910/uniquest_1', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 1, - 1 - ], - [ - 300, - 300 - ], - [ - 300, - 250 - ] - ] - } - }, - 'bids': [ - { - 'bidder': 'uniquest', - 'params': { - 'sid': '3pwnAHWX' - } - }, - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 12345678 - } - } - ], - 'sizes': [ - [ - 1, - 1 - ], - [ - 300, - 300 - ], - [ - 300, - 250 - ] - ], - 'transactionId': '12345678' - } - ], - 'adUnitCodes': [ - '/12345678910/uniquest_1' - ], - 'bidderRequests': [ - { - 'auctionId': '75e394d9', - 'auctionStart': 1733709113010, - 'bidderCode': 'uniquest', - 'bidderRequestId': '1207cb49191887', - 'bids': [ - { - 'adUnitCode': '/12345678910/uniquest_1', - 'auctionId': '75e394d9', - 'bidId': '206be9a13236af', - 'bidderRequestId': '1207cb49191887', - 'bidder': 'uniquest', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 1, - 1 - ], - [ - 300, - 300 - ], - [ - 300, - 250 - ] - ] - } - }, - - 'transactionId': '6b29369c', - 'sizes': [ - [ - 1, - 1 - ], - [ - 300, - 300 - ], - [ - 300, - 250 - ] - ], - 'src': 'client', - } - ], - 'timeout': 400, - 'refererInfo': { - 'page': 'http://test-pb.ust-ad.com/banner.html', - 'domain': 'test-pb.ust-ad.com', - 'referer': 'http://test-pb.ust-ad.com/banner.html', - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': [ - 'http://test-pb.ust-ad.com/banner.html' - ], - 'canonicalUrl': null - }, - 'start': 1733709113020 - }, - { - 'bidderCode': 'appnexus', - 'auctionId': '75e394d9', - 'bidderRequestId': '32b97f0a935422', - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 12345678 - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 1, - 1 - ], - [ - 300, - 300 - ], - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': '/12345678910/uniquest_1', - 'transactionId': '6b29369c', - 'sizes': [ - [ - 1, - 1 - ], - [ - 300, - 300 - ], - [ - 300, - 250 - ] - ], - 'bidId': '41badc0e164c758', - 'bidderRequestId': '32b97f0a935422', - 'auctionId': '75e394d9', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'device': { - 'mobile': 1 - } - } - } - ], - 'auctionStart': 1733709113010, - 'timeout': 400, - 'refererInfo': { - 'page': 'http://test-pb.ust-ad.com/banner.html', - 'domain': 'test-memo.wakaue.info', - 'referer': 'http://test-pb.ust-ad.com/banner.html', - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': [ - 'http://test-pb.ust-ad.com/banner.html' - ], - 'canonicalUrl': null - }, - 'start': 1733709113020 - } - ], - 'noBids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 12345678 - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 1, - 1 - ], - [ - 300, - 300 - ], - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': '/12345678910/uniquest_1', - 'transactionId': '6b29369c', - 'sizes': [ - [ - 1, - 1 - ], - [ - 300, - 300 - ], - [ - 300, - 250 - ] - ], - 'bidId': '41badc0e164c758', - 'bidderRequestId': '32b97f0a935422', - 'auctionId': '75e394d9', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'bidsReceived': [ - { - 'bidderCode': 'uniquest', - 'width': 300, - 'height': 300, - 'statusMessage': 'Bid available', - 'adId': '53c5a9c1947c57', - 'requestId': '4d9eec3fe27a43', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 2.73, - 'currency': 'JPY', - 'ad': ' ', - 'ttl': 300, - 'creativeId': '7806bcbb-a156-4ec4-872b-bd0d8e8bff34', - 'netRevenue': true, - 'meta': { - 'advertiserDomains': [ - 'test-pb.ust-ad.com' - ] - }, - 'originalCpm': 2.73, - 'originalCurrency': 'JPY', - 'auctionId': '75e394d9', - 'responseTimestamp': 1733709113100, - 'requestTimestamp': 1733709113000, - 'bidder': 'uniquest', - 'adUnitCode': '/12345678910/uniquest_1', - 'timeToRespond': 100, - 'pbLg': '2.50', - 'pbMg': '2.70', - 'pbHg': '2.73', - 'pbAg': '2.70', - 'pbDg': '2.73', - 'pbCg': '', - 'size': '300x250', - 'adserverTargeting': { - 'hb_bidder': 'uniquest', - 'hb_adid': '53c5a9c1947c57', - 'hb_pb': '2.70', - 'hb_size': '300x300', - 'hb_source': 'client', - 'hb_format': 'banner', - 'hb_adomain': 'test-pb.ust-ad.com' - } - } - ], - 'winningBids': [], - 'timeout': 400 - }, - AD_RENDER_SUCCEEDED: { - 'doc': { - 'location': { - 'href': 'http://test-pb.ust-ad.com/banner.html', - 'protocol': 'http:', - 'host': 'test-pb.ust-ad.com', - 'hostname': 'localhost', - 'port': '80', - 'pathname': '/page_banner.html', - 'hash': '', - 'origin': 'http://test-pb.ust-ad.com', - 'ancestorOrigins': { - '0': 'http://test-pb.ust-ad.com' - } - } - }, - 'bid': { - 'bidderCode': 'uniquest', - 'width': 300, - 'height': 300, - 'statusMessage': 'Bid available', - 'adId': '53c5a9c1947c57', - 'requestId': '4d9eec3fe27a43', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': '2.73', - 'currency': 'JPY', - 'ad': 'test_ad', - 'metrics': { - 'someMetric': 0 - }, - 'ttl': 300, - 'creativeId': '7806bcbb-a156-4ec4-872b-bd0d8e8bff34', - 'netRevenue': true, - 'meta': { - 'advertiserDomains': [ - 'test-pb.ust-ad.com' - ] - }, - 'originalCpm': 2.73, - 'originalCurrency': 'JPY', - 'auctionId': '75e394d9', - 'responseTimestamp': 1733709113100, - 'requestTimestamp': 1733709113000, - 'bidder': 'uniquest', - 'adUnitCode': '12345678910/uniquest_1', - 'timeToRespond': 100, - 'size': '300x300', - 'adserverTargeting': { - 'hb_bidder': 'uniquest', - 'hb_adid': '53c5a9c1947c57', - 'hb_pb': '2.70', - 'hb_size': '300x300', - 'hb_source': 'client', - 'hb_format': 'banner', - 'hb_adomain': 'test-pb.ust-ad.com' - }, - 'status': 'rendered', - 'params': [ - { - 'nonZetaParam': 'nonZetaValue' - } - ] - } - } -} - -describe('Uniquest Analytics Adapter', function () { - let sandbox; - let requests; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - requests = server.requests; - sandbox.stub(events, 'getEvents').returns([]); - }); - - afterEach(function () { - sandbox.restore(); - config.resetConfig(); - }); - - describe('handle events', function () { - beforeEach(function () { - uniquestAnalyticsAdapter.enableAnalytics({ - options: { - sid: 'ABCDE123', - } - }); - }); - - afterEach(function () { - uniquestAnalyticsAdapter.disableAnalytics(); - }); - - it('Handle events', function () { - this.timeout(1000); - - events.emit(EVENTS.AUCTION_END, SAMPLE_EVENTS.AUCTION_END); - events.emit(EVENTS.AD_RENDER_SUCCEEDED, SAMPLE_EVENTS.AD_RENDER_SUCCEEDED); - - // bids count - expect(requests.length).to.equal(2); - const auctionEnd = JSON.parse(requests[0].requestBody); - // event_type - expect(auctionEnd.event_type).to.eql(EVENTS.AUCTION_END); - // URL - expect(auctionEnd.url).to.eql(window.top.location.href); - // bid - expect(auctionEnd.bids).to.be.deep.equal([{ - auction_id: '75e394d9', - creative_id: '7806bcbb-a156-4ec4-872b-bd0d8e8bff34', - bidder: 'uniquest', - media_type: 'banner', - size: '300x250', - cpm: '2.73', - currency: 'JPY', - original_cpm: '2.73', - original_currency: 'JPY', - hb_pb: '2.70', - bidding_time: 100, - ad_unit_code: '/12345678910/uniquest_1', - }] - ); - - const auctionSucceeded = JSON.parse(requests[1].requestBody); - // event_type - expect(auctionSucceeded.event_type).to.eql(EVENTS.AD_RENDER_SUCCEEDED); - // URL - expect(auctionSucceeded.url).to.eql(window.top.location.href); - // bid - expect(auctionSucceeded.bid).to.be.deep.equal({ - auction_id: '75e394d9', - creative_id: '7806bcbb-a156-4ec4-872b-bd0d8e8bff34', - bidder: 'uniquest', - media_type: 'banner', - size: '300x300', - cpm: '2.73', - currency: 'JPY', - original_cpm: '2.73', - original_currency: 'JPY', - hb_pb: '2.70', - bidding_time: 100, - ad_unit_code: '12345678910/uniquest_1' - }); - }); - }); -}); diff --git a/test/spec/modules/uniquestBidAdapter_spec.js b/test/spec/modules/uniquestBidAdapter_spec.js deleted file mode 100644 index 57051d33a..000000000 --- a/test/spec/modules/uniquestBidAdapter_spec.js +++ /dev/null @@ -1,104 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/uniquestBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; - -const ENDPOINT = 'https://adpb.ust-ad.com/hb/prebid'; - -describe('UniquestAdapter', function () { - const adapter = newBidder(spec); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - const request = { - bidder: 'uniquest', - params: { - sid: 'sid_0001', - }, - }; - expect(spec.isBidRequestValid(request)).to.equal(true) - }) - - it('should return false when required params are not passed', function () { - expect(spec.isBidRequestValid({})).to.equal(false) - expect(spec.isBidRequestValid({ sid: '' })).to.equal(false) - }) - }) - - describe('buildRequest', function () { - const bids = [ - { - bidder: 'uniquest', - params: { - sid: 'sid_0001', - }, - adUnitCode: 'adunit-code', - sizes: [ - [300, 300], - [300, 250], - [320, 100], - ], - bidId: '259d7a594535852', - bidderRequestId: '247f62f777e5e4', - } - ]; - const bidderRequest = { - timeout: 1500, - } - it('sends bid request to ENDPOINT via GET', function () { - const requests = spec.buildRequests(bids, bidderRequest); - expect(requests[0].url).to.equal(ENDPOINT); - expect(requests[0].method).to.equal('GET'); - expect(requests[0].data).to.equal('bid=259d7a594535852&sid=sid_0001&widths=300%2C300%2C320&heights=300%2C250%2C100&timeout=1500&') - }) - }) - - describe('interpretResponse', function() { - it('should return a valid bid response', function () { - const serverResponse = { - request_id: '247f62f777e5e4', - cpm: 12.3, - currency: 'JPY', - width: 300, - height: 250, - bid_id: 'bid_0001', - deal_id: '', - net_revenue: false, - ttl: 300, - ad: '
', - media_type: 'banner', - meta: { - advertiser_domains: ['advertiser.com'], - }, - }; - const expectResponse = [{ - requestId: '247f62f777e5e4', - cpm: 12.3, - currency: 'JPY', - width: 300, - height: 250, - ad: '
', - creativeId: 'bid_0001', - netRevenue: false, - mediaType: 'banner', - ttl: 300, - meta: { - advertiserDomains: ['advertiser.com'], - } - }]; - const result = spec.interpretResponse({ body: serverResponse }, {}); - expect(result).to.have.lengthOf(1); - expect(result).to.deep.have.same.members(expectResponse); - }) - - it('should return an empty array to indicate no valid bids', function () { - const result = spec.interpretResponse({ body: {} }, {}) - expect(result).is.an('array').is.empty; - }) - }) -}) diff --git a/test/spec/modules/unrulyBidAdapter_spec.js b/test/spec/modules/unrulyBidAdapter_spec.js deleted file mode 100644 index d73b9b6e8..000000000 --- a/test/spec/modules/unrulyBidAdapter_spec.js +++ /dev/null @@ -1,1328 +0,0 @@ -/* globals describe, it, beforeEach, afterEach, sinon */ -import {expect} from 'chai' -import * as utils from 'src/utils.js' -import {VIDEO, BANNER} from 'src/mediaTypes.js' -import {Renderer} from 'src/Renderer.js' -import {adapter} from 'modules/unrulyBidAdapter.js' - -describe('UnrulyAdapter', function () { - function createOutStreamExchangeBid({ - adUnitCode = 'placement2', - statusCode = 1, - requestId = 'foo', - vastUrl = 'https://targeting.unrulymedia.com/in_article?uuid=74544e00-d43b-4f3a-a799-69d22ce979ce&supported_mime_type=application/javascript&supported_mime_type=video/mp4&tj=%7B%22site%22%3A%7B%22lang%22%3A%22en-GB%22%2C%22ref%22%3A%22%22%2C%22page%22%3A%22https%3A%2F%2Fdemo.unrulymedia.com%2FinArticle%2Finarticle_nypost_upbeat%2Ftravel_magazines.html%22%2C%22domain%22%3A%22demo.unrulymedia.com%22%7D%2C%22user%22%3A%7B%22profile%22%3A%7B%22quantcast%22%3A%7B%22segments%22%3A%5B%7B%22id%22%3A%22D%22%7D%2C%7B%22id%22%3A%22T%22%7D%5D%7D%7D%7D%7D&video_width=618&video_height=347' - }) { - return { - 'ext': { - 'statusCode': statusCode, - 'renderer': { - 'id': 'unruly_inarticle', - 'config': { - 'siteId': 123456, - 'targetingUUID': 'xxx-yyy-zzz' - }, - 'url': 'https://video.unrulymedia.com/native/prebid-loader.js' - }, - 'adUnitCode': adUnitCode - }, - 'cpm': 20, - 'bidderCode': 'unruly', - 'width': 323, - 'vastUrl': vastUrl, - 'requestId': requestId, - 'creativeId': requestId, - 'height': 323, - 'netRevenue': true, - 'ttl': 360, - 'currency': 'USD', - 'meta': { - 'mediaType': 'video', - 'videoContext': 'outstream' - } - } - } - - function createOutStreamExchangeAuctionConfig() { - return { - 'seller': 'https://nexxen.tech', - 'decisionLogicURL': 'https://nexxen.tech/padecisionlogic', - 'interestGroupBuyers': 'https://mydsp.com', - 'perBuyerSignals': { - 'https://mydsp.com': { - 'floor': 'bouttreefiddy' - } - } - } - }; - - function createExchangeResponse (bidList, auctionConfigs = null) { - let bids = []; - if (Array.isArray(bidList)) { - bids = bidList; - } else if (bidList) { - bids.push(bidList); - } - - if (!auctionConfigs) { - return { - 'body': {bids} - }; - } - - return { - 'body': { - bids, - auctionConfigs - } - } - }; - - const inStreamServerResponse = { - 'requestId': '262594d5d1f8104', - 'cpm': 0.3825, - 'currency': 'USD', - 'width': 640, - 'height': 480, - 'creativeId': 'cr-test-video-3', - 'netRevenue': true, - 'ttl': 350, - 'vastUrl': 'https://adserve.rhythmxchange.dvl/rtbtest/nurlvast?event=impnurl&doc_type=testad&doc_version=2&crid=cr-test-video-3&ssp=2057&pubid=545454&placementid=1052819&oppid=b516bc57-0475-4377-bdc6-369c44b31d46&mediatype=site&attempt_ts=1622740567081&extra=1', - 'meta': { - 'mediaType': 'video', - 'videoContext': 'instream' - } - }; - - const inStreamServerResponseWithVastXml = { - 'requestId': '262594d5d1f8104', - 'cpm': 0.3825, - 'currency': 'USD', - 'width': 640, - 'height': 480, - 'creativeId': 'cr-test-video-3', - 'netRevenue': true, - 'ttl': 350, - 'vastXml': 'https://adserve.rhythmxchange.dvl/rtbtest/nurlvast?event=impnurl&doc_type=testad&doc_version=2&crid=cr-test-video-3&ssp=2057&pubid=545454&placementid=1052819&oppid=b516bc57-0475-4377-bdc6-369c44b31d46&mediatype=site&attempt_ts=1622740567081&extra=1', - 'meta': { - 'mediaType': 'video', - 'videoContext': 'instream' - } - }; - - const bannerServerResponse = { - 'requestId': '2de3a9047fa9c6', - 'cpm': 5.34, - 'currency': 'USD', - 'width': 300, - 'height': 250, - 'creativeId': 'cr-test-banner-1', - 'netRevenue': true, - 'ttl': 350, - 'ad': "", - 'meta': { - 'mediaType': 'banner' - } - }; - - let sandbox; - let fakeRenderer; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - sandbox.stub(utils, 'logError'); - sandbox.stub(Renderer, 'install'); - - fakeRenderer = { - setRender: sinon.stub() - }; - Renderer.install.returns(fakeRenderer) - }); - - afterEach(function () { - sandbox.restore(); - delete parent.window.unruly - }); - - it('should expose Unruly Bidder code', function () { - expect(adapter.code).to.equal('unruly') - }); - - it('should contain the VIDEO mediaType', function () { - expect(adapter.supportedMediaTypes).to.deep.equal([VIDEO, BANNER]) - }); - - describe('isBidRequestValid', function () { - it('should be a function', function () { - expect(typeof adapter.isBidRequestValid).to.equal('function') - }); - it('should return false if bid is false', function () { - expect(adapter.isBidRequestValid()).to.be.false; - }); - it('should return true if bid.mediaType is "banner"', function () { - const mockBid = { - mediaTypes: { - banner: { - sizes: [ - [600, 500], - [300, 250] - ] - } - }, - params: { - siteId: 233261 - } - }; - expect(adapter.isBidRequestValid(mockBid)).to.be.true; - }); - it('should return true if bid.mediaTypes.video.context is "outstream"', function () { - const mockBid = { - mediaTypes: { - video: { - context: 'outstream', - mimes: ['video/mp4'], - playerSize: [[640, 480]] - } - }, - params: { - siteId: 233261 - } - }; - expect(adapter.isBidRequestValid(mockBid)).to.be.true; - }); - it('should return true if bid.mediaTypes.video.context is "instream"', function () { - const mockBid = { - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mp4'], - playerSize: [[640, 480]] - } - }, - params: { - siteId: 233261 - } - }; - expect(adapter.isBidRequestValid(mockBid)).to.be.true; - }); - it('should return false if bid.mediaTypes.video.context is not "instream" or "outstream"', function () { - const mockBid = { - mediaTypes: { - video: { - context: 'context', - mimes: ['video/mp4'], - playerSize: [[640, 480]] - } - }, - params: { - siteId: 233261 - } - }; - expect(adapter.isBidRequestValid(mockBid)).to.be.false; - }); - it('should return false if bid.mediaTypes.video.context not exist', function () { - const mockBid = { - mediaTypes: { - video: { - mimes: ['video/mp4'], - playerSize: [[640, 480]] - } - }, - params: { - siteId: 233261 - } - }; - expect(adapter.isBidRequestValid(mockBid)).to.be.false; - }); - it('should return false if bid.mediaType is not "video" or "banner"', function () { - const mockBid = { - mediaTypes: { - native: { - image: { - sizes: [300, 250] - } - } - }, - params: { - siteId: 233261 - } - }; - expect(adapter.isBidRequestValid(mockBid)).to.be.false; - }); - it('should return false if bid.mediaTypes is empty', function () { - const mockBid = { - mediaTypes: {}, - params: { - siteId: 233261 - } - }; - expect(adapter.isBidRequestValid(mockBid)).to.be.false; - }); - it('should return false if bid.params.siteId not exist', function () { - const mockBid = { - mediaTypes: { - video: { - context: 'outstream', - mimes: ['video/mp4'], - playerSize: [[640, 480]] - } - }, - params: { - targetingUUID: 233261 - } - }; - expect(adapter.isBidRequestValid(mockBid)).to.be.false; - }); - }); - - describe('buildRequests', function () { - let mockBidRequests; - beforeEach(function () { - mockBidRequests = { - 'bidderCode': 'unruly', - 'bids': [ - { - 'bidder': 'unruly', - 'params': { - 'siteId': 233261, - }, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'mimes': [ - 'video/mp4' - ], - 'playerSize': [ - [ - 640, - 480 - ] - ] - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'sizes': [ - [ - 640, - 480 - ] - ], - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b', - } - ] - }; - }); - - it('should be a function', function () { - expect(typeof adapter.buildRequests).to.equal('function'); - }); - it('should return an object', function () { - // const mockBidRequests = ['mockBid']; - expect(typeof adapter.buildRequests(mockBidRequests.bids, mockBidRequests)).to.equal('object') - }); - it('should return an array with 2 items when the bids has different siteId\'s', function () { - mockBidRequests = { - 'bidderCode': 'unruly', - 'bids': [ - { - 'bidder': 'unruly', - 'params': { - 'siteId': 233261, - }, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'mimes': [ - 'video/mp4' - ], - 'playerSize': [ - [ - 640, - 480 - ] - ] - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'sizes': [ - [ - 640, - 480 - ] - ], - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b', - }, - { - 'bidder': 'unruly', - 'params': { - 'siteId': 2234554, - }, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'mimes': [ - 'video/mp4' - ], - 'playerSize': [ - [ - 640, - 480 - ] - ] - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'sizes': [ - [ - 640, - 480 - ] - ], - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b', - } - ] - }; - - const result = adapter.buildRequests(mockBidRequests.bids, mockBidRequests); - expect(typeof result).to.equal('object'); - expect(result.length).to.equal(2); - expect(result[0].data.bidderRequest.bids.length).to.equal(1); - expect(result[1].data.bidderRequest.bids.length).to.equal(1); - }); - it('should return an array with 1 items when the bids has same siteId', function () { - mockBidRequests = { - 'bidderCode': 'unruly', - 'bids': [ - { - 'bidder': 'unruly', - 'params': { - 'siteId': 233261, - }, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'mimes': [ - 'video/mp4' - ], - 'playerSize': [ - [ - 640, - 480 - ] - ] - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'sizes': [ - [ - 640, - 480 - ] - ], - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b', - }, - { - 'bidder': 'unruly', - 'params': { - 'siteId': 233261, - }, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'mimes': [ - 'video/mp4' - ], - 'playerSize': [ - [ - 640, - 480 - ] - ] - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'sizes': [ - [ - 640, - 480 - ] - ], - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b', - } - ] - }; - - const result = adapter.buildRequests(mockBidRequests.bids, mockBidRequests); - expect(typeof result).to.equal('object'); - expect(result.length).to.equal(1); - expect(result[0].data.bidderRequest.bids.length).to.equal(2); - }); - it('should return a server request with a valid exchange url', function () { - expect(adapter.buildRequests(mockBidRequests.bids, mockBidRequests)[0].url).to.equal('https://targeting.unrulymedia.com/unruly_prebid') - }); - it('should return a server request with a the end point url instead of the exchange url', function () { - mockBidRequests.bids[0].params.endpoint = '//testendpoint.com'; - expect(adapter.buildRequests(mockBidRequests.bids, mockBidRequests)[0].url).to.equal('//testendpoint.com'); - }); - it('should return a server request with method === POST', function () { - expect(adapter.buildRequests(mockBidRequests.bids, mockBidRequests)[0].method).to.equal('POST'); - }); - it('should ensure contentType is `application/json`', function () { - expect(adapter.buildRequests(mockBidRequests.bids, mockBidRequests)[0].options).to.deep.equal({ - contentType: 'application/json' - }); - }); - it('should return a server request with valid payload', function () { - const expectedResult = { - bidderRequest: { - 'bids': [ - { - 'bidder': 'unruly', - 'params': { - 'siteId': 233261 - }, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'mimes': [ - 'video/mp4' - ], - 'playerSize': [ - [ - 640, - 480 - ] - ], - 'floor': 0 - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'sizes': [ - [ - 640, - 480 - ] - ], - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b' - } - ], - 'invalidBidsCount': 0, - 'prebidVersion': '$prebid.version$' - } - }; - - expect(adapter.buildRequests(mockBidRequests.bids, mockBidRequests)[0].data).to.deep.equal(expectedResult) - }); - it('should return request and remove the duplicate sizes', function () { - mockBidRequests = { - 'bidderCode': 'unruly', - 'bids': [ - { - 'bidder': 'unruly', - 'params': { - 'siteId': 233261, - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 640, - 480 - ], - [ - 640, - 480 - ], - [ - 300, - 250 - ], - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b', - } - ] - }; - - const expectedResult = { - bidderRequest: { - 'bids': [ - { - 'bidder': 'unruly', - 'params': { - 'siteId': 233261 - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 640, - 480 - ], - [ - 300, - 250 - ] - ], - 'floor': 0 - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b', - } - ], - 'invalidBidsCount': 0, - 'prebidVersion': '$prebid.version$' - } - }; - - const result = adapter.buildRequests(mockBidRequests.bids, mockBidRequests); - expect(result[0].data).to.deep.equal(expectedResult); - }); - - it('should return have the floor value from the bid', function () { - mockBidRequests = { - 'bidderCode': 'unruly', - 'bids': [ - { - 'bidder': 'unruly', - 'params': { - 'siteId': 233261, - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 640, - 480 - ] - ] - } - }, - 'floors': { - 'enforceFloors': true, - 'currency': 'USD', - 'schema': { - 'fields': [ - 'mediaType' - ] - }, - 'values': { - 'banner': 3 - }, - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b', - } - ] - }; - - const getFloor = (data) => { - return {floor: 3} - }; - - mockBidRequests.bids[0].getFloor = getFloor; - - const expectedResult = { - bidderRequest: { - 'bids': [ - { - 'bidder': 'unruly', - 'params': { - 'siteId': 233261 - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 640, - 480 - ] - ], - 'floor': 3 - } - }, - 'floors': { - 'enforceFloors': true, - 'currency': 'USD', - 'schema': { - 'fields': [ - 'mediaType' - ] - }, - 'values': { - 'banner': 3 - }, - }, - getFloor: getFloor, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b', - } - ], - 'invalidBidsCount': 0, - 'prebidVersion': '$prebid.version$' - } - }; - - const result = adapter.buildRequests(mockBidRequests.bids, mockBidRequests); - expect(result[0].data).to.deep.equal(expectedResult); - }); - describe('Protected Audience Support', function() { - it('should return an array with 2 items and enabled protected audience', function () { - mockBidRequests = { - 'bidderCode': 'unruly', - 'paapi': { - enabled: true - }, - 'bids': [ - { - 'bidder': 'unruly', - 'params': { - 'siteId': 233261, - }, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'mimes': [ - 'video/mp4' - ], - 'playerSize': [ - [ - 640, - 480 - ] - ] - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'sizes': [ - [ - 640, - 480 - ] - ], - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b', - 'ortb2Imp': { - 'ext': { - 'ae': 1 - } - } - }, - { - 'bidder': 'unruly', - 'params': { - 'siteId': 2234554, - }, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'mimes': [ - 'video/mp4' - ], - 'playerSize': [ - [ - 640, - 480 - ] - ] - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'sizes': [ - [ - 640, - 480 - ] - ], - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b', - 'ortb2Imp': { - 'ext': { - 'ae': 1 - } - } - } - ] - }; - - const result = adapter.buildRequests(mockBidRequests.bids, mockBidRequests); - expect(typeof result).to.equal('object'); - expect(result.length).to.equal(2); - expect(result[0].data.bidderRequest.bids.length).to.equal(1); - expect(result[1].data.bidderRequest.bids.length).to.equal(1); - expect(result[0].data.bidderRequest.bids[0].ortb2Imp.ext.ae).to.equal(1); - expect(result[1].data.bidderRequest.bids[0].ortb2Imp.ext.ae).to.equal(1); - }); - it('should return an array with 2 items and enabled protected audience on only one unit', function () { - mockBidRequests = { - 'bidderCode': 'unruly', - 'paapi': { - enabled: true - }, - 'bids': [ - { - 'bidder': 'unruly', - 'params': { - 'siteId': 233261, - }, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'mimes': [ - 'video/mp4' - ], - 'playerSize': [ - [ - 640, - 480 - ] - ] - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'sizes': [ - [ - 640, - 480 - ] - ], - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b', - 'ortb2Imp': { - 'ext': { - 'ae': 1 - } - } - }, - { - 'bidder': 'unruly', - 'params': { - 'siteId': 2234554, - }, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'mimes': [ - 'video/mp4' - ], - 'playerSize': [ - [ - 640, - 480 - ] - ] - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'sizes': [ - [ - 640, - 480 - ] - ], - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b', - 'ortb2Imp': { - 'ext': {} - } - } - ] - }; - - const result = adapter.buildRequests(mockBidRequests.bids, mockBidRequests); - expect(typeof result).to.equal('object'); - expect(result.length).to.equal(2); - expect(result[0].data.bidderRequest.bids.length).to.equal(1); - expect(result[1].data.bidderRequest.bids.length).to.equal(1); - expect(result[0].data.bidderRequest.bids[0].ortb2Imp.ext.ae).to.equal(1); - expect(result[1].data.bidderRequest.bids[0].ortb2Imp.ext.ae).to.be.undefined; - }); - it('disables configured protected audience when fledge is not availble', function () { - mockBidRequests = { - 'bidderCode': 'unruly', - 'fledgeEnabled': false, - 'bids': [ - { - 'bidder': 'unruly', - 'params': { - 'siteId': 233261, - }, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'mimes': [ - 'video/mp4' - ], - 'playerSize': [ - [ - 640, - 480 - ] - ] - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'sizes': [ - [ - 640, - 480 - ] - ], - 'bidId': '27a3ee1626a5c7', - 'bidderRequestId': '12e00d17dff07b', - 'ortb2Imp': { - 'ext': { - 'ae': 1 - } - } - } - ] - }; - - const result = adapter.buildRequests(mockBidRequests.bids, mockBidRequests); - expect(typeof result).to.equal('object'); - expect(result.length).to.equal(1); - expect(result[0].data.bidderRequest.bids.length).to.equal(1); - expect(result[0].data.bidderRequest.bids[0].ortb2Imp.ext.ae).to.be.undefined; - }); - }); - }); - - describe('interpretResponse', function () { - it('should be a function', function () { - expect(typeof adapter.interpretResponse).to.equal('function'); - }); - it('should return [] when serverResponse is undefined', function () { - expect(adapter.interpretResponse()).to.deep.equal([]); - }); - it('should return [] when serverResponse has no bids', function () { - const mockServerResponse = {body: {bids: []}}; - expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([]) - }); - it('should return array of bids when receive a successful response from server', function () { - const mockExchangeBid = createOutStreamExchangeBid({adUnitCode: 'video1', requestId: 'mockBidId'}); - const mockServerResponse = createExchangeResponse(mockExchangeBid); - expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([ - { - 'ext': { - 'statusCode': 1, - 'renderer': { - 'id': 'unruly_inarticle', - 'config': { - 'siteId': 123456, - 'targetingUUID': 'xxx-yyy-zzz' - }, - 'url': 'https://video.unrulymedia.com/native/prebid-loader.js' - }, - 'adUnitCode': 'video1' - }, - requestId: 'mockBidId', - bidderCode: 'unruly', - cpm: 20, - width: 323, - height: 323, - vastUrl: 'https://targeting.unrulymedia.com/in_article?uuid=74544e00-d43b-4f3a-a799-69d22ce979ce&supported_mime_type=application/javascript&supported_mime_type=video/mp4&tj=%7B%22site%22%3A%7B%22lang%22%3A%22en-GB%22%2C%22ref%22%3A%22%22%2C%22page%22%3A%22https%3A%2F%2Fdemo.unrulymedia.com%2FinArticle%2Finarticle_nypost_upbeat%2Ftravel_magazines.html%22%2C%22domain%22%3A%22demo.unrulymedia.com%22%7D%2C%22user%22%3A%7B%22profile%22%3A%7B%22quantcast%22%3A%7B%22segments%22%3A%5B%7B%22id%22%3A%22D%22%7D%2C%7B%22id%22%3A%22T%22%7D%5D%7D%7D%7D%7D&video_width=618&video_height=347', - netRevenue: true, - creativeId: 'mockBidId', - ttl: 360, - 'meta': { - 'mediaType': 'video', - 'videoContext': 'outstream' - }, - currency: 'USD', - renderer: fakeRenderer, - mediaType: 'video' - } - ]); - }); - - it('should return object with an array of bids and an array of auction configs when it receives a successful response from server', function () { - const bidId = '27a3ee1626a5c7' - const mockExchangeBid = createOutStreamExchangeBid({adUnitCode: 'video1', requestId: 'mockBidId'}); - const mockExchangeAuctionConfig = {}; - mockExchangeAuctionConfig[bidId] = createOutStreamExchangeAuctionConfig(); - const mockServerResponse = createExchangeResponse(mockExchangeBid, mockExchangeAuctionConfig); - const originalRequest = { - 'data': { - 'bidderRequest': { - 'bids': [ - { - 'bidder': 'unruly', - 'params': { - 'siteId': 233261, - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 640, - 480 - ], - [ - 640, - 480 - ], - [ - 300, - 250 - ], - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'bidId': bidId, - 'bidderRequestId': '12e00d17dff07b', - } - ] - } - } - }; - - expect(adapter.interpretResponse(mockServerResponse, originalRequest)).to.deep.equal({ - 'bids': [ - { - 'ext': { - 'statusCode': 1, - 'renderer': { - 'id': 'unruly_inarticle', - 'config': { - 'siteId': 123456, - 'targetingUUID': 'xxx-yyy-zzz' - }, - 'url': 'https://video.unrulymedia.com/native/prebid-loader.js' - }, - 'adUnitCode': 'video1' - }, - requestId: 'mockBidId', - bidderCode: 'unruly', - cpm: 20, - width: 323, - height: 323, - vastUrl: 'https://targeting.unrulymedia.com/in_article?uuid=74544e00-d43b-4f3a-a799-69d22ce979ce&supported_mime_type=application/javascript&supported_mime_type=video/mp4&tj=%7B%22site%22%3A%7B%22lang%22%3A%22en-GB%22%2C%22ref%22%3A%22%22%2C%22page%22%3A%22https%3A%2F%2Fdemo.unrulymedia.com%2FinArticle%2Finarticle_nypost_upbeat%2Ftravel_magazines.html%22%2C%22domain%22%3A%22demo.unrulymedia.com%22%7D%2C%22user%22%3A%7B%22profile%22%3A%7B%22quantcast%22%3A%7B%22segments%22%3A%5B%7B%22id%22%3A%22D%22%7D%2C%7B%22id%22%3A%22T%22%7D%5D%7D%7D%7D%7D&video_width=618&video_height=347', - netRevenue: true, - creativeId: 'mockBidId', - ttl: 360, - 'meta': { - 'mediaType': 'video', - 'videoContext': 'outstream' - }, - currency: 'USD', - renderer: fakeRenderer, - mediaType: 'video' - } - ], - 'paapi': [{ - 'bidId': bidId, - 'config': { - 'seller': 'https://nexxen.tech', - 'decisionLogicURL': 'https://nexxen.tech/padecisionlogic', - 'interestGroupBuyers': 'https://mydsp.com', - 'perBuyerSignals': { - 'https://mydsp.com': { - 'floor': 'bouttreefiddy' - } - } - } - }] - }); - }); - - it('should return object with an array of auction configs when it receives a successful response from server without bids', function () { - const bidId = '27a3ee1626a5c7'; - const mockExchangeAuctionConfig = {}; - mockExchangeAuctionConfig[bidId] = createOutStreamExchangeAuctionConfig(); - const mockServerResponse = createExchangeResponse(null, mockExchangeAuctionConfig); - const originalRequest = { - 'data': { - 'bidderRequest': { - 'bids': [ - { - 'bidder': 'unruly', - 'params': { - 'siteId': 233261, - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 640, - 480 - ], - [ - 640, - 480 - ], - [ - 300, - 250 - ], - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': 'video2', - 'transactionId': 'a89619e3-137d-4cc5-9ed4-58a0b2a0bbc2', - 'bidId': bidId, - 'bidderRequestId': '12e00d17dff07b' - } - ] - } - } - }; - - expect(adapter.interpretResponse(mockServerResponse, originalRequest)).to.deep.equal({ - 'bids': [], - 'paapi': [{ - 'bidId': bidId, - 'config': { - 'seller': 'https://nexxen.tech', - 'decisionLogicURL': 'https://nexxen.tech/padecisionlogic', - 'interestGroupBuyers': 'https://mydsp.com', - 'perBuyerSignals': { - 'https://mydsp.com': { - 'floor': 'bouttreefiddy' - } - } - } - }] - }); - }); - - it('should initialize and set the renderer', function () { - expect(Renderer.install.called).to.be.false; - expect(fakeRenderer.setRender.called).to.be.false; - - const mockReturnedBid = createOutStreamExchangeBid({adUnitCode: 'video1', requestId: 'mockBidId'}); - const mockRenderer = { - url: 'value: mockRendererURL', - config: { - siteId: 123456, - targetingUUID: 'xxx-yyy-zzz' - } - }; - mockReturnedBid.ext.renderer = mockRenderer; - const mockServerResponse = createExchangeResponse(mockReturnedBid); - - adapter.interpretResponse(mockServerResponse); - - expect(Renderer.install.calledOnce).to.be.true; - sinon.assert.calledWithExactly( - Renderer.install, - Object.assign({}, mockRenderer) - ); - - sinon.assert.calledOnce(fakeRenderer.setRender); - sinon.assert.calledWithExactly(fakeRenderer.setRender, sinon.match.func) - }); - - it('should return [] and log if bidResponse renderer config is not available', function () { - sinon.assert.notCalled(utils.logError); - - expect(Renderer.install.called).to.be.false; - expect(fakeRenderer.setRender.called).to.be.false; - - const mockReturnedBid = createOutStreamExchangeBid({adUnitCode: 'video1', requestId: 'mockBidId'}); - const mockRenderer = { - url: 'value: mockRendererURL' - }; - mockReturnedBid.ext.renderer = mockRenderer; - const mockServerResponse = createExchangeResponse(mockReturnedBid); - - expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([]); - - const logErrorCalls = utils.logError.getCalls(); - expect(logErrorCalls.length).to.equal(1); - - const [configErrorCall] = logErrorCalls; - - expect(configErrorCall.args.length).to.equal(1); - expect(configErrorCall.args[0].message).to.equal('UnrulyBidAdapter: Missing renderer config.'); - }); - - it('should return [] and log if siteId is not available', function () { - sinon.assert.notCalled(utils.logError); - - expect(Renderer.install.called).to.be.false; - expect(fakeRenderer.setRender.called).to.be.false; - - const mockReturnedBid = createOutStreamExchangeBid({adUnitCode: 'video1', requestId: 'mockBidId'}); - const mockRenderer = { - url: 'value: mockRendererURL', - config: {} - }; - mockReturnedBid.ext.renderer = mockRenderer; - const mockServerResponse = createExchangeResponse(mockReturnedBid); - - expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([]); - - const logErrorCalls = utils.logError.getCalls(); - expect(logErrorCalls.length).to.equal(1); - - const [siteIdErrorCall] = logErrorCalls; - - expect(siteIdErrorCall.args.length).to.equal(1); - expect(siteIdErrorCall.args[0].message).to.equal('UnrulyBidAdapter: Missing renderer siteId.'); - }); - - it('bid is placed on the bid queue when render is called', function () { - const exchangeBid = createOutStreamExchangeBid({adUnitCode: 'video', vastUrl: 'value: vastUrl'}); - const exchangeResponse = createExchangeResponse(exchangeBid); - - adapter.interpretResponse(exchangeResponse); - - sinon.assert.calledOnce(fakeRenderer.setRender); - fakeRenderer.setRender.firstCall.args[0](); - - expect(window.top).to.have.deep.nested.property('unruly.native.prebid.uq'); - - const uq = window.top.unruly.native.prebid.uq; - const sentRendererConfig = uq[0][1]; - - expect(uq[0][0]).to.equal('render'); - expect(sentRendererConfig.vastUrl).to.equal('value: vastUrl'); - expect(sentRendererConfig.renderer).to.equal(fakeRenderer); - expect(sentRendererConfig.adUnitCode).to.equal('video') - }); - - it('should ensure that renderer is placed in Prebid supply mode', function () { - const mockExchangeBid = createOutStreamExchangeBid({adUnitCode: 'video1', requestId: 'mockBidId'}); - const mockServerResponse = createExchangeResponse(mockExchangeBid); - - expect('unruly' in window.parent).to.equal(false); - - adapter.interpretResponse(mockServerResponse); - - const supplyMode = window.parent.unruly.native.supplyMode; - - expect(supplyMode).to.equal('prebid'); - }); - - it('should return correct response when ad type is instream with vastUrl', function () { - const mockServerResponse = createExchangeResponse(inStreamServerResponse); - const expectedResponse = inStreamServerResponse; - expectedResponse.mediaType = 'video'; - - expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([expectedResponse]); - }); - - it('should return correct response when ad type is instream with vastXml', function () { - const mockServerResponse = {...createExchangeResponse(inStreamServerResponseWithVastXml)}; - const expectedResponse = inStreamServerResponseWithVastXml; - expectedResponse.mediaType = 'video'; - - expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([expectedResponse]); - }); - - it('should return [] and log if no vastUrl in instream response', function () { - const {vastUrl, ...inStreamServerResponseNoVast} = inStreamServerResponse; - const mockServerResponse = createExchangeResponse(inStreamServerResponseNoVast); - - expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([]); - - const logErrorCalls = utils.logError.getCalls(); - - expect(logErrorCalls.length).to.equal(1); - - const [siteIdErrorCall] = logErrorCalls; - - expect(siteIdErrorCall.args.length).to.equal(1); - expect(siteIdErrorCall.args[0].message).to.equal('UnrulyBidAdapter: Missing vastUrl or vastXml config.'); - }); - - it('should return correct response when ad type is banner', function () { - const mockServerResponse = createExchangeResponse(bannerServerResponse); - const expectedResponse = bannerServerResponse; - expectedResponse.mediaType = 'banner'; - - expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([expectedResponse]); - }); - - it('should return [] and log if no ad in banner response', function () { - const {ad, ...bannerServerResponseNoAd} = bannerServerResponse; - const mockServerResponse = createExchangeResponse(bannerServerResponseNoAd); - - expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([]); - - const logErrorCalls = utils.logError.getCalls(); - - expect(logErrorCalls.length).to.equal(1); - - const [siteIdErrorCall] = logErrorCalls; - - expect(siteIdErrorCall.args.length).to.equal(1); - expect(siteIdErrorCall.args[0].message).to.equal('UnrulyBidAdapter: Missing ad config.'); - }); - - it('should return correct response for multiple bids', function () { - const outStreamServerResponse = createOutStreamExchangeBid({adUnitCode: 'video1', requestId: 'mockBidId'}); - const mockServerResponse = createExchangeResponse([outStreamServerResponse, inStreamServerResponse, bannerServerResponse]); - const expectedOutStreamResponse = outStreamServerResponse; - expectedOutStreamResponse.mediaType = 'video'; - - const expectedInStreamResponse = inStreamServerResponse; - expectedInStreamResponse.mediaType = 'video'; - - const expectedBannerResponse = bannerServerResponse; - expectedBannerResponse.mediaType = 'banner'; - - expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([expectedOutStreamResponse, expectedInStreamResponse, expectedBannerResponse]); - }); - - it('should return only valid bids', function () { - const {ad, ...bannerServerResponseNoAd} = bannerServerResponse; - const mockServerResponse = createExchangeResponse([bannerServerResponseNoAd, inStreamServerResponse]); - const expectedInStreamResponse = inStreamServerResponse; - expectedInStreamResponse.mediaType = 'video'; - - expect(adapter.interpretResponse(mockServerResponse)).to.deep.equal([expectedInStreamResponse]); - - const logErrorCalls = utils.logError.getCalls(); - - expect(logErrorCalls.length).to.equal(1); - - const [siteIdErrorCall] = logErrorCalls; - - expect(siteIdErrorCall.args.length).to.equal(1); - expect(siteIdErrorCall.args[0].message).to.equal('UnrulyBidAdapter: Missing ad config.'); - }); - }); -}); diff --git a/test/spec/modules/userId_spec.js b/test/spec/modules/userId_spec.js index 5707a043f..4139c1479 100644 --- a/test/spec/modules/userId_spec.js +++ b/test/spec/modules/userId_spec.js @@ -35,7 +35,7 @@ import {allConsent, GDPR_GVLIDS, gdprDataHandler} from '../../../src/consentHand import {MODULE_TYPE_UID} from '../../../src/activities/modules.js'; import {ACTIVITY_ENRICH_EIDS} from '../../../src/activities/activities.js'; import {ACTIVITY_PARAM_COMPONENT_NAME, ACTIVITY_PARAM_COMPONENT_TYPE} from '../../../src/activities/params.js'; -import {extractEids} from '../../../modules/prebidServerBidAdapter/bidderConfig.js'; +import {extractEids} from '../../../modules/openadsServerBidAdapter/bidderConfig.js'; import {generateSubmoduleContainers, addIdData } from '../../../modules/userId/index.js'; import { registerActivityControl } from '../../../src/activities/rules.js'; import { diff --git a/test/spec/modules/valuadBidAdapter_spec.js b/test/spec/modules/valuadBidAdapter_spec.js deleted file mode 100644 index 5a37d2458..000000000 --- a/test/spec/modules/valuadBidAdapter_spec.js +++ /dev/null @@ -1,508 +0,0 @@ -import { expect } from 'chai'; -import * as sinon from 'sinon'; -import { spec } from 'modules/valuadBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { BANNER } from 'src/mediaTypes.js'; -import { deepClone, generateUUID } from 'src/utils.js'; -import { config } from 'src/config.js'; -import * as utils from 'src/utils.js'; -import * as gptUtils from 'libraries/gptUtils/gptUtils.js'; -import * as refererDetection from 'src/refererDetection.js'; -import * as BoundingClientRect from 'libraries/boundingClientRect/boundingClientRect.js'; - -const ENDPOINT = 'https://rtb.valuad.io/adapter'; -const WON_URL = 'https://hb-dot-valuad.appspot.com/adapter/win'; - -describe('ValuadAdapter', function () { - const adapter = newBidder(spec); - let requestToServer; - let validBidRequests; - let bidderRequest; - let sandbox; - let clock; - - before(function() { - validBidRequests = [ - { - bidder: 'valuad', - params: { - placementId: 'test-placement-id-1' - }, - adUnitCode: 'adunit-code-1', - mediaTypes: { - [BANNER]: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: 'bid-id-1', - bidderRequestId: 'br-id-1', - auctionId: 'auc-id-1', - transactionId: 'txn-id-1' - } - ]; - - bidderRequest = { - bidderCode: 'valuad', - auctionId: 'auc-id-1', - bidderRequestId: 'br-id-1', - bids: validBidRequests, - refererInfo: { - topmostLocation: 'http://test.com/page', - ref: 'http://referrer.com', - reachedTop: true - }, - timeout: 3000, - gdprConsent: { - apiVersion: 2, - gdprApplies: true, - consentString: 'test-consent-string', - allowAuctionWithoutConsent: false - }, - uspConsent: '1YN-', - ortb2: { - regs: { - gpp: 'test-gpp-string', - gpp_sid: [7], - ext: { - dsa: { behalf: 'advertiser', paid: 'advertiser' } - } - }, - site: { - ext: { - data: { pageType: 'article' } - } - }, - device: { - w: 1920, - h: 1080, - language: 'en-US' - } - } - }; - }); - - beforeEach(function () { - sandbox = sinon.sandbox.create(); - clock = sinon.useFakeTimers(); - - // Stub utility functions - sandbox.stub(utils, 'getWindowTop').returns({ - location: { href: 'http://test.com/page' }, - document: { - referrer: 'http://referrer.com', - documentElement: { - clientWidth: 1200, - scrollHeight: 2000, - scrollWidth: 1200 - } - }, - innerWidth: 1200, - innerHeight: 800, - screen: { width: 1920, height: 1080 }, - pageXOffset: 0, - pageYOffset: 0 - }); - - sandbox.stub(utils, 'getWindowSelf').returns({ - location: { href: 'http://test.com/page' }, - document: { - referrer: 'http://referrer.com', - documentElement: { - clientWidth: 1200, - scrollHeight: 2000, - scrollWidth: 1200 - } - }, - innerWidth: 1200, - innerHeight: 800, - screen: { width: 1920, height: 1080 }, - pageXOffset: 0, - pageYOffset: 0 - }); - - sandbox.stub(utils, 'canAccessWindowTop').returns(true); - sandbox.stub(utils, 'getDNT').returns(false); - sandbox.stub(utils, 'generateUUID').returns('test-uuid'); - - sandbox.stub(refererDetection, 'parseDomain').returns('test.com'); - - sandbox.stub(gptUtils, 'getGptSlotInfoForAdUnitCode').returns({ - gptSlot: '/123/adunit', - divId: 'div-gpt-ad-123' - }); - - sandbox.stub(config, 'getConfig').withArgs('coppa').returns(false); - - sandbox.stub(BoundingClientRect, 'getBoundingClientRect').returns({ - left: 10, - top: 20, - right: 310, - bottom: 270, - width: 300, - height: 250 - }); - - requestToServer = spec.buildRequests(validBidRequests, bidderRequest)[0]; - }); - - afterEach(function () { - sandbox.restore(); - clock.restore(); - }); - - describe('inherited functions', function () { - it('should exist and be a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', function () { - const bid = { - bidder: 'valuad', - params: { - placementId: 'test-placement-id' - }, - adUnitCode: 'adunit-code', - mediaTypes: { - [BANNER]: { - sizes: [[300, 250], [300, 600]] - } - }, - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - }; - - it('should return true for a valid banner bid request', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when placementId is missing', function () { - const invalidBid = deepClone(bid); - delete invalidBid.params.placementId; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when params are missing', function () { - const invalidBid = deepClone(bid); - delete invalidBid.params; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when bidId is missing', function () { - const invalidBid = deepClone(bid); - delete invalidBid.bidId; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when mediaTypes is missing', function () { - const invalidBid = deepClone(bid); - delete invalidBid.mediaTypes; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when banner sizes are missing', function () { - const invalidBid = deepClone(bid); - delete invalidBid.mediaTypes[BANNER].sizes; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('should return a valid server request object', function () { - expect(requestToServer).to.exist; - expect(requestToServer).to.be.an('object'); - expect(requestToServer.method).to.equal('POST'); - expect(requestToServer.url).to.equal(ENDPOINT); - expect(requestToServer.data).to.be.a('object'); - }); - - it('should build a correct ORTB request payload', function () { - const payload = requestToServer.data; - - expect(payload.id).to.be.a('string'); - expect(payload.imp).to.be.an('array').with.lengthOf(1); - expect(payload.cur).to.deep.equal(['USD']); - expect(payload.tmax).to.equal(bidderRequest.timeout); - - expect(payload.site).to.exist; - expect(payload.site.ext.data.pageType).to.equal('article'); - - expect(payload.device).to.exist; - expect(payload.device.language).to.equal('en-US'); - expect(payload.device.js).to.equal(1); - expect(payload.device.w).to.equal(1920); - expect(payload.device.h).to.equal(1080); - - expect(payload.regs).to.exist; - expect(payload.regs.gdpr).to.equal(1); - expect(payload.regs.coppa).to.equal(0); - expect(payload.regs.us_privacy).to.equal(bidderRequest.uspConsent); - expect(payload.regs.ext.gdpr_consent).to.equal(bidderRequest.gdprConsent.consentString); - expect(payload.regs.ext.gpp).to.equal(bidderRequest.ortb2.regs.gpp); - expect(payload.regs.ext.gpp_sid).to.deep.equal(bidderRequest.ortb2.regs.gpp_sid); - expect(payload.regs.ext.dsa).to.deep.equal(bidderRequest.ortb2.regs.ext.dsa); - - expect(payload.ext.params).to.deep.equal(validBidRequests[0].params); - - const imp = payload.imp[0]; - expect(imp.id).to.equal(validBidRequests[0].bidId); - expect(imp.banner).to.exist; - expect(imp.banner.format).to.be.an('array').with.lengthOf(2); - expect(imp.banner.format[0]).to.deep.equal({ w: 300, h: 250 }); - }); - - it('should include schain if present', function () { - const bidWithSchain = deepClone(validBidRequests); - bidWithSchain[0].schain = { ver: '1.0', complete: 1, nodes: [] }; - const reqWithSchain = deepClone(bidderRequest); - reqWithSchain.bids = bidWithSchain; - - const request = spec.buildRequests(bidWithSchain, reqWithSchain); - const payload = request[0].data; - expect(payload.source.ext.schain).to.deep.equal(bidWithSchain[0].schain); - }); - - it('should include eids if present', function () { - const bidWithEids = deepClone(validBidRequests); - bidWithEids[0].userIdAsEids = [{ source: 'pubcid.org', uids: [{ id: 'test-pubcid' }] }]; - const reqWithEids = deepClone(bidderRequest); - reqWithEids.bids = bidWithEids; - - const request = spec.buildRequests(bidWithEids, reqWithEids); - const payload = request[0].data; - expect(payload.user.ext.eids).to.deep.equal(bidWithEids[0].userIdAsEids); - }); - - it('should handle floors correctly', function () { - const bidWithFloor = deepClone(validBidRequests); - bidWithFloor[0].getFloor = sandbox.stub().returns({ currency: 'USD', floor: 1.50 }); - const reqWithFloor = deepClone(bidderRequest); - reqWithFloor.bids = bidWithFloor; - - const request = spec.buildRequests(bidWithFloor, reqWithFloor); - const payload = request[0].data; - expect(payload.imp[0].bidfloor).to.equal(1.50); - expect(payload.imp[0].bidfloorcur).to.equal('USD'); - sinon.assert.calledWith(bidWithFloor[0].getFloor, { currency: 'USD', mediaType: BANNER, size: [300, 250] }); - }); - }); - - describe('interpretResponse', function () { - let serverResponse; - - beforeEach(function() { - serverResponse = { - body: { - id: 'test-response-id', - seatbid: [ - { - seat: 'valuad', - bid: [ - { - id: 'test-bid-id', - impid: 'bid-id-1', - price: 1.50, - adm: '', - crid: 'creative-id-1', - mtype: 1, - w: 300, - h: 250, - adomain: ['advertiser.com'], - ext: { - prebid: { - type: BANNER - } - } - } - ] - } - ], - cur: 'USD', - ext: { - valuad: { serverInfo: 'some data' } - } - } - }; - }); - - it('should return an array of valid bid responses', function () { - expect(requestToServer).to.exist; - const bids = spec.interpretResponse(serverResponse, requestToServer); - - expect(bids).to.be.an('array').with.lengthOf(1); - const bid = bids[0]; - - expect(bid.requestId).to.equal('bid-id-1'); - expect(bid.cpm).to.equal(1.50); - expect(bid.currency).to.equal('USD'); - expect(bid.width).to.equal(300); - expect(bid.height).to.equal(250); - expect(bid.ad).to.equal(''); - expect(bid.creativeId).to.equal('creative-id-1'); - expect(bid.netRevenue).to.equal(true); - expect(bid.ttl).to.equal(30); - expect(bid.mediaType).to.equal(BANNER); - expect(bid.meta.advertiserDomains).to.deep.equal(['advertiser.com']); - expect(bid.vid).to.equal('test-placement-id-1'); - }); - - it('should return an empty array if seatbid is missing', function () { - const responseNoSeatbid = deepClone(serverResponse); - delete responseNoSeatbid.body.seatbid; - const bids = spec.interpretResponse(responseNoSeatbid, requestToServer); - expect(bids).to.be.an('array').with.lengthOf(0); - }); - - it('should return an empty array if bid array is empty', function () { - const responseEmptyBid = deepClone(serverResponse); - responseEmptyBid.body.seatbid[0].bid = []; - const bids = spec.interpretResponse(responseEmptyBid, requestToServer); - expect(bids).to.be.an('array').with.lengthOf(0); - }); - - it('should return empty array when response is null or undefined', function () { - expect(spec.interpretResponse(null, requestToServer)).to.deep.equal([]); - expect(spec.interpretResponse(undefined, requestToServer)).to.deep.equal([]); - }); - - it('should return empty array when response body is missing or invalid', function () { - expect(spec.interpretResponse({}, requestToServer)).to.deep.equal([]); - expect(spec.interpretResponse({ body: null }, requestToServer)).to.deep.equal([]); - expect(spec.interpretResponse({ body: undefined }, requestToServer)).to.deep.equal([]); - }); - }); - - describe('getUserSyncs', function () { - let serverResponses; - - beforeEach(function() { - serverResponses = [ - { - body: { - id: 'test-response-id', - userSyncs: [ - { type: 'iframe', url: 'https://sync.example.com/iframe?id=1' }, - { type: 'image', url: 'https://sync.example.com/pixel?id=2' } - ] - } - } - ]; - }); - - it('should return correct sync objects if server response has userSyncs', function () { - const syncs = spec.getUserSyncs({}, serverResponses); - expect(syncs).to.be.an('array').with.lengthOf(2); - expect(syncs[0]).to.deep.equal({ type: 'iframe', url: 'https://sync.example.com/iframe?id=1' }); - expect(syncs[1]).to.deep.equal({ type: 'image', url: 'https://sync.example.com/pixel?id=2' }); - }); - - it('should return false if server response is empty', function () { - const syncs = spec.getUserSyncs({}, []); - expect(syncs).to.be.false; - }); - - it('should return false if server response body is empty', function () { - const syncs = spec.getUserSyncs({}, [{ body: '' }]); - expect(syncs).to.be.false; - }); - - it('should return false if userSyncs array is missing in response body', function () { - const responseNoSyncs = deepClone(serverResponses); - delete responseNoSyncs[0].body.userSyncs; - const syncs = spec.getUserSyncs({}, responseNoSyncs); - expect(syncs).to.be.false; - }); - - it('should return false if userSyncs array is empty', function () { - const responseEmptySyncs = deepClone(serverResponses); - responseEmptySyncs[0].body.userSyncs = []; - const syncs = spec.getUserSyncs({}, responseEmptySyncs); - expect(syncs).to.be.an('array').with.lengthOf(0); - }); - }); - - describe('onBidWon', function () { - let triggerPixelStub; - let bidWonEvent; - let sandbox; - - beforeEach(function () { - sandbox = sinon.sandbox.create(); - triggerPixelStub = sandbox.stub(utils, 'triggerPixel'); - - bidWonEvent = { - adUnitCode: 'adunit-code-1', - adUnitId: 'adunit-id-1', - auctionId: 'auc-id-1', - bidder: 'valuad', - cpm: 1.50, - currency: 'USD', - originalCpm: 1.50, - originalCurrency: 'USD', - size: '300x250', - vbid: 'server-generated-vbid', - vid: 'test-placement-id-1', - }; - }); - - afterEach(function () { - sandbox.restore(); - }); - - it('should call triggerPixel with the correct URL and encoded data', function () { - spec.onBidWon(bidWonEvent); - - const expectedData = { - adUnitCode: bidWonEvent.adUnitCode, - adUnitId: bidWonEvent.adUnitId, - auctionId: bidWonEvent.auctionId, - bidder: bidWonEvent.bidder, - cpm: bidWonEvent.cpm, - currency: bidWonEvent.currency, - originalCpm: bidWonEvent.originalCpm, - originalCurrency: bidWonEvent.originalCurrency, - size: bidWonEvent.size, - vbid: bidWonEvent.vbid, - vid: bidWonEvent.vid, - }; - const expectedEncodedData = btoa(JSON.stringify(expectedData)); - const expectedUrl = `${WON_URL}?b=${expectedEncodedData}`; - - sinon.assert.calledOnce(triggerPixelStub); - sinon.assert.calledWith(triggerPixelStub, expectedUrl); - }); - - it('should handle missing optional properties in bid object gracefully', function () { - const minimalBid = { - adUnitCode: 'adunit-code-2', - auctionId: 'auc-id-2', - bidder: 'valuad', - cpm: 2.00, - currency: 'USD', - size: '728x90' - }; - - spec.onBidWon(minimalBid); - - const expectedData = { - adUnitCode: minimalBid.adUnitCode, - adUnitId: undefined, - auctionId: minimalBid.auctionId, - bidder: minimalBid.bidder, - cpm: minimalBid.cpm, - currency: minimalBid.currency, - originalCpm: undefined, - originalCurrency: undefined, - size: minimalBid.size, - vbid: undefined, - vid: undefined, - }; - const expectedEncodedData = btoa(JSON.stringify(expectedData)); - const expectedUrl = `${WON_URL}?b=${expectedEncodedData}`; - - sinon.assert.calledOnce(triggerPixelStub); - sinon.assert.calledWith(triggerPixelStub, expectedUrl); - }); - }); -}); diff --git a/test/spec/modules/vdoaiBidAdapter_spec.js b/test/spec/modules/vdoaiBidAdapter_spec.js deleted file mode 100644 index 4f3d9621e..000000000 --- a/test/spec/modules/vdoaiBidAdapter_spec.js +++ /dev/null @@ -1,768 +0,0 @@ -import { expect } from 'chai'; -import { spec } from '../../../modules/vdoaiBidAdapter.js'; - -describe('vdoaiBidAdapter', function () { - const bid1 = { - bidId: '2dd581a2b6281d', - bidder: 'vdoai', - bidderRequestId: '145e1d6a7837c9', - params: { - host: 'exchange.ortb.net', - adUnitId: 123, - adUnitType: 'banner', - publisherId: 'perfectPublisher', - custom1: 'custom1', - custom2: 'custom2', - custom3: 'custom3', - custom4: 'custom4', - custom5: 'custom5' - }, - placementCode: 'placement_0', - auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - ortb2Imp: { - ext: { - gpid: '/1111/homepage#300x250', - tid: '738d5915-6651-43b9-9b6b-d50517350917', - data: { - 'pbadslot': '/1111/homepage#300x250' - } - } - }, - userIdAsEids: [ - { - source: 'test1.org', - uids: [ - { - id: '123', - } - ] - } - ], - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'example.com', - sid: '1', - hp: 1 - } - ] - } - } - } - } - } - const bid2 = { - bidId: '58ee9870c3164a', - bidder: 'vdoai', - bidderRequestId: '209fdaf1c81649', - params: { - host: 'ads.vdo.ai', - adUnitId: 456, - adUnitType: 'banner', - custom1: 'custom1', - custom2: 'custom2', - custom3: 'custom3', - custom4: 'custom4', - custom5: 'custom5' - }, - placementCode: 'placement_1', - auctionId: '482f88de-29ab-45c8-981a-d25e39454a34', - sizes: [[350, 200]], - ortb2Imp: { - ext: { - gpid: '/1111/homepage#300x250', - tid: '738d5915-6651-43b9-9b6b-d50517350917', - data: { - 'pbadslot': '/1111/homepage#300x250' - } - } - }, - userIdAsEids: [ - { - source: 'test2.org', - uids: [ - { - id: '234', - } - ] - } - ], - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'example.com', - sid: '1', - hp: 1 - }, - { - asi: 'example1.com', - sid: '2', - hp: 1 - } - ] - } - } - } - } - } - const bid3 = { - bidId: '019645c7d69460', - bidder: 'vdoai', - bidderRequestId: 'f2b15f89e77ba6', - params: { - host: 'exchange.ortb.net', - adUnitId: 789, - adUnitType: 'video', - publisherId: 'secondPerfectPublisher', - custom1: 'custom1', - custom2: 'custom2', - custom3: 'custom3', - custom4: 'custom4', - custom5: 'custom5' - }, - placementCode: 'placement_2', - auctionId: 'e4771143-6aa7-41ec-8824-ced4342c96c8', - sizes: [[800, 600]], - ortb2Imp: { - ext: { - gpid: '/1111/homepage#300x250', - tid: '738d5915-6651-43b9-9b6b-d50517350917', - data: { - 'pbadslot': '/1111/homepage#300x250' - } - } - }, - userIdAsEids: [ - { - source: 'test3.org', - uids: [ - { - id: '345', - }, - { - id: '456', - } - ] - } - ], - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'example.com', - sid: '1', - hp: 1 - } - ] - } - } - } - } - } - const bid4 = { - bidId: '019645c7d69460', - bidder: 'vdoai', - bidderRequestId: 'f2b15f89e77ba6', - params: { - host: 'exchange.ortb.net', - adUnitId: 789, - adUnitType: 'video', - custom1: 'custom1', - custom2: 'custom2', - custom3: 'custom3', - custom4: 'custom4', - custom5: 'custom5' - }, - placementCode: 'placement_2', - auctionId: 'e4771143-6aa7-41ec-8824-ced4342c96c8', - video: { - playerSize: [800, 600] - }, - ortb2Imp: { - ext: { - gpid: '/1111/homepage#300x250', - tid: '738d5915-6651-43b9-9b6b-d50517350917', - data: { - 'pbadslot': '/1111/homepage#300x250' - } - } - }, - userIdAsEids: [ - { - source: 'test.org', - uids: [ - { - id: '111', - } - ] - } - ], - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'example.com', - sid: '1', - hp: 1 - } - ] - } - } - } - } - } - - describe('buildRequests', function () { - const bidderRequest = { - ortb2: { - device: { - sua: { - browsers: [], - platform: [], - mobile: 1, - architecture: 'arm' - } - } - }, - refererInfo: { - page: 'testPage' - } - } - const serverRequests = spec.buildRequests([bid1, bid2, bid3, bid4], bidderRequest) - it('Creates two ServerRequests', function() { - expect(serverRequests).to.exist - expect(serverRequests).to.have.lengthOf(2) - }) - serverRequests.forEach(serverRequest => { - it('Creates a ServerRequest object with method, URL and data', function () { - expect(serverRequest).to.exist - expect(serverRequest.method).to.exist - expect(serverRequest.url).to.exist - expect(serverRequest.data).to.exist - }) - it('Returns POST method', function () { - expect(serverRequest.method).to.equal('POST') - }) - it('Returns valid data if array of bids is valid', function () { - const data = serverRequest.data; - expect(data).to.be.an('object'); - expect(data).to.have.all.keys( - 'deviceWidth', - 'deviceHeight', - 'secure', - 'adUnits', - 'sua', - 'page', - 'ortb2', - 'refererInfo' - ); - expect(data.deviceWidth).to.be.a('number'); - expect(data.deviceHeight).to.be.a('number'); - expect(data.secure).to.be.a('boolean'); - data.adUnits.forEach(adUnit => { - expect(adUnit).to.have.all.keys( - 'id', - 'bidId', - 'type', - 'sizes', - 'transactionId', - 'publisherId', - 'userIdAsEids', - 'supplyChain', - 'custom1', - 'custom2', - 'custom3', - 'custom4', - 'custom5', - 'ortb2Imp' - ); - expect(adUnit.id).to.be.a('number'); - expect(adUnit.bidId).to.be.a('string'); - expect(adUnit.type).to.be.a('string'); - expect(adUnit.transactionId).to.be.a('string'); - expect(adUnit.sizes).to.be.an('array'); - expect(adUnit.userIdAsEids).to.be.an('array'); - expect(adUnit.supplyChain).to.be.an('object'); - expect(adUnit.custom1).to.be.a('string'); - expect(adUnit.custom2).to.be.a('string'); - expect(adUnit.custom3).to.be.a('string'); - expect(adUnit.custom4).to.be.a('string'); - expect(adUnit.custom5).to.be.a('string'); - expect(adUnit.ortb2Imp).to.be.an('object'); - }) - expect(data.sua.browsers).to.be.a('array'); - expect(data.sua.platform).to.be.a('array'); - expect(data.sua.mobile).to.be.a('number'); - expect(data.sua.architecture).to.be.a('string'); - expect(data.page).to.be.a('string'); - expect(data.page).to.be.equal('testPage'); - expect(data.ortb2).to.be.an('object'); - }) - }) - it('Returns valid URL', function () { - expect(serverRequests[0].url).to.equal('https://exchange.ortb.net/hb') - expect(serverRequests[1].url).to.equal('https://ads.vdo.ai/hb') - }) - it('Returns valid adUnits', function () { - validateAdUnit(serverRequests[0].data.adUnits[0], bid1) - validateAdUnit(serverRequests[1].data.adUnits[0], bid2) - validateAdUnit(serverRequests[0].data.adUnits[1], bid3) - }) - it('Returns empty data if no valid requests are passed', function () { - const serverRequests = spec.buildRequests([]) - expect(serverRequests).to.be.an('array').that.is.empty - }) - it('Returns request with page field value from ortb2 object if ortb2 has page field', function () { - bidderRequest.ortb2.site = { - page: 'testSitePage' - } - const serverRequests = spec.buildRequests([bid1], bidderRequest) - expect(serverRequests).to.have.lengthOf(1) - serverRequests.forEach(serverRequest => { - expect(serverRequest.data.page).to.be.a('string'); - expect(serverRequest.data.page).to.be.equal('testSitePage'); - }) - }) - }) - describe('interpretBannerResponse', function () { - const resObject = { - body: [ { - requestId: '123', - cpm: 0.3, - width: 320, - height: 50, - ad: '

Hello ad

', - ttl: 1000, - creativeId: '123asd', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['example.com'], - mediaType: 'banner' - } - } ] - }; - let serverResponses = spec.interpretResponse(resObject); - it('Returns an array of valid server responses if response object is valid', function () { - expect(serverResponses).to.be.an('array').that.is.not.empty; - for (let i = 0; i < serverResponses.length; i++) { - const dataItem = serverResponses[i]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'meta'); - expect(dataItem.requestId).to.be.a('string'); - expect(dataItem.cpm).to.be.a('number'); - expect(dataItem.width).to.be.a('number'); - expect(dataItem.height).to.be.a('number'); - expect(dataItem.ad).to.be.a('string'); - expect(dataItem.ttl).to.be.a('number'); - expect(dataItem.creativeId).to.be.a('string'); - expect(dataItem.netRevenue).to.be.a('boolean'); - expect(dataItem.currency).to.be.a('string'); - expect(dataItem.meta.advertiserDomains).to.be.an('array'); - expect(dataItem.meta.mediaType).to.be.a('string'); - } - it('Returns an empty array if invalid response is passed', function () { - serverResponses = spec.interpretResponse('invalid_response'); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - }); - describe('interpretVideoResponse', function () { - const resObject = { - body: [ { - requestId: '123', - cpm: 0.3, - width: 320, - height: 50, - vastXml: '', - ttl: 1000, - creativeId: '123asd', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['example.com'], - mediaType: 'video' - } - } ] - }; - let serverResponses = spec.interpretResponse(resObject); - it('Returns an array of valid server responses if response object is valid', function () { - expect(serverResponses).to.be.an('array').that.is.not.empty; - for (let i = 0; i < serverResponses.length; i++) { - const dataItem = serverResponses[i]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'vastXml', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'meta'); - expect(dataItem.requestId).to.be.a('string'); - expect(dataItem.cpm).to.be.a('number'); - expect(dataItem.width).to.be.a('number'); - expect(dataItem.height).to.be.a('number'); - expect(dataItem.vastXml).to.be.a('string'); - expect(dataItem.ttl).to.be.a('number'); - expect(dataItem.creativeId).to.be.a('string'); - expect(dataItem.netRevenue).to.be.a('boolean'); - expect(dataItem.currency).to.be.a('string'); - expect(dataItem.meta.advertiserDomains).to.be.an('array'); - expect(dataItem.meta.mediaType).to.be.a('string'); - } - it('should return an empty array if invalid response is passed', function () { - serverResponses = spec.interpretResponse('invalid_response'); - expect(serverResponses).to.be.an('array').that.is.empty; - }); - }); - }); - describe('isBidRequestValid', function() { - const bid = { - bidId: '2dd581a2b6281d', - bidder: 'vdoai', - bidderRequestId: '145e1d6a7837c9', - params: { - host: 'exchange.ortb.net', - adUnitId: 123, - adUnitType: 'banner' - }, - placementCode: 'placement_0', - auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', - sizes: [[300, 250]], - transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e62' - }; - - it('should return true when required params found', function() { - [bid, bid1, bid2, bid3].forEach(bid => { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - - it('should return true when adUnitId is zero', function() { - bid.params.adUnitId = 0; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function() { - const bidFailed = { - bidder: 'vdoai', - bidderRequestId: '145e1d6a7837c9', - params: { - adUnitId: 123, - adUnitType: 'banner' - }, - placementCode: 'placement_0', - auctionId: '74f78609-a92d-4cf1-869f-1b244bbfb5d2', - sizes: [[300, 250]], - transactionId: '3bb2f6da-87a6-4029-aeb0-bfe951372e62' - }; - expect(spec.isBidRequestValid(bidFailed)).to.equal(false); - }); - }); - describe('interpretResponse', function() { - const resObject = { - requestId: '123', - cpm: 0.3, - width: 320, - height: 50, - ad: '

Hello ad

', - ttl: 1000, - creativeId: '123asd', - netRevenue: true, - currency: 'USD', - meta: { - advertiserDomains: ['example.com'], - mediaType: 'banner' - } - }; - it('should skip responses which do not contain required params', function() { - const bidResponses = { - body: [ { - cpm: 0.3, - ttl: 1000, - currency: 'USD', - meta: { - advertiserDomains: ['example.com'], - mediaType: 'banner' - } - }, resObject ] - } - expect(spec.interpretResponse(bidResponses)).to.deep.equal([ resObject ]); - }); - it('should skip responses which do not contain advertiser domains', function() { - const resObjectWithoutAdvertiserDomains = Object.assign({}, resObject); - resObjectWithoutAdvertiserDomains.meta = Object.assign({}, resObject.meta); - delete resObjectWithoutAdvertiserDomains.meta.advertiserDomains; - const bidResponses = { - body: [ resObjectWithoutAdvertiserDomains, resObject ] - } - expect(spec.interpretResponse(bidResponses)).to.deep.equal([ resObject ]); - }); - it('should return responses which contain empty advertiser domains', function() { - const resObjectWithEmptyAdvertiserDomains = Object.assign({}, resObject); - resObjectWithEmptyAdvertiserDomains.meta = Object.assign({}, resObject.meta); - resObjectWithEmptyAdvertiserDomains.meta.advertiserDomains = []; - const bidResponses = { - body: [ resObjectWithEmptyAdvertiserDomains, resObject ] - } - expect(spec.interpretResponse(bidResponses)).to.deep.equal([resObjectWithEmptyAdvertiserDomains, resObject]); - }); - it('should skip responses which do not contain meta media type', function() { - const resObjectWithoutMetaMediaType = Object.assign({}, resObject); - resObjectWithoutMetaMediaType.meta = Object.assign({}, resObject.meta); - delete resObjectWithoutMetaMediaType.meta.mediaType; - const bidResponses = { - body: [ resObjectWithoutMetaMediaType, resObject ] - } - expect(spec.interpretResponse(bidResponses)).to.deep.equal([ resObject ]); - }); - }); - describe('getUserSyncs', function () { - it('should return trackers for lm(only iframe) if server responses contain lm user sync header and iframe and image enabled', function () { - const serverResponses = [ - { - headers: { - get: function (header) { - if (header === 'X-PLL-UserSync-Image') { - return 'https://tracker-lm.ortb.net/sync'; - } - if (header === 'X-PLL-UserSync-Iframe') { - return 'https://tracker-lm.ortb.net/sync.html'; - } - } - }, - body: [] - } - ]; - const syncOptions = { - iframeEnabled: true, - pixelEnabled: true - }; - expect(spec.getUserSyncs(syncOptions, serverResponses)).to.deep.equal([ - { - type: 'iframe', - url: 'https://tracker-lm.ortb.net/sync.html' - } - ]); - }); - it('should return empty array if all sync types are disabled', function () { - const serverResponses = [ - { - headers: { - get: function (header) { - if (header === 'X-PLL-UserSync-Image') { - return 'https://tracker-1.ortb.net/sync'; - } - if (header === 'X-PLL-UserSync-Iframe') { - return 'https://tracker-1.ortb.net/sync.html'; - } - } - }, - body: [] - } - ]; - const syncOptions = { - iframeEnabled: false, - pixelEnabled: false - }; - expect(spec.getUserSyncs(syncOptions, serverResponses)).to.be.an('array').that.is.empty; - }); - it('should return no pixels if iframe sync is enabled and headers are blank', function () { - const serverResponses = [ - { - headers: null, - body: [] - } - ]; - const syncOptions = { - iframeEnabled: true, - pixelEnabled: false - }; - expect(spec.getUserSyncs(syncOptions, serverResponses)).to.be.an('array').that.is.empty; - }); - it('should return image sync urls for lm if pixel sync is enabled and headers have lm pixel', function () { - const serverResponses = [ - { - headers: { - get: function (header) { - if (header === 'X-PLL-UserSync-Image') { - return 'https://tracker-lm.ortb.net/sync'; - } - if (header === 'X-PLL-UserSync-Iframe') { - return 'https://tracker-lm.ortb.net/sync.html'; - } - } - }, - body: [] - } - ]; - const syncOptions = { - iframeEnabled: false, - pixelEnabled: true - }; - expect(spec.getUserSyncs(syncOptions, serverResponses)).to.deep.equal([ - { - type: 'image', - url: 'https://tracker-lm.ortb.net/sync' - } - ]); - }); - it('should return image sync urls for client1 and clien2 if pixel sync is enabled and two responses and headers have two pixels', function () { - const serverResponses = [ - { - headers: { - get: function (header) { - if (header === 'X-PLL-UserSync-Image') { - return 'https://tracker-1.ortb.net/sync'; - } - if (header === 'X-PLL-UserSync-Iframe') { - return 'https://tracker-1.ortb.net/sync.html'; - } - } - }, - body: [] - }, - { - headers: { - get: function (header) { - if (header === 'X-PLL-UserSync-Image') { - return 'https://tracker-2.ortb.net/sync'; - } - if (header === 'X-PLL-UserSync-Iframe') { - return 'https://tracker-2.ortb.net/sync.html'; - } - } - }, - body: [] - } - ]; - const syncOptions = { - iframeEnabled: false, - pixelEnabled: true - }; - expect(spec.getUserSyncs(syncOptions, serverResponses)).to.deep.equal([ - { - type: 'image', - url: 'https://tracker-1.ortb.net/sync' - }, - { - type: 'image', - url: 'https://tracker-2.ortb.net/sync' - } - ]); - }); - it('should return image sync url for pll if pixel sync is enabled and two responses and headers have two same pixels', function () { - const serverResponses = [ - { - headers: { - get: function (header) { - if (header === 'X-PLL-UserSync-Image') { - return 'https://tracker-lm.ortb.net/sync'; - } - if (header === 'X-PLL-UserSync-Iframe') { - return 'https://tracker-lm.ortb.net/sync.html'; - } - } - }, - body: [] - }, - { - headers: { - get: function (header) { - if (header === 'X-PLL-UserSync-Image') { - return 'https://tracker-lm.ortb.net/sync'; - } - if (header === 'X-PLL-UserSync-Iframe') { - return 'https://tracker-lm.ortb.net/sync.html'; - } - } - }, - body: [] - } - ]; - const syncOptions = { - iframeEnabled: false, - pixelEnabled: true - }; - expect(spec.getUserSyncs(syncOptions, serverResponses)).to.deep.equal([ - { - type: 'image', - url: 'https://tracker-lm.ortb.net/sync' - } - ]); - }); - it('should return iframe sync url for pll if pixel sync is enabled and iframe is enables and headers have both iframe and img pixels', function () { - const serverResponses = [ - { - headers: { - get: function (header) { - if (header === 'X-PLL-UserSync-Image') { - return 'https://tracker-lm.ortb.net/sync'; - } - if (header === 'X-PLL-UserSync-Iframe') { - return 'https://tracker-lm.ortb.net/sync.html'; - } - } - }, - body: [] - } - ]; - const syncOptions = { - iframeEnabled: true, - pixelEnabled: true - }; - expect(spec.getUserSyncs(syncOptions, serverResponses)).to.deep.equal([ - { - type: 'iframe', - url: 'https://tracker-lm.ortb.net/sync.html' - } - ]); - }); - }); -}); - -function validateAdUnit(adUnit, bid) { - expect(adUnit.id).to.equal(bid.params.adUnitId); - expect(adUnit.bidId).to.equal(bid.bidId); - expect(adUnit.type).to.equal(bid.params.adUnitType.toUpperCase()); - expect(adUnit.transactionId).to.equal(bid.ortb2Imp.ext.tid); - let bidSizes = []; - if (bid.mediaTypes) { - if (bid.mediaTypes.video && bid.mediaTypes.video.playerSize) { - bidSizes = bidSizes.concat([bid.mediaTypes.video.playerSize]); - } - if (bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) { - bidSizes = bidSizes.concat(bid.mediaTypes.banner.sizes); - } - } - if (bid.sizes) { - bidSizes = bidSizes.concat(bid.sizes || []); - } - expect(adUnit.sizes).to.deep.equal(bidSizes.map(size => { - return { - width: size[0], - height: size[1] - } - })); - expect(adUnit.publisherId).to.equal(bid.params.publisherId); - expect(adUnit.userIdAsEids).to.deep.equal(bid.userIdAsEids); - expect(adUnit.supplyChain).to.deep.equal(bid.ortb2?.source?.ext?.schain); - expect(adUnit.ortb2Imp).to.deep.equal(bid.ortb2Imp); -} diff --git a/test/spec/modules/ventesBidAdapter_spec.js b/test/spec/modules/ventesBidAdapter_spec.js deleted file mode 100644 index 8e1a747f6..000000000 --- a/test/spec/modules/ventesBidAdapter_spec.js +++ /dev/null @@ -1,846 +0,0 @@ -import { expect } from 'chai'; -import * as utils from 'src/utils.js'; -import { spec } from 'modules/ventesBidAdapter.js'; - -const BIDDER_URL = 'https://ad.ventesavenues.in/va/ad'; - -describe('Ventes Adapter', function () { - const examples = { - adUnit_banner: { - adUnitCode: 'ad_unit_banner', - bidder: 'ventes', - bidderRequestId: 'bid_request_id', - bidId: 'bid_id', - params: { - publisherId: 'agltb3B1Yi1pbmNyDAsSA0FwcBiJkfTUCV', - placementId: 'VA-062-0013-0183', - device: { - ip: '123.145.167.189', - ifa: 'AEBE52E7-03EE-455A-B3C4-E57283966239', - } - }, - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - } - }, - - adUnitContext: { - refererInfo: { - page: 'https://ventesavenues.in', - domain: 'ventesavenues.in', - } - }, - - serverRequest_banner: { - method: 'POST', - url: BIDDER_URL, - data: { - id: 'bid_request_id', - imp: [ - { - id: 'imp_id_banner', - banner: { - format: [{ - w: 300, - h: 200 - }] - } - } - ], - site: { - page: 'https://ventesavenues.in', - domain: 'ventesavenues.in', - name: 'ventesavenues.in' - }, - device: { - ua: '', - ip: '123.145.167.189', - ifa: 'AEBE52E7-03EE-455A-B3C4-E57283966239', - language: 'en' - }, - user: null, - regs: null, - at: 1 - } - }, - serverResponse_banner: { - body: { - cur: 'USD', - seatbid: [ - { - seat: '4', - bid: [ - { - id: 'id', - impid: 'imp_id_banner', - cid: 'campaign_id', - crid: 'creative_id', - adm: '..', - price: 1.5, - w: 300, - h: 200 - } - ] - } - ] - } - } - }; - - describe('isBidRequestValid', function () { - describe('General', function () { - it('should return false when not given an ad unit', function () { - const adUnit = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an invalid ad unit', function () { - const adUnit = 'bad_bid'; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit without bidder code', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.bidder = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with a bad bidder code', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.bidder = 'unknownBidder'; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit without ad unit code', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.adUnitCode = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an invalid ad unit code', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.adUnitCode = {}; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit without bid request identifier', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.bidderRequestId = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an invalid bid request identifier', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.bidderRequestId = {}; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit without impression identifier', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.bidId = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an invalid impression identifier', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.bidId = {}; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit without media types', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with empty media types', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes = {}; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with invalid media types', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes = 'bad_media_types'; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - }); - - describe('Banner', function () { - it('should return true when given a valid ad unit', function () { - const adUnit = examples.adUnit_banner; - - expect(spec.isBidRequestValid(adUnit)).to.equal(true); - }); - - it('should return true when given a valid ad unit with invalid publisher id', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.params = {}; - adUnit.params.publisherId = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return true when given a valid ad unit without placement id', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.params = {}; - adUnit.params.publisherId = 'agltb3B1Yi1pbmNyDAsSA0FwcBiJkfTUCV'; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return true when given a valid ad unit with invalid placement id', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.params = {}; - adUnit.params.publisherId = 'agltb3B1Yi1pbmNyDAsSA0FwcBiJkfTUCV'; - adUnit.params.placementId = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit without size', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = undefined; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an invalid size', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = 'bad_banner_size'; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an empty size', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = []; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an invalid size value', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = ['bad_banner_size_value']; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with a size value with less than 2 dimensions', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = [[300]]; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with a size value with more than 2 dimensions', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = [[300, 250, 30]]; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with a negative width value', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = [[-300, 250]]; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with a negative height value', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = [[300, -250]]; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an invalid width value', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = [[false, 250]]; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - - it('should return false when given an ad unit with an invalid height value', function () { - const adUnit = utils.deepClone(examples.adUnit_banner); - adUnit.mediaTypes.banner.sizes = [[300, {}]]; - - expect(spec.isBidRequestValid(adUnit)).to.equal(false); - }); - }); - }); - - describe('buildRequests', function () { - describe('ServerRequest', function () { - it('should return a server request when given a valid ad unit and a valid ad unit context', function () { - const adUnits = [examples.adUnit_banner]; - const serverRequests = spec.buildRequests(adUnits, examples.adUnitContext); - expect(serverRequests).to.be.an('array').and.to.have.length(1); - expect(serverRequests[0].method).to.exist.and.to.be.a('string').and.to.equal('POST'); - expect(serverRequests[0].url).to.exist.and.to.be.a('string').and.to.equal(BIDDER_URL); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - }); - - it('should return an empty server request list when given an empty ad unit list and a valid ad unit context', function () { - const adUnits = []; - const serverRequests = spec.buildRequests(adUnits, examples.adUnitContext); - expect(serverRequests).to.be.an('array').and.to.have.length(0); - }); - - it('should not return a server request when given no ad unit and a valid ad unit context', function () { - const serverRequests = spec.buildRequests(null, examples.adUnitContext); - expect(serverRequests).to.equal(null); - }); - - it('should not return a server request when given a valid ad unit and no ad unit context', function () { - const adUnits = [examples.adUnit_banner]; - const serverRequests = spec.buildRequests(adUnits, null); - expect(serverRequests).to.be.an('array').and.to.have.length(1); - }); - - it('should not return a server request when given a valid ad unit and an invalid ad unit context', function () { - const adUnits = [examples.adUnit_banner]; - const serverRequests = spec.buildRequests(adUnits, {}); - expect(serverRequests).to.be.an('array').and.to.have.length(1); - }); - }); - - describe('BidRequest', function () { - it('should return a valid server request when given a valid ad unit', function () { - const adUnits = [examples.adUnit_banner]; - const serverRequests = spec.buildRequests(adUnits, examples.adUnitContext); - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data.id).to.exist.and.to.be.a('string').and.to.equal(adUnits[0].bidderRequestId); - expect(serverRequests[0].data.at).to.exist.and.to.be.a('number').and.to.equal(1); - }); - - it('should return one server request when given one valid ad unit', function () { - const adUnits = [examples.adUnit_banner]; - const serverRequests = spec.buildRequests(adUnits, examples.adUnitContext); - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data.id).to.exist.and.to.be.a('string').and.to.equal(adUnits[0].bidderRequestId); - }); - }); - - describe('Impression', function () { - describe('Banner', function () { - it('should return a server request with one impression when given a valid ad unit', function () { - const adUnits = [examples.adUnit_banner]; - - const serverRequests = spec.buildRequests(adUnits, examples.adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.imp).to.exist.and.to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data.imp[0]).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.imp[0].id).to.exist.and.to.be.a('string').and.to.equal(`${adUnits[0].bidId}`); - expect(serverRequests[0].data.imp[0].banner).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.imp[0].banner.w).to.exist.and.to.be.a('number').and.to.equal(adUnits[0].mediaTypes.banner.sizes[0][0]); - expect(serverRequests[0].data.imp[0].banner.h).to.exist.and.to.be.a('number').and.to.equal(adUnits[0].mediaTypes.banner.sizes[0][1]); - expect(serverRequests[0].data.imp[0].banner.format).to.exist.and.to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data.imp[0].banner.format[0]).to.exist.and.to.be.an('object').and.to.deep.equal({ - w: adUnits[0].mediaTypes.banner.sizes[0][0], - h: adUnits[0].mediaTypes.banner.sizes[0][1] - }); - }); - }); - }); - - describe('Site', function () { - it('should return a server request with site information when given a valid ad unit and a valid ad unit context', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = examples.adUnitContext; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - expect(serverRequests[0].data.site).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.site.page).to.exist.and.to.be.an('string').and.to.equal(adUnitContext.refererInfo.page); - expect(serverRequests[0].data.site.domain).to.exist.and.to.be.an('string').and.to.equal('ventesavenues.in'); - expect(serverRequests[0].data.site.name).to.exist.and.to.be.an('string').and.to.equal('ventesavenues.in'); - }); - - it('should return a server request without site information when given an ad unit context without referer information', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = utils.deepClone(examples.adUnitContext); - adUnitContext.refererInfo = undefined; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - }); - - it('should return a server request without site information when given an ad unit context with invalid referer information', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = utils.deepClone(examples.adUnitContext); - adUnitContext.refererInfo = 'bad_referer_information'; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - }); - - it('should return a server request without site information when given an ad unit context without referer', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = utils.deepClone(examples.adUnitContext); - adUnitContext.refererInfo.referer = undefined; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - }); - - it('should return a server request without site information when given an ad unit context with an invalid referer', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = utils.deepClone(examples.adUnitContext); - adUnitContext.refererInfo.referer = {}; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - }); - - it('should return a server request without site information when given an ad unit context with a misformatted referer', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = utils.deepClone(examples.adUnitContext); - adUnitContext.refererInfo.referer = 'we-are-adot'; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - }); - }); - - describe('Device', function () { - it('should return a server request with device information when given a valid ad unit and a valid ad unit context', function () { - const adUnits = [examples.adUnit_banner]; - - const serverRequests = spec.buildRequests(adUnits, examples.adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - expect(serverRequests[0].data.device).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.device.ua).to.exist.and.to.be.a('string'); - expect(serverRequests[0].data.device.language).to.exist.and.to.be.a('string'); - }); - }); - - describe('User', function () { - it('should return a server request with user information when given a valid ad unit and a valid ad unit context', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = examples.adUnitContext; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - expect(serverRequests[0].data.user).to.exist.and.to.be.an('object'); - }); - - it('should return a server request without user information when not given an ad unit context', function () { - const adUnits = [examples.adUnit_banner]; - - const adUnitContext = undefined; - - const serverRequests = spec.buildRequests(adUnits, adUnitContext); - - expect(serverRequests).to.be.an('array').and.to.have.lengthOf(1); - expect(serverRequests[0].data).to.exist.and.to.be.an('object'); - expect(serverRequests[0].data.id).to.exist.and.to.be.an('string').and.to.equal(adUnits[0].bidderRequestId); - }); - }); - }); - - describe('interpretResponse', function () { - describe('General', function () { - it('should return an ad when given a valid server response with one bid with USD currency', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.cur = 'USD'; - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(1); - expect(ads[0].creativeId).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.seatbid[0].bid[0].crid); - expect(ads[0].cpm).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].price); - expect(ads[0].currency).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.cur); - expect(ads[0].netRevenue).to.exist.and.to.be.a('boolean').and.to.equal(true); - expect(ads[0].ttl).to.exist.and.to.be.a('number').and.to.equal(10); - expect(ads[0].height).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].h); - expect(ads[0].width).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].w); - expect(ads[0].mediaType).to.exist.and.to.be.a('string').and.to.equal('banner'); - }); - - it('should return no ad when not given a server response', function () { - const ads = spec.interpretResponse(null); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when not given a server response body', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given an invalid server response body', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body = 'invalid_body'; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response without seat bids', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with invalid seat bids', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid = 'invalid_seat_bids'; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with an empty seat bids array', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid = []; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with an invalid seat bid', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid = 'invalid_bids'; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with an empty bids array', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid = []; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with an invalid bid', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid = ['invalid_bid']; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid without currency', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.cur = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid with an invalid currency', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.cur = {}; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid without impression identifier', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].impid = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid with an invalid impression identifier', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].impid = {}; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid without creative identifier', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].crid = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid with an invalid creative identifier', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].crid = {}; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid without ad markup and ad serving URL', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].adm = undefined; - serverResponse.body.seatbid[0].bid[0].nurl = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid with an invalid ad markup', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].adm = {}; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid without bid price', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].price = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid with an invalid bid price', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].price = {}; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a valid server response and no server request', function () { - const serverRequest = undefined; - - const serverResponse = examples.serverResponse_banner; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a valid server response and an invalid server request', function () { - const serverRequest = 'bad_server_request'; - - const serverResponse = examples.serverResponse_banner; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a valid server response and a server request without bid request', function () { - const serverRequest = utils.deepClone(examples.serverRequest_banner); - serverRequest.data = undefined; - - const serverResponse = examples.serverResponse_banner; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a valid server response and a server request with an invalid bid request', function () { - const serverRequest = utils.deepClone(examples.serverRequest_banner); - serverRequest.data = 'bad_bid_request'; - - const serverResponse = examples.serverResponse_banner; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a valid server response and a server request without impression', function () { - const serverRequest = utils.deepClone(examples.serverRequest_banner); - serverRequest.data.imp = undefined; - - const serverResponse = examples.serverResponse_banner; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a valid server response and a server request with an invalid impression field', function () { - const serverRequest = utils.deepClone(examples.serverRequest_banner); - serverRequest.data.imp = 'invalid_impressions'; - - const serverResponse = examples.serverResponse_banner; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - }); - - describe('Banner', function () { - it('should return an ad when given a valid server response with one bid', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = examples.serverResponse_banner; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(1); - expect(ads[0].adUrl).to.equal(null); - expect(ads[0].creativeId).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.seatbid[0].bid[0].crid); - expect(ads[0].cpm).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].price); - expect(ads[0].currency).to.exist.and.to.be.a('string').and.to.equal(serverResponse.body.cur); - expect(ads[0].netRevenue).to.exist.and.to.be.a('boolean').and.to.equal(true); - expect(ads[0].ttl).to.exist.and.to.be.a('number').and.to.equal(10); - expect(ads[0].height).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].h); - expect(ads[0].width).to.exist.and.to.be.a('number').and.to.equal(serverResponse.body.seatbid[0].bid[0].w); - expect(ads[0].mediaType).to.exist.and.to.be.a('string').and.to.equal('banner'); - }); - - it('should return no ad when given a server response with a bid without height', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].h = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid with an invalid height', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].h = {}; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid without width', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].w = undefined; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - - it('should return no ad when given a server response with a bid with an invalid width', function () { - const serverRequest = examples.serverRequest_banner; - - const serverResponse = utils.deepClone(examples.serverResponse_banner); - serverResponse.body.seatbid[0].bid[0].w = {}; - - const ads = spec.interpretResponse(serverResponse, serverRequest); - - expect(ads).to.be.an('array').and.to.have.length(0); - }); - }); - }); -}); diff --git a/test/spec/modules/viantBidAdapter_spec.js b/test/spec/modules/viantBidAdapter_spec.js deleted file mode 100644 index 46717e151..000000000 --- a/test/spec/modules/viantBidAdapter_spec.js +++ /dev/null @@ -1,557 +0,0 @@ -import {spec, converter} from 'modules/viantBidAdapter.js'; -import {assert, expect} from 'chai'; -import {deepClone} from '../../../src/utils.js'; -import {buildWindowTree} from '../../helpers/refererDetectionHelper.js'; -import {detectReferer} from '../../../src/refererDetection.js'; - -describe('viantOrtbBidAdapter', function () { - function testBuildRequests(bidRequests, bidderRequestBase) { - const clonedBidderRequest = deepClone(bidderRequestBase); - clonedBidderRequest.bids = bidRequests; - const requests = spec.buildRequests(bidRequests, clonedBidderRequest); - return requests - } - - describe('isBidRequestValid', function () { - function makeBid() { - return { - 'bidder': 'viant', - 'params': { - 'publisherId': '464', - 'placementId': 'some-PlacementId_1' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [728, 90] - ] - } - }, - 'adUnitCode': 'adunit-code', - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - }; - } - - describe('core', function () { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(makeBid())).to.equal(true); - }); - - it('should return false when publisherId not passed', function () { - const bid = makeBid(); - delete bid.params.publisherId; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return true if placementId is not passed ', function () { - const bid = makeBid(); - delete bid.params.placementId; - bid.ortb2Imp = {} - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false if mediaTypes.banner is Not passed', function () { - const bid = makeBid(); - delete bid.mediaTypes - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('banner', function () { - it('should return true if banner.pos is passed correctly', function () { - const bid = makeBid(); - bid.mediaTypes.banner.pos = 1; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - }); - - describe('video', function () { - describe('and request config uses mediaTypes', () => { - function makeBid() { - return { - 'bidder': 'viant', - 'params': { - 'unit': '12345678', - 'delDomain': 'test-del-domain', - 'publisherId': '464', - 'placementId': 'some-PlacementId_2' - }, - 'mediaTypes': { - 'video': { - 'context': 'instream', - 'playerSize': [[640, 480]], - 'mimes': ['video/mp4'], - 'protocols': [1, 2, 3, 4, 5, 6, 7, 8], - 'api': [1, 3], - 'skip': 1, - 'skipafter': 5, - 'minduration': 10, - 'maxduration': 30 - } - }, - 'adUnitCode': 'adunit-code', - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'transactionId': '4008d88a-8137-410b-aa35-fbfdabcb478e' - } - } - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(makeBid())).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const videoBidWithMediaTypes = Object.assign({}, makeBid()); - videoBidWithMediaTypes.params = {}; - expect(spec.isBidRequestValid(videoBidWithMediaTypes)).to.equal(false); - }); - }); - }); - - describe('native', function () { - describe('and request config uses mediaTypes', () => { - function makeBid() { - return { - 'bidder': 'viant', - 'params': { - 'unit': '12345678', - 'delDomain': 'test-del-domain', - 'publisherId': '464', - 'placementId': 'some-PlacementId_2' - }, - 'mediaTypes': { - 'video': { - 'context': 'instream', - 'playerSize': [[640, 480]], - 'mimes': ['video/mp4'], - 'protocols': [1, 2, 3, 4, 5, 6, 7, 8], - 'api': [1, 3], - 'skip': 1, - 'skipafter': 5, - 'minduration': 10, - 'maxduration': 30 - } - }, - 'adUnitCode': 'adunit-code', - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'transactionId': '4008d88a-8137-410b-aa35-fbfdabcb478e' - } - } - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(makeBid())).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const nativeBidWithMediaTypes = Object.assign({}, makeBid()); - nativeBidWithMediaTypes.params = {}; - expect(spec.isBidRequestValid(nativeBidWithMediaTypes)).to.equal(false); - }); - }); - }); - }); - - describe('buildRequests-banner', function () { - const baseBannerBidRequests = [{ - 'bidder': 'viant', - 'params': { - 'publisherId': '464', - 'placementId': '1' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[728, 90]] - } - }, - 'gdprConsent': { - 'consentString': 'consentString', - 'gdprApplies': true, - }, - 'uspConsent': '1YYY', - 'sizes': [[728, 90]], - 'transactionId': '1111474f-58b1-4368-b812-84f8c937a099', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'bidId': '243310435309b5', - 'bidderRequestId': '18084284054531', - 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'src': 'client', - 'bidRequestsCount': 1 - }]; - const basePMPDealsBidRequests = [{ - 'bidder': 'viant', - 'params': { - 'publisherId': '464', - 'placementId': '1' - }, - 'ortb2Imp': { - 'pmp': { - 'private_auction': 0, - 'deals': [ - { - 'id': '1234567', - 'at': 3, - 'bidfloor': 25, - 'bidfloorcur': 'USD', - 'ext': { - 'must_bid': 1, - 'private_auction': 1 - } - }, - { - 'id': '1234568', - 'at': 3, - 'bidfloor': 25, - 'bidfloorcur': 'USD', - 'ext': { - 'must_bid': 0 - } - } - ] - }, - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[728, 90]] - } - }, - 'gdprConsent': { - 'consentString': 'consentString', - 'gdprApplies': true, - }, - 'uspConsent': '1YYY', - 'sizes': [[728, 90]], - 'transactionId': '1111474f-58b1-4368-b812-84f8c937a099', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'bidId': '243310435309b5', - 'bidderRequestId': '18084284054531', - 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'src': 'client', - 'bidRequestsCount': 1 - }]; - - const testWindow = buildWindowTree(['https://www.example.com/test', 'https://www.example.com/other/page', 'https://www.example.com/third/page'], 'https://othersite.com/', 'https://example.com/canonical/page'); - const baseBidderRequestReferer = detectReferer(testWindow)(); - const baseBidderRequest = { - 'bidderCode': 'viant', - 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'bidderRequestId': '18084284054531', - 'auctionStart': 1540945362095, - 'timeout': 3000, - 'refererInfo': baseBidderRequestReferer, - 'start': 1540945362099, - 'doneCbCallCount': 0 - }; - - it('test regs', function () { - const gdprBaseBidderRequest = Object.assign({}, baseBidderRequest, { - gdprConsent: { - consentString: 'consentString', - gdprApplies: true, - }, - uspConsent: '1YYN' - }); - const request = testBuildRequests(baseBannerBidRequests, gdprBaseBidderRequest)[0]; - expect(request.data.regs.ext).to.have.property('gdpr', 1); - expect(request.data.regs.ext).to.have.property('us_privacy', '1YYN'); - }); - - it('sends bid request to our endpoint that makes sense', function () { - const request = testBuildRequests(baseBannerBidRequests, baseBidderRequest)[0]; - expect(request.method).to.equal('POST'); - expect(request.url).to.be.not.empty; - expect(request.data).to.be.not.null; - }); - it('sends bid requests to the correct endpoint', function () { - const url = testBuildRequests(baseBannerBidRequests, baseBidderRequest)[0].url; - expect(url).to.equal('https://bidders-us.adelphic.net/d/rtb/v25/prebid/bidder'); - }); - - it('sends site', function () { - const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest)[0].data; - expect(requestBody.site).to.be.not.null; - }); - - it('includes the ad size in the bid request', function () { - const requestBody = testBuildRequests(baseBannerBidRequests, baseBidderRequest)[0].data; - expect(requestBody.imp[0].banner.format[0].w).to.equal(728); - expect(requestBody.imp[0].banner.format[0].h).to.equal(90); - }); - - it('sets the banner pos correctly if sent', function () { - const clonedBannerRequests = deepClone(baseBannerBidRequests); - clonedBannerRequests[0].mediaTypes.banner.pos = 1; - - const requestBody = testBuildRequests(clonedBannerRequests, baseBidderRequest)[0].data; - expect(requestBody.imp[0].banner.pos).to.equal(1); - }); - it('includes the deals in the bid request', function () { - const requestBody = testBuildRequests(basePMPDealsBidRequests, baseBidderRequest)[0].data; - expect(requestBody.imp[0].pmp).to.be.not.null; - expect(requestBody.imp[0].pmp).to.deep.equal({ - 'private_auction': 0, - 'deals': [ - { - 'id': '1234567', - 'at': 3, - 'bidfloor': 25, - 'bidfloorcur': 'USD', - 'ext': { - 'must_bid': 1, - 'private_auction': 1 - } - }, - { - 'id': '1234568', - 'at': 3, - 'bidfloor': 25, - 'bidfloorcur': 'USD', - 'ext': { - 'must_bid': 0 - } - } - ] - }); - }); - }); - - if (FEATURES.VIDEO) { - describe('buildRequests-video', function () { - function makeBid() { - return { - 'bidder': 'viant', - 'params': { - 'unit': '12345678', - 'delDomain': 'test-del-domain', - 'publisherId': '464', - 'placementId': 'some-PlacementId_2' - }, - 'mediaTypes': { - 'video': { - 'context': 'instream', - 'playerSize': [[640, 480]], - 'mimes': ['video/mp4'], - 'protocols': [1, 2, 3, 4, 5, 6, 7, 8], - 'api': [1, 3], - 'skip': 1, - 'skipafter': 5, - 'minduration': 10, - 'placement': 1, - 'maxduration': 31 - } - }, - 'adUnitCode': 'adunit-code', - 'bidId': '30b31c1838de1e', - 'bidderRequestId': '22edbae2733bf6', - 'auctionId': '1d1a030790a475', - 'transactionId': '4008d88a-8137-410b-aa35-fbfdabcb478e' - } - } - - it('assert video and its fields is present in imp ', function () { - const requests = spec.buildRequests([makeBid()], {referrerInfo: {}}); - const clonedRequests = deepClone(requests) - assert.equal(clonedRequests[0].data.imp[0].video.mimes[0], 'video/mp4') - assert.equal(clonedRequests[0].data.imp[0].video.maxduration, 31) - assert.equal(clonedRequests[0].data.imp[0].video.placement, 1) - assert.equal(clonedRequests[0].method, 'POST') - }); - }); - } - - describe('interpretResponse', function () { - const baseBannerBidRequests = [{ - 'bidder': 'viant', - 'params': { - 'publisherId': '464', - 'placementId': '1' - }, - 'mediaTypes': { - 'banner': { - 'sizes': [[728, 90]] - } - }, - 'sizes': [[728, 90]], - 'transactionId': '1111474f-58b1-4368-b812-84f8c937a099', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'bidId': '243310435309b5', - 'bidderRequestId': '18084284054531', - 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'src': 'client', - 'bidRequestsCount': 1 - }]; - - const testWindow = buildWindowTree(['https://www.example.com/test', 'https://www.example.com/other/page', 'https://www.example.com/third/page'], 'https://othersite.com/', 'https://example.com/canonical/page'); - const baseBidderRequestReferer = detectReferer(testWindow)(); - const baseBidderRequest = { - 'bidderCode': 'viant', - 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'bidderRequestId': '18084284054531', - 'auctionStart': 1540945362095, - 'timeout': 3000, - 'refererInfo': baseBidderRequestReferer, - 'start': 1540945362099, - 'doneCbCallCount': 0 - }; - - it('empty bid response test', function () { - const request = testBuildRequests(baseBannerBidRequests, baseBidderRequest)[0]; - const bidResponse = {nbr: 0}; // Unknown error - const bids = spec.interpretResponse({body: bidResponse}, request); - expect(bids.length).to.equal(0); - }); - - it('bid response is a banner', function () { - const request = testBuildRequests(baseBannerBidRequests, baseBidderRequest)[0]; - const bidResponse = { - seatbid: [{ - bid: [{ - impid: '243310435309b5', - price: 2, - w: 728, - h: 90, - crid: 'test-creative-id', - dealid: 'test-deal-id', - adm: 'test-ad-markup', - }] - }], - cur: 'USD' - }; - const bids = spec.interpretResponse({body: bidResponse}, request); - expect(bids.length).to.equal(1); - const bid = bids[0]; - it('should return the proper mediaType', function () { - it('should return a creativeId', function () { - expect(bid.mediaType).to.equal('banner'); - }); - }); - it('should return a price', function () { - expect(bid.cpm).to.equal(bidResponse.seatbid[0].bid[0].price); - }); - - it('should return a request id', function () { - expect(bid.requestId).to.equal(bidResponse.seatbid[0].bid[0].impid); - }); - - it('should return width and height for the creative', function () { - expect(bid.width).to.equal(bidResponse.seatbid[0].bid[0].w); - expect(bid.height).to.equal(bidResponse.seatbid[0].bid[0].h); - }); - it('should return a creativeId', function () { - expect(bid.creativeId).to.equal(bidResponse.seatbid[0].bid[0].crid); - }); - it('should return an ad', function () { - expect(bid.ad).to.equal(bidResponse.seatbid[0].bid[0].adm); - }); - - it('should return a deal id if it exists', function () { - expect(bid.dealId).to.equal(bidResponse.seatbid[0].bid[0].dealid); - }); - - it('should have a time-to-live of 5 minutes', function () { - expect(bid.ttl).to.equal(300); - }); - - it('should always return net revenue', function () { - expect(bid.netRevenue).to.equal(true); - }); - it('should return a currency', function () { - expect(bid.currency).to.equal(bidResponse.cur); - }); - }); - }); - describe('interpretResponse-Video', function () { - const baseVideoBidRequests = [{ - 'bidder': 'viant', - 'params': { - 'publisherId': '464', - 'placementId': '1' - }, - 'mediaTypes': { - 'video': { - 'context': 'instream', - 'playerSize': [[640, 480]], - 'mimes': ['video/mp4'], - 'protocols': [1, 2, 3, 4, 5, 6, 7, 8], - 'api': [1, 3], - 'skip': 1, - 'skipafter': 5, - 'minduration': 10, - 'maxduration': 31 - } - }, - 'sizes': [[640, 480]], - 'transactionId': '1111474f-58b1-4368-b812-84f8c937a099', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'bidId': '243310435309b5', - 'bidderRequestId': '18084284054531', - 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'src': 'client', - 'bidRequestsCount': 1 - }]; - - const testWindow = buildWindowTree(['https://www.example.com/test', 'https://www.example.com/other/page', 'https://www.example.com/third/page'], 'https://othersite.com/', 'https://example.com/canonical/page'); - const baseBidderRequestReferer = detectReferer(testWindow)(); - const baseBidderRequest = { - 'bidderCode': 'viant', - 'auctionId': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'bidderRequestId': '18084284054531', - 'auctionStart': 1540945362095, - 'timeout': 3000, - 'refererInfo': baseBidderRequestReferer, - 'start': 1540945362099, - 'doneCbCallCount': 0 - }; - - it('bid response is a video', function () { - const request = testBuildRequests(baseVideoBidRequests, baseBidderRequest)[0]; - const VIDEO_BID_RESPONSE = { - 'id': 'bidderRequestId', - 'bidid': 'e7b34fa3-8654-424e-8c49-03e509e53d8c', - 'seatbid': [ - { - 'bid': [ - { - 'id': '1', - 'impid': '243310435309b5', - 'price': 1.09, - 'adid': '144762342', - 'nurl': 'http://0.0.0.0:8181/nurl', - 'adm': '', - 'adomain': [ - 'https://dummydomain.com' - ], - 'cid': 'cid', - 'crid': 'crid', - 'iurl': 'iurl', - 'cat': [], - 'h': 480, - 'w': 640 - } - ] - } - ], - 'cur': 'USD' - }; - const bids = spec.interpretResponse({body: VIDEO_BID_RESPONSE}, request); - expect(bids.length).to.equal(1); - const bid = bids[0]; - it('should return the proper mediaType', function () { - expect(bid.mediaType).to.equal('video'); - }); - it('should return correct Ad Markup', function () { - expect(bid.vastXml).to.equal(''); - }); - it('should return correct Notification', function () { - expect(bid.vastUrl).to.equal('http://0.0.0.0:8181/nurl'); - }); - it('should return correct Cpm', function () { - expect(bid.cpm).to.equal(1.09); - }); - }); - }); -}); diff --git a/test/spec/modules/vibrantmediaBidAdapter_spec.js b/test/spec/modules/vibrantmediaBidAdapter_spec.js deleted file mode 100644 index 6aaa84a00..000000000 --- a/test/spec/modules/vibrantmediaBidAdapter_spec.js +++ /dev/null @@ -1,1227 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/vibrantmediaBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; -import {BANNER, NATIVE, VIDEO} from 'src/mediaTypes.js'; -import {INSTREAM, OUTSTREAM} from 'src/video.js'; -import { getWinDimensions } from '../../../src/utils.js'; - -const EXPECTED_PREBID_SERVER_URL = 'https://prebid.intellitxt.com/prebid'; - -const BANNER_AD = - 'Test Banner Ad UnitHello!'; -const VIDEO_AD = 'Test Video Ad Unit' + - ''; - -const VALID_BANNER_BID_PARAMS = Object.freeze({ - member: '1234', - invCode: 'ABCD', - placementId: '10433394' -}); - -const VALID_VIDEO_BID_PARAMS = Object.freeze({ - member: '1234', - invCode: 'ABCD', - placementId: '10433394', - video: { - skippable: false, - playback_method: 'auto_play_sound_off' - } -}); - -const VALID_NATIVE_BID_PARAMS = VALID_BANNER_BID_PARAMS; - -const DEFAULT_BID_SIZES = [[300, 250], [600, 240]]; - -const VALID_CONSENT_STRING = 'BOJ8RZsOJ8RZsABAB8AAAAAZ+A=='; - -const getValidBidderRequest = (bidRequests) => { - return Object.freeze({ - bidderCode: 'vibrantmedia', - auctionId: '1d1a030790a475', - bidderRequestId: '22edbae2733bf6', - timeout: 3000, - gdprConsent: { - consentString: VALID_CONSENT_STRING, - vendorData: {}, - gdprApplies: true, - }, - bids: bidRequests, - }); -}; - -describe('VibrantMediaBidAdapter', function () { - const adapter = newBidder(spec); - - describe('constants', function () { - expect(spec.code).to.equal('vibrantmedia'); - expect(spec.supportedMediaTypes).to.deep.equal([BANNER, NATIVE, VIDEO]); - }); - - describe('inherited functions', function () { - it('exists and is a function', function () { - expect(adapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - let bidRequest; - - beforeEach(function () { - bidRequest = { - bidder: 'vibrantmedia', - params: { - // Filled in by individual tests - }, - mediaTypes: { - // Filled in by individual tests - }, - adUnitCode: 'test-div', - transactionId: '13579acef87623', - placementId: '7623587623857', - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475' - }; - }); - - describe('isBidRequestValid', function () { - describe('with banner bid requests', function () { - beforeEach(function () { - bidRequest.mediaTypes.banner = { - sizes: DEFAULT_BID_SIZES, - }; - }); - - it('should return true for a valid banner bid request', function () { - bidRequest.params = VALID_BANNER_BID_PARAMS; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true for a valid banner bid request with a member id and inventory code', function () { - bidRequest.params = { - member: '1234', - invCode: 'ABCD', - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true for a valid banner bid request with a placement id', function () { - bidRequest.params = { - placementId: '10433394', - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false for a valid banner bid request but with a member id and no inventory code', function () { - bidRequest.params = { - member: '1234', - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false for a valid banner bid request but with no member id and an inventory code', function () { - bidRequest.params = { - invCode: 'ABCD', - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false for a valid banner bid request but with no supported media types', function () { - bidRequest.params = { - placementId: '10433394', - }; - delete bidRequest.mediaTypes.banner; - bidRequest.mediaTypes.unsupported = { - sizes: DEFAULT_BID_SIZES, - } - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false for a valid banner bid request but with no params', function () { - bidRequest.params = {}; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); - - describe('with video bid requests', function () { - describe('with sizes attribute', function () { - const validVideoMediaTypes = { - context: OUTSTREAM, - sizes: DEFAULT_BID_SIZES, - minduration: 1, - maxduration: 60, - skip: 0, - skipafter: 5, - playbackmethod: [2], - protocols: [1, 2, 3] - }; - - it('should return true for a valid video bid request', function () { - bidRequest.params = VALID_VIDEO_BID_PARAMS; - bidRequest.mediaTypes.video = validVideoMediaTypes; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false for an instream video bid request', function () { - bidRequest.params = VALID_VIDEO_BID_PARAMS; - bidRequest.mediaTypes.video = { - context: INSTREAM, - sizes: DEFAULT_BID_SIZES, - }; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false for a video bid request with an unknown context', function () { - bidRequest.params = VALID_VIDEO_BID_PARAMS; - bidRequest.mediaTypes.video = { - context: 'fake', - sizes: DEFAULT_BID_SIZES, - }; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false for a video bid request with no context', function () { - bidRequest.params = VALID_VIDEO_BID_PARAMS; - bidRequest.mediaTypes.video = { - sizes: DEFAULT_BID_SIZES, - }; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return true for a valid video bid request with a member id and inventory code', function () { - bidRequest.params = { - member: '1234', - invCode: 'ABCD', - }; - bidRequest.mediaTypes.video = validVideoMediaTypes; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true for a valid video bid request with a placement id', function () { - bidRequest.params = { - placementId: '10433394', - }; - bidRequest.mediaTypes.video = validVideoMediaTypes; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false for a valid video bid request but with a member id and no inventory code', function () { - bidRequest.params = { - member: '1234', - }; - bidRequest.mediaTypes.video = validVideoMediaTypes; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false for a valid video bid request but with no member id and an inventory code', function () { - bidRequest.params = { - invCode: 'ABCD', - }; - bidRequest.mediaTypes.video = validVideoMediaTypes; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false for a valid video bid request but with no params', function () { - bidRequest.params = {}; - bidRequest.mediaTypes.video = validVideoMediaTypes; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); - - describe('with playerSize attribute', function () { - const validVideoMediaTypes = { - context: OUTSTREAM, - playerSize: DEFAULT_BID_SIZES, - minduration: 1, - maxduration: 60, - skip: 0, - skipafter: 5, - playbackmethod: [2], - protocols: [1, 2, 3] - }; - - beforeEach(function () { - bidRequest.mediaTypes.video = { - // Filled in by individual tests - }; - }); - - it('should return true for a valid video bid request', function () { - bidRequest.params = VALID_VIDEO_BID_PARAMS; - bidRequest.mediaTypes.video = validVideoMediaTypes; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false for an instream video bid request', function () { - bidRequest.params = VALID_VIDEO_BID_PARAMS; - bidRequest.mediaTypes.video = { - context: INSTREAM, - playerSize: DEFAULT_BID_SIZES, - }; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false for a video bid request with an unknown context', function () { - bidRequest.params = VALID_VIDEO_BID_PARAMS; - bidRequest.mediaTypes.video = { - context: 'fake', - playerSize: DEFAULT_BID_SIZES, - }; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false for a video bid request with no context', function () { - bidRequest.params = VALID_VIDEO_BID_PARAMS; - bidRequest.mediaTypes.video = { - playerSize: DEFAULT_BID_SIZES, - }; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return true for a valid video bid request with a member id and inventory code', function () { - bidRequest.params = { - member: '1234', - invCode: 'ABCD', - }; - bidRequest.mediaTypes.video = validVideoMediaTypes; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true for a valid video bid request with a placement id', function () { - bidRequest.params = { - placementId: '10433394', - }; - bidRequest.mediaTypes.video = validVideoMediaTypes; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false for a valid video bid request but with a member id and no inventory code', function () { - bidRequest.params = { - member: '1234', - }; - bidRequest.mediaTypes.video = validVideoMediaTypes; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false for a valid video bid request but with no member id and an inventory code', function () { - bidRequest.params = { - invCode: 'ABCD', - }; - bidRequest.mediaTypes.video = validVideoMediaTypes; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false for a valid video bid request but with no params', function () { - bidRequest.params = {}; - bidRequest.mediaTypes.video = validVideoMediaTypes; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); - }); - - describe('with native bid requests', function () { - beforeEach(function () { - bidRequest.mediaTypes.native = { - image: { - required: true, - // Sizes is filled in by individual tests - }, - title: { - required: true - }, - sponsoredBy: { - required: true - }, - clickUrl: { - required: true - } - }; - }); - - it('should return true for a valid native bid request with a single size', function () { - bidRequest.params = VALID_NATIVE_BID_PARAMS; - bidRequest.mediaTypes.native.image.sizes = [300, 250]; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true for a valid native bid request with multiple sizes', function () { - bidRequest.params = VALID_NATIVE_BID_PARAMS; - bidRequest.mediaTypes.native.image.sizes = [[300, 250], [300, 600]]; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true for a valid native bid request with a member id and inventory code', function () { - bidRequest.params = { - member: '1234', - invCode: 'ABCD', - }; - bidRequest.mediaTypes.native.image.sizes = [300, 250]; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true for a valid native bid request with a placement id', function () { - bidRequest.params = { - placementId: '10433394', - }; - bidRequest.mediaTypes.native.image.sizes = [300, 250]; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false for a valid native bid request but with a member id and no inventory code', function () { - bidRequest.params = { - member: '1234', - }; - bidRequest.mediaTypes.native.image.sizes = [300, 250]; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false for a valid native bid request but with no member id and an inventory code', function () { - bidRequest.params = { - invCode: 'ABCD', - }; - bidRequest.mediaTypes.native.image.sizes = [300, 250]; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false for a valid native bid request but with no params', function () { - bidRequest.params = {}; - bidRequest.mediaTypes.native.image.sizes = [300, 250]; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false for a native bid request with no image property', function () { - bidRequest.params = VALID_NATIVE_BID_PARAMS; - delete bidRequest.mediaTypes.native.image; - - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); - }); - - describe('buildRequests', function () { - let bidRequests; - - beforeEach(function () { - bidRequests = [bidRequest]; - - bidRequests[0].params = VALID_BANNER_BID_PARAMS; - bidRequests[0].mediaTypes.banner = { - sizes: DEFAULT_BID_SIZES, - }; - }); - - it('should use HTTP POST', function () { - const request = spec.buildRequests(bidRequests, {}); - expect(request.method).to.equal('POST'); - }); - - it('should use the correct prebid server URL', function () { - const request = spec.buildRequests(bidRequests, {}); - expect(request.url).to.equal(EXPECTED_PREBID_SERVER_URL); - }); - - it('should add the page URL to the server request', function () { - const request = spec.buildRequests(bidRequests, {}); - const payload = JSON.parse(request.data); - - expect(payload.url).to.exist; - expect(payload.url).to.be.a('string'); - }); - - it('should add GDPR consent to the server request, where present', function () { - const bidderRequest = { - bidderCode: 'vibrantmedia', - auctionId: '1d1a030790a475', - bidderRequestId: '22edbae2733bf6', - timeout: 3000, - gdprConsent: { - consentString: VALID_CONSENT_STRING, - gdprApplies: true, - }, - bids: bidRequests, - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - // TODO: Check that we should not be implementing withCredentials - // expect(request.options).to.deep.equal({withCredentials: true}); - - const payload = JSON.parse(request.data); - expect(payload.gdpr).to.exist; - expect(payload.gdpr.consentString).to.exist.and.to.equal(VALID_CONSENT_STRING); - expect(payload.gdpr.gdprApplies).to.exist.and.to.be.true; - }); - - it('should add USP consent to the server request, where present', function () { - const bidderRequest = { - bidderCode: 'vibrantmedia', - auctionId: '1d1a030790a475', - bidderRequestId: '22edbae2733bf6', - timeout: 3000, - uspConsent: { - cmpApi: 'iab', - timeout: 10000, - consentData: { - testDatum: true - } - }, - bids: bidRequests - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - // TODO: Check that we should not be implementing withCredentials - // expect(request.options).to.deep.equal({withCredentials: true}); - - const payload = JSON.parse(request.data); - expect(payload.usp).to.exist; - expect(payload.usp.cmpApi).to.exist.and.to.equal('iab'); - expect(payload.usp.timeout).to.exist.and.to.equal(10000); - expect(payload.usp.consentData).to.exist.and.to.deep.equal({ - testDatum: true - }); - }); - - it('should add GDPR and USP consent to the server request, where both present', function () { - const bidderRequest = { - bidderCode: 'vibrantmedia', - auctionId: '1d1a030790a475', - bidderRequestId: '22edbae2733bf6', - timeout: 3000, - gdprConsent: { - consentString: VALID_CONSENT_STRING, - gdprApplies: true, - }, - uspConsent: { - cmpApi: 'iab', - timeout: 10000, - consentData: { - testDatum: true - } - }, - bids: bidRequests, - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - // TODO: Check that we should not be implementing withCredentials - // expect(request.options).to.deep.equal({withCredentials: true}); - - const payload = JSON.parse(request.data); - - expect(payload.gdpr).to.exist; - expect(payload.gdpr.consentString).to.exist.and.to.equal(VALID_CONSENT_STRING); - expect(payload.gdpr.gdprApplies).to.exist.and.to.be.true; - - expect(payload.usp).to.exist; - expect(payload.usp.cmpApi).to.exist.and.to.equal('iab'); - expect(payload.usp.timeout).to.exist.and.to.equal(10000); - expect(payload.usp.consentData).to.exist.and.to.deep.equal({ - testDatum: true - }); - }); - - it('should add window dimensions to the server request', function () { - const request = spec.buildRequests(bidRequests, {}); - const payload = JSON.parse(request.data); - - expect(payload.window).to.exist; - expect(payload.window.width).to.equal(getWinDimensions().innerWidth); - expect(payload.window.height).to.equal(getWinDimensions().innerHeight); - }); - - it('should add the top-level sizes to the bid request, if present', function () { - bidRequest.params = VALID_BANNER_BID_PARAMS; - bidRequest.sizes = DEFAULT_BID_SIZES; - bidRequest.mediaTypes = { - banner: {}, - }; - - const request = spec.buildRequests(bidRequests, {}, true); - const payload = JSON.parse(request.data); - - expect(payload.biddata).to.exist; - expect(payload.biddata.length).to.equal(1); - expect(payload.biddata[0]).to.exist; - expect(payload.biddata[0].code).to.equal(bidRequest.adUnitCode); - expect(payload.biddata[0].id).to.equal(bidRequest.placementId); - expect(payload.biddata[0].bidder).to.equal(bidRequest.bidder); - expect(payload.biddata[0].sizes).to.deep.equal(DEFAULT_BID_SIZES); - expect(payload.biddata[0].mediaTypes).to.exist; - expect(payload.biddata[0].mediaTypes[BANNER]).to.exist; - expect(payload.biddata[0].mediaTypes[BANNER]).to.deep.equal({}); - }); - - it('should add the list of bids to the bid request, if present', function () { - const testBid = { - bidder: 'testBidder', - params: { - placement: '12345' - } - }; - - bidRequest.params = VALID_BANNER_BID_PARAMS; - bidRequest.bids = [testBid]; - bidRequest.mediaTypes = { - banner: {}, - }; - - // These will be present in the list of bids instead - delete bidRequest.bidId; - delete bidRequest.transactionId; - delete bidRequest.bidder; - - const request = spec.buildRequests(bidRequests, {}, true); - const payload = JSON.parse(request.data); - - expect(payload.biddata).to.exist; - expect(payload.biddata.length).to.equal(1); - expect(payload.biddata[0]).to.exist; - expect(payload.biddata[0].code).to.equal(bidRequest.adUnitCode); - expect(payload.biddata[0].id).to.equal(bidRequest.placementId); - expect(payload.biddata[0].bidder).to.equal(bidRequest.bidder); - expect(payload.biddata[0].bids.length).to.equal(1); - expect(payload.biddata[0].bids[0]).to.deep.equal(testBid); - expect(payload.biddata[0].mediaTypes).to.exist; - expect(payload.biddata[0].mediaTypes[BANNER]).to.exist; - expect(payload.biddata[0].mediaTypes[BANNER]).to.deep.equal({}); - }); - - it('should add the correct bid data to the server request for one bid request', function () { - bidRequest.params = VALID_BANNER_BID_PARAMS; - bidRequest.mediaTypes = { - banner: { - sizes: DEFAULT_BID_SIZES, - }, - }; - - const request = spec.buildRequests(bidRequests, {}, true); - const payload = JSON.parse(request.data); - - expect(payload.biddata).to.exist; - expect(payload.biddata.length).to.equal(1); - expect(payload.biddata[0]).to.exist; - expect(payload.biddata[0].code).to.equal(bidRequest.adUnitCode); - expect(payload.biddata[0].id).to.equal(bidRequest.placementId); - expect(payload.biddata[0].bidder).to.equal(bidRequest.bidder); - expect(payload.biddata[0].sizes).to.be.undefined; - expect(payload.biddata[0].mediaTypes).to.exist; - expect(payload.biddata[0].mediaTypes[BANNER]).to.exist; - expect(payload.biddata[0].mediaTypes[BANNER]).to.deep.equal({ - sizes: DEFAULT_BID_SIZES, - }); - }); - - it('should add the correct bid data to the server request for multiple bid requests', function () { - bidRequest.params = VALID_BANNER_BID_PARAMS; - bidRequest.mediaTypes = { - banner: { - sizes: DEFAULT_BID_SIZES, - }, - }; - const bid2 = { - bidder: 'vibrantmedia', - params: VALID_VIDEO_BID_PARAMS, - mediaTypes: { - video: { - context: OUTSTREAM, - sizes: DEFAULT_BID_SIZES, - } - }, - adUnitCode: 'video-div', - bidId: '30b31c1838de1f', - placementId: '135797531abcdef', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - }; - const bid3 = { - bidder: 'vibrantmedia', - params: VALID_NATIVE_BID_PARAMS, - mediaTypes: { - native: { - image: { - required: true, - sizes: [300, 250] - }, - title: { - required: true - }, - sponsoredBy: { - required: true - }, - clickUrl: { - required: true - } - } - }, - adUnitCode: 'native-div', - bidId: '30b31c1838de14', - placementId: '918273645abcdef', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - }; - - bidRequests.push(bid2, bid3); - - const request = spec.buildRequests(bidRequests, {}, true); - const payload = JSON.parse(request.data); - - expect(payload.biddata).to.exist; - expect(payload.biddata.length).to.equal(3); - expect(payload.biddata[0]).to.exist; - expect(payload.biddata[0].code).to.equal(bidRequest.adUnitCode); - expect(payload.biddata[0].id).to.equal(bidRequest.placementId); - expect(payload.biddata[0].bidder).to.equal(bidRequest.bidder); - expect(payload.biddata[0].mediaTypes).to.exist; - expect(payload.biddata[0].mediaTypes[BANNER]).to.exist; - expect(payload.biddata[0].mediaTypes[BANNER]).to.deep.equal({ - sizes: DEFAULT_BID_SIZES, - }); - expect(payload.biddata[1]).to.exist; - expect(payload.biddata[1].code).to.equal(bid2.adUnitCode); - expect(payload.biddata[1].id).to.equal(bid2.placementId); - expect(payload.biddata[1].bidder).to.equal(bid2.bidder); - expect(payload.biddata[1].mediaTypes).to.exist; - expect(payload.biddata[1].mediaTypes[VIDEO]).to.exist; - expect(payload.biddata[1].mediaTypes[VIDEO]).to.deep.equal({ - context: OUTSTREAM, - sizes: DEFAULT_BID_SIZES, - }); - expect(payload.biddata[2]).to.exist; - expect(payload.biddata[2].code).to.equal(bid3.adUnitCode); - expect(payload.biddata[2].id).to.equal(bid3.placementId); - expect(payload.biddata[2].bidder).to.equal(bid3.bidder); - expect(payload.biddata[2].mediaTypes[NATIVE]).to.exist; - expect(payload.biddata[2].mediaTypes[NATIVE]).to.deep.equal(bid3.mediaTypes.native); - }); - - it('should add the correct bid data to the bid request where a bid has multiple media types', function () { - bidRequest.params = VALID_VIDEO_BID_PARAMS; - bidRequest.mediaTypes = { - banner: { - sizes: DEFAULT_BID_SIZES, - }, - video: { - context: OUTSTREAM, - sizes: DEFAULT_BID_SIZES, - }, - native: { - image: { - required: true, - sizes: [300, 250] - }, - title: { - required: true - }, - sponsoredBy: { - required: true - }, - clickUrl: { - required: true - } - } - }; - bidRequest.adUnitCode = 'mixed-div'; - - const bid2 = { - bidder: 'vibrantmedia', - params: VALID_VIDEO_BID_PARAMS, - mediaTypes: { - video: { - context: OUTSTREAM, - sizes: DEFAULT_BID_SIZES, - } - }, - adUnitCode: 'video-div', - bidId: '30b31c1838de1a', - bidderRequestId: '22edbae2733bf6', - placementId: '293857832abfef', - auctionId: '1d1a030790a475', - }; - - bidRequests.push(bid2); - - const request = spec.buildRequests(bidRequests, {}, true); - const payload = JSON.parse(request.data); - - expect(payload.biddata).to.exist; - expect(payload.biddata.length).to.equal(2); - expect(payload.biddata[0]).to.exist; - expect(payload.biddata[0].code).to.equal(bidRequest.adUnitCode); - expect(payload.biddata[0].id).to.equal(bidRequest.placementId); - expect(payload.biddata[0].bidder).to.equal(bidRequest.bidder); - expect(payload.biddata[0].mediaTypes).to.exist; - expect(Object.keys(payload.biddata[0].mediaTypes).length).to.equal(3); - expect(payload.biddata[0].mediaTypes[BANNER]).to.exist; - expect(payload.biddata[0].mediaTypes[BANNER]).to.deep.equal({ - sizes: DEFAULT_BID_SIZES, - }); - expect(payload.biddata[0].mediaTypes[VIDEO]).to.exist; - expect(payload.biddata[0].mediaTypes[VIDEO]).to.deep.equal({ - context: OUTSTREAM, - sizes: DEFAULT_BID_SIZES, - }); - expect(payload.biddata[0].code).to.equal(bidRequest.adUnitCode); - expect(payload.biddata[0].id).to.equal(bidRequest.placementId); - expect(payload.biddata[0].bidder).to.equal(bidRequest.bidder); - expect(payload.biddata[0].mediaTypes[NATIVE]).to.exist; - expect(payload.biddata[0].mediaTypes[NATIVE]).to.deep.equal(bidRequest.mediaTypes.native); - expect(payload.biddata[1]).to.exist; - expect(payload.biddata[1].code).to.equal(bid2.adUnitCode); - expect(payload.biddata[1].id).to.equal(bid2.placementId); - expect(payload.biddata[1].bidder).to.equal(bid2.bidder); - expect(payload.biddata[1].mediaTypes).to.exist; - expect(Object.keys(payload.biddata[1].mediaTypes).length).to.equal(1); - expect(payload.biddata[1].mediaTypes[VIDEO]).to.exist; - expect(payload.biddata[1].mediaTypes[VIDEO]).to.deep.equal({ - context: OUTSTREAM, - sizes: DEFAULT_BID_SIZES, - }); - }); - }); - - describe('interpretResponse', function () { - it('returns a valid Prebid API response object for a banner Prebid Server response', function () { - const prebidServerResponse = { - body: [{ - mediaType: 'banner', - requestId: '12345', - cpm: 1, - currency: 'USD', - width: 640, - height: 240, - ad: BANNER_AD, - ttl: 300, - creativeId: '86f4aef9-2f17-421d-84db-5c9814bf4a79', - netRevenue: false, - meta: Object.freeze({ - advertiser: '105600', - width: 300, - height: 250, - isCustom: '1', - progressBar: false, - mpuSrc: '//images.intellitxt.com/a/105600/Genpact/genpact.jpg', - clickURL: '{{click}}' - }) - }] - }; - - const interpretedResponse = spec.interpretResponse(prebidServerResponse, {}); - - expect(interpretedResponse).to.be.a('array'); - expect(interpretedResponse.length).to.equal(1); - - const interpretedBid = interpretedResponse[0]; - - expect(interpretedBid.mediaType).to.equal('banner'); - expect(interpretedBid.requestId).to.equal('12345'); - expect(interpretedBid.cpm).to.equal(1); - expect(interpretedBid.currency).to.equal('USD'); - expect(interpretedBid.width).to.equal(640); - expect(interpretedBid.height).to.equal(240); - expect(interpretedBid.ad).to.equal(BANNER_AD); - expect(interpretedBid.ttl).to.equal(300); - expect(interpretedBid.creativeId).to.equal('86f4aef9-2f17-421d-84db-5c9814bf4a79'); - expect(interpretedBid.netRevenue).to.be.false; - expect(interpretedBid.meta).to.deep.equal(prebidServerResponse.body[0].meta); - expect(interpretedBid.renderer).to.be.undefined; - expect(interpretedBid.adResponse).to.deep.equal(prebidServerResponse); - }); - - it('returns a valid Prebid API response object for a video Prebid Server response', function () { - const prebidServerResponse = Object.freeze({ - body: [{ - mediaType: 'video', - requestId: '67890', - cpm: 2, - currency: 'USD', - width: 600, - height: 300, - ad: VIDEO_AD, - ttl: 300, - creativeId: '248e8e0c-2f17-421d-84db-5c9814bf4a79', - netRevenue: false, - meta: { - advertiser: '105600', - width: 300, - height: 250, - isCustom: '1', - progressBar: false, - mpuSrc: '//images.intellitxt.com/a/105600/Genpact/genpact.jpg', - clickURL: '{{click}}' - }, - vastUrl: 'https://www.example.com/myVastVideo' - }] - }); - - const interpretedResponse = spec.interpretResponse(prebidServerResponse, {}); - - expect(interpretedResponse).to.be.a('array'); - expect(interpretedResponse.length).to.equal(1); - - const interpretedBid = interpretedResponse[0]; - - expect(interpretedBid.mediaType).to.equal('video'); - expect(interpretedBid.requestId).to.equal('67890'); - expect(interpretedBid.cpm).to.equal(2); - expect(interpretedBid.currency).to.equal('USD'); - expect(interpretedBid.width).to.equal(600); - expect(interpretedBid.height).to.equal(300); - expect(interpretedBid.ad).to.equal(VIDEO_AD); - expect(interpretedBid.ttl).to.equal(300); - expect(interpretedBid.creativeId).to.equal('248e8e0c-2f17-421d-84db-5c9814bf4a79'); - expect(interpretedBid.netRevenue).to.be.false; - expect(interpretedBid.meta).to.deep.equal(prebidServerResponse.body[0].meta); - expect(interpretedBid.renderer).to.be.undefined; - expect(interpretedBid.adResponse).to.deep.equal(prebidServerResponse); - }); - - it('returns a valid Prebid API response object for a native Prebid Server response', function () { - const prebidServerResponse = Object.freeze({ - body: [{ - mediaType: 'native', - requestId: '13579', - cpm: 3, - currency: 'USD', - width: 240, - height: 300, - ad: 'https://www.example.com/native-display.html', - ttl: 300, - creativeId: 'd28e8e0c-2f17-421d-84db-5c9814bf4a81', - netRevenue: false, - meta: {}, - title: 'Test native ad bid for 13579', - sponsoredBy: 'Vibrant Media Ltd', - clickUrl: 'https://www.example.com/native-ct.html', - image: { - url: 'https://www.example.com/native-display.html', - width: 240, - height: 300 - } - }] - }); - - const interpretedResponse = spec.interpretResponse(prebidServerResponse, {}); - - expect(interpretedResponse).to.be.a('array'); - expect(interpretedResponse.length).to.equal(1); - - const interpretedBid = interpretedResponse[0]; - - expect(interpretedBid.mediaType).to.equal('native'); - expect(interpretedBid.requestId).to.equal('13579'); - expect(interpretedBid.cpm).to.equal(3); - expect(interpretedBid.currency).to.equal('USD'); - expect(interpretedBid.width).to.equal(240); - expect(interpretedBid.height).to.equal(300); - expect(interpretedBid.ad).to.equal('https://www.example.com/native-display.html'); - expect(interpretedBid.ttl).to.equal(300); - expect(interpretedBid.creativeId).to.equal('d28e8e0c-2f17-421d-84db-5c9814bf4a81'); - expect(interpretedBid.netRevenue).to.be.false; - expect(interpretedBid.meta).to.deep.equal(prebidServerResponse.body[0].meta); - expect(interpretedBid.renderer).to.be.undefined; - expect(interpretedBid.adResponse).to.deep.equal(prebidServerResponse); - }); - - it('returns a valid Prebid API response object for a multi-bid Prebid Server response', function () { - const prebidServerResponse = Object.freeze({ - body: [ - { - mediaType: 'banner', - requestId: '12345', - cpm: 3, - currency: 'USD', - width: 640, - height: 240, - ad: BANNER_AD, - ttl: 300, - creativeId: '86f4aef9-2f17-421d-84db-5c9814bf4a79', - netRevenue: false, - meta: { - advertiser: '105600', - width: 300, - height: 250, - isCustom: '1', - progressBar: false, - mpuSrc: '//images.intellitxt.com/a/105600/Genpact/genpact.jpg', - clickURL: '{{click}}' - } - }, - { - mediaType: 'video', - requestId: '67890', - cpm: 4, - currency: 'USD', - width: 300, - height: 300, - ad: VIDEO_AD, - ttl: 300, - creativeId: 'd28e8e0c-2f17-421d-84db-5c9814bf4a79', - netRevenue: false, - meta: { - advertiser: '105600', - width: 300, - height: 250, - isCustom: '1', - progressBar: false, - mpuSrc: '//images.intellitxt.com/a/105600/Genpact/genpact.jpg', - clickURL: '{{click}}' - }, - vastUrl: 'https://www.example.com/myVastVideo' - }, - { - mediaType: 'native', - requestId: '13579', - cpm: 5, - currency: 'USD', - width: 640, - height: 240, - ad: 'https://www.example.com/native-display.html', - ttl: 300, - creativeId: '888e8e0c-2f17-421d-84db-5c9814bf4a81', - netRevenue: false, - meta: {}, - title: 'Test native ad bid for 13579', - sponsoredBy: 'Vibrant Media Ltd', - clickUrl: 'https://www.example.com/native-ct.html', - image: { - url: 'https://www.example.com/native-display.html', - width: 640, - height: 240 - } - } - ] - }); - - const interpretedResponse = spec.interpretResponse(prebidServerResponse, {}); - - expect(interpretedResponse).to.be.a('array'); - expect(interpretedResponse.length).to.equal(3); - - const interpretedBannerBid = interpretedResponse[0]; - - expect(interpretedBannerBid.mediaType).to.equal('banner'); - expect(interpretedBannerBid.requestId).to.equal('12345'); - expect(interpretedBannerBid.cpm).to.equal(3); - expect(interpretedBannerBid.currency).to.equal('USD'); - expect(interpretedBannerBid.width).to.equal(640); - expect(interpretedBannerBid.height).to.equal(240); - expect(interpretedBannerBid.ad).to.equal(BANNER_AD); - expect(interpretedBannerBid.ttl).to.equal(300); - expect(interpretedBannerBid.creativeId).to.equal('86f4aef9-2f17-421d-84db-5c9814bf4a79'); - expect(interpretedBannerBid.netRevenue).to.be.false; - expect(interpretedBannerBid.meta).to.deep.equal(prebidServerResponse.body[0].meta); - expect(interpretedBannerBid.renderer).to.be.undefined; - expect(interpretedBannerBid.adResponse).to.deep.equal(prebidServerResponse); - - const interpretedVideoBid = interpretedResponse[1]; - - expect(interpretedVideoBid.mediaType).to.equal('video'); - expect(interpretedVideoBid.requestId).to.equal('67890'); - expect(interpretedVideoBid.cpm).to.equal(4); - expect(interpretedVideoBid.currency).to.equal('USD'); - expect(interpretedVideoBid.width).to.equal(300); - expect(interpretedVideoBid.height).to.equal(300); - expect(interpretedVideoBid.ad).to.equal(VIDEO_AD); - expect(interpretedVideoBid.ttl).to.equal(300); - expect(interpretedVideoBid.creativeId).to.equal('d28e8e0c-2f17-421d-84db-5c9814bf4a79'); - expect(interpretedVideoBid.netRevenue).to.be.false; - expect(interpretedVideoBid.meta).to.deep.equal(prebidServerResponse.body[1].meta); - expect(interpretedVideoBid.renderer).to.be.undefined; - expect(interpretedVideoBid.adResponse).to.deep.equal(prebidServerResponse); - - const interpretedNativeBid = interpretedResponse[2]; - - expect(interpretedNativeBid.mediaType).to.equal('native'); - expect(interpretedNativeBid.requestId).to.equal('13579'); - expect(interpretedNativeBid.cpm).to.equal(5); - expect(interpretedNativeBid.currency).to.equal('USD'); - expect(interpretedNativeBid.width).to.equal(640); - expect(interpretedNativeBid.height).to.equal(240); - expect(interpretedNativeBid.ad).to.equal('https://www.example.com/native-display.html'); - expect(interpretedNativeBid.ttl).to.equal(300); - expect(interpretedNativeBid.creativeId).to.equal('888e8e0c-2f17-421d-84db-5c9814bf4a81'); - expect(interpretedNativeBid.netRevenue).to.be.false; - expect(interpretedNativeBid.meta).to.deep.equal(prebidServerResponse.body[2].meta); - expect(interpretedNativeBid.renderer).to.be.undefined; - expect(interpretedNativeBid.adResponse).to.deep.equal(prebidServerResponse); - }); - }); - - describe('Flow tests', function () { - describe('For successive API calls to the public functions', function () { - it('should succeed with one media type per bid', function () { - const bannerBid = { - bidder: 'vibrantmedia', - params: VALID_BANNER_BID_PARAMS, - mediaTypes: { - banner: { - sizes: DEFAULT_BID_SIZES, - }, - }, - adUnitCode: 'banner-div', - bidId: '30b31c1838de11', - bidderRequestId: '22edbae2733bf6', - placementId: '293857832abfef', - auctionId: '1d1a030790a475', - }; - const videoBid = { - bidder: 'vibrantmedia', - params: VALID_VIDEO_BID_PARAMS, - mediaTypes: { - video: { - context: OUTSTREAM, - sizes: DEFAULT_BID_SIZES, - }, - }, - adUnitCode: 'video-div', - bidId: '30b31c1838de15', - bidderRequestId: '22edbae2733bf6', - placementId: '293857832abfef', - auctionId: '1d1a030790a475', - }; - const nativeBid = { - bidder: 'vibrantmedia', - params: VALID_NATIVE_BID_PARAMS, - mediaTypes: { - native: { - image: { - required: true, - sizes: [300, 250] - }, - title: { - required: true - }, - sponsoredBy: { - required: true - }, - clickUrl: { - required: true - } - } - }, - adUnitCode: 'native-div', - bidId: '30b31c1838de12', - bidderRequestId: '22edbae2733bf6', - placementId: '293857832abfef', - auctionId: '1d1a030790a475', - }; - - expect(spec.isBidRequestValid(bannerBid)).to.be.true; - expect(spec.isBidRequestValid(videoBid)).to.be.true; - expect(spec.isBidRequestValid(nativeBid)).to.be.true; - - const bidRequests = [bannerBid, videoBid, nativeBid]; - const validBidderRequest = getValidBidderRequest(bidRequests); - const serverRequest = spec.buildRequests(bidRequests, validBidderRequest); - expect(serverRequest.method).to.equal('POST'); - expect(serverRequest.url).to.equal(EXPECTED_PREBID_SERVER_URL); - - const payload = JSON.parse(serverRequest.data); - expect(payload.biddata).to.exist; - expect(payload.biddata.length).to.equal(3); - expect(payload.biddata[0]).to.exist; - expect(payload.biddata[0].code).to.equal(bannerBid.adUnitCode); - expect(payload.biddata[0].id).to.equal(bannerBid.placementId); - expect(payload.biddata[0].bidder).to.equal(bannerBid.bidder); - expect(payload.biddata[0].mediaTypes[BANNER]).to.exist; - expect(payload.biddata[0].mediaTypes[BANNER]).to.deep.equal({ - sizes: DEFAULT_BID_SIZES, - }); - expect(payload.biddata[1]).to.exist; - expect(payload.biddata[1].code).to.equal(videoBid.adUnitCode); - expect(payload.biddata[1].id).to.equal(videoBid.placementId); - expect(payload.biddata[1].bidder).to.equal(videoBid.bidder); - expect(payload.biddata[1].mediaTypes[VIDEO]).to.exist; - expect(payload.biddata[1].mediaTypes[VIDEO]).to.deep.equal({ - context: OUTSTREAM, - sizes: DEFAULT_BID_SIZES - }); - expect(payload.biddata[2]).to.exist; - expect(payload.biddata[2].code).to.equal(nativeBid.adUnitCode); - expect(payload.biddata[2].id).to.equal(nativeBid.placementId); - expect(payload.biddata[2].bidder).to.equal(nativeBid.bidder); - expect(payload.biddata[2].mediaTypes[NATIVE]).to.exist; - expect(payload.biddata[2].mediaTypes[NATIVE]).to.deep.equal(nativeBid.mediaTypes.native); - - // From here, the API would call the Prebid Server and call interpretResponse, which is covered by tests elsewhere - }); - - it('should succeed with multiple media types for a single bid', function () { - const bid = { - bidder: 'vibrantmedia', - params: VALID_VIDEO_BID_PARAMS, - mediaTypes: { - banner: { - sizes: DEFAULT_BID_SIZES - }, - video: { - context: OUTSTREAM, - sizes: DEFAULT_BID_SIZES - }, - native: { - sizes: DEFAULT_BID_SIZES - } - }, - adUnitCode: 'test-div', - bidId: '30b31c1838de13', - bidderRequestId: '22edbae2733bf6', - placementId: '293857832abfef', - auctionId: '1d1a030790a475', - }; - - expect(spec.isBidRequestValid(bid)).to.be.true; - - const bidRequests = [bid]; - const validBidderRequest = getValidBidderRequest(bidRequests); - const serverRequest = spec.buildRequests(bidRequests, validBidderRequest); - expect(serverRequest.method).to.equal('POST'); - expect(serverRequest.url).to.equal(EXPECTED_PREBID_SERVER_URL); - - const payload = JSON.parse(serverRequest.data); - expect(payload.biddata).to.exist; - expect(payload.biddata.length).to.equal(1); - expect(payload.biddata[0]).to.exist; - expect(payload.biddata[0].code).to.equal(bid.adUnitCode); - expect(payload.biddata[0].id).to.equal(bid.placementId); - expect(payload.biddata[0].bidder).to.equal(bid.bidder); - expect(payload.biddata[0].mediaTypes[BANNER]).to.exist; - expect(payload.biddata[0].mediaTypes[BANNER]).to.deep.equal({ - sizes: DEFAULT_BID_SIZES, - }); - expect(payload.biddata[0].mediaTypes[VIDEO]).to.exist; - expect(payload.biddata[0].mediaTypes[VIDEO]).to.deep.equal({ - context: OUTSTREAM, - sizes: DEFAULT_BID_SIZES, - }); - expect(payload.biddata[0].mediaTypes[NATIVE]).to.exist; - expect(payload.biddata[0].mediaTypes[NATIVE]).to.deep.equal({ - sizes: DEFAULT_BID_SIZES, - }); - - // From here, the API would call the Prebid Server and call interpretResponse, which is covered by tests elsewhere - }); - }); - }); -}); diff --git a/test/spec/modules/vidazooBidAdapter_spec.js b/test/spec/modules/vidazooBidAdapter_spec.js deleted file mode 100644 index ab0820ef3..000000000 --- a/test/spec/modules/vidazooBidAdapter_spec.js +++ /dev/null @@ -1,1124 +0,0 @@ -import {expect} from 'chai'; -import { - spec as adapter, - storage, - createDomain, - webSessionId -} from 'modules/vidazooBidAdapter.js'; -import { - hashCode, - extractPID, - extractCID, - extractSubDomain, - getStorageItem, - setStorageItem, - tryParseJSON, - getUniqueDealId, - getNextDealId, - getTopWindowQueryParams, - getVidazooSessionId -} from 'libraries/vidazooUtils/bidderUtils.js' -import * as utils from 'src/utils.js'; -import {version} from 'package.json'; -import {useFakeTimers} from 'sinon'; -import {BANNER, VIDEO} from '../../../src/mediaTypes.js'; -import {config} from '../../../src/config.js'; -import {deepSetValue} from 'src/utils.js'; -import {getGlobal} from '../../../src/prebidGlobal.js'; - -export const TEST_ID_SYSTEMS = ['criteoId', 'id5id', 'idl_env', 'lipb', 'netId', 'pubcid', 'tdid', 'pubProvidedId']; - -const SUB_DOMAIN = 'openrtb'; - -const BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': 'div-gpt-ad-12345-0', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '59db6b3b4ffaa70004f45cdc', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1, - 'ext': { - 'param1': 'loremipsum', - 'param2': 'dolorsitamet' - } - }, - 'placementCode': 'div-gpt-ad-1460505748561-0', - 'sizes': [[300, 250], [300, 600]], - 'bidderRequestId': '1fdb5ff1b6eaa7', - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'requestId': 'b0777d85-d061-450e-9bc7-260dd54bbb7a', - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'mediaTypes': [BANNER], - 'ortb2Imp': { - 'ext': { - tid: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - 'gpid': '1234567890' - } - } -}; - -const VIDEO_BID = { - 'bidId': '2d52001cabd527', - 'adUnitCode': '63550ad1ff6642d368cba59dh5884270560', - 'bidderRequestId': '12a8ae9ada9c13', - ortb2Imp: { - ext: { - tid: '56e184c6-bde9-497b-b9b9-cf47a61381ee', - } - }, - 'bidRequestsCount': 4, - 'bidderRequestsCount': 3, - 'bidderWinsCount': 1, - 'schain': 'a0819c69-005b-41ed-af06-1be1e0aefefc', - 'params': { - 'subDomain': SUB_DOMAIN, - 'cId': '635509f7ff6642d368cb9837', - 'pId': '59ac17c192832d0011283fe3', - 'bidFloor': 0.1 - }, - 'sizes': [[545, 307]], - 'mediaTypes': { - 'video': { - 'playerSize': [[545, 307]], - 'context': 'instream', - 'mimes': [ - 'video/mp4', - 'application/javascript' - ], - 'protocols': [2, 3, 5, 6], - 'maxduration': 60, - 'minduration': 0, - 'startdelay': 0, - 'linearity': 1, - 'api': [2, 7], - 'placement': 1 - } - } -} - -const ORTB2_DEVICE = { - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - w: 980, - h: 1720, - dnt: 0, - ua: 'Mozilla/5.0 (iPhone; CPU iPhone OS 17_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/125.0.6422.80 Mobile/15E148 Safari/604.1', - language: 'en', - devicetype: 1, - make: 'Apple', - model: 'iPhone 12 Pro Max', - os: 'iOS', - osv: '17.4', - ext: {fiftyonedegrees_deviceId: '17595-133085-133468-18092'}, -}; - -const BIDDER_REQUEST = { - 'gdprConsent': { - 'consentString': 'consent_string', - 'gdprApplies': true - }, - 'gppString': 'gpp_string', - 'gppSid': [7], - 'uspConsent': 'consent_string', - 'refererInfo': { - 'page': 'https://www.greatsite.com', - 'ref': 'https://www.somereferrer.com' - }, - 'ortb2': { - 'site': { - 'cat': ['IAB2'], - 'pagecat': ['IAB2-2'], - 'content': { - 'language': 'en', - 'data': [{ - 'name': 'example.com', - 'ext': { - 'segtax': 7 - }, - 'segments': [ - {'id': 'segId1'}, - {'id': 'segId2'} - ] - }] - } - }, - 'regs': { - 'gpp': 'gpp_string', - 'gpp_sid': [7], - 'coppa': 0 - }, - device: ORTB2_DEVICE, - user: { - data: [ - { - ext: {segtax: 600, segclass: '1'}, - name: 'example.com', - segment: [{id: '243'}], - }, - ], - }, - source: { - ext: { - omidpn: 'MyIntegrationPartner', - omidpv: '7.1' - } - } - } -}; - -const SERVER_RESPONSE = { - body: { - cid: 'testcid123', - results: [{ - 'ad': '', - 'bidId': '2d52001cabd527-response', - 'price': 0.8, - 'creativeId': '12610997325162499419', - 'exp': 30, - 'width': 300, - 'height': 250, - 'advertiserDomains': ['securepubads.g.doubleclick.net'], - 'cookies': [{ - 'src': 'https://sync.com', - 'type': 'iframe' - }, { - 'src': 'https://sync.com', - 'type': 'img' - }] - }] - } -}; - -const VIDEO_SERVER_RESPONSE = { - body: { - 'cid': '635509f7ff6642d368cb9837', - 'results': [{ - 'ad': '', - 'advertiserDomains': ['vidazoo.com'], - 'exp': 60, - 'width': 545, - 'height': 307, - 'mediaType': 'video', - 'creativeId': '12610997325162499419', - 'price': 2, - 'cookies': [] - }] - } -}; - -const ORTB2_OBJ = { - "device": ORTB2_DEVICE, - "regs": {"coppa": 0, "gpp": "gpp_string", "gpp_sid": [7]}, - "site": { - "cat": ["IAB2"], - "content": { - "data": [{ - "ext": {"segtax": 7}, - "name": "example.com", - "segments": [{"id": "segId1"}, {"id": "segId2"}] - }], - "language": "en" - }, - "pagecat": ["IAB2-2"] - }, - "source": {"ext": {"omidpn": "MyIntegrationPartner", "omidpv": "7.1"}}, - "user": { - "data": [{"ext": {"segclass": "1", "segtax": 600}, "name": "example.com", "segment": [{"id": "243"}]}] - } -}; - -const REQUEST = { - data: { - width: 300, - height: 250, - bidId: '2d52001cabd527' - } -}; - -describe('VidazooBidAdapter', function () { - before(() => config.resetConfig()); - after(() => config.resetConfig()); - - describe('validtae spec', function () { - it('exists and is a function', function () { - expect(adapter.isBidRequestValid).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.buildRequests).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.interpretResponse).to.exist.and.to.be.a('function'); - }); - - it('exists and is a function', function () { - expect(adapter.getUserSyncs).to.exist.and.to.be.a('function'); - }); - - it('exists and is a string', function () { - expect(adapter.code).to.exist.and.to.be.a('string'); - }); - - it('exists and contains media types', function () { - expect(adapter.supportedMediaTypes).to.exist.and.to.be.an('array').with.length(2); - expect(adapter.supportedMediaTypes).to.contain.members([BANNER, VIDEO]); - }); - }); - - describe('validate bid requests', function () { - it('should require cId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - pId: 'pid' - } - }); - expect(isValid).to.be.false; - }); - - it('should require pId', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid' - } - }); - expect(isValid).to.be.false; - }); - - it('should validate correctly', function () { - const isValid = adapter.isBidRequestValid({ - params: { - cId: 'cid', - pId: 'pid' - } - }); - expect(isValid).to.be.true; - }); - }); - - describe('build requests', function () { - let sandbox; - before(function () { - getGlobal().bidderSettings = { - vidazoo: { - storageAllowed: true, - } - }; - sandbox = sinon.createSandbox(); - sandbox.stub(Date, 'now').returns(1000); - }); - - it('should build video request', function () { - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - config.setConfig({ - bidderTimeout: 3000 - }); - const requests = adapter.buildRequests([VIDEO_BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/635509f7ff6642d368cb9837`, - data: { - adUnitCode: '63550ad1ff6642d368cba59dh5884270560', - bidFloor: 0.1, - bidId: '2d52001cabd527', - bidderVersion: adapter.version, - cat: ['IAB2'], - pagecat: ['IAB2-2'], - ortb2Imp: VIDEO_BID.ortb2Imp, - ortb2: ORTB2_OBJ, - cb: 1000, - dealId: 1, - gdpr: 1, - gdprConsent: 'consent_string', - usPrivacy: 'consent_string', - gppString: 'gpp_string', - gppSid: [7], - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - transactionId: '56e184c6-bde9-497b-b9b9-cf47a61381ee', - bidderRequestId: '12a8ae9ada9c13', - gpid: '', - prebidVersion: version, - ptrace: '1000', - vdzhum: '1000', - publisherId: '59ac17c192832d0011283fe3', - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - res: `${window.top.screen.width}x${window.top.screen.height}`, - schain: VIDEO_BID.schain, - sessionId: '', - sizes: ['545x307'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - contentLang: 'en', - coppa: 0, - device: ORTB2_DEVICE, - contentData: [{ - 'name': 'example.com', - 'ext': { - 'segtax': 7 - }, - 'segments': [ - {'id': 'segId1'}, - {'id': 'segId2'} - ] - }], - userData: [ - { - ext: {segtax: 600, segclass: '1'}, - name: 'example.com', - segment: [{id: '243'}], - }, - ], - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - uqs: getTopWindowQueryParams(), - isStorageAllowed: true, - webSessionId: webSessionId, - mediaTypes: { - video: { - api: [2, 7], - context: 'instream', - linearity: 1, - maxduration: 60, - mimes: [ - 'video/mp4', - 'application/javascript' - ], - minduration: 0, - placement: 1, - playerSize: [[545, 307]], - protocols: [2, 3, 5, 6], - startdelay: 0 - } - }, - omidpn: 'MyIntegrationPartner', - omidpv: '7.1' - } - }) - ; - }); - - it('should build banner request for each size', function () { - config.setConfig({ - bidderTimeout: 3000 - }); - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - const requests = adapter.buildRequests([BID], BIDDER_REQUEST); - expect(requests).to.have.length(1); - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/59db6b3b4ffaa70004f45cdc`, - data: { - gdprConsent: 'consent_string', - gdpr: 1, - usPrivacy: 'consent_string', - gppString: 'gpp_string', - gppSid: [7], - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - bidderRequestId: '1fdb5ff1b6eaa7', - sizes: ['300x250', '300x600'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - cb: 1000, - bidFloor: 0.1, - bidId: '2d52001cabd527', - adUnitCode: 'div-gpt-ad-12345-0', - publisherId: '59ac17c192832d0011283fe3', - dealId: 2, - sessionId: '', - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - bidderVersion: adapter.version, - prebidVersion: version, - schain: BID.schain, - ptrace: '1000', - vdzhum: '1000', - res: `${window.top.screen.width}x${window.top.screen.height}`, - mediaTypes: [BANNER], - uqs: getTopWindowQueryParams(), - 'ext.param1': 'loremipsum', - 'ext.param2': 'dolorsitamet', - isStorageAllowed: true, - gpid: '1234567890', - cat: ['IAB2'], - pagecat: ['IAB2-2'], - ortb2Imp: BID.ortb2Imp, - ortb2: ORTB2_OBJ, - contentLang: 'en', - coppa: 0, - contentData: [{ - 'name': 'example.com', - 'ext': { - 'segtax': 7 - }, - 'segments': [ - {'id': 'segId1'}, - {'id': 'segId2'} - ] - }], - userData: [ - { - ext: {segtax: 600, segclass: '1'}, - name: 'example.com', - segment: [{id: '243'}], - }, - ], - webSessionId: webSessionId - } - }); - }); - - it('should build single banner request for multiple bids', function () { - config.setConfig({ - bidderTimeout: 3000, - vidazoo: { - singleRequest: true, - chunkSize: 2 - } - }); - - const hashUrl = hashCode(BIDDER_REQUEST.refererInfo.page); - - const BID2 = utils.deepClone(BID); - BID2.bidId = '2d52001cabd528'; - BID2.adUnitCode = 'div-gpt-ad-12345-1'; - BID2.sizes = [[300, 250]]; - - const REQUEST_DATA = { - gdprConsent: 'consent_string', - gdpr: 1, - usPrivacy: 'consent_string', - gppString: 'gpp_string', - gppSid: [7], - bidRequestsCount: 4, - bidderRequestsCount: 3, - bidderWinsCount: 1, - bidderTimeout: 3000, - transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - bidderRequestId: '1fdb5ff1b6eaa7', - sizes: ['300x250', '300x600'], - sua: { - 'source': 2, - 'platform': { - 'brand': 'Android', - 'version': ['8', '0', '0'] - }, - 'browsers': [ - {'brand': 'Not_A Brand', 'version': ['99', '0', '0', '0']}, - {'brand': 'Google Chrome', 'version': ['109', '0', '5414', '119']}, - {'brand': 'Chromium', 'version': ['109', '0', '5414', '119']} - ], - 'mobile': 1, - 'model': 'SM-G955U', - 'bitness': '64', - 'architecture': '' - }, - device: ORTB2_DEVICE, - url: 'https%3A%2F%2Fwww.greatsite.com', - referrer: 'https://www.somereferrer.com', - cb: 1000, - bidFloor: 0.1, - bidId: '2d52001cabd527', - adUnitCode: 'div-gpt-ad-12345-0', - publisherId: '59ac17c192832d0011283fe3', - dealId: 3, - sessionId: '', - uniqueDealId: `${hashUrl}_${Date.now().toString()}`, - bidderVersion: adapter.version, - prebidVersion: version, - schain: BID.schain, - ptrace: '1000', - vdzhum: '1000', - res: `${window.top.screen.width}x${window.top.screen.height}`, - mediaTypes: [BANNER], - uqs: getTopWindowQueryParams(), - 'ext.param1': 'loremipsum', - 'ext.param2': 'dolorsitamet', - isStorageAllowed: true, - gpid: '1234567890', - cat: ['IAB2'], - pagecat: ['IAB2-2'], - contentLang: 'en', - coppa: 0, - contentData: [{ - 'name': 'example.com', - 'ext': { - 'segtax': 7 - }, - 'segments': [ - {'id': 'segId1'}, - {'id': 'segId2'} - ] - }], - userData: [ - { - ext: {segtax: 600, segclass: '1'}, - name: 'example.com', - segment: [{id: '243'}], - }, - ], - webSessionId: webSessionId - }; - - const REQUEST_DATA2 = utils.deepClone(REQUEST_DATA); - REQUEST_DATA2.bidId = '2d52001cabd528'; - REQUEST_DATA2.adUnitCode = 'div-gpt-ad-12345-1'; - REQUEST_DATA2.sizes = ['300x250']; - REQUEST_DATA2.dealId = 4; - - const requests = adapter.buildRequests([BID, BID2], BIDDER_REQUEST); - expect(requests).to.have.length(1); - - expect(requests[0]).to.deep.equal({ - method: 'POST', - url: `${createDomain(SUB_DOMAIN)}/prebid/multi/59db6b3b4ffaa70004f45cdc`, - data: {bids: [ - {...REQUEST_DATA, ortb2: ORTB2_OBJ, ortb2Imp: BID.ortb2Imp}, - {...REQUEST_DATA2, ortb2: ORTB2_OBJ, ortb2Imp: BID.ortb2Imp} - ]} - }); - }); - - it('should return separated requests for video and banner if singleRequest is true', function () { - config.setConfig({ - bidderTimeout: 3000, - vidazoo: { - singleRequest: true, - chunkSize: 2 - } - }); - - const requests = adapter.buildRequests([BID, VIDEO_BID], BIDDER_REQUEST); - expect(requests).to.have.length(2); - }); - - it('should chunk requests if requests exceed chunkSize and singleRequest is true', function () { - config.setConfig({ - bidderTimeout: 3000, - vidazoo: { - singleRequest: true, - chunkSize: 2 - } - }); - - const requests = adapter.buildRequests([BID, BID, BID, BID], BIDDER_REQUEST); - expect(requests).to.have.length(2); - }); - - it('should set fledge correctly if enabled', function () { - config.resetConfig(); - const bidderRequest = utils.deepClone(BIDDER_REQUEST); - bidderRequest.paapi = {enabled: true}; - deepSetValue(bidderRequest, 'ortb2Imp.ext.ae', 1); - const requests = adapter.buildRequests([BID], bidderRequest); - expect(requests[0].data.fledge).to.equal(1); - }); - - after(function () { - getGlobal().bidderSettings = {}; - config.resetConfig(); - sandbox.restore(); - }); - }); - - describe('getUserSyncs', function () { - it('should have valid user sync with iframeEnabled', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.cootlogix.com/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - - it('should have valid user sync with cid on response', function () { - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.cootlogix.com/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0' - }]); - }); - - it('should have valid user sync with pixelEnabled', function () { - const result = adapter.getUserSyncs({pixelEnabled: true}, [SERVER_RESPONSE]); - - expect(result).to.deep.equal([{ - 'url': 'https://sync.cootlogix.com/api/sync/image/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=0', - 'type': 'image' - }]); - }); - - it('should have valid user sync with coppa 1 on response', function () { - config.setConfig({ - coppa: 1 - }); - const result = adapter.getUserSyncs({iframeEnabled: true}, [SERVER_RESPONSE]); - expect(result).to.deep.equal([{ - type: 'iframe', - url: 'https://sync.cootlogix.com/api/sync/iframe/?cid=testcid123&gdpr=0&gdpr_consent=&us_privacy=&coppa=1' - }]); - }); - }); - - describe('interpret response', function () { - it('should return empty array when there is no response', function () { - const responses = adapter.interpretResponse(null); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no ad', function () { - const responses = adapter.interpretResponse({price: 1, ad: ''}); - expect(responses).to.be.empty; - }); - - it('should return empty array when there is no price', function () { - const responses = adapter.interpretResponse({price: null, ad: 'great ad'}); - expect(responses).to.be.empty; - }); - - it('should return an array of interpreted banner responses', function () { - const responses = adapter.interpretResponse(SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 0.8, - width: 300, - height: 250, - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 30, - ad: '', - meta: { - advertiserDomains: ['securepubads.g.doubleclick.net'] - } - }); - }); - - it('should get meta from response metaData', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - serverResponse.body.results[0].metaData = { - advertiserDomains: ['vidazoo.com'], - agencyName: 'Agency Name', - }; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses[0].meta).to.deep.equal({ - advertiserDomains: ['vidazoo.com'], - agencyName: 'Agency Name' - }); - }); - - it('should return an array of interpreted video responses', function () { - const responses = adapter.interpretResponse(VIDEO_SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0]).to.deep.equal({ - requestId: '2d52001cabd527', - cpm: 2, - width: 545, - height: 307, - mediaType: 'video', - creativeId: '12610997325162499419', - currency: 'USD', - netRevenue: true, - ttl: 60, - vastXml: '', - meta: { - advertiserDomains: ['vidazoo.com'] - } - }); - }); - - it('should populate requestId from response in case of singleRequest true', function () { - config.setConfig({ - vidazoo: { - singleRequest: true, - chunkSize: 2 - } - }); - - const responses = adapter.interpretResponse(SERVER_RESPONSE, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0].requestId).to.equal('2d52001cabd527-response'); - - config.resetConfig(); - }); - - it('should take default TTL', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - delete serverResponse.body.results[0].exp; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0].ttl).to.equal(300); - }); - - it('should add nurl if exists on response', function () { - const serverResponse = utils.deepClone(SERVER_RESPONSE); - serverResponse.body.results[0].nurl = 'https://test.com/win-notice?test=123'; - const responses = adapter.interpretResponse(serverResponse, REQUEST); - expect(responses).to.have.length(1); - expect(responses[0].nurl).to.equal('https://test.com/win-notice?test=123'); - }); - }); - - describe('user id system', function () { - TEST_ID_SYSTEMS.forEach((idSystemProvider) => { - const id = Date.now().toString(); - const bid = utils.deepClone(BID); - - const userId = (function () { - switch (idSystemProvider) { - case 'lipb': - return {lipbid: id}; - case 'id5id': - return {uid: id}; - default: - return id; - } - })(); - - bid.userId = { - [idSystemProvider]: userId - }; - - it(`should include 'uid.${idSystemProvider}' in request params`, function () { - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data[`uid.${idSystemProvider}`]).to.equal(id); - }); - }); - // testing bid.userIdAsEids handling - it("should include user ids from bid.userIdAsEids (length=1)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - }) - it("should include user ids from bid.userIdAsEids (length=2)", function() { - const bid = utils.deepClone(BID); - bid.userIdAsEids = [ - { - "source": "audigent.com", - "uids": [{"id": "fakeidi6j6dlc6e"}] - }, - { - "source": "rwdcntrl.net", - "uids": [{"id": "fakeid6f35197d5c", "atype": 1}] - } - ] - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.audigent.com']).to.equal("fakeidi6j6dlc6e"); - expect(requests[0].data['uid.rwdcntrl.net']).to.equal("fakeid6f35197d5c"); - }) - // testing user.ext.eid handling - it("should include user ids from user.ext.eid (length=1)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - }) - it("should include user ids from user.ext.eid (length=2)", function() { - const bid = utils.deepClone(BID); - bid.user = { - ext: { - eids: [ - { - "source": "pubcid.org", - "uids": [{"id": "fakeid8888dlc6e"}] - }, - { - "source": "adserver.org", - "uids": [{"id": "fakeid495ff1"}] - } - ] - } - } - const requests = adapter.buildRequests([bid], BIDDER_REQUEST); - expect(requests[0].data['uid.pubcid.org']).to.equal("fakeid8888dlc6e"); - expect(requests[0].data['uid.adserver.org']).to.equal("fakeid495ff1"); - }) - }); - - describe('alternate param names extractors', function () { - it('should return undefined when param not supported', function () { - const cid = extractCID({'c_id': '1'}); - const pid = extractPID({'p_id': '1'}); - const subDomain = extractSubDomain({'sub_domain': 'prebid'}); - expect(cid).to.be.undefined; - expect(pid).to.be.undefined; - expect(subDomain).to.be.undefined; - }); - - it('should return value when param supported', function () { - const cid = extractCID({'cID': '1'}); - const pid = extractPID({'Pid': '2'}); - const subDomain = extractSubDomain({'subDOMAIN': 'prebid'}); - expect(cid).to.be.equal('1'); - expect(pid).to.be.equal('2'); - expect(subDomain).to.be.equal('prebid'); - }); - }); - - describe('vidazoo session id', function () { - before(function () { - getGlobal().bidderSettings = { - vidazoo: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - it('should get undefined vidazoo session id', function () { - const sessionId = getVidazooSessionId(storage); - expect(sessionId).to.be.empty; - }); - - it('should get vidazoo session id from storage', function () { - const vidSid = '1234-5678'; - window.localStorage.setItem('vidSid', vidSid); - const sessionId = getVidazooSessionId(storage); - expect(sessionId).to.be.equal(vidSid); - }); - }); - - describe('deal id', function () { - before(function () { - getGlobal().bidderSettings = { - vidazoo: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - const key = 'myDealKey'; - - it('should get the next deal id', function () { - const dealId = getNextDealId(storage, key); - const nextDealId = getNextDealId(storage, key); - expect(dealId).to.be.equal(1); - expect(nextDealId).to.be.equal(2); - }); - - it('should get the first deal id on expiration', function (done) { - setTimeout(function () { - const dealId = getNextDealId(storage, key, 100); - expect(dealId).to.be.equal(1); - done(); - }, 200); - }); - }); - - describe('unique deal id', function () { - before(function () { - getGlobal().bidderSettings = { - vidazoo: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - const key = 'myKey'; - let uniqueDealId; - beforeEach(() => { - uniqueDealId = getUniqueDealId(storage, key, 0); - }) - - it('should get current unique deal id', function (done) { - // waiting some time so `now` will become past - setTimeout(() => { - const current = getUniqueDealId(storage, key); - expect(current).to.be.equal(uniqueDealId); - done(); - }, 200); - }); - - it('should get new unique deal id on expiration', function (done) { - setTimeout(() => { - const current = getUniqueDealId(storage, key, 100); - expect(current).to.not.be.equal(uniqueDealId); - done(); - }, 200) - }); - }); - - describe('storage utils', function () { - before(function () { - getGlobal().bidderSettings = { - vidazoo: { - storageAllowed: true - } - }; - }); - after(function () { - getGlobal().bidderSettings = {}; - }); - it('should get value from storage with create param', function () { - const now = Date.now(); - const clock = useFakeTimers({ - shouldAdvanceTime: true, - now - }); - setStorageItem(storage, 'myKey', 2020); - const {value, created} = getStorageItem(storage, 'myKey'); - expect(created).to.be.equal(now); - expect(value).to.be.equal(2020); - expect(typeof value).to.be.equal('number'); - expect(typeof created).to.be.equal('number'); - clock.restore(); - }); - - it('should get external stored value', function () { - const value = 'superman' - window.localStorage.setItem('myExternalKey', value); - const item = getStorageItem(storage, 'myExternalKey'); - expect(item).to.be.equal(value); - }); - - it('should parse JSON value', function () { - const data = JSON.stringify({event: 'send'}); - const {event} = tryParseJSON(data); - expect(event).to.be.equal('send'); - }); - - it('should get original value on parse fail', function () { - const value = 21; - const parsed = tryParseJSON(value); - expect(typeof parsed).to.be.equal('number'); - expect(parsed).to.be.equal(value); - }); - }); - - describe('validate onBidWon', function () { - beforeEach(function () { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function () { - utils.triggerPixel.restore(); - }); - - it('should call triggerPixel if nurl exists', function () { - const bid = { - adUnitCode: 'div-gpt-ad-12345-0', - adId: '2d52001cabd527', - auctionId: '1fdb5ff1b6eaa7', - transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - status: 'rendered', - timeToRespond: 100, - cpm: 0.8, - originalCpm: 0.8, - creativeId: '12610997325162499419', - currency: 'USD', - originalCurrency: 'USD', - height: 250, - mediaType: 'banner', - nurl: 'https://test.com/win-notice?test=123', - netRevenue: true, - requestId: '2d52001cabd527', - ttl: 30, - width: 300 - }; - adapter.onBidWon(bid); - expect(utils.triggerPixel.called).to.be.true; - - const url = utils.triggerPixel.args[0]; - - expect(url[0]).to.be.equal('https://test.com/win-notice?test=123&adId=2d52001cabd527&creativeId=12610997325162499419&auctionId=1fdb5ff1b6eaa7&transactionId=c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf&adUnitCode=div-gpt-ad-12345-0&cpm=0.8¤cy=USD&originalCpm=0.8&originalCurrency=USD&netRevenue=true&mediaType=banner&timeToRespond=100&status=rendered'); - }); - - it('should not call triggerPixel if nurl does not exist', function () { - const bid = { - adUnitCode: 'div-gpt-ad-12345-0', - adId: '2d52001cabd527', - auctionId: '1fdb5ff1b6eaa7', - transactionId: 'c881914b-a3b5-4ecf-ad9c-1c2f37c6aabf', - status: 'rendered', - timeToRespond: 100, - cpm: 0.8, - originalCpm: 0.8, - creativeId: '12610997325162499419', - currency: 'USD', - originalCurrency: 'USD', - height: 250, - mediaType: 'banner', - netRevenue: true, - requestId: '2d52001cabd527', - ttl: 30, - width: 300 - }; - adapter.onBidWon(bid); - expect(utils.triggerPixel.called).to.be.false; - }); - }); -}); diff --git a/test/spec/modules/videobyteBidAdapter_spec.js b/test/spec/modules/videobyteBidAdapter_spec.js deleted file mode 100644 index b9fd1e4e4..000000000 --- a/test/spec/modules/videobyteBidAdapter_spec.js +++ /dev/null @@ -1,628 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/videobyteBidAdapter.js'; - -describe('VideoByteBidAdapter', function () { - let bidRequest; - let bidderRequest = { - 'bidderCode': 'videobyte', - 'auctionId': 'e158486f-8c7f-472f-94ce-b0cbfbb50ab4', - 'bidderRequestId': '1e498b84fffc39', - 'bids': bidRequest, - 'auctionStart': 1520001292880, - 'timeout': 3000, - 'start': 1520001292884, - 'doneCbCallCount': 0, - 'refererInfo': { - 'numIframes': 1, - 'reachedTop': true, - 'referer': 'test.com' - } - }; - let mockConfig; - - beforeEach(function () { - bidRequest = { - mediaTypes: { - video: { - context: 'instream', - playerSize: [[640, 480]], - } - }, - bidder: 'videobyte', - sizes: [640, 480], - bidId: '30b3efwfwe1e', - adUnitCode: 'video1', - params: { - video: { - playerWidth: 640, - playerHeight: 480, - mimes: ['video/mp4', 'application/javascript'], - protocols: [2, 5], - api: [2], - position: 1, - delivery: [2], - sid: 134, - rewarded: 1, - placement: 1, - hp: 1, - inventoryid: 123 - }, - site: { - id: 1, - page: 'https://test.com', - referrer: 'http://test.com' - }, - pubId: 'vb12345' - } - }; - }); - - describe('spec.isBidRequestValid', function () { - it('should return false when mediaTypes is empty', function () { - bidRequest.mediaTypes = {}; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return true (skip validations) when e2etest = true', function () { - bidRequest.params.video = { - e2etest: true - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true when mediaTypes.video has all mandatory params', function () { - bidRequest.mediaTypes.video = { - context: 'instream', - playerSize: [[640, 480]], - mimes: ['video/mp4', 'application/javascript'], - } - bidRequest.params.video = {}; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true when params.video has all override params instead of mediaTypes.video', function () { - bidRequest.mediaTypes.video = { - context: 'instream' - }; - bidRequest.params.video = { - playerSize: [[640, 480]], - mimes: ['video/mp4', 'application/javascript'] - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return true when mimes is passed in params.video', function () { - bidRequest.mediaTypes.video = { - context: 'instream', - playerSize: [[640, 480]] - }; - bidRequest.video = { - mimes: ['video/mp4', 'application/javascript'] - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(true); - }); - - it('should return false when both mediaTypes.video and params.video Objects are missing', function () { - bidRequest.mediaTypes = {}; - bidRequest.params = { - pubId: 'brxd' - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false when both mediaTypes.video and params.video are missing mimes and player size', function () { - bidRequest.mediaTypes = { - video: { - context: 'instream' - } - }; - bidRequest.params = { - pubId: 'brxd' - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false when the "pubId" param is missing', function () { - bidRequest.params = { - video: { - playerWidth: 480, - playerHeight: 640, - mimes: ['video/mp4', 'application/javascript'], - } - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - it('should return false when the "pubId" param is missing', function () { - bidRequest.params = { - video: { - playerWidth: 480, - playerHeight: 640, - mimes: ['video/mp4', 'application/javascript'], - } - }; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - - it('should return false when no bid params are passed', function () { - bidRequest.params = {}; - expect(spec.isBidRequestValid(bidRequest)).to.equal(false); - }); - }); - - describe('spec.buildRequests', function () { - it('should create a POST request for every bid', function () { - const requests = spec.buildRequests([bidRequest], bidderRequest); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(spec.ENDPOINT + '?pid=' + bidRequest.params.pubId); - }); - - it('should attach request data', function () { - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - const [width, height] = bidRequest.sizes; - const VERSION = '1.0.0'; - expect(data.imp[0].video.w).to.equal(width); - expect(data.imp[0].video.h).to.equal(height); - expect(data.imp[0].bidfloor).to.equal(bidRequest.params.bidfloor); - expect(data.ext.prebidver).to.equal('$prebid.version$'); - expect(data.ext.adapterver).to.equal(spec.VERSION); - }); - - it('should set pubId to e2etest when bid.params.video.e2etest = true', function () { - bidRequest.params.video.e2etest = true; - const requests = spec.buildRequests([bidRequest], bidderRequest); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.equal(spec.ENDPOINT + '?pid=e2etest'); - }); - - it('should attach End 2 End test data', function () { - bidRequest.params.video.e2etest = true; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.imp[0].bidfloor).to.not.exist; - expect(data.imp[0].video.w).to.equal(640); - expect(data.imp[0].video.h).to.equal(480); - }); - - it('should send Global schain', function () { - bidRequest.params.video.sid = null; - const globalSchain = { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'some-platform.com', - sid: '111111', - rid: bidRequest.id, - hp: 1 - }] - }; - bidRequest.ortb2 = bidRequest.ortb2 || {}; - bidRequest.ortb2.source = bidRequest.ortb2.source || {}; - bidRequest.ortb2.source.ext = bidRequest.ortb2.source.ext || {}; - bidRequest.ortb2.source.ext.schain = globalSchain; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - const schain = data.source.ext.schain; - expect(schain.nodes.length).to.equal(1); - expect(schain).to.deep.equal(globalSchain); - }); - - describe('content object validations', function () { - it('should not accept content object if value is Undefined ', function () { - bidRequest.params.video.content = null; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.site.content).to.be.undefined; - }); - it('should not accept content object if value is is Array ', function () { - bidRequest.params.video.content = []; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.site.content).to.be.undefined; - }); - it('should not accept content object if value is Number ', function () { - bidRequest.params.video.content = 123456; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.site.content).to.be.undefined; - }); - it('should not accept content object if value is String ', function () { - bidRequest.params.video.content = 'keyValuePairs'; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.site.content).to.be.undefined; - }); - it('should not accept content object if value is Boolean ', function () { - bidRequest.params.video.content = true; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.site.content).to.be.undefined; - }); - it('should accept content object if value is Object ', function () { - bidRequest.params.video.content = {}; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.site.content).to.be.a('object'); - }); - - it('should not append unsupported content object keys', function () { - bidRequest.params.video.content = { - fake: 'news', - unreal: 'param', - counterfit: 'data' - }; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.site.content).to.be.empty; - }); - - it('should not append content string parameters if value is not string ', function () { - bidRequest.params.video.content = { - id: 1234, - title: ['Title'], - series: ['Series'], - season: ['Season'], - genre: ['Genre'], - contentrating: {1: 'C-Rating'}, - language: {1: 'EN'} - }; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.site.content).to.be.a('object'); - expect(data.site.content).to.be.empty - }); - it('should not append content Number parameters if value is not Number ', function () { - bidRequest.params.video.content = { - episode: '1', - context: 'context', - livestream: {0: 'stream'}, - len: [360], - prodq: [1], - }; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.site.content).to.be.a('object'); - expect(data.site.content).to.be.empty - }); - it('should not append content Array parameters if value is not Array ', function () { - bidRequest.params.video.content = { - cat: 'categories', - }; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.site.content).to.be.a('object'); - expect(data.site.content).to.be.empty - }); - it('should not append content ext if value is not Object ', function () { - bidRequest.params.video.content = { - ext: 'content.ext', - }; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.site.content).to.be.a('object'); - expect(data.site.content).to.be.empty - }); - it('should append supported parameters if value match validations ', function () { - bidRequest.params.video.content = { - id: '1234', - title: 'Title', - series: 'Series', - season: 'Season', - cat: [ - 'IAB1' - ], - genre: 'Genre', - contentrating: 'C-Rating', - language: 'EN', - episode: 1, - prodq: 1, - context: 1, - livestream: 0, - len: 360, - ext: {} - }; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.site.content).to.deep.equal(bidRequest.params.video.content); - }); - }); - }); - describe('price floor module validations', function () { - beforeEach(function () { - bidRequest.getFloor = (floorObj) => { - return { - floor: bidRequest.floors.values[floorObj.mediaType + '|640x480'], - currency: floorObj.currency, - mediaType: floorObj.mediaType - } - } - }); - - it('should get bidfloor from getFloor method', function () { - bidRequest.params.cur = 'EUR'; - bidRequest.floors = { - currency: 'EUR', - values: { - 'video|640x480': 5.55 - } - }; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.imp[0].bidfloor).is.a('number'); - expect(data.imp[0].bidfloor).to.equal(5.55); - }); - it('should get bidfloor from params method', function () { - bidRequest.params.bidfloor = 4.0; - bidRequest.params.currency = 'EUR'; - bidRequest.getFloor = null; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.imp[0].bidfloor).is.a('number'); - expect(data.imp[0].bidfloor).to.equal(4.0); - expect(data.imp[0].bidfloorcur).to.equal('EUR'); - }); - - it('should use adUnit/module currency & floor instead of bid.params.bidfloor', function () { - bidRequest.params.cur = 'EUR'; - bidRequest.params.bidfloor = 3.33; - bidRequest.floors = { - currency: 'EUR', - values: { - 'video|640x480': 5.55 - } - }; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.imp[0].bidfloor).is.a('number'); - expect(data.imp[0].bidfloor).to.equal(5.55); - }); - - it('should load video floor when multi-format adUnit is present', function () { - bidRequest.params.cur = 'EUR'; - bidRequest.mediaTypes.banner = { - sizes: [ - [640, 480] - ] - }; - bidRequest.floors = { - currency: 'EUR', - values: { - 'banner|640x480': 2.22, - 'video|640x480': 9.99 - } - }; - const requests = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(requests[0].data); - expect(data.imp[0].bidfloor).is.a('number'); - expect(data.imp[0].bidfloor).to.equal(9.99); - }) - }) - - describe('spec.interpretResponse', function () { - it('should return no bids if the response is not valid', function () { - const bidResponse = spec.interpretResponse({ - body: null - }, { - bidRequest - }); - expect(bidResponse.length).to.equal(0); - }); - - it('should return no bids if the response "nurl" and "adm" are missing', function () { - const serverResponse = { - seatbid: [{ - bid: [{ - price: 6.01 - }] - }] - }; - const bidResponse = spec.interpretResponse({ - body: serverResponse - }, { - bidRequest - }); - expect(bidResponse.length).to.equal(0); - }); - - it('should return no bids if the response "price" is missing', function () { - const serverResponse = { - seatbid: [{ - bid: [{ - adm: '' - }] - }] - }; - const bidResponse = spec.interpretResponse({ - body: serverResponse - }, { - bidRequest - }); - expect(bidResponse.length).to.equal(0); - }); - - it('should return a valid video bid response with just "adm"', function () { - const serverResponse = { - id: '123', - seatbid: [{ - bid: [{ - id: 1, - adid: 123, - crid: 2, - price: 6.01, - adm: '', - adomain: [ - 'videobyte.com' - ], - w: 640, - h: 480 - }] - }], - cur: 'USD' - }; - const bidResponse = spec.interpretResponse({ - body: serverResponse - }, { - bidRequest - }); - const o = { - requestId: serverResponse.id, - cpm: serverResponse.seatbid[0].bid[0].price, - creativeId: serverResponse.seatbid[0].bid[0].crid, - vastXml: serverResponse.seatbid[0].bid[0].adm, - width: 640, - height: 480, - mediaType: 'video', - currency: 'USD', - ttl: 300, - netRevenue: true, - meta: { - advertiserDomains: ['videobyte.com'] - } - }; - expect(bidResponse[0]).to.deep.equal(o); - }); - - it('should default ttl to 300', function () { - const serverResponse = {seatbid: [{bid: [{id: 1, adid: 123, crid: 2, price: 6.01, adm: ''}]}], cur: 'USD'}; - const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); - expect(bidResponse[0].ttl).to.equal(300); - }); - it('should not allow ttl above 3601, default to 300', function () { - bidRequest.params.video.ttl = 3601; - const serverResponse = {seatbid: [{bid: [{id: 1, adid: 123, crid: 2, price: 6.01, adm: ''}]}], cur: 'USD'}; - const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); - expect(bidResponse[0].ttl).to.equal(300); - }); - it('should not allow ttl below 1, default to 300', function () { - bidRequest.params.video.ttl = 0; - const serverResponse = {seatbid: [{bid: [{id: 1, adid: 123, crid: 2, price: 6.01, adm: ''}]}], cur: 'USD'}; - const bidResponse = spec.interpretResponse({ body: serverResponse }, { bidRequest }); - expect(bidResponse[0].ttl).to.equal(300); - }); - }); - - describe('when GDPR and uspConsent applies', function () { - beforeEach(function () { - bidderRequest = { - 'gdprConsent': { - 'consentString': 'test-gdpr-consent-string', - 'gdprApplies': true - }, - 'uspConsent': '1YN-', - 'bidderCode': 'videobyte', - 'auctionId': 'e158486f-8c7f-472f-94ce-b0cbfbb50ab4', - 'bidderRequestId': '1e498b84fffc39', - 'bids': bidRequest, - 'auctionStart': 1520001292880, - 'timeout': 3000, - 'start': 1520001292884, - 'doneCbCallCount': 0, - 'refererInfo': { - 'numIframes': 1, - 'reachedTop': true, - 'referer': 'test.com' - } - }; - - mockConfig = { - consentManagement: { - gdpr: { - cmpApi: 'iab', - timeout: 3000, - allowAuctionWithoutConsent: 'cancel' - }, - usp: { - cmpApi: 'iab', - timeout: 1000, - allowAuctionWithoutConsent: 'cancel' - } - } - }; - }); - - it('should send a signal to specify that GDPR applies to this request', function () { - const request = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(request[0].data); - expect(data.regs.ext.gdpr).to.equal(1); - }); - - it('should send the consent string', function () { - const request = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(request[0].data); - expect(data.user.ext.consent).to.equal(bidderRequest.gdprConsent.consentString); - }); - - it('should send the uspConsent string', function () { - const request = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(request[0].data); - expect(data.regs.ext.us_privacy).to.equal(bidderRequest.uspConsent); - }); - - it('should send the uspConsent and GDPR ', function () { - const request = spec.buildRequests([bidRequest], bidderRequest); - const data = JSON.parse(request[0].data); - expect(data.regs.ext.gdpr).to.equal(1); - expect(data.regs.ext.us_privacy).to.equal(bidderRequest.uspConsent); - }); - }); - - describe('getUserSyncs', function () { - const ortbResponse = { - 'body': { - 'ext': { - 'usersync': { - 'sovrn': { - 'status': 'none', - 'syncs': [ - { - 'url': 'urlsovrn', - 'type': 'iframe' - } - ] - }, - 'appnexus': { - 'status': 'none', - 'syncs': [ - { - 'url': 'urlappnexus', - 'type': 'pixel' - } - ] - } - } - } - } - }; - it('handles no parameters', function () { - const opts = spec.getUserSyncs({}); - expect(opts).to.be.an('array').that.is.empty; - }); - it('returns non if sync is not allowed', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: false}); - - expect(opts).to.be.an('array').that.is.empty; - }); - - it('iframe sync enabled should return results', function () { - const opts = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: false}, [ortbResponse]); - - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('iframe'); - expect(opts[0].url).to.equal(ortbResponse.body.ext.usersync['sovrn'].syncs[0].url); - }); - - it('pixel sync enabled should return results', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [ortbResponse]); - - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('image'); - expect(opts[0].url).to.equal(ortbResponse.body.ext.usersync['appnexus'].syncs[0].url); - }); - - it('all sync enabled should return only iframe result', function () { - const opts = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, [ortbResponse]); - - expect(opts.length).to.equal(1); - }); - }); -}); diff --git a/test/spec/modules/videoheroesBidAdapter_spec.js b/test/spec/modules/videoheroesBidAdapter_spec.js deleted file mode 100644 index e06b04f3f..000000000 --- a/test/spec/modules/videoheroesBidAdapter_spec.js +++ /dev/null @@ -1,363 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/videoheroesBidAdapter.js'; - -const request_native = { - code: 'videoheroes-native-prebid', - mediaTypes: { - native: { - title: { - required: true, - len: 800 - }, - image: { - required: true, - len: 80 - }, - sponsoredBy: { - required: true - }, - clickUrl: { - required: true - }, - privacyLink: { - required: false - }, - body: { - required: true - }, - icon: { - required: true, - sizes: [50, 50] - } - } - }, - bidder: 'videoheroes', - params: { - placementId: '1a8d9c22db19906cb8a5fd4518d05f62' - } -}; - -const request_banner = { - code: 'videoheroes-prebid', - mediaTypes: { - banner: { - sizes: [[300, 250]] - } - }, - bidder: 'videoheroes', - params: { - placementId: '1a8d9c22db19906cb8a5fd4518d05f62' - } -} - -const bidRequest = { - gdprConsent: { - consentString: 'HFIDUYFIUYIUYWIPOI87392DSU', - gdprApplies: true - }, - uspConsent: 'uspConsentString', - bidderRequestId: 'testid', - refererInfo: { - referer: 'testdomain.com' - }, - timeout: 700 -} - -const request_video = { - code: 'videoheroes-video-prebid', - mediaTypes: { video: { - minduration: 1, - maxduration: 999, - boxingallowed: 1, - skip: 0, - mimes: [ - 'application/javascript', - 'video/mp4' - ], - playerSize: [[768, 1024]], - protocols: [ - 2, 3 - ], - linearity: 1, - api: [ - 1, - 2 - ] - } - }, - - bidder: 'videoheroes', - params: { - placementId: '1a8d9c22db19906cb8a5fd4518d05f62' - } - -} - -const response_banner = { - id: 'request_id', - bidid: 'request_imp_id', - seatbid: [{ - bid: [{ - id: 'bid_id', - impid: 'request_imp_id', - price: 5, - adomain: ['example.com'], - adm: 'admcode', - crid: 'crid', - ext: { - mediaType: 'banner' - } - }] - }] -}; - -const response_video = { - id: 'request_id', - bidid: 'request_imp_id', - seatbid: [{ - bid: [{ - id: 'bid_id', - impid: 'request_imp_id', - price: 5, - adomain: ['example.com'], - adm: 'admcode', - crid: 'crid', - ext: { - mediaType: 'video' - } - }], - }], -}; - -const imgData = { - url: `https://example.com/image`, - w: 1200, - h: 627 -}; - -const response_native = { - id: 'request_id', - bidid: 'request_imp_id', - seatbid: [{ - bid: [{ - id: 'bid_id', - impid: 'request_imp_id', - price: 5, - adomain: ['example.com'], - adm: { native: - { - assets: [ - {id: 1, title: 'dummyText'}, - {id: 3, image: imgData}, - { - id: 5, - data: {value: 'organization.name'} - } - ], - link: {url: 'example.com'}, - imptrackers: ['tracker1.com', 'tracker2.com', 'tracker3.com'], - jstracker: 'tracker1.com' - } - }, - crid: 'crid', - ext: { - mediaType: 'native' - } - }], - }], -}; - -describe('VideoheroesBidAdapter', function() { - describe('isBidRequestValid', function() { - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(request_banner)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const bid = Object.assign({}, request_banner); - bid.params = { - 'IncorrectParam': 0 - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('build Native Request', function () { - const request = spec.buildRequests([request_native], bidRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(request).to.exist; - expect(request.method).to.exist; - expect(request.url).to.exist; - expect(request.data).to.exist; - }); - - it('sends bid request to our endpoint via POST', function () { - expect(request.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(request.url).to.equal('https://point.contextualadv.com/?t=2&partner=1a8d9c22db19906cb8a5fd4518d05f62'); - }); - - it('Returns empty data if no valid requests are passed', function () { - const serverRequest = spec.buildRequests([]); - expect(serverRequest).to.be.an('array').that.is.empty; - }); - }); - - describe('build Banner Request', function () { - const request = spec.buildRequests([request_banner], bidRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(request).to.exist; - expect(request.method).to.exist; - expect(request.url).to.exist; - expect(request.data).to.exist; - }); - - it('sends bid request to our endpoint via POST', function () { - expect(request.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(request.url).to.equal('https://point.contextualadv.com/?t=2&partner=1a8d9c22db19906cb8a5fd4518d05f62'); - }); - }); - - describe('build Video Request', function () { - const request = spec.buildRequests([request_video], bidRequest); - - it('Creates a ServerRequest object with method, URL and data', function () { - expect(request).to.exist; - expect(request.method).to.exist; - expect(request.url).to.exist; - expect(request.data).to.exist; - }); - - it('sends bid request to our endpoint via POST', function () { - expect(request.method).to.equal('POST'); - }); - - it('Returns valid URL', function () { - expect(request.url).to.equal('https://point.contextualadv.com/?t=2&partner=1a8d9c22db19906cb8a5fd4518d05f62'); - }); - }); - - describe('interpretResponse', function () { - it('Empty response must return empty array', function() { - const emptyResponse = null; - const response = spec.interpretResponse(emptyResponse); - - expect(response).to.be.an('array').that.is.empty; - }) - - it('Should interpret banner response', function () { - const bannerResponse = { - body: response_banner - } - - const expectedBidResponse = { - requestId: response_banner.seatbid[0].bid[0].impid, - cpm: response_banner.seatbid[0].bid[0].price, - width: response_banner.seatbid[0].bid[0].w, - height: response_banner.seatbid[0].bid[0].h, - ttl: response_banner.ttl || 1200, - currency: response_banner.cur || 'USD', - netRevenue: true, - creativeId: response_banner.seatbid[0].bid[0].crid, - dealId: response_banner.seatbid[0].bid[0].dealid, - mediaType: 'banner', - ad: response_banner.seatbid[0].bid[0].adm - } - - const bannerResponses = spec.interpretResponse(bannerResponse); - - expect(bannerResponses).to.be.an('array').that.is.not.empty; - const dataItem = bannerResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'ad', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType'); - expect(dataItem.requestId).to.equal(expectedBidResponse.requestId); - expect(dataItem.cpm).to.equal(expectedBidResponse.cpm); - expect(dataItem.ad).to.equal(expectedBidResponse.ad); - expect(dataItem.ttl).to.equal(expectedBidResponse.ttl); - expect(dataItem.creativeId).to.equal(expectedBidResponse.creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(expectedBidResponse.currency); - expect(dataItem.width).to.equal(expectedBidResponse.width); - expect(dataItem.height).to.equal(expectedBidResponse.height); - }); - - it('Should interpret video response', function () { - const videoResponse = { - body: response_video - } - - const expectedBidResponse = { - requestId: response_video.seatbid[0].bid[0].impid, - cpm: response_video.seatbid[0].bid[0].price, - width: response_video.seatbid[0].bid[0].w, - height: response_video.seatbid[0].bid[0].h, - ttl: response_video.ttl || 1200, - currency: response_video.cur || 'USD', - netRevenue: true, - creativeId: response_video.seatbid[0].bid[0].crid, - dealId: response_video.seatbid[0].bid[0].dealid, - mediaType: 'video', - vastXml: response_video.seatbid[0].bid[0].adm - } - - const videoResponses = spec.interpretResponse(videoResponse); - - expect(videoResponses).to.be.an('array').that.is.not.empty; - const dataItem = videoResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'vastXml', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType'); - expect(dataItem.requestId).to.equal(expectedBidResponse.requestId); - expect(dataItem.cpm).to.equal(expectedBidResponse.cpm); - expect(dataItem.vastXml).to.equal(expectedBidResponse.vastXml) - expect(dataItem.ttl).to.equal(expectedBidResponse.ttl); - expect(dataItem.creativeId).to.equal(expectedBidResponse.creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(expectedBidResponse.currency); - expect(dataItem.width).to.equal(expectedBidResponse.width); - expect(dataItem.height).to.equal(expectedBidResponse.height); - }); - - it('Should interpret native response', function () { - const nativeResponse = { - body: response_native - } - - const expectedBidResponse = { - requestId: response_native.seatbid[0].bid[0].impid, - cpm: response_native.seatbid[0].bid[0].price, - width: response_native.seatbid[0].bid[0].w, - height: response_native.seatbid[0].bid[0].h, - ttl: response_native.ttl || 1200, - currency: response_native.cur || 'USD', - netRevenue: true, - creativeId: response_native.seatbid[0].bid[0].crid, - dealId: response_native.seatbid[0].bid[0].dealid, - mediaType: 'native', - native: {clickUrl: response_native.seatbid[0].bid[0].adm.native.link.url} - } - - const nativeResponses = spec.interpretResponse(nativeResponse); - - expect(nativeResponses).to.be.an('array').that.is.not.empty; - const dataItem = nativeResponses[0]; - expect(dataItem).to.have.all.keys('requestId', 'cpm', 'width', 'height', 'native', 'ttl', 'creativeId', - 'netRevenue', 'currency', 'dealId', 'mediaType'); - expect(dataItem.requestId).to.equal(expectedBidResponse.requestId); - expect(dataItem.cpm).to.equal(expectedBidResponse.cpm); - expect(dataItem.native.clickUrl).to.equal(expectedBidResponse.native.clickUrl) - expect(dataItem.ttl).to.equal(expectedBidResponse.ttl); - expect(dataItem.creativeId).to.equal(expectedBidResponse.creativeId); - expect(dataItem.netRevenue).to.be.true; - expect(dataItem.currency).to.equal(expectedBidResponse.currency); - expect(dataItem.width).to.equal(expectedBidResponse.width); - expect(dataItem.height).to.equal(expectedBidResponse.height); - }); - }); -}) diff --git a/test/spec/modules/videonowBidAdapter_spec.js b/test/spec/modules/videonowBidAdapter_spec.js deleted file mode 100644 index c9eb5ba0b..000000000 --- a/test/spec/modules/videonowBidAdapter_spec.js +++ /dev/null @@ -1,80 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/videonowBidAdapter'; - -describe('videonowBidAdapter', function () { - it('minimal params', function () { - expect(spec.isBidRequestValid({ - bidder: 'videonow', - params: { - pId: 'advDesktopBillboard' - }})).to.equal(true) - }) - - it('minimal params no placementId', function () { - expect(spec.isBidRequestValid({ - bidder: 'videonow', - params: { - currency: `GBP` - }})).to.equal(false) - }) - - it('generated_params common case', function () { - const bidRequestData = [{ - bidId: 'bid1234', - bidder: 'videonow', - params: { - pId: 'advDesktopBillboard', - currency: `GBP` - }, - sizes: [[240, 400]] - }]; - - const request = spec.buildRequests(bidRequestData); - const req_data = request[0].data; - - expect(req_data.places[0].id).to.equal(`bid1234`) - expect(req_data.places[0].placementId).to.equal(`advDesktopBillboard`) - expect(req_data.settings.currency).to.equal(`GBP`) - expect(req_data.places[0].sizes[0][0]).to.equal(240); - expect(req_data.places[0].sizes[0][1]).to.equal(400); - }); - - it('response_params common case', function () { - const bidRequestData = { - data: { - bidId: 'bid1234' - } - }; - - const serverResponse = { - body: { - bids: [ - { - 'displayCode': 'test html', - 'id': '123456', - 'cpm': 375, - 'currency': 'RUB', - 'placementId': 'profileName', - 'codeType': 'js', - 'size': { - 'width': 640, - 'height': 480 - } - } - ] - } - }; - - const bids = spec.interpretResponse(serverResponse, bidRequestData); - expect(bids).to.have.lengthOf(1); - const bid = bids[0]; - expect(bid.requestId).to.equal('123456') - expect(bid.cpm).to.equal(375); - expect(bid.currency).to.equal('RUB'); - expect(bid.width).to.equal(640); - expect(bid.height).to.equal(480); - expect(bid.ad).to.equal('test html'); - expect(bid.creativeId).to.equal(`123456`) - expect(bid.netRevenue).to.equal(true); - }); -}) diff --git a/test/spec/modules/videoreachBidAdapter_spec.js b/test/spec/modules/videoreachBidAdapter_spec.js deleted file mode 100644 index 82c7a1539..000000000 --- a/test/spec/modules/videoreachBidAdapter_spec.js +++ /dev/null @@ -1,145 +0,0 @@ -import {expect} from 'chai'; -import {spec} from 'modules/videoreachBidAdapter.js'; -import {newBidder} from 'src/adapters/bidderFactory.js'; - -const ENDPOINT_URL = 'https://a.videoreach.com/hb/'; - -describe('videoreachBidAdapter', function () { - describe('isBidRequestValid', function () { - const bid = { - 'params': { - 'TagId': 'ABCDE' - }, - 'bidId': '242d506d4e4f15', - 'bidderRequestId': '1893a2136a84a2', - 'auctionId': '8fb7b1c7-317b-4edf-83f0-c4669a318522', - 'transactionId': '85a2e190-0684-4f95-ad32-6c90757ed622' - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - delete invalidBid.params; - invalidBid.params = { - 'TagId': '' - }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - 'bidder': 'videoreach', - 'params': { - 'TagId': 'ABCDE' - }, - 'adUnitCode': 'adzone', - 'auctionId': '8fb7b1c7-317b-4edf-83f0-c4669a318522', - 'sizes': [[1, 1]], - 'bidId': '242d506d4e4f15', - 'bidderRequestId': '1893a2136a84a2', - 'transactionId': '85a2e190-0684-4f95-ad32-6c90757ed622', - 'mediaTypes': { - 'banner': { - 'sizes': [1, 1] - }, - } - } - ]; - - it('send bid request to endpoint', function () { - const request = spec.buildRequests(bidRequests); - - expect(request.url).to.equal(ENDPOINT_URL); - expect(request.method).to.equal('POST'); - }); - - it('send bid request with GDPR to endpoint', function () { - const consentString = 'BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA'; - - const bidderRequest = { - 'gdprConsent': { - 'consentString': consentString, - 'gdprApplies': true - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - const payload = JSON.parse(request.data); - - expect(payload.gdpr.consent_required).to.exist; - expect(payload.gdpr.consent_string).to.equal(consentString); - }); - }); - - describe('interpretResponse', function () { - const serverResponse = - { - 'body': { - 'responses': [{ - 'bidId': '242d506d4e4f15', - 'transactionId': '85a2e190-0684-4f95-ad32-6c90757ed622', - 'cpm': 10.0, - 'width': '1', - 'height': '1', - 'ad': '', - 'ttl': 360, - 'creativeId': '5cb5dc9375c0e', - 'netRevenue': true, - 'currency': 'EUR', - 'sync': ['https:\/\/SYNC_URL'], - 'adomain': [] - }] - } - }; - - it('should handle response', function() { - const expectedResponse = [ - { - cpm: 10.0, - width: '1', - height: '1', - currency: 'EUR', - netRevenue: true, - ttl: 360, - ad: '', - requestId: '242d506d4e4f15', - creativeId: '5cb5dc9375c0e', - meta: { - advertiserDomains: [] - } - } - ]; - - const result = spec.interpretResponse(serverResponse); - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); - }); - - it('should handles empty response', function() { - const serverResponse = { - 'body': { - 'responses': [] - } - }; - - const result = spec.interpretResponse(serverResponse); - expect(result.length).to.equal(0); - }); - - describe('getUserSyncs', () => { - it('should push user sync images if enabled', () => { - const syncOptions = { pixelEnabled: true }; - const syncs = spec.getUserSyncs(syncOptions, [serverResponse]); - - expect(syncs[0]).to.deep.equal({ - type: 'image', - url: 'https://SYNC_URL' - }); - }) - }); - }); -}); diff --git a/test/spec/modules/vidoomyBidAdapter_spec.js b/test/spec/modules/vidoomyBidAdapter_spec.js deleted file mode 100644 index 449e33f3e..000000000 --- a/test/spec/modules/vidoomyBidAdapter_spec.js +++ /dev/null @@ -1,452 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/vidoomyBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { INSTREAM } from '../../../src/video.js'; - -const ENDPOINT = `https://d.vidoomy.com/api/rtbserver/prebid/`; -const PIXELS = ['/test.png', '/test2.png?gdpr={{GDPR}}&gdpr_consent={{GDPR_CONSENT}}'] - -describe('vidoomyBidAdapter', function() { - const adapter = newBidder(spec); - - describe('isBidRequestValid', function () { - let bid; - beforeEach(() => { - bid = { - 'bidder': 'vidoomy', - 'params': { - pid: '123123', - id: '123123', - bidfloor: 0.5 - }, - 'adUnitCode': 'code', - 'sizes': [[300, 250]] - }; - }); - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when pid is empty', function () { - bid.params.pid = ''; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when bidfloor is invalid', function () { - bid.params.bidfloor = 'not a number'; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when id is empty', function () { - bid.params.id = ''; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when required params are not passed', function () { - const invalidBid = Object.assign({}, bid); - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when mediaType is video with INSTREAM context and lacks playerSize property', function () { - bid.params.mediaTypes = { - video: { - context: INSTREAM - } - } - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidRequests = [ - { - 'bidder': 'vidoomy', - 'params': { - pid: '123123', - id: '123123' - }, - 'adUnitCode': 'code', - 'mediaTypes': { - 'banner': { - 'context': 'outstream', - 'sizes': [[300, 250], [200, 100]] - } - }, - 'ortb2': { - 'source': { - 'ext': { - 'schain': { - ver: '1.0', - complete: 1, - nodes: [ - { - 'asi': 'exchange1.com', - 'sid': '1234!abcd', - 'hp': 1, - 'rid': 'bid-request-1', - 'name': 'publisher, Inc.', - 'domain': 'publisher.com' - }, - { - 'asi': 'exchange2.com', - 'sid': 'abcd', - 'hp': 1 - }, - { - 'asi': 'exchange2.com', - 'sid': 'abcd', - 'hp': 1, - 'rid': 'bid-request-2', - 'name': 'intermediary', - 'domain': 'intermediary.com' - } - ] - } - } - } - } - }, - { - 'bidder': 'vidoomy', - 'params': { - pid: '456456', - id: '456456' - }, - 'mediaTypes': { - 'video': { - 'context': 'outstream', - 'playerSize': [400, 225], - } - }, - 'adUnitCode': 'code2', - } - ]; - - const bidderRequest = { - refererInfo: { - numIframes: 0, - reachedTop: true, - domain: 'example.com', - page: 'http://example.com', - stack: ['http://example.com'] - } - }; - - const request = spec.buildRequests(bidRequests, bidderRequest); - - it('sends bid request to our endpoint via GET', function () { - expect(request[0].method).to.equal('GET'); - expect(request[1].method).to.equal('GET'); - }); - - it('attaches source and version to endpoint URL as query params', function () { - expect(request[0].url).to.equal(ENDPOINT); - expect(request[1].url).to.equal(ENDPOINT); - }); - - it('accepts all width and height sizes', function () { - expect(request[0].data.w).to.equal('300,200'); - expect(request[0].data.h).to.equal('250,100'); - expect(request[1].data.w).to.equal('400'); - expect(request[1].data.h).to.equal('225'); - }); - - it('should send id and pid parameters', function () { - expect('' + request[0].data.id).to.equal('123123'); - expect('' + request[0].data.pid).to.equal('123123'); - expect('' + request[1].data.id).to.equal('456456'); - expect('' + request[1].data.pid).to.equal('456456'); - }); - - it('should send multiBidsSupport parameters', function () { - expect('' + request[0].data.multiBidsSupport).to.equal('1'); - expect('' + request[1].data.multiBidsSupport).to.equal('1'); - }); - - it('should send schain parameter in serialized form', function () { - const serializedForm = '1.0,1!exchange1.com,1234%21abcd,1,bid-request-1,publisher%2C%20Inc.,publisher.com!exchange2.com,abcd,1,,,!exchange2.com,abcd,1,bid-request-2,intermediary,intermediary.com' - expect(request[0].data).to.include.any.keys('schain'); - expect(request[0].data.schain).to.eq(serializedForm); - }); - - it('should return standard json formated eids', function () { - const eids = [{ - source: 'pubcid.org', - uids: [ - { - id: 'some-random-id-value-1', - atype: 1 - } - ] - }, - { - source: 'adserver.org', - uids: [{ - id: 'some-random-id-value-2', - atype: 1 - }] - }] - bidRequests[0].userIdAsEids = eids - const bidRequest = spec.buildRequests(bidRequests, bidderRequest); - expect(bidRequest[0].data).to.include.any.keys('eids'); - expect(JSON.parse(bidRequest[0].data.eids)).to.eql(eids); - }); - - it('should set the bidfloor if getFloor module is undefined but static bidfloor is present', function () { - const request = { ...bidRequests[0], params: { bidfloor: 2.5 } } - const req = spec.buildRequests([request], bidderRequest)[0]; - expect(req.data).to.include.any.keys('bidfloor'); - expect(req.data.bidfloor).to.equal(2.5); - }); - - describe('floorModule', function () { - const getFloordata = { - 'currency': 'USD', - 'floor': 1.60 - }; - bidRequests[0].getFloor = _ => { - return getFloordata; - }; - it('should return getFloor.floor if present', function () { - const request = spec.buildRequests(bidRequests, bidderRequest)[0]; - expect(request.data.bidfloor).to.equal(getFloordata.floor); - }); - it('should return the getFloor.floor if it is greater than static bidfloor', function () { - const bidfloor = 1.40; - const request = { ...bidRequests[0] }; - request.params.bidfloor = bidfloor; - const bidRequest = spec.buildRequests([request], bidderRequest)[0]; - expect(bidRequest.data.bidfloor).to.equal(getFloordata.floor); - }); - it('should return the static bidfloor if it is greater than getFloor.floor', function () { - const bidfloor = 1.90; - const request = { ...bidRequests[0] }; - request.params.bidfloor = bidfloor; - const bidRequest = spec.buildRequests([request], bidderRequest)[0]; - expect(bidRequest.data.bidfloor).to.equal(bidfloor); - }); - }); - - describe('badv, bcat, bapp, btype, battr', function () { - const bidderRequestNew = { - ...bidderRequest, - bcat: ['EX1', 'EX2', 'EX3'], - badv: ['site.com'], - bapp: ['app.com'], - btype: [1, 2, 3], - battr: [1, 2, 3] - } - const request = spec.buildRequests(bidRequests, bidderRequestNew); - it('should have badv, bcat, bapp, btype, battr in request', function () { - expect(request[0].data).to.include.any.keys('badv'); - expect(request[0].data).to.include.any.keys('bcat'); - expect(request[0].data).to.include.any.keys('bapp'); - expect(request[0].data).to.include.any.keys('btype'); - expect(request[0].data).to.include.any.keys('battr'); - }) - - it('should have equal badv, bcat, bapp, btype, battr in request', function () { - expect(request[0].badv).to.deep.equal(bidderRequest.refererInfo.badv); - expect(request[0].bcat).to.deep.equal(bidderRequest.refererInfo.bcat); - expect(request[0].bapp).to.deep.equal(bidderRequest.refererInfo.bapp); - expect(request[0].btype).to.deep.equal(bidderRequest.refererInfo.btype); - expect(request[0].battr).to.deep.equal(bidderRequest.refererInfo.battr); - }) - }) - - describe('first party data', function () { - const bidderRequest2 = { - ...bidderRequest, - ortb2: { - bcat: ['EX1', 'EX2', 'EX3'], - badv: ['site.com'], - bapp: ['app.com'], - btype: [1, 2, 3], - battr: [1, 2, 3] - } - } - const request = spec.buildRequests(bidRequests, bidderRequest2); - - it('should have badv, bcat, bapp, btype, battr in request and equal to bidderRequest.ortb2', function () { - expect(request[0].data.bcat).to.deep.equal(bidderRequest2.ortb2.bcat) - expect(request[0].data.badv).to.deep.equal(bidderRequest2.ortb2.badv) - expect(request[0].data.bapp).to.deep.equal(bidderRequest2.ortb2.bapp); - expect(request[0].data.btype).to.deep.equal(bidderRequest2.ortb2.btype); - expect(request[0].data.battr).to.deep.equal(bidderRequest2.ortb2.battr); - }); - }); - }); - - describe('interpretResponse', function () { - const serverResponseVideo = { - body: [{ - 'vastUrl': 'https:\/\/vpaid.vidoomy.com\/demo-ad\/tag.xml', - 'mediaType': 'video', - 'requestId': '123123', - 'cpm': 3.265, - 'currency': 'USD', - 'width': 0, - 'height': 300, - 'creativeId': '123123', - 'dealId': '23cb20aa264b72', - 'netRevenue': true, - 'ttl': 60, - 'meta': { - 'mediaType': 'video', - 'rendererUrl': 'https:\/\/vpaid.vidoomy.com\/outstreamplayer\/bundle.js', - 'advertiserDomains': ['vidoomy.com'], - 'advertiserId': 123, - 'advertiserName': 'Vidoomy', - 'agencyId': null, - 'agencyName': null, - 'brandId': null, - 'brandName': null, - 'dchain': null, - 'networkId': null, - 'networkName': null, - 'primaryCatId': 'IAB3-1', - 'secondaryCatIds': null - } - }, - { - 'vastUrl': 'https:\/\/vpaid.vidoomy.com\/demo-ad-two\/tag.xml', - 'mediaType': 'video', - 'requestId': '102030', - 'cpm': 5.265, - 'currency': 'USD', - 'width': 10, - 'height': 400, - 'creativeId': '112233', - 'dealId': '23cb20aa264b72c', - 'netRevenue': true, - 'ttl': 80, - 'meta': { - 'mediaType': 'video', - 'rendererUrl': 'https:\/\/vpaid.vidoomy.com\/outstreamplayer\/bundle.js', - 'advertiserDomains': ['vidoomy.com'], - 'advertiserId': 123, - 'advertiserName': 'Vidoomy', - 'agencyId': null, - 'agencyName': null, - 'brandId': null, - 'brandName': null, - 'dchain': null, - 'networkId': null, - 'networkName': null, - 'primaryCatId': 'IAB3-1', - 'secondaryCatIds': null - } - }] - } - - const serverResponseBanner = { - body: [{ - 'ad': '` + - `` + - `');` - } - } - }]; - const bidderRequest = generateBuildRequestMock({}).bidderRequest; - - it('for only iframe enabled syncs', () => { - const syncOptions = { - iframeEnabled: true, - pixelEnabled: false - }; - const pixelObjects = spec.getUserSyncs( - syncOptions, - SERVER_RESPONSES, - bidderRequest.gdprConsent, - bidderRequest.uspConsent, - bidderRequest.gppConsent - ); - expect(pixelObjects.length).to.equal(2); - - pixelObjects.forEach(pixelObject => { - expect(pixelObject).to.have.all.keys('type', 'url'); - expect(pixelObject.type).to.equal('iframe'); - }); - }); - - it('for only pixel enabled syncs', () => { - const syncOptions = { - iframeEnabled: false, - pixelEnabled: true - }; - const pixelObjects = spec.getUserSyncs( - syncOptions, - SERVER_RESPONSES, - bidderRequest.gdprConsent, - bidderRequest.uspConsent, - bidderRequest.gppConsent - ); - expect(pixelObjects.length).to.equal(1); - expect(pixelObjects[0]).to.have.all.keys('type', 'url'); - expect(pixelObjects[0].type).to.equal('image'); - }); - - it('for both pixel and iframe enabled syncs', () => { - const syncOptions = { - iframeEnabled: true, - pixelEnabled: true - }; - const pixelObjects = spec.getUserSyncs( - syncOptions, - SERVER_RESPONSES, - bidderRequest.gdprConsent, - bidderRequest.uspConsent, - bidderRequest.gppConsent - ); - expect(pixelObjects.length).to.equal(3); - let iframeCount = 0; - let imageCount = 0; - pixelObjects.forEach(pixelObject => { - if (pixelObject.type === 'iframe') { - iframeCount++; - } else if (pixelObject.type === 'image') { - imageCount++; - } - }); - expect(iframeCount).to.equal(2); - expect(imageCount).to.equal(1); - }); - - describe('user consent parameters are updated', () => { - const syncOptions = { - iframeEnabled: true, - pixelEnabled: true - }; - describe('when all consent data is set', () => { - const pixelObjects = spec.getUserSyncs( - syncOptions, - SERVER_RESPONSES, - bidderRequest.gdprConsent, - bidderRequest.uspConsent, - bidderRequest.gppConsent - ); - pixelObjects.forEach(pixelObject => { - const url = pixelObject.url; - const urlParams = new URL(url).searchParams; - const expectedParams = { - 'baz': 'true', - 'gdpr_consent': bidderRequest.gdprConsent.consentString, - 'gdpr': bidderRequest.gdprConsent.gdprApplies ? '1' : '0', - 'us_privacy': bidderRequest.uspConsent, - 'gpp': bidderRequest.gppConsent.gppString, - 'gpp_sid': Array.isArray(bidderRequest.gppConsent.applicableSections) ? bidderRequest.gppConsent.applicableSections.join(',') : '' - } - for (const [key, value] of Object.entries(expectedParams)) { - it(`Updates the ${key} consent param in user sync URL ${url}`, () => { - expect(urlParams.get(key)).to.equal(value); - }); - }; - }); - }); - - describe('when no consent data is set', () => { - const pixelObjects = spec.getUserSyncs( - syncOptions, - SERVER_RESPONSES, - undefined, - undefined, - undefined - ); - pixelObjects.forEach(pixelObject => { - const url = pixelObject.url; - const urlParams = new URL(url).searchParams; - const expectedParams = { - 'baz': 'true', - 'gdpr_consent': '', - 'gdpr': '0', - 'us_privacy': '', - 'gpp': '', - 'gpp_sid': '' - } - for (const [key, value] of Object.entries(expectedParams)) { - it(`Updates the ${key} consent param in user sync URL ${url}`, () => { - expect(urlParams.get(key)).to.equal(value); - }); - }; - }); - }); - }); - }); - - // Validate Bid Requests - describe('isBidRequestValid()', () => { - const INVALID_INPUT = [ - {}, - {params: {}}, - {params: {dcn: '2c9d2b50015a5aa95b70a9b0b5b10012'}}, - {params: {dcn: 1234, pos: 'header'}}, - {params: {dcn: '2c9d2b50015a5aa95b70a9b0b5b10012', pos: 1234}}, - {params: {dcn: '2c9d2b50015a5aa95b70a9b0b5b10012', pos: ''}}, - {params: {dcn: '', pos: 'header'}}, - ]; - - INVALID_INPUT.forEach(input => { - it(`should determine that the bid is INVALID for the input ${JSON.stringify(input)}`, () => { - expect(spec.isBidRequestValid(input)).to.be.false; - }); - }); - - it('should determine that the bid is VALID if dcn and pos are present on the params object', () => { - const validBid = { - params: { - dcn: '2c9d2b50015a5aa95b70a9b0b5b10012', - pos: 'header' - } - }; - expect(spec.isBidRequestValid(validBid)).to.be.true; - }); - - it('should mark bid as VALID if bid.params.testing.e2etest = "true" (dcn & pos not required)', () => { - const validBid = { - params: { - dcn: 8888, - pos: 9999, - testing: { - e2etest: true - } - } - }; - expect(spec.isBidRequestValid(validBid)).to.be.true; - }); - - it('should mark bid ad VALID if pubId exists instead of dcn & pos', () => { - const validBid = { - params: { - pubId: DEFAULT_PUBID - } - }; - expect(spec.isBidRequestValid(validBid)).to.be.true; - }); - }); - - describe('Price Floor module support:', () => { - it('should get bidfloor from getFloor method', () => { - const { bidRequest, validBidRequests, bidderRequest } = generateBuildRequestMock({}); - bidRequest.params.bidOverride = {cur: 'EUR'}; - bidRequest.getFloor = (floorObj) => { - return { - floor: bidRequest.floors.values[floorObj.mediaType + '|640x480'], - currency: floorObj.currency, - mediaType: floorObj.mediaType - } - }; - bidRequest.floors = { - currency: 'EUR', - values: { - 'banner|640x480': 5.55 - } - }; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.cur).to.deep.equal(['EUR']); - expect(data.imp[0].bidfloor).is.a('number'); - expect(data.imp[0].bidfloor).to.equal(5.55); - }); - }); - - describe('Schain module support:', () => { - it('should not include schain data when schain array is empty', function () { - const { bidRequest, validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const globalSchain = { - ver: '1.0', - complete: 1, - nodes: [] - }; - bidRequest.ortb2 = bidRequest.ortb2 || {}; - bidRequest.ortb2.source = bidRequest.ortb2.source || {}; - bidRequest.ortb2.source.ext = bidRequest.ortb2.source.ext || {}; - bidRequest.ortb2.source.ext.schain = globalSchain; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - const schain = data.source.ext.schain; - expect(schain).to.be.undefined; - }); - - it('should send Global or Bidder specific schain', function () { - const { bidRequest, validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const globalSchain = { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'some-platform.com', - sid: '111111', - rid: bidRequest.bidId, - hp: 1 - }] - }; - bidRequest.ortb2 = bidRequest.ortb2 || {}; - bidRequest.ortb2.source = bidRequest.ortb2.source || {}; - bidRequest.ortb2.source.ext = bidRequest.ortb2.source.ext || {}; - bidRequest.ortb2.source.ext.schain = globalSchain; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - const schain = data.source.ext.schain; - expect(schain.nodes.length).to.equal(1); - expect(schain).to.equal(globalSchain); - }); - }); - - describe('First party data module - "Site" support (ortb2):', () => { - // Should not allow invalid "site" data types - const INVALID_ORTB2_TYPES = [ null, [], 123, 'unsupportedKeyName', true, false, undefined ]; - INVALID_ORTB2_TYPES.forEach(param => { - it(`should not allow invalid site types to be added to bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { site: param } - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site[param]).to.be.undefined; - }); - }); - - // Should add valid "site" params - const VALID_SITE_STRINGS = ['name', 'domain', 'page', 'ref', 'keywords', 'search']; - const VALID_SITE_ARRAYS = ['cat', 'sectioncat', 'pagecat']; - - VALID_SITE_STRINGS.forEach(param => { - it(`should allow supported site keys to be added bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - [param]: 'something' - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site[param]).to.exist; - expect(data.site[param]).to.be.a('string'); - expect(data.site[param]).to.be.equal(ortb2.site[param]); - }); - }); - - VALID_SITE_ARRAYS.forEach(param => { - it(`should determine that the ortb2.site Array key is valid and append to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - [param]: ['something'] - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site[param]).to.exist; - expect(data.site[param]).to.be.a('array'); - expect(data.site[param]).to.be.equal(ortb2.site[param]); - }); - }); - - // Should not allow invalid "site.content" data types - INVALID_ORTB2_TYPES.forEach(param => { - it(`should determine that the ortb2.site.content key is invalid and should not be added to bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - content: param - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.content).to.be.undefined; - }); - }); - - // Should not allow invalid "site.content" keys - it(`should not allow invalid ortb2.site.content object keys to be added to bid-request: {custom object}`, () => { - const ortb2 = { - site: { - content: { - fake: 'news', - unreal: 'param', - counterfit: 'data' - } - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.content).to.be.a('object'); - }); - - // Should append valid "site.content" keys - const VALID_CONTENT_STRINGS = ['id', 'title', 'series', 'season', 'genre', 'contentrating', 'language']; - VALID_CONTENT_STRINGS.forEach(param => { - it(`should determine that the ortb2.site String key is valid and append to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - content: { - [param]: 'something' - } - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.content[param]).to.exist; - expect(data.site.content[param]).to.be.a('string'); - expect(data.site.content[param]).to.be.equal(ortb2.site.content[param]); - }); - }); - - const VALID_CONTENT_NUMBERS = ['episode', 'prodq', 'context', 'livestream', 'len']; - VALID_CONTENT_NUMBERS.forEach(param => { - it(`should determine that the ortb2.site.content Number key is valid and append to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - content: { - [param]: 1234 - } - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.content[param]).to.be.a('number'); - expect(data.site.content[param]).to.be.equal(ortb2.site.content[param]); - }); - }); - - const VALID_PUBLISHER_OBJECTS = ['ext']; - VALID_PUBLISHER_OBJECTS.forEach(param => { - it(`should determine that the ortb2.site.publisher Object key is valid and append to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - publisher: { - [param]: {a: '123', b: '456'} - } - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.publisher[param]).to.be.a('object'); - expect(data.site.publisher[param]).to.be.equal(ortb2.site.publisher[param]); - }); - }); - - const VALID_CONTENT_ARRAYS = ['cat']; - VALID_CONTENT_ARRAYS.forEach(param => { - it(`should determine that the ortb2.site Array key is valid and append to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - content: { - [param]: ['something', 'something-else'] - } - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.content[param]).to.be.a('array'); - expect(data.site.content[param]).to.be.equal(ortb2.site.content[param]); - }); - }); - - const VALID_CONTENT_OBJECTS = ['ext']; - VALID_CONTENT_OBJECTS.forEach(param => { - it(`should determine that the ortb2.site.content Object key is valid and append to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - site: { - content: { - [param]: {a: '123', b: '456'} - } - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.content[param]).to.be.a('object'); - expect(data.site.content[param]).to.be.equal(ortb2.site.content[param]); - }); - }); - }); - - describe('First party data module - "User" support (ortb2):', () => { - // Global ortb2.user validations - // Should not allow invalid "user" data types - const INVALID_ORTB2_TYPES = [ null, [], 'unsupportedKeyName', true, false, undefined ]; - INVALID_ORTB2_TYPES.forEach(param => { - it(`should not allow invalid site types to be added to bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { user: param } - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.user[param]).to.be.undefined; - }); - }); - - // Should add valid "user" params - const VALID_USER_STRINGS = ['id', 'buyeruid', 'gender', 'keywords', 'customdata']; - VALID_USER_STRINGS.forEach(param => { - it(`should allow supported user string keys to be added bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - user: { - [param]: 'something' - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.user[param]).to.exist; - expect(data.user[param]).to.be.a('string'); - expect(data.user[param]).to.be.equal(ortb2.user[param]); - }); - }); - - const VALID_USER_NUMBERS = ['yob']; - VALID_USER_NUMBERS.forEach(param => { - it(`should allow supported user number keys to be added bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - user: { - [param]: 1982 - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.user[param]).to.exist; - expect(data.user[param]).to.be.a('number'); - expect(data.user[param]).to.be.equal(ortb2.user[param]); - }); - }); - - const VALID_USER_ARRAYS = ['data']; - VALID_USER_ARRAYS.forEach(param => { - it(`should allow supported user Array keys to be added to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - user: { - [param]: ['something'] - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.user[param]).to.exist; - expect(data.user[param]).to.be.a('array'); - expect(data.user[param]).to.be.equal(ortb2.user[param]); - }); - }); - - const VALID_USER_OBJECTS = ['ext']; - VALID_USER_OBJECTS.forEach(param => { - it(`should allow supported user extObject keys to be added to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - user: { - [param]: {a: '123', b: '456'} - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - const user = data.user; - expect(user[param]).to.be.a('object'); - expect(user[param]).to.be.deep.include({[param]: {a: '123', b: '456'}}); - }); - }); - - // Should allow valid user.data && site.content.data - const VALID_USER_DATA_STRINGS = ['id', 'name']; - VALID_USER_DATA_STRINGS.forEach(param => { - it(`should allow supported user.data & site.content.data strings to be added to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - user: { - data: [{[param]: 'string'}] - }, - site: { - content: { - data: [{[param]: 'string'}] - } - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - const user = data.user; - const site = data.site; - expect(user.data[0][param]).to.exist; - expect(user.data[0][param]).to.be.a('string'); - expect(user.data[0][param]).to.be.equal(ortb2.user.data[0][param]); - expect(site.content.data[0][param]).to.exist; - expect(site.content.data[0][param]).to.be.a('string'); - expect(site.content.data[0][param]).to.be.equal(ortb2.site.content.data[0][param]); - }); - }); - - const VALID_USER_DATA_ARRAYS = ['segment'] - VALID_USER_DATA_ARRAYS.forEach(param => { - it(`should allow supported user data arrays to be added to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - user: { - data: [{[param]: [{id: 1}]}] - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - const user = data.user; - expect(user.data[0][param]).to.exist; - expect(user.data[0][param]).to.be.a('array'); - expect(user.data[0][param]).to.be.equal(ortb2.user.data[0][param]); - }); - }); - - const VALID_USER_DATA_OBJECTS = ['ext']; - VALID_USER_DATA_OBJECTS.forEach(param => { - it(`should allow supported user data objects to be added to the bid-request: ${JSON.stringify(param)}`, () => { - const ortb2 = { - user: { - data: [{[param]: {id: 'ext'}}] - } - }; - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - const user = data.user; - expect(user.data[0][param]).to.exist; - expect(user.data[0][param]).to.be.a('object'); - expect(user.data[0][param]).to.be.equal(ortb2.user.data[0][param]); - }); - }); - - // adUnit.ortb2Imp.ext.data - it(`should allow adUnit.ortb2Imp.ext.data object to be added to the bid-request`, () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}) - validBidRequests[0].ortb2Imp = { - ext: { - data: { - pbadslot: 'homepage-top-rect', - adUnitSpecificAttribute: '123' - } - } - }; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].ext.data).to.deep.equal(validBidRequests[0].ortb2Imp.ext.data); - }); - // adUnit.ortb2Imp.instl - it(`should allow adUnit.ortb2Imp.instl numeric boolean "1" to be added to the bid-request`, () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}) - validBidRequests[0].ortb2Imp = { - instl: 1 - }; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].instl).to.deep.equal(validBidRequests[0].ortb2Imp.instl); - }); - - it(`should prevent adUnit.ortb2Imp.instl boolean "true" to be added to the bid-request`, () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}) - validBidRequests[0].ortb2Imp = { - instl: true - }; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].instl).to.not.exist; - }); - - it(`should prevent adUnit.ortb2Imp.instl boolean "false" to be added to the bid-request`, () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}) - validBidRequests[0].ortb2Imp = { - instl: false - }; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].instl).to.not.exist; - }); - }); - - describe('e2etest mode support:', () => { - it(`should override DCN & POS when params.testing.e2etest = "true".`, () => { - const { bidRequest, validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const params = { - dcn: '1234', - pos: '5678', - testing: { - e2etest: true - } - } - bidRequest.params = params; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.id).to.be.equal('8a969516017a7a396ec539d97f540011'); - expect(data.imp[0].tagid).to.be.equal('8a969978017a7aaabab4ab0bc01a0009'); - expect(data.imp[0].ext.e2eTestMode).to.be.true; - }); - }); - - describe('GDPR & Consent & GPP:', () => { - it('should return request objects that do not send cookies if purpose 1 consent is not provided', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - bidderRequest.gdprConsent = { - consentString: 'BOtmiBKOtmiBKABABAENAFAAAAACeAAA', - apiVersion: 2, - vendorData: { - purpose: { - consents: { - '1': false - } - } - }, - gdprApplies: true - }; - const options = spec.buildRequests(validBidRequests, bidderRequest)[0].options; - expect(options.withCredentials).to.be.false; - }); - - it('set the GPP consent data from the data within the bid request', function () { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const clonedBidderRequest = {...bidderRequest}; - const data = spec.buildRequests(validBidRequests, clonedBidderRequest)[0].data; - expect(data.regs.ext.gpp).to.equal(bidderRequest.gppConsent.gppString); - expect(data.regs.ext.gpp_sid).to.eql(bidderRequest.gppConsent.applicableSections); - }); - - it('overrides the GPP consent data using data from the ortb2 config object', function () { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const ortb2 = { - regs: { - gpp: 'somegppstring', - gpp_sid: [6, 7] - } - }; - const clonedBidderRequest = {...bidderRequest, ortb2}; - const data = spec.buildRequests(validBidRequests, clonedBidderRequest)[0].data; - expect(data.regs.ext.gpp).to.equal(ortb2.regs.gpp); - expect(data.regs.ext.gpp_sid).to.eql(ortb2.regs.gpp_sid); - }); - }); - - describe('Endpoint & Impression Request Mode:', () => { - afterEach(() => { - config.setConfig({ - yahooAds: { - singleRequestMode: undefined - } - }); - }); - - VALID_BIDDER_CODES.forEach(bidderCode => { - it(`should route request to config override endpoint for ${bidderCode} override config`, () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({bidderCode}); - const testOverrideEndpoint = 'http://foo.bar.baz.com/bidderRequest'; - const cfg = {}; - cfg[bidderCode] = { - endpoint: testOverrideEndpoint - }; - config.setConfig(cfg); - const response = spec.buildRequests(validBidRequests, bidderRequest)[0]; - expect(response).to.deep.include( - { - method: 'POST', - url: testOverrideEndpoint - }); - }); - }); - - it('should route request to /bidRequest endpoint when dcn & pos present', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const response = spec.buildRequests(validBidRequests, bidderRequest); - expect(response[0]).to.deep.include({ - method: 'POST', - url: 'https://c2shb.pubgw.yahoo.com/bidRequest' - }); - }); - - it('should route request to /partners endpoint when pubId is present', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({pubIdMode: true}); - const response = spec.buildRequests(validBidRequests, bidderRequest); - expect(response[0]).to.deep.include({ - method: 'POST', - url: 'https://c2shb.pubgw.yahoo.com/admax/bid/partners/PBJS' - }); - }); - - it('should return a single request object for single request mode', () => { - let { bidRequest, validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const BID_ID_2 = '84ab50xxxxx'; - const BID_POS_2 = 'footer'; - const AD_UNIT_CODE_2 = 'test-ad-unit-code-123'; - const { bidRequest: bidRequest2 } = generateBuildRequestMock({bidId: BID_ID_2, pos: BID_POS_2, adUnitCode: AD_UNIT_CODE_2}); - validBidRequests = [bidRequest, bidRequest2]; - bidderRequest.bids = validBidRequests; - - config.setConfig({ - yahooAds: { - singleRequestMode: true - } - }); - - const responsePayload = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(responsePayload.imp).to.be.an('array').with.lengthOf(2); - - expect(responsePayload.imp[0]).to.deep.include({ - id: DEFAULT_BID_ID, - ext: { - pos: DEFAULT_BID_POS, - dfp_ad_unit_code: DEFAULT_AD_UNIT_CODE - } - }); - - expect(responsePayload.imp[1]).to.deep.include({ - id: BID_ID_2, - ext: { - pos: BID_POS_2, - dfp_ad_unit_code: AD_UNIT_CODE_2 - } - }); - }); - }); - - describe('Validate request filtering:', () => { - it('should not return request when no bids are present', function () { - const request = spec.buildRequests([]); - expect(request).to.be.undefined; - }); - - it('buildRequests(): should return an array with the correct amount of request objects', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const reqs = spec.buildRequests(validBidRequests, bidderRequest); - expect(reqs).to.be.an('array').to.have.lengthOf(1); - expect(reqs[0]).to.be.an('object').that.has.keys('method', 'url', 'data', 'options', 'bidderRequest'); - }); - }); - - describe('Request Headers validation:', () => { - it('should return request objects with the relevant custom headers and content type declaration', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - bidderRequest.gdprConsent.gdprApplies = false; - const options = spec.buildRequests(validBidRequests, bidderRequest)[0].options; - expect(options).to.deep.equal( - { - contentType: 'application/json', - customHeaders: { - 'x-openrtb-version': '2.5' - }, - withCredentials: true - }); - }); - }); - - describe('User data', () => { - it('should set the allowed sources user eids', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - validBidRequests[0].userIdAsEids = [ - {source: 'yahoo.com', uids: [{id: 'connectId_FROM_USER_ID_MODULE', atype: 3}]}, - {source: 'admixer.net', uids: [{id: 'admixerId_FROM_USER_ID_MODULE', atype: 3}]}, - {source: 'adtelligent.com', uids: [{id: 'adtelligentId_FROM_USER_ID_MODULE', atype: 3}]}, - {source: 'amxdt.net', uids: [{id: 'amxId_FROM_USER_ID_MODULE', atype: 1}]}, - {source: 'britepool.com', uids: [{id: 'britepoolid_FROM_USER_ID_MODULE', atype: 3}]}, - {source: 'deepintent.com', uids: [{id: 'deepintentId_FROM_USER_ID_MODULE', atype: 3}]}, - {source: 'epsilon.com', uids: [{id: 'publinkId_FROM_USER_ID_MODULE', atype: 3}]}, - {source: 'intentiq.com', uids: [{id: 'intentIqId_FROM_USER_ID_MODULE', atype: 1}]}, - {source: 'liveramp.com', uids: [{id: 'idl_env_FROM_USER_ID_MODULE', atype: 3}]}, - {source: 'intimatemerger.com', uids: [{id: 'imuid_FROM_USER_ID_MODULE', atype: 1}]}, - {source: 'criteo.com', uids: [{id: 'criteoId_FROM_USER_ID_MODULE', atype: 1}]}, - {source: 'neustar.biz', uids: [{id: 'fabrickId_FROM_USER_ID_MODULE', atype: 1}]} - ]; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - - expect(data.user.ext.eids).to.deep.equal(validBidRequests[0].userIdAsEids); - }); - - it('should not set not allowed user eids sources', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - validBidRequests[0].userIdAsEids = createEidsArray({ - justId: 'justId_FROM_USER_ID_MODULE' - }); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - - expect(data.user.ext.eids).to.deep.equal([]); - }); - }); - - describe('Request Payload oRTB bid validation:', () => { - it('should generate a valid openRTB bid-request object in the data field', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site).to.deep.equal({ - id: bidderRequest.bids[0].params.dcn, - page: bidderRequest.refererInfo.page - }); - - expect(data.device).to.deep.equal({ - dnt: 0, - ua: navigator.userAgent, - ip: undefined, - w: window.screen.width, - h: window.screen.height - }); - - expect(data.regs).to.deep.equal({ - ext: { - 'us_privacy': bidderRequest.uspConsent, - gdpr: 1, - gpp: bidderRequest.gppConsent.gppString, - gpp_sid: bidderRequest.gppConsent.applicableSections - } - }); - - expect(data.source).to.deep.equal({ - ext: { - hb: 1, - adapterver: ADAPTER_VERSION, - prebidver: PREBID_VERSION, - integration: { - name: INTEGRATION_METHOD, - ver: PREBID_VERSION - } - }, - fd: 1 - }); - - expect(data.user).to.deep.equal({ - ext: { - consent: bidderRequest.gdprConsent.consentString, - eids: [] - } - }); - - expect(data.cur).to.deep.equal(['USD']); - }); - - it('should generate a valid openRTB imp.ext object in the bid-request', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const bid = validBidRequests[0]; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].ext).to.deep.equal({ - pos: bid.params.pos, - dfp_ad_unit_code: DEFAULT_AD_UNIT_CODE - }); - }); - - it('should use siteId value as site.id in the outbound bid-request when using "pubId" integration mode', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({pubIdMode: true}); - validBidRequests[0].params.siteId = '1234567'; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.id).to.equal('1234567'); - }); - - it('should use site publisher ortb2 config in default integration mode', () => { - const ortb2 = { - site: { - publisher: { - ext: { - publisherblob: 'pblob', - bucket: 'bucket' - } - } - } - } - const { validBidRequests, bidderRequest } = generateBuildRequestMock({ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.publisher).to.deep.equal({ - ext: { - publisherblob: 'pblob', - bucket: 'bucket' - } - }); - }); - - it('should use site publisher ortb2 config when using "pubId" integration mode', () => { - const ortb2 = { - site: { - publisher: { - ext: { - publisherblob: 'pblob', - bucket: 'bucket' - } - } - } - } - const { validBidRequests, bidderRequest } = generateBuildRequestMock({pubIdMode: true, ortb2}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.site.publisher).to.deep.equal({ - id: DEFAULT_PUBID, - ext: { - publisherblob: 'pblob', - bucket: 'bucket' - } - }); - }); - - it('should use placementId value as imp.tagid in the outbound bid-request when using "pubId" integration mode', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({pubIdMode: true}); - validBidRequests[0].params.placementId = 'header-300x250'; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].tagid).to.deep.equal('header-300x250'); - }); - }); - - describe('Request Payload oRTB bid.imp validation:', () => { - it('should generate a valid "Banner" imp object when mode config override is undefined', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].video).to.not.exist; - expect(data.imp[0].banner).to.deep.equal({ - mimes: ['text/html', 'text/javascript', 'application/javascript', 'image/jpg'], - format: [{w: 300, h: 250}, {w: 300, h: 600}] - }); - }); - - // Validate Banner imp when config value for mode="banner" - VALID_BIDDER_CODES.forEach(bidderCode => { - it(`should generate a valid "Banner" imp object for ${bidderCode} config override`, () => { - const cfg = {}; - cfg[bidderCode] = { - mode: BANNER - }; - config.setConfig(cfg); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({bidderCode}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].video).to.not.exist; - expect(data.imp[0].banner).to.deep.equal({ - mimes: ['text/html', 'text/javascript', 'application/javascript', 'image/jpg'], - format: [{w: 300, h: 250}, {w: 300, h: 600}] - }); - }); - - // Validate Video imp - it(`should generate a valid "Video" only imp object for ${bidderCode} config override`, () => { - const cfg = {}; - cfg[bidderCode] = { - mode: VIDEO - }; - config.setConfig(cfg); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({bidderCode, adUnitType: 'video'}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].banner).to.not.exist; - expect(data.imp[0].video).to.deep.equal({ - mimes: ['video/mp4', 'application/javascript'], - w: 300, - h: 250, - api: [2], - protocols: [2, 5], - startdelay: 0, - linearity: 1, - maxbitrate: undefined, - maxduration: undefined, - minduration: undefined, - delivery: undefined, - pos: undefined, - playbackmethod: undefined, - rewarded: undefined, - placement: undefined, - plcmt: undefined - }); - }); - - // Validate multi-format Video+banner imp - it(`should generate a valid multi-format "Video + Banner" imp object for ${bidderCode} config override`, () => { - const cfg = {}; - cfg[bidderCode] = { - mode: 'all' - }; - config.setConfig(cfg); - const { validBidRequests, bidderRequest } = generateBuildRequestMock({bidderCode, adUnitType: 'multi-format'}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].banner).to.deep.equal({ - mimes: ['text/html', 'text/javascript', 'application/javascript', 'image/jpg'], - format: [{w: 300, h: 250}, {w: 300, h: 600}] - }); - expect(data.imp[0].video).to.deep.equal({ - mimes: ['video/mp4', 'application/javascript'], - w: 300, - h: 250, - api: [2], - protocols: [2, 5], - startdelay: 0, - linearity: 1, - maxbitrate: undefined, - maxduration: undefined, - minduration: undefined, - delivery: undefined, - pos: undefined, - playbackmethod: undefined, - rewarded: undefined, - placement: undefined, - plcmt: undefined - }); - }); - }); - - // Validate Key-Value Pairs - it('should generate supported String, Number, Array of Strings, Array of Numbers key-value pairs and append to imp.ext.kvs', () => { - const { validBidRequests, bidderRequest } = generateBuildRequestMock({}) - validBidRequests[0].params.kvp = { - key1: 'String', - key2: 123456, - key3: ['String', 'String', 'String'], - key4: [1, 2, 3], - invalidKey1: true, - invalidKey2: null, - invalidKey3: ['string', 1234], - invalidKey4: {a: 1, b: 2}, - invalidKey5: undefined - }; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].ext.kvs).to.deep.equal({ - key1: 'String', - key2: 123456, - key3: ['String', 'String', 'String'], - key4: [1, 2, 3] - }); - }); - }); - - describe('Multiple adUnit validations:', () => { - // Multiple banner adUnits - it('should generate multiple bid-requests for each adUnit - 2 banner only', () => { - const BID_ID_2 = '84ab50xxxxx'; - const BID_POS_2 = 'footer'; - const AD_UNIT_CODE_2 = 'test-ad-unit-code-123'; - const BID_ID_3 = '84ab50yyyyy'; - const BID_POS_3 = 'hero'; - const AD_UNIT_CODE_3 = 'video-ad-unit'; - - let { bidRequest, validBidRequests, bidderRequest } = generateBuildRequestMock({}); // banner - const { bidRequest: bidRequest2 } = generateBuildRequestMock({bidId: BID_ID_2, pos: BID_POS_2, adUnitCode: AD_UNIT_CODE_2}); // banner - const { bidRequest: bidRequest3 } = generateBuildRequestMock({bidId: BID_ID_3, pos: BID_POS_3, adUnitCode: AD_UNIT_CODE_3, adUnitType: 'video'}); // video (should be filtered) - validBidRequests = [bidRequest, bidRequest2, bidRequest3]; - bidderRequest.bids = validBidRequests; - - const reqs = spec.buildRequests(validBidRequests, bidderRequest) - expect(reqs).to.be.a('array'); - expect(reqs.length).to.equal(2); - reqs.forEach(req => { - expect(req.data.imp[0].video).to.not.exist - expect(req.data.imp[0].banner).to.deep.equal({ - mimes: ['text/html', 'text/javascript', 'application/javascript', 'image/jpg'], - format: [{w: 300, h: 250}, {w: 300, h: 600}] - }); - }); - }); - - // Multiple video adUnits - it('should generate multiple bid-requests for each adUnit - 2 video only', () => { - const cfg = {}; - cfg[DEFAULT_BIDDER_CODE] = { - mode: VIDEO - }; - config.setConfig(cfg); - const BID_ID_2 = '84ab50xxxxx'; - const BID_POS_2 = 'footer'; - const AD_UNIT_CODE_2 = 'test-ad-unit-code-123'; - const BID_ID_3 = '84ab50yyyyy'; - const BID_POS_3 = 'hero'; - const AD_UNIT_CODE_3 = 'video-ad-unit'; - - let {bidRequest, validBidRequests, bidderRequest} = generateBuildRequestMock({adUnitType: 'video'}); // video - const {bidRequest: bidRequest2} = generateBuildRequestMock({bidId: BID_ID_2, pos: BID_POS_2, adUnitCode: AD_UNIT_CODE_2, adUnitType: 'video'}); // video - const {bidRequest: bidRequest3} = generateBuildRequestMock({bidId: BID_ID_3, pos: BID_POS_3, adUnitCode: AD_UNIT_CODE_3}); // banner (should be filtered) - validBidRequests = [bidRequest, bidRequest2, bidRequest3]; - bidderRequest.bids = validBidRequests; - - const reqs = spec.buildRequests(validBidRequests, bidderRequest) - expect(reqs).to.be.a('array'); - expect(reqs.length).to.equal(2); - reqs.forEach(req => { - expect(req.data.imp[0].banner).to.not.exist - expect(req.data.imp[0].video).to.deep.equal({ - mimes: ['video/mp4', 'application/javascript'], - w: 300, - h: 250, - api: [2], - protocols: [2, 5], - startdelay: 0, - linearity: 1, - maxbitrate: undefined, - maxduration: undefined, - minduration: undefined, - delivery: undefined, - pos: undefined, - playbackmethod: undefined, - rewarded: undefined, - placement: undefined, - plcmt: undefined - }); - }); - }); - // Mixed adUnits 1-banner, 1-video, 1-native (should filter out native) - it('should generate multiple bid-requests for both "video & banner" adUnits', () => { - const cfg = {}; - cfg[DEFAULT_BIDDER_CODE] = { mode: 'all' }; - config.setConfig(cfg); - const BID_ID_2 = '84ab50xxxxx'; - const BID_POS_2 = 'footer'; - const AD_UNIT_CODE_2 = 'video-ad-unit'; - const BID_ID_3 = '84ab50yyyyy'; - const BID_POS_3 = 'hero'; - const AD_UNIT_CODE_3 = 'native-ad-unit'; - - let { bidRequest, validBidRequests, bidderRequest } = generateBuildRequestMock({adUnitType: 'banner'}); // banner - const { bidRequest: bidRequest2 } = generateBuildRequestMock({bidId: BID_ID_2, pos: BID_POS_2, adUnitCode: AD_UNIT_CODE_2, adUnitType: 'video'}); // video - const { bidRequest: bidRequest3 } = generateBuildRequestMock({bidId: BID_ID_3, pos: BID_POS_3, adUnitCode: AD_UNIT_CODE_3, adUnitType: 'native'}); // native (should be filtered) - validBidRequests = [bidRequest, bidRequest2, bidRequest3]; - bidderRequest.bids = validBidRequests; - - const reqs = spec.buildRequests(validBidRequests, bidderRequest); - expect(reqs).to.be.a('array'); - expect(reqs.length).to.equal(2); - reqs.forEach(req => { - expect(req.data.imp[0].native).to.not.exist; - }); - - const data1 = reqs[0].data; - expect(data1.imp[0].video).to.not.exist; - expect(data1.imp[0].banner).to.deep.equal({ - mimes: ['text/html', 'text/javascript', 'application/javascript', 'image/jpg'], - format: [{w: 300, h: 250}, {w: 300, h: 600}] - }); - - const data2 = reqs[1].data; - expect(data2.imp[0].banner).to.not.exist; - expect(data2.imp[0].video).to.deep.equal({ - mimes: ['video/mp4', 'application/javascript'], - w: 300, - h: 250, - api: [2], - protocols: [2, 5], - startdelay: 0, - linearity: 1, - maxbitrate: undefined, - maxduration: undefined, - minduration: undefined, - delivery: undefined, - pos: undefined, - playbackmethod: undefined, - rewarded: undefined, - placement: undefined, - plcmt: undefined - }); - }); - }); - - describe('Video params firstlook & bidOverride validations:', () => { - VALID_BIDDER_CODES.forEach(bidderCode => { - it(`should first look at params.bidOverride for video placement data for ${bidderCode} config override`, () => { - const cfg = {}; - cfg[bidderCode] = { - mode: VIDEO - }; - config.setConfig(cfg); - const bidOverride = { - imp: { - video: { - mimes: ['video/mp4'], - w: 400, - h: 350, - api: [1], - protocols: [1, 3], - startdelay: 0, - linearity: 1, - maxbitrate: 400000, - maxduration: 3600, - minduration: 1500, - delivery: 1, - pos: 123456, - playbackmethod: 1, - rewarded: 1, - placement: 1, - plcmt: 1 - } - } - } - const { validBidRequests, bidderRequest } = generateBuildRequestMock({bidderCode, adUnitType: 'video', bidOverrideObject: bidOverride}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].video).to.deep.equal(bidOverride.imp.video); - }); - - it(`should second look at bid.mediaTypes.video for video placement data for ${bidderCode} config override`, () => { - const cfg = {}; - cfg[bidderCode] = { - mode: VIDEO - }; - config.setConfig(cfg); - const { bidRequest, bidderRequest } = generateBuildRequestMock({bidderCode, adUnitType: 'video'}); - bidRequest.mediaTypes.video = { - mimes: ['video/mp4'], - playerSize: [400, 350], - api: [1], - protocols: [1, 3], - startdelay: 0, - linearity: 1, - maxbitrate: 400000, - maxduration: 3600, - minduration: 1500, - delivery: 1, - pos: 123456, - playbackmethod: 1, - placement: 1, - plcmt: 1 - } - const validBidRequests = [bidRequest]; - bidderRequest.bids = validBidRequests; - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.imp[0].video).to.deep.equal({ - mimes: ['video/mp4'], - w: 400, - h: 350, - api: [1], - protocols: [1, 3], - startdelay: 0, - linearity: 1, - maxbitrate: 400000, - maxduration: 3600, - minduration: 1500, - delivery: 1, - pos: 123456, - playbackmethod: 1, - placement: 1, - plcmt: 1, - rewarded: undefined - }); - }); - - it(`should use params.bidOverride.device.ip override for ${bidderCode} config override`, () => { - const cfg = {}; - cfg[bidderCode] = { - mode: 'all' - }; - config.setConfig(cfg); - const bidOverride = { - device: { - ip: '1.2.3.4' - } - } - const { validBidRequests, bidderRequest } = generateBuildRequestMock({bidderCode, adUnitType: 'video', bidOverrideObject: bidOverride}); - const data = spec.buildRequests(validBidRequests, bidderRequest)[0].data; - expect(data.device.ip).to.deep.equal(bidOverride.device.ip); - }); - }); - }); - // #endregion buildRequests(): - - describe('interpretResponse()', () => { - describe('for mediaTypes: "banner"', () => { - it('should insert banner payload into response[0].ad', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ad).to.equal(''); - expect(response[0].mediaType).to.equal('banner'); - }) - }); - - describe('for mediaTypes: "video"', () => { - beforeEach(() => { - config.setConfig({ - yahooAds: { - mode: VIDEO - } - }); - }); - - afterEach(() => { - config.setConfig({ - yahooAds: { - mode: undefined - } - }); - }); - - it('should insert video VPAID payload into vastXml', () => { - const { serverResponse, bidderRequest } = generateResponseMock('video'); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ad).to.be.undefined; - expect(response[0].vastXml).to.equal(''); - expect(response[0].mediaType).to.equal('video'); - }) - - describe('wrapped in video players for display inventory', () => { - beforeEach(() => { - config.setConfig({ - yahooAds: { - mode: undefined - } - }); - }); - - it('should insert video DAP O2 Player into ad', () => { - const { serverResponse, bidderRequest } = generateResponseMock('dap-o2', 'vpaid'); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ad).to.equal(''); - expect(response[0].vastUrl).to.be.undefined; - expect(response[0].vastXml).to.be.undefined; - expect(response[0].mediaType).to.equal('banner'); - }); - - it('should insert video DAP Unified Player into ad', () => { - const { serverResponse, bidderRequest } = generateResponseMock('dap-up', 'vpaid'); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ad).to.equal(''); - expect(response[0].vastUrl).to.be.undefined; - expect(response[0].vastXml).to.be.undefined; - expect(response[0].mediaType).to.equal('banner'); - }) - }); - }); - - describe('Support Advertiser domains', () => { - it('should append bid-response adomain to meta.advertiserDomains', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].meta.advertiserDomains).to.be.a('array'); - expect(response[0].meta.advertiserDomains[0]).to.equal('advertiser-domain.com'); - }) - }); - - describe('bid response Ad ID / Creative ID', () => { - it('should use adId if it exists in the bid-response', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - const adId = 'bid-response-adId'; - serverResponse.body.seatbid[0].bid[0].adId = adId; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].adId).to.equal(adId); - }); - - it('should use impid if adId does not exist in the bid-response', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - const impid = '25b6c429c1f52f'; - serverResponse.body.seatbid[0].bid[0].impid = impid; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].adId).to.equal(impid); - }); - - it('should use crid if adId & impid do not exist in the bid-response', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - const crid = 'passback-12579'; - serverResponse.body.seatbid[0].bid[0].impid = undefined; - serverResponse.body.seatbid[0].bid[0].crid = crid; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].adId).to.equal(crid); - }); - }); - - describe('Time To Live (ttl)', () => { - VALID_BIDDER_CODES.forEach(bidderCode => { - const UNSUPPORTED_TTL_FORMATS = ['string', [1, 2, 3], true, false, null, undefined]; - UNSUPPORTED_TTL_FORMATS.forEach(param => { - it(`should not allow unsupported global ${bidderCode}.ttl formats and default to 300`, () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - const cfg = {}; - cfg['yahooAds'] = { ttl: param }; - config.setConfig(cfg); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ttl).to.equal(300); - }); - - it('should not allow unsupported params.ttl formats and default to 300', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - bidderRequest.bids[0].params.ttl = param; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ttl).to.equal(300); - }); - }); - - const UNSUPPORTED_TTL_VALUES = [-1, 3601]; - UNSUPPORTED_TTL_VALUES.forEach(param => { - it('should not allow invalid global config ttl values 3600 < ttl < 0 and default to 300', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - config.setConfig({ - yahooAds: { ttl: param } - }); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ttl).to.equal(300); - }); - - it('should not allow invalid params.ttl values 3600 < ttl < 0 and default to 300', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - bidderRequest.bids[0].params.ttl = param; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ttl).to.equal(300); - }); - }); - - it('should give presedence to Gloabl ttl over params.ttl ', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - config.setConfig({ - yahooAds: { ttl: 500 } - }); - bidderRequest.bids[0].params.ttl = 400; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].ttl).to.equal(500); - }); - }); - }); - - describe('Aliasing support', () => { - it('should return undefined as the bidder code value', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(response[0].bidderCode).to.be.undefined; - }); - }); - - describe('Renderer:', () => { - it('should create and set renderer when bidder request context is outstream, bidder request renderer is falsy, and bid response mediaType is VIDEO', () => { - config.setConfig({ - yahooAds: { - mode: VIDEO - } - }); - const { serverResponse, bidderRequest } = generateResponseMock('video', 'vast'); - bidderRequest.mediaTypes = { - video: { - context: 'outstream' - } - }; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(deepAccess(bidderRequest, 'mediaTypes.video.context')).to.equal('outstream'); - expect(bidderRequest.renderer).to.be.undefined; - expect(response[0].mediaType).to.equal('video'); - expect(response[0].renderer).to.not.be.undefined; - }); - - it('should not create and set renderer when bidder request renderer is falsy and bid response mediaType is VIDEO, but bidder request context is not outstream,', () => { - config.setConfig({ - yahooAds: { - mode: VIDEO - } - }); - const { serverResponse, bidderRequest } = generateResponseMock('video', 'vast'); - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(deepAccess(bidderRequest, 'mediaTypes.video.context')).to.not.equal('outstream'); - expect(bidderRequest.renderer).to.be.undefined; - expect(response[0].mediaType).to.equal('video'); - expect(response[0].renderer).to.be.undefined; - }); - - it('should not create and set renderer when bidder request context is outstream and bid response mediaType is VIDEO, but bidder request renderer is not falsy', () => { - config.setConfig({ - yahooAds: { - mode: VIDEO - } - }); - const { serverResponse, bidderRequest } = generateResponseMock('video', 'vast'); - bidderRequest.mediaTypes = { - video: { - context: 'outstream' - } - }; - bidderRequest.renderer = 'not falsy'; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(deepAccess(bidderRequest, 'mediaTypes.video.context')).to.equal('outstream'); - expect(bidderRequest.renderer).to.not.be.undefined; - expect(response[0].mediaType).to.equal('video'); - expect(response[0].renderer).to.be.undefined; - }); - - it('should not create and set renderer when bidder request context is outstream and bidder request renderer is falsy, but bid response mediaType is not VIDEO', () => { - const { serverResponse, bidderRequest } = generateResponseMock('banner'); - bidderRequest.mediaTypes = { - video: { - context: 'outstream' - } - }; - const response = spec.interpretResponse(serverResponse, {bidderRequest}); - expect(deepAccess(bidderRequest, 'mediaTypes.video.context')).to.equal('outstream'); - expect(bidderRequest.renderer).to.be.undefined; - expect(response[0].mediaType).to.not.equal('video'); - expect(response[0].renderer).to.be.undefined; - }); - }); - }); -}); diff --git a/test/spec/modules/yandexAnalyticsAdapter_spec.js b/test/spec/modules/yandexAnalyticsAdapter_spec.js deleted file mode 100644 index a7a850b7c..000000000 --- a/test/spec/modules/yandexAnalyticsAdapter_spec.js +++ /dev/null @@ -1,164 +0,0 @@ -import * as sinon from 'sinon'; -import yandexAnalytics, { EVENTS_TO_TRACK, PBJS_INIT_EVENT_NAME } from 'modules/yandexAnalyticsAdapter.js'; -import * as log from '../../../src/utils.js' -import * as events from '../../../src/events.js'; -import * as globalUtils from '../../../src/prebidGlobal.js'; - -describe('Yandex analytics adapter testing', () => { - const sandbox = sinon.createSandbox(); - let clock; - let logError; - let getEvents; - let onEvent; - const counterId = 123; - const counterWindowKey = 'yaCounter123'; - const prebidVersion = '123.0'; - const prebidInitEvent = { - event: PBJS_INIT_EVENT_NAME, - data: { - version: prebidVersion, - }, - } - - beforeEach(() => { - yandexAnalytics.counters = {}; - yandexAnalytics.counterInitTimeouts = {}; - yandexAnalytics.bufferedEvents = []; - yandexAnalytics.oneCounterInited = false; - clock = sinon.useFakeTimers(); - logError = sandbox.stub(log, 'logError'); - sandbox.stub(globalUtils, 'getGlobal').returns({ - version: prebidVersion, - }); - sandbox.stub(log, 'logInfo'); - getEvents = sandbox.stub(events, 'getEvents').returns([]); - onEvent = sandbox.stub(events, 'on'); - sandbox.stub(window.document, 'createElement').callsFake((tag) => { - const element = { - tag, - events: {}, - attributes: {}, - addEventListener: (event, cb) => { - element.events[event] = cb; - }, - removeEventListener: (event, cb) => { - chai.expect(element.events[event]).to.equal(cb); - }, - setAttribute: (attr, val) => { - element.attributes[attr] = val; - }, - }; - return element; - }); - }); - - afterEach(() => { - window.Ya = null; - window[counterWindowKey] = null; - sandbox.restore(); - clock.restore(); - }); - - it('fails if timeout for counter insertion is exceeded', () => { - yandexAnalytics.enableAnalytics({ - options: { - counters: [ - 123, - ], - }, - }); - clock.tick(25001); - chai.expect(yandexAnalytics.bufferedEvents).to.deep.equal([]); - sinon.assert.calledWith(logError, `Can't find metrika counter after 25 seconds.`); - sinon.assert.calledWith(logError, `Aborting yandex analytics provider initialization.`); - }); - - it('fails if no valid counters provided', () => { - yandexAnalytics.enableAnalytics({ - options: { - counters: [ - 'abc', - ], - }, - }); - sinon.assert.calledWith(logError, 'options.counters contains no valid counter ids'); - }); - - it('subscribes to events if counter is already present', () => { - window[counterWindowKey] = { - pbjs: sandbox.stub(), - }; - - getEvents.returns([ - { - eventType: EVENTS_TO_TRACK[0], - }, - { - eventType: 'Some_untracked_event', - } - ]); - const eventsToSend = [ - prebidInitEvent, - { - event: EVENTS_TO_TRACK[0], - data: { - eventType: EVENTS_TO_TRACK[0], - } - } - ]; - - yandexAnalytics.enableAnalytics({ - options: { - counters: [ - counterId, - ], - }, - }); - - EVENTS_TO_TRACK.forEach((eventName, i) => { - const [event, callback] = onEvent.getCall(i).args; - chai.expect(event).to.equal(eventName); - callback(i); - eventsToSend.push({ - event: eventName, - data: i, - }); - }); - - clock.tick(1501); - - const [ sentEvents ] = window[counterWindowKey].pbjs.getCall(0).args; - chai.expect(sentEvents).to.deep.equal(eventsToSend); - }); - - it('waits for counter initialization', () => { - window.Ya = {}; - // Simulatin metrika script initialization - yandexAnalytics.enableAnalytics({ - options: { - counters: [ - counterId, - ], - }, - }); - - // Sending event - const [event, eventCallback] = onEvent.getCall(0).args; - eventCallback({}); - - const counterPbjsMethod = sandbox.stub(); - window[`yaCounter${counterId}`] = { - pbjs: counterPbjsMethod, - }; - clock.tick(2001); - - const [ sentEvents ] = counterPbjsMethod.getCall(0).args; - chai.expect(sentEvents).to.deep.equal([ - prebidInitEvent, - { - event, - data: {}, - } - ]); - }); -}); diff --git a/test/spec/modules/yandexBidAdapter_spec.js b/test/spec/modules/yandexBidAdapter_spec.js deleted file mode 100644 index 4382fae3e..000000000 --- a/test/spec/modules/yandexBidAdapter_spec.js +++ /dev/null @@ -1,954 +0,0 @@ -import { assert, expect } from 'chai'; -import { NATIVE_ASSETS, spec } from 'modules/yandexBidAdapter.js'; -import * as utils from 'src/utils.js'; -import * as ajax from 'src/ajax.js'; -import { config } from 'src/config.js'; -import { setConfig as setCurrencyConfig } from '../../../modules/currency.js'; -import { BANNER, NATIVE } from '../../../src/mediaTypes.js'; -import { addFPDToBidderRequest } from '../../helpers/fpd.js'; - -describe('Yandex adapter', function () { - let sandbox; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - - config.setConfig({ - yandex: { - sampling: 1.0, - }, - }); - }); - - afterEach(function () { - sandbox.restore(); - }); - - describe('isBidRequestValid', function () { - it('should return true when required params found', function () { - const bid = getBidRequest(); - assert(spec.isBidRequestValid(bid)); - }); - - it('should return false when required params not found', function () { - expect(spec.isBidRequestValid({})).to.be.false; - }); - - it('should return false when required params.placementId are not passed', function () { - const bid = getBidConfig(); - delete bid.params.placementId; - - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('should return false when required params.placementId are not valid', function () { - const bid = getBidConfig(); - bid.params.placementId = '123'; - - expect(spec.isBidRequestValid(bid)).to.be.false; - }); - - it('should return true when passed deprecated placement config', function () { - const bid = getBidConfig(); - delete bid.params.placementId; - - bid.params.pageId = 123; - bid.params.impId = 1; - - expect(spec.isBidRequestValid(bid)); - }); - }); - - describe('buildRequests', function () { - let mockBidRequests; - let mockBidderRequest; - - beforeEach(function () { - mockBidRequests = [{ - bidId: 'bid123', - params: { - placementId: 'R-I-123456-2', - } - }]; - mockBidderRequest = { - ortb2: { - device: { - language: 'fr' - }, - site: { - ext: { - data: { - documentLang: 'en' - } - } - } - } - }; - }); - - it('should set site.content.language from document language if it is not set', function () { - const requests = spec.buildRequests(mockBidRequests, mockBidderRequest); - expect(requests[0].data.site.content.language).to.equal('en'); - }); - - it('should preserve existing site.content.language if it is set', function () { - mockBidderRequest.ortb2.site.content = {language: 'es'}; - const requests = spec.buildRequests(mockBidRequests, mockBidderRequest); - expect(requests[0].data.site.content.language).to.equal('es'); - }); - - it('should do nothing when document language does not exist', function () { - delete mockBidderRequest.ortb2.site.ext.data.documentLang; - const requests = spec.buildRequests(mockBidRequests, mockBidderRequest); - expect(requests[0].data.site?.content?.language).to.be.undefined; - }); - - it('should return displaymanager', function () { - const requests = spec.buildRequests(mockBidRequests, mockBidderRequest); - expect(requests[0].data.imp[0].displaymanager).to.equal('Prebid.js'); - expect(requests[0].data.imp[0].displaymanagerver).to.not.be.undefined; - }); - - /** @type {import('../../../src/auction').BidderRequest} */ - const bidderRequest = { - ortb2: { - site: { - domain: 'ya.ru', - ref: 'https://ya.ru/', - page: 'https://ya.ru/', - publisher: { - domain: 'ya.ru', - }, - }, - device: { - w: 1600, - h: 900, - dnt: 0, - ua: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36', - language: 'en', - sua: { - source: 1, - platform: { - brand: 'macOS', - }, - browsers: [ - { - brand: 'Not_A Brand', - version: ['8'], - }, - { - brand: 'Chromium', - version: ['120'], - }, - { - brand: 'Google Chrome', - version: ['120'], - }, - ], - mobile: 0, - }, - }, - }, - gdprConsent: { - gdprApplies: 1, - consentString: 'concent-string', - apiVersion: 1, - }, - }; - - it('creates a valid banner request', function () { - const bannerRequest = getBidRequest(); - bannerRequest.getFloor = () => ({ - currency: 'EUR', - // floor: 0.5 - }); - - const requests = spec.buildRequests([bannerRequest], bidderRequest); - - expect(requests).to.have.lengthOf(1); - const request = requests[0]; - - expect(request).to.exist; - const { method, url, data } = request; - - expect(method).to.equal('POST'); - - const parsedRequestUrl = utils.parseUrl(url); - const { search: query } = parsedRequestUrl - - expect(parsedRequestUrl.hostname).to.equal('yandex.ru'); - expect(parsedRequestUrl.pathname).to.equal('/ads/prebid/123'); - - expect(query['imp-id']).to.equal('1'); - expect(query['target-ref']).to.equal('ya.ru'); - expect(query['ssp-id']).to.equal('10500'); - - expect(query['gdpr']).to.equal('1'); - expect(query['tcf-consent']).to.equal('concent-string'); - - expect(request.data).to.exist; - expect(data.site).to.not.equal(null); - expect(data.site.page).to.equal('https://ya.ru/'); - expect(data.site.ref).to.equal('https://ya.ru/'); - }); - - it('should send currency if defined', function () { - setCurrencyConfig({ - adServerCurrency: 'USD' - }); - - const bannerRequest = getBidRequest(); - - return addFPDToBidderRequest(bidderRequest).then(res => { - const requests = spec.buildRequests([bannerRequest], res); - const { url } = requests[0]; - const parsedRequestUrl = utils.parseUrl(url); - const { search: query } = parsedRequestUrl - - expect(query['ssp-cur']).to.equal('USD'); - setCurrencyConfig({}); - }); - }); - - it('should send eids and ortb2 user data if defined', function() { - const bidderRequestWithUserData = { - ...bidderRequest, - ortb2: { - ...bidderRequest.ortb2, - user: { - data: [ - { - ext: { segtax: 600, segclass: '1' }, - name: 'example.com', - segment: [{ id: '243' }], - }, - { - ext: { segtax: 600, segclass: '1' }, - name: 'ads.example.org', - segment: [{ id: '243' }], - }, - ], - }, - } - }; - const bidRequestExtra = { - userIdAsEids: [{ - source: 'sharedid.org', - uids: [{ id: '01', atype: 1 }], - }], - }; - - const expected = { - ext: { - eids: bidRequestExtra.userIdAsEids, - }, - data: bidderRequestWithUserData.ortb2.user.data, - }; - - const bannerRequest = getBidRequest(bidRequestExtra); - const requests = spec.buildRequests([bannerRequest], bidderRequestWithUserData); - - expect(requests).to.have.lengthOf(1); - const request = requests[0]; - - expect(request.data).to.exist; - const { data } = request; - - expect(data.user).to.exist; - expect(data.user).to.deep.equal(expected); - }); - - it('should send site', function() { - const expected = { - site: bidderRequest.ortb2.site - }; - - const requests = spec.buildRequests([getBidRequest()], bidderRequest); - - expect(requests[0].data.site).to.deep.equal(expected.site); - }); - - describe('banner', () => { - it('should create valid banner object', () => { - const bannerRequest = getBidRequest({ - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600] - ], - }, - } - }); - - const requests = spec.buildRequests([bannerRequest], bidderRequest); - expect(requests[0].data.imp).to.have.lengthOf(1); - - const imp = requests[0].data.imp[0]; - expect(imp.banner).to.not.equal(null); - expect(imp.banner.w).to.equal(300); - expect(imp.banner.h).to.equal(250); - - expect(imp.banner.format).to.deep.equal([ - { w: 300, h: 250 }, - { w: 300, h: 600 }, - ]); - }); - }); - - describe('video', function() { - function getVideoBidRequest(extra) { - const bannerRequest = getBidRequest(extra); - const requests = spec.buildRequests([bannerRequest], bidderRequest); - - return requests[0].data.imp[0].video; - } - - it('should map basic video parameters', function() { - const bidRequest = getVideoBidRequest({ - mediaTypes: { - video: { - context: 'instream', - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - protocols: [2, 3], - playbackmethod: [1], - w: 640, - h: 480, - startdelay: 0, - placement: 1, - skip: 1, - skipafter: 5, - minbitrate: 300, - maxbitrate: 1500, - delivery: [2], - api: [2], - linearity: 1, - battr: [1, 2, 3], - sizes: [[640, 480], [800, 600]] - } - } - }); - - expect(bidRequest).to.deep.equal({ - context: 'instream', - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - protocols: [2, 3], - playbackmethod: [1], - w: 640, - h: 480, - startdelay: 0, - placement: 1, - skip: 1, - skipafter: 5, - minbitrate: 300, - maxbitrate: 1500, - delivery: [2], - api: [2], - linearity: 1, - battr: [1, 2, 3], - format: [ - {w: 640, h: 480}, - {w: 800, h: 600} - ] - }); - }); - }); - - describe('native', () => { - function buildRequestAndGetNativeParams(extra) { - const bannerRequest = getBidRequest(extra); - const requests = spec.buildRequests([bannerRequest], bidderRequest); - - return JSON.parse(requests[0].data.imp[0].native.request); - } - - it('should extract native params', () => { - const nativeParams = buildRequestAndGetNativeParams({ - mediaTypes: { - native: { - title: { - required: true, - len: 100, - }, - body: { - len: 90 - }, - body2: { - len: 90 - }, - sponsoredBy: { - len: 25, - }, - icon: { - sizes: [32, 32], - }, - image: { - required: true, - sizes: [300, 250], - }, - }, - }, - }); - const sortedAssetsList = nativeParams.assets.sort((a, b) => a.id - b.id); - - expect(sortedAssetsList).to.deep.equal([ - { - id: NATIVE_ASSETS.title[0], - required: 1, - title: { - len: 100, - } - }, - { - id: NATIVE_ASSETS.body[0], - data: { - type: NATIVE_ASSETS.body[1], - len: 90, - }, - }, - { - id: NATIVE_ASSETS.body2[0], - data: { - type: NATIVE_ASSETS.body2[1], - len: 90, - }, - }, - { - id: NATIVE_ASSETS.sponsoredBy[0], - data: { - type: NATIVE_ASSETS.sponsoredBy[1], - len: 25, - }, - }, - { - id: NATIVE_ASSETS.icon[0], - img: { - type: NATIVE_ASSETS.icon[1], - w: 32, - h: 32, - }, - }, - { - id: NATIVE_ASSETS.image[0], - required: 1, - img: { - type: NATIVE_ASSETS.image[1], - w: 300, - h: 250, - }, - }, - ]); - }); - - it('should parse multiple image sizes', () => { - const nativeParams = buildRequestAndGetNativeParams({ - mediaTypes: { - native: { - image: { - sizes: [[300, 250], [100, 100]], - }, - }, - }, - }); - - expect(nativeParams.assets[0]).to.deep.equal({ - id: NATIVE_ASSETS.image[0], - img: { - type: NATIVE_ASSETS.image[1], - w: 300, - h: 250, - }, - }); - }); - - it('should parse aspect ratios with min_width', () => { - const nativeParams = buildRequestAndGetNativeParams({ - mediaTypes: { - native: { - image: { - aspect_ratios: [{ - min_width: 320, - ratio_width: 4, - ratio_height: 3, - }], - }, - }, - }, - }); - - expect(nativeParams.assets[0]).to.deep.equal({ - id: NATIVE_ASSETS.image[0], - img: { - type: NATIVE_ASSETS.image[1], - wmin: 320, - hmin: 240, - }, - }); - }); - - it('should parse aspect ratios without min_width', () => { - const nativeParams = buildRequestAndGetNativeParams({ - mediaTypes: { - native: { - image: { - aspect_ratios: [{ - ratio_width: 4, - ratio_height: 3, - }], - }, - }, - }, - }); - - expect(nativeParams.assets[0]).to.deep.equal({ - id: NATIVE_ASSETS.image[0], - img: { - type: NATIVE_ASSETS.image[1], - wmin: 100, - hmin: 75, - }, - }); - }); - - it('should include eventtrackers in the native request', () => { - const nativeParams = buildRequestAndGetNativeParams({ - mediaTypes: { - native: { - title: { required: true }, - }, - }, - }); - - expect(nativeParams.eventtrackers).to.deep.equal([{ event: 1, methods: [1] }]); - }); - }); - }); - - describe('interpretResponse', function () { - const bannerRequest = getBidRequest(); - - const bannerResponse = { - body: { - seatbid: [{ - bid: [ - { - impid: '1', - price: 0.3, - crid: 321, - adm: '', - mtype: 1, - w: 300, - h: 250, - adomain: [ - 'example.com' - ], - adid: 'yabs.123=', - nurl: 'https://example.com/nurl/?price=${AUCTION_PRICE}&cur=${AUCTION_CURRENCY}', - lurl: 'https://example.com/nurl/?reason=${AUCTION_LOSS}', - } - ] - }], - cur: 'USD', - }, - }; - - it('handles banner responses', function () { - bannerRequest.bidRequest = { - mediaType: BANNER, - bidId: 'bidid-1', - }; - const result = spec.interpretResponse(bannerResponse, bannerRequest); - - expect(result).to.have.lengthOf(1); - expect(result[0]).to.exist; - - const rtbBid = result[0]; - expect(rtbBid.width).to.equal(300); - expect(rtbBid.height).to.equal(250); - expect(rtbBid.cpm).to.be.within(0.3, 0.3); - expect(rtbBid.ad).to.equal(''); - expect(rtbBid.currency).to.equal('USD'); - expect(rtbBid.netRevenue).to.equal(true); - expect(rtbBid.ttl).to.equal(180); - expect(rtbBid.nurl).to.equal('https://example.com/nurl/?price=0.3&cur=USD'); - expect(rtbBid.lurl).to.exist; - - expect(rtbBid.meta.advertiserDomains).to.deep.equal(['example.com']); - }); - - describe('video', function() { - const videoBidRequest = { - bidRequest: { - mediaType: 'video', - bidId: 'videoBid1', - adUnitCode: 'videoAdUnit' - } - }; - - const sampleVideoResponse = { - body: { - seatbid: [{ - bid: [{ - impid: 'videoBid1', - price: 1.50, - adm: '', - mtype: 2, - w: 640, - h: 480, - adomain: ['advertiser.com'], - cid: 'campaign123', - crid: 'creative456', - nurl: 'https://tracker.example.com/win?price=${AUCTION_PRICE}' - }] - }], - cur: 'USD' - } - }; - - it('should handle valid video response', function() { - const result = spec.interpretResponse(sampleVideoResponse, videoBidRequest); - - expect(result).to.have.lengthOf(1); - const bid = result[0]; - - expect(bid).to.deep.include({ - requestId: 'videoBid1', - cpm: 1.50, - width: 640, - height: 480, - vastXml: '', - mediaType: 'video', - currency: 'USD', - ttl: 180, - meta: { - advertiserDomains: ['advertiser.com'] - } - }); - - expect(bid.nurl).to.equal('https://tracker.example.com/win?price=1.5'); - }); - }); - - describe('native', () => { - function getNativeAdmResponse() { - return { - native: { - link: { - url: 'https://example.com' - }, - imptrackers: [ - 'https://example.com/imptracker' - ], - assets: [ - { - title: { - text: 'title text', - }, - id: NATIVE_ASSETS.title[0], - }, - { - data: { - value: 'body text' - }, - id: NATIVE_ASSETS.body[0], - }, - { - data: { - value: 'sponsoredBy text' - }, - id: NATIVE_ASSETS.sponsoredBy[0], - }, - { - img: { - url: 'https://example.com/image', - w: 200, - h: 150, - }, - id: NATIVE_ASSETS.image[0], - }, - { - img: { - url: 'https://example.com/icon', - h: 32, - w: 32 - }, - id: NATIVE_ASSETS.icon[0], - }, - ] - } - }; - } - - it('handles native responses', function() { - bannerRequest.bidRequest = { - mediaType: NATIVE, - bidId: 'bidid-1', - }; - - const nativeAdmResponce = getNativeAdmResponse(); - const bannerResponse = { - body: { - seatbid: [{ - bid: [ - { - impid: 1, - price: 0.3, - adomain: [ - 'example.com' - ], - adid: 'yabs.123=', - adm: JSON.stringify(nativeAdmResponce), - mtype: 4, - }, - ], - }], - }, - }; - - const result = spec.interpretResponse(bannerResponse, bannerRequest); - - expect(result).to.have.lengthOf(1); - expect(result[0]).to.exist; - - const bid = result[0]; - expect(bid.meta.advertiserDomains).to.deep.equal(['example.com']); - expect(bid.native).to.deep.equal({ - clickUrl: 'https://example.com', - impressionTrackers: ['https://example.com/imptracker'], - title: 'title text', - body: 'body text', - sponsoredBy: 'sponsoredBy text', - image: { - url: 'https://example.com/image', - width: 200, - height: 150, - }, - icon: { - url: 'https://example.com/icon', - width: 32, - height: 32, - }, - }); - }); - - it('should add eventtrackers urls to impressionTrackers', function () { - bannerRequest.bidRequest = { - mediaType: NATIVE, - bidId: 'bidid-1', - }; - - const nativeAdmResponse = getNativeAdmResponse(); - nativeAdmResponse.native.eventtrackers = [ - { - event: 1, // TRACKER_EVENTS.impression - method: 1, // TRACKER_METHODS.img - url: 'https://example.com/imp-event-tracker', - }, - { - event: 2, - method: 2, - url: 'https://example.com/skip-me', - }, - ]; - - const bannerResponse = { - body: { - seatbid: [ - { - bid: [ - { - impid: 1, - price: 0.3, - adm: JSON.stringify(nativeAdmResponse), - mtype: 4, - }, - ], - }, - ], - }, - }; - - const result = spec.interpretResponse(bannerResponse, bannerRequest); - const bid = result[0]; - - expect(bid.native.impressionTrackers).to.include( - 'https://example.com/imptracker' - ); - expect(bid.native.impressionTrackers).to.include( - 'https://example.com/imp-event-tracker' - ); - expect(bid.native.impressionTrackers).to.not.include('https://example.com/skip-me'); - }); - - it('should handle missing imptrackers', function () { - bannerRequest.bidRequest = { - mediaType: NATIVE, - bidId: 'bidid-1', - }; - - const nativeAdmResponse = getNativeAdmResponse(); - delete nativeAdmResponse.native.imptrackers; - nativeAdmResponse.native.eventtrackers = [{ - event: 1, - method: 1, - url: 'https://example.com/fallback-tracker' - }]; - - const bannerResponse = { - body: { - seatbid: [{ - bid: [{ - impid: 1, - price: 0.3, - adm: JSON.stringify(nativeAdmResponse), - mtype: 4, - }] - }] - } - }; - - const result = spec.interpretResponse(bannerResponse, bannerRequest); - const bid = result[0]; - - expect(bid.native.impressionTrackers) - .to.deep.equal(['https://example.com/fallback-tracker']); - }); - - it('should handle missing eventtrackers', function () { - bannerRequest.bidRequest = { - mediaType: NATIVE, - bidId: 'bidid-1', - }; - - const nativeAdmResponse = getNativeAdmResponse(); - - const bannerResponse = { - body: { - seatbid: [{ - bid: [{ - impid: 1, - price: 0.3, - adm: JSON.stringify(nativeAdmResponse), - mtype: 4, - }] - }] - } - }; - - const result = spec.interpretResponse(bannerResponse, bannerRequest); - const bid = result[0]; - - expect(bid.native.impressionTrackers) - .to.deep.equal(['https://example.com/imptracker']); - }); - }); - }); - - describe('onBidWon', function() { - beforeEach(function() { - sinon.stub(utils, 'triggerPixel'); - }); - afterEach(function() { - utils.triggerPixel.restore(); - }); - - it('Should not trigger pixel if bid does not contain nurl', function() { - spec.onBidWon({}); - - expect(utils.triggerPixel.callCount).to.equal(0) - }) - - it('Should trigger pixel if bid has nurl', function() { - spec.onBidWon({ - nurl: 'https://example.com/some-tracker', - timeToRespond: 378, - }); - - expect(utils.triggerPixel.callCount).to.equal(1) - expect(utils.triggerPixel.getCall(0).args[0]).to.equal('https://example.com/some-tracker?rtt=378') - }) - - it('Should trigger pixel if bid has nurl with path & params', function() { - spec.onBidWon({ - nurl: 'https://example.com/some-tracker/abcdxyz?param1=1¶m2=2', - timeToRespond: 378, - }); - - expect(utils.triggerPixel.callCount).to.equal(1) - expect(utils.triggerPixel.getCall(0).args[0]).to.equal('https://example.com/some-tracker/abcdxyz?param1=1¶m2=2&rtt=378') - }) - - it('Should trigger pixel if bid has nurl with path & params and rtt macros', function() { - spec.onBidWon({ - nurl: 'https://example.com/some-tracker/abcdxyz?param1=1¶m2=2&custom-rtt=${RTT}', - timeToRespond: 378, - }); - - expect(utils.triggerPixel.callCount).to.equal(1) - expect(utils.triggerPixel.getCall(0).args[0]).to.equal('https://example.com/some-tracker/abcdxyz?param1=1¶m2=2&custom-rtt=378') - }) - - it('Should trigger pixel if bid has nurl and there is no timeToRespond param, but has rtt macros in nurl', function() { - spec.onBidWon({ - nurl: 'https://example.com/some-tracker/abcdxyz?param1=1¶m2=2&custom-rtt=${RTT}', - }); - - expect(utils.triggerPixel.callCount).to.equal(1) - expect(utils.triggerPixel.getCall(0).args[0]).to.equal('https://example.com/some-tracker/abcdxyz?param1=1¶m2=2&custom-rtt=-1') - }) - }); - - describe('onTimeout callback', () => { - it('will always call server', () => { - const ajaxStub = sandbox.stub(ajax, 'ajax'); - expect(spec.onTimeout({ forTest: true })).to.not.throw; - expect(ajaxStub.calledOnce).to.be.true; - }); - }); - - describe('on onBidderError callback', () => { - it('will always call server', () => { - const ajaxStub = sandbox.stub(ajax, 'ajax'); - spec.onBidderError({ forTest: true }); - expect(ajaxStub.calledOnce).to.be.true; - }); - }); - - describe('on onBidBillable callback', () => { - it('will always call server', () => { - const ajaxStub = sandbox.stub(ajax, 'ajax'); - spec.onBidBillable({ forTest: true }); - expect(ajaxStub.calledOnce).to.be.true; - }); - }); - - describe('on onAdRenderSucceeded callback', () => { - it('will always call server', () => { - const ajaxStub = sandbox.stub(ajax, 'ajax'); - spec.onAdRenderSucceeded({ forTest: true }); - expect(ajaxStub.calledOnce).to.be.true; - }); - }); -}); - -function getBidConfig() { - return { - bidder: 'yandex', - params: { - placementId: '123-1', - }, - }; -} - -function getBidRequest(extra = {}) { - return { - ...getBidConfig(), - bidId: 'bidid-1', - adUnitCode: 'adUnit-123', - ...extra, - }; -} diff --git a/test/spec/modules/yieldlabBidAdapter_spec.js b/test/spec/modules/yieldlabBidAdapter_spec.js deleted file mode 100644 index 16a52acfb..000000000 --- a/test/spec/modules/yieldlabBidAdapter_spec.js +++ /dev/null @@ -1,979 +0,0 @@ -import { config } from 'src/config.js'; -import { expect } from 'chai'; -import { spec } from 'modules/yieldlabBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; - -const DEFAULT_REQUEST = () => ({ - bidder: 'yieldlab', - params: { - adslotId: '1111', - supplyId: '2222', - targeting: { - key1: 'value1', - key2: 'value2', - notDoubleEncoded: 'value3,value4', - }, - customParams: { - extraParam: true, - foo: 'bar', - }, - extId: 'abc', - iabContent: { - id: 'foo_id', - episode: '99', - title: 'foo_title,bar_title', - series: 'foo_series', - season: 's1', - artist: 'foo bar', - genre: 'baz', - isrc: 'CC-XXX-YY-NNNNN', - url: 'http://foo_url.de', - cat: ['cat1', 'cat2,ppp', 'cat3|||//'], - context: '7', - keywords: ['k1,', 'k2..'], - live: '0', - }, - }, - bidderRequestId: '143346cf0f1731', - auctionId: '2e41f65424c87c', - adUnitCode: 'adunit-code', - bidId: '2d925f27f5079f', - sizes: [728, 90], - userIdAsEids: [{ - source: 'netid.de', - uids: [{ - id: 'fH5A3n2O8_CZZyPoJVD-eabc6ECb7jhxCicsds7qSg', - atype: 1, - }], - }, { - source: 'digitrust.de', - uids: [{ - id: 'd8aa10fa-d86c-451d-aad8-5f16162a9e64', - atype: 2, - }], - }], - ortb2: { - source: { - ext: { - schain: { - ver: '1.0', - complete: 1, - nodes: [ - { - asi: 'indirectseller.com', - sid: '1', - hp: 1, - }, - { - asi: 'indirectseller2.com', - name: 'indirectseller2 name with comma , and bang !', - sid: '2', - hp: 1, - }, - ], - } - } - } - }, -}); - -const VIDEO_REQUEST = () => Object.assign(DEFAULT_REQUEST(), { - mediaTypes: { - video: { - playerSize: [[640, 480]], - context: 'instream', - }, - }, -}); - -const NATIVE_REQUEST = () => Object.assign(DEFAULT_REQUEST(), { - mediaTypes: { - native: {}, - }, -}); - -const IAB_REQUEST = () => Object.assign(DEFAULT_REQUEST(), { - params: { - adslotId: '1111', - supplyId: '2222', - iabContent: { - id: 'foo', - episode: '99', - title: 'bar', - series: 'baz', - season: 's01', - artist: 'foobar', - genre: 'barbaz', - isrc: 'CC-XXX-YY-NNNNN', - url: 'https://foo.test', - cat: ['cat1', 'cat2,ppp', 'cat3|||//'], - context: '2', - keywords: ['k1', 'k2', 'k3', 'k4'], - live: '0', - album: 'foo', - cattax: '3', - prodq: 2, - contentrating: 'foo', - userrating: 'bar', - qagmediarating: 2, - sourcerelationship: 1, - len: 12345, - language: 'en', - embeddable: 0, - producer: { - id: 'foo', - name: 'bar', - cattax: 532, - cat: [1, 'foo', true], - domain: 'producer.test', - }, - data: { - id: 'foo', - name: 'bar', - segment: [{ - name: 'foo', - value: 'bar', - ext: { - foo: { - bar: 'bar', - }, - }, - }, { - name: 'foo2', - value: 'bar2', - ext: { - test: { - nums: { - int: 123, - float: 123.123, - }, - bool: true, - string: 'foo2', - }, - }, - }], - }, - network: { - id: 'foo', - name: 'bar', - domain: 'network.test', - }, - channel: { - id: 'bar', - name: 'foo', - domain: 'channel.test', - }, - }, - }, -}); - -const RESPONSE = { - advertiser: 'yieldlab', - curl: 'https://www.yieldlab.de', - format: 0, - id: 1111, - price: 1, - pid: 2222, - adsize: '728x90', - adtype: 'BANNER', - netRevenue: false, -}; - -const NATIVE_RESPONSE = Object.assign({}, RESPONSE, { - adtype: 'NATIVE', - native: { - link: { - url: 'https://www.yieldlab.de', - }, - assets: [ - { - id: 1, - title: { - text: 'This is a great headline', - }, - }, - { - id: 2, - img: { - url: 'https://localhost:8080/yl-logo100x100.jpg', - w: 100, - h: 100, - type: 3, - }, - }, - { - id: 3, - data: { - value: 'Native body value', - }, - }, - { - id: 4, - img: { - url: 'https://localhost:8080/assets/favicon/favicon-16x16.png', - w: 16, - h: 16, - type: 1, - }, - }, - ], - imptrackers: [ - 'http://localhost:8080/ve?d=ODE9ZSY2MTI1MjAzNjMzMzYxPXN0JjA0NWUwZDk0NTY5Yi05M2FiLWUwZTQtOWFjNy1hYWY0MzFiZj1kaXQmMj12', - 'http://localhost:8080/md/1111/9efa4e76-2030-4f04-bb9f-322541f8d611?mdata=false&pvid=false&ids=x:1', - 'http://localhost:8080/imp?s=13216&d=2171514&a=12548955&ts=1633363025216&tid=fb134faa-7ca9-4e0e-ba39-b96549d0e540&l=0', - ], - }, -}); - -const VIDEO_RESPONSE = Object.assign({}, RESPONSE, { - adtype: 'VIDEO', -}); - -const PVID_RESPONSE = Object.assign({}, VIDEO_RESPONSE, { - pvid: '43513f11-55a0-4a83-94e5-0ebc08f54a2c', -}); - -const DIGITAL_SERVICES_ACT_RESPONSE = Object.assign({}, RESPONSE, { - dsa: { - behalf: 'some-behalf', - paid: 'some-paid', - transparency: [{ - domain: 'test.com', - dsaparams: [1, 2, 3] - }], - adrender: 1 - } -}); - -const DIGITAL_SERVICES_ACT_CONFIG = { - ortb2: { - regs: { - ext: { - dsa: { - dsarequired: '1', - pubrender: '2', - datatopub: '3', - transparency: [{ - domain: 'test.com', - dsaparams: [1, 2, 3] - }] - }, - } - }, - } -} - -const REQPARAMS = { - json: true, - ts: 1234567890, -}; - -const REQPARAMS_GDPR = Object.assign({}, REQPARAMS, { - gdpr: true, - gdpr_consent: 'BN5lERiOMYEdiAKAWXEND1AAAAE6DABACMA', -}); - -const REQPARAMS_IAB_CONTENT = Object.assign({}, REQPARAMS, { - iab_content: 'id%3Afoo_id%2Cepisode%3A99%2Ctitle%3Afoo_title%252Cbar_title%2Cseries%3Afoo_series%2Cseason%3As1%2Cartist%3Afoo%2520bar%2Cgenre%3Abaz%2Cisrc%3ACC-XXX-YY-NNNNN%2Curl%3Ahttp%253A%252F%252Ffoo_url.de%2Ccat%3Acat1%7Ccat2%252Cppp%7Ccat3%257C%257C%257C%252F%252F%2Ccontext%3A7%2Ckeywords%3Ak1%252C%7Ck2..%2Clive%3A0', -}); - -describe('yieldlabBidAdapter', () => { - describe('instantiation from spec', () => { - it('is working properly', () => { - const yieldlabBidAdapter = newBidder(spec); - expect(yieldlabBidAdapter.callBids).to.exist.and.to.be.a('function'); - }); - }); - - describe('isBidRequestValid', () => { - it('should return true when all required parameters are found', () => { - const request = { - params: { - adslotId: '1111', - supplyId: '2222', - }, - }; - expect(spec.isBidRequestValid(request)).to.equal(true); - }); - - it('should return false when required parameters are missing', () => { - expect(spec.isBidRequestValid({})).to.equal(false); - }); - }); - - describe('buildRequests', () => { - const bidRequests = [DEFAULT_REQUEST()]; - - describe('default functionality', () => { - let request; - - before(() => { - request = spec.buildRequests(bidRequests); - }); - - it('sends bid request to ENDPOINT via GET', () => { - expect(request.method).to.equal('GET'); - }); - - it('returns a list of valid requests', () => { - expect(request.validBidRequests).to.eql(bidRequests); - }); - - it('passes single-encoded targeting to bid request', () => { - expect(request.url).to.include('t=key1%3Dvalue1%26key2%3Dvalue2%26notDoubleEncoded%3Dvalue3%2Cvalue4'); - }); - - it('passes userids to bid request', () => { - expect(request.url).to.include('ids=netid.de%3AfH5A3n2O8_CZZyPoJVD-eabc6ECb7jhxCicsds7qSg%2Cdigitrust.de%3Ad8aa10fa-d86c-451d-aad8-5f16162a9e64'); - }); - - it('passes atype to bid request', () => { - expect(request.url).to.include('atypes=netid.de%3A1%2Cdigitrust.de%3A2'); - }); - - it('passes extra params to bid request', () => { - expect(request.url).to.include('extraParam=true&foo=bar'); - }); - - it('passes unencoded schain string to bid request', () => { - expect(request.url).to.include('schain=1.0,1!indirectseller.com,1,1,,,,!indirectseller2.com,2,1,,indirectseller2%20name%20with%20comma%20%2C%20and%20bang%20%21,,'); - }); - - it('passes iab_content string to bid request', () => { - expect(request.url).to.include('iab_content=id%3Afoo_id%2Cepisode%3A99%2Ctitle%3Afoo_title%252Cbar_title%2Cseries%3Afoo_series%2Cseason%3As1%2Cartist%3Afoo%2520bar%2Cgenre%3Abaz%2Cisrc%3ACC-XXX-YY-NNNNN%2Curl%3Ahttp%253A%252F%252Ffoo_url.de%2Ccat%3Acat1%7Ccat2%252Cppp%7Ccat3%257C%257C%257C%252F%252F%2Ccontext%3A7%2Ckeywords%3Ak1%252C%7Ck2..%2Clive%3A0'); - }); - - it('passes correct size to bid request', () => { - expect(request.url).to.include('728x90'); - }); - - it('passes external id to bid request', () => { - expect(request.url).to.include('id=abc'); - }); - }); - - describe('iab_content handling', () => { - const siteConfig = { - ortb2: { - site: { - content: { - id: 'id_from_config', - }, - }, - }, - }; - - beforeEach(() => { - config.setConfig(siteConfig); - }); - - afterEach(() => { - config.resetConfig(); - }); - - it('generates iab_content string from bidder params', () => { - const request = spec.buildRequests(bidRequests); - expect(request.url).to.include('iab_content=id%3Afoo_id%2Cepisode%3A99%2Ctitle%3Afoo_title%252Cbar_title%2Cseries%3Afoo_series%2Cseason%3As1%2Cartist%3Afoo%2520bar%2Cgenre%3Abaz%2Cisrc%3ACC-XXX-YY-NNNNN%2Curl%3Ahttp%253A%252F%252Ffoo_url.de%2Ccat%3Acat1%7Ccat2%252Cppp%7Ccat3%257C%257C%257C%252F%252F%2Ccontext%3A7%2Ckeywords%3Ak1%252C%7Ck2..%2Clive%3A0'); - }); - - it('generates iab_content string from first party data if not provided in bidder params', () => { - const requestWithoutIabContent = DEFAULT_REQUEST(); - delete requestWithoutIabContent.params.iabContent; - - const request = spec.buildRequests([{...requestWithoutIabContent, ...siteConfig}]); - expect(request.url).to.include('iab_content=id%3Aid_from_config'); - }); - - it('flattens the iabContent, encodes the values, joins the keywords into one value, and than encodes the iab_content request param ', () => { - const expectedIabContentValue = encodeURIComponent( - 'id:foo,' + - 'episode:99,' + - 'title:bar,' + - 'series:baz,' + - 'season:s01,' + - 'artist:foobar,' + - 'genre:barbaz,' + - 'isrc:CC-XXX-YY-NNNNN,' + - 'url:https%3A%2F%2Ffoo.test,' + - 'cat:cat1|cat2%2Cppp|cat3%7C%7C%7C%2F%2F,' + - 'context:2,' + - 'keywords:k1|k2|k3|k4,' + - 'live:0,' + - 'album:foo,' + - 'cattax:3,' + - 'prodq:2,' + - 'contentrating:foo,' + - 'userrating:bar,' + - 'qagmediarating:2,' + - 'sourcerelationship:1,' + - 'len:12345,' + - 'language:en,' + - 'embeddable:0,' + - 'producer.id:foo,' + - 'producer.name:bar,' + - 'producer.cattax:532,' + - 'cat:1|foo|true,' + - 'producer.domain:producer.test,' + - 'data.id:foo,data.name:bar,' + - 'data.segment.0.name:foo,' + - 'data.segment.0.value:bar,' + - 'data.segment.0.ext.foo.bar:bar,' + - 'data.segment.1.name:foo2,' + - 'data.segment.1.value:bar2,' + - 'data.segment.1.ext.test.nums.int:123,' + - 'data.segment.1.ext.test.nums.float:123.123,' + - 'data.segment.1.ext.test.bool:true,' + - 'data.segment.1.ext.test.string:foo2,' + - 'network.id:foo,network.name:bar,' + - 'network.domain:network.test,' + - 'channel.id:bar,' + - 'channel.name:foo,' + - 'channel.domain:channel.test' - ); - const request = spec.buildRequests([IAB_REQUEST()], REQPARAMS); - expect(request.url).to.include('iab_content=' + expectedIabContentValue); - }); - }); - - it('passes unencoded schain string to bid request when complete == 0', () => { - const schainRequest = DEFAULT_REQUEST(); - schainRequest.ortb2.source.ext.schain.complete = 0; - const request = spec.buildRequests([schainRequest]); - expect(request.url).to.include('schain=1.0,0!indirectseller.com,1,1,,,,!indirectseller2.com,2,1,,indirectseller2%20name%20with%20comma%20%2C%20and%20bang%20%21,,'); - }); - - it('passes encoded referer to bid request', () => { - const refererRequest = spec.buildRequests(bidRequests, { - refererInfo: { - canonicalUrl: undefined, - numIframes: 0, - reachedTop: true, - page: 'https://www.yieldlab.de/test?with=querystring', - stack: ['https://www.yieldlab.de/test?with=querystring'], - }, - }); - - expect(refererRequest.url).to.include('pubref=https%3A%2F%2Fwww.yieldlab.de%2Ftest%3Fwith%3Dquerystring'); - }); - - it('passes gdpr flag and consent if present', () => { - const gdprRequest = spec.buildRequests(bidRequests, { - gdprConsent: { - consentString: 'BN5lERiOMYEdiAKAWXEND1AAAAE6DABACMA', - gdprApplies: true, - }, - }); - - expect(gdprRequest.url).to.include('&gdpr_consent=BN5lERiOMYEdiAKAWXEND1AAAAE6DABACMA'); - expect(gdprRequest.url).to.include('&gdpr=true'); - }); - - describe('sizes handling', () => { - it('passes correct size to bid request for mediaType banner', () => { - const bannerRequest = DEFAULT_REQUEST(); - bannerRequest.mediaTypes = { - banner: { - sizes: [[123, 456]], - }, - }; - - // when mediaTypes is present it has precedence over the sizes field (728, 90) - let request = spec.buildRequests([bannerRequest], REQPARAMS); - expect(request.url).to.include('sizes'); - expect(request.url).to.include('123x456'); - - bannerRequest.mediaTypes.banner.sizes = [123, 456]; - request = spec.buildRequests([bannerRequest], REQPARAMS); - expect(request.url).to.include('123x456'); - - bannerRequest.mediaTypes.banner.sizes = [[123, 456], [320, 240]]; - request = spec.buildRequests([bannerRequest], REQPARAMS); - expect(request.url).to.include('123x456'); - expect(request.url).to.include('320x240'); - }); - - it('passes correct sizes to bid request when mediaType is not present', () => { - // information is taken from the top level sizes field - const sizesRequest = DEFAULT_REQUEST(); - - let request = spec.buildRequests([sizesRequest], REQPARAMS); - expect(request.url).to.include('sizes'); - expect(request.url).to.include('728x90'); - - sizesRequest.sizes = [[728, 90]]; - request = spec.buildRequests([sizesRequest], REQPARAMS); - expect(request.url).to.include('728x90'); - - sizesRequest.sizes = [[728, 90], [320, 240]]; - request = spec.buildRequests([sizesRequest], REQPARAMS); - expect(request.url).to.include('728x90'); - }); - - it('does not pass the sizes parameter for mediaType video', () => { - const videoRequest = VIDEO_REQUEST(); - - const request = spec.buildRequests([videoRequest], REQPARAMS); - expect(request.url).to.not.include('sizes'); - }); - - it('does not pass the sizes parameter for mediaType native', () => { - const nativeRequest = NATIVE_REQUEST(); - - const request = spec.buildRequests([nativeRequest], REQPARAMS); - expect(request.url).to.not.include('sizes'); - }); - }); - - describe('Digital Services Act handling', () => { - beforeEach(() => { - config.setConfig(DIGITAL_SERVICES_ACT_CONFIG); - }); - - afterEach(() => { - config.resetConfig(); - }); - - it('does pass dsarequired parameter', () => { - const request = spec.buildRequests([DEFAULT_REQUEST()], { ...REQPARAMS, ...DIGITAL_SERVICES_ACT_CONFIG }); - expect(request.url).to.include('dsarequired=1'); - }); - - it('does pass dsapubrender parameter', () => { - const request = spec.buildRequests([DEFAULT_REQUEST()], { ...REQPARAMS, ...DIGITAL_SERVICES_ACT_CONFIG }); - expect(request.url).to.include('dsapubrender=2'); - }); - - it('does pass dsadatatopub parameter', () => { - const request = spec.buildRequests([DEFAULT_REQUEST()], { ...REQPARAMS, ...DIGITAL_SERVICES_ACT_CONFIG }); - expect(request.url).to.include('dsadatatopub=3'); - }); - - it('does pass dsadomain parameter', () => { - const request = spec.buildRequests([DEFAULT_REQUEST()], { ...REQPARAMS, ...DIGITAL_SERVICES_ACT_CONFIG }); - expect(request.url).to.include('dsadomain=test.com'); - }); - - it('does pass encoded dsaparams parameter', () => { - const request = spec.buildRequests([DEFAULT_REQUEST()], { ...REQPARAMS, ...DIGITAL_SERVICES_ACT_CONFIG }); - expect(request.url).to.include('dsaparams=1%2C2%2C3'); - }); - - it('does pass multiple transparencies in dsatransparency param', () => { - const DSA_CONFIG_WITH_MULTIPLE_TRANSPARENCIES = { - ortb2: { - regs: { - ext: { - dsa: { - dsarequired: '1', - pubrender: '2', - datatopub: '3', - transparency: [ - { - domain: 'test.com', - dsaparams: [1, 2, 3] - }, - { - domain: 'example.com', - dsaparams: [4, 5, 6] - } - ] - } - } - } - } - }; - - config.setConfig(DSA_CONFIG_WITH_MULTIPLE_TRANSPARENCIES); - - const request = spec.buildRequests([DEFAULT_REQUEST()], { ...REQPARAMS, ...DSA_CONFIG_WITH_MULTIPLE_TRANSPARENCIES }); - - expect(request.url).to.include('dsatransparency=test.com~1_2_3~~example.com~4_5_6'); - expect(request.url).to.not.include('dsadomain'); - expect(request.url).to.not.include('dsaparams'); - }); - }); - - describe('google topics handling', () => { - afterEach(() => { - config.resetConfig(); - }); - - it('does pass segtax, segclass, segments for google topics data', () => { - const GOOGLE_TOPICS_DATA = { - ortb2: { - user: { - data: [ - { - ext: { - segtax: 600, - segclass: 'v1', - }, - segment: [ - {id: '717'}, {id: '808'}, - ] - } - ] - }, - }, - } - config.setConfig(GOOGLE_TOPICS_DATA); - const request = spec.buildRequests([DEFAULT_REQUEST()], { ...REQPARAMS, ...GOOGLE_TOPICS_DATA }); - expect(request.url).to.include('segtax=600&segclass=v1&segments=717%2C808'); - }); - - it('does not pass topics params for invalid topics data', () => { - const INVALID_TOPICS_DATA = { - ortb2: { - user: { - data: [ - { - segment: [] - }, - { - segment: [{id: ''}] - }, - { - segment: [{id: null}] - }, - { - segment: [{id: 'dummy'}, {id: '123'}] - }, - { - ext: { - segtax: 600, - segclass: 'v1', - }, - segment: [ - { - name: 'dummy' - } - ] - }, - ] - } - } - }; - - config.setConfig(INVALID_TOPICS_DATA); - const request = spec.buildRequests([DEFAULT_REQUEST()], { ...REQPARAMS, ...INVALID_TOPICS_DATA }); - - expect(request.url).to.not.include('segtax'); - expect(request.url).to.not.include('segclass'); - expect(request.url).to.not.include('segments'); - }); - }); - }); - - describe('interpretResponse', () => { - let bidRequest; - - before(() => { - bidRequest = DEFAULT_REQUEST(); - }); - - it('handles nobid responses', () => { - expect(spec.interpretResponse({body: {}}, {validBidRequests: []}).length).to.equal(0); - expect(spec.interpretResponse({body: []}, {validBidRequests: []}).length).to.equal(0); - }); - - it('should get correct bid response', () => { - const result = spec.interpretResponse({body: [RESPONSE]}, {validBidRequests: [bidRequest], queryParams: REQPARAMS}); - - expect(result[0].requestId).to.equal('2d925f27f5079f'); - expect(result[0].cpm).to.equal(0.01); - expect(result[0].width).to.equal(728); - expect(result[0].height).to.equal(90); - expect(result[0].creativeId).to.equal('1111'); - expect(result[0].dealId).to.equal(2222); - expect(result[0].currency).to.equal('EUR'); - expect(result[0].netRevenue).to.equal(false); - expect(result[0].ttl).to.equal(300); - expect(result[0].referrer).to.equal(''); - expect(result[0].meta.advertiserDomains).to.deep.equal(['yieldlab']); - expect(result[0].ad).to.include('', - 'adid': '144762342', - 'advertiserDomains': [ - 'https://dummydomain.com' - ], - 'iurl': 'iurl', - 'cid': '109', - 'crid': 'creativeId', - 'cat': [], - 'w': 300, - 'h': 250, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'appnexus': { - 'brand_id': 334553, - 'auction_id': '514667951122925701', - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - } - }, - { - 'id': 'bidId2', - 'impid': 'bidId2', - 'price': 0.1, - 'adm': '', - 'adid': '144762342', - 'advertiserDomains': [ - 'https://dummydomain.com' - ], - 'iurl': 'iurl', - 'cid': '109', - 'crid': 'creativeId', - 'cat': [], - 'w': 300, - 'h': 250, - 'ext': { - 'prebid': { - 'type': 'banner' - }, - 'bidder': { - 'appnexus': { - 'brand_id': 386046, - 'auction_id': '517067951122925501', - 'bidder_id': 2, - 'bid_ad_type': 0 - } - } - } - } - ], - 'seat': 'yieldlift' - } - ], - 'ext': { - 'usersync': { - 'sovrn': { - 'status': 'none', - 'syncs': [ - { - 'url': 'urlsovrn', - 'type': 'iframe' - } - ] - }, - 'appnexus': { - 'status': 'none', - 'syncs': [ - { - 'url': 'urlappnexus', - 'type': 'pixel' - } - ] - } - }, - 'responsetimemillis': { - 'appnexus': 127 - } - } - } -}; - -describe('YieldLift', function () { - describe('isBidRequestValid', function () { - it('should accept request if only unitId is passed', function () { - const bid = { - bidder: 'yieldlift', - params: { - unitId: 'unitId', - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should accept request if only networkId is passed', function () { - const bid = { - bidder: 'yieldlift', - params: { - networkId: 'networkId', - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - it('should accept request if only publisherId is passed', function () { - const bid = { - bidder: 'yieldlift', - params: { - publisherId: 'publisherId', - } - }; - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('reject requests without params', function () { - const bid = { - bidder: 'yieldlift', - params: {} - }; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - it('creates request data', function () { - const request = spec.buildRequests(REQUEST.bidRequest, REQUEST); - - expect(request).to.exist.and.to.be.a('object'); - const payload = JSON.parse(request.data); - expect(payload.imp[0]).to.have.property('id', REQUEST.bidRequest[0].bidId); - expect(payload.imp[1]).to.have.property('id', REQUEST.bidRequest[1].bidId); - }); - - it('has gdpr data if applicable', function () { - const req = Object.assign({}, REQUEST, { - gdprConsent: { - consentString: 'consentString', - gdprApplies: true, - } - }); - const request = spec.buildRequests(REQUEST.bidRequest, req); - - const payload = JSON.parse(request.data); - expect(payload.user.ext).to.have.property('consent', req.gdprConsent.consentString); - expect(payload.regs.ext).to.have.property('gdpr', 1); - }); - - it('should properly forward eids parameters', function () { - const req = Object.assign({}, REQUEST); - req.bidRequest[0].userIdAsEids = [ - { - source: 'dummy.com', - uids: [ - { - id: 'd6d0a86c-20c6-4410-a47b-5cba383a698a', - atype: 1 - } - ] - }]; - const request = spec.buildRequests(req.bidRequest, req); - - const payload = JSON.parse(request.data); - expect(payload.user.ext.eids[0].source).to.equal('dummy.com'); - expect(payload.user.ext.eids[0].uids[0].id).to.equal('d6d0a86c-20c6-4410-a47b-5cba383a698a'); - expect(payload.user.ext.eids[0].uids[0].atype).to.equal(1); - }); - }); - - describe('interpretResponse', function () { - it('have bids', function () { - const bids = spec.interpretResponse(RESPONSE, REQUEST); - expect(bids).to.be.an('array').that.is.not.empty; - validateBidOnIndex(0); - validateBidOnIndex(1); - - function validateBidOnIndex(index) { - expect(bids[index]).to.have.property('currency', 'USD'); - expect(bids[index]).to.have.property('requestId', RESPONSE.body.seatbid[0].bid[index].impid); - expect(bids[index]).to.have.property('cpm', RESPONSE.body.seatbid[0].bid[index].price); - expect(bids[index]).to.have.property('width', RESPONSE.body.seatbid[0].bid[index].w); - expect(bids[index]).to.have.property('height', RESPONSE.body.seatbid[0].bid[index].h); - expect(bids[index]).to.have.property('ad', RESPONSE.body.seatbid[0].bid[index].adm); - expect(bids[index]).to.have.property('creativeId', RESPONSE.body.seatbid[0].bid[index].crid); - expect(bids[index].meta).to.have.property('advertiserDomains', RESPONSE.body.seatbid[0].bid[index].advertiserDomains); - expect(bids[index]).to.have.property('ttl', 300); - expect(bids[index]).to.have.property('netRevenue', true); - } - }); - - it('handles empty response', function () { - const EMPTY_RESP = Object.assign({}, RESPONSE, {'body': {}}); - const bids = spec.interpretResponse(EMPTY_RESP, REQUEST); - - expect(bids).to.be.empty; - }); - }); - - describe('getUserSyncs', function () { - it('handles no parameters', function () { - const opts = spec.getUserSyncs({}); - expect(opts).to.be.an('array').that.is.empty; - }); - it('returns non if sync is not allowed', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: false}); - - expect(opts).to.be.an('array').that.is.empty; - }); - - it('iframe sync enabled should return results', function () { - const opts = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: false}, [RESPONSE]); - - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('iframe'); - expect(opts[0].url).to.equal(RESPONSE.body.ext.usersync['sovrn'].syncs[0].url); - }); - - it('pixel sync enabled should return results', function () { - const opts = spec.getUserSyncs({iframeEnabled: false, pixelEnabled: true}, [RESPONSE]); - - expect(opts.length).to.equal(1); - expect(opts[0].type).to.equal('image'); - expect(opts[0].url).to.equal(RESPONSE.body.ext.usersync['appnexus'].syncs[0].url); - }); - - it('all sync enabled should return all results', function () { - const opts = spec.getUserSyncs({iframeEnabled: true, pixelEnabled: true}, [RESPONSE]); - - expect(opts.length).to.equal(2); - }); - }); -}); diff --git a/test/spec/modules/yieldloveBidAdapter_spec.js b/test/spec/modules/yieldloveBidAdapter_spec.js deleted file mode 100644 index b142eef0f..000000000 --- a/test/spec/modules/yieldloveBidAdapter_spec.js +++ /dev/null @@ -1,128 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/yieldloveBidAdapter.js'; - -const ENDPOINT_URL = 'https://s2s.yieldlove-ad-serving.net/openrtb2/auction'; - -// test params -const pid = 34437; -const rid = 'website.com'; - -describe('Yieldlove Bid Adaper', function () { - const bidRequests = [ - { - 'bidder': 'yieldlove', - 'adUnitCode': 'adunit-code', - 'sizes': [ [300, 250] ], - 'params': { - pid, - rid - } - } - ]; - - const serverResponse = { - body: { - seatbid: [ - { - bid: [ - { - impid: 'aaaa', - price: 0.5, - w: 300, - h: 250, - adm: '
test
', - crid: '1234', - } - ] - } - ], - ext: {} - } - } - - describe('isBidRequestValid', () => { - const bid = bidRequests[0]; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when required params are not present', function () { - const invalidBid = { ...bid, params: {} }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when required param "pid" is not present', function () { - const invalidBid = { ...bid, params: { ...bid.params, pid: undefined } }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - - it('should return false when required param "rid" is not present', function () { - const invalidBid = { ...bid, params: { ...bid.params, rid: undefined } }; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', () => { - it('should build the request', function () { - const request = spec.buildRequests(bidRequests, {}); - const payload = request.data; - const url = request.url; - - expect(url).to.equal(ENDPOINT_URL); - - expect(payload.site).to.exist; - expect(payload.site.publisher).to.exist; - expect(payload.site.publisher.id).to.exist; - expect(payload.site.publisher.id).to.equal(rid); - expect(payload.site.domain).to.exist; - expect(payload.site.domain).to.equal(rid); - - expect(payload.imp).to.exist; - expect(payload.imp[0]).to.exist; - expect(payload.imp[0].ext).to.exist; - expect(payload.imp[0].ext.prebid).to.exist; - expect(payload.imp[0].ext.prebid.storedrequest).to.exist; - expect(payload.imp[0].ext.prebid.storedrequest.id).to.exist; - expect(payload.imp[0].ext.prebid.storedrequest.id).to.equal(pid.toString()); - }); - }); - - describe('interpretResponse', () => { - it('should interpret the response by pushing it in the bids elem', function () { - const allResponses = spec.interpretResponse(serverResponse); - const response = allResponses[0]; - const seatbid = serverResponse.body.seatbid[0].bid[0]; - - expect(response.requestId).to.exist; - expect(response.requestId).to.equal(seatbid.impid); - expect(response.cpm).to.exist; - expect(response.cpm).to.equal(seatbid.price); - expect(response.width).to.exist; - expect(response.width).to.equal(seatbid.w); - expect(response.height).to.exist; - expect(response.height).to.equal(seatbid.h); - expect(response.ad).to.exist; - expect(response.ad).to.equal(seatbid.adm); - expect(response.ttl).to.exist; - expect(response.creativeId).to.exist; - expect(response.creativeId).to.equal(seatbid.crid); - expect(response.netRevenue).to.exist; - expect(response.currency).to.exist; - }); - }); - - describe('getUserSyncs', function() { - it('should retrieve user iframe syncs', function () { - expect(spec.getUserSyncs({ iframeEnabled: true }, [serverResponse], undefined, undefined)).to.deep.equal([{ - type: 'iframe', - url: 'https://cdn-a.yieldlove.com/load-cookie.html?endpoint=yieldlove&max_sync_count=100&gdpr=NaN&gdpr_consent=&' - }]); - - expect(spec.getUserSyncs({ iframeEnabled: true }, [serverResponse], { gdprApplies: true, consentString: 'example' }, undefined)).to.deep.equal([{ - type: 'iframe', - url: 'https://cdn-a.yieldlove.com/load-cookie.html?endpoint=yieldlove&max_sync_count=100&gdpr=1&gdpr_consent=example&' - }]); - }); - }); -}) diff --git a/test/spec/modules/yieldmoBidAdapter_spec.js b/test/spec/modules/yieldmoBidAdapter_spec.js deleted file mode 100644 index a368ad681..000000000 --- a/test/spec/modules/yieldmoBidAdapter_spec.js +++ /dev/null @@ -1,938 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/yieldmoBidAdapter.js'; -import * as utils from 'src/utils.js'; - -/* eslint no-console: ["error", { allow: ["log", "warn", "error"] }] */ -// above is used for debugging purposes only - -describe('YieldmoAdapter', function () { - const BANNER_ENDPOINT = 'https://ads.yieldmo.com/exchange/prebid'; - const VIDEO_ENDPOINT = 'https://ads.yieldmo.com/exchange/prebidvideo'; - const PB_COOKIE_ASSIST_SYNC_ENDPOINT = `https://ads.yieldmo.com/pbcas`; - - const mockBannerBid = (rootParams = {}, params = {}) => ({ - bidder: 'yieldmo', - params: { - bidFloor: 0.1, - ...params, - }, - adUnitCode: 'adunit-code', - mediaTypes: { - banner: { - sizes: [ - [300, 250], - [300, 600], - ], - }, - }, - bidId: '30b31c1838de1e', - bidderRequestId: '22edbae2733bf6', - auctionId: '1d1a030790a475', - crumbs: { - pubcid: 'c604130c-0144-4b63-9bf2-c2bd8c8d86da', - }, - userId: { - tdid: '8d146286-91d4-4958-aff4-7e489dd1abd6' - }, - transactionId: '54a58774-7a41-494e-9aaf-fa7b79164f0c', - ...rootParams - }); - - const mockVideoBid = (rootParams = {}, params = {}, videoParams = {}) => ({ - bidder: 'yieldmo', - adUnitCode: 'adunit-code-video', - bidId: '321video123', - auctionId: '1d1a03073455', - mediaTypes: { - video: { - playerSize: [640, 480], - context: 'instream', - mimes: ['video/mp4'], - }, - }, - params: { - placementId: '123', - ...params, - video: { - placement: 1, - maxduration: 30, - startdelay: 10, - protocols: [2, 3], - api: [2, 3], - skipppable: true, - playbackmethod: [1, 2], - ...videoParams, - }, - }, - transactionId: '54a58774-7a41-494e-8cbc-fa7b79164f0c', - ...rootParams, - }); - - const mockBidderRequest = (params = {}, bids = [mockBannerBid()]) => ({ - bidderCode: 'yieldmo', - auctionId: 'e3a336ad-2761-4a1c-b421-ecc7c5294a34', - bidderRequestId: '14c4ede8c693f', - bids, - auctionStart: 1520001292880, - start: 1520001292884, - doneCbCallCount: 0, - refererInfo: { - numIframes: 1, - reachedTop: true, - referer: 'yieldmo.com', - }, - ...params - }); - - const mockGetFloor = floor => ({getFloor: () => ({ currency: 'USD', floor })}); - - describe('isBidRequestValid', function () { - describe('Banner:', function () { - it('should return true when necessary information is found', function () { - expect(spec.isBidRequestValid(mockBannerBid())).to.be.true; - }); - - it('should return false when necessary information is not found', function () { - // empty bid - expect(spec.isBidRequestValid({})).to.be.false; - - // empty bidId - expect(spec.isBidRequestValid(mockBannerBid({bidId: ''}))).to.be.false; - - // empty adUnitCode - expect(spec.isBidRequestValid(mockBannerBid({adUnitCode: ''}))).to.be.false; - - const invalidBid = mockBannerBid(); - delete invalidBid.mediaTypes.banner; - expect(spec.isBidRequestValid(invalidBid)).to.be.false; - }); - }); - - describe('Instream video:', function () { - const getVideoBidWithoutParam = (key, paramToRemove) => { - const bid = mockVideoBid(); - delete utils.deepAccess(bid, key)[paramToRemove]; - return bid; - } - - it('should return true when necessary information is found', function () { - expect(spec.isBidRequestValid(mockVideoBid())).to.be.true; - }); - - it('should return false when necessary information is not found', function () { - // empty bidId - expect(spec.isBidRequestValid(mockVideoBid({bidId: ''}))).to.be.false; - - // empty adUnitCode - expect(spec.isBidRequestValid(mockVideoBid({adUnitCode: ''}))).to.be.false; - }); - - it('should return false when required mediaTypes.video.* param is not found', function () { - const getBidAndExclude = paramToRemove => getVideoBidWithoutParam('mediaTypes.video', paramToRemove); - - expect(spec.isBidRequestValid(getBidAndExclude('playerSize'))).to.be.false; - expect(spec.isBidRequestValid(getBidAndExclude('mimes'))).to.be.false; - }); - - it('should return false when required bid.params.* is not found', function () { - const getBidAndExclude = paramToRemove => getVideoBidWithoutParam('params', paramToRemove); - - expect(spec.isBidRequestValid(getBidAndExclude('placementId'))).to.be.false; - expect(spec.isBidRequestValid(getBidAndExclude('video'))).to.be.false; - }); - - it('should return false when required bid.params.video.* is not found', function () { - const getBidAndExclude = paramToRemove => getVideoBidWithoutParam('params.video', paramToRemove); - expect(spec.isBidRequestValid(getBidAndExclude('maxduration'))).to.be.false; - expect(spec.isBidRequestValid(getBidAndExclude('protocols'))).to.be.false; - expect(spec.isBidRequestValid(getBidAndExclude('api'))).to.be.false; - }); - }); - }); - - describe('buildRequests', function () { - const build = (bidRequests, bidderReq = mockBidderRequest()) => spec.buildRequests(bidRequests, bidderReq); - const buildAndGetPlacementInfo = (bidRequests, index = 0, bidderReq = mockBidderRequest()) => - utils.deepAccess(build(bidRequests, bidderReq), `${index}.data.p`); - const buildAndGetData = (bidRequests, index = 0, bidderReq = mockBidderRequest()) => - utils.deepAccess(build(bidRequests, bidderReq), `${index}.data`) || {}; - - describe('Banner:', function () { - it('should attempt to send banner bid requests to the endpoint via GET', function () { - const requests = build([mockBannerBid()]); - expect(requests.length).to.equal(1); - expect(requests[0].method).to.equal('GET'); - expect(requests[0].url).to.be.equal(BANNER_ENDPOINT); - }); - - it('should pass default timeout in bid request', function () { - const requests = build([mockBannerBid()]); - expect(requests[0].data.tmax).to.equal(400); - }); - it('should pass tmax to bid request', function () { - const requests = build([mockBannerBid()], mockBidderRequest({timeout: 1000})); - expect(requests[0].data.tmax).to.equal(1000); - }); - it('should not blow up if crumbs is undefined', function () { - expect(function () { - build([mockBannerBid({crumbs: undefined})]); - }).not.to.throw(); - }); - - it('should place bid information into the p parameter of data', function () { - const bidArray = [mockBannerBid()]; - expect(buildAndGetPlacementInfo(bidArray)).to.equal( - '[{"placement_id":"adunit-code","callback_id":"30b31c1838de1e","sizes":[[300,250],[300,600]],"bidFloor":0.1,"auctionId":"1d1a030790a475"}]' - ); - // multiple placements - bidArray.push(mockBannerBid( - {adUnitCode: 'adunit-2', bidId: '123a', bidderRequestId: '321', auctionId: '222', transactionId: '444'}, {bidFloor: 0.2})); - expect(buildAndGetPlacementInfo(bidArray)).to.equal( - '[{"placement_id":"adunit-code","callback_id":"30b31c1838de1e","sizes":[[300,250],[300,600]],"bidFloor":0.1,"auctionId":"1d1a030790a475"},' + - '{"placement_id":"adunit-2","callback_id":"123a","sizes":[[300,250],[300,600]],"bidFloor":0.2,"auctionId":"222"}]' - ); - }); - - it('should add placement id if given', function () { - const bidArray = [mockBannerBid({}, {placementId: 'ym_1293871298'})]; - let placementInfo = buildAndGetPlacementInfo(bidArray); - expect(placementInfo).to.include('"ym_placement_id":"ym_1293871298"'); - expect(placementInfo).not.to.include('"ym_placement_id":"ym_0987654321"'); - bidArray.push(mockBannerBid({}, {placementId: 'ym_0987654321'})); - placementInfo = buildAndGetPlacementInfo(bidArray); - expect(placementInfo).to.include('"ym_placement_id":"ym_1293871298"'); - expect(placementInfo).to.include('"ym_placement_id":"ym_0987654321"'); - }); - - it('should add additional information to data parameter of request', function () { - const data = buildAndGetData([mockBannerBid()]); - expect(data.hasOwnProperty('page_url')).to.be.true; - expect(data.hasOwnProperty('bust')).to.be.true; - expect(data.hasOwnProperty('pr')).to.be.true; - expect(data.hasOwnProperty('scrd')).to.be.true; - expect(data.dnt).to.be.false; - expect(data.hasOwnProperty('description')).to.be.true; - expect(data.hasOwnProperty('title')).to.be.true; - expect(data.hasOwnProperty('h')).to.be.true; - expect(data.hasOwnProperty('w')).to.be.true; - expect(data.hasOwnProperty('pubcid')).to.be.true; - expect(data.userConsent).to.equal('{"gdprApplies":"","cmp":"","gpp":"","gpp_sid":[]}'); - expect(data.us_privacy).to.equal(''); - }); - - it('should add pubcid as parameter of request', function () { - const pubcid = 'c604130c-0144-4b63-9bf2-c2bd8c8d86da2'; - const pubcidBid = mockBannerBid({crumbs: undefined, userId: {pubcid}}); - expect(buildAndGetData([pubcidBid]).pubcid).to.deep.equal(pubcid); - }); - - it('should add transaction id as parameter of request', function () { - const transactionId = '54a58774-7a41-494e-9aaf-fa7b79164f0c'; - const pubcidBid = mockBannerBid({ ortb2Imp: { - ext: { - tid: '54a58774-7a41-494e-9aaf-fa7b79164f0c', - } - }}); - const bidRequest = buildAndGetData([pubcidBid]); - expect(bidRequest.p).to.contain(transactionId); - }); - - it('should add auction id as parameter of request', function () { - const auctionId = '1d1a030790a475'; - const pubcidBid = mockBannerBid({}); - const bidRequest = buildAndGetData([pubcidBid]); - expect(bidRequest.p).to.contain(auctionId); - }); - - it('should add unified id as parameter of request', function () { - const unifiedIdBid = mockBannerBid({crumbs: undefined}); - expect(buildAndGetData([unifiedIdBid]).tdid).to.deep.equal(mockBannerBid().userId.tdid); - }); - - it('should add CRITEO RTUS id as parameter of request', function () { - const criteoId = 'aff4'; - const criteoIdBid = mockBannerBid({crumbs: undefined, userId: { criteoId }}); - expect(buildAndGetData([criteoIdBid]).cri_prebid).to.deep.equal(criteoId); - }); - - it('should add gdpr information to request if available', () => { - const gdprConsent = { - consentString: 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - vendorData: {blerp: 1}, - gdprApplies: true, - }; - const data = buildAndGetData( - [mockBannerBid()], - 0, - mockBidderRequest({ gdprConsent }) - ); - expect(data.userConsent).equal( - JSON.stringify({ - gdprApplies: true, - cmp: 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - gpp: '', - gpp_sid: [], - }) - ); - }); - - it('should add gpp information to request if available', () => { - const gppConsent = { - 'gppString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - 'applicableSections': [8] - }; - const data = buildAndGetData([mockBannerBid()], 0, mockBidderRequest({gppConsent})); - expect(data.userConsent).equal( - JSON.stringify({ - gdprApplies: '', - cmp: '', - gpp: 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - gpp_sid: [8], - }) - ); - }); - - it('should add ccpa information to request if available', () => { - const uspConsent = '1YNY'; - const data = buildAndGetData([mockBannerBid()], 0, mockBidderRequest({uspConsent})); - expect(data.us_privacy).equal(uspConsent); - }); - - it('should add schain if it is in the bidRequest', () => { - const schain = { - ver: '1.0', - complete: 1, - nodes: [{asi: 'indirectseller.com', sid: '00001', hp: 1}], - }; - const data = buildAndGetData([mockBannerBid({ortb2: {source: {ext: {schain}}}})]); - expect(data.schain).equal(JSON.stringify(schain)); - }); - - it('should process floors module if available', function () { - const placementsData = JSON.parse(buildAndGetPlacementInfo([ - mockBannerBid({...mockGetFloor(3.99)}), - mockBannerBid({...mockGetFloor(1.23)}, { bidFloor: 1.1 }), - ])); - expect(placementsData[0].bidFloor).to.equal(3.99); - expect(placementsData[1].bidFloor).to.equal(1.23); - }); - - it('should use bidFloor if no floors module is available', function() { - const placementsData = JSON.parse(buildAndGetPlacementInfo([ - mockBannerBid({}, { bidFloor: 1.2 }), - mockBannerBid({}, { bidFloor: 0.7 }), - ])); - expect(placementsData[0].bidFloor).to.equal(1.2); - expect(placementsData[1].bidFloor).to.equal(0.7); - }); - - it('should not write 0 bidfloor value by default', function() { - const placementsData = JSON.parse(buildAndGetPlacementInfo([mockBannerBid()])); - expect(placementsData[0].bidfloor).to.undefined; - }); - - it('should not exceed max url length', () => { - const longString = Array(8000).join('a'); - const localWindow = utils.getWindowTop(); - - const originalTitle = localWindow.document.title; - localWindow.document.title = longString; - - const request = spec.buildRequests( - [mockBannerBid()], - mockBidderRequest({ - refererInfo: { - numIframes: 1, - reachedTop: true, - referer: longString, - }, - }) - )[0]; - const url = `${request.url}?${utils.parseQueryStringParameters(request.data)}`; - - expect(url.length).equal(8000); - - localWindow.document.title = originalTitle; - }); - - it('should only shortcut properties rather then completely remove it', () => { - const longString = Array(8000).join('a'); - const localWindow = utils.getWindowTop(); - - const originalTitle = localWindow.document.title; - localWindow.document.title = `testtitle${longString}`; - - const request = spec.buildRequests( - [mockBannerBid()], - mockBidderRequest({ - refererInfo: { - numIframes: 1, - reachedTop: true, - title: longString, - }, - }) - )[0]; - - expect(request.data.title.length).greaterThan(0); - - localWindow.document.title = originalTitle; - }); - - it('should add ats_envelope to banner bid request', function() { - const envelope = 'test_envelope'; - const requests = build([mockBannerBid({}, { lr_env: envelope })]); - - expect(requests[0].data.ats_envelope).to.equal(envelope); - }); - - it('should add gpid to the banner bid request', function () { - const bidArray = [mockBannerBid({ - ortb2Imp: { - ext: { gpid: '/6355419/Travel/Europe/France/Paris' }, - } - })]; - const placementInfo = buildAndGetPlacementInfo(bidArray); - expect(placementInfo).to.include('"gpid":"/6355419/Travel/Europe/France/Paris"'); - }); - - it('should add topics to the banner bid request', function () { - const biddata = build([mockBannerBid()], mockBidderRequest({ortb2: { user: { - data: [ - { - ext: { - segtax: 600, - segclass: '2206021246', - }, - segment: ['7', '8', '9'], - }, - ], - }}})); - - expect(biddata[0].data.topics).to.equal(JSON.stringify({ - taxonomy: 600, - classifier: '2206021246', - topics: [7, 8, 9], - })); - }); - - it('should add cdep to the banner bid request', function () { - const biddata = build( - [mockBannerBid()], - mockBidderRequest({ - ortb2: { - device: { - ext: { - cdep: 'test_cdep' - }, - }, - }, - }) - ); - - expect(biddata[0].data.cdep).to.equal( - 'test_cdep' - ); - }); - - it('should send gpc in the banner bid request', function () { - const biddata = build( - [mockBannerBid()], - mockBidderRequest({ - ortb2: { - regs: { - ext: { - gpc: '1' - }, - }, - }, - }) - ); - expect(biddata[0].data.gpc).to.equal('1'); - }); - - it('should add eids to the banner bid request', function () { - const params = { - userIdAsEids: [{ - source: 'pubcid.org', - uids: [ - { - id: 'fake_pubcid', - atype: 1, - } - ] - }], - fakeUserIdAsEids: [{ - source: 'pubcid.org', - uids: [{ - id: 'fake_pubcid', - atype: 1 - }] - }] - }; - expect(buildAndGetData([mockBannerBid({...params})]).eids).equal(JSON.stringify(params.fakeUserIdAsEids)); - }); - }); - - describe('Instream video:', function () { - let videoBid; - const buildVideoBidAndGetVideoParam = () => build([videoBid])[0].data.imp[0].video; - - beforeEach(() => { - videoBid = mockVideoBid(); - }); - - it('should attempt to send video bid requests to the endpoint via POST', function () { - const requests = build([videoBid]); - expect(requests.length).to.equal(1); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.be.equal(VIDEO_ENDPOINT); - }); - - it('should not require params.video if required props in mediaTypes.video', function () { - videoBid.mediaTypes.video = { - ...videoBid.mediaTypes.video, - ...videoBid.params.video - }; - delete videoBid.params.video; - const requests = build([videoBid]); - expect(requests.length).to.equal(1); - expect(requests[0].method).to.equal('POST'); - expect(requests[0].url).to.be.equal(VIDEO_ENDPOINT); - }); - - it('should add mediaTypes.video prop to the imp.video prop', function () { - utils.deepAccess(videoBid, 'mediaTypes.video')['minduration'] = 40; - expect(buildVideoBidAndGetVideoParam().minduration).to.equal(40); - }); - - it('should override mediaTypes.video prop if params.video prop is present', function () { - utils.deepAccess(videoBid, 'mediaTypes.video')['minduration'] = 50; - utils.deepAccess(videoBid, 'params.video')['minduration'] = 40; - expect(buildVideoBidAndGetVideoParam().minduration).to.equal(40); - }); - - it('should add mediaTypes.video.mimes prop to the imp.video', function () { - utils.deepAccess(videoBid, 'mediaTypes.video')['minduration'] = ['video/mp4']; - expect(buildVideoBidAndGetVideoParam().minduration).to.deep.equal(['video/mp4']); - }); - - it('should add plcmt value to the imp.video', function () { - const videoBid = mockVideoBid({}, {}, { plcmt: 1 }); - expect(utils.deepAccess(videoBid, 'params.video')['plcmt']).to.equal(1); - }); - - it('should add start delay if plcmt value is not 1', function () { - const videoBid = mockVideoBid({}, {}, { plcmt: 2 }); - expect(build([videoBid])[0].data.imp[0].video.startdelay).to.equal(0); - }); - - it('should override mediaTypes.video.mimes prop if params.video.mimes is present', function () { - utils.deepAccess(videoBid, 'mediaTypes.video')['mimes'] = ['video/mp4']; - utils.deepAccess(videoBid, 'params.video')['mimes'] = ['video/mkv']; - expect(buildVideoBidAndGetVideoParam().mimes).to.deep.equal(['video/mkv']); - }); - - describe('video.skip state check', () => { - it('should not set video.skip if neither *.video.skip nor *.video.skippable is present', function () { - utils.deepAccess(videoBid, 'mediaTypes.video')['skippable'] = false; - utils.deepAccess(videoBid, 'params.video')['skippable'] = false; - expect(buildVideoBidAndGetVideoParam().skip).to.undefined; - }); - - it('should set video.skip=1 if mediaTypes.video.skip is present', function () { - utils.deepAccess(videoBid, 'mediaTypes.video')['skip'] = 1; - expect(buildVideoBidAndGetVideoParam().skip).to.equal(1); - }); - - it('should set video.skip=1 if params.video.skip is present', function () { - utils.deepAccess(videoBid, 'params.video')['skip'] = 1; - expect(buildVideoBidAndGetVideoParam().skip).to.equal(1); - }); - - it('should set video.skip=1 if mediaTypes.video.skippable is present', function () { - utils.deepAccess(videoBid, 'mediaTypes.video')['skippable'] = true; - expect(buildVideoBidAndGetVideoParam().skip).to.equal(1); - }); - - it('should set video.skip=1 if mediaTypes.video.skippable is present', function () { - utils.deepAccess(videoBid, 'params.video')['skippable'] = true; - expect(buildVideoBidAndGetVideoParam().skip).to.equal(1); - }); - - it('should set video.skip=1 if mediaTypes.video.skippable is present', function () { - utils.deepAccess(videoBid, 'mediaTypes.video')['skippable'] = false; - utils.deepAccess(videoBid, 'params.video')['skippable'] = true; - expect(buildVideoBidAndGetVideoParam().skip).to.equal(1); - }); - - it('should not set video.skip if params.video.skippable is false', function () { - utils.deepAccess(videoBid, 'mediaTypes.video')['skippable'] = true; - utils.deepAccess(videoBid, 'params.video')['skippable'] = false; - expect(buildVideoBidAndGetVideoParam().skip).to.undefined; - }); - }); - - it('should process floors module if available', function () { - const requests = build([ - mockVideoBid({...mockGetFloor(3.99)}), - mockVideoBid({...mockGetFloor(1.23)}, { bidfloor: 1.1 }), - ]); - const imps = requests[0].data.imp; - expect(imps[0].bidfloor).to.equal(3.99); - expect(imps[1].bidfloor).to.equal(1.23); - }); - - it('should use bidfloor if no floors module is available', function() { - const requests = build([ - mockVideoBid({}, { bidfloor: 1.2 }), - mockVideoBid({}, { bidfloor: 0.7 }), - ]); - const imps = requests[0].data.imp; - expect(imps[0].bidfloor).to.equal(1.2); - expect(imps[1].bidfloor).to.equal(0.7); - }); - - it('should have 0 bidfloor value by default', function() { - const requests = build([mockVideoBid()]); - expect(requests[0].data.imp[0].bidfloor).to.equal(0); - }); - - it('should add ats_envelope to video bid request', function() { - const envelope = 'test_envelope'; - const requests = build([mockVideoBid({}, { lr_env: envelope })]); - - expect(requests[0].data.ats_envelope).to.equal(envelope); - }); - - it('should add transaction id to video bid request', function() { - const transactionId = '54a58774-7a41-494e-8cbc-fa7b79164f0c'; - const requestData = { - ortb2Imp: { - ext: { - tid: '54a58774-7a41-494e-8cbc-fa7b79164f0c', - } - } - }; - expect(buildAndGetData([mockVideoBid({...requestData})]).imp[0].ext.tid).to.equal(transactionId); - }); - - it('should add auction id to video bid request', function() { - const auctionId = '1d1a03073455'; - expect(buildAndGetData([mockVideoBid({})]).auctionId).to.deep.equal(auctionId); - }); - - it('should add schain if it is in the bidRequest', () => { - const schain = { - ver: '1.0', - complete: 1, - nodes: [{ - asi: 'indirectseller.com', - sid: '00001', - hp: 1 - }], - }; - expect(buildAndGetData([mockVideoBid({ortb2: {source: {ext: {schain}}}})]).schain).to.deep.equal(schain); - }); - - it('should add gpid to the video request', function () { - const ortb2Imp = { - ext: { gpid: '/6355419/Travel/Europe/France/Paris' }, - }; - expect(buildAndGetData([mockVideoBid({ortb2Imp})]).imp[0].ext.gpid).to.be.equal(ortb2Imp.ext.gpid); - }); - - it('should pass consent in video bid along with eids', () => { - const params = { - userIdAsEids: [ - { - source: 'pubcid.org', - uids: [ - { - id: 'fake_pubcid', - atype: 1, - }, - ], - }, - ], - fakeUserIdAsEids: [ - { - source: 'pubcid.org', - uids: [ - { - id: 'fake_pubcid', - atype: 1, - }, - ], - }, - ], - }; - const videoBidder = mockBidderRequest( - { - gdprConsent: { - gdprApplies: 1, - consentString: 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - }, - }, - [mockVideoBid()] - ); - const payload = buildAndGetData([mockVideoBid({...params})], 0, videoBidder); - expect(payload.user.ext.consent).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A=='); - expect(payload.user.ext.eids).to.eql(params.fakeUserIdAsEids); - }); - - it('should add eids to the video bid request', function () { - const params = { - userIdAsEids: [{ - source: 'pubcid.org', - uids: [ - { - id: 'fake_pubcid', - atype: 1, - } - ] - }], - fakeUserIdAsEids: [{ - source: 'pubcid.org', - uids: [{ - id: 'fake_pubcid', - atype: 1 - }] - }] - }; - expect(buildAndGetData([mockVideoBid({...params})]).user.ext.eids).to.eql(params.fakeUserIdAsEids); - }); - - it('should add topics to the bid request', function () { - const videoBidder = mockBidderRequest( - { - ortb2: { - user: { - data: [ - { - ext: { - segtax: 600, - segclass: '2206021246', - }, - segment: ['7', '8', '9'], - }, - ], - }, - }, - }, - [mockVideoBid()] - ); - const payload = buildAndGetData([mockVideoBid()], 0, videoBidder); - expect(payload.topics).to.deep.equal({ - taxonomy: 600, - classifier: '2206021246', - topics: [7, 8, 9], - }); - }); - - it('should send gpc in the bid request', function () { - const videoBidder = mockBidderRequest( - { - ortb2: { - regs: { - ext: { - gpc: '1', - }, - }, - }, - }, - [mockVideoBid()] - ); - const payload = buildAndGetData([mockVideoBid()], 0, videoBidder); - expect(payload.regs.ext.gpc).to.equal('1'); - }); - - it('should add device info to payload if available', function () { - let videoBidder = mockBidderRequest({ ortb2: { - device: { - sua: { - platform: { - brand: 'macOS', - version: [ '12', '4', '0' ] - }, - browsers: [ - { - brand: 'Chromium', - version: [ '106', '0', '5249', '119' ] - }, - { - brand: 'Google Chrome', - version: [ '106', '0', '5249', '119' ] - }, - { - brand: 'Not;A=Brand', - version: [ '99', '0', '0', '0' ] - } - ], - mobile: 0, - model: '', - bitness: '64', - architecture: 'x86' - } - } - }}, [mockVideoBid()]); - let payload = buildAndGetData([mockVideoBid()], 0, videoBidder); - expect(payload.device.sua).to.exist; - expect(payload.device.sua).to.deep.equal({ - platform: { - brand: 'macOS', - version: [ '12', '4', '0' ] - }, - browsers: [ - { - brand: 'Chromium', - version: [ '106', '0', '5249', '119' ] - }, - { - brand: 'Google Chrome', - version: [ '106', '0', '5249', '119' ] - }, - { - brand: 'Not;A=Brand', - version: [ '99', '0', '0', '0' ] - } - ], - mobile: 0, - model: '', - bitness: '64', - architecture: 'x86' - } - ); - expect(payload.device.ua).to.not.exist; - expect(payload.device.language).to.not.exist; - // remove sua info and check device object - videoBidder = mockBidderRequest({ ortb2: { - device: { - ua: navigator.userAgent, - language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage), - } - }}, [mockVideoBid()]); - payload = buildAndGetData([mockVideoBid()], 0, videoBidder); - expect(payload.device.sua).to.not.exist; - expect(payload.device.ua).to.exist; - expect(payload.device.language).to.exist; - }); - }); - }); - - describe('interpretResponse', function () { - const mockServerResponse = () => ({ - body: [{ - callback_id: '21989fdbef550a', - cpm: 3.45455, - publisherDealId: 'YMO_123', - width: 300, - height: 250, - ad: '' + - '
', - creative_id: '9874652394875', - adomain: ['www.example.com'], - }], - header: 'header?', - }); - - it('should correctly reorder the server response', function () { - const newResponse = spec.interpretResponse(mockServerResponse()); - expect(newResponse.length).to.be.equal(1); - expect(newResponse[0]).to.deep.equal({ - dealId: 'YMO_123', - requestId: '21989fdbef550a', - cpm: 3.45455, - width: 300, - height: 250, - creativeId: '9874652394875', - currency: 'USD', - netRevenue: true, - ttl: 300, - ad: '' + - '
', - meta: { - advertiserDomains: ['www.example.com'], - mediaType: 'banner', - }, - }); - }); - - it('should correctly reorder video bids', function () { - const response = mockServerResponse(); - const seatbid = [ - { - bid: { - adm: '', - adomain: ['www.example.com'], - crid: 'dd65c0a7536aff', - impid: '91ea8bba1', - price: 1.5, - dealid: 'YMO_456' - }, - }, - ]; - const bidRequest = { - data: { - imp: [ - { - id: '91ea8bba1', - video: { - h: 250, - w: 300, - }, - }, - ], - }, - }; - - response.body.seatbid = seatbid; - - const newResponse = spec.interpretResponse(response, bidRequest); - expect(newResponse.length).to.be.equal(2); - expect(newResponse[1]).to.deep.equal({ - dealId: 'YMO_456', - cpm: 1.5, - creativeId: 'dd65c0a7536aff', - currency: 'USD', - height: 250, - mediaType: 'video', - meta: { - advertiserDomains: ['www.example.com'], - mediaType: 'video', - }, - netRevenue: true, - requestId: '91ea8bba1', - ttl: 300, - vastXml: '', - width: 300, - }); - }); - - it('should not add responses if the cpm is 0 or null', function () { - const response = mockServerResponse(); - response.body[0].cpm = 0; - expect(spec.interpretResponse(response)).to.deep.equal([]); - - response.body[0].cpm = null; - expect(spec.interpretResponse(response)).to.deep.equal([]); - }); - }); - - describe('getUserSync', function () { - const gdprFlag = `&gdpr=0`; - const usPrivacy = `us_privacy=`; - const gdprString = `&gdpr_consent=`; - const pbCookieAssistSyncUrl = `${PB_COOKIE_ASSIST_SYNC_ENDPOINT}?${usPrivacy}${gdprFlag}${gdprString}`; - it('should use type iframe when iframeEnabled', function() { - const syncs = spec.getUserSyncs({iframeEnabled: true}); - expect(syncs).to.deep.equal([{type: 'iframe', url: pbCookieAssistSyncUrl + '&type=iframe'}]) - }); - it('should use type image when pixelEnabled', function() { - const syncs = spec.getUserSyncs({pixelEnabled: true}); - expect(syncs).to.deep.equal([{type: 'image', url: pbCookieAssistSyncUrl + '&type=image'}]) - }); - it('should register no syncs', function () { - expect(spec.getUserSyncs({})).to.deep.equal([]); - }); - }); -}); diff --git a/test/spec/modules/yieldoneAnalyticsAdapter_spec.js b/test/spec/modules/yieldoneAnalyticsAdapter_spec.js deleted file mode 100644 index 7721c81f3..000000000 --- a/test/spec/modules/yieldoneAnalyticsAdapter_spec.js +++ /dev/null @@ -1,289 +0,0 @@ -import yieldoneAnalytics from 'modules/yieldoneAnalyticsAdapter.js'; -import { targeting } from 'src/targeting.js'; -import { expect } from 'chai'; -import _ from 'lodash'; -import { EVENTS } from 'src/constants.js'; - -const events = require('src/events'); -const adapterManager = require('src/adapterManager').default; - -describe('Yieldone Prebid Analytic', function () { - let sendStatStub; - let getAllTargetingStub; - const fakeTargeting = { - '0000': {'someId': 'someValue'} - }; - let clock; - - describe('enableAnalytics', function () { - beforeEach(function () { - sendStatStub = sinon.stub(yieldoneAnalytics, 'sendStat'); - getAllTargetingStub = sinon.stub(targeting, 'getAllTargeting').returns(fakeTargeting); - sinon.stub(events, 'getEvents').returns([]); - clock = sinon.useFakeTimers(); - }); - - afterEach(function () { - sendStatStub.restore(); - getAllTargetingStub.restore(); - events.getEvents.restore(); - clock.restore(); - }); - - after(function () { - yieldoneAnalytics.disableAnalytics(); - }); - - it('should catch all events', function () { - adapterManager.registerAnalyticsAdapter({ - code: 'yieldone', - adapter: yieldoneAnalytics - }); - - const initOptions = { - pubId: '123456' - }; - - const auctionId = 'test-test-test'; - const testReferrer = 'http://test'; - - const request = [ - { - bidderCode: 'biddertest_1', - auctionId: auctionId, - refererInfo: {page: testReferrer}, - bids: [ - { - adUnitCode: '0000', - auctionId: auctionId, - bidId: '1234', - bidder: 'biddertest_1', - mediaTypes: {banner: {sizes: [[300, 250], [336, 280]]}}, - params: {param1: '111', param2: '222'}, - sizes: [[300, 250], [336, 280]] - }, - { - adUnitCode: '0000', - auctionId: auctionId, - bidId: '5678', - bidder: 'biddertest_1', - mediaTypes: {banner: {sizes: [[300, 250], [336, 280]]}}, - params: {param1: '222', param2: '222'}, - sizes: [[300, 250], [336, 280]] - } - ] - }, - { - bidderCode: 'biddertest_2', - auctionId: auctionId, - refererInfo: {page: testReferrer}, - bids: [ - { - adUnitCode: '0000', - auctionId: auctionId, - bidId: '91011', - bidder: 'biddertest_2', - mediaTypes: {banner: {sizes: [[300, 250], [336, 280]]}}, - params: {paramA: '111', paramB: '222'}, - sizes: [[300, 250], [336, 280]] - } - ] - }, - { - bidderCode: 'biddertest_3', - auctionId: auctionId, - refererInfo: {page: testReferrer}, - bids: [ - { - adUnitCode: '0000', - auctionId: auctionId, - bidId: '12131', - bidder: 'biddertest_3', - mediaTypes: {banner: {sizes: [[300, 250], [336, 280]]}}, - params: {param_1: '111', param_2: '222'}, - sizes: [[300, 250], [336, 280]] - }, - { - adUnitCode: '0000', - auctionId: auctionId, - bidId: '14151', - bidder: 'biddertest_3', - mediaTypes: {banner: {sizes: [[300, 250], [336, 280]]}}, - params: {param_1: '333', param_2: '222'}, - sizes: [[300, 250], [336, 280]] - } - ] - } - ]; - - const responses = [ - { - ad: 'test ad content 1', - width: 300, - height: 250, - statusMessage: 'Bid available', - bidId: '1234', - auctionId: auctionId, - cpm: 0.1, - bidder: 'biddertest_1', - adUnitCode: '0000', - timeToRespond: 100 - }, - { - ad: 'test ad content 2', - width: 336, - height: 280, - statusMessage: 'Bid available', - bidId: '5678', - auctionId: auctionId, - cpm: 0.2, - bidder: 'biddertest_1', - adUnitCode: '0000', - timeToRespond: 100 - }, - { - ad: 'test ad content 3', - width: 300, - height: 250, - statusMessage: 'Bid available', - bidId: '91011', - auctionId: auctionId, - cpm: 0.3, - bidder: 'biddertest_2', - adUnitCode: '0000', - timeToRespond: 100 - }, - { - bidId: '12131', - auctionId: auctionId, - bidder: 'biddertest_3' - }, - { - bidId: '14151', - auctionId: auctionId, - bidder: 'biddertest_3' - } - ]; - - const winner = { - ad: 'test ad content 3', - width: 300, - height: 250, - statusMessage: 'Bid available', - bidId: '91011', - auctionId: auctionId, - cpm: 0.3, - bidder: 'biddertest_2', - adUnitCode: '0000', - timeToRespond: 100 - }; - - const auctionEnd = { - auctionId: auctionId, - bidsReceived: responses.slice(0, 3) - }; - - const preparedResponses = responses.map((resp) => { - const res = Object.assign({}, resp); - delete res.ad; - return res; - }); - - const expectedEvents = [ - { - eventType: EVENTS.AUCTION_INIT, - params: { - config: initOptions, - auctionId: auctionId - } - }, - { - eventType: EVENTS.BID_REQUESTED, - params: Object.assign(request[0]) - }, - { - eventType: EVENTS.BID_REQUESTED, - params: Object.assign(request[1]) - }, - { - eventType: EVENTS.BID_REQUESTED, - params: Object.assign(request[2]) - }, - { - eventType: EVENTS.BID_RESPONSE, - params: Object.assign(preparedResponses[0]) - }, - { - eventType: EVENTS.BID_RESPONSE, - params: Object.assign(preparedResponses[1]) - }, - { - eventType: EVENTS.BID_RESPONSE, - params: Object.assign(preparedResponses[2]) - }, - { - eventType: EVENTS.BID_TIMEOUT, - params: Object.assign(request[2]) - } - ]; - const expectedResult = { - pubId: initOptions.pubId, - page: {url: testReferrer}, - wrapper_version: '$prebid.version$', - events: sinon.match(evs => { - return !expectedEvents.some((expectedEvent) => evs.find(ev => _.isEqual(ev, expectedEvent)) === -1) - }) - }; - - const preparedWinnerParams = Object.assign({adServerTargeting: fakeTargeting}, winner); - delete preparedWinnerParams.ad; - const wonExpectedEvents = [ - { - eventType: EVENTS.BID_WON, - params: preparedWinnerParams - } - ]; - const wonExpectedResult = { - pubId: initOptions.pubId, - page: {url: testReferrer}, - wrapper_version: '$prebid.version$', - events: wonExpectedEvents - }; - - adapterManager.enableAnalytics({ - provider: 'yieldone', - options: initOptions - }); - - events.emit(EVENTS.AUCTION_INIT, { config: initOptions, auctionId: auctionId }); - - events.emit(EVENTS.BID_REQUESTED, request[0]); - events.emit(EVENTS.BID_REQUESTED, request[1]); - events.emit(EVENTS.BID_REQUESTED, request[2]); - - events.emit(EVENTS.BID_RESPONSE, responses[0]); - events.emit(EVENTS.BID_RESPONSE, responses[1]); - events.emit(EVENTS.BID_RESPONSE, responses[2]); - - events.emit(EVENTS.BID_TIMEOUT, [responses[3], responses[4]]); - - events.emit(EVENTS.AUCTION_END, auctionEnd); - - sinon.assert.match(yieldoneAnalytics.eventsStorage[auctionId], expectedResult); - - delete yieldoneAnalytics.eventsStorage[auctionId]; - - clock.tick(1000); - events.emit(EVENTS.BID_WON, winner); - - sinon.assert.callCount(sendStatStub, 2); - const billableEventIndex = yieldoneAnalytics.eventsStorage[auctionId].events.findIndex(event => event.eventType === EVENTS.BILLABLE_EVENT); - if (billableEventIndex > -1) { - yieldoneAnalytics.eventsStorage[auctionId].events.splice(billableEventIndex, 1); - } - expect(yieldoneAnalytics.eventsStorage[auctionId]).to.deep.equal(wonExpectedResult); - - delete yieldoneAnalytics.eventsStorage[auctionId]; - }); - }); -}); diff --git a/test/spec/modules/yieldoneBidAdapter_spec.js b/test/spec/modules/yieldoneBidAdapter_spec.js deleted file mode 100644 index 7e3ae3b94..000000000 --- a/test/spec/modules/yieldoneBidAdapter_spec.js +++ /dev/null @@ -1,737 +0,0 @@ -import { expect } from 'chai'; -import { spec } from 'modules/yieldoneBidAdapter.js'; -import { newBidder } from 'src/adapters/bidderFactory.js'; -import { getBrowser, getOS } from '../../../libraries/userAgentUtils/index.js'; -import { browserTypes, osTypes } from '../../../libraries/userAgentUtils/userAgentTypes.enums.js'; - -const ENDPOINT = 'https://y.one.impact-ad.jp/h_bid'; -const USER_SYNC_URL = 'https://y.one.impact-ad.jp/push_sync'; -const VIDEO_PLAYER_URL = 'https://img.ak.impact-ad.jp/ic/pone/ivt/firstview/js/dac-video-prebid.min.js'; - -const DEFAULT_VIDEO_SIZE = {w: 640, h: 360}; - -describe('yieldoneBidAdapter', function () { - const adapter = newBidder(spec); - - describe('isBidRequestValid', function () { - const bid = { - 'bidder': 'yieldone', - 'params': { - placementId: '36891' - }, - 'adUnitCode': 'adunit-code', - 'sizes': [[300, 250], [336, 280]], - 'bidId': '23beaa6af6cdde', - 'bidderRequestId': '19c0c1efdf37e7', - 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', - }; - - it('should return true when required params found', function () { - expect(spec.isBidRequestValid(bid)).to.equal(true); - }); - - it('should return false when placementId not passed correctly', function () { - bid.params.placementId = ''; - expect(spec.isBidRequestValid(bid)).to.equal(false); - }); - - it('should return false when require params are not passed', function () { - const invalidBid = Object.assign({}, bid); - invalidBid.params = {}; - expect(spec.isBidRequestValid(invalidBid)).to.equal(false); - }); - }); - - describe('buildRequests', function () { - const bidderRequest = { - refererInfo: { - numIframes: 0, - reachedTop: true, - referer: 'http://example.com', - stack: ['http://example.com'] - } - }; - - describe('Basic', function () { - const bidRequests = [ - { - 'bidder': 'yieldone', - 'params': {placementId: '36891'}, - 'adUnitCode': 'adunit-code1', - 'bidId': '23beaa6af6cdde', - 'bidderRequestId': '19c0c1efdf37e7', - 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', - }, - { - 'bidder': 'yieldone', - 'params': {placementId: '47919'}, - 'adUnitCode': 'adunit-code2', - 'bidId': '382091349b149f"', - 'bidderRequestId': '"1f9c98192de251"', - 'auctionId': '61466567-d482-4a16-96f0-fe5f25ffbdf1', - } - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - - it('sends bid request to our endpoint via GET', function () { - expect(request[0].method).to.equal('GET'); - expect(request[1].method).to.equal('GET'); - }); - it('attaches source and version to endpoint URL as query params', function () { - expect(request[0].url).to.equal(ENDPOINT); - expect(request[1].url).to.equal(ENDPOINT); - }); - it('adUnitCode should be sent as uc parameters on any requests', function () { - expect(request[0].data.uc).to.equal('adunit-code1'); - expect(request[1].data.uc).to.equal('adunit-code2'); - }); - }); - - describe('Old Format', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - mediaType: 'banner', - sizes: [[300, 250], [336, 280]], - }, - { - params: {placementId: '1'}, - mediaType: 'banner', - sizes: [[336, 280]], - }, - { - // It doesn't actually exist. - params: {placementId: '2'}, - }, - { - params: {placementId: '3'}, - mediaType: 'video', - sizes: [[1280, 720], [1920, 1080]], - }, - { - params: {placementId: '4'}, - mediaType: 'video', - sizes: [[1920, 1080]], - }, - { - params: {placementId: '5'}, - mediaType: 'video', - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - - it('parameter sz has more than one size on banner requests', function () { - expect(request[0].data.sz).to.equal('300x250,336x280'); - expect(request[1].data.sz).to.equal('336x280'); - expect(request[2].data.sz).to.equal(''); - expect(request[3].data).to.not.have.property('sz'); - expect(request[4].data).to.not.have.property('sz'); - expect(request[5].data).to.not.have.property('sz'); - }); - - it('width and height should be set as separate parameters on outstream requests', function () { - expect(request[0].data).to.not.have.property('w'); - expect(request[1].data).to.not.have.property('w'); - expect(request[2].data).to.not.have.property('w'); - expect(request[3].data.w).to.equal(1280); - expect(request[3].data.h).to.equal(720); - expect(request[4].data.w).to.equal(1920); - expect(request[4].data.h).to.equal(1080); - expect(request[5].data.w).to.equal(DEFAULT_VIDEO_SIZE.w); - expect(request[5].data.h).to.equal(DEFAULT_VIDEO_SIZE.h); - }); - }); - - describe('Single Format', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - mediaTypes: { - banner: { - sizes: [[300, 250], [336, 280]], - }, - }, - }, - { - params: {placementId: '1'}, - mediaTypes: { - banner: { - sizes: [[336, 280]], - }, - }, - }, - { - // It doesn't actually exist. - params: {placementId: '2'}, - mediaTypes: { - banner: { - }, - }, - }, - { - params: {placementId: '3'}, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [[1280, 720], [1920, 1080]], - }, - }, - }, - { - params: {placementId: '4'}, - mediaTypes: { - video: { - context: 'outstream', - playerSize: [1920, 1080], - }, - }, - }, - { - params: {placementId: '5'}, - mediaTypes: { - video: { - context: 'outstream', - }, - }, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - - it('parameter sz has more than one size on banner requests', function () { - expect(request[0].data.sz).to.equal('300x250,336x280'); - expect(request[1].data.sz).to.equal('336x280'); - expect(request[2].data.sz).to.equal(''); - expect(request[3].data).to.not.have.property('sz'); - expect(request[4].data).to.not.have.property('sz'); - expect(request[5].data).to.not.have.property('sz'); - }); - - it('width and height should be set as separate parameters on outstream requests', function () { - expect(request[0].data).to.not.have.property('w'); - expect(request[0].data).to.not.have.property('h'); - expect(request[1].data).to.not.have.property('w'); - expect(request[1].data).to.not.have.property('h'); - expect(request[2].data).to.not.have.property('w'); - expect(request[2].data).to.not.have.property('h'); - expect(request[3].data.w).to.equal(1280); - expect(request[3].data.h).to.equal(720); - expect(request[4].data.w).to.equal(1920); - expect(request[4].data.h).to.equal(1080); - expect(request[5].data.w).to.equal(DEFAULT_VIDEO_SIZE.w); - expect(request[5].data.h).to.equal(DEFAULT_VIDEO_SIZE.h); - }); - }); - - describe('Multiple Format', function () { - const bidRequests = [ - { - // It will be treated as a banner. - params: { - placementId: '0', - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [336, 280]], - }, - video: { - context: 'outstream', - playerSize: [1920, 1080], - }, - }, - }, - { - // It will be treated as a video. - params: { - placementId: '1', - playerParams: {}, - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [336, 280]], - }, - video: { - context: 'outstream', - playerSize: [1920, 1080], - }, - }, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - - it('parameter sz has more than one size on banner requests', function () { - expect(request[0].data.sz).to.equal('300x250,336x280'); - expect(request[1].data).to.not.have.property('sz'); - }); - - it('width and height should be set as separate parameters on outstream requests', function () { - expect(request[0].data).to.not.have.property('w'); - expect(request[0].data).to.not.have.property('h'); - expect(request[1].data.w).to.equal(1920); - expect(request[1].data.h).to.equal(1080); - }); - }); - - describe('1x1 Format', function () { - const bidRequests = [ - { - // It will be treated as a banner. - params: { - placementId: '0', - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [336, 280]], - }, - video: { - context: 'outstream', - playerSize: [[1, 1]], - }, - }, - }, - { - // It will be treated as a video. - params: { - placementId: '1', - playerParams: {}, - playerSize: [1920, 1080], - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [336, 280]], - }, - video: { - context: 'outstream', - playerSize: [[1, 1]], - }, - }, - }, - { - // It will be treated as a video. - params: { - placementId: '2', - playerParams: {}, - }, - mediaTypes: { - banner: { - sizes: [[300, 250], [336, 280]], - }, - video: { - context: 'outstream', - playerSize: [[1, 1]], - }, - }, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - - it('parameter sz has more than one size on banner requests', function () { - expect(request[0].data.sz).to.equal('300x250,336x280'); - expect(request[1].data).to.not.have.property('sz'); - expect(request[2].data).to.not.have.property('sz'); - }); - - it('width and height should be set as separate parameters on outstream requests', function () { - expect(request[0].data).to.not.have.property('w'); - expect(request[0].data).to.not.have.property('h'); - expect(request[1].data.w).to.equal(1920); - expect(request[1].data.h).to.equal(1080); - expect(request[2].data.w).to.equal(DEFAULT_VIDEO_SIZE.w); - expect(request[2].data.h).to.equal(DEFAULT_VIDEO_SIZE.h); - }); - }); - - describe('LiveRampID', function () { - it('dont send LiveRampID if undefined', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - }, - { - params: {placementId: '1'}, - userId: {}, - }, - { - params: {placementId: '2'}, - userId: undefined, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].data).to.not.have.property('lr_env'); - expect(request[1].data).to.not.have.property('lr_env'); - expect(request[2].data).to.not.have.property('lr_env'); - }); - - it('should send LiveRampID if available', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - userId: {idl_env: 'idl_env_sample'}, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].data.lr_env).to.equal('idl_env_sample'); - }); - }); - - describe('IMID', function () { - it('dont send IMID if undefined', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - }, - { - params: {placementId: '1'}, - userId: {}, - }, - { - params: {placementId: '2'}, - userId: undefined, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].data).to.not.have.property('imuid'); - expect(request[1].data).to.not.have.property('imuid'); - expect(request[2].data).to.not.have.property('imuid'); - }); - - it('should send IMID if available', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - userId: {imuid: 'imuid_sample'}, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].data.imuid).to.equal('imuid_sample'); - }); - }); - - describe('DAC ID', function () { - it('dont send DAC ID if undefined', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - }, - { - params: {placementId: '1'}, - userId: {}, - }, - { - params: {placementId: '2'}, - userId: undefined, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].data).to.not.have.property('dac_id'); - expect(request[1].data).to.not.have.property('dac_id'); - expect(request[2].data).to.not.have.property('dac_id'); - expect(request[0].data).to.not.have.property('fuuid'); - expect(request[1].data).to.not.have.property('fuuid'); - expect(request[2].data).to.not.have.property('fuuid'); - }); - - it('should send DAC ID if available', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - userId: {dacId: {fuuid: 'fuuid_sample', id: 'dacId_sample'}}, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].data.fuuid).to.equal('fuuid_sample'); - expect(request[0].data.dac_id).to.equal('dacId_sample'); - }); - }); - - describe('ID5', function () { - it('dont send ID5 if undefined', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - }, - { - params: {placementId: '1'}, - userId: {}, - }, - { - params: {placementId: '2'}, - userId: undefined, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].data).to.not.have.property('id5Id'); - expect(request[1].data).to.not.have.property('id5Id'); - expect(request[2].data).to.not.have.property('id5Id'); - }); - - it('should send ID5 if available', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - userId: {id5id: {uid: 'id5id_sample'}}, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].data.id5Id).to.equal('id5id_sample'); - }); - }); - - describe('UID2.0', function () { - it('dont send UID2.0 if undefined', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - }, - { - params: {placementId: '1'}, - userId: {}, - }, - { - params: {placementId: '2'}, - userId: undefined, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].data).to.not.have.property('uid2id'); - expect(request[1].data).to.not.have.property('uid2id'); - expect(request[2].data).to.not.have.property('uid2id'); - }); - - it('should send UID2.0 if available', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - userId: {uid2: {id: 'uid2_sample'}}, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].data.uid2id).to.equal('uid2_sample'); - }); - }); - - describe('GPID', function () { - it('dont send GPID if undefined', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - }, - { - params: {placementId: '1'}, - ortb2Imp: {}, - }, - { - params: {placementId: '2'}, - ortb2Imp: undefined, - }, - { - params: {placementId: '3'}, - ortb2Imp: {ext: {gpid: undefined, data: {pubadslot: 'aaa'}}}, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].data).to.not.have.property('gpid'); - expect(request[1].data).to.not.have.property('gpid'); - expect(request[2].data).to.not.have.property('gpid'); - expect(request[3].data).to.not.have.property('gpid'); - }); - - it('should send GPID if available', function () { - const bidRequests = [ - { - params: {placementId: '0'}, - ortb2Imp: {ext: {gpid: 'gpid_sample'}}, - }, - ]; - const request = spec.buildRequests(bidRequests, bidderRequest); - expect(request[0].data.ext).to.be.not.null; - expect(request[0].data).to.have.property('gpid'); - expect(request[0].data.gpid).to.equal('gpid_sample'); - }); - }); - }); - - describe('interpretResponse', function () { - const bidRequestBanner = [ - { - 'method': 'GET', - 'url': 'https://y.one.impact-ad.jp/h_bid', - 'data': { - 'v': 'hb1', - 'p': '36891', - 'sz': '300x250,336x280', - 'cb': 12892917383, - 'r': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836', - 'uid': '23beaa6af6cdde', - 't': 'i', - 'language': 'ja', - 'screen_size': '1440x900' - } - } - ]; - - const serverResponseBanner = { - body: { - 'adTag': '', - 'uid': '23beaa6af6cdde', - 'height': 250, - 'width': 300, - 'cpm': 0.0536616, - 'crid': '2494768', - 'currency': 'JPY', - 'statusMessage': 'Bid available', - 'dealId': 'P1-FIX-7800-DSP-MON', - 'adomain': [ - 'www.example.com' - ], - } - }; - - it('should get the correct bid response for banner', function () { - const expectedResponse = [{ - 'requestId': '23beaa6af6cdde', - 'cpm': 53.6616, - 'width': 300, - 'height': 250, - 'creativeId': '2494768', - 'dealId': 'P1-FIX-7800-DSP-MON', - 'currency': 'JPY', - 'netRevenue': true, - 'ttl': 3000, - 'referrer': '', - 'meta': { - 'advertiserDomains': [ - 'www.example.com' - ] - }, - 'mediaType': 'banner', - 'ad': '' - }]; - const result = spec.interpretResponse(serverResponseBanner, bidRequestBanner[0]); - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); - expect(result[0].requestId).to.equal(expectedResponse[0].requestId); - expect(result[0].cpm).to.equal(expectedResponse[0].cpm); - expect(result[0].width).to.equal(expectedResponse[0].width); - expect(result[0].height).to.equal(expectedResponse[0].height); - expect(result[0].creativeId).to.equal(expectedResponse[0].creativeId); - expect(result[0].dealId).to.equal(expectedResponse[0].dealId); - expect(result[0].currency).to.equal(expectedResponse[0].currency); - expect(result[0].mediaType).to.equal(expectedResponse[0].mediaType); - expect(result[0].ad).to.equal(expectedResponse[0].ad); - expect(result[0].meta.advertiserDomains[0]).to.equal(expectedResponse[0].meta.advertiserDomains[0]); - }); - - const serverResponseVideo = { - body: { - 'uid': '23beaa6af6cdde', - 'height': 360, - 'width': 640, - 'cpm': 0.0536616, - 'dealId': 'P1-FIX-7800-DSP-MON', - 'crid': '2494768', - 'currency': 'JPY', - 'statusMessage': 'Bid available', - 'adm': '' - } - }; - - const bidRequestVideo = [ - { - 'method': 'GET', - 'url': 'https://y.one.impact-ad.jp/h_bid', - 'data': { - 'v': 'hb1', - 'p': '41993', - 'w': '640', - 'h': '360', - 'cb': 12892917383, - 'r': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836', - 'uid': '23beaa6af6cdde', - 't': 'i', - 'language': 'ja', - 'screen_size': '1440x900' - } - } - ]; - - it('should get the correct bid response for video', function () { - const expectedResponse = [{ - 'requestId': '23beaa6af6cdde', - 'cpm': 53.6616, - 'width': 640, - 'height': 360, - 'creativeId': '2494768', - 'dealId': 'P1-FIX-7800-DSP-MON', - 'currency': 'JPY', - 'netRevenue': true, - 'ttl': 3000, - 'referrer': 'http%3A%2F%2Flocalhost%3A9876%2F%3Fid%3D74552836', - 'meta': { - 'advertiserDomains': [] - }, - 'mediaType': 'video', - 'vastXml': '', - 'renderer': { - id: '23beaa6af6cdde', - url: VIDEO_PLAYER_URL - } - }]; - const result = spec.interpretResponse(serverResponseVideo, bidRequestVideo[0]); - expect(Object.keys(result[0])).to.deep.equal(Object.keys(expectedResponse[0])); - expect(result[0].requestId).to.equal(expectedResponse[0].requestId); - expect(result[0].cpm).to.equal(expectedResponse[0].cpm); - expect(result[0].width).to.equal(expectedResponse[0].width); - expect(result[0].height).to.equal(expectedResponse[0].height); - expect(result[0].creativeId).to.equal(expectedResponse[0].creativeId); - expect(result[0].dealId).to.equal(expectedResponse[0].dealId); - expect(result[0].currency).to.equal(expectedResponse[0].currency); - expect(result[0].vastXml).to.equal(expectedResponse[0].vastXml); - expect(result[0].mediaType).to.equal(expectedResponse[0].mediaType); - expect(result[0].referrer).to.equal(expectedResponse[0].referrer); - expect(result[0].renderer.id).to.equal(expectedResponse[0].renderer.id); - expect(result[0].renderer.url).to.equal(expectedResponse[0].renderer.url); - expect(result[0].meta.advertiserDomains[0]).to.equal(expectedResponse[0].meta.advertiserDomains[0]); - }); - - it('handles empty bid response', function () { - const response = { - body: { - 'uid': '2c0b634db95a01', - 'height': 0, - 'crid': '', - 'statusMessage': 'Bid returned empty or error response', - 'width': 0, - 'cpm': 0 - } - }; - const result = spec.interpretResponse(response, bidRequestBanner[0]); - expect(result.length).to.equal(0); - }); - }); - - describe('getUserSyncs', function () { - it('handles empty sync options', function () { - expect(spec.getUserSyncs({})).to.be.undefined; - }); - - it('should return a sync url if iframe syncs are enabled and UserAgent is not Safari or iOS', function () { - const result = spec.getUserSyncs({ - 'iframeEnabled': true - }); - - if (getBrowser() === browserTypes.SAFARI || getOS() === osTypes.IOS) { - expect(result).to.be.undefined; - } else { - expect(result).to.deep.equal([{ - type: 'iframe', url: USER_SYNC_URL - }]); - } - }); - - it('should skip sync request in case GDPR applies', function () { - expect(spec.getUserSyncs({'iframeEnabled': true}, [], { - consentString: 'GDPR_CONSENT_STRING', - gdprApplies: true, - })).to.be.undefined; - }); - }); -}); diff --git a/test/spec/modules/yuktamediaAnalyticsAdapter_spec.js b/test/spec/modules/yuktamediaAnalyticsAdapter_spec.js deleted file mode 100644 index 9366821fa..000000000 --- a/test/spec/modules/yuktamediaAnalyticsAdapter_spec.js +++ /dev/null @@ -1,714 +0,0 @@ -import yuktamediaAnalyticsAdapter from 'modules/yuktamediaAnalyticsAdapter.js'; -import { expect } from 'chai'; -import { EVENTS } from 'src/constants.js'; - -const events = require('src/events'); - -const prebidAuction = { - 'auctionInit': { - 'auctionId': 'ca421611-0bc0-4164-a69c-fe4158c68954', - 'timestamp': 1595850680304, - }, - 'bidRequested': { - 'bidderCode': 'appnexus', - 'auctionId': 'ca421611-0bc0-4164-a69c-fe4158c68954', - 'bidderRequestId': '181df4d465699c', - 'bids': [ - { - 'bidder': 'appnexus', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'userId': { - 'id5id': { uid: 'ID5-ZHMOxXeRXPe3inZKGD-Lj0g7y8UWdDbsYXQ_n6aWMQ' }, - 'parrableid': '01.1595590997.46d951017bdc272ca50b88dbcfb0545cfc636bec3e3d8c02091fb1b413328fb2fd3baf65cb4114b3f782895fd09f82f02c9042b85b42c4654d08ba06dc77f0ded936c8ea3fc4085b4a99', - 'pubcid': '100a8bc9-f588-4c22-873e-a721cb68bc34' - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '2bccebeda7fbe4', - 'bidderRequestId': '181df4d465699c', - 'auctionId': 'ca421611-0bc0-4164-a69c-fe4158c68954', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'auctionStart': 1595850680304, - 'timeout': 1100, - 'start': 1595850680307 - }, - 'noBid': {}, - 'bidTimeout': [], - 'bidResponse': { - 'bidderCode': 'appnexus', - 'width': 300, - 'height': 250, - 'statusMessage': 'Bid available', - 'getStatusCode': function () { return 1; }, - 'adId': '3ade442375213f', - 'requestId': '2bccebeda7fbe4', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 0.5, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'auctionId': 'ca421611-0bc0-4164-a69c-fe4158c68954', - 'responseTimestamp': 1595850681254, - 'requestTimestamp': 1595850680307, - 'bidder': 'appnexus', - 'timeToRespond': 947, - 'size': '300x250', - 'adserverTargeting': { - 'hb_bidder': 'appnexus', - 'hb_adid': '3ade442375213f', - 'hb_pb': '0.50', - 'hb_size': '300x250', - 'hb_source': 'client', - 'hb_format': 'banner' - } - }, - 'auctionEnd': { - 'auctionId': 'ca421611-0bc0-4164-a69c-fe4158c68954' - }, - 'bidWon': { - 'bidderCode': 'appnexus', - 'width': 300, - 'height': 250, - 'requestId': '2bccebeda7fbe4', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 0.5, - 'currency': 'USD', - 'netRevenue': true, - 'ttl': 300, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'auctionId': 'ca421611-0bc0-4164-a69c-fe4158c68954', - 'responseTimestamp': 1595850681254, - 'requestTimestamp': 1595850680307, - 'bidder': 'appnexus', - 'timeToRespond': 947, - 'size': '300x250', - 'adserverTargeting': { - 'hb_bidder': 'appnexus', - 'hb_adid': '3ade442375213f', - 'hb_pb': '0.50', - 'hb_size': '300x250', - 'hb_source': 'client', - 'hb_format': 'banner' - }, - 'status': 'rendered' - } -}; - -const prebidNativeAuction = { - 'auctionInit': { - 'auctionId': '86e005fa-1900-4782-b6df-528500f09128', - 'timestamp': 1595589742100, - }, - 'bidRequested': { - 'bidderCode': 'appnexus', - 'auctionId': '86e005fa-1900-4782-b6df-528500f09128', - 'tid': 'f9c220eb-e44f-412b-92ff-8c24085ca675', - 'bids': [ - { - 'bidder': 'appnexus', - 'bid_id': '19a879bd73bc8d', - 'nativeParams': { - 'title': { - 'required': true, - 'len': 800 - }, - 'image': { - 'required': true, - 'sizes': [ - 989, - 742 - ] - }, - 'sponsoredBy': { - 'required': true - } - }, - 'mediaTypes': { - 'native': { - 'title': { - 'required': true, - 'len': 800 - }, - 'image': { - 'required': true, - 'sizes': [ - 989, - 742 - ] - }, - 'sponsoredBy': { - 'required': true - } - } - }, - 'adUnitCode': '/19968336/prebid_native_example_1', - 'sizes': [], - 'bidId': '19a879bd73bc8d', - 'auctionId': '86e005fa-1900-4782-b6df-528500f09128', - 'src': 's2s', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 0, - 'bidderWinsCount': 0 - }, - { - 'bidder': 'appnexus', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '28f8cc7d10f2db', - 'auctionId': '86e005fa-1900-4782-b6df-528500f09128', - 'src': 's2s', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 2, - 'bidderWinsCount': 0 - } - ], - 'auctionStart': 1595589742100, - 'timeout': 1000, - 'src': 's2s', - 'start': 1595589742108 - }, - 'bidRequested1': { - 'bidderCode': 'ix', - 'auctionId': '86e005fa-1900-4782-b6df-528500f09128', - 'bidderRequestId': '5e64168f3654af', - 'bids': [ - { - 'bidder': 'ix', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': 'dfp-ad-rightrail_top', - 'sizes': [[300, 250]], - 'bidId': '9424dea605368f', - 'bidderRequestId': '5e64168f3654af', - 'auctionId': '86e005fa-1900-4782-b6df-528500f09128', - 'src': 's2s' - } - ], - 'auctionStart': 1595589742100, - 'timeout': 1000, - 'src': 's2s', - 'start': 1595589742108 - }, - 'noBid': { - 'bidder': 'ix', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': 'dfp-ad-rightrail_top', - 'transactionId': 'd99d90e0-663a-459d-8c87-4c92ce6a527c', - 'sizes': [[300, 250]], - 'bidId': '9424dea605368f', - 'bidderRequestId': '5e64168f3654af', - 'auctionId': '86e005fa-1900-4782-b6df-528500f09128', - 'src': 's2s', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 4, - 'bidderWinsCount': 0 - }, - 'bidTimeout': [ - { - 'bidId': '28f8cc7d10f2db', - 'bidder': 'appnexus', - 'adUnitCode': 'div-gpt-ad-1460505748561-0', - 'auctionId': '86e005fa-1900-4782-b6df-528500f09128' - } - ], - 'bidResponse': { - 'bidderCode': 'appnexus', - 'statusMessage': 'Bid available', - 'source': 's2s', - 'getStatusCode': function () { return 1; }, - 'cpm': 10, - 'adserverTargeting': { - 'hb_bidder': 'appnexus', - 'hb_pb': '10.00', - 'hb_adid': '4e756c72ee9044', - 'hb_size': 'undefinedxundefined', - 'hb_source': 's2s', - 'hb_format': 'native', - 'hb_native_linkurl': 'some_long_url', - 'hb_native_title': 'This is a Prebid Native Creative', - 'hb_native_brand': 'Prebid.org' - }, - 'native': { - 'clickUrl': { - 'url': 'some_long_url' - }, - 'impressionTrackers': [ - 'some_long_url' - ], - 'javascriptTrackers': [], - 'image': { - 'url': 'some_long_image_path', - 'width': 989, - 'height': 742 - }, - 'title': 'This is a Prebid Native Creative', - 'sponsoredBy': 'Prebid.org' - }, - 'currency': 'USD', - 'ttl': 60, - 'netRevenue': true, - 'auctionId': '86e005fa-1900-4782-b6df-528500f09128', - 'responseTimestamp': 1595589742827, - 'requestTimestamp': 1595589742108, - 'bidder': 'appnexus', - 'adUnitCode': '/19968336/prebid_native_example_1', - 'timeToRespond': 719, - 'size': 'undefinedxundefined' - }, - 'auctionEnd': { - 'auctionId': '86e005fa-1900-4782-b6df-528500f09128' - }, - 'bidWon': { - 'bidderCode': 'appnexus', - 'mediaType': 'native', - 'source': 's2s', - 'getStatusCode': function () { return 1; }, - 'cpm': 10, - 'adserverTargeting': { - 'hb_bidder': 'appnexus', - 'hb_pb': '10.00', - 'hb_adid': '4e756c72ee9044', - 'hb_size': 'undefinedxundefined', - 'hb_source': 's2s', - 'hb_format': 'native', - 'hb_native_linkurl': 'some_long_url', - 'hb_native_title': 'This is a Prebid Native Creative', - 'hb_native_brand': 'Prebid.org' - }, - 'native': { - 'clickUrl': { - 'url': 'some_long_url' - }, - 'impressionTrackers': [ - 'some_long_url' - ], - 'javascriptTrackers': [], - 'image': { - 'url': 'some_long_image_path', - 'width': 989, - 'height': 742 - }, - 'title': 'This is a Prebid Native Creative', - 'sponsoredBy': 'Prebid.org' - }, - 'currency': 'USD', - 'ttl': 60, - 'netRevenue': true, - 'auctionId': '86e005fa-1900-4782-b6df-528500f09128', - 'responseTimestamp': 1595589742827, - 'requestTimestamp': 1595589742108, - 'bidder': 'appnexus', - 'adUnitCode': '/19968336/prebid_native_example_1', - 'timeToRespond': 719, - 'size': 'undefinedxundefined', - 'status': 'rendered' - } -} - -describe('yuktamedia analytics adapter', function () { - beforeEach(() => { - sinon.stub(events, 'getEvents').returns([]); - }); - afterEach(() => { - events.getEvents.restore(); - }); - - describe('enableAnalytics', function () { - beforeEach(() => { - sinon.spy(yuktamediaAnalyticsAdapter, 'track'); - }); - afterEach(() => { - yuktamediaAnalyticsAdapter.disableAnalytics(); - yuktamediaAnalyticsAdapter.track.restore(); - }); - - it('should catch all events 1', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.AUCTION_INIT, prebidAuction[EVENTS.AUCTION_INIT]); - sinon.assert.called(yuktamediaAnalyticsAdapter.track); - }); - - it('should catch all events 2', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.BID_REQUESTED, prebidAuction[EVENTS.BID_REQUESTED]); - sinon.assert.called(yuktamediaAnalyticsAdapter.track); - }); - - it('should catch all events 3', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.NO_BID, prebidAuction[EVENTS.NO_BID]); - sinon.assert.called(yuktamediaAnalyticsAdapter.track); - }); - - it('should catch all events 4', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.BID_TIMEOUT, prebidAuction[EVENTS.BID_TIMEOUT]); - sinon.assert.called(yuktamediaAnalyticsAdapter.track); - }); - - it('should catch all events 5', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.BID_RESPONSE, prebidAuction[EVENTS.BID_RESPONSE]); - sinon.assert.called(yuktamediaAnalyticsAdapter.track); - }); - - it('should catch all events 6', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.AUCTION_END, prebidAuction[EVENTS.AUCTION_END]); - sinon.assert.called(yuktamediaAnalyticsAdapter.track); - }); - - it('should catch no events if no pubKey and pubId', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - } - }); - - events.emit(EVENTS.AUCTION_INIT, {}); - events.emit(EVENTS.AUCTION_END, {}); - events.emit(EVENTS.BID_REQUESTED, {}); - events.emit(EVENTS.BID_RESPONSE, {}); - events.emit(EVENTS.BID_WON, {}); - - sinon.assert.callCount(yuktamediaAnalyticsAdapter.track, 0); - }); - - it('should catch nobid, timeout and bidwon event events one of eight', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.AUCTION_INIT, prebidNativeAuction[EVENTS.AUCTION_INIT]); - sinon.assert.called(yuktamediaAnalyticsAdapter.track); - }); - - it('should catch nobid, timeout and bidwon event events two of eight', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.BID_REQUESTED, prebidNativeAuction[EVENTS.BID_REQUESTED]); - sinon.assert.called(yuktamediaAnalyticsAdapter.track); - }); - - it('should catch nobid, timeout and bidwon event events three of eight', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.BID_REQUESTED, prebidNativeAuction[EVENTS.BID_REQUESTED + '1']); - sinon.assert.called(yuktamediaAnalyticsAdapter.track); - }); - - it('should catch nobid, timeout and bidwon event events four of eight', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.NO_BID, prebidNativeAuction[EVENTS.NO_BID]); - sinon.assert.called(yuktamediaAnalyticsAdapter.track); - }); - - it('should catch nobid, timeout and bidwon event events five of eight', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.BID_TIMEOUT, prebidNativeAuction[EVENTS.BID_TIMEOUT]); - sinon.assert.called(yuktamediaAnalyticsAdapter.track); - }); - - it('should catch nobid, timeout and bidwon event events six of eight', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.BID_RESPONSE, prebidNativeAuction[EVENTS.BID_RESPONSE]); - sinon.assert.called(yuktamediaAnalyticsAdapter.track); - }); - - it('should catch nobid, timeout and bidwon event events seven of eight', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.AUCTION_END, prebidNativeAuction[EVENTS.AUCTION_END]); - sinon.assert.called(yuktamediaAnalyticsAdapter.track); - }); - - it('should catch nobid, timeout and bidwon event events eight of eight', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.AUCTION_END, prebidNativeAuction[EVENTS.BID_WON]); - sinon.assert.called(yuktamediaAnalyticsAdapter.track); - }); - }); - - describe('build utm tag data', function () { - beforeEach(function () { - localStorage.setItem('yuktamediaAnalytics_utm_source', 'prebid'); - localStorage.setItem('yuktamediaAnalytics_utm_medium', 'ad'); - localStorage.setItem('yuktamediaAnalytics_utm_campaign', ''); - localStorage.setItem('yuktamediaAnalytics_utm_term', ''); - localStorage.setItem('yuktamediaAnalytics_utm_content', ''); - localStorage.setItem('yuktamediaAnalytics_utm_timeout', Date.now()); - }); - - afterEach(function () { - localStorage.clear(); - }); - - it('should build utm data from local storage', function () { - const utmTagData = yuktamediaAnalyticsAdapter.buildUtmTagData({ - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - }); - expect(utmTagData.utm_source).to.equal('prebid'); - expect(utmTagData.utm_medium).to.equal('ad'); - expect(utmTagData.utm_campaign).to.equal(''); - expect(utmTagData.utm_term).to.equal(''); - expect(utmTagData.utm_content).to.equal(''); - }); - - it('should return empty object for disabled utm setting', function () { - const utmTagData = yuktamediaAnalyticsAdapter.buildUtmTagData({ - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: false, - enableSession: true, - enableUserIdCollection: true - }); - expect(utmTagData).deep.equal({}); - }); - }); - - describe('build session information', function () { - beforeEach(() => { - sinon.spy(yuktamediaAnalyticsAdapter, 'track'); - localStorage.clear(); - }); - afterEach(() => { - yuktamediaAnalyticsAdapter.disableAnalytics(); - yuktamediaAnalyticsAdapter.track.restore(); - localStorage.clear(); - }); - - it('should create session id in local storage if enabled', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: true, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.AUCTION_INIT, prebidAuction[EVENTS.AUCTION_INIT]); - events.emit(EVENTS.BID_REQUESTED, prebidAuction[EVENTS.BID_REQUESTED]); - events.emit(EVENTS.NO_BID, prebidAuction[EVENTS.NO_BID]); - events.emit(EVENTS.BID_TIMEOUT, prebidAuction[EVENTS.BID_TIMEOUT]); - events.emit(EVENTS.BID_RESPONSE, prebidAuction[EVENTS.BID_RESPONSE]); - events.emit(EVENTS.AUCTION_END, prebidAuction[EVENTS.AUCTION_END]); - expect(localStorage.getItem('yuktamediaAnalytics_session_id')).to.not.equal(null); - }); - - it('should not create session id in local storage if disabled', function () { - yuktamediaAnalyticsAdapter.enableAnalytics({ - provider: 'yuktamedia', - options: { - pubId: '1', - pubKey: 'ZXlKaGJHY2lPaUpJVXpJMU5pSjkuT==', - enableUTMCollection: true, - enableSession: false, - enableUserIdCollection: true - } - }); - events.emit(EVENTS.AUCTION_INIT, prebidAuction[EVENTS.AUCTION_INIT]); - events.emit(EVENTS.BID_REQUESTED, prebidAuction[EVENTS.BID_REQUESTED]); - events.emit(EVENTS.NO_BID, prebidAuction[EVENTS.NO_BID]); - events.emit(EVENTS.BID_TIMEOUT, prebidAuction[EVENTS.BID_TIMEOUT]); - events.emit(EVENTS.BID_RESPONSE, prebidAuction[EVENTS.BID_RESPONSE]); - events.emit(EVENTS.AUCTION_END, prebidAuction[EVENTS.AUCTION_END]); - expect(localStorage.getItem('yuktamediaAnalytics_session_id')).to.equal(null); - }); - }); -}); diff --git a/test/spec/modules/zeta_globalBidAdapter_spec.js b/test/spec/modules/zeta_globalBidAdapter_spec.js deleted file mode 100644 index 031b52d19..000000000 --- a/test/spec/modules/zeta_globalBidAdapter_spec.js +++ /dev/null @@ -1,84 +0,0 @@ -import { spec } from '../../../modules/zeta_globalBidAdapter.js' - -describe('Zeta Bid Adapter', function() { - const bannerRequest = [{ - bidId: 12345, - auctionId: 67890, - mediaTypes: { - banner: { - sizes: [[300, 250]], - } - }, - refererInfo: { - page: 'testprebid.com' - }, - params: { - placement: 12345, - user: { - uid: 12345, - buyeruid: 12345 - }, - device: { - ip: '111.222.33.44', - geo: { - country: 'USA' - } - }, - definerId: '44253', - test: 1 - } - }]; - - it('Test the bid validation function', function() { - const validBid = spec.isBidRequestValid(bannerRequest[0]); - const invalidBid = spec.isBidRequestValid(null); - - expect(validBid).to.be.true; - expect(invalidBid).to.be.false; - }); - - it('Test the request processing function', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - expect(request).to.not.be.empty; - - const payload = request.data; - expect(payload).to.not.be.empty; - }); - - const responseBody = { - id: '12345', - seatbid: [ - { - bid: [ - { - id: 'auctionId', - impid: 'impId', - price: 0.0, - adm: 'adMarkup', - crid: 'creativeId', - h: 250, - w: 300 - } - ] - } - ], - cur: 'USD' - }; - - it('Test the response parsing function', function () { - const receivedBid = responseBody.seatbid[0].bid[0]; - const response = {}; - response.body = responseBody; - - const bidResponse = spec.interpretResponse(response, null); - expect(bidResponse).to.not.be.empty; - - const bid = bidResponse[0]; - expect(bid).to.not.be.empty; - expect(bid.ad).to.equal(receivedBid.adm); - expect(bid.cpm).to.equal(receivedBid.price); - expect(bid.height).to.equal(receivedBid.h); - expect(bid.width).to.equal(receivedBid.w); - expect(bid.requestId).to.equal(receivedBid.impid); - }); -}); diff --git a/test/spec/modules/zeta_global_sspAnalyticsAdapter_spec.js b/test/spec/modules/zeta_global_sspAnalyticsAdapter_spec.js deleted file mode 100644 index 6e5508333..000000000 --- a/test/spec/modules/zeta_global_sspAnalyticsAdapter_spec.js +++ /dev/null @@ -1,706 +0,0 @@ -import zetaAnalyticsAdapter from 'modules/zeta_global_sspAnalyticsAdapter.js'; -import {config} from 'src/config'; -import {EVENTS} from 'src/constants.js'; -import {server} from '../../mocks/xhr.js'; -import {logError} from '../../../src/utils.js'; - -const utils = require('src/utils'); -const events = require('src/events'); - -const SAMPLE_EVENTS = { - AUCTION_END: { - 'auctionId': '75e394d9', - 'timestamp': 1638441234544, - 'auctionEnd': 1638441234784, - 'auctionStatus': 'completed', - 'metrics': { - 'someMetric': 1 - }, - 'adUnits': [ - { - 'code': '/19968336/header-bid-tag-0', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'bids': [ - { - 'bidder': 'zeta_global_ssp', - 'params': { - 'sid': 111, - 'tags': { - 'shortname': 'prebid_analytics_event_test_shortname', - 'position': 'test_position' - } - } - }, - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 13232385 - } - } - ], - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'transactionId': '6b29369c' - } - ], - 'adUnitCodes': [ - '/19968336/header-bid-tag-0' - ], - 'bidderRequests': [ - { - 'bidderCode': 'zeta_global_ssp', - 'auctionId': '75e394d9', - 'bidderRequestId': '1207cb49191887', - 'bids': [ - { - 'bidder': 'zeta_global_ssp', - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-0', - 'transactionId': '6b29369c', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '206be9a13236af', - 'bidderRequestId': '1207cb49191887', - 'auctionId': '75e394d9', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'device': { - 'mobile': 1 - } - } - } - ], - 'auctionStart': 1638441234544, - 'timeout': 400, - 'refererInfo': { - 'page': 'http://test-zeta-ssp.net:63342/zeta-ssp/ssp/_dev/examples/page_banner.html', - 'domain': 'test-zeta-ssp.net:63342', - 'referer': 'http://test-zeta-ssp.net:63342/zeta-ssp/ssp/_dev/examples/page_banner.html', - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': [ - 'http://test-zeta-ssp.net:63342/zeta-ssp/ssp/_dev/examples/page_banner.html' - ], - 'canonicalUrl': null - }, - 'start': 1638441234547 - }, - { - 'bidderCode': 'appnexus', - 'auctionId': '75e394d9', - 'bidderRequestId': '32b97f0a935422', - 'bids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 13232385 - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-0', - 'transactionId': '6b29369c', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '41badc0e164c758', - 'bidderRequestId': '32b97f0a935422', - 'auctionId': '75e394d9', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'device': { - 'mobile': 1 - } - } - } - ], - 'auctionStart': 1638441234544, - 'timeout': 400, - 'refererInfo': { - 'page': 'http://test-zeta-ssp.net:63342/zeta-ssp/ssp/_dev/examples/page_banner.html', - 'domain': 'test-zeta-ssp.net:63342', - 'referer': 'http://test-zeta-ssp.net:63342/zeta-ssp/ssp/_dev/examples/page_banner.html', - 'reachedTop': true, - 'isAmp': false, - 'numIframes': 0, - 'stack': [ - 'http://test-zeta-ssp.net:63342/zeta-ssp/ssp/_dev/examples/page_banner.html' - ], - 'canonicalUrl': null - }, - 'start': 1638441234550 - } - ], - 'noBids': [ - { - 'bidder': 'appnexus', - 'params': { - 'placementId': 13232385 - }, - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ] - } - }, - 'adUnitCode': '/19968336/header-bid-tag-0', - 'transactionId': '6b29369c', - 'sizes': [ - [ - 300, - 250 - ], - [ - 300, - 600 - ] - ], - 'bidId': '41badc0e164c758', - 'bidderRequestId': '32b97f0a935422', - 'auctionId': '75e394d9', - 'src': 'client', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0 - } - ], - 'bidsReceived': [ - { - 'bidderCode': 'zeta_global_ssp', - 'width': 480, - 'height': 320, - 'statusMessage': 'Bid available', - 'adId': '5759bb3ef7be1e8', - 'requestId': '206be9a13236af', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 2.258302852806723, - 'currency': 'USD', - 'ad': 'test_ad', - 'ttl': 200, - 'creativeId': '456456456', - 'netRevenue': true, - 'meta': { - 'advertiserDomains': [ - 'example.adomain' - ] - }, - 'originalCpm': 2.258302852806723, - 'originalCurrency': 'USD', - 'auctionId': '75e394d9', - 'responseTimestamp': 1638441234670, - 'requestTimestamp': 1638441234547, - 'bidder': 'zeta_global_ssp', - 'adUnitCode': '/19968336/header-bid-tag-0', - 'timeToRespond': 123, - 'pbLg': '2.00', - 'pbMg': '2.20', - 'pbHg': '2.25', - 'pbAg': '2.25', - 'pbDg': '2.25', - 'pbCg': '', - 'size': '480x320', - 'adserverTargeting': { - 'hb_bidder': 'zeta_global_ssp', - 'hb_adid': '5759bb3ef7be1e8', - 'hb_pb': '2.20', - 'hb_size': '480x320', - 'hb_source': 'client', - 'hb_format': 'banner', - 'hb_adomain': 'example.adomain' - } - } - ], - 'winningBids': [], - 'timeout': 400 - }, - AD_RENDER_SUCCEEDED: { - 'doc': { - 'location': { - 'href': 'http://test-zeta-ssp.net:63342/zeta-ssp/ssp/_dev/examples/page_banner.html', - 'protocol': 'http:', - 'host': 'test-zeta-ssp.net', - 'hostname': 'localhost', - 'port': '63342', - 'pathname': '/zeta-ssp/ssp/_dev/examples/page_banner.html', - 'hash': '', - 'origin': 'http://test-zeta-ssp.net:63342', - 'ancestorOrigins': { - '0': 'http://test-zeta-ssp.net:63342' - } - } - }, - 'bid': { - 'bidderCode': 'zeta_global_ssp', - 'width': 480, - 'height': 320, - 'statusMessage': 'Bid available', - 'adId': '5759bb3ef7be1e8', - 'requestId': '206be9a13236af', - 'mediaType': 'banner', - 'source': 'client', - 'cpm': 2.258302852806723, - 'currency': 'USD', - 'ad': 'test_ad', - 'metrics': { - 'someMetric': 0 - }, - 'ttl': 200, - 'creativeId': '456456456', - 'netRevenue': true, - 'meta': { - 'advertiserDomains': [ - 'example.adomain' - ] - }, - 'originalCpm': 2.258302852806723, - 'originalCurrency': 'USD', - 'auctionId': '75e394d9', - 'responseTimestamp': 1638441234670, - 'requestTimestamp': 1638441234547, - 'bidder': 'zeta_global_ssp', - 'adUnitCode': '/19968336/header-bid-tag-0', - 'timeToRespond': 123, - 'size': '480x320', - 'adserverTargeting': { - 'hb_bidder': 'zeta_global_ssp', - 'hb_adid': '5759bb3ef7be1e8', - 'hb_pb': '2.20', - 'hb_size': '480x320', - 'hb_source': 'client', - 'hb_format': 'banner', - 'hb_adomain': 'example.adomain' - }, - 'status': 'rendered', - 'params': [ - { - 'nonZetaParam': 'nonZetaValue' - } - ] - }, - 'adId': '5759bb3ef7be1e8' - }, - BID_TIMEOUT: [ - { - 'bidder': 'zeta_global_ssp', - 'params': [ - { - 'tags': { - 'position': 'top', - 'shortname': 'someShortName', - }, - 'sid': 100 - } - ], - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': 'ad-1', - 'transactionId': '6d2c4757-d34b-4538-b812-c6e638f05eac', - 'adUnitId': '9dc8cbf6-9b2d-48c7-b424-be9ae4be3dfc', - 'sizes': [ - [ - 300, - 250 - ] - ], - 'bidId': '27c8c05823e2f', - 'bidderRequestId': '1e8e895de1708', - 'auctionId': 'fa9ef841-bcb9-401f-96ad-03a94ac64e63', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'site': { - 'domain': 'zetaglobal.com', - 'publisher': { - 'domain': 'zetaglobal.com' - }, - 'page': 'https://zetaglobal.com/page' - }, - 'device': { - 'w': 807, - 'h': 847, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36', - 'language': 'en', - 'sua': { - 'source': 1, - 'platform': { - 'brand': 'macOS' - }, - 'browsers': [ - { - 'brand': 'Google Chrome', - 'version': [ - '123' - ] - }, - { - 'brand': 'Not:A-Brand', - 'version': [ - '8' - ] - }, - { - 'brand': 'Chromium', - 'version': [ - '123' - ] - } - ], - 'mobile': 0 - } - } - }, - 'timeout': 3 - }, - { - 'bidder': 'zeta_global_ssp', - 'params': [ - { - 'tags': { - 'position': 'top', - 'shortname': 'someShortName', - }, - 'sid': 100 - } - ], - 'mediaTypes': { - 'banner': { - 'sizes': [ - [ - 300, - 250 - ] - ] - } - }, - 'adUnitCode': 'ad-2', - 'transactionId': '11eaa59f-221d-4027-a0a8-7841e0ffc4ee', - 'adUnitId': '4397b4bc-6368-40b8-91f1-987a31076886', - 'sizes': [ - [ - 300, - 250 - ] - ], - 'bidId': '31a3b551cbf1ed', - 'bidderRequestId': '1e8e895de1708', - 'auctionId': 'fa9ef841-bcb9-401f-96ad-03a94ac64e63', - 'bidRequestsCount': 1, - 'bidderRequestsCount': 1, - 'bidderWinsCount': 0, - 'ortb2': { - 'site': { - 'domain': 'zetaglobal.com', - 'publisher': { - 'domain': 'zetaglobal.com' - }, - 'page': 'https://zetaglobal.com/page' - }, - 'device': { - 'w': 807, - 'h': 847, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36', - 'language': 'en', - 'sua': { - 'source': 1, - 'platform': { - 'brand': 'macOS' - }, - 'browsers': [ - { - 'brand': 'Google Chrome', - 'version': [ - '123' - ] - }, - { - 'brand': 'Not:A-Brand', - 'version': [ - '8' - ] - }, - { - 'brand': 'Chromium', - 'version': [ - '123' - ] - } - ], - 'mobile': 0 - } - } - }, - 'timeout': 3 - } - ] -} - -describe('Zeta Global SSP Analytics Adapter', function () { - let sandbox; - let requests; - - beforeEach(function () { - sandbox = sinon.createSandbox(); - requests = server.requests; - sandbox.stub(events, 'getEvents').returns([]); - config.setConfig({ pageUrl: 'https://www.config.domain.com/index.html' }) - }); - - afterEach(function () { - sandbox.restore(); - config.resetConfig(); - }); - - it('should require publisherId', function () { - sandbox.stub(utils, 'logError'); - zetaAnalyticsAdapter.enableAnalytics({ - options: {} - }); - expect(utils.logError.called).to.equal(true); - }); - - describe('handle events', function () { - beforeEach(function () { - zetaAnalyticsAdapter.enableAnalytics({ - options: { - sid: 111, - tags: { - position: 'top', - shortname: 'name' - } - } - }); - }); - - afterEach(function () { - zetaAnalyticsAdapter.disableAnalytics(); - }); - - it('Handle events', function () { - this.timeout(3000); - - events.emit(EVENTS.AUCTION_END, SAMPLE_EVENTS.AUCTION_END); - events.emit(EVENTS.AD_RENDER_SUCCEEDED, SAMPLE_EVENTS.AD_RENDER_SUCCEEDED); - events.emit(EVENTS.BID_TIMEOUT, SAMPLE_EVENTS.BID_TIMEOUT); - - expect(requests.length).to.equal(3); - const auctionEnd = JSON.parse(requests[0].requestBody); - expect(auctionEnd).to.be.deep.equal({ - zetaParams: {sid: 111, tags: {position: 'top', shortname: 'name'}}, - bidderRequests: [{ - bidderCode: 'zeta_global_ssp', - domain: 'test-zeta-ssp.net:63342', - page: 'http://test-zeta-ssp.net:63342/zeta-ssp/ssp/_dev/examples/page_banner.html', - bids: [{ - adUnitCode: '/19968336/header-bid-tag-0', - bidId: '206be9a13236af', - auctionId: '75e394d9', - bidder: 'zeta_global_ssp', - mediaType: 'BANNER', - size: '300x250', - device: { - mobile: 1 - } - }] - }, { - bidderCode: 'appnexus', - domain: 'test-zeta-ssp.net:63342', - page: 'http://test-zeta-ssp.net:63342/zeta-ssp/ssp/_dev/examples/page_banner.html', - bids: [{ - adUnitCode: '/19968336/header-bid-tag-0', - bidId: '41badc0e164c758', - auctionId: '75e394d9', - bidder: 'appnexus', - mediaType: 'BANNER', - size: '300x250', - device: { - mobile: 1 - } - }] - }], - bidsReceived: [{ - adUnitCode: '/19968336/header-bid-tag-0', - adId: '5759bb3ef7be1e8', - requestId: '206be9a13236af', - creativeId: '456456456', - bidder: 'zeta_global_ssp', - mediaType: 'banner', - size: '480x320', - adomain: 'example.adomain', - timeToRespond: 123, - cpm: 2.258302852806723 - }] - }); - const auctionSucceeded = JSON.parse(requests[1].requestBody); - expect(auctionSucceeded.zetaParams).to.be.deep.equal({ - sid: 111, - tags: { - position: 'top', - shortname: 'name' - } - }); - expect(auctionSucceeded.domain).to.eql('config.domain.com'); - expect(auctionSucceeded.page).to.eql('https://www.config.domain.com/index.html'); - expect(auctionSucceeded.bid).to.be.deep.equal({ - adUnitCode: '/19968336/header-bid-tag-0', - adId: '5759bb3ef7be1e8', - requestId: '206be9a13236af', - auctionId: '75e394d9', - creativeId: '456456456', - bidder: 'zeta_global_ssp', - mediaType: 'banner', - size: '480x320', - adomain: 'example.adomain', - timeToRespond: 123, - cpm: 2.258302852806723 - }); - expect(auctionSucceeded.device.ua).to.not.be.empty; - - const bidTimeout = JSON.parse(requests[2].requestBody); - expect(bidTimeout.zetaParams).to.be.deep.equal({ - sid: 111, - tags: { - position: 'top', - shortname: 'name' - } - }); - expect(bidTimeout.domain).to.eql('zetaglobal.com'); - expect(bidTimeout.page).to.eql('https://zetaglobal.com/page'); - expect(bidTimeout.timeouts).to.be.deep.equal([{ - 'bidId': '27c8c05823e2f', - 'auctionId': 'fa9ef841-bcb9-401f-96ad-03a94ac64e63', - 'bidder': 'zeta_global_ssp', - 'mediaType': 'BANNER', - 'size': '300x250', - 'timeout': 3, - 'device': { - 'w': 807, - 'h': 847, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36', - 'language': 'en', - 'sua': { - 'source': 1, - 'platform': {'brand': 'macOS'}, - 'browsers': [{'brand': 'Google Chrome', 'version': ['123']}, { - 'brand': 'Not:A-Brand', - 'version': ['8'] - }, {'brand': 'Chromium', 'version': ['123']}], - 'mobile': 0 - } - }, - 'adUnitCode': 'ad-1' - }, { - 'bidId': '31a3b551cbf1ed', - 'auctionId': 'fa9ef841-bcb9-401f-96ad-03a94ac64e63', - 'bidder': 'zeta_global_ssp', - 'mediaType': 'BANNER', - 'size': '300x250', - 'timeout': 3, - 'device': { - 'w': 807, - 'h': 847, - 'dnt': 0, - 'ua': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/123.0.0.0 Safari/537.36', - 'language': 'en', - 'sua': { - 'source': 1, - 'platform': {'brand': 'macOS'}, - 'browsers': [{'brand': 'Google Chrome', 'version': ['123']}, { - 'brand': 'Not:A-Brand', - 'version': ['8'] - }, {'brand': 'Chromium', 'version': ['123']}], - 'mobile': 0 - } - }, - 'adUnitCode': 'ad-2' - }]); - }); - }); -}); diff --git a/test/spec/modules/zeta_global_sspBidAdapter_spec.js b/test/spec/modules/zeta_global_sspBidAdapter_spec.js deleted file mode 100644 index 31e6a173a..000000000 --- a/test/spec/modules/zeta_global_sspBidAdapter_spec.js +++ /dev/null @@ -1,877 +0,0 @@ -import {spec} from '../../../modules/zeta_global_sspBidAdapter.js' -import {BANNER, VIDEO} from '../../../src/mediaTypes.js'; -import {deepClone} from '../../../src/utils.js'; -import {expect} from 'chai'; - -describe('Zeta Ssp Bid Adapter', function () { - const eids = [ - { - 'source': 'example.com', - 'uids': [ - { - 'id': 'someId1', - 'atype': 1 - }, - { - 'id': 'someId2', - 'atype': 1 - }, - { - 'id': 'someId3', - 'atype': 2 - } - ], - 'ext': { - 'foo': 'bar' - } - } - ]; - - const schain = { - complete: 1, - nodes: [ - { - asi: 'asi1', - sid: 'sid1', - rid: 'rid1' - }, - { - asi: 'asi2', - sid: 'sid2', - rid: 'rid2' - } - ] - }; - - const params = { - user: { - uid: 222, - buyeruid: 333 - }, - tags: { - someTag: 444, - emptyTag: {}, - nullTag: null, - complexEmptyTag: { - empty: {}, - nullValue: null - } - }, - sid: 'publisherId', - tagid: 'test_tag_id', - site: { - page: 'http://www.zetaglobal.com/page?param=value' - }, - app: { - bundle: 'testBundle' - }, - bidfloor: 0.2, - test: 1 - }; - - const multiImpRequest = [ - { - bidId: 12345, - auctionId: 67890, - mediaTypes: { - banner: { - sizes: [[300, 250]], - } - }, - refererInfo: { - page: 'http://www.zetaglobal.com/page?param=value', - domain: 'www.zetaglobal.com', - }, - gdprConsent: { - gdprApplies: 1, - consentString: 'consentString' - }, - uspConsent: 'someCCPAString', - params: params, - userIdAsEids: eids - }, { - bidId: 54321, - auctionId: 67890, - mediaTypes: { - banner: { - sizes: [[600, 400]], - } - }, - refererInfo: { - page: 'http://www.zetaglobal.com/page?param=value', - domain: 'www.zetaglobal.com', - }, - gdprConsent: { - gdprApplies: 1, - consentString: 'consentString' - }, - uspConsent: 'someCCPAString', - params: params, - userIdAsEids: eids - } - ]; - - const bannerRequest = [{ - bidId: 12345, - auctionId: 67890, - mediaTypes: { - banner: { - sizes: [[300, 250]], - } - }, - refererInfo: { - page: 'http://www.zetaglobal.com/page?param=value', - domain: 'www.zetaglobal.com', - }, - gdprConsent: { - gdprApplies: 1, - consentString: 'consentString' - }, - uspConsent: 'someCCPAString', - params: params, - userIdAsEids: eids, - timeout: 500, - ortb2: { - source: { - ext: { - schain: schain - } - }, - bcat: ['CAT1'], - badv: ['test1.com'], - site: { - inventorypartnerdomain: 'disqus.com' - }, - device: { - sua: { - mobile: 1, - architecture: 'arm', - platform: { - brand: 'Chrome', - version: ['102'] - } - } - }, - user: { - data: [ - { - ext: { - segtax: 600, - segclass: 'classifier_v1' - }, - segment: [ - { id: '3' }, - { id: '44' }, - { id: '59' } - ] - } - ], - geo: { - lat: 40.0, - lon: -80.0, - type: 2, - country: 'USA', - region: 'NY', - metro: '501', - city: 'New York', - zip: '10001', - } - } - } - }]; - - const bannerWithFewSizesRequest = [{ - bidId: 12345, - auctionId: 67890, - mediaTypes: { - banner: { - sizes: [[300, 250], [200, 240], [100, 150]], - } - }, - refererInfo: { - page: 'http://www.zetaglobal.com/page?param=value', - domain: 'www.zetaglobal.com', - }, - gdprConsent: { - gdprApplies: 1, - consentString: 'consentString' - }, - ortb2: { - source: { - ext: { - schain: schain - } - } - }, - uspConsent: 'someCCPAString', - params: params, - userIdAsEids: eids, - timeout: 500 - }]; - - const videoRequest = [{ - bidId: 112233, - auctionId: 667788, - mediaTypes: { - video: { - context: 'instream', - playerSize: [[720, 340]], - mimes: ['video/mp4'], - minduration: 5, - maxduration: 30, - placement: 2, - plcmt: 1, - protocols: [2, 3] - } - }, - refererInfo: { - referer: 'http://www.zetaglobal.com/page?param=video' - }, - params: params - }]; - - const zetaResponse = { - body: { - id: '12345', - seatbid: [ - { - seat: '1', - bid: [ - { - id: 'auctionId', - impid: 'impId', - price: 0.0, - adm: 'adMarkup', - crid: 'creativeId', - adomain: [ - 'https://example.com' - ], - h: 250, - w: 300 - } - ] - } - ], - cur: 'USD' - } - } - - const responseBannerPayload = { - data: { - id: '123', - site: { - id: 'SITE_ID', - page: 'http://www.zetaglobal.com/page?param=value', - domain: 'domain.com' - }, - user: { - id: '45asdf9tydhrty789adfad4678rew656789', - buyeruid: '1234567890' - }, - cur: [ - 'USD' - ], - imp: [ - { - id: '1', - banner: { - h: 600, - w: 160 - } - } - ], - at: 1 - } - }; - - const responseVideoPayload = { - data: { - id: '123', - site: { - id: 'SITE_ID', - page: 'http://www.zetaglobal.com/page?param=value', - domain: 'domain.com' - }, - user: { - id: '45asdf9tydhrty789adfad4678rew656789', - buyeruid: '1234567890' - }, - cur: [ - 'USD' - ], - imp: [ - { - id: '1', - video: { - h: 600, - w: 160 - } - } - ], - at: 1 - } - }; - - it('Test the bid validation function', function () { - const invalidBid = deepClone(bannerRequest[0]); - invalidBid.params = {}; - const isValidBid = spec.isBidRequestValid(bannerRequest[0]); - const isInvalidBid = spec.isBidRequestValid(null); - - expect(isValidBid).to.be.true; - expect(isInvalidBid).to.be.false; - }); - - it('Test provide eids', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - expect(payload.user.ext.eids).to.eql(eids); - }); - - it('Test contains ua and language', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - expect(payload.device.ua).to.not.be.empty; - expect(payload.device.language).to.not.be.empty; - }); - - it('Test page and domain in site', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - expect(payload.site.page).to.eql('zetaglobal.com/page'); - expect(payload.site.domain).to.eql('zetaglobal.com'); - }); - - it('Test the request processing function', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - expect(request).to.not.be.empty; - - const payload = request.data; - expect(payload).to.not.be.empty; - }); - - it('Test the response parsing function', function () { - const response = { - body: { - id: '12345', - seatbid: [ - { - bid: [ - { - id: 'auctionId', - impid: 'impId', - price: 0.0, - adm: 'adMarkup', - crid: 'creativeId', - adomain: [ - 'https://example.com' - ], - h: 250, - w: 300, - ext: { - prebid: { - type: 'banner' - } - } - }, - { - id: 'auctionId2', - impid: 'impId2', - price: 0.1, - adm: 'adMarkup2', - crid: 'creativeId2', - adomain: [ - 'https://example2.com' - ], - h: 150, - w: 200, - ext: { - prebid: { - type: 'video' - } - } - }, - { - id: 'auctionId3', - impid: 'impId3', - price: 0.2, - adm: '', - crid: 'creativeId3', - adomain: [ - 'https://example3.com' - ], - h: 400, - w: 300, - ext: { - prebid: { - type: 'video' - } - } - } - ] - } - ], - cur: 'USD' - } - }; - - const bidResponse = spec.interpretResponse(response, responseBannerPayload); - expect(bidResponse).to.not.be.empty; - - const bid1 = bidResponse[0]; - const receivedBid1 = response.body.seatbid[0].bid[0]; - expect(bid1).to.not.be.empty; - expect(bid1.ad).to.equal(receivedBid1.adm); - expect(bid1.vastXml).to.be.undefined; - expect(bid1.mediaType).to.equal(BANNER); - expect(bid1.cpm).to.equal(receivedBid1.price); - expect(bid1.height).to.equal(receivedBid1.h); - expect(bid1.width).to.equal(receivedBid1.w); - expect(bid1.requestId).to.equal(receivedBid1.impid); - expect(bid1.meta.advertiserDomains).to.equal(receivedBid1.adomain); - - const bid2 = bidResponse[1]; - const receivedBid2 = response.body.seatbid[0].bid[1]; - expect(bid2).to.not.be.empty; - expect(bid2.ad).to.equal(receivedBid2.adm); - expect(bid2.vastXml).to.equal(receivedBid2.adm); - expect(bid2.mediaType).to.equal(VIDEO); - expect(bid2.cpm).to.equal(receivedBid2.price); - expect(bid2.height).to.equal(receivedBid2.h); - expect(bid2.width).to.equal(receivedBid2.w); - expect(bid2.requestId).to.equal(receivedBid2.impid); - expect(bid2.meta.advertiserDomains).to.equal(receivedBid2.adomain); - - const bid3 = bidResponse[2]; - const receivedBid3 = response.body.seatbid[0].bid[2]; - expect(bid3).to.not.be.empty; - expect(bid3.ad).to.equal(receivedBid3.adm); - expect(bid3.vastXml).to.equal(receivedBid3.adm); - expect(bid3.mediaType).to.equal(VIDEO); - expect(bid3.cpm).to.equal(receivedBid3.price); - expect(bid3.height).to.equal(receivedBid3.h); - expect(bid3.width).to.equal(receivedBid3.w); - expect(bid3.requestId).to.equal(receivedBid3.impid); - expect(bid3.meta.advertiserDomains).to.equal(receivedBid3.adomain); - }); - - describe('getUserSyncs', function() { - const USER_SYNC_URL_IFRAME = 'https://ssp.disqus.com/sync?type=iframe'; - const USER_SYNC_URL_IMAGE = 'https://ssp.disqus.com/sync?type=image'; - - it('execute as per config', function() { - expect(spec.getUserSyncs({iframeEnabled: true})).to.deep.equal([{ - type: 'iframe', url: `${USER_SYNC_URL_IFRAME}` - }]); - expect(spec.getUserSyncs({iframeEnabled: false})).to.deep.equal([{ - type: 'image', url: `${USER_SYNC_URL_IMAGE}` - }]); - }); - - it('GDPR', function() { - expect(spec.getUserSyncs({iframeEnabled: true}, {}, {gdprApplies: true, consentString: 'foo'})).to.deep.equal([{ - type: 'iframe', url: `${USER_SYNC_URL_IFRAME}&gdpr=1&gdpr_consent=foo` - }]); - expect(spec.getUserSyncs({iframeEnabled: true}, {}, {gdprApplies: false, consentString: 'foo'})).to.deep.equal([{ - type: 'iframe', url: `${USER_SYNC_URL_IFRAME}&gdpr=0&gdpr_consent=foo` - }]); - expect(spec.getUserSyncs({iframeEnabled: true}, {}, {gdprApplies: true, consentString: undefined})).to.deep.equal([{ - type: 'iframe', url: `${USER_SYNC_URL_IFRAME}&gdpr=1&gdpr_consent=` - }]); - expect(spec.getUserSyncs({iframeEnabled: false}, {}, {gdprApplies: true, consentString: 'foo'})).to.deep.equal([{ - type: 'image', url: `${USER_SYNC_URL_IMAGE}&gdpr=1&gdpr_consent=foo` - }]); - expect(spec.getUserSyncs({iframeEnabled: false}, {}, {gdprApplies: false, consentString: 'foo'})).to.deep.equal([{ - type: 'image', url: `${USER_SYNC_URL_IMAGE}&gdpr=0&gdpr_consent=foo` - }]); - expect(spec.getUserSyncs({iframeEnabled: false}, {}, {gdprApplies: true, consentString: undefined})).to.deep.equal([{ - type: 'image', url: `${USER_SYNC_URL_IMAGE}&gdpr=1&gdpr_consent=` - }]); - }); - - it('CCPA', function() { - expect(spec.getUserSyncs({ iframeEnabled: true }, {}, undefined, '1NYN')).to.deep.equal([{ - type: 'iframe', url: `${USER_SYNC_URL_IFRAME}&us_privacy=1NYN` - }]); - expect(spec.getUserSyncs({ iframeEnabled: false }, {}, undefined, '1NYN')).to.deep.equal([{ - type: 'image', url: `${USER_SYNC_URL_IMAGE}&us_privacy=1NYN` - }]); - }); - - describe('GPP', function() { - it('should return userSync url without GPP consent if gppConsent is undefined', () => { - const result = spec.getUserSyncs({iframeEnabled: true}, undefined, undefined, undefined, undefined); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${USER_SYNC_URL_IFRAME}` - }]); - }); - - it('should return userSync url without GPP consent if gppConsent.gppString is undefined', () => { - const gppConsent = { applicableSections: ['5'] }; - const result = spec.getUserSyncs({iframeEnabled: true}, undefined, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${USER_SYNC_URL_IFRAME}` - }]); - }); - - it('should return userSync url without GPP consent if gppConsent.applicableSections is undefined', () => { - const gppConsent = { gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN' }; - const result = spec.getUserSyncs({iframeEnabled: true}, undefined, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${USER_SYNC_URL_IFRAME}` - }]); - }); - - it('should return userSync url without GPP consent if gppConsent.applicableSections is an empty array', () => { - const gppConsent = { gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', applicableSections: [] }; - const result = spec.getUserSyncs({iframeEnabled: true}, undefined, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${USER_SYNC_URL_IFRAME}` - }]); - }); - - it('should concatenate gppString and applicableSections values in the returned userSync iframe url', () => { - const gppConsent = { gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', applicableSections: [5] }; - const result = spec.getUserSyncs({iframeEnabled: true}, undefined, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'iframe', url: `${USER_SYNC_URL_IFRAME}&gpp=${encodeURIComponent(gppConsent.gppString)}&gpp_sid=${encodeURIComponent(gppConsent.applicableSections)}` - }]); - }); - - it('should concatenate gppString and applicableSections values in the returned userSync image url', () => { - const gppConsent = { gppString: 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', applicableSections: [5] }; - const result = spec.getUserSyncs({iframeEnabled: false}, undefined, undefined, undefined, gppConsent); - expect(result).to.deep.equal([{ - type: 'image', url: `${USER_SYNC_URL_IMAGE}&gpp=${encodeURIComponent(gppConsent.gppString)}&gpp_sid=${encodeURIComponent(gppConsent.applicableSections)}` - }]); - }); - }); - }); - - it('Test provide gdpr and ccpa values in payload', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - - expect(payload.user.ext.consent).to.eql('consentString'); - expect(payload.regs.ext.gdpr).to.eql(1); - expect(payload.regs.ext.us_privacy).to.eql('someCCPAString'); - }); - - describe('buildRequests: GPP', function() { - it('Request params check with GPP Consent', function () { - const bidRequest = { - gppConsent: { - 'gppString': 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', - 'fullGppData': { - 'sectionId': 3, - 'gppVersion': 1, - 'sectionList': [ - 5, - 7 - ], - 'applicableSections': [ - 5 - ], - 'gppString': 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', - 'pingData': { - 'cmpStatus': 'loaded', - 'gppVersion': '1.0', - 'cmpDisplayStatus': 'visible', - 'supportedAPIs': [ - 'tcfca', - 'usnat', - 'usca', - 'usva', - 'usco', - 'usut', - 'usct' - ], - 'cmpId': 31 - }, - 'eventName': 'sectionChange' - }, - 'applicableSections': [ - 5 - ], - 'apiVersion': 1 - } - }; - const request = spec.buildRequests(bannerRequest, bidRequest); - const data = JSON.parse(request.data); - expect(data.regs.gpp).to.equal('DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN'); - expect(data.regs.gpp_sid[0]).to.equal(5); - }); - - it('Request params check without GPP Consent', function () { - const bidRequest = {}; - const request = spec.buildRequests(bannerRequest, bidRequest); - const data = JSON.parse(request.data); - expect(data.regs).to.equal(undefined); - }); - - it('Request params check with GPP Consent read from ortb2', function () { - const bidRequest = { - ortb2: { - regs: { - 'gpp': 'DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN', - 'gpp_sid': [ - 5 - ] - } - } - }; - const request = spec.buildRequests(bannerRequest, bidRequest); - const data = JSON.parse(request.data); - expect(data.regs.gpp).to.equal('DBACNYA~CPXxRfAPXxRfAAfKABENB-CgAAAAAAAAAAYgAAAAAAAA~1YNN'); - expect(data.regs.gpp_sid[0]).to.equal(5); - }); - }); - - it('Test do not override user object', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - expect(payload.user.uid).to.eql(222); - expect(payload.user.buyeruid).to.eql(333); - expect(payload.user.ext.consent).to.eql('consentString'); - }); - - it('Test video object', function () { - const request = spec.buildRequests(videoRequest, videoRequest[0]); - const payload = JSON.parse(request.data); - - expect(payload.imp[0].video.minduration).to.eql(videoRequest[0].mediaTypes.video.minduration); - expect(payload.imp[0].video.maxduration).to.eql(videoRequest[0].mediaTypes.video.maxduration); - expect(payload.imp[0].video.protocols).to.eql(videoRequest[0].mediaTypes.video.protocols); - expect(payload.imp[0].video.mimes).to.eql(videoRequest[0].mediaTypes.video.mimes); - expect(payload.imp[0].video.w).to.eql(720); - expect(payload.imp[0].video.h).to.eql(340); - expect(payload.imp[0].video.placement).to.eql(videoRequest[0].mediaTypes.video.placement); - expect(payload.imp[0].video.plcmt).to.eql(videoRequest[0].mediaTypes.video.plcmt); - - expect(payload.imp[0].banner).to.be.undefined; - }); - - it('Test required params in banner request', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - expect(request.url).to.eql('https://ssp.disqus.com/bid/prebid?sid=publisherId'); - expect(payload.ext.sid).to.eql('publisherId'); - expect(payload.ext.tags.someTag).to.eql(444); - expect(payload.ext.tags.shortname).to.be.undefined; - }); - - it('Test required params in video request', function () { - const request = spec.buildRequests(videoRequest, videoRequest[0]); - const payload = JSON.parse(request.data); - expect(request.url).to.eql('https://ssp.disqus.com/bid/prebid?sid=publisherId'); - expect(payload.ext.sid).to.eql('publisherId'); - expect(payload.ext.tags.someTag).to.eql(444); - expect(payload.ext.tags.shortname).to.be.undefined; - }); - - it('Test multi imp', function () { - const request = spec.buildRequests(multiImpRequest, multiImpRequest[0]); - const payload = JSON.parse(request.data); - expect(request.url).to.eql('https://ssp.disqus.com/bid/prebid?sid=publisherId'); - - expect(payload.imp.length).to.eql(2); - - expect(payload.imp[0].id).to.eql(12345); - expect(payload.imp[1].id).to.eql(54321); - - expect(payload.imp[0].banner.w).to.eql(300); - expect(payload.imp[0].banner.h).to.eql(250); - - expect(payload.imp[1].banner.w).to.eql(600); - expect(payload.imp[1].banner.h).to.eql(400); - }); - - it('Test provide tmax', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - - expect(payload.tmax).to.eql(500); - }); - - it('Test provide tmax without value', function () { - const request = spec.buildRequests(videoRequest, videoRequest[0]); - const payload = JSON.parse(request.data); - - expect(payload.tmax).to.be.undefined; - }); - - it('Test provide bidfloor', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - - expect(payload.imp[0].bidfloor).to.eql(params.bidfloor); - }); - - it('Test schain provided', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - - expect(payload.source.ext.schain).to.eql(schain); - }); - - it('Test tagid provided', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - - expect(payload.imp[0].tagid).to.eql(params.tagid); - }); - - it('Test if only one size', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - - // banner - expect(payload.imp[0].banner.w).to.eql(300); - expect(payload.imp[0].banner.h).to.eql(250); - - expect(payload.imp[0].banner.format).to.be.undefined; - }); - - it('Test few sizes provided in format', function () { - const request = spec.buildRequests(bannerWithFewSizesRequest, bannerWithFewSizesRequest[0]); - const payload = JSON.parse(request.data); - - // banner - expect(payload.imp[0].banner.w).to.eql(300); - expect(payload.imp[0].banner.h).to.eql(250); - - expect(payload.imp[0].banner.format.length).to.eql(3); - - // format[0] - expect(payload.imp[0].banner.format[0].w).to.eql(300); - expect(payload.imp[0].banner.format[0].h).to.eql(250); - - // format[1] - expect(payload.imp[0].banner.format[1].w).to.eql(200); - expect(payload.imp[0].banner.format[1].h).to.eql(240); - - // format[2] - expect(payload.imp[0].banner.format[2].w).to.eql(100); - expect(payload.imp[0].banner.format[2].h).to.eql(150); - }); - - it('Test the response default mediaType:banner', function () { - const bidResponse = spec.interpretResponse(zetaResponse, responseBannerPayload); - expect(bidResponse).to.not.be.empty; - expect(bidResponse.length).to.eql(1); - expect(bidResponse[0].mediaType).to.eql(BANNER); - expect(bidResponse[0].ad).to.eql(zetaResponse.body.seatbid[0].bid[0].adm); - expect(bidResponse[0].vastXml).to.be.undefined; - expect(bidResponse[0].dspId).to.eql(zetaResponse.body.seatbid[0].seat); - }); - - it('Test the response default mediaType:video', function () { - const bidResponse = spec.interpretResponse(zetaResponse, responseVideoPayload); - expect(bidResponse).to.not.be.empty; - expect(bidResponse.length).to.eql(1); - expect(bidResponse[0].mediaType).to.eql(VIDEO); - expect(bidResponse[0].ad).to.eql(zetaResponse.body.seatbid[0].bid[0].adm); - expect(bidResponse[0].vastXml).to.eql(zetaResponse.body.seatbid[0].bid[0].adm); - expect(bidResponse[0].dspId).to.eql(zetaResponse.body.seatbid[0].seat); - }); - - it('Test the response mediaType:video from ext param', function () { - zetaResponse.body.seatbid[0].bid[0].ext = { - prebid: { - type: 'video' - } - } - const bidResponse = spec.interpretResponse(zetaResponse, responseBannerPayload); - expect(bidResponse).to.not.be.empty; - expect(bidResponse.length).to.eql(1); - expect(bidResponse[0].mediaType).to.eql(VIDEO); - expect(bidResponse[0].ad).to.eql(zetaResponse.body.seatbid[0].bid[0].adm); - expect(bidResponse[0].vastXml).to.eql(zetaResponse.body.seatbid[0].bid[0].adm); - expect(bidResponse[0].dspId).to.eql(zetaResponse.body.seatbid[0].seat); - }); - - it('Test the response mediaType:banner from ext param', function () { - zetaResponse.body.seatbid[0].bid[0].ext = { - prebid: { - type: 'banner' - } - } - const bidResponse = spec.interpretResponse(zetaResponse, responseVideoPayload); - expect(bidResponse).to.not.be.empty; - expect(bidResponse.length).to.eql(1); - expect(bidResponse[0].mediaType).to.eql(BANNER); - expect(bidResponse[0].ad).to.eql(zetaResponse.body.seatbid[0].bid[0].adm); - expect(bidResponse[0].vastXml).to.be.undefined; - expect(bidResponse[0].dspId).to.eql(zetaResponse.body.seatbid[0].seat); - }); - - it('Test provide segments into the request', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - expect(payload.user.data[0].segment.length).to.eql(3); - expect(payload.user.data[0].segment[0].id).to.eql('3'); - expect(payload.user.data[0].segment[1].id).to.eql('44'); - expect(payload.user.data[0].segment[2].id).to.eql('59'); - }); - - it('Test provide device params', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - - expect(payload.device.sua.mobile).to.eql(1); - expect(payload.device.sua.architecture).to.eql('arm'); - expect(payload.device.sua.platform.brand).to.eql('Chrome'); - expect(payload.device.sua.platform.version[0]).to.eql('102'); - - // expecting the same values for user.geo and device.geo - expect(payload.device.geo.type).to.eql(2); - expect(payload.device.geo.lat).to.eql(40.0); - expect(payload.device.geo.lon).to.eql(-80.0); - expect(payload.device.geo.country).to.eql('USA'); - expect(payload.device.geo.region).to.eql('NY'); - expect(payload.device.geo.metro).to.eql('501'); - expect(payload.device.geo.city).to.eql('New York'); - expect(payload.device.geo.zip).to.eql('10001'); - - expect(payload.device.ua).to.not.be.undefined; - expect(payload.device.language).to.not.be.undefined; - expect(payload.device.w).to.not.be.undefined; - expect(payload.device.h).to.not.be.undefined; - }); - - it('Test provide user params', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - - // expecting the same values for user.geo and device.geo - expect(payload.user.geo.type).to.eql(2); - expect(payload.user.geo.lat).to.eql(40.0); - expect(payload.user.geo.lon).to.eql(-80.0); - expect(payload.user.geo.country).to.eql('USA'); - expect(payload.user.geo.region).to.eql('NY'); - expect(payload.user.geo.metro).to.eql('501'); - expect(payload.user.geo.city).to.eql('New York'); - expect(payload.user.geo.zip).to.eql('10001'); - }); - - it('Test that all empties are removed', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - - expect(payload.ext.tags.someTag).to.eql(444); - - expect(payload.ext.tags.emptyTag).to.be.undefined; - expect(payload.ext.tags.nullTag).to.be.undefined; - expect(payload.ext.tags.complexEmptyTag).to.be.undefined; - }); - - it('Test that site payload param are merged from ortb2 and params', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - - expect(payload.site.page).to.eql('zetaglobal.com/page'); - expect(payload.site.inventorypartnerdomain).to.eql('disqus.com'); - expect(payload.bcat).to.eql(['CAT1']); - expect(payload.badv).to.eql(['test1.com']); - }); -}); diff --git a/test/spec/modules/zmaticooBidAdapter_spec.js b/test/spec/modules/zmaticooBidAdapter_spec.js deleted file mode 100644 index 6561301c8..000000000 --- a/test/spec/modules/zmaticooBidAdapter_spec.js +++ /dev/null @@ -1,266 +0,0 @@ -import {checkParamDataType, spec} from '../../../modules/zmaticooBidAdapter.js' -import utils, {deepClone} from '../../../src/utils.js'; -import {expect} from 'chai'; - -describe('zMaticoo Bidder Adapter', function () { - const bannerRequest = [{ - auctionId: '223', - mediaTypes: { - banner: { - sizes: [[320, 50]], - } - }, - refererInfo: { - page: 'testprebid.com' - }, - params: { - user: { - uid: '12345', - buyeruid: '12345' - }, - pubId: 'prebid-test', - test: 1, - bidfloor: 1, - tagid: 'test' - } - }]; - const bannerRequest1 = [{ - auctionId: '223', - mediaTypes: { - banner: { - sizes: [[320, 50]], - } - }, - refererInfo: { - page: 'testprebid.com' - }, - params: { - user: { - uid: '12345', - buyeruid: '12345' - }, - pubId: 'prebid-test', - test: 1, - tagid: 'test' - }, - gdprConsent: { - gdprApplies: 1, - consentString: 'consentString' - }, - getFloor: function () { - return { - currency: 'USD', - floor: 0.5, - } - }, - }]; - const videoRequest = [{ - auctionId: '223', - mediaTypes: { - video: { - playerSize: [480, 320], - mimes: ['video/mp4'], - context: 'instream', - placement: 1, - maxduration: 30, - minduration: 15, - pos: 1, - startdelay: 10, - protocols: [2, 3], - api: [2, 3], - playbackmethod: [2, 6], - skip: 10, - } - }, - refererInfo: { - page: 'testprebid.com' - }, - params: { - user: { - uid: '12345', - buyeruid: '12345' - }, - pubId: 'prebid-test', - test: 1, - tagid: 'test', - bidfloor: 1 - } - }]; - - const videoRequest1 = [{ - auctionId: '223', - mediaTypes: { - video: { - playerSize: [[480, 320]], - mimes: ['video/mp4'], - context: 'instream', - placement: 1, - maxduration: 30, - minduration: 15, - pos: 1, - startdelay: 10, - protocols: [2, 3], - api: [2, 3], - playbackmethod: [2, 6], - skip: 10, - } - }, - params: { - user: { - uid: '12345', - buyeruid: '12345' - }, - pubId: 'prebid-test', - test: 1, - tagid: 'test', - bidfloor: 1 - } - }]; - - describe('isBidRequestValid', function () { - it('this is valid bidrequest', function () { - const validBid = spec.isBidRequestValid(videoRequest[0]); - expect(validBid).to.be.true; - }); - it('missing required bid data {bid}', function () { - const invalidBid = spec.isBidRequestValid(null); - expect(invalidBid).to.be.false; - }); - it('missing required params.pubId', function () { - const request = deepClone(videoRequest[0]) - delete request.params.pubId - const invalidBid = spec.isBidRequestValid(request); - expect(invalidBid).to.be.false; - }); - }) - describe('buildRequests', function () { - it('Test the banner request processing function', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - expect(request).to.not.be.empty; - const payload = request.data; - expect(payload).to.not.be.empty; - }); - it('Test the video request processing function', function () { - const request = spec.buildRequests(videoRequest, videoRequest[0]); - expect(request).to.not.be.empty; - const payload = request.data; - expect(payload).to.not.be.empty; - }); - it('Test the param', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - expect(payload.imp[0].tagid).to.eql(videoRequest[0].params.tagid); - expect(payload.imp[0].bidfloor).to.eql(videoRequest[0].params.bidfloor); - }); - it('Test video object', function () { - const request = spec.buildRequests(videoRequest, videoRequest[0]); - const payload = JSON.parse(request.data); - expect(payload.imp[0].video).to.exist; - expect(payload.imp[0].video.minduration).to.eql(videoRequest[0].mediaTypes.video.minduration); - expect(payload.imp[0].video.maxduration).to.eql(videoRequest[0].mediaTypes.video.maxduration); - expect(payload.imp[0].video.protocols).to.eql(videoRequest[0].mediaTypes.video.protocols); - expect(payload.imp[0].video.mimes).to.eql(videoRequest[0].mediaTypes.video.mimes); - expect(payload.imp[0].video.w).to.eql(480); - expect(payload.imp[0].video.h).to.eql(320); - expect(payload.imp[0].banner).to.be.undefined; - }); - - it('Test video isArray size', function () { - const request = spec.buildRequests(videoRequest1, videoRequest1[0]); - const payload = JSON.parse(request.data); - expect(payload.imp[0].video.w).to.eql(480); - expect(payload.imp[0].video.h).to.eql(320); - }); - it('Test banner object', function () { - const request = spec.buildRequests(bannerRequest, bannerRequest[0]); - const payload = JSON.parse(request.data); - expect(payload.imp[0].video).to.be.undefined; - expect(payload.imp[0].banner).to.exist; - }); - - it('Test provide gdpr and ccpa values in payload', function () { - const request = spec.buildRequests(bannerRequest1, bannerRequest1[0]); - const payload = JSON.parse(request.data); - expect(payload.user.ext.consent).to.eql('consentString'); - expect(payload.regs.ext.gdpr).to.eql(1); - }); - - it('Test bidfloor is function', function () { - const request = spec.buildRequests(bannerRequest1, bannerRequest1[0]); - const payload = JSON.parse(request.data); - expect(payload.imp[0].bidfloor).to.eql(0.5); - }); - }); - describe('checkParamDataType tests', function () { - it('return the expected datatypes', function () { - assert.isString(checkParamDataType('Right string', 'test', 'string')); - assert.isBoolean(checkParamDataType('Right bool', true, 'boolean')); - assert.isNumber(checkParamDataType('Right number', 10, 'number')); - assert.isArray(checkParamDataType('Right array', [10, 11], 'array')); - }); - - it('return undefined var for wrong datatypes', function () { - expect(checkParamDataType('Wrong string', 10, 'string')).to.be.undefined; - expect(checkParamDataType('Wrong bool', 10, 'boolean')).to.be.undefined; - expect(checkParamDataType('Wrong number', 'one', 'number')).to.be.undefined; - expect(checkParamDataType('Wrong array', false, 'array')).to.be.undefined; - }); - }) - describe('interpretResponse', function () { - const responseBody = { - id: '12345', - seatbid: [ - { - bid: [ - { - id: 'auctionId', - impid: 'impId', - price: 0.0, - adm: 'adMarkup', - crid: 'creativeId', - adomain: ['test.com'], - h: 50, - w: 320, - nurl: 'https://gwbudgetali.iymedia.me/budget.php', - ext: { - vast_url: '', - prebid: { - type: 'banner' - } - } - } - ] - } - ], - cur: 'USD' - }; - it('Test the response parsing function', function () { - const receivedBid = responseBody.seatbid[0].bid[0]; - const response = {}; - response.body = responseBody; - const bidResponse = spec.interpretResponse(response, null); - expect(bidResponse).to.not.be.empty; - const bid = bidResponse[0]; - expect(bid).to.not.be.empty; - expect(bid.ad).to.equal(receivedBid.adm); - expect(bid.cpm).to.equal(receivedBid.price); - expect(bid.height).to.equal(receivedBid.h); - expect(bid.width).to.equal(receivedBid.w); - expect(bid.requestId).to.equal(receivedBid.impid); - expect(bid.vastXml).to.equal(receivedBid.ext.vast_url); - expect(bid.meta.advertiserDomains).to.equal(receivedBid.adomain); - expect(bid.mediaType).to.equal(receivedBid.ext.prebid.type); - expect(bid.nurl).to.equal(receivedBid.nurl); - }); - }); - describe('onBidWon', function () { - it('should make an ajax call with the original cpm', function () { - const bid = { - nurl: 'http://test.com/win?auctionPrice=${AUCTION_PRICE}', - cpm: 2.1, - } - const bidWonResult = spec.onBidWon(bid) - expect(bidWonResult).to.equal(true) - }); - }) -}); From df9595323731b6353686773da0449187b022e6bc Mon Sep 17 00:00:00 2001 From: Khang Vu Date: Fri, 6 Mar 2026 00:31:23 -0800 Subject: [PATCH 02/15] unneeded workflow and fix --- .github/workflows/code-path-changes.yml | 37 ------------------------- .github/workflows/jscpd.yml | 2 +- 2 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 .github/workflows/code-path-changes.yml diff --git a/.github/workflows/code-path-changes.yml b/.github/workflows/code-path-changes.yml deleted file mode 100644 index 5927aae1a..000000000 --- a/.github/workflows/code-path-changes.yml +++ /dev/null @@ -1,37 +0,0 @@ -name: Notify Code Path Changes - -on: - pull_request_target: - types: [opened, synchronize] - paths: - - '**' - -env: - OAUTH2_CLIENT_ID: ${{ secrets.OAUTH2_CLIENT_ID }} - OAUTH2_CLIENT_SECRET: ${{ secrets.OAUTH2_CLIENT_SECRET }} - OAUTH2_REFRESH_TOKEN: ${{ secrets.OAUTH2_REFRESH_TOKEN }} - GITHUB_REPOSITORY: ${{ github.repository }} - GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - -permissions: - contents: read - -jobs: - notify: - runs-on: ubuntu-latest - steps: - - name: Checkout Code - uses: actions/checkout@v5 - - - name: Set up Node.js - uses: actions/setup-node@v5 - with: - node-version: '18' - - - name: Install dependencies - run: npm install axios nodemailer - - - name: Run Notification Script - run: | - node .github/workflows/scripts/send-notification-on-change.js diff --git a/.github/workflows/jscpd.yml b/.github/workflows/jscpd.yml index 5fc6e4829..5a9c23fef 100644 --- a/.github/workflows/jscpd.yml +++ b/.github/workflows/jscpd.yml @@ -35,7 +35,7 @@ jobs: ], "output": "./", "pattern": "**/*.js", - "ignore": "**/*spec.js" + "ignore": ["**/*spec.js"] }' > .jscpd.json - name: Run jscpd on entire codebase From 620e9ef1e0bd4bd6ab0a0693c753f746cac95724 Mon Sep 17 00:00:00 2001 From: Khang Vu Date: Fri, 6 Mar 2026 00:33:01 -0800 Subject: [PATCH 03/15] try this --- .github/workflows/jscpd.yml | 51 +++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 22 deletions(-) diff --git a/.github/workflows/jscpd.yml b/.github/workflows/jscpd.yml index 5a9c23fef..9ec6b0e02 100644 --- a/.github/workflows/jscpd.yml +++ b/.github/workflows/jscpd.yml @@ -1,29 +1,30 @@ name: Check for Duplicated Code on: - pull_request_target: + pull_request: branches: - master +permissions: + contents: read + jobs: check-duplication: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@v5 + uses: actions/checkout@v6 with: - fetch-depth: 0 # Fetch all history for all branches - ref: ${{ github.event.pull_request.head.sha }} + fetch-depth: 0 - name: Set up Node.js - uses: actions/setup-node@v5 + uses: actions/setup-node@v6 with: node-version: '20' - - name: Install dependencies - run: | - npm install -g jscpd diff-so-fancy + - name: Install jscpd + run: npm install -g jscpd - name: Create jscpd config file run: | @@ -41,20 +42,21 @@ jobs: - name: Run jscpd on entire codebase run: jscpd - - name: Fetch base and target branches + - name: Fetch base branch for comparison run: | - git fetch origin +refs/heads/${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }} - git fetch origin +refs/pull/${{ github.event.pull_request.number }}/merge:refs/remotes/pull/${{ github.event.pull_request.number }}/merge + git fetch origin refs/heads/${{ github.base_ref }} - - name: Get the diff - run: git diff --name-only origin/${{ github.event.pull_request.base.ref }}...refs/remotes/pull/${{ github.event.pull_request.number }}/merge > changed_files.txt + - name: Get changed files + run: | + git diff --name-only FETCH_HEAD...HEAD > changed_files.txt + cat changed_files.txt - name: List generated files (debug) run: ls -l - name: Upload unfiltered jscpd report if: always() - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: unfiltered-jscpd-report path: ./jscpd-report.json @@ -87,12 +89,12 @@ jobs: - name: Upload filtered jscpd report if: env.filtered_report_exists == 'true' - uses: actions/upload-artifact@v4 + uses: actions/upload-artifact@v7 with: name: filtered-jscpd-report path: ./filtered-jscpd-report.json - - name: Post GitHub comment + - name: Generate PR comment if: env.filtered_report_exists == 'true' uses: actions/github-script@v8 with: @@ -101,7 +103,7 @@ jobs: const filteredReport = JSON.parse(fs.readFileSync('filtered-jscpd-report.json', 'utf8')); let comment = "Whoa there, partner! 🌵🤠 We wrangled some duplicated code in your PR:\n\n"; function link(dup) { - return `https://github.com/${{ github.event.repository.full_name }}/blob/${{ github.event.pull_request.head.sha }}/${dup.name}#L${dup.start + 1}-L${dup.end - 1}` + return `https://github.com/${{ github.repository }}/blob/${{ github.event.pull_request.head.sha }}/${dup.name}#L${dup.start + 1}-L${dup.end - 1}` } filteredReport.forEach(duplication => { const firstFile = duplication.firstFile; @@ -110,15 +112,20 @@ jobs: comment += `- [\`${firstFile.name}\`](${link(firstFile)}) has ${lines} duplicated lines with [\`${secondFile.name}\`](${link(secondFile)})\n`; }); comment += "\nReducing code duplication by importing common functions from a library not only makes our code cleaner but also easier to maintain. Please move the common code from both files into a library and import it in each. We hate that we have to mention this, however, commits designed to hide from this utility by renaming variables or reordering an object are poor conduct. We will not look upon them kindly! Keep up the great work! 🚀"; - github.rest.issues.createComment({ - owner: context.repo.owner, - repo: context.repo.repo, + fs.writeFileSync('${{ runner.temp }}/comment.json', JSON.stringify({ issue_number: context.issue.number, body: comment - }); + })) + + - name: Upload comment data + if: env.filtered_report_exists == 'true' + uses: actions/upload-artifact@v7 + with: + name: comment + path: ${{ runner.temp }}/comment.json - name: Fail if duplications are found if: env.filtered_report_exists == 'true' run: | echo "Duplications found, failing the check." - exit 1 + exit 1 \ No newline at end of file From 0111d9461efda26f54442512f3ede630bd159846 Mon Sep 17 00:00:00 2001 From: Khang Vu Date: Fri, 6 Mar 2026 00:34:07 -0800 Subject: [PATCH 04/15] remove --- .github/workflows/jscpd.yml | 131 ------------------------------------ 1 file changed, 131 deletions(-) delete mode 100644 .github/workflows/jscpd.yml diff --git a/.github/workflows/jscpd.yml b/.github/workflows/jscpd.yml deleted file mode 100644 index 9ec6b0e02..000000000 --- a/.github/workflows/jscpd.yml +++ /dev/null @@ -1,131 +0,0 @@ -name: Check for Duplicated Code - -on: - pull_request: - branches: - - master - -permissions: - contents: read - -jobs: - check-duplication: - runs-on: ubuntu-latest - - steps: - - name: Checkout code - uses: actions/checkout@v6 - with: - fetch-depth: 0 - - - name: Set up Node.js - uses: actions/setup-node@v6 - with: - node-version: '20' - - - name: Install jscpd - run: npm install -g jscpd - - - name: Create jscpd config file - run: | - echo '{ - "threshold": 20, - "minTokens": 100, - "reporters": [ - "json" - ], - "output": "./", - "pattern": "**/*.js", - "ignore": ["**/*spec.js"] - }' > .jscpd.json - - - name: Run jscpd on entire codebase - run: jscpd - - - name: Fetch base branch for comparison - run: | - git fetch origin refs/heads/${{ github.base_ref }} - - - name: Get changed files - run: | - git diff --name-only FETCH_HEAD...HEAD > changed_files.txt - cat changed_files.txt - - - name: List generated files (debug) - run: ls -l - - - name: Upload unfiltered jscpd report - if: always() - uses: actions/upload-artifact@v7 - with: - name: unfiltered-jscpd-report - path: ./jscpd-report.json - - - name: Filter jscpd report for changed files - run: | - if [ ! -f ./jscpd-report.json ]; then - echo "jscpd-report.json not found" - exit 1 - fi - echo "Filtering jscpd report for changed files..." - CHANGED_FILES=$(jq -R -s -c 'split("\n")[:-1]' changed_files.txt) - echo "Changed files: $CHANGED_FILES" - jq --argjson changed_files "$CHANGED_FILES" ' - .duplicates | map(select( - (.firstFile?.name as $fname | $changed_files | any(. == $fname)) or - (.secondFile?.name as $sname | $changed_files | any(. == $sname)) - )) - ' ./jscpd-report.json > filtered-jscpd-report.json - cat filtered-jscpd-report.json - - - name: Check if filtered jscpd report exists - id: check_filtered_report - run: | - if [ $(wc -l < ./filtered-jscpd-report.json) -gt 1 ]; then - echo "filtered_report_exists=true" >> $GITHUB_ENV - else - echo "filtered_report_exists=false" >> $GITHUB_ENV - fi - - - name: Upload filtered jscpd report - if: env.filtered_report_exists == 'true' - uses: actions/upload-artifact@v7 - with: - name: filtered-jscpd-report - path: ./filtered-jscpd-report.json - - - name: Generate PR comment - if: env.filtered_report_exists == 'true' - uses: actions/github-script@v8 - with: - script: | - const fs = require('fs'); - const filteredReport = JSON.parse(fs.readFileSync('filtered-jscpd-report.json', 'utf8')); - let comment = "Whoa there, partner! 🌵🤠 We wrangled some duplicated code in your PR:\n\n"; - function link(dup) { - return `https://github.com/${{ github.repository }}/blob/${{ github.event.pull_request.head.sha }}/${dup.name}#L${dup.start + 1}-L${dup.end - 1}` - } - filteredReport.forEach(duplication => { - const firstFile = duplication.firstFile; - const secondFile = duplication.secondFile; - const lines = duplication.lines; - comment += `- [\`${firstFile.name}\`](${link(firstFile)}) has ${lines} duplicated lines with [\`${secondFile.name}\`](${link(secondFile)})\n`; - }); - comment += "\nReducing code duplication by importing common functions from a library not only makes our code cleaner but also easier to maintain. Please move the common code from both files into a library and import it in each. We hate that we have to mention this, however, commits designed to hide from this utility by renaming variables or reordering an object are poor conduct. We will not look upon them kindly! Keep up the great work! 🚀"; - fs.writeFileSync('${{ runner.temp }}/comment.json', JSON.stringify({ - issue_number: context.issue.number, - body: comment - })) - - - name: Upload comment data - if: env.filtered_report_exists == 'true' - uses: actions/upload-artifact@v7 - with: - name: comment - path: ${{ runner.temp }}/comment.json - - - name: Fail if duplications are found - if: env.filtered_report_exists == 'true' - run: | - echo "Duplications found, failing the check." - exit 1 \ No newline at end of file From bc34ec07de67a4d99c7895d8999fcaa817d6e27e Mon Sep 17 00:00:00 2001 From: Khang Vu Date: Fri, 6 Mar 2026 00:59:22 -0800 Subject: [PATCH 05/15] restore and maek triggable manually --- .github/workflows/code-path-changes.yml | 34 +++++++ .github/workflows/jscpd.yml | 125 ++++++++++++++++++++++++ 2 files changed, 159 insertions(+) create mode 100644 .github/workflows/code-path-changes.yml create mode 100644 .github/workflows/jscpd.yml diff --git a/.github/workflows/code-path-changes.yml b/.github/workflows/code-path-changes.yml new file mode 100644 index 000000000..ef4dc4f2e --- /dev/null +++ b/.github/workflows/code-path-changes.yml @@ -0,0 +1,34 @@ +name: Notify Code Path Changes + +on: + workflow_dispatch: + +env: + OAUTH2_CLIENT_ID: ${{ secrets.OAUTH2_CLIENT_ID }} + OAUTH2_CLIENT_SECRET: ${{ secrets.OAUTH2_CLIENT_SECRET }} + OAUTH2_REFRESH_TOKEN: ${{ secrets.OAUTH2_REFRESH_TOKEN }} + GITHUB_REPOSITORY: ${{ github.repository }} + GITHUB_PR_NUMBER: ${{ github.event.pull_request.number }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + +permissions: + contents: read + +jobs: + notify: + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v5 + + - name: Set up Node.js + uses: actions/setup-node@v5 + with: + node-version: '18' + + - name: Install dependencies + run: npm install axios nodemailer + + - name: Run Notification Script + run: | + node .github/workflows/scripts/send-notification-on-change.js \ No newline at end of file diff --git a/.github/workflows/jscpd.yml b/.github/workflows/jscpd.yml new file mode 100644 index 000000000..f51706879 --- /dev/null +++ b/.github/workflows/jscpd.yml @@ -0,0 +1,125 @@ +name: Check for Duplicated Code + +on: + workflow_dispatch: + pull_request_target: + branches: + - master + +jobs: + check-duplication: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v5 + with: + fetch-depth: 0 # Fetch all history for all branches + ref: ${{ github.event.pull_request.head.sha }} + + - name: Set up Node.js + uses: actions/setup-node@v5 + with: + node-version: '20' + + - name: Install dependencies + run: | + npm install -g jscpd diff-so-fancy + + - name: Create jscpd config file + run: | + echo '{ + "threshold": 20, + "minTokens": 100, + "reporters": [ + "json" + ], + "output": "./", + "pattern": "**/*.js", + "ignore": "**/*spec.js" + }' > .jscpd.json + + - name: Run jscpd on entire codebase + run: jscpd + + - name: Fetch base and target branches + run: | + git fetch origin +refs/heads/${{ github.event.pull_request.base.ref }}:refs/remotes/origin/${{ github.event.pull_request.base.ref }} + git fetch origin +refs/pull/${{ github.event.pull_request.number }}/merge:refs/remotes/pull/${{ github.event.pull_request.number }}/merge + + - name: Get the diff + run: git diff --name-only origin/${{ github.event.pull_request.base.ref }}...refs/remotes/pull/${{ github.event.pull_request.number }}/merge > changed_files.txt + + - name: List generated files (debug) + run: ls -l + + - name: Upload unfiltered jscpd report + if: always() + uses: actions/upload-artifact@v4 + with: + name: unfiltered-jscpd-report + path: ./jscpd-report.json + + - name: Filter jscpd report for changed files + run: | + if [ ! -f ./jscpd-report.json ]; then + echo "jscpd-report.json not found" + exit 1 + fi + echo "Filtering jscpd report for changed files..." + CHANGED_FILES=$(jq -R -s -c 'split("\n")[:-1]' changed_files.txt) + echo "Changed files: $CHANGED_FILES" + jq --argjson changed_files "$CHANGED_FILES" ' + .duplicates | map(select( + (.firstFile?.name as $fname | $changed_files | any(. == $fname)) or + (.secondFile?.name as $sname | $changed_files | any(. == $sname)) + )) + ' ./jscpd-report.json > filtered-jscpd-report.json + cat filtered-jscpd-report.json + + - name: Check if filtered jscpd report exists + id: check_filtered_report + run: | + if [ $(wc -l < ./filtered-jscpd-report.json) -gt 1 ]; then + echo "filtered_report_exists=true" >> $GITHUB_ENV + else + echo "filtered_report_exists=false" >> $GITHUB_ENV + fi + + - name: Upload filtered jscpd report + if: env.filtered_report_exists == 'true' + uses: actions/upload-artifact@v4 + with: + name: filtered-jscpd-report + path: ./filtered-jscpd-report.json + + - name: Post GitHub comment + if: env.filtered_report_exists == 'true' + uses: actions/github-script@v8 + with: + script: | + const fs = require('fs'); + const filteredReport = JSON.parse(fs.readFileSync('filtered-jscpd-report.json', 'utf8')); + let comment = "Whoa there, partner! 🌵🤠 We wrangled some duplicated code in your PR:\n\n"; + function link(dup) { + return `https://github.com/${{ github.event.repository.full_name }}/blob/${{ github.event.pull_request.head.sha }}/${dup.name}#L${dup.start + 1}-L${dup.end - 1}` + } + filteredReport.forEach(duplication => { + const firstFile = duplication.firstFile; + const secondFile = duplication.secondFile; + const lines = duplication.lines; + comment += `- [\`${firstFile.name}\`](${link(firstFile)}) has ${lines} duplicated lines with [\`${secondFile.name}\`](${link(secondFile)})\n`; + }); + comment += "\nReducing code duplication by importing common functions from a library not only makes our code cleaner but also easier to maintain. Please move the common code from both files into a library and import it in each. We hate that we have to mention this, however, commits designed to hide from this utility by renaming variables or reordering an object are poor conduct. We will not look upon them kindly! Keep up the great work! 🚀"; + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: comment + }); + + - name: Fail if duplications are found + if: env.filtered_report_exists == 'true' + run: | + echo "Duplications found, failing the check." + exit 1 \ No newline at end of file From 46a23e1b52e9d5c8b4ad77a21ec5ff041f66228f Mon Sep 17 00:00:00 2001 From: Khang Vu Date: Fri, 6 Mar 2026 10:26:55 -0800 Subject: [PATCH 06/15] use oajs global var and correct targeting keys --- test/spec/e2e/banner/basic_banner_ad.spec.js | 20 +++++++------- .../instream/basic_instream_video_ad.spec.js | 26 +++++++++---------- .../e2e/modules/e2e_bidderSettings.spec.js | 20 +++++++------- test/spec/e2e/modules/e2e_currency.spec.js | 4 +-- .../multi-bidder/e2e_multiple_bidders.spec.js | 18 ++++++------- test/spec/e2e/native/basic_native_ad.spec.js | 18 ++++++------- .../basic_outstream_video_ad.spec.js | 22 ++++++++-------- 7 files changed, 64 insertions(+), 64 deletions(-) diff --git a/test/spec/e2e/banner/basic_banner_ad.spec.js b/test/spec/e2e/banner/basic_banner_ad.spec.js index 91e7b16b1..c978f55bf 100644 --- a/test/spec/e2e/banner/basic_banner_ad.spec.js +++ b/test/spec/e2e/banner/basic_banner_ad.spec.js @@ -7,12 +7,12 @@ const CREATIVE_IFRAME_ID = 'google_ads_iframe_/19968336/header-bid-tag-0_0'; const CREATIVE_IFRAME_CSS_SELECTOR = 'iframe[id="' + CREATIVE_IFRAME_ID + '"]'; const EXPECTED_TARGETING_KEYS = { - 'hb_format': 'banner', - 'hb_pb': '0.50', - 'hb_bidder': 'appnexus', - 'hb_format_appnexus': 'banner', - 'hb_pb_appnexus': '0.50', - 'hb_bidder_appnexus': 'appnexus' + 'oa_format': 'banner', + 'oa_pb': '0.50', + 'oa_bidder': 'appnexus', + 'oa_format_appnexus': 'banner', + 'oa_pb_appnexus': '0.50', + 'oa_bidder_appnexus': 'appnexus' }; Object.entries({ @@ -26,14 +26,14 @@ Object.entries({ }, `Prebid.js Banner Ad Unit Test (loading ${t})`, function () { it('should load the targeting keys with correct values', async function () { const result = await browser.execute(function () { - return window.pbjs.getAdserverTargeting('div-gpt-ad-1460505748561-1'); + return window.oajs.getAdserverTargeting('div-gpt-ad-1460505748561-1'); }); const targetingKeys = result['div-gpt-ad-1460505748561-1']; expect(targetingKeys).to.include(EXPECTED_TARGETING_KEYS); - expect(targetingKeys.hb_adid).to.be.a('string'); - expect(targetingKeys.hb_adid_appnexus).to.be.a('string'); - expect(targetingKeys.hb_size).to.satisfy((size) => size === '300x250' || '300x600'); + expect(targetingKeys.oa_adid).to.be.a('string'); + expect(targetingKeys.oa_adid_appnexus).to.be.a('string'); + expect(targetingKeys.oa_size).to.satisfy((size) => size === '300x250' || '300x600'); }); }); }); diff --git a/test/spec/e2e/instream/basic_instream_video_ad.spec.js b/test/spec/e2e/instream/basic_instream_video_ad.spec.js index 302090555..ef1f2731f 100644 --- a/test/spec/e2e/instream/basic_instream_video_ad.spec.js +++ b/test/spec/e2e/instream/basic_instream_video_ad.spec.js @@ -5,14 +5,14 @@ const TEST_PAGE_URL = testPageURL('instream.html?pbjs_debug=true'); const ALERT_BOX_CSS_SELECTOR = 'div[id="event-window"] > p[id="statusText"]'; const EXPECTED_TARGETING_KEYS = { - hb_format: 'video', - hb_size: '640x480', - hb_pb: '10.00', - hb_bidder: 'appnexus', - hb_format_appnexus: 'video', - hb_size_appnexus: '640x480', - hb_pb_appnexus: '10.00', - hb_bidder_appnexus: 'appnexus' + oa_format: 'video', + oa_size: '640x480', + oa_pb: '10.00', + oa_bidder: 'appnexus', + oa_format_appnexus: 'video', + oa_size_appnexus: '640x480', + oa_pb_appnexus: '10.00', + oa_bidder_appnexus: 'appnexus' }; setupTest({ url: TEST_PAGE_URL, @@ -20,14 +20,14 @@ setupTest({ }, 'Prebid.js Instream Video Ad Test', function () { it('should load the targeting keys with correct values', async function () { const result = await browser.execute(function () { - return window.top.pbjs.getAdserverTargeting('video1'); + return window.top.oajs.getAdserverTargeting('video1'); }); const targetingKeys = result['video1']; expect(targetingKeys).to.include(EXPECTED_TARGETING_KEYS); - expect(targetingKeys.hb_adid).to.be.a('string'); - expect(targetingKeys.hb_adid_appnexus).to.be.a('string'); - expect(targetingKeys.hb_uuid).to.be.a('string'); - expect(targetingKeys.hb_uuid_appnexus).to.be.a('string'); + expect(targetingKeys.oa_adid).to.be.a('string'); + expect(targetingKeys.oa_adid_appnexus).to.be.a('string'); + expect(targetingKeys.oa_uuid).to.be.a('string'); + expect(targetingKeys.oa_uuid_appnexus).to.be.a('string'); }); }); diff --git a/test/spec/e2e/modules/e2e_bidderSettings.spec.js b/test/spec/e2e/modules/e2e_bidderSettings.spec.js index a27f2be0e..913467b93 100644 --- a/test/spec/e2e/modules/e2e_bidderSettings.spec.js +++ b/test/spec/e2e/modules/e2e_bidderSettings.spec.js @@ -5,14 +5,14 @@ const TEST_PAGE_URL = testPageURL('bidderSettings.html?pbjs_debug=true'); const CREATIVE_IFRAME_CSS_SELECTOR = 'iframe[id="google_ads_iframe_/19968336/header-bid-tag-0_0"]'; const EXPECTED_TARGETING_KEYS = { - hb_pb_appnexus: '10.00', - hb_format: 'native', - hb_size: '0x0', - hb_bidder_appnexus: 'appnexus', - hb_pb: '10.00', - hb_bidder: 'appnexus', - hb_format_appnexus: 'native', - hb_size_appnexus: '0x0', + oa_pb_appnexus: '10.00', + oa_format: 'native', + oa_size: '0x0', + oa_bidder_appnexus: 'appnexus', + oa_pb: '10.00', + oa_bidder: 'appnexus', + oa_format_appnexus: 'native', + oa_size_appnexus: '0x0', }; setupTest({ @@ -22,14 +22,14 @@ setupTest({ }, 'Prebid.js Bidder Settings Ad Unit Test', function () { it('should load the targeting keys with correct values', async function () { const result = await browser.execute(function () { - return window.pbjs.getAdserverTargeting('/19968336/prebid_native_example_2'); + return window.oajs.getAdserverTargeting('/19968336/prebid_native_example_2'); }); const targetingKeys = result['/19968336/prebid_native_example_2']; expect(targetingKeys).to.include(EXPECTED_TARGETING_KEYS); // check that custom (bidderSettings) keys are present expect(targetingKeys.apn_adId).to.be.a('string'); - expect(targetingKeys.apn_adId).to.equal(targetingKeys.hb_adid); + expect(targetingKeys.apn_adId).to.equal(targetingKeys.oa_adid); expect(targetingKeys.apn_pbMg).to.equal('10.00'); }); }); diff --git a/test/spec/e2e/modules/e2e_currency.spec.js b/test/spec/e2e/modules/e2e_currency.spec.js index 3567ae448..3980b4221 100644 --- a/test/spec/e2e/modules/e2e_currency.spec.js +++ b/test/spec/e2e/modules/e2e_currency.spec.js @@ -5,7 +5,7 @@ const TEST_PAGE_URL = testPageURL('currency.html?pbjs_debug=true'); const CREATIVE_IFRAME_CSS_SELECTOR = 'iframe[id="google_ads_iframe_/19968336/header-bid-tag-0_0"]'; const EXPECTED_TARGETING_KEYS = { - hb_pb: '8.00' // response is 10; currency conversion is set to 0.8 + oa_pb: '8.00' // response is 10; currency conversion is set to 0.8 } setupTest({ @@ -15,7 +15,7 @@ setupTest({ }, 'Prebid.js Currency Ad Unit Test', function () { it('should load the targeting keys with correct values', async function () { const result = await browser.execute(function () { - return window.pbjs.getAdserverTargeting('/19968336/prebid_native_example_2'); + return window.oajs.getAdserverTargeting('/19968336/prebid_native_example_2'); }); const targetingKeys = result['/19968336/prebid_native_example_2']; diff --git a/test/spec/e2e/multi-bidder/e2e_multiple_bidders.spec.js b/test/spec/e2e/multi-bidder/e2e_multiple_bidders.spec.js index b91dfe3cf..2ef95c5f9 100644 --- a/test/spec/e2e/multi-bidder/e2e_multiple_bidders.spec.js +++ b/test/spec/e2e/multi-bidder/e2e_multiple_bidders.spec.js @@ -5,14 +5,14 @@ const TEST_PAGE_URL = testPageURL('multiple_bidders.html?pbjs_debug=true'); const CREATIVE_BANNER_CSS_SELECTOR = 'iframe[id="google_ads_iframe_/19968336/prebid_multiformat_test_0"]'; const EXPECTED_TARGETING_KEYS = { - hb_pb_adasta: '10.00', - hb_format: 'native', - hb_size: '0x0', - hb_bidder_adasta: 'adasta', - hb_pb: '10.00', - hb_bidder: 'adasta', - hb_format_adasta: 'native', - hb_size_adasta: '0x0' + oa_pb_adasta: '10.00', + oa_format: 'native', + oa_size: '0x0', + oa_bidder_adasta: 'adasta', + oa_pb: '10.00', + oa_bidder: 'adasta', + oa_format_adasta: 'native', + oa_size_adasta: '0x0' }; setupTest({ @@ -22,7 +22,7 @@ setupTest({ }, 'Prebid.js Multiple Bidder Ad Unit Test', function () { it('should load the targeting keys with correct values', async function () { const result = await browser.execute(function () { - return window.pbjs.getAdserverTargeting('div-banner-native-2'); + return window.oajs.getAdserverTargeting('div-banner-native-2'); }); const targetingKeys = result['div-banner-native-2']; diff --git a/test/spec/e2e/native/basic_native_ad.spec.js b/test/spec/e2e/native/basic_native_ad.spec.js index 320a83bda..53fb9662d 100644 --- a/test/spec/e2e/native/basic_native_ad.spec.js +++ b/test/spec/e2e/native/basic_native_ad.spec.js @@ -5,14 +5,14 @@ const TEST_PAGE_URL = testPageURL('native.html?pbjs_debug=true'); const CREATIVE_IFRAME_CSS_SELECTOR = 'iframe[id="google_ads_iframe_/19968336/prebid_native_example_1_0"]'; const EXPECTED_TARGETING_KEYS = { - hb_pb_appnexus: '10.00', - hb_format: 'native', - hb_size: '0x0', - hb_bidder_appnexus: 'appnexus', - hb_pb: '10.00', - hb_bidder: 'appnexus', - hb_format_appnexus: 'native', - hb_size_appnexus: '0x0' + oa_pb_appnexus: '10.00', + oa_format: 'native', + oa_size: '0x0', + oa_bidder_appnexus: 'appnexus', + oa_pb: '10.00', + oa_bidder: 'appnexus', + oa_format_appnexus: 'native', + oa_size_appnexus: '0x0' } setupTest({ @@ -23,7 +23,7 @@ setupTest({ }, 'Prebid.js Native Ad Unit Test', function () { it('should load the targeting keys with correct values', async function () { const result = await browser.execute(function () { - return window.pbjs.getAdserverTargeting('/19968336/prebid_native_example_2'); + return window.oajs.getAdserverTargeting('/19968336/prebid_native_example_2'); }); const targetingKeys = result['/19968336/prebid_native_example_2']; diff --git a/test/spec/e2e/outstream/basic_outstream_video_ad.spec.js b/test/spec/e2e/outstream/basic_outstream_video_ad.spec.js index 2854ed13a..85fc8d72a 100644 --- a/test/spec/e2e/outstream/basic_outstream_video_ad.spec.js +++ b/test/spec/e2e/outstream/basic_outstream_video_ad.spec.js @@ -5,14 +5,14 @@ const TEST_PAGE_URL = testPageURL('outstream.html'); const CREATIVE_IFRAME_CSS_SELECTOR = 'div[id="video_ad_unit_1"] > div:nth-child(2) > iframe:nth-child(1)'; const EXPECTED_TARGETING_KEYS = { - hb_format: 'video', - hb_size: '640x480', - hb_pb: '10.00', - hb_bidder: 'appnexus', - hb_format_appnexus: 'video', - hb_size_appnexus: '640x480', - hb_pb_appnexus: '10.00', - hb_bidder_appnexus: 'appnexus' + oa_format: 'video', + oa_size: '640x480', + oa_pb: '10.00', + oa_bidder: 'appnexus', + oa_format_appnexus: 'video', + oa_size_appnexus: '640x480', + oa_pb_appnexus: '10.00', + oa_bidder_appnexus: 'appnexus' }; setupTest({ @@ -21,13 +21,13 @@ setupTest({ }, 'Prebid.js Outstream Video Ad Test', function () { it('should load the targeting keys with correct values', async function () { const result = await browser.execute(function () { - return window.pbjs.getAdserverTargeting('video_ad_unit_2'); + return window.oajs.getAdserverTargeting('video_ad_unit_2'); }); const targetingKeys = result['video_ad_unit_2']; expect(targetingKeys).to.include(EXPECTED_TARGETING_KEYS); - expect(targetingKeys.hb_adid).to.be.a('string'); - expect(targetingKeys.hb_adid_appnexus).to.be.a('string'); + expect(targetingKeys.oa_adid).to.be.a('string'); + expect(targetingKeys.oa_adid_appnexus).to.be.a('string'); }); it('should render the video ad on the page', async function() { From 523fea2e1b59624e4a87424a629741b29c0a2411 Mon Sep 17 00:00:00 2001 From: Khang Vu Date: Wed, 11 Mar 2026 00:29:35 -0700 Subject: [PATCH 07/15] testing --- test/pages/banner.html | 18 +++--- test/pages/banner_sync.html | 16 ++--- test/spec/e2e/banner/basic_banner_ad.spec.js | 2 +- .../instream/basic_instream_video_ad.spec.js | 33 ---------- .../e2e/modules/e2e_bidderSettings.spec.js | 35 ----------- .../e2e/modules/e2e_consent_mgt_gdpr.spec.js | 62 ------------------- test/spec/e2e/modules/e2e_currency.spec.js | 24 ------- .../multi-bidder/e2e_multiple_bidders.spec.js | 31 ---------- test/spec/e2e/native/basic_native_ad.spec.js | 32 ---------- .../basic_outstream_video_ad.spec.js | 42 ------------- 10 files changed, 18 insertions(+), 277 deletions(-) delete mode 100644 test/spec/e2e/instream/basic_instream_video_ad.spec.js delete mode 100644 test/spec/e2e/modules/e2e_bidderSettings.spec.js delete mode 100644 test/spec/e2e/modules/e2e_consent_mgt_gdpr.spec.js delete mode 100644 test/spec/e2e/modules/e2e_currency.spec.js delete mode 100644 test/spec/e2e/multi-bidder/e2e_multiple_bidders.spec.js delete mode 100644 test/spec/e2e/native/basic_native_ad.spec.js delete mode 100644 test/spec/e2e/outstream/basic_outstream_video_ad.spec.js diff --git a/test/pages/banner.html b/test/pages/banner.html index 19593ff49..35b14aeef 100644 --- a/test/pages/banner.html +++ b/test/pages/banner.html @@ -13,8 +13,8 @@ @@ -66,10 +66,10 @@ googletag.pubads().disableInitialLoad(); }); - pbjs.que.push(function () { - pbjs.setConfig({enableTIDs: true}); - pbjs.addAdUnits(adUnits); - pbjs.bidderSettings = { + oajs.que.push(function () { + oajs.setConfig({enableTIDs: true}); + oajs.addAdUnits(adUnits); + oajs.bidderSettings = { appnexus: { adserverTargeting: [ { @@ -86,18 +86,18 @@ ] } } - pbjs.requestBids({ + oajs.requestBids({ bidsBackHandler: sendAdserverRequest, timeout: PREBID_TIMEOUT }); }); function sendAdserverRequest() { - if (pbjs.adserverRequestSent) return; - pbjs.adserverRequestSent = true; + if (oajs.adserverRequestSent) return; + oajs.adserverRequestSent = true; googletag.cmd.push(function () { - pbjs.que.push(function () { - pbjs.setTargetingForGPTAsync(); + oajs.que.push(function () { + oajs.setTargetingForGPTAsync(); googletag.pubads().refresh(); }); }); @@ -107,7 +107,7 @@ @@ -75,8 +75,8 @@ googletag.pubads().disableInitialLoad(); }); - pbjs.que.push(function() { - pbjs.setConfig({ + oajs.que.push(function() { + oajs.setConfig({ enableTIDs: true, "currency": { "adServerCurrency": "GBP", @@ -84,19 +84,19 @@ "rates": { "USD": { "GBP": 0.80 }} } }); - pbjs.addAdUnits(adUnits); - pbjs.requestBids({ + oajs.addAdUnits(adUnits); + oajs.requestBids({ bidsBackHandler: sendAdserverRequest, timeout: PREBID_TIMEOUT }); }); function sendAdserverRequest() { - if (pbjs.adserverRequestSent) return; - pbjs.adserverRequestSent = true; + if (oajs.adserverRequestSent) return; + oajs.adserverRequestSent = true; googletag.cmd.push(function() { - pbjs.que.push(function() { - pbjs.setTargetingForGPTAsync('div-gpt-ad-1460505748561-0'); + oajs.que.push(function() { + oajs.setTargetingForGPTAsync('div-gpt-ad-1460505748561-0'); googletag.pubads().refresh(); }); }); @@ -110,7 +110,7 @@