github.com/prebid/prebid-server/v2@v2.18.0/adapters/trafficgate/params_test.go (about) 1 package trafficgate 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/prebid/prebid-server/v2/openrtb_ext" 8 ) 9 10 // TestValidParams makes sure that the trafficgate schema accepts all imp.ext fields which we intend to support. 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.BidderTrafficGate, json.RawMessage(validParam)); err != nil { 19 t.Errorf("Schema rejected trafficgate params: %s", validParam) 20 } 21 } 22 } 23 24 // TestInvalidParams makes sure that the trafficgate schema rejects all the imp.ext fields we don't support. 25 func TestInvalidParams(t *testing.T) { 26 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 27 if err != nil { 28 t.Fatalf("Failed to fetch the json-schemas. %v", err) 29 } 30 31 for _, invalidParam := range invalidParams { 32 if err := validator.Validate(openrtb_ext.BidderTrafficGate, json.RawMessage(invalidParam)); err == nil { 33 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 34 } 35 } 36 } 37 38 var validParams = []string{ 39 `{"placementId": "11", "host": "example"}`, 40 } 41 42 var invalidParams = []string{ 43 `{"id": "456"}`, 44 `{"placementid": "3456", "host": ""}`, 45 `{"placement_id": 346, "host": ""}`, 46 `{"placementID": "", "HOST": "example"}`, 47 `{"placementId": 234}`, 48 }