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