github.com/prebid/prebid-server/v2@v2.18.0/adapters/smarthub/params_test.go (about) 1 package smarthub 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 `{"partnerName":"partnertest", "seat":"9Q20EdGxzgWdfPYShScl", "token":"eKmw6alpP3zWQhRCe3flOpz0wpuwRFjW"}`, 12 } 13 14 func TestValidParams(t *testing.T) { 15 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 16 if err != nil { 17 t.Fatalf("Failed to fetch the json-schemas. %v", err) 18 } 19 20 for _, validParam := range validParams { 21 if err := validator.Validate(openrtb_ext.BidderSmartHub, json.RawMessage(validParam)); err != nil { 22 t.Errorf("Schema rejected smarthub params: %s", validParam) 23 } 24 } 25 } 26 27 var invalidParams = []string{ 28 ``, 29 `null`, 30 `true`, 31 `5`, 32 `[]`, 33 `{}`, 34 `{"anyparam": "anyvalue"}`, 35 `{"partnerName":"partnertest"}`, 36 `{"seat":"9Q20EdGxzgWdfPYShScl"}`, 37 `{"token":"Y9Evrh40ejsrCR4EtidUt1cSxhJsz8X1"}`, 38 `{"seat":"9Q20EdGxzgWdfPYShScl", "token":"alNYtemWggraDVbhJrsOs9pXc3Eld32E"}`, 39 `{"partnerName":"partnertest", "token":"LNywdP2ebX5iETF8gvBeEoB6Cam64eeq"}`, 40 `{"partnerName":"partnertest", "seat":"9Q20EdGxzgWdfPYShScl"}`, 41 `{"partnerName":"", "seat":"", "token":""}`, 42 `{"partnerName":"", "seat":"9Q20EdGxzgWdfPYShScl", "token":"alNYtemWggraDVbhJrsOs9pXc3Eld32E"}`, 43 `{"partnerName":"partnertest", "seat":"9Q20EdGxzgWdfPYShScl", "token":""}`, 44 `{"partnerName":"partnertest", "seat":"", "token":"alNYtemWggraDVbhJrsOs9pXc3Eld32E"}`, 45 } 46 47 func TestInvalidParams(t *testing.T) { 48 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 49 if err != nil { 50 t.Fatalf("Failed to fetch the json-schemas. %v", err) 51 } 52 53 for _, invalidParam := range invalidParams { 54 if err := validator.Validate(openrtb_ext.BidderSmartHub, json.RawMessage(invalidParam)); err == nil { 55 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 56 } 57 } 58 }