github.com/prebid/prebid-server/v2@v2.18.0/adapters/zmaticoo/params_test.go (about) 1 package zmaticoo 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-schemas. %v", err) 14 } 15 16 for _, validParam := range validParams { 17 if err := validator.Validate(openrtb_ext.BidderZmaticoo, json.RawMessage(validParam)); err != nil { 18 t.Errorf("Schema rejected zmaticoo params: %s", validParam) 19 } 20 } 21 } 22 23 // TestInvalidParams makes sure that the zmaticoo schema rejects all the imp.ext fields we don't support. 24 func TestInvalidParams(t *testing.T) { 25 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 26 if err != nil { 27 t.Fatalf("Failed to fetch the json-schemas. %v", err) 28 } 29 30 for _, invalidParam := range invalidParams { 31 if err := validator.Validate(openrtb_ext.BidderZmaticoo, json.RawMessage(invalidParam)); err == nil { 32 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 33 } 34 } 35 } 36 37 var validParams = []string{ 38 `{"pubId": "11233", "zoneId": "sin"}`, 39 `{"pubId": "11244", "zoneId": "iad"}`, 40 } 41 42 var invalidParams = []string{ 43 `{"pubId": "11233"}`, 44 `{"zoneId": "aaa"}`, 45 `{"pubId": 123, "zoneId": "sin"}`, 46 `{"pubId": "", "zoneId": "iad"}`, 47 `{"pubId": "11233", "zoneId": ""}`, 48 }