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