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