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