github.com/prebid/prebid-server/v2@v2.18.0/adapters/adot/params_test.go (about) 1 package adot 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/adot.json 11 // 12 // These also validate the format of the external API: request.imp[i].ext.prebid.bidder.adot 13 14 // TestValidParams makes sure that the adot 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.BidderAdot, json.RawMessage(validParam)); err != nil { 23 t.Errorf("Schema rejected adot params: %s", validParam) 24 } 25 } 26 } 27 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.BidderAdot, json.RawMessage(invalidParam)); err == nil { 36 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 37 } 38 } 39 } 40 41 var validParams = []string{ 42 `{}`, 43 `{"placementId": "test-114"}`, 44 `{"placementId": "test-113", "parallax": true}`, 45 `{"placementId": "test-113", "parallax": false}`, 46 `{"placementId": "test-113", "parallax": false, "publisherPath": "/hubvisor"}`, 47 `{"placementId": "test-113", "parallax": false, "publisherPath": ""}`, 48 } 49 50 var invalidParams = []string{ 51 `{"parallax": 1}`, 52 `{"placementId": 135123}`, 53 `{"publisherPath": 111}`, 54 `{"placementId": 113, "parallax": 1}`, 55 `{"placementId": 142, "parallax": true}`, 56 `{"placementId": "test-114", "parallax": 1}`, 57 `{"placementId": "test-114", "parallax": true, "publisherPath": 111}`, 58 }