github.com/prebid/prebid-server/v2@v2.18.0/adapters/invibes/params_test.go (about) 1 package invibes 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.BidderInvibes, json.RawMessage(validParam)); err != nil { 18 t.Errorf("Schema rejected invibes params: %s", validParam) 19 } 20 } 21 } 22 23 func TestInvalidParams(t *testing.T) { 24 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 25 if err != nil { 26 t.Fatalf("Failed to fetch the json-schemas. %v", err) 27 } 28 29 for _, invalidParam := range invalidParams { 30 if err := validator.Validate(openrtb_ext.BidderInvibes, json.RawMessage(invalidParam)); err == nil { 31 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 32 } 33 } 34 } 35 36 var validParams = []string{ 37 `{"placementId":"123", "domainId": 1}`, 38 `{"placementId":"123", "domainId": 2, "debug":{}}`, 39 `{"placementId":"123", "domainId": 0, "debug":{"testLog":true}}`, 40 `{"placementId":"123", "domainId": 0, "debug":{"testBvid":"1234"}}`, 41 } 42 43 var invalidParams = []string{ 44 ``, 45 `{"placementId":123}`, 46 `{"placementId":"123", "debug":"malformed"}`, 47 `{"placementId":"123", "domainId": "abc"}`, 48 `{"placementId":"123", "domainId": 2, "debug":{"testLog":1}}`, 49 `null`, 50 `true`, 51 `0`, 52 `abc`, 53 `[]`, 54 `{}`, 55 }