github.com/prebid/prebid-server/v2@v2.18.0/hooks/hookexecution/mocks_test.go (about) 1 package hookexecution 2 3 import ( 4 "context" 5 "errors" 6 "time" 7 8 "github.com/prebid/prebid-server/v2/hooks/hookstage" 9 "github.com/prebid/prebid-server/v2/openrtb_ext" 10 "github.com/prebid/prebid-server/v2/util/ptrutil" 11 ) 12 13 type mockUpdateHeaderEntrypointHook struct{} 14 15 func (e mockUpdateHeaderEntrypointHook) HandleEntrypointHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.EntrypointPayload) (hookstage.HookResult[hookstage.EntrypointPayload], error) { 16 c := hookstage.ChangeSet[hookstage.EntrypointPayload]{} 17 c.AddMutation(func(payload hookstage.EntrypointPayload) (hookstage.EntrypointPayload, error) { 18 payload.Request.Header.Add("foo", "bar") 19 return payload, nil 20 }, hookstage.MutationUpdate, "header", "foo") 21 22 return hookstage.HookResult[hookstage.EntrypointPayload]{ChangeSet: c}, nil 23 } 24 25 type mockUpdateQueryEntrypointHook struct{} 26 27 func (e mockUpdateQueryEntrypointHook) HandleEntrypointHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.EntrypointPayload) (hookstage.HookResult[hookstage.EntrypointPayload], error) { 28 c := hookstage.ChangeSet[hookstage.EntrypointPayload]{} 29 c.AddMutation(func(payload hookstage.EntrypointPayload) (hookstage.EntrypointPayload, error) { 30 params := payload.Request.URL.Query() 31 params.Add("foo", "baz") 32 payload.Request.URL.RawQuery = params.Encode() 33 return payload, nil 34 }, hookstage.MutationUpdate, "param", "foo") 35 36 return hookstage.HookResult[hookstage.EntrypointPayload]{ChangeSet: c}, nil 37 } 38 39 type mockUpdateBodyHook struct{} 40 41 func (e mockUpdateBodyHook) HandleEntrypointHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.EntrypointPayload) (hookstage.HookResult[hookstage.EntrypointPayload], error) { 42 c := hookstage.ChangeSet[hookstage.EntrypointPayload]{} 43 c.AddMutation( 44 func(payload hookstage.EntrypointPayload) (hookstage.EntrypointPayload, error) { 45 payload.Body = []byte(`{"name": "John", "last_name": "Doe", "foo": "bar"}`) 46 return payload, nil 47 }, hookstage.MutationUpdate, "body", "foo", 48 ).AddMutation( 49 func(payload hookstage.EntrypointPayload) (hookstage.EntrypointPayload, error) { 50 payload.Body = []byte(`{"last_name": "Doe", "foo": "bar"}`) 51 return payload, nil 52 }, hookstage.MutationDelete, "body", "name", 53 ) 54 55 return hookstage.HookResult[hookstage.EntrypointPayload]{ChangeSet: c}, nil 56 } 57 58 func (e mockUpdateBodyHook) HandleRawAuctionHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.RawAuctionRequestPayload) (hookstage.HookResult[hookstage.RawAuctionRequestPayload], error) { 59 c := hookstage.ChangeSet[hookstage.RawAuctionRequestPayload]{} 60 c.AddMutation( 61 func(payload hookstage.RawAuctionRequestPayload) (hookstage.RawAuctionRequestPayload, error) { 62 payload = []byte(`{"name": "John", "last_name": "Doe", "foo": "bar"}`) 63 return payload, nil 64 }, hookstage.MutationUpdate, "body", "foo", 65 ).AddMutation( 66 func(payload hookstage.RawAuctionRequestPayload) (hookstage.RawAuctionRequestPayload, error) { 67 payload = []byte(`{"last_name": "Doe", "foo": "bar"}`) 68 return payload, nil 69 }, hookstage.MutationDelete, "body", "name", 70 ) 71 72 return hookstage.HookResult[hookstage.RawAuctionRequestPayload]{ChangeSet: c}, nil 73 } 74 75 type mockRejectHook struct{} 76 77 func (e mockRejectHook) HandleEntrypointHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.EntrypointPayload) (hookstage.HookResult[hookstage.EntrypointPayload], error) { 78 return hookstage.HookResult[hookstage.EntrypointPayload]{Reject: true}, nil 79 } 80 81 func (e mockRejectHook) HandleRawAuctionHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.RawAuctionRequestPayload) (hookstage.HookResult[hookstage.RawAuctionRequestPayload], error) { 82 return hookstage.HookResult[hookstage.RawAuctionRequestPayload]{Reject: true}, nil 83 } 84 85 func (e mockRejectHook) HandleProcessedAuctionHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.ProcessedAuctionRequestPayload) (hookstage.HookResult[hookstage.ProcessedAuctionRequestPayload], error) { 86 return hookstage.HookResult[hookstage.ProcessedAuctionRequestPayload]{Reject: true}, nil 87 } 88 89 func (e mockRejectHook) HandleBidderRequestHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.BidderRequestPayload) (hookstage.HookResult[hookstage.BidderRequestPayload], error) { 90 return hookstage.HookResult[hookstage.BidderRequestPayload]{Reject: true}, nil 91 } 92 93 func (e mockRejectHook) HandleRawBidderResponseHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.RawBidderResponsePayload) (hookstage.HookResult[hookstage.RawBidderResponsePayload], error) { 94 return hookstage.HookResult[hookstage.RawBidderResponsePayload]{Reject: true}, nil 95 } 96 97 func (e mockRejectHook) HandleAllProcessedBidResponsesHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.AllProcessedBidResponsesPayload) (hookstage.HookResult[hookstage.AllProcessedBidResponsesPayload], error) { 98 return hookstage.HookResult[hookstage.AllProcessedBidResponsesPayload]{Reject: true}, nil 99 } 100 101 func (e mockRejectHook) HandleAuctionResponseHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.AuctionResponsePayload) (hookstage.HookResult[hookstage.AuctionResponsePayload], error) { 102 return hookstage.HookResult[hookstage.AuctionResponsePayload]{Reject: true}, nil 103 } 104 105 type mockTimeoutHook struct{} 106 107 func (e mockTimeoutHook) HandleEntrypointHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.EntrypointPayload) (hookstage.HookResult[hookstage.EntrypointPayload], error) { 108 time.Sleep(20 * time.Millisecond) 109 c := hookstage.ChangeSet[hookstage.EntrypointPayload]{} 110 c.AddMutation(func(payload hookstage.EntrypointPayload) (hookstage.EntrypointPayload, error) { 111 params := payload.Request.URL.Query() 112 params.Add("bar", "foo") 113 payload.Request.URL.RawQuery = params.Encode() 114 return payload, nil 115 }, hookstage.MutationUpdate, "param", "bar") 116 117 return hookstage.HookResult[hookstage.EntrypointPayload]{ChangeSet: c}, nil 118 } 119 120 func (e mockTimeoutHook) HandleRawAuctionHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.RawAuctionRequestPayload) (hookstage.HookResult[hookstage.RawAuctionRequestPayload], error) { 121 time.Sleep(20 * time.Millisecond) 122 c := hookstage.ChangeSet[hookstage.RawAuctionRequestPayload]{} 123 c.AddMutation(func(payload hookstage.RawAuctionRequestPayload) (hookstage.RawAuctionRequestPayload, error) { 124 payload = []byte(`{"last_name": "Doe", "foo": "bar", "address": "A st."}`) 125 return payload, nil 126 }, hookstage.MutationUpdate, "param", "address") 127 128 return hookstage.HookResult[hookstage.RawAuctionRequestPayload]{ChangeSet: c}, nil 129 } 130 131 func (e mockTimeoutHook) HandleProcessedAuctionHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.ProcessedAuctionRequestPayload) (hookstage.HookResult[hookstage.ProcessedAuctionRequestPayload], error) { 132 time.Sleep(20 * time.Millisecond) 133 c := hookstage.ChangeSet[hookstage.ProcessedAuctionRequestPayload]{} 134 c.AddMutation(func(payload hookstage.ProcessedAuctionRequestPayload) (hookstage.ProcessedAuctionRequestPayload, error) { 135 payload.Request.User.CustomData = "some-custom-data" 136 return payload, nil 137 }, hookstage.MutationUpdate, "bidRequest", "user.customData") 138 139 return hookstage.HookResult[hookstage.ProcessedAuctionRequestPayload]{ChangeSet: c}, nil 140 } 141 142 func (e mockTimeoutHook) HandleBidderRequestHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.BidderRequestPayload) (hookstage.HookResult[hookstage.BidderRequestPayload], error) { 143 time.Sleep(20 * time.Millisecond) 144 c := hookstage.ChangeSet[hookstage.BidderRequestPayload]{} 145 c.AddMutation(func(payload hookstage.BidderRequestPayload) (hookstage.BidderRequestPayload, error) { 146 payload.Request.User.CustomData = "some-custom-data" 147 return payload, nil 148 }, hookstage.MutationUpdate, "bidRequest", "user.customData") 149 150 return hookstage.HookResult[hookstage.BidderRequestPayload]{ChangeSet: c}, nil 151 } 152 153 func (e mockTimeoutHook) HandleRawBidderResponseHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.RawBidderResponsePayload) (hookstage.HookResult[hookstage.RawBidderResponsePayload], error) { 154 time.Sleep(20 * time.Millisecond) 155 c := hookstage.ChangeSet[hookstage.RawBidderResponsePayload]{} 156 c.AddMutation(func(payload hookstage.RawBidderResponsePayload) (hookstage.RawBidderResponsePayload, error) { 157 payload.Bids[0].BidMeta = &openrtb_ext.ExtBidPrebidMeta{AdapterCode: "new-code"} 158 return payload, nil 159 }, hookstage.MutationUpdate, "bidderResponse", "bidMeta.AdapterCode") 160 161 return hookstage.HookResult[hookstage.RawBidderResponsePayload]{ChangeSet: c}, nil 162 } 163 164 func (e mockTimeoutHook) HandleAllProcessedBidResponsesHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.AllProcessedBidResponsesPayload) (hookstage.HookResult[hookstage.AllProcessedBidResponsesPayload], error) { 165 time.Sleep(20 * time.Millisecond) 166 c := hookstage.ChangeSet[hookstage.AllProcessedBidResponsesPayload]{} 167 c.AddMutation(func(payload hookstage.AllProcessedBidResponsesPayload) (hookstage.AllProcessedBidResponsesPayload, error) { 168 payload.Responses["some-bidder"].Bids[0].BidMeta = &openrtb_ext.ExtBidPrebidMeta{AdapterCode: "new-code"} 169 return payload, nil 170 }, hookstage.MutationUpdate, "processedBidderResponse", "bidMeta.AdapterCode") 171 172 return hookstage.HookResult[hookstage.AllProcessedBidResponsesPayload]{ChangeSet: c}, nil 173 } 174 175 func (e mockTimeoutHook) HandleAuctionResponseHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.AuctionResponsePayload) (hookstage.HookResult[hookstage.AuctionResponsePayload], error) { 176 time.Sleep(2 * time.Millisecond) 177 c := hookstage.ChangeSet[hookstage.AuctionResponsePayload]{} 178 c.AddMutation(func(payload hookstage.AuctionResponsePayload) (hookstage.AuctionResponsePayload, error) { 179 payload.BidResponse.Ext = []byte("another-byte") 180 return payload, nil 181 }, hookstage.MutationUpdate, "auctionResponse", "bidResponse.Ext") 182 183 return hookstage.HookResult[hookstage.AuctionResponsePayload]{ChangeSet: c}, nil 184 } 185 186 type mockModuleContextHook struct { 187 key, val string 188 } 189 190 func (e mockModuleContextHook) HandleEntrypointHook(_ context.Context, miCtx hookstage.ModuleInvocationContext, _ hookstage.EntrypointPayload) (hookstage.HookResult[hookstage.EntrypointPayload], error) { 191 miCtx.ModuleContext = map[string]interface{}{e.key: e.val} 192 return hookstage.HookResult[hookstage.EntrypointPayload]{ModuleContext: miCtx.ModuleContext}, nil 193 } 194 195 func (e mockModuleContextHook) HandleRawAuctionHook(_ context.Context, miCtx hookstage.ModuleInvocationContext, _ hookstage.RawAuctionRequestPayload) (hookstage.HookResult[hookstage.RawAuctionRequestPayload], error) { 196 miCtx.ModuleContext = map[string]interface{}{e.key: e.val} 197 return hookstage.HookResult[hookstage.RawAuctionRequestPayload]{ModuleContext: miCtx.ModuleContext}, nil 198 } 199 200 func (e mockModuleContextHook) HandleProcessedAuctionHook(_ context.Context, miCtx hookstage.ModuleInvocationContext, _ hookstage.ProcessedAuctionRequestPayload) (hookstage.HookResult[hookstage.ProcessedAuctionRequestPayload], error) { 201 miCtx.ModuleContext = map[string]interface{}{e.key: e.val} 202 return hookstage.HookResult[hookstage.ProcessedAuctionRequestPayload]{ModuleContext: miCtx.ModuleContext}, nil 203 } 204 205 func (e mockModuleContextHook) HandleBidderRequestHook(_ context.Context, miCtx hookstage.ModuleInvocationContext, _ hookstage.BidderRequestPayload) (hookstage.HookResult[hookstage.BidderRequestPayload], error) { 206 miCtx.ModuleContext = map[string]interface{}{e.key: e.val} 207 return hookstage.HookResult[hookstage.BidderRequestPayload]{ModuleContext: miCtx.ModuleContext}, nil 208 } 209 210 func (e mockModuleContextHook) HandleRawBidderResponseHook(_ context.Context, miCtx hookstage.ModuleInvocationContext, _ hookstage.RawBidderResponsePayload) (hookstage.HookResult[hookstage.RawBidderResponsePayload], error) { 211 miCtx.ModuleContext = map[string]interface{}{e.key: e.val} 212 return hookstage.HookResult[hookstage.RawBidderResponsePayload]{ModuleContext: miCtx.ModuleContext}, nil 213 } 214 215 func (e mockModuleContextHook) HandleAllProcessedBidResponsesHook(_ context.Context, miCtx hookstage.ModuleInvocationContext, _ hookstage.AllProcessedBidResponsesPayload) (hookstage.HookResult[hookstage.AllProcessedBidResponsesPayload], error) { 216 miCtx.ModuleContext = map[string]interface{}{e.key: e.val} 217 return hookstage.HookResult[hookstage.AllProcessedBidResponsesPayload]{ModuleContext: miCtx.ModuleContext}, nil 218 } 219 220 func (e mockModuleContextHook) HandleAuctionResponseHook(_ context.Context, miCtx hookstage.ModuleInvocationContext, _ hookstage.AuctionResponsePayload) (hookstage.HookResult[hookstage.AuctionResponsePayload], error) { 221 miCtx.ModuleContext = map[string]interface{}{e.key: e.val} 222 return hookstage.HookResult[hookstage.AuctionResponsePayload]{ModuleContext: miCtx.ModuleContext}, nil 223 } 224 225 type mockFailureHook struct{} 226 227 func (h mockFailureHook) HandleEntrypointHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.EntrypointPayload) (hookstage.HookResult[hookstage.EntrypointPayload], error) { 228 return hookstage.HookResult[hookstage.EntrypointPayload]{}, FailureError{Message: "attribute not found"} 229 } 230 231 func (h mockFailureHook) HandleRawAuctionHook(_ context.Context, miCtx hookstage.ModuleInvocationContext, _ hookstage.RawAuctionRequestPayload) (hookstage.HookResult[hookstage.RawAuctionRequestPayload], error) { 232 return hookstage.HookResult[hookstage.RawAuctionRequestPayload]{}, FailureError{Message: "attribute not found"} 233 } 234 235 func (h mockFailureHook) HandleBidderRequestHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.BidderRequestPayload) (hookstage.HookResult[hookstage.BidderRequestPayload], error) { 236 return hookstage.HookResult[hookstage.BidderRequestPayload]{}, FailureError{Message: "attribute not found"} 237 } 238 239 func (h mockFailureHook) HandleAllProcessedBidResponsesHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.AllProcessedBidResponsesPayload) (hookstage.HookResult[hookstage.AllProcessedBidResponsesPayload], error) { 240 return hookstage.HookResult[hookstage.AllProcessedBidResponsesPayload]{}, FailureError{Message: "attribute not found"} 241 } 242 243 type mockErrorHook struct{} 244 245 func (h mockErrorHook) HandleEntrypointHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.EntrypointPayload) (hookstage.HookResult[hookstage.EntrypointPayload], error) { 246 return hookstage.HookResult[hookstage.EntrypointPayload]{}, errors.New("unexpected error") 247 } 248 249 func (h mockErrorHook) HandleRawAuctionHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.RawAuctionRequestPayload) (hookstage.HookResult[hookstage.RawAuctionRequestPayload], error) { 250 return hookstage.HookResult[hookstage.RawAuctionRequestPayload]{}, errors.New("unexpected error") 251 } 252 253 func (h mockErrorHook) HandleBidderRequestHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.BidderRequestPayload) (hookstage.HookResult[hookstage.BidderRequestPayload], error) { 254 return hookstage.HookResult[hookstage.BidderRequestPayload]{}, errors.New("unexpected error") 255 } 256 257 func (h mockErrorHook) HandleAllProcessedBidResponsesHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.AllProcessedBidResponsesPayload) (hookstage.HookResult[hookstage.AllProcessedBidResponsesPayload], error) { 258 return hookstage.HookResult[hookstage.AllProcessedBidResponsesPayload]{}, errors.New("unexpected error") 259 } 260 261 func (h mockErrorHook) HandleAuctionResponseHook(_ context.Context, miCtx hookstage.ModuleInvocationContext, _ hookstage.AuctionResponsePayload) (hookstage.HookResult[hookstage.AuctionResponsePayload], error) { 262 return hookstage.HookResult[hookstage.AuctionResponsePayload]{}, errors.New("unexpected error") 263 } 264 265 type mockFailedMutationHook struct{} 266 267 func (h mockFailedMutationHook) HandleEntrypointHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.EntrypointPayload) (hookstage.HookResult[hookstage.EntrypointPayload], error) { 268 changeSet := hookstage.ChangeSet[hookstage.EntrypointPayload]{} 269 changeSet.AddMutation(func(payload hookstage.EntrypointPayload) (hookstage.EntrypointPayload, error) { 270 return payload, errors.New("key not found") 271 }, hookstage.MutationUpdate, "header", "foo") 272 273 return hookstage.HookResult[hookstage.EntrypointPayload]{ChangeSet: changeSet}, nil 274 } 275 276 func (h mockFailedMutationHook) HandleRawAuctionHook(_ context.Context, miCtx hookstage.ModuleInvocationContext, _ hookstage.RawAuctionRequestPayload) (hookstage.HookResult[hookstage.RawAuctionRequestPayload], error) { 277 changeSet := hookstage.ChangeSet[hookstage.RawAuctionRequestPayload]{} 278 changeSet.AddMutation(func(payload hookstage.RawAuctionRequestPayload) (hookstage.RawAuctionRequestPayload, error) { 279 return payload, errors.New("key not found") 280 }, hookstage.MutationUpdate, "header", "foo") 281 282 return hookstage.HookResult[hookstage.RawAuctionRequestPayload]{ChangeSet: changeSet}, nil 283 } 284 285 func (h mockFailedMutationHook) HandleBidderRequestHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.BidderRequestPayload) (hookstage.HookResult[hookstage.BidderRequestPayload], error) { 286 changeSet := hookstage.ChangeSet[hookstage.BidderRequestPayload]{} 287 changeSet.AddMutation(func(payload hookstage.BidderRequestPayload) (hookstage.BidderRequestPayload, error) { 288 return payload, errors.New("key not found") 289 }, hookstage.MutationUpdate, "header", "foo") 290 291 return hookstage.HookResult[hookstage.BidderRequestPayload]{ChangeSet: changeSet}, nil 292 } 293 294 func (h mockFailedMutationHook) HandleAllProcessedBidResponsesHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.AllProcessedBidResponsesPayload) (hookstage.HookResult[hookstage.AllProcessedBidResponsesPayload], error) { 295 changeSet := hookstage.ChangeSet[hookstage.AllProcessedBidResponsesPayload]{} 296 changeSet.AddMutation(func(payload hookstage.AllProcessedBidResponsesPayload) (hookstage.AllProcessedBidResponsesPayload, error) { 297 return payload, errors.New("key not found") 298 }, hookstage.MutationUpdate, "some-bidder", "bids[0]", "deal_priority") 299 300 return hookstage.HookResult[hookstage.AllProcessedBidResponsesPayload]{ChangeSet: changeSet}, nil 301 } 302 303 type mockUpdateBidRequestHook struct{} 304 305 func (e mockUpdateBidRequestHook) HandleProcessedAuctionHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.ProcessedAuctionRequestPayload) (hookstage.HookResult[hookstage.ProcessedAuctionRequestPayload], error) { 306 c := hookstage.ChangeSet[hookstage.ProcessedAuctionRequestPayload]{} 307 c.AddMutation( 308 func(payload hookstage.ProcessedAuctionRequestPayload) (hookstage.ProcessedAuctionRequestPayload, error) { 309 payload.Request.User.Yob = 2000 310 userExt, err := payload.Request.GetUserExt() 311 if err != nil { 312 return payload, err 313 } 314 newPrebidExt := &openrtb_ext.ExtUserPrebid{ 315 BuyerUIDs: map[string]string{"some": "id"}, 316 } 317 userExt.SetPrebid(newPrebidExt) 318 return payload, nil 319 }, hookstage.MutationUpdate, "bidRequest", "user.yob", 320 ).AddMutation( 321 func(payload hookstage.ProcessedAuctionRequestPayload) (hookstage.ProcessedAuctionRequestPayload, error) { 322 payload.Request.User.Consent = "true" 323 return payload, nil 324 }, hookstage.MutationUpdate, "bidRequest", "user.consent", 325 ) 326 327 return hookstage.HookResult[hookstage.ProcessedAuctionRequestPayload]{ChangeSet: c}, nil 328 } 329 330 func (e mockUpdateBidRequestHook) HandleBidderRequestHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.BidderRequestPayload) (hookstage.HookResult[hookstage.BidderRequestPayload], error) { 331 c := hookstage.ChangeSet[hookstage.BidderRequestPayload]{} 332 c.AddMutation( 333 func(payload hookstage.BidderRequestPayload) (hookstage.BidderRequestPayload, error) { 334 user := ptrutil.Clone(payload.Request.User) 335 user.Yob = 2000 336 payload.Request.User = user 337 return payload, nil 338 }, hookstage.MutationUpdate, "bidRequest", "user.yob", 339 ).AddMutation( 340 func(payload hookstage.BidderRequestPayload) (hookstage.BidderRequestPayload, error) { 341 user := ptrutil.Clone(payload.Request.User) 342 user.Consent = "true" 343 payload.Request.User = user 344 return payload, nil 345 }, hookstage.MutationUpdate, "bidRequest", "user.consent", 346 ) 347 348 return hookstage.HookResult[hookstage.BidderRequestPayload]{ChangeSet: c}, nil 349 } 350 351 type mockUpdateBidderResponseHook struct{} 352 353 func (e mockUpdateBidderResponseHook) HandleRawBidderResponseHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.RawBidderResponsePayload) (hookstage.HookResult[hookstage.RawBidderResponsePayload], error) { 354 c := hookstage.ChangeSet[hookstage.RawBidderResponsePayload]{} 355 c.AddMutation( 356 func(payload hookstage.RawBidderResponsePayload) (hookstage.RawBidderResponsePayload, error) { 357 payload.Bids[0].DealPriority = 10 358 return payload, nil 359 }, hookstage.MutationUpdate, "bidderResponse", "bid.deal-priority", 360 ) 361 362 return hookstage.HookResult[hookstage.RawBidderResponsePayload]{ChangeSet: c}, nil 363 } 364 365 type mockUpdateBiddersResponsesHook struct{} 366 367 func (e mockUpdateBiddersResponsesHook) HandleAllProcessedBidResponsesHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.AllProcessedBidResponsesPayload) (hookstage.HookResult[hookstage.AllProcessedBidResponsesPayload], error) { 368 c := hookstage.ChangeSet[hookstage.AllProcessedBidResponsesPayload]{} 369 c.AddMutation( 370 func(payload hookstage.AllProcessedBidResponsesPayload) (hookstage.AllProcessedBidResponsesPayload, error) { 371 payload.Responses["some-bidder"].Bids[0].DealPriority = 10 372 return payload, nil 373 }, hookstage.MutationUpdate, "processedBidderResponse", "bid.deal-priority", 374 ) 375 376 return hookstage.HookResult[hookstage.AllProcessedBidResponsesPayload]{ChangeSet: c}, nil 377 } 378 379 type mockUpdateBidResponseHook struct{} 380 381 func (e mockUpdateBidResponseHook) HandleAuctionResponseHook(_ context.Context, _ hookstage.ModuleInvocationContext, _ hookstage.AuctionResponsePayload) (hookstage.HookResult[hookstage.AuctionResponsePayload], error) { 382 c := hookstage.ChangeSet[hookstage.AuctionResponsePayload]{} 383 c.AddMutation( 384 func(payload hookstage.AuctionResponsePayload) (hookstage.AuctionResponsePayload, error) { 385 payload.BidResponse.CustomData = "new-custom-data" 386 return payload, nil 387 }, hookstage.MutationUpdate, "auctionResponse", "bidResponse.custom-data") 388 389 return hookstage.HookResult[hookstage.AuctionResponsePayload]{ChangeSet: c}, nil 390 }