github.com/prebid/prebid-server/v2@v2.18.0/endpoints/openrtb2/interstitial_test.go (about) 1 package openrtb2 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/prebid/openrtb/v20/openrtb2" 8 "github.com/prebid/prebid-server/v2/openrtb_ext" 9 "github.com/stretchr/testify/assert" 10 ) 11 12 var request = &openrtb2.BidRequest{ 13 ID: "some-id", 14 Imp: []openrtb2.Imp{ 15 { 16 ID: "my-imp-id", 17 Banner: &openrtb2.Banner{ 18 Format: []openrtb2.Format{ 19 { 20 W: 300, 21 H: 600, 22 }, 23 }, 24 }, 25 Instl: 1, 26 Ext: json.RawMessage(`{"appnexus": {"placementId": 12883451}}`), 27 }, 28 }, 29 Device: &openrtb2.Device{ 30 H: 640, 31 W: 320, 32 Ext: json.RawMessage(`{"prebid": {"interstitial": {"minwidthperc": 60, "minheightperc": 60}}}`), 33 }, 34 } 35 36 var requestWithoutPrebidDeviceExt = &openrtb2.BidRequest{ 37 ID: "some-id", 38 Imp: []openrtb2.Imp{ 39 { 40 ID: "my-imp-id", 41 Banner: &openrtb2.Banner{ 42 Format: []openrtb2.Format{ 43 { 44 W: 300, 45 H: 600, 46 }, 47 }, 48 }, 49 Instl: 1, 50 Ext: json.RawMessage(`{"appnexus": {"placementId": 12883451}}`), 51 }, 52 }, 53 Device: &openrtb2.Device{ 54 H: 640, 55 W: 320, 56 Ext: json.RawMessage(`{"field": 1}`), 57 }, 58 } 59 60 func TestInterstitial(t *testing.T) { 61 myRequest := request 62 if err := processInterstitials(&openrtb_ext.RequestWrapper{BidRequest: myRequest}); err != nil { 63 t.Fatalf("Error processing interstitials: %v", err) 64 } 65 targetFormat := []openrtb2.Format{ 66 { 67 W: 300, 68 H: 600, 69 }, 70 { 71 W: 250, 72 H: 600, 73 }, 74 { 75 W: 300, 76 H: 480, 77 }, 78 { 79 W: 180, 80 H: 500, 81 }, 82 { 83 W: 300, 84 H: 500, 85 }, 86 { 87 W: 300, 88 H: 431, 89 }, 90 { 91 W: 300, 92 H: 430, 93 }, 94 { 95 W: 200, 96 H: 600, 97 }, 98 { 99 W: 202, 100 H: 600, 101 }, 102 { 103 W: 300, 104 H: 360, 105 }, 106 } 107 assert.Equal(t, targetFormat, myRequest.Imp[0].Banner.Format) 108 109 } 110 111 func TestInterstitialWithoutPrebidDeviceExt(t *testing.T) { 112 myRequest := requestWithoutPrebidDeviceExt 113 if err := processInterstitials(&openrtb_ext.RequestWrapper{BidRequest: myRequest}); err != nil { 114 t.Fatalf("Error processing interstitials: %v", err) 115 } 116 targetFormat := []openrtb2.Format{ 117 { 118 W: 300, 119 H: 600, 120 }, 121 } 122 assert.Equal(t, targetFormat, myRequest.Imp[0].Banner.Format) 123 }