github.com/prebid/prebid-server@v0.275.0/adapters/undertone/params_test.go (about) 1 package undertone 2 3 import ( 4 "encoding/json" 5 "github.com/prebid/prebid-server/openrtb_ext" 6 "testing" 7 ) 8 9 func TestValidParams(t *testing.T) { 10 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 11 if err != nil { 12 t.Fatalf("Failed to fetch the json schema. %v", err) 13 } 14 15 for _, validParam := range validParams { 16 if err := validator.Validate(openrtb_ext.BidderUndertone, json.RawMessage(validParam)); err != nil { 17 t.Errorf("Schema rejected valid 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 schema. %v", err) 26 } 27 28 for _, p := range invalidParams { 29 if err := validator.Validate(openrtb_ext.BidderUndertone, json.RawMessage(p)); err == nil { 30 t.Errorf("Schema allowed invalid params: %s", p) 31 } 32 } 33 } 34 35 var validParams = []string{ 36 `{"placementId": 12345, "publisherId": 1234}`, 37 `{"placementId": 1, "publisherId": 1}`, 38 } 39 40 var invalidParams = []string{ 41 `{"placementId": "1234some-string"}`, 42 `{"placementId": 1234, "publisherId": 0}`, 43 `{"placementId": 0, "publisherId": 1}`, 44 `{"placementId": "1non-numeric", "publisherId": "non-numeric"}`, 45 }