github.com/prebid/prebid-server/v2@v2.18.0/injector/injector_test.go (about) 1 package injector 2 3 import ( 4 "errors" 5 "strings" 6 "testing" 7 8 "github.com/prebid/openrtb/v20/openrtb2" 9 "github.com/prebid/prebid-server/v2/exchange/entities" 10 "github.com/prebid/prebid-server/v2/macros" 11 "github.com/prebid/prebid-server/v2/openrtb_ext" 12 "github.com/prebid/prebid-server/v2/util/ptrutil" 13 "github.com/stretchr/testify/assert" 14 ) 15 16 var reqWrapper = &openrtb_ext.RequestWrapper{ 17 BidRequest: &openrtb2.BidRequest{ 18 ID: "123", 19 Site: &openrtb2.Site{ 20 Domain: "testdomain", 21 Publisher: &openrtb2.Publisher{ 22 Domain: "publishertestdomain", 23 ID: "testpublisherID", 24 }, 25 Page: "pageurltest", 26 }, 27 App: &openrtb2.App{ 28 Domain: "testdomain", 29 Bundle: "testbundle", 30 Publisher: &openrtb2.Publisher{ 31 Domain: "publishertestdomain", 32 ID: "testpublisherID", 33 }, 34 }, 35 Device: &openrtb2.Device{ 36 Lmt: ptrutil.ToPtr(int8(1)), 37 }, 38 User: &openrtb2.User{Ext: []byte(`{"consent":"1" }`)}, 39 Ext: []byte(`{"prebid":{"channel": {"name":"test1"},"macros":{"CUSTOMMACR1":"value1"}}}`), 40 }, 41 } 42 43 func TestInjectTracker(t *testing.T) { 44 b := macros.NewProvider(reqWrapper) 45 b.PopulateBidMacros(&entities.PbsOrtbBid{ 46 Bid: &openrtb2.Bid{ 47 ID: "bid123", 48 }, 49 }, "testSeat") 50 ti := NewTrackerInjector( 51 macros.NewStringIndexBasedReplacer(), 52 b, 53 VASTEvents{ 54 Errors: []string{"http://errortracker.com?macro1=##PBS-BIDID##¯o2=##PBS-APPBUNDLE##¯o3=##PBS-APPBUNDLE##¯o4=##PBS-PUBDOMAIN##¯o5=##PBS-PAGEURL##¯o6=##PBS-ACCOUNTID##¯o6=##PBS-LIMITADTRACKING##¯o7=##PBS-GDPRCONSENT##¯o8=##PBS-GDPRCONSENT##¯o9=##PBS-MACRO-CUSTOMMACR1CUST1##¯o10=##PBS-MACRO-CUSTOMMACR1CUST2##"}, 55 Impressions: []string{"http://impressiontracker.com?macro1=##PBS-BIDID##¯o2=##PBS-APPBUNDLE##¯o3=##PBS-APPBUNDLE##¯o4=##PBS-PUBDOMAIN##¯o5=##PBS-PAGEURL##¯o6=##PBS-ACCOUNTID##¯o6=##PBS-LIMITADTRACKING##¯o7=##PBS-GDPRCONSENT##¯o8=##PBS-GDPRCONSENT##¯o9=##PBS-MACRO-CUSTOMMACR1CUST1##¯o10=##PBS-MACRO-CUSTOMMACR1CUST2##"}, 56 VideoClicks: []string{"http://videoclicktracker.com?macro1=##PBS-BIDID##¯o2=##PBS-APPBUNDLE##¯o3=##PBS-APPBUNDLE##¯o4=##PBS-PUBDOMAIN##¯o5=##PBS-PAGEURL##¯o6=##PBS-ACCOUNTID##¯o6=##PBS-LIMITADTRACKING##¯o7=##PBS-GDPRCONSENT##¯o8=##PBS-GDPRCONSENT##¯o9=##PBS-MACRO-CUSTOMMACR1CUST1##¯o10=##PBS-MACRO-CUSTOMMACR1CUST2##"}, 57 NonLinearClickTracking: []string{"http://nonlinearclicktracker.com?macro1=##PBS-BIDID##¯o2=##PBS-APPBUNDLE##¯o3=##PBS-APPBUNDLE##¯o4=##PBS-PUBDOMAIN##¯o5=##PBS-PAGEURL##¯o6=##PBS-ACCOUNTID##¯o6=##PBS-LIMITADTRACKING##¯o7=##PBS-GDPRCONSENT##¯o8=##PBS-GDPRCONSENT##¯o9=##PBS-MACRO-CUSTOMMACR1CUST1##¯o10=##PBS-MACRO-CUSTOMMACR1CUST2##"}, 58 CompanionClickThrough: []string{"http://companionclicktracker.com?macro1=##PBS-BIDID##¯o2=##PBS-APPBUNDLE##¯o3=##PBS-APPBUNDLE##¯o4=##PBS-PUBDOMAIN##¯o5=##PBS-PAGEURL##¯o6=##PBS-ACCOUNTID##¯o6=##PBS-LIMITADTRACKING##¯o7=##PBS-GDPRCONSENT##¯o8=##PBS-GDPRCONSENT##¯o9=##PBS-MACRO-CUSTOMMACR1CUST1##¯o10=##PBS-MACRO-CUSTOMMACR1CUST2##"}, 59 TrackingEvents: map[string][]string{"firstQuartile": {"http://eventracker1.com?macro1=##PBS-BIDID##¯o2=##PBS-APPBUNDLE##¯o3=##PBS-APPBUNDLE##¯o4=##PBS-PUBDOMAIN##¯o5=##PBS-PAGEURL##¯o6=##PBS-ACCOUNTID##¯o6=##PBS-LIMITADTRACKING##¯o7=##PBS-GDPRCONSENT##¯o8=##PBS-GDPRCONSENT##¯o9=##PBS-MACRO-CUSTOMMACR1CUST1##¯o10=##PBS-MACRO-CUSTOMMACR1CUST2##"}}, 60 }, 61 ) 62 type args struct { 63 vastXML string 64 NURL string 65 } 66 tests := []struct { 67 name string 68 args args 69 want string 70 wantError error 71 }{ 72 { 73 name: "Empty vastXML and NURL present", 74 args: args{ 75 vastXML: "", 76 NURL: "www.nurl.com", 77 }, 78 want: `<VAST version="3.0"><Ad><Wrapper><AdSystem>prebid.org wrapper</AdSystem><VASTAdTagURI><![CDATA[www.nurl.com]]></VASTAdTagURI><Creatives></Creatives></Wrapper></Ad></VAST>`, 79 wantError: nil, 80 }, 81 { 82 name: "Empty vastXML and empty NURL", 83 args: args{ 84 vastXML: "", 85 NURL: "", 86 }, 87 want: "", 88 wantError: errors.New("invalid Vast XML"), 89 }, 90 { 91 name: "No Inline/Wrapper tag present", 92 args: args{ 93 vastXML: `<VAST version="4.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.iab.com/VAST"><Ad id="20001" sequence="1" conditionalAd="false"></Ad></VAST>`, 94 NURL: "", 95 }, 96 want: `<VAST version="4.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.iab.com/VAST"><Ad id="20001" sequence="1" conditionalAd="false"></Ad></VAST>`, 97 wantError: errors.New("invalid VastXML, inline/wrapper tag not found"), 98 }, 99 { 100 name: "Invalid Vast XML, parsing error", 101 args: args{ 102 vastXML: `<VAST version="4.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.iab.com/VAST"><Ad id="20001" sequence="1" conditionalAd="false"><InLine><AdSystem version="4.0">iabtechlab</AdSystem><Error>http://example.com/error<Impression id="Impression-ID">http://example.com/track/impression</Impression><Pricing model="cpm" currency="USD"><![CDATA[ 25.00 ]]></Pricing><AdTitle>Inline Simple Ad</AdTitle><AdVerifications></AdVerifications><Advertiser>IAB Sample Company</Advertiser><Category authority="http://www.iabtechlab.com/categoryauthority">AD CONTENT description category</Category><Creatives><Creative id="5480" sequence="1" adId="2447226"><UniversalAdId idRegistry="Ad-ID" idValue="8465">8465</UniversalAdId><Linear><Duration>00:00:16</Duration><MediaFiles><MediaFile id="5241" delivery="progressive" type="video/mp4" bitrate="2000" width="1280" height="720" minBitrate="1500" maxBitrate="2500" scalable="1" maintainAspectRatio="1" codec="H.264"><![CDATA[https://iab-publicfiles.s3.amazonaws.com/vast/VAST-4.0-Short-Intro.mp4]]></MediaFile><MediaFile id="5244" delivery="progressive" type="video/mp4" bitrate="1000" width="854" height="480" minBitrate="700" maxBitrate="1500" scalable="1" maintainAspectRatio="1" codec="H.264"><![CDATA[https://iab-publicfiles.s3.amazonaws.com/vast/VAST-4.0-Short-Intro-mid-resolution.mp4]]></MediaFile><MediaFile id="5246" delivery="progressive" type="video/mp4" bitrate="600" width="640" height="360" minBitrate="500" maxBitrate="700" scalable="1" maintainAspectRatio="1" codec="H.264"><![CDATA[https://iab-publicfiles.s3.amazonaws.com/vast/VAST-4.0-Short-Intro-low-resolution.mp4]]></MediaFile></MediaFiles></Linear></Creative></Creatives></InLine></Ad></VAST>`, 103 NURL: "", 104 }, 105 want: ``, 106 wantError: errors.New("XML processing error: xml: end tag </InLine> does not match start tag <Error>"), 107 }, 108 { 109 name: "Inline Linear vastXML, no existing event tracker", 110 args: args{ 111 vastXML: `<VAST version="4.0" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.iab.com/VAST"><Ad id="20001" sequence="1" conditionalAd="false"><InLine><AdSystem version="4.0">iabtechlab</AdSystem><Error>http://example.com/error</Error><Impression id="Impression-ID">http://example.com/track/impression</Impression><Pricing model="cpm" currency="USD"><![CDATA[ 25.00 ]]></Pricing><AdTitle>Inline Simple Ad</AdTitle><AdVerifications></AdVerifications><Advertiser>IAB Sample Company</Advertiser><Category authority="http://www.iabtechlab.com/categoryauthority">AD CONTENT description category</Category><Creatives><Creative id="5480" sequence="1" adId="2447226"><UniversalAdId idRegistry="Ad-ID" idValue="8465">8465</UniversalAdId><Linear><Duration>00:00:16</Duration><MediaFiles><MediaFile id="5241" delivery="progressive" type="video/mp4" bitrate="2000" width="1280" height="720" minBitrate="1500" maxBitrate="2500" scalable="1" maintainAspectRatio="1" codec="H.264"><![CDATA[https://iab-publicfiles.s3.amazonaws.com/vast/VAST-4.0-Short-Intro.mp4]]></MediaFile><MediaFile id="5244" delivery="progressive" type="video/mp4" bitrate="1000" width="854" height="480" minBitrate="700" maxBitrate="1500" scalable="1" maintainAspectRatio="1" codec="H.264"><![CDATA[https://iab-publicfiles.s3.amazonaws.com/vast/VAST-4.0-Short-Intro-mid-resolution.mp4]]></MediaFile><MediaFile id="5246" delivery="progressive" type="video/mp4" bitrate="600" width="640" height="360" minBitrate="500" maxBitrate="700" scalable="1" maintainAspectRatio="1" codec="H.264"><![CDATA[https://iab-publicfiles.s3.amazonaws.com/vast/VAST-4.0-Short-Intro-low-resolution.mp4]]></MediaFile></MediaFiles></Linear></Creative></Creatives></InLine></Ad></VAST>`, 112 NURL: "", 113 }, 114 want: `<VAST version="4.0" xmlns:_xmlns="xmlns" _xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.iab.com/VAST"><Ad id="20001" sequence="1" conditionalAd="false"><InLine><AdSystem version="4.0"><![CDATA[iabtechlab]]></AdSystem><Error><![CDATA[http://example.com/error]]></Error><Error><![CDATA[http://errortracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Error><Impression id="Impression-ID"><![CDATA[http://example.com/track/impression]]></Impression><Impression><![CDATA[http://impressiontracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Impression><Pricing model="cpm" currency="USD"><![CDATA[25.00]]></Pricing><AdTitle><![CDATA[Inline Simple Ad]]></AdTitle><AdVerifications></AdVerifications><Advertiser><![CDATA[IAB Sample Company]]></Advertiser><Category authority="http://www.iabtechlab.com/categoryauthority"><![CDATA[AD CONTENT description category]]></Category><Creatives><Creative id="5480" sequence="1" adId="2447226"><UniversalAdId idRegistry="Ad-ID" idValue="8465"><![CDATA[8465]]></UniversalAdId><Linear><Duration><![CDATA[00:00:16]]></Duration><MediaFiles><MediaFile id="5241" delivery="progressive" type="video/mp4" bitrate="2000" width="1280" height="720" minBitrate="1500" maxBitrate="2500" scalable="1" maintainAspectRatio="1" codec="H.264"><![CDATA[https://iab-publicfiles.s3.amazonaws.com/vast/VAST-4.0-Short-Intro.mp4]]></MediaFile><MediaFile id="5244" delivery="progressive" type="video/mp4" bitrate="1000" width="854" height="480" minBitrate="700" maxBitrate="1500" scalable="1" maintainAspectRatio="1" codec="H.264"><![CDATA[https://iab-publicfiles.s3.amazonaws.com/vast/VAST-4.0-Short-Intro-mid-resolution.mp4]]></MediaFile><MediaFile id="5246" delivery="progressive" type="video/mp4" bitrate="600" width="640" height="360" minBitrate="500" maxBitrate="700" scalable="1" maintainAspectRatio="1" codec="H.264"><![CDATA[https://iab-publicfiles.s3.amazonaws.com/vast/VAST-4.0-Short-Intro-low-resolution.mp4]]></MediaFile></MediaFiles><VideoClicks><ClickTracking><![CDATA[http://videoclicktracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></ClickTracking></VideoClicks><TrackingEvents><Tracking event="firstQuartile"><![CDATA[http://eventracker1.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Tracking></TrackingEvents></Linear></Creative></Creatives></InLine></Ad></VAST>`, 115 }, 116 { 117 name: "Non Linear vastXML, no existing event tracker", 118 args: args{ 119 NURL: "", 120 vastXML: `<VAST version="4.0" xmlns="http://www.iab.com/VAST"><Ad id="20005" sequence="1" conditionalAd="false"><InLine><AdSystem version="4.0">iabtechlab</AdSystem><Extensions><Extension type="iab-Count"><total_available><![CDATA[ 2 ]]></total_available></Extension></Extensions><Pricing model="cpm" currency="USD"><![CDATA[ 25.00 ]]></Pricing><AdTitle><![CDATA[VAST 4.0 Pilot - Scenario 5]]></AdTitle><Creatives><Creative id="5480" sequence="1" adId="2447226"><UniversalAdId idRegistry="Ad-ID" idValue="8465">8465</UniversalAdId><NonLinearAds><NonLinear><StaticResource creativeType="image/png"><![CDATA[http://mms.businesswire.com/media/20150623005446/en/473787/21/iab_tech_lab.jpg]]></StaticResource></NonLinear></NonLinearAds></Creative></Creatives><Description><![CDATA[VAST 4.0 sample tag for Non Linear ad (i.e Overlay ad). Change the StaticResources to have a tag with your own content. Change NonLinear tag's parameters accordingly to view desired results.]]></Description></InLine></Ad></VAST>`, 121 }, 122 want: `<VAST version="4.0" xmlns="http://www.iab.com/VAST"><Ad id="20005" sequence="1" conditionalAd="false"><InLine><AdSystem version="4.0"><![CDATA[iabtechlab]]></AdSystem><Extensions><Extension type="iab-Count"><total_available><![CDATA[2]]></total_available></Extension></Extensions><Pricing model="cpm" currency="USD"><![CDATA[25.00]]></Pricing><AdTitle><![CDATA[VAST 4.0 Pilot - Scenario 5]]></AdTitle><Creatives><Creative id="5480" sequence="1" adId="2447226"><UniversalAdId idRegistry="Ad-ID" idValue="8465"><![CDATA[8465]]></UniversalAdId><NonLinearAds><NonLinear><StaticResource creativeType="image/png"><![CDATA[http://mms.businesswire.com/media/20150623005446/en/473787/21/iab_tech_lab.jpg]]></StaticResource><NonLinearClickTracking><![CDATA[http://nonlinearclicktracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></NonLinearClickTracking></NonLinear><TrackingEvents><Tracking event="firstQuartile"><![CDATA[http://eventracker1.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Tracking></TrackingEvents></NonLinearAds></Creative></Creatives><Description><![CDATA[VAST 4.0 sample tag for Non Linear ad (i.e Overlay ad). Change the StaticResources to have a tag with your own content. Change NonLinear tag's parameters accordingly to view desired results.]]></Description><Impression><![CDATA[http://impressiontracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Impression><Error><![CDATA[http://errortracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Error></InLine></Ad></VAST>`, 123 }, 124 { 125 name: "Wrapper Liner vastXML", 126 args: args{ 127 NURL: "", 128 vastXML: `<VAST version="4.0" xmlns="http://www.iab.com/VAST"><Ad id="20011" sequence="1" conditionalAd="false"><Wrapper followAdditionalWrappers="0" allowMultipleAds="1" fallbackOnNoAd="0"><AdSystem version="4.0">iabtechlab</AdSystem><Error>http://example.com/error</Error><Impression id="Impression-ID">http://example.com/track/impression</Impression><Creatives><Creative id="5480" sequence="1" adId="2447226"><CompanionAds><Companion id="1232" width="100" height="150" assetWidth="250" assetHeight="200" expandedWidth="350" expandedHeight="250" apiFramework="VPAID" adSlotID="3214" pxratio="1400"><StaticResource creativeType="image/png"><![CDATA[https://www.iab.com/wp-content/uploads/2014/09/iab-tech-lab-6-644x290.png]]></StaticResource><CompanionClickThrough><![CDATA[https://iabtechlab.com]]></CompanionClickThrough></Companion></CompanionAds></Creative></Creatives><VASTAdTagURI><![CDATA[https://raw.githubusercontent.com/InteractiveAdvertisingBureau/VAST_Samples/master/VAST%204.0%20Samples/Inline_Companion_Tag-test.xml]]></VASTAdTagURI></Wrapper></Ad></VAST>`, 129 }, 130 want: `<VAST version="4.0" xmlns="http://www.iab.com/VAST"><Ad id="20011" sequence="1" conditionalAd="false"><Wrapper followAdditionalWrappers="0" allowMultipleAds="1" fallbackOnNoAd="0"><AdSystem version="4.0"><![CDATA[iabtechlab]]></AdSystem><Error><![CDATA[http://example.com/error]]></Error><Error><![CDATA[http://errortracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Error><Impression id="Impression-ID"><![CDATA[http://example.com/track/impression]]></Impression><Impression><![CDATA[http://impressiontracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Impression><Creatives><Creative id="5480" sequence="1" adId="2447226"><CompanionAds><Companion id="1232" width="100" height="150" assetWidth="250" assetHeight="200" expandedWidth="350" expandedHeight="250" apiFramework="VPAID" adSlotID="3214" pxratio="1400"><StaticResource creativeType="image/png"><![CDATA[https://www.iab.com/wp-content/uploads/2014/09/iab-tech-lab-6-644x290.png]]></StaticResource><CompanionClickThrough><![CDATA[https://iabtechlab.com]]></CompanionClickThrough><CompanionClickThrough><![CDATA[http://companionclicktracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></CompanionClickThrough></Companion></CompanionAds></Creative></Creatives><VASTAdTagURI><![CDATA[https://raw.githubusercontent.com/InteractiveAdvertisingBureau/VAST_Samples/master/VAST%204.0%20Samples/Inline_Companion_Tag-test.xml]]></VASTAdTagURI></Wrapper></Ad></VAST>`, 131 }, 132 { 133 name: "Wapper companion vastXML", 134 args: args{ 135 NURL: "", 136 vastXML: `<VAST version="4.2" xmlns="http://www.iab.com/VAST"><Ad id="20011" sequence="1" ><Wrapper followAdditionalWrappers="0" allowMultipleAds="1" fallbackOnNoAd="0"><AdSystem version="4.0">iabtechlab</AdSystem><Error><![CDATA[https://example.com/error]]></Error><Impression id="Impression-ID"><![CDATA[https://example.com/track/impression]]></Impression><Creatives><Creative id="5480" sequence="1" adId="2447226"><CompanionAds><Companion id="1232" width="100" height="150" assetWidth="250" assetHeight="200" expandedWidth="350" expandedHeight="250" apiFramework="SIMID" adSlotId="3214" pxratio="1400"><StaticResource creativeType="image/png"><![CDATA[https://www.iab.com/wp-content/uploads/2014/09/iab-tech-lab-6-644x290.png]]></StaticResource><CompanionClickThrough><![CDATA[https://iabtechlab.com]]></CompanionClickThrough></Companion></CompanionAds></Creative></Creatives><VASTAdTagURI><![CDATA[https://raw.githubusercontent.com/InteractiveAdvertisingBureau/VAST_Samples/master/VAST%204.2%20Samples/Inline_Companion_Tag-test.xml]]></VASTAdTagURI></Wrapper></Ad></VAST>`, 137 }, 138 want: `<VAST version="4.2" xmlns="http://www.iab.com/VAST"><Ad id="20011" sequence="1"><Wrapper followAdditionalWrappers="0" allowMultipleAds="1" fallbackOnNoAd="0"><AdSystem version="4.0"><![CDATA[iabtechlab]]></AdSystem><Error><![CDATA[https://example.com/error]]></Error><Error><![CDATA[http://errortracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Error><Impression id="Impression-ID"><![CDATA[https://example.com/track/impression]]></Impression><Impression><![CDATA[http://impressiontracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Impression><Creatives><Creative id="5480" sequence="1" adId="2447226"><CompanionAds><Companion id="1232" width="100" height="150" assetWidth="250" assetHeight="200" expandedWidth="350" expandedHeight="250" apiFramework="SIMID" adSlotId="3214" pxratio="1400"><StaticResource creativeType="image/png"><![CDATA[https://www.iab.com/wp-content/uploads/2014/09/iab-tech-lab-6-644x290.png]]></StaticResource><CompanionClickThrough><![CDATA[https://iabtechlab.com]]></CompanionClickThrough><CompanionClickThrough><![CDATA[http://companionclicktracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></CompanionClickThrough></Companion></CompanionAds></Creative></Creatives><VASTAdTagURI><![CDATA[https://raw.githubusercontent.com/InteractiveAdvertisingBureau/VAST_Samples/master/VAST%204.2%20Samples/Inline_Companion_Tag-test.xml]]></VASTAdTagURI></Wrapper></Ad></VAST>`, 139 }, 140 { 141 name: "Wapper no companion vastXML", 142 args: args{ 143 NURL: "", 144 vastXML: `<VAST version="4.2" xmlns="http://www.iab.com/VAST"><Ad id="20011" sequence="1" ><Wrapper followAdditionalWrappers="0" allowMultipleAds="1" fallbackOnNoAd="0"><AdSystem version="4.0">iabtechlab</AdSystem><Error><![CDATA[https://example.com/error]]></Error><Impression id="Impression-ID"><![CDATA[https://example.com/track/impression]]></Impression><Creatives><Creative id="5480" sequence="1" adId="2447226"><CompanionAds></CompanionAds></Creative></Creatives><VASTAdTagURI><![CDATA[https://raw.githubusercontent.com/InteractiveAdvertisingBureau/VAST_Samples/master/VAST%204.2%20Samples/Inline_Companion_Tag-test.xml]]></VASTAdTagURI></Wrapper></Ad></VAST>`, 145 }, 146 want: `<VAST version="4.2" xmlns="http://www.iab.com/VAST"><Ad id="20011" sequence="1"><Wrapper followAdditionalWrappers="0" allowMultipleAds="1" fallbackOnNoAd="0"><AdSystem version="4.0"><![CDATA[iabtechlab]]></AdSystem><Error><![CDATA[https://example.com/error]]></Error><Error><![CDATA[http://errortracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Error><Impression id="Impression-ID"><![CDATA[https://example.com/track/impression]]></Impression><Impression><![CDATA[http://impressiontracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Impression><Creatives><Creative id="5480" sequence="1" adId="2447226"><CompanionAds><Companion><CompanionClickThrough><![CDATA[http://companionclicktracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></CompanionClickThrough></Companion></CompanionAds></Creative></Creatives><VASTAdTagURI><![CDATA[https://raw.githubusercontent.com/InteractiveAdvertisingBureau/VAST_Samples/master/VAST%204.2%20Samples/Inline_Companion_Tag-test.xml]]></VASTAdTagURI></Wrapper></Ad></VAST>`, 147 }, 148 { 149 name: "Inline Non Linear empty", 150 args: args{ 151 NURL: "", 152 vastXML: `<VAST version="4.2" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.iab.com/VAST"><Ad id="20001" ><InLine><AdSystem version="1">iabtechlab</AdSystem><Pricing model="cpm" currency="USD"><![CDATA[ 25.00 ]]></Pricing><AdServingId>a532d16d-4d7f-4440-bd29-2ec0e693fc80</AdServingId><AdTitle>iabtechlab video ad</AdTitle><Creatives><Creative id="5480" sequence="1" adId="2447226"><NonLinearAds></NonLinearAds></Creative></Creatives></InLine></Ad></VAST>`, 153 }, 154 want: `<VAST version="4.2" xmlns:_xmlns="xmlns" _xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.iab.com/VAST"><Ad id="20001"><InLine><AdSystem version="1"><![CDATA[iabtechlab]]></AdSystem><Pricing model="cpm" currency="USD"><![CDATA[25.00]]></Pricing><AdServingId><![CDATA[a532d16d-4d7f-4440-bd29-2ec0e693fc80]]></AdServingId><AdTitle><![CDATA[iabtechlab video ad]]></AdTitle><Creatives><Creative id="5480" sequence="1" adId="2447226"><NonLinearAds><TrackingEvents><Tracking event="firstQuartile"><![CDATA[http://eventracker1.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Tracking></TrackingEvents></NonLinearAds></Creative></Creatives><Impression><![CDATA[http://impressiontracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Impression><Error><![CDATA[http://errortracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Error></InLine></Ad></VAST>`, 155 }, 156 { 157 name: "Wrapper linear and non linear", 158 args: args{ 159 NURL: "", 160 vastXML: `<?xml version="1.0" encoding="UTF-8"?><VAST version="3.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../vast/vast3_draft.xsd"><Ad id="1" sequence="1"><Wrapper><AdSystem version="1.0">Test Ad Server</AdSystem><VASTAdTagURI><![CDATA[http://localhost/test/resources/vast/inlines/test_vast_inline_with-linear-ad.xml]]></VASTAdTagURI><Creatives><Creative><NonLinearAds></NonLinearAds></Creative><Creative><Linear><TrackingEvents><Tracking event="start"><![CDATA[http://example.com/start?d=[CACHEBUSTER]]]></Tracking><Tracking event="start"><![CDATA[http://example.com/start2?d=[CACHEBUSTER]]]></Tracking><Tracking event="firstQuartile"><![CDATA[http://example.com/q2?d=[CACHEBUSTER]]]></Tracking><Tracking event="midpoint"><![CDATA[http://example.com/q3?d=[CACHEBUSTER]]]></Tracking><Tracking event="thirdQuartile"><![CDATA[http://example.com/q4?d=[CACHEBUSTER]]]></Tracking><Tracking event="complete"><![CDATA[http://example.com/complete?d=[CACHEBUSTER]]]></Tracking></TrackingEvents><VideoClicks><ClickTracking id="video_click"><![CDATA[http://example.com/linear-video-click]]></ClickTracking><ClickTracking id="video_click"><![CDATA[http://example.com/linear-video-click2]]></ClickTracking><ClickTracking id="video_click"><![CDATA[http://example.com/linear-video-click3]]></ClickTracking><ClickTracking id="post_video_click"><![CDATA[http://example.com/linear-post-video-click]]></ClickTracking><ClickTracking id="post_video_click"><![CDATA[http://example.com/linear-post-video-click2]]></ClickTracking></VideoClicks></Linear></Creative></Creatives></Wrapper></Ad></VAST>`, 161 }, 162 want: `<?xml version="1.0" encoding="UTF-8"?><VAST version="3.0" xmlns:_xmlns="xmlns" _xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="xsi" xsi:noNamespaceSchemaLocation="../../vast/vast3_draft.xsd"><Ad id="1" sequence="1"><Wrapper><AdSystem version="1.0"><![CDATA[Test Ad Server]]></AdSystem><VASTAdTagURI><![CDATA[http://localhost/test/resources/vast/inlines/test_vast_inline_with-linear-ad.xml]]></VASTAdTagURI><Creatives><Creative><NonLinearAds><TrackingEvents><Tracking event="firstQuartile"><![CDATA[http://eventracker1.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Tracking></TrackingEvents><NonLinear><NonLinearClickTracking><![CDATA[http://nonlinearclicktracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></NonLinearClickTracking></NonLinear></NonLinearAds></Creative><Creative><Linear><TrackingEvents><Tracking event="firstQuartile"><![CDATA[http://eventracker1.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Tracking><Tracking event="start"><![CDATA[http://example.com/start?d=[CACHEBUSTER]]]></Tracking><Tracking event="start"><![CDATA[http://example.com/start2?d=[CACHEBUSTER]]]></Tracking><Tracking event="firstQuartile"><![CDATA[http://example.com/q2?d=[CACHEBUSTER]]]></Tracking><Tracking event="midpoint"><![CDATA[http://example.com/q3?d=[CACHEBUSTER]]]></Tracking><Tracking event="thirdQuartile"><![CDATA[http://example.com/q4?d=[CACHEBUSTER]]]></Tracking><Tracking event="complete"><![CDATA[http://example.com/complete?d=[CACHEBUSTER]]]></Tracking></TrackingEvents><VideoClicks><ClickTracking><![CDATA[http://videoclicktracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></ClickTracking><ClickTracking id="video_click"><![CDATA[http://example.com/linear-video-click]]></ClickTracking><ClickTracking id="video_click"><![CDATA[http://example.com/linear-video-click2]]></ClickTracking><ClickTracking id="video_click"><![CDATA[http://example.com/linear-video-click3]]></ClickTracking><ClickTracking id="post_video_click"><![CDATA[http://example.com/linear-post-video-click]]></ClickTracking><ClickTracking id="post_video_click"><![CDATA[http://example.com/linear-post-video-click2]]></ClickTracking></VideoClicks></Linear></Creative></Creatives><Impression><![CDATA[http://impressiontracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Impression><Error><![CDATA[http://errortracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Error></Wrapper></Ad></VAST>`, 163 }, 164 } 165 for _, tt := range tests { 166 t.Run(tt.name, func(t *testing.T) { 167 got, err := ti.InjectTracker(tt.args.vastXML, tt.args.NURL) 168 assert.Equal(t, tt.want, got, tt.name) 169 if tt.wantError != nil { 170 assert.EqualError(t, err, tt.wantError.Error()) 171 } 172 }) 173 } 174 } 175 176 func TestAddClickTrackingEvent(t *testing.T) { 177 tests := []struct { 178 name string 179 addParentTag bool 180 expected string 181 }{ 182 { 183 name: "With Parent Tag", 184 addParentTag: true, 185 expected: "<VideoClicks><ClickTracking><![CDATA[http://videoclicktracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></ClickTracking></VideoClicks>", 186 }, 187 { 188 name: "Without Parent Tag", 189 addParentTag: false, 190 expected: "<ClickTracking><![CDATA[http://videoclicktracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></ClickTracking>", 191 }, 192 } 193 194 for _, tt := range tests { 195 t.Run(tt.name, func(t *testing.T) { 196 var outputXML strings.Builder 197 b := macros.NewProvider(reqWrapper) 198 b.PopulateBidMacros(&entities.PbsOrtbBid{ 199 Bid: &openrtb2.Bid{ 200 ID: "bid123", 201 }, 202 }, "testSeat") 203 ti := NewTrackerInjector( 204 macros.NewStringIndexBasedReplacer(), 205 b, 206 VASTEvents{ 207 VideoClicks: []string{"http://videoclicktracker.com?macro1=##PBS-BIDID##¯o2=##PBS-APPBUNDLE##¯o3=##PBS-APPBUNDLE##¯o4=##PBS-PUBDOMAIN##¯o5=##PBS-PAGEURL##¯o6=##PBS-ACCOUNTID##¯o6=##PBS-LIMITADTRACKING##¯o7=##PBS-GDPRCONSENT##¯o8=##PBS-GDPRCONSENT##¯o9=##PBS-MACRO-CUSTOMMACR1CUST1##¯o10=##PBS-MACRO-CUSTOMMACR1CUST2##"}, 208 }, 209 ) 210 ti.addClickTrackingEvent(&outputXML, "testCreativeId", tt.addParentTag) 211 assert.Equal(t, tt.expected, outputXML.String(), tt.name) 212 }) 213 } 214 } 215 216 func TestAddImpressionTrackingEvent(t *testing.T) { 217 tests := []struct { 218 name string 219 addParentTag bool 220 expected string 221 }{ 222 { 223 name: "Add impression tag", 224 addParentTag: true, 225 expected: "<Impression><![CDATA[http://impressiontracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Impression>", 226 }, 227 } 228 for _, tt := range tests { 229 t.Run(tt.name, func(t *testing.T) { 230 var outputXML strings.Builder 231 b := macros.NewProvider(reqWrapper) 232 b.PopulateBidMacros(&entities.PbsOrtbBid{ 233 Bid: &openrtb2.Bid{ 234 ID: "bid123", 235 }, 236 }, "testSeat") 237 ti := NewTrackerInjector( 238 macros.NewStringIndexBasedReplacer(), 239 b, 240 VASTEvents{ 241 Impressions: []string{"http://impressiontracker.com?macro1=##PBS-BIDID##¯o2=##PBS-APPBUNDLE##¯o3=##PBS-APPBUNDLE##¯o4=##PBS-PUBDOMAIN##¯o5=##PBS-PAGEURL##¯o6=##PBS-ACCOUNTID##¯o6=##PBS-LIMITADTRACKING##¯o7=##PBS-GDPRCONSENT##¯o8=##PBS-GDPRCONSENT##¯o9=##PBS-MACRO-CUSTOMMACR1CUST1##¯o10=##PBS-MACRO-CUSTOMMACR1CUST2##"}, 242 }, 243 ) 244 ti.addImpressionTrackingEvent(&outputXML) 245 assert.Equal(t, tt.expected, outputXML.String(), tt.name) 246 }) 247 } 248 } 249 250 func TestAddErrorTrackingEvent(t *testing.T) { 251 tests := []struct { 252 name string 253 addParentTag bool 254 expected string 255 }{ 256 { 257 name: "Add impression tag", 258 addParentTag: true, 259 expected: "<Error><![CDATA[http://errortracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Error>", 260 }, 261 } 262 for _, tt := range tests { 263 t.Run(tt.name, func(t *testing.T) { 264 var outputXML strings.Builder 265 b := macros.NewProvider(reqWrapper) 266 b.PopulateBidMacros(&entities.PbsOrtbBid{ 267 Bid: &openrtb2.Bid{ 268 ID: "bid123", 269 }, 270 }, "testSeat") 271 ti := NewTrackerInjector( 272 macros.NewStringIndexBasedReplacer(), 273 b, 274 VASTEvents{ 275 Errors: []string{"http://errortracker.com?macro1=##PBS-BIDID##¯o2=##PBS-APPBUNDLE##¯o3=##PBS-APPBUNDLE##¯o4=##PBS-PUBDOMAIN##¯o5=##PBS-PAGEURL##¯o6=##PBS-ACCOUNTID##¯o6=##PBS-LIMITADTRACKING##¯o7=##PBS-GDPRCONSENT##¯o8=##PBS-GDPRCONSENT##¯o9=##PBS-MACRO-CUSTOMMACR1CUST1##¯o10=##PBS-MACRO-CUSTOMMACR1CUST2##"}, 276 }, 277 ) 278 ti.addErrorTrackingEvent(&outputXML) 279 assert.Equal(t, tt.expected, outputXML.String(), tt.name) 280 }) 281 } 282 } 283 284 func TestAddNonLinearClickTrackingEvent(t *testing.T) { 285 tests := []struct { 286 name string 287 addParentTag bool 288 expected string 289 }{ 290 { 291 name: "With Parent Tag", 292 addParentTag: true, 293 expected: "<NonLinear><NonLinearClickTracking><![CDATA[http://nonlinearclicktracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></NonLinearClickTracking></NonLinear>", 294 }, 295 { 296 name: "Without Parent Tag", 297 addParentTag: false, 298 expected: "<NonLinearClickTracking><![CDATA[http://nonlinearclicktracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></NonLinearClickTracking>", 299 }, 300 } 301 302 for _, tt := range tests { 303 t.Run(tt.name, func(t *testing.T) { 304 var outputXML strings.Builder 305 b := macros.NewProvider(reqWrapper) 306 b.PopulateBidMacros(&entities.PbsOrtbBid{ 307 Bid: &openrtb2.Bid{ 308 ID: "bid123", 309 }, 310 }, "testSeat") 311 ti := NewTrackerInjector( 312 macros.NewStringIndexBasedReplacer(), 313 b, 314 VASTEvents{ 315 NonLinearClickTracking: []string{"http://nonlinearclicktracker.com?macro1=##PBS-BIDID##¯o2=##PBS-APPBUNDLE##¯o3=##PBS-APPBUNDLE##¯o4=##PBS-PUBDOMAIN##¯o5=##PBS-PAGEURL##¯o6=##PBS-ACCOUNTID##¯o6=##PBS-LIMITADTRACKING##¯o7=##PBS-GDPRCONSENT##¯o8=##PBS-GDPRCONSENT##¯o9=##PBS-MACRO-CUSTOMMACR1CUST1##¯o10=##PBS-MACRO-CUSTOMMACR1CUST2##"}, 316 }, 317 ) 318 ti.addNonLinearClickTrackingEvent(&outputXML, "testCreativeId", tt.addParentTag) 319 assert.Equal(t, tt.expected, outputXML.String(), tt.name) 320 }) 321 } 322 } 323 324 func TestAddCompanionClickThroughEvent(t *testing.T) { 325 tests := []struct { 326 name string 327 addParentTag bool 328 expected string 329 }{ 330 { 331 name: "With Parent Tag", 332 addParentTag: true, 333 expected: "<Companion><CompanionClickThrough><![CDATA[http://companionclicktracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></CompanionClickThrough></Companion>", 334 }, 335 { 336 name: "Without Parent Tag", 337 addParentTag: false, 338 expected: "<CompanionClickThrough><![CDATA[http://companionclicktracker.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></CompanionClickThrough>", 339 }, 340 } 341 for _, tt := range tests { 342 t.Run(tt.name, func(t *testing.T) { 343 var outputXML strings.Builder 344 b := macros.NewProvider(reqWrapper) 345 b.PopulateBidMacros(&entities.PbsOrtbBid{ 346 Bid: &openrtb2.Bid{ 347 ID: "bid123", 348 }, 349 }, "testSeat") 350 ti := NewTrackerInjector( 351 macros.NewStringIndexBasedReplacer(), 352 b, 353 VASTEvents{ 354 CompanionClickThrough: []string{"http://companionclicktracker.com?macro1=##PBS-BIDID##¯o2=##PBS-APPBUNDLE##¯o3=##PBS-APPBUNDLE##¯o4=##PBS-PUBDOMAIN##¯o5=##PBS-PAGEURL##¯o6=##PBS-ACCOUNTID##¯o6=##PBS-LIMITADTRACKING##¯o7=##PBS-GDPRCONSENT##¯o8=##PBS-GDPRCONSENT##¯o9=##PBS-MACRO-CUSTOMMACR1CUST1##¯o10=##PBS-MACRO-CUSTOMMACR1CUST2##"}, 355 }, 356 ) 357 ti.addCompanionClickThroughEvent(&outputXML, "testCreativeId", tt.addParentTag) 358 assert.Equal(t, tt.expected, outputXML.String(), tt.name) 359 }) 360 } 361 } 362 363 func TestAddTrackingEvent(t *testing.T) { 364 tests := []struct { 365 name string 366 addParentTag bool 367 expected string 368 }{ 369 { 370 name: "With Parent Tag", 371 addParentTag: true, 372 expected: "<TrackingEvents><Tracking event=\"firstQuartile\"><![CDATA[http://eventracker1.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Tracking></TrackingEvents>", 373 }, 374 { 375 name: "Without Parent Tag", 376 addParentTag: false, 377 expected: "<Tracking event=\"firstQuartile\"><![CDATA[http://eventracker1.com?macro1=bid123¯o2=testbundle¯o3=testbundle¯o4=publishertestdomain¯o5=pageurltest¯o6=testpublisherID¯o6=1¯o7=1¯o8=1¯o9=¯o10=]]></Tracking>", 378 }, 379 } 380 for _, tt := range tests { 381 t.Run(tt.name, func(t *testing.T) { 382 var outputXML strings.Builder 383 b := macros.NewProvider(reqWrapper) 384 b.PopulateBidMacros(&entities.PbsOrtbBid{ 385 Bid: &openrtb2.Bid{ 386 ID: "bid123", 387 }, 388 }, "testSeat") 389 ti := NewTrackerInjector( 390 macros.NewStringIndexBasedReplacer(), 391 b, 392 VASTEvents{ 393 TrackingEvents: map[string][]string{"firstQuartile": {"http://eventracker1.com?macro1=##PBS-BIDID##¯o2=##PBS-APPBUNDLE##¯o3=##PBS-APPBUNDLE##¯o4=##PBS-PUBDOMAIN##¯o5=##PBS-PAGEURL##¯o6=##PBS-ACCOUNTID##¯o6=##PBS-LIMITADTRACKING##¯o7=##PBS-GDPRCONSENT##¯o8=##PBS-GDPRCONSENT##¯o9=##PBS-MACRO-CUSTOMMACR1CUST1##¯o10=##PBS-MACRO-CUSTOMMACR1CUST2##"}}, 394 }, 395 ) 396 ti.addTrackingEvent(&outputXML, "testCreativeId", tt.addParentTag) 397 assert.Equal(t, tt.expected, outputXML.String(), tt.name) 398 }) 399 } 400 } 401 402 func TestWriteTrackingEvent(t *testing.T) { 403 tests := []struct { 404 name string 405 urls []string 406 startTag string 407 endTag string 408 creativeId string 409 eventType string 410 vastEvent string 411 expectedXML string 412 }{ 413 { 414 name: "Single URL", 415 urls: []string{"http://tracker.com"}, 416 startTag: "<Tracking>", 417 endTag: "</Tracking>", 418 creativeId: "123", 419 eventType: "start", 420 vastEvent: "tracking", 421 expectedXML: "<Tracking>http://tracker.com</Tracking>", 422 }, 423 { 424 name: "Multiple URL", 425 urls: []string{"http://tracker1.com", "http://tracker2.com"}, 426 startTag: "<Tracking>", 427 endTag: "</Tracking>", 428 creativeId: "123", 429 eventType: "start", 430 vastEvent: "tracking", 431 expectedXML: "<Tracking>http://tracker1.com</Tracking><Tracking>http://tracker2.com</Tracking>", 432 }, 433 } 434 435 for _, tt := range tests { 436 t.Run(tt.name, func(t *testing.T) { 437 var outputXML strings.Builder 438 b := macros.NewProvider(reqWrapper) 439 b.PopulateBidMacros(&entities.PbsOrtbBid{ 440 Bid: &openrtb2.Bid{ 441 ID: "bid123", 442 }, 443 }, "testSeat") 444 ti := NewTrackerInjector( 445 macros.NewStringIndexBasedReplacer(), 446 b, 447 VASTEvents{ 448 TrackingEvents: map[string][]string{"firstQuartile": {"http://eventracker1.com?macro1=##PBS-BIDID##¯o2=##PBS-APPBUNDLE##¯o3=##PBS-APPBUNDLE##¯o4=##PBS-PUBDOMAIN##¯o5=##PBS-PAGEURL##¯o6=##PBS-ACCOUNTID##¯o6=##PBS-LIMITADTRACKING##¯o7=##PBS-GDPRCONSENT##¯o8=##PBS-GDPRCONSENT##¯o9=##PBS-MACRO-CUSTOMMACR1CUST1##¯o10=##PBS-MACRO-CUSTOMMACR1CUST2##"}}, 449 }, 450 ) 451 ti.writeTrackingEvent(tt.urls, &outputXML, tt.startTag, tt.endTag, tt.creativeId, tt.eventType, tt.vastEvent) 452 assert.Equal(t, tt.expectedXML, outputXML.String(), tt.name) 453 }) 454 } 455 }