github.com/prebid/prebid-server/v2@v2.18.0/adapters/silvermob/params_test.go (about) 1 package silvermob 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/prebid/prebid-server/v2/openrtb_ext" 8 ) 9 10 // TestValidParams makes sure that the silvermob schema accepts all imp.ext fields which we intend to support. 11 func TestValidParams(t *testing.T) { 12 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 13 if err != nil { 14 t.Fatalf("Failed to fetch the json-schemas. %v", err) 15 } 16 17 for _, validParam := range validParams { 18 if err := validator.Validate(openrtb_ext.BidderSilverMob, json.RawMessage(validParam)); err != nil { 19 t.Errorf("Schema rejected silvermob params: %s", validParam) 20 } 21 } 22 } 23 24 // TestInvalidParams makes sure that the silvermob schema rejects all the imp.ext fields we don't support. 25 func TestInvalidParams(t *testing.T) { 26 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 27 if err != nil { 28 t.Fatalf("Failed to fetch the json-schemas. %v", err) 29 } 30 31 for _, invalidParam := range invalidParams { 32 if err := validator.Validate(openrtb_ext.BidderSilverMob, json.RawMessage(invalidParam)); err == nil { 33 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 34 } 35 } 36 } 37 38 var validParams = []string{ 39 `{"zoneid": "16", "host": "us"}`, 40 `{"zoneid": "16", "host": "eu"}`, 41 } 42 43 var invalidParams = []string{ 44 ``, 45 `null`, 46 `true`, 47 `5`, 48 `4.2`, 49 `[]`, 50 `{}`, 51 `{"ZoneID": "asd", "Host": "123"}`, 52 `{}`, 53 `{"ZoneID": "asd"}`, 54 `{"Host": "111"}`, 55 `{"zoneid": 16, "host": 111}`, 56 }