github.com/prebid/prebid-server/v2@v2.18.0/adapters/sharethrough/params_test.go (about) 1 package sharethrough 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.BidderSharethrough, 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.BidderSharethrough, json.RawMessage(p)); err == nil { 31 t.Errorf("Schema allowed invalid params: %s", p) 32 } 33 } 34 } 35 36 var validParams = []string{ 37 `{"pkey": "123"}`, 38 `{"pkey": "123", "bcat": []}`, 39 `{"pkey": "123", "bcat": ["IAB-1"]}`, 40 `{"pkey": "abc", "badv": []}`, 41 `{"pkey": "abc", "badv": ["advertiser.com"]}`, 42 `{"pkey": "abc123", "bcat": [], "badv": []}`, 43 `{"pkey": "abc123", "bcat": ["IAB-1", "IAB-2"], "badv": ["other.advertiser.com"]}`, 44 } 45 46 var invalidParams = []string{ 47 ``, 48 `null`, 49 `true`, 50 `5`, 51 `4.2`, 52 `[]`, 53 `{}`, 54 `{"pkey": 123}`, 55 `{"bcat": 123}`, 56 `{"badv": 123}`, 57 `{"bcat": ["IAB-1", "IAB-2"]}`, 58 `{"badv": ["other.advertiser.com"]}`, 59 `{"bcat": ["IAB-1", "IAB-2"], "badv": ["other.advertiser.com"]}`, 60 `{"pkey": 123, "bcat": ["IAB-1", "IAB-2"], "badv": ["other.advertiser.com"]}`, 61 }