github.com/prebid/prebid-server/v2@v2.18.0/adapters/mobfoxpb/params_test.go (about) 1 package mobfoxpb 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 mobfoxpb 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.BidderMobfoxpb, json.RawMessage(validParam)); err != nil { 19 t.Errorf("Schema rejected mobfoxpb params: %s", validParam) 20 } 21 } 22 } 23 24 // TestInvalidParams makes sure that the mobfoxpb 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.BidderMobfoxpb, json.RawMessage(invalidParam)); err == nil { 33 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 34 } 35 } 36 } 37 38 var validParams = []string{ 39 `{"TagID": "6"}`, 40 `{"key": "1"}`, 41 } 42 43 var invalidParams = []string{ 44 `{"id": "123"}`, 45 `{"tagid": "123"}`, 46 `{"TagID": 16}`, 47 `{"TagID": ""}`, 48 `{"Key": "1"}`, 49 `{"key": 1}`, 50 `{"key":""}`, 51 }