github.com/prebid/prebid-server/v2@v2.18.0/adapters/bwx/params_test.go (about) 1 package bwx 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 `{"env":"boldwinx-stage", "pid":"123456"}`, 12 `{"pid":"123456"}`, 13 } 14 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.BidderBWX, json.RawMessage(validParam)); err != nil { 23 t.Errorf("Schema rejected boldwinx params: %s", validParam) 24 } 25 } 26 } 27 28 var invalidParams = []string{ 29 ``, 30 `null`, 31 `true`, 32 `5`, 33 `[]`, 34 `{}`, 35 `{"some": "param"}`, 36 `{"env":"boldwinx-stage"}`, 37 `{"othervalue":"Lorem ipsum"}`, 38 `{"env":"boldwinx-stage", pid:""}`, 39 `{pid:101010}`, 40 `{pid:"valid-pid", env: 0}`, 41 } 42 43 func TestInvalidParams(t *testing.T) { 44 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 45 if err != nil { 46 t.Fatalf("Failed to fetch the json-schemas. %v", err) 47 } 48 49 for _, invalidParam := range invalidParams { 50 if err := validator.Validate(openrtb_ext.BidderBWX, json.RawMessage(invalidParam)); err == nil { 51 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 52 } 53 } 54 }