github.com/prebid/prebid-server/v2@v2.18.0/adapters/adnuntius/params_test.go (about) 1 package adnuntius 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/adnuntius.json 11 // These also validate the format of the external API: request.imp[i].ext.prebid.bidder.adnuntius 12 // TestValidParams makes sure that the adnuntius 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.BidderAdnuntius, json.RawMessage(validParam)); err != nil { 22 t.Errorf("Schema rejected adnuntius params: %s", validParam) 23 } 24 } 25 } 26 27 // TestInvalidParams makes sure that the adnuntius 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.BidderAdnuntius, json.RawMessage(invalidParam)); err == nil { 36 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 37 } 38 } 39 } 40 41 var validParams = []string{ 42 `{"auId":"123"}`, 43 `{"auId":"123", "network":"test"}`, 44 } 45 46 var invalidParams = []string{ 47 ``, 48 `null`, 49 `true`, 50 `5`, 51 `4.2`, 52 `[]`, 53 `{}`, 54 `{"auId":123}`, 55 `{"auID":"123"}`, 56 `{"network":123}`, 57 `{"network":123, "auID":123}`, 58 `{"network":"test", "auID":123}`, 59 `{"network":test, "auID":"123"}`, 60 }