github.com/prebid/prebid-server/v2@v2.18.0/adapters/adhese/params_test.go (about) 1 package adhese 2 3 import ( 4 "encoding/json" 5 "fmt" 6 "testing" 7 8 "github.com/prebid/prebid-server/v2/openrtb_ext" 9 ) 10 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.BidderAdhese, json.RawMessage(validParam)); err != nil { 19 fmt.Println(err) 20 t.Errorf("Schema rejected Adhese params: %s", validParam) 21 } 22 } 23 } 24 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.BidderAdhese, json.RawMessage(invalidParam)); err == nil { 33 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 34 } 35 } 36 } 37 38 var validParams = []string{ 39 `{"account": "demo", "location": "loc1", "format": "for1"}`, 40 `{"account": "demo", "location": "loc1", "format": "for1", "targets": { "ab": ["test", "test2"]}}`, 41 } 42 43 var invalidParams = []string{ 44 `null`, 45 `nil`, 46 ``, 47 `[]`, 48 `true`, 49 `{"location": "loc1", "format": "for1"}`, 50 `{"account": "demo", "format": "for1"}`, 51 `{"account": "demo", "location": "loc1"}`, 52 `{"account": "demo", "location": "loc1", "format": "for1", "targets": null`, 53 `{"account": 5, "location": "loc1", "format": "for1"}`, 54 `{"account": "demo", "location": 5, "format": "for1"}`, 55 `{"account": "demo", "location": "loc1", "format": 5}`, 56 `{"account": "demo", "location": "loc1", "format": "for1", "targets": "test"}`, 57 `{"account": "demo", "location": "loc1", "format": "for1", "targets": 5}`, 58 }