1
1
import adagioAnalyticsAdapter from 'modules/adagioAnalyticsAdapter.js' ;
2
2
import { expect } from 'chai' ;
3
3
import * as utils from 'src/utils.js' ;
4
- import { getGlobal } from 'src/prebidGlobal.js' ;
5
4
import { server } from 'test/mocks/xhr.js' ;
5
+ import * as prebidGlobal from 'src/prebidGlobal.js' ;
6
6
7
7
let adapterManager = require ( 'src/adapterManager' ) . default ;
8
8
let events = require ( 'src/events' ) ;
@@ -647,17 +647,19 @@ describe('adagio analytics adapter', () => {
647
647
} ) ;
648
648
649
649
it ( 'builds and sends auction data' , ( ) => {
650
- getGlobal ( ) . convertCurrency = ( cpm , from , to ) => {
651
- const convKeys = {
652
- 'GBP-EUR' : 0.7 ,
653
- 'EUR-GBP' : 1.3 ,
654
- 'USD-EUR' : 0.8 ,
655
- 'EUR-USD' : 1.2 ,
656
- 'USD-GBP' : 0.6 ,
657
- 'GBP-USD' : 1.6 ,
658
- } ;
659
- return cpm * ( convKeys [ `${ from } -${ to } ` ] || 1 ) ;
660
- } ;
650
+ sandbox . stub ( prebidGlobal , 'getGlobal' ) . returns ( {
651
+ convertCurrency : ( cpm , from , to ) => {
652
+ const convKeys = {
653
+ 'GBP-EUR' : 0.7 ,
654
+ 'EUR-GBP' : 1.3 ,
655
+ 'USD-EUR' : 0.8 ,
656
+ 'EUR-USD' : 1.2 ,
657
+ 'USD-GBP' : 0.6 ,
658
+ 'GBP-USD' : 1.6 ,
659
+ } ;
660
+ return cpm * ( convKeys [ `${ from } -${ to } ` ] || 1 ) ;
661
+ }
662
+ } ) ;
661
663
662
664
events . emit ( constants . EVENTS . AUCTION_INIT , MOCK . AUCTION_INIT . another ) ;
663
665
events . emit ( constants . EVENTS . BID_RESPONSE , MOCK . BID_RESPONSE . adagio ) ;
@@ -697,6 +699,7 @@ describe('adagio analytics adapter', () => {
697
699
expect ( search . e_sid ) . to . equal ( '42' ) ;
698
700
expect ( search . e_pba_test ) . to . equal ( 'true' ) ;
699
701
expect ( search . bdrs_bid ) . to . equal ( '1,1,0' ) ;
702
+ expect ( search . bdrs_cpm ) . to . equal ( '1.42,2.052,' ) ;
700
703
}
701
704
702
705
{
@@ -710,27 +713,25 @@ describe('adagio analytics adapter', () => {
710
713
expect ( search . win_bdr ) . to . equal ( 'another' ) ;
711
714
expect ( search . win_mt ) . to . equal ( 'ban' ) ;
712
715
expect ( search . win_ban_sz ) . to . equal ( '728x90' ) ;
713
- expect ( search . win_cpm ) . to . equal ( '1.71' ) ;
714
- expect ( search . cur ) . to . equal ( 'EUR' ) ;
715
- expect ( search . cur_rate ) . to . equal ( '1.2' ) ;
716
- expect ( search . og_cpm ) . to . equal ( '1.62' ) ;
717
- expect ( search . og_cur ) . to . equal ( 'GBP' ) ;
718
- expect ( search . og_cur_rate ) . to . equal ( '1.6' ) ;
716
+ expect ( search . win_net_cpm ) . to . equal ( '2.052' ) ;
717
+ expect ( search . win_og_cpm ) . to . equal ( '2.592' ) ;
719
718
}
720
719
} ) ;
721
720
722
721
it ( 'builds and sends auction data with a cached bid win' , ( ) => {
723
- getGlobal ( ) . convertCurrency = ( cpm , from , to ) => {
724
- const convKeys = {
725
- 'GBP-EUR' : 0.7 ,
726
- 'EUR-GBP' : 1.3 ,
727
- 'USD-EUR' : 0.8 ,
728
- 'EUR-USD' : 1.2 ,
729
- 'USD-GBP' : 0.6 ,
730
- 'GBP-USD' : 1.6 ,
731
- } ;
732
- return cpm * ( convKeys [ `${ from } -${ to } ` ] || 1 ) ;
733
- } ;
722
+ sandbox . stub ( prebidGlobal , 'getGlobal' ) . returns ( {
723
+ convertCurrency : ( cpm , from , to ) => {
724
+ const convKeys = {
725
+ 'GBP-EUR' : 0.7 ,
726
+ 'EUR-GBP' : 1.3 ,
727
+ 'USD-EUR' : 0.8 ,
728
+ 'EUR-USD' : 1.2 ,
729
+ 'USD-GBP' : 0.6 ,
730
+ 'GBP-USD' : 1.6 ,
731
+ } ;
732
+ return cpm * ( convKeys [ `${ from } -${ to } ` ] || 1 ) ;
733
+ }
734
+ } ) ;
734
735
735
736
events . emit ( constants . EVENTS . AUCTION_INIT , MOCK . AUCTION_INIT . bidcached ) ;
736
737
events . emit ( constants . EVENTS . AUCTION_INIT , MOCK . AUCTION_INIT . another ) ;
@@ -794,6 +795,7 @@ describe('adagio analytics adapter', () => {
794
795
expect ( search . e_sid ) . to . equal ( '42' ) ;
795
796
expect ( search . e_pba_test ) . to . equal ( 'true' ) ;
796
797
expect ( search . bdrs_bid ) . to . equal ( '0,0,0' ) ;
798
+ expect ( search . bdrs_cpm ) . to . equal ( ',,' ) ;
797
799
}
798
800
799
801
{
@@ -808,12 +810,8 @@ describe('adagio analytics adapter', () => {
808
810
expect ( search . win_bdr ) . to . equal ( 'adagio' ) ;
809
811
expect ( search . win_mt ) . to . equal ( 'ban' ) ;
810
812
expect ( search . win_ban_sz ) . to . equal ( '728x90' ) ;
811
- expect ( search . win_cpm ) . to . equal ( '1.42' ) ;
812
- expect ( search . cur ) . to . equal ( 'USD' ) ;
813
- expect ( search . cur_rate ) . to . equal ( '1' ) ;
814
- expect ( search . og_cpm ) . to . equal ( '1.42' ) ;
815
- expect ( search . og_cur ) . to . equal ( 'USD' ) ;
816
- expect ( search . og_cur_rate ) . to . equal ( '1' ) ;
813
+ expect ( search . win_net_cpm ) . to . equal ( '1.42' ) ;
814
+ expect ( search . win_og_cpm ) . to . equal ( '1.42' ) ;
817
815
expect ( search . rndr ) . to . not . exist ;
818
816
}
819
817
@@ -829,5 +827,31 @@ describe('adagio analytics adapter', () => {
829
827
expect ( search . rndr ) . to . equal ( '0' ) ;
830
828
}
831
829
} ) ;
830
+
831
+ it ( 'send an "empty" cpm when adserver currency != USD and convertCurrency() is undefined' , ( ) => {
832
+ sandbox . stub ( prebidGlobal , 'getGlobal' ) . returns ( { } ) ;
833
+
834
+ events . emit ( constants . EVENTS . AUCTION_INIT , MOCK . AUCTION_INIT . another ) ;
835
+ events . emit ( constants . EVENTS . BID_RESPONSE , MOCK . BID_RESPONSE . adagio ) ;
836
+ events . emit ( constants . EVENTS . BID_RESPONSE , MOCK . BID_RESPONSE . another ) ;
837
+ events . emit ( constants . EVENTS . AUCTION_END , MOCK . AUCTION_END . another ) ;
838
+ events . emit ( constants . EVENTS . BID_WON , MOCK . BID_WON . another ) ;
839
+ events . emit ( constants . EVENTS . AD_RENDER_SUCCEEDED , MOCK . AD_RENDER_SUCCEEDED . another ) ;
840
+
841
+ expect ( server . requests . length ) . to . equal ( 3 , 'requests count' ) ;
842
+
843
+ // fail to compute bidder cpm and send an "empty" cpm
844
+ {
845
+ const { protocol, hostname, pathname, search } = utils . parseUrl ( server . requests [ 1 ] . url ) ;
846
+ expect ( protocol ) . to . equal ( 'https' ) ;
847
+ expect ( hostname ) . to . equal ( 'c.4dex.io' ) ;
848
+ expect ( pathname ) . to . equal ( '/pba.gif' ) ;
849
+ expect ( search . v ) . to . equal ( '2' ) ;
850
+ expect ( search . e_sid ) . to . equal ( '42' ) ;
851
+ expect ( search . e_pba_test ) . to . equal ( 'true' ) ;
852
+ expect ( search . bdrs_bid ) . to . equal ( '1,1,0' ) ;
853
+ expect ( search . bdrs_cpm ) . to . equal ( '1.42,,' ) ;
854
+ }
855
+ } ) ;
832
856
} ) ;
833
857
} ) ;
0 commit comments