github.com/prebid/prebid-server/v2@v2.18.0/adapters/huaweiads/params_test.go (about) 1 package huaweiads 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.BidderHuaweiAds, json.RawMessage(validParam)); err != nil { 18 t.Errorf("Schema rejected huaweiads 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 `{"slotid": "m8x9x3rzff","adtype": "banner","publisherid": "123","signkey": "2f910deac52ff34f0d80585d8664c55e3422ff3c6aeb5e1cf2ff94f1ac6a9642","keyid": "41","clienttime": "2018-11-02 16:34:07.981+1300"}`, 38 `{"slotid": "m8x9x3rzff","adtype": "banner","publisherid": "123","signkey": "2f910deac52ff34f0d80585d8664c55e3422ff3c6aeb5e1cf2ff94f1ac6a9642","keyid": "41"}`, 39 } 40 41 var invalidParams = []string{ 42 `null`, 43 `nil`, 44 ``, 45 `{}`, 46 `[]`, 47 `true`, 48 `2`, 49 `{"slotid": "","adtype": "banner","publisherid": "123","signkey": "2f910deac52ff34f0d80585d8664c55e3422ff3c6aeb5e1cf2ff94f1ac6a9642","keyid": "41","clienttime": "2018-11-02 16:34:07.981+1300"}`, 50 `{"slotid": "m8x9x3rzff","adtype": "","publisherid": "123","signkey": "2f910deac52ff34f0d80585d8664c55e3422ff3c6aeb5e1cf2ff94f1ac6a9642","keyid": "41","clienttime": "2018-11-02 16:34:07.981+1300"}`, 51 `{"slotid": "m8x9x3rzff","adtype": "banner","publisherid": "","signkey": "2f910deac52ff34f0d80585d8664c55e3422ff3c6aeb5e1cf2ff94f1ac6a9642","keyid": "41","clienttime": "2018-11-02 16:34:07.981+1300"}`, 52 `{"slotid": "m8x9x3rzff","adtype": "banner","publisherid": "123","signkey": "","keyid": "41","clienttime": "2018-11-02 16:34:07.981+1300"}`, 53 `{"slotid": "m8x9x3rzff","adtype": "banner","publisherid": "123","signkey": "2f910deac52ff34f0d80585d8664c55e3422ff3c6aeb5e1cf2ff94f1ac6a9642","keyid": "","clienttime": "2018-11-02 16:34:07.981+1300"}`, 54 }