github.com/prebid/prebid-server/v2@v2.18.0/adapters/adgeneration/params_test.go (about) 1 package adgeneration 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-schemas. %v", err) 14 } 15 for _, validParam := range validParams { 16 if err := validator.Validate(openrtb_ext.BidderAdgeneration, json.RawMessage(validParam)); err != nil { 17 t.Errorf("Schema rejected adgeneration params: %s", validParam) 18 } 19 } 20 } 21 22 func TestInvalidParams(t *testing.T) { 23 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 24 if err != nil { 25 t.Fatalf("Failed to fetch the json-schemas. %v", err) 26 } 27 28 for _, invalidParam := range invalidParams { 29 if err := validator.Validate(openrtb_ext.BidderAdgeneration, json.RawMessage(invalidParam)); err == nil { 30 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 31 } 32 } 33 } 34 35 var validParams = []string{ 36 `{"id":"12345"}`, 37 `{"id":"123456"}`, 38 `{"id":""}`, 39 `{"id":"12345","other_params":"hoge"}`, 40 } 41 42 var invalidParams = []string{ 43 `{}`, 44 `null`, 45 `12345`, 46 `{"id":123456}`, 47 }