github.com/prebid/prebid-server@v0.275.0/openrtb_ext/floors_test.go (about) 1 package openrtb_ext 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 ) 8 9 func getFlag(in bool) *bool { 10 return &in 11 } 12 13 func TestPriceFloorRulesGetEnforcePBS(t *testing.T) { 14 tests := []struct { 15 name string 16 floors *PriceFloorRules 17 want bool 18 }{ 19 { 20 name: "EnforcePBS_Enabled", 21 floors: &PriceFloorRules{ 22 Enabled: getFlag(true), 23 Enforcement: &PriceFloorEnforcement{ 24 EnforcePBS: getFlag(true), 25 }, 26 }, 27 want: true, 28 }, 29 { 30 name: "EnforcePBS_NotProvided", 31 floors: &PriceFloorRules{ 32 Enabled: getFlag(true), 33 Enforcement: &PriceFloorEnforcement{}, 34 }, 35 want: true, 36 }, 37 { 38 name: "EnforcePBS_Disabled", 39 floors: &PriceFloorRules{ 40 Enabled: getFlag(true), 41 Enforcement: &PriceFloorEnforcement{ 42 EnforcePBS: getFlag(false), 43 }, 44 }, 45 want: false, 46 }, 47 } 48 for _, tt := range tests { 49 t.Run(tt.name, func(t *testing.T) { 50 got := tt.floors.GetEnforcePBS() 51 assert.Equal(t, tt.want, got, tt.name) 52 }) 53 } 54 } 55 56 func TestPriceFloorRulesGetFloorsSkippedFlag(t *testing.T) { 57 tests := []struct { 58 name string 59 floors *PriceFloorRules 60 want bool 61 }{ 62 { 63 name: "Skipped_true", 64 floors: &PriceFloorRules{ 65 Enabled: getFlag(true), 66 Skipped: getFlag(true), 67 }, 68 want: true, 69 }, 70 { 71 name: "Skipped_false", 72 floors: &PriceFloorRules{ 73 Enabled: getFlag(true), 74 Skipped: getFlag(false), 75 }, 76 want: false, 77 }, 78 { 79 name: "Skipped_NotProvided", 80 floors: &PriceFloorRules{ 81 Enabled: getFlag(true), 82 }, 83 want: false, 84 }, 85 } 86 87 for _, tt := range tests { 88 t.Run(tt.name, func(t *testing.T) { 89 got := tt.floors.GetFloorsSkippedFlag() 90 assert.Equal(t, tt.want, got, tt.name) 91 }) 92 } 93 } 94 95 func TestPriceFloorRulesGetEnforceRate(t *testing.T) { 96 tests := []struct { 97 name string 98 floors *PriceFloorRules 99 want int 100 }{ 101 { 102 name: "EnforceRate_100", 103 floors: &PriceFloorRules{ 104 Enabled: getFlag(true), 105 Enforcement: &PriceFloorEnforcement{ 106 EnforcePBS: getFlag(true), 107 EnforceRate: 100, 108 }, 109 }, 110 want: 100, 111 }, 112 { 113 name: "EnforceRate_0", 114 floors: &PriceFloorRules{ 115 Enabled: getFlag(true), 116 Enforcement: &PriceFloorEnforcement{ 117 EnforcePBS: getFlag(true), 118 EnforceRate: 0, 119 }, 120 }, 121 want: 0, 122 }, 123 { 124 name: "EnforceRate_NotProvided", 125 floors: &PriceFloorRules{ 126 Enabled: getFlag(true), 127 }, 128 want: 0, 129 }, 130 } 131 132 for _, tt := range tests { 133 t.Run(tt.name, func(t *testing.T) { 134 got := tt.floors.GetEnforceRate() 135 assert.Equal(t, tt.want, got, tt.name) 136 }) 137 } 138 } 139 140 func TestPriceFloorRulesGetEnforceDealsFlag(t *testing.T) { 141 tests := []struct { 142 name string 143 floors *PriceFloorRules 144 want bool 145 }{ 146 { 147 name: "FloorDeals_true", 148 floors: &PriceFloorRules{ 149 Enabled: getFlag(true), 150 Enforcement: &PriceFloorEnforcement{ 151 EnforcePBS: getFlag(true), 152 EnforceRate: 0, 153 FloorDeals: getFlag(true), 154 }, 155 }, 156 want: true, 157 }, 158 { 159 name: "FloorDeals_false", 160 floors: &PriceFloorRules{ 161 Enabled: getFlag(true), 162 Enforcement: &PriceFloorEnforcement{ 163 EnforcePBS: getFlag(true), 164 FloorDeals: getFlag(false), 165 }, 166 Skipped: getFlag(false), 167 }, 168 want: false, 169 }, 170 { 171 name: "FloorDeals_NotProvided", 172 floors: &PriceFloorRules{ 173 Enabled: getFlag(true), 174 }, 175 want: false, 176 }, 177 } 178 179 for _, tt := range tests { 180 t.Run(tt.name, func(t *testing.T) { 181 got := tt.floors.GetEnforceDealsFlag() 182 assert.Equal(t, tt.want, got, tt.name) 183 }) 184 } 185 } 186 187 func TestPriceFloorRulesGetEnabled(t *testing.T) { 188 tests := []struct { 189 name string 190 floors *PriceFloorRules 191 want bool 192 }{ 193 { 194 name: "Enabled_true", 195 floors: &PriceFloorRules{ 196 Enabled: getFlag(true), 197 }, 198 want: true, 199 }, 200 { 201 name: "Enabled_false", 202 floors: &PriceFloorRules{ 203 Enabled: getFlag(false), 204 }, 205 want: false, 206 }, 207 { 208 name: "Enabled_NotProvided", 209 floors: &PriceFloorRules{}, 210 want: true, 211 }, 212 } 213 214 for _, tt := range tests { 215 t.Run(tt.name, func(t *testing.T) { 216 got := tt.floors.GetEnabled() 217 assert.Equal(t, tt.want, got, tt.name) 218 }) 219 } 220 }