github.com/prebid/prebid-server/v2@v2.18.0/adapters/bidstack/params_test.go (about) 1 package bidstack 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 `{"publisherId": "355cf800-8348-433a-9d95-70345fa70afc"}`, 12 `{"publisherId": "355cf800-8348-433a-9d95-70345fa70afc","placementId":"Some placement ID"}`, 13 `{"publisherId": "355cf800-8348-433a-9d95-70345fa70afc","consent":false}`, 14 `{"publisherId": "355cf800-8348-433a-9d95-70345fa70afc","placementId":"Some placement ID","consent":true}`, 15 } 16 17 var invalidParams = []string{ 18 `{"publisherId": ""}`, 19 `{"publisherId": "non-uuid"}`, 20 `{"consent": "true"}`, 21 } 22 23 func TestValidParams(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 validParams { 30 if err := validator.Validate(openrtb_ext.BidderBidstack, json.RawMessage(p)); err != nil { 31 t.Errorf("Schema rejected valid params: %s", p) 32 } 33 } 34 } 35 36 func TestInvalidParams(t *testing.T) { 37 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 38 if err != nil { 39 t.Fatalf("Failed to fetch the json schema. %v", err) 40 } 41 42 for _, p := range invalidParams { 43 if err := validator.Validate(openrtb_ext.BidderBidstack, json.RawMessage(p)); err == nil { 44 t.Errorf("Schema allowed invalid params: %s", p) 45 } 46 } 47 }