github.com/prebid/prebid-server/v2@v2.18.0/adapters/medianet/params_test.go (about) 1 package medianet 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/prebid/prebid-server/v2/openrtb_ext" 8 ) 9 10 // This file actually intends to test static/bidder-params/medianet.json 11 func TestValidParams(t *testing.T) { 12 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 13 if err != nil { 14 t.Fatalf("Failed to fetch the json-schemas. %v", err) 15 } 16 17 for _, validParam := range validParams { 18 if err := validator.Validate(openrtb_ext.BidderMedianet, json.RawMessage(validParam)); err != nil { 19 t.Errorf("Schema rejected medianet params: %s", validParam) 20 } 21 } 22 } 23 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.BidderMedianet, json.RawMessage(invalidParam)); err == nil { 32 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 33 } 34 } 35 } 36 37 var validParams = []string{ 38 `{"cid":"123", "crid":"1234"}`, 39 } 40 41 var invalidParams = []string{ 42 ``, 43 `null`, 44 `true`, 45 `5`, 46 `4.2`, 47 `[]`, 48 `{}`, 49 `{"cid":"", "crid":""}`, 50 `{"cid":"only cid is present"}`, 51 `{"crid":"only crid is present"}`, 52 `{"ccid":"123","ccrid":"123"}`, 53 `{"aid":123, "placementId":"123", "siteId":"321"}`, 54 }