github.com/prebid/prebid-server/v2@v2.18.0/adapters/lockerdome/params_test.go (about) 1 package lockerdome 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/prebid/prebid-server/v2/openrtb_ext" 8 ) 9 10 // This file tests static/bidder-params/lockerdome.json 11 // and validates the format of the external API: request.imp[i].ext.prebid.bidder.lockerdome 12 13 // TestValidParams makes sure that the LockerDome schema accepts all imp.ext fields which we intend to support. 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.BidderLockerDome, json.RawMessage(validParam)); err != nil { 22 t.Errorf("Schema rejected LockerDome params: %s", validParam) 23 } 24 } 25 } 26 27 // TestInvalidParams makes sure that the LockerDome 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.BidderLockerDome, json.RawMessage(invalidParam)); err == nil { 36 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 37 } 38 } 39 } 40 41 var validParams = []string{ 42 `{"adUnitId": "LD1234567890"}`, // adUnitId can start with "LD" 43 } 44 45 var invalidParams = []string{ 46 `null`, 47 `nil`, 48 ``, 49 `true`, 50 `1`, 51 `1.5`, 52 `[]`, 53 `{}`, 54 `{"adUnitId": true}`, 55 `{"adUnitId": 123456789}`, // adUnitId can't be a number 56 }