github.com/prebid/prebid-server/v2@v2.18.0/adapters/dmx/params_test.go (about) 1 package dmx 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.BidderDmx, json.RawMessage(validParam)); err != nil { 18 t.Errorf("Schema rejected dmx params: %s", validParam) 19 } 20 } 21 for _, invalidParam := range invalidParams { 22 if err := validator.Validate(openrtb_ext.BidderDmx, json.RawMessage(invalidParam)); err == nil { 23 t.Errorf("Schema was not supposed to be valid: %s", invalidParam) 24 } 25 } 26 } 27 28 var validParams = []string{ 29 `{"memberid": "anyMemberId", "placement_id":"anyPlacementId", "seller_id":"anySellerId", "dmxid":"anyDmxid", "tagid": "25251", "bidfloor": 0.01}`, 30 `{"memberid": "anyMemberId", "seller_id": "anySellerId", "dmxid": "anyDmxid", "tagid": "25251", "bidfloor": 0.01}`, 31 `{"memberid": "anyMemberId", "placement_id": "anyPlacementId", "dmxid": "anyDmxid", "tagid": "25251", "bidfloor": 0.01}`, 32 `{"memberid": "anyMemberId", "placement_id": "anyPlacementId", "seller_id": "anySellerId", "tagid": "25251", "bidfloor": 0.01}`, 33 `{"memberid": "anyMemberId", "placement_id": "anyPlacementId", "seller_id": "anySellerId", "dmxid": "anyDmxid", "bidfloor": 0.01}`, 34 `{"memberid": "anyMemberId", "placement_id": "anyPlacementId", "seller_id": "anySellerId", "dmxid": "anyDmxid", "tagid": "25251"}`, 35 `{"memberid": "anyMemberId"}`, 36 } 37 38 var invalidParams = []string{ 39 `null`, 40 `nil`, 41 ``, 42 `[]`, 43 `true`, 44 `{}`, 45 // Invalid because missing "memberid" 46 `{"placement_id":"anyPlacementId", "seller_id":"anySellerId", "dmxid":"anyDmxid", "tagid": "25251", "bidfloor": 0.01}`, 47 // Invalid because "memberid" not a string 48 `{"memberid": 5}`, 49 // Invalid since dmxid need to be a string 50 `{"memberid": "1222", "dmxid": 432423}`, 51 // 52 // ...more invalid param scenarios 53 // 54 }