github.com/prebid/prebid-server/v2@v2.18.0/adapters/pulsepoint/params_test.go (about) 1 package pulsepoint 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.BidderPulsepoint, json.RawMessage(validParam)); err != nil { 18 t.Errorf("Schema rejected pulsepoint params: %s \n Error: %s", validParam, err) 19 } 20 } 21 } 22 23 // TestInvalidParams makes sure that the pubmatic 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.BidderPulsepoint, json.RawMessage(invalidParam)); err == nil { 32 t.Errorf("Schema allowed unexpected pulsepoint params: %s", invalidParam) 33 } 34 } 35 } 36 37 var validParams = []string{ 38 `{"cp":1000, "ct": 2000}`, 39 `{"cp":1001, "ct": 2001}`, 40 `{"cp":1001, "ct": 2001, "cf": "1x1"}`, 41 } 42 43 var invalidParams = []string{ 44 ``, 45 `null`, 46 `true`, 47 `5`, 48 `4.2`, 49 `[]`, 50 `{}`, 51 `{"cp":"1000"}`, 52 `{"ct":"1000"}`, 53 `{"cp":1000}`, 54 `{"ct":1000}`, 55 `{"cp":1000, "ct":"1000"}`, 56 `{"cp":1000, "ct": "abcd"}`, 57 `{"cp":"abcd", "ct": 1000}`, 58 `{"cp":"1000.2", "ct": "1000.1"}`, 59 }