github.com/prebid/prebid-server/v2@v2.18.0/adapters/appnexus/params_test.go (about) 1 package appnexus 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/prebid/prebid-server/v2/openrtb_ext" 8 ) 9 10 // This file actually intends to test static/bidder-params/appnexus.json 11 // 12 // These also validate the format of the external API: request.imp[i].ext.prebid.bidder.appnexus 13 14 // TestValidParams makes sure that the appnexus schema accepts all imp.ext fields which we intend to support. 15 func TestValidParams(t *testing.T) { 16 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 17 if err != nil { 18 t.Fatalf("Failed to fetch the json-schemas. %v", err) 19 } 20 21 for _, validParam := range validParams { 22 if err := validator.Validate(openrtb_ext.BidderAppnexus, json.RawMessage(validParam)); err != nil { 23 t.Errorf("Schema rejected appnexus params: %s", validParam) 24 } 25 } 26 } 27 28 // TestInvalidParams makes sure that the appnexus schema rejects all the imp.ext fields we don't support. 29 func TestInvalidParams(t *testing.T) { 30 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 31 if err != nil { 32 t.Fatalf("Failed to fetch the json-schemas. %v", err) 33 } 34 35 for _, invalidParam := range invalidParams { 36 if err := validator.Validate(openrtb_ext.BidderAppnexus, json.RawMessage(invalidParam)); err == nil { 37 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 38 } 39 } 40 } 41 42 var validParams = []string{ 43 `{"placement_id":123}`, 44 `{"placement_id":"123"}`, 45 `{"placementId":123}`, 46 `{"placementId":"123"}`, 47 `{"placementId":123,"position":"above"}`, 48 `{"placement_id":123,"position":"below"}`, 49 `{"member":"123","inv_code":"456"}`, 50 `{"placementId":123, "keywords":[{"key":"foo","value":["bar"]}]}`, 51 `{"placement_id":123, "keywords":[{"key":"foo","value":["bar", "baz"]}]}`, 52 `{"placement_id":123, "keywords":[{"key":"foo"}]}`, 53 `{"placement_id":123, "keywords":"foo=bar,foo=baz"}`, 54 `{"placement_id":123, "keywords":{"genre": ["rock", "pop"], "pets": ["dog"]}}`, 55 `{"placement_id":123, "use_pmt_rule": true, "private_sizes": [{"w": 300, "h":250}]}`, 56 `{"placementId":123, "ext_inv_code": "invCode"}`, 57 `{"placementId":123, "external_imp_id": "impId"}`, 58 } 59 60 var invalidParams = []string{ 61 ``, 62 `null`, 63 `true`, 64 `5`, 65 `4.2`, 66 `[]`, 67 `{}`, 68 `{"placement_id":123, "placementId":123}`, 69 `{"member":"123"}`, 70 `{"member":"123","invCode":45}`, 71 `{"placementId":"123","member":"123","invCode":45}`, 72 `{"placement_id":123, "position":"left"}`, 73 `{"placement_id":123, "position":"left"}`, 74 `{"placement_id":123, "reserve":"45"}`, 75 `{"placement_id":123, "keywords":[]}`, 76 `{"placement_id":123, "keywords":["foo"]}`, 77 `{"placementId":123, "keywords":[{"key":"foo","value":[]}]}`, 78 `{"placementId":123, "keywords":[{"value":["bar"]}]}`, 79 `{"placement_id":123, "keywords":{"genre": [12]}}`, 80 `{"placement_id":123, "use_pmt_rule": "true"}`, 81 `{"placement_id":123, "private_sizes": [[300,250]]}`, 82 `{"placement_id":123, "private_sizes": [{"w": "300", "h": "250"}]}`, 83 `{"placementId":123, "ext_inv_code": 1}`, 84 `{"placementId":123, "external_imp_id": 2}`, 85 }