github.com/prebid/prebid-server/v2@v2.18.0/adapters/gamma/params_test.go (about) 1 package gamma 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/gamma.json 11 12 // TestValidParams makes sure that the Gamma schema accepts all imp.ext fields which we intend to support. 13 func TestValidParams(t *testing.T) { 14 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 15 if err != nil { 16 t.Fatalf("Failed to fetch the json-schemas. %v", err) 17 } 18 19 for _, validParam := range validParams { 20 if err := validator.Validate(openrtb_ext.BidderGamma, json.RawMessage(validParam)); err != nil { 21 t.Errorf("Schema rejected Gamma params: %s", validParam) 22 } 23 } 24 } 25 26 // TestInvalidParams makes sure that the Gamma schema rejects all the imp.ext fields we don't support. 27 func TestInvalidParams(t *testing.T) { 28 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 29 if err != nil { 30 t.Fatalf("Failed to fetch the json-schemas. %v", err) 31 } 32 33 for _, invalidParam := range invalidParams { 34 if err := validator.Validate(openrtb_ext.BidderGamma, json.RawMessage(invalidParam)); err == nil { 35 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 36 } 37 } 38 } 39 40 var validParams = []string{ 41 `{"id": "1397808490", "wid": "1513150517", "zid": "1513151405"}`, 42 `{"id": "1397808490", "wid": "1513150517", "zid": "1513151405", "app_id": "123456789"}`, 43 } 44 45 var invalidParams = []string{ 46 `{"id": 100}`, 47 `{"wid": false}`, 48 `{"zid": true}`, 49 `{"pub_id": 123, "headerbidding": true}`, 50 `{"pub_id": "1"}`, 51 ``, 52 `null`, 53 `true`, 54 `9`, 55 `1.2`, 56 `[]`, 57 `{}`, 58 }