github.com/prebid/prebid-server/v2@v2.18.0/adapters/kayzen/params_test.go (about) 1 package kayzen 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/prebid/prebid-server/v2/openrtb_ext" 8 ) 9 10 var validParams = []string{ 11 `{ "zone": "dc", "exchange": "ex" }`, 12 } 13 14 func TestValidParams(t *testing.T) { 15 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 16 if err != nil { 17 t.Fatalf("Failed to fetch the json-schemas. %v", err) 18 } 19 20 for _, validParam := range validParams { 21 if err := validator.Validate(openrtb_ext.BidderKayzen, json.RawMessage(validParam)); err != nil { 22 t.Errorf("Schema rejected Kayzen params: %s", validParam) 23 } 24 } 25 } 26 27 var invalidParams = []string{ 28 ``, 29 `null`, 30 `true`, 31 `5`, 32 `4.2`, 33 `[]`, 34 `{}`, 35 `{ "key": 2 }`, 36 `{ "anyparam": "anyvalue" }`, 37 `{ "zone": "dc" }`, 38 `{ "exchange": "ex" }`, 39 `{ "exchange": "", "zone" : "" }`, 40 `{ "exchange": "ex", "zone" : "" }`, 41 `{ "exchange": "", "zone" : "dc" }`, 42 } 43 44 func TestInvalidParams(t *testing.T) { 45 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 46 if err != nil { 47 t.Fatalf("Failed to fetch the json-schemas. %v", err) 48 } 49 50 for _, invalidParam := range invalidParams { 51 if err := validator.Validate(openrtb_ext.BidderKayzen, json.RawMessage(invalidParam)); err == nil { 52 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 53 } 54 } 55 }