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