github.com/prebid/prebid-server/v2@v2.18.0/adapters/adtelligent/params_test.go (about) 1 package adtelligent 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/adtelligent.json 11 // These also validate the format of the external API: request.imp[i].ext.prebid.bidder.adtelligent 12 // TestValidParams makes sure that the adtelligent schema accepts all imp.ext fields which we intend to support. 13 14 func TestValidParams(t *testing.T) { 15 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 16 if err != nil { 17 t.Fatalf("Failed to fetch the json-schemas. %v", err) 18 } 19 20 for _, validParam := range validParams { 21 if err := validator.Validate(openrtb_ext.BidderAdtelligent, json.RawMessage(validParam)); err != nil { 22 t.Errorf("Schema rejected adtelligent params: %s", validParam) 23 } 24 } 25 } 26 27 // TestInvalidParams makes sure that the adtelligent schema rejects all the imp.ext fields we don't support. 28 func TestInvalidParams(t *testing.T) { 29 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 30 if err != nil { 31 t.Fatalf("Failed to fetch the json-schemas. %v", err) 32 } 33 34 for _, invalidParam := range invalidParams { 35 if err := validator.Validate(openrtb_ext.BidderAdtelligent, json.RawMessage(invalidParam)); err == nil { 36 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 37 } 38 } 39 } 40 41 var validParams = []string{ 42 `{"aid":123}`, 43 `{"aid":123,"placementId":1234}`, 44 `{"aid":123,"siteId":4321}`, 45 `{"aid":123,"siteId":0,"bidFloor":0}`, 46 } 47 48 var invalidParams = []string{ 49 ``, 50 `null`, 51 `true`, 52 `5`, 53 `4.2`, 54 `[]`, 55 `{}`, 56 `{"aid":"123"}`, 57 `{"aid":"0"}`, 58 `{"aid":"123","placementId":"123"}`, 59 `{"aid":123, "placementId":"123", "siteId":"321"}`, 60 }