github.com/prebid/prebid-server/v2@v2.18.0/adapters/gumgum/params_test.go (about) 1 package gumgum 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.BidderGumGum, json.RawMessage(validParam)); err != nil { 18 t.Errorf("Schema rejected gumgum params: %s", validParam) 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.BidderGumGum, json.RawMessage(invalidParam)); err == nil { 31 t.Errorf("Schema allowed unexpected params: %s", invalidParam) 32 } 33 } 34 } 35 36 var validParams = []string{ 37 `{"zone":"dc9d6be1"}`, 38 `{"pubId":12345678}`, 39 `{"zone":"dc9d6be1", "pubId":12345678}`, 40 `{"zone":"dc9d6be1", "pubId":12345678, "product": "skins"}`, 41 `{"zone":"dc9d6be1", "slot":1234567}`, 42 `{"pubId":12345678, "slot":1234567}`, 43 `{"pubId":12345678, "irisid": "iris_6f9285823a48bne5"}`, 44 `{"zone":"dc9d6be1", "irisid": "iris_6f9285823a48bne5"}`, 45 `{"zone":"dc9d6be1", "pubId":12345678, "irisid": "iris_6f9285823a48bne5"}`, 46 `{"zone":"dc9d6be1", "pubId":12345678, "irisid": "iris_6f9285823a48bne5", "product": "skins"}`, 47 } 48 49 var invalidParams = []string{ 50 `null`, 51 `nil`, 52 ``, 53 `{}`, 54 `[]`, 55 `true`, 56 `2`, 57 `{"zone":12345678}`, 58 `{"zone":""}`, 59 `{"placementId": 1}`, 60 `{"zone": true}`, 61 `{"placementId": 1, "zone":"1234567"}`, 62 `{"pubId":"123456"}`, 63 `{"slot":123456}`, 64 `{"zone":"1234567", "irisid": ""}`, 65 `{"zone":"1234567", "irisid": 1234}`, 66 `{"irisid": "iris_6f9285823a48bne5"}`, 67 `{"product": "test"}`, 68 `{"product": 12345678}`, 69 }