github.com/prebid/prebid-server/v2@v2.18.0/adapters/tappx/params_test.go (about) 1 package tappx 2 3 import ( 4 "encoding/json" 5 "testing" 6 7 "github.com/prebid/prebid-server/v2/openrtb_ext" 8 ) 9 10 func TestValidParams(t *testing.T) { 11 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 12 if err != nil { 13 t.Fatalf("Failed to fetch the json-schemas. %v", err) 14 } 15 16 for _, validParam := range validParams { 17 if err := validator.Validate(openrtb_ext.BidderTappx, json.RawMessage(validParam)); err != nil { 18 t.Errorf("Schema rejected tappx params: %s \n Error: %s", validParam, err) 19 } 20 } 21 } 22 23 func TestInvalidParams(t *testing.T) { 24 validator, err := openrtb_ext.NewBidderParamsValidator("../../static/bidder-params") 25 if err != nil { 26 t.Fatalf("Failed to fetch the json-schemas. %v", err) 27 } 28 29 for _, invalidParam := range invalidParams { 30 if err := validator.Validate(openrtb_ext.BidderTappx, json.RawMessage(invalidParam)); err == nil { 31 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 32 } 33 } 34 } 35 36 var validParams = []string{ 37 `{"tappxkey":"pub-12345-android-9876", "endpoint":"ZZ1INTERNALTEST149147915"}`, 38 `{"tappxkey":"pub-12345-android-9876", "endpoint":"ZZ1INTERNALTEST149147915", "host":"test.tappx.com"}`, 39 `{"tappxkey":"pub-12345-android-9876", "endpoint":"ZZ1INTERNALTEST149147915", "host":"test.tappx.com", "bidfloor":0.5}`, 40 `{"tappxkey":"pub-12345-android-9876", "endpoint":"ZZ1INTERNALTEST149147915", "host":"test.tappx.com", "bidfloor":0.5, "mktag":"txmk-xxxxx-xxx-xxxx"}`, 41 `{"tappxkey":"pub-12345-android-9876", "endpoint":"ZZ1INTERNALTEST149147915", "host":"test.tappx.com", "bidfloor":0.5, "bcid":["123"]}`, 42 `{"tappxkey":"pub-12345-android-9876", "endpoint":"ZZ1INTERNALTEST149147915", "host":"test.tappx.com", "bidfloor":0.5, "bcrid":["245"]}`, 43 `{"tappxkey":"pub-12345-android-9876", "endpoint":"ZZ1INTERNALTEST149147915", "host":"test.tappx.com", "bidfloor":0.5, "bcrid":["245", "321"]}`, 44 `{"tappxkey":"pub-12345-android-9876", "endpoint":"ZZ1INTERNALTEST149147915", "host":"test.tappx.com", "bidfloor":0.5, "bcid":["123", "654"], "bcrid":["245", "321"]}`, 45 } 46 47 var invalidParams = []string{ 48 ``, 49 `null`, 50 `true`, 51 `5`, 52 `4.2`, 53 `[]`, 54 `{}`, 55 `{"tappxkey":""}`, 56 `{"tappxkey":"pub-12345-android-9876"}`, 57 `{"endpoint":""}`, 58 `{"endpoint":"ZZ1INTERNALTEST149147915"}`, 59 `{"tappxkey": 1, "endpoint":"ZZ1INTERNALTEST149147915"}`, 60 `{"tappxkey":"pub-12345-android-9876", "endpoint": 1}`, 61 `{"tappxkey": 1, "endpoint": 1}`, 62 `{"tappxkey": 1, "endpoint":"ZZ1INTERNALTEST149147915", "host":""}`, 63 `{"tappxkey":"pub-12345-android-9876", "endpoint": 1, "host":""}`, 64 `{"tappxkey": 1, "endpoint": 1, "host": 123}`, 65 `{"tappxkey": "1", "endpoint": 1}`, 66 `{"tappxkey": "1", "endpoint": "ZZ1INTERNALTEST149147915", "host":[]]}`, 67 `{"tappxkey": "1", "endpoint": 1}`, 68 `{"tappxkey": "1", "endpoint": "1", "mktag":1}`, 69 `{"tappxkey": "1", "endpoint": "1", "mktag":[1,2]}`, 70 `{"tappxkey": "1", "endpoint": "1", "bcid":""}`, 71 `{"tappxkey": "1", "endpoint": "1", "bcid":"123", bcrid: ["123"]}`, 72 `{"tappxkey": "1", "endpoint": "1", "bcid":["123"], bcrid: 123}`, 73 `{"tappxkey": "1", "endpoint": "1", "bcid":["123"], bcrid: [123]}`, 74 `{"tappxkey": "1", "endpoint": "1", "bcid":[123], bcrid: ["123"]}`, 75 }