github.com/prebid/prebid-server@v0.275.0/adapters/improvedigital/params_test.go (about) 1 package improvedigital 2 3 import ( 4 "encoding/json" 5 "github.com/prebid/prebid-server/openrtb_ext" 6 "testing" 7 ) 8 9 func TestValidParams(t *testing.T) { 10 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 11 if err != nil { 12 t.Fatalf("Failed to fetch the json-schemas. %v", err) 13 } 14 15 for _, validParam := range validParams { 16 if err := validator.Validate(openrtb_ext.BidderImprovedigital, json.RawMessage(validParam)); err != nil { 17 t.Errorf("Schema rejected improvedigital params: %s", validParam) 18 } 19 } 20 } 21 22 func TestInvalidParams(t *testing.T) { 23 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 24 if err != nil { 25 t.Fatalf("Failed to fetch the json-schemas. %v", err) 26 } 27 28 for _, invalidParam := range invalidParams { 29 if err := validator.Validate(openrtb_ext.BidderImprovedigital, json.RawMessage(invalidParam)); err == nil { 30 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 31 } 32 } 33 } 34 35 var validParams = []string{ 36 `{"placementId":13245}`, 37 `{"placementId":13245, "size": {"w":16, "h":9}}`, 38 `{"publisherId":13245, "placementKey": "slotA"}`, 39 `{"placementId":13245, "keyValues":{"target1":["foo"],"target2":["bar", "baz"]}}`, 40 } 41 42 var invalidParams = []string{ 43 `null`, 44 `nil`, 45 ``, 46 `[]`, 47 `true`, 48 `2`, 49 `{"size": {"w": 10, "h": 5}}`, 50 `{"other_optional": true}`, 51 `{"size":12345678}`, 52 `{"size":""}`, 53 `{"placementId":-9}`, 54 `{"publisherId":9}`, 55 `{"placementId": "1"}`, 56 `{"size": true}`, 57 `{"placementId": true, "size":"1234567"}`, 58 `{"placementId":13245, "publisherId":13245, "placementKey": "slotA"}`, 59 }